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

void prians(bool answer) {
  if(answer)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
// answerstring2 will be num1  ~  num2
// 2 split: 1 ~ num2, num1 ~ last
vector<string> split(string splitstring, int stringnum1,
                     int stringnum2) {
  vector<string> stringanswer;
  string answerstring1 = splitstring;
  string answerstring2 = splitstring;
  string answerstring3 = splitstring;
  if(stringnum1 >= (int)splitstring.size() ||
     stringnum2 > (int)splitstring.size()) {
    stringanswer.resize(3);
    return stringanswer;
  }
  answerstring1.erase(
      answerstring1.begin() + stringnum1 - 1,
      answerstring1.end());
  answerstring2.erase(answerstring2.begin() + stringnum2,
                      answerstring2.end());
  answerstring2.erase(
      answerstring2.begin(),
      answerstring2.begin() + stringnum1 - 1);
  answerstring3.erase(answerstring3.begin(),
                      answerstring3.begin() + stringnum2);
  stringanswer.push_back(answerstring1);
  stringanswer.push_back(answerstring2);
  stringanswer.push_back(answerstring3);
  return stringanswer;
}
string memo[4] = {"dream", "dreamer", "erase", "eraser"};
string s;

int main() {
  int i;
  bool ans = 1;
  cin >> s;
  i = s.size();
  while(i != 0 && ans) {
    if(i > 4 && s[i - 1] == 'm' && s[i - 2] == 'a' &&
       s[i - 3] == 'e' && s[i - 4] == 'r' &&
       s[i - 5] == 'd')
      i -= 5;
    else if(i > 6 && s[i - 1] == 'r' && s[i - 2] == 'e' &&
            s[i - 3] == 'm' && s[i - 4] == 'a' &&
            s[i - 5] == 'e' && s[i - 6] == 'r' &&
            s[i - 7] == 'd')
      i -= 7;
    else if(i > 4 && s[i - 1] == 'e' && s[i - 2] == 's' &&
            s[i - 3] == 'a' && s[i - 4] == 'r' &&
            s[i - 5] == 'e')
      i -= 5;
    else if(i > 5 && s[i - 1] == 'r' && s[i - 2] == 'e' &&
            s[i - 3] == 's' && s[i - 4] == 'a' &&
            s[i - 5] == 'r' && s[i - 6] == 'e')
      i -= 6;
    else
      ans = 0;
  }
  prians(ans);
  return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(void){

	int i,j,k,q,p,inning,point,kazu[20];
	char eve[10];
	
		point=0;
		j=0;
		k=0;
		q=0;
		p=0;	
	
		scanf("%d",&inning);
		
		for(k=0;k<inning;k++){
		
			point=0;
			j=0;
			q=0;
			p=0;
			
		while(q<3){
		
			for(j=0;j<10;j++){
				eve[j]=0;
			}
			
			scanf("%s",eve);
			
			if(eve[0]=='O'){
				if(eve[1]=='U'){
					if(eve[2]=='T'){
						q++;
					}
				}		
			}
			if(eve[0]=='H'){
				if(eve[1]=='I'){
					if(eve[2]=='T'){
						p++;
						if(p>=4){
							point++;
							p--;
						}
					}
				}
			}		
			
			if(eve[0]=='H'){
				if(eve[1]=='O'){
					if(eve[2]=='M'){
						if(eve[3]=='E'){
							if(eve[4]=='R'){
								if(eve[5]=='U'){
									if(eve[6]=='N'){
										point=point+p+1;
										p=0;
									}
								}
							}
						}		
					}
				}
			}
		}		
		kazu[k]=point;
	}
	for(k=0;k<inning;k++){
		printf("%d\n",kazu[k]);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;


ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
bool root(string s){
    int n=s.length();
    if(n==2){
        if(s[0]==s[1]){
            return true;
        }
        else return false;
    }
    if(n==3){
        if(s[0]==s[2]){
            return true;
        }
        else return false;
    }
 
    return false;
}
 
 
//深さ優先
vector<int> seen;
vector<ll> h;
 
//普通の深さ優先探索seenを返す感じ
void dfs(const Graph &G,int v){

    seen[v] = 0; //v探索済み
 
    P good=make_pair(v,h[v]);
    for(auto next_v :G[v]){
        if(seen[next_v]!=-1) continue;//もう探索していた
        if(h[next_v]>good.second){
            good=make_pair(next_v,h[next_v]);
        }
        dfs(G,next_v);
    }
 
    if(!(h[v]==good.second && v==good.first)){
        seen[good.first]=1;
    }
}


signed main(){
    int n;
    cin>>n;
    int h[n+1];
    rep(i,0,n) cin>>h[i];

    h[n]=0;
    ll ans = 0;

    while(1){
        rep(i,0,n){
            if(h[i]>0 && h[i+1]==0){
                ans++;
            }
        }

        bool abe=true;

        rep(j,0,n){
                if (h[j]>0){
                    h[j]--;
                    abe=false;
                }
        }

        if(abe){
                break;
        }
    }

    cout<<ans<<endl;

}   

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>

int main() {
  size_t N;
  scanf("%zu", &N);

  int Ma, Mb;
  scanf("%d %d", &Ma, &Mb);

  std::vector<int> a(N), b(N), c(N);
  int sa=0, sb=0;
  for (size_t i=0; i<N; ++i) {
    scanf("%d %d %d", &a[i], &b[i], &c[i]);
    sa += a[i];
    sb += b[i];
  }

  int INF=40000000;
  std::vector<std::vector<std::vector<int>>> dp(
      N, std::vector<std::vector<int>>(
        sa+1, std::vector<int>(sb+1, INF)));

  dp[0][0][0] = 0;
  for (size_t i=0; i<N; ++i) {
    // dp[i][a[i]][b[i]] = std::min(dp[i][a[i]][b[i]], c[i]);
    if (i > 0) {
      for (int j=0; j<=sa; ++j)
        for (int k=0; k<=sb; ++k)
          dp[i][j][k] = std::min(dp[i][j][k], dp[i-1][j][k]);
    }
    for (int j=sa; j>=a[i]; --j) {
      for (int k=sb; k>=b[i]; --k) {
        if (dp[i][j-a[i]][k-b[i]] < INF) {
          dp[i][j][k] = std::min(dp[i][j][k], dp[i][j-a[i]][k-b[i]]+c[i]);
        }
      }
    }
  }

  int res=INF;
  for (int j=0; j<=sa; ++j) {
    for (int k=0; k<=sb; ++k) {
      if (j == 0 && k == 0) continue;
      // fprintf(stderr, "%d%c", dp[N-1][j][k], k<sb? ' ':'\n');
      if (j*Mb == k*Ma) {
        res = std::min(res, dp[N-1][j][k]);
      }
    }
  }

  printf("%d\n", res<INF? res:-1);
}


Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=2005;
const ll INF=1LL<<59;
struct team{
    int ti;
    vector<int> cnt;
    int ok;
    int id;
};

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int M,T,P,R;cin>>M>>T>>P>>R;
        
        if(M+T+P+R==0) break;
        
        vector<team> S(T);
        for(int i=0;i<T;i++){
            S[i].cnt.resize(15);
            S[i].id=i;
        }
        
        for(int i=0;i<R;i++){
            int a,b,c,d;cin>>a>>b>>c>>d;
            b--;c--;
            if(d){
                S[b].cnt[c]++;
            }else{
                S[b].ti+=S[b].cnt[c]*20+a;
                S[b].ok++;
            }
        }
        
        sort(all(S),[](team a,team b){
            if(a.ok==b.ok){
                if(a.ti==b.ti){
                    return a.id>b.id;
                }
                return a.ti<b.ti;
            }
            return a.ok>b.ok;
        });
        
        for(int i=0;i<T;i++){
            if(i){
                if(S[i].ok==S[i-1].ok&&S[i].ti==S[i-1].ti){
                    cout<<'='<<S[i].id+1;
                }else{
                    cout<<','<<S[i].id+1;
                }
            }else{
                cout<<S[i].id+1;
            }
        }
        cout<<endl;
    }
    
}






Measured memory_bytes: 3240
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int k, n;
  cin >> k >> n;
  vector<int> a(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  a[n] = k + a[0];

  int smax = -1;
  for (int i = 0; i < n; i++) {
    smax = max(smax, a[i + 1] - a[i]);
  }
  const int ans = k - smax;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define debug(x) cout << #x << " = " << (x) << endl;
#define MOD 1000000007
#define EPS (1 >> 30)
#define INF (1 << 30)
//#define INFll (1LL << 60)

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------

    int n;
    cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    sort(all(l));
    ll ans = 0;
    rep(i, n - 2)
    {
        Rep(j, i+1, n - 1)
        {
            int memo = l[j] - l[i];
            int memomax = l[j] + l[i];
            int koe = l.end() - upper_bound(all(l), memo);
            int miman = lower_bound(all(l), memomax) - l.begin();
            if (upper_bound(all(l), memo)==lower_bound(all(l), memomax)){
                continue;
            }
            int a = n-koe;
            if(a>j){

            }
            else{
                koe = n-(j+1) ;
            }
            
            ans += miman + koe - n ;
            
            //cout<<memo<<" "<<memomax<<" "<<koe<<" "<<miman<<endl;
            //debug(a);
            //debug(ans);
        }
    }
    cout << ans <<endl;
}

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

ll gcd(ll a, ll b) //最大公約数
{
    if(b==0) return a;
    return gcd(b,a%b);
}

signed main(){
    int k;
    cin >> k;
    ll ans=0;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            int temp=gcd(i,j);
            for(int l=1;l<=k;l++){
                ans+=gcd(temp,l);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int a, b, c, d, e, f;
int answater = 0, anssugar = 0;
double maxv = 0;

int main() {
  cin >> a >> b >> c >> d >> e >> f;

  for (int i = 0; 100 * a * i <= f; i++) {
    for (int j = 0; 100 * b * j <= f; j++) {
      for (int k = 0; c * k <= f; k++) {
        for (int l = 0; d * l <= f; l++) {
          int water = 100 * a * i + 100 * b * j;
          int sugar = c * k + d * l;
          int sum = water + sugar;

          double concentration = 0;
          if (sum != 0) {
            concentration = (double) sugar / (water + sugar);
          }
          if (sum <= f && concentration >= maxv && 100.0 * sugar / water <= e) {
            maxv = concentration;
            answater = water;
            anssugar = sugar;
          }
        }
      }
    }
  }
  cout << answater + anssugar << " " << anssugar << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <array>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
#define asn ans
using namespace std;
template <typename T> istream & operator >> (istream & is, vector<T> & vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;
using VI = vector<int>;

int main() {
	int a, b, c; CI a >> b >> c;
	array<int,50> d;
	int j = 1;
	for (int i = min(a,b); i > 0; i--) {
		if (a % i == 0 and b % i == 0) { d[j] = i; j++; }
	}
	CO d[c] EN;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[]argc){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int count=0;
        for(int j=0;j<N;j++){
            int min = j;
            for(int k=j;k<N;k++){
                if(A[k]<A[min]){
                    min = k;
                }
            }
            if(j==min){
                int x = A[min];
                A[min] = A[j];
                A[j] = x;
            }
            else{
                int x = A[min];
                A[min] = A[j];
                A[j] = x;
                count++;
            }
        }
        for(int m=0;m<N;m++){
            if(m==N-1){
                System.out.printf("%d",A[m]);
            }else{
                System.out.printf("%d ",A[m]);
            }
        }
        System.out.printf("\n");
        System.out.println(count);
    }
}



Measured memory_bytes: 26584
#include <stdio.h>
#include <string.h>
#define rep(i,l,r)for(int i=(l);i<(r);i++)

char s[400010];
int dp[27*27*27*27];
int main(){
	int n;
	scanf("%d",&n);
	while(n--){
		scanf(" %s",s);
		int len=strlen(s);
		int x=0;
		rep(i,0,len){
			x%=27*27*27;
			x=x*27+(s[i]-'a')+1;
			dp[x]|=1;
			dp[x%(27*27*27)]|=1;
			dp[x%(27*27)]|=1;
			dp[x%(27)]|=1;
		}
	}
	rep(i,1,27)if(!dp[i]){
		printf("%c\n",'a'+(i-1));
		return 0;
	}
	rep(i,1,27)rep(j,1,27)if(!dp[i*27+j]){
		printf("%c%c\n",'a'+(i-1),'a'+(j-1));
		return 0;
	}
	rep(i,1,27)rep(j,1,27)rep(k,1,27)if(!dp[i*27*27+j*27+k]){
		printf("%c%c%c\n",'a'+(i-1),'a'+(j-1),'a'+(k-1));
		return 0;
	}
	rep(i,1,27)rep(j,1,27)rep(k,1,27)rep(l,1,27)if(!dp[i*27*27*27+j*27*27+k*27+l]){
		printf("%c%c%c%c\n",'a'+(i-1),'a'+(j-1),'a'+(k-1),'a'+(l-1));
		return 0;
	}
}


Measured memory_bytes: 4264
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(ll i = 0; i < (n); i++)
typedef long long ll;
const ll MOD = 1000000007;

int main()
{
    ll n, ans = 0;
    ll j = 1;
    cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n){
        if(a[i] != j) ans++;
        else j++;
    }
    if(j == 1) ans = -1;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(void)
{
	int i,j,count=0;
    long int n,m,min;
	scanf("%ld %ld",&n,&min);
	for(i=1;i<n;i++)
	{
		scanf("%ld",&m);
		if(m>min)
		{
			count++;
		}
		else min=m;
	}
	printf("%d",n-count);
	return 0;
}

Measured memory_bytes: 128
n = int(input())
t = list(map(int,input().split()))
m = int(input())
ans =[]
for i in range(m):
    p,x = map(int,input().split())
    q = sum(t)-t[p-1]+x
    ans.append(q)
for i in range(m):
    print(ans[i])

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

using namespace std;
using ll = long long int;

int main(void) {
    cout << fixed << setprecision(16);
    cin.tie(0); ios::sync_with_stdio(false);

    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    while(a>0 && c>0) {
        c -= b;
        a -= d;
    }
    if(c <= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3640
n=int(input())
a=list(map(int,input().split()))
num1=[0]*(2*(10**5)+10)
num2=[0]*(2*(10**5)+10)
for i in range(n):
    if a[i]+i+1<2*(10**5)+5:
        num1[a[i]+i+1]+=1
    if a[i]+1<i+1:
        num2[-a[i]+i+1]+=1
ans=0
for i in range(len(num1)):
    ans+=num1[i]*num2[i]
print(ans)


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

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

int dfs(int i,int j,int n)
{
	int d=0,h;
	ice[i][j]=0;
	for(h=0;h<=3;h++)
	{
		if(ice[i+dx[h]][j+dy[h]]==1)
		{
			d=max(d,dfs(i+dx[h],j+dy[h],n+1));
		}
	}
	ice[i][j]=1;
	return max(d,n);
}

int main()
{
	int i,j,m,n,d;
	
	while(1)
	{
		cin >> m >> n;
		
		if(m==0) break;
		
		for(i=0;i<=m+1;i++) ice[0][i]=0;
		for(i=1;i<=n;i++)
		{
			ice[i][0]=0;
			for(j=1;j<=m;j++)
			{
				cin >> ice[i][j];
			}
			ice[i][m+1]=0;
		}
		for(i=0;i<=m+1;i++) ice[n+1][i];
		
		d=0;
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=m;j++)
			{
				if(ice[i][j]==1)
				{
					d=max(d,dfs(i,j,1));
				}
			}
		}
		cout << d << endl;
	}
	return 0;
}

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

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

////////////////////////////////////////////////////////////////////

const int N = 1e5 + 2;

int A[N];

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);	

	int n, x = 0; cin >> n;
	for (int i = 1; i <= n; i++) cin >> A[i];
	for (int i = 1; i <= n + 1; i++) x += abs(A[i] - A[i - 1]);
	for (int i = 1; i <= n; i++) cout << x - abs(A[i + 1] - A[i]) - abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i - 1]) << endl;

	return 0;
}


Measured memory_bytes: 1664
N=input()
N=int(N)
A=[]
for i in range(N):
    b=input()
    b=int(b)
    A.append(b)
flag=0
max_value=max(A)
for i in range(N):
    if flag==1:
        print(max_value)
    elif A[i]<max_value:
        print(max_value)
    else:
        data=A.pop(i)
        print(max(A))
        A.insert(i,data)
        if max(A)==max_value:
            flag=1



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

//ソートは時間がかかりすぎてダメ ← qsortを使えばいいっぽい

int compare_int(const void *a, const void *b){
  return *(int *)a - *(int *)b;
}

int main(void){
  int N, K;
  int h[100000] = {};
  int i, j, k;
  int min = 1000000000;
  int buf;
  scanf("%d %d", &N, &K);
  for(i = 0; i < N; i++){
    scanf("%d", &h[i]);
  }
  //h[]を昇順に並べ替え
  qsort(h, N, sizeof(int), compare_int);//こんな便利なものがあるとは
  /*
  ソートを自作すると時間がかかりすぎてダメだった
  for(i = 0; i < N; i++){
    for(j = i + 1; j < N; j++){
      if(h[i] > h[j]){
        buf = h[i];
        h[i] = h[j];
        h[j] = buf;
      }
    }
  }
  */
  for(i = 0; i < N - K + 1; i++){
    buf = h[i + K - 1] - h[i];
    if(buf < min){
      min = buf;
    }
  }
  printf("%d\n", min);
  return 0;
}


Measured memory_bytes: 892
using System;

namespace csITP1d
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse (Console.ReadLine());
            int h;
            int m;
            int s;
            h = a / 3600;
            a %= 3600;
            m = a / 60;
            s = a % 60;

            Console.WriteLine("{0}:{1}:{2}", h, m, s);
        }
    }
}

