akhauriyash/Code-Regression huggingface dataset:
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
//typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
ll MOD=1000000007;
int main(){
	ll n,t;
	cin>>n>>t;
	vi in(n+1,inf);
	rep(i,n)cin>>in[i];
	sort(all(in));
	int r=0;
	ll out=1;
	rep(i,n){
		while(in[r]-in[i]<=t)r++;
		(out*=(r-i))%=MOD;
	}
	cout<<out<<endl;
}
/*
int n;
vi in;
int dp[310][310];
int f(int l,int r){
	if(dp[l][r]+inf)return dp[l][r];
	if(r-l<2)return dp[l][r]=0;
	int out=-inf;
	loop(i,l,r-1)if(abs(in[i]-in[i+1])<2){
		out=max(out,f(l,i)+2+f(i+2,r));
	}
	int t=f(l+1,r-1);
	if(t==r-l-2){
		if(abs(in[l]-in[r-1])<2)out=max(out,r-l);
	}
	out=max(out,f(l+1,r));
	out=max(out,f(l,r-1));
//	cout<<l<<" "<<r<<" "<<out<<endl;
	return dp[l][r]=out;
}
int main(){
	while(cin>>n,n){
		in=vi(n);
		rep(i,n)cin>>in[i];
		rep(i,310)rep(j,310)dp[i][j]=-inf;
		cout<<f(0,n)<<endl;;
	}
}
*/



Measured memory_bytes: 3560
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    la = rli()
    lb = rli()
    lc = rli()
    ans = sum(lb)
    for i in range(n-1):
        if la[i+1] == la[i]+1:
            ans += lc[la[i]-1]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N, K;
    std::cin >> N >> K;

    std::vector<int64_t> posX;
    std::vector<int64_t> negX;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        if (t > 0) {
            posX.push_back(t);
        }
        else if (t < 0) {
            negX.push_back(t* (-1));
        }
        else {
            // 0
            K--;
        }
    }

    std::sort(std::begin(negX), std::end(negX));


    std::vector<int64_t> cands;

    #if 0
    // 片側通行
    if (posX.size() >= K) {
        cands.push_back(posX[K-1]);
    }

    if (negX.size() >= K) {
        cands.push_back(negX[K-1]);
    }
    #endif


    // 折り返し
    int64_t ans = INT64_MAX;
    for (int64_t i = 0; i <= std::min(posX.size(), (size_t)K); ++i) {
        // i 個 プラス側
        int64_t t = 0;
        if (i > 0) {
            t += posX[i-1] * 2;

        }

        if (i == K) {
            // 折り返しなし
            ans =std::min(ans, t);

        }
        else {
            // K - i 個、マイナス側
            if (negX.size() >= K - i) {
                t += negX[K-i -1];

                ans =std::min(ans, t);
            }
        }

    }
    cands.push_back(ans);

    ans = INT64_MAX;
    for (int64_t i = 0; i <= std::min(negX.size(), (size_t)K); ++i) {
        int64_t t = 0;
        if (i > 0) {
            t += negX[i-1] * 2;
        }
        if (i == K) {
            // 折り返しなし
            ans =std::min(ans, t);
        }
        else {
            if (posX.size() >= K - i) {
                t += posX[K-i -1];
                ans =std::min(ans, t);
            }
        }
    }

    cands.push_back(ans);

    std::cout << *std::min_element(cands.begin(), cands.end()) << std::endl;

    return 0;
}


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

def main():
    N = int(input())
    s = [input().strip() for i in range(2)]

    MOD = 1000000007
    if N == 1:
        print(3)
        return
    ans = 0
    pre = -1
    i = 0
    while i < N-1:
        if s[0][i] == s[0][i+1]:# type 0
            if ans == 0:
                ans = 6
            else:
                if pre == 0:
                    ans *= 3
                    ans %= MOD
                else:
                    ans *= 2
                    ans %= MOD
            i += 2
            pre = 0
        else:# type 1
            if ans == 0:
                ans = 3
            else:
                if pre == 0:
                    pass
                else:
                    ans *= 2
                    ans %= MOD
            i += 1
            pre = 1
    if i == N-1:
        if pre == 1:
            ans *= 2
            ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

ll n;

int main()
{
    cin >> n;

    ll a = 0;
    for (int i = sqrt(n); i >= 1; i--)
    {
        if (n % i == 0)
        {
            a = i;
            break;
        }
    }
    ll b = n / a;
    cout << (a - 1) + (b - 1) << endl;
}


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

