akhauriyash/Code-Regression huggingface dataset:
/*
        * @Author: hesorchen
        * @Date: 2020-08-15 16:08:10
 * @LastEditTime: 2020-09-12 19:39:20
        * @Description: 栽种绝处的花
        */
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <vector>
#include <bitset>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define endl '\n'
#define PI acos(-1)
#define PB push_back
#define ll long long
#define INF 0x3f3f3f3f
#define mod 1000000007
#define pll pair<ll, ll>
#define lowbit(abcd) (abcd & (-abcd))
#define max(a, b) ((a > b) ? (a) : (b))
#define min(a, b) ((a < b) ? (a) : (b))

#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define FRE                              \
    {                                    \
        freopen("in.txt", "r", stdin);   \
        freopen("out.txt", "w", stdout); \
    }

//head==============================================================================
map<int, int> mp1, mp2;
struct node
{
    int v, s;
    bool operator<(node temp)
    {
        return s > temp.s;
    }
} a1[100010], a2[100010];
int main()
{
    int n;
    scanf("%d", &n);
    for (int ct = 1; ct <= n; ct++)
    {
        int temp;
        scanf("%d", &temp);
        if (ct & 1)
            mp1[temp]++;
        else
            mp2[temp]++;
    }
    int ct1 = 0, ct2 = 0;
    for (auto i = mp1.begin(); i != mp1.end(); i++)
    {
        a1[++ct1].v = i->first;
        a1[ct1].s = i->second;
    }
    for (auto i = mp2.begin(); i != mp2.end(); i++)
    {
        a2[++ct2].v = i->first;
        a2[ct2].s = i->second;
    }
    a2[++ct2].v = -1;
    a2[ct2].s = 0;

    sort(a1 + 1, a1 + 1 + ct1);
    sort(a2 + 1, a2 + 1 + ct2);

    int ans = INF;

    for (int i = 1; i <= ct1; i++)
        for (int j = 1; j <= ct2; j++)
            if (a1[i].v != a2[j].v)
            {
                ans = min(ans, n / 2 - a1[i].s + n / 2 - a2[j].s);
                break;
            }
    cout << ans << endl;

    return 0;
}

/*
12
1 2 1 2 1 2 1 2 1 4 1 4
        */

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

bool check(vector<int> &motigoma) {
    int cnt = 0;
    for (int i : motigoma)
        if (i != 0) cnt++;
    if (cnt == 1)
        return true;
    else
        return false;
}

int solve(int N, int P) {
    vector<int> motigoma(N, 0);
    int nokori = P;
    int sum    = P;
    int i      = 0;
    while (1) {
        if (nokori != 0) {
            motigoma[i]++;
            nokori--;
        } else if (sum - motigoma[i] == 0) {
            return i;
        } else {
            nokori += motigoma[i];
            motigoma[i] = 0;
        }
        i++;
        i %= N;
    }
}

int main() {
    int N, P;
    vector<int> ans;
    while (cin >> N >> P) {
        if (!N && !P) break;
        ans.push_back(solve(N, P));
    }
    for (int a : ans) cout << a << endl;
}


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

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;


void solve(){
#ifdef _WIN32
	istream &cin = ifstream("input.txt");
#endif
	
	string str, ans = "";
	cin >> str;

	rep(i, str.size()){
		if (str[i] == 'B'){
			if (ans.size() > 0) ans.pop_back();
		}
		else ans.push_back(str[i]);
	}


	cout << ans << endl;
}


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


	solve();
	system("PAUSE");
	return 0;
}

Measured memory_bytes: 504
//
// Created by たかえすみずき on 2017/07/15.
//

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif

#define PRINT(s) cout << (s);
#define PRINTLN(s) cout << (s) << endl;

using namespace std;

int main() {
    priority_queue<int> priority_queue1;
    int n,k;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        priority_queue1.push(tmp);
    }
    int sum = 0;
    for(int i = 0; i < k; i++){
        sum += priority_queue1.top();
        priority_queue1.pop();
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
import math

h, n = map(int,input().split())
alist=list(map(int, input().split()))

alist=sorted(alist)
atk=0
for i in range(min(n, len(alist))):
    atk+=alist[len(alist)-1-i]

#print(atk)
if atk>=h:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 53572
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int P,Q,R;
  cin >> P >> Q >> R;
 
  if(R >= P && R >= Q)
  {
    cout << P + Q << endl;
  }
  else if(Q >= P && Q >= R)
  {
    cout << P + R << endl;
  }
  else
  {
    cout << Q + R << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n;
    cin >> n;
    vi as(n);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }

    int q;
    cin >> q;
    while (q--) {
        int k;
        cin >> k;
        cout << lower_bound(as.begin(), as.end(), k) - as.begin() << endl;
    }
}


Measured memory_bytes: 3628
from collections import deque
def solve():
    n = int(input())
    a = list(map(int, input().split()))

    deq = deque()
    for i in range(n):
        if i % 2 == 0:
            deq.append(a[i])
        else:
            deq.appendleft(a[i])
    
    ans = list(deq)
    if n % 2 == 0:
        print(*ans, sep=' ')
    else:
        print(*ans[::-1], sep=' ')

if __name__ == '__main__':
    solve()

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

