akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
const int INF = 100100100;
using namespace std;

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

    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> A(N);
    REP(i, N) {
        int a, b;
        cin >> a >> b;
        A[i].first  = a;
        A[i].second = b;
    };
    SORT(A);

    ll sum = 0;
    ll cnt = 0;
    REP(i, N) {
        cnt += A[i].second;
        sum += (ll)A[i].first * A[i].second;
        if (cnt >= M) {
            ll diff = cnt - M;
            sum -= (ll)A[i].first * diff;
            break;
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<vector>
#include<algorithm>

using namespace std;
int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    int l[n],i;
    for(i=0;i<=n-1;i++){
        scanf("%d",&l[i]);
    }
    sort(l,l+n);
    int ans=0;
    for(i=n-1;i>=n-k;i--){
        ans+=l[i];
    }
    
    printf("%d",ans);
    return 0;
}



Measured memory_bytes: 128
from collections import defaultdict

def main():
    S = input()
    d = defaultdict(int)
    d[0] = 1

    num = 0
    for digit, c in enumerate(S[::-1]):
        num += int(c) * pow(10, digit, 2019)
        num %= 2019
        d[num] += 1
    ans = sum([d[i]*(d[i]-1)//2 for i in range(2019)])
    print(ans)
if __name__ == "__main__":
    main()

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

using std::cin;
using std::cout;
using std::endl;

int main()
{
	long long int N;
	cin>> N;
	std::vector<long long int>A(N);
	for (long long int i = 0; i < N; i++){
		cin >> A[i]; 
	}
	long long int X = 0;
	for (long long int i = 0; i < N; i++){
		X += ((i % 2 == 0) ? (1) : (-1)) * A[i]; 
	} 
	cout << X;
	for (long long int i = 1; i < N; i++){
		X = (A[i - 1] * 2) - X;
		cout << ' ' << X;
	}
	return 0;
}

Measured memory_bytes: 2048
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = []
minus = 0
minuskamoku = 0
for i in range(N):
    C.append(A[i]-B[i])
D = sorted(C)[::-1]
for i in C:
    if i < 0:
        minus += i
        minuskamoku += 1
count = 0
for i in D:
    if minus >= 0:
        break
    else:
        minus += i
        count += 1
if minus >= 0:
    print(count + minuskamoku)
else:
    print(-1)

Measured memory_bytes: 18292
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N= 2e5 + 5;
const ll MOD=1e9 + 7;

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

    ll x,y,ans=0;
    cin>>x>>y;
    ll arr[]={300000,200000,100000};
    x-=1,y-=1;
    if(x<3)ans=ans + arr[x];
    if(y<3)ans=ans + arr[y];
    if(x==0 && y==0)ans=ans + 400000;
    cout<<ans;
}



Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <list>
#include <math.h>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N;
  int d[51];
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> d[i];
  }
  ll sum = 0;
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < N; j++) {
      if(i != j) {
         sum += d[i] * d[j];
      }
    }
  }
  cout << sum / 2;
  
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin >> a.at(i);
    for(int j=i;0<j;j--){
      int tmp;
      if(a.at(j-1)<a.at(j)){
        tmp=a.at(j-1);
        a.at(j-1)=a.at(j);
        a.at(j)=tmp;
      }
      else{
        break;
      }
    }
  }
  int sum1=0,sum2=0;
  for(int i=0;i<N;i++){
    if(i%2==0){
      sum1+=a.at(i);
    }
    else{
      sum2+=a.at(i);
    }
  }
  cout << sum1-sum2 <<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a[10], i, n, nt, sum;
	for (i = 0; i < 10; i++) {
		a[i] = 0;
	}
	scanf("%d", &n);
	nt = n;
	i = 0;
	sum = 0;
	do {
		a[i] = n % 10;
		sum += a[i];
		n = n / 10;
		i++;
	} while (n > 0);
	if (nt%sum == 0) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	return 0;
}



Measured memory_bytes: 128
import sys
import numpy as np
from math import ceil as C, floor as F, sqrt
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
 
ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

x = I()

A = []
As = []
B = []
Bs = []

for i in range(250):
  n = i ** 5
  A.append(i)
  As.append(n)
  B.append(i)
  Bs.append(n)
  B.append(-i)
  Bs.append(-n)

xs = [a-x for a in As]
for i, x in enumerate(xs):
  if x in Bs:
    print(A[i], B[Bs.index(x)])
    break


Measured memory_bytes: 27224
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

char s[20], t[20];

int main(){
	scanf("%s%s", s, t);
	int n = strlen(s);
	bool ok = true;
	REP(i, n) if(s[i]!=t[i]) ok = false;
	if(ok) printf("Yes\n");
	else printf("No\n");
}


Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
struct node{
	int a,b;
}c[200005];
bool cmp(node a,node b){return a.b<b.b;}
int n,s;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>c[i].a>>c[i].b;
	sort(c+1,c+n+1,cmp);
	for(int i=1;i<=n;i++){
		s+=c[i].a;
		if(s>c[i].b)cout<<"No",exit(0);
	}
	cout<<"Yes";
    return 0;
}

