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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;

using Index = int;
template<typename Data>
class FenwickTree{
  private:
    vector<Data> data;
  public:
    FenwickTree(int n){
        data.resize(n+1,0);
    }  
    //sum of index 0,1,..,i
    Data sum(Index idx){
        Data s = 0;
        while(idx > 0){
            s += data[idx];
            idx -= idx & (-idx);
        }
        return s;
    }  
    //sum of index i,i+1,...,j
    // sum of [i,j]
    Data sum(Index i,Index j){
        return sum(j) - sum(i-1);
    }
    //add x to index i
    void add(Index i,Data x){
        while(i < data.size()){
            data[i] += x;
            i += i & (-i);
        }
    }
};

class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        vector<int> P(N); cin >> P;
        reverse(all(P));
        FenwickTree<ll> a(N), b(N);
        repeat(i, 1, N + 1) {
            a.add(i , 1);
            b.add(i , -1);
        }
        rep(i, N) {            
            int p = P[i];
            b.add(p, -i);
            if(p < N) a.add(p + 1, i);
        }
        vector<ll> A(N), B(N);
        ll mb = INFL;
        rep(i, N) {
            A[i] = a.sum(i+1);
            B[i] = b.sum(i+1);
            set_min(mb, B[i]);
        }
        rep(i, N) cout << A[i] << (i == N - 1 ? "\n" : " ");
        rep(i, N) cout << B[i] - mb + 1 << (i == N - 1 ? "\n" : " ");
        
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 1408
from scipy.sparse.csgraph import floyd_warshall as wf
import itertools

N, M, R = map(int, input().split())
r = [int(i) for i in input().split()]

G = [[float('inf')] * N for _ in range(N)]
for i in range(N):
    G[i][i] = 0
for _ in range(M):
    i, j, k = map(int, input().split())
    G[i - 1][j - 1] = k
    G[j - 1][i - 1] = k
    
wf = wf(G)

ans = float('inf')
for perm in itertools.permutations(r):
    tmp = 0
    for i in range(len(perm) - 1):
        tmp += wf[perm[i] - 1][perm[i + 1] - 1]
    ans = min(ans, tmp)
    
print(int(ans))

Measured memory_bytes: 18976
import java.util.Scanner;


	public class Main {
		
		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			
			long n = sc.nextLong();
			long m = sc.nextLong();
			long x = 1000000007L;
			long retn = 1L;
			long retm = 1L;
			long ret = 1L;
			
			if(Math.abs((n-m))!=0&&Math.abs((n-m))!=1) {
				System.out.println(0);
				return;
			}
			
			for(long i=1;i<=n;i++) {
				retn *= i;
				retn %= x;
				
			}
			
			for(long i=1;i<=m;i++) {
				retm *= i;
				retm %= x;
			}
			
			
			if(Math.abs(n-m)==0) {
				ret = (retn*retm*2)%x;
			}else {
				ret = (retn*retm)%x;
			}
			
			System.out.println(ret);
			
	    }
		
	}
	


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> As(N);
    for (auto & a : As) cin >> a;
    cout << accumulate(As.begin(), As.end(), 0) - N << endl;
    return 0;
}

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


int main(){
  while(1){
  int n,x;
  cin>>n>>x;
  if(n ==0 && x ==0) break;
 int ans = 0;
 for(int a=1;a<=n;a++)
 for(int b=a+1;b<=n;b++)
 for(int c=b+1;c<=n;c++){
 if(a + b + c != x) continue;
 ans++;
 }
 cout<<ans<<endl;
 }

 return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);



int main(){
    FIN;

    ll n,l; cin >> n >> l;
    vector<string> s(n);
    for(ll i=0;i<n;i++) cin >> s[i];
    sort(ALL(s));
    for(ll i=0;i<n;i++) cout << s[i];
    cout << endl;



    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back

typedef long long ll;


int main()
{
   ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a,b;
cin>>a>>b;
int ans=a-2*b;
ans=max(ans,0);
cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int main()
{
        const int T2S = 3600, H2S = 60;
        const int MAXS = 120 * H2S;
        int t, h, s;

        while (true) {
                cin >> t >> h >> s;
                if (t < 0 && h < 0 && s < 0) {
                        break;
                }
                int sec = t * T2S + h * H2S + s;
                int ans = MAXS - sec;
                int ans3bai = ans * 3;
                int t2 = ans / T2S, t23bai = ans3bai / T2S;
                ans %= T2S, ans3bai %= T2S;
                int h2 = ans / H2S, h23bai = ans3bai / H2S;
                int s2 = ans % H2S, s23bai = ans3bai % H2S;

                printf("%02d:%02d:%02d\n", t2, h2, s2);
                printf("%02d:%02d:%02d\n", t23bai, h23bai, s23bai);
        }
}

Measured memory_bytes: 3100
import java.util.Arrays;
import java.util.Scanner;

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

        if (x % (y + z) < z) {
            System.out.println(x / (y + z) - 1);
        } else {
            System.out.println(x / (y + z));
        }
    }
}


