akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int m = sc.nextInt();
        sc.nextLine();
        long res = 0L;
        long sum = 0L;
        for (int i = 0; i < m; i++) {
            int di = sc.nextInt();
            long ci = sc.nextLong();
            res += ci*((long)di);
            sum += ci;
        }
        System.out.println((res-1)/9L + sum -1);
    }
}


Measured memory_bytes: 92128
import sys

c = [list(map(int, input().split(" "))) for _ in range(0, 3)]

for a in range(0, 1+c[0][0]):
	b = [c[0][i] - a for i in range(0, 3)]
	a = [c[i][0] - b[0] for i in range(0, 3)]

	ok = True
	for i in range(0, 3):
		for j in range(0, 3):
			if c[i][j] != a[i] + b[j]:
				ok = False

	if ok:
		print("Yes")
		sys.exit(0)

print("No")


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

int main(){
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   int a,b,c,k;cin>>a>>b>>c>>k;
   while(k--){
      if(b>a){
         c*=2;
      }
      else{
         b*=2;
      }
   }
   if(b>a && c>b){
      cout<<"Yes"<<endl;
   }
   else{
      cout<<"No"<<endl;
   }
   return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<char> a(26);
  a = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  char alp;
  cin >> alp;
  for(int i = 0; i < 26; i++){
    if(a.at(i) == alp) cout << a.at(i+1) << endl;
  }
}

Measured memory_bytes: 3576
/*
                                                                                                                                               
8b        d8                           888888888888                                             88b           d88                  ad88888ba   
 Y8,    ,8P                                 88                                        ,d        888b         d888                 d8"     "8b  
  Y8,  ,8P                                  88                                        88        88`8b       d8'88                 ""      a8P  
   "8aa8"  ,adPPYba,   88       88          88  8b,dPPYba,  88       88  ,adPPYba,  MM88MMM     88 `8b     d8' 88   ,adPPYba,          ,a8P"   
    `88'  a8"     "8a  88       88          88  88P'   "Y8  88       88  I8[    ""    88        88  `8b   d8'  88  a8P_____88         d8"      
     88   8b       d8  88       88          88  88          88       88   `"Y8ba,     88        88   `8b d8'   88  8PP"""""""         ""       
     88   "8a,   ,a8"  "8a,   ,a88          88  88          "8a,   ,a88  aa    ]8I    88,       88    `888'    88  "8b,   ,aa         aa       
     88    `"YbbdP"'    `"YbbdP'Y8          88  88           `"YbbdP'Y8  `"YbbdP"'    "Y888     88     `8'     88   `"Ybbd8"'         88       
                                                                                                                                               
*/
#include <bits/stdc++.h>
using namespace std;

const int MOD = 1e9 + 7;
int n, adj[25][25];
int dp[(1 << 22)];

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

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

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

	dp[0] = 1;
	for (int i = 0; i < (1 << n); i++) {
		int c = 0;
		for (int j = 0; j < n; j++) {
			if (i & (1 << j)) c++;
		}

		for (int j = 0; j < n; j++) {
			if ((~i & (1 << j)) && adj[c][j]) {
				dp[i | (1 << j)] += dp[i];
				if (dp[i | (1 << j)] > MOD) dp[i | (1 << j)] -= MOD;
			}
		}
	}

	cout << dp[(1 << n) - 1] << '\n';

	return 0;
} 

Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
int main() {
  lli A,B=0,D=0,F=INF;
  cin >> A;
  string S;
  cin >> S;
  rep(i,A)if(S[i]=='.')B++;
  F=B;
  for(int i=0;i<A;i++){
    if(S[i]=='#')D++;
    if(S[i]=='.')B--;
    F=min(B+D,F);
  }
Out(F);
}

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

#define ntest 0
#define l first
#define r second

using namespace std;
const int mod = 998244353;
int n, k;
pair<int,int> seg[11];
long long dp[200005], f[200005];
void solve() {
    cin >> n >> k;
    for (int i = 1; i <= k; ++i) cin >> seg[i].l >> seg[i].r;
    dp[1] = 1;
    f[1] = 1;
    for (int i = 2; i <= n; ++i) {
        for (int j = 1; j <= k; ++j) {
            int s = max(0, i - seg[j].l);
            int e = max(1, i - seg[j].r);
            dp[i] = (dp[i] + (f[s] - f[e-1] + mod)%mod) % mod;
        }
        f[i] = (f[i-1] + dp[i]) % mod;
    }
    cout << dp[n];
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    if(ntest){
        int t;
        cin >> t;
        while(t--) solve();
    } else {
        solve();
    }

}




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

const int N=1e5+10;

int n,q,x,y;
int a[N];
int b[N];
long long sum;

int main(){
	scanf("%d", &n);
	
	for(int i=0;i<n;i++) scanf("%d",&a[i]), b[a[i]]++, sum+=a[i];
	
	scanf("%d", &q);
	while(q--){
		scanf("%d%d",&x,&y);
		sum+=(y-x)*b[x];
		b[y]+=b[x],b[x]=0;
		printf("%ld\n",sum);
	}
	return 0;
}


