akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define num 1000000007
//#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define avg(a,b) ((a)+(b))/2
#define pb push_back
#define pob pop_back
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.00000000001)
typedef long long ll;
ll mod(ll a, ll b)
{
	if(a%b<0)
	{
		return a%b + b;
	}
	return a%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll mymod(ll a,ll b)
{
    return ((a%b)+b)%b;
}
bool prime[200001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=200000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=200000; i += p) 
                prime[i] = false; 
        } 
    } 
    return;
}
ll powe[200005];
void power()
{
    powe[0]=1;
    REP(i,1,200005)
    {
        powe[i]=mymod(2*powe[i-1],num);
    }
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
        ll res = (x%m + m) % m;
        return res;
} 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
    return gcd; 
}
ll n; 
struct node
{
	vll adj;
    ll dist;
   // ll max_depth;
    ll cwgd;
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    cout<<fix((double)(M_PI * n * 2),12)<<endl;
	return 0;
}

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

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

	set <char> se;
	int n;
	char ch;

	cin >> n;

	for(int i=0;i<n;i++)
	{
		cin >> ch;
		se.insert(ch);
	}

	if(se.size()==3)
	{
		cout << "Three" << '\n';
	}
	else
	{
		cout << "Four" << '\n';
	}
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define x first
#define y second
#define size(a) (ll)(a).size()

typedef long long ll;
typedef long double ld;

using namespace std;
int n;
string s;


int main()
{
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");


    cin.tie(0);
    ios_base::sync_with_stdio(0);

    cin >> n;

    vector<pair<ll, ll>> Points(n);
    ll min_x = 2e9, max_x = 0, min_y = 2e9, max_y = 0;
    for (int i = 0; i < n; ++i) {
        ll a, b;
        cin >> a >> b;
        Points[i].x = a + b;
        Points[i].y = b - a;

        min_x = min(min_x, Points[i].x);
        max_x = max(max_x, Points[i].x);

        min_y = min(min_y, Points[i].y);
        max_y = max(max_y, Points[i].y);
    }

    cout << max(max_x - min_x, max_y - min_y);



}


Measured memory_bytes: 6360
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
int man(pii p1, pii p2) { return abs(p1.first - p2.first) + abs(p1.second - p2.second); }
/* main */
int main(){
    int n, m;
    cin >> n >> m;
    vector<pii> stu(n), ch(m);

    int a, b;
    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        stu[i] = pii(a, b);
    }
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        ch[i] = pii(a, b);
    }

    for (int i = 0; i < n; i++) {
        int minD = INF;
        int minI = 0;
        for (int j = 0; j < m; j++) {
            if (minD > man(stu[i], ch[j])) {
                minD = man(stu[i], ch[j]);
                minI = j+1;
            }
        }
        cout << minI << '\n';
    }
}


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

using namespace std;

using ll = long long int;

ll ara[50][50],mod=1e9+7,dp[22][(1LL<<22)+5],n;

ll Set(ll N, ll pos)
{
    return N = (N | (1LL<<pos));
}

bool Check(ll N, ll pos)
{
    return (bool)(N & (1LL<<pos));
}

ll func(ll indx, ll mask)
{
    if(mask==(1LL<<n)-1) return 1;
    if(dp[indx][mask]!=-1) return dp[indx][mask];
    ll ans=0;
    for(ll i=1; i<=n; i++)
    {
        if(ara[indx][i]==1 && !Check(mask,i-1))
        {
            ans+=func(indx+1,Set(mask,i-1));
            ans%=mod;
        }
    }

    return dp[indx][mask]=ans;
}

int main()
{
    ll i,j;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=n; j++)
        {
            cin>>ara[i][j];
        }
    }

    memset(dp, -1, sizeof dp);
    ll ans=func(1,0);
    cout<<ans<<endl;
    return 0;

}


Measured memory_bytes: 721152
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)

const ll mod = (ll)1e9+7;
const ll maxn = (ll)2e5+5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;

ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};


void solve(){ 
    
    ll n,a;
    vector < ll > v;
    cin >> n;
    f1(n) cin >> a, v.pb(a);
	sort(v.begin() , v.end());
	ll ans = 1;
	for(ll i = 0; i < v.size(); i++){
		if( (ll)(1e18)/ans  < v[i]){
			cout << "-1\n";
			return;
		}
		ans *= v[i];
		if(ans == 0){
			cout << "0";
			return;
		}
	} 
    cout << ans;
	return;
}


int main() {
   
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll T;
    T=1;
    //cin >> T;
    //scanf("%lld",&T);
    ll CT = 0;
    //work();
    while(T--){
    	//cout << "Case " << ++CT <<": " ;
    	//printf("Case %lld: ",++CT);
		solve();
	}
    
    return 0;
}


Measured memory_bytes: 4252
import java.util.Scanner;

public class Main {
	
	Scanner sc = new Scanner(System.in);
	int kane;
	int[] kingaku = new int [4];
	int n;
	
