akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
int keta;
string S;
vvll dp(1e6 + 1, vll(2, -1));
ll solve(int i, bool pitari)
{
    int x = S[i] - '0';
    if (i == keta - 1)
    {
        if (pitari)
            return dp[i][1] = x;
        else
            return dp[i][0] = 10 - x;
    }
    if (dp[i][pitari] != -1)
        return dp[i][pitari];

    if (pitari)
    {
        dp[i][true] = min(x + solve(i + 1, true), 1 + x + solve(i + 1, false));
        return dp[i][true];
    }
    else
    {
        dp[i][false] = min(9 - x + solve(i + 1, false), 10 - x + solve(i + 1, true));
        return dp[i][false];
    }
}
int main()
{
    cin >> S;

    keta = S.size();
    cout << min(solve(0, 1), solve(0, 0) + 1) << endl;
    return 0;
}

Measured memory_bytes: 134172
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 21
#define mod 1000000007

int n, k, m, i, a, b, c, lim, conf;
int rest[maxN][maxN];

int bit;
ll dp[1 << maxN][maxN];

void add(ll &a, ll b) {
    a += b;
    if (a >= mod) a -= mod;
}

int zrs(int x) {
    return (x ^ (x - 1)) & x;
}

int set_one(int conf, int pos) {
    static ll aux;

    conf ^= 1 << pos;
    aux = conf >> (pos + 1);

    if (aux == 0) return conf;
    return conf ^ (zrs(aux) << (pos + 1));
}

int main()
{
   // freopen("test.in","r",stdin);

    scanf("%d%d%d", &n, &m, &k);
    for (i = 1; i <= k; i++) {
        scanf("%d%d%d", &a, &b, &c);
        rest[a][b] = c + 1;
    }

    lim = 1 << (n - 1);
    dp[0][0] = 1;
    for (int ray = 1; ray <= m; ray++) {

        for (i = 0; i <= n - 2; i++) {
            for (conf = 0; conf < lim; conf++) {
                if (dp[conf][i] == 0) continue;
                bit = (conf >> i) & 1;


                if (rest[ray][i + 1] == 0) {

                    if (bit == 1) {
                        add(dp[conf][i + 1], dp[conf][i]);
                    } else {
                        add(dp[conf][i + 1], dp[conf][i]);
                        add(dp[ set_one(conf, i) ][i + 1], dp[conf][i]);
                    }

                    continue;
                }

                if (rest[ray][i + 1] == 1) {

                    if (bit == 1) {
                        //! no way boss
                    } else {
                        add(dp[conf][i + 1], dp[conf][i]);
                    }

                    continue;
                }

                if (rest[ray][i + 1] == 2) {

                    if (bit == 1) {
                        add(dp[conf][i + 1], dp[conf][i]);
                    } else {
                        add(dp[ set_one(conf, i) ][i + 1], dp[conf][i]);
                    }

                    continue;
                }
            }
        }

        for (conf = 0; conf < lim; conf++) {
            dp[conf][0] = dp[conf][n - 1];
            //cerr << dp[conf][0] << ' ';
            for (i = 1; i < n; i++)
                dp[conf][i] = 0;
        }

        //cerr << '\n';
    }

    ll ans = 0;
    for (conf = 0; conf < lim; conf++)
        add(ans, dp[conf][0]);

    printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 88448
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;


int main(){
	int n,m;
	cin >> n >> m;
	int sum = 0;
	for(int i = 0;i < m;i++){
		int a;
		cin >> a;
		sum += a;
	}

	if(n - sum >= 0)cout << n - sum << endl;
	else cout << -1 << endl;
}


Measured memory_bytes: 3636
line = False
while 1:
    a,b = map(int, raw_input().split())
    if a == b == 0: break
    if line: print
    line = True
    count = 0
    for i in range(a, b+1):
        if (i % 4 == 0 and i % 100 != 0) or (i % 400 == 0):
            print i
            count += 1
    if count == 0: print "NA"

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

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

  ll total = 0;
  map<ll, ll> mp;
  vector<int> A(N);
  rep(i,0,N-1) {
    cin >> A[i];
    total += A[i];
    mp[A[i]]++;
  }

  int Q;
  cin >> Q;

  ll b, c;
  queue<ll> answers;
  rep(i,0,Q-1) {
    cin >> b >> c;
    total -= b * mp[b];
    total += c * mp[b];
    mp[c] += mp[b];
    mp[b] = 0;
    answers.push(total);
  }

  while (!answers.empty()) {
    cout << answers.front() << endl; answers.pop();
  }

  return 0;
}


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

int main() {
  int N, K, a;
  a=1;
  cin >> N >> K;
  
  for (int i=0; i<N; i++){
    if (a <= K) {
      a *= 2;
    } else {
      a += K;
    }
  }
  cout << a << endl;
}

Measured memory_bytes: 256
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

sys.setrecursionlimit(2147483647)
INF = float('inf')

if os.getenv('LOCAL'):
    sys.stdin = open('_in.txt')

#
# N = int(sys.stdin.readline())
# print((N-2)*180)


S = sys.stdin.readline().rstrip() + 'oooooooooooooooooooooooooooooo'
if S[:15].count('o') >=8:
    print('YES')
else:
    print('NO')



