akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <cmath>
#include <iomanip>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int main() {
  int R;
  std::cin >> R;
  std::cout << std::fixed << std::setprecision(20);
  std::cout << std::acos(-1.0L) * 2 * R << '\n';
  return 0;
}


Measured memory_bytes: 3780
import sys

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """

    def __init__(self, n_max, mod=998244353):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

n,m,k = map(int,input().split())

mod = 998244353
ans = 0

comb = Combination(2*10**5)


for i in range(k+1):
    ans += m * comb(n-1, i) * pow(m-1, n-i-1, mod)
    ans %= mod

print(ans)


Measured memory_bytes: 100320
#include <iostream>
using namespace std;
long long number(long long x, long long y){
  long long a=x, b=y;
  while(x!=y){
    if(x < y)swap(x, y);
    x-=y;
  }
  return a*b/x;
}
int main(){
  long long a, b;
  long long c, d;
  cin >> a >> b >> c >> d;
  long long ans = (b/c + b/d - b/number(c, d))-((a-1)/c+(a-1)/d-(a-1)/number(c, d));
  cout << b-a+1-ans << endl;
  return 0;
}

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

int main(){
  string S;
  //vector <int> A;
  int count = 0;//the number of 0s
  cin >> S;
  //A.resize(S.size());
  for(int i = 0; i < S.size(); i++){
    //S[i]がoならば0
    if(S[i] == '0'){
    //  A[i] = 0;
      count++;
    }
    /*else{
      A[i] = 1;
    }*/
  }
  if(count > S.size() / 2){
    count = S.size() - count;
  }
  cout << 2 * count << endl;
  return 0;
}


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

using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<int> xs(n + 1);
    for (int i = 0; i < n; i++)
    {
        int p;
        cin >> p;
        xs[p] = i + 1;
    }
    multiset<int> id;
    if (xs[n - 1] > xs[n])
    {
        swap(xs[n - 1], xs[n]);
    }
    long ans = 1L * xs[n - 1] * (n + 1 - xs[n]) * (n - 1);
    id.insert(0);
    id.insert(n + 1);
    id.insert(xs[n - 1]);
    id.insert(xs[n]);
    for (int p = n - 2; p > 0; p--)
    {
        auto itne = id.lower_bound(xs[p]);
        auto itpr = prev(itne);
        long res = 0;
        bool f = 1;
        if (*itpr == 0)
        {
            res += 1L * (*next(itne) - (*itne)) * xs[p];
            f = 0;
        }
        else
        {
            res += 1L * (*itpr - *prev(itpr)) * ((*itne) - xs[p]);
        }
        if (*itne == n + 1)
        {
            res += 1L * (*itpr - *prev(itne)) * (n + 1 - xs[p]);
        }
        else
        {
            if (f)
                res += 1L * (xs[p] - *itpr) * (*next(itne) - (*itne));
        }
        //cout << res << endl;
        res *= p;
        ans += res;
        id.insert(xs[p]);
    }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}


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

int main(){
  int n;
  while(cin >> n){
    int cnt = 0;
    for(int a = 0; a < 10; a++){
      for(int b = 0; b < 10; b++){
        for(int c = 0; c < 10; c++){
          for(int d = 0; d < 10; d++){
            if(a + b + c + d == n)
             cnt++;
          }
        }
      }
    }
    cout << cnt << endl;
  }

}

Measured memory_bytes: 3056
#include <stdio.h>
#include <string.h>
int main()
{
	int n;
	scanf("%d",&n);
	char name[128];
	scanf("%s",name);
	int namelen=strlen(name);
	char kanban[128];
	int count=0;
	for(int k=0;k<n;k++)
	{
		scanf("%s",kanban);
		int kanbanlen=strlen(kanban);
		for(int start=0;start<kanbanlen;start++){
			for(int step=1;start+(namelen-1)*step<kanbanlen;step++){
				for(int i=0;i<namelen;i++){
					if(kanban[start+i*step]!=name[i]){
						goto fail;
					}
				}
				count++;
				goto naxtk;
			  fail:;
			}
		}
	  naxtk:;
	}
	printf("%d\r\n",count);
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

int main()
{
    int H, W, D;
    cin >> H >> W >> D;

    int A[H+10][W+10];
    int a;
    rep(i,H) rep(j,W) cin >> A[i][j];

    int Q;
    cin >> Q;

    int L[Q+10], R[Q+10];
    rep(i,Q) cin >> L[i] >> R[i];

    map<int, pair<int,int>> field;
    rep(i,H) rep(j,W) field[A[i][j]] = make_pair(i,j);

    int accum[D+10][H*W/D+10];
    rep(i,D) rep(j, H*W/D) accum[i][j] = 0;

    rep(i,D)
    {
        int x;
        if (i == 0) x = D;
        else x = i;
        while (x + D <= H*W)
        {
            accum[i][x/D+1] = accum[i][x/D] + abs(field[x].first - field[x+D].first) + abs(field[x].second - field[x+D].second);
            x += D;
        }
    }

    rep(q,Q)
    {
        int x = L[q], y = R[q];
        int ans = accum[x%D][y/D] - accum[x%D][x/D];   
        cout << ans << endl;
    }
}

Measured memory_bytes: 11136
N=int(input())
A=[int(x) for x in input().split()]
count=0
for i in range(N):
    if 1<=A[i]<=399:
        A[i]=1
    elif 400<=A[i]<=799:
        A[i]=2
    elif 800<=A[i]<=1199:
        A[i]=3
    elif 1200<=A[i]<=1599:
        A[i]=4
    elif 1600<=A[i]<1999:
        A[i]=5
    elif 2000<=A[i]<=2399:
        A[i]=6
    elif 2400<=A[i]<=2799:
        A[i]=7
    elif 2800<=A[i]<=3199:
        A[i]=8
    else:
        A[i]=9
        count+=1

A=[x for x in set(A)]

if A==[9]:
    print(1,count)
else:
    if 9 in A:
        print(len(A)-1,len(A)-1+count)
    else:
        print(len(A),len(A))


Measured memory_bytes: 3064
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
 
signed main() {
	IOS;
	#ifdef LOCAL
		freopen("input.txt","r", stdin);
		freopen("output.txt","w",stdout);
	#endif
	int r;
	cin >> r;
	cout << 3*r*r;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//整数の入力
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		//条件分岐
		if(A == 5) {
			if((B == 5 && C == 7) || (B == 7 && C == 5)) {
				System.out.println("YES");
				return;
			}
		}
		if(A == 7) {
			if(B == 5 && C == 5) {
				System.out.println("YES");
				return;
			}
		}
		System.out.println("NO");
	}

}


Measured memory_bytes: 20948
#pragma GCC optimize(2)
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, int> pdd;

const ll mod = 1e9 + 7;
const int N = 20, M = 1e5 + 10;
const ll INF = 1e18;
const int inf = 0x3f3f3f3f;
const double eps = 1e-4;

#define pi acos(-1)
#define mk make_pair

int main()
{
    string s;
    cin >> s;
    if(s == "ABC")
        puts("ARC");
    else
    {
        puts("ABC");
    }
    
    return 0;
}

/*

*/

Measured memory_bytes: 3596
while l = gets.to_i
  break if l.zero?
  savings = 0
  months = 0
  flag = false

  12.times do |month|
    m, n = gets.split.map(&:to_i)
    savings += (m-n)
    if l <= savings && !flag
      months = month+1
      flag = true
    end
  end

  puts flag ? months : "NA"
end

Measured memory_bytes: 6100
#include <iostream>
#include <cstdint>
#include <cmath>
using namespace std;

int main() {
    int64_t n, d; cin >> n >> d;

    int64_t ans = 0;
    while (n--) {
        int64_t x, y; cin >> x >> y;

        if ((x * x + y * y) <= d * d) {
            ++ans;
        }
    }

    cout << ans << endl;


    /*int n, d;
    cin >> n >> d;
    int ans = 0;
    while (n--) {
        int x, y;
        cin >> x >> y;
        if (x * x + y * y <= d * d) {
            ++ans;
        }
    }
    cout << ans << endl;*/
}



Measured memory_bytes: 3632
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


class DGraph:
    def __init__(self, n, edges):
        self._vertice = [{} for _ in range(n)]
        for e in edges:
            self._vertice[e[0]][e[1]] = e[2] if len(e) == 3 else 1

    def __len__(self):
        return len(self._vertice)

    def edges(self, n=None):
        srcs = range(len(self)) if n is None else [n]
        return sum([[(s, d, c) for d, c in self._vertice[s].items()] for s in srcs], [])

    def transpose(self):
        tedges = [(t, f, c) for f, t, c in self.edges()]
        return DGraph(len(self), tedges)

    def cost(self, src, dst):
        return self._vertice[src].get(dst, float('inf'))


def dijkstra(g, src, dst):
    import heapq

    min_cost = [[float('inf')] * 3 for _ in range(len(g))]

    node_heap = []
    heapq.heappush(node_heap, (0, 0, src))
    while node_heap:
        cost, hop, node = heapq.heappop(node_heap)
        if min_cost[node][hop] <= cost:
            continue
        min_cost[node][hop] = cost

        for _, d, c in g.edges(node):
            dc = min_cost[node][hop] + c
            dh = (hop + 1) % 3
            heapq.heappush(node_heap, (dc, dh, d))
    ret = min_cost[dst][0] // 3
    if isnan(ret):
        return -1
    return ret



def solve(N: int, M: int, u: "List[int]", v: "List[int]", S: int, T: int):
    es = [(cu - 1, cv - 1, 1) for cu, cv in zip(u, v)]
    g = DGraph(N, es)

    S = S - 1
    T = T - 1
    cost = dijkstra(g, S, T)
    return cost


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    u = [int()] * (M)  # type: "List[int]" 
    v = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
    S = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    result = solve(N, M, u, v, S, T)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 77492
# -*- coding: utf-8 -*-
# 13:50 -> 

class Node():
    def __init__(self, idx):
        self.idx = idx
        self.next_node = []
    
    def add_node(self, node):
        self.next_node.append(node)

N, M = map(int, input().split())
nodes = {i:Node(i) for i in range(1,N+1)}

for m in range(M):
    a,b = map(int, input().split())
    nodes[a].add_node(nodes[b])
    nodes[b].add_node(nodes[a])

def permutation_search(idxs, now_idx):
    if len(idxs) == 0:
        return 1

    num = 0
    for i in range(len(idxs)):
        next_idx = idxs[i]
        next_idxs = idxs[:i]+idxs[i+1:]
        if next_idx in [node.idx for node in nodes[now_idx].next_node]:
            num += permutation_search(next_idxs, next_idx)
    
    return num

total = permutation_search([i for i in range(2,N+1)], 1)

print(total)

Measured memory_bytes: 75144
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
 
typedef long long ll;
 
using namespace std; 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;
 
#define REP(inc, bgn, end) for (int inc = bgn; inc < end; inc++)

int main() {
    ll x, now = 100;
    cin >> x;
    int cnt = 0;
    while (true) {
        now *= 1.01;
        cnt++;
        if (now >= x) {
            cout << cnt << endl;
            exit(0);
        }
    }

}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main(){
    int n,cnt;
    int *L;
    cin >> n;
    cnt=0;
    L= new int[n];
    for(int num=0;num<n;num++){
        cin >> L[num]; 
    }
    for (int i=0;i<n;i++){
        for (int j=0;j<i;j++){
               for (int k=0;k<j;k++){
                   if(L[i]!=L[j]&&L[k]!=L[i]&&L[k]!=L[j]){
                       if(L[i]+L[j]>L[k]&&L[j]+L[k]>L[i]&& L[i]+L[k]>L[j]){
                           cnt++;
                           //cout<<L[i]<<L[j]<<L[k]<<endl;
                       }
                    }
                }
            }
    }
    cout <<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

vector<ll> vecx, vecy;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    string s; cin >> s;
    int x, y; cin >> x >> y;

    bool xflag = true;
    int cnt = 0;
    rep(i, s.size()){
        if(s[i] == 'T'){
            if(xflag && cnt != 0){
                vecx.push_back(cnt);
            }
            else if(!xflag && cnt != 0){
                vecy.push_back(cnt);
            }
            cnt = 0;
            xflag = !xflag;
        }
        else{
            cnt++;
            if(i == s.size() - 1){
                if(xflag && cnt != 0){
                    vecx.push_back(cnt);
                }
                else if(!xflag && cnt != 0){
                    vecy.push_back(cnt);
                }
            }
        }
    }

    if(s[0] == 'F'){
        x -= vecx[0];
        vecx.erase(vecx.begin());
    }

    // for(auto x : vecx){
    //     cout << x << endl;
    // }
    // cout << endl;
    // for(auto y : vecy){
    //     cout << y << endl;
    // }

    x += accumulate(vecx.begin(), vecx.end(), 0);
    y += accumulate(vecy.begin(), vecy.end(), 0);

    rep(i, vecx.size()){
        vecx[i] *= 2;
    }
    rep(i, vecy.size()){
        vecy[i] *= 2;
    }

    set<int> stx, sty;
    stx.insert(0);
    sty.insert(0);

    for(auto t : vecx){
        vector<int> vtemp;
        for(auto e : stx){
            vtemp.push_back(e + t);
        }
        for(auto enew : vtemp){
            stx.insert(enew);
        }
    }
    for(auto t : vecy){
        vector<int> vtemp;
        for(auto e : sty){
            vtemp.push_back(e + t);
        }
        for(auto enew : vtemp){
            sty.insert(enew);
        }
    }

    if(stx.find(x) != stx.end() && sty.find(y) != sty.end()){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

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

int main(){
  int n, m; cin >> n >> m;
  int H[m];
  for (int i=0; i<m; i++){
    H[i] = 0;
  }
  for (int i=0; i<n; i++){
    int numbers; cin >> numbers;
    for (int j=0; j<numbers; j++){
      int temp; cin >> temp;
      H[temp - 1] += 1;
    }
  }
  int ans; ans = 0;
  for (int i=0; i<m; i++){
    if(H[i] == n){
      ans += 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    x, y, z = map(int, input().split())
    x, y = y, x
    x, z = z, x
    print(x, y, z)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 38256
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,m=nii()
ab=[lnii() for i in range(n)]
cd=[lnii() for i in range(m)]

ans=[]
for a,b in ab:
  min_dist=10**10
  for i in range(m):
    c,d=cd[i]
    if abs(a-c)+abs(b-d)<min_dist:
      t_ans=i
      min_dist=abs(a-c)+abs(b-d)
  ans.append(t_ans+1)

for i in ans:
  print(i)

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  
  int n, m;
  cin >> n >> m;
  
  map<pair<int, int>, int> name;
  vector<vector<pair<int, int>>> adj;
  
  for (int i = 0; i < n; i++) {
    name[{i, 0}] = adj.size();
    adj.emplace_back();
  }

  for (int i = 0; i < m; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    u--, v--;
    if (name.count(make_pair(u, c)) == 0) {
      name[{u, c}] = adj.size();
      adj.emplace_back();
      adj[name[{u, 0}]].emplace_back(name[{u, c}], 1);
      adj[name[{u, c}]].emplace_back(name[{u, 0}], 0);
    }
    if (name.count(make_pair(v, c)) == 0) {
      name[{v, c}] = adj.size();
      adj.emplace_back();
      adj[name[{v, 0}]].emplace_back(name[{v, c}], 1);
      adj[name[{v, c}]].emplace_back(name[{v, 0}], 0);
    }
    adj[name[{u, c}]].emplace_back(name[{v, c}], 0);
    adj[name[{v, c}]].emplace_back(name[{u, c}], 0);
  }

  vector<int> dist(name.size(), -1);
  deque<pair<int, int>> dq;
  dq.emplace_back(name[{0, 0}], 0);
  dist[name[{0, 0}]] = 0;

  while (!dq.empty()) {
    int u = dq.front().first;
    int dt = dq.front().second;
    dq.pop_front();
    if (dist[u] != dt) {
      continue;
    }

    for (auto &i : adj[u]) {
      if (i.second == 0) {
        if (dist[i.first] == -1 || dist[i.first] > dist[u]) {
          dist[i.first] = dist[u];
          dq.emplace_front(i.first, dist[i.first]);
        }
      } else if (i.second == 1) {
        if (dist[i.first] == -1 || dist[i.first] > dist[u] + 1) {
          dist[i.first] = dist[u] + 1;
          dq.emplace_back(i.first, dist[i.first]);
        }
      }
    }
  }

  cout << dist[name[{n - 1, 0}]] << "\n";
  return 0;

}

Measured memory_bytes: 64296
<?php
    $num = intval(trim(fgets(STDIN)));
    
    $line = trim(fgets(STDIN));
    
    if(strlen($line)<=$num){
        echo $line."\n";
    }else{
        echo substr($line,0,$num)."...\n";
    }
    
    
    
    
    
    
?>

Measured memory_bytes: 16140
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

const int MaxNL = 500000;

char s[MaxNL + 2];

struct bigNum
{
	int l, w;
	int a[MaxNL + 3];

	inline void read()
	{
		scanf("%s", s + 1);
		l = strlen(s + 1);
		reverse(s + 1, s + l + 1);

		for (int i = 1; i <= l; ++i)
			a[i] = s[i] - '0';

		int t = w = 0;
		for (int i = 1; i <= l; ++i)
		{
			t += a[i] * 9;
			w += (a[i] = t % 10);
			if ((t /= 10) > 0 && i == l)
				++l;
		}
	}

	inline void operator+=(const int &v)
	{
		int t = v;
		for (int i = 1; t && i <= l; ++i)
		{
			w -= a[i], t += a[i];
			w += (a[i] = t % 10);
			if ((t /= 10) > 0 && i == l)
				++l;
		}
	}
};
bigNum cur;

int main()
{
	cur.read();

	for (int k = 1; ; ++k)
	{
		cur += 9;
		if (cur.w <= 9 * k)
		{
			cout << k << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 2688
import math

sets = dict()

def gcd2(a, b):
    if a > b:
        key = (b, a)
    else:
        key = (a, b)
    
    try:
        # print("cached")
        return sets[key]
    except:
        # print("stored")
        ans = math.gcd(a, b)
        sets[key] = ans
        return ans

n = int(input())

ans = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        pre = gcd2(i, j)

        for k in range(1, n+1):
            ans += gcd2(pre, k)

print(ans)


Measured memory_bytes: 10960
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

const int MOD = 1e9 + 7;

map<pair<int, int>, int> C;

long long fact[500005] = {1};

int power(int a, int n) {
	long long ret = 1;
	while (n) {
		if (n & 1) ret = ret * a % MOD;
		a = 1LL * a * a % MOD;
		n >>= 1;
	}
	return ret;
}
long long comb(int n, int m)
{
	long long ret = 1LL * fact[n] * power(fact[m], MOD - 2) % MOD;
	ret = ret * power(fact[n - m], MOD - 2) % MOD;
	return ret;
}
int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= max(n, m); i++) {
		fact[i] = 1LL * fact[i - 1] * i % MOD;
	}
	long long a = 1LL * comb(m, n) * fact[n] % MOD;
	// printf("%lld\n", a);
	long long b = a;
	bool neg = true;
	for (int i = 1; i <= n; i++) {
		// printf("C(%d,%d), C(%d, %d), %d!\n", n, i, m - i, n - i, n - i);
		long long t = comb(n, i) * comb(m - i, n - i) % MOD;
		t = t * fact[n - i] % MOD;
		if (neg) {
			b -= t;
			if (b < 0) b += MOD;
		} else {
			b += t;
			b %= MOD;
		}
		neg = !neg;
	}
	long long ans = a * b % MOD;
	printf("%lld\n", ans);
	return 0;
}


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

int gcd(int a,int b){
    if (b>a){
        b+=a;
        a=b-a;
        b=b-a;
    }
    if (a%b==0){
        return b;
    }else{
        return(gcd(b,a%b));
    }
}

int main(){
    int K;
    cin >> K;
    int sum=0;
    int r=0;
    for (int a=1;a<=K;a++){
        for(int b=1;b<=K;b++){
            r=gcd(a,b);
            if (r==1){
                sum+=K;
            }else{
                for(int c=1;c<=K;c++){
                    sum+=gcd(r,c);
                }
            }
        }
    }
    cout << sum;
}

Measured memory_bytes: 3596
while true
  n = gets.to_f
  exit if n == 0
  s = gets.chomp.split(" ").map{|x|x.to_f}
  sum = 0.0
  s.size.times do |i|
    sum += s[i]
  end
  heikin = sum / n
  ans = 0.0
  s.size.times do |i|
    ans += ((s[i] - heikin)**2)
  end
  p (ans / n)**0.5
end

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

int main(){
  int x,y,z;
  cin>>x>>y>>z;
  int a,b;
  a=x;
  x=y;
  y=a;
  b=x;
  x=z;
  z=b;
  cout<<x<<" "<<y<<" "<<z<<endl;
  
  return 0;
}

Measured memory_bytes: 256
s, t, k = map(int,input().split())

if s>=k:
  ans_s = s-k
  ans_t = t
else:
  ans_s, k = 0, k-s
  if k<t:
    ans_t = t-k
  else:
    ans_t = 0
print(ans_s, ans_t)

Measured memory_bytes: 2940
import math

class Point:
    def __init__(self):
        self.x = None
        self.y = None

def koch(d, p1, p2):
    if d == 0:
        return

    s = Point()
    u = Point()
    t = Point()
    rad = math.radians(60)

    s.x = (2 * p1.x + 1 * p2.x) / 3
    s.y = (2 * p1.y + 1 * p2.y) / 3
    t.x = (1 * p1.x + 2 * p2.x) / 3
    t.y = (1 * p1.y + 2 * p2.y) / 3
    u.x = (t.x - s.x) * math.cos(rad) - (t.y - s.y) * math.sin(rad) + s.x
    u.y = (t.x - s.x) * math.sin(rad) + (t.y - s.y) * math.cos(rad) + s.y
    
    koch(d-1, p1, s)
    print(s.x, s.y)
    koch(d-1, s, u)
    print(u.x, u.y)
    koch(d-1, u, t)
    print(t.x, t.y)
    koch(d-1, t, p2)

def main():
    n = int(input())
    a = Point()
    b = Point()

    a.x = 0.0
    a.y = 0.0
    b.x = 100.0
    b.y = 0.0

    print(a.x, a.y)
    koch(n, a, b)
    print(b.x, b.y)
    
             
if __name__ == "__main__":
    main()


Measured memory_bytes: 5800
from bisect import bisect_left
import sys

input = sys.stdin.readline

s = input().strip()
n = len(s)
t = input().strip()

d = [[] for _ in range(26)]
base = ord('a')
for i, c in enumerate(s):
    idx = ord(c) - base
    d[idx].append(i)

string_count = 0
cur = -1
for tt in t:
    cur += 1
    idx = ord(tt) - base
    pos_lst = d[idx]
    lst_len = len(pos_lst)

    if not lst_len:
        print(-1)
        exit()
    pos = bisect_left(pos_lst, cur)  # cur以降で文字ttが見つかる位置
    if lst_len == pos:
        string_count += 1
        cur = pos_lst[0]
    else:
        cur = pos_lst[pos]

    # print(cur, pos_lst, lst_len, string_count * n)

print(string_count * n + cur + 1)


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

int main(){
    ll n;
    cin >> n;
    vector<ll> vec(n+1);
    ll a=0,b=1;
    for(ll i=0;i<n;i++){
        cin >> vec[i];
        if(vec[i]==b){
            a++;
            b++;
        }
    }
    if(a==0) cout << "-1" << endl;
    else cout << n-a << endl;
    

    return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int M1;
int D1;
int M2;
int D2;
int main(){
  rd(M1);
  rd(D1);
  rd(M2);
  rd(D2);
  if(M1!=M2){
    wt_L(1);
    wt_L('\n');
  }
  else{
    wt_L(0);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20191227-1

// --- original code ---
// int M1, D1, M2, D2;
// {
//   rd(M1,D1,M2,D2);
//   wt(if[M1!=M2, 1, 0]);
// }


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);

        int n = stdIn.nextInt();

        if(n < 105){
            System.out.println(0);
        }else if(n < 135){
            System.out.println(1);
        }else if(n < 165){
            System.out.println(2);
        }else if(n < 189){
            System.out.println(3);
        }else if(n < 195){
            System.out.println(4);
        }else{
            System.out.println(5);
        }
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
  string s;
  cin>>s;
  for(int i=0;i<3;i++)
  {
   if(s[i]=='7')
   {
     cout<<"Yes"<<endl;
     return 0;
   }
  }
  cout<<"No"<<endl;
  return 0;
}


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

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(10);

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

    vector<int> q(n);
    q[0] = p[0];
    for (int i = 1; i < n; i++)
    {
        q[i] = min(q[i - 1], p[i]);
    }

    int count=0;
    for (int i = 0; i < n; i++)
    {
        if(p[i]==q[i])
            count++;
    }
    cout << count << endl;

}


Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;

#define rep(i, n) for (i = 0; i < n; i++)
#define P pair<int, int>

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

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  bool odd;
  if (n % 2 == 1)
  {
    odd = true;
  }
  else
  {
    odd = false;
  }

  if (odd)
  {
    int med_lb = a[(n - 1) / 2];
    int med_ub = b[(n - 1) / 2];
    cout << med_ub - med_lb + 1 << endl;
  }
  else
  {
    int med_lb_2 = a[n / 2 - 1] + a[n / 2];
    int med_ub_2 = b[n / 2 - 1] + b[n / 2];
    cout << med_ub_2 - med_lb_2 + 1 << endl;
  }
}


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

int main(){
  int N;
  cin >> N;
  char S[N+10];
  for(int i=0; i<N; i++){
    cin >> S[i];
    if(S[i]=='Y'){
      cout << "Four" << endl;
      return 0;
    }
  }cout << "Three" << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
accept = set()
penalty = 0
wa_cnt = [0] * N

for m in range(M):
    p, s = input().split()
    p = int(p) -1 
    if p in accept:
        continue
    elif s == 'AC':
        accept.add(p)
        penalty += wa_cnt[p]
    else:
        wa_cnt[p] += 1

print(len(accept), penalty)



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

int main(){ 
int n;
cin>>n;
vector<int> a(n);
for(int i=0; i<n; i++){
cin>>a[i];
}
vector<int> b(n);
for(int i=0; i<n; i++){
b[i]=a[i];
}
sort(a.begin(), a.end());
reverse(a.begin(), a.end());
for(int i=0; i<n; i++){
if(b[i]==a[0]){
cout<<a[1]<<endl;
}
else{
cout<<a[0]<<endl;
}
}
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using ll = long long;
using ull = unsigned long long;

/* Counter Lib */
template <class T>
class Counter {
 public:
  Counter() = default;
  template <class U>
  Counter(const U& container) {
    for (auto x : container) {
      counter_[x]++;
    }
  }
  auto val(const T& key) const { return counter_.find(key)->second; }
  auto add(const T& key) { counter_[key]++; }
  auto get() { return counter_; }
  auto get() const { return counter_; }
  auto hist() const {
    map<int, int> hist_counter;
    for (auto kv : counter_) {
      hist_counter[kv.second]++;
    }
    return hist_counter;
  }

 private:
  map<T, int> counter_;
};
/* /Counter Lib */

int main(int argc, char* argv[]) {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  /* */
  int h, w, n;
  cin >> h >> w >> n;

  int dx[] = {-2, -2, -2, -1, -1, -1, 0, 0, 0};
  int dy[] = {-2, -1, 0, -2, -1, 0, -2, -1, 0};

  Counter< std::pair<int, int> > counter;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> y >> x;
    --x;  --y;
    for (int j = 0; j < 9; ++j) {
      int nx = x + dx[j];
      int ny = y + dy[j];
      if (0 <= nx && nx < w - 2 && 0 <= ny && ny < h - 2) {
        counter.add( make_pair(nx, ny) );
      }
    }
  }

  ll total = (ll)(w - 2) * (h - 2);
  auto hist = counter.hist();
  for (auto kv : hist) {
    total -= kv.second;
  }
  printf("%lld\n", total);
  for (int i = 1; i <= 9; ++i) {
    printf("%d\n", hist[i]);
  }

  /* */

  return EXIT_SUCCESS;
}


Measured memory_bytes: 56576
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e16;
#define int long long

const int MAX_N = 1010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	int ans = 0; int ans2 = 0;
	int sum = 0;
	rep(i, n) {
		sum += a[i];
		if (i % 2 == 0) {
			if (sum <= 0) {
				ans += 1 - sum; sum = 1;
			}
		}
		else {
			if (sum >= 0) {
				ans += sum + 1; sum = -1;
			}
		}
	}
	sum = 0;
	rep(i, n) {
		sum += a[i];
		if (i % 2 == 1) {
			if (sum <= 0) {
				ans2 += 1 - sum;
				sum = 1;
			}
		}
		else {
			if (sum >= 0) {
				ans2 += sum + 1;
				sum = -1;
			}
		}
	}
	COUT(min(ans, ans2));
	return 0;
}


Measured memory_bytes: 1024
import numpy as np

N, W = map(int, input().split())
MAX_V = (10**3) * N + 1
INF = 1 << 60

dp = np.full(MAX_V, INF)
dp[0] = 0

for i in range(N):
    w, v = map(int, input().split())
    np.minimum(dp[v:], dp[:-v] + w, out=dp[v:])

print(np.where(dp <= W)[0].max())

Measured memory_bytes: 21252
#include <cstdio>
#include <cstdint>
#include <map>
#include <algorithm>

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

  std::map<int, int> F;
  for (int i = 0; i < N; ++i) {
    int a;
    scanf("%d", &a);
    ++F[a];
  }

  intmax_t res = 0;
  for (const auto& p: F) {
    int a = p.first;
    int k = p.second;
    if (k == a) continue;
    if (k < a) {
      res += k;
    } else {
      res += k-a;
    }
  }
  printf("%jd\n", res);
}


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

using namespace std;


int main()
{
  int N;
  bitset< 100 * 101 > dp;
  dp[0] = 1;

  cin >> N;
  for(int i = 0; i < N; i++) {
    int K;
    cin >> K;
    dp |= dp << K;
  }

  int ret = 0;
  for(int i = 0; i < 100 * 101; i++) {
    if(i % 10 != 0 && dp[i]) ret = max(ret, i);
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,c=0,p=0,s=0,k;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  sort(a,a+n);
  for(int i=n-1;i>=2;i--)
  {
    for(int j=0;j<i;j++)
    {
      int flag=0;
      for(k=j+1;k<i;k++)
      {
        if(a[i]<a[k]+a[j])
        {
          flag=1;
          c=k;
          break;
        }
      }
      if(flag==1)
      {
        p=i-c;
        s+=p;
      }
    }
  }
  cout<<s; 
}

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

int main() {

    while (1) {
        string s;
        cin >> s;
        if (s == "-")
            break;

        int n, h;
        cin >> n;
        rep(i, n) {
            cin >> h;

            string t = "";
            for (int i = h; i < s.size(); ++i)
                t.push_back(s[i]);

            for (int i = 0; i < h; ++i)
                t.push_back(s[i]);

            s = t;
        }
        cout << s << endl;
    }

    return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int N;
vector<int> C, nsub;
vv<int> tree, parColorDescendant, rootDescendant, colorVCh;
vector<ll> ans;

void eulerTour(int v, int p) {
    nsub[v] = 1;
    if (!colorVCh[C[v]].empty()) {
        parColorDescendant[colorVCh[C[v]].back()].push_back(v);
    }
    else {
        rootDescendant[C[v]].push_back(v);
    }
    for (int u : tree[v]) {
        if (u == p) continue;
        colorVCh[C[v]].push_back(u);
        eulerTour(u, v);
        colorVCh[C[v]].pop_back();
        nsub[v] += nsub[u];
    }
}

void dfs_ans(int v, int p) {
    for (int u : tree[v]) {
        if (u == p) continue;
        ll n = nsub[u];
        for (int d : parColorDescendant[u]) n -= nsub[d];
        ans[C[v]] -= n * (n + 1) / 2;
        dfs_ans(u, v);
    }
}

int main() {
    cin >> N;
    C.resize(N);
    rep(i, N) {
        cin >> C[i];
        C[i]--;
    }
    tree.resize(N);
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    nsub.resize(N);
    parColorDescendant.resize(N);
    rootDescendant.resize(N);
    colorVCh.resize(N);
    eulerTour(0, -1);

    ans.resize(N, (ll)N * (N + 1) / 2);
    rep(c, N) {
        ll n = N;
        for (int d : rootDescendant[c]) n -= nsub[d];
        ans[c] -= n * (n + 1) / 2;
    }
    dfs_ans(0, -1);

    for (ll n : ans) write(n);
}

Measured memory_bytes: 57200
/*
Problem : atcoder abc123 D
Algorithm :
Status :
*/
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const int MAXN = 1005;

int x,y,z,K;
ll a[MAXN],b[MAXN],c[MAXN];
vector<ll> ans;

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d%d%d%d",&x,&y,&z,&K);
	for(int i = 1;i <= x;i++)
	    scanf("%lld",&a[i]);
	for(int i = 1;i <= y;i++)
	    scanf("%lld",&b[i]);
	for(int i = 1;i <= z;i++)
	    scanf("%lld",&c[i]);
	sort(a + 1,a + 1 + x,greater<ll>());
	sort(b + 1,b + 1 + y,greater<ll>());
	sort(c + 1,c + 1 + z,greater<ll>());
	for(int i = 1;i <= x;i++){
		for(int j = 1;j <= y;j++){
			for(int k = 1;k <= z;k++){
				if(i * j * k > K)
				    break;
				ans.push_back(a[i] + b[j] + c[k]);
			}
		}
	}
	sort(ans.begin(),ans.end(),greater<ll>());
	for(int i = 0;i < K;i++)
	    printf("%lld\n",ans[i]);
	return 0;
}

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

int main(void){
	string str;
	int q;
	cin >> str;
	cin >> q;
	string cmd;
	int t1,t2;
	string t3;
	for(int i = 0; i < q; i++){
		cin >> cmd >> t1 >> t2;
		if(cmd == "replace"){
			cin >> t3;
			str.replace(t1,t2-t1+1,t3);
		}else if(cmd == "reverse"){
			reverse(str.begin()+t1, str.begin()+t2+1);
		}else if(cmd == "print"){
			cout << str.substr(t1,t2-t1+1) << endl;
		}
	}
}


Measured memory_bytes: 3152
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
using namespace std;

struct Node{
	vector<int> next;
	long long point=0;
};

void add_point(vector<Node> &node, int index, int parent){
	if(node[index].next.size()==1&&index!=0){
		return;
	}else{
		for(int i=0; i<int(node[index].next.size()); i++){
			if(node[index].next[i]!=parent){
				int child_index=node[index].next[i];
				node[child_index].point+=node[index].point;
				add_point(node, child_index, index);
			}
		}
	}

}

int main(int argc, char* argv[]){

	int N,Q;
	scanf("%d %d", &N, &Q);
	vector<Node> node(N);

	for(int i=0; i<N-1; i++){
		int a, b;
		scanf("%d %d", &a, &b);
			node[a-1].next.push_back(b-1);
			node[b-1].next.push_back(a-1);
	}
	for(int i=0; i<Q; i++){
		int p;
		long long x;
		scanf("%d %lld", &p, &x);
		node[p-1].point+=x;
	}

	add_point(node, 0, 0);

	for(int i=0; i<N; i++){
		printf("%lld\n", node[i].point);
	}

	return 0;
}







Measured memory_bytes: 24320
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 1000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

ll gcd(ll a,ll b) { return b ? gcd(b, a%b) : a; }

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

using graph = vector<vector<ll>>;
pair<pair<ll,ll>,ll> p[100010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,k,s;
    cin>>n>>k>>s;
    rep(i,k){
        cout<<s<<" ";
    }
    rep(i,n-k){
        if(i!=n-k-1){
            if(s==INF) cout<<1<<" ";
            else cout<<INF<<" ";
        }else{
           if(s==INF) cout<<1<<endl;
           else cout<<INF<<endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N 1000010
string s;
ll n,q,cs[N];
vector<ll> c;
void Solve(ll k){
    ll ans=0,l=0,r=0,cur=0,cnt=0;
    lol(i,n){
	for(;l<c.size()&&c[l]<i;l++){
	    cnt--;
	}
	for(;r<c.size()&&c[r]<i+k;r++){
	    cur+=max((ll)0,cs[c[r]+1]-cs[i]);
	    cnt++;
	}
	if(s[i]=='M')cur-=cnt;
	if(s[i]=='D')ans+=cur;
    }
    cout<<ans<<endl;
}
int main(){
    cin>>n>>s>>q;
    cs[0]=0;
    lol(i,n)cs[i+1]=cs[i]+(s[i]=='M');
    lol(i,n)if(s[i]=='C')c.push_back(i);
    
    lol(i,q){
	ll k;cin>>k;
	Solve(k);
    }
    return 0;
}


Measured memory_bytes: 19320
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N;
      cin >> N;
      if (N % 1110 == N % 10 || (N % 1000) % 111 == 0){
        cout << "Yes" << endl;
      }
      else {
        cout << "No" << endl;
      }
    }

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    boolean good = true;
    
    for (int i=0;i<S.length()-1;i++){
     if (S.charAt(i) == S.charAt(i+1)){
       good = false;
     }
    }
    if (good){
      System.out.println("Good");
    }else{
      System.out.println("Bad");
    }
  }
}

Measured memory_bytes: 23380
function Main(input) {
	tmp = input.split(" ");
	var r = parseInt(tmp[0]);
	var d = parseInt(tmp[1]);
	var x = parseInt(tmp[2]);
	for (var i = 0 ; i < 10 ; i++){
		var nx = (r*x) - d;
		console.log(nx);
		x = nx;
	}
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21320
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Part(vec, b, e) vec.begin() + b, vec.begin() + e
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(S, s) S.find(s) != string::npos

int main() {
	int n;
	cin >> n;
	vector<tuple<int, int, char, ll, string>> A(n);
	Rep(i, n) {
		int v, w;
		char t;
		ll d;
		string s;
		cin >> v >> w >> t >> d >> s;
		A[i] = make_tuple(v, w, t, d, s);
	}
	Sort(A);
	Rep(i, n) {
		cout << get<0>(A[i]) << " " << get<1>(A[i]) << " " << get<2>(A[i]) << " " << get<3>(A[i]) << " " << get<4>(A[i]) << endl;
	}
	return 0;
}


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

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    int flag = 1;
    if (s.size() + 1 == t.size()) {
        for (int i = 0; i < s.size(); i++) {
            if (s[i] != t[i]) {
                flag = 0;
            }
        }
    }

    flag == 1 ? cout << "Yes" : cout << "No";

    return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
 
using namespace std;
 
#define EPS 1e-8
typedef complex<double> Point;
 
int main(){
    int N;
    while(cin >> N,N){
	Point p[N];
	for(int i = 0 ; i < N ; i++){
	    cin >> p[i].real() >> p[i].imag();
	}
	int res = 1;
	for(int i = 0 ; i < N-1 ; i++){
	    for(int j = i+1 ; j < N ; j++){
		Point np = p[j]-p[i];
		double d = abs(np);
		if(d + EPS > 2.0){ continue; }
		np /= d;
		np *= Point(0,1);
		Point cp = (p[i]+p[j])/2.0;
		Point v = sqrt(1.0-d*d/4.0)*np;
		int cnt = 2;
		Point center = cp + v;
		for(int k = 0 ; k < N ; k++){
		    if(i == k || j == k) continue;
		    Point diff = center-p[k];
		    if(norm(diff) < 1.0 + EPS){
			cnt++;
		    }
		}
		res = max(res,cnt);
	    }
	}
	cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1260
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


int main() {
	ll s[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	ll k;
	cin >> k;
	k--;
	cout << s[k] << endl;
}


Measured memory_bytes: 256