int main(){

    int N,X;
    cin >> N >> X;

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

    int a=2;
    int d=L[0];

    for(int i=2;i<=N+1;i++){
        d+=L[i-1];
        if(d>X){
            cout << i <<endl;
            return 0;
        }
    }

    cout << N+1 << endl;

    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; cin >> n;
  priority_queue<l_l, vector<l_l>, greater<l_l>> q;
  rep(i,n){
    int a,b;
    cin >> a >> b;
    q.push(l_l(b,a));
  }
  ll time=0;
  rep(i,n){
    time+=q.top().second;
    if(time>q.top().first){
      cout << "No" << endl;
      return 0;
    }
    q.pop();
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 6128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#include "string"
	

int32_t main(){
	int n;
	cin>>n;
	int a[n];
	int xr = 0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(i>1)
			xr ^= a[i];
	}
	
	int s = a[0] + a[1];
	if(s < xr) {
		cout<<-1<<endl;
		return 0;
	}

	if((a[0]^a[1]) == xr){
		cout<<0<<endl;
		return 0;
	}

	int A = 0,B = 0;
	A = B = (s - xr)/2;
	if((s-xr)%2 != 0 or A > a[0] ){
		cout<<-1<<endl;
		return 0;
	}

	for(int i=0;i<64;i++){
		if(xr&(1ll<<i) && A&(1ll<<i)){
			cout<<-1<<endl;
			return 0;
		}
	}

	for(int i=64;i>=0;i--){
		if(xr&(1ll<<i) && (A|(1ll<<i)) < a[0] ){
			A |= (1ll<<i);
		}
	}

	int tra = a[0] - A;
	if(tra == a[0] ){
		cout<<-1<<endl;
		return 0;
	}

	cout<< tra <<endl; 
}



Measured memory_bytes: 3636
import sys
readline = sys.stdin.buffer.readline

n,q= map(int,readline().split())

#Union Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

#xが属するグループの要素全てを返す
def members(x):
    root = find(x)
    return [i for i in range(n) if find(i) == root]

#全ての根の要素をlistで返す(一個下の関数で使う)
def roots():
    return [i for i,x in enumerate(par) if x < 0]

#グループ数を返す
def group_count():
    return len(roots())

#根をkey,そのグループに含まれる要素をvalueとして全てを辞書型で返す
def all_group_members():
    return {r: members(r) for r in roots()}

#初期化
#根なら-size,子なら親の頂点
par = [-1]*n

"""
uniteでまとめ、findで見つける。
n(要素数)だけ最初に付け加えること。
"""

for i in range(q):
    com,a,b = map(int,readline().split())
    if com:
        if same(a,b):
            print(1)
        else:
            print(0)
    else:
        unite(a,b)


Measured memory_bytes: 6488
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;

const ll INF=1e10+100;

int main()
{
    ll a,b;
    cin >> a >> b;
    ll ans=a+b;
    if(ans>=10) cout << "error" << endl;
    else cout << ans << endl;
    return 0;
} 


Measured memory_bytes: 3584
import java.util.*;

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

        Map<Integer, Integer> freqMap = new HashMap<>();
        for(int i = 0; i < n; i++) {
        	int num = sc.nextInt();
        	freqMap.put(num, freqMap.getOrDefault(num, 0) + 1);
        }
        if(freqMap.size() % 2 == 1)
        	System.out.println(freqMap.size());
        else
        	System.out.println(freqMap.size() - 1);
    }
}


Measured memory_bytes: 62544
#include<iostream>
#include<string>
using namespace std;
string S;
int A,B;
int main(void){
	cin>>A>>B>>S;
	if(S[A]!='-'){
		cout<<"No";
		return 0;
	}
	for(int i=0;i<S.size();i++)
		if((S[i]>'9'||S[i]<'0')&&i!=A){
			cout<<"No";
			return 0;
		}
	cout<<"Yes";
	return 0;
}

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

int main(){
  int a,b;
  cin>>a>>b;
  vector<int> s(4);
  s.at(0)=a;
  s.at(1)=b;
  s.at(2)=a-1;
  s.at(3)=b-1;
  sort(s.begin(),s.end());
  cout<<s.at(2)+s.at(3)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){
  int H, W;
  cin >> H >> W;
  vector<string> field(H);

  REP(h, H) cin >> field[h];
  REP(h,H){
    cout << field[h] << endl;
    cout << field[h] << endl;
  }
  return 0;
}

Measured memory_bytes: 3644
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    A_arr = list(map(int,_in[1].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = 0
    i = -1
    while True:
        i += 1
        while i<N-1 and A_arr[i]==A_arr[i+1]:
            i += 1
        if i<N-1 and A_arr[i]<=A_arr[i+1]:
            while i<N-1 and A_arr[i]<=A_arr[i+1]:
                i += 1
        elif i<N-1 and A_arr[i]>=A_arr[i+1]:
            while i<N-1 and A_arr[i]>=A_arr[i+1]:
                i += 1
        cnt += 1
        if i>=N-1:
            break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int main()
{
    FastRead;
    int n;
    cin>>n;
    LL s=0;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            for(int k=1; k<=n; k++)
            {
                s+=__gcd(__gcd(i,j),k);
            }
        }
    }
    cout<<s;

}


Measured memory_bytes: 3612
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

#ifndef LOCAL
#define cerr _cer
struct _cert
{
    template <typename T> _cert& operator << (T) { return *this; }
};
_cert _cer;
#endif

template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
		cerr << (*i) << " ";
    }
    cerr << "\n";
}