Measured memory_bytes: 23380
nkc=list(map(int, input().split()))
s=input()
n=nkc[0]
k=nkc[1]
c=nkc[2]
l=[]
r=[]
onum=sum(1 for i in range(len(s)) if s[i]=='o')
num=0
counter=0
while counter<k and num<n:
    #print(num)
    if s[num]=='o':
        l.append(num)
        counter+=1
        num+=c+1
    else:
        num+=1
num=n-1
counter=0
while counter<k and num>=0:
    #print(num)
    if s[num]=='o':
        r.append(num)
        counter+=1
        num-=c+1
    else:
        num-=1
#print(l)
#print(r)
lenr=len(r)
for i in range(min(lenr, len(l))):
    if r[lenr-i-1]==l[i]:
        print(l[i]+1)

Measured memory_bytes: 58232
#include<stdio.h>
int main()
{
	int n,k,h[100000],i,cnt;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++){
		scanf("%d",&h[i]);
	}
	cnt=0;
	for(i=0;i<n;i++){
		if(k<=h[i]){
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int a,b,c;
  cin >> a >> b;
  
  for(int i=0;i<2;i++) {
    if(a >= b) {
      c += a;
      a--;
    }
    else {
      c += b;
      b--;
    }
  }
  
  cout << c << endl;
}


Measured memory_bytes: 256
//https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0514?year=2007

#include <bits/stdc++.h>

using namespace std;

int main() {
    int a, b, c;//電源，モーター，ケーブルの個数

    while (true) {
        cin >> a >> b >> c;
        if (a + b + c == 0) return 0;

        int n;
        cin >> n;

        int st[310];
        for (int i = 0; i < a + b + c; ++i) {
            st[i] = 2;//初期状態は「不明」
        }

        int x[1010], y[1010], z[1010], res[1010];
        for (int i = 0; i < n; ++i) {
            cin >> x[i] >> y[i] >> z[i] >> res[i];
            if (res[i] == 1) {//「正常」を確定
                st[x[i]] = 1;
                st[y[i]] = 1;
                st[z[i]] = 1;
            }
        }

        //「異常」を確定
        for (int i = 0; i < n; ++i) {
            if (res[i] == 0) {
                if (st[x[i]] == 1 and st[y[i]] == 1) st[z[i]] = 0;
                if (st[y[i]] == 1 and st[z[i]] == 1) st[x[i]] = 0;
                if (st[z[i]] == 1 and st[x[i]] == 1) st[y[i]] = 0;;
            }
        }

        for (int i = 1; i <= a + b + c; ++i) {
            cout << st[i] << endl;
        }
    }
}

/*
 * f(a,b,c)=1（正常）のときa,b,cは正常。
 * f(a,b,c)=0（異常）のときa,b,cは異常の可能性あり。
 * ---
 * aが正常だと言えるのは
 * f(a,b,c)=1（正常）でb,cが正常なとき。
 * aが異常だと言えるのは
 * f(a,b,c)=0（異常）でb,cが正常なとき。
 * ---
 * f(a,b,c)=1型のデータは読み込み時に1回処理すれば十分。
 * 「ある機器が正常」というデータはここでしか得られない。
 * f(a,b,c)=0型のデータを使って，
 * 「不明」->「異常」と更新する。
 *
 */


Measured memory_bytes: 3008
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

using namespace std;

#define LL long long

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

bool *ac;
int *wa;
int n, m, p;
string res;
int main() {
	cin >> n >> m;
	ac = new bool[n];
	wa = new int[n];
	for (int i = 0; i < n; ++i) {
		ac[i] = false;
		wa[i] = 0;
	}
	int ans = 0, pen = 0;
	for (int i = 0; i < m; ++i) {
		cin >> p >> res;
		if (res == "AC") {
			if (ac[p]) {
				continue;
			}
			else {
				ac[p] = true;
				++ans;
				pen += wa[p];
			}
		}
		else {
			if (ac[p]) {
				continue;
			}
			else {
				++wa[p];
			}
		}
	}
	cout << ans << ' ' << pen << endl;
	return 0;
}

Measured memory_bytes: 768
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }

    vector<int> b(n), c(n);
    rep(i, n)
    {
        if (i == 0) {
            b[i] = c[i] = 0;
        } else {
            b[i] = gcd(b[i - 1], a[i - 1]);
            c[i] = gcd(c[i - 1], a[n - i]);
        }
    }

    int64_t m = 1;
    rep(i, n)
    {
        m = max(m, gcd(b[i], c[n - 1 - i]));
    }
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr const int INF  = 0x3f3f3f3f;
constexpr const i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr const int MOD  = int(1e9) + 7;
// }}}

