akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<int>nums;
		while (N--) {
			int a; cin >> a; nums.emplace_back(a);
		}
		vector<pair<int, int>>anss;
		for (int i = 0; i < nums.size(); ++i) {
			int b = nums[i];
			int c = b;
			while (i != nums.size() - 1 && c + 1 == nums[i + 1]) {
				i++;
				c++;
			}
			anss.emplace_back(b, c);
			
		}
		for (int i = 0; i < anss.size(); ++i) {
			if (anss[i].first == anss[i].second)cout << anss[i].first;
			else cout << anss[i].first << '-' << anss[i].second;
			if (i == anss.size() - 1)cout << endl;
			else cout << ' ';
		}
	}
	return 0;
}

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

int main (){
  int a, b, c;
  cin >> a >> b >> c ;
  if (a + b + c >= 22){
    cout << "bust" << endl;
  }
  else{
    cout << "win" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <queue>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

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

    vector<char> chars((int)s.size());

    REP(i,(int)s.size()){
        chars[i] = s[i];
    }

    set<char> set_char(chars.begin(), chars.end());

    int ans = (int)s.size();
    for(auto itr=set_char.begin(); itr!=set_char.end(); itr++){
        int count = 0;
        char target = *itr;
        string tmp_s = s;

        while(true){
            bool is_equal = true;
            REP(i,(int)s.size()-count){
                if(tmp_s[i] != tmp_s[0]){
                    is_equal = false;
                    break;
                }
            }

            if(is_equal)break;

            string _s = "";
            REP(i,(int)s.size()-count-1){
                if(tmp_s[i] == target || tmp_s[i+1]== target){
                    _s += target;
                }else{
                    _s += tmp_s[i+1];
                }
            }

            tmp_s = _s;
            count++;
        }

        if(ans > count)ans=count;
    }

    cout << ans << endl;
    return 0;

    

}

Measured memory_bytes: 3596
def main():
    N, M = map(int, input().split())
    S, C = [0]*M, [0]*M
    for i in range(M):
        S[i], C[i] = map(int, input().split())
    ans = -1
    for i in range(10**N):
        found = True
        for j in range(M):
            s, c = N - S[j], C[j]
            if s > 1 and s == N - 1 and c == 0:
                found = False
                break
            v = (i // (10**s)) % 10
            if v != c:
                found = False
                break
        if found and N != 1 and (i // (10**(N-1))) != 0:
            ans = i
            break
        elif N == 1 and found:
            ans = i
            break
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, m, c, a, b;
  in3(n, m, c);
  a = 0;
  vector<ll> s(m);
  rep(i, m)
    in(s[i]);
  vector<vector<ll>> t(n, vector<ll> (m));
  rep(i, n){
    rep(j, m)
      in(t[i][j]);
  }
  rep(i, n){
    b = 0;
    rep(j, m)
      b += s[j] * t[i][j];
    if(b > c * (-1))
      a++;
  }
  out(a);
  memi;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

const int MOD = 1e9 + 7;

void solve() {
    string K;
    cin >> K;

    int D;
    cin >> D;

    const int n = K.size();
    vector<vector<long long>> dp(n, vector<long long>(D, 0));

    for (int i = 0; i < 10; ++i)
        dp[0][i % D] += 1;
    for (int i = 0; i < n - 1; ++i) {
        for (int j = 0; j < D; ++j) {
            for (int k = 0; k < 10; ++k)
                dp[i + 1][j] += dp[i][(((j - k) % D) + D) % D];
            dp[i + 1][j] %= MOD;
        }
    }

    long long cnt = 0, k = 0;
    for (int i = 0; i < n - 1; ++i) {
        for (int j = 0; j < K[i] - 48; ++j) {
            cnt += dp[n - i - 2][(((-j - k) % D) + D) % D];
        }
        cnt %= MOD;
        k += K[i] - 48;
    }

    for (int j = 0; j < K[n - 1] + 1 - 48; ++j)
        cnt += (j + k) % D == 0;

    cout << (cnt - 1) % MOD << '\n';
}

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

    cout << boolalpha;
    cout << fixed << setprecision(16);

    solve();
    return 0;
}


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

#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
const double pi = 3.14159265358979;



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

    string s;
    cin >> s;
    reverse(s.begin(), s.end());

    string t = "";

    for (ll i = 0; i < s.size(); i++){
        t += s[i];
        if (t == "maerd" || t == "remaerd" || t == "esare" || t == "resare"){
            t = "";
        }
        if (t.size() > 8){
            break;
        }
    }

    YESNO(t == "");
}

Measured memory_bytes: 3788
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
typedef long long ll;
using namespace std;

int main() {
    string S;
    cin >> S;
    ll bcount = 0;
    ll wcount = 0;

    for (int i = 0; i < S.size(); ++i) {
        if (S[i] == 'B') ++bcount;
        else wcount += bcount;
    }

    cout << wcount << endl;
}

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

int main(void){
    int Y,X;
    while(cin>>Y>>X, Y|X){
        int e[10][10] = {};
        rep(y,Y)rep(x,X) cin>>e[y][x];
        int res = 0;
        rep(y2,Y)rep(y1,y2-1)rep(x2,X)rep(x1,x2-1){
            int mn = 9, sum = 0, mx = 0;
            for(int y = y1; y<=y2; y++)for(int x = x1; x<=x2; x++){
                if(x==x1 || x==x2 || y==y1 || y==y2){
                    mn = min(mn,e[y][x]);
                }else{
                    mx = max(mx,e[y][x]);
                    sum += e[y][x];
                }
            }
            if(mn > mx){
                res = max(res, mn*(y2-y1-1)*(x2-x1-1) - sum);
            }
        }
        cout<<res<<endl;
    }
    return 0;
}



Measured memory_bytes: 2936
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i += 2) {
    int cnt = 0;
    for (int j = 1; j <= i; j++) {
      
      if (i % j == 0) {
        cnt++;
        if (cnt > 8) break;
      }
      
    }
    
    if (cnt == 8) {
      ans++;
    }
    
  }
  
  cout << ans << endl;
  
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1000000007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }


int main(){
    int A[3][3];
    REP(i, 3) REP(j, 3) cin >> A[i][j];
    int N;
    cin >> N;
    for(int i=0; i<N; i++){
        int b;
        cin >> b;
        REP(j, 3) REP(k, 3)
            if(A[j][k] == b)
                A[j][k] = 0;
    }
    REP(i, 3){
        bool ok = true;
        REP(j, 3)
            if(A[i][j] != 0) ok = false;
        if(ok){
            cout << "Yes" << endl;
            return 0;
        }
    }
    REP(i, 3){
        bool ok = true;
        REP(j, 3)
            if(A[j][i] != 0) ok = false;
        if(ok){
            cout << "Yes" << endl;
            return 0;
        }
    }
    if(A[0][0] == 0 && A[1][1] == 0 && A[2][2] == 0){
        cout << "Yes" << endl;
        return 0;
    }
    if(A[0][2] == 0 && A[1][1] == 0 && A[2][0] == 0){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


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

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b){
        cout<<c<<endl;
    }else if(b==c){
        cout<<a<<endl;
    }else{
        cout<<b<<endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>

int a[10];

int main(){
  int n;
  scanf("%d",&n);
  for(int t=0;t<n;t++){
    bool ans = true;
    for(int i=0;i<10;i++){
      scanf("%d",&a[i]);
    }
    int l,r;
    l=r=0;
    for(int i=0;i<10;i++){
      if(a[i]>l){
        l = a[i];
      }
      else if(a[i]>r){
        r = a[i];
      }else{
        ans = false;
        break;
      }
    }
    printf("%s\n",ans?"YES":"NO");
  }
  return 0;
}



Measured memory_bytes: 2508
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long i,n,s,p,a;
    p = 0;
    s = 0;
    cin >> n;
    for(i = 0; i < n; i++) {
        cin >> a;
        p = a + max(0LL,p-a);
        s += p-a;
    }
    cout << s;
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <stack>
#define STACK_SIZE 1e5
using namespace std;
const int maxn=1e5+10;

int c,cnt;
char a[maxn];
int main()
{
       while(~scanf("%s",a))
       {

        int x=0,y=0;
       int l=strlen(a);
     // printf("l=%d\n",l);
       for(int i=0;i<l;i++)
       {
          // printf("a[%d]=%d\n",i,a[i]);
           if(a[i]=='1'){x++;}
           else {y++;}
       }
      // printf("x=%d y=%d\n",x,y);
       int k=abs(x-y);
      printf("%d\n",l-k);
       }
    return 0;
}


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

#define REP(i, n) for(int i=1; i<=n; i++)
using namespace std;
const int MAX = 1100100;

char s[MAX];

int main(){
	cin >> (s+1);
	
	int N = strlen(s+1);
	
	int pos = 0;
	REP(I, N){
		if(s[pos]=='S' && s[I]=='T')
			pos--;
		else
			s[++pos] = s[I];
		//cout << s+1 << endl;
	}
	s[pos+1]=0;
	cout << strlen(s+1) << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


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



int main() {

	ll N;
	cin >> N;

	if (N / 10 % 111 == 0 || N % 1000 % 111 == 0) { cout << "Yes"; }
	else { cout << "No"; }

	system("PAUSE");

	

}


Measured memory_bytes: 504
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    n = int(input())
    # 整数複数個
    # a, b = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    A = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    A = sorted(A)
    cnt = 1
    flag = True
    for i in range(n):
        cnt *= A[i]
        #print(cnt)
        if cnt > 10**18:
            flag = False
            break

    if flag == True:
        print(cnt)
    else:
        print(-1)


resolve()

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

int main(){
   ll n,i,x=0,ans=0;

   cin>>n;
   ll a[n+9],b[n+9];


    for(i=0;i<n;i++){
    cin>>a[i];
    x+=a[i];
   }
   ll y=x;
   x=x/n;
   ll z=x;
if(x*n!=y) {
      if(x>0)  x+=1;
      else x--;

   }

    for(i=0;i<n;i++){
       if(x!=a[i]){

        ans+=(a[i]-x)*(a[i]-x);

       }
   }
  ll ans1=0;
   for(i=0;i<n;i++){
       if(z!=a[i]){

        ans1+=(a[i]-z)*(a[i]-z);

       }
   }


cout<<min(ans,ans1)<<endl;


}



Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)

void solve()
{
    int n;
    while(cin>>n,n){
        vector<int> x(1,0),y(1,0);x[0]=0;y[0]=0;
        int a,b;REP(i,n-1){
            cin>>a>>b;
            if(b==0)x.push_back(x[a]-1),y.push_back(y[a]);
            if(b==1)x.push_back(x[a]),y.push_back(y[a]-1);
            if(b==2)x.push_back(x[a]+1),y.push_back(y[a]);
            if(b==3)x.push_back(x[a]),y.push_back(y[a]+1);
        }
        sort(x.begin(),x.end());
        sort(y.begin(),y.end());
        cout<<x[x.size()-1]-x[0]+1<<" "<<y[y.size()-1]-y[0]+1<<endl;
    }
}

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


Measured memory_bytes: 3116
#include <iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>

using namespace std;

int main()
{
	long long n, a, b;
	cin >> n >> a >> b;
	long long sum = a + b;
	long long c = n % (a + b);
	long long ans = n / (a + b);
	ans *= a;
	if (c > a) {
		ans += a;
	}
	else {
		ans += c;
	}
	cout << ans << endl;
	return 0;
}

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

h = [int(x) for x in input().split()]

dp = [10**9]*N
dp[0] = 0

for i in range(1,N):
    for j in range(1,min(i+1,K+1)):
        dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))

