akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int N;
cin >> N;
vector<string> A(N);
vector<int> B(4);
for(int k=0; k<4 ; k++)
{
    B.at(k) == 0;
}
for(int i=0; i<N;i++)
{
  cin >> A.at(i);
  if(A.at(i)=="AC")B.at(0)++;
  if(A.at(i)=="WA")B.at(1)++;
  if(A.at(i)=="TLE")B.at(2)++;
  if(A.at(i)=="RE")B.at(3)++;
}
cout << "AC x " << B.at(0) << endl;
cout << "WA x " << B.at(1) << endl;
cout << "TLE x " << B.at(2) << endl;
cout << "RE x " << B.at(3) << endl;
}

Measured memory_bytes: 6344
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<vector<int>> a(3,vector<int>(3));
	rep(i,3)rep(j,3) cin>>a[i][j];
	int n;
	cin>>n;
	rep(i,n){
		int b;
		cin>>b;
		rep(j,3)rep(k,3){
			if(a[j][k]==b) a[j][k]=-1;
		}
	}
	bool flag=false;
	if(a[0][0]==a[1][1] && a[1][1]==a[2][2] && a[0][0]==-1) flag=true;
	if(a[0][2]==-1 && a[1][1]==-1 && a[2][0]==-1) flag=true;
	rep(i,3){
		bool f=true;
		rep(j,3){
			if(a[i][j]!=-1) f=false;
		}
		if(f) flag=true;
	}
	rep(j,3){
		bool f=true;
		rep(i,3){
			if(a[i][j]!=-1) f=false;
		}
		if(f) flag=true;
	}
	if(flag) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main() {
    char a[20], b[20], c[20];
    int d, e;
    scanf("%s %s\n", &a, &b);
    scanf("%d %d\n", &d, &e);
    scanf("%s", &c);

    if(strcmp(a, c) == 0) {
        printf("%d %d", d - 1, e);
    } else if (strcmp(b, c) == 0) {
        printf("%d %d", d, e - 1);
    }
    return 0;
}

Measured memory_bytes: 3148
#include<stdio.h>
int main(){
    char strt[100];
    char *ptime=strt;
    int i=0;
    int j=0;
    int flag=0;
    int ttl=0;
    int a[5] = {0};
    int tmp=0;
    int W, H, x, y, r;
    char strflag[4][10] = {0};
    fgets(strt, sizeof(strt), stdin);
     
    //数字をすべてchar型で読み込みstrflagに一文字ずつ格納していっている。
    while(*ptime){
        //改行文字削除して文字列の最後にNULLを入れる
        if(*ptime=='\n'){
            *ptime='\0';
        }else if(*ptime==' '){  //ひとまとまりの数字を読み込むとflagをインクリメントすることで、flagと数字のまとまりを対応させる
            flag++;
            i=0;
            ptime++;
        }else{
            strflag[flag][i]=*ptime;
            i++;
            ptime++;
        }
    }
    
    W = atoi(&strflag[0]);
    H = atoi(&strflag[1]);
    x = atoi(&strflag[2]);
    y = atoi(&strflag[3]);
    r = atoi(&strflag[4]);
    
    flag=0;
    
    if(0<=x-r && x+r<=W)
       if(0<=y-r && y+r<=H)
          flag=1;
          
    if(flag==1) printf("Yes\n");
    else printf("No\n");
    
    /*
    if(atoi(&strflag[0]) > atoi(&strflag[1]) ) printf("a > b\n");
    else if(atoi(&strflag[0])< atoi(&strflag[1]) ) printf("a < b\n");
    else printf("a == b\n");
    */
    
    /*
    if( atoi(&strflag[0]) < atoi(&strflag[1]) && atoi(&strflag[1]) < atoi(&strflag[2]) ){
       printf("Yes\n");
       exit(0);
    }
    printf("No\n");
    */
    
    /*
    for(i=0; i<3; ++i) a[i] =atoi(&strflag[i]);
    
    for (i=0; i<3; ++i) {
       for (j=i+1; j<3; ++j) {
          if (a[i] > a[j]) {
             tmp = a[i];
             a[i] = a[j];
             a[j] = tmp;
          }
       }
    }
    
    for (i=0; i<2; i++) printf("%d ",a[i]);
    printf("%d\n",a[2]);
    */
    
    /*
    for (i=0; i<3; i++){
       ttl+=atoi(&strflag[i]);
    }
    printf("TTL:%d\n",ttl);
    */
    
    
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll H,W,i,j,c=0;P S,G;cin>>H>>W>>S.F>>S.S>>G.F>>G.S;bool X[H][W];ll Y[H][W];deque<P>B,C;
  REP(i,H)REP(j,W){char s;cin>>s;X[i][j]=(s=='.');Y[i][j]=H*W;}S.F--;S.S--;G.F--;G.S--;
  B.push_back(S);Y[S.F][S.S]=0;vector<P>O(4);
  O.at(0)=P(-1,0);O.at(1)=P(0,-1);O.at(2)=P(1,0);O.at(3)=P(0,1);
  while(B.size()+C.size()&&c<7000000){
    P E;if(B.size()){E=B.front();B.pop_front();}else{E=C.front();C.pop_front();}
    REP(i,4){
      ll x=E.F+O.at(i).F,y=E.S+O.at(i).S;
      if(0<=x&&x<H&&0<=y&&y<W&&X[x][y]&&Y[x][y]>Y[E.F][E.S]){
        Y[x][y]=Y[E.F][E.S];B.push_back(P(x,y));
      }
    }
    FOR(i,-2,3)FOR(j,-2,3)if(abs(i)+abs(j)>1){
      ll x=E.F+i,y=E.S+j;
      if(0<=x&&x<H&&0<=y&&y<W&&X[x][y]&&Y[x][y]>Y[E.F][E.S]+1){
        Y[x][y]=Y[E.F][E.S]+1;C.push_back(P(x,y));
      }
    }
  }
  if(Y[G.F][G.S]==H*W)Y[G.F][G.S]=-1;
  cout<<Y[G.F][G.S]<<endl;
  return 0;
}

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

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi > 

