akhauriyash/Code-Regression huggingface dataset:
// template version 1.7

// varibable settings {{{
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

#define int long long
#define INF 1e18
// #define INF 2147483647
#define MOD 1e9+7
#define infile "../test/sample-1.in"
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
// }}}

vi vl,vr,vlen;

int connect(int l, int r, int len){
  if (l==r) return 0;
  dump(l, r, len);
  // cout << abs(l-20) << " " << abs(r-20) << " " << len << endl;
  vl.pb(abs(l-20));
  vr.pb(abs(r-20));
  vlen.pb(len);
  return 0;
}

int solve(){
  int L;cin>>L; L--;

  int len = 0;
  bool flag = false;
  rrep(i, 1, 21){
    if (flag) {
      connect(i+1, i, 0);
      connect(i+1, i, pow(2, i));
    }
    if (L>=pow(2, i)){  // 1
      flag=true;
      connect(19, i, len);
      len += pow(2, i);
      L -= pow(2, i);
    }
  }
  connect(1, 0, 0);
  connect(1, 0, 1);
  if (L==1) connect(19, 1, len);
  if (L==0) connect(19, 0, len);

  cout << "20 " << sz(vl) << endl;
  rep(i, sz(vl)){
    cout << vl[i] << " " << vr[i] << " " << vlen[i] << endl;
  }

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main{
    static MyReader in = new MyReader();

    public static void main(String[] args){
        final int N = in.i();
        char[] c = in.s(N);
        int x = 0;
        int y = 0;
        for (int i = 0; i < c.length; i++) {
            if (c[i] == 'R') {
                y++;
            }
        }
        int ans = y;
        for (int i = 0; i < c.length; i++) {
            x += c[i] == 'W' ? 1 : 0;
            y -= c[i] == 'R' ? 1 : 0;
            ans = Math.min(ans, Math.max(x, y));
        }
        out.println(ans);
    }

    static class MyReader extends BufferedReader {
        char[] cbuf = new char[1024];
        int head = 0;
        int tail = 0;

        MyReader() {
            super(new InputStreamReader(System.in));
        }

        char next() {
            if (head == tail) {
                try {
                    tail = read(cbuf, 0, cbuf.length);
                } catch (IOException e) {}
                head = 0;
            }
            return cbuf[head++];
        }

        void back() {
            head--;
        }

        boolean minus() {
            boolean minus;
            while (true) {
                char c = next();
                if (c != ' ' && c != '\n' && c != '\r') {
                    if (!(minus = c == '-')) back();
                    return minus;
                }
            }
        }

        void skip() {
            while (true) {
                char c = next();
                if (c != ' ' && c != '\n' && c != '\r') {
                    back();
                    break;
                }
            }
        }

        char[] s(final int N) {
            skip();
            char[] s = new char[N];
            for (int i = 0; i < s.length; i++) {
                s[i] = next();
            }
            return s;
        }

        int i() {
            boolean minus = minus();
            int n = 0;
            while (true) {
                int k = next() - '0';
                if (k < 0 || 9 < k) break;
                n = 10 * n + k;
            }
            return minus ? -n : n;
        }

        int[] ii(final int N) {
            int[] a = new int[N];
            for (int j = 0; j < a.length; j++) a[j] = i();
            return a;
        }

        long l() {
            boolean minus = minus();
            long n = 0;
            while (true) {
                int k = next() - '0';
                if (k < 0 || 9 < k) break;
                n = 10 * n + k;
            }
            return minus ? -n : n;
        }
    }
}


Measured memory_bytes: 35644
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d,f,g,h,j,i;
	scanf("%d %d %d",&a,&s,&d);
	f=a*100+s*10+d;
	if(f%4==0) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
    int A,B,C;
    scanf("%d %d %d",&A,&B,&C);
    if((A==5&&B==7&&C==5)||(A==5&&B==5&&C==7)||(A==7&&B==5&&C==5))
        printf("YES");
    else
        printf("NO");
}

Measured memory_bytes: 1628
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007
#define INF 1000000000
#define EPS 0.0000000001
typedef long long ll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int x;
    cin>>x;
    if(x==25){
        cout<<"Christmas";
    }
    else if(x==24){
        cout<<"Christmas Eve";
    }
    else if(x==23){
        cout<<"Christmas Eve Eve";
    }
    else{
        cout<<"Christmas Eve Eve Eve";
    }
}

Measured memory_bytes: 256
N=int(input())
a=list(map(int,input().split()))

data=[0 for i in range(N+1)]
ans=0
q=0
for i in range(N):
    q+=(a[i]+1)//(N+1)
    data[(a[i]+1)%(N+1)]+=1
ans=q*(N+1)

for r in range(1,N+1):
    q+=data[N+1-r]-1
    t=max(q,0)*(N+1)+r
    ans=min(ans,t)

print(ans)


Measured memory_bytes: 3064
import sys
read_=sys.stdin.buffer.readline

N=int(read_())
ans_d={}
ans=0
for i in range(N):
    s=''.join(sorted(input()))
    if s in ans_d:
        ans+=ans_d[s]
        ans_d[s]+=1
    else:
        ans_d[s]=1

print(ans)

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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

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

