akhauriyash/Code-Regression huggingface dataset:
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#include<list>
#include<limits>
#include<bitset>
#define MOD 10007LL
#define INF 100000000LL
#define MAX 8001
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
int main() {    
    string s;
    cin>>s;
    int x,y;
    cin>>x>>y;
    x+=MAX;
    y+=MAX;
    int sl=s.length();
    int fx[MAX]={};
    int fy[MAX]={};
    int c=0;
    int tc=0;
    bool f=true;
  	int sx=0;
  	int sy=0;
    for(int i=0;i<sl;i++){
        if(s[i]=='F'){
            tc=0;
            c++;
        }else{
            if(tc==0){
                if(f){
                    sx++;
                    fx[sx]+=c;
                }else{
                    sy++;
                    fy[sy]+=c;
                }
                c=0;
            }
            tc++;
            f=!f;
        }
    }
    if(f){
	    sx++;
      	fx[sx]+=c;
    }else{
        sy++;
      	fy[sy]+=c;
    }
    bool dpx[4050][MAX*2+1]={false};
    bool dpy[4050][MAX*2+1]={false};
    dpy[0][MAX]=true;
    dpx[1][MAX+fx[1]]=true;
    for(int i=2;i<=sx;i++){
        for(int j=0;j<=MAX*2;j++){
            if(j>=fx[i]){
                dpx[i][j]|=dpx[i-1][j-fx[i]];
            }
            if(j+fx[i]<=MAX*2){
                dpx[i][j]|=dpx[i-1][j+fx[i]];
            }
        }
    }
    for(int i=1;i<=sy;i++){
        for(int j=0;j<=MAX*2;j++){
            if(j>=fy[i]){
                dpy[i][j]|=dpy[i-1][j-fy[i]];
            }
            if(j+fy[i]<MAX*2){
                dpy[i][j]|=dpy[i-1][j+fy[i]];
            }
        }
    }
    if(dpx[sx][x]&&dpy[sy][y]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

                           


Measured memory_bytes: 126848
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
   int N;
   cin>>N;
   if(N>999){
       cout<<"ABD"<<endl;
   }
   else{
       cout<<"ABC"<<endl;
   }
   
}

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

int main() {
    vector<vector<int>> vec(3, vector<int>(3));
    rep(i, 3) rep(j, 3) cin >> vec[i][j];
    vector<int> x(3), y(3);
    x[0] = 0;
    rep(i, 3) y[i] = vec[0][i] - x[0];
    rep(i, 3) x[i] = vec[i][0] - y[0];
    string ans = "Yes";
    rep(i, 3) {
        rep(j, 3) if (x[i] + y[j] != vec[i][j]) ans = "No";
    }
    cout << ans << endl;
    return 0;
}

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

#define INIT_CAP 10
#define INF 1000000000

inline int nextInt(void) {
	int ch;
	int sign, x;

	do {
		ch = getchar();
	} while (ch < '-');

	if (ch == '-') {
		sign = -1;
		ch = getchar();
	} else
		sign = 1;

	x = 0;
	while (ch >= '0' && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}

	return sign * x;
}

inline void printInt(int x) {
	char ch[10];
	int cnt;

	if (x < 0) {
		putchar('-');
		x = -x;
	}

	cnt = 0;
	do {
		ch[cnt++] = '0' + x % 10;
		x /= 10;
	} while (x);

	while (cnt--)
		putchar(ch[cnt]);
}

typedef struct {
	int to, w;
} Edge;

typedef struct {
	Edge *elem;
	int cap, size;
} VecEdge;

typedef struct {
	int num, d;
} PNumDis;

VecEdge adj[10000];
PNumDis heap[500000];
int hsize;
int d[10000];

void init(int n) {
	while (n--)
		adj[n] = (VecEdge){malloc(sizeof(Edge) * INIT_CAP), INIT_CAP, 0};
}

inline void add(int from, int to, int w) {
	if (adj[from].size == adj[from].cap) {
		adj[from].cap <<= 1;
		adj[from].elem = realloc(adj[from].elem, sizeof(Edge) * adj[from].cap);
	}
	adj[from].elem[adj[from].size++] = (Edge){to, w};
}

inline void insert(int num, int d) {
	int i;
	for (i = hsize++; i > 0 && d < heap[i - 1 >> 1].d; i = i - 1 >> 1)
		heap[i] = heap[i - 1 >> 1];
	heap[i] = (PNumDis){num, d};
}

inline int calcNextIdx(int i) {
	return i * 2 + 1 + (i * 2 + 2 < hsize && heap[i * 2 + 1].d > heap[i * 2 + 2].d);
}

inline PNumDis delete(void) {
	int i;
	int nextIdx;
	const PNumDis root = heap[0], last = heap[--hsize];

	for (i = 0; i * 2 + 1 < hsize && last.d > heap[nextIdx = calcNextIdx(i)].d; i = nextIdx)
		heap[i] = heap[nextIdx];
	heap[i] = last;

	return root;
}

void dijkstra(int n, int s) {
	int i;

	for (i = 0; i < n; i++)
		d[i] = INF;

	d[s] = 0;
	insert(s, 0);
	while (hsize > 0) {
		const PNumDis fromP = delete();

		if (fromP.d > d[fromP.num])
			continue;

		for (i = 0; i < adj[fromP.num].size; i++) {
			const Edge e = adj[fromP.num].elem[i];
			if (fromP.d + e.w < d[e.to]) {
				d[e.to] = fromP.d + e.w;
				insert(e.to, d[e.to]);
			}
		}
	}
}

int main(void) {
	int i;
	int n;

	scanf("%d", &n);

	init(n);
	for (i = 0; i < n; i++) {
		int u = nextInt(), k = nextInt();
		while (k--) {
			int v = nextInt(), c = nextInt();
			add(u, v, c);
		}
	}

	dijkstra(n, 0);

	for (i = 0; i < n; i++) {
		printInt(i);
		putchar(' ');
		printInt(d[i]);
		putchar('\n');
	}

	return 0;
}


Measured memory_bytes: 6724
n=int(input())
l=[["a"],["aa","ab"],[],[],[],[],[],[],[],[]]
for i in range(2,10):
  for j in l[i-1]:
    syurui=len(set(list(j)))
    for h in range(syurui+1):
      l[i].append(j+chr(97+h))
for i in l[n-1]:print(i)

Measured memory_bytes: 56540
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Usize1},
};

