akhauriyash/Code-Regression huggingface dataset:
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <functional>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define MAX_DWORD				(0xFFFFFFFF)
#define	MAX_SDWORD				((SDWORD)0x7FFFFFFF)
#define	MIN_SDWORD				((SDWORD)0x80000000)
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define	MIN_QWORD				((QWORD)0x0000000000000000)
#define	MAX_SQWORD				((SQWORD)0x7FFFFFFFFFFFFFFF)
#define	MIN_SQWORD				((SQWORD)0x8000000000000000)
#define M_PI					3.14159265358979323846

typedef long					SDWORD;
typedef long long				SQWORD;
typedef unsigned long			DWORD;
typedef unsigned long long int	QWORD;
typedef long long ll;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
const int MAX = 2000000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
	int X, Y;
	cin >> X >> Y;

	COMinit();

	if ((X + Y) % 3 != 0) {
		cout << 0 << endl;
		return 0;
	}

	int xNum = (2 * X - Y) / 3;
	int yNum = (2 * Y - X) / 3;
	int total = xNum + yNum;
	ll ans = COM(total, yNum) % MOD;
	cout << ans << endl;
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a & 1) {
            cout << "first" << endl;
            return 0;
        }
    }
    cout << "second" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;
typedef pair<int, int> P;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = { 0, 1, 0, -1 };

