akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define BUF_SIZE 30

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

int get_int3(int *a1, int *a2, int *a3) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d %d", a1, a2, a3);
#else
#error
#endif
  return 0;
}

struct range {
    int start;
    int end;
};

#define TRAINS_MAX 200000
#define TOWNS_MAX 500
#define QUERIES_MAX 100000

int main(void) {
    int towns, trains, queries;
    get_int3(&towns, &trains, &queries);
    int i, j;
    static int map[TOWNS_MAX+1][TOWNS_MAX+1];
    static int dp[TOWNS_MAX+1][TOWNS_MAX+1];
    for(i = 0; i < trains; i++) {
        struct range r;
        get_int2(&r.start, &r.end);
        map[r.start][r.end]++;
        if(r.start == r.end) dp[r.start][r.end]++;
    }

    // size=1
    int size, start;
    for(start = 1; start <= towns-1; start++) {
        int end = start+1;
        dp[start][end] = dp[start][start] + dp[end][end] + map[start][end];
    }

    // size>=2
    for(size = 2; size <= towns-1; size++) {
        for(start = 1; start <= towns-size; start++) {
            int end = start+size;
            dp[start][end] = dp[start+1][end] + dp[start][end-1] - dp[start+1][end-1] + map[start][end];
        }
    }

    int ans[QUERIES_MAX];
    int ans_idx = 0;
    for(i = 0; i < queries; i++) {
        int src, dst;
        get_int2(&src, &dst);
        ans[ans_idx++] = dp[src][dst];
    }
    for(i = 0; i < ans_idx; i++) {
        printf("%d\n", ans[i]);
    }
    return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define INF 1e9
typedef pair<int, int> P;

/* 　"assert"    assert(A：条件式)で　Aが真なら処理は続行、偽ならプログラムを終了する　*/

/*　　ラムダ式　　 auto a = [キャプチャ](パラメータ){ 処理 }  */

/* string型　メンバ関数　substr()    replace()  */

int main (){
    int a, b; cin >> a >> b;
    string x,y;
    rep(i,b){
        x += to_string(a);
    }
    rep(i,a){
        y += to_string(b);
    }
   
    if(x < y){
        cout << x << endl;
        return 0;
    }
    cout << y << endl;
    
}


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

ll dp[100005][101];ll wt[100005], val[100005];ll  n,W;
ll  knapsack(ll *wt, ll *val, ll W, ll n)
{
  if(n==0||W==0)
    return 0;
  if(dp[W][n]!=-1)
    return dp[W][n];
  if(wt[n-1]<=W)
    return dp[W][n]=max(val[n-1]+knapsack(wt,val,W-wt[n-1],n-1),knapsack(wt,val,W,n-1));
  else if(wt[n-1]>W)
    return dp[W][n]=knapsack(wt,val,W,n-1);


}
  
 

int  main()
{

 cin>>n>>W;
 memset(dp,-1,sizeof(dp));

 for(int i=0;i<n;i++)
 {
  cin>>wt[i]>>val[i];
 }

  cout<<knapsack(wt,val,W,n);
 

  return 0;

}

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

using ll = long long;
using P = pair<int, int>;

int main()
{
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int totalPrice = 1e9;
    for (int Z = 0; Z <= max(X, Y); Z++)
    {
        totalPrice = min(2 * C * Z + A * max(0, X - Z) + B * max(0, Y - Z), totalPrice);
    }

    cout << totalPrice << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
using PL = pair<ll , ll> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
#define mod 1000000007

int main(){
    int n ;
    cin >> n ;
    vector<int> a (n) ;
    deque<int> deq(n, 1e9 + 10) ;
    rep(i, n) cin >> a[i] ;
    rep(i, n){
        if(a[i] <= deq[0]){
            deq.push_front(a[i]) ;
        }
        else {
            int k = lower_bound(deq.begin(), deq.end(), a[i]) - deq.begin();
            deq[k - 1] = a[i] ;
        }
    }
    int ans = 0 ;
    rep(i, n){
        if(deq[i] == 1e9 + 10) break ;
        ans++ ;
    }
    cout << ans << endl ;
} 

Measured memory_bytes: 4584
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const int MOD = 1e9+7;
//}}}

ll a[200000];

int main(){
  ll N;
  cin >> N;
  rep(i, N) cin >> a[i];
  if(a[0] != 0){
    cout << "-1" << endl;
    return 0;
  }

  ll ans = 0;
  rep(i, 1, N){
    if(a[i] > a[i - 1] + 1){
      cout << "-1" << endl;
      return 0;
    }
    if(a[i]){
      if(a[i] == a[i - 1] + 1){
        ans++;
      }else{
        if(a[i] == 1){
          ans++;
        }else{
          ans += a[i];
        }
      }
    }
  }

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


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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

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

using ll = long long;

template<class T> void chmax(T& a, T b){ a>b?:a=b; }
template<class T> void chmin(T& a, T b){ a<b?:a=b; }

int main() {
    int n, k, a[15];
    cin >> n >> k;
    rep(i, n) cin >> a[i];
    ll ans = 1LL << 62;
    for (int i = 0; i < (1 << n); ++i) {
        int maxh = 0, cnt = 0;
        ll cost = 0;
        for (int j = 0; j < n; ++j) {
            if (i & (1 << j)) {
                cnt++;
                if (maxh >= a[j]) {
                    cost += maxh - a[j] + 1;
                    maxh++;
                }
            }
            chmax(maxh, a[j]);
        }
        if (cnt >= k)
            chmin(ans, cost);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
S = list(input())

word_num = int(len(S)/2)

temp_num = 0

if len(S) % 2 == 0:
    for i in range(word_num):
        if S[2*i]+S[2*i+1] == 'hi':
            pass
        else:
            temp_num += 1
else:
    pass

if len(S) % 2 == 0 and temp_num == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
/* 

Author: Vishal Singh  
(singhvishal0304@gmail.com)

"The days that break you are the days that make you."

*/

#include <bits/stdc++.h>
using namespace std;

#define fastio() ios_base::sync_with_stdio(false);\
cin.tie(NULL);

#define md 1000000007


#define lli long long int
#define pb push_back
#define mp make_pair
#define vvi(r,c) vector<vector<lli>> v(r,vector<lli>(c));
#define fi first
#define se second
#define mem(arr,x) memset(arr,x,sizeof(arr))

lli power(lli a,lli b){
	if(b==0)
		return 1;
	if(b%2)
		return ((a%md)*(power(a,b-1)))%md;
	else
	{
		lli x=power(a,b/2);
		return (x*x)%md;
	}
}

void solve(){
	lli n,d;
	cin>>n>>d;
	int ans=0;
	for(int i=0;i<n;i++){
			lli a,b;
			cin>>a>>b;
			lli s=a*a+b*b;
			s=ceil(sqrt(s));
			if(s<=d)
				ans++;
	}
	cout<<ans<<endl;
}


int main()
{	
    fastio();
	int t;
	// cin>>t;
	t=1;
	while(t--){
		solve();
	}

	return 0;
}

Measured memory_bytes: 3736
from collections import deque

N = int(input())
Sss = [input() for _ in range(N)]

adjL = [[] for _ in range(N)]
for i, Ss in enumerate(Sss):
    for j, S in enumerate(Ss):
        if S == '1':
            adjL[i].append(j)

def IsBipartiteGraph(adjList):
    def bfs(vSt):
        colors[vSt] = 1
        Q = deque([vSt])
        while Q:
            vNow = Q.popleft()
            color = colors[vNow]
            for v2 in adjList[vNow]:
                if colors[v2] == color:
                    return False
                elif colors[v2] == 0:
                    colors[v2] = -color
                    Q.append(v2)
        return True
    numV = len(adjList)
    colors = [0] * numV
    for vSt in range(numV):
        if colors[vSt] != 0: continue
        if not bfs(vSt):
            return False
    return True

def getDiameterOfUnweightedGraph(adjList):
    numV = len(adjList)
    def bfs(vSt):
        costs = [-1] * numV
        costs[vSt] = cost = 0
        vs = [vSt]
        while vs:
            cost += 1
            v2s = []
            for v in vs:
                for v2 in adjList[v]:
                    if costs[v2] == -1:
                        costs[v2] = cost
                        v2s.append(v2)
            vs = v2s
        return cost - 1
    return max([bfs(vSt) for vSt in range(numV)])


if not IsBipartiteGraph(adjL):
    print(-1)
else:
    maxDist = getDiameterOfUnweightedGraph(adjL)
    print(maxDist+1)


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
    if(a%b==0)
    return b;
    return gcd(b,a%b);
}
int lcm(int a,int b){
   return a*b/gcd(a,b);
}
int main(){
    int n;
    cin>>n;
    cout<<lcm(n,2)<<endl;
}

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

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  ll ans=0;
  
  
  ll p=0;
  rep(i,n-1){
    for(int j=i+1 ;j<n ; j++){
      if(a.at(i) > a.at(j)) p++;
    }
  }
  p = p%1000000007;
  p*=k;
  p = p%1000000007;
  
  ll q=0;
  rep(i,n){
    rep(j,n){
      if(a.at(i) > a.at(j)) q++;
    }
  }
  q = q%1000000007;  
  k = k%1000000007;
  q *= k*(k-1)/2%1000000007; //kC2
  ans = p+q;
  
  cout << ans%1000000007 << endl;
  
  return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

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

const int MOD = 1e9 + 7;
const ll INF = 1e17;
const int INT_INF = 1e9;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;


int N;
double X[101], Y[101];
double dist(double x, double y) {
	return sqrt(x*x + y * y);
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	REP(i, N) {
		cin >> X[i] >> Y[i];
	}
	double theta = 0;
	double ans = 0;
	while (theta <= 2 * pi) {
		double x = 0, y = 0;
		REP(i, N) {
			if (cos(theta)*X[i] + sin(theta)*Y[i] > 0) {
				x += X[i];
				y += Y[i];
			}
		}
		ans = max(ans, dist(x, y));
		theta += pi / 4000000.0;
	}
	cout << setprecision(12) << ans << endl;
}



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

int n, k;
int r,s,p;
string t, t_alt;
long long sum;

int main(){

    cin >> n >> k >> r >> s >> p;
    cin >> t;

    sum = 0;
    for (int i=0; i<n; i++){
//        cout << "i = " << i << endl;
//        cout << "t_alt = " << t_alt << endl;
        if (i-k<0){
            if (t.at(i) == 'r'){
                t_alt.push_back('p');
                sum += p;
            }
            else if (t.at(i) == 's'){
                t_alt.push_back('r');
                sum += r;
            }
            else if (t.at(i) == 'p'){
                t_alt.push_back('s');
                sum += s;
            }
            else continue;
        }
        else{
            //  t.at(i) == 'r'
            if ((i+k>=n) && (t.at(i) == 'r') && (t_alt.at(i-k) == 'p')){
                t_alt.push_back('s');   //  p以外であればOK
            }
            else if ((i+k<n) && (t.at(i) == 'r') && (t_alt.at(i-k) == 'p') && (t.at(i+k) == 'r')){
                t_alt.push_back('s');   //  p以外であればOK
            }
            else if ((i+k<n) && (t.at(i) == 'r') && (t_alt.at(i-k) == 'p') && (t.at(i+k) == 's')){
                t_alt.push_back('s');   //  rとpはダメ
            }
            else if ((i+k<n) && (t.at(i) == 'r') && (t_alt.at(i-k) == 'p') && (t.at(i+k) == 'p')){
                t_alt.push_back('r');   //  sとpはダメ
            }
            else if (t.at(i) == 'r'){
                t_alt.push_back('p');
                sum += p;
            }

            //  t.at(i) == 's'
            else if ((i+k>=n) && (t.at(i) == 's') && (t_alt.at(i-k) == 'r')){
                t_alt.push_back('p');   //  r以外であればOK
            }
            else if ((i+k<n) && (t.at(i) == 's') && (t_alt.at(i-k) == 'r') && (t.at(i+k) == 's')){
                t_alt.push_back('p');   //  r以外であればOK
            }
            else if ((i+k<n) && (t.at(i) == 's') && (t_alt.at(i-k) == 'r') && (t.at(i+k) == 'p')){
                t_alt.push_back('p');   //  rとsはダメ
            }
            else if ((i+k<n) && (t.at(i) == 's') && (t_alt.at(i-k) == 'r') && (t.at(i+k) == 'r')){
                t_alt.push_back('s');   //  rとpはダメ
            }
            else if (t.at(i) == 's'){
                t_alt.push_back('r');
                sum += r;
            }

            //  t.at(i) == 'p'
            else if ((i+k>=n) && (t.at(i) == 'p') && (t_alt.at(i-k) == 's')){
                t_alt.push_back('r');   //  sはダメ
            }
            else if ((i+k<n) && (t.at(i) == 'p') && (t_alt.at(i-k) == 's') && (t.at(i+k) == 'r')){
                t_alt.push_back('r');   //  pとsはダメ
            }
            else if ((i+k<n) && (t.at(i) == 'p') && (t_alt.at(i-k) == 's') && (t.at(i+k) == 'p')){
                t_alt.push_back('r');   //  sはダメ
            }
            else if ((i+k<n) && (t.at(i) == 'p') && (t_alt.at(i-k) == 's') && (t.at(i+k) == 's')){
                t_alt.push_back('p');   //  sとrはダメ
            }
            else if (t.at(i) == 'p'){
                t_alt.push_back('s');
                sum += s;
            }

            else continue;
        }
    }

//    cout << t_alt << endl;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 640
x,y,a,b,c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort()
q.sort()
r.sort()
p.reverse()
q.reverse()
r.reverse()

ret = 0
z = 0

pidx=0
qidx=0
ridx=0

plen=len(p)
qlen=len(q)
rlen=len(r)
while(x + y > z):
    pattern = 0
    apple = 0
    if x > 0 and pidx < plen:
        apple = p[pidx]
        pattern = 1
    if y > 0 and qidx < qlen:
        if apple < q[qidx]:
            apple = q[qidx]
            pattern = 2
    if ridx < rlen and apple < r[ridx]:
        apple = r[ridx]
        pattern = 3
    ret += apple
    if pattern == 1:
        x -= 1
        pidx += 1
    elif pattern == 2:
        y -= 1
        qidx  += 1
    elif pattern == 3:
        z += 1
        ridx += 1

print(ret)


Measured memory_bytes: 22720
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N,X;
  cin >> N >> X;
  int m[N];
  for(int i=0;i<N;i++) cin >> m[i];

  int ans = N;
  for(int i=0;i<N;i++) X -= m[i];

  int mn = *min_element(m,m+N);
  ans += X / mn;

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		if(N == 1) {
			System.out.println("Hello World");
		}else {
			int a = sc.nextInt();
			int b = sc.nextInt();
			System.out.println(a+b);
		}
		sc.close();
	}

}


Measured memory_bytes: 21588
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, H = MAP()
L = [LIST() for i in range(N)]

A = []
B = []
for a, b in L:
    A.append(a)
    B.append(b)

A.sort(reverse=True)
B.sort(reverse=True)

big_B = []

ma_A = max(A)
for b in B:
    if ma_A <= b:
        big_B.append(b)
thr = sum(big_B)
damage = 0 
cnt = 0
if thr >= H:
    for i in range(N):
        if damage < H:
            damage += B[i]
            cnt += 1
else:
    need_damage = H - thr
    cnt = len(big_B)
    if need_damage % A[0] == 0:
        cnt += need_damage // A[0]
    else:
        cnt += need_damage // A[0] + 1
print(cnt)


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

#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(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i >= 0;i--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define pii pair<int,int>
#define piii pair<int,pii>
#define mp make_pair
#define pb push_back

#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second

const int INF = (INT_MAX/2);
const double eps = 1e-14;
const double PI = M_PI;

#define DEB cout<<"!"<<endl
#define SHOW(a,b) cout<<(a)<<" "<<(b)<<endl

#define DIV 1000000009

int check_digit(int val,int table){
  for(;;){
    if(val == 0) return 0;
    if(val % 10 == table)  return 1;
    else val /= 10;
  }
}

int main(){
      int N,K; cin >> N >> K;
      vi table(K,-1);
      REP(i,K)   cin >> table[i];
      for(int i = N;;i++){
        int flag = 0;
        REP(j,K){
          if(check_digit(i,table[j])){
            flag++;
          }
        }
        if(!flag){
          cout << i << endl;
          return 0;
        }
      }
      return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        
        //int x = stdIn.nextInt();
        int a[] = new int[n];
        int tmp[] = new int[n];
        //String s = stdIn.next();
        //String t = stdIn.next();
        //char c[] = s.toCharArray();
        //int sum = 0;
        //boolean flag = true;
        for(int i = 0; i < n; i++){
            a[i] = stdIn.nextInt();
        }
        
        
        int q = stdIn.nextInt();

        for(int i = 0; i < q; i++){
            int b = stdIn.nextInt();
            int m = stdIn.nextInt();
            int e = stdIn.nextInt();
            
            for(int k = 0; k < e - b; k++){
                tmp[k] = a[b + k];
            }
            
            for(int k = 0; k < e - b; k++){
                a[b + ((k + (e - m)) % (e - b))] = tmp[k];
            }
            
            
        }
        
        for(int i = 0; i < n - 1; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println(a[n - 1]);

        //System.out.println();
        //System.out.print();

        stdIn.close();
    }
}





Measured memory_bytes: 38148
#include <cassert>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "limits.h"
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;

  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;



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

  ll n,k;
  std::cin>>n>>k;

  std::vector<P> num(n);

  rep(i,0,n)std::cin>>num[i].first>>num[i].second;

  ll ans=0;

  rep(i,0,n){
    if((k|num[i].first)==k)ans+=num[i].second;
  }

  rep(i,0,31){
    if((k>>i)&1){
      ll bit=k-(1ll<<i);

      rep(j,0,i){
        if(!((bit>>j)&1)){
          bit+=(1ll<<j);
        }
      }

      ll temp=0;

      rep(j,0,n){
        if((bit|num[j].first)==bit)temp+=num[j].second;
      }

      chmax(ans,temp);
    }
  }

  std::cout<<ans<<"\n";

  return 0;
}

Measured memory_bytes: 1792
while True:
  n,m = input().split()
  n = int(n)
  m = int(m)
  if n==m==0:
    break
  l = [i for i in range(n)]
  c = -1
  while len(l) >= 2:
    c = (c+m)%len(l)
    l.pop(c)
    c -= 1
  print(l[0]+1)

Measured memory_bytes: 7560
n = int(input())

l = [int(i) for i in input().split()]

cnt = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if l[i] != l[j] and l[j] != l[k] and l[i] != l[k]:
                if l[i] + l[j] > l[k] and l[j] + l[k] > l[i] and l[k] + l[i] > l[j]:
                    cnt += 1

print(cnt)

Measured memory_bytes: 9212
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

int main() {
    string s; cin >> s;
    int n = s.size();
    vector<int> al;
    REP(j,26){
        bool ok = false;
        rep(i,n){
            if(j+96==s[i]) ok = true;
        }
        if(!ok){
            cout << (char) (j + 96) << endl;
            return 0;
        }
    }
    cout << "None" << endl;

}




Measured memory_bytes: 3724
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
  ll n;cin>>n;
  ll ans=0;
  ans+=n/500*1000;
  n%=500;
  ans+=n/5*5;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();   
        String s = sc.next();
        int cnt = 0;
        for (int i = 0; i < n-2; i++) {
            if (s.charAt(i) == 'A') {
                if (s.charAt(i+1) == 'B') {
                    if (s.charAt(i+2) =='C') {
                        cnt++;
                    }
                }
            }
        }        
        
        System.out.println(cnt);
    }
}

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