Measured memory_bytes: 23080
n,m,X,Y=map(int,input().split())
x=[int(i) for i in input().split()]
y=[int(i) for i in input().split()]
a=0
for i in range(X+1,Y+1):
    if max(x)<i<=min(y):
        print("No War")
        a+=1
        break
if  a==0:
    print("War")

Measured memory_bytes: 3060
i=input()
b=True
while b==True:
  if int(i[0])+int(i[1])+int(i[2])+int(i[3])==7:
    print(i[0]+"+"+i[1]+"+"+i[2]+"+"+i[3]+"="+"7")
    exit
    b=False
  elif int(i[0])+int(i[1])+int(i[2])-int(i[3])==7:
    print(i[0]+"+"+i[1]+"+"+i[2]+"-"+i[3]+"="+"7")
    exit
    b=False
  elif int(i[0])+int(i[1])-int(i[2])-int(i[3])==7:
    print(i[0]+"+"+i[1]+"-"+i[2]+"-"+i[3]+"="+"7")
    exit
    b=False
  elif int(i[0])-int(i[1])+int(i[2])-int(i[3])==7:
    print(i[0]+"-"+i[1]+"+"+i[2]+"-"+i[3]+"="+"7")
    exit
    b=False
  elif int(i[0])-int(i[1])-int(i[2])-int(i[3])==7:
    print(i[0]+"-"+i[1]+"-"+i[2]+"-"+i[3]+"="+"7")
    exit
    b=False
  elif int(i[0])+int(i[1])-int(i[2])+int(i[3])==7:
    print(i[0]+"+"+i[1]+"-"+i[2]+"+"+i[3]+"="+"7")
    exit
    b=False
  elif int(i[0])-int(i[1])+int(i[2])+int(i[3])==7:
    print(i[0]+"-"+i[1]+"+"+i[2]+"+"+i[3]+"="+"7")
    exit
    b=False
  elif int(i[0])-int(i[1])-int(i[2])+int(i[3])==7:
    print(i[0]+"-"+i[1]+"-"+i[2]+"+"+i[3]+"="+"7")
    exit
    b=False

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  string s;
  cin >> s;

  int ans = 0;
  rep(i, 3) {
    if (s[i] == '1') ans++;
  }
  cout << ans << endl;


  
  return 0;
}

Measured memory_bytes: 256
n = int(input())
t = 0
x = 0
y = 0
d = 0
ans = 'No'
for i in range(0, n):
    t_p = t
    x_p = x
    y_p = y
    t, x, y = [int(_) for _ in input().split()]
    d = abs(x-x_p) + abs(y-y_p)
    delta_t = t - t_p
    if delta_t < d:
        break;
    if delta_t >= d and (delta_t-d)%2 != 0:
        break;
    if i == n-1:
        ans = 'Yes'
print(ans)


Measured memory_bytes: 3064
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(unused_variables)]

use proconio::{fastout, input};
use std::cmp::{max, min};

const INF: i32 = 1001001001;
const LNF: i64 = 1001001001001001001;
const MOD: i32 = 1000000007;

fn is_prime(x: usize) -> bool {
  if x == 1 {
    return false;
  }
  let mut i = 2;
  while i * i <= x {
    if x % i == 0 {
      return false;
    }
    i += 1;
  }
  true
}

#[fastout]
fn main() {
  input! {
    q: usize,
    lines: [(usize, usize); q],
  }
  let mut st = SegmentTree::new(100001, |a, b| a + b, 0);
  for i in (1..=100000).step_by(2) {
    if is_prime(i) && is_prime((i + 1) / 2) {
      st.set(i, 1);
    }
  }
  st.build();
  for (l, r) in lines {
    println!("{}", st.query(l, r + 1));
  }
}

struct SegmentTree<T> {
  v: Vec<T>,
  f: fn(T, T) -> T,
  e: T,
  n: usize,
}

impl<T: Copy> SegmentTree<T> {
  fn new(size: usize, f: fn(T, T) -> T, e: T) -> Self {
    let mut n = 1;
    while n < size {
      n <<= 1;
    }
    let v: Vec<T> = vec![e; n * 2];
    SegmentTree { v, f, e, n }
  }
  fn set(&mut self, k: usize, x: T) {
    self.v[k + self.n] = x;
  }
  fn build(&mut self) {
    for i in (1..self.n).rev() {
      self.v[i] = (self.f)(self.v[i * 2 + 0], self.v[i * 2 + 1]);
    }
  }
  fn query(&self, a: usize, b: usize) -> T {
    let mut l = self.e;
    let mut r = self.e;
    let mut a = a + self.n;
    let mut b = b + self.n;
    while a < b {
      if a & 1 == 1 {
        l = (self.f)(l, self.v[a]);
        a += 1;
      }
      if b & 1 == 1 {
        b -= 1;
        r = (self.f)(self.v[b], r);
      }
      a >>= 1;
      b >>= 1;
    }
    (self.f)(l, r)
  }
  fn update(&mut self, mut k: usize, x: T) {
    self.v[k + self.n] = x;
    k += self.n;
    while (k >> 1) > 0 {
      k >>= 1;
      self.v[k] = (self.f)(self.v[k * 2 + 0], self.v[k * 2 + 1]);
    }
  }
  fn reset(&mut self, k: usize) {
    self.update(k, self.e);
  }
}


