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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define oset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

#define ll long long

#ifdef sarthak
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#else
#define trace(...)
#endif

#ifndef sarthak
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

#define foreach(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fort(i,v) for(auto i:v)
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fill(ar,val) rep(i,sizeof(ar)/sizeof(ll)) ar[i]=val
#define fill2(ar,val) rep(i,sizeof(ar)/sizeof(ar[0])) rep(j,sizeof(ar[0])/sizeof(ll)) ar[i][j]=val
#define fill0(ar) memset(ar,0,sizeof(ar))
#define debug(x) cout<<#x<<": "<<x<<endl

#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define sd2(x,y) scanf("%d %d",&x,&y)
#define slld2(x,y) scanf("%lld %lld",&x,&y)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pd2(x,y) printf("%d %d\n",x,y)
#define plld2(x,y) printf("%lld %lld\n",x,y)
#define all(ar) ar.begin(), ar.end()
#define endl '\n'
#define sz(x) (int)x.size()
#define len(x) (int)x.length()

typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ii> vii;
typedef vector<ll> vi;

#define INF 1000000000000000000
#define PI 3.14159265358979323846L

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rngb(chrono::steady_clock::now().time_since_epoch().count()); // can give negative values too

void solve()
{
    ll h,w;
    cin >> h >> w;

    if(h==1 || w==1)
    {
        cout << 1 << endl;
        return;
    }
    
    ll ans = h*w;
    ll xx = ans/2;
    if(ans%2==1)
        xx++;

    cout << xx << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed;
    cout << setprecision(10);
    #ifdef sarthak
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ll t = 1;
    // cin >> t;
    while(t--)
    {
        solve();
    }

    #ifdef sarthak
    cerr << "Time elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
    #endif
}


Measured memory_bytes: 256
def get_value(s):
    return int(s[1])

def get_suit(s):
    return s[0]

def bubble_sort(A):
    a = list(A)
    for i in range(0, len(a)):
        
        
        for j in range(len(a)-1, i, -1):
            if get_value(a[j-1]) > get_value(a[j]):
                a[j-1], a[j] = a[j], a[j-1]
    return a

def selection_sort(A):
    a = list(A)
    for i in range(len(A)-1):
        i_min = i
        for j in range(i+1, len(A)):
            if get_value(a[j]) < get_value(a[i_min]):
                i_min = j
        a[i], a[i_min] = a[i_min], a[i]
    return a

def is_stable(A_orig, A_sort):
    dict_orig = {}
    dict_sort = {}
    
    # dict初期化
    for i in range(10):
        dict_orig[i] = list()
        dict_sort[i] = list()
    
    # dictに値設定
    for i in range(0, len(A_orig)):
        
        vo = get_value(A_orig[i])
        vs = get_value(A_sort[i])
        so = get_suit(A_orig[i])
        ss = get_suit(A_sort[i])
        
        dict_orig[vo].append(so)
        dict_sort[vs].append(ss)
    
    # stableかどうか検証
    for i in range(10):
        for j in range(len(dict_orig[i])):
            if dict_orig[i][j] is not dict_sort[i][j]:
                return False
    return True

input()
input_arr = input().split()

arr_bubble = bubble_sort(input_arr)
arr_selection = selection_sort(input_arr)

print(' '.join(arr_bubble))
print('Stable' if is_stable(input_arr, arr_bubble) else 'Not stable')
print(' '.join(arr_selection))
print('Stable' if is_stable(input_arr, arr_selection) else 'Not stable')


Measured memory_bytes: 5612
#include<stdio.h>
 
int main(void){
 
    int numWorker;
    int senpai[200001]={0};
 
    int indexCheck = 1;
 
    int counter;
 
    //入力部分
    scanf("%d",&numWorker);
    for(int i=1;i<numWorker;i++){
        scanf("%d",&counter);
        senpai[counter]++;
    }
 
    //計算部分
 
    //出力部分
    for(int j=1;j<=numWorker;j++){
        printf("%d\n",senpai[j]);
    }
}

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

ll gcd(ll x, ll y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̒萔 (10��9��)
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 { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n);
    vector<int> b(m);
    int ans = 0;
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];

    vector<ll> rui_a(n + 1);
    for (int i = 1; i <= n; i++) {
        rui_a[i] = rui_a[i - 1] + a[i - 1];
    }
    vector<ll> rui_b(m + 1);
    for (int i = 1; i <= m; i++) {
        rui_b[i] = rui_b[i - 1] + b[i - 1];
    }

    for (int i = 0; i <= n; i++) {
        int num = k - rui_a[i];
        if (num < 0) break;
        int ok = 0, ng = m + 1;
        while (ng - ok > 1) {
            int mid = (ok + ng) / 2;
            if (num >= rui_b[mid])
                ok = mid;
            else
                ng = mid;
        }

        ans = max(ans, i + ok);
    }

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

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
ll gcd(ll x, ll y) {
    ll num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 8044
import java.util.Scanner;

class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt(), x = sc.nextInt();
        int m[] = new int[n];
        int sum = 0;
        int min = 1000;
        for (int i = 0; i < n; i++) {
            m[i] = sc.nextInt();
            sum += m[i];
            min = Math.min(min, m[i]);
        }
        System.out.println(n + (x - sum) / min);
    }
}

