Problem:
Problem A:
Ohgas' Fortune
The Ohgas are a prestigious family based on Hachioji.  The head of the family,
Mr. Nemochi Ohga, a famous wealthy man, wishes to increase his fortune
by depositing his money to an operation company. You are asked to help
Mr. Ohga maximize his profit by operating the given money during a specified
period.
From a given list of possible operations, 
you choose an operation to deposit the given fund to. 
You commit on the single operation throughout the period and
deposit all the fund to it.

Each operation specifies an annual interest rate, whether the interest
is simple or compound, and an annual operation charge.

An annual operation charge is a constant 
not depending on the balance of the fund.

The amount of interest is calculated at the end of every year, by
multiplying the balance of the fund under operation by the annual
interest rate, and then rounding off its fractional part. For compound
interest, it is added to the balance of the fund under operation, and
thus becomes a subject of interest for the following years.  For
simple interest, on the other hand, it is saved somewhere else and
does not enter the balance of the fund under operation (i.e. it is
not a subject of interest in the following years).

An operation charge is then subtracted from the balance of the fund
under operation.  You may assume here that you can always pay the
operation charge (i.e. the balance of the fund under operation is
never less than the operation charge).

The amount of money you obtain after the specified years of operation
is called ``the final amount of fund.''  For simple interest, it is
the sum of the balance of the fund under operation at the end of the
final year, plus the amount of interest accumulated throughout the
period. For compound interest, it is simply the balance of the fund
under operation at the end of the final year.
Operation companies use C, C++, Java, etc., to perform their
calculations, so they pay a special attention to their interest
rates. That is, in these companies, an interest rate is always an
integral multiple of 0.0001220703125 and between 0.0001220703125 and
0.125 (inclusive).  0.0001220703125 is a decimal representation of
1/8192. Thus, interest rates' being its multiples means that they can
be represented with no errors under the double-precision binary
representation of floating-point numbers.
For example, if you operate 1000000 JPY for five years with an annual,
compound interest rate of 0.03125 (3.125 %) and an annual operation charge of 3000 JPY, the balance changes as
follows.
The balance of the fund under operation
(at the beginning of year)
Interest
The balance of the fund under operation (at the end of year)
A
B = A × 0.03125 (and rounding off fractions)
A + B - 3000
1000000
31250
1028250
1028250
32132
1057382
1057382
33043
1087425
1087425
33982
1118407
1118407
34950
1150357
After the five years of operation, the final amount of fund is 1150357 JPY.
If the interest is simple with all othe
...(truncated)

Submitted solutions:

code_snippet: #include <iostream>
using namespace std;
int main(){
    int a, moneyF, yearL, vary, i1, i2, i3, s, moneyB1, moneyB2, risi1, risi2, moneyto, max;
    double per;
    i1 = 0;
    cin >> a;
    while(1){
        i1++;
        if(i1>a){break;}
        cin >> moneyF >> yearL >> vary;
        i2 = 0;
        max = 0;
        while(1){
            i2++;
            if(i2>vary){break;}
            cin >> s >> per >> moneyB1;
            i3 = 0;
            moneyB2 = moneyF;
            risi2 = 0;
            if(s==0){
                while(1){
                    i3++;
                    if(i3>yearL){break;}
                    risi1 = moneyB2 * per;
                    moneyB2 = moneyB2 - moneyB1;
                    risi2 = risi2 + risi1;
                }
            }
            else{
                while(1){
                    i3++;
                    if(i3>yearL){break;}
                    risi1 = moneyB2 * per;
                    moneyB2 = moneyB2 + risi1 - moneyB1;
                }
            }
            moneyto = moneyB2 + risi2;
            if(max<moneyto){max = moneyto;}
        }
        cout << max << endl;
        
        
    }
    return 0;

}
accuracy: 1
time_ms: 10
memory_kb: 1232
final_rank: 3

code_snippet: #include <iostream>
using namespace std;

int investment = 0;
double rate = 0;
int commision = 0;

int simple(int y){
	int wage = investment;
	int InterestTotal = 0;
	
	for (int i = 0; i < y; i++){
		InterestTotal += wage * rate;
		wage -= commision;
	}
	wage += InterestTotal;
	return wage;
}

int compound(int y){
	int wage = investment;

	for (int i = 0; i < y; i++){
		wage = (wage * (1+rate)) - commision;
	}

	return wage;
}

