akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename F>
struct FixPoint : F{
  FixPoint(F&& f):F(forward<F>(f)){}
  template<typename... Args>
  decltype(auto) operator()(Args&&... args) const{
    return F::operator()(*this,forward<Args>(args)...);
  }
};
template<typename F>
inline decltype(auto) MFP(F&& f){
  return FixPoint<F>{forward<F>(f)};
}

//INSERT ABOVE HERE
signed main(){
  int m,n;
  while(cin>>m>>n,m){
    vector<string> ss(n);
    for(int i=0;i<n;i++) cin>>ss[i];

    auto check=
      [&](int ask,int ans){
        int cnt=0;
        for(string s:ss){
          int flg=1;
          for(int j=0;j<m;j++)
            if((ask>>j)&1)
              flg&=(s[j]-'0')==((ans>>j)&1);
          if(flg) cnt++;
        }
        return cnt<=1;
      };

    int s=1<<m;
    vector<int> dp(s*s,-1);
    MFP([&](auto dfs,int ask,int ans)->int{
          int &res=dp[ask*s+ans];
          if(~res) return res;
          if(check(ask,ans)) return res=0;
          res=m+1;
          for(int j=0;j<m;j++){
            if((ask>>j)&1) continue;
            chmin(res,max(dfs(ask|(1<<j),ans|(0<<j)),
                          dfs(ask|(1<<j),ans|(1<<j)))+1);
          }
          return res;
        })(0,0);

    cout<<dp[0]<<endl;
  }
  return 0;
}



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