Measured memory_bytes: 24276
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=1000000000000000010;
int dx[5]={0,1,0,-1,0};
int dy[5]={1,0,-1,0,0};
struct edge{int to;ll cap;int rev;};
vector<edge> G[100010];
int lev[100010];
int itr[100010];
struct Dinic{
    void add_edge(int from,int to,ll cap){
        G[from].push_back((edge){to,cap,(int)G[to].size()});
        G[to].push_back((edge){from,0LL,(int)G[from].size()-1});
    }
 
    void bfs(int s){
        memset(lev,-1,sizeof(lev));
        queue<int> q;
        lev[s]=0;
        q.push(s);
        while(!q.empty()){
            int v=q.front();q.pop();
            for(int i=0;i<G[v].size();i++){
                edge &e=G[v][i];
                if(e.cap>0&&lev[e.to]<0){
                    lev[e.to]=lev[v]+1;
                    q.push(e.to);
                }
            }
        }
    }
 
    ll dfs(int v,int t,ll f){
        if(v==t)return f;
        for(int &i=itr[v];i<G[v].size();i++){
            edge &e=G[v][i];
            if(e.cap>0&&lev[v]<lev[e.to]){
                ll d=dfs(e.to,t,min(f,e.cap));
                if(d>0){
                    e.cap-=d;
                    G[e.to][e.rev].cap+=d;
                    return d;
                }
            }
        }
        return 0;
    }
    
    ll max_flow(int s,int t){
        ll flow=0;
        for(;;){
            bfs(s);
            if(lev[t]<0)return flow;
            memset(itr,0,sizeof(itr));
            ll f;
            while((f=dfs(s,t,LINF))>0){
                flow+=f;
            }
        }
    }
};

int main(){
    int h,w;cin>>h>>w;
    char c[110][110];
    int sy,sx,ty,tx;
    for(int i=0;i<h;i++){
        cin>>c[i];
        for(int j=0;j<w;j++){
            if(c[i][j]=='S'){
                sx=j;sy=i;
            }else if(c[i][j]=='T'){
                tx=j;ty=i;
            }
        }
    }
    if(sx==tx||sy==ty){
        cout<<-1<<endl;
        return 0;
    }
    Dinic d;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(c[i][j]=='o'){
                d.add_edge(i,h+j,1);
                d.add_edge(h+j,i,1);
            }else if(c[i][j]=='S'){
                d.add_edge(w+h,h+j,INF);
                d.add_edge(w+h,i,INF);
            }else if(c[i][j]=='T'){
                d.add_edge(h+j,w+h+1,INF);
                d.add_edge(i,w+h+1,INF);
            }
        }
    }
    cout<<d.max_flow(w+h,w+h+1)<<endl;
}


Measured memory_bytes: 4608
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());
        int[] l = new int[n];
        for(int i = 0; i < n; i++){
            l[i] = Integer.parseInt(sc.next());
        }
        
        int d = 0;
        int count = 1;
        for(int i = 0; i < n; i++){
            d += l[i];
            if(d <= x){
                count++;
            }
        }
        
        System.out.println(count);
    }
}

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

using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> coin(h, vector<int>(w));
  for (int i=0; i<h; ++i) {
    for (int j=0; j<w; ++j) {
      cin >> coin.at(i).at(j);
    }
  }
  
  vector<vector<int>> res;
  int pi = 0, pj = 0;
  for (int i=0; i<h; ++i) {
    if (i%2 == 0) {
      for (int j=0; j<w; ++j) {
        if (i == 0 && j == 0) continue;
        if (coin.at(pi).at(pj) %2 != 0) {
          coin.at(i).at(j)++;
          res.push_back({pi+1, pj+1, i+1, j+1});
        }
        pi = i, pj = j;
      }
    } else {
      for (int j=w-1; j>=0; --j) {
        if (coin.at(pi).at(pj) %2 != 0) {
          coin.at(i).at(j)++;
          res.push_back({pi+1, pj+1, i+1, j+1});
        }
        pi = i;
        pj = j;
      }
    }
  }
  
  cout << (int)res.size() << endl;
  for (auto v : res) {
    cout << v.at(0) << ' ' << v.at(1) << ' ' << v.at(2) << ' ' << v.at(3) << endl;
  }
  return 0;
}


Measured memory_bytes: 9904
fun main() {
  val (L, R) = readInts()
  val l = L
  val r = minOf(L + 2019, R)
  var min = Long.MAX_VALUE
  for (i in l until r) {
    for (j in (i + 1)..r) {
      min = minOf(min, (i.toLong() * j) % 2019)
    }
  }
  println(min)
}