int main(){
	int m; //????????????????????°
	int Max = 0;
	cin >> m;

	for (int i = 0; i < m; i++){
		int y, n; //?????¨??´??°????¨??????°
		cin >> investment >> y >> n;

		for (int j = 0; j < n; j++){
			int type; //??????:0, ??????:1
			cin >> type >> rate >> commision;
			int tmp;

			if (type == 0){
				tmp = simple(y);
				if (Max < tmp){
					Max = tmp;
				}
			}
			else{
				tmp = compound(y);
				if (Max < tmp){
					Max = tmp;
				}
			}
		}
		cout << Max << endl;
		Max = 0;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1232
final_rank: 3

code_snippet: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int m, n, t, y;
double r, x, s;

int main(){
	cin >> m;
	while (m--){
		int ans = -1;
		cin >> s >> y >> n;
		REP(i, n){
			cin >> t >> r >> x;
			double money = s;
			if (t == 0){
				int sum = 0;
				REP(i, y){
					sum += (int)(money*r);
					money -= x;
				}
				money += sum;
			}
			else{
				REP(i, y){
					money = money + (int)(money*r) - x;
				}
			}
			ans = max(ans, (int)money);
		}
		cout << ans << endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 1232
final_rank: 3

code_snippet: #include<iostream>
#include<algorithm>

using namespace std;

int rieki(bool ri,double riritu,int kingaku, int kikan,int tesuu){
    int risi=0;
    if(ri){
        for(int i=0;i<kikan;i++){
            kingaku=kingaku*(1+riritu)-tesuu;
        }
    }else{
        for(int i=0;i<kikan;i++){
            risi+=kingaku*riritu;
            kingaku-=tesuu;
        }
    }
    return kingaku+risi;
}

int main(){
    int m;
    cin>>m;
    for(int j=0;j<m;j++){
        int kane,nen;
        cin>>kane>>nen;
        int n;
        cin>>n;
        int ans=0;
        for(int k=0;k<n;k++){
            bool r;
            double riri;
            int te;
            cin>>r>>riri>>te;
            ans=max(rieki(r,riri,kane,nen,te),ans);
        }
        cout<<ans<<endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1232
final_rank: 3

code_snippet: #include<iostream>
#include<algorithm>
using namespace std;
int maxn, n, m, y, money, money2, a, c; double b;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> money; money2 = money;
		cin >> y >> m; maxn = 0;
		for (int j = 0; j < m; j++) {
			cin >> a >> b >> c; money = money2;
			if (a == 1) {
				for (int k = 0; k < y; k++) {
					money = (double)money*(1 + b);
					money -= c;
				}
			}
			else {
				for (int k = 0; k < y; k++) {
					money += (double)(money2 - k*c)*b;
				}
				money -= y*c;
			}
			maxn = max(maxn, money);
		}
		cout << maxn << endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 1232
final_rank: 3

code_snippet: #include <iostream>
#include <algorithm>
using namespace std;

const int MAX_SIZE = 100;

int calc(int a, int y, int n, int soc[], double air[], int aoc[]) {
  int r = 0;
  for (int i = 0; i < n; ++i) {
    int A = a;
    if (soc[i] == 0) {
      int interest = 0;
      for (int j = 0; j < y; ++j) {
        interest += A * air[i];
        A -= aoc[i];
      }
      A += interest;
    } else {
      for (int j = 0; j < y; ++j) {
        A += A * air[i] - aoc[i];
      }
    }
    r = max(r, A);
  }
  return r;
}

int main() {
  int a, n, m, y;
  int soc[MAX_SIZE], aoc[MAX_SIZE];
  double air[MAX_SIZE];
  cin >> m;
  for (int i = 0; i < m; ++i) {
    cin >> a >> y >> n;
    for (int j = 0; j < n; ++j) {
      cin >> soc[j] >> air[j] >> aoc[j];
    }
    cout << calc(a, y, n, soc, air, aoc) << endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 1232
final_rank: 3

code_snippet: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;

long long int calc(long long int type, double rate, long long int decr, long long int fund, long long int year){
	if(type == 0){
		
		int interest = 0;
		
		for(int i = 0; i < year; i++){
			interest += fund * rate;
			fund -= decr;
		}
		
		fund += interest;
		
	}else if(type == 1){
		for(int i = 0; i < year; i++){
			fund *= (1 + rate);
			fund -= decr;
		}
	}
	return fund;
}

int main(){
	
	int M;
	
	cin >> M;
	
	for(int loop = 0; loop < M; loop++){
		long long int fund, year, n, max;
		cin >> fund >> year >> n;
		max = 0;
		for(int i = 0; i < n; i++){
			long long int type, decr, result;
			double rate;
			cin >> type >> rate >> decr;
			result = calc(type, rate, decr, fund, year);
			if(max < result){
				max = result;
			}
		}
		printf("%lld\n", max);
	}
	
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1224
final_rank: 2

code_snippet: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
double EPS=1e-10;
int INF=1e9;
int MOD=1000000007;
int main(){
	int m;
	cin>>m;
	while(m--){
		int n,init,type,year,comm;
		double rate;
		cin>>init>>year>>n;
		int ans=0;
		while(n--){
			cin>>type>>rate>>comm;
			int now=init;
			if(type){
				REP(i,year){
					now=now*rate+now-comm;
				}
			}else{
				int sum=0;
				REP(i,year){
					sum+=now*rate;
					now-=comm;
				}
				now+=sum;
			}
			ans=max(ans,now);
		}
		cout<<ans<<endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 1232
final_rank: 3

code_snippet: #include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
	
	int m;
	cin>>m;
	int y,n;
	long long int A;
	while(m>0){
		long long int max=0;
		cin>>A>>y>>n;
		for(int i=0;i<n;i++){
			int t,h;
			double x;
			long long int a=A;
			long long int B=0,s=0;
			cin>>t>>x>>h;
			for(int j=0;j<y;j++){
				if(t!=0){
					B=a*x;
					a=a+B-h;
				}
				else{
					B=a*x;
					a=a-h;
					s+=B;
				}
			}
			if(max<a+s)
				max=a+s;
	}
		cout<<max<<endl;
		m--;
	}
	
}
accuracy: 1
time_ms: 10
memory_kb: 1232
final_rank: 3

code_snippet: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int solve(int money,int year,int type,double per,int mine){
	if(type==1){
		rep(i,year){
			money=money+(int)( money * per);
			money-=mine;
		}
		return money;
	}
	else{
		int tmp=0;
		rep(i,year){
			tmp+=(int)( money * per);
			money-=mine;
		}
		return money+tmp;
	}

}



int main(){
	int m;

	cin>>m;

	rep(loop,m){
		int money,year,n;
		cin>>money>>year>>n;
		int type,mine;
		double per;
		int maxi=-1;
		rep(i,n){
			cin>>type>>per>>mine;
			maxi=max(solve(money,year,type,per,mine),maxi);
		}
		cout<<maxi<<endl;
	}
}

//テ・ツ債佚・ツ按ゥテ」ツδサティツ、ツ?・ツ按ゥテ」ツ?ョテ・ツ按・ テ・ツケツエテ・ツ按ゥテァツ篠?テヲツッツ偲・ツケツエテ」ツ?ョテヲツ可凝ヲツ閉ーテヲツ鳴?
accuracy: 1
time_ms: 10
memory_kb: 1232
final_rank: 3

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>

using namespace std;


typedef struct {
	int type;
	double nenri;
	double minus;
} pattern;

int rishi=0;

int sim(int year,int money,int type,double nenri,double minus) {
	int rishi=0;

	for (int i=0;i<year;i++) {
		if(type==0)
			rishi+=money*nenri;
		else
			money+=money*nenri;

		money-=minus;
	}


	return money+rishi;
}

int main(void) {

	int m;


	cin >> m;

	for(int j=0;j<m;j++) {
		int shikin;

		int years;
		int n;
		
		cin >> shikin;
		cin >> years;
		cin >> n;

		vector<int> money;
		for(int i=0;i<n;i++) {
			pattern tmp;

			cin >> tmp.type >> tmp.nenri >> tmp.minus;
			money.push_back(sim(years ,shikin, tmp.type ,tmp.nenri ,tmp.minus));
		}

		sort(money.begin(),money.end(),greater<int>() );
		//cout << money[money.size()-1] << endl;
		cout << money[0] << endl;

	}


	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1260
final_rank: 17

code_snippet: #include <cstdio>
#include <iostream>

using namespace std;

int nmoney(int s, double ratio, int cost, int pmomey, int year) {
	int nmoney;
	int total_ratio = 0;

	if (s == 0) {
		for (int i = 0; i < year; i++) {
			total_ratio += pmomey*ratio;
			pmomey -= cost;
		}
		nmoney = pmomey + total_ratio;
	} else if (s == 1) {
		for (int i = 0; i < year; i++) {
			pmomey += pmomey*ratio - cost;
		}
		nmoney = pmomey;
	}

	return nmoney;
}

int main(void) {
	int m;
	cin >> m;
	for (int i = 0; i < m; i++) {
		int pmoney;
		cin >> pmoney;

		int year;
		cin >> year;

		int n;
		int money = 0;
		cin >> n;
		for (int j = 0; j < n; j++) {
			int s, cost;
			double ratio;
			cin >> s >> ratio >> cost;
			int n;
			n = nmoney(s, ratio, cost, pmoney, year);
			if (n > money) {
				money = n;
			}
		}
		printf("%d\n", money);
	}
}
accuracy: 1
time_ms: 10
memory_kb: 1216
final_rank: 1

code_snippet: #include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>

using namespace std;
int main(){
	long long int start, temp = 0, start2 = 0;
	int year, n, y, m, i, j;
	char a;
	double x;
	int ans[100], count = 0;

	cin >> m;
	for(i = 0;i < m;i++){
		cin >> start >> year >> n;
		for(j = 0;j < n;j++){
			cin >> a >> x >> y;
			start2 = start;
			if(a == '0'){
				for(int k = 0;k < year;k++){
					temp += (int)(start2 * x);
					start2 -= y;
				}
				ans[count] = start2 + temp;
				//cout << ans[count] << " " << start2 << " " << temp << endl;
				temp = 0;
				count++;
			}
			else if(a == '1'){
				for(int k = 0;k < year;k++){
					temp += (int)(start2 * x);
					start2 = start2 + temp - y;
					temp = 0;
				}
				ans[count] = start2;
				//cout << ans[count] << " " << start2 << " " << temp << endl;
				count++;
			}
		}
		sort(ans, ans+count);
		cout << ans[count-1] << endl;
		for(int k = 0;k < count;k++){
			ans[k] = 0;
		}
		count = 0;

	}

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1256
final_rank: 16

code_snippet: #include<bits/stdc++.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int m;
	cin>>m;
	rep(z,m){
		long long money;
		int time,n;
		cin>>money>>time>>n;
		vector<long long> ans;
		long long memory=money;
		rep(u,n){
			int tax,fee;
			long double percent;
			cin>>tax>>percent>>fee;
			long long nenri=0;
			money=memory;
			rep(i,time){
				if(tax==0){//???????????´???
					nenri+=(int)money*percent;
					money-=fee;
				}else{//???????????´???
					money=(long long)money*(1+percent)-fee;
				}
			}
			if(tax==0)money+=nenri;
			ans.push_back(money);
		}
		sort(ans.begin(),ans.end());
		cout<<ans[ans.size()-1]<<endl;
	}
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1264
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

int m, n, q;
double s, y, r, d;

int main()
{
  cin >> m;

  while(m--){
    cin >> s >> y >> n;
    int res = 0;
    while(n--){
      cin >> q >> r >> d;
      double ss = s;
      if(q == 0){
        int sum = 0;
        rep(i, y){
          sum += ss * r;
          ss -= d;
        }
        maxup(res, (int)(ss + sum));
      }
      else{
        rep(i, y) ss += floor(ss * r - d);
        maxup(res, ss);
      }
    }
    cout << res << endl;
  }

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1232
final_rank: 3

code_snippet: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>

 
using namespace std;
 
#define INF 1000000000
#define EPS 1e-9
#define PI acos(-1)
 
typedef long long ll;

#define MAX_M 100

int m;
vector<ll> ans_list;

int main(){

  cin >> m;
  while(m > 0){
    m--;
    int n;
    ll money;
    ll year;
    ll ans = 0;
    cin >> money;
    cin >> year;
    cin >> n;
    while(n > 0){
      n--;
      ll mMoney = money;
      int num;
      double r;
      int mai;
      int t = 0;
      cin >> num >> r >> mai;
      if(num == 0){
	for(int i = 0; i < year; i++){
	  int B = mMoney*r/10*10;
	  t += B;
	  mMoney -= mai;
	}
	ans = max(ans, mMoney+t);
      }
      else{
	for(int i = 0; i < year; i++){
	  mMoney += -mai + mMoney*r/10*10;
	}
	ans = max(ans, mMoney);
      }
      
    }
  
    ans_list.push_back(ans);

  }

  for(int i = 0; i < ans_list.size(); i++){
    cout << ans_list[i] << endl;
  }

  return 0;

}
accuracy: 1
time_ms: 10
memory_kb: 1264
final_rank: 18

code_snippet: #include <iostream>
#include <algorithm>

using namespace std;

int tanri(int y, int A, int fee, double rate){
    int sum = 0;
    for(int i=0; i < y; i++){
        sum += (int)A*rate;
        A -= fee;
    }
    return A+sum;
}

int hukuri(int y, int A, int fee, double rate){
    for(int i=0; i < y; i++){
        A += (int)(A*rate)-fee;
    }
    return A;
}

int main(){
    int n;
    cin >> n;
    for(int p=0; p < n; p++){
        long long money;
        cin >> money;
        int y, m;
        cin >> y >> m;

        int res = 0;
        for(int i=0; i < m; i++){
            int s, fee;
            double rate;
            cin >> s >> rate >> fee;
            if(s == 0) res = max(res, tanri(y, money, fee, rate));
            else res = max(res, hukuri(y, money, fee, rate));
        }
        cout << res << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 1236
final_rank: 14

code_snippet: #include<iostream>
#include<stdio.h>
using namespace std;

int m;
int inis;
int year,n;

int type;
double ritu;
int tesu;

int main(){
	int t;
	int i,j;
	int output;
	int a,b;
	
	cin >> m;
	for( t = 0; t < m; t++ ){
		if( scanf("%d",&inis) != 1 )break;
		cin >> year >> n;
		
		output = 0;
		for( i = 0; i < n; i++ ){
			cin >> type >> ritu >> tesu;
			if( type == 0 ){
				a = inis; b = 0;
				for( j = 0; j < year; j++ ){
					b += (double)a*ritu;
					a -= tesu;
				}
				//cout << "tanri = " << a + b << endl;
			}
			else{
				a = inis; b = 0;
				for( j = 0; j < year; j++ ){
					a = (double)a*(ritu+1.0);
					a -= tesu;
				}
				//cout << "fukuri = " << a + b << endl;
			}
			output = max( a+b, output );
		}
		cout << output << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1268
final_rank: 19

code_snippet: #include <algorithm>
#include <iostream>
#include <vector>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

#define ALL(v) (v).begin(),(v).end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define REP(i,a,b) for(int i=(int)(a); i<(int)(b); ++i)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define SORT(x) sort(begin(x),end(x))
#define SELECT_SORT(x, n) sort(begin(x),begin(x)+n)
#define SWAP(type, a, b) do {type tmp = a; a = b; b = tmp;} while (0)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))

#define INF 2000000000000
#define MAX 10

#define BAR() cout << "----------------------------" << endl;
#define DUMP(v) (cerr << #v << ": " << v << endl)
#define PRINT(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;


int main()
{
	int m,money,y,n;
	int a,c;
	long double risi;
	cin >> m;
	while(m)
	{
		cin >> money;
		cin >> y;
		cin >> n;

		int ans=0;

		int moneytmp = money;
		rep(i,n){
			cin >> a >> risi >> c;
			int tmpRisi=0;
			int anstmp=0;

			moneytmp = money;   
			if(!a){
				rep(i,y)
				{
					tmpRisi += moneytmp*risi;
					moneytmp -= c;  
				}
				anstmp = moneytmp + tmpRisi;
			}else{
				rep(i,y)
				{
					moneytmp +=moneytmp*risi-c;
				}
				anstmp=moneytmp;
			}
			ans = max(ans, anstmp);
		}
		cout << ans << endl;
		m--;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1236
final_rank: 14

code_snippet: #include<iostream>

using namespace std;

template<typename T> inline void chmax(T& t, T f){if(t < f)t = f;}

int compound(int A, int year, double rate, int charge){
    int res = A;
    while(year--){
        int B = res * rate;
        res += B - charge;
    }
    return res;
}

int simple(int A, int year, double rate, int charge){
    int res1 = A, res2 = 0;
    while(year--){
        int B = res1 * rate;
        res2 += B;
        res1 -= charge;
    }
    return res1 + res2;
}

int main(){
    int m;
    cin >> m;
    while(m--){
        int init, year, n;
        cin >> init >> year >> n;
        int ans = 0;
        while(n--){
            int k, charge; double rate;
            cin >> k >> rate >> charge;
            chmax(ans, k? compound(init, year, rate, charge): simple(init, year, rate, charge));
        }
        cout << ans << '\n';
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1232
final_rank: 3