int main() {

	ll a, b, x;
	cin >> a >> b >> x;

	ll ans = 0;
	if (a % x != 0) {
		ans = b / x - (a / x);
	}
	else {
		ans = b / x - (a / x - 1);
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s=[]
for i in range(n):
    s.append(input())
from collections import Counter
cs = Counter(s)
m = int(input())
for i in range(m):
    t = input()
    if cs[t]:
        cs[t] -= 1
print(cs.most_common(1)[0][1], flush=True)



Measured memory_bytes: 9432
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <climits>

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define in1(n) cin>>n;
#define in2(n, k) cin>>n>>k;
#define in3(n, k, s) cin>>n>>k>>s;
#define scn(t) scanf("%d", &t)
#define scnld(t) scanf("%ld", &t)
#define scnlld(t) scanf("%lld", &t)
#define scnc(t) scanf("%c", &t)
#define scns(t) scanf("%s", t)
#define scnf(t) scanf("%f", &t)
#define scnlf(t) scanf("%lf", &t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define nloop(i, j, k, in) for (int i = j; i < k; i += in)
#define rloop(i, j, k, in) for (int i = j; i >= k; i -= in)
#define rep(i, j) nloop(i, 0, j, 1)
#define rrep(i, j) rloop(i, j, 0, 1)
#define inar(n, a) \
    rep(i, n)\
        cin>>a[i];
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert(B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define fast  \
    ios_base::sync_with_stdio(false);\
    cin.tie(NULL);
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
const double pi = acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int, int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;

int main()
{
    fast
    int k;
    cin>>k;
    string s;
    cin>>s;
    int n = s.length();
    if(n <= k)
    {
        cout<<s;
    }
    else
    {
        cout<<s.substr(0,k)+"...";
    }
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e5+5;

int pos[MAX];
int lsw[MAX];
int lsb[MAX];

int main(){
	int N,K;
	cin>>N>>K;
	lli a[MAX];
	rep(i,N){
		cin>>a[i];
		if(a[i]>0){
			pos[i]=1;
			lsw[i]=1;
			lsb[i]=1;
		}
	}
	lli ans=0;
	lli wh=0;
	lli bl=0;
	//ラストwhite
	rep(i,K)lsw[i]=0;
	rep(i,N)wh+=lsw[i]*a[i];
	ans=max(ans,wh);
	rep(i,N-K){
		if(pos[i]==1){
			wh+=a[i];
		}
		if(pos[i+K]==1){
			wh-=a[i+K];
		}
		ans=max(ans,wh);
	}
	//ラストblack
	rep(i,K)lsb[i]=1;
	rep(i,N)bl+=lsb[i]*a[i];
	ans=max(ans,bl);
	rep(i,N-K){
		if(pos[i]==0){
			bl-=a[i];
		}
		if(pos[i+K]==0){
			bl+=a[i+K];
		}
		ans=max(ans,bl);
	}
	cout<<ans;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

vector<ll> v(200001), G[200001];
bool used[200001];

int main(){	
	long long N;
	long long Q;
	scanf("%lld",&N);
	ll a,b;
	scanf("%lld",&Q);
	ll x,p;
	for(int i = 0 ; i <= (N-1)-1 ; i++){
		scanf("%lld",&a);
		scanf("%lld",&b);
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for(int i = 0 ; i <= Q-1 ; i++){
		scanf("%lld",&p);
		scanf("%lld",&x);
		p--;
		v[p] += x;
	}
	priority_queue<ll> que;
	que.push(0);
	while (!que.empty()) {
		ll t = que.top();
		que.pop();
		// cout << t << endl;
		used[t] = true;
		rep(i, G[t].size()) {
			if (!used[G[t][i]]) {
				que.push(G[t][i]);
				v[G[t][i]] += v[t];
			}
		}
	}
	rep(i, N-1) {
		cout << v[i] << " ";
	}
	cout << v[N-1] << endl;
	return 0;
}



Measured memory_bytes: 18160
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <complex>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(4);
    int r, n;
    while(cin >> r >> n, r or n)
    {
        int hight[50] = {};
        for(int k = 0; k < n; k++)
        {
            int x1, x2, h; cin >> x1 >> x2 >> h;
            x1 += 20, x2 += 20;
            for(int i = x1; i < x2; i++) hight[i] = max(hight[i], h);
        }
        double ans = 1e5;
        for(int i = -r + 1; i < r; i++)
        {
            int y = min(hight[i + 19], hight[i + 20]);
            double t = y + r - sqrt(r * r - i * i);
            ans = min(ans, t);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3256
#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

int64 gcd(int64 a,int64 b){
  int64 r=a%b;
  while(r>0){
    a=b;b=r;r=a%b;
  }
  return b;
}

int64 calc(int64 n,int64 x){
  int64 g=gcd(n,x);
  return g*3*(n/g-1);
}

void run(void){
  int64 n,x;
  scanf("%lld%lld",&n,&x);
  printf("%lld\n",calc(n,x));
}

int main(void){
  run();
  return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

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

const ll mod=1000000007;
//head

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

    int r, c;
    cin >> r >> c;
    vector<string> g;
    for(int i = 0; i < r; i++) {
        string s;
        cin >> s;
        g.pb(s);
    }
    vector<vi> dp(r,vi(c,0));
    if(g[0][0] == '.') dp[0][0] = 1;

    for(int i = 0; i < r; i++) {
        for(int j = 0; j < c; j++) {
            if(g[i][j] == '.') {
                if(i > 0)
                    dp[i][j] += dp[i-1][j];
                dp[i][j] %= mod;
                if(j > 0)
                    dp[i][j] += dp[i][j-1];
                dp[i][j] %= mod;
            }
        }
    }
    cout << dp[r-1][c-1] << endl;
    return 0;
}


Measured memory_bytes: 5248
l = list(map(int, input().split()))
A = l[0]
B = l[1]
C = l[2]

if(A == B):
    if(A != C):
        print("Yes")
    else:
        print("No")
else:
    if(A != C):
        if(B == C):
            print("Yes")
        else: print("No")
    else:
        print("Yes")

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

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

int n;
int a[11];

bool rec(int idx, int l, int r) {
   if (idx == 10) return true;

   bool x = false, y = false;
   int val = a[idx];
   if (l < val) x = rec(idx+1, val, r);
   if (r < val) y = rec(idx+1, l, val);

   return x || y;
}

int main() {
   cin >> n;
   while (n--) {
      rep (i, 10) cin >> a[i];
      puts(rec(0, -1, -1)?"YES":"NO");
   }

   return 0;
}


Measured memory_bytes: 3008
map_ = ( \
        (1,4) # start
        ,(-1,2)
        ,(5,3) 
        ,(4,1) # goal
        ,(1,-1)
        ,(3,4)
        )

while 1:
    x = input()
    if x == '#':break
    
    pt = 0
    for v in map(int,list(x)):
        pt = map_[pt][v]
        if pt == -1: break

    print("Yes" if pt == 3 else "No")
        

Measured memory_bytes: 6720
#include<stdlib.h>
#include<iostream>
#include<cstdio>
#include<unordered_map>
#include<unordered_set>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<map>
#include<string.h>
#include<queue>
#define P pair<int,int>
using namespace std;

string a[800];
int mincost[800][800];
bool OK[800][800];
int dx[4] = { -1,0,0,1 }, dy[4] = { 0,-1,1,0 };
signed main() {
	P S;
	int b, c, d; cin >> b >> c >> d;
	for (int e = 0; e < b; e++) {
		cin >> a[e];
		for (int f = 0; f < c; f++) {
			if (a[e][f] == 'S') {
				S = { e,f };
			}
		}
	}
	OK[S.first][S.second] = true;
	queue<P>Q;
	memset(mincost, 0x3f, sizeof(mincost));
	Q.push({ S.first, S.second });
	mincost[S.first][S.second] = 0;
	while (Q.size()) {
		P t = Q.front(); Q.pop();
		if (mincost[t.first][t.second] > d) {
			while (Q.size())Q.pop();
			break;
		}
		OK[t.first][t.second] = true;
		for (int u = 0; u < 4; u++) {
			int n = t.first + dx[u], m = t.second + dy[u];
			if (n >= 0 && n < b&&m >= 0 && m < c&&mincost[n][m]>100000 && a[n][m] != '#') {
				mincost[n][m] = mincost[t.first][t.second] + 1;
				Q.push({ n,m });
			}
		}
	}
	for (int n = 0; n < b; n++) {
		for (int m = 0; m < c; m++) {
			if ((n == 0 || m == 0 || n + 1 == b || m + 1 == c)&&OK[n][m]) {
				cout << 1 << endl;
				return 0;
			}
		}
	}
	for (int i = 2;; i++) {
		memset(mincost, 0x3f, sizeof(mincost));
		for (int n = 0; n < b; n++) {
			for (int m = 0; m < c; m++) {
				if (OK[n][m]) {
					Q.push({ n,m });
					mincost[n][m] = 0;
				}
			}
		}
		while (Q.size()) {
			P t = Q.front(); Q.pop();
			if (mincost[t.first][t.second] > d) {
				while (Q.size())Q.pop();
				break;
			}
			OK[t.first][t.second] = true;
			for (int u = 0; u < 4; u++) {
				int n = t.first + dx[u], m = t.second + dy[u];
				if (n >= 0 && n < b&&m >= 0 && m < c&&mincost[n][m]>100000) {
					mincost[n][m] = mincost[t.first][t.second] + 1;
					Q.push({ n,m });
				}
			}
		}
		for (int n = 0; n < b; n++) {
			for (int m = 0; m < c; m++) {
				if ((n == 0 || m == 0 || n + 1 == b || m + 1 == c) && OK[n][m]) {
					cout << i << endl;
					return 0;
				}
			}
		}
	}
}

Measured memory_bytes: 6220
#include <bits/stdc++.h>
#define MAX_N 10000
#define INF 1e9

using namespace std;

typedef int long long ll;
typedef int long l;
typedef pair<int, int> Pii;
const ll MOD = 1000000007;

int dp[101][10001];  // dp[i+1][j]:=i番目までで重さがj以下
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, W;
    int v[100];
    int w[100];
    cin >> n >> W;
    for (int i = 0; i < n; i++) {
        cin >> v[i] >> w[i];
    }
    for (int j = 0; j <= W; j++) {
        for (int i = 0; i < n; i++) {
            if (j - w[i] >= 0)
                dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
            else
                dp[i + 1][j] = dp[i][j];
        }
    }
    cout << dp[n][W] << endl;


    return 0;
}


Measured memory_bytes: 7068
n = int(input())
X = list(map(int, input().split()))
low = min(X)
high = max(X)
ans = []

for p in range(low, high-low+1):
  dist = 0
  for x in X:
    dist += (x-p)**2
  ans.append(dist)
if len(ans) != 0:
  print(min(ans))
else:
  print(0)

Measured memory_bytes: 3064
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


l = int(input())
a = [None]*l
for i in range(l):
    a[i] = int(input())
dp = [[float("inf")]*(l+1) for _ in range(5)]
for i in range(5):
    dp[i][0] = 0
def c1(v):
    if v==0:
        return 2
    else:
        return v%2
def c2(v):
    if v%2==0:
        return 1
    else:
        return 0
for i in range(1,l+1):
    v = a[i-1]
    m = dp[0][i-1]
    dp[0][i] = m + v
    m = min(m, dp[1][i-1])
    dp[1][i] = m + c1(v)
    m = min(m, dp[2][i-1])
    dp[2][i] = m + c2(v)
    m = min(m, dp[3][i-1])
    dp[3][i] = m + c1(v)
    m = min(m, dp[4][i-1])
    dp[4][i] = m + v
ans = min(dp[i][l] for i in range(5))
print(ans)

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

int main()
{
  int n,r;
  for(;cin>>n>>r;)
    {
      int cc[r];
      for(int i=0;i<r;i++)
     	  cin>>cc[i];
      vector<int> sr;
      for(int i=0;i<n;i++)
	sr.push_back(i);

      for(int xx=0;xx<r;xx++)
	{
	  //  cout<<"xx"<<xx<<endl;
	  vector<int> a,b,c;
	  for(int i=0;i<n/2;i++)
	    b.push_back(sr[i]);
	  for(int i=n/2;i<n;i++)
	    a.push_back(sr[i]);

	while(a.size()!=0 || b.size()!=0 )
	  {
	    // cout<<"size"<<a.size() <<" "<<b.size()<<endl;
	    for(int i=0;i<cc[xx] && a.size()!=0;i++)
	      {
		//	cout<<"a-i "<<i<<endl;
		c.push_back(a[0]);
		a.erase(a.begin());
	      }
	    for(int i=0;i<cc[xx] && b.size()!=0;i++)
	      {
		//	cout<<"b-i "<<i<<endl;
		c.push_back(b[0]);
		b.erase(b.begin());
	      }
	  }
	sr=c;
	/*
	for(int i=0;i<sr.size();i++)
	  cout<<sr[i]<<" ";
	cout<<endl;
	*/
      }
      cout<<sr[sr.size()-1]<<endl;
    }
}

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

using namespace std;

int main(void) {
	int a, b, c, d;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	scanf("%d", &d);

	while(a>0 && c>0) {
		c -= b;
		a -= d;
		if (c<=0) {
			printf("Yes\n");
			break;
		}
		if (a<=0) {
			printf("No\n");
		}
	}



	return 0;
}

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

using namespace std;

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

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

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

int n, m;
int s[100100];
int a;

int main(){
	cin >> n >> m;
	int ans = 0;
	s[1] = 0;
	FOR(i, 2, n + 1)cin >> s[i];
	FOR(i, 1, n + 1)s[i + 1] += s[i];
	int now = 1;
	REP(i, m){
		cin >> a;
		ans = (ans + abs(s[now + a] - s[now])) % 100000;
		now += a;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1552
#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 k,x;
   cin >> k >> x;

   if(500*k >= x) cout << "Yes" << endl;
   else cout << "No" << endl;
   return 0;  
}

Measured memory_bytes: 256
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
import           Data.Maybe
import           Data.Int
import           Data.List
import           Data.Char
  -- import qualified Data.Vector.Unboxing as VU
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import           Data.List (scanl')
import           Data.IORef
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Control.Applicative

readInt = BS.readInt . BS.dropWhile isSpace
getVector f = VU.unfoldr f <$> BS.getLine
getIntVector = getVector readInt
getBSVector = getVector BS.uncons

main = do
  [a,b,c,k] <- map read . words <$> getLine :: IO [Int]


  print $ solve a b c k

solve a b c k = if k <= a
                then k
                else if k-a <= b
                     then a
                     else a - (k-a-b)


Measured memory_bytes: 3820
using System.Linq;
using System.Collections.Generic;
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var ary = new int[n, 5];
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(' ');
                for (int j = 0; j < 4; j++)
                {
                    ary[i, j] = int.Parse(line[j]);
                    if (j == 1 | j == 3) ary[i, 4] += 4 * ary[i, j];
                    if (j == 2) ary[i, 4] += 9 * ary[i, j];
                }
            }
            string[] line2 = Console.ReadLine().Trim().Split(' ');
            var emax = new int[5];
            for (int i = 0; i < 3; i++) emax[i + 1] = int.Parse(line2[i]);
            emax[4] = int.Parse(line2[3]);
            var oklist = new List<int>();
            for (int i = 0; i < n; i++)
            {
                var okflg = 0;
                for (int j = 1; j <= 4; j++)
                    if (ary[i, j] > emax[j]) okflg = 1;
                if (okflg == 0) oklist.Add(ary[i, 0]);
            }
            if (oklist.Count() == 0) Console.WriteLine("NA");
            else
            {
                foreach (var x in oklist) Console.WriteLine(x);
            }
        }
    }
}

Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

int d[305][305][305];

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  for (int i = 0; i < n; ++i) {
    d[i][i][0] = 1;
  }
//  int res = 0;
  for (int l = 2; l <= n; ++l) {
    for (int i = 0; i + l <= n; ++i) {
      int j = i + l - 1;
      for (int t = 0; t <= k; ++t) {
        d[i][j][t] = max(d[i+1][j][t], d[i][j-1][t]);
        if (s[i] == s[j]) d[i][j][t] = max(d[i][j][t], d[i+1][j-1][t] + 2);
        if (t) {
          d[i][j][t] = max(max(d[i][j][t], d[i+1][j-1][t-1] + 2), d[i][j][t-1]);
        }
//        res = max(res, d[i][j][t]);
      }
    }
  }
  cout << max(1, d[0][n-1][k]) << endl;
  return 0;
}

Measured memory_bytes: 110848
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#define pb push_back
#define mod 1000000007
using namespace std;
typedef long long int ll;

int main(void){
  string s;
  cin>>s;

  bool f1,f2;
  f1=f2=false;
  for(int i=0;i<s.size();i++){
    if(s[i]=='C') f1=true;
    if(f1&&s[i]=='F') f2=true;
  }
  cout<<(f2?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    N, M = map(int, readline().split())
    if N == M:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) os << "[" << el.first << " " << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) os << el << " "; return os; }

ll Q;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> Q;
}

int solve(){
    ll sumB=0;
    int n=0;
    // ll mid=0;
    ll f=0;
    multiset<pair<ll,int>> se;
    multiset<pair<ll,int>>::iterator mid;
    vector<pair<int,ll>> ans;
    for (int i = 0; i < Q; i++)
    {
        int q;
        cin >> q;
        if(q==1){
            n++;
            ll a,b;
            cin >> a >> b;
            se.insert({a,n});
            sumB+=b;
            if(n==1){mid = se.begin();}
            else if(n%2==0 && a<(*mid).first){
                // a1 a2 a3 からanの追加
                // a a1 a2 a3 mid=a2→a1の場合とか
                f+=abs((*mid).first-a);
                --mid;
                // auto itr = se.find(mid);
                // ll mid_tmp = max(a,*(--itr));
                // f+=abs(mid-mid_tmp);
                // mid = mid_tmp;
            }
            else if(n%2==1 && a>=(*mid).first){
                f+=abs((*mid).first-a);
                // auto itr = se.find(mid);
                // ll mid_tmp = max(a,*(++itr));
                auto mid_tmp = mid;
                mid_tmp++;
                f+=((*mid).first-(*mid_tmp).first);
                mid = mid_tmp;
            }
            else{f+=abs((*mid).first-a);}
        }
        else{
            ans.emplace_back((*mid).first,f+sumB);
        }
    }

    for(auto a:ans) cout << a.first << " " << a.second << "\n";
    return 0;
}

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 12800
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, int n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n in O(log(n)) time

const int MOD = 1000000007; //10^9+7
const double PI = 3.1415926535897932384626;

/*********** variables ************/
lng N, M;
/**********************************/


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

    lng scc = min(N, M/2);
    lng cccc = (M-scc*2)/4;
    cout << scc + cccc << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

#include <iostream>
 
int main(void)
{
    int64_t r;
    std::cin >> r;

    std::cout << (3 * r * r) << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
	int map[3][3];
	bool flag = true;
	for(int i=0;i<3;++i){
		for(int j=0;j<3;j++){
			cin >> map[i][j];
		}
	}
	int a[3],b[3];
	a[0] = 0;
	for(int i=0;i<3;i++){
		b[i] = map[0][i] - a[0];
	}
	for(int i=0;i<3;i++){
		a[i] = map[i][0] - b[0];
	}
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			if(a[i] + b[j] != map[i][j])flag = false;
		}
	}
	if(flag)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

int main()
{
    int r;
    std::cin >> r;

    std::cout << r * r << std::endl;
}


Measured memory_bytes: 888
def main():
    n=input()
    a=[int(i) for i in input().split()]
    ans=0
    f=False
    while True:
        for k,v in enumerate(a):
            if v%2==0:
                a[k]=a[k]//2
            else:
                print(ans)
                f=True
                break
        if f:
            break
        else:
            ans+=1

if __name__=='__main__':
    main()


Measured memory_bytes: 2940
use strict;
use warnings;

my $n = <STDIN>;
chomp $n;
my @d;
{
    for (my $i=0; $i<$n; $i++)
    {
        my $in = <STDIN>;
        chomp $in;
        $d[$i] = $in;
    }
}
@d = sort { $b <=> $a } @d;

my $ans = 1;
for (my $i=1; $i<$n; $i++)
{
    $ans++ if $d[$i]<$d[$i-1];
}

print "$ans\n";

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define INF 1e9+7
#define ll long long
#define f(x) for(ull i=0;i<x;i++)
#define F first
#define S second
#define N 100005
#define M 1000000007
#define mp make_pair
#define ull unsigned long long
#define sc(n) scanf("%d",&n)
#define gcd __gcd
using namespace std;
int main() {
	ios::sync_with_stdio(false);
    ll n,k,s,t;
    ll c,sum=0,p;
    cin>>n>>s>>t;
    cin>>p;
    for(int i=1;i<n;i++){
        cin>>c;
        sum+=min((c-p)*s,t);
        p=c;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
'use strict';

const ABC_LIMIT = 1200;
const ARC_LIMIT = 2800;

const process = input => {
    if (input < ABC_LIMIT) {
        return 'ABC';
    } else if (input < ARC_LIMIT) {
        return 'ARC';
    }

    return 'AGC';
}

console.log(process(parseInt(require("fs").readFileSync("/dev/stdin", "utf8").trim())));

Measured memory_bytes: 7372
import collections
n,k = map(int,input().split())

a = list(map(int,input().split()))

b = collections.Counter(a)
b = sorted(b.items(), key=lambda x:x[1])
c = set(a)

if len(c) <= k:
    print(0)
else:
    ans = 0
    b = b[:len(b)-k]
    for i in b:
        ans +=i[1]
        
    print(ans)        

Measured memory_bytes: 41356
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long 
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl; 
#define cno cout << "No" << endl;
#define mod (long long)1000000007
#define mod2 (long long)998244353
#define INT_MAX1 900000000
#define MAXN 2000000
#define INF INT_MAX



 
void solve()
{
    int n,m,k1;
    cin >> n >> m >> k1;
    string s[n];
    int ans = 0;
    inp(s, n);
    rep(i,0,(1<<n)-1)
        rep(j,0,(1<<m)-1)
        {
            string x[n];
            rep(i,0,n-1)
                x[i] = s[i];
            rep(k,0,(n-1))
            {
                bool f = (bool)((1<<k)&(i));
                if(!f)
                    continue;
                rep(l,0,m-1)
                    x[k][l] = '.';
            }

            rep(k,0,(m-1))
            {
                bool f = (bool)((1<<k)&(j));
                if(!f)
                    continue;
                rep(l,0,n-1)
                    x[l][k] = '.';
            }

            int cnt = 0;
            rep(i,0,n-1)
                rep(j,0,m-1)
                {
                    cnt += (x[i][j] == '#');
                }

                      if(cnt == k1)
                ans++;


        }
    cout << ans << endl;
}


signed main()
{
    
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,x;
    cin>>n>>x;
    int sum=0,X=0;
    for(;x>=X;sum++){
        int a;
        cin>>a;
        X+=a;
    }
    if(sum<=n+1) cout<<sum;
    else cout<<n+1;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
        int count;
        int[] array1;
        int[] array2;
        int[] array3;
        int flag = 0;

        try{
            Scanner scan = new Scanner(System.in);
            String str = scan.next();

            count = Integer.parseInt(str);

            if(count > 10000){
                throw new Exception("ERROE");
            }
            array1 = new int[count];
            array3 = new int[count];

            for(int i = 0; i < array1.length; i++){
                str = scan.next();
                array1[i] = Integer.parseInt(str);
            }

            str = scan.next();
            count = Integer.parseInt(str);

            if(count > 500){
                throw new Exception("ERROE");
            }
            array2 = new int[count];
            for(int i = 0; i < array2.length; i++){
                str = scan.next();
                array2[i] = Integer.parseInt(str);
            }


            //配列の確認部分
            // for(int i = 0; i < array1.length; i++){
            //     System.out.print(array1[i] + " ");
            // }
            // System.out.println();
            // for(int i = 0; i < array2.length; i++){
            //     System.out.print(array2[i] + " ");
            // }
            // System.out.println();

            count = 0;
            for(int i = 0; i < array1.length; i++){
                for(int j = 0; j < array2.length; j++){
                    flag = 0;
                    if(array1[i] == array2[j]){
                        for(int k = 0; k < count; k++){
                            if(array1[i] == array3[k]){
                                flag = -1;
                                break;
                            }
                        }
                        if(flag != -1){
                            array3[count] = array1[i];
                            count++;
                        }
                    }
                }
            }

            System.out.println(count);

        }catch(Exception e){
            System.out.println("ERROR");
        }

    }
}



Measured memory_bytes: 38764
#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(){
    string s;
    cin >> s;
    int l;
    l=s.size();
    string s2;
    int s3,ans=1000;
    rep(i,l-2){
        s2=s.substr(i,3);
        //s4=s2;
        s3=atoi(s2.c_str());
        ans=min(ans,abs(753-s3));
        //cout << s2 << endl;
    }

    cout << ans << endl;
    

    return 0;
}

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

#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define F first
#define S second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pll = pair <ll, ll>;
using ld = long double;
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;
// const int mod = 998244353;
const ll inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-7;

const int N = 2e5 + 66;

bool bit (int a, int j) {
	return (1 << j) & a;
}

int cnt[N][22];

void solve () {
	int n;
	cin >> n;
	for (int i = 1, a ; i <= n ; ++ i) {
		cin >> a;
		for (int j = 0 ; j < 22 ; ++ j) {
			cnt[i][j] = cnt[i - 1][j] + bit (a, j);
			// cout << cnt[i][j] << " ";
		}
		// cout << "\n
	}
	ll ans = 0;
	for (int i = 1 ; i <= n ; ++ i) {
		int l = 0, r = i - 1, res = i;
		while (l <= r) {
			int m = (l + r) / 2;
			bool ok = true;
			for (int j = 0 ; j < 22 ; ++ j) {
				ok &= (cnt[i][j] - cnt[m][j] <= 1);
			}
			if (ok) {
				res = m;
				r = m - 1;
			}
			else {
				l = m + 1;
			}
		}
		// cout << i << " " << res << "\n";
		ans += i - res;
	}
	cout << ans;
}

int main () {
	ios;
	// double start_time = clock();
	// cout << fixed << setprecision (10);
	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
		cout << "\n";
	}
	// cerr << (clock() - start_time) / CLOCKS_PER_SEC;
}