int main(void){
    int N;
    cin >> N;
    map<int,int> mp;
    int A;
    int cont = 0;
    
    for(int i = 0; i < N;i++){
        cin >> A;

        
        if(mp[A]==0){
            cont++;
            mp[A]++;   
        }
    }
    
    if(cont % 2 == 0)cout << cont - 1 << endl;
    else cout << cont  << endl;
}


Measured memory_bytes: 4992
n,m=map(int,input().split())
costs=[]
for i in range(n):
  a,b=map(int,input().split())
  costs.append([a,b])
costs=sorted(costs, key=lambda student: student[0])
pointer=0
ans=0
while m>0:
  costs[pointer][1]-=1
  ans+=costs[pointer][0]
  m-=1
  if costs[pointer][1]==0:
    pointer+=1
print(ans)

Measured memory_bytes: 93228
n,x=map(int,input().split())

thickness=[1]
for i in range(1,n):
    thickness.append(2*thickness[i-1]+3)
patty=[1]
for i in range(1,n):
    patty.append(2*patty[i-1]+1)


def pattyCnt(n,x):
    if n==0:
        return 0 if x<=0 else 1
    elif x<=1+thickness[n-1]:
        return pattyCnt(n-1,x-1)
    else:
        return patty[n-1]+1+pattyCnt(n-1,x-2-thickness[n-1])

