akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

const int MAXN = 500000;

int bit[MAXN];

int read(int idx) {
	int ret = 0;
	while (idx) {
		ret += bit[idx];
		idx -= idx & (-idx);
	}
	return ret;
}

void update(int idx, int val) {
	while (idx < MAXN) {
		bit[idx] += val;
		idx += idx & (-idx);
	}
}

vector<pair<pair<int, int>, int> > pc0, prR, pcC, pr0;

int R, C;

void addPair(int r, int c, int i) {
	pair<pair<int, int>, int> el = make_pair(make_pair(r, c), i);
	if (c == 0)
		pc0.pb(el);
	else if (r == R)
		prR.pb(el);
	else if (c == C) {
		el.first.first *= -1;
		pcC.pb(el);
	}
	else if (r == 0) {
		el.first.second *= -1;
		pr0.pb(el);
	}
}

int main() {
	cin >> R >> C;
	int N;
	cin >> N;
	int r1, c1, r2, c2;
	pr0.clear();
	prR.clear();
	pc0.clear();
	pcC.clear();
	FOR (i, N) {
		cin >> r1 >> c1 >> r2 >> c2;
		if ((r1 != 0 && r1 != R) && (c1 != 0 && c1 != C))
			continue;
		if ((r2 != 0 && r2 != R) && (c2 != 0 && c2 != C))
			continue;
		addPair(r1, c1, i);
		addPair(r2, c2, i);
	}
	sort(all(pc0));
	sort(all(prR));
	sort(all(pcC));
	sort(all(pr0));
	int rank[2 * N];
	int lastSeen[2 * N];
	SET(rank, 255);
	vector<int> els;
	els.clear();
	FOR (i, pc0.sz)
		els.pb(pc0[i].second);
	FOR (i, prR.sz)
		els.pb(prR[i].second);
	FOR (i, pcC.sz)
		els.pb(pcC[i].second);
	FOR (i, pr0.sz)
		els.pb(pr0[i].second);
	int nextRank = 1;
	SET(bit, 0);
	FOR (i, els.sz) {
		if (rank[els[i]] == -1) {
			rank[els[i]] = nextRank;
			lastSeen[els[i]] = read(rank[els[i]]);
			//update(rank[els[i]], 1);
			nextRank++;
		}
		else {
			if (read(rank[els[i]]) > lastSeen[els[i]]) {
				cout << "NO" << endl;
				return 0;
			}
			update(rank[els[i]], 1);
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 7784
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define db cout << " HERE " << endl;
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 2000001;
int vis[1000002];
int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
int main() {
	int n;
	cin >> n ;
	ll ar[n];
	F0R(i,n) {
		cin >> ar[i] ;
		vis[ar[i]]=true;
	}
	int flag = 0 ;
	ll gc = ar[0];
	F0R(i,n) {
		for(int j = 2 ; j*j <= ar[i] ; j++) {
			if(ar[i]%j==0) {
				int a = ar[i]/j;
				if(vis[a]==true) {
					flag = 1;
					break;
				}
				if(vis[j]==true){ flag = 1;
				break;
			}
				vis[a]=true;
				vis[j] = true;
			}
		}
	}
	if(flag == 0){ cout << "pairwise coprime" << endl; return 0;	}
	F0R(i,n) {
		gc = gcd(ar[i],gc);
	}
	if(gc ==1) {
		cout << "setwise coprime" << endl;
	}
	else
	cout << "not coprime" << endl;
	
}
// template by benq


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

using namespace std;
typedef long long ll;

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

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

    vector<int> dx = {0, 1, 1, 1, 0, -1, -1, -1};
    vector<int> dy = {-1, -1, 0, 1, 1, 1, 0, -1};

    vector<string> mass(h), ck(h);
    rep(i, h) cin >> mass[i];
    ck = mass;

    rep(i, h)
    {
        rep(j, w)
        {
            int cnt = 0;
            if (mass[i][j] == '.')
            {
                rep(k, 8)
                {
                    int y = i + dy[k], x = j + dx[k];
                    if (0 <= x && x < w && 0 <= y && y < h && mass[y][x] == '#')
                    {
                        cnt++;
                    }
                }
                mass[i][j] = cnt + '0';
            }
        }
    }

    rep(i, h)
    {
        cout << mass[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 3608
s=list(input())
k=[]
g=[]
kcount=0
gcount=0
for i in range(len(s)):
        if i%2==0:
                k.append(s[i])
                if s[i]=="R" or s[i]=="U" or s[i]=="D":
                        kcount+=1
        else:
                g.append(s[i])
                if s[i]=="L" or s[i]=="U" or s[i]=="D":
                        gcount+=1 

if len(k)==kcount and len(g)==gcount:
        print("Yes")
else:
        print("No")

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

#define FOR(i, j, k) for(int i=j ; i<k ; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

    int D, N; cin >> D >> N;

    int ans = 1;
    REP(i, D) ans *= 100;
    if (N == 100) N++;
    cout << ans * N << endl;

    return 0;
}


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

typedef long long ll;

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

int main() {
ll a, b;
while(cin >> a >> b)
cout << gcd(a, b) << " " << a / gcd(a, b) * b << endl;}

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

#define MOD 1000000007
#define N 2000100

#define scd(x) scanf("%d",&x);
#define prd(x) printf("%d\n",x);
#define scl(x) scanf("%lld",&x);
#define prl(x) printf("%lld",x);
#define forall(i,j) memset(i,j,sizeof(i));


#define FOR(i,k,e) for (int i=e ; i<k ; i++)
#define RFOR(i,k,e) for (int i=e ; i>=k ; i--)

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

// int tree[4*N];
// int lazy[4*N];

// void update(int i, int j , int si , int sj , int index){
// 	if(lazy[index]!=0){
// 		if(lazy[index]%2==1){
// 			tree[index] = (sj-si+1) - tree[index];
// 		}
// 		if(si!=sj){
// 			lazy[2*index + 1] = lazy[2*index + 1] +  lazy[index];
// 			lazy[2*index + 2] = lazy[2*index + 2] +  lazy[index];
// 		}
// 		lazy[index] = 0;
// 	}
// 	if(j<si || i > sj){
// 	 return ;
//  	}
// 	if(si>=i && sj<=j){
// 		int l = sj-si+1;
// 		int temp = tree[index];
// 		tree[index] = l - tree[index];
// 		if(si!=sj){
// 			lazy[2*index + 1] = lazy[2*index+1] + 1;
// 			lazy[2*index + 2] = lazy[2*index+2] + 1;
 
// 		}
// 		return;
		
// 	}
 
// 	 update(i, j, si , (si + sj)/2 , 2*index + 1);
// 	 update( i, j, (si + sj)/2 +1 , sj , 2*index + 2);
// 	 tree[index] = tree[2*index+1] + tree[2*index+2];
	
	
// }
// int query(int i, int j , int si , int sj , int index){
// 	if(lazy[index]!=0){
// 		if(lazy[index]%2==1){
// 			tree[index] = (sj-si+1) - tree[index];
// 		}
// 		if(si!=sj){
// 			lazy[2*index + 1] = lazy[2*index + 1] +  lazy[index];
// 			lazy[2*index + 2] = lazy[2*index + 2] +  lazy[index];
// 		}
// 		lazy[index] = 0;
// 	}
// 	if(j<si || i > sj){
// 	 return 0;
//  	}
// 	if(si>=i && sj<=j){
// 		return tree[index];
// 	}
 
 
// 	return  query(i, j, si , (si + sj)/2 , 2*index + 1)
// 			+ query( i,  j, (si + sj)/2 +1 , sj , 2*index + 2);
 
// }
// int make_tree(int i,int j,int r){
// 	if(i==j){
// 		tree[r] = euler[i];
// 		return tree[r];
// 	}
// 	tree[r] = make_tree(i,(i+j)/2,2*r+1) + make_tree(((i+j)/2)+1,j,2*r+2);
// 	return tree[r];
// }
// vi adj[N];
// int vis[N];
// void dfs(int r){
// 	vis[r] = 1;
// 	FOR(i,adj[r].size(),0){
// 		if(vis[adj[r][i]] == 0){
// 			dfs(adj[r][i]);
// 		}
// 	}
// }

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  int n;
cin >> n;
if(n%2==0){
cout << n;
}
else{
cout << 2*n;
}
  return 0;
}



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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  for(int i = 0; i <= n - 3;i++){
    if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

const int N = 2e5 + 5;

vector<int> bst(N, -1);
int cur = 1;
vector<int> g[N];
int a[N], ans[N];

void dfs(int u, int par=-1){
	// edit	
	int ind = lower_bound(bst.begin(),bst.begin()+cur,a[u]) - bst.begin();
	int pcur = cur, pv = bst[ind];
	if(ind == cur)++cur;
	bst[ind] = a[u];
	ans[u] = cur-1;
	for(int v:g[u]){
		if(v == par)continue;
		dfs(v,u);	
	}
	cur = pcur;
	bst[ind] = pv;
}

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	rep(i,0,n)cin >> a[i];
	rep(i,0,n-1){
		int x,y;
		cin >> x >> y;
		--x,--y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	bst[0] = 0;
	dfs(0);
	rep(i,0,n){
		cout << ans[i] << '\n';
	}
}


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

int main() {
    int N,M;
    cin>>N>>M;
    vector<int> vec1(M);
    vector<int> vec2(M);
    vector<int> vec3(N);
    for(int i=0;i<M;i++){
        cin>>vec1.at(i)>>vec2.at(i);
        vec3.at(vec1.at(i)-1)++;
        vec3.at(vec2.at(i)-1)++;
    }
    for(int i=0;i<N;i++){
        cout<<vec3.at(i)<<endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC043A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a,c;
            var word = Console.ReadLine();
            a = int.Parse(word);
            c = 0;
            for (int i = 1; i <=a; i++)
            {
              
                c += i;
            
                    
            }
            Console.WriteLine(c);
            Console.ReadKey();
        }
    }
}

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

const int N = 26;

int main()
{
    int d;
    cin >> d;
    vector<int> c(N);
    rep(i, 0, N) cin >> c[i];
    vector<vector<int>> s(d, vector<int> (N));
    rep(i, 0, d) rep(j, 0, N) cin >> s[i][j];
    rep(i, 0, 365){
        cout << i%26 + 1 << endl;
    }
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll h, w, d;
    cin >> h >> w >> d;
    vector<ll> a(h*w+1), x(h*w+1);
    ll q, c;
    for(ll i=0;i<h;i++){
    	for(ll j=0;j<w;j++){
    		cin >> c;
    		a[c] = i;
    		x[c] = j;
    	}
    }
    vector<ll> b(h*w+1, 0);
    ll le, ri;
    for(int i=1;i<=d;i++){
    	ll now = i;
    	while(now + d <= h * w){
    		ll nx = now + d;
    		b[nx] = b[now] + abs(x[now] - x[nx]) + abs(a[now] - a[nx]);
    		now = nx;
    	}
    }
    cin >> q;
    vector<ll> ans;
    for(int i=0;i<q;i++){
    	cin >> le >> ri;
    	ans.pb(b[ri] - b[le]);
    }
    for(auto& i: ans){
    	cout << i << endl;
    }
    return 0;
}


Measured memory_bytes: 4212
const main = arg => {
  let returnString = 'hon';
  const n = arg.trim().split('\n')[0].slice(-1);

  if (n === '3') {
    returnString = 'bon';
  } else if (['0', '1', '6', '8'].includes(n)) {
    returnString = 'pon';
  }
  console.log(returnString);
};

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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


#define for0(i, n) for (long long  i = 0; i < n; i++) 
#define for1(i, n) for (long long  i = 1; i <= n; i++) 
#define forc(i, l, r) for (long long  i = l; i <= r; ++i) 
#define forr0(i, n) for (long long  i = n - 1; i >= 0; i--) 
#define forr1(i, n) for (long long  i = n; i >= 1; i--) 


#define pb push_back
#define fi first
#define se second


#define all(x) (x).begin(), (x).end() 
#define rall(x) (x).rbegin, (x).rend() 

using namespace std;


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef long long int lli;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

const ll N = 1e5 + 5;
const ll mod = 1e9 + 7;

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    {
        ll i,j,k,n,m,cnt,x,y;
        string a,b;
        cin>>a>>b;
        n = a.length();
        m = b.length();
        ll dp[n+1][m+1];
        for(i=0;i<=n;i++)
        {
            for(j=0;j<=m;j++)
            {
                if(i==0 || j==0)
                {
                    dp[i][j]=0;
                }
                else if(a[i-1]==b[j-1])
                {
                    dp[i][j] = 1 + dp[i-1][j-1];
                }
                else
                {
                    dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }
        cnt = dp[n][m];
        char lcs[cnt+1];
        lcs[cnt]='\0';
        i=n,j=m;
        while(i>0 && j>0)
        {
            if(a[i-1]==b[j-1])
            {
                lcs[cnt-1]=a[i-1];
                i--,j--,cnt--;
            }
            else if(dp[i-1][j]>dp[i][j-1]) i--;
            else j--;
        }
        cout<<lcs<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 73808
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
long long d[100][100];

void warshall_floyd(int V){
  rep(i,V){
    d[i][i] = 0;
  }
  rep(i,V){
      rep(j,V){
          rep(k,V){
              d[j][k] = min(d[j][k],d[j][i]+d[i][k]);
          }
      }
  }
}

int main(){
  while(1){
    long long n,m,s,g1,g2,from,to,cost,minn=1e9;
    cin >> n >> m >> s >> g1 >> g2;
    if(n==0)break;
    s--;g1--;g2--;
    rep(i,n){rep(j,n){d[i][j]=1e9;}}
    rep(i,m){
      cin >> from >> to >> cost;
      from--;to--;
      d[from][to] = cost;
    }
    warshall_floyd(n);
    rep(i,n)if (minn>d[s][i]+d[i][g1]+d[i][g2]) minn=d[s][i]+d[i][g1]+d[i][g2];
    cout << minn << endl;
  }
  return 0;
}

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

int main() {
    string s;
    cin >> s;
    int n = s.length();
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == '0') cnt++;
    }
    cout << min(cnt, n - cnt) * 2 << endl;
}

Measured memory_bytes: 512
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
using namespace std;


int main() {
    vector<int> v(3);
    for(int i = 0; i < 3; i++){
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    if(v[0] + v[1] == v[2]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>>to(100000);
vector<int>done;
vector<int>memo;
int dp(int i){
  if (done.at(i)){
  return memo.at(i); 
  }
  else{
  int res=0;
  for (int b:to.at(i)){
	res=max(res,dp(b)+1);
  }
    //当たり前やんか、一回触ったらそれをdoneに書き込まないと
    done.at(i)=1;
    memo.at(i)=res;
return res;
  }
}
/*i=0  3               
1     2
2     0
3     1
 4    4

0(3 2)
1(2 3)
2(0)
3(2)
4(2 1 0)*/


int main(){
//入力は同じでいい
  int N,M;
  cin >>N>>M;
  done.resize(N);
  memo.resize(N);//これはdp(i)の値をmemo.at(i)に入れる。
   
for(int i= 0;i<M;i++){
  int a,b;
  	cin >>a>>b;
  --a;
  --b;
  //0番目からのスタートにしたいから。
  to.at(a).push_back(b);
 //これで木の入力は済んだはず
}
 priority_queue<int>q;
 for (int i=0;i<N;i++){
   //cout <<dp(i)<<endl;//dpを出力させる
   q.push(dp(i));//ここでdp(i)はi番目出発の最長経路を表す数値 or 戻り値でそれを返す関数。
 }
 cout <<q.top()<<endl; 
}


Measured memory_bytes: 9212
import java.util.*;

public class Main{
   public static void main(String[] args) {
	  Scanner sc =new Scanner(System.in);
   int n=sc.nextInt();
   int []tri=new int[3];
   for(;n>0;n--){
	   for(int i=0;i<3;i++)tri[i]=sc.nextInt();
	   Arrays.sort(tri);
	   if(tri[2]*tri[2]==tri[0]*tri[0]+tri[1]*tri[1])
		 System.out.println("YES");
	   else System.out.println("NO");
   }
   }
}

Measured memory_bytes: 23376
#include<stdio.h>
int main()
{
int n,m;
long long s=0;
scanf("%d%d",&n,&m);
while(m--)
{
int a;
scanf("%d",&a);
s+=a;
}
if(n<s) puts("-1");
else printf("%lld\n",n-s);
return 0;
}

Measured memory_bytes: 1732
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as V

main :: IO ()
main = readLine >>= main'
    where
        main' abq = readf abq >>= printRes . solve
        readf [a, b, q] = (,,) <$> rf a <*> rf b<*> rf q 
        rf = flip replicateM (head <$> readLine)
        printRes = mapM_ print

solve :: ([Int], [Int], [Int]) -> [Int]
solve (ss, ts, qs) = map answer qs
    where
        answer q = minimum [v0, v1, v2, v3, v4, v5]
            where
                !v0 = max sdr tdr
                !v1 = max sdl tdl
                !v2 = 2 * sdl + tdr
                !v3 = 2 * tdl + sdr
                !v4 = 2 * sdr + tdl
                !v5 = 2 * tdr + sdl

                !sdr = sr - q
                !tdr = tr - q
                !sdl = q - sl
                !tdl = q - tl

                !(sl, sr) = edit vas $ binarySearch q vas
                !(tl, tr) = edit vbs $ binarySearch q vbs

        edit vs (Right i) = (x, x)
            where
                x = vs V.! i
        edit vs (Left i)
            | i == 0 = (-inf, r)
            | i == V.length vs = (l, inf)
            | otherwise = (l, r)
            where
                l = vs V.! (i - 1)
                r = vs V.! i

        vas = V.fromList ss
        vbs = V.fromList ts
        
        inf = 10 ^ 11

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

--binarySearch :: (Ord a) => a -> V.Vector a -> Either Int Int
binarySearch k !xs
    | V.null xs = Left 0
    | otherwise = bsf 0 $ V.length xs
    where
        bsf !base !size
            | size > 1 && mv > k = bsf base $ size - half
            | size > 1 = bsf mid $ size - half
            | bv == k = Right base
            | bv < k = Left $ base + 1
            | otherwise = Left base
            where
                half = size `div` 2
                !mid = base + half
                bv = xs V.! base
                mv = xs V.! mid
{-# INLINE binarySearch #-}

Measured memory_bytes: 81020
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n;i++)
#define INF 1e9
int main(){
    int n; cin>>n;
    using pii = pair<int,int>;
    using piii = pair<pii,int>;
    vector<pii>range;
    vector<int>nd(361,0);
    vector<int>s;
    rep(i,n){
        int m,d,v,_s; cin>>m>>d>>v>>_s;
        pii temp;
        temp.first=(m-1)*30+d;
        temp.second=temp.first+v-1;  if(temp.second>360)temp.second-=360;
        range.push_back(temp);
        if(temp.first<=temp.second)
            for(int i=temp.first;i<=temp.second;i++)
                nd[i]=max(nd[i],_s);
        else{
            for(int i=temp.first; i<=360;i++)nd[i]=max(nd[i],_s);
            for(int i=1; i<=temp.second;i++)nd[i]=max(nd[i],_s);
        }
        
        s.push_back(_s);
    }
    
    for(int day=1; day<=360;day++){
        for(int i=0; i<n;i++){
            pii t=range[i];
            pii value;
            if(t.first>=day)value.first=t.first-day;
            else value.first=360-day+t.first;
            if(t.second<=day)value.second=day-t.second;
            else value.second=360-t.second+day;
            nd[day]=max(nd[day],max(0,s[i]-min(value.first,value.second)));
        }
    }
    int ans=INF;
    for(int i=1; i<=360;i++)ans=min(ans,nd[i]);
    cout<<ans<<endl;
}

Measured memory_bytes: 3156
//InfiniteCoins.java
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
        int a=sc.nextInt();
        
        int sum=0;
        for(int i=0; i<n; i++){
            sum=n-500*i;
            if(sum<500){
                break;
            }
        }
        if(sum<=a){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
        sc.close();
    }
}

Measured memory_bytes: 23764
#include<stdio.h>
#include<iostream>
#include<string.h>
#include <iomanip>
#include<math.h>
#include<queue>
#include<vector>
#include<algorithm>
#define Max (int)105
#define MAX2 (int)1e5+5
#define MOD ((int)1e9+7)
using namespace std;


int solve(int x){
	int a = 10;
	a = a - (x%10);
	if(a == 10)
		return 0;
	return a;
}

int main(){
	int a[5],i;
	for(i=0;i<5;i++)
		scanf("%d",&a[i]);

	int tmp = 0,c=1,j;
	for(i=0;i<10;i++){
		for(j=0;j<5;j++){
			if(solve(a[j]) == i){
				tmp += a[j];
				if(c < 5){
					tmp += i;
				}
				c++;
			}
		}
	}

	printf("%d\n",tmp);
}










/*
Atcoder Dp G-Longest Path iterative solution

vector<int>vec[Max];
queue<int>q;

int dp[Max];
int vis[Max];

void init(){
	int i;
	for(i=0;i<Max;i++){
		dp[i] = 0;
		vis[i] = 0;
	}
}

int getMax(int a,int b){
	return (a<b)?b:a;
}

void solve(int x){
	int i,u;
	q.push(x);

	while(!q.empty()){
		u = q.front();
		q.pop();

		if(vis[u])
			continue;
		vis[u] = 1;
		
		for(i=0;i<vec[u].size();i++){
			dp[vec[u][i]] = getMax(dp[vec[u][i]],dp[u]+1);
			q.push(vec[u][i]);
		}
	}

}

int main(){
	int n,m,incoming[Max],x,y,i;
	for(i=0;i<Max;i++)
		incoming[i] = 0;
	
	init();

	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++){
		scanf("%d%d",&x,&y);
		vec[y].push_back(x);
		incoming[x]++;
	}
	
	for(i=1;i<=n;i++)
		solve(i);
	
	int max = 0;
	for(i=0;i<Max;i++)
		max = getMax(max,dp[i]);
	
	printf("%d\n",max);
	return 0;
}
*/

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }
	
int main() {
	int n,res;
	for(;n=in();){
		res=0;
		while(n){
			n/=5;
			res+=n;
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long int LL;
const int MAX=1e9+7;
char ca[100005];
bool can[100005];

int main(){
	int n;
	int i,j,k;
	int a,b,c,d;
	cin>>ca;
	n=strlen(ca);
	for(i=0;i<n;i++){
		if(ca[i]=='0')can[i]=false;
		else can[i]=true;
	}
	for(i=0;i<n-1;i++){
		if(can[i]!=can[n-i-2]){
			cout<<-1<<endl;
			return 0;
		}
	}
	if(ca[0]=='0' || ca[n-1]=='1'){
		cout<<-1<<endl;
		return 0;
	}
	for(i=1,j=0;i<n;i++){
		if(can[i-1]){
			cout<<j+1<<" "<<i+1<<endl;
			j=i;
		}else{
			cout<<j+1<<" "<<i+1<<endl;
		}
	}
	return 0;
	
}


Measured memory_bytes: 1536
#include <stdio.h>

int main(int argc, const char * argv[])
{

    long long num = 39;
    long long candy;
    long long stu;
    
    while(scanf("%lld",&candy) != EOF){
        stu = candy % num;
        if (stu == 0) stu = 39;
        printf("3C");
        if (stu / 10 == 0) {
            printf("0");
        }
        printf("%lld\n",stu);
    }
    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define MEM(ara,val) memset(ara,val,sizeof(ara))
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

#define maxn 200000

i64 a[maxn+5] ;

int main()
{
    i64 i , j , k , l , m , n ;

    scanf("%lld",&n) ;

    for(i=1 ; i<=n ; i++) scanf("%lld",&a[i]) ;

    for(i=1 ; i<=n ; i++) a[i] -= i ;

    sort(a+1,a+n+1) ;

    m = a[ (n+1)/2 ] ;

 //   for(i=1 ; i<=n ; i++) printf("%lld\n",a[i]) ;
  //  printf("m: %lld\n",m) ;
    i64 ans = 0LL ;

    for(i=1 ; i<=n ; i++) ans += abs(a[i]-m) ;

    cout<<ans<<endl ;

    return 0 ;
}



Measured memory_bytes: 1792
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

struct Point {
    double x;
    double y;
};
void print(Point p) {
    printf("%.8f %.8f\n",p.x,p.y);
}

int n;

void koch(Point p1, Point p2,int depth) {
    if(n==depth) return;
    Point s;
    s.x = (2*p1.x+p2.x)/3;
    s.y = (2*p1.y+p2.y)/3;

    Point t;
    t.x = (p1.x+2*p2.x)/3;
    t.y = (p1.y+2*p2.y)/3;

    Point u;
    u.x=(t.x-s.x)/2-(t.y-s.y)*sqrt(3.0)/2+s.x;
    u.y=(t.x-s.x)*sqrt(3.0)/2+(t.y-s.y)/2+s.y;

    koch(p1,s,depth+1);
    print(s);
    koch(s,u,depth+1);
    print(u);
    koch(u,t,depth+1);
    print(t);
    koch(t,p2,depth+1);
}

int main() {
    cin>>n;
    Point p1,p2;
    p1.x=0;
    p1.y=0;
    p2.x=100;
    p2.y=0;
    print(p1);
    koch(p1,p2,0);
    print(p2);

    return 0;
}

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

int main(){
	int a[500] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin >> k;
	cout << a[k-1];
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define INF 10000000
int main( void )
{
	while ( !cin.eof() )
	{
		int n;
		cin >> n;

		if ( cin.eof() )
			break;

		for ( int i = 0; i < n; i++ )
		{
			double x1, x2, x3, x4;
			double y1, y2, y3, y4;

			cin >> x1 >> y1;
			cin >> x2 >> y2;
			cin >> x3 >> y3;
			cin >> x4 >> y4;

			double m1;
			double m2;
			if ( x2-x1 != 0 )
				m1 = (y2-y1)/(x2-x1);
			else
				m1 = INF;

			if ( x4-x3 != 0 )
				m2 = (y4-y3)/(x4-x3);
			else
				m2 = INF;

			if ( m1 == m2 )
				cout << "YES" << endl;
			else
				cout << "NO" << endl;
		}

	}

	return 0;
}

Measured memory_bytes: 0
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc109_a.cpp
 * time   : Thu Apr 30 22:39:21 2020
 * quest  : A - ABC333
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  cout << ((a * b) % 2 ? "Yes" : "No") << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
	  #define endl "\n"
	  #define ll long long int
	  #define mod 1000000007
	  #define inf 1000000000000000001;
	  using namespace std;
	  int main()
	  {
	    //  #ifndef ONLINE_JUDGE
	    //  // for getting input from input.txt
	    //  freopen("input.txt", "r", stdin);
	    //  // for writing output to output.txt
	    //  freopen("output.txt", "w", stdout);
	    // #endif
	    std::ios::sync_with_stdio(false);
	    cin.tie(NULL);

	    int v[5],sum=0,rm=0,a[5];
	    for (int i = 0; i < 5; ++i)
	    {
	    	cin>>v[i];
	    	a[i] = v[i];
	    	while(v[i]%10 != 0){
	    		v[i]++;
	    	}
	    	rm = max(rm,v[i]-a[i]);

	    	sum += v[i];

	    	// cout<<sum<<endl;
	    }

	    cout<<v[0]+v[1]+v[2]+v[3]+v[4]-rm;
	    return 0;
	  }


Measured memory_bytes: 3540
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <map>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  map<int, int> chie;
  for (int i = 0; i < n; ++i) {
    int v;
    cin >> v;
    chie[v]++;
  }
  int s = chie.size() - k;
  int ans = 0;

  vector<int> v;
  for (auto&& c : chie) {
    v.emplace_back(c.second);
  }
  sort(begin(v), end(v));
  for (int i = 0; i < s && i < v.size(); ++i) ans += v[i];

  cout << ans << endl;
}


Measured memory_bytes: 10748
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int num = Integer.parseInt(line);
        
        line = sc.nextLine();
        String[] lines = line.split(" ", 0);

        int before = Integer.parseInt(lines[0]);
        long sum = 0;
        for (int i = 1; i < lines.length; i++) {
            int now = Integer.parseInt(lines[i]);
            if (now < before) {
                sum+= before - now;
            } else {
                before = now;
            }
        }
        
        System.out.println(sum);
    }
}


Measured memory_bytes: 80796
#include<bits/stdc++.h>
using namespace std;
string s;
long long sum;
int main()
{
 //freopen(".in","r",stdin);
 //freopen(".out","w",stdout);
 cin>>s;
 for(int i=0; i<6; i++)
 if(s[i]=='1')
 sum++;
 printf("%d",sum);
 return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    int n,x,y=0,z=0;
    boolean a;
    String b;
    public void solve(){
        Scanner sc = new Scanner(System.in);
        sc.useDelimiter("\\s");
        while(a == false){
            n = sc.nextInt();
            x = sc.nextInt();
            if(n == 0 && x == 0){
                a = true;
                break;
            }
            for(int s1 = 1;s1 <= n-2; s1++){
                for(int s2 = s1+1;s2 <= n-1; s2++){
                    for(int s3 = s2+1;s3 <= n; s3++){
                        if(s1 == s2 || s1 == s3 || s2 == s3){
                            break;
                        }else if(s1 + s2 + s3 == x){
                            z++;
                        }
                    }
                }
            }
            System.out.println(z);
            z = 0;
        }
    }
    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 19592
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;
typedef pair<int, int> pii;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 5005
const ll INF = 1e9 + 7;


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

const ll MOD = 1e9 + 7;

int h, w;
char mp[10][10];

int main() {

	/*cin >> h >> w;
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			cin >> mp[i][j];
		}
	}*/

	ll q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;

	ll mini = min(min(8 * q, 4 * h), min(2 * s, d));

	ll mini2 = min(4 * q, min(2 * h, s));

	//cout << mini << " " << mini2 << endl;
	
	cout << mini * (n / 2) + mini2 * (n % 2) << endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[110];

signed main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	int ans=0;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			ans+=A[i]*A[j];
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

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;
}

int main() {
	int n;
	string s;
	cin >> n >> s;
	
	s.erase(unique(s.begin(), s.end()), s.end());

	cout << s.length() << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
const int P = 998244353;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int fac[MAXN], inv[MAXN];
int power(int x, int y) {
	if (y == 0) return 1;
	int tmp = power(x, y / 2);
	if (y % 2 == 0) return 1ll * tmp * tmp % P;
	else return 1ll * tmp * tmp % P * x % P;
}
int binom(int x, int y) {
	if (y > x) return 0;
	else return 1ll * fac[x] * inv[y] % P * inv[x - y] % P;
}
void update(int &x, int y) {
	x += y;
	if (x >= P) x -= P;
}
void init(int n) {
	fac[0] = 1;
	for (int i = 1; i <= n; i++)
		fac[i] = 1ll * fac[i - 1] * i % P;
	inv[n] = power(fac[n], P - 2);
	for (int i = n - 1; i >= 0; i--)
		inv[i] = inv[i + 1] * (i + 1ll) % P;
}
int n, ans; ll a, b, k;
int main() {
	read(n), init(n);
	read(a), read(b), read(k);
	for (int i = 0; i <= n; i++) {
		ll lft = k - a * i;
		if (lft >= 0 && lft % b == 0 && lft / b <= n) update(ans, 1ll * binom(n, i) * binom(n, lft / b) % P);
	}
	writeln(ans);
	return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <cmath>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <climits>
#define sync                                                                   \
        ios_base::sync_with_stdio(0);                                                \
        cin.tie(0);                                                                  \
        cout.tie(0)
#define ss second
#define ff first
#define ll long long
#define mp make_pair
#define endl "\n"
#define pb push_back
#define ld long double
#define M_PI 3.14159265358979323846
#define puss vector
#define ull unsigned long long
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define die {cout<<-1; return 0;}
double EPS = 0.00001;
const ll INF = 1000000007;
using namespace std;


int main() {
        sync;
        string s;
        cin>>s;
        int ans=0;
        FOR(i, 0, s.size()) if (s[i]=='1') ans++;
        cout<<ans;
}


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

int main()
{
	int N;
	int64_t W;
	scanf("%d%lld", &N, &W);
	using vi = std::vector<int64_t>;
	vi v(N), w(N);
	int64_t sum{};
	for (int i{}; i < N; i++)
	{
		scanf("%lld%lld", &v[i], &w[i]);
		sum += v[i];
	}
	
	vi dp(sum + 1, 1ll << 60);
	dp[0] = 0;
	for (int i{}; i < N; i++)
		for (int64_t j{sum}; j >= v[i]; j--)
			dp[j] = std::min(dp[j], dp[j - v[i]] + w[i]);
	for (int64_t i{sum}; i >= 0; i--)
	{
		if (dp[i] <= W)
		{
			printf("%lld\n", i);
			break;
		}
	}
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>


int main(){
    ll A,B,C,K; cin>>A>>B>>C>>K;
    ll ans = 0;
    if(K<=A){
        ans = K;
    }else if(K<=A+B){
        ans = A;
    }else{
        ans = A - max(K-A-B,0LL);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3600
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()

void Calc();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0); cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

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

void Calc() {
  string s = in;
  cout << (s.substr(0, 4)) << ' ' << s.substr(4) << endl;
}


Measured memory_bytes: 256
// floyd2.cpp : アプリケーションのエントリ ポイントを定義します。
//

// floyd.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include <iostream>
#include <string>
using namespace std;



int main()
{
    int D, N;
    long long sum = 0, num = 1;
    
    cin >> D >> N;
    for (int k = 0; k < D; k++) {
        num *= 100;
    }
    for (int i = 0; i < N; i++) {
        sum += (num);
    }
    if (N == 100) {
        sum += (num);
    }

    cout << sum;
        
    cout << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

int main()
{
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a);
    vector<int> q(b);
    vector<int> r(c);
    for (int i = 0; i < a; i++) {
        cin >> p[i];
    }
    for (int i = 0; i < b; i++) {
        cin >> q[i];
    }
    for (int i = 0; i < c; i++) {
        cin >> r[i];
    }
    sort(p.begin(), p.end(), greater<int>());
    sort(q.begin(), q.end(), greater<int>());
    sort(r.begin(), r.end(), greater<int>());
    // 今のスコア
    // 赤を何個食ったか
    // 緑を何個食ったか
    // 無色を何個食ったか

    deque<int> ansdeq;
    for (int i = 0; i < x; i++) {
        ansdeq.push_back(p[i]);
    }
    for (int i = 0; i < y; i++) {
        ansdeq.push_back(q[i]);
    }
    // for (int i = 0; i < c; i++) {
    //     ansdeq.push_back(r[i]);
    // }
    sort(ansdeq.begin(), ansdeq.end(), greater<int>());
    int i = 0;
    while (ansdeq.back() < r[i]) {
        ansdeq.pop_back();
        ansdeq.push_front(r[i]);
        i++;
    }
    ll ans = 0;
    for (int i = 0; i < ansdeq.size(); i++) { 
        ans += ansdeq[i];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2176
using System;
using System.Linq;

namespace agc030_a
{
    class Program
    {
        static void Main(string[] args)
        {
            var text = Console.ReadLine();
            var list = text.Split(' ').ToList();

            var a = int.Parse(list[0]);
            var b = int.Parse(list[1]);
            var c = int.Parse(list[2]);

            var x = c;
            for (var i = 0; i < 10; i++)
            {
                x = a * x - b;
                Console.WriteLine(x);
            }
        }
    }
}


Measured memory_bytes: 11220
fun main(args: Array<String>?): Unit {
    val n = readLine()!!.toInt()
    val words = Array(n){ readLine()!!.trim().let{ l ->
        val a = IntArray(26){0}
        for (c in l) a[c - 'a']++
        a
    }}
    println(('a' .. 'z').joinToString(""){c -> c.toString().repeat(words.map{a -> a[c - 'a']}.min()!!)})
}


Measured memory_bytes: 33816
#include <cstdio>
#include <cctype>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
	char s[1000];
	scanf("%[^\n]",s);
	string str = s;
	transform(str.begin(),str.end(),str.begin(),::toupper);
	printf("%s\n",str.c_str());
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b; cin >> a >> b;
    if(a == b) cout << "Draw" << endl;
    else if ((a > b && b > 1) || a == 1) cout << "Alice" << endl;
    else cout << "Bob" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
enum = enumerate

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().split()))

def vinput(rep=1, ty=int, cvt=list):
	return cvt(ty(input().rstrip()) for _ in "*"*rep)

def gcd(a: int, b: int):
	while b: a, b = b, a%b
	return a

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

def main():
	a,b,c = linput()
	d = a-b
	res = 0

	cnt = 0
	while cnt<10**2:
		if a%2 or b%2 or c%2:
			break
		p,q,r = a//2, b//2, c//2
		s = p+q+r
		a,b,c = s-p, s-q, s-r
		cnt += 1
		#print(a,b,c)
	else:
		cnt = -1
	
	res = cnt
	#sT = "No Yes".split()
	#print(sT[res])
	print(res)

if __name__ == "__main__":
	main()


Measured memory_bytes: 61964
#include <bits/stdc++.h>
using namespace std;
int main(){
    string a,ans;
    cin >> a;
    bool cnt = false;
    while (a.size()>0){
         a.erase(a.size()-1);
        if(a.size()%2 ==0){
            int n = a.size()/2;
            string b = a.substr(0,n);
            string c = a.substr(n,a.size()-1);
            if(b == c){
                ans = a;
                break;
            }
            
        }
    }
    cout << ans.size() << endl;
}



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

int main()
{

	long s;
	cin >> s;

	int digits = 0;
	for (long tmp = s; tmp > 0; digits++) {
		tmp /= 10;
	}

	long sum = 0;
	for (int i = 0; i < 1 << (digits - 1); i++) {
		long s_tmp = s;
		int div = 10;
		for (int j = 0; j < digits - 1; j++) {
			if (1 & i >> j) {
				sum += (s_tmp % div);
				s_tmp /= div;
				div = 10;
			} else {
				div *= 10;
			}

		}
		sum += s_tmp;
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1'000'000'007;

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

    int s; cin >> s;
    vector<int> dp(2001, 1);
    dp[0] = dp[1] = dp[2] = 0;

    for (int i = 3; i <= s; i++) {
        int j = i - 3;
        while (j >= 3) {
            dp[i] += dp[j];
            dp[i] %= MOD;
            j--;
        }
    }

    cout << dp[s];
}

Measured memory_bytes: 3652
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int sum = 0;
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
            sum += array[i];
        }
        Arrays.sort(array);
        
        if (sum % 10 != 0) {
            System.out.println(sum);
            return;
        }
        
        for (int i = 0; i < n; i++) {
            if (array[i] % 10 != 0) {
                System.out.println(sum - array[i]);
                return;
            }
        }
        System.out.println(0);
        return;
    }
}


Measured memory_bytes: 22612
Explosion = (-3..3).map{|i| [[i,0], [0,i]]}.flatten(1) - [[0, 0]]

def bomb(x, y)
	@field[y][x] = "0"
	Explosion.each do |dx, dy|
		nextX = x + dx
		nextY = y + dy
		next if !(0..7).include?(nextX) || !(0..7).include?(nextY)
		if @field[nextY][nextX] == "1"
			bomb(nextX, nextY)
		end
		@field[nextY][nextX] = "0"
	end
end

gets.to_i.times do |dataset|
	gets
	@field = 8.times.map{ gets.chomp }
	x, y = 2.times.map{ gets.to_i - 1 }
	bomb(x, y)
	puts "Data #{dataset+1}:"
	puts @field.join("\n")
end

Measured memory_bytes: 6200