print(dp[N-1])

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

int main()
{
    int n;
    cin>>n;
    int a[n];
    int h;
    for (int i = 1; i <= n; i++) {
         cin >> h;
         a[h-1] = i;
    }
    for (int i = 0; i < n; i++) {
          if (i > 0) cout << " ";
          cout << a[i];
     }
    cout << "\n";
}

Measured memory_bytes: 1152
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int H = sc.nextInt();
		int W = sc.nextInt();
		int h = sc.nextInt();
		int w = sc.nextInt();

		out.println((H-h)*(W-w));

		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


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

int main(){
  int N;
  cin >> N;
  vector<int64_t> A(N),sum(N+1);
  sum.at(0)=0;
  //double half=0;
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    //half+=A.at(i)/2.0;
    sum.at(i+1)=sum.at(i)+A.at(i);
  }
  int64_t ans=abs(sum.at(1)-(sum.at(N)-sum.at(1)));
  for(int i=2;i<N;i++){
    ans=min(ans,abs(sum.at(i)-(sum.at(N)-sum.at(i))));
  }
  cout << ans << endl;
}


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

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long int 
#define MAX 100005
const int M=1e9+7;
const ll INF = 1LL << 60;
typedef pair<int,int> pii;
bool visited[MAX];
vector<int>adj[MAX];
int a[105];
bool mark[MAX][2],dp[MAX][2];
int n;
bool check(int i,int j)
{
	if(i==0)
		return false;
	if(mark[i][j])
		return dp[i][j];
	mark[i][j]=true;
	bool ret = false;
	for(int k=0;k<n;k++)
	{
		if(i-a[k]<0)
			continue;
		if(!check(i-a[k],j^1))
		{
			ret=true;
			break;
		}
	}
	return dp[i][j]=ret;

}
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL); 
	int k;
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>a[i];
	if(check(k,0))
		cout<<"First"<<endl;
	else
		cout<<"Second"<<endl;
	return 0;	
}


Measured memory_bytes: 9216
import sys
input = sys.stdin.readline

S=tuple(input().strip())
N=len(S)+1
sets = []
count = 0

for c in S:
    d = 1 if c == '<' else -1
    if count * d < 0:
        sets.append(count)
        count = d
    else:
        count += d
sets.append(count)

sum = 0
for i in range(len(sets)):
    k=sets[i]
    if k > 0:
        sum += (k*(k+1))//2
    else:
        sum += (k*(k-1))//2
        if i > 0:
            sum -= min(sets[i-1], -k)

print(sum)