int main()
{
    int w,h;
    while(cin >> w >> h)
    {
        if(w == 0 && h == 0) break;

        vector<string> s(h);
        rep(i,h) cin >> s[i];

        int sy,sx;
        rep(i,h) {
            rep(j,w) {
                if(s[i][j] == '@') {
                    sy = i;
                    sx = j;
                }
            }
        }
        
        int ans = 1;
        bool memo[25][25];
        memset(memo,0,sizeof(memo));

        queue<pair<int,int> > que;
        que.push(make_pair(sy,sx));
        memo[sy][sx] = true;
        
        while(que.size()) {
            pair<int,int> p = que.front();
            que.pop();
            
            rep(i,4) {
                int ny = p.first + dy[i];
                int nx = p.second + dx[i];

                if(0 <= ny && ny < h && 0 <= nx && nx < w) {
                    if(s[ny][nx] == '.' && !memo[ny][nx]) {
                        ans++;
                        memo[ny][nx] = true;
                        que.push(make_pair(ny,nx));
                    }
                }
            }
        }

        cout << ans << endl;
    }

    return 0;
}

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

int main(){
    int N,M;
    cin>>N>>M;
    vector<pair<int,vector<int>>> vec(N);
    for(int i=0;i<N;i++){
        cin>>vec.at(i).first;
        vec.at(i).second.push_back(vec.at(i).first);
    }

    for(int i=0;i<M;i++){
        int A,B;
        cin>>A>>B;
        A--;
        B--;
        vec.at(A).second.push_back(vec.at(B).first);
        vec.at(B).second.push_back(vec.at(A).first);
    }

    int count=0;
    for(int i=0;i<N;i++){
        sort(vec.at(i).second.begin(),vec.at(i).second.end());
    
        if(vec.at(i).second.at(vec.at(i).second.size()-1) == vec.at(i).first ){
            if(vec.at(i).second.size()<2 || vec.at(i).second.at(vec.at(i).second.size()-2) != vec.at(i).first){
                count++;
            }    
            
        }
    }
    cout<<count<<endl;
    
}

Measured memory_bytes: 10124
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const ll MOD = 1e9 +7;




int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    ll ans=0,cnt=0;
    rep(i,s.size()){
        if(s[i]=='W'){
            cnt++;
            ans+=(i+1-cnt);
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

const int maxn=(int)1e5+10;
int dp[maxn];
int t[110];
bool mex[110];

int main()
{
	int n,k;
	scanf("%d %d",&n, &k);
	for(int i=1;i<=n;i++)
		scanf("%d",&t[i]);
	dp[0]=0;
	for(int i=1;i<=k;i++)
	{
		for(int j=1;j<=n;j++)
			if(i-t[j]>=0)
				mex[dp[i-t[j]]]=true;
		for(int j=0;j<=n;j++)
			if(!mex[j])
				{ dp[i]=j; break; }
		for(int j=0;j<=n;j++)
			mex[j]=false;
	}
	(dp[k]) ? printf("First") : printf("Second");
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using i64 = long long;

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

    if (!q) {
        for (int i = 0; i < n; i++) std::cout << "1\n";
        std::cout << std::flush;
        return 0;
    }

    std::vector<i64> v(q);
    for (auto &e : v) std::cin >> e;

    std::vector<i64> w { v.back() };
    for (int i = q - 2; i >= 0; i--) {
        if (w.back() > v[i]) w.push_back(v[i]);
    }

    q = w.size();

    i64 qmin = w.back();
    int lim = std::min((i64)n, w.back());

    for (i64 i = std::min((i64)n, w.back() - 1); i >= 0; i--) {
        w.push_back(i);
    }

    std::reverse(w.begin(), w.end());

    std::vector<i64> cnt(w.size());
    cnt.back() = 1;

    for (int i = 0, len = w.size(); i < q - (qmin <= n ? 1 : 0); i++) {
        int j = len - 1 - i;

        i64 b = cnt[j];
        i64 quo = w[j] / w[j - 1], rem = w[j] % w[j - 1];
        cnt[j - 1] += b * quo;

        while (rem > 0) {
            int to = std::upper_bound(w.begin(), w.end(), rem) - w.begin() - 1;
            cnt[to] += rem / w[to] * b;
            rem %= w[to];
        }
    }

    for (int i = w.size() - q - (qmin <= n ? 0 : 1); i > 0; i--) {
        cnt[i - 1] += cnt[i];
    }

    for (int i = 1; i <= lim; i++) std::cout << cnt[i] << '\n';
    for (int i = lim + 1; i <= n; i++) std::cout << "0\n";
    std::cout << std::flush;

    return 0;
}


Measured memory_bytes: 5744
#include<cstdio>
#include<iostream>
using namespace std;
int n,m,lim;
int f[105][105][305],w[10005],v[10005];
char vis[105][105][305];
int dp(int i,int j,int k)
{
	if (1LL*j*lim+k>m) return -2e9;
	if (i==n) return 0;
	if (vis[i][j][k]) return f[i][j][k];
	vis[i][j][k]=1;
	return f[i][j][k]=max(dp(i+1,j,k),dp(i+1,j+1,k+w[i+1])+v[i+1]);
}
main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i) scanf("%d%d",w+i,v+i);
	lim=w[1];
	
	for (int i=1;i<=n;++i) w[i]-=lim;
	printf("%d\n",dp(0,0,0));
}

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

#define forn(i, n) for(int i = 0; i < (int)n; ++i)

int main()
{
	string s;
	cin >> s;

	map<char, int> mp;

	forn(i, s.size()) ++mp[s[i]];

	bool flag = false;
	for(auto item : mp) {
		if(item.second == 2) {
			flag = true;
			continue;
		}
		else {
			flag = false;
			break;
		}
	}

	if(flag) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}

Measured memory_bytes: 256
// E - League