fun gcd(a: Int, b: Int): Int = if (a < b) gcd(b, a) else if (b == 0) a else gcd(b, a % b)
fun gcd(a: Long, b: Long): Long = if (a < b) gcd(b, a) else if (b == 0L) a else gcd(b, a % b)
fun lcm(a: Int, b: Int): Int = (a * b) / gcd(a, b)
fun lcm(a: Long, b: Long): Long = (a * b) / gcd(a, b)

fun readString() = readLine()!!
fun readStrings() = readLine()!!.split(" ")
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readInts() = readLine()!!.split(" ").map { it.toInt() }
fun readLongs() = readLine()!!.split(" ").map { it.toLong() }

fun myBinarySearch(begin: Int, end: Int, isOk: (key: Int) -> Boolean): Int {
  var ng = begin
  var ok = end

  while (Math.abs(ok - ng) > 1) {
    val mid = (ok + ng) / 2
    if (isOk(mid)) {
      ok = mid
    } else {
      ng = mid
    }
  }

  return ok
}

fun <T> List<T>.myBinarySearch(isOk: (T) -> Boolean): Int {
  return myBinarySearch(-1, size) { index -> isOk(get(index)) }
}

fun <T> Array<T>.myBinarySearch(isOk: (T) -> Boolean): Int {
  return myBinarySearch(-1, size) { index -> isOk(get(index)) }
}


Measured memory_bytes: 36496
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

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

}



Measured memory_bytes: 512
#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 n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    rep(i, n)
    {
        cin >> c[i];
        rep(j, m) cin >> a[i][j];
    }
    int ans = 1e9;
    bool res = false;
    rep(bit, 1 << n)
    {
        vector<int> d(n);
        rep(i, n)
        {
            if (bit >> i & 1)
                d[i] = 1;
        }
        vector<int> tgt(m);
        int cost = 0;
        rep(i, n)
        {
            if (d[i] != 1)
                continue;
            rep(j, m)
            {
                tgt[j] += a[i][j];
            }
            cost += c[i];
        }
        bool ok = true;
        rep(i, m)
        {
            if (tgt[i] < x)
                ok = false;
        }
        if (ok)
        {
            ans = min(ans, cost);
            res = true;
        }
    }
    if (res)
        cout << ans << endl;
    else
        cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3616
N = gets.chomp.to_i
a = Array.new(N)
str = gets.split
for i in 0...N do
    a[i] = str[i].to_i
end

for i in 0...N do
    if a[i] % 2 == 0
        if a[i] % 3 != 0 && a[i] % 5 != 0
            puts "DENIED"
            exit
        end
    end
end
puts "APPROVED"

Measured memory_bytes: 3836
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <bitset>

#include <iostream>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <iomanip>
#include <random>
#include <numeric>

// #include <bits/stdc++.h>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>

using namespace std;
// using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;
typedef priority_queue<int, vector<int>, greater<int> > min_heap;

// template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const double PI = 4*atan(1);
const ll INF = 1e18;
const int MX = 100001;

int n, k;
const int maxn = 1005;
int a[maxn];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    int ans = 0;
    for (int i = 1; i <= k; i++) {
        ans += a[i];
    }
    cout << ans << "\n";
    
}
/*
    Potential bugs:
    - Not resetting the arrays properly
    - Out of bounds
*/

Measured memory_bytes: 3656
open Batteries
let () =
  let n = Scanf.scanf "%d " (fun a -> a) in
  let pair_lst = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf "%d %d " (fun a b -> a,b)) in

  Printf.printf "%d\n" @@
  List.fold_left (fun acc (x,y) -> acc+(y-x+1)) 0 pair_lst


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

#define MAXN 100000

using namespace std;

int A[MAXN+1];
vector<int> V6, V9;

int dp ( int N )
{
  for ( int i = 0; i < N; ++i ) {
    A[i+1] = min(A[i+1], A[i]+1);
    for ( int j = 0; j < V6.size(); ++j ) {
      if ( i + V6[j] <= N ) A[i+V6[j]] = min(A[i+V6[j]], A[i]+1);
    }

    for ( int j = 0; j < V9.size(); ++j ) {
      if ( i + V9[j] <= N ) A[i+V9[j]] = min(A[i+V9[j]], A[i]+1);
    }
  }

  return A[N];
}

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

  for ( int i = 6; i <= N; i *= 6 ) V6.push_back(i);
  for ( int i = 9; i <= N; i *= 9 ) V9.push_back(i);

  cout << dp(N) << endl;
}


Measured memory_bytes: 1016
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, pair<int, int> > pii;

int M, T, P, R;

bool cmp(const pii &a, const pii &b){
  if(a.S.F != b.S.F) return a.S.F > b.S.F;
  if(a.S.S != b.S.S) return a.S.S < b.S.S;
  return a.F > b.F;
}