Measured memory_bytes: 126436
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <iomanip>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <nmmintrin.h>
#include <chrono>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}


int main(void) {
	int n;
	cin >> n;
	vector<__int128> a(n);
	pair<__int128,int> Max = {-1, 0};
	REP(i, n) {
		int buf;
		scanf("%d", &buf);
		a[i] = buf;
		Max = max(Max, {abs(a[i]), i});
	}
	vector<pii> ans;

	REP(i, n) {
		if (i != Max.second) {
			ans.push_back({ Max.second, i});
			a[i] += a[Max.second];
		}
	}

	if (a[Max.second] > 0) {
		REP(i, n - 1) {
			if (a[i] > a[i + 1]) {
				ans.push_back({ i, i + 1 });
				a[i + 1] += a[i];
			}
		}
	}
	else {
		for(int i = n-1; 0 < i; i--)  {
			if (a[i] < a[i - 1]) {
				ans.push_back({ i , i-1});
				a[i - 1] += a[i];
			}
		}
	}
	cout << ans.size() << endl;
	for (auto itr : ans) {
		printf("%d %d\n", itr.first + 1, itr.second + 1);
	}

	return 0;
}

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

void output(const std::vector<int>& array)
{
	for (int i = 0; i < array.size(); ++i)
	{
		std::cout << array[i];
		if( i < array.size() - 1)
			std::cout << " ";
		else
			std::cout << std::endl;
	}
}

int main(int argc, char* argv[])
{
	int n = 0;
	std::cin >> n;
	std::vector<int> array(n);
	for (int i = 0; i < n; ++i)
		std::cin >> array[i];
	output(array);

	for (int i = 1; i < n; ++i)
	{
		const int key = array[i];
		int j = i - 1;
		for ( ;(j >= 0) && (array[j] > key); --j)
			array[j + 1] = array[j];
		array[j + 1] = key;
		output(array);
	}

	return 0;
}

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

#define M 1046527
#define L 14

//std::vector<std::string> sv(M);
char H[M][L];

long long int getChar(char a[]){
    int x;
    long long int key, p;
    key = 0;
    p = 1;

    for(int i = 0; i < strlen(a); i++){

        if(a[i] == 'A'){
            x = 1;
        }else if(a[i] == 'C'){
            x = 2;
        }else if(a[i] == 'G'){
            x = 3;
        }else if(a[i] == 'T'){
            x = 4;
        }
        key += p * x;
        p *= 5;
    }

    return key;
}

int hash1(long long int key){
    return key % M;
}

int hash2(long long int key){
    return 1 + (key % (M - 1));
}

int insert(char a[]){
    int hash;
    long long int key = getChar(a);
    int h1 = hash1(key);
    int h2 = hash2(key);
    for(long long int i = 0; ; i++){
        hash = (h1 + i * h2) % M;
        if(strlen(H[hash]) == 0){
            strcpy(H[hash], a);
            break;
            //return 1;
      
        }else if(strcmp(H[hash], a) == 0){
           //return 0;
           break;
        }
    }
    return 0;
}

int find(char a[]){
    int hash;

    long long int key = getChar(a);
    int h1 = hash1(key);
    int h2 = hash2(key);
    for(long long int i = 0; ; i++){
        hash = (h1 + i * h2) % M;
    
        if(strlen(H[hash]) == 0){
            printf("no\n");
            break;
            //return 0;
        }else if(strcmp(H[hash], a) == 0){
            printf("yes\n");
            break;
            //return 1;
        }
    }
    return 0;

}

int main(void){
    int n;
    //std::string s1, s2;
    char t1[14];
    char t2[14];
    for(int i = 0; i < M; i++){
        H[i][0] = '\0';
    }
    scanf("%d", &n);
    for(int i = 0; i < n; i++){

        scanf("%s %s", t1, t2);
    
        //std::cin >> s1 >> s2;
        
        //std::string s1 = t1;
        //std::string s2 = t2;
        if(t1[0] == 'i'){
            insert(t2);
        }else{
            find(t2);
        }
    }
    return 0;
}


Measured memory_bytes: 17452
import java.util.*;

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

    int n = sc.nextInt();
    int x = sc.nextInt();

    int[] l = new int[n + 1];
    for (int i = 1; i < n + 1; i++) {
      l[i] = sc.nextInt();
    }

    int d = 0;
    int ans = 1;
    for (int i = 0; i < n; i++) {
      if (d + l[i + 1] > x) {
        break;
      } else {
        ans++;
        d += l[i + 1];
      }
    }
    
    System.out.println(ans);
  }
}


Measured memory_bytes: 21844
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
 