Measured memory_bytes: 17408
#include<stdio.h>
#include<stdlib.h>

#define POS(i,j) (((i)+1)*(w+2)+(j)+1)

void run(void){
  int h,w;
  scanf("%d%d",&h,&w);
  char *s=(char *)calloc((h+2)*(w+2)+1,sizeof(char));
  int i,j;
  for(i=0;i<h;i++) scanf("%s",s+POS(i,0));
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(s[POS(i,j)]=='#') continue;
      int c=0;
      int a,b;
      for(a=-1;a<=1;a++){
	for(b=-1;b<=1;b++){
	  if(s[POS(i+a,j+b)]=='#') c++;
	}
      }
      s[POS(i,j)]='0'+c;
    }
  }
  for(i=0;i<h;i++) printf("%s\n",s+POS(i,0));
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
# define ll long long
# define inf 1e9+5
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
# define maxn 100005
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
ll dp[101][100005];
int main(){
	ll n,W;
	cin>>n>>W;
	vector<ll>v(n+1);
	vector<ll>w(n+1);
	
	for(ll i=1;i<=n;i++){
		
		cin>>w[i];
		cin>>v[i];
		}
	for(ll i=1;i<=n;i++){
	for(ll j=1;j<=W;j++){
		if(j-w[i]>=0)
		dp[i][j]=max(dp[i-1][j-1],dp[i-1][j-w[i]]+v[i]); 
		else dp[i][j]=dp[i-1][j];
		
		}
	}
	ll ans=0;
	for(ll i=0;i<=W;i++)
	 ans=max(ans,dp[n][i]);
	cout<<ans<<"\n";
		
/*

for(ll i=0;i<=n;i++){
		for(ll j=0;j<=W;j++){ 
			 
			 cout<<dp[i][j]<<" ";
			 
		}
		cout<<"\n";
		 
	 }

*/
			
	
	
	
	
	
	return 0;
	}


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

