akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define nth(n)  (1LL << n)

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

    vector<lint> key(m, 0);
    vector<lint> cost(m);
    for(lint i=0; i<m; i++) {
        lint a, b;
        cin >> a >> b;
        cost[i] = a;
        for(lint j=0; j<b; j++) {
            lint c;
            cin >> c;
            c--;
            key[i] += nth(c);
        }
    }

    vector<lint> dp(nth(n), LLONG_MAX);
    dp[0] = 0;
    for(lint bit=0; bit<nth(n); bit++)
    for(lint i=0; i<m; i++) {
        if(dp[bit] == LLONG_MAX)  continue;
        dp[bit|key[i]] = min(dp[bit|key[i]], dp[bit]+cost[i]);
    }

    if(dp[nth(n) - 1] == LLONG_MAX)  cout << -1 << endl;
    else  cout << dp[nth(n) - 1] << endl;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;

#define rep(i, a, b) for(auto i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back

struct edge{int to;};
using graph = vector<vector<edge>>;

ll simulate(ll curr, int years) {
  rep(i, 0, years) {
    curr += curr / 100;
  }
  return curr;
}

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

  ll x;
  cin >> x;

  int lo = 0, hi = 3800;
  while (lo < hi) {
    auto mid = (lo + hi) / 2;
    if (simulate(100, mid) < x) {
      lo = mid + 1;
    } else {
      hi = mid;
    }
  }
  cout << lo << '\n';
  
}


Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>
#include<utility>

typedef long long ll;

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define P pair<int, int>
#define PLI pair<ll, int>
#define PLL pair<ll, ll>

using namespace std;


int H, W, N;
int main() {
	while (cin >> H >> W >> N, H)
	{
		vector<vector<int>> sign(H, vector<int>(W));
		rep(i, H) rep(j, W) {
			cin >> sign[i][j];
		}
		
		vector<vector<int>> dp(H+1, vector<int>(W+1));
		dp[0][0] = N - 1;
		rep(i, H) rep(j, W){
			dp[i + 1][j] += dp[i][j] / 2;
			dp[i][j + 1] += dp[i][j] / 2;
			if (sign[i][j] == 0) dp[i + 1][j] += dp[i][j] % 2;
			else dp[i][j + 1] += dp[i][j] % 2;
		}

		int x = 0, y = 0;
		while (x < H && y < W)
		{
			if ((sign[x][y] + dp[x][y]) % 2 == 0) x++;
			else y++;
		}


		cout << x + 1 << ' ' << y + 1 << endl;
	}

	return 0;
}



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

using namespace std;

#ifdef LOCAL_DEFINE
  #include "../../library/DEBUG.hpp"
#else
  #define debug(...) 0
#endif

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  int total = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    total ^= a[i];
  }
  for (int i = 0; i < n; i++) {
    cout << (total ^ a[i]) << " ";
  }
  cout << '\n';
  return 0;
}

Measured memory_bytes: 3936
#include <stdio.h>
 