int main()
{
	string s;
	cin>>s;
	if(s.size()<4||s[0]!='Y'||s[1]!='A'||s[2]!='K'||s[3]!='I')
		cout<<"No";
	else
		cout<<"Yes";

	return 0;
}

Measured memory_bytes: 256
/*
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>

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

#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}

using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

ll factor(ll x) {
	ll ret = 1;
	ll tmp = 0;
	for (ll p = 2;;p++) {
		if (x == 1) {
			ret *= tmp + 1;
			break;
		}
		if (x % p == 0) {
			tmp += 1;
			x /= p;
			p--;
			continue;
		}
		ret *= tmp + 1;
		tmp = 0;
	}
	return ret;
}

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

	ll N;
	cin >> N;
	ll ans = 0;

	for (ll i = 1; i <= N; i++) {
		ll ret = factor(i);
		ll tmp = ret;
		ans += i * tmp;
	}

	cout << ans << endl;



EndPoint:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG

	return 0;
}


*/

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>

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

#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}

using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;

	cout << (15 - (a + b + c + d + e)) << endl;

EndPoint:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG

	return 0;
}




Measured memory_bytes: 3144
from sys import stdin
from collections import defaultdict
readline = stdin.readline


def main():
    v, e = map(int, readline().split())
    g = defaultdict(set)
    residual = [[0] * v for _ in range(v)]
    source, sink = 0, v - 1

    for _ in range(e):
        s, t, c = map(int, readline().split())
        if 0 < c and s != sink and t != source:
            g[s] |= {t}
            g[t] |= {s}
            residual[s][t] = c

    while True:
        route, flow = search(g, residual, source, sink)
        if not route:
            break
        for s, t in zip(route, route[1:]):
            residual[s][t] -= flow
            residual[t][s] += flow

    print(sum(residual[sink][i] for i in g[sink]))


def search(g, residual, source, sink):
    dfs_stack = [(source, None, float('inf'))]
    route = [None]
    visited = set()
    while dfs_stack:
        u, prev, flow = dfs_stack.pop()
        while route[-1] != prev:
            route.pop()
        route.append(u)
        visited |= {u}
        if u == sink:
            return route[1:], flow
        for v in g[u]:
            if v not in visited and 0 < residual[u][v]:
                dfs_stack.append((v, u, min(residual[u][v], flow)))
    return [], 0
main()