int main()
{
    while (1)
    {
        string s;
        cin >> s;
        if (s == "-")
        {
            break;
        }
        int m;
        cin >> m;
        int h, sum = 0;
        for (int i = 0; i < m; i++)
        {
            cin >> h;
            sum += h;
        }
        string ans;
        for (int i = sum % s.size(); i < s.size(); i++)
        {
            ans += s[i];
        }
        for (int i = 0; i < sum % s.size(); i++)
        {
            ans += s[i];
        }
        cout << ans << endl;
    }
}


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

struct Node {
    vector<int> e;
    int color;
};

struct Edge {
    int u, v;
    int64_t w;
};

int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N;
    cin >> N;
    vector<Node> node(N);
    vector<Edge> edge(N - 1);
    for(int i = 0; i < N; i++) {
        node[i].e = vector<int>();
        node[i].color = -1;
    }
    node[0].color = 0;
    for(int i = 0; i < N - 1; i++) {
        int u, v;
        int64_t w;
        cin >> u >> v >> w;
        u--, v--;
        edge[i] = {u, v, w};
        node[u].e.push_back(i);
        node[v].e.push_back(i);
    }
    queue<int> q;
    q.push(0);
    while(!q.empty()) {
        int x = q.front();
        q.pop();
        int c = node[x].color;
        for(auto itor = node[x].e.begin(); itor != node[x].e.end(); itor++) {
            int y = (edge[*itor].u == x ? edge[*itor].v : edge[*itor].u);
            if(node[y].color >= 0) continue;
            q.push(y);
            node[y].color = (edge[*itor].w & 1) != c;
        }
    }
    for(int i = 0; i < N; i++) {
        cout << node[i].color << endl;
    }
    return 0;
}