Measured memory_bytes: 5588
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1LL << 60;
constexpr int INF = 1000000007;
const double INFD = 1e100;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// ----------------------------------------------------------------------------

int main(){
  int N,L;
  cin >> N >> L;
  int R = N+L-1;
  int e;
  if(R<=0){
    e = R;
  }else if(0<=L){
    e = L;
  }else{
    e = 0;
  }
  cout << (R+L)*(R-L+1)/2 - e << endl;
  return 0;
}


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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vec p = ivec(n);
    vector<double> rui(n + 1);
    rep (i, n)
        rui[i + 1] = rui[i] + (double)(p[i] + 1) / 2;

    double ma = -1;
    rep (i, n) {
        if (i + k > n) break;
        chmax(ma, rui[i + k] - rui[i]);
    }
    cout << setprecision(10) << ma << endl;

    return 0;
}


Measured memory_bytes: 3456
s = input()
q = int(input())
reverse = False
front = []
back = []
for i in range(q):
    inp = list(input().split())
    if len(inp) == 1:
        if reverse:
            reverse = False
        else:
            reverse = True
        continue
    t, f, c = inp[0], int(inp[1]), inp[2]
    if not reverse:
        if f == 1:
            front.append(c)
        else:
            back.append(c)
    else:
        if f == 2:
            front.append(c)
        else:
            back.append(c)
s = "".join(front[::-1]) + s + "".join(back)
if reverse:
    print(s[::-1])
else:
    print(s)


