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

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class K, class V> ostream& operator<<(ostream& os, const pair<K, V>& p) {
        return os << "(" << p.first << "," << p.second << ")";
    }
    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int N;
    vector<string> ws;
    vector<int> ss;
    int T;
    vector<string> F;
    void input() {
        cin >> N;
        ws.clear(); ws.resize(N);
        ss.clear(); ss.resize(N);
        for (int i = 0; i < N; i++) cin >> ws[i] >> ss[i];
        F.clear(); F.resize(4);
        cin >> F;
        cin >> T;
    }

    vector<int> count;

    void dfs(int i, int j, int y, int x, int used) {
        if (j == ws[i].size()) {
            count[i]++;
            return;
        }
        for (int dy = -1; dy <= 1; dy++) {
            for (int dx = -1; dx <= 1; dx++) {
                if (dy == 0 && dx == 0) continue;
                int ny = y + dy;
                int nx = x + dx;
                if (ny < 0 || ny >= 4 || nx < 0 || nx >= 4) continue;
                if (F[ny][nx] != ws[i][j]) continue;
                if (used & (1 << (4*ny+nx))) continue;
                dfs(i, j + 1, ny, nx, used | (1<<4*ny+nx));
            }
        }
    }

    const int INF = 1<<28;

    void solve() {
        count.clear(); count.resize(N, 0);
        map<char, bool> found;
        for (int y = 0; y < 4; y++) {
            for (int x = 0; x < 4; x++) {
                found[F[y][x]] = true;
            }
        }
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < ws[i].size(); j++) {
                if (not found[ws[i][j]]) {
                    goto next;
                }
            }
            for (int y = 0; y < 4; y++) {
                for (int x = 0; x < 4; x++) {
                    if (F[y][x] == ws[i][0]) {
                        dfs(i, 1, y, x, 1<<(4*y+x));
                    }
                }
            }
            next:;
        }
        auto dp = vector<vector<int>>(2, vector<int>(T + 1, -INF));
        dp[0][0] = 0;
        for (int i = 1; i <= N; i++) {
            int l = ws[i - 1].size();
            for (int t = 0; t <= T; t++) {
                if (dp[0][t] >= 0) {
                    for (int k = 0; k <= count[i - 1]; k++) {
                        int x = t + k * l;
                        if (x > T) break;
                        dp[1][x] = max(dp[1][x], dp[0][t] + k * ss[i - 1]);
                    }
                }
            }
            swap(dp[0], dp[1]);
        }
        int ans = 0;
        for (int t = 0; t <= T; t++) {
            ans = max(ans, dp[0][t]);
        }
        cout << ans << endl;
    }
}

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

Measured memory_bytes: 3316
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <list>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
#define LL long long
#define eps 1e-6
using namespace std;
const double pi = 3.1415926535;
/*
https://codeforces.com/contest/1106/problems
https://codeforces.com/contest/1106/submit
*/

int main(){
	/*ll n,x;
	ll a[1000000];
    sld(n) sld(x)
    ll sum = 0;
    for(ll i = 0; i < n; i ++){

    }*/

    char a[1000000];
    ss(a)
    int lena = len(a);
    int sum = 0;
    for(int i = 1; i <lena; i ++){
        if(a[i] != a[i-1]){
            sum ++;
        }
    }
    p(sum) pn
    return 0;

}



Measured memory_bytes: 384
#include<iostream>

using namespace std;

int selectionSort(int A[], int N){
    int sw = 0;
    
    for(int i = 0; i < N; i++){
        int minj = i;
        for(int j = i; j < N; j++){
            if(A[j] < A[minj]) minj = j;
        }

        swap(A[i], A[minj]);
        if(i != minj) sw++;
    }

    return sw;
}