Measured memory_bytes: 8320
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <cstring>
#include <iterator>
#include <typeinfo>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int MOD=1e9+7;
const int INF=1e9+7;
const double PI=3.141592653589793238462643383279;
//
int main(){
  long long N;
  cin>>N;
  long long TA,AO;
  cin>>TA>>AO;
  FOR(i,1,N){
    long long T,A;
    cin>>T>>A;
    long long H=max((TA+T-1)/T,(AO+A-1)/A);
    TA=T*H;
    AO=A*H;
  }
  cout<<TA+AO<<endl;
  return 0;
}


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

using namespace std;

#define INF 2140000000
#define MOD 1000000007

int main() {
	int a;
	int sum = 0, minn = 11;
	bool flag = 0;

	cin >> a;

	if (a % 10) {
		flag = 1;
		sum += a - (a % 10) + 10;
		minn = min(a % 10, minn);	
	}
	else {
		sum += a;
	}
	
	cin >> a;

	if (a % 10) {
		flag = 1;
		sum += a - (a % 10) + 10;
		minn = min(a % 10, minn);
	}
	else {
		sum += a;
	}

	cin >> a;

	if (a % 10) {
		flag = 1;
		sum += a - (a % 10) + 10;
		minn = min(a % 10, minn);
	}
	else {
		sum += a;
	}

	cin >> a;

	if (a % 10) {
		flag = 1;
		sum += a - (a % 10) + 10;
		minn = min(a % 10, minn);
	}
	else {
		sum += a;
	}

	cin >> a;

	if (a % 10) {
		flag = 1;
		sum += a - (a % 10) + 10;
		minn = min(a % 10, minn);	
	}
	else {
		sum += a;
	}

	if (flag) {
		cout << sum - 10 + minn;
	}
	else {
		cout << sum;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

signed main(){
  string s;
  cin>>s;
  string t="";
  int c;
  cin>>c;
  for(int i=0;i<(int)s.size();i+=c)t+=s[i];
    cout<<t<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static ArrayList<Integer> list = new ArrayList<>();
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int m = parseInt(sc.next());
		int[] p = new int[m];
		String[] s = new String[m];
		for(i=0;i<m;i++) {
			p[i] = parseInt(sc.next());
			s[i] = sc.next();
		}
		sc.close();
		boolean[] acf = new boolean[n+1];
		int[] wac = new int[n+1];
		int ac = 0;
		int wa = 0;
		for(i=0;i<m;i++) {
			if(s[i].equals("WA")) {
				if(!acf[p[i]]) {
					wac[p[i]]++;
				}
			} else {
				if(!acf[p[i]]) {
					ac++;
					wa+=wac[p[i]];
					acf[p[i]]=true;
				}
			}
		}
		out.printf("%d %d%n", ac, wa);
	}
}


Measured memory_bytes: 67536
package main

import (
	"bufio"
	"fmt"
	"os"
)

var debug = false

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var n, y int
	fmt.Scanf("%d %d", &n, &y)

	res := GetAnswer(n, y)
	fmt.Printf("%v\n", res)
}

