akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

const int N = 100010;
vector<pi> X[N],Y[N];

vector<int> G[N];

int main(){
    int n;
    cin >>n;

    vector<pi> p(n);
    rep(i,n){
        int x,y;
        cin >>x >>y;
        X[x].pb({y,i});
        Y[y].pb({x,i});

        p[i] = {x,y};
    }

    rep(i,N){
        int sz;

        sort(all(X[i]));
        sz = X[i].size();
        rep(j,sz-1){
            int u = X[i][j].se, v = X[i][j+1].se;
            G[u].pb(v);
            G[v].pb(u);
        }

        sort(all(Y[i]));
        sz = Y[i].size();
        rep(j,sz-1){
            int u = Y[i][j].se, v = Y[i][j+1].se;
            G[u].pb(v);
            G[v].pb(u);
        }
    }

    ll ans = 0;
    vector<bool> vis(n);
    rep(i,n)if(!vis[i]){
        vis[i] = true;
        queue<int> que({i});
        vector<int> cc({i});
        while(!que.empty()){
            int v = que.front();
            que.pop();
            for(int e:G[v])if(!vis[e]){
                que.push(e);
                vis[e] = true;
                cc.pb(e);
            }
        }

        set<int> ux,uy;
        for(int idx:cc){
            ux.insert(p[idx].fi);
            uy.insert(p[idx].se);
        }

        ll sx = ux.size(), sy = uy.size();
        int C = cc.size();
        ans += sx*sy - C;
    }

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 19832
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include<queue>
#include<map>
using namespace std;
int main() {
	int N, M;
	cin >> N;
	vector<int> vec(N);
	int Y = N;

	for (int i = 0; i < N; i++) {
		cin>>vec.at(i);
	}
	sort(vec.begin(), vec.end());
	int R = 1;
	for (int i = 0; i < N-1; i++) {

		if (vec.at(i) == vec.at(i + 1)) {
			R++;
		}
		else {
			if (R % 2 == 0) {
				Y -= R;
				R = 1;
			}
			else if (R != 1&&R%2!=0) {
				Y -= R - 1;
				 R = 1;
			}
		}
		
	}

	if (R % 2 == 0) {
		Y -= R;
		int R = 1;
	}
	else if (R != 1 && R % 2 != 0) {
		Y -= R - 1;
	}

	cout << Y << endl;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(void){


int n,a,b,c,i;


long d=0;


b=-1000000;


c=1000000;


scanf("%d",&n);


for(a=0;a<n;a++){


scanf("%d",&i);


if(b<i){


b=i;


}


if(c>i){


c=i;


}


d+=i;


}


printf("%d %d %ld\n",c,b,d);


return 0;


}

Measured memory_bytes: 600
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	cin >> N >> K;
	vector<vector<int>>tapi(60, vector<int>(N));
	for (int i = 0; i < N; i++) {
		cin >> tapi[0][i];
		tapi[0][i]--;
	}
	for (int i = 1; i < 60; i++) {
		for (int j = 0; j < N; j++) {
			tapi[i][j] = tapi[i - 1][tapi[i - 1][j]];
		}
	}
	int ans = 0;
	for (int i = 0; i < 60; i++) {
		if ((K >> i) & 1) {
			ans = tapi[i][ans];
		}
	}
	cout << ans + 1 << endl;
}

Measured memory_bytes: 50980
//This is getting accepted!
#include<bits/stdc++.h>
#define ll long long
#define oo 1000000009
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define INARR(a,n) for (int i = 1; i <= (n); ++i) cin >> a[i];
#define ITE(x) for(auto it = (x).begin(); it != (x).end(); ++it)
#define isset(x, i) (((x)>>(i))&1)
#define setbit(x, i) ((x)^(1ll<<(i)))
#define clearbit(x, i) ((x)&(~(1ll<<(i))))
#define twoexp(i) (1ll<<(i))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define FI first
#define SE second
#define son1 (id*2)
#define son2 (id*2+1)

using namespace std;

const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = 2 * acos(0);
const int MAXN = 1e6 + 6;

int n;
int a[MAXN];
int max1, max2;

void input() {
	int u, v, w, x, y, qtype;
	
	cin >> n;
	INARR(a, n);
	
}


void preprocess() {
	
	if (a[0] > a[1])
		max1 = 0, max2 = 1;
	else
		max1 = 1, max2 = 0;
	
	FOR(i, 2, n) {
		if (a[i] > a[max1]) {
			max2 = max1, max1 = i;
		}
		else if (a[i] > a[max2])
			max2 = i;
	}
	
}

void process(int itest) {
	int u, v, w, x, y, qtype;
	
	FOR(i, 1, n)
		if (i == max1)
			cout << a[max2] << "\n";
		else
			cout << a[max1] << "\n";
	
}

void oneTest() {
	
	input();
	preprocess();
	process(0);
	
}

void multiTest() {
	
	int t;
	cin >> t;
	
	for (int it = 1; it <= t; ++it) {
		input();
		preprocess();
		process(it);
	}
}

int main(){
    #ifndef ONLINE_JUDGE
//    freopen("../out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	oneTest();
//	multiTest();

    return 0;

}


Measured memory_bytes: 2432
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
#include<set>
using namespace std;
#define ll long long int
#define all(v) begin(v), end(v)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
//typedef vector<int> V;
//typedef vector<V> VV;
//typedef vector<VV> VVV;
using namespace std;

ll map1[2003][2003], map2[2003][2003];
int main() {
	ll h,w;
	string s[2005];
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < w; i++) {
		int x = 0;
		for (int j = 0; j < h; j++) {
			if (s[j][i] == '#') {
				if(j-1>=0)map1[j-1][i] = x;
				x = 0;
			}
			else {
				x++;
			}
		}
		map1[h-1][i] = x;
	}
	for (int i = 0; i < h; i++) {
		int x = 0;
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '#') {
				if (j - 1 >= 0)map2[i][j-1] = x;
				x = 0;
			}
			else {
				x++;
			}
		}
		map2[i][w - 1] = x;
	}
	//aaaaaaaaa
	for (int i = 0; i < w; i++) {
		int x = 0;
		for (int j = h - 1; j >= 0; j--) {
			if (map1[j][i] != 0)x = map1[j][i];

			if (s[j][i] != '#') {
				map1[j][i] = x;
			}
			else {
				x = 0;
			}
		}
	}
	for (int i = 0; i < h; i++) {
		int x = 0;
		for (int j = w - 1; j >= 0; j--) {
			if (map2[i][j] != 0)x = map2[i][j];

			if (s[i][j] != '#') {
				map2[i][j] = x;
			}
			else {
				x = 0;
			}
		}
	}
	ll sum = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			sum = max(sum, map1[i][j] + map2[i][j]);
		}
	}
	cout << sum -1<< endl;


	return 0;
}