Measured memory_bytes: 9188
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <utility>
#include <tuple>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
	int n,q;
	cin >> n >> q;
	vector<tuple<int,int,int>> a(n);
	for(int i = 0;i < n;i++){
		int s,t,x;
		cin >> s >> t >> x;
		a[i] = tie(x,s,t);
	}

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

	set<int> d;
	for(int i = 0;i < q;i++){
		int dd;
		cin >> dd;
		d.insert(dd);
	}

	map<int,int> ans;
	for(int i = 0;i < n;i++){
		int x,l,r;
		tie(x,l,r) = a[i];

		auto it = d.lower_bound(l-x);
		while(it != d.end()){
			if(*it > r-1-x)break;

			ans[*it] = x;
			d.erase(it++);
		}
	}

	if(d.size()){
		for(auto itr = d.begin();itr != d.end();itr++){
			ans[*itr] = -1;
		}
	}

	for(auto p:ans){
		cout << p.second << endl;
	}
}


Measured memory_bytes: 21888
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
  std.range, std.container, std.bigint, std.ascii, std.typecons, std.format, std.bitmanip;

// }}}
// nep.scanner {{{
class Scanner {
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin) {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next() {
    if (idx < str.length) {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0) {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)() {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len) {
    T[] ret = new T[len];

    foreach (ref c; ret) {
      c = next!(T);
    }

    return ret;
  }

  void scan()() {
  }

  void scan(T, S...)(ref T x, ref S args) {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType)) {
    str ~= s.to!(char[]).strip.split;
  }
}
// }}}