// GetAnswer ...
func GetAnswer(n, y int) string {
	prt("inputs: n:%v y%v", n, y)
	a := -1
	b := -1
	c := -1
	result := fmt.Sprintf("%d %d %d\n", a, b, c)
	if y > (10000*n) || y < (1000*n) {
		return result
	}
FOR_LABEL:
	for i := n; i >= 0; i-- {
		if 10000*i > y {
			continue
		}
		for j := n - i; j >= 0; j-- {
			if (10000*i)+(5000*j) > y {
				continue
			}
			h := n - i - j
			res := (i * 10000) + (j * 5000) + (h * 1000)
			prt("testing: yukichi:%d nitobe:%d soseki:%d", i, j, h)
			if res == y {
				a = i
				b = j
				c = h
				break FOR_LABEL
			}
		}
	}
	result = fmt.Sprintf("%d %d %d", a, b, c)
	prt("%v\n", result)
	return result
}

func prt(format string, inputs ...interface{}) {
	if debug {
		fmt.Printf(format+"\n", inputs...)
	}
}

Measured memory_bytes: 6656
from collections import deque

N, X, Y = map(int, input().split())

ans_list = [0 for _ in range(N-1)]

for i in range(1, N+1): #1 ～ N start
    for j in range(i+1, N+1): # i+1 ～ N goal
        ans1 = j - i
        ans2 = abs(i-X) + 1 + abs(j-Y)
        ans_list[min(ans1, ans2)-1] += 1
print(*ans_list, sep="\n")

Measured memory_bytes: 9644
#include<stdio.h>
int main(){
  int a,b,c,d,x,i,j,k,r=0;
  scanf("%d%d%d%d",&a,&b,&c,&x);
  for(i = 0;i<=x/500;i++)for(j = 0;j<=(x-500*i)/100;j++){
      k = x -500*i-100*j;
      r+=k%50==0&&c>=k/50&&a>=i&&b>=j;
    }
  printf("%d\n",r);
  return 0;
}


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

int main(){
  int a[3];
  for(int i = 0; i < 3; i++) cin >> a[i];
  int k;
  cin >> k;
  for(int i = 0; i < 3; i++){
    for(int j = i + 1; j < 3; j++){
      if(a[i] < a[j]){
	swap(a[i], a[j]);
      }
    }
  }
  for(int i = 0; i < k; i++) a[0] *= 2;
  cout << a[0] + a[1] + a[2] << endl;
  return 0;
}


Measured memory_bytes: 256