akhauriyash/Code-Regression huggingface dataset:
//Author:xht37
#include <bits/stdc++.h>

#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double

#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair

#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)

#define vi vector <int>
#define pb push_back
#define pq priority_queue

#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

using namespace std;

namespace io {
	const int SI = 1 << 21 | 1;
	char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
	int f, t;
	#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
	inline void flush() {
		fwrite(OB, 1, OS - OB, stdout), OS = OB;
	}
	inline void pc(char x) {
		*OS++ = x;
		if (OS == OT) flush();
	}

	template <class I>
	inline void rd(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
		x *= f;
	}
	template <class I>
	inline void rd(I &x, I &y) {
		rd(x), rd(y);
	}
	template <class I>
	inline void rd(I &x, I &y, I &z) {
		rd(x), rd(y), rd(z);
	}
	template <class I>
	inline void rda(I *a, int n) {
		for (int i = 1; i <= n; i++) rd(a[i]);
	}
	inline void rdc(char &c) {
		for (c = gc(); c < 33 || c > 126; c = gc());
	}
	inline void rds(char *s, int &n) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
		s[n+1] = '\0';
	}
	inline void rds(string &s) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
	}

	template <class I>
	inline void print(I x, char k = '\n') {
		if (!x) pc('0');
		if (x < 0) pc('-'), x = -x;
		while (x) ch[++t] = x % 10 + '0', x /= 10;
		while (t) pc(ch[t--]);
		pc(k);
	}
	template <class I>
	inline void print(I x, I y) {
		print(x, ' '), print(y);
	}
	template <class I>
	inline void print(I x, I y, I z) {
		print(x, ' '), print(y, ' '), print(z);
	}
	template <class I>
	inline void printa(I *a, int n) {
		for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
	}
	inline void printc(char c) {
		pc(c);
	}
	inline void prints(char *s, int n) {
		for (int i = 1; i <= n; i++) pc(s[i]);
		pc('\n');
	}
	inline void prints(string s) {
		int n = s.length();
		while (t < n) pc(s[t++]);
		pc('\n'), t = 0;
	}
	struct Flush {
		~Flush() {
			flush();
		}
	} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;

const int N = 1e5 + 7;
int n, a[N];

int main() {
	rd(n), rda(a, n);
	map<int, int> c;
	for (int i = 1; i <= n; i++) ++c[a[i]];
	if (c[0] == n) return prints("Yes"), 0;
	if (n % 3) return prints("No"), 0;
	for (pi o : c)
		if (o.se % (n / 3)) return prints("No"), 0;
	int k = 0;
	for (pi o : c) {
		int t = o.se / (n / 3);
		while (t--) k ^= o.fi;
	}
	if (k) return prints("No"), 0;
	prints("Yes");
	return 0;
}


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

typedef long long ll;
const int INF = 1e9;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin>>n;
	cout<<(n/500)*1000+(n%500)/5*5<<'\n';
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#define llu long long unsigned int
#define f(x,y) for(int x=0;x<y;x++)

int main() {
    int a,b,c,d,f,l;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a>c)
        f=a;
    else f=c;
    if(b<d)
        l=b;
    else l=d;
    if(l<f)printf("0\n");
    else printf("%d\n",l-f);
    return 0;}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int a, b;
      cin >> a >> b;
      if(a < 10){
            cout << b + 100 * (10 - a);
      }
      else cout << b;

}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Linq;

namespace competitive_programming
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int M = int.Parse(input[1]);

            int ans = 0;

            if (N >= 2) ans += (N )* (N - 1) / 2;
          	//Console.WriteLine(ans);
            if (M >= 2) ans += (M )*( M - 1) / 2;
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
from collections import deque
S = input()
S_deque = deque(S)
# print(S_deque)

Q = int(input())

reverse = 0

for i in range(Q):
    q = input().split()
    # print(q)

    if q[0] == "2":
        if not reverse:
            if q[1] == "1":
                S_deque.appendleft(q[2])
            elif q[1] == "2":
                S_deque.append(q[2])
        if reverse:
            if q[1] == "1":
                S_deque.append(q[2])
            elif q[1] == "2":
                S_deque.appendleft(q[2])
    else:
        if not reverse:
            reverse = 1
        else:
            reverse = 0

if reverse:
    print("".join(reversed(S_deque)))
else:
    print("".join(S_deque))

Measured memory_bytes: 74968
/**
 *  author: mahfuzz
 *  created: 23.09.2019
**/

#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define pii pair<int, int>
#define pll pair<long long, long long>
//~ const double pi = 2*acos(0.0);
//~ const long long mod = 1000000007;
//~ const int max_n = 1000005;
typedef long long ll;

int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
       
    #ifdef _DEBUG
    freopen("input.txt","r",stdin);
    //~ freopen("output.txt","w",stdout);
    #endif
    
    string s; cin >> s;
    for(int i = 0; s[i]; i++){
        if((i % 2 == 0 && s[i] == 'L')
            || (i % 2 == 1 && s[i] == 'R')){
            cout << "No\n";
            return 0;
        }
            
    }
    
    cout << "Yes\n";
    
    return 0;
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  
  cout<<max({a,b,c})-min({a,b,c})<<endl;


  return 0;
}