void main() {
  auto cin = new Scanner;
  int n, x, y;
  cin.scan(n, x, y);
  x--; y--;


  auto dist = new int[][](2000, 2000);
  auto G = new int[][](2000, 0);
  foreach (i; 0 .. n - 1) {
    G[i] ~= i + 1;
    G[i + 1] ~= i;
  }

  G[x] ~= y;
  G[y] ~= x;

  foreach (i; 0 .. 2000) {
    foreach (j; 0 .. 2000) {
      dist[i][j] = cast(int)(1e9 + 7);
    }
  }

  foreach (i; 0 .. n) {
    alias P = Tuple!(int, "cost", int, "next");
    // P[] a;
    // auto heap = heapify!"a.cost > b.cost"(a);
    DList!P q;
    dist[i][i] = 0;
    q.insertBack(P(0, i));

    while (!q.empty) {
      auto p = q.front;
      q.removeFront();
      if (dist[i][p.next] < p.cost) continue;
      foreach (e; G[p.next]) {
        if (dist[i][e] > dist[i][p.next] + 1) {
          dist[i][e] = dist[i][p.next] + 1;
          q.insertBack(P(dist[i][e], e));
        }
      }
    }
  }

  int[int] chie;
  foreach (i; 0 .. n) {
    foreach (j; 0 .. n) {
      chie[dist[i][j]]++;
    }
  }


  foreach (i; 1 .. n) {
    writeln(chie.get(i, 0) / 2);
  }
}


