akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	m := make(map[int]int)
	for x := 1; x <= 100; x++ {
		for y := 1; y <= 100; y++ {
			for z := 1; z <= 100; z++ {
				r := x*x + y*y + z*z + x*y + y*z + z*x
				if r <= n {
					m[r]++
				}
			}
		}
	}
	for i := 1; i <= n; i++ {
		if cnt, ok := m[i]; ok {
			fmt.Println(cnt)
		} else {
			fmt.Println(0)
		}
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 2692
#include<iostream>
#include <math.h> 
using namespace std;

int main()
{
	int n;
	int b[200];
	int ans = 0;

	cin >> n;
	for (int i = 1; i < n; i++) {
		cin >> b[i];
	}
	b[n] = 100000;
	b[0] = 100000;

	for (int i = 0; i < n; i++) {
		if (b[i] < b[i + 1]) {
			ans = ans + b[i];
		}
		else {
			ans = ans + b[i + 1];
		}
	}
	cout << ans;
}

Measured memory_bytes: 888
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;

int main() {
	int n, m;
	while(cin >> n >> m, n|m) {
		int t[n], h[m];
		int sum_t = 0, sum_h = 0;
		for(int i=0; i<n; i++) {
			cin >> t[i];
			sum_t += t[i];
		}
		for(int i=0; i<m; i++) {
			cin >> h[i];
			sum_h += h[i];
		}

		int t2[n], h2[m];
		for(int i=0; i<n; i++)
			t2[i] = sum_t - t[i];
		for(int i=0; i<m; i++)
			h2[i] = sum_h - h[i];

		int cnt = 1000 * 10000;
		int taro = 0, hana = 0;

		for(int i=0; i<n; i++) {
			for(int j=0; j<m; j++) {
				if(t2[i] + h[j] == h2[j] + t[i]) {
					int just = t2[i] + h[j];
					if(cnt > just) {
						cnt = just;
						taro = t[i];
			 			hana = h[j];
					}
				}
			}
		}

		if(taro || hana)
			cout << taro << ' ' << hana << endl;
		else
			cout << "-1"  << endl;
	}


	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int p = 0;
  for (int i =0; i < N; i ++) {
    string S;
    cin >> S;
    if (S == "Y") {
      cout << "Four" << endl;
      break;
    }
    p ++;
  }
  if (p == N) {
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
while 1:
    try:
        s=input()
        ans=0
        for i in range(len(s)-1):
            if s[i]=="M":ans+=1000
            elif s[i]=="D":
                if s[i+1]=="M":ans-=500
                else:ans+=500
            elif s[i]=="C":
                if s[i+1]=="M" or s[i+1]=="D":ans-=100
                else:ans+=100
            elif s[i]=="L":
                if s[i+1]=="M" or s[i+1]=="D" or s[i+1]=="C":ans-=50
                else:ans+=50
            elif s[i]=="X":
                if s[i+1]=="M" or s[i+1]=="D" or s[i+1]=="C" or s[i+1]=="L":ans-=10
                else:ans+=10
            elif s[i]=="V":
                if s[i+1]=="M" or s[i+1]=="D" or s[i+1]=="C" or s[i+1]=="L" or s[i+1]=="X":ans-=5
                else:ans+=5
            elif s[i]=="I":
                if s[i+1]=="M" or s[i+1]=="D" or s[i+1]=="C" or s[i+1]=="L" or s[i+1]=="X" or s[i+1]=="V":ans-=1
                else:ans+=1
        if s[-1]=="M":ans+=1000
        elif s[-1]=="D":ans+=500
        elif s[-1]=="C":ans+=100
        elif s[-1]=="L":ans+=50
        elif s[-1]=="X":ans+=10
        elif s[-1]=="V":ans+=5
        elif s[-1]=="I":ans+=1
        print(ans)
    except:break


Measured memory_bytes: 5580
#include<bits/stdc++.h>
#define ll long long int
#define INF 0x3f3f3f3f
#define pb push_back
#define se second
#define fi first
using namespace std;
string str;
int n;

bool Contains(string temp,char ch){
    bool ret=false;
    for(int i=0;i<temp.size();i++){
        if(temp[i]==ch) ret=true;
    }
    return ret;
}

bool check(string temp){
    for(int i=0;i<temp.size()-1;i++){
        if(temp[i]!=temp[i+1]) return false;
    }
    return true;
}

int f(char ch){
    string temp=str;
    
    if(!Contains(temp,ch)) return INF;
    int ret=0;
    while(check(temp)!=1){
        ret++;
        string temp2="";
        for(int i=0;i<temp.size()-1;i++){
            if(temp[i]!=ch and temp[i+1]==ch){
                temp[i]=ch;
            }
        }
        for(int i=0;i<temp.size()-1;i++) temp2+=temp[i];
        temp=temp2;
    }
    return ret;
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
    cin>>str;
    n=str.length();
    int ans=n;
    for(char ch='a';ch<='z';ch++){
        ans=min(ans,f(ch));
    }
    cout<<ans<<endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int audience = 0;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    audience += b - a + 1;
  }
  cout << audience << endl;
}


Measured memory_bytes: 256
(defun f(line)
  (labels ((rec (i acc)
                (if (< i (- (length line) 2))
                  (if (and (char= (char line i) #\A)
                           (char= (char line (1+ i)) #\B)
                           (char= (char line (+ i 2)) #\C))
                    (rec (1+ i) (1+ acc))
                    (rec (1+ i) acc))
                  acc)))
    (rec 0 0)))
(let* ((line0 (read-line nil nil))
       (line (read-line nil nil)))
  (format t "~A~%" (f line)))


Measured memory_bytes: 13152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;


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

    ll ans = 0;
    for(int i=0; i<n; i++){
        ans += (a[i] - 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    string s;
    cin >> s;
    ll K;
    cin >> K;
    for(ll i = 0; i < s.size(); i++){
        if(s[i] == '1'){
            K--;
            if(K == 0){
                cout << 1 << endl;
                return 0;
            }
        }
        else{
            cout << s[i] << endl;
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
"""
ビット演算, XOR

XORは桁ごとに独立して計算できるので、桁ごとに計算する
XORが1になるのは0と1を足した時。2つの数を足す時、一方の数のi桁目が1でもう一方の数のi桁目が0であれば、2つの数を足した時のi桁目が1になる
全部で数がn個あるとき、i桁目が1の数がx個ある場合は、i桁目が0の数がn-x個あることになるので、x*(n-x)個の組み合わせでi桁目のXORが1になる
"""

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

MOD = 10**9+7
ans = 0

for i in range(60):
    x = 0 # i桁目が1である数の個数
    for j in range(n):
        if a[j]>>i&1: # "a[j]のi桁目が1である"という意味
            x += 1
    now = x*(n-x)%MOD
    for j in range(i):
        now = now*2%MOD # 2**60をかけると容易にオーバーフローするので、安全に2をかけるごとにMODをとっている
    ans += now
    ans %= MOD
    
print(ans)

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

int main(){
   long long N;
   cin >> N;
    int f = 100;
    int s;
   for(long long i = 1; i <= 100000; i++) {
       s = 0; 
       long long it;
       
       if(N % i == 0) {
        if(N / i >= i)
        it = N / i;
        else if(N / i < i)
        it = i;
        
       while(it > 0) {
           it /= 10;
           s++;
       }
        if(f > s) f = s;
       }  
   }

   cout << f;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N){
  std::cout << N*N*N << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  solve(N);
  return 0;
}



Measured memory_bytes: 256
from math import sqrt
from math import ceil
x = int(raw_input())

def eq(x):
    a1 = (-1 + sqrt(1-4*(-2*x)))/2
    a2 = (-1 - sqrt(1-4*(-2*x)))/2
    if a1 >= 0 and a2 >= 0:
        return int(ceil(min(a1, a2)))
    elif a1 >= 0 and a2 < 0:
        return int(ceil(a1))
    return int(ceil(a2))
n = eq(x)
for n in range(n, -1, -1):
    if n*(n+1) - 2*x < 0:
        break
print n + 1

Measured memory_bytes: 3972
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = 2000005;
const int K = 50;
set < int > g1[N], g2[N];
int s1[N], s2[N], a[N], b[N], x[N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n, m;
        srand(time(NULL));
        cin >> n >> m;
 //   n = rand() % 300 + 1;
  //  m = rand() % 300 + 1;
  //  cout << n << " " << m << endl;
    for (int i = 1; i <= n; i++){
       // a[i] = rand() % m;
        cin >> a[i];
        a[i]--;
    }
    x[1] = a[1];
    for (int i = 2; i <= n; i++){
        int y;
        if (a[i] > a[i - 1]) y = a[i] - a[i - 1]; else
        y = m - (a[i - 1] - a[i]);
        x[i] = x[i - 1] + y;
    }
    int res = 1e9;
    for (int i = 0; i < 0; i++){
        int y = 0;
        for (int j = 2; j <= n; j++){
            if (a[j] > a[j - 1]){
                if (i > a[j - 1] && i <= a[j]){
                    y = y + a[j] - i + 1;
                } else y = y + a[j] - a[j - 1];
            } else{
                if (i > a[j - 1] || i <= a[j]){
                    if (i > a[j - 1]){
                        y = y + a[j] + m - i + 1;
                    } else{
                        y = y + a[j] - i + 1;
                    }
                } else y = y + m - (a[j - 1] - a[j]);
            }
        }
        res = min(res, y);
    }

   // cout << endl;
    for (int i = 2; i <= n; i++){
        if (x[i] - x[i - 1] == 1 || m == 2) continue;
        int l, r;
        if (x[i] % m > x[i - 1] % m){
            l = x[i - 1] % m + 2;
            r = x[i] % m;
        } else{
            l = x[i - 1] % m + 2;
            r = x[i] % m + m;
        }
        s1[l]++;
        s1[r + 1]--;
        int d = r - l + 1;
       // cout << d <<  endl;
        s1[r + 1] += (-d);
        s1[r + 2] += d;
    }
    int xx = 0;
    for (int i = 0; i <= m + m + m; i++){
        xx += s1[i];
        s2[i] = xx;
    }
  //  cout << xx << endl;
    xx = 0;
    int ans = 0;
    for (int i = 0; i <= m + m + m; i++){
        xx += s2[i];
        b[i] = xx;
    }
   // cout << xx << endl;
    for (int i = 0; i < m; i++){
        ans = max(ans, b[i] + b[i + m] + b[i + m + m]);
    }
   // cout << ans << endl;
    cout << x[n] - x[1] - ans;
  //  if (x[n] - x[1] - ans != res){
     //   cout << n << " " << m << endl;
  //  }
}


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

int imos[100005]={0};

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;++i){
        int a, b;
        cin >> a >> b;
        imos[a]++;
        imos[b+1]--;
    }
    imos[0]++;
    int acc = 0, maxi = 0;
    for(int i=0;i<=100001;++i){
        acc += imos[i];
        if(acc >= i)maxi = max(maxi, min(i, acc));
    }

    cout << maxi - 1 << endl;

    return 0;
}



Measured memory_bytes: 3472
#include <iostream>

using namespace std;

const int MAX_N = 2e5 + 5;

typedef long long ll;

ll ways (ll x) {
  return (x * (x - 1)) / 2;
}

int arr [MAX_N];
ll cnt [MAX_N];

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

  for (int i = 1; i <= n; i++) {
    cin >> arr[i];

    cnt[arr[i]]++;
  }

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += ways(cnt[i]);
  }
  //  cerr << ans << endl;
  
  for (int i = 1; i <= n; i++) {
    cout << ans - ways(cnt[arr[i]]) + ways(cnt[arr[i]] - 1) << "\n";
  }
}


Measured memory_bytes: 3968
#include <iostream>

using namespace std;

int main() {
    int n;
    string s;
    cin >> n >> s;
    int count = 0;
    for(int i = 0; i < 1000; i++) {
        int j = 0;
        int x = i/100;
        int y = i/10%10;
        int z = i%10;
        int nums[3];
        nums[0] = x;
        nums[1] = y;
        nums[2] = z;
        for(int k = 0; k < n;k++) {
            if(nums[j] == s[k] - '0') {
                j++;
                if(j == 3){
                    count++;
                    break;
                }
            }
        }
    }
    cout << count << endl;
}


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

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

  }
   return 0;
  }


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  ll h,w;
  cin>>h>>w;
  vstr s(h);
  for(int i=0;i<h;i++){
    cin>>s[i];
  }
  vector<vector<char>> ans(h,vector<char>(w));
  rep(i,h){
    rep(j,w){
      if(s[i][j]=='#') ans[i][j]='#';
      else{
      ll k=0;
      if(i-1>=0&&j-1>=0){
        if(s[i-1][j-1]=='#') k++;
      }
      if(i-1>=0){
        if(s[i-1][j]=='#') k++;
      }
      if(i-1>=0&&j+1<w){
        if(s[i-1][j+1]=='#') k++;
      }
      if(j-1>=0){
        if(s[i][j-1]=='#') k++;
      }
      if(j+1<w){
        if(s[i][j+1]=='#') k++;
      }
      if(i+1<h&&j-1>=0){
        if(s[i+1][j-1]=='#') k++;
      }
      if(i+1<h){
        if(s[i+1][j]=='#') k++;
      }
      if(i+1<h&&j+1<w){
        if(s[i+1][j+1]=='#') k++;
      }
      ans[i][j]=(char)('0'+k);
    }
  }
  }
  rep(i,h){
    rep(j,w){
      cout<<ans[i][j];
    }
    cout<<endl;
  }
}
    

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
typedef vector<lint> LIV;
#define rep(i,n) for(int i=0;i<n;++i)
#define MAXN 100010
#define MAXM 1100000
#define all(v) v.begin(),v.end()
#define inf 2147483647
#define linf 1152921504606846976

int main(){
	lint a,b,c;cin>>a>>b>>c;
	c=min(c,a+b+1);
	cout<<b+c<<endl;
}

//int main(){//平方数を1<k<=nで割ったあまりを求める
//	lint n;cin>>n;
//	LIV ans(n);
//	for(int i=1;i<=n;++i){
//		set<int> s;
//		rep(x,i)s.insert(x*x%i);
//		cout<<i<<": ";
//		for(auto x:s)cout<<x<<",";cout<<endl;
//		ans[i-1]=s.size();
//	}rep(i,n)cout<<ans[i]<<endl;
//	getchar();
//	getchar();
//}

//sub-EOF


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String S = sc.next();
		// スペース区切りの整数の入力
		char sa[] = new char[S.length()];
		int counter = 0;
		for(int i=0; i<S.length(); i++){
			sa[i] = S.charAt(i);
			if(i > 0){
				if(sa[i] == sa[i-1]){
					counter = counter;
				}
				else{
					counter = counter + 1;
				}
			}
		}
		System.out.println(counter);
}
}


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

int main() {
  int count=1;
  string s;
  cin >> s;

 if (s.at(0) == 'R' && s.at(1) == 'R' && s.at(2) == 'R') 
   count = 3;

  if (s.at(0) == 'S' && s.at(1) == 'S' && s.at(2) == 'S') 
   count = 0;
  
  if (s.at(0) == 'R' && s.at(1) == 'R' && s.at(2) == 'S') 
   count = 2;
  
  if (s.at(0) == 'S' && s.at(1) == 'R' && s.at(2) == 'R') 
count = 2;
 


  cout << count << endl;
}





Measured memory_bytes: 3596
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i=0; i<n; i++) {
            list.add(sc.nextInt());
        }
        List<Integer> list2 = new ArrayList<>();
        list2.addAll(list);
        Collections.sort(list2);
        Collections.reverse(list2);
        int max = list2.get(0);
        int max2 = list2.get(1);
        for(int i=0; i<n; i++) {
            if(list.get(i) == max) System.out.println(max2);
            else System.out.println(max);
        }
    }
}