Measured memory_bytes: 4488
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

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

template <class InputIterator, class T>
bool contains_itr(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class T>
bool contains_set(set<T> st, const T &value)
{
    if (st.find(value) == st.end())
    {
        return false;
    }
    else
    {
        return true;
    }
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// endは排他的(exclusive)なので注意
vector<ll> range(ll begin, ll end)
{
    vector<ll> result;
    for (ll i = begin; i < end; ++i)
    {
        result.push_back(i);
    }
    return result;
}

// =========ここまでテンプレ============

int main()
{
    ll n;
    cin >> n;
    ll m = n % 10;

    if (m == 2 || m == 4 || m == 5 || m == 7 || m == 9)
    {
        cout << "hon" << endl;
    }
    else if (m == 3)
    {
        cout << "bon" << endl;
    }
    else
    {
        cout << "pon" << endl;
    }
}


Measured memory_bytes: 3128
/*  -*- coding: utf-8 -*-
 *
 * e.cc: E - Sequence Decomposing
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef deque<int> di;

/* global variables */

di bs;

/* subroutines */

/* main */

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

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

    int k = lower_bound(bs.begin(), bs.end(), ai) - bs.begin() - 1;
    if (k < 0)
      bs.push_front(ai);
    else
      bs[k] = ai;
  }

  printf("%lu\n", bs.size());
  return 0;
}


Measured memory_bytes: 640
import sys
n=int(input())
a=[]
f=[]
has2=False
for i in range(n):
  ai=int(input())-1
  if ai==1:
    has2=True
  a.append(ai)
  f.append(False)

if has2==False:
  print("-1")
  sys.exit()

now=0
cnt=0
while True:
  
  if f[now]==True:
    print(-1)
    sys.exit()
  if now==1:
    print(cnt)
    sys.exit()
  f[now]=True
  now=a[now]
  cnt+=1

  


Measured memory_bytes: 61656
import bisect

N = int(input())
L = [int(_) for _ in input().split()]
L.sort()

ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        r = L[i] + L[j]
        # 同じ長さでも違う棒はOK
        ri = bisect.bisect_left(L, r, lo=j)
        ans += ri - j - 1

print(ans)

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

int main(){
    long long a, b, x;
    cin >> a >> b >> x;

    long long ans = 0;
    if(a == 0){
        ans = b/x + 1;
    }else if(b == 0){
        ans = 0;
    }else{
        ans = b/x - (a-1)/x;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string red,green,bottom,right;
  char set;
  while(cin>>red>>green>>bottom,red!="-"){
    set=green[0];
    green.erase(green.begin());
    right="";
    while(green.size()){
      if(set==bottom[0]){
	set=red[0];
	red.erase(red.begin());
	bottom.erase(bottom.begin());
      }else{
	right+=set;
	set=green[0];
	green.erase(green.begin());
      }
    }
    if(red.size())set=red[red.size()-1];
    right+=set;
    cout<<right<<endl;
  }
}

Measured memory_bytes: 0
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


void solve() {
    long double L; cin >> L;
    cout << setprecision(15) << (L/(long double)3) * (L/(long double)3) * (L/(long double)3) << endl;
}


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

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#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++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    string K; int D; cin >> K >> D;
    ll dp[100100][2][110];
    int N = K.size();
    dp[0][0][0] = 1LL;
    rep(dgt, N) {
        int a = K[dgt] - '0';
        rep(isless, 2) {
            rep(d, D) {
                rep(nxt, 10) {
                    int e = (d + nxt) % D;
                    if(a < nxt) {
                        if(isless) {
                            dp[dgt + 1][isless][e] += dp[dgt][isless][d];
                            dp[dgt + 1][isless][e] %= mod;
                        }
                    } else if(a == nxt){
                        dp[dgt + 1][isless][e] += dp[dgt][isless][d];
                        dp[dgt + 1][isless][e] %= mod;
                    } else {
                        dp[dgt + 1][1][e] += dp[dgt][isless][d];
                        dp[dgt + 1][1][e] %= mod;
                    }
                    
                }
            }
        }
    }
    cout << (dp[N][0][0] + dp[N][1][0] - 1 + mod) % mod << endl; // 000…000をのぞいておくための−１

	return 0;
}

Measured memory_bytes: 19200
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<int> w(n);
	int sum = 0;
	for(int i = 0; i < n; i++){
		cin >> w.at(i);	
		sum += w.at(i);
	}
	int dif_min = INT_MAX;
	for(int t = 0; t < n; t++){
		int left = 0;
		for(int i = 0; i < t; i++)
			left += w.at(i);
		int right = sum-left;
		int dif = max(left,right)-min(left,right);
		if(dif < dif_min)
			dif_min = dif;
	}
	cout << dif_min << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <stack>
#include <unordered_set>
using namespace std;

char rgb[] = "RGB";