Measured memory_bytes: 66944
#include<bits/stdc++.h>
#include <numeric>
#define rep(i,N) for(ll i=0; i<N; i++)
using namespace std;
using ll = long long;
ll gcd( ll C, ll D){
  	ll a = C; ll b = D;
	while(a % b != 0){
      	ll tmp = a;
      	a = b;
      	b = tmp % b;
    }
  	return b;
}

ll lcm( ll C, ll D){
	return (C*D) / gcd(C,D);
}

int main(){
    ll A, B, C, D; cin >> A >> B >> C >> D;
  	ll c = ( C*(B/C) - C*((A+C-1)/C) ) / C + 1;
  	ll d = ( D*(B/D) - D*((A+D-1)/D) ) / D + 1;
	ll l = lcm(C,D);
  	ll cd = ( l*(B/l) - l*((A+l-1)/l) ) / l + 1;
  	
    cout << B - A + 1 - c - d + cd << endl;
} 


Measured memory_bytes: 256
"""
桁DPで解ける
dp[i][j][k][l] => i桁目まで見る。i桁目がjであるような数字の数。kは0でない数の個数のメモ。lは未満フラグ。
"""
N = input()
K = int(input())
dp = [[[[0]*(2) for _ in range(5)]for _ in range(10)]for _ in range(len(N))]

#初期化
x = int(N[0])
for i in range(x+1):
    if i == 0:
        dp[0][i][0][1] += 1
    else:
        if i<x:
            flag = 1
        else:
            flag = 0
        dp[0][i][1][flag] += 1

for i in range(len(N)-1):
    x = int(N[i+1])
    for j in range(10):
        for k in range(4):
            for l in range(2):
                if l:
                    r = 10
                else:
                    r = x+1
                for m in range(r):
                    if l==0 and m==x:
                        flag = 0
                    else:
                        flag = 1
                    
                    if m == 0:
                        cnt = k
                    else:
                        cnt = k+1
                    dp[i+1][m][cnt][flag] += dp[i][j][k][l]

ans = 0
for j in range(10):
    ans += sum(dp[-1][j][K])

print(ans)

Measured memory_bytes: 74776
N = input()

if N[len(N)-1] == '3':
    print("bon")
elif N[len(N)-1] == '0' or N[len(N)-1] == '1' or N[len(N)-1] == '6' or N[len(N)-1] == '8':
    print("pon")
else:
    print("hon")

Measured memory_bytes: 9116
#include<bits/stdc++.h>
using namespace std;
string a;
int main()
{
    cin>>a;
    cout<<a[0]<<a[1]<<a[2]<<'8'<<a[4]<<a[5]<<a[6]<<a[7]<<a[8]<<a[9]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int H, W;
    
    while(cin >> H >> W){
        if(W==0 and H==0) break;
        
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                
                if((i + j) % 2 == 0){
                    cout << '#';
                }else{
                    cout << '.';
                }
                
            }
            cout << endl;
        }
        cout << endl;
    }
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
typedef long long ll;
int a,b,c;
ll k;
int main(){
	a=read();b=read();c=read();
	scanf("%lld",&k);
	if(k&1) printf("%d",b-a);
	else printf("%d",a-b);
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
const int INF = 100000000;

int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<char>> A(H, vector<char>(W));
    for (int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> A.at(i).at(j);
        }
    }
   
    vector<vector<int>> d(H, vector<int>(W, INF));
    queue<P> que;
    for (int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if (A.at(i).at(j) == '#'){
                que.push(P(i, j));
                d.at(i).at(j) = 0;
            }
        }
    }
                
    
    vector<int> dy = {1, 0, -1, 0};
    vector<int> dx = {0, 1, 0, -1};
    while (que.size()){
         P p = que.front();
         que.pop();
         //cout << p.second << " " << p.first << " " << d.at(p.first).at(p.second) <<endl;
         
         for (int i = 0; i < 4; i ++){
             int ny = p.first + dy.at(i);
             int nx = p.second + dx.at(i);
             if (ny >= 0 && ny < H && nx >= 0 && nx < W && d.at(ny).at(nx) == INF && A.at(ny).at(nx) == '.'){
                que.push(P(ny, nx));
                d.at(ny).at(nx) = d.at(p.first).at(p.second) + 1;
             }
         }
     }
    
    int ans = -1;
    for (int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
           // cout << "ans_bfs" << d.at(i).at(j) << endl;
            if (ans < d.at(i).at(j)){
                ans = d.at(i).at(j);
            }
        }
    }
    
    cout << ans << endl;
}


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