int main(){
    int N, D;
    cin >> N >> D;
    vector<vector<int>> v(N, vector<int>(D));
    for(int i = 0; i < N; i++){
        for(int j = 0; j < D; j++){
            cin >> v.at(i).at(j);
        }
    }
    int cnt;
    for(int i = 0; i < N; i++){
        for(int j = i+1; j < N; j++){
            int buf1 = 0;
            for(int k = 0; k < D; k++){
                int buf2 = 0;
                buf2 = v.at(i).at(k) - v.at(j).at(k);
                buf1 += buf2 * buf2;
            }
            for(int k = 0; k <= buf1; k++){
                if(buf1 == k * k){
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
}

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


int solve(vector<int> a) {
    int ptr = 0;
    int cnt = 0;
    rep (i, n) {
        ptr = a[ptr]; cnt++;
        if (ptr == 1) return cnt;
    }
    return -1;
}


int main() {
    cin >> n;
    vector<int> a(n); rep(i, n) cin >> a[i];
    rep (i, n) --a[i];
    cout << solve(a) << endl;
    return 0;
}

Measured memory_bytes: 1024
N, M, K = map(int, input().split())
MOD = 998244353
ans = 0

def calc(n, m):
    return (m * pow(m-1, n-1, MOD)) % MOD

C, ans = 1, calc(N, M)
for k in range(1, K+1):
    C = ((C * (N - k)) % MOD * pow(k, MOD-2, MOD)) % MOD
    ans = (ans + (C * calc(N-k, M)) % MOD) % MOD

print(ans)

Measured memory_bytes: 9208
#include <stdio.h>


int main(){
	int N;
	unsigned long int A[100000];
	scanf("%d",&N);
	int i;
	int odd=0,even=0;
	for(i=0;i<N;i++){
		scanf("%lu",&A[i]);
		A[i]=A[i]%2;
		if(A[i]==0)
			even++;
		else
			odd++;
	}
	even+=odd/2;
	odd=odd%2;
	if(odd==0 || (odd==1 && even==0))
		printf("YES\n");
	else
		printf("NO\n");
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> pippi;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<61;
int iinf=1<<30;
double pi=3.14159265358979323846;
double pi2=pi/2.0;
double eps=1e-8;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
//#define endl "\n"
int dh[4]={1,0,-1,0};
int dw[4]={0,1,0,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<int,int,custom_hash>
ll gcd(ll a,ll b){
    if(a<0)a=-a;
    if(b<0)b=-b;
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    if(k<0)return 0;
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,k;cin>>n>>k;
    int a[n];
    rep(i,0,n)cin>>a[i];
    rep(i,k,n){
        if(a[i]>a[i-k])cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}


Measured memory_bytes: 4420
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main{

  public static void main(String[] args) throws FileNotFoundException {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);
    int[] res = new int[4];
    res[0] = cin.nextInt();
    res[1] = cin.nextInt();
    res[2] = cin.nextInt();
    res[3] = cin.nextInt();

    Arrays.sort(res);

    if (res[0]!=1) {
      System.out.println("NO");
      return;
    }
    if (res[1]!=4) {
      System.out.println("NO");
      return;
    }
    if (res[2]!=7) {
      System.out.println("NO");
      return;
    }
    if (res[3]!=9) {
      System.out.println("NO");
      return;
    }

    System.out.println("YES");
    
  }

}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf=0x3f3f3f3f;
const int N=2e5+20;
int main()
{
	int n;
	while(cin>>n)
	{
		int cnt=0,x,odd=0,num=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&x);
			if(x%4==0)
				cnt++;
			if(x%2)
				odd++;
			if(x%4&&x%2==0)
				num++;
		}
		int res=cnt;
		if(num==0)
			res++;
		if(res<odd)
			puts("No");
		else
			puts("Yes");
	
	}
	return 0;
 
} 

Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

long N;
long Q;
std::vector<std::vector<long>> tree;
std::vector<long> value;
std::vector<long> total;
std::vector<int> arrived;

void rec(long curnode, long curval) {
	curval += value[curnode];
	total[curnode] = curval;
	arrived[curnode] = 1;

	for (auto child : tree[curnode]) {
		if (!arrived[child])
			rec(child, curval);
	}
}

int main()
{
	std::cin >> N >> Q;
	tree.resize(N);
	value.resize(N);
	total.resize(N);
	arrived.resize(N);
	for (long i = 0; i < N-1; ++i) {
		long a, b;
		std::cin >> a >> b;
		tree[a-1].push_back(b-1);
		tree[b-1].push_back(a-1);
	}
	for (long i = 0; i < Q; ++i) {
		long p, x;
		std::cin >> p >> x;
		value[p-1] += x;
	}

	rec(0, 0);

	for (long i = 0; i < total.size(); ++i) {
		std::cout << " ";
		std::cout << total[i];
	}
	std::cout << "\n";
}


Measured memory_bytes: 23424
class Stack
  attr_accessor :stack, :max, :top
  def initialize()
    @stack = []
    @max   = 1000
    @top   = 0
  end

  def isFull?()
    return true if @top == @max - 1

    return false
  end
  
  def isEmpty?()
    return true if @top == 0

    return false
  end
  
  def push(x)
    if isFull? then
      puts "stack is full!"
      return -1
    end
    stack[top] = x
    @top += 1
  end
  
  def pop()
    if isEmpty? then
      puts "stack is empty!"
      return -1
    end
    @top -= 1
    ret = stack[top]
    stack[top] = nil
    return ret
  end
end
  
line = gets.chop.split
stack = Stack.new
line.each do |s|
  if s == '+'
    a = stack.pop()
    b = stack.pop()
    stack.push(a + b)
  elsif s == '-'
    a = stack.pop()
    b = stack.pop()
    stack.push(b - a)
  elsif s == '*'
    a = stack.pop()
    b = stack.pop()
    stack.push(a * b)
  else
    stack.push(s.to_i)
  end
end

puts stack.pop()
  



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

int main()
{
	int N;
	vector < char > vec;
	cin >> N;
	for ( int i = 0; i < N; i++ ) {
		char c;
		cin >> c;
		vec.push_back(c);
	}
	sort(begin(vec), end(vec));
	vec.erase(unique(begin(vec), end(vec)), end(vec));

	if ( vec.size() == 3 ) {
		cout << "Three" << endl;
	} else {
		cout << "Four" << endl;
	}

	return ( 0 );
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,k,arr[100005];
int dp[100005];
int solve(int pos)
{
    if(pos == n){
        return 0;
    }
    if(dp[pos]!=-1){
        return dp[pos];
    }
    dp[pos] = 1e9+100;
    for(int i=1;i<=k;i++){
        if(pos+i<=n){
            dp[pos] = min(dp[pos] , solve(pos+i)+abs(arr[pos]-arr[pos+i]));
        }
    }
    return dp[pos];
}
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
        dp[i] = -1;
    }
    cout<<solve(1)<<endl;
    return 0;
}


Measured memory_bytes: 5760
n,d = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]

cnt =0
for i in range(n-1):
    for j in range(i+1,n):
        dist =0
        for k in range(d):
            dist += (x[i][k]-x[j][k])**2
        dist = dist**0.5
        if dist.is_integer():
            cnt+=1
print(cnt)


Measured memory_bytes: 9448
from sys import setrecursionlimit
setrecursionlimit(10**7)
s,t=input(),input()
dp=[[0]*(len(t)+1) for i in range(len(s)+1)]
for i in range(len(s)+1):
    for j in range(len(t)+1):
        if i<len(s):
            dp[i+1][j]=max(dp[i+1][j],dp[i][j])
        if j<len(t):
            dp[i][j+1]=max(dp[i][j+1],dp[i][j])
        if i<len(s) and j<len(t):
            dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+(s[i]==t[j]))
ans=""
def move(i,j):
    global dp,ans
    if i==0 or j==0:
        return
    elif dp[i][j]>dp[i-1][j-1] and s[i-1]==t[j-1]:
        ans=s[i-1]+ans
        move(i-1,j-1)
    else:
        if dp[i][j]==dp[i][j-1]:
            move(i,j-1)
        else:
            move(i-1,j)
move(len(s),len(t))
print(ans)

Measured memory_bytes: 148140
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <utility>
#include <vector>
using namespace std;

vector<int> ant;

int main() {
#ifdef HOME
	freopen("agc01d.in", "r", stdin);
	freopen("agc01d.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n, m, odd(0);

	vector<int> v;
	cin >> n >> m;
	v.resize(m);
	for (auto &i: v) {
		cin >> i;
		if (i % 2)
			odd+= 1; }

	if (odd > 2) {
		cout << "Impossible\n";
		return 0; }

	ant.reserve(n);

	partition(begin(v), end(v), [&](const int &x) { return x % 2; });
	partition(begin(v) + 1, end(v), [&](const int &x) { return 1 - x % 2; });

	ant.push_back(v[0] - 1);
	n-= v[0] - 1;
	for (int i = 1; i < m; ++i) {
		ant.push_back(v[i]);
		n-= v[i]; }

	if (n > 0) {
		if (v.back() == 1 || m != 1)
			ant.back()+= n;
		else
			ant.push_back(n); }

	ant.erase(remove(begin(ant), end(ant), 0), end(ant));

	for  (auto i: v)
		cout << i << ' ';
	cout << '\n' << ant.size() << '\n';
	for (auto i: ant)
		cout << i << ' ';
	cout << endl;

	return 0; }



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
using namespace std;
#define i64  long long
#define lint long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define MOD_Q 1e9 + 7
#define MOD_A 998244353

 #define int long long



void solve()
{
 
  int N;
  cin>>N;
  vector<int> X(N,0);
  for (int i = 0; i < N; i++)
  {
    cin>>X[i];
  }

  int A = 0;
  //first
  for (int i = 0; i < N; i++)
  {
    if(i%2 == 0)
    {
      A += X[i];
    }
    else
    {
      A -=X[i];
    }
  }

  vector<int> Ans(N,0);
  Ans[0] = A;

  for (int i = 1; i < N; i++)
  {
    Ans[i] = 2*X[i-1] -A;
    A = Ans[i];
  }
  
  
  for (int i = 0; i < N; i++)
  {
    cout<<Ans[i]<<" ";
  }
  cout<<endl;
  
  
  return;
}
 
int32_t main(int32_t argc, const char *argv[])
{
 
  solve();
 
  return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<int> x(N);
    vector<int> y(N);

    vector<int> ar(N);
    rep(i,N)ar[i] = i;

    rep(i,N)cin >> x[i] >> y[i];

    double ans = 0;
    int now;
    do{
        double tmp = 0;
        for(int i = 0;i < N;i++){
            if(i == 0){
                now = ar[0];
                continue;
            }
            double a = x[now] - x[ar[i]];
            double b = y[now] - y[ar[i]];
            double t = sqrt(a*a + b*b);
            tmp += t;
            now = ar[i];
        }
        ans += tmp;
    }while(next_permutation(all(ar)));

    double bun = 1;
    for(int i = 1;i<=N;i++)bun *= i;

    ans = (double)(ans / bun);

    cout << std::fixed << std::setprecision(15) << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    unsigned long long int n, k;
    scanf("%lld %lld", &n, &k);
    unsigned long long int a, b;
    if (k % 2 == 1)
    {
        a = n / k;
        printf("%lld\n", a*a*a);
    }
    else
    {
        a = n / k;
        b = a;
        if ((n%k) >= (k / 2))
            b++;
        printf("%lld\n", a*a*a + b * b*b);
    }
    return 0;
}

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

    using namespace std;

    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        long long n;
        cin>>n;
        int m;
        cin>>m;
        long long sum=0;
        for(int i=0;i<m;i++){
            int k;
            cin>>k;
            sum+=k;
        }
        if(sum<=n)
            cout<<n-sum;
        else
            cout<<-1;
        return 0;
    }


Measured memory_bytes: 3656
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

A,B = map(int,read().split())

MOD = 10 ** 9 + 7

U = 2001
comb = np.zeros((U,U),np.int64)
comb[0,0] = 1
for n in range(1,U):
    comb[n,0:n] += comb[n-1,0:n]
    comb[n,1:n+1] += comb[n-1,0:n]
    comb[n,:n+1] %= MOD

comb_cum = comb.cumsum(axis=1)

# (1,s) しか使えない場合. (青、赤) -> 数え上げ
S = np.zeros((U,U),np.int64)
S[0,:] = 1
S[1:,:] = comb_cum[:-1].cumsum(axis=1) % MOD

x = 0
for k in range(A+1):
    x += comb[B-1,k] * (S[k,:A-k+1].sum() % MOD) % MOD
x %= MOD
print(x)

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

using namespace std;

#define F 		first
#define S 		second
#define ll 		long long
#define ld 		long double
#define pii		pair<int, int>
#define vi 		vector<int>
#define mii 	map<int, int>
#define umii 	unordered_map<int, int>
#define pb		push_back
#define mk		make_pair
#define all(a)	a.begin(), a.end()
#define ask(x) 	cerr << #x << " = " << x << "\n";
#define INF 	1000000007
#define hell 	998244353

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

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int a, b, h, m;

	cin >> a >> b >> h >> m;

	double ah = h * 30, am = 6 * m;
	ah += m * 0.5;

	double x1, y1, x2, y2;

	double rah = ah * 2 * acos(0.0) / 180.0;
	double ram = am * 2 * acos(0.0) / 180.0;

	x1 = (double)a * sin(rah), y1 = (double)a * cos(rah);
	x2 = (double)b * sin(ram), y2 = (double)b * cos(ram);

	// cout << fixed << setprecision(12) << x1 << ' ' << y1 << '\n' << x2 << ' ' << y2 << '\n';

	double d = sqrt(((y2 - y1) * (y2 - y1)) + ((x2 - x1) * (x2 - x1)));

	cout << fixed << setprecision(12) << d;

	return 0;
}

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