int main(){
    int n;
    cin >> n;
    char arr[n];
    int r[n], g[n], b[n];
    cin >> arr[0];
    r[0] = (*arr == 'R');
    g[0] = (*arr == 'G');
    b[0] = (*arr == 'B');
    for(int i = 1; i < n; i++){
        cin >> arr[i];
        r[i] = (arr[i] == 'R') + r[i-1];
        g[i] = (arr[i] == 'G') + g[i-1];
        b[i] = (arr[i] == 'B') + b[i-1];
    }
    long long ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(arr[i] == arr[j]) continue;
            char c;
            for(int a = 0; a < 3; a++){
                if(rgb[a] != arr[i] && rgb[a] != arr[j]){
                    c = rgb[a];
                    break;
                }
            }
            if(c == 'R'){
                ans += r[n-1] - r[j];
            } else if(c == 'G'){
                ans += g[n-1] - g[j];
            } else { // B
                ans += b[n-1] - b[j];
            }
            ans -= (j+(j-i) < n && arr[j+(j-i)] == c);
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3640
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<vin> vvin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
const int MOD=1e9+7;

int main(){

  ll n=1,m=1;
  while(n!=0){
  cin>>n>>m;ll ans=MOD;
  if(n==0&&m==0){break;}
  vll c(m),x(n);
  vvll dp(n+1,vll(256,MOD));
  rep(i,0,m){cin>>c[i];}
  rep(i,0,n){cin>>x[i];}
  dp[0][128]=0;
  rep(i,0,n){
    rep(j,0,256){
      rep(k,0,m){
        int yn=j+c[k];
        if(yn>=255){yn=255;}
        if(yn<=0){yn=0;}
        dp[i+1][yn]=min(dp[i+1][yn],dp[i][j]+(yn-x[i])*(yn-x[i]));
      }
    }
  }
  rep(i,0,256){
    ans=min(dp[n][i],ans);
  }
  cout<<ans<<endl;
  }
}



Measured memory_bytes: 43752
from itertools import combinations
from collections import Counter
import math


def main():
    x, k, d = map(int, input().split())
    t = abs(x) // d

    if t >= k:
        if x > 0:
            x -= d * k
        else:
            x += d * k
    else:
        k -= t
        k = k % 2
        if x > 0:
            x -= d * t
            x -= d * k
        else:
            x += d * t
            x += d * k
    print(abs(x))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    long double w, h, x, y;
    cin >> w >> h >> x >> y;
    long double ma_x, ma_y, mi_x, mi_y;
    long double ans;
    ans = h / 2 * w;
    cout << fixed << setprecision(10) << ans << " ";
    cout << (x == w / 2 && y == h / 2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll>v[100010];
ll danger[100010];
void dfs(ll node,ll par,ll val){
    //cout<<node<<' '<<val<<'\n';
    danger[node]=val;
    for (ll i=0;i<v[node].size();i++){
        if (par!=v[node][i])dfs(v[node][i],node,val+1);
    }
    return;
}
ll dist[100010];
void dfs1(ll node,ll par,ll val){
    dist[node]=val;
    for (ll i=0;i<v[node].size();i++){
        if (val+1<danger[v[node][i]]&&v[node][i]!=par)dfs1(v[node][i],node,val+1);
    }
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    ll n,i,x,y,s,e,leaf=-1,maxdist=-1,takadist=0,ans=0;
    cin>>n>>e>>s;
    for (i=0;i<n-1;i++){
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    memset(dist,-1,sizeof(dist));
    dfs(s,s,0);
    //cout<<'\n';
    dfs1(e,e,0);
    for (i=1;i<=n;i++){
        //cout<<dist[i]<<' '<<danger[i]<<'\n';
        if (dist[i]!=-1){
            if (maxdist<danger[i]){
                maxdist=danger[i];
                leaf=i;
                takadist=dist[i];
            }
        }
    }
    //cout<<maxdist<<' '<<takadist<<'\n';
    ans=0;
    x=0;
    y=maxdist-takadist;
    while (x!=y){
        if (x%2==0)y--;
        else y++;
        if (x==y)break;
        x++;
        ans++;
    }
    cout<<ans+takadist<<'\n';
}

Measured memory_bytes: 12544
import copy
k = int(input())

count = 0
x = 0

runrun = [1, 2, 3, 4, 5, 6, 7, 8, 9]
def dfs(current, next, max_len):
    if next < 0 or next > 9:
        return
    current.append(str(next))
    if len(current) == max_len:
        tmp = ''.join(current)
        runrun.append(int(tmp))
        return
    dfs(copy.deepcopy(current), next - 1, max_len)
    dfs(copy.deepcopy(current), next, max_len)
    dfs(copy.deepcopy(current), next + 1, max_len)

for i in range(1, 10):
    dfs([], i, 2)
for i in range(1, 10):
    dfs([], i, 3)
for i in range(1, 10):
    dfs([], i, 4)
for i in range(1, 10):
    dfs([], i, 5)
for i in range(1, 10):
    dfs([], i, 6)
for i in range(1, 10):
    dfs([], i, 7)
for i in range(1, 10):
    dfs([], i, 8)
for i in range(1, 10):
    dfs([], i, 9)
for i in range(1, 5):
    dfs([], i, 10)

print(runrun[k - 1])

Measured memory_bytes: 8900
N = int(input())
a = [int(i) for i in input().split()]
b = [0] * (N + 1)
ans = 0
for i in range(N):
    if a[i] <= N:
        b[a[i]] += 1
    else:
        ans += 1

for i in range(N + 1):
    if b[i] < i:
        ans += b[i]
    else:
        ans+= b[i] - i
print(ans)

Measured memory_bytes: 14268
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    int n , l ; cin >> n >> l;
    int mn = 100000 , tot = 0 ,sig;
    int x;
    for(int i = 0 ;i < n ;i++){
        x = l + i;
        tot += l+i;
        mn = min(mn , abs(x));
        if(mn == abs(x)){
            if(x < 0)
                sig = 1;
            else
                sig = 0;
        }
    }
    if(!sig)
    cout << tot-mn << endl;
    else
    cout << tot+mn << endl;
    return 0;
}

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


using namespace std;


using ll = long long;


int main(void) {
    ll N, M, K;
    cin >> N >> M >> K;

    vector<ll> A(N), B(M);

    for (ll i = 0; i < N; i++)
        cin >> A[i];
    for (ll i = 0; i < M; i++)
        cin >> B[i];

    vector<ll> cum_A(N + 1, 0), cum_B(M + 1, 0);
    for (ll i = 1; i < N + 1; i++) {
        cum_A[i] = cum_A[i - 1] + A[i - 1];
    }
    for (ll i = 1; i < M + 1; i++) {
        cum_B[i] = cum_B[i - 1] + B[i - 1];
    }

    ll ans = 0;
    for (ll i = 0; i <= N; i++) {
        ll time_b = K - cum_A[i];
        // cout << endl << cum_A[i] << ", " << time_b << endl;
        if (time_b < 0)
            continue;
        auto b = upper_bound(cum_B.begin(), cum_B.end(), time_b) - 1;
        // cout << *b << endl;
        ll book_read = i + (b - cum_B.begin());
        ans = max(ans, book_read);
    }
    cout << ans << endl;
}


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

int main()
{
    int n,q;
    std::cin>>n>>q;
    std::vector<std::vector<int>> hen(n); //vertex
    std::vector<int> cost(n);
    for(int i=0;i<n-1;i++){
        int a,b;
        std::cin>>a>>b;
        a--;b--;
        hen[a].push_back(b);
        hen[b].push_back(a);
    }
    for(int i=0;i<q;i++){
        int p,x;
        std::cin>>p>>x;
        p--;
        cost[p] += x;
    }
    //BFS
    std::queue<int> que;
    std::vector<bool> seen(n);
    seen[0] = true;
    que.push(0);
    while(que.size()){
        int vert = que.front();
        que.pop();
        for(auto i : hen[vert]){
            if(seen[i])continue;
            cost[i] += cost[vert];
            que.push(i);
            seen[i] = true;
        }
    }
    for(auto i : cost){
        std::cout<<i<<" ";
    }

}

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

string s;
int transition[10][10101], n, p;
ll ans;
int dp[2][10101];
ll modpow(ll x, ll y)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

int32_t main()
{
    cin >> n >> p >> s;
    int inv = modpow(10, p-2);
    if (p < 10)
    {
        for (int j = 0; j<10; j++)
            for (int i = 0; i<p; i++)
                transition[j][i] = ((i*10)+j)%p;
        int r = 0;
        for (int i = 0; i<n; i++)
        {
            int u = s[i]-'0';
            r = 1-r;
            memset(dp[r],0,sizeof(dp[r]));
            for (int j = 0; j<p; j++)
            {
                int k = transition[u][j];
                dp[r][k] += dp[1-r][j];
            }
            dp[r][transition[u][0]]++;
            ans += dp[r][0];
        }
        cout << ans << '\n';
    }
    else
    {
        for (int j = 0; j<10; j++)
            for (int i = 0; i<p; i++)
                transition[j][i] = (((i-j+p)%p)*(inv))%p;
        int r = 0;
        for (int i = 0; i<n; i++)
        {
            register int u = s[i]-'0';
            r = 1-r;
            for (int j = 0; j<p; j++)
            {
                int k = transition[u][j];
                dp[r][j] = dp[1-r][k];
            }
            dp[r][u]++;
            ans += dp[r][0];
        }
        cout << ans << '\n';
    }
}


Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    ll H, W, A, B;
    cin >> H >> W >> A >> B;
    vector<ll> inv(200005); inv[1] = 1;
    for (int i = 2; i < 200005; i++) {
        inv[i] = MOD - (MOD / i) * inv[MOD % i] % MOD;
    }   
    vector<ll> invfact(200005);
    invfact[0] = 1; invfact[1] = 1;
    for (int i = 2; i < 200005; i++) {
        invfact[i] = invfact[i-1] * inv[i] % MOD;
    }   
    vector<ll> fact(200005);
    fact[0] = 1; fact[1] = 1;
    for (int i = 2; i < 200005; i++) {
        fact[i] = fact[i-1] * i % MOD;
    }   

    ll ans = 1;
    for (int i = 0; i < H-1; i++) {
        ans = ans * (H+W-2-i) % MOD;
    }
    ans = ans * invfact[H-1] % MOD;

    vector<ll> p(B+1);
    p[0] = 1; p[1] = 1;
    for (int i = 0; i < A-1; i++) {
        p[1] = p[1] * (W+A-2-i) % MOD;
    }
    p[1] = p[1] * invfact[A-1] % MOD;

    for (int i = 2; i < B+1; i++) {
        p[i] = p[i-1] * (H-A-2+i) % MOD;
        p[i] = p[i] * (W+1-i) % MOD;
        p[i] = p[i] * inv[i-1] % MOD;
        p[i] = p[i] * inv[W+A-i] % MOD;
    }

    for (int i = 1; i < B+1; i++) {
        ans = (MOD + ans - p[i]) % MOD;
    }

    printf("%lld\n", ans);

}

Measured memory_bytes: 8720
typedef long long ll;
typedef long double ld;
#define mod 1000000007
#define INF 1000000000
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	int ones = n % 10;
	if (ones == 3) {
		cout << "bon\n";
	} else if (ones == 0 || ones == 1 || ones == 6 || ones == 8) {
		cout << "pon\n";
	} else {
		cout << "hon\n";
	}
	
	return 0;
}


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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int,int> dct;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define pi 3.14159265