// queueを用いた解法
// チェック対象を前日に試合があったプレイヤーに限定

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

queue<int> plan[1000];
set<pair<int, int>> games;
set<int> candidates; // 対戦を行う可能性のあるプレイヤー
set<int> next_candidates; // 次の日に対戦を行う可能性のあるプレイヤー

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

	int A;
	for (int i=0; i<N; i++) {
		for (int j=0; j<N-1; j++) {
			cin >> A;
			A--;
			plan[i].push(A);
		}

		candidates.insert(i);
	}

	int day = 0;
	while(!candidates.empty()) {
		day++;
		//cout << "day " << day << endl; // **** debug ****
		for (int a : candidates) {
			int b = plan[a].front();
			int c = plan[b].front();

			//cout << a+1 << "->" << b+1 << " " << b+1 << "->" << c+1 << endl; // **** debug ****

			if (a == c) {
				if (a > b) swap(a, b);
				//cout << "game: " << a+1 << " vs " << b+1 << endl; // **** debug ****
				games.insert(make_pair(a, b));
			}
		}

		for (auto p : games) {
			int a = p.first;
			int b = p.second;
			plan[a].pop();
			plan[b].pop();
			if (!plan[a].empty()) next_candidates.insert(a);
			if (!plan[b].empty()) next_candidates.insert(b);
		}

		games.clear();
		swap(candidates, next_candidates);
		next_candidates.clear();
	}

	bool finish = true;
	for (int i=0; i<N; i++) {
		if (!plan[i].empty()) {
			finish = false;
			break;
		}
	}

	int ans;
	if (finish) {
		ans = day;
	} else {
		ans = -1;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4736
import java.util.Scanner;

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

		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());

		sc.close();


		System.out.println(A - 2 * B >= 0 ? A - 2 * B : 0);

	}
}



Measured memory_bytes: 21844
from itertools import product
H,W,K = list(map(int, input().split()))
mod=int(1e9+7)

memo = [[0]*W for _ in range(H+1)]
memo[0][0]=1
#memo[h][w] = h行目のw列の場合の数

from itertools import product
def one_row(W):
    one_row_amida={i:{i:0 for i in range(W)} for i in range(W)}

    for p in product([0,1], repeat=W-1):
        if any([p[i]==1 and p[i+1]==1 for i in range(W-2)]):
            continue
        after = [i for i in range(W)]
        for i in range(W-1):
            if p[i]:
                after[i], after[i+1] = after[i+1], after[i]
        for i, a in enumerate(after):
            one_row_amida[i][a] += 1
    return one_row_amida

one_row_amida = one_row(W)

for h in range(H):
    for w in range(W):
        for j in range(W):
            memo[h+1][j] += memo[h][w] * one_row_amida[w][j]
    memo[h+1] = [x%mod for x in memo[h+1]]

answer = memo[H][K-1]

print(answer)


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;

int main(void) {
    int n;
    char b[2] = {'Z', 'Z'};
    int blood[4] = {};
    
    while(scanf("%d,%s", &n, b) != EOF) {
        if(b[0] == 'A' && strlen(b) == 1) {
            ++blood[0];
        } else if(b[0] == 'B') {
            ++blood[1];
        } else if(b[0] == 'A' && b[1] == 'B') {
            ++blood[2];
        } else if(b[0] == 'O') {
            ++blood[3];
        }
    }
    
    for(int i = 0; i < 4; ++i) {
        cout << blood[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3144
#include "bits/stdc++.h"
    using namespace std;
    //#define MOD 1000000007
    //#define MOD 998244353
    #define MOD 2019
    const double EPS = 1e-9;
    #define INF (1LL<<60)
    #define D double
    #define fs first
    #define sc second
    #define int long long
    #define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
    #define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
    #define REP(i,n)  FOR(i,0,(n))
    #define RREP(i,n) RFOR(i,0,(n))
    #define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
    #define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
    #define range(i,a,b) ((a)<=(i) && (i)<(b))
    #define debug(x)  cout << #x << " = " << (x) << endl;
    #define SP << " " << 
    typedef pair<int,int> P;
    typedef vector<int> vec;
    typedef vector<vector<int>> mat;
     
    signed main(){
      ios::sync_with_stdio(false);
      cin.tie(0);
      cout.precision(20);
     
      int n = 0;
      cin >> n;
      vector<P> x(n);
      REP(i,n) {
        cin >> x[i].first;
        x[i].second = i;
      }
      
      sort(x.begin(), x.end(),[](P a, P b){
        return a.first < b.first;
      });

      vec b(n);
      REP(i, n){
        if(i <= n / 2 - 1){
          b[x[i].second] = x[n / 2].first;
        }
        else{
          b[x[i].second] = x[n / 2 - 1].first;
        }
      }

      REP(i, b.size()) cout << b[i] << endl;

      return 0;
    }

Measured memory_bytes: 6912
a = gets.to_i
b = gets.to_i
c = gets.to_i
d = gets.to_i
e = gets.to_i
k = gets.to_i

if e-a > k
	puts ':('
	exit
elsif d-a >k
	puts ':('
	exit
elsif c-a > k
	puts ':('
	exit
elsif b-a > k
	puts ':('
	exit
end

if e-b > k
	puts ':('
	exit
elsif d-b > k
	puts ':('
	exit
elsif c-b > k
	puts ':('
	exit
end

if e-c > k
	puts ':('
	exit
elsif d-c > k
	puts ':('
	exit
end

if e-d > k
	puts ':('
	exit
else
	puts 'Yay!'
end


Measured memory_bytes: 1788
n = gets.chomp.to_i
def log9(x)
  i = 0
  while x - 9 ** i >= 0
    i += 1
  end
  i-1
end
def log6(x)
  i = 0
  while x - 6 ** i >= 0
    i += 1
  end
  i-1
end
$dfs_hash = {0 => 0}
def dfs(n)
  return $dfs_hash[n] if $dfs_hash[n]
  pow9 = log9(n)
  pow6 = log6(n)
  return n if pow9 == 0 && pow6 == 0
  if pow9 > 0 && pow6 > 0
    $dfs_hash[n] = [dfs(n-9**pow9),dfs(n-6**pow6)].min + 1
  elsif pow9 > 0
    $dfs_hash[n] = dfs(n-9**pow9) + 1
  else
    $dfs_hash[n] = dfs(n-6**pow6) + 1
  end
end
puts dfs(n)


Measured memory_bytes: 1788
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		long K = stdIn.nextInt();
		int[] A = new int[N];
		for(int i = 0; i < N; i++) {
			A[i] = stdIn.nextInt();
		}
		
		long count1 = 0;
		for(int i = 0; i < N-1; i++) {
			for(int j = i+1; j < N; j++) {
				if(A[i]>A[j]) count1++;
			}
		}
		count1 *= K;
		
		long count2 = 0;
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < N; j++) {
				if(A[i]>A[j]) count2++;
			}
		}
		count2 *= (K*(K-1)/2)%1000000007;
		
		System.out.println((count1%1000000007+count2%1000000007)%1000000007);

	}

}