#[fastout]
fn main() {
    input! {
        s: Bytes,
        t: Bytes,
    }
    println!(
        "{}",
        (0..=s.len() - t.len())
            .map(|i| t.iter().zip(&s[i..]).filter(|&(s, t)| s != t).count())
            .min()
            .unwrap()
    );
}


Measured memory_bytes: 2196
#include <iostream>
#include <iomanip>
#include <string>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    string s;
    cin >> s;
    bool c = false, f = false;
    repi(i, s.size(), 0)
    {
        if (!c)
        {
            if (s.at(i) == 'C')
                c = true;
        }
        else if (s.at(i) == 'F')
            f = true;
    }
    if (c && f)
    {
        puts("Yes");
    }
    else
    {
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 256
def examA():
    N, R = LI()
    ans = R+100*max(0,(10-N))
    print(ans)
    return

def examB():
    N, K = LI()
    ans = 1
    while(N>=K):
        N //=K
        ans += 1
    print(ans)
    return

def examC():
    N = I()
    X = LI()
    ans = inf
    for i in range(101):
        cur = 0
        for x in X:
            cur += (i-x)**2
        ans = min(ans,cur)
    print(ans)
    return

def examD():
    def cmb(n, r, mod):
        cur = 1
        for i in range(r):
            cur *= (n-i)
            cur %= mod
        for i in range(r):
            cur *= pow(i+1,mod-2,mod)
            cur %= mod
        return cur
    n, a, b = LI()
    ans = pow(2,n,mod) - cmb(n,a,mod) - cmb(n,b,mod) -1
    ans = (ans+mod*2)%mod
    print(ans)
    return

def examE():
    class combination():
        # 素数のmod取るときのみ　速い
        def __init__(self, n, mod):
            self.n = n
            self.fac = [1] * (n + 1)
            self.inv = [1] * (n + 1)
            for j in range(1, n + 1):
                self.fac[j] = self.fac[j - 1] * j % mod

            self.inv[n] = pow(self.fac[n], mod - 2, mod)
            for j in range(n - 1, -1, -1):
                self.inv[j] = self.inv[j + 1] * (j + 1) % mod

        def comb(self, n, r, mod):
            if r > n or n < 0 or r < 0:
                return 0
            return self.fac[n] * self.inv[n - r] * self.inv[r] % mod
    n, k = LI()
    C = combination(2*10**5+1,mod)
    if k>n:
        k = n
    ans = 0
    for i in range(k+1):
        cur = C.comb(n,i,mod) * C.comb(n-1,i,mod)
        ans += cur
        ans %= mod
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examE()

"""

"""

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    int N, M;
    cin >> N >> M;
    map<int, int> V;
    REP(i,M){
        int a, b;
        cin >> a >> b;
        a--, b--;
        V[a]++;
        V[b]++;
    }

    bool ans = true;
    for(auto&& p : V){
        int v = p.first;
        int c = p.second;
        if(c % 2 != 0)
            ans = false;
    }

    if(ans){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;


int main(){
    int N;
    cin>>N;
    string s;
    cin>>s;
    string t="ABC";
    int j=0;

    int ans=0;
    rep(i,N){
        if(s[i]==t[j]){
        j++;
        }
        else if(s[i]=='A'){
        j=1;
        }
        else{
            j=0;
        }
        if(j==3){
            ans++;
            j=0;
        }
    }
    
    cout<<ans<<endl;

return 0;

}
/*


*/


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

using namespace std;
#define forn(i,n) for(i=0;i<n;i++)
#define forn1(i,a,n) for(i=a;i<n;i++)

int32_t main(void)
{
	int i,n,j,x;
	cin>>n;
	vector<int>dp(n,INT_MAX);
	vector<int>h(n);
	forn(i,n)
	{
		cin>>h[i];
	}
	dp[0]=0;
	dp[1]=fabs(h[0]-h[1]);
	forn1(i,2,n)
	{
		dp[i]=min(dp[i-1]+fabs(h[i-1]-h[i]),dp[i-2]+fabs(h[i-2]-h[i]));
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

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

using namespace std;

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)
#define SCANFD(x) scanf("%d",&x)

int main(){
    int N,A;

    scanf("%d%d",&N,&A);

    printf("%d\n",N*N-A);
    return 0;
}


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

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

    int ans = 0;
    for (int a = 1; a <= K; a++) {
        for (int b = 1; b <= K; b++) {
            for (int c = 1; c <= K; c++) {
                ans += gcd(gcd(a, b), c);
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {

    string s;
    cin >> s;

    int n = s.size();
    int sum = 0;
    int inc = 0;
    s = "0" + s;
    for(int i = n; i >= 1; i--){
        int tmp = (s[i] - '0') + inc;
        if (tmp == 5){
            int tmp1 = (s[i-1] - '0');
            inc = (tmp1 >= 5) ? 1 : 0;
            sum += 5;
        }
        else if (tmp >= 6){
            inc = 1;
            sum += 10 - tmp;
        }else{
            inc = 0;
            sum += tmp;
        }
    }
    if (inc == 1) sum++;

    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 2308
//我是菜鸡
#include<bits/stdc++.h>
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _defor(i,a,b) for((i) = (a);(i)<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto p:st)
#define debug(q,x) cout<<q<<x<<endl
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;
const double ext = 1e-6;
void deprint() {
	//ofstream cout("E:\\acm dream\\debug.txt");
	return;
}
int main() {
	//ifstream cin("E:\\acm dream\\in.txt");
	//ofstream cout("E:\\acm dream\\out.txt");
	//srand((unsigned)time(nullptr));
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int a[100], n, so[3];
	while (cin >> n) {
		int ans = 0;
		memset(a, 0, sizeof(a));
		_for(i, 0, n)cin >> a[i];
		_for(i, 1, n - 1) {
			so[0] = a[i], so[1] = a[i - 1], so[2] = a[i + 1];
			sort(so, so + 3);
			if (a[i] == so[1])ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#define taskname ""

#include <iostream>
#include <algorithm>

using namespace std;
#define long long long

const int N = 1e5 + 10;
const int MOD = 1e9 + 7;

int n, k, a[N], f[110][N], pre[N];

int main()
{
//    freopen(taskname".INP", "r", stdin);
//    freopen(taskname".OUT", "w", stdout);
    cin.tie(nullptr); ios_base::sync_with_stdio(false);

    cin >> n >> k;
    for (int i = 1; i <= n; ++i) cin >> a[i];

    f[0][0] = 1;
    for (int i = 1; i <= n; ++i) {
        fill(pre, pre + N, 0);
        pre[0] = f[i - 1][0];
        for (int sum = 1; sum <= k; ++sum) pre[sum] = (pre[sum - 1] + f[i - 1][sum]) % MOD;

        for (int sum = 0; sum <= k; ++sum)
            f[i][sum] = (pre[sum] - (sum - a[i] - 1 < 0 ? 0 : pre[sum - a[i] - 1]) + MOD) % MOD;
    }
    cout << f[n][k];

    return 0;
}


Measured memory_bytes: 40832
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/

import math
import statistics

# fact(int)
def fact(n):
  if(n == 1):
    return 1
  else:
    return (n * fact(n - 1))

# gcd(int,int)
def gcd(a,b):
  if a == 0:
    return b
  elif b == 0:
    return a
  else:
    return gcd(b,a % b)

# lcm(int,int)
def lcm(a,b):
  return (a * b / gcd(a,b))

# qsort(array[])
def qsort(seq):
  if len(seq) < 1:
      return seq
  pivot = seq[0]
  left = []
  right = []
  for x in range(1, len(seq)):
    if seq[x] <= pivot:
        left.append(seq[x])
    else:
        right.append(seq[x])
  left = qsort(left)
  right = qsort(right)
  foo = [pivot]
  return (left + foo + right)

# = map(int, input().split())
n  = int(input())
#  = raw_input().split()
v  = list(int(i) for i in input().split())  
lastguzai = 0.00

for i in range(n):
  vs = sorted(v)
  if len(v) == 2:
    lastguzai = (v[0] + v[1]) / 2.00
    break
  # print(vs)
  v = vs
  lastguzai = (v[0] + v[1]) / 2.00
  del v[0]
  del v[0]
  
  v.append(lastguzai)
  # print(v)

print('{:.6f}'.format(lastguzai))


Measured memory_bytes: 5776
import sys

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
date = {a, b, c, d, e}
for h in date:
    for i in date:
        if int(abs(h - i)) > k:
            print(':(')
            sys.exit()

print('Yay!')


Measured memory_bytes: 3060
N = gets.to_i
E = []
N.times{|i|
  x, y = gets.chomp.split(" ").map(&:to_i)
  next if x == 0 && y == 0
  E << Complex(x, y)
}

def solve(ans, c, lst, all)
  if c.angle > 0 then
    wk1 = E.select{|e| c.angle <= e.angle || e.angle < (c.angle - Math::PI)}.inject(&:+)
    wk2 = E.select{|e| c.angle < e.angle || e.angle <= (c.angle - Math::PI)}.inject(&:+)
  else
    wk1 = E.select{|e| c.angle <= e.angle && e.angle < (c.angle + Math::PI)}.inject(&:+)
    wk2 = E.select{|e| c.angle < e.angle && e.angle <= (c.angle + Math::PI)}.inject(&:+)
  end
  wk1 = 0 if wk1.nil?
  wk2 = 0 if wk2.nil?
  [ans, wk1.abs, wk2.abs, (all - wk1).abs, (all - wk2).abs].max
end

all = E.inject(&:+)
ans = 0
E.each{|e|
  ans = solve(ans, e, E.dup, all)
}

puts ans


Measured memory_bytes: 1916
import sys

n, T, *t = map(int, sys.stdin.read().split())

def main():
    pushed = t[0]
    tot = 0
    for x in t[1:]:
        tot += min(T, x - pushed)
        pushed = x
    tot += T
    print(tot)

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 25132
N, K = map(int, input().split())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans = 0
for i in range(N):
  a = 0
  b = 0
  for j in range(N):
    if j < i and A[j] < A[i]:
      a += 1
    elif i < j and A[i] > A[j]:
      b += 1
  ans = (ans + ((K - 1) * a + (K + 1) * b) * K // 2) % mod
print(ans)

Measured memory_bytes: 68428
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MAX_N (200010)
P a[MAX_N];
int main()
{
    int N;
    scanf("%d", &N);

    for ( int i = 0; i < N; i++ ) {
	scanf("%d\n", &a[i].first);
	a[i].second = i + 1;
    }

    sort(a, a+N);

    ll ans = 0;
    set<int> s;// = {0, N+1};
    s.insert(0);
    s.insert(N+1);

    for ( int i = 0; i < N; i++ ) {
	P p = a[i];
	int index = p.second;
	s.insert(index);
	set<int>::iterator it = s.find(index);
	set<int>::iterator l = it;
	set<int>::iterator r = it;
	l--;
	r++;
	ll add = (ll)(*r - index) * (index - *l) * p.first;
	ans += add;
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 11136
int main(){
 while(1){
  int a,b,x;
  char op;
  scanf("%d %c %d",&a,&op,&b);
  if(op=='+'){
   x=a+b;
   printf("%d\n",x);
  }else if(op=='-'){
   x=a-b;
   printf("%d\n",x);
  }else if(op=='*'){
   x=a*b;
   printf("%d\n",x);
  }else if(op=='/'){
   x=a/b;
   printf("%d\n",x);
  }else{
   break;
  }
 }
}

Measured memory_bytes: 1808
from itertools import product
N = int(input())

F = [list(map(int,input().split())) for _ in range(N)]
P = [list(map(int,input().split())) for _ in range(N)]

c = product([0,1],repeat=10)
profits = []

for i in c:
    i = list(i)
    if sum(i) == 0:
        continue
    Duplist = []
    profit = 0
    for j in range(N):
        shop = F[j]
        Dup = 0
        for i_,k in enumerate(shop):
            if i[i_] == 1 and k == 1:
                Dup += 1
        Duplist.append(Dup)
    for i_,j in enumerate(Duplist):
        profit += P[i_][j]
    profits.append(profit)
    
print(max(profits))

Measured memory_bytes: 3188
<?php
function zigzag($y,$x,$n)
{
  if($y==0)
    {
      if(($x % 2)==0)
	return(($x+2)*($x+1)/2);
      else
	return(1 + $x*($x+1)/2);
    }

  if($x + $y < $n)
    {
      if(($x+$y)%2 == 0)
	return(-$y+zigzag(0,$x+$y,$n));
      else
	return($y+zigzag(0,$x+$y,$n));
    }
  return($n*$n+1-zigzag($n-1-$y,$n-1-$x,$n));

}
$no=1;
while(fscanf(STDIN,"%d",$siz) && $siz)
  {
    fprintf(STDOUT,"Case %d:\n",$no);
    for($i=0;$i<$siz;$i++)
      {
	for($j=0;$j<$siz;$j++)
	    fprintf(STDOUT,"%3d",zigzag($i,$j,$siz));
	fprintf(STDOUT,"\n");
      }
    $no++;
  }
return(0);
?>

Measured memory_bytes: 6596
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let s = s.trim_end().to_string();
    let mut iter = s.split_whitespace();
    let a: i32 = iter.next().unwrap().parse().unwrap();
    let b: i32 = iter.next().unwrap().parse().unwrap();
    println!("{}", a * b);
}


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

char t[][5] = {
    {},
    {'.', ',', '!', '?', ' '},
    {'a', 'b', 'c'},
    {'d', 'e', 'f'},
    {'g', 'h', 'i'},
    {'j', 'k', 'l'},
    {'m', 'n', 'o'},
    {'p', 'q', 'r', 's'},
    {'t', 'u', 'v'},
    {'w', 'x', 'y', 'z'}};

int main()
{
  int n;
  cin >> n;
  vector<string> ans;
  for (int i = 0; i < n; ++i)
  {
    string s;
    cin >> s;
    string sum = "";
    int cnt = 0;
    char c = '0';
    for (int j = 0; j < s.size(); ++j)
    {
      if (s[j] == '0')
      {
        if (c == '0')
          continue;
        if ((c - '0') == 1)
          sum += t[c - '0'][(cnt - 1) % 5];
        else if ((c - '0') == 7 || (c - '0') == 9)
          sum += t[c - '0'][(cnt - 1) % 4];
        else
          sum += t[c - '0'][(cnt - 1) % 3];
        cnt = 0;
        c = '0';
      }
      else
      {
        c = s[j];
        cnt++;
      }
    }
    ans.push_back(sum);
  }
  for (auto &e : ans)
    cout << e << endl;

  return 0;
}



Measured memory_bytes: 3120
from sys import stdin
n=int(stdin.readline())
dp=[0]*3
for i in range(n):
    before=[0,0,0]
    l=list(map(int,stdin.readline().split()))
    for i in range(3):
        before[i]=max(dp[(i+1)%3],dp[(i+2)%3])+l[i]
    dp=before
print(max(dp))


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

string ask(ll n) {
    cout << "? " << n << '\n';
    cout << flush;
    string s;
    cin >> s;
    return s;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    ll cur = 1;
    while (1) {
        if (ask(cur) == "Y") cur *= 10ll;
        else break;
        if (cur > 1e10) {
            cur = 9;
            ll ans = 1;
            while (1) {
                if (ask(cur) == "Y") break;
                ans *= 10;
                cur = cur * 10ll + 9ll;
            }
            cout << "! " << ans << '\n';
            cout << flush;
            return 0;
        }
    }
    ll l = cur, r = cur * 10;
    while (r - l > 1ll) {
        ll m = (l + r) / 2ll;
        if (ask(m) == "Y") r = m;
        else l = m;
    }
    cout << "! " << r / 10 << '\n';
    cout << flush;
}

Measured memory_bytes: 668
from copy import *
from sys import *
import math
import queue
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	n = int(input())
	a = list(map(int,input().split()))
	r = [a[0]]
	for i in range(1,n):
		r.append(r[i-1] + a[i])
	s = sum(a)
	m = []
	for i in range(n-1):
		m.append(abs(2*r[i]-s))
	print(min(m))

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Measured memory_bytes: 114120
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int inputA = Integer.parseInt(scan.next());
    int inputB = Integer.parseInt(scan.next());
    int inputC = Integer.parseInt(scan.next());
    scan.close();	
    
    int large;
    int small;
    int result;
    
    if(inputA > inputB){
      large = inputA;
      small = inputB;
    } else {
      large = inputB;
      small = inputA;
    }
    
    if(large > inputC){
      result = large * 10 + small + inputC;
    } else {
      result = inputC * 10 + small + large;
    }
    System.out.print(result);
  }
}

Measured memory_bytes: 21844
// ABC 143-A
// 2019.10.19 bal4u

#include <stdio.h>

int main()
{
	int A, B;
	
	scanf("%d%d", &A, &B);
	B <<= 1;
	if (A < B) puts("0");
	else printf("%d\n", A-B);
	return 0;
}


Measured memory_bytes: 128
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

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

    int cnt = 0;
    int remain = 0;

    for(int i = 0; i < x.size(); i++){
        if(x[i] == 'S'){
            cnt++;
        } else {
            cnt--;
        }

        if(cnt < 0){
            remain++;
            cnt = 0;
        }
    }

    cout << remain + cnt << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include<string>
using namespace std;
int main(void){
    // Your code here!
    int n,flag=1,count=0;
    string A[36]={},B[36]={},C[36]={};
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>A[i];
        B[i]=A[i];
        C[i]=A[i];
    }
    int i=0;
    while(flag){
        flag=0;
        for(int j=n-1;j>=i+1;j--){
            string x=A[j],y=A[j-1];
            if(x[1]<y[1]){
                string tmp=A[j-1];
                A[j-1]=A[j];
                A[j]=tmp;
                flag=1;
            }
        }
        i+=1;
    }
    for(int i=0;i<n;i++){
        int minj=i;
        for(int j=i;j<=n-1;j++){
            string x=B[j],y=B[minj];
            if(x[1]<y[1]){
                minj=j;
            } 
        }
        string tmp=B[i];
        B[i]=B[minj];
        B[minj]=tmp;
        
    }
    for(int i = 0; i< n; i++) {
		if (i > 0) cout << " ";
		cout << A[i];
	}cout << endl;
	cout<<"Stable"<<endl;
	
	for(int i= 0; i< n; i++){
		if (i > 0) cout << " ";
		cout << B[i];
	}cout << endl;
	for(int i=0;i<n;i++){
	    for(int j=i+1;j<n;j++){
	        for(int v=0;v<n;v++){
	                for(int w=v+1;w<n;w++){
	                    string a=B[v],b=B[w];
	                    if(a[1]==b[1] && C[i]==b && C[j]==a) count+=1;
	                }
            }
	        
	    }
	}
	if(count>0) cout<<"Not stable"<<endl;
	else cout<<"Stable"<<endl;
	return 0;
    
}


Measured memory_bytes: 3228
def resolve():
    n = int(input())
    S = list(map(int, input().split()))
    if n % 2 == 0:
        sum_a = (1 + max(S)) * (n // 2)
    else:
        sum_a = (2 + max(S)) * (n // 2)
    if sum(S) == sum_a:
        ans = pow(2, n // 2, (10 ** 9 + 7))
    else:
        ans = 0

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 13880
X = int(input())

def search(x):
    for a in range(1000):
        for b in range(1000):
            a5 = a**5
            b5 = b**5
            if (a5 - b5 == X):
                print(a, b)
                return
            elif (a5 + b5 == X): 
                print(a, -b)
                return
            elif (-a5 - b5 == X):
                print(-a, b)
                return

search(X)


Measured memory_bytes: 9188
#include <iostream>
#include <algorithm>
#include <cmath>
#define INF 0x3f3f3f3f
using namespace std;
int a[105];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int ans=INF;
	for(int p=1;p<=100;p++){
		int total=0;
		for(int i=1;i<=n;i++)
			total+=pow((a[i]-p),2);
		if(ans>total) ans=total;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <iostream>

using namespace std;
const int MaxN = 2e4;

int dis[MaxN + 5], vis[MaxN + 5], seq[10 * MaxN + 5];
int pre[2 * MaxN + 5], last[MaxN + 5], other[2 * MaxN + 5], cost[2 * MaxN + 5];
int all, h, w, a[205][205];

void build(int u, int v, int c){
	pre[++all] = last[u];
	last[u] = all;
	other[all] = v;
	cost[all] = c;
}
 
void SPFA(int s) {
	for(int i = 0; i < 10; i++) dis[i] = 1 << 30;
	dis[s] = 0;
	int head = 1, tail = 0;
	seq[++tail] = s, vis[s] = true;
	while(head <= tail){
		int now = seq[head], ed = last[now], dr;
		while(ed != -1){
			dr = other[ed];
			if(dis[now] + cost[ed] < dis[dr] ){
				dis[dr] = dis[now] + cost[ed];
				if(vis[dr] == 0)
					seq[++tail] = dr, vis[dr] = true;
			}
			ed = pre[ed];
		}
		vis[now] = false;
		head++;
	}
}
int main()
{
	int s = 0, n;
	all = -1;
	memset(last, -1, sizeof(last));
	cin >> h >> w;
	for(int i = 0; i <= 9; i++) {
		for(int j = 0; j <= 9; j++) {
			cin >> a[i][j];
			build(j, i, a[i][j]);
		}
	}
	SPFA(1);
	for(int i = 1; i <= h * w; i++) {
		cin >> n;
		if(n != -1 || n != 1) {
			s += dis[n];
		}
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<lint, int> pi;
const int MAXN = 200005;

struct disj{
	int pa[MAXN];
	void init(int n){
		iota(pa, pa + n + 1, 0);
	}
	int find(int x){
		return pa[x] = (pa[x] == x ? x : find(pa[x]));
	}
	bool uni(int p, int q){
		p = find(p);
		q = find(q);
		if(p == q) return 0;
		pa[q] = p; return 1;
	}
}disj;

struct edg{
	int s, e;
	lint x;
	bool operator<(const edg &ee)const{
		return x < ee.x;
	}
};

int n, a[MAXN], proc[MAXN];
int sz[MAXN], msz[MAXN];
vector<edg> ans;
vector<pi> gph[MAXN];
vector<int> cdfn;

void dfs(int x, int p){
	cdfn.push_back(x);
	sz[x] = 1;
	msz[x] = 0;
	for(auto &i : gph[x]){
		if(!proc[i.second] && i.second != p){
			dfs(i.second, x);
			sz[x] += sz[i.second];
			msz[x] = max(msz[x], sz[i.second]);
		}
	}
}

int get_center(int x){
	cdfn.clear();
	dfs(x, -1);
	pi ans(1e9, x);
	for(auto &i : cdfn){
		int w = max(msz[i], sz[x] - sz[i]);
		ans = min(ans, pi(w, i));
	}
	return ans.second;
}

vector<pi> dfn;
lint dis[MAXN];

void dfs2(int x, int p){
	dfn.push_back(pi(a[x] + dis[x], x));
	for(auto &i : gph[x]){
		if(proc[i.second] || i.second == p) continue;
		dis[i.second] = dis[x] + i.first;
		dfs2(i.second, x);
	}
}

int main(){
	scanf("%d",&n);
  int d; scanf("%d",&d);
	for(int i=1; i<=n; i++) scanf("%d",&a[i]);
	for(int i=1; i<n; i++){
		int s = i, e = i + 1, x = d;
		gph[s].push_back(pi(x, e));
		gph[e].push_back(pi(x, s));
	}
	queue<int> que;
	que.push(1);
	while(!que.empty()){
		int x = que.front();
		que.pop();
		x = get_center(x);
		dfn.clear();
		dis[x] = 0;
		dfs2(x, -1);
		sort(dfn.begin(), dfn.end());
		for(int i=1; i<dfn.size(); i++){
			ans.push_back({dfn[0].second, dfn[i].second, 
					dfn[0].first + dfn[i].first});
		}
		proc[x] = 1;
		for(auto &i : gph[x]){
			if(!proc[i.second]){
				que.push(i.second);
			}
		}
	}
	sort(ans.begin(), ans.end());
	disj.init(n);
	lint dap = 0;
	for(auto &i : ans){
		if(disj.uni(i.s, i.e)) dap += i.x;
	}
	cout << dap << endl;
}


Measured memory_bytes: 100832
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second   
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define setval(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ; 
#define int ll
using namespace std;

const int N = 1e5 + 5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const long double eps = 1e-9 ;

using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef pair<int, int> pii; 
typedef pair<int , pii> ipii ;
typedef pair<pii , int> piii ; 
typedef unsigned long long ull ;
typedef long double ld;

ll po(ll x,ll y,ll p = mod) {ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}

string s;
int dp[N][15];
int get_dp(int len, int rem){
  if(len == s.length())  return (rem == 5);
  int& ans = dp[len][rem];
  if(~ans) return ans ;
  if(s[len] != '?'){
    int d = s[len] - '0';
    return ans = get_dp(len +  1, (10 * rem + d) % 13); 
  }
  else{
    ans= 0;
    for(int i = 0 ; i < 10 ; ++i){
      ans = (ans + get_dp(len + 1, (10 * rem + i) % 13)) % mod ;
    }
    return ans ;
  }
}

void solve()
{
  cin >> s;
  setval(dp , -1);
  cout << get_dp( 0  , 0);
}
     
int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}


Measured memory_bytes: 21704
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0

for i in range(n):
    if a[i] >= b[i]:
        ans += b[i]
    else: #i + 1番目の街のモンスターを倒せる場合
        ans += a[i] #i番目のモンスター数を足す。
        if a[i + 1] < b[i] - a[i]: #i + 1番目の街のモンスターも倒しきれる場合
            ans += a[i + 1]
            a[i + 1] = 0
        else: #i + 1番目の街のモンスターを倒しきれない場合
            ans += b[i] - a[i]
            a[i + 1] -= b[i] - a[i]
print(ans)

Measured memory_bytes: 18476
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D; 
  cin >> A >> B >>C >> D ; 
  if(A+B > C+D){  
  cout << "Left" <<endl;
  }
  else if (A+B < C+D){
  cout << "Right" <<endl;
  }
  else if(A+B == C+D){
  cout << "Balanced" <<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int       lint;
typedef vector<int>         vi;
typedef vector<lint>        vl;
typedef pair<int, int>      pii;
typedef vector<pii>         vii;
typedef set<int>            si;
typedef map<string, int>    msi;
 
#define pb(n)           push_back(n)
#define SORT(v)         sort(v.begin(), v.end());
#define REV(v)          reverse(v.begin(), v.end());
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define M               10000000
#define MOD             10000007
#define INF             1e9+7
#define eps             1.0E-14
#define REP(i,a,b)      for(int i = int(a); i <= int(b); i++)
#define REPL(i,a,b)     for(lint i = lint(a); i <= lint(b); i++)
#define fastIO()        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
    long double a, b, c;
    cin>>a>>b>>c;

    if(sqrt(a) + sqrt(b) + eps< sqrt(c)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


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

int main()
{
    int n, L; cin>>n>>L;
    int a[n];
    for(int& e: a) cin>>e;

    for(int i=0; i+1<n; ++i) {
        if (a[i]+a[i+1]>=L) {
            cout<<"Possible\n";
            for(int j=0; j<i; ++j) cout<<j+1<<'\n';
            for(int j=n-1; j>i; --j) cout<<j<<'\n';
            return 0;
        }
    }
    cout<<"Impossible\n";
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define M1 1000000007
#define M2 998244353

#define fl(i,a,b)  for(ll i=a;i<b;i++)
#define bfl(i,a,b) for(ll i=b-1;i>=a;i--)
#define f(i,n)     for(int i=0;i<n;i++)
#define bf(i,n)    for(int i=n-1;i>=0;i--)


#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define bn "\n"

//------------------------------------------------------------------------ 
// #define V(a) vector<a>
// #define vt() vector< tuple < int ,int ,int > > ;
// #define vector< int ,int > pv;
// vector< pair <int,int> > vect;


//------------------------------------------------------------------------

ll modI(ll a,ll m);
ll gcd(ll a,ll b);
ll powM(ll x,ll y,ll m);
ll swap(ll a,ll b);

void swap(ll& a,ll& b)
{
    ll tp=a;
    a=b;
    b=tp;
}

ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}

ll powM(ll x,ll y,ll m)
{
    ll ans=1,r=1;
    x%=m;
    while(r>0&&r<=y)
    {
        if(r&y)
        {
            ans*=x;
            ans%=m;
        }
        r<<=1;
        x*=x;
        x%=m;
    }
    return ans;
}
 
ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

//---------------------------------------------------------------------------

// variable = Expression1 ? Expression2 : Expression3
// max = (n1 > n2) ? n1 : n2; 
// (n>m) ? cout<<"True"<<endl:cout<<"false"<<endl ;

// ---------------------------------------------------------------------------	

// int n;cin>>n;int a[n];for(int i=0;i<n;i++)cin>>a[i];    
// for(int i=0;i<n;i++)cout<<a[i];
// int a,b;cin>>a>>b;   

//----------------------------------------------------------------------------

// vector< tuple < int ,int ,int > > tv;
// vector< int ,int > pv;


//----------------------------------------------------------------------------


int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	int tt=1;
   // cin>>tt;
	while(tt--)
	{
	     int a,b;cin>>a>>b;  
	     cout<<a*b<<bn;
	   
	   
	   
	    
	}
	
	return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int main(){
	int N, K;
	string S;
	char ans;
	cin >> N >> S >> K;
	ans = S[K - 1];
	for (int i = 0; i < N; i++){
		if (ans != S[i]){
			S[i] = '*';
		}
	}

	cout << S << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a[100001],b[100001];
int main() {
    int n,m,i,d,c;
    c=0;
    d=0;
    cin>>n>>m;
    for (i=0;i<m;i++){
        cin>>a[i]>>b[i];
        if (a[i]>a[c]){
            c=i;
        }
        if (b[i]<b[d]){
            d=i;
        }
    }
    if (b[d]<a[c])
        cout<<0;
    else
        cout<<b[d]-a[c]+1;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main() {
    int k, a, b, c;
    cin >> a >> b >> c >> k;
    if (k <= a + b + c && k > a + b) {
        int cntc = k - (a + b);
        cout << a - cntc << endl;
    }
    else if (k > a && k <= a + b) {
        cout << a << endl;
    }
    else if (k >= 0 && k <= a) {
        cout << k << endl;
    }
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef pair<double,ll> pdl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<pdd> vdd;
typedef vector<pdi> vdi;
typedef vector<pdl> vdl;
#define fi first
#define se second
const ll INFLL=LLONG_MAX;
const int INF=INT_MAX;
const ll MAXLL=0x3f3f3f3f3f3f3f3f;
const int MAX=0x3f3f3f3f;
#define eb emplace_back
#define emp emplace
#define mp(a,b) make_pair(a,b)
template<class T> using min_heap=priority_queue<T,vector<T>,greater<T> >;
template<class T>
void sort(vector<T>& v){
	sort(v.begin(),v.end());
}
template <class T, class U>
void sort(vector<T>& v,U func){
	sort(v.begin(),v.end(),func);
}
template<class T>
void rsort(vector<T>& v){
	sort(v.rbegin(),v.rend());
}
template <class T>
int lb_index(vector<T>& v,T k){
	return lower_bound(v.begin(),v.end(),k)-v.begin();
}
template <class T>
int ub_index(vector<T>& v,T k){
	return upper_bound(v.begin(),v.end(),k)-v.begin();
}
template<class T>
bool is_sorted(vector<T>& v){
	return is_sorted(v.begin(),v.end());
}
template<class T>
bool sorted(vector<T>& v){
	return is_sorted(v);
}

void solve(){
	int n;
	cin>>n;
	vi v(n);
	for(int i=0;i<n;i++)cin>>v[i];
	int ans=0;
	for(int i=0;i<n;i+=2){
		if(v[i]&1)ans++;
	}
	cout<<ans;
}

int main(){
	ios::sync_with_stdio(0);
	int numberofsubtestcases=1;
//	cin>>numberofsubtestcases;
	while(numberofsubtestcases--){
		solve();
	}
}

Measured memory_bytes: 3608
#include<iostream>  
#include<cstring>  
#include<algorithm>  
using namespace std;  
struct node  
{  
    int x;  
    int y;  
  
}a[105],b[105];  
  
int cmp(struct node p,struct node q)  
{  
    if(p.x==q.x)  
    {  
        return p.y<q.y;  
  
    }  
    else  
        return p.x<q.x;  
}  
  
int main()  
{  
    int n;  
    cin>>n;  
    for(int i=0;i<n;i++)  
    {  
  
        cin>>a[i].x>>a[i].y;  
    }  
  
    for(int i=0;i<n;i++)  
    {  
  
        cin>>b[i].x>>b[i].y;  
  
    }  
      
    sort(b,b+n,cmp);  
  
    int c[105];  
    memset(c,0,sizeof(c));  
    int ans=0;  
    for(int i=0;i<n;i++)  
    {  
        int max=-1;int z=-1;  
        for(int j=0;j<n;j++)  
        {  
            if(!c[j]&&a[j].x<b[i].x&&a[j].y<b[i].y&&a[j].y>max)  
            {  
                max=a[j].y;  
                z=j;  
            }  
  
        }  
        if(max!=-1)  
        {  
            c[z]=1;  
            ans++;  
    }  
  
    }  
    cout<<ans<<endl;  
    return 0;  
  
}  

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,q = readInts()
    s = input()
    nya = [0] * (n+1)# 累積和
    for i in range(n):
        if i+1 < n:
            if s[i] == 'A' and s[i+1] == 'C':
                nya[i+1] = nya[i] + 1
            else:
                nya[i+1] = nya[i]
    #print(nya)
    for q_ in range(q):
        l,r = readInts()
        l -=1
        r -=1
        print(nya[r] - nya[l])


if __name__ == '__main__':
  main()


Measured memory_bytes: 6164
#include <stdio.h>



int insertionSort(int A[], int n, int g){
    int i, v, j, cnt;
    cnt = 0;
    for(i = g; i < n; i++){
        v = A[i];
        j = i - g;
        while(j >= 0 && A[j] > v){
            A[j + g] = A[j];
            j -= g;
            cnt++;
        }

        A[j + g] = v;
        
    }

    return cnt;

}


void shellsort(int A[], int n){
    int cnt = 0;
    int i;
    int m = 0;
    int h = 1;
    int g[n + 1];

    for(i = 0; ;i++){
        if(h > n || m > 100) break;
        g[i] = h;
        h = 3*h + 1;
        m++;
    }

    printf("%d\n",m);

    for(i =  m - 1; i >= 0; i--){
        printf("%d ", g[i]);
        cnt += insertionSort(A, n, g[i]);
    }

    printf("\n");


    printf("%d\n", cnt);

}

int main(){
    int A[1000000], n, i;

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

    shellsort(A, n);
    for(i = 0; i < n; i++) printf("%d\n", A[i]);
    return 0;
}


Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
const long long dh[] = {-1, 0, 0, 1}; long long dw[] = {0, -1, 1, 0};
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for(const auto& e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long gcd(long long a, long long b){return a % b ? gcd(b , a % b) : b;}
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void yn(bool j){cout << (j ? "Yes" : "No") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> long long bcount(T1 v, T2 a){return upper_index(v, a) - lower_index(v, a);} 
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}

bool valid(ll mh, ll mw, ll h, ll w){
    return 0 <= h && h < mh && 0 <= w && w < mw;
}

int main(){
    ll H, W; cin >> H >> W;
    vector<vector<char>> m(H, vector<char>(W));
    vector<vector<ll>> d(H, vector<ll>(W, -1));
    queue<pair<P, ll>> que;
    rep(i, H) rep(j, W) cin >> m[i][j];
    rep(i, H) rep(j, W) if(m[i][j] == '#') que.push(make_pair(P(i, j), 0LL));
    while(!que.empty()){
        pair<P, ll> cur = que.front(); que.pop();
        ll ni = cur.first.first;
        ll nj = cur.first.second;
        // pt(ni, nj);
        if (d[ni][nj] != -1) continue;
        d[ni][nj] = cur.second;
        chmin(d[ni][nj], cur.second);
        rep(i, 4){
            if (valid(H, W, ni + dh[i], nj + dw[i])) que.push(make_pair(P(ni + dh[i], nj + dw[i]), cur.second + 1));
        }
    }
    ll ans = 0;
    rep(i, H) rep(j, W) chmax(ans, d[i][j]);
    pt(ans);
}

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

#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()

using namespace std;

using ll = long long;

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

    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    ll A_sum = accumulate(all(A), 0ll);
    const ll A_SUM_MAX = (ll) N * N;

    while (K-- > 0 && A_sum < A_SUM_MAX) {
        vector<int> B(N + 1);
        REP(i, N) {
            B[max(i - A[i], 0)] += 1;
            B[min(i + A[i] + 1, N)] -= 1;
        }
        REP(i, N) {
            B[i + 1] += B[i];
        }
        A = B;
        A_sum = accumulate(all(A), 0ll);
    }

    REP(i, N) {
        cout << A[i] << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 5580
N = int(input())
V = tuple(map(int,list(input().split())))
C = tuple(map(int,list(input().split())))

tmp_c = 0
tmp_v = 0

for i in range(N):
    if V[i] > C[i]:
        tmp_v += V[i]
        tmp_c += C[i]

print(tmp_v-tmp_c)

Measured memory_bytes: 3064