int main(){
    int A[100], N, sw;

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

    sw = selectionSort(A, N);

    for(int i = 0; i < N; i++){
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;

    return 0;
}


Measured memory_bytes: 3092
x = [0] * 4
y = [0] * 4
x[0], y[0], x[1], y[1] = map(int, input().split())

x[3] = x[0] - (y[1] - y[0])
y[3] = y[0] + (x[1] - x[0])
x[2] = x[3] - (y[0] - y[3])
y[2] = y[3] + (x[0] - x[3])

print(x[2], y[2], x[3], y[3])

Measured memory_bytes: 3064
#include <cstdio>

using namespace std;

char s[2];

int get(long long x) {
    printf("? %lld\n", x);
    fflush(stdout);
    
    scanf("%s", s);
    
    if (s[0] == 'Y') {
        return 1;
    } else {
        return 0;
    }
}

int main() {
    int f = 1;
    long long ans = 0;
    
    while (1) {
        int l, r, m;
        
        l = -1, r = 9;
        if (ans == 0) l = 0;
        m = (l + r) / 2;
        
        while (r - l > 1) {
            long long x = ans * 10 + m;
            
            while (x < 1e10) x = x * 10 + 9;
            
            if (get(x) == 1) {
                r = m;
                m = (l + r) / 2;
            } else {
                l = m;
                m = (l + r) / 2;
            }
        }
        
        if (ans > 0 && r == 0) {
            long long x = (ans - 1) * 10 + 9;
            
            if (get(x) == f) {
                printf("! %lld\n", ans);
                return 0;
            }
        }
        
        if (r > 1) f = 0;
        
        ans = ans * 10 + r;
    }
    
    return 0;
}


Measured memory_bytes: 504
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<class T>
vector<T> make_vec(size_t s, T val) { return vector<T>(s, val); }
template<class... Size>
auto make_vec(size_t s, Size... tail) {
	return vector<decltype(make_vec(tail...))>(s, make_vec(tail...));
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	auto dp = make_vec(301, 301, 301, 0.0);

	auto dfs = [&] (auto &&f, int i, int j, int k) -> double {
		
		if (dp[i][j][k] != 0.0) return dp[i][j][k];

		double res = 0.0;
		int sum = i + j + k; // res += dfs(i, j, k) * (N - i + j + k) / N;
        if(sum == 0.0) return res;
		if(k > 0) res += f(f, i, j + 1, k - 1) * k / sum;
		if(j > 0) res += f(f, i + 1, j - 1, k) * j / sum;
		if(i > 0) res += f(f, i - 1, j, k) * i / sum;

		dp[i][j][k] = res + (double)N / sum;

		return dp[i][j][k];

	};

	vector<int> a(3);
	for (int i = 0; i < N; i++) {
		int in;
		cin >> in;
		in--;
		a[in]++;
	}

	cout << fixed << setprecision(10);
    cout << dfs(dfs, a[0], a[1], a[2]) << "\n";

	return 0;
}

Measured memory_bytes: 219008
#pragma GCC optimize(3, "Ofast", "inline")

#include <bits/stdc++.h>

#define start ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define int ll
#define ls st<<1
#define rs st<<1|1
#define pii pair<int,int>
#define rep(z, x, y) for(int z=x;z<=y;++z)
#define com bool operator<(const node &b)
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int maxn = (ll) 3e5 + 5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
int T = 1;

int ans;
char mp[10][10];

void solve() {
    int h, w, k;
    cin >> h >> w >> k;
    rep(i, 0, h-1)cin >> mp[i];
    for (int i = 0; i < (1 << h); ++i) {
        for (int j = 0; j < (1 << w); ++j) {
            int num = 0;
            rep(q, 0, h - 1) {
                rep(e, 0, w - 1) {
                    if ((1 << q) & i)
                        continue;
                    if ((1 << e) & j)
                        continue;
                    num += (mp[q][e] == '#');
                }
            }
            if (num == k)
                ++ans;
        }
    }
    cout << ans;
}

signed main() {
    start;
    while (T--)
        solve();
    return 0;
}

Measured memory_bytes: 3652
/** coder Mohammad Al-Hussein *_^ */
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define mp make_pair
#define All(v) v.begin(),v.end()
#define mod  1000000007
#define write freopen("output.txt","w",stdout)
#define read freopen("test (1).txt","r",stdin)
#define FIO std::ios_base::sync_with_stdio(false);
using namespace std;



string s[101];


bool cmp(string a,string b)
{
    return a+b < b+a;
}


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

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

    sort(s,s+n);

    for(int i=0; i<n; i++)
        cout << s[i];
    cout << '\n';




    return 0;
}














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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define foreach(it, S) for (__typeof (S.begin()) it = S.begin(); it != S.end(); it++)
#define all(x) x.begin(), x.end()
#define endl '\n'
#define _ ios_base :: sync_with_stdio(false); cin.tie(NULL);

#ifdef inputf
# define fname ""
#else
# define fname "" // <- Here
#endif

#ifndef lcl
# define cerr if (0) cout
#endif

template <typename T> T gcd(T a, T b) {
	return b ? gcd (b, a % b) : a;
}

#define dlong long double

const dlong eps = 1e-30;
const int MAXN = (1 << 20) + 256;
const int MOD = (int)1e9 + 7, INF = (int)1e9;
const ll INFLL = (ll)1e18;

int a[MAXN], l[MAXN], r[MAXN];

int main() { // _
	#ifdef lcl
		freopen(fname".in", "r", stdin);
		freopen(fname".out", "w", stdout);
	#endif

	int n; scanf("%d", &n);

	for (int i = 1; i <= n; ++i) 
		scanf("%d", a + i);

	vector <int> st;
	l[1] = 1;

	for (int i = 1; i <= n; ++i) {
		while (!st.empty() && a[st.back()] >= a[i])
			st.pop_back();
		if (st.empty()) {
			l[i] = 1;
		} else {
			l[i] = st.back() + 1;
		}
		st.push_back(i);
	}

	st.clear();

	for (int i = n; i >= 1; --i) {
		while (!st.empty() && a[st.back()] >= a[i])
			st.pop_back();
		if (st.empty()) {
			r[i] = n;
		} else {
			r[i] = st.back() - 1;
		}
		st.push_back(i);
	}

	ll res = 0;

	// for (int i = 1; i <= n; ++i)
	// 	cerr << l[i] << " " << r[i] << " " << a[i] << endl;

	for (int i = 1; i <= n; ++i) {
		int x = abs(i - l[i]) + 1;
		int y = abs(i - r[i]) + 1;
		res += a[i] * (x * 1ll * y);
	}

	cout << res << endl;

	return 0;
}