Measured memory_bytes: 256
N = int(input())

F=[int(input().replace(" ",""),2) for i in range(N)]
#f = [list(map(int, input().split())) for _ in range(n)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = - 10**18
for i in range(1, 2**10):
    s = 0
    for f,p in zip(F,P):
        s += p[bin(f&i).count("1")]
    ans = max(ans, s)
print(ans)

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; i++) {
        cin >> s.at(i);
        s.at(i) = '#' + s.at(i) + '#';
    }

    for (int i = 0; i < w + 2; i++) {
        cout << '#';
    }
    cout << endl;
    for (int i = 0; i < h; i++) {
        cout << s.at(i) << endl;
    }
    for (int i = 0; i < w + 2; i++) {
        cout << '#';
    }
    cout << endl;
}   

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int k,a,b;
    cin>>k>>a>>b;
    
   for(int i=0;i<=(b-a);i++){
       if((a+i)%k==0){
           cout<<"OK"<<endl;
           goto Exit;
       }
   }
    cout<<"NG"<<endl;
    
    Exit:
        ;
}

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

int N, M;
vector<vector<int>> A, B;
int main() {
  cin >> N >> M;
  A.resize(N, vector<int>(N, 0));
  B.resize(M, vector<int>(M, 0));
  {
    char c;
    rep(i, N) rep(j, N) {
      cin >> c;
      if (c == '#') A[i][j] = 1;
    }
    rep(i, M) rep(j, M) {
      cin >> c;
      if (c == '#') B[i][j] = 1;
    }
  }

  for (int di = 0; M + di <= N; ++di) {
    for (int dj = 0; M + dj <= N; ++dj) {
      bool match = true;
      rep(i, M) rep(j, M) {
        if (A[i + di][j + dj] != B[i][j]) match = false;
      }
      if (match) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

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

    int f[100][10]; /* f[i][j]は、店iが「ある曜日(1～5)の
                       ある時間帯(1～2)」j(0～9)に
                       営業していれば1,営業していなければ0 */

    int p[100][11]; /* p[i][j]は、店iとお姉ちゃんの店の両方
                       が営業している時間帯の個数がjの
                       ときに得られる利益 */

    rep(i, n) {
        rep(j, 10) {
            cin >> f[i][j];
        }
    }
    rep(i, n) {
        rep(j, 11) {
            cin >> p[i][j];
        }
    }

    //利益の最大値(-INFで初期化)
    int ans = -(1 << 30);
    //00…01(0が9個と1が1個)から11…1(1が10個)の0＆1列bを全て調べる
    for(int b = 1; b < (1 << 10); b++) {

        //お姉ちゃんの店の利益
        int profit = 0;

        //i番目の店について調べる
        rep(i, n) {

            int cnt = 0;    /* i番目の店とお姉ちゃんの店の両方が
                               営業している時間帯の個数 */

            //bのjビット目について調べる
            rep(j, 10) {
                //bのjビット目が1かつf[i][j]が1だったら
                if( ((b >> j) & 1) && f[i][j] ) {
                    /* ある曜日のある時間帯jではi番目の店と
                       お姉ちゃんの店の両方が営業している */
                    cnt++;
                }
            }

            //i番目の店についてはp[i][cnt]の利益が得られる
            profit += p[i][cnt];
        }

        //profitの中で最大のものがansに入る
        if(ans < profit) {
            ans = profit;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    string s;
    cin >> s;
    ll cnt = 0;
    if(s[0] == s.back())
    cnt++;
    set<char> st;
    map<char,ll> mp;
    for(ll i = 1; i < s.size() - 1; i++){
        mp[s[i]]++;
        st.insert(s[i]);
    }
    for(auto v : st){
        cnt += mp[v] / 2 * 2;
    }
    cout << ((s.size()  - 2 - cnt) % 2 == 0 ? "Second" : "First") << endl;
}

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

int main(){
  double l;
  cin >> l;
  double a = l / 3.000000;
  double b = a;
  double c = a;
  
  cout << fixed << setprecision(15) << a * b * c << endl;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d%d%d%d%d", $n, $a, $b, $c, $d);
$s = "#".trim(fgets(STDIN));
$f = strpos(substr($s, $a, $c-$a+1), "##")===false && strpos(substr($s, $b, $d-$b+1), "##")===false;
if($c > $d){
  $f = $f && strpos(substr($s, $b-1, $d-$b+3), "...")!==false;
}
echo $f ? "Yes" : "No";

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

struct UnionFind{
  vector<int> v;
  UnionFind(int n) : v(n, -1) {}
  int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (-v[x] < -v[y]) swap(x, y);
    v[x] += v[y]; v[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
};

int n;
map<string,int> r;
string crs[1000];
bool es[222][222];
bool ess[222][222];
bool esss[222][222];
int dir[222];

void dfs(int v,int nd){
  dir[v]=nd;
  repl(i,1,n){
    if(!esss[v][i])continue;
    if(dir[i]==-1)dfs(i,1-nd);
  }
}

int main(){
	cin.sync_with_stdio(false);
  while(1){
    int N;
    cin>>N;
    if(N==0)break;
    r.clear();
    memset(es,0,sizeof(es));
    memset(esss,0,sizeof(esss));
    n=1;
    rep(i,N){
      cin>>crs[i];
      rep(j,crs[i].length()){
        if(crs[i][j]=='-'){
          string ls=crs[i].substr(0,j);
          string rs=crs[i].substr(j+1,crs[i].length()-j);
          if(!r[ls])r[ls]=n++;
          if(!r[rs])r[rs]=n++;
          es[r[ls]][r[rs]]=true;
          esss[r[ls]][r[rs]]=esss[r[rs]][r[ls]]=true;
          break;
        }
      }
    }
    /*
    each(it,r){
      printf("%s %d\n", it.first.c_str(),it.second);
    }*/
    cout<<n-1<<endl;
    UnionFind uf(n);
    repl(i,1,n)repl(j,i+1,n){
      bool ok=false;
      repl(k,1,n){
        if((es[k][i]&&es[k][j])||(es[i][k]&&es[j][k]))ok=true;
      }
      repl(k,1,n){
        if((es[i][k]&&es[k][j])||(es[j][k]&&es[k][i]))ok=false;
      }
      if(ok)uf.unite(i,j);
    }
    repl(i,1,n)repl(j,1,n){
      ess[i][j]=i==j?true:false;
    }
    repl(i,1,n)repl(j,1,n){
      if(es[i][j])ess[uf.find(i)][uf.find(j)]=true;;
    }
    /*
    repl(i,1,n)repl(j,1,n){
      printf("%d%c", ess[i][j],j==n-1?'\n':' ');
    }*/
    repl(k,1,n)repl(i,1,n)repl(j,1,n)ess[i][j]|=ess[i][k]&ess[k][j];
    /*
    repl(i,1,n)repl(j,1,n){
      printf("%d%c", ess[i][j],j==n-1?'\n':' ');
    }*/
    int q;
    cin>>q;
    while(q--){
      string qs;
      cin>>qs;
      rep(i,qs.length()){
        if(qs[i]=='-'){
          string ls=qs.substr(0,i);
          string rs=qs.substr(i+1,qs.length()-i);
          memset(dir,-1,sizeof(dir));
          dfs(r[ls],0);
          if(ess[uf.find(r[ls])][uf.find(r[rs])]&&dir[r[rs]]!=-1&&dir[r[ls]]!=dir[r[rs]])cout<<"YES"<<endl;
          else cout<<"NO"<<endl;
          break;
        }
      }
    }
  }
	return 0;
}

Measured memory_bytes: 3476
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int INF = 2e9;



int main() {
	ll x; cin >> x;
	ll ans = 2 * (x / 11);
	if (x % 11 > 6) ans += 2;
	else if (x % 11 != 0) ans++;
	printf("%lld", ans);
	return 0;
}

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

int main(void) {
  int r, g;
  scanf("%d%d", &r, &g);
  printf("%d\n", 2*g-r);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define INF 1e9
typedef pair<int, int> P;

/* 　"assert"    assert(A：条件式)で　Aが真なら処理は続行、偽ならプログラムを終了する　*/

/*　　ラムダ式　　 auto a = [キャプチャ](パラメータ){ 処理 }  */

/* string型　メンバ関数　substr()    replace()  */

bool isOK(string s){
    //cout << "文字列　＝"<< s << endl;
    string prevS = s;
    reverse(s.begin(), s.end());
    string revS = s;
    if(revS == prevS){
        return true;
    }
    return false;
}

int main(){
 
    string s; cin >> s;
    auto n = s.size();
    string before = s.substr(0,(n-1)/2);
    string after = s.substr((n+3)/2-1, n);
 
    if (isOK(s)) {
        if (isOK(before)) {
            if (isOK(after)) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
     
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  
  int l, r;
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys

class Node:
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left = self.right = None

class BST:
    def __init__(self):
        self.root = None
    def insert(self, key):
        x, y = self.root, None
        while x != None: x, y = x.left if key < x.key else x.right, x
        if y == None: self.root = Node(key)
        elif key < y.key: y.left = Node(key)
        else: y.right = Node(key)
    def print_tree(self):
        def inorder(node):
            return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else ''
        def preorder(node):
            return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else ''
        print(inorder(self.root))
        print(preorder(self.root))

tree = BST()
input()
for e in sys.stdin:
    if e[0] == 'i': tree.insert(int(e[7:]))
    else: tree.print_tree()


Measured memory_bytes: 63272
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 998244353;

const int MAX = 200000;
ll fac[MAX], finv[MAX], inv[MAX];

//前処理
void COMinit (){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1]*i%mod;
        inv[i] = mod-inv[mod%i]*(mod/i)%mod;
        finv[i] = finv[i-1]*inv[i]%mod;
    }
}
//二項係数
ll COM(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

//繰り返し二乗法
ll EX(ll x,ll n){
    if(n == 0) return 1;
    else if(n%2 == 1) return EX(x,n-1)*x%mod;
    else return EX(x*x%mod,n/2)%mod;
};

int main(){
    ll n,m,k;
    cin >> n >> m >> k;
    ll ans = 0;
    COMinit();
    for(int i = 0; i <= k; i++){
        ans += (((m*EX(m-1,n-i-1))%mod)*COM(n-1,i))%mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8348
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long


signed main(){
  int n;
  int w[100];
  int sum=0;
  int ans=BIG;
  cin>>n;
  rep(i,n){
    cin>>w[i];
    sum+=w[i];
    if(i!=0) w[i]+=w[i-1];
    
  }
  rep(i,n){
    ans=min(ans,abs(w[i]-(sum-w[i])) );
  }
  cout<<ans<<endl;
  return 0;
}


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

int n;
vi h;

int main() {
    cin >> n;
    h.resize(n);
    rep(i,0,n) cin >> h[i];
    int cnt=0;
    int _max = h[0];
    rep(i,0,n-1) {
        if (h[i]>=_max) cnt++;
        _max = (h[i+1]>_max) ? h[i+1] : _max;
    }
    if (h[n-1] >= _max) cnt++;
    cout << cnt << '\n';
    return 0;
}

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

const int limit = 100010;
using edge = struct {int to; long long cost;};
vector<edge> tree[limit];
long long depth[limit];
int color[limit];

void dfs(int v, int p, long long d){
    depth[v] = d;
    if(d%2 == 0) color[v] = 0;
    else color[v] = 1;
    for(auto &e : tree[v]) {
        if(e.to == p) continue;
        dfs(e.to, v, d + e.cost);
    }
}

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

    int n;
    cin >> n;

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

    dfs(0, -1, 0);

    for(int i = 0; i < n; i++){
        cout << color[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 10624
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
#include <math.h>
int main(void){
int n,a[105],b[105];
scanf("%d",&n);

for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
}

for(int i=0;i<n;i++){
    scanf("%d",&b[i]);
}
int sum=0;
double sum2=0.0;
double sum3=0.0;
int sum4=-555555;
for(int i=0;i<n;i++){
    sum=sum+abs(a[i]-b[i]);
}
for(int i=0;i<n;i++){
    sum2=sum2+(double)(abs(a[i]-b[i]))*(abs(a[i]-b[i]));
}
sum2=sqrt(sum2);

for(int i=0;i<n;i++){
    sum3=sum3+(double)(abs(a[i]-b[i]))*(abs(a[i]-b[i])*(abs(a[i]-b[i])));
}
sum3=pow(sum3,0.333333333333333333333333);
for(int i=0;i<n;i++){
    if(sum4<=abs(a[i]-b[i])){sum4=abs(a[i]-b[i]);}


}
printf("%.15d\n%lf\n%lf\n%.15d",sum,sum2,sum3,sum4);

}



Measured memory_bytes: 2148
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	ll n, t, x, px, res;
	cin >> n >> t >> px;
	res = t;
	REP(i, n - 1) {
		cin >> x;
		res += (x - px >= t ? t : x - px);
		px = x;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int debug = 0;

int K,minimum;
char ans[11];

int calc(int num,int diff){
	return (num+diff)%10;
}

void recursive(char buf[11],int loc,int count){

	if(count >= minimum)return;

	bool FLG = true;
	for(int i = 0; i < K; i++){
		if(buf[i] != ans[i]){
			FLG = false;
			break;
		}
	}
	if(FLG){
		minimum = min(minimum,count);
		return;
	}

	int diff;

	if(ans[loc] == buf[loc]){
		diff = 0;
	}else if(ans[loc] < buf[loc]){
		diff = ans[loc] + 10 - buf[loc];
		count++;
	}else{
		diff = ans[loc] - buf[loc];
		count++;
	}

	for(int right = loc; right < K; right++){
		char next[11];

		for(int i = 0; i < loc; i++){
			next[i] = buf[i];
		}
		for(int i = loc; i <= right; i++){
			next[i] = '0' + calc(buf[i]-'0',diff);
		}
		for(int i = right+1; i < K; i++){
			next[i] = buf[i];
		}
		recursive(next,loc+1,count);
	}
}

int main(){

	char first[11];

	while(true){
		scanf("%d",&K);
		if(K == 0)break;

		minimum = BIG_NUM;

		scanf("%s %s",first,ans);

		recursive(first,0,0);

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

	return 0;
}

Measured memory_bytes: 2760
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

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

    vector<bool> A(n*n);
    fill(A.begin(), A.end(), false);

    for (int32_t i = 0; i < n; i++) {
        int32_t u, k;
        cin >> u >> k;

        for (int32_t j = 0; j < k; j++) {
            int32_t v;
            cin >> v;

            A[(u-1)*n+(v-1)] = true;
        }
    }

    for (int32_t i = 0; i < n; i++) {
        cout << A[i*n];
        for (int32_t j = 1; j < n; j++) {
            cout << " " << A[i*n+j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3104
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    N = int(input())
    A = input()
    B = input()
    C = input()

    ans = 0

    for i in range(N):
        if A[i] == B[i] == C[i]:
            continue
        
        if A[i] == B[i] or A[i] == C[i] or B[i] == C[i]:
            ans += 1
        else:
            ans += 2

    print(ans)
        


main()


Measured memory_bytes: 5160
#include <iostream>
#include <vector>

using namespace std;

int m,d;
int ans = 0;

int main()
{
	cin >> m >> d;
	for(int i=4;i<=m;++i)
	{
		for(int j=2;j<= min(m / 2,10);++j)
		{
			if((i%j) == 0 and (i/j) < 10 and (i/j) > 1 and ((j * 10) + (i/j))<=d)
				++ans;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
 int n;
  cin>>n;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
    cin>>vec.at(i);}
  sort(vec.begin(),vec.end());
  vec.at(n-1)/=2;
  int sum=0;
  for(int j=0;j<n;j++){
    sum+=vec.at(j);}
  cout <<sum <<endl;
    
}


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

const ll nax=1e18;

void solve()
{
ll a,ans;
   long double b,mul;
    cin>>a>>b;
    mul=a*b;
    ans=(ll)mul;
    cout<<ans<<endl;
}

int main()
{
 int t=1;
  //  cin>>t; 
    
    while(t--)
     solve();   
    
}

Measured memory_bytes: 3728
import math
N, K = map(int, input().split())
S = input()

# 連続した 0 と 1 の数を数える
cnt_list = []
flag = True if S[0] == '1' else False
cnt = 1
flag_flag = True
for i in range(1, N):
    if S[i] == '1':
        if i == N - 1:
            flag_flag = True
        if flag:
            cnt += 1
        else:
            flag = True
            cnt_list.append([cnt, -1])
            cnt = 1
    if S[i] == '0':
        if i == N - 1:
            flag_flag = False
        if flag:
            flag = False
            cnt_list.append([-1, cnt])
            cnt = 1
        else:
            cnt += 1
if not flag_flag:
    cnt_list.append([cnt, -1])
else:
    cnt_list.append([-1, cnt])
# 指示する回数を求める． K 回 >= 連続した 0 の個数の時は上手に行えば全て逆立ちできる
n = len(cnt_list)
if cnt_list[0][0] == -1:    # 1 スタート
    if K >= n//2:
        print(N)
        exit()
    k = K
else:                       # 0 スタート
    if K >= math.ceil(n/2):
        print(N)
        exit()
    k = K

# あとは区間内の総和を計算するのに累積和を用いる
# 累積和を計算
cumsum = [0] * (n+1)
for i in range(n):
    cumsum[i+1] = cumsum[i] + max(cnt_list[i])

ans = 0
if cnt_list[0][0] == -1:        # 1 start
    if cnt_list[-1][0] == -1:   # 1 end
        for i in range(1, n - 2 * k + 1, 2):
            ans = max(ans, cumsum[2 * k + i] - cumsum[i-1])
    else:                        # 0 end
        for i in range(1, n - 2*k + 1, 2):
            ans = max(ans, cumsum[2 * k + i] - cumsum[i-1])
        ans = max(ans, cumsum[n] - cumsum[n - 2*k])
    
else:                           # 0 start
    if cnt_list[-1][0] == -1:   # 1 end
        ans = cumsum[2*k] - cumsum[0]
        for i in range(2, n - 2 * k + 1, 2):
            ans = max(ans, cumsum[2 * k + i] - cumsum[i-1])
    else:                       # 0 end
        ans = cumsum[2 * k] - cumsum[0]
        for i in range(2, n - 2 * k + 1, 2):
            ans = max(ans, cumsum[ 2* k + i] - cumsum[i-1])
        ans = max(ans, cumsum[n] - cumsum[n - 2*k])
##print(cumsum)
print(ans)

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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  ll zero = 0;
  ll one = 0;
  rep(i, s.size()) {
    if(s[i] == '0')
      zero++;
    else
      one++;
  }
  cout << 2 * min(zero, one) << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

#define MOD 1000000007

LL mult(LL a, LL b){
    return ((a % MOD) * (b % MOD)) % MOD;
}

LL solve2(LL a, LL b, LL c, LL d){
    LL ans = 0;
    LL i = 1;
    while(i < (c-d)){
        LL go = 1e9;
        LL go1 = 0;
        //if(i < 1000000 || (c-d-i) < 1000000) go1 = 1;
        LL x = a*i/c;
        LL y = b*i/c;
        LL l1 = min(a-1, x+d) - max(0LL, x-d);
        LL l2 = min(b-1, y+d) - max(0LL, y-d);

        if(l1 == 2*d){
            go = min(go, c*(a-d-1)/a - i);
        } else {
            go = min(go, (c*(x+1)-1)/a - i);
        }

        if(l2 == 2*d){
            go = min(go, c*(b-d-1)/b - i);
        } else {
            go = min(go, (c*(y+1)-1)/b - i);
        }

        if(go1) go = 1;
        go = max(go, 1LL);
        go = min(go, c-d-i);
        ans += mult(go, mult(l1+1, l2+1));
        ans %= MOD;
        i += go;
    }
    return ans % MOD;
}

LL solve(LL a, LL b, LL c, LL d){
    LL ans = 0;
    for(LL i = 1; i < c-d; i++){
        LL x = a*i/c;
        LL y = b*i/c;
        LL l1 = min(a-1, x+d) - max(0LL, x-d);
        LL l2 = min(b-1, y+d) - max(0LL, y-d);
        ans += mult(l1+1, l2+1);
        ans %= MOD;
    }
    return ans;
}

int main(){
    LL a, b, c;
    LL d;
    cin >> a >> b >> c >> d;

    LL ans = mult(min(a,d+1), mult(min(b,d+1), min(c,d+1)));
    // solve each dimension
    ans += solve2(a,b,c,d);
    ans += solve2(b,c,a,d);
    ans += solve2(c,a,b,d);
    ans %= MOD;
    while(ans < 0) ans += MOD;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


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

    ll ans = 0;
    FOR(i, 1, n + 1)
    {
        if(i % 3 != 0 && i % 5 != 0){
            ans += i;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3624
(let ((n (read))
            (s '())
            (a (make-array 3 :initial-element 0 :element-type 'fixnum))
            (ans 0))
            (setq s (loop for _ below n collect (read-char)))
            (loop for i below 1000 do
                (progn
                  (setf a (format nil "~3,'0d" i))
                    (let ((f 0))
                        (loop for j in s do
                            (progn
                                (if (eq j (aref a f)) (incf f))
                                (if (= f 3) (return))
                            )
                        )
                    (if (= f 3) (incf ans))
                    )
                )
            )
         
            (format t "~D~%" ans)
        )

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define in(x) cin>>x
#define ina(x, n) rep(x_i,n) cin>>x[x_i]
#define outa(x, n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  int n; in(n);
  REP(i,1,10) {
    REP(j,1,10) {
      if (i*j == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define r(i,n) for(int i=0;i<n;i++)
int main(){
  int n,m;
  cin>>n>>m;
  int a[n]={};
  while(m--){
    int q,w;
    cin>>q>>w;
    a[q-1]++;
    a[w-1]++;
  }
  for(int i=0;i<n;i++)
    cout<<a[i]<<endl;
}

Measured memory_bytes: 256
import sys
s=input()
l=[ "dream", "dreamer", "erase", "eraser" ]
while True:
    for i in l:
        if s.endswith(i):
            s=s[:-len(i)]
            #print(s)
            break
    else:
        if len(s) ==0:
            print("YES")
        else:
            print("NO")
        sys.exit()

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

using namespace std;

const int M=2e5;

vector<vector<int> > mp(501);

pair<int,int> in[M];

int main()
{
    int n,m,q;
    scanf("%d%d%d",&n,&m,&q);
    for(int i=0;i<m;i++)
        scanf("%d%d",&in[i].first,&in[i].second);
    sort(in,in+m);
    for(int i=0;i<m;i++)
        mp[in[i].first].push_back(in[i].second);
    while (q--){
        int a,b,ans=0;
        scanf("%d%d",&a,&b);
        for(int i=a;i<=b;i++){
            ans+=upper_bound(mp[i].begin(),mp[i].end(),b)-mp[i].begin();
        }
        printf("%d\n",ans);
    }
}


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

using namespace std;
int main() {
    string s;
    int a_pos;
    int z_pos;

    cin >> s;

    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'A') {
            a_pos = i;
            break;
        }
    }

    for (int i = s.length()-1; i >= 0; i--) {
        if (s[i] == 'Z') {
            z_pos = i;
            break;
        }
    }

    cout << z_pos - a_pos + 1<< endl;

    return 0;
}


Measured memory_bytes: 640
h, w, a, b = map(int, input().split())
m = 10**9 + 7

fac = [1, 1]
inv = [1, 1]
finv = [1, 1]
for i in range(2, w+h+5):
    fac.append(fac[i-1] * i % m)
    inv.append(m - inv[m%i] * (m//i) % m)
    finv.append(finv[i-1] * inv[i] % m)

def nck(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % m) % m


row = []
for i in range(h-a):
    row.append(nck(b+i, i))

ans = 0
for i in range(len(row)-1):
    ans += row[i] * nck(w-b-2 + h-1-i, h-1-i)
    ans %= m

ans += row[-1] * nck(w-b-1 + a, a)
ans %= m

print(ans)


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

int main() {

    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> M(N);
    int sum = 0;
    for(int i=0;i<N;i++){
        cin >> A.at(i);
        sum += A.at(i);
    }
    int x = 0;
    for(int i=0;i<N;i++){
        if(i%2==0){
            x += A.at(i);
        }else{
            x -= A.at(i);
        }
    }
    M.at(0) = x;
    for(int i=1;i<N;i++){
        M.at(i) = 2*A.at(i-1) - M.at(i-1);
    }
    for(int i=0;i<N;i++){
        if(i==N-1){
            cout << M.at(i) << endl;
        }else{
            cout << M.at(i) << " ";
        }
        
    }

    return 0;

}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  
    if (S == "Sunny") {
    cout << "Cloudy" << endl;
  }
  
    if (S == "Cloudy") {
    cout << "Rainy" << endl;
  }
  
    if (S == "Rainy") {
    cout << "Sunny" << endl;
  }
}

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

using i64 = long long;

#define REP(i, stop) for (register int i = 1; i <= stop; ++i)

const int is = 1 << 17;
char ib[is], *ip = ib + is, it;
inline char getc() {
	if (ip == ib + is) { fread_unlocked(ib, 1, is, stdin); ip = ib; }
	return *ip++;
}
inline int read() {
	int r = 0;
	if (ip + 16 > ib + is) while ((it = getc()) & 16) r = r * 10 + it - '0';
	else while ((it = *ip++) & 16) r = r * 10 + it - '0';
	return r;
}

const int os = 1 << 17;
char ob[os], *op = ob, ot;
inline void putc(const char c) {
	*op++ = c;
	if (op == ob + os) { fwrite_unlocked(ob, 1, os, stdout); op = ob; }
}
// x shoud be greater than or equal to zero
inline void write(int x) {
	char d[6];
	int i = 0;
	while (true) {
		d[i] = x % 10 + 48;
		x /= 10;
		++i;
		if (x <= 0) break;
	}
	while (i--) {
		putc(d[i]);
	}
	putc(' ');
}

i64 cnt[200001];
bool used[200001];
vector<vector<i64>> G(200001);
void dfs(i64 a) {
  used[a] = true;
  for (i64 b : G[a]) {
    if (!used[b]) {
      cnt[b] += cnt[a];
      dfs(b);
    }
  }
}
signed main() {
  i64 N = read(), Q = read();
  REP(_, N - 1) {
    i64 a = read(), b = read();
    G[a].push_back(b);
    G[b].push_back(a);
  }
  REP(_, Q) {
    i64 p = read(), x = read();
    cnt[p] += x;
  }
  dfs(1);
  REP(i, N) {
    printf("%d ", cnt[i]);
//    write(cnt[i]);
  }
//  fwrite_unlocked(ob, 1, op - ob, stdout);
}


Measured memory_bytes: 21504
n = int(input())
a = [int(input()) for _i in range(n)] + [-1]

result = -1
for i in range(n):
    if a[i-1] >= a[i]:
        result += a[i]
    elif a[i-1] + 1 == a[i]:
        result += 1
    else:
        result = -1
        break
print(result)

Measured memory_bytes: 61016
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

int main(){
	IO_STREAM;
	int K;	cin>>K;
	int x=7%K;
	rep(i,1,1e6+1){
		if(x==0){
			cout<<i<<endl;
			return 0;
		}
		x=(x*10+7)%K;
	}
	cout<<-1<<endl;
	return 0;
}


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

using namespace std;

struct data_t {
  int b;
  int f;
  int r;
  int v;

  bool operator<(const data_t& right) const {
    return b == right.b ? f == right.f ? r < right.r : f < right.f : b < right.b;
  }
};

int main(void) {
  int n;
  int count[4][3][10] = {};
  int b,f,r,v;
  cin >> n;
  vector<data_t> data_array(n);
  for(int i = 0; i < n; i++) {
    cin >> b >> f >> r >> v;
    data_array[i].b = b;
    data_array[i].f = f;
    data_array[i].r = r;
    data_array[i].v = v;
  }
  sort(data_array.begin(), data_array.end());
  int t = 0;
  for(int i = 0; i < 4; i++) {
    for(int j = 0; j < 3; j++) {
      for(int k = 0; k < 10; k++) {
        while(i + 1 == data_array[t].b && j + 1 == data_array[t].f && k + 1 == data_array[t].r) {
          count[i][j][k] += data_array[t++].v;
        }
      }
    }
  }
  for(int i = 0; i < 4; i++) {
    for(int j = 0; j < 3; j++) {
      for(int k = 0; k < 10; k++) {
        cout << ' ' << count[i][j][k];
      }
      cout << endl;
    }
    if(i < 3)
      cout << "####################" << endl;
  }
  return 0;
}

Measured memory_bytes: 3104
#include <vector>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <set>
using namespace std;

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

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


  int c = -1;
  double h = (double)a[0] / 2;
  for (int i = 1; i < n; ++i) {
    if (c == -1) c = a[i];
    else {
      if (fabs(h - c) > fabs(h - a[i])) c = a[i];
    }
  }
  cout << a[0] << " " << c << endl;
  return 0;
}


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

//#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

typedef pair<int, int> P;

#define rep(i, a, b) for(int i=a;i<b;i++)
#define fore(i, a) for(auto &i:a)
typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;

struct BipartiteMatching {
    vector<vector<int>> E;
    int n, m;
    vector<int> match, dist;

    void init(int _n, int _m) {
        n = _n, m = _m;
        E.resize(n + m + 2);
        match.resize(n + m + 2);
        dist.resize(n + m + 2);
    }

    bool bfs() {
        queue<int> que;
        rep(i, 1, n + 1) {
            if (!match[i]) dist[i] = 0, que.push(i);
            else dist[i] = inf;
        }
        dist[0] = inf;
        while (!que.empty()) {
            int u = que.front();
            que.pop();
            if (u)
                fore(v, E[u]) if (dist[match[v]] == inf) {
                        dist[match[v]] = dist[u] + 1;
                        que.push(match[v]);
                    }
        }
        return (dist[0] != inf);
    }

    bool dfs(int u) {
        if (u) {
            fore(v, E[u]) if (dist[match[v]] == dist[u] + 1)
                    if (dfs(match[v])) {
                        match[v] = u;
                        match[u] = v;
                        return true;
                    }
            dist[u] = inf;
            return false;
        }
        return true;
    }

    void add(int a, int b) {
        b += n;
        E[a + 1].push_back(b + 1);
        E[b + 1].push_back(a + 1);
    }

    int whois(int x) { return match[x + 1] - 1; }

    int solve() {
        rep(i, 0, n + m + 1) match[i] = 0;
        int res = 0;
        while (bfs()) rep(i, 1, n + 1) if (!match[i] && dfs(i)) res++;
        return res;
    }
};

int main() {
    int N;
    cin >> N;
    vector<P> R(N);
    vector<P> B(N);
    rep(i, 0, N) cin >> R[i].first >> R[i].second;
    rep(i, 0, N) cin >> B[i].first >> B[i].second;

    BipartiteMatching bm;
    bm.init(N, N);
    rep(i, 0, N) rep(j, 0, N) {
            if (R[i].first < B[j].first && R[i].second < B[j].second) bm.add(i, j);
        }
    cout << bm.solve() << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int h, w, n;

bool solve(int y, int x, vector<vector<char>> &board) {
	vector<vector<char>> v = board;
	int x1 = x - 1, x2 = x;
	swap(v[y][x1], v[y][x2]);
	while(true) {
		for(int j = 0; j < w; ++j) {
			int cnt = h - 1;
			for(int i = h - 1; i >= 0; --i) {
				if(v[i][j] != '.') {
					swap(v[i][j], v[cnt][j]);
					--cnt;
				}
			}
		}
		vector<vector<char>> ans = v;
		bool flg = false;
		for(int i = 0; i < h; ++i) {
			char pre = '!';
			int cnt = 0;
			for(int j = 0; j < w; ++j) {
				if(pre != v[i][j]) {
					if(cnt >= n and pre != '.') {
						for(int k = 1; k <= cnt; ++k) {
							ans[i][j - k] = '.';
						}
						flg = true;
					}
					cnt = 1;
					pre = v[i][j];
				} else {
					cnt++;
				}
			}
			if(cnt >= n and pre != '.') {
				for(int k = 1; k <= cnt; ++k) {
					ans[i][w - k] = '.';
				}
				flg = true;
			}
		}
		for(int j = 0; j < w; ++j) {
			char pre = '!';
			int cnt = 0;
			for(int i = 0; i < h; ++i) {
				if(pre != v[i][j]) {
					if(cnt >= n and pre != '.') {
						for(int k = 1; k <= cnt; ++k) {
							ans[i - k][j] = '.';
						}
						flg = true;
					}
					cnt = 1;
					pre = v[i][j];
				} else {
					cnt++;
				}
			}
			if(cnt >= n and pre != '.') {
				for(int k = 1; k <= cnt; ++k) {
					ans[h - k][j] = '.';
				}
				flg = true;
			}
		}
		if(not flg) {
			bool ret = true;
			for(int i = 0; i < h; ++i) {
				for(int j = 0; j < w; ++j) {
					// cerr << ans[i][j];
					if(ans[i][j] != '.') ret = false;
				}
				// cerr << endl;
			}
			return ret;
		}
		v = ans;
	}
}

int main() {
	cin >> h >> w >> n;
	vector<vector<char>> board(h, vector<char>(w));
	rep(i,h)rep(j,w) cin >> board[i][j];
	for(int i = 0; i < h; ++i) {
		for(int j = 1; j < w; ++j) {
			if(solve(i, j, board)) {
				cout << "YES" << '\n';
				return 0;
			}
		}
	}
	cout << "NO" << '\n';
	return 0;
}


Measured memory_bytes: 3168
import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}
	
	int n = read.to!int;
	int k = read.to!int - 1;
	char[] s = readln.chomp.to!(char[]);
	
	if(s[k] == 'A') s[k] = 'a';
	if(s[k] == 'B') s[k] = 'b';
	if(s[k] == 'C') s[k] = 'c';
	
	s.writeln;
}


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

int main(){

bool N[10002];
//for(int i=0;i<10001;i++)
//N[i]=false;
int R[10003]={};
int H=2;

for(int i=3;H<=10001;i+=2)
{bool G=true;
for(int j=2;j<=sqrt((double)i);j++)
{if(i%j==0){G=false;break;}}
if(G==true){R[H]=i;H++;}
}

//N[2]=true;N[3]=true;
R[1]=2;R[0]=0;
int n;
while(1){

scanf("%d",&n);
if(n==0)break;
int s=0;
for(int i=1;i<=n;i++)
	s+=R[i];

printf("%d\n",s);
}
return 0;
}

Measured memory_bytes: 1072