print(pattyCnt(n,x))

Measured memory_bytes: 3064
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define m_p make_pair
#define sz(x) (int)x.size()
#define out(x) cerr<<#x<<" = "<<x<<" "
#define outln(x) cerr<<#x<<" = "<<x<<endl
#define outarr(x,l,r) cerr<<#x"["<<l<<"-"<<r<<"] = "; for (int _i=l;_i<=r;++_i) cerr<<x[_i]<<" ";cerr<<endl;
using namespace std;
typedef long long ll;
typedef pair<ll,int> pii;
#define gc() getchar()
//char buf[1<<23],*p1=buf,*p2=buf;
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline void read(int &x)
{
    x=0; char c=gc(); int flag=0;
    while (c<'0'||c>'9') flag|=(c=='-'),c=gc();
    while (c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=gc();
    if (flag) x=-x;
}
template <class T> T _max(T a,T b){return a>b ? a : b;}
template <class T> T _min(T a,T b){return a<b ? a : b;}
template <class T> bool checkmax(T &a,T b){return b>a ? a=b,1 : 0;}
template <class T> bool checkmin(T &a,T b){return b<a ? a=b,1 : 0;}
const int N=200005;
int n,l,t,rnk=0;
int a[N],w[N],b[N];
void init()
{
    read(n); read(l); read(t);
    for (int i=1;i<=n;++i)
    {
        read(a[i]); read(w[i]);
    }
}

void solve()
{
    for (int i=1;i<=n;++i)
    {
        if (w[i]==1)
        {
            b[i]=a[i]+t;
        }
        else
        {
            b[i]=a[i]-t;
        }
        rnk+=b[i]/l;
        if (b[i]%l<0) --rnk;
        b[i]=(b[i]%l+l)%l;
    }
    sort(b+1,b+n+1);
    rnk=(rnk%n+n)%n+1;
    //outarr(b,1,n); outln(rnk);
    for (int i=1;i<=n;++i)
    {
        b[n+i]=b[i];
    }
    for (int i=rnk;i<rnk+n;++i)
    {
        printf("%d\n",b[i]);
    }
}

int main()
{
    int t=1;
    while (t--)
    {
        init();
        solve();
    }
    return 0;
}


Measured memory_bytes: 5248
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
	ll n;
	cin >> n;
	n /= 3;
	cout << n << endl;
	return 0;
}


