akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			int[] tmpArr = Console.ReadLine().Trim().Split(' ').Select(hogehoge => int.Parse(hogehoge)).ToArray<int>();

			int n = tmpArr[0];
			int m = tmpArr[1];

			int[] tmp = new int[n];
			int[] ans = new int[n];

			for (int i = 0; i < m; i++)
			{
				int[] arr = Console.ReadLine().Trim().Split(' ').Select(hogehoge => int.Parse(hogehoge)).ToArray<int>();

				if (arr[0] == 1 && arr[1] == 0 && n != 1)
				{
					Console.WriteLine(-1);
					return;
				}
				if (tmp[arr[0] - 1] != -1)
				{
					ans[arr[0] - 1] = arr[1];
					tmp[arr[0] - 1] = -1;
				}
				else
				{
					if (ans[arr[0] - 1] == arr[1]) continue;
					Console.WriteLine(-1);
					return;
				}
			}

			if (ans[0] == 0 && n != 1)
			{
				ans[0] = 1;
			}

			for (int i = 0; i < n; i++)
			{
				Console.Write(ans[i]);
			}

			return;
		}


	}


}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = (1 << 30);
constexpr ll L_INF = (1ll << 62);

//==================================

class UnionFind {
private:
    Vi rank;
    Vi par;

public:
    UnionFind(int n) : rank(n), par(n) {
        for (int i = 0; i < n; ++i) {
            par[i] = i;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            return par[x] = root(par[x]);
        }
    }

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

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;

        if (rank[x] < rank[y]) {
            par[x] = y;
        }
        else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x];
        }
    }
};

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

    int N, M;
    cin >> N >> M;

    Vi X(M), Y(M), Z(M);
    for (int i = 0; i < M; ++i) {
        int x, y, z;
        cin >> x >> y >> z;
        --x, --y;
        X[i] = x;
        Y[i] = y;
        Z[i] = z;
    }

    UnionFind uf(N);

    for (int i = 0; i < M; ++i) {
        uf.unite(X[i], Y[i]);
    }

    unordered_set<int> us;
    for (int i = 0; i < N; ++i) {
        us.insert(uf.root(i));
    }

    cout << us.size() << endl;

    return 0;
}

Measured memory_bytes: 6308
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
int main() {
    int i,j,n,b,c,x;
    int flag=0;
    int count=1;
    int sum=0;
    int souwa=0;
    int max=0;
    int temp;
    cin>>n;
   int d[n];
   for(i=0; i<n; ++i){
       cin>>d[i];
   }
   sort(d,d+n);
   temp=d[0];
   for(i=1; i<n; ++i){
       if(temp!=d[i]){++count;temp=d[i];}
   }
   cout<<count;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int main() {
	//freopen("a.in", "r", stdin);
	int n; scanf("%d", &n);
	for(int i = 1; i <= n; ++ i) {
		scanf("%d", &a[i]);
	}
	sort(a + 1, a + n + 1);
	int mx = 1;
	for(int i = 2; i <= n; ++ i) {
		if(min(a[n] - a[i], a[i]) > min(a[n] - a[mx], a[mx])) {
			mx = i;
		}
	}
	printf("%d %d\n", a[n], a[mx]);
}

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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

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

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n)
    {
        if(n & 1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return result;
}



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

    int n,x,t;
    cin>>n>>x>>t;
    int ans=(n+x-1)/x*t;
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

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

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	sc.close();
    	int ans = 1;
    	if(N == 1 || N == 2 || N == 4){
    		System.out.println(4);
    		System.exit(0);
    	}
    	while(true){
    		if(N % 2 == 0){
    			N = N / 2;
    			ans++;
    		}else{
    			N = N * 3 + 1;
    			ans++;
    		}
    		if(N == 4) break;
    	}
    	System.out.println(ans + 3);
    }
}

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

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

    int i1 = 1;
    int i2 = M + 2;
    for (int d = M; d >= 1; d--) {
        cout << i1 << " " << i1 + d << endl;
        i1++;
        swap(i1, i2);
    }
}


Measured memory_bytes: 3612
local n, m = io.read("*n", "*n")
local t = {}
for i = 1, n do t[i] = true end
for i = 1, m do
  local a, b = io.read("*n", "*n")
  t[a] = not t[a]
  t[b] = not t[b]