int en[210000];
int ds[210000];
int was[210000];
vector<int> eds[210000];
int a[210000];
int n;
int cc;
map<int, int> mm;

void addedge(int a, int b) {
	eds[a].push_back(b);
	eds[b].push_back(a);
}

int dfs1(int v) {
	int now = -1;
	was[v] = 1;
	if (en[v])
		now = v;
	for (int u: eds[v]) {
		if (!was[u] && !ds[u]) {
			int x = dfs1(u);
			if (x != -1 && (now == -1 || a[now] > a[x]))
				now = x;
		}
	}
	return now;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	cc = n;
	for (int i = 0; i < n; ++i) {
		int tmp = a[i];
		for (int j = 2; j * j <= tmp; ++j)
			if (tmp % j == 0) {
				if (mm.count(j))
					addedge(mm[j], i);
				else
					addedge(mm[j] = cc++, i);
				while (tmp % j == 0)
					tmp /= j;
			}
		if (tmp != 1) {
			int j = tmp;
			if (mm.count(j))
				addedge(mm[j], i);
			else
				addedge(mm[j] = cc++, i);
		}

	}
	for (int i = 0; i < n; ++i)
		en[i] = 1, ds[i] = 0;
	for (int i = 0; i < n; ++i) {
		memset(was, 0, sizeof(was[0]) * cc);
		int mx = -1;
		for (int j = 0; j < n; ++j) {
			if (en[j] && !was[j]) {
				int xx = dfs1(j);
				if (mx == -1 || a[mx] < a[xx])
					mx = xx;
			}
		}
		//cerr << mx << "\n";
		cout << a[mx] << " ";
		ds[mx] = 1;
		en[mx] = 0;
		for (int i = 0; i < n; ++i)
			if (a[i] > a[mx])
				en[i] = 0;
		for (int i = 0; i < n; ++i)
			if (!ds[i] && __gcd(a[i], a[mx]) != 1)
				en[i] = 1;
	}
	cout << "\n";
	return 0;
}




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

int main()
{
    int a,b,num,tap=0;
    cin>>a>>b;
    while(1)
    {
        if(b==1)break;
        tap++;
        
        if(tap==1) num=a;
        else num+=a-1;

        if(num>=b)
        {
            break;
        }
    }
    cout<<tap;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

int main(void)
{
    int64_t N, M;

    std::cin >> N >> M;

    int64_t total = 0;
    for (int64_t i = 0; i < M; ++i) {
        int64_t A;
        std::cin >> A;
        total += A;
    }

    int64_t ans = -1;

    if (total <= N) {
        ans = N - total;
    }

    std::cout << ans << std::endl;

    return 0;
}

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

using namespace std;

int x[1024], y[1024];

pair< vector<int> , vector<int> > sol(int x, int y, int p) {
	if(p == -1) {
		return {{}, {}};
	}
	if(x < 0) {
		auto pv = sol(-x, y, p);
		for(int i=0;i<=p;i++)
			pv.first[i] *= -1;
		return pv;
	}
	if(y < 0) {
		auto pv = sol(x, -y, p);
		for(int i=0;i<=p;i++)
			pv.second[i] *= -1;
		return pv;
	}
	if (x < y) {
		auto pv = sol(y, x, p);
		return {pv.second,pv.first};
	}
	if (x + y >= (1 << p)) {
		auto pv = sol(x-(1<<p), y, p-1);
		pv.first.push_back(1);
		pv.second.push_back(0);
		return pv;
	} else {
		auto pv = sol(x, y, p-1);
		vector<int> v = pv.first, u = pv.second;
		v.push_back(v[p-1]);
		v[p-1] *= -1;
		u.push_back(u[p-1]);
		u[p-1] *= -1;
		return {v, u};
	}
}

int main()
{
	int n, eo;
	int s = 0;
	cin >> n;
	for (int i=0;i<n;i++) {
		cin >> x[i] >> y[i];
		s = max(s, abs(x[i]) + abs(y[i]));
	}
	eo = abs(x[0] + y[0]) % 2;
	for (int i=1;i<n;i++) {
		if (abs(x[i]+y[i])%2 != eo) {
			cout << -1 << endl;
			return 0;
		}
	}
	int p;
	if (eo) {
		for (p=0;(1LL<<p+1)-1<s;p++);
		cout << p+1 << endl;
		for(int i=0;i<=p;i++)
			cout << (1LL<<i) << " ";
		cout << endl;
	} else {
		for(int i=0;i<n;i++)
			x[i]-=1;
		s = 0;
		for (int i=0;i<n;i++)
			s = max(s, abs(x[i]) + abs(y[i]));
		for (p=0;(1LL<<p+1)-1<s;p++);
		cout << p+2 << endl;
		cout << 1 << " ";
		for(int i=0;i<=p;i++)
			cout << (1LL<<i) << " ";
		cout << endl;
	}
	
	for (int i=0;i<n;i++) {
		auto ans = sol(x[i], y[i], p);
		vector<int> v = ans.first, u = ans.second;
		if(eo == 0)
			cout << "R";
		for(int i=0;i<=p;i++) {
			if(v[i]) {
				if(v[i] > 0) {
					cout << "R";
				} else {
					cout << "L";
				}
			} else {
				if(u[i] > 0) {
					cout << "U";
				} else {
					cout << "D";
				}
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	int a,b,c,d;
	a=n%10;
	n/=10;
	b=n%10;
	n/=10;
	c=n%10;
	n/=10;
	d=n%10;
	n/=10;
	if(a==b&&a==c)
	{
		printf("Yes\n");
		return 0;
	}
	if(b==c&&b==d)
	{
		printf("Yes\n");
		return 0;
	}
	printf("No\n");
	return 0;
} 

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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  int A, B;
  std::cin >> A >> B;

  int ans = 1;
  if(A == ans || B == ans) {
    ++ans;
  }
  if(A == ans || B == ans) {
    ++ans;
  }
  std::cout << ans << '\n';
}


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

int X[4];
bool R[51][51][101];
bool W[51];
vector < int > G[51];

int main() {

//    freopen("rin.txt", "r", stdin);

    int n, m, i, j, k;
    int a, b, c;

    cin>>n>>m>>X[0]>>X[1]>>X[2];
    while (m--) {
        cin>>i>>j;
        G[i].push_back(j);
        R[i][j][1] = 1;
    }
    for (i = 1; i <= n; i++) R[i][i][0] = 1;
    for (int len = 2; len <= 100; len++) {
        for (i = 1; i <= n; i++) {
            for (j = 1; j <= n; j++) {
                if (R[i][j][len-1] == 1) {
                    for (k = 0; k < G[j].size(); k++) {
                        int v = G[j][k];
                        R[i][v][len] = 1;
                    }
                }
            }
        }
    }

    W[n] = 1;
    int steps = 0;
    while (true) {
        vector < int > nw;
        for (i = 1; i <= n; i++) {
            if (W[i] == 1) continue;
            bool f = true;
            for (j = 0; j < 3; j++) {
                for (k = 1; k <= n; k++) {
                    if (R[i][k][X[j]] == 1 && W[k] == 1) break;
                }
                f &= (k <= n);
            }
            if (f) nw.push_back(i);
        }
        if (nw.size() == 0) break;
        steps++;
        for (k = 0; k < nw.size(); k++) W[nw[k]] = 1;
        if (W[1] == 1) break;
    }

    if (W[1] == 1) cout<<steps<<endl;
    else cout<<"IMPOSSIBLE"<<endl;


    return 0;
}



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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  
  int h, w, n;
  cin >> h >> w >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  vector<vector<int>> ans(h, vector<int>(w));
  int iter = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[iter] == 0) iter++;
      a[iter]--;
      if (i & 1) {
        ans[i][w - 1 - j] = iter + 1;
      } else {
        ans[i][j] = iter + 1;
      }
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << ans[i][j] << ' ';
    }
    cout << '\n';
  }

  return 0;
}


