akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

// definitions
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++)
#define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--)
#define high(x) __builtin_popcountll(x)
#define pb push_back
#define pf push_front
#define mod1 998244353
#define mod 1000000007
#define MAX_CHAR 256
#define pi 3.1415926535897932384



using namespace std;
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef vector<tuple<long long , long long , long long> > vtup;
typedef deque <long long> dql;
typedef deque <char> dqc;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

ll INF=1e18;



// prevent collisions in unordered_map
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

template <class T>
void read(T arr[],ll n) {rep(i,0,n) cin>> arr[i];}

typedef unordered_map <long long, long long, custom_hash> umap;


// standard functions
ll mystoi(string str)
{
    stringstream ss(str);
    ll ans=0;
    ss >> ans;

    return ans;
}

ll exp(ll x, ll ex, ll p) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x)%p;
        ex >>= 1ll;
        x = (x * x)%p;
    }
    return ans;
}

bool sort_cond(const pair<ll,ll> &a, const pair <ll,ll> &b)
{
    return ((a.f-a.s)>(b.f-b.s));
}

vl primeFactors(ll n)  
{
    vl pf;
    while (n % 2 == 0)  
    {  
        pf.pb(2);
        n = n/2;  
    }  

    for (ll i = 3; i <= sqrt(n); i = i + 2)  
    {  
        while (n % i == 0)  
        {  
            pf.pb(i);  
            n = n/i;  
        }  
    }  
  
    if (n > 2)  
        pf.pb(n);  
    return pf;
}

// code beigns in main
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); cout.tie(0);
    ll t=1;
    // cin >> t;
    while(t--)
    {
        ll n;
        cin >> n;

        vl ans=primeFactors(n);
        sort(all(ans));
        ans.pb(-1);

        vl count;
        ll c=1;
        rep(i,0,ans.size()-1)
        {
            if(ans[i]!=ans[i+1])
            {
                count.pb(c);
                c=1;
            }
            else 
                c++;
        }

        ll fi=0;
        rep(i,0,count.size())
        {
            ll a=sqrt(2*count[i]);
            ll b=a-1;
            if(a*(a+1)<=2*count[i])
            {
                fi+=a;
            }
            else
            {
                fi+=b;
            }
        }

        cout << fi << endl;
    }
}

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

