akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
int main()
{
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    int p[a],q[b],r[c],re[x],gr[y],m=c-1,l=0, o=0;
    ll sum=0;
    for(int i=0;i<a;i++) cin >> p[i];
    for(int i=0;i<b;i++) cin >> q[i];
    for(int i=0;i<c;i++) cin >> r[i];
    sort(p, p+a);
    sort(q,q+b);
    sort(r, r+c);
    for(int i=0; i<x; i++)
	{
        re[i] = p[i+a-x];
    }
    for(int i=0; i<y; i++)
	{
        gr[i] = q[i+b-y];
    }
    while(m>=0 && (o<y || l<x))
	{
        if(l>=x && o<y)
		{
            if(gr[o] < r[m])
			{
                gr[o] = r[m];
                m--;
                o++;
            }
			else break;
        }
		else if(l<x && o>=y)
		{
            if(re[l] < r[m])
			{
                re[l] = r[m];
                m--;
                l++;
            }else break;
        }
		else if(re[l]<=gr[o] && r[m] > re[l])
		{
            re[l] = r[m];
            m--;
            l++;
        }
		else if(re[l]>gr[o] && r[m] > gr[o])
		{
            gr[o] = r[m];
            m--;
            o++;
        }else break;
    }
 
    for(int i=0; i<x; i++) {
        sum+=re[i];
    }
    for(int i=0; i<y; i++) {
        sum+=gr[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 2176
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    int n;cin>>n;
    string s;cin>>s;
    string res="";
    int cnt=0;
    for(int i=0;i<n;i++){
        if(s[i]=='(') cnt++;
        else{
            cnt--;
        }
        res += s[i];
        if(cnt>=0)continue;
        res = '(' + res;
        cnt++;
    }
    for(int i=0;i<cnt;i++) res += ")";
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <numeric>

#define loop(i, n) for (int i = 0; i < (int)n; i++)

using namespace std;
typedef pair<int, int> pint;

int cost(int n, vector<int> a, int p) {
    int c = 0;
    loop(i, n) c += (a[i] - p)* (a[i] - p); 
    return c;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n,0);
    loop(i, n) cin >> a[i];
    int p = (int)floor(accumulate(a.begin(), a.end(), 0) / n); 
    cout << min(cost(n, a, p), cost(n, a, p + 1)) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb          push_back
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define endl        "\n"
#define fast        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int         long long int
#define mod         1000000007
#define test        int t;cin>>t;while(t--)
#define REP(i,a,b)  for(int i=a,i<=b;i++)
#define MAXN        200001

int32_t main()
{
    
    int d,t,s;
    cin>>d>>t>>s;

    if(t*s>=d)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main (){
    int n;cin>>n;
    int ct=0;
    char s[50];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }for(int i=0;i<n;i++){
        if (s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
            ct=ct+1;}
           } cout<<ct;
}














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

using namespace std;

int main(){

	string a,b,c;
	cin >> a >> b >> c;
	char next = 'a';
	int charsize = a.size() + b.size() + c.size();

	for(int i = 0; i < charsize; i++){
		if(next == 'a'){
			if(a.size() == 0){
				cout << 'A' <<endl;
				return 0;
			}
			next = a.front();
			a.erase(a.begin());
		}

		else if(next == 'b'){
			if(b.size() == 0){
				cout << 'B' <<endl;
				return 0;
			}
			next = b.front();
			b.erase(b.begin());
		}

		else if(next == 'c'){
			if(c.size() == 0){
				cout << 'C' <<endl;
				return 0;
			}
			next =c.front();
			c.erase(c.begin());
		}

	}


	return 0;
}

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

int main() {
	int n,m,i,j,k,ans,cur,res;
	cin >> n;
	vector<int> a(n,0);
	for(i=0; i<n-1; i++){
		cin >> cur;
		cur--;
		a[cur]++;
	}
	for(i=0; i<n; i++){
		cout << a[i] << endl;
	}
	return 0;
}

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

#define fi first
#define se second

const int N = 21;
const long long mod = 1e9 + 7;

using namespace std;

int n;
int d[1 << N];
int f[1 << N];

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin >> n;
        d[0] = 1;
        for(int i = 0; i < n; i++){
                for(int j = 0; j < n; j++){
                        int x;
                        cin >> x;
                        if(x == 0){
                                continue;
                        }
                        for(int h = 0; h < (1 << n); h++){
                                if(h & (1 << j)){
                                        continue;
                                }
                                int nh = h | (1 << j);
                                f[nh] += d[h];
                                if(f[nh] >= mod){
                                        f[nh] -= mod;
                                }
                        }
                }
                for(int h = 0; h < (1 << n); h++){
                        d[h] = f[h];
                        f[h] = 0;
                }
        }
        cout << d[(1 << n) - 1] << "\n";
}



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

int main()
{
    string s; cin>>s;
    int K; cin>>K;
    set<string, greater<string>> q;
    for(int i=0; i<s.size(); ++i) {
        string t;
        for(int j=0; j<K && i+j<s.size(); ++j) {
            t+=s[i+j];
            q.insert(t);
            if (q.size()>K) q.erase(begin(q));
        }
    }
    cout<<*begin(q)<<endl;
}

Measured memory_bytes: 256
def main():
  n = int(input())
  #s = input()
  #s = input().split()
  #a,b = list(map(int,input().split()))
  #a = [input() for i in range(n)]
  #a = [int(input()) for i in range(n)]
  #a = [input().split() for i in range(n)]
  #a = [list(map(int,input().split())) for i in range(n)]
  ans = 0
  count = 0
  lis = []
  
  if n == 7 or n == 5 or n == 3:
    print("YES")
  else:
    print("NO")

if __name__ == '__main__':
  main()

Measured memory_bytes: 2940
N, M = map(int, input().split())

even = 0
for ni in range(N):
    for nj in range(ni, N):
        if ni != nj:
            even += 1

odd = 0
for mi in range(M):
    for mj in range(mi, M):
        if mi != mj:
            odd += 1

ans = even + odd

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int st[1000003][5];
string q;
int dmc(int g,int k)
{
    if(g==q.length())return k;
    if(st[g][k]!=1e9)return st[g][k];
    int z=1e8;
    if(!k)z=min((dmc(g+1,0)+(q[g]-'0')),(dmc(g+1,1)+10-(q[g]-'0')));
    else{
        if(q[g]!='9')z=min(z,dmc(g+1,0)+1+(q[g]-'0'));
        z=min(z,dmc(g+1,1)+10-((q[g]-'0')+1));
    }
    return st[g][k]=z;
}
int main()
{
    int g;
    cin>>q;
    reverse(q.begin(),q.end());
    for(g=0;q[g];g++)st[g][0]=st[g][1]=1e9;
    printf("%d\n",dmc(0,0));
    return 0;
}


Measured memory_bytes: 70692
#include<stdio.h>

int main(void){
    int N,M;
    int small,big;
    scanf("%d %d",&N,&M);
    if(N<=M){
        small = N;
        big = M;
    }else{
        small = M;
        big = N;
    }
    if(small==1){
        if(big==1){
            printf("1");
            return 0;
        }else{
            printf("%d",big-2);
            return 0;
        }
    }else if(small==2){
        printf("0");
        return 0;
    }else if(small>=3){
        printf("%lld",(long long int)(small-2)*(big-2));
        return 0;
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
ll exp(ll taban, ll us) {
    ll carpan = taban % mod;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
    }
    return res;
}
ll ebob(ll a, ll b){
	if(!a)return b;
	return ebob(b%a, a);
}
ll ekok(ll a, ll b){
	return (a*b)/ebob(a, b);
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin>>n;
	cout<<(n+1)/2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int k;
    cin>>k;
    int a[n];
    int dp[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        dp[i]=1e12;
    }
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j=i;j<=i+k;j++){
            if(j<n){
                dp[j]=min(dp[j],dp[i]+abs(a[j]-a[i]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1792
#include <cstring>
#include <regex>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

int main() {
    string s;
    cin >> s;
    rep(i, s.length() + 1) {
        FOR(j, i, s.length()) {
            if (s.substr(0, i) + s.substr(j, s.length() - j) == "keyence") {
                cout << "YES" << endl;
                return 0;
            }
        }
    }

    cout << "NO" << endl;
    return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  if(A + B >= A - B && A + B >= A * B){
    cout << A + B << endl;
  }
  else if(A + B <= A - B && A - B >= A * B){
    cout << A - B << endl;
  }
  else if(A + B <= A * B && A - B <= A * B){
    cout << A * B << endl;
  }
  else {
    cout << "error" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
  int a,b;
  cin >> a >> b;
  int c = a - b + 1;
  vector<vector<char>> deka(a, vector<char>(a));
  vector<vector<char>> tiisa(b, vector<char>(b));
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < a; j++) {
      cin >> deka.at(i).at(j);
    }
  }
   for (int i = 0; i < b; i++) {
    for (int j = 0; j < b; j++) {
      cin >> tiisa.at(i).at(j);
    }
  }
  bool exist = false;
  for(int ss = 0;ss<c;ss++){
  for(int tt = 0;tt<c;tt++){
   if(ss+b-1>=a||tt+b-1>=a) continue;
    bool match = true;
   for (int i = 0; i < b; i++) {
    for (int j = 0; j < b; j++) {
      if(tiisa.at(i).at(j) != deka.at(i+ss).at(j+tt)) match = false;
    }
   }
    if(match) exist = true;
    }
  }
  if(exist) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 3604
#include <iostream>
#include <atcoder/all>
using namespace std;long N,Q,i,a;int main(){cin>>N>>Q;atcoder::fenwick_tree<long> b(N);for(;i<N;i++){cin>>a;b.add(i,a);}while(Q--){cin>>i>>a>>N;if(i)cout<<b.sum(a,N)<<endl;else b.add(a,N);}}

Measured memory_bytes: 8216
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
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 200005
int a[N];
deque<int> q1,q2;
void push(int x)
{
	while(!q1.empty()&&a[q1.back()]>a[x]) q1.pop_back();
	q1.push_back(x);
	while(!q2.empty()&&a[q2.back()]<a[x]) q2.pop_back();
	q2.push_back(x);
}
int mx[N],mi[N];
signed main()
{
#ifdef __LOCAL__
	freopen("in.txt","r",stdin);
#endif
	int n=read(),k=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1;i<k;i++) push(i);
	int ans=0,res=1;
	for(int i=k;i<=n;i++)
	{
		while(!q1.empty()&&q1.front()<i-k+1) q1.pop_front();
		while(!q2.empty()&&q2.front()<i-k+1) q2.pop_front();
		push(i);
		mi[i]=a[q1.front()],mx[i]=a[q2.front()];
		if(i>k&&mx[i]==a[i]&&mi[i-1]==a[i-k]) continue;
		if(q1.size()==k)
		{
			ans+=res,res=0; continue;
		}
		ans++;
	}
	cout<<ans<<endl;
#ifdef __LOCAL__
	printf("Time Used : %d\n",clock());
#endif
	return 0;
}



Measured memory_bytes: 2560
from itertools import permutations

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

patterns = list(permutations(range(n)))

g = [ [False for _ in range(n)] for _ in range(n) ]
for a, b in ab:
    g[a-1][b-1] = True
    g[b-1][a-1] = True

ans = 0
for p in patterns:
    if p[0] != 0:
        continue
    ok = True
    for i in range(n-1):
        if not g[p[i]][p[i+1]]:
            ok = False
    if ok:
        ans += 1
print(ans)


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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n, m;
    cin >> n >> m;
    int a[n], b[m];
    rep(i, 0, n)
        cin >> a[i];
    rep(i, 0, m)
        cin >> b[i];
    sort(a, a + n);
    sort(b, b + m);
    ll s1 = 0, s2 = 0;
    for (int i = 0; i < n - 1; i++)
        s1 = (s1 + (a[i + 1] - a[i]) * ((ll)(i + 1) * (n - i - 1) % MOD)) % MOD;
    for (int i = 0; i < m - 1; i++)
        s2 = (s2 + (b[i + 1] - b[i]) * ((ll)(i + 1) * (m - i - 1) % MOD)) % MOD;
    cout << s1 * s2 % MOD << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.io.*;
public class Main {

	public static void main(String[] args)throws IOException{
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);

		int n = 5;
		String c = br.readLine();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++){
		if(c.indexOf(" ") !=  -1){
		String str = c.substring(0, c.indexOf(" "));
		arr[i] = Integer.parseInt(str);
		c = c.substring(c.indexOf(" ") + 1);
		}
		else{
			arr[i] = Integer.parseInt(c);
		}
		}
		arr = sort(arr, 5);
		for(int i = 0; i < 5;i++){
			System.out.print(arr[i]);
			if(i != 4)
				System.out.print(" ");
		}
		System.out.println();
		
	}
	static int[] sort(int[] arr, int len){
		for(int i = 0; i < len;i++){
			int max = arr[i];
			int index = i;
			for(int j = i; j < len; j++){
				if(max < arr[j]){
					max = arr[j];
					index  = j;
				}
			}
			arr[index] = arr[i];
			arr[i] = max;
		}
		return arr;
	}

}

Measured memory_bytes: 9356
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  long long ret = 0;
  if (!(n & 1)) {
    int m = n / 2;
    for (int i = 0; i < m - 1; i++) {
      ret += - 2 * a[i] + 2 * a[n - 1 - i];
    }
    ret += -a[m - 1] + a[m];
  } else {
    int m = n / 2;
    for (int i = 0; i < m; i++) {
      ret += -2 * a[i] + 2 * a[n - 1 - i];
    }
    ret += max(a[m - 1] - a[m], a[m] - a[m + 1]);
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        var S = ReadLine();
        var K = cin.nextlong;
        for (int i = 0; i < S.Length; i++)
        {
            if (K - 1 == i)
            {
                WriteLine(S[i]);
                return;
            }
            if (S[i] != '1')
            {
                WriteLine(S[i]);
                return;
            }
        }

    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 11092
fun main(args: Array<String>) {
    val (x, y) = readLine()!!.split(" ").map{it.toLong()}

    val res: Long

    when {
        x in 0..y -> {
            res = y - x
        }
        x >= 0 && y >= 0 && x > y -> {
            res = Math.min(2 + x - y, 1 + x + y)
        }
        x < 0 && y <= x -> {
            res = 2 + x - y
        }
        x < 0 && y < 0 && x < y -> {
            res = y - x
        }
        x < 0 && y >= 0 -> {
            if (-x <= y) {
                res = Math.min(y - x, 1 + y - (-x))
            } else {
                res = Math.min(y - x, 1 + -y - x)
            }
        }
        x >= 0 && y < 0 -> {
            if (-x <= y) {
                res = 1 + y - (-x)
            } else {
                res = -y - x + 1
            }
        }
        else -> {
            res = 0
            System.exit(1)
        }
    }

    println(res)
}


Measured memory_bytes: 37744
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
inline void add(int &a,int b){if((a+=b)>=mod)a-=mod;}
int n,p,a[601],f[220001][601],lim[220001];
int main()
{
	cin>>n>>p;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+1+n,greater<int>());
	for(int i=0;i<=p;i++)lim[i]=lower_bound(a+1,a+1+n,i,greater<int>())-a-1;
	f[p][lim[p]]=1;
	for(int x=p;x>=0;x--)
		for(int i=n;i>=0;i--)
			if(f[x][i])
			{
				if(i)add(f[x][i-1],1ll*f[x][i]*i%mod);
				for(int j=lim[x]+1;j<=n;j++)add(f[x%a[j]][lim[x%a[j]]-(lim[x]-i)-1],f[x][i]);
			}
	int ans=0;
	for(int x=0;x<a[n];x++)add(ans,1ll*x*f[x][0]%mod);
	cout<<ans<<'\n';
}


Measured memory_bytes: 100096
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using boost::multiprecision::cpp_int;
using namespace std;
#define ll long long int
#define F first
#define S second
//#define endl "\n"
//#define nl cout<<endl;
#define pb push_back
#define ull unsigned long long 
#define f(i,a,b) for(ll i=a;i<b;i++)
#define Knucklehead ios_base::sync_with_stdio(false);cin.tie(NULL);
//#define mod 100000007
#define mat vector<vector<ll>>
mat cn(ll n, ll m){return vector< vector<ll> >(n, vector<ll>(m));}
bool compare(char &s1,char &s2){return s1 > s2;} 
bool sortmahstyle(const pair<ll,ll> &a,  const pair<ll,ll> &b) 
{ 
    if(a.second > b.second )
        return true;
    if( a.second==b.second && a.first > b.second )
       return true;
    return false;
}
bool cmp(int n, pair<int, int> const& p)
{
    return (p.first < n);
}
//me
ll const mod = 1e9+7;//998244353;
ll const inf = 1e18;
ll const maxn = 5e2+1;

bool month(ll n)
{
     return ( n>=1&&n<=12);
}
bool year(ll n){
     return (n>=0&&n<=99);
}
void solve()
{    
     ll n; cin >> n;

     ll last = n%10;
     n/=10;
     last += 10*(n%10);
     n/=10;
     bool yymm=0, mmyy=0;
     if( year(n) && month(last) )
          yymm=1;
     if( year(last) && month(n))
          mmyy=1;

     if(mmyy && yymm)
          cout << "AMBIGUOUS";
     else if (mmyy)
          cout << "MMYY";
     else if (yymm)
          cout << "YYMM";
     else 
          cout << "NA";
}

int main() {
Knucklehead 
//*
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
/**/ 
        
          ll t;
          /**/t=1;
          /*/cin>>t;/**/
          f(testcases,0,t){
               //cout << "Case #" <<testcases+1<<": ";
               solve();
          }
 
 
    return 0;
}

Measured memory_bytes: 3612
import java.util.*;

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

		int a[] = new int[5];
		for (int i = 0; i < 5; i++) {
			a[i] = sc.nextInt();
		}
		int k = sc.nextInt();

		int judge = 1;
		for (int i = 0; i < 4; i++) {
			for (int j = i+1; j < 5; j++) {
				if (a[j] - a[i] > k) {
					judge--;
				}
			}
		}

		if (judge == 1) {
			System.out.println("Yay!");
		} else {
			System.out.println(":(");
		}
	}
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,k,gc,bc,kc;
  cin >> a >> b >> c >> k;
  gc = b;
  bc = c;
  kc=0;
  while(gc<=a){
    gc*=2;
    kc++;
  }
  while(bc<=gc){
    bc*=2;
    kc++;
  }
  if(k>=kc){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3632
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<list>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
#define MK make_pair
const ll E=1e18+7;
const ll MOD=1000000007;
const ll MODD=1000000007;



int main(){
    string s;
    cin>>s;
    vector<ll> dp(3,0);
    ll A=1;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A'){dp[0]+=A; dp[0]%=MOD;}
        else if(s[i]=='B'){dp[1]+=dp[0]; dp[1]%=MOD;}
        else if(s[i]=='C'){dp[2]+=dp[1]; dp[2]%=MOD;}
        else if(s[i]=='?'){
            dp[2]=dp[2]*3+dp[1]; dp[2]%=MOD;
            dp[1]=dp[1]*3+dp[0]; dp[1]%=MOD;
            dp[0]=dp[0]*3+A; dp[0]%=MOD;
            A*=3; A%=MOD;
        }
    }
    cout<<dp[2]<<endl;
    
    return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for(int i = a ; i < (int)n ; i++)
#define INF 1e9
#define MAX_N 100000

using namespace std;

struct Card{
  char c;
  int num;
};

int n;
Card A[100000], B[100000];
int comp;
Card l[MAX_N/2+2];
Card r[MAX_N/2+2];

void merge(int left, int right, int mid){
  rep(i, mid-left){
    l[i] = B[left + i];
  }
  rep(i, right-mid){
    r[i] = B[mid + i];
  }

  l[mid-left].num = r[right-mid].num = INF;
  
  int left_idx, right_idx;
  left_idx = right_idx = 0;
  REP(i,left,right){
    comp++;
    if(l[left_idx].num <= r[right_idx].num){
      B[i] = l[left_idx];
      left_idx++;
    }else{
      B[i] = r[right_idx];
      right_idx++;
    }
  }
}

void mergeSort(int left, int right){
  if(right - left > 1){
    int mid = (right + left)/2;
    mergeSort(left, mid);     
    mergeSort(mid, right);    
    merge(left, right, mid);  
  }
}

int partition(int p, int r){
  int i;
  i = p-1;
  REP(j, p, r){
    if(A[j].num <= A[r].num){
      i++;
      swap(A[i], A[j]);
    }
  }
  swap(A[i+1], A[r]);
  
  return i+1;
}

void quickSort(int p, int r){
  if(r - p > 0){
    int ret = partition(p, r);
    quickSort(p, ret-1);
    quickSort(ret+1, r);
  }
}

bool compare(Card l, Card r){
  return (l.num <= r.num);
}

signed main(){

  cin >> n;
  rep(i, n){
    cin >> A[i].c >> A[i].num;    
    B[i].c = A[i].c;
    B[i].num = A[i].num;
  }
  
  quickSort(0, n-1);
  mergeSort(0, n);

  bool flag = false;
  rep(i, n){
    if(A[i].c != B[i].c) flag = true;
  }
  
  if(flag) cout << "Not stable" << endl;
  else cout << "Stable" << endl;

  rep(i, n){
    cout << A[i].c << " " << A[i].num << endl;
  }

}


Measured memory_bytes: 5352
#include<iostream>
#include<map>
using namespace std;
string s;
int d[200001];
map<int,int> best;
int main()
{
	cin>>s;
	int n=s.size(),x=0;s=' '+s;
	best[0]=0;
	for(int i=1;i<=n;i++)
	{
		d[i]=i;
		x^=1<<(s[i]-'a');
		for(int j=0;j<26;j++)
			if(best.count(x^(1<<j)))d[i]=min(d[i],best[x^(1<<j)]+1);
		if(best.count(x))d[i]=min(d[i],best[x]),best[x]=min(best[x],d[i]);
		else best[x]=d[i];
	}
	cout<<max(1,d[n])<<endl;
	return 0;
}


Measured memory_bytes: 10560
import scala.io.StdIn.{readLine,readInt}

object Main extends App {
  val seq1 = for(i<-1 to 9) yield List(i,i,i)
  val seq2 = for(i<-1 to 7) yield List(i,i+1,i+2)

  def check(m:List[Int], count:Int,u:Int,v:Int):Boolean =  {
    if(m.length != count) false
    else if(count==2) {
      val List(x,y) = m
      if(x==y) true else false
    } else {
      if((u to 8).exists( i=> check(m diff seq1(i),count-3,i,v))) {
        true
      } else {
        (v to 6).exists(i=> check(m diff seq2(i),count-3,u,i) )
      }
    }
  }

  Iterator.continually(readLine).takeWhile ( _!=null ).foreach { line =>
    val l = line.map(_.asDigit).toList
    val m = (1 to 9).filter { i=> if(l.count( _==i ) >= 4) false else check(i::l,14,0,0) }
    if(m.length>0) println(m.mkString(" ")) else println(0)
  }
}

Measured memory_bytes: 72252
#include <bits/stdc++.h>
#define INF 1ll<<60
#define int long long
using namespace std;
bool dia(int x,int j){
  int aux1,aux2;
  if(j>=10){
    aux1=j%10;
    j/=10;
    aux2=j%10;
    if(aux1>=2 and aux2>=2 and aux1*aux2==x)
      return true;
    return false;
  }
  return false;
}
signed main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  int M,D;
  cin>>M>>D;
  string a;
  int soma=0;
  for(int i=1;i<=M;i++){
    for(int j=1;j<=D;j++){
      if(dia(i,j)){
        soma++;
      }
    }
  }
  cout<<soma<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <numeric>
#define ll long long
using namespace std;

int main() {
	vector<int> p;
	ll max, n, hoge, ans;
	max = -1;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> hoge;
		if (hoge > max)max = hoge;
		p.push_back(hoge);
	}
	ans = accumulate(p.begin(), p.end(), 0);
	ans -= max;
	ans += max / 2;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

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

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

template <typename T>
std::vector<T> enum_div(T n) {
    std::vector<T> ret;
    for (T i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

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

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

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

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

    int N;
    cin >> N;
    vector<int> P(N);
    cin >> P;

    int ans = 0;
    int m = INF;
    REP(i, N) {
        if (m > P[i]) ans++;
        chmin(m, P[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
typedef long long ll;
#include <bits/stdc++.h>
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 );
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll mod = 1000000000+7;
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    ll n,c[200001],count[200001],result[200001];
    ll dokode_sum[200001];
  	ll dokode_last[200001];
    std::cin >> n;
    Fill(count,0);
    Fill(dokode_sum,0);
      Fill(dokode_last,-1);
    result[0] = 1;
    for (int i = 0; i < n; i++) {
        std::cin >> c[i];
        
        count[i]++;
        if(i>0){
            result[i] = result[i-1];
            if(c[i]!=c[i-1] && dokode_last[c[i]]!=-1){
              result[i] += result[dokode_last[c[i]]];
            }
        }
//            std::cout << result[i]<<" "<<dokode_last[c[i]] << std::endl;
      	dokode_last[c[i]] = i;
      result[i] %= mod;
    }
    std::cout << result[n-1]%mod << std::endl;
    
    
}


Measured memory_bytes: 8064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
int DBG = 1;										/* デバッグプリント 提出時は0 */
/* main *************************************************************/
int a[100001],dp[100001],grp[100001]={0};

int main()
{
	int		g,c,i,j,k,n,x,y,pre,ans;
	
	scanf("%d", &n);
	for(i=1;i<=n;i++) scanf("%d", &a[i]);

	ans = 1;
	grp[ans] = a[1];
	if (n>1) {
		for(i=2;i<=n;i++) {
			if (grp[ans] >= a[i]) {
				grp[++ans] = a[i];
			} else {
				for(j=1;j<=ans;j++) {
					if (grp[j]<a[i]) {
						grp[j] = a[i];
						break;
					}
				}
			}
		}
	}

	printf("%d\n",ans);


	return 0;
}


Measured memory_bytes: 896
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int A;
	rep(i, 0, 5)
	{
		cin >> A;
		if (A != (i + 1))cout << i + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 3560
class common_function():
    """
        1. よく使いそうで予め用意してあるものをまとめた
        2. よく使いそうな関数群をまとめた
    """
    def __init__(self):
        """
            1. 英字の一覧をリストに格納しておいた変数
        """
        self.sletter = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
        self.bletter = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']


    def combi(self, n:int, k:int, MOD=pow(10, 9) + 7):
        """
            mod の下での combination nCk を高速に求めるメソッド
            n が大きい場合(10^6)に使用する. 
            1回 nCk を求めるのに O(k) かかる.
        """
        k = min(k, n-k)
        numer = 1
        for i in range(n, n-k, -1):
            numer *= i
            numer %= MOD
        denom = 1
        for j in range(k, 0, -1):
            denom *= j
            denom %= MOD
        return (numer*(pow(denom, MOD-2, MOD)))%MOD


def main():
    common = common_function()
    X, Y = map(int, input().split())
    if X <= 0 or Y <= 0 or (X + Y) % 3 != 0:
        print(0)
        return
    if Y > 2*X or X > 2*Y:
        print(0)
        return
    for i in range(X):
        two = i
        one = X-2*i
        if two + one*2 == Y:
            break
    ans = common.combi(two+one, one)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9228
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>

#define SIZE 100005
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
 
using namespace std;


int main()
{	
	ll A[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	
	ll N;
	scanf("%lld", &N);



	printf("%lld", A[N-1]);
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <ctime>

#define pb push_back
#define ll long long
#define mp make_pair
#define f first
#define s second
#define pii pair < int, int >
#define ull unsigned long long
#define pll pair < ll, ll >
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)
#define all(s) s.begin(), s.end()
#define sz(a) (int)a.size()
#define filename "infinite"
const int inf = (1ll << 30) - 1;
const int N = (int)2e5 + 5;
using namespace std;


int n, a[N], st[N], h;
int L[N], R[N];


void solve() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", a + i);
	h = 0;
	for (int i = 1; i <= n; i++) {
		while (h > 0 && a[st[h]] > a[i]) h--;
		L[i] = st[h];
		st[++h] = i;
	}
	h = 0;
	st[0] = n + 1;
	for (int i = n; i > 0; i--) {
		while (h > 0 && a[st[h]] > a[i]) h--;
		R[i] = st[h];
		st[++h] = i;
	}
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += (ll)a[i] * (L[i] - i) * (i - R[i]);
	}
	cout << ans << "\n";
	
}

int main () {

	solve();


    return 0;
}




Measured memory_bytes: 3328
fun main(args: Array<String>) {
    val s = readLine()!!
    val len = s.length
    val ans = IntArray(len) { 0 }

    var rc = 0
    var lc = 0
    var ls = -1
    for (i in 0 until len - 1) {
        if (s[i] == 'R') rc++
        if (s[i] == 'L') lc++
        if (s[i] == 'R' && s[i + 1] == 'L') {
            ans[i] = rc / 2 + (rc % 2)
            ans[i + 1] = rc / 2
            rc = 0
            ls = i + 1
        }
        if (s[i] == 'L' && s[i + 1] == 'R') {
            ans[ls-1] += lc/2
            ans[ls] += lc / 2 + (lc % 2)
            lc = 0
        }
    }
    lc++
    ans[ls-1] += lc/2
    ans[ls] += lc / 2 + (lc % 2)


    println(ans.joinToString(" "))
}


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

int main() {
  
  int64_t N; string S; cin >> N;
  
  string alp = "abcdefghijklmnopqrstuvwxyz";
  
  while (true) {
    
    int64_t index = N % 26;
    
    if (index == 0) {
      index = 25;
      N--;
    }
    
    else index--;
    
    char tmp = alp.at(index);
    
    S = tmp + S; N /= 26;
    
    if (N == 0) break;
    
  }
  
  cout << S << endl;
  
}

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

int main() {
	int k, n;
	cin >> k >> n;
	int result = 0;

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

	int max;
	max = a[0] + k - a[n-1];

	for(int i = 1; i < n; i++) {
		if(max < a[i] - a[i - 1]) max = a[i] - a[i - 1];
	}

	cout << k - max << '\n';

    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i,n) for(ll i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define ll long long
//木構造グラフ
struct edge{
  struct treev* to;
  ll length;
  int num;
  int color;
  int pair;
};
struct treev{
  int num;
  vector<int> nexts;
};
vector<treev*> vs;
vector<edge> es;

vi colors;
int cmax=0;
treev* createtreenode(int num){
  treev* newt=new treev;
  if(newt==NULL){
    cout << "memory error" << endl;
    while(1){
      num=1;//メモリエラー対策
    }
  }
  newt->num=num;
  newt->nexts={};
  return newt;
}
void insertree(ll len,int Va,int Vb,int num){//結ぶ頂点を
  es.pb({vs[Va],len,num,-1});
  es.pb({vs[Vb],len,num,-1});
  int size=es.size();
  es[size-1].pair=size-2;
  es[size-2].pair=size-1;
  vs[Va]->nexts.push_back(size-1);
  vs[Vb]->nexts.push_back(size-2);
  
  return;
}
void DFS(treev* root,ll depth,treev* pre, int precol){
  //ここにやりたい処理を書く
  int ncnt=0;
  for(auto i:root->nexts){
    if(pre==es[i].to){
      continue;
    }
    while(1){
      if(ncnt==precol){
        ncnt++;
        continue;
      }
      es[i].color=ncnt;
      //cout<<i.pair->color<<endl;
      //
      
      
      //これを消すとACする。
      es[es[i].pair].color=ncnt;
      
      
      
      //
      colors[es[i].num]=ncnt;
      
      DFS(es[i].to,depth+es[i].length,root,ncnt);
      ncnt++;
      break;
    }
  }
  return;
}

  
int main(void){
  ll n;
  cin>>n;
  rep(i,n){
    vs.push_back(createtreenode(i));
  }
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    insertree(1,a-1,b-1,i);
  }
  colors=vi(n-1,-1);
  DFS(vs[0],0,NULL,-1);
  int cmax=0;
  rep(i,n-1){
    cmax=max(cmax,colors[i]);
  }
  cout<<cmax+1<<endl;
  rep(i,n-1){
    cout<<colors[i]+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 17132
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define d_flag 0
int v[50],n;
int get[100];
int c(const void* a,const void* b){
  return ((*((int *)a))-(*((int *)b)));
}
int d_count=100000;
void get_value(int a,int b){
  int itr=0;
  if(a+b>n){
    for(itr=0;itr<n;itr++){
      get[itr]=v[itr];
    }
    qsort(get,n,sizeof(int),c);
    return;
  }
  while(itr<a){
    get[itr]=v[itr];
    itr++;
  }
  itr=0;
  while(itr<b){
    get[itr+a]=v[n-itr-1];
    itr++;
  }
  qsort(get,a+b,sizeof(int),c);
  
}

int main(){
  int i,k,j,sum;

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

  for (i=0;i<n;i++){
    d_count-=d_flag; if(d_count<0){printf("AAA\n");break;}

    scanf("%d",&v[i]);
  }
  if(k>=n*2){
    if(d_flag)printf("take all.\n");
    sum=0;
    for(i=0;i<n;i++)
      sum+=(v[i]>0?v[i]:0);
    printf("%d",sum);
    return 0;
  }

  int  waste=0,max=0;
  for(;waste*2<=k;waste++){
    // a+b=k-waste
    for(i=0;i<=k-waste;i++){
      get_value(i,k-waste-i);
      if(d_flag){
	printf("waste:%d:",waste);
	for(j=0;j<k-waste;j++)
	  printf(" %d",get[j]);
      }
 
      j=0;sum=0;
      while(j<waste){
	sum+=get[j]>0?get[j]:0;
	j++;
      }
      while(j<k-waste){
	sum+=get[j++];
      }
      if(d_flag)
	printf(" >>> %d\n",sum);
      
      if(max<sum)max=sum;
    }
  }

  if(d_count<0)printf("err.\n");
  printf("%d\n",max);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define prev asnjsd
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define Aint(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FIint(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = (LL)INF * INF;

const int mod = 1000 * 1000 * 1000 + 7;
const int MAX = 1107;
int dp[200005];
int c[200005];
int prev[200005];
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < 200005; i++)
		prev[i] = -2;
    
    dp[0] = 1;
    for(int i = 0; i < n; i++)
    {
		cin >> c[i];
		dp[i + 1] = dp[i];
		if(prev[c[i]] + 1 != i && prev[c[i]] != -2)
		{
			dp[i + 1] += dp[prev[c[i]] + 1];
			dp[i + 1] %= mod;
		}
		prev[c[i]] = i;
	}
	cout << dp[n];
    return 0;
}


Measured memory_bytes: 2560
# import numpy as np
N, K, Q = list(map(int, input().split()))

p = [0] * N
# p = np.array(p)

# for _ in range(Q):
#     A = int(input()) - 1
#     p -= 1
#     p[A] += 1

for _ in range(Q):
    A = int(input()) - 1
    p[A] += 1

sum_p = sum(p)
# print(p)
for pp in p:
    if (pp + K) > sum_p:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 4680
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int n,k;
  cin >> n >> k;
  if((n+1)/2>=k)cout << "YES" << endl;
  else cout << "NO" << endl;
return 0;}

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

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

  string alph = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
  string ans;
  for (int i = 0; i < s.size(); i++) {
      ans += alph.at(alph.find(s.at(i)) + n);
  }

  cout << ans << endl;
}


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

using std::vector;
using std::cin;
using std::cout;
using std::endl;

int main()
{
	int N, K, num = 0;  // N: ブロック個数、K: ブロック強度、num: 積み上げるブロック数
	vector<int> digit;
	cin >> N >> K;
	for (;;) {
		int n = 0;
		while (num > ++n * K);
		num += n;
		if (num > N) {
			break;
		}
		digit.push_back(n);
	}
	cout << digit.size() << endl;
	return 0;
}




Measured memory_bytes: 3420
N, Y = map(int, input().split())
for i in range(N+1):
    for j in range(N-i+1):
        if 1000 * i + 5000 * j + 10000 * (N-i-j) == Y:
            print(N - i - j, j, i)
            exit()
print(-1, -1, -1)


Measured memory_bytes: 2940
import java.util.*;

public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        HashMap<String, Integer> map = new HashMap<>();
        for (int i = 0; i < N; ++i) {
            String S = sc.next();
            map.put(S, map.getOrDefault(S, 0));
            map.put(S, map.get(S) + 1);
        }
        sc.close();

        int ans = 0;
        for (Map.Entry<String, Integer> e : map.entrySet()) {
            if (e.getValue() % 2 != 0) {
                ++ans;
            }
        }

        System.out.println(ans);

    }
}

Measured memory_bytes: 51696
#include<iostream>
using namespace std;
#define f(a) for(int i=0;i<a;i++)

int main()
{
	int n,m;
	cin>>n>>m;
	int *card;
	card=new int[2*n];
	f(2*n){card[i]=i+1;}

	f(m){
		int k;
		cin>>k;
		int *card2;
		
		if (k){
			card2=new int[k];
			f(k){card2[i]=card[i];}
			f(2*n-k){card[i]=card[k+i];}
			f(k){card[2*n-k+i]=card2[i];}
		}
		else{
			card2=new int[n];
			f(n){card2[i]=card[n+i];}
			f(n){card[2*(n-1-i)]=card[n-1-i];}
			f(n){card[2*i+1]=card2[i];}
		}

		delete[]card2;
		}

	f(2*n){cout<<card[i]<<endl;}

	return 0;
}

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

int main()
{
	int n;
	cin >> n;
	vector<long long> a;
	a.resize(n+1);
	vector<long long> b;
	b.resize(n);
	for (int i = 0; i <= n; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < n; ++i) {
		cin >> b[i];
	}

	long long ret = 0;
	long long preb = 0;
	long long nokori = 0;
	for (int i = 0; i < n; ++i) {
		nokori = a[i] - preb;
		if (nokori <= 0) {
			ret += a[i];
			preb = b[i];
			continue;
		}
		
		if ((nokori - b[i]) <= 0) {
			preb = -(nokori - b[i]);
			ret += a[i];
		}
		else {
			preb = 0;
			ret += a[i] - (nokori - b[i]);
		}
	}

	if ((a[n] - preb) <= 0) {
		ret += a[n];
	}
	else {
		ret += preb;
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 1792