akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli x,k;
vll r;
lli q;
vll t,a;

int main(){
  cin >> x >> k;
  r = vll(k+1);
  for(lli i = 1;i <= k;i++) cin >> r[i];
  cin >> q;
  t = a = vll(q);
  for(lli i = 0;i < q;i++) cin >> t[i] >> a[i];
  lli l,u,s;
  l = 0;u = x;s = 0;
  for(lli i = 0,j = 0;i < q;i++){
    while(j+1 <= k && r[j+1] < t[i]){
      if(j%2){
        lli d = min(r[j+1]-r[j],x-l-s);
        u = min(u,x-s-d);
        s += d;
      }else{
        lli d = max(r[j]-r[j+1],-u-s);
        l = max(l,-s-d);
        s += d;
      }
      j++;
    }
    if(j%2){
      lli d = min(t[i]-r[j],x-l-s);
      u = min(u,x-s-d);
      s += d;
    }else{
      lli d = max(r[j]-t[i],-u-s);
      l = max(l,-s-d);
      s += d;
    }
    r[j] = t[i];
    if(a[i] <= l) cout << l+s << endl;
    else if(a[i] >= u) cout << u+s << endl;
    else cout << a[i]+s << endl;
  }


  return 0;

}


Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

using namespace std;
typedef long long ll;

ll N, X, M;

bool used[100005];
int idx[100005];

vector<ll> sum;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> X >> M;
    ll cur = X;
    ll s = 0;
    int i = 0;
    if(X == 0){
        cout << 0 << endl;
        return 0;
    }
    if(X == 1){
        if(M != 1) cout << N << endl;
        if(M == 1) cout << 0 << endl;
        return 0;
    }
    // if(N == 1){
    //     cout << X << endl;
    //     return 0;
    // }
    while(!used[cur]){
        // cout << cur << endl;
        used[cur] = true;
        idx[cur] = i;
        s += cur;
        cur = (cur*cur)%M;
        i++;
        sum.push_back(s);
    }
    if(N < i){
        cout << sum[N-1] << endl;
        return 0;
    }
    // cout << cur << ' ' << idx[cur] << endl;
    ll loop = i-idx[cur];
    ll ans = 0;
    if(idx[cur] > 0) ans += sum[idx[cur]-1];
    ll before_loop = ans;
    // cout << before_loop << endl;
    ll m = N-(idx[cur]);
    ll sum_loop = (sum[i-1]-before_loop);
    ans += sum_loop*(m/loop);
    if(idx[cur] == 0 && loop == 1){
        cout << ans << endl;
        return 0;
    }
    // cout << sum_loop << ' ' << m << ' ' << loop << endl;
    ans += (sum[idx[cur]+(m%loop)-1]-before_loop);
    cout << ans << endl;
}

Measured memory_bytes: 4360
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	cnt7 := 0
	cnt5 := 0
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	arr := strings.Split(sc.Text(), " ")
	for i := 0; i < 3; i++ {
		if arr[i] == "7" {
			cnt7++
		}
		if arr[i] == "5" {
			cnt5++
		}
	}
	if cnt7 == 1 && cnt5 == 2 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A, B ,C;
    cin >> A >> B >> C;
    int x=A+B;
    if( x>=C ){
        cout << B+C << endl;
    }else{
        if(x+1==C){cout<<B+C;}
        else{cout<<x+B+1<<endl;}
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
// #include <cstdio>

using namespace std;

int main() {
    string s;
    
    while(1) {
        cin >> s;
        if(s == "0") break;
        int sum = 0;
        // cout << "文字列の長さ :" << s.length() << endl;
        for(int i = 0; i < s.length(); i++) {
            sum += s[i] - '0';
        }
        cout << sum << endl;
    }

    return 0;
}


Measured memory_bytes: 3164
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, gcd, lcm 
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <vector> // vectors
#include <string> // string
#include <queue> // queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <unordered_map> // hashed by keys
#define _for(i,n) for(int i = 0; i < n; i++)

typedef long long ll; // at least int64 > 9*10^18
typedef unsigned long long ull; // at least uint64

std::vector<int> par;
int root(int i) {
  if(par[i]==i) return i;
  return par[i] = root(par[i]);
}

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if(x==y)return;
  par[x] = y;
}

int main() {
  int n,m;
  std::cin >> n >> m;
  par.resize(n);
  std::iota(par.begin(),par.end(),0);
  int x[m][2];
  int z[m];
  _for(i,m) {
    std::cin >> x[i][0] >> x[i][1] >> z[i];
    _for(j,2) x[i][j]--;
    unite(x[i][0],x[i][1]);
  }
  int count = 0;
  _for(i,n) {
    if(root(i)==i) {
      count++;
    }
  }
  std::cout << count << std::endl;

  return 0;
}

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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    char a, b;
    cin >> a >> b;

    // 処理
    // 出力
    // HH	H
    // HD	D
    // DH	D
    // DD	H
    if (a == 'H' && b == 'H') {
        cout << "H" << endl;
    } else if (a == 'H' && b == 'D') {
        cout << "D" << endl;
    } else if (a == 'D' && b == 'H') {
        cout << "D" << endl;
    } else {
        cout << "H" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	int N,x=0,MAX=0;
	string S;
	cin >> N;
	cin >> S;
	for (int i = 0; i < N; i++){
		if (S[i] == 'I'){ x++; }
		if (S[i] == 'D'){ x--; }
		if (MAX < x){ MAX = x; }
	}
	cout << MAX << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<(int)(r); i++)
