akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int main() {
	string S;
	cin >> S;
	long sum1 = 0,sum2 = 0;
	int l = S.length();
	int nums[10];
	for (int i = 0; i < l; i++)nums[i] = S[i] - '1' + 1;
	int max = pow(2, l - 1);
	for (int b = 0; b < max; b++) {
		long temp1 = nums[0];
		long temp2 = 0;
		for (int i = 0; i < l-1; i++) {
			int t = b & (int)pow(2,i);
			if (t != 0) {
				sum1 += temp1;
				sum2 += temp2;
				if (sum1 >= 100000000) {
					sum2 += floor(sum1 / 100000000);
					sum1 = sum1 % 100000000;
				}
				temp1 = nums[i + 1];
				temp2 = 0;
			}
			else {
				temp1 = 10 * temp1 + nums[i + 1];
				temp2 *= 10;
				if (temp1 >= 100000000) {
					temp2 += floor(temp1 / 100000000);
					temp1 = temp1 % 100000000;
				}
			}
		}
		sum1 += temp1;
		sum2 += temp2;
		if (sum1 >= 100000000) {
			sum2 += floor(sum1 / 100000000);
			sum1 = sum1 % 100000000;
		}
	}
	if (sum2 == 0) cout << sum1 << endl;
	else {
		int dig = floor(log10(sum1)) + 1;   //sum1の桁数
		cout << sum2;
		for (int i = 0; i < 8 - dig; i++)cout << "0";
		cout << sum1 << endl;
	}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define x_ real()
#define y_ imag()
#define cross(a, b) (conj(a)*(b)).imag()
#define dot(a, b) (conj(a)*(b)).real()
#define PI acos(-1)
#define F first
#define S second
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define fileIO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<ld> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
typedef pair<double, double> pd;
//pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };
const ll mod = 1e9 + 7;
const ll N = 3e5 + 7;

ll gcd(ll a, ll b) {
	if (!b)
		return a;
	return gcd(b, a%b);
}

ll count(ll x, ll c, ll d) {
	ll lcm = c * d / gcd(c, d);
	return x - x / c - x / d + x / lcm;
}



int main() {
	fastIO;
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << count(b, c, d) - count(a - 1, c, d);
	


}


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

const int MOD = 1000000007;

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

    vector <vector <long long>> dp(s.size() + 1, vector <long long> (4, 0));
    dp[0][0] = 1LL;

    rep (i, s.size()) {
        rep (j, 4) {
            (dp[i + 1][j] += s[i] == '?' ? dp[i][j] * 3
                                         : dp[i][j]) %= MOD;
        }

        if (s[i] == '?' || s[i] == 'A') (dp[i + 1][1] += dp[i][0]) %= MOD;
        if (s[i] == '?' || s[i] == 'B') (dp[i + 1][2] += dp[i][1]) %= MOD;
        if (s[i] == '?' || s[i] == 'C') (dp[i + 1][3] += dp[i][2]) %= MOD;
    }
    cout << dp[s.size()][3] << endl;

    return 0;
}

Measured memory_bytes: 7424
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		StringBuilder sa = new StringBuilder(in.next());
		StringBuilder sb = new StringBuilder(in.next());
		StringBuilder sc = new StringBuilder(in.next());

		char nextTurn = 'a';
		int N = sa.length() + sb.length() + sc.length();
		for (int i = 0; i < N; i++) {
			if (nextTurn == 'a') {
				if (sa.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTurn = sa.charAt(0);
				sa.delete(0, 1);
			} else if (nextTurn == 'b') {
				if (sb.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTurn = sb.charAt(0);
				sb.delete(0, 1);
			} else {
				if (sc.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTurn = sc.charAt(0);
				sc.delete(0, 1);
			}
		}
		in.close();
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef vector<ii> vii;

int main(){
  int N, M;cin>>N>>M;
  vii v;
  for (int i=0;i<M;++i){
    int a, b;cin>>a>>b;
    ii p=make_pair(b,a);
    v.push_back(p);
  }

  sort(v.begin(), v.end());

  int count=1;
  ii p=v[0];
  int bar=p.first;
  for (int i=1;i<M;++i){
    p=v[i];
    int a=p.second;
    if (a<bar){continue;}
    count++;
    bar=p.first;
  }

  cout << count << endl;
  return 0;
}

Measured memory_bytes: 1400
using System;
using System.Linq;

namespace ProgramingStydying
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var t = Console.ReadLine();
            var ans = S.Length;

            for(int i =0; i < S.Length - t.Length + 1; i++)
            {
                var kouho = 0;

                var s = S.Substring(i, t.Length);
                for(int j = 0; j < t.Length; j++)
                {
                    if(s[j] != t[j])
                    {
                        kouho++;
                    }
                }
                if (kouho < ans)
                {
                    ans = kouho;
                }
            }
            Console.WriteLine(ans);
        }
    }
}

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

