akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
 #include <cstdlib>
 #include <iostream>
 #include <fstream>
 #include <sstream>
 #include <set>
 #include <map>
 #include <vector>
 #include <list>
 #include <algorithm>
 #include <cstring>
 #include <cmath>
 #include <string>
 #include <stack>
 #include <queue>
 #include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
 #include <cassert>
 #include <iomanip>        //do setprecision
 #include <ctime>
 #include <complex>
 using namespace std;

 #define FOR(i,b,e) for(int i=(b);i<(e);++i)
 #define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
 #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
 #define REP(x, n) for(int x = 0; x < (n); ++x)

 #define ST first
 #define ND second
 #define PB push_back
 #define PF push_front
 #define MP make_pair
 #define LL long long
 #define ULL unsigned LL
 #define LD long double
 #define pii pair<int,int>
 #define pll pair<LL,LL>

 const double pi = 3.14159265358979323846264;
 const int mod=1000000007;

 int main(){
	 int n,q;
	 cin>>n>>q;
	 vector<LL> a(n+1),x(q+1);
	 FOR(i,0,n)cin>>a[i+1];
	 FOR(i,0,q)cin>>x[i];
	 vector<LL> b(n+3),c(q+3);
	 FOR(i,0,n){
		 b[i+2]=a[i+1];
		 b[i+2]+=b[i];
		 c[i+1]=a[i+1];
		 c[i+1]+=c[i];
	 }
	 FOR(t,0,q){
		 int y=x[t];
		 int l=0,r=n,m=(l+r)/2;
		 while(l!=m){
			 if(2*m>n){
				 r=m;
				 m=(l+r)/2;
				 continue;
			 }
			 if(abs(a[n-m*2+1]-y)<=abs(a[n-m+1]-y)){
				 l=m;
			 }else{
				 r=m;
			 }
			 m=(l+r)/2;
		 }
		 //cerr<<"t:"<<t<<" y:"<<y<<" m:"<<m<<endl;
		 if(m==0){
			 cout<<b[n-1+2]<<endl;
		 }else{
			 if(abs(a[n-m*2+1]-y)==abs(a[n-m+1]-y)){
				 LL ans=c[n-1+1]-c[n-m-1+1]+b[n-2*m-1+2];
				 //cerr<<"type:"<<0<<" y:"<<y<<" m:"<<m<<endl;
				 cout<<ans<<endl;
			 }else{
				 if(n-1-2*m+1==0){
					 LL ans=c[n-1+1]-c[n-m-1+1]+b[n-2*m-1+2];
					 //cerr<<"type:"<<1<<" y:"<<y<<" m:"<<m<<endl;

					 cout<<ans<<endl;
				 }else if(abs(a[n-m*2-1+1]-y)<=abs(a[n-m-1+1]-y)){
					 LL ans=c[n-1+1]-c[n-m-2+1];
					 //cerr<<"type:"<<2<<" y:"<<y<<" m:"<<m<<endl;

					 if(n-3-2*m+1>0){
						 ans+=b[n-3-2*m+2];
					 }
					 cout<<ans<<endl;
				 }else{
					 LL ans=c[n-1+1]-c[n-m-1+1]+b[n-2*m-1+2];
					 //cerr<<"type:"<<3<<" y:"<<y<<" m:"<<m<<endl;

					 cout<<ans<<endl;
				 }
			 }
		 }

	 }


   return 0;
 }


Measured memory_bytes: 4864
import java.util.Scanner;
public class Main{	
   int x;

public void solve(){
    Scanner sc = new Scanner(System.in);
    x = sc.nextInt();
    
	x = x*x*x;
	
	System.out.println(x);
	}



	public static void main(String[] args){
		Main obj = new Main();
	   obj.solve();
	}
}

Measured memory_bytes: 17168
#include<bits/stdc++.h>
#define lson l, mid, i<<1
#define rson mid+1, r, i<<1|1
#define PII pair<int, int>
#define Size(x) (int)(x.size())
using namespace std;
typedef long long LL;
const int MOD = 1e9+7;
const auto INF = 0x3f3f3f3f;
const int N = 1e5+5;

char str[N];
char ch[] = {"FESTIVAL"};

int main() {
    scanf("%s", str);
    int len = (int)strlen(str);
    str[len-8] = '\0';
    printf("%s\n", str);
}






Measured memory_bytes: 256
a, b = input().split()
a = int(a)
b = b.split('.')
if len(b) == 1:
    ans = a * int(b[0])
elif len(b[-1]) == 1:
    ans = a * (10 * int(b[0]) + int(b[1])) // 10
else:
    ans = a * (100 * int(b[0]) + int(b[1])) // 100
print(ans)

