akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;main(){int p,c,w,s,l,i,x,y,z;for(string t,B,S,L[500];cin>>p>>c>>w>>s,p;puts("?")){B=S="";for(l=x=y=z=i=0;i++<w;)B+=".";for(;y++<s;)S+=".";for(getline(cin,t);getline(cin,t),t!="?";){if(t=="")t=".";for(;t.size()%w!=0;)t+=".";for(i=0;i+w<=t.size();i+=w)L[l++]=t.substr(i,w);}for(;l%(p*c);)L[l++]=B;for(;p*c*z<l;){t="";for(y=0;y<c;t+=(y++?S:"")+(i<=l?L[i]:B))i=x+y*p+z*p*c;cout<<t<<"\n";if(++x>=p){x=0;z++;puts("#");}}}}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int n;
  cin>>n;
  int x = 0, y = 0, t = 0;
  bool ok = true;
  REP(i,n) {
    int nx, ny, nt;
    cin>>nt>>nx>>ny;
    int diff = abs(x-nx) + abs(y-ny);
    if (diff > nt-t || ((nt-t) - diff) % 2 != 0) {
      ok = false;
    }
    x = nx;
    y = ny;
    t = nt;
  }
  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

void main()
{
    auto S = sread();
    auto T = "CODEFESTIVAL2016";
    zip(S, T).map!(t => t[0] != t[1]).sum().writeln();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string Coms[]={"dream","dreamer","erase","eraser"};
int main()
{
    string now;
    cin>>now;
    int len=now.length();
    now+="000000";
    int pos=0;
    int flag=-1;
    while(pos<len)
    {
        //printf("pos=%d\n",pos);
        if(now[pos]=='a'){
            if(flag==1 && now.substr(pos,4)=="aser")
            {
                flag=3;pos=pos+4;
            }else if(flag==1 && now.substr(pos,3)=="ase"){
                flag=2;pos=pos+3;
            }else{printf("NO\n");exit(0);}
        }else if(now[pos]=='d'){
            if(now.substr(pos,5)!="dream") {printf("NO\n");exit(0);}
            else{
                if(now[pos+5]=='e' && now[pos+6]=='r'){
                    pos=pos+7;
                    flag=1;
                }else{
                    pos=pos+5;
                    flag=0;
                }
            }
        }else if(now[pos]=='e'){
            if(now.substr(pos,5)!="erase") {printf("NO\n");exit(0);}
            else{
                if(now[pos+4]=='e' && now[pos+5]=='r'){
                    pos=pos+6;
                    flag=3;
                }else if(now[pos+4]=='e'){
                    pos=pos+5;
                    flag=2;
                }else{
                    //printf("pos=%d\n",pos);
                    printf("NO\n");exit(0);
                }
            }
        }else{
            printf("NO\n");exit(0);
        }
    }
    printf("YES\n");
    return 0;
}


Measured memory_bytes: 512
S = input()
goukei = 0

for i in range(1 << len(S) - 1):
    f = ""
    for j in range(len(S) - 1):
        f += S[j]
        if (i >> j) & 1:
            f += '+'
    goukei += eval(f + S[-1])

print(goukei)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<functional>
using namespace std;
#define int long long
#define double long double
const long long mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int> P;
struct edge { int to,cost; };
int a[2005];
int use[2005];
vector<P>v; 
vector<int>V;
void disp() {
	rep(i, V.size()) {
		if (i)cout << ' ';
		cout << V[i];

	}
	cout << endl;
}
signed main(){
	int n, k, q; cin >> n >> k >> q;
	rep(i, n)cin >> a[i];
	rep(i, n)v.push_back(P(a[i], i));
	sort(v.begin(), v.end());
	int ans = 1145141919810931;
	use[n] = 1;
	rep(i, n) {//minimum==a[i]
		int mn = v[i].first;
		rep(j, n) {
			if (a[j] < mn)use[j]++;
		}
		int s = 0, t = 0;
		vector<int>VA;
		rep(j, n+1) {
			if (!use[j])t=j;
			else {
			for (int l = s; l <= t; l++) {
			VA.push_back(a[l]);
				}
			
			s = j+1; t = j;
			sort(VA.begin(), VA.end());
			rep(l,(int)VA.size()-k+1)V.push_back(VA[l]);
			VA.clear();
			}
		}

		sort(V.begin(), V.end());
	//	disp();
		if (V.size() < q)break;
		ans = min(ans, V[q - 1] - V[0]);
		//cout << ans << endl;
		V.clear();
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#
from math import ceil,floor
n = int(input())
a_upper = ceil(n/1.08)
a_lower = floor(n/1.08)

if a_upper == a_lower:
    print(a_upper)
else:
    if floor(a_upper*1.08) == n:
        print(a_upper)
    elif floor(a_lower*1.08) == n:
        print(a_lower)
    else:
        print(":(")

Measured memory_bytes: 38384
from heapq import *

n = int(input())
v = list(map(int, input().split()))

h = []
for i in range(n):
    heappush(h, v[i])

for i in range(n-1):
    x, y = heappop(h), heappop(h)
    heappush(h, (x + y) / 2)

print(h[0])

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

int main(){
  int x,y;
  cin >> x  >>y;
  for(int c = 0; c <=x; c++){
   int t = x-c;
    int asi = 2*c + 4*t;
    if(asi == y){
     cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

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

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    LL a, b, c, d;
    cin >> a >> b >> c >> d;

    LL res = -4e18;
    if (a <= 0 && 0 <= b) res = 0;
    if (c <= 0 && 0 <= d) res = 0;

    res = max({res, a * c, a * d, b * c, b * d});
    cout << res << endl;
}

Measured memory_bytes: 3648
//  Created by Sengxian on 2017/6/3.
//  Copyright (c) 2017年 Sengxian. All rights reserved.
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
inline int readInt() {
	int n = 0, ch = getchar();
	while (!isdigit(ch)) ch = getchar();
	while (isdigit(ch)) n = n * 10 + ch - '0', ch = getchar();
	return n;
}

const int MAX_N = 200000 + 3;
int n, K, a[MAX_N];
ll s[MAX_N];

namespace Treap {
	const int MAX_NODE = MAX_N;
	
	struct Node {
		ll key;
		int val, s;
		Node *ls, *rs;
		
		inline void maintain() {
			s = ls->s + rs->s + 1;
		}
	} pool[MAX_NODE], *pit, *null;

	void init() {
		pit = pool;
		null = new Node();
		null->s = 0;
	}

	inline Node *newNode(ll v) {
		pit->key = v, pit->val = rand();
		pit->s = 1, pit->ls = pit->rs = null;
		return pit++;
	}

	Node *merge(Node *a, Node *b) {
		if (a == null) return b;
		if (b == null) return a;
		if (a->val < b->val) {
			a->rs = merge(a->rs, b);
			a->maintain();
			return a;
		} else {
			b->ls = merge(a, b->ls);
			b->maintain();
			return b;
		}
	}
	
	typedef pair<Node *, Node *> Droot;
	Droot split(Node *o, int k) {
		Droot d(null, null);
		if (o == null) return d;
		int s = o->ls->s;
		if (k <= s) {
			d = split(o->ls, k);
			o->ls = d.second;
			o->maintain();
			d.second = o;
		} else {
			d = split(o->rs, k - s - 1);
			o->rs = d.first;
			o->maintain();
			d.first = o;
		}
		return d;
	}

	int lowerCount(const Node *o, ll v) { // 找到最后一个小于 v 的数的排名
		if (o == null) return 0;
		return v <= o->key ? lowerCount(o->ls, v) : lowerCount(o->rs, v) + o->ls->s + 1;
	}

	int upperCount(const Node *o, ll v) { // 找到最后一个小于等于 v 的数的排名
		if (o == null) return 0;
		return v < o->key ? upperCount(o->ls, v) : upperCount(o->rs, v) + o->ls->s + 1;
	}

	inline void insert(Node *&root, ll v) {
		int x = lowerCount(root, v);
		Droot l = split(root, x);
		root = merge(merge(l.first, newNode(v)), l.second);
	}
}

using namespace Treap;


int main() {
	n = readInt(), K = readInt();
	for (int i = 0; i < n; ++i) s[i + 1] = s[i] + (a[i] = readInt());
	
	init();
	Node *root = null;
	insert(root, s[0]);
	
	ll cnt = 0;
	for (int i = 1; i <= n; ++i) {
		cnt += upperCount(root, s[i] - (ll)K * i);
		insert(root, s[i] - (ll)K * i);
	}
	
	printf("%lld\n", cnt);
	
	return 0;
}


Measured memory_bytes: 8832
import java.util.*;

public class Main {
	public Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new aoj2508().doIt();
	}
	class aoj2508{
		char change(int num,char c){
			String alf = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
			char alf2[] = alf.toCharArray();
			for(int i = 0;i < 52;i++){
				if(alf2[i] == c){
					if(i - num < 0)c = alf2[i - num + 52];
					else c = alf2[i - num];
					break;
				}
			}
			return c;
		}
		void doIt(){
			while(true){
				int n = sc.nextInt();
				if(n == 0)break;
				int a[] = new int [n];
				for(int i = 0;i < n;i++){
					a[i] = sc.nextInt();
				}
				String str = sc.next();
				char ctr[] = str.toCharArray();
				for(int i = 0;i < ctr.length;i++){
					System.out.print(change(a[i % n],ctr[i]));
				}
				System.out.println();
			}
		}
	}
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
string s;
  cin >> s;
  int cnt = 0;

  for (int i = 1; i < s.length(); ++i) {
    if (s[i] != s[i - 1]) cnt++;
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
// now

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0) : d(n,-1){}
    int Find (int x){//根の番号を探す
        if(d[x] < 0) return x;
        return d[x] = Find(d[x]);
    }
    bool unite (int x, int y){
        x = Find(x); y = Find(y);
        if(x == y ) return false;
        if(d[x] < d[y]){
            swap(x,y);
        }
        d[x] += d[y];
        d[y] = x;
        return true;
    } 

    bool same(int x, int y){
        return Find(x) == Find(y);
    }
    int size(int x) {
        return (-d[Find(x)]);
    }
};


ll nCr (ll n, ll r){
    ll ans = 1;
    for(ll i = n ; i > n-r ; i --){
        ans *= i;
    }
    for(ll i = 1 ; i<= r; i ++){
        ans /= i;
    }
    return ans ;
}

int nPr (int n,int r){
    int ans = 1;
    for(int i = n ; i > n-r ; i --){
        ans *= i;
    }
    return ans ;
}
 ll modd = 1e9+ 7;
ll wa (ll n,ll mi, ll ma){
    ll ans  = n * (mi+ma) /2;
    return ans;
}
ll kw(ll k,ll n){
    
    ll ans  =0;
    ll mi,ma;
    mi= wa(k,0,k-1);
    
    ma = wa(k,n-k+1,n);
    
    return (ma-mi +1)%modd;
}

int main(){
    double l;
    cin >> l;

    double s = l/3;
    double ans = s;

    ans *= s;
    ans *= s;

    printf("%.8f\n",ans);
}





Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct {
	int id, solved, penalty;
} Team;

int compare(const void *a, const void *b) {
	int t;
	const Team ta = *(Team *)a, tb = *(Team *)b;

	t = tb.solved - ta.solved;
	if (t)
		return t;
	else {
		t = ta.penalty - tb.penalty;
		if (t)
			return t;
		else
			return ta.id - tb.id;
	}
}

int main(void) {
	int i;
	int t, p, r;

	while (scanf("%d %d %d", &t, &p, &r), t) {
		Team team[50] = {0};
		int wrong[50][10] = {0};

		for (i = 0; i < t; i++)
			team[i].id = i + 1;

		for (i = 0; i < r; i++) {
			int tid, pid, t;
			char mes[10];

			scanf("%d %d %d %s", &tid, &pid, &t, mes);
			tid--;
			pid--;

			if (mes[0] == 'C') {
				team[tid].solved++;
				team[tid].penalty += wrong[tid][pid] * 1200 + t;
			} else
				wrong[tid][pid]++;
		}

		qsort(team, t, sizeof(Team), &compare);

		for (i = 0; i < t; i++)
			printf("%d %d %d\n", team[i].id, team[i].solved, team[i].penalty);
	}

	return 0;
}

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

using namespace std;

const int N = 123456;

int n, a[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  sort(a + 1, a + 1 + n);
  int l = 1, r = n + 1;
  auto check = [&] (int x) {
    long long value = a[x];
    for (int i = 1; i <= n; ++i) {
      if (i != x) {
        if (a[i] > value * 2) {
          return false;
        }
        value += a[i];
      }
    }
    return true;
  };
  while (l != r) {
    int mid = l + r >> 1;
    if (check(mid)) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << n - l + 1 << '\n';
  return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <set>
#include <string>

using namespace std;

const int N = 5'009;

char s[N];

int main() {
  int k;
  scanf("%s %d", s, &k);
  int n = (int)strlen(s);
  set<string> ss;
  for (int len = 1; len <= k; ++len) {
    for (int i = 0; i + len - 1 < n; ++i) {
      string t = "";
      for (int j = 0; j < len; ++j) {
        t += s[i + j];
      }
      ss.insert(t);
    }
  }
  for (string e : ss) {
    --k;
    if (k == 0) {
      puts(e.c_str());
    }
  }
}


Measured memory_bytes: 1664
#python3
from collections import defaultdict

def f(x):
    return (str(x)[0], str(x)[-1]) 

def main():

    n = int(input())
    freq = defaultdict(int)

    for i in range(1, n+1):
        p = f(i)
        freq[p]+=1


    ans = 0
    for i in range(1, n + 1):
        p = f(i)
        q = (p[1], p[0])
        ans += freq[q]

    print(ans)

main()

Measured memory_bytes: 3316
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n), b(n), c(n);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for(int i = 0; i < n; i++) {
    cin >> b[i];
  }
  for(int i = 0; i < n; i++) {
    cin >> c[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  vector<int> sum(n + 5, 0);

  for(int i = 0; i < n; i++) {
    sum[1 + distance(b.begin(), upper_bound(b.begin(), b.end(), a[i]))]++;
  }
  for(int i = 0; i < n; i++) {
    sum[i + 1] += sum[i];
  }
  ll ans = 0;
  for(int i = 0; i < n; i++) {
    ans += (n - distance(c.begin(), upper_bound(c.begin(), c.end(), b[i]))) * sum[i + 1];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5876
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

multiset<int> st;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;

    cin>>n;

    for(int i=1;i<=n;i++)
        cin>>A[i];

    set<int>::iterator it;

    for(int i=n;i>=1;i--){
        it = st.lower_bound(A[i]+1);
        if(it==st.end()){
            cnt++;
            st.insert(A[i]);
        }
        else {
            st.erase(it);
            st.insert(A[i]);
        }
    }

    cout<<cnt<<"\n";


    return 0;
}


Measured memory_bytes: 5376
while True:
    try:
        i = 0
        a = list(map(int,input().split()))
        for x in range(10):
            for y in range(10):
                for z in range(10):
                    for s in range(10):
                        if a[0]==(x+y+z+s):
                            i = i+1
                        else:
                            pass
        print(i)
    except EOFError:
        break


Measured memory_bytes: 5596
#include <stdio.h>

int main(void){
	int matrix[11][11];
	int sum;
	int i,j,n;
	while(1){
		scanf("%d",&n);
		if(n == 0){break;}
		for(i = 0; i < n; i++){
			sum = 0;
			for(j = 0; j < n; j++){
				scanf("%d",&matrix[i][j]);
				sum += matrix[i][j];
				printf("%5d",matrix[i][j]);
			}
			matrix[i][n] = sum;
			printf("%5d\n",sum);
		}
		for(j = 0; j < n; j++){
			sum = 0;
			for(i = 0; i < n; i++){
				sum += matrix[i][j];
			}
			matrix[n][j] = sum;
			printf("%5d",matrix[i][j]);
		}
		sum = 0;
		for(i = 0; i < n; i++){
			sum += matrix[i][n];
		}
		matrix[n][n] = sum;
		printf("%5d\n",matrix[n][n]);
	}
	return 0;
}

Measured memory_bytes: 0
n=int(input())
s=input()

if n%2==1:
    print('No')

else:
    count=0
    for i in range(0,int(n/2)):
        if s[i]==s[i+int(n/2)]:
            count=count+1
    if count==int(n/2):
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 3060
#include <stdio.h>
int main(){
    int a,b,count=0,i,sum;
    scanf("%d %d",&a,&b);
    sum=a+b;
    char s[15];
    scanf("%s",s);
    for(i=0;i<=sum;i++){
        if(i==a) continue;
        else if(!(s[i]>='0' && s[i]<='9')|| s[a]!='-'){
            count++;
            break;
        }
    }
    if(count==0) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 128
def cum2D(a, H, W):
    cum = [[0]*(W+1) for _ in range(H+1)]
    for i in range(H):
        for j in range(W):
            cum[i+1][j+1] = cum[i][j+1] + cum[i+1][j] - cum[i][j] + a[i+1][j+1]
    return cum
    
n, m, q = map(int, input().split())
trains = [tuple(map(int, input().split())) for _ in range(m)]  #;print(trains)
a = [[0]*(n+1) for j in range(n+1)]
for k in range(m):
    start, stop = trains[k]
    a[start][stop] += 1
cum = cum2D(a, n, n)          #;print2D(a, n+1) ;print() ;print2D(cum, n+1)

for _ in range(q):
    p, q = map(int, input().split())
    print(cum[n][q] - cum[p-1][q])
   

Measured memory_bytes: 40972
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 100000;

int main(){
    
    int ans=0;
    int n;
    string s;
    cin >> n;
    cin >> s;
    rep(i,n-1){
        if(s[i]!=s[i+1])ans++;
    }
    ans++;
    cout << ans<<endl;
    
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

using Graph = vector<vector<int>>;

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_MAX	2,147,483,647 = 2*1.0e9

vector<bool> seen;

void dfs(Graph& _g, int _v){
  seen[_v] = true;

  for(auto i : _g[_v]){
    if(seen[i]) continue;
    else dfs(_g, i);
  }
}


int main(){
  int N, M;
  cin >> N >> M;

  Graph g(N);
  for(int i = 0 ; i < M; i++){
    int x, y, z; cin >> x >> y >> z;
    x--; y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }

  seen.assign(N, false);

  int ans = 0;
  for(int i = 0; i < N; i++){
    if(seen[i]) continue;
    dfs(g, i);
    ans++;
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 10368
import Control.Applicative
import Text.Printf
import Debug.Trace

gcd_n :: [Integer]->Integer
gcd_n l = foldl gcd 0 l 

divisors :: Integer -> [Integer]
divisors n = let smalls = [x |x<-[1..(min n 100000)], x*x<=n && mod n x == 0] in
                            if n==(last smalls)^2 then smalls ++ [div n x| x<-tail $ reverse smalls]
                            else smalls ++ [div n x| x<-reverse smalls]

solve :: [Integer]->[Integer]
solve a = divisors $ gcd_n a

listToStrings :: [Integer]->String
listToStrings [] = ""
listToStrings (x:xs) = ((show x)++"\n")++(listToStrings xs)

main :: IO ()
main = do
  n <- getLine
  nums <- fmap (read :: String -> Integer) . words <$> getLine
  putStr $ listToStrings $ solve nums



Measured memory_bytes: 4112
#include<bits/stdc++.h>
#define ll long long int
#define ff first
#define ss second
#define eps 1e-9

using namespace std;

int main()
{

    ll t,n,m,f,a,b,c,l,r,q,k,x,y,z,ans,mn,mx,sum=0;
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    string exp;
    cin>>exp;
    
    for(int i=0;i<exp.size();i++)
    {
        sum += exp[i]-'0';
    }
    
    if(sum%9)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }


}




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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n' //toggle off for interactive problems
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define int long long
// #define pow mypow

typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9+5;
const int MOD = 1e9+7;

int x, k, d;
int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> x >> k >> d;
	if (x < 0) x = -x;
	int newk = k - x / d;
	int ans;
	if (newk == 0) ans = x % d;
	else if (newk < 0) ans = x - k*d;
	else {
		if (newk&1) ans = d - x%d;
		else ans = x%d;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3528
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll base = 998244353;

int main() {
	int n, s; cin >> n >> s;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];

	vector<ll> dp(s+1);
	ll total = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = s; j >= a[i]; --j) {
			if (j == a[i]) dp[j] = (dp[j] + i+1) % base;
			else dp[j] = (dp[j] + dp[j-a[i]]) % base;
		}
		total = (total + dp[s] * (n-i) % base) % base;
		dp[s] = 0;
	}

	cout << total << endl;
}


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

using namespace std;
using ll = long long;

void max_self(ll& a, ll b) {
    a = max(a, b);
}

signed main() {
    int n;
    scanf("%d", &n);
    int base = 1;
    while (base <= n) {
        base *= 2;
    }
    // base is the smallest power of 2 that is not smaller than n
    vector<ll> tree(2 * base);
    vector<int> h(n), a(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &h[i]);
    }
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    vector<ll> dp(n + 1);
    // dp[i] - the max total beauty so far if the last taken flower has height i
    for (int flower = 0; flower < n; flower++) {
        // max dp[i] for i in [0, h[flower]-1]
        int x = h[flower] + base;
        ll best = 0;
        while (x > 1) {
            if(x % 2 == 1) {
                max_self(best, tree[x-1]);
            }
            x /= 2;
        }
        dp[h[flower]] = best + a[flower];
        for (int i = base + h[flower]; i >= 1; i /= 2) {
            max_self(tree[i], dp[h[flower]]);
        }
    }
    ll answer = 0;
    for (int i = 0; i <= n; i++) {
        max_self(answer, dp[i]);
    }
    printf("%lld\n", answer);
    return false;
}

Measured memory_bytes: 7424
# -*- coding: utf-8 -*-
from heapq import heappop, heappush, heapify
import sys
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))

N, M = inpl()
A = inpl()
Q = [[-A[i], A[i], 0] for i in range(N)]
F = 2
heapify(Q)

for _ in range(M):
    b, a, x = heappop(Q)
    if b:
        b = a//(2**(x+1))
    heappush(Q, [-b, a, x+1])

ans = 0
for i in range(N):
    ans -= Q[i][0]

print(ans)

Measured memory_bytes: 92696
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5])    cout << "Yes\n";
    else    cout << "No\n";
}

Measured memory_bytes: 256
S = input()
T = input()
lens = len(S)
lent = len(T)

ans = -1
for i in range(lens-lent+1):
    S2 = S[i:i+lent]
    diff = 0
    for j in range(lent):
        if S2[j] != T[j]:
            diff += 1
    if ans == -1:
        ans = diff
    else:
        if ans > diff:
            ans = diff
print(ans)

Measured memory_bytes: 8976
#include<iostream>
#include<algorithm>
using namespace std;
struct bisai{
	int begin;
	int end;
};
bisai a[1000005];
struct rule1{
	bool operator()(const bisai &s1,const bisai &s2){
		return s1.end<s2.end;
	}
};
int main(){
	int n,i,t=-2147483647,count=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i].begin>>a[i].end;
		a[i].begin-=a[i].end;
		a[i].end=a[i].begin+(a[i].end<<1);
	}
	sort(a,a+n,rule1());
	for(i=0;i<n;i++){
		//printf("a[%d].bigin=%d,end=%d\n",i,a[i].begin,a[i].end);
		if(a[i].begin>=t){
			//cout<<a[i].end<<endl;
			//cout<<"t="<<t<<endl;
			count++;
			t=a[i].end;
		}
	}
	cout<<count;
} 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const ll inf = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+5;
//int a[N];