typedef unsigned long long int ll;
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define  ff          first
#define  ss          second
#define  pb          push_back
#define  IOS         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  lb          lower_bound
#define  ub          upper_bound
#define  D2(x)       { cerr << "[" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }
#define  all(x)      (x).begin(), (x).end()
#define  mem(a)      memset(a , 0 ,sizeof a)
#define  deb(x)      cout << #x << " - " << x << "\n";
#define  ps(x,y)     fixed<<setprecision(y)<<x
#define  setbit(x)   __builtin_popcount(x)
#define  deb2(x,y)   cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define  rep(i,a,b)  for(int i=a ; i<b ; ++i)
#define  repr(i,a,b)  for(int i=a ; i>=b ; --i)
 
#define PI 3.141592653589793
const ll p = 5;
const ll INF = 1000000000;
const ll MAX_N = 2e5 + 2;

int main() {
    IOS;
    ll n,total = 0; cin >> n;
    vi v(n);
    rep(i,0,n) cin >> v[i], total ^= v[i];
    rep(i,0,n) cout << (total^v[i]) << ' ';
}

Measured memory_bytes: 3944
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

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

int main() {
    uint64_t N;
    cin >> N;

    if(N % 2) {
        cout << 0 << endl;
        return 0;
    }

    uint64_t ret = 0;
    uint64_t diviser = 10;

    while(1) {
        uint64_t diff = N / diviser;
        ret += diff;
        if(diff==0)
            break;
        diviser *= 5;

    }
    cout << ret << endl;

    return 0;
}



Measured memory_bytes: 3192
/*
	Name: Harshit Jain
	Institution: IIIT Vadodara
*/
#include <bits/stdc++.h>
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define pb push_back
#define mp make_pair
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ull unsigned long long
#define rep(i,a,b) for(ll i = a; i < b; ++i)
#define sz(a) int((a).size()) 
#define pb push_back 
#define all(c) (c).begin(),(c).end() 
#define tr(c,i) for(typeofa((c).begin() i = (c).begin(); i != (c).end(); i++) 
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end()) 
#define p(a) cout << a << "\n";
#define p1(a) cout << a << " ";

#define PI 3.141592653589793
#define MOD (ll)(1e9 + 7)
#define m(a) ((a)%MOD)

using namespace std;
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef pair<int,int> ii; 
//=======================

void solve()
{
	int t;
	cin >> t;
	int prev = 0, prev_time = 0;
	while(t--)
	{
		int a,b,c;
		cin >> a >> b >> c;
		int min_time = abs(b+c - prev);
		// p(min_time)
		if(min_time > a || (a - min_time - prev_time)%2 == 1)
		{
			p("No")
			return;
		}
		prev_time = a;
		prev = b+c;
	}
	p("Yes")
}

//=======================
int main()
{
	bool testing = false;
	IOS
	if(testing)
	{
		freopen("test.txt","rt",stdin);
		int start = clock();
		solve();
		int end = clock();
		cout << "time: " << (end - start)/(double)(CLOCKS_PER_SEC)*1000 << " milliseconds\n";
	}
	else
	{
		solve();
	}
} 

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
 
namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            var enc = new Dictionary<string, string> {
                {" " , "101"     }, {"'" , "000000"  }, {"," , "000011"  }, {"-" , "10010001"},
                {"." , "010001"  }, {"?" , "000001"  }, {"A" , "100101"  }, {"B" , "10011010"},
                {"C" , "0101"    }, {"D" , "0001"    }, {"E" , "110"     }, {"F" , "01001"   },
                {"G" , "10011011"}, {"H" , "010000"  }, {"I" , "0111"    }, {"J" , "10011000"},
                {"K" , "0110"    }, {"L" , "00100"   }, {"M" , "10011001"}, {"N" , "10011110"},
                {"O" , "00101"   }, {"P" , "111"     }, {"Q" , "10011111"}, {"R" , "1000"    },
                {"S" , "00110"   }, {"T" , "00111"   }, {"U" , "10011100"}, {"V" , "10011101"},
                {"W" , "000010"  }, {"X" , "10010010"}, {"Y" , "10010011"}, {"Z" , "10010000"}
            };
            var dec = new Dictionary<string, string> {
                {"00000","A"}, {"00001","B"}, {"00010","C"}, {"00011","D"},
                {"00100","E"}, {"00101","F"}, {"00110","G"}, {"00111","H"},
                {"01000","I"}, {"01001","J"}, {"01010","K"}, {"01011","L"},
                {"01100","M"}, {"01101","N"}, {"01110","O"}, {"01111","P"},
                {"10000","Q"}, {"10001","R"}, {"10010","S"}, {"10011","T"},
                {"10100","U"}, {"10101","V"}, {"10110","W"}, {"10111","X"},
                {"11000","Y"}, {"11001","Z"}, {"11010"," "}, {"11011","."},
                {"11100",","}, {"11101","-"}, {"11110","'"}, {"11111","?"}
            };
            string input;
            while((input = Console.ReadLine()) != null) {
                var val = string.Join("", input.Select(p => enc[p.ToString()]).ToArray());
                if(val.Length % 5 != 0) {
                    val += new string('0', 5 - (val.Length % 5));
                }
                Console.WriteLine(string.Join("", Enumerable.Range(0, val.Length / 5).Select(p => val.Substring(p * 5, 5)).Select(p => dec[p]).ToArray()));
            }
        }
    }
}