vector<int>E[100000];
int a[100000], b[100000];
int ans[100000];

void dfs(int v, int p, int d) {
	for (int u : E[v]) {
		if (u == p)continue;
		dfs(u, v, d ^ 1);
		a[v] = max(a[v], a[u] - 1);
		b[v] = min(b[v], b[u] + 1);
	}
	if (a[v] % 2 != d)a[v]++;
	if (b[v] % 2 != d)b[v]--;
	if (a[v] > b[v]) {
		puts("No"); exit(0);
	}
}
void dfs2(int v, int p) {
	for (int u : E[v]) {
		if (u == p)continue;
		if (a[u] <= ans[v] + 1 && ans[v] + 1 <= b[u]) {
			ans[u] = ans[v] + 1; dfs2(u, v);
		}
		else {
			ans[u] = ans[v] - 1; dfs2(u, v);
		}
	}
}
int main() {
	int n; scanf("%d", &n);
	rep(i, n - 1) {
		int u, v; scanf("%d%d", &u, &v); u--; v--;
		E[u].push_back(v); E[v].push_back(u);
	}
	int k; scanf("%d", &k);
	rep(i, n)a[i] = INT_MIN + 1, b[i] = INT_MAX - 1;
	int s;
	rep(i, k) {
		int v, p; scanf("%d%d", &v, &p); v--;
		a[v] = b[v] = p;
		s = v;
	}
	dfs(s, -1, a[s] % 2);
	ans[s] = a[s];
	dfs2(s, -1);
	puts("Yes");
	rep(i, n)printf("%d\n", ans[i]);
}