Measured memory_bytes: 6216
while True:
    lis = input().split()
    a=int(lis[0])
    b=int(lis[2])
    if lis[1]=='?':
        break
    elif lis[1]=='+':
        print(a+b)
    elif lis[1]=='-':
        print(a-b)
    elif lis[1]=='*':
        print(a*b)
    else:
        print(a//b)


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

int main(){
    int n, k;
    cin >> n >> k;
    
    vector<int> l(n);
    for (int i = 0; i < n; i++) cin >> l[i];
    
    sort(l.rbegin(), l.rend());
    
    int ans = 0;
    for (int i = 0; i < k; i++) ans += l[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
module AtCoder

(* Examples *)
(*
stdin.ReadLine()
printfn "%d"
printfn "%s"
*)

(* Library *)
module Library = ()

(* Standard Input *)
let readSplit elementFun=
  stdin.ReadLine().Split()
  |> Array.map elementFun

let read elementFun =
  stdin.ReadLine() |> elementFun

let readMap H =
  [|for i in 1..H -> stdin.ReadLine()|]
  |> Array.map(fun line ->
    line.ToCharArray()
  )
  |> array2D

(* Main *)
open Library

let n = 
  readSplit int
  |> Array.sum

(if n >= 22 then "bust" else "win") |> printfn "%s"

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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	string S,T;
	cin >>S>>T;

	string ans = "Yes";
	rep(i,S.length()){
		if(S[i]!=T[i]){
			ans = "No";
			break;
		}
	}
	cout<<ans<<"\n";
	return 0;
}


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

#define MOD 1000000007
typedef unsigned long long ull;

int main() {
  string s;
  cin >> s;
  int len = s.length();

  for (int i = 0; i < len; i++) {
    if (i % 2 == 0) {
      // 奇数
      if (s.at(i) == 'R' || s.at(i) == 'U' || s.at(i) == 'D') {
      } else {
        cout << "No";
        return 0;
      }
    } else {
      // 偶数
      if (s.at(i) == 'L' || s.at(i) == 'U' || s.at(i) == 'D') {
      } else {
        cout << "No";
        return 0;
      }
    }
  }
  cout << "Yes";
}

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

using namespace std;

struct cmp
{
    bool operator()(double &a,double &b)
    {
        return a>b;
    }
};

priority_queue<double,vector<double>,cmp>qu;
int n,i;

int main()
{
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		double temp;
		scanf("%lf",&temp);
		qu.push(temp);
	}
	while(qu.size()!=1)
	{
		double t1,t2;
		t1=qu.top();
		qu.pop();
		t2=qu.top();
		qu.pop();
		qu.push((t1+t2)/2.0);
	}
	printf("%lf",qu.top());
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> c(n);
    bool f[n];
    REP(i,n) f[i] = false;
    ll A = 0ll; ll B = 0ll;
    REP(i,n) {
        cin >> a[i];
        A += a[i];
    }
    REP(i,n) {
        cin >> b[i];
        B+=b[i];
    }
    if (A < B) {
        std::cout << -1 << std::endl;
        return 0;
    }
    int cnt = 0;
    REP(i,n) {
        c[i] = a[i] - b[i];
    }
    sort(c.begin(), c.end());
    ll ans = 0;
    REP(i,n) {
        if(c[i]>=0) break;
        else ans++;
        for(int j = c.size()-1; j > i; --j){
            if (c[i] >= 0) break;
            if(c[j]+c[i] >= 0) {
                //printf("prev, c[i] = %lld, c[j] = %lld\n", c[i], c[j]);
                if(!f[j]) ans++;
                f[j] = true;
                c[j] = c[j]+c[i];
                c[i] = 0;
                //printf("now, c[i] = %lld, c[j] = %lld\n", c[i], c[j]);
            }
            else if(c[j] > 0) {
                //printf("c[i] = %lld, c[j] = %lld\n", c[i], c[j]);
                if(!f[j]) ans++;
                f[j] == true;
                c[i] = c[i]+c[j];
                c[j] = 0;
                //printf("now, c[i] = %lld, c[j] = %lld\n", c[i], c[j]);
            }
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 2688
#[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, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}


fn main() {
    input! {
        s: chars,
        t: chars,
    }

    let pos = check_pos(&s, &t);

    //println!("hey. {}", pos);
    //println!("hey. length of s {}", s.len());
    
    if pos == -1 {
        println!("UNRESTORABLE");
    } else {
        let mut tmp = Vec::with_capacity(s.len());

        for (_, cs) in s.iter().rev().enumerate() {
            tmp.push(if *cs == '?'
                        {
                            'a'
                        } else {
                            *cs
                        });
        }
        
        for (i, ct) in t.iter().rev().enumerate() {
            tmp[pos as usize +i] = *ct; 
        }

        for a in tmp.iter().rev() {
            print!("{}", a);
        }
        println!("");
    }

}

fn check_pos(s: &Vec<char>, t: &Vec<char>) -> i32 {
    let t_len = t.len();
    if s.len() < t.len() {
        return -1;
    }
    let len = s.len() - t.len() + 1;

    

    for i in 0..len {
            let mut count = 0;
            for (ct, cs) in t.iter().rev().zip(s.iter().rev().skip(i)) {
                if *cs == '?' || *cs == *ct {
                    //println!("cs: {}, ct {}", *cs, *ct);
                    count = count + 1;
                } else {
                    break;
                }
                if count == t_len {
                    return i as i32;
                }
            }
    }

    -1

}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep(i,a,b) for(int i=(a);(i)<(b);(i)++)
#define ll long long
#define mp map<int,int>
using namespace std;
int main() {
	int a,b;
	cin>>a>>b;
	if(a%(b*2+1)==0)cout<<a/(b*2+1);
	else cout<<a/(b*2+1)+1;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

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

typedef vector<vector<int>> graph;

inline int get_index(int x, int y, int w) {
	return x + y * w;
}

inline void add_edge(graph &G, int a, int b) {
	G[a].emplace_back(b);
	G[b].emplace_back(a);
}

inline int bfs(int s, int g, vector<int> &dist, const graph &G, int ng_x = -1, int ng_y = -1) {
	const int n = G.size();

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

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

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

		if(v == g) return dist[v];

		for(const auto &to : G[v]) {
			if(v == ng_x && to == ng_y) continue;

			if(dist[to] == -1) {
				dist[to] = dist[v] + 1;
				que.push(to);
			}
		}
	}

	return -1;
}

vector<int> get_path(int v, const vector<int> &dist, const graph &G) {
	vector<int> res{v};
	while(dist[v] > 0) {
		for(const auto &to : G[v]) {
			if(dist[to] + 1 == dist[v]) {
				v = to;
				res.emplace_back(to);
				break;
			}
		}
	}
	reverse(res.begin(), res.end());
	return res;
}

int main() {
	int w, h, n;
	cin >> w >> h >> n;

	vector<vector<bool>> wall_h(h, vector<bool>(w - 1, false));
	vector<vector<bool>> wall_v(h - 1, vector<bool>(w, false));

	for(int i = 0; i < n; ++i) {
		int sx, sy, dx, dy;
		cin >> sx >> sy >> dx >> dy;

		if(sx == dx) {
			if(sx == 0 || sx == w) continue;
			if(sy > dy) swap(sy, dy);

			for(int y = sy; y < dy; ++y) {
				wall_h[y][sx - 1] = true;
			}
		}
		else {
			if(sy == 0 || sy == h) continue;
			if(sx > dx) swap(sx, dx);

			for(int x = sx; x < dx; ++x) {
				wall_v[sy - 1][x] = true;
			}
		}
	}

	const int V = w * h;
	graph G(V);

	for(int y = 0; y < h; ++y) {
		for(int x = 0; x < w - 1; ++x) {
			if(!wall_h[y][x]) add_edge(G, get_index(x, y, w), get_index(x + 1, y, w));
		}
	}

	for(int y = 0; y < h - 1; ++y) {
		for(int x = 0; x < w; ++x) {
			if(!wall_v[y][x]) add_edge(G, get_index(x, y, w), get_index(x, y + 1, w));
		}
	}

	int ix, iy, ox, oy;
	cin >> ix >> iy >> ox >> oy;

	const int s = get_index(ix, iy, w);
	const int g = get_index(ox, oy, w);

	vector<int> dist;
	const int base = bfs(s, g, dist, G);
	const auto path = get_path(g, dist, G);

	int ans = 0;
	for(unsigned i = 1; i < path.size(); ++i) {
		chmax(ans, bfs(s, g, dist, G, path[i - 1], path[i]) - base);
	}

	cout << ans << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1404
#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h> 
 
using namespace std;
 
#define len(x) (int)((x).size())
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vi vector<int> 
#define vvi vector<vector<int>>
#define pb push_back
 
#ifdef LOCAL
    #define dbg(x) cout << #x << " = " << x << endl;
#else 
    #define dbg(x)
#endif 
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);                                       
    freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(10);
    solve();    
}
 
const int INF = 1e18, MAXN = 2e5 + 10, MOD = 1e9 + 7;
int n, m, sum = 0;
int p[MAXN], sz[MAXN];

int get_set(int v) {
	if (p[v] == v) {
		return v;
	}

	return p[v] = get_set(p[v]);
}

void union_set(int a, int b) {
	a = get_set(a);
	b = get_set(b);

	if (a != b) {
		p[b] = a;
		sum -= sz[a] * sz[a]; sum -= sz[b] * sz[b];
		sz[a] += sz[b];
		sum += sz[a] * sz[a];
	}
}

void precalc() {
	for (int i = 0; i < MAXN; ++i) {
		p[i] = i;
		sz[i] = 1;
	}
}

void solve() {
	precalc();

	cin >> n >> m;
	vector<pair<int, int>> ed(m);
	for (int i = 0; i < m; ++i) {
		cin >> ed[i].x >> ed[i].y;
		ed[i].x--, ed[i].y--;
	}
	sum = n;

	reverse(all(ed));

	vi ans;
	ans.pb(sum);
	for (auto edge : ed) {
		int u, v;
		u = edge.x, v = edge.y;
		union_set(u, v);
		// dbg(sum)
		ans.pb(sum);
	}

	reverse(all(ans));
	ans.erase(ans.begin());
	

	for (auto it : ans) {
		cout << (n * n - it) / 2 << endl;
	}
}


Measured memory_bytes: 6900
n, m = map(int, input().split())
total = 0
d_list = []

for i in range(n):
  l = list(map(int, input().split()))
  d_list.append(l)

d_list = sorted(d_list)

for j in range(len(d_list)):
  p1 = d_list[j][0]
  p2 = d_list[j][1]
  if m > p2:
    m -= p2
    total += p1 * p2
  else:
    total += p1 * m
    break

print(total)

Measured memory_bytes: 28652
#include <iostream>
#include <vector>
#include <stack>
#include <map>
#include <string>

using Edge = std::map< std::string, long int>;
using Tree = std::map<long int, std::vector<Edge> >;

std::vector<long int> measureDistance(int root,  Tree tree){
    int N = tree.size();
    std::vector<bool> isVisited(N,false);
    std::vector<long int> distance(N);
    std::stack<int> stack;
    int parent = root;
    distance[parent-1]=0;
    isVisited[parent-1]=true;
    stack.push(parent);
    int child;
    long int length;
    while(!stack.empty()){
        parent = stack.top();
        stack.pop();
        for(auto &edge : tree[parent]){
            child = edge["child"];
            length = edge["length"];
            if(!isVisited[child-1]){
                distance[child-1] = (distance[parent-1]+length)&1;
                isVisited[child-1] = true;
                stack.push(child);
            }
        }
    }
    return distance;
}

int main(int argc, char *argv[]){
    int N;
    std::cin >> N;

    Tree tree;
    int u,v;
    long int w;
    Edge edge;
    for(int i=0; i<N-1; ++i){
        std::cin >> u >> v >> w;
        edge.clear();
        edge["length"] = w;
        edge["child"] = v;
        tree[u].emplace_back(edge);
        edge["child"] = u;
        tree[v].emplace_back(edge);
    }

    auto distance = measureDistance(1,tree);
    for(const auto &d : distance){
        std::cout << d << std::endl;
    }
    return 0;
}


Measured memory_bytes: 99328
#include<bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll  long long
#define ull unsigned long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd double
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
using namespace std;
ll a[200005];
ll b[200005];

int main(){
	boost;
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=1;i<=n;i++){
    	ll j;
    	cin>>j;
    	if(i%2 && j%2)ans++;
	}
	cout<<ans;

}
			
			


Measured memory_bytes: 3608
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] x = new int[N + 1];
        for (int i = 0; i < x.length; i++) {
            x[i] = sc.nextInt();
        }
        Arrays.sort(x);
        int D = 0;
        for (int i = 0; i < x.length - 1; i++) {
            D = gcd(D, x[i + 1] - x[i]);
        }
        System.out.println(D);
        sc.close();
    }

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

