10773 - Fish Farmer   

Description

Adam is a fish farmer whose job is to manage two fishponds A and B. At the beginning of the first year, fishponds A and B contains N and M fish, respectively. The number of fish in each pond increases by 8% every year. At the beginning of each of the following K years, Adam moves some amount of fish from one fishpond to the other. You are asked to help calculate the amount of fish in fishponds A and B after K years.

Note: When you calculate the amount of fish by multiplying the increasing rate, you should round the result down to the nearest integer; For example,1.7→1. (無條件捨去成整數).

 

Consider the following example:

  • In the beginning of year 1:
    • fishpond A contains 500 fish  
    • fishpond B contains 300 fish.
  • In the beginning of year 2:
    • fishpond A contains (500*1.08) -25=540-25=515 fish 
    • fishpond B contains (300*1.08) +25=324+25=349 fish
  • In the beginning of year 3:
    • fishpond A contains (515*1.08)+150=556+150= 706 fish 
    • fishpond B contains (349*1.08) -150=376-150=226 fish
  • In the beginning of year 4:
    • fishpond A contains (706*1.08)+176=762+176= 938 fish 
    • fishpond B contains (226*1.08) -176=244-176=68 fish

Input

The input contains several lines. The first line contains two positive integers N and M, which represents the number of fish in fishponds A and B at the beginning of the first year, respectively.

The second line contains a positive integer K, which represents the number of years you should consider.

Each of the remaining K lines contains two elements, which are separated by a blank, describing the fish movement in each year, starting from the 2nd year:

  • The first element indicates the instruction.
    • ‘A’: move fish from A to B
    • ‘B’: move fish from B to A
  • The second element indicates the number of fish that are moved. (0 < the number of fish < 1000)

Output

The amounts of fish in fishponds A and B in the beginning of year K+1, respectively, which are separated by a blank. Note that you need to print a '\n' at the end. 

Sample Input  Download

Sample Output  Download

Tags




Discuss