int main(){
  int N, M; cin >> N >> M;
  vector<int> L(M), R(M);
  int Lans = 0, Rans = N;
  for(int i = 0; i < M; i++){
    int l, r; cin >> l >> r;
    l--; r--;
    L[i] = l;
    R[i] = r;

  }
  
  for(int i = 0; i < M; i++){
    Lans = max(L[i], Lans);
    Rans = min(R[i], Rans);
  }

  int ans = 0;
  for(int i = 0; i < N; i++){
    if(Lans <= i && i <= Rans){
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

string N;
int K;
ll dp[101][2][5];

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

    int n=N.size();
    dp[0][0][0]=1;

    rep(dgt,n) rep(isless,2) rep(k,K+1){
        int c=N[dgt]-'0';
        rep(nxt,10){
            if(c<nxt && isless==0) continue;

            int isless2=isless;
            if(nxt<c) isless2=1;
            int k2=k;
            if(nxt!=0) k2++;

            dp[dgt+1][isless2][k2]+=dp[dgt][isless][k];
        }
    }

    cout<<dp[n][0][K]+dp[n][1][K]<<endl;
}


 

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main( String[] args ) {
		Scanner stdIn = new Scanner( System.in );
	
		int n = stdIn.nextInt();
		
		for ( int i = 0; i < n; i++ ) {
			int a = stdIn.nextInt(), b = stdIn.nextInt(), c = stdIn.nextInt();
			
			if ( a * a + b * b == c * c || a * a + c * c == b * b || b * b + c * c == a * a )
				System.out.println( "YES" );
			else
				System.out.println( "NO" );
			}
	}
}

Measured memory_bytes: 23396
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(N) for (int i = 0; i < N; i++)

int get_gcd(int a, int b){
    if (a % b == 0) return b;
    return get_gcd(b, a % b);
}

int get_gcd_for_x(vector<int> x){
    int gcd;
    for (int i = 0; i < x.size(); i++){
        if (i == 0) gcd = x[i];
        else{
            if (gcd > x[i]){
                gcd = get_gcd(gcd, x[i]);
            }else{
                gcd = get_gcd(x[i], gcd);
            }
        }
    }
    return gcd;
}

int main(){
    int N, X;
    cin >> N >> X;
    vector<int> x(N);
    int gcd;
    for (int i = 0; i < N; i++){
        cin >> x[i];
    }
    for (int i = 0; i < N; i++){
        if (x[i] - X < 0) x[i] = X - x[i];
        else x[i] = x[i] - X;
    }
    gcd = get_gcd_for_x(x);
    cout << gcd << endl;
}


Measured memory_bytes: 1024
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#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 <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;


int main() {

    while (true) {

        int H;
        cin >> H;

        if (H == 0) break;

        vector <vector<int>> S(H, vector<int>(5));
        for (int i = 0; i < H; i++) for (int j = 0; j < 5; j++) cin >> S[i][j];

        int score = 0;

        while (true) {
            bool finish = true;

            //終了か確認
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < 3; j++) {
                    bool good = true;
                    int color = S[i][j];
                    if (color == 0) continue;
                    for (int k = 0; k < 3; k++) if (color != S[i][j + k]) good = false;
                    if (good) finish = false;
                }
            }

            if (finish) break;

            for (int i = 0; i < H; i++) {
                for (int j = 0; j < 3; j++) {
                    int count = 0;
                    int color = S[i][j];
                    int index = 0;
                    while ((j + index) < 5 && S[i][j + index] == color) count++, index++;
                    if (count >= 3) {
                        for (int k = 0; k < count; k++) {
                            score += S[i][j + k];
                            S[i][j + k] = 0;
                        }
                    }
                }
            }

            vector <vector<int>> newS(H, vector<int>(5, 0));
            for (int i = 0; i < 5; i++) {
                int index = H - 1;
                for (int j = H - 1; j >= 0; j--) {
                    if (S[j][i] != 0) {
                        newS[index][i] = S[j][i];
                        index--;
                    }
                }
            }

            S = newS;

        }

        cout << score << endl;

    }

    return 0;
}

































Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)