int main() {
	int len;
	cin>>len;
	int arr[len];
	//int copy[len];
	for(int i=0;i<len;i++){
		cin>>arr[i];
		//cout<<arr[i]<<" ";
		//cin>>copy[i];
	}
	//cout<<endl;
	int m;
	cin>>m;
	//cout<<m<<endl;
	for(int j=0;j<m;j++){
		int total =0;
		int p,x;
		cin>>p>>x;
		//cout<<arr[p-1]<<" "<<x<<endl;
		int tmp =arr[p-1];
		arr[p-1] =x;
		for(int a=0;a<len;a++){
			total+=arr[a];
		}
		cout<<total<<endl;
		arr[p-1] =tmp;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){

  int H,N;
  cin >> H >> N;

  int AllA = 0;

  int A[N];
  for(int i = 0;i < N;i++){
    cin >>A[i];
    AllA += A[i];
  }

  if(H <= AllA){
    cout << "Yes";
  }else{
    cout << "No";
  }

  return 0;
}


Measured memory_bytes: 640
n, m = map(int, input().split())
#ab = [list(map(int, input().split()))]
ab = [[] for i in range(n)]
for i in range(m):
    ai, bi = map(int, input().split())
    ai -= 1
    bi -= 1
    ab[ai].append(bi)
    ab[bi].append(ai)
from collections import deque
# g : グラフ
# 例 [[1], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8]]
# i : 始点
def bfs(g, i, N):
    
    #各頂点への距離
    dis = [float('Inf')] * N 
    route = [0] * N
    #訪れたかどうか
    d = [False] * N
    #初期設定
    que = deque()
    que.append(i)
    d[i] = True
    dis[i] = 0
    
    while que:
        p = que.popleft()
        for k in g[p]:
            if d[k]:
                continue
            else:
                d[k] = True
                que.append(k)
                dis[k] = dis[p] + 1
                route[k] = p

    return dis, route
dis, route = bfs(ab, 0, n)
for i in range(n):
    if i == 0:
        continue
    if dis[i] == 0:
        print('No')
        #quit()
print('Yes')
for i in range(1, n):
    print(route[i] + 1)

Measured memory_bytes: 35412
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int n,m,x,y;
  cin>>n>>m>>x>>y;
  vector<long long int> hoge(n);
  for(long long int i=0; i<n; i++){
    cin>>hoge.at(i);
  }
  vector<long long int> huga(m);
  for(long long int i=0; i<m; i++){
    cin>>huga.at(i);
  }
  sort(hoge.begin(),hoge.end());
  sort(huga.begin(),huga.end());
  long long int rightx=hoge.at(n-1);
  long long int lefty=huga.at(0);
  if(rightx<lefty&&rightx<y&&x<lefty){
    cout<<"No War"<<endl;
  }else{
    cout<<"War"<<endl;
  }
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
#define per(i,n) for ((i)=n;(i)>=(1);(i)--)
using namespace std;
const int mod=998244353;
int n,m,fac[1000005],inv[1000005],fiv[5000005],ans;
int c(int x,int y)
{
	return 1ll*fac[x]*fiv[y]%mod*fiv[x-y]%mod;
}
int pw(int x,int y)
{
	int z=1;
	while(y)
	{
		if(y&1)
		{
			z=1ll*z*x%mod;
		}
		y/=2;
		x=1ll*x*x%mod;
	}
	return z;
}
int main()
{
	int i;
	fac[0]=fac[1]=inv[0]=inv[1]=fiv[0]=fiv[1]=1;
	for(i=2;i<=1000000;i++)
	{
		fac[i]=1ll*fac[i-1]*i%mod;
		inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
		fiv[i]=1ll*fiv[i-1]*inv[i]%mod;
	}
	scanf("%d%d",&n,&m);
	if(n<m) swap(n,m);
	rep(i,m)
	{
		ans=(ans+1ll*c(i+i,i)%mod*c(n+m-i-i,n-i))%mod;
	}
	printf("%d\n",(n+1ll*ans*pw(2ll*c(n+m,n)%mod,mod-2))%mod);
	return 0;
}

Measured memory_bytes: 13312
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
#include<bitset>
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
#define _GLIBCXX_DEBUG

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> v1(n);
	rep(i, n) {
		cin >> v1[i];
	}
	int min = v1[0];
	int count = 0;
	for (int i = 1; i < n; i++) {
		if (min >= v1[i - 1]) {
			min = v1[i - 1];
		}
		if (v1[i] <= min) {
			count++;
		}
	}
	cout << count+1 << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

int main(){
    int h,w; cin >> h >> w;
    vector<vector<char>> s(h+2,vector<char> (w+2));
    rep(i,h+2) rep(j,w+2) s[i][j] = 'e';
    for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) cin >> s[i][j];
    
    if(h==1 && w == 1){
        cout << 0 << endl;
        return 0;
    }

    queue<pair<int,int>> que;
    int ANS = 0;
    for(int i=1;i<=h;i++) for(int j=1;j<=w;j++){
        vector<vector<int>> ans(h+2,vector<int> (w+2));
        rep(l,h+2) rep(m,w+2) ans[l][m] = -1;
        for(int l=1;l<=h;l++) for(int m=1;m<=w;m++) ans[l][m] = -3;
        ans[i][j] = 0;
        que.push(make_pair(i,j));
        if(s[i][j] != '#'){
            while(que.size()){
                pair<int,int> p = que.front();
                que.pop();
                rep(k,4){
                    int py = p.first + my4[k];
                    int px = p.second + mx4[k];
                    if(s[py][px] =='.' && ans[py][px] == -3){
                        que.push(make_pair(py,px));
                        ans[py][px] = ans[p.first][p.second] + 1;          //cout << ans[py][px] <<" ";
                    }
                }   
            }                                                               //cout << endl;
            for(int x = 1;x <= h;x++) for(int y = 1;y <= w;y++){
                ANS = max(ANS,ans[x][y]);
            }
        }else{
            que.pop();
        }
    }
    cout << ANS << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define dfor(i,a,b) for(int i=(a);i>=(b);i--)
#define ll long long
#define ull unsigned long long
#define MOD  1000000007
#define MAX  1e9
#define pb   push_back
#define F    first
#define S    second


int main() {
	int a,b;
	cin>>a>>b;
	int c = a - (2*b);
	if(c<=0) cout<<0;
	else cout<<c;
	
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String str = br.readLine();
        Dice d = new Dice(line.split(" "));
        d.roll(str);
        System.out.println(d.getTop());
    }
}
class Dice
{
    int top,bottom,front,back,left,right;
    Dice(String s[]){
        top=Integer.parseInt(s[0]);
        bottom=Integer.parseInt(s[5]);
        front=Integer.parseInt(s[1]);
        left=Integer.parseInt(s[3]);
        right=Integer.parseInt(s[2]);
        back=Integer.parseInt(s[4]);
    }
    void roll(String s) {
        char ord=0;
        for(int i=0;i<s.length();i++) {
            ord=s.charAt(i);
        int tmp;
        switch(ord) {
            case'N':
                tmp=top;
                top=front;
                front=bottom;
                bottom=back;
                back=tmp;
                break;
            case'E':
                tmp=top;
                top=left;
                left=bottom;
                bottom=right;
                right=tmp;
                break;
            case'W':
                tmp=top;
                top=right;
                right=bottom;
                bottom=left;
                left=tmp;
                break;
            case'S':
                tmp=top;
                top=back;
                back=bottom;
                bottom=front;
                front=tmp;
                break;
            default:break;
        }
        }
    }
    public int getTop() {
        return top;
    }
}