Measured memory_bytes: 48092
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    R, G, B, N = LI()
    ans = 0
    for r in range(0, N+1, R):
        for g in range(0, N+1 - r, G):
            if (N - r - g) % B == 0:
                ans += 1
    return ans

print(main())

Measured memory_bytes: 3064
s = input()
M = len(s)
N = int(s)

l1 = 9
l3 = 999-99
l5 = 99999-9999

ans = 0

if M == 1:
    ans = N
elif M == 2:
    ans = l1
elif M == 3:
    ans = l1 + N - 99
elif M == 4:
    ans = l1 + l3
elif M == 5:
    ans = l1 + l3 + N - 9999
elif M == 6:
    ans = l1 + l3 + l5

print(ans)


Measured memory_bytes: 3060
s = input()
S=[]
for c in s:
    S.append(int(c))

count0 = 0
count1 = 0

for i in range(len(S)):
    if S[i] == 0:
        count0 += 1
    if S[i] == 1:
        count1 += 1

remainder = max(count0, count1) - min(count0, count1)

print(len(S) - remainder)

Measured memory_bytes: 3956
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;
#define ll long long
#define Pair pair<int,int> 
#define Edge pair<int,ll>
#define nmax 100000
const ll inf = 1000000000000000;

int N,Q,K;
vector<Pair> xy;
vector<vector<Edge>> edge;