bool compare(pair<pii,vector<int>> a, pair<pii,vector<int>> b){
    if(a.first.first*b.first.second==a.first.second*b.first.first)
        return a.first.second>b.first.second;
    return a.first.first*b.first.second<a.first.second*b.first.first;
}

const int mod = 1e9 + 9;
const ll inf = ll(1e18);

ll modexp(ll x,ll n){
    if(n==0)return 1;
    if(n%2==0)return modexp((x*x)%mod,n/2);
    return (x*modexp((x*x)%mod,n/2))%mod;
}

ll zeros(ll n){
    ll count = 0;
    for (ll i = 10; n / i >= 1; i *= 5)
        count += n / i;
    return count;
}
int main(){
    fastio;
    ll n;
    cin>>n;
    if(n<10 or n%2==1)cout<<0<<endl;
    else{
        cout<<zeros(n)<<endl;
    }
}

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

using namespace std;

#define pb            push_back
#define mp            make_pair
#define po            pop_back
#define fi            first
#define se            second
#define mxn           100005
#define ll            long long int
#define ldb           long double
#define fr(i,a,b,k)   for(int i=a ; i<b ; i+=k)
#define frr(i,a,b,k)  for(int i=a ; i>b ; i-=k)
#define all(v)        v.begin(),v.end()
#define endl          "\n"
#define deg(x)        cout<<endl<<#x<<" = "<<(x)<<endl;
#define casep(x)      cout<<"Case #"<<(x)<<": ";
#define fast          ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