using namespace std;
string s[60] = {};
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  string ans;
  for (char c = 'a'; c <= 'z'; c++)
  {
    int small = 100;

    for (int i = 0; i < n; i++)
    {
      int cnt = 0;
      for (int j = 0; j < s[i].length(); j++)
      {
        if (s[i][j] == c)cnt++;

      }
      small = min(small, cnt);
    }
    for (int i = 0; i < small; i++)
    {
      ans += c;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3584
result = []

while True:

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

    if n == 0 and x == 0:
        break

    res = 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            for k in range(j+1, n+1):
                if x == i + j + k:
                    res += 1

    result.append(res)

for result in result:
    print(result)



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

struct UnionFindTree {
    vector<int> par, sz;
    int operator [](int x) { return find(x); }
    void build(int n) { par.assign(n, -1); sz.assign(n, 1); }
    int find(int x) { return par[x] < 0 ? x : (par[x] = find(par[x])); }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) { return sz[find(x)]; }
    bool unite(int x, int y) {
        if ((x = find(x)) == (y = find(y))) return 0;
        par[x] = min(par[x], par[y] - 1); sz[x] += sz[y]; par[y] = x; return 1;
    }
    bool uniteByRank(int x, int y) { return par[find(x)] > par[find(y)] ? unite(y, x) : unite(x, y); }
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    for (int i = 0; i < M; ++i) cin >> A[i] >> B[i], A[i]--, B[i]--;

    UnionFindTree uf;
    uf.build(N);

    vector<ll> ans(M, (ll)N * (N - 1) / 2);
    for (int i = M - 1; i > 0; --i) {
        ans[i - 1] = ans[i];
        if (!uf.same(A[i], B[i])) {
            int s = uf.size(A[i]), t = uf.size(B[i]);
            ans[i - 1] -= (ll)s * t;
            uf.uniteByRank(A[i], B[i]);
        }
    }

    for (ll x : ans) cout << x << endl;
}


Measured memory_bytes: 3712
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
	int N,M,X;
	cin >> N >> M >> X;
	int right = 0;
	int left = 0;
	for (int i = 0; i < M; ++i) {
		int A;
		cin >> A;
		if (A > X) {
			++right;
		}
		else {
			++left;
		}
	}
	cout << min(right,left) << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <vector>
#include <map>
#include <algorithm>
//#include <functional>
//#include <cmath>


struct restaurant_info{
    std::string name;
    int32_t score;
    int32_t id;
};
using restaurants = std::vector<restaurant_info>; 

bool guide_book_order(restaurant_info lhs, restaurant_info rhs){
    if(lhs.name == rhs.name){
        return lhs.score > rhs.score;
    }
    else {
        return lhs.name < rhs.name;
    }
}

int main(){
    int32_t N;
    std::cin >> N;

    restaurants restaurant_vect(N);
    for(int32_t i = 0; i < N; i ++){
        std::cin >> restaurant_vect[i].name >> restaurant_vect[i].score;
        restaurant_vect[i].id = i + 1;
    }

    std::sort(restaurant_vect.begin(), restaurant_vect.end(), guide_book_order);
    for(int32_t i = 0; i < N; i ++){
        std::cout << restaurant_vect[i].id << std::endl;
    }

    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
	char s[100100];
	while(~scanf("%s",s))
	{
		int len = strlen(s);
		for(int i=0;i<len;++i)
		{
			if((i+1)%2!=0)
				printf("%c",s[i]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 384
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_cumsum, B_cumsum = [0], [0]

for i in range(n):
    A_cumsum.append(A_cumsum[i] + A[i])
    
for j in range(m):
    B_cumsum.append(B_cumsum[j] + B[j])
    
ans, j = 0, m

for i in range(n + 1): # 0を最初に代入した分
    if A_cumsum[i] > k:
        break
    while A_cumsum[i] + B_cumsum[j] > k:
        j -= 1
    ans = max(ans, i + j)

print(ans)

Measured memory_bytes: 132492
// =====================================================================================
//
//       Filename:  atcoder.cpp
//
//    Description:  
//
//        Version:  1.0
//        Created:  26/04/20 03:38:51 AM IST
//       Revision:  none
//       Compiler:  g++
//
//         Author:  Kiran Bhanushali (), kiranbhanushali143.kb143@gmail.com
//   Organization:  
//
// =====================================================================================

#include<bits/stdc++.h>


using namespace std;

#define int long long 
#define pb push_back
//#define _SHOW_TIME

void solve(){
  int a , b , c;
  cin>>a>>b>>c;
  for(int i=0 ; i<b;i++){
      if(a*i%b==c){
          cout<<"YES"<<"\n";
          return ;
      }
  }
  cout<<"NO"<<"\n";
}
int32_t main(){
 /////////////////////////////////////
    #ifdef _SHOW_TIME
	int tt = (int) clock();
    #endif
    /////////////////////////////////////
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /////////////////////////////////////
    solve();
    /////////////////////////////////////
    #ifdef _SHOW_TIME
        cerr << "TIME = " << (double)(clock() - tt) / CLOCKS_PER_SEC << endl;
    #endif
    /////////////////////////////////////
    return 0;

}



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

using namespace std;

int main(){
    int S;
    int h,m,s;

    cin >> S;

    h = S / 3600;
    m = (S % 3600) / 60;
    s = (S % 3600) % 60;

    cout << h << ":" << m << ":" << s << endl;

    return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

int main(){
    string s, t;
    cin >> s >> t;
    int sn[26] = {}, tn[26] = {};

    rep(i, (int)s.size()){
        sn[s[i] - 'a']++;
        tn[t[i] - 'a']++;
    }
    sort(sn, sn + 26);
    sort(tn, tn + 26);
    rep(i, 26){ 
        if(sn[i] != tn[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 776
from collections import deque
S=list(input())
Q=int(input())
ls=[list(input().split()) for _ in range(Q)]
D=deque()
for i in range(len(S)):
  D.append(S[i])  
a=1
for i in range(Q):
  if ls[i][0]=="1":
    a*=(-1)
  else:
    if (ls[i][1]=="1" and a==1) or (ls[i][1]=="2" and a==-1):
      D.appendleft(ls[i][2])
    else:
      D.append(ls[i][2])
if a==1:
  while D:
    print(D.popleft(), end="")
else:    
  while D:
    print(D.pop(), end="")

Measured memory_bytes: 35036
import java.io.BufferedReader;
import java.io.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[]a=new int[n+4];
		int[]b =new int[n];
		for(int i =0;i<n;i++)b[i]=sc.nextInt();
		for(int i =n-1;i>=0;i--) {
			a[b[i]]=Math.max(a[b[i]],1+a[b[i]+1] );
		}
		if(a[1]==0) {
			System.out.println(-1);
		}else System.out.println(n-a[1]);
	}
	static int gcd(int a,int b) {
		if(a==0)return b;
		return gcd(b%a,a);
	}
	  static class Scanner {
	        StringTokenizer st;
	        BufferedReader br;
	 
	        public Scanner(FileReader r) {
	            br = new BufferedReader(r);
	        }
	 
	        public Scanner(InputStream s) {
	            br = new BufferedReader(new InputStreamReader(s));
	        }
	 
	        public String next() throws IOException {
	            while (st == null || !st.hasMoreTokens())
	                st = new StringTokenizer(br.readLine());
	            return st.nextToken();
	        }
	 
	        public int nextInt() throws IOException {
	            return Integer.parseInt(next());
	        }
	 
	        public long nextLong() throws IOException {
	            return Long.parseLong(next());
	        }
	 
	        public String nextLine() throws IOException {
	            return br.readLine();
	        }
	 
	        public double nextDouble() throws IOException {
	            String x = next();
	            StringBuilder sb = new StringBuilder("0");
	            double res = 0, f = 1;
	            boolean dec = false, neg = false;
	            int start = 0;
	            if (x.charAt(0) == '-') {
	                neg = true;
	                start++;
	            }
	            for (int i = start; i < x.length(); i++)
	                if (x.charAt(i) == '.') {
	                    res = Long.parseLong(sb.toString());
	                    sb = new StringBuilder("0");
	                    dec = true;
	                } else {
	                    sb.append(x.charAt(i));
	                    if (dec)
	                        f *= 10;
	                }
	            res += Long.parseLong(sb.toString()) / f;
	            return res * (neg ? -1 : 1);
	        }
	 
	        public boolean ready() throws IOException {
	            return br.ready();
	        }
	    }
}


Measured memory_bytes: 46320
#include <bits/stdc++.h>           
    using namespace std;
    #define ll long long
    #define ld long double
    #define inf 100000
    #define io  ios_base::sync_with_stdio(false); cin.tie(NULL); 
    int main()
    {
        io
        string n;
        cin>>n;
       
      if (n[2]==n[3] && n[4]==n[5])
      {
          cout<<"Yes"<<endl;
      }
      else
      {
          cout<<"No"<<endl;
      }
        }
        

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

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  ll A,B,C,X,Y; cin>>A>>B>>C>>X>>Y;
  ll r;
  for(ll i=0; i<=max(X,Y); ++i){
    if(i==0){ r = A*X+B*Y;}
    else{ r = min( A*max((X-i),(ll)0)+B*max((Y-i),(ll)0)+C*2*i,   r);}
  }
  cout << r;
}

Measured memory_bytes: 256
X, N=map(int,input().split())
if N==0:
  print(X)
  exit()
  
else:
  P=sorted(map(int, input().split()))
  
if P.count(X)==0:
  print(X)
  exit()
  
for n in range(N+30):
  if P.count(X-n)==0:
    print(X-n)
    exit()
  elif P.count(X+n)==0:
    print(X+n)
    exit()



Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n;
	cin >> n;
	for (double i = 1; i <= 50000; i += 1)
	{
		if((int)(i * 1.08) == n)
		{
			cout << i << endl;
			return 0;
		}
	}
	cout << ":(" << endl;
 
	return 0;
}

Measured memory_bytes: 256
#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>;

string s;
int r, b;

int main() {
  cin >> s;
  r = 0; b = 0;
  rep (i, s.size()) {
    if (s[i] == '1') b++;
    if (s[i] == '0') r++;
  }
  cout << min(r, b) * 2 << endl;
  return 0;
}


Measured memory_bytes: 3756
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int[] x = new int[N];
        for(int i=0;i<N;i++) x[i]=sc.nextInt();
        int sum=0;
        for(int w:x) sum+=w;
        long[][][] dp = new long[N+1][N+1][2501];
        dp[0][0][0]=1;
        for(int i=1;i<=N;i++){
            dp[i][0][0]=1;
            for(int j=1;j<=i;j++){
                dp[i][j][0]=0;
                for(int k=1;k<=sum;k++){
                    dp[i][j][k] += dp[i-1][j][k];
                    if(k>=x[i-1]) dp[i][j][k]+=dp[i-1][j-1][k-x[i-1]];
                }
            }
        }
        long ans = 0;
        for(int j=1;j<=N;j++){
            ans += dp[N][j][A*j];
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 85364
H, N = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

inf = 10 ** 9 + 7
dp = [[inf] * (H + 1) for _ in range(N + 1)]
dp[0][0] = 0

for i in range(N):
    for j in range(H + 1):
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
        dp[i + 1][min(j + X[i][0], H)] = min(dp[i + 1][min(j + X[i][0], H)],
                                             dp[i][j] + X[i][1],
                                             dp[i + 1][j] + X[i][1])
        
print(dp[-1][-1])


Measured memory_bytes: 152268
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string A;
    cin >> A ;
    int B = A.length();
    string C = "x";
    string X ="";
    for (int i = 0 ; i < B ; i++){
        X = X + C;
    }
    cout<< X << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int ans = 0;
  for(int i = 0; i < s.length()-1; i++){
    if(s[i] != s[i+1]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  char x;
  char y[200001];
  int swapcount=0;
  int rcount=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x;
    if(x=='R') rcount++;
    y[i]=x;
  }
  for(int i=0;i<rcount;i++){
    if(y[i]=='W') swapcount++;
  }
  cout<<swapcount<<endl;
}


Measured memory_bytes: 3784
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int N;
int x[200002],y[200002];
int main(){
  cin >> N;
  for(int i=0;i<N;i++){cin >> x[i];y[i]=x[i];}
  sort(y,y+N);

  for(int i=0;i<N;i++){
    int l=0,h=N-1,m=(l+h)/2;
    while(y[m]!=x[i]){
     
      if(x[i]<y[m])h=m;
      else l=m+1;
      m=(l+h)/2;
    }
    if(m<N/2)cout << y[N/2] << endl;
    else cout << y[N/2-1] << endl;
  }
  return 0;
}


Measured memory_bytes: 3712
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define pi pair<int,int> 
#define pii pair<pi,int>
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a >= mod)a %= mod;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	vi v(n);
	vi pre(2001,0);
	rep(i,n){
		cin>>v[i];
		pre[v[i]]++;
	}
	repa(i,1,2001){
		pre[i] += pre[i-1];
	}
	ll ans = 0; 
	rep(i,n){
		repa(j,i+1,n){
			int x = v[i];
			int y = v[j];
			// int max1 = max(x,y);
			int c = pre[x+y-1] - pre[abs(x-y)];
			if(x > abs(x-y) && x < x+y){
				c--;
			}
			if(y > abs(x-y) && y < x+y){
				c--;
			}
			// cout<<i<<" "<<j<<" "<<c<<"\n";
			ans += c;
		}
	}
	ans /= 3;
	cout<<ans;
	// pre[0] = 0;
	return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N ;
    cin >> N ;
    vector<ll> A;
    
    rep(i, N){
        ll inp;
        cin >> inp;
        A.pb(inp);
    }
    ll a = 0 , b = 0;
    rep(i, N){
        a = max(a, A[i]);
    }
    ll a_cnt = 0;
    rep(i, N){
        if(A[i] == a) a_cnt++;
        if(A[i] != a) b = max(b, A[i]);
    }
    
    if(a_cnt == 1){
        rep(i, N){
            if(A[i] == a) cout << b << endl;
            else cout << a << endl;
        }
    }else{
        rep(i, N){
            cout << a << endl;
        }
    }
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 3312
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": # "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

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

int main()
{
	int n;
	cin>>n;
	rep(loop,n){
		string s;
		cin>>s;
		sort(allof(s));
		int small=atoi(s.c_str());
		reverse(allof(s));
		int large=atoi(s.c_str());
		cout<<large-small<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main() { 
  int s=0, t=0, x;  
  for(int i=0; i<4; i++) { 
    cin >> x;  
    s+=x; 
  }
  for(int i=0; i<4; i++) {   
    cin >> x;   
    t+=x;
  } 
  if(s>=t) cout << s << endl; 
  else cout << t << endl; 
  return 0;
}


Measured memory_bytes: 1160
#include<stdio.h>
#define MAX 500000
int maxHeap(int);
int A[MAX+1],H;
int main(){
  int i;
  scanf("%d",&H);
  for(i=1;i<=H;i++)scanf("%d",&A[i]);

  for(i=H/2;i>=1;i--)maxHeap(i);
    for(i=1;i<H;i++)printf(" %d",A[i]);
    printf(" %d\n",A[i]);
  return 0;
}

int maxHeap(int i){
  int l,r,lgs,k;
  l=2*i;
  r=2*i+1;
  if(l<=H&&A[l]>A[i])lgs=l;
  else lgs=i;
  if(r<=H&&A[r]>A[lgs])lgs=r;
  
  if(lgs!=i){
    k=A[i];
    A[i]=A[lgs];
    A[lgs]=k;
     maxHeap(lgs);
  }
 
  
}



Measured memory_bytes: 3756
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

int main(){
    int n, c, k;
    cin >> n >> c >> k;

    list<int> v;
    rep(i,n){
        int x;
        cin >> x;
        v.emplace_back(x);
    }
    v.sort();

    int sum = 0;
    while(not v.empty()){
        int first = v.front() + k;
        v.pop_front();
        rep(i,c - 1){
            if(v.empty()) break;
            if(v.front() <= first) v.pop_front();
        }
        sum++;
    }
    cout << sum << endl;
}


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

#define ll long long
#define pb push_back

using namespace std;

int main()
{
    ll n, x, a, b;
    //string s;

    cin >> a >> b >> n;

    x = n < b ? n : b - 1;

    cout << ((a * x) / b) - (a * (x / b)) << endl;

    return 0;
}




Measured memory_bytes: 3596
package main

import (
	"fmt"
	"io"
	"math/big"
	"os"
)

func main() {
	sc := NewScanner(os.Stdin)
	n := sc.Int()
	a := sc.Int64s(n)

	for _, v := range a {
		if v == 0 {
			fmt.Println(0)
			return
		}
	}

	res := big.NewInt(1)
	max := big.NewInt(1000000000000000000)

	for _, v := range a {
		res = res.Mul(res, big.NewInt(v))
		if res.Cmp(max) == 1 {
			fmt.Println(-1)
			return
		}
	}

	fmt.Println(res)
}

// generated by https://github.com/murosan/gollect

type Scanner struct {
	r     io.Reader
	buf   []byte
	delim byte
	size, eof,
	start, end int
}

func NewScanner(r io.Reader) *Scanner { return NewScannerSize(r, 4096) }
func NewScannerSize(r io.Reader, size int) *Scanner {
	return &Scanner{
		r:     r,
		buf:   make([]byte, size),
		delim: ' ',
		size:  size, start: size, end: size,
	}
}

func (s *Scanner) Int() int     { return ParseInt(s.bytes()) }
func (s *Scanner) Int64() int64 { return ParseInt64(s.bytes()) }

func (s *Scanner) Int64s(len int) []int64 {
	a := make([]int64, len)
	for i := 0; i < len; i++ {
		a[i] = s.Int64()
	}
	return a
}

func (s *Scanner) bytes() []byte { b, _ := s.next(); return b }
func (s *Scanner) next() (b []byte, size int) {
	for n := 0; ; {
		for i := s.end; i < s.size; i++ {
			if s.buf[i] == s.delim || s.buf[i] == '\n' || i == s.eof {
				b, size = s.buf[s.start:i], i-s.start
				s.start, s.end = i+1, i+1
				return
			}
		}
		s.end = s.size
		if n++; n == 2 {
			panic("lack of buffer size")
		}
		s.read()
	}
}
func (s *Scanner) read() {
	copy(s.buf, s.buf[s.start:s.end])
	s.end -= s.start
	s.start = 0
	n, _ := s.r.Read(s.buf[s.end:])
	s.eof = s.end + n
}

func ParseInt(b []byte) (n int) {
	var i int
	if b[0] == '-' {
		i++
	}
	for ; i < len(b); i++ {
		n *= 10
		n += int(b[i] - '0')
	}
	if b[0] == '-' {
		return -n
	}
	return
}

func ParseInt64(b []byte) (n int64) {
	var i int
	if b[0] == '-' {
		i++
	}
	for ; i < len(b); i++ {
		n *= 10
		n += int64(b[i] - '0')
	}
	if b[0] == '-' {
		return -n
	}
	return
}


Measured memory_bytes: 3392
import os, sys, re, math

N = int(input())
H = [int(n) for n in input().split()]

max_array = [H[0]]
for i in range(1, len(H)):
    max_array.append(max(H[i], max_array[-1]))

count = 0
for i in range(len(H)):
    if H[i] == max_array[i]:
        count += 1

print(count)


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

int main() {
    int w, h, n; cin >> w >> h >> n;
    vector<int> x(n), y(n), a(n);
    rep(i, n) {
        cin >> x.at(i) >> y.at(i) >> a.at(i);
    }
    int min_x = 0, max_x= w,min_y = 0, max_y= h;
    rep(i, n) {
        switch (a.at(i)) {
        case 1:
            //max_x = min(max_x, x.at(i));
            min_x = max(min_x, x.at(i));
            break;
        case 2:
            //min_x = max(min_x, x.at(i));
            max_x = min(max_x, x.at(i));
            break;
        case 3:
            //max_y = min(max_y, y.at(i));
            min_y = max(min_y, y.at(i));
            break;
        case 4:
            //min_y = max(min_y, y.at(i));
            max_y = min(max_y, y.at(i));
            break;
        default:
            assert(false);
        }
    }
    //printf("min_x=%d\n", min_x);
    //printf("max_x=%d\n", max_x);
    //printf("min_y=%d\n", min_y);
    //printf("max_y=%d\n", max_y);

    if (min_x >= max_x || min_y >= max_y){
         cout << 0 << endl;
         return 0;
    }
    int tate, yoko;
    yoko = max_x - min_x;
    tate = max_y - min_y;
    cout << max(0, yoko * tate) <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<int> p(n);
	for(int i = 0; i < n; ++i){
		cin >> p[i];
		--p[i];
	}
	vector<vector<int>> conn(n);
	for(int i = 0; i < m; ++i){
		int a, b;
		cin >> a >> b;
		--a; --b;
		conn[a].push_back(b);
		conn[b].push_back(a);
	}
	vector<int> group(n, -1);
	for(int r = 0; r < n; ++r){
		if(group[r] >= 0){ continue; }
		queue<int> q;
		q.push(r);
		group[r] = r;
		while(!q.empty()){
			const int u = q.front();
			q.pop();
			for(const auto v : conn[u]){
				if(group[v] >= 0){ continue; }
				group[v] = r;
				q.push(v);
			}
		}
	}
	int answer = 0;
	for(int i = 0; i < n; ++i){
		if(group[i] == group[p[i]]){ ++answer; }
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 6528
#include <iostream>
#include <string.h>
#include <sstream>
#include <ctype.h>
using namespace std;

string com[3] = {"the", "this", "that"};

string incAlpha (string str, int k) {
    for (int i = 0; i < str.size(); i++) {
        if(isalpha(str[i])) str[i] = ((str[i] + k - 'a') % 26) + 'a'; 
    }
    return str;
}

bool strsrch(string str1, string str2) {
    for (int i = 0; i < str1.size(); i++) {
        if (str1[i] == str2[0]) {
            bool flag = true;
            if (i + str2.size() > str1.size()) flag = false;
            for (int j = 0; j < str2.size() && flag; j++) {
                if (str1[i + j] != str2[j]) flag = false;
            }
            if (flag) return true;
        }
    }

    return false;
}

bool check (string str) {
    for (int i = 0; i < 3; i++) {
        if (strsrch(str, com[i])) return true;
    }
    return false;
}

int main ()
{
    string str;
    while (getline(cin, str)) {
        for (int i = 0; i <= 26; i++) {
            if (check((incAlpha(str, i)))) {
                cout << (incAlpha(str, i)) << endl;
                break;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 1188
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <map>
#include <queue>
#define N 200010
#define ll long long
#define mo ((ll)1e9+7)
//10000000000037ll
//21993833369ll
#define db double
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define drep(i,a,b) for(int i=a;i>=b;--i)
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
bool cmp(int a, int b) {return a > b;}
inline ll read() {
	ll x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') {if (ch == '-')f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	return x * f;
}
int n, m;
int fa[N], sz[N];
int Find(int x) {return fa[x] == x ? x : fa[x] = Find(fa[x]);}
void Link(int u, int v) {
	int pu = Find(u), pv = Find(v);
	if (pu == pv)return;
	fa[pu] = pv;
	sz[pv] += sz[pu];
}
int main() {
	n = read(), m = read();
	rep(i, 1, n)fa[i] = i, sz[i] = 1;
	rep(i, 1, m) {
		int u = read(), v = read();
		Link(u, v);
	}
	int ans = 0;
	rep(i, 1, n)cmax(ans, sz[Find(i)]);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 11460
n, m = [int(line) for line in input().split()]

a = [list(map(int, input().split())) for _ in range(n)]

b = [int(input()) for _ in range(m)]

for i in range(n):
    c = 0
    for j in range(m):
        c += a[i][j] * b[j]
    print(c)



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

//***********************************************************************
int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n),b(n),c(n),dp1(n),dp2(n),dp3(n);
    for(int i=0;i<n;i++)
    {
        cin >> a[i] >> b[i] >> c[i];
    }
	dp1[0]=a[0];
    dp2[0]=b[0];
    dp3[0]=c[0];
    for(int i=1;i<n;i++)
    {
        dp1[i]=max(dp2[i-1]+a[i],dp3[i-1]+a[i]);
        dp2[i]=max(dp1[i-1]+b[i],dp3[i-1]+b[i]);
        dp3[i]=max(dp2[i-1]+c[i],dp1[i-1]+c[i]);
    }
    cout << max(max(dp1[n-1],dp2[n-1]),dp3[n-1]) << endl;
}


int main()
{ 
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll t;
	//cin >> t;
	t=1;
	while(t--)
	{
		solve();
	}

	return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long
#define MOD 1000000007

const ll MAX_N = 200010;
ll fac[MAX_N], inv[MAX_N];

ll powmod(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) {
			res = (res*x) % mod;
		}
		x = (x*x) % mod;
		n >>= 1;
	}
	return res;
}

void init() {
	fac[0] = 1;
	for (int i = 1; i < MAX_N;i++) fac[i] = fac[i - 1] * i%MOD;
	inv[MAX_N - 1] = powmod(fac[MAX_N - 1], MOD - 2, MOD);
	for (int i = MAX_N - 2; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % MOD;
}

ll C(int x, int y) {
	return fac[x] * inv[y] % MOD*inv[x - y] % MOD;
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	init();
	ll ret = C(h + w - 2, h - 1);
	for (int i = 0; i < b;i++) {
		ret = (ret - C(i + h - a - 1, h - a - 1)*C(w - i + a - 2, a - 1) % MOD + MOD) % MOD;
	}
	cout << ret << endl;
}

Measured memory_bytes: 3328
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
C.append(0)

for i in range(1, N+1):
    if i == N:
        break
    if A[i-1]+1 == A[i]:
        B.append(C[A[i-1]-1])
    
print(sum(B))

Measured memory_bytes: 9144
#include<bits/stdc++.h>
using namespace std;
int  main()
{
    int n,m;
    cin>>n>>m;
    int n1,sum=0;
    int i;
    for(i=0;i<m;i++)
    {
        cin>>n1;
        sum+=n1;
    }
    int result=n-sum;
    if(result<0)
        cout<<"-1"<<endl;
    else
        cout<<result<<endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

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

	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if ((int)to_string(i).size() & 1) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;



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


    ll n, k;
    cin >> n >> k;
    ll a[n], b[n];
    for (ll i = 0; i < n; i++) cin >> a[i];
    for (ll i = 0; i < n; i++) cin >> b[i];

    sort(a, a + n);
    sort(b, b + n, greater<>());

    ll ans = LONG_LONG_MAX;
    ll l = 0, r = LONG_LONG_MAX;

    while (l <= r) {
        ll mid = (l + r) / 2;
        ll till = 0;
        for (ll i = 0; i < n; i++) {
            if (a[i] > mid / b[i]) {
                till += a[i] - mid / b[i];
            }
        }

        if (till <= k) {
            ans = mid;
            r = mid - 1;
        }

        else {
            l = mid + 1;
        }
    }

    cout << ans;


}





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

using int64 = long long;

int64 Solve(int64 A, int64 B, int64 C, int64 X, int64 Y) {
  int64 ret = 2 * max(X, Y) * C;
  for (int64 c = 0; c <= 2 * max(X, Y); ++c) {
    int64 a = max<int64>(X - c / 2, 0);
    int64 b = max<int64>(Y - c / 2, 0);
    int64 cost = a * A + b * B + c * C;
    ret = min(ret, cost);
  }
  return ret;
}

int main() {
  int64 A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  cout << Solve(A, B, C, X, Y) << "\n";
  return 0;
}


Measured memory_bytes: 256
import sys

n, x=map(int, input().split())
A=list(map(int, input().split()))

ans=0
for i in range(n-1):
    next_sum=A[i]+A[i+1]
    if next_sum>x:
        if next_sum-x<=A[i+1]:
            A[i+1]=A[i+1]-(next_sum-x)
            ans=ans+(next_sum-x)
        else:
            ans=ans+A[i+1]
            if next_sum-x-A[i+1]<=A[i]:
                A[i]=A[i]-(next_sum-x-A[i+1])
                ans=ans+(next_sum-x-A[i+1])
            else:
                print(0)
                sys.exit()
            A[i+1]=0
print(ans)


Measured memory_bytes: 63984
/* author   : mpily :-()
title : Competing.cpp
time :Tue Aug 27 13:18:01 2019

*/
#include<bits/stdc++.h>
using namespace std;
int main(){
	int K,X;
	cin>>K>>X;
	int a = X-K+1;
	int b = X+K-1;
	for(int i = a ; i <= b; i++){
		cout<<i<<" "; 
	}
	return 0;
}


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

void Main() {
    // input
    double L;
    cin >> L;


    // translate
    double ans = L * L * L / 27;


    // output
    cout << ans << endl;

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3684
#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;

typedef long long ll;
typedef long double ld;

template <class T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

ll niz[200005];
ordered_set <pair <ll, ll>> q;

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

    int n, k;
    cin >> n >> k;
    for(int i=1; i<=n; i++){
        cin >> niz[i];
        niz[i] -= k;
    }
    q.insert({0, 0});
    ll pre = 0;
    ll res = 0;
    for(int i=1; i<=n; i++){
        pre += niz[i];
        int k = q.order_of_key({pre, n+5});
        res += k;
        q.insert({pre, i});
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 14336
// ABC178B.cpp
#include <iostream>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ac = a * c;
    ll ad = a * d;
    ll bc = b * c;
    ll bd = b * d;

    cout<<max(max(ac, ad), max(bc, bd))<<endl;
}



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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


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

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li parent[101010];
vector<li> children[100100];
li n, k;

// {add_num, depth_unpruned}
PI dfs(li now) {
    li add_num = 0;
    li depth = 1;
    for (auto && child : children[now]) {
        auto res_child = dfs(child);
        add_num += res_child.F;
        depth = max(depth, res_child.S + 1);
    }
    if (depth == k && (parent[now] != 0 && now != 0)) {
        return {add_num + 1, 0};
    }
    return {add_num, depth};
}

int main() {
    cin >> n >> k;
    rin{
        li x;
        cin >> x;
        x--;
        parent[i] = x;
        if (i != 0)children[x].pb(i);
    }
    auto res = dfs(0);
    cout << res.F + (parent[0] != 0) << endl;

    return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 200003;
int n, a[N], st[18][N], lg2[N];
LL ans;
inline int calc(int l, int r){
	int k = lg2[r - l + 1];
	return a[st[k][l]] < a[st[k][r - (1 << k) + 1]] ? st[k][l] : st[k][r - (1 << k) + 1];
}
inline void solve(int l, int r){
	if(l == r) ans += a[l];
	if(l >= r) return;
	int mid = calc(l, r);
	ans += (LL) a[mid] * (mid - l + 1) * (r - mid + 1);
	solve(l, mid - 1); solve(mid + 1, r);
}
int main(){
	scanf("%d", &n);
	for(Rint i = 1;i <= n;i ++) scanf("%d", a + i), st[0][i] = i;
	for(Rint i = 1;i <= 18;i ++)
		for(Rint j = 1;j <= n - (1 << i) + 1;j ++)
			st[i][j] = a[st[i - 1][j]] < a[st[i - 1][j + (1 << i - 1)]] ? st[i - 1][j] : st[i - 1][j + (1 << i - 1)];
	lg2[0] = -1;
	for(Rint i = 1;i <= n;i ++) lg2[i] = lg2[i >> 1] + 1;
	solve(1, n);
	printf("%lld", ans);
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second
#define lwb lower_bound
#define upb upper_bound
#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  freopen("in", "r", stdin);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int s = 1, c = 0;
  vector<int> v(n + 1), t(1);
  while (!v[s]) {
    v[s] = ++c;
    t.push_back(s);
    s = a[s];
  }
  if (k + 1 <= c) {
    cout << t[k + 1] << '\n';
    return 0;
  }
  k -= v[s] - 1;
  cout << t[v[s] + k % (c - v[s] + 1)] << '\n';
}


Measured memory_bytes: 8464
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

li calc(string s) {
    vector<li> dp(s.size() + 1, s.size());
    dp[0] = 0;
    dp[1] = 0;
    for (int i = 2; i <= s.size(); ++i) {
        if (s[i - 2] != s[i - 1]) {
            dp[i] = min(dp[i - 2] + 1, dp[i - 1]);
        } else {
            dp[i] = dp[i - 2] + 1;
        }
    }
    return dp[s.size()];
}

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

    string s;
    cin >> s;
    li k;
    cin >> k;

    if (k <= 100) {
        string ss;
        for (int i = 0; i < k; ++i) {
            ss += s;
        }
        cout << calc(ss) << endl;
        return 0;
    }

    string ss;
    for (int i = 0; i < 100; ++i) {
        ss += s;
    }
    li even = calc(ss);
    ss += s;
    li odd = calc(ss);
    ss += s;
    li delta = calc(ss) - even;

    li ans;
    if (k % 2 == 0) {
        ans = even + (k - 100) / 2 * delta;
    } else {
        ans = odd + (k - 101) / 2 * delta;
    }

    cout << ans << endl;


    return 0;
}

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

int main() {
    long long n; cin >> n;
    map<string, int> s;
    for (int i = 0; i < n; i++) {
        string x; cin >> x;
        s[x] += 1;
    }
    cout << s.size() << endl;
    return 0;
}


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

int main(){
   int count = 1;
   int hoz;
   int n;
   cin >> n;
   vector<int> moti(n);

   for(int i = 0; i < n; i++){
       cin >> moti.at(i);
   }
    
    sort(moti.begin(), moti.end());
    reverse(moti.begin(), moti.end());

    hoz = moti.at(0);

    for(int i = 0; i < n; i++){
        if(moti.at(i) != hoz){
            hoz = moti.at(i);
            count++;
        }
    }

    cout << count << endl;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cmath>

using ll = long long;

using namespace std;

template <typename T>
T gcd(T a, T b) {
    if (a > b) {
        T buf = a;
        a = b;
        b = buf;
    }
    return a == 0 ? b : gcd(a, b%a);
}

int main() {
    long a, b;
    cin >> a >> b;
    long g = gcd(a, b), r = (long)sqrt(g);
    int cnt = 1;
    for (int i=2; i<=r; i++) {
        if (g % i == 0) {
            while (g % i == 0) g /= i;
            cnt++;
        }
    }
    if (g != 1) cnt++;
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int s;
    cin >> s;
    int h = s / 3600;
    s = s % 3600;
    int m = s / 60;
    s = s % 60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n, m;
    cin >> n >> m;
    cout << n * (n-1) / 2 + m * (m-1) / 2 << endl;
}

Measured memory_bytes: 3628
import java.util.Scanner;

class Main{
	public static void main(String Args[]){
		Scanner sc = new Scanner(System.in);
		String[] s = new String[3];
		for (int i = 0;i < 3 ; i++ ) {
			s[i] = sc.next();
		}
		int p = 0;
		while(s[p].length() != 0){
			int np = s[p].charAt(0)-'a';
			s[p] = s[p].substring(1,s[p].length());
			// else s[p] = "";
			p = np;
		}
		System.out.println((char)('A'+p));
	}
}

Measured memory_bytes: 9684