Measured memory_bytes: 15360
// D - Dice in Line.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;

int main()
{
	int N, K;
	double m = 0.0, e = 0.0;
	cin >> N >> K;
	vector<int> p(N);
	for (int i = 0; i < N; i++) {
		cin >> p[i];
	}
	for (int s = 0; s < N; s++) {	//s -> start index
		if (s < K) {
			e += p[s];
		}else {
			e = e - p[s - K] + p[s];
		}
		if (m < e) {
			m = e;
		}
	}
	m += K;
	m *= 0.5;
	cout << fixed << setprecision(10);
	cout << m << endl;
}


Measured memory_bytes: 1024
from collections import deque

N = int(input())
T = [{} for i in range(N+1)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    T[a][b] = c
    T[b][a] = c

Q, K = map(int, input().split())
shortest_path = [0 for _ in range(N+1)]
queue = deque([[v, T[K][v], K] for v in T[K].keys()])
for _ in range(N-1):
    v = queue.popleft()
    shortest_path[v[0]] = v[1]
    queue.extend([[u, T[v[0]][u] + v[1], v[0]] for u in T[v[0]].keys() if u != v[2]])

for _ in range(Q):
    x, y = map(int, input().split())
    print(shortest_path[x] + shortest_path[y])

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

using namespace std;

int main() {
  int a;
  cin >> a;
  
  if (a % 10 == 2 || a % 10 == 4 || a % 10 == 5 || a % 10 == 7 || a % 10 == 9) {
    cout << "hon\n";
  } else if (a % 10 == 3) {
    cout << "bon\n";
  } else {
    cout << "pon\n";
  }
  
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <thread>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

static const int kMaxV = 100000;

struct Record {
	int v;
	int c;
};

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

	vector<Record> count_as(kMaxV + 1);
	vector<Record> count_bs(kMaxV + 1);
	FOR_LE(i, 0, kMaxV) {
		count_as[i].v = i;
		count_bs[i].v = i;
	}

	FOR_LT(i, 0, n) {
		int v; cin >> v;
		if (i & 1) count_as[v].c++;
		else       count_bs[v].c++;
	}

	auto pred = [](const Record & lhs, const Record & rhs) {
		return lhs.c > rhs.c;
	};

	sort(count_as.begin(), count_as.end(), pred);
	sort(count_bs.begin(), count_bs.end(), pred);

	if (count_as.front().v != count_bs.front().v) {
		int ans = n - count_as.front().c - count_bs.front().c;
		cout << ans << endl;
	}
	else {
		int ans_a = n - (count_as.begin() + 1)->c - (count_bs.begin())->c;
		int ans_b = n - (count_as.begin())->c - (count_bs.begin() + 1)->c;
		cout << min(ans_a, ans_b) << endl;
	}

	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define LL long long
#define dl double
template <class T>
void rd(T &x){
  x=0;T f=1;char ch=getchar();
  while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
  while(ch<='9' && ch>='0')x=x*10+ch-'0',ch=getchar();x*=f;
}

using namespace std;

int a,b,c,k;

int main(){
 // freopen("in.txt","r",stdin);
 // freopen("o.txt","w",stdout);
 rd(a);rd(b);rd(c);rd(k);
 while(b <= a)b*=2,k--;
 while(c <= b)c*=2,k--;
 if(k >= 0)printf("Yes\n");
 else printf("No\n");
 return 0;
}
/**/

Measured memory_bytes: 3628
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  N = int(readline())
  W = list(map(int, readline().split()))
  
  left = 0
  right = sum(W)
  ans = INF
  for i in range(N):
    left += W[i]
    right -= W[i]
    ans = min(ans, abs(left-right))
  print(ans)
  
if __name__ == '__main__':
  main()

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

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int x, n; cin >> x >> n;
	vector<int> num(n);
	rep(i,n){
		cin >> num[i];
	}
	int ans = 0;
	int tmp = 1001001001;
	for(int i = 0; i <= 101; i++){
		bool ok = true;
		rep(j, n){
			if(i == num[j]) ok = false;
		}
		if(ok){
			if(abs(i-x) < tmp) ans = i;
			tmp = abs(i-x);
		}
	}
	cout << ans << endl;
} 

Measured memory_bytes: 3656
// 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>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll n;
  cin >> n;
  ll ga,gb,sa,sb,ba,bb;
  cin >> ga >> sa >> ba >> gb >> sb >> bb;
  vector<ll> dp(n+1,0);
  dp[0] = n;
  for(int i=1;i<=n;i++){
    dp[i]=dp[i-1];
    if(i-ga>=0){
      dp[i] = max(dp[i-ga]+gb-ga,dp[i]);
    }
    if(i-sa>=0){
      dp[i] = max(dp[i-sa]+sb-sa,dp[i]);
    }
    if(i-ba>=0){
      dp[i] = max(dp[i-ba]+bb-ba,dp[i]);
    }
  }
  ll m = dp[n];
  vector<ll> dp2(m+1,0);
  dp2[0] = m;
  for(int i=1;i<=m;i++){
    dp2[i] = dp2[i-1];
    if(i-gb>=0){
      dp2[i] = max(dp2[i-gb]+ga-gb,dp2[i]);
    }
    if(i-sb>=0){
      dp2[i] = max(dp2[i-sb]+sa-sb,dp2[i]);
    }
    if(i-bb>=0){
      dp2[i] = max(dp2[i-bb]+ba-bb,dp2[i]);
    }
  }
  cout << dp2[m]<<endl;
}