typedef pair<ll,ll> pp;
typedef vector<int> vi;
typedef vector<pp> vpp;
typedef vector<vi> vvi;

const int inf = 1e9+7;
const int minf = (-1)*(1e9+7);

ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
ll gcd(ll a,ll b){ return __gcd(a,b);}
ll lcm(ll a,ll b){return a*b/__gcd(a,b);}


void solve(int test){

    ll k;
    cin >> k;

    ll temp = 0;
    fr(i,0,1000007,1){
        temp = (temp*10+7)%k;
        if(temp == 0){
            cout << i+1;
            return ;
        }
    }

    cout << -1;

}

int main(){

    fast;
    int t=1;
    // cin >> t;
    for(int i=1 ; i<=t ; i++){
        solve(i);
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    ll n;
    cin >> n;
    ll res = n*(n-1)/2;
    if (n>2)cout << res << endl;
    else if (n == 2) cout << 1 << endl;
    else cout << 0 << endl;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

struct Edge {
    int to, cost, id;
    Edge(int _to, int _cost, int _id) : to(_to), cost(_cost), id(_id) {}
};

vector<vector<Edge>> G;
int N;

PII dfs(int v, int prev, int cost)
{
    if (G[v].size() == 1 && G[v][0].to == prev) return PII(cost, v);

    PII res(0, -1);
    for (Edge e : G[v]) {
        if (e.to != prev) {
            res = max(res, dfs(e.to, v, cost + e.cost));
        }
    }

    return res;
}

int diameter()
{
    int s = 0;
    while (s < N && G[s].size() == 0) s++;
    if (s == N) return 0;

    PII tmp = dfs(s, -1, 0);

    s = tmp.second;
    tmp = dfs(s, -1, 0);
    return tmp.first;
}


int main()
{
    while (cin >> N, N) {
        G.resize(N);

        vector<int> list;
        rep(i, N) G[i].clear();
        
        vector<int> P(N-1), D(N-1);
        rep(i, N-1) cin >> P[i];
        rep(i, N-1) cin >> D[i];

        rep(i, N-1) {
            G[i+1].emplace_back(P[i]-1, D[i], i);
            G[P[i]-1].emplace_back(i+1, D[i], i);
            list.push_back(D[i]);
        }

        int ans = 0;
        set<int> to_leaf;
        for (int i=0; i<N; i++) {
            if (G[i].size() == 1) to_leaf.insert(G[i][0].id);
        }

        rep(i, N-1) {
            if (to_leaf.count(i)) ans += list[i];
            else ans += 3 * list[i];
        }

        rep(i, N) {
            for (int j=0; j<G[i].size(); j++) {
                if (to_leaf.count(G[i][j].id)) {
                    G[i].erase(G[i].begin() + j--);
                }
            }
        }

        cout << ans - diameter() << endl;
    }
}

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

struct flower{
    int height;
    int beauty;
};

ll maxBeauty(vector<flower>& v,int n){
    vector<ll> dp(n+1);
    map<ll,ll> meaningful;
    dp[1] = v[1].beauty;
    meaningful[v[1].height] = dp[1];
    ll ans = dp[1];
    for(int i=2;i<=n;i++){
        dp[i] = v[i].beauty;
        auto it = meaningful.upper_bound(v[i].height);
        if(it != meaningful.begin()){
            it--;
            dp[i] = dp[i] + it->second;
        }
        meaningful[v[i].height] = dp[i];
        it = meaningful.upper_bound(v[i].height);
        while(it!=meaningful.end() && it->second<=dp[i]){
            auto temp = it;
            temp++;
            meaningful.erase(it);
            it = temp;  
        }
        ans = max(ans,dp[i]);
    }
    return ans;
}

int main(){
    int n;
    cin>>n;
    vector<flower> v(n+1);
    for(int i=1;i<=n;i++){
        cin>>v[i].height;
    }
    for(int i=1;i<=n;i++){
        cin>>v[i].beauty;
    }
    cout<<maxBeauty(v,n);
    return 0;
}


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

int main(){
	int bingo[3][3];
	cin >> bingo[0][0] >> bingo[0][1] >> bingo[0][2];
	cin >> bingo[1][0] >> bingo[1][1] >> bingo[1][2];
	cin >> bingo[2][0] >> bingo[2][1] >> bingo[2][2];
	int n;
	cin >> n;
	for (int i=0;i<n;i++){
		int b;
		cin >> b;
		for (int j=0;j<3;j++){
			for (int k=0;k<3;k++){
				if (bingo[j][k] == b){
					bingo[j][k] = 0;
					break;
				}
			}
		}
	}
	if (!(bingo[0][0]+bingo[0][1]+bingo[0][2])) {cout << "Yes";return 0;}
	if (!(bingo[1][0]+bingo[1][1]+bingo[1][2])) {cout << "Yes";return 0;}
	if (!(bingo[2][0]+bingo[2][1]+bingo[2][2])) {cout << "Yes";return 0;}
	
	if (!(bingo[0][0]+bingo[1][0]+bingo[2][0])) {cout << "Yes";return 0;}
	if (!(bingo[0][1]+bingo[1][1]+bingo[2][1])) {cout << "Yes";return 0;}
	if (!(bingo[0][2]+bingo[1][2]+bingo[2][2])) {cout << "Yes";return 0;}
	
	if (!(bingo[0][0]+bingo[1][1]+bingo[2][2])) {cout << "Yes";return 0;}
	if (!(bingo[0][2]+bingo[1][1]+bingo[2][0])) {cout << "Yes";return 0;}
	
	cout << "No";
}


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

ll solve() {
    ll N, A, B, p;
    cin >> N >> A >> B;
    vector<ll> n(3);
    for ( int i = 0; i < N; i++ ) {
        cin >> p;
        if ( p <= A ) n[0]++;
        else if ( p <= B ) n[1]++;
        else n[2]++;
    }
    ll ans = min({n[0],n[1],n[2]});
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AnandOza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AAC solver = new AAC();
        solver.solve(1, in, out);
        out.close();
    }

    static class AAC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            char m = in.next().charAt(1);
            out.println(m == 'R' ? "ABC" : "ARC");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 25608
#include<iostream>
#include<string>
using namespace std;
int main(void){
  string str;
  cin >> str;
  long long count = 0;
  long long sum=0;
  long long length = str.length();
  for(long long i=0;i<length-1;i++){
    if(str[i] == 'A'){
      count++;
    }else if(str[i] == 'B'){
      if(count == 0){
        //
      }else{
        if(str[i+1] =='C'){
          sum+=count;
          i++;
        }else if(str[i] == 'A'){
          count=1;
          i++;
        }else{
          count=0;
        }
      }
    }else{
      count=0;
    }
  }
  cout << sum;
  return 0;
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(int i=a; i<int(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> istream& operator>>(istream& is, vector<T>& v);
template<class T> ostream& operator<<(ostream& os, vector<T> const& v);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream&, const tuple<T...>&){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream& os, const tuple<T...>& t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream& operator<<(ostream& os, const tuple<T...>& t){ _ot<0>(os, t); return os; }
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _it(istream&, tuple<T...>&){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _it(istream& is, tuple<T...>& t){ is >> get<n>(t); _it<n+1>(is, t); }
template<class...T> istream& operator>>(istream& is, tuple<T...>& t){ _it<0>(is, t); return is; }
template<class T> istream& operator>>(istream& is, vector<T>& v){ rep(i,v.size()) is >> v[i]; return is; }
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif


string ans[1<<20];
char s[32];
char t[32];

int main(){
#ifdef LOCAL
    freopen("in","r",stdin);
#endif
    while(~scanf("%s",s) && s[0]!='#'){
        int sz = 0;
        int n = strlen(s);
        rep(i,n) t[i] = s[i];
        t[n] = 0;
        int change[32];
        rep(mask,1<<n){
            bool ok = true;
            rep(i,n){
                ok &= s[i]!='z' || ~mask>>i&1;
            }
            if(!ok) continue;
            rep(i,n){
                t[i] = s[i] + (mask>>i & 1);
            }
            rep(i,32){
                change[i] = 30;
            }
            rep(i,n){
                change[t[n-i-1]-'a'] = n-i-1;
            }
            change[0] = 30;
            rep(i,32){
                t[change[i]]--;
            }
            if(strcmp(t,s)==0){
                rep(i,n){
                    t[i] = s[i] + (mask>>i&1);
                }
                ans[sz++] = t;
            }
        }
        sort(ans, ans + sz);
        printf("%d\n",sz);
        if(sz > 10){
            rep(i,5) printf("%s\n", ans[i].c_str());
            rep(i,5) printf("%s\n", ans[sz-5+i].c_str());
        } else {
            rep(i,sz){
                printf("%s\n",ans[i].c_str());
            }
        }
    }
}

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

int main(){
	long long n, k;
	cin >> n >> k;
	if(k -(n%k) <= n%k){
		cout << k - (n%k) << endl;
	}else{
		cout << n%k << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 1e5+205;
ll inp[N][3];
void solve(){
	int n; 
	cin>>n; 
	for(int i=1;i<n;i++){
		for(int j=0;j<3;j++)cin>>inp[i][j];
	}
	for(int i=1;i<=n;i++){
		ll cur = 0;
		for(int j=i;j<n;j++){
			if(cur<inp[j][1]){
				cur = inp[j][1];
			}
			else if(cur%inp[j][2]!=0){
				cur+=inp[j][2]-cur%inp[j][2];
			}
			cur+=inp[j][0];
		}
		cout<<cur<<endl;
	}
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

bool in(ll y, ll x, ll h, ll w){
	return 0 <= y && y < h && 0 <= x && x < w;
}

int main(){
	ll h,w; cin >> h >> w;
	char s[55][55];
	rep(i,h) rep(j,w) cin >> s[i][j];
	char ans[55][55];
	rep(i,h) rep(j,w) ans[i][j] = '0';
	rep(i,h){
		rep(j,w){
			if(s[i][j]=='#'){
				rep(k,8){
					ll ny = i + dy[k];
					ll nx = j + dx[k];
					if(in(ny,nx,h,w)){
						if(ans[ny][nx]!='#') ans[ny][nx]++;
					}
				}
				ans[i][j] = '#';
			}
		}
	}
	rep(i,h){
		rep(j,w) cout << ans[i][j];
		cout << endl;
	}
}


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

typedef long long ll;
int N,M;
ll D[1010];
bool negative[1010];
ll inf = 1e18;
struct edge {int from,to; ll cost;};

vector<edge> v;

void shortest_path(int s){
	for(int i=1;i<=N;i++) D[i] = inf;
	D[s] = 0;
	for(int j=0;j<N-1;j++){
		//bool update = false;
		for(int i=0;i<v.size();i++){
			edge e = v[i];
			if(D[e.from] != inf && D[e.to] > D[e.from] + e.cost){
				D[e.to] = D[e.from] + e.cost;
				//update = true;
			}
		}
		//if(!update) break;
	}
}

void find_negative_loop(){
	//memset(D,0,sizeof(D));
	for(int i=1;i<=N;i++) negative[i] = false;
	for(int i=1;i<=N;i++){
		for(int j=0;j<v.size();j++){
			edge e = v[j];
			if(D[e.to]!=inf && D[e.to] > D[e.from] + e.cost){
				D[e.to] = D[e.from] + e.cost;
				negative[e.to] = true;
			}
			if(negative[e.from]) negative[e.to] = true;
		}
	}
}

int main(){
	cin >> N >> M;
	for(int i=0;i<M;i++){
		int a,b,c;
		cin >> a >> b >> c;
		v.push_back((edge{a,b,-c}));
	}
	shortest_path(1);
	ll ans = -D[N];
	find_negative_loop();
	if(negative[N]) cout << "inf" << endl;
	else{
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

#define MAX 3000

int dp[MAX + 1][MAX + 1][2];

signed main(){
    int n;
    ll t;
    cin >> n >> t;
    int a[n],b[n];
    REP(i,n){
        cin >> a[i] >> b[i];
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < t; j++){
            for(int k = 0; k < 2; k++){
                dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k]);
                if(k == 0){
                    dp[i + 1][j][1] = max(dp[i + 1][j][1], dp[i][j][k] + b[i]);
                }
                if(j - a[i] < 0) continue;
                dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j - a[i]][k] + b[i]);
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < t; i++){
        for(int j = 0; j < 2; j++){
            ans = max(ans, dp[n][i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 70656
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
 
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！
 
def main():
    n,*a=map(int,open(0).read().split())
    dp=deepcopy(a)
    dp[:n//2]=[0]*(n//2)
    for i in reversed(range(n//2)):
        if sum(dp[j] for j in range(i,n,i+1))%2!=a[i]:
            dp[i]=1
    #print(dp)
    d=[k+1 for k,v in enumerate(dp)if v==1]
    print(len(d))
    print(*d)
if __name__ == '__main__':
    main()


Measured memory_bytes: 16148
var
	L,R,ans,tmp,M,i,j:Longint;
begin
	read(L,R);
	M:=2019;
	ans:=M;
	if L+2018<=R then begin
		writeln(0);
		exit;
	end;
	for i:=L to R do begin
		for j:=1 to 500 do begin
			if i+j>R then break;
			tmp:=i mod M*(i+j)mod M;
			if ans>tmp then ans:=tmp;
		end;
	end;
	writeln(ans);
end.


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
    int A, B, M;
    cin>>A>>B>>M;
    vector<int>a, b, c;
    vector<int>x, y;
    int tmp;
    for(int i=0;i<A;++i){
        cin>>tmp;
        a.push_back(tmp);
    }
    for(int i=0;i<B;++i){
        cin>>tmp;
        b.push_back(tmp);
    }
    int tmpx, tmpy, tmpc;
    for(int i=0;i<M;++i){
        cin>>tmpx>>tmpy>>tmpc;
        tmpx--;
        tmpy--;
        x.push_back(tmpx);
        y.push_back(tmpy);
        c.push_back(tmpc);
    }
    vector<int>ansarr;
    for(int i=0;i<M;++i){
        ansarr.push_back(a[x[i]]+b[y[i]]-c[i]);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(ansarr.begin(), ansarr.end());
    if(a[0]+b[0] < ansarr[0]){
        cout<<a[0]+b[0]<<endl;
    }
    else cout<<ansarr[0]<<endl;
}


Measured memory_bytes: 3064
/**So..a**/
#include<bits/stdc++.h>
//#include <chrono>
// Success after trying 5 hour 11 minute :(


using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define PB(x, v) x.push_back(v);
#define M_P(a, b) make_pair(a, b)
#define pll pair<ll, ll>
#define ll long long
#define mll map<ll, ll>
#define vl vector<ll>
#define fa(x, v) for(auto x: v)
#define fr(i, a, b) for(ll i= a;i <=b; i++)
#define TEST  int test; cin >> test; while(test--)
#define FTEST int TesT; cin >> TesT; for(int test = 1; test<=TesT; test++)

#define B_ begin()
#define E_ end()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define NL_ "\n"
#define F first
#define S second
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second

#define MOD (1000000007)
#define  ull unsigned long long

#define MAX 300000+10

int arr[MAX], tree[4*MAX];



void update(int node, int i, int j, int ind, int val)
{
    if(i==j and i==ind)
    {
        tree[node] = val;
        return ;
    }
    int mid = (i+j)/2;
    if(mid>= ind) update(2*node+1, i, mid, ind, val);
    else update(2*node+2, mid+1, j, ind, val);
    tree[node] = max(tree[2*node+1], tree[2*node+2]);
    return ;
}

ll result(int node, int s, int e, int i, int j)
{
    if(j < s or e < i)
    {
        return -1;
    }

    if(s>=i and j >=e)  return tree[node];
    int mid = (s+e)/2;
    int a = result(2*node+1,s, mid, i, j ), b = result(2*node+2, mid+1, e, i, j);
    return max(a, b);
}
int main()
{
    FAST;
    int n;
    cin >> n;
    int k ;
    cin >> k;
    for(int i= 1; i<=n; i++) cin >> arr[i];
    for(int i=1; i<=n; i++)
    {
        int mn = max(arr[i]-k, 0);
        int mx = min(arr[i]+k, 300000);
        int c = result(0, 0, 300000, mn, mx);
        update(0, 0, 300000, arr[i], c+1);
    }
    cout << result(0, 0, 300000, 0, 300000);
}



Measured memory_bytes: 8892