// Library {{{

// }}}

struct FastIO {
    FastIO() { cin.tie(nullptr); ios::sync_with_stdio(false); }
} fastIO_ydk ;

signed main()
{
    int N; cin >> N;
    vector<i64> a(N), b(N);

    rep(i, 0, N) {
        cin >> a[i] >> b[i];
    }

    i64 ans = 0;
    i64 propagation = 0;
    for (int i = N-1; i >= 0; --i) {
        a[i] += propagation;
        i64 t = (a[i] + b[i] - 1) / b[i] * b[i];
        propagation += t - a[i];
        ans += t - a[i];
    }

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


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
 
int main(){
    int n;
    cin>>n;
    ll a[n], b[n*(n-1)];
    rep(i,n){
        cin >> a[i];
    }
    int ans=0;
    rep(i, n)
        REP(j, i+1, n){
            ans += a[i]*a[j];
        }
    cout << ans << endl;


    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
  int a,b,flag=0;
  cin >> a >> b;
  string c;
  cin >> c;
  if(c.at(a)!='-') flag = 1;
  rep(i,a+b+1){
    if(i==a) continue;
    if(c.at(i)<'0'||c.at(i)>'9')flag =1;
  }
  if(flag) cout << "No";
  else cout << "Yes";
}

Measured memory_bytes: 3592
import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue

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

inf = float("inf")


def main():
    A, B, C, X, Y = map(int, input().split())
    if A + B > 2 * C:
        if X > Y:
            ret = 2 * C * Y
            if A > 2 * C:
                ret += 2 * C * (X - Y)
            else:
                ret += A * (X - Y)
        else:
            ret = 2 * C * X
            if B > 2 * C:
                ret += 2 * C * (Y - X)
            else:
                ret += B * (Y - X)
    else:
        ret = A * X + B * Y
    print(ret)
        
      
if __name__=='__main__':
    main()

Measured memory_bytes: 40428
N = int(input())
V = [int(j) for j in input().split()]
C = [int(j) for j in input().split()]
mxX = 0
for j in range(0,N):
	if V[j] > C[j]:
		mxX = mxX + V[j] - C[j]
print(mxX)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>

int main(void) {
	// input
	std::string str;
	std::cin >> str;

	std::vector<int> nums(4);
	for(int i = 0; i < 4; ++i) nums[i] = (str[i] - '0');

	for(int i_op = 0; i_op < 8; ++i_op) {
		int op1 = ((i_op >> 2) & 1 == 1 ? 1 : -1);
		int op2 = ((i_op >> 1) & 1 == 1 ? 1 : -1);
		int op3 = (i_op & 1 == 1 ? 1 : -1);
		int ans = nums[0] + op1 * nums[1] + op2 * nums[2] + op3 * nums[3];
		if(ans == 7) {
			std::cout << nums[0] << (op1 == 1 ? '+' : '-')
				<< nums[1] << (op2 == 1 ? '+' : '-')
				<< nums[2] << (op3 == 1 ? '+' : '-')
				<< nums[3] << "=7" << std::endl;
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 256
import sys


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    S = list(input())



    ans =0
    for k in range(1,N):
        i=0
        count =0
        while i<N-k:
            if S[i]==S[i+k]:
                count+=1
                ans =max(ans,min(count,k))
            else:
                count=0

            i+=1

    print(ans)









if __name__ == "__main__":
    main()


Measured memory_bytes: 73532
N = int(input())
A = tuple(map(lambda n: int(n) - 1, input().split()))

rem = 0
bk = 0
for a in A:
    if a == rem:
        rem += 1
    else:
        bk += 1

if bk == N:
    print(-1)
else:
    print(bk)

Measured memory_bytes: 25824
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        long[] a = new long[n+1];
        for (int i = 0; i < n+1; i++) {
            a[i] = sc.nextLong();
        }

        long cnt = 0;
        for (int i = 0; i < n; i++) {
            long b = sc.nextLong();
            if (b > a[i]) {
                cnt += a[i];
                b -= a[i];
            } else {
                cnt += b;
                b = 0;
            }
            if (b >= a[i+1]) {
                cnt += a[i+1];
                a[i+1] = 0;
            } else {
                cnt += b;
                a[i+1] -= b;
            }
        }

        System.out.println(cnt);
    }
}

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

int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=1; i<=n; i++){
		cin>>a[i];
	}
	for(int i=1; i<=n; i++){
		if(a[i]%2==0){
			if(a[i]%3==0 || a[i]%5==0){
				i++;
			}
			else{
				cout<<"DENIED"<<endl;
				return 0;
			}
		}
	}
	cout<<"APPROVED"<<endl;
	return 0;
}

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