int main(){
  while(scanf("%d%d%d%d",&M, &T, &P, &R) && M+T+P+R){
    vector<vector<int> >pe(T, vector<int>(P));
    rep(i, T) rep(j, P) pe[i][j] = 0;
    vector<pii>team(T); // team, ac, penalty
    rep(i, T) team[i] = make_pair(i, make_pair(0, 0));

    int m, t, p, j;
    rep(i, R){
      scanf("%d%d%d%d", &m, &t, &p, &j); t--; p--;
      if(j){
	pe[t][p]++;
      }else{
	team[t].S.F++;
	team[t].S.S += m + (20 * pe[t][p]);
      }
    }
    //    rep(i, T) printf("%d %d %d\n", team[i].F+1, team[i].S.F, team[i].S.S);
    sort(team.begin(), team.end(), cmp);

    //    rep(i, T) printf("%d ", team[i].F+1); puts("");
    rep(i, T) printf(i?team[i-1].S.F==team[i].S.F&&team[i-1].S.S==team[i].S.S?"=%d":",%d":"%d", team[i].F+1); puts("");
  }
  return 0;
}

Measured memory_bytes: 1224
class Dice(object):
    def __init__(self, top, south, east, west, north, bottom):
        self.top = top
        self.south = south
        self.east = east
        self.west = west
        self.north = north
        self.bottom = bottom

    def get_face(self, face):
        if face == 'top':
            return self.top
        elif face == 'south':
            return self.south
        elif face == 'east':
            return self.east
        elif face == 'west':
            return self.west
        elif face == 'north':
            return self.north
        elif face == 'bottom':
            return self.bottom

    def rotate(self, directions):
        for direction in directions:
            if direction == 'S':
                self.prev_top = self.top
                self.top = self.north
                self.north = self.bottom
                self.bottom = self.south
                self.south = self.prev_top
            elif direction == 'E':
                self.prev_top = self.top
                self.top = self.west
                self.west = self.bottom
                self.bottom = self.east
                self.east = self.prev_top
            elif direction == 'W':
                self.prev_top = self.top
                self.top = self.east
                self.east = self.bottom
                self.bottom = self.west
                self.west = self.prev_top
            elif direction == 'N':
                self.prev_top = self.top
                self.top = self.south
                self.south = self.bottom
                self.bottom = self.north
                self.north = self.prev_top

dice = Dice(*map(int,input().split()))
n = int(input())
for _ in range(n):
  top, south = map(int, input().split())
  # find top face
  for direction in 'NNNEEE':
    if dice.get_face('top') == top:
        break
    dice.rotate(direction)

  # find south face
  for directions in ['NES']*3:
    if dice.get_face('south') == south:
        break
    for direction in directions:
        dice.rotate(direction)
  print(dice.get_face('east'))

Measured memory_bytes: 7840
N, M = map(int, input().split())
A = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))

c = 0
for n in range(1 << N):
    for i, S in enumerate(A):
        #print(P[i] , sum(n >> s-1 & 1 for s in S))
        if P[i] ^ sum(n >> s-1 & 1 for s in S) & 1:
            break
    else:
        c += 1

print(c)


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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    float t,x;
    cin >> t >> x;
    cout << t/x << endl;
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;
#pragma endregion
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int N, R, ans = 0;
	cin >> N >> R;

	if (N >= 10)
	{
		ans = R;
	}
	else
	{
		ans = R + 100 * (10 - N);
	}

	cout << ans << '\n';


	return 0;
}


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

typedef long long ll;

using namespace std;

