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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  a[0] = 0;
  rep(i, n) cin >> a[i + 1];
  dump(n, a);
  map<int, int> mp;
  function<int(int)> check = [&](int k) {
    dump(k);
    mp.clear();
    for (int i = 1; i <= n; i++) {
      if (i == 1) mp[a[i] - 1] = 0;
      if (a[i - 1] < a[i]) {
        // 何もしない
      } else {
        // auto it = mp.lower_bound(a[i]);
        auto it = mp.upper_bound(a[i] - 1);
        mp.erase(it, mp.end());
        int j = a[i] - 1;
        if (k == 1) {
          j = -1;
        } else {
          while (mp[j] + 1 >= k) {
            mp[j] = 0;
            j--;
          }
        }
        if (0 <= j) {
          mp[j] += 1;
        } else {
          dump("false", mp);
          return false;
        }
      }
      dump(mp);
    }
    return true;
  };
  int ans = 0;
  // for (int k = 1; k < n; k++) {
  //   if (check(k)) {
  //     ans = k;
  //     break;
  //   }
  // }
  // index=0が条件を満たすこともあるので、leftの初期値は-1
  int left = 0;
  // index=a.size()-1が条件を満たさないこともあるので、rightの初期値はa.size()
  int right = n;
  while (right - left > 1) {
    int mid = left + (right - left) / 2;
    if (check(mid))
      right = mid; // 例えば(key<=a[mid])など
    else
      left = mid;
  }
  ans = min(n, right);
  // leftは条件を満たさない最大の値、rightは条件を満たす最小の値になっている
  dump(ans);
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<sstream>
using namespace std;
int main(){
	char b[4]={'3','5','7'};
	map<int,bool> M;
    queue<string> q;
    q.push("357");
    q.push("375");
    q.push("537");
    q.push("573");
    q.push("735");
    q.push("753");
    int w=3;
    int count=6,nn=0,n,ans=6;
    stringstream ss;
    cin>>n;
    if(n>=3357){
    	while(w>0){
	    	int sign=0,x;
	    	for(int j=1;j<=count;j++){
	    		string str=q.front(),str1;
		    	q.pop();
		    	for(int i=0;i<3;i++)
		    	{
		    		str1=b[i]+str;
		    		ss<<str1;
		    		ss>>x;
		    		ss.clear();
		    		if(x<=n)
		    		{
		    			if(M[x]==0)
						{
							q.push(str1);
			    			nn++;
			    			ans++;
			    			M[x]=1;
						}
					}
					else{
						sign=1;
					}
				}
		    	for(int i=1;i<w-1;i++){
		    		for(int k=0;k<3;k++){
		    			str1=str.substr(0,i)+b[k]+str.substr(i);
			    		ss<<str1;
			    		ss>>x;
			    		ss.clear();
			    		if(x<=n)
			    		{
			    			if(M[x]==0)
							{
								q.push(str1);
				    			nn++;
				    			ans++;
				    			M[x]=1;
							}
						}
						else{
							sign=1;
						}
					}
		    		
				}
				for(int i=0;i<3;i++)
		    	{
		    		str1=str+b[i];
		    		ss<<str1;
		    		ss>>x;
		    		ss.clear();
		    		if(x<=n)
		    		{
		    			if(M[x]==0)
						{
							q.push(str1);
			    			nn++;
			    			ans++;
			    			M[x]=1;
						}
					}
					else{
						sign=1;
					}
				}
			}
			count=nn;
	    	nn=0;
	    	if(sign){
	    		break;
			}
			w++;
		}
	}
    else if(n>=753) ans=6;
    else if(n>=735) ans=5;
    else if(n>=573) ans=4;
    else if(n>=537) ans=3;
    else if(n>=375) ans=2;
    else if(n>=357) ans=1;
    else ans=0;
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int n ;
int r[4010] , g[4010] , b[4010] ;

ll solve(int i , int a[] , int b[]){
    ll ans = 0 , cnt1=0 , cnt2=0;
    for (int j = i+1 ; j<=n ; j++){
        //cout << i << " " << j << " " << j+(j-i) << " " << a[j] << " " << b[j+j-i] << endl;
        if (a[j]){
            cnt1++;
            if (j+(j-i)<=n&&b[j+(j-i)])ans--;
        }
        else if(b[j]){
            cnt2++;
            if (j+(j-i)<=n &&a[j+(j-i)])ans--;
        }
    //cout << ans << endl;
    }
    return (cnt1*cnt2) +ans;
}


int main()
{
string s ; cin >> n;
cin >> s ;
for (int i=0 ; i<s.size() ;++i){
    if (s[i]=='R')r[i+1]=1;
    else if (s[i]=='G')g[i+1]=1;
    else b[i+1]=1;
}
ll ans =0;
for (int i = 0 ; i < s.size() ; i++){
    if(s[i]=='R')ans+=solve(i+1,g,b);
    else if (s[i]=='G')ans+=solve(i+1,r,b);
    else ans+=solve(i+1,r,g);
}
cout << ans ;

}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

typedef long long ll;
struct unionfind{
	int par[100000];
	ll d[100000];
	void init(int n) { rep(i,n) par[i]=i,d[i]=0; }
	int find(int x){
		if(x==par[x]) return x;
		int r=find(par[x]);
		d[x]+=d[par[x]];
		return par[x]=r;
	}
	bool unite(int x,int y,int z){		//w[x]-w[y]=z	
		int rx=find(x),ry=find(y);
		if(rx==ry){
			if(diff(x,y)!=z) return 0;
			return 1;
		}
		d[ry]=d[x]-d[y]-z;
		par[ry]=rx;
		return 1;
	}
	int diff(int x,int y){		//w[x]-w[y]=?
		find(x),find(y);			//いる!!
		return d[x]-d[y];
	}
	bool same(int x,int y) { return find(x)==find(y); }
}UF;

int N,M;
int main(){
	cin>>N>>M;
	UF.init(N);
	rep(i,M){
		int x,y,d;
		cin>>x>>y>>d;
		x--,y--;
		if(!UF.unite(x,y,d)){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
}


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

#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
inline string numstr(int m){str s="";while(m>0){char c;int a=m/10;if(a>0)a=m%(a*10);else a=m;c=(char)('0'+a);s+=c;m/=10;}str st="";for(int i=s.size()-1;i>=0;i--){st+=s[i];}return st;}
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
int dp[4005][4005];
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    str n,m;
    while(cin >> n){
    rep(i,0,4001){
        rep(j,0,4001){
        dp[i][j]=0;
        //cout << dp[i][j];
        }
    }
    cin >> m;
    rep(i,0,n.size()){
        rep(j,0,m.size()){
            if(n[i]==m[j]){
                if(i==0||j==0)dp[i][j]=1;
                else dp[i][j]=dp[i-1][j-1]+1;
            }
        }
    }int ans=0;
    rep(i,0,n.size()){
        rep(j,0,m.size()){
        ans=max(ans,dp[i][j]);
        //if(ans==6)cout << i << " " << j <<" ";
        }
    }
    cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 128320
import java.util.*;

import static java.lang.System.*;

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

        int[] C = new int[N];
        int[] S = new int[N];
        int[] F = new int[N];
        for (int i = 0; i < N - 1; i++) {
            C[i] = sc.nextInt();
            S[i] = sc.nextInt();
            F[i] = sc.nextInt();
        }

        for (int i = 0; i < N; i++) {
            int time = 0;
            for (int j = i; j < N - 1; j++) {
                int start = S[j];
                if (time > S[j]) {
                    if ((time - S[j]) % F[j] != 0) {
                        start = S[j] + (((time - S[j]) / F[j]) + 1) * F[j];
                    } else {
                        start = time;
                    }
                }

                int wait = start - time;
                time += wait + C[j];
            }
            out.println(time);
        }
    }
}

Measured memory_bytes: 27944
#include<bits/stdc++.h>
using namespace std;
int main()
{
        string a;
        int a0 = 0, a1 = 0;
        cin >> a;
        for (int i = 0; i < a.length(); i++)
        {
                if (a[i] == '0')
                {
                        a0++;
                }
                if (a[i] == '1')
                {
                        a1++;
                }

        }
        cout<<min(a0,a1)*2<<endl;
        return 0;
}


Measured memory_bytes: 512
#include<cstdio>
using namespace std;
long long a,b,x;
long long s,e;
int main(){
    scanf("%lld%lld%lld",&a,&b,&x);
    if(a%x==0)s=a/x;
    else s=a/x+1;
    e=b/x;
    printf("%lld",e-s+1);
    return 0;
}

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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back

#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i++)
#define RepA(x) for(auto item : (x))
#define output_s(a) printf("%s\n",(a).c_str())

//library----------------------------------------------


int main(){
    int k,x;cin>>k>>x;
    printf(k*500>=x?"Yes":"No");
    return 0;
}

Measured memory_bytes: 256
mod = 10 ** 9 + 7

N = int(input())
s = raw_input()
ans, cnt, tmp = 1, 0, 0
for i in xrange(1, N*2+1):
    if (cnt & 1) ^ (s[i-1] == 'B'):
        cnt += 1
    else:
        ans = (ans * cnt) % mod
        cnt -= 1
        tmp += 1
for i in xrange(1, N+1):
    ans = ans * i % mod

print(ans if tmp == N else 0)

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


int main(){
  int N;
  cin  >> N;
  string ans = "";
  while(N != 0){
    if(N % 2 != 0){
      N--;
      ans = "1" + ans;
    }
    else{
      ans = "0" + ans;
    }
    N /= (-2);
  }
  if(ans == ""){
    ans = "0";
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int ar[3],b,c,d,e,f,i,tm;
    scanf ("%d %d %d",&ar[0],&ar[1],&ar[2]);
    for (i=0;i<2;i++)
    {
        for (f=2;f>0;f--)
        {
            if (ar[f]<ar[f-1])
            {
                tm=ar[f];
                ar[f]=ar[f-1];
                ar[f-1]=tm;
            }
        }
    }
    printf ("%d",((ar[2]-ar[1])+ar[1]-ar[0]));
    return 0;
}


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

typedef pair<int, int> pii;

vector<vector<int> > ans;
vector<int> cnt;

int main() {
    int K = 38, N = K*K - K + 1;
    //int N = 13, K = 4;

    cnt = vector<int>(N, 0);

    for(int i = 0; i < K; i++) {
        ans.push_back(vector<int>());
        ans.back().push_back(0);
        cnt[ans.back().back()]++;
        for(int j = 0; j < K - 1; j++) {
            ans.back().push_back(i*(K - 1) + j + 1);
            cnt[ans.back().back()]++;
        }
    }

    for(int i = 1; i < K; i++) {
        for(int j = 0; j < K - 1; j++) {
            ans.push_back(vector<int>());
            ans.back().push_back(i);
            cnt[ans.back().back()]++;

            for(int k = 0; k < K - 1; k++) {
                int t = ans[k + 1][((i - 1)*k + j) % (K - 1) + 1];
                ans.back().push_back(t);
                cnt[ans.back().back()]++;
            }
        }
    }

    printf("%d %d\n", N, K);
    for(int i = 0; i < ans.size(); i++) {
        //cout << ans[i].size() << endl;
        //*
        for(int j = 0; j < K; j++) {
            printf("%d ", ans[i][j] + 1);
        }
        printf("\n");
        //*/
    }
}


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b)* b; }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int n,k; cin>>n>>k;
  vi h(n);
  rep(i,n) cin>>h[i];
  
  int dp[n];
  fill(dp, dp+n, INF);
  dp[0]=0;
  for(int i=1; i<n; i++){
    for(int j=i-1; j>=max(0,i-k); j--){
      chmin(dp[i], dp[j]+abs(h[i]-h[j]));
    }
  }
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"

using namespace std;

const int MSIZE  = 100100;

long long dp[MSIZE];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    memset(dp, 0x3f, sizeof dp);
    int n, k;
    cin >> n >> k;
    vector<int> arr(n);
    for (int i = 0; i < n; i++) cin >> arr[i];
    dp[0] = 0;

    for (int i = 1; i < n; i++) {
        for (int j = 1; j <= k; j++) {
            if (i - j < 0) continue;
            dp[i] = min(dp[i], dp[i - j] + abs(arr[i] - arr[i - j]));
        }
    }
    cout << dp[n - 1] << endl;
}

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