Measured memory_bytes: 61880
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
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 FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(void){
    ll k;
    cin >> k;
    int n = 50;
    VL ans(n);
    ll m = (k + n - 1) / n;
    REP(i,n){
        ans[i] = n - 1 - i + m;
    }

    ll x = n * m - k;
    REP(i,x){
        REP(j,n){
            if (j == i) ans[j] -= n;
            else ans[j]++;
        }
    }


    cout << n << endl;
    REP(i,n) cout << ans[i] << " ";
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int n, a, b, c, d; cin >> n >> a >> b >> c >> d;
    a--; b--; c--; d--;
    string s; cin >> s;

    if(c < d) {
        for(int i = a + 1; i <= d; i++) {
            if(s[i] == '#' && s[i + 1] == '#') {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }

    for(int i = b; i <= d; i++) {
        if(s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <climits>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
const ll INF = LLONG_MAX;
vector<int> xnorm = {0, 1, 0, -1};
vector<int> ynorm = {1, 0, -1, 0};
vector<int> xmagic = {-2, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -1, 1, 1, -1};
vector<int> ymagic = {2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, 0, 1, 1, 1, -1, -1};

int main()
{
    ll h, w;
    cin >> h >> w;
    ll ch, cw, dh, dw;
    cin >> ch >> cw >> dh >> dw;
    ch--;
    cw--;
    dh--;
    dw--;
    vector<vector<char>> s(h, vector<char>(w));
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> s[i][j];
        }
    }
    priority_queue<PP, vector<PP>, greater<PP>> q;
    vector<vector<ll>> dist(h + 5, vector<ll>(w + 5, INF));
    dist[ch][cw] = 0;
    q.push(make_pair(0, make_pair(ch, cw)));
    while (!q.empty())
    {
        auto item = q.top();
        q.pop();

        for (int i = 0; i < 4; i++)
        {
            ll tempx = item.second.first + xnorm[i];
            ll tempy = item.second.second + ynorm[i];
            if (tempx > h - 1 || tempx < 0 || tempy > w - 1 || tempy < 0)
            {
                continue;
            }
            if (s[tempx][tempy] != '.')
            {
                continue;
            }
            if (dist[tempx][tempy] <= item.first)
            {
                continue;
            }
            dist[tempx][tempy] = item.first;
            q.push(make_pair(dist[tempx][tempy], make_pair(tempx, tempy)));
        }
        for (int i = 0; i < 20; i++)
        {
            ll tempx = item.second.first + xmagic[i];
            ll tempy = item.second.second + ymagic[i];
            if (tempx > h - 1 || tempx < 0 || tempy > w - 1 || tempy < 0)
            {
                continue;
            }
            if (s[tempx][tempy] != '.')
            {
                continue;
            }
            if (dist[tempx][tempy] <= item.first + 1)
            {
                continue;
            }
            dist[tempx][tempy] = item.first + 1;
            q.push(make_pair(dist[tempx][tempy], make_pair(tempx, tempy)));
        }
    }
    if (dist[dh][dw] != INF)
    {
        cout << dist[dh][dw] << endl;
    }
    else
    {
        cout << -1 << endl;
    }
    return 0;
}

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

int main() {
    int A,B,C,D,E,F;
    cin >> A >> B >> C >> D >> E >> F;
    int sumw=0,sums=0,suma=0;
    int maxa=0,maxs=0;
    long double ma=0;

    for(int b=0;b<31;b++){
        for(int a=0;a<31;a++){
            for(int d=0;d<201;d++){
                for(int c=0;c<201;c++){
                    if(a==0 && b==0) break;
                    sumw=(a*A+b*B)*100;
                    sums=c*C+d*D;
                    suma=sumw+sums;
                    if(sums<=(a*A+b*B)*E && suma<=F){
                        if(ma<100*(long double)sums/suma){
                            ma=100*(long double)sums/suma;
                            maxa=suma;
                            maxs=sums;
                        }
                    }else{
                        break;
                    }
                }
            }
        }
    }
    if(maxa==0) maxa=100*A;
    cout << maxa << " " << maxs << endl;
}

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

int N;
int dp[100001];
bool dfs(int s[100], int K)
{
    if(K == 0)return false;
    if(dp[K] >= 0)return dp[K]; 
    bool result = false;
    for(int i=0; i<N; i++)
    {
        if(K >= s[i])
        {
            result |= !dfs(s, K-s[i]);
        }
    }
    return dp[K] = result;
}

int main()
{
    int K;
    //freopen("input.txt", "r", stdin);
    memset(dp, -1, sizeof(dp));
    scanf("%d%d", &N, &K);
    int stones[100];
    for(int i=0; i<N; i++)
    {
        scanf("%d", &stones[i]);
    }
    printf(dfs(stones, K) ? "First\n" : "Second\n");
    return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const ll MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

void solve(){
    int n;cin >> n;
    int c[11][11];
    memset(c,0,sizeof(c));
    for(int i = 1;i<=n;i++){
        int f = i;
        int l = i%10;
        //cout << f <<' '<< l <<endl;
        while(f>9){
            f /= 10;
        }
        c[f][l]++;
    }
    int ans = 0;
    for(int i = 0;i<10;i++)
        for(int j = 0;j<10;j++)
        ans += c[i][j]*c[j][i];
        cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 3644
from scipy.misc import comb
n = int(input())
s = sorted([''.join(sorted(list(input()))) for i in range(n)])
ans = 0
tmp = 1
for i in range(1, n):
    if s[i] == s[i - 1]:
        tmp += 1
    else:
        ans += comb(tmp, 2, exact = True)
        tmp = 1
ans += comb(tmp, 2, exact = True)
print(ans)


Measured memory_bytes: 21756
// 5_abc137_e
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int n, m, s, p;
vector<vector<pair<int, int> > > g;
vector<ll> dist;

void bellman_ford(){
    rep(i, n - 1){
        rep1(j, n){
            if(dist[j] == INF) continue;

            rep(k, g[j].size()){
                int next = g[j][k].first;
                if(dist[next] > dist[j] + g[j][k].second){
                    dist[next] = dist[j] + g[j][k].second;
                }
            }
        }
    }

    ll ans = dist[n];

    rep(i, n){
        rep1(j, n){
            if(dist[j] == INF) continue;

            rep(k, g[j].size()){
                int next = g[j][k].first;
                if(dist[j] == -INF){
                    dist[next] = -INF;
                }else{
                    if(dist[next] > dist[j] + g[j][k].second){
                        dist[next] = -INF;
                    }
                }
            }
        }
    }

    if(ans > dist[n]){
        cout << -1 << endl;
    }else{
        if(ans > 0) cout << 0 << endl;
        else cout << -ans << endl;
    }
}

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

    cin >> n >> m >> p;
    g.resize(n + 1);
    dist.resize(n + 1);
    rep(i, m){
        int a, b, c;
        cin >> a >> b >> c;
        g[a].push_back(make_pair(b, -c + p));
    }
    rep1(i, n){
        dist[i] = INF;
    }
    dist[s] = 0;

    bellman_ford();
    return 0;
}

Measured memory_bytes: 512
import java.lang.Math

fun main(args: Array<String>) {
    val s = readLine()
    var diff = Int.MAX_VALUE
    for (i in 0..(s!!.length - 3)) {
        val chunk = s.substring(i, i + 3).toInt()
        diff = Math.min(diff, Math.abs(753 - chunk))
    }
    println(diff)
}


Measured memory_bytes: 33648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

ll dp[101][9];

int main(void){
    ll h, w, k;
    cin >> h >> w >> k;

    dp[0][0] = 1;

    rep(i, 0, h){
        rep(j, 0, w){
            rep(bit, 0, 1<<(w-1)){
                bool flag = true;
                rep(t, 0, w-2){
                    if(((bit >> t) & 3) == 3)
                        flag = false;
                    }
                if(!flag) continue;

                if((bit >> j) & 1 && j < w-1){
                    dp[i+1][j+1] += dp[i][j];
                    dp[i+1][j+1] %= 1000000007;
                }else if((bit >> (j-1)) & 1 && j > 0){
                    dp[i+1][j-1] += dp[i][j];
                    dp[i+1][j-1] %= 1000000007;
                }else{
                    dp[i+1][j] += dp[i][j];
                    dp[i+1][j] %= 1000000007;
                }
            }
        }
    }

    cout << dp[h][k-1] << endl;
    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

a = 0
b = 0
for i in range(N - 1):
  for j in range(i + 1, N):
    if A[i] > A[j]:
      a += 1
    if A[i] < A[j]:
      b += 1
ans = a * K * (K + 1) // 2
ans += b * K * (K - 1) // 2
print(ans % MOD)

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

using ll=long long;
template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  ll k;cin>>k;
  ll now=0;
  set<ll> s;
  for(int i=1;;i++){
    now=(now*10+7)%k;
    if(!now)fin(i);
    if(s.count(now))fin(-1);
    s.insert(now);
  }
}


Measured memory_bytes: 50496
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
#include<string.h>
using namespace std;
typedef long long int llint;
int main() {
	llint a, b, c;
	cin >> a >> b >> c;
	if (c <= a + b + 1) {
		cout << b + c << endl;
	}
	else {
		cout << b + a + b + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
 
#if DEBUG
    #include "debug.h"
#else
    #define debug(args...)
#endif    

using namespace std;

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


#define M 1000000 
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = INT_MAX;
const int mod = 1e9+7;

const int N = 2e5 + 10;
inline int add(int x,int y){
  x += y;
  if(x >= mod) x -= mod;
  return x;
}
inline int mul(int x,int y){
  x = (1LL * x * y) % mod;
  return x;
}
clock_t time_p=clock();



int32_t main(){
	fast;

	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);

	int a,b;
	cin >> a >> b;
	cout << max(0,a - 2 * b) << "\n";

	time_p=clock()-time_p;
	cerr<<"\nTime Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";

	return 0;
}

Measured memory_bytes: 256
N = gets.chomp.to_i
p = gets.chomp.split.map(&:to_i)
q = gets.chomp.split.map(&:to_i)

hash = {}
i = 1
(1..N).to_a.permutation(N) do |arr|
  hash[arr] = i
  i += 1
end

p (hash[p]-hash[q]).abs


Measured memory_bytes: 21128
#include<iostream>
using namespace std;
int main() {
	string str;
	cin>>str;
	char ch='h';
	int count = 0;
	for(int i = 0; i < str.length(); i++) {
		if(str[i]==ch) {
			count++;
			if(ch=='h')
				ch='i';
			else
				ch='h';		
		}
	}					
	if(str.length()/2+str.length()%2==count/2)
		cout<<"Yes";
	else
		cout<<"No";						
}

Measured memory_bytes: 256
/*
 * src.cpp
 *
 *  Created on: 2016/08/01
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

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

const int MAX_X=15,MAX_Y=15;

int X,Y;
int c[MAX_Y][MAX_X];

int memo[MAX_Y][MAX_X];

int dfs(int x,int y){
	if (y<Y && c[y][x]==1){
		return 0;
	}
	if (y>=Y-1){
		return 1;
	}
	if (memo[y][x]!=-1){
		return memo[y][x];
	}
	if (c[y][x]==2){
		return dfs(x,y+2);
	}
	int res=0;
	if (x>0 && c[y+1][x-1]==0){
		res+=dfs(x-1,y+1);
	}
	if (x<X-1 && c[y+1][x+1]==0){
		res+=dfs(x+1,y+1);
	}
	res+=dfs(x,y+1);
	return memo[y][x]=res;
}

int main(){
	do{
		scanf("%d %d",&X,&Y);
		if (X || Y){
			REP(i,Y){
				REP(j,X){
					scanf("%d",&c[i][j]);
				}
			}
			memset(memo,-1,sizeof(memo));
			int ans=0;
			REP(i,X){
				ans+=dfs(i,0);
			}
			printf("%d\n",ans);
		}
	}while (X || Y);
	return 0;
}

Measured memory_bytes: 1188
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
		char[] a = sc.next().toCharArray();
		char[] b = sc.next().toCharArray();
		int[][] dp = new int[a.length][b.length];
		int max = 0;
		for(int i = 0; i < a.length; i++) {
			for(int j = 0; j < b.length; j++) {
				if(a[i] == b[j]) {
					if(i != 0 && j != 0)
					dp[i][j] = Math.max(dp[i-1][j-1]+1, 1);
					else dp[i][j] = 1;
					max = Math.max(dp[i][j], max);
				}
				
				
				
			}
		}
		System.out.println(max);
		}
		
	}

	
}

Measured memory_bytes: 184348
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll x,y,v,ans=0;
  cin >> x >> y;
  v = x;
  while(true){
    if(v>y) break;
    ans++;
    v *= 2;
  }
  cout << ans << endl;
}


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

void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
}

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


Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#define int long long
#define endre getchar();getchar();return 0
#define moder 1000000007
#define inf 1000000000000000000
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int kai(int x) {
	if (x == 0)return 1;
	return (kai(x - 1)*x) % moder;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

int n, c, s[100005], t[100005], ch[1000005];
int cnt[1000005][50];
signed main() {
	cin >> n >> c;
	rep(i, n) {
		cin >> s[i] >> t[i] >> ch[i];
		cnt[s[i] - 1][ch[i]]++;
		cnt[t[i]][ch[i]]--;
	}
	for (int i = 1; i <= 100001; i++) {
		for (int j = 1; j <= c; j++) {
			cnt[i][j] += cnt[i - 1][j];
		}
	}
	int ans = 0;
	for (int i = 1; i <= 100001; i++) {
		int memo = 0;
		for (int j = 1; j <= c; j++) {
			memo += (bool)cnt[i][j];
		}
		ans = max(ans, memo);
	}
	cout << ans << endl;
	endre;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); 
	cout.tie(NULL);
	
	ll l,r,d;
	cin>>l>>r>>d;
	l-=1;
	ll p=abs(l/d-r/d);
	cout<<p;
	return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll dp[33][33];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	vector<ii> a;
	for(int i=0;i<n;i++)
	{
		ld x; cin>>x;
		ll v = round(x*ld(1e9));
		ii c = {0,0};
		while(v%2==0)
		{
			v/=2;
			c.fi++;
		}
		while(v%5==0)
		{
			v/=5; c.se++;
		}
		c.fi=min(c.fi,18LL);
		c.se=min(c.se,18LL);
		a.pb(c);
		dp[c.fi][c.se]++;
	}
	ll ans=0;
	for(int i=0;i<n;i++)
	{
		dp[a[i].fi][a[i].se]--;
		for(int j=0;j<=18;j++)
		{
			for(int k=0;k<=18;k++)
			{
				if(j+a[i].fi>=18&&k+a[i].se>=18) ans+=dp[j][k];
			}
		}
		dp[a[i].fi][a[i].se]++;
	}
	ans/=2;
	cout<<ans<<'\n';
}


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

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define endl "\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

ll const inf = 1e18;
ll const maxn = 1e6+5;
ll const mod = 998244353;

// code begins here

int main(){
    fast;
    
    ll n;
    cin>>n;
    
    vector<ll> arr(n), brr(n);
    for(auto &u: arr)
        cin>>u;
    
    ll x = 0;
    for(ll i=n-1;i>1;i--)
        x ^= arr[i];
    
    brr[0] = x^arr[1];
    
    for(ll i=1;i<n;i++)
        brr[i] = arr[i]^arr[i-1]^brr[i-1];
    
    for(auto u: brr)
        cout<<u<<" ";
    cout<<endl;
    
    return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a;
    string s;
    cin >> a >> s;
    cout << (a >= 3200 ? s : "red") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 N, Q;
  std::string S;
  std::cin >> N >> S >> Q;
  std::vector<i64> k;
  tools::read(k, Q);

  for (const i64& k_i : k) {
    i64 D = 0;
    i64 M = 0;
    i64 DM = 0;
    i64 answer = 0;

    for (i64 j = 0; j < N; ++j) {
      if (j >= k_i) {
        switch (S[j - k_i]) {
        case 'D':
          --D;
          DM -= M;
          break;
        case 'M':
          --M;
          break;
        }
      }
      switch (S[j]) {
      case 'D':
        ++D;
        break;
      case 'M':
        ++M;
        DM += D;
        break;
      case 'C':
        answer += DM;
        break;
      }
    }

    std::cout << answer << std::endl;
  }

  return 0;
}

Measured memory_bytes: 1412
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i > 0; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;

int main() {
	int n;
	cin >> n;
	int div = 0;
	string ans = "No";
	string m = to_string(n);
	rep(i, m.size()) {
		div += (m[i] - '0');
	}
	if (n%div == 0) {
		ans = "Yes";
	}
	cout << ans << endl;
	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=0;i<b;i++)
#define REP(i,a,b) for(int i=0;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout <<(f?"Yes":"No")<<endl//fが真の場合Yesを出力、偽の場合Noを出力
#define yes(f) cout <<(f?"yes":"no")<<endl
#define YES(f) cout <<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())

using namespace std;

const int mod=1e9+7;

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

    int ans;
    rep(i,4)
    {
        if(s[i]=='+')ans++;
        if(s[i]=='-')ans--;
    }

    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

// Defines and one-liners
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
template <typename T> inline T& back(vector<T> &vec) { return *(vec.end() - 1); }
template <typename T> inline void pop(vector<T> &vec) { return vec.erase(vec.end() - 1); }

// Scan, Debug, and other nonsense
template <typename T> ostream& operator<<(ostream& out,vector<T> iter){out<<"[";for(auto t:iter){out<<t<<", ";}out<<"]";return out;}
template <typename T> void printArray(ostream& out,T* arr,int sz){out<<"[";for(int i=0;i<sz;i++){out<<arr[i]<<", "; } out<<"]";}
#define OUT_OPERATOR(type, propa, propb) ostream& operator<<(ostream& out,type obj){out<<"("<<#propa<<"="<<obj. propa<<", "<<#propb<<"="<<obj. propb<<")";return out;}

void scan(){}
template<typename F, typename... R> void scan(F &f,R&... r){cin>>f;scan(r...);}
int di_; string dnms_, co_ = ",";
void debug_(){cout<<endl;}
template<typename F, typename... R> void debug_(F f,R... r){while(dnms_[di_] != ',')cout<<dnms_[di_++];di_++;cout<<": "<<f<<",";debug_(r...);}
#define debug(...) dnms_=#__VA_ARGS__+co_,di_=0,debug_(__VA_ARGS__)

template <int MAX, typename T = int>
struct BIT {
    int n; T defaultV, tree[MAX];
    inline void merge(T& a, T& b){ a = max(a, b); };
    void init(int n0, T defaultV0) { n = n0; defaultV = defaultV0; }
    void upd(int x, T z){ // Adds value `z` to index `x`
        for(; x <= n; x += x & -x)
            merge(tree[x], z);
    }
    T query(int x){ // Queries index `x`
        T sum = defaultV;
        for(; x; x -= x & -x)
            merge(sum, tree[x]);
        return sum;
    }
    void reverseUpd(int x, T z) { upd(n - x + 1, z); }
    T reverseQuery(int x) { return query(n - x + 1); }
};

const int MAX = 2e5 + 1;
int n,
    a[MAX], h[MAX];
ll dp[MAX];
BIT<MAX, ll> bit;

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

    scan(n);

    bit.init(n, 0);

    for (int i = 1; i <= n; i++)
        scan(h[i]);
    for (int i = 1; i <= n; i++)
        scan(a[i]);
    
    for (int i = 1; i <= n; i++) {
        dp[i] = bit.query(h[i] - 1) + a[i];
        bit.upd(h[i], dp[i]);
    }

    cout << *max_element(dp + 1, dp + n + 1) << "\n";

    return 0;
}

Measured memory_bytes: 4992
<?php
$line  = explode(' ', trim(fgets(STDIN)));
$limit = $line[0];
$sum   = $line[1];
$count = 0;
for ($x = 0; $x <= $limit; $x++) {
    for ($y = 0; $y <= $limit; $y++) {
        if ($x + $y <= $sum && $sum - $x - $y <= $limit) {
            $count++;
        }
    }
}
print $count;


Measured memory_bytes: 4604
package main

import "fmt"

func main() {
  var n, x, t int
  fmt.Scan(&n, &x, &t)
  var sum int
  if n % x == 0 {
    sum = n / x * t
  } else {
    sum = n / x * t + t
  }
  fmt.Println(sum)
}

Measured memory_bytes: 1768
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	int n, k, x, y; scanf("%d %d %d %d", &n, &k, &x, &y);
	printf("%d\n", min(n, k) * x + max(0, n - k) * y);
	return 0;
}

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

int main() {
  int a,b;cin>>a>>b;
  ll ans=a/(ll)gcd(a,b)*b;
  cout<<ans<<endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <climits>
#include <unordered_map>
#include <functional>
#include <queue>

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

#define p2(a, b) cout << a << "\t" << b << endl
#define p3(a, b, c) cout << a << "\t" << b << "\t" << c << endl

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

inline int ctoi(char c) {
    return (int)(c -'0');
}

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

int main() {
    ll n,k;
    cin >> n >> k;
    vector<ll> vec(n);
    rep(i, n) {
        cin >> vec[i];
    }

    ll ans = 0;
    rep(i, n) {
        ans += min(2*vec[i], 2 * abs(k-vec[i]));
    }

    cout << ans << endl;
    return 0;
}


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

using namespace std;
#define ll long long
#define ld long double

ll binPow(ll a, ll b) {
    ll ans = 1;
    while(b > 0) {
        if(b & 1) ans *= a;
        a *= a;
        b >>= 1;
    }
    return ans;
}

ll binPowMod(ll a, ll b, ll m) {
    ll ans = 1;
    a %= m;
    while(b > 0) {
        if(b & 1) ans *= a % m;
        a *= a % m;
        b >>= 1;
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int n;
    string s;
    cin >> n >> s;
    int cnt = 0;
    for(int i=0;i<n-2;i++) {
        string sub = s.substr(i, 3);
        //cout << sub << '\n';
        if(sub == "ABC") cnt++;
    }
    cout << cnt << '\n';
    return 0;
}


Measured memory_bytes: 256
x = input()
N = len(x)
x1 = "01" * (N//2)
x2 = "10" * (N//2)
if N%2 == 1:
  x1 = x1 + "0"
  x2 = x2 + "1"
count1 = 0
count2 = 0
for x, y, z in zip(x, x1, x2):
  if x != y:
	  count1 += 1
  if x != z:
	  count2 += 1
count = min(count1, count2)
print(count)


Measured memory_bytes: 3316
#include <iostream>
#include <cmath>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n, t, a, ret;
    double p = 100000000.0;
    cin >> n >> t >> a;
    rep(i, n){
        int h;
        cin >> h;
        if(fabs(t - h * 0.006 - a) < fabs(t - p * 0.006 - a)){
            p = h;
            ret = i + 1;
        }
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <climits>
using namespace std;

int ans[10010];
char tmp[8];

int dfs(int x){
	if(ans[x] >= 0){
		return ans[x];
	}
	if(ans[x] != -1){
		return INT_MIN;
	}
	ans[x] = INT_MIN;

	sprintf(tmp, "%04d", x);
	sort(tmp, tmp + 4);
	int b = strtol(tmp, 0, 10);
	reverse(tmp, tmp + 4);
	int a = strtol(tmp, 0, 10);
	ans[x] = dfs(a - b) + 1;
	return ans[x];
}


int main(){
	for(int i = 0; i < 10005; ++i){
		ans[i] = -1;
	}
	ans[6174] = 0;

	int n;
	while(scanf("%d", &n), n){
		int a = dfs(n);
		printf(a < 0 ? "NA\n" : "%d\n", a);
	}
}

Measured memory_bytes: 1100
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

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

vector<int>bitSearch(int bit,int n){
    vector<int>S,False(1,-1);
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

template<typename A,size_t N,typename T>
void Fill(A(&array)[N],const T &val){
    fill((T*)array,(T*)(array+N),val);
}

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



int main(){
    int n , a , b;
    cin >> n >> a >> b;

    string s;
    cin >> s;

    int cnt = 0, rank = 0;

    rep(i, n){
        if( s[i] == 'a' && cnt < a + b ){
            cout << "Yes" << endl;
            cnt++;
        }

        else if( s[i] == 'b' && cnt < a + b && rank < b ){
            cout << "Yes" << endl;
            cnt++;
            rank++;
        }

        else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 832
#!/usr/bin/env python3

def main():
    n = int(input())
    ai = list(map(int, input().split()))
    assert len(ai) == n

    for i in range(n):
        ai[i] -= i + 1

    ai = sorted(ai)
    b = ai[(n - 1) // 2]

    mi = 0
    for i in range(n):
        mi += abs(ai[i] - b)

    print(mi)

main()



Measured memory_bytes: 25200
import collections


def main():
    n = int(input())
    vn = list(map(int, input().split()))

    odd_vn = [v for i, v in enumerate(vn) if i % 2 == 0]
    even_vn = [v for i, v in enumerate(vn) if i % 2 == 1]

    odd_vn_counter = collections.Counter(odd_vn)
    even_vn_counter = collections.Counter(even_vn)

    odd_vn_mode = odd_vn_counter.most_common(2)
    even_vn_mode = even_vn_counter.most_common(2)

    odd_num = odd_vn_mode[0][0]
    even_num = even_vn_mode[0][0]

    if odd_vn_mode[0][0] == even_vn_mode[0][0]:
        if 2 <= len(odd_vn_mode) and 2 <= len(even_vn_mode):
            if odd_vn_mode[1][1] <= even_vn_mode[1][1]:
                even_num = even_vn_mode[1][0]
            else:
                odd_num = odd_vn_mode[1][0]
        elif 2 <= len(odd_vn_mode):
            odd_num = odd_vn_mode[1][0]
        elif 2 <= len(even_vn_mode):
            even_num = even_vn_mode[1][0]
        else:
            even_num = even_vn_mode[0][0] + 1

    ans = n - odd_vn.count(odd_num) - even_vn.count(even_num)
    print(ans)


main()


Measured memory_bytes: 19032
use std::fmt;
use std::io::stdin;
use std::io::BufRead;
use std::str;
use std::str::FromStr;
use std::vec::Vec;

fn main() {
    let stdin = stdin();
    let mut scan = InputScanner::new(stdin.lock(),256);

    let x:usize = scan.next();
    let y:usize = scan.next();

    let mut v = x;
	let mut r = vec![x];

    while v * 2 <= y {
        v = v * 2;
		r.push(v);
    }

    println!("{}",r.len());
}
struct InputScanner<R: BufRead> {
	reader: R,
	buf: Vec<u8>, // Should never be empty
	pos: usize,   // Should never be out of bounds as long as the input ends with '\n'
}
impl<R: BufRead> InputScanner<R> {
	fn new(reader: R, capacity: usize) -> Self {
		InputScanner {
			reader: reader,
			buf: Vec::with_capacity(capacity),
			pos: 0,
		}
	}

	#[inline]
	fn next<T: FromStr>(&mut self) -> T
	where
		T::Err: fmt::Debug,
	{
		if self.buf.is_empty() {
			self._read_next_line();
		}
		let mut start = None;
		loop {
			match (self.buf[self.pos], start.is_some()) {
				(b' ', true) | (b'\n', true) | (b'\r', true) => break,
				(_, true) | (b' ', false) => self.pos += 1,
				(b'\n', false) | (b'\r', false) => self._read_next_line(),
				(_, false) => start = Some(self.pos),
			}
		}
		let target = &self.buf[start.unwrap()..self.pos];
		unsafe { str::from_utf8_unchecked(target) }.parse().unwrap()
	}

	#[inline]
	fn _read_next_line(&mut self) {
		self.pos = 0;
		self.buf.clear();
		if self.reader.read_until(b'\n', &mut self.buf).unwrap() == 0 {
			panic!("Reached EOF");
		}
	}
}



Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<cstdlib>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
#include<string>
#include<deque>
#define lmid l,mid,rt<<1
#define rmid mid+1,r,rt<<1|1
using namespace std;
int s[15][15], t[205][205];
int main() {
     int n, m;
     scanf("%d%d", &n, &m);
     for(int i = 0; i < 10; i++)
          for(int j = 0; j < 10; j++)
               scanf("%d", &s[i][j]);
     for(int k = 0; k <10; k++)
          for(int i = 0; i <10; i++)
               for(int j = 0; j < 10; j++)
                    s[i][j] = min(s[i][j], s[i][k] + s[k][j]);
     int sum = 0;
     for(int i = 0; i < n * m; i++) {
          int a;
          scanf("%d", &a);
          if(a == 1 || a == -1) continue;
          sum += s[a][1];
     }
     cout << sum << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
typedef pair<lint,lint> P;
#define rep(i, n) for (lint i = 0; i < (n); i++)
#define INF LLONG_MAX
#define MAX_V 100005
struct edge{lint to,cost;};
lint n;
vector<edge> vec[MAX_V];
lint d[MAX_V];
void dfs(lint v);
void dijkstra(lint k);
void dijkstra2(lint k);
signed main(){
    cin>>n;
    rep(i,n-1){  
        lint a,b,c;
        cin>>a>>b>>c;
        a--;
        b--;
        vec[a].push_back({b,c});
        vec[b].push_back({a,c});
    }          
    lint q,k;
    cin>>q>>k;
    k--;
    fill(d,d+n,INF);
    d[k]=0;
    dfs(k);
    rep(i,q){
        lint x,y;
        cin>>x>>y; 
        x--;
        y--;
         cout<<d[x]+d[y]<<endl;
    }
    return 0;
}
void dijkstra(lint k){
    priority_queue<P, vector<P>,greater<P> >que;
    fill(d,d+n,INF);
    d[k]=0;
    que.push(P(0,k));
    while(!que.empty()){
        P p=que.top();
        que.pop();
        lint v= p.second;
        if(d[v]<p.first)continue;
        for(lint i=0;i<vec[v].size();i++){
            edge temp=vec[v][i];
            if(d[temp.to]>d[v]+temp.cost){
                d[temp.to]=d[v]+temp.cost;
                que.push(P(d[temp.to],temp.to));
            }
        }
    }
}
void dijkstra2(lint k){
    queue<P>que;
    fill(d,d+n,INF);
    d[k]=0;
    que.push(P(0,k));
    while(!que.empty()){
        P p=que.front();
        que.pop();
        lint v= p.second;
        for(lint i=0;i<vec[v].size();i++){
            edge temp=vec[v][i];
            if(d[temp.to]>d[v]+temp.cost){
                d[temp.to]=d[v]+temp.cost;
                que.push(P(d[temp.to],temp.to));
            }
        }
    }
}
void dfs(lint v){
    for(lint i=0;i<vec[v].size();i++){
            edge temp=vec[v][i];
            if(d[temp.to]>d[v]+temp.cost){
                d[temp.to]=d[v]+temp.cost;
                dfs(temp.to);
            }
    }
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

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

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

int main() {

  int a=0;
  int b=0;
  rep(i,4) { int x; cin >> x; a += x; }
  rep(i,4) { int x; cin >> x; b += x; }
  cout << max(a,b)<<endl;

  return 0;
}

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

const int DIM = 1e5 + 5;

int arr[DIM];

int main( void ) {
    
    int n, c, k;
    cin >> n >> c >> k;
    
    for( int i = 1; i <= n; i ++ )
        cin >> arr[i];
    
    sort( arr + 1, arr + n + 1 );
    
    int tm = -1e9 - 7, cnt = 0, ans = 0;
    for( int i = 1; i <= n; i ++ ) {
        if( arr[i] - tm > k || cnt == c ) {
            tm = arr[i]; cnt = 1;
            ans ++;
        }
        else
            cnt ++;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
import sys

n, k = [int(x) for x in input().split(" ")]
h_list = [int(x) for x in input().split(" ")]

dp = [sys.maxsize] * len(h_list)
dp[0] = 0
dp[1] = abs(h_list[1] - h_list[0])

for i in range(2, len(dp)):
  dp_i_costs = []
  for j in range(k+1):
    if i - j >= 0:
      dp_i_costs.append(dp[i - j] + abs(h_list[i] - h_list[i - j]))
  
  dp[i] = min(dp_i_costs)

print(dp[-1])

Measured memory_bytes: 52212
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());
        Integer[] a = new Integer[m];
        Arrays.setAll(a, i -> Integer.parseInt(sc.next()));
        sc.close();

        // 主処理
        int cost0 = 0;
        int costN = 0;
        for (int i = 0; i < m; i++) {
            if (a[i] < x) {
                cost0++;
            } else {
                costN++;
            }
        }

        int result = Math.min(cost0, costN);

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 26964
#include<bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  char c1, c2;
  int y, m, d;
  cin >> y >> c1 >> m >> c2 >> d;
  if(m <= 4) {
      cout << "Heisei" << endl;
  } else {
      cout << "TBD" << endl;
  }
}

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

using namespace std;

int main() {
    int A, B, T;
    cin >> A >> B >> T;
    
    int count = 1;
    int res = 0;
    
    while (count * A < (T + 0.5)) {
        res += B;
        count += 1;
    }
    
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
char s[N];
map <char,int> cot;
int main(){
//a	freopen("1.txt","r",stdin);
	cin>>s+1;
	int len=strlen(s+1);
	for(int i=1;i<=len;i++) cot[s[i]]++;
	long long ans=len;
	ans*=(len-1);
	ans/=2;
	ans++;
	//cout<<len<<endl;
	//cout<<ans<<endl;
	for(int i=1;i<=len;i++) if(cot[s[i]]){
		long long dep=cot[s[i]];
		dep*=cot[s[i]]-1;
		dep/=2;
		ans-=dep;//'cot[s[i]]*(cot[s[i]]-1)/2;
		//cout<<cot[s[i]]<<" ";
		//cout<<ans<<endl;
		cot[s[i]]=0;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
x,k,d = gets.split.map(&:to_i)
x = x.abs
if x == 0
  if k.odd?
    puts d
  else
    puts 0
  end
  exit
end
c = k * d
if c <= x
  puts x - c
  exit
end
x = x.abs
a = x / d
b = k - a
y = x - a * d
z = y - d
if b.odd?
  puts z.abs
else
  puts y
end

Measured memory_bytes: 14368
import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n=int(input())
points=[]
uf=UnionFind(n)
for i in range(n):
  x,y=map(int,input().split())
  points.append([x,y,i])
points=sorted(points, key=lambda student: student[0])
minimum=n+1
index=-1
for i in range(n):
  if points[i][1]<minimum:
    minimum=points[i][1]
    index=i
  else:
    uf.union(points[index][2],points[i][2])
maximum=0
index=-1
for i in range(n-1,-1,-1):
  if points[i][1]>maximum:
    maximum=points[i][1]
    index=i
  else:
    uf.union(points[index][2],points[i][2])
points=sorted(points, key=lambda student: student[1])
minimum=n+1
index=-1
for i in range(n):
  if points[i][0]<minimum:
    minimum=points[i][0]
    index=i
  else:
    uf.union(points[index][2],points[i][2])
maximum=0
index=-1
for i in range(n-1,-1,-1):
  if points[i][0]>maximum:
    maximum=points[i][0]
    index=i
  else:
    uf.union(points[index][2],points[i][2])
for i in range(n):
  print(uf.size(i))

Measured memory_bytes: 124412