int main(){
    int a[3];
    for( int i = 0; i < 3; i++ ) cin >> a[i];

    
    sort( a, a+3, greater<int>() );
    cout << a[0]*10 + a[1] + a[2] << endl;

    return 0;
}

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

int main() {
  int h, N;
  int a[100000];
    cin >> h >> N;
    for (int i = 0; i < N; ++i) cin >> a[i];
   
  int sum;
    for (int i = 0; i < N; ++i) sum += a[i];
   
  if (h <= sum ){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(){
	int w, h;
	while(1){
		cin >> h >> w;
		if(!h && !w)break;
		int size = (h*h)+(w*w), min =(150*150)*(150*150);
		int ans1=h, ans2=w;
		for(int i=1; i<150; i++){
			for(int j=i+1; j<150; j++){
				int tmp = (i*i)+(j*j);
				if(size <= tmp && tmp<=min){
					if(size == tmp && h>i)continue;
					if(min == tmp && ans1<i)continue;
					if(i==h && j==w)continue;
					min = tmp;
					ans1 = i;
					ans2 = j;
				}
			}
		}
		cout << ans1 << " " << ans2 << endl;
	}
	return 0;
}



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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int k;
    cin >> k;

    /* aにする */
    REP(i, n) {
        int times = (26 - (s[i] - 'a')) % 26;
        if(k >= times) {
            k -= times;
            s[i] = 'a';
        }
    }
    k %= 26;
    s[n-1] = s[n-1] + k;

    cout << s << endl;

    return 0;
}

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

using namespace std;


int main()
{
	int N;
	cin >> N;
	vector<int> B(N - 1);
	for (int i = 0; i < N - 1; i++) cin >> B.at(i);
	int answer = 0;

	answer += B.at(0);
	for (int i = 1; i < N - 1; i++)
	{
		answer += min(B.at(i - 1), B.at(i));
	}
	answer += B.at(N - 1 - 1);

	cout << answer << endl;

	return 0;
}

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

t = [0] * (N - 1)
for i in range(1, N):
    for j in range(i + 1, N + 1):
        t[min(j - i, abs(X - i) + 1 + abs(Y - j)) - 1] += 1
print('\n'.join(map(str, t)))


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

using namespace std;

template<class value_type>
class my_vector{
public:
  int imag_size;
  int real_size;
  value_type *array;
  my_vector(int n_){
    real_size = n_;
    imag_size = 1;
    while(real_size>imag_size)imag_size<<=1;
    array = new value_type[imag_size];
  }
  my_vector():my_vector(0){}

  void push_back(value_type x){
    if(real_size==imag_size){
      imag_size <<= 1;
      value_type *next = new value_type[imag_size];
      for(int i=0;i<real_size;++i){
        next[i] = array[i];
      }
      delete[] array;
      array = next;
    }
    array[real_size++] = x;
  }

  value_type pop_back(){
    if(real_size==0){
      cout << "my_vector::pop_back() invalid data size" << endl;
      exit(1);
    }
    return array[--real_size];
  }

  value_type& operator[](int p){
    return array[p];
  }
};

int main(){
  my_vector<int> line;

  int q;
  cin >> q;
  for(int i=0;i<q;++i){
    int kind;
    cin >> kind;
    if(kind==0){
      int data;
      cin >> data;
      line.push_back(data);
    }else if(kind==1){
      int place;
      cin >> place;
      cout << line[place] << endl;
    }else{
      line.pop_back();
    }

  }

  return 0;
}



Measured memory_bytes: 3976
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if (a+b == c || a+c == b || a == b+c) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n,k;
  cin>>n>>k;
  map<int,int> M;
  REP(i,n){
    int a;cin>>a;
    M[a]++;
  }
  int ans = 0;
  vi V;
  for(pii P : M){
    V.push_back(P.second);
  }
  sort(ALL(V));
  reverse(ALL(V));
  while(V.size() > k){
    ans += V.back(); V.pop_back();
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 10748
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int main() {
  string S ;
  int ans = 0 ;
  cin >> S ;
  if( 1 <= stoi(S.substr(0,2))  && stoi(S.substr(0,2)) <= 12 ){
    if( 1 <= stoi(S.substr(2,2))  && stoi(S.substr(2,2)) <= 12){
	 cout << "AMBIGUOUS" << endl;
     return 0 ;
  	}
  }
  if( 1 <= stoi(S.substr(0,2))  && stoi(S.substr(0,2)) <= 12 ){
    if( 0 <= stoi(S.substr(2,2)) ){
      cout << "MMYY" << endl;
      return 0 ;
    }
  }
  if( 0 <= stoi(S.substr(0,2)) ){
    if( 1 <= stoi(S.substr(2,2))  && stoi(S.substr(2,2)) <= 12 ){
      cout << "YYMM" << endl;
      return 0 ;
    }
  }
  cout << "NA" << endl;
}

Measured memory_bytes: 256
import heapq, math

n, m = map(int, input().split())
A = list(map(int, input().split()))
a = list(map(lambda x: x*(-1), A))
heapq.heapify(a)
for i in range(m):
    max_a = heapq.heappop(a)
    heapq.heappush(a, math.ceil(max_a/2))
print(-sum(a))

Measured memory_bytes: 20332
#include <iostream>
#include <queue>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;

int main(){
	int num;
	cin >> num;
		priority_queue<int> pq;
	for (int i = 0; i < num; ++i) {
		for (int j = 0; j < 3; ++j) {
			int a;
			cin >> a;
			pq.push(a);
		}
		int a, b, c;
		a = pq.top();
		pq.pop();
		b = pq.top();
		pq.pop();
		c = pq.top();
		pq.pop();
		if (a * a == b * b + c * c) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1208
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#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 <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

  while(true){
	int N;
	cin >> N; if(N == 0) break;
	VVI edge(20, VI(20, 123456789));
	vector<bool> use(20, false);
	REP(i,N){
	  int a, b, c; cin >> a >> b >> c;
	  edge[a][b] = edge[b][a] = c;
	  use[a] = use[b] = true;
	}
	REP(i,20) edge[i][i] = 0;

	VI t;
	REP(i,20) if(use[i]) t.PB(i);
	int M = SZ(t);

	REP(i,M) REP(j, M) REP(k,M){
	  int a = t[i], b = t[j], c = t[k];
	  edge[b][c] = min(edge[b][c], edge[b][a] + edge[a][c]);
	}
	
	int idx, ans = 1234567890;
	REP(i,M){
	  int st = t[i];
	  int sum = 0;
	  REP(j,M){
		int to = t[j];
		sum += edge[st][to];
	  }
	  if(sum < ans){
		idx = st;
		ans = sum;
	  }
	}
	cout << idx << " " << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1220
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>

struct node{
	struct node *left;
	struct node *right;
	struct node *parent;
	int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
	while (x->left!=NIL){
		x = x->left;
	}
	return x;
}

Node treeSearch(Node u, int k){
	if (u == NIL){return NIL;}
	if (u->key == k){ return u; }
	else if (u->key > k){
		return treeSearch(u->left, k);
	}
	else{
		return treeSearch(u->right, k);
	}
}

Node treeSuccessor(Node x){
}

void treeDelete(Node z){
	Node y; // node to be deleted
	Node x; // child of y

	if (z->left == NIL && z->right == NIL){//子なし
		if (z->parent->left == z){
			z->parent->left = NIL;
		}
		else{
			z->parent->right = NIL;
		}
		free(z);
	}
	else if (z->left != NIL && z->right != NIL){//子2人
		x = z->right;
		while (x->left != NIL){
			x = x->left;
		}
		z->key = x->key;
		treeDelete(x);
		
	}
	else{//子1人
		if (z->left!=NIL){//左に子がいたら
			if (z->parent->left == z){//zが親の左側にいたら
				z->parent->left = z->left;
				z->left->parent = z->parent;
			}
			else{//zが親の右側にいたら
				z->parent->right = z->left;
				z->left->parent = z->parent;
			}
		}
		else{//右に子がいたら
			if (z->parent->left == z){//zが親の左側にいたら
				z->parent->left = z->right;
				z->right->parent = z->parent;
				free(z);
			}
			else{//zが親の右側にいたら
				z->parent->right = z->right;
				z->right->parent = z->parent;
			}
		}
	}
}

Node sss(int k, Node x){
	if (x == NIL){ return x; }
	if (k < x->key){
		if (x->left != NIL){
			return sss(k, x->left);
		}
		else{
			return x;
		}
	}
	else{
		if (x->right != NIL){
			return sss(k, x->right);
		}
		else{
			return x;
		}
	}
}

void insert(int k){
	Node y = sss(k,root);
	Node z;

	z = malloc(sizeof(struct node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	z->parent = y;

	if (y == NIL){ root=z; }
	else if (y->key < k){
		y->right = z;
	}
	else{
		y->left = z;
	}
}

void inorder(Node u){
	if (u->left != NIL)
		inorder(u->left);
	printf(" %d", u->key);
	if (u->right != NIL)
		inorder(u->right);	
}
void preorder(Node u){
	printf(" %d", u->key);
	if (u->left != NIL)
		preorder(u->left);
	if (u->right != NIL)
		preorder(u->right);
}


int main(){
	int n, i, x;
	char com[20];
	scanf("%d", &n);

	for (i = 0; i < n; i++){
		scanf("%s", com);
		if (com[0] == 'f'){
			scanf("%d", &x);
			Node t = treeSearch(root, x);
			if (t != NIL) printf("yes\n");
			else printf("no\n");
		}
		else if (com[0] == 'i'){
			scanf("%d", &x);
			insert(x);
		}
		else if (com[0] == 'p'){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
		else if (com[0] == 'd'){
			scanf("%d", &x);
			treeDelete(treeSearch(root, x));
		}
	}

	return 0;
}

Measured memory_bytes: 19364
#include<bits/stdc++.h>
using namespace std;
#define N 333333
#define rev(a) reverse(a+1,a+n+1)
#define ll long long
 
int n,t,a[N];
long long s[N],l[N],r[N],f[N],g[N],h[N],q[N];
int read(){
	char c=getchar();int k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}
ll sum(int n){return (ll)n*(n+1)/2;} 
double slope(int x,int y){return (double)(g[x]-g[y])/(x-y);}
void pop(int x){for (;t>1&&slope(q[t-1],q[t])<=x;t--);}
void push(int x){
	for (;t>1&&slope(q[t-1],q[t])<=slope(q[t],x);t--);q[++t]=x;
}
void init_s(){for (int i=1;i<=n;i++) s[i]=s[i-1]+a[i];}
void calc(ll *f){
	int i;q[t=1]=0;init_s();
	for (i=1;i<=n;i++){
		pop(i);f[i]=max(f[i-1],f[q[t]]+sum(i-q[t])-s[i]+s[q[t]]);
		g[i]=f[i]+sum(i-1)+s[i];push(i);
	}
}
 
void solve(int x,int y){
	if (x==y) return;
	int mid=(x+y)/2;t=0;
	for (int i=x;i<=mid;i++){
		g[i]=l[i]+1ll*i*(i-1)/2+s[i];
		push(i);
	}
	for (int i=mid+1;i<=y;i++){
		pop(i);
		h[i]=l[q[t]]+r[i+1]+sum(i-q[t])-s[i]+s[q[t]];
	}
	for (int i=y-1;i>mid;i--) h[i]=max(h[i],h[i+1]);
	for (int i=mid+1;i<=y;i++) f[i]=max(f[i],h[i]);
	solve(x,mid);solve(mid+1,y);
}
 
int main(){
	n=read();
	for (int i=1;i<=n;i++) a[i]=read(),f[i]=-1e18;
	calc(l);rev(a);calc(r);rev(a);rev(r);
	init_s();solve(0,n);rev(a);rev(f);rev(l);rev(r);swap(l,r);
	init_s();solve(0,n);rev(a);rev(f);rev(l);rev(r);swap(l,r);
	for (int m=read();m;m--){
		int p=read(),x=read();
		printf("%lld\n",max(l[p-1]+r[p+1],a[p]+f[p]-x));
	}
}

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

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

int digit(ll num){
  return to_string(num).length();
}

int find(ll x) {
  int answer = numeric_limits<int>::max();
  for(ll a=1;a*a<=x;a++) {
    if(x%a!=0) continue;
    int n_answer = max(digit(a), digit(x/a));
    answer = min(answer, n_answer);
  }
  return answer;
}

int main(void) {
  ll x;
	cin >> x;
  cout << find(x) << '\n';
}


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

typedef long long ll;

int main(){
  ll x;
  cin >> x;
  
  ll ans = 0;
  ans += int(x / 500) * 1000;
  x = x % 500;
  ans += int(x / 5) * 5;
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
int n,c;
ll a[401],b[401];
ll u[401][401];
ll dp[401][401];

int main(void){
	scanf("%d%d",&n,&c);
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	for(int i=0;i<n;i++){
		scanf("%lld",&b[i]);
	}
	for(int i=1;i<=400;i++){
		u[i][0]=1;
		for(int j=0;j<400;j++){
			u[i][j+1]=u[i][j]*i%MOD;
		}
	}
	for(int i=0;i<=400;i++){
		for(int j=1;j<=400;j++){
			u[j][i]=(u[j][i]+u[j-1][i])%MOD;
		}
	}
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<=c;j++){
			for(int k=0;k<=j;k++){
				ll plus=(u[b[i]][k]-u[a[i]-1][k]+MOD)%MOD;
				ll plus2=(dp[i][j-k]*plus)%MOD;
				dp[i+1][j]=(dp[i+1][j]+plus2)%MOD;
			}
		}
	}
	printf("%lld\n",dp[n][c]);
	return 0;
}

Measured memory_bytes: 2688
from collections import*;M=lambda:map(int,input().split());n,k,l=M();d=[-1]*n;t=[-1]*n;r=range
def f(l,x):
  if l[x]<0:return x
  l[x]=f(l,l[x]);return l[x]
def u(l,x,y):
  if f(l,x)!=f(l,y):l[f(l,y)]=f(l,x)
for i in r(k+l):a,b=M();u(d if i<k else t,a-1,b-1)
p=[(f(d,i),f(t,i))for i in r(n)];c=Counter(p);print(*[c[p[i]]for i in r(n)])

Measured memory_bytes: 44392
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
T = [2, 5, 5, 4, 5, 6, 3, 7, 6]

H = set(T[a-1] for a in A)
H = list(H)
H.sort()

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

for i in range(1,N+1):
    ret = 0
    if i-H[0] < 0:
        continue
    dp[i] = max(dp[i-h] + 1 for h in H if i-h>=0)

ans = ''
j = N
for i in range(1,dp[-1]):
    for a in A:
        if dp[j-T[a-1]] == dp[j] - 1:
            ans += str(a)
            j -= T[a-1]
            break

for a in A:
    if j == T[a-1]:
        ans += str(a)
        j -= T[a-1]
        break

print(ans)


Measured memory_bytes: 3384
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int r = stdIn.nextInt();
		
		if(n>=10) {
			System.out.println(r);
		}else {
			System.out.println(r+100*(10-n));
		}
		
		
		
	}

}


Measured memory_bytes: 25172
import sys
import os

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = list(sys.stdin.buffer.readline().decode().rstrip())
    M = S[0: (len(S) - 1) // 2]
    U = S[(len(S) + 2) // 2:]
    print('Yes' if S == S[::-1] and M == M[::-1] and U == U[::-1] else 'No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
constexpr double eps = 1e-6;
constexpr ll LINF = 100200300400500600ll;
constexpr int INF = 2*((1<<30)-1)+1;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
constexpr int dx[4] = {0,1,0,-1};
constexpr int dy[4] = {-1,0,1,0};
constexpr int mod = 1000000007;
#define Yes(ifeq) cout<<(( ifeq )? "Yes":"No")<<endl;

void Main(){
  int r;
  cin>>r;
  cout<<setprecision(6)<<2*r*M_PI<<endl;
  
} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 3848
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] arr = new String[]{"p", "p", "h", "b", "h", "h", "p", "h", "p", "h"};
        System.out.println(arr[in.nextInt() % 10] + "on");
    }
}

Measured memory_bytes: 38684
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define N 1000
#define EPS 1e-9

using namespace std;


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

	long long n;
	cin >> n;
	int t = 1;
	long double m = 100L;
	while (true) {
		m =(long long)(m * 1.01L);
		if (m >= n)
			break;
		++t;
	}
	cout << t << '\n';
}

Measured memory_bytes: 3644
#include "bits/stdc++.h"

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }

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

	int n, t;
	cin >> n >> t;

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

	LL ans = t;
	for (int i = 0; i < n - 1; i++) {
		ans += min(t, pushTime[i + 1] - pushTime[i]);
	}

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

Measured memory_bytes: 1024
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// #include <functional> 
// using namespace __gnu_pbds;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MaX 300005
using namespace std;

 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1e18;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
   	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
// typedef tree<int, null_type, less<int>, rb_tree_tag, 
//              tree_order_statistics_node_update> 
//     new_data_set; 
bool isprime(ll n) 
{ 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}


int main()
{
	fast();
	int i,a[5];
	for(i=0;i<5;i++)
	{
		cin>>a[i];
		if(a[i]==0)
		{
			cout<<i+1;
			exit(0);
		}
	}

}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

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


int main(){
    int n; cin >> n;
    vector<int> p(n);
    rep(i, n){
        cin >> p[i];
        p[i]--;
    }
    int count = 0;
    _rep(i, 1, n){
        if(p[i - 1] == i - 1){
            swap(p[i - 1], p[i]);
            count++;      
        }  
    }
    if(p[n - 1] == n - 1)count++;
    cout << count << endl;
}

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

const int nmax=8;
bool graph[nmax][nmax];

int dfs(int v,int N,bool visited[nmax]){
    bool allOK=true;
    for(int i=0;i<N;i++){
        if(!visited[i]){
            allOK=false;
        }
    }
    if(allOK){
        return 1;
    }
    int ret=0;
    for(int i=0;i<N;i++){
        if(visited[i]) continue;
        if(!graph[v][i]) continue;

        visited[i]=true;
        ret += dfs(i,N,visited);
        visited[i]=false;
    }
    return ret;

}
int main(){
    int N,M;
    cin >> N >> M;
    for(int i=0;i<M;i++){
        int A,B;
        cin >> A >>B;
        graph[A-1][B-1]=true;
        graph[B-1][A-1]=true;
    }

    bool visited[nmax];
    for(int i=0;i<nmax;i++){
        visited[i]=false;
    }
    visited[0]=true;
    cout << dfs(0,N,visited) <<endl;
    return 0;
}



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

int main(){
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	ll money = 1000;
	rep(i,n-1){
		ll stock = 0;
		if(a[i+1] > a[i]){
			stock = money / a[i];
			money -= stock * a[i];
			money += stock * a[i+1];
		}
	}
	cout << money << endl;
    return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)

    while(true) {
        val nums = scan.nextLine().split(" ")
        val n = Integer.parseInt(nums[0])
        val x = Integer.parseInt(nums[1])

        if (n == 0 && x == 0) {
            break
        }

        println(detect(n, x))
    }
}

fun detect(n: Int, x: Int): Int {
    var count = 0
    for (i in 1..n) {
        for (j in 1..n) {
            for (k in 1..n) {
                if (i != j && j != k && i != k && i + j + k == x && i < j && j < k) {
                    count++
                }
            }
        }
    }
    return count
}



Measured memory_bytes: 35532
import fractions
import sys

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

if n == 1 :
  print(abs(a[0]-x))
  sys.exit()

ans = fractions.gcd(abs(a[0]-x),abs(a[1]-x))
for i in range(2,n) :
  ans = fractions.gcd(ans,abs(a[i]-x))
  
print(ans)

Measured memory_bytes: 16296
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S, T;
  cin >> S >> T;
  int count = 0;
  for(int i = 0; i < 3; i++) if(S[i] == T[i]) count += 1;
  cout << count << endl;
  return 0;
}

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

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))