Measured memory_bytes: 3700
#include <iostream>

using namespace std;

int n;
int x[100000];

void solve()
{
    bool f = true;
    int diff;

    if (n == 1)
    {
        cout << "Yes" << endl;
    }
    else
    {
        for (int i = n - 1; 0 < i; i--)
        {
            diff = x[i] - x[i - 1];
            if (diff <= -2)
            {
                f = false;
                break;
            }
            else if (diff == -1)
            {
                x[i - 1]--;
            }
        }

        if (f)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x[i];
    }

    solve();
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
signed main(){
    string s,t; cin>>s>>t;
    vector<int> alphaS(s.size()),alphaT(t.size());
    for(int i=0; i<s.size(); i++)
        alphaS.at(i) = s.at(i)-'0';
    for(int i=0; i<t.size(); i++)
        alphaT.at(i) = t.at(i)-'0';
    sort(alphaS.begin(),alphaS.end());
    sort(alphaT.begin(),alphaT.end(),greater<int>());
    for(int i=0; i<min(alphaS.size(),alphaT.size()); i++){
        if(alphaS.at(i)<alphaT.at(i)){
            cout<<"Yes"<<endl; return 0;
        }
        if(alphaS.at(i)>alphaT.at(i)){
            cout<<"No"<<endl; return 0;
        }
    }
    cout<<(alphaS.size()<alphaT.size()?"Yes":"No")<<endl; return 0;
}

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

int main() {
  vector V(3, 0);
  char C;
  while (cin >> C) V.at(C - 'a')++;
  sort(V.begin(), V.end());
  cout << ((V.at(2) - V.at(0) <= 1) ? "YES" : "NO") << "\n";
}

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

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

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

  int prev_max = 0;
  long long ans = 0;
  for(auto a: A){
    if(a <= prev_max){
      continue;
    }else if(a == prev_max + 1){
      prev_max = a;
    }else{
      ans += (a - 1) / (prev_max + 1);
      prev_max = max(prev_max, 1);
    }
    //cout << ans << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
import heapq

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

heap = list()
heapq.heapify(heap)
for i in range(n):
    heapq.heappush(heap, (lst[i], i))
res = ''
for i in range(n):
    a,b = heapq.heappop(heap)
    res += str(b+1) + ' '
print(res[:-1])

Measured memory_bytes: 19428
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define INF 0x77777777
#define MAXN 200010
using namespace std;

int n;
int p[MAXN];
pair<int,int> pt[MAXN];
int ch[MAXN][3],numpt;

namespace Treap{
	struct node{
		int lc,rc,size,key;
		int v,minv;
	}a[MAXN];

	void init(){
		for(int i=1;i<=n;i++){
			a[i].key=rand();
			a[i].v=a[i].minv=p[i];
			a[i].size=1;
		}
		a[0].v=a[0].minv=INF;
	}

	void pushup(int x){
		a[x].size=a[a[x].lc].size+a[a[x].rc].size+1;
		a[x].minv=min(min(a[a[x].lc].minv,a[a[x].rc].minv),a[x].v);
	}

	int merge(int x,int y){
		if(!x) return y;
		if(!y) return x;
		if(a[x].key<a[y].key){
			a[x].rc=merge(a[x].rc,y);
			pushup(x);
			return x;
		}else{
			a[y].lc=merge(x,a[y].lc);
			pushup(y);
			return y;
		}
	}

	pair<int,int> split(int x,int k){
		if(!x) return make_pair(0,0);
		if(k<=a[a[x].lc].size){
			pair<int,int> temp=split(a[x].lc,k);
			a[x].lc=temp.second;
			pushup(x);
			return make_pair(temp.first,x);
		}else{
			pair<int,int> temp=split(a[x].rc,k-a[a[x].lc].size-1);
			a[x].rc=temp.first;
			pushup(x);
			return make_pair(x,temp.second);
		}
	}

	int findmin(int x){
		if(a[x].v==a[x].minv) return a[a[x].lc].size+1;
		if(a[a[x].lc].minv<a[a[x].rc].minv) return findmin(a[x].lc);
		else return findmin(a[x].rc)+a[a[x].lc].size+1;
	}
}

int gao(int r1,int r2){
	using namespace Treap;
	if(!r1 || !r2) return 0;
	int minpos=findmin(r1);
	pair<int,int> t1=split(r1,minpos-1);
	pair<int,int> t2=split(t1.second,1);
	int pt1=t2.first;
	pair<int,int> t3=split(r2,minpos-1);
	int minpos2=findmin(t3.second);
	pair<int,int> t4=split(t3.second,minpos2-1);
	pair<int,int> t5=split(t4.second,1);
	int pt2=t5.first;
	pair<int,int> t6=split(t2.second,minpos2-1);
	int x=++numpt;
	pt[x]=make_pair(a[pt1].v,a[pt2].v);
	ch[x][0]=gao(t1.first,t3.first);
	ch[x][1]=gao(t4.first,t6.first);
	ch[x][2]=gao(t6.second,t5.second);
	return x;
}

void output(){
	static priority_queue< pair<int,int> > Q;
	Q.push(make_pair(-pt[1].first,1));
	while(!Q.empty()){
		int x=Q.top().second;
		Q.pop();
		printf("%d %d ",pt[x].first,pt[x].second);
		if(ch[x][0]) Q.push(make_pair(-pt[ch[x][0]].first,ch[x][0]));
		if(ch[x][1]) Q.push(make_pair(-pt[ch[x][1]].first,ch[x][1]));
		if(ch[x][2]) Q.push(make_pair(-pt[ch[x][2]].first,ch[x][2]));
	}
}

int main(){
#ifdef DEBUG
	freopen("E.in","r",stdin);
#endif
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",p+i);
	Treap::init();
	int r1=0,r2=0;
	for(int i=1;i<=n;i+=2){
		r1=Treap::merge(r1,i);
		r2=Treap::merge(r2,i+1);
	}
	gao(r1,r2);
	output();
	return 0;
}


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

using namespace std;

int n;
long long a[100100],ans,bank;
int main()
{
	cin >> n;
	ans = 0;
	for(int i=0;i<n;i++) cin >> a[i];
	for(int i=0;i<n-1;i++) 
	{
		ans+=a[i]/2;
		if(a[i]%2==1)
		{
			if(a[i+1]>0) 
			{
				ans++;
				a[i+1]--;
			}
		}
	}
	ans+=a[n-1]/2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func makeDp(sLen, tLen int) [][]int {
	var dp [][]int
	for i := 0; i <= sLen; i++ {
		dp = append(dp, []int{})
		dp[i] = make([]int, tLen+1)
	}
	return dp
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func reverse(bs []byte) {
	var beforeHarfStart, afterHarfStart, loopCnt int
	length := len(bs)
	if length%2 == 0 {
		beforeHarfStart = length/2 - 1
		afterHarfStart = length / 2
		loopCnt = length / 2
	} else {
		beforeHarfStart = (length - 1) / 2
		afterHarfStart = (length - 1) / 2
		loopCnt = (length + 1) / 2
	}

	for i := 0; i < loopCnt; i++ {
		s1 := bs[beforeHarfStart-i]
		s2 := bs[afterHarfStart+i]
		bs[beforeHarfStart-i] = s2
		bs[afterHarfStart+i] = s1
	}
}

func extract(s, t string) string {
	// Definition of DP
	//var dp [3001][3001]int
	dp := makeDp(len(s), len(t))

	for i := 0; i < len(s); i++ {
		for j := 0; j < len(t); j++ {
			if s[i] == t[j] {
				dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1)
			}
			dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j])
			dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1])
		}
	}

	var result []byte
	i, j := len(s), len(t)
	for i > 0 && j > 0 {
		if dp[i][j] == dp[i-1][j] {
			// (i-1, j) -> (i, j) と更新されていた場合
			i-- // DP の遷移を遡る
		} else if dp[i][j] == dp[i][j-1] {
			// (i, j-1) -> (i, j) と更新されていた場合
			j-- // DP の遷移を遡る
		} else {
			// (i-1, j-1) -> (i, j) と更新されていた場合
			result = append(result, s[i-1]) // このとき s[i-1] == t[j-1] なので、t[j-1] + res でも OK
			i--                             // DP の遷移を遡る
			j--
		}
	}

	reverse(result)
	return string(result)
}