int main()
{
	int n, m;
	cin >> n >> m;
	int h[100000];
	bool good[100000] = {false};
	//std::fill(std::begin(good), std::end(good), false);
	std::fill_n(std::begin(good), n, true);
	for (int i = 0; i < n; i++)
	{
		cin >> h[i];
	}
	for (int j = 0; j < m; j++)
	{
		int a, b;
		cin >> a >> b;
		a--; b--;
		int minor = 0;
		if (h[a] == h[b])
		{
			good[a] = false; good[b] = false;
			continue;
		}
		if (h[a] < h[b])
		{
			minor = a;
		} 
		else
		{
			minor = b;
		}
		good[minor] = false;
	}
	cout << std::count(std::begin(good), std::end(good), true) << endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N=3000+5;

int n;
ll v[N];
ll dp[N][N];

void calc(int l,int r)
{
    if(dp[l][r]!=-1) return;
    calc(l+1,r);
    calc(l,r-1);
    ll a=v[l]-dp[l+1][r];
    ll b=v[r]-dp[l][r-1];
    dp[l][r]=max(a,b);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
    }
    for(int i=0;i<N;i++)
    {
        for(int j=0;j<N;j++)
        {
            dp[i][j]=-1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        dp[i][i]=v[i];
    }
    calc(1,n);
    cout<<dp[1][n]<<"\n";
    return 0;
}


Measured memory_bytes: 70912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

struct board{
    int n, w, ok=0, nnm[2]{};
    map<int,P> pos;
    vector<int> rcnt, ccnt;

    void init(int _n, int _w){
        n = _n;
        w = _w;
        if(n==1 && w>1) w=IINF;
        rcnt.resize(n,0);
        ccnt.resize(n,0);
    }
    void setPos(int a, int i, int j){
        pos[a] = {i,j};
    }
    void mark(int a){
        if(pos.count(a)==0)return;
        int i, j;
        i = pos[a].first;
        j = pos[a].second;
        rcnt[i]++;
        ccnt[j]++;
        if(i==j){
            nnm[0]++;
            if(nnm[0]==n)ok++;
        }
        if(i==n-j-1){
            nnm[1]++;
            if(nnm[1]==n)ok++;
        }
        if(rcnt[i]==n)ok++;
        if(ccnt[j]==n)ok++;
    }
    bool iswin(){
        return ok>=w;
    }
};

int main() {
    int n, u, v, m;
    cin >> n >> u >> v >> m;
    board usa, neko;
    usa.init(n,u);
    neko.init(n,v);
    REP(i,n)REP(j,n){
        int a;
        cin >> a;
        usa.setPos(a,i,j);
    }
    REP(i,n)REP(j,n){
        int a;
        cin >> a;
        neko.setPos(a,i,j);
    }
    string ans="";
    REP(i,m){
        int a;
        cin >> a;
        usa.mark(a);
        neko.mark(a);
        if(ans.size()==0){
            if(usa.iswin() && !neko.iswin()){
                ans = "USAGI";
            }
            else if(!usa.iswin() && neko.iswin()){
                ans = "NEKO";
            }
            else if(usa.iswin() && neko.iswin()){
                ans = "DRAW";
            }
        }
    }
    if(ans.size()==0) ans = "DRAW";
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 20992
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;

int main() {
    int N, i, a;
    map<long, long>A;
    vector<long> v;
    cin >> N;
    for (i = 0; i < N; i++) {
        cin >> a;
        A[a]++;
        if (A[a] % 2 == 0) {
            v.push_back(a);
        }
    }

    if (v.size() < 2) {
        cout << 0 << endl;
        return 0;
    }
    sort(v.begin(), v.end(), greater<long>());

    cout << v[0] * v[1] << endl;
    return 0;
}


Measured memory_bytes: 6528
/**
 *    author: Behradm
 *    Created: 14.06.2020 16:31:46
 *    In the Name of God
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x, y;
  cin >> x >> y;
  for (int i = 0; i <= x; i++) {
    for (int j = 0; j <= y; j++) {
      if (i + j == x && 2 * i + 4 * j == y) {
        cout << "Yes\n";
        return 0;
      } 
    }
  }
  cout << "No\n";
  return 0;
}




Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 0;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
signed main() {
	int n = read();
	int ans = 0;
	for (int i = 1; i <= n; i+=2) {
		int sum = 0;
		for (int j = 1; j <= i; j++) {
			if (i%j == 0) sum++;
		}
		if (sum == 8) {
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
from sys import stdin, setrecursionlimit
from collections import defaultdict
from math import gcd

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


MOD = 1000000007
N = int(input())

d = defaultdict(int)
zeros = 0
for i in range(N):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zeros += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        if a == 0 and b == -1:
            b = 1
        d[(a, b)] += 1

ans = 1
free = 0
for (a, b), n in d.items():
    if b > 0:
        if (b, -a) in d:
            m = d[(b, -a)]
            ans = ans * (pow(2, n, MOD) + pow(2, m, MOD) - 1) % MOD
        else:
            free += n
    else:
        if (-b, a) not in d:
            free += n

ans = (ans * pow(2, free, MOD) + zeros - 1) % MOD
print(ans)


Measured memory_bytes: 113988
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    S = LS()
    q = deque([])
    # print(S)
    cnt = 0
    for s in S:
        if s == '(':
            cnt += 1
            q.append(s)
        else:   # ')'
            if cnt >= 1:
                q.append(s)
                cnt -= 1
            else:
                q.appendleft('(')
                q.append(s)
    for _ in range(cnt):
        q.append(')')

    # print(q)
    printlist(q, '')

if __name__ == '__main__':
    solve()


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

int main(){
  ll ans;
  ll k,n;
  vector<ll> a(n);
  cin >> k >> n;
  rep(i,n)
    cin >> a[i];
  ll interbal = a[0] + (k-a[n-1]);
  rep(i,n-1)
    interbal = max(interbal, (a[i+1]-a[i]));
  ans = k - interbal;
  cout << ans << endl;
}

Measured memory_bytes: 33024
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

int main() {
	int x, y, z;
	cin >> x >> y >> z;
	int ans;
	ans = z;
	for (int i = 0; i < 10; i++) {
		ans = ans * x - y;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// const ll MOD = 1000000007;
const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
    fio();
    ll a;
    double b;
    cin >> a >> b;
    cout << (ll)(a * (ll)((b + 0.00000001) * 100) / 100) << endl;
}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int A, B;
  cin >> A >> B;

  cout << max(0, A - 2*B) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N,M,X,Y;
    cin >> N >> M >> X >> Y;
    vector<int> A(N), B(M);
    for(int i = 0; i < N; ++i) cin >> A[i];
    for(int i = 0; i < M; ++i) cin >> B[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    if(A[N-1] > X && A[N-1] < B[0] && B[0] <= Y) cout << "No War" << '\n';
    else cout << "War" << '\n';
    return 0;
}

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

typedef long long ll;
#define rep(i, s, n) for(int i=s;i<n;i++)
#define repeq(i,s,n) for(int i=s;i<=n;i++)
#define MOD 10e9+7

void max_self(int& a, int b) { a=a>b?a:b; }
void min_self(int& a, int b) { a=a<b?a:b; }

using namespace std;

int n, k;

const int MAX_N = 2e5+5;

int st[MAX_N*2];

void build() {
    for(int i = n-1; i > 0; i--)
        st[i]=max(st[i<<1],st[i<<1|1]);
}

int range(int l, int r) {
    int p = 0;

    for(l+=n, r+=n; l < r; l>>=1, r>>=1) {
        if(l&1) max_self(p, st[l++]);
        if(r&1) max_self(p, st[--r]);
    }

    return p;
}



int main() {
    
    cin >> n;
    
    for(int i = n; i < 2*n; i++)
        cin >> st[i];
    
    build();
    
    cout << range(1,n) << endl;

    for(int i = 1; i < n-1; i++) {
        int temp = max(range(0,i),range(i+1,n));
        cout << temp << endl;
    }
    int temp2 = range(0,n-1);
    cout << temp2 << endl;
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define rep(i, l, r) for (__typeof(l) i = (l); i <= (r); ++i)
#define per(i, r, l) for (__typeof(r) i = (r); i >= (l); --i)
using namespace std;
typedef long long ll;
const int mod = 998244353;
int read() {
	int f = 1, x = 0; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return f * x;
}
int qpow(int a, int b) { int res = 1; while (b) { if (b & 1) res = (ll)res * a % mod; a = (ll)a * a % mod; b >>= 1; } return res; }
string s;
int main() {
	cin >> s;
	puts(s[2] == s[3] && s[4] == s[5] ? "Yes" : "No");	
	return 0;
}


Measured memory_bytes: 256
import math

def isPrime(n):
    for i in range(2, int(math.sqrt(n) + 1)):
        if n%i == 0:
            return False
    return True

if __name__=='__main__':
    N = int(input())
    _ = 0
    for i in range(N):
        if isPrime(int(input())):
            _ += 1
    print(_)


Measured memory_bytes: 5672
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
//#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000000000;
const int mod = 1000000007;
int test[12345678], cost[12345678];
signed main() {
	vector<int> v;
	int n, m, a, b, cnt = 0, ans = 0; string s, t;
	cin >> n >> m >> a >> b;
	for (int h = 0; h < 1000; h++) {
		if (h % 2 == 0) {
			a -= m;
		}
		else {
			n -= b;
		}
		if (a <= 0) { cout << "Yes" << endl; return 0; }
		if (n <= 0) { cout << "No" << endl; return 0; }
	}
	return 0;
}

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

typedef struct Node {
  Node *left, *right;
  int data;
} Node;

Node* base;

void Node_init() {
  base = new Node();
  base->right= base;
  base->left  = base;
  return;
}

void Node_insert(int x) {
  Node *node = new Node();
  node->data = x;
  node->right = base->right;
  node->left  = base;
  base->right->left = node;
  base->right = node;
  return;
}

void Node_delete(int x) {
  Node *node = base->right;
  while( node != base ) {
    if( node->data == x ) {
      node->right->left = node->left;
      node->left->right = node->right;
      delete node;
      return;
    }
    node = node->right;
  }
  return;
}

void Node_deleteFirst(void) {
  Node *node = base->right;
  node->right->left = node->left;
  node->left->right = node->right;
  delete node;
  return;
}

void Node_deleteLast(void) {
  Node *node = base->left;
  node->right->left = node->left;
  node->left->right = node->right;
  delete node;
  return;
}

void Node_print(void) {
  Node *node = base->right;
  while( node != base ) {
    if( node->right == base ) {
      printf("%d\n", node->data);
      return;
    }
    else {
      printf("%d ", node->data);
    }
    node = node->right;
  }
  return;
}

int main(void) {

  int N;
  char str[256];
  int x;

  Node_init();
  
  std::cin >> N;
  for(int i = 0; i < N; ++i) {
    scanf("%s", str);
    if( strcmp(str,"insert") == 0 ) {
      scanf("%d", &x);
      Node_insert(x);
    }
    else if( strcmp(str, "delete") == 0 ) {
      scanf("%d", &x);
      Node_delete(x);
    }
    else if( strcmp(str, "deleteFirst") == 0 ) {
      Node_deleteFirst();
    }
    else if( strcmp(str, "deleteLast") == 0 ) {
      Node_deleteLast();
    }
    else {
      std::cout << "Error : " << str << std::endl;
      exit(1);
    }
  }

  Node_print();

  return 0;
}

Measured memory_bytes: 32412
#include <cstdio>
#include <vector>
#include <algorithm>

int gcd(int m, int n) {
  while (n) std::swap(m %= n, n);
  return m;
}

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

  int res = 0;
  for (int i = 0; i < N; ++i) {
    int a;
    scanf("%d", &a);
    res = gcd(res, a);
  }
  printf("%d\n", res);
}


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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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


signed main() {

	string S;
	int K;
	int N;
	cin >> S;
	cin >> K;
	N = S.length();

//	string S2 = S + S;

	
	//先頭と末尾が異なる場合
	if (S[0] != S[N - 1]) {
		int cnt = 0;
		int p = 0;
		for (; p < S.length();) {
			int q = p;
			while (q < S.length() && S[p] == S[q]) q++;
			cnt += (q - p) / 2;
			p = q;
		}
		cout << cnt * K << endl;
	}
	else {
		// 先頭と末尾が同じ場合
		// 先頭を数える
		int top=0, last = 0;
		for (int i = 0; i < S.length(); i++) {
			if (S[i] != S[0]) {
				top = i; break;
			}
		}
		// 末尾
		for (int i = S.length()-1; i >=0; i--) {
			if (S[i] != S[N-1]) {
				last = N-1-i; break;
			}
		}
		// 全部同じケース
		if (top == 0 && last == 0) {
			cout << N * K / 2 << endl;
			return 0;
		}

		int cnt = 0;
		int p = top;
		for (; p < S.length()-last-1;) {
			int q = p;
			while (q < S.length() && S[p] == S[q]) q++;
			cnt += (q - p) / 2;
			p = q;
		}

//		cerr << top << " " << last << endl;
		cout << cnt * K + (top + last) / 2 * (K - 1) + top / 2 + last / 2 << endl;
	}



	return 0;
}


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

int main(){
	int h,w ; 
	cin >> h >> w ;
	vector<vector<char>> field(h+2,vector<char>(w+2,'.')) ;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin >> field.at(i).at(j) ;
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(field.at(i).at(j)=='#'){
				cout << '#' ;
				continue ;
			}
			int cnt = 0 ;
			if(field.at(i-1).at(j-1)=='#') cnt++ ;
			if(field.at(i-1).at(j)=='#') cnt++ ;
			if(field.at(i-1).at(j+1)=='#') cnt++ ;
			if(field.at(i).at(j-1)=='#') cnt++ ;
			if(field.at(i).at(j+1)=='#') cnt++ ;
			if(field.at(i+1).at(j-1)=='#') cnt++ ;
			if(field.at(i+1).at(j)=='#') cnt++ ;
			if(field.at(i+1).at(j+1)=='#') cnt++ ;
			cout << cnt ;
		}
		cout << endl ;
	}
}

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

using namespace std;

const int MaxN = 4e5 + 25;

int n;
int a[MaxN], b[MaxN];
int c[MaxN], d[MaxN];

long long solve(vector <int> & a, vector <int> & b, int h)
{
    long long res = 0;
    int l = 0;

    for(int i = a.size() - 1; i >= 0; --i)
    {
        while(l < b.size() && b[l] + a[i] < h)
            ++l;
        res += b.size() - l;
    }
    return res;
}

long long solve1(vector <int> & a, vector <int> & b, int h)
{
    long long res = 0;

    int l = b.size() - 1;
    h += h;

    for(int i = 0; i < a.size(); ++i)
    {
        while(l >= 0 && a[i] + b[l] >= h)
            --l;
        res += l + 1;
    }

    return res;
}

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

    cin >> n;

    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    for(int i = 1; i <= n; ++i)
        cin >> b[i];

    int res = 0;

    for(int bit = 0; bit <= 29; ++bit)
    {
        int curH = (1 << bit);

        vector <int> va[2], vb[2];

        for(int i = 1; i <= n; ++i)
        {
            c[i] = a[i] % curH;
            d[i] = b[i] % curH;

            if(a[i] & curH)
                va[1].push_back(c[i]);
            else
                va[0].push_back(c[i]);

            if(b[i] & curH)
                vb[1].push_back(d[i]);
            else
                vb[0].push_back(d[i]);
        }

        for(int i = 0; i < 2; ++i)
        {
            sort(va[i].begin(), va[i].end());
            sort(vb[i].begin(), vb[i].end());
        }

        long long ans = 0;

        ans += solve(va[0], vb[0], curH);
        ans += solve(va[1], vb[1], curH);

        ans += va[0].size() * 1ll * vb[1].size() - solve(va[0], vb[1], curH);
        ans += va[1].size() * 1ll * vb[0].size() - solve(va[1], vb[0], curH);

        if(ans & 1)
            res += curH;
    }

    cout << res << '\n';

    return 0;
}


Measured memory_bytes: 8612
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>
#include <functional>
#include <iomanip>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n;
	cin >> n;
	
	ll ans = 0;
	
	for(int i = 1; i < n; ++i) {
		ans += (n - 1) / i;
	}
	
	cout << ans << endl;
	
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  int64_t l0 = 2, l1 = 1;
  for(int i = 1; i < N; i++){
    int64_t tmp = l1;
    l1 = l0 + l1;
    l0 = tmp;
  }
  cout << l1 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


void solve()
{
    int n;
    scanf("%d", &n);
    int i;
    int maxb=0;
    int max=0;
    for(i=0; i<n; i++) {
        int a,b;
        scanf("%d%d", &a, &b);
        if(max<a) {
            max=a;
            maxb=b;
        }
    }
    printf("%d\n", max+maxb);

    return;
}


int main(int argc, char* argv[])
{
#if 1
	solve();
#else
	int T; scanf("%d", &T);
	while (T--) {
		solve();
	}
#endif
	return 0;
}


Measured memory_bytes: 128
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static long Mod = (long)1e9 + 7;
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }
        static void Solve()
        {
            (long W, long H, long N) = Slice3<long>();
            long xl = 0;long xh = W;
            long yl = 0;long yh = H;
            
            for (var i = 0; i < N; ++i)
            {
                (long x, long y, long a) = Slice3<long>();
                if (a == 1) xl = Max(xl, x);
                if (a == 2) xh = Min(xh, x);
                if (a == 3) yl = Max(yl, y);
                if (a == 4) yh = Min(yh, y);
            }
            if (xh <= xl || yh <= yl)
                WriteLine(0);
            else
                WriteLine((xh - xl) * (yh - yl));
        }
    }
}

Measured memory_bytes: 27412
#include <stdio.h>
#define N 100000

int n,S[N];

int binary(int key){
  int left,m,right;
    left = 0;
    right = n;
    while(left < right){
      m = (left + right)/2;
      if(key == S[m])return 1;
      else if(key > S[m])left = m + 1;
      else if(key < S[m])right = m;
    }
    return NULL;
}

int main(){
  int q,key,i,count = 0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&S[i]);
  
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if(binary(key)==1)count++;
  }

  printf("%d\n",count);
  
  return 0;
}



Measured memory_bytes: 2108
N, x = map(int, input().split())
a = sorted(list(map(int, input().split())))
count = 0
for i in range(N):
    x -= a[i]
    count += 1
    if x == 0:
        break
    elif x < 0:
        count -= 1
        break
    elif (i == (len(a) - 1)) and (x > 0):
        count -= 1
print(count)

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

int main(){
 int start,end;
  cin >> start >> end;
  
  int count = 0;
  for(int i = start; i <= end; i++){
    int N;
    N = i;
    int n1,n2,n3,n4,n5;
    n1 = N / 10000;
    n2 = (N - n1*10000) /1000;
    n3 = (N - n1*10000 - n2*1000) /100;
    n4 = (N - n1*10000 - n2*1000 - n3 *100) /10;
    n5 = (N - n1*10000 - n2*1000 - n3 *100 - n4*10);
    
    if(n1 == n5 && n2 ==n4){
      count++;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
# coding: utf-8
from operator import itemgetter
    
n, m = map(int, input().split())

stores = sorted([tuple(map(int,input().split())) for _ in range(n)])

price = 0
count = 0

for j in range(n):
    if count == m:
        break
    for k in range(int(stores[j][1])):
        if count < m:
            price += int(stores[j][0])
            count += 1
        else:
            break

print(price)


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

using namespace std;

int main() {
	int An=0, Bn=0, Cn=0;
	string As, Bs, Cs,cur;
	cin >> As >> Bs >> Cs;
	cur = 'a';
	while (1) {
		switch (cur[0]) {
		case 'a':
			cur = As[An];
			An++;
			break;
		case 'b':
			cur = Bs[Bn];
			Bn++;
			break;
		case 'c':
			cur = Cs[Cn];
			Cn++;
			break;
		}
		if (An-1 == As.size()) {
			cout << "A" << endl;
			break;
		}
		if (Bn-1 == Bs.size()) {
			cout << "B" << endl;
			break;
		}
		if (Cn-1 == Cs.size()) {
			cout << "C" << endl;
			break;
		}
	}
	return 0;
} 

Measured memory_bytes: 256
import scala.io.StdIn
object Main extends App {
  def avg(a: Double, b: Double): Double = { (a + b)/2.0 }
  val N = StdIn.readLine()
  val Vs = StdIn.readLine().split(" ").map(_.toDouble).toList.sorted
  println(Vs.tail.foldLeft(Vs.head)(avg))
}


Measured memory_bytes: 27320
x,n = map(int,input().split())
p = list( map(int,input().split()))

if n==0:
    print(x)
else:
    minp = min(min(p),x)
    maxp = max(max(p),x)
    
    mi=200
    ans=0
    for i in range(minp-1,maxp+2):
        if i not in p and abs(i-x)<mi:
                mi=abs(i-x)
                ans=i
    print(ans)

Measured memory_bytes: 61808
#include <stdio.h>
#include <string.h>

/* {1,2,3} -> ... -> {3,2,1} */
int next_permutation(char arr[],int n) {
	int target;
	int i;
	int temp;
	char* arr2;
	int n2;
	for(i=n-2;i>=0;i--) {
		if(arr[i]<arr[i+1])break;
	}
	if(i<0)return 0;
	target=i;

	/* inline reverse_arr */
	arr2=arr+target+1;
	n2=n-target-1;
	for(i=0;n2-i-1>i;i++) {
		int t;
		t=arr2[i];
		arr2[i]=arr2[n2-i-1];
		arr2[n2-i-1]=t;
	}

	for(i=target+1;i<n;i++) {
		if(arr[i]>arr[target])break;
	}
	temp=arr[i];
	arr[i]=arr[target];
	arr[target]=temp;
	return 1;
}

char statList[40320][12]; /* 8! */
int rinsetuList[40320][3];

int searchStat(const char* stat) {
	int left,right,mid;
	left=0;right=40320-1;
	while(left<=right) {
		int cmp;
		mid=(left+right)/2;
		cmp=strcmp(stat,statList[mid]);
		if(cmp==0)return mid;
		else if(cmp<0)right=mid-1; else left=mid+1;
	}
	return 0;
}

void makeStatList(void) {
	char now[]="01234567";
	int i=0;
	do {
		strcpy(statList[i++],now);
	} while(next_permutation(now,8));
}

void makeRinsetuList(void) {
	int i;
	for(i=0;i<40320;i++) {
		char buf[12];
		char tmp;
		int zeroPos;
		strcpy(buf,statList[i]);
		for(zeroPos=0;statList[i][zeroPos]!='0';zeroPos++);
		if(zeroPos==3 || zeroPos==7) {
			rinsetuList[i][0]=-1;
		} else {
			tmp=buf[zeroPos];
			buf[zeroPos]=buf[zeroPos+1];
			buf[zeroPos+1]=tmp;
			rinsetuList[i][0]=searchStat(buf);
			tmp=buf[zeroPos];
			buf[zeroPos]=buf[zeroPos+1];
			buf[zeroPos+1]=tmp;
		}
		if(zeroPos==0 || zeroPos==4) {
			rinsetuList[i][1]=-1;
		} else {
			tmp=buf[zeroPos];
			buf[zeroPos]=buf[zeroPos-1];
			buf[zeroPos-1]=tmp;
			rinsetuList[i][1]=searchStat(buf);
			tmp=buf[zeroPos];
			buf[zeroPos]=buf[zeroPos-1];
			buf[zeroPos-1]=tmp;
		}
		tmp=buf[zeroPos];
		buf[zeroPos]=buf[zeroPos^4];
		buf[zeroPos^4]=tmp;
		rinsetuList[i][2]=searchStat(buf);
	}
}

int cost[40320];

void dfs(int pos,int nowCost) {
	if(nowCost>=cost[pos])return;
	cost[pos]=nowCost;
	if(rinsetuList[pos][0]>=0)dfs(rinsetuList[pos][0],nowCost+1);
	if(rinsetuList[pos][1]>=0)dfs(rinsetuList[pos][1],nowCost+1);
	if(rinsetuList[pos][2]>=0)dfs(rinsetuList[pos][2],nowCost+1);
}

int main(void) {
	int i;
	int query[8];
	makeStatList();
	makeRinsetuList();
	for(i=0;i<40320;i++)cost[i]=1000000;
	dfs(searchStat("01234567"),0);
	while(scanf("%d%d%d%d%d%d%d%d",&query[0],&query[1],&query[2],&query[3],
	&query[4],&query[5],&query[6],&query[7])==8) {
		char qstr[12]={};
		for(i=0;i<8;i++)qstr[i]=query[i]+'0';
		printf("%d\n",cost[searchStat(qstr)]);
	}
	return 0;
}

Measured memory_bytes: 2128
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define out return 0
#define pii pair<ll,ll>
#define ll long long int
using namespace std;
ll mn=1e18,mx=-1e18;
const ll mv=1000005;
ll n,m,x[mv],y[mv],a[mv],b[mv],ans;
int main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cin>>n>>m;
	a[0]=1;
	for(int i=0;i<n;i++){
		b[i]=1;
	}
	for(int i=0;i<m;i++){
		cin>>x[i]>>y[i];
		x[i]--,y[i]--;
		b[y[i]]++;
		b[x[i]]--;
		if(a[x[i]]){
			a[y[i]]=1;
		}
		if(!b[x[i]]){
			a[x[i]]=0;
		}
	}
	for(int i=0;i<n;i++){
		ans+=a[i];
	}
	cout<<ans;
}

Measured memory_bytes: 11264
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

long long n, a[200010], mu, ans;
vector<long long> ta;

signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		ta.push_back(a[i] - (i - n));
	}
	sort(ta.begin(), ta.end());
	mu = ta[n / 2];
	rep(i, n) ans += abs((i + mu - n) - a[i]);
	cout << ans << endl;
	ggr
}


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

