akhauriyash/Code-Regression huggingface dataset:
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    a=[parseInt(readline()) for i in 1:n]
    ans=-1
    now=1
    cnt=0
    for i in 1:n
        now=a[now]
        cnt+=1
        if now==2
            ans=cnt
            break
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 183028
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b) {if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b) {if(a<b) a=b;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    int ans = 0;
    vector<int> h(n);
    REP(i,n) {
        cin >> h[i];
        ans += (h[i]>=k);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;

    int M_N = M / N;

    for (int i = 0; ; i++) {
        int D = M_N - i;
        if (M % D == 0) {
            cout << D << endl;
            return 0;
        }
    }

    return 0;
}


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

int main()
{
	int a, b;
	cin >> a >> b;
	int K = 0;
	if (a > b) {
		K--;
	}
	cout << a + K << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define elnd endl //* missspell check

void solve(long long H, long long W, std::vector<std::vector<long long>> a){
    ll i=0, j=0, idx=0;
    vector<pll> B(H*W);
    while(i < H && j < W){
        B[idx] = make_pair(i, j);
        if((i % 2) == 0){
            if(j < W-1)
                j++;
            else{
                i++;
            }
        }
        else{
            if(j > 0)
                j--;
            else{
                i++;
            }
        }
        idx++;
    }
    
    idx = 0;
    vector<vll> record;
    while(idx < H*W-1){
        auto p = B[idx];
        if(a[p.first][p.second] %2){
            auto q = B[idx+1];
            vll tmp;
            tmp.push_back(p.first); tmp.push_back(p.second); tmp.push_back(q.first); tmp.push_back(q.second); 
            record.push_back(tmp);
            a[q.first][q.second]++;
        }
        idx++;
    }
    cout << record.size()<<endl;
    REP(i, record.size()){
        cout << record[i][0]+1 << " " << record[i][1]+1 << " " << record[i][2]+1 << " " << record[i][3]+1 << endl;
    }
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    std::vector<std::vector<long long>> a(H, std::vector<long long>(W));
    for(int i = 0 ; i < H ; i++){
        for(int j = 0 ; j < W ; j++){
            scanf("%lld",&a[i][j]);
        }
    }
    solve(H, W, std::move(a));
    return 0;
}


Measured memory_bytes: 18736
#define _CRT_SECURE_NO_WARNINGS 0
#include<stdio.h>
#include<stdlib.h>

void prob_A(void);
void prob_B(void);
void prob_C(void);

int main(void) {

	prob_B();
	return 0;

}


//A問題
void prob_A() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);

	if ((a + b == c) || (b + c == a) || (c + a == b)) {
		printf("Yes");
	}
	else {
		printf("No");
	}
}

//B問題
void prob_B() {
	int w, h, n;
	int x, y,a;
	int **rect;
	int count = 0;

	//1行目の入力
	scanf("%d %d %d", &w, &h, &n);
	
	//メモリの確保・初期化
	rect = (int **)malloc(sizeof(int*)*w);
	for (int i = 0; i < w; i++) {
		rect[i] = (int *)malloc(sizeof(int)*h);
	}
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < h; j++) {
			rect[i][j] = 1;
		}
	}

	//2行目以降の入力に対する処理
	//黒い部分の要素は0以外にする．
	for (int i = 0; i < n; i++) {
		scanf("%d %d %d", &x, &y, &a);
		if (1 == a) {
			for (int j = 0; j < x; j++) {
				for (int k = 0; k < h; k++) {
					rect[j][k] = 0;
				}
			}
		}
		else if (2 == a) {
			for (int j = x; j < w; j++) {
				for (int k = 0; k < h; k++) {
					rect[j][k] = 0;
				}
			}
		}
		else if (3 == a) {
			for (int j = 0; j < y; j++) {
				for (int k = 0; k < w; k++) {
					rect[k][j] = 0;
				}
			}
		}
		else if (4 == a) {
			for (int j = y; j < h; j++) {
				for (int k = 0; k < w; k++) {
					rect[k][j] = 0;
				}
			}
		}
	}
	
	//白い部分の面積の計算
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < h; j++) {
			count += rect[i][j];
//			printf("%d ", rect[i][j]);
		}
//		printf("\n");
	}

	//結果の出力
	printf("%d", count);

	//メモリ開放
	for (int i = 0; i < w; i++) {
		free(rect[i]);
	}
	free(rect);
}

//C問題


Measured memory_bytes: 256
x,y = map(int,input().split())
A = {1,3,5,7,8,10,12}
B = {4,6,9,11}
C = {2}
if x in A:
  if y in A:
    print('Yes')
  else:
    print('No')
elif x in B:
  if y in B:
    print('Yes')
  else:
    print('No')
else:
  print('No')