int main(void){
  string s;
  cin >> s;
  vector<int> arr(2,0);
  for(int i = 0; i < s.size(); i++){
    if((s[i] - '0') == i % 2)arr[0]++;
    else arr[1]++;
  }
  cout << min(arr[0],arr[1]) << endl;
  return 0;
}

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

int main() {
	int n, m;
	cin >> n>>m;
	vector<int>b(50); 
	vector<int>a(50);
	vector<int>countc(51);
	for (int i = 0; i < m; i++) {
		cin>>a.at(i)>>b.at(i);
	}
	for (int i = 0; i < m; i++) {
		for (int s = 1; s <= n ; s++) {
			if (a.at(i) == s) {
				countc.at(s)++;
			}
			if (b.at(i) == s) {
				countc.at(s)++;
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << countc.at(i) << endl;
	}
	
}

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

int main() {

  string S;
  cin >> S;

  if (S[2] == S[3] && S[4] == S[5]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <math.h>
#include <algorithm>
#define pii pair<int, int>

using namespace std;

int niz[100010], dp[100010];
int main()
{
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> niz[i];
	for (int i = 1; i <= n; i++)
		dp[i] = 1000000000;
	for (int i = 1; i < n; i++)
	{
		for (int j = 1; j <= k; j++)
		{
			if (i - j < 0)
				break;
			dp[i] = min(dp[i], dp[i - j] + abs(niz[i - j] - niz[i]));
		}
	}
	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();

            long cl = in.nextLong();
            long cr = in.nextLong();

            for (int i = 0; i < n - 1; i++) {
                long nl = in.nextLong();
                long nr = in.nextLong();

                cl = (cl % nl == 0) ? (cl / nl) * nl : (1 + (cl / nl)) * nl;
                cr = (cr % nr == 0) ? (cr / nr) * nr : (1 + (cr / nr)) * nr;
                if (cl < (nl * (cr / nr)))
                    cl = nl * (cr / nr);
                if (cr < (nr * (cl / nl)))
                    cr = nr * (cl / nl);
            }

            out.println(cl + cr);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long nextLong() {
            long n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

        public int nextInt() {
            long n = nextLong();

            if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE)
                throw new NumberFormatException();

            return (int) n;
        }

    }
}



Measured memory_bytes: 23380
N,M=map(int,input().split())
H=list(map(int,input().split()))
l=[1]*N
for i in range(M):
    A,B=map(int,input().split())
    A-=1
    B-=1
    if H[A] <= H[B]:
        l[A] = 0
    if H[A] >= H[B]:
        l[B] = 0
print(l.count(1))

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;i++)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

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

#define int ll

const int inf = 1ll<<62;
const int mod = 1e9+7;

main(){
  int n; cin >> n;
  string s,t; cin >> s >>t;
  rep(i, n){
    if(s.substr(i, n - i) == t.substr(0, n - i)){
      cout << i + n<< endl;
      return 0;
    }
  }
  cout << 2 * n << endl;
}

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

using namespace std;

int n, d;

int main()
{
	cin >> n >> d;
	
	int ile=0;
	
	for(int m = 4; m <= n; ++m)
		for(int i=2; i <= 9; ++i)
		{
			if(m % i || m / i > 9)continue;
			
			if(10*i + (m / i) <= d && m / i > 1)
				++ile;
		}
	
	cout << ile;
}


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

using namespace std;

typedef long double ld;

struct Point {
    ld x, y;
    Point(ld x=0.0, ld y=0.0) : x(x), y(y) {}
    string to_s() {
        ostringstream os;
        os << x << ',' << y;
        return os.str();
    }
    Point operator+(const Point& o) const {
        return Point(x+o.x, y+o.y);
    }
};

struct Circle {
    ld x, y;
    ld r;
    Circle(ld x=0.0, ld y=0.0, ld r=1.0) : x(x), y(y), r(r) {}
    const static ld eps = 1e-8;
    bool isIntersect(const Circle& o) const {
        ld dx = o.x - x;
        ld dy = o.y - y;
        return (r + o.r) * (r + o.r) > (dx*dx + dy*dy);
    }
    pair<Point, Point> intersectionPoint(const Circle& o) const {
        ld dx = x - o.x;
        ld dy = y - o.y;
        ld a = (dx*dx + dy*dy + r*r - o.r*o.r) / 2.0;
        ld d = sqrt((dx*dx+dy*dy)*r*r-a*a);
        Point p, q;
        p.x = (a*dx + dy * d) / (dx*dx+dy*dy) + o.x;
        q.x = (a*dx - dy * d) / (dx*dx+dy*dy) + o.x;
        p.y = (a*dy - dx * d) / (dx*dx+dy*dy) + o.y;
        q.y = (a*dy + dx * d) / (dx*dx+dy*dy) + o.y;
        //cout << p.x << ',' << p.y << endl;
        //cout << q.x << ',' << q.y << endl;
        return make_pair(p, q);
    }
    bool contains(ld px, ld py) const {
        return r*r + eps >= (px - x) * (px - x) + (py - y) * (py - y);
    }
    string to_s() {
        ostringstream os;
        os << x << ',' << y << ':' << r << endl;
        return os.str();
    }
};

int countContainingPoints(const Circle& c, const vector<Circle>& ps) {
    int cnt = 0;
    for (int i = 0; i < ps.size(); i++) 
        if (c.contains(ps[i].x, ps[i].y)) 
            cnt++;
    return cnt;
}

int N;
int main() {
    //cout << Circle(0, 0, 5).intersectionPoint(Circle(8, 0, 5)).first.to_s() << endl;
    vector<Circle> cs;
    while (cin >> N, N) {
        cs.clear(); cs.resize(N);
        for (int i = 0; i < N; i++) cin >> cs[i].x >> cs[i].y;

        vector<Point> ips; // Intersection PointS
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (i == j) continue;
                if (!cs[i].isIntersect(cs[j])) continue;
                pair<Point, Point> ip = cs[i].intersectionPoint(cs[j]);
                ips.push_back(ip.first);
                ips.push_back(ip.second);
            }
        }

        if (ips.empty()) {
            cout << 1 << endl;
            continue;
        }

        int maxPoint = 0;
        for (int i = 0; i < ips.size(); i++) {
            maxPoint = max(maxPoint, countContainingPoints(Circle(ips[i].x, ips[i].y, 1.0), cs));
        }
        cout << maxPoint << endl;
    }
    return 0;
}