#define MAX_N 200005
#define MAX_M 100005

#define pb push_back
#define mp make_pair
#define all(V) (V).begin(),(V).end()
#define reset(V) (V).clear();(V).resize(0);

#define sq(x) ((x)*(x))
#define abs(x) ((x)>0?(x):(-(x)))

#define fi first
#define se second

#define LL_inf (1LL<<60)
#define full_inf 0x7fffffff
#define half_inf 0x3fffffff
#define inf 0x3fffffff

#define MOD 1000000007LL

#define cpx_mod(x) (((LD)(((LL)x.real())%MOD)),((LD)(((LL)x.imag())%MOD)))


using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pil;
typedef pair<LL,string> pls;
typedef complex<LD> Complex;
typedef long double LD;
int d[5];
int main(){
	for(int i=1;i<4;i++){
		int x,y;
		scanf("%d %d",&x,&y);
		d[x]++;d[y]++;
	}
	for(int i=1;i<=4;i++){
		if(d[i]>2 || d[i]<1)	return !printf("NO\n");
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
from string import ascii_lowercase


n = int(input())
dic = {c: 50 for c in ascii_lowercase}
for _ in range(n):
    tmp = Counter(input())
    for c in ascii_lowercase:
        dic[c] = min(dic[c], tmp.get(c, 0))
print(''.join(c * dic[c] for c in ascii_lowercase))

Measured memory_bytes: 3768
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: Chars
    };

    let n = n
        .into_iter()
        .map(|ch| ch.to_digit(10).unwrap() as isize)
        .rev()
        .chain(vec![0])
        .collect::<Vec<_>>();
    let len = n.len();
    // dp[i][j] = 最小のコイン数
    // i: 後ろからi桁目まで見た
    // j: 0: 繰り下がりがない, 1: 繰り下がりがある
    let mut dp = vec![vec![1_isize << 30; 2]; len + 1];
    dp[0][0] = 0;
    for i in 0..len {
        let a = n[i];
        for j in 0..2 {
            for b in 0_isize..=9 {
                let to_i = i + 1;
                let x = b - if j == 0 { 0 } else { 1 };
                if x >= a {
                    let to_j = 0;
                    dp[to_i][to_j] = dp[to_i][to_j].min(dp[i][j] + b + (x - a));
                } else {
                    let to_j = 1;
                    dp[to_i][to_j] = dp[to_i][to_j].min(dp[i][j] + b + (x - a + 10));
                }
            }
        }
    }
    println!("{}", dp[len][0].min(dp[len][1]));
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


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


int main(){
int n;
cin>>n;
    vector<int> p(n);
    vector<int> q(n);
    int countp=0;
    int countq=0;
    
    rep(i,n)cin>>p[i];
    rep(i,n)cin>>q[i];
    while(prev_permutation(p.begin(),p.end())){
countp++;
    }
    while(prev_permutation(q.begin(),q.end())){
countq++;
    }
    cout<<abs(countp-countq)<<endl;
    
    return 0;

}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    int k,x;
    cin >> k >> x;
    if(500*k>=x) cout << "Yes";
    else cout << "No";

    return 0;
}

