akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
bool D[81][81][2*80*80+1];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector<vector<int> > A(H, vector<int>(W)), B(H, vector<int>(W));
    for (auto &a : A) for (auto &_a :a) cin >> _a;
    for (auto &b : B) for (auto &_b :b) cin >> _b;
    D[0][0][abs(A[0][0] - B[0][0])] = true;
    const int BUF = (W+H)*80+1;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            int c = abs(A[i][j] - B[i][j]);
            for (int k = 0; k < BUF; ++k) {
                if (i > 0 && D[i - 1][j][k]) {
                    D[i][j][abs(c - k)] = true;
                    if (c + k < BUF) D[i][j][c + k] = true;
                }
                if (j > 0 && D[i][j - 1][k]) {
                    D[i][j][abs(c - k)] = true;
                    if (c + k < BUF) D[i][j][c + k] = true;
                }
            }
        }
    }
    for (int k = 0; k < BUF; ++k) {
        if (D[H - 1][W - 1][k]) {
            printf("%d\n", k);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 81280
#include <stdio.h>

double func(double a ,double b,double c,double d,double e,double f){
	return (c*d-a*f)/(b*d-a*e);
}

int main(void){
	double a,b,c,d,e,f,x,y;
	while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f) != EOF){
		y=func(a,b,c,d,e,f);
		x=(c-b*y)/a;
		//func(a,b,c,d,e,f,x,y);
		printf("%.3lf %.3lf\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 652
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    long long  a[100];
    a[0]=2;
    a[1]=1;
    for(int i=2;i<=n;i++){
        a[i]=a[i-1]+a[i-2];
    }
    printf("%lld",a[n]);
    return 0;
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int N;
Vi A, B;
int dp[(1 << 18) + 1][20];

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

    cin >> N;
    A.resize(N), B.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }

    for (int i = 0; i < (1 << N); i++) {
        for (int j = 0; j < N; j++) {
            dp[i][j] = I_INF;
        }
    }
    for (int i = 0; i < N; i++) {
        dp[(1 << i)][i] = 0;
    }

    for (int bit = 0; bit < (1 << N); bit++) {
        for (int i = 0; i < N; i++) {
            if (!(bit & (1 << i))) continue;
            int prev_bit = bit & ~(1 << i);

            int i_pos = __builtin_popcount(bit) - 1;
            int i_val;
            if (abs(i_pos - i) & 1) {
                i_val = B[i];
            }
            else {
                i_val = A[i];
            }

            int cnt = 0;
            for (int j = 0; j < N; j++) {
                if (prev_bit & (1 << j)) {
                    if (i < j) ++cnt;
                }
            }

            for (int j = 0; j < N; j++) {
                if (!(prev_bit & (1 << j))) continue;

                int j_pos = i_pos - 1;
                int j_val;
                if (abs(j_pos - j) & 1) {
                    j_val = B[j];
                }
                else {
                    j_val = A[j];
                }

                if (j_val > i_val) continue;

                if (dp[prev_bit][j] != I_INF)
                    dp[bit][i] = min(dp[bit][i], dp[prev_bit][j] + cnt);
            }
        }
    }

    int ans = I_INF;
    for (int i = 0; i < N; i++) {
        ans = min(ans, dp[(1 << N) - 1][i]);
    }

    if (ans == I_INF) ans = -1;

    cout << ans << endl;

    return 0;
}

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

int main()
{
	int mountain[10] = { 0 };
	int i, j, max, tmp;
	for(i = 0; i < 10; i++)
		cin >> mountain[i];
	for(i = 0; i < 10; i++)
	{
		max = i;
		for(j = i; j < 10; j++)
		{
			if(mountain[j] > mountain[max])
				max = j;
		}
		tmp = mountain[i];
		mountain[i] = mountain[max];
		mountain[max] = tmp;
	}
	for(i = 0; i < 3; i++)
	{
		cout << mountain[i] << endl;
	}
}

Measured memory_bytes: 1160
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

ll K;
string S;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> K;
    cin >> S;
    solve();
}

// K は 1 以上 100 以下の整数
// S は英小文字からなる文字列
// S の長さは 1 以上 100 以下

// ll K, string S
// 問題文の通りに出力せよ。
void solve(){
    if(S.size()<=K){
        cout<<S<<endl;
    }else{
        cout<<S.substr(0,K)<<"..."<<endl;
    }
}


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

using namespace std;

const int X = 3999;

int a[1234][1234];

int main() {
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (i % h == h - 1 && j % w == w - 1) {
        a[i][j] = -X * (h * w - 1) - 1;
      } else {
        a[i][j] = X;
      }
    }
  }
  long long total = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      total += a[i][j];
    }
  }
  if (total <= 0) {
    puts("No");
    return 0;
  }
  puts("Yes");
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (j > 0) putchar(' ');
      printf("%d", a[i][j]);
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 5632
// atcoder/abc088/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<int> a(n);
    vector<int> b(n);
    cin >> a >> b;

    int z = 0;
    for (int k = 1 << 29; k; k /= 2) {
      each (i, a) i %= (k << 1);
      each (i, b) i %= (k << 1);
      sort(a.begin(), a.end());
      sort(b.begin(), b.end());
      int cnt = 0;
      each (i, a) {
        if (k & i) {
          cnt += lower_bound(b.begin(), b.end(), (k << 1) - i) - b.begin();
          cnt += lower_bound(b.begin(), b.end(), (k << 1)) - lower_bound(b.begin(), b.end(), (k << 1) + k - i);
        } else {
          cnt += lower_bound(b.begin(), b.end(), (k << 1) - i) - lower_bound(b.begin(), b.end(), k - i);
        }
      }
      if (cnt % 2) z |= k;
    }
    cout << z << endl;
  }

  return 0;
}