Measured memory_bytes: 195584
import itertools
s = list(input())
n = len(s)

ans = 0
if n == 1:
	ans = int(s[0])
else:
	for x in itertools.product(["", "+"], repeat = n - 1):
		tmp = ""
		for i in range(n - 1):
			tmp += s[i] + x[i]
		tmp += s[-1]
		ans += eval(tmp)
print(ans)


Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(i=a;i<b;i++)
using namespace std;
 
int n,k,ar[105],dp[100005][2],mn;

int fun(int rem, int x)
{
    int i;
    if(rem<mn)
        return dp[rem][x] = x^1;
    if(dp[rem][x]!=-1)
        return dp[rem][x];

    dp[rem][x]=x^1;

    f(i,0,n)
    {
    	if(ar[i] <= rem){
    		if(x)
        		dp[rem][x] |= fun(rem-ar[i],x^1);
        	else
        		dp[rem][x] &= fun(rem-ar[i],x^1);
   		}
    }
    return dp[rem][x];
}

int main()
{
    fast;
    int i;
    cin>>n>>k;
    f(i,0,n)
        cin>>ar[i];
    mn=*min_element(ar,ar+n);
    memset(dp,-1,sizeof(dp));
    (fun(k,1))?cout<<"First":cout<<"Second";
}

Measured memory_bytes: 12228
// 2020-06-22 19:31:27
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

vector<int> a;
vector<vector<int> > G;
vector<int> dp, memo;
const int INF = 1e9+10;
void dfs(int u, int p) {
  auto itr = lower_bound(ALL(dp), a[u]);
  if(p == -1) {
    memo[u] = itr - dp.begin() + 1;
  } else {
    chmax(memo[u], max(memo[p], int(itr - dp.begin() + 1)));
  }
  int before = *itr;
  *itr = a[u];
  for(const int v : G[u]) if(v != p) {
    dfs(v, u);
  }
  *itr = before;
}
void answer() {
  int n;
  cin >> n;
  a.resize(n);
  G.resize(n);
  dp.assign(n+1, INF);
  memo.assign(n, -1);
  rep(i, n) cin >> a[i];
  rep(i, n-1) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(0, -1);
  rep(i, n) cout << memo[i] << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 27888
#include<bits/stdc++.h>
using namespace std;
 
#define int long long 
#define ll long long 
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define ff first
#define ss second
#define vi vector<ll>
#define vii vector<vector<ll>>
#define vpi vector<pii>
#define mod 1000000007
#define MOD 1000000007
#define full(a) a.begin(),a.end()
#define inf INT_MAX
#define minf INT_MIN
#define dd double
#define fori(x,n) for(ll i=x;i<n;i++)
#define modd 998244353
#define umap unordered_map<ll,ll>
#define mmap map<ll,ll>
#define mm 100000000


int32_t main() 
{ 
  
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif


    
    ll t;
    t=1;
    // cin>>t;
    while(t--){
      ll n;
      cin>>n;
      if(n%1000==0)cout<<0;
      else
      cout<<1000*(n/1000+1)-n;
 








      

       




     

    






      
  
    }





return 0;
}     



Measured memory_bytes: 3648
import java.util.*;
import java.math.*;

class Main{
public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   int n = sc.nextInt();
   long[] count = new long[200005];
   for(int i=0;i<200005;i++){
     count[i] = 0;
   }
   int[] a = new int[n];
   for(int i=0;i<n;i++) {     
   int t = sc.nextInt();
   a[i] = t;
   count[t] += 1;
            }
   long ret = 0;
   for(int i=0;i<200005;i++){
     ret += (long)count[i]*(count[i]-1);
   }
   ret /= 2;
   for(int i=0;i<n;i++) { 
   int t = a[i];
   long remove = (long)count[t]*(count[t]-1) - (long)(count[t]-1)*(count[t]-2);
   remove /= 2;
   System.out.println(ret-remove);
   }
}
}


Measured memory_bytes: 102136
#include<cstdio>
#include<map>
#define maxn 200005
using namespace std;
typedef pair<int,int> PII;
int n,k,l,fa[2][maxn],siz[maxn];
int find(int i,int x)
{
	if(fa[i][x]==x) return x;
	return fa[i][x]=find(i,fa[i][x]);
}
map<PII,int> mp;
int main()
{
	scanf("%d%d%d",&n,&k,&l);
	for(int i=1;i<=n;i++) fa[0][i]=fa[1][i]=i,siz[i]=1;
	while(k--)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		int r1=find(0,u),r2=find(0,v);
		if(r1!=r2) fa[0][r2]=r1;
	}
	while(l--)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		int r1=find(1,u),r2=find(1,v);
		if(r1!=r2) fa[1][r2]=r1;
	}
	for(int i=1;i<=n;i++)
	{
		int r1=find(0,i),r2=find(1,i);
		mp[PII(r1,r2)]++;
	}
	for(int i=1;i<=n;i++)
	{
		int r1=find(0,i),r2=find(1,i);
		printf("%d",mp[PII(r1,r2)]);
		if(i!=n) printf(" ");
	}
}

Measured memory_bytes: 14336
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
count = 0