Measured memory_bytes: 3612
/**
 * Title:
 * Url:
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    int n, q; cin >> n >> q;
    vector<vector<int>> g(n+1);
    for(int i=0; i<n-1; i++) {
        int ai, bi; cin >> ai >> bi;
        g[ai].push_back(bi);
        g[bi].push_back(ai);
    }
    g[0].push_back(1);
    
    map<int, ll> dic;
    for(int i=0; i<q; i++) {
        int pi, xi; cin >> pi >> xi;
        if(dic.count(pi)>0) {
            dic[pi] += xi;
        } else {
            dic[pi] = xi;
        }
        
    }

    map<int, int> used;
    for(int i=0; i<n; i++) {
        used[i+1] = 0;
    }
    vector<ll> ans(n+1, 0);
    queue<pair<int, ll>> que;
    que.push(make_pair(0, 0));
    while(!que.empty()) {
        auto pi = que.front();
        que.pop();
        used[pi.first] = 1;
        ll pt = 0;
        if(dic.count(pi.first)>0) {
            pt = dic[pi.first];
        }
        ans[pi.first]=pi.second+pt;
        for(auto ei:g[pi.first]) {
            if(used[ei]==0) {
                que.push(make_pair(ei, pi.second+pt));
            }
        }
    }

    for(int i=1; i<n+1; i++) {
        if(i==n) {
            cout << ans[i] << endl;
        } else {
            cout << ans[i] << " "; 
        }
    }


    return 0;
}

Measured memory_bytes: 39668
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main(){
  int n,k; cin >> n >> k;
  double ans = 0.0;
  for (int i=1; i<=n; i++){
    double tmp = 1.0/n;
    int now = i;
    while(now < k){
      now *= 2;
      tmp /= 2;
    }
    ans += tmp;
  }
  cout << setprecision(10) << ans << endl;
}

Measured memory_bytes: 3696
fn solve(ksss: Vec<Vec<u64>>, ps: Vec<u64>, n: usize) -> usize {
    let mut result = 0;
    let sss: Vec<Vec<u64>> = ksss.iter()
        .map(|kss| kss.iter().skip(1).map(|s| s - 1).collect::<Vec<_>>())
        .collect();

    for bins in binary_combinations(n) {
        if (0..ps.len()).all(|i| sss[i].iter().filter(|&s| bins[*s as usize]).count() % 2 == ps[i] as usize) {
            result += 1
        }
    }

    result
}

fn binary_combinations(n: usize) -> Vec<Vec<bool>> {
    fn rec(n: usize, mut acc: Vec<Vec<bool>>) -> Vec<Vec<bool>> {
        if n == 0 {
            acc
        } else {
            let mut tmp = acc.clone();
            acc.iter_mut().for_each(|v| v.push(false));
            tmp.iter_mut().for_each(|v| v.push(true));
            acc.extend(tmp);

            rec(n - 1, acc)
        }
    }

    rec(n, vec![vec![]])
}

fn main() {
    let (n, m) = read_tup2();
    let ksss = read_vec_n(m);
    let ps = read_vec();

    println!("{}", solve(ksss, ps, n));
}

fn read_tup2<T: std::str::FromStr + Copy>() -> (T, T) {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let v = s.trim().split_whitespace()
        .map(|c| c.parse().ok().unwrap())
        .collect::<Vec<T>>();
    (v[0], v[1])
}

fn read_vec_n<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    let mut ss = String::new();
    for _ in 0..n {
        std::io::stdin().read_line(&mut ss).ok();
    }
    let mut v = ss.split("\n").collect::<Vec<&str>>();
    v.pop();
    v.iter()
        .map(
            |s| {
                s.trim().split_whitespace()
                    .map(|c| c.parse().ok().unwrap())
                    .collect()
            }
        )
        .collect()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|c| c.parse().ok().unwrap())
        .collect()
}


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

char rankCheck(int m, int f, int r) {
	int total = m + f;
	if (m == -1 || f == -1 || total <30)
		return 'F';
	if (total >= 80)
		return 'A';
	if (total >= 65)
		return 'B';
	if (total >= 50 || r >= 50)
		return 'C';
	else
		return 'D';
}

int main() {
	int middle, fin, retest;
	while(true) {
		cin >> middle >> fin >> retest;
		if (middle == -1 && fin == -1 && retest == -1)
			break;
		cout << rankCheck(middle, fin, retest) << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
  int s ;
  cin >> s ;
  
  vector<int> ss(s) ;
  
  for(int i=0;i<s;i++){
    cin >> ss[i] ;
}
  
  sort(ss.begin(),ss.end(), greater<int>()) ;
  
  int ct = 0 ;
  for(int i=1;i<s;i++){
    ct += ss[i] ;
  }
  
  if(ct>ss[0])
    cout << "Yes" << endl ;
  else
    cout << "No" << endl ;
  
  return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

int main() {
  i64 H, N;
  cin >> H >> N;
  i64 sum = 0;
  rep(i,0,N) {
    i64 a;
    cin >> a;
    sum += a;
  }
  if(H <= sum) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 100000000000000009
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

vector<P> prime_factorize(int a){
  vector<P> ans;
  for(int i = 2;i*i <= a;i++){
    int num = 0;
    if(a % i == 0){
      while(a % i == 0){
        num++;
        a /= i;
      }
      ans.push_back(make_pair(i,num));
    }
  }
  if(a != 1) ans.push_back(make_pair(a,1));
  return ans;
}

int gcd(int a,int b){
  if(a < b) swap(a,b);
  if(b == 0) return a;
  return gcd(a%b,b);
} 

signed main(){
  int a,b;
  cin >> a >> b;
  int GCD = gcd(a,b);
  auto PRI = prime_factorize(GCD);
  int ans = 0;
  //cout << GCD << endl;
  for(auto u:PRI){
    if(u.first == 1) break;
    //cout << u.first << endl;
    ans++;
  }
  cout << ans + 1 << endl;
}

Measured memory_bytes: 256