int main(){

string s;
cin>>s;

if(s[0]==s[1]&&s[1]==s[2]){
    cout<<"No"<<endl;
}
else{
    cout<<"Yes"<<endl;
}

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

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

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int hsum[300030] = {};
int wsum[300030] = {};
int hm[300030] = {};
int wm[300030] = {};
vector<vector<int>> hv(300030);
int main() {
	long long int n,d;
	cin >> n >>d;
	long long int ans=0;
	for (int i = 0; i < n; i++) {
		long long int x, y;
		cin >> x >> y;
		if (x * x + y * y <= d * d) {
			ans++;
		}
	}
	cout << ans;
}


Measured memory_bytes: 10204
#import sys
#import numpy as np
#import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect

n=int(input())
s=[input() for _ in range(n)]
ans=0
bn=an=0
d=0
for i in range(n):
    ans+=s[i].count("AB")
    if s[i][0]=="B":
        an+=1
        if s[i][-1]=="A":
            d+=1
    if s[i][-1]=="A":
        bn+=1
if an==0 or bn==0:
  print(ans)
  exit()
if bn==an==d:
    print(ans+d-1)
else:
    print(ans+min(an,bn))

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

bool ans(int x,int y){
    return x>=2*y-1;
}
int main(void){
    // Your code here!
    long long int a,b,k;
        cin >> k;
        cin >> a;
        cin >> b;

    //A+1回でb枚数生成
    //AとBを繰り返す
    long long int ans =0;
    if(k >= a + 1) ans = b + (k - (a + 1))/2*(b-a) + (k - a + 1)%2;
    if(ans < 1+k) ans = 1+k;
    
    
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
// head

const int N=201000;

int l[N],r[N],id[N],sz[N],hs[N],tot;
int f[N],se[N],ret[N],ans,c[N],d[N],n,k;
int u,v;
VI e[N];

int find(int x) { return f[x]==x?x:f[x]=find(f[x]); }
void dfs(int u,int f) {
	l[u]=++tot;
	id[tot]=u;
	sz[u]=1;
	hs[u]=-1;
	for (auto v:e[u]) if (v!=f) {
		dfs(v,u);
		sz[u]+=sz[v];
		if (hs[u]==-1||sz[v]>sz[hs[u]]) hs[u]=v;
	}
	r[u]=tot;
}

void unmark(int x) {
	//printf("del %d\n",x);
	f[x]=x; sz[x]=1; se[x]=0;
}

void add(int u,int v) {
	//printf("add %d %d\n",u,v);
	u=find(u); v=find(v);
	if (u==v) {
		if (sz[u]==se[u]+1) ans++;
		se[u]++;
	} else {
		if ((sz[u]==se[u]+1)||(sz[v]==se[v]+1)) ans++;
		f[v]=u; sz[u]+=sz[v]; se[u]+=se[v]; se[u]++;
	}
	//printf("zz %d %d %d\n",sz[u],se[u],ans);
}

void dfs2(int u,int f,bool fg) {
	for (auto v:e[u]) if (v!=f&&v!=hs[u]) {
		dfs2(v,u,0);
	}
	if (hs[u]!=-1) {
		dfs2(hs[u],u,1);
	}
	for (auto v:e[u]) {
		if (v!=f&&v!=hs[u])
			rep(x,l[v],r[v]+1) add(c[id[x]],d[id[x]]);
	}
	add(c[u],d[u]);
	ret[u]=ans;
	//printf("query %d %d\n",u,ans);
	if (!fg) {
		rep(i,l[u],r[u]+1) {
			unmark(c[id[i]]);
			unmark(d[id[i]]);
		}
		ans=0;
	}
}

int main() {
	scanf("%d%d",&n,&k);
	rep(i,1,n) {
		scanf("%d%d",&u,&v);
		e[u].pb(v);
		e[v].pb(u);
	}
	rep(i,1,n+1) {
		scanf("%d%d",c+i,d+i);
	}
	dfs(1,0);
	rep(i,1,k+1) f[i]=i,sz[i]=1;
	dfs2(1,0,0);
	rep(i,1,n+1) printf("%d\n",ret[i]);
}



Measured memory_bytes: 23712
import queue

N = int(input())
K = int(input())

que = queue.Queue()
que.put((1, 0))

min = -1
while (True):
    if que.empty():
        break
    test = que.get()
    # print(test)
    num = test[0]
    count = test[1]
    if count == N:
        if min == -1 or min > test[0]:
            min = test[0]
        continue
    que.put((num * 2, count + 1))
    que.put((num + K, count + 1))
print(min)


Measured memory_bytes: 41708
#include<bits/stdc++.h>
using namespace std;
int main(void){
    string s,t;
    cin>>s>>t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char>());
    if(s<t)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
      Scanner scn = new Scanner(System.in);
      String word = scn.nextLine();
      int n = word.length();
      int m = (n-1)/2;
      for(int i = 0; i < m+1;i++){
        if(word.charAt(i)!=word.charAt(n-1-i)){
          System.out.println("No");
          return;
        }
      }
      for(int j = 0; j<(m+1)/2;j++){
        if(word.charAt(j)!=word.charAt(m-1-j)){
          System.out.println("No");
          return;
        }
      }
      System.out.println("Yes");
	}
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
int N;
int m[111111];
long long a,b,sa,sb;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>m[i];
    }
    for(int i=0;i<N;i++){
        sa+=m[i];
        sb+=m[i];
        if(i%2){
            if(sa>=0){
                a+=sa+1;
                sa=-1;
            }
            if(sb<=0){
                b-=sb-1;
                sb=1;
            }
        }
        else{
            if(sa<=0){
                a-=sa-1;
                sa=1;
            }
            if(sb>=0){
                b+=sb+1;
                sb=-1;
            }
        }
    }
    cout<<min(a,b);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