Measured memory_bytes: 26108
#include <bits/stdc++.h>
#define P pair<long long, long long>

using namespace std;
const int INF=1e5;

int main(){
  int n[5], ref[5]={1,4,7,9};
  for(int i=0;i<4;i++)cin >> n[i];
  sort(n, n+4);
  for(int i=0;i<4;i++){
    if(n[i]!=ref[i]){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mod 1000000007
#define inp(arr,n) for(int i=0;i<n;i++) cin>>arr[i]
#define soa(arr,n) sort(arr,arr+n)
#define sov(arr) sort(arr.begin(),arr.end())
#define fr(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t=1;
    while(t--){
       int n;
       cin>>n;
       ll arr[n];
       inp(arr,n);
       int c=0;
       fr(i,0,n-3){
           fr(j,i+1,n-2){
               fr(k,j+1,n-1){
                   if((arr[i]+arr[j]>arr[k] && abs(arr[i]-arr[j])<arr[k]) && (arr[i]!=arr[j] && arr[j]!=arr[k] && arr[i]!=arr[k])) c++;
               }
           }
       }
       cout<<c<<endl;
    }
    return 0;
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (int) 1e9+7
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define vi vector<int>
ll xpow(ll a, ll b)
{
	if (b == 0)
		return 1;
	if (b % 2 == 0)
	{
		ll k = xpow(a, b / 2);
		return k * k;
	}
	if (b % 2 != 0)
		return a * xpow(a, b - 1);
}
int main()
{

#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out1.txt", "w", stdout);
#endif
	fio;
	ll n;
	cin >> n;
	string res = "";
	while (n != 0) {
		n -= 1;
		int k = n % 26;
		char c;
		c = 'a' + k;
		res += c;
		n /= 26;
	}
	reverse(res.begin(), res.end());
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3620
N, W = map(int, input().split(" "))
#items = [tuple(map(int, input().split(" "))) for _ in range(N)]
dp = [[0]*(W+1) for i in range(N+1)]

for i in range(1, N+1):
    w, v = map(int, input().split(" "))
    for j in range(1, W+1):
        if j >= w:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]+v)
        else:
            dp[i][j] = dp[i-1][j]

print(dp[N][W])

Measured memory_bytes: 120152
#include<bits/stdc++.h>
using namespace std ;
#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )
#define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
#define drep( i, s, t ) for( register int i = (t); i >= (s); -- i )
#define re register
#define int long long
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = ( 1 << 16 ) ;
const int P = 1e9 + 7 ;
const int M = 30 ;
int n, m, a[M][M], Go[M], dp[N], num[N], fac[N] ; 
int lowbit( int x ) {
	return ( x & (-x) ) ;
}
signed main()
{
	n = gi(), m = gi() ; int x, y ; 
	rep( i, 1, m ) x = gi(), y = gi(), a[x][y] = 1, Go[x] = ( Go[x] | ( 1 << ( y - 1 ) ) ) ; 
	int d = 3, maxn = ( 1 << n ) - 1 ; 
	dp[0] = 1 ; 
	rep( i, 1, maxn ) num[i] = num[i ^ lowbit(i)] + 1 ; 
	rep( i, 0, maxn ) {
		if( ( ( i & d ) == 2 ) || ( ( i & d ) == 1 )  ) continue ; 
		for( re int j = i; j <= maxn; j = ( j + 1 ) | i ) {
			int S = ( j ^ i ), ans = 1 ; if( ( ( S & d ) == 2 ) || ( ( S & d ) == 1 )  ) continue ; 
			if( !S ) continue ; 
			rep( k, 1, n ) 
				if( ( 1 << ( k - 1 ) ) & S ) ans = ans * ( 1 << num[i & Go[k]] ) % P ;
				else if( ( 1 << ( k - 1 ) ) & i ) ans = ans * ( ( 1 << num[Go[k] & S] ) - 1 ) % P ;
			dp[j] = ( dp[j] + ans * dp[i] % P ) % P ;
		}
	}
	int Ans = ( 1ll << ( m >> 1 ) ) % P ;
	Ans = Ans * Ans % P, Ans = Ans * ( 1ll << ( m & 1 ) ) % P ;   
	printf("%lld\n", ( Ans - dp[maxn] + P ) % P ) ;
	return 0 ;
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; exit(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1 << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

int main() {
    cin >> n >> k;
    set<char> s;
    REP(i, 0, k) {
        char tmp;
        cin >> tmp;
        s.insert(tmp);
    }
    ll now = n;
    while (true) {
        string str_n = to_string(now);
        bool ok = true;
        REP(j, 0, str_n.size()) {
            if (s.count(str_n[j]) != 0) {
                ok = false;
                break;
            }
        }

        if (ok) {
            END(now)
        }
        now++;
    }
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let n:u32 = read();
    let d:Vec<u32> = (0..n).map(|_| read()).collect();

    let mut ans:u32 = 0;
    for i in (0..n) {
        for j in (i+1..n) {
            let i = i as usize;
            let j = j as usize;
            ans += d[i]*d[j];
        }
    }

    println!("{}", ans);

}


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

typedef long long ll;
typedef vector<long long> vl;
typedef pair<long , long> pll;
typedef vector< pll > vll;
typedef set<ll> sl;
typedef map<string, int> msi;

#define pb push_back
#define mp make_pair
#define f first
#define s second
#define inf 0x3f3f3f3f
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))

const ll md = 1000000007;
//void mod(ll &x){if (x >= md) x -= md; if (x < 0) x += md;}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n,w,i,j;
	cin>>n>>w;
	ll wt[n+1],val[n+1];
	ll dp[n+1][w+1];
	for(i=1;i<=n;i++){
		cin>>wt[i]>>val[i];
	}
	for(i=0;i<=n;i++){
		for(j=0;j<=w;j++){
			if(i==0 || j==0)
				dp[i][j] = 0;
			else if(wt[i]<=j)
				dp[i][j] = max(val[i]+dp[i-1][j-wt[i]],dp[i-1][j]);
			else
				dp[i][j] = dp[i-1][j];
		}
	}
	cout<<dp[n][w];
    return 0;
}




Measured memory_bytes: 79232
#include <iostream>
#include <cstring>

using namespace std;

const int MAX_N = 8;

int h, w, c;
int field[6][MAX_N][MAX_N];
int old;
/*
int field1[MAX_N][MAX_N];
int field2[MAX_N][MAX_N];
int field3[MAX_N][MAX_N];
int field4[MAX_N][MAX_N];
int field5[MAX_N][MAX_N];
*/

void debug(int m) {
	for (int i = 0; i < MAX_N; i++) {
		for (int j = 0; j < MAX_N; j++) {
			cout << field[m][i][j] << " ";
		}
		cout << endl;
	}
	cout << "----------" << endl;
}

void dfs(int x, int y, int n, int m) {
	int dx[4] = {1, 0, -1, 0};
	int dy[4] = {0, 1, 0, -1};
	
	field[m][y][x] = n;
	
	for (int i = 0; i < 4; i++) {
		int nx = x + dx[i];
		int ny = y + dy[i];
		if (0 <= nx && nx < w && 0 <= ny && ny < h && field[m][ny][nx] == old) {
			dfs(nx, ny, n, m);
		}
	}
}

// 左上とつながっているマスをすべて色nに変える, mは回数(1〜5)
void change(int n, int m) {
	memcpy(field[m], field[m-1], sizeof(field[m-1]));
	old = field[m][0][0];
	dfs(0, 0, n, m);
}

int check() {
	int ans = 0;
	old = field[5][0][0];
	dfs(0, 0, -1, 5);
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (field[5][i][j] == -1) {
				ans++;
			}
		}
	}
	
	return ans;
}