func main() {
	var s, t string
	fmt.Scan(&s)
	fmt.Scan(&t)

	fmt.Println(extract(s, t))
}


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

int main() {
  // freopen("input.txt", "r", stdin);

  int n, m;
  scanf("%d %d", &n, &m);
  vector<int> p(m), y(m);
  for (int i = 0; i < m; ++i) {
    scanf("%d %d", &p[i], &y[i]);
  }

  vector<vector<int>> a(n, vector<int>(0));
  for (int i = 0; i < m; ++i) {
    a[p[i]-1].push_back(y[i]);
  }

  for (int i = 0; i < n; ++i) {
    sort(a[i].begin(), a[i].end());
  }

  for (int i = 0; i < m; ++i) {
    auto itr = lower_bound(a[p[i]-1].begin(), a[p[i]-1].end(), y[i]);
    printf("%06d%06d\n", p[i], distance(a[p[i]-1].begin(), itr) + 1);
  }
  return 0;
}


Measured memory_bytes: 7808
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <random>
#include <iomanip>
#include <functional>
#include <list>
using namespace std;

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

	int area = a * b - a - b + 1;
	cout << max(area, 0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define debug freopen("input", "r", stdin);freopen("output", "w", stdout)
#define endl '\n'
#define all(var) var.begin(), var.end()
int const MOD = 1e9+7;
typedef unsigned long long ll;
using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> pos(m);
    for(auto &i: pos)
        cin >> i.first >> i.second;


    for(int i = 0; i < 1000; i++){
        string s = to_string(i);
        if(s.size() != n) continue;
        bool ok = true;
        for(auto it: pos){
            if(s[it.first-1]-'0' != it.second){
                ok = false;
                break;
            }
        }
        if(ok) {
            cout << s << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 256
t1, t2 = list(map(int, input().split()))
a1, a2 = list(map(int, input().split()))
b1, b2 = list(map(int, input().split()))

fin_gap = t1 * (a1 - b1) + t2 * (a2 - b2)
mid_gap = t1 * (a1 - b1) 

if fin_gap == 0:
  print("infinity")
else:
  if mid_gap * fin_gap > 0:
    print(0)
  else:
    
    mod = abs(mid_gap) % abs(fin_gap)
    q = abs(mid_gap) // abs(fin_gap)
    
    if mod == 0:
      ans = q * 2
    else:
      ans = q * 2 + 1
    
    print(ans)

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

int main(){
	int n, m, l;
	cin >> n >> m >> l;
	vector<vector<int> > a(n,vector<int>(m));
	vector<vector<int> > b(m,vector<int>(l));
	vector<vector<long> > c(n,vector<long>(l));
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin >> a[i][j];
		}
		for(int k=0;k<l;k++){
			c[i][k] = 0;
		}
	}
	for(int j=0;j<m;j++){
		for(int k=0;k<l;k++){
			cin >> b[j][k];
		}
	}
	for(int i=0;i<n;i++){
		for(int k=0;k<l;k++){
			for(int j=0;j<m;j++){
				c[i][k]+=a[i][j]*b[j][k];
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int k=0;k<l;k++){
			if(!k) cout << c[i][k];
			else cout << " " << c[i][k];
		}
		cout << endl;
	}
	return 0;
}

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

int main(){
  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  if(a == 0){
    cout << 1 << endl;
  }
  else if(b == 0) cout << 2 << endl;
  else if(c == 0) cout << 3 << endl;
  else if(d == 0) cout << 4 << endl;
  else cout << 5 << endl;
  return 0;
}

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

constexpr int64_t INF = 1'010'000'000'000'000'017LL;
constexpr int64_t MOD = 1'000'000'007LL;
constexpr double EPS = 1e-12;
constexpr double PI = 3.14159265358979323846;

#define FOR(i, start, end) for(int64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

// 最小公倍数lcm=m*n/gcd
uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// nCm
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

signed main() {
  uint64_t k;
  string s;
  cin >> k;
  cin >> s;
  
  if(s.length()<=k){
    cout << s << endl;
  }
  else{
    cout << s.substr(0,k) << "..." << endl;
  }
 
  return 0;
}

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

using namespace std;

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

int main(){
    
    int n;
    cin >> n;
    int num, cnt = 0;
    rep(i,n){
        cin >> num;
        while(num % 2 == 0){
            num /= 2;
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

#define ll long long
#define ld long double

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define repA(i,A)   for(auto i:A)

#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define mp make_pair
#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second

#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V> 
#define Vpll vector<pll>

#define endl "\n"

const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265

const ll N = 100005;

ll dp[N];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,k;
    cin>>n>>k;
    dp[k]=1;
    rep(i,0,n){
        ll x;
        cin>>x;
        rep(i,0,k+1){
            if(i-x-1>=0)    dp[i-x-1]=((dp[i-x-1]-dp[i])%M+M)%M;; 
        }
        repb(i,k-1,0)     dp[i] = (dp[i]+dp[i+1])%M;
    }
    cout<<dp[0]%M<<endl;
    return 0;
}

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

using namespace std;

int n,i,j;
long long r,c;

bool check(long long u, long long v){
	return (u == 0 || u == r || v == 0 || v == c);
}

stack <int> b;

int main(){
	scanf("%lld%lld%d", &r, &c, &n);
	
	vector <pair<long long, int> > up,left,down,right;
	for(i = 0; i < n; i++){
		long long x,y,xx,yy;
		
		scanf("%lld%lld%lld%lld", &x, &y, &xx, &yy);
		
		if(check(x, y) && check(xx, yy)){
			if(x == 0)
			up.push_back({y, i});
			else if(y == c)
			left.push_back({x, i});
			else if(x == r)
			down.push_back({y, i});
			else
			right.push_back({x, i});
			
			if(xx == 0)
			up.push_back({yy, i});
			else if(yy == c)
			left.push_back({xx, i});
			else if(xx == r)
			down.push_back({yy, i});
			else
			right.push_back({xx, i});
		}
	}
	
	sort(up.begin(), up.end());
	sort(left.begin(), left.end());
	sort(down.begin(), down.end());
	sort(right.begin(), right.end());
	
	reverse(down.begin(), down.end());
	reverse(right.begin(), right.end());
	
	for(i = 0; i < up.size(); i++){
		if(b.empty() || b.top() != up[i].second)
		b.push(up[i].second);
		else
		b.pop();
	}
	
	for(i = 0; i < left.size(); i++){
		if(b.empty() || b.top() != left[i].second)
		b.push(left[i].second);
		else
		b.pop();
	}
	
	for(i = 0; i < down.size(); i++){
		if(b.empty() || b.top() != down[i].second)
		b.push(down[i].second);
		else
		b.pop();
	}
	
	for(i = 0; i < right.size(); i++){
		if(b.empty() || b.top() != right[i].second)
		b.push(right[i].second);
		else
		b.pop();
	}
	
	if(b.size())
	printf("NO\n");
	else
	printf("YES\n");
	
}


Measured memory_bytes: 4836
def income_inequality():
    n = int(input())
    low_income_num = []
    while n:
        incomes = [int(i) for i in input().split()]
        sum = 0.0
        for i in incomes:
            sum += i
        everage = sum / len(incomes)
        count = 0
        for i in incomes:
            if i <= everage:
                count += 1
        low_income_num.append(count)
        n = int(input())
    for i in low_income_num:
        print(i)

income_inequality()


Measured memory_bytes: 6632
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define ll long long
#define pq priority_queue
#define mp make_pair
#define vl vector<long long>
long long INF = 1e10;
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
/******************************define**********************************/

/*****************************functions********************************/

/****************************main function*****************************/
int main(void){
    string S1,S2,S3; cin >> S1 >> S2 >> S3;
    queue<char> qA,qB,qC;
    for(int i = 0;i < S1.size();i++) qA.push(S1[i]);
    for(int i = 0;i < S2.size();i++) qB.push(S2[i]);
    for(int i = 0;i < S3.size();i++) qC.push(S3[i]);

    char f = qA.front(); qA.pop();
    
    while(true){
        if(f == 'a'){
            if(qA.empty()){
                cout << "A" << endl;
                return 0;
            }
            f = qA.front(); qA.pop();
            
        }else if(f == 'b'){
            if(qB.empty()){
                cout << "B" << endl;
                return 0;
            }
            f = qB.front(); qB.pop();
            
        }else{
            if(qC.empty()){
                cout << "C" << endl;
                return 0;
            }
            f = qC.front(); qC.pop();
            
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
const int mod = (int) 1e9 + 7;
const int maxn = (int) 2e5 + 5;
const ll inf = 1LL << 60;
const double eps = 1e-9;

vector<int> N;

vector<int> to_vi(ll n) {
    vector<int> v;
    while (n > 0) {
        v.pb(n % 10);
        n /= 10;
    }
    return v;
}
vector<int> operator + (vector<int> a, vector<int> b) {
    if(SZ(a) > SZ(b)) swap(a, b);
    while (SZ(a) < SZ(b)) a.pb(0);
    vector<int> c;
    int r = 0;
    rep(i, 0, SZ(a)) {
        c.push_back(a[i] + b[i] + r);
        r = 0;
        if(c.back() > 9) r = 1, c.back() -= 10;
    }
    if(r) c.pb(1);
    return c;
}
vector<int> operator * (vector<int> a, int k) {
    vector<int> b;
    ll r = 0;
    rep(i, 0, SZ(a)) {
        r += k * a[i];
        b.pb(r % 10);
        r /= 10;
    }
    while (r > 0) b.pb(r % 10), r /= 10;
    return b;
}
ostream& operator << (ostream &o, const vector<int> &v) {
    per(i, 0, SZ(v)) o << v[i];
}

bool check(int k) {
    vector<int> M = N * 9;
    M = M + to_vi(k * 9);
    int sum = 0;
    for (auto i : M) sum += i;
    return (sum / 9 <= k);
}

int main() {
//#ifndef ONLINE_JUDGE
//    freopen("test.txt", "r", stdin);
//#endif
    ios_base::sync_with_stdio(0); cin.tie(0);
    string s; cin >> s;
    per(i, 0, SZ(s)) N.pb(s[i] - '0');
    int lo = 0, hi = 1e8, res;
    while (lo <= hi) {
        int md = (lo + hi) >> 1;
        if(check(md)) res = md, hi = md - 1;
        else lo = md + 1;
    }
    cout << res << endl;
}


Measured memory_bytes: 12736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = 0;
			while((n=int.Parse(Console.ReadLine()))!=0)
			{
				var t = new int[n + 1][];
				t[n] = new int[n+1];
				for (int i = 0; i < n; i++)
					t[i] = (Console.ReadLine() + " 0").Split(' ')
						.Select(d => int.Parse(d)).ToArray();
				for (int i = 0; i < n; i++)
				{
					t[i][n] = t[i].Sum();
					t[n][i] = t.Select(a => a[i]).Sum();
				}
				t[n][n] = t[n].Sum();

				for (int i = 0; i <= n; i++)
				{
					for (int j = 0; j <= n; j++)
					{
						Console.Write("{0,5}", t[i][j]);
					}
					Console.WriteLine();
				}
			}
		}
	}
}

Measured memory_bytes: 6184
using System;
using System.Collections.Generic;

class ABC164
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        Dictionary<string, bool> list = new Dictionary<string, bool>();
        for(int i = 0; i < n; i++)
        {
            string s = Console.ReadLine();
            if(!list.ContainsKey(s))
            {
                list.Add(s, true);
            }
        }
        Console.WriteLine($"{list.Count}");
    }
}

Measured memory_bytes: 45508
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;


typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;

#define rep(i,b) for(i=0;i<b;++i)
#define repp(i,a,b) for(i=a;i<b;++i)

int main() {
    ll n;
    cin >> n;
    std::vector<ll> v;
    for(int i =1 ;i <=9; i++){
        for(int j = 1 ;j <= 9; j++){
            v.push_back(i * j);
        }

    }
    bool cnt  = false;
    for(int i = 0;i < v.size(); i++){
        if(v[i] == n) {
            cnt = true;
            break;
        }
    }
    if(cnt ) cout << "Yes";
    else cout << "No";

  return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<int> X(N), Y(N);
    for(int i=0; i<N; i++) cin >> X[i] >> Y[i];

    int cnt = 0;
    string ans = "No";
    for(int i=0; i<N; i++) {
        if(X[i] == Y[i]) cnt++;
        else cnt = 0;
        if(cnt == 3) {
            ans = "Yes";
            break;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3652
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    x, y = map(int, input().split())
    if y & 1:
        print("No")
        return
    print("Yes" if 2 * x <= y <= 4 * x else "No")
resolve()

Measured memory_bytes: 62000
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    n, k = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    H = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    Cost = [float("inf")] * n
    Cost[0] = 0
    for i in range(1, n):
        for j in range(i-k, i):
            if j >= 0:
                costtemp = Cost[j] + abs(H[i] - H[j])
                if Cost[i] > costtemp:
                    Cost[i] = costtemp

    print(Cost[n-1])


resolve()

Measured memory_bytes: 53340
#include<bits/stdc++.h>
using namespace std;
  int n=100005; 


int main()
{
  
string s,t;
cin>>s>>t;
int N=s.length(),M=t.length();
int dp[N+1][M+1]={0};
string ans;
for(int i=0;i<=N;i++)
{
    for(int j=0;j<=M;j++)
    {   if(i==0||j==0)
        {
            dp[i][j]=0;
        }
        
        else if(s[i-1]==t[j-1])
        {
            dp[i][j]+=dp[i-1][j-1]+1;
            //ans.push_back(s[i-1]);
        }
   
        else
        {
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
        
    }
}
//N--,M--;
while(N>0&&M>0)
{
    if(s[N-1]==t[M-1])
    {
        ans.push_back(s[N-1]);
        N--;M--;
    }
    else if(dp[N-1][M]>dp[N][M-1])
    {
        N--;
    }
    else
    {
        M--;
    }
}
reverse(ans.begin(),ans.end());
cout<<ans;

}

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

int main()
{
long long int h;
cin>>h;
int n=log2(h);
long long int a[n+1];
a[0]=1;
for(int i=1;i<=n;i++)
{
    a[i]=1+2*a[i-1];
}
cout<<a[n];
return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int a[100001];
int com[100001],x[100001],y[100001],b[100001];
int B=350;
int n,q;
void put(int a[100001]);
int min(int a,int b);
void update(int i,int x);
void find(int s,int t);
int main(void){
  put(a);
  int i;
  scanf("%d %d",&n,&q);
  for(i=0;i<q;i++){
    scanf("%d %d %d",&com[i],&x[i],&y[i]);
    if(com[i]==0)
      update(x[i],y[i]);
    else if(com[i]==1)
      find(x[i],y[i]);
  }
  return 0;
}
int min(int a,int b){
  if(a<=b)
    return a;
  else
    return b;
}
void update(int i,int x){
  int j;
  a[i]=x;
  b[i/B]=2147483647;
  for(j=i-i%B;j<min(i-i%B+B,n);j++){
    b[i/B]=min(b[i/B],a[j]);
  }
}
void find(int s,int t){
  int ans=2147483647;
  int j;
  for(j=s;j<=t;){
    if(j%B==0 && j+B<=t-1){
      ans=min(ans,b[j/B]);
      j+=B;
    }else{
      ans=min(ans,a[j]);
      j++;
    }
  }
  printf("%d\n",ans);
}
void put(int a[100001]){
  int i;
  for(i=0;i<100001;i++)
    a[i]=2147483647,b[i]=2147483647;
}

Measured memory_bytes: 2552