#define rep_eq(i,l,r) for(int i=l; i<=(int)(r); i++)
#define all(vec) vec.begin(),vec.end()
#define allr(vec) vec.rbegin(),vec.rend()
using namespace std;

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

using ll=int64_t;

using vb=vector<bool>;
using vc=vector<char>;
using vs=vector<string>;
using vi=vector<int>;
using vll=vector<ll>;
using vvi=vector<vi>;

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

  int N; cin >>N;
  string S; cin >>S;

  vi w_sum(N+2);
  vi e_sum(N+2);

  rep(i,1,N+1) {
    if (S[i-1]=='W') {
      w_sum[i]=w_sum[i-1]+1;
    } else {
      w_sum[i]=w_sum[i-1];
    }
  }

  reverse(all(S));
  rep(i,1,N+1) {
    if (S[i-1]=='E') {
      e_sum[i]=e_sum[i-1]+1;
    } else {
      e_sum[i]=e_sum[i-1];
    }
  }
  reverse(all(e_sum));

  int ans=INT_MAX;
  rep(i,1,N+1) {
    chmin(ans,w_sum[i-1]+e_sum[i+1]);
  }

  cout <<ans <<'\n';
  return 0;
}


Measured memory_bytes: 6124
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include<tuple>
using namespace std;

int main()
{
    int n, cnt = 1;
    cin >> n;
    vector<tuple<string,int,int>> a(n);
    int p;
    string s;
    for(int i = 0;i < n;i++){
        cin >> s >>p;
        a[i] = make_tuple(s, -p, i + 1);
    }

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

    for(int i = 0;i < n;i++){
        cout << get<2>(a[i]) << "\n";
    }    
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100

int main(){
int a[N],i,j,n,m=0,tmp;
scanf("%d",&n);
for(i=0;i<n;i++)scanf("%d",&a[i]);
for(i=0;i<n;i++){
for(j=n-1;j>i;j--){
if(a[j]<a[j-1]){
tmp=a[j];
a[j]=a[j-1];
a[j-1]=tmp;
m++;
}
}
}
for(i=0;i<n;i++){
if(i==n-1)printf("%d\n",a[i]);
else printf("%d ",a[i]);
}
printf("%d\n",m);
return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

struct edge{int c,s,f;};

int main(){
    int n;
    cin >> n;
    vector<edge> v(n-1);
    rep(i,n-1){
        int a,b,c;
        cin >> a >> b >> c;
        v[i].c = a;
        v[i].s = b;
        v[i].f = c;
    }
    
    for (int i = 0;i < n-1;i++){
        int now = v[i].s;
        now += v[i].c;
        for (int j = i+1;j < n-1;j++){
            int tmp = v[j].s/v[j].f;
            while (tmp*v[j].f < now){
                tmp++;
                //cout << tmp*v[j].f << endl; 
            }
            now = tmp*v[j].f + v[j].c;
        }
        cout << now << endl;;
    }
    cout << 0 << endl;
    

    return 0;
    
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner c = new Scanner(System.in);
        int a = c.nextInt();
        int b = c.nextInt();
        int tower[] = new int[1000];
        int k = 0;
        for (int i = 1; i <= 999; i++) {
            k = k + i;
            tower[i] = k;
        }
        if (b - a == tower[b - a] - tower[b - a - 1]) {
            System.out.println(tower[b - a -1] - a);
        }
    }
}


Measured memory_bytes: 21456
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    long long N, Q;
    cin >> N >> Q;
    int R = N-1, C = N-1;
    long long res = (N - 2) * (N - 2);
    vector<long long> yoko(N, N-1), tate(N, N-1);
    for (int q = 0; q < Q; ++q) {
        int type, x;
        cin >> type >> x;
        --x;

        // (0, x) に置く
        if (type == 1) {
            if (x > C) res -= tate[x] - 1;
            else {
                res -= R - 1;
                tate[x] = 0;
                for (int c = C-1; c > x; --c) tate[c] = R;
                C = x;
            }
        }
        // (x, 0) に置く
        else {
            if (x > R) res -= yoko[x] - 1;
            else {
                res -= C - 1;
                yoko[x] = 0;
                for (int r = R-1; r > x; --r) yoko[r] = C;
                R = x;
            }
        }
    }
    cout << res << endl;
}

















Measured memory_bytes: 6276
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int x, y, s;
	while (cin >> x >> y >> s && (x || y || s)) {
		vector<vector<int> > tax(1000, vector<int>(2));
		int maxi = 0, i = 0, a = 1, b;
		while (a < s) {
			b = (s - (int)((a * (100 + x)) / 100.0) + 1) / ((100 + x) / 100.0);
			if (((int)((a * (100 + x)) / 100.0) + (int)((b * (100 + x)) / 100.0)) == s && b != 0) {
				tax[i][0] = a; tax[i][1] = b;
				maxi = max(maxi, (int)((tax[i][0] * (100 + y)) / 100.0) + (int)((tax[i][1] * (100 + y)) / 100.0));
				i++;
			}
			a++;
		} 

		cout << maxi << endl;
	}

	return 0;
}


Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;
const int N = 2e5 + 5;

