akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define ff       first
#define ss       second
#define vpop     pop_back
#define pb       push_back
#define mp       make_pair
#define ll       long long int
#define umap	 unordered_map
#define pii	 pair<int, int>
#define clz(x)   __builtin_clz(x)       
#define ctz(x)   __builtin_ctz(x)      
#define all(v)   v.begin(), v.end() 
#define sbts(x)  __builtin_popcount(x) 
#define ull      unsigned long long int
#define ms(a,v)  memset(a, v, sizeof(a))
#define ps(x, y) fixed << setprecision(y) << x
const int MOD  = 1e9 + 7;
const ll  INF  = 1e12;
const int   N  = 1e5 + 1;

int main() { 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  cout.tie(NULL);
//  *-------------------------------*
    int n; cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }    
    int dp[n + 1];
    dp[0] = 0; dp[1] = abs(arr[1] - arr[0]);
    for (int i = 2; i <= n; i++) {
        int a = dp[i - 1] + abs(arr[i - 1] - arr[i]);
        int b = dp[i - 2] + abs(arr[i - 2] - arr[i]);
        dp[i] = min(a, b);
    }
    cout << dp[n - 1];
    return 0;
}



Measured memory_bytes: 4420
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		

		Scanner stdin = new Scanner(System.in);
		long a = 0;
		long b = 0;
		long ab = 0;
		long r = 0;
		long gcd = 0;
		long lcm = 0;
		long temp = 0;
		while(stdin.hasNext()) {
			a = stdin.nextInt();
			b = stdin.nextInt();
			ab = a * b;

			if(a < b) {
				temp = a;
				a = b;
				b = temp;
			}
			if(a >= b) {
				do {
					r = a % b;
					if(r == 0) {
						break;
					} else {
						a = b;
						b = r;
					}
				}while(r != 1);
				gcd = b;
				lcm = ab / b;
				System.out.println(gcd + " " + lcm);

			}
		}
	}
}

Measured memory_bytes: 26176
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define yokuwaruprime (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int n,m;
  cin>>n>>m;
  int64 x[n],y[m];
  rep(i,n){
    cin>>x[i];
  }
  rep(i,m){
    cin>>y[i];
  }
  int64 bigX=0,bigY=0;
  rep(i,n){
    bigX+=(2*i-n+1)*x[i];
    bigX%=yokuwaruprime;
  }
  rep(i,m){
    bigY+=(2*i-m+1)*y[i];
    bigY%=yokuwaruprime;
  }
  cout<<(bigX*bigY)%yokuwaruprime<<endl;
}


Measured memory_bytes: 1792
/*
@ author:pyyyyyy/guhl37
-----思路------

-----debug-------

*/
#include<bits/stdc++.h>
using namespace std;
const int N=10;
int a[N][N],b[N][N],n,m,k,cnt,ans,num[N][N];//num为被修改次数
void solvej(int now) {
	if(now==m+1) {
		int tmp=0;
		for(int i=1; i<=n; ++i)
			for(int j=1; j<=m; ++j)
				if(a[i][j]==1&&num[i][j]==0) tmp++;
		if(tmp==k) ans++;
		return ;
	}
	for(int i=0; i<=1; ++i) {
		if(i==1)
			for(int j=1; j<=n; ++j) num[j][now]++;
		solvej(now+1);
		if(i==1)
			for(int j=1; j<=n; ++j) num[j][now]--;
	}
}
void solvei(int now) { //处理行
	if(now==n+1) {
		solvej(1);//处理列
		return ;
	}
	for(int i=0; i<=1; ++i) {
		if(i==1)
			for(int j=1; j<=m; ++j) num[now][j]++;
		solvei(now+1);
		if(i==1)
			for(int j=1; j<=m; ++j) num[now][j]--;
	}
}
int main() {
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n>>m>>k;
	for(int i=1; i<=n; ++i) {
		char opt;
		for(int j=1; j<=m; ++j) {
			cin>>opt;
			if(opt=='.') a[i][j]=0;
			else if(opt=='#') a[i][j]=1,cnt++;
		}
	}
//	if(cnt==k) {
//		cout<<1<<'\n';
//		return 0;
//	}
	solvei(1);
	cout<<ans<<'\n';
	return 0;
}



Measured memory_bytes: 3616
#include <stdio.h>
int main() {
    short int n, a, cnt = 0;
    scanf("%hi", &n);
    for (short int i = 1; i <= n; i++) {
        scanf("%hi", &a);
        cnt += (i & 1) * (a & 1);
    }
    printf("%hi", cnt);
}


Measured memory_bytes: 1728
#include<stdio.h>
int N, m, q;
int vector[100000][100];
int count[100000];
int group[100000];
int ID = 1;
  
void dfs(int s){
    int i;
    group[s]=ID;
    for(i = 0; i < count[s]; i++ ) {
        if ( group[vector[s][i]] == 0 ) dfs(vector[s][i]);
    }
}
  
int main(void) {
    int i, j, a, b; 
    scanf("%d%d", &N, &m);
    for ( i = 0; i < m; i++ ) {
        scanf("%d%d", &a, &b);
        vector[a][count[a]++] = b;
        vector[b][count[b]++] = a;
    }
    for ( i = 0; i < N; i++ ) {
        if ( group[i] == 0 ) {
            dfs(i);
            ID++;
        }
    } 
    scanf("%d",&q);
    for ( i = 0; i < q; i++ ) {
        scanf("%d%d", &a, &b);
        if ( group[a] == group[b] ) printf("yes\n");
        else printf("no\n");
    }
  
    return 0;
}