void solve() {
	int ans = 0;
	for (int i = 1; i <= 6; i++) {
		if (field[0][0][0] == i) {
			continue;
		}
		change(i, 1);
		for (int j = 1; j <= 6; j++) {
			if (field[1][0][0] == j) {
				continue;
			}
			change(j, 2);
			for (int k = 1; k <= 6; k++) {
				if (field[2][0][0] == k) {
					continue;
				}
				change(k, 3);
				for (int l = 1; l <= 6; l++) {
					if (field[3][0][0] == l || c == l) {
						continue;
					}
					change(l, 4);
					change(c, 5);
					//debug(5);
					ans = max(ans, check());
				}
			}
		}
	}
	cout << ans << endl;
}

int main() {
	while (true) {
		cin >> h >> w >> c;
		
		if (h == 0) {
			break;
		}
		memset(field, 0, sizeof(field));
		
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> field[0][i][j];
			}
		}
		//cout << "初期状態" << endl;
		//debug(0);
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using db = double;
using pll = pair < ll, ll >;
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
#define pb push_back
#define mp make_pair
#define fastIo() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
 
const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
 
int main(){   
	ll x, n; cin >> x >> n;
	ll occur[105] = {0};
	ll a[n];
	for(ll i = 0; i < n; i++) {
		cin >> a[i];
		occur[a[i]] = 1;
	}
	ll ans = INF;
	ll cur = INF;
	for(ll i = 0; i <= 101; i++) {
		if(!occur[i]) {
			if(abs(x - i) < cur) {
				cur = abs(x - i);
				trace(i, cur);
				ans = i;
			}
		}		
	}
	cout << ans << endl;
}
	