ll dis[nmax]; // store the shortest distance from K to i



void sub_solve(int k){
	for(int i=0;i<N;i++){
		dis[i] = inf;
	}

	stack<int> s;
	vector<bool> visit(N,false);
	int cur;

	s.push(k);dis[k] = 0;
	visit[k]=true;

	while(!s.empty()){
		cur = s.top(); s.pop();
		for(auto e:edge[cur]){
			int node = e.first;
			ll distance = e.second;
			dis[node] =  min(dis[node],dis[cur]+distance);
			if(!visit[node]){
				s.push(node);
				visit[node]=true;
			}
		}
	}
}


int solve(){
	//for all i, decide the shortest distance from K to i.
	sub_solve(K);

	// for(int i=0;i<N;i++){
	// 	cout << i << " to " << K << ": " << dis[i] << endl;
	// } 

	int x,y;
	for(int i=0;i<xy.size();i++){
		x=xy[i].first; y=xy[i].second;
		cout << dis[x] + dis[y] << endl;
	}
	return 0;
}



int main(){
	int a,b,x,y;
	ll c;
	cin >> N;
	edge.resize(N);
	for(int i=0;i<N-1;i++){
		cin >> a >> b >> c;
		a--;b--;
		edge[a].push_back({b,c});
		edge[b].push_back({a,c});
	}
	cin >> Q >> K;
	K--;
	xy.resize(Q);
	for(int i=0;i<Q;i++){
		cin >> x >> y;
		x--;y--;
		xy[i]={x,y};
	}
	solve();
	return 0;
}




Measured memory_bytes: 10752
#include<stdio.h>

int main(void){
	int H, W;
	int i, j;
	while(1){
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 0) break;
		for(i=0; i<H; i++){
			for(j=0; j<W; j++){
				if(i == 0 || i == H-1 || j == 0 || j == W-1) printf("#");
				else printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2036
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
int main(){
  ll n,q,x,count=0;
  string s;
  cin >> n >> q;
  cin >> s;
  ll l[n],r[n],flag[n];
  for(int i=0;i<q;i++){
    cin >> l[i] >> r[i];
  }
  for(ll j=0;j<n;j++){
    if(s[j] == 'A'){
      x = 1;
      flag[j] = count;
    }else{
      if(s[j] == 'C' && x == 1){
        count++;
      }
      flag[j] = count;
      x=0;
    }
  }
  for(int i=0;i<n;i++){
    //cout << flag[i];
  }
  //cout << endl;
  for(int i=0;i<q;i++){
    cout << flag[r[i]-1] - flag[l[i]-1] << endl;
  }
}


Measured memory_bytes: 3456
use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).ok();
    let mut n: i32 = input.trim().parse().unwrap();

    if 0 <= n && n < 86400 {
        let s = n % 60; // seconds
        n = (n - s) / 60;
        let m = n % 60; // minites
        n = (n - m) / 60;
        let h = n % 60; // hour
        println!("{}:{}:{}", h, m, s);
    }
}


Measured memory_bytes: 5028
#include<bits/stdc++.h>
using namespace std;
//define
typedef pair<int,int>pi;
#define int long long
#define elif else if
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define Rep(x,y) for(int k=x;k<y;k++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define vint vector<int>
#define vvint vector<vector<int>>
#define vtr vector<string>
#define vvtr vector<vector<string>>
#define vhar vector<char>
#define vvhar vector<vector<char>>
#define mod 100000007
#define elif else if
#define str string

signed main(){
  int N,M,O,P=0,c=0,co=0,cou=0;
  double D,Do;
  char C,Ca;
  str S,T;
  cin>>N;
  vint a(N);rep(0,N)cin>>a[i];
  rep(0,N)if(a[i]%2==1)c++;
  c%2==0?cout<<"YES"<<endl:cout<<"NO"<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i ++)
#define rep1(i, n) for (int i=1; i <= n; i ++)
#define _min(x, y) x = min(x, y)
#define _max(x, y) x = max(x, y)
using namespace std;


int main() {
  long long N, K; cin >> N >> K;
  vector<long long> A;
  vector<long long> F;
  rep(i, N) {
    long long a; cin >> a;
    A.push_back(a);
  }
  rep(i, N) {
    long long f; cin >> f;
    F.push_back(f);
  }
  sort(A.begin(), A.end());
  sort(F.begin(), F.end());
  reverse(F.begin(), F.end());

  long long e = 0;
  rep(i, N) {
    _max(e, A[i] * F[i]);
  }
  long long s = -1;
  long long ans = e;
  while (s + 1 < e) {
    long long use = 0;
    long long _ans = (e + s) / 2;
    // cout << _ans << endl;
    rep(j, N) {
      if (A[j] * F[j] >= _ans) {
        use += max(0ll, A[j] - (_ans / F[j]));
        // cout << " ";
      }
      // cout << (long long)(_ans / F[j]) << " " << A[j] << " " << F[j] << " " <<use << endl;
    }
    //cout << endl;
    if (use <= K) {
      e = _ans;
    } else {
      s = _ans;
    }
  }
  cout << e << endl;
  return 0;
}


Measured memory_bytes: 4848
import sys

n, x = list(map(int, input().split()))
exams = []
norma = 0
for i, line in enumerate(sys.stdin):
    b, l, u = map(int, line.split())
    exams.append((u * x - b * (u - l), b, l, u, i))
    norma += b * l
exams_sorted = sorted(exams, reverse=True)

remain_norma = norma
sub_d = -1
i = 0
used = set()
for i, (d, b, l, u, ei) in enumerate(exams_sorted):
    if remain_norma < d:
        sub_d = d
        break
    remain_norma -= d
    used.add(ei)

if sub_d == -1:
    print(n * x)
    exit()

base_ans = i * x
base_remain_norma = remain_norma

ans = 10 ** 10

for d, b, l, u, i in exams:
    if i in used:
        curr_remain_norma = base_remain_norma + d - sub_d
    else:
        curr_remain_norma = base_remain_norma
    if curr_remain_norma <= b * l:
        extra = (curr_remain_norma - 1) // l + 1
    else:
        extra = (curr_remain_norma + b * (u - l) - 1) // u + 1
    if extra > x:
        continue
    ans = min(ans, base_ans + extra)

print(ans)


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

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using ull = unsigned long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vvc = vector<vc>;
using ii = pair<int,int>;
using vii = vector<ii>;
using vvii = vector<vii>;
using dd = pair<double, double>;
using vdd = vector<dd>;
using vvdd = vector<vdd>;
using Mii = map<int,int>;
using vMii = vector<Mii>;

#define fi first
#define se second
#define INF INT_MAX
#define mod(a,m) (a%m+m)%m
#define PB push_back
#define MP make_pair

const int MOD = 1e9 + 7;

vvll a;

vvll prod(vvll& a, vvll& b) {
	int n = a.size();
	int m = b[0].size();
	int l = b.size();
	vvll ans(n, vll(m, 0));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			for (int k = 0; k < l; ++k) {
				ans[i][j] = (ans[i][j] + a[i][k] * b[k][j]) % MOD;
			}
		}
	}
	return ans;
}