Measured memory_bytes: 6048
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll, ll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define reQv(a) reverse(all(a)
#define ld long double
const ll mod=1e9+7;
const ld pi=3.1415926535;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
int main() {
    IOS;
    ld r;
    cin >> r;
    ld ans=2*pi*r;
    cout << fixed << setprecision(18) << ans << endl;
	return 0;
}

Measured memory_bytes: 3804
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# LANGUAGE BangPatterns      #-}
{-# LANGUAGE CPP               #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections     #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString             as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           Unsafe.Coerce

main :: IO ()
main = do
    !n <- readLn :: IO Int
    bs <- B.getLine
    print $ solve n bs

solve :: Int -> B.ByteString -> Int
solve n bs = M.foldl' (+) 0 $ M.intersectionWith (*) leftFreq rightFreq
  where
    (left, right) = B.splitAt n bs
    lefts = pairs n left
    rights = map swap . pairs n $ B.reverse right
    !leftFreq = foldl' (\m pair -> M.insertWith (+) pair 1 m) M.empty lefts
    !rightFreq = foldl' (\m pair -> M.insertWith (+) pair 1 m) M.empty rights

pairs :: Int -> B.ByteString -> [(B.ByteString, B.ByteString)]
pairs n bs = [divide i bs|i<-[0..2^n-1]]
  where
    divide :: Int -> B.ByteString -> (B.ByteString, B.ByteString)
    divide i bs = (xs, ys)
      where
        (xis, yis) = partition (testBit i) [0..n-1]
        !xs = B.pack $ map (B.unsafeIndex bs) xis
        !ys = B.pack $ map (B.unsafeIndex bs) yis



Measured memory_bytes: 301052
iter_num = input()
variables = input()

raw_variables = variables.split(' ')
variables = list()

for raw_variable in raw_variables:
    variables.append(int(raw_variable))


def calc(variable):
    process_count = 0
    while (variable % 2 == 0):
        process_count += 1
        variable = variable / 2
    return process_count


min_count = None

for variable in variables:
    process_count = calc(variable)
    if min_count is None:
        min_count = process_count
    if process_count < min_count:
        min_count = process_count

print(min_count)


Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, k;
  cin >> n >> k;
  vector<int> s(1 << (n + 1));
  for (int l = 0; l <= n; ++l) {
    string str;
    cin >> str;
    for (int i = 0; i < (1 << l); ++i)
      s[i | (1 << l)] = str[i] == '1';
  }
  function<vector<vector<int>>(int, vector<int>)> solve = [&](int n, vector<int> s) {
    vector<vector<int>> ret(4, vector<int>(1 << (n + 1)));
    ret[0][1] = s[1];
    if (n) {
      vector<int> s0(1 << n), s1(1 << n);
      for (int i = 2; i < (1 << (n + 1)); ++i)
        ((i & 1) ? s1 : s0)[i >> 1] = s[i];
      auto r0 = solve(n - 1, s0), r1 = solve(n - 1, s1);
      for (int x = 0; x < 4; ++x)
        for (int j = 1; j < (1 << n); ++j)
          ret[x | 1][j] += r0[x][j];
      for (int x = 0; x < 4; x += 2)
        for (int j = 1; j < (1 << n); ++j)
          ret[0][j << 1] += r0[x][j];
      for (int x = 0; x < 4; ++x)
        for (int j = 1; j < (1 << n); ++j)
          ret[x | 2][j] += r1[x][j];
      for (int x = 0; x < 2; ++x)
        for (int j = 1; j < (1 << n); ++j)
          ret[0][(j << 1) | 1] += r1[x][j];
    }
    return ret;
  };
  auto res = solve(n, s);

  for (int l = n; l; --l)
    for (int x = 0; x < 1 << l; ++x) {
      int v = 0;
      for (int j = 0; j < 4; ++j)
        v += res[j][x | 1 << l];
      if (v >= k) {
        for (int i = l - 1; i >= 0; --i)
          putchar('0' + ((x >> i) & 1));
        putchar('\n');
        goto DONE;
      }
    }
  DONE:;

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 140444
s=input()
K=int(input())
l=len(s)


L=[]

for i in range(l):
    L=L+[s[i]]

for i in range(l-1):
    L=L+[s[i]+s[i+1]]

for i in range(l-2):
    L=L+[s[i]+s[i+1]+s[i+2]]

for i in range(l-3):
    L=L+[s[i]+s[i+1]+s[i+2]+s[i+3]]
    
for i in range(l-4):
    L=L+[s[i]+s[i+1]+s[i+2]+s[i+3]+s[i+4]]


M=sorted(list(set(L)))

print(M[K-1])

Measured memory_bytes: 5172
#include<cstdio>
using namespace std;
int main()
{
	int n;
	scanf("%d", &n);
	int x = n;
	int sum = 0;
	while (n)
	{
		sum = sum + (n % 10);
		n /= 10;
	}
	if (x%sum)
	{
		puts("No");
	}
	else
		puts("Yes");
}

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



int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if (d<=a) cout<<d;
    else if (d<=b+a) cout<<a;
    else if (d<=a+b+c) cout<<a-(d-a-b);
    else cout<<a-c;


	return 0;
}


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

using namespace std;

int main()
{

    int n;
    cin>>n;

    int total = 0;
    for(int i = 1;i<=n;i++)
    {
        total += n/i;
    }

    for(int i = 1;i <= n;i++)
    {
       if(n % i == 0)
       {
           total--;
       }
    }
    cout<<total <<"\n";
    
    return 0;
}

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


int main() {
    string s;
    cin >> s;
    string agct = "AGCT";
    int max_len = 0;
    int current_len = 0;
    for (int i = 0; i < s.size(); i++) {
        if (count(agct.begin(), agct.end(), s.at(i)) == 0) {
            if (current_len > max_len) max_len = current_len;
            current_len = 0;
            continue;
        } else {
            current_len++;
        }
    }

    if (current_len > max_len) max_len = current_len;
    cout << max_len << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

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

  int match = 0;
  for(int i = 0; i < 3; i++) {
    if(S[i] == T[i]) {
      match++;
    }
  }

  std::cout << match;

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */


// 素数列挙
const ll MAX_PRIME = 100000;
vector<int> primes;
vector<int> is_prime(MAX_PRIME + 1,true);
void init_primes(){
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <= MAX_PRIME;i++){
        if(is_prime[i]){
            primes.push_back(i);
            for(int j = i*2; j <= MAX_PRIME; j+=i) is_prime[j] = false;
        }
    }
}

template<class Type>
Type solve(Type res = Type()){
    init_primes();
    ll m,a,b;
    while(cin >> m >> a >> b,a){
        
        ll maxm = -1;
        pll ans = {-1,-1};
        for(int i = 0; i < primes.size();i++){
            for(int j = i; j < primes.size();j++){
                ll L = primes[i] , R = primes[j];
                if(L*R > m) break;
                
                if(a*R <= b*L){
                    if(maxm < R*L){
                        maxm = R*L;
                        ans = pll(L,R);
                    }
                }
            }
        }
        cout << ans.first << " " << ans.second << endl;
    }
    return res;
}


int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve(0);
    // cout << fixed << setprecision(15) << solve<string>() << endl;
    return 0;
}



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