Measured memory_bytes: 3628
use std::io;


fn main() {
    let (n, k) = {
        let i = read::<usize>();
        (i[0], i[1])
    };
    let (r, s, p) = {
        let i = read::<usize>();
        (i[0], i[1], i[2])
    };
    let tn = read_one::<String>().chars().collect::<Vec<_>>();
    let mut ans = 0;
    let mut ok = vec![false; n];
    for i in 0..n {
        if i >= k && tn[i - k] == tn[i] {
            if ok[i - k] {
                ok[i] = false;
            } else {
                ok[i] = true;
                continue;
            }
        }
        ans += match tn[i] {
            'r' => p,
            's' => r,
            'p' => s,
            _   => unreachable!()
        };
    }

    println!("{}", ans);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

int main(){
  string S,T;
  cin >> S >> T;
  int64_t ans=1e9;
  for(int i=0;i<S.size()-T.size()+1;i++){
    int64_t count=0;
    for(int j=0;j<T.size();j++){
      if(S.at(i+j)!=T.at(j)){
        count++;
      }
    }
    ans=min(count,ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;


int main()
{
    
    string S;
    cin >> S;
    
    if(S[0] != 'A' || !islower(S[1]) || !islower(S[S.size()-1]))
    {
        cout << "WA" << endl;
        return 0;
    }
    
    int Ccnt = 0;
    for(int i = 2; i <= S.size()-2; i++)
    {
        if(S[i] == 'C')
        {
            Ccnt++;
            if(Ccnt >= 2)
            {
                cout << "WA" << endl;
                return 0;
            }
        }
        else if(!islower(S[i]))
        {
            cout << "WA" << endl;
            return 0;
        }
    }
    if(Ccnt == 1) cout << "AC" << endl;
    else cout << "WA" << endl;
    
    return 0;
}


Measured memory_bytes: 764
#include <iostream>

using namespace std;

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int total = 0;
  for (int i = 1; i <= n; i++) {
    //cout << "-----------" << endl;
    int number = i;
    int sum = 0;
    while(1) {
      int rest = number % 10;
      sum += rest;
      number /= 10;
      //cout << i << "," << sum << "," << rest << "," << number << endl;
      if (number == 0) {
        break;
      }
    }
    if (sum >= a && sum <= b) {
      //cout << "get" << endl;
      total += i;
    }
  }
  cout << total << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

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

int main(){
	ll a,b,c,d;cin>>a>>b>>c>>d;
	ll e=c*d/gcd(c,d);a--;
	ll ans=(b-(b/c+b/d-b/e))-(a-(a/c+a/d-a/e));
	cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  switch(n%10){
    case 1:
      cout << "pon" << endl;
      break;
    case 3:
      cout << "bon" << endl;
      break;
    case 6:
      cout << "pon" << endl;
      break;
    case 8:
      cout << "pon" << endl;
      break;
    case 0:
      cout << "pon" << endl;
      break;
    default:
      cout << "hon" << endl;
      break;
 
  }
}

Measured memory_bytes: 3624
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

int n,x;
int pat[51],total[51];

int eat(int ni, int xi){
    // cerr << ni << " " << xi << endl;
    int ret = 0;
    if (xi >= total[ni]) return pat[ni];
    if (ni == 0) return 0;
    
    if (xi <= 1) return 0;
    if (xi <= 1 + total[ni-1]) return eat(ni-1, xi-1);
    ret += pat[ni-1];
    xi -= 1 + total[ni-1];
    if (xi < 1) return ret;
    ret++;
    xi--;
    return ret + eat(ni-1,xi);
}

signed main(){
    I(n); I(x);
    pat[0] = 1;
    REPS(i,n) pat[i] = pat[i-1]*2 + 1;
    total[0] = 1;
    REPS(i,n) total[i] = total[i-1]*2 + 3;

    cout << eat(n,x) << endl;
}

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

int main(){
  int n,i,S;
  while(cin >> n){
    i = 0;
    for(S=0;S<=9999;S++){
      if((S/1000)+((S-S/1000*1000)/100)+((S-S/100*100)/10)+(S-S/10*10)==n)
	i=i+1;
    }
    cout<<i<<endl;
  }
  return 0;
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Int int32_t
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair< int , int >
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(auto x : c )cout << x << " ";
#define ol(c , s , e ) for(int pos=s; pos<e ; pos++) cout << c[pos] << " ";
#define PI acos(-1l)
const int M = 1000000007;
const int N=3e6+5;
const long long INF = 1e18+5;

//#define rohit
#ifdef rohit
template<typename... T >
void bug(T... __VA_ARGS__) {
    ((cerr << __VA_ARGS__ << " ") , ...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", bug(__VA_ARGS__) , cerr << endl;
#endif

int get(int k){
    double ans = (-1.0 + sqrt(1.0+8.0*k))/2.0;
    return (int)ans;
}
int minPrime[N+1];
void leastPrimeFactor()
{
    for (int i = 2; i * i <= N; ++i)
    {
        if (minPrime[i] == 0)
        { //If i is prime
            for (int j = i * i; j <= N; j += i)
            {
                if (minPrime[j] == 0)
                {
                    minPrime[j] = i;
                }
            }
        }
    }
    for (int i = 2; i <= N; ++i)
    {
        if (minPrime[i] == 0)
        {
            minPrime[i] = i;
        }
    }
}

//**** ALL PRIME FACTORS without repetitions
//**** IT IS IN O(LOG N)
vector<int> getPrimeFactorization(int x)
{

    vector<int> res;
    while (x != 1)
    {
        res.push_back(minPrime[x]);
        x = x / minPrime[x];
    }
    return res;
}
void solve() {
    int n;
    cin >> n;
    if(n==1){
        cout<<0<<endl;
        return;
    }
//    vector< int > v = getPrimeFactorization(n);
//    map< int , int > mp;
//    for(auto x : v){
//        mp[x]++;
//    }
//    int ans  = 0;
//    for(auto x : mp){
//        ans+=get(x.second);
//    }
//    cout << ans << endl;
    map< int, int > mp;
    for (int i = 2; i * i <= n; ++i)
    {
        while (n % i == 0)
        {
            mp[i]++;
            n /= i;
        }
    }
    if (n != 1)
    {
        mp[n]++;
    }
    int ans  = 0;
    for(auto x : mp){
        ans+=get(x.second);
    }
    cout << ans << endl;
}

signed main(){
    FAST;
    //TODO:  check test cases.
    int tc=1;
    leastPrimeFactor();
//    cin >> tc;
    for(int t = 1 ; t <= tc ; t++){
        solve();
    }
}

/*Extra Cares
 * 1)In graphs or dp problems sometimes long long creates MLE.
 * 2)Check whether int to long long typecasting is commented or not?
 * 3)Check overflows.
*/

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

public class Main {

	public static void main(String[] arges) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] k = line.split(" ");
		int[] v = new int[k.length];
		for (int i = 0; i < v.length; i++) {
			v[i] = Integer.parseInt(k[i]);
		}
		Arrays.sort(v);

		System.out.println(v[0] + " " + v[1] + " " + v[2]);
	}
}

Measured memory_bytes: 26120
#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <tuple>

using namespace std;

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int a, b;
    scanf("%d%d", &a, &b);
    printf("%d", (a-1)*(b-1));
    return 0;
}

Measured memory_bytes: 128
//abc162_e.cpp
//Thu May 14 21:30:18 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

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

	ll ans = 0;
	ll comb[k+1];
	fill(comb,comb+k+1,0);
	for (int i=k;i>=1;i--){
		ll baisu = k/i;
		comb[i] = mod_pow(baisu,n);
		for (int j=2;j<=baisu;j++){
			comb[i] = (comb[i]-comb[i*j]+MOD)%MOD;
		}
		ans = (ans + comb[i]*i)%MOD;
	}

	cout << ans << endl;

}

Measured memory_bytes: 4400
N=int(input())
A=list(map(int,input().split()))
max_=A[0]
ans=0
for i in range(1,N):
    if max_<A[i]:
        max_=A[i]
    else:
        ans+=max_-A[i]
        A[i]+=max_-A[i]
print(ans)

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

int dist[2005][2005];
vector<int> adjl[2005];
bool disabled[2005];
int n,k;

void dfs(int node, int parent, int s){
for (auto x : adjl[node]){
    if (x==parent) continue;
    dist[s][x] = dist[s][node] + 1;
    dfs(x,node,s);
}
}

int main(){
scanf("%d%d",&n,&k);
for (int x = 0; x<n-1; x++){
    int a,b;
    scanf("%d%d",&a,&b);
    a--;b--;
    adjl[a].push_back(b);
    adjl[b].push_back(a);
}
for (int x = 0; x<n; x++){
    dist[x][x] = 0;
    dfs(x,-1,x);
}
int curdist = 0;
int farnode = -1;
for (int x = 0; x<n; x++){
    if (dist[0][x]>curdist){
        curdist = dist[0][x];
        farnode = x;
    }
}
int diameter = 0;
for (int x = 0; x<n; x++){
    diameter = max(diameter,dist[farnode][x]);
}
if (diameter<=k){
    printf("0");
    return 0;
}
vector<pair<int,int> > nodes;
for (int x = 0; x<n; x++){
    nodes.push_back({dist[0][x],x});
}
sort(nodes.begin(),nodes.end(),greater<pair<int,int> > ());
stack<int> nxt;
int ans = 0;
for (int x = 0; x<n; x++){
    if (x!=0 && nodes[x].first<nodes[x-1].first){
        while (!nxt.empty()){
            int t = nxt.top();
            nxt.pop();
            disabled[t] = true;
        }
    }
    int te = 0;
    for (int y = 0; y<n; y++){
        if (disabled[y]) continue;
        if (dist[nodes[x].second][y]<=k){
            te++;
        }
    }
    ans = max(ans,te);
    nxt.push(nodes[x].second);
}
printf("%d",n-ans);
}


Measured memory_bytes: 16256
#include <iostream>
#include<string>
#include<cctype>
#include<algorithm>
using namespace std;

int main() {
	int n,all,a;
	int s[100];
	all = 0;
	a = 0;
	cin >> n ;
	for (int x = 0; x < n; ++x) cin >> s[x];
	for (int x = 0; x < n; ++x) all = all + s[x];
	if ((all % 10) != 0)cout << all << endl;
	else {
		sort(s, s + n);
		for (int x = 0; x < n; ++x) {
			if ((s[x] % 10) != 0) {
				cout << all - s[x] << endl;
				a = 1;
				break;
			}
		}
		if (a == 0)cout << a << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
#include<queue>
#include<tuple>
#include<utility>
#include<map>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define MP make_pair
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll N, s=0, ans=0, tot=0;
	ll X, M, len=0;
	cin >> N >> X >> M;
	vector<ll> id(M,-1);
	vector<ll> a;
	while(id[X]==-1){
		a.push_back(X);
		id.at(X) = len;
		len++;
		tot += X;
		X = (X * X) % M;
	}

	
	if (N <= len){
		FOR(i, 0, N){
			ans += a.at(i);
		}
	}

	else{
		ll c = len - id.at(X); //ループ回数
		FOR(i, id.at(X), len)
			s += a.at(i);
		ans += tot;
		N -= len;
		ans += (N / c) * s;
		N %= c;
		FOR(i, 0, N)
			ans += a.at(id.at(X) + i);
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 4656
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstdio>
#include <queue>
using namespace std;

int main(void){
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    cin >> v[i];
  }
  int r = n -1;
  int p = 0;
  int x = v[r];
  int i = p-1;
  for(int j=p;j<r;j++){
    if(v[j] <= x){
      swap(v[++i], v[j]);
    }
  }
  swap(v[i+1], v[r]);

  int val = i+1;

  for(int i=0;i<n;i++){
    if(i == val) cout << "[" << v[i] << "]";
     else cout << v[i];
    if(i!=n-1)
      cout << " ";
    else
      cout << endl;
  }

  return 0;
}

Measured memory_bytes: 1532
#include <stdio.h>
int main()
{
	long long lla;
	long long llb;
	long long llTotal;
	lla = llb = llTotal = 0;
	char cCalc;
	scanf("%lld %c %lld", &lla, &cCalc, &llb);

	if (cCalc == '+')
		llTotal = lla + llb;
	else
		llTotal = lla - llb;

	printf("%lld", llTotal);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void){
  int i;
  int score;
  int sum = 0;
  int min;

  /*?????????????????????????????°???*/
  min = 100;
  for(i = 0 ; i < 4 ; i++){
    scanf("%d", &score);
    if(score < min){
      min = score;
    }
    sum += score;
  }
  sum -= min;

  /*??´????????°???*/
  min = 100;
  for(i = 0 ; i < 2 ; i++){
    scanf("%d", &score);
    if(score < min){
      min = score;
    }
    sum += score;
  }
  sum -= min;

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


Measured memory_bytes: 600
#include<bits/stdc++.h>
#define Mod 1000000007
#define inv 500000004
#define N 5005
using namespace std;
int n,x,y,Q,a[N],dp[N][N];
inline int ksm(int x,int y){
	int ans1=1;while (y){
		if (y&1) ans1=1ll*ans1*x%Mod;
		y>>=1;x=1ll*x*x%Mod;
	}return ans1;
} 
int main(){
	scanf("%d%d",&n,&Q);int tmp=ksm(2,Q); 
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++) dp[i][j]=a[i]<a[j];//a[i]<a[j]的方案数 
	while (Q--){
		scanf("%d%d",&x,&y);
		if (x>y) swap(x,y);
		for (int i=1;i<=n;i++){
			if (i==x||i==y) continue;
			//dp[x][i]=dp[y][i]=(dp[x][i]+dp[y][i])%Mod;
			//dp[i][x]=dp[i][y]=(dp[i][x]+dp[i][y])%Mod;
			dp[x][i]=dp[y][i]=1ll*(dp[x][i]+dp[y][i])*inv%Mod;
			dp[i][x]=dp[i][y]=1ll*(dp[i][x]+dp[i][y])*inv%Mod;
		}
		//dp[x][y]=dp[y][x]=(dp[x][y]+dp[y][x])%Mod;
		dp[x][y]=dp[y][x]=1ll*(dp[x][y]+dp[y][x])*inv%Mod;
	}
	int ans=0;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=i;j++) ans=(ans+1ll*tmp*dp[i][j]%Mod)%Mod;
	printf("%d\n",ans); 
	return 0;
}

Measured memory_bytes: 59264
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            String str = sc.next();
            if(str.equals("-")){
                break;
            }
            int m = sc.nextInt();
            for(int i = 0; i < m; i++){
                int length = sc.nextInt();
                str = str.substring(length) + str.substring(0, length);
            }
            System.out.println(str);
        }
        sc.close();
    }
}


Measured memory_bytes: 26380
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REPS(i,n) for(int i=1;i<=(int)(n);i++)
using namespace std;
using ll = long long;
using ld = long double;

int main(void) {
    int N;
    cin >> N;
    set<string> set;
    REP (i, N) {
        string buf;
        cin >> buf;
        set.insert(buf);
    }
    cout << set.size() << endl;
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

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

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n, nn;
    cin >> n;
    nn = n;

    int f = 0;
    while (nn)
    {
        f += nn % 10;
        nn /= 10;
    }

    if (n % f)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
}


Measured memory_bytes: 256
#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>;
const int INF=1001001001;



int main() {
  int n;
  cin>>n;
  vector<int> h(n);
  vector<int> a(n);
  int now=0;
  rep(i,n){
    cin>>h[i];
  }
  int ans=0;
  for(int i=1;i<=100;i++){
    int cnt=0;
    int now=0;
    rep(j,n){
      int next=h[j];
      if (h[j]>=i) {
        if (now==1) continue;
        cnt++; now=1;
      }
      if (h[j]<i) {
        now=0;
      }
    }
    ans+=cnt;
  }
  cout<<ans;

  }


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
int main(void)
{
	int N;
	int A[100010],B[100010];
	int p = 1;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
		B[A[i]] = p;
		p++;
	}
	for (int j = 1; j <= N; j++) {
		printf("%d ", B[j]);
	}

	return 0;
}


Measured memory_bytes: 1536