int a[N];
int vis[N];
int b[N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,k;cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	bool ok=true;
	int idx=1;
	int tot=0;
	int L=0;
	b[++tot]=idx;vis[idx]++;
	for(;ok;){
		idx=a[idx];
		if(vis[idx]==2){
			L=idx;
			break;
		}
		vis[idx]++;
		b[++tot]=idx;
	}
	int cnt=0;
	for(int i=1;i<=tot;i++){
		if(b[i]==L) {cnt=i-1;break;}
	}
	k++;
	int base=tot-cnt;
	if(k<=tot){
		cout<<b[k]<<'\n';
	}else{
		int f=(k-tot)%base;
		if(f==0) f=base;
		cout<<b[f+cnt]<<'\n';
	}
	return 0;
}

Measured memory_bytes: 5964
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
 
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(in, out);
		out.close();
	}
	
	
	static class Task{
		long M = (long) (1e18);
		
		public void solve(InputReader in, PrintWriter out) {
			String line = in.next();
			
			char d[] = line.toCharArray();
			long []chars = new long[26];
 			
			long sum = 0;
			long len = line.length();
			for(char c : d) {
			         chars[c-'a']++;
			}
			sum = len*(len-1)/2;
			for(long x :chars)
			{
				if(x > 1) {
					sum -= x*(x-1)/2;
				}
			}
			System.out.println(sum+1);
			
		}//solve

		
		}//Task
	
	
	
	//InputReader
	static class InputReader{
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}
		public String next() {
			while(tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public float nextFloat() {
			return Float.parseFloat(next());
		}
		
	}
}

Measured memory_bytes: 25300
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n');
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr('time : ' + end + 'ms');
  myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var output = "";
  var map = {};
  var list = "abcdefghijklmnopqrstuvwxyz".split("");
  for(var i = 0; i < list.length; i++){
    map[i + 1] = list[i];
  }
  map[0] = "z";
  var count = 1;
  while(true){
    var min = Math.pow(26, count) + Math.pow(26, count - 1);
    if(N >= min){
      count++;
    }else{
      break;
    }
  }
  while(N > 0){
    var single = N % 26;
    if(single == 0){
      N -= 26;
    }
    output = map[single] + output;
    N = Math.floor(N / 26);
  }
  myout(output);
}


Measured memory_bytes: 30052
#include<bits/stdc++.h>
using namespace std;
#define pb  push_back
#define mod 1000000007
#define INF 1e18
typedef  long long ll;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n,m;
	cin>>n>>m;
	vector<vector<int>> v(n+1);
	for (int i = 0; i < m; ++i)
	{
		int a,b;
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	int c=0;
	int vis[n+1];
	for (int i = 0; i < n+1; ++i)
	{
		vis[i]=0;
	}
	for (int i = 1; i <= n; ++i)
	{
		if(vis[i]==0){
			c++;
			queue <int> q;
			q.push(i);
			while(!q.empty()){
				int a=q.front();
				q.pop();
				for (int j :v[a])
				{
					if(vis[j]==0){
						vis[j]=1;
						q.push(j);
					}
				}
			}
		}
	}
	cout<<c-1;
	return 0;
}

Measured memory_bytes: 8716
import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int X  = keyboard.nextInt();
		int Y  = keyboard.nextInt();
		
		int HW = 0;
		
		for(int i=0; i<Y; i++) {
			HW += keyboard.nextInt();
		}
		
		int P = -1;
		if(X - HW >= 0) {
			P = X - HW;
		}
		
		System.out.println(P);
		keyboard.close();	
	}
}


Measured memory_bytes: 46748
#include <stdio.h>

int right_trianglep(int a, int b, int c)
{
        //Find longest edge;
        int max;
        max = a;
        if(max < b) max = b;
        if(max < c) max = c;
        //Check
        if(max == a)
                return (max*max == (b*b+c*c));
        else if(max == b)
                return (max*max == (a*a+c*c));
        else
                return (max*max == (a*a+b*b));
}

int main()
{
        int n;
        int a,b,c;
        scanf("%d",&n);
        for(;n > 0; n--) {
                scanf("%d %d %d",&a,&b,&c);
                if(right_trianglep(a,b,c)) 
                        printf("YES\n");
                else
                        printf("NO\n");
        }
        return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    if(n * a < b)
    {
       cout << n * a << endl;
    }else{
        cout << b << endl;
    }
    return 0;
}


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

def gcd(a, b):
    while a > 0:
        if a < b:
            a, b = b, a
        a = a % b
    return b

def main():
    n, x = map(int, input().split())
    distance = (abs(x - int(y)) for y in input().split())

    res = next(distance)
    for d in distance:
        res = gcd(res, d)

    print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 11172
#include<iostream>
#include<string>
int main()
{
    std::string  s,t1,t2;
    std::cin>>s;
    std::cin>>t1;
    std::size_t lg=t1.length();
    t2=t1.erase(lg-1,1);
    if(s==t2){
        std::cout<<"Yes";
    }else{
        std::cout<<"No";
    }
    std::cout<<std::endl;
}

Measured memory_bytes: 3628
class Tree
  class Node
    attr_reader :id, :distance

    def initialize(id, distance)
      @id = id
      @distance = distance
    end

    def children
      @children ||= []
    end
  end

  def initialize(size)
    @size = size
    @nodes = []
    @info = {}
  end

  def add(x, y, d)
    d = d % 2
    @info[x] ||= []
    @info[x] << [y, d]
    @info[y] ||= []
    @info[y] << [x, d]
  end

  def build
    @root = Node.new(1, 0)
    @nodes[@root.id] = @root
    q = [@root.id]
    until q.empty? do
      id = q.shift
      node = @nodes[id]
      @info[id].each do |c, d|
        next unless @nodes[c].nil?

        d = node.distance + d
        n = Node.new(c, d % 2)
        @nodes[c] = n
        node.children << n

        q << c
      end
    end
  end

  def colors
    @nodes.drop(1).map(&:distance)
  end
