akhauriyash/Code-Regression huggingface dataset:
import java.util.* ;
class Main {
  public static void main(String[] args) {
    
    Scanner scan = new Scanner(System.in);
	int A = scan.nextInt();
    int B = scan.nextInt();
    int C =scan.nextInt();
    int D = scan.nextInt();
    
    if(A+B < C+D){
      System.out.println("Right");
    }else if(A+B == C+D){
      System.out.println("Balanced");
    }else{
      System.out.println("Left");
    }
  }
}


Measured memory_bytes: 22868
from itertools import product
N, K = map(int, input().split())
*A, = map(int, input().split())

ans = 10**18
for P in product(range(2), repeat=N-1):
    if sum(P) < K-1:
        continue
    res = 0
    base = A[0]
    for i in range(N-1):
        if P[i]:
            if A[i+1] <= base:
                res += (base+1 - A[i+1])
                base += 1
            else:
                base = A[i+1]
        else:
            if base < A[i+1]:
                res += (A[i+1] - base)
                base = A[i+1]
    ans = min(ans, res)
print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
   string S,T; cin>>S>>T;
   int ans=0;
   int N=S.size();
   for(int i=0;i<N;i++){
       if(S[i]!=T[i])ans++;
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 3908
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================

int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	ll N;
	cin >> N;
	vll C(N), S(N), F(N);
	for (int i = 0; i < N-1; i++)
	{
		cin >> C[i] >> S[i] >> F[i];
	}


	for (int j = 0; j < N-1; j++)
	{

		ll now = 0;
		for (int i = j; i < N - 1; i++)
		{
			if (now <= S[i])
			{
				now = S[i] + C[i];
				continue;
			}
			else
			{
				if ((now - S[i]) % F[i] == 0)
				{
					now += C[i];
				}
				else
				{
					now += F[i] - (now - S[i]) % F[i] + C[i];
				}
			}


		}
		cout << now << endl;

	}

	cout << 0 << endl;


}





Measured memory_bytes: 256
public partial class IntroductionToProgramming{
	public static void Main(){
		string[] line = System.Console.ReadLine().Split(' ');
		int a = int.Parse(line[0]);
		int b = int.Parse(line[1]);

		int d = a / b;
		int r = a % b;
		decimal f = (decimal)a / (decimal)b;

		
		System.Console.WriteLine(d.ToString() + " " + r.ToString() + " " + f.ToString());
	}
}