Measured memory_bytes: 4816
use proconio::*;

fn main() {
    input! {
        n: usize,
        s: i64,
    }

    let mut v = vec![];
    for _ in 0..n {
        input! {
            x: i64,
        }

        v.push(x);
    }
    // v.sort();

    let m = 998244353;
    let mut d = [0; 3001];
    let mut p = [0; 3001];
    d[0] = 1;
    for i in 0..n {
        for j in 0..s+1 {
            let iter = (s - j) as usize;
            p[iter] = d[iter] * 2;
            p[iter] %= m;
            if iter >= v[i] as usize {
                p[iter] += d[iter - v[i] as usize];
                p[iter] %= m;
            }
        }
        for j in 0..s as usize + 1 {
            d[j] = p[j];
        }
    }

    println!("{}", p[s as usize]);
}

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

int n, m, ans;

priority_queue<int>q;

template<class T>inline void read(T &x) {
    x = 0;int f = 0;char ch = getchar();
    while(!isdigit(ch)) f |= (ch == '-'),ch = getchar();
    while(isdigit(ch)) x = x * 10 + ch - '0',ch = getchar();
    x = f ? -x : x;
    return ;
}

signed main() {
    read(n), read(m);
    for (int i = 1, x; i <= n; ++i) read(x), q.push(x); 
    while (m) {
        int u = q.top();
        q.pop();
        u /= 2;
        m--;
        q.push(u);
    }
    while (!q.empty()) {
        ans += q.top();
        q.pop();
    }
    cout << ans;
}