#define dist(x1, y1, x2, y2) sqrtl((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))

int main() {
    init();

    int n; cin >> n;
    vector<ld> X(n), Y(n);
    FOR(i, 0, n)cin >> X[i] >> Y[i];

    function<ld(ld, ld)> calcDist = [&](ld x, ld y) {
        ld ret = 0;
        FOR(i, 0, n)chmax(ret, dist(x, y, X[i], Y[i]));
        return ret;
    };

    function<ld(ld)> solve = [&](ld x) {
        ld l = 0, r = 1000;
        FOR(loop, 0, 100) {
            ld m1 = (l * 2 + r) / 3, m2 = (l + r * 2) / 3;
            if (calcDist(x, m1) < calcDist(x, m2))r = m2;
            else l = m1;
        }
        return calcDist(x, r);
    };

    ld l = 0, r = 1000;
    FOR(loop, 0, 100) {
        ld m1 = (l * 2 + r) / 3, m2 = (l + r * 2) / 3;
        if (solve(m1) < solve(m2))r = m2;
        else l = m1;
    }

    cout << solve(r) << "\n";
}


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

int main(){
    //input
    int n;
    cin >> n;
    vector<int> h(n);
    for(auto itr=h.begin(); itr!=h.end(); itr++){
        cin >> *itr;
    }
    //calculate
    int max = 0;
    int tmp_max = 0;
    for(int i=0; i+1<n; i++){
        if(h.at(i) >= h.at(i+1)){
            tmp_max++;
          	max = ((max <= tmp_max) ? tmp_max : max);
        }
        else{
          	tmp_max = 0;
        }
    }
    //output
    cout << max << endl;
}

Measured memory_bytes: 640
from itertools import combinations

N = int(input())
d = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for _ in range(N):
    fl = input()[0]
    if fl in d:
        d[fl] += 1

s_comb_list = list(combinations('MARCH', 3))
v = 0
for s_comb in s_comb_list:
    v += (d[s_comb[0]] * d[s_comb[1]] * d[s_comb[2]])