	public void syurui(){
		
		for(n = 0;n <= 3;n++){
		int syurui = sc.nextInt();
		int maisu = sc.nextInt();

		switch(syurui){
			case 1:
				kane = 6000;
				break;
			case 2:
				kane = 4000;
				break;
			case 3 :
				kane = 3000;
				break;
			case 4 :
				kane = 2000;
				break;
			}
		kingaku[n] = kane * maisu;
		}
	}
	public void hyouji(){
		for(n = 0;n <= 3;n++){
			System.out.println(kingaku[n]);
		}
	}
	public static void main(String[] args) {
		Main toi = new Main();
		toi.syurui();
		toi.hyouji();
		
	}

}

Measured memory_bytes: 17168
//Problem D
#include<bits/stdc++.h>
using namespace std;
int rd(){
    int a=0;char ch=getchar();
    while(!isdigit(ch))ch=getchar();
    while(isdigit(ch))a=(a<<1)+(a<<3)+(ch^48),ch=getchar();
    return a;
}
const int p=1000000007,N=200005;
int n,m,ans=1;
int mul(int a,int b){return (long long)a*b%p;}
int expo(int a,int b){
    int c=1;
    while(b){
        if(b&1)c=mul(a,c);
        b>>=1,a=mul(a,a);
    }
    return c;
}
void C(int a,int b){
    for(int i=1;i<=b;i++)ans=mul(ans,a+i),ans=mul(ans,expo(i,p-2));
}
int main(){
    scanf("%d%d",&n,&m);
    int s=sqrt(m);
    for(int i=2;i<=s;i++)if(m%i==0){
        int c=0;
        while(m%i==0)++c,m/=i;
        C(n-1,c);
    }
    if(m!=1)C(n-1,1);
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
import java.io.*;

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			String line = br.readLine();
			String[] str = line.split(" ");
			int h = Integer.parseInt(str[0]);
			int w = Integer.parseInt(str[1]);
			if ( h == 0 && w == 0 ){ //??\????????¨??????0
				break;
			}

			for (int i = 0; i < h ; i++ ) {
				for (int k = 0; k < w ; k++ ) {
					if ((i%2) == (k%2)) {
						System.out.print("#");
					}else{
						System.out.print(".");
				 	}
				 }
					System.out.print("\n");
			}
			System.out.print("\n");
		}
	}
}

Measured memory_bytes: 36488
def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

N = int_raw()
memo = [{} for x in range(N+1)]

dna = ["A","C","G","T"]

def chk(last4):
    for i in range(len(last4)):
        l = list(last4)
        if i > 0:
            l[i],l[i-1] = l[i-1],l[i]
        if "AGC" in "".join(l):
            return False
    return True

def rec(idx, last3):
    if idx == N:
        return 1
    elif last3 in memo[idx]:
        return memo[idx][last3]
    else:
        ret =0
        for d in dna:
            if chk(last3 + d):
                ret+= rec(idx+1,last3[1:]+d)
                ret = ret % (10**9+7)
        memo[idx][last3] = ret
        return ret


def ans():
    return rec(0,"TTT")

print(ans())


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

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

        int N = sc.nextInt();
        int[] s = new int[N];
        for (int i = 0; i < s.length; ++i) {
            s[i] = sc.nextInt();
        }

        System.out.println(solve(s));

        sc.close();
    }

    static int solve(int[] s) {
        int sum = Arrays.stream(s).sum();
        if (sum % 10 != 0) {
            return sum;
        }

        return Arrays.stream(s).allMatch(si -> si % 10 == 0) ? 0
                : (sum - Arrays.stream(s).filter(si -> si % 10 != 0).min().getAsInt());
    }
}

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

int main(){
    ll n,d,a;
    cin >> n >> d >> a;
    vector<ll> bit(n+1,0);
    vector<pair<ll,ll>> monsters;
    for(int i = 0;i<n;++i){
        int x,h;
        cin >> x >> h;
        h = (h+a-1)/a;//reduce the health of monster by a 'h' times
        monsters.emplace_back(x,h);
    }
    
    auto update = [&](int idx,int val){
        ++idx;
        while(idx <= n){
            bit[idx] += val;
            idx += (idx & (-idx));
        }
    };
    
    auto updateRange = [&] (int l,int r,ll val){
        update(l,val);
        update(r+1,-val);
    };
    
    auto read = [&](int idx){
        ++idx;
        ll sum = 0;
        while(idx > 0){
            sum += bit[idx];
            idx -= (idx &(-idx));
        }
        return sum;
    };
    
    auto sum = [&](int l,int r){
        return read(r) - read(l-1);
    };
    
    ll ans = 0;
    sort(monsters.begin(),monsters.end());
    for(int i = 0;i<n;++i)
    {
        update(i,monsters[i].second);
        update(i+1,-monsters[i].second);
    }
    for(int i = 0;i<n;++i){
       // update(i,monsters[i].second);
        ll health = read(i);
       // cout << health <<"\n";
        if(health <= 0)
            continue;
        int l = i;
        int r = n-1;
        int ok = -1;
        //find the ending point of covered in the range x[i] to x[i]+2*d-1
        while(l <= r){
            int mid = l+(r-l)/2;
            if(monsters[mid].first <= monsters[i].first + 2*d){
                ok = mid;
                l = mid+1;
            }
            else{
                r = mid-1;
            }
        }
        assert(ok!=-1);
        updateRange(i,ok,-health);
        ans += health;
    }
    cout << ans <<"\n";
    return 0;
}