Measured memory_bytes: 1400
s=input()

i=0
flug=0
for x in range(1,len(s)+1):
    if(x%2==1):
        if(s[x-1] =='L'):
            flug=1
            break
    else:
        if(s[x-1] =='R'):
            flug=1
            break

if(flug==1):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3060
from sys import stdin

def main():

    input = stdin.readline

    S = input()[:-1]

    if len(S) % 2 == 1:
        print("No")
        return

    for i in range(len(S)//2):

        if (S[i*2:i*2+2] == "hi"):
            continue
        else:
            print("No")
            return
    
    print("Yes")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
d = {}
n = int(input())
for i in range(n):
	s, x = input().split()
	x = int(x)
	if s in d:
		d[s].append([x, i])
	else:
		d[s] = [[x, i]]
a = []
for key in d:
	b = d[key]
	b.sort(reverse = True)
	a.append([key, b])
a.sort()
for x in a:
	for y in x[1]:
		print(y[1] + 1)


Measured memory_bytes: 3064
#include<stdio.h>

typedef int value_type; /* ソートするキーの型 */

value_type med3(value_type x, value_type y, value_type z)
/* x, y, z の中間値を返す */
{
    if (x < y)
        if (y < z) return y; else if (z < x) return x; else return z; else
        if (z < y) return y; else if (x < z) return x; else return z;
}

void quicksort(value_type a[],value_type b[], int left, int right)
/* クイックソート
 * a     : ソートする配列
 * left  : ソートするデータの開始位置
 * right : ソートするデータの終了位置
 */
{
    if (left < right) {
        int i = left, j = right;
        value_type tmp, pivot = med3(a[i], a[i + (j - i) / 2], a[j]); /* (i+j)/2ではオーバーフローしてしまう */
        while (1) { /* a[] を pivot 以上と以下の集まりに分割する */
            while (a[i] < pivot) i++; /* a[i] >= pivot となる位置を検索 */
            while (pivot < a[j]) j--; /* a[j] <= pivot となる位置を検索 */
            if (i >= j) break;
            tmp = a[i]; a[i] = a[j]; a[j] = tmp; /* a[i],a[j] を交換 */
            tmp = b[i]; b[i] = b[j]; b[j] = tmp;
            i++; j--;
        }
        quicksort(a,b, left, i - 1);  /* 分割した左を再帰的にソート */
        quicksort(a,b, j + 1, right); /* 分割した右を再帰的にソート */
    }
}


int main(){
  int N,X[200000],B[200000],A[200000];

  scanf("%d",&N);

  for(int i=0;i<N;i++){
    scanf("%d", &X[i]);
    B[i]=i;
  }

  quicksort(X,B,0,N-1);

  for(int i=0;i<N;i++){
    if(i<N/2)
      A[B[i]]=1;
    else
      A[B[i]]=-1;
  }
  for(int i=0;i<N;i++){
    if(A[i]==1)
      printf("%d\n",X[N/2]);
    else
      printf("%d\n",X[N/2-1]);
  }
  return 0;
}


Measured memory_bytes: 4480
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <algorithm>
using namespace std;

typedef long long ll;

int a[1000000];

int main()
{
    int n, k;
    while(cin >> n >> k && n && k) {
        for(int i = 0; i < n; i++) {
            cin >> a[i];
        }
        
        ll pre = 0;
        for(int i = 0; i < k; i++) {
            pre += a[i];
        }
        
        ll ret = pre;
        for(int i = 0; i < n - k; i++) {
            pre = pre - a[i] + a[k + i];
            ret = max(ret, pre);
        }
        
        cout << ret << endl;
    }
}

Measured memory_bytes: 1208
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

void solve(long long N, long long A){
    if (N % 500 <= A) cout << YES << '\n';
    else cout << NO << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    solve(N, A);
    return 0;
}


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

const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<double> a(n);
	rep(i,n) cin >> a.at(i);
	sort(a.begin(), a.end());
	double ans = a.at(0);
	for(int i = 1; i < n; i++){
		ans = (ans + a.at(i))/2;
	}
	cout << ans << endl;
} 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] row = new int[n];
		for(int i = 0; i < n; i++) {
			row[sc.nextInt() - 1] = i + 1;
		}
		for(int i = 0; i < n; i++) {
			if(i != 0) {
				System.out.print(" ");
			}
			System.out.print(row[i]);
		}

	}

}