print(v)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cout<<(#v)<<":";for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;
#define printVS(vs) cout<<(#vs)<<":"<<endl;for(auto(s):(vs)){cout<<(s)<< endl;}
#define printVV(vv) cout<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;}
#define printP(p) cout<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cout<<(#vp)<<":"<<endl;for(auto(p):(vp)){cout<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cout << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cout << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

    int n;
    cin >> n;
    vi t(n);
    rep(i, n) cin >> t[i];
    int sm = accumulate(all(t), 0);

    int m;
    cin >> m;
    rep(i, m) {
        int p, x;
        cin >> p >> x;
        p--;
        cout << sm - (t[p] - x) << endl;
    }
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int n2 = 1;
    while(n2<n){
        n2*=2;
    }
    vvint ed(n2+1,vint(n2+1,0));
    int st=2;
    int lv=2;
    if(n==2){
        cout << 1 << endl;
        return 0;
    }
    ed[0][1]=1;
    ed[1][0]=1;
    while(st*2<=n2){
        for(int i=0;i<st;i++){
            for(int j=0;j<st;j++){
                ed[i+st][j+st]=ed[i][j];
                ed[j+st][i+st]=ed[i][j];
            }
        }
        for(int i=0;i<st;i++){
            for(int j=0;j<st;j++){
                ed[i+st][j]=lv;
                ed[i][j+st]=lv;
            }
        }
        st*=2;
        lv++;
    }
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n-1;j++){
            cout << ed[i][j] << " ";
        }
        cout << ed[i][n-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1536
h, w = map(int, input().split())
a = [['*' for _ in range(w+2)]]
for _ in range(h):
    a.append(['*'] + list(input()) + ['*'])
a.append(['*' for _ in range(w+2)])

q = set()

def encode(i, j):
    return i*w + j-1

def decode(x):
    i = x // w
    j = x % w + 1
    return [i, j]

for i in range(1, h+1):
    for j in range(1, w+1):
        if a[i][j] == '#':
            q.add(encode(i, j))

for ans in range(h+w):
    nq = set()
    for x in q:
        i, j = decode(x)
        for k in [-1,1]:
            if a[i+k][j] == '.':
                nq.add(encode(i+k, j))
                a[i+k][j] = '#'
        for k in [-1,1]:
            if a[i][j+k] == '.':
                nq.add(encode(i, j+k))
                a[i][j+k] = '#'
    if len(nq) == 0:
        print(ans)
        exit()
    else:
        q = set()
        q = q | nq


Measured memory_bytes: 139148
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n, m;
  cin >> n >> m;
  vector<ll> x(n), y(n), z(n);
  for(int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> z[i];
  }
  ll ans = 0;
  for(int i = 0; i < 8; i++) {
    vector<ll> sum(n, 0);
    for(int j = 0; j < n; j++) {
      if(i >> 0 & 1){
        sum[j] += x[j];
      }else{
        sum[j] -= x[j];
      }
      if(i >> 1 & 1){
        sum[j] += y[j];
      }else{
        sum[j] -= y[j];
      }
      if(i >> 2 & 1){
        sum[j] += z[j];
      }else{
        sum[j] -= z[j];
      }
    }
    sort(sum.rbegin(), sum.rend());
    ll score = 0;
    for(int j = 0; j < m; j++) {
      score += sum[j];
    }
    ans = max(ans, score);
    //cout << score << " ";
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)  
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl

int main()
{
  int n;
  cin >> n;
  int nums[200005];
  rep(i,n-1)
  {
    nums[i] = 0;
  }
  rep(i,n-1)
  {
    int tmp = 0;
    cin >> tmp;
    nums[tmp-1]++;
  }
  rep(i,n-1)
  {
    cout << fixed << nums[i] << endl;
  }
  cout << fixed << 0 << endl;
  return 0;
}

Measured memory_bytes: 4400
# codefestival_2016_qualB_b.py
N,A,B = map(int,input().split())
S = input()
cnt = 0
bcnt = 0
for i,c in enumerate(S):
    if c =="a":
        if cnt < A+B:
            print("Yes")
            cnt +=1
        else:
            print("No")
    elif c=="b":
        if cnt < A+B and bcnt<B:
            print("Yes")
            cnt +=1
            bcnt +=1
        else:
            print("No")
    elif c=="c":
        print("No")

Measured memory_bytes: 53848
N = int(input())
words = []
for _ in range(N):
    words.append(input())
count_table = {}
for w in words:
    if w in count_table:
        count_table[w] += 1
    else:
        count_table[w] = 0
best_count = 0
best_words = []
for w in count_table:
    if best_count < count_table[w]:
        best_count = count_table[w]
        best_words = [w]
    elif best_count == count_table[w]:
        best_words.append(w)
for w in sorted(best_words):
    print(w)

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

using namespace std;

typedef long long ll;

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

	string o, e;
	cin >> o >> e;
	
	int oz = o.size();
	int ez = e.size();

	rep(i, max(oz, ez)){
		if(i < oz) cout << o[i];
		if(i < ez) cout << e[i];
	}
	cout << endl;
}


Measured memory_bytes: 256
A, B, K = list(map(int, input().rstrip().split()))
if K % 2 == 0:
    for i in range(K // 2):
        if A % 2 != 0:
            A -= 1
        A = A // 2
        B += A
        if B % 2 != 0:
            B -= 1
        B = B // 2
        A += B
else:
    for i in range(K // 2):
        if A % 2 != 0:
            A -= 1
        A = A // 2
        B += A
        if B % 2 != 0:
            B -= 1
        B = B // 2
        A += B
    if A % 2 != 0:
        A -= 1
    A = A // 2
    B += A
print(A, B)

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();

        int count = 0;
        for (int i = a;i >= 0; i--) {
            
            for (int j = b; j >= 0; j--) {
                for (int k = c ;k >= 0; k--) {
                    if (500 * i + 100 * j + 50 * k == x) {
                        count++;
                    }
                }
            }
        }
        System.out.println(count);
    }
}

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

using namespace std;

int main(){
    long int N;
    cin >> N;
    vector<long int> A(N);
    vector<long int> B(N);
    long int sumA=0,sumB=0;
    for(long int i=0; i<N; i++){
        cin >> A[i];
        sumA += A[i];
    }
    for(long int i=0; i<N; i++){
        cin >> B[i];
        sumB += B[i];
    }
    
    if(sumA < sumB){
        cout << -1 << endl;
        return 0;
    }

    bool pass = true;
    for(long int i=0; i<N; i++){
        if(A[i] < B[i]){ pass=false; }
    }
    if(pass){
        cout << 0 << endl;
        return 0;
    }

    //main
    vector<long int> diff(N), diffbefore(N);
    for(long int i=0; i<N; i++){
        diff[i] = A[i] - B[i];
    }
    
    //diffをsort
    sort(diff.begin(),diff.end());
    diffbefore = diff;

    //差分を埋める
    long int backpointer = N-1;
    for(long int i=0; i<N;i++){
        if( diff[i] < 0 ){
            //backpointerが十分大きい
            if((diff[backpointer] + diff[i]) > 0){
                //backpointerを分け与えて次へ。
                diff[backpointer] += diff[i];
                diff[i] = 0;
                continue;
            }else{
                //backpointerの限界まで分けて次のbackpointerへ
                diff[i] += diff[backpointer];
                diff[backpointer] = 0;
                backpointer--;
                i--;
                continue;
            }
        } 
    }

    //変化があった数をカウントして表示する
    long int counter=0;
    for(long int i=0; i<N; i++){
        if(diff[i] != diffbefore[i]){ counter++; }
    }
    cout << counter << endl;

    return 0;
}


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