Measured memory_bytes: 7920
def abc067_c():
    n = int(input())
    a = list(map(int, input().split()))
    x = a[0]
    y = sum(a[1:])
    del a[0]
    del a[-1]
    diff = abs(x - y)
    for v in a:
        x += v
        y -= v
        if abs(x - y) < diff:
            diff = abs(x - y)
    print(diff)


abc067_c()

Measured memory_bytes: 24832
#include <iostream>
#include <math.h>
using namespace std;
int main(){
	int X, N, p;
	int cnt[201] = {0};
	cin >> X >> N;
	for(int i=0; i<N; i++){
		cin >> p;
		cnt[p] ++;
	}
	for(int d=0; d<=X; d++)
		for(int s=-1; s<=1; s+=2)
			if(cnt[X+d*s] == 0){
				cout << X+d*s << endl;
				return 0;
			}
}






Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	std::string s; cin >> s;
	
	std::string ans = "";
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == 'B') {
			if(ans.empty()) continue;
			ans.pop_back();
		} else {
			ans.push_back(s[i]);
		}
	}
	
	printf("%s\n", ans.c_str());
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	int x, y;
	while (cin >> x >> y, x){
		vector<int> xv;
		vector<int> yv;
		for (int i = 1; i <= sqrt(x); i++){
			if (x%i == 0)xv.push_back(i);
		}
		for (int i = 1; i <= sqrt(y); i++){
			if (y%i == 0)yv.push_back(i);
		}
		vector<int> calc(4);
		int ans = 1000000007;
		REP(i, xv.size()){
			REP(j, yv.size()){
				calc[0] = xv[i];
				calc[1] = x / xv[i];
				calc[2] = yv[j];
				calc[3] = y / yv[j];
				SORT(calc);
				ans = min(ans, (calc[0] - calc[1])*(calc[0] - calc[1]) + (calc[2] - calc[1])*(calc[2] - calc[1]) + (calc[3] - calc[2])*(calc[3] - calc[2]));
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1216
#include <stdio.h>


int main()
{
    int min = 100;
    int max = 1;
    int N;
    int x[100];
    int i;
    int j;
    int sumN = 0;
    int minSumN = 10000000;

    scanf("%d\n", &N);

    for (i = 0; i < N; i++) {
        scanf("%d", &x[i]);
        if (x[i] < min) {
            min = x[i];
        }

        if (x[i] > max) {
            max = x[i];
        }
    }

    for (i = min; i <= max; i++) {
        sumN = 0;
        for (j = 0; j < N; j++) {
            sumN += (x[j] - i) * (x[j] - i);
        }
        if (sumN < minSumN) {
            minSumN = sumN;
        }
    }

    printf("%d", minSumN);
    return 0;
}

Measured memory_bytes: 128
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

int main()
{
    IOS();
    ll x,a,b;
    cin>>x>>a>>b;
    x -= a;
    x %= b;
    cout<<x<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int calcDigSum( int num )
{
    int res = 0;
    while(num > 0)
    {
        res += num%10;
        num = num / 10;
    }
    return res;
}

int main() {
	int n, a, b, result; cin >> n >> a >> b;
    result = 0;
    for (int i = n; i >= 0; i--)
    {
        int sum = calcDigSum(i);
        if (sum >= a && sum <= b)
        {
            result += i;
        }
    }
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
	ll n,m;
	cin >> n >> m;
	if (n*2<=m) {
		cout << n+(m-n*2)/4;
	} else if (n*2>m) {
		cout << m/2;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int n, m;
int ok[105] = {0};
vector<int> l, a;
vector<int> ans;

void solve();

int main() {
  cin >> n >> m;
  l.resize(m);
  a.resize(m);
  ans.assign(n + 1, 0);
  for(int i = 0; i < m; ++i) cin >> a[i] >> l[i];
  solve();
  for(int i = n; i > 0; --i)
    if(ans[i] > 0) cout << i << " " << ans[i] << endl;
  return 0;
}

void solve() {
  int num = -1;
  for(int i = 0; i < m; ++i)
    for(int j = 0; j < l[i]; ++j) ++ok[(a[i] + j) % n];
  for(int i = 0; i < n; ++i)
    if(ok[i] == 0) {
      num = i;
      break;
    }
  if(num == -1) {
    ans[n] = 1;
    return;
  }
  for(int i = num + 1; i <= num + n; ++i) {
    int now = i, cnt = 0;
    while(ok[now % n] > 0 && now <= (num + n)) {
      ++cnt;
      ++now;
    }
    ++ans[cnt];
    i = now;
  }
}


Measured memory_bytes: 3112
#include"bits/stdc++.h"
using namespace std;

void Main() {
  long long n, m[5];
  cin >> n >> m[0] >> m[1] >> m[2] >> m[3] >> m[4];

  sort(m, m + 5);
  if (n % m[0]) cout << n / m[0] + 5 << endl;
  else cout << n / m[0] + 4 << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


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

int main(){
    char a[100],b[100],c[100];
    scanf("%s",a);
    scanf("%s",b);
    scanf("%s",c);
    int sa=strlen(a);
    int sb=strlen(b);
    int sc=strlen(c);

    char s[3][100];
    for(int t=0;t<100;t++){
        s[0][t]=a[t];
        s[1][t]=b[t];
        s[2][t]=c[t];   
    }

    int x=0;
    int y=0;

    int i=0;
    int j=0;
    int k=0;
    for(;;){
        if(s[x][y]=='a'){
            if(x==0){
                i++;
            }else if(x==1){
                j++;
            }else if(x==2){
                k++;
            }
            x=0;
            y=i;
        }else if(s[x][y]=='b'){
            if(x==0){
                i++;
            }else if(x==1){
                j++;
            }else if(x==2){
                k++;
            }
            x=1;
            y=j;
        }else if(s[x][y]=='c'){
            if(x==0){
                i++;
            }else if(x==1){
                j++;
            }else if(x==2){
                k++;
            }
            x=2;
            y=k;
        }else{
            if(x==0){
                i++;
            }else if(x==1){
                j++;
            }else if(x==2){
                k++;
            }
            break;
        }
    }

    if(i>sa){
        printf("A\n");
    }else if(j>sb){
        printf("B\n");
    }else if(k>sc){
        printf("C\n");
    }
    return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define show(x) cout<<#x<<"="<<x<<"\n"
using namespace std;

int n,m;
string s;
int a[100001],b[100001];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
#ifdef LOCAL_DEFINE
    FILE *stream1;
    //FILE *stream2;
    stream1=freopen("in","r",stdin);
    //stream2=freopen("out","w",stdout);
    if(stream1==NULL)return 0;
    //if(stream2==NULL)return 0;
#endif
    cin>>n>>m;
    int maxa=0;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        maxa=max(maxa,a[i]);
    }
    ll ans=0;
    sort(b,b+n);
    reverse(b,b+n);
    for(int i=0;i<n;i++){
        if(m<=0)break;
        if(b[i]>=maxa){
            m-=b[i];
            ans++;
        }
    }
    if(m>0)ans+=m/maxa;
    if(m%maxa!=0 && m>0)ans++;
    cout<<ans<<endl;
#ifdef LOCAL_DEFINE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    fclose(stream1);
    //fclose(stream2);
#endif
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <deque>

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 1234;
int a[MAXN];
LL sum[MAXN];

void solve(vector<int> &cand, int N) {
     vector<int> ans;
     for (int i = N; i > cand.back(); i--) ans.push_back(i);
     for (int i = 1; i < cand[0]; i++) ans.push_back(1);
     int pre = cand[0];
     for (int i = 1; i < (int)cand.size(); i++) {
         for (int j = 1; j < (cand[i] - pre) / 2; j++) ans.push_back(3);
         ans.push_back(2);
         pre = cand[i];
     }
     printf("%d\n", (int)ans.size());
     for (int i : ans) printf("%d\n", i);
}

int main() {
    int N;
    scanf("%d", &N);
    for (int i = 1; i <= N; i++) {
        scanf("%d", &a[i]);
        if (a[i] > 0) sum[i % 2] += a[i];
    }
    vector<int> cand;
    if (!sum[0] && !sum[1]) {
       int idx = 1;
       for (int i = 2; i <= N; i++) {
           if (a[idx] < a[i]) idx = i;
       }
       printf("%d\n", a[idx]);
       cand.push_back(idx);
    } else {
       printf("%lld\n", max(sum[0], sum[1]));
       for (int i = (sum[0] > sum[1]) ? 2 : 1; i <= N; i+= 2) {
           if (a[i] > 0) cand.push_back(i);
       }
    }
    solve(cand, N);
    return 0;
}


Measured memory_bytes: 256
def generate_ac(name)
  ac = name[0]

  name.split("").each_cons(2){|n| ac += n[1] if n[0].match(/[aiueo]/)}
  
  ac
end

def calc_minimam_k(ac_list)
  return -1 unless ac_list.uniq.size == ac_list.size
  
  max_ac_length = ac_list.max_by{|ac| ac.length }.length
  
  max_ac_length.times do |n|
    return n + 1 if ac_list.uniq.size == ac_list.map{ |ac| ac[0..n] }.uniq.size
  end
end

loop do
  n = gets.to_i
  break if n == 0
  ac_list = []
  
  n.times do
    ac_list << generate_ac(gets.chomp)
  end
  
  puts calc_minimam_k(ac_list)
end

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

ll N, K;
ll A[200000];

// ペア (i, i+1), (i, i+2), ..., (i, N-1) の中の key 以下の数の個数
ll binarySearch(int i, ll key){
	if(A[i] < 0){
		int ok = N;
		int ng = i;
		while(ok - ng > 1){
			int m = (ok+ng) / 2;
			if(A[i]*A[m] <= key) ok = m;
			else ng = m;
		}
		return N-ok;
	}
	else{
		int ok = i;
		int ng = N;
		while(ng - ok > 1){
			int m = (ng+ok) / 2;
			if(A[i]*A[m] <= key) ok = m;
			else ng = m;
		}
		return ok-i;
	}
}

signed main(){
	scanf("%lld%lld", &N, &K);
	rep(i, N){
		scanf("%lld", A+i);
	}
	sort(A, A+N);
	
	// その数以下のペアが K 個以上存在するか？
	// 答えは ok
	ll ng = -1000000000LL*1000000000LL-1LL;
	ll ok = 1000000000LL*1000000000LL+1LL;
	while(ok-ng > 1){
		ll m = (ng+ok) / 2;
		ll c = 0;
		rep(i, N) c += binarySearch(i, m);
		if(c >= K) ok = m;
		else ng = m;
	}
	printf("%lld\n", ok);
}


Measured memory_bytes: 1792
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

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

  auto r = 0;
  for (auto i = 105; i <= n; i += 2) {
    auto f = 0;
    foreach (j; 1..i+1)
      if (i%j == 0) ++f;
    if (f == 8) ++r;
  }

  writeln(r);
}


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

int main(){
	int k;
	cin>>k;
	string s;
	cin>>s;
	if(s.size()>k){
		cout<<s.substr(0,k)<<"..."<<endl;
	}else{
		cout<<s<<endl;
	}
	return 0;
}


Measured memory_bytes: 3632
n = int(input())
a = input()
b = input()
c = input()
ans = 0
for i in range(n):
    if a[i] == b[i] and b[i] == c[i]:
        ans += 2
    elif a[i] == b[i]:
        ans += 1
    elif b[i] == c[i]:
        ans += 1
    elif a[i] == c[i]:
        ans += 1
print(n*2-ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n;  cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++){
        cin >> p[i];
    }
    sort(p.begin(), p.end());

    int ans = 0;
    for (int i = 0; i < n - 1; i++){
        ans += p[i];
    }
    cout << ans + p[n - 1] / 2 << endl;
}

Measured memory_bytes: 256
N=int(input())
like=list(map(int,input().split()))
count=0

for i in range(N):
    like_1=like[i]
    #print("like_1")
    #print(like_1)
    if like[like_1-1]==i+1:
        #print(like[like_1-1])
        #print(i+1)
        count+=1
        #print("///")
        
print(count//2)

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

using namespace std;

typedef __int128 bigint;

int N;
bigint A[100001];
bool pr[100001];
vector<long long> pcube;
map<long long, long long> bigpr;

bigint reduce(bigint x, bool more, long long orig)
{
    for(auto& it: pcube)
    {
        if(x<it)
            break;
        while(x%it==0)
            x/=it;
    }
    if(more)
    {
        for(int i=100; i>=1; i--) if(orig%i==0)
        {
            if(bigpr.count(orig/i))
                x/=bigpr[orig/i];
            break;
        }
    }
    return x;
}

int main()
{
    for(int i=2; i<=100000; i++)
        pr[i]=true;
    for(int i=2; i<=100000; i++) if(pr[i])
    {
        if(1LL*i*i*i<=10000000000LL)
            pcube.push_back(1LL*i*i*i);
        else
            bigpr[1LL*i*i]=1LL*i*i*i;
        for(int j=i*2; j<=100000; j+=i)
            pr[j]=false;
    }
    scanf("%d", &N);
    for(int i=0; i<N; i++)
    {
        long long x;
        cin>>x;
        A[i]=x;
    }
    vector<pair<bigint, bigint>> e;
    map<bigint, int> cnt;
    int one=0;
    for(int i=0; i<N; i++)
    {
        A[i]=reduce(A[i], false, 0);
        if(A[i]==1)
            one=1;
        else
        {
            cnt[A[i]]++;
            bigint x=A[i];
            bigint y=reduce(A[i]*A[i], true, A[i]);
            if(x>y)
                swap(x, y);
            e.push_back({x, y});
        }
    }
    sort(e.begin(), e.end());
    e.erase(unique(e.begin(), e.end()), e.end());
    int ans=one;
    for(auto& it: e)
        ans+=max(cnt[it.first], cnt[it.second]);
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 21228
#include <iostream>
using namespace std;
int main(void){
	string s;
	cin>>s;
	int k=0;
	for(int i=0;i<s.size();++i){
		if(s[i]=='J'){
			int JOI[3]={1,0,0};
			while(s[i]=='J'){++JOI[0];++i;}
			while(s[i]=='O'){++JOI[1];++i;}
			while(s[i]=='I'){++JOI[2];++i;}
			if(JOI[0]>=JOI[1] && JOI[2]>=JOI[1]){
				if(k<JOI[1]) k=JOI[1];
			}
		}
	}
	cout<<k<<endl;
	return 0;
}

Measured memory_bytes: 2048
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const int INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

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

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



int main() {
    int N; cin >> N;
    vector<vector<P>>G(N);
    rep(i, N - 1) {
        int a, b, c;
        cin >> a >> b >> c; --a, --b;
        G[a].pb(mp(b, c));
        G[b].pb(mp(a, c));
    }
    int Q, K; cin >> Q >> K;
    --K;
    vector<ll>dist(N, INF); //K -> i への最短経路
    dist[K] = 0;
    queue<int>que;
    que.push(K);
    while(!que.empty()) {
        int q = que.front(); que.pop();
        for(auto next : G[q]) {
            if(dist[next.first] == INF) {
                que.push(next.first);
                dist[next.first] = dist[q] + next.second;
            }
        }
    }
    int x[Q], y[Q];
    rep(i, Q) {
        cin >> x[i] >> y[i];
        --x[i], --y[i];
    }

    rep(i, Q) {
        cout << dist[x[i]] + dist[y[i]] << endl;
    }
}


Measured memory_bytes: 9588
#include<bits/stdc++.h>
using namespace std;
int n;
string s;

bool visited[501][501];
bool dp[501][501];
bool solve(int l,int r){
  if(r<l)return true;
  if(visited[l][r])return dp[l][r];
  visited[l][r]=true;
  if(s[l]!='m'||s[r]!='w')return false;
  for(int i=l+1;i<r;i++){
    if(s[i]!='e')continue;
    if(solve(l+1,i-1)&&solve(i+1,r-1))return dp[l][r]=true;
  }
  return false;
}

int main(){
  cin>>s;
  n=s.size();
  if(solve(0,n-1))cout<<"Cat"<<endl;
  else cout<<"Rabbit"<<endl;
  return 0;
}

Measured memory_bytes: 1652
#define _CRT_SECURE_NO_WvNINGS
#include <bits/stdc++.h>
using namespace std;
#define ll long long
string ss, s;
int dp[3003][3003];
pair<int, int> vis[3003][3003];

int solve(int i, int j) {
    if (i==s.size() || j == ss.size())return 0;
    if (~dp[i][j])return dp[i][j];

    if (s[i] == ss[j]) {
        vis[i][j] = { i + 1, j + 1 };
        return dp[i][j] = 1 + solve(i + 1, j + 1);
    }
    
    int a = solve(i + 1, j);
    int b = solve(i, j + 1);
    int ans = max(a, b);
    if (a == ans) {
        vis[i][j] = { i + 1, j };
    }
    else {
        vis[i][j] = { i, j + 1 };
    }
    return dp[i][j] = ans;
}
int main() {
    cin.sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> s >> ss;
    memset(dp, -1, sizeof(dp));
    solve(0, 0);
    pair<int, int> cur = { 0, 0 };
    while (cur.first < s.size() && cur.second < ss.size()) {
        if (s[cur.first]==ss[cur.second]) {
            cout << s[cur.first];
        }
        cur = vis[cur.first][cur.second];
    }
    return 0;
}



Measured memory_bytes: 106368
import java.math.BigInteger;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int temp = Integer.valueOf(scan.nextLine());
		for (int i = 0; i < temp; i++) {
			BigInteger a1 = new BigInteger(scan.nextLine());
			BigInteger a2 = new BigInteger(scan.nextLine());
			a1 = a1.add(a2);
			if(a1.toString().length()>80){
				System.out.println("overflow");
			}
			else{
			System.out.println(a1);
			}
		}
	}
}

Measured memory_bytes: 18628
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=510;
int n,L;
int a[maxn],s;
int ans=(1e9),tmp;
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	read(L);
	for (int i=1;i<=n;i++)
		a[i]=L+i-1,s+=a[i];
	for (int i=1;i<=n;i++) {
		if (abs(a[i])<ans)
			ans=abs(a[i]),tmp=s-a[i];
	}
	printf("%d\n",tmp);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int 
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second


int main(){
    fast;
    string a,b; cin >> a >> b;
    int n1 = a.size();
    int n2 = b.size();
    a= "*" + a;
    b = "*" + b;
    int dp[n1+1][n2+1];
    memset(dp,0,sizeof(dp));
    string ans = "";
    for(int i=1 ; i<n1+1 ; i++){
        for(int j=1 ; j<n2+1 ; j++){
            if(a[i]==b[j]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        }
    }
    int i= n1,j = n2;
    while(i>=1 && j>=1){
            if(dp[i-1][j] == dp[i][j])
                    i--;
            else if(dp[i][j-1] == dp[i][j])
                    j--;
            
            else if(dp[i-1][j-1] + 1 == dp[i][j]){
                ans+= a[i];
                i--,j--;
            }

    }
    reverse(all(ans));
    cout << ans << endl;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    cout << n * n * n << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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


int main(){
    
    ll n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;

    rep(i,0,n){
	ll l = a + i*c - (n-1-i)*d;
	ll u = a + i*d - (n-1-i)*c;
	if(l <= b && b <= u){
	    YES;
	    ret 0;
	}
    }
    NO;
    return  0;
}


Measured memory_bytes: 256
#include <iostream>

int main(void)
{
    int input;
    while(std::cin >> input){
        bool* table = new bool[input + 1]();
        for(int i=0; i <= input; ++i){
            if(i < 2){
                table[i] = true;
                continue;
            }
            if(table[i] == false){
                for(int j=2;i * j <= input;++j){
                    table[i * j] = true;
                }
            }
        }
        int count = 0;
        for(int i=0;i <= input;++i){
            if(table[i] == false){
                ++count;
            }
        }
        std::cout << count << std::endl;
        delete[] table;
    }
    return 0;
}

Measured memory_bytes: 2244
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;

using ipair = pair<int, int>;

ll INF = 1e16+7;

bool operator>(const ipair a,const ipair b){return a.first > b.first;}

void print_vector(vector<int> v){
  rep(i, sz(v)){
    cout << v[i] << " ";
  }
  cout << endl;
  return;
}

int main(){
  int A, B, C, K;
  cin >> A >> B >> C >> K;

  ll ans = 0;
  ans += min(A, K);
  K -= A;
  if(K <= 0){
    cout << ans << endl;
    return 0;
  }
  K -= B;
  if(K <= 0){
    cout << ans << endl;
    return 0;
  }

  ans -= min(K, C);
  cout << ans << endl;


 
  return 0;
}


Measured memory_bytes: 3640
//verma_ankit484

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

typedef long long ll;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
const ll mod = (ll) 1e9+7;

using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

vector<ll> vc;
ll x;

ll dp[7][1000005];

ll rec(ll idx, ll s) {
  if (idx >= 6) return 0;
  if (s > x) return 0;
  ll &ans = dp[idx][s];
  if (ans != -1) return ans;
  if (s == x) {
    return 1;
  }
  ans = 0;
  ans = rec(idx, s+vc[idx]);
  ans |= rec(idx+1, s);
  return ans;
}

int main() {
  IOS
  #ifdef AV
  freopen("int.txt", "r", stdin);
  #endif
  memset(dp, -1, sizeof(dp));
  vc.resize(6);
  vc[0] = 100;
  for (ll i = 1; i < 6; i++) {
    vc[i] = vc[i-1]+1;
  }
  cin >> x;
  ll k = rec(0, 0);
  cout << k << endl;
  return 0;
}


Measured memory_bytes: 55040
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const int INF = 1001001001;
const int MOD = 1000000007;


int main(){
    int h, w;
    cin >> h >> w;

    vector<string> a(h);
    rep(i, h) cin >> a[i];

    vector<vector<int>> dp(h + 1, vector<int>(w + 1, 0));
    dp[0][0] = 1;

    rep(i, h)rep(j, w) {
        if (i + 1 < h && a[i + 1][j] == '.') {
            dp[i + 1][j] += dp[i][j];
            dp[i + 1][j] %= MOD;
        }
        if (j + 1 < w && a[i][j + 1] == '.') {
            dp[i][j + 1] += dp[i][j];
            dp[i][j + 1] %= MOD;
        }
    }

    cout << dp[h - 1][w - 1] << endl;
}

Measured memory_bytes: 5248
object Main {
  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readInt()
    val dices = (0 until n).map(_ => Dice(io.StdIn.readLine().split(" ").map(_.toInt)))

    val answer =
      if (dices
        .zipWithIndex
        .forall { case (dice, i) => (i + 1 until n).forall(j => Dice.notEquals(dice, dices(j))) }) {
        "Yes"
      } else {
        "No"
      }

    println(answer)
  }

  case class Dice(upSide: Int, southSide: Int, eastSide: Int, westSide: Int, northSide: Int, downSide: Int) {
    import Direction._
    def roll(direction: Direction): Dice = direction match {
      case North =>
        Dice(southSide, downSide, eastSide, westSide, upSide, northSide)
      case South =>
        Dice(northSide, upSide, eastSide, westSide, downSide, southSide)
      case West =>
        Dice(eastSide, southSide, downSide, upSide, northSide, westSide)
      case East =>
        Dice(westSide, southSide, upSide, downSide, northSide, eastSide)
    }
  }
  object Dice {
    def apply(sides: Array[Int]): Dice = Dice(sides(0), sides(1), sides(2), sides(3), sides(4), sides(5))

    def equals(d1: Dice, d2: Dice): Boolean = {
      import Direction._

      val sides = d1.northSide :: d1.westSide :: d1.southSide :: d1.eastSide ::
                  d1.northSide :: d1.westSide :: d1.southSide :: Nil
      @annotation.tailrec
      def sameDice(next: Option[Direction], d: Dice): Boolean = {
        val same =
          if (d1.upSide == d.upSide && d1.downSide == d.downSide) {
            sides.containsSlice(d.northSide :: d.westSide :: d.southSide :: d.eastSide :: Nil)
          } else if (d1.upSide == d.downSide && d1.downSide == d.upSide) {
            sides.containsSlice(d.northSide :: d.eastSide :: d.southSide :: d.westSide :: Nil)
          } else {
            false
          }
        if (same) {
          true
        } else {
          next match {
            case Some(North) => sameDice(Some(West), d.roll(North))
            case Some(West) => sameDice(None, d.roll(West))
            case _ => false
          }
        }
      }

      sameDice(Some(North), d2)
    }

    def notEquals(d1: Dice, d2: Dice): Boolean = !equals(d1, d2)
  }

  sealed trait Direction
  object Direction {
    case object North extends Direction
    case object South extends Direction
    case object West extends Direction
    case object East extends Direction

    def apply(c: Char): Direction = c match {
      case 'N' => North
      case 'S' => South
      case 'E' => East
      case 'W' => West
      case _ => throw new Exception
    }
  }
}

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

int main(){

	int card[5], cnt, max_cnt, min_cnt, cnt_one;
	char cnm;

	while(cin >> card[0]){
		cnt = 1;
		for(int i=1; i<9; i++){
			if(i % 2 == 0){
				cin >> card[cnt];
				cnt++;
			}
			else cin >> cnm;
		}
		
		sort(card, card + 5);
		max_cnt = 1;
		min_cnt = 5;
		cnt_one = 0;
		cnt = 1;
		for(int i=0; i<4; i++){
			if(card[i] == card[i+1]) cnt++;
			else {
				min_cnt = min(min_cnt, cnt);
				if(cnt == 1) cnt_one++;
				cnt = 1;
			}
			max_cnt = max(max_cnt, cnt);
		}
		if(card[3] != card[4]) cnt_one++;

		if(max_cnt == 4) cout << "four card" << endl;
		else if(max_cnt == 3){
			if(min_cnt == 1) cout << "three card" << endl;
			else cout << "full house" << endl;
		}
		else if(max_cnt == 2){
			if(cnt_one == 3) cout << "one pair" << endl;
			else cout << "two pair" << endl;
		}
		else if(card[0] + 4 == card[4] || (card[0] == 1 && card[1] == 10)){
			cout << "straight" << endl;
		}
		else cout << "null" << endl;
	}

	return 0;

}

Measured memory_bytes: 1176
n = int(input())
A = list(map(int, input().split()))
A = [a for a in A if a % 2 == 0]

ans = "APPROVED"
for a in A:
    if (a % 3 != 0) and (a % 5 != 0):
        ans = "DENIED"
        break
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
    int H, W, X, Y, A, B;
    scanf("%d %d %d %d", &H, &W, &X, &Y);
    A = H * W;
    B = X + Y;
    if(A % 2 == 1 && B % 2 == 1){
        printf("No\n");
    }
    else printf("Yes\n");
    return 0;
    
    
}



Measured memory_bytes: 2044
#include<stdio.h>
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_A
int find(int a,int b,int a1[]){
	return a1[a]==a1[b]?1:0;
}
void union1(int a,int b, int a1[], int n)
{
	int temp = a1[a];//a1[a] may change
	for(int i = 0; i<n; i++){
		if(a1[i]==temp) a1[i] = a1[b];
	}
}


int main(){
	int n,q;
	scanf("%d %d",&n,&q);
	int a1[n+1];//start with 1;
	for(int i = 0; i<n; i++) a1[i] = i;
	for(int i = 0; i<q; i++){
		int a, b;
		int com = 0;
		scanf("%d %d %d",&com,&a,&b);
		if(com==0){
			union1(a,b,a1,n);
			/*for(int i = 0; i<n; i++){
				printf("%d ",a1[i]);
			}printf("\n");*/
		} else {
			printf("%d\n",find(a,b, a1));
		}
	}
	
	
	return 0;
}


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

vector<vector<int>> graph;
vector<int> values;

void dfs(int x, int p=-1) {
    for (int v : graph[x]) {
        if (v == p) continue;
        values[v] += values[x];
        dfs(v,x);
    }
}

int main() {
    int n, q;
    cin >> n >> q;
    graph.resize(n);
    values.resize(n);
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    rep(i,q) {
        int p, x;
        cin >> p >> x;
        --p;
        values[p] += x;
    }
    dfs(0);
    for (int i = 0; i < n; i++) {
        if (i != n-1) printf("%d ", values[i]);
        else printf("%d\n",values[i]);
    }
    return 0;
}

Measured memory_bytes: 23424