akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int64_t sieve(int64_t n);
int main(void) {
    int64_t A,B;
    int64_t g;
    int64_t ex;
    cin >> A >> B;

    g = __gcd(A,B);
//printf("gcd:%ld\n", g);

    ex = sieve(g) + 1;

    cout << ex << "\n";
    return 0;
}
int64_t sieve(int64_t n) {
    unordered_set<int64_t> s;
    int64_t loopmax = sqrt(n) + 1;
    while((n%2) == 0) {
        s.insert(2);
        n /= 2;
    }
    for (int i=3;i<=loopmax; i+=2){
        while ((n%i) == 0){
            s.insert(i);
            n /= i;
        }
    }

//for(auto it:s) {
//    printf("%ld ", it);
//}
//printf("\n");
    
    int64_t last = (n == 1) ? 0 : 1;
    return s.size() + last;
}


Measured memory_bytes: 256
object Main{
	def main(args:Array[String]){
		val s = new java.util.Scanner(System.in)
		val n=s.nextInt
		var prev=0
		var r=0
		for(_ <-1 to n){
			val v=s.nextInt
			if(prev<=v){
				prev=v
				r+=1
			}
		}

		println(r)
	}
}

Measured memory_bytes: 27328
N, M = list(map(int, input().split()))
L = [None] * M
R = [None] * M
for i in range(M):
    L[i], R[i] = list(map(int, input().split()))

l = [L[0], R[0]] 
for i in range(1, M):
    if L[i] > l[0]:
        l[0] = L[i]
    if R[i] < l[1]:
        l[1] = R[i]

if l[0] <= l[1]:
    ans = l[1] - l[0] + 1
else:
    ans = 0
print(ans)