Measured memory_bytes: 764
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

//int max(int,int);

int main(){
  int i,j;
  int n;
  int cx;
  int cy;
  int H;
  int p,q;
  int l,k=0;
  int CX=0;
  int CY=0;
  int Hi=0;

  scanf("%d",&n);

  int x[n];
  int y[n];
  int h[n];

  for(i=0; i<=n-1; i++){
    scanf("%d %d %d",&x[i],&y[i],&h[i]);
  }

  for(cx=0; cx<=100; cx++){
    for(cy=0; cy<=100; cy++){
      if(h[0]!=0){
        p = abs(x[0]-cx) + abs(y[0]-cy) + h[0];
      }else if(h[n-1]!=0){
        p = abs(x[n-1]-cx) + abs(y[n-1]-cy) + h[n-1];
      }else if(n!=1 && h[1]!=0){
        p = abs(x[1]-cx) + abs(y[1]-cy) + h[1];
      }
      l=0;
      k=0;
      for(i=0; i<=n-1; i++){
        if(h[i]==0){
          if(p - abs(x[i]-cx) - abs(y[i]-cy)<=0){
            l++;
          }
          continue;
        }
        q = abs(x[i]-cx) + abs(y[i]-cy) + h[i];
        if(q==p){
          l++;
        }
      }
      if(l==n){
        CX = cx;
        CY = cy;
        Hi = p;
      }
    }
  }

  printf("%d %d %d\n",CX,CY,Hi);

  return 0;
}

