akhauriyash/Code-Regression huggingface dataset:
import sys
input=sys.stdin.readline
from collections import deque
H,W=map(int,input().split())
maze=[]
visited=[[None]*W for _ in range(H)]
q=deque([])
for i in range(H):
    a=input().rstrip()
    maze.append(a)
    for j in range(W):
        if a[j]=="#":
            visited[i][j]=0
            q.append([i,j])
ans=0
while q:
    h,w=q.popleft()
    for nh,nw in ([h+1,w],[h-1,w],[h,w+1],[h,w-1]):
        if nh<0 or nh>H-1 or nw<0 or nw>W-1:
            continue
        if visited[nh][nw]!=None:
            continue
        visited[nh][nw]=visited[h][w]+1
        ans=max(ans,visited[nh][nw])
        q.append([nh,nw])
print(ans)

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

using namespace std;

#define intt long long 
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 100005;

int n;

vector <intt> d;
vector <bool> used;
vector <int> color;
vector <vector <pair <int, intt>>> adj;

void bfs (int node) {
	queue <int> q;
	q.push(node);
	used[node] = true;
	d[node] = 0;
	while (!q.empty()) {
		int from = q.front();
		q.pop();
		for (auto to : adj[from]) {
			int tov = to.first;
			int tow = to.second;
			if (!used[tov]) {
				used[tov] = true;
				d[tov] = d[from] + tow;
				q.push(tov);
			}
		}
	}
}

int main() {

	FAST;

	cin >> n;
	d.resize(n + 1);
	color.resize(n + 1);
	used.assign(n + 1, false);
	adj.resize(n + 1);
	for (int i = 1; i < n; i ++) {
		int u, v, w;
		cin >> u >> v >> w;
		adj[u].push_back({v, w});
		adj[v].push_back({u, w});
	} 		
	bfs(1);
	color[1] = 0;
	for (int i = 2; i <= n; i ++) {
		color[i] = d[i] % 2;
	}
	for (int i = 1; i <= n; i ++) {
		cout << color[i] << '\n';
	}
	return 0;
}

Measured memory_bytes: 9088
import math

a,b,n = map(int, input().split())

maxresult = 0

#これはタイムオーバー
#for x in range(n+1):
#    if (a * x * 1.0 // b) - a * (x * 1.0 // b) >= maxresult:
#        maxresult = (a * x * 1.0 // b) - a * (x * 1.0 // b)

#これもタイムオーバー
#for x in range(n+1):
#    if a * math.modf(x*1.0/b)[0] >= maxresult:
#        maxresult = a * math.modf(x*1.0/b)[0]

"""
解説動画を見て、再考
x = pB + qと変形する。（https://twitter.com/chokudai/status/1256806061194874881）
floor[Ax / B]
=floor[(APB+Aq) / B]
=Ap + floor[Aq / B]

A * floor[x / B]
= A * floor[(pB+q) / B]
= A * (p + floor[q/B])

よって、
floor[Ax / B] - A * floor[x / B]
=Ap + floor[Aq / B] - Ap - A * floor[q / B]
=floor[Aq / B] - A * floor[q / B]
  #x = pB + qであるため、floor[q/B] = 0
=floor[Aq / B]
  #q = (x % B)なので
=floor[A/B * (x % B)]
この値が最大になればよく、xは整数なので、
x = B-1の時が最大となる。

ただしN < B-1の場合は、x = B-1を取れないので、
そのときにはxの最大値x=Nとなる。
"""

if n < b-1:
    x = n
else:
    x = b-1
maxresult = a * (x%b) // b

print(int(maxresult))

Measured memory_bytes: 62060
import sys

sys.setrecursionlimit(20000)

while True:
    H, W = map(int, input().split())
    if H == W == 0:
        exit()
    orchard = [list(input()) for i in range(H)]

    def dfs(i, j, fruit):
        orchard[i][j] = '.'
        move = [[0, 1], [0, -1], [1, 0], [-1, 0]]
        for di, dj in move:
            if 0 <= i+di < H and 0 <= j+dj < W and orchard[i+di][j+dj] == fruit:
                dfs(i+di, j+dj, fruit)

    count = 0
    for i in range(H):
        for j in range(W):
            if orchard[i][j] != '.':
                count += 1
                dfs(i, j, orchard[i][j])
    print(count)



Measured memory_bytes: 19976
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    long n,m;
    cin>>n>>m;
    pair<long,long> CB[n+m];
    for(int i = 0;i<n;i++) {
      int a;cin>>a;
      CB[i] = make_pair(a,1);
    }
    for(int i = n;i<n+m;i++){
      int b,c;cin>>b>>c;
      CB[i] = make_pair(c,b);
    }
    sort(CB,CB+n+m,greater<>());
    long g = 0;
    long mg = 0;
    for(int i = 0;i<n;i++){
       g+= CB[i].first*CB[i].second;
       mg+= CB[i].second;
       if(mg > n){
        long sa = mg-n;
        g-= sa*CB[i].first;
        mg = n;     
       }
       if(mg == n){
         cout<<g;
         return 0;
       }     
    }
    return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>