Measured memory_bytes: 19068
<?php
while ($line = fgets(STDIN)) {
 $array[] = trim($line);
}
$a = $array[0];
$b = $array[1];

          if((2800 <= $a)&&(5000 > $a)){
            if($a < 3200){
              echo "red";
            }else{
              echo $b;
            
            }
          }
?>


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
int S[1000000]={0};
int T[50000]={0};

int main(){
	int n,q,k,ans=0;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> S[i];
	}
	cin >> q;
	for(int i=0;i<q;i++){
		cin >> T[i];
	}
	sort(T,T+q);
	sort(S,S+n);
	int t=0,s=0;k=-1;
	while(s<n && t<q){
		if(S[s]==T[t]){
			if(T[t]!=k)++ans;
			++s;
			k = T[t];
		}else if(S[s]>T[t]){
			++t;
		}else if(S[s]<T[t]){
			++s;
		}
	}
	cout << ans << endl;

	return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	if (v.size()) {
		os << v[0];
		for (int i = 1; i < v.size(); i++) os << " " << v[i];
	}
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

bool operator < (pair<int, string> a, pair<int, string> b) {
	if (a.first < b.first) return (true);
	if (a.first > b.first) return (false);
	return (a.second < b.second);
}

void Main() {
	int N, M; cin >> N >> M;
	int cost[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
	vint A(M); cin >> A;
	sort(rbegin(A), rend(A));

	vint dp(N+1, -INF);
	dp[0] = 0;

	for (int i = 0; i < M; i++) {
		int c = cost[A[i]];
		for (int j = 0; j < N; j++) {
			if (j+c <= N) chmax(dp[j+c], dp[j] + 1);
		}
	}

	int cur = N;
	while (cur > 0) {
		for (int i = 0; i < M; i++) {
			if (cur-cost[A[i]] >= 0 && dp[cur-cost[A[i]]] == dp[cur] - 1) {
				cout << (char)(A[i]+'0');
				cur -= cost[A[i]];
				break;
			}
		}
	}
	cout << el;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3672
s=input()
q=int(input())
q_=[input() for i in range(q)]
l=[]
r=list(s)
reverse=False
for i in q_:
  if i=="1":
    reverse=not reverse
  elif (i.split()[1]=="1" and not reverse) or (i.split()[1]=="2" and reverse):
    l.append(i.split()[2])
  else:
    r.append(i.split()[2])
#print(l)
#print(r)
if reverse:
  print(''.join(r[::-1]+l))
else:print(''.join(l[::-1]+r))

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

int main() {
    int n;
    int a[105];
    int count = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 1; i <= n; i += 2) {
        if (a[i] % 2 != 0) {
            count++;
        }
    }
    printf("%d", count);
    return 0;
}

Measured memory_bytes: 1728
//Created by Kira

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

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
    



int main(){
   IOS

    int n; cin>>n;
    string s; cin>>s;

    if(n & 1){
        cout<<"No\n";
    }else{

        if(s.substr(0, n/2) == s.substr(n/2, n/2)){
            cout<<"Yes\n";
        }
        else{
            cout<<"No\n";
        }

    }

}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1) res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}



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