end

def print_node(node, indent = 0)
  puts ' ' * indent + node.id.to_s
  node.children.each do |c|
    print_node(c, indent + 2)
  end
end

n = gets.chomp.to_i

t = Tree.new(n)

(n-1).times do
  u, v, w = gets.chomp.split(' ').map(&:to_i)
  t.add(u, v, w)
end

t.build
t.colors.each do |c|
  puts c
end


Measured memory_bytes: 38524
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N-1];
		int[] count = new int[N];
		for(int i = 0;i < N-1;i++){
			A[i] = sc.nextInt();
		}
		for(int i = 0;i < N-1;i++){
			count[A[i]-1]++;
		}
		for(int num : count){
			System.out.println(num);
		}
		sc.close();

	}

}

Measured memory_bytes: 62776
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/**
 * 境界部分には気をつける(そこだけ別で処理するというのもあり)
 * 逆再生することで簡単になることもある
 */
public class Main {
    public Main() {
    }

    public static void main(String[] args ) {
            Main main = new Main();
            main.exec();
    }

    public void exec() {
        BufferedReader bf = null;
        try{
            bf = new BufferedReader(new InputStreamReader(System.in));
            exec_body(bf);
        } catch (IOException e) {
            e.printStackTrace();
        }
        finally{
            if( bf != null ) {
                try {
                    bf.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public ArrayList<Integer> toList( String line ) {
    		ArrayList<Integer> list = new ArrayList<>();
    		if ( line == null || line.length() == 0 ) {
    			return list;
    		}

    		String[] lines = line.split(" ");
    		for( int i = 0; i < lines.length; i++ ) {
    			String element = lines[i];
    			list.add(Integer.valueOf(element));
    		}

    		return list;
    }

    public boolean isCalculable( int m, ArrayList<Integer> aList ) {
    		for( int ii = 0; ii < Math.pow(2, aList.size()); ii++) {
    			int val = 0;
        		for( int kk = 0; kk < aList.size(); kk++ ) {
        			int flag = ( ii >>> kk ) & 0b01;
        			if( flag == 1 ) {
        				val = val + aList.get(kk);
        			}
        		}
        		if( m == val ) {
        			return true;
        		}
    		}

    		return false;
    }

    public void exec_body( BufferedReader bf ) throws IOException {
    		bf.readLine();
    		ArrayList<Integer> aList = toList(bf.readLine());
    		bf.readLine();
    		ArrayList<Integer> mList = toList(bf.readLine());

    		for( Integer mVal : mList ) {
    			boolean isCalculable = isCalculable(mVal,aList);
    			String msg = isCalculable ? "yes" : "no";
    			System.out.println(msg);
    		}
    }
}


Measured memory_bytes: 25648
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt(); sc.nextLine()
    val S = Array.fill(N)(sc.nextLine())

    val candidates = S.groupBy(_(0)).filter {
      case (key, _) => key match {
        case 'M' | 'A' | 'R' | 'C' | 'H' => true
        case _ => false
      }
    }. mapValues(_.length)

    val result = candidates.keys.toSeq.combinations(3)
      .foldLeft(0L)((b, n) => b + n.foldLeft(1L)(_ * candidates(_)))

    println(result)
  }

}


Measured memory_bytes: 108772
#include <cstring>
#include <cstdint>
#include <iostream>
#include <string>
#include <memory>
#include <queue>
#include <stack>
#include <limits>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <sstream>
#include <random>
#include <functional>
#include<algorithm>
#include <array>
#include<random>
using namespace std;

int main(){
	uint64_t N;
	uint64_t ulim = 1;
	uint64_t ans = 0;
	cin >> N;
	uint64_t A;
	cin >> A;
	if(A != 0) {
		cout << -1;
		return 0;
	}
	for (size_t i = 1; i < N; i++)
	{
		cin >> A;
		if (A > ulim) {
			cout << -1;
			return 0;
		}
		else {
			if(A < ulim)ans += A;
			if (A == ulim)++ans;
			ulim = A + 1;
		}
	}
	cout << ans;
 	return 0;
}

Measured memory_bytes: 384
package main
 
import (
	"fmt"
)
 
func main() {
	var S string
	fmt.Scanf("%s", &S)
	var T string
	fmt.Scanf("%s", &T)

	var max = 0

	for n:=0 ; n < len(S) - len(T) +1; n++{
		var count = 0
		var str = S[n:n+len(T)]

		for i:=0; i < len(T); i++{
			if T[i] == str[i]{
				count += 1
			}
		}

		if max < count{
			max = count
		}	
	}

	fmt.Printf("%d\n", len(T)-max)
}

Measured memory_bytes: 1848
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include<math.h>
using namespace std;

 int main(){
   int n; cin >> n;
   string s = to_string(n);
  for(int i=0;i<s.size();i++){
   if(s[i]=='1') s[i]='9';
   else s[i]='1';
  }
   cout << s <<endl;
 }

Measured memory_bytes: 256
/*
[abc125] C - GCD on Blackboard
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e5;

int N;
int A[MAX_N];
int l[MAX_N + 1], r[MAX_N + 1];

int gcd(int a, int b) {
    while (b > 0) {
        swap(b, a %= b);
    }
    return a;
}

ll solve() {
    l[0] = 0;
    for (int i = 0; i < N; i++) {
        l[i + 1] = gcd(l[i], A[i]);
    }
    r[N] = 0;
    for (int i = N; i > 0; i--) {
        r[i - 1] = gcd(r[i], A[i - 1]);
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans = max(ans, gcd(l[i], r[i + 1]));
    }

    return ans;
}

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

    cout << solve() << endl;

    return 0;
}


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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;

signed main(){
    int K;
    cin >> K;
    queue<ll> que;
    for(ll i = 1; i < 10; i++) que.push(i);
    REP(i, K - 1){
        ll x = que.front();
        que.pop();
        if(x % 10 != 0) que.push(10 * x + x % 10 - 1);
        que.push(10 * x + x % 10);
        if(x % 10 != 9) que.push(10 * x + x % 10 + 1);
    }
    PRINT(que.front());
    return 0;
}

Measured memory_bytes: 1792
N = int(input())
A = list(map(int,input().split()))
i = 0
B = 0
C = 100000000000000
D = 0
#B = max(A) - min(A)
#print(abs(B))
while("Treu"):
    if B < A[i]:
        B = A[i]
    if C > A[i]:
        C = A[i]
    i+=1
    if i == N :
        break
D = B - C
print(abs(D))


Measured memory_bytes: 3060
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>
#include <iomanip>
using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;
const int INF = 1e9;
 
long long gcd(long long x, long long y){
			if (x==0)return y;
      if(y==0)return x;
      if(x<y){
				long long temp = x;
			x = y;
				y = temp;
			}
			long long r = x % y;
				while(r!=0){
					x = y;
					y = r;
				r = x % y;
	    		}
			return y;
	    }


int main(){
int N,M;
cin >> N >> M;
vector<int> L(M),R(M);
for(int i =0;i<M;i++){
	cin >> L[i] >> R[i];
}
int saisyou = L[0];
int saidai = R[0];
bool ans = true;
for(int i = 1;i<M;i++){
	saisyou = max(saisyou,L[i]);
	saidai = min(saidai,R[i]);
	if(saidai-saisyou<0)ans = false;
}

if(ans)cout << saidai - saisyou + 1 << endl;
else cout << 0 << endl;

}

Measured memory_bytes: 1024
n = int(input())
N = list(map(int, input().split()))

L=[]
for n in N:
    if n%2==0:
        L.append(n)
ans='APPROVED'
for l in L:
    if l%3==0 or l%5==0:
        ans='APPROVED'
    else:
        ans='DENIED'
        break


print(ans)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atc_0033
{
    class Program
    {
        static void Main(string[] args)
        {

            var s = Console.ReadLine();

            double T = double.Parse(s.Split(' ')[0]);
            double X = double.Parse(s.Split(' ')[1]);

            double result = T / X;
          
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 27620
D,*CS = map(int, open(0).read().split())
C = CS[:26]
S = [CS[26*i:26*(i+1)] for i in range(1, D+1)]

def imax(xs):
    m = -1
    i = 0
    for j, x in enumerate(xs):
        if x > m:
            i = j
            m = x
    return i

ds = [0] * 26

def pick(d):
    ss = S[d]
    dp = [(d + 1 - ds[i]) * x for i, x in enumerate(C)]
    total = sum(dp)
    tt = [total - x for x in dp]
    st = [s - t for s, t in zip(ss, tt)]
    return imax(st)

for d in range(D):
    i = pick(d)
    ds[i] = d
    print(i + 1)

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

int main() {
	int N, sum = 0;
	cin >> N;
	vector<int> W(N);
	for (int i = 0; i < N; i++) {
		cin >> W.at(i);
		sum += W.at(i);
	}

	int ans = sum;
	int x = 0;
	for (int i = 0; i < N; i++) {
		x += W.at(i);
		ans = min(ans, abs(x - (sum-x)));
	}

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

Measured memory_bytes: 256
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
N = int(input())
A = list(map(int, input().split()))
M = [0] * (10**6+1)
for i in A:
    M[i] += 1
if gcd_list(A) > 1:
    print('not coprime')
    exit()
for i in range(2,10**6+1):
    c = 0
    for j in range(i,10**6+1,i):
        c += M[j]
    if c > 1:
        print('setwise coprime')
        exit()
print('pairwise coprime')


Measured memory_bytes: 210412
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <queue>

using namespace std;
using ll = long long int;
using P = pair<int, ll>;

int main()
{
  int n;
  cin >> n;
  vector<vector<P>> tree(n, vector<P>());
  for(int i = 0; i < n - 1; i++)
  {
    int u, v;
    ll w;
    cin >> u >> v >> w;
    tree[u - 1].push_back({v - 1, w});
    tree[v - 1].push_back({u - 1, w});
  } 
  vector<int> color(n, 0);
  vector<bool> flag(n, false);
  queue<int> q;
  q.push(0);
  flag[0] = true;
  color[0] = 0;
  while(!q.empty()) {
    int cnum = q.front();
    q.pop();
    int ccolor = color[cnum];
    for(int i = 0; i < tree[cnum].size(); i++)
    {
      P next = tree[cnum][i];
      if(!flag[next.first]) {
        flag[next.first] = true;
        q.push(next.first);
        if(next.second % 2 == 0) {
          color[next.first] = ccolor;
        }else{
          color[next.first] = ccolor == 0 ? 1 : 0;
        }
      }
    }
  }
  for(auto e : color) {
    cout << e << endl;
  }
}


Measured memory_bytes: 8320
n=int(input())
a=list(map(int,input().split()))

odd=0
ni=0
si=0
for x in a:
    if x%4==0:
        si+=1
    elif x%2==0:
        ni+=1
    else:
        odd+=1
ni=ni%2
if odd+ni<=si+1:
    print("Yes")
else:
    print("No")

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

int main()
{
    int n, a[100], sum{}, thumnail{};
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", a + i);
        sum += a[i];
        a[i] *= n;
    }
    for (int i = 0; i < n; i++)
    {
        if (std::abs(a[i] - sum) < std::abs(a[thumnail] - sum)) thumnail = i;
    }
    printf("%d\n", thumnail);

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int Y = sc.nextInt(); 
        int Z = sc.nextInt();
        if(X + Y + Z >= 22) {
        	System.out.println("bust");
        }else {
        	System.out.println("win");
        }
    }
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greater<int>()

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

const int INF = 1001001001;
const int MOD = 1000000007;
const long long INFL = (1LL << 60);
const double EPS = 1e-9;

vector<uint64_t> divisor(uint64_t n) {
  vector<uint64_t> ret;
  for (uint64_t i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(all(ret));
  return ret;
}

int digit(uint64_t n) {
  int cnt = 0;
  while (true) {
    n /= 10;
    cnt++;
    if (n < 1) break;
  }
  return cnt;
}

int main() {
  uint64_t N;
  cin >> N;

  int res = INF;
  vector<uint64_t> div = divisor(N);
  rep(i, div.size()) rep(j, div.size()) {
    if (div[i] * div[j] != N) continue;
    res = min(res, max(digit(div[i]), digit(div[j])));
  }

  cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int H, W;
    cin >> H >> W;
    
    for (int i = 0; i < H + 2; i++) {
        for (int j = 0; j < W + 2; j++) {
            if (i == 0 || i == H + 1 || j == 0 || j == W + 1) {
                cout << "#";
            } else {
                char a;
                cin >> a;
                cout << a;
            }
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
 
typedef struct{
    long long int code;
    int steps;
} puzz;
 
int q[1000000][14],size[100000];
long long int FR,TO,SW;
puzz* hash[100000][20];
 
void swap (int* x,int* y){
    int z;
    z=*x;
    *x=*y;
    *y=z;
}
 
long long int convert(int a[]){
    long long int ret=0;
    int i;
    for(i=0;i<13;i++)ret=ret*13+a[i];
    return ret;
}
 
void hashadd(long long int code,int step){
    int ccc=code%100000;
    puzz* ppp=(puzz*)malloc(sizeof(puzz));
    ppp->code=code;
    ppp->steps=step;
    if(size[ccc]>19){fprintf(stderr,"SIZE OVER!! (%d)\n",ccc);return;}
    hash[ccc][size[ccc]]=ppp;
    size[ccc]++;
}
 
int hashsearch(long long int code){
    int ccc=code%100000;
    int i=size[ccc]-1;
    for(;i>=0;i--){
        if(hash[ccc][i]->code==code)return hash[ccc][i]->steps;
    }
    return -1;
}
 
void mark(int x,int y){
    int k;
    long long int cd;
 
    swap(&q[FR][x],&q[FR][y]);
    cd=convert(q[FR]);
 
    if(SW==1 || hashsearch(cd)<0){
        for(k=0;k<14;k++){q[TO][k]=q[FR][k];}
        q[TO][13]++;
        if(SW==0)hashadd(cd,q[TO][13]);
        TO++;
    }
 
    swap(&q[FR][x],&q[FR][y]);
 
}
 
void check(){
    if(q[FR][0]==0){mark(0,2);}
    if(q[FR][1]==0){mark(1,2);mark(1,5);}
    if(q[FR][2]==0){mark(2,0);mark(2,1);mark(2,3);mark(2,6);}
    if(q[FR][3]==0){mark(3,2);mark(3,7);}
    if(q[FR][4]==0){mark(4,5);}
    if(q[FR][5]==0){mark(5,1);mark(5,4);mark(5,6);mark(5,9);}
    if(q[FR][6]==0){mark(6,2);mark(6,5);mark(6,7);mark(6,10);}
    if(q[FR][7]==0){mark(7,3);mark(7,6);mark(7,8);mark(7,11);}
    if(q[FR][8]==0){mark(8,7);}
    if(q[FR][9]==0){mark(9,5);mark(9,10);}
    if(q[FR][10]==0){mark(10,6);mark(10,9);mark(10,11);mark(10,12);}
    if(q[FR][11]==0){mark(11,7);mark(11,10);}
    if(q[FR][12]==0){mark(12,10);}
}
 
 
int main(){
    int i,ans;
    long long int cd;
 
    for(i=1;i<12;i++)q[0][i]=i;
    q[0][0]=0;q[0][12]=0;q[0][13]=0;
    hashadd(convert(q[0]),0);
 
    FR=0;TO=1;SW=0;
 
    while(FR<TO && q[FR][13]<=13){
        check();
        FR++;
    }

    while(scanf("%d",&q[0][0])*q[0][0]>=0){
        for(i=1;i<13;i++)scanf("%d",&q[0][i]);
        q[0][13]=0;FR=0;TO=1;SW=1;ans=9999;
 
        while(FR<TO){
            cd=hashsearch(convert(q[FR]));
            if(cd>=0){
                ans=(int)cd+q[FR][13];
                break;
            }
            if(q[FR][13]<6)check();
            FR++;
        }
 
        if(ans>20)printf("NA\n"); else printf("%d\n",ans);
    }
 
    return 0;
}

Measured memory_bytes: 29540
package main

import (
	"fmt"
	"sort"
)

func main() {
	var (
		s string
		k int
	)
	fmt.Scan(&s, &k)

	array := make([]string, 0, 50000)
	for i := 'a'; i <= 'z'; i++ {
		for j, c := range s {
			if i == rune(c) {
				array = addSubstring(array, s[j:], k)
			}
		}
		sort.Strings(array)
		if len(array) == k {
			break
		}
	}

	fmt.Println(array[k-1])
}

func addSubstring(a []string, s string, k int) []string {
	for i := 0; i < min(k, len(s)); i++ {
		subs := s[0 : i+1]
		flag := true
		for _, t := range a {
			if t == subs {
				flag = false
				break
			}
		}
		if flag == true {
			a = append(a, subs)
		}
	}
	return a
}

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


Measured memory_bytes: 896
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace PaizaTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = Console.ReadLine().Split().Select(int.Parse).ToList();

            var As = Console.ReadLine().Split().Select(int.Parse).ToList();

            var sumA = As.Sum();
            var borderVoteCount = sumA / (4.0 * NM[1]);

            // sumA / (4 * M) >= Aiの場合のみ選べる

            var selectableCount = As.Count(x => x >= borderVoteCount);

            Console.WriteLine(selectableCount >= NM[1] ? "Yes" : "No");

        }
    }
}


Measured memory_bytes: 13396
import sys
sys.setrecursionlimit(1000000)
s=sys.stdin.readlines()
n,q=map(int,s[0].split())
G=[[]*n for i in range(n)]
P=[0]*n
V=[0]*n
R=[0]*n
for e in s[1:n]:
    a,b=map(int,e.split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
for e in s[n:]:
    c,d=map(int,e.split())
    P[c-1]+=d

def dsf(i,p):
    V[i]=1
    R[i]+=p+P[i]
    p=0
    for j in G[i]:
        if V[j]!=1:
            dsf(j,R[i])
dsf(0,0)
print(' '.join(map(str,R)))

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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;

using namespace std;


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 
	
	string s;
	int k;
	cin >> s >> k;
	
	int n = sz(s);
	
	rep(i , n){
		int need = 'z' - s[i] + 1;
		if(k > 0 && need <= k && s[i] != 'a'){
			s[i] = 'a';
			k -= need;
		}
	}
	
	
	
	k %= 26;
	
	while(k--){
		++s[n - 1];
		if(s[n - 1] > 'z')s[n - 1] = 'a';
		
	}
	cout << s << nl;
	
	return 0;
}

Measured memory_bytes: 592
def factorial(N,MOD,r=True):
    fact = [1]*(N+1)
    rfact = [1]*(N+1)
    r = 1
    for i in range(1,N+1):
        fact[i] = r = r * i % MOD
    rfact[N] = r = pow(fact[N],MOD-2,MOD)
    for i in range(N, 0, -1):
        rfact[i-1] = r = r * i % MOD
    if r:
        return fact,rfact
    else:
        return fact
mod = 10**9 + 7
fact,rfact = factorial(10**6,mod)

def perm(n,k): #上のfactorialと併用
    return fact[n]*rfact[n-k]%mod
def comb(n,k): #上のfactorialと併用
    return fact[n]*rfact[k]*rfact[n-k]%mod

x,y = map(int,input().split())
if (x+y)%3:
    print(0)
    exit()
a = (-x+2*y)//3
b = (2*x-y)//3

print(comb(a+b,a) if a >= 0 and b >= 0 else 0)

Measured memory_bytes: 54384
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

const int MOD = 1e9+7;

signed main() {
	int n,k;
	std::cin >> n >> k;
	std::vector<int> states;
	for(int i=1;i*i<=n;i++) {
		states.emplace_back(i);
		if(i!=n/i) states.emplace_back(n/i);
	}
	std::sort(all(states));
	int state_count = states.size();
	std::vector<int> a;
	std::vector<int> b;
	a.reserve(state_count);
	b.reserve(state_count);
	for(int i=0;i<state_count;i++) a[i] = states[i];
	for(int i=1;i<k;i++) {
		int last = 0;
		for(int j=0;j<state_count;j++) {
			b[j] = (states[j]-last)*a[state_count-1-j]%MOD;
			if(j!=0) b[j] = (b[j]+b[j-1])%MOD;
			last = states[j];
		}
		std::swap(a,b);
	}
	print(a[state_count-1]);
	return 0;
}


Measured memory_bytes: 1912
import java.math.BigInteger;
import java.util.*;


public class Main {
	
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int k = sc.nextInt();
			int [] data = new int[n];
			for(int i = 0; i < n; i++){
				data[i] = sc.nextInt();
			}
			for(int i = 1;i < n; i++){
				if((k - 1) * i + 1 >= n){
					System.out.println(i);
					break;
				}
			}
			
		}
	}
	
	private long calc(long n, long m, long l){
		long sum = 1;
		for(long i = n; i > m; i--){
			sum *= i;
		}
		for(long i = 2; i <= l; i++){
			sum /= i;
		}
		return sum;
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


Measured memory_bytes: 50992
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    
    cout << (char)((int)s1.at(0)-32)<< (char)((int)s2.at(0)-32)<< (char)((int)s3.at(0)-32)<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = []
b = []
for i in range(n):
	a_1, b_1 = input().split()
	a.append(int(a_1))
	b.append(int(b_1))
a.sort()
b.sort()
is_odds = n % 2 == 0
a_med = a[(n + 1) // 2 - 1] if not is_odds else a[n // 2 - 1] + a[n // 2]
b_med = b[(n + 1) // 2 - 1] if not is_odds else b[n // 2 - 1] + b[n // 2]
print(b_med - a_med + 1)

Measured memory_bytes: 25392
// https://atcoder.jp/contests/abc154/tasks/abc154_e
// AtCoder Beginner Contest 154
// E - Almost Everywhere Zero

/*
Problem.
n以下で、0でない桁の数がちょうどk個の自然数(>0)の数？

Point.
みるからに桁DP。
dp[桁数(上位から)][0以外の桁数][0]:現在値がn未満であることが確定でない。
dp[桁数(上位から)][0以外の桁数][1]:        ,,           確定である。
*/

#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
  string n;
  cin >> n;
  int k;
  cin >> k;
  int dp[101][4][2] = {};
  dp[0][0][0] = 1;

  for(int i = 0; i < n.length(); i++){
    int num = n[i] - '0';
    for(int j = 0; j < k+1; j++){
      for(int l = 0; l < 2; l++){
        for(int d = 0; d < 10; d++){
          int n_zero = (d) ? j + 1 : j;     //0以外を使用したためn_zeroが増加
          if(n_zero > k) continue;          //すでに0でない数がkを超えている。
          if(l == 0 && d > num) continue;   //d > num -> nを超えている
          if(l == 0 && d == num)            //nより小さいことが確定していない
            dp[i+1][n_zero][0] += dp[i][j][l];
          else                              //nより小さいことが確定した。
            dp[i+1][n_zero][1] += dp[i][j][l];
        }
      }
    }
  }
  cout << dp[n.length()][k][0] + dp[n.length()][k][1] << endl;
}


Measured memory_bytes: 256
S = int(input())

if S == 1 or S == 2:
    print(0)
    exit()
if S == 3:
    print(1)
    exit()

dp = [0] * (S+1)
dp[0] = 0
dp[1] = 0
dp[2] = 0
dp[3] = 1


for wa in range(4, S+1):
    dp[wa] = 1
    for coin in range(3, S+1):
        if wa - coin >= 3:
            dp[wa] += dp[wa - coin]
    dp[wa] %= int(10**9+7)

# print(dp)
print(dp[S])


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

int main()
{
    char s[100];
    int i,cc=0,l,f=0;
    scanf("%s",s);
    l=strlen(s);
    if(s[0]!='A') printf("WA\n");
    else if(s[1]=='C') printf("WA\n");
    else if(s[l-1]=='C') printf("WA\n");
    else
    {
        for(i=1; i<l; i++)
        {
            if(s[i]=='C') cc++;
            else if(s[i]<97)
            {
                f=1;
                break;
            }
        }
        if(f==0 && cc==1) printf("AC\n");
        else printf("WA\n");
    }
    return 0;
}


Measured memory_bytes: 128
h,w=map(int,input().split())
a=[]
for _ in range(h):
    a.append(list(map(int, input().split())))
ans=[]
cnt=0
for i in range(h):
    for j in range(w-1):
        if a[i][j]%2==1:
            a[i][j+1]+=1
            a[i][j]-=1
            cnt+=1
            ans.append((i+1,j+1,i+1,j+2))
for i in range(h-1):
    if a[i][w-1]%2==1:
        a[i][w-1]-=1
        a[i+1][w-1]+=1
        cnt+=1
        ans.append((i+1,w,i+2,w))

print(cnt)
for i,j,k,l in ans:
    print(i,j,k,l)


Measured memory_bytes: 26664
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n;
  ll a[n+1];
  ll b[n];
  rep(i,n+1) cin >> a[i];
  rep(i,n) cin >> b[i];
  ll ans = 0;
  rep(i,n){
    if(a[i] <= b[i]){
      b[i] -= a[i];
      ans += a[i];
      if(a[i+1] <= b[i]){
        ans += a[i+1];
        a[i+1] = 0;
      }else{
        a[i+1] -= b[i];
        ans += b[i];
      }
    }else{
      a[i] -= b[i];
      ans += b[i];
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int q, t, a, b;
ll ans;
priority_queue<int> low;
priority_queue<int, vector<int>, greater<int>> high;

int main(){
	scanf("%d%d%d%d", &q, &t, &a, &b);
	ans += b;
	low.push(a);
	for(int i = 0; i < q-1; i++){
		scanf("%d", &t);
		if(t == 1){
			scanf("%d%d", &a, &b);
			ans += (ll)b + abs(low.top() - a);
			if(a < low.top()) low.push(a);
			else high.push(a);
			if(low.size() > high.size() + 1){
				high.push(low.top()); low.pop();
			}else if(low.size() < high.size()){
				ans -= high.top() - low.top();
				low.push(high.top()); high.pop();
			}
		}else printf("%d %lld\n", low.top(), ans);
	}
}

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


int main()
{
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	if (a + 5 * b + 10 * c + 50 * d + 100 * e + 500*f >= 1000) {
		cout << "1" << endl;
	}
	else {
		cout << "0" << endl;
	}
    return 0;
}

Measured memory_bytes: 3120