Measured memory_bytes: 1792
N, M = map(int, input().split())

lower = 0
upper = N+1
for _ in range(M):
    L, R = map(int, input().split())
    lower = max(lower, L)
    upper = min(upper, R+1)
c = upper - lower
if c <= 0:
    print(0)
else:
    print(c)


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

char S[10];
ll i, j, k;
int main(){
    scanf("%s", S);
    j = 0;
    fornum(i,0,4){
        if(S[i]=='+'){
            ++j;
        }else{
            --j;
        }
    }
    printf("%lld\n", j);
    return 0;
}

Measured memory_bytes: 256
h,w,k = map(int,input().split())
s = []

for i in range(h):
    s.append(input())

ans = [[0 for i in range(w)] for j in range(h)]

f = 1
empL = []
befP = []
for x in range(h):
    fsf = False # 行の一番初めのイチゴは無視する
    nexS = True # その行にイチゴが存在するかどうかのフラグ
    for y in range(w):
        if (s[x][y] == "#"):
            nexS = False
            if (fsf):
                f += 1
            else:
                fsf = True
        ans[x][y] = f
    if (nexS):
        #その行にイチゴが存在しなければ
        #前に解析済みパターンが無ければ
        if (len(befP) == 0):
            empL.append(x)
        else:
            ans[x] = befP
            for i in range(len(empL)):
                ans[empL.pop(0)] = befP

    else:
        f += 1
        befP = ans[x]
        for i in range(len(empL)):
                ans[empL.pop(0)] = befP

for x in range(h):
    for y in range(w):
        print(ans[x][y],end=" ")
    print()


Measured memory_bytes: 7568
import java.util.*;

public class Main{

	public static void main(String[] args){
    	Scanner scanner = new Scanner(System.in);
        
        int P = scanner.nextInt(); // A-B
        int Q = scanner.nextInt(); // B-C
        int R = scanner.nextInt(); // C-A
        
        // A-B-C
        int t = P + Q;
        
        // C-A-B
        if(t > R+P){
        	t = R + P;
        }
        
        // B-C-A
        if(t > Q+R){
        	t = Q + R;
        }
        
        System.out.println(t);
    }

}

Measured memory_bytes: 21972
n = int(input())
l = list(input())

ans = 3*10**5

w_cnt = [0]*n 
e_cnt = [0]*n

for i in range(n):
    if i == 0:
        if l[i] == 'W':
            w_cnt[0] = 1
    if i >= 1 and i <= n-1:
        if l[i] == 'W':
            w_cnt[i] = w_cnt[i-1] + 1
        else:
            w_cnt[i] = w_cnt[i-1]
for i in range(n)[::-1]:
    if i == n-1:
        if l[i] == 'E':
            e_cnt[i] = 1
    if 0 <= i and i <= n-2:
        if l[i] == 'E':
            e_cnt[i] = e_cnt[i+1] + 1
        else:
            e_cnt[i] = e_cnt[i+1]
for i in range(1,n-2):
    ans = min(ans,w_cnt[i-1]+e_cnt[i+1])
print(min(ans,e_cnt[0],w_cnt[n-1]))

Measured memory_bytes: 21628
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<cstdlib>
//#include<cmath>
//#include<algorithm>
//#include<vector>
//#include<queue>
//#include<stack>
//#include<map>
//#include<set>
using namespace std;
#define SC scanf
#define PR printf
#define pb push_back
#define mp make_pair
#define SZ(v) ((int)(v).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define db double
#define ldb long double
#define uint unsigned
#define ll long long
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef pair<pii,pii> ppp;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef map<int,int> mii;
const int INF=0x3f3f3f3f;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
const int xx[4]={1,-1,0,0};
const int yy[4]={0,0,1,-1};
int inline nextin(){
	int t;
	if(scanf("%d",&t)!=1)exit(0);
	return t;
}
int inline in(){
	int x=0,c;
	for(;(uint)((c=getchar())-'0')>=10;){
		if(c=='-')return -in();
		if(!~c)throw ~0;
	}
	do{
		x=(x<<3)+(x<<1)+(c-'0');
	}while((uint)((c=getchar())-'0')<10);
	return x;
}
bool dislike[10];
int main(){
    cin.sync_with_stdio(false);cin.tie(0);
	int n;
	int k;
	cin>>n>>k;
	rep(i,k){
		int x;
		cin>>x;
		dislike[x]=true;
	}
	for(int i=n;i<100000;i++){
		stringstream ss;
		ss<<i;
		string S=ss.str();
		bool ok=true;
		rep(j,SZ(S)){
			if(dislike[S[j]-'0']){
				ok=false;
				break;
			}
		}
		if(!ok)continue;
		cout<<i<<endl;
		break;
	}
	return 0;
}

