akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define mod ( (int)1e9 + 7 )
using namespace std;
int a , dp[10000007];
 
void solve()
{
	int n , k;
	cin >> n >> k;
	
	dp[0] = 1;
	
	for(int i = 1; i <= n; i++)
	{
		cin >> a;
		for(int j = 1; j <= k; j++)dp[j] = (dp[j - 1] % mod + dp[j] % mod ) % mod;
		for(int j = k; j >= a + 1; j--)dp[j] = ( dp[j] - dp[ j - a - 1 ] + mod ) % mod;
		
	}
	
	cout << dp[k] << endl;
}
 
 
main()
{
	solve();
}


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

using namespace std;

int n;

void p(int *card){
  printf("card\'s order:");
  for(int i=0;i<2*n;i++)
    printf("%d ",card[i]);
  printf("\b\n");
}
void shuffle(int *card){
  int tmp[n];
  for(int i=n;i<2*n;i++){
    tmp[i-n]=card[i];
  }
  for(int i=n-1;i>=0;i--){
    //bottom half
    card[2*i+1]=tmp[i];
    //top half
    card[2*i]=card[i];
  }
}
void cut(int k,int *card){
  int tmp[k];
  for(int i=0;i<k;i++){
    tmp[i]=card[i];
  }
  for(int i=0;i<2*n-k;i++){
    card[i]=card[i+k];
  }
  for(int i=2*n-k;i<2*n;i++){
    card[i]=tmp[i+k-2*n];
  }
}
int main(int args, char *argc[]){
  int m;
  while(cin>>n>>m){
    int card[2*n];
    for(int i=0;i<2*n;i++)
      card[i]=i+1;
//    p(card);

    while(m--){
      int k;
      cin>>k;
      if(k)
        cut(k,card);
      else 
        shuffle(card);
 //     p(card);
    }
    for(int i=0;i<2*n;i++)
      cout<<card[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 1160
#include<iostream>
#include<climits>
#include<cstdio>
#include<cmath>
using namespace std;
const int M=1e5+5;
const long long MN=LONG_MAX;
long long pos[M];
int main()
{
     int n,k;
     long long ans;
     while(cin>>n>>k)
     {
           pos[0]=0;
         int s=0,bound=0,flag=0;
         for(int i=1;i<=n;++i)
         {
             scanf("%lld",&pos[i]);
             if(pos[i-1]<0&&pos[i]>=0)s=i-1;
             if(s!=0)bound++;
         }
        // cout<<s<<endl;
         if(s==0)
         {
             if(pos[1]>=0)cout<<pos[k]<<endl;
             else if(pos[1]<=0)cout<<-pos[n-k+1]<<endl;
         }
         else
         {
           //  cout<<s<<" "<<bound<<endl;
             if(bound>k)bound=k;
             bound+=s;
             ans=MN;
            // cout<<s<<" "<<bound<<endl;
             for(int i=bound;i-k+1>=1&&i>=s;--i)
             {
                 int t=i-k+1;
               // cout<<t<<" "<<i<<endl;
                 if(t>s)ans=min(ans,pos[i]);
                 else if(i==s)ans=min(ans,-pos[t]);
                 else ans=min(ans,min(pos[i]+pos[i]-pos[t],-pos[t]+pos[i]-pos[t]));
               // cout<<ans<<endl;
             }
             cout<<ans<<endl;
          }
     }

}


Measured memory_bytes: 1024
from sys import stdin
import sys
import math
from functools import reduce
import itertools

n = int(stdin.readline().rstrip())
p = [x for x in stdin.readline().rstrip().split()]
q = [x for x in stdin.readline().rstrip().split()]

x = ()
y = ()
for pp in p:
    x = x + (pp,)
for qq in q:
    y = y + (qq,)

c = []
for i in itertools.permutations([str(j) for j in range(1,n+1)]):
    c.append(i)
    
a = c.index(x)
b = c.index(y)

print (abs(b-a))

Measured memory_bytes: 14408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int P[100001];
int K[100001];

int Find(int A) {
	if (P[A] < 0) return A;
	return P[A] = Find(P[A]);
}

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();

	pair<int, int> E[100010];
	int H[100010] = {};
	rep1(i, N) {
		int x = getint(), y = getint();
		E[i] = mp(y, H[x]);
		H[x] = i;
	}

	rep1(i, 100000) P[i] = -1;

	rep1(i, 100000) {
		if (H[i]) {
			int a = Find(E[H[i]].first);
			for (int j = E[H[i]].second; j; j = E[j].second) {
				int b = Find(E[j].first);

				if (a == b) continue;
				if (P[a] > P[b]) swap(a, b);
				P[a] += P[b];
				P[b] = a;
				K[a] += K[b];
			}
			K[a]++;
		}
	}

	ll kotae = 0;
	rep1(i, 100000) {
		if (K[i] && P[i] < 0) {
			kotae -= 1ll * K[i] * P[i];
		}
	}
	co(kotae - N);

	Would you please return 0;
}

Measured memory_bytes: 2304
#![allow(unused_imports)]

//input
use proconio::input;
use proconio::marker::{Bytes, Chars};
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;
//use std::collections::BinaryHeap;

//use std::cmp::*;

fn main() {
    input! {
        r: f64,
    }

    let pi = 3.14159265358979323846264;

    println!("{}", 2. * pi * r);
}


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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};

 
int main(){
  int n;
  cin >> n;
  string ans;
  if(n==3 || n==5 || n==7) ans = "YES";
  else ans = "NO";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007;



int main()
{
    ll H;
    cin >> H;
    int a = 0;
    
    while (H > 1) {
        a++;
        H/=2;
    }
    ll ans = 1;
    ll an = 1;
    rep(i,a){
        an *= 2;
        ans += an;
    }
    out(ans);


    return 0;
}


Measured memory_bytes: 256
use {
    proconio::{input, marker::Usize1},
    std::{
        collections::{BTreeSet, BTreeMap},
        ops::Bound::Included,
    },
};

const M: usize = usize::max_value();

fn main() {
    input! {
        h: usize,
        w: usize,
        ab: [(Usize1, Usize1); h],
    }

    let mut es = BTreeSet::new();
    let mut dc = BTreeMap::new();
    for j in 0..w {
        es.insert((j, j));
    }
    dc.insert(0, w);

    for i in 0..h {
        let (a, b) = ab[i];
        let mut rm = vec![];
        for &(e, s) in es.range((Included(&(a, 0)), Included(&(b, w)))) {
            rm.push((e, s));
        }
        let add = if let Some(&(_, s)) = es.range((Included(&(a, 0)), Included(&(b, w)))).last() {
            let e = if b == w - 1 { M } else { b + 1 };
            Some((e, s))
        } else {
            None
        };

        for (e, s) in rm {
            es.remove(&(e, s));

            let d = e - s;
            if let Some(v) = dc.get_mut(&d) {
                if *v <= 1 {
                    dc.remove(&d);
                } else {
                    *v -= 1;
                }
            }
        }

        if let Some((e, s)) = add {
            es.insert((e, s));
            *dc.entry(e - s).or_insert(0) += 1;
        }

        let d = if let Some(f) = dc.iter().next() { *f.0 } else { M };
        if d >= w {
            println!("-1");
        } else {
            println!("{}", d + i + 1);
        }
    }
}


Measured memory_bytes: 14972
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

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

  int x, y, s;
  while (true) {
    cin >> x >> y >> s;
    if (x == 0 && y == 0 && s == 0) break;
    // s = p*(100+x)/100
    // p = s * 100 / (100+x)
    int ans = 0;
    for (int i = 1; i < s; i++) {
      for (int j = 1; j < s; j++) {
        int s1 = i * (100 + x) / 100;
        int s2 = j * (100 + x) / 100;
        if (s1 + s2 != s) continue;
        s1 = i * (100 + y) / 100;
        s2 = j * (100 + y) / 100;
        ans = max(ans, s1 + s2);
      }
    }
    cout << ans << "\n";
  }

  return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
struct UnionFind
{
  vector<ll> data;
  UnionFind(ll size) : data(size, -1) {}
  bool unionSet(ll x, ll y)
  {
    x = root(x);
    y = root(y);
    if (x != y)
    {
      if (data[y] < data[x])
        swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool findSet(ll x, ll y)
  {
    return root(x) == root(y);
  }
  ll root(ll x)
  {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  ll size(ll x)
  {
    return -data[root(x)];
  }
};
int main()
{
ll n , m , q ;
cin >> n >> m >> q ;
vector<vector<ll>> v;
set<ll> s;
set<ll> sss;
UnionFind arr(n);
set<pair<ll,ll>> ss;
rep(i,q){
  ll a , b , c ;
  cin >> a >> b >> c ;
  s.insert(a);
  s.insert(b);
  if(c==0)arr.unionSet(a, b);
  else {
    ss.insert({a,b});
    sss.insert(a);
    sss.insert(b);
    vector<ll> aaa={a,b};
    v.emplace_back(aaa);
  }
}
rep(i,v.size()){
  if(arr.findSet(v[i][0], v[i][1])){
    cout << "No" << endl;
    return 0;
  }
}
ll ko=0;
set<ll> ssss;
rep(i,n){
  ssss.insert(arr.root(i));
}

ll und=n-s.size();
if(ss.size()==1&&und==0){
  cout << "No" << endl;
  return 0;
}
if(ss.size()>=1&&m==n-1){
  cout << "No" << endl;
  return 0;
}
/* if(m>(und+sss.size())*(und+sss.size()-1)/2 -(und+sss.size())+n){
  cout << "No" << endl;
  return 0;
} */
if(m-(n-ssss.size())>(ssss.size()-1)*ssss.size()/2){
  cout << "No" << endl;
  return 0;
}
if(und+sss.size()==0 && m!=n-1){
  cout << "No" << endl;
  return 0;
}
cout << "Yes" << endl;
return 0;
}

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

int main()
{
    ll L, R;
    cin >> L >> R;

    ll ans = LLONG_MAX;
    ll maxL = min(L+2019, R);
    for(ll i=L;i<=maxL;i++){
        for(ll j=i+1;j<=maxL;j++){
            ans = min(ans, i*j%2019);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
const int N = 2e5 + 10, OO = 0x3f3f3f3f, mod = 1e9 + 7;

#define PI acos(-1)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, n) for (int i = 0; i < int(n); i++)
#define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define xloop(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ALL(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
//int dx[] = {1, 0, -1, 0};
//int dy[] = {0, 1, 0, -1}; //4 Direction
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; //8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

int n , m , k;

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

  /*
        3 4 240
        60 90 120 -- SumA : 60 150 270
        80 150 80 150 -- SumB : 0 80 230 310 460
                                0 1   2   3   4
 
    */
  scanf("%d %d %d", &n, &m, &k);
  vector<ll> prefA(n + 1), prefB(m + 1);
  for (int i = 1; i <= n; ++i)
  {
    scanf("%lld", &prefA[i]);
    prefA[i] += prefA[i - 1];
  }

  for (int i = 1; i <= m; ++i)
  {
    scanf("%lld", &prefB[i]);
    prefB[i] += prefB[i - 1];
  }

  // we want to count how many i , j (0 <= i <= n , 0 <= j <= m) such that
  // a[j] + b[j] <= k -- b[j] <= k - a[j]

  int ans = 0;
  for (int cntA = 1; cntA <= n; ++cntA)
  {
    if (prefA[cntA] > k)
      break;
    ll bj = k - prefA[cntA];
    int cntB = upper_bound(prefB.begin(), prefB.end(), bj) - prefB.begin() - 1;
    ans = max(ans, cntA + cntB);
  }
  for (int cntB = 1; cntB <= m; ++cntB)
  {
    if (prefB[cntB] > k)
      break;
    ll aj = k - prefB[cntB];
    int cntA = upper_bound(prefA.begin(), prefA.end(), aj) - prefA.begin() - 1;
    ans = max(ans, cntA + cntB);
  }

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

  return 0;
}


Measured memory_bytes: 6416
#include<iostream>
#include<string>
#include<algorithm>
#include <sstream>

using namespace std;

string func(string);
string itos(int);

int main(void){
  int n;
  string in;

  while(cin >> n,n){
  cin.ignore();
  cin >> in;

  while(n--)
    in=func(in);

  cout << in << endl;
  }
  return 0;
}

string func(string s){
  int cnt=1,i;
  string ans;
  for(i=1;i<s.size();i++){
    if(s[i]==s[i-1])cnt++;
    else {
      ans+=itos(cnt);
      ans+=s[i-1];
      cnt=1;
    }
  }
  ans+=itos(cnt);
  ans+=s[i-1];

  return ans;
}

string itos( int i ) {
  ostringstream s ;
  s << i ;
  return s.str() ;
}

Measured memory_bytes: 1356
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 1e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
int color[nax];
vector< int > g[nax];
void dfs(int u , int p , int c){
	color[u] = c;
	for(auto v : g[u]){
		if(color[v] == c){
			cout << -1 << endl;
			exit(0);
		}
		if(color[v] == 0){
			dfs(v , u , 3 - c);
		}
	}
}
int main(){
	dhoom;
	int s , w;
	cin >> s >> w;
	if(w >= s)
		cout << "unsafe" << endl;
	else 
		cout << "safe" << endl;
	
}


Measured memory_bytes: 27088
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    ll H, W;
    cin >> H >> W;
    if (H == 1 || W == 1) {
        cout << 1 << endl;
    } else {
        cout << (H * W + 1LL) / 2LL << endl;
    }
    return 0;
}


Measured memory_bytes: 256
a,b,c,x,y=map(int,input().split())

if x >= y:
    print(min(a*x+b*y , 2*x*c , 2*c*y + a*(x-y)))

else:
    print(min(a*x+b*y , 2*y*c , 2*c*x + b*(y-x)))
    

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<int>>;
#define MAX 100000

int main()
{
    ll l,r;
    cin >> l >> r;
    int mod_l=l%2019;
    int mod_r=r%2019;
    if(mod_r<=mod_l){
        cout << 0 << endl;
    }else{
        if(l+2019<r){
            cout << 0 << endl;
        }else{
            int min=MAX;
            for(int i=mod_l;i<mod_r;++i){
                for(int j=i+1;j<=mod_r;++j){
                    if((i*j)%2019<min){
                        min=(i*j)%2019;
                    }
                }
            }
            cout << min << endl;
        }
    }
}

Measured memory_bytes: 3604
object Main extends App {
  val _ = readLine

  val (t, a) = readLine.split(" ").map(_.toInt) match {
    case Array(t, a) => (t, a)
  }
  def temp(h: Int) = t - 0.006 * h
  val res = readLine
    .split(" ")
    .map(_.toInt)
    .map(h => math.abs(temp(h) - a))
    .zipWithIndex
    .min(Ordering.fromLessThan[(Double, Int)]((t1, t2) => t1._1 <= t2._1))
    ._2
  println(res + 1)

}

Measured memory_bytes: 27196
/*
   first we need to sort the all edges then updates them one after another .
   we update them according to the adjacent edges then maximize the answer of edge
*/
#include<queue>
#include<map>
#include <string>
#include<bits/stdc++.h>
#define pi 3.141592654
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);
//#define x real()
//#define y imag()
using namespace std;
typedef pair<double,double>pdd;
typedef long long  ll;
typedef pair<ll, ll>pii;
//typedef complex<double> point;
//template<typename T>T gcd(T x, T y) { if(y == 0)return x; else return gcd(y, x%y); }
//typedef bitset<30> mask;
//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
//#define var(x) ((x)<<1)
//#define nvar(x) ((x)^1)

 main()
{

//cout<<Pow((ll)1000000,(ll)110);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//    char input[15];
//    scanf("%s", &input);  array of char
//  gets(c+1);  array of char
//printf("%s, ",name[k[i]].c_str());  printf of string
input;
int a,b;
cin>>a>>b;

if(a<=5)cout<<"0";
else if(a>5&&a<13)cout<<b/2;
else cout<<b;
return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Node{
	int id;
	int parent, left, right;
	public Node(int id){
		this.id = id;
		this.parent = -1;
		this.left = -1;
		this.right = -1;
	}
}

class Nodes{

	Node[] nodes;

	public void printPre(int id){
		if(id == -1)
			return;
		System.out.print(" " + id);
		printPre(nodes[id].left);
		printPre(nodes[id].right);
	}

	public void printIn(int id){
		if(id == -1)
			return;
		printIn(nodes[id].left);
		System.out.print(" " + id);
		printIn(nodes[id].right);
	}

	public void printPost(int id){
		if(id == -1)
			return;
		printPost(nodes[id].left);
		printPost(nodes[id].right);
		System.out.print(" " + id);
	}
}

public class Main{

	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		Node[] nodes = new Node[n];
		Nodes mynodes = new Nodes();
		mynodes.nodes = nodes;
		for(int i = 0; i < n; i++)
			nodes[i] = new Node(i);
		for(int i = 0; i < n; i++){
			int id = scan.nextInt();
			int left = scan.nextInt();
			int right = scan.nextInt();
			if(left != -1){
				nodes[id].left = left;
				nodes[left].parent = id;
			}
			if(right != -1){
				nodes[id].right = right;
				nodes[right].parent = id;
			}
		}

		int root = 0;
		while(nodes[root].parent != -1)
			root = nodes[root].parent;

		System.out.print("Preorder\n");
		mynodes.printPre(root);
		System.out.print("\nInorder\n");
		mynodes.printIn(root);
		System.out.print("\nPostorder\n");
		mynodes.printPost(root);
		System.out.println();
	}
}

Measured memory_bytes: 26340
import itertools

N, M = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(M)]

def is_path(seq):
    for idx in range(len(seq)):
        if idx == 0:
            if [1, seq[idx]] not in edges and [seq[idx], 1] not in edges:
                return False
        else:
            if [seq[idx-1], seq[idx]] not in edges and [seq[idx], seq[idx-1]] not in edges:
                return False
    return True
        
num = 0
for seq in list(itertools.permutations(list(range(2, N+1)))):
    if is_path(seq):
        num += 1
print(num)

Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define int long long
#define fi first
#define sc second
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define msi map<string,int>
#define si set<int>
#define all(v) v.begin(),v.end()
#define sz(v)  int((v).size())
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define dep(i,a,b)	for(int i=a;i>=b;i--)
#define isinarr(i,n) ((i>=0)?((i<n)?1:0):0)
#define fastio  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ppb pop_back
#define present(container, element) (container.find(element) != container.end())      //set,map etc.
#define cpresent(container, element) (find(all(container),element) != container.end())    //vector
#define hell 1000000007
#define PI 3.14159265
#define mp make_pair
#define inparr(a,n) rep(i,0,n)cin>>a[i];
#define give(x,y) cout<<x<<" "<<y<<endl;
#define setp(n) cout<<fixed<<setprecision(n);
#define	endl '\n'

using namespace std;
void solve()
{
	int n,i,j,k,l;
	cin>>k>>n;
	int a[n],gap=0;
	rep(i,0,n)
	{
		cin>>a[i];
		if(i==0)
		{
			gap=a[0]-0;
		}
		else
		{
			gap+=a[i]-a[i-1];
		}
	}
	gap+=k-a[n-1];
	int large=a[0]+(k-a[n-1]);
	int miin=10000000;
	rep(i,0,n)
	{
		if(i==0)
		{
			miin=min(miin,gap-large);
		}
		else
		{
			miin=min(miin,gap-(a[i]-a[i-1]));
		}
	}
	cout<<miin;
} 



signed main()
{
    fastio
    int t=1;
    //cin>>t;
    while(t--)
    	solve();
    return 0;
}

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

using namespace std;

int main(){
  int n,k; cin >> n >> k;
  vector<int> h(n);
  for(int i=0;i<n;++i) cin >> h[i];
  sort(h.begin(),h.end());
  int ans=1e9;
  for(int i=0;i+k-1<n;++i)
    ans = min(ans,h[i+k-1]-h[i]);
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
using namespace std;
#define int long long
#define V vector
#define vel V<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp make_pair
#define pin pair<int,int>
pin solve(V<pin>& ab, int ex) {
	if (!ex) { return mkp(0, 0); }
	V<V<pin>> qab(2);
	int sz = ab.size();
	qab[0].reserve(sz);
	qab[1].reserve(sz);
	for (pin& x : ab) {
		qab[x.second & 1].push_back(mkp(x.first / 2, x.second / 2));
		if (x.first & 1) { qab[(x.second + 1) & 1].push_back(mkp(x.first / 2, (x.second + 1) / 2)); }
	}
	int c = 0;
	for (pin& x : qab[0]) {
		int qc = 2 * x.first + x.second + 1;
	qc = (qc & (0xffffffff)) + ((qc & (0x7fffffff00000000)) >> 32);//qc<=1ffffffff
	qc = (qc & (0xffff)) + ((qc & (0x1ffff0000)) >> 16);//qc<=2ffff
	qc = (qc & (0xff)) + ((qc & (0x3ff00)) >> 8);//qc<=3ff
	qc = (qc & (0xf)) + ((qc & (0x3f0)) >> 4);//qc<=4e
	qc = (qc & (0xf)) + ((qc & (0x7e)) >> 4);//qc<=18
	qc = (qc & 3) + ((qc & 28) >> 2);
	qc = (qc & 3) + ((qc & 4) >> 2);
		c ^= qc;
	}
	if (!c) {
		pin ans = solve(qab[1], ex - 1);
		ans.first *= 2; ans.second *= 2; ans.second++;
		return ans;
	}
	pin ans = solve(qab[0], ex - 1);
	c = 0;
	int d = 0;
	for (pin& x : qab[1]) {
		int w = ans.second - x.second - 1;
		if ((w & x.first) == w) { c ^= 1; }
		w++;
		if ((w & x.first) == w) { d ^= 1; }
	}
	ans.first *= 2; ans.second *= 2;
	ans.first += (c | d); ans.second -= c;
	return ans;
}
signed main() {
	cin.tie(0); ios::sync_with_stdio(false);
	long long inf = 1e17;
	int n; cin >> n;
	V<pin> ab(n);
	rep(i, n) {
		long long a, b; cin >> a >> b;
		ab[i] = { a + inf,b + inf };
	}
	pin ret = solve(ab, 59);
	cout << ret.first - inf << " " << ret.second - inf << "\n";
}


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

#define mp make_pair
#define pb push_back
#define xx first
#define yy second
#define i64 long long int
#define MEM(a,x) memset(a,x,sizeof(x))
#define INF 1000000000
#define mod 1000000007LL

using namespace std ;

typedef pair<int,int> pi ;

#define maxn 100005

i64 dp[404][404] , f[404][404] , a[404] , b[404] ;

int main()
{
    i64 i , j , k , l , m ;

    for(i=0 ; i<=400 ; i++)
    {
        i64 ret = 1LL ;
        for(j=0 ; j<=400 ; j++ ,ret =(ret*i)%mod) f[j][i] = ret ;
    }

    for(i=0 ; i<=400 ; i++) for(j=1 ; j<=400 ; j++) f[i][j] = ( f[i][j-1] + f[i][j] )%mod ;

 //   printf("%lld\n",f[2][3]) ;

    i64 n, c ;

    scanf("%lld %lld",&n,&c) ;

    for(i=1 ; i<=n  ; i++ ) scanf("%lld",&a[i]) ;
    for(i=1 ; i<=n  ; i++ ) scanf("%lld",&b[i]) ;

    dp[0][0] = 1LL ;

    for(i=1 ; i<=n ; i++)
    {
        for(j=0 ; j<=c ; j++)
        {
            for(k=0 ; k+j<=c ; k++)
            {
                i64 s = k+j;
                dp[i][s] += dp[i-1][j]*( f[k][ b[i] ] - f[k][ a[i]-1 ] ) ;
                dp[i][s] %= mod ;
            }
        }
    }

    i64 ans = dp[n][c] ;
    ans = ( ans%mod + mod )%mod ;

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

    return 0 ;
}


Measured memory_bytes: 2816
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()

int main()
{
	int N;
	cin >> N;
	int ans = 0;
	int prev = -1;
	int count = 0;
	rep(i, N) {
		int a;
		cin >> a;
		if (prev == -1) {
			count = 1;
			prev = a;
		} else if (a == prev) {
			count++;
		} else {
			ans += count / 2;
			count = 1;
			prev = a;
		}
	}
	ans += count / 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] c = new int[n][26];
        for (int i = 0;i < n;i++) {
            char[] s = sc.next().toCharArray();
            for (int j = 0;j < s.length;j++) {
                c[i][s[j]-97]++;
            }
        }
        int[] m = new int[26];
        for (int i = 0;i < 26;i++) m[i] = 1010;
        for (int i = 0;i < n;i++) {
            for (int j = 0;j < 26;j++) {
                m[j] = Math.min(m[j], c[i][j]);
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0;i < 26;i++) {
            int l = m[i];
            for (int j = 0;j < l;j++) {
                sb.append((char)(i+97));
            }
        }
        System.out.println(sb.toString());
    }
}

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

using str = string;
using ss = stringstream;

int a[26];

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

    str s;cin>>s;

    for(int i=0;i<s.size();i++)a[s[i]-'a']++;

    if(s.size()==26)
    {
        for(int i=s.size()-1;i>=0;i--)
        {
            int j=s[i]-'a';
            for(;j<26;j++)if(a[j]==0)
            {
                s[i]=j+'a';break;
            }

            if(j==26)
            {
                a[s[i]-'a']--;
                s[i]='A';
            }
            else break;
        }
    }
    else
    {
        for(int i=0;i<26;i++)if(a[i]==0){s.push_back(i+'a');break;}
    }
    

    if(s[0]=='A')cout<<-1;
    else for(int i=0;i<s.size();i++)
    {
        if(s[i]=='A')break;
        cout<<s[i];
    }

    cout<<"\n";

    return 0;
}


Measured memory_bytes: 3660
def main():
    N = int(input())
    A = [int(input()) for a in range(N)]
    S = set()

    for i in range(N):
        if A[i] in S:
            S.remove(A[i])
        else:
            S.add(A[i])
    print(len(S))
if __name__ == "__main__":
    main()

Measured memory_bytes: 13204
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

string s[102];
int main(){
    int h,w;
    cin>>h>>w;
    rep(i,h){
        string si;
        cin>>si;
        s[i+1]="#";
        s[i+1]+=si+"#";
    }
    rep(i,w+2){
        s[0]+='#';
        s[h+1]+='#';
    }
    rep(i,h+2){
        cout<<s[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
from operator import itemgetter
N= int(input())
ans = 1
a = []

for i in range(N):
    tmpa, tmpb = map(int,input().split())
    a.append([tmpa+tmpb, tmpa-tmpb])

a.sort()
    
tmp = a[0][0]
for i in range(1, N):
    if a[i][1] >= tmp:
        ans += 1
        tmp = a[i][0]
print(ans)


Measured memory_bytes: 20136
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<cmath>
#include<cstring>
using namespace std;
typedef long long ll;

ll ans(ll sum,ll n,ll now,ll jnum);
ll joi[65005]={};

int main(){
  ll n,p;  
  while(1){
    p=0;
    scanf("%lld",&n);
    if(n==0) break;
    for(ll i=0;i<n;i++){
      ll a;
      scanf("%lld",&a);
      p+=a;
    }
    for(ll i=0;i<n-1;i++){
      scanf("%lld",&joi[i]);
    }
    sort(joi,joi+n-1);
    cout<<ans(p,n,0,n-2)<<endl;
  }
  return 0;
}
  
ll ans(ll sum,ll n,ll now,ll jnum){
  ll aa=sum*n,es;
  if(aa<(sum+joi[jnum-now])*(n-1)){
    es=ans(sum+joi[jnum-now],n-1,now+1,jnum);
    aa=max(es,aa);
  }
  return aa;
}



Measured memory_bytes: 3660
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
#define endl "\n"
//#define int long long
#define ALL(x) begin(x),end(x)
#define resort(v) sort((v).rbegin(), (v).rend())
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int fact(int i) {
    if (i == 0) return 1;
    return ((fact(i - 1)) * i) % MOD;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
int modpow(int a, int n, int mod) {
    int hi = 1;
    while (n > 0) {
        if (n & 1) hi = hi * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return hi;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}
/*signed*/int main(void) {
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    ll f = min(k, x / d);
    k -= f;
    x -= f * d;
    if (k & 1) cout << d - x << endl;
    else cout << x << endl;
    return 0;
}

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

int main() {
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());

    int N, K;
    cin >> N >> K;

    vector<int> D(K);
    for (int i = 0; i < K; i++) {
        cin >> D[i];
    }

    for (int i = 0; ; i++) {
        // N未満はスキップ
        if (i <N) continue;
        
        // 各桁の数が嫌いな数でないかチェック
        int number = i;
        bool hasNgNum = false;
        while(number > 0) {
            int n = number % 10;
            for (int j = 0; j < K; j++) {
                if (n == D[j]) {
                    hasNgNum = true;
                    break;
                }
            }
            number /= 10;
        }

        // 嫌いな数がなければそれを出力
        if (!hasNgNum) {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
// #define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pair < pii, int > a, pair < pii, int > b)//true for a before b
{
	if(a.F.F/300 < b.F.F/300)
		return 1;
	if(a.F.F/300 > b.F.F/300)
		return 0;
	if(a.F.S < b.F.S)
		return 1;
	if(a.F.S > b.F.S)
		return 0;
	if(a.F <= b.F)
		return 1;
	return 0;
}

const int N = (1e6) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 2*550;
const int SQRT = BUCK+9;

ll fact[N], ifact[N];

void pre()
{
	int i;
	fact[0] = ifact[0] = 1;
	fo(i,1,N)
	{
		fact[i] = (fact[i-1] * 1LL * i)%mod;
		ifact[i] = inmodx(fact[i]);
	}
	return;
}

ll choose(int n, int r)
{
	if(n < 0 || r < 0 || r > n)
		return 0LL;
	ll ans = (fact[n]*ifact[r])%mod;
	ans = (ans * ifact[n-r])%mod;
	return ans;
}

void solve()
{
	pre();
	int n, i;
	ll ans = 0, val, sum = 0;
	cin >> n;

	if(n == 2)
	{
		cout << 1 << '\n';
		return;
	}
	
	fo(i,(n+1)/2,n)
	{
		val = (choose(i-1,n-1-i)*fact[i])%mod;
		val = (val * fact[n-1-i])%mod;
		ans = (ans + 1LL*i*(val-sum+mod))%mod;
		sum = val;
	}	
	cout << ans << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(9);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  string s;
  map<string,int> mp;
  
  for (int i = 0; i < n; i++){
    cin >> s;
    mp[s]++;
  }
  
  int mx = 0;
  for (auto p : mp) mx = max( mx, p.second );
  for (auto p : mp){
    if(p.second != mx) continue;
    cout << p.first << endl;
 }
 return 0;
}

Measured memory_bytes: 25216
#include<iostream>
#include<vector>
#include<algorithm>
#define MOD 1000000007
using namespace std;
int main(){
  long long int r=0,c=0;
  long long int n,m; cin >> n >> m;
  vector<int> row(n), col(m); 
  for(int i=0;i<n;i++) cin >> row[i];
  for(int i=0;i<m;i++) cin >> col[i];
  sort(row.begin(), row.end(), greater<int>());
  sort(col.begin(), col.end(), greater<int>());
  long long int ans = 1;
  int rp=0,cp=0;
  for(int i=0;i<n*m;i++){
    int num = n*m-i;
  	if(rp<n && row[rp]==num && cp<m && col[cp]==num){
    	ans = ans; r++;c++;rp++;cp++;
    }else if(rp<n && row[rp]==num){
    	ans = (c * ans)%MOD; rp++; r++;
    }else if(cp<m && col[cp]==num){
    	ans = (r * ans)%MOD; cp++; c++;
    }else{
      	ans = ((r*c - i)*ans)% MOD; 
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/*
 * c.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int a, b;
  cin >> a >> b;
  printf("%d %d\n", a * b, (a + b) * 2);
  return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

string S, C, T;

void input() { cin >> S >> C >> T; }
void solve() {
  cout << "A" << C[0] << "C" << endl;
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
n = int(input())
b = [int(i) for i in input().split(" ")]
r = []

while len(b) > 0:
    f = False
    for i in reversed(range(0, len(b))):
        if b[i] == i + 1:
            r.append(b[i])
            del b[i]
            f = True
            break
    if not f:
        print(-1)
        r = []
        break

for i in reversed(range(0, len(r))):
    print(r[i])

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

vector<ll> v;
vector<char> ans;
bool ok=1;
ll n, t;
ll ind=0;

void solve(string s) {
  if (!v[s[0]-'A'] && !v[s[1]-'A']) {
    ok=0;
    return;
  }
  if (!v[s[0]-'A']) v[s[0]-'A']++, v[s[1]-'A']--, ans[ind++]=s[0];
  else if (!v[s[1]-'A']) v[s[1]-'A']++, v[s[0]-'A']--, ans[ind++]=s[1];
  else {
    if (t == 2) {
      if (n--) {
        string c;
        cin >> c;
        if (s[0] == c[0] || s[0] == c[1])
          v[s[0]-'A']++, v[s[1]-'A']--, ans[ind++]=s[0];
        else
          v[s[1]-'A']++, v[s[0]-'A']--, ans[ind++]=s[1];
        solve(c);
      }
      else 
        v[s[0]-'A']++, v[s[1]-'A']--, ans[ind++]=s[0];
    }
    else {
      if (v[s[1]-'A'] == t-1)
        v[s[0]-'A']++, v[s[1]-'A']--, ans[ind++]=s[0];
      else
        v[s[1]-'A']++, v[s[0]-'A']--, ans[ind++]=s[1];
    }
  }
}

int main() {
  cin >> n;
  v.resize(3), ans.resize(n);
  cin >> v[0] >> v[1] >> v[2];
  t=v[0]+v[1]+v[2];
  while (n-- > 0) {
    string s; cin >> s;
    if (!ok) continue;
    solve(s);
  }
  if (n == 0 || !ok) cout << "No";
  else {
    cout << "Yes\n";
    for (char c : ans)
      cout << c << "\n";
  }
  return 0;
}


Measured memory_bytes: 3696
#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<set>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 

#define  mx 200004
#define base 193ll
 
typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  200007
#define md 998244353ll
///////////////////////////
///////////////////////////
///


int main(){

    int n ;
    I(n);

    string a[] = {"Christmas Eve Eve Eve", "Christmas Eve Eve", "Christmas Eve", "Christmas"};

    cout<<a[n-22]<<endl;

    return 0;
}

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

using namespace std;

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

using ll = long long;

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
    cout << '[';
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len-1) s << ", ";
	}
    cout << ']';
	return s;
}

int main(){

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

	int a, b;
	cin >> a >> b;
	int ans = 0;
	if(a > b){
		ans += a;
		--a;
	}
	else{
		ans += b;
		--b;
	}

	if(a > b){
		ans += a;
	}
	else{
		ans += b;
	}

	ppp(ans);


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long p,q,x;
    cin>>p>>q;
    long long a=min(p,q);
    long long b=max(p,q);
    if(b%a==0)
        cout<<b<<endl;
    else
    {
        for(long long i=1; ;i++)
            {

            x=b*i;

           if(x%a==0)
           {
               
               cout<<x<<endl;
               return 0;
           }
            }
    }


    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    string A; cin >> A;
    int N = A.size();

    int alf[26];
    fill(alf, alf + 26, 0);
    REP(i, N) alf[(int)(A[i] - 'a')]++;

    int ans = N * (N - 1) / 2 + 1;
    REP(i, 26) ans -= alf[i] * (alf[i] - 1) / 2;

    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 640