Measured memory_bytes: 3064
#include<stdio.h>
void funk(int,int);
int a,b;
char kuda[101][101],ku;
int main(void)
{
	int i,m,ka;
	
	while(1){
		ka=0;
		scanf("%d %d",&a,&b);
		if(a==0 && b==0){break;}
		else{
			for(i=0;i<a;i++){
					scanf("%s",kuda[i]);
			}
			for(i=0;i<a;i++){
				for(m=0;m<b;m++){
					if(kuda[i][m]=='@' || kuda[i][m]=='#' || kuda[i][m]=='*'){
							ku=kuda[i][m];
							ka++;
							kuda[i][m]='^';
//							printf("aaa\n");
							funk(i,m);
					}
				}
			}
			printf("%d\n",ka);
		}
	}
}	
void funk(int i,int m)
{
	//printf("i=%d m=%d\n",i,m);
	int kx[4]={0,1,0,-1},ky[4]={1,0,-1,0};
	int kkx,kky,j;
	//printf("aaaaaa\n");
	for(j=0;j<4;j++){
		kky=i+ky[j];
		kkx=m+kx[j];
		if(kkx>=0 && kkx<b && kky>=0 && kky<a && kuda[kky][kkx]==ku){
			kuda[kky][kkx]='^';
			funk(kky,kkx);
		}
	}
}

Measured memory_bytes: 1660
#include <iostream>
int main(){
  int a,b,c;
  std::cin>>a>>b>>c;
  int coin = 0;
  int day = 0;
  while(coin < c){
    day += 1;
    coin += a;
    if(day%7==0){
      coin += b;
    }
  }
  std::cout<<day<<"\n";
}


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

int main() {
	// your code goes here
	int a,b,ans;
	cin >> a >> b;
	if(a>=13) cout << b << endl;
	if(a<=12&&a>=6) cout << b/2 << endl;
	if(a<=5) cout << "0" << endl;
	return 0;
}

Measured memory_bytes: 764
#include <stdio.h>
#include <iostream>

using namespace std;

