akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

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

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

ll n,m,num,sum,a,b,c,d,e,f,g,h,i,j,k,w,ok,ng,l,ans,q;
ll x[500005],y[500005],r[500005];
char s[500005],t[500005];
bool flag,dame;

int main(){
    cin >> s;
	n = strlen(s);
	for(i=0;i<n;i++){
		if(s[i] == '0')a++;
		if(s[i] == '1')b++;
	}
	p(min(a,b) * 2);
	

	return 0;
}

Measured memory_bytes: 24192
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    string S,T; cin >> S >> T;
    vector<string> ans;
    if(S.size() < T.size()) cout << "UNRESTORABLE" << endl;
    else {
        for(int i = 0; i <= S.size()-T.size(); i++) {
            string S_ = S;
            int count = 0;
            //cout << S_ << endl;
            for(int j = 0; j < T.size(); j++) {
                if(S_.at(i+j) == '?') S_.at(i+j) = T.at(j);
                else if(S_.at(i+j) != T.at(j)) break;
                count++;
            }
            if(count == T.size()) {
                for(int i = 0; i < S.size(); i++) if(S_.at(i) == '?') S_.at(i) = 'a';
                ans.push_back(S_);
            }
        }
        sort(ans.begin(),ans.end());
        if(ans.size() == 0) cout << "UNRESTORABLE" << endl;
        else cout << ans.at(0) << endl;
    }
}

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

//#include<boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//using Bint = mp::cpp_int;

int main() {
    int64_t k, q;
    cin >> k >> q;
    vector<int64_t> d(k);
    for (int64_t& D : d) {
        cin >> D;
    }
    vector<int64_t> n(q), x(q), m(q);
    for (int64_t i = 0; i < q; i++) {
        cin >> n[i] >> x[i] >> m[i];
    }

    for (int64_t i = 0; i < q; i++) {
        vector<int64_t> copy_d(k);
        for (int64_t j = 0; j < k; j++) {
            copy_d[j] = (d[j] % m[i] == 0 ? m[i] : d[j] % m[i]);
        }

        int64_t sum_d = accumulate(copy_d.begin(), copy_d.end(), (int64_t)0);

        //まずkで割れるところまでは足していく
        int64_t final = x[i] % m[i] + sum_d * ((n[i] - 1) / k);

        //残りを足す
        final += accumulate(copy_d.begin(), copy_d.begin() + (n[i] - 1) % k, (int64_t)0);

        int64_t ans = n[i] - 1 - final / m[i];
        cout << ans << endl;
    }
}

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

vector<int64_t> lc(87, -1);

int main() {
  int64_t x;
  int i;
  cin >> i;
  
  lc.at(0) = 2;
  lc.at(1) = 1;
  for (int j = 2; j <= i; j++) {
    lc.at(j) = lc.at(j -1) + lc.at(j - 2);
  }
  
  printf("%ld\n", lc.at(i));
}

Measured memory_bytes: 256
#![allow(non_snake_case,unused_imports,dead_code)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut buf_it = buf.split_whitespace();

    let N = buf_it.next().unwrap().parse::<usize>().unwrap();
    let A = (0..N).map(|_| buf_it.next().unwrap().parse::<isize>().unwrap()).collect::<Vec<_>>();

    let mut B = A.clone();
    B.sort();
    
    let mut Ae = HashMap::new();
    let mut Ao = HashMap::new();
    let mut Be = HashMap::new();
    let mut Bo = HashMap::new();


    for i in 0..N{
        let a = A[i];
        let b = B[i];
        if i%2==0{
            let n:isize = *Ae.get(&a).unwrap_or(&0);
            let m:isize = *Be.get(&b).unwrap_or(&0);
            Ae.insert(a,n+1);
            Be.insert(b,m+1);
        } else {
            let n:isize = *Ao.get(&a).unwrap_or(&0);
            let m:isize = *Bo.get(&b).unwrap_or(&0);
            Ao.insert(a,n+1);
            Bo.insert(b,m+1);
        }
    }

    let mut ans = 0;
    for (k,v) in Ae.into_iter(){
        let n = *Be.get(&k).unwrap_or(&0);
        ans += (v-n).abs();
    }
    println!("{}",ans);
}


Measured memory_bytes: 17992
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    string n;
    cin >> n;
    int num = 0;
    rep(i,n.size()) {
        num += (n[i] - '0');
        num %= 9;
    }
    if(num%9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3776
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstring>

#ifdef __LOCAL
  #define DBG(X) cout << #X << " = " << (X) << endl;
  #define SAY(X) cout << (X) << endl;
  #include <filesystem>
  namespace fs = std::filesystem;
#else
  #define DBG(X)
  #define SAY(X)
#endif

using namespace std;
using ll = long long int;
using pll = pair<ll, ll>;

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) os << el << " "; return os; }

int N;
vector<vector<ll> > A;