int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    ll k;
    string s;

    cin >> s >> k;

    for (int i = 0; i < s.size(); i++) {

        if (i+1 == k || s[i] != '1') {

            cout << s[i];
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

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

#define MP make_pair
#define MT make_tuple
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

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

	int N, A;
	cin >> N >> A;

	vector<LL> X(N);
	REP(i, N) cin >> X[i];

	vector<vector<LL>> dp(51, vector<LL>(51 * 51, 0));
	dp[0][0] = 1;

	REP(i, N){
		map<pair<LL, LL>, LL> done;
		FOR(j, 1, i + 2){
			REP(k, 50 * 50){
				done[MP(j, k + X[i])] = dp[j - 1][k];
			}
		}
		EACH(d, done) dp[d.first.first][d.first.second] += d.second;
	}

#if 0
	REP(j, 40) cout << j << '\t';
	cout << endl;
	REP(i, 10){
		REP(j, 40){
			cout << dp[i][j] << '\t';
		}
		cout << endl;
	}
#endif

	LL ret = 0;
	REP(i, N){
		ret += dp[i + 1][(i + 1) * A];
	}

	cout << ret << endl;

	return 0;
}


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

string S;

int main() {
    cin >> S;

    bool ans = true;
    if (S.length() % 2 == 1) ans = false;
    else {
        for (int i = 0; i < S.length(); i++) {
            if (i % 2 == 0 && S[i] != 'h') {
                ans = false;
            }
            else if (i % 2 == 1 && S[i] != 'i') {
                ans = false;
            }
        }  
    }

    cout << (ans ? "Yes" : "No") << endl;
   

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

ll gcd(ll a, ll b){ return b==0?a:gcd(b,a%b);}

ll add(ll a, ll b, ll m = MOD){ return (a%m + b%m+2*m)%m;}

ll mul(ll a, ll b, ll m = MOD){ return ((a%m+m)*(b%m+m))%m;}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 300+5;

int n;
bool vis[N][N][N];
long double memo[N][N][N];

long double DP(int unos, int dos, int tres){
	int total = unos + dos + tres;
	if(total == 0) return 0.0L;
	if(vis[unos][dos][tres]) return memo[unos][dos][tres];
	long double ans = 1.0*n/total;
	if(unos > 0){
		ans += unos*DP(unos-1,dos,tres)/total;
	}
	if(dos > 0){
		ans += dos*DP(unos+1,dos-1,tres)/total;
	}
	if(tres > 0){
		ans += tres*DP(unos,dos+1,tres-1)/total;
	}
	vis[unos][dos][tres] = true;
	return memo[unos][dos][tres] = ans;
}

int main(){
	ri(n);
	int x;
	int unos = 0, dos = 0, tres = 0;
	for(int i=0; i<n; i++){
		ri(x);
		if(x == 1) unos++;
		else if(x == 2) dos++;
		else tres++;
	}
	cout << setprecision(10) << fixed << DP(unos,dos,tres) << endl;
	return 0;
}


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

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 998244353

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast;
    vi a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(all(a));
    cout << a[0] + a[1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define int long long
#define pb push_back
#define fi first
#define se second
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define sz(x) (int)x.size()
const int mod = 1e9 + 7;
const int mod1 = 998244353;
typedef long double f80;

#ifndef LOCAL
#pragma GCC optimize ("O2")
#define endl '\n'
#endif

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}

ll pwr(ll a,ll b, ll mod){
    a %= mod;
    int ans = 1;
    while(b){
        if(b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

vector<vector<int>> z;
void add(int u,int v, int val){
	z.pb({u, v, val});
}
void solve(){
	int l;
	cin >> l;
	int c = (1 << 17);
	fr(i, 2, 19){
		add(i, i + 1, c);
		add(i, i + 1, 0);
		c >>= 1;
	}
	int cur = 0;
	if(l & (1 << 19)){
		add(1, 2, 0);
		add(1, 2, (1 << 18));
		if(l & (1 << 18)){
			add(1, 2, (1 << 19));
			cur = (1 << 19) ^ (1 << 18);
		}
		else{
			cur = (1 << 19);
		}
	}
	else if(l & (1 << 18)){
		cur = (1 << 18);
		add(1, 2, 0);
	}
	for(int i = 17; i >= 0; i--){
		if((l >> i) & 1){
			int node = 20 - i;
			add(1, node, cur);
			cur += (1 << i);
		}
	}
	cout << 20 << " " << sz(z) << endl;
	for(auto e : z){
		cout << e[0] << " " << e[1] << " " << e[2] << endl;
	}
}
signed main(){
    IO;
    #ifdef LOCAL
        freopen("inp.txt","r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    cout << setprecision(10) << fixed;
    int t = 1;
    // cin >> t;
    fr(tt, 1, t){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
import itertools,sys
def f(s):
 for a,b,c,d in itertools.permutations(s):
  for x,y,z in itertools.product('+-*',repeat=3):
   yield f"({a} {x} {b}) {y} ({c} {z} {d})"
   yield f"(({a} {x} {b}) {y} {c}) {z} {d}"
   yield f"{a} {x} ({b} {y} ({c} {z} {d}))"
   yield f"({a} {x} ({b} {y} {c})) {z} {d}"
   yield f"{a} {x} (({b} {y} {c}) {z} {d})"
for e in sys.stdin:
 s=list(map(int,e.split()));a=0
 if sum(s)==0:break
 for m in f(s):
  if eval(m)==10:a='('+m+')';break
 print(a)


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

// #define fi first
// #define se second
#define rep(i, n) for (ll i=0;i<(n); i++)
#define ALL(v) (v).begin(), (v).end()
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;

const ll M=1000000007ll;
const ll MOD=1000000007ll;
const ll MAX=100000001ll;
//const ll M = 1000000000+7;

ll cnt = 0; 

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint f(ll n){
  if(n==0) return 1;
  mint ans = f(n/2);
  ans *= ans;
  if(n%2==1) ans*= 2;
  return ans;
}

mint choose(ll n, ll k){
  mint x=1, y=1;
  rep(i,k){
    x *= (n-i);
    y *= (i+1);
  }
  return x / y;
}

struct BIT {
  private:
   vector<ll> bit;
   ll N;
 
  public:
   BIT(ll size) {
     N = size;
     bit.resize(N + 1);
   }
 
   // 一点更新です
   void add(ll a, ll w) {
     for (ll x = a; x <= N; x += x & -x) bit[x] += w;
   }
 
   // 1~Nまでの和を求める。
   int sum(ll a) {
     ll ret = 0;
     for (ll x = a; x > 0; x -= x & -x) ret += bit[x];
     return ret;
   }
 };
 

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

  vector<ll> v(n);
  rep(i, n){
    cin>>v[i];
  }
  ll tmp = v[0];
  ll cnt=1;
  
  rep(i, 1000000){
    if(tmp==2) break;
    tmp = v[tmp-1];
    cnt++;
  }
  if(tmp==2) cout << cnt<<endl;
  else cout << -1<<endl;
}


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

int main(void) {
    int K, X;
    cin >> K >> X;

    for (int i = X - K + 1; i <= X + K - 1; i++) {
        cout << i;
        if (i != X - K - 1) {
            cout << " ";
        } else {
            cout << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
# F

N, A, B, C = list(map(int, input().split()))
d = {'A': A, 'B': B, 'C': C}
res = []
SN = [input() for i in range(N)]
for i in range(N):
    s = SN[i]
    s0 = s[0]
    s1 = s[1]
    
    if d[s0] == d[s1] == 0:
        print('No')
        exit()
    elif d[s0] == 0:
        d[s0] += 1
        d[s1] -= 1
        res.append(s0)
    elif d[s1] == 0:
        d[s0] -= 1
        d[s1] += 1
        res.append(s1)
    elif i == N-1:
        res.append(s0)
    elif s0 in SN[i+1]:
        d[s0] += 1
        d[s1] -= 1
        res.append(s0)
    else:
        d[s0] -= 1
        d[s1] += 1
        res.append(s1)
        
print('Yes')
for r in res:
    print(r)

Measured memory_bytes: 16900
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
/*
vector<char>al(26);
al = {'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'};
vector<char>AL(26);
AL = {'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'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	string S;
	cin >> S;
	int Z = S.size();
	int cnt = 0;
	if (Z % 2 == 0) {
		for (int i = 0; i <= Z / 2 - 1; i++) {
			if (S[i] != S[Z - i - 1]) {
				cnt++;
			}
		}
	}
	else {
		for (int i = 0; i <= Z / 2 - 1; i++) {
			if (S[i] != S[Z - i - 1]) {
				cnt++;
			}
		}
	}
	cout << cnt << endl;
}




Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
    int N;
    cin >> N;
    
    for(int i = 1; i <= 10; i++){
        N -= 1000;
        if(N <= 0){
            cout << -N << endl;
            break;
        }
    }

    
}


Measured memory_bytes: 3152
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
/*#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX*/

using namespace std;

using ll = long long;

#define mp make_pair

const int p = 1e9 + 7;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/


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

    int A, B, M;
    cin>>A>>B>>M;
    vector<int> a(A), b(B);
    for (int i = 0; i<A; i++) cin>>a[i];
    for (int i = 0; i<B; i++) cin>>b[i];
    int best = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());

    int x, y, c;
    for (int i = 0; i<M; i++)
    {
        cin>>x>>y>>c;
        best = min(best, a[x-1] + b[y-1] - c);
    }
    cout<<best;


}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>


using namespace std;
string yn(bool a)
{
  if (a){return "Yes";}
  else{return "No";}
}

int main()
{
  ios::sync_with_stdio(false);
  string s;
  int x,y;
  cin>>s>>x>>y;
  vector<int> a,b;
  bool f=1;
  int tmp=0;
  int suma=0,sumb=0;
  for(auto itr=s.begin();itr !=s.end();itr++)
  {
    if(*itr=='F'){tmp++;}
    else {
      if(f){a.push_back(tmp);suma+=tmp;}
      else{b.push_back(tmp);sumb+=tmp;}
      f=!f;
    tmp=0;
  }

  }
  if(f){a.push_back(tmp);suma+=tmp;}
  else{b.push_back(tmp);sumb+=tmp;}
  x-=a[0];
  suma-=a[0];
  x=abs(x);
  y=abs(y);
  a.erase(a.begin());
  int flag=0;
  if((suma-x)%2 or (sumb-y)%2 or suma<x or sumb<y){flag=0;}
  else
  {
    x=(suma-x)/2;
    y=(sumb-y)/2;
    vector<int> dpx(8001),dpy(8001);
    dpx[0]=1;dpx[suma]=1;
    dpy[0]=1;dpy[sumb]=1;
    for(auto itr1=a.begin();itr1 !=a.end();itr1++)
    {
      for(int i=x-*itr1;i>-1;i--)
      {
        if(dpx[i]==1){dpx[i+*itr1]=1;}
      }
      if(dpx[x]!=0){flag+=1;break;}

    }
    if(a.size()==0 and x==0){flag+=1;}
    for(auto itr2=b.begin();itr2 !=b.end();itr2++)
    {
      for(int i=y-*itr2;i>-1;i--)
      {
        if(dpy[i]==1){dpy[i+*itr2]=1;}
      }
      if(dpy[y]!=0){flag+=1;break;}
    }
    if(b.size()==0 and y==0){flag+=1;}
  }
  cout<<yn(flag>=2)<<endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) (a)=max(a, b)
#define chmin(a, b) (a)=min(a, b)
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/


 
int main(void) {
  ll i, j, k;
  
  ll N;
  cin >> N;
  
  map<string, ll> mp;
  for(i=0; i<N; i++) {
    string s;
    cin >> s;
    mp[s]++;
  }
  
  pt(mp.size());
  
  
}
 
 


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

int main()
{
	int n;
	
	cin >> n;
	long *R = new long[n];

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

	signed long maxv = -1000000000;
	long minv = R[0];
	for (int i = 1; i < n; i++)
	{
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}

	cout << maxv << endl;
	return 0;
}


Measured memory_bytes: 4656
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void){

  string s;
  while( getline( cin , s ) ){

    for( int i = 0 ; i < s.size() ; i++ ){
      if( i > s.size() - 5 )break;
      if( s.substr( i , 5 ) == "apple" ){//　substrはstring s の　i番目から5文字の文字列を返す関数
	s.replace( i , 5 , "peach" );//replaceはstring s の i番目から5文字を置換する関数
      }
      else if( s.substr( i , 5 ) == "peach" ){
	s.replace( i , 5 , "apple" );
      }

    }
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 1188
import java.util.Scanner;

public class Main{
public static void main(String[] args){
    try (Scanner sc = new Scanner(System.in)){
        while(true){
        double average = 0, variance = 0,total = 0,total2 = 0;
            int n = sc.nextInt();
            if(n == 0) {
                break;
            }
            int[] scores = new int[n];
            for(int i =0;i < scores.length;i++){
                scores[i] = sc.nextInt();
            }
            for(int j = 0; j < scores.length;j++) {
                total += scores[j];
                average = total / scores.length;
            }
            for(int k = 0; k < scores.length;k++) {
                total2 += (scores[k] - average) * (scores[k] - average);
                variance = total2 / scores.length;
            }
            System.out.println(Math.sqrt(variance));
        }
    }
}
}



Measured memory_bytes: 31316
#include <iostream>
#include <algorithm>

#define MAXN 100

using namespace std;

int A[MAXN+1],B[MAXN+1];

int main()
{
  int N,M,X;

  cin >> N >> M >> X;

  while(M--) {
    int tmp;
    scanf("%d", &tmp);
    A[tmp] = 1;
  }

  for ( int i = 1; i <= MAXN; ++i ) B[i] = B[i-1]+A[i];

  int tmp = B[MAXN]-B[X];
  int tmp2 = B[X]-A[X];

  cout << min ( tmp,tmp2) << "\n";
}


Measured memory_bytes: 256