akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

int ans = INF;
int h = 19,w = 15;
int dx[] = {0,1,0,-1,1,1,-1,-1};
int dy[] = {1,0,-1,0,1,-1,1,-1};
vs s(19);

void dfs(int x, int y, int cnt){
    if(cnt > 20)return;
    //cout << x << " " << y << " " << cnt << endl;
    //rep(i,h)cout << s[i]<<endl;
    if(x == h-1){
        ans = min(ans,cnt);
        return;
    }
    rep(i,8){
        int nx = x + dx[i];
        int ny = y + dy[i];
        if(nx < 0 || nx >= h || ny < 0 || ny >= w)continue;
        if(s[nx][ny] != 'X')continue;
        bool c = true;
        while(c && s[nx][ny] == 'X'){
            s[nx][ny] = '.';
            nx += dx[i];
            ny += dy[i];
            if(nx < 0 || nx >= h || ny < 0 || ny >= w){
                if(nx >= h)ans = min(ans, cnt+1);
                c = false;
            }
        }
        if(c)dfs(nx,ny,cnt+1);
        while(nx != x || ny != y){
            nx -= dx[i];
            ny -= dy[i];
            s[nx][ny] = 'X';
        }
        s[x][y] = '.';
    }
}

signed main(void) {
    rep(i,h)cin >> s[i];
    int sx,sy;
    rep(i,h)rep(j,w)if(s[i][j] == 'O'){
        sx = i, sy = j;
        s[i][j] = '.';
    }
    dfs(sx,sy,0);
    if(ans == INF)cout << -1 << endl;
    else cout << ans << endl;
}



Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}



struct Combinations {
  static int num;
  vi fact,factr,inv;

  Combinations(int num) {

    fact.assign(num+1,0);
    factr.assign(num+1,0);
    inv.assign(num+1,0);
    inv[1]=fact[0]=factr[0]=1;
    FOR(i,2,num+1) inv[i]=inv[M%i]*(M-M/i)%M;
    FOR(i,1,num+1) fact[i]=fact[i-1]*i%M,factr[i]=factr[i-1]*inv[i]%M;
  }


  int comb(int n,int c){
    if(c<0||c>n) return 0;
    return factr[c]*fact[n]%M*factr[n-c]%M;
  }

  int per(int n,int c){
    if(c<0||c>n) return 0;
    return fact[n]*factr[n-c]%M;
  }

  int hcomb(int n,int c){
    if(n==0&&c==0) return 1;
    return comb(n+c-1,c);
  }

};

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n,k;
  cin>>n>>k;
  Combinations comb(n);
  cout<<comb.comb(n-1,k-1)<<endl;


}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/02/24  Problem: ABC 119 B / Link: http://abc119.contest.atcoder.jp/tasks/abc119_b  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */


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

	int N; cin >> N;
	double ans = 0;
	FOR(i, 0, N) {
		string a, b;
		cin >> a >> b;
		if (b == "JPY") {
			ans += stoll(a);
		}
		else {
			ans += 380000.0*stod(a);
		}
	}


	cout << fixed << setprecision(10) << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }



int main(int argc, char const *argv[]) {
  int n,k;
  cin >> n >> k;
  int ans=0;
  rep(i,n){
    int h;
    cin >> h;
    if(h>=k) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

template<size_t maxN>
class PascalTri{
public:
    uint_fast64_t val[maxN][maxN];

    PascalTri() : val(){
        for(size_t i = 0; i < maxN; ++i)
            for(size_t j = 0; j < maxN; ++j)
                val[i][j] = 0;
        val[0][0] = 1;
        for(size_t i = 1; i < maxN; ++i)
            for(size_t j = 0; j < maxN; ++j)
                val[i][j] = val[i - 1][j] + (j ? val[i - 1][j - 1] : 0);
    }
};

PascalTri<55> C = PascalTri<55>();

long long binom(int a, int b){
    if(a < 0 || b < 0 || b > a)return 0;
    return C.val[a][b];
}

long long int N, A, B, D, E, v[55], ans;

int main(){
    scanf("%lld%lld%lld", &N, &A, &B);
    for(int i = 0; i < N; ++i)
        scanf("%lld", v + i);
    sort(v, v + N);
    reverse(v, v + N);
    for(int i = 0; i < A; ++i)
        ans += v[i];
    printf("%.12Lf\n", static_cast<long double>(ans) / A);
    reverse(v, v + N);
    if(v[N - A] == v[N - 1]){
        D = v - lower_bound(v, v + N, v[N - 1]) + N;
        ans = 0;
        for(int i = A; i <= B; ++i){
            ans += binom(D, i);
        }
        cout << ans << endl;
    }else{
        D = v - upper_bound(v, v + N, v[N - A]) + N;
        E = v - lower_bound(v, v + N, v[N - A]) + N;
        cout << binom(E - D, E - A) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#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;

int ctoi(char c){
  return c - '0';
}

int main(){
  string S;
  cin >> S;
  int ssize = S.size();
  string t = "";
  int result = 999;
  for(int i = 0; i < ssize-2; i++){
    int num = ctoi(S.at(i)) * 100 + ctoi(S.at(i+1)) * 10 + ctoi(S.at(i+2));
    result = min(abs(num - 753), result);
  }
  cout << result << endl;
}

Measured memory_bytes: 256
///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
using namespace std;
#define f first
#define s second
#define PB pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef map<string , int> msi;
typedef pair<int , string> pis;
typedef pair<int , pair<int , int> > piii;
const int MAXN = 1e5 + 10;
int n , m , a , b;
vector<int> adj[MAXN];
vector<int> ans;
bool bo[MAXN];
void dfs(int u)
{
	bo[u] = true, ans.pb(u);
	for(auto v : adj[u])
		if(!bo[v])
			return dfs(v);
	return;
}
int32_t main()
{
	cin >> n >> m;
	while(m --)
		cin >> a >> b , a -- , b -- , adj[a].pb(b) , adj[b].pb(a);
	dfs(0) , reverse(all(ans)) , ans.PB() , dfs(0) , cout << sz(ans) << endl;
	for(auto it : ans)
		cout << it + 1 << " ";
	return cout << endl , 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int sx,sy,tx,ty;


bool viz[2009][2009];

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

    cin>>sx>>sy>>tx>>ty;

    string res;


    //X
    for (int i=0; i<abs(tx-sx); i++) {
	res+='R';
    }
    

    //Y
    for (int i=0; i<abs(ty-sy); i++) {
	res+='U';
    }



    res+='U';

    //X
    for (int i=0; i<abs(tx-sx); i++) {
	res+='L';
    }

    res+='L';

    //Y
    for (int i=0; i<abs(ty-sy); i++) {
	res+='D';
    }

    res += 'D';
    res += 'R';






    //Y
    for (int i=0; i<abs(ty-sy); i++) {
	res+='U';
    }
    
    //X
    for (int i=0; i<abs(tx-sx); i++) {
	res+='R';
    }
    




    
    res += 'R';
    for (int i=0; i<abs(ty-sy); i++) {
	res+='D';
    }
    res+='D';
    for (int i=0; i<abs(tx-sx); i++) {
	res+='L';
    }
    res+='L';
    res+='U';
    cout<<res<<endl;


    return 0;

    int x=sx;
    int y=sy;
    for (char c :res) {
	if (c=='R') x++;
	if (c=='L') x--;
	if (c=='U') y++;
	if (c=='D') y--;
	cout<<x<<" "<<y<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	 for(int i=1;i<=9;i++)
	 {
	 	for(int j=1;j<=9;j++)
	 	{
	 		cout<<i<<"x"<<j<<"="<<i*j<<endl;
		 }
	 }
	return 0;
}

Measured memory_bytes: 3064
using System;
namespace csharptest
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            double []ans=new double[100000];
            int n;
            for (n = 0; str[1] != "?"; n++)
            {
                if (str[1] == "+")
                {
                    ans[n] = int.Parse(str[0]) + int.Parse(str[2]);
                }
                else if (str[1] == "-")
                {
                    ans[n] = int.Parse(str[0]) - int.Parse(str[2]);
                }
                else if (str[1] == "*")
                {
                    ans[n] = int.Parse(str[0]) * int.Parse(str[2]);
                }
                else if (str[1] == "/")
                {
                    ans[n] = Math.Floor(double.Parse(str[0]) / double.Parse(str[2]));
                }
                str = Console.ReadLine().Split(' ');
            }
            for (int m = 0; m < n; m++)
            {
                Console.WriteLine(ans[m]);
            }
        }
    }
}

Measured memory_bytes: 6504
# -*- coding: utf-8 -*-

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (a, b) = [int(e) for e in lines[0].split(' ')]

    return (a, b)


def solve(a, b):
    
    return a * b 
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 62120
s=list(map(int,input()))
l=[1,0]*(len(s)//2+1)
r=[0,1]*(len(s)//2+1)
lc=0
rc=0
for i in range(len(s)):
    if s[i]!=l[i]:
        lc+=1
    elif s[i]!=r[i]:
        rc+=1
print(min(lc,rc))    
    

Measured memory_bytes: 5536
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<58;

// vector v において、x の前方と後方の index を求める
template<class T> int former(const vector<T> &v, T x) {
    return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
template<class T> int latter(const vector<T> &v, T x) {
    return lower_bound(v.begin(), v.end(), x) - v.begin();
}

int main() {
    int A, B, Q; cin >> A >> B >> Q;
    vector<long long> s(A), t(B);
    for (int i = 0; i < A; ++i) cin >> s[i];
    for (int i = 0; i < B; ++i) cin >> t[i];
    s.push_back(INF); s.push_back(-INF); sort(s.begin(), s.end());
    t.push_back(INF); t.push_back(-INF); sort(t.begin(), t.end());
    
    for (int _ = 0; _ < Q; ++_) {
        long long x; cin >> x;
        long long res = INF;
        
        // 最初に s (前方に行くか後方に行くか場合分け)
        for (int i = 0; i < 2; ++i) {
            long long first = (i ? s[former(s, x)] : s[latter(s, x)]);
            // 次に t (現在地の前後を見る)
            for (int j = 0; j < 2; ++j) {
                long long second = (j ? t[former(t, first)] : t[latter(t, first)]);
                chmin(res, abs(x - first) + abs(first - second));
            }
        }
        // 最初に t (前方に行くか後方に行くか場合分け)
        for (int i = 0; i < 2; ++i) {
            long long first = (i ? t[former(t, x)] : t[latter(t, x)]);
            // 次に t (現在地の前後を見る)
            for (int j = 0; j < 2; ++j) {
                long long second = (j ? s[former(s, first)] : s[latter(s, first)]);
                chmin(res, abs(x - first) + abs(first - second));
            }
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 4140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll ch[3];
int main() {
	for(ll i=0;i<2;i++){
		ll now;
		cin>>now;
		now--;
		ch[now]=true;
	}
	for(ll i=0;i<3;i++){
		if(ch[i]==false){
			cout << i+1;
		}
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int main()
{
	string s;
	cin >> s;
	string ans="";
	for(int i=0; i<s.size(); i++){
		if(s.at(i)=='0'){
			ans.push_back('0');
		}else if(s.at(i)=='1'){
			ans.push_back('1');
		}else{
			if(ans.size()){
				ans.pop_back();
			}
		}
	}

	cout << ans << endl;
	return 0;
}

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

int main(void){
    int n, k;
    cin >> n >> k;

    ll x[n];
    rep(i, n)
        cin >> x[i];

    ll ans = 10000000000;
    rep(i, n - k + 1){
        ll l = abs(x[i]) + abs(x[i] - x[i + k - 1]);
        ll r = abs(x[i + k - 1]) + abs(x[i] - x[i + k - 1]);
        ans = min(ans, min(l, r));
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
a, b, c = map(int, input().split())  # 入力
k = int(input())  # 入力
num_ary = [a, b, c]
max_n = max(num_ary)

max_index = num_ary.index(max_n)#最大値のindex

max_num = max_n * pow(2, k)

num_ary[max_index] = max_num

print(num_ary[0] + num_ary[1] + num_ary[2])





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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) {
        cin >> a[i]; 
    }
    vector<int> num(n);
    rep(i,n) num[a[i]-1] = i+1;
    rep(i,n) cout << num[i] << " ";
}


Measured memory_bytes: 1536
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

int MAIN()
{
	int a, b;
	cin >> a >> b;
	if(a <= 0 && b >= 0)
		cout << "Zero" << endl;
	else if(a < 0 && b < 0)
	{
		if(abs(b - a) % 2 == 0)
			cout << "Negative" << endl;
		else
			cout << "Positive" << endl;
	}
	else
		cout << "Positive" << endl;
	return 0;
}

int main()
{
	int start = clock();
	#ifdef LOCAL_TEST
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif
	ios :: sync_with_stdio(false);
	cout << fixed << setprecision(16);
	int ret = MAIN();
	#ifdef LOCAL_TEST
		cout << "[Finished in " << clock() - start << " ms]" << endl;
	#endif
	return ret;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K = INT()
print("ACL"*K)


Measured memory_bytes: 9868
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
    ll n, k; cin >> n >> k;
    ll nmin, nmin1, nmin2; 
    nmin1 = n % k;
    nmin2 = abs(n % k - k);
    nmin = min(nmin1, nmin2);
    if(nmin<0){nmin += k;}
    cout << nmin << endl;
    return 0;
}   


Measured memory_bytes: 3672
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
#define pll pair<ll, ll>

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

    int N;
    cin >> N;
    vector<pll> P(N);

    rep(i, N) {
        ll a, b;
        cin >> a >> b;
        P[i] = {a, b};
    }

    sort(all(P), [](pll a, pll b) { return a.second < b.second; });

    ll time = 0;
    rep(i, N) {
        time += P[i].first;
        if (time > P[i].second) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 6348
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin>>a;
    if(int(a.find('C'))!=-1&&int(a.rfind('F'))!=-1&&a.find('C')<a.rfind('F'))
        cout<<"Yes";
    else
        cout<<"No";
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long int ll;
ll N;
int main(int argc, char const *argv[]) {
  cin >> N;
  ll temp=N;
  string S;
  for(int i=1;i<=60;i++){
    if(temp%(ll)pow(2,i)!=0){
      S.push_back('1');
      temp=temp-(ll)pow(-2,i-1);
    }else{
      S.push_back('0');
    }
  }
  while(S.back()=='0'){
    S.pop_back();
    if(S.empty()){
      S='0';
      break;
    }
  }
  reverse(S.begin(),S.end());
  cout<<S<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

void solve(){
    int n;
    scanf("%d", &n);
    int K[n]; lint L[n], R[n];
    vector<lint> d(n);
    vector<int> a, b;
    lint ans = 0;
    rep(i, n){
        scanf("%d%lld%lld", &K[i], &L[i], &R[i]);
        d[i] = abs(L[i] - R[i]);
        ans += min(L[i], R[i]);
        if(L[i] > R[i]) a.push_back(i);
        else b.push_back(i);
    }
    auto cmp = [&](const int &i, const int &j){return d[i] > d[j];};
    sort(a.begin(), a.end(), cmp);
    sort(b.begin(), b.end(), cmp);
    set<int> apos, bpos;
    rep(i, a.size()) apos.insert(i);
    For(i, a.size(), n) bpos.insert(i);

    for(auto i: a){
        auto itr = apos.lower_bound(K[i]);
        if(itr == apos.begin()){
            apos.erase(*apos.rbegin());
            continue;
        }
        ans += d[i];
        apos.erase(*prev(itr));
    }

    for(auto i: b){
        auto itr = bpos.lower_bound(K[i]);
        if(itr == bpos.end()){
            bpos.erase(*bpos.begin());
            continue;
        }
        ans += d[i];
        bpos.erase(*itr);
    }

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

int main(){
    int t;
    scanf("%d", &t);
    rep(tt, t){
        solve();
    }
}

Measured memory_bytes: 18936
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll mod = 1000000007;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	mint& operator+=(const mint a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if(!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

struct Combination{
	vector<mint> fact, ifact;
	Combination(int n):fact(n+1),ifact(n+1){
		assert(n < mod);
		fact[0] = 1;
		for(int i = 1; i <= n; i++) fact[i] = fact[i-1]*i;
		ifact[n] = fact[n].inv();
		for(int i = n; i >= 1; i--) ifact[i-1] = ifact[i]*i;
	}
	mint operator()(int n, int k){
		if(k < 0 || k > n) return 0;
		return fact[n]*ifact[k]*ifact[n-k];
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m, k;
	cin >> n >> m >> k;
	Combination comb(1000000);
	mint ans = 0;
	for(ll i = 1; i <= n; ++i){
		mint add = i * (n - i) % mod * m % mod * m % mod;
		add *= comb(n*m-2, k-2);
		ans += add;
	}
	for(ll i = 1; i <= m; ++i){
		mint add = i * (m - i) % mod * n % mod * n % mod;
		add *= comb(n*m-2, k-2);
		ans += add;
	}
	cout << ans.x << endl;
	return 0;
}

Measured memory_bytes: 18752
#include <stdio.h>
#include <stdlib.h>

int q(const int *a,const int *b)
{
	return *a-*b;
}

int main(void)
{
	int n,a[200],i,s=0;
	scanf("%d",&n);
	for(i=0;i<2*n;i++)scanf("%d",&a[i]);
	qsort(a,2*n,sizeof(int),q);
	for(i=0;i<n*2;i+=2){
		if(a[i]>a[i+1])s+=a[i+1];
		else s+=a[i];
	}
	printf("%d",s);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		Scanner pw = new Scanner(System.in);
		int a = pw.nextInt();
		int b = pw.nextInt();
		int c = a+b;
		int d = a-b;
		int e = a*b;
		int max = c;
		if(max>=d&&max>=e){System.out.print(max);}
		else if(d>=max&&d>=e){System.out.print(d);}
		else{System.out.print(e);}
		
	}
	

}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int  ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
LL mod = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	LL n; cin >> n;
	LL arr[n], sum = 0, maxl = 0;
	rep(i, 0, n) {
		arr[i] = scanLong();
		sum += arr[i];
		maxl = max(arr[i], maxl);
	}
	if(2*maxl < sum)	cout << "Yes" << endl;
	else	cout << "No" << endl;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<vector<ll>> matrix;//matrix A(n, vl(m)); //n*m行列
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007 //998244353

bool bit(ll subset, ll Rsift){ return ((subset)>>(Rsift))&1; }

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

    // solution comes here

    ll N;
    cin >> N;
    matrix honest(N, vl(18, INF));//[証言i][人ｊは...]
    rep(i, N) {
        ll A, x, y;
        cin >> A;
        rep(j, A) {
            cin >> x >> y;
            x--;//0-indexed
            honest[i][x] = y;
        }
    }

    
    ll ALL = 1<<N, ans=0;
    rep(sub, ALL) {
        //subは仮説
        bool ok=true;
        rep(i, N) {
            if(bit(sub, i)){
                rep(j, N){
                    if(honest[i][j] != INF){
                        if(honest[i][j] != bit(sub, j)) ok=false;
                    }
                }
            }
            /*else {
                rep(j, N){
                    if(honest[i][j] != INF){
                        if(honest[i][j] == bit(sub, j)) ok=false;
                    }
                }
            }*/
        }

        if(ok) {
            ll cnt = 0;
            rep(x, N) cnt += bit(sub, x);
            chmax(ans, cnt);
        }
    }

    cout << ans << nl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
S = []
for _ in range(M):
    s = list(map(int, input().split()))
    S.append(s[1:])
P = list(map(int, input().split()))
SS = [0] * N

ans = 0
for i in range(2**N):
    num = 0
    for j in range(N):
        if (i >> j) & 1 == 1:
            SS[j] = 1
    flg = True
    for j, s in enumerate(S):
        num = 0
        for e in s:
            if SS[e-1] == 1:
                num += 1
        if num % 2 != P[j]:
            flg = False
            break
    if flg:
        ans += 1
    SS = [0] * N   
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define lint long long
#define st first
#define nd second
#define MAX 100010

using namespace std;

int pai[MAX], r[MAX];

int find(int v){
	return pai[v] = v==pai[v]?v:find(pai[v]);
}
int une(int a, int b){
	a=find(a),b=find(b);
	if(a==b)return 0;
	if(r[a]>r[b])swap(a,b);
	pai[a]=b;
	if(r[a]==r[b])r[b]++;
	return -1;
}

int n,m;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	cin>>n>>m;
	int ans=n;
	for(int i=1;i<=n;i++){
		r[i]=0; pai[i]=i;
	}
	while(m--){
		int a,b,c;
		cin>>a>>b>>c;
		ans+=une(a,b);
	}

	cout<<ans<<"\n";

	return 0;	
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


int main(void){
    int n;
    cin>>n;
    vector<ll>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    ll ans = 0;
    while(true){
        bool flag = true;
        int j=0;
        for(int i=0;i<n;i++){
            if(a[i]>=n){
                flag=false;
                ll num = a[i]/n;
                for(int j=0;j<n;j++){
                    if(j==i)a[i]-=num*n;
                    else a[j]+=num;
                }
                ans+=num;
            }
        }
        if(flag)break;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int  long long int
#define fi first
#define se second
#define pb push_back
#define soo(v) sort(v.rbegin(),v.rend())
#define so(v) sort(v.begin(),v.end())
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
//#define endl '\n'
#define dbv(v) cout<<endl;cout<<#v<<"-->> ";for(auto it:v){cout<<it<<" ";}cout<<endl;
#define dbm(m)cout<<endl;cout<<#m<<"-->> ";for(auto it:m){cout<<it.fi<<" "<<it.se<<endl;}
#define dbs(s)cout<<endl;cout<<#s<<"-->> ";for(auto it:s){cout<<it<<" ";}cout<<endl;
#define mod 1000000007
#define db1(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl;
#define mx 1e18
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v)  *min_element(v.begin(),v.end())
#define double long double
#define io std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

int32_t main()
{
  io
int n,d;
cin>>n>>d;
int x[n],y[n];int cc=0;
for(int i=0;i<n;i++){cin>>x[i]>>y[i];if(d*d>=x[i]*x[i]+y[i]*y[i])cc++;}
  cout<<cc<<endl;

}

Measured memory_bytes: 6780
#-------------------------------------------------------------------
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")
#-------------------------------------------------------------------

S = input()

a=int(S[:2])
b=int(S[2:])

if (1<=a)and(a<=12):
	if (1<=b)and(b<=12):
		print("AMBIGUOUS")
	else:
		print("MMYY")
else:
	if (1<=b)and(b<=12):
		print("YYMM")
	else:
		print("NA ")
	


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

int main()
{
    string S, T;
    bool A;
    cin >> S >> T;
    for (int i = 0; i < S.size();i++)
    {
        if(S.at(i)!=T.at(i))
        {
            A = false;
            break;
        }
        else
        {
            A = true;
        }
    }
    if(A==false)
    {
        cout << "No" << endl;
    }
    else if(T.size()==S.size()+1)
    {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 3600
module Main where

    import Debug.Trace
    import Data.List
    
    solve :: Int -> Int -> Int -> String
    solve a b c = init $ iter $ sort (a:b:c:[]) where
        iter [] = ""
        iter (x:xs) = show x ++ " " ++ iter xs
       
    readLine:: IO [Int]
    readLine = fmap (map read . words) getLine
    
    main :: IO() 
    main = do
        [a, b, c] <- readLine
        let ans = solve a b c
        putStrLn ans
    


Measured memory_bytes: 3664
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	x1, y1, x2, y2 := nextInt(), nextInt(), nextInt(), nextInt()

	x := x2 - x1
	y := y2 - y1

	fmt.Printf("%d %d %d %d",x2-y,y2+x,x1-y,y1+x)
}


Measured memory_bytes: 640
package main

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

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)
	a := nextInt()
	b := nextInt()
	if a%2 == 0 || b%2 == 0 {
		fmt.Fprintf(writer, "Even")
	} else {
		fmt.Fprintf(writer, "Odd")
	}
}

func main() {
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


q = int(input())

M = 1000003 # 出力の制限
N = 10**6+20 # 必要なテーブルサイズ

g1 = [None] * (N+1) # 元テーブル
g2 = [None] * (N+1) #逆元テーブル
inverse = [None] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 

for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 

def cmb(n, r, M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] * g2[n-r]) % M

def sub(x, n):
#     print(x, n)
    if x+n-1>=M:
        ans = 0
    else:
        if x>=1:
            ans = g1[x+n-1]*g2[x-1]
        else:
            ans = g1[x+n-1]
    return ans
ans = [None]*q
for i in range(q):
    x,d,n = list(map(int, input().split()))
    if d>=1:
        xd = (x * inverse[d]) % M
        ans[i] = (sub(xd, n) * pow(d, n, M)) % M
    else:
        ans[i] = pow(x, n, M)
write("\n".join(map(str, ans)))

Measured memory_bytes: 152960
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int n;cin>>n;
  int min=inf*inf;
  rep1(i,1000000){
    if(n%i==0){
      int buf=i+n/i-2;
      if(min>buf)min=buf;
    }
  }
  cout<<min<<"\n";
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
class SCC {
public:
  int N;
  vector< vector<int> > G, R;
  vector<int> vs, used, ord;

  SCC(int N) : N(N) {
    G.resize(N);
    R.resize(N);
    used.resize(N);
    ord.resize(N);
  }

  void add_edge(int x, int y) {
    G[x].pb(y);
    R[y].pb(x);
  }

  void dfs(int x) {
    if (used[x]) return;
    used[x] = true;
    for (int t : G[x]) dfs(t);
    vs.pb(x);
  }
  void rdfs(int x, int k) {
    if (used[x]) return;
    used[x] = true;
    ord[x] = k;
    for (int t : R[x]) rdfs(t, k);
  }

  int scc() {
    rep(i, N) used[i] = false;
    rep(i, N) dfs(i);
    rep(i, N) used[i] = false;
    int k = 0;
    for (int i=vs.size()-1; i>=0; i--) {
      if (!used[vs[i]]) rdfs(vs[i], k++);
    }
    return k;
  }
};

int N, M;
int par[100000];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> M;
  SCC scc(N);
  rep(i, N+M-1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    scc.add_edge(a,b);
  }
  scc.scc();

  rep(i, N) par[i] = -1;

  rep(i, N) {
    int m = -1;
    for (int t : scc.R[i]) m = max(m, scc.ord[t]);
    int ne = -1;
    for (int t : scc.R[i]) if (scc.ord[t]==m) ne = t;
    par[i] = ne;
  }
  rep(i, N) cout << par[i]+1 << "\n";
  return 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
string to_str(ll x){string res; while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return res;}
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; }
//template end

int mod=1e9+7;
struct Mint {
    int val;
    int inv() const{
        int tmp,a=val,b=mod,x=1,y=0;
        while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
        if(x<0)x+=mod; return x;
    }
    Mint():val(0){}
    Mint(ll x):val(x>=0?x%mod:mod+(x%mod)){}
    Mint pow(ll t){Mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
    Mint& operator+=(const Mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
    Mint& operator-=(const Mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
    Mint& operator*=(const Mint& x){val=(ll)val*x.val%mod; return *this;}
    Mint& operator/=(const Mint& x){val=(ll)val*x.inv()%mod; return *this;}
    Mint operator+(const Mint& x)const{return Mint(*this)+=x;}
    Mint operator-(const Mint& x)const{return Mint(*this)-=x;}
    Mint operator*(const Mint& x)const{return Mint(*this)*=x;}
    Mint operator/(const Mint& x)const{return Mint(*this)/=x;}
    bool operator==(const Mint& x)const{return val==x.val;}
    bool operator!=(const Mint& x)const{return val!=x.val;}
};
struct factorial {
    vector<Mint> Fact, Finv;
public:
    factorial(int maxx){
        Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1);
        Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i;
    }
    Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
    Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
    Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};

int main(){
    int x,y; scanf("%d%d",&x,&y);
    if((x+y)%3!=0){printf("0\n"); return 0;}
    int t=(x+y)/3;
    x-=t; y-=t;
    if(x<0||y<0){printf("0\n"); return 0;}
    factorial fact(4000010);
    printf("%d\n",fact.nCr(x+y,x).val);
    return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<63;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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; }

long long gcd(long long x, long long y){
    if(x == 0) return y;
    else if(y == 0) return x;
    return x % y == 0 ? y : gcd(y, x%y);
}

int main(void){
    ll N; cin >> N;
    vector<ll> A(N); REP(i,N) cin >> A[i];

    vector<ll> L(N), R(N);
    L[0] = 0;
    REP(i,N-1) L[i+1] = gcd(L[i], A[i]);
    R[N-1] = 0;
    RREP(i,N-1) R[i] = gcd(R[i+1], A[i+1]);

    ll ans = 0;
    REP(i,N) chmax(ans, gcd(L[i], R[i]));
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
const int mod=1e9+7;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
ll qpow(ll a,ll b){ll ans=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)ans=ans*a%mod;a=a*a%mod;}return ans;}
ll gcd(ll a,ll b){return b>0?gcd(b,a%b):a;}

ll a[maxn];
ll b[maxn];
ll cal(ll x,ll y,ll t){
    if(x>y)swap(x,y);//x<=y
    if(t<=x) return y-t;
    else if(t>=y) return t-x;
    else{
        return y-x+min(abs(t-x),abs(t-y));
    }

}
int main(){
    ll qq,n,m,T,x;
    ll la,ra,lb,rb;
    int l,r,L,R;
    cin>>n>>m>>qq;
    rep(i,0,n) cin>>a[i];
    rep(i,0,m) cin>>b[i];
    sort(a,a+n);
    sort(b,b+m);
    ll ans;
    while(qq--){
        //cout<<qq<<endl;
        ans=1e18;
        cin>>x;
        r=lower_bound(a,a+n,x)-a;
        R=lower_bound(b,b+m,x)-b;
        l=max(0,r-1);
        L=max(0,R-1);
        ans=min(ans,cal(a[l],b[L],x));
        ans=min(ans,cal(a[l],b[R],x));
        ans=min(ans,cal(a[r],b[L],x));
        ans=min(ans,cal(a[r],b[R],x));
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define ll long long int
#define ff first
#define ss second
#define eps 1e-10

using namespace std;


int main()
{

    ll t,n,m,f,l,r,q,k,x,y,z,mn,mx,sum=0;
    ll a,b,c,d,ar,ans1,ans2;
    cin>>a>>b>>c>>d;

    cout<<(a*b)/2.0<<" ";

if((c+c) == a && (d+d)==b)
{
cout<<1<<endl;
}
else
{
cout<<0<<endl;
}




}


Measured memory_bytes: 3720
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Graph Start
struct edge {
    int from, to;
    long long cost;
};
/// Graph End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template

signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    ll K, A, B;
    cin >> K >> A >> B;
    ll a, b, c;
    b = 1LL;
    for (ll i = 1; i <= K; i++) {
        if (i >= 2) {
            c = b;
            b = a;
        }
        a = max(b + 1, ((i >= 2 && c >= A) ? c - A + B : 0));
    }
    cout << a << nn;
    return 0;
}

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

int main() {
  int a[26]={};
  string s;
  cin >> s;
  for ( char c:s ) {
    a[c-'a']++;
  }
  for ( int i=0; i<26; i++ ) {
    if ( a[i]%2 ) {
      cout << "No" << '\n';
      return 0;
    }
  }
  cout << "Yes" << '\n';
  return 0; 
}

Measured memory_bytes: 3620
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

/// Number of k-combinations
T combination(T = long)(T n, T k)
{
    assert(0 <= k);
    assert(0 <= n);
    if (n < k)
        return 0;
    k = min(n - k, k);
    if (k == 0)
        return 1;
    if (k == 1)
        return n;
    return memoize!combination(n - 1, k - 1) + memoize!combination(n - 1, k);
}

void main()
{
    auto S = sread();
    auto T = sread();
    long ans;
    foreach(i;0..3)
    {
        ans += S[i] == T[i];
    }
    writeln(ans);
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int n,c,k,ans = 0,pos = 0,now = 0,rest;
	int t[100000];
	scanf("%d %d %d",&n,&c,&k);
	for(int i=0;i<n;i++) scanf("%d",t+i);
	sort(t,t+n);
	while(pos<n){
		now = t[pos];
		rest = c;
		while(pos<n&&rest>0&&now+k>=t[pos]){
			pos++;
			rest--;
		}
		ans++;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 512