end
local ret = true
for i = 1, n do ret = ret and t[i] end
print(ret and "YES" or "NO")


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

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<long long> R(2*N);
    vector<long long> G(2*N);
    vector<long long> B(2*N);
    vector<long long> sumR(N+1);
    vector<long long> sumG(N+1);
    vector<long long> sumB(N+1);
    for(int i=0;i<N;i++){
        if(S[i] == 'R') R[i+1]++;
        if(S[i] == 'G') G[i+1]++;
        if(S[i] == 'B') B[i+1]++;
        sumR[i+1] = sumR[i] + R[i+1];
        sumG[i+1] = sumG[i] + G[i+1];
        sumB[i+1] = sumB[i] + B[i+1];
    }
    long long ans =0;
    for(int i=1;i<=N-2;i++){
        for(int j=1;i+j<=N-1;j++){
            ans += R[i]*G[i+j]*(sumB[N]-sumB[i+j]-B[i+2*j]);
            ans += R[i]*B[i+j]*(sumG[N]-sumG[i+j]-G[i+2*j]);
            ans += G[i]*B[i+j]*(sumR[N]-sumR[i+j]-R[i+2*j]);
            ans += G[i]*R[i+j]*(sumB[N]-sumB[i+j]-B[i+2*j]);
            ans += B[i]*R[i+j]*(sumG[N]-sumG[i+j]-G[i+2*j]);
            ans += B[i]*G[i+j]*(sumR[N]-sumR[i+j]-R[i+2*j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3716
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 310;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n;
ll a[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) cin >> a[i];
    ll xorSum = 0;
    FOR(i,3,n) xorSum ^= a[i];
    ll sum = a[1] + a[2];
    if (sum - xorSum < 0 || (sum - xorSum) % 2) {
        cout << -1;
        return 0;
    }
    ll andSum = (sum - xorSum) / 2;
    ll A = 0, B = 0;
    FORE(i,45,0)
        if (xorSum & (1LL << i)) {
            if (andSum & (1LL << i)) {
                cout << -1;
                return 0;
            }
            B |= (1LL << i);
        } else {
            if (andSum & (1LL << i)) {
                A |= (1LL << i);
                B |= (1LL << i);
            }
        }
    if (A > a[1]) {
        cout << -1;
        return 0;
    }
    FORE(i,45,0)
        if (xorSum & (1LL << i)) {
            if ((A ^ (1LL << i)) <= a[1]) {
                A ^= (1LL << i);
                B ^= (1LL << i);
            }
        }
    if (A == 0) {
        cout << -1;
        return 0;
    }
    cout << a[1] - A;
    return 0;
}


Measured memory_bytes: 3608
from collections import Counter
n = int(input())
a = [int(item) for item in input().split()]
cnt = Counter(a)

key_num = len(cnt.keys())
rank = [0] * key_num 
keys = list(cnt.keys())
keys.sort(reverse=True)
for i, key in enumerate(keys):
    rank[i] = cnt[key]
cur = [0] * key_num 
cur[0] = 1
for i in range(n):
    tmp = cur[:]
    free = 0
    for j in range(key_num):
        if rank[j] > cur[j] and free > 0:
            if cur[j] + free > rank[j]:
                free -= rank[j] - cur[j]
                cur[j] = rank[j]
            else:
                cur[j] += free
                free = 0
        free += tmp[j] 
if sum(cur) == 2**n:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 119752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);

const int N = 2e5+5, M = 1e6+6, OO = 0x3f3f3f3f, MOD  = 998244353;

long long power(ll a, ll b, ll m){  // Fast power with mod;
    if(!b)  return 1;
    ll t = power(a, b>>1, m)%m;
    return ((t*t)%m * (b&1 ? a : 1)%m)%m;
}

unsigned long long modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 

// int tc;
// int n, s;
// vector<int> vec;
// ll ans = 0;
// void solve(int idx = 0, int target = s)
// {
//     if(target == 0)
//     {
//         ans = (ans%MOD + power(2, (ll) n - (ll) vec.size(),MOD))%MOD;
//         cout<<vec.size()<<endl;
//             for(auto x : vec)
//                 cout<<x<<" ";
//             cout<<endl;
//             return;
//     }
//     if(idx == n)
//     {
//         return ;
//     }
//     if(arr[idx] <= target)
//     {
//         vec.push_back(arr[idx]);
//         solve(idx+1, target - arr[idx]);
//         vec.pop_back();
//         solve(idx+1, target);
//     }
//     else
//         solve(idx+1, target);
// }


ll mem[3005][3005];
ll arr[3005];


int main()
{
    FIO
    ll n, s;
    cin>>n>>s;
    for(int i = 0 ; i<n ; i++)
        cin>>arr[i];
    sort(arr, arr+n);
    if(arr[0] > s)
        return cout<<0, 0;
    for(int i = 0; i <= n ; i++)
        for(int j = 0; j <= s; j++)
            mem[i][j] = 0;

    ll tmp = modInverse(2, MOD);
    mem[0][0] = power(2, n, MOD);
    for(ll i = 0 ; i <= n ; i++)
    {
        for(ll j = 0 ; j <= s; j++)
        {
            mem[i+1][j] += mem[i][j];
            mem[i+1][j] %= MOD;
            if(j + arr[i] <= s)
            {
                mem[i+1][j + arr[i]] += (mem[i][j] * tmp);
                mem[i+1][j+arr[i]] %= MOD;
            }
        }
    }
    cout<<mem[n][s]<<endl;
    return 0;
}

Measured memory_bytes: 74144
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      (int)1e9+7
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;

int main(){
	llong n;
	cin>>n;
	
	int ans=INF;
	for(llong i=1;i*i<=n;++i){
		if(n%i==0){
			string s=to_string(n/i);
			ans=min(ans,(int)s.size());
		}
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int main()
{
    int n, c = 0;
    cin >> n;
    vector<int> h(n);
    int ans = 0;
    rep(i,n) cin >> h[i];
    rep(i,n-1){
        if(h[i] >= h[i+1]) c++;
        else c = 0;
        ans = max(ans,c);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(void)
{
   int a,b,c,d,e,f;

   scanf("%d%d%d%d",&a,&b,&c,&d);
   if(a<b) e=a;
   else e=b;

   if(c<d) f=c;
   else f=d;
   printf("%d\n",e+f);
   return 0;
}


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

int n, m, f[100001];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	for(int i = 0, a, b; i < m; i++) {
		cin >> a >> b;
		f[a]++;
		f[b]++;
	}
	for(int i = 1; i <= n; i++) if(f[i] % 2) cout << "NO", exit(0);
	cout << "YES";
}


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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

int a[3][3];
set<int> s;
bool in(int x) {
	return !!s.count(x);
}

void solve() {
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			scanf("%d", &a[i][j]);
		}
	}
	int n; scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		int b; scanf("%d", &b);
		s.insert(b);
	}
	bool ans = false;
	for (int i = 0; i < 3; ++i) {
		ans |= in(a[i][0])&&in(a[i][1])&&in(a[i][2]);
		ans |= in(a[0][i])&&in(a[1][i])&&in(a[2][i]);
	}
	ans |= in(a[0][0])&&in(a[1][1])&&in(a[2][2]);
	ans |= in(a[2][0])&&in(a[1][1])&&in(a[0][2]);
	puts(ans?"Yes":"No");
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define rep(i,n) for(i=0;i<n;i++)
#define For(i,a,n) for(i=a;i<n;i++)
//char s[100005][16];
//int cmp(const void*a,const void*b){
// return *(int*)a-*(int*)b;}
//int asc(const void*a,const void*b){
// return strcmp(s[*(int*)a],s[*(int*)b]);}
#define ll long long
ll i,j;

int main(){
  int m,d;
  scanf("%d%d",&m,&d);
  int p,q,l;
  l=0;
  for(j=1;j<m+1;j++){
    for(i=10;i<d+1;i++){
      p=i%10;q=i/10;
      if(p*q==j&&p>=2&&q>=2){
	l++;
      }
    }
  }
  printf("%d\n",l);
  return 0;}





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

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

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

  int n; cin >> n;
  vector<P> vec(n);
  rep(i, n) {
    ll x, y; cin >> x >> y;
    vec[i] = P(x, y);
  }
  map<P, int> mp;
  rep(i, n) {
    rep(j, n) {
      if (i==j) continue;
      auto x = vec[i].first - vec[j].first;
      auto y = vec[i].second - vec[j].second;
      mp[P(x,y)]++;
    }
  }
  int ma = 0;
  for(auto e: mp) {
    chmax(ma, e.second);
  }
  cout << n-ma << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

typedef long long ll;

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

void solve(){

}

int main(void){
  int t;
  int sum=0;
  for(int i=0;i<4;i++){
    cin>>t;
    sum+=t;
  }
  cout<<sum/60<<endl;
  cout<<sum%60<<endl;
}

Measured memory_bytes: 0
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

// ModInt begin

using ll = long long;
template<ll mod>
struct ModInt {
    ll v;
    ll mod_pow(ll x, ll n) const {
        return (!n) ? 1 : (mod_pow((x*x)%mod,n/2) * ((n&1)?x:1)) % mod;
    }
    ModInt(ll a = 0) : v((a %= mod) < 0 ? a + mod : a) {}
    ModInt operator+ ( const ModInt& b ) const {
        return (v + b.v >= mod ? ModInt(v + b.v - mod) : ModInt(v + b.v));
    }
    ModInt operator- () const {
        return ModInt(-v);
    }
    ModInt operator- ( const ModInt& b ) const {
        return (v - b.v < 0 ? ModInt(v - b.v + mod) : ModInt(v - b.v));
    }
    ModInt operator* ( const ModInt& b ) const {return (v * b.v) % mod;}
    ModInt operator/ ( const ModInt& b ) const {return (v * mod_pow(b.v, mod-2)) % mod;}
    
    bool operator== ( const ModInt &b ) const {return v == b.v;}
    bool operator!= ( const ModInt &b ) const {return !(*this == b); }
    ModInt& operator+= ( const ModInt &b ) {
        v += b.v;
        if(v >= mod) v -= mod;
        return *this;
    }
    ModInt& operator-= ( const ModInt &b ) {
        v -= b.v;
        if(v < 0) v += mod;
        return *this;
    }
    ModInt& operator*= ( const ModInt &b ) {
        (v *= b.v) %= mod;
        return *this;
    }
    ModInt& operator/= ( const ModInt &b ) {
        (v *= mod_pow(b.v, mod-2)) %= mod;
        return *this;
    }
    ModInt pow(ll x) { return ModInt(mod_pow(v, x)); }
    // operator int() const { return int(v); }
    // operator long long int() const { return v; }
};

template<ll mod>
ModInt<mod> pow(ModInt<mod> n, ll k) {
    return ModInt<mod>(n.mod_pow(n.v, k));
}

template<ll mod>
ostream& operator<< (ostream& out, ModInt<mod> a) {return out << a.v;}
template<ll mod>
istream& operator>> (istream& in, ModInt<mod>& a) {
    in >> a.v;
    return in;
}

// ModInt end


int main() {
    ll N, K; scanf("%lld%lld", &N, &K);

    ll ans = 0;
    for(ll i=K; i<=N+1; i++) {
        // K-1 ... 0
        ll lb = (i-1)*i/2;
        // N ... N-i+1
        ll ub = N*(N+1)/2 - (N-i)*(N-i+1)/2;
        ans += (ub - lb + 1);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3764
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      m1: usize,
      d1: usize,
      m2: usize,
      d2: usize,
    }
    if m1 != m2 {
        puts!("{}\n", 1);
    } else {
        puts!("{}\n", 0);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

map<ll, ll> prime_factorization(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while(n >= a*a){
    if(n % a == 0){
      ans[a]++;
      n /= a;
    }else{
      a++;
    }
  }
  ans[n]++;

  return ans;
}

int main(){
  int n;
  cin >> n;
  map<ll, ll> pt;
  rep2(i, 1, n+1){
    auto add = prime_factorization(i);
    for(auto p : add){
      pt[p.first] += p.second;
    }
  }

  repit(itr, pt){
    cerr << itr->first << " " << itr->second << endl;
  }

  int c74 = 0, c24 = 0, c14 = 0, c4 = 0, c2 = 0;
  for(auto p : pt){
    if(p.second >= 74) c74++;
    if(p.second >= 24) c24++;
    if(p.second >= 14) c14++;
    if(p.second >= 4) c4++;
    if(p.second >= 2) c2++;
  }
  cerr << c74 << " " << c24 << " " << c14 << " " << c4 << " " << c2 << endl;
  ll ans = c74;
  ans += (ll)c24 * (c2 - 1);
  ans += (ll)c14 * (c4 - 1);
  cerr << ans << endl;
  ans += (ll)c4 * (c4-1)/2 * (c2-2);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *p;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->p = y;

  if(y == NIL){
    root = z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else{
    y->right = z;
  }
}

void inorder(Node u){
  if(u == NIL){
    return;
  }
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node u){
  if(u == NIL){
    return;
  }
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

Node treeSearch(Node u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key){
      u = u->left;
    }
    else{
      u = u->right;
    }
  }
  return u;
}

int main(){
  int n, i, x;
  char com[20];
  Node t;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);

    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    else if( com[0] == 'f'){
      scanf("%d", &x);
      t = treeSearch(root,x);
      if( t != NIL){
	printf("yes\n");
      }
      else printf("no\n");
    }
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 20600
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
const int maxn = 1e5 + 1;
struct node{
	int p,y;
	int num;
	int sub;
}no;
vector<node> v[maxn];
bool cmp(node a,node b){
	return a.y<b.y;
}
int main(){
	int n,m,p,y;
	cin>>n>>m;
	map<int,node> Map;
	for(int i=1;i<=m;i++){
		cin>>p>>y;
		no.p=p;no.y=y;
		no.sub=i;
		Map[i]=no;
		v[p].push_back(no);
	}
	for(int i=1;i<=n;i++){
		sort(v[i].begin(),v[i].end(),cmp);
		for (int j=0;j<v[i].size();j++){
        	Map[v[i][j].sub].num=j+1;
    	}
	}
	for(int i=1;i<=m;i++){
		printf("%06d%06d\n",Map[i].p,Map[i].num);
	}
	return 0;
}

Measured memory_bytes: 13184
use std::io::*;
use std::str::FromStr;
use std::collections::BinaryHeap;

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

fn main() {
    let n = read::<usize>();
    let mut aseq = vec![0; 3 * n];
    for i in 0..3 * n {
        aseq[i] = read::<i64>();
    }
    let mut forward_max_sums = vec![0; 3 * n];
    let mut sum = 0;
    let mut que = BinaryHeap::<i64>::new();
    for i in 0..2 * n {
        sum += aseq[i];
        que.push(-aseq[i]);
        if i >= n {
            sum -= -que.pop().unwrap();
        }
        if i >= n - 1 {
            forward_max_sums[i] = sum;
        }
    }
    forward_max_sums[2 * n] = forward_max_sums[2 * n - 1];
    let mut backward_min_sums = vec![0; 3 * n];
    let mut sum = 0;
    let mut que = BinaryHeap::<i64>::new();
    for i in (n..3 * n).rev() {
        sum += aseq[i];
        que.push(aseq[i]);
        if i <= 2 * n - 1 {
            sum -= que.pop().unwrap();
        }
        if i <= 2 * n {
            backward_min_sums[i] = sum;
        }
    }
    backward_min_sums[n - 1] = backward_min_sums[n];
    let mut ans = -(1 << 60);
    for i in n - 1..2 * n {
        // println!("{} {} {}", i, forward_max_sums[i], backward_min_sums[i + 1]);
        ans = std::cmp::max(ans, forward_max_sums[i] - backward_min_sums[i + 1]);
    }
    println!("{}", ans);
}


Measured memory_bytes: 18684
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
using ll = long long;
int main(){ 
    ll n;
    cin>>n;
    vector<double> a(n);
    REP(i,n) cin>>a[i];
    double c=0,b=0;
    REP(i,n){
        b+=1/a[i];
    }
    c=1/b;
    cout<<c;
    return 0;
}


Measured memory_bytes: 256
A, B = map(int,input().split())
def min2(A,B):
  C = abs(A - B)
  D = [A, B, C]
  D.sort()
  if D[0] == 1:
    return 1
  elif D[0] == D[1]:
    return D[0]
  else:
    return min2(D[0],D[1])
a = min2(A,B)

print(int(A*B/a))

Measured memory_bytes: 3064
def s():
 n=int(input())+1
 e=[input().split()for _  in[0]*~-n]
 p=[int(e[0][0])]+list(int(x[1])for x in e)
 m=[[0]*n for _ in[0]*n]
 for i in range(n):
  for r in range(n-i-1):
   c=r+i+1
   for j in range(r+1,c):
    x=m[r][j]+m[j][c]+p[r]*p[j]*p[c]
    if 1>m[r][c]or m[r][c]>x:m[r][c]=x
 print(m[r][c])
if'__main__'==__name__:s()


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

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

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

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



int main(){
    string s;cin>>s;
    int res = INF;
    int n = s.size();
    rep(i,n-2){
        int t = stoi(s.substr(i,3));
        res = min(res,abs(753-t));
    }
    cout<<res;
}



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

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


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

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; }

const long long INF = 1LL << 60;

int main(){
  int H, W; cin >> H >> W;
  vector<string> field(H);
  rep(i, H) cin >> field[i];

  vector<bool> h_ok(H, false);
  vector<bool> w_ok(W, false);

  rep(i, H){
    rep(j, W){
      if(field[i][j] == '#'){
        h_ok[i] = true;
        break;
      }
    }
  }

  rep(j, W){
    rep(i, H){
      if(field[i][j] == '#'){
        w_ok[j] = true;
        break;
      }
    }
  }

  rep(i, H) if(h_ok[i]){
    rep(j, W) if(w_ok[j]){
      cout << field[i][j];
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
d={i:[] for i in range(n)}
n-=1
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    d[a].append(b)
    d[b].append(a)
for i in d[0]:
    if n in d[i]:
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')

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

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,A,B;
	cin >> N >> A >> B;
	A--;B--;
	vector<vector<int>> g(N);
	vector<int> da(N),db(N);
	da[A] = 1;
	db[B] = 1;
	rep(i,N-1){
		int a,b;
		cin >> a >> b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	queue<int> q,q2;
	q.push(A);
	while(!q.empty()){
		int now = q.front();q.pop();
		for(int i=0;i<g[now].size();i++){
			int next = g[now][i];
			if(da[next])continue;
			da[next] = da[now] + 1;
			q.push(next);
		}
	}
	q.push(B);
	while(!q.empty()){
		int now = q.front();q.pop();
		for(int i=0;i<g[now].size();i++){
			int next = g[now][i];
			if(db[next])continue;
			db[next] = db[now] + 1;
			q.push(next);
		}
	}
	int mx = 0;
	int p  = -1;
	rep(i,N){
		if(da[i]<db[i])mx = max(mx,db[i]-1);
	}
	cout << mx-1 << endl;
}


Measured memory_bytes: 6656
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	i, e := strconv.Atoi(nextString())
	if e != nil {
		panic(e)
	}
	return i
}

func nextInt64() int64 {
	i, e := strconv.ParseInt(nextString(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Buffer(make([]byte, 0), 1000000009)
	sc.Split(bufio.ScanWords)

	var n int
	n = nextInt()

	a := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	var ans int64

	for i := 0; i < n; i++ {
		ans += int64(a[i])
		if i%2 == 1 {
			ans -= 2 * int64(a[i])
		}
	}

	for i := 0; i < n; i++ {
		fmt.Print(ans)
		ans = 2*int64(a[i]) - ans
		if i == n-1 {
			fmt.Print("\n")
		} else {
			fmt.Print(" ")
		}
	}
}

Measured memory_bytes: 6528
using System.Linq;
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var a = new bool[110000];
        GeneratePrime(a);
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var p = int.Parse(line[1]);
            if (n == -1 && p == -1) break;
            var t = n + 1;
            var ba = new int[30];
            var count = 0;
            while (count < 30)
            {
                if (a[t]) ba[count++] = t;
                t++;
            }
            Console.WriteLine(getAns(ba,p));
        }
    }
    public static int getAns (int[] a ,int p)
    {
        var aL = a.Length;
        var ret = new List<int>();
        for (int i = 0; i < aL; i++)
            for (int j = i; j < aL; j++) ret.Add(a[i] + a[j]);
        var ret2 = ret.OrderBy(x => x).ToArray();
        return ret2[p - 1];
    }
    public static void GeneratePrime(bool[] p)
    {
        int prime;
        var m = p.Length;
        var sqrtMax = Math.Sqrt(m);
        var searchList = Enumerable.Range(2, m - 1).ToList();
        do
        {
            prime = searchList.First();
            p[prime] = true;
            searchList.RemoveAll(n => n % prime == 0);
        }
        while (prime < sqrtMax);
        foreach (var x in searchList)
            p[x] = true;
    }
}



Measured memory_bytes: 11148
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007
using namespace std;

int main() {
    vector<ll> D;
    ll N; cin >> N;
    ll A[N],B[N],C[N];
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        B[i] = i-A[i];
        C[i] = i+A[i];
    }
    
    ll ans = 0;
    sort(B,B+N);
    sort(C,C+N);
    ll bi,ci;
    bi = ci = 0;
    while(bi < N and ci < N){
        if(B[bi]<C[ci]) bi++;
        else if(B[bi]>C[ci])ci++;
        else{
            ll ab,ac;
            ab = ac = 1;
            while(B[bi+1] == B[bi] and bi < N-1){
                bi++; ab++;
            }
            while(C[ci+1] == C[ci] and ci < N-1){
                ci++; ac++;
            }
            ans += ab*ac;
            bi++;
            ci++;
        }
    }

    cout << ans << endl;
}

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

int main() {
    int N, T, t[200005], ans = 0;
    cin >> N >> T;
    for(int i=0; i<N; i++){
        cin >> t[i];
    }
    for(int i=0; i<N-1; i++){
        ans += min(t[i+1]-t[i], T);
    }
    ans += T;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    char a[n][m+5];
    for(int i=0;i<n;i++){
            scanf("%s",&a[i]);
    }
    for(int i=0;i<2*n;i++){
        for(int j=0;j<m;j++){
            printf("%c",a[i/2][j]);
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    int A,B;
    cin >> A >> B;
    if(A==B) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int solve(int n,int p){
  int stones[100];
  fill(stones,stones+100,0);
  int cnt = 0;
  int haveStoneMan = 0;
  while(true){
    if (p > 0){
      if(stones[cnt] == 0)haveStoneMan++;
      stones[cnt] += 1;
      p--;
      if(p == 0 && haveStoneMan == 1){
        return cnt;
      }
    }else{
      if(stones[cnt] > 0)haveStoneMan--;
      p = stones[cnt];
      stones[cnt] = 0;
    }
    cnt = (cnt+1) % n;
  }
}


int main(){
  int a,b;
  while(true){
    cin >> a >> b;
    if(a == 0 && b == 0)break;
    cout << solve(a,b) << endl;
  }
}

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

#define re return
#define pb push_back
#define po pop_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define pi 3.14159265359
#define fo(i, n) for(int i = 0; i < n; ++i)
#define ro(i, n) for(int i = n - 1; i >= 0; --i)
#define fill(x, y) memset(x, y, sizeof(x))


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef double D;
typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    if (a < b) {
        if ((b - a) % 2 == 1) cout << "Borys" << endl;
        else cout << "Alice" << endl;
    } else {
        if ((a - b) % 2 == 1) cout << "Alice" << endl;
        else cout << "Borys" << endl;
    }
    re 0;
}


Measured memory_bytes: 256
def main():
	n = int(input())
	
	n_list = list(str(n))

	ans = 0

	for i in range(len(n_list)):
		ans += int(n_list[i])
	if ans % 9 ==0:
		print("Yes")
	else:
		print("No")

if __name__ == '__main__':
	main()

Measured memory_bytes: 79904
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
#define ll long long
using namespace std;
const int N=42;
const ll mod=1e9+7;
int n,X,Y,Z,endd,anss;
ll ans=1,dp[N][1<<17];
int main()
{
	//freopen("Iroha and Haiku.in","r",stdin);
	scanf("%d%d%d%d",&n,&X,&Y,&Z);
	anss=(1<<X+Y+Z-1)|(1<<Y+Z-1)|(1<<Z-1);
	endd=(1<<X+Y+Z)-1;
	dp[0][0]=1;
	for(RG int i=1;i<=n;i++)
	{
		(ans*=10)%=mod;
		for(RG int j=0;j<=endd;j++)
		{
			if(!dp[i-1][j]) continue;
			for(RG int k=1;k<=10;k++)
			{
				int tt=(j<<k)|(1<<k-1); tt&=endd;
				if((tt&anss)!=anss) (dp[i][tt]+=dp[i-1][j])%=mod;
			}
		}
	}
	for(RG int i=0;i<=endd;i++) ans=(ans-dp[n][i]+mod)%mod;
	printf("%lld\n",ans);
	return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    set<int> st;
    rep(i, n) {
        st.insert(a[i]);
    }
    if (int(st.size()) == n) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}



Measured memory_bytes: 10368
N,Q = map(int, input().strip().split(' '))
tree_dict = { i:set() for i in range(N)}
for _ in range(N-1):
  a,b = map(int, input().strip().split(' '))
  a,b = a-1, b-1
  tree_dict[a].add(b)
  tree_dict[b].add(a)
tree_counter = [0 for _ in range(N)]
for _ in range(Q):
  p,x = map(int, input().strip().split(' '))
  tree_counter[p-1] += x

stack = []
for c in tree_dict[0]:
  tree_counter[c] += tree_counter[0]
  stack.append((0, c))

for i in range(N-1):
  parent,child = stack.pop()
  for c in tree_dict[child]-{parent}:
    tree_counter[c] += tree_counter[child]
    stack.append((child, c))
  
print(*tree_counter)

Measured memory_bytes: 108508
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define PI 3.141592653589793
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
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;}
const ll INF = 1LL << 62;

//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    ll n,q,k;
    cin >> n;
    vector<pair<ll,ll> > dis[n];
    for (ll i=0;i<n-1;i++){
        ll a,b,c;
        cin >> a >> b >> c;
        a--;
        b--;
        dis[a].push_back(make_pair(b,c));
        dis[b].push_back(make_pair(a,c));
    }
    cin >> q >> k;
    ll ans[n];
    k--;
    fill(ans,ans+n,INF);
    ans[k]=0;
    queue<ll> que;
    que.push(k);
    while(!que.empty()){
        ll p=que.front();
        que.pop();
        for (ll i=0;i<dis[p].size();i++){
            ll next=dis[p][i].first;
            if (ans[next]>ans[p]+dis[p][i].second){
                ans[next]=ans[p]+dis[p][i].second;
                que.push(next);
            }
        }
    }
    for (ll i=0;i<q;i++){
        ll x,y;
        cin >> x >> y;
        x--;
        y--;
        cout << ans[x]+ans[y] << endl;
    }
    return 0;
}


Measured memory_bytes: 12092
void main() {
	auto ip = readAs!(int[]), N = ip[0], K = ip[1];
	auto D = readAs!(int[]);

	auto a = N;
	while(true) {
		bool ok = true;
		foreach(i; D) {
			if(a.to!string.canFind(i.to!string)) {
				ok = false;
				break;
			}
		}
		if(ok) {
			a.writeln;
			return;
		}
		a++;
	}
	/*
	auto S = N.to!string;
	string P;
	foreach(i; S) {
		auto k = i.to!string.to!int;
		foreach(n; 0..10) {
			debug writefln("k: %d, n: %d", k, n);
			if(!D.canFind(n) && k <= n) {
				P ~= n.to!string;
				break;
			}
		}
	}
	P.writeln;
	*/
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 1276
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << endl; }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}


#line 2 "abc162_a.cpp"

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

  string s;
  cin >> s;
  bool flag = false;
  REP(i, 3) { flag = flag || s[i] == '7'; }

  say(flag, "Yes", "No");

  return 0;
}


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

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

using namespace std;

const int INF = 1000000000;

typedef int Weight;
struct Edge{
  int src, dest; Weight weight;
  bool operator < (const Edge &rhs) const {return weight > rhs.weight;}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

// Dijkstra (Verified: AOJ2005)
void dijkstra(Graph &g, Array &d, int s) {
  d.assign(g.size(), INF);
  d[s] = 0;
  typedef pair<Weight,int> P;
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0, s));
  while (!que.empty()) {
    Weight dist = que.top().first;
    int v = que.top().second;
    que.pop();
    if (d[v] < dist) continue;
    REP(i, g[v].size()) {
      Edge e = g[v][i];
      if (d[e.dest] > d[v] + e.weight) {
        d[e.dest] = d[v] + e.weight;
        que.push(P(d[e.dest], e.dest));
      }
    }
  }
}


int main() {
  while(1){
    int w,h;
    cin>>w>>h;
    if(!w)break;
    int n = w*h;
    Graph g(n*2);
    vector<vector<string>> t(h,vector<string>(w));
    REP(i,h){
      REP(j,w){
        cin>>t[i][j];
      }
    }
    set<int> s_set,t_set;
    REP(i,h){
      REP(j,w){
        if (t[i][j] == "S") {
          s_set.insert(i*w+j);
          s_set.insert(n+i*w+j);
        } else if (t[i][j] == "T") {
          t_set.insert(i*w+j);
          t_set.insert(n+i*w+j);
        }
        int p = i*w+j;
        for(int k=-2;k<=2;++k)REP(l,3){
          if(abs(k)+l>=3) continue;
          int nir = i+k;
          int njr = j+1+l;
          int nil = i+k;
          int njl = j-1-l;
          if (nir >= 0 && nir < h && njr >= 0 && njr < w) {
            if (t[nir][njr] == "S" || t[nir][njr] == "T")
              g[p].push_back({p, n+nir*w+njr, 0});
            else if (t[nir][njr] != "X")
              g[p].push_back({p, n+nir*w+njr, t[nir][njr][0] - '0'});
          }
          if (nil >= 0 && nil < h && njl >= 0 && njl < w) {
            if (t[nil][njl] == "S" || t[nil][njl] == "T")
              g[n+p].push_back({n+p, nil*w+njl, 0});
            else if (t[nil][njl] != "X")
              g[n+p].push_back({n+p, nil*w+njl, t[nil][njl][0] - '0'});
          }
        }
      }
    }
    int mind = INF;
    for (int i:s_set) {
      Array a(n*2, INF);
      dijkstra(g, a, i);
      for (int j:t_set)
        mind = min(mind, a[j]);
    }
    if (mind < INF)
      cout << mind << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}

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

const int M = 1e9 + 7;
string K;
int D, dp[10002][101][2];

int solve (int i, int rem, bool f) {
	if (dp[i][rem][f] != -1) return dp[i][rem][f];
	if (i == (int)K.length()) return dp[i][rem][f] = (rem == 0);
	int ret = 0;
	if (f)
		for (int j=0; j<10; ++j)
			ret = (ret + solve(i + 1, (rem + j) % D, 1)) % M;
	else {
		ret = (ret + solve(i + 1, (rem + (K[i]-'0')) % D, 0)) % M;
		for (int j=0; j<(K[i]-'0'); ++j)
			ret = (ret + solve(i + 1, (rem + j) % D, 1)) % M;
	}
	return dp[i][rem][f] = ret;
}

int main ()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cin >> K >> D;
	memset(dp, -1, sizeof(dp));
	cout << max(0, (solve(0, 0, 0) - 1 + M) % M) << '\n';
	return 0;
}


Measured memory_bytes: 8960