Measured memory_bytes: 1792
from collections import deque

def main():
    H, W = map(int, input().split())
    maze = [list(input()) for _ in range(H)]
    directions = [[0, 1], [0, -1], [1, 0], [-1, 0]]

    ans = 0
    for h in range(H):
        for w in range(W):
            if maze[h][w] == '#':
                continue

            goal_dists = [[-1] * W for _ in range(H)]
            goal_dists[h][w] = 0
            d = deque([[h, w]])

            while d:
                ht, wt = d.popleft()
                for dh, dw in directions:
                    if not (0 <= ht+dh < H and 0 <= wt+dw < W):
                        continue
                    if maze[ht+dh][wt+dw] == '#':
                        continue
                    if goal_dists[ht+dh][wt+dw] == -1:
                        goal_dists[ht+dh][wt+dw] = goal_dists[ht][wt] + 1
                        d.append([ht+dh, wt+dw])
            
            ans = max(ans, max([max(l) for l in goal_dists]))

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include <stdio.h>
#include<math.h>
int main(void) {
double a,b,c,d;
double e;
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
e=(a-c)*(a-c)+(b-d)*(b-d);
e=sqrt(e);
printf("%f",e);
  return 0;
}




Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std; 
#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 INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }

int main(){
  int N; cin>>N;
  int a[N]; CINA(a,N);
  sort(a,a+N,greater<int>());
  int s[2] = {0};
  REP(i,N){
    s[i%2] += a[i];
  }
  int r = s[0]-s[1];
  printf("%d\n",r);
}


Measured memory_bytes: 256
//Author:- Yatin Patel
//Mail:- yatinpatel.gt@gmail.com

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define FILEIN ifstream fin;fin.open("input.txt");
#define FILEOUT ofstream fout;fout.open("output.txt");

using namespace std;
using namespace __gnu_pbds;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << "  ";
    err(++it, args...);
}

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

#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second

#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define minQueue priority_queue<ll,vector<ll>,greater<ll> >
#define maxQueue priority_queue<ll,vector<ll>,less<ll> > 

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define RFOR(i,a,b) for(ll i=a;i>b;i--)
#define FILL(a,b) memset((a),(b),sizeof((a)))

#define MOD 1000000007
#define INF LONG_MAX
#define MINF LONG_MIN

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

ll power(ll x, unsigned ll y){
    if (y == 0)
        return 1;
    else if (y%2 == 0)
        return power(x, y/2)*power(x, y/2);
    else
        return x*power(x, y/2)*power(x, y/2);
}

//#define fin cin
//#define fout cout



int strtoint(string str)
{

    stringstream geek(str);

    int y =0;
    geek>>y;

    return y;

}




int main(){

    FAST;
    string str;
    cin>>str;

    string str1 = "";
    str1 += str[0];
    str1 += str[1];

    string str2 = "";
    str2 +=  str[2];
    str2 += str[3];

    int a,b;
    a = strtoint(str1);
    b = strtoint(str2);

    if(a>12 && b<=12 && b>0){
        cout<<"YYMM";
    }


    else if(a<=12 && a>0 && b>12){
        cout<<"MMYY";
    }


    else if(a<=12 && b<=12 && !(a==0 || b==0)){
        cout<<"AMBIGUOUS";
    }
    else if(a==0 && b!=0 && b<=12){
        cout<<"YYMM";
    }
    else if(a!=0 && a<=12 && b==0){
        cout<<"MMYY";
    }
    else {
        cout<<"NA";
    }


    return 0;
}






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

using namespace std;

#define IO ios_base::sync_with_stdio(0);cin.tie(0);

int main()
{
  IO;
  int n; cin >> n;
  map <int, int> mp;
  for (int i = 0; i < n; ++i)
  {
    int k; cin >> k;
    mp[k]++;
  }
  int m; cin >> m;
  for (int i = 0; i < m; ++i)
  {
    int k; cin >> k;
    if (mp[k] == 0)
    {
      cout << "NO" << endl;
      return 0;
    }
    else mp[k]--;
  }
  cout << "YES" << endl;

  return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n);

	double ans = 0.0;
	for(int i = 0; i < n; i++) {
		int a; scanf("%d", &a);

		ans += 1. / a;
	}
	
	printf("%.8lf\n", 1. / ans);
	return 0;
}


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

using namespace std;

int main(){

  int n, m, d[100], v[100];

  while(cin>>n>>m, n){
    for(int i=0;i<n;i++) cin>>d[i]>>v[i];

    int sum=0;
    for(int i=1;i<=m;i++){
      int ma=0;
      for(int j=0;j<n;j++){
        if(d[j]==i&&ma<v[j]) ma=v[j];
      }
      sum+=ma;
    }
    cout<<sum<<endl;
  }

  return 0;
}



Measured memory_bytes: 3076
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
using namespace std;

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

