akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    string s, t; cin >> s >> t;
    reverse(t.begin(), t.end());
    if (s == t)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	char s[19];
	while(scanf("%s",&s)!=EOF)
	{
		char c1[5],c2[7],c3[5];
		for(int i=0,j=0;i<5;i++,j++)
		{
		    printf("%c",s[i]);
		}
		printf(" "); 
		for(int i=6,j=0;i<13;i++,j++)	
		{
		    printf("%c",s[i]);
		}
		printf(" ");
		for(int i=14,j=0;i<19;i++,j++)	
		{
			printf("%c",s[i]);
		}
		printf(" \n");	
	}	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
 
 
#define li			long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)	for(li i=(li)(start);i<((li)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define rjm	rep(j,m)
#define VV			vector


#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)		idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)	for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)		idp p2((x).F, (x).S)
#define dump(x,n)	idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)	idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)	idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)	idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}



#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007

#define PRIME_MAX 1000001

typedef pair<li, li> PI;

li m,n;

li a[555], b[555];

vector<li> bipartite_match[1555];
li match_to[1555];
bool used[1555];

bool dfs(li now){
	used[now]=true;
	rep(i,sz(bipartite_match[now])){
		li next = bipartite_match[now][i];
		li next_next = match_to[next];
		if(next_next < 0 || (!used[next_next] && dfs(next_next))){
			match_to[now]=next;
			match_to[next]=now;
			return true;
		}
	}
	return false;
}

int main(int argc, char *argv[]){
	while(1){
		cin>>m>>n;
		if(min(m,n)<=0)break;

		rep(i,m)cin>>a[i];
		rep(i,n)cin>>b[i];

		// construct graph
		rep(i,1500)bipartite_match[i].clear();
		rep(i,1555){
			match_to[i]=-1;
		}
		rep(i,m){
			rep(j,n){
				if(__gcd(a[i], b[j])>1){
					bipartite_match[i].pb(m+j);
					bipartite_match[m+j].pb(i);
				}
			}
		}



		// do matching
		li res=0;
		rep(i,m){
			if(match_to[i]<0){
				memset(used, false, 1555);
				if(dfs(i))res++;
			}
		}
		cout<<res<<endl;

	}

	return 0;
}

Measured memory_bytes: 5484
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> L(n);

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

    int sum = 0;
    int maxValue = 0;

    for (int i = 0; i < n; i++) {
        sum += L[i];
        maxValue = max(maxValue, L[i]);
    }

    sum -= maxValue;

    if (maxValue < sum) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

typedef long long ll;

const int N = 5e3 + 15, inf = 1e9 + 7;
int n, ans;
int p[N * N];
int val[N][N];
bool mark[N][N];
int dx[] = {-1, 0, 0, +1};
int dy[] = {0, -1, +1, 0};

bool in(int x, int y) {
	return 0 <= x && x < n && 0 <= y && y < n;
}

void dfs(int x, int y, int va) {
	val[x][y] = min(val[x][y], va);
	for (int k = 0; k < 4; k++) {
		int nx = x + dx[k], ny = y + dy[k];
		if (!in(nx, ny))
			continue;
		if (va + !mark[nx][ny] < val[nx][ny])
			dfs(nx, ny, va + !mark[nx][ny]);
	}
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 0; i < n * n; i++)
		cin >> p[i];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			val[i][j] = min({i, j, n - i - 1, n - j - 1}) + 1;

	for (int i = 0; i < n * n; i++) {
		int x = (p[i] - 1) / n, y = (p[i] - 1) % n;
		ans += val[x][y] - 1;
		mark[x][y] = true;

		int mn = inf;
		for (int k = 0; k < 4; k++) {
			int nx = x + dx[k], ny = y + dy[k];
			if (in(nx, ny))
				mn = min(mn, val[nx][ny]);
			else
				mn = 0;
		}
		dfs(x, y, mn);
	}

	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 24968
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc086/tasks/abc086_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(a, b):
    p = a * b
    if p % 2 == 0:
        return 'Even'
    else:
        return 'Odd'


def main(args):
    a, b = map(int, input().split())
    ans = solve(a, b)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
    


Measured memory_bytes: 3060
import java.lang.*

fun main(args: Array<String>) {
    val mod = 1e9.toInt() + 7
    val n = readLine()!!.toInt()
    val l = readLine()!!.split(" ").map(String::toInt).toList()
    val m = mutableListOf<Int>()
    for ( i in 1..n ) m.add(0)
    for ( i in l ) {
        m[i]++
    }
    var cur = if (n % 2 == 0) 1 else 0
    var ok = true
    while(cur < n) {
        val x = if (cur == 0) 1 else 2
        if (m[cur] != x) {
            ok = false
            break
        }
        cur += 2
    }
    var ans = 0
    if (ok) {
        ans = 1
        for (i in 1..n/2) ans = ans * 2 % mod
    }
    println(ans)
}


Measured memory_bytes: 51900
N,M = map(int,input().split())
K = []
sum = 0
if N==1:
  W=list(map(int,input().split()))
  W.pop(0)
  K+=W
  print(len(K))
  exit()
for i in range(N):
  W=list(map(int,input().split()))
  W.pop(0)
  K+=W
for T in range(1,len(K)+1):
  B=K.count(T)
  if B == N:
    sum+=1
print(sum)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

string s;
string ss[4] = {"resare","remaerd","esare","maerd"};
int sl[4] = {6,7,5,5};