int main(){
    int N,K,i,j;
    cin >> N >> K;
    ll ans = 0;
    for(int b = 1; b <= N; b++){
        if (b > K){
            ans += (N/b) * (b - K);
            int tmp = (N/b) * b;

            int last_num = N - tmp;

            if(last_num - K >= 0){
                if (K == 0){
                    ans += last_num - K;
                }else{
                    ans += last_num - K + 1;
                }
            }
        }

    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define ll long long  
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define S second
#define F first
#define die() return 0;
 
 
#define md          1000000007
#define fmd         998244353 
#define M           500011
#define N            18
ll exp(ll a,ll b){if(b<0)return 0;ll r=1;while(b){if(b&1)r=r*a%md,r%=md;a=a*a%md;b/=2;}return r;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll F[M],IV[M];
ll down[M],sz[M];

ll chose(ll n,ll k){
	if(k>n)return 0;
	ll r=F[n];r=r*IV[k];r%=md;r=r*IV[n-k]%md;return r%md;
}
int solve(){
    ll n,i,j,k,m,x,y,z;
    cin>>n>>m;
    ll ans=0;
    for(i=0;i<=n;++i){
    	ll p=chose(n,i);
    	ll k=chose(m-i,n-i);
    	ll ff=F[n-i];ff%=md;
    	k=k*ff;k%=md;
    	p=p*k;p%=md;
    	if(i%2){
    		ans=(ans-p+md);
    		if(ans>md)ans-=md;
    	}
    	else{
    		ans+=p;
    		if(ans>md)ans-=md;
    	}
    }
    ll p=ans;
	p=p*chose(m,n);p%=md;
	p=p*F[n];p%=md;

    cout<<p<<"\n";


    
 
 
 
 
 
    // trace(f(2,2));
 
 
 
	die();
 
}
void prec(){
	F[0]=IV[0]=1;
	for(int i=1;i<M;++i){
		F[i]=F[i-1]*i%md;F[i]%=md;
		IV[i]=IV[i-1]*exp(i,md-2)%md;IV[i]%=md;
	}
} 
 
int main(){
 
 
#ifndef ONLINE_JUDGE
    double _tBeg=clock();
#endif
 
     
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
    int t;
    t=1;;
    prec();
    // cin>>t;
 
    while(t--){
 
        solve();
    }
 
 
 
 
 
 
#ifndef ONLINE_JUDGE
    double _tEnd=clock();
    // printf("\ntotal time %.6f\n",(_tEnd-_tBeg)/CLOCKS_PER_SEC);
#endif
 
    die();
}

Measured memory_bytes: 11472
// D - Equals
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
	int n, m; cin>>n>>m;
	vi P(n); rep(i, n){ cin>>P[i]; P[i]--; }
	vvi G(n, vi());
	rep(i, m){
		int x, y; cin>>x>>y; x--, y--;
		G[x].push_back(y), G[y].push_back(x);
	}

	int ans = 0;
	vi vis(n, false);
	queue<int> q;
	rep(i, n){
		vi xx, px;
		q.push(i);
		while(q.size()){
			int x = q.front(); q.pop();
			if(vis[x]) continue;
			vis[x] = true;
			xx.push_back(x), px.push_back(P[x]);
			for(int y:G[x]){
				if(vis[y]) continue;
				q.push(y);
			}
		}
		sort(all(xx)), sort(all(px));
		for(int x:xx)
			if(px[lower_bound(all(px), x) - px.begin()] == x) ans++;
	}
	cout<< ans <<endl;
}


Measured memory_bytes: 7376
NN = 2020202
MOD = 10**9+7
INF = float("inf")


class BIT():
    def __init__(self, n):
        self.n = n
        self.bit = [[0]*26 for _ in range(self.n+1)]
        self.s = ["*"]*self.n

    def _sum(self, i):
        s = [0]*26
        while i > 0:
            for idx, v in enumerate(self.bit[i]):
                s[idx] += v
            i -= i & -i
        return s

    def add(self, i, val):
        """i番目にvalを加える"""
        old = self.s[i-1]
        self.s[i - 1] = val
        # print(old, val)
        if old == val:
            return

        while i <= self.n:
            # print(i)
            self.bit[i][ord(val) - ord("a")] += 1
            if 0 <= ord(old) - ord("a") < 26:
                self.bit[i][ord(old) - ord("a")] -= 1

            i += i & -i

    def get_sum(self, l, r):
        """区間[l, r)の和を求める"""
        A = self._sum(r)
        B = self._sum(l-1)
        # print(A, B)
        ans = 0
        for idx in range(26):
            if A[idx] > B[idx]:
                ans += 1

        return ans
        # return self._sum(r) - self._sum(l)


N = int(input())
S = input()
Q = int(input())
query = [list(input().split()) for i in range(Q)]

tree = BIT(N)
for i in range(N):
    tree.add(i+1, S[i])
# print(tree.bit)

for i in range(Q):
    if query[i][0] == "1":
        tree.add(int(query[i][1]), query[i][2])
        # print(tree.bit)
    if query[i][0] == "2":
        print(tree.get_sum(int(query[i][1]), int(query[i][2])))


Measured memory_bytes: 206080
#include <stdio.h>

int main(void)
{
    double d, t, s;

    scanf("%lf", &d);
    scanf("%lf", &t);
    scanf("%lf", &s);

    if ((d / s) <= t)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }

    return 0;
}

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

int N, M, X;
vector<int> C;
vector<vector<int>> A;
const int INF = 1e+9;

void dfs(vector<int> & bit, int & res) {

	if (bit.size() == N) {
		int cost = 0;
		vector<int> skill(M);
		// 本を買ったらコストと理解度を加算する
		for (int i = 0; i < N; i++) {
			if (bit[i]) {
				cost += C[i];
				for (int j = 0; j < M; j++) {
					skill[j] += A[i][j];
				}
			}
		}
		bool ok = true;
		for (int i = 0; i < M; i++) {
			if (skill[i] < X) {
				ok = false;
				break;
			}
		}
		if (ok) res = min(res, cost);

		return;
	}

	for (int i = 0; i < 2; i++) {
		bit.push_back(i);
		dfs(bit, res);
		bit.pop_back();
	}
}

int main(void) {
	// 入力
	cin >> N >> M >> X;
	C.resize(N);
	A.resize(N, vector<int>(M));

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

	int res = INF;
	vector<int> bit;
	dfs(bit, res);

	if (res == INF) cout << -1 << endl;
	else cout << res << endl;

	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

#define LEN 16010
#define SIZE 8000

bool in(int x)
{
    return 0 <= x && x < LEN;
}

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

    string s;
    cin >> s;
    s.push_back('T');
    int x, y;
    cin >> x >> y;
    x += SIZE, y += SIZE;
    int cnt = 0;
    vector<int> vx, vy;
    bool f = true;
    rep(i, s.size())
    {
        if (s[i] == 'F')
            cnt++;
        else
        {
            if (f)
                vx.push_back(cnt), f = false;
            else
                vy.push_back(cnt), f = true;
            cnt = 0;
        }
    }
    bool dpx[LEN], dpy[LEN];
    rep(i, LEN) dpx[i] = dpy[i] = false;
    dpx[vx[0] + SIZE] = dpy[SIZE] = true;
    for (int i = 1; i < vx.size(); i++)
    {
        bool nxt[LEN];
        rep(j, LEN) nxt[j] = false;
        int len = vx[i];
        rep(j, LEN)
        {
            if (in(j - len))
                nxt[j] |= dpx[j - len];
            if (in(j + len))
                nxt[j] |= dpx[j + len];
        }
        rep(j, LEN) dpx[j] = nxt[j];
    }
    for (int i = 0; i < vy.size(); i++)
    {
        bool nxt[LEN];
        rep(j, LEN) nxt[j] = false;
        int len = vy[i];
        rep(j, LEN)
        {
            if (in(j - len))
                nxt[j] |= dpy[j - len];
            if (in(j + len))
                nxt[j] |= dpy[j + len];
        }
        rep(j, LEN) dpy[j] = nxt[j];
    }
    bool ans = dpx[x] && dpy[y];
    cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
	int number[4] = {0,0,0,0};
	int a, b;
	int i;
	for ( i = 0; i < 3; i++)
	{
		scanf("%d %d", &a, &b);
		number[a - 1]++;
		number[b - 1]++;
		if (number[a - 1] >= 3 || number[b - 1] >= 3)
		{
			printf("NO");
			return 0;
		}
	}
	for ( i = 0; i < 4; i++)
	{
		if (number[i] == 0)
		{
			printf("NO");
			return 0;
		}
	}
	printf("YES");
	return 0;
}

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

int main() {
  int64_t N,K;
  cin>>N>>K;
  vector<int64_t> v(N);
  for(int i=0;i<N;i++){
    cin>>v.at(i);
  }
  vector<int64_t> memo(N);
  int64_t c=0;
  int64_t d=0;
  while(memo.at(d)==0){
    c++;
    memo.at(d)=c;
    d=v.at(d)-1;
  }
  int64_t r=memo.at(d)-1;
  int64_t mod=c-r;
  int64_t ans=0;
  if(K<=r){
    ans=K+1;
  }
  else{
    ans=(K-r)%mod+r+1;
  }
  int64_t z=0;
  while(memo.at(z)!=ans){
    z++;
  }
  cout<<z+1;
}

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

string s;
int main(){
	cin >> s;
	bool flag = 0;
	for(int i = 1;i < s.size();i++){
		if(s[i] != '9') flag = 1;
	}
	if(flag){
		cout << 9 * s.size() - 9 + int(s[0] - '0') - 1;
	}
	else cout << 9 * s.size() - 9 + int(s[0] - '0');
	return 0;
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s;
map <char,int> m;
vector<int> v;
int main() {
    cin >> s;
    for (char c:s) {
        m[c]++;
    }
    for (auto p:m) {
        v.push_back(p.second);
    }
    if (v.size()==2 && v.front() == 2) printf("Yes");
    else printf("No");
}


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

num = 0
min_num = 1000000000000000000000000

for p in range(1,max(a)+1):
  for i in a:
    num += (i-p)**2
    
  if num < min_num:
    min_num = num
  
  num = 0

print(min_num)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <stack>

constexpr int MAX = (1 << 9);
constexpr int MAX_W = 100010;

void chmax (int &a, int b){
	if (a < b) a = b;
}

int main() {
	int n;
	std::cin >> n;
	std::vector<int> value(n + 1), weight(n + 1);
	for (int i = 1; i <= n; i++) {
		std::cin >> value[i] >> weight[i];
	}
	
	std::vector<std::vector<int>> dp(MAX, std::vector<int>(MAX_W, 0));
	std::stack<int> sta;
	sta.push(1);
	while (not sta.empty()) {
		int v = sta.top(); sta.pop();
		dp[v] = dp[v >> 1];
		for (int sum_w = MAX_W; sum_w-->0;) {
			if (sum_w + weight[v] < MAX_W) {
				chmax(dp[v][sum_w + weight[v]], dp[v][sum_w] + value[v]);
			}
		}
		
		for (int u : {(v << 1 | 0), (v << 1 | 1)}) {
			if (u <= n and u < MAX) sta.push(u);
		}
	}
	
	int q;
	std::cin >> q;
	while (q--) {
		int v, max_w;
		std::cin >> v >> max_w;
		if (v < MAX) {
			std::cout << dp[v][max_w] << '\n';
			continue;
		}
		
		std::vector<int> ver;
		for (; v >= MAX; v >>= 1) {
			ver.push_back(v);
		}
		
		const int m = int(ver.size());
		int sv = 0, sw = 0, ans = dp[v][max_w];
		for (int tmp = 1; tmp < (1 << m); tmp++) {
			int s = (tmp ^ (tmp >> 1)), i = __builtin_ctz(tmp);
			if (s & (1 << i)) {
				sv += value[ver[i]];
				sw += weight[ver[i]];
			} else {
				sv -= value[ver[i]];
				sw -= weight[ver[i]];
			}
			
			if (sw <= max_w) chmax(ans, sv + dp[v][max_w - sw]);
		}
		
		std::cout << ans << '\n';
	}

}

Measured memory_bytes: 206468
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
    int a,b,k;
    cin>>a>>b>>k;
    for (int i=1; i<k+1; i++) {
        if (i%2!=0) {
                b += a/2;
            a = a/2;
        }else{
                a += b/2;
            b = b/2;
            }
    }
    cout<<a<<endl;
    cout<<b<<endl;
    return 0;
}

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

using namespace std;
#define ll long long int

void dfs(vector<int> adj[], bool visited[], int node, ll dist[])
{
    visited[node] = true;
    for (auto x : adj[node])
    {
        if (!visited[x])
        {
            dfs(adj, visited, x, dist);
        }

        dist[node] = max(dist[node], 1 + dist[x]);
    }
}

int main()
{
    ll n, m;
    cin >> n >> m;
    int degree[n + 1] = {0};
    vector<int> adj[n + 1];
    for (int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        adj[x].push_back(y);
        degree[y]++;
    }
    ll ans = 1;
    bool visited[n + 1] = {0};
    ll dist[n + 1] = {0};
    for (int i = 1; i <= n; i++)
    {
        ll count = 0;
        if (degree[i] == 0)
        {
            visited[i] = true;
            for (auto x : adj[i])
            {
                if (!visited[x])
                {
                    dfs(adj, visited, x, dist);
                }
                dist[i] = max(dist[i], 1 + dist[x]);
            }
        }
        ans = max(dist[i], ans);
    }
    cout << ans << endl;
}

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

using namespace std;

#define TEMP_T template<typename T>
TEMP_T void sort(T& v){ sort(v.begin(), v.end()); }
TEMP_T void revs(T& v){ reverse(v.begin(), v.end()); }
TEMP_T void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end()), v.end()); }
TEMP_T T    cums(T& v){ T r(v.size()); partial_sum(v.begin(), v.end(), r); return r; }
TEMP_T void show(T& v, char delim=' ', char end='\n'){ for(int i=0; i<v.size()-1; i++) cout << v[i] << delim; cout << v[v.size()-1] << end; }
TEMP_T T    acum(vector<T>& v, T b=0){ return accumulate(v.begin(), v.end(), b); }
TEMP_T vector<T> inpt(int n){ vector<T> v(n); for (int i=0; i<n; i++) cin >> v[i]; return v; }