Measured memory_bytes: 6900
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif
int main(){
  fastIO();
  int n;
  string s;
  cin>>n>>s;
  int red=0,ans=0;
  for(int i=0;i<s.length();i++){
    if(s[i]=='R')red++;
  }
  for(int i=0;i<s.length();i++){
    if(s[i]=='W'&&red>0){
      ans++,red--;
    }else if(s[i]=='R'){
      red--;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3756
import operator
N, M = map(int, raw_input().split(" "))

PY = []
for i in range(M):
    py = map(int, raw_input().split(" "))
    py.append(i)
    PY.append(py)

PY.sort(key=operator.itemgetter(0, 1))

j = PY[0][0]
count = -1
for i in range(M):
    count += 1
    if j!= PY[i][0]:
        count = 0
        j = PY[i][0]
    PY[i].append(count)

PY.sort(key=operator.itemgetter(2))

for i in PY:
    print ("000000" + str(i[0]))[-6:]+ ("000000"+ str(i[3]+1))[-6:]

Measured memory_bytes: 41076
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j, v;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  trace(A, n);

  for(i=2;i<n+1;i++){
    v = A[i];
    j = i - 1;
    while(j >= 0&& A[j] > v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }
    trace(A,n);
  }

  return 0;
}

Measured memory_bytes: 608
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

char t[200001];

int main() {
    int n, m, c0 = 0, c1 = 0, c = 0, x = 0, i, j;
    long long ans = 0;
    vector<int> v;
    
    scanf("%s", t);
    
    n = strlen(t);
    
    for (i = 0; i < n; i++) {
        if (t[i] == '0') {
            c0++;
        } else {
            c1++;
            ans += (c1 + 1) / 2;
        }
    }
    
    if (c0 == 0) {
        printf("%lld\n", ans);
        
        return 0;
    }
    
    for (i = 0; i < n; ) {
        for (j = i; j < n; j++) {
            if (t[i] != t[j]) break;
        }
        
        if (t[i] == '0') {
            c += j - i;
        } else {
            int x = j - i;
            
            ans += (long long)c0 * (x / 2);
            
            if (x % 2 == 1) {
                v.push_back(c);
                c = 0;
            }
        }
        
        i = j;
    }
    
    v.push_back(c);
    
    m = v.size();
    
    for (i = 1; i < m; i++) {
        if (v[i] > 0) {
            v[i]--;
            ans += i + (m - i) / 2;
        }
    }
    
    for (i = 0; i < m; i++) {
        while (v[i] >= 2) {
            v[i] -= 2;
            ans += i * 2 + m - i - 1;
        }
    }
    
    for (i = m - 1; i >= 0; i--) {
        if (v[i] > 0) {
            x = m - i - 1 - x;
            ans += m - x - 1;
        }
    }
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 3524
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b) {if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b) {if(a<b) a=b;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    double n; cin >> n;
    int a = n/2 + (int)n%2;
    double ans = (double)a / n;
    cout << setprecision(8) << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>

using namespace std;

void paint(const vector<string> &field, int r, int c, vector<vector<bool>> &buf) {
    const int R = field.size();
    const int C = field[0].size();
    const char ch = field[r][c];
    queue<pair<int,int>> q;
    q.push(make_pair(r, c));
    buf[r][c] = true;
    while(!q.empty()) {
        const int cur_r = q.front().first;
        const int cur_c = q.front().second;
        q.pop();
        static const int DR[] = {0, -1, 0, 1};
        static const int DC[] = {1, 0, -1, 0};
        for(int dir = 0; dir < 4; ++dir) {
            const int nr = cur_r + DR[dir];
            const int nc = cur_c + DC[dir];
            if(nr < 0 || nr >= R || nc < 0 || nc >= C) continue;
            if(field[nr][nc] != ch && field[nr][nc] != '.') continue;
            if(buf[nr][nc]) continue;
            buf[nr][nc] = true;
            q.push(make_pair(nr, nc));
        }
    }
}

bool solve() {
    int R, C;
    if(!(cin >> C >> R)) return false;
    if(!R && !C) return false;
    vector<string> field(R);
    for(string &s : field) {
        cin >> s;
    }
    vector<vector<bool>> white(R, vector<bool>(C));
    vector<vector<bool>> black(R, vector<bool>(C));
    for(int r = 0; r < R; ++r) {
        for(int c = 0; c < C; ++c) {
            if(field[r][c] == 'W') {
                paint(field, r, c, white);
            } else if(field[r][c] == 'B') {
                paint(field, r, c, black);
            }
        }
    }
    int w = 0, b = 0;
    for(int r = 0; r < R; ++r) {
        for(int c = 0; c < C; ++c) {
            if(field[r][c] == '.') {
                if(white[r][c] && !black[r][c]) ++w;
                else if(!white[r][c] && black[r][c]) ++b;
            }
        }
    }
    cout << b << ' ' << w << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if (a + b >= 10) cout << "error";
    else cout << a + b;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <unordered_set>
using namespace std;

#define ll long long


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

	vector<int> arr(n);
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}

	sort(arr.begin(), arr.end());
	if (arr[n / 2] == arr[n / 2 - 1])
	{
		cout << 0 << endl;
	}
	else
	{
		cout << arr[n / 2] - arr[n / 2 - 1] << endl;
	}
}

Measured memory_bytes: 640
H, W = map(int, input().split())
S = [input() for _ in range(H)]


def f(i, j):
    t = [[-1] * W for _ in range(H)]
    t[i][j] = 0
    q = [(i, j)]
    while q:
        y, x = q.pop(0)
        if y - 1 >= 0 and S[y - 1][x] != '#' and t[y - 1][x] == -1:
            t[y - 1][x] = t[y][x] + 1
            q.append((y - 1, x))
        if y + 1 < H and S[y + 1][x] != '#' and t[y + 1][x] == -1:
            t[y + 1][x] = t[y][x] + 1
            q.append((y + 1, x))
        if x - 1 >= 0 and S[y][x - 1] != '#' and t[y][x - 1] == -1:
            t[y][x - 1] = t[y][x] + 1
            q.append((y, x - 1))
        if x + 1 < W and S[y][x + 1] != '#' and t[y][x + 1] == -1:
            t[y][x + 1] = t[y][x] + 1
            q.append((y, x + 1))
    return max(max(tt) for tt in t)


result = 0
for i in range(H):
    for j in range(W):
        if S[i][j] != '#':
            result = max(result, f(i, j))
print(result)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>
#include <string>

//Some constants don't work
#ifndef INT_MAX
#define INT_MAX 2147483647
#endif
#ifndef INT_MIN
#define INT_MIN -2147483648
#endif
//short hand tricks
typedef long long ll;

using namespace std;

int main(int argc, char * argv[]) {
    ios_base::sync_with_stdio(false);
    string s,t;
    cin >> s >> t;
    int res =0;
    for(int i=0; i<s.size(); i++) {
        if(s[i]!=t[i]) {
            res++;
        }
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 3860
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
struct position{
    int y, x;
};

int need_magic_cost[100000];
 
int main(){
    int H, W, D;
    cin >> H >> W >> D;
    position number_position[H * W];
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            int num;
            cin >> num;
            number_position[num - 1] = {i, j};
        }
    }
    for(int i = H * W - D - 1; i >= 0; i--){
        need_magic_cost[i] = need_magic_cost[i + D] + abs(number_position[i].y - number_position[i + D].y) + abs(number_position[i].x - number_position[i + D].x);
    }
    int Q;
    cin >> Q;
    for(int i = 0; i < Q; i++){
        int left, right;
        cin >> left >> right;
        cout << need_magic_cost[left - 1] - need_magic_cost[right - 1] << endl;
    }
}

Measured memory_bytes: 2176
#include <stdio.h>
#include <string.h>
#define MIN(x, y) (((x) > (y)) ? (y) : (x))
#define ABS(x) ((x) >= 0 ? (x) : (-(x)))

int main()
{
  int n;
  long long k;
  scanf("%d%lld", &n,&k);
  int a[200001];
  char visited[200001] = {0};
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int rem = 0;
  int offset = 1;
  int next = 1;
  for (int i = 0; i < n * 2; i++) {
    visited[next]++;
    next = a[next];
    if (visited[next] == 1) {
      rem++;
    } else if (visited[next] == 2) {
      break;
    } else {
      offset++;
    }
  }
  //printf("%d, %d\n", offset, rem);
  int m = (k <= (long long)offset) ? k : (k - (offset + 1)) % rem + (offset + 1);
  //((k - (long long)offset) % (long long)(rem) + (long long)offset);
  next = 1;
  for (int i = 0; i < m; i++) {
    next = a[next];
  }
  printf("%d", next);
  return 0;
}

Measured memory_bytes: 3128
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

int main() {
	ll N;
	cin >> N;
	string s;
	cin >> s;
	ll ans = 0;
	rep(bits,0,1<<N) {
		string zeros;
		string ones;
		rrep(i,N,0) {
			if (bits & (1 << i)) {
				ones.push_back(s[i]);
			} else {
				zeros.push_back(s[i]);
			}
		}
		/*
		if (bits == 1) {
			cout << "zeros:" << zeros << endl;
			cout << "ones:" << ones << endl;
		}
		*/
		auto dp = make_vec_nd(0, 1+zeros.size(), 1+ones.size());
		dp[0][0] = 1; 
		rep(n,1,N+1) {
			rep(z,0,min((ll)zeros.size(),n)+1) {
				ll o = n - z;
				if (o > ones.size()) {
					continue;
				}
				if (z >= 1 && s[2*N-n] == zeros[zeros.size()-z]) {
					dp[z][o] += dp[z-1][o];
				}
				if (o >= 1 && s[2*N-n] == ones[ones.size()-o]) {
					dp[z][o] += dp[z][o-1];
				}
				// cout << z << "," << o << ":" << dp[z][o] << endl;
			}
		}
		ans += dp[zeros.size()][ones.size()];
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define x real()
#define y imag()
using namespace std;
typedef complex<double> point;
double cross(point a,point b){return a.x*b.y-a.y*b.x;}

point crosspoint(point a,point b,point c,point d){
  point base=d-c;
  double d1=abs(cross(base,a-c));
  double d2=abs(cross(base,b-c));
  double t=d1/(d1+d2);
  return a+(b-a)*t;
}

int main(){
  int q;
  cin>>q;
  while(q--){
    int x1,y1,x2,y2,a1,b1,a2,b2;
    cin>>x1>>y1>>x2>>y2>>a1>>b1>>a2>>b2;
    point res=crosspoint(point(x1,y1),point(x2,y2),point(a1,b1),point(a2,b2));
    printf("%.8f %.8f\n",res.x,res.y);
  }

}

Measured memory_bytes: 1196
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			n = scanner.nextInt();
			u = scanner.nextInt();
			if ((n | u) == 0)
				break;
			need = new int[n];
			gain = new int[n];
			int all = 0;
			unit = new int[n];
			for (int i = 0; i < n; i++) {
				unit[i] = gain[i] = scanner.nextInt();
				all += unit[i];
				int k = scanner.nextInt();
				for (int j = 0; j < k; j++) {
					int x = scanner.nextInt();
					need[i] |= (1 << x);
				}
			}
			Arrays.sort(gain);
			for (int i = n - 2; i >= 0; i--)
				gain[i] += gain[i + 1];
			if (all == u) {
				System.out.println(n);
				continue;
			}
			ans = n;
			v = new boolean[1 << n];
			slove(0, 0, 0);
			System.out.println(ans);
		}
	}

	private void slove(int bit, int one, int have) {
		if (ans <= one)
			return;
		if (have >= u) {
			ans = one;
			return;
		}

		for (int i = 0; i < n; i++) {
			int a = bit | (1 << i);
			if (v[a] || (bit | need[i]) != bit)
				continue;
			v[a] = true;
			slove(bit | (1 << i), one + 1, have + unit[i]);
		}
	}

	int n, u;
	int[] need, unit, gain;
	int ans;
	boolean[] v;
}

Measured memory_bytes: 56660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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

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

int main(){
  int i,j;
  ll n,a,b;
  cin>>n>>a>>b;
  ll c=a+b;
  ll ans=n/c*a;
  n%=c;
  ans+=min(n,a);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<numeric>
#include<queue>
#include<algorithm>
#include<stack>
#include<iterator>
#include<set>
#include<utility>
#include<map>
#include<string>

#define ll long long int
#define max(x,y)        ((x>y)?x:y)
#define min(x,y)        ((x<y)?x:y)
#define PI 3.1415926535897932384626
#define REP(a, n) for (int i = a; i < n; i++)
#define pb(a) push_back(a)




using namespace std;

int main(){
	ll a ;
	double b;
	cin >> a >> b;
	ll result = (float)(a*b);
	result = trunc(result);
	cout << result; 
	return 0;
		
	
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

ll xORTrick(ll n) {
	if (n % 4 == 0) {
		return n;
	}

	if (n % 4 == 1) {
		return 1;
	}

	if (n % 4 == 2) {
		return n + 1;
	}

	return 0;
}

ll solution(ll M, ll N) {
	return xORTrick(N) ^ xORTrick(M - 1);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a, b;
	cin >> a >> b;
	ll ans = solution(a, b);
	dunk(ans);
	return 0;
}

Measured memory_bytes: 256
N, A, B, C, D = map(int, input().split())
S = '.' + input()
ans = True
if C > D:
  s = B - 1
  while s < D:
    if S[s] == '#':
      _s = s + 1
    elif S[s + 1] == '#':
      _s = s + 2
    elif S[s + 2] == '#':
      _s = s + 3
    else:
      break
    s = _s
  if s >= D:
    ans = False
s = A + 1
while s < C:
  if S[s] != '#':
    _s = s + 1
  elif S[s + 1] != '#':
    _s = s + 2
  else:
    ans = False
    break
  s = _s
s = B + 1
while s < D:
  if S[s] != '#':
    _s = s + 1
  elif S[s + 1] != '#':
    _s = s + 2
  else:
    ans = False
    break
  s = _s
print('Yes' if ans else 'No')

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define INF 2000000000	//int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int x, a, b;
	cin >> x >> a >> b;
	cout << (x - a) % b << endl;

	rtn 0;
}

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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const double PI = atan(1.0) * 4.0;
// const int MOD = 998244353;
const ll LINF = 9e18;
const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};

vector<string> s;
map<string, ll> memo;
const ll NMAX = 1e6;
ll com[1000000][10];

ll comb(ll n, ll r) {
    if(com[n][r]) return com[n][r];
    if(n < 0 || r < 0 || n < r) return 0;
    if(n == r || !r) return 1;
    return com[n][r] = comb(n - 1, r) + comb(n - 1, r - 1);
}

signed main() {
    LCIN(N);
    REP(i, N) {
        SCIN(S);
        sort(All(S));
        memo[S]++;
    }
    ll ans = 0;
    FOREACH(m, memo) {
        if(m.second >= 2) {
            ans += comb(m.second, 2);
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 13184
#include <bits/stdc++.h>
using namespace std;
// x^y≡x^(y%(p-1))mod p
// but there is a condition that x needs to be coprime to p
///assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
typedef long long int ll;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
#define  pb push_back
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fo(i,a,b) for(ll i = a; i<=b;i+=1)
#define rf(i,a,b)  for(ll i=a;i>=b;i--)
#define vll vector<ll>
#define tests() int test_cases ; cin >> test_cases ; while(test_cases--)
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define MAXN 100010
#define MOD 1000000007
#define mod 998244353
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define sp " "
#define MS(x,y) fill_n(*x, sizeof x / sizeof **x, y);
#define mem(x,y) memset(x,y,sizeof(x));
#define INF 1000000000000000000
ll power(ll x, ll y,ll p) 
{ 
    ll res = 1;     // Initialize result 
    x = x % p;
    if (y==0)return 1;
    if(x==0)return 0;   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p;    
        y = y>>1; // y = y/2 
        x = (x*x) % p;  // Change x to x^2 
    } 
    return res; 
}
int gcd(int a, int b) { if (a == 0)return b;return gcd(b % a, a);} 

ll modinv(ll a,ll p){return power(a,p-2,p);}

int solve(){
    ll k;
    ll a,b;
    cin>>k>>a>>b;
    fo(i,a,b){
        if (i%k==0)
        {
            cout<<"OK"<<endl;
            return 0;
        }
    }
     cout<<"NG"<<endl;
     return 0;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);



    
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif



    // tests(){solve();}
    solve();
    return 0;
}/*#ifndef ONLINE_JUDGE
    #endif*/

    // make_pair make_tuple  tuple<int,int,int> 

Measured memory_bytes: 3644
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

l = []
ans = 0
for t in [a,b,c,d,e]:
  if t%10 == 0:
    ans += t
  else:
    l.append(t)

if len(l) < 1:
  print(ans)
elif len(l) == 1:
  print(ans + l[0])
else:
  l = sorted(l, key=lambda x: x%10, reverse=True)

  def tyumon(t, ans):
    ans += t
    if ans % 10 == 0:
      return ans
    else:
      return (ans//10 + 1)*10

  for i in range(len(l)-1):
    ans = tyumon(l[i], ans)
  print(ans + l[-1])

Measured memory_bytes: 3064
/*
{

AuThOr Gwj
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define R(a) cin>>a
#define R2(a,b) cin>>a>>b
#define int LL
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
int n,a[200000+20];
double a_[200000+20];
int all[65][65];
signed main(){
	fastio;
	R(n);
	LL res=0;
	rb(i,1,n){
		R(a_[i]);
		;
		a[i]=llround(a_[i]*=1000000000.0);
		int A,B;
		A=B=0;
		while(a[i]%5==0){
			a[i]/=5;
			A++;
		}
		while(a[i]%2==0){
			a[i]/=2;
			B++;
		}
//		cout<<A<<" "<<B<<endl;
		rb(k,0,64)
			rb(j,0,64){
				if(k+A>=18&&j+B>=18){
					res+=all[k][j];
				}
		}
		all[A][B]++;
	}	
	cout<<res<<endl;
	return 0;
}




Measured memory_bytes: 6808
N = int(input())
o, h = N%2, N//2
arr = [0]*h
for a in map(int, input().split()):
    if a > 0:
        arr[a//2 - o] += 1
if all(c == 2 for c in arr):
    print((1 << h) % (10**9 + 7))
else:
    print(0)


Measured memory_bytes: 11124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define bit(k) (1LL<<(k))
typedef long long ll;

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

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

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

/*------------------------------------/
for library*/

/*------------------------------------*/

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

    int N,Z,W;
    cin>>N>>Z>>W;
    vector<ll> a(N);
    rep(i,N)cin>>a[i];

    if(N == 1){
        cout<<abs(a[0] - W)<<endl;
        return 0;
    }
    cout<<max(abs(a[N-1] - a[N-2]), abs(a[N-1] - W))<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define int long long
#define endl "\n"
#define print_array(name,n) for(int o=0;o<n;o++) cout<<name[o]<<" "

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
bool sortbysecond(const pair<int,int> &a,const pair<int,int> &b){
	return (a.ss>b.ss);
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int h;
    cin>>h;
    int num = 0;
    int attack = 0;
    while(h!=0){
    	h = h/2;
    	// cout<<h<<endl;
    	attack+=pow(2,num);
    	num++;
    }
    cout<<attack<<endl;
    return 0;
}

Measured memory_bytes: 512
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		boolean[] prime = sieve(999999);
		while(true){
			String s = r.readLine();
			if(s == null) break;
			int count = 0;
			int n = Integer.valueOf(s);
			for(int i = 2; i <= n; i++) {
				if(prime[i]) {
					count++;
				}
			}
			System.out.println(count);
		}
	}
	private static boolean[] sieve(int n) {
		boolean[] prime = new boolean[n+1];
		Arrays.fill(prime, true);
		prime[0]=false;
		prime[1]=false;
		int m = (int)Math.sqrt(n);
		for(int i = 2; i <= m; i++) {
			if(prime[i]) {
				for (int k = i*i; k <= n; k += i) {
					prime[k]=false;
				}
			}
		}
		return prime;
	}
}

Measured memory_bytes: 10000
n, m = map(int, input().split())
lrs = [list(map(int, input().split())) for _ in range(m)]

l_max = 1
r_min = n
for l, r in lrs:
    l_max = max(l, l_max)
    r_min = min(r, r_min)

print(max(r_min - l_max + 1, 0))


Measured memory_bytes: 27332
#include<stdio.h>
#include<string.h>
#define LEN 1000050

/*?§???????*/
typedef struct pp{
  char name[100];
  int t;
}P;

/*????????????????????£?¨?*/
void enqueue(P);
P dequeue(void);


/*??°?????????????????°*/
P Q[LEN+1];
int head=1, tail, n;/*n?????????????????° */


int main(){
  int elaps = 0;
  int i, q; /*q?????????????????????*/
  P u;

  scanf("%d %d", &n, &q);

  tail = n+1;

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  while(n!=0){
    u = dequeue(); /*?????????????´????????????????*/

    
    if(u.t>=q){
    u.t = u.t - q;
    elaps += q;
    }
    else{
        elaps += u.t;
        u.t = 0;
      }


    if(u.t==0){  /*????????????????????????????????¨???*/
        printf("%s %d\n",u.name,elaps);
        n -= 1;
    }
    else{
        enqueue(u);
    }
  }

  return 0;
}

/*??¢??°*/
void enqueue(P x){
  Q[tail] = x;
  tail++;
}

P dequeue(){
  head++;
  return Q[head-1];
}

Measured memory_bytes: 21076
#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
int n,num,sum;
string s;
int main(){
	cin>>s;
	n=s.size();
	for (int i=0;i<n;i++){
		if (i%2==1) if (s[i]=='1') num++;
		if (i%2==0) if (s[i]=='0') num++;
	}
	for (int i=0;i<n;i++){
		if (i%2==1) if (s[i]=='0') sum++;
		if (i%2==0) if (s[i]=='1') sum++;
	}
	cout<<min(sum,num);
	return 0;
}

Measured memory_bytes: 512
import sys
from collections import deque
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    X = readline().decode('utf-8').strip()
    L = len(X)
    S = X[0]
    count = 0
    RLE = []
    for i in range(L):
        if X[i] == S:
            count += 1
        else:
            RLE.append((S,count))
            S = X[i]
            count = 1
        if i==L-1:
            RLE.append((S,count))
    d = deque(RLE)
    if d[0][0] == 'T':
        d.popleft()
    if d[-1][0] == 'S':
        d.pop()
    s = 0
    t = 0
    count = 0
    while d:
        s += d.popleft()[1]
        t = d.popleft()[1]
        if s>=t:
            count += t*2
            s -= t
        else:
            count += s*2
            s = 0
    ans = L-count
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 11428
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

signed main() {
	int a, b;
	cin >> a >> b;
	int mi = min(a, b), ma = max(a, b);
	rep(i, ma) {
		cout << mi;
	}
	cout << endl;

	return 0;
}


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


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N, R = MI()
    if N >= 10:
        print(R)
    else:
        print(R + 100 * (10 - N))


main()


Measured memory_bytes: 64908
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#include <math.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
using namespace std;



int main() {
    ll r, ans;
    cin >> r;
    ans = r * r;
    cout << ans << endl;

   
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        while(!is_prime(x))
            x++;

        System.out.println(x);
    }

    static boolean is_prime(int x){
        for(int i = 2;i < x;i++){
            if(x%i==0)
                return false;
        }
        return true;
    }
}