/*
	x x x y x x
*/


Measured memory_bytes: 3448
function main()
  
  N = parse(Int,readline())
  a = map(x -> parse(Int,x), split(readline()))
  
  sort!(a,rev = true)
  
  Alice = 0
  Bob = 0
  
  for i in 1:N
    if i % 2 == 1
      Alice += a[i]
    else
      Bob += a[i]
    end
  end
  
  println(Alice - Bob)
  
end

main()

Measured memory_bytes: 114204
lis = list(map(int, input().split()))
sort = sorted(lis)
if sort[0] == sort[1] and sort[1] == sort[2]:
	print(0)
elif sort[0] == sort[1]:
	print(sort[2] - sort[1])
elif sort[1] == sort[2]:
	if (sort[1] - sort[0]) % 2 == 0:
		print(int((sort[1] - sort[0]) / 2))
	else:
		print(int((sort[1] - sort[0] + 1) / 2) + 1)
else:
	if (sort[1] - sort[0]) % 2 == 0: 
		print(sort[2] - sort[1] + int((sort[1] - sort[0]) / 2))
	else:
		print(sort[2] - sort[1] + int((sort[1] - sort[0] + 1) / 2) + 1)

Measured memory_bytes: 3064
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	void quickSort_ascend(int[] a, int[] b, int[] c, int l, int r) {
		if (l < r) {
			int w = a[(l+r)/2];
			int i = l, j = r, temp;
			while (i < j) {
				while (a[i] < w) i++;
				while (a[j] > w) j--;
				if (i <= j) {
					temp = a[i];
					a[i] = a[j]; a[j] = temp;
					temp = b[i];
					b[i] = b[j]; b[j] = temp;
					temp = c[i];
					c[i] = c[j]; c[j] = temp;
					i++; j--;
				}
			}
			quickSort_ascend(a, b, c, l, j);
			quickSort_ascend(a, b, c, i, r);
		}
	}
	
	void run() {
		int n, m;
		while (true) {
			n = sc.nextInt(); m = sc.nextInt();
			if (n == 0 && m == 0) break;
			int[] t = new int[m];
			int[] s = new int[m];
			int[] d = new int[m];
			for (int i = 0; i < m; i++) {
				t[i] = sc.nextInt();
				s[i] = sc.nextInt();
				d[i] = sc.nextInt();
			}
			quickSort_ascend(t,s,d,0,m-1);
			boolean[] comp = new boolean[n+1];
			comp[1] = true;
			if (m > 0) {
				int time = t[0];
				List<Integer> list = new ArrayList<Integer>();
				for (int i = 0; i < m; i++) {
					if (t[i] == time) {
						if (comp[s[i]]) list.add(d[i]);
					} else {
						for (int k : list)
							comp[k] = true;
						list.clear();
						time = t[i];
						if (comp[s[i]]) list.add(d[i]);
					}
				}
				
				for (int k : list)
					comp[k] = true;
			}
			
			int ans = 0;
			for (int i = 1; i <= n; i++)
				if (comp[i])
					ans++;
			
			out.println(ans);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

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

int main(){
  string s ; cin >> s ;
  int s0 = s.at(0)-'0' ;
  int s1 = s.at(1)-'0' ;
  int s2 = s.at(2)-'0' ;
  int s3 = s.at(3)-'0' ;
  int s5 = s.at(5)-'0' ;
  int s6 = s.at(6)-'0' ;
  int y = 1000*s0+100*s1+10*s2+s3 ;
  if(y<2019) cout << "Heisei" << endl ;
  else if(y>2019) cout << "TBD" << endl ;
  else{
    int m = 10*s5+s6 ;
    if(m<5) cout << "Heisei" << endl ;
    else cout << "TBD" << endl ;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int MultiplyInteger( int integer );

int main()
{
    int integer;
    int answer;
    
    scanf("%d",&integer);
    
    answer = MultiplyInteger( integer );
    
    printf("%d\n",answer);
}

int MultiplyInteger( int integer )
{
    int result;
    
    result = ( ( integer * integer ) * integer );
    
    return result;
}

Measured memory_bytes: 1672
from itertools import product
n, m = map(int, input().split())
s = [list(map(int, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))

all_on = 0
for sp in product([0, 1], repeat=n):
    on = 0
    # 対象の電球を固定
    for i in range(m):
        cnt = 0
        # スイッチを固定
        for j in range(len(s[i])):
            if sp[s[i][j] - 1] == 1:
                cnt += 1
        if cnt % 2 == p[i]:
            on += 1
    if on == m:
        all_on += 1

print(all_on)

Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        long X, Y, Z;
        X = sc.nextLong();
        Y = sc.nextLong();
        Z = sc.nextLong();
        var K = sc.nextInt();
        var A = new long[X];
        for (int i = 0; i < X; i++) A[i] = sc.nextLong();
        var B = new long[Y];
        for (int i = 0; i < Y; i++) B[i] = sc.nextLong();
        var C = new long[Z];
        for (int i = 0; i < Z; i++) C[i] = sc.nextLong();

        var lst = new long[X * Y];
        var idx = 0;
        for (int i = 0; i < X; i++) {
            for (int j = 0; j < Y; j++) {
                lst[idx] = A[i] + B[j];
                idx++;
            }
        }
        Array.Sort(lst);
        Array.Reverse(lst);
        lst = lst.Take(K).ToArray();

        var ans = new long[lst.Length * Z];
        idx = 0;
        for (int i = 0; i < lst.Length; i++) {
            for (int j = 0; j < Z; j++) {
                ans[idx] = lst[i] + C[j];
                idx++;
            }
        }
        Array.Sort(ans);
        Array.Reverse(ans);

        for (int i = 0; i < K; i++) {
            WriteLine(ans[i]);
        }
    }
}

class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 44896
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill( (T*)array, (T*)(array+N), val );}
using ld=long double;
struct edge{int to,cost,limit;};
using P=pair<ld,pair<int,pair<int,int>>>;
#define mp(i,j,k,l) make_pair((i),make_pair((j),make_pair((k),(l))))
const ld INF=1<<29;
const int MAX_V=35;
vector<edge> G[MAX_V];
ld t[MAX_V][MAX_V][35];

int n,m,s,g;
void dijkstra(){
  priority_queue<P,vector<P>,greater<P>> que;
  Fill(t,INF);
  t[0][s][1]=0;
  que.push(mp(0,0,s,1));
  while(!que.empty()){
    P p=que.top();que.pop();
    int last=p.second.first;
    int v=p.second.second.first;
    int spd=p.second.second.second;
    REP(i,G[v].size()){
      edge e=G[v][i];
      if(last==e.to)continue;
      for(int j=-1;j<=1;j++){
	//cout<<"["<<v<<"->"<<e.to<<"] "<<t[e.to][spd+j]<<">"<<t[v][spd]<<"+"<<((double)e.cost)/spd<<endl;
	if(spd>e.limit)continue;
	if(t[v][e.to][spd+j]>t[last][v][spd]+((double)e.cost)/spd){
	  t[v][e.to][spd+j]=t[last][v][spd]+((double)e.cost)/spd;
	  que.push(mp(t[v][e.to][spd+j],v,e.to,spd+j));
	}
      }
    }
  }
  ld mn=INF;
  REP(i,n){
    mn=min(t[i+1][g][0],mn);
  }
  if(mn!=INF) printf("%.12Lf\n",mn);
  else printf("unreachable\n");
}
int x,y,d,c;
int main(){ _;
  while(cin>>n>>m,(n|m)){
    REP(i,MAX_V)G[i].clear();
    cin>>s>>g;
    REP(i,m){
      cin>>x>>y>>d>>c;
      G[x].push_back(edge{y,d,c});
      G[y].push_back(edge{x,d,c});
    }
    dijkstra();
  }
}

Measured memory_bytes: 5536
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}

constexpr ll LNF = 1LL<<50;

constexpr int INF = 1e9+7;

const long double PI=3.14159265358979323846;


vector<int> dx = {1,0,-1,1,-1,0};
vector<int> dy = {1,1,1,0,0,-1};

/* template */

ll Pow(ll x, ll n){
    ll res = 1;
    while(n>0){
        if(n&1) res = res *x;
        x = x*x;
        n>>=1;
    }
    return res;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll index = 0;
    ll sum = 0;
    while(sum<=n){
        sum += Pow(26,index);
        index++;
    }
    index--;
    sum -= Pow(26,index);
    debug(index,sum);
    string ans = "";
    while(index>0){
        ll p = 0;
        while(sum+Pow(26,index-1)<=n){
            sum += Pow(26,index-1);
            p++;
        }
        debug(sum,p);
        ans += (char)('a'+p);
        index--;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3652
module Main where
import Debug.Trace
import Data.List
import Data.Char
import Data.Array
import Data.Maybe
import Data.Ord
import Control.Monad

solve :: [Int] -> [[Int]]
solve l = iter 0 [] (l) where
    iter c sl [] = [sl, [c]]
    iter c sl l = iter2 c [] l where
        iter2 c ac [x] = iter c (x:sl) (reverse ac)
        iter2 c ac (x:y:ds)
            | x <= y     = iter2 (c) (x:ac) (y:ds)
            | otherwise = iter2 (c+1) (y:ac) (x:ds)

readLine:: IO [Int]
readLine = fmap (map read . words) getLine

main :: IO() 
main = do
    n <- readLn :: IO Int
    l <- readLine
    mapM_ putStrLn $ map (\y -> init (concatMap (\x-> show x ++ " ") y)) (solve l)



Measured memory_bytes: 4104
#include<bits/stdc++.h>
using namespace std;
const int N=205;
int x,n,a[N],c[2],match[N],b[N][N],flag[N],flag2[10000005];
int pd(int x){
	if (x==1)return 0;
	for (int i=2;i*i<=x;i++)
		if (x%i==0)return 0;
	return 1;
}
int dfs(int x){
	for (int i=1;i<=n;i++)
		if (flag[i]&&b[x][i]){
			flag[i]=0;
			if (!match[i]||dfs(match[i])){
				match[i]=x;
				return 1;
			}
		}
	return 0;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&x);
		flag2[x]=1;
	}
	n=0;
	for (int i=1;i<=10000001;i++)
		if (flag2[i]^flag2[i-1])a[++n]=i;
	for (int i=1;i<=n;i++)
		if (a[i]&1)for (int j=1;j<=n;j++)
			if (!(a[j]&1))b[i][j]=pd(abs(a[i]-a[j]));
	int sum=0;
	for (int i=1;i<=n;i++)
		if (a[i]&1){
			memset(flag,1,sizeof(flag));
			sum+=dfs(i);
		}
	for (int i=1;i<=n;i++)c[a[i]&1]++;
	c[0]-=sum;c[1]-=sum;
	printf("%d\n",sum+c[0]+c[1]+(c[0]&c[1]&1));
	return 0;
}


Measured memory_bytes: 37376
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

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

  cout << (n + 1) / 2 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int atai(int n) {
  if (n >= 0) {
    return n;
  }
  else{
    n=n*(-1);
       return n;
      }
}
int main() {
	int N,P[100000],sum,x,y,z,m,X;
  cin>>N;
  P[0] = 0;
  P[N+1]=0;
  sum=0;
	for (int a = 1; a <= N; a++) {
      int b=0;
      cin >> P[a];
      b=P[a]-P[a-1];
      sum+=atai(b);
    }
  sum+=atai(P[N]);//総合値が出る
for(int i=1;i<=N;i++){
    m=0;
    x=0;
    y=0;
    z=0;
    X=0;//引くものを求めていく（場合分け必須）
                        if(P[i]>=P[i-1]){
                          if(P[i+1]>=P[i]){
                            X=sum;
                          }
                          else{
                            x=P[i]-P[i-1];
                            y=P[i+1]-P[i];
                            m=atai(x)+atai(y);
                            z=P[i+1]-P[i-1];
                            X=sum-m+atai(z);
                          }
                        }
                       else{
                         if(P[i+1]<=P[i]){
                           X=sum;
                         }
                         else{
                           x=P[i]-P[i-1];
                           y=P[i+1]-P[i];
                           m=atai(x)+atai(y);
                            z=P[i+1]-P[i-1];
                           X=sum-m+atai(z);
                         }
                       }
  cout<<X<<endl;}

}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz() size()
#define fr first
#define sc second
#define pb push_back
#define er erase
#define in insert
#define pi pair<int,int>
#define mp make_pair
#define el cout<<'\n'
#define rc(s) return cout<<s,0
//#define cin fin
//#define cout fout
using namespace std;

#define inf 1000000000

//ifstream fin("input.in");
//ofstream fout("input.out");

const int mod=1e9+7;

int h,w,n,x1,y11;
string s,t;

int dp1[200005],dp2[200005];

int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie();cout.tie();
    cin >> h >> w >> n >> x1 >> y11 >> s >> t;
    int x2=x1,y2=y11;
    for(int i=0;i<s.size();i++){
        if(s[i]=='L') y2--;
        if(y2==0) rc("NO");
        if(t[i]=='R') y2++;
        if(y2==w+1) y2=w;
    }
    x2=x1,y2=y11;
    for(int i=0;i<s.size();i++){
        if(s[i]=='R') y2++;
        if(y2==w+1) rc("NO");
        if(t[i]=='L') y2--;
        if(y2==0) y2=1;
    }
    x2=x1,y2=y11;
    for(int i=0;i<s.size();i++){
        if(s[i]=='U') x2--;
        if(x2==0) rc("NO");
        if(t[i]=='D') x2++;
        if(x2==h+1) x2=h;
    }
    x2=x1,y2=y11;
    for(int i=0;i<s.size();i++){
        if(s[i]=='D') x2++;
        if(x2==h+1) rc("NO");
        if(t[i]=='U') x2--;
        if(x2==0) x2=1;
    }
    rc("YES");
}