void input(){
  fast_io();
  #ifdef __LOCAL
    fs::path p = __FILE__;
    fs::path input,output;
    input = output = p.parent_path();
    input += string("/input/") + string(p.stem()) + string(".txt");
    output += string("/output/") + string(p.stem()) + string(".txt");
    freopen(input.c_str(), "r", stdin);
    freopen(output.c_str(), "w", stdout);
  #endif
  cin >> N;
  A.assign(N,vector<ll>(N,0));
  for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) cin >> A[i][j];
}

ll Score[1<<16];
ll score_group(int bit){
  if(Score[bit]) return Score[bit];
  ll ret=0;
  for (int j = 0; j < N; j++){
    for (int k = j+1; k < N; k++){
      if((bit>>j)&1 && (bit>>k)&1){
      ret += A[j][k];
      }
    }
  }
  return Score[bit] = ret;  
}

// ll dfs(int bits=0){
//   if(memo[bits]) return memo[bits];
//   if(bits>=(1<<N)-1) return 0;
//   pll ret = {0,(1<<N)-1};
//   vector<pll> v;
//   for (int bit = 0; bit < 1<<N; bit++)
//   {
//     if(bit&bits) continue;
//     ll s = score(bit);
//     if(s>ret.first){
//       ret.first = s;
//       ret.second = bit;
//     }
//   }
//   ll res = ret.first;
//   res += dfs(ret.second);
//   return memo[bits] = res;  
// }

ll memo[1<<16];
ll dfs(ll bit=((1<<N)-1LL)){
  if(memo[bit]) return bit;
  if(bit==0) return memo[bit] = 0;
  if(__builtin_popcount(bit)<=1) return memo[bit] = 0;
  ll ret=0;
  ret = score_group(bit);
  for (ll sub = (bit-1)&bit; sub > 0; sub=(sub-1)&bit)
  {
    ret = max(ret,dfs(sub)+dfs(bit&(~sub)));
  }
  return memo[bit] = ret;  
}


ll dp[1<<16];

void chmax(ll &a, ll b){if(a<b) a=b;}
int solve(){
  memset(dp,0,sizeof(dp));
  memset(memo,0,sizeof(memo));
  memset(Score,0,sizeof(Score));
  for (int bit = 0; bit < 1<<N; bit++)
  {
    score_group(bit);
  }
  for (int use = 0; use < 1<<N; use++)
  {
    int unuse = ((1<<N)-1)&~use;
    for (int sub = unuse; sub > 0; sub=(sub-1)&unuse)
    {
      chmax(dp[use|sub],dp[use]+Score[sub]);
    }
  }
  cout << dp[((1<<N)-1)] << endl;
  // cout << dfs() << endl;
  return 0;
}

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 1792
import collections
N=int(input())
D=list(map(int,input().split()))
l=[]
c=collections.Counter(D)
values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
key=list(c.keys())	#先のvalue値に相当する要素のリスト(要素1,要素2,…)
p=998244353
cnt=1
for i in range(len(key)):
    l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
#print(l)
if (c[0]==1)and(D[0]==0):
    for i in range(N-1):
        cnt=(cnt*pow(c[i],c[i+1],p))%p
    print(cnt%p)
else:
    print("0")

Measured memory_bytes: 76724
program sum_difference
  implicit none
  integer(8) :: n, x, d, t, k
  read(*,*) n, x, d
  if (d == 0) then
    if (x == 0) then
      write(*,'(i0)') 1
    else
      write(*,'(i0)') n+1
    end if
    stop
  else if (x == 0) then
    write(*,'(i0)') n*(n-1)/2+1
    stop
  else if (x < 0) then
    x = -x
    d = -d
  end if
  t = gcd(x,d)
  x = x/t
  d = d/t
  t = (n+1)*(n**2-n+6)/6
  do k = 0, n
    t = t-f(k)
  end do
  write(*,'(i0)') t
contains
  integer(8) function gcd(a,b)
    integer(8), intent(in) :: a, b
    integer(8) :: x, y
    x = max(abs(a),abs(b))
    y = min(abs(a),abs(b))
    do while (y > 0)
      gcd = y
      y = mod(x,y)
      x = gcd
    end do
  end
  integer(8) function f(k)
    integer(8), intent(in) :: k
    integer(8) :: l1, l2, r1, r2
    l1 = k*(n*2-k-1)/2
    l2 = k*(k-1)/2
    r1 = (k+d)*(n*2-k-d-1)/2+x
    r2 = (k+d)*(k+d-1)/2+x
    f = max(min(l1,r1)-max(l2,r2)+1,0)
  end
end program sum_difference

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <iomanip>
using namespace std;


int mathC(int a,int b){

  int i,ans=1;
  if(b>a/2) b=a-b;
  for(i=1;i<=b;i++){
    ans*=(a-i+1);
    ans/=i;
  }
  
  return ans;
}

void solve(void){

long long int N;
cin >> N;
  
  long long int a=0,b=0;
  a=(N/500)*1000;
  N=N%500;
  b=(N/5)*5;
  
  cout << a+b <<endl;
  
  return;
  
return;
}

int main(void){
  
	solve();
	return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <n; (i)++) 
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}