/*int max(int m,int n){
  if(m>=n){
    return m;
  }else if(n>m){
    return n;
  }
}*/


Measured memory_bytes: 128
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll k,x;
  std::cin>>k>>x;

  for(ll i=-1000000;i<=1000000;i++){
    if(std::abs(i-x)<=k-1)std::cout<<i<<" ";
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);

  int maxId = 0;
  int max = 0;
  for(int i = 0; i < N;i ++){
    cin >> A.at(i);
    if(max < A.at(i) ) {
       max = A.at(i);
       maxId = i;
    }
  }
  
  sort(A.begin(), A.end());
  
  for(int i = 0; i < N;i++){
    if(i != maxId) cout << max << endl;
    else cout << A.at(N-2) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 2432
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n = k()
d=l()

for i in itertools.combinations(d,2):
    ans += i[0]*i[1]

print(ans)


Measured memory_bytes: 10356
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define int long long

// using P = pair<int, int>;

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define debug(x) cerr << #x << ": " << x << '\n'

const int MOD = (int)1e9 + 7;


int mypow(int n, int p) {
    // cout << "p=" << p << endl;
    if (p == 0) {
        return 1;
    }

    if (p == 1) {
        return n;
    }

    if (p % 2 == 0) {
        int a = mypow(n, p /2);
        return (a * a) % MOD;
    } else {
        return (n * mypow(n, p - 1)) % MOD;
    }
}


int combination(int n, int r) {
    int i;
    int ans;
    int nume = 1;
    FORE (i,n-r+1,n) {
        nume = (nume * i) % MOD;
    }

    int deno = 1;
    FORE(i,1, r) {
        deno = (deno * i) % MOD;
    }

    ans = (nume * mypow(deno, MOD - 2)) % MOD;

    debug(nume);
    debug(deno);
    debug(ans);

    return ans;
}

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

    int ans = mypow(2, N) - 1;
    debug(ans);
    ans = (ans - combination(N, A) + MOD) % MOD;
    debug(ans);

    ans = (ans - combination(N, B) + MOD) % MOD;
    debug(ans);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int main(){
    iostream::sync_with_stdio(false);

    int N;
    cin >> N;
    vector<pair<LL, int> > SV;
    for(int i=0; i<N; i++){
        long long s;
        int v;
        cin >> s >> v;
        SV.push_back(MP(s,v));
    }
    sort(SV.begin(), SV.end());

    long long wa[500000];
    wa[0] = SV[0].second;
    for(int i=1; i<N; i++) wa[i] = wa[i-1] + SV[i].second;

    long long iMax[500000];
    for(int i=0; i<N; i++){
        if(i==0) iMax[0] = SV[0].first;
        else iMax[i] = max(iMax[i-1], -wa[i-1]+SV[i].first);
    }
    long long ans = 0;
    for(int j=0; j<N; j++){
        ans = max(ans, wa[j]-SV[j].first+iMax[j]);
    }
    cout << ans << endl;
    
    return 0;
}

/*

大きさをもとにソート
価値についての累積和をつくる
answer = (価値累積和[j]-価値累積和[i-1]) - (大きさ[j]-大きさ[i])
answer = (価値累積和[j]-大きさ[j]) + (-価値累積和[i-1]+大きさ[i])
(-価値累積和[i-1]+大きさ[i])について、j項目での最大値を持つ配列をつくる
answer = (価値累積和[j]-大きさ[j]) + 最大値[j]
文字が1文字になった！ループ1個でOK！

O(NlogN + N + N + N) = O(NlogN)

*/


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

#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define tp top()
#define fr front()
#define pii pair<int,int>
#define pip pair<int,pii>
#define ppi pair<pii,int>
#define ppp pair<pii,pii>
#define sz size()
using namespace std;

int main()
{
	ll mins = 1e18;
	ll n;
	scanf("%lld",&n);
	for(ll i = 1; i*i <= n; i++){
		if (n % i == 0){
		 	ll a = i-1;
		 	ll b = (n / i)-1;
		 	if (mins > a+b){
		 		mins = a+b;
			 }
        }
	}
	printf("%lld\n",mins);

	return 0;
}



Measured memory_bytes: 256
(n,),a,b=$<.map{|l|l.split.map &:to_i}
c,d=[a,b].map{|z|y=z[-1];z.map{|i|y^y=i}}
d+=m=[k=-1]
d.map{|x|k=m[k]until k<0||d[k]==x;m<<k+=1}
j=0
(2*n-1).times{|i|j=m[j]until j<0||d[j]==c[i%n];p i+=1-n,b[0]^a[i]if n==j+=1}

Measured memory_bytes: 59080
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using uInt = long long unsigned int;
using Double = long double;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int N, M;
        cin >> N >> M;

        vector<Int> A(N);
        for (int i = 0; i < N; ++i) cin >> A[i];

        Int sum = accumulate(all(A), 0ll);
        Int cnt = 0;

        for (auto e : A) {
            Int left = 4 * M * e;
            Int right = sum;
            if (left >= sum) {
                cnt++;
            }
        }
        if (cnt >= M) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }


    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    Solve().solve();


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_abs(const _T& a) {
	//	usage:  tp_abs<type name>(a);
	return ((a < 0) ? (a * -1) : a);
}