int main(){
    cin >> s;
    reverse(s.begin(),s.end());
    int p = 0;
    bool b,bb;
    while(true){
        b = false;
        for(int i=0;i<4;i++){
            if(p+sl[i]>s.size()) continue;
            bb = true;
            for(int j=0;j<sl[i];j++){
                if(ss[i][j] != s[p+j]){
                    bb = false;
                    break;
                }
            }
            if(bb){
                b = true;
                p += sl[i];
                break;
            }
        }
        if(!b){
            cout << "NO" << endl;
            return 0;
        }
        if(p == s.size()){
            cout << "YES" << endl;
            return 0;
        }
        if(p > s.size()){
            cout << "NO" << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 512
from collections import deque
H, W = map(int, input().split())
C=list(list(input()) for _ in range(H))

def bfs():
	sx, sy = 0, 0
	gx, gy = H-1, W-1
	dx = [1, 0, -1, 0]
	dy = [0, 1, 0, -1]

	que=deque()
	que.append([sx, sy])
	visit=[[float("inf")]*W for _ in range(H)]
	visit[sx][sy]=1

	while que:
		x, y = que.popleft()
		for i in range(4):
			nx, ny = x+dx[i], y+dy[i]
			if 0<=nx and nx<H and 0<=ny and ny<W and visit[nx][ny]==float("inf") and C[nx][ny]!="#":
				que.append([nx,ny])
				visit[nx][ny]= visit[x][y]+1
	return visit[gx][gy]

black=0
white=0
for i in range(H):
	for j in range(W):
		if C[i][j]=="#":
			black+=1
		else:
			white+=1

temp=bfs()
if temp==float("inf"):
	print(-1)
else:
	ans=white-temp
	print(ans)

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;
const ll 	N 		= 	2*1e6;

vll adj[N];
ll visited[N]={};

// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,m,k,q,h,s,d;
vll a,b,c;
// <------------- Implement Functions Here ----------> //
ll cost = 0;
	
ll findMIN(ll a, ll b=INF, ll c=INF, ll d=INF) {
	ll mini = min({a,b,c,d});
	if(mini == a) return 0;
	if(mini == b) return 1;
	if(mini == c) return 2;
	if(mini == d) return 3;
}

void choice(ll val, ll*n) {
	ll qty = *n;
	if(val == 0 ) {
		cost += qty*q;
		*n = (*n)%1;
	}
	if(val == 1 ) {
		qty/=2;
		cost += qty*h;
		*n = (*n)%2;
	}
	if(val == 2 ) {
		qty/=4;
		cost += qty*s;
		*n = (*n)%4;
	}
	if(val == 3 ) {
		qty/=8;
		cost += qty*d;
		*n = (*n)%8;
	}
}
// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>q>>h>>s>>d>>n;
	n*=4;
	if(n >= 8) {
		ll val = findMIN(q*8,h*4,s*2,d);
		choice(val,&n);
	}

	if(n >= 4) {
		ll val = findMIN(q*8,h*4,s*2);
		choice(val,&n);
	}
	if(n >= 2) {
		ll val = findMIN(q*8,h*4);
		choice(val,&n);
	}
	if(n >= 1) {
		ll val = findMIN(q*8);
		choice(val,&n);
	}

	cout<<cost;newl;
}

int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}



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

int main(void)
{
    int n;
    cin >> n;
    if(n % 3 == 0){cout << n / 3 << endl;}
    else if(n < 3){cout << '0' << endl;}
    else{cout << n / 3  << endl;}
    return 0;
}

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

long long int MOD=1000000007;

long long int sigma[200001];

long long int inv(long long int t){
	long long int t2[36];
	t2[0]=1;t2[1]=t;
	for(int i=2;i<36;i++){
		t2[i]=(t2[i-1]*t2[i-1])%MOD;
	}
	long long int ans=1;
	long long int s=MOD-2;
	int i=1;
	while(s>0){
		if(s%2==1){ans=(ans*t2[i])%MOD;}
		s=s/2;i++;
	}
  return ans;
}

long long int C(long long int a,long long int b){
  if(a==b or b==0){return 1;}
	long long int ans=sigma[a];
	ans=(ans*inv(sigma[b]))%MOD;
	ans=(ans*inv(sigma[a-b]))%MOD;
	return ans;
}

int main(){
  sigma[0]=1;
for(long long int i=1;i<=200000;i++){
	sigma[i]=(sigma[i-1]*i)%MOD;
}
long long int ans=0;
long long int h,w,a,b;
cin>>h>>w>>a>>b;
while(a<h and b<w){
	ans=(ans+C(w+a-b-1,a)*C(h+b-a-1,b)%MOD)%MOD;
  	a++;b++;
}
cout<<ans<<endl;
}

Measured memory_bytes: 1920
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#include<bitset>
#include<vector>
#include <math.h>
#include <iomanip>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
#define inf 1000000007

signed main(){
    int n;cin>>n;
    int a[214514];
    int st[214514]={};
    rep(i,0,n)cin>>a[i];
    if(a[0]){
        cout<<-1<<endl;
        return 0;
    }
    rep(i,1,n){
        if(a[i-1]+1<a[i]){
            cout<<-1<<endl;
            return 0;
        }
    }
    int ans=0;
    rep(i,1,n){
        if(a[i]==0)continue;
        else if(a[i]==a[i-1]+1){
            st[i-a[i]]=a[i];
        }
        else if(a[i]<=i){
            if(st[i-a[i]]){
                cout<<-1<<endl;
                return 0;
            }
         else st[i-a[i]]=a[i];
        }
        else {
            cout<<-1<<endl;
            break;
        }
    }
    rep(i,0,n){
        ans+=st[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int main(){
	int count1=-1,count2=-1;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='A'&&count1==-1)count1=i;
		if(s[i]=='Z')count2=i;
	}
	cout<<count2-count1+1<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main(void){
    int R, n;
    
    cin >> n;

    int maxv = -1000000000;
    int minv;
    cin >> minv;
    
    for ( int i = 1; i < n; i++) {
        cin >> R;
        maxv = max(maxv, R - minv);
        minv = min(minv, R);
    }
    
    cout << maxv << "\n";
    
    return 0;
}

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

int main() {
  int s;
  cin >> s;
  
  vector<long long> ans(s+1);
  ans.at(0) = 1;
  long long cnt = 0, mod = pow(10, 9) + 7;
  for(int i = 3; i <= s; i++){
    cnt += ans.at(i-3);
    cnt %= mod;
    ans.at(i) = cnt;
  }
  
  cout << ans.at(s) << endl;
}

Measured memory_bytes: 3612
N,M = map(int,input().split())
nlis = []
for i in range(N):
    nlis.append(input())
mlis = []
for i in range(M):
    mlis.append(input())
k = N-M
for i in range(k+1):
    for j in range(k+1):
        l = []
        for o in range(M):
            l.append(nlis[i+o][j:j+M])
        if l == mlis:
            print('Yes')
            exit()
print('No')

Measured memory_bytes: 3064
import sys
from bisect import bisect_left
inpurt = sys.stdin.readline
a, b, q = map(int, input().split())
INF = 10 ** 11
s = [-INF] + [int(input()) for _ in range(a)] + [INF]
t = [-INF] + [int(input()) for _ in range(b)] + [INF]

for _ in range(q):
    xi = int(input())
    index_s = bisect_left(s, xi)
    s1 = xi - s[index_s - 1]
    s2 = s[index_s] - xi
    index_t = bisect_left(t, xi)
    t1 = xi - t[index_t - 1]
    t2 = t[index_t] -xi
    print(min(max(s1, t1), max(s2, t2), min(s1, t2) * 2 + max(s1, t2), min(s2, t1) * 2 + max(s2, t1)))


Measured memory_bytes: 12800
#include<iostream>
using namespace std;
int n;
main()
{
	while(cin>>n,n)
	{
		int cnt=0;
		for(int i=0;i*i<=n;i++)
		{
			for(int j=i;i*i+j*j<=n;j++)
			{
				for(int k=j;i*i+j*j+k*k<=n;k++)
				{
					for(int l=k;i*i+j*j+k*k+l*l<=n;l++)
					{
						cnt+=i*i+j*j+k*k+l*l==n;
					}
				}
			}
		}
		cout<<cnt<<endl;
	}
}



Measured memory_bytes: 3012
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n,k,x,y;
	cin >> n >> k >> x >> y;
	cout <<  (n-k>0 ? k : n)*x + y*(n-k>0 ? n-k : 0) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int A, B;
	cin >> A >> B;
	cout << 6 - A - B << endl;
}


Measured memory_bytes: 3640
N = input()
K = int(input())

l = len(N)

nozero = [0]*l
if N[0] != "0":
    nozero[0] = 1

for i in range(1, l):
    nozero[i] = nozero[i-1]
    if N[i] != "0":
        nozero[i] += 1 

dp0 = [[0]*2 for _ in range(l)]
dp1 = [[0]*2 for _ in range(l)]
dp2 = [[0]*2 for _ in range(l)]
dp3 = [[0]*2 for _ in range(l)]

for i in range(l):
    dp0[i][0] = 1

def dp(K):
    dps = [dp0, dp1, dp2, dp3]
    return dps[K]

dp(1)[0][0] = int(N[0])

for k in range(1, K+1):
    for i in range(l-1):
        if nozero[i] == k:
            dp(k)[i+1][0] = 1
        elif nozero[i] == k-1:
            dp(k)[i+1][0] = int(N[i+1])
        else:
            dp(k)[i+1][0] = 0
            
        if nozero[i] == k-1:
            dp(k)[i+1][1] += (sum(dp(k-1)[i])-1)*9
        else:
            dp(k)[i+1][1] += sum(dp(k-1)[i])*9

            
        if nozero[i] == k:
            dp(k)[i+1][1] += (sum(dp(k)[i])-1)*1
        else:
            dp(k)[i+1][1] += sum(dp(k)[i])*1

print(sum(dp(K)[l-1]))

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

int main(){
    int A,B,M;
    cin >> A >> B >> M;
    int a[A];
    for (int i=0; i<A; ++i) cin >> a[i];
    int b[B];
    for (int i=0; i<B; ++i) cin >> b[i];
    int m[M][3];
    for (int i=0; i<M; ++i) cin >> m[i][0] >> m[i][1] >> m[i][2];

    int minA = pow(10, 6);
    int minB = pow(10, 6);

    for(int i=0; i<A; ++i){
        if(a[i] < minA) minA = a[i];
    }

    for(int i=0; i<B; ++i){
        if(b[i] < minB) minB = b[i];
    }

    int ans = minA + minB;

    for(int i=0; i<M; ++i){
        int temp = a[m[i][0]-1]+b[m[i][1]-1]-m[i][2];
        if(temp < ans) ans = temp;
    }

    cout << ans << endl;
}

Measured memory_bytes: 2176
#include<cstdio>
#include<algorithm>
using namespace std;

int N, A[100];

void BubbleSort(){
	int cnt = 0;
	for(int i = 0; i < N; i++){
		for(int j = N - 1; j > i; j--){
			if(A[j] < A[j-1]){
				swap(A[j], A[j-1]);
				cnt++;
			}
		}
	}
	for(int i = 0; i < N; i++){
		printf("%d", A[i]);
		if(i == N - 1) printf("\n");
		else printf(" ");
	}
	printf("%d\n", cnt);
}

int main(void){
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		scanf("%d", &A[i]);
	}
	BubbleSort();
	return 0;
}

Measured memory_bytes: 2712
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] line = Stream.of(sc.nextLine().split(" ", 0)).mapToInt(Integer::parseInt).toArray();
		System.out.println(line[0] * line[1]);

	}


}