Measured memory_bytes: 44580
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using lll = long long;
using ull = unsigned long long;
using namespace std;



int main(){
  lll ii,jj,kk;
  lll n,d,num,pos;
  cin >> n >> d;
  num = 1;
  pos = 1+d;
  while(pos + d < n){
    num++;
    pos = pos + d * 2 + 1;
    // cout << "pos" << pos << endl;
  }
  cout << num << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stack>

#define Max 100
#define white 0
#define gray 1
#define black 2
using namespace std;
int dia=0;
int d[Max+1],f[Max+1];
	bool g[Max+1][Max+1];
	int color[Max+1];
	
void dft(int a,int n){
	int i;
	color[a]=gray;
	d[a]=++dia;
	for(i=1;i<=n;i++){
		if(g[a][i] && color[i]==white)
			dft(i,n);	
		}
		color[a]=black;
		f[a]=++dia;
	
}
void defa( int n){
	int i;
	for( i=1;i<=n;i++)
	color[i]=white;
	for(i=1;i<=n;i++){
		if(color[i]==white)
		dft(i,n);
	}
}
main(){
	int j,i,n,u,k,v;
	
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++)
		g[i][j]=false;
	}
	for(i=1;i<=n;i++){
		scanf("%d%d",&u,&k);
		for(j=0;j<k;j++){
		scanf("%d",&v);
		g[u][v]=true;
		}
	}
	defa(n);
	for(i=1;i<=n;i++)
	printf("%d %d %d\n",i,d[i],f[i]);
	
	return 0;
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int x, y;
	cin >> x >> y;

	int ans = 0;
	if (x == 3) { ans += 100000; }
	if (x == 2) { ans += 200000; }
	if (x == 1) { ans += 300000; }
	if (y == 3) { ans += 100000; }
	if (y == 2) { ans += 200000; }
	if (y == 1) { ans += 300000; }
	if (x == 1 && y == 1) { ans += 400000; }
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 764
data class Edge(val to: Int, val id: Int)
fun main(args: Array<String>) {
    val N = nextInt()
    val G = Array(N) { mutableListOf<Edge>() }
    val ans = IntArray(N - 1)
    repeat(N - 1) {
        val (a, b) = listOfInt(-1)
        G[a].add(Edge(b, it))
        G[b].add(Edge(a, it))
    }
    tailrec fun dfs(v: Int, c: Int = -1, p: Int = -1) {
        var k = 1
        for (e in G[v]) {
            val u = e.to
            val ei = e.id
            if (u == p) continue
            if (k == c) k++
            ans[ei] = k++
            dfs(u, ans[ei], v)
        }
    }
    dfs(0)
    val max = G.map { it.size }.max()!!
    println(max)
    println(ans.joinToString(separator = "\n"))
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }
fun printErr(value: Any) = System.err.println(value)


Measured memory_bytes: 78960
import itertools
n,m,q = map(int,input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
for i in range(q):
    a[i],b[i],c[i],d[i] = map(int,input().split())
ans = 0
for A in itertools.combinations_with_replacement(range(1,m+1),n):
    cnt = 0
    for i in range(q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            cnt += d[i]
    ans = max(ans,cnt)
print(ans)


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

typedef long long ll;

int n, m;
map <int, int> M;
ll res;

int main()
{
	cin >> n >> m;
	M[0]++;
	int cur = 0;
	for (int i = 1; i <= n; i++) {
		int a; scanf("%d", &a);
		cur = (cur + a) % m;
		res += M[cur]++;
	}
	cout << res << endl;
	return 0;
}

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

void Main() {
  int N;
  cin >> N;

  long long x[N], y[N], max_x = 0;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i];
    max_x = max(max_x, x[i]);
  }

  long long d[N], dr[N];
  for (int i = 0; i < N; i++) {
    d[i] = x[i] + y[i];
    dr[i] = (max_x - x[i]) + y[i];
  }

  sort(d, d + N);
  sort(dr, dr + N);

  cout << max(d[N - 1] - d[0], dr[N - 1] - dr[0]) << endl;
}

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



Measured memory_bytes: 9868
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
using mat = vector<vector<ll>>;
using vec = vector<ll>;
#define INF1  INT_MAX
#define INF2  LLONG_MAX
const double  PI =  acos(-1);
#define MOD 1000000007
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;



int main(){

int N;
cin>>N;
int max_;
rep3(i,N){
    if(i*(i+1)/2>=N){
        max_=i;
        break;
    }
}
int res=max_*(max_+1)/2-N;
vector<int> ans;
rep3(i,max_){
    if(i==res)continue;
    ans.push_back(i);

}
rep(i,ans.size())cout<<ans[i]<<endl;
return 0;
}

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

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 3005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t;
int cev;
string s;
double d[li],dp[3005][3005],dp1[3005][3005];
vector<int> v;

inline double f(int sira,int kac){
	double cevv=0;
	if(sira>n){
		if(kac<=n/2)return 0;
		return 1;
	}
	if(dp[sira][kac]!=-1)return dp[sira][kac];
	cevv+=f(sira+1,kac+1)*d[sira];
	cevv+=f(sira+1,kac)*(1.0-d[sira]);
	return dp[sira][kac]=cevv;
}

int main(void){
	scanf("%d",&n);
	FOR{
		for(int j=0;j<=3005;j++)dp[i][j]=-1;
	}
	FOR{
		scanf("%lf",&d[i]);
	}
	printf("%.18lf\n",f(1,0));
	return 0;
}


