akhauriyash/Code-Regression huggingface dataset:
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)	cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
#define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 1000005
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1005;
const long double epsilon = 1e-9;
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {

	fast
	ll n;
	cin >> n;
	ll ac = 0, tle = 0, wa = 0, re = 0;
	loop(i, n)
	{
		string s;
		cin >> s;
		if (s == "AC")
			++ac;
		else if (s == "TLE")
			++tle;
		else if (s == "RE")
			++re;
		else
			++wa;
	}
	cout << "AC x " << ac << END;
	cout << "WA x " << wa << END;
	cout << "TLE x " << tle << END;
	cout << "RE x " << re << END;


// #ifndef ONLINE_JUDGE
// 	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
// #endif
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const double PI = 3.14159265358979323846;

int main(void) {
  int n;
  cin >> n;
  vector<ll> l(n);
  rep(i, n) cin >> l[i];
  int res = 0;
  for (int i = 0; i < n - 2; i++) {
    for (int j = i + 1; j < n - 1; j++) {
      for (int k = j + 1; k < n; k++) {
        if (l[i] == l[j]) continue;
        if (l[j] == l[k]) continue;
        if (l[k] == l[i]) continue;
        if (l[i] + l[j] > l[k] && l[k] + l[i] > l[j] && l[j] + l[k] > l[i])
          res++;
      }
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
	int temp;
	if(b>a)
	{
		swap(a,b);
	}
	while(b!=0)
	{
	temp=b;
	b=a%b;
	a=temp;
}
return a;
}
int main()
{
	long long int k,sum=0,q;
	cin>>k;
	for(int i=1;i<=k;i++)
	for(int j=1;j<=k;j++)
	for(int l=1;l<=k;l++)
	{
		q=gcd(i,j);
		sum+=gcd(q,l);
	}
	cout<<sum;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main(){
  int N;
  cin >> N;
  vi h(N);
  for(int i = 0; i < N; i++){
    cin >> h.at(i);
  }
  int counter = 0;
  for(int i = 0; i < N; i++){
    if(h.at(i) == 0) continue;

    while(h.at(i) > 0){
      counter++;
      for(int j = i; j < N; j++){
        if(h.at(j) > 0) h.at(j)--;
        else break;
      }
    }
  }
  cout << counter << endl;
}

Measured memory_bytes: 256
a,b,c = map(int,input().split())

if a <= b:
    if b <= c:
        print(f"{a} {b} {c}")
    else:
        if a <= c:
            print(f"{a} {c} {b}")
        else:
            print(f"{c} {a} {b}")
else:
    if b <= c:
        if a <= c:
            print(f"{b} {a} {c}")
        else:
            print(f"{b} {c} {a}")
    else:
        print(f"{c} {b} {a}")



Measured memory_bytes: 5604
N = int(input())
A = sorted(list(map(int, input().split())))

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

candidate1 = []
candidate = {}
for i in range(N):
    if i > 1:
        delete_key = []
        for c in candidate.keys():
            if A[i] % c == 0:
                candidate[c]['atari'] += 1
            else:
                candidate[c]['hazure'] += 1        
    elif i == 0:
        candidate1 = make_divisors(A[i])
    elif i == 1:
        candidate2 = make_divisors(A[i])
        prev = -1
        for c in sorted(candidate1 + candidate2):
            if c != prev and prev != -1 and candidate[prev]['atari'] < 2:
                candidate[prev]['hazure'] += 1
            if c not in candidate:
                candidate[c] = {
                    'atari': 1,
                    'hazure': 0
                }
            else:
                candidate[c]['atari'] += 1
            prev = c
        if candidate[prev]['atari'] < 2:
            candidate[prev]['hazure'] += 1            
max = 0
for c in candidate:
    if candidate[c]['hazure'] < 2 and max < c:
        max = c
print(max)

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

map<int,int> mp;
int num[100050];
int main(){
	int n;
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> num[i];
		mp[num[i]]++;
	}
	int mx = -100;
	for(int i=1;i<=n;i++){
		mx = max(mx,mp[num[i]-1]+mp[num[i]+1]+mp[num[i]]);
	}
	cout << mx << endl;
}

Measured memory_bytes: 5120
#include <stdio.h>

int main(void) {
  int sum = 0;
  char input;  
  while (1) {
    scanf("%c", &input);
    if (input == '\n') {
      printf("%d\n", sum);
      sum = 0;
      continue;
    }
    if (sum == 0 && input == '0')
      return 0;
    sum += input - '0';
  }
  return 0;
}



Measured memory_bytes: 2028
// ABC 158-D
// 2020.3.7 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int in() {   // 非負整数の入力
	int n = 0; int c;
	c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

int ins(char *s) { // 文字列の入力　スペース以下の文字で入力終了
	char *p = s--;
	do *++s = gc();
	while (*s > ' ');
	*s = 0;
	return s - p;
}

char S[600005], *a, *b;

int main()
{
	int Q, rev, id, F, C;

	a = S+250000;
	b = a + ins(a);
	rev = 0;
	Q = in();
	while (Q--) {
		id = gc(), gc();
		if (id == '1') rev = !rev;
		else {
			F = gc(), gc();
			C = gc(), gc();
			if (F == '1') {
				if (rev) *b++ = C;
				else *--a = C;
			} else {
				if (rev) *--a = C;
				else *b++ = C;
			}
		}
	}
	if (rev) {
		while (b > a) pc(*--b);
	} else {
		while (a < b) pc(*a++);
	}
	pc('\n');
	return 0;
}


Measured memory_bytes: 768
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
 
using namespace std;
 
int main(void) {
	long long int count[100001] = { 0, };
	long long int N, K, a, b;
	cin >> N >> K;
 
	for (int i = 0; i < N; i++)
	{
		cin >> a >> b;
		count[a] += b;
	}
 
	a = 0;
	for (int i = 1; i <= 100000; i++)
	{
		if (a<K && K<=a+count[i])
		{
			cout << i << endl;
			break;
		}
		a += count[i];
	}
 
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>


using namespace std;



int main() {

	int N, K, Q, *score, A;

	cin >> N >> K >> Q;

	score = new int[N];

	for (int i = 0; i < N; i++) {
		score[i] = K - Q;
	}

	for (int i = 0; i < Q; i++) {
		cin >> A;
		score[A-1]++;
	}
	for (int i = 0; i < N; i++) {
		if (score[i] > 0)cout << "Yes\n";
		else cout << "No\n";
	}
	
	return 0;

}

Measured memory_bytes: 1024
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define jkl int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<int, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7


int main(){
    ll n, m;
    ll a[200002], b[200002];
    map<ll, ll>internal;
    cin >> n >> m;
    REP(i, m){
        cin >> a[i] >> b[i];
        if(a[i] == 1)internal[b[i]]++;
        if(b[i] == 1)internal[a[i]]++;
        if(a[i] == n)internal[b[i]]++;
        if(b[i] == n)internal[a[i]]++;
    }
    bool f = false;
    for(auto itr = internal.begin(); itr != internal.end(); ++itr){
        if(itr -> second == 2)f = true;
    }
    if(f){print("POSSIBLE");}
    else print("IMPOSSIBLE");
}

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

int main()
{
	double a, b, c, d, e, f;
	while(cin>>a>>b>>c>>d>>e>>f){     
 double y = ( a * f - c * d) / ( a * e - b * d);
    double x = ( c - b * y ) / a;
	  cout<<fixed<<setprecision(3)<<x << " " << y << endl;
	}

    return 0;
}




Measured memory_bytes: 3268
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
    int n;
    cin>>n;
    vector<int> p(n),q(n);
    for(int i=0; i<n; i++) cin>>p[i];
    for(int i=0; i<n; i++) cin>>q[i];
    ll P=0,Q=0;
    for(int i=0; i<n; i++){
        P+=p[i]*pow(10,n-i-1);
        Q+=q[i]*pow(10,n-i-1);
    }
    vector<int> a(n);
    vector<ll> b;
    for(int i=0; i<n; i++) a[i]=i+1;
    do{
        ll tmp=0;
        for(int i=0; i<n; i++){
            tmp+=a[i]*pow(10,n-i-1);
        }
        b.push_back(tmp);
        //cout<<tmp<<endl;
    }while(next_permutation(a.begin(),a.end()));
    sort(b.begin(),b.end());

    int pi,qi;
    for(int i=0; i<b.size(); i++){
        if(b[i]==P) pi=i;
        if(b[i]==Q) qi=i;
    }
    //cout<<P<<endl;cout<<Q<<endl;
    cout<<abs(pi-qi)<<endl;
}

Measured memory_bytes: 892
#include <stdio.h> 
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
using namespace std;
int main(){
	int t=0;
	int i, j;
	int d;
	int test;
	int low, high; 
	int number=0;
	long long l;
	long long p;
	char a[65];
	printf("? %lld\n", 10000000000);
	cout.flush();
	t++;
	cin>>a[1];
	if(a[1]=='Y'){
		for(i=1;i<=10;i++){
			p=pow(10, i)-1;
			printf("? %lld\n", p);
			cout.flush();
			t++;
			cin>>a[t];
			if(a[t]=='Y'){
				p=pow(10, i-1);
				printf("! %lld\n", p);
				cout.flush();
				return 0;
			}
		}
	}
	if(a[1]=='N'){
		for(i=0;i<=9;i++){
			p=pow(10, i);
			printf("? %lld\n", p);
			cout.flush(); 
			t++;
			cin>>a[t];
			if(a[t]=='N'){
				d=i;
				break;
			}
		}//确定N的位数d 
		for(i=1;i<=d-1;i++){
			low=0;
			high=9;
			if(i==1) low=1;
			for(j=1;low<high;j++){
				test=(low+high+1)/2;
				l=(number+test*pow(10,d-i))*10;
				printf("? %lld\n", l);
				cout.flush();
				t++;
				cin>>a[t];
				if(a[t]=='Y') high=test-1;
				else low=test;
			}
			number+=low*pow(10,d-i);
		}//对1-d之间的每个i，确定N的左数第i位 
		for(i=d;i<=d;i++){
			low=0;
			high=9;
			if(i==1) low=1;
			for(j=1;low<high;j++){
				test=(low+high)/2;
				l=(number+test*pow(10,d-i))*10;
				printf("? %lld\n", l);
				cout.flush();
				t++;
				cin>>a[t];
				if(a[t]=='Y') high=test;
				else low=test+1;
			}
			number+=low*pow(10,d-i);
		}
	}
	printf("! %d\n", number);
	cout.flush();
	return 0;
}

Measured memory_bytes: 596
#include <cstdio>
#include <array>
#include <algorithm>

using namespace std;

const int32_t N = 40;
array<int32_t, N> preorder, inorder;
vector<int32_t> postorder;

void construct_postorder(int32_t s_pre, int32_t s_in, int32_t l) {
    if (l > 1) {
        int32_t r_pre = s_pre, r_in = s_in;
        while (inorder[r_in] != preorder[r_pre]) r_in++;

        construct_postorder(s_pre + 1, s_in, r_in - s_in);
        construct_postorder(s_pre + r_in + 1 - s_in, r_in + 1, s_in + l - r_in - 1);
    }

    if (l >= 1) {
        postorder.push_back(preorder[s_pre]);
    }

    return;
}

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

    for (int32_t i = 0; i < n; i++) {
        scanf("%d", &preorder[i]);
    }
    for (int32_t i = 0; i < n; i++) {
        scanf("%d", &inorder[i]);
    }

    construct_postorder(0, 0, n);

    for (int32_t i = 0; i < n; i++) {
        if (i != 0) printf(" ");
        printf("%d", postorder[i]);
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 2808
#include<iostream>
#include<vector>
using namespace std;
int gcd(int,int);
int main(){
    int k;
    cin>>k;
    vector<int> a;
    long long sum=0;
    for(int i=1;i<=k;i++){
       for(int j=1;j<=k;j++){
           a.push_back(gcd(i,j));
       } 
    }
    for(int i=0;i<a.size();i++){
        for(int j=1;j<=k;j++){
            sum+=gcd(a[i],j);
        }
    }
    cout<<sum<<endl;
    return 0;
}
int gcd(int a,int b){
    if(b==0){
        return a;
    }
    return gcd(b,a%b);
}


Measured memory_bytes: 3724
#include <stdio.h>
int main(void){
   int n,a[21],b[21],c[21],sum=0,add=-1;
   
   scanf("%d",&n);
   for(int i=1;i<=n;i++){
       scanf("%d",&a[i]);
   }
    for(int i=1;i<=n;i++){
       scanf("%d",&b[i]);
   }
    for(int i=1;i<n;i++){
       scanf("%d",&c[i]);
   }
   
   for(int i=1;i<=n;i++){
       sum += b[a[i]];
       if(add==a[i]-1){sum+=c[a[i-1]];}
       add = a[i];
   }
   printf("%d",sum);
   return 0;
}


Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
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<vi> vvi;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;
ll const MOD = 1000000007;


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

int A,B,C,X;
cin >> A >> B >> C >> X;

int cnt = 0;

for(int a = 0; a <= A;a++) {
    for(int b = 0; b <= B;b++) {
        int remain = X - 500*a - 100*b;
        if(0 <= (remain/50) && (remain/50) <= C) cnt++;
    }
}

cout << cnt << endl;

return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
def cmb(n, r):
    if n<2:
        return 0
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
print(cmb(n,2)+cmb(k,2))

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    ll A[X], B[Y], C[Z];
    REP(i, 0, X) {
        cin >> A[i];
    }
    REP(i, 0, Y) {
        cin >> B[i];
    }
    REP(i, 0, Z) {
        cin >> C[i];
    }
    sort(A, A + X);
    reverse(A, A + X);
    sort(B, B + Y);
    reverse(B, B + Y);
    sort(C, C + Z);
    reverse(C, C + Z);
    set<tlglglg> st;
    priority_queue<tlglglglg> que;
    que.push(tlglglglg(A[0] + B[0] + C[0], 0, 0, 0));
    st.insert(tlglglg(0, 0, 0));
    REP(i, 0, K) {
        tlglglglg t = que.top();
        que.pop();
        ll x = get<1>(t);
        ll y = get<2>(t);
        ll z = get<3>(t);
        cout << get<0>(t) << endl;
        // cout << x << " " << y << " " << z << endl;
        if (x + 1 < X && st.count(tlglglg(x + 1, y, z)) == 0) {
            que.push(tlglglglg(A[x + 1] + B[y] + C[z], x + 1, y, z));
            st.insert(tlglglg(x + 1, y, z));
        }
        if (y + 1 < Y && st.count(tlglglg(x, y + 1, z)) == 0) {
            que.push(tlglglglg(A[x] + B[y + 1] + C[z], x, y + 1, z));
            st.insert(tlglglg(x, y + 1, z));
        }
        if (z + 1 < Z && st.count(tlglglg(x, y, z + 1)) == 0) {
            que.push(tlglglglg(A[x] + B[y] + C[z + 1], x, y, z + 1));
            st.insert(tlglglg(x, y, z + 1));
        }
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for(int i = 0; i < n; ++i) {
            par[i] = i; rank[i] = 0; diff_weight[i] = SUM_UNITY;
        }
    }

    int find(int x) {
        if(par[x] == x) return x;
        else {
            int r = find(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        find(x);
        return diff_weight[x];
    }

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

    bool unite(int x, int y, Abel w) {
        w += weight(x); w -= weight(y); // xとyそれぞれについて、rootとの重み差分を補正
        x = find(x); y = find(y);
        if(x == y) return false;
        if(rank[x] < rank[y]) swap(x, y), w = -w;   // rank[x] >= rank[y]になるようにswap
        if(rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w; // xがyの親になるので、xとyの差分をdiff_weight[y]に記録
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main() {
    int n, m; cin >> n >> m;
    UnionFind<int> uf(n);
    for(int i = 0; i < m; ++i) {
        int l, r, d; cin >> l >> r >> d;
        l--; r--;
        if(uf.same(l, r)) {
            int diff = uf.diff(l, r);
            if(diff != d) {
                cout << "No" << endl;
                return 0;
            }
        }else uf.unite(l, r, d);
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 4580
IMP = "IMPOSSIBLE"


def main():
    A, B = map(int, input().split())
    if A - B == 0:
        print(0)
    elif (A + B) % 2 == 0:
        print((A + B) // 2)
    else:
        print(IMP)


if __name__ == '__main__':
    main()


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

#define rep(i, a, b) for(int i=a; i<=b; i++)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int n, m, u, v;
bool visited[100001];
vi ord;
vi par[100001];

void dfs(int x){
	if(visited[x]) return;
	visited[x]=true;
	if(par[x].empty()) return;
	trav(k, par[x]){
		if(!visited[k]){
			dfs(k);
			ord.pb(k);
		}
	}
	ord.pb(x);
}

int main(){
  // freopen("input.txt", "r", stdin); 
  // freopen("output.txt", "w", stdout);
  cin.sync_with_stdio(0); cin.tie();
  cin.exceptions(cin.failbit);

  cin >> n >> m;
  rep(i, 1, m){
  	cin >> u >> v;
  	par[v].pb(u);
  }

  rep(i, 1, n) visited[i]=false;
  rep(i, 1, n){
  	if(visited[i]) continue;
  	else(dfs(i));
  }

  vi dp(n+1);
  int ans=0;
  trav(x, ord){
  	trav(p, par[x]){
  		dp[x]=max(dp[x], dp[p]+1);
  	}
  	ans=max(ans, dp[x]);
  }
  cout << ans;
}

Measured memory_bytes: 16008
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 100005
#define INF (ll)1e18
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define repr(i,n) repr2(i,n,0)
#define repr2(i,m,n) for(ll i=m;i>=(n);i--)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); //cout.tie(0);
#define pi 3.1415926535897
#define db long double  /* print with %Lf */
#define EPS 1e-9
#define flu fflush(stdout)
#define imp {cout<<"0\n"; return 0;}
#define yup {cout<<"YES\n"; return 0;}
#define debug_vec(vec,n) {rep(idxi,n) cout<<vec[idxi]<<" "; cout<<"\n";}
#define debug_pvec(vec,n) {rep(idxi,n) cout<<vec[idxi].fi<<"-"<<vec[idxi].se<<"  "; cout<<"\n";}
#define debug_set(seta) {cout<<seta.size()<<"\n"; for(auto idxi:seta) cout<<idxi<<" "; cout<<"\n";}
#define debug_map(mappa) {cout<<mappa.size()<<"\n";for(auto idxi:mappa) cout<<idxi.fi<<"-"<<idxi.se<<"  "; cout<<"\n";}
#define debug_vecvec(vec,n) {rep(idxi,n) {for(auto idxi2:vec[idxi]) cout<<idxi2<<" "; cout<<"\n";}}

int main() {

	get2(x,y);
	get3(a,b,c);
	ll ans = 0;

	fill_nums(A,a);
	sort(ALL(A)); reverse(ALL(A));
	priority_queue<int, vector<int>, greater<int>> pqa;
	rep(i,x) {
		ans += A[i];
		pqa.push(A[i]);
	}

	fill_nums(B,b);
	sort(ALL(B)); reverse(ALL(B));
	priority_queue<int, vector<int>, greater<int>> pqb;
	rep(i,y) {
		ans += B[i];
		pqb.push(B[i]);
	}

	fill_nums(C,c);
	sort(ALL(C));
	for(auto i:C) {
		ll t = min(pqa.top(), pqb.top());
		if(t >= i) continue;
		ans -= t;
		ans += i;
		if(t==pqa.top()) {
			pqa.pop();
			pqa.push(i);
		}
		else {
			pqb.pop();
			pqb.push(i);
		}
	}

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 3448
#include<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;

int main()
{
    int a[3],count=0,min0,Max,min1,i0,i1;
    cin>>a[0]>>a[1]>>a[2];

   sort(a,a+3);
   while( a[1]!=a[2])
   {
       a[0]++;
       a[1]++;
       count++;
   }
   while(a[0]<a[2])
   {
       a[0]+=2;
       count++;
   }
   if(a[0]>a[2])
   {
       a[1]++;
       a[2]++;
    count++;
   }


    cout<<count<<endl;


}

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

using ll = long long;
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;

int main(){

    int h, a;
    cin >> h >> a;
    int cnt=0;


    while(h>0){
        h-=a;
        cnt++;
    }


    cout << cnt << endl;

     return 0;
}

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

int main() {
  int n;
  bool flag = false;
  cin >> n;
  for (int i = 0; i < n; i++) {
    char c;
    cin >> c;
    if (c == 'Y') {
      flag = true;
      break;
    }
  }
  if (flag) {
    cout << "Four";
  } else {
    cout << "Three";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;
const double PI = 3.141592653589793;

bool possible(double cri,vi& r){
    int n = (int)r.size();
    double sm = 0;
    rep(i,n){
        sm += acos(2*cri/(r[i]*r[(i+1)%n]));
    }
    return (sm < 2*PI);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi r(n);
    rep(i,n){
        cin >> r[i];
    }
    double ans = 0;
    srep(i,3,n+1){
        vector<bool> v(n,false);
        fill(v.end() - i, v.end(), true);
        do{
            vector<int> vec;
            rep(j,n){
                if(v[j]){
                    vec.pb(r[j]);
                }
            }
            sort(all(vec));
            do{
                double mn = INF;
                rep(j,i){
                    cmn(mn,(double)vec[j]*vec[(j+1)%i]);
                }
                double l = -mn/2;
                double r = mn/2;
                while(r-l > EPS){
                    double mid = (l+r)/2;
                    if(possible(mid,vec)){
                        r = mid;
                    }else{
                        l = mid;
                    }
                }
                vd st(i);
                double sm = 0;
                rep(j,i){
                    st[j] = acos(2*l/(vec[j]*vec[(j+1)%i]));
                    sm += vec[j]*vec[(j+1)%i]*sin(st[j])/2.0;
                }
                if(abs(accumulate(all(st),0.0)-2*PI) < 1e-6){
                    cmx(ans,sm);
                }
            }while(next_permutation(all(vec)));
        } while (next_permutation(all(v)));
    }
    printf("%.12lf\n",ans);
    return 0;
}



Measured memory_bytes: 3696
from networkx import *
N = int(input())
E1 = [list(map(int,input().split())) for n in range(N-1)]
Q,K = map(int,input().split())
E2 = [list(map(int,input().split())) for q in range(Q)]
G = Graph()

for a,b,c in E1:
  G.add_edge(a-1,b-1,weight=c)

D = shortest_path_length(G,K-1,weight="weight")

for x,y in E2:
  print(D[x-1]+D[y-1])

Measured memory_bytes: 207928
#include <bits/stdc++.h>
#define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i))
#define down(i,b,a) for(int (i) = (b);i>=(a);--i)
#define debug(x) cerr << (x) << '\n';
#define bits(x,i) ((x >> i) & 1)
using namespace std;
const int N = 200005;
int a,b,c,d;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> a >> b >> c >> d;
	swap(b,a);
	swap(c,d);
	while (b || d){
		d-=a;
		if (d <= 0) {
			cout << "Yes";
			return 0;
		}
		b-=c;
		if (b <= 0){
			cout << "No";
			return 0;
		}
	}
}

Measured memory_bytes: 3648
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    X = readInts()
    mid = (sum(X) + (n-1)) // n
    ans = float('inf')
    for k in range(-1,2,1):
        p = 0
        for i in range(n):
            p += (mid + k - X[i]) ** 2
        ans = min(ans,p)
    print(ans)
if __name__ == '__main__':
  main()


Measured memory_bytes: 3064
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n - 1; i >= 0; i--)
#define REP2(i, n, k) for(ll i = 0; i < n; i += k)




int main() {
	ll n, k;
	cin >> n >> k;
	cout << ((n % k == 0) ? 0 : 1) << endl;
}

Measured memory_bytes: 764
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


vector<string> puyo;

bool valid(int x, int y)
{
	return 0 <= x && x < 6 && 0 <= y && y < 12;
}

bool _v[12][6];
vector<pint> _c;
void _connect(char c, int x, int y)
{
	if (_v[y][x] || !valid(x, y) || puyo[y][x] != c)
		return;

	_v[y][x] = true;
	_c.push_back(pint(x, y));
	rep (i, 4)
		_connect(c, x + dx[i], y + dy[i]);
}
vector<pint> connect_puyo(char c, int x, int y)
{
	CLEAR(_v, 0);
	_c.clear();
	_connect(c, x, y);
	return _c;
}
void vanish(const vector<pint>& p)
{
	foreach (it, p)
	{
		int x = it->first, y = it->second;
		puyo[y][x] = '.';
		rep (i, 4)
		{
			int tx = x + dx[i], ty = y + dy[i];
			if (valid(tx, ty) && puyo[ty][tx] == 'O')
				puyo[ty][tx] = '.';
		}
	}
}
void fall()
{
	for (int x = 0; x < 6; ++x)
	{
		for (int y = 0; y < 12; ++y)
		{
			if (puyo[y][x] != '.')
				continue;

			int t = -1;
			for (int i = y + 1; i < 12 && t == -1; ++i)
				if (puyo[i][x] != '.')
					t = i;
			if (t != -1)
				swap(puyo[y][x], puyo[t][x]);
		}
	}
}
bool go()
{
	bool vani = false;
	for (int y = 0; y < 12; ++y)
	{
		for (int x = 0; x < 6; ++x)
		{
			if (strchr("RGBYP", puyo[y][x]))
			{
				vector<pint> p = connect_puyo(puyo[y][x], x, y);
				if (p.size() >= 4)
				{
					vanish(p);
					vani = true;
				}
			}
		}
	}
	if (vani)
		fall();
	return vani;
}
void p()
{
	for (int i = 11; i >= 0; --i)
		cout << puyo[i] << endl;
	cout << endl;
}
int main()
{
	int T;
	cin >> T;
	while (T--)
	{
		puyo = vector<string>(12);
		rep (i, 12)
			cin >> puyo[11 - i];

		int res = 0;
		while (go())
			++res;
		cout << res << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n, m;
	cin >> n >> m;
	vector<vector<pair<int, int> > > e;
	vector<vector<pair<int, int> > > G;
	e.resize(n);
	int node = n;
	map<pair<int, int>, int> id;
	for(int i = 0; i < m; ++i) {
		int x, y, c;
		cin >> x >> y >> c;
		--x;
		--y;
		if(id.count({c, x}) == 0) {
			id[{c, x}] = node++;
		}
		if(id.count({c, y}) == 0) {
			id[{c, y}] = node++;
		}
		e[x].emplace_back(c, y);
		e[y].emplace_back(c, x);
	}
	G.resize(node);
	for(int i = 0; i < n; ++i) {
		for(auto o : e[i]) {
			int c = o.first, u = id[{c, i}], v = o.second;
			G[i].emplace_back(u, 1);
			G[u].emplace_back(i, 1);
			G[u].emplace_back(v, 0);
			int w = id[{c, v}];
			G[u].emplace_back(w, 0);
		}
	}
	vector<int> d(node, inf);
	d[0] = 0;
	priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > q;
	q.emplace(0, 0);
	while(!q.empty()) {
		auto o = q.top();
		q.pop();
		int u = o.second;
		if(o.first < d[u]) {
			continue;
		}
		for(auto o : G[u]) {
			int v = o.first, w = o.second;
			if(d[v] > d[u] + w) {
				d[v] = d[u] + w;
				q.emplace(d[v], v);
			}
		}
	}
	if(d[n - 1] == inf) {
		cout << -1 << '\n';
	} else {
		cout << d[n - 1] << '\n';
	}
	return 0;
}

Measured memory_bytes: 74492
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val a = sc.nextInt
    val b = sc.nextInt

    (a - b) match {
      case d if d < 0  =>
        println("a < b")
      case d if d == 0 =>
        println("a == b")
      case _ =>
        println("a > b")
    }
  }
}

Measured memory_bytes: 44984
import java.util.*;
public class Main{
    static long count = 0;
    public static void Merge(long s[], int left, int mid, int right){
        int n1 = mid- left;
        int n2 = right - mid;
        long L1[] = new long[n1 + 1];
        long L2[] = new long[n2 + 1];
        for(int i = 0 ; i < n1 ; i++)
            L1[i] = s[left+i];
        for(int i = 0 ; i < n2 ; i++)
            L2[i] = s[mid+i];
        L1[n1] = L2[n2] = 1000000001;
        int i = 0;
        int j = 0;
	int l = 0;
	int m = 0;
	while(true){
		if(L2[m] < L1[l]){
			count += (n1 - l);
			m++;
		}
		else
			l++;
		if(l == n1 || m == n2)
			break;
	}
        for(int k = left ; k < right ; k++){
            if(L1[i] <= L2[j]){
                s[k] = L1[i];
                i++;
            }
            else{
                s[k] = L2[j];
                j++;
            }
        }
    }
    public static void MergeSort(long s[], int left, int right){
        if(left+1 < right){
            int mid = (left + right)/2;
            MergeSort(s,left,mid);
            MergeSort(s,mid,right);
            Merge(s,left,mid,right);
        }
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long s[] = new long[n];
        for(int i = 0 ; i < n ; i++)
            s[i] = sc.nextLong();
        MergeSort(s,0,n);
        System.out.println(count);
    }
}


Measured memory_bytes: 102988
import sys,copy

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	H,W = MI()
	maze = [[-1 for _ in range(W)] for _ in range(H)]
	for i in range(H):
		S = IS()
		for j,s in enumerate(S):
			if s == '#':
				maze[i][j] = '#'

	def bfs(sx,sy):
		from collections import deque
		que = deque()
		dist_map = copy.deepcopy(maze)
		dist_map[sy][sx]=0
		que.append((sx,sy))
		res = 0
		while len(que) > 0:
			x,y=que.popleft()
			for dx,dy in [(-1,0),(1,0),(0,1),(0,-1)]:
				nx = x+dx
				ny = y+dy
				if(0<=nx<W and 0<=ny<H):
					if(dist_map[ny][nx]==-1):
						dist_map[ny][nx] = dist_map[y][x]+1
						res = max(res, dist_map[ny][nx])
						que.append((nx,ny))
		return res

	ans = -1
	for i in range(H):
		for j in range(W):
			if(maze[i][j]==-1):
				dist = bfs(j,i)
				if(dist > ans):
					ans = dist
	print(ans)

main()

Measured memory_bytes: 51804
//
//  main.cpp
//  ABC159A
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    // insert code here...
    int N,M;
    cin>>N>>M;
    // 偶数の組み合わせ
    int even=0;
    if (N>0) {
        even=N*(N-1)/2;
    }else{
        even=0;
    }
    // 奇数の組み合わせ
    int odd=0;
    if (M>0) {
        odd=M*(M-1)/2;
    }
    int ans=even+odd;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import collections
def modpow(a,n,p):
    if n==0:
        return 1
    x=modpow(a,n//2,p)
    x=(x*x)%p
    if (n%2)==1:
        x=(x*a)%p
    return x%p
def modinv(a,p):
    return modpow(a,p-2,p)
n=int(input())
a=list(map(int,input().split()))
id=0
frac=[1]*(10**5+10)
fracinv=[0]*(10**5+10)
p=10**9+7
c=collections.Counter(a)
id=c.most_common()[0][0]
buf=[]
for i in range(1,10**5+10):
    frac[i]=(frac[i-1]*i)%p
for i in range(0,10**5+10):
    fracinv[i]=modinv(frac[i],p)
#print(frac[:6])
for i in range(n+1):
    if a[i]==id:
        buf.append(i)
#print(a,l,buf)
N=n+1
short=N-(max(buf)-min(buf))

#print(short,N)

for i in range(1,n+2,1):
    if short-i<0:
        sub1=0
    else:
        sub1 = (((frac[short] * fracinv[i]) % p) * fracinv[short-i]) % p

    if short-i-1<0:
        sub2=0
    else:
        sub2 = (((frac[short - 1] * fracinv[i]) % p) * fracinv[short - i - 1]) % p
    all=(((frac[N]*fracinv[i])%p)*fracinv[N-i])%p

    #print(all,sub1,sub2)
    print((all-(sub1-sub2)%p)%p)

Measured memory_bytes: 77928
N,A,B=map(int,input().split())
S=input()
total=0
foreign=0
ans=['' for i in range(len(S))]

for i in range(len(S)):
    if S[i]=='a':
        if total<A+B:
            total+=1
            ans[i]='Yes'
        else:
            ans[i]='No'
    elif S[i]=='b':
        if total<A+B and foreign<B:
            total+=1
            foreign+=1
            ans[i]='Yes'
        else:
            ans[i]='No'
    else:
        ans[i]='No'

for anss in ans:
    print(anss)

Measured memory_bytes: 10024
#include <stdio.h>
signed main(){
    int i,x,n,p[105];
    scanf("%d %d",&x,&n);
    for(i=0;i<n;i++){
        scanf("%d",&p[i]);
    }
    int flag[105]={};
    int ans=0;
    for(i=0;i<n;i++){
        flag[p[i]]=1;
    }
    for(i=1;i<=101;i++){
        if(flag[i]==0){
            int abs1,abs2;
            abs1=x-ans;
            abs2=x-i;
            if(abs1<0){
                abs1=abs1*-1;
            }
            if(abs2<0){
                abs2=abs2*-1;
            }
            if(abs1>abs2){
                ans=i;
            }
        }
    }
    printf("%d\n",ans);
    return(0);
}

Measured memory_bytes: 1728
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>
#include <algorithm>
#include <cctype>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);

string str;

int main(){
	getline(cin,str);
	for(int i=0;i<str.size();i++) str[i]=toupper(str[i]);
	cout<<str<<endl;
}

Measured memory_bytes: 1176
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<pii,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?9e18:1e9;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};
int main(){
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	ll out=0;
	while(1){
		bool h=true;
		rep(i,n)if(in[i]>=n){
			h=false;
			ll co=in[i]/n;
			in[i]-=n*co;
			rep(j,n)if(i!=j)in[j]+=co;
			out+=co;
		}
		if(h)break;
	}
	cout<<out<<endl;
}








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

sorted_a = sorted(a)
a_max = sorted_a[-1]

dif = []
for i,ai in enumerate(sorted_a[:n-1]):
    dif.append((i,abs(ai-(a_max/2))))

min_i = sorted(dif, key=lambda x:x[1])[0][0]
dif_min = sorted_a[min_i]

print(a_max, dif_min)

Measured memory_bytes: 97656
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;
const int ny[4] = {-1,1,0,0}, nx[4] = {0,0,-1,1};
int sy,sx,gy,gx;


int main(){
  int n; cin >> n;
  vector<int> T(n);
  rep(i,n) cin >> T[i];
  int m; cin >> m;
  vector<int> P(m), X(m);
  rep(i,m) cin >> P[i] >> X[i];
  for(int i = 0; i < m; i++){
    ll time = 0;
    for(int j = 0; j < n; j++){
      if(j == P[i]-1){
        time += X[i];
      }else{
        time += T[j];
      }
    }
    cout << time << endl;
  }
  return 0;
}


Measured memory_bytes: 256
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y,x%y)
    
def di(z):
    divi = []
    for i in range(1 , int(z**0.5) +1 ):
        if z%i == 0:
            divi.append(i)
            if i != z//i:
                divi.append(z//i) 
    return divi
    
n = int(input())
a = list(map(int , input().split()))

g = a[0]
for i in range(n-1):
    g = gcd( g , a[i+1] )
    
a = di(g)
a = sorted(a)
for i in a:
    print(i)


Measured memory_bytes: 5636
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'
#define mset(a,v) memset(a,v,sizeof(a))
#define setp(x) cout<<fixed<<setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1e9;
const LL INF = 1e9;

void print_a(VI v)
{
    if(v.size()) cout<<v[0];
    loop(i,1,v.size()) cout<<' '<<v[i];
    cout<<'\n';
}

VVI init_vvi(int n, int m, int val)
{
    return VVI(n,VI(m,val));
}

VVL init_vvl(int n, int m, LL val)
{
    return VVL(n,VL(m,val));
}

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    string s, t;
    cin>>s>>t;
    int ans = 0;
    loop(i,0,s.length())
    {
        if(s[i] != t[i]) ++ans;
    }

    cout<<ans<<'\n';

    /*
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int a[n];
        loop(i,0,n) cin>>a[i];
    }
    */

    /*
    int n;
    cin>>n;
    int a[n];
    loop(i,0,n) cin>>a[i];
    */

    /*
    cout<<ans<<'\n';

    if(f) cout<<"YES\n";
    else cout<<"NO\n";

    if(f) cout<<"Yes\n";
    else cout<<"No\n";
    */

    return 0;
}


Measured memory_bytes: 3804
#include <iostream>

using namespace std;

int main(void){
    // Your code here!
   int n;
   cin >> n;
   if(n % 10 == 9 || n / 10 == 9){
       cout << "Yes" << endl;
   } else {
       cout << "No" << endl;
   }
   return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

ll MOD = 1000000007;

int main(void)
{
    cin.sync_with_stdio(false);
    int N;
    cin >> N;

    vector<int> colors(3);

    ll ans = 1;
    REP(n, N) {
        int a;
        cin >> a;

        int cnt = 0;
        for(auto c: colors) {
            cnt += (c == a);
        }

        if (cnt == 0) {
            ans = 0;
            break;
        }
        else {
            ans *= cnt;
            ans %= MOD;
            for(auto& c: colors) {
                if (c == a) {
                    c++;
                    break;
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <map>
using namespace std;
int main(){
   int N;
   cin >> N;
   map<int,int>mp;
   for(int i=0;i<N;i++){
       int a;
       cin >> a;
       mp[a-1] +=1;
       mp[a  ] +=1;
       mp[a+1] +=1;
   }
   int ans = 0;
   for(auto &x : mp){
       ans = max(ans, x.second);
   }
   cout << ans << endl;
}

Measured memory_bytes: 4736