int main() {
    string s;
    while (cin >> s >> s) {
        auto p = s.find("xx");
        int n = s.size();
        if (p == string::npos) {
            cout << n;
        } else {
            cout << p + 1;
        }
        cout << endl;
    }
}

Measured memory_bytes: 3344
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll) (1e9)
#define mod (ll) (1e9 + 7)
#define endl "\n"
#define tt ll testcase; cin>>testcase; while(testcase--)
 
int main(){
	fast;
	ll n, W;
	cin >> n >> W;
	ll we[n], v[n];
	for(int i=0; i<n; i++){
		cin >> we[i] >> v[i];
	}
	vector<ll>dp(W+1, 0);
	for(ll i = 0; i < n; i++){
		for(ll j = W - we[i]; j >= 0; j--){
			dp[j+we[i]] = max(dp[j+we[i]], dp[j] + v[i] );
		}
	}
	cout<<*max_element(dp.begin(), dp.end());
}

Measured memory_bytes: 1024
from bisect import bisect_left, bisect_right


def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    
    A.sort()
    C.sort()
    
    ans = 0
    for i in range(N):
        cnt_a = bisect_left(A, B[i])
        cnt_b = N - bisect_right(C, B[i])
        ans += cnt_a * cnt_b
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 22720
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    int N;
    cin >> N;
    vector<int> h;
    int count = 0;
    int maxH = 0;
    rep(i, N) {
        int hi;
        cin >> hi;
        h.pb(hi);
        maxH = max(maxH, hi);
    }

    for(int limit = 1; limit <= maxH; limit++) {
        bool isWater = false;
        rep(i, N) {
            if (h[i] >= limit) {
                if (!isWater) count++;
                isWater = true;
            } else {
                isWater = false;
            }
        }
    }
    cout << count << endl;
}


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

int main(){
  string str;
  cin>>str;
  str.push_back('T');
  int x,y;
  scanf("%d %d",&x,&y);
  vector<int> X,Y;
  int length=str.size();
  int d=0,i,dir=0,hoge=0;
  for(i=0;i<length;i++){
    if (str[i]=='F'){
      d+=1;
    }
    else{
      if(dir==0){
	if(hoge==0){
	  x-=d;
	  d=0;
	  dir=1;
	  hoge=1;
	}
	else{
	  X.push_back(d);
	  d=0;
	  dir=1;
	}
      }
      else{
	Y.push_back(d);
	d=0;
	dir=0;
      }
    }
  }
  sort(X.begin(),X.end(),greater<int>());
  sort(Y.begin(),Y.end(),greater<int>());
  int x_size=X.size(),y_size=Y.size(),x_val=0,y_val=0;
  for(i=0;i<x_size;i++){
    if(x>x_val) x_val+=X[i];
    else x_val-=X[i];
  }
  for(i=0;i<y_size;i++){
    if(y>y_val) y_val+=Y[i];
    else y_val-=Y[i];
  }
  if(x==x_val && y==y_val) printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: char
    }

    if a == a.to_lowercase().next().unwrap() {
        println!("a");
    } else {
        println!("A")
    }
}


Measured memory_bytes: 2124
#include<bits/stdc++.h>
#define long long ll ;
#define mod 1e+9;
#define rep for(int i=0;i<n;i++);
#define pb push_back;
#define popb pop_back;
using namespace std;
const int ma=1e6+9;