Measured memory_bytes: 71808
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
    int n,q;
    cin>>n;
    vector<long long> a(int(1e5)+1,0);
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        a[x]++;
    }
    long long sm=0;
    for(int i=0;i<a.size();i++) sm+=(a[i]*i);
    cin>>q;
    for(int i=0;i<q;i++){
        int b,c;
        cin>>b>>c;
        long long del=a[b]*(c-b);
        a[c]+=a[b];
        a[b]=0;
        sm+=del;
        cout<<sm<<"\n";
    }
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

    solve();
    return 0;
}

Measured memory_bytes: 3960
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _h cout<<"here"<<endl;
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i,n) for(int i=0;i<n;i+=1)
#define prarr(a,n) rep(i,n) cout<<a[i]<<" \n"[i==n-1];// printf("%s\n"," " );
#define ff first
#define ss second
#define pu push_back
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T> 
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.ff<<", "<<p.ss<<')';return out;}
template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}
template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
const int inf = 1e9+10;
const ll INF = 1e18+10;
const int MOD = 1e9+7;
const int MAXN = 2e5+10;

void solve()
{
	ll n;
	cin>>n;
	ll ans = 0;
	if(n&1){
		cout<<0<<endl;
		return;
	}
	n/=2;
	ll pw = 5;
	while(pw<=n){
		ans+=n/pw;
		pw*=5;
	}
	cout<<ans<<endl;
}
int main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin>>t;
	while(t--){
		solve();
	}
	return 0;

}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){

	string s;
	cin >> s;
	string t = "keyence";
	if (s==t) {
		cout << "YES" << endl;
		return 0;
	}
	rep(i, (int)s.size()) {
		FOR(j, i, (int)s.size()) {
			string fi = s.substr(0, i);
			string se = s.substr(j+1);

			if (fi+se == t) {
				cout << "YES" << endl;
				return 0;
			}
		}
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int H,W; cin >> H >> W;
    int ans=999999999;
    for(int i=1;i<H;i++){
        int a[3]={i*W,(H-i)*(W/2),(W-W/2)*(H-i)};
        sort(a,a+3); 
        ans = min(ans,a[2]-a[0]);
    }
    for(int i=1;i<W;i++){
        int b[3]={i*H,(W-i)*(H/2),(H-H/2)*(W-i)};
        sort(b,b+3);
        ans = min(ans,b[2]-b[0]);
    }
    ans = min(ans,(H%3==0 ? 0 : W));
    ans = min(ans,(W%3==0 ? 0 : H));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//author: Harsh :)
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define maxN 100007
using namespace std;
bool check(ll i, ll j, ll k, ll n) {
  if (i * i + j * j + k * k + i * j + j * k + k * i <= n)
    return true;
  else
    return false;
}
ll value(ll i, ll j, ll k, ll n) {
  ll x = i * i + j * j + k * k + i * j + j * k + k * i;
  return x;
}
int main() {
  fastio;
  ll n = 0;
  cin >> n;
  ll ar[n + 1] = {0};
  for (ll i = 1; i * i <= n; ++i) {
    for (ll j = 1; j * j <= n; ++j) {
      for (ll k = 1; k * k <= n; ++k) {
        if (check(i, j, k, n))
          ++ar[value(i, j, k, n)];
        else
          break;
      }
    }
  }
  for (ll i = 1; i <= n; ++i)
    cout << ar[i] << "\n";
}



Measured memory_bytes: 3668
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
    int L, N;
    cin >> N >> L;

    vector<string> S(N);
    int i;
    for (i=0; i<N; i++) {
        cin >> S[i];
    }
    sort(S.begin(), S.end());
    for (i=0; i<N; i++) {
        cout << S[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int s[100005];
bool a[100005];
int main(){
    fill(s,s+100005,1);
    a[0]=true;
    int b;cin>>b>>b;
    for(int c=0;c<b;c++){
	int d,e;scanf("%d%d",&d,&e);
	d--;e--;
	if(a[d]){
	    if(s[d]==1)a[d]=false;
	    a[e]=true;
	    }
	    s[d]--;s[e]++;
	}
	int sum=0;
	for(int i=0;i<100005;i++){if(a[i])sum++;}
	cout<<sum<<endl;
    }

Measured memory_bytes: 768
// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).split('\n');
main();
 
// ここから
function main(){
  for(var i = 0, len = input.length - 1; i < len; i++){
    var target = input[i] - 0;
    var pattern = 0;
    for(var a = 0; a <= 9; a++){
      if(a > target)
        continue;

      for(var b = 0; b <= 9; b++){
        if(a + b > target)
          continue;

        for(var c = 0; c <= 9; c++){
          if(a + b + c > target)
            continue;

          for(var d = 0; d <= 9; d++){
            if(a + b + c + d == target)
              pattern++;
          }
        }
      }
    }
    console.log(pattern);
  }
}

Measured memory_bytes: 8684
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
typedef long double la;
using namespace std;
 
int main(){
    int n,d,x,sum=0;
    cin >> n >> d >> x;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];

    for(int i=0;i<n;i++){
        int count=0;
        for(int j=1;j<=d;j+=a[i]){
            count++;
        }
        sum += count;
    }
    cout << sum+x << endl;
}

Measured memory_bytes: 256
#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 = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int n, a[MAX], ans[MAX];
vector<int> x, G[MAX];
int dp[MAX];

void dfs(int v, int pv){
    ans[v] = lower_bound(dp, dp+MAX, a[v]) - dp;
    int tmp = dp[ans[v]];
    chmin(dp[ans[v]], a[v]);
    for(auto nv: G[v])if(nv != pv) dfs(nv, v);
    dp[ans[v]] = tmp;
}

void dfs2(int v, int pv){
    for(int nv: G[v])if(nv != pv){
        chmax(ans[nv], ans[v]);
        dfs2(nv, v);
    }
}

int main(){
    scanf("%d", &n);
    rep(i, n){
        scanf("%d", &a[i]);
    }
    rep(i, n-1){
        int u, v;
        scanf("%d%d", &u, &v);
        --u; --v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    fill(dp, dp+MAX, mod);
    dp[0] = 0;
    dfs(0, -1);
    dfs2(0, -1);
    rep(i, n) printf("%d\n", ans[i]);
}

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

int n, temp, ans;
deque<int> s;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> temp;
        if(temp%10!=0) s.push_back(temp);
        ans+=temp;
    }
    sort(s.begin(), s.end());
    while(ans%10==0&&!s.empty()) {
        ans-=s.front();
        s.pop_front();
    }
    if(ans%10==0) cout<<0;
    else cout << ans;

    return 0;
}

Measured memory_bytes: 256
using System.Collections.Generic;
using static System.Console;
class Program
{
    static void Main(string[] args)
    {
        var str = ReadLine();
        var charas = new HashSet<string>();
        var isContain = false;
        for(var i = 0; i < str.Length; i++)
        {
            var chara = str.Substring(i, 1);
            if (charas.Contains(chara)) { isContain = true;break; }
            charas.Add(chara);
        }
        var result = isContain ? "no" : "yes";
        WriteLine(result);
    }
}


Measured memory_bytes: 13280
// ConsoleApplication70.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include<cstring>
#include<string>
#include <iostream>
using namespace std;
int main()
{
	int aa, bb;
    char a[15], b[15], c[15];
	while (cin>>a>>b)
	{
		cin >> aa >> bb;
		cin >> c;
		if (!strcmp(a, c))
		{
			aa--;
		}
		else if (!strcmp(b, c))
		{
			bb--;
		}
		cout << aa << " " << bb << "\n";
	}

   
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>  // min, max
#include <fstream>  // ifstream
#include <iomanip>  // setprecision
using namespace std;
typedef long long ll;

int main(void)
{
#ifdef FILE_DEBUG
    ifstream inputFile("data/input.txt");
    cin.rdbuf(inputFile.rdbuf());
#endif
    // これより下にコードを書く

    int K;
    cin >> K;

    int foo = K/2;
    if (K % 2 == 0) {
        cout << (foo * foo) << endl;
    } else {
        cout << (foo * (foo + 1)) << endl;
    }

    return 0;
}


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

int main()
{
	string s;
	cin >> s;
	for(int i = s.size();;){
		if(i == 0){
			cout << "YES" << endl;
			return 0;
		}
		if(i < 5) break;
		if(s.substr(i-5, 5) == "erase" || s.substr(i-5, 5) == "dream"){
			i -= 5;
			continue;
		}
		if(i < 6) break;
		if(s.substr(i-6, 6) == "eraser"){
			i -= 6;
			continue;
		}
		if(i < 7) break;
		if(s.substr(i-7, 7) == "dreamer"){
			i -= 7;
			continue;
		}
		break;
	}
	cout << "NO" << endl;
	return 0;
	
}

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

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

int n, m;
int a[1000], s[1000];

int main() {
	ios::sync_with_stdio(false);
	
	while(cin>>n>>m,n|m) {
		rep(i, n)cin >> a[i];
		rep(i, m)cin >> s[i];
		int c=0, t=0;
		while(t<n-1) {
			t += a[t];
			if(t>=n-1)break;
			t += s[c];
			c++;
		}
		cout << c << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1204
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<list>
#define X first
#define Y second
#define INF 987654321
#define PI 3.14159265358979323
#define MOD 20091101
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
ll gcd(ll a, ll b)
{
	return b ? gcd(b, a%b) : a;
}
ll res(ll n) { return 3 * (n - 1); }
int main() {
	ll n, x;
	scanf("%lld%lld", &n, &x);
	ll t = gcd(n, x);
	printf("%lld", res(n/t)*t);
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn vs(a: &mut Vec<Vec<usize>>, n: usize, p1: usize, p2: usize, done: &mut Vec<bool>) -> bool {
    if done[p2 - 1] {
        a[p1 - 1].push(p2);
        done[p1 - 1] = true;
        return false;
    } else if let Some(p3) = a[p2 - 1].pop() {
        if p1 != p3 {
            done[p1 - 1] = true;
            a[p1 - 1].push(p2);
            return vs(a, n, p2, p3, done);
        }
        done[p1 - 1] = true;
        done[p2 - 1] = true;
        return true;
    }
    false
}

fn day(a: &mut Vec<Vec<usize>>, n: usize) -> u32 {
    let mut done: Vec<bool> = vec![false; n];
    let mut cnt: u32 = 0;
    for p1 in 1..(n + 1) {
        if done[p1 - 1] {
            continue;
        } else if let Some(p2) = a[p1 - 1].pop() {
            if vs(a, n, p1, p2, &mut done) {
                cnt += 1;
            }
        }
    }
    cnt
}

fn all(a: &mut Vec<Vec<usize>>, n: usize) -> i32 {
    let mut vs_cnt: u32 = 0;
    let mut day_cnt: i32 = 0;

    while vs_cnt < ((n * (n - 1)) / 2) as u32 {
        let tmp = day(a, n);
        if tmp == 0 {
            day_cnt = -1;
            break;
        } else {
            vs_cnt += tmp;
        }
        day_cnt += 1;
    }

    return day_cnt;
}

fn gcd(x: u64, y: u64) -> u64 {
    if x > y {
        gcd_sub(x, y)
    } else {
        gcd_sub(y, x)
    }
}

fn gcd_sub(x: u64, y: u64) -> u64 {
    let r = x % y;
    if r == 0 {
        y
    } else {
        gcd_sub(y, r)
    }
}

fn main() {
    let s: String = read();
    let cv: Vec<char> = s.chars().collect();
    let mut oe: bool = true;
    let mut ans = true;
    for c in cv {
        if (oe && c == 'L') || (!oe && c == 'R') {
            ans = false;
            break;
        }
        oe = !oe;
    }
    if ans {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
 
int main() {
    int i,j,k,n,d,a[5],b[5],f,h;
    while(cin >> n && n>0) {
	for (i=0;i<5;i++) cin >> a[i];
	if (a[1]-a[0]==a[2]-a[1] && a[2]-a[1]==a[3]-a[2] && a[3]-a[2]==a[4]-a[3]) { f=0; h=a[4];} else {
	f=1;	
    for (i=0;i<5;i++) {	
		 for (j=0,h=0;j<4;j++) { if (h==i) h++; b[j]=a[h++]; }
		 if (b[1]-b[0]==b[2]-b[1] && b[2]-b[1]==b[3]-b[2]) k=a[i]; 
		}
	}
	for (i=5;i<n+1;i++) {
		cin >> d;
		if (f==0 && d-h!=a[1]-a[0]) { k=d; f=1;}
		h=d;
	}
	cout << k << endl;
   } 
  return 0;
} 

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

int main() {
  int D;
  cin >> D;
  
  if (D == 25) cout << "Christmas" << endl;
  if (D == 24) cout << "Christmas Eve" << endl;
  if (D == 23) cout << "Christmas Eve Eve" << endl;
  if (D == 22) cout << "Christmas Eve Eve Eve" << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
using namespace std;
#define ll long long
#define INF 1000000007
typedef pair<int,int> P;

int main(){
    string a;
    int s[20];
    cin>>a;
    ll ans=0;
    int n=(int)a.size();
    for(int i=0;i<n;i++)s[i]=a[i]-'0';
    for(int bit=0;bit<(1<<(n-1));bit++){
        int count=0;
        ans+=s[n-1];
        for(int i=n-2;i>=0;i--){
            if(bit&(1<<i)){
                count++;
            }else{
                count=0;
            }
            ans+=s[i]*pow(10,count);
        }
    }
    cout<<ans<<endl;
}


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

int main() {
    int a,b,c,ans=10000000;
    cin>>a>>b>>c;
    ans=min(ans,a+b);
    ans=min(ans,b+c);
    ans=min(ans,c+a);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    
    int w,a,b;
    
    scanf( "%d %d %d",&w,&a,&b );
    
    if( a+w < b ) {
        printf( "%d\n",b-(a+w) );
    }
    else if ( a+w > b ){
        if( b+w < a) printf( "%d\n",a-(b+w) );
        else printf( "0" );

    }
    else printf( "0" );
    
    return 0;
}

Measured memory_bytes: 128
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		int n, a, b = 0;
		int[] page;
		boolean flag = false;
		
		while (true) {
			n = sc.nextInt();
			if (n == 0) break;
			
			StringBuilder sb = new StringBuilder();
			
			page = new int[n + 1];
			for (int i = 0; i < n; i++) {
				page[i] = sc.nextInt();
			}
			
			flag = false;
			for (int i = 0; i < n; i++) {
				a = page[i];
				flag = false;
				for (int j = i + 1; j < n; j++) {
					if (page[j] - page[j - 1] == 1) {
						flag = true;
						b = page[j];
					} else {
						break;
					}
					i++;
				}
				if (flag) {
					sb.append(a);
					sb.append("-");
					sb.append(b);
				} else {
					sb.append(a);
				}
				
				if (i < n - 1) {
					sb.append(" ");
				}
			}
			
			out.println(sb.toString());
		}
		
		out.flush();
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) return false;
		}
		return true;
	}
	
	private byte readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	
	private boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}
	
	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}
	
	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}
	
	public int nextInt() {
		if (!hasNext()) { throw new NoSuchElementException(); }
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) { throw new NumberFormatException(); }
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	
}

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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D ;
  

  if ((A+B) >(C+D)) {
    cout << "Left" << endl;
  }
  else if ((A+B) == (C+D)){
    cout << "Balanced" << endl;
  }
    else{
      cout << "Right" <<endl;
  }
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int[] sieve(int n) {
    assert(n > 1);
    auto t = new bool[n + 1];
    int[] primes = [2];
    for (int i = 3; i < t.length; i += 2) {
        if (!t[i]) {
            primes ~= i;
            for (int j = i + i; j < t.length; j += i)
                t[j] = true;
        }
    }
    return primes;
}

void main() {
    int n = 10 ^^ 5;
    auto pmap = new bool[n + 1];
    foreach (p; sieve(n)) pmap[p] = true;

    bool isLike(int n) {
        if (n % 2 == 0) return false;
        if (pmap[n] && pmap[(n + 1) / 2]) return true;
        return false;
    }

    auto t = new int[n + 1];
    for (int i = 3; i <= n; i++) {
        t[i] = t[i - 1] + (isLike(i) ? 1 : 0);
    }

    int q = readint;
    for (int i = 0; i < q; i++) {
        auto lr = readints;
        int l = lr[0];
        int r = lr[1];

        writeln(t[r] - t[l - 1]);
    }
}


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

struct data{
	double b;
	double r;
	double t;
	double g;
};

bool operator<(const data &data1,const data &data2){
	return data1.g < data2.g;
};

int main(){
	int n,y;
	while(true){
		cin >> n;
		if(!n)break;
		cin >> y;
		priority_queue<data> q;
		for(int i = 0; i < n; i++){
			data d;
			cin >> d.b >> d.r >> d.t;
			if(d.t == 1){
				d.g = 1 + y * d.r / 100;
			}
			else{
				d.g = 1 + d.r / 100;
				double j = d.g;
				for(int i = 0; i < y - 1; i++){
					d.g *= j;
				}
			}
			q.push(d);
		}
		cout << q.top().b << endl;
	}
	return 0;
}



Measured memory_bytes: 3292
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>

using namespace std;

vector<int> total;
vector<int> coin;
const int INF = 10000000;
int n, m;

int main()
{
	scanf("%d %d", &n, &m);

	for (int i = 0; i < m; i++)
	{
		int c;
		scanf("%d", &c);

		coin.push_back(c);
	}

	for (int i = 0; i <= n; i++)
	{
		total.push_back(INF);
	}

	total[0] = 0;

	for (int i = 0; i < m; i++)
	{
		for (int j = coin[i]; j <= n; j++)
		{
			total[j] = min(total[j], total[j - coin[i]] + 1);
		}
	}

	printf("%d\n", total[n]);

	return 0;
}

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

typedef long long ll;
typedef tuple<int, int, int, ll> T;

int N;
int fst[400];
int dx[9] = {0, 0, 1, 0, -1, 0, 2, 0, -2};
int dy[9] = {0, -1, 0, 1, 0, -2, 0, 2, 0};
set<T> memo;

bool rain(int px, int py,  int idx){
	int cloud = px + py * 4;
	return cloud == idx || cloud + 1 == idx || cloud + 4 == idx || cloud + 5 == idx;
}

bool dfs(int day, int px, int py,  ll state){
	//printf("Day %d (%d %d)\n", day, px, py);

	if(day >= N) return true;
	if(memo.count(T(day, px, py, state))) return false;
	memo.insert(T(day, px, py, state));
	int rainy = 0;
	for(int y = 0; y < 4; y++){
		for(int x = 0; x < 4; x++){
			ll idx = x + y * 4;
			ll cnt = (state >> (idx * 3LL)) & 7LL;
			if(rain(px, py, idx)) {
				cnt = 0;
				rainy |= (1 << idx);
			}else{
				cnt++;
			}

			if(cnt >= 7) return false;
			state = (state & ~(7LL << (idx * 3LL))) | (cnt << (idx * 3LL));
		}
	}
	if((fst[day] & rainy)) return false;
	for(int i = 0; i < 9; i++){
		int nx = px + dx[i];
		int ny = py + dy[i];
		if(0 <= nx && nx <= 2 && 0 <= ny && ny <= 2){
			if(dfs(day + 1, nx, ny, state)) return true;
		}
	}
	return false;
}

int main(){
	while(cin >> N, N){
		for(int i = 0; i < N; i++){
			fst[i] = 0;
			for(int j = 0; j < 16; j++){
				int v;
				cin >> v;
				fst[i] |= (v << j); 
			}
		}
		memo.clear();
		if(dfs(0, 1, 1, 0)){
			cout << 1 << endl;
		}else{
			cout << 0 << endl;
		}
	}
}

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

vector<int> g[1000];
ll x[1000];

// そこ自身以外で提供可能な最小の数
// 根は0

int dfs(int i) {
  if((int) g[i].size() == 0) return 0;
  bitset<5001> dp(1);
  ll s = 0;
  for(int j : g[i]) {
    ll d = dfs(j);
    if(d == -1) return -1;
    dp = (dp << x[j]) | (dp << d);
    s += x[j] + d;
  }
  for(int k = x[i]; k >= 0; k--) {
    if(dp[k]) return s - k;
  }
  return -1;
}

int solve() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n; cin >> n;
  for(int i = 1; i < n; i++) {
    int p; cin >> p; p--;
    g[p].emplace_back(i);
  }
  for(int i = 0; i < n; i++) cin >> x[i];
  return dfs(0) != -1;
}

int main() {
  cout << (solve() ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}



Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int A, B, C, X, ans = 0;

	cin >> A >> B >> C >> X;

	repc(a, 0, A) {
		repc(b, 0, B) {
			repc(c, 0, C) {
				if (500 * a + 100 * b + 50 * c == X) ans++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


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

template<class T, class E, class C = std::less<T>>
struct SkewHeap {
    using F = function<T(T, E)>;
    using G = function<E(E, E)>;
    using value_type = T;
    using operation_type = E;
private : 
    C compare;
    const F f;
    const G g;
    const E ie;
    int sz;

    struct node_data {
    public : 
        value_type val;
        operation_type add;
        unique_ptr<node_data> left_node, right_node;
        node_data(const value_type &val, const operation_type &add) :
            val(val), add(add), left_node(nullptr), right_node(nullptr) { }
    };

    using node_type = unique_ptr<node_data>;

    node_type root;

public : 
    SkewHeap() : f([](const T &a, const E &b) { return (a + b); }),
                 g([](const E &a, const E &b) { return (a + b); }),
                 ie(E()) { }

    SkewHeap(const F &f, const G &g, const E &ie) : f(f), g(g), ie(ie), root(nullptr), sz(0) { }

    node_type propagate(node_type node) {
        if (node == nullptr) return (move(node));
        if (node->add == ie) return (move(node));
        if (node->left_node) {
            node->left_node->add = g(node->left_node->add, node->add);
        }
        if (node->right_node) {
            node->right_node->add = g(node->right_node->add, node->add);
        }
        node->val = f(node->val, node->add);
        node->add = ie;
        return move(node);
    }

    node_type meld(node_type a, node_type b) {
        if (not a) return b;
        if (not b) return a;
        if (compare((b->val), (a->val))) a.swap(b);
        a = propagate(move(a));
        a->right_node = meld(move(a->right_node), move(b));
        a->left_node.swap(a->right_node);
        return a;
    };

    int size() const noexcept {
        return size_t(sz);
    }

    bool empty() const noexcept {
        return (sz == 0);
    }

    void insert(const value_type &x) {
        root = propagate(move(root)); sz++;
        root = meld(move(root), make_unique<node_data>(move(node_data(x, ie))));
    }

    value_type& top() {
        assert(not empty());
        root = propagate(move(root));
        return (root->val);
    }

    value_type pop() {
        const value_type top_value = top(); sz--;
        root = meld(move(root->left_node), move(root->right_node));
        return top_value;
    }

    void add(const operation_type &x) noexcept {
        if (root) root->add = g(root->add, x);
    }

    void meld(SkewHeap &skew) {
        sz += skew.sz; skew.sz = 0;
        root = meld(move(root), move(skew.root));
    }

};

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

    SkewHeap<int, int, greater<int>> skew;

    for (int i = 0; i < n; i++) {
        int e;
        cin >> e;
        skew.insert(e);
    }

    for (int i = 0; i < m; i++) {
        int e = skew.pop();
        skew.insert(e / 2);
    }

    long long ans = 0;
    while (skew.size()) ans += skew.pop();

    cout << ans << '\n';

    return 0;
}


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

vector<int>to[200005];
vector<int>ans;
void dfs(int v,int p=-1){
  for(int u:to[v]){
    if(u==p)continue;
    ans[u]+=ans[v];
    dfs(u,v);
  }
}


int main() {
  int N,Q;cin>>N>>Q;
  rep(i,N-1){
    int a,b;cin>>a>>b;
    a--;b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(N);
  rep(i,Q){
    int p,x;cin>>p>>x;
    p--;
    ans[p]+=x;
  }
  dfs(0);
  rep(i,N){cout<<ans[i]<<endl;}
}

Measured memory_bytes: 23424
#if 0
date +%Y.%m.%d

题解先咕着。
#endif
#include <cstdio>
#include <cstring>
#define debug(...) fprintf(stderr, __VA_ARGS__)

inline int input() { int x; scanf("%d", &x); return x; }

const int maxn = 200005;
char s[maxn];

int main() {
	scanf("%s", s);
	int n = int(strlen(s)), last = -1, ans = 0;
	for(int i = 0; i < n; i ++) {
		if(last != -1 and last == s[i]) {
			i ++;
			last = -1;
		} else
			last = s[i];
		if(i < n)
			ans ++;
		// debug("%d %d\n", i, last);
	}
	printf("%d\n", ans);
}

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

int n;
void dfs(string s, char mx) {
    if (s.size() == n) {
        cout << s << endl;
        return;
    }
    for (char c = 'a'; c <= mx + 1; c++) {
        string t = s;
        t += c;
        dfs(t, max(mx, c));
    }
}

int main(){
    cin >> n;
    dfs("", 'a' - 1);
    return 0;
}

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

using namespace std;

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

int main(){

	int n;
	priority_queue<int> a;

	cin >> n;

	REP(n){
		int tmp;
		cin >> tmp;
		a.push(tmp);
	}

	//sort(a.rbegin(), a.rend());

	int alice = 0, bob = 0;

	REP(n){
		i % 2 == 0 ? alice += a.top() : bob += a.top();
		a.pop();
	}

	cout << alice - bob << endl;
	
	return 0;

}

Measured memory_bytes: 256
n,m = [int(x) for x in input().split()];
pair = [];
(a,b) = (int(x) for x in input().split());
pair.append((a,b));
for i in range(1,n) :
    (a,b) = (int(x) for x in input().split());
    pair.append((a,b));

#newlst = sorted(pair,cmp=lambda x,y:cmp(x[0],y[0]));
pair = sorted(pair,key=lambda x:x[0]);

sum =0;
i = 0;
while m > 0 :
    if m >= pair[i][1] :
        m = m - pair[i][1];
        sum = sum + pair[i][0] * pair[i][1];
        i = i +1;
    else :
        sum = sum + m*pair[i][0];
        m = 0;

print(sum);
 

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

set<int> inds[128];

int main() {
#ifndef ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
#endif
    string s, t;
    cin >> s >> t;
    for(int i=0; i<s.size(); i++){
        inds[s[i]].insert(i);
    }
    int cur = -1, rounds =0;
    for(int i=0; i<t.size(); i++){
        if(inds[t[i]].empty()){
            puts("-1");
            return 0;
        }
        auto it = inds[t[i]].upper_bound(cur);
        if(it == inds[t[i]].end())
            cur = *inds[t[i]].upper_bound(-1), rounds++;
        else
            cur = *it;
    }

    cout << 1ll * rounds * (long long)s.size() + cur + 1 << "\n";
    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main() {
  ll n, k; cin >> n >> k;
  vector <ll> v(n);
  rep(i, n) cin >> v.at(i);
  sort(v.begin(), v.end());
  ll res;
  if (k%2) {
    res = v.at(n-1);
    ll be = 0, en = n-2;
    if (res < 0) {
      while (k-1) {
        k -= 2;
        ll tmp1 = v.at(be)*v.at(be+1);
        ll tmp2 = v.at(en-1)*v.at(en);
        if (tmp1 >= tmp2) {
          res *= tmp2%mod;
          res %= mod;
          en -= 2;
        } else {
          res *= tmp1%mod;
          res %= mod;
          be += 2;
        }
      }
    } else {
      while (k-1) {
        k -= 2;
        ll tmp1 = v.at(be)*v.at(be+1);
        ll tmp2 = v.at(en-1)*v.at(en);
        if (tmp1 >= tmp2) {
          res *= tmp1%mod;
          res %= mod;
          be += 2;
        } else {
          res *= tmp2%mod;
          res %= mod;
          en -= 2;
        }
      }
    }
  } else {
    res = 1;
    ll be = 0, en = n-1;
    while (k) {
      k -= 2;
      ll tmp1 = v.at(be)*v.at(be+1);
      ll tmp2 = v.at(en-1)*v.at(en);
      if (tmp1 >= tmp2) {
        res *= tmp1%mod;
        res %= mod;
        be += 2;
      } else {
        res *= tmp2%mod;
        res %= mod;
        en -= 2;
      }
    }
  }
  if (res < 0) cout << (res+mod)%mod << endl;
  else cout << res << endl;
}

Measured memory_bytes: 4840
#include<stdio.h>
#define BUFSIZE 10000

int main(void)
{
    char S_hoge[BUFSIZE] = { 0 };
    char T_hoge[BUFSIZE] = { 0 };
    int N;
    scanf("%d", &N);

    for (int i = 0; i < N; i++) {
        scanf(" %c", &S_hoge[i]);
    }
    for (int i = 0; i < N; i++) {
        scanf(" %c", &T_hoge[i]);
    }
    for (int i = 0; i < N; i++) {
        printf("%c%c", S_hoge[i], T_hoge[i]);
    }
    return 0;
}


Measured memory_bytes: 128
n = int( input() )
a = sorted( list( map( int, input().split())))

res = a[0]

while True:
    base = res
    total = 0
    for i in a:
        if  i % base > 0:
            res = min( res, i % base)
        total +=  i % base
    if total == 0:
        break

print(base)



Measured memory_bytes: 62704
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())




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

	int n;
	unordered_multiset<long long> s;
	cin >> n;
	rep(i,n) {
		int a;
		cin >> a;
		s.insert(a);
	}
	int ans = 0;
	for(int i=31;i>=0;i--){
		auto x = 1LL << i;

		for (auto it = s.begin(); it != s.end() ;) {
			auto rem = x - *it;
			if (rem <= 0) {
				++it;
				continue;
			}
			if (rem == *it) {
				auto it2 = it;
				++it2;
				if (it2!=s.end() && *it2 == rem) {
					it = s.erase(it);
					it = s.erase(it);
					ans++;
				}
				else {
					++it;
				}
			}
			else {
				auto it2 = s.find(rem);
				if (it2 != s.end()) {
					s.erase(it2);
					it = s.erase(it);
					ans++;
				}
				else {
					++it;
				}
			}

		}
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 8520
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,st,en) for(i=st;i<=en;i++)
#define repv(i,en,st) for(i=en;i>=st;i--)
#define fout cout<<fixed<<setprecision(7)
#define bi(n) __builtin_popcount(n)
#define bil(n) __builtin_popcountll(n)


typedef long long ll;
typedef pair<int,int> pii;
const int N = 100010;
ll mod = 1e9+7;
ll fmod(ll b,ll exp){
    ll res =1;
    while(exp){if(exp&1ll)res=(res*b)%mod;
    b =(b*b)%mod;exp/=2ll;
    }
    return res;
}
vector<int> adj[N];
int vis[N],A[N];
int u,v;
int dp[N];
int len = 0;
void dfs(int i)
{
    vis[i]=1;
    for(auto ve:adj[i])
    {
        if(!vis[ve])dfs(ve);
    }
    A[++len]=i;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int t=1,n,i,j,m;
    cin>>n>>m;
    rep(i,1,m){
        cin>>u>>v;
        adj[u].pb(v);
    }
    rep(i,1,n)if(!vis[i])dfs(i);
    int ans = 0;
    rep(i,1,n)
    {
        int ind = A[i];
        for(auto ve:adj[ind])
         dp[ind]= max(dp[ind],dp[ve]+1);
        ans = max(ans,dp[ind]);
    }
    cout<<ans<<"\n";




    
    return 0;
}


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

int main(){
    int n;
    double base = 0.00;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        base += 1.00/a[i];
    }
    cout << setprecision(16) << 1.00/base << endl;

    return 0;
}

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

int sum(int i) {
  int ans = 0;
  if (i<10) ans += i%10;
  else if (i<100) ans += i/10+sum(i%10);
  else if (i<1000) ans += i/100+sum(i%100);
  else if (i<10000) ans += i/1000+sum(i%1000);
  else ans = 1;
  return ans;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int ans = 0;
  for (int i=1; i<N+1; i++) {
    if (A-1<sum(i)&&sum(i)<B+1) ans += i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256