akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(n)-1,i##_len=(int)(s);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};
//今回の変数
ll a[200000], b[200000];

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
ll Minl(ll a, ll b) {
	return (a)<(b) ? (a) : (b);
}
ll Maxl(ll a, ll b) {
	return (a)>(b) ? (a) : (b);
}

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
void ShowData(ll x[], int left, int right)
{
	int i;
	for (i = left; i <= right; i++)printf("%lld  ", x[i]);
	printf("\n");
}
void hSwap(ll x[], int i, int j)
{
	ll temp;

	temp = x[i];
	x[i] = x[j];
	x[j] = temp;
}
void QSort2(ll x[], ll y[], int left, int right, int n) {
	int i, j;	//左端,右端
	ll pivot;	//軸

	i = left;
	j = right;
	pivot = x[(left + right) / 2];

	while (1) {
		if (n > 0) {				//n>0なら昇順、n<=0なら降順
			while ((x[i] < pivot) && (i <= right))i++;	//軸値より大きい要素
			while ((pivot < x[j]) && (i <= right))j--;	//軸値より小さい要素
		}
		else {
			while ((x[i] > pivot) && (i <= right))i++;	//軸値より小さい要素
			while ((pivot > x[j]) && (i <= right))j--;	//軸値より大きい要素
		}
		if (i >= j)	break;
		hSwap(x, i, j);
		hSwap(y, i, j);
		i++; j--;
	}
	//ShowData(x, left, right);

	if (left < i - 1)QSort2(x, y, left, i - 1, n);
	if (j + 1 <  right)QSort2(x, y, j + 1, right, n);
}

int main() {
	int n;
	scanf("%d", &n);
	REP(i, n) {
		scanf("%lld%lld", &a[i], &b[i]);
	}

	QSort2(b, a, 0, n - 1, 0);
	//ShowData(a, 0, n - 1);
	//ShowData(b, 0, n - 1);

	ll now=b[0];
	REP(i, n) {
		now = Minl(now, b[i]);
		if (now - a[i] < 0) {
			puts("No");
			return 0;
		}
		now -= a[i];
	}
	puts("Yes");
}


Measured memory_bytes: 3328
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int i = 1;
        int x = scan.nextInt();
        while(x > 0){
            System.out.println("Case "+i+": "+x);
            x = scan.nextInt();
            i++;
        }
    }
}


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

int main()
{
    double v;
    while(cin >> v)
    {
        double y = 4.9 * (v / 9.8) * (v / 9.8);
        cout << std::ceil(y/5+1) << endl;
    }
    return 0;
}

Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, D, N, ans=0;
    vector<int> V(3);
    char tmp;
    string S;
    cin >> V[0] >>V[1] >>V[2];

    if(V[2]-V[1]<=0)
	puts("delicious");
    else if(V[2]-V[1] <=V[0])
	puts("safe");
    else
	puts("dangerous");
    
    // cout <<ans<<endl;
    

    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;
    // if(A+B==C || B+C==A || C+A==B)
    // 	puts("Yes");
    // else
    // 	puts("No");
}


Measured memory_bytes: 256
N = int(input())
s = []
t = []
k = []
for i in range(N):
    a, b = map(str,input().split())
    s.append(a)
    c = int(b)
    t.append(c)
X = input()

for i in range(N):
    if s[i] == X:
        count = i+1
        break
ans = 0
for i in range(count,N):
    ans += t[i]
print(ans)

Measured memory_bytes: 3064
N = int(input())
S = input()
begin = 0
end = 0
for i in range(N):
    if(S[i] == "(" ):
        begin += 1
    elif(S[i] == ")" and begin <= 0):
        end += 1
    else:
        begin -= 1
S = ("(" * end) + S + (")" * begin)
print(S)


Measured memory_bytes: 2940
N = int(input())
AB = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x:x[1], reverse=True)
CD = sorted([list(map(int, input().split())) for _ in range(N)])
ans = 0
for cd in CD:
    for ab in AB:
        if cd[0] > ab[0] and cd[1] > ab[1]:
            ans += 1
            AB.remove(ab)
            break


print(ans)