int main(){
    int i, j, hit, blow, a[4], b[4];

    while(scanf("%d", &a[0]) != EOF){
        hit = blow = 0;
        
        for(i = 1; i < 4; i++) scanf("%d", &a[i]);
        for(i = 0; i < 4; i++) scanf("%d", &b[i]);
        
        for(i = 0; i < 4; i++)
            for(j = 0; j < 4; j++)
                if(a[i] == b[j])
                    if(i == j) hit++;
                    else blow++;
        
        printf("%d %d\n", hit, blow);
    }
 
    return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
long long gcd(long long a,long long b){
    a=a%b;
    if(a==0)return b;
    else if(a==1)return 1;
    else return gcd(b,a);
}
int main(void){
    long long i,j,k,s,ans=0;
    scanf("%lld",&s);
    for(i=1; i<=s; i++){
        for(j=1; j<=s; j++){
            for(k=1; k<=s; k++){
                ans+=gcd(i,gcd(j,k));
            }
        }
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define mod ((ll)1e9+7)
#define inf 0x3f3f3f3f
#define infl 0x3f3f3f3f3f3f3f3f
#define Ninf -0x3e3e3e3f
#define Ninfl -0x3e3e3e3e3e3e3e3f
#define maxx ((ll)1e5+5)
#define endl "\n"
#define time(i) cout<<"\nTime Elapsed "<<i<<" : " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expm(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
ll add(ll x, ll y) { x += y; if (x >= mod) return x-mod; return x;}
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + mod; return x;}
ll mult(ll x, ll y) { return (x * y) % mod;}
ll rev(ll x) { return expm(x, mod - 2);}
/*
bool sv[maxx]={0};    // returns 0 if a num is prime
int sp[maxx]={0};     // gives smallest prime factor of the number
void Sieve() {for(int i= 2; i< maxx; i+= 2) sv[i]=1,sp[i] = 2;sv[2]=0;for(ll i = 3; i < maxx; i += 2){if (!sv[i]){sp[i] = i;for (ll j = i; (j*i) < maxx; j += 2){if (!sv[j*i])sv[j*i] = true, sp[j*i] = i;}}}}
ll fact[maxx]={0}; // returns factorial of that number
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<maxx;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncrm(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expm(fact[r],mod-2)))%mod; res=(res*(expm(fact[n-r],mod-2)))%mod; return res;}
ll inv[maxx];   // returns the modular inverse of number
void inversify( ll m){inv[1]=1;for(int i=2;i<maxx;i++){inv[i]= m- m/i*inv[m%i]%m;}}
ll ncr(ll n,ll r,ll m){int ans=1;for (int i = 0; i < r; i++){ans=ans*(n-i)%m*inv[i+1]%m;}return ans;}
*/
signed main(){
  fast;
  //test
  {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    bool ok=0;
    while(1)
    {
      c=c-b;
      if(c<=0)
      {
        cout<<"Yes";
        break;
      }
      a=a-d;
      if(a<=0)
      {
        cout<<"No";
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3648
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

ll gcd(ll a, ll b) {
	while (b) {
		ll q = a % b;
		a = b;
		b = q;
	}
	return a;
}

int solve() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a < b || d < b)
		return 0;
	if (c >= b)
		return 1;
	d %= b;
	a %= b;
	ll l = c + 1;
	ll r = b;
	r -= l;
	a -= l;
	if (a < 0)
		a += b;
	l = 0;
	d = gcd(d, b);
	if (r >= d)
		return 0;
	if (a % d >= r)
		return 1;
	else
		return 0;
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	int tt;
	cin >> tt;
	for (int i = 0; i < tt; ++i) {
		int x = solve();
		if (x)
			cout << "Yes\n";
		else
			cout << "No\n";
	}
	return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	final int N = 4;
	final int N2 = 16;
	final int LIMIT = 45;

	class Puzzle {
		int[] board = new int[N2];
		int space, md;
		Puzzle() {}
		Puzzle(Puzzle p) {
			space = p.space;
			md = p.md;
			for (int i = 0; i < N2; i++)
				board[i] = p.board[i];
		}
		int getAllMD() {
			int sum = 0;
			for (int i = 0; i < N2; i++) {
				if (board[i] == N2) continue;
				sum += mdt[i][board[i] - 1];
			}
			return sum;
		}
		void swap(int next, int cur) {
			int tmp = this.board[cur];
			this.board[cur] = this.board[next];
			this.board[next] = tmp;
		}
	}

	int limit = 0;
	int[] path = new int[LIMIT];
	int[][] mdt = new int[N2][N2];
	Puzzle state = null;
	char[] dir = {'r', 'u', 'l', 'd'};
	int[] dx = { 0, -1, 0, 1 };
	int[] dy = { 1, 0, -1, 0 };

	void run() {
		Scanner scan = new Scanner(System.in);
		
		for (int i = 0; i < N2; i++)
			for (int j = 0; j < N2; j++)
				mdt[i][j] = Math.abs(i / N - j / N) + Math.abs(i % N - j % N);

		Puzzle p = new Puzzle();
		
		for (int i = 0; i < N2; i++) {
			p.board[i] = scan.nextInt();
			if (p.board[i] == 0) {
				p.board[i] = N2;
				p.space = i;
			}
		}
		iterative_deepening(p);
	}
	boolean dfs(int depth, int prev) {
		if (state.md == 0) return true;
		if (depth + state.md > limit) return false;

		int sx = state.space / N;
		int sy = state.space % N;
		for (int i = 0; i < 4; i++) {
			int tx = sx + dx[i];
			int ty = sy + dy[i];
			if (tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
			if (Math.max(prev, i) - Math.min(prev, i) == 2) continue;
			Puzzle p = new Puzzle(state);
			state.md -= mdt[tx * N + ty][state.board[tx * N + ty] - 1];
			state.md += mdt[sx * N + sy][state.board[tx * N + ty] - 1];
			state.swap(tx * N + ty, sx * N + sy);
			state.space = tx * N + ty;
			if (dfs(depth + 1, i)) {
				path[depth] = i;
				return true;
			}
			state = p;
		}
		return false;
	}
	void iterative_deepening(Puzzle p) {
		p.md = p.getAllMD();
		
		for (limit = p.md; limit <= LIMIT; limit++) {
			state = new Puzzle(p);
			if (dfs(0, -100)) {
				System.out.println(limit);
				return;
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 283160
#include <bits/stdc++.h>
#define int long long
using namespace std;

int H, W;
vector<string> vs;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

pair<int, int> dfs(int y, int x, auto& vis) {
    vis[y][x] = true;

    pair<int, int> p;
    p = {vs[y][x] == '#', vs[y][x] == '.'};
    for (int i = 0; i < 4; i++) {
        int ny = y + dy[i];
        int nx = x + dx[i];

        if (ny < 0 || nx < 0 || ny >= H || nx >= W) continue;
        if (vis[ny][nx] || vs[y][x] == vs[ny][nx]) continue;

        auto t = dfs(ny, nx, vis);
        p.first += t.first;
        p.second += t.second;
    }

    return p;
}
signed main() {
    cin >> H >> W;

    vs.resize(H);
    for (auto& s : vs) cin >> s;

    vector<vector<bool>> vis(H, vector<bool> (W));
    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (vs[i][j] == '.') continue;
            if (vis[i][j]) continue;
            auto p = dfs(i, j, vis);
            ans += p.first * p.second;
        }
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 20480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main(){
  int N, M;
  cin >> N >> M;
  int ans = 0;
  if (N == 0 && M != 0) ans = M * (M - 1) / 2;
  else if (M == 0 && N != 0) ans = N * (N - 1) / 2;
  else if (N == 0 && M == 0) ans = 0;
  else ans = N * (N - 1) / 2 + M * (M - 1) / 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,m,n) for(ll i=(m);i<(n);i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back








ll kaijou(ll a, ll b){

    if (b==0){
        return 1;
    }

    else if (b==1){
        return a%MOD;
    }

    else if (b%2==0){
        return ((kaijou(a,b/2)%MOD)*(kaijou(a,b/2)%MOD))%MOD;
    }

    else if(b%2==1){
         return ((((kaijou(a,b/2)%MOD)*(kaijou(a,b/2)%MOD))%MOD)*a)%MOD;
        
    }

}




ll combi(ll a, ll b, vector<ll> &pjou){
    ll tmp=1;

    for (ll k=1;k<=b;k++){
        tmp=(((tmp*(a-k+1))%MOD)*pjou.at(k))%MOD;
    }

    return tmp;
}


int main(){

    int s;
    cin>>s;

    int kosu=s/3;
  





    vector<ll> pjou(2000);

    rep(i,2000){
        pjou.at(i)=kaijou(i,MOD-2);
    }

    ll answer=0;

	
    for (int i=1;i<=kosu;i++){

        answer+=combi(s-2*i-1,i-1, pjou);
        answer%=MOD;



    }

    cout<<answer<<endl;
















}

Measured memory_bytes: 3636
def main():
    N = int(input())
    A = [int(v) for v in input().split()]

    balls = {}
    for a in A:
        if a in balls:
            balls[a] += 1
        else:
            balls[a] = 1

    total = 0
    dp = {}
    dp1 = {}
    for k, v in balls.items():
        u = v * (v - 1) // 2
        if u > 0:
            dp[k] = - u + (v - 2) * (v - 1) // 2
        else:
            dp[k] = 0
        total += u

    for k in A:
        print(total + dp[k])

main()

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

using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;

#define out(a) cout << a << endl
#define out1(a) cout << a
#define in(a) cin >> a
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define rep(i, N) for (ll i = 0; i < (ll)N; i++)
#define rep1(i, N) for (ll i = 1; i <= (ll)N; i++)
#define repi(i, j, N) for (ll j = (ll)i + 1; j < (ll)N; j++)
#define all(v) v.begin(), v.end()

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;
constexpr ll mod = 1e9 + 7;

void solve();

int main()
{
    solve();
}

void solve()
{
    int n, m, x;
    in3(n, m, x);
    int a[n][m];
    int c[n];
    rep(i, n)
    {
        in(c[i]);
        rep(j, m)
        {
            in(a[i][j]);
        }
    }
    int ans = inf;
    for (int bit = 0; bit < (1 << n); bit++)
    {
        int sum_c = 0;
        int sum_a[m];
        rep(i, m)
        {
            sum_a[i] = 0;
        }
        rep(i, n)
        {
            if (bit & (1 << i))
            {
                sum_c += c[i];
                rep(j, m)
                {
                    sum_a[j] += a[i][j];
                }
            }
        }
        int flag = 1;
        rep(i, m)
        {
            if (sum_a[i] < x)
            {
                flag = 0;
                break;
            }
        }
        if (flag)
            chmin(ans, sum_c);
    }
    if (ans == inf)
    {
        out("-1");
    }
    else
        out(ans);
}

Measured memory_bytes: 3632
let answer r d x =
  let rec hoge r d x n =
    if n = 1 then
      string_of_int (r * x - d)
    else
      string_of_int (r * x -d) ^ "\n" ^ hoge r d (r * x -d) (n - 1)
  in
  hoge r d x 10

let () = Scanf.scanf "%d %d %d" (fun r d x -> print_endline ((answer r d x)))


Measured memory_bytes: 384
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

#define int LL

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

signed main()
{
	ios_init();
	int n;
	while(cin >> n) {
		vector<int> a(n);
		REP(i,n) cin >> a[i];
		sort(ALL(a));
		vector<bool> v(n);
		int sum = accumulate(ALL(a),0ll);
		v[n-1] = true;
		int ans = 0;
		RREP(i,n-1){
			sum -= a[i+1];
			if(a[i+1] <= sum*2){
				v[i] = v[i+1];
			}else{
				v[i] = false;
			}
		}
		REP(i,n) ans += v[i];
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;

  int maxx = -INF;
  REP(i, N) {
    int x;
    cin >> x;
    if (maxx < x) maxx = x;
  }
  int miny = INF;
  REP(i, M) {
    int y;
    cin >> y;
    if (miny > y) miny = y;
  }

  for (int Z = X + 1; Z <= Y; Z++) {
    if (maxx < Z && miny >= Z) {
      cout << "No War" << endl;
      return 0;
    }
  }
  cout << "War" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n; cin>>n; vector<int>L(n); int ans=0;
  rep(i,n) cin>>L[i];
  
  sort(L.begin(),L.end());
  
   rep(i,n-2) for(int k=i+1;k<n-1;k++){
    
     if(L[i]+L[k]<=L[n-1]) ans+=lower_bound(L.begin(),L.end(),L[i]+L[k])-L.begin()-k-1;
   else ans += n-k-1;
   }
  cout<<ans<<endl;
  
}


Measured memory_bytes: 256
s = str(input())
s = s.replace('BC', 'D')
n = len(s)

ans = 0
cnt = 0
for i in range(n):
    if s[i] == 'A':
        cnt += 1
    if s[i] == 'D':
        ans += cnt
    if s[i] == 'B' or s[i] == 'C':
        cnt = 0
print(ans)

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

typedef long long ll;
using namespace std;

int main() {
    int n;
    cin >> n;
    int maxv = 0;
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        int p;
        cin >> p;
        maxv = max(maxv, p);
        sum += p;
    };
    sum -= maxv / 2;
    cout << sum;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

vector<vector<pii> > graph;
vector<int> min_cost;
 
void Dijkstra(int s){
   
  priority_queue<pii, vector<pii>, greater<pii> > pq;
  min_cost[s] = 0;
  pq.emplace(0, s);
   
  while(!pq.empty()){
    int now_cost, now_node;
    tie(now_cost, now_node) = pq.top();
    pq.pop();
     
    if(min_cost[now_node] < now_cost){
      continue; 
    }
     
    for(int i = 0; i < graph[now_node].size(); ++i){
      int next_node, next_cost;
      tie(next_node, next_cost) = graph[now_node][i];
 
      if(min_cost[now_node] + next_cost < min_cost[next_node]){
        min_cost[next_node] = min_cost[now_node] + next_cost;
        pq.emplace(min_cost[next_node], next_node);
      }
    }
  }
}
 
signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
   
  int N, X, Y;
  cin >> N >> X >> Y;
  if(X > Y){
    swap(X, Y);
  }
  min_cost.resize(N+1, INF);
  graph.resize(N+1);
   
  for(int i = 1; i < N; ++i){
    graph[i].emplace_back(i+1, 1); 
    graph[i + 1].emplace_back(i, 1);
  }
  graph[X].emplace_back(Y, 1);
  graph[Y].emplace_back(X, 1);
   
  Dijkstra(1);
  int ans[N + 5] = {};
  reps(i, N){
    for(int j = i + 1;j <= N;j ++){
      int nasu;
      if(X < i && i < Y){
	nasu = min(j - i, (i - X) + 1 + abs(Y,j));
      } else {
	nasu = min_cost[j] - min_cost[i];
      }
      ans[nasu] ++;
      // cout << i << " " << j << " " << nasu << '\n'; 
    }
  }
  reps(i, N - 1){
    cout << ans[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 384
bingo = [list(map(int, input().split())) for _ in range(3)]
def chec_line():
    ret = False
    for i in range(3):
        cnt = 0
        for j in range(3):
            if bingo[i][j] == -1:
                cnt += 1
        if cnt == 3:
            ret =True

    for i in range(3):
        cnt = 0
        for j in range(3):
            if bingo[j][i] == -1:
                cnt += 1
        if cnt == 3:
            ret =True
    cnt = 0
    for i in range(3):
        if bingo[i][i] == -1:
            cnt += 1
    if cnt == 3:
        ret =True
    
    cnt = 0
    for i in range(3):
        if bingo[2-i][i] == -1:
            cnt += 1
    if cnt == 3:
        ret =True

    return ret
def check_num( num):
    for i in range(3):
        for j in range(3):
            if bingo[i][j] == num:
                bingo[i][j] = -1
                

n = int(input())
flag = False
for _ in range(n):
    check_num(int(input()))
    flag = chec_line() 
    if flag:
        break
if flag :
    print('Yes')
else:
    print('No')

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

typedef long long ll;

const int MOD = 1e9+7;

int main() {
	int N;
	string S;
	cin>>N>>S;
	vector<ll> cnt(26,0);
	rep(i,N){
		cnt[S[i]-'a']++;
	}
	ll ans  = 1;
	rep(i,26){
		if(cnt[i]>0){
			ans*=cnt[i]+1;
			ans%=MOD;
		}
	}
	cout<<ans-1<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <stdio.h>
#include <string.h>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x * x + y * y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;



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

	int N = SZ(S);
	int del = N - 7;

	for (int i=0;i<=N-del;++i)
	{
		string x = S.substr(0, i) + S.substr(i+del);
		if (x == "keyence")
		{
			printf("YES\n");
			return 0;
		}
	}
	printf("NO\n");


	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long

#ifdef sarthak
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#else
#define trace(...)
#endif

#ifndef sarthak
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

#define foreach(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fort(i,v) for(auto i:v)
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fill(ar,val) rep(i,sizeof(ar)/sizeof(ll)) ar[i]=val
#define fill2(ar,val) rep(i,sizeof(ar)/sizeof(ar[0])) rep(j,sizeof(ar[0])/sizeof(ll)) ar[i][j]=val
#define fill0(ar) memset(ar,0,sizeof(ar))
#define debug(x) cout<<#x<<": "<<x<<endl

#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define sd2(x,y) scanf("%d %d",&x,&y)
#define slld2(x,y) scanf("%lld %lld",&x,&y)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pd2(x,y) printf("%d %d\n",x,y)
#define plld2(x,y) printf("%lld %lld\n",x,y)
#define all(ar) ar.begin(), ar.end()
#define endl '\n'
#define sz(x) (int)x.size()
#define len(x) (int)x.length()

typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ii> vii;
typedef vector<ll> vi;

#define INF 1000000000000000000
#define PI 3.14159265358979323846L

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rngb(chrono::steady_clock::now().time_since_epoch().count()); // can give negative values too

void solve()
{
    ll l,r;
    cin >> l >> r;

    ll ans = INF;
    for(ll i=l; i<=r-1; i++)
    {
        for(ll j=i+1; j<=r; j++)
        {
            ll x = i*j;
            ll y = x%2019;
            ans = min(ans,y);
            if(ans==0)
                break;
        }
        if(ans==0)
            break;
    }

    cout << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed;
    cout << setprecision(10);
    #ifdef sarthak
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ll t = 1;
    // cin >> t;
    while(t--)
    {
        solve();
    }

    #ifdef sarthak
    cerr << "Time elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
    #endif
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int x, y, z;
    int a, b;

    scanf("%d", &x);
    scanf("%d", &y);

    z = y % 2;

    if(z == 1){
        printf("No\n");
    }else if(z == 0){
        b = y/2 - x;
        a = 2*x - y/2;
        if(a>=0 && b>=0){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }

return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int m,d;
	cin>>m>>d;
	int ans=0;
	for(int i=0;i<=d;i++)
	{
		if((i%10)<2)
		{
			continue;
		}
		if((i/10)<2)
		{
			continue;
		}
		int a=(i%10)*(i/10);
		if(a<=m)
		{
			ans++;
		}
	}
	cout<<ans<<endl;
}


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

int main(){
  int n,m,a[3]={-1,-1,-1},ans;cin>>n>>m;
  bool f=0;
  
  REP(i,m){
    int s,c;cin>>s>>c;
    
    if(n==1){
      if(a[2]==-1) a[s+1]=c;
      else if(a[2]!=c) f=1;
    }else if(n==2){
      if(s==1&&c==0) f=1;
      else if(a[s]==-1) a[s]=c;
      else if(a[s]!=c) f=1;
    }else if(n==3){
      if(s==1&&c==0) f=1;
      else if(a[s-1]==-1) a[s-1]=c;
      else if(a[s-1]!=c) f=1;
    }
    if(f) break;
  }
  
  REP(i,3) if(a[i]==-1) a[i]=0;
  ans=a[0]*100+a[1]*10+a[2];

  if(n==2&&ans<10) ans+=10;
  if(n==3&&ans<100) ans+=100;
  
  cout<<(f?-1:ans);
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<int,int> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// テーブルを作る前処理
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        ll num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

vector<int> prime;
vector<bool> is_prime;
void sieve(int n){
    is_prime.resize(n);
    
    // 全ての数は素数と仮定
    for (int i = 0 ; i<= n ; i++) is_prime[i]=true;
    // 0と1は非素数
    is_prime[0]=is_prime[1]=false;
 
    // is_primeがtrueなもののうち、最小のものは素数確定
    // 確定した素数の倍数は非素数なのでis_primeを更新していく
    for (int i = 2 ; i<= n ; i++) {
        if(is_prime[i]){
            // 格納
            prime.push_back(i);
            // is_primeの更新
            for(int j = i*2;j <= n;j+=i) is_prime[j] = false;
        }
    }
}


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

    sieve(55555);

    vector<int> ans;
    for(auto p:prime){
        if(p%5==1) ans.push_back(p);
        if(ans.size()==N) break;
    }

    REP(i,N-1) cout << ans[i] << " ";
    cout << ans[N-1] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
 
#define int                     long long
#define file(s)                 freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a)          for(int i = (b); i >=(a); i--)
#define forn(i, a, b)           for(int i = (a); i <= (b); i++)
#define speed                   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
using namespace std;
 
typedef long long ll;
typedef double db;
typedef long double ldb;
 
const ldb pi = 3.14159265358979323846264;
const int maxn = 2e5 + 1;
const int mod = 1e9 + 7;
    
int n, W, ans = -1;
int w[maxn], v[maxn];
int dp[101][100001];
    
main(){
    //file("");
    speed;
    cin >> n >> W;
    forn(i, 1, n){
        int num1, num2;
        cin >> num1 >> num2;
        w[i] = num1;
        v[i] = num2;
    }
    forn(i, 1, n){
        forn(j, 0, W){
            if(j - w[i] >= 0){
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
            }
            else{
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
    forn(i, 1, n){
        forn(j, 1, W){
            if(dp[i][j] > ans)ans = dp[i][j];
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 81708
# omi

def main():
    n = int(input())

    print(0,flush=True)
    s = input()
    if s=="Vacant": return 0
    cap = 0
    if s=="Female": cap = 1

    lo = 0
    hi = n
    while True:
        mid = (hi+lo)//2
        print(mid, flush=True)
        s = input()

        if s=="Vacant": return 0
        gen = 0
        if s=="Female": gen = 1

        if (cap+mid)%2 == gen:
            lo = mid
        else:
            hi = mid

main()

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
pair<int,int> pii;
vector<int> vec;
int main()
{
  string s;

  cin>>s;
  if(s=="SUN")cout<<7<<'\n';
  if(s=="MON")cout<<6<<'\n';
  if(s=="TUE")cout<<5<<'\n';
  if(s=="WED")cout<<4<<'\n';
  if(s=="THU")cout<<3<<'\n';
  if(s=="FRI")cout<<2<<'\n';
  if(s=="SAT")cout<<1<<'\n';


  return 0;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;  

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



Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>

using namespace std;
typedef long long ll;

const int MN = 220;
const ll MD = 1e9+7;

int n;
int d[MN];
ll dp[MN][MN];

ll solve(int i, int j) {
    if (i == 0) {
        if (j == 0) return 1;
        return 0;
    }
    if (dp[i][j] != -1) return dp[i][j];
    ll &res = dp[i][j];
    if (d[i-1] == 0) {
        //-
        return res = solve(i-1, j);
    } else if (d[i-1] == 1) {
        //U
        res = solve(i-1, j-1);
        res += j*solve(i-1, j);
        res %= MD;
        return res;
    } else {
        //D
        res = (j+1)*(j+1)*solve(i-1, j+1);
        res += j*solve(i-1, j);
        res %= MD;
        return res;
    }
}

int main() {
    memset(dp, -1, sizeof(dp));
    cin >> n;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if (s == "-") {
            d[i] = 0;
        } else if (s == "U") {
            d[i] = 1;
        } else {
            d[i] = 2;
        }
    }
    cout << solve(n, 0) << endl;
    return 0;
}

Measured memory_bytes: 1596
#include<stdio.h>


int main() {

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

	n = n % 10;
	
	if (n == 3) {
		printf("bon\n");
	}
	else if (n == 0||n==1||n==6||n==8) {
		printf("pon\n");
	}
	else {
		printf("hon\n");
	}


	return 0;
}

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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define pli pair<long long,int>
#define pil pair<int,long long>
#define ll long long
#define el '\n'

using namespace std;

const int N = 1e3 + 7;
const int H = 1e4 + 7;
const int INF = 2e9;

int h, n;
int dp[H];
int a[N], b[N];

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

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

    fill(dp, dp + H, INF);
    dp[h] = 0;
    for (int i=h;i>=0;i--){
        for (int j=1;j<=n;j++){
            int id = max(i - a[j], 0);
            // cout << i << " " << id << "=> " << dp[i] + b[j] << el;
            dp[id] = min(dp[id], dp[i] + b[j]);
        }
    }
    cout << dp[0] << el;

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N, Q, a, b, p, x;
    cin >> N >> Q;
    vector<vector<int>> edge(N);
    rep(i, N - 1) {
        cin >> a >> b;
        a--;
        b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    vector<int> c(N, 0);
    rep(i, Q) {
        cin >> p >> x;
        c[p - 1] += x;
    }
    vector<bool> done(N, false);
    queue<pair<int, int>> q;
    q.push(make_pair(0, 0));
    while (!q.empty()) {
        auto d = q.front();
        q.pop();
        int u = d.first, v = d.second;
        done[u] = true;
        c[u] += v;
        rep(i, edge[u].size()) {
            int w = edge[u][i];
            if (done[w]) continue;
            q.push(make_pair(w, c[u]));
        }
    }
    rep(i, N) {
        cout << c[i];
        if (i == N - 1) cout << "\n";
        else cout << " ";
    }
}

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

#define int long long
#define rep(i,a,n) for(int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort((c).begin(), (c).end(), greater<int>());
#define fi first
#define se second
  
typedef pair<int,int> P;
typedef vector<int> vi;

signed main() {
    int H, W, x, y;
    cin >> H >> W >> x >> y;

    double ans1 = H * W / 2.0;
    cout << ans1 << endl;

    if((double)x == (double)H/2.0 and (double)y == (double)W/2.0) {
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

int main() {
    ll N;
    cin >> N;
    vector<ll> As(N);
    rep(i,0,N) {
        cin >> As[i];
    }
    if (N == 1) {
        cout << 1 << endl;
        return 0;
    }
    auto is_ok = [&As, N](ll n) {
        if (n == 1) {
            rep(i,1,N) {
                if (As[i] <= As[i-1]) {
                    return false;
                }
            }
            return true;
        }
        map<ll, ll> digits;
        rep(i,1,N) {
            if (As[i] <= As[i-1]) {
                ll d = As[i] - 1;
                digits.erase(digits.upper_bound(d), digits.end());
                digits[d]++;
                while (digits[d] >= n) {
                    if (d == 0) {
                        return false;
                    }
                    digits.erase(d);
                    d--;
                    digits[d]++;
                }
            }
        }
        return true;
    };
    ll ng = 1;
    ll ok = 1;
    while (is_ok(ok) == false) {
        ok *= 2;
    }
    while (ok - ng >= 2) {
        ll mid = (ng + ok) / 2;
        if (is_ok(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok << endl;
}

/*
 
 1
 1
 
 2
 1 1
 
 3
 1 1 1
 
 4
 1 1 1 1
 
 1
 2
 
 2
 2 2
 
 3
 2 2 2
 
 4
 2 2 2 2
 
 5
 2 2 2 2 2
 
 */


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Map<Integer,Integer> po=new HashMap<Integer,Integer>();
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int count=1;
        for(;!(po.containsKey(n));count++){
            po.put(n,n);
            if(n%2==0)n/=2;
            else n=n*3+1;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 23636
#include <stdio.h>
int main(void){
    int i,j,r,c;
    static int s[101][101];
    scanf("%d %d",&r,&c);
    for(i=0;i<=r;i++){
        for(j=0;j<c;j++){
            scanf("%d", &s[i][j]);
            printf("%d ", s[i][j]);
            s[i][c] += s[i][j];
            s[r][j] += s[i][j];
        }
        printf("%d\n",s[i][c]);
    }
    return 0;
}



Measured memory_bytes: 2040
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next()); 
        int [] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = Integer.parseInt(sc.next());
        for (int i = n-1; i > 0; i--)
            System.out.print(a[i] + " ");
        System.out.println(a[0]);
    }
}


Measured memory_bytes: 26144
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] x = new int[3];
		for(int i=0; i<3; i++)
			x[i] = sc.nextInt();
		
		if(x[0]%2==0 || x[1]%2==0 || x[2]%2==0) {
			System.out.println(0);
		} else {
			Arrays.sort(x);
			System.out.println((long)x[0]*x[1]);
		}
		
		sc.close();
	}
}


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

using namespace std;

#define Rep(i,a,b)  for (int i=(a);i<(b);i++)
#define rep(i,n)    for (int i=0;i<(n);i++)
#define all(x)      (x).begin(), (x).end()

#define ll long long

int main()
{
	ll n, m, a, sum = 0, ans = 0;
	cin >> n >> m;
	map<ll, ll> mp;
	mp[0]++;
	rep (i, n) {
		cin >> a;
		sum += a;
		mp[sum%m]++;
	}
	for (auto i: mp)
		ans += i.second * (i.second - 1) / 2;
	cout << ans << endl;
}



Measured memory_bytes: 4224
N=int(input())
X=[0]*N
for i in range(N):
 X[i]=[list(map(int,input().split())) for _ in [0]*int(input())]
print(max(['{:b}'.format(i).count('1')for i in range(2**N) if all([all([y[1]==i>>(y[0]-1)&1 for y in X[j]]) for j in range(N) if (i>>j&1)])]))

Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<pair<string, int>> p(n);
    REP(i, n) cin >> p[i].first >> p[i].second;
    string x;
    cin >> x;
    bool sl = false;
    int ans = 0;
    for (auto r : p) {
        if (sl) ans += r.second;
        else if (r.first == x) sl = true;
    }
    cout << ans << endl;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
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;}
void dump(){cout<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cout<<h<<", ";dump(forward<Ts>(t)...);}
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
void solve1();void solve2();
int main(){solve1();return 0;}

void solve1(){

  ll n;
  cin>>n;
  vector<ll> a(n);
  cin>>a;

  auto b = a;
  auto c = a;
  ll bsum = 0;
  ll csum = 0;

  // b -,+,-,+,-,...
  // c +,-,+,-,+,...

  for(int i=0;i<n;++i){
    if(i&1){
      if(bsum+b[i]<=0){
        b[i] += abs(bsum+b[i])+1;
        bsum += b[i];
      }else{
        bsum += b[i];
      }
    }else{
      if(bsum+b[i]<0){
        bsum += b[i];
      }else{
        b[i] -= (bsum+b[i]+1);
        bsum += b[i];
      }
    }
  }
  for(int i=0;i<n;++i){
    if(!(i&1)){
      if(csum+c[i]<=0){
        c[i] += abs(csum+c[i])+1;
        csum += c[i];
      }else{
        csum += c[i];
      }
    }else{
      if(csum+c[i]<0){
        csum += c[i];
      }else{
        c[i] -= (csum+c[i]+1);
        csum += c[i];
      }
    }
  }
  //for(auto x:b)cout<<x<<" ";cout<<endl;
  //for(auto x:c)cout<<x<<" ";cout<<endl;
  
  ll bcnt=0,ccnt=0;
  rep(i,n){
    bcnt += abs(a[i]-b[i]);
    ccnt += abs(a[i]-c[i]);
  }

  cout<<(min(bcnt,ccnt))<<endl;


}

Measured memory_bytes: 2560
import sys
input=sys.stdin.readline
from collections import deque
sys.setrecursionlimit(10**6)

def main():
    n,m=map(int,input().split())
    graph=[[] for _ in range(n)]
    seen=[False]*n

    for _ in range(m):
        a,b=map(int,input().split())
        graph[a-1].append(b-1)
        graph[b-1].append(a-1)
    ans=[-1]*n
    q=deque([0])
    seen[0]=True
    while len(q):
        now=q.popleft()
        for i in graph[now]:
            if seen[i]:
                continue
            seen[i]=True
            q.append(i)
            if ans[i]==-1:
                ans[i]=now
    print("Yes")
    for i in range(1,n):
        print(ans[i]+1)

if __name__=="__main__":
    main()

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

int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a), q(b), r(c);
    rep(i, a) cin >> p[i];
    rep(i, b) cin >> q[i];
    rep(i, c) cin >> r[i];

    sort(p.rbegin(), p.rend());
    sort(q.rbegin(), q.rend());
    rep(i, x) r.push_back(p[i]);
    rep(i, y) r.push_back(q[i]);

    sort(r.rbegin(), r.rend());
    cout << accumulate(r.begin(), r.begin() + x + y, 0ll) << endl;
}

Measured memory_bytes: 6256