int main(){
    int N;
    cin >> N;
    int res=0;
    REP(i,N){
        if(pow(2,i)>N){
            break;
        }else{
            res = pow(2,i);
        }
    }
    cout << res;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    ll h, n; cin >> h >> n;
    VL a(n), b(n);
    FOR(i, 0, n)cin >> a[i] >> b[i];

    auto dp = defvec<ll>(LLINF, n + 1, h + 1);
    dp[0][0] = 0;
    FOR(i, 0, n)eFOR(j, 0, h) {
        chmin(dp[i + 1][j], dp[i][j]);
        chmin(dp[i + 1][min(h, j + a[i])], dp[i + 1][j] + b[i]);
    }

    cout << dp[n][h] << "\n";
}


Measured memory_bytes: 78592
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

s = input()

t= input()
ans = 0
for i in range(len(s)):
    if(s[i]!=t[i]):
        ans+=1

print(ans)

Measured memory_bytes: 74916
#include <cstdio>
#include <cmath>
#include <iostream>
using namespace std;
const int maxn = 1e5+5;
const int INF = 0x3f3f3f3f;

int n,k;
int s0,b0;
int arr[maxn], w[maxn];

int main() {
	scanf("%d%d",&n,&k);
	for (int i = 1; i <= n; i++) {
		scanf("%d",&arr[i]);
		w[i] = abs(arr[i]);
	}
	int cs = INF;
	for (int i = 1; i+k-1 <= n; i++) {
		int x,y;
		x = min(abs(arr[i+k-1]),abs(arr[i]));
		y = arr[i+k-1] - arr[i];
		cs = min(cs,x+y);
	}
	printf ("%d\n",cs);
	return 0;
}

Measured memory_bytes: 1024
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    N = II()
    S = []
    T = []
    for i in range(N):
        s,t = list(input().split())
        S.append(s)
        T.append(int(t))

    X = input()
    idx = S.index(X)
    print(sum(T[idx+1:]))



if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll a, b;
    cin >> a >> b;
    cout << a/__gcd(a,b)*b << endl;

    return 0;
}

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

int main()
{
	int num[4];
	int n;
	cin>>n;
	map<string, int> m;
	string s;
	while(n--)
	{
		cin>>s;
		m[s]++;
	}
	cout<<"AC x "<<m["AC"]<<endl;
	cout<<"WA x "<<m["WA"]<<endl;
	cout<<"TLE x "<<m["TLE"]<<endl;
	cout<<"RE x "<<m["RE"]<<endl;
	return 0;
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 998244353
#define INF 93193111451418101
#define bitcnt(a) (ll) __builtin_popcount((a))
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  int a, b;
  cin >> a >> b;
  cout << (a + b) / 2 << endl;
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
char a[100001]={0};
char b[100001]={1};
int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s %s",a,b);
	for(int i=0;i<n;i++)
	{
		printf("%c%c",a[i],b[i]);
	}
	return 0;
}

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

int n, k, l;
typedef pair<int, int> P;
map<P, int> mp;
class UnionFind{
	public:
		vector<int> Parent;
		vector<int> Rank;
		UnionFind(int n){
			++n;
			Parent.resize(n, 0);
			Rank.resize(n, 0);
			for(int i=0; i<n; ++i)
				Parent[i] = i;
		}

		int find(int x){
			if(Parent[x] == x) return x;
			return Parent[x] = find(Parent[x]);
		}

		void unite(int x, int y){
			x = find(x);
			y = find(y);
			if(x == y) return;
			if(Rank[x] < Rank[y]) Parent[x] = y;
			else{
				Parent[y] = x;
				if(Rank[x] == Rank[y]) ++Rank[x];
			}
		}

		bool same(int x, int y){
			return find(x) == find(y);
		}
};

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n >> k >> l;
	UnionFind ufa(n), ufc(n);
	for(int i=0; i<k; ++i){
		int p, q;
		cin >> p >> q;
		ufa.unite(p, q);
	}
	for(int i=0; i<l; ++i){
		int r, s;
		cin >> r >> s;
		ufc.unite(r, s);
	}
	for(int i=1; i<=n; ++i){
		P p = P(ufa.find(i), ufc.find(i));
		if(mp.find(p) == mp.end()) mp[p] = 1;
		else ++mp[p];
	}
	for(int i=1; i<=n; ++i)
		cout << mp[P(ufa.find(i), ufc.find(i))] << (i == n ? "\n" : " ");
}

Measured memory_bytes: 15104
GI = lambda: int(input()); GIS = lambda: map(int, input().split()); LGIS = lambda: list(GIS())

def main():
    GI()
    CEIL = 10 ** 18

    xs = LGIS()

    prod = 1
    for x in xs:
        prod *= x
        if prod > CEIL:
            prod = -1
            break

    if prod == -1:
        print(0 if 0 in xs else -1)
    else:
        print(prod)

main()


Measured memory_bytes: 84700
#include<bits/stdc++.h>
using namespace std;
vector<int> h;
int k,n;
int main() {
    cin>>n>>k;
    for(int i=0;i<n;++i){
        int x;
        cin>>x;
        h.emplace_back(x);
    }
    sort(h.begin(),h.end());
    int ans = INT_MAX;
    for(int i=k-1;i<n;++i) {
        ans= min(ans,h[i]-h[i-k+1]);
    }
    cout<<ans<<endl;
}

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