Measured memory_bytes: 3064
//hinagata.cpp
/*includes*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPi(i,a,b) for(int i=(a);i<(b);i++)
#define REPRi(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    int S;
    cin>>S;
    vector<int> V(1010000,0);
    REPi(i,1,1000000){
        V[S]+=1;
        if(V[S]==2){
            cout<<i<<endl;
            break;
        }
        if(S%2==0){
            S/=2;
        }else{
            S=3*S+1;
        }
    }
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" )

int main()
{
    int n;
    string s,t;
    set<string> x;
    cin>>n>>s;
    x.insert(s);
    rep(i,n-1){
        cin>>t;
        x.insert(t);
        if(s[s.size()-1]!=t[0])yn(0),exit(0);
        s=t;
    }
    if(x.size()!=n)yn(0);
    else yn(1);
    
    return 0;
}


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

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 DECIM8  fixed<<setprecision(8) 
#define SZ(a) int((a).size())
#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);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

using namespace std;
int main(void)
{
  bool prime[104857];
  REP(i,104857) prime[i]=true;
  prime[0]=false;
  prime[1]=false;
  REP(i,sqrt(104857)+10){
    if(prime[i]) for(int j=i*i;j<104857;j+=i) prime[j]=false;
  }
  vector<int> pv;
  REP(i,104857) if(prime[i]) pv.push_back(i);
  for(;;){
    int m,a,b;
    cin >> m >> a >> b;
    if(!m&&!a&&!b) return 0;
    int ansp=0,ansq=0;
    REP(pi,10000){
      if(pv[pi]*pv[pi]>m) break;
      FOR(qi,pi,10000){
	if(pv[qi]*pv[pi]>m || a*pv[qi]>b*pv[pi]) break;
	if(ansp*ansq<pv[qi]*pv[pi]){
	  ansp=pv[pi];
	  ansq=pv[qi];
	}
      }
    }	
    cout << ansp << ' ' << ansq << endl;
  }
}

Measured memory_bytes: 1424
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }



signed main(){

    int N, T; cin >> N >> T;
    vec A(N); readv(A);

    vec maxA(N);
    maxA[N - 1] = A[N - 1];
    IREP(i, N - 1) maxA[i] = max(A[i], maxA[i + 1]);

    int m = -1;
    REP(i, N) m = max(m, maxA[i] - A[i]);
    int ans = 0;
    REP(i, N) if(maxA[i] - A[i] == m) ans++;
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	ll n,k;cin>>n>>k;
	ll ans=0;
	if(n>=k){
		ans = min(n%k,k*((n/k)+1)-n);
	}
	else{
		ans = min(n,k-n);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
# unionfindで共通部分の数調べたらいけるかと思ったけど
# 共通部分の構造が重要だった...

# 知りたいのは0とn-1間のパス上における優劣
# →BFSで各頂点までの距離を調べると白黒どちらになるか分かる

# (おまけ)各頂点に付けた順位はその数字の手数以下で
# どちらかの色がつくことが確定している

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    adj = [[] for _ in range(n)] #頂点数, 場合によって変える
    for _ in range(n-1):
        a,b = map(int, input().split())
        adj[a-1].append(b-1)
        adj[b-1].append(a-1)

    black = [-1] * n
    white = [-1] * n
    f = deque([0])
    black[0] = 0
    s = deque([n-1])
    white[-1] = 0

    def bfs(q, color):
        while q:
            v = q.popleft()
            for nv in adj[v]:
                if color[nv] < 0:
                    color[nv] = color[v] + 1
                    q.append(nv)

    bfs(f, black)
    bfs(s, white)
    cnt = 0
    for i in range(n):
        if black[i] <= white[i]:
            cnt += 1
    if cnt > n-cnt:
        print('Fennec')
    else:
        print('Snuke')



if __name__ == '__main__':
    main()

Measured memory_bytes: 29336
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;
ll f[ohara], t[ohara], rui[ohara];

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

  f[0] = 1;
  t[0] = 1;
  rrep(i, 1, ohara) {
    f[i] = f[i - 1] * 4;
    t[i] = t[i - 1] * 2;
    f[i] %= MOD;
    t[i] %= MOD;
  }

  cin >> n;
  rep(i, n) cin >> a[i];
  sort(a, a + n);
  reverse(a, a + n);

  rep(i, n) {
    ll cost;
    cost = t[2 * i];
    cost *= f[n - i - 1];
    cost %= MOD;
    cost *= a[i];
    cost %= MOD;
    cost *= (i + 2);
    cost %= MOD;
    ans += cost;
    ans %= MOD;
  }
  Cout(ans);
  return 0;
}


Measured memory_bytes: 20736
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int n,m,k,f;

int main(){
	cin>>n>>m>>k;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			int a;
			a=m*i+n*j-i*j*2;
			if(a==k&&f==0){
				f=1;
				cout<<"Yes"<<endl;
			}
		}
	}
	if(f==0) cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
def main(input = STDIN)
    n = input.gets.to_i
    a = input.gets.split.map(&:to_i)
    n.times do |i|
      v = a[i]
      (i - 1).step(0, -1) do |j|
        if v < a[j]
          a[j + 1] = a[j]
        else
          break
        end
        a[j] = v
      end
      puts a.join(" ")
    end
end
main



Measured memory_bytes: 6896
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  for (int i = 0; i < (int) s.size(); i++) {
    if (s[i] == '?') {
      s[i] = 'D';
    }
  }
  cout << s << endl;
  /*
  for (int i = 0; i < (int) s.size(); i++) {
    if (s[i] == '?') {
      int last = i;
      for (int j = i; j < (int) s.size(); j++) {
        if (s[j] != '?') {
          break;
        }
        last = j;
      }
      char l = (i ? s[i - 1] : '-');
      char r = (last + 1 < (int) s.size() ? s[last + 1] : '-');
      if (l == 'P') {
        for (int x = i; x < (int) s.size(); x+
      }
      i = last;
    }
  }
  */
}