int main(){
    ll n,k;cin>>n>>k;
    if((n-1)*(n-2)/2<k)cout<<-1<<endl;
    else{
        cout<<(n-1)*n/2-k<<endl;
        for(int i=1;i<=n-1;i++){
            for(int j=i+1;j<=n;j++){
                if(j!=n&&k){
                    k--;
                }
                else{
                    cout<<i<<" "<<j<<endl;
                }
            }
        }
    }
}

    









Measured memory_bytes: 256
n = int(input())
w = list(map(int, input().split()))

s1 = w[0]
s2 = w[n - 1]
c1 = 1
c2 = 1

ref = sum(w)

for i in range(n - 2):
    if abs(s1 + w[c1] - s2) >= abs(s1 - (s2 + w[n - 1 - c2])):
        s2 = s2 + w[n - 1 - c2]
        c2 = c2 + 1
    else:
        s1 = s1 + w[c1]
        c1 = c1 + 1

print(abs(s1 - s2))

Measured memory_bytes: 3064
class Newhash < Hash
  def [](key)
    self[key] = Array.new if !has_key?(key)
    super(key)
  end
end
def main
  hsh = Newhash.new
  while arg = gets
    arg = arg.split(" ")
    hsh[arg[0]] << arg[1].to_i
  end  
  hsh.keys.sort.each{|key|
    puts key, hsh[key].sort.join(" ")
  }
end
main

Measured memory_bytes: 6096
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if (k<=a) {
        cout << k << endl;
    }
    else if (k <= a+b) {
        cout << a << endl;
    }
    else {
        cout << a - (k-a-b) << endl;
    }
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