Measured memory_bytes: 25044
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;


#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        x: isize,
        k: isize,
        d: isize,
    }

    if d >= x.abs() {
        if k % 2 == 0 {
            println!("{}", x.abs())
        } else {
            println!("{}", (x.abs() - d).abs())
        }
    } else {
        // 引ける回数
        let f = x.abs() / d;
        if f >= k {
            println!("{}", ((x.abs() - k * d).abs()))
        } else {
            let l_cnt = k - f;
            let l_dist = (x.abs() - f * d).abs();

            if l_cnt % 2 == 0 {
                println!("{}", l_dist.abs())
            } else {
                println!("{}", (l_dist.abs() - d).abs())
            }
        }
    }
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


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

int main(){
    long long n, x;
    cin >> n >> x;
    long long a[n];
    for(long long i = 0; i < n; i++){
        cin >> a[i];
    }

    long long count = 0;
    for(long long i = 0; i < n-1; i++){
        if(a[i] + a[i+1] > x){
            long long delta = a[i] + a[i+1] - x;
            count += delta;
            if(a[i+1] - delta >= 0){
                a[i+1] -= delta;
            }
            else{
                delta -= a[i+1];
                a[i+1] = 0;
                a[i] -= delta;
            }
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 4376
#include <cstdio>
 
int main()
{
    char N[10];
    scanf("%s", N);
 
    int ans = 0;
    for (int i = 0; i < 4; ++i) {
        if (N[i] == '2') ++ans;
    }
 
    printf("%d\n", ans);
    return 0;
}

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

//for loop
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

//abbreviati
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

//constant
const int INF = 1<<30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/

//adjacency list
vector<int> to[100005];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a,b,c; cin >> a >> b >> c;
    if(c-(a-b)<=0) cout << 0 ENDL;
    else cout << c-(a-b) ENDL;
    
    return 0;
}

Measured memory_bytes: 5964
n, x = map(int, input().split())
a = list(map(int, input().split()))

a2 = sorted(a)
s = 0
ans = 0
for i in range(n):
    s += a2[i]
    if s <= x:
        if i == n - 1:
            if s == x:
                ans += 1
        else:
            ans += 1
    else:
        break
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;
 
int main() {
    fast();
   /* ll t;
    cin>>t;
    while(t--)
    {
       
    }*/
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
    cin>>a[i];
    ll ans=1;
    ll mn=a[0];
    for(ll i=1;i<n;i++)
    {
        if(mn>a[i])
        {
            ans++;
            mn=a[i];
        }
    }
    cout<<ans;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans;
        
        if(n<10) ans = n;
        else if(n<100) ans = 9;
        else if(n<1000) ans = n-99+9;
        else if(n<10000) ans = 999-(99-9);
        else if(n<100000) ans = n-9999+999-(99-9);
        else ans = 99999-(9999-(999-(99-9)));
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 21076
#include<iostream>
using namespace std;
int main(){
  int a[10001][7];
  for(int i=0;i<7;i++)a[0][i]=i;
  int n;
  while(cin>>n){
    if(n==0)return 0;
  string in;
  for(int i=1;i<=n;i++){
    cin>>in;
    for(int j=1;j<7;j++){
      a[i][j]=a[i-1][j];
    }
    if(in=="North"){
      a[i][1]=a[i-1][2];
      a[i][2]=a[i-1][6];
      a[i][5]=a[i-1][1];
      a[i][6]=a[i-1][5];
    }
    if(in=="East"){
      a[i][1]=a[i-1][4];
      a[i][3]=a[i-1][1];
      a[i][4]=a[i-1][6];
      a[i][6]=a[i-1][3];
    }
 if(in=="West"){
      a[i][1]=a[i-1][3];
      a[i][3]=a[i-1][6];
      a[i][4]=a[i-1][1];
      a[i][6]=a[i-1][4];
    }
 if(in=="South"){
      a[i][1]=a[i-1][5];
      a[i][2]=a[i-1][1];
      a[i][5]=a[i-1][6];
      a[i][6]=a[i-1][2];
    }
 if(in=="Right"){
      a[i][2]=a[i-1][3];
      a[i][3]=a[i-1][5];
      a[i][4]=a[i-1][2];
      a[i][5]=a[i-1][4];
    }
 if(in=="Left"){
      a[i][2]=a[i-1][4];
      a[i][3]=a[i-1][2];
      a[i][4]=a[i-1][5];
      a[i][5]=a[i-1][3];
    }
  }int sum=0;
  for(int i=0;i<=n;i++){
    sum+=a[i][1];
  }
  cout<<sum<<endl;
 
  }
}

Measured memory_bytes: 1360
#include <stdio.h>

int main(void) {
  int i = 0, j = 0;
  char s1[11], s2[11], s3[11], a, b;
  scanf("%s %s %s", s1, s2, s3);
  while (i < 10 && s1[i] != '\0') a = s1[i++];
  while (j < 10 && s2[j] != '\0') b = s2[j++];
  if (a == s2[0] && b == s3[0])
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}


Measured memory_bytes: 128