Measured memory_bytes: 3376
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
        #include <bits/stdc++.h>
        #include <cstdio>
        #include <cstring>
        #include <cmath>
        #include <cstring>
        #include <chrono>
        #include <complex>
        #define ll long long
        #define ld long double
        #define vi vector<int>
        #define vll vector<ll>
        #define vvi vector < vi >
        #define pii pair<int,int>
        #define pll pair<long long, long long>
        #define mod 1000000007
        #define inf 1000000000000000001;
        #define all(c) c.begin(),c.end()
        #define mp(x,y) make_pair(x,y)
        #define mem(a,val) memset(a,val,sizeof(a))
        #define eb emplace_back
        #define pb push_back
        #define f first
        #define s second
        
        using namespace std;
        int main()
        {
            std::ios::sync_with_stdio(false);
            int T;
            T=1;
            // cin.ignore(); must be there when using getline(cin, s)
            while(T--)
            {
                ll n;
                cin>>n;
                cout<<n*(n-1)/2<<endl;
            }
            return 0;
        }
    

Measured memory_bytes: 256
Q, H, S, D = map(int, input().split())
N = int(input())
q, h, s, d = 4 * Q, 2 * H, S, D / 2
if d == min(q, h, s, d) and N >= 2:
    res = D * (N // 2) + (N % 2) * min(q, h, s)
else:
    res = N * min(q, h, s)
print(res)


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

typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

int lcm(int a, int b) { return a * b / gcd(a, b); }

int comb(vector<vector<ll>> &v){
    for (int i = 0; i < v.size(); i++){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for (int i = 1; i < v.size(); i++){
        for (int j = 1; j < i; j++){
            v[i][j] = (v[i - 1][j - 1] + v[i - 1][j]) % mod;
        }
    }
}

int main(){
    int n, k;
    vector<vector<ll>> v(2000, vector<ll>(2000, 0));
    ll ans[4000];
    cin >> n >> k;
    comb(v);
    for (int i = 1; i < k + 1; i++)
    {
        ans[i] = (v[n-k+1][i] * v[k-1][i-1]) % mod;
    }

    for (int i = 1; i < k + 1; i++){
        cout << ans[i] << endl;
    }
    return 0;
}


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


int main() {

	int n, T;
	cin >> n >> T;
	
	map<int, int> mp;
	for(int i = 0; i <n; ++i){
		int s, t;
		cin >> s >> t;
		mp[s]++;
		mp[t]--;
	}
	
	int ans = 0;
	int sum = 0;
	for(auto it : mp){
		sum += (it.second);
		ans = max(ans, sum);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4624
#include <bits/stdc++.h>
using namespace std;
// long long int knapspack(long long int *p,long long int *w,long long int k ,long long int n,long long int i)
// {
//     if(k==0 || i==n)
//     {
//         return 0;
//     }
//     if(w[i]<=k)
//     {
//         return max(p[i]+knapspack(p,w,k-w[i],n,i+1),knapspack(p,w,k,n,i+1));
//     }
//     else
//     {
//         return knapspack(p,w,k,n,i+1);
//     }
// }
int main() {
    long long int n,k;
    cin>>n>>k;
    long long int p[n],w[n];
    for(int i=0;i<n;i++)
    {
        long long int a,b;
        cin>>a>>b;
        w[i]=a;
        p[i]=b;
    }
    long long int A[n+1][k+1];
    for(int i=0;i<=k;i++)
    {
        A[0][i]=0;
    }
    for(int i=0;i<=n;i++)
    {
        A[i][0]=0;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(w[i-1]<=j)
            {
                A[i][j]=max(p[i-1]+A[i-1][j-w[i-1]],A[i-1][j]);
            }
            else
            {
                A[i][j]=A[i-1][j];
            }
        }
    }
    cout<<A[n][k]<<endl;
    
}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,W;
vector<ll> a[4];
int main(){
    scanf("%d%d",&n,&W);
    int x;
    for(int i=1;i<=n;i++){
        int w,v;scanf("%d%d",&w,&v);
        if(i==1)x=w;
        a[w-x].push_back(v);
    }
    for(int i=0;i<4;i++)sort(a[i].begin(),a[i].end(),greater<int>());
    for(int i=0;i<4;i++){
        for(int j=1;j<a[i].size();j++)a[i][j]+=a[i][j-1];
    }
    ll ans=0;
    for(int i=0;i<=a[0].size();i++){
        for(int j=0;j<=a[1].size();j++){
            for(int k=0;k<=a[2].size();k++){
                for(int l=0;l<=a[3].size();l++){
                    ll tmp=(i+j+k+l)*1ll*x+j*1+k*2+l*3;
                    if(tmp<=W){
                        //cout<<i<<' '<<j<<' '<<k<<' '<<l<<endl;
                        ll res=0;
                        if(i)res+=a[0][i-1];
                        if(j)res+=a[1][j-1];
                        if(k)res+=a[2][k-1];
                        if(l)res+=a[3][l-1];
                        ans=max(ans,res);
                    }
                }
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
string s;
int n;

int main(){
	cin>>n>>s;
	if(s.length()<=n){
		cout<<s;
		return 0;
	}
	int i;
	for(i=0;i<n;++i)
		cout<<s[i];
	cout<<"...";
	
	
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vector<string> s,t;
    map<string,int> a,b;
    rep(i,n){
        string tmp; cin>>tmp;
        s.pb(tmp);
        a[tmp]++;
    }
    int m; cin>>m;
    rep(i,m){
        string tmp; cin>>tmp;
        t.pb(tmp);
        b[tmp]++;
    }
    int ans=0;
    rep(i,n){
        chmax(ans,a[s[i]]-b[s[i]]);
    }
    cout<<ans<<"\n";
    return 0;
}


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

const long long INF = 1LL << 60;

template <class T> bool chmin(T& a, T b)
{
  if (a > b) {
    a = b; return true;
  } else return false;
}

template <class T> bool chmax(T& a, T b)
{
  if (a < b) {
    a = b; return true;
  } else return false;
}

int main() 
{
  int N;
  cin >> N;
  vector<vector<long long>> a(N + 2, vector<long long>(3));
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      cin >> a.at(i).at(j);
    }
  }
  
  vector<vector<long long>> dp(N + 2, vector<long long>(3, 0));
  
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      for (int k = 0; k < 3; k++)
      {
        if (j != k)
          chmax(dp.at(i + 1).at(k), 
                dp.at(i).at(j) + a.at(i).at(k));
      }
    }
  }
  
  long long ans = 0;
  for (int i = 0; i < 3; i++) chmax(ans, dp.at(N).at(i));
  cout << ans << endl;
}

Measured memory_bytes: 11136
import java.io.*;
import java.util.*;
public class Main{

     public static void main(String []args){
    Scanner s=new Scanner(System.in);
      String a=s.next();
      String b=s.next();
      long aa=s.nextLong();
      long bb=s.nextLong();
      String c=s.next();
      if(c.equals(a))
      {aa--;
      System.out.println(aa+" "+bb);}
      else
      {bb--;
      System.out.println(aa+" "+bb);}
    
    
     }
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

typedef long long int lli;

const lli maxn = lli(1e5)+5, MOD = lli(1e9)+7;

lli x[maxn], y[maxn];

int main(void)
{
	lli n, m;
	scanf("%lld%lld", &n, &m);
	for(lli i = 0;i < n;i++) scanf("%lld", &x[i]);
	for(lli i = 0;i < m;i++) scanf("%lld", &y[i]);


	lli valxx = 0;
	for(lli i = 0;i < n-1;i++)
	{
		lli vall = ((i+1)%MOD*(n-i-1)%MOD)%MOD;
		vall %= MOD;
		vall *= (x[i+1]-x[i])%MOD;
		vall %= MOD;
		valxx += vall;
		valxx %= MOD;
		//cout << valxx << "\n";
	}
	//cout << valxx << "\n";

	lli res = 0;
	for(lli i = 0;i < m-1;i++)
	{
		lli vall = ((i+1)%MOD*(m-i-1)%MOD)%MOD;
		vall %= MOD;
		vall *= valxx%MOD;
		vall %= MOD;
		vall *= (y[i+1]-y[i])%MOD;
		vall %= MOD;
		res += vall;
		//cout << ((((i+1)%MOD*(n-i-1)%MOD)%MOD*valxx%MOD)%MOD*(y[i+1]-y[i])%MOD)%MOD << "\n";
		res %= MOD;
	}
	printf("%lld\n", res);
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;

int main(void){
	int n,m,a,b,mx=0,sum=0,add,i;
	cin >> n >> m;
	for(i=0; i<m; i++){
		cin >> a >> b;
		add = max(b-n,0);
		sum += add;
		mx = max(mx,add);
	}
	cout << (sum-mx) << endl;
	return 0;
}

Measured memory_bytes: 3080
#include<iostream>
#include<vector>
using namespace std;
using ll=long long ;
int main()
{
    int n;
    cin>>n;
    vector<ll> arr(n);
    for(int i=0;i<n;i++)
    cin>>arr[i];
    ll dp[n][n];
    for(int i=n-1;i>=0;i--)
    {
        for(int j=i;j<n;j++)
        {
            if(i==j)
            {
                dp[i][j]=arr[i];
            }
            else 
            {
                dp[i][j]=max(arr[i]-dp[i+1][j],arr[j]-dp[i][j-1]);
            }
        }
    }
    cout<<dp[0][n-1];
}

Measured memory_bytes: 49672
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  ll l, r;
  cin >> l >> r;
  ll ans = 1001001001001;
  for (ll i = l; i < r; i++) {
    for (ll j = i + 1; j <= r; j++) {
      ll tmp = (i * j) % 2019;
      ans = min(ans, tmp);
      if (ans == 0) break;
    }
    if (ans == 0) break;
  }
  cout << ans << endl;
  return 0;
}

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

int dfs(int p, int n, vector<bool>& done, const vector<vector<int>>& g){
	if(done[p]) return 0;
	int r = p < n;
	done[p] = true;
	for(auto &next:g[p]) r += dfs(next, n, done, g);
	return r;
}

int main(){
	int n, m;
	cin >> n >> m;
	vector<vector<int>> g(n + m);
	for(int i = 0; i < n; i++){
		int k;
		cin >> k;
		while(k--){
			int l;
			cin >> l;
			l--;
			g[i].emplace_back(n + l);
			g[n + l].emplace_back(i);
		}
	}
	vector<bool> done(n + m, false);
	cout << (n == dfs(0, n, done, g) ? "YES" : "NO") << endl;
}

Measured memory_bytes: 8440
#include <stdio.h>

int main(){
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	int turn = 1;

	while ((0 < a) && (0 < c)){
		if (turn++%2) {
			c -= b;
		}else {
			a -= d;
		}
	}
	if (a > c){
		printf("Yes");
	}else {
		printf("No");
	}
	return (0);
}

Measured memory_bytes: 1724
//a
#include <iostream>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <functional>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>

#define REP(i,b,n) for(int i=b;i<n;i++)
#define REPR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#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 BIT(n, b) ((n>>b) & 1)
#define PB push_back
#define MP make_pair

using namespace std;

static const double PI = acos(-1.0);
static const double EPS = 1e-9;
typedef long long ll;
typedef pair<int, int> pii;	

inline bool chk(int n){
	
	stringstream ss;
	string str, rstr;
	
	ss << n;
	ss >> str;
	
	rstr = string(str.rbegin(), str.rend());
	
	return str == rstr;
}

int solve(const int n){
	
	int dis, palnum, res = n;
	
	if(chk(n))
		return n;
	
	int t = n;
	
	while(!chk(++t)){
	}	

	res = t;
	dis = t-n;
	t = n;
	
	while(!chk(--t)){
	}
	
	if(n-t <= dis)
		res = t;
	
	return res;
}	
	
int main(){
	
	int n;
	
	cin>>n;
	
	cout << solve(n) << endl;
	
	return 0;	
}

Measured memory_bytes: 1232
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main(){
   int n,b;
   char a;
   int card[4][13]={{}};
   cin >> n;

   for(int i=0; i<n; i++){
      cin >> a >> b;
      switch(a){
         case 'S':
            card[0][b-1]=1;
            break;
         case 'H':
            card[1][b-1]=1;
            break;
         case 'C':
            card[2][b-1]=1;
            break;
         case 'D':
            card[3][b-1]=1;
            break;
      }
   }
   for(int i=0; i<4; i++){
      for(int j=0; j<13; j++){
         if(card[i][j] == 0){
            switch(i){
               case 0:
                  printf("S %d\n",j+1);
                  break;
               case 1:
                  printf("H %d\n",j+1);
                  break;
                case 2:
                  printf("C %d\n",j+1);
                  break;
                case 3:
                  printf("D %d\n",j+1);
                  break;
            }
         }
      }
   }

   return 0;
}



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

main() {
  ll N, A, B;
  cin >> N >> A >> B;
  ll ans = 0;
  if (B >= A && N >= 2) {
    ans = (B - A) * (N - 2) + 1;
  } else if (B == A && N == 1) {
    ans = 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        xy: [(isize, isize); n]
    }
    let mut maxu = -10000000000;
    let mut minu = 10000000000;
    let mut maxv = -10000000000;
    let mut minv = 10000000000;
    for &(x, y) in &xy {
        let u = x + y;
        let v = x - y;
        maxu = maxu.max(u);
        minu = minu.min(u);
        maxv = maxv.max(v);
        minv = minv.min(v);
    }
    println!("{}", (maxu - minu).max(maxv - minv));
}


Measured memory_bytes: 9000
#include <iostream>
#include <stdio.h>
#include <string>

int main()
{
    std::string  S, T;

    int x = 0, i;

    std::cin >> S >> T;

    for( i = 0; i < S.length(); i++)
    {
        if(S[i] != T[i])
        {
            x = -2;
            break;
        }
    }

    if(x == -2)
        printf("No\n");
    else
        printf("Yes\n");

    return 0;
}


Measured memory_bytes: 3032
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const double PI = acos(-1);
const long long INF = (1LL << 60);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

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

  ll n, m;
  cin >> n >> m;
  vector<ll> x(n), y(n), z(n);
  for(ll i = 0; i < n; i++){
    cin >> x[i] >> y[i] >> z[i];
  }

  ll p[8][3] = {{0, 0, 0},
                {0, 0, 1},
                {0, 1, 0},
                {0, 1, 1},
                {1, 0, 0},
                {1, 0, 1},
                {1, 1, 0},
                {1, 1, 1}};
  
  ll ans = 0;
  for(ll i = 0; i < 8; i++){
    ll sum = 0;
    vector<ll> a;
    for(ll j = 0; j < n; j++){
      sum = 0;
      if(p[i][0] == 0) sum += x[j];
      else sum += -x[j];

      if(p[i][1] == 0) sum += y[j];
      else sum += -y[j];

      if(p[i][2] == 0) sum += z[j];
      else sum += -z[j];
      a.pb(sum);
    }
    sort(all(a), greater<ll>());
    
    ll ma = 0;
    for(ll i = 0; i < m; i++){
      ma += a[i];
    }
    ans = max(ma, ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1244
from typing import List, Dict

atomic_table: Dict[str, int] = {}


class NoAppearAtomicSymbol(Exception):
    pass


class Token:
    s: str
    index = 0

    def __init__(self, s: str):
        self.s = s

    @property
    def c(self) -> str:
        assert self.ok
        return self.s[self.index]

    @property
    def ok(self) -> bool:
        return self.index < len(self.s)

    def next(self):
        self.index += 1


def molecule(t: Token) -> int:
    n = 0
    while t.ok:
        if t.c == '(':
            t.next()
            m = molecule(t)
            t.next()
            m *= number(t)
            n += m
        elif t.c == ')':
            break
        else:
            m = atom(t)
            m *= number(t) or 1
            n += m
    return n


def atom(t: Token) -> int:
    c = ''
    if t.c.isupper():
        c += t.c
        t.next()
    if t.ok and t.c.islower():
        c += t.c
        t.next()
    try:
        return atomic_table[c]
    except KeyError:
        raise NoAppearAtomicSymbol


def number(t: Token) -> int:
    n = 0
    while t.ok and t.c.isdigit():
        n = n * 10 + int(t.c)
        t.next()
    return n


def readuntil(sep: str) -> List[str]:
    lines = []
    while True:
        line = input()
        if line == sep:
            break
        lines.append(line)
    return lines


def main():
    global atomic_table

    atoms = [l.split() for l in readuntil('END_OF_FIRST_PART')]
    atomic_table = {k: int(v) for (k, v) in atoms}
    for seq in readuntil('0'):
        try:
            print(molecule(Token(seq)))
        except NoAppearAtomicSymbol:
            print('UNKNOWN')


main()



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

#define LL long long int
#define LD long double
#define inp_s ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define mod 1000000007


int main(){
      LL x, y;
      cin >> x >>  y;
      if(x % y == 0){
            cout << "-1";
      } else {
            cout << x << "\n";
      }
      return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  P a[n];
  rep(i,n) cin >> a[i].S >> a[i].F;
  sort(a,a+n);
  ll sum=0;
  rep(i,n) {
    sum+=a[i].S;
    if(sum>a[i].F) {
      pr("No");
      return;
    }
  }
  pr("Yes");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3328
n = int(input())
w = list(map(int, input().split()))
is_complete = False
l_i = 0
r_i = len(w)
idx = new_idx = len(w)//2
while not is_complete:
    idx = new_idx
    diff = sum(w[:idx:]) - sum(w[idx::])
    if diff == 0:
        print('0')
        exit()
    if diff > 0:
        r_i = idx
    else:
        l_i = idx
    new_idx = (l_i + r_i)//2
    if r_i <= l_i or new_idx == idx:
        is_complete = True
print(min([abs(sum(w[:idx-1+i:]) - sum(w[idx-1+i::])) for i in range(3)]))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
 {
 	string s;
 	cin>>s;
 	if(s[0]==s[1]&&s[1]==s[2])
 		cout<<"No"<<endl;
 	else
 		cout<<"Yes"<<endl;
 	return 0;
}
 	
 					

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n; cin >> n;
  if(n % 2) {
    cout << 0 << endl;
    return 0;
  }
  
  ll cnt2 = 0;
  ll now2 = 2;
  while(1) {
    if(n / now2 == 0) break;
    cnt2 += n / now2;
    now2 *= 2;
  }

  ll cnt5 = 0;
  ll now5 = 10;
  while(1) {
    if(n / now5 == 0) break;
    cnt5 += n / now5;
    now5 *= 5;
  }

  cout << min(cnt2, cnt5) << endl;

}


Measured memory_bytes: 256
#include <cmath>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#include <numeric>
#include <map>

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;

int n;
string s;

vi r;
vi g;
vi b;

void input() {
  r.clear();
  g.clear();
  b.clear();

  cin >> n >> s;
}

ll cnt(vi& a, vi& b, vi& c) {
  ll ans = 0;

  for (int i = 0; i < (int)a.size(); ++i) {
    auto it1 = upper_bound(b.cbegin(), b.cend(), a[i]);

    if (it1 == b.cend())
      break;

    for (int j = it1 - b.cbegin(); j < (int)b.size(); ++j) {
      auto it2 = upper_bound(c.cbegin(), c.cend(), b[j]);

      if (it2 == c.cend())
        break;

      for (int k = it2 - c.cbegin(); k < (int)c.size(); ++k) {
        if (b[j] - a[i] < c[k] - b[j]) {
          ans += (int)c.size() - k;

          break;
        }

        if (b[j] - a[i] != c[k] - b[j])
          ++ans;
      }
    }
  }

  return ans;
}

void solve() {
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'R') {
      r.push_back(i);
    } else if (s[i] == 'G') {
      g.push_back(i);
    } else {
      b.push_back(i);
    }
  }

  vi p(3);
  iota(p.begin(), p.end(), 0);

  map<int, vi> t = {
    {0, r},
    {1, b},
    {2, g}
  };

  ll ans = 0;

  do {
    ans += cnt(t[p[0]], t[p[1]], t[p[2]]);
  } while (next_permutation(p.begin(), p.end()));

  cout << ans << '\n';
}

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

  cout.precision(16);
  cout << fixed;

  int _times = 1;

#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  _times = 2;
#endif

  // cin >> _times;

  while (_times--) {
    input();
    solve();
  }
}

Measured memory_bytes: 3588
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
  int n, x, cnt;
  while(cin >> n >> x, n || x){
  cnt = 0;
  for(int i = 1; i <= n; i++){
	for(int j = i + 1; j <= n; j++){
	  for(int k = j + 1; k <= n; k++){
		  cnt += (i + j + k == x); 
		}
	  }  
	}
  cout << cnt << endl; 
 }
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int64_t sum = 0;
    rep(i,n){
        sum += a[i];
    }
    int res = 0;
    rep(i,n){
        if(sum%(4*m) == 0){
            if(a[i] >= sum/(4*m)){
                res++;
        	}
        }
        else{
            if(a[i] >= sum/(4*m)+1){
                res++;
        	}
        }
    }
    if(res >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n=1,cnt=1,ans=0,a,b,c[100000],s[100000],f[100000],cmp,data,m,h,w,x,y,xcmp=0,ycmp=0,sum=0;



vector<int> z;

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

       cin >> n;
       rep(i,n-1){
           cin >> c[i] >> s[i] >> f[i];
       }
     rep(i,n){
         ans=0;
         for(int j=i;j<n-1;j++){
             if(ans<s[j]){
                 ans=s[j];
             }
             if(ans%f[j]!=0){
                  ans=ans+f[j]-ans%f[j];
             }
             ans+=c[j];
             
         }
         Cout(ans);
     }
return 0;
}


Measured memory_bytes: 256
five = gets.to_i
one = gets.to_i
fifth = gets.to_i
x = gets.to_i
count = 0


 for f in 0..five
                 for o in 0..one
                                 for fi in 0..fifth
                                                 #puts "sum : #{f*500+o*100+fi*50}"
                                                 if x == f*500 + o*100 + fi*50
                                                                  count += 1
                                                  end
                                 end
                 end
end
 p count


Measured memory_bytes: 1788
#include <map>
#include <algorithm>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <string>
#include <iostream>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;

template<class T> bool chmin(T &a, T b) { return a>b?(a=b,true):false; }
template<class T> bool chmax(T &a,T  b) { return a<b?(a=b,true):false; }
#define forn(i,x,y) for(int i=(x);i<(int)(y);i++)
#define rep(i,y) for(int i=0;i<(int)(y);i++)
#define repb(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)

template<class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << " ";
    os << *it;
  }
  return os;
}

int main() {
    int a,b,c,d;
    cin >> a>> b>> c>> d;
    cout << max(max(1LL*a*d, 1LL*a*c), max(1LL*b*c, 1LL*b*d))  << endl;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()

int main(){
  ll a; cin >> a;
  string s; cin >> s;
  if(a>=3200) cout << s << endl;
  else cout << "red" << endl;
}



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

using namespace std;

int pos[] = {3, 5, 7};

inline bool alldigits(long long N){
  long long n = N;
  int pt[3] = {0, 0, 0};
  while(n > 0){
    if(n % 10 == 3){
      pt[0] ++;
    }else
    if(n % 10 == 5){
      pt[1] ++;
    }else{
      pt[2] ++;
    }

    n /= 10;
  }
  return pt[0] > 0 && pt[1] > 0 && pt[2] > 0;
}

int ways = 0;

long long n;

void solve(long long cur){
  if(cur > n) return;
  if(alldigits(cur)) ways += 1;
  for(int i = 0; i < 3; ++i){
     solve(cur * 10 + pos[i]);
  }
}


int main(){
  cin >> n;
  solve(3);
  solve(5);
  solve(7);
  cout << ways << endl;
  return 0;
}

Measured memory_bytes: 256
var
  s:string;
  i,l,firstc,lastf:longint; 
begin
  read(s);
  l:=length(s);
  firstc:=maxlongint;
  for i:=1 to l do if s[i]='F'then lastf:=i;
   for i:=l downto 1 do if s[i]='C'then firstc:=i;
    if firstc<lastf then writeln('Yes')
     else writeln('No');
 end.

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

int main(){

    string P;
    cin>>P;
    int a=1,count=0;
    for(int i=0;i<P.size();i++){
        if(P[i]=='R' && a==1){
            a=1;
            count++;
        }else{
            a=0;
            if(P[0]=='S'){
                a=1;
            }
            if(P[0]=='S'&&P[1]=='S'){
                a=1;
            }

        }
    }
    cout<<count<<endl;

    return 0;
}


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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<bool> dp (k+1);
	vector<int> a (n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i <= k; i++) {
		for (int e : a) {
			if (e <= i && !dp[i-e])
				dp[i] = true;
		}
	}
	cout << (dp[k] ? "First" : "Second");
}



Measured memory_bytes: 256
#include <iostream>
#include <list>


int main()
{
	std::list<int> li;
	
	std::list<int>::iterator it = li.begin();
	
	int q; std::cin >> q;
	for (int i=0; i<q; i++) {
		int op;
		std::cin >> op;
		int key, d;
		switch (op) {
		case 0:
			std::cin >> key;
			it = li.insert(it, key);
			break;
		case 1:
			std::cin >> d;
			if (d>0) {
				for (int i=0; i<d; i++) {
					if (it == li.end()) break;
					++it;
				}
			} else {
				for (int i=0; i<-d; i++) {
					if (it == li.begin()) break;
					--it;
				}
			}
			break;
		case 2:
			it = li.erase(it);
			break;
		}
		// std::cout << i << " : " << std::distance(li.begin(), it) << std::endl;
	}
	
	for (it = li.begin(); it != li.end(); it++) std::cout << *it << std::endl;
	
	return 0;
}
		



Measured memory_bytes: 18636
import sys
from itertools import product

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    nums = list(input())
    for pattern in product(["+", "-"],repeat=3):
        pattern = list(pattern) + [""]
        fomula = ""
        for op, num in zip(pattern, nums):
            fomula += num + op
        if eval(fomula) == 7:
            print(fomula + "=" + "7")
            break


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(j, m) for (int j = 1; j <= (int)(m); j++)

int bSort(int a[], int n){
int sw = 0;
bool flag = 1;
for (int i = 0; flag; i++){
flag  = 0;
  for(int j = n-1; j > i; j--){
    if(a[j-1] > a[j]){
      swap(a[j],a[j-1]);
      sw++;
      flag = 1;
    }
  }  
}
return sw;
}

int main(){

int n;
cin >> n;
int a[n];
rep(i,n) cin >> a[i];

int ans = bSort(a,n);

rep(i,n){
  if(i > 0) cout << " ";
  cout << a[i];
}
cout << endl;
cout << ans << endl;

return 0;

}


Measured memory_bytes: 3088
import Data.List

main = readLn >>= print . factors

factors n = foldr (*%) 1 . map (succ . length) . group . sort . concatMap factorization $ [2..n]

modulus :: Int
modulus = 1000000007

(+%) :: Int -> Int -> Int
(+%) x y = mod (x + y) modulus

(*%) :: Int -> Int -> Int
(*%) x y = fromIntegral $ mod (fromIntegral x * fromIntegral y) (fromIntegral modulus)

primes :: Integral a => [a]
primes = 2 : 3 : [x | i <- [1..], j <- [-1,1], let x = 6*i+j, isPrime x]
  where
    isPrime n = null [i | i <- takeWhile (\p -> p*p <= n) primes, mod n i == 0]

factorization :: Integral a => a -> [a]
factorization n = unfoldr go (n, primes)
  where
    go (_, []) = Nothing
    go (m, pps@(p:ps))
      | m == 1 = Nothing
      | p > isqrt n = Just (m, (1, pps))
      | otherwise = let (q,r) = divMod m p in if r == 0 then Just (p, (q,pps)) else go (m,ps)

isqrt :: Integral a => a -> a
isqrt = floor . sqrt . (fromIntegral :: Integral a => a -> Double)

Measured memory_bytes: 1532