static inline int in(){ int x; scanf("%d", &x); return x; }
static const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
static const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};

struct Field {
  Field(int w, int h) : w(w), h(h) {}
  bool invalid(int x, int y){ return x < 0 || w <= x || y < 0 || h <= y; }
  const int w, h;
};

struct Solver {
  Solver(){}
  int solve(){
  }
};

int main()
{
  int n, m, a;
  while (n = in(), m = in(), a = in()){
    vector<int> vs;
    for (int i = 0; i <= n; i++) vs.push_back(i);
    vector<pair<int, pair<int, int> > > ss;
    for (int i = 0; i < m; i++){
      int h, p, q;
      h = in();
      p = in();
      q = in();
      ss.push_back(make_pair(h, make_pair(p, q)));
    }
    sort(ss);
    for (int i = 0; i < m; i++){
      int f, t;
      f = ss[i].second.first;
      t = ss[i].second.second;
      swap(vs[f], vs[t]);
    }
    printf("%d\n", vs[a]);
  }

  return (0);
}

Measured memory_bytes: 1236
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const ll maxn = 1e6+10;
const ll inf = 1e14;

vector<pii> ve[maxn];
ll dis[maxn];
priority_queue<pii,vector<pii>,greater<pii>> heap;
int n,m;

void init(){
	for(int i = 1;i<=n;i++) dis[i] = inf;
	for(int i = 1;i<=n;i++) ve[i].push_back({0,i-1});
	
}