using namespace std;
int main(){
    int n;std::cin >> n;
    std::cout << ((n>=2800)?"AGC":((n>=1200)?"ARC":"ABC")) << std::endl;
    
}




Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <utility>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <set> 
#include <vector>
#include <limits.h>
#include <math.h>

#define ll long long 

using namespace std; 
string n;
int main(void)
{
	cin >> n;
	cout << "ABC" << n << '\n';


	return false;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

int N, M;
vector<unordered_set<int>> to, from;

signed main() {
    cin >> N >> M;

    to.resize(N);
    from.resize(N);

    rep(i, N + M - 1) {
        int A, B;
        cin >> A >> B;
        A--; B--;
        to[A].insert(B);
        from[B].insert(A);
    }

    vector<int> parent(N, -1);
    int root;
    rep(i, N) {
        if (from[i].empty()) {
            root = i;
            parent[i] = 0;
            break;
        }
    }

    queue<int> q;
    q.push(root);
    while (!q.empty()) {
        int now = q.front(); q.pop();
        for (int child : to[now]) {
            from[child].erase(now);
            if (from[child].empty()) {
                q.push(child);
                parent[child] = now + 1;
            }
        }
    }

    for (int num : parent) {
        cout << num << endl;
    }

    return 0;
}


Measured memory_bytes: 25088
# AOJ 0127 Pocket Pager Input
# Python3 2018.6.18 bal4u

a = ['']*100

a[11], a[12], a[13], a[14], a[15] = 'a', 'b', 'c', 'd', 'e'
a[21], a[22], a[23], a[24], a[25] = 'f', 'g', 'h', 'i', 'j'
a[31], a[32], a[33], a[34], a[35] = 'k', 'l', 'm', 'n', 'o'
a[41], a[42], a[43], a[44], a[45] = 'p', 'q', 'r', 's', 't'
a[51], a[52], a[53], a[54], a[55] = 'u', 'v', 'w', 'x', 'y'
a[61], a[62], a[63], a[64], a[65] = 'z', '.', '?', '!', ' '

while True:
	try: buf = list(input())
	except: break
	
	f = True
	ans = ''
	for i in range(0, len(buf), 2):
		if i+1 >= len(buf):
			f = False
			break
		if buf[i].isdigit() and buf[i+1].isdigit():
			k = int(buf[i]+buf[i+1])
			if a[k] != '': ans += a[k]
			else:
				f = False
				break
	print(ans if f else "NA")


Measured memory_bytes: 5608
import heapq

N, M, r = map(int, input().split())
inf = 10 ** 18

def dijkstra(start):
    q = [(0, start)]
    heapq.heapify(q)
    cost = [inf] * N
    cost[start] = 0
    while q:
        c, v = heapq.heappop(q)
        if c > cost[v]:
            continue
        for d, u in G[v]:
            tmp = d + cost[v]
            if tmp < cost[u]:
                cost[u] = tmp
                heapq.heappush(q, (tmp, u))
    return cost

# G = [(cost, edge), ...]
G = [[] for _ in range(N)]
for _ in range(M):
    a, b, t = map(int, input().split())
    # a, b = a - 1, b - 1
    G[a].append((t, b))
    # G[b].append((t, a))

res = dijkstra(r)
for i in res:
    if i == inf:
        print("INF")
        continue
    print(i)



Measured memory_bytes: 89284
/**
       **********    ************
	  Author : Avi J Patel
	  University : DA-IICT
       **********    ************
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair 
#define mt make_tuple
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define Mod 998244353
#define N 200001
#define large 10000000000000001
#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    if(a.second < b.second) return true; 
    else if(a.ss==b.ss) return a.ff<b.ff;
	else return false;
}
bool sortbyboth(const pair<int,int> &a, const pair<int,int> &b)
{
	if(a.first<b.first) return true;
	else if(a.first==b.first) return a.second<b.second;
	else return false;
}
int comp(const void* a, const void* b)  
{ return *(int*)a > *(int*)b ; }  
int ti(int arr[], int n)  
{  
    // Sort the array elements in non-decreasing order  
    qsort(arr, n, sizeof( arr[0] ), comp);  
  
    // Initialize count of triangles  
    int count = 0;  
  
    // Fix the first element. We need to run till n-3  
    // as the other two elements are selected from  
    // arr[i+1...n-1]  
    for (int i = 0; i < n - 2; ++i)  
    {  
        // Initialize index of the rightmost third  
        // element  
        int k = i + 2;  
  
        // Fix the second element  
        for (int j = i + 1; j < n; ++j)  
        {  
            // Find the rightmost element which is  
            // smaller than the sum of two fixed elements  
            // The important thing to note here is, we  
            // use the previous value of k. If value of  
            // arr[i] + arr[j-1] was greater than arr[k],  
            // then arr[i] + arr[j] must be greater than k,  
            // because the array is sorted.  
            while (k < n && arr[i] + arr[j] > arr[k])  
            ++k;  
  
            // Total number of possible triangles that can  
            // be formed with the two fixed elements is  
            // k - j - 1. The two fixed elements are arr[i]  
            // and arr[j]. All elements between arr[j+1]/ to  
            // arr[k-1] can form a triangle with arr[i] and arr[j].  
            // One is subtracted from k because k is incremented  
            // one extra in above while loop.  
            // k will always be greater than j. If j becomes equal  
            // to k, then above loop will increment k, because arr[k]  
            // + arr[i] is always greater than arr[k]  
            if(k > j)  
            count += k - j - 1;  
        }  
    }  
  
    return count;  
}
int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	cout<<ti(a,n);
	return 0;
}















Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;



int main()
{
	int k, a, b;
	scanf("%d%d%d", &k, &a, &b);
	
	for (int i = a ; i <= b ; i++) {
		if (i % k == 0) {
			printf("OK\n");
			return 0;
		}
	}
	printf("NG\n");
	return 0;
}


Measured memory_bytes: 1620
#include <iostream>

int main(void)
{
    int a, b;

    std::cin >> a;
    std::cin >> b;

    if (a < b) {
        std::cout << "a < b" << std::endl;
    } else if (a > b) {
        std::cout << "a > b" << std::endl;
    } else {
        std::cout << "a == b" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+15+7;
ll n,m,l;
string s,t;
ll d[100000],dp[100][100];

int main(){
  cin >> n >> m;
  int ans[3];
  bool flag = false;
  pel(i,m/10000,0){
    pel(j,m/5000,0){
      if(m - i * 10000 - j * 5000 >= 0 && (m - i * 10000 - j * 5000) / 1000 == n-i-j){
        // cout << (m - i * 10000 - j * 5000)/1000 << " "<< n-i-j << endl;
        flag = true;
        ans[0] = i;
        ans[1] = j;
        ans[2] = (m - i * 10000 - j * 5000) / 1000;
        break;
      }
      if(flag)break;
    }
    if(flag)break;
  }
  if(!flag)rep(i,0,3)ans[i] = -1;
  rep(i,0,3)cout << ans[i] << " ";
  puts("");
  return 0;
}

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

void swap(int a, int b, int c[]) {
    int tmp = c[a];
    c[a] = c[b];
    c[b] = tmp; 
}

void print(int a[], int n) {
    for (int i=0; i<n-1; i++) {
        cout << a[i] << " ";
    }
    cout << a[n-1] << endl;
}

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i=0; i<n; i++) {
        cin >> a[i];
    }
    
    print(a, n);
    for (int target=1; target < n; target++ ) {
        int left = target - 1;
        while( left >= 0  && a[left] > a[left+1] ) {
            swap(left, left+1, a);
            left--;
        }
        print(a, n);
    }
}

Measured memory_bytes: 3088
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n+1) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
  
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	b -= b / c + b / d - b / lcm(c,d);
	a--;
	a -= a / c + a / d - a / lcm(c,d);
	cout << b - a << '\n';
	return 0;
}


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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;


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

    queue<char> ss, ts;

    {
        string t;
        for (char c : s) if (c != 'x') t.push_back(c);
        string a = t.substr(0, t.size() / 2),
                b = t.substr((t.size() + 1) / 2);
        reverse(a.begin(), a.end());

        if (a != b) {
            cout << -1 << endl;
            ret();
        }

    }

    string t = s;
    reverse(t.begin(), t.end());
    for (char c : s) ss.push(c);
    for (char c : t) ts.push(c);

    int ans = 0;

    while (!ss.empty() || !ts.empty()) {
        if (ss.empty()) {
            assert(ts.front() == 'x');
            ans++;
            ts.pop();
            continue;
        }
        if (ts.empty()) {
            assert(ss.front() == 'x');
            ans++;
            ss.pop();
            continue;
        }
        if (ss.front() == ts.front()) {
            ss.pop();
            ts.pop();
            continue;
        }
        if (ss.front() == 'x') {
            ss.pop();
            ans++;
            continue;
        }
        if (ts.front() == 'x') {
            ts.pop();
            ans++;
            continue;
        }
        __throw_runtime_error("okasii");
    }

    cout << ans / 2 << endl;

}

Measured memory_bytes: 768
function main(input) {
  input=input.trim();
  const a = parseInt(input.split("")[0], 10);
  const b = parseInt(input.split("")[1], 10);
  const c = parseInt(input.split("")[2], 10);
  var ans=0;
  if(a==1) ans++
  if(b==1) ans++
  if(c==1) ans++
  console.log(ans);


}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));



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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

void solve() {
    int n, m; scanf("%d%d", &n, &m);
    if (n > m) swap(n, m);
    long long ans = 0;
    if (n == 1 && m == 1) {
        ans = 1;
    } else if (n == 1) {
        ans = m-2;
    } else {
        ans = (long long)(n-2)*(m-2);
    }

    printf("%lld", ans);
}

int main() {
    init();
    int t = 1; //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}



Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    nums = [int(i) for i in input()]
    #1なら+,0なら-
    for i in range(1<<3):
        s = nums[0]
        ans = str(nums[0])
        for j in range(3):
            if (i>>j) & 1:
                s += nums[j+1]
                ans += '+' + str(nums[j+1])
            else:
                s -= nums[j+1]
                ans += '-' + str(nums[j+1])
        if s == 7:
            print(ans+'=7')
            return
if __name__ == '__main__':
    main()


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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

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

    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int hour = h2 - h1;
    int Min = m2 - m1;
    Min += hour * 60;
    cout << Min - k << endl;
    
    return 0;
}

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

typedef pair<int,int> P;

vector<int> g[100100];
int dist[3][100100];
int N;

void solve(int s){
    for(int i=0;i<3;i++){
        for(int j=0;j<N;j++){
            dist[i][j]=-1;
        }
    }
    queue<P> que;
    que.push({0,s});
    dist[0][s]=0;
    while(!que.empty()){
        P q=que.front(); que.pop();
        int parity=q.first;
        int u=q.second;
        for(auto v:g[u]){
            if(dist[(parity+1)%3][v]!=-1) continue;
            dist[(parity+1)%3][v]=dist[parity][u]+1;
            que.push({(parity+1)%3,v});
        }
    }
}

int main(){
    int M; cin >> N >> M;
    for(int i=0;i<M;i++){
        int u,v; cin >> u >> v;
        u--;v--;
        g[u].push_back(v);
    }
    int s,t; cin >> s >> t;
    s--;t--;
    solve(s);
    if(dist[0][t]==-1){
        cout << -1 << endl;
    }else{
        cout << dist[0][t]/3 << endl;
    }
}

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

using namespace std;

int main(){
    string str;
    cin >> str;
    if(str.length() >= 6){
        if(str[2] == str[3] && str[4] == str[5]){
            cout << "Yes" << "\n";
        }else{
            cout << "No" << "\n";
        }
    }else{
        cout << "No" << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
    int A[3];
    int tmp;
    for(int i = 0; i < 3; i++)
    {
        cin >> A[i];
    }
    for(int i = 0; i < 3 ; i++)
    {
        for(int j = 2; j > i; j--)
        {
            if(A[j] < A[j - 1])
            {
                tmp = A[j];
                A[j] = A[j - 1];
                A[j - 1] = tmp;
            }
        }
    }
    for(int i = 0; i < 3; i++)
    {
        cout << A[i];
        if(i != 2)
        {
            cout << ' ';
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3092
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<string>
#include<iostream>
using namespace std;
int my_max(int a,int b)
{
	return a>b ? a:b;
}
int my_min(int a,int b)
{
	return a<b ? a:b;
 } 
int main()
{
	string a;
	cin >> a;
	int len=a.length();
	int max=0;
	for(int i=0;i<len;i++)
	{
		int k;
		int min=len;
		for(k=i;k<len&& a[k]==a[i];k++);
		min=my_min(k,len-i);
		max=my_max(min,max);
		i=k-1;
	}
	printf("%d\n",max);
	return 0;
 } 

Measured memory_bytes: 512
// bismillah .....
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define  boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ull unsigned long long
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb2l(x,y,i) cout<<#x<<i<<" "<<x<<" "<<#y<<i<<" "<<y<<endl;

#define fr(i,l,r) for(ll i=l;i<r;i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define mod 998244353
#define ff first
#define ss second
#define pb(x) push_back(x)
#define vll vector<ll>
#define pbp(x,y) push_back(make_pair(x,y))
#define  mat vector<vector<ll>>
 void solve(){
    ll n,m;
     cin>>m>>n;
     ll   ans=0;
     if(n==1 || m==1 ){
        cout<<1;
        return ;
     }
      ll r=n/2+n%2;

      ll c=m/2+m%2;
      ans+=r*c+(n-r)*(m-c);
      cout<<ans;
 }
int main(){
    boost;
    ll t=1;
   // cin>>t;
    while(t--){
        solve();
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var N int

func main() {
	N = nextInt()
	S := nextString()
	div := int(math.Pow10(9) + 7)
	alpha := make([]int, 26)
	for i := 0; i < 26; i++ {
		alpha[i] = 1
	}
	for i := 0; i < N; i++ {
		alpha[int(S[i])-97] += 1
	}
	result := 1
	for i := 0; i < 26; i++ {
		result = result * alpha[i]
		result = result % div
	}
	fmt.Printf("%v", result-1)
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextString() string {
	return nextReader()
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func Min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func MaxIn2Values(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func MinIn4Values(a int, b int, c int, d int) int {
	e := MinIn2Values(a, b)
	f := MinIn2Values(c, d)
	return MinIn2Values(e, f)
}

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


Measured memory_bytes: 896
//dragon->emperor
#include <bits/stdc++.h>

using namespace std;

/*************************************************/

#define mod 1000000007
#define mod2 998244353
const double pi = acos(-1);
#define inf (1ll<<61)-1

#define ll long long
#define ld  long double
#define floop(i,a,n) for(ll i=a;i<n;i++)
#define loopf(i,a,n) for(ll i=n-1;i>=a;i--)
#define space " "
#define TEST(t) ll t; cin>>t; while(t--)
#define r(n) ll n; cin>>n;
#define r1(a,n) ll a[n]; for(ll i=0;i<n;i++) cin>>a[i];
#define p1(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout<<endll;
#define p2(n) cout<<n<<" ";
#define p(n) cout<<n<<endll;

#define endll "\n"
#define pb push_back
#define mp make_pair
#define dec(n) fixed<<setprecision(n)
#define F first
#define S second

#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define reverseall(x) reverse(all(x))

typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef map<ll,ll> mll;

bitset<200000>vis(0);
vector<bool> prime;

void primes(ll n)
{
    prime.resize(n+1);
    prime.assign(n+1,true);
    prime[0]=0;
    prime[1]=0;
    for(ll i=2; i*i<=n; i++)
    {
        if(prime[i])
        {
            for(ll j=(i*i); j<n; j=j+i) prime[j]=false;
        }
    }
}

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

ll gcd(ll x, ll y)
{
    if(x==0) return y;
    return gcd( y%x ,x);
}

ll powM(ll x, ll y, ll m)
{
    ll ans=1, r=1;
    x=x%m;
    while(r>0 && r<=y)
    {
        if(r & y)
        {
            ans=ans*x;
            ans=ans%m;
        }
        r=r<<1;
        x=x*x;
        x=x%m;
    }
    return ans;
}

ll powN(ll a,ll n)
{
    if(n==0) return 1;
    if(n==1) return a;
    ll u=powN(a,n/2);
    u=u*u;
    if(n%2) u=u*a;
    return u;
}

ll modinv(ll a,ll m)
{
    return powM(a,m-2,m);
}

ll ncr(ll n, ll r, ll m)
{
    if(n<r) return 0;
    if(n==r || r==0) return 1;
    if(r==1) return n;
    if(n-r<r) return ncr(n,n-r,m);
    ll a=n;
    ll b=r;
    for(ll i=1; i<r; i++)
    {
        a=(a*(n-i))%m;
        b=(b*(r-i))%m;
    }
    b=modinv(b,m);
    a=(a*b)%m;
    return a;
}

ll countbits(ll n)
{
    ll cot=0;
    while(n)
    {
        cot++;
        n >>= 1;
    }
    return cot;
}

ll check_prime(ll n)
{
    ll ans=1;
    for(ll i=2; i*i<=n; i++)
    {
        if(n%i==0) { ans=0; break;}
    }
    return ans;
}

ll SOD(ll n)
{
    ll sum=0;
    while(n>0)
    {
        sum+=n%10;
        n/=10;
    }
    return sum;
}

ll countsubstring(const string &s, ll n)
{
    ll count=0;
    string ttt="";
    for(ll i=0;i<=n;i++)
    {
        if(s.substr(i,ttt.size())==ttt) count++;
    }
    return count;
}

/*************************************************/
int main()
{    
    fast();
    ll t=1; 
    // cin>> t;
    while(t--)
    {
        ll n; cin>>n;
        ll a[n];
        floop(i,0,n) cin>>a[i];
        ll dp[n+1]={0};
        dp[0]=0;
        dp[1]=0;
        dp[2]=abs(a[1]-a[0]);
        floop(i,3,n+1)
        {
            dp[i]=min(dp[i-1]+abs(a[i-1]-a[i-2]),dp[i-2]+abs(a[i-1]-a[i-3]));
        }
        cout<<dp[n]<<endll;
    }
    return 0;
}

Measured memory_bytes: 5200
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>
#include <random>
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<int,int> pii;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAXN = 2e5+50;
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define f first
#define s second
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define rep0(i,l,r) for(int i=l;i<r;++i
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
 
int main(){
 
   ios::sync_with_stdio(false);
  cin.tie(0);
  int X;
  cin>>X;
  if(X>=30)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//二項係数の計算
int nCr(int A, int B) {
    ll ans = 1;
    for (int i = 0; i < B; i++) {
        ans *= A - i;
    }
    for (int i = 0; i < B; i++) {
        ans /= i + 1;
    }
    return ans;
}
int main() {
    int N;
    cin>>N;
    bool ans=false;
    for(int i=0; i<100; i++){
        for(int j=0; j<100; j++){
            if(i*4+j*7==N){
                ans=true;
                break;
            }
        }
    }
    if(ans==false){
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
    
}


Measured memory_bytes: 3620
N, M = map(int, input().rstrip().split(' '))

stores = []
for _ in range(N):
    stores.append(list(map(int, input().rstrip().split(' '))))
    
stores = sorted(stores, key=lambda x: x[0])

count_purchase = 0
cost = 0
for a, b in stores:
    if count_purchase + b >= M:
        cost += (M - count_purchase) * a
        break
    else:
        cost += a * b
        count_purchase += b

print(cost)

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

int main()
{
  int N;
  cin >> N;
  vector<string> S(N);
  vector<int> T(N);
  int all = 0;
  for (int i = 0; i < N; i++)
  {
    cin >> S[i];
    int t;
    cin >> t;
    T[i] = t;
    all += t;
  }
  string X;
  cin >> X;
  int num = -1;
  for (int i = 0; i < N; i++)
  {
    if (S[i] == X)
    {
      num = i;
      break;
    }
  }
  int sum = 0;
  for (int i = 0; i <= num; i++)
  {
    sum += T[i];
  }
  int ans = all - sum;
  cout << ans << endl;
}


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

const int MOD = 1e9 + 7;

int n;
int a[64], b[64], c[64];
int dp[64][2];

void conv(string &s, int a[])
{
	for (int i = 0; i < n; i++){
		if (s[i] == '?') a[i] = -1;
		else a[i] = s[i] - '0';
	}
}

int calc(int d, int m)
{
	if (d == n) return !m;
	if (~dp[d][m]) return dp[d][m];
	
	int res = 0;
	
	for (int i = !d; i <= 9; i++){
		for (int j = !d; j <= 9; j++){
			for (int k = !d; k <= 9; k++){
				if ((~a[d]) && a[d] != i) continue;
				if ((~b[d]) && b[d] != j) continue;
				if ((~c[d]) && c[d] != k) continue;
				int kk = m * 10 + k;
				if (i + j != kk && i + j + 1 != kk) continue;
				int nm = kk - i - j;
				res = (res + calc(d + 1, nm)) % MOD;
			}
		}
	}
	
	return dp[d][m] = res;
}

int main()
{
	string sa, sb, sc;
	while (cin >> sa >> sb >> sc){
		n = sa.size();
		conv(sa, a);
		conv(sb, b);
		conv(sc, c);
		
		memset(dp, -1, sizeof(dp));
		printf("%d\n", calc(0, 0));
	}
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define INF 1000000007
 
ll f[1000001];
 
ll pow(ll a, ll b, ll MOD)
{
 ll x=1,y=a; 
 while(b > 0)
 	{
 		if(b%2 == 1)
 	{
 		x=(x*y);
 		if(x>MOD) x%=MOD;
 	}
 	y = (y*y);
 	if(y>MOD) y%=MOD; 
 	b /= 2;
 	}
 return x;
}
 

ll InverseEuler(ll n, ll MOD)
{
 return pow(n,MOD-2,MOD);
}
 
ll C(ll n, ll r, ll MOD)
{
 return (f[n]*((InverseEuler(f[r], MOD) * InverseEuler(f[n-r], MOD)) % MOD)) % MOD;
}
 
int main(){
	f[0] = 1;
	for(int i = 1 ; i <= 1000001 ; i++)
		f[i] = (f[i-1]*i)%INF;
	int x,y; cin >> x >> y;
	if((x+y)%3 != 0){
		cout << "0\n";
		return 0;
	}

	int tmp = (x+y)/3;
	int tmp1 = x - tmp;
	if(tmp1 < 0 || tmp1 > tmp){
		cout << "0\n";
		return 0;
	}
 	cout << C(tmp,tmp1,INF) << endl;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
signed main(){
  string ans="Yes";
  vii A(3,vi(3));
  rep(i,0,3){
    rep(j,0,3)
      cin>>A[i][j];
    }
  int A1=A[0][0]-A[0][1],A2=A[0][1]-A[0][2],A3=A[0][0]-A[1][0],A4=A[1][0]-A[2][0];
  rep(i,1,3){
    if(A[i][0]-A[i][1]!=A1){
      ans="No";
      break;
      }
    if(A[i][1]-A[i][2]!=A2){
      ans="No";
      break;
      }
    if(A[0][i]-A[1][i]!=A3){
      ans="No";
      break;
      }
    if(A[1][i]-A[2][i]!=A4){
      ans="No";
      break;
      }
    }
  cout<<ans<<endl;
}



Measured memory_bytes: 256
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, a, b, c = na()
d = [a, b, c]
s = nsn(n)

ans = []
flag = True
for i in range(n):
    x, y = [ord(c) - ord('A') for c in s[i]]
    if d[x] == 0 and d[y] == 0:
        flag = False
        break
    elif d[x] < d[y]:
        ans.append(x)
        d[x] += 1
        d[y] -= 1
    elif d[x] > d[y]:
        ans.append(y)
        d[x] -= 1
        d[y] += 1
    elif d[x] == d[y] and d[x] >= 2:
        ans.append(x)
        d[x] += 1
        d[y] -= 1
    else:
        if i + 1 == n:
            ans.append(x)
        else:
            nx, ny = [ord(c) - ord('A') for c in s[i + 1]]
            if x == nx:
                ans.append(x)
                d[x] += 1
                d[y] -= 1
            elif y == ny:
                ans.append(y)
                d[x] -= 1
                d[y] += 1
            elif x == 1:
                ans.append(x)
                d[x] += 1
                d[y] -= 1
            else:
                ans.append(y)
                d[x] -= 1
                d[y] += 1

if flag:
    print("Yes")
    for i in range(n):
        print(chr(ans[i] + ord('A')))
else:
    print("No")

Measured memory_bytes: 17104
/*Template by hemnath_d(Enlightened by chamow)*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vec vector<ll>
#define pll pair<ll,ll>
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fx first
#define sx second
#define inf 100000000000000
#define minf -100000000000000
#define maxi 100005
vec adj[maxi];
/*Function to add an edge*/
//Undirected graph
void add_edge(ll a,ll b)
{
    adj[a].pb(b);
    adj[b].pb(a);
}
ll mod=1e9+7;
bool visited[maxi]={false};
ll dp[maxi][2];
ll dfs(ll x,int prev,int par)
{
	if(dp[x][prev]!=-1)
		return dp[x][prev];
	ll ans=1;
	for(ll i=0;i<adj[x].size();i++)
	{
		if(adj[x][i]==par)continue;
		if(prev==0)
			ans=ans*dfs(adj[x][i],1,x);
		else
		{
			ans=ans*((dfs(adj[x][i],1,x)+dfs(adj[x][i],0,x))%mod);
		}
		ans=ans%mod;
	}
	dp[x][prev]=ans;
	return ans;
}
int main()
{
    fastread;
    ll n,x,y;
    cin>>n;
    for(ll i=0;i<maxi;i++)
    	dp[i][0]=dp[i][1]=-1;
    for(ll i=0;i<(n-1);i++)
    {
    	cin>>x>>y;
    	add_edge(x,y);
    }
    cout<<(dfs(1,1,0)+dfs(1,0,0))%mod<<endl;
    return 0;
}

Measured memory_bytes: 15616
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
  Scanner in = new Scanner(System.in);
  boolean hasNext = true;
  boolean isF = true;
  while (in.hasNext()) {

	int start = in.nextInt();
	int end = in.nextInt();
	if (start != 0) {
	  if (!isF) {
		System.out.println();
	  } else {
		isF = false;
	  }
	  if (start % 4 != 0) {
		start += (4 - start % 4);
	  }
	  boolean hasUru = false;
	  for (int year = start; year <= end; year = year + 4) {
		boolean isX100 = year % 100 != 0;
		boolean isX400 = year % 400 == 0;
		if (isX400 || isX100) {
		  System.out.println(year);
		  hasUru = true;
		}
	  }
	  if (!hasUru) {
		System.out.println("NA");
	  }
	}
  }
}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
  int H,W,h,w;
  cin>>H>>W>>h>>w;
  int white=H*W;
  white-=h*W+w*(H-h);
  cout<<white<<endl;
  
  
}

Measured memory_bytes: 3604
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <array>

using namespace std;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REPM(i,n,a) for(int i = ((n) - 1); i >= (a); --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
#define FLOAT setprecision(16)
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) {
	return ist >> right.first >> right.second;
}
template <class T, class U>
ostream& operator<<(ostream& ost, pair<T, U>& right) {
	return ost << right.first << ' ' << right.second;
}

#if 1
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

int N;
map<int, bool> M;
int main() {
	cin >> N;
	REP(i, 0, N) {
		int a;
		cin >> a;
		M[a] = !M[a];
	}
	int sum = 0;
	for (auto&& e : M) {
		if (e.second) ++sum;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 4864
s = io.read()
if s:match("^(%w+)keyence$")
  or s:match("^k(%w+)eyence$")
  or s:match("^ke(%w+)yence$")
  or s:match("^key(%w+)ence$")
  or s:match("^keye(%w+)nce$")
  or s:match("^keyen(%w+)ce$")
  or s:match("^keyenc(%w+)e$")
  or s:match("^keyence(%w+)$")
  or s == "keyence" then
  print("YES")
else
  print("NO")
end


Measured memory_bytes: 376
#include<bits/stdc++.h>
#define re register
using namespace std;
string a,b;
int main(){
    cin>>a;b=a;
    reverse(a.begin(),a.end());
    for(re int i=0;i<a.length();i++)
    {
        if(a[i]=='b') a[i]='d';
        else if(a[i]=='d') a[i]='b';
        else if(a[i]=='p') a[i]='q';
        else if(a[i]=='q') a[i]='p';
    }
    if(a==b) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 512
H,W=map(int,input().split())
A = []
hh = H
for y in range(H):
  ain = input()
  if "#" in ain:
    A.append(ain)
  else:
    hh -= 1
d = [ 0 for _ in range(W)]
for x in range(W):
  for y in range(hh):
    if A[y][x] == "#":
      break
  else:
    d[x] = 1
for y in range(hh):
  for x in range(W):
    if d[x] == 0:
        print(A[y][x], end="")
  print("")



Measured memory_bytes: 4468
import sys
input = sys.stdin.readline

import heapq

n, m = map(int, input().split())
a = []
for _ in range(n):
	a.append(list(map(int, input().split())))
a.sort()
a.append([m+1, 0])

h = []
ptrA = 0
ans = 0
for i in range(m):
	while a[ptrA][0] <= i + 1:
		heapq.heappush(h, a[ptrA][1] * (-1))
		ptrA += 1
	if len(h) > 0:
		ans += heapq.heappop(h)
print(-ans)


Measured memory_bytes: 68060