int main(void) {
	int sx, sy, tx, ty;
	int dx, dy;
	int i;
	if (scanf("%d%d%d%d", &sx, &sy, &tx, &ty) != 4) return 1;
	if (sx >= tx || sy >= ty) {
		puts("invalid input");
		return 0;
	}
	dx = tx - sx;
	dy = ty - sy;
	for (i = 0; i < dy; i++) putchar('U');
	for (i = 0; i < dx; i++) putchar('R');
	for (i = 0; i < dy; i++) putchar('D');
	for (i = 0; i < dx; i++) putchar('L');
	putchar('L');
	for (i = 0; i < dy; i++) putchar('U');
	putchar('U');
	putchar('R');
	for (i = 0; i < dx; i++) putchar('R');
	putchar('D');
	putchar('R');
	for (i = 0; i < dy; i++) putchar('D');
	putchar('D');
	putchar('L');
	for (i = 0; i < dx; i++) putchar('L');
	putchar('U');
	putchar('\n');
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main(void){
  int max=0,a,b,c,k;
  scanf("%d%d%d%d",&a,&b,&c,&k);
  if(a>=k) max=k;
  else if(a+b>=k) max=a;
  else if(a+b<k) max=2*a+b-k;
  printf("%d",max);
  return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

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

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

ll dp[1001][1001][2][2][2];
const ll INF = 1LL<<60;

int main(){
  int N, M;
  cin >> N >> M;
  vector<ll> x(N), y(N), z(N);
  rep(i,N) cin >> x[i] >> y[i] >> z[i];
  rep(i,1001)rep(j,1001)rep(k,2)rep(l,2)rep(m,2)
    dp[i][j][k][l][m] = -INF;
  rep(i,2)rep(j,2)rep(k,2)
    dp[0][0][i][j][k] = 0;
  for(int i=1; i<=N; i++){
    for(int j=0; j<=M; j++){
      rep(k,2)rep(l,2)rep(m,2){
        ll a=x[i-1], b=y[i-1], c=z[i-1];
        if(k)
          a=-a;
        if(l)
          b=-b;
        if(m)
          c=-c;
        chmax(dp[i][j][k][l][m], dp[i-1][j][k][l][m]);
        if(j)
          chmax(dp[i][j][k][l][m], dp[i-1][j-1][k][l][m]+a+b+c);
      }
    }
  }
  ll ans=0;
  rep(i,2)rep(j,2)rep(k,2)
    chmax(ans, dp[N][M][i][j][k]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 62976
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int n;
	int max=1<<15;
	int[] prime;
	boolean[] isPrime;

	void run(){
		int p=0;
		prime=new int[max];
		isPrime=new boolean[max+1];
		Arrays.fill(isPrime, true);
		isPrime[0]=isPrime[1]=false;
		for(int i=2; i<=max; i++){
			if(isPrime[i]){
				prime[p++]=i;
				for(int j=2*i; j<=max; j+=i){
					isPrime[j]=false;
				}
			}
		}
		for(;;){
			n=sc.nextInt();
			if(n==0){
				break;
			}
			solve();
		}
	}

	void solve(){
		int ans=0;
		for(int i=0; prime[i]<=n-prime[i]; i++){
			if(isPrime[n-prime[i]]){
				ans++;
			}
		}
		println(ans+"");
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int H1, M1, H2, M2, K;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> H1 >> M1 >> H2 >> M2 >> K;

	int st = H1 * 60 + M1;
	int gl = H2 * 60 + M2;

	int len = gl - st;
	int ans = len - K;
	cout << ans << endl;
}







Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ppb pop_back
int n,k,cnt=1;
int a[100001];
long long b[100001];
int main()
{
	cin>>k>>n;
	for (int i=1;i<=n;i++){
		cin>>a[i];
	}
	for (int i=1;i<n;i++){
		if (a[i]==(a[i+1]-1)) {
			cout<<0;
			return 0;
		}
	}
	b[1]=1;
	b[2]=2;
	if (a[cnt]==1) {
		b[2]=1;
		cnt++;
	}
	for (int i=3;i<=k;i++){
		if (i-1==a[cnt]) {
				b[i]=b[i-2];
				cnt++;
			}
		else if (i-2==a[cnt-1]) b[i]=b[i-1];
		else b[i]=b[i-1]+b[i-2];
		b[i]%=1000000007;
	}
	if (k!=a[n]) {
		cout<<b[k]; 
	}
	else cout<<0;
	return 0;
}

Measured memory_bytes: 1280
from collections import Counter, deque
from random import randint

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

CA = Counter(A)
CB = Counter(B)
keys = set(A + B)
M = 0
for k in keys:
    M = max(M, CA[k] + CB[k])

if M > N:
    print('No')
    exit()

CB = CB.most_common()
L, R = [], []
for i, x in enumerate(CB):
    if i % 2 == 0:
        L.append(list(x))
    else:
        R.append(list(x))
X = deque(L + R[::-1])

y = L + R
ans = [None] * N
for i in range(N):
    if (X[0][0] != A[i]) and (X[-1][0] != A[i]):
        if X[0][1] > X[-1][1]:
            ans[i] = X[0][0]
            X[0][1] -= 1
            if X[0][1] == 0:
                X.popleft()
        else:
            ans[i] = X[-1][0]
            X[-1][1] -= 1
            if X[-1][1] == 0:
                X.pop()

    elif X[0][0] != A[i]:
        ans[i] = X[0][0]
        X[0][1] -= 1
        if X[0][1] == 0:
            X.popleft()
    else:
        ans[i] = X[-1][0]
        X[-1][1] -= 1
        if X[-1][1] == 0:
            X.pop()


for i in range(10):
    m = randint(0, N - 1)
    for i in range(N):
        if ans[i] != A[i]:
            continue
        ans[i], ans[m] = ans[m], ans[i]
        m += 1
        m %= N
print('Yes')
print(*ans, sep=' ')


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

int main(){
    int i = 0;
    int x[25565] = {0};
    int y[25565] = {0};
    do{
        cin >> x[i] >> y[i];
        i = i + 1;
    }while(x[i-1] != 0 || y[i-1] != 0);
    i = 0;
    do{
        if(x[i] != 0 || y[i] != 0){
            if(x[i] <= y[i]){
                cout << x[i] << " " << y[i] << endl;
            }else if(x[i] > y[i]){
                cout << y[i] << " " << x[i] << endl;
            }
        }
        i = i + 1;
    }while(x[i-1] != 0 || y[i-1] != 0);
}

Measured memory_bytes: 1364
#include <stdio.h>

int main(void)
{
    int N,D;
    int X[10][10];
    scanf("%d%d",&N,&D);
    for(int i=1;i<=N;i++){
        for(int j=1;j<=D;j++){
            scanf("%d",&X[i][j]);
        }
    }
    int c=0;
    for(int i=1;i<=N-1;i++){
        for(int j=i+1;j<=N;j++){
            //printf("i=%d j=%d\n",i,j);
            int sum=0;
            for(int k=1;k<=D;k++){
                sum+=(X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
            }
            //printf("i=%d j=%d sum=%d\n",i,j,sum);
            for(int l=1;l<=16000;l++){
                if(sum==l*l){
                    c++;
                    break;
                }
            }
        }
    }
    printf("%d\n",c);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define M 1000000007

using namespace std;

int main() 
{
	IOS	
	ll n,x;
	cin>>n>>x;
	ll w[n],v[n];
	for(ll i=0;i<n;++i)
	{
	    cin>>w[i]>>v[i];
	}
	ll dp[n+1][x+1];
	memset(dp,-1,sizeof dp);
	for(ll i=0;i<=n;++i)
	{
	    for(ll j=0;j<=x;++j)
	    {
	        if(i==0 || j==0)dp[i][j]=0;
	        else if(j>=w[i-1])dp[i][j]=max(v[i-1]+dp[i-1][j-w[i-1]],dp[i-1][j]);
	        else dp[i][j]=dp[i-1][j];
	    }
	}
	ll ans=-1;
	for(ll i=1;i<=n;++i)
	{
	    ans=max(ans,dp[i][x]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 79232
#include <iostream>
#include <vector>
#include <functional>

template <class T>
struct SegmentTree {
    using Merger = std::function<T(T, T)>;

    int length;
    std::vector<T> dat;
    T unit;
    Merger merge;

    explicit SegmentTree(int n, const T& unit, const Merger& merge)
        : length(1), unit(unit), merge(merge) {
        while (length < n) length <<= 1;
        dat.assign(length * 2, unit);
    }

    template <class Container>
    explicit SegmentTree(const Container& elems, const T& unit, const Merger& merge)
        : length(1), unit(unit), merge(merge) {
        int n = elems.size();
        while (length < n) length <<= 1;

        dat.assign(length * 2, unit);

        std::copy(elems.begin(), elems.end(), dat.begin() + length);

        for (int nidx = length - 1; nidx >= 1; --nidx) {
            T vl = dat[nidx * 2 + 0];
            T vr = dat[nidx * 2 + 1];
            dat[nidx] = merge(vl, vr);
        }
    }

    void update(int nidx, const T& elem) {
        nidx += length;
        dat[nidx] = elem;

        while (nidx > 0) {
            nidx >>= 1;
            T vl = dat[nidx * 2 + 0];
            T vr = dat[nidx * 2 + 1];
            dat[nidx] = merge(vl, vr);
        }
    }

    T fold(int ql, int qr) {
        ql = std::max(ql, 0);
        qr = std::min(qr, length);
        ql += length, qr += length;

        T lacc = unit, racc = unit;
        while (ql < qr) {
            if (ql & 1) {
                lacc = merge(lacc, dat[ql]);
                ++ql;
            }
            if (qr & 1) {
                --qr;
                racc = merge(dat[qr], racc);
            }
            ql >>= 1, qr >>= 1;
        }

        return merge(lacc, racc);
    }

    T get(int idx) { return dat[idx + length]; }
    T whole() { return dat[1]; }
};

constexpr int INF = 1 << 30;

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> xs(n);
    for (auto& x : xs) std::cin >> x;

    std::vector<std::vector<int>> rss(n);
    {
        int q;
        std::cin >> q;
        while (q--) {
            int l, r;
            std::cin >> l >> r;
            rss[--l].push_back(r);
        }
    }

    SegmentTree<int>
        seg(n + 1, INF, [](auto a, auto b) { return std::min(a, b); });
    seg.update(0, 0);
    int buf = 0;

    for (int l = 0; l < n; ++l) {
        for (auto r : rss[l]) {
            seg.update(r, seg.fold(l, r + 1));
        }

        if (xs[l] == 0) {
            ++buf;
            seg.update(l, seg.get(l) - 1);
        } else {
            seg.update(l, seg.get(l) + 1);
        }

        seg.update(l + 1, seg.fold(l, l + 2));
    }

    std::cout << seg.get(n) + buf << "\n";
}

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

    solve();

    return 0;
}


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

#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;

int main(void){
    int n;
    cin >> n;
    ll ans = 0;
    rep(i,n){
        if((i+1) % 3 == 0 || (i+1) %5 == 0){
        }else{
            ans += i+1;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(n) for (int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define dump(x) cout << " " << #x << "=" << x
#define vdump(v) for(size_t T=0; T<v.size(); ++T){cout << " " << #v << "[" << T << "]=" << v[T];} cout << endl
using namespace std;
using lint = long long;
using ld = long double;

void show(vector<vector<bool>> dp) {
    int n = dp.size();
    int k = dp[0].size();
    repeat(i, n) {
        repeat(j, k) {
            cout << boolalpha << dp[i][j] << " ";
        }
        cout << endl;
    }
    cout << endl;
}

int main(void) {
    int n, k;
    cin >> n >> k;
    vector<lint> a(n);
    repeat(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    
    auto is_no_need = [](const vector<lint> &a, int lb, int ub) {
        int n = a.size();
        if (lb < 0) lb = 0;
        // dp[x][y] = x 枚目(0-index)まで使って総和を y にできるか
        vector<vector<bool>> dp(n, vector<bool>(ub+1, false));
        dp[0][0] = true;
        if (a[0] <= ub) dp[0][a[0]] = true;
        repeat_from(x, 1, n) {
            repeat_from_to(y, 0, ub) {
                if (y-a[x] >= 0 && dp[x-1][y-a[x]]) dp[x][y] = true;
                if (dp[x-1][y]) dp[x][y] = true;
                if (dp[x-1][y] && y + a[x] >= ub) dp[x][ub] = true;
            }
        }
        bool ret = false;
        repeat_from(i, lb, ub) {
            if (dp[n-1][i]) {
                ret = true;
                break;
            }
        }
        return !ret;
    };
    
    auto judge = [=](int t) {
        vector<lint> arg_a = a;
        auto pos = lower_bound(arg_a.begin(), arg_a.end(), t);
        arg_a.erase(pos);
        return is_no_need(arg_a, k-t, k);
    };
    
    if (n == 1) {
        if (a[0] < k) cout << 1 << endl;
        else cout << 0 << endl;
        return 0;
    }
    auto it = partition_point(a.begin(), a.end(), judge);
    cout << distance(a.begin(), it) << endl;
    return 0;
    
}

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

int main() {
    Int n, T; cin >> n >> T;
    vector<Int> t(n);
    rep(i, n) cin >> t[i];
    Int ans = 0;

    for (int i = 0; i < n-1; i++) {
        ans += min(T, t[i+1]-t[i]);
    }
    cout << ans + T<< endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int N=sc.nextInt(),K=sc.nextInt();
		int ans=0;

		for(int i=0;i<N;i++) {
			int x=sc.nextInt();
			if(x<(K-x)) {
				ans+=2*x;
			}else {
				ans+=2*(K-x);
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23636
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=1;i<=n;i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//完全グラフからk本切って、連結を維持
///nC2-k>=n-1なら構築可能


int main(){
    int n,k;
    cin >> n >> k;
    int m = n*(n-1)/2-k;
    if(m<n-1){
        cout << -1 << endl;
        return 0;
    }
    cout << m << endl;
    repp(i,n-1){
        cout << i << " " << n << endl;
    }
    m-=n-1;
    int res=0;
    repp(i,n-1){
        repp(j,n-1){
            if(res==m) return 0;
            if(i<j){
                cout << i << " " << j << endl;
                res++;
            }
        }
    }
}


Measured memory_bytes: 256
S = input()
s = len(S)
T = input()
t = len(T)

key = 0
for i in range(s-t,-1,-1):
    for j,k in enumerate(S[i:i+t]):
        if k == T[j] or k =="?":
            pass
        else:
            break
    else:
        key = i
        break
    key = 100
if key == 100 or s<t:
    print("UNRESTORABLE")
else:
    ans = S[0:i]+T+S[i+t:]
    ans = ans.replace("?","a")
    print(ans)

Measured memory_bytes: 9088
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <algorithm>

using namespace std;

int main(){
    int A,B,M;

    cin >> A >> B >> M;

    vector<int> Aa,Bb;

    int amin = 100000;
    int bmin = 100000;
    int min = 200000;

    for(int i = 0; i < A; i++){
        int a;
        cin >> a;

        if(a < amin){
            amin = a;
        }

        Aa.push_back(a);
    }

    for(int i = 0; i < B; i++){
        int b;
        cin >> b;

        if(b < bmin){
            bmin = b;
        }

        Bb.push_back(b);
    }

    min = amin + bmin;

    for(int i = 0; i < M; i++){
        int x,y,c;

        cin >> x >> y >> c;

        if(Aa[x-1] + Bb[y-1] - c < min){
            min = Aa[x-1] + Bb[y-1] - c;
        }
    }

    cout << min << endl;

    return 0;
}


Measured memory_bytes: 1400
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)

#define PI 3.1415926535

typedef long long ll;
typedef pair<int, int> P;
//typedef complex<double> C;

const ll INF = (1LL << 31) - 1;
const int MAX_N = 1 << 17;

int n;
ll dat[2 * MAX_N - 1];

void init(int n_) {
    // n: num of elements in the bottom row
    // let n be the power of 2
    n = 1;
    while (n < n_) n *= 2;

    // set all values by INF
    REP(i, 2 * n - 1) dat[i] = INF;
}

// change the k-th(0-index) value to a
void update(int k, int a) {
    // set a in the leaf
    k += n - 1;
    dat[k] = a;

    // update upward
    while (k > 0) {
        k = (k - 1) / 2;
        dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
    }
}

// get the minimum value in [a, b)
// k: num of the node corresponds to [l, r)
// call like this: 'query(a, b, 0, 0, n)'
int query(int a, int b, int k, int l, int r) {
    // if [a, b) & [l, r) = 0, then return INF
    if (r <= a || b <= l) return INF;

    // if [a, b) covers the whole [l, r),
    // then return the value of this node
    if (a <= l && r <= b) return dat[k];

    // otherwise, return the min of two children
    int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);

    return min(vl, vr);
}

void solve() {
    int t_n, q;
	cin >> t_n >> q;
	init(t_n);
    REP(i, q) {
		int c, x, y;
		cin >> c >> x >> y;
		if (c) {
			cout << query(x, y + 1, 0, 0, n) << endl;
		} else {
			update(x, y);
		}

	}
}

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

Measured memory_bytes: 5152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
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; }


int main() {
    string s, r, l;
    cin >> s;
    ll q;
    cin >> q;
    ll t, f, count=0;
    char c;
    rep1(i, q){
        cin >> t;
        if (t == 1){
            swap(r, l);
            count++;
        } else{
            cin >> f >> c;
            if (f == 1) l += c;
            else r += c;
        }
    }
    if (count%2 == 1) reverse(s.begin(), s.end());
    reverse(l.begin(), l.end());
    string ans = l + s + r; 
    cout << ans << endl;
    //printf("%.12f", ans);
}

Measured memory_bytes: 4316
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int d[256][51][51];

int main(){
	int h, w;
	cin>>h>>w;
	vector<string> s(h);
	rep(i, h) cin>>s[i];

	for(int i = 0; i <= h; i++){
		for(int j = 0; j <= w; j++){
			d['W'][i][j] = 0;
			d['B'][i][j] = 0;
			d['R'][i][j] = 0;
		}
	}
	char cs[] = "WBR";
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			for(auto c : cs){
				d[c][i + 1][j + 1] += d[c][i + 1][j] +(s[i][j] == c ? 1 : 0);
			}
		}
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			for(auto c : cs){
				d[c][i + 1][j + 1] += d[c][i][j + 1];
			}
		}
	}
	int ans = INF;

	for(int i = 1; i < h - 1; i++){//0 -  i-1 -> white
		for(int j = i + 1; j < h; j++){//i - j-1 -> brue j - n-1 -> red
			int tmp = 0;
			tmp += d['B'][i][w] + d['R'][i][w];
			tmp += d['W'][j][w] + d['R'][j][w] - d['W'][i][w] - d['R'][i][w];
			tmp += d['W'][h][w] + d['B'][h][w] - d['W'][j][w] - d['B'][j][w];
			ans = min(ans, tmp);
		}
	}

	cout<<ans<<endl;
 }

Measured memory_bytes: 3260
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

# (A0 - m) ^ (A1 + m) == XORとなる最小のmを考える

#処理内容
def main():
	N = int(input())
	A = getlist()
	XOR = 0	
	for i in range(2, N):
		XOR ^= A[i]

	Asum = A[0] + A[1]
	ans = INF
	AA = Asum
	# print(A[0], A[1], XOR)
	a0 = 0; a1 = 0
	# XORが1のbitの値を先に引く
	for i in range(50, -1, -1):
		if (2 ** i) & XOR == (2 ** i):
			AA -= 2 ** i

	# print(AA)

	# XORが0のbitの01を決める
	for i in range(50, -1, -1):
		if (2 ** i) & XOR == 0:
			if AA >= 2 ** (i + 1):
				AA -= 2 ** (i + 1)
				a0 += 2 ** i
				a1 += 2 ** i
			else:
				pass

	# print(a0, a1)

	# a0のbitをどん欲に決める
	for i in range(50, -1, -1):
		if (2 ** i) & XOR == (2 ** i):
			if a0 + 2 ** i <= A[0]:
				a0 += 2 ** i
			else:
				a1 += 2 ** i

	if a0 == 0 or a0 > A[0] or a0 + a1 != Asum or a0 ^ a1 != XOR:
		print(-1)
	else:
		print(A[0] - a0)

	# print(a0, a1)


if __name__ == '__main__':
	main()

Measured memory_bytes: 65260
#include<stdio.h>
#include<stdlib.h>
int main(){
    int a,b,max;
    scanf("%d%d",&a,&b);
    if(-100>a || b>100) exit(0);
max=a+b;
if(a-b>max) max=a-b;
if(a*b>max) max=a*b;
    printf("%d",max);
    return 0;
}

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

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> P(N);
	for (int i = 0; i < N; i++) cin >> P[i];
	sort(P.begin(), P.end());
	int COUNT = 0;
	for (int i = 0; i < K; i++) COUNT += P[i];
	cout << COUNT << endl;
}

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


int main(){
    int n; cin >> n;
    vector<int> c(n),s(n),f(n);
    int now = 0;
    rep(i,n-1) cin >> c[i] >> s[i] >> f[i];
    rep(i,n){ // start
        if(i == n-1){
            cout << 0 << endl;
            continue;
        } 
        int now = 0;
        for(int j = i; j < n-1; ++j){ // simulation
            now = max(now,s[j]);
            now = ((now+f[j]-1)/f[j])*f[j] + c[j];
        }
        cout << now << "\n";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ri register int
using namespace std;
const int rlen = 1 << 20 | 5;
char buf[rlen], *ib = buf, *ob = buf;
#define gc() (((ib == ob) && (ob = (ib = buf) + fread(buf, 1, rlen, stdin))), ib == ob ? -1 : *ib++)
inline int read() {
  static int ans;
  static char ch;
  for (ans = 0, ch = gc(); !isdigit(ch); ch = gc());
  while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = gc();
  return ans;
}
typedef long long ll;
#define pb push_back
#define rez resize
#define ppp pop_back
template <typename T> inline void exgcd(T a, T b, T &x, T &y) {
  if (!b) { x = 1, y = 0; return; }
  exgcd(b, a - a / b * b, y, x), y -= a / b * x;
}
namespace modular {
  const int mod = 998244353;
  int ret;
  inline int add(int a, int b) { return a < mod - b ? a + b : a - mod + b; }
  inline int dec(int a, int b) { return a < b ? a - b + mod : a - b; }
  inline int mul(int a, int b) { return (ll) a * b % mod; }
  inline void Add(int &a, int b) { a = a < mod - b ? a + b : a - mod + b; }
  inline void Dec(int &a, int b) { a = a < b ? a - b + mod : a - b ; }
  inline void Mul(int &a, int b) { a = (ll) a * b % mod; }
  inline int ksm(int a, int p) { for (ret = 1; p; p >>= 1, Mul(a, a)) (p & 1) && (Mul(ret, a), 1); return ret; }
  inline int fix(int x) {
    x <= -mod || x >= mod ? x %= mod : 0;
    return x < 0 ? x + mod : x;
  }
  inline int Inv(int a) {
    static int x, y;
    return exgcd(a, mod, x, y), fix(x);
  }
}  using namespace modular;
const int N = 2e5 + 5;
int n, a[N], b[N];
bool in[N];
inline bool check(int p) {
  int pre = p > 1 ? p - 1 : n;
  int suf = p < n ? p + 1 : 1;
  if (b[pre] + b[suf] <= b[p]) return 1;
  return 0; 
}
int main() {
  #ifdef ldxcaicai
  freopen("lx.in", "r", stdin);
  #endif
  n = read();
  for (ri i = 1; i <= n; ++i) a[i] = read();
  for (ri i = 1; i <= n; ++i) {
    b[i] = read();
    if (b[i] < a[i]) return cout << -1, 0;
  }
  queue <int> q;
  for (ri i = 1; i <= n; ++i) if (check(i)) q.push(i), in[i] = 1;
  ll res = 0;
  while (q.size()) {
    int x = q.front();
    q.pop(), in[x] = 0;
    int pre = x > 1 ? x - 1 : n;
    int suf = x < n ? x + 1 : 1;
    int ss = b[pre] + b[suf];
    int t = max(0, (b[x] - a[x]) / ss);
    if (!t && a[x] != b[x]) return cout << -1, 0;
    res += t, b[x] -= ss * t;
    if (!in[pre] && check(pre)) q.push(pre), in[pre] = 1;
    if (!in[suf] && check(suf)) q.push(suf), in[suf] = 1;
  }
  for (ri i = 1; i <= n; ++i) if (a[i] != b[i]) return cout << -1, 0;
  cout << res;
  return 0;
}

Measured memory_bytes: 6752
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main implements Runnable {

	public static void main(String[] args) {

		new Thread(null, new Main(), "", 16 * 1024 * 1024).start();

	}

	@Override
	public void run() {
		exec();
	}

	private void exec() {

		FastScanner sc = new FastScanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		if(b == 1) {
			System.out.println(0);
			System.exit(0);
		}

		int ans = 1;
		int hole = a;
		while(hole < b) {
			hole--;
			hole += a;
			ans++;
		}

		System.out.println(ans);

	}

}

class FastScanner {

	private final InputStream in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	public FastScanner(InputStream in) {
		this.in = in;
	}

	private boolean hasNextByte() {
		if(ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if(buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if(hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while(hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){
				return minus ? -n : n;
			}else{
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

}


Measured memory_bytes: 23252
#include "bits/stdc++.h"
using namespace std;

int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int ans=1e9;
  int w=0;
  int e=0;
  for(int i=0;i<n;i++){
    if(s[i]=='W'){
      w++;
    }else{
      e++;
    }
  }
  int ww=0;
  int ee=0;
  ans=e;
  for(int i=0;i<n;i++){
    if(s[i]=='W'){
      w--;
      ee++;
    }else{
      e--;
      ww++;
    }
    ans=min(ans,e+ee);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 900
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), k = sc.nextInt();
		sc.close();
		long ans = (long)Math.pow((long)(n / k), (long)3);
		if(k % 2 == 0) {
			ans += (long)Math.pow((long)((n + (k / 2)) / k), (long)3);
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ARB ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pp __builtin_popcount
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int maxn=1e5+5;
int main()
{
    ARB
    ll x;
    cin>>x;
    ll ans=0;
    while(x>0)
    {
        if(x>=500)
        {
            x-=500;
            ans+=1000;
        }
        if(x>=5&&x<500)
        {
            ans+=5;
            x-=5;
        }
        if(x<5)
            break;
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
const int max = 100000;
int n,v[max],cnt0[max + 1],cnt1[max + 1];
inline int maximum(int M)
{
	std::memset(cnt0 + 1,0,max << 2);
	int M0 = 0;
	for (int i = M;i < n;i += 2)
		if (cnt0[M0] < ++ cnt0[v[i]])
			M0 = v[i];
	std::memset(cnt1 + 1,0,max << 2);
	int M1 = 0;
	for (int i = M ^ 1;i < n;i += 2)
		if (cnt1[M1] < ++ cnt1[v[i]] && M0 != v[i])
			M1 = v[i];
	return cnt0[M0] + cnt1[M1];
}
main()
{
	std::ios_base::sync_with_stdio(0),std::cin.tie(0);
	std::cin >> n;
	for (int i = 0;i < n;++ i)
		std::cin >> v[i];
	std::cout << n - std::max(maximum(0),maximum(1)) << '\n';
}

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

using namespace std;

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

    vector<int> l;
    l.assign(N, 0);

    for(int i = 0; i < N; i++) {
        cin >> l[i];
    }

    sort(l.begin(), l.end());
    int ans = 0;
    for(int i = N-1; i >= N-K; i--) {
        ans += l[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
M, D = map(int, input().split())

ans = 0
for m in range(1, M+1):
    for d1 in range(2, 10):
        for d2 in range(2, 10):
            d = d1 + d2 * 10
            if d <= D:
                if d1 * d2 == m:
                    ans += 1
                    # print()

print(ans)


Measured memory_bytes: 40304
n,m=map(int,input().split())
xy=[]

for i in range(n):
    xy+=[list(map(int,input().split()))]

xy1=[]
for i in range(m):
    xy1+=[list(map(int,input().split()))]


for i in range(n):
    num=0
    dist=10**20
    for j in range(m):
        dist1=abs(xy[i][0]-xy1[j][0])+abs(xy[i][1]-xy1[j][1])
        if dist>dist1:
            dist=dist1
            num=j+1
    print(num)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
template <class T> void chmax(T &x, T y) { if (x < y) x = y; }
Int dp[3000][3000][4], val[3000][3000];
int main() {
    int R, C, K; cin >> R >> C >> K;
    while (K--) {
        int r, c, v; cin >> r >> c >> v; r--, c--;
        val[r][c] = v;
    }
    dp[0][0][0] = 0;
    dp[0][0][1] = val[0][0];
    for (int r = 0; r < R; r++) {
        for (int c = 0; c < C; c++) {
            for (int n = 0; n < 4; n++) {
                if (r + 1 < R) {
                    chmax(dp[r + 1][c][0], dp[r][c][n]);
                    chmax(dp[r + 1][c][1], dp[r][c][n] + val[r + 1][c]);
                }
                if (c + 1 < C) {
                    chmax(dp[r][c + 1][n], dp[r][c][n]);
                    if (n <= 2) chmax(dp[r][c + 1][n + 1], dp[r][c][n] + val[r][c + 1]);
                }
            }
        }
    }
    Int ans = 0;
    for (int i = 0; i < 4; i++) {
        chmax(ans, dp[R-1][C-1][i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 354996
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
A = []
for i in range(N):
    A.append(list(map(int, input().split())))

def main():
    cnt = 0
    for i in range(N):
        val = C
        for j in range(M):
            val += A[i][j] * B[j]
        if val > 0:
            cnt += 1
    return cnt

print(main())

Measured memory_bytes: 3064
#include <stdio.h>

int main(){
	char sn[200];
	int i = 0;

	scanf("%s", sn);

	while (sn[i] != '\0'){
		if ((i % 2) == 0) {
			if (sn[i] == 'L') {
				printf("No\n");
				return 0;
			}
			i++;
		}
		else{
			if (sn[i] == 'R') {
				printf("No\n");
				return 0;
			}
			i++;
		}
	}

	printf("Yes\n");

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;

void dfs(string s,char c){
	if(s.size()==N){
		cout<<s<<endl;
	}
	else{
		for(char i='a';i<=c;i++){
			dfs(s+i,(i==c)?c+1:c);
		}
	}
}

signed main(){
	cin>>N;
	dfs("",'a');
	return 0;
}


Measured memory_bytes: 1536
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
n, q = map(int, input().split())

ki = [[] for i in range(n + 1)]
for i in range(n - 1):
    a, b = map(int, input().split())
    ki[a].append(b)
    ki[b].append(a)
# print(ki)

cnt = [0] * (n + 1)
for i in range(q):
    p, x = map(int, input().split())
    cnt[p] += x


# print(cnt)


def d(y, parent):
    for i in ki[y]:
        if i == parent:
            continue
        cnt[i] += cnt[y]
        d(i, y)


d(1, -1)
print(*cnt[1:])

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

int main() {
  int n;
  ll k;
  cin >> n >> k;
  ll a[n], f[n];
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];
  sort(a, a+n);
  sort(f, f+n, greater<ll>());
  ll l, r;
  l = 0; r = MAX*MAX+1;

  while (l < r) {
    ll mid = (l+r) / 2;
    ll rem = k;
    rep(i, n) {
      ll buf = ( (a[i]*f[i] - mid) + (f[i] - 1) ) / f[i];
      if (buf > 0) rem -= buf;
    }
    if (rem < 0) l = mid+1;
    else r = mid;
  }
  cout << l << endl;
  return 0;
}

Measured memory_bytes: 3328
import sys


def main():
    while True:
        H, W = map(int, sys.stdin.readline().split())
        if H == 0 and W == 0: break
        for h in range(H):
            for w in range(W):
                if h % 2 == 0:
                    if w % 2 == 0:
                        print('#', end='')
                    else:
                        print('.', end='')
                else:
                    if w % 2 == 0:
                        print('.', end='')
                    else:
                        print('#',end='')
            print()
        print()
    return


if __name__ == '__main__':
    main()



Measured memory_bytes: 7012
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<list>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
#define P pair<int,int>
using namespace std;

int a, b;
vector<P>V;
int c[100][100];
int f[50][50];
int g[50][50];
void kaiten() {
	int sum = 0;
	for (int i = 0; i < b;i++) {
		for (int j = b - 1; j >= 0;j--, sum++) {
			g[sum / b][sum%b] = f[j][i];
		}
	}
	for (int i = 0; i < b; i++) {
		for (int j = 0; j < b; j++) {
			f[i][j] = g[i][j];
		}
	}
}
signed main(){
	while (cin >> a >> b, a | b) {
		V.clear();
		for (int d = 0; d < a; d++) {
			for (int e = 0; e < a; e++) {
				scanf("%d", &c[d][e]);
			}
		}
		for (int d = 0; d < b; d++) {
			for (int e = 0; e < b; e++) {
				scanf("%d", &f[d][e]);
			}
		}
		for (int i = 0; i < 4; i++) {
			kaiten();
			for (int x = 0; x < a - b + 1; x++) {
				for (int y = 0; y < a - b + 1; y++) {
					bool S = true;
					for (int n = 0; n < b; n++) {
						for (int m = 0; m < b; m++) {
							if (f[n][m] != -1 && c[x+n][y+m] != f[n][m])S = false;
						}
					}
					if (S) {
						for (int n = 0; n < b; n++) {
							for (int m = 0; m < b; m++) {
								if (f[n][m] != -1) { V.push_back(P(x+n,y+m)); break; }
							}
						}
					}
				}
			}
		}
		if (V.size()>=1) {
			P Q = P(1 << 29, 1 << 29);
			for (P i : V) {
				Q = min(Q, i);
			}
			cout << Q.second + 1 << " " << Q.first + 1 << endl;
		}
		else {
			puts("NA");
		}
	}
}

Measured memory_bytes: 3524
#include<stdio.h>
 int main(void)
{
 int r, c, c_last, i, j, table[100][100], rsum = 0, csum = 0, total = 0;
 scanf("%d %d\n", &r, &c);
 c_last = c-1;
 for(i = 0; i < r; i++)
{
 for(j = 0; j < c; j++){ if(j == c_last)
{
 scanf("%d\n", &table[i][j]);
 }
else
{
 scanf("%d ", &table[i][j]);
 }
 }
 }
 for(i = 0;
 i < r;
 i++)
{
 for(j = 0;
 j < c;
 j++)
{
 rsum += table[i][j];
 printf("%d ", table[i][j]);
 if(j == c_last)
{
 printf("%d\n", rsum);
 }
 }
 rsum = 0;
 }
 for(j = 0;
 j < c;
 j++)
{
 for(i = 0;
 i < r;
 i++)
{
 csum += table[i][j];
 }
 printf("%d ", csum);
 total += csum;
 csum = 0;
 if(j == c_last)
{
 printf("%d\n", total);
 }
 }
 return 0;
 }
 


Measured memory_bytes: 2140
//In The Name Of The God

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define F first
#define S second
#define X first.first
#define Y first .second
#define A second.first
#define B second.second
#define mp make_pair
#define pb push_back
#define pf push_front
#define P push
#define pob pop_back
#define pof pop_front
#define PO pop
#define rep(i,j,k) for(int i = j ; i <= k ; ++ i)
#define rrep(i,j,k) for(int i = j ; i>=k ; --i)
#define FR(i,j,k) for(int i = j ; i < k ; ++ i )
#define rFR(i,j,k) for(int i = j ; i > k ; -- i )
#define lb(x) x&-x
#define p2(x) (1LL<<x)
#define SZ size()
#define LB lower_bound
#define UB upper_bound
#define IT iterator
#define RIT reverse_iterator
#define E end()
#define BE begin()
#define RE rend()
#define RBE rbegin()
#define UN unsigned

typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll ;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;
typedef pair<int,pll> pipl;
typedef pair<pll,int> ppli ;
typedef pair<pll,pll> plpl ;
typedef pair<ll,pii> lpip;
typedef pair<pii,ll> lppi;
typedef pair<pii,pii> lppp;
typedef pair<ll,pll> lpipl;
typedef pair<pll,ll> lppli ;
typedef pair<pll,pll> lplpl ;
typedef vector<int> vi ;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef set<int> sti;
typedef set<ll> stl;
typedef set<pii > stpi;
typedef set<pll> stpl;
typedef vi::IT vit;
typedef vl::IT vlt;
typedef vpi::IT vpit;
typedef vpl::IT vplt;
typedef sti::IT stit;
typedef stl::IT stlt;
typedef stpi::IT stpit;
typedef stpl::IT stplt;
typedef vpi::RIT rvpit;
typedef vpl::RIT rvplt;
typedef sti::RIT rstit;
typedef stl::RIT rstlt;
typedef stpi::RIT rstpit;
typedef stpl::RIT rstplt;

const int MAXN = 500000;
const int SUPERN = 5000000;
const int MAXS = 325;
const int SUPERS = 1000;
const int MD = 1e9+7;
//......Structures.......

//......Variables........
int h,w,cnt[29],k[10];
char u;
//......Funcs............
ll sum(ll a,ll b)
{
    return (a+b)%MD;
}
ll mu(ll a,ll b)
{
    return (a*b)%MD;
}
ll mn(ll a,ll b)
{
    return(a-b+MD)%MD;
}
//......Code.............
int main()
{
	cin>>h>>w;
	rep(i,1,h)rep(j,1,w)
	{
		cin>>u;
		cnt[u-'a']++;
	}
	rep(i,0,'z'-'a')
	{
		k[cnt[i]%4]++;
	}
	if(h%2==0&&w%2==0)
	{
		if(k[1]+k[3]+k[2]==0)
		{
			cout<<"Yes";
		}
		else cout<<"No";
	}
	if(h%2==0&&w%2||w%2==0&&h%2)
	{
		if(k[1]+k[3]==0&&k[2]<=(h%2?w/2:h/2))
		{
			cout<<"Yes";
		}
		else cout<<"No";
	}
	if(h%2&&w%2)
	{
		if(k[1]+k[3]==1&&k[2]<=(h-1)/2+(w-1)/2)
		{
			cout<<"Yes";
		}
		else cout<<"No";
	}

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <assert.h>
#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater <>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
using namespace std;
using ll = long long;
typedef std::pair<int,int> P;
#include <boost/multiprecision/cpp_int.hpp>

using bint = boost::multiprecision::cpp_int;
 



int main(){
    int n,d;
    cin >> d >> n;
    int ans = 1;
    rep(i,d) ans*=100;
    while(n%100==0){
        n += n/100;
    }
    cout << n*ans;
}


Measured memory_bytes: 256
# if (true)

# include <iostream>
# include <string>

using Int = int;

bool containC(const std::string& str)
{
    int count{};
    for (int i{ 2 }; i < str.size() - 1; ++i)
    {
        if (str[i] == 'C') ++count;
    }

    return count == 1;
}

std::string removeAC(std::string str)
{
    for (int i{ 2 }; i < str.size() - 1; ++i)
    {
        if (str[i] == 'C')
        {
            str.erase(str.begin() + i);
            break;
        }
    }
    str.erase(str.begin());

    return str;
}

bool isLowerCase(const std::string& str)
{
    for (auto c : removeAC(str))
    {
        if (c < 'a' || 'z' < c)
        {
            return false;
        }
    }

    return true;
}

int main()
{
   
    std::string str;
    std::cin >> str;

    if (str.front() == 'A' &&
        containC(str) &&
        isLowerCase(str) )
    {
        std::cout << "AC";
    }
    else
    {
        std::cout << "WA";
    }

    return 0;
}


# endif



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int cnt[200100];
int main(){
	int n,k;
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++){
		int tmp;
		scanf("%d",&tmp);
		cnt[tmp]++;
	}
	sort(cnt+1,cnt+1+n);
	int res=0;
	for(int i=1;i<=n-k;i++)res+=cnt[i];
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 896