Measured memory_bytes: 10996
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
int main() {
	int n, c, k, t[100010], ans = 0;
	cin >> n >> c >> k;
	for (int i = 0; i < n; i++)cin >> t[i];
	sort(t, t + n);
	pair<int, int>cnt;
	cnt.first;//time
	cnt.second = 0;//people
	for (int i = 0; i < n; i++) {
		if (!cnt.second) {
			cnt.first = t[i];
			cnt.second = 1;
			ans++;
		}
		else if (cnt.second == c || t[i] - cnt.first > k) {
			cnt.first = t[i];
			cnt.second = 1;
			ans++;
		}
		else {
			cnt.second++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
import itertools
N = int(input())
Pl = [int(x) for x in input().split()]
Ql = [int(x) for x in input().split()]
P = tuple(Pl)
Q = tuple(Ql)
S = [x for x in range(1, N+1)]
a = 0
b = 0
Slist = list(itertools.permutations(S))
Slist.sort()
for i in range(len(Slist)):
  if P == Slist[i]:
    a = i
  if Q == Slist[i]:
    b = i
print(abs(a-b))

Measured memory_bytes: 8052
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main()
{
    string a;
    cin >> a;
    int n = a.size();

    vector<int> dp1(n);
    vector<int> dp2(26, 0);
    rep(i, n)
    {
        int c = a[i] - 'a';
        dp1[i] = i - dp2[c];
        dp2[c]++;
    }

    int64_t result = 1;
    rep(i, n)
    {
        result += dp1[i];
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int result = 700;
  cin >> s;
  for (int i = 0; i < 3; i++) {
    if(s[i] == 'o') {
      result += 100;
    }
  }
  cout << result << endl;
}

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

int main(){
  while (1){
    int m, nmin,nmax;
    cin >> m >> nmin >> nmax;
    if(m==0) break;

    vector<int> pt(m+1);
    for(int i=1; i<=m; i++){
      cin >> pt[i];
    }
    int dmax=0, mx=0;
    for(int i=nmin; i<=nmax; i++){
      if(dmax <= pt[i]-pt[i+1]){
        dmax = pt[i]-pt[i+1];
        mx=i;
      }
    }
    cout << mx << endl;
    
  }
  return 0;
}

Measured memory_bytes: 3068
N = int(input())
B = list(map(int,input().split()))
A = []
A.append(B[0])

for i in range(N-1):
 if(i != N-2):
  A.append(min(B[i],B[i+1]))
 else:
  A.append(B[i])
  
ans = sum(A)
print(ans)


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

int main() {
    int N;
    cin >> N;
    int a_arr[N];
    int max_a = -1;
    int max_n = 0;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        if (a == max_a) {
            max_n++;
        } else if (a > max_a) {
            max_a = a;
            max_n = 1;
        }
        a_arr[i] = a;
    }
    int sub_max_a = -1;
    for (int i = 0; i < N; ++i) {
        int a = a_arr[i];
        if (a == max_a) {
            continue;
        }
        if (a > sub_max_a) {
            sub_max_a = a;
        }
    }
    for (int i = 0; i < N; ++i) {
        int a = a_arr[i];
        if (a == max_a) {
            if (max_n > 1) {
                cout << max_a << "\n";
            } else {
                cout << sub_max_a << "\n";
            }
        } else {
            cout << max_a << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 2432
S = int(input())

a = [0] * 2000
a[0] = 0
a[1] = 0
a[2] = 1
a[3] = 1
a[4] = 1
a[5] = 2

for i in range(6, S):
  k = 0
  for l in range(2, i-2):
    k += a[l]
  a[i] = 1 + k
  
p = a[S-1] % (10**9 + 7)
print(p)

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

int n;
long long num[2005], loc[2005];
long long dp[2005][2005] = {0};

struct node {
	long long a, id;
}	input[2005];

bool comp (node xx, node yy) {
	return xx.a > yy.a;
}

int main () {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> input[i].a;
		input[i].id = (long long)(i);
	}
	sort (input+1, input+n+1, comp);
	for (int i = 1; i <= n; ++i) {
		num[i] = input[i].a;
		loc[i] = input[i].id;
	}
	for (int i = 1; i <= n; ++i)
		for (int j = 0; j <= i; ++j) {
			if (j == 0) {
				dp[j][i-j] = dp[j][i-j-1] + num[i] * abs (loc[i] - (n-(i-j)+1));
				continue;
			}
			if (i-j == 0) {
				dp[j][i-j] = dp[j-1][i-j] + num[i] * abs (loc[i] - j);
				continue;
			}
			dp[j][i-j] = max (dp[j-1][i-j] + num[i] * abs (loc[i] - j), dp[j][i-j-1] + num[i] * abs (loc[i] - (n-(i-j)+1)));
		}
	long long mx = -1;
	for (int i = 0; i <= n; ++i)
		mx = max (mx, dp[i][n-i]);
	cout << mx << endl;
	return 0;
}

Measured memory_bytes: 26352
<?php
//error_reporting(0);
//$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
list($N,$M,$Q) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$s = trim(fgets(STDIN));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));

for($i=0;$i<$Q;$i++) {
  $A[] = array_map('intval',explode(" ",trim(fgets(STDIN))));
}
$maxscore=0;
$ary[0]=1;
dfs($ary);
printf("%d\n",$maxscore);

function chkscore($v) {
 // printf("%s\n",implode(",",$v));
  global $A;
  $score=0;
  foreach($A as $a) {
    if ($v[$a[1]-1]-$v[$a[0]-1]==$a[2]) {
      //printf("%d-%d = %d => %d\n",$v[$a[1]-1],$v[$a[0]-1],$a[2],$a[3]);
      $score+=$a[3];
    }
  }
 return $score;
}

function dfs($ary) {
  global $N,$M,$Q;
  global $maxscore;
  $last = count($ary);
  if ($last==$N) {
   $maxscore=max($maxscore,chkscore($ary));
   return;
  }
  $ary[]=$ary[$last-1];
  $last++;
  while($ary[$last-1]<=$M) {
    dfs($ary);
    $ary[$last-1]++;
  }
}


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

using namespace std;

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

int main() {

  //  cout << 5 * 100000 + 100000 + 5 * 10000 + 10000 + 5 * 1000 + 1000 << endl;
  
  while(1) {
    int P, N[7] = {};
    scanf("%d", &P); if(P == 0) break;
    REP(i, 1, 7) scanf("%d", &N[i]);

    int ans = 1000000000;

    REP(d, P, P + 100000) {
      int D = d;
      
      int U = 0;
      int k, m;
      
      m = D / 500;
      k = min(m, N[6]);
      D %= 500; D += (m - k) * 500;
      U += k;
      
      m = D / 100;
      k = min(m, N[5]);
      D %= 100; D += (m - k) * 100;
      U += k;
      
      m = D / 50;
      k = min(m, N[4]);
      D %= 50; D += (m - k) * 50;
      U += k;
      
      m = D / 10;
      k = min(m, N[3]);
      D %= 10; D += (m - k) * 10;
      U += k;
      
      m = D / 5;
      k = min(m, N[2]);
      D %= 5; D += (m - k) * 5;
      U += k;
      
      m = D;
      k = min(D, N[1]);
      D += (m - k);
      U += k;
      
      int T = d - P;
      int S = 0;
      S += T / 500; T %= 500;
      S += T / 100; T %= 100;
      S += T / 50; T %= 50;
      S += T / 10; T %= 10;
      S += T / 5; T %= 5;
      S += T;

      ans = min(ans, U + S);
    }
    printf("%d\n", ans);
  }
  
  return 0;
}

Measured memory_bytes: 1184
use std::cmp::min;

fn main() {
    proconio::input! {
        a: i32,
        b: i32,
        c: i32,
        mut k: i32,
    }
    let mut ans = 0;
    ans += min(a, k);
    k -= min(a, k);
    k -= min(b, k);
    ans -= min(c, k);
    println!("{}", ans);
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define mset(a,x) memset(a,x,sizeof(a))
#define FASTIO cin.tie(0),ios::sync_with_stdio(0)



int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    ll sum = 0;
    rep(i, n) cin >> a[i], sum += a[i];

    sort(ALL(a));
    if (sum % 10 != 0) {
        cout << sum << endl;
        return 0;
    }

    for (auto&& i : a) {
        if ((sum - i) % 10 != 0) {
            cout << sum - i << endl;
            return 0;
        }
    }

    cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod ((long long)(1e9+7))
#define ll long long
int main()
{
  ll n;
  cin>>n;
  ll ans=1;
  for(ll i=1;i<=n;i++){
    ans*=i;
    ans%=mod;
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
 
int main() {
  int n;
  cin>>n;
  string s;
  cin>>s;
  rep(i,len(s)){
    printf("%c",((s[i]-'A'+n)%26)+'A');
  }
}

Measured memory_bytes: 3624
a,b,c = gets.chomp.split(" ").map(&:to_i)
k = gets.chomp.to_i

k.times do
  if b <= a
    b *= 2
  elsif c <= b
    c *= 2
  end
end

if b > a && c > b
  puts "Yes"
else
  puts "No"
end



Measured memory_bytes: 14332
N = int(input())
t0, a0 = 1, 1
for _ in range(N):
    t, a = map(int, input().split())
    n = max((t0- 1)// t+ 1, (a0-1)//a+1)
    t0, a0 = n*t, n*a

print(t0 + a0)

Measured memory_bytes: 3060
[X,Y,A,B,C] = [int(x) for x in input().split()]
R_list = [int(x) for x in input().split()]
G_list = [int(x) for x in input().split()]
T_list = [int(x) for x in input().split()]
R_list.sort()
G_list.sort()
T_list.sort()
ans = 0
r = 0
g = 0
for i in range(X+Y):
    if r == X:
        R_list = [0]
    if g == Y:
        G_list = [0]
    if len(T_list) == 0:
        T_list = [0]
    if max(R_list[-1],G_list[-1],T_list[-1]) == R_list[-1]:
        ans += R_list.pop(-1)
        r += 1
    elif max(R_list[-1],G_list[-1],T_list[-1]) == G_list[-1]:
        ans += G_list.pop(-1)
        g += 1
    elif max(R_list[-1],G_list[-1],T_list[-1]) == T_list[-1]:
        ans += T_list.pop(-1)
print(ans)

Measured memory_bytes: 23088
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int N, A[100000], B, D, judge1, judgex[100000], judge2, M, i, j;
long long Ans = 0, judgey[100000];
string S;
int n = 0;

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

	if (N >= B)
		cout << 10;
	else
		cout << 0;


	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

static const int N = 100;

int main(){
  int M[N][N];
  int i, j, n, u, k, v;

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

  for(i = 0; i<n; i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j = 0; j<k; j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  for(i = 0; i<n; i++){
    for(j = 0; j<n; j++){
      if(j)printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }
  
  return 0;
}



Measured memory_bytes: 2052
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
//#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n;
long long f[2010][2010];	//i--left，j--right左区，右区

struct Elem
{
	int oriPos;
	long long val;
};

Elem a[2010];

bool compare(const Elem &a, const Elem &b) {
	if (a.val == b.val) {
		return a.oriPos < b.oriPos;
	} else {
		return a.val > b.val;
	}
}


int main()
{
	scanf("%d", &n);
	for (int i = 0 ; i < n ; i++) {
		scanf("%lld", &(a[i].val));
		a[i].oriPos = i;
	}
		
	sort(a, a + n, compare);
	
	f[0][0] = 0;
	
	int count = 0;
	for (int i = 0 ; i < n ; i++) {
		count++;
		for (int l = 0 ; l <= count ; l++) {
			int r = count - l;
			
			long long curMax = 0;
			if (l == 0) {
				int rPos = n - r;
				curMax = f[l][r - 1] + abs(rPos - a[i].oriPos) * a[i].val;
			} else if (r == 0) {
				int lPos = l - 1;
				curMax = f[l - 1][r] + abs(lPos - a[i].oriPos) * a[i].val;
			} else {	//都不为0 
				int rPos = n - r;
				int lPos = l - 1;
				
				long long lVal = f[l][r - 1] + abs(rPos - a[i].oriPos) * a[i].val;
				long long rVal = f[l - 1][r] + abs(lPos - a[i].oriPos) * a[i].val;
				
				if (lVal > rVal)
					curMax = lVal;
				else
					curMax = rVal;
			}
			
			if (f[l][r] < curMax)
				f[l][r] = curMax;
		}
	}
	
	long long realMax = 0;
	for (int l = 0 ; l <= n ; l++) {
		int r = n - l;
		if (realMax < f[l][r])
			realMax = f[l][r];
	}
	
	printf("%lld\n", realMax);
		
	return 0;
}

Measured memory_bytes: 24412
//Name: Building a Space Station
//Level: 2
//Category: グラフ,Graph,最小全域木,MST
//Note:

/**
 * 球体と球体を最短距離で結ぶには、中心同士を結ぶような線分で結べばよい。
 * 交差している球の間にはコスト0の辺があるものとして、最小全域木を求めればよい。
 *
 * オーダーは O(N^2 log N)。
 */
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct DisjointSet/*{{{*/
{
  vector<int> parent;

  int root(int x)
  {
    if (parent[x] < 0) {
      return x;
    } else {
      parent[x] = root(parent[x]);
      return parent[x];
    }
  }

  explicit DisjointSet(int n) : parent(n, -1) {}

  bool unite(int x, int y)
  {
    const int a = root(x);
    const int b = root(y);
    if (a != b) {
      if (parent[a] < parent[b]) {
        parent[a] += parent[b];
        parent[b] = a;
      } else {
        parent[b] += parent[a];
        parent[a] = b;
      }
      return true;
    } else {
      return false;
    }
  }

  bool find(int x, int y) { return root(x) == root(y); }
  int size(int x) { return -parent[root(x)]; }
};/*}}}*/

struct Sphere {
    double x, y, z, r;

    double distance(const Sphere &s) const {
        const double dx = x - s.x;
        const double dy = y - s.y;
        const double dz = z - s.z;
        const double d = sqrt(pow(dx, 2) + pow(dy, 2) + pow(dz, 2)) - r - s.r;
        return d < 0 ? 0 : d;
    }
};

struct Edge {
    int a, b;
    double cost;

    Edge(int a, int b, double c) : a(a), b(b), cost(c) {}

    bool operator <(const Edge &e) const {
        return cost < e.cost;
    }
};

bool solve() {
    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;

    vector<Sphere> nodes(N);
    for(int i = 0; i < N; ++i) {
        cin >> nodes[i].x >> nodes[i].y >> nodes[i].z >> nodes[i].r;
    }

    vector<Edge> edges;
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < i; ++j) {
            edges.emplace_back(i, j, nodes[i].distance(nodes[j]));
        }
    }
    sort(begin(edges), end(edges));

    DisjointSet ds(N);
    double ans = 0;
    for (auto &e : edges) {
        if(ds.unite(e.a, e.b)) {
            ans += e.cost;
        }
    }
    cout << ans << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(3);

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1504
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

ll IN(){
	int c,f;ll x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=100000+19;
const int p=1e9+7;

ll val[N],A,B;
int s[2][N],Ti[2],T[2][N];
int n,ans;

void Add(int w,int x,int v){
	for (++x;x<=n+1;x+=x&-x){
		if (T[w][x]!=Ti[w]) T[w][x]=Ti[w],s[w][x]=0;
		s[w][x]=(s[w][x]+v)%p;
	}
}
int Qry(int w,int x){
	int res=0;
	for (++x;x;x-=x&-x){
		if (T[w][x]==Ti[w]) res=(res+s[w][x])%p;
	}
	return res;
}

int main(){
	n=IN(),A=IN(),B=IN();
	For(i,1,n+1) val[i]=IN();
	val[0]=-(1e18);
	Add(0,0,1);
	Add(1,0,1);
	For(i,2,n+1){
		int s0=0,s1=0;
		s1=Qry(0,upper_bound(val,val+n+1,val[i]-B)-val-1);
		s0=Qry(1,upper_bound(val,val+n+1,val[i]-A)-val-1);
		if (val[i]-val[i-1]<A) Ti[0]++;
		if (val[i]-val[i-1]<B) Ti[1]++;
		Add(1,i-1,s1);
		Add(0,i-1,s0);
	}
	ans=(Qry(0,n)+Qry(1,n))%p;
	printf("%d\n",ans);
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int Q[] = new int[N+1];
    for (int i=0; i<N; i++) {
      int tmp = sc.nextInt();
      Q[tmp] = i;
    }
    
    int tmp = 0;
    int anstmp = 1;
    for (int i=2; i<=N; i++) {
      if (Q[i] > Q[i-1]) {
        anstmp++;
      } else {
        tmp = Math.max(tmp, anstmp);
        anstmp = 1;
      }
    }
    tmp = Math.max(tmp, anstmp);
    System.out.println(N-tmp);
  }
}


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

vector<vector<int> > seq[50];
vector<bool> vis[50];
bool used[50];
void solve(int idx,int a,int b,vector<int> v){
	if(a<b)	return;
	if(a==b){
		seq[idx].emplace_back(v);
		vis[idx].emplace_back(false);
		return;
	}
	for(int i=1;i<=a;i++){
		vector<int> nxt = v;
		nxt.emplace_back(i);
		solve(idx,a%i,b,nxt);
	}
}

int y[50],z[50];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>y[i];
	for(int i=0;i<n;i++)
		cin>>z[i];
	for(int i=0,a,b;i<n;i++){
		a=y[i],b=z[i];
		if(a==b)
			used[i]=true;
		else{
			solve(i,a,b,vector<int>());
			if(seq[i].empty()){
				cout<<-1<<endl;
				return 0;
			}
		}
	}
	long long int ans = 0;
	for(int i=50;i>=1;i--){
		bool nec = false;
		for(int j=0;j<n;j++)
			if(used[j])	continue;
			else{
				bool ok = false;
				for(int k=0;k<seq[j].size();k++)
					if(!vis[j][k]){
						bool ex=false;
						for(int it:seq[j][k])
							if(it==i){
								ex=true;
								break;
							}
						if(!ex)	ok=true;
					}
				if(!ok)	nec = true;
			}
		if(nec){
			ans |= 1LL<<i;
		}
		else{
			for(int j=0;j<n;j++)
				if(!used[j]){
					for(int k=0;k<seq[j].size();k++)
						if(!vis[j][k]){
							for(auto it:seq[j][k])
								if(it==i){
									vis[j][k]=true;
									break;
								}
						}
				}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
#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() {
    vector<int> vt(5);
    REP(i,5) {
        cin >>vt.at(i);
        if(vt.at(i)==0){
        cout<<i+1<<endl;
        }
    }
  
  return 0;
}


Measured memory_bytes: 3596
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
double ans[1010][2];
int main()
{
	ans[2][0]=1.00,ans[2][1]=1.00;
	for(int i=3;i<1001;i++)
	{
		ans[i][0]=ans[i-1][0]+1.00/hypot(ans[i-1][0],ans[i-1][1])*(-ans[i-1][1]);
		ans[i][1]=ans[i-1][1]+1.00/hypot(ans[i-1][0],ans[i-1][1])*(ans[i-1][0]);
	}
	while(1)
	{
		int k;
		cin >> k;
		if(k==-1)break;
		/*cout << ans[k][0] << endl;
		cout << ans[k][1] << endl;*/
		printf("%.2f\n%.2f\n",ans[k][0],ans[k][1]);
	}
	return 0;
}

Measured memory_bytes: 1224
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D: Lazy Faith
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_M = 100000;
const int MAX_N = 100000;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;

/* global variables */

ll ss[MAX_M], ts[MAX_N];

/* subroutines */

inline void setmin(ll &a, ll b) { if (a > b) a = b; }

/* main */

int main() {
  int m, n, q;
  scanf("%d%d%d", &m, &n, &q);
  for (int i = 0; i < m; i++) scanf("%lld", ss + i);
  for (int i = 0; i < n; i++) scanf("%lld", ts + i);

  while (q--) {
    ll x;
    scanf("%lld", &x);

    int i = lower_bound(ss, ss + m, x) - ss;
    int j = lower_bound(ts, ts + n, x) - ts;
    //printf("%d %d\n", i, j);

    ll mind = LINF;
    if (i > 0 && j > 0)
      setmin(mind, x - min(ss[i - 1], ts[j - 1]));
    if (i < m && j < n)
      setmin(mind, max(ss[i], ts[j]) - x);
    if (i > 0 && j < n) {
      ll d0 = x - ss[i - 1], d1 = ts[j] - x;
      setmin(mind, d0 + d1 + min(d0, d1));
    }
    if (i < m && j > 0) {
      ll d0 = x - ts[j - 1], d1 = ss[i] - x;
      setmin(mind, d0 + d1 + min(d0, d1));
    }

    printf("%lld\n", mind);
  }
  return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K;
  string S;
  cin >> K >> S;
  int l=S.size();
  if(l<=K){
    cout << S << endl;
  }else{
    for(int i=0; i<K; i++){
      cout << S.at(i);
    }
  	cout << "..." << endl;
  }
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> a(n * 3);
  rep(i, 3 * n) cin >> a[i];
  sort(all(a));

  ll ans = 0;
  rep(i, n) ans += a[2 * i + n];

  cout << ans << endl;
}


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

using namespace std;
using ll = long long;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount


int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
    }

    reverse(all(A));
    reverse(all(B));

    ll sum = 0;
    for (int i = 0; i < N; i++) {
        if((A[i]+sum)%B[i]!=0)sum += (ll)B[i] * (((A[i] + sum) / B[i]) + 1)-(A[i]+sum);
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 1024
#pragma region Include
#include <bits/stdc++.h>
// #include <algorithm>
// #include <bitset>
// #include <climits>
// #include <cmath>
// #include <iostream>
// #include <iterator>
// #include <map>
// #include <queue>
// #include <sstream>
// #include <stack>
// #include <string>
// #include <unordered_map>
// #include <unordered_set>
// #include <vector>
#pragma endregion

using namespace std;

#pragma region Macros
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define all(c) (c).begin(), (c).end()
#define dump(x) \
  cout << "Line " << __LINE__ << " : " << #x << " = " << (x) << endl
template <class T>
using VV = vector<vector<T>>;

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  os << "[";
  rep(i, vec.size()) os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  os << "]";
  return os;
}

template <typename T>
ostream& operator<<(ostream& os, vector<vector<T>>& mat) {
  os << "[";
  rep(i, mat.size()) os << mat[i] << (i + 1 == mat.size() ? "" : ",\n ");
  os << "]";
  return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x;
  return is;
}

template <typename V, typename H>
void resize(vector<V>& vec, const H head) {
  vec.resize(head);
}

template <typename V, typename H, typename... T>
void resize(vector<V>& vec, const H& head, const T... tail) {
  vec.resize(head);
  for (auto& v : vec) resize(v, tail...);
}
constexpr double EPS = 1e-10;
const int INF = 0x3f3f3f3f;

string tostring(int i, int digit) {
  auto cur = cout.flags();
  stringstream ss;
  ss << setw(4) << setfill('0') << i;
  string ret = ss.str();
  cout.flags(cur);
  return ret;
}
#pragma endregion

int main() {
  int N;
  cin >> N;
  vi d(N);
  cin >> d;
  int ans = 0;
  rep(i, N - 1) {
    rep2(j, i + 1, N) { ans += d[i] * d[j]; }
  }
  cout << ans << endl;
  return 0;
}

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

  int k,i=2;main(){
     cin>>k;
     cout<<k<<":";
     while (i<=sqrt(k)){
       if(k%i == 0){
         cout<<' '<<i;
         k/=i;
        }
        else{
          i++;
        }
      }
      if(k-1){
        cout<<' '<<k;
      }
      cout<<endl;
    } 


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

#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define IN freopen("input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(int i=a ; i<=b ; i++)
#define FORD(i,a,b) for(int i=a ; i>=b ; i--)
#define INF 1000000000
#define ll long long int
#define eps (1e-8)
#define sq(x) ( (x)*(x) )
#define all(x) x.begin(),x.end()
#define flog2(n) 64 - __builtin_clzll(n) - 1
#define popcnt(n) __builtin_popcountll(n)
#define sz(n) (int) (n.size())

using namespace std;

typedef pair < int, int > pii;
typedef pair < ll, ll > pll;


bool isEqual (ld a, ld b){
    return (abs(a-b)<eps);
}

struct point {
    ld x,y;
    point() {x=y=0;}
    point (ld a, ld b) {x=a;y=b;}
};

struct line {
    ld a, b;
    line (){ a=b=0;}
    line (ld u, ld v){a=u;b=v;}
};

point line_intersection(line l1, line l2){
    ld x=(l1.b-l2.b)/(l2.a-l1.a);
    return point (x,l1.a*x+l1.b);
}

bool operator < (line a, line b){
    if (abs(a.a-b.a) >eps) return a.a>b.a;
    else return a.b>b.b;
}

line l[200004];

//true with both min-max
bool isBad (line l1, line l2, line l3){
    return (line_intersection(l1,l3).x<line_intersection(l1,l2).x || abs(line_intersection(l1,l3).x-line_intersection(l1,l2).x)<eps);
}

vector<line> M;
vector<ld> M1;

//add line i
void add(int i){
    M.pb(l[i]);
    if (M.size()>=2){
        if (isEqual(M[sz(M)-2].a,M[sz(M)-1].a)) {
            M.erase(M.end()-2);
            M1.pop_back();
        }
    }
    while (sz(M)>=3 && isBad(M[sz(M)-3],M[sz(M)-2],M[sz(M)-1])){
        M.erase(M.end()-2);
        M1.pop_back();
    }
    if (M.size()>=2) M1.pb(line_intersection(M[sz(M)-1],M[sz(M)-2]).x);
}

ll query (ll x){
    ll u=sz(M);
    if (M.size() == 1 || x < M1[0]) return (M[0].a*x+M[0].b);
    ll dau=0,cuoi=sz(M1)-1,mid;
    while (dau<cuoi){
        mid=(dau+cuoi+1)/2;
        if (x<M1[mid]) cuoi=mid-1;
        else dau=mid;
    }
    return M[dau+1].a*x+M[dau+1].b;
}

ll h[200005], d[200005];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
  	
  	int n;
  	ll C;
  	cin >> n >> C;

	FOR (i, 1, n) {
		cin >> h[i];
	}

	d[1] = 0;
	l[1] = line(-2 * h[1], sq(h[1]));

	add(1);

	FOR (i, 2, n) {
		d[i] = query(h[i]) + sq(h[i]) + C;

		l[i] = line(-2 * h[i], sq(h[i]) + d[i]);

		add(i);
	}

	cout << d[n] << endl;

    return 0;
}

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

int main(){
    string sa, sb, sc; cin >> sa >> sb >> sc;
    int a_id=0, b_id=0, c_id=0;

    int order = 0; // 0:a 1:b 2:c
    while(true){
        int tmp =0;
        if(order==0){
            if(a_id == sa.length()){
                cout << 'A' << endl;
                break;
            }
            tmp = sa[a_id] - 'a';
            
            a_id++;
        }else if(order==1){
            if(b_id == sb.length()){
                cout << 'B' << endl;
                break;
            }
            tmp = sb[b_id] - 'a';
            b_id++;
        }else if(order==2){
            if(c_id == sc.length()){
                cout << 'C' << endl;
                break;
            }
            tmp = sc[c_id] - 'a';
            c_id++;
        }
        order = tmp;
    }
    return 0;
}

Measured memory_bytes: 3608
/*author  ADITYA BANSAL
                 //~ MNNIT ALLAHABAD     */
        #include<bits/stdc++.h>
        using namespace std;
        #define ll long long
        #define ull unsigned long long
        ll power(ll,ll);
        ll ncr(ll,ll);
        ll add(ll a,ll b);
        void fact();
        ll mul(ll a,ll b);
        #define watch(x) cerr<<(#x)<<"is"<<x<<nl;
        #define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
        #define fi(a,b) for(ll i=a; i<b; i++)
        #define fk(a,b) for(ll k=a; k<b; k++)
        #define fri(a,b) for(ll i=a; i>=b; i--)
        #define fj(a,b) for(ll j=a; j<b; j++)
        #define ffi(a,b) for(ll i=a;i*i<=b;i++)
        #define mp make_pair
        #define ff first 
        #define  tc ll t; cin>>t; while(t--)
        #define all(v) (v).begin(),(v).end()
        #define ss second
        #define pb push_back
        #define mem(v,a) memset((v),a,sizeof(v));
        #define pll pair<ll,ll>
        #define mll map<ll,ll>
        #define sll set<ll>
        #define vll vector<ll>
        #define max3(a,b,c) max(a,max(b,c))
        #define min3(a,b,c) min(a,min(b,c))
        #define nl endl
         int mod=1e9+7;
        const ll  N=100002LL;
        ll fac[N+2];
        ll inv[N+2];
    
        signed main(){  
    	fast
    	
    	 //~ tc
        {
		     ll n;
		     cin>>n;
		     cout<<n*n<<nl;
		
		
		
		
	     }
            return 0;
        }
         
         
        /******************************************************************************/
         
        ll add(ll a,ll b){
			a+=b+mod;
		   if(a>=mod) a-=mod;
		   
		   return a;
		} 
         
        ll mul(ll a,ll b){
            return ((a)*(b))%mod;
        }
         
        ll power(ll a,ll n){
          ll res=1;
          while(n){
              if(n&1) res= mul(res,a);
             n>>=1; 
             a= mul(a,a);
          }
            return res;
        }
        void fact(){
        	inv[0]=fac[0]=1;
        	fi(1,N){
        	 fac[i]=mul(fac[i-1],i);
        	inv[i]=power(fac[i],mod-2);
        }
        }
         
        ll ncr(ll n,ll r){
        	
        	if(r>n) return 0;
        	ll e=fac[n];
        	e=mul(e,inv[r]);
        	e=mul(e,inv[n-r]);
        	return e;
        }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};
constexpr ll INF = 1LL << 60;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N, K;
    cin >> N >> K;
    vector<ll> h(N+2, 0);
    for(int i=1;i<=N;++i){
        cin >> h[i];
    }

    vector<vector<ll>> dp(N+2, vector<ll>(K+1, INF));
    for(int j=0;j<=K;++j) {
        dp[0][j] = 0;
    }
    for(int i=1;i<=N+1;++i) {
        for(int j=0;j<=K;++j) {
            int k_low = max(0, i-j-1);
            // cerr << i << ", " << j << ": " << endl;
            for(int k=k_low;k<i;++k) {
                // cerr << dp[i][j] << " vs " << dp[k][i-k-1] + max(0, h[i]-h[k]) << endl;
                dp[i][j] = min(dp[i][j], dp[k][j-(i-k-1)] + max(0LL, h[i]-h[k]));
            }
            // cerr << i << ", " << j << ": " << dp[i][j] << endl;
        }

        for(int j=1;j<=K;++j) {
            dp[i][j] = min(dp[i][j], dp[i][j-1]);
        }
    }

    cout << *min_element(dp[N+1].begin(), dp[N+1].end()) << endl;

}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 import java.util.Arrays;
import java.util.Comparator;
 
class Main{
  public static void main(String[] args)throws IOException{
      
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
  
    String[] strAry = str.split(" ");
    int a = Integer.parseInt(strAry[0]);
  	int b = Integer.parseInt(strAry[1]);
  	int c = Integer.parseInt(strAry[2]);
    int d;
  	
  	if ( a>b ) { d=a;a=b;b=d;}
	if ( b>c) { d=b; b=c;c=d;}
 	if ( a>b ) { d=a;a=b;b=d;}
  	
System.out.println( a +" "+ b +" "+c);
  	
  	
  } 
}

Measured memory_bytes: 24132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

// 0~AまでのXOR
ll F(ll A){
    ll res;
    if(A%2==1){
        if((A+1)/2 % 2 == 0){
            res = 0;
        }else{
            res = 1;
        }
    }else{
        res = F(A+1)^(A+1);
    }
    return res;
}

int main(){
    ll A,B;
    cin >> A >> B;
    cout << (ll)(F(A-1)^F(B)) << endl;
    return 0;
}

Measured memory_bytes: 3636
N =list(str(input()))

flag = 0
for i in range(len(N) - 2):
    if(N[i] == N[i + 1] and N[i + 1] == N[i + 2]):
        print("Yes")
        flag = 1
        break;
        
if(flag == 0):
    print("No")

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        double a = scan.nextDouble();
        double b = scan.nextDouble();

        if(a>b){
            System.out.println("a > b");
        }else if(a<b){
            System.out.println("a < b");
        }else{
            System.out.println("a == b");
        }

    }
}


Measured memory_bytes: 28000
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
int a[102],dp[102][100004],s[102][100005];
signed main()
{
	int n,i,j,k,w=0,t;
	cin>>n>>k;
	for(i=1;i<=n;i++)
	cin>>a[i];
	for(i=1;i<=k+1;i++)
	s[0][i]=1;
	for(i=1;i<=n;i++)
	for(j=0;j<=k;j++)
	{   
	    int v=s[i-1][j+1]-s[i-1][max(w,j-a[i])];
	    if(v<0)
	    v=v+1000000007;
	    dp[i][j]=(v+dp[i][j])%1000000007;
	    s[i][j+1]=(s[i][j]+dp[i][j])%1000000007;
	    
	}
	cout<<dp[n][k]<<"\n";
}


Measured memory_bytes: 160592
//
//  abc167_Bracket_Sequencing.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
ll mod = 998244353;
ll INF = 1000000007;
#define PI 3.14159265

std::map<int, int> factorization (int n) {
  std::map<int, int> f;
  for (int i = 2; i*i <= n; i++) {
    while (n%i == 0) {
      f[i] += 1;
      n /= i;
    }
  }
  if (n > 1) {
    f[n] += 1;
  }
  return f;
}

ll modpow (int x, int n) {
  if (n==0) return 1%mod;
  ll u = modpow(x, n/2);
  u = (u*u)%mod;
  if (n%2==1) u = (u*x)%mod;
  return u;
}

void dfs(vector<int> A, int n, int m)  {
  if  (A.size() > n) {
    for (int i = 1; i <= n; i++) {
      std::cout << A[i];
    }
    std::cout << std::endl;
    return;
  }
  A.push_back(A.back());
  while (A.back() <= m) {
    dfs(A, n, m);
    A.back()++;
  }
}

const int MAX = 510000;

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

ll COM(int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

ll HCOM(int n, int k) {
    return (n == 0 && k == 0) ? 1 : COM(n+k-1, k);
}

int main() {
  ll n;
  std::cin >> n;
  std::vector<string> s;

  priority_queue<pair<ll, ll> > pos_q;
  priority_queue<pair<ll, ll> > neg_q;

  ll final_balance = 0;
  for (int i = 0; i < n; i++) {
    std::string t;
    std::cin >> t;
    s.push_back(t);

    ll balance = 0;
    ll min_prefix = 0;
    for (int j = 0; j < t.size(); j++) {
      if (t[j] == '(') {
        balance++;
      }
      else {
        balance--;
      }
      min_prefix = min(min_prefix, balance);
    }
    final_balance += balance;
    if (balance != 0 || min_prefix != 0) {
      if (balance >= 0) {
        pos_q.push(make_pair(min_prefix, balance));
      }
      else {
        neg_q.push(make_pair(min_prefix - balance, -balance)); // reverse sequence
      }
    }
  }

  bool check_pos = true;
  int b_pos = 0;

  while (!pos_q.empty()) {
    pair<int, int> pos = pos_q.top();
    pos_q.pop();
    int prefix = b_pos + pos.first;
    if (prefix < 0) { check_pos = false; break; }
    b_pos += pos.second;
  }

  bool check_neg = true;
  int b_neg = 0;

  while (!neg_q.empty()) {
    pair<int, int> neg = neg_q.top();
    neg_q.pop();
    int prefix = b_neg + neg.first;
    if (prefix < 0) { check_neg = false; break; }
    b_neg += neg.second;
  }

  if (final_balance == 0 && check_neg && check_pos) {
    std::cout << "Yes" << std::endl;
  }
  else {
    std::cout << "No" << std::endl;
  }

  // std::cout << " balance: " << final_balance << " prefix: " << final_prefix << std::endl;



  return 0;
}

Measured memory_bytes: 61136
import math
 
# D - Maximum Average Sets
# 問題URL:http://abc057.contest.atcoder.jp/tasks/abc057_d
 
# N:商品の数　A個以上B個以下の範囲で選ぶ
N, A, B = map(int, input().split())
# C：最大価値組み合わせ総数
C = 0
 
# 商品価値をリストに入れる
V = [int(value) for value in input().split()]
# 商品価値が高い順に並び替え
V.sort()

 
# 商品価値が高いものから出来るだけ少なく（＝A個）選ぶのが最も平均価値が高くなる
S = V[-A:]
ave = sum(S) / A
print(ave)
 
Vs = V.count(min(S))
Ss = S.count(min(S))
if min(S) != max(S):
    C = math.factorial(Vs) // (math.factorial(Vs -Ss) * math.factorial(Ss))
    print(C)
else:
    i = A
    C = 0
    while i <= B and V[-i] == min(S):
        c = math.factorial(Vs) // (math.factorial(Vs -i) * math.factorial(i))
        C = C + c
        i = i + 1
    print(C)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define P pair<int,int>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define re(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007;
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    string s;
    cin>>s;
    int k;
    cin>>k;
    int kai=k;
    rep(i,s.size()){
        if(s[i]=='1'){
            if(kai==1){
                cout<<1<<endl;
                return 0;
            }
            else{
                kai--;
            }
        }
        else{
            cout<<s[i]<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
using System;
using System.Linq;
//using System.Collections.Generic;

class Test
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int q = int.Parse(Console.ReadLine());

        for (int i = 0; i < q; i++)
        {
            int[] query = Console.ReadLine().Split().Select(int.Parse).ToArray();

            new Test().swapRange(query[0], query[1], query[2], ref A);
        }
        Console.WriteLine(string.Join(" ", A));
    }

    void swapRange(int b, int e, int t, ref int[] A)
    {
        for (int k = 0; k < e - b; k++)
        {
            int tmp = A[b + k];
            A[b + k] = A[t + k];
            A[t + k] = tmp;
        }
    }
}



Measured memory_bytes: 20296
# 04-Branch_on_Condition-Range.py

# ??????
# ???????????´??°a, b, c?????????????????????????????? a < b < c????????¶????????????????????°"Yes"?????????????????????????????°"No"???????????????????????°?????????????????????????????????

# Input
# ???????????´??°???????????§????????????????????????????????????
# Output
# Yes?????????No????????????????????????????????????

# Sample Input 1
# 1 3 8
# Sample Output 1
# Yes
# Sample Input 2
# 3 8 1
# Sample Output 2
# No

# print("a,b,c?????\??????")
a,b,c=map(int,input().split())
# print("a=%d, b=%d, c=%d."%(a,b,c))

if a<b and b<c:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 7644
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
long long i[3000000];
lol u[111111];
lol ii[121111];
bool o;
bool ans[5];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=0,h=0,j=0;
  string s;
  cin >>a>>b;
  if((a*b)%2==0) cout <<"Even\n";
  else cout <<"Odd\n";
  return (0);
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

bool chk(ll N, ll A, ll B, std::vector<ll> h, ll T) {
  ll check = 0;
  REP(i, N) {
    if (h[i] - B * T <= 0)
      continue;
    check += (h[i] - B * T) / (A - B) + ((h[i] - B * T) % (A - B) == 0 ? 0 : 1);
  }
  // cout << T << " " << check << endl;
  return check <= T;
}

void solve(long long N, long long A, long long B, vector<long long> h) {
  ll left = 0;
  ll right = 1000000000;
  ll ans = right;

  //二分探索
  // binarySearch + iwashi!
  while (left < right) {
    ll mid = (left + right) / 2;
    if (chk(N, A, B, h, mid)) {
      ans = min(ans, mid);
      right = mid;
    } else {
      left = mid;
    }

    if (right - left < 100)
      break;
  }

  for (ll i = left; i <= right; ++i)
    if (chk(N, A, B, h, i)) {
      ans = min(ans, i);
    }

  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long A;
  long long N;
  long long B;
  cin >> N;
  vector<long long> h(N - 1 + 1);
  cin >> A;
  cin >> B;
  for (int i = 0; i <= N - 1; i++) {
    cin >> h[i];
  }
  solve(N, A, B, h);
  return 0;
}


Measured memory_bytes: 2672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll dist[301000];
ll X, Y, Z, N, M, S, T;
ll A[105000], B[105000], C[105000], D[105000];
vector<ll> paths[301000];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> X >> Y >> Z >> N >> M >> S >> T;
    for(int i = 0; i < N; i++) cin >> A[i] >> B[i];
    for(int i = 0; i < M; i++) cin >> C[i] >> D[i];
    S--;
    T--;
    for(int i = 0; i <= 3e5; i++) dist[i] = 1e18;
    for(int i = 0; i < N; i++) {
        paths[A[i]].push_back(100000 + B[i]);
        paths[100000 + B[i]].push_back(A[i]);
    }
    for(int i = 0; i < M; i++) {
        paths[100000 + C[i]].push_back(200000 + D[i]);
        paths[200000 + D[i]].push_back(100000 + C[i]);
    }
    dist[A[S]] = 0;
    dist[100000 + B[S]] = 0;
    queue<int> que;
    que.push(A[S]);
    que.push(100000 + B[S]);
    while(!que.empty()) {
        int now = que.front();
        que.pop();
        if(now == 100000 + C[T] or now == 200000 + D[T]) {
            cout << dist[now] + 1<< endl;
            return 0;
        }
        for(auto to : paths[now]) {
            if(chmin(dist[to], dist[now] + 1)) {
                que.push(to);
            }
        }
    }
    cout << -1 << endl;
    return 0;
}



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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    string s;
    cin >> s;
    int in1 = -1,in2 = -1;
    for (int i = 0; i < (int)s.size(); i++){
        if (in1 == -1 && s[i] == 'A'){
            in1 = i;
        }
        if (s[i] == 'Z'){
            in2 = i;
        }
    }

    cout << in2 - in1 + 1 << endl;





    return 0;
}


Measured memory_bytes: 832