#define F first
#define S second
#define ll long long
#define pb push_back
#define endl '\n'

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	cout << 1 - n << endl;
}


Measured memory_bytes: 3632
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		String s;
		int idt;
		BufferedReader kbd = new BufferedReader(new InputStreamReader(System.in));
			s = kbd.readLine();
			idt = Integer.parseInt(s);
			System.out.println(idt * idt * idt);
	}

}

Measured memory_bytes: 17056
#include <stdio.h>

int main(void)
{
	int i, j;
	int score[2], s;
	
	for (i = 0; i < 2; i++){
		score[i] = 0;
		for (j = 0; j < 4; j++){
			scanf("%d", &s);
			score[i] += s;
		}
	}
	
	if (score[0] > score[1]){
		printf("%d\n", score[0]);
	}
	else{
		printf("%d\n", score[1]);
	}
	
	return (0);
}

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

int main() {
  int A, B;
  
  cin >> A >> B ;
  
  
  if ((A*B)%2==0) {
    cout << "Even" << endl;
  }
  
  else  {
    cout << "Odd"<< endl;
  } 
}


Measured memory_bytes: 256
import sys

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


def main():
    from collections import Counter
    h, w = map(int, readline().split())
    c = Counter()
    res = [[""] * w for _ in range(h)]

    for _ in range(h):
        s = list(input())
        c.update(s)

    d = Counter()

    if h % 2 == 1 and w % 2 == 1:
        d[1] = 1
        d[2] = (h - 1) // 2 + (w - 1) // 2
    elif h % 2 == 1 and w % 2 == 0:
        d[1] = 0
        d[2] = w // 2
    elif h % 2 == 0 and w % 2 == 1:
        d[1] = 0
        d[2] = h // 2
    d[4] = (h * w - d[1] - 2 * d[2]) // 4

    keys = c.keys()

    for key in keys:
        if c[key] % 2 == 1:
            c[key] -= 1
            d[1] -= 1

    for key in keys:
        if c[key] % 4 == 2:
            c[key] -= 2
            d[2] -= 1

    for key in keys:
        if c[key] % 4 == 0:
            d[4] -= c[key] // 4
            c[key] = 0

    while d[2] > 0:
        d[2] -= 2
        d[4] += 1

    if d[1] == d[2] == d[4] == 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s1, s2;
    cin >> s1 >> s2;
    reverse(s2.begin(), s2.end());
    if(s1 == s2){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << 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);
        char[] input = sc.next().toCharArray();
        int k = sc.nextInt();
        int index = 0;
        while(k > 0 && index < input.length){
            int diff = input[index] - 'a';
            if(diff == 0){
                
            }else if(diff + k >= 26){
                input[index] = 'a';
                k = k - (26 - diff);
            }
            index += 1;
        }
        index = input.length - 1;
        input[index] = (char) (((input[index] - 'a' + k) % 26) + 'a');
        String result = new String(input);
        System.out.println(result);
    }
}