static const ULLONG UL_HUGE_DIVIDER = 1000000007LLU;
static const LLONG LL_HUGE_DIVIDER = 1000000007LL;

//static void ABC111D_RobotArms();
static void ABC115A_ChristmasEveEveEve();

#if 1
int main()
{
	//ABC111D_RobotArms();
	ABC115A_ChristmasEveEveEve();
	fflush(stdout);
	return 0;
}
#endif

static void ABC115A_ChristmasEveEveEve()
{
	int D;
	scanf(" %d", &D);

	const char* ans[] = {
		"Christmas Eve Eve Eve",
		"Christmas Eve Eve",
		"Christmas Eve",
		"Christmas" 
	};

	printf("%s\n", ans[D - 22]);
}


Measured memory_bytes: 256
n = gets.to_i
nums = gets.split.map(&:to_i)
r = gets.to_i
ress = gets.split.map(&:to_i)

resdic = {}
(1..n).each do |i|
  nums.combination(i) do |array|
    resdic[array.sum] = true
  end
end
ress.each do |resnum|
  resdic[resnum] ? puts("yes") : puts("no")
end


Measured memory_bytes: 9108
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,max=0,x=0;
	string s;
	cin>>n>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='I'){
		x=x+1;
			if(max<x){
			max=x;
			}
		}
		if(s[i]=='D'){
		x=x-1;
			
		}
	}
	cout<<max<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

