akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

int h, n;
char b[20][2][2];
char c[3][2][2][2];

void init() {
	for (int i = 0; i < 20; i++) {
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				b[i][j][k] = '.';
			}
		}
	}
}

void input() {
	int i, j, k;
	string str;
	
	cin >> h >> n;
	for (i = 0; i < h; i++) {
		for (j = 0; j < 2; j++) {
			cin >> str;
			b[i][j][0] = str[0];
			b[i][j][1] = str[1];
		}
	}
	
	for (i = 0; i < n; i++) {
		for (j = 0; j < 2; j++) {
			for (k = 0; k < 2; k++) {
				cin >> str;
				c[i][j][k][0] = str[0];
				c[i][j][k][1] = str[1];
			}
		}
	}
}

bool isRange(int r, int c) {
	return (0 <= r && r < 2 && 0 <= c && c < 2);
}

bool isLegal(int id, int tr, int tc) {
	int i, j, k;
	for (i = 0; i < 2; i++) {
		for (j = 0; j < 2; j++) {
			for (k = 0; k < 2; k++) {
				if (c[id][i][j][k] != '#') continue;
				if (!isRange(j + tr, k + tc)) return false;
			}
		}
	}
	return true;
}

bool isAll(int z) {
	int i, j;
	for (i = 0; i < 2; i++) {
		for (j = 0; j < 2; j++) {
			if (b[z][i][j] != '#') return false;
		}
	}
	return true;
}

int getDropHeight(int id, int tr, int tc) {
	int i, j, k, l;
	int ret = -114514;
	
	for (i = 0; i < 2; i++) {
		for (j = 0; j < 2; j++) {
			for (k = 0; k < 2; k++) {
				if (c[id][i][j][k] != '#') continue;
				
				int row = j + tr;
				int col = k + tc;
				
				for (l = 19; l >= 0; l--) {
					if (b[l][row][col] == '#') break;
				}
				l++;
				ret = max(ret, l - i);
			}
		}
	}
	return ret;
}

int drop(int id, int tr, int tc) {
	int i, j, k, l;
	
	i = getDropHeight(id, tr, tc);
	for (j = 0; j < 2; j++) {
		for (k = 0; k < 2; k++) {
			for (l = 0; l < 2; l++) {
				if (c[id][j][k][l] != '#') continue;
				b[i + j][k + tr][l + tc] = '#';
			}
		}
	}
	
	int eraseNum = 0;
	
	for (i = 19; i >= 0; i--) {
		if (!isAll(i)) continue;
		
		eraseNum++;
		for (j = i + 1; j < 20; j++) {
			for (k = 0; k < 2; k++) {
				for (l = 0; l < 2; l++) {
					b[j-1][k][l] = b[j][k][l];
				}
			}
			for (k = 0; k < 2; k++) {
				for (l = 0; l < 2; l++) {
					b[j][k][l] = '.';
				}
			}
		}
	}
	return eraseNum;
}

int dfs(int id) {
	int tr, tc;
	int i, j, k;
	char backup[20][2][2];
	
	if (id == n) { return 0; }
	
	int ret = -114514;
	for (tr = -1; tr <= 1; tr++) {
		for (tc = -1; tc <= 1; tc++) {
			if (!isLegal(id, tr, tc)) continue;
			for (i = 0; i < 20; i++) for (j = 0; j < 2; j++) for (k = 0; k < 2; k++) backup[i][j][k] = b[i][j][k];
			ret = max(ret, drop(id, tr, tc) + dfs(id + 1));
			for (i = 0; i < 20; i++) for (j = 0; j < 2; j++) for (k = 0; k < 2; k++) b[i][j][k] = backup[i][j][k];
		}
	}
	return ret;
}

int main() {
	while (true) {
		init();
		input();
		if (h == 0) { break; }
		cout << dfs(0) << endl;
	}
	return 0;
}

Measured memory_bytes: 3088
#include<stdio.h>
long abs(long  a)
{
	if(a>0) return a;
	else return -a;
}
int main()
{
	long sum=0;
	int n,i;
	long min;
	long sumz=0,sumy=0;
	long x[200001];
	scanf("%d",&n);
	for (i=1;i<=n;i++)
	{
		scanf("%ld",&x[i]);
		sum+=x[i];
	}
	sumy=sum;
	for(i=1;i<n;i++)
	{
		sumz+=x[i];
		sumy-=x[i];
		if(i==1) min=abs(sumz-sumy);
		else if(abs(sumz-sumy)<min) min=abs(sumz-sumy);
	}
	printf("%ld",min);
}

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

int main() {
	int num;
  	cin>>num;
    map<string,int> m;
  	while(num--) {
      string s;
      cin>>s;
      m[s]++;
    }
  
  	cout<<"AC"<<" x "<<m["AC"]<<"\n";
   cout<<"WA"<<" x "<<m["WA"]<<"\n";
  cout<<"TLE"<<" x "<<m["TLE"]<<"\n";
  cout<<"RE"<<" x "<<m["RE"]<<"\n";
  
}

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

using namespace std;

