akhauriyash/Code-Regression huggingface dataset:
n,q = map(int,input().split())
lis = [0 for i in range(n)]
li = [0 for i in range(n)]
tree = [0 for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    tree[b-1] = a-1
for i in range(q):
    c,d = map(int,input().split())
    li[c-1] += d
lis[0] = li[0]
for i in range(1,n):
    lis[i] = lis[tree[i]]+li[i]
for i in range(n):
    lis[i] = str(lis[i])
print(" ".join(lis))

Measured memory_bytes: 38832
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    if(m-2*n<=0):
        print(m//2)
        return

    ans=n
    m=m-2*n
    print(ans+m//4)
resolve()

Measured memory_bytes: 38256
#include <iostream>

using namespace std;
typedef long long ll;
#define square(x) (x)*(x)

int main(){
	int x;
	ll area = 0;
	while(cin >> x){
		area = 0;
		for(int i = 1;i*x<600;i++){
			area += square(i*x)*x;
		}
		cout << area << endl; 
	}
}

Measured memory_bytes: 3068
S = input()
T = input()

start = [-1]*26
goal = [-1]*26

temp = 0

for i in range(len(S)):
    a = ord(S[i]) - ord("a")
    b = ord(T[i]) - ord("a")

    if (b in start or a in goal):
        if (start[a] != b or goal[b] != a):
            temp = 1
            break
    else:
        start[a] = b
        goal[b] = a

if temp:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 3760
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;


class A
{
    static int n;
   
    public static void Main() {
        int[] nodes = new int[2000001];
        StringBuilder output = new StringBuilder();
        while (true) {
            string[] input = Console.ReadLine().Split(' ');
            if (input[0] == "end") {
                break;
            }
            if (input[0] == "insert") {
                Insert(nodes, int.Parse(input[1]));
            } else {
                output.AppendLine(HeapExtractMax(nodes).ToString());
            }
        }
        Console.Write(output);
    }
    public static void Insert(int[] nodes,int key) {
        n++;
        nodes[n] = int.MinValue;
        HeapIncreaseKey(nodes, n, key);
    }

    public static void HeapIncreaseKey(int[] nodes, int n, int key) {
        if (key < nodes[n]) {
            return;
        }
        nodes[n] = key;
        while (n > 1 && nodes[n / 2] < nodes[n]) {
            int temp = nodes[n];
            nodes[n] = nodes[n / 2];
            nodes[n / 2] = temp;
            n = n / 2;
        }
    }
    public static int HeapExtractMax(int[] nodes) {
        if (n < 1) {
            Console.WriteLine("HeapUnderFlow");
            return int.MinValue;
        }
        int max = nodes[1];
        nodes[1] = nodes[n];
        n--;
        Maxheapify(nodes, 1);
        return max;
    }
    public static void Maxheapify(int[] nodes, int i) {
        int left = i * 2;
        int right = i * 2 + 1;
        int largest = (left <= n && nodes[left] > nodes[i]) ? left : i;
        if (right <= n && nodes[right] > nodes[largest]) {
            largest = right;
        }
        if (largest != i) {
            int temp = nodes[i];
            nodes[i] = nodes[largest];
            nodes[largest] = temp;
            Maxheapify(nodes, largest);
        }
    }
}


Measured memory_bytes: 38608
#include<stdio.h>
int main()
{
    int n,m,l,i,j,k,table1[100][100]={},table2[100][100]={};
    long int table3[100][100]={};
    scanf("%d %d %d",&n,&m,&l);
    for(i=0; i<n; i++)
    {
        for(j=0; j<m; j++)
        {
            scanf("%d",&table1[i][j]);
        }
    }
    for(i=0; i<m; i++)
    {
        for(j=0; j<l; j++)
        {
            scanf("%d",&table2[i][j]);
        }
    }
    for(i=0; i<n; i++)
    {
        for(j=0; j<l; j++)
        {
            for(k=0; k<m; k++)
            {
                table3[i][j]+=table1[i][k]*table2[k][j];
            }
        }
    }
    for(i=0; i<n; i++)
    {
        for(j=0; j<l; j++)
        {
            if(j)
            {
                printf(" ");
            }
            printf("%li",table3[i][j]);
        }
        printf("\n");
    }
}



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

int main()
{
    char b, out;

    cin >> b;

    switch( b ){
        case 'A':
            out = 'T';
            break;

        case 'T':
            out = 'A';
            break;

        case 'C':
            out = 'G';
            break;

        case 'G':
            out = 'C';
            break;
    }

    cout << out << endl;
}


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

int main() {
    string s;
    int q;
    cin >> s >> q;
    vector<char> c1;
    c1.reserve(q + 1);
    vector<char> c2(s.begin(), s.end());
    c2.reserve(c2.size() + q + 1);
    bool reverse_mode = false;
    for(int i = 0; i < q; ++i) {
        int t;
        cin >> t;
        if(t == 1) reverse_mode = !reverse_mode;
        else {
            int f;
            char c;
            cin >> f >> c;
            if(!reverse_mode) {
                if(f == 1)  c1.push_back(c);
                else        c2.push_back(c);
            } else {
                if(f == 1)  c2.push_back(c);
                else        c1.push_back(c);
            }
        }
    }

    vector<char>* front = &c1;
    vector<char>* last = &c2;
    if(reverse_mode) {
        front = &c2;
        last = &c1;
    }

    if(front->size() > 0) {
        vector<char> f(front->rbegin(), front->rend());
        f.push_back('\0');
        cout << &(f[0]);
    }
    if(last->size() > 0) {
        last->push_back('\0');
        cout << &((*last)[0]);
    }
    cout << endl;

    return 0;
}

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

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

    if (b == "A") {
      cout << "T";
    } else if (b == "T") {
      cout << "A";
    } else if (b == "G") {
      cout << "C";
    } else if (b == "C") {
      cout << "G";
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
using namespace std;
const static int MAX_H = 500;
const static int MAX_W = 500;
bool a[MAX_H][MAX_W];

int main(){
	int H, W;
	scanf("%d %d", &H, &W);
	for (int i = 0; i < H; ++i){
		for (int j = 0; j < W; ++j){
			int tmp;
			scanf("%d", &tmp);
			a[i][j] = (bool)(tmp & 1);
		}
	}
	vector<int> X_from, Y_from, X_to, Y_to;
	for (int i = 0; i < H-1; ++i){
		for (int j = 0; j < W; ++j){
			if(a[i][j]){
				X_from.push_back(j+1);
				Y_from.push_back(i+1);
				X_to.push_back(j+1);
				Y_to.push_back(i+2);
				a[i+1][j] ^= 1;
			}
		}
	}
	for (int i = 0; i < W-1; ++i){
		if(a[H-1][i]){
			X_from.push_back(i+1);
			Y_from.push_back(H);
			X_to.push_back(i+2);
			Y_to.push_back(H);
			a[H-1][i+1] ^= 1;
		}
	}
	int N = X_from.size();
	printf("%d\n", N);
	for (int i = 0; i < N; ++i){
		printf("%d %d %d %d\n", Y_from[i], X_from[i], Y_to[i], X_to[i]);
	}
	return 0;
}

Measured memory_bytes: 4452
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n= sc.nextInt();
		int m= sc.nextInt();
		Long[][] a = new Long[n][2];
		for(int i=0;i<n;i++) {
			a[i][0]=sc.nextLong();
			a[i][1]=sc.nextLong();
		}
		
		Arrays.sort(a,(x,y)->Long.compare(x[0], y[0]));
		long l=0;
		for(int i=0;i<n;i++) {
			long k=a[i][1];
			m-=k;
			if(m>0) {
				l+=k*a[i][0];
			}else {
				l+=a[i][0]*(m+k);
				System.out.println(l);
				break;
			}
		}
    }

}


Measured memory_bytes: 99672
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 10000007;
const int inf = 1001001001;

bool ok(int a,set<int> no){
  while(a>=1){
    if(no.count(a%10)) return false;
    a/=10;
  }
  return true;
}

int main(void) {
  int n,k;
  cin >> n >> k;
  set<int> no;
  rep(i,k) {
    int a;
    cin >> a;
    no.insert(a);
  }
  rep2(i,n,100*n){
    if(ok(i,no)){
      cout << i << endl;
      return 0;
    }
  }
  
  
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;


int main() {
    int n;
    int m;

    cin >> n >> m;

    for (int i = 0; i <= n; i++) {
        for (int j = 0; i + j <= n; j++) {
            int k = n - (i + j);
            if (i + j + k == n && i * 10000 + j * 5000 + k * 1000 == m) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    
    cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>

using namespace std;

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

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

    sort(s, s + n);

    string str = "";
    for (int i = 0; i < n; i++) {
        str += s[i];
    }

    cout << str << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
  
  int n, s[100000], q, t[50000], i, left, right, mid; 
  int count = 0;

  scanf("%d", &n);
  
 for(i = 0; i < n; i++)
    
    scanf("%d", &s[i]);
 
    scanf("%d", &q);
 
  for(i = 0; i < q; i++)
    
    scanf("%d", &t[i]);
 
  for(i = 0; i < q; i++){
    
      left = 0;
    
      right = n;
 
    while(left < right){
      
       mid = (left + right)/2;
 
      if(s[mid] == t[i]){
    
         count++;
   
               break;
     
   }
 
      else if(s[mid] < t[i])
    
      left = mid + 1;
      
   else
   
        right = mid;
    }
 
  }
 
  printf("%d\n", count);
  
   return 0;

}

Measured memory_bytes: 2288
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

import math
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''
a,b,h,m=map(int, input().split())
if m!=0:
    arga=360*(h/12+m/(60*12))
    argb=360*(m/60)
else:
    arga=360*(h/12)
    argb=360

if m==0 and h==0:
    print("{:.10f}".format(float(abs(b-a))))
else:
    #print(argb-arga,arga,argb,math.cos(math.radians(abs(argb-arga))))
    #print(round(math.cos(math.radians(argb-arga)),11))
    #print(b**2+a**2,-2*a*b*round(math.cos(math.radians(argb-arga)),11))
    c=(b**2+a**2-2*a*b*round(math.cos(math.radians(argb-arga)),20))**(1/2)
    print(c)
    a=input()

Measured memory_bytes: 9532
n,k=map(int,input().split())
h=list(map(int,input().split()))
c=[0,abs(h[1]-h[0])]
for i in range(2,n):
  c.append(min(c[i-j]+abs(h[i]-h[i-j]) for j in range(1,min(k,i)+1)))
print(c[-1])

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

const ll SEG_LEN = 1LL << 20;
int seg[26][SEG_LEN * 2];


void add(int alpha, int idx, int x){
    idx += SEG_LEN;
    seg[alpha][idx] += x;
    while(1){
        idx /= 2;
        if(idx==0) break;
        seg[alpha][idx] = seg[alpha][idx*2] + seg[alpha][idx*2+1];
    }
}


int get_sum(int alpha, int l, int r){
    l += SEG_LEN;
    r += SEG_LEN;
    int ret = 0;

    while(l<r){
        if(l%2){
            ret += seg[alpha][l];
            ++l;
        }
        l /= 2;

        if(r%2){
            ret += seg[alpha][r-1];
            --r;
        }
        r /= 2;
    }
    return ret;
}

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

    ll n, q;
    string s;

    cin >> n >> s >> q;

    rep(i, n){
        add(s[i] - 'a', i+1, 1);
    }

    rep(_, q){
        int cmd;
        cin >> cmd;

        if(cmd==1){
            int idx;
            char c;
            cin >> idx >> c;

            add(c - 'a', idx, 1);
            add(s[idx-1] - 'a', idx, -1);
            s[idx-1] = c;
        }
        else{
            int l, r;
            cin >> l >> r;

            int res = 0;
            rep(alpha, 26){
                if(get_sum(alpha, l, r+1)) ++res;
            }
            cout << res << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 159644
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
 
using namespace std;

typedef long long ll;
const int mod=1e9+7;
const int INF=1<<30;

int main(){
  int N,H,W,a,b;
  cin >> H >> W >> N ;
  map<pair<int,int>,int> mp;
  rep(i,N){
    cin >> a >> b ;
    for(int y=a-1; y<=a+1; y++){
      for(int x=b-1; x<=b+1; x++){
        if((y>1 && y<H)&&(x>1 && x<W)){
          if(mp.find({x,y})==mp.end()) mp[{x,y}]=1;
          else mp[{x,y}]++;
        }
      }
    }
  }
  ll c[10],s=0;
  fill(c,c+10,0);
  for(auto itr=mp.begin();itr!=mp.end();itr++){
    c[itr->second]++;
  }
  REP(i,1,10) s+=c[i];
  c[0]=(ll)(H-2)*(W-2)-s;
  rep(i,10) cout << c[i] << endl;

  return 0;
}

Measured memory_bytes: 56448
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    long[] num = new long[N];
    long[] sub = new long[N+1];
    for(int i = 0; i < N; i++){
      num[i] = Long.parseLong(sc.next());
      sub[i+1] = num[i] + sub[i];
    }
    
    Arrays.sort(sub);
    long count = 1;
    long now = 0;
    long ans = 0;
    for(int i = 0; i <= N; i++){
      if(i == 0){
        now = sub[i];
      }else{
        if(sub[i] == now && i != N){
          count++;
        }else if(sub[i] == now){
          count++;
          ans += count*(count-1)/2;
        }else{
          ans += count*(count-1)/2;
          count = 1;
          now = sub[i];
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 62208
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import sys
import numpy as np

def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    H = list(map(int, input().split()))
    H = np.array(H)
    #dp[i]:iまでくるのに最小のコスト
    dp = np.zeros(N, dtype = int)
    for i in range(1, N):
        hi = H[i]
        dp[i] = min(dp[max(0,i-K):i] + np.abs(hi-H[max(0,i-K):i]))
    print(dp[-1])

if __name__=='__main__':
    main()


Measured memory_bytes: 22808
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define ALL(a) (a).begin(), (a).end()
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";


int main(void){
  int N;
  cin >> N;
  int F[N][10], P[N][11];
  rep(i, N) rep(j, 10) cin >> F[i][j];
  rep(i, N) rep(j, 11) cin >> P[i][j];
  int res = -(1<<30);
  //cout << res << endl;
  rep_s(b, 1, (1<<10)){
    int cc = 0;
    
    rep(i, N){
      int c = 0;
      
      rep(j, 10) {
        //cout << "b: " << (b>>j&1) << endl;
        if ((b>>j&1)&&F[i][j]) c++;
      }
      cc += P[i][c];
    }
    //cout << "cc: " << cc << endl;
    if(res<cc) res=cc;
  }
  cout << res << endl;
  
  



}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int N;
  scanf("%d", &N);
  char S[N];
  scanf("%s", S);

  char prev = "";
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (prev != S[i]) {
      ans++;
    }
    prev = S[i];
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<queue>
using namespace std;
int n, k,typ;

int main() {
	cin >> n >> k;
	for (int i = 0; i < k; i++) {
		int a, b;
		cin >> a >> b;
		if (a < n / 2) {//left
			if (b < a) typ = b % 3;//up
			else if (n - b <= a) typ = (n - b + 1) % 3;//down
			else typ = a % 3;//middle
		}
		else {//right
			if (b <= n - a)typ = b % 3;//up
			else if (b > a)typ = (n - b + 1) % 3;//down
			else typ = (n - a + 1) % 3;//middle
		}

		if (typ == 0)typ = 3;
		cout << typ << endl;
	}

	return 0;
}



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

int main() {
    int n, m, ans = 0;
    cin >> n;
    map<string, int> mp;
    rep(i, n) {
        string blue;
        cin >> blue;
        mp[blue]++;
    }
    cin >> m;
    rep(i, m) {
        string red;
        cin >> red;
        mp[red]--;
    }
    for(pair<string, int> p : mp) if(p.second > ans) ans = p.second;
    cout << ans << endl;
}

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

int A,B;

int main(){
    cin>>A>>B;
    cout<<A*B<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const long long &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
const int MOD = 1e9 + 7;
int h, w, dp[1000][1000];
char a[1000][1001];
int calc(int i, int j) {
	if(i >= h || j >= w || a[i][j] == '#') return 0;
	if(i == h - 1 && j == w - 1) return 1;
	if(dp[i][j] != -1) return dp[i][j];
	int res = 0;
	res = (res + calc(i + 1, j)) % MOD;
	res = (res + calc(i, j + 1)) % MOD;
	return dp[i][j] = res;
}
int main() {
	R(h, w);
	for(int i = 0; i < h; i++) R(a[i]);
	memset(dp, -1, sizeof(dp));
	int ans = calc(0, 0);
	W(ans);
	return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30

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

int main() {
    int h, w; cin >> h >> w;
    V<string> s(h);
    for(int i = 0; i < h; i++) cin >> s[i];


    int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(s[i][j] == '#') continue;

            int dis[h + 1][w + 1];
            memset(dis, -1, sizeof(dis));
            dis[i][j] = 0;
            queue<P<int, int> > que;
            que.push({i, j});

            while(!que.empty()){
                auto p = que.front();
                que.pop();

                int y = p.first;
                int x = p.second;
                for(int i = 0; i < 4; i++){
                    int ny = y + dy[i];
                    int nx = x + dx[i];
                    if(ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
                    if(s[ny][nx] == '#') continue;
                    if(dis[ny][nx] != -1) continue;
                    dis[ny][nx] = dis[y][x] + 1;
                    ans = max(dis[ny][nx], ans);
                    que.push({ny, nx});
                }
            }
        }
    }
    cout << ans << endl;


    return 0;
}


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

using namespace std;

typedef unsigned long long int ull;

int main() 
{
    int i;
    ull x;
    cin >> x;
    
    vector<string> v;
    char bin32_1[] = "00000000000000000000000000000000";
    char bin32_2[] = "00000000000000000000000000000000";
    char bin32_3[] = "00000000000000000000000000000000";
    char inversionBin32[] = "00000000000000000000000000000000";
    
    for(i = 31; i >= 0 && x; i--)
    {
        if(x & 1)
            bin32_1[i] = '1';
        x >>= 1;
    }
    
    v.emplace_back(bin32_1);
    
    for(i = 31; i >= 0; i--)
    {
        if(bin32_1[i] == '0')
            inversionBin32[i] = '1';
        else
            inversionBin32[i] = '0';
    }
    
    v.emplace_back(inversionBin32);
    
    for(i = 0; i <= 31; i++)
    {
        if(i == 0)
        {
            if(bin32_1[i] == '1')
                bin32_2[i] = '0';
        }
        else if(bin32_1[i] == '1')
            bin32_2[i-1] = '1';
    }
    
    v.emplace_back(bin32_2);
    
    for(i = 31; i >= 0; i--)
    {
        if(i == 31)
        {
            if(bin32_1[i] == '1')
                bin32_3[i] = '0';
        }
        else if(bin32_1[i] == '1')
            bin32_3[i+1] = '1';
    }
    
    v.emplace_back(bin32_3);
    
    for(auto y : v)
        cout << y << "\n";
    
    return 0;
}


Measured memory_bytes: 3204
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int dx[13]={1,1,1,1,1,1,1,1,1,0,0,0,0};
	int dy[13]={1,1,1,0,0,0,-1,-1,-1,1,1,1,0};
	int dz[13]={1,0,-1,1,0,-1,1,0,-1,1,0,-1,1};
	int n,m,k;
	while(cin>>n>>m>>k,n+m+k){
		vi a(k),b(k);
		rep(i,k)cin>>a[i]>>b[i];
		int in[8][8][8]={0};
		rep(i,k)a[i]--,b[i]--;
		rep(i,k){
			int t=0;
			while(in[a[i]][b[i]][t]!=0)t++;
			in[a[i]][b[i]][t]=(i%2?1:2);
			rep(j,13){
				int x=a[i],y=b[i],z=t;
				while(in[a[i]][b[i]][t]==in[x][y][z]){
					x+=dx[j];
					y+=dy[j];
					z+=dz[j];
					if(x<0||x>=n||y<0||y>=n||z<0||z>=n)break;
				}
				x-=dx[j];
				y-=dy[j];
				z-=dz[j];
				int co=0;
				while(in[a[i]][b[i]][t]==in[x][y][z]){
					x-=dx[j];
					y-=dy[j];
					z-=dz[j];
					co++;
					if(x<0||x>=n||y<0||y>=n||z<0||z>=n)break;
				}
				if(co>=m){
					cout<<(i%2?"White":"Black")<<" "<<i+1<<endl;
					goto end;
				}
			}
		}
		cout<<"Draw"<<endl;
		end:;
	}
}

Measured memory_bytes: 1200
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//ABC123D
int compare_lli(const void *a, const void *b) {
  long long *A=(long long *) a, *B=(long long *) b;
  if(*A>*B) return 1;
  if(*A<*B) return -1;
  return 0;
}

int main(void) {
  int i, j;
  long long x, y, z, k;
  scanf(" %lld %lld %lld %lld", &x, &y, &z, &k);
  long long a[x], b[y], c[z], ab[x*y];
  for(i=0; i<x; i++)
    scanf("%lld", &a[i]);
  for(i=0; i<y; i++)
    scanf("%lld", &b[i]);
  for(i=0; i<z; i++)
    scanf("%lld", &c[i]);

  for(i=0; i<x; i++){
    for(j=0; j<y; j++){
      ab[y*i+j]=a[i]+b[j];
      //printf("ab[%lld]=%lld\n", y*i+j, ab[y*i+j]);
    }
  }
  qsort(ab, x*y, sizeof(long long), compare_lli); //sort
  int absize=x*y>k ? k : x*y;
  long long abc[absize*z];
  for(i=0; i<absize; i++){
    //printf("ab[%lld]=%lld\n",x*y-i-1,ab[x*y-i-1]);
    for(j=0; j<z; j++){
      abc[z*i+j]=ab[x*y-i-1]+c[j];
      //printf("abc[%lld]=%lld\n",z*i+j,abc[z*i+j]);
    }
  }
  qsort(abc, absize*z, sizeof(long long), compare_lli); //sort

  for(i=0; i<k; i++)
    printf("%lld\n", abc[absize*z-i-1]);
}

Measured memory_bytes: 54904
#include<bits/stdc++.h>
using namespace std;
#define AC ios::sync_with_stdio(0),cin.tie(0);
#define ll long long int

string s1,s2;
const int N=3005;
int dp[N][N];
int main(){
  	AC
	cin>>s1>>s2;
	for(int i=s1.length();i>=0;--i){
        for(int j =s2.length();j>=0;--j){
            if(s1[i]==s2[j])dp[i][j]=dp[i+1][j+1]+1;
            else dp[i][j]=max(dp[i+1][j],dp[i][j+1]);
        }
    }	
    int i=0,j=0;
    
    while(i<s1.length() && j<s2.length()){
    	if(s1[i]==s2[j]){
            cout<<s1[i];
            i++,j++;
        }
        else if(dp[i][j]==dp[i+1][j]) i++;
        else j++;
	}
	cout<<endl;
}


Measured memory_bytes: 38676
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <boost/math/constants/constants.hpp>
#include <boost/math/common_factor_rt.hpp>

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

int main(){
  ll N, K;
  cin >> N >> K;
  ll h[100010];
  rep(i,N) cin >> h[i]; 
  
  ll count = 0;
  
  rep(i,N) if(h[i]>=K) count++;
    
  cout << count << endl;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	ll n, a[200000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	ll sum[200000];
	sum[0] = a[0];
	for (int i = 1; i < n; i++) {
		sum[i] = sum[i-1] + a[i];
	}

	double half = (double)sum[n-1] / 2;
	// cout << half << endl;

	double min = 2000000020;
	ll ans;
	for (int i = 0; i < n-1; i++) {
		if(abs((double)sum[i] - half) < min){
			min = abs((double)sum[i] - half);
			ans = abs(sum[i]-(sum[n-1]-sum[i]));
		}
	}

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

Measured memory_bytes: 3328
import math

N,D= [int(i) for i in input().split()]

X = N*[None]

def distance(y,z):
    s = 0
    for i in range(D):
        s+=(X[y][i]-X[z][i])**2
    return s


for i in range(N):
    x_t = [int(i) for i in input().split()]
    X[i] = x_t
ans = 0
for i in range(N):
    for j in range(i+1,N):
        a = distance(i,j)
        k = math.sqrt(a)
        if k==int(k):
            ans +=1
print(ans)

Measured memory_bytes: 3064
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
T[] readArray(T)(size_t n){auto a=new T[](n),r=readln.splitter;foreach(ref v;a){v=r.front.to!T;r.popFront;}return a;}
T[] readArrayM(T)(size_t n){auto a=new T[](n);foreach(ref v;a)v=readln.chomp.to!T;return a;}

alias graph = GraphW!(int, long, 10L ^^ 18);

void main()
{
  int n, m; readV(n, m);

  auto g = graph(n);
  foreach (_; 0..m){
    int a, b; long c; readV(a, b, c); --a; --b;
    g.addEdge(a, b, -c);
  }

  auto dist = BellmanFord!(typeof(g)).bellmanFord(g, 0), d = dist[n-1];
  if (d <= -graph.inf)
    writeln("inf");
  else
    writeln(-d);
}

struct GraphW(N = int, W = int, W i = 10^^9)
{
  import std.typecons;
  alias Node = N, Wt = W, inf = i;
  struct Edge { Node src, dst; Wt wt; }
  Node n;
  Edge[][] g;
  mixin Proxy!g;
  this(Node n) { this.n = n; g = new Edge[][](n); }
  void addEdge(Node u, Node v, Wt w) { g[u] ~= Edge(u, v, w); }
  void addEdgeB(Node u, Node v, Wt w) { g[u] ~= Edge(u, v, w); g[v] ~= Edge(v, u, w); }
}

template BellmanFord(Graph)
{
  import std.traits;
  alias Node = TemplateArgsOf!Graph[0], Wt = TemplateArgsOf!Graph[1];

  void bellmanFord(Graph g, Node s, out Wt[] dist, out Node[] prev)
  {
    auto n = g.n, sent = n;

    dist = new Wt[](n);
    dist[] = g.inf + g.inf;
    dist[s] = 0;

    prev = new Node[](n);
    prev[] = sent;

    foreach (k; 0..n)
      foreach (i; 0..n)
        foreach (e; g[i])
          if (dist[e.dst] > dist[e.src] + e.wt) {
            dist[e.dst] = dist[e.src] + e.wt;
            prev[e.dst] = e.src;
            if (k == n-1) dist[e.dst] = -g.inf;
          }
  }

  Wt[] bellmanFord(Graph g, Node s)
  {
    Wt[] dist;
    Node[] prev;
    bellmanFord(g, s, dist, prev);
    return dist;
  }
}


Measured memory_bytes: 380
import numpy as np
N=int(input())
#N以下の正の整数の文字列を生成



list_a=np.arange(1, N+1)
list_b =[]


#print(list_a)
#print(len(str(list_a)))

for i in list_a:
    if  len(str(i))%2 !=0:
        #print(i)
        list_b.append(i)

print(len(list_b))

Measured memory_bytes: 16436
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
using tii = tuple<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
//#define INF (ll)1E9
#define INF INT_MAX
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

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

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

int main() {
	//cin.tie(0); ios::sync_with_stdio(false);
	string s;
	int n;
	cin >> s >> n;
	int i = 0;
	while(i<s.size()) {
		cout<<s[i];
		i += n;
	}
	cout << endl;
}

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

int main(){
    ll n, s=0;
    cin >> n;
    vector<ll> a(n);
    rep(i, n){
        cin >> a.at(i);
        s+=a.at(i);
    }

    ll oddsum = 0;
    for(int i=1;i<n;i+=2){
        oddsum+=a.at(i);
    }
    ll x = s - 2*oddsum;
    cout << x;
    for(int i=1;i<n;i++){
        x = 2*a.at(i-1) -x;
        cout << ' '<< x;
    }

    return 0;
}

Measured memory_bytes: 2048
#include<string>
#include<vector>
#include<cctype>
#include<cmath>
#include<iostream>
#include<map>
using namespace std;

int main(){
    int num1, num2, num3;
    cin >> num1 >> num2 >> num3;
    bool eq1=false, eq2=false, eq3=false;
    if(num1==num2)
        eq1 = true;
    if(num1==num3)
        eq2 = true;
    if(num3==num2)
        eq3 = true;
    if(eq1||eq2||eq3){
        if(eq1&&eq2&&eq3)
            cout << "No" << endl;
        else
            cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    T, A = map(int, input().split())
    i = sorted(list((abs(T - A - x*0.006),i) for i, x in enumerate(map(int, input().split()), start=1)))[0][1]
    return str(i)
    
if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 3188
def main(N, K, P):
    sorted_P = sorted(P)
    ans = sum(sorted_P[:K%N]) + sum(P)*(K//N)
    return ans

if __name__ == '__main__':
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    ans = main(N, K, P)
    print(ans)



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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  map<char,map<char,int>> mp;
  for (int i = 1; i <= n; ++i) {
    string s = to_string(i);
    ++mp[s[0]][s.back()];
  }
  long long res = 0;
  for (int i = 1; i <= n; ++i) {
    string s = to_string(i);
    res += mp[s.back()][s[0]];
  }
  cout << res << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,x1,y,y1,ans1,ans2,ans;
	cin>>x>>x1>>y>>y1;
	x+=x1;
	y+=y1;
	if(x>y)
	{
		cout<<"Left"<<endl;
		return 0;
	}
	if(x<y)
	{
		cout<<"Right"<<endl;
		return 0;
	}
	if(x==y)
	{
		cout<<"Balanced"<<endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
A=[input()for i in range(H)]
for i in range(H):
    A[i]=A[i]+"."
A.append("."*(W+1))
p,q=1,1
c=1
t=0
for i in A:
    t+=i.count("#")
if t!=H+W-1:
    c=0
for i in range(H+W-2):
    if A[p-1][q-1]==".":
        c=0
        break
    if A[p][q-1]=="." and A[p-1][q]=="#":
        q+=1
    elif A[p][q-1]=="#" and A[p-1][q]==".":
        p+=1
    else:
        c=0
        break
print("Possible" if c else "Impossible")

Measured memory_bytes: 9164
#include<iostream>
using namespace std;
int main()
{
	int a[100000], b[100000];
	int i,j,r,d;
	for (i = 0; i < 98000; i++){
		cin >> a[i] >> b[i];
		if (a[i] == 0 && b[i] == 0){
			j = i;
			break;
		}
	}
	for (i = 0; i < j; i++){
		for (r=0;r<a[i];r++){
			for (d=0;d<b[i];d++){
				if (r == 0 || r == a[i] - 1){
					cout << "#";
				}
				else if (d == 0 || d == b[i] - 1){
					cout << "#";
				}
				else{
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3100
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    bool  flag=false,can=true;
    ll now=LLINF;
    map<ll,ll> mp;
    cin>>s;
    if(s.size()!=26){
        rep(i,(ll)s.size()){
            mp[s[i]-'a']++;
            if(mp[s[i]-'a']==2){
                now=i;
                if(s[i]=='z'  && i==1){
                    flag=true;
                }
                else if(s[i]=='z') now--;
                break;
            }
        }
        if(flag){
            cout<<-1<<endl;
            return 0;
        }
        if(now==LLINF){
            cout<<s;
            rep(i,26){
                if(mp[i]==0){
                    cout<<(char)('a'+i)<<endl;
                    break;
                }
            }
        } else{
            rep(i,now){
            cout<<s[i];
            }
            rep2(i,s[now]-'a',26){
                if(mp[i]==0){
                cout<<(char)('a'+i)<<endl;
                    break;
                }
            }
        }
    }

    if(s.size()==26){
        for(ll  i=25;i>=1;i--){
            if((s[i]-'a')>(s[i-1]-'a')){
                now=i-1;
                break;
            }
        }
        if(now==LLINF){
            cout<<-1<<endl;
            return 0;
        }
        rep(i,now){
            mp[s[i]-'a']++;
            if(mp[s[i]-'a']==2){
                now=i;
                can=false;
                break;
            }
        }
        if(!can){
            rep(i,now){
                cout<<s[i];
            }
            rep2(i,s[now]-'a',26){
                if(mp[i]==0){
                    cout<<(char)('a'+i)<<endl;
                    break;
                }
            }
            return 0;
        }
        rep(i,now){
            cout<<s[i];
        }
        rep2(i,s[now]-'a'+1,26){
            if(mp[i]==0){
                cout<<(char)('a'+i)<<endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  long long n,m,i,j,s;
  scanf("%lld %lld",&n,&m);
  if(n==m){
    printf("%lld\n",n+1);
    return 0;
  }
  for(i=2;i*i<=n;i++){
    s=0;
    for(j=n;j;j/=i)s+=j%i;
    if(s==m){
      printf("%lld\n",i);
      return 0;
    }
  }
  if((i-1)*(i-1)==n)i--;
  for(i--;i;i--){
    j=n/(i+1)+1;
    s=n/j+n%j;
    if(m>s)continue;
    if((s-m)%i==0&&s-m<=n%j&&j+(s-m)/i-1){
      printf("%lld\n",j+(s-m)/i);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/*-----------------------*/
#define FAST        ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
#define endl        "\n"
#define ff          first
#define ss          second
#define cc(x)       cout<<#x<<"="<<x<<" ";
#define CC(x)       for(auto xx: x) cout<<xx<<" ";
#define ee          cout<<"\n";
#define ll          long long
#define ull         unsigned long long
#define pii         pair<int,int>
#define mp          make_pair
#define all(x)      x.begin(),x.end()
#define ps(x)       push(x)
#define psb(x)      push_back(x)
#define psf(x)      push_front(x)
#define pp          pop()
#define ppb         pop_back()
#define ppf         pop_front()
#define OK          cout<<"Ok"<<"\n";
#define TESTS       ll test;cin>>test;for(ll   tcase=1;tcase<=test;tcase++)
/*------------------------*/
#define MAX int(2e6+9)



int main()
{
    FAST
    vector <int> v(3);
    for(int &x : v) cin>>x;
    sort(all(v));
    if((v[0]==v[1] and v[2]!=v[1]) || (v[1]==v[2] and v[1]!=v[0])) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;






    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
dp = []
train = []

def subq(l, r):
    global dp, train
    if l == 0 or r == 0:
        return 0
    else:
        tmp1 = dp[l][r]
        if tmp1 != -1:
            return tmp1
        else:
            tmp2 = train[l][r] + subq(l - 1, r) + subq(l, r - 1) -  subq(l - 1, r - 1)
            dp[l][r] = tmp2
            return tmp2

def main():
    global dp, train
    n, m, qn = map(int, input().split())
    dp = [[-1] * (n+1) for _ in range(n+1)]
    train = [[0] * (n+1) for _ in range(n+1)]
    for _ in range(m):
        l, r = map(int, input().split())
        train[int(l)][int(r)] += 1

    for _ in range(qn):
        p, q = map(int, input().split())
        r = subq(q, q) - subq(p-1, q) - subq(q, p-1) + subq(p-1, p-1)
        print(r)

if __name__ == '__main__':
    main()


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

int main()
{
	int N;
	cin >> N;
	vector<long long> A( N );
	for( int i = 0; i < N; i++ ) {
		cin >> A[i];
	}

	sort( A.begin(), A.end(), greater<long long>() );
	long long ma[2] = {0};
	int j = 0;
	for( int i = 0; i < N - 1; i++ ) {
		if( A[i] == A[i + 1] ) {
			ma[j] = A[i];
			i++;
			j++;
			if( j >= 2 ) break;
		}
	}
	long long ans = ma[0] * ma[1];

	cout << ans << endl;
}


Measured memory_bytes: 4056
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,ans=0;
  cin >> N;
  
  vector<int> v(N-1);
  for(int i=0; i < N-1; i++){
    cin >> v.at(i);
  }
  
  ans += v.at(0);
  for(int i=0; i < N-2; i++){
    ans += min(v.at(i),v.at(i+1));
  }
  ans += v.at(N-2);
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline


def main():
    N, Q = map(int, input().split())
    con = [[] for i in range(N)]
    ops = []
    ans = [0] * N

    for _ in range(N - 1):
        a, b = map(int, input().split())
        con[a - 1].append(b - 1)
        con[b - 1].append(a - 1)
    for _ in range(Q):
        ops.append(tuple(map(int, input().split())))

    for op in ops:
        node = op[0] - 1
        pnt = op[1]
        ans[node] += pnt

    stacks = deque()
    stacks.append((0, -1))

    while stacks:
        stack = stacks.pop()
        node, parent = stack[0], stack[1]

        children = con[node]
        for child in children:
            if child == parent:
                continue
            ans[child] += ans[node]
            stacks.append((child, node))

    print(*ans)


if __name__ == '__main__':
    main()


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

int main(){
	ios::sync_with_stdio(0);
	cout << setprecision(10) << fixed;
	int n, q;
	string s;
	cin >> n >> s >> q;
	set<int> cnt[26];
	for (int i = 0; i < 26; ++i){
		cnt[i].insert(1e9 + 1);
	}
	for (int i = 0; i < n; ++i){
		cnt[s[i] - 'a'].insert(i);
	}
	while (q--){
		int t;
		cin >> t;
		if (t == 1){
			int i;
			char c;
			cin >> i >> c;
			i--;
			cnt[s[i] - 'a'].erase(i);
			cnt[c - 'a'].insert(i);
			s[i] = c;
		}
		else{
			int l, r;
			cin >> l >> r;
			l--, r--;
			int ans = 0;
			for (int i = 0; i < 26; ++i){
				if (cnt[i].size() == 0){
					continue;
				}
				int now = *cnt[i].lower_bound(l);

				if (now >= l && now <= r){
					ans++;
				}
			}
			cout << ans << "\n";
		}
	}
	return 0;
}



Measured memory_bytes: 24220
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
	int n,k;
	cin>>n>>k;
	int ans=114514;
	for(int i=0;i<n;i++){
	    int a,b;
	    cin>>a>>b;
	    if(b<=k&&a<ans){
	        ans=a;
	    }
	}
	if(ans==114514){
	    cout<<"TLE"<<endl;
	}
	else{
	    cout<<ans<<endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int main(){
    int a, b;
    while(cin >> a >> b,a||b){
        int ans = 0;
        range(i,1,a+1){
            range(j,i + 1,a+1){
                range(k,j + 1,a+1){
                    if(i + j + k == b) ans++;
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1164
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    String s = sc.next();
    String hundreds = s.substring(0, 1);
    String tens = s.substring(1, 2);
    String ones = s.substring(2, 3);
    
    String reverseOfS = ones + tens + hundreds;
    
    if (s.equals(reverseOfS)) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21588
def comb(n, k):
    nu, de = 1, 1
    for i in range(k):
        de *= n - i
        nu *= i + 1
    return de // nu


def ans(N, K):
    if K == 0:
        return 1
    N = str(int(N))
    if len(N) < K or int(N) == 0:
        return 0
    ret = sum([9 ** K * comb(max(dig - 1, 1), K - 1)
               for dig in range(K, len(N))])
    ret += (int(N[0]) - 1) * 9 ** (K - 1) * comb(len(N) - 1, K - 1)
    return ret + ans(N[1:], K - 1)


N = input()
K = int(input())
print(ans(N, K))


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

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector< vector<ll> > d(n,  vector<ll>(n));
    vector< vector<ll> > G(n,  vector<ll>(n));
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            cin >> d[i][j];
            G[i][j] = d[i][j];
        }
    }
    vector< vector<ll> > F;
    F = d;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            for (int k = 0; k < n; ++k)
                if (F[j][i] + F[i][k] < F[j][k])
                    F[j][k] = F[j][i] + F[i][k];
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if (F[i][j] != d[i][j])
            {
                cout << "-1";
                return 0;
            }
        }
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            for (int k = 0; k < n; ++k)
            {
                if (i != j && j != k && i != k && d[j][i] + d[i][k] <= d[j][k])
                {
                    G[j][k] = -1;
                    G[k][j] = -1;
                }
            }
        }
    }
    ll s = 0;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            if (G[i][j] != -1)
                s += G[i][j];
    cout << s / 2;
    return 0;
}


Measured memory_bytes: 2432
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

class UFT {
private:
  vi data, rnk, _size;

public:
  UFT(const int &n)
    : data(n), rnk(n), _size(n, 1) {
    iota(all(data), 0);
  }

  int root(const int &x) {
    return data[x] == x ? x : data[x] = root(data[x]);
  }

  bool same(const int &a, const int &b) {
    return root(a) == root(b);
  }

  void unite(int a, int b) {
    a = root(a), b = root(b);
    if (a == b) return;
    if (rnk[a] < rnk[b]) swap(a, b);
    data[b] = a;
    _size[a] += _size[b];
    if (rnk[a] == rnk[b]) rnk[a]++;
  }

  int size(int x) {
    return _size[root(x)];
  }
};

void solve() {
  int n, k;
  cin >> n >> k;
  UFT uf(n);
  while (k--) {
    int m;
    cin >> m;
    vi v(m);
    rep(i, m) {
      cin >> v[i];
      --v[i];
    }
    loop(i, 1, m) uf.unite(v.front(), v[i]);
  }
  int r;
  cin >> r;
  set<int> s;
  while (r--) {
    int p, q;
    cin >> p >> q;
    --p, --q;
    if (uf.same(p, q)) s.insert(p), s.insert(q);
  }
  cout << s.size() << endl;
}

Measured memory_bytes: 3080