ll Dji(){
	heap.push({0,1});
	dis[1] = 0;
	
	while(heap.size()){
		auto cur = heap.top();heap.pop();
		ll d = cur.first,id = cur.second;
		for(auto v:ve[id]){
			ll w = v.first,id2 = v.second;
			if(d+w<dis[id2]){
				dis[id2] = d+w;
				heap.push({dis[id2],id2});
			}
		}
	}
	if(dis[n] == inf) return -1;
	return dis[n];
}

int main(){
	cin>>n>>m;
	init();
	int a,b,c;
	for(int i = 0;i<m;i++){
		scanf("%d%d%d",&a,&b,&c);
		ve[a].push_back({c,b});
	}
	cout<<Dji()<<endl;
	return 0;
}

Measured memory_bytes: 32888
# Mix Juice
def fruits(arr, k):
    arr.sort()
    ans = 0
    while k:
        ans += arr.pop(0)
        k -= 1
    return ans



n, k = list(map(int, input().rstrip().split()))
ar = list(map(int, input().rstrip().split()))
print(fruits(ar, k))

Measured memory_bytes: 9188
#!/usr/bin/env python3
MOD = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
ans = 0
for b in range(60)[::-1]:
    ans <<= 1
    c = sum(a[i] >> b & 1 for i in range(n))
    ans = (ans + c * (n - c)) % MOD
