akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))

res = 0
for i in range(N - 1):
  if a[i] == i + 1:
    res += 1
    a[i], a[i + 1] = a[i + 1], a[i]
if a[-1] == N:
  res += 1
print(res)

Measured memory_bytes: 52892
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
3 5
0 0 1
0 1 2
0 2 3
1 0 2
1 1 2

output:
1
2
"""

import math
import sys

INIT_MAX = pow(2, 31) - 1


class RMQ(object):
    __slots__ = ('queries', 'ext_heap_length', 'dat')

    def __init__(self, in_data):
        """
        Init a SegmentTree with update and find for range minimum queries.
        """
        n_num, q_num = map(int, in_data[0].split())
        self.queries = map(lambda x: x.split(), in_data[1:])
        self.ext_heap_length = pow(2, math.ceil(math.log2(n_num)))
        self.dat = [INIT_MAX] * (2 * self.ext_heap_length - 1)

    # let A[k]=a
    def update(self, k, a):
        k += self.ext_heap_length - 1
        self.dat[k] = a
        while k > 0:
            k = (k - 1) // 2
            self.dat[k] = min(self.dat[k * 2 + 1], self.dat[k * 2 + 2])

    # get min(A[s] A[s+1] ... A[t])
    def find(self, s, t, k=0, left=0, right=float('inf')):
        if right <= s or t <= left:
            return INIT_MAX
        elif s <= left <= right <= t:
            return self.dat[k]
        else:
            vl = self.find(s, t, k * 2 + 1, left, (left + right) // 2)
            vr = self.find(s, t, k * 2 + 2, (left + right) // 2, right)
            return min(vl, vr)

    def cmd_exec(self):
        for query in self.queries:
            cmd, ele_1, ele_2 = map(int, query)
            if cmd == 0:
                self.update(ele_1, ele_2)
            elif cmd == 1:
                # assert ele_1 <= ele_2
                res = self.find(s=ele_1, t=ele_2 + 1, right=self.ext_heap_length)
                print(res)

        return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    case = RMQ(in_data=_input)
    case.cmd_exec()

Measured memory_bytes: 19760
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,m,k;
cin>>n>>m>>k;
int a[n],b[m];
vector<long long> sma(n),smb(m);
int ans=0;

for(int i=0;i<n;i++)
{cin>>a[i];
if(i==0)
sma[i]=a[i];
else sma[i]=sma[i-1]+a[i];
if(sma[i]<=k)
ans=max(ans,i+1);
}
for(int i=0;i<m;i++)
{cin>>b[i];
if(i==0)
smb[i]=b[i];
else smb[i]=smb[i-1]+b[i];
if(smb[i]<=k)
ans=max(ans,i+1);
}
for(int i=0;i<n;i++)
{
    if(k-sma[i]>0){
       // cout<<k-sma[i]<<endl;
    int ind=upper_bound(smb.begin(),smb.end(),k-sma[i])-smb.begin();
      ind--;
    
     if(ind>=0&&k-sma[i]>=smb[ind])
    {
   // cout<<i<<" "<<ind<<endl;

        ans=max(i+ind+2,ans);
    }}
}
cout<<ans;
return 0;

}


Measured memory_bytes: 7992
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod

#include <bits/stdc++.h>
using namespace std;
signed main(){
    int N; cin>>N;
    vec S(N);
  int M = 0, L = INF; 
  	REP(i,N){
      cin>>S[i];
      M = max(M,S[i]);
      L = min(L,S[i]);
    }
  Out(M-L);
}


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

int main() {
    string sssss;
    int K;

    cin >> K;
    cin >> sssss;

    if (sssss.length() > K) {
        for (int i = 0; i < K; i++) {
            cout << sssss[i];
        }
        cout << "...";
    } else {
        cout << sssss;
    }

    return 0;
}

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

using namespace std;

#define int long long

typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define DEL(v, n) v.erase(v.begin() + (n))
typedef pair<int, int> p;

vector<p> seiza;
vector<p> hoshi;

bool exist(p nn)
{
    REP(i, hoshi.size())
    {
        if(hoshi[i] == nn)
        {
            return true;
        }
    }
    return false;
}

signed main()
{
    while(true)
    {
        seiza.clear();
        hoshi.clear();
        int m;
        cin >> m;
        if(m == 0) break;
        int x0, y0;
        cin >> x0 >> y0;
        FOR(i, 1, m)
        {
            int x,y;
            cin >> x >> y;
            seiza.push_back({x - x0, y - y0});
        }
        int N;
        cin >> N;
        REP(i, N)
        {
            int x,y;
            cin >> x >> y;
            hoshi.push_back({x, y}); 
        }
        REP(i, hoshi.size())
        {
            bool can = true;
            REP(h, seiza.size())
            {
                if(
                    !exist(
                    {hoshi[i].first + seiza[h].first,
                    hoshi[i].second + seiza[h].second}
                    )
                )
                {
                    can = false;
                    break;
                }
            }
            if(can)
            {
                cout << (hoshi[i].first - x0) << " " <<
                (hoshi[i].second - y0) << endl; 
                break;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3016
n, k = list(map(int,input().split()))
a = list(map(int,input().split()))
steps =[-1 for _ in range(n)]
loop = 0
step = 0
idx = 0
while True:
    if steps[idx]>=0:
        loop = steps[idx] #閉路の始まりの場所までの距離
        step -= 1
        break
    steps[idx] = step
    step += 1
    idx = a[idx] -1
    # print(steps)
p=0
if loop <= k:
    k-=loop
    p = loop
    x = step-loop + 1
    k = k%x
ans = 0
# print(k,p)
for i in range(n):
    if steps[i] == k+p:
        ans = i

print(ans+1)
# print(steps)
# print(loop,step,k,ans,a[ans])


Measured memory_bytes: 32024
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    ll N,K;
    cin >> N >> K;

    if (K % 2 == 0) {
        ll a = N / K;
        ll b = (N + (K/2)) / K;
        cout << a*a*a + b*b*b << endl;
    } else {
        ll a = N/K;
        cout << a*a*a << endl;
    }


    return 0;
}


Measured memory_bytes: 256
import math
from collections import defaultdict,deque
from itertools import permutations
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

t=1
#t=ii()
for _ in range(t):
    n=ii()
    ans=0
    a=ll()
    #a.sort()
    for i in range(n):
        for j in range(i+1,n):
            for k in range(j+1,n):
                if((a[i]+a[j])>a[k] and (a[i]+a[k])>a[j] and (a[j]+a[k])>a[i] and a[i]!=a[j] and a[j]!=a[k] and a[i]!=a[k]) :
                    ans+=1
    print(ans)                
            

Measured memory_bytes: 68616
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}



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

    int ans[55555];
    for(int i=0;i<5555;i++){
        ans[i] = 0;
    }

    int i = 0;
    int count = 0;
    int tmp_sum = 0;

    while(i<=55555){
        i++;
        if(IsPrime(i) && i % 5 == 1){
            ans[count] = i;
            count++;
            if(count == N){
                for(int j=0;j<N-1;j++){
                    cout << ans[j] << ' ' << endl;
                }
                cout << i << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<map>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

int main(){
  int n;
  while(cin>>n){
    int i = 1;
    bool f = true;
    while(i != 1024){
      if((n&i)!=0){
	if(f) f=false;
	else printf(" ");
	printf("%d",i);
      }
      i <<= 1;
    }
    puts("");
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

vector<int> m;
int dfs(int i, int n){
    if(m[i] == 1 || n == 0)return n;
    int cnt = n / m[i];
    int mn = 1001001001;
    rep(j, min(cnt + 1, 3)){
        mn = min(mn, dfs(i + 1, n%m[i] + m[i]*j) + cnt - j);
    }
    return mn;
}

int main() {
    int n;
    cin >> n;
    m.push_back(1);
    int s = 6;
    while(s <= n){
        m.push_back(s);
        s *= 6;
    }
    s = 9;
    while(s <= n){
        m.push_back(s);
        s *= 9;
    }
    sort(m.begin(), m.end(), greater<int>());

    int ans = dfs(0, n);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vec>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll a,b;
  cin >> a >> b;
  cout << max(a+b,max(a-b,a*b)) << endl;

}

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

#define int long long

template<class T> istream& operator>>(istream &is,vector<T> &st){
  for(size_t i=0;i<st.size();++i) is >> st[i];
  return is;
}
template<class T> ostream& operator<<(ostream &os, const vector<T> &st){
  for(size_t i=0;i<st.size();++i){
    if(i==st.size()-1) os << st[i];
    else os << st[i] << " ";
  }
  return os;
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N;
    cin >> N;
    vector<int> A(N + 1);
    vector<int> B(N);
    cin >> A;
    cin >> B;
    int ans = 0;
    for (int i = 0; i < N; i ++) {
        int diff = B[i] - A[i];
        if (diff < 0) {
            ans += B[i];
            continue;
        }
        ans += A[i];
        int diff1 = A[i + 1] - diff;
        if (diff1 < 0) {
            ans += A[i + 1];
            A[i + 1] = 0;
            continue;
        }
        A[i + 1] = diff1;
        ans += diff;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(auto i = (N) - 1; i >= 0; i -= 1)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it!= v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define rand mtrand
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cout << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,...) do { cout << #v << " = "; array_out(v , ##__VA_ARGS__);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
#endif
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = 0x1FFFFFFFFFFFFFFFLL;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >> (istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}

random_device seed_gen; mt19937_64 mtrand(seed_gen());
#define MOD 1000000007
//////////////////////////////////////////

int main(){
  ins(S);
  string T = "CODEFESTIVAL2016";
  int ans = 0;
  rep(i,16){
    if(S[i] != T[i]) ans++;
  }
  out(ans);
}

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

int main() {
    double T, X;
    cin >> T >> X;
    printf("%.10f\n", T/X);
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int list[10],i,j,temp;
	for(i=0;i<10;i++)
	{
    	scanf("%d",&list[i]);
	}
	for(i=0;i<10;i++)
	{
		for(j=i+1;j<10;j++)
		{
			if(list[i]>list[j])
			{
				temp=list[i];
				list[i]=list[j];
                list[j]=temp;
			}	
		}
        
	}
	printf("%d\n",list[9]);
	printf("%d\n",list[8]);
    printf("%d\n",list[7]);
	return 0;
}

Measured memory_bytes: 600
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] array= new int[n];
        for (int i = 0; i < n; i++){
            array[i] =  Integer.parseInt(br.readLine());
        }
        int minv = array[0];
        int maxv = Integer.MIN_VALUE;
        for (int j = 1; j < n; j++){
            maxv = max(maxv, array[j] - minv);
            minv = min(minv, array[j]);
        }
        System.out.println(maxv);
    }
    static int max(int a, int b){
        if (a > b){
            return a;
        }else{
            return b;
        }
    }
    static int min(int a, int b){
        if (a > b){
            return b;
        }else{
            return a;
        }
    }
}

Measured memory_bytes: 37612
n=int(input())
a=[int(i) for i in input().split()]
a=[a[i]-(i+1) for i in range(n)]
a.sort()
if n%2==0:
    print(sum(a[n//2:])-sum(a[0:n//2]))
else:
    print(sum(a[n//2+1:])-sum(a[0:n//2]))


Measured memory_bytes: 100436
// C - Grid Repainting 2
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)
using VS = vector<string>;

bool solve(int H, int W, VS &S){
	vi dy{-1,1,0,0}, dx{0,0,-1,1};//{U,D,L,R}
	rpz(h, H) rpz(w, W){
		if(S[h][w]=='.') continue;
		int d;
		for(d=0; d<4; ++d){
			int y = h + dy[d], x = w + dx[d];
			if(y<0 || x<0 || y>H-1 || x>W-1) continue;
			if(S[y][x]!='.') break;
		}
		if(d >= 4) return false;
	}
	return true;
}

int main(){
	int H,W; cin>>H>>W;
	VS S(H); rpz(i, H) cin>>S[i];
	cout<< (solve(H,W,S)?"Yes":"No") <<endl;
}

Measured memory_bytes: 256
// 6/30 解き直し
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    priority_queue<int> q;
    rep(i, N) q.push(A[i]);

    while (M--) {
        int p = q.top();
        q.pop();
        q.push(p/2);
    }

    ll res = 0;
    while (!q.empty()) {
        res += q.top();
        q.pop();
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4284
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
#define printd(x) printf("%.12f\n", ans);
#define Yes() cout << "Yes" << endl;
#define No() cout << "No" << endl;
#define YES() cout << "YES" << endl;
#define NO() cout << "NO" << endl;
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;

int main(void) {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    ll ans = 1e9 + 7;

    for (int i = 0; i <= 200003; i += 2) {
        ll tmp = 0;
        tmp = i * c + max(0, (x - i / 2) * a) + max(0, (y - i / 2) * b);
        chmin(ans, tmp);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
        "fmt"
)

func solution(x int) []int {
        for a := -118; a <= 119; a++ {
                for b := -119; b <= 118; b++ {
                        if a*a*a*a*a-b*b*b*b*b == x {
                                return []int{a, b}
                        }
                }
        }
        return []int{}
}

func main() {
        var x int
        fmt.Scan(&x)
        ans := solution(x)
        fmt.Printf("%d %d\n", ans[0], ans[1])
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>


int main(){
  int N; cin>>N;
  int a[N+1];
  for(int i=1;i<=N;++i){
    cin >> a[i];
  }
  int count = 0;
  for(int i=1;i<=N;++i){
    if(a[i]==i){
      if(i<N){ swap(a[i],a[i+1]); ++count;}
      else{ swap(a[i],a[i-1]); ++count; }
    }
  }
  cout << count << "\n";
}

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

int main()
{
    /*
    int a,b;
    cin>>a>>b;
    int count=a;
    int sockets = 1;
    if(b==1)
    {
        cout<<0<<endl;
        return 0;
    }
    if(a<b)
    {
        while(count<b)
        {
            count+=(a-1);
            sockets++;
        }
    }
    else
    {
        cout<<1<<endl;
        return 0;
    }  
    
    cout<<sockets<<endl;
    */
    /*
    int n;
    cin>>n;
    vector <int> x(n);
    rep(i,n)
    {
        cin>>x[i];
    }

    int ans = 1001001001;
    for (int p = 1; p <= 100; ++p) {
        int now = 0;
        rep(i,n) now += (x[i]-p)*(x[i]-p);
        ans = min(ans, now);
    }
    cout << ans << endl;
    */

    int n,A,B;
    cin>>n>>A>>B;
    string s;
    cin>>s;
    int pass = 0;
    int passb = 0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='a')
        {
            if(pass<A+B)
            {
                cout<<"Yes"<<endl;
                pass++;
            }
            else
            {
                cout<<"No"<<endl;
            }
        }
        else if(s[i]=='b')
        {
            if(passb<B && pass<A+B)
            {
                cout<<"Yes"<<endl;
                pass++;
                passb++;
            }
            else
            {
                cout<<"No"<<endl;
            }
        }
        else
        {
            cout<<"No"<<endl;
        }
    }

    return 0;
}

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

int res[100005],n;
string s;

int main(){
	cin>>n>>s;
	for(int i=0;i<2;i++)
		for(int j=0;j<2;j++){
			res[0]=i;
			res[1]=j;
			bool flag=true;
			for(int k=2;k<n;k++) 
				res[k]=(s[k-1]!='o')^res[k-1]^res[k-2];
			for(int k=0;k<n;k++){
				int a=(k-1+n)%n,b=(k+1+n)%n;
				if(res[k]^(s[k]=='o')!=(res[a]==res[b])) flag=false;
			}	
			if(flag){
				for(int i=0;i<n;i++) cout<<(res[i]?'W':'S');
				return 0;
			}
		}
	cout<<-1;
	return 0;
}

Measured memory_bytes: 896
#include<cstdio>

int n,m,q,a[510][510],b[510][510],f[510][510];

int main()
{
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1; i<=m; i++)
	{
		int l,r;
		scanf("%d %d",&l,&r);
		a[l][r]++;
	}
	for(int i=1; i<=n; i++)
	{
		b[i][i]=a[i][i];
		for(int j=i-1; j; j--)
		{
			b[j][i]=b[j+1][i]+a[j][i];
		}
	}
	for(int i=1; i<=n; i++)
	{
		f[i][i]=a[i][i];
		for(int j=i+1; j<=n; j++)
		{
			f[i][j]=f[i][j-1]+b[i][j];
		}
	}
	while(q--)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		printf("%d\n",f[l][r]);
	}
	return 0;
}

Measured memory_bytes: 3840
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


def combinations_count(n, r):
    if n < r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def main():
    n, k = map(int, input().split())

    for i in range(1, k+1):
        print((combinations_count(k-1, i-1) *
               combinations_count(n-k+1, i)) % (1000000007))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6696
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            //var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
            string s = Console.ReadLine();
            string ans = "No";
            if (s.Contains("a") && s.Contains("b") && s.Contains("c"))
            {
                ans = "Yes";
            }
            Console.WriteLine(ans);

            //Console.Out.Flush();
            
        }
    }



    public class Calculation
    {

    }

    public class Graph
    {

    }
}
// aa b ba a
// a b a 

Measured memory_bytes: 13140
N = int(input())
LA = list(map(int, input().split()))
LB = list(map(int, input().split()))
LC = list(map(int, input().split()))

SFB = sum(LB)
SFC = 0

for i in range(1, N):
    j = i - 1
    if LA[i] == (LA[j] + 1):
        A = LA[i] - 2
        SFC += LC[A]

print(SFB + SFC)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a <= c && c <= b) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

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

    vector <vector <ll>> ab(n,vector <ll> (2));

    rep(i,n){
        cin >> ab[i][0] >> ab[i][1];
    }

    sort(ab.begin(),ab.end());
    ll k=0,ans=0,j=0;

    while(k<m){
        k+=ab[j][1];
        if(k>m){
            ans+=ab[j][0]*(ab[j][1]-(k-m));
        }
        else{
            ans+=ab[j][0]*ab[j][1];
        }
        ++j;
    }

    cout << ans << endl;

    

    return 0;
}

Measured memory_bytes: 8804
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define REP(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define TF(flag) (flag)?1:0
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================

int main(void){
  int N; cin>>N;
  vec<int> A(N); cin>>A;
  sort(all(A));
  vec<int> Ac;
  unique_copy(all(A),back_inserter(Ac));
  int ans=N-(N-Ac.size())-(N-Ac.size())%2;
  cout<<ans<<endl;
}














Measured memory_bytes: 1276
#include<iostream>
#include<cstdio>
using namespace std;
#define rep(i, n) for(i = 0;i < n;++i)

void change(int a[4], int n){
  int tmp = a[0], i;
  rep(i, n - 1)a[i] = a[i + 1];
  a[i] = tmp;
  return;
}

int f(int l, int c, int r){
  if(c == 0)return l + r;
  if(c == 1)return l - r;
  return l * r;
}

signed main(void){
  int a[4], i[3], j[3];
  string s = "+-*";
  for(;;){
    rep(i[0], 4)scanf("%d", &a[i[0]]);
    if(!(a[0] | a[1] | a[2] | a[3]))break;
    bool fl = false;
    rep(i[0], 4){rep(i[1], 3){rep(i[2], 2){
      rep(j[0], 3)rep(j[1], 3)rep(j[2], 3)
      if(f(f(f(a[0], j[0], a[1]), j[1], a[2]), j[2], a[3]) == 10){
        fl = true;
        printf("(((%d %c %d) %c %d) %c %d)\n", a[0], s[j[0]], a[1], s[j[1]], a[2], s[j[2]], a[3]);
        i[0] = 4; i[1] = 3; i[2] = 2; j[0] = 3; j[1] = 3; j[2] = 3;
      }else if(f(f(a[0], j[0], a[1]), j[1], f(a[2], j[2], a[3])) == 10){
        fl = true;
        printf("((%d %c %d) %c (%d %c %d))\n", a[0], s[j[0]], a[1], s[j[1]], a[2], s[j[2]], a[3]);
        i[0] = 4; i[1] = 3; i[2] = 2; j[0] = 3; j[1] = 3; j[2] = 3;
      }
      change(a, 2);}change(a, 3);}change(a, 4);
    }
    if(!fl)cout << 0 << endl;
  }

  return 0;
}

Measured memory_bytes: 1252
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB_lst = [0] * (N+1)
for i in range(N+1): AB_lst[i] = []
for i in range(M):
    A, B = map(int, input().split())
    AB_lst[A].append(B)
    AB_lst[B].append(A)
# print(AB_lst)
ans = 0
for i in range(1, N+1):
    flug = True
    for j in AB_lst[i]:
        if not (H[i-1] > H[j-1]):
            flug = False
    if flug:
        ans += 1
print(ans)


Measured memory_bytes: 92520
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    string s;
    cin>>s;
    int len=s.length(),cnt_g=0,cnt_k=0;
    for(int i=0;i<len;i++){
        if(i%2==0){
            if(s[i]=='R'||s[i]=='U'||s[i]=='D') cnt_k++;
        }else{
            if(s[i]=='L'||s[i]=='U'||s[i]=='D') cnt_g++;    
        }
    }
    if(cnt_k+cnt_g==len) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main(void){
int n,a=0,b=0,c=0,d=0,e=0;
int m[15]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
int p[15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
cin>>n;
    for(int i=0;2*m[i]<=n;i++){
        for(int j=m[i];n>j;j=j*m[i]){
            p[i]=p[i]+n/j;
        }
        if(p[i]>=74){
            a++;};
        if(p[i]>=24){
            b++;};
        if(p[i]>=14){
            c++;};
        if(p[i]>=4){
            d++;};
        if(p[i]>=2){
            e++;};
    };
    cout<<a+b*(e-1)+c*(d-1)+d*(d-1)*(e-2)/2;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a>b){
		printf("%d\n",a+(a-1));
	}
	if(b>a){
		printf("%d\n",b+(b-1));
	}
	if(a==b){
		printf("%d\n",a*2);
	}
	return 0;
}

Measured memory_bytes: 1732
#include <iostream>
//#include <string>
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string x,y;
  cin>>x>>y;
  int c=0;
  for(int i=0;i<3;i++)
  {
    if(x[i]==y[i])
      c++;
	 }
  cout<<c;
  return 0;
}

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

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

using namespace std;

template<class M>
class segment_tree{
	int sz;
	vector<M> seg;
public:
	segment_tree(){}
	segment_tree(int n){ build(n); }
	template<class T>
	segment_tree(const vector<T>& a){ build(a); }
	void build(int n){
		for(sz=1;sz<n;sz<<=1);
		seg.assign(2*sz,M());
	}
	template<class T>
	void build(const vector<T>& a){
		int n=a.size();
		build(n);
		rep(i,n) seg[sz+i]=a[i];
		for(int i=sz-1;i>0;i--){
			seg[i]=seg[2*i]*seg[2*i+1];
		}
	}
	const M& operator[](int i)const{
		return seg[sz+i];
	}
	void update(int i,const M& x){
		i+=sz;
		seg[i]=x;
		for(i>>=1;i>0;i>>=1) seg[i]=seg[2*i]*seg[2*i+1];
	}
	M get(int l,int r)const{
		M lcum,rcum;
		for(int a=l+sz,b=r+sz;a<b;a>>=1,b>>=1){
			if(a&1) lcum=lcum*seg[a++];
			if(b&1) rcum=seg[--b]*rcum;
		}
		return lcum*rcum;
	}
};

template<class T>
class max_monoid{
	T a;
public:
	max_monoid():a(numeric_limits<T>::min()){}
	max_monoid(const T& val):a(val){}
	max_monoid operator*(const max_monoid& x)const{
		return max(a,x.a);
	}
	T& get(){ return a; }
	const T& get()const{ return a; }
};

int main(){
	int n,k; scanf("%d%d",&n,&k);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	segment_tree<max_monoid<int>> S(300001);
	rep(i,n){
		int l=max(a[i]-k,0);
		int r=min(a[i]+k,300000)+1;
		S.update(a[i],max(S.get(l,r).get(),0)+1);
	}
	printf("%d\n",S.get(0,300001).get());

	return 0;
}


Measured memory_bytes: 8560
#include<bits/stdc++.h>
using namespace std;
bool cmp(int x,int y){
	return x>y;	
}

void move_one(char *s,int n)
{
	char t = s[0];
	for(int i=1; i<n; ++i)
		s[i-1] = s[i];
	s[n-1] = t;
}

bool Equal(char *a,char *b)
{
	int length=strlen(a);
	for(int i=0; i<length; i++){
		if(a[i] != b[i])return false; 
	}	
	return true;
}
int main(){
	char S[1010],T[1010];
	cin>>S>>T;
	int l = strlen(S);
	for(int i=0; i<l; ++i){
		if(Equal(S,T)){
			cout<<"Yes"<<endl;
			return 0;
		}
		else move_one(S,l);
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX 1000000
#define MOD 1e9
#define pb push_back
#define pairs pair<int, int>
#define vi vector<int>
#define vb vector<bool>
#define vii vector<pairs>
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define endl '\n'
using namespace std;
/* ----------------------------------------------------------------------------------- */

#define FastInput ios_base::sync_with_stdio(false), cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define read(x) freopen(x, "r", stdin)
#define write(x) freopen(x, "w", stdout)
#define rep(i, a, n) for (int i = a; i < n; i++)
#define REP(i, a, n) for (int i = a; i <= n; i++)
#define inputArray(a,n) rep(i, 0, n) cin >> a[i];
#define copyArray(a,temp,n) rep(i, 0, n) temp[i]=a[i];
#define printArray(a,n) rep(i, 0, n) cout << a[i] << " "; cout << endl;

/* ----------------------------------------------------------------------------------- */

#define Cases  cout << "Case " << ++Case << ": ";
#define __test int tt; int Case=0; cin >> tt; while(tt--)

#define dbgA2(A, n, m) {cout<<"--> "<<#A<<" = \n";rep(i, 0, n){rep(j, 0, n){cout<<A[i][j]<<" ";}cout<<"\n";}cout<<"\n";}
#define dbgA(A, n) {cout<<" --> "<<#A<<" = (";rep(i, 0, n)cout<<A[i]<<" ";cout<<")\n";}
#define dbg(args...) {string sss(#args);sss+=',';cout<<" --> ";debugger::call(all(sss), args);cout<<"\n";}

/* ----------------------------------------------------------------------------------- */

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }

struct debugger {
	typedef string::iterator si;
	static void call(si it, si ed) {}
	template<typename T, typename ... aT>
	static void call(si it, si ed, T a, aT... rest) {
		string b;
		for(; *it!=','; ++it)
			if(*it!=' ')
				b+=*it;
		cout << b << "=" << a << " ";
		call(++it, ed, rest...);
	}
};
  
/* ----------------------------------------------------------------------------------- */



void solve() {
	ll n, a, b;
	cin >> n >> a >> b;
	cout << ((n / (a + b)) * a) + min(n % (a + b), a) << endl;
}


int main() {
	solve();

	// __test {
	// 	solve();
	// }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
struct edge { int to, cost; };
typedef pair<int, int> P;
int V;
vector<edge> G[10];
int d[10];
int INF = 1000000000;

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d, d+V, INF);
  d[s] = 0;
  que.push(P(0,s));
  while (!que.empty()){
    P p = que.top(); que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for( int i=0; i<G[v].size(); i++){
      edge e = G[v][i];
      if ( d[e.to] > d[v] + e.cost){
        //cout << "e.to " << e.to << " e.cost " << e.cost << endl;
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main(){
  int h,w; cin >> h >> w;
  V = 10;
  for(int i=0; i<10; i++){
    for(int j=0; j<10; j++){
      //if(i==j){int tmp; cin >> tmp; continue;}
      int tmp; cin >> tmp;
      edge e;
      e.to = j;
      e.cost = tmp;
      G[i].push_back(e);
    }
  }
  //dijkstra(8);
  //for(int i=0; i<10; i++){
    //cout << d[i] << endl;
  //}
  int ans[10];
  for(int i=0; i<10; i++){
    dijkstra(i);
    ans[i] = d[1];
  }
  long long answer=0;
  vector<int> bkt(10, 0);
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      int tmp; cin >> tmp;
      if(tmp!=-1){
        answer += ans[tmp];
      }
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
def resolve():
    N,M=map(int,input().split())
    Y = [list(map(int,input().split()))+[0] for i in range(M)]
    Y2 = sorted(Y)
    index=0
    for i in Y2:
        if i[0]!=index:
            x=1
        else:
            x+=1
        index=i[0]
        i[2] = x
    for i in Y:
        print(str(i[0]).zfill(6)+str(i[2]).zfill(6))
resolve()

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

ll solve() {
    ll N, sa = 0, za = 0;
    cin >> N;
    vector<ll> A(3);
    for ( int i = 0; i < 3; i++ ) {
        cin >> A[i];
        sa += A[i];
        if ( A[i] == 0 ) za++;
    }
    string s;
    vector<vector<int>> S(N, vector<int>(2));
    for ( int i = 0; i < N; i++ ) {
        cin >> s;
        S[i][0] = s[0] - 'A'; 
        S[i][1] = s[1] - 'A'; 
    }
    vector<char> ans;
    bool ng = false;
    if ( sa != 2 ) {
        for ( int i = 0; i < N; i++ ) {
            int s1 = S[i][0], s2 = S[i][1];
            if ( A[s1] >= A[s2] ) {
                A[s1]--;
                A[s2]++;
                if ( A[s1] < 0 ) {
                    ng = true;
                    break;
                }
                ans.push_back('A'+s2);
            } else {
                A[s2]--;
                A[s1]++;
                if ( A[s2] < 0 ) {
                    ng = true;
                    break;
                }
                ans.push_back('A'+s1);
            }
        }
    } else {
        for ( int i = 0; i < N; i++ ) {
            int s1 = S[i][0], s2 = S[i][1];
            if ( !(A[s1] == 1 && A[s2] == 1) || i == N-1) {
                if ( A[s1] >= A[s2] ) {
                    A[s1]--;
                    A[s2]++;
                    if ( A[s1] < 0 ) {
                        ng = true;
                        break;
                    }
                    ans.push_back('A'+s2);
                } else {
                    A[s2]--;
                    A[s1]++;
                    if ( A[s2] < 0 ) {
                        ng = true;
                        break;
                    }
                    ans.push_back('A'+s1);
                }
            } else {
                int ns1 = S[i+1][0], ns2 = S[i+1][1];
                if ( s1 == ns1 && s2 == ns2 ) {
                    A[s1]--;
                    A[s2]++;
                    if ( A[s1] < 0 ) {
                        ng = true;
                        break;
                    }
                    ans.push_back('A'+s2);
                } else {
                    if( s1 == ns1 || s1 == ns2 ) {
                        A[s2]--;
                        A[s1]++;
                        if ( A[s2] < 0 ) {
                            ng = true;
                            break;
                        }
                        ans.push_back('A'+s1); 
                    } else {
                        A[s1]--;
                        A[s2]++;
                        if ( A[s1] < 0 ) {
                            ng = true;
                            break;
                        }
                        ans.push_back('A'+s2);
                    }
                }
            }
        }
    }

    if ( ng ) {
        cout << "No" << "\n";
    } else {
        cout << "Yes" << "\n";
        for ( int i = 0; i < N; i++ ) {
            cout << ans[i] << "\n";
        }
    }

    return 0;
}

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

Measured memory_bytes: 9068
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc120_c.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  string S;
  cin >> S;

  int N = S.size();
  int zero = 0;
  int one = 0;
  ll ans = 0;

  rep(i, N) {
    if (S[i] == '0' && one == 0) {
      zero++;
    } else if (S[i] == '1' && zero == 0) {
      one++;
    } else if (S[i] == '0') {
      ans += 2;
      one--;
    } else {
      ans += 2;
      zero--;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
int n, m, q, ss[2007][2007], s1[2007][2007], s2[2007][2007];
char s[2007][2007];
int read()
{
	int num = 0;
	char c = getchar();
	while (c < '0' || c>'9')c = getchar();
	while (c >= '0' && c <= '9')num = num * 10 + c - '0', c = getchar();
	return num;
}
int main()
{
	scanf("%d%d%d", &n, &m, &q);
	for (int i = 1; i <= n; i++)
		scanf("%s", s[i] + 1);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			if (s[i][j] == '1')
				ss[i][j]++;
	for (int i = 2; i <= n; i++)
		for (int j = 1; j <= m; j++)
			if (s[i][j] == '1' && s[i - 1][j] == '1')
				s1[i][j]++;
	for (int i = 1; i <= n; i++)
		for (int j = 2; j <= m; j++)
			if (s[i][j] == '1' && s[i][j - 1] == '1')
				s2[i][j]++;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			ss[i][j] += ss[i - 1][j];
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			ss[i][j] += ss[i][j - 1];
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			s1[i][j] += s1[i - 1][j];
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			s1[i][j] += s1[i][j - 1];
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			s2[i][j] += s2[i][j - 1];
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			s2[i][j] += s2[i - 1][j];
	for (int i = 1; i <= q; i++)
	{
		int x1 = read(), y1 = read(), x2 = read(), y2 = read();
		int res = (ss[x2][y2] - ss[x1 - 1][y2] - ss[x2][y1 - 1] + ss[x1 - 1][y1 - 1]);
		res -= (s1[x2][y2] - s1[x1][y2] - s1[x2][y1 - 1] + s1[x1][y1 - 1]);
		res -= (s2[x2][y2] - s2[x1 - 1][y2] - s2[x2][y1] + s2[x1 - 1][y1]);
		printf("%d\n", res);
	}
	return 0;
}

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

int main() {
  string s,t;
  cin >> s >> t;
  int a = 0;
  if(s.at(0) == t.at(0)){
    a++;
  }
  
  if(s.at(1) == t.at(1)){
    a++;
  }
  
   if(s.at(2) == t.at(2)){
    a++;
  }
  
  cout << a << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    string s;
    cin>>n>>s;
    string ans=s;
    stack<char> st;
    rep(i,n){
        if(st.empty())st.push(s[i]);
        else{
            if(st.top()=='('&&s[i]==')')st.pop();
            else st.push(s[i]);
        }
    }
    while(!st.empty()){
        char c=st.top();
        st.pop();
        if(c==')')ans.insert(0,"(");
        else ans.insert(ans.size(),")");
    }
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 3564
#include <stdio.h>
int main(){
	int a,b,c,d,e;
	-1000<=a<=1000;
	-1000<=b<=1000;
	scanf("%d%d",&a,&b);
	c = a+b;
	d = a-b;
	e = a*b;
	if(d<c){
		(d=c);}
		if(d<e){
			(d=e);}
			printf("%d",d);
	return 0;
		}

Measured memory_bytes: 384
[N,Y] = list(map(int,input().split()))
x = [0,0,0]
x[0] = Y//10000
x[1] = (Y - (10000*x[0]))//5000
x[2] = (Y - (10000*x[0]) - (5000*x[1]))//1000
ans = [-1,-1,-1]
for i in range(x[0]+1):
    for j in range(x[1]+(2*i)+1):
        N_temp = (x[0]-i) + (x[1]+2*i-j) + (x[2]+5*j)
        if N_temp == N:
            ans = [(x[0]-i) , ((x[1]+2*i-j)) , (x[2]+5*j)]
            print('{0[0]} {0[1]} {0[2]}'.format(ans))
            exit()
print('{0[0]} {0[1]} {0[2]}'.format(ans))

Measured memory_bytes: 3064