akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A;
    vector<int> B;
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--;
        A.push_back(a);
        B.push_back(b);
    }

    int res = 10000;
    rep(i, 1000) {
        string str = to_string(i);
        if (str.size() == N) {
            bool judge = 1;
            rep(j, M) {
                if ((str[A[j]] - '0') != B[j]) {
                    judge = 0;
                    break;
                }
            }
            if (judge)
                res = min(res, i);
        }
    }
    if (res == 10000)
        cout << -1 << endl;
    else
        cout << res << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
nn=[0,0,0]
for i,v in enumerate(a):
    tmp=0
    while v%2==0:
        v//=2
        tmp+=1
    nn[min(tmp,2)]+=1
if nn[1]:
    if nn[0]>(n-nn[1])//2:
        print("No")
    else:
        print("Yes")
else:
    if nn[0]>(n+1)//2:
        print("No")
    else:
        print("Yes")

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a <= 5) {
		cout << 0 << endl;
	}
	else if (a < 13) {
		cout << b / 2 << endl;
	}
	else {
		cout << b << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define MAX_NUM 100000
#define NUM_MAX 1000000008
 
int main(void){
	int i, j, N;
	long tmp;
	char A[NUM_MAX/8] = {0};
	int count;
 
	scanf("%d", &N);
 
	for(i=0; i<N; i++){
		scanf("%ld", &tmp);
		switch(tmp%8){
			case 0: A[tmp/8] = A[tmp/8]^1; break;
			case 1: A[tmp/8] = A[tmp/8]^2; break;
			case 2: A[tmp/8] = A[tmp/8]^4; break;
			case 3: A[tmp/8] = A[tmp/8]^8; break;
			case 4: A[tmp/8] = A[tmp/8]^16; break;
			case 5: A[tmp/8] = A[tmp/8]^32; break;
			case 6: A[tmp/8] = A[tmp/8]^64; break;
			case 7: A[tmp/8] = A[tmp/8]^128; break;
		}
	}
 
	count = 0;
	for(i=0; i<NUM_MAX/8; i++){
		for(j=0; j<8; j++){
			if((A[i] >> j) & 1)
				count++;
		}
	}
 
	printf("%d", count);
 
	return 0;
}

Measured memory_bytes: 122368
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Random;
import java.util.Scanner;
public class Main {
	static Scanner sc = new Scanner(System.in);static void p(int i) {System.out.println(i);}static void p(long i) {System.out.println(i);}static void p(String i) {System.out.println(i);}static void p(double i) {System.out.println(i);}
	
	//a 97 || 
	public static void main(String[] args) {
		//int N=sc.nextInt();
		//String S=sc.next();
		//for(int i=0;i<N;i++) {}
		int A=sc.nextInt();
		int B=sc.nextInt();
		int C=sc.nextInt();
		
		
		
		p(Math.max(A+B*10+C, Math.max(A*10+B+C, C*10+B+A)));
	}
	
}
	


Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int i, j, N, M;
int A[101], B[101][101], P[101];
int main(){
    cin >> N >> M;
    for (i=1; i<=M; i++) { cin >> A[i]; }
    for (i=1; i<=M; i++) {
        for (j=1; j<=N; j++) {
            cin >> B[i][j];
        }
    }
    for (j=1; j<=N; j++) { P[j] = 0; }
    for (i=1; i<=M; i++) {
        for (j=1; j<=N; j++) {
            if(A[i]==B[i][j]) {
                P[j]++;
            } else {
                P[A[i]]++;
            }
        }
   }
   for (j=1; j<=N; j++) {
       cout << P[j] << endl;
   }
   return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;

int a,b,c;
int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b;
    ll ab = 0;
    if(a>=b){
        ab += a;
        a--;
    }else{
        ab += b;
        b--;
    }
     if(a>=b){
         cout << ab + a << endl;
    }else{
        cout << ab + b << endl;

    }

    

    return 0;
}

Measured memory_bytes: 256
# Author: cr4zjh0bp
# Created: Sun Mar 22 23:25:40 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

x, a, b = na()

if a >= b:
    print("delicious")
elif b - a <= x:
    print("safe")
else:
    print("dangerous")

Measured memory_bytes: 3064
strings = input()

#YYMMの検討
def can_yymm(strings):
    mm = int(strings[2:])
    if mm >= 1 and mm <= 12:
        return True
    else:
        return False

def can_mmyy(strings):
    mm = int(strings[:2])
    if mm >= 1 and mm <= 12:
        return True
    else:
        return False

if can_yymm(strings) and not can_mmyy(strings):
    print('YYMM')
elif not can_yymm(strings) and can_mmyy(strings):
    print('MMYY')
elif can_yymm(strings) and can_mmyy(strings):
    print('AMBIGUOUS')
else:
    print('NA')

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

int main(void){
  int N;
  cin >> N;
  set<string> set;
  int list_item[N];
  string tmp;
  for(int i=0;i<N;i++){
    cin >> tmp;
    set.insert(tmp);
  }
  
  printf("%d\n",set.size());
  return 0;
}

Measured memory_bytes: 19316
jobs = []
for _ in range(int(input())):
    a, b = [int(i) for i in input().split()]
    jobs.append((a, b))

jobs.sort(key=lambda j: j[1])
curr_jour = 0

can = True
for j in jobs:
    curr_jour += j[0]
    if curr_jour > j[1]:
        can = False
        break

print("Yes" if can else "No")


Measured memory_bytes: 31796
/* ex4_1
   kohei0713 */

#include <stdio.h>

int main(void){
    
    int treeNumber, treeWatch, answer;
    
    //input
    scanf("%d %d", &treeNumber, &treeWatch);

    //treeNumber / (2 * treeWatch + 1)の天井関数
    if(treeNumber % (2 * treeWatch + 1) == 0){
        answer = treeNumber / (2 * treeWatch + 1);
    }else{
        answer = treeNumber / (2 * treeWatch + 1) + 1;
    }
    
    //answerを表示
    printf("%d\n", answer);

    return 0;
}

Measured memory_bytes: 128
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 105
#define maxM 2005
#define oo 1000000000000000007LL
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

ll add(ll &a, const ll &b) {a = min(a+b, oo);}

ll mul(const ll &a, const ll &b) {
    if (a == 0) return 0;
    if ((a*b)/a != b) return oo;
    return min(oo, a*b);
}

int n, m, z[maxM][maxN];
ll id, cnt[maxM], dp[maxM];
string s[maxN];

int main () {
    scanf("%d%d%lld", &n, &m, &id);
    fto(i, 0, n-1) cin >> s[i];

    cnt[0] = 1;
    fto(i, 1, m) {
        fto(j, 0, n-1) {
            if (i >= sz(s[j])) add(cnt[i], cnt[i-sz(s[j])]);
        }
    }

//    fto(i, 0, m) printf("%lld ", cnt[i]);
//    puts("");

    dp[0] = 1;
    string ans;
    fto(i, 1, m) {
//        debug(i);
        fto(c, 'a', 'z') {
            ll sum = 0;
            fto(j, 0, n-1) {
                fto(p, max(1, i-sz(s[j])+1), min(i, m-sz(s[j])+1)) {
                    if (z[p][j] == i-p && s[j][z[p][j]] == c) {
//                        printf("%d %d\n", j, p);
                        add(sum, mul(dp[p-1], cnt[m-(p+sz(s[j])-1)]));
                        if (sum == oo) break;
                    }
                }
                if (sum == oo) break;
            }
//            printf("%c %lld\n", c, sum);
            if (sum >= id) {
                ans += c;
                fto(j, 0, n-1) {
                    fto(p, max(1, i-sz(s[j])+1), i) {
                        if (z[p][j] == i-p && s[j][z[p][j]] == c) ++z[p][j];
                    }
                    if (i >= sz(s[j]) && z[i-sz(s[j])+1][j] == sz(s[j]))
                        add(dp[i], dp[i-sz(s[j])]);
                }

                break;
            } else id -= sum;
        }

        if (sz(ans) != i) {
            puts("-");
            return 0;
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 4124
#include <stdio.h>
#include <stdlib.h>

int A[10], Req[50][4];
int N, M, Q;

int score(int idx) {
    int i, v, max = 0;
    if (idx == N) {
        for (i = 0; i < Q; i++) {
            if (A[Req[i][1] - 1] - A[Req[i][0] - 1] == Req[i][2]) max += Req[i][3];
        }
        return max;
    }
    v = idx ? A[idx - 1] : 1;
    while (v <= M) {
        A[idx] = v;
        int temp = score(idx + 1);
        if (max < temp) max = temp;
        v++;
    }
    return max;
}

int main() {
    int i, j, max = 0;
    scanf("%d %d %d", &N, &M, &Q);
    for (i = 0; i < Q; i++)
        for (j = 0; j < 4; j++)
            scanf("%d", &Req[i][j]);

    printf("%d\n", score(0));
    return 0;
}

Measured memory_bytes: 1716
//#define _USE_MATH_DEFINES
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }
inline int safe_mul(const int x, const int y) __attribute__ ((warn_unused_result));


int main()
{
//    freopen("in.txt","r", stdin);
//    freopen("out.txt", "w", stdout);
//    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int64_t> a(n);
    for (auto& x : a)
        cin >> x;

    int64_t st = 0;

    for(int i = 0, sign = 1; i < n; ++i, sign *= -1)
        st += sign * a[i];


    for (int i = 0; i < n; ++i) {
        cout << st << ' ';
        st = 2LL * (a[i] - st / 2);
    }
}


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

int main(){
    int n;
    cin>>n;
    map<int,ll>mp;
    vector<int>a(n);
    rep(i,n){
        cin>>a[i];
        mp[a[i]]++;
    }
    ll ans=0;
    for(auto&p:mp){
        ans+=p.second*(p.second-1)/2;
    }
    rep(i,n){
        cout<<ans-(mp[a[i]]*(mp[a[i]]-1)/2)+((mp[a[i]]-1)*(mp[a[i]]-2)/2)<<endl;
    }
    return 0;
}

Measured memory_bytes: 10240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    ll N, D; cin >> N >> D;
    vector<ll> X(N), Y(N);
    REP(n, N) {
        cin >> X[n];
        cin >> Y[n];
    }

    ll ans = 0;
    REP(n, N) {
        double d = sqrt(X[n]*X[n] + Y[n]*Y[n]);
        if (d <= D) ans++;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
int n, m, x;
int main()
{
    //freopen("test.inp","r", stdin);
    cin >> n >> m;
    long long tmp = 0;
    for (int i = 1; i <= m; i++)
    {
        cin >> x;
        tmp += x;
    }
    n = n-tmp;
    cout << max(-1, n);
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    bool x=false;
    cin>>n;
    while(n>0)
    {
    	if(n%10==9)
    		x=true;
    	n/=10;
    }
    x?	cout<<"Yes":cout<<"No";
}

Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#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 LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}

struct edge { int to, cost;};

class Dijkstra{
private:
    vector< vector<edge> > g;

public:
    Dijkstra(){};
    Dijkstra(int size){
        g.resize(size);
    }

    vi dist;

    void add(int a, int b, int c){//無向辺
        edge e1 = {b, c}, e2 = {a, c};
        g[a].push_back(e1);
        g[b].push_back(e2);//有向辺の場合はここをコメントアウトする
    }

    void calc(int s){
        priority_queue< pii, vector<pii>, greater<pii> > q;
        int n = g.size();
        dist = vi (n, INF);
        dist[s] = 0;
        q.push(pii(0, s));

        while(!q.empty()){
            pii p = q.top();
            q.pop();
            int v = p.second;
            if(dist[v] < p.first)continue; //更新されていたら何もしない
            for(int i = 0; i < g[v].size(); i++){
                edge e = g[v][i];
                if(dist[e.to] > dist[v] + e.cost){
                    dist[e.to] = dist[v] + e.cost;
                    q.push(pii(dist[e.to], e.to));
                }
            }
        }
    }

};

signed main(void) {
    int i,j;
    int n,m,s,t;
    cin >> n >> m >> s >> t;
    s--,t--;
    Dijkstra dij = Dijkstra(n);
    rep(i,m){
        int x,y;
        cin >> x >> y;
        x--,y--;
        dij.add(x,y,1);
    }
    dij.calc(s);
    int dist = dij.dist[t] - 2;
    map<int,int> ma1;
    rep(i,n)ma1[dij.dist[i]]++;
    dij.calc(t);
    map<int,int> ma2;
    rep(i,n)ma2[dij.dist[i]]++;
    int ans = 0;
    for(auto itr = ma1.begin(); itr != ma1.end(); itr++){
        int x = itr->first;//きょり
        int a = itr->second;//個数
        int b = ma2[dist-x];//個数
        ans += a*b;
    }
    cout << ans << endl;
}



Measured memory_bytes: 16504
S=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
C=input()
for i in range(25):
    if S[i]==C:
        K=i+1
        break
    
if S[25]==C:
    K=0

print(S[K])


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

char tolowr(char c) {
  if ((c >= 'A') && (c <= 'Z')){
    return (c + 0x20);
  } else {
    return 0;
  }
}


int main(){
    int i,flug=0;
    string S;
    string T;
    int s,t;
    char c;

    cin >> S >> T;

    s=S.size();
    t=T.size();
    
    for(i=0;i<s;i++){
        if(S.at(i)!=T.at(i)){
            flug=1;
            //cout << i << ":" << flug << endl;
        }
    }

    //cout << flug << endl;
    
    //transform (T.begin (), T.end (), T.begin (), tolower);
    //t=
    //cout << T.at(n)-0x20 << endl;
    
    if(t-s==1 && flug==0 && T.at(t-1)==tolower(T.at(t-1))){
        if(t<=11){

                cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){

 string s;cin>>s;
 int count = 0;
 int ans = 0;
  REP(i,s.length()){
    if(s[i]=='A'||s[i]=='G'||s[i]=='C'||s[i]=='T'){
      count++;

    }else{
      count = 0;
    }
    ans = max(ans,count);
  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
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 X = sc.nextInt();
		String ans = "";

		if(A > X) {
			ans = "NO";
		} else if(A + B < X) {
			ans = "NO";
		} else {
			ans = "YES";
		}

		System.out.println(ans);

	}

}


Measured memory_bytes: 20820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    int x;
    cin >> x;
    int a = x / 1000, b = (x % 1000) / 100, c = (x % 100) / 10, d = (x % 10);
    vector<int> vec;
    vec.push_back(b);
    vec.push_back(c);
    vec.push_back(d);
    rep(i, 0, 1 << 3) {
        int sum = a;
        rep(j, 0, 3) {
            if (i & 1 << j) {
                sum += vec[j];
            } else {
                sum -= vec[j];
            }
        }
        if (sum == 7) {
            cout << a;
            rep(j, 0, 3) {
                if (i & 1 << j) {
                    cout << "+";
                } else {
                    cout << "-";
                }
                cout << vec[j];
            }
            cout << "=7\n";
            return 0;
        }
    }
}

Measured memory_bytes: 3612
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return read.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtype!real;

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

void solve(){
	int n = rint;
	
	int[][] af;
	foreach(i; 0 .. n) af ~= rint(n - 1).map!(x => x - 1).array;
	log("af:", af);
	
	int[] js = new int[](n);
	S[] q;
	int qx = 0;
	foreach(i; 0 .. n){
		int x = af[i][js[i]];
		if(i < x && af[x][js[x]] == i) q ~= S(i, x);
	}
	int ans = 0;
	while(1){
		log("q:", q, "qx:", qx);
		if(qx >= q.length){
			bool f = 0;
			foreach(i; 0 .. n) if(js[i] < n - 1) f = 1;
			if(f){
				"-1".writeln;
				return;
			}
			else break;
		}
		int qx0 = q.length.to!int;
		while(qx < qx0){
			S p = q[qx];
			js[p.x] += 1, js[p.y] += 1;
			if(js[p.x] < n - 1){
				int x2 = af[p.x][js[p.x]];
				if(af[x2][js[x2]] == p.x) q ~= S(p.x, x2);
			}
			if(js[p.y] < n - 1){
				int y2 = af[p.y][js[p.y]];
				if(af[y2][js[y2]] == p.y) q ~= S(p.y, y2);
			}
			qx += 1;
		}
		ans += 1;
	}
	
	ans.writeln;
}

struct S{
	int x, y;
}


Measured memory_bytes: 18300
#include<stdio.h>

int main(){
    
    int counter = 0;
    int test_case;
    
    while(1){
        scanf("%d", &test_case);
        if(test_case == 0) break;
        else printf("Case %d: %d\n", counter+1, test_case);
        counter++;
    }
}


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

#define ll long long int

#define pi 2*acos(0.0)
#define mod 1000000007

#define fast   ios_base::sync_with_stdio(false);cin.tie(NULL);

#define pii pair<ll,ll>

#define pb push_back

#define Bit_off(val,pos)       (val & (~(1<<pos)))
#define Bit_on(val,pos)        (val | (1<<pos))
#define Bit_toggle(val,pos)    (val ^ (1<<pos))
#define Bit_check(val,pos)     (bool)(val & (1<<pos))
#define odd_even(val)          (bool)(val & 1)
#define koita_1_ase(val)       (__builtin_popcount(val))

//ll Big_Mod(ll v1, ll p, ll md)  { ll res=1; v1=v1%md; while (p > 0){if (p & 1)res = (res * v1) % md; p =p>>1; v1 = (v1 * v1) % md;}return res;}
ll ar[500009],br[500009],cr[500009],tr[500009];
map<ll,ll>mp;
vector<ll>v;
string s;

struct evan
{
    ll l,r,pos;
}st[500009];
bool com(evan i1,evan i2)
{
    return (i1.r < i2.r);
}

int main()
{
    ll a,b,c,d,e,i,j,k,x,y,z,f,g,h,n,m;
    char ch;
    cin>>ch;
    if(ch>='a' and ch<='z')
    {
        cout<<"a"<<endl;
    }
    else
    {
        cout<<"A"<<endl;
    }
}






Measured memory_bytes: 3596
/**
*    author:  yuya1234
*    created: 24.06.2020 16:03:13
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int n;
    cin>>n;

    ll a[100];
    ll minN = 1000000000, maxN = 0, tmp;
    REP(i,n)
    {
        cin>>tmp;
        minN=min(minN,tmp);
        maxN=max(maxN,tmp);
    }

    cout<<maxN-minN<<endl;

    return 0;
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)


void func(long long N, long long L, std::vector<std::string> S){
    sort(S.begin(),S.end());

    REP(i,0,N)cout<<S[i];
    cout<<endl;
}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    long long L;
    scanf("%lld",&L);
    std::vector<std::string> S(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> S[i];
    }
    func(N, L, std::move(S));
    return 0;
}


Measured memory_bytes: 256
import math

A,B,H,M = list(map(float,input().split()))

hm = H + M / 60
h = hm * 30
m = M * 6

sa = abs(h - m)
ans = (A**2 + B**2 - A * B * math.cos(math.radians(sa)) * 2) ** 0.5


# if int(sa) == 0:
#     if int(h) == int(m):
#         ans = abs(A - B)
#     else:
#         ans = A + B

print(ans)

Measured memory_bytes: 9508
n=int(input())
a=list(map(int,input().split()))
count=0
f=True
while f:
    b=0
    for i in range(n):
        if a[i]%2==0:
            count+=1
            a[i]/=2

            if a[i]%2==0:
                b+=1

    if b==0:
        print(count)
        exit()


Measured memory_bytes: 4148
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N;
    cin >> N;
    vector<double> p(N);
    Rep (i, N) cin >> p[i];

    vector<vector<double>> dp(N+1, vector<double>(N+1, 0));
    dp[0][0] = 1;
    Rep (i, N) {
        Rep (j, N) {
            dp[i+1][j] += dp[i][j] * (1-p[i]);
            dp[i+1][j+1] += dp[i][j] * p[i];
        }
    }

    // Rep (i, N+1) {
    //     Rep (j, N+1) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    double ans = 0;
    for (ll i = (N+1)/2; i <= N; i++) ans += dp[N][i];

    cout << setprecision(10) << ans << "\n";
}

Measured memory_bytes: 70784
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())

    for i in range(N, 1000):
        if len(set(str(i))) == 1:
            return print(i)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
int func(string s,string t){
  int ans=0;
  for(char w='a';w<='z';w++){
    bool b=false,f=false;
    for(int j=0;j<s.size();j++){
      if(s[j]==w)b=true;
    }
    for(int i=0;i<t.size();i++){
      if(t[i]==w)f=true;
    }
    if(b&&f)ans++;
  }
  return ans;
}
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int ans=0;
  for(int i=1;i<n;i++){
    int tmp=func(s.substr(0,i),s.substr(i));
    if(tmp>ans)ans=tmp;
  }
  cout <<ans<<endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val n = sc.nextLong()
        var a = 1L
        var ans = Int.MAX_VALUE
        while (a * a <= n) {
            if (n % a == 0L) {
                val b = n / a
                ans = Math.min(ans, Math.max(a.toString().length, b.toString().length))
            }
            a++
        }

        println(ans)
    }
}

class MyScanner {
    private var ptr = 0
    private var l = listOf<String>()

    fun next(): String {
        while (l.size <= ptr) {
            l = readLine()!!.split(' ')
            ptr = 0
        }
        return l[ptr++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun list(): List<String> {
        ptr = l.size
        return readLine()!!.split(' ')
    }

    fun intList() = list().map { s -> s.toInt() }
    fun longList() = list().map { s -> s.toLong() }
    fun doubleList() = list().map { s -> s.toDouble() }

    fun array() = list().toTypedArray()
    fun intArray() = intList().toIntArray()
    fun longArray() = longList().toLongArray()
    fun doubleArray() = doubleList().toDoubleArray()
}


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

int main(){
    int k,s;
    cin >> k >> s;
    int c=0;
    int cnt=0;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++)
            if(i+j>s) continue;
            else if(i+j==s) cnt++;
            else{
                c=s-(i+j);
                if(c<=k) cnt++;
            }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <numeric>

#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
using namespace std;
using ll = long long;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}



int main(){
	ll n,pos,x[100000],memo;
  	cin >> n >> pos;
  
  	rep(i,n){
    	cin >> x[i];
      	if(i == 0){
          memo = abs(pos-x[i]);
        }
		else{
          memo = gcd(memo,abs(pos-x[i]));
        }
  	}
      cout << memo << endl;
  	
 	return 0; 
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

signed main(){

    int N;
    cin >> N;
    vector<int> a(N);
    readvec(a);

    int ans = 0;
    REP(i, N - 1){
        if(a[i] == a[i + 1]){
            ans++;
            a[i + 1] = 101;
        }
    }

    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

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

typedef long long lint;
typedef long double ldouble;
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = 1e18;
const lint MOD = 1e9 + 7;
const lint inv = 1e9 + 5;

int main(){
    int n;
    cin >> n;
    vector<double> t(n), v(n);
    rep(i, n){
        cin >> t[i];
        t[i] *= 2.0;
    }
    t.push_back(1.0);
    rep(i, n){
        cin >> v[i];
        v[i] *= 2.0;
    }
    v.push_back(0.0);
    repr(i, n){
        v[i] = min(v[i], v[i+1] + t[i]);
    }
    rep(i, n){
        t[i+1] += t[i];
    }
    int sum = t[n-1];
    double ans = 0.0, nowv = 0.0;
    int j = 0;
    rep(i, sum){
        if(i >= t[j]){
            j++;
        }
        double limit = min(v[j], v[j+1] + t[j] - i - 1);
        ans += nowv;
        if(nowv < limit){
            ans += 0.5;
            nowv += 1.0;
        }else if(nowv > limit){
            ans -= 0.5;
            nowv -= 1.0;
        }
    }
    ans /= 4.0;
    cout << fixed << setprecision(6) << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000)
h, w = map(int, input().split())
cam = [input() for _ in range(h)]
painted = [[False for i in range(w)] for j in range(h)]

def dfs(x, y):
    global cnt
    if x < 0 or y < 0 or x > h-1 or y > w-1:
        return
    elif cam[x][y] == ".":
        return
    elif painted[x][y]:
        return
    cnt += 1
    painted[x][y] = True
    dfs(x-1, y)
    dfs(x, y-1)
    dfs(x+1, y)
    dfs(x, y+1)
    
for i in range(h):
    for j in range(w):
        cnt = 0
        if cam[i][j] == "#":
            dfs(i, j)
        if cnt == 1:
            painted[i][j] = False
            
flag = False
for i in range(h):
    for j in range(w):
        if cam[i][j] == "#":
            if not painted[i][j]:
                flag = True
                break
        elif cam[i][j] == ".":
            if painted[i][j]:
                flag = True
                break
    if flag:
        break
if flag:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 4724
#include<iostream>
using namespace std;
int main(){

    int a,b,x;
    cin >> a >> b >> x;
    if (a>x){
        cout << "NO" << endl;
    }else{
        if(a==x){
            cout << "YES" << endl;
        }else{
            if(b>=x-a){
                cout << "YES" << endl;
            }else{
                cout << "NO" << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string S;
  cin >> S;
  bool bl = true;
  if (S[2] != S[3] || S[4] != S[5]) bl = false;
  puts(bl ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 3560
#include "bits/stdc++.h"
using namespace std;
long long A[1005] , B[1005] , C[1005] , D[1000005] , E[3000005];

int main(){
    int X , Y , Z , K , i;
    scanf( "%d%d%d%d" , &X , &Y , &Z , &K );

    for( i = 1 ; i <= X ; ++i )
        scanf( "%lld" , A + i );
    for( i = 1 ; i <= Y ; ++i )
        scanf( "%lld" , B + i );
    for( i = 1 ; i <= Z ; ++i )
        scanf( "%lld" , C + i );

    int j , k = 1;

    for( i = 1 ; i <= X ; ++i ){
        for( j = 1 ; j <= Y ; ++j )
            D[k++] = A[i] + B[j];
    }

    sort( D + 1 , D + k , greater<long long>() );
    k = min( K , X * Y );
    int p = 1;

    for( i = 1 ; i <= k ; ++i ){
        for( j = 1 ; j <= Z ; ++j )
            E[p++] = D[i] + C[j];
    }

    sort( E + 1 , E + p , greater<long long>() );

    for( i = 1 ; i <= K ; ++i )
        printf( "%lld " , E[i] );
    
    puts( "" );
    return 0;
}

Measured memory_bytes: 31488
N = int(input())
S = input()

num = "1234567890"

ans = 0
for a in num:
    pa = S.find(a)
    if pa == -1:
        continue
    for b in num:
        pb = S.find(b, pa + 1)
        if pb == -1:
            continue
        for c in num:
            pc = S.find(c, pb + 1)
            if pc == -1:
                continue
            ans += 1
print(ans)


Measured memory_bytes: 9272
N = int(input())

def check(num):
    # print(num)
    if num//100000 != 0:
        return False
    elif num//10000 != 0:
        #print(10000,N//10000)
        return True
    elif num//1000 != 0:
        #print(1000,N//1000)
        return False
    elif num//100 != 0:
        #print(100,N//100)
        return True
    elif num//10 != 0:
        #print(10,N//10)
        return False
    else:
        #print(N)
        return True

print(sum(check(i) for i in range(1,N+1)))

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

int main(int argc, char **argv) {
  string S;
  cin >> S;
  S = S + 'R';
  size_t num = S.size();

  bool rflag = true; // True: right, False: left.
  size_t Rsum = 0, Lsum = 0;
  size_t Rbegin = 0, Lbegin = 0;
  size_t Rend = 0, Lend = 0;
  size_t Rcnt = 0, Lcnt = 0;

  for (size_t i = 0; i < num; i++) {
    if (rflag && S[i] == 'L') {
      // RR...RL
      rflag = false;
      Rend = i - 1;

      // Rbegin ~ Rend - 1
      for (size_t j = Rbegin; j < Rend; j++) {
        cout << 0 << " ";
      }

      Lbegin = i;
      continue;
    }
    if (!rflag && S[i] == 'R') {
      // LL...LR
      rflag = true;
      Lend = i - 1;

      size_t Rlen = Rend - Rbegin + 1;
      size_t Llen = Lend - Lbegin + 1;
      Rcnt = (Rlen + 1) / 2 + Llen / 2;
      Lcnt = (Llen + 1) / 2 + Rlen / 2;

      // Rend
      cout << Rcnt << " ";
      // Lbegin
      cout << Lcnt << " ";
      for (size_t j = Lbegin + 1; j <= Lend; j++) {
        cout << 0 << " ";
      }

      Rbegin = i;
      continue;
    }
  }

  cout << endl;

  return 0;
}


Measured memory_bytes: 636
N = int(input())
S = []
for i in range(N):
    S.append("".join(sorted(input())))
S.sort()
C = []
cnt = 1
for i in range(N - 1):
    if S[i] == S[i + 1]:
        cnt += 1
    else:
        C.append(cnt)
        cnt = 1
C.append(cnt)
ans = 0
for cnt in C:
    ans += cnt * (cnt-1) // 2
print(ans)

Measured memory_bytes: 11272
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int t,i,l,r;
char chr;

template<typename T>
struct BIT {
    int n;
    vector<T> d;
    BIT(int n=0):n(n),d(n+1) {}
    void add(int i,T x=1){
        for(i++;i<=n;i += i&-i){
            d[i] += x;
        }
    }
    T sum(int i){
        T x = 0;
        for(i++;i;i-= i&-i) {
            x += d[i];
        }
        return x;
    }
    // 下の2個の操作を使う時は上の2個の操作が使えない事に注意
    T getmax(int i){ // get max(d[i]) for i = 0,1,...,i-1,i
        T x = 0;
        for(i++;i;i-=i&-i) {
            x = max(x, d[i]);
        }
        return x;
    }
    void setmax(int i, int v){ // set d[i] = max(d[i], v)
        for(i++;i<=n;i+=i&-i){
            d[i] = max(d[i], v);
        }
    }
};

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    vector<BIT<int>> bit(26,BIT<int>(500005));
    int n;
    string s;
    int q;
    cin >> n >> s >> q;
    rep(i,n){
        int x = s[i] - 'a';
        bit[x].add(i+1,1);
    }
    rep(_,q){
        cin >> t;
        if(t==1){
            cin >> i >> chr;
            int x = s[i-1] - 'a';
            bit[x].add(i,-1);
            bit[chr-'a'].add(i,1);
            s[i-1] = chr;
        }else{
            cin >> l >> r;
            int ans = 0;
            rep(i,26){
                if(bit[i].sum(r) - bit[i].sum(l-1))ans++;
            }
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 53120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M,i,sum=0,keta=1e8,a[8]={0};
  cin >> N ;
  M=N;
  for (i=0;i<9;i++){
	a[i]=N/keta;
//    cout <<"10の"<<8-i<<"乗="<< a[i]<<endl;
//    cout <<keta<<endl;
    N=N-a[i]*keta;
	keta=keta/10;
    sum=sum+a[i];
//    cout <<"sum="<<sum<<endl;
  }
//  cout << M%sum<<endl;
  if(M%sum==0){
   cout << "Yes" <<endl; 
  }
  else
    cout<< "No" <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];

int main() {
	int n, k;
	cin >> n >> k;
	vector<int>l(n);
	rep(i, n) {
		cin >> l[i];
	}
	sort(l.rbegin(), l.rend());
	int ans = 0;
	rep(i, k) {
		ans += l[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

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

        String s = scanner.nextLine().toLowerCase();
        boolean flag = false;
        if (s.charAt(2)==s.charAt(3)&&s.charAt(4)==s.charAt(5)){
            System.out.println("Yes");
        }else
            System.out.println("No");
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename key>
using ordered_set = tree<key, null_type, less<key>, rb_tree_tag, tree_order_statistics_node_update>;
#define F first
#define S second
#define T second.first
//#define C second.second
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);
#define all(v) v.begin(),v.end()
#define OO 0x3f3f3f3fLL
#define INF 0x3f3f3f3f3f3f3f3fLL
#define sz(s) (int)(s.size())
#define RT(s) return cout<<s,0
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef pair<ll,pair<ll,ll>> piii;
const int N = 2e5+5, M= 20, mod = 1000000000;
const double EPS = 1e-10;


int main(){
    FIO
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    ll n;
    cin>>n;
    ll div = (n+999)/1000;
    ll ans = 1000*div;
    ans -= n;
    cout<<ans;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef long double ld;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 3;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < b; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define lb lower_bound
#define ub upper_bound
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod);
#define mod_in(a) exp(a, mod-2)
#define ncr(n, r) ((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod)
#define deb(x) cout << #x << " " << x << endl;
#define flash ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
ll prime[100002];
ll exp(ll a,ll b);
void sieve(ll n);
ll gcd(ll a ,ll b);
ll countdigit(ll n);
vector<ll>ft;

ll mul(ll a, ll b){
    ll ans= ((a%mod)*(b%mod))%mod;
    return ans%mod;
}
ll sub(ll a, ll b){
    ll ans = (a-b+mod)%mod;
    return ans;
}
ll add(ll a,ll b){
    ll ans = (a+b)%mod;
    return ans;
}

void solve() {
    string s;
    cin>>s;
    string r;
    if(s[s.size()-1]=='s')r+="es";
    else r+="s";
    cout<<s<<r<<endl;
}


int main()
{
    flash;
    ll t=1;
    //ft.pb(1);
    //fact(10000001);
   // cin >> t;
    while(t--) { 
        solve();
    }
}

//
//
//
//
//
// IMPORTANT FUNCTIONS
ll exp(ll a, ll b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res%mod;
}
ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}
void sieve(ll n) {
    for(ll i=0;i<=n;i++) {
        prime[i]=1;
    }
    prime[0]=0;prime[1]=0;
    for(ll i=2;i<=n;i++) {
        if(prime[i]==1) {
            for(ll j=2;i*j<=n;j++) {
                prime[i*j]=0;
            }
        }
    }
}
ll countdigit(ll  n)
{
    return floor(log10(n) + 1);
}

Measured memory_bytes: 3680
n = int(input())
A = list(map(int, input().split()))
b = [0]*n
if n % 2 == 0:
    k = 1
else:
    k = -1
index_= int(n/2)
for i in range(n):
    index_ += i * k
    b[index_] = A[i]
    k *= -1
print(*b)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = (int)(n)-1; i >=0; i--)

using ll = long long;

int main(){
  int n,k;
  cin >> n >> k;
  set<int> s;
  vector<int> a(n+10);
  rep(i,n+10)a.at(i) = n+1;
  rep(i,n){
    int tmp;
    cin >> tmp;
    if(a.at(tmp)==n+1)a.at(tmp) = 1;
    else a.at(tmp)++;
    s.insert(tmp);
  }
  int l = s.size();//種類
  int ans = 0;
  sort(a.begin(),a.end());
  rep(i,n+5){
    if(l<=k)break;
    ans+=a.at(i);
    l--;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 10368
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	if (x == y)return 1;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int n, p[21451];
int ta[20010];
int ans[20010];

signed main() {
	cin >> n;
	rep(i, n) {
		cin >> p[i];
		ta[p[i] - 1] = n - i;
	}
	cout << 1 << " ";
	int cnt = 1;
	for (int i = 1; i < n; i++) {
		if (ta[i - 1] > ta[i]) {
			cout << cnt + (ta[i - 1] - ta[i]) + 1;
			cnt += (ta[i - 1] - ta[i]) + 1;
		}
		else {
			cout << cnt + 1;
			cnt++;
		}
		if (i == n - 1)cout << endl;
		else cout << " ";
	}
	ans[n - 1] = 1;
	for (int i = n - 2; i >= 0; i--) {
		if (ta[i] < ta[i + 1])ans[i] = ans[i + 1] + (ta[i + 1] - ta[i]) + 1;
		else ans[i] = ans[i + 1] + 1;
	}
	rep(i, n) {
		if (i == n - 1)cout << ans[i] << endl;
		else cout << ans[i] << " ";
	}
}

Measured memory_bytes: 1024
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

a, b, c = rs()
print(a[0] + b[0] + c[0])









Measured memory_bytes: 26928
n,a,b,*h=map(int,open(0).read().split())
i,j=0,-(-max(h)*n//a)
while True:
  if j-i<2:
    print(j)
    break
  k=c=(j+i+1)//2
  for t in h:
    t-=b*k
    if t>0:
      c+=-t//(a-b)
  if c>=0:
    j=k
  else:
    i=k

Measured memory_bytes: 71228
#include <iostream>
using namespace std;
 
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (n == i * j) {
				cout << "Yes" << '\n';
				return 0;
			}
		}
	}
	cout << "No" << '\n';
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <cmath>
#include <algorithm>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){

ll n,a,b;

cin >> n >> a >> b;

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

ll sum = 0;

for(int i = 0; i < n-1; i++){
sum += min((x[i+1] -x[i])*a,b);
}

cout << sum << endl;
return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



int N;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    int macnt = -1, ans = -1;
    rep(x, 1, N + 1) {
        int cnt = 0;
        int y = x;
        while (y % 2 == 0) y /= 2, cnt++;
        if (macnt < cnt) macnt = cnt, ans = x;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256