Measured memory_bytes: 5656
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    int q;
    cin >> q;

    vs32 t(q), f;
    vector<char> c;

    int len = 0;
    rep (i, q)
    {
        cin >> t[i];
        if (t[i] == 2)
        {
            int tempf;
            char tempc;
            cin >> tempf >> tempc;
            f.push_back(tempf);
            c.push_back(tempc);
            ++len;
        }
    }

    string ans(s.size() + len, '\0');
    bool inverted = false;
    int cnt = 0;
    int front = 0;
    int back = s.size() + len - 1;
    for (int i = q - 1; i >= 0; --i)
    {
        if (t[i] == 1)
        {
            inverted = (inverted ? false : true);
        }
        else
        {
            if (f[len - cnt - 1] == 1)
            {
                if (inverted) { ans[back] = c[len - cnt - 1]; --back; }
                else { ans[front] = c[len - cnt - 1]; ++front; }
            }
            else
            {
                if (inverted) { ans[front] = c[len - cnt - 1]; ++front; }
                else { ans[back] = c[len - cnt - 1]; --back; }
            }
            ++cnt;
        }
    }

    rep (i, s.size())
    {
        if (inverted) { ans[back] = s[i]; --back; }
        else { ans[front] = s[i]; ++front; }
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3012
from copy import copy

n = int(input())
t_list = list(map(int, input().split()))
m = int(input())
px_list = [list(map(int, input().split())) for _ in range(m)]

for px in px_list:
    p, x = px
    tmp_list = copy(t_list)
    tmp_list[p - 1] = x
    print(sum(tmp_list))


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

int n, m, x;

int main() {
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  rep (i, n) {
    cin >> c[i];
    rep (j, m) {
      cin >> a[i][j];
    }
  }
  queue<vector<int>> que;
  vector<int> firstV(m+2, 0);//cost, level, knowledge
  firstV[1] = -1;
  que.push(firstV);
  vector<int> v;
  while (true) {
    v = que.front();
    que.pop();
    if (v[1] == n-1) {
      que.push(v);
      break;
    }
    v[1]++;
    que.push(v);
    v[0] += c[v[1]];
    rep (i, m) {
      v[i+2] += a[v[1]][i];
    }
    que.push(v);
  }
  bool skilled = true;
  int minimum = 1200001;
  while (que.size() != 0) {
    v = que.front();
    que.pop();
    skilled = true;
    rep (i, m) {
      if (v[i+2] < x) {
        skilled = false;
      }
    }
    if (skilled) minimum = min(minimum, v[0]);
  }
  if (minimum == 1200001) minimum = -1;
  cout << minimum << endl;
  return 0;
}


Measured memory_bytes: 3876
k , a , b = map(int,input().split())
if a + 2 >= b:
    print(k+1)
elif a + 2 < b:
    if a > k - 1:
        print(k+1)
    elif a <= k - 1:
        s = k - (a - 1)
        if s % 2 == 0:
            print(b + (s//2 - 1)*(b-a))
        elif s % 2 == 1:
            print(b + (s//2 - 1)*(b-a) + 1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	ll min = 0;
	ll max = 0;

	REP(i, n-1){
		min += a;
	}
	min += b;

	REP(i, n-1){
		max += b;
	}
	max += a;

	ll ans = max - min + 1;
	cout << (ans > 0 ? ans : 0) << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

#define MAX_V (10000*2)

struct edge{int to,cap,rev;};

vector<edge> G[MAX_V];  //グラフのパス
int level[MAX_V];       //始点からの距離
int iter[MAX_V];        //どこまで調べたか

// fromからtoへ向かう、容量capの辺をグラフに追加する
void add_edge(int from,int to,int cap){
    G[from].push_back(  (edge){ to  ,cap,(int)G[to  ].size()   }  );
    G[to  ].push_back(  (edge){ from,0  ,(int)G[from].size()-1 }  );
}

// sからの最短距離をBFSで計算する
void bfs(int s){
    rep(i,MAX_V)level[i]=-1;
    queue<int> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()){
        int v=que.front();que.pop();
        
        rep(i,G[v].size()){
            edge &e=G[v][i];
            if(e.cap>0 && level[e.to]<0){
                level[e.to]=level[v]+1;
                que.push(e.to);
            }
        }
    }
}

//増加パスをDFSで探す
int dfs(int v,int t,int f){
    if(v==t)return f;
    for(int &i=iter[v];i<G[v].size();i++){
        edge &e=G[v][i];
        if(e.cap>0&&level[v]<level[e.to]){
            int d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}

// sからtへの最大流を求める
int max_flow(int s,int t){
    if(s==t)return INF;
    int flow=0;
    for(;;){
        bfs(s);
        if(level[t]<0)return flow;
        memset(iter,0,sizeof(iter));
        int f;
        while((f=dfs(s,t,INF))>0){
            flow+=f;
        }
    }
}

int h,w;

int f(ll y,ll x){
    return y*w+x;
}

int main(){
    cin>>h>>w;
    vector<string> vs(h);
    rep(i,h)cin>>vs[i];
    
    pii s,t;
    rep(i,h)rep(j,w){
        if(vs[i][j]=='S')s = pii(i,j);
        if(vs[i][j]=='T')t = pii(i,j);
    }
    
    rep(i,h){
        rep(j,w){
            if(vs[i][j]=='o')
                add_edge(f(i,j)+h*w,f(i,j),1);
        }
    }
    rep(i,h){
        rep(j,w){
            if(vs[i][j]=='.')continue;
            for(ll k=i+1;k<h;k++){
               if( vs[k][j]!='.' ){
                    add_edge(f(i,j),f(k,j)+h*w,INF);
                    add_edge(f(k,j),f(i,j)+h*w,INF);
                }
            }
            for(ll l=j+1;l<w;l++){
                if( vs[i][l]!='.' ){
                    add_edge(f(i,j),f(i,l)+h*w,INF);
                    add_edge(f(i,l),f(i,j)+h*w,INF);
                }
            }
        }
    }
    int res = max_flow(f(s.first,s.second), f(t.first,t.second)+h*w);
    if(res>=INF)cout<<-1<<endl;
    else cout<<res<<endl;
}







Measured memory_bytes: 63104
#include <bits/stdc++.h>
using namespace std;
#define rep(i,A) for(int i = 0;i < A;i++)

int main() {
  int A;
  cin >> A;
  int B[A];
  int C = 1;
  int count = 0;
  rep(i,A){
    cin >> B[i];
  }
  sort(B,B + A);
  rep(i,A){
    if(B[i] == B[C]){
      count++;
    }
    C++;
  }
  if(count > 0){
    cout << "NO" << endl;
  }
else{
  cout << "YES" << endl;
}
}


Measured memory_bytes: 4388
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int A,B,ans;
  cin>>A>>B;
  
  if((A+B)%2==0) cout<<(A+B)/2<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
char code[]={'I','V','X','L','C','D','M'};
int value[]={1,5,10,50,100,500,1000};
int main(){
  int i,j,sum,prev;
  char str[101];
  while(scanf("%s",str)!=EOF){
    for(i=0,sum=0,prev=1000;str[i];i++){
      for(j=0;j<7;j++)
    if(code[j]==str[i]) break;
      if(prev<value[j]){
    sum+=value[j]-prev*2;
      }else{
    sum+=value[j];
      }
      prev=value[j];
    }
    printf("%d\n",sum);
  }
  return 0;
}

Measured memory_bytes: 540
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<cctype>
#include<string.h>
#include <stdlib.h>

#define PI 3.1415926
void swap(int* x, int* y) {
	int a = *x;
	int b = *y;
	*x = b;
	*y = a;
}
int factorial(int n);
int sum(int n, int*);
int ave(int n, int*);
int min(int n, int*), min(int n, int m);
int max(int n, int*), max(int n, int m);

int main() {
	int W, H, N, X, Y;
	int x = 0, y = 0;
	int ans = 0;
	scanf("%d %d %d", &W, &H, &N);
	scanf("%d %d", &x, &y);
	for (int i = 2; i <= N; i++) {
		//printf("%d %d %d\n",x,y,ans);
		scanf("%d %d", &X, &Y);
		ans += abs(x - X);
		ans += abs(y - Y);
		if ((X > x && Y > y) | (X < x && Y < y)) {
			ans -= min(abs(x - X), abs(y - Y));
		}
		x = X;
		y = Y;
		
	}
	printf("%d\n", ans);
	return 0;
}

int factorial(int n) {
	if (n > 0) {
		return n * factorial(n - 1);
	}
	else {
		return 1;
	}
}
int sum(int n, int *all) {
	int total = 0;
	for (int i = 0; i < n; ++i) {
		total += all[i];
	}
	return total;
}
int ave(int n, int *all) {
	int total = 0;
	for (int i = 0; i<n; ++i) {
		total += all[i];
	}
	return total / n;
}
int min(int n, int *all) {

	int min = all[0];
	for (int i = 1; i < n; ++i) {
		if (all[0] > all[i]) {
			min = all[i];
		}
	}
	return min;
}
int max(int n, int *all) {
	int max = all[0];
	for (int i = 1; i<n; ++i) {
		if (all[0]<all[i]) {
			max = all[i];
		}
	}
	return max;
}
int max(int n, int m) {
	if (n >= m) {
		return n;
	}
	else {
		return m;
	}
}
int min(int n, int m) {
	if (n >= m) {
		return m;
	}
	else {
		return n;
	}
}

Measured memory_bytes: 2592
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

bool isPrime(long long num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (long long i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(void){
    int Q; cin >> Q;
    int l[Q], r[Q], mx=0; REP(i,Q){cin >> l[i] >> r[i]; chmax(mx, r[i]);}
    int p[mx+1]; REP(i,mx+1) p[i] = 0;
    p[2] = 1;
    for(ll i=3; i<mx+1; i+=2){
        if(isPrime(i)) p[i] = 1;
    }
    int n[mx+1];
    REP(i,mx+1){
        if(p[i] && p[(i+1)/2]) n[i] = 1;
        else n[i] = 0;
    }
    int sum[mx+1]; sum[0] = 0;
    REP(i,mx) sum[i+1] = sum[i] + n[i+1];

    REP(i,Q) cout << sum[r[i]] - sum[l[i]] + n[l[i]] << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define s(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
int main(){
  int N;
  string s;
  cin >> N>>s;
  int ans = 0;
  for(int i =0;i<=999;i++){
    bool a =false;
    bool b= false;
    bool c = false;
    rep(j,N){
      int ichi = i%10;
      int juu = (i/10)%10;
      int hyaku = i/100;
      if(a&&b)if(s[j]-'0'==ichi)c=true;
      if(a&&!b)if(s[j]-'0'==juu)b=true;
      if(!a)if(s[j]-'0'==hyaku)a=true;
    }
    if(a&&b&&c)ans++;
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;


int main() {
    int N, M; cin >> N >> M;
    priority_queue<pair<int, int>> card_numbers;
    for (int i = 0; i < N; i++) {
        int A; cin >> A;
        card_numbers.push(make_pair(A, 1));
    }
    for (int i = 0; i < M; i++) {
        int B, C; cin >> B >> C;
        card_numbers.push(make_pair(C, B));
    }

    long long ans = 0;
    for (int i = 0; i < N; i++) {
        auto p = card_numbers.top();
        card_numbers.pop();
        ans += p.first;
        if (p.second > 1) {
            p.second--;
            card_numbers.push(p);
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
using namespace std;

int main(void)
{
    long long N, P;
    cin >> N >> P;

    map<long long, long long> m;

    for (long long i = 2; i * i <= P; i++)
    {
        while (P % i == 0)
        {
            m[i]++;
            P /= i;
        }
    }
    if(P != 1) m[P]++;
    
    long long ans = 1;

    for (auto i = m.begin(); i != m.end(); i++)
    {
        for (long long j = 0; j < i->second / N; j++)
        {
            ans *= i->first;
        }
        
    }    
    
    cout << ans << endl;
}


Measured memory_bytes: 3628
// A - Tenki
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	string s, t;
	cin >> s >> t;
	int ans = 0;
	for (int i = 0; i < 3; i++) ans += (s[i] == t[i] ? 1 : 0);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int A,B,C,X,Y; R(A,B,C,X,Y);
    if(B>C*2)B=C*2;
    if(A>C*2)A=C*2;
    if(C*2<=A+B)W(C*2*min(X,Y)+(X-min(X,Y))*A+(Y-min(X,Y))*B);
    else W(A*X+B*Y);
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

vector<long long int> v[110000];

int main(){
    int N, M;
    cin >> N >> M;
    for(int i = 0; i < N; i++){
        long long int A, B;
        cin >> A >> B;
        v[A].push_back(B);
    }
    long long int ans = 0;
    priority_queue<long long int> que;
    for(int i = 1; i <= M; i++){
        for(long long int num : v[i]){
            que.push(num);
        }
        if(que.size() > 0){
            ans += que.top();
            que.pop();
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5888
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if op == "?":
        break
    if op=="+":
        print(a+b)
    if op=="-":
        print(a-b)
    if op=="*":
        print(a*b)
    if op=="/":
        print(a//b)


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;

long long MOD = 1e9+7;
int MAX_INT = 1e9;

// 最大公約数
long long gcd(long long a, long long b){
  if(b == 0) return a;
  return gcd(b, a % b);
}
// 最小公倍数
long long lcm(long long a, long long b) {
  return a / gcd(a, b) * b;
}

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  long long N;
  cin >> N;
  vector<long long> L(N);
  for(int i = 0; i < N; ++i) {
    cin >> L[i];
  }

  // sort(L.begin(), L.end());

  long long ans = 0;
  if(N < 3) {
    cout << 0 << endl;
    return 0;
  }

  for(int i = 0; i < N; ++i) {
    for(int j = i + 1; j < N; ++j) {
      for(int k = j + 1; k < N; ++k) {
        if(L[i] != L[j] && L[j] != L[k] && L[k] != L[i]) {
          long long len = L[i] + L[j] + L[k];
          long long max_len = max(L[i], max(L[j], L[k]));
          long long tmp = len - max_len;

          if(max_len < tmp) {
            // cout << i+1 << " : " << j+1 << " : " << k+1 << endl;
            ans++;
        }
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3648
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.math.BigDecimal;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            out.println((n-1)*(m-1));
            
        }
    }


    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

Measured memory_bytes: 21460
'''     ░░█ ▄▀█ █   █▀ █░█ █▀█ █▀▀ █▀▀   █▀█ ▄▀█ █▀▄▀█  
        █▄█ █▀█ █   ▄█ █▀█ █▀▄ ██▄ ██▄   █▀▄ █▀█ █░▀░█     '''


# [temp1.py] => [29-07-2020 @ 10:25:10] 
# Author & Template by : Udit "luctivud" Gupta
# https://www.linkedin.com/in/udit-gupta-1b7863135/


import math;   from collections import *
import sys;    from functools import reduce
import time;   from itertools import groupby

# sys.setrecursionlimit(10**6)

def input()         : return sys.stdin.readline()
def get_ints()      : return map(int, input().strip().split())
def get_list()      : return list(get_ints())
def get_string()    : return list(input().strip().split())
def printxsp(*args) : return print(*args, end="")
def printsp(*args)  : return print(*args, end=" ")


DIRECTIONS = [(+0, +1), (+0, -1), (+1, +0), (+1, -1)] 
NEIGHBOURS = [(-1, -1), (-1, +0), (-1, +1), (+0, -1),\
              (+1, +1), (+1, +0), (+1, -1), (+0, +1)]


CAPS_ALPHABETS = {chr(i+ord('A')) : i for i in range(26)}
SMOL_ALPHABETS = {chr(i+ord('a')) : i for i in range(26)}
INF = float('inf')


# Custom input output is now piped through terminal commands.
# for _test_ in range(int(input())): 
input()
s = input()

print("Yes" if s.count('R') > s.count('B') else "No")





# print("Time Elapsed: {}".format(float(S34p-S34t)))


Measured memory_bytes: 9384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int, int>;

int main() {
  int n; cin >> n;
  int keta = 0;
  int sn = n;
  while (sn > 0) {
    keta += sn%10;
    sn /= 10;
  }

  if (n%keta == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
typedef  long long ll;
using namespace std;
const int maxn = 2e4 + 100;
const int inf = 2e9;
ll a[maxn], b[maxn];
ll dp[maxn];
int main() {
	ios::sync_with_stdio(0);
	ll h, n;
	cin >> h >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i] >> b[i];
	for (int i = 1; i <= 2e4; i++)
		dp[i] = inf;
	for (int i = 1; i <= n; i++) {
		for (int j = a[i]; j <= 2e4; j++) {
			dp[j] = min(dp[j], dp[j - a[i]] + b[i]);
		}
	}
	ll ans = inf;
	for (int i = h; i <= 2e4; i++)
		ans = min(ans, dp[i]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
var
	N,i:Longint;
	A:Array[1..100000]of int64;
	ret:int64;
begin
	read(N);
	for i:=1 to N do begin
		read(A[i]);
		if A[i]=0 then begin
			writeln(0);
			exit;
		end;
	end;
	ret:=1;
	for i:=1 to N do begin
		if A[i]>1000000000000000000 div ret then begin
			writeln(-1);
			exit;
		end;
		ret:=ret*A[i];
	end;
	writeln(ret);
end.


Measured memory_bytes: 1384
#include <iostream>
#include<vector>
#include<map>
#include<string>
#include<stdio.h>
#include<math.h>
#include <algorithm>

using namespace std;

int main(void) {
	
	int a, b, c;
	cin >> a >> b >> c;
	int sum = 0;

	vector<int> vi;
	vi.push_back(a);
	vi.push_back(b);
	vi.push_back(c);

	sort(vi.begin(), vi.end());


	sum += vi[0];
	sum += vi[1];

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct Edge {
	int src;
	int dst;
	int cost;
};

int main()
{
	int N, M, P;
	cin >> N >> M >> P;

	vector<vector<Edge>> g(N);

	for (int i = 0; i < M; ++i) {
		int A, B, C;
		cin >> A >> B >> C;
		--A;
		--B;
		Edge e;
		e.src = A;
		e.dst = B;
		e.cost = P - C;
		g[A].push_back(e);
	}

	const long long INF = 1LL << 60;
	vector<long long> d(N,INF);
	d[0] = 0;

	for (int k = 0; k < 4 * N; ++k) {
		for (const auto &edges : g) {
			for (const auto &e : edges) {
				d[e.dst] = min(d[e.dst], d[e.src] + e.cost);
			}
		}
	}

	long long ans1 = -d[N - 1];

	for (int k = 0; k < 4 * N; ++k) {
		for (const auto &edges : g) {
			for (const auto &e : edges) {
				d[e.dst] = min(d[e.dst], d[e.src] + e.cost);
			}
		}
	}

	long long ans2 = -d[N - 1];

	if (ans2 > ans1) {
		cout << -1 << endl;
	}
	else if (ans2 < 0) {
		cout << 0 << endl;
	}
	else {
		cout << ans2 << endl;
	}
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void) {
	int numlist[5];
	int num;
	int i,j;
	int onenum;
	int waru;
	int did=0;
	char out;
	while(scanf("%d",&num)==1) {
		if(did)puts("");
		waru=10000;
		for(i=0;i<5;i++) {
			numlist[i]=(num/waru)%10;
			waru/=10;
		}
		for(i=0;i<8;i++) {
			for(j=0;j<5;j++) {
				if(i==0) {
					if(numlist[j]<5)out='*';
					else out=' ';
				} else if(i==1) {
					if(numlist[j]>=5)out='*';
					else out=' ';
				} else if(i==2) {
						out='=';
				} else {
					if(numlist[j]%5==i-3)out=' ';
					else out='*';
				}
				putchar(out);
			}
			puts("");
		}
		did=1;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

int N,a[200001];
bool b[200001];

bool check(int x){
	for(int i=1;i<=(N<<1)-1;++i)b[i]=(a[i]<=x);
	for(int i=0;i<N;++i){if(b[N-i]==b[N-i-1])return b[N-i];if(b[N+i]==b[N+i+1])return b[N+i];}
	return b[1];
}

int main(){
	scanf("%d",&N);for(int i=1;i<=(N<<1)-1;++i)scanf("%d",a+i);
	int l=1,r=(N<<1)-1,m;
	while(l<r)if(check(m=l+r>>1))r=m;else l=m+1;
	printf("%d",l);
}

Measured memory_bytes: 1280
#include<iostream>

using namespace std;
int m[4][2]={
    0,1,1,0,0,-1,-1,0
};
int a[10010],g[110][110];
int main()
{
    int t,i,j,h,w,n;
    cin>>h>>w>>n;
    for (i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int x=1,y=0;
    t=0;
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=a[i];j++)
        {
            x+=m[t][0],y+=m[t][1];
            if (x>h||x<1||y>w||y<1||g[x][y])
            {
                x-=m[t][0],y-=m[t][1];
                t++;
                t%=4;
                x+=m[t][0],y+=m[t][1];
            }
            g[x][y]=i;
        }
    }
    for (i=1;i<=h;i++)
    {
        for (j=1;j<=w;j++)
        {
            cout<<g[i][j]<<' ';
        }
        cout<<endl;
    }
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
    int n, a, b, j;
    ll k;

    cin >> n >> k;
    vector<ll> v(100001);

    for(int i = 0; i < n; i++){
        cin >> a >> b;
        v[a] += b;
    }

    j = 0;
    while(1){
        if(v[j] != 0) k -= v[j];
        if(k <= 0) break;
        j++;
    }

    cout << j;
}


Measured memory_bytes: 4040
N, X, Y = map(int, input().split())

ans = [0]*(N-1)

for i in range(1, N):
    for j in range(i+1, N+1):
        k = min(abs(j-i), abs(X-i)+1+abs(Y-j), abs(Y-i)+1+abs(X-j))
        ans[k-1] += 1

for v in ans:
    print(v)

Measured memory_bytes: 47580
#include <bits/stdc++.h>

#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;

double dp[301][301][301];

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12);
    cin.tie(nullptr);

    double N;
    cin >> N;

    int c[3] = {0, 0, 0};
    forn(i, N) {
        int a;
        cin >> a;
        c[a - 1]++;
    }

    int pieces = c[0] + 2 * c[1] + 3 * c[2];
    for (int s = 1; s <= pieces; s++) {
        for (int i = 0; i <= s; i++) {
            for (int j = 0; i + 2 * j <= s; j++) {
                int k = (s - i - 2 * j) / 3;
                if (i + j + k == 0 || i + j + k > N)
                    continue;
                double p[4] = {
                    (N - i - j - k) / N,
                    i / N,
                    j / N,
                    k / N,
                };
                double& E = dp[i][j][k];
                E = 1;
                if (i > 0)
                    E += p[1] * dp[i - 1][j][k];
                if (j > 0)
                    E += p[2] * dp[i + 1][j - 1][k];
                if (k > 0)
                    E += p[3] * dp[i][j + 1][k - 1];
                E /= 1 - p[0];
            }
        }
    }

    cout << dp[c[0]][c[1]][c[2]] << endl;
}


Measured memory_bytes: 213248
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;



int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n){ cin>>a[i]; }
  rep(i,n-1){ a[i+1] += a[i]; }
  ll ans=longinf;

  for(int i=0; i<n-2; i++){
    vector<ll> v[4];
    if(i==0){ continue; }
    int j = lower_bound(a.begin(),a.end(),a[i]/2)-a.begin();
    int k = lower_bound(a.begin(),a.end(),(a[i]+a[n-1])/2)-a.begin();
    if(j<i){
      v[0].push_back(a[j]); v[0].push_back(a[i]-a[j]);
      v[1].push_back(a[j]); v[1].push_back(a[i]-a[j]);
    }
    if(j>0){
      v[2].push_back(a[j-1]); v[2].push_back(a[i]-a[j-1]);
      v[3].push_back(a[j-1]); v[3].push_back(a[i]-a[j-1]);
    }
    if(n-1!=k){
      v[0].push_back(a[k]-a[i]); v[0].push_back(a[n-1]-a[k]);
      v[2].push_back(a[k]-a[i]); v[2].push_back(a[n-1]-a[k]);
    }
    if(k-1>i){
      k--;
      v[3].push_back(a[k]-a[i]); v[3].push_back(a[n-1]-a[k]);
      v[1].push_back(a[k]-a[i]); v[1].push_back(a[n-1]-a[k]);
    }
    rep(p,4){
      sort(v[p].begin(),v[p].end());
      if((int)v[p].size()==4){ ans=min(ans,v[p][3]-v[p][0]); }
    }
  }
  cout<<ans<<endl;
  return 0;
}
  


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,s,n) for(int i = s; i < (int)(n); i++)

vector<ll>Sieve(int n){
  vector<ll>table(n+1,1);
  for(long long i = 2;i <= n;i++){
    if(table[i] == 1){
      ll j = i;
      while(j <= n){
        int now = j,cnt = 0;
        while(now%i == 0){
          now /= i;
          cnt++;
        }
        table[j] *= (cnt+1);
        j += i;
      }
    }
  }
  return table;
}

int main() {
  int n;
  cin >> n;
  vector<ll>table;
  table = Sieve(n);
  ll ans = 0;
  rep(i,1,n+1){
    ans += i*table[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 81396
#include <iostream>
using namespace std;

bool IsPrime(int n);
bool BinarySearch(int target, int ar[], int array_num);

int main()
{
	const int MAX_N = 256;
	int n[MAX_N], list[123456/2], listnum=0, max=0, min=123456;
	int i=0, count=0;

	while(i<256){
		cin >> n[i];
		if(n[i] == 0) break;
		if(max<n[i]) max = n[i];
		if(n[i]<min) min = n[i];
		i++;
	}
	if(min==1){
		list[listnum] = 2;
		listnum++;
	}
	for(int j=(min+1)%2==0?min+2:min+1; j<max*2; j+=2){
		if(IsPrime(j)){
			list[listnum]=j;
			listnum++;
		}
	}
	for(int j=0; j<i; j++){
		if(n[j] == 1){
			cout << 1 << endl;
			continue;
		}
		count=0;
		for(int k=((n[j]+1)%2==0)?n[j]+2:n[j]+1; k<=n[j]*2; k+=2){
			if(!BinarySearch(k, list, listnum))continue;
			count++;
		}
		cout << count << endl;
	}
	return 0;
}

bool BinarySearch(int target, int ar[], int array_num)
{
	int L=0, R=array_num-1, M;
	while(L<=R){
		M = (L+R)/2;
		if(ar[M] == target) return true;
		else if(ar[M]<target)L=M+1;
		else R=M-1;
	}
	return false;
}

bool IsPrime(int n){
    int i;
    if(n < 2)
        return 0;
    else if(n == 2)
        return 1;
    if(n%2 == 0)
        return 0;
    for(i=3; i<=n/i; i+=2)
         if(n%i == 0)
            return false;
    return true;
}

Measured memory_bytes: 1252
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val n = nextInt()
    val aa = listOfInt()
    val rates = mutableSetOf<String>()

    var freeColors = 0

    aa.forEach {
        when {
            it < 400 -> rates.add("Grey")
            it < 800 -> rates.add("Brown")
            it < 1200 -> rates.add("Green")
            it < 1600 -> rates.add("LightBlue")
            it < 2000 -> rates.add("Blue")
            it < 2400 -> rates.add("Yellow")
            it < 2800 -> rates.add("Orange")
            it < 3200 -> rates.add("Red")
            else -> freeColors++
        }
    }

    println("${Math.max(rates.size, 1)} ${rates.size + freeColors}")
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 36036
n,m = gets.split.map(&:to_i)
A = Array.new(n).map{Array.new(m)}
b = Array.new(m)
n.times do |i|
    A[i] = gets.split.map(&:to_i)
end
m.times do |i|
    b[i] = gets.to_i
end
n.times do |i|
    x = 0
    m.times do |j|
        x += A[i][j] * b[j]
    end
    puts x
end


Measured memory_bytes: 7056
n = int(input())
L = list(map(int, input().split()))

import itertools
cnt = 0
for s, t, u in itertools.combinations(L, 3):
    if (s != t) and (t != u) and (u != s):
        if (s+t > u) and (t+u > s) and (s+u > t):
            cnt += 1

print(cnt)

Measured memory_bytes: 9208
#include <bits/stdc++.h>

 using namespace std;

int main() {
int M, D; cin >> M >> D;
int ans = 0;
for (int m = 1; m <= M; ++m) {
for (int d = 10; d <= D; ++d) {
 int d_1 = d % 10, d_10 = d / 10;
 if (d_1 >= 2 && d_10 >= 2 && d_1 * d_10 == m) {
 ++ans;
 }
 }
 }
 cout << ans << endl;
 }


Measured memory_bytes: 256
#include<stdio.h>
int main() {
    int k, a, b, found = 0;
    scanf("%d", &k);
    scanf("%d %d", &a, &b);
    for (int i = a; i <= b; i++)
    {
        if (i % k == 0)
        {
            found = 1;
        }
    }
    if (found)
    {
        printf("OK\n");
    }
    else
    {
        printf("NG\n");
    }



    return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<queue>
#include<algorithm>
#include<stack>
#include<vector>
#include<string>
using namespace std;


int N, K, L[50110], R[50110], count;
char S[100100];

int main()
{
	
	cin >> N >> K;
	::count = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> S[i];
		if (S[i] == '0')
		{
			if (i == 0)
			{
				L[::count] = i;
			}
			else if (S[i - 1] == '1')
			{
				L[::count] = i;
			}
			
			if (i == N - 1)
			{
				R[::count] = i;
				::count++;
			}
		}

		else
		{
			if (S[i - 1] == '0')
			{
				R[::count] = i - 1;
				::count++;
			}
		}
	}


	

	if (::count <= K)
		cout << N;

	else
	{
		int ans = 0;
		for (int i = 0; i < ::count - K + 1; i++)
		{
			if (i == 0)
			{
				ans = L[K + i];
			}
			else if (i == ::count - K)
			{
				int tmp = N - 1 - R[::count - K - 1];
				
				if (tmp > ans)
					ans = tmp;
			}

			else
			{
				int tmp = L[K + i] - R[i - 1] - 1;
				if (tmp > ans)
					ans = tmp;
			}
		}

		cout << ans;
	}

	return 0;
}

Measured memory_bytes: 768
# include <bits/stdc++.h>

# define F first    
# define S second
      
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector

# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right  

using namespace std;

typedef pair <int, int> pii; 
typedef long long ll;
typedef long double ld;

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;

inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {   
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
int n;

int s[Sz], f[Sz], c[Sz];

int ans[Sz];

int main() 
{
  Read_rap (); 
  cin >> n;
  for (int i = 1; i < n; i++)
  	cin >> c[i] >> s[i] >> f[i];
  for (int i = n; i >= 1; i--) {
  	int t = 0;     
  	for (int j = i; j < n; j++) {
  		t = max (t, s[j]);
  		t = max (t, ((t + f[j] - 1) / f[j]) * f[j]);
  		t += c[j];
  	}        
  	ans[i] = t;
  }                       
  for (int i = 1; i <= n; i++)
  	cout << ans[i] << endl;
     

  return 0;
} 










// Coded by Z..

Measured memory_bytes: 6400
import Control.Monad
import Control.Monad.ST
import Data.List
import Control.Monad.Trans.State.Strict
import Data.Char (isSpace)
import Data.Array.Unboxed
import Data.Array.ST

import qualified Data.ByteString.Char8 as B

type Parser a = StateT B.ByteString Maybe a

parseInt :: Parser Int
parseInt = StateT (B.readInt . B.dropWhile isSpace)

parseInt2 :: Parser (Int,Int)
parseInt2 = liftM2 (,) parseInt parseInt

main = do
    (n:h:_)<-map read.words<$>getLine::IO[Int]
    abs<-unfoldr (runStateT parseInt2) <$> B.getContents::IO[(Int,Int)]
    --
    print $ solve h abs
--
solve h abs = case f1 of
    Just x -> x+1
    Nothing -> (h - last bsums + maxa -1) `div` maxa + length bsums
    where
        maxa = maximum $ map fst abs
--        maxaminb = minimum $ map snd $ filter (\(a,_)->a==maxa) abs
        bcs = sortBy (flip compare) $ filter (>=maxa) $ map snd abs
        bsums = scanl1 (+) bcs
        f1 = findIndex (>=h) bsums


Measured memory_bytes: 21884
#include <bits/stdc++.h>
using namespace std;

#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const ll mod = 1000000007;

vector<ll> S;
const ll inf = 1LL << 62;
ll difs[2];
vi failures[2];
int N;

bool valid(int from, int to, int col) {
	if (to - from <= 1) return true;
	return failures[col][to-1] == failures[col][from];
}

vector<ll> mem[2];
ll rec(int at, int col) {
	assert(at != N);
	ll& out = mem[col][at];
	if (out != -1) return out;
	int ind = (int)(lower_bound(all(S), S[at] + difs[col]) - S.begin());
	if (!valid(at+1, ind, !col)) return out = 0;
	if (ind == N) return out = 1;
	ll pos = S[ind], prev = S[ind-1];
	ll next = (ind+1 == N ? inf : S[ind+1]);
	ll res = 0;
	if (ind == at + 1) {
		res += rec(ind, col);
		res += rec(ind, !col);
	}
	else {
		if (col == 1 && next - prev >= difs[!col]) {
			res += rec(ind, col);
		}
		if (col == 0) {
			if (pos - prev >= difs[!col])
				res += rec(ind, col);
			else
				res += rec(ind-1, !col);
		}
		if (pos - prev >= difs[!col]) {
			res += rec(ind, !col);
		}
	}
	res %= mod;
	out = res;
	return res;
}

int main() {
	cin.sync_with_stdio(false);
	cin.exceptions(cin.failbit);
	cin >> N >> difs[0] >> difs[1];
	if (difs[0] > difs[1]) swap(difs[0], difs[1]);
	S.resize(N);
	rep(i,0,N) cin >> S[i];

	rep(col,0,2) {
		failures[col].resize(N);
		ll p = S[0];
		int f = 0;
		failures[col][0] = 0;
		rep(i,1,N) {
			if (S[i] - p < difs[col]) f++;
			failures[col][i] = f;
			p = S[i];
		}
	}

	mem[0].assign(N, -1);
	mem[1].assign(N, -1);
	ll res = rec(0, 0) + rec(0, 1);
	res %= mod;
	cout << res << endl;
	exit(0);
}

Measured memory_bytes: 11264
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

//-------------------------------------------------------------------
const int MAX_V = 200001;
vvl G = VV(MAX_V, 0, 0, ll);
int root;
vll dat(200001, 0);

//-------------------------------------------------------------------
struct segtree{
  ll M=1, INIT;
  vector<ll> dat;
  segtree(ll N, ll num){
    INIT = num;
    while(M<N) M*=2;
    for(int i=0;i<M*2-1;i++)  dat.push_back(num);
  }
  void update(ll x, ll k, ll l=0, int r=-1){
    if(r==-1) r = M;
    k+=M-1;
    dat[k] = x;
    while(k>0) k = (k-1)/2, dat[k] = max(dat[k*2+1],dat[k*2+2]);
  }
  ll query(ll a, ll b=-1, ll k=0, ll l=0, ll r=-1){
    if(r==-1) r = M;
    if(b==-1) b = M;
    if(r<=a || b<=l) return INIT;
    if(a<=l && r<=b) return dat[k];
    ll A = query(a, b, k*2+1, l, (l+r)/2);
    ll B = query(a, b, k*2+2, (l+r)/2, r);
    return max(A, B);
  }
};

segtree seg(200001, 0);
vll ans(200001, 0);
vector<multiset<ll>> num(200001);

void f(ll now, ll from){
  ll q = seg.query(0, dat[now]);
  ll t = seg.query(0, 200001);
  ans[now] = max(q+1, t);

  num[dat[now]].insert(q+1);
  auto itr = --num[dat[now]].end();
  seg.update((*itr), dat[now]);

  for(auto to:G[now]){
    if(to==from) continue;
    f(to, now);
  }
  itr = num[dat[now]].find(q+1);
  num[dat[now]].erase(itr);
  if(num[dat[now]].size()==0) seg.update(0, dat[now]);
  else{
    itr = --num[dat[now]].end();
    seg.update((*itr), dat[now]);  
  }
}
//-------------------------------------------------------------------
int main(int argc, char const *argv[]) {
  ll a, b, n;std::cin >> n;
  map<ll, ll> mp;

  re(i, n) {
    scanf("%lld", &dat[i+1]);
    mp.emplace(dat[i+1], 0);
  }

  ll cnt = 0;
  for(auto itr=mp.begin();itr!=mp.end();itr++, cnt++) {
    (*itr).second = cnt;
  }

  for(int i=1;i<=n;i++) dat[i] = mp.at(dat[i]);
  re(i, n-1){
    scanf("%lld %lld", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  f(1, -1);

  for(int i=1;i<=n;i++) std::cout << ans[i] << '\n';
  return 0;
}


Measured memory_bytes: 51424
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1e9+10)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))


int main(void){
	int n,m,x;
	cin>>n>>m;
	vector<int> X;
	rep(i,m){
		cin>>x;
		X.push_back(x);
	}
	//昇順
	sort(X.begin(),X.end());

	vector<int> sa;
	rep(i,X.size()-1){
		sa.push_back(X[i+1]-X[i]);
	}

	sort(sa.begin(),sa.end());

	int ans = 0;
	rep(i,m-n){
		ans += sa[i];
	}

	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int mod = 1e9+7;

int main()
{
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    int ab = c*2;
    int tmp, ans= 1e9;

    rep(i, x+y)
    {
        tmp = ab*i + a*max(0, x-i) + b*max(0, y-i);
        ans = min(ans, tmp);
    }

    cout << ans << endl;

}

Measured memory_bytes: 3568
n, a, b = map(int, input().split())
ans = pow(2,n,10**9+7)-1

A = 1
for i in range(1,a+1):
  A = (A*(n-i+1))%(10**9+7)
  x = pow(i,10**9+5,10**9+7)
  A *= x

B = 1
for i in range(1,b+1):
  B = (B*(n-i+1))%(10**9+7)
  y = pow(i,10**9+5,10**9+7)
  B *= y

ans = ans-A-B
if ans < 0:
  ans = ans+10**9+7
ans = int(ans%(10**9+7))
print(ans)

Measured memory_bytes: 3064