Measured memory_bytes: 36300
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long  
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int u=c+b-1;
    int uu=a+d-1;
    u/=b;
    uu/=d;
    if(u<=uu)
    {
        cout<<"Yes";
    }
    else
    cout<<"No";
    return 0;
}
//make all values ll

Measured memory_bytes: 3608
A, B, C, D, E, F = map(int, input().split())

maxStrength = 0
ansMass = 0
ansSugar = 0
for i in range(0, F+1, 100*A):
        for j in range(0, F-i+1, 100*B):
                for k in range(0, F-i-j+1, C):
                        for l in range(0, F-i-j-k+1, D):
                                a = i + j
                                b = k + l
                                mass = a + b
                                if (a / 100)*E >= b and mass <= F and mass != 0:
                                        strength = (100*b) / mass
                                        if strength >= maxStrength:
                                                maxStrength = strength
                                                ansMass = mass
                                                ansSugar = b

print(ansMass, ansSugar)


Measured memory_bytes: 3064
function main(input){

	var document = input[1].split(' ');
	var ary = document.filter(
		function(e) {
    		return e != ' '
    	}
    )

	var num = ary.map( str => parseInt(str, 10) );
  	var result = 'APPROVED';
 	for (var i = 0; i < num.length; i++) {
    	if (num[i]%2 === 0) {
        	if(!(num[i]%3 === 0 || num[i]%5 === 0)) {
            	result = 'DENIED';
            }
        }
    }
	console.log(result);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').split("\n"))

Measured memory_bytes: 11468
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> inline int Log2(T& x) {int k; for(k=0; (T(1)<<k)<=x; ++k); return k;} // number of binary digits


using Graph = vector<vector<int>>;

int main() {
  int N; cin >> N;
  Graph G(N);
  rep(i, N-1) {
    G[i].push_back(i+1);
    G[i+1].push_back(i);
  }
  int u, v;
  cin >> u >> v;
  u--; v--;
  G[u].push_back(v);
  G[v].push_back(u);

  Vll ans(N);

  rep(i, N) {
    int s = i;
    vector<int> dist(N, INF);
    queue<int> que;
    dist[s] = 0;
    que.push(s);
    while (!que.empty()) {
      int v = que.front(); que.pop();
      for (auto nv : G[v]) {
        if (chmin(dist[nv], dist[v] + 1)) {
          que.push(nv);
        }
      }
    }
    rep(i, N) ans[dist[i]]++;
  }

  rep2(i, 1, N) cout << (ans[i] / 2) << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,(e))
#define irp(i,s,e) for(int i=(s);i>(e);--i)
#define irpz(i,s) irp(i,(s),-1)
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T> T in(){T x;cin>>x;return x;}
// long long a = in<long long>();
template<class T> vector<T> inarr(int s,int e, T init){
	vector<T> v;T x;
	for(int i=0;i<s;++i)v.push_back(init);
	for(int i=s;i<e;++i){cin>>x;v.push_back(x);}
	return v;
}
// vi P = inarr<int>(0,N,0);
// vi P = inarr<int>(1,N+1,INT_MAX);
// vs P = inarr<int>(0,N,"");
template<class T>void outarr(int s,int e,vector<T> &V){
	for(int i=s;i<e;i++)cout<<V[i]<<(i<e-1?" ":"\n");
}
// outarr<int>(0,V.size(),V);
// outarr<ll>(0,V.size(),V);

// #define NMAX 1000000000
int N;
string S, T;
vi V;

bool ok(int l, int r){
	if(l>r) return false;
	l--;
	r--;
	while(l<r){
		if(S[l]!=S[r]){
			return false;
		}
		l++;
		r--;
	}
	return true;
}

string solve(){
	int n = S.size();
	if(!ok(1,n)){
		return "No";
	}
	if(!ok(1, (n-1)/2)){
		return "No";
	}
	if(!ok((n+3)/2, n)){
		return "No";
	}
	return "Yes";
}

int main(){
	cin>>S;
	cout<< solve() <<endl;
}


Measured memory_bytes: 256
import numpy as np
import math

n,k = map(int, input().split())

ans = 0
for i in range(n):
    if k <= i+1:
        ans += (1/n)
    else:
        tmp = math.ceil(np.log2(k/(i+1)))
        #print(tmp)
        ans += (1/n) * (1/2)**tmp

print(ans)


Measured memory_bytes: 17808
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
int ans;
int main(){
    ios::sync_with_stdio(false);
    cin >> s;
    for(int i=0;i<s.size();i++)
    	if(s[i]=='2')ans++;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
l,r = map(int,input().split())
setA = set()
num = r
for i in range(l,r):
    for j in range(i+1,r+1):
        next = (i*j)%2019
        if next not in setA:
            setA.add(next)
            if next ==0:
                print(0)
                exit()
        else:
            if len(setA)==2019:
                print(min(setA))
                exit()
# print(setA)
print(min(setA))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
  long int n,a,b=-1000000000,s,i;
  cin>>n>>s;
  for(a=s,i=1;i<n;i++){
    cin>>s;
    b=max(b,s-a);
    a=min(a,s);
  }
  cout<<b<<endl;
}

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

int main() {
  int N, A;
  cin >> N >> A;
  while(N >= 500){
    N -= 500;
    if(N == 0){
      cout << "Yes" << endl;
      return 0;
    }
  }
  for(int i = 0; i < A; i++){
    N -= 1;
    if(N == 0){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<iterator>
#include<algorithm>
#include<numeric>
using ifs = std::istream_iterator<int>; 
int main(){
	int n;
	std::cin >> n;
	auto v = std::vector<int>(ifs(std::cin),ifs());
	auto sum = std::accumulate(v.begin(),v.end(),0);
	auto sum2 = 0;
  	auto min = 1000000000;
	for (size_t i = 0; i < n; i++)
	{
		sum2 += v[i];
		auto sum3 = sum - sum2;
      	if(std::abs(sum2-sum3) > min)
          	break;
      	min = std::abs(sum2-sum3);
	}
  	std::cout << min;
}

Measured memory_bytes: 256
/**
                 MD.Faysal Hasan
                Comilla Univesity               **/

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

#define         rep(i,n)       for ( i=0 ; i<n ; i++ )
#define         rep1(i,n)      for ( i=1 ; i<=n ; i++ )
#define         sajo(str)      sort(str.begin(),str.end())
#define         rev(str)       reverse(str.begin(),str.end())
#define         usajo(str)     sort(str.rbegin(),str.rend())
#define         pi             2*acos(0.0)
#define         nel            printf("\n")
#define         longmx         92233720368547758
#define         gcd(a,b)       __gcd(a,b)
#define         lcm(a,b)       (a/gcd(a,b))*b
#define         yes            cout<<"YES"<<"\n"
#define         no             cout<<"NO"<<"\n"
#define         pb             push_back
#define         prl            pair< ll , ll >
#define         mkp(x,y)       make_pair(x,y)
#define         ff             first
#define         ss             second
#define         Faysal         ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef         long long int  lli;
typedef         long long      ll;

int main(){//Faysal

    int ans,sum,tot,cnt,mx,mn,idx,chk,rem,ret,tmp,mid,lft,rgt,pos;

    int tc,n,m,a,b,c,d,g,h,l,r,x,y,i,j,k;

    cin>>n;
    cout<<(n+1)/2<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <array>
#include <valarray>

using namespace std;

int main()
{
    int N;
    double D, X;
    scanf("%d %lf %lf\n", &N, &D, &X);
    double result = 0;
    for (; N > 0; --N){
        result += D + (N - 0.5) * X;
        D = ((N + 1.0) * D + 2.5 * X) / N;
        X = ((N + 2.0) * X) / N;
    }
    printf("%.9lf\n", result);
}


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

def find(x):
    if par[x]<0:
        return x
    else:
        par[x]=find(par[x])
        return par[x]

def union(x,y):
    x=find(x)
    y=find(y)
    
    if x==y:
        return False
    else:
        if par[x]>par[y]:
            x,y=y,x
        par[x]+=par[y]
        par[y]=x
        return True

def same(x,y):
    return find(x)==find(y)
    
def size(x):
    return -par[find(x)]

N,M=map(int,input().split())
par=[-1]*N
for _ in range(M):
    a,b,c=map(int,input().split())
    union(a-1,b-1)
ans=0
for i in par:
    if i<0:
        ans+=1
print(ans)

Measured memory_bytes: 76480
#include<cstdio>
#include<algorithm>

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

using namespace std;

const int INF=1<<29;

const int V_MAX=202;
const int E_MAX=2*100+100*100;

template<class T>
struct graph{
	int n,m,head[V_MAX],next[2*E_MAX],to[2*E_MAX];
	T capa[2*E_MAX],flow[2*E_MAX];

	void init(int N){
		n=N;
		m=0;
		rep(u,n) head[u]=-1;
	}

	void add_directed_edge(int u,int v,T ca){
		next[m]=head[u]; head[u]=m; to[m]=v; capa[m]=ca; flow[m]=0; m++;
		next[m]=head[v]; head[v]=m; to[m]=u; capa[m]= 0; flow[m]=0; m++;
	}

	void add_undirected_edge(int u,int v,T ca){
		next[m]=head[u]; head[u]=m; to[m]=v; capa[m]=ca; flow[m]=0; m++;
		next[m]=head[v]; head[v]=m; to[m]=u; capa[m]=ca; flow[m]=0; m++;
	}
};

int layer[V_MAX],now[V_MAX];

template<class T>
bool make_layer(const graph<T> &G,int s,int t){
	int n=G.n;
	rep(u,n) layer[u]=(u==s?0:-1);

	int head=0,tail=0;
	static int Q[V_MAX]; Q[tail++]=s;
	while(head<tail && layer[t]==-1){
		int u=Q[head++];

		for(int e=G.head[u];e!=-1;e=G.next[e]){
			int v=G.to[e];
			T capa=G.capa[e],flow=G.flow[e];

			if(capa-flow>0 && layer[v]==-1){
				layer[v]=layer[u]+1;
				Q[tail++]=v;
			}
		}
	}

	return layer[t]!=-1;
}

template<class T>
T augment(graph<T> &G,int u,int t,T water){
	if(u==t) return water;

	for(int &e=now[u];e!=-1;e=G.next[e]){
		int v=G.to[e];
		T capa=G.capa[e],flow=G.flow[e];

		if(capa-flow>0 && layer[v]>layer[u]){
			T w=augment(G,v,t,min(water,capa-flow));
			if(w>0){
				G.flow[ e ]+=w;
				G.flow[e^1]-=w;
				return w;
			}
		}
	}
	return 0;
}

template<class T>
T Dinic(graph<T> &G,int s,int t){
	int n=G.n;
	T ans=0;
	while(make_layer(G,s,t)){
		rep(u,n) now[u]=G.head[u];
		for(T water=1;water>0;ans+=water) water=augment(G,s,t,INF);
	}
	return ans;
}

int main(){
	for(int n,m,L;~scanf("%d%d%d",&n,&m,&L);){
		static int d[100][100];
		rep(u,n) rep(v,n) d[u][v]=(u==v?0:INF);
		rep(i,m){
			int u,v,cost; scanf("%d%d%d",&u,&v,&cost); u--; v--;
			d[u][v]=d[v][u]=cost;
		}

		int ini[100],cap[100];
		rep(u,n) scanf("%d",ini+u);
		rep(u,n) scanf("%d",cap+u);

		rep(k,n) rep(i,n) rep(j,n) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);

		int s=2*n,t=2*n+1;
		static graph<int> G;
		G.init(2*n+2);
		rep(u,n){
			G.add_directed_edge(s,2*u,ini[u]);
			G.add_directed_edge(2*u+1,t,cap[u]);
			rep(v,n) if(d[u][v]<L) G.add_directed_edge(2*u,2*v+1,INF);
		}
		printf("%d\n",Dinic(G,s,t));
	}

	return 0;
}

Measured memory_bytes: 1388
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <math.h>
#include <map>
#include <stack>
using namespace std;
static const int INF = 1e9+7;
// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i =a; i < b; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define PI 3.14159265359

int main(){
    int N; cin >> N;
    int T, A; cin >> T >> A;
    vector<int> H(N);

    int ans;
    int diff = 1000000000;
    rep(i, N){
        cin >> H[i];
        int tmp = abs((T*1000-H[i]*6) -  A*1000);
        if(tmp < diff){
            ans = i+1;
            diff = tmp;
        }
    }

    cout << ans << endl;

    return 0;
}


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

class THuman
{
public:
	void Move(int Distance);
	void Turn(int Degree);
	int GetIntegerPartX();
	int GetIntegerPartY();
	THuman();
private:
	double FX;
	double FY;
	int FDegree;
};

void THuman::Move(int Distance)
{
	FX += Distance * sin(FDegree * M_PI / 180);
	FY += Distance * cos(FDegree * M_PI / 180);
}

void THuman::Turn(int Degree)
{
	FDegree += Degree;
}

int THuman::GetIntegerPartX()
{
	double IntegerPartX;
	modf(FX, &IntegerPartX);
	return IntegerPartX;
}

int THuman::GetIntegerPartY()
{
	double IntegerPartY;
	modf(FY, &IntegerPartY);
	return IntegerPartY;
}

THuman::THuman()
{
	FX = 0;
	FY = 0;
	FDegree = 0;
}

int main()
{
	THuman Human;
	while(true){
		int Distance;
		int Degree;
		char Dummy;
		cin >> Distance >> Dummy >> Degree;
		if(Distance == 0 && Degree == 0) break;
		Human.Move(Distance);
		Human.Turn(Degree);
	}
	cout << Human.GetIntegerPartX() << endl << Human.GetIntegerPartY() << endl;
	return 0;
}

Measured memory_bytes: 3428
import java.util.Scanner;

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

        int c11 = sc.nextInt();
        int c12 = sc.nextInt();
        int c13 = sc.nextInt();
        int c21 = sc.nextInt();
        int c22 = sc.nextInt();
        int c23 = sc.nextInt();
        int c31 = sc.nextInt();
        int c32 = sc.nextInt();
        int c33 = sc.nextInt();
        
        int diff21 = c21 - c11;
        int diff31 = c31 - c11;
        
        if (c22 - c12 == diff21 && c23 - c13 == diff21 &&
            c32 - c12 == diff31 && c33 - c13 == diff31) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
using System;

class A
{
	static void Main()
	{
		var s = Console.ReadLine();
		int a = 0, ans = 0;
		for (int i = 0; i < s.Length; i++)
		{
			if (s[i] == 'R') a++;
			else a = 0;
			ans = Math.Max(ans, a);
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 25944
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (A, B): (i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };

    let ans = if A <= 9 && B <= 9 { A * B } else { - 1 };

    println!("{}", ans);
}

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

using namespace std;
const int MAXN = 1e5 + 7;
const int INF = 1e9 + 7;

int dp[MAXN][3], a[MAXN], b[MAXN], c[MAXN];
int n;

long long solve(int on, int last) {
  if(on == n) return 0;
  int &ans = dp[on][last];
  if(~ans) return ans;
  if(last == 0) return ans = max(b[on] + solve(on + 1, 1), c[on] + solve(on + 1, 2));
  if(last == 1) return ans = max(a[on] + solve(on + 1, 0), c[on] + solve(on + 1, 2));
  if(last == 2) return ans = max(a[on] + solve(on + 1, 0), b[on] + solve(on + 1, 1));
}

int main() {
  memset(dp, -1, sizeof(dp));
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d %d %d", &a[i], &b[i], &c[i]);
  }
  cout << max({a[0] + solve(1, 0), b[0] + solve(1, 1), c[0] + solve(1, 2)});
  return 0;
}

Measured memory_bytes: 7296
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, K = map(int, rl().split())
    if N % K == 0:
        print(0)
        exit()

    print(min(N % K, abs(N - K * (N // K + 1))))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
#include<iostream>
#include<stack>

bool listen_input(int &);

void exec_order(std::stack<int> &,const int);

//--------------------main-------------------------
int main()
{
	using namespace std;
	
	stack<int> carStop;
	
	int order;
	while(listen_input(order))
	{
		exec_order(carStop,order);
	}
	
	return 0;
}
//-------------------------------------------------

bool listen_input(int &order)
{
	using namespace std;
	
	cin>>order;
	if(cin.eof())
	{
		return false;
	}
	else
	{
		return true;
	}
}

void exec_order(std::stack<int> &carStop,const int order)
{
	using namespace std;
	
	if(order)
	{
		carStop.push(order);
	}
	else
	{
		cout<<carStop.top()<<endl;
		carStop.pop();
	}
}

Measured memory_bytes: 1200
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;

const int MAXN = 2e5 + 5;

int vis_1[MAXN + 5], vis_2[MAXN + 5];

int N, M;
int main()
{
	scanf("%d %d", &N, &M);
	for(int i = 1; i <= M; i++){
		int u, v;
		scanf("%d %d", &u, &v);
		if(u == N) vis_2[v] = 1;
		else if(v == N) vis_2[u] = 1;
		if(u == 1) vis_1[v] = 1;
		else if(v == 1) vis_1[u] = 1;
	}
	bool check = false;
	for(int i = 1; i <= N; i++){
		if(vis_1[i] == 1 && vis_2[i] == 1) check = true;
	}
	if(check) printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
}

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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define EPS (1e-5)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX 110000

int N;
// vector<pair<int,int>> fuga, hoge;
vector<pair<pair<int,int>,int>> fuga, hoge;
int used[MAX];
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(7);

	int ans1 = 0, ans2 = 0;
	
	cin>>N;
	
	fuga.resize(N);
	hoge.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>fuga[i].first .second>>hoge[i].first.second;
		fuga[i].first .first = fuga[i].first .second + hoge[i].first .second;
		hoge[i].first .first = hoge[i].first .second + fuga[i].first .second;
		fuga[i].second = i;
		hoge[i].second = i;
	}
	
	sort(fuga.begin(), fuga.end());
	sort(hoge.begin(), hoge.end());
	
	
	int taka = 0, aoki = 0;
	for(int i = 0, j = N-1, k = N-1; i < N; i++){//cout<<i<<endl;
		if(i%2 == 0){
			for(;used[fuga[j].second];)j--;
			taka += fuga[j].first .second;
			// cout<<"taka "<<j<<" "<<fuga[j].first .second<<" "<<fuga[j].first .first<<endl;;
			used[fuga[j].second] = true;
		} else {
			for(;used[hoge[k].second];)k--;
			aoki += hoge[k].first .second;
			// cout<<"aoki "<<k<<" "<<hoge[k].first .second<<" "<<hoge[k].first .first<<endl;
			used[hoge[k].second] = true;
		}
	}
	ans1 = taka-aoki;
	
	cout<<ans1<<endl;
	
	
	return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
/**  I'm Klaus, NicKlaus :v **/
using namespace std;
#define ms(a,v) memset(a,v,sizeof a)
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define LOG2(X) ((unsigned) (8*sizeof(int) - __builtin_clz((X)) - 1))
ll gcd(ll x, ll y){return (y ? gcd(y, x%y) : x); }
ll lcm(ll x, ll y){return x*(y/gcd(x,y));}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int n;
int go(int i, int a, int b){
	if(i == n+1) return abs(a-b);
	return min(go(i+1, a+i, b),go(i+1,a,b+i));
}
int main(){
	//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	#ifdef LOCAL_JUDGE
		//freopen("in_out/in.txt", "rt", stdin);
		//freopen("int_out/out.txt", "wt", stdout);
	#endif
	int a, b;
	cin>>a>>b;
	int ans = 1;
	int inx = 0;
	for(int i=0; ans < b; i++){
		ans--;
		ans += a;
		inx++;
	}
	cout<<inx<<endl;
	return 0;
}


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

int DIV2(int n)
{
    int ctr = 0;
    
    while(n%2 == 0)
    {
        n = n/2;
        
        ctr++;
    }
    
    return ctr;
}

int main(void)
{
    int N, a;
    char c;
    int i;
    int ctr = 0;
    
    
    scanf("%d%c", &N, &c);
    
    for(i=0; i<N; i++)
    {
        scanf("%d%c", &a, &c);
        
        ctr += DIV2(a);
    }
    
    printf("%d\n", ctr);

    //system("pause");
    
    return 0;
}


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

int main(){
  ll a,b;
  int k,n=0;
  cin >> a >> b >> k;
  while(k--){
    if(n%2==0){
      if(a%2==1){
        b+=a/2;
        a=a-a/2-1;
      }
      else{
        b+=a/2;
        a/=2;
      }
    }
    else{
      if(b%2==1){
        a+=b/2;
        b=b-b/2-1;
      }
      else{
        a+=b/2;
        b/=2;
      }
    }
    n++;
  }
  cout << a <<" " << b << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

// C - Fennec vs Monster
// https://atcoder.jp/contests/abc153/tasks/abc153_c
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int K = Integer.parseInt(scanner.next());
        Long[] H = new Long[N];
        for (int i = 0; i < N; i++) {
            H[i] = Long.parseLong(scanner.next());
        }
        scanner.close();

        // HPの高い順に必殺技を使いたいのでHPの降順にする
        Arrays.sort(H, Collections.reverseOrder());

        long attackCount = 0;
        for (int i = K; i < N; i++) {
            attackCount += H[i];
        }

        System.out.println(attackCount);
    }
}


Measured memory_bytes: 66088
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
#define fi first
#define se second
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

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

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
	if(y<=0) return 1;
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

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

//const ll N = 1e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<<fixed<<setprecision(10);


	char x;
	cin>>x;
	if('a'<=x && x<='z') cout<<'a';
	else cout<<'A';


    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  string S, T;
  cin >> S >> T;
  int U[26], V[26];
  for(int i=0; i<26; i++) {
    U[i] = -1;
    V[i] = -1;
  }
  bool ans = true;
  for(int i=0; i<S.size(); i++) {
    int tmp_s = (int)S[i]-(int)'a';
    int tmp_t = (int)T[i]-(int)'a';
    if(U[tmp_s] < 0) {
      U[tmp_s] = i;
    } else if(T[U[tmp_s]] != T[i]) {
      ans = false;
      break;
    }
    if(V[tmp_t] < 0) {
      V[tmp_t] = i;
    } else if(S[V[tmp_t]] != S[i]) {
      ans = false;
      break;
    }
  }
  if(ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

typedef struct{
  int x;
  int y;
}dir;

int map[21][21];
dir ds[4]={{0,1},{-1,0},{0,-1},{1,0}};

int d2n(char dir){
  return dir=='N'?0:dir=='W'?1:dir=='S'?2:3;
}

int main(){
  int x,y,n,gn,i,st,step,count,j;
  char dir,str[29],*s;
  st=0;
  do{
    fgets(str,29,stdin);
    gn=atoi(str);
    if(gn==0) break;
    st++;
    for(i=0;i<gn;i++){
      fgets(str,29,stdin);
      s=strchr(str,' ');
      *s='\0';
      x=atoi(str);
      y=atoi(s+1);
      map[y][x]=st;
    }
    x=y=10;
    count=(map[y][x]==st)?1:0;
    fgets(str,29,stdin);
    n=atoi(str);
    for(i=0;i<n;i++){
      fgets(str,29,stdin);
      dir=str[0];
      step=atoi(str+2);
      for(j=0;j<step;j++){
	x+=ds[d2n(dir)].x;
	y+=ds[d2n(dir)].y;
	if(map[y][x]==st){
	  count++;
	  map[y][x]=0;
	}
      }
    }
    printf("%s\n",(count==gn)?"Yes":"No");
  }while(1);
  return 0;
}

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

int main(){
    string s;   cin>>s;
    string t="";
    int a=0;

    bool flag=false;

    for(int i=s.length()-1;i>=0;i--){
        a++;
        t+=s[i];
        //cout<<t<<endl;
        if(a>=5){
            if(t=="esare"||t=="resare"||t=="remaerd"||t=="maerd"){
                a=0;
                t="";
                flag=true;
            }else{
                flag=false;
            }
        }
    }

    flag? cout<<"YES"<<endl : cout<<"NO"<<endl;


    return 0;
}


Measured memory_bytes: 512
import sys

ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: [int(x) for x in ns().split()]
nall = lambda: [int(x) for x in sys.stdin.readlines()]

def main():
    a, b = na()
    for c in [1,2,3]:
        if a * b * c % 2 == 1 :
            print('Yes')
            return

    print('No')

main()


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int A, B, C;
    cin >> A >> B >> C;
    int ans = C - (A - B);
    cout << (ans > 0 ? ans : 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 120000 + 10;
int main(){
	int n,f=1;
	int a[maxn];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	if(n==1){
		cout<<"Yes";
	}
	else{
		a[0]--;
		for(int i=1;i<n;i++){
			if(a[i]>a[i-1]){
				a[i]--;
			}
			else if(a[i]<a[i-1]){
				f=0;
				break;
			}
		}
		if(f){
			cout<<"Yes";
		}
		else{
			cout<<"No";
		}
	}
}

Measured memory_bytes: 640
h,w=map(int,input().split())
c=[]
for i in range(10):
	c.append(list(map(int,input().split())))
a=[]
ans=0
for i in range(h):
	a.append(list(map(int,input().split())))
for i in range(10):
    for j in range(10):
        for k in range(10):
            c[j][k]=min(c[j][k],c[j][i]+c[i][k])
for j in range(h):
	for k in range(w):
		if a[j][k]==-1:
			continue
		else:
			ans+=c[a[j][k]][1]
print(ans)
					


Measured memory_bytes: 3316
from fractions import gcd

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

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

a = 0
b = A[0]
while b % 2 == 0:
  a += 1
  b = b//2
  
for i in range(1,N):
  if A[i] % (2**a) != 0 or A[i] % (2**(a+1)) == 0:
    print(0)
    exit()

c = A[0]
for i in range(N-1):
  c = lcm(c,A[i+1])

print((M+c//2)//c)

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    for(int i = 0; i < N; i++){
      cin >> A.at(i);
      B.at(i) = A.at(i);
    }

    sort(A.begin(),A.end());
  
  	A.push_back(0);

    vector<long long> P(0);
    vector<long long> Q(N + 1);


    int j = 0;
    long long k = 1;

    while(j < N){
        if(A.at(j) == A.at(j + 1)){
            j++;
            k++;
            continue;
        }else{
            P.push_back(k * (k - 1)/2);
          	Q.at(A.at(j)) = k;
            k = 1;
            j++;
        }
    }
  
  long long bef = 0;
  for(int i = 0; i < P.size(); i++) bef += P.at(i);

  for(int i = 0; i < B.size(); i++){
  	cout << bef - Q.at(B.at(i)) + 1 << endl;
  }
}


Measured memory_bytes: 8432