print(ans)


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

int main(){
      int n;cin >> n;
      set<string> s;
      string last;
      for(int i = 0;i < n;i++){
            string str;cin >> str;
            if(i > 0){
                  if(str[0] != last[last.length() - 1] || s.count(str) != 0)return cout << "No", 0;
            }
            last = str;
            s.insert(str);
      }
      cout << "Yes";
}

Measured memory_bytes: 256
/*
    Created by Ezio112
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define inf ll(10e16)
#define mod ll(10e8+7)
#define ff first
#define ss second
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    ll t;
    //cin>>t;
    t=1;
    while(t--)
    {
        ll n,a,b,c;
        map<char,ll> val;
        cin>>n>>a>>b>>c;

        val['A']=a;
        val['B']=b;
        val['C']=c;

        if(a+b+c<=0)
        {
            cout<<"No";
            return 0;
        }
        vector<char> ans;
        vector<pair<char,char>> qu(n);

        for(ll i=0;i<n;++i)
            cin>>qu[i].ff>>qu[i].ss;


        for(ll i=0;i<n;++i)
        {
            char f=qu[i].ff,s=qu[i].ss;

            if(val[f]==0 && val[s]==0)
            {
                cout<<"No";
                return 0;
            }
            else if(val[f]==0)
            {
                ans.push_back(f);
                val[f]++;
                val[s]--;
            }
            else if(val[s]==0)
            {
                ans.push_back(s);
                val[s]++;
                val[f]--;
            }
            else if(val[f]==1 || val[s]==1)
            {
                char to_take,not_taken;
                if(i==n-1)
                {
                    ans.push_back(f);
                }
                else{
                    if(qu[i+1].ff==f || qu[i+1].ss==f)
                    {
                        to_take=f;
                        not_taken=s;
                    }
                    else {
                        to_take=s;
                        not_taken=f;
                    }
                    ans.push_back(to_take);
                    val[to_take]++;
                    val[not_taken]--;
                }
            }
            else {
                if(val[f]>val[s])
                {
                    ans.push_back(s);
                    val[s]++;
                    val[f]--;
                }
                else
                {
                    ans.push_back(f);
                    val[f]++;
                    val[s]--;
                }
            }
        }
        cout<<"Yes\n";
        for(char x:ans)
        cout<<x<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3848
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    INT(h,w);
    vector2d(char,s,h,w);
    vector<int> table(26,0);
    in(s);
    rep(y,h){
        rep(x,w){
            table[s[y][x]-'a']++;
        }
    }
    int counter=0,odd=0,oddn=0,two=0,twon=0,line;
    rep(i,26){
        counter+=(table[i]%4==0);
        if(table[i]%2==1){
            odd++;
        }else if(table[i]%2==0&&table[i]%4!=0){
            two++;
            twon+=table[i];
        }
    }   
    if(h%2==0&&w%2==0){
        Yes(counter==26);
    }else if(h%2==1&&w%2==1){
        Yes(odd==1&&two<=(h+w-2)/2);
    }else{
        if(h%2==0)line=h;
        else line=w;
        Yes(odd==0&&two<=line/2);
    }
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
// #pragma GCC optimize("O3")

#define debug(var)  do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ std::cerr << std::endl; for(const auto& v : vv){ view(v); } }
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 (b<a) { a=b; return 1; } return 0; }
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> v1;
typedef vector<v1> v2;
typedef vector<v2> v3;

typedef unordered_map<ll, unordered_map<ll, ll>> graph;

const ll INF = 1ll << 50;
const ll mod = 1000000007;

ll n;
v1 a;
priority_queue<ll, v1, greater<ll>> pq;

int main(){
    cin >> n;
    a = v1(n);
    for(ll i = 0;i < n;i++) cin >> a[i];
    for(ll i = 0;i < n;i++) pq.push(a[i]);
    ll x = pq.top();
    pq.pop();
    while(!pq.empty()){
        ll y = pq.top();
        pq.pop();
        y %= x;
        if(y != 0){
            swap(x,y);
            pq.push(y);
        }
    }
    cout << x << endl;
}


Measured memory_bytes: 4988