vvll exp(vvll& a, ll k) {
	if(k == 1) return a;
	vvll temp = exp(a, k/2);
	vvll temp2 = prod(temp, temp);
	if(k&1) return prod(temp2, a);
	return temp2;
}

int main(){
//	cout.setf(ios::fixed);
//	cout.precision(4);
	int n;
	ll k;
	while (cin >> n >> k) {
		a = vvll(n, vll(n));
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				cin >> a[i][j];
			}
		}
		a = exp(a, k);
		ll ans = 0;
		for (auto f : a) for (auto x : f) ans = (ans + x) % MOD;
		cout << ans << '\n';
	}
}




Measured memory_bytes: 384
#include <stdio.h>
int main (void)
{
	int kazu=1,tou=1;//???????????\?????????????????¨??????
	int a,b,c;//for??????????????¨????????¢??°
	int an=0;//?????????????????¨?????¢??°

	
	while(1)
	{
		
		scanf("%d %d",&kazu,&tou);
		if((kazu==0)&&(tou==0)) break;
		

		for(a=1;a<=kazu;a++)//??°???????¢??????????????????????????????°?????\?????????
		{
			for(b=a+1;b<=kazu;b++)
			{
				for(c=b+1;c<=kazu;c++)
				{
					if((a+b+c==tou)&&(a!=b)&&(b!=c)&&(c!=a)) 
					{
						an++;
					}
				}
			}
		}
		
		printf("%d\n",an);
		an=0;
	}

	return 0;
}

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

const int N=2e+5+5;
int a[N];
int n;
map<int,int> mp;

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		mp[a[i]]++;
	}
	int ans=0;
	for(auto it:mp)
	{
		if(it.second==1)
			ans++;
		for(int i=2;i*it.first<=1e+6;i++)
		{
			int j=i*it.first;
			if(mp.find(j)!=mp.end())
				mp[j]=0;
		}
	}
	cout<<ans;
}



Measured memory_bytes: 13712
#![allow(dead_code)]
#![allow(unused_imports)]
use ascii::{AsciiChar, AsciiStr, AsciiString};
use indexmap::IndexMap;
use itertools::*;
use libm::*;
use num::*;
use ordered_float::OrderedFloat;
use permutohedron::LexicalPermutation;
use proconio::marker::{Bytes, Chars};
use proconio::{fastout, input};
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::mem::swap;