Measured memory_bytes: 26168
#define ll long long int
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define maxx(a,b) std::max(a,b)
#define maxxx(a,b,c) std::max(a,std::max(b,c))
#define minn(a,b) std::min(a,b)
#define minnn(a,b,c) std::min(a,std::min(b,c))

#include <bits/stdc++.h>
using namespace std;
int main()
{
   
   int a,b,c,k;
   cin>>a>>b>>c>>k;
   ll sum=0;
   while(k--)
   {
       if(a>0){sum+=1;a--;continue;}
       else if(b>0){b--;continue;}
       else if(c>0){sum-=1;c--;continue;}
   }
   cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 3624
b1,b2,b3=map(int,input().split())
if b1==1:
    if b2==1:
        print("Open")
    if b2==0:
        print("Close")
if b2==1:
    if b1==0:
        print("Close")
if b3==1:
        print("Open")
if b1==0 and b2==0 and b3==0:
    print("Close")


Measured memory_bytes: 5596
/*
    Created by Ezio112
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
ll inf(1e18);
#define mod ll(1e9+7)
//#define mod ll(998244353)
#define ff first
#define ss second
ll power(ll a,ll b)
{
	if(!b)
		return 1;
	ll dp=power(a,b/2)%mod;
	
	if(b&1) return (((dp*dp)%mod)*a)%mod;
	
	return (dp*dp)%mod;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll test=1;
    //cin>>test;

    while(test--)
    {
		ll n;
		cin>>n;
		unordered_map<ll,ll> div;
		
		ll r=2;
		while(n!=1 && r*r<n)
		{
			while(n%r==0)
			{
				div[r]++;
				n/=r;
			}
			++r;
		}
		if(n>1)
			div[n]++;
		ll ways=0;
		
		for(auto x:div)
		{
			ll p=x.ss;
			ll taken=1;
			while(p>=taken)
			{
				++ways;
				p-=taken;
				++taken;
			}
		}
		cout<<ways;
	}
	return 0;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int board[11][11];

int conv(int a, int b, int c, int d, int e) {
    int n1 = board[0][a];
    int n2 = board[n1][b];
    int n3 = board[n2][c];
    int n4 = board[n3][d];
    return board[n4][e];
}

bool check(int a, int b, int c, int d, int e) {
    rep(aa, 10) {
        if (a == aa) continue;
        if (conv(aa, b, c, d, e) == 0) return false;
    }
    rep(bb, 10) {
        if (b == bb) continue;
        if (conv(a, bb, c, d, e) == 0) return false;
    }
    rep(cc, 10) {
        if (c == cc) continue;
        if (conv(a, b, cc, d, e) == 0) return false;
    }
    rep(dd, 10) {
        if (d == dd) continue;
        if (conv(a, b, c, dd, e) == 0) return false;
    }
    rep(ee, 10) {
        if (e == ee) continue;
        if (conv(a, b, c, d, ee) == 0) return false;
    }

    if (a != b and conv(b, a, c, d, e) == 0) return false;
    if (b != c and conv(a, c, b, d, e) == 0) return false;
    if (c != d and conv(a, b, d, c, e) == 0) return false;
    if (d != e and conv(a, b, c, e, d) == 0) return false;

    return true;
}

int main() {
    rep(i, 10) rep(j, 10) cin >> board[i][j];
    int ans = 0;
    rep(a, 10) {
        int n1 = board[0][a];
        rep(b, 10) {
            int n2 = board[n1][b];
            rep(c, 10) {
                int n3 = board[n2][c];
                rep(d, 10) {
                    int e = board[n3][d];
                    if (!check(a, b, c, d, e)) ans++;
                }
            }
        }
    }
    cout << ans << endl;
}



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

long long ans = 0,pow[51] = {1};
int A[51],B[51],visited[51] = {0};
bool use[51] = {0};
int N;

bool dfs(vector<vector<int>>& v, int n,int x){
	visited[n] = 1;
	if(n==x){
		return true;
	}
	bool j = false;
	for(int i=0;i<v[n].size();i++){
		if(visited[v[n][i]]==0) j = (j | dfs(v,v[n][i],x));
	}
	return j;
}

int main(){
	cin >> N;
	for(int i=1;i<=50;i++){
		pow[i] = 2*pow[i-1];
		use[i] = true;
	}
	for(int i=1;i<=2*N;i++){
		if(i<=N) cin >> A[i];
		else cin >> B[i-N];
	}
	bool pos = true;
	for(int i=1;i<=N;i++){
		if((2*B[i]>=A[i] && A[i]!=B[i]) || A[i]<B[i]) pos = false;
	}
	if(!pos){
		cout << -1 << endl;
		return 0;
	}
	vector<vector<int>> v(51);
	for(int num=50;num>=1;num--){
		bool judge = false;
		for(int i=1;i<=N;i++){
			for(int j=0;j<=50;j++){
				v[j].clear();
				visited[j] = 0;
			}
			for(int j=1;j<=A[i];j++){
				for(int k=1;k<=50;k++){
					if(k!=num && use[k]){
						v[j].push_back(j%k);
					}
				}
			}
			if(!dfs(v,A[i],B[i])){
				judge = true;
				break;
			}
		}
		use[num] = judge;
	}
	for(int i=1;i<=50;i++){
		if(use[i]) ans += pow[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n,x = list(map(int,input().split()))

#n=1~50までのパティの数と、バーガーの長さ
l = [(1,1)]
for i in range(1,51):
    l.append((l[-1][0]*2+1,l[-1][1]*2+3))

def calc(dim,eat):
    ret = 0
    if eat==0:
        return 0
    elif dim==0:
        return 1
    else:
        if eat < l[dim][0]:
            ret+=calc(dim-1,eat-1)
        elif eat==l[dim][1]:
            return l[dim][0]
        else:
            ret+=(l[dim-1][0]+1+calc(dim-1,eat-l[dim][0]))
    return ret

print(calc(n,x))

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>

using namespace std;

#define PI 3.14159265358979323846264338327950

int main() {
	long double A, B, H, M;

	cin >> A >> B >> H >> M;

	long double h, m,kaku;
	m = (long double)M / 60 * 2 * PI;
	h = ((long double)H / 12 + (long double)M / 720) * 2 * PI;
	kaku = fabs(m - h);

	long double ans;

	ans = A * A + B * B - 2 * A * B * cosl(kaku);
	ans = sqrt(ans);
	cout << fixed << setprecision(20) << ans << endl;

	return 0;
}

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

int combine(int n, int x){
    int m = 0;

    for (int i = 1; i <= n; i++){
        for (int j = i + 1; j <= n; j++){
            for (int k = j + 1; k <= n; k++){
                if (i + j + k == x) m += 1;
            }
        }
    }

    return m;
}

int main(){
    int n, x;

    while(1){
        cin >> n >> x;
        if (n == 0 && x == 0) break;
        else {
            cout << combine(n, x) << endl;
        }
        
    }
   
}



Measured memory_bytes: 3120
def f(vs):
    t = 0
    for i in range(len(vs)):
        c, s, f = vs[i]
        m = max(0, (t - s + f - 1) / f)
        t = s + m*f + c
    return t

def solve():
    n = input()
    vs = [map(int, raw_input().split()) for i in range(n-1)]
    return [f(vs[i:]) for i in range(n)]

print "\n".join(map(str, solve()))

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    ll h; cin>>h;
    vector<pll> ba(n);
    rep(i,n) cin>>ba[i].se>>ba[i].fi;
    sort(rall(ba));
    ll bsum=0;
    ll amax=0;
    ll ans=1e10;
    rep(i,n){
        chmax(amax,ba[i].se);
        bsum+=ba[i].fi;
        int H = h-bsum;
        chmin(ans,i+1+max(0ll,(H+amax-1)/amax));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
a, b = map(int, input().split())
str1 = list(input())  # 1文字区切りでリスト格納

if 'a' <= str1[b-1] and 'z'>=str1[b-1]:
    str1[b-1] = str1(str1[b-1]).upper()
    for s in str1:
        print(s, end="")
else:
    str1[b-1] = str(str1[b-1]).lower()
    for s in str1:
        print(s, end="")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define inf 1000000007
#define MAXN 250
#define MAXT 250
#define ff first
#define ss second
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef pair<int,int> pii;

	
int32_t main(){
	fastio;
	int n,m;
	cin>>n>>m;
	
	int ini=-1;
	int fim=n;
	
	for(int i=0;i<m;i++){
		int l,r;
		cin>>l>>r;
		ini=max(ini,l);
		fim=min(fim,r);
	}
	if(fim-ini+1<0)cout<<0<<endl;
	else cout<<fim-ini+1<<endl;
}

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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template<class A, class B>
inline bool chmax(A &a, const B &b) { return b > a ? a = b, 1 : 0; }

template<class A, class B>
inline bool chmin(A &a, const B &b) { return b < a ? a = b, 1 : 0; }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

//IN
void IN() {}
template<class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

//OUTS
template<size_t> struct int_{};
template<class Tuple, size_t Pos>
ostream& print_tuple(ostream& out, const Tuple& t, int_<Pos>) {
  out << get<tuple_size<Tuple>::value-Pos>(t) << " ";
  return print_tuple(out, t, int_<Pos-1>());
}

template <class Tuple>
ostream& print_tuple(ostream& out, const Tuple& t, int_<1>) {
  return out << get<tuple_size<Tuple>::value-1>(t);
}

template<class... Args>
ostream& operator<<(ostream& out, const tuple<Args...>& t) {
  return print_tuple(out, t, int_<sizeof...(Args)>());
}

#define OUTS(...) cout << make_tuple(__VA_ARGS__) << "\n";

//OUTL
void OUTL() {}
template<class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}
// }}} End

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

  int n;
  IN(n);

  i64 res = 0;
  map<int, int> mp;
  reps(i, 1, n) {
    int a; IN(a);
    mp[i] = a;
    if (mp[a] == i) ++res;
  }

  OUTL(res);

  return 0;
}


Measured memory_bytes: 4992
G = {i:[] for i in range(1,5)}
for _ in range(3):
    a,b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)
cnt = 0
for x in G:
    if len(G[x])%2==1:
        cnt += 1
if cnt>2:
    print("NO")
else:
    print("YES")

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
using namespace std;
int F(long long A, long long B) {
    long long t = A>B?A:B;
    int cnt = 1;
    while(t/=10) cnt++;
    return cnt;
}
int main() {
    long long N; cin >> N;
    int min = 11;
    for(int i = 1, d; i <= sqrt(N); i++) {
        if(N%i == 0) d = F(i, N/i);
        if(min > d) min = d;
    }
    cout << min;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,tmp;cin >> tmp >> s >> tmp;
	cout << "A" << s.at(0) << "C" << endl;
}


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

#define MAX 100
#define THOU 1000
#define FIVEMAX 100000
#define NINEMAX 1000000000
#define TWEMAX 1000000000000
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define arep(i,a,n) for(int i=a;i<n;i++)

int main(){
 
 string str;
 vector<int>v;

 map<string,int>m;
 pair<int,int>p;
 int h,w,ch,cw,dh,dw;
 char s[THOU+1][THOU+1];
 cin>>str;
 long long sum=0;
 rep(i,str.length())sum+=(str[i]-'0');
 
 if(sum%9==0)cout<<"Yes"<<endl;
 else cout<<"No"<<endl;

cin.tie(0);
ios::sync_with_stdio(false);

return 0;
}

Measured memory_bytes: 3800
#include <iostream>

using namespace std;

int main() {
  for (;;) {
    int N, M, result = 0;
    cin >> N >> M;
    if (!N && !M) return 0;
    int board[N], dices[M];
    for (int i = 0; i < N; i++)
      cin >> board[i];
    for (int i = 0; i < M; i++)
      cin >> dices[i];
    for (int c = 0;;) {
      c += dices[result];
      result++;
      if (c >= N - 1) break;
      c += board[c];
      if (c >= N - 1) break;
    }
    cout << result << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool bigorder(const int& a, const int& b)
{
  return a > b;
}
int main()
{
  int K, N;
  cin >> N >> K;
  vector <int> A(N+1);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A[a]++;
  }
  sort(A.begin(), A.end(), bigorder);
  int ans = 0;
  for (int i = K; i <= N; i++) {
    ans += A[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const ll mod = 1e9+7;

int a,b,c;

int main()
{
    cin >> a >> b >> c;
    int fl = 0;
    if(a == 7){
        if(b == 5 && c == 5) fl = 1;
    }
    if(b == 7){
        if(a == 5 && c == 5) fl = 1;
    }
    if(c == 7){
        if(b == 5 && a == 5) fl = 1;
    }
    if(fl == 1) puts("YES");
    else puts("NO");
    return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main() 
{

  int a,b;
  cin>>a>>b;
  if (a>b)
  {
      cout<<a+(a-1)<<endl;
  }
  else if (a==b)
  {
      cout<<2*a<<endl;
  }
  else
  {
      cout<<b+(b-1)<<endl;
  }

  return 0;
}

Measured memory_bytes: 3640
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    ll k, t; cin >> k >> t;
    vll a(t);
    Map m;
    ll mx = 0; ll s = 0;
    rep(i, 0, t){
        cin >> a[i];
        m[i] = a[i];
        s += a[i]; mx = max(mx, a[i]);
    }
    ll g = s - mx;
    if(mx < g){
        prtl(0);
    }else{
        prtl(mx - g - 1);
    }
}



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

int main() {

  int N, M;
  cin >> N >> M;

  int L = 0;
  int R = N;
  for (int i = 0; i < M; i++) {
    int L_, R_;
    cin >> L_ >> R_;
    L = max(L, L_);
    R = min(R, R_);
  }

  if (L <= R) {
    cout << R - L + 1 << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;

}

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


int main()
{
	vector<int> a = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int k;
	cin >> k;
	cout << a[k - 1] << endl;
	return 0;

}

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

int main()
{
    int n;
    std::cin>>n;
    std::vector<std::vector<int>> hen(n);
    std::vector<std::pair<int,int>> p;
    for(int i=0;i<n-1;i++){
        int a,b;
        std::cin>>a>>b;
        a--;b--;
        hen[a].push_back(b);
        hen[b].push_back(a);
        p.push_back({a,b});
    }


    std::map<std::pair<int,int>,int> mp;
    std::vector<int> color(n,0);
    std::vector<int> used(n,0);
    std::queue<int> que;
    used[0] = 1;
    que.push(0);

    while(que.size()){
        int v = que.front();
        que.pop();
        int cur = 1;
        for(int u : hen[v]){
            if(used[u])continue;
            if(cur == color[v]) cur++;
            color[u] = mp[{u,v}] = mp[{v,u}] = cur;
            cur++;
            used[u] = 1;
            que.push(u);
        }
    }
    std::cout<<*std::max_element(color.begin(),color.end())<<std::endl;
    for(auto vp : p)std::cout<<mp[vp]<<std::endl;
}

Measured memory_bytes: 20084
import java.util.*;

class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = Integer.parseInt(sc.next());
    int B = Integer.parseInt(sc.next());
    int C = Integer.parseInt(sc.next());
    int X = Integer.parseInt(sc.next());
    
    int res = 0;
    for(int a=0; a<=A; a++){
      for(int b=0; b<=B; b++){
        int c = (X-a*500-b*100)/50;
        if(c>=0 && c<=C){
          res++;
        }
      }
    }
    System.out.println(res);
  }
}

Measured memory_bytes: 21844