int main()
{
//     #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
   ios_base::sync_with_stdio(0);
    cin.tie(0);
    int temp;
    cin >> temp;
    if(temp>=30)
      cout << "Yes" << endl;
    else
      cout <<"No" << endl;
  }


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  int N;
  vector<pair<int, int>> v;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    v.push_back(make_pair(x, y));
  }

  sort(v.begin(), v.end());

  double ans = 0;
  int cnt = 0;

  do {
    cnt++;
    double sum = 0;
    for (int i = 0; i < v.size() - 1; i++) {
      sum += sqrt(
          (v[i].first - v[i + 1].first) * (v[i].first - v[i + 1].first) +
          (v[i].second - v[i + 1].second) * (v[i].second - v[i + 1].second));
    }
    ans += sum;
  } while (next_permutation(v.begin(), v.end()));

  cout << fixed << setprecision(15) << double(ans / cnt) << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	bool flag = true;
	rep(i, n) {
		if (a[i] == 1) flag = false;
	}
	if (flag) {
		cout << -1 << endl;
		return 0;
	}
	int num = 1;
	int ans = 0;
	rep(i, n) {
		if (a[i] == num) {
			num++;
		}
		else {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<map>
#include<queue>
#include<cstdio>
#include<vector>

#define	pb	push_back

using namespace std;

typedef	vector<int>	vi;

vi mv[13];
long long pow12[13];

void findEmptyPos(long long stat,int *z){
	for(int i=0,j=0;i<13;i++){
		if(stat%12==0)	z[j++]=12-i;
		stat/=12;
	}
}

long long sw(long long stat,int i,int j){
	long long powi=pow12[12-i],powj=pow12[12-j];
	int pi=(stat/powi)%12,pj=(stat/powj)%12;
	return stat+(pj-pi)*powi+(pi-pj)*powj;
}

void bfs(map<long long,int> &f,long long inistat,int stop){
	f[inistat]=0;
	queue<long long> qu;	qu.push(inistat);
	while(!qu.empty()){
		long long stat=qu.front();	qu.pop();
		int cnt=f[stat];
		if(cnt==stop)	break;

		int z[2];	findEmptyPos(stat,z);
		for(int i=0;i<2;i++){
			for(int j=0;j<mv[z[i]].size();j++){
				long long nextstat=sw(stat,z[i],mv[z[i]][j]);
				if(f.count(nextstat)==0){
					qu.push(nextstat);
					f[nextstat]=cnt+1;
				}
			}
		}
	}
}

int main(){
	long long a=1;
	for(int i=0;i<13;i++)	pow12[i]=a,a*=12;

	mv[0].pb(2);
	mv[1].pb(2);	mv[1].pb(5);
	mv[2].pb(0);	mv[2].pb(1);	mv[2].pb(3);	mv[2].pb(6);
	mv[3].pb(2);	mv[3].pb(7);
	mv[4].pb(5);
	mv[5].pb(1);	mv[5].pb(4);	mv[5].pb(6);	mv[5].pb(9);
	mv[6].pb(2);	mv[6].pb(5);	mv[6].pb(7);	mv[6].pb(10);
	mv[7].pb(3);	mv[7].pb(6);	mv[7].pb(8);	mv[7].pb(11);
	mv[8].pb(7);
	mv[9].pb(5);	mv[9].pb(10);
	mv[10].pb(6);	mv[10].pb(9);	mv[10].pb(11);	mv[10].pb(12);
	mv[11].pb(7);	mv[11].pb(10);
	mv[12].pb(10);

	int ans[]={0,1,2,3,4,5,6,7,8,9,10,11,0};
	long long ansstat=0;
	for(int i=0;i<13;i++)	ansstat=ansstat*12+ans[i];

	map<long long,int> f;
	bfs(f,ansstat,11);

	for(long long inistat;scanf("%lld",&inistat),~inistat;){
		for(int i=1,p;i<13;i++)	scanf("%d",&p),inistat=inistat*12+p;
		map<long long,int> g;
		bfs(g,inistat,9);

		int cmin=21;
		map<long long,int>::iterator it;
		for(it=g.begin();it!=g.end();it++){
			long long stat=it->first;
			int cnt=it->second;
			if(f.count(stat))	cmin=min(cmin,cnt+f[stat]);
		}
		if(cmin<=20)	printf("%d\n",cmin);
		else	puts("NA");
	}

	return 0;
}

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

int main(){
  string s,t,u;
  cin >> s >> t;
  int a,b;
  cin >> a >> b;
  cin >> u;

  if(s == u){
    a--;
  }
  if(t == u){
    b--;
  }
  cout << a << " " << b << endl;
  return 0;
}


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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

template<typename T = long long> inline T toInteger(const string&);

template<> inline int toInteger<int>(const string& s) {
  return stoi(s);
}

template<> inline long toInteger<long>(const string& s) {
  return stol(s);
}

template<> inline long long toInteger<long long>(const string& s) {
  return stoll(s);
}

template<typename T = long long> inline T toInteger(const string& s, int n) {
  T res = 0;
  for (char c : s) {
    if (isdigit(c)) res = res * n + c - '0';
    else if (isalpha(c)) res = res * n + tolower(c) - 'a' + 10;
  }
  return s[0] == '-' ? -res : res;
}

int main() {
  string s;
  cin >> s;
  int64_t res = 0;
  for (int i = 0; i < (1 << (s.size() - 1)); ++i) {
    int64_t t = 0;
    for (size_t j = 0; j < s.size(); ++j) {
      t = t * 10 + s[j] - '0';
      if (i & 1 << j) {
        res += t;
        t = 0;
      }
    }
    res += t;
  }
  cout << res << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        String s = sc.next();
        String re = s;

        if (s.length() == 3) {
            char[] c = new char[3];
            c[0] = s.charAt(2);
            c[1] = s.charAt(1);
            c[2] = s.charAt(0);
            re = String.valueOf(c);
        }
        
        System.out.println(re);
    }
}

Measured memory_bytes: 22100
N,K,Q= [int(s) for s in input().split()]
A = [int(input()) for _ in range(Q)]

temp=[0]*N

for i in A:
  temp[i-1]=temp[i-1]+1
ans=[K - (Q- d) for d in temp]

#ans = list(map(lambda x: K-(Q-x), temp))

for t in ans:
  if t>0:
    print("Yes")
  else:
    print("No")

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

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector < string > S(N);
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}

	sort(S.begin(), S.end());
	S.erase(unique(S.begin(), S.end()), S.end());

	cout << S.size() << endl;

	return 0;
}


