Andr ́es is a young guy who decided to become a street magician in the beautiful city of Bogot. He is very quick with his hands, and one of his favourite ways to earn money is gambling with people who approach him on the streets, over a game he calls “Red and Purple Coins”, or RPC for short. The game is simple. He has a bag filled with coins, and each of these coins has one of two colors: red or purple. Whenever a good crowd forms around him, he explains that he will pick up one coin at random from the bag, and he will start doing various tricks with it, in such a way that the coin will be clearly visible to everyone. Then people just have to say the color of the coin, and those who get the color right win the bet. However, as you can imagine, it is not Andrs’ intention to lose money. He knows that he can move around the coin at such speed that even when it is in plain sight for everyone, it gets blurry and therefore it is difficult to determine its color. You decide to play the game, confident in your reasoning and programming abilities more than in your visual perception. You have been keeping track of all the people who play with Andrs for a long time, and in this way have determined the probability of any given person identifying the color correctly in an independent test. We will call this the reliability value (RV) of each person. You also have figured out the exact number of coins of each color that Andrs has in his bag at all times. So, for example, if Andrs does his trick and then someone from the crowd, whose RV is 0.8, says that the coin is purple, and you check your notes and see that 77% of the coins in the bag were red and 23% were purple, you can start doing your calculations and. . . how about that? The probability that the coin was in fact purple is about 54%. Since these calculations can get a little tedious, you decide to write a program to help you figure out the probability of the coin being red or purple, given the testimonies and RVs of all the people from the crowd, and the initial proportion of red/purple coins in the bag. Input Each test case starts with a real number R, the proportion of red coins in the bag (the proportion for purple coins is 1−R). The second line of a test case contains N, the number of people who have made a guess. This is followed by N lines, each one with a letter representing the person’s guess (R for red and P for purple), and a real number V , which is that person’s RV. The input ends when there are no more lines to process. 0≤R≤1;1≤N≤20;0<V <1 Output For each case print two real number in a single line. These numbers must be the probability of the coin being red, and the probability of it being purple, in that order. Answers with a relative or absolute error less than 10−4 are considered correct. Sample Input 0.77 1 P 0.8 0.6 3
2/2 R 0.5 R 0.333 P 0.9 Sample Output 0.455621 0.544379 0.076817 0.923183