Measured memory_bytes: 256
#http://abc079.contest.atcoder.jp/
# -*- coding: utf-8 -*-

h,w = map(int,input().split())

mp = []
for _ in range(10):
    mp.append(list(map(int,input().split())))

wall = []
for _ in range(h):
    wall.append(list(map(int,input().split())))

def min_cost(i,j,current,min_cost_current):
    if i == j: return current
    for index in range(10):
        if i == index: continue
        if current + mp[i][index] < min_cost_current:
            min_cost_current = min_cost(index,j,current+mp[i][index],min_cost_current)
    return min_cost_current


mp_min_cost =[]
for i in range(10):
    tmp = []
    for j in range(10):
        if i == j :
            tmp.append(0)
            continue

        min_cost_current = mp[i][j]
        if min_cost_current == sorted(mp[i])[1]:
            tmp.append(mp[i][j])
            continue

        # from i to j
        for index in range(10):
            if i == index: continue
            if mp[i][index] < min_cost_current:
                min_cost_current = min_cost(index,j,mp[i][index],min_cost_current)
        tmp.append(min_cost_current)
    mp_min_cost.append(tmp)

amount = 0
for i in wall:
    for j in i:
        if j == -1 or j == 1: continue
        amount += mp_min_cost[j][1]
print(amount)


Measured memory_bytes: 3444
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n;
cin >> n;
vector<ll> top(n),bottom(n);
ll sumt = 0, sumb = 0;
for(ll i = 0; i < n; i++) {
    cin >> top[i];
}
for(ll i = 0; i < n; i++) {
    cin >> bottom[i];
    sumb += bottom[i];
}
sumt = top[0];
ll sum = 0;
for(ll i = 0; i < n - 1; i++){
    sum = max(sum, sumt + sumb);
    sumt += top[i + 1];
    sumb -= bottom[i];
}
sum = max(sum, sumt + sumb);

cout << sum << endl;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 100100;

int ST[MAX];

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n, m;
	scanf("%d%d", &n, &m);
	FOR (i, 0, m)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		x--;
		y--;

		ST[x]++;
		ST[y]++;
	}

	FOR (i, 0, n)
	{
		if (ST[i] & 1)
		{
			cout<<"NO"<<endl;
			return 0;
		}
	}

	cout<<"YES"<<endl;
}


Measured memory_bytes: 640
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

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

struct DSU{
	int S;
	struct node{
		int parent; ll sum;
	};
	vector<node> dsu;
	DSU(int n){
		S = n;
		rep(i, n){
			node tmp;
			tmp.parent = i; tmp.sum = 1;
			dsu.pb(tmp);
		}
	}
	void reset(int n){
		dsu.clear();
		S = n;
		rep(i, n){
			node tmp;
			tmp.parent = i; tmp.sum = 1;
			dsu.pb(tmp);
		}
	}
	int root(int u){
		if(dsu[u].parent == u) return u;
		dsu[u].parent = root(dsu[u].parent);
		return dsu[u].parent;
	}
	void merge(int u, int v){
		u = root(u); v = root(v);
		if(u == v) return;
		if(getsum(u) < getsum(v)) swap(u, v);
		dsu[v].parent = u;
		dsu[u].sum += dsu[v].sum;
	}
	bool sameset(int u, int v){
		if(root(u) == root(v)) return true;
		return false;
	}	
	ll getsum(int u){
		return dsu[root(u)].sum;
	}
};

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int m;
	ll n;
	cin >> n >> m;
	vi a(m), b(m);
	rep(i, m){
		cin >> a[i] >> b[i];
		a[i]--, b[i]--;
	}
	reverse(all(a));
	reverse(all(b));
	DSU dsu(n);
	ll ans = (n * (n - 1)) / 2;
	vector<ll> ret(m, 0LL);
	ret[0] = ans;
	rep(i, m - 1){
		ret[i + 1] = ans;
		if(!dsu.sameset(a[i], b[i])){
			ans -= dsu.getsum(a[i]) * dsu.getsum(b[i]);
			ret[i + 1] = ans;
			dsu.merge(a[i], b[i]);
		}
	}
	reverse(all(ret));
	rep(i, ret.size()) cout << ret[i] << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 4464
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int n,k,vis[N];
vector<ll>v[N];
multiset<ll>one,three;
vector<pair<ll,int> >jewels;
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        int x,y;scanf("%d%d",&x,&y);
        v[x].emplace_back(y*2);
    }
    for(int i=1;i<=k;i++)
    {
        sort(v[i].begin(),v[i].end(),greater<int>());
        if(v[i].size()>2) three.insert(v[i][0]+v[i][1]+v[i][2]);
        ll avg=v[i][0]+v[i][1]>>1;
        jewels.push_back({avg,i});
        jewels.push_back({avg,i});
        for(int j=2;j<v[i].size();j++)
        jewels.push_back({v[i][j],i});
    }
    sort(jewels.begin(),jewels.end(),greater<pair<ll,int>>());
    ll sum=0,mnone=1ll<<60,mntwo=1ll<<60;
    for(int i=0;i<n;i++)
    {
        ll ans=-2,value=jewels[i].first,c=jewels[i].second;
        if(vis[c]==0)
        {
            if(!one.empty())
                ans=max(ans,sum+*one.rbegin());
            ans=max(ans,sum-mnone+value+jewels[i+1].first);
            if(!three.empty())
                ans=max(ans,sum-mntwo+*three.rbegin());
            if(v[c].size()>2)
                three.erase(three.find(v[c][0]+v[c][1]+v[c][2]));
        }
        else
        {
            ans=sum+value;
            if(vis[c]==1)
            {
                for(int j=2;j<v[c].size();j++)
                    one.insert(v[c][j]);
                mntwo=min(mntwo,v[c][0]+v[c][1]);
            }
            else
            {
                one.erase(one.find(value));
                mnone=min(mnone,value);
            }
        }
        vis[c]++;
        sum+=value;
        printf("%lld\n",ans/2);
    }
}


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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