Measured memory_bytes: 17096
fn dfs(val: i64, prev: i64, rem: usize, ans: &mut Vec<i64>) {
    if rem == 0 {
        ans.push(val);
        return;
    }
    for d in (prev - 1)..(prev + 2) {
        if 0 <= d && d < 10 {
            dfs(10 * val + d, d, rem - 1, ans);
        }
    }
}

fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let n: usize = s.trim().parse().unwrap();
    let mut ans = vec![];
    for i in 0.. {
        if ans.len() >= n {
            break;
        }
        for s in 1..10 {
            dfs(s, s, i, &mut ans);
        }
    }
    println!("{}", ans[n - 1]);
}

fn main() {
    run();
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
const int mod=1e9+7;

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




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

   
   int k,a,b;
   cin>>k>>a>>b;
   int x=b/k-(a-1)/k;
   if(x>=1)
   {
     cout<<"OK\n";
   }
   else cout<<"NG\n";
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  int l = S.size();
  int ans = 0;
  for(int i=0; i<l/2; i++){
    if(S[i] != S[l-i-1])ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
using namespace std;

int main()
{
    string s;
    cin >> s;
    int sum = 0;
    int count = 0;
    unordered_map <int, int> mp;
    mp[0] = 1;

    int base = 1;
    for(int i = s.length() - 1; i >= 0; i --)
    {
    	sum = (sum + (s[i] - '0') * base) % 2019;
    	base = (base * 10) % 2019;
    	mp[sum] ++;
    }

    for(auto it = mp.begin(); it != mp.end(); it ++)
    {
    	count = count + ((it -> second) * (it -> second - 1)) / 2;
    }
    cout << count << endl;
}


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

int main(){
    int n,k;
    cin>>n>>k;
    ll ans=0;
    ll sum_min=0;
    ll sum_max=0;
    ll mod=pow(10,9)+7;
    rep(i, k-1){
        sum_min+=i;
        sum_max+=n-i;
    }
    for(int i=k-1;i<n+1;i++){
        sum_min+=i;
        sum_max+=n-i;
        ans+=sum_max-sum_min+1;
        ans%=mod;
    }
    cout<<ans<<endl;
}

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

int main() {
	int n;
	cin >> n;
	if (n % 10 == 3) cout << "bon" << endl;
	else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) cout << "pon" << endl;
	else cout << "hon" << endl;
	return 0;
}

Measured memory_bytes: 3632
# coding: utf-8
# Your code here!
from collections import deque

N,M=map(int,input().split())

way=[[] for i in range(N)]

for _ in range(M):
    A,B=map(int,input().split())
    way[A-1].append(B-1)
    way[B-1].append(A-1)

visited=[-1 for i in range(N)]
visited[0]=0
dq=deque([0]) #loc,value

while dq:
    temp=dq.popleft()
    for item in way[temp]:
        if visited[item]==-1:
            visited[item]=temp
            dq.append(item)

if -1 in visited:
    print("No")
else:
    print("Yes")
    for item in visited[1:]:
        print(item+1)


Measured memory_bytes: 35040
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long int
#define mod 1000000007
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
int countWays(int n) 
{ 
    // To store count of such pairs 
    int count = 0; 
  
    // Counting number of pairs 
    // upto sqrt(n) - 1 
    int i;
    for (i = 1; i * i < n; i++) 
        if (n % i == 0) 
            count++; 
    count= 2*count;
    if(i*i==n)
        count++;
    // To return count of pairs 
    return count; 
} 

int main() {
    FIO;
    int n,i;
    cin>>n;
    int count=0;
    for(i=1;i<n;i++){
        count+=countWays(i);
    }
    cout<<count;
    return 0;
}

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

int main() {
    int n,a;
    cin >> n;
    a = n%1000;
    if(a > 0){
        cout << 1000-a << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
using namespace std;
int main(){
int c,d;
  double a,b,e;
cin>>a>>b>>c>>d;
  e=a*b*1000000000/2000000000;
  if(c==a/2&&d==b/2){cout<<e<<" "<<1;}
  else cout<<e<<" "<<0;
}


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

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S>& p) {
	os << '(' << p.first << ',' << p.second << ')';
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

int f(vector<int>& a, int d, int c) {
	int ans = 0, cnt;
	switch (d) {
		case 0:
			ans += c - 1;
			a.emplace_back(0);
			break;

		case 1:
			while (c >= 10) {
				cnt = c / 10;
				ans += cnt * 10;
				c = cnt + c % 10;
			}
			ans += max(0LL, c - 1);
			if (c != 0) a.emplace_back(c);
			break;

		case 2:
			cnt = c / 5;
			c = c % 5;
			ans += f(a, 1, cnt) + cnt * 5;
			ans += max(0LL, c - 1);
			if (c != 0) a.emplace_back(c * 2);
			break;

		case 3:
			while (c >= 4) {
				cnt = c / 4;
				ans += cnt * 4;
				c = cnt + c % 4;
			}
			ans += max(0LL, c - 1);
			if (c != 0) a.emplace_back(c * 3);
			break;

		case 4:
			cnt = c / 3;
			c %= 3;
			ans += f(a, 3, cnt) + cnt * 3;
			ans += max(0LL, c - 1);
			if (c != 0) a.emplace_back(c * 4);
			break;

		case 5:
			cnt = c / 2;
			c %= 2;
			ans += f(a, 1, cnt) + cnt * 2;
			if (c != 0) a.emplace_back(c * 5);
			break;

		case 6:
			cnt = c / 2;
			c %= 2;
			ans += f(a, 3, cnt) + cnt * 2;
			if (c != 0) a.emplace_back(c * 6);
			break;

		case 7:
			cnt = c / 2;
			c %= 2;
			ans += f(a, 5, cnt) + cnt * 2;
			if (c != 0) a.emplace_back(c * 7);
			break;

		case 8:
			cnt = c / 2;
			c %= 2;
			ans += f(a, 7, cnt) + cnt * 2;
			if (c != 0) a.emplace_back(c * 8);
			break;

		case 9:
			while (c >= 2) {
				cnt = c / 2;
				ans += cnt * 2;
				c = c % 2 + cnt;
			}
			if (c != 0) a.emplace_back(c * 9);
			break;
	}
	return ans;
}

signed main() {
	int m;
	cin >> m;

	int ans = 0;
	vector<int> a;
	rep(i, m) {
		int d, c;
		cin >> d >> c;
		ans += f(a, d, c);
	}
	//show(ans) cout << a << endl;

	int cur = a[0];
	range(i, 1, a.size()) {
		ans++;
		cur += a[i];
		if (cur >= 10) {
			ans++;
			cur = cur % 10 + cur / 10;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 6256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define For(i,a,b) for(int (i)=(a); (i)<(b); (i)++)

int fact(int n) {
    if (n == 0) return 1;
    else return n * fact(n-1);
}

void solve30(int n, int s) {
    int cnt = 0;
    vector<int> data = {0,1,2,3,4,5,6,7,8,9};
    int skip = fact(10 - n);
    int i = 0;
    do {
        if (i % skip == 0) if (accumulate(data.begin(), data.begin() + n, 0) == s) {
            cnt++;
        }
        i++;
    }while (next_permutation(data.begin(), data.end()));
    cout << cnt / fact(n) << endl;
}

int main() {
    int n, s;
    while(cin >> n >> s, n + s) {
        solve30(n, s);
    }
    return 0;
}

Measured memory_bytes: 3088
var
 n,m,i,j,ans,t,k:longint;
 a,b,c,d:array[0..70] of longint;
begin
 readln(n,m);
 for i:=1 to n do readln(a[i],b[i]);
 for i:=1 to m do readln(c[i],d[i]);
 for i:=1 to n do
  begin
   ans:=1000000000;
   for j:=1 to m do
    begin
     t:=abs(a[i]-c[j])+abs(b[i]-d[j]);
     if t<ans then begin ans:=t;k:=j; end;
    end;
   writeln(k);
  end;
end.

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**5)


N,M = map(int,raw_input().split(" "))
path = [[] for i in range(N)]
for i in range(M):
    a,b = map(int,raw_input().split(" "))
    a-=1
    b-=1
    path[a].append((b,i))
    path[b].append((a,i))




vmemo = [0 for i in range(N)]
ememo = [1 for i in range(M)]

stk = []

def loop(pos,last_edge):
    global stk,vmemo,ememo
    
    if vmemo[pos]:
        for i in range(len(stk)-1,-1,-1):
            _v,_e = stk[i]
            ememo[_e] = 0
            if _v == pos:
                return pos
    
    vmemo[pos] = 1
    for v,e in path[pos]:
        if e != last_edge:
            stk.append((pos,e))
            _p = loop(v,e)
            stk.pop()
    vmemo[pos] = 0

    return -1



loop(0,-1)

print(ememo.count(1))


Measured memory_bytes: 2696
// In the name of God

#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	k = 2 * k;
	string s;
	cin >> s;
	int ans = 0;
	for(int i = 1; i < n; i++) {
		if(s[i] == s[i - 1]) {
			ans++;
		}
		else if(k) {
			k--;
			ans++;
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 512
import sys

line = sys.stdin.readline()
line = line.split(" ")
inp = []
for i in line:
    inp.append(int(i))
inp.sort()
inp.reverse()
for i in range(len(inp)):
    if i<len(inp)-1:
        print (inp[i], end=" ")
    else:
        print (inp[i])

Measured memory_bytes: 7584
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 3e6 + 5;
ll a[N];
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int a, b;
    cin >> a >> b;
    if(max(a, b) <= 8) cout << "Yay!";
    else cout << ":(";
return 0;
}


Measured memory_bytes: 256
module M = Map.Make (struct type t = int let compare = compare end)

let () =
    let split s =
        let rec loop i cur flag acc =
            if i = String.length s then ( if flag then cur :: acc else acc) else (
                match flag, s.[i] with
                | true,  ' ' -> loop (i + 1) "" false (cur :: acc)
                | false, ' ' -> loop (i + 1) "" false acc
                | true,  v   -> loop (i + 1) (Printf.sprintf "%s%c" cur v) true acc
                | false, v   -> loop (i + 1) (Printf.sprintf "%s%c" cur v) true acc
            )
        in
        List.map int_of_string (List.rev (loop 0 "" false []))
    in
    let check a =
        let rep = Array.length a / 3 in
        let hist = Array.fold_left (fun map v -> M.add v (1 + try M.find v map with _ -> 0) map) M.empty a in
        let cont = Array.of_list (M.fold (fun k v acc -> (k, v) :: acc) hist []) in
        match Array.length cont with
        | 1 -> fst cont.(0) = 0 
        | 2 -> let (k1, v1) = cont.(0) in
               let (k2, v2) = cont.(1) in
               if v1 = rep * 2 && v2 = rep then (
                   k2 = 0
               ) else if v2 = rep * 2 && v1 = rep then (
                   k1 = 0
               ) else false
        | 3 -> let (k1, v1) = cont.(0) in
               let (k2, v2) = cont.(1) in
               let (k3, v3) = cont.(2) in
               v1 = rep && v2 = rep && v3 = rep && k1 lxor k2 lxor k3 = 0
        | _ -> false

    in
    let main () =
        let n = int_of_string (read_line ()) in
        let a = Array.of_list (split (read_line ())) in
        let flag = if n mod 3 = 0 then (
            check a
        ) else Array.fold_left (+) 0 a = 0
        in
        print_endline (if flag then "Yes" else "No")
    in
    main ()

Measured memory_bytes: 17152
# B
n, m, x = map(int, input().split())
a = list(map(int, input().split()))

count_l = 0
count_r = 0
for i in range(m):
    if a[i] < x:
        count_l += 1
    if a[i] > x:
        count_r += 1
print(min(count_l, count_r))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct P {
    int a, b, c, d;
};

int main() {
    int n, m, q;
    cin >> n >> m >> q;

    int A[10];
    vector<P> p(q);
    int r = 0;

    for (auto &[a, b, c, d] : p) {
        cin >> a >> b >> c >> d;
        a--; b--;
    }

    for (A[9] = 0; A[9] <= m - 1; A[9]++) {
        for (A[8] = 0; A[8] <= A[9]; A[8]++) {
            for (A[7] = 0; A[7] <= A[8]; A[7]++) {
                for (A[6] = 0; A[6] <= A[7]; A[6]++) {
                    for (A[5] = 0; A[5] <= A[6]; A[5]++) {
                        for (A[4] = 0; A[4] <= A[5]; A[4]++) {
                            for (A[3] = 0; A[3] <= A[4]; A[3]++) {
                                for (A[2] = 0; A[2] <= A[3]; A[2]++) {
                                    for (A[1] = 0; A[1] <= A[2]; A[1]++) {
                                        for (A[0] = 0; A[0] <= A[1]; A[0]++) {
                                            int s = 0;
                                            for (const auto &[a, b, c, d] : p) {
                                                if (A[b] - A[a] == c) s += d;
                                            }
                                            r = max(r, s);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int main()
{
	ios::sync_with_stdio(false);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	cin>>n;
	int a[n+1],b[n+1],c[n];
	for (int i=1; i<=n; i++)
	{
		cin>>a[i];
	}
	for (int i=1; i<=n; i++)
	{
		cin>>b[i];
	}
	for (int i=1; i<n; i++)
	{
		cin>>c[i];
	}
	int ans=0;
	ans+=b[1];
	for (int i=2; i<=n; i++)
	{
		ans+=b[i];
		if (a[i]==a[i-1]+1)
		{
			ans+=c[a[i-1]];
		}
	}
	cout<<ans;
	return 0;
}


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

int main(void) {
  int v[100];
  int num, n;
  int cnt = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int temp = 0;
  for (int i = 0; i < n; i++){
    for (int j = n - 1; j > i; j--) {
      if(v[j] < v[j - 1]){
        temp = v[j];
        v[j] = v[j - 1];
        v[j - 1] = temp;
        cnt++;
      }
    }
  }

  for (int i = 0; i < n; i++){
    cout << v[i] << (i == n - 1 ? "\n" : " " );
  }
  cout << cnt << endl;
}




Measured memory_bytes: 3092
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    x,y=map(int,input().split())
    for n in range(x+1):
        m=x-n
        if 2*n+4*m==y:
            print("Yes")
            sys.exit()
    print("No")

if __name__=='__main__':
    main()

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, x, y;
int main(){
	scanf("%d%d", &n, &m);
	if(m >= (1<<n)) printf("-1\n");
	else if(m == 0){
		for(i=0; i<=(1<<n)-1; i++){
			printf("%d %d ", i, i);
		}
	}
	else if(n < 2) printf("-1\n");
	else{
		for(i=0; i<=(1<<n)-1; i=++x){
			if((j=i^m) < i) continue;
			for(x=i+1; (y=x^m)<x; x++);
			printf("%d %d %d %d %d %d %d %d ", i, j, x, y, j, i, y, x);
		}
	}
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <math.h>
using namespace std;
int main(){
    long long X,K,D;
    unsigned long long answer = 0;
    int flag = -1;
    cin >> X >> K >> D;
    unsigned long long quo = abs(X)/D;
    while(flag==-1 && K>0){
        if(abs(X)<=D){
            if(K%2==0) answer = abs(X);
            else answer = abs(abs(X)-D);
            flag = 1;
        }else {
            if(quo>=K){
                answer = abs(abs(X)-K*D);
                flag = 1;
            }else {//quo<K
                X = abs(X)%D;
                K = K - quo;
            }
        }
    }

    printf("%llu\n",answer);
    return 0;
}

Measured memory_bytes: 3696
#include "bits/stdc++.h"
using namespace std;
#define int long long 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define vi vector <int>
#define ff first
#define ss second
#define vp vector <pair<int,int>>
#define vpp vector <pair<int,pair<int,int>>>
#define seti set<int>
#define setbit(x) __builtin_popcountll(x)
#define sov(v) accumulate(all(v),0)
#define fs(it,a) for(auto it=a.begin();it!=a.end();it++)
#define pb push_back
#define pob pop_back
#define mp make_pair
#define pqmax priority_queue <int,vector <int>> 
#define pqmin priority_queue <int,vector <int>,greater<int>> 
#define dq deque <int>
#define umi unordered_map<int,int>
#define ums unordered_map<string,int>
#define ps(x,y) fixed << setprecision(y) << x
#define all(x) x.begin(),x.end()
#define f(x,y,z) for(x=y;x<z;x++)
#define si size()
#define ps(x,y) fixed << setprecision(y) << x
#define countdigit(x) floor( log10(x) +1)
#define M 1000000007  
#define PI 3.1415926535
//Use (k%M+m)%m always where k is any no
#define ee "\n"
#define re return 



//Author Rahul Sannigrahi


vector<int> take(int n)
{
    int i,j;
    vi v;
    f(i,0,n)
    {
        cin>>j;
        v.pb(j);
    }
    return v;
}

void show(vector<int>v)
{
    int i;
    for(i=0;i<v.si;i++)
    {
     cout<<v[i]<<" ";   
    }
    cout<<ee;
}

int decode()
{
    int i,j,k,l,n,m;
    cin>>n;
    vi v=take(n);
    vi pes(n);
    pes[v.si-1]=v[v.si-1];
    
    for(i=v.si-2;i>=0;i--)
    {
        pes[i]=pes[i+1]+v[i];
    }
    //show(pes);
    l=0;
    f(i,0,v.si-1)
    l=(l%M+((v[i]%M)*(pes[i+1]%M)+M))%M;
    cout<<l<<ee;
    re 0;
}
 
int32_t main()
{
    IOS
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    //  freopen("output.txt","w",stdout);
    // #endif 
    int t=1;
    //cin>>t;
    while(t--)
    decode();
    return 0;
}
 













Measured memory_bytes: 6344
#include <iostream>
#include <vector>
#include <math.h>

int main() {
    long long n, d;
    std::cin >> n >> d;

    long long k = n / (2 * d + 1);
    if( (k * (2 * d + 1)) < n ) {
        k += 1;
    }

    std::cout << k;

    return 0;
}


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

int main()
{
	int n;
	cin >> n;

	int ans = n*n*n;

	cout << ans << endl;

	return 0;
}

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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int res = 1e9;
  for(int i = -100; i <= 100; i++)
  {
    int sum = 0;
    rep(j, n) sum += abs(a[j] - i) * abs(a[j] - i);
    res = min(res, sum);
  }
  cout << res << endl;
  return 0;
}

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


int main(){
  int n,m;
  cin >> n >> m;
  vector<string> a(n),b(m);
  for(int i=0;i<n;++i){
    cin >> a[i];
  }
  for(int i=0;i<m;++i){
    cin >> b[i];
  }
  if(n<m){
    cout << "No" << endl;
    return 0;
  }
  for(int i=0;i<n-m+1;++i){
    for(int j=0;j<n-m+1;++j){
      bool ha=true;
      for(int x=0;x<m;++x){
        for(int y=0;y<m;++y){
          if(b[x][y]!=a[x+i][y+j]){
            ha=false;
            break;
          }
        }
      }
      if(ha==true){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

// 疎なグラフ（木など）
struct Graph {
    struct Vertex { int n, v; };
    struct Edge { int i, n; };
    Graph(int n, int m) : v(n, { -1, 0 }), e(m), n(n), m(0) {}
    void add_edge(int i, int j) {
        e[m] = { j, v[i].n };
        v[i].n = m;
        m++;
    }
    void dfs(int i) {
        if (v[i].v) return; else v[i].v = 1;
        for (int j = v[i].n; j >= 0; j = e[j].n) {
            Edge& o = e[j];
            dfs(o.i);
        }
        l.push_back(i);
    }
    int solve() {
        int r = 0;
        for (int i : l) {
            int t = 0;
            for (int j = v[i].n; j >= 0; j = e[j].n) {
                Edge& o = e[j];
                t = max(t, v[o.i].v + 1);
            }
            v[i].v = t;
            r = max(r, t);
        }
        return r;
    }
    vector<Vertex> v;
    vector<Edge> e;
    vector<int> l;
    int n, m;
};

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

    int n, m;
    cin >> n >> m;

    Graph g(n, m);
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;

        g.add_edge(y, x);
    }

    for (int i = 0; i < n; i++) {
        g.dfs(i);
    }

    cout << g.solve() << endl;

    return 0;
}

Measured memory_bytes: 3964
<?php
fscanf(STDIN, "%d", $N);
fscanf(STDIN, "%s", $S);
$a = str_split($S);
$s = array_count_values($a);
$ans = $s['R'] * $s['G'] * $s['B'];
$n = str_replace('R', '1', $S);
$n = str_replace('G', '2', $n);
$n = str_replace('B', '4', $n);
$n = array_map('intval', str_split($n));
for ($i = 0; $i < $N; $i++) {
    for ($j = $i + 2; $j < $N; $j += 2) {
        $mid = ($i + $j) / 2;
        if ($n[$i] + $n[$mid] + $n[$j] === 7) {
            $ans--;
        }
    }
}
printf("%d", $ans);


Measured memory_bytes: 16612
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 505;

int n, k, sum = 0;
int a[N];

int check(int x)
{
	int reqd = 0;
	vector<int> v;
	for(int i = 1; i <= n; i++)
	{
		int cur = a[i] % x;
		v.push_back(cur);
	}
	sort(v.begin(), v.end());
	int l = 0, r = v.size() - 1;
	int rem = 0;
	while(l <= r)
	{
		if(rem <= 0)
		{
			rem += v[l];
			reqd += v[l];
			l++;
		}
		else
		{
			rem -= (x - v[r]);
			reqd += (x - v[r]);
			r--;
		}
	}
	if(reqd > 2 * k)
		return 0;
	if(rem != 0)
		return 0;
	return 1;
}

int32_t main()
{
	IOS;
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	int ans = 1;
	for(int i = 1; i * i <= sum; i++)
	{
		if(sum % i == 0)
		{
			if(check(i))
				ans = max(ans, i);
			if(check(sum / i))
				ans = max(ans, sum / i);
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}

int main(){
    int n=in();
    vector<string> p={"AC","WA","TLE","RE"};
    vec num(4);
    rep(i,n){
        string s=stin();
        rep(j,4)if(p[j]==s)num[j]++;
    }
    rep(i,4){
        cout<<p[i]<<" x "<<num[i]<<endl;
    }
}


Measured memory_bytes: 3696
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())

def eratosthenes(lim):
  is_p=[2]*lim

  is_p[0]=0
  is_p[1]=1

  for i in range(2,lim):
    for j in range(i+i,lim,i):
      is_p[j] +=1
  return is_p

lim=n+1
is_p=eratosthenes(lim)

ans=0
for i in range(1,n+1):
  ans+=i*is_p[i]

print(ans)

Measured memory_bytes: 151876
#include <iostream>
using namespace std;
int main(void) {
	long long n, a, b;
	cin >> n >> a >> b;
	long long ans = (n - 2) * (b - a) + 1;
	if (a > b) ans = 0;
	if (n == 1) {
		if (a == b) ans = 1;
		else ans = 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <numeric>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecvec vector<vec>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}

int cnt2(ll a,int n){
    if(a%2==1)return n;
    return cnt2(a/2,n+1);
}

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

ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}

int main(){
    int n=in(),m=in();
    ll L=1;
    vec a(n);
    int k=-1;
    rep(i,n){
        a[i]=in();
        int x=cnt2(a[i],0);
        if(k==-1)k=x;
        if(k!=x){
            cout<<0<<endl;
            return 0;
        }
        a[i]/=pow(2,k);
        L=lcm(L,a[i]);
        if(L>m){
            cout<<0<<endl;
            return 0;
        }
    }
    cout<<m/(L*(ll)pow(2,k-1))-m/(L*(ll)pow(2,k))<<endl;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if(s < t) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        if(A * B % 2 == 1){
        	System.out.println("Yes");
        } else {
        	System.out.println("No");
        }
        
        sc.close();
        
    }
}


Measured memory_bytes: 22740
import math
a,b,c,d=map(int,input().split())
ans=""
for i in range (c-a):
    ans+="R"
for i in range (d-b):
    ans+="U"
for i in range (c-a):
    ans+="L"
for i in range (d-b):
    ans+="D"
ans+="D"
for i in range (c-a+1):
    ans+="R"
for i in range (d-b+1):
    ans+="U"
ans+="LU"
for i in range (c-a+1):
    ans+="L"
for i in range (d-b+1):
    ans+="D"
ans+="R"
print(ans)

Measured memory_bytes: 9236
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner scan = new Scanner(System.in);
		int X = scan.nextInt();
		int y = 2147483647;
		int z = -2147483648;
		long sum = 0;
		for(int i = 0; i < X; i++){
			int a = scan.nextInt();
			
			y = Math.min(y, a);
			z = Math.max(z, a);
			sum = sum + a;
		}
			System.out.println(y + " " + z + " " + sum);
	}

}

Measured memory_bytes: 41308