Measured memory_bytes: 9540
def gcd(a,b):
  if( b == 0 ):
    return a
  else:
    return gcd(b, a%b)
def lcm(a,b):
  return a* b // (gcd(a,b))
a, b, c, d = [int(x) for x in input().split()]
g = lcm(c,d)
a1 = b//c - (a-1)//c + b//d  - (a-1)//d - b// g + (a-1)//g
print( b - a + 1 - a1)


Measured memory_bytes: 3060
#include <iostream>
    #include <string>
    #include <sstream>
    #include <vector>
    #include <tuple>
    using namespace std;
     
    int main() {
    	int N,T;
    	cin >> N >> T;
     
    	int cost = 10000;
    	int time = 10000;
    	for (int i = 0; i < N; i++) {
    		int c, t;
    		cin >> c >> t;
    		if (t <= T) {
    			if (cost > c) {
    				cost = c;
    			}
    		}
    	}
      if(cost==10000){
        cout <<"TLE";
      }else{
    	cout << cost;
      }
     
    	
    	return 0;
    }

Measured memory_bytes: 256
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
#define LL long long
#define NUM 1000000007

using namespace std;

int main()
{
    int a, b, c, x, count = 0;
    cin >> a >> b >> c >> x;
    for (size_t i = 0; i < a + 1; i++)
    {
        for (size_t j = 0; j < b + 1; j++)
        {
            for (size_t k = 0; k < c + 1; k++)
            {
                if (i * 500 + j * 100 + k * 50 == x)
                {
                    count++;
                }
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main() {

	int N, M;
	std::cin >> N >> M;

	int total = 0;
	int tmp;
	for (int i=0; i<M; i++) {
		std::cin >> tmp;
		total += tmp;
	}
	if (N-total < 0) {
		std::cout << -1 << "\n";
	}
	else {
		std::cout << N - total << "\n";
	}

	return 0;
}


Measured memory_bytes: 3636
s = input()
dic = ['A','C','G','T']
ans = 0
max_ans=0
for i in range(len(s)):
  if s[i] in dic:
    ans +=1
  else:
    if max_ans <ans:
      max_ans = ans
    ans=0
if max_ans < ans:
  max_ans = ans
print(max_ans)


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

//p = 1, 2, 3, ∞の時のミコンフスキー距離を求めるプログラム
int main(){
    int n, i;
    double Dp1 = 0, Dp2 = 0, Dp3 = 0, Dp_inf = 0;

    cin >> n;
    int x[n] = {}, y[n] = {};
    
    i = 0;
    while(i < n){
        cin >> x[i];
        i++;
    }
    i = 0;
    while(i < n){
        cin >> y[i];
        i++;
    }

    i = 0;
    while(i < n){
        Dp1 = Dp1 + fabs(x[i] - y[i]);
        Dp2 = Dp2 + pow(x[i] - y[i], 2);
        Dp3 = Dp3 + pow(fabs(x[i] - y[i]), 3);
        if (Dp_inf < fabs(x[i] - y[i])) Dp_inf = fabs(x[i] - y[i]);
        i++;
    }
    Dp2 = sqrt(Dp2);
    Dp3 = pow(Dp3, 1.0/3.0);

    cout << fixed << Dp1 << endl;
    cout << fixed << Dp2 << endl;
    cout << fixed << Dp3 << endl;
    cout << fixed << Dp_inf << endl;

    return 0;
}


Measured memory_bytes: 3484
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = int(input())
MAX_a = 0
ans = 0
for i in range(N):
	a,b = inpl()
	if MAX_a < a:
		ans = a+b
		MAX_a = a

print(ans)


Measured memory_bytes: 4212