// 約数の列挙
inline int divisor(int n) {
    int ret = 0;
    for (int i=1;i*i<=n;++i) {
        if (n%i == 0) {
            ret++;
            if (i != n/i) ret++;
        }
    }
    return ret;
}

int main() {
    int N;
    cin >> N;
    int ans = N - 1;
    for (int A = 2; A < N; ++A) {
        for (int B = 1; A*B < N; ++B) {
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3644
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        int n = scan.nextInt();
        int k = scan.nextInt();
        int[] h = new int[n];
        int a = 0;
        for(int i = 0; i < n; i++){
            h[i] = scan.nextInt();
            if(h[i] >= k){
                a++;
            }
        }
        System.out.println(a);
    }
}

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


int main() {
    int n;
    cin >> n;
    map<string, int> s;
    rep(i, n){
        string item;
        cin >> item;
        s[item] ++;
    }

    cout << s.size() << endl;
    
    return 0;
}

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

int main()
{
    int n,flag=0,f1=1;
    string s[101];
    char s1[220];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
        if(i>0)
        {
            if(s[i-1][s[i-1].length()-1]==s[i][0])
                flag++;

        for(int j=i-1;j>=0;j--)
        {
            if(s[i]==s[j])
                f1=0;
        }
        }
    }
    if(flag==n-1){
    if(f1==1){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
    }
    else cout<<"No"<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
// const int k_mod = 1e9 + 7;
const int k_mod = 998244353;

typedef struct {
	vector <int> to;
	int cost;
} edge;
template <typename T, typename K> struct P {
	T a; K b;
};
vector <P <ll, ll> >calc_get_factor_pair( ll N ){
	vector <P <ll, ll> > vec;
	vec.push_back( P <ll, ll>{1, N} );
	int lim = sqrt( N ) + 5;
	rep( i, 2, N + 1 ){
		if (i >= lim)
			break;
		if (N % i == 0)
			vec.push_back( P <ll, ll>{i, N / i} );
	}
	return vec;
}

int main( void ){
	ll N; cin >> N;
	const auto &pairs = calc_get_factor_pair( N );

	int ans = k_mod;
	for(auto p:pairs)
		ans = min( max(( int )log10( p.a ) + 1, ( int )log10( p.b ) + 1 ), ans );
	cout << ans << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 384
cards = {
    "S":[0 for i in range(13)],
    "H":[0 for i in range(13)],
    "C":[0 for i in range(13)],
    "D":[0 for i in range(13)]
}

n = int(input())

for i in range(n):
    a,b = input().split()
    cards[a][int(b)-1] = 1

for a in ("S","H","C","D"):
    for b in range(13):
        if cards[a][b] == 0:
            print(a,b+1)

Measured memory_bytes: 7788
while line = gets.split.map(& :to_i)
  if line[0] == 0 && line[1] == 0
    break
  elsif line[0] <= line[1]
    print line[0].to_s + " " + line[1].to_s + "\n"
  else
    print line[1].to_s + " " + line[0].to_s + "\n"
  end
end

Measured memory_bytes: 8784
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
  #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl "\n"
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MAXN=3e3+1;
void solve(){
    vector<int> v(3);
    string s,x;
    for(auto &it:v)cin>>it;
    sort(v.rbegin(),v.rend());
    for(auto it:v)s+=to_string(it);
    x+=s[0],x+=s[1];
    int a=stoi(x);
    int b=s[2]-'0';
    cout<<a+b<<endl;
   
}
int32_t main(){
   IOS;
   solve();
   //debug();
  #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
  #endif	
}

Measured memory_bytes: 256
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int
main()
{
  int N;
  cin >> N;
  int mismatch = 0;
  for (int n = 1; n <= N; n++)
  {
    int i;
    cin >> i;
    if (i != n)
    {
      mismatch++;
    }
  }
  cout << (mismatch <= 2 ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 256
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a=(a[1]-a[0],a[2]-a[0])
b=(b[1]-b[0],b[2]-b[0])
c=(c[1]-c[0],c[2]-c[0])
if a==b and b==c:
  print("Yes")
else:
  print("No")

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)

#define lli long long
#define li long
#define vi vector<int>
#define vli vector<li>
#define vlli viector<lli>
#define pi pair<int,int>
#define vpi vector<pi>

using namespace std;

int main() {
    li n, m;

    scanf("%ld %ld", &n, &m);

    priority_queue<lli> pq;
    map<lli, li> qtd;
    set<lli> cards;

    int i;
    lli soma = 0;
    REP(i, 0, n-1) {
        lli a;
        scanf("%lld", &a);
        
        if(cards.count(a)) {
            qtd[a] += 1;
        }else {
            qtd[a] = 1;
            cards.insert(a);
            pq.push(-a);
        }
    }
    REP(i, 0, m-1) {
        lli b, c;
        scanf("%lld %lld", &b, &c);

        lli sobra = b;
        while(sobra > 0) {
            lli kk = -pq.top();
            if(kk >= c) break;

            if(b <= qtd[kk]) {
                qtd[kk] -= b;
                sobra = 0;
            }else {
                sobra -= qtd[kk];
                qtd[kk] = 0;
                pq.pop();
                cards.erase(kk);
            }

            if(cards.count(c)) {
                qtd[c] += b - sobra;
            }else {
                qtd[c] = b - sobra;
                cards.insert(c);
                pq.push(-c);
            }
            b = sobra;
        }
    }

    for(auto it = cards.begin(); it != cards.end(); ++it) {
        soma += qtd[*it] * *it;
    }

    cout << soma << endl;

}



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

int main() {
    string s;
    cin>>s;
    bool flag=false;
    for(int i=0; i<2; i++){
        if(s[i]!=s[i+1])
            flag=true;
    }
    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

}


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

int main(){
    ll n,cnter = 1000000000000000;
    cin >> n;
    int sum=0;
    int keta[16];
    int cnt;
    rep(i,16) keta[i] = 10;
    int j = 15;
    bool a = true;
    while(j >= 0){
        if(n / cnter >= 1){
            keta[j] = n/cnter;
            n -= keta[j]*cnter; 
            if(a){
                cnt = j;
                a = false;
            }
        }
        else if(!a){
            keta[j] = n/cnter;
            n -= keta[j]*cnter;
        }
        j--;
        cnter /= 10;
    }
    bool han = true;
    int i = 0;
    while(i < cnt){
        if(keta[i] < 9){
            han = false;
        }
        i++;
    }
    if(han){
        rep(i,cnt+1) sum += keta[i];
    }
    else{ 
        rep(i,cnt){
        sum += 9;
        }
        sum += keta[cnt] -1;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
/*
          , -- 、
        /;;;;;;', 　　　
        i二二二i
      , ' 　    ヽ ???
     i　ﾉﾉﾉﾉﾉﾍ .', 　　
     〉ﾘi' ﾟ ヮﾟﾉﾚく　 WAyon..........
  ○⊂}〈lﾄ--ｲl〉{つ● 　　
      ,ｒ/ー i-ヽヽ 　　　
     ｀｀i_ﾗi_ﾗ
*/



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

const int INF=(long long)1e12;
const int mod=(int)1e9+7;
#define all(a) (a).begin(),(a).end()
typedef vector<vector<int>> graph;
int sz=262144;complex<double> y[262160],A[262160],B[262160];
#define int long long
#define P pair<int,int>

signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n;cin >>n;
    int x,y;cin >>x>>y;
    vector<int> a(n+10);
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            int sho=min({abs(j-i),abs(x-i)+abs(y-j)+1,abs(y-i)+abs(x-j)+1});
            a[sho]++;
        }
    }
    for(int i=1;i<n;i++)cout <<a[i]<<endl;
}





Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());

        var ans = 0d;
        for (int i = 1; i <= n; i++)
        {
            if (i % 2 == 1) ans++;
        }

        Console.WriteLine(ans / n);
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <string.h>

int main () {
  int n;
  std::cin >> n;
  
  if (n < 1200) {
    std::cout << "ABC" << std::endl;  
  }
  else {
    if (n < 2800) {
      std::cout << "ARC" << std::endl;  
    }
    else {
      std::cout << "AGC" << std::endl;  
    }
  }  
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut heights: Vec<usize> = (0..n)
        .map(|_| iterator.next().unwrap().parse().unwrap())
        .collect();

    let mut count: usize = 0;
    loop {
        if heights.iter().all(|x| *x == 0) {
            break;
        }
        let mut grouped = false;
        for i in 0..n {
            if heights[i] == 0 {
                grouped = false;
                continue;
            }

            heights[i] -= 1;
            if !grouped {
                grouped = true;
                count += 1;
            }
        }
    }

    return count.to_string();
}


Measured memory_bytes: 4352
/**************************************
 * Au: Hany01
 * Prob: AGC028A
 * Date: Oct 14th, 2018
 * Email: hany01@foxmail.com
**************************************/

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)
#define Rep(i, j) for (register int i = 0, i##_end_ = j; i < i##_end_; ++ i)
#define For(i, j ,k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define SZ(a) ((int)(a.size()))
#define ALL(a) a.begin(), a.end()
#define PB(a) push_back(a)
#define MP(a, b) make_pair(a, b)
#define X first
#define Y second
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define y1 wozenmezhemecaia 
#ifdef hany01
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline T read() {
    register char c_; register T _, __;
    for (_ = 0, __ = 1, c_ = getchar(); !isdigit(c_); c_ = getchar()) if (c_ == '-')  __ = -1;
    for ( ; isdigit(c_); c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}
//EOT


const int maxn = 1e5 + 5;

int main()
{
#ifdef hany01
    File("agc028a");
#endif

    int n = read<int>(), m = read<int>(), g = __gcd(n, m);
    static char S[maxn], T[maxn];
    scanf("%s%s", S + 1, T + 1);

    for (LL c1 = 1, c2 = 1; c1 <= n && c2 <= m; c1 += n / g, c2 += m / g)
        if (S[c1] != T[c2]) { puts("-1"); return 0; }
    printf("%lld\n", (LL)n * m / g);

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>

using namespace std;

int main() {
    int R, G, B, N; cin >> R >> G >> B >> N;

    long res = 0;
    for (int i = 0; (i * R) <= N; ++i) {
        int cr = i * R;
        for (int j = 0; (cr + j * G) <= N; ++j) {
            int cg = cr + j * G;
            if ((N - cg) % B == 0) { ++ res; }
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 256
// AOJ 1068
#include<cstdio>
#include<algorithm>
#include<vector>
#define rep(i,a) for( int i = 0; i != (a); ++i )
#define repi(i,a,b) for( int i = (a); i != (b); ++i )
#define all(a) (a).begin(), (a).end()

const int INF = (1<<31)-1;

int r, c, q;
std::vector<std::vector<int> > segR, segC;

void init( std::vector<std::vector<int> > &seg, int n )
{
	int sz = 1;
	while( sz < n )
		sz <<= 1;

	rep( i, seg.size() )
	{
		seg[i].resize( 2*sz );
		std::fill( all( seg[i] ), INF );
	}

	return;
}

void update( std::vector<int> &seg, int k, int x )
{
	k += (seg.size()>>1)-1;
	seg[k] = x;
	while( k )
	{
		k = (k-1)>>1;
		seg[k] = std::min( seg[(k<<1)+1], seg[(k<<1)+2] );
	}

	return;
}

int query( const std::vector<int> &seg, int a, int b, int k, int l, int r )
{
	if( r <= a || b <= l )
		return INF;
	else if( a <= l && r <= b )
		return seg[k];
	
	return std::min( query( seg, a, b, (k<<1)+1, l, (l+r)>>1 ), query( seg, a, b, (k<<1)+2, (l+r)>>1, r ) );
}

int main()
{
	while( scanf( "%d%d%d", &r, &c, &q ), r|c|q )
	{
		segR.resize( r );
		segC.resize( c );
		init( segR, c );
		init( segC, r );

		rep( i, r )
		{
			rep( j, c )
			{
				int grid;
				scanf( "%d", &grid );

				update( segR[i], j, grid );
				update( segC[j], i, grid );
			}
		}

		rep( i, q )
		{
			int r1, c1, r2, c2;
			scanf( "%d%d%d%d", &r1, &c1, &r2, &c2 );

			int ans = INF;

			if( r2-r1 <= c2-c1 )
				repi( j, r1, r2+1 )
					ans = std::min( ans, query( segR[j], c1, c2+1, 0, 0, segR[j].size()>>1 ) );
			else
				repi( j, c1, c2+1 )
					ans = std::min( ans, query( segC[j], r1, r2+1, 0, 0, segC[j].size()>>1 ) );

			printf( "%d\n", ans );
		}
	}

	return 0;
}

Measured memory_bytes: 63744
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

ll binpow(ll a, ll b) {
    if (b == 0)
    {
        return 1;
    }
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
    {
        return res * a;
    }
    return res;
}

ll gcd(ll a,ll b)
{
    if (b==0) return a;
    return gcd(b,a%b);
}

string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int x,n,k;
    cin>>x>>n;
    map<int,bool> m;
    for (int i=0;i<n;++i)
    {
        cin>>k;
        m[k]=1;
    }
    for (int i=0;i<10000;++i)
    {
        if (!m[x-i])
        {
            cout<<x-i;
            return 0;
        }
        if (!m[x+i])
        {
            cout<<x+i;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3648
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    int n, m;
    ArrayList<ArrayList<Edge>> es;
    long[] dist;
    private final long INF = Long.MAX_VALUE;

    public static void main(String[] args) {
        Main m = new Main();
        m.read();
        m.solve();
    }

    private void read() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        es = new ArrayList<>(n);
        for (int i = 0; i < n; i++) es.add(new ArrayList<>());
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            long c = sc.nextLong();
            es.get(a).add(new Edge(a, b, -c));
        }
    }

    private void solve() {
        boolean b = bellman();
        if (!b)
            System.out.println(-dist[n-1]);
        else
            System.out.println("inf");
    }

    private boolean bellman() {
        dist = new long[n];
        Arrays.fill(dist, INF);
        dist[0] = 0;
        boolean[] flg = new boolean[n];
        flg[0] = true;
        for (int i = 0; i < n+1; i++) {
            for (ArrayList<Edge> ls: es) {
                for (Edge e: ls) {
                    if (flg[e.a] && dist[e.b] > dist[e.a] + e.c) {
                        dist[e.b] = dist[e.a] + e.c;
                        flg[e.b] = true;
                    }
                }
            }
        }

        boolean[] nflg = new boolean[n];
        for (int i = 0; i < n; i++) {
            for (ArrayList<Edge> ls: es) {
                for (Edge e: ls) {
                    if (flg[e.a] && dist[e.b] > dist[e.a] + e.c) {
                        dist[e.b] = dist[e.a] + e.c;
                        nflg[e.b] = true;
                    }

                    if (nflg[e.a])
                        nflg[e.b] = true;
                }
            }
        }
        return nflg[n-1];
    }

    private class Edge {
        int a, b;
        long c;
        Edge (int a, int b, long c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }
    }
}


Measured memory_bytes: 48052
#include<bits/stdc++.h>
using namespace std;
int X[55],Y[55];
double dist(double x1,double y1,double x2,double y2){
    return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}
double max_dist(double x,double y,int n){
    double ans=0;
	for(int i=1;i<=n;i++) 
		ans=max(ans,dist(x,y,X[i],Y[i]));
    return ans;
}
double func(double x,int n){
    double le=0,ri=1000,ans;
    for(int i=1;i<=1000;i++){
    	double mid1=le+(ri-le)/3;
        double f1=max_dist(x,mid1,n);
        double mid2=ri-(ri-le)/3;
        double f2=max_dist(x,mid2,n);
        if(f1<f2){
        	ri=mid2;
        	ans=f1;
		}
		else{
			le=mid1;
			ans=f2;
		}
    }
    return ans;
}
int n;
void solve(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>X[i]>>Y[i];
	double le=0,ri=1000,ans;
    for(int i=1;i<=1000;i++){
        double mid1=le+(ri-le)/3;
        double mid2=ri-(ri-le)/3;
        double f1=func(mid1,n);
        double f2=func(mid2,n);
        if(f1<f2){
        	ri=mid2;
        	ans=f1;
		}
		else{
			le=mid1;
			ans=f2;
		}
    }
    cout<<fixed<<setprecision(50)<<ans<<endl;
}
int main(){
	solve();
	return 0;
}


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

int main() {
  int H,W;
  cin >> H >> W;
  
  vector<string> vec(H);
  for(int i=0;i<H;i++) {
    cin >> vec.at(i);
  }
  
  for(int i=0;i<W+2;i++) cout <<"#";
  cout <<endl;
  
  for(int i=0;i<H;i++) {
    cout <<"#"<< vec.at(i) <<"#"<<endl;
  }
  
  for(int i=0;i<W+2;i++) cout <<"#";
  cout <<endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int n;
ll k;
vector<ll> a;

bool f(ll x){
    ll cnt = 0;
    rep(i,n){
        cnt += (a[i]-1)/x;
    }
    if (cnt <= k) return true;
    else return false;
}

int main(){
    cin >> n >> k;
    a.resize(n);
    rep(i,n) cin >> a[i];
    ll ng = 0, ok = 1e9;
    while(abs(ok - ng) > 1){
        ll mid = (ok + ng) / 2;
        if (f(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 4788
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vector<int> c(n-1),s(n-1),f(n-1);
    for(int i = 0;i < n-1;i ++){
        cin >> c.at(i) >> s.at(i) >> f.at(i);
    }

    for(int i = 0;i < n-1;i ++){
        int ans = 0;
        for(int j = i;j < n-1;j ++){
            ans = max(ans,s.at(j));
            if(ans % f.at(j) > 0)ans += f.at(j) - (ans - s.at(j)) % f.at(j);
            ans += c.at(j);
        }

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



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CompetitiveProgCsLib
{
	class MainProg
	{
		static string R => Console.ReadLine();
		static int RI => int.Parse(R);
		static double RD => double.Parse(R);
		static int[] RIs => R.Split(' ').Select(int.Parse).ToArray();
		static double[] RDs => R.Split(' ').Select(double.Parse).ToArray();
		static void Out(object obj) => Console.WriteLine(obj);
		static void Outb(bool b) => Out(b ? "Yes" : "No");
		static void OutB(bool b) => Out(b ? "YES": "NO");

		static void Main(string[] args)
		{
			var N = RI;
			var x = RIs;
			var li = new List<int>(x);
			Array.Sort(x);
			for(int i = 0;i < N;i++)
			{
				if (li[i] < x[N / 2]) Out(x[N / 2]);
				else Out(x[N / 2 - 1]);
			}
		}
	}
}


Measured memory_bytes: 36456
def main():
  #n = int(input())
  s = input()
  #s = input().split()
  #a,b = list(map(int,input().split()))
  #a = [input() for i in range(n)]
  #a = [int(input()) for i in range(n)]
  #a = [input().split() for i in range(n)]
  #a = [list(map(int,input().split())) for i in range(n)]
  ans = 0
  count = 0
  lis = []
  
  for i in s:
    if i in "ACGT":
      count += 1
      ans = max(ans,count)
    else:
      count = 0
  print(ans)

if __name__ == '__main__':
  main()

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m, x; cin >> n >> m >> x;
    int a[n][m], c[n];
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    int ans = 1e9;
    for (int i = 0; i < (1 << n); i++) {
        vector<int> v(m, 0);
        int d = 0;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                d += c[j];
                for (int k = 0; k < m; k++) {
                    v[k] += a[j][k];
                }
            }
        }
        bool ok = true;
        for (int j = 0; j < m; j++) {
            ok &= (v[j] >= x);
        }
        if (ok) ans = min(ans, d);
    }
    if (ans == 1e9) ans = -1;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3700
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main() {
	int n, i;
	cin >> n >> i;

	print(n - i + 1);


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
constexpr int MX = 1000005;
int n, el, er;
char s[MX];
using P = pair<int,int>;
P ls[MX], rs[MX];
int main(){
	scanf("%d", &n);
	rep(i,n){
		scanf("%s", s);
		int len = strlen(s), l = 0, r = 0;
		rep(j,len){
			if(s[j] == '(') r++;
			else if(r > 0) r--;
			else l++;
		}
		if(l < r) ls[el++] = {l,r};
		else rs[er++] = {l,r};
	}
	sort(ls, ls+el);
	sort(rs, rs+er, [](P &l, P &r){return l.second > r.second;});
	auto f = [](P l, P r){return P{l.first + max(0,r.first-l.second), r.second + max(0, l.second - r.first)};};
	P p = accumulate(ls, ls+el, P{0,0}, f);
	p = accumulate(rs, rs+er, p, f);
	puts(p == P{0,0} ? "Yes" : "No");
}

Measured memory_bytes: 11480
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <array>
#include <cassert>
#include <utility>
#include <vector>

std::vector<int> A, B;
std::vector<int> necessary, pending;
std::vector<std::vector<char>> dp;

constexpr char unsettled = 0;
constexpr char ok = 1;
constexpr char ng = 2;

bool dfs(const int a, const int b){
    if(dp[a][b] == ok) return true; 
    if(dp[a][b] == ng) return false;
    dp[a][b] = ng;
    for(const int v : necessary){
        if(a < v) continue;
        const int c = a % v;
        if(dfs(c, b)){ dp[a][b] = ok; break; }
    }
    if(dp[a][b] == ok) return true;
    for(const int v : pending){
        if(dp[a][b] == ok) break;
        if(a < v) continue;
        const int c = a % v;
        if(dfs(c, b)){ dp[a][b] = ok; break; }
    }
    if(dp[a][b] == ok) return true;
    return false;
}

bool possible(const int n, const int m){
    dp.assign(n + 1, std::vector<char>(n + 1));
    for(int i = 0; i <= n; ++i){
        for(int j = 0; j < i; ++j) dp[i][j] = unsettled;
        dp[i][i] = ok;
        for(int j = i + 1; j <= n; ++j) dp[i][j] = ng;
    }
    for(int i = 0; i < m; ++i) if(not dfs(A[i], B[i])) return false;
    return true;
}

int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); 
    std::cout << std::fixed << std::setprecision(16);

    int n; std::cin >> n;
    A.resize(n); B.resize(n);
    for(auto& itr : A) std::cin >> itr;
    for(auto& itr : B) std::cin >> itr;

    const int max_a = *std::max_element(A.cbegin(), A.cend());
    necessary.resize(0); pending.resize(max_a); for(int i = 0; i < max_a; ++i) pending[i] = i + 1;
    if(not possible(max_a, n)){ std::cout << "-1\n"; return 0; }

    long long int res = 0;
    while(not pending.empty()){
        const int val = pending.back(); pending.pop_back();
        if(not possible(max_a, n)){
            necessary.push_back(val);
            res |= (1LL << val);
        }
    }
    std::cout << res << '\n';

    return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>
int main(void){
int a,b,c,i;
	for(;;){
		scanf("%d %d %d",&a,&b,&c);
		if(a==-1&&b==-1&&c==-1){
			break;}
		if(a==-1||b==-1){
			printf("F\n");
		}else if(80<=a+b){
			printf("A\n");
		}else if(80>a+b&&65<=a+b){
			printf("B\n");
		}else if(65>a+b&&50<=a+b){
			printf("C\n");
		}else if(50>a+b&&30<=a+b){
			if(50<=c){
				printf("C\n");
			}else{
				printf("D\n");
			}
		}else{
		printf("F\n");
		}
	}
	return 0;
}

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

using namespace std;

int main(){
  int n;
  cin >> n;
  string a;
  string b;
  vector <char> ans(0);
  int j=0;
  cin >> a;
  cin >> b;

  for(int i=0;i<n;i++){
    ans.push_back(a.at(i));
    ans.push_back(b.at(i));
  }
  for( char k : ans){
    cout << k;
  }
  cout << endl;
  return 0;
}


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

int main(){
	int n , m , k , p , psum;
	string a , b;
	string want;
	while(cin >> n , n){
		map<string , int> item;
		for(int i=0;i<n;++i){
			cin >> a >> p ;
			item.insert(map<string , int>::value_type( a , p ));
		}
		cin >> m;
		for(int i=0;i<m;++i){
			psum=0;
			cin >> a >> k; //??¬??????a ???????????°k
			for(int j=0 ; j<k ;++j){
				cin >> b;  //??¬??????
				if(item.find(b)!=item.end()) psum+=item[b];
			}
				if(psum < item[a]) {
					item[a]=psum;//???????????´
				}
		}
		cin >> want;
		cout << item[want] << endl;
	}	
	return 0;
}

Measured memory_bytes: 1224