int main()
{
    double xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3;
    int q;

    cin >> q;

    //内積
    for( int i = 0; i < q; i++ )
    {
        cin >> xp0 >> yp0 >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3;

        double a, b, c, d;
        a = xp1 - xp0;
        b = yp1 - yp0;
        c = xp3 - xp2;
        d = yp3 - yp2;

        if( a * c + b * d == 0 )        //直交：内積0
            cout << 1 << endl;
        else if( a * d == c * b )       //並行
            cout << 2 << endl;
        else                            //それ以外
            cout << 0 << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"

const int N = 1e5;

ll a[1 + N];
ll sum[1 + N];

int main() {

    ios::sync_with_stdio (false);
    cin.tie (0); cout.tie (0);

    ll n, m, v, p;
    cin >> n >> m >> v >> p;
    for (ll i = 1; i <= n; i++) {
        cin >> a[i];
    }
    sort (a + 1, a + n + 1);
    for (ll i = 1; i <= n; i++)
        sum[i] = sum[i - 1] + a[i];
    ll ans = p;
    for (ll i = 1; i <= n - p; i++) {
        ll j = i;
        while (j < n - p && a[i] == a[j + 1])
            j++;
        if (j == n - p && a[i] == a[j + 1]) {
            ans += (j - i + 1);
        }
        else if (a[n - p + 1] - a[i] <= m) {
            if (j + p - 1 >= v) {
                ans += (j - i + 1);
            //    dbg (a[i]);
           //     dbg (j - i + 1);
            }
            else {
                ll lft = v - (j + p - 1);
                ll target = a[i] + m;
                ll l = j + 1, r = n - p + 1;
                ll best = 0;
                while (l <= r) {
                    ll mid = (l + r) / 2;
                    if (a[mid] <= target) {
                        l = mid + 1;
                        best = mid;
                    }
                    else
                        r = mid - 1;
                }
                if (best) {
                    if (best - j >= lft) {
                        ll felt = target * (best - j) - (sum[best] - sum[j]);
                        if (felt >= lft * m) {
                            ans += (j - i + 1);
                     //       dbg (a[i]);
                   //         dbg (j - i + 1);
                        }
                    }
                }
            }
        }
        i = j;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iterator>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vector<int> > 
#define vl vector<long long>
#define vc vector<char> 
#define vvc vector<vector<char> > 
#define vpi vector<pair<int,int> >
#define ll long long 
#define sz(a) int(a.size())
#define forn(i,n) for(int i = 0 ; i < int(n) ; i++)
#define all(x) x.begin(),x.end()
#define vpl vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pci pair<char,int>
#define len(s) s.length()
#define un unsigned
# define M_PI           3.14159265358979323846  /* pi */
#define modulo 998244353ll
#define mod 1000000007ll
#define MAXN  1000001 
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
ll gcd(ll a,ll b){if(a==0 || b == 0) return max(a,b);if(a == 1 || b == 1)return 1;return gcd(max(a,b)%min(a,b),min(a,b));}


void solve()
{
    int n;
    cin>>n;
    vl dp(n+1,0);
    dp[0] = 1;
    for(int i = 3 ; i <= n ; i++)
    {
        for(int j = 3 ; j <= i ; j++)
        {
            dp[i] += dp[i-j];
            dp[i] %= mod;    
        }
    }
    cout<<dp[n]<<endl;
}


int main()
{
    fast();
    int t = 1;
    // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3664
n,w=map(int,input().split())
dp=[0]+[-1]*w
for i in range(n):
    weight,value=map(int,input().split())
    for j in range(w-weight,-1,-1):
        if dp[j]!=-1:
            sum_weight=j+weight
            dp[sum_weight]=max(dp[sum_weight],dp[j]+value)

print(max(dp))

Measured memory_bytes: 70144
#include <iostream>

using namespace std;

int main(){
    long long int a,b,k,tmp;
    cin >> a >> b >> k;

    if(a-k <= 0){
        k -= a;
        a = 0;
        if(b-k <= 0){
            b = 0;
        }else{
            b -= k;
        }
    }else{
        a -= k;
    }

    cout << a << " " << b << endl;
    return 0;
}

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

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

    ll ans = 0;
    if(n * 2 <= m){
        ans += n;
        m -= n * 2;
        ll k = m / 4;
        ans += k;
    }else{
        ll k = m / 2;
        ans += k;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

void printSharp(int count) {
  for (int i = 0; i < count + 2; i++) {
    printf("#");
  }
  printf("\n");
}

void printPixel(char* str) {
  printf("#%s#\n", str);
}

int main(void) {
  int H, W;
  char str[256];

  scanf("%d%d", &H, &W);
  printSharp(W);
  
  for (int i = 0; i < H; i++) {
    scanf("%s", str);
    printPixel(str);
  }
  printSharp(W);
  
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
template<class T>inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}
const char symbol[4]={'R','G','B','Y'};
int n,m,k;
int main()
{
	init(n),init(m),init(k);
	for(int i=0;i<n;putchar('\n'),++i) {
		for(int j=0;j<m;++j) {
			int x=((m+i+j)/k)&1;
			int y=((m+i-j)/k)&1;
			putchar(symbol[(x<<1)+y]);
		}
	}
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int             long long
#define pb              push_back
#define mp              make_pair
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define nl			    "\n";
#define w(x)            int x; cin>>x; while(x--)
#define fr(i,n)         for (int i = 0; i < n; ++i)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)



int32_t main()
{
	FIO;

	int n,k;cin>>n>>k;
	int h[n];
	fr(i,n) cin>>h[i];
	int dp[n]={0};
	// dp[1]=abs(h[1]-h[0]);
	for (int i =1; i < n; ++i)
	{
		int rel=INT_MAX;
		for (int j = 1; j <= k; ++j)
		{
			if(i-j >=0){
				int op=dp[i-j]+abs(h[i]-h[i-j]);
				rel=min(rel,op);
			}
		}
		dp[i]=rel;
	}
	cout<<dp[n-1];
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    string S;

    cin >> S;

    if(S == "Sunny"){
        cout << "Cloudy";
    }

    else if(S == "Cloudy"){
        cout << "Rainy";
    }

    else{
        cout << "Sunny";
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
import collections,sys
def s():
 d=collections.deque()
 input()
 for e in sys.stdin:
  if'i'==e[0]:d.appendleft(e[7:-1])
  else:
   if' '==e[6]:
    m=e[7:-1]
    if m in d:d.remove(m)
   elif'i'==e[7]:d.popleft()
   else:d.pop()
 print(*d)
if'__main__'==__name__:s()


Measured memory_bytes: 69732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
int main(){
    string s;
    cin>>s;
    ll pointer = 0;
    ll need_left = 0;
    rep(i,s.size()){
        if(s[i]=='S') pointer++;
        else {
            if(pointer==0) need_left++;
            else pointer--;
        }
    }
    cout<<pointer+need_left<<endl;
    // ll need_right = need_left;
    // string res = "";
    // rep(i,need_left) res += '(';
    // res += s;
    // rep(i,pointer) res += ')';
    // cout<<res<<endl;    
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main () {
  int N;
  cin >> N;
  int l = 400;
  int r = 599;
  for (int i = 8; i >= 0; i --) {
    if (l <= N && N <= r) {
      cout << i << endl;
      return 0;
    }
    l += 200;
    r += 200;
  }
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main() {
  int L{}, R{}, d{};
  cin >> L >> R >> d;
  int cnt{};
  int i = 0;
  for (i = 0;i*d < L; ++i) {
  }
  for (;i*d<=R ;++i) {
    cnt++;
  }
  cout << cnt;
  return 0;
}

Measured memory_bytes: 3192
#include <iostream>
using namespace std;
int X,Y;
int fields[20][20];
int dp[20][20];
int counter=0;
int Max(int x,int y){
        return x>y?x:y;
}
int Min(int x,int y){
        return x>y?y:x;
}
int recursion(int y,int x){
        int res=0;
        if(dp[y][x]!=-1)
                return dp[y][x];
        if(y>=Y){
                res=1;
        }
        else if(fields[y][x]==3)
                res=0;
        else if(fields[y][x]==2){
                if(fields[y+2][x]==1)
                        return 0;
                res+=recursion(y+2,x);
        }
        else{
                if(fields[y+1][x]!=1){
                        res+=recursion(y+1,x);
                }
                if(fields[y+1][x-1]==0){
                        res+=recursion(y+1,x-1);
                }
                if(fields[y+1][x+1]==0){
                        res+=recursion(y+1,x+1);
                }
        }
        return dp[y][x]=res;
}
int main(){
        while(true){
                for(int i=0 ; i<20 ; i++ )
                        for(int j=0 ; j<20 ; j++ )
                                dp[i][j]=-1;
                cin >> X >> Y;
                counter=0;
                if(X+Y==0)
                        break;
                for(int i=0 ; i<=X ; i++ ){
                        fields[0][i]=3;
                        fields[Y+1][i]=3;
                }
                for(int i=0 ; i<=Y ; i++ ){
                        fields[i][0]=3;
                        fields[i][X+1]=3;
                }
                for(int i=1 ; i<=Y ; i++ )
                        for(int j=1 ; j<=X ; j++ )
                                cin >> fields[i][j];
                int ans=0;
                for(int i=1 ; i<=X ; i++ ){
                        if(fields[1][i]==1)
                                continue;
                        ans+=recursion(1,i);
                }
                cout << ans << endl;
        }
        return 0;
}

Measured memory_bytes: 3076
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1e18;

int main() {
  //
  ll q, h, s, d;
  cin >> q >> h >> s >> d;
  ll n;
  cin >> n;

  vector<pll> prices = {{8 * q, 0}, {4 * h, 1}, {2 * s, 2}, {d, 3}};
  sort(ALL(prices));

  ll cost = 0;
  for (auto& p : prices) {
    // cout << p.first << ":" << p.second << endl;
    if (p.second == 3) {
      cost += n / 2 * d;
      n = n & 1;
      if (n == 0) break;
    } else {
      if (p.second == 0) {
        cost += n * 4 * q;
      } else if (p.second == 1) {
        cost += n * 2 * h;
      } else {
        cost += n * s;
      }
      break;
    }
  }
  cout << cost << endl;

  return 0;
}


Measured memory_bytes: 256
s = int(input())
l = [s]
flag = True
i = 2
while flag:
  x = l.pop()
  y = x/2 if x%2==0 else 3*x+1
  l.append(x)
  if y in l:
    print(i)
    exit()
  l.append(y)
  i += 1
  

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define ull uint64_t
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mx5 100005
#define mx6 1000005
#define mod 1000000007
#define nfs ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

vector<int> gr[mx5];
ll sub[mx5] = {}, dp[mx5] = {}, M;
void dfs(int u, int pa = 0) {
    sub[u] = 1;
    for (int v : gr[u]) {
        if (v == pa) continue;
        dfs(v,u);
        sub[u] = (sub[u] * sub[v]) % M;
    }
    sub[u] = (sub[u] + 1) % M;
}

void dfs2(int u, int pa = 0) {
    dp[u] = 1;
    
    ll left = 1, right = 1;
    deque<ll> lprod(1,1), rprod(1,1);
    for (auto itr = gr[u].begin(); itr != gr[u].end(); itr++)
        lprod.push_back(left = (left * sub[*itr]) % M);
    
    for (auto itr = gr[u].rbegin(); itr != gr[u].rend(); itr++)
        rprod.push_front(right = (right * sub[*itr]) % M);
    dp[u] = rprod.front();
    rprod.pop_front();

    ll tmp = sub[u];
    for (int i = 0; i < gr[u].size(); i++) {
        if (gr[u][i] != pa) {
            sub[u] = (1 + (lprod[i] * rprod[i]) % M) % M;
            dfs2(gr[u][i], u);
            sub[u] = tmp;
        }
    }
}

int main() {
    nfs
    int i, n, u, v;
    cin >> n >> M;
    for (i = 1; i < n; i++) {
        cin >> u >> v;
        gr[u].pb(v);
        gr[v].pb(u);
    }
    dfs(1);
    dfs2(1);
    for(i = 1; i <= n; i++)
        cout << dp[i] << "\n";    
}

Measured memory_bytes: 153704
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int INF = Integer.MAX_VALUE;

		while(true){
			int m = sc.nextInt();
			int n = sc.nextInt();
			int k = sc.nextInt();
			int d = sc.nextInt();
			if(m == 0) break;

			int[] cake = new int[m];
			for(int i=0;i<m;i++)
				cake[i] = sc.nextInt();

			//[0]:X^[g
			//[1]~[m]:P[L®
			//[m+1]~[m+n]:h}[N
			//[m+n+1]:sð
			int[][] map = new int[m+n+2][m+n+2];
			for(int[] tmp : map) Arrays.fill(tmp,INF);

			for(int i=0;i<d;i++){
				String a = sc.next();
				String b = sc.next();
				int cost = sc.nextInt();
				int from=-1,to=-1;

				if(a.equals("H")) from = 0;
				else if(a.equals("D")) from = m+n+1;
				else if(a.charAt(0) == 'C') from = Integer.parseInt(a.substring(1));
				else from = m + Integer.parseInt(a.substring(1));

				if(b.equals("H")) to = 0;
				else if(b.equals("D")) to = m+n+1;
				else if(b.charAt(0) == 'C') to = Integer.parseInt(b.substring(1));
				else to = m + Integer.parseInt(b.substring(1));

				map[from][to] = map[to][from] = k * cost;
			}

			PriorityQueue<State> open = new PriorityQueue<State>();
			int[][] closed = new int[m+n+4][1000];
			for(int[] tmp : closed) Arrays.fill(tmp,INF);
			int ans = INF;
			open.add(new State(0,0,0));

			while(!open.isEmpty()){
				State st = open.poll();
				if(closed[st.id][st.used] <= st.cost) continue;
				closed[st.id][st.used] = st.cost;

				if(st.id == m+n+1){
					ans = Math.min(ans,st.cost);
				}

				for(int i=0;i<m+n+2;i++){
					if(map[st.id][i] != INF && ( i<1 || m<i || (st.used & (1<<i)) == 0 ) ){
						int ncost = st.cost + map[st.id][i];
						int nused = st.used;
						if(1 <= i && i <= m){
							ncost -= cake[i-1];
							nused |= (1<<i);
						}
						if(closed[i][nused] > ncost)
							open.add(new State(ncost,i,nused));
					}
				}
			}

			System.out.println(ans);
		}
	}
}

class State implements Comparable<State>{
	int cost,id,used;

	State(int cost,int id,int used){
		this.cost = cost;
		this.id = id;
		this.used = used;
	}

	public int compareTo(State st){
		return this.cost - st.cost;
	}
}

Measured memory_bytes: 17000
#include<bits/stdc++.h>
using namespace std;
int main()
{ int a;int l=0;int k=0;
 cin>>a;
 cout<<"\n";
 char h[100000];
 char t;
 char g[100000];
 for (int i=0;i<((2*a));i++)
 {cin>>h[i];
 }

 for (int j=0;j<a;j++)
 { 
   cout<<h[j]<<h[j+a];
 }



return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

int r, c;

int dist(int x, int y){
    if(y == 0){
        return x;
    }
    if(x == r){
        return r + y;
    }
    if(y == c){
        return 2 * r + c - x;
    }
    return 2 * (r + c) - y;
}

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

    int n;
    cin >> r >> c >> n;

    vector<P> vp;
    rep(i, n){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;

        if(x1 != 0 && x1 != r && y1 != 0 && y1 != c){
            continue;
        }
        if(x2 != 0 && x2 != r && y2 != 0 && y2 != c){
            continue;
        }
        vp.emplace_back(dist(x1, y1), i);
        vp.emplace_back(dist(x2, y2), i);
    }
    sort(ALL(vp));

    vector<bool> used(n, false);
    stack<int> st;
    rep(i, SZ(vp)){
        if(used[vp[i].second]){
            if(st.top() != vp[i].second){
                cout << "NO" << endl;
                return 0;
            }
            st.pop();
            continue;
        }
        st.push(vp[i].second);
        used[vp[i].second] = true;
    }
    cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 6128
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#define N 4
using namespace std;

int main(void) {
    int M[N][N];
    int i, j, k;

    for (i=0; i<N; i++) {
        for (j=0; j<N; j++) {
           M[i][j] = 0;
        }
    }

    int a, b;
    for (i=0; i<N-1; i++) {
        scanf("%d %d", &a, &b);
        M[a-1][b-1] = 1;
        M[b-1][a-1] = 1;
    }

    int ans = 0;

    for (i=0; i<N; i++) {
        if (M[0][i]) {
            M[0][i]=0;
            M[i][0]=0;
            for (j=0; j<N; j++) {
                if( M[i][j] ) {
                    M[i][j] = 0;
                    M[j][i] = 0;
                    for (k=0; k<N; k++) {
                        if (M[j][k]) {
                            ans = 1;
                        }
                    }
                }
            }
        }
    }

    if (ans) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }


}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

  long n,a,b,c;
  scanf("%ld %ld %ld %ld", &n, &a, &b, &c);
  char s[n][3];
  for (long i = 0; i < n; i++) {
    scanf("%s", s[i]);
  }
  char operation[n];
  for (long i = 0; i < n; i++) {
    if (s[i][0] == 'A' && s[i][1] == 'B') {
      if (a == 0 && b == 0) {
        printf("No\n");
        return 0;
      } else if (b == 0) {
        a--;
        b++;
        operation[i] = 'B';
      } else if (a == 0) {
        a++;
        b--;
        operation[i] = 'A';
      } else if (i != n-1 && s[i+1][0] == 'B' && s[i+1][1] == 'C') {
        a--;
        b++;
        operation[i] = 'B';
      } else {
        a++;
        b--;
        operation[i] = 'A';
      }
    } else if (s[i][0] == 'A' && s[i][1] == 'C') {
      if (a == 0 && c == 0) {
        printf("No\n");
        return 0;
      } else if (c == 0) {
        a--;
        c++;
        operation[i] = 'C';
      } else if (a == 0) {
        a++;
        c--;
        operation[i] = 'A';
      } else if (i != n-1 && s[i+1][0] == 'B' && s[i+1][1] == 'C') {
        a--;
        c++;
        operation[i] = 'C';
      } else {
        a++;
        c--;
        operation[i] = 'A';
      }
    } else {
      if (b == 0 && c == 0) {
        printf("No\n");
        return 0;
      } else if (c == 0) {
        b--;
        c++;
        operation[i] = 'C';
      } else if (b == 0) {
        b++;
        c--;
        operation[i] = 'B';
      } else if (i != n-1 && s[i+1][0] == 'A' && s[i+1][1] == 'C') {
        b--;
        c++;
        operation[i] = 'C';
      } else {
        b++;
        c--;
        operation[i] = 'B';
      }
    }
  }
  printf("Yes\n");
  for (long i = 0; i < n; i++) {
    printf("%c\n", operation[i]);
  }

  return 0;
}

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

int main() {
  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  bool x[31]={false};
  for(int i=0; 100*a*i<=f; i++){
    for(int j=0; 100*(a*i+b*j)<=f; j++){
      x[a*i+b*j]=true;
    }
  }
  bool y[f+1]={false};
  for(int i=0; c*i<=f; i++){
    for(int j=0; c*i+d*j<=f; j++){
      y[c*i+d*j]=true;
    }
  }
  int sugar_water=0;
  int sugar=0;
  double res=0;
  for(int i=0;i<31;i++){
    for(int j=0;j<f+1;j++){
      if(x[i]==false || y[j]==false) continue;
      else if(100*i+j>f || i*e<j) break;
      else if(i==0 && j==0) continue;
      else {
        double temp=(double)(100*j)/(double)(100*i+j);
        if (temp>=res){
          res=temp;
          sugar_water=100*i+j;
          sugar=j;
        }
      }
    }    
  }
  cout<<sugar_water<<' '<<sugar<<endl;
  return 0;
}

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

int main(){
    string s;
    cin >> s;
    int a[4] = {s[0] - '0', s[1] - '0', s[2] - '0', s[3] - '0'};
    //cout << a[0] << a[1] << a[2] << a[3] << endl;
    string ans = "";
    string res = "";
    int seven = a[0];
    for (int bits = 0; bits < (1 << 3); bits++){
        for (int i = 0; i < 3; i++){
            if(bits&(1<<i)){
                seven += a[i + 1];
                ans += '+';
            }
            else
            {
                seven -= a[i + 1];
                ans += '-';
            }
        }
        //cout << ans << endl;
        //cout << seven << endl;
        //cout << s[0] + ans[0] << endl;
        if (seven == 7)
        {
            res += s[0];
            res += ans[0];
            res += s[1];
            res += ans[1];
            res += s[2];
            res += ans[2];
            res += s[3];
            res += '=';
            res += '7';
            break;
        }else{
            seven = a[0];
            ans = "";
        }
    }
    cout << res << endl;
}

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

typedef long long ll;
const int p = (int)1e9+7;


int main() {
	ll H, W, N;
	cin >> H >> W >> N;
	vector<ll> a(N), b(N);
	for (ll i = 0; i < N; i++) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
	}

	map<ll,ll> m;
	for (ll i = 0; i < N; i++) {
		for (ll j = 0; j < 3; j++) {
			for (ll k = 0; k < 3; k++) {
				if(a[i]-j < 0 || a[i]-j > H-3 || b[i]-k < 0 || b[i]-k > W-3) continue;
				m[(a[i]-j)*W+b[i]-k]++;
			}
		}
	}

	vector<ll> ans(10,0);
	ll sum=0;
	for (auto itr = m.begin(); itr != m.end(); itr++) {
		//cout << itr->first <<" "<< itr->second << endl;
		ans[itr->second]++;
		sum++;
	}
	ans[0] = (H-2)*(W-2) - sum;

	for(ll i=0; i<10; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 58112
//                             In The Name Of Allah                                           
//                             	Mohammad Hosseini
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std; 

const int N = 1e5 + 100, OO = 100, T = 10, M = 100, P = 6151, SQ = 280, lg = 30;
typedef pair <int, int> pii;
int a[N];

int32_t main() {
	use_fast;
	int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    int cnt = 0;
    for(int i = 1; i <= n - 1; i++) {
       	int m = (a[i] + a[i + 1]) / 2;
        cnt += m;
        if(a[i + 1] == 0)
            continue;
		else {
            a[i + 1] = (a[i] + a[i + 1]) % 2;
            a[i] = 0;
        }
    }
    if(n == 1) 
        cnt = a[1] / 2;
    cout << cnt << endl;
	return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- uploaded by ubuntu 20.04 
5- ...
*/



Measured memory_bytes: 4392
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

using PR = vector<int>;

int N, M;
int G[700][700];

int color[700];
char dp[705][705];

PR partite(int v, int c) {
    color[v] = c;

    PR res = {1-c, c};
    for (int i = 0; i < N; ++i) {
        if (G[v][i] == 1) {
            if (color[i] != -1) {
                if (color[i] != 1-c) return PR();
            } else {
                PR m = partite(i, 1-c);
                if (m.size() == 0) return m;
                res[0] += m[0];
                res[1] += m[1];
            }
        }
    }

    return res;
}


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

    for (int i = 0; i < N; ++i) fill(G[i], G[i]+N, 1);
    fill(color, color+N, -1);
    for (int i = 0; i <= N; ++i) fill(dp[i], dp[i]+N+1, 0);

    for (int i = 0; i < N; ++i) G[i][i] = 0;
    for (int m = 0; m < M; ++m) {
        int a, b; cin >> a >> b; --a; --b;
        G[a][b] = G[b][a] = 0;
    }

    vector<pair<int, int>> bs;

    for (int i = 0; i < N; ++i) {
        if (color[i] != -1) continue;
        PR res = partite(i, 0);
        if (res.size() == 0) {
            cout << "-1" << endl;
            return 0;
        }

        bs.emplace_back(res[0], res[1]);
    }

    int B = bs.size();

    dp[0][0] = 1;
    for (int n = 0; n < B; ++n) {
        auto b = bs[n];
        for (int i = 0; i <= N; ++i) {
            if (i >= b.first) dp[n+1][i] = max(dp[n+1][i], dp[n][i-b.first]);
            if (i >= b.second) dp[n+1][i] = max(dp[n+1][i], dp[n][i-b.second]);
        }
    }

    int ans = N*(N-1)/2;
    for (int i = 1; i <= N; ++i) {
        if (dp[B][i])
            ans = min(ans, i*(i-1)/2 + (N-i)*(N-i-1)/2);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2688