Measured memory_bytes: 59248
#include<bits/stdc++.h>
#define title "title"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed<<setprecision(x)
#define pii pair<int,int>
#define vint vector<int>
#define pb push_back
using namespace std;
void Freopen(){
	freopen(title".in","r",stdin);
	freopen(title".out","w",stdout);
}
int read(){
	int g=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){g=g*10+ch-'0';ch=getchar();}
	return g*f;
}
int n,c,l[10],cnt;
ll f[305][65],res;
signed main(){
	n=read(),c=read()*n;
	for(int i=0;i<n;i++)l[i]=read()*n;
	sort(l,l+n);
	while(true){
		memset(f,0,sizeof(f));
		f[l[n-1]][0]=1;
		for(int i=1;i<=c;i++){
			int pos=i%n-1;
			if(pos<0)continue;
			for(int j=i;j<=c;j++)for(int sta=0;sta<(1<<n-1);sta++){
				if(~sta>>pos&1)f[min(c,max(j,i+l[pos]))][sta|(1<<pos)]+=f[j][sta];
			}
		}res+=f[c][(1<<n-1)-1],cnt++;
		if(!next_permutation(l,l+n-1))break;
	}return cout<<fix(13)<<1.*res/cnt/pow(c/n,n-1),signed();
} 