Measured memory_bytes: 66336
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define N 1046527

using namespace std;
char hs[N][14];

int dd(char d){
	switch(d){
		case 'A':
		return 1;

		case 'C':
		return 2;
		
		case 'T':
		return 3;
		
		case 'G':
		return 4;
	}
	return 0;
}

int ids(char *c){
	int id = 0;
	int pos = 0, p =1;
	while(1){

		if(c[pos] == '\0') break;
		id += p*dd(c[pos]);
		pos++;
		p *= 5;
	}
	return id;
}

int h1(int key){
	return key%N;
}
int h2(int key){
	return 1+key%(N-1);
}
int h(int key, int i){
	return (h1(key)+i*h2(key))%N;
}

void insert(char *c){
	int i=0;
	int key = ids(c);
	while(true){
		int j = h(key, i);
		if(hs[j][0] == '?'){
			strcpy(hs[j], c);
			return;
		}
		i = i+1;
	}
}

bool search(char* c){
	int i=0;
	int key = ids(c);
	while(true){
		int j = h(key, i);
		if( strcmp(hs[j], c) == 0 ){
			return true;
		} else if( hs[j][0]=='?' || i>=N){
			return false;
		}
		i = i+1;
	}
}


int main(){
	int n;
	scanf("%d", &n);
	for(int i=0;i<N;i++) hs[i][0] = '?';
	char in[9];
	char inn[14];
	for(int i=0;i<n;i++){
		scanf(" %s %s", in, inn);
		if(in[0] == 'i'){
			insert(inn);
		} else {
			if(search(inn)){
				printf("yes\n");
			} else {
				printf("no\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 15340
#include <bits/stdc++.h>
#define MAX 100005
using namespace std;

const int inf = 2147483647;
int n, k, h[MAX], dp[MAX];

int main()
{
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    cin>>n>>k;

    for(int i = 0; i < n; i++){
        cin>>h[i];
    }
    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);
    for(int i = 2; i < n; i++){
        int x = min(i, k);
        dp[i] = inf;
        for(int j = 1; j <= x; j++){
            dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
        }
    }

    cout<<dp[n-1]<<endl;

    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ABC053A
{
    class Program
    {
        static void Main(string[] args)
        {
            int x=int.Parse(Console.ReadLine());
            string s;
            if ( 1<=x && x<1200)
            {
                s = "ABC";
            }
            else
            {
                s = "ARC";
            }
            Console.WriteLine(s);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
import sys
import queue

input = sys.stdin.readline

N, Q = map(int, input().split())

node = [0] * (N+1)
nxt = [[] for _ in range(N+1)]

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

for _ in range(Q):
    p,x = map(int, input().split())
    node[p] += x

visited = [False] * (N+1)
q = queue.Queue()
q.put(1)
while not q.empty():
    v = q.get()
    visited[v] = True
    for nv in nxt[v]:
        if not visited[nv]:
            node[nv] += node[v]
            q.put(nv)

for i in range(1, N+1):
    print(node[i], end=' ')
print()


Measured memory_bytes: 97736
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define clt(x) 63-__builtin_clzll(x)
#define bct(x) __builtin_popcountll(x)
#define all(v) (v).begin(),(v).end()
#define pi pair<ll,ll>
#define vi vector<ll>
#define vpi vector<pair<ll,ll>>
#define maxq priority_queue<ll>
#define minq priority_queue<ll,vector<ll>, greater<ll>>
#define cont continue;
#define reto return 0;
#define sz size()
#define spmod 1116295198451
#define mod 1000000007
#define md 998244353 
#define N 2e5+10
//typedef tree<int,null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> //pbds;


int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ll n,x,t;
  cin>>n>>x>>t;
  ll sum=0,m=0;
  while(sum<n)
  {
    sum+=x;
    m+=t;
  }
  deb(m)
}

Measured memory_bytes: 3636
s = input()
q_num = int(input())
for _ in range(q_num):
    q = input().split()
    a = int(q[1])
    b = int(q[2])
    if q[0] == "print":
        print(s[a:b+1])
    elif q[0] == "reverse":
        s_re = s[a:b+1]
        s = s[:a:]+s_re[::-1]+s[b+1::]
    elif q[0] == "replace":
        s = s[:a:]+q[3]+s[b+1::]


Measured memory_bytes: 5612
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  ll A, B, C, K;
  cin >> A >> B >> C >> K;
  
  if (K % 2 == 0) {
    cout << A - B << '\n';
  } else {
    cout << B - A << '\n';
  }
  
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int> alp(26, 0);
string s;
int main() {
    cin >> s;
    int slen = s.length();
    for(int i = 0; i < slen; ++i) {
        alp.at(s.at(i) - 97)++;
    }

    string ans;

    if(slen != 26) {
        char target;
        for(int i = 0; i < 26; ++i) {
            if(alp.at(i) == 0) {
                target = i+97;
                break;
            }
        }
        ans = s + target;
        cout << ans << endl;
    }else {
        int sub = -1;
        for(int i = 25; i >= 1; --i) {
            if(s.at(i) > s.at(i-1)) {
                sub = i;
                break;
            }
        }
        if(sub == -1) {
            cout << -1 << endl;
        }else {
            string cmp;
            cmp = s.substr(sub);
            sort(cmp.begin(), cmp.end());
            char last = s.at(sub-1);
            int cmplen = cmp.length();
            char chg;
            for(int i = 0; i < cmplen; ++i) {
                if(last < cmp.at(i)) {
                    chg = cmp.at(i);
                    break;
                }
            }
            ans = s.substr(0, sub-1) + chg;
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int count=0;
    int n;
    int p[30];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    for(int j=1;j<n-1;j++){
        if(p[j-1]<p[j]&&p[j]<p[j+1]){
            count++;
        }else if(p[j+1]<p[j]&&p[j]<p[j-1]){
            count++;
        }else{
            
        }
    }
    cout<<count;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n,k,i,j,p=1000000007,temp=0,count=0,flag=0,a,b;
string s;
cin>>k>>n;
ll arr[n];
for(i=0;i<n;i++)cin>>arr[i];
temp=arr[n-1]-arr[0];

for(i=1;i<n;i++)
{
  flag=k-arr[i]+arr[i-1];
  temp=min(temp,flag);
}
cout<<temp<<endl;

return 0; 
 
 
}

Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {

		Scanner sc = new Scanner(System.in);

		int dir[][] = { { 0, -1 }, { 0, 1 }, { 1, 0 } };

		while (true) {
			final int w = sc.nextInt();
			final int h = sc.nextInt();

			if (w == 0 && h == 0) {
				break;
			}

			final int amount = sc.nextInt();
			final int capacity = sc.nextInt();
			final int init = sc.nextInt();

			int[][] map = new int[h][w];

			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					map[i][j] = sc.nextInt();
				}
			}

			PriorityQueue<Walk> queue = new PriorityQueue<Walk>();
			for (int i = 0; i < w; i++) {
				boolean[][] b = new boolean[h][w];
				Walk walk = new Walk(0, init, 0, i, b);
				walk.sanso--;
				queue.add(walk);
			}

			boolean flag = false;
			while (!queue.isEmpty()) {
				Walk walk = queue.poll();
				int y = walk.y;
				int x = walk.x;

				if (walk.sanso <= 0) {
					continue;
				} else if (walk.y >= h) {
					flag = true;
					System.out.println(walk.cost);
					break;
				}

				walk.visited[y][x] = true;

				if (map[y][x] <= 0) {
					walk.cost += (-map[y][x]);
				} else {
					walk.sanso = Math.min(map[y][x] + walk.sanso, capacity);
				}

				if (walk.cost > amount) {
					continue;
				}

				for (int i = 0; i < 3; i++) {
					int ny = y + dir[i][0];
					int nx = x + dir[i][1];
					if (nx >= 0 && nx < w && ny >= 0 && ny <= h - 1
							&& !walk.visited[ny][nx]) {
						boolean[][] nb = new boolean[h][w];
						for(int j = 0;j<h;j++){
							nb[j] = Arrays.copyOf(walk.visited[j], w);
						}
						Walk wa = new Walk(walk.cost, walk.sanso-1, ny, nx, nb);
						queue.add(wa);
					} else if (i == 2 && walk.y == h - 1) {
						Walk wa = new Walk(walk);
						wa.y++;
						queue.add(wa);
					}
				}
			}

			if (!flag) {
				System.out.println("NA");
			}

		}
	}
}

class Walk implements Comparable<Walk> {
	int cost;
	int sanso;
	int x, y;
	boolean[][] visited;

	public Walk(int cost, int sanso, int y, int x, boolean[][] visited) {
		super();
		this.cost = cost;
		this.sanso = sanso;
		this.x = x;
		this.y = y;
		this.visited = visited;
	}

	public Walk(Walk w) {
		this.cost = w.cost;
		this.sanso = w.sanso;
		this.x = w.x;
		this.y = w.y;
		visited = new boolean[w.visited.length][w.visited[0].length];
		for (int i = 0; i < w.visited.length; i++) {
			visited[i] = Arrays.copyOf(w.visited[i], w.visited[0].length);
		}
	}

	@Override
	public int compareTo(Walk arg0) {
		return this.cost - arg0.cost;
	}
}

Measured memory_bytes: 74844
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n,x,y;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];

	}
	for (int i = 1; i < n; i++) {
		x = max(a[i-1], a[i]);
		y = min(a[i], a[i-1]);
		int r = x % y;
		while (r != 0) {
			x = y;
			y = r;
			r = x % y;
		}
		a[i] = y;
	}

	cout << y<< endl;
}

Measured memory_bytes: 768
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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




int main() {
	int n;
	cin >> n;
	deque<ll> x(n);
	rep(i, n) cin >> x[i];

	deque<ll> ans;
	deque<ll> tmp = x;
	sort(tmp.begin(), tmp.end());
	rep(i, n) {
		if (x[i] <= tmp[n / 2 - 1]) cout << tmp[n / 2] << endl;
		else cout << tmp[n / 2-1] << endl;
	}
	return 0;
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    for(int d = m / n; d >= 1; -- d){
        int ret = m / d;
        if(m % d == 0 && ret >= n){
            printf("%d\n", d);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <deque>

long long dp[5050][5050][2];
long long copy[5050][2];

int main() {
    constexpr auto mod = 1000000007ll;
    long long n, x, y;
    scanf("%lld", &n);
    std::vector<std::deque<long long>> g(n);
    for (auto i = 0ll; i < n - 1; i++) {
        scanf("%lld%lld", &x, &y);
        x--;
        y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    std::vector<std::deque<long long>> c(n);
    std::deque<long long> q, q2;
    std::vector<bool> done(n);
    q.push_back(0);
    while (!q.empty()) {
        auto curr = q.front();
        q.pop_front();
        q2.push_back(curr);
        done[curr] = true;
        for (auto to : g[curr]) {
            if (done[to]) continue;
            q.push_back(to);
            c[curr].push_back(to);
        }
    }

    std::vector<long long> f(n + 1);
    f[0] = 1;
    for (auto i = 2ll; i <= n; i++) f[i] = i & 1 ? 0 : f[i - 2] * (i - 1) % mod;

    //std::vector<std::vector<std::vector<long long>>> dp(n, std::vector<std::vector<long long>>(n + 1, std::vector<long long>(2)));
    std::vector<long long> sz(n);
    //std::vector<std::vector<long long>> copy(n + 1, std::vector<long long>(2));

    while (!q2.empty()) {
        auto curr = q2.back();
        q2.pop_back();
        dp[curr][1][0] = 1;
        sz[curr] = 1;

        // 今までマージしたやつとi番目をマージ
        for (auto i : c[curr]) {
            for (auto j = 1ll; j <= sz[curr]; j++) {
                copy[j][0] = dp[curr][j][0];
                copy[j][1] = dp[curr][j][1];
                dp[curr][j][0] = 0;
                dp[curr][j][1] = 0;
            }

            for (auto j = 1ll; j <= sz[curr]; j++) {
                for (auto k = 1ll; k <= sz[i]; k++) {
                    dp[curr][j + k][0] += dp[i][k][0] * copy[j][0] % mod + dp[i][k][1] * copy[j][1] % mod;
                    dp[curr][j + k][1] += dp[i][k][0] * copy[j][1] % mod + dp[i][k][1] * copy[j][0] % mod;
                    dp[curr][j + k][0] %= mod;
                    dp[curr][j + k][1] %= mod;
                    if (k % 2) continue;
                    dp[curr][j][1] += dp[i][k][0] * f[k] % mod * copy[j][0] % mod + dp[i][k][1] * f[k] % mod * copy[j][1] % mod;
                    dp[curr][j][0] += dp[i][k][1] * f[k] % mod * copy[j][0] % mod + dp[i][k][0] * f[k] % mod * copy[j][1] % mod;
                    dp[curr][j][0] %= mod;
                    dp[curr][j][1] %= mod;
                }
            }
            sz[curr] += sz[i];
        }
    }

    auto ret = 0ll;
    for (auto i = 1ll; i <= n; i++) {
        ret += f[i] * dp[0][i][0] % mod;
        ret = (ret + mod - f[i] * dp[0][i][1]) % mod;
    }
    printf("%lld\n", ret);

    return 0;
}

Measured memory_bytes: 401280
import itertools
n,m,r = map(int, input().split())
req = list(map(lambda x:int(x)-1, input().split()))
dist = [[float('inf') for j in range(n)] for i in range(n)]
for i in range(m):
    a,b,c = map(int, input().split())
    a -= 1
    b -= 1
    dist[a][b] = c
    dist[b][a] = c

for k in range(n):
    for i in range(n):
        for j in range(n):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

min_dist = float('inf')
for p in itertools.permutations(req):
    total_dist = 0
    for i in range(r-1):
        total_dist += dist[p[i]][p[i+1]]
    min_dist = min(min_dist, total_dist)
print(min_dist)
                

Measured memory_bytes: 73012
"use strict";
const main = arg => {
  const input = arg.trim().split('\n');
  const arr = input[0].split(" ").map(Number);
	
  if(arr[0] <= arr[1]){
    console.log("unsafe");
  }else{
    console.log("safe");
  }
}
 
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29624
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,c=7,sum=0,mx=0;
	cin>>n;
	vector<int>v(4);
	for(int i=3;i>=0;i--)
	{
		v[i]=n%10;
		//cout<<v[i];
		n=n/10;
	}
	sum=v[0]+v[1]+v[2]+v[3];
	//cout<<v[0]<<endl;
	if(v[0]+v[1]+v[2]+v[3]==7)
	{
		cout<<v[0]<<"+"<<v[1]<<"+"<<v[2]<<"+"<<v[3]<<"=7"<<endl;
		return 0;
	}
	if(v[0]-v[1]+v[2]+v[3]==7)
	{
		cout<<v[0]<<"-"<<v[1]<<"+"<<v[2]<<"+"<<v[3]<<"=7"<<endl;
		return 0;
	}
	if(v[0]-v[1]-v[2]+v[3]==7)
	{
		cout<<v[0]<<"-"<<v[1]<<"-"<<v[2]<<"+"<<v[3]<<"=7"<<endl;
		return 0;
	}
	if(v[0]-v[1]-v[2]-v[3]==7)
	{
		cout<<v[0]<<"-"<<v[1]<<"-"<<v[2]<<"-"<<v[3]<<"=7"<<endl;
		return 0;
	}
	if(v[0]-v[1]+v[2]-v[3]==7)
	{
		cout<<v[0]<<"-"<<v[1]<<"+"<<v[2]<<"-"<<v[3]<<"=7"<<endl;
		return 0;
	}
	if(v[0]+v[1]-v[2]-v[3]==7)
	{
		cout<<v[0]<<"+"<<v[1]<<"-"<<v[2]<<"-"<<v[3]<<"=7"<<endl;
		return 0;
	}
	if(v[0]+v[1]+v[2]-v[3]==7)
	{
		cout<<v[0]<<"+"<<v[1]<<"+"<<v[2]<<"-"<<v[3]<<"=7"<<endl;
		return 0;
	}
	if(v[0]+v[1]-v[2]+v[3]==7)
	{
		cout<<v[0]<<"+"<<v[1]<<"-"<<v[2]<<"+"<<v[3]<<"=7"<<endl;
		return 0;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[105];
int last[27],mx[27];
int main(){
	scanf("%s",s+1);int n=strlen(s+1);
	for(int i=1;i<=n;i++){
		int ch=s[i]-'a';
		mx[ch]=max(mx[ch],i-last[ch]-1);
		last[ch]=i;
	}
	for(int i=0;i<26;i++) mx[i]=max(mx[i],n-last[i]); 
	int ans=1e9;
	for(int i=0;i<26;i++) ans=min(ans,mx[i]);
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 256
n, k = map(int, input().split())
mod = 10 ** 9 + 7

gcd = [0] * k
for i in range(k):
    test = k - i
    temp = 0
    for j in range(k // test):
        if j == 0:
            temp2 = 1
            temp3 = [k // test]
            for l in range(len(bin(n)) - 2):
                temp3.append(temp3[-1] ** 2 % mod)
            test3 = bin(n)
            for l in range(len(test3) - 2):
                if test3[-1-l] == "1":
                    temp2 *= temp3[l]
                    temp2 %= mod
            temp += temp2
        else:
            test2 = test * (j + 1)
            temp -= gcd[test2 - 1]
    gcd[test - 1] = temp
ans = 0
for i in range(k):
    ans += gcd[i] * (i + 1)
    ans %= mod
print(ans)

Measured memory_bytes: 69728
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,ans;
	cin>>n;
	int a[n],b[n],c[n],d[n]={0};
	for(int i=0;i<n;i++)
	cin>>a[i]>>b[i]>>c[i];
	int dp[3][n];
	dp[0][0]=a[0];
	dp[1][0]=b[0];
	dp[2][0]=c[0];
	for(int i=1;i<n;i++)
	{
		dp[0][i]=a[i]+max(dp[1][i-1],dp[2][i-1]);
		dp[1][i]=b[i]+max(dp[0][i-1],dp[2][i-1]);
		dp[2][i]=c[i]+max(dp[1][i-1],dp[0][i-1]);
	}
	ans=max(dp[0][n-1],dp[1][n-1]);
	ans=max(ans,dp[2][n-1]);
	cout<<ans<<endl;
}

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

const ll M = 1000000007;
ll n;
map<ll, ll> mp;

ll f(ll x){
	if(__builtin_popcount(x) == 1) return 1;
	if(mp.find(x) != mp.end()) return mp[x];
	ll t; for(t = 1; t <= x; t <<= 1); t /= 2;
	if(x > 3 * t / 2) x = 3 * t - x;
	return mp[x] = (f(x - t) + f(x - t / 2)) % M;
}

ll g(ll x){
	if(x == 1) return 2;
	return (3 * g(x / 2) - (2 - (x & 1)) * f(x / 2 + 1) + 2 * M) % M;
}

int main(){
	scanf("%lld", &n);
	printf("%lld\n", g(n));
}

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

int solve(int i, int m, int n, int A[])
{
	int d[21][2001];
	
	if(m==0) return 2;
	if(i>=n) return 1;
	if(d[i][m]!=0) return d[i][m];
	if(solve(i+1,m,n,A)==2 || solve(i+1,m-A[i],n,A)==2) return d[i][m]=2;
	else return d[i][m]=1;
}

int main()
{
	int i,n,A[20],q,m;
	
	scanf("%d",&n);
	for(i=0;i<=n-1;i++) scanf("%d",&A[i]);
	scanf("%d",&q);
	for(i=0;i<=q-1;i++)
	{
		scanf("%d",&m);
		if(solve(0,m,n,A)==2) printf("yes\n");
		else printf("no\n");
	}
	return 0;
}

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

bool check(int x,int y,int z)
{
    return (x + y > z) && (x + z > y) && ( y + z > x ) && x != y && x!=z && y !=z;
}
int main(){
    int n;
    while(scanf("%d",&n) == 1 && n)
    {
        int buffer[n];
        for(int i = 0; i < n; ++i) scanf("%d",&buffer[i]);
        int cont = 0;
        for(int i = 0; i < n -2 ; ++i) 
        {
            for(int j = i + 1; j < n - 1; ++j)
            {
                for(int k = j + 1; k < n; ++k)
                {
                    if(check(buffer[i],buffer[j],buffer[k])) 
                    {
                        ++cont;
                    }
                }
            }
        }
        printf("%d\n",cont);
    } 
    return 0;
}


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

int main(void){
    ll nums[3], cnt = 0, tmp[3];
    for (int i=0; i<3; i++) cin >> nums[i];
    if (nums[0]%2==0 && nums[0] == nums[1] && nums[1] == nums[2]){
        cout << -1 << endl;
    } else{
        while (nums[0]%2==0 && nums[1]%2==0 && nums[2]%2==0){
            cnt++;
            for (int i=0; i<3; i++) tmp[i] = nums[i] / 2;
            nums[0] = tmp[1] + tmp[2];
            nums[1] = tmp[0] + tmp[2];
            nums[2] = tmp[0] + tmp[1];
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
 
// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ---------------------------------------------------------------------------

int main(){
  int N,M,s,t;
  cin >> N >> M >> s >> t;
  s--;
  t--;
  vector<vector<pair<int,ll>>> G_yen(N),G_sn(N);
  for(int i=0; i<M; i++){
    int u,v;
    ll a,b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    G_yen[u].push_back(make_pair(v,a));
    G_yen[v].push_back(make_pair(u,a));
    G_sn[u].push_back(make_pair(v,b));
    G_sn[v].push_back(make_pair(u,b));
  }
  priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> que_yen,que_sn;
  vector<ll> dist_yen(N,INF);
  que_yen.push(make_pair(0,s));
  dist_yen[s] = 0;
  while(que_yen.size()){
    auto v = que_yen.top();
    que_yen.pop();
    if(v.first > dist_yen[v.second]) continue;
    for(auto nv: G_yen[v.second]){
      if(dist_yen[v.second] + nv.second < dist_yen[nv.first]){
        dist_yen[nv.first] = dist_yen[v.second] + nv.second;
        que_yen.push(make_pair(dist_yen[nv.first],nv.first));
      }
    }
  }
  vector<ll> dist_sn(N,INF);
  que_sn.emplace(0,t);
  dist_sn[t] = 0;
  while(que_sn.size()){
    auto v = que_sn.top();
    que_sn.pop();
    if(v.first > dist_sn[v.second]) continue;
    for(auto nv: G_sn[v.second]){
      if(dist_sn[v.second] + nv.second < dist_sn[nv.first]){
        dist_sn[nv.first] = dist_sn[v.second] + nv.second;
        que_sn.emplace(dist_sn[nv.first],nv.first);
      }
    }
  }
  vector<ll> ans(N);
  ll mn = pow(10,15) + 100;
  for(int i=N-1; i>=0; i--){
    chmin(mn,dist_yen[i]+dist_sn[i]);
    ans[i] = mn;
  }
  ll have = pow(10,15);
  for(int i=0; i<N; i++){
    cout << have - ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 20216
n = gets.chomp.to_i - 1

result = []
lsb = true

while true
  n = n - 1 unless lsb
  a = n % 26
  n = n / 26
  result.push ('a'..'z').to_a[a]
  break if n == 0
  lsb = false
end

puts result.reverse.join

Measured memory_bytes: 14372
from collections import Counter,defaultdict,deque
from bisect import bisect_left
import sys,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
print((n+1)//2)

Measured memory_bytes: 5300
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
count = 0
for i in range(N):
    count += B[i]
    if i != N-1 and A[i+1] == A[i]+1:
        count += C[A[i]-1]
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>

using namespace std;
int main(void){
    char s[100];
    int a,b;
    
    while(1){
        cin>>a;
        scanf("%s",s)!=EOF;
        cin>>b;
        if(s[0]=='+'){
            cout<<a+b<<endl;
        }else if(s[0]=='-'){
            cout<<a-b<<endl;
        }else if(s[0]=='*'){
            cout<<a*b<<endl;
        }else if(s[0]=='/'){
            cout<<a/b<<endl;
        }else{
            break;
        }
    }
    
    
    return 0;
}


Measured memory_bytes: 3132
def same?(f,*ns)
  r = true
  ns.each do |n|
    unless f == n then r = false; break end
  end
  return r
end

def succ?(f,*ns)
  r = true
  ns.each.with_index do |n, idx|
    unless f == (n-idx-1) then r = false; break end
  end
  return r
end

while gets
  a,b,c,d,e = $_.split(",").map(&:to_i).sort
  if same?(a,b,c,d) or same?(b,c,d,e) then puts "four card"
  elsif (same?(a,b,c) and d==e) or (a==b and same?(c,d,e)) then puts "full house"
  elsif (a==1 and b==10 and succ?(b,c,d,e)) or succ?(a,b,c,d,e) then puts "straight"
  elsif same?(a,b,c) or same?(b,c,d) or same?(c,d,e) then puts "three card"
  elsif (a==b and c==d) or (a==b and d==e) or (b==c and d==e) then puts "two pair"
  elsif a==b or b==c or c==d or d==e then puts "one pair"
  else puts "null"
  end
end

Measured memory_bytes: 8624
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  long long n, m, l, b[100][100], a[100][100], c[100][100] = {};
  cin >> n >> m >> l;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      cin >> a[i][j];
    }
  }
  for(int i = 0; i < m; i++){
    for(int j = 0; j < l; j++){
      cin >> b[i][j];
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      for(int k = 0; k < l; k++){
        c[i][k] += a[i][j] * b[j][k];
      }
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < l; j++){
      cout << (j == 0 ? "": " ") << c[i][j];
    }
    cout << endl;
  }
}


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

using namespace std;

using Number = double;
const Number EPS = 1e-10;

inline int sign(Number x) { return (x < -EPS) ? -1 : (x > EPS) ? +1 : 0; }
inline bool equal(Number a, Number b) { return sign(a - b) == 0; }

class Point {
public:
    Number x, y;

    Point() {}
    Point(Number x, Number y) : x(x), y(y) {}

    Point operator+(const Point &rhs) const {
        return Point(this->x + rhs.x, this->y + rhs.y);
    }
    Point operator-(const Point &rhs) const {
        return Point(this->x - rhs.x, this->y - rhs.y);
    }
};

inline Number abs_cross(const Point &p1, const Point &p2) {
    return p1.x * p2.y - p1.y * p2.x;
}

class Line : public std::array<Point, 2> {
public:
    Line() {}
    Line(const Point &p1, const Point &p2) {
        (*this)[0] = p1;
        (*this)[1] = p2;
    }
};
inline bool IsParallel(const Line &l1, const Line &l2) {
    return equal(abs_cross(l1[0] - l1[1], l2[0] - l2[1]), 0.0);
}

int Search(const int i, const int m, vector<int> &idx, const vector<Point> &p) {
    if (i == m - 2) {
        int sum = 0;
        vector<bool> check(m / 2, false);

        for (int j = 0; 2 * j < m; ++j) {
            if (check[j]) continue;

            check[j] = true;
            int num = 1;
            Line l(p[idx[2 * j]], p[idx[2 * j + 1]]);
            for (int k = j + 1; 2 * k < m; ++k)
                if (IsParallel(l, Line(p[idx[2 * k]], p[idx[2 * k + 1]]))) {
                    ++num;
                    check[k] = true;
                }
            sum += num * (num - 1) / 2;
        }
        return sum;
    }

    int res = 0;
    if (i % 2 == 0) {
        int min_idx = distance(idx.begin(), min_element(idx.begin() + i, idx.end()));
        swap(idx[i], idx[min_idx]);
        res=  Search(i + 1, m, idx, p);
        swap(idx[i], idx[min_idx]);
    }
    else {
        for (int j = i; j < m; ++j) {
            swap(idx[i], idx[j]);
            res = max(res, Search(i + 1, m, idx, p));
            swap(idx[i], idx[j]);
        }
    }

    return res;
}

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

    int m;

    cin >> m;
    vector<Point> p(m);
    for (auto &pp : p) cin >> pp.x >> pp.y;

    vector<int> idx(m);
    iota(idx.begin(), idx.end(), 0);

    cout << Search(1, m, idx, p) << endl;

    return 0;
}



Measured memory_bytes: 3232
import sys
x, y = map(int, input().split())
ans = 0
if x == 1:
    ans += 300000
elif x == 2:
    ans += 200000
elif x == 3:
    ans += 100000

    
if y == 1:
    ans += 300000
elif y == 2:
    ans += 200000
elif y == 3:
    ans += 100000

if x == 1 and y == 1:
    ans += 400000

print(ans)
    

        


        


    







        



Measured memory_bytes: 3060
fun main(args: Array<String>){
    val (D, N) = readLine()!!.split(' ').map { it -> it.toInt() }

    var kiriban: Int = 1
    var ans: Int = 0

    for (i in 0 until D){
        kiriban *= 100
    }

    if (N == 100){
        ans = kiriban * N
        ans += kiriban
    } else {
        ans = kiriban * N
    }

    println(ans)
}

Measured memory_bytes: 38184
#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#include<utility>

typedef long long ll;

using namespace std;

int main() {
    ll N;
    ll tmp,out;
    out = 1000000000000;
    cin >> N;
    
    for(ll i=2;i*i<=N;i++){
        if(N%i==0){
            tmp = N/i;
            if (out > (tmp + i-2)) out = tmp + i-2;
        }
    }
    if(out == 1000000000000) out = N -1;
    cout << out;
    
    return 0;
    
}

Measured memory_bytes: 256