int main() {
	int x[5];
	int ans;

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

	for (int i = 0; i < 5; i++) {
		if (x[i] == 0) {
			ans = i + 1;
		}
	}

	cout << ans;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int64_t ans = 0, left, right;
  cin >> left;
  for (int i = 1; i < n; i++) {
    cin >> right;
    if(left > right) {
      ans += (left - right);
    }else {//left <= right
      left = right;
    }
  }
  cout << ans;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

const string YES = "Yes";
const string NO  = "No";

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

    int a, b, c, d;

    cin >> a >> b >> c >> d;

    if (abs(c - a) <= d || (abs(a - b) <= d && abs(c - b) <= d)) {
        cout << YES;
    } else {
        cout << NO;
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int main(){
    string S; cin>>S;
    if(S=="SUN")
        cout<<"7";
    else if(S=="MON")
        cout<<"6";
    else if(S=="TUE")
        cout<<"5";
    else if(S=="WED")
        cout<<"4";
    else if(S=="THU")
        cout<<"3";
    else if(S=="FRI")
        cout<<"2";
    else
        cout<<"1";

  return 0;

 }

Measured memory_bytes: 256
from bisect import*
s=input()
t=input()
n=len(s)
d=dict(zip([chr(i+97) for i in range(26)],[[] for _ in range(26)]))
for i,j in enumerate(s,1):
  d[j]+=[i]
ans=0
cnt=0
for i in t:
  if d[i]:
    j=bisect(d[i],ans)
    if j==len(d[i]):
      cnt+=1
      ans=d[i][0]
    else:ans=d[i][j]
  else:
    cnt,ans=0,-1
    break
print(cnt*n+ans)

Measured memory_bytes: 80144
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<limits.h>
#include<math.h>

int main(void){
	int a,b;

	scanf("%d%d",&a,&b);
	if(a+b==15)
		printf("+\n");
	else if(a*b==15)
		printf("*\n");
	else
		printf("x\n");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
vector <long long > v,v1;
char arr[100][100];
string s[10000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    long long i,j,k,x,y,z,n,m,a,b,c,l,xxx;
    cin>>n>>m>>k;
    for (i=0;i<200;i++)
    {
    	s[i]="000000";
	}
	for (i=1;i<200;i+=2)
	{
		s[i][5]='1';
	}
	for (i=2;i<200;i+=4)
	{
		for (j=0;j<2;j++)
		{
			s[i+j][4]='1';
		}
	}
	for (i=4;i<200;i+=8)
	{
		for (j=0;j<4;j++)
		{
			s[i+j][3]='1';
		}
	}
	for (i=8;i<200;i+=16)
	{
		for (j=0;j<8;j++)
		{
			s[i+j][2]='1';
		}
	}
	for (i=16;i<200;i+=32)
	{
		for (j=0;j<16;j++)
		{
			s[i+j][1]='1';
		}
	}
	for (i=32;i<200;i+=64)
	{
		for (j=0;j<32;j++)
		{
			s[i+j][0]='1';
		}
	}
	
	y=0;
    for (i=0;i<n;i++)
    {
    	for (j=0;j<m;j++)
    	{
    		cin>>arr[i][j];
    		if (arr[i][j]=='#')
    		{
    			y++;
			}
		}
	}
	for (i=0;i<n;i++)
	{
		x=0;
		for (j=0;j<m;j++)
		{
			if (arr[i][j]=='#')
			{
				x++;
			}
		}
		v.push_back(x);
	}
	for (i=0;i<m;i++)
	{
		x=0;
		for (j=0;j<n;j++)
		{
			if (arr[j][i]=='#')
			{
				x++;
			}
		}
		v1.push_back(x);
	}	
	a=1;
	for (i=0;i<n;i++)
	{
		a=a*2;
	}
	b=1;
	for (i=0;i<m;i++)
	{
		b=b*2;
	}
	string s1,s2;z=0;
	for (i=0;i<a;i++)
	{
		x=y;
		s1=s[i].substr((6-n),n);
		//cout<<s1<<endl;
		for (j=0;j<v.size();j++)
		{
			if (s1[j]=='1')
			{
				x-=v[j];
			}
		}
		if (x<k)
		{
			continue;
		}
		xxx=x;
		for (j=0;j<b;j++)
		{
			x=xxx;
			s2=s[j].substr((6-m),m);
			for (l=0;l<v1.size();l++)
			{
				if (s2[l]=='1')
				{
					x-=v1[l];
					//cout<<x<<endl;
					for (c=0;c<s1.length();c++)
					{
						if (s1[c]=='1' && arr[c][l]=='#')
						{
							x++;
						}
					}
				}
			}
			if (x==k)
			{
				z++;
			}
		}

	}
	cout<<z<<endl;
}

Measured memory_bytes: 3924
#include<bits/stdc++.h>
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define nd second
#define st first
using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vl=vector<ll>;
using mii=map<int,int>;
using si=set<int,int>;
using vpi=vector<pii>;
using vpl=vector<pll>;

const int N=(int)1e5+5;

int n,m,a,b,c,q,W;
ll dp[N];
vpi V;

int R(int l, int p){
	return rand()%(p-l+1)+l;
}

void wczytaj(){
	cin>>n>>W;
	for (int i=0; i<n; ++i){
		cin>>a>>b;
		V.pb({a,b});
	}
	sort(V.begin(),V.end());
}

void solve(){
	for (pii p:V){
		for (int i=W; i>=0; --i){
			if (p.st<=i){
				dp[i]=max(dp[i], dp[i-p.st]+p.nd);
			}
		}
	}
	cout<<dp[W]<<'\n';
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int ilosc_przypadkow_testowych=1;
//	cin>>ilosc_przypadkow_testowych
	for (int i=1; i<=ilosc_przypadkow_testowych; ++i){
		wczytaj();
		solve();
	}
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
  int i,n,a=1;
  cin>>n;
  queue<int> q;
  while(n--)a*=2;
  n=a;
  rep(i,n){
    cin>>a;
    q.push(a);
  }
  while(q.size()>1){
    int x=q.front();
    q.pop();
    int y=q.front();
    q.pop();
    if(x==y)q.push(x);
    else q.push(max(x,y)-min(x,y));
  }
  cout<<q.front()<<endl;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i,n) for(int i=(int)(n)-1; i>=0; i--)
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define pr(a) cout << (a) << endl
#define PR(a,b) cout << (a) << " " << (b) << endl
#define F first
#define S second
typedef long long ll;
typedef pair<int,string> P;
const int MAX=1000000001;
const ll MAXL=1000000000000000001LL;
const ll mod=1000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main() {
  int n;
  while(cin >> n && n) {
    P a[n];
    fill(a,a+n,P(0,""));
    rep(i,n) {
      cin >> a[i].S;
      rep(j,8) {
	int x;
	cin >> x;
	if(j%2) a[i].F+=x;
	else a[i].F+=x*60;
      }
    }
    sort(a,a+n);
    pr(a[0].S);
    pr(a[1].S);
    pr(a[n-2].S);
  }
  return 0;
}


Measured memory_bytes: 1520
# from fractions import gcd
# gcd = __import__("fractions").gcd

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

N, X = map(int, input().split())
V = list(map(int, input().split()))
V.append(X)
V.sort()
vD = [V[i+1]-V[i] for i in range(len(V)-1)]
vD.sort()

res = vD[0]
for d in vD:
    res = gcd(res, d)
    if res <= 1:
        break
print(res)

Measured memory_bytes: 64024
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int main(){
        ios::sync_with_stdio(false);    
        cin.tie(0);
        int n;
        int temp;
        int s;
        cin>>n;
        s = n;
        int array[n] = {0};
        while(--n){
        	cin>>temp;
        	array[temp-1]++;
		}
		for(int i=0; i<s; i++){
			cout<<array[i]<<endl;
		}

        return 0;

}

Measured memory_bytes: 4440
#include <stdio.h>

int main(void){
  int n;
  int i,j;
  int p[4001];
  int ans;
  for(i=0;i<=4000;i++) p[i]=0;
  for(i=0;i<=1000;i++){
    for(j=0;j<=1000;j++){
      p[i+j]++;
    }
  }
  while(scanf("%d",&n)!=EOF){
    ans=0;
    for(i=0;i<=n;i++){
      ans+=(p[i]*p[n-i]);
    }
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 612
def modPow(a, n, mod):
  if n == 1:
    return a % mod
  if n%2 == 1:
    return (a * modPow(a, n - 1, mod)) % mod
  t = modPow(a, n / 2, mod)
  return (t * t) % mod

def comb(n, r, mod):
  r = min(r, n-r)
  x = 1
  y = 1
  for i in range(1, r+1):
    x = x * (n+1-i) % mod
    y = y * i % mod
  return x * modPow(y, mod-2, mod) % mod

  
n, a, b = map(int, input().split())
mod = 10**9+7
ans = modPow(2, n, mod)-1
aa = comb(n, a, mod)
bb = comb(n, b, mod)

print((ans-aa-bb)%mod)


Measured memory_bytes: 3064
//
// Created by Jaikirat Sandhu on 16/06/18.
//

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

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

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

    if(D == 0) {
        if(N == 100) {
            cout << 101 << endl;
        }else {
            cout << N << endl;
        }
    }else if(D == 1) {
        if(N == 100) {
            cout << "10100" << endl;
        }else {
            cout << N*100 << endl;
        }
    }else if(D == 2) {
        if(N == 100) {
            cout << "1010000" << endl;
        }else{
            cout << N*10000 << endl;
        }
    }
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import bisect

def solve(N: int, L: "List[int]"):
    L.sort()
    answer = 0
    for i in range(N):
        for j in range(i+1,N):
            max_k = bisect.bisect_left(L,L[i]+L[j])
            answer += max_k-(j+1)
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, L)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
 

int main() {
	// 入力
	ll N,Z,W;
	cin >> N>>Z>>W;
	ll a[N];
	for (ll i = 0; i < N; ++i) cin >> a[i];
 
	// 解法
	// Xが最後の札を取る場合
	ll score;
	if (N==1){
		score = abs(a[0]-W);
	}
	else{
		ll X1 = a[N-1]; // Xが全部引く
		ll score1 = abs(X1-W);
		ll X2 = a[N-2]; // Xが1枚残す
		ll Y2 = a[N-1];
		ll score2 =abs(X2 - Y2);
		score = max(score1, score2);
	}
	
	//出力
	cout << score << endl;
}


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


void solve(long long a, long long b){
  long long n = abs(a - b)-1;

  cout << (((n*(n+1))/2)-a) << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long a;
  scanf("%lld",&a);
  long long b;
  scanf("%lld",&b);
    solve(a, b);
    return 0;
}


Measured memory_bytes: 3776
using System;

class A{
	public static void Main(){

		string[] input = Console.ReadLine ().Split (' ');
		int a = int.Parse (input [0]);
		int b = int.Parse (input [1]);



		Console.WriteLine ("{0} {1} {2:F7}", a/b, a%b, a/ (double)b);
	}
}

Measured memory_bytes: 9144
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
int s;
const char* sixteen="0123456789abcdef";
ll num[10];

int main(void){
	scanf("%d",&s);
	for(int ddd=0;ddd<s;ddd++){
		for(int i=0;i<9;i++){
			num[i]=0;
			string str;
			cin >> str;
			for(int j=0;j<str.size();j++){
				if(str[j]>='a' && str[j]<='f')num[i]=(ll)num[i]*16+str[j]-'a'+10;
				if(str[j]>='0' && str[j]<='9')num[i]=(ll)num[i]*16+str[j]-'0';
			}
		}
		ll res=0;
		ll p=1;
		int cnt=0;
		for(int i=0;i<32;i++){
			int cnt2=0;
			for(int i=0;i<8;i++){
				if(num[i] & 1)cnt2++;
				num[i]>>=1;
			}
			if((cnt2+cnt%2)%2!=(num[8] & 1)){
				res=res+p;
				cnt2=8-cnt2;
			}
			p<<=1;
			cnt=(cnt+cnt2)/2;
			num[8]>>=1;
		}
		string restr="";
		while(res>=0){
			restr+=sixteen[res%16];
			res/=16;
			if(res==0)break;
		}
		reverse(restr.begin(),restr.end());
		cout << restr << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
#[allow(unused_imports)]
use proconio::{input, marker::*};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

macro_rules ! min { ( $ x : expr ) => ( $ x ) ; ( $ x : expr , $ ( $ z : expr ) ,+ ) => { { std :: cmp :: min ( $ x , min ! ( $ ( $ z ) ,* ) ) } } }

fn main() {
    input! {
        n: usize,
        a: [usize; n+1],
    }

    if n == 0 && a[0] != 1 {
        println!("-1");
        return;
    }

    let mut vec = vec![0; n + 1];
    vec[0] = 1;
    for i in 0..n {
        if vec[i] <= a[i] {
            println!("-1");
            return;
        }
        vec[i + 1] = (vec[i] - a[i]).saturating_mul(2);
    }
    if vec[n] < a[n] {
        println!("-1");
        return;
    }
    let mut sum = 0;
    let mut s = 0;
    for i in (0..n + 1).rev() {
        s += a[i];
        sum += min!(vec[i], s);
    }
    println!("{}", sum);
}


Measured memory_bytes: 4344
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = nk[0];
            var k = nk[1];

            var p = Console.ReadLine().Split().Select(double.Parse).ToList();

            var Ep = new double[n];
            for (int i = 0; i < n; i++) 
            {
                Ep[i] = (p[i] + 1) / 2;
            }

            var sum = 0.0;
            for(int i = 0; i< k; i++)
            {
                sum += Ep[i];
            }

            var ans = sum;
            
            for(int i = 0; i < n - k; i++)
            {
                sum += Ep[k + i] - Ep[i];
                if(sum > ans)
                {
                    ans = sum;
                }
            }
            Console.WriteLine(ans); 
        }
    }
}


Measured memory_bytes: 43608
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

struct Dscc {
public:

	//fst:belongs , scd:newedges
	pair<vector<vector<int>>, vector<vector<int>>>get(const vector<vector<int>>&edges) {
		nums.resize(edges.size());
		fill(nums.begin(), nums.end(), -1);
		vector<vector<int>>revedges(edges.size());
		for (int i = 0; i < edges.size(); ++i) {
			for (auto j : edges[i]) {
				revedges[j].push_back(i);
			}
		}
		int num = 0;
		for (int i = 0; i < edges.size(); ++i) {
			dfs(i, num, edges);
		}
		vector<int>big(nums.size());
		for (int i = 0; i < nums.size(); ++i) {
			big[nums[i]] = i;
		}
		reverse(big.begin(), big.end());
		unis.resize(edges.size());
		fill(unis.begin(), unis.end(), -1);
		num = 0;
		for (int i = 0; i < big.size(); ++i) {

			dfs2(big[i], num, revedges);
			num++;
		}
		vector<int>nums;
		for (int i = 0; i < unis.size(); ++i) {
			nums.push_back(unis[i]);
		}
		sort(nums.begin(), nums.end());
		nums.erase(unique(nums.begin(), nums.end()), nums.end());


		map<int, int>mp;
		for (int i = 0; i < nums.size(); ++i) {
			mp[nums[i]] = i;
		}
		for (int i = 0; i < unis.size(); ++i) {
			unis[i] = mp[unis[i]];
		}

		vector<vector<int>>belongs(nums.size());
		for (int i = 0; i < unis.size(); ++i) {
			belongs[unis[i]].push_back(i);
		}
		vector<vector<int>>newedges(nums.size());
		for (int i = 0; i < edges.size(); ++i) {
			for (auto j : edges[i]) {
				if (unis[i] != unis[j]) {
					newedges[unis[i]].push_back(unis[j]);
				}
			}
		}
		return make_pair(belongs, newedges);
	}
private:
	vector<int>nums;
	vector<int>unis;


	void dfs(const int id, int &num, const vector<vector<int>>&edges) {
		if (nums[id] != -1)return;
		else {
			nums[id] = -2;
			for (auto i : edges[id]) {
				dfs(i, num, edges);
			}
		}
		nums[id] = num++;
		return;
	}
	void dfs2(const int id, const int &num, const vector<vector<int>>&edges) {
		if (unis[id] != -1)return;
		else {
			unis[id] = -2;
			for (auto i : edges[id])
				dfs2(i, num, edges);
		}
		unis[id] = num;
		return;
	}

}dscc;

int main() {	
	int W,H,N;cin>>W>>H>>N;
	vector<vector<int>>ops(H);
	map<int,int>xs;
	for (int i = 0; i < N; ++i) {
		int x,y;cin>>x>>y;
		ops[y].push_back(x);
		xs[x]++;
	}
	int ans=min(H,W);
	for (int i = 0; i < H; ++i) {
		for (auto x : ops[i]) {
			xs[x]--;
			if (xs[x] == 0) {
				xs.erase(x);
			}
		}
		if (xs.empty()) {
			ans=min(ans,i);
		}
		else {

			int max_x = prev(xs.end())->first;
			ans = min(ans, i + max_x);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 10156
S = input()

def AtoZ(s):
    for front in range(0,len(s)):
        if s[front] == "A":
            break
    for back in range(0,len(s))[::-1]:
        if s[back] == "Z":
            break
    ans = back - front + 1
    return ans

ans = AtoZ(S)
print(ans)


Measured memory_bytes: 3516
#include <bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char>> s(h+2,vector<char>(w+2));
  for (int i=0;i<h+2;i++){
    for (int j=0;j<w+2;j++){
      s[i][j]='#';
    }
  }
  for (int i=0;i<h;i++){
    for (int j=0;j<w;j++){
      cin >> s[i+1][j+1];
    }
  }
  for (int i=0;i<h+2;i++){
    for (int j=0;j<w+2;j++){
      cout << s[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
s = input()

a = False
for i in range(len(s)):
    if s[i] == "A":
        a = True
        break

b = False
for i in range(len(s)):
    if s[i] == "B":
        b = True
        break

if a and b:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;
int main(int argc, char const *argv[]) {
  string s;std::cin >> s;
  string ans = "";
  ans += s[0] + to_string(s.size()-2) + s[s.size()-1];
  std::cout << ans << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<vector<int>> vec(N,vector<int>(3));
  for(int i=0; i<N; i++){
    for(int j=1; j<3; j++){
      cin >> vec.at(i).at(j);
    }
    vec.at(i).at(0) = vec.at(i).at(1) + vec.at(i).at(2);
  }
  sort(vec.rbegin(),vec.rend());
  
  int64_t takahashi = 0;
  int64_t aoki = 0;
  for(int i=0; i<N; i++){
    if(i %2 == 0){
      takahashi += vec.at(i).at(1);
    }
    else{
      aoki += vec.at(i).at(2);
    }
  }
  cout << takahashi - aoki << endl;
}

Measured memory_bytes: 5760
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans=0,n;
    cin >>n;
    for(int i=0;i<n;i++){
        ll a;
        cin >>a;
        for(;a%2==0;a/=2){
            ans++;
        }
    }

    dbg{
        if(true)cout <<"YES"<<endl;
        else cout <<"NO"<<endl;
    }

    cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
def main():

    # 標準入力からデータの受け取り
    l_list = list(map(int, input().split()))
    d = l_list[0]
    t = l_list[1]
    s = l_list[2]

    # 待ち合わせまでの時間に間に合う？
    if (d / s <= t):
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N,T;
pll AB[202020];
vector<pair<double, ll>> abb;
ll dp[202020][60];
ll mk[202020];
ll i, j, k;


int main(){
    scanf("%lld%lld", &N,&T);
    fornum(i,0,N){
        ll a, b;
        scanf("%lld%lld", &a, &b);
        AB[i] = {a, b};
    }
    k = 0;
    fornum(i,0,N)
    {
       if(AB[i].first==0){
           mk[k++] = AB[i].second;
       }else{
           abb.push_back({(double)AB[i].first / (AB[i].second + 1), i});
       }
    }
    sort(mk, mk + k);
    sort(abb.begin(), abb.end());

    fornum(i,1,50){
        dp[0][i] = 1e15;
    }
    fornum(i,0,abb.size()){
        ll ii = abb[abb.size()-1-i].second;
        fornum(j,0,50){
            dp[i + 1][j] = 1e15;
        }
        fornum(j,0,50){
            ll b = (dp[i][j] + 1) * (AB[ii].first + 1) + AB[ii].second;
            if(b>T)
                continue;
            dp[i + 1][j + 1] = min(dp[i + 1][j + 1], b);
        }
        fornum(j,0,50){
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        }
    }
    ll ans = 0;
    fornum(i,0,50){
        ll a = dp[abb.size()][i];
        //printf("%lld ", a);
        if(a>T)
            continue;
        fornum(j,0,k){
            a += mk[j]+1;
            if(a>T)
                break;
        }
        ans = max(ans, i + j);
    }
    printf("%lld", ans);
    return 0;
}

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

#define ll long long
#define mii make_pair<int, int>
#define mll make_pair<ll, ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define all(v) (v).begin(), (v).end()

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

    int n;
    cin >> n;
    vi v(n);
    int c = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
        if (!(i & 1) && (v[i] & 1))
            ++c;
    }
    cout << c << '\n';
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int n,a[100],b[100],t;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		b[i]=a[i];
	}
	sort(b,b+1+n);
	for(int i=1;i<=n;i++){
		if(a[i]!=b[i])t++;
	}
	if(t==0||t==2)cout<<"YES";
	else cout<<"NO";
}

Measured memory_bytes: 256
// When you are hungry for something and you're determined and you're focused 
// and you're committed to something it's hard to surrender, isn't it?

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define ll long long 
#define int ll
#define mod 1000000007
#define mod1 1000000006
#define modi 998244353
#define setbit(x) __builtin_popcount(x)
#define ff first
#define ss second
#define pb push_back
vector<ll> vi[300005];
int color[100005];
ll pa[500005];
ll si[500005];
#define pb push_back
bool visi[1000005]={false};
bool is[100005];
ll fac[10000001];
ll prime[400005];
ll bit[100005];
const long double eps = 1.0e-14;      // allowable error
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
 
 
void fact(){
    fac[0]=1;
    for(int i=1;i<=10000000;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
    return ;
}
void sieve(){
    prime[0]=0;
    prime[1]=0;
    for(int i=2;i<400005;i++){
        prime[i]=1;
    }
    for(int i=2;i*i<400005;i++){
        if(prime[i]==1){
            for(int j=i*i;j<400005;j+=i){
                prime[j]=0;
            }
        }
    }
    
}
 
ll power(ll n , ll p ){
    if(p==0)
        return 1;
    
    ll res = power((n*n)%mod,p/2);
    if(p%2==1)
        res = (n*res)%mod;
    
    return res;
}
 
 
void upd(ll i,ll val,ll n) {
    for(;i<=n;i+=i&(-i))
        bit[i]+=val;
}
 
ll qry(ll i) {
    ll sum=0;
    for(;i>0;i-=i&(-i))
        sum+=bit[i];
    return sum;
}
 
 
ll fin(ll u) {
    if(pa[u]==u)
        return u;
    return fin(pa[u]);
}
 
void uni(ll u,ll v) {
    ll p1=fin(u);
    ll p2=fin(v);
    if(p1==p2)
        return;
    if(si[p1]<si[p2])
        swap(p1,p2);
    si[p1]+=si[p2];
    pa[p2]=p1;
    return;
}
 
int32_t main() {
    fio
    
    string s;
    cin >> s;
    
    if((s[0]==s[1] or s[0]==s[2] or s[1]==s[2]) and (s[0]!=s[1] or s[0]!=s[2] or s[1]!=s[2]))
        cout << "Yes" << endl;
        else
        cout << "No" << endl;
	return 0;
    
}

Measured memory_bytes: 8832
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <sstream>
#include <set>
using namespace std;
using ll = long long;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

int main() {
  int N, M;
  while (scanf("%d%d", &N, &M) != EOF) {
    vector<int> cnt(N, 1), red(N, 0);
    red[0] = 1;
    for (int i : range(M)) {
      int x, y;
      scanf("%d%d", &x, &y);
      x--;
      y--;

      assert(cnt[x] >= 1);
      cnt[y]++;
      cnt[x]--;
      if (red[x]) red[y] = 1;
      if (cnt[x] == 0) red[x] = 0;
    }

    printf("%d\n", accumulate(red.begin(), red.end(), 0));
  }
}


Measured memory_bytes: 1024
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>
#include <sstream>
#include <stdio.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> PSI;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define REP(i,n)  for(int i=0; i<(n); i++)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
/*int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}*/
/*bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.second > secondElof.second;
}*/


/*long nCr(int n, int r)
{
       if(n==r) return dp[n][r] = 1;
       if(r==0) return dp[n][r] = 1;
       if(r==1) return dp[n][r] = n;
       if(dp[n][r]) return dp[n][r];
       return dp[n][r] = nCr(n-1,r) + nCr(n-1,r-1);
}*/
/*int stoi(std::string str){
int ret;
std::stringstream ss;
ss << str;
ss >> ret;
return ret;
}*/
//LL a[200000];
//LL mis=-1, maf=-1;
/*bool under(int i, int j, LL t){
    if()
}*/
int main(){
    string n;
    cin >> n;
    int s = n.size();
    if(n[s-1]=='3') cout << "bon" << endl;
    else if(n[s-1]=='0'||n[s-1]=='1'||n[s-1]=='6'||n[s-1]=='8') cout << "pon" << endl;
    else cout << "hon" << endl;
}
/*int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(0);
	Main();
}*/


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

int main() {
    string S, S_, T;
    cin >> S >> T;
    S_ = S;

    for (int i = S.length() - 1; i >= 0; i--) {
        for (int j = 0; j < T.length(); j++) {
            if ((S[i] == T[j] || S[i] == '?') &&
                T.length() - j <= S.length() - i && j <= i) {
                bool match = true;
                for (int k = 0; k < T.length(); k++) {
                    if (!(S[i - j + k] == T[k] || S[i - j + k] == '?')) {
                        match = false;
                    }
                }
                if (match) {
                    for (int k = 0; k < T.length(); k++) {
                        S[i - j + k] = T[k];
                    }
                    for (int k = 0; k < S.length(); k++) {
                        if (S[k] == '?') {
                            S[k] = 'a';
                        }
                    }
                    cout << S << endl;
                    return 0;
                }
            }
        }
    }

    cout << "UNRESTORABLE" << endl;

    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define f first
#define s second
#define vi_a vector<int>a;
#define p_b push_back
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define getfiles ifstream cin("input.txt");ofstream cout("output.txt");
#define closefiles cin.close();cout.close();
#define all(x) x.begin(),x.end()
#define sset ordered_set
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)
#define sz(x) (int)x.size()
#define endl "\n"
#define len(x) x.length()
using namespace std;
struct triple{
    ll a,b,c;
};
const ll tx[6]={1,-1,1,-1,1,-1};
const ll ty[6]={0,0,1,1,-1,-1};
int main()
{
    fast_io;
    string a;
    cin>>a;
    bool ok=1;
    for(ll i=0;i<a.length();i++){
        if(i%2==0){
            if(a[i]!='h'){
                ok=0;
            }
        }
        else{
             if(a[i]!='i'){
                ok=0;
            }
        }
    }
    if(ok && len(a)%2==0){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	bool ans = true;
	int n, m;
	cin >> n >> m;
	vector<int> v(n, -1);
	rep(i, m) {
		int s,c;
		cin >> s >> c;
		s--;
		if (s == 0 && c == 0 && n>1) ans = false;
		if (v[s] == c) continue;
		else if (v[s] == -1) v[s] = c;
		else ans = false;
	}
	if (not ans) cout << -1 << endl;
	else {
		rep(i, n) {
			if (v[i] == -1) {
				if (i == 0 && n > 1) v[i] = 1;
				else v[i] = 0;
			}
			cout << v[i];
		}
	}
	
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        final int N = sc.nextInt();
        
        int[] count = new int[100_001];
        long total = 0;
        
        for (int i = 0; i < N; i++) {
            int A = sc.nextInt();
            count[A]++;
            total += A;
        }
        
        final int Q = sc.nextInt();
        
        StringBuilder str = new StringBuilder();
        final String BR = System.lineSeparator();
        
        for (int j = 0; j < Q; j++) {
            int B = sc.nextInt();
            int C = sc.nextInt();
            
            total += (C - B) * count[B];
            
            count[C] += count[B];
            count[B] = 0;
            
            str.append(total).append(BR);
        }
        
        System.out.println(str);
    }
}


Measured memory_bytes: 61344
#include<bits/stdc++.h>
using namespace std;
int i,n;
long long f[87]; 
int main()
{
	cin>>n;
	f[0]=2;
	f[1]=1;
	for (i=2;i<=n;i++)
	  f[i]=f[i-1]+f[i-2];
	cout<<f[n]<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace C
{
    class Program
    {
        static int[] DG = new int[2];
        static void Main(string[] args)
        {
            DG = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
            int index = 0;
            List<Score> pc = Enumerable
                                            .Range(0, DG[0])
                                            .Select(k =>
                                            {
                                                int[] tmp = Console.ReadLine().Split().Select(j => int.Parse(j)).ToArray();
                                                index++;
                                                return new Score {
                                                    num = tmp[0],
                                                    each = index * 100,
                                                    total = tmp[0] * index * 100 + tmp[1]
                                                };
                                            })
                                            .ToList();
            // 1つを途中まで
            // いくつかを完璧に
            // いくつか完璧に、あと一つは途中まで
            int ans = int.MaxValue;
            for (var i = 0; i < (1 << DG[0]); i++)
            {
                int num = 0;
                int score = 0;
                int restMax = -1;
                for (var j = 0; j < DG[0]; j++)
                {
                    if ((i >> j & 1) == 1)
                    {
                        score += pc[j].total;
                        num += pc[j].num;
                    }
                    else
                    {
                        restMax = j;
                    }
                }
                if (score < DG[1])
                {
                    int remain = DG[1] - score + pc[restMax].each - 1;
                    int restNum = remain / pc[restMax].each;
                    if (restNum > pc[restMax].num)
                    {
                        continue;
                    }
                    num += restNum;
                }
                ans = Math.Min(ans, num);
            }
            Console.WriteLine(ans);
        }
    }

    class Score
    {
        public int num;
        public int each;
        public int total;
    }

}


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int ans;
    ans = c / (7 * a + b);
    int sa = c % (7 * a + b);
    vector<int> s = {a,a,a,a,a,a,a+b};
    int cnt = 0;
    while (sa > 0){
        sa -= s[cnt];
        cnt++;
    }
    ans = ans * 7 + cnt;
    cout << ans << endl;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define llu unsigned long long
#define ll long long
#define INF 0x3f3f3f3f
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.141592653589793
using namespace std;

int main()	
{
	#ifdef SANS
		freopen("C:\\Users\\ASUS\\Documents\\Sublime\\input_output\\inputf.txt","r",stdin);
		freopen("C:\\Users\\ASUS\\Documents\\Sublime\\input_output\\outputf.txt","w",stdout);
	#endif
	fast
	int t=1;
	while(t--)
	{
		int n,m;
		cin>>n>>m;
		int arr[m], sum=0;
		for(int i=0; i<m; i++) 
		{
			cin>>arr[i];
			sum+=arr[i];
		}
		cout<<(n-sum<0?(-1):n-sum)<<endl;
	}
	#ifdef SANS
		cout<<"\nTime Elapsed:"<<1.0*clock()/CLOCKS_PER_SEC <<"sec\n";
	#endif
}

Measured memory_bytes: 3696
#include <stdio.h>

char s[100010];

int main()
{
	scanf ("%s",s);

	int l = 0;
	while (s[l]) l++;

	int u = s[0] == s[l-1];
	u = (u + l) % 2;
	puts(u?"First":"Second");

	return 0;
}

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

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

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a;
    cin >> a;
    int t=a%10;
    if(t==3) cout << "bon" << "\n";
    else if(t==0 || t==1 || t==6 || t==8) cout << "pon" << "\n";
    else cout << "hon" << "\n";
    return 0;
}

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int h, w; cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; i++) cin >> s[i];

    vector<vector<int>> dp(h, vector<int>(w, inf));
    dp[0][0] = (s[0][0] == '#');
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (i < h - 1) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (s[i][j] == '.' && s[i + 1][j] == '#')); 
            if (j < w - 1) dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + (s[i][j] == '.' && s[i][j + 1] == '#')); 
        }
    }
    cout << dp[h - 1][w - 1] << endl;
    return 0;
}


Measured memory_bytes: 384
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


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


def solve():
    return


def main():
    R = int(input())
    print(R * R)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3944