Measured memory_bytes: 4436
#include <iostream>

std::string table = "  kstnhmyr", table2 = "aiueo", table3 = "TLURD";

int main(){
    std::string S, T = "";
    std::cin >> S;
    for(int i=0;i<S.size();i+=2){
        if(S[i] == '0'){
            if(S[i+1] == 'T'){T += "wa";}
            else if(S[i+1] == 'D'){T += "wo";}
            else{T += "nn";}
        }else if(S[i] == '1'){
            T += table2[table3.find(S[i+1])];
        }else{
            T += table[S[i]-'0'];
            T += table2[table3.find(S[i+1])];
        }
    }

    std::cout << T << std::endl;
}

Measured memory_bytes: 1196
// Ivan Carvalho
// Problem Y - Educational Dynamic Programming Contest - AtCoder
#include <bits/stdc++.h>
using namespace std;

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

const int MAXN = 2*1e5 + 10;
const int MAXK = 3010;
const int MOD = 1e9 + 7;

vector<ii> pontos;
ll fatorial[MAXN],invfatorial[MAXN],qnts[MAXK];
int H,W,N;

ll fast_expo(ll x,int y){
	if(y == 0) return 1;
	if(y & 1) return (x*fast_expo(x,y-1)) % MOD;
	ll temp = fast_expo(x,y/2);
	return (temp*temp) % MOD;
}

ll binomial(ll n,ll k){
	return ((fatorial[n]*invfatorial[k] % MOD)*invfatorial[n - k]) % MOD;
}

int main(){

	fatorial[0] = invfatorial[0] = 1;
	for(int i = 1;i<MAXN;i++){
		fatorial[i] = (fatorial[i-1]*i) % MOD;
		invfatorial[i] = fast_expo(fatorial[i],MOD - 2);
	}

	cin >> H >> W >> N;
	pontos.push_back(ii(H,W));

	for(int i = 0;i<N;i++){
		int x,y;
		cin >> x >> y;
		pontos.push_back(ii(x,y));
	}

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

	for(int i = 0;i<=N;i++){
		qnts[i] = binomial(pontos[i].first + pontos[i].second - 2, pontos[i].first - 1 );
	}

	for(int i = 0;i<N;i++){
		for(int j = i+1;j<=N;j++){
			int deltax = pontos[j].first - pontos[i].first;
			int deltay = pontos[j].second - pontos[i].second;
			if(deltax < 0 || deltay < 0) continue;
			qnts[j] -= binomial(deltax+deltay,deltay)*qnts[i];
			qnts[j] %= MOD;
		}
	}

	if(qnts[N] < 0) qnts[N] += MOD;
	cout << qnts[N] << endl;

	return 0;

}

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

int linearSearch(int A[], int n, int key){
    A[n] = key;
    int i = 0;
    while (A[i] != key) i++;
    
    return i != n;
}

int main(){
    int n, a[10010];
    int q, key;
    int sum = 0;
    cin >> n;
    for (int i=0;i<n;i++) cin >> a[i];
    cin >> q;
    for (int i=0;i<q;i++){
        cin >> key;
        sum += linearSearch(a, n, key);
    }
    
    cout << sum << endl;
}



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

int main(){
  int k;
  cin >> k;
  
  vector<int> vec;
  for(int a = 1; a < k+1; a++){
    for(int b = 1; b < k+1; b++){
      for(int c = 1; c < k+1; c++){
        vec.push_back(__gcd(__gcd(a, b), c));
      }
    }
  }
  
  int ans = 0;
  for(int i = 0; i < vec.size(); i++) ans += vec[i];
  
  cout << ans << endl;
  return 0;
}

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

//#define Fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>PII;
typedef vector<PII>Vll;
typedef vector<pair<int,pair<int,int> > >Vlll;
typedef priority_queue<int>PQL;
typedef map<int,int>MP;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)
const int mod=1e9+7;
const int sze=1e5+2;
signed main(){
   int a,b,h;
   cin>>a>>b>>h;
   cout<<(double((a+b)*h))/2;
  return 0;
}


Measured memory_bytes: 256
int main(void) {
	int n, x, i, j, k, count, sum = 0;
	count = 0;
	while (1) {

		scanf("%d %d", &n, &x);

		if (n == 0 && x == 0) break;

		for (i = 1; i <= n; i++) {
			for (j = i + 1; j <= n; j++) {
				for (k = j + 1; k <= n; k++) {
					sum = i + j + k;
					if (sum == x) {
						count++;
					}
				}
			}
		}
		printf("%d\n", count);
		count = 0;
	}
	return 0;
}

Measured memory_bytes: 1812
import java.util.*;
public class Main{
	public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int[] N = new int[4];
		N[0] = scan.nextInt();
		N[1] = scan.nextInt();
        N[2] = scan.nextInt();
        N[3] = scan.nextInt();
        Arrays.sort(N);
        if(N[0]==1 && N[1]==4 && N[2]==7 && N[3]==9){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
	}
}