fn main() {
    input!(n:usize, d:[usize;n]);
    let mut ans = 0;
    for i in 0..n {
        for j in i+1..n {
            ans += d[i] * d[j]
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2088
N, Q = map(int, input().split())
tree_data = [tuple(map(int, input().split())) for i in range(N - 1)]
operation = [tuple(map(int, input().split())) for i in range(Q)]

tree_data = sorted(tree_data)

node = dict(zip(range(1, N + 1), [0] * N))
for o in operation:
    node[o[0]] += o[1]

for n in tree_data:
    node[n[1]] += node[n[0]]

print(' '.join(map(str, node.values())))


Measured memory_bytes: 99064
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 2147483647;
int prime = 998244353;
void Debug(auto a);
double PI = 3.14159265358979;
void input(vector<auto>& a,int n);
int n;


int gcd(int u, int v) {
  int r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
int lcm(int u,int v){
    int r = gcd(u,v);
    r = (u / r)*v;
    return r;
}
signed main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    a--;
    int l = lcm(c,d);
    int tmp1 = b/c-a/c;
    int tmp2 = b/d-a/d;
    int tmp3 = b/l-a/l;
    print(b-a-tmp1-tmp2+tmp3);
    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}

void input(vector<auto>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


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

int main(){
  int n;
  cin >> n;
  long long cnt[2]={};
  while(n--){
    int a,b;
    char c;
    cin >> a >> c >> b;
    cnt[c-'(']+= b;
    if(cnt[0] == cnt[1]) cout <<"Yes"<<endl;
    else cout <<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N,M;
    cin >> N >> M;
    vector<vector<int>>road(N);
    for(int i = 0; i < M; i++) {
        int A,B;
        cin >> A >> B;
        A--;B--;
        road[A].push_back(B);
        road[B].push_back(A);
    }
    queue<int> que;
    vector<int>cnt(N,-1);
    cnt[0] = 0;
    que.push(0);
    while(!que.empty()) {
        int x = que.front();
        que.pop();
        for(int i = 0; i < (int)road[x].size(); i++) {
            if(cnt[road[x][i]] == -1) {
                cnt[road[x][i]] = x;
                que.push(road[x][i]);
            }
        }
    }
    bool ok = true;
    for(int i = 0; i < N; i++) {
        if(cnt[i] == -1) {
            ok = false;
        }
    } 
    if(ok) {
        cout << "Yes" << endl;
        for(int i = 1; i < N; i++) {
            cout << cnt[i]+1 << endl;
        }
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 10216
object Main extends App {
    val in = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt))
    val n = in.next.head
    val tree = in.map(_.drop(2).map(_ - 1)).toList
    val res = List.fill(n)(Array.fill(2)(0))
    def solve(d: Int, id: Int, ids: Array[Int]): Int =
        if (res(id)(0) != 0) {
            d - 1
        } else {
            res(id)(0) = d
            val f_chld = ids.foldLeft(d)((_d, _id) => solve(_d + 1, _id, tree(_id)))
            res(id)(1) = f_chld + 1
            f_chld + 1
        }

    var x = 1
    for (i <- 0 until n if res(i)(0) == 0) {
        x = solve(x, i, tree(i)) + 1
    }
    res.zipWithIndex.foreach{case (x, i) => println(i + 1 + " " + x.mkString(" "))}
}

Measured memory_bytes: 44648
N = int(input())
H = list(map(int,input().split()))
m = 0
for k in range(1,N):
    if H[k-1] > H[k]+1 or H[k] < m:
        print("No")
        exit(0)
    elif H[k-1] == H[k]+1:
        m = H[k]
print("Yes")


Measured memory_bytes: 63856
#include <stdio.h>
#include <string.h>
typedef unsigned int uint;

inline static uint gl(void){
    uint x = 0;
    for(;;){
        const uint c = getchar_unlocked() - 48;
        if(c < 10){
            x = x*10 + c;
        }else{
            break;
        }
    }
    return x;
}

#define H 200000
uint v[H] __attribute__((aligned(64)));
int main(void){
    memset(v, 0x33, sizeof(uint)*H);
    {
        const uint h = gl();
        gl();
        const uint n = gl();
        for(uint i=0; i<n; i++){
            const uint x = gl()-1;
            const uint y = gl()-1;
            v[x] = y<v[x] ? y : v[x];
        }
        v[h] = 0;
    }
    {
        uint right = 0;
        uint x = 1;
        for(;;){
            const auto b = v[x];
            const auto r = right+1;
            if(b<r){
                printf("%d\n", x);
                return 0;
            }else if(b>r){
                right=r;
            }
            x++;
        }
    }
}


Measured memory_bytes: 896
#coding:UTF-8
num = int(input())
num_list = input()
new = num_list.split(" ")
#print(new)
min=int(new[0])
max=int(new[0])
for i in range(num):
  if min>int(new[i]):
    min=int(new[i])
  if max<int(new[i]):
    max=int(new[i])
print(max-min)


Measured memory_bytes: 3060
let n = stdin.ReadLine() |> int 

let mightAns =
    n
    |> float
    |> fun x -> x / 1.08 
    |> ceil
    |> int

mightAns
|> float
|> (*) 1.08
|> int
|> function
| x when x = n -> string mightAns
| _ -> ":( "
|> stdout.WriteLine

Measured memory_bytes: 11220
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        init();

        int N = nextInt();

        double[] probability = new double[N];

        for (int i = 0; i < probability.length; i++) probability[i] = nextDouble();

        double[][] coinProbabilities = new double[N + 1][N + 1];

        coinProbabilities[0][0] = 1;

        for (int i = 0; i < coinProbabilities.length; i++) {
            for (int j = 0; i + j <= N; j++) {
                int numOfCoins;
                if (i > 0) {
                    numOfCoins = j + i - 1;
                    coinProbabilities[i][j] += coinProbabilities[i - 1][j] * probability[numOfCoins];
                }

                if (j > 0) {
                    numOfCoins = i + j - 1;
                    coinProbabilities[i][j] += coinProbabilities[i][j - 1] * (1 - probability[numOfCoins]);
                }
            }
        }

        double ans = 0.0;
        for (int i = 0; i < coinProbabilities.length; i++) {
            for (int j = 0; j < coinProbabilities.length; j++) {
                if (i + j == N && i > j) ans += coinProbabilities[i][j];
            }
        }

        System.out.println(ans);
    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    private static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 130512