def main():
    S = readline().rstrip()
    K = int(readline())
    N = len(S)
    d = {}
    for i in range(N):
        s = ''
        head = S[i]
        d.setdefault(head, set())
        for j in range(i, min(N, i+5)):
            s += S[j]
            d[head].add(s)

    for key, val in sorted(d.items()):
        if K <= len(val):
            print(sorted(list(val))[K-1])
            return
        else:
            K -= len(val)


if __name__ == '__main__':
    main()

Measured memory_bytes: 4720
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
using namespace std;

#define A_MAX 2000000
#define INVALID -2000000000

int A[A_MAX];

void insert(int i, int* start) {
    int parent = i / 2;
//    printf(" key[%d]  = %d, p key[%d] = %d\n", i, *(start+i-1), parent, *(start+parent-1));
    if (parent != 0) {
        if (*(start+i-1) > *(start+parent-1)) {
            int tmp = *(start+i-1);
            *(start+i-1) = *(start+parent-1);
            *(start+parent-1) = tmp;
            insert(parent, start);
        }
    }
}

void max_heapify(int i, int *start, int n) {
    int l = i * 2;
    int r = i * 2 + 1;
    int largest;
    if (l <= n && *(start+l-1) > *(start+i-1)) {
        largest = l;
    }
    else {
        largest = i;
    }
    if (r <= n && *(start+r-1) > *(start+largest-1)) {
        largest = r;
    }

    if (largest != i) {
        int tmp = *(start+i-1);
        *(start+i-1) = *(start+largest-1);
        *(start+largest-1) = tmp;
        max_heapify(largest, start, n);
    }
}

void extract(int *start, int n) {
    int parent = n / 2;
    
    // copy last key to root
    *start = *(start + n - 1);

    max_heapify(1, start, n-1);
}

void build_max_heap(int *start, int n) {
    for (int i = n/2; i > 0; i--) {
        max_heapify(i, start, n);
    }
}


void print_queue(int *start, int n) {
    for (int i = 0; i < n; i++) {
        printf(" %d", *(start+i));
    }
    printf("\n");
}


int main() {
    int* start = A;
    int* end = A;
    int n = 0;
    char order[10];
    int key;

    while (1) {
        scanf("%s", order);
        if (strcmp(order, "insert") == 0) {
            cin >> key;
            *end = key;
            n++;
//            printf("insert %d\n", key);
            insert(n, start);
            end++;
        }
        else if (strcmp(order, "extract") == 0) {
            key = *start;
            extract(start, n);
            end--;
            n--;
            cout << key << endl;
        }
        else if (strcmp(order, "end") == 0) {
            break;
        }
//        print_queue(start, n);
    }
        
    return 0;
}