int main() {
    char a, b;
    cin >> a >> b;
    if (a == 'H') {
        cout << b;
    } else {
        if (b == 'H') {
            cout << 'D' << endl;
        } else {
            cout << 'H' << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;

/*各Kについて、K*(1+2+...+[N/K])を足す。*/
int main() {
	long long N, ans;

	cin >> N;
	ans = 0;
	for (long long i = 1; i <= N; i++) {
		ans += i * ((N / i) * (N / i + 1) / 2);
	}
	cout << ans;

}

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

int main(){
	int n;
	cin >> n;
	vector<int> d(n);
	rep(i,n) cin >> d[i];
	ll ans(0);
	rep(i,n){
		rep(j,n){
			if(j>=i)continue;
			ans += d[i]*d[j];
		}
	}
	cout << ans << endl;
	return 0;
}

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

int n, m, ans = INT_MAX, a[301][301], cnt[301], sidx[301];
bool mark[301];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin >> a[i][j], --a[i][j];
	for(int i = 0; i < n; i++) cnt[a[i][sidx[i]]]++;
	for(int t = 0; t < m; t++) {
		int mx = 0;
		for(int j = 0; j < m; j++) if(cnt[j] > cnt[mx]) mx = j;
		ans = min(cnt[mx], ans);
		mark[mx] = true;
		for(int i = 0; i < n; i++) while(mark[a[i][sidx[i]]]) {
			cnt[a[i][sidx[i]]]--;
			sidx[i]++;
			cnt[a[i][sidx[i]]]++;
		}
	}
	cout << ans;
}


Measured memory_bytes: 640
#include <cstdio>

long long int gcd(long long int a,long long int b){
	if(b==0) return a;
	gcd(b,a%b);
}

int main(){
	long long int a,b;
	while(scanf("%lld%lld",&a,&b)!=EOF){
	    long long int c=gcd(a,b);
	    long long int d=a*b/c;
	    printf("%lld %lld\n",c,d);
	}
	return 0;
}

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

double a[4][4];

int main(){
    for(ll i=1; i<=3; i++){
        for(ll j=1; j<=3; j++) scanf("%lf",&a[i][j]);
    }
    if(a[1][2]+a[2][3]+a[3][1]+a[1][3]+a[2][1]+a[3][2]==(a[1][1]+a[2][2]+a[3][3])*2) printf("Yes");
    else printf("No");
    return 0;
}

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    
    ll r=0, g=0, b=0;
    for(int i=0;i<n;i++){
        if(s[i] == 'R')
            r++;
        if(s[i] == 'G')
            g++;
        if(s[i] == 'B')
            b++;
    }

    ll ans = r*g*b;

    for(int i=0;i<n;i++){
        for(int step=1;step<n;step++){
            int j = i + step;
            int k = i + 2*step;
            if(k>n-1)
                break;
            if(s[i]!=s[j] && s[j]!=s[k] && s[k]!=s[i])
                ans--;
        }
    }

    cout << ans << endl;
}

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

using namespace std;

typedef pair<int, int> pi;

int N, M;
vector<int> G[10];
int ans = 0;
vector<bool> visited(10, false);

void dfs(int v){
	bool allvisited = true;
	for(int i = 0; i < N; ++i)
		if(visited[i] == false) allvisited = false;

	if(allvisited){
		ans++;
		return;
	}else{
		for(int i = 0; i < G[v].size(); ++i){
			if(visited[G[v][i]] == false){
				visited[G[v][i]] = true;
				dfs(G[v][i]);
				visited[G[v][i]] = false;
			}
		}
		return;
	}
}

int main(){
	cin >> N >> M;
	for(int i = 0; i < M; ++i){
		int from, to;
		cin >> from >> to; from--; to--;
		G[from].push_back(to);
		G[to].push_back(from);
	}

	visited[0] = true;
	dfs(0);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define endl '\n'
int main(){
    ll k;
    cin>>k;
    if(k<=9)cout<<k<<endl;
    else{
        vector<ll>ans(10,0);
        for(ll i=1;i<=9;i++)ans[i]=i;
        ll counter=k-9;
        counter=counter/3 +1;
        counter*=3;
        ll curr=1;
        while(counter>0){
            if(ans[curr]%10-1>=0){
                ans.push_back(ans[curr]*10+ans[curr]%10 -1);
                counter--;
            }
             if(ans[curr]%10>=0){
                ans.push_back(ans[curr]*10+ans[curr]%10);
                counter--;
            }
             if(ans[curr]%10+1<=9){
                ans.push_back(ans[curr]*10+ans[curr]%10 +1);
                counter--;
            }
            curr++;}
            cout<<ans[k]<<endl;


    }
    return 0;
}


Measured memory_bytes: 1656
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int a[3],n;
    cin>>a[0]>>a[1]>>a[2]>>n;
    sort(a,a+3);

    int count=0;
    for (int i = 0; a[2]*i<=n; ++i) {
        for (int j = 0; a[1]*j <=n-a[2]*i ; ++j) {
            int z=n-a[2]*i-a[1]*j;
            if(z%a[0]==0)
                count++;
        }
    }
     cout<<count;
}

Measured memory_bytes: 256
int main(){
    char key[101];
    char sub[101];
    scanf("%s%s", key, sub);
    unsigned long keylen = strlen(key), sublen = strlen(sub);
    int i; int x;
    int ac = 0; int flag = 1; int y = -1;
    for(i = keylen - sublen;i >= 0; i--){
        for(x = 0; x < sublen; x++){
            if(!(key[x + i] == '?'||sub[x] ==key[x + i])){
                flag = 0; break;
            }
        }
        if(flag == 1){
            ac = 1; y = i; break;
        }
        flag = 1;
    }
    
    if(ac == 0) {
        printf("UNRESTORABLE\n");
    }else{
        for(x = 0; x < sublen; x++){
            key[x + y] = sub[x];
        }
        for(x = 0; x < keylen; x ++){
            if(key[x] == '?'){
                key[x] = 'a';
            }
        }
        printf("%s\n", key);
    }
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>

int main(void){
  int n,i;
  long long dp[1000050];
  int y[1000050];
  scanf("%d",&n);
  dp[0] = dp[1] = 0;
  
  int k,j;
  for(k=1;k<n+1;k++){
    for(j=k;j<n+1;j+=k){
      if(j >= 1000001) break;
      y[j] += 1;
    }
    dp[k] = dp[k-1] + y[k-1];
  }
  
  //for(i=0;i<n+1;i++) printf("%d,",y[i]);
  printf("%d",dp[n]);
  return 0;
}

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

int main(){
	int64_t X;
	cin >> X;

	int ans = 0;
	int64_t price = 100;
	for(int i = 0; i <= X; i++){
		if(X <= price)
			break;
		price *= 1.01;
		ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  string s;
  cin >> s;
  int n = s.length();
  int p = 673;
  int ten = 1;
  vector<pair<int,int>> d(n + 1, {0, 0});
  for(int i = n - 1; i >= 0; i--){
    int a = (s[i] - '0') * ten % p;
    d[i].first = (d[i + 1].first + a) % p;
    ten *= 10;
    ten %= p;
  }
  int p1 = 3;
  ten = 1;
  for(int i = n - 1; i >= 0; i--) {
    int a = (s[i] - '0') * ten % p1;
    d[i].second = (d[i + 1].second + a) % p1;
    ten *= 10;
    ten %= p1;
  }
  /*
  vector<int> count(p);
  vector<int> count1(p1);
  for(int i = n; i >= 0; i--){
    ans += count[d[i]];
    cout << count[d[i]] << " " << d[i] << " ";
    cout << count1[d1[i]] <<" " <<  d1[i] << endl;
    count[d[i]]++;
    count1[d1[i]]++;
  }
  */
  vector<int> q(n + 1, 0);
  for(int i = 0; i <= n; i++){
    q[i] = d[i].first + d[i].second * 1000;
  }
  vector<int> count(10000, 0);
  ll ans = 0;
  for(int i = n; i >= 0; i--){
    ans += count[q[i]];
    count[q[i]]++;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 5956
#include <iostream>
using namespace std;
int main() {
  unsigned int n, m, l;
  cin >> n >> m >> l;

  unsigned long **A = new unsigned long*[n];
  for (int i = 0; i < n; i++) {
    A[i] = new unsigned long[m];
  }

  unsigned long **B = new unsigned long*[m];
  for (int i = 0; i < m; i++) {
    B[i] = new unsigned long[l];
  }
  unsigned long **C = new unsigned long*[n];
  for (int i = 0; i < n; i++) {
    C[i] = new unsigned long[l];
  }

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

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

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      C[i][j] = 0;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      for (int k = 0; k < m; k++) {
        C[i][j] += A[i][k] * B[k][j];
      }
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      cout << C[i][j];
      if (j != l-1) {
        cout << " ";
      }
    }
    cout << endl;
  }

  delete [] A;
  delete [] B;
  delete [] C;
  return 0;
}

Measured memory_bytes: 1428
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

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

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var N, K int

func main() {
	sc.Split(bufio.ScanWords)

	N, K = nextInt(), nextInt()
	kind := 0
	m := make([]int, N)
	for i := 0; i < N; i++ {
		a := nextInt() - 1
		if m[a] == 0 {
			kind++
		}
		m[a]++
	}

	sort.Ints(m)
	ans := 0
	if K >= kind {
		fmt.Println(ans)
		return
	}
	for i := N - kind; i < N; i++ {
		kind--
		ans += m[i]
		if K >= kind {
			fmt.Println(ans)
			return
		}

	}
}


Measured memory_bytes: 4768
#include<stdio.h>

int main(void){
  int i,j;
  double visL,visR;
  int table[2][4];

  for(i=0;i<2;i++)
    for(j=0;j<4;j++)
      table[i][j]=0;

  for(;scanf("%lf%lf",&visL,&visR)==2;){
    if(visL>=1.1) table[0][0]++;
    else if(visL>=0.6) table[0][1]++;
    else if(visL>=0.2) table[0][2]++;
    else table[0][3]++;

    if(visR>=1.1) table[1][0]++;
    else if(visR>=0.6) table[1][1]++;
    else if(visR>=0.2) table[1][2]++;
    else table[1][3]++;
  }

  for(i=0;i<4;i++)
    printf("%d %d\n",
        table[0][i],
        table[1][i]);

  return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    private long fac[];
    private long finv[];
    private long inv[];
    private static int MAX_LEN = 510000;
    private static int MOD = 1000000007;
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int K = scan.nextInt();
        if (N == K) {
            System.out.println(1);
            for (int i = 2; i <= K; i++) {
                System.out.println(0);
            }
            return;
        }
        COMinit();
        long b = 1000000007;
        for (int i = 1; i <= K; i++) {
            long blue_count = f(K, i) % b;
            long red_count = f(N-K, i-1) % b;
            red_count = (red_count + f(N-K, i)) % b;
            red_count = (red_count + f(N-K, i)) % b;
            red_count = (red_count + f(N-K, i+1)) % b;
            long ans = (blue_count * red_count) % b;
            System.out.println(ans);
        }
    }
    long f(int n, int k) {
        if (n < k) {
            return 0;
        }
        if (n == 0 && k == 0) {
            return 1;
        }
        if (k < 1) {
            return 0;
        }
        return f2(n-k,k);
    }
    long f2(int n, int k) {
        return comb(n+k-1,k-1);
    }
    long comb(int n, int k) {
        return COM(n, k);
    }
    void COMinit() {
        this.fac = new long[MAX_LEN];
        this.finv = new long[MAX_LEN];
        this.inv = new long[MAX_LEN];
        this.fac[0] = this.fac[1] = 1;
        this.finv[0] = this.finv[1] = 1;
        this.inv[1] = 1;
        for (int i = 2; i < MAX_LEN; i++) {
            fac[i] = fac[i-1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i-1] * inv[i] % MOD;
        }
    }
    long COM(int n, int k) {
        if (n < k) {
            return 0;
        };
        if (n < 0 || k < 0) {
            return 0;
        }
        return fac[n] * (finv[k] * finv[n - k]%MOD)%MOD;
    }
}


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

int main()
{
  int k, s, i, j, y, z, ans;
  cin >> k;
  cin >> s;
  ans = 0;
  for(i=0; i<=k; i++)
  {
    for(j=0; j<=k; j++)
    {
      z= s-(i+j);
      if(z <= k&&z >=0)ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

int N, M;
string a[55], b[55];

bool match(int sx, int sy)
{
  for (int i = 0; i < M; ++i) {
    if (sy + i >= N) return false;
    for (int j = 0; j < M; ++j) {
      if (sx + j >= N) return false;
      if (a[sy+i][sx+j] != b[i][j]) return false;
    }
  }
  return true;
}

signed main()
{
  cin >> N >> M;
  for (int i = 0; i < N; ++i) cin >> a[i];
  for (int i = 0; i < M; ++i) cin >> b[i];

  for (int sy = 0; sy < N; ++sy) {
    for (int sx = 0; sx < N; ++sx) {
      if (match(sx, sy)) {
        puts("Yes");
        return 0;
      }
    }
  }

  puts("No");

  return 0;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

# AB = [[int(x) for x in input().split()] for _ in range(N-1)]

# print(AB)

# 添字を1からにしたいのでN+1
graph = [[] for _ in range(N+1)]

# 各頂点に隣接する頂点
for _ in range(N-1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

# print(graph)
counter = [0] * (N+1)

# print(counter)

# PX = [[int(x) for x in input().split()] for _ in range(Q)]

# 各頂点に点数を足す
for _ in range(Q):
  p, x = map(int, input().split())
  counter[p] += x


def shori(pa,c,val):
  val += counter[c]
  counter[c] = val
  for i in graph[c]:
    if i == pa:
      continue
    shori(c,i,val)
  
shori(0,1,0)
  

print(" ".join(map(str, counter[1:])))




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

int n;
int v[100100];
int cnt1[100100], cnt2[100100];

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> n;
    rep(i, n) cin >> v[i];
    for (int i=0; i<n; i+=2) cnt1[v[i]]++;
    for (int i=1; i<n; i+=2) cnt2[v[i]]++;
    vector<P> v1, v2;
    rep(i, 100100) v1.pb(P(n/2-cnt1[i], i));
    rep(i, 100100) v2.pb(P(n/2-cnt2[i], i));
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    if (v1[0].second!=v2[0].second) cout << v1[0].first+v2[0].first << endl;
    else cout << min(v1[0].first+v2[1].first, v1[1].first+v2[0].first) << endl;
}

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

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

Measured memory_bytes: 3864
#include <iostream>
using namespace std;
int main(){
	int W,H,x,y,r;
	cin >> W>>H>> x>> y>> r;
	if (W >= x + r && x-r >=0 && H >= y + r && y-r >= 0){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

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

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;

using namespace std;
int dp[1005][1005];

int main() {
    int n; cin >> n;
    REP(k, n){
        REP(i, 1005) REP(j, 1005) dp[i][j] = 0;
        string a, b;
        cin >> a >> b;
        REP(i, a.length()){
            string q = a.substr(i, 1);
            REP(j, b.length()){
                string t = b.substr(j, 1);
                if(q == t){
                    if(i == 0 || j == 0)
                        dp[i][j] = 1;
                    else
                        dp[i][j] = (dp[i-1][j] > dp[i][j-1]) ? max(dp[i-1][j-1] + 1, dp[i-1][j]) : max(dp[i-1][j-1] + 1, dp[i][j-1]);
                }
                else if (i != 0 && j != 0)
                    dp[i][j] = (dp[i-1][j] > dp[i][j-1]) ? dp[i-1][j] : dp[i][j-1];
                else if (i != 0)
                    dp[i][j] = dp[i-1][j];
                else
                    dp[i][j] = dp[i][j-1];
            }
        }
        cout << dp[a.length()-1][b.length()-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 5160
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int mod = 1000000007;
int main(){
    ll x;
    cin >> x;
    ll a,b;
    ll fl=0;
    for(a=0;fl==0;a++){
        for(b=-1*a;b<=a;b++){
            if(pow(a,5)-pow(b,5)==x){
                fl++;
                cout << a << " " << b << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4008
import itertools
import collections

class PrimeFactorize:
    def __init__(self, n):
        self.prime_factor_table = self.create_prime_factor_table(n)

    # O(NloglogN)
    def create_prime_factor_table(self, n):
        self.table = [0] * (n + 1)
        
        for i in range(2, n + 1):
            if self.table[i] == 0:
                for j in range(i + i, n + 1, i):
                    self.table[j] = i
        return self.table

    def prime_factor(self, n):
        prime_count = collections.Counter()
        
        while self.prime_factor_table[n] != 0:
            prime_count[self.prime_factor_table[n]] += 1
            n //= self.prime_factor_table[n]
        prime_count[n] += 1
        return prime_count

N = int(input())
A_s = list(map(int, input().split()))
pc = True
sc = True
M = {}
MAX = 0
pf = PrimeFactorize(10**6+1)

for i,A in enumerate(A_s):
    L = pf.prime_factor(A)
    for l in L.keys():
        if l == 1:
            continue
        if l in M:
            # print()
            M[l] += 1
            pc = False
        else:
            M[l] = 1
        MAX = max(MAX, M[l])
    if not pc and MAX <= i:
        break
else:
    sc = False

if pc:
    print('pairwise coprime')
elif sc:
    print('setwise coprime')
else:
    print('not coprime')

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

int main() {
  long long int n,m;
  cin >> n >> m;
  
  long long int a,b;
  
  a = n>m ? n : m;
  b = n>m ? m : n;
  
  if (b == 1) {
    if (a == 1)
      cout << 1 << endl;
    else if (a == 2)
      cout << 0 << endl;
    else 
      cout << a - 2 << endl;
  } else if (b == 2) {
    cout << 0 << endl;
  } else {
    cout << (a-2) * (b-2) << endl;
  }
}

Measured memory_bytes: 256
using System;

class Program
{
  /// <summary>
  ///   The main entry point for the application
  /// </summary>
  [STAThread]
  public static void Main(string[] args)
  {
    string[] s = Console.ReadLine().Split(' ');
    int n = int.Parse(s[0]);
    int a = int.Parse(s[1]);
    int b = int.Parse(s[2]);
    if (n >= a + b) Console.WriteLine("{0} {1}", Math.Min(a,b),0);
    else if (n < a + b && a + b < n * 2) Console.WriteLine("{0} {1}", Math.Min(a,b),(a+b)-n);
    else Console.WriteLine("{0} {1}", n, n);
  }
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long

int n;
LL mod;
string s;
LL a[200005];

LL pow2(LL a, LL b) {
    LL ans = 1;
    while(b > 0) {
        if(b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

LL inv(LL x) {
    return pow2(x, mod - 2);
}


int main() {
  //auto start_clock = clock();
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  cin >> n >> mod;
  cin >> s;
  LL ans = 0;
  if (mod == 2) {
    for(int i = 0; i < n; i++) {
      int x = s[i] - '0';
      if(x % 2 == 0) ans += i + 1;
    }
  }
  else if (mod == 5) {
    for(int i = 0; i < n; i++) {
      int x = s[i] - '0';
      if(x == 0 || x == 5) ans += i + 1;
    }
  }
  else {
    a[n] = 0;
    for (int i = n - 1; i >= 0; i--) {
      a[i] = a[i + 1] + (s[i] - '0') * pow2(10, n - 1 - i);
      a[i] %= mod;
    }
    map<LL, int> mp;
    for (int i = 0; i < n; i++) {
      ans += mp[a[i]];
      mp[a[i]] += 1;
    }
    ans += mp[0];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2564
#include <iostream>

using namespace std;

typedef long long ll;

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

  ll n;
  ll b;
  ll r;

  cin >> n >> b >> r;

  ll cnt = n / (b + r);
  ll ans = b * cnt;

  n -= cnt * (b + r);

  cout << ans + min(b, n) << '\n';
}


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

using namespace std;

int main() {
	int A[10000];
	int B,max,min;
	long C = 0;

	cin >> B;

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

	max = A[0];
	min = A[0];

	for (int i = 0; i < B; i++) {
		if (max < A[i]) {
			max = A[i];
		}
		if (min > A[i]) {
			min = A[i];
		}
	}

	for (int i = 0; i < B; i++) {
		C = C + A[i];
	}

	cout << min << " " << max << " " << C << endl;

	return 0;
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,a[N],ans=0,v[2],p[2],nxt[3];

int main() {
	cin>>n;
	for(int i=1;i<=n;i++) a[i]=gi();
	for(int i=1;i<=n+1;i++) {
		p[0]=0,p[1]=a[i]-a[i-1];
		if(p[0]<p[1]) swap(p[0],p[1]);
		nxt[0]=nxt[1]=1e9,nxt[2]=0;
		for(int j=0;j<2;j++)
			for(int k=0;k<2;k++)
				nxt[j+k]=min(nxt[j+k],max(0,v[j]+p[k]));
		int d=nxt[0]>a[i];ans+=d;
		for(int j=0;j<2;j++) v[j]=nxt[j+d];
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
 
signed main(){
	int q,h,s,d,n,mi = 0;
	cin >> q >> h >> s >> d >> n;
	if(n % 2){
		cout << (int)(n / 2) * min({q * 8,h * 4,s * 2,d}) + min({q * 4,h * 2,s}) << endl;
	}
	else cout << (int)(n / 2) * min({q * 8,h * 4,s * 2,d}) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <typeinfo>
#include <cstring>
#include <iostream>
#define NIL (-1)
#define L 14
using namespace std;
int n,A[50];

int solve(int i,int m){
    if(m == 0)return 1;
    if(i >= n)return 0;
    int res = solve(i + 1,m) || solve(i + 1,m - A[i]);
    return res;
}

int main(){
    int q,M,i;
    
    cin >> n;
    for(i = 0; i < n; i++)cin >> A[i]; cin >> q;
    for(i = 0; i < q; i++){
        cin >> M;
        if(solve(0,M))cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}


Measured memory_bytes: 3104
#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
#include <vector>
#include<math.h>


using namespace std;

bool f[1000002];

int main(){
	for(int i=3;i<1000001;i+=2){f[i]=true;
		for(int j=3;j*j<=i;j+=2)
			if(i%j==0)f[i]=false;
	}
	f[2]=true;
	int n,p;
	while(1){
		cin>>n>>p;if(n==-1&&n==p)break;

		int r=0;
		int q[10001]={};
		int x=0;
		int y=n+1;
		while(1){
			if(f[y]==true)x++;
			if(x==p)break;
			y++;
		}
		n++;
		 vector<int> anslist;
		 for(int i=n;i<=y;i++)
			for(int j=i;j<=y;j++)
			{
				if(f[i]==true&&f[j]==true){
					anslist.push_back(i+j);
				
				//cout<<i<<" "<<j<<endl;
				}
			}
			sort(anslist.begin(),anslist.end());
/*
		for(int i=n;i<=y;i++)
			for(int j=i;j<=y;j++)
			{
				if(f[i]==true&&f[j]==true){
				q[r]=i+j;r++;
				}
			}

		/*	
		sort(q,q+r);
		for(int i=0;i<r;i++)
		cout<<q[i]<<endl;

		cout<<q[p-1]<<endl;*/
			  cout << anslist[p-1] << endl;

	}
	
	return 0;
}

Measured memory_bytes: 2248
#include <iostream>
#include <bits/stdc++.h>
#include <sstream>
#define PI 3.14159265358979323846264338327950L
#define ll long long
using namespace std;


int main()
{
    int n;
    cin >> n;
    vector<int> dp(3);
    for(int d=0; d<n; d++){
        vector<int> np(3,0);
        vector<int> c(3,0);
        for(int i=0; i<3; i++){
            cin >> c[i];
        }
        for(int i=0; i<3; i++){
            for(int j=0; j<3; j++){
                if(i != j){
                    np[i] = max(np[i], dp[j] + c[i]);
                }
            }
        }
        dp = np;
    }
    cout << max(dp[0], max(dp[1], dp[2]));
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repr(i,n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;



int main() {
    int n, m;
    cin >> n >> m;
    if ((n < 2) && (m < 2)) cout << 0 << endl;
    else if (n < 2) cout << m * (m-1) / 2 << endl;
    else if (m < 2) cout << n * (n-1) / 2 << endl;
    else cout << n * (n-1) / 2 + m * (m-1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a, b;
	cin>>a>>b;
	sort(a.begin(),a.end());
	sort(b.begin(),b.end(),greater<int>());
	//cout<<a<<endl<<b<<endl;
	if(a.compare(b)<0)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
N=int(input())
ans=0
cnt_a,cnt_b,cnt_c=0,0,0
for i in range(N):
    s=input()
    ans+=s.count("AB")
    s=s.replace("AB","")
    if s[0]=="B" and s[-1]=="A":
        cnt_c+=1
    elif s[0]=="B":
        cnt_b+=1
    elif s[-1]=="A":
        cnt_a+=1
if cnt_c==0:
    print(ans+min(cnt_a,cnt_b))
elif cnt_a+cnt_b == 0:
    print(ans+cnt_c-1)
else:
    print(ans+cnt_c+min(cnt_a,cnt_b))


Measured memory_bytes: 74380
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;
const int ny[4] = {-1,1,0,0}, nx[4] = {0,0,-1,1};
int sy,sx,gy,gx;

int main(){
  int n,m,c; cin >> n >> m >> c;
  vector<int> b(m);
  rep(i,m) cin >> b[i];
  vector<vector<int>> a(n);
  rep(i,n)rep(j,m){
    int temp; cin >> temp;
    temp *= b[j];
    a[i].push_back(temp);
  }
  int ans = 0;
  rep(i,n){
    int s = 0;
    rep(j,m){
      s += a[i][j];
    }
    s += c;
    if(s > 0) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from operator import itemgetter
n, m = map(int, input().split())

ab = [tuple(map(int, input().split())) for i in range(m)]

ab = sorted(ab, key=itemgetter(1))

count = 0
cut = 0
for i in range(m):
    if cut <= ab[i][0]:
        count += 1
        cut = ab[i][1]

print(count)

Measured memory_bytes: 18976
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
typedef pair <int, int> cn;
const int N = 1e5 + 100;

int main() {
	long long sum = 0;
	int n, m, a[N];
	auto cmp = [](cn a, cn b) {
		return a.second < b.second;
	};
	priority_queue <cn, vector<cn>, decltype(cmp)> q(cmp);
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; ++i) {
		scanf("%d", a + i);
	}
	sort(a, a + n);
	for (int i = 0; i < m; ++i) {
		cn p;
		scanf("%d%d", &p.first, &p.second);
		q.push(p);
	}
	int i = 0;
	--m;
	for (; i < n; ++i) {
		cn t = q.top();
		int f = t.second;
		if (a[i] >= t.second) { break; }
		sum += t.second;
		q.pop();
		if (t.first-- > 1) {
			q.push(t);
			continue;
		}
		if (m-- == 0) {
			++i;
			break;
		}
	}
	for (;i < n; ++i) {
		sum += a[i];
	}
	cout << sum;
	return 0;
}


Measured memory_bytes: 1784
#define TEST_MODE true

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= (int)b; --i)
#define range(i, a, b, c) for (int i = a;             \
                                   c > 0 ? i < b : i > b; \
                                   i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long

#ifdef LOCAL_ENV

#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x)
#define dumpl(x) dump(x) << endl
#else
const bool test = false;
#define dump(x) 
#define dumpl(x)
#endif

#else
const bool test = false;
#define dump(x) 
#define dumpl(x)
#endif

int dx[] = { 1, 0, -1, 0 };
int dy[] = { 0, 1, 0, -1 };
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep)
{
	vector<string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep))
	{
		v.push_back(buffer);
	}
	return v;
}

template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
	return accumulate(begin, end, 0ll);
}

template<typename T>
T gcd(T a, T b)
{
	T c;
	while (a != 0) {
		c = a; a = b%a;  b = c;
	}
	return b;
}

template<typename T>
T bit_count(T N) {
	T cnt = 0;
	while (N) {
		if (N & 1) cnt++;
		N >>= 1;
	}
	return cnt;
}

struct Point {
	int y, x;
	bool operator < (const Point& r) {
		if (x < r.x) return true;
		else return false;
	}
};

class Solver {
public:
	int N, A, B;

	bool is_first_win() {
		while (true) {
			if (A + 1 != B) A += 1;
			else A -= 1;
			if (A < 1) return false;

			if (B - 1 != A) B -= 1;
			else B += 1;
			if (B > N) return true;
		}
	}

	void solve() {
		cin >> N >> A >> B;
		puts(is_first_win() ? "Alice" : "Borys");
	}
};

signed main()
{
	srand((unsigned int)time(NULL));
	cout << fixed << setprecision(20);
	auto ptr = new Solver();
	ptr->solve();
	delete ptr;
	//while (true) {
	//	if (cin.eof() == true) break;
	//	auto ptr = new Solver();
	//	ptr->solve();
	//	delete ptr;
	//}
	return 0;
}

Measured memory_bytes: 256
import sys
X,K,D = map(int,input().split())

if (abs(X)>abs(K*D)):
  print(abs(X)-abs(K*D))
  sys.exit()

alpha = X%D
count = K-(X//D)
if(alpha>abs(alpha-D)):
  count +=1
  alpha = abs(alpha-D)
  
beta = count%2
if beta==1:
  print(abs(alpha-D))
else:
  print(alpha)

Measured memory_bytes: 9024
function GCD(a,b)
    return b!=0 ? GCD(b,a%b) : a
end

function main()
    n=parse.(Int,readline())
    A=parse.(Int,split(readline()))
    all_gcd=A[1]
    for i=2:n
        all_gcd=GCD(all_gcd,A[i])
    end
    if all_gcd!=1
        println("not coprime")
        exit()
    end
    A_max=maximum(A)
    hurui=zeros(Int,A_max+10)
    for i=1:n
        hurui[A[i]]+=1
    end
    for i=2:A_max+10
        j=i
        cnt=0
        while j<=A_max+10
            if hurui[j]==true
                cnt+=hurui[j]
            end
            j+=i
        end
        if cnt>1
            println("setwise coprime")
            exit()
        end
    end
    println("pairwise coprime")
end
main()




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

int main(){
  cout << fixed << setprecision(5);
  int N; cin >> N;
  vector<double> v(N);
  for (int i=0;i<N;i++){
    cin >> v.at(i);
  }
  sort(v.begin(),v.end());
  double sum=v.at(0);
  for (int i=1;i<N;i++){
    sum=(sum+v.at(i))/2;
  }
  cout << sum << endl;
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());


void c_p_c()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
 // c_p_c();
  int n;
  cin >> n;
  string s="";
  while(n > 0)
  {
    int r = (n%26);
    int k = (n/26);
    if(r == 0)
    {
      s += 'z';
      k--;
     
    }
    else
    {
      s += ('a' + (r - 1));  
    }
    n = k;


  }
  for(int i = s.size()-1;i>=0;i--)
  {
    cout<<s[i];
  }

    return 0;
}



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

int main() {
  
  int h, a;
  cin >> h >> a;
  int x = 1;
  int i = 0;
  while(x){
    i++;
    h -= a;
    if(h <= 0){
      break;
    }
  }
  
  cout << i << endl;
  
  
}



Measured memory_bytes: 3592
n,m=map(int,input().split())
jouken=[]
for x in range(m):
  jouken.append(list(map(int,input().split())))

ans=0

for y in range(m-1):
  for z in range(y+1,m):
    if jouken[y][0]==jouken[z][0]:
      if not jouken[y][1]==jouken[z][1]:
        ans+=1


if ans>0:
  print(-1)
else:
  if m==0:
    if n==1:
      print(0)
    elif n==2:
      print(10)
    else:
      print(100)
  else:
    if n==0:
      ans1=[0]
    else:
      ans1=[0]*n
      ans1[0]=1
    for q in range(m):
      a=jouken[q][0]-1
    
      b=jouken[q][1]
      ans1[a]=b
    if ans1[0]==0 and n>1:
      print(-1)
    else:
      print(''.join(map(str,ans1)))
    




Measured memory_bytes: 9200
#include <stdio.h>
#include <string.h>

int main(){
  char s[258] = {}, tmp[258] = {};
  int m, h, i, l;
  while(scanf("%s", s) && s[0] != '-'){
    scanf("%d", &m);
    while(m--){
      scanf("%d", &h);
      strcpy(tmp, s + h);
      s[h] = '\0';
      strcat(tmp, s);
      strcpy(s, tmp);
    }
    puts(s);
  }
  return 0;
}

Measured memory_bytes: 600
s = input()[::-1]

dp = [0] * 13
dp[0] = 1
mod = 10 ** 9 + 7

for i, char in enumerate(s):
    dp_new = [0] * 13

    if char != '?':
        l = [int(char)]
    else:
        l = list(range(10))

    for k in l:
        tmp = pow(10, i, 13)
        tmp = (k * tmp) % 13

        for j in range(13):
            dp_new[(j + tmp) % 13] += dp[j]

    dp = []
    for x in dp_new:
        dp.append(x % mod)

print(dp[5])


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

const long long INF = 1ll << 60;

const int max_v = 300;
vector<vector<long long>> d(max_v, vector<long long>(max_v, INF));
vector<vector<long long>> nd(max_v, vector<long long>(max_v, INF));
int V;

void warshall_floyd(vector<vector<long long>> &d) {
    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main() {
    int n, m, l;
    cin >> n >> m >> l;
    V = n;
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        d.at(a).at(b) = d.at(b).at(a) = c;
    }

    warshall_floyd(d);

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (d.at(i).at(j) <= l) nd.at(i).at(j) = 1;
        }
    }

    warshall_floyd(nd);
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int s, t;
        cin >> s >> t;
        s--; t--;
        cout << (nd.at(s).at(t) != INF ? nd.at(s).at(t) - 1 : -1) << endl;
    }
}

Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long int ll;

const ll INF=100000000;

int H,W,K;
string S[1005];

int choco[15][1005];
int B[15];

int Pow(int a,int b){
    int res=1;
    for(int i=0;i<b;++i)res*=a;
    return res;
}

int calc_choco(int x,int y,int pline_x,int pline_y){
    int cnt;
    if(pline_y==0){
        if(pline_x==0)cnt=choco[y-1][x-1];
        else cnt=choco[y-1][x-1]-choco[y-1][pline_x-1];
    }
    else if(pline_x==0)cnt=choco[y-1][x-1]-choco[pline_y-1][x-1];
    else cnt=choco[y-1][x-1]-choco[pline_y-1][x-1]-choco[y-1][pline_x-1]+choco[pline_y-1][pline_x-1];
    return cnt;
}

int calc(int b){
    int res=0;
    vector<int> line_y;
    int pline_x=0;
    int pline_y=0;
    for(int i=1;i<H;++i){
        if((b&B[i])==B[i])line_y.push_back(i);
    }
    line_y.push_back(H);
    //cout<<"y=";
    //for(auto u:line_y)cout<<u<<" ";
    //cout<<endl;
    for(int x=1;x<=W;++x){
        pline_y=0;
        int cnt;
        for(auto y:line_y){
            cnt=calc_choco(x,y,pline_x,pline_y);
            //cout<<"(pline_x,pline_y)="<<pline_x<<" "<<pline_y<<endl;
            //cout<<"(x,y)="<<x<<" "<<y<<endl;
            //cout<<"cnt="<<cnt<<endl;
            if(cnt>K){
                pline_x=x-1;
                res++;
            }
            if(x==W){
                //cout<<calc_choco(x,y,pline_x,pline_y)<<endl;
                if(calc_choco(x,y,pline_x,pline_y)>K)return INF;
            }
            pline_y=y;
        }
    }
    return line_y.size()+res-1;
}

int main(){
    for(int i=0;i<15;++i)B[i]=Pow(2,i);
    int ans=10000005;
    cin>>H>>W>>K;
    for(int i=0;i<H;++i)cin>>S[i];
    for(int y=0;y<H;++y){
        for(int x=0;x<W;++x){
            int c=S[y][x]-'0';
            if(y==0){
                if(x==0)choco[y][x]=c;
                else choco[y][x]=choco[y][x-1]+c;
            }
            else {
                if(x==0)choco[y][x]=choco[y-1][x]+c;
                else choco[y][x]=choco[y-1][x]+(choco[y][x-1]-choco[y-1][x-1])+c;
            }
            //cout<<choco[y][x]<<endl;
        }
    }
    if(choco[H-1][W-1]<=K)cout<<0<<endl;
    else{
        for(int i=2;i<=B[H]-1;++i)ans=min(ans,calc(i));
        cout<<ans<<endl;
    }

}

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

ll N, M;
vector<ll> E[100000], R[100000];
ll parent[100000];
bool path[100000];

void dfs(ll v, ll p) {
  for (ll u : R[v]) if (!path[u]) return;

  parent[v] = p;
  path[v] = true;

  for (ll u : E[v]) dfs(u, v);

  path[v] = false;
}

int main(void) {
  cin >> N >> M;
  REP(i, 0, N + M - 1) {
    ll A, B;
    cin >> A >> B, A--, B--;
    E[A].push_back(B);
    R[B].push_back(A);
  }

  ll root;
  REP(i, 0, N) if (R[i].size() == 0) root = i;

  dfs(root, -1);

  REP(i, 0, N) cout << parent[i] + 1 << endl;
}

Measured memory_bytes: 15744
/*
 * a.c
 *
 *  Created on: 2017/06/13
 *      Author: AWV060608
 */

#include	<stdio.h>
#include	<string.h>
//#include	<math.h>

int		main(void)
{
	int		a, b;
	char	op[10];	//"+"(???)???"-"(???)???"*"(???)???"/"(???)

	while(1)
	{
		scanf("%d",&a);
		scanf("%s",op);
		scanf("%d",&b);

		if( strcmp("?", op) ==0)
			break;
		else if( strcmp("+", op) ==0)
			printf("%d\n",a+b);
		else if( strcmp("-", op) ==0)
			printf("%d\n",a-b);
		else if( strcmp("*", op) ==0)
			printf("%d\n",a*b);
		else
			printf("%d\n",a/b);
	}
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){

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

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

	cout << a[0] << " " << a[a.size() - 1] << " " << sum << endl;

	return 0;
}


Measured memory_bytes: 3184
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

int main(){
    int r,D,x;

    cin >> r >> D >> x;

    for(int i = 0;i < 10;i++){
        int y = r*x-D;
        cout << y << endl;
        x = y;
    }

    return 0;
}

Measured memory_bytes: 256
use std::collections::HashSet;
use std::io::{self, BufRead, Read};

fn main() {
    let stdin = io::stdin();
    let mut stdin = stdin.lock();
    for _ in stdin.by_ref().bytes().take_while(|r| r.as_ref().unwrap() != &b'\n') {}

    let mut set = HashSet::with_capacity(100_000);
    for a in stdin.lines() {
    	let a: u32 = a.unwrap().parse().unwrap();
        if ! set.remove(&a) { set.insert(a); }
    }

    println!("{}", set.len());
}

Measured memory_bytes: 4352
# ABC068C - Cat Snuke and a Voyage (ARC079C)
def main():
    N, M, *AB = map(int, open(0).read().split())
    sources, targets = set(), set()
    for a, b in zip(*[iter(AB)] * 2):
        if a == 1:
            sources.add(b)
        if b == N:
            targets.add(a)
    flg = sources & targets  # intermediate point of both 1, N exists?
    print("POSSIBLE" if flg else "IMPOSSIBLE")


if __name__ == "__main__":
    main()

Measured memory_bytes: 46660