Measured memory_bytes: 920
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    if(a[0]!=0){
        cout<<-1<<endl;
        return 0;
    }else if(n==1){
        cout<<0<<endl;
        return 0;
    }
    for(int i=1;i<n;i++){
        if(a[i]-a[i-1]>1){
            cout<<-1<<endl;
            return 0;
        }
    }
    int res=0;
    a.push_back(0);
    for(int i=0;i<n;i++){
        if(a[i]>=a[i+1])res+=a[i];
    }
    cout<<res<<endl;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_A = 1123456;
int divisible[MAX_A];
int done[MAX_A];

int main2() {

  CLR(divisible, 0);
  CLR(done, 0);

  int N = nextLong();
  vector<int> A(N);
  REP(i, N) A[i] = nextLong();

  REP(ai, N) {
    const int a = A[ai];
    if (done[a] >= 2) continue;
    done[a]++;
    for (int j = a; j < MAX_A; j += a) {
      ++divisible[j];
    }
  }

  int ans = 0;
  REP(i, N) {
    if (divisible[A[i]] <= 1) ans++;
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 12784
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c, n;
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> a >> b >> c;
    if(b + c > a && a * a == b * b + c * c) cout << "YES\n";
    else if(a + c > b && b * b == a * a + c * c) cout << "YES\n";
    else if(a + b > c && c * c == a * a + b * b) cout << "YES\n";
    else cout << "NO\n"; 
  }

  return 0;
}