long long ncr(int n, int r) {
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    long long ans = 1;
    int i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
ll mod(ll a,ll b,ll m){
    if(b==0)return 1;
    if(b%2==0){
        ll y =  mod(a,b/2,m);
        return (y*y)%m;
    }
    else{
        return ((a%m)*mod(a,b-1,m))%m;
    }
}

ll modinv(ll a,ll m){
return mod(a,m-2,m);
//works only for prime m.
//else calculate phi(m)-1.
}



int main()
{
    int n,x,t;
    cin>>n>>x>>t;
    int s=0;
    while(n>0){
        s+=t;
        n-=x;
    }
    cout<<s;

    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

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

// value
int N, A, B, C;
vi l;

struct Flags {
	vi f;

	Flags(int N) {
		f.resize(N, 0);
	}

	int inc() {
		f[0]++;
		for (int i = 0; i < f.size() - 1; i++) {
			if (f[i] > 3) {
				f[i] = 0;
				f[i + 1]++;
			}
		}
		if (f.back() > 3) return 1;
		return 0;
	}

};

void solve() {

	int mp = 1e8;

	cin >> N >> A >> B >> C;
	Flags flag(N);
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		l.eb(tmp);
	}

	while (!flag.inc()) {
		bool af = false, bf = false, cf = false;
		int sumA = 0, sumB = 0, sumC = 0;
		int lenA = 0, lenB = 0, lenC = 0;

		for (int i = 0; i < N; i++) {
			if (flag.f[i] == 1) {
				lenA += l[i];
				if (af) {
					sumA += 10;
				}
				else {
					af = true;
				}
			}
			if (flag.f[i] == 2) {
				lenB += l[i];
				if (bf) {
					sumB += 10;
				}
				else {
					bf = true;
				}
			}
			if (flag.f[i] == 3) {
				lenC += l[i];
				if (cf) {
					sumC += 10;
				}
				else {
					cf = true;
				}
			}
		}

		if (af == true && bf == true && cf == true) {
			mp = min(mp, abs(lenA - A) + abs(lenB - B) + abs(lenC - C) + sumA + sumB + sumC);
		}

	}

	cout << mp << endl;


	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

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

#define is_uruu leapyear
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(a);i>(b);--i)
#define REP(i,a) for(int i=0;i<(a);++i)


 
int main()
{
	int n, a, to, A[200005];
	cin >> n;
	
	FOR(i, 0, n){
		cin >> a;
		if(i%2 == n%2){
			to = n/2+(i+1)/2;
		} 
		else {
			to = n/2-(i+1)/2;
		}
		A[to] = a;
	}
	
	FOR(i, 0, n){
		printf("%d%c", A[i], i==n-1?'\n':' ');
	}
	
	return 0;
}

Measured memory_bytes: 2944
n,m = map(int,input().split())
db = []

for i in range(n):
    a,b = map(int,input().split())
    if(a<=m):
        db.append([m-a,-1*b])

db.sort(reverse=True)

# ヒープキュー（最小値・最大値の取得）
import heapq
a=[]
heapq.heapify(a)

ans = 0
pnt = 0
day = m-1
while(day>=0):
    if(pnt < len(db)):
        while(db[pnt][0] == day):
            heapq.heappush(a,db[pnt][1])
            pnt += 1
            if(pnt == len(db)):
                break
    day -= 1

    if(len(a) > 0):
        ans -= heapq.heappop(a)

print(ans)

Measured memory_bytes: 70232
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
int main()
{
  ll d; cin >> d;
  vector<ll> c(26);
  rep(i,26) cin >> c[i];
  vector<vector<ll>> s(d, vector<ll>(26));
  rep(i,d) {
    rep(j,26) {
      cin >> s[i][j];
    }
  }
  vector<ll> t(d);
  rep(i,d) {
    cin >> t[i];
    t[i]--;
  }

  ll res = 0;
  vector<ll> last(26, -1);
  rep(i,d) {
    res += s[i][t[i]];
    last[t[i]] = i;
    rep(j,26) {
      res -= c[j] * (i - last[j]);
    }
    cout << res << "\n";
  }
  return 0;
}


Measured memory_bytes: 3688
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int n, m, q;
int ma = 0;
int a[55], b[55], c[55], d[55];
int now = 1;
void dfs(vector<int> v) {
	if (v.size() == n) {
		int co = 0;
		for (int k = 0; k < q; k++) {
			if (v[b[k] - 1] - v[a[k] - 1] == c[k]) {
				co += d[k];
			}
		}
		if (ma < co) {
			ma = co;
		}
		return;
	}
	for (int i = now; i <= m; i++) {
		now = i;
		v.push_back(i);
		dfs(v);
		v.pop_back();
	}
}
int main() {
	cin >> n >> m >> q;
	for (int i = 0; i < q; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	vector<int> vec;
	dfs(vec);
	cout << ma << endl;
	return 0;
}

Measured memory_bytes: 3604