Measured memory_bytes: 7052
/*
    @uthor: Amit Kumar
    user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define ll    long long
#define ld    long double
#define ull   unsigned long long
#define endl "\n"
ll google_itr = 1;
#define google(x) cout<<"Case #"<<x<<":"
#define pi 3.14159265358979323846264338327950L

const ll mod = 1e9+7;
const ll inf = 1e18;

ll popcount(ll num){
    num = num - ((num >> 1) & 0x55555555);
    num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
    return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}

vector<pair<ll,ll>> factor_arr;

void myfactor(ll num){ 
    ll count = 0;   
    while (!(num % 2)) { 
        num >>= 1; count++; 
    }  
    if (count) factor_arr.push_back({2,count}); 
    for (auto i = 3; i <= sqrt(num); i += 2) { 
        count = 0; 
        while (num % i == 0) { 
            count++; 
            num /= i; 
        } 
        if (count) factor_arr.push_back({i,count}); 
    } 
    if (num > 2) factor_arr.push_back({num,1});
}

void virus(){
    ll len;cin>>len;
    map<string,ll> mp;
    while(len--){
        string s;
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;

}


int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

    ll t=1;
    //cin>>t;
    while(t--){
           auto start = high_resolution_clock::now();
           virus();
           auto stop = high_resolution_clock::now();
           auto duration = duration_cast<seconds>(stop - start);
         //cout << "Time: "<<duration.count()<<endl;
        //your code goes here
    }
    return 0;
}

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

#ifdef MYDEBUG
#define dbp(x) cout<<#x<<": "<<x<<endl
#define dbp2(x,y) cout<<#x<<","<<#y<<": "<<x<<","<<y<<endl
#define dbp3(x,y,z) cout<<#x<<","<<#y<<","<<#z<<": "<<x<<","<<y<<","<<z<<endl
#else
#define dbp(x)
#define dbp2(x,y)
#define dbp3(x,y,z)
#endif
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define all(x) x.begin(), x.end()
#define rep(i, from, to) for(int i=from; i<to; ++i)

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  size_t last = v.size() - 1;
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i];
    if (i != last)
      out << ",";
  }
  out << "]";
  return out;
}

ll n, a, b;
void solve() {
  cin >> n >> a >> b;
  if (b < a) {
    cout << 0 << endl;
    return;
  }
  ll ans = (n - 2) * (b - a) + 1;
  cout << (ans < 0 ? 0 : ans) << endl;
}

int main() {
  solve();
  return 0;
}


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

// GCD
int gcd(int a, int b) {
    if(a == 0) return b;
    if(b == 0) return a;
    if(a < b) {
        int tmp = a;
        a = b;
        b = tmp;
    }
    int r = a % b;

    while(r > 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int n;
vector<int> l(100010);
vector<int> r(100010);
vector<int> mgcd(100010);

int main() {
    cin >> n;
    vector<int> a(n+1, 0);
    for(int i = 0; i < n; ++i) cin >> a.at(i);

    l.at(0) = 0; r.at(n+1) = 0;
    for(int i = 0; i < n; ++i) l.at(i+1) = gcd(l.at(i), a.at(i));
    for(int i = n; i > 0; --i) r.at(i) = gcd(r.at(i+1), a.at(i));

    int maxgcd = 0;

    for(int i = 0; i < n; ++i) {
        mgcd.at(i) = gcd(l.at(i), r.at(i+1));
        maxgcd = max(maxgcd, mgcd.at(i));
    }

    cout << maxgcd << endl;


}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REP(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define REP1(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using Int = long long;

//INT_MAX = 2147483647;
//LLONG_MAX = 9223372036854775807;
//ULLONG_MAX = 18446744073709551615;
const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    char s;
    cin >> s;
    if(islower(s)){
        cout << "a" << endl;
    }else{
        cout << "A" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define pb push_back
#define li long int

using namespace std;

void FAST()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}

int main()
{
    FAST();
    li n,i,j;
	cin>>n;
    li a[n][3];
    for(i=0;i<n;i++)
    {
    	for(j=0;j<3;j++)
    		cin>>a[i][j];
	}
    li dp[n][3];
    dp[0][0]=a[0][0];	dp[0][1]=a[0][1];	dp[0][2]=a[0][2];
    
    for(i=1;i<n;i++)
    {
    	dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
    	dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
    	dp[i][2]=a[i][2]+max(dp[i-1][1],dp[i-1][0]);
	}
	
li ans=max(dp[n-1][0],dp[n-1][1]);
	ans=max(ans,dp[n-1][2]);
	
	
	cout<<ans;
}

Measured memory_bytes: 8272
#include <iostream>

using namespace std;

int main() {
	int a, b, c;
	int maxI, cnt = 0;
	cin >> a >> b >> c;
	maxI = b < c ? b : c;

	for (int i = a; i <= maxI; i++) {
		if (c % i == 0) {
			cnt++;
		}
	}
	cout << cnt << endl;
}


Measured memory_bytes: 3116
#include<iostream>

using namespace std;
int main(){
	int a,b;
	
	cin >> a >> b;
	
	if( a == b ){
		cout << "Draw" <<endl;
	}else if( a == 1 || (a > b && b != 1) ){
		cout << "Alice" << endl;
	}else{
		cout << "Bob" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256