Measured memory_bytes: 3060
using System;

class Sample{
    static void Main(string[] args){
        while(true){
            string[] a;
            int h,w;
            a = Console.ReadLine().Split(' ');
            h = int.Parse(a[0]);
            w = int.Parse(a[1]);
            if((h==0)&&(w==0)) break;
            for(int i=0; i<h; i++){
                for(int j=0; j<w; j++){
                    if((((i==0)||(i==h-1)) 
                           || ((j==0)||(j==w-1)))){
                        Console.Write("#");
                    } else {
                        Console.Write(".");
                    }
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
}


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

int main(){
    int S;
    cin >> S;
    int h,m,s;
    h = S / (60*60);
    m = (S %(60 * 60)) /60;
    s = S % 60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
#define N 305
#define INF 0x3fffffff
int f[N][N];
int d[N][N];
bool check(int x,int y,int v)
{
	int res=INF;
	for(int i=0;i<=100;i++)
	{
		for(int j=0;j<=100;j++)
		{
			if(f[i][j]>=0)
			{
				res=min(res,i*x+j*y+f[i][j]);
			}
		}
	}
	return res==v;
}
signed main()
{
	memset(f,-1,sizeof(f));
	int a,b;
	cin>>a>>b;
	for(int i=1;i<=a;i++)
	{
		for(int j=1;j<=b;j++)
		{
			d[i][j]=read();
		}
	}
	int sum=0;
	for(int i=0;i<=100;i++)
	{
		for(int j=0;j<=100;j++)
		{
			int tmp=-INF;
			for(int c=1;c<=a;c++)
			{
				for(int e=1;e<=b;e++)
				{
					tmp=max(tmp,d[c][e]-i*c-j*e);
				}
			}
			f[i][j]=tmp;
			if(f[i][j]<0) break;
			sum++;
		}
	}
	for(int i=1;i<=a;i++)
	{
		for(int j=1;j<=b;j++)
		{
			if(!check(i,j,d[i][j]))
			{
				printf("Impossible\n");
				return 0;
			}
		}
	}
	int s=201,t=202;
	printf("Possible\n");
	printf("%d %d\n",202,sum+200);
	for(int i=1;i<100;i++)
	{
		printf("%d %d X\n",i,i+1);
		printf("%d %d Y\n",i+101,i+100);
	}
	printf("%d %d X\n",s,1);
	printf("%d %d Y\n",101,t);
	for(int i=0;i<=100;i++)
	{
		for(int j=0;j<=100;j++)
		{
			if(f[i][j]>=0)
			{
				printf("%d %d %d\n",i==0?s:i,j==0?t:j+100,f[i][j]);
			}
		}
	}
	printf("%d %d\n",s,t);
	return 0;
}



Measured memory_bytes: 640
N = map(int, input().split())
l = list(map(int, input().split()))
from collections import deque


l = deque(l)

count=0
for i in range(len(l)-1):
    if l[i] >l[i+1]:
        c=l[i] -l[i+1]
        l[i+1]+=c
        count+=c

print(count)

Measured memory_bytes: 94260
def max_ten(s):
    if memo[s]!="e":
        return memo[s]
    ten = 0
    # 分けない場合の点数
    for ai, ar in enumerate(a[:-1]):
        if s >> ai & 1:
            ten += sum(ar[j] * (s >> j & 1) for j in range(1 + ai, n))
    # 分ける場合の点数
    bubun = (s - 1) & s
    while bubun > 0:
        kari = max_ten(bubun) + max_ten(bubun ^ s)
        if kari > ten:
            ten = kari
        bubun = (bubun - 1) & s
    memo[s] = ten
    return ten


n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
s = (1 << n) - 1
memo = ["e"] * (1 << n)
print(max_ten(s))


Measured memory_bytes: 60248
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

vector<int> G[SIZE];
int Aoki[SIZE];

void dfs1(int now, int back = -1, int t = 0) {
  Aoki[now] = t;

  for (int to : G[now]) {
    if (to == back) continue;
    dfs1(to, now, t + 1);
  }
}

int dfs2(int now, int back = -1, int t = 0) {
  int res = Aoki[now] - 1; //(Aoki[now] % 2 == t % 2);

  if (Aoki[now] <= t) return res;

  bool isleaf = true;

  for (int to : G[now]) {
    if (to == back) continue;
    res = max(res, dfs2(to, now, t + 1));
    isleaf = false;
  }

  return res;
}

int main() {
  int N, u, v;

  scanf("%d%d%d", &N, &u, &v);
  u--; v--;

  for (int i=0; i<N-1; i++) {
    int A, B;
    scanf("%d%d", &A, &B);
    A--; B--;
    G[A].push_back(B);
    G[B].push_back(A);
  }

  dfs1(v);
  int ans = dfs2(u);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 12544
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 100000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;

LL a[N];
LL inv[N];
LL fac[N];
map<LL,int> bucket;
void init() {
    fac[0]=1;
    fac[1]=1;
    inv[0]=1;
    inv[1]=1;
    for(LL i=2;i<N;i++) {
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD;
    }
    for(int i=1;i<N;i++)
        inv[i]=inv[i]*inv[i-1]%MOD;
}
LL C(LL n, LL m){
    if(m>n)
        return 0;
    return ((fac[n]*inv[m]%MOD)*inv[n-m])%MOD;
}
int main() {
    init();
    LL n;
    while(cin >> n)
    {
        map<LL, int>q;
        LL p = 0;
        for(int i = 1; i <= n + 1; i++)
        {
            scanf("%lld", a + i);
            if(!q[a[i]])
                q[a[i]] = i;
            else
                p = i;
        }
        for(int i = 0; i <= n; i++)
        {
            LL ans = 0;
            ans = (ans + C(n + 1, i + 1)) % MOD;
            ans = (ans - C(n - p + q[a[p]], i)) % MOD;
            while(ans < 0)
                ans += MOD;
            printf("%lld\n", ans);
        }
    }
    return 0;
}


Measured memory_bytes: 9856
#include <vector>
#include <algorithm>
#include <limits.h>
#include <iostream>
#include <set>
#include <cmath>
#include <queue>
#include <cstring>
#include <string.h>
#include <stdio.h>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#define MOD 1000000007
typedef  long long int  lli;
using namespace std;
int main() {
    int t; t=1;
    while(t--) {
        long long int n; cin>>n; long long int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        /* if(n==2)
         {
             if(a[0]<a[1]){cout<<-1<<"\n";
                 continue;}
             else if(a[0]==a[1]){cout<<0<<"\n";
                 continue;}
             else if(a[0]>a[1])
             {
                 if(((a[0]-a[1])%2)!=0) {cout<<-1<<"\n"; continue;}
                 long long int x=(a[0]-a[1])/2;

                 cout<<x<<"\n";
                 continue;
             }
         }*/
        long long int X=0;
        for(int i=2;i<n;i++)
        {
            X^=a[i];
        }
        long long int S=a[0]+a[1];
        if((S-X)%2!=0) {cout<<-1<<"\n";
            continue;}

        long long int D=(S-X)/2;
        if(D < 0) {cout<<-1<<"\n";
            continue;}
        if((D&X) != 0){cout<<-1<<"\n";
            continue;}
        if(D>a[0]){cout<<-1<<"\n";
            continue;}
        long long int a_val=D; long long int y=0;
        for(int i=60;i>=0;i--)
        {
            if((X>>i)&1)
            {
                long long int z = y+(1ll<<i);
                if((z^a_val)<=a[0])
                {
                    y=z;
                }
            }
        }
        if((y^a_val) == 0) cout<<-1<<"\n";
        else cout<<a[0]-(y^a_val)<<"\n";






    }
    return 0;
}


Measured memory_bytes: 3608
import scala.io.StdIn._

object Main extends App {


  val n = readInt()
  val P = readLine().split(" ").map(_.toInt)

  def solve() = {
    val cntAndTmpMin = (0, Long.MaxValue)
    P.foldLeft(cntAndTmpMin) { case ((cnt, tmpMin), num) =>
      if(num <= tmpMin) (cnt+1, num) else (cnt, tmpMin)
    }._1
  }

  println(solve())

}



Measured memory_bytes: 76052
#include <cstdio>
#include <algorithm>

using namespace std;
int main(){
    char c;
    int ans = 0;
    int maxn = 0;
    for(int i = 1 ; i <= 3 ; i++){
        scanf("%c", &c);
        if(c == 'R') ans++;
        else maxn = max(maxn, ans), ans = 0;
    }
    printf("%d", max(maxn, ans));
    return 0;
}

Measured memory_bytes: 1656
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# input=sys.stdin.readline
def resolve():
    n=int(input())
    s=input()
    dp=[[0]*(n+1) for _ in range(n+1)]
    from itertools import product
    for i,j in product(reversed(range(n)),repeat=2):
        if i>=j: continue # i<j
        if s[i]==s[j]:
            dp[i][j]=dp[i+1][j+1]+1
        else:
            dp[i][j]=0
    ans=0
    for i,j in product(reversed(range(n)),repeat=2):
        if i>=j: continue
        ans=max(ans,min(j-i,dp[i][j]))
    print(ans)


resolve()

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

#define NIL -1

struct Node{ int p, l, r; };

Node tree[10000];
int n, D[10000], H[10000];

//深さを求める関数
void setDepth(int id, int depth){
    //終了条件(外部節点NILに到達)
    if(id == NIL) return;
    //深さを配列に代入
    D[id] = depth;
    //左右の子それぞれに進んでいく
    setDepth(tree[id].l, depth+1);
    setDepth(tree[id].r, depth+1);
}

//高さを求める関数
int setHeight(int id){
    int h1 = 0, h2 = 0;
    if(tree[id].l != NIL) h1 = setHeight(tree[id].l) + 1;
    if(tree[id].r != NIL) h2 = setHeight(tree[id].r) + 1;
    //max(左の子の高さ+1, 右の子の高さ+1)
    return H[id] = max(h1, h2);
}

//節点idのもう1人の兄弟を返す関数
int getSibling(int id){
    if(tree[id].p == NIL) return NIL;
    if(id != tree[tree[id].p].l && tree[tree[id].p].l != NIL) return tree[tree[id].p].l;  //自分が右
    if(id != tree[tree[id].p].r && tree[tree[id].p].r != NIL) return tree[tree[id].p].r;  //自分が左
    return NIL;
}

//出力用関数
void print(int id){
    printf("node %d: ", id);
    printf("parent = %d, ", tree[id].p);
    printf("sibling = %d, ", getSibling(id));
    int deg = 0;
    if(tree[id].l != NIL) deg++;
    if(tree[id].r != NIL) deg++;
    printf("degree = %d, ", deg);
    printf("depth = %d, ", D[id]);
    printf("height = %d, ", H[id]);

    if(tree[id].p == NIL) printf("root\n");
    else if(tree[id].l == NIL && tree[id].r == NIL) printf("leaf\n");
    else printf("internal node\n");
}

int main(){
    int v, l, r, root = 0;
    cin >> n;

    for(int i=0; i<n; i++) tree[i].p = NIL;

    for(int i=0; i<n; i++){
        cin >> v >> l >> r;
        tree[v].l = l;
        tree[v].r = r;
        if(l != NIL) tree[l].p = v;
        if(r != NIL) tree[r].p = v;
    }

    for(int i=0; i<n; i++){
        if(tree[i].p == NIL) root = i;
    }

    setDepth(root, 0);
    setHeight(root);

    for(int i=0; i<n; i++) print(i);

    return 0;
}


Measured memory_bytes: 3168
def factorial(n, r, p):
    ret = 1
    for i in range(n, n - r, -1):
        ret = (ret * i) % p
    return ret


def comb(n, r, p):
    r = min(r, n - r)
    return (factorial(n, r, p) * pow(factorial(r, r, p), p - 2, p)) % p


mod = 10 ** 9 + 7
x, y = map(int, input().split())
a = (2 * y - x) // 3
b = (2 * x - y) // 3
if (x + y) % 3 != 0 or a < 0 or b < 0:
    ans = 0
else:
    ans = comb(a + b, a, mod)
print(ans)


Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<iostream>
#include<stdlib.h>
#include<ctime>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LL long long
#define FOR(i,a,b) for (int i=a;i<=b;i++)
#define FORD(i,a,b) for (int i=a;i>=b;i--)
using namespace std;
typedef pair<int,int> pa;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int n,t,ans;
char s[111];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	FOR(i,1,n) if (s[i]>'0'){
		int t=0;
		FOR(j,1,i-1) t+=s[j]-'0';
		t+=s[i]-'1';
		FOR(j,i+1,n) t+=9;
		ans=max(ans,t);
	}
	int t=0;
	FOR(i,1,n) t+=s[i]-'0';
	ans=max(ans,t);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll solve(){
    ll N,S; cin >> N >> S;
    vector<ll> a(N); for(auto& in:a) cin >> in;
    ll res = INF;
    ll l = 0, r = 0,sum = 0;
    while(true){
        while(r < N && sum < S){
            if(l >= ++r){
                continue;
            }
            sum += a[r-1];
        }
        if(sum < S) break;
        if(sum >= S){
            res = min(res,r-l);
        }
        sum -= a[l];
        l++;
    }
    if(res == INF) res = 0;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int k, t; cin >> k >> t;
  V<> a(t); for (int i = 0; i < t; i++) cin >> a[i];
  sort(a.begin(), a.end());
  int res = a.back() <= (k + 1) / 2 ? 0 : k - 1 - 2 * (k - a.back());
  cout << res << '\n';
}

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

print("50")
ans = []
a, b = divmod(K, 50)
for i in range(b):
    ans.append(49 + a + 50 - (b - 1))
for i in range(50-b):
    ans.append(49 + a - b)
print(" ".join([str(_) for _ in ans]))

Measured memory_bytes: 61868
#include <iostream>
#include <string>

using namespace std;

int main()
{
    long long int a, b, k;
    cin >> a >> b >> k;

    // for(int i = 0; i < k; ++i){
    //     if(a) a--;
    //     else if(b) b--;
    // }

    if(a + b <= k){
        a = b = 0;
    }
    else if(a <= k){
        b = a + b - k;
        a = 0;
    }
    else{
        a = a - k;
    }

    cout << a << ' ' << b;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.Collections;
import java.util.ArrayList;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int ans = 0;

        ArrayList<Integer> list = new ArrayList<Integer>();

        for(int i=0; i<N; i++){
            list.add(sc.nextInt());
        }

        Collections.sort(list);

        ans = list.get(N-1) / 2;
        for(int i=0; i<N-1; i++){
            ans += list.get(i);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
N = int(input())
A = list(map(int,input().split()))
B = [0]*N
ans = []

for i in range(N-1,-1,-1) :
    num = i+1
    cnt = 0
    for j in range(i+num,N,num) :
        cnt += B[j]
    
    if A[i] != cnt % 2 :
        ans.append(i+1)
        B[i] = 1
    
print(len(ans))
print(*ans, sep="\n")
    


Measured memory_bytes: 15340
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    char a,b,c,d;
    cin >> a >> b >> c >> d;
    if(( (a == b) + (a == c) + (a == d) + (b == c) + (b == d) + (c == d) ) == 2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 256