#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;

long dp[305][305];

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

  string s, t;
  cin >> s >> t;
  int q;
  cin >> q;

  vector<int> ss(s.size() + 1);
  vector<int> tt(t.size() + 1);
  rep(i, s.size()) {
    ss[i+1] = ss[i];
    if (s[i] == 'A') {
      ss[i+1]+=2;
    } else {
      ss[i+1]++;
    }
  }
  rep(i, t.size()) {
    tt[i+1] = tt[i];
    if (t[i] == 'A') {
      tt[i+1]+=2;
    } else {
      tt[i+1]++;
    }
  }

  rep(i, q) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int s1 = ss[b] - ss[a-1];
    int t1 = tt[d] - tt[c-1];
    cout << ((s1%3) == (t1%3) ? "YES": "NO") << endl;
  }
}


Measured memory_bytes: 1744
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define ll long long 

int main () {
	int i,j,k,l,n,m;
	cin>>n>>m;
	cout<<(n*(n-1))/2 + (m*(m-1))/2<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactice problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main() 
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ll n,x;
    cin>>n>>x;
    ll p[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>p[i];
    }
    sort(p, p+n);
    ll ans=0;
    for (int i = 0; i < x; ++i)
    {
        ans+=p[i];
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<28;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-10;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

string s;

int main(){
	cin>>s;
	vi a,b;
	int I=0;
	s+='A';
	for(int i=1;i<s.size();i++){
		if(s[i]!=s[i-1]){
			a.push_back(i-I);
			int num=2;
			if(s[i-1]=='J') num=0;
			else if(s[i-1]=='O') num=1;
			b.push_back(num);
			I=i;
		}
	}
	int ans=0;
	for(int i=1;i<a.size()-1;i++){
		if(b[i-1]==0&&b[i]==1&&b[i+1]==2&&a[i]<=a[i-1]&&a[i]<=a[i+1]){
			ans=max(ans,a[i]);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 12684