def solve(K: int):

    def cDfs(prev, prevDigit, remainDigit):
        global count
        if remainDigit == 0:
            count += 1
            if count == K:
                print(prev)
                exit()
            # print(prev)
            return
        else:
            if prevDigit == 0:
                cDfs(prev*10, prevDigit, remainDigit-1)
                cDfs(prev*10+1, 1, remainDigit-1)
            elif prevDigit == 9:
                cDfs(prev*10+8, 8, remainDigit-1)
                cDfs(prev*10+9, prevDigit, remainDigit-1)
            else:
                a = (prevDigit+1) % 10
                b = (prevDigit-1) % 10
                MIN = min(a, b)
                MAX = max(a, b)
                cDfs(prev*10+MIN, MIN, remainDigit-1)
                cDfs(prev*10+prevDigit, prevDigit, remainDigit-1)
                cDfs(prev*10+MAX, MAX, remainDigit-1)
    for i in range(0, 100):
        for j in range(1, 10):
            cDfs(j, j, i)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;
long long n,a,b,ans;
int main(){
    cin >> n >> a >> b;
    long long t = n / (a+b), r = n % (a+b);
    ans = t * a + min(a,r);
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
// 5/20
// ANT2-4-3. Union Find Tree, 食物連鎖
// 類題
// あり本の意図通り、重みつきUnion Findで解いてみる。
#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>;
using LLP = pair<ll, ll>;

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        // SUM_UNITYはAbelの単位元として、diff_weight[i]の初期値として使う。
        // 整数以外を使う場合は個別に単位元を定義する。
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        // xのrootを求めるとともに、重みを保持したまま経路圧縮を行う。
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);  // 経路圧縮をしている。
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        // ルート同士をつなぐので、x, yそれぞれのルートとの距離を引く。
        // ここで、wは y - x の距離。
        // xのルートの下にyのルートを繋げる想定なので、そのためまずx側の重み分足して、
        // その後に、y側の重み分減らしている。
        // もしrank的にyのルート下に繋げる場合は、wを正負反転する。
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);

        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        // なおy側の子供たちのdiffをアップデートする必要はない。
        // 次の経路圧縮のタイミングで更新される。なるほど。
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

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

    UnionFind<int> uf(N);

    vector<int> L(M), R(M), D(M);
    rep(i, M) {
        cin >> L[i] >> R[i] >> D[i];
        L[i]--;
        R[i]--;
    }

    rep(i, M) {
        int l, r, d;
        l = L[i];
        r = R[i];
        d = D[i];

        if (uf.issame(l, r)) {
            if (d != uf.diff(l, r)) {
                cout << "No" << endl;
                return 0;
            }
        } else {
            uf.merge(l, r, d);
        }
    }

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


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

using namespace std;

const int N = 301;
const int INF = (1<<28);

struct edge { int to, cap, rev; };

vector<edge> G[N];
bool used[N];
vector<pair<int, int> > data;

void add_edge(int from, int to, int cap){
  G[from].push_back((edge){to, cap, G[to].size()});
  G[to].push_back((edge){from, cap, (int)G[from].size()-1});
}

int dfs(int v, int t, int f){
  if(v == t) return f;
  used[v] = true;
  for(int i=0;i<G[v].size();i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0){
      int d = dfs(e.to, t, min(f, e.cap));
      if(d > 0){
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s, int t){
  int flow = 0;
  while(1){
    fill(used, used+N, false);
    int f = dfs(s, t, INF);
    if(f == 0) return flow;
    flow += f;
  }
}

void solve(int n, int m, int s, int t){
  cout << max_flow(s, t) << endl;
  vector<int> ans;
  for(int i=0;i<m;i++){
    for(int j=0;j<G[data[i].second].size();j++){
      if(G[data[i].second][j].to == data[i].first && G[data[i].second][j].cap == 0){
        ans.push_back(i+1);
        break;
      }
    }
  }
  cout << ans.size() << endl;
  for(int i=0;i<ans.size();i++) cout << ans[i] << endl;
}

main(){
  int n, m, s, t;
  cin >> n >> m;
  for(int i=0;i<m;i++){
    int a, b;
    cin >> a >> b;
    add_edge(a, b, 1);
    data.push_back(make_pair(a, b));
  }
  cin >> s >> t;
  solve(n, m, s, t);
}

Measured memory_bytes: 1296
def c_grand_garden(N, H):
    ans = min(H)
    for k in range(N):
        H[k] -= ans
    H.append(0)
    for k in range(N):
        if H[k] > H[k + 1]:
            ans += H[k] - H[k + 1]
    return ans

N = int(input())
H = [int(i) for i in input().split()]
print(c_grand_garden(N, H))

Measured memory_bytes: 3060
fun main(args:Array<String>) {
    val abc = (1..3).map { readLine()!!.toInt() }
    val x = readLine()!!.toInt()
    val ans = getAns(0, abc, x)
    println(ans)
}


fun getAns(index:Int, coins:List<Int>, remain:Int):Long {
    if(remain == 0) {
        return 1
    }
    if(remain < 0) {
        return 0
    }
    if(index >= coins.size) {
        return 0
    }
    val coinKind = listOf(500,100,50)
    var ret = 0L
    for(i in (0..coins[index])) {
        val subList = mutableListOf<Int>()
        subList.addAll(coins)
        subList[index] -= i
        ret += getAns(index + 1, subList, remain - (coinKind[index]*i) )
    }
    return ret
}

Measured memory_bytes: 53176
#include <stdio.h>
#include <string.h>


int main()
{
  int i, j;
  char t[1003], p[1003];
  fgets(t, 1002, stdin);
  fgets(p, 1002, stdin);

  if (p[strlen(p)-1]=='\n') p[strlen(p)-1]='\0';

  int n = strlen(t)-1;
  int m = strlen(p);
  int qt[128];
  for (int i=0; i<128; i++) qt[i] = m+1;
  for (int i=0; i<m; i++) {
    qt[(int)p[i]] = m-i;
  }

  i=0;
  while (i<=n-m) {
    for (j=0; j<m; j++) {
      if (t[i+j] != p[j]) break;
    }
    if (j==m)
      printf("%d\n", i);

    i += qt[(int)t[i+m]];
  }
  return 0;
}



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

using ll = long long;

using namespace std;
#define MAX_N 100010

using P = pair<int, int>;
#define fi first
#define se second

int n, taka, aoki;
vector<P> G[100010];

// 各点への最短経路 dijkstra
int ad[MAX_N], td[MAX_N];  //頂点kから各点への距離
void dijkstra(int k, int *d) { //Gは隣接行列 G[i][j].firstが距離, secondが向かう頂点名, kはスタートする頂点
    fill(d, d+n, MAX_N); d[k] = 0;
    priority_queue< P, vector<P>, greater<P> > que;
    que.push(P(0, k));
    while (!que.empty()) {
        P p = que.top(); que.pop();
        int now = p.second;
        if (d[now] < p.first) continue;
        for (auto g:G[now]) {
            int to = g.second;
            long newd = g.first + d[now];
            if (d[to] > newd) {
                d[to] = newd;
                que.push(P(d[to], to));
            }
        }
    }
}


int main() {
    cin >> n >> taka >> aoki;
    taka--; aoki--;
    for (int i=0, a, b; i<n-1; i++) {
        cin >> a >> b;
        a--; b--;
        G[a].push_back({1, b});
        G[b].push_back({1, a});
    }
    dijkstra(aoki, ad);
    dijkstra(taka, td);
    int ans = 0;
    for (int i=0; i<n; i++) {
        if (td[i] <= ad[i]) {
            ans = max(ad[i], ans);
        }
    }
    cout << ans - 1 << '\n';
    return 0;
}

Measured memory_bytes: 7948
#include <bits/stdc++.h>
#define ll long long

#define INF 999999999

using namespace std;

// input
int h,w;
vector<string> field;

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

    string row;
    for(int i = 0; i < w+2;i++) cout << "#";
    cout << "\n";
    while(cin >> row){
        cout << "#";
        cout << row;
        cout << "#\n";
    }
    for(int i = 0; i < w+2;i++) cout << "#";
    cout << "\n";
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

int main(){
  ll i, j;
  ll n;
  cin >> n;
  if(n < 105)
  cout << 0 << endl;
  else if(n < 135)
  cout << 1 << endl;
  else if(n < 165)
    cout << 2 << endl;
  else if(n < 189)
    cout << 3 << endl;
  else if(n < 195)
    cout << 4 << endl;
  else 
    cout << 5 << endl;
    

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const int MAX_N = (int)1e5 + 5;

int a[MAX_N];

int main()
{
	memset(a, 0, sizeof(a));
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int N; cin >> N;
	rep (i, N) cin >> a[i], --a[i];

	int res = 0;
	rep (i, N){
		int j = a[i];	// i番目のウサギが好きな相手
		int k = a[j]; // j番目のウサギが好きな相手
		res += (i == k);
	} // end rep

	res /= 2;
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 640
N = int(input())
S = []
for i in range(N):
    S.append(input())
count_ac = 0
count_wa = 0
count_re = 0
count_tle = 0
    
for j in range(N):
    if S[j] == "AC":
        count_ac += 1
    elif S[j] == "WA":
        count_wa += 1
    elif S[j] == "TLE":
        count_tle += 1
    elif S[j] == "RE":
        count_re += 1
print("AC x {0}".format(count_ac))
print("WA x {0}".format(count_wa))
print("TLE x {0}".format(count_tle))
print("RE x {0}".format(count_re))

Measured memory_bytes: 79072
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int N=s.size();
  int sumo=0;
  bool OK=false;
  if(N<8){
    OK=true;
  }
  else{
    for(int i=0;i<N;i++){
      if(s[i]=='x'){
        sumo++;
      }
    }
  }
    if(15-sumo>7) OK=true;
    if(OK) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")

typedef long long ll;
typedef unsigned long long ull;
#define fatnet ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

const ll MOD = 1e9 + 7;
const ll MOD1 = 1e9 + 7;
const ll MOD2 = 2000003983;
const ll MOD3 = 1e9 + 9;
const ll p1 = 1e6 + 3;
const ll p2 = 2017;
const ll p3 = 37;
const ll INF = 5e18;

int main() {
    fatnet;

    ll n;
    cin >> n;
    vector < ll > a(n + 1, 0), b(n + 1, 0), c(n + 1, 0);
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    for (int i = 1; i <= n; ++i)
        cin >> b[i];
    for (int i = 1; i < n; ++i)
        cin >> c[i];
    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans += b[a[i]];
        if (i > 1) {
            if (a[i - 1] == a[i] - 1)
                ans += c[a[i - 1]];
        }
    }
    cout << ans << "\n";

    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

vpll sieve(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  int a,b;
  cin >> a >> b;
  int x=b-a;
  int ans=x*(x-1)/2-a;
  cout << ans << endl;
  return 0;
}


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

template<class Monoid> struct SegmentTree {
    using func = function<Monoid(Monoid, Monoid)>;
    int n;
    Monoid ie;
    func f;
    vector<Monoid> node;

    SegmentTree(){};
    SegmentTree(int n, Monoid ie, func f) : n(n), ie(ie), f(f) {
        const int cn = n;
        n = 1; while(n < cn)  n *= 2;
        node.assign(2*n, ie);
    }

    void update(int i, Monoid x) {
        i += n;
        node[i] = x;
        while(i /= 2)  node[i] = f(node[2*i], node[2*i+1]);
    }

    // [l, r)
    Monoid query(int l, int r) {
        l = max(l, 0);  r = min(n, r);
        if(l >= r)  return ie;

        Monoid res = ie;
        for(l += n, r += n; l != r; l /= 2, r /= 2) {
            if(l % 2)  res = f(res, node[l++]);
            if(r % 2)  res = f(res, node[--r]);
        }
        return res;
    }

    Monoid operator[](int i) {
        assert(0 <= i && i < n);
        return node[i+n];
    }
};

int main() {
    lint n, m, v, p;
    cin >> n >> m >> v >> p;

    vector<lint> a(n);
    for(lint i=0; i<n; i++)  cin >> a[i];

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

    map<lint, lint> mp;
    for(auto e : a)  mp[e]++;

    reverse(begin(a), end(a));
    lint bottom = a[p-1];
    lint bottom_cnt = mp[bottom];
    reverse(begin(a), end(a));

    SegmentTree<lint> seg(n, 0LL, plus<lint>());
    for(lint i=0; i<n; i++) {
        seg.update(i, a[i]);
    }

    lint ans = 0;
    for(lint i=0; i<n; i++) {
        if(a[i] >= bottom) {
            ans++;
            continue;
        }

        lint left = upper_bound(begin(a), end(a), a[i]) - begin(a);
        lint right = upper_bound(begin(a), end(a), bottom) - begin(a);
        lint goal = a[i] + m;
        if(goal < bottom)  continue;

        lint need = goal * (right - left) - seg.query(left, right);
        lint nv = (right - left) * m - need;
        ans += (nv <= m * (n-v));
    }

    cout << ans << endl;
}

Measured memory_bytes: 9344
from itertools import tee


def pairwise(iterable):
    x, y = tee(iterable)
    next(y, None)
    return zip(x, y)


n = int(input())
b = tuple(map(int, input().split(" ")))

if len(b) == 1:
    print(2 * b[0])
else:
    s = b[0] + sum(min((i, j)) for i, j in pairwise(b)) + b[-1]
    print(s)


Measured memory_bytes: 3060
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <regex>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
const long long INF =  999999999;

ll N;
vector<ll> edge[100010];
bool used[100010];
ll d1[100010],d2[100010];

void bfs(ll u,ll (&d)[100010],vector<ll>& leaf ){
  queue<ll> que;
  fill(used,used+N+10,false);
  used[u]=true;
  d[u]=0;
  que.push(u);
  while(!que.empty()){
    ll s=que.front();que.pop();
    REP(i,edge[s].size()){
      ll t=edge[s][i];
      if(!used[t]){
        used[t]=true;
        d[t]=d[s]+1;
        que.push(t);
      }
    }
    if(edge[s].size()<=1)leaf.push_back(s);
  }
}

//d1が高橋、d2が青木
int main(){
  ll u,v;
  cin>>N>>u>>v;
  REP(i,N-1){
    ll a,b;
    cin>>a>>b;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  vector<ll> leaf;
  bfs(u,d1,leaf);
  bfs(v,d2,leaf);

  ll nige,dmax=-1;
  REP(i,leaf.size()){
    ll s=leaf[i];
    if(d1[s]<d2[s] && dmax<d2[s]){
      dmax=d2[s];
      nige=s;
    }
  }
  cout<<dmax-1<<endl;
}


Measured memory_bytes: 9844
import sys
sys.setrecursionlimit(10**6)

def main():
	n = int(input())
	s = input()

	dic = {}
	for i in range(0,2**n):
		temp = bin(i)[2:].zfill(n)
		ts1 = ""
		ts2 = ""
		for j in range(n):
			if temp[j] == "1":
				ts1 += s[j]
			else:
				ts2 += s[j]
		if (ts1, ts2) in dic.keys():
			dic[(ts1,ts2)] += 1
		else:
			dic.update({(ts1,ts2):1})
			
	ans = 0
	s = s[::-1]
	for i in range(0,2**n):
		temp = bin(i)[2:].zfill(n)
		ts1  =""
		ts2 = ""
		for j in range(n):
			if temp[j] == "1":
				ts1 += s[j]
			else:
				ts2 += s[j]
		if (ts1, ts2) in dic.keys():
			ans += dic[(ts1,ts2)]
	print(ans)

main()


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

void solve(){
    int a;
    cin>>a;
    int r = a%10;
    if(r==2 or r==4 or r==5 or r==7 or r==9) puts("hon");
    else if(r==0 or r==1 or r==6 or r==8) puts("pon");
    else if(r==3) puts("bon");
}

int main()
{

           solve();

    return 0; 
}


Measured memory_bytes: 3592
fun main(args: Array<String>) {
    val (n, m, c) = readLine()?.split(" ")?.map(String::toInt) ?: return
    val b = readLine()?.split(" ")?.map(String::toInt) ?: return
    0.until(n).count {
        val a = readLine()?.split(" ")?.map(String::toInt) ?: return
        a.foldIndexed(0, { i, t, aa ->
            t + (aa * b[i])
        }) + c > 0
    }.let {
        println(it.toString())
    }
}

Measured memory_bytes: 37816