Measured memory_bytes: 21460
#include <iostream>
using namespace std;
int main(){
    int a,b;
    char x;
   while( cin>>a>>x>>b){;
    if(x=='+')cout<<a+b<<endl;
    if(x=='-')cout<<a-b<<endl;
    if(x=='*')cout<<a*b<<endl;
    if(x=='/')cout<<a/b<<endl;
    if(x=='?') break;
}
    return 0;
}

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

int main()
{
    int N, D;
    cin >> N >> D;
    vector<int> X(N), Y(N);
    for (int i = 0; i < N; i++)
    {
        cin >> X.at(i) >> Y.at(i);
    }
    int count = 0;
    for (int i = 0; i < N; i++)
    {
        if (pow(X.at(i), 2) + pow(Y.at(i), 2) <= pow(D, 2))
        {
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 4840
while True:
    n=input()
    if n==0:break
    d={}
    for i in range(n):
        c1,m1,s1,m2,s2,m3,s3,m4,s4=map(int,raw_input().split())
        d[(m1+m2+m3+m4)*60+(s1+s2+s3+s4)]=c1
    t=sorted(d)
    for i in t[:2]:
        print d[i]
    print d[t[-2]]

Measured memory_bytes: 4676
#include <bits/stdc++.h>
using namespace std;
long long n;
int a[99];
int b[99];
int c[99];
void nhap()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
        cin>>b[i];
    for(int i=0;i<n;i++)
        c[i]=a[i+1];
    sort(c,c+n);
}
void xuli()
{
    int d=0;
    int tam1=0;
    int tam2=0;
    do
    {
        bool TF=true;
        for(int i=0;i<n;i++)
            if(c[i]!=a[i+1])
                TF=false;
        if(TF==true)
        {
            tam1=d;
            break;
        }
        d++;
    }while(next_permutation(c,c+n));
    sort(c,c+n);
    d=0;
    do
    {
        bool TF=true;
        for(int i=0;i<n;i++)
            if(c[i]!=b[i+1])
                TF=false;
        if(TF==true)
        {
            tam2=d;
            break;
        }
        d++;
    }while(next_permutation(c,c+n));
    cout<<abs(tam1-tam2);
}
int main()
{
    nhap();
    xuli();
    return 0;
}


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

int main() {
 int A,B ;
  cin >> A >> B;
  
  if(A == 3 && B == 1){
  	cout << "2" << endl;
  }else if(A == 1 && B == 3){
  	cout << "2" << endl;
  }else if(A == 1 && B == 2){
  	cout << "3" << endl;
  }else if(A == 2 && B == 1){
  	cout << "3" << endl;
  }else if(A == 2 && B == 3){
  	cout << "1" << endl;
  }else if(A == 3 && B == 2){
  	cout << "1" << endl;
  }
}




Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author izban
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;

#ifdef HOME
#define db(x) { cerr << #x << " = " << x << endl; }
#define db2(x, y) { cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl; }
#define db3(x, y, z) { cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")" << endl; }
#define dbv(a) { cerr << #a << " = "; for (auto xxx: a) cerr << xxx  << " "; cerr << endl; }
#else
#define db(x) ;
#define db3(x, y, z) ;
#define db2(x, y) ;
#define dbv(a) ;
#endif

#define sz(a)  (int)(a).size()
#define all(a) (a).begin(),a.end()
#define pw(x)  (1LL << (x))


const int INF = 1e9;

class E {
public:
    void solve(std::istream &in, std::ostream &out) {
        ios_base::sync_with_stdio(0);
        in.tie(0);

        int n;
        string s;
        in >> n >> s;
        vector<vector<int>> e(n);
        for (int i = 0; i < n - 1; i++) {
            int u, v;
            in >> u >> v;
            u--;
            v--;
            e[u].push_back(v);
            e[v].push_back(u);
        }

        function<pair<pair<int, int>, int>(int, int, int)> dfs = [&](int v, int pr, int ch) {
            pair<pair<int, int>, int> res;
            if (s[v] == '1') {
                res.second++;
            }

            vector<pair<int, int>> vct;
            for (int to : e[v]) {
                if (to == pr) continue;
                auto o = dfs(to, v, ch + 1);
                o.first.first += o.second;
                o.first.second += o.second;
                vct.push_back(o.first);
                res.first.second += o.first.second;
                res.second += o.second;
            }

            if (!vct.empty()) {
                int mx = 0;
                for (int i = 1; i < (int) vct.size(); i++) if (vct[i] > vct[mx]) mx = i;
                swap(vct[0], vct[mx]);

                int oth = 0;
                for (int i = 1; i < (int) vct.size(); i++) oth += vct[i].second;
                if (vct[0].first > oth) {
                    for (int i = 1; i < (int) vct.size(); i++) {
                        vct[0].first -= vct[i].second;
                    }
                    res.first.first = vct[0].first;
                } else {
                    res.first.first = res.first.second % 2;
                }
            }

            return res;
        };

        int ans = INF;
        for (int root = 0; root < n; root++) {
            auto o = dfs(root, -1, 0);
            if (o.first.first == 0 && o.first.second % 2 == 0) {
                ans = min(ans, o.first.second / 2);
            }
        }
        if (ans == INF) ans = -1;
        out << ans << endl;
    }
};


int main() {
    E solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

int N;

const int MAXN = 300000;

vector<int> G[MAXN];
int parent[MAXN], largestParent[MAXN];
vector<int> children[MAXN];

void dfsFindParents(int v, int p) {
	parent[v] = p;
	largestParent[v] = p;
	if (p != -1)
		largestParent[v] = max(largestParent[v], largestParent[p]);
	for (int w : G[v]) {
		if (w == p)
			continue;
		children[v].pb(w);
		dfsFindParents(w, v);
	}
}

int value[MAXN];
stack<int> nextChild;
bool visited[MAXN];

int bound, cntVisitedFirst;

void dfs(int v) {
	cntVisitedFirst++;
	visited[v] = true;
	for (int w : children[v]) {
		if (w > bound)
			break;
		dfs(w);
	}
}

int cntVisitedSecond;
vector<int> processed;

void dfsSecond(int v) {
	if (!visited[v])
		cntVisitedSecond++;
	visited[v] = true;
	processed.pb(v);
	for (int w : children[v]) {
		if (w > bound)
			break;
		dfsSecond(w);
	}
}


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

	cin >> N;
	
	FOR (i, MAXN) {
		G[i].clear();
		children[i].clear();
	}
	
	int a, b;
	FOR (i, N - 1) {
		cin >> a >> b;
		a--;
		b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	
	dfsFindParents(0, -1);
	FOR (i, N)
		sort(all(children[i]));
	
	while (!nextChild.empty())
		nextChild.pop();
	
	value[0] = 0;
	SET(visited, 0);
	visited[0] = true;
	for (int w : children[0])
		nextChild.push(w);
	while (!nextChild.empty()) {
		int v = nextChild.top();
		nextChild.pop();
		processed.clear();
		bound = largestParent[v];
		cntVisitedFirst = 0;
		dfs(v);
		//cout << "v = " << v << " " << processed.sz << endl;
		
		value[v] = value[parent[v]] + cntVisitedFirst;
		bound = v;
		for (int w : children[v]) {
			if (w < v) {
				processed.clear();
				cntVisitedSecond = 0;
				dfsSecond(w);
				for (int x : processed) {
					value[x] = value[v] + cntVisitedSecond;
					for (int c : children[x]) {
						if (!visited[c]) {
							nextChild.push(c);
						}	
					}
				}
			}
			else
				nextChild.push(w);
		}
	}
	
	ffor (i, 1, N) {
		cout << value[i] << " ";
/*		if (value[i] == 0) {
			cout << "Bad for i = " << i << endl;
			break;
		}*/
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 45044
#include <bits/stdc++.h>
using namespace std;
int main () {
// input
int N , M , C ;
cin >> N >> M >> C ;
vector <int > B ( M );
for ( int i = 0; i < M ; ++i ) {
cin >> B [ i ];
}
vector < vector <int >> A (N , vector <int >( M ));
for ( int i = 0; i < N ; ++i ) {
for ( int j = 0; j < M ; ++j ) {
cin >> A [ i ][ j ];
}
}
// compute
int ans = 0;
for ( int i = 0; i < N ; ++i ) {
// check whether i-th source code solves this problem
int sum = 0;
for ( int j = 0; j < M ; ++j ) {
sum += A [ i ][ j ] * B [ j ];
}
if ( sum + C > 0) {
++ans;
}
}
// output
cout << ans << endl;
}

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

int main()
{
	long long int X,Y,count=1;
	scanf("%lld %lld",&X,&Y);
	while(X*2<=Y) {
		count++;
		X*=2;
	}
	printf("%lld\n",count);
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, K;
    cin >> N >> K;
    cout << N - K + 1 << endl;
    return 0;
}


Measured memory_bytes: 3588
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

int main()
{
	int a, b, i, n, s;

	while(scanf("%d%d%d", &a, &b, &n) != EOF){

		s = 0;

		for(i=0; i<n; i++){
			a = a % b;
			a = a * 10;
			s += a / b;
		}

		printf("%d\n", s);

	}
	return 0;
}

Measured memory_bytes: 596
import sys

X, N = map(int,input().split())
P = []
if N != 0:
  P = list(map(int,input().split()))

table = [True]*102

for i in range(N):
  table[P[i]] = False

ans = 1e18
dif = 1e18

for i in range(0,102):
  if table[i] == False:
    continue
  elif abs(i-X) > dif:
    continue
  elif abs(i-X) == dif:
    if i < ans:
      ans = i
      dif = abs(i-X)
  else:
    ans = i
    dif = abs(i-X)

print(ans)

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

typedef long long ll;

ll mod = 1000000007;

int main(){
    string s, t;
    cin >> s >> t;
    int correct = 0;
    for(int i=0; i<3; i++){
        if(s[i] == t[i]) correct++;
    }
    cout << correct << endl;
}

Measured memory_bytes: 256
N=int(input())
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))

import itertools
for i,A in enumerate(itertools.permutations( [i for i in range(1,N+1)] )):
  if A==P:
    a=i+1
  if A==Q:
    b=i+1
print(abs(b-a))

Measured memory_bytes: 39792