akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
int t,n,a,b,c,d;
map<int,int> cc;
int chg(int x){
	if(x==0) return 0;
	if(x==1) return d;
	if(cc[x]) return cc[x];
	int res = 1e18;
	if(x<res/d) res = x*d;
	res = min(res,chg(x/2) + (x%2)*d + a);
	if(x>2&&x%2)res = min(res,chg(x/2+1) + (2 - x%2) * d + a);
	if(x%3<2)res = min(res,chg(x/3) + (x%3)*d + b);
	if(x%3>1&&x>1)res = min(res,chg(x/3+1) + (3 - x%3) * d + b);
	if(x%5<3)res = min(res,chg(x/5) + (x%5)*d + c);
	if(x%5>2&&x>1)res = min(res,chg(x/5+1) + (5 - x%5) * d + c);
	cc[x] = res;
	return res;
}
signed main(){
	scanf("%lld",&t);
	while(t--){
		cc.clear();
		scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
		printf("%lld\n",chg(n));
	}
	return 0;
}

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

using namespace std;

int main(){
    int x,y;
    scanf("%d %d",&x,&y);
    if(x==2||y==2)  printf("No");
    else if(x==1||x==3){
        if(y==4||y==6||y==9||y==11)    printf("No");
        else    printf("Yes");
    }
    else if(x==4){
        if(y==6||y==9||y==11)   printf("Yes");
        else    printf("No");
    }
    else if(x==5){
        if(y==6||y==9||y==11)   printf("No");
        else    printf("Yes");
    }
    else if(x==6){
        if(y==9||y==11)   printf("Yes");
        else    printf("No");
    }
    else if(x==7||x==8){
        if(y==9||y==11)   printf("No");
        else    printf("Yes");
    }
    else if(x==9){
        if(y==11)   printf("Yes");
        else    printf("No");
    }
    else if(x==10){
        if(y==12)   printf("Yes");
        else    printf("No");
    }
    else if(x==11){
        if(y==12)   printf("No");
        else    printf("Yes");
    }

    return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

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

void Main()
{
	int n; 
  	cin >> n;
  	vector<double> a(n);
  	double sum = 0;
  	rep(i,n) {
		cin >> a[i];
    	sum += 1.0/a[i];
    }
	cout << 1.0/sum << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl

#define rep(i, n) REP(i, 0, n)                  // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for(auto &(x) : (a))

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

using Graph = vector<vector<int>>;

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

    int n;
    cin >> n;
    Graph G(n);
    rep(i, n) {
        int u, k;
        cin >> u >> k;
        u--;
        rep(j, k) {
            int v;
            cin >> v;
            v--;
            G[u].push_back(v);
        }
    }

    vector<int> dist(n, -1);
    queue<int> que;

    dist[0] = 0;
    que.push(0);

    while(!que.empty()) {
        int v = que.front();
        que.pop();

        for(auto nv : G[v]) {
            if(dist[nv] != -1) continue;
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }

    rep(i, n) { cout << i + 1 << " " << dist[i] << endl; }
}



Measured memory_bytes: 3208
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

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

  if (a == "H") {
    if (b == "H")
      cout << "H" << endl;
    else
      cout << "D" << endl;
  }

  else if (a == "D") {
    if (b == "H")
      cout << "D" << endl;
    else
      cout << "H" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
mod = 10**9+7
N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
dp = [0]*(1<<N)
dp[0] = 1
def bitcount(i): # i < 2^32
    i = i - ((i >> 1) & 0x55555555)
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
    return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24
for s in range(1, 1<<N):
    women = []
    m = bitcount(s)-1
    for w in range(N):
        if a[m][w] == 1 and s&1<<w:
            dp[s]+=dp[s^(1<<w)]
            dp[s]%=mod
print(dp[-1])

Measured memory_bytes: 58716
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #n,m,k=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    n=int(readline())
    ans=""
    for _ in range(n):
        ans+="ACL"
    print(ans)
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 16124
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
template <class X> void print(X x) { cout << x << endl; }
#define in(A, n)                                                                                                       \
    rep(i, n) {                                                                                                        \
        cin >> f;                                                                                                      \
        A.push_back(f);                                                                                                \
    }

void print(vl x) {
    for(ll i : x) {
        cout << i << " ";
    }
    cout << endl;
}
const ll INF = (1LL << 61) - 1;
const ll MOD = 1000000007 /*998244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, i, j, u, v, m;
ll codeforces = 1;
string S, T;
vector<vl> g(MAX_N);
vl A, B;
void input() { cin >> n; }
void solve() {
    rep(i, n) {
        a = i + 1;
        ans += (n - 1) / a;
    }
    print(ans);
}
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    while(codeforces--) {
        solve();
    }
}

Measured memory_bytes: 15088
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 2005
using namespace std;
int n,k,cnt1,cnt2;
int sum1[maxn][maxn],sum2[maxn][maxn];
char s[10];
int getsum(int x,int y,int sum[][maxn])
{
//	int temp1=(x+k+k-1)-(2*k),temp2=(y+k+k-1)-(2*k);

	int res1=(sum[x+k-1][y+k-1]-sum[x+k-1][y-1]-sum[x-1][y+k-1]+sum[x-1][y-1]);
	int res2=(sum[x-1][y-1]);
	int res3=(sum[x-1][2*k-1]-sum[x-1][y+k-1]);
	int res4=(sum[2*k-1][y-1]-sum[x+k-1][y-1]);
	int res5=(sum[2*k-1][2*k-1]+sum[x+k-1][y+k-1]-sum[2*k-1][y+k-1]-sum[x+k-1][2*k-1]);

	return res1+res2+res3+res4+res5;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		int x,y;
		scanf("%d%d%s",&x,&y,s);
		if(s[0]=='B')
		{
			cnt1++;
			x%=(2*k);
			y%=(2*k);
			sum1[x][y]++;
		}
		if(s[0]=='W')
		{
			cnt2++;
			x%=2*k;
			y%=2*k;
			sum2[x][y]++;
		}
//		cerr<<"its "<<x<<" "<<y<<endl;
	}

//	cerr<<"+1"<<endl;

	int nn=n;
	n=2*k;

	for(int i=1;i<=n;i++)
		sum1[0][i]+=sum1[0][i-1];

	for(int j=1;j<=n;j++)
		sum1[j][0]+=sum1[j-1][0];

	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			sum1[i][j]=(sum1[i][j]+sum1[i-1][j]+sum1[i][j-1]-sum1[i-1][j-1]);

	for(int i=1;i<=n;i++)
		sum2[0][i]+=sum2[0][i-1];

	for(int j=1;j<=n;j++)
		sum2[j][0]+=sum2[j-1][0];

	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			sum2[i][j]=(sum2[i][j]+sum2[i-1][j]+sum2[i][j-1]-sum2[i-1][j-1]);

	int ans=0;

//	cerr<<"+2"<<endl;


//	for(int i=0;i<=n;i++)
//	{
//		for(int j=0;j<=n;j++)
//			cerr<<sum1[i][j]<<" ";
//		cerr<<endl;
//	}


	for(int i=1;i<=k;i++)
	{
		for(int j=1;j<=k;j++)
		{
			int temp1=getsum(i,j,sum1);
			int temp2=cnt2-getsum(i,j,sum2);
//			cerr<<temp1<<" "<<temp2<<endl;
			ans=max(ans,temp1+temp2);
			ans=max(ans,nn-(temp1+temp2));
		}
	}

	printf("%d\n",ans);
}


Measured memory_bytes: 31616
using System;

namespace ITP1_2_D
{
  class Program
  {
    static void Main(string[] args)
    {
      bool flag = true;
      var line = Console.ReadLine().Split();
      int[] input = new int[5];
      for (int i = 0; i < line.Length; i++)
      {
        input[i] = int.Parse(line[i]);
      }

      if (input[2] < input[4] || input[3] < input[4])
      {
        flag = false;
      }
      if (input[0] - input[2] < input[4] || input[1] - input[3] < input[4])
      {
        flag = false;
      }

      if (flag)
      {
        Console.WriteLine("Yes");

      }
      else
      {
        Console.WriteLine("No");

      }

    }
  }
}



Measured memory_bytes: 17996
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
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;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    int n;
    scanf("%d", &n);
    int a[n];
    rep(i, n) scanf("%d", &a[i]);
    int ans = 0;
    rep(i, n) ans += (i%2==0 && a[i]%2==1);
    printf("%d\n", ans);
}

Measured memory_bytes: 3832
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
//S.size()
//配列名.Length()
using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;


int main(void){
	int N;cin>>N;
	int p[N];rep(i,N)cin>>p[i];
	int jud = 0;
	for(int t = 0;t < N; t++){
		if(p[t] != t + 1)jud++;
	}
	cout<<(jud == 2 || jud==0?"YES":"NO");
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int n = sc.nextInt();
        int max = Math.max(h,w);
        if(n % max != 0){
            System.out.println(n/max+1);
        }else{
            System.out.println(n/max);
        }
    }
}

Measured memory_bytes: 22868
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	int a,b;
	cin>>a>>b;
	if(a+b==15){
		cout<<"+"<<endl;
	}
	else if(a*b==15){
		cout<<"*"<<endl;
	}
	else{
		cout<<"x"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
// Bismillahir Rahmanir Rahim  //
// Tanbir Ahmed  << RibNat >>  //
// University of Barisal       //



#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     fast            ios_base::sync_with_stdio(false);cin.tie(NULL)
#define     in1(X)          scanf("%lli",&(X))
#define     ins(S)          scanf("%s",(S))
#define     out(X)          printf("%lli",(X))
#define     outs(S)         printf("%s",(S))
#define     Pnl             printf("\n")
#define     End             return 0
#define     ll              long long int
#define     Pair            pair<ll,ll>
#define     F               first
#define     S               second
#define     all(v)          v.begin(),v.end()
#define     mem(a,v)        memset(a,v,sizeof(a))
#define     Max             1000000000000000014
#define     Min             -1000000000000000014
#define     mod             1000000007
#define     range           100007

#define     pb              push_back
#define     Vector          vector<ll>
#define     mp              make_pair
#define     PI              3.1415926535897
#define     min_heap        priority_queue <ll, vector<ll>, greater<ll> >
#define     ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>  //*(x.find_by_order(k)),x.order_of_key(k)

/*************** #Template FUNCTIONS# **************/

// ll pc;void PrintCase(){printf("Case %lli: ",++pc);}
// ll GCD(ll a,ll b){if(a<0) a*=-1;if(b<0) b*=-1;if(a<b)swap(a,b);if(b==1) return 1;if(!b) return a;if(!(a%b)) return b;else return GCD(b,a%b);}
//  ll LCM(ll a,ll b){ll x=GCD(a,b);return (a/x)*b;}
// ll bigmod(ll n,ll p){if(p==0) return 1;if(p==1)return (n+mod)%mod;if(p%2)return (bigmod(n,p-1)*n+mod)%mod;else{ll x=bigmod(n,p/2);return (x*x+mod)%mod;}}
 ll power(ll n,ll p){if(p==0) return 1;if(p==1)return n;if(p%2)return power(n,p-1)*n;else{ll x=power(n,p/2);return x*x;}}
// ll modinverse(ll n){return bigmod(n,mod-2)%mod;}
// ll Check(ll n,ll i){return (n&(1LL<<i));}
// ll Set(ll n,ll i){return (n|(1LL<<i));}
// ll status[(ll)range/64+5];Vector primes;void sieve(){for(ll i=3;i<=sqrt(range);i+=2){if(Check(status[i/64],i%64)==0){for(ll j=i*i;j<range;j+=2*i){status[j/64]=Set(status[j/64],j%64);}}}primes.pb(2);for(ll i=3;i<range;i+=2)if(Check(status[i/64],i%64)==0)primes.pb(i);}

// ll dx[] = {-2, -1, 1, 2,  2,  1, -1, -2};
// ll dy[] = { 1,  2, 2, 1, -1, -2, -2, -1};

// ll X[]= {0,0,1,-1,1,1,-1,-1};
// ll Y[]= {1,-1,0,0,1,-1,1,-1};

/********************** START **********************/



int main(){

    string s,p,x;

    cin>>x;

    p="ABC"; s="ARC";

    if(x==p) cout<<s<<endl;
    else cout<<p<<endl;

}



/*******      ALHAMDULILLAH     *********/  
/*******      Happy Coding      *********/


Measured memory_bytes: 3600
#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;}

//INSERT ABOVE HERE
signed main(){
  Int a,b;
  cin>>a>>b;
  cout<<(a^b)<<endl;
  return 0;
}


Measured memory_bytes: 256
def encode(switch_state, x, y, z)
    (switch_state << 13) + (x << 7) + (y << 1) + z
end

def decode(state)
    [state >> 13, (state >> 7) & 0b111111, (state >> 1) & 0b111111, state & 0b1]
end

w, h = gets.split.map(&:to_i)

init_floor = wall = stair = 0

switch = {}
gx = gy = nil
sx = sy = nil

(0..h-1).each do |i|
    gets.chomp.each_char.with_index do |c, j|
        bit = 1 << i * w + j
        case c
        when ?#
            wall   |= bit
        when ?_
        when ?^
            init_floor |= bit
        when /[a-z]/
            switch[[j, i]] = c.ord - ?a.ord
        when /[A-Z]/
            init_floor |= bit
            switch[[j, i]] = c.ord - ?A.ord
        when ?|
            stair |= bit
        when ?&
            gx = j
            gy = i
        when ?%
            sx = j
            sy = i
        end
    end
end

mover = (0..h-1).map { [0] * w }
gets.to_i.times do |k|
    s = (?a.ord + k).chr
    m = 0
    (0..h-1).each do |i|
        gets.chomp.each_char.with_index do |c, j|
            if c == ?*
                mover[i][j] |= (1 << k)
            end
        end
    end
end

init_state = encode(0, sx, sy, 0)
dist = {init_state => 0}
queue = [init_state]

def one_num_parity(x)
    k = 0
    until x == 0
        x &= (x - 1)
        k ^= 1
    end
    k
end

dirs = [[1, 0], [-1, 0], [0, 1], [0, -1]]
catch(:break) do
    until queue.empty?
        state = queue.shift
        switch_state, x, y, z = decode(state)
        next_states = []

        if stair[y * w + x] == 1
            next_states << encode(switch_state, x, y, z ^ 1)
        end

        if i = switch[[x, y]]
            next_states << encode(switch_state ^ (1 << i), x, y, z ^ mover[y][x][i])
        end

        dirs.each do |dx, dy|
            u, v = x + dx, y + dy
            pos = v * w + u
            next if wall[pos] == 1
            if stair[pos] == 1
                next_states << encode(switch_state, u, v, z)
            elsif init_floor[pos] ^ one_num_parity(mover[v][u] & switch_state) == z
                next_states << encode(switch_state, u, v, z)
            end
        end

        next_states.each do |s|
            next if dist[s]
            dist[s] = dist[state] + 1
            _, x, y, _ = decode(s)
            if x == gx && y == gy
                puts dist[s]
                throw(:break)
            end
            queue << s
        end
    end
    puts -1
end

Measured memory_bytes: 196192
#include <bits/stdc++.h>
using namespace std;
long long read()
{
    long long f=1,x=0;
    char ss=getchar();
    while(ss<'0'||ss>'9'){if(ss=='-')f=-1;ss=getchar();}
    while(ss>='0'&&ss<='9'){x=x*10+ss-'0';ss=getchar();}
    return f*x;
}
int main()
{
    string s;int n;
    cin>>n;
    cin>>s;
    int ans=0;
    for(int i=0;i<n-1;i++)
    {
        if(s[i]!=s[i+1])ans++;
    }
    cout<<ans+1<<endl;
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
const int  N=2e5+7;
const int  mod=1e9+7;
long long  arr[N];
long long  num[N];
int  main(){
	long long  n;
	cin>>n;
	for(int  i=1;i<=n;i++){
		cin>>num[i];
	}
	for(int  i=n;i>=1;i--){
		arr[i]=(arr[i+1]+num[i])%mod;
	}
	long long  ans=0;
	for(int  i=1;i<=n;i++){
		ans=(ans+num[i]*arr[i+1])%mod;
	}
	cout<<ans<<endl;
	return 0;
}

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

/*==============変数宣言==============*/
int N;
const int M = 26;
int n;
int m = M;
const int def = 1000000;

int c[30];
int s[400][30];

void input(){
	scanf("%d", &N);
	n = N;

	for(int i = 0;i < M;i++) scanf("%d", &c[i]);

	for(int i = 0;i < N;i++)
		for(int j = 0;j < M;j++)
			scanf("%d", &s[i][j]);
	
	return;
}

/*================関数================*/
struct RandomNumberGenerator {
  mt19937 mt;

  RandomNumberGenerator() : mt(chrono::steady_clock::now().time_since_epoch().count()) {}

  int operator()(int a, int b) { // [a, b)
    uniform_int_distribution< int > dist(a, b - 1);
    return dist(mt);
  }

  int operator()(int b) { // [0, b)
    return (*this)(0, b);
  }
};

struct Timer {
  chrono::high_resolution_clock::time_point st;

  Timer() { reset(); }

  void reset() {
    st = chrono::high_resolution_clock::now();
  }

  chrono::milliseconds::rep get() {
    auto ed = chrono::high_resolution_clock::now();
    return chrono::duration_cast< chrono::milliseconds >(ed - st).count();
  }
};

Timer timer;
RandomNumberGenerator rnd;
/*====================================*/



void init(){
	input();
	return;
}


void output(short ans[]){
	for(int i = 0;i < n;i++){
		printf("%d\n", ans[i]+1);
	}
}

int getScore(short a[]){
	int last[30] = {};
	int ans = 0;
	for(int i = 0;i < n;i++){
		ans += s[i][a[i]]; 
		last[a[i]] = i+1;
		for(int j = 0;j < M;j++){
			ans -= c[j] * ((i+1)-last[j]); 
		}
	}
	return ans;
}

int main(){
	init();

	short now[500];
	short ans[500]; 

	for(int i = 0;i < n;i++){
		ans[i] = now[i] = rnd(26); 
	}

	int ans_score = getScore(ans);
	while(timer.get() < 1990){
		int idx = rnd(365);
		int old = now[idx];
		int next = rnd(26);
		now[idx] = next;
		int now_score = getScore(now);
		if(ans_score <= now_score){
			ans[idx] = next;
			ans_score = now_score;
		}else{
			now[idx] = old; 
		}
	}

	output(ans);
	//cerr << getScore(ans) << endl;

	return 0;
}

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


int main(){


    int a, b, c, i;

 
    cin >> a >> b >> c;


    if( a % b == 0 ){

        cout << "NO" << endl;

        return 0;

        }

    for( i = 1 ; i < b + 1 ; i = i + 1 ){ 

         if( ( a * i ) % b == c ){

             cout << "YES" << endl;

             return 0;

             }

         }


    cout << "NO" << endl;


    return 0;


    }

Measured memory_bytes: 256
N, M, Q = map(int, input().split())
a = []
b = []
c = []
d = []
for _ in range(Q):
    ad, bd, cd, dd = map(int, input().split())
    a.append(ad-1)
    b.append(bd-1)
    c.append(cd)
    d.append(dd)
def score(A):
    tmp = 0
    for ai, bi, ci, di in zip(a, b, c, d):
        if A[bi] - A[ai] == ci:
            tmp += di
    return tmp
def dfs(A):
    if len(A) == N:
        return score(A) 
    res = 0
    prev_last = A[-1] if len(A) > 0 else 0
    for v in range(prev_last, M):
        A.append(v)
        res = max(res, dfs(A)) 
        A.pop()
    return res
print(dfs([]))

Measured memory_bytes: 9188
// Vicfred
// https://atcoder.jp/contests/abc167/tasks/abc167_c
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>

using namespace std;

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

    vector<long long> C(N);
    vector<vector<long long>> A(N, vector<long long>(M));

    for(long long i = 0LL; i < N; ++i) {
        cin >> C[i];

        for(long long j = 0LL; j < M; ++j) {
            cin >> A[i][j];
        }
    }

    long long minima = 1LL<<60;

    for(long long mask = 0LL; mask <= (1LL<<N)-1LL; ++mask) {
        long long total = 0LL;
        vector<long long> level(M);

        for(long long bit = 0LL; bit < N; ++bit) {
            if(mask&(1LL<<bit)) {
                total += C[bit];

                for(long long i = 0LL; i < M; ++i) {
                    level[i] += A[bit][i];
                }
            }
        }

        if(none_of(level.begin(),
                    level.end(),
                    [=](long long x) { return x < X; })
          ) {
            minima = min(minima, total);
        }
    }

    if(minima == 1LL<<60)
        minima = -1;

    cout << minima << endl;

    return 0;
}



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

int main() {
  string S;
  cin>>S;
  int sum=0;
  rep(i,S.size()) sum+=S[i]-'0';
  if(sum%9==0) cout<<"Yes\n";
  else cout<<"No\n";
}


Measured memory_bytes: 3704
from collections import deque

s=deque(list(input()))
flag=0
for i in range(int(input())):
  dir=input().split()
  if int(dir[0])==1:flag+=1
  else:
    if int(dir[1])==1:
      if flag%2==0:s.appendleft(dir[2])
      else:s.append(dir[2])
    else:
      if flag%2==0:s.append(dir[2])
      else:s.appendleft(dir[2])
s=list(s)
if flag%2==1:s.reverse()
print(*s,sep='')

Measured memory_bytes: 16320
#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>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

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

int main(){
	int n;
    cin>>n;
    cout<<(n+1)/2;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int k;
long long mod = 1000000007;
long long fac[100005];
vector<int>tree[100005];
bool visited[100005];
long long multi(long long a,long long b){
	if(b==0) return 1;
	if(b==1) return a;
	long long ret = multi(a,b/2);
	ret*=ret;
	ret%=mod;
	if(b%2) ret*=a;
	return ret%mod;
}
long long P(long long n,long long r){
	long long ret = fac[n];
	long long down = fac[n-r];
	return (ret*multi(down,mod-2))%mod;
}
long long dfs(long long curr,bool p){
	visited[curr] = true;
	long long child = 0;
	for(int i=0; i<tree[curr].size(); i++){
		int nxt = tree[curr][i];
		if(!visited[nxt]) child++;
	}
	if(k-1-p<child){
		return 0;
	}
	long long ret = P(k-1-p,child);
	for(int i=0; i<tree[curr].size(); i++){
		int nxt = tree[curr][i];
		if(!visited[nxt]){
			ret*=dfs(nxt,1);
			ret%=mod;
		}
	}
	return ret;
}
int main(){
	int n;
	cin>>n>>k;
	fac[0] = 1;
	for(int i=1; i<=100000; i++){
		fac[i] = fac[i-1]*i;
		fac[i]%=mod;
	}

	for(int i=1; i<n; i++){
		int a,b;
		cin>>a>>b;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}

	long long ans = k;
	ans*=dfs(1,0);
	cout<<ans%mod;
}

Measured memory_bytes: 13348
package main

import "fmt"

const inf = 1 << 60

func chmin(a *int, b int) {
	if *a > b {
		*a = b
	}
}

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)

	cw := make([]int, n+1)
	ce := make([]int, n+1)
	for i := 0; i < n; i++ {
		cw[i+1] = cw[i]
		ce[i+1] = ce[i]
		if s[i] == 'W' {
			cw[i+1]++
		} else {
			ce[i+1]++
		}
	}

	minCost := inf
	for i := 0; i < n; i++ {
		cost := 0
		cost += cw[i] - cw[0]
		cost += ce[n] - ce[i+1]
		chmin(&minCost, cost)
	}
	fmt.Println(minCost)
}


Measured memory_bytes: 7296
import sys

S = str(input())
T = str(input())

jisho_s = {}
jisho_t = {}
for i in range(len(S)):
    s = S[i]
    t = T[i]
    if s in jisho_s and jisho_s[s] != t:
        print("No")
        sys.exit()
    if t in jisho_t and jisho_t[t] != s:
        print("No")
        sys.exit()
    if s not in jisho_s:
        jisho_s[s] = t
    if t not in jisho_t:
        jisho_t[t] = s

print("Yes")

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    char c[100001]={0};
    cin >> c;
    for(int i=1;i<100001;i=i+2) {
        if(c[i-1]!=0) cout << c[i-1];
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, D, N, ans=0;
    string S[3];
    cin >> S[0];
    cin >> S[1];

    cout <<"A"<<S[1][0]<<"C"<<endl;
    
    // if(A<B)
    // 	cout << 0<<endl;
    // else
    // 	cout <<10<<endl;
    

    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;
    // if(A+B==C || B+C==A || C+A==B)
    // 	puts("Yes");
    // else
    // 	puts("No");
    	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP2(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REP3(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define OVERLOAD2(_1, _2, _3, name, ...) name
#define REP(...) OVERLOAD2(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Tue Feb 11 19:59:56 JST 2020
 **/

template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}

signed main() {
    Int n;
    cin >> n;
    struct Edge {
        Int to, idx;
    };
    vector<vector<Edge>> g(n);
    for (int i = 0; i < n - 1; i++) {
        Int u, v;
        cin >> u >> v;
        u--, v--;
        g[u].push_back({v, i});
        g[v].push_back({u, i});
    }
    vector<Int> edges(n - 1);
    auto dfs = [&](auto f, Int v, Int prv, Int to, Int query) -> bool {
        if (v == to) return true;
        for (Edge e : g[v]) {
            if (e.to == prv) continue;
            if (f(f, e.to, v, to, query)) {
                edges[e.idx] |= 1 << query;
                return true;
            }
        }
        return false;
    };
    Int m;
    cin >> m;
    REP(i, m) {
        Int u, v;
        cin >> u >> v;
        u--, v--;
        assert(dfs(dfs, u, -1, v, i));
    }
    auto dp = make_vec<Int>(n - 1 + 1, 1 << m, 0);
    dp[0][0] = 1;
    REP(i, n - 1) {
        REP(k, 1 << m) {
            dp[i + 1][k] += dp[i][k];
            dp[i + 1][k | edges[i]] += dp[i][k];
        }
    }
    Int all = (1 << m) - 1;
    cout << dp[n - 1][all] << endl;
}


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

int main() {
	int big = 1e5;
	int H, W;
	cin>>H>>W;
	vector<string>arr;
	string tmp;
	for(int i=0;i<H;++i){
		cin>>tmp;
		arr.push_back(tmp);
	}
	int map[H*W][H*W];
	for(int i=0;i<H*W;++i){
		for(int j=0;j<H*W;++j){
			if(i==j)map[i][j]=0;
			else map[i][j] = big;
		}
	}
	for(int i=0;i<H;++i){
		for(int j=0;j<W;++j){
			if(arr[i][j]=='#'){
				for(int k=0;k<H*W;++k){
					map[k][W*i+j]=-1;
					map[W*i+j][k]=-1;
				}
			}
		}
	}
	for(int i=0;i<H;++i){
		for(int j=0;j<W;++j){
			if(j<W-1){
				if(arr[i][j]=='.' & arr[i][j+1]=='.'){
					map[W*i+j][W*i+j+1] = 1;
					map[W*i+j+1][W*i+j] = 1;
				}
			}
			if(j>0){
				if(arr[i][j]=='.' & arr[i][j-1]=='.'){
					map[W*i+j][W*i+j-1] = 1;
					map[W*i+j-1][W*i+j] = 1;
				}
			}
			if(i<H-1){
				if(arr[i][j]=='.' & arr[i+1][j]=='.'){
					map[W*i+j][W*(i+1)+j] = 1;
					map[W*(i+1)+j][W*i+j] = 1;
				}
			}
			if(i>0){
				if(arr[i][j]=='.' & arr[i-1][j]=='.'){
					map[W*i+j][W*(i-1)+j] = 1;
					map[W*(i-1)+j][W*i+j] = 1;
				}
			}
		}
	}
	/**
	for(int i=0;i<H*W;++i){
		for(int j=0;j<H*W;++j){
			cout<<map[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
	**/
	for(int k=0;k<H*W;++k){
		for(int i=0;i<H*W;++i){
			for(int j=0;j<H*W;++j){
				if(map[i][j]==-1)continue;
				if(map[i][k]==-1 | map[k][j]==-1)continue;
				map[i][j] = min(map[i][j], map[i][k]+map[k][j]);
			}
		}
	}
	/**
	for(int i=0;i<H*W;++i){
		for(int j=0;j<H*W;++j){
			cout<<map[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
	**/
	int ans = 0;
	for(int i=0;i<H*W;++i){
		for(int j=0;j<H*W;++j){
			if(ans<map[i][j])ans = map[i][j];
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<int, int>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

template<int MOD> struct Fp {
	long long val;
	Fp(long long v = 0) : val(v % MOD) {
		if (val < 0) v += MOD;
	}
	int getmod() { return MOD; }
	Fp operator - () const {
		return val ? MOD - val : 0;
	}
	Fp operator + (const Fp& r) const { return Fp(*this) += r; }
	Fp operator - (const Fp& r) const { return Fp(*this) -= r; }
	Fp operator * (const Fp& r) const { return Fp(*this) *= r; }
	Fp operator / (const Fp& r) const { return Fp(*this) /= r; }
	Fp& operator += (const Fp& r) {
		val += r.val;
		if (val >= MOD) val -= MOD;
		return *this;
	}
	Fp& operator -= (const Fp& r) {
		val -= r.val;
		if (val < 0) val += MOD;
		return *this;
	}
	Fp& operator *= (const Fp& r) {
		val = val * r.val % MOD;
		return *this;
	}
	Fp& operator /= (const Fp& r) {
		long long a = r.val, b = MOD, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % MOD;
		if (val < 0) val += MOD;
		return *this;
	}
	bool operator == (const Fp& r) const {
		return this->val == r.val;
	}
	bool operator != (const Fp& r) const {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream &os, const Fp<MOD>& x) {
		return os << x.val;
	}
	friend istream& operator >> (istream &is, Fp<MOD>& x) {
		return is >> x.val;
	}
	friend Fp<MOD> modpow(const Fp<MOD> &a, long long n) {
		if (n == 0) return 1;
		auto t = modpow(a, n / 2);
		t = t * t;
		if (n & 1) t = t * a;
		return t;
	}
};

using mint = Fp<MOD>;

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

using Data = tuple<int, ll, ll>;

int main(){
	ll n; cin >> n;
	map<Data, ll> mp;
	for(int i = 0; i < n; ++i){
		ll a, b; cin >> a >> b;
		if(a == 0 && b == 0) ++mp[{0,0,0}];
		else if (a == 0 && b != 0) ++mp[{0, 0, 1}];
		else if(a != 0 && b == 0) ++mp[{0,1,0}];
		else{
			int sign = 1;
			if (a < 0 && b > 0) sign = -1;
                        if (a > 0 && b < 0) sign = -1;
			a = abs(a); 
			b = abs(b);
			ll tmp = GCD(a, b);
			++mp[{sign, a/tmp, b/tmp}];
		}
	}

    mint ans = 1, sub = 0, two = 2;
	set<Data> se;
	for(auto it : mp){
		if (se.count(it.first)) continue;

		int sign = get<0>(it.first);
		ll a     = get<1>(it.first);
		ll b     = get<2>(it.first);
		ll p = it.second;

		if(a == 0 && b == 0) sub = p;
		else{
			ll q = 0;
			if(mp.count({-sign, b, a}) != 0){
				q += mp[{-sign, b, a}];
				se.insert({-sign, b, a});
			}
			mint tmp = modpow(two, p) + modpow(two, q) - 1;
			ans *= tmp;
		}
	}
	ans += sub - 1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 19164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 9223372036854775807;
const ll half_inf = 0x3f3f3f3f;
const ll inf = 0x7fffffff;
const ll mod = 1e9 + 7;
const ll maxn = 200005;
int dp[maxn]={0};
int main(){  
	cin.tie(0);
    ios::sync_with_stdio(false);
	int T,n,m;
	scanf("%d",&T);
	/*while(T--){
		
		
		
		
	}*/
	printf("%d",(T+1)/2);
	
	
	
	
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
		long long s;
		cin >> s;
		long long  x1,y1,x2,y2,x3,y3;
		if(s == 1e18)printf("0 0 1000000000 0 0 1000000000");
		else {
				x2 = 0;y2 = 0;
				x1 = 1; y1 = 1e9;
				x3 = ((s)/(long long)1e9) +1;y3 = 1e9 - (s%(long long) 1e9); 
				printf("%lld %lld %lld %lld %lld %lld",x1,y1,x2,y2,x3,y3);
		}
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>

ll INF = 1000000007;


//-----------------//
  #define amin main
//-----------------//


int amin()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll i,j;
	string s;
	string t;
	cin>>s>>t;
	ll ans = INF;
	for(i=0;i<s.length()-t.length()+1;i++)
	{
		ll k = 0;
		ll cnt= 0;
		for(j=i;j<i+t.length();j++)
		{
			if(s[j]!=t[k])
				cnt++;
			k++;
		}
		ans = min(ans,cnt);
	}
	cout<<ans<<endl;
	
	


	
	return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
int main(void)
{
    int x,y,z;
	z=0;
	scanf("%d %d",&x,&y);
	while(!(x==0 && y==0)){
	    if(x>y){
		    z=y;
			y=x;
			x=z;
		}
		printf("%d %d\n",x,y);
	    scanf("%d %d",&x,&y);
	}
	return 0;
}

Measured memory_bytes: 2544
#include <cstdio>
#include <vector>
using namespace std;

vector<int> p;

void Prime(){
	bool prime[100000];
	prime[0] = false;
	prime[1] = false;
	for(int i = 2; i < 100000; i++) prime[i] = true;
	for(int i = 2; i < 1000; i++){
		if(!prime[i]) continue;
		for(int j = i*2; j < 100000; j += i) prime[j] = false;
	}
	for(int i = 0; i < 100000; i++) if(prime[i]) p.push_back(i);
}

int main(){
	Prime();
	int m, a, b;
	while(scanf("%d%d%d", &m, &a, &b),m||a||b){
		int aa, bb;
		int ans = 0;
		for(int i = 0; i < p.size(); i++){
			if(p[i] > 1000) break;
			for(int j = i; j < p.size(); j++){
				if(p[i]*p[j] > m || a*p[j] > b*p[i]) break;
				if(p[i]*p[j] > ans){
					ans = p[i]*p[j];
					aa = p[i]; bb = p[j];
				}
			}
		}
		printf("%d %d\n", aa, bb);
	}
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in(),A=in();
	int v=N%500;
	
	out(v<=A ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>


using namespace std;

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


struct v_t
{
	int a, c, l;
	vi e;
};


void solve_i(vector<v_t>&v, vi&w, int p)
{
	v_t&c=v[p];

	for(int me:c.e)
	{
		v_t&n=v[me];

		if(n.l) continue;
		auto it=lower_bound(w.begin(), w.end(), n.a);
		if(it==w.end())
		{
			w.push_back(n.a);
			n.l=w.size()-1;
			solve_i(v, w, me);
			w.pop_back();
		}
		else
		{
			int x=it-w.begin();
			int s=w[x];
			w[x]=n.a;
			n.l=w.size()-1;
			solve_i(v, w, me);
			w[x]=s;
		}
	}
}


void solve(vector<v_t>&v)
{
	vi w;

	w.reserve(v.size());
	w.push_back(0);
	w.push_back(v[1].a);
	v[1].l=w.size()-1;
	solve_i(v, w, 1);
}


int main(void)
{
	int n;
	while(scanf("%d", &n)==1)
	{
		vector<v_t> v(n+1);
		for(int i=1;i<=n;i++) scanf("%d", &v[i].a);

		for(int i=0;i<n-1;i++)
		{
			int f, t;

			scanf("%d%d", &f, &t);
			v[f].e.push_back(t);
			v[t].e.push_back(f);
		}

		solve(v);
		for(int i=1;i<=n;i++)
		{
			printf("%d\n", v[i].l);
		}
	}
	return 0;
}


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

#define all(c) (c).begin(),(c).end()
#define FOR(i, x, n) for(int i = x; i < (int)n; i++)
#define REP(i, n) FOR(i, 0, n)
#define debug(x) #x << "=" << (x) << "(L" << __LINE__ << ")"
#define show(x) cout << #x << "=" << x << endl
#define show2(x,y) cout << #x << "=" << x << "," << #y << "=" << y <<  endl
#define show3(x,y,z) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z <<  endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long double> vld;

const ld eps = 1e-9, pi = acos(-1.0);
const ld EPS = 1e-8;
const int INF = INT_MAX/2;
const ll LINF = LONG_MAX/2;
const int MOD = 1000000007;

template<class T> inline void amin(T &a, const T &b) { if (b<a) a=b; }
template<class T> inline void amax(T &a, const T &b) { if (a<b) a=b; }

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
    
    int n;
    cin >> n;
    
    vld a;
    ld bb = 0.0;
    int tmp;
    
    rep(i,n){
        cin >> tmp;
        a.emplace_back(tmp);
    }
    //for(auto e : a) cout << e << endl;
    for(auto e : a) bb += 1.0/(double)e;
	
	ld ans = 1.0 / bb;
	
    //cout << fixed << setprecision(10);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

LL H, W;
std::vector<std::string>S;
std::vector<std::vector<bool>>vis;
std::vector<std::pair<LL, LL>>memo;

LL dx[] = { -1,0,0,1 }, dy[] = { 0,-1,1,0 };
void f(LL i, LL j)
{
	if (vis[i][j]) return;
	vis[i][j] = true;
	memo.push_back(std::make_pair(i, j));
	rep(k, 4)
	{
		LL x = i + dx[k], y = j + dy[k];
		if (x < 0 || H <= x || y < 0 || W <= y) continue;
		if (S[x][y] != S[i][j]) f(x, y);
	}
}

int main()
{
	in >> H >> W;
	S.resize(H);
	rep(i, H) in >> S[i];

	vis.resize(H);
	rep(i, H) vis[i].resize(W, false);

	LL ans = 0;
	rep(i, H)
	{
		rep(j, W)
		{
			if (!vis[i][j])
			{
				memo.clear();
				f(i, j);
				LL cnt1 = 0, cnt2 = 0;
				for (auto k : memo)
				{
					if (S[k.first][k.second] == '#') ++cnt1;
					else ++cnt2;
				}
				ans += cnt1 * cnt2;
			}
		}
	}

	out << ans << std::endl;
}


Measured memory_bytes: 18540
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		String str[] = br.readLine().split(" ");
		if (!str[0].equals("0")) {
			System.out.println("0");
			return;
		}

		int s[] = new int[n];
		int max = 0;

		for (int i = 0; i < n; i++) {
			int d = Integer.parseInt(str[i]);
			s[d]++;
			max = Math.max(max, d);
		}

		if (s[0] != 1) {
			System.out.println("0");
			return;
		}
		long ans = 1;
		for (int i = 1; i < n; i++) {
			ans *= modpow(s[i - 1], s[i], 998244353);
			ans %= 998244353;
		}

		System.out.println(ans % 998244353);
	}

	// a^n mod を計算する
	static long modpow(long a, long n, long mod) {
		long res = 1;
		while (n > 0) {
			if ((n & 1) == 1)
				res = res * a % mod;
			a = a * a % mod;
			n >>= 1;
		}
		return res;
	}
}

Measured memory_bytes: 44788
/*
ID: wangjun30
LANG: C++11
TASK:
*/
#include<iostream>
#include<algorithm>
#include<array>
#include<unordered_map>
#include<map>
#include<set>
#include<list>
#include<stack>
#include<unordered_set>
#include<vector>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
//#include<fstream>
#define int long long
using namespace std;
//ifstream cin(".in");
//ofstream cout(".out");
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int a,b,k;
	cin>>k>>a>>b;
	for(int i=a;i<=b;i++)
		if(i%k==0){
			cout<<"OK";
			return 0;
		}
	cout<<"NG";
	return 0;
}

Measured memory_bytes: 3652
import sys
timo = list(map(int, input().split()))
n = timo[0]
y = timo[1]
for i in range(n + 1):
  for j in range(n - i + 1):
    if 10000 * i + 5000 * j + 1000 * (n - i - j) == y:
      print(i, j, n - i - j)
      sys.exit()
print('-1 -1 -1')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
int main() {
  int R,G,B,N,i,j,k;
  cin>>R>>G>>B>>N;
  int a,sum;
  a=0;
  sum=0;
  for(i=0;;i++){
    if(R*i>N) break;
  for(j=0;;j++){
    sum=R*i+G*j;
    if(sum>N) break;
    if((N-sum)%B==0){
    a++;
      
    }
    
  
  }
  }
  cout<<a<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll A[100007],B[100007];

int main(){
  ll N,L;
  cin >> N >> L;
  rep(i,N){
    cin >> A[i];
  }
  ll P=0,ma=-1;
  Rep(i,1,N){
    if(ma<A[i-1]+A[i]){
      ma=A[i-1]+A[i];
      P=i;
    }
  }
  if(ma<L){
    cout <<"Impossible"<< endl;
    return 0;
  }
  cout <<"Possible"<< endl;
  Rep(i,1,P){
    cout << i << endl;
  }
  rRep(i,N-1,P){
    cout << i  << endl;
  }
}

Measured memory_bytes: 1536
#ABC164C
def main():
    import sys
    import copy
    N, limit = map(int, sys.stdin.readline().split())
    L = tuple([tuple(map(int, sys.stdin.readline().split())) for _ in range(N)])
    dp = [[0 for _ in range(limit+1)] for _ in range(N)]
    dp[0][L[0][0]] = L[0][1] #初期値
    for i in range(1, N):
        dp[i] = copy.copy(dp[i-1]) #前回をコピー(初)
        w, v = L[i][0], L[i][1]
        dp[i][w] = max(v, dp[i][w])
        for j in range(limit+1-w):
            if dp[i-1][j] >0:
                dp[i][w+j] = max(v+ dp[i-1][j], dp[i][w+j])
            
    
    
    print(max(dp[-1]))



if __name__=='__main__':
    main()

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

const int N = 10;
char s[N + 1], ans[N + 1];
int main(){
	cin >> s;
	int j = 0;
	for(int i = 0;s[i] != '\0';++i){
		if(s[i] == 'B' && j != 0){
			ans[--j] = '\0';
		}
		else if(s[i] != 'B'){
			ans[j++] = s[i];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<set>
using namespace std;
const int N=100100;
int i,j,k,n,ch,ff,dn,x,y;
int f[N];
set<int> S[N];
set<int>::iterator it;
struct cc { int x,y;} d[N];
void R(int &x) {
	ff=x=0;ch=getchar();
	while (ch<'0' || '9'<ch) ch=getchar();
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
int getf(int x) {
	if (f[x]==x) return x;
	return f[x]=getf(f[x]);
}
void Add(int x,int y) {
	x=getf(x);y=getf(y);
	if (S[x].find(y)!=S[x].end()) {
		S[x].erase(y);
		S[y].erase(x);
		d[++dn].x=x;d[dn].y=y;
	}
	else {
		S[x].insert(y);
		S[y].insert(x);
	}
}
void Merge(int x,int y) {
	x=getf(x);y=getf(y);
	if (S[x].size()>S[y].size()) {
		int t=x;x=y;y=t;
	}
	f[x]=y;
	for (it=S[x].begin();it!=S[x].end();it++) {
		int t=*it;
		S[t].erase(x);
		Add(t,y);
	}
}
int main() {
	R(n);
	for (i=1;i<n;i++) f[i]=i;
	for (i=1;i<n;i++) {
		R(x);R(y);
		Add(x,y);
	}
	for (i=1;i<n;i++) {
		R(x);R(y);
		Add(x,y);
	}
	for (i=1;i<n-1;i++) {
		if (i>dn) return puts("NO"),0;
		Merge(d[i].x,d[i].y);
	}
	puts("YES");
}

Measured memory_bytes: 25088