akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>

int round(double n){
	double f;
	f = n - floor(n);
	if(f<0.5) return floor(n);
	else return ceil(n);	
}

int main(void){
	int price , num , count = 0 , p_sum = 0 , n_sum = 0;
	while(scanf("%d,%d" , &price , &num)!=EOF){
		count++;
		p_sum += price * num;
		n_sum += num;
	}
	printf("%d\n%d\n" , p_sum , round((double)n_sum / count));
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const long long LINF = 1000000000000000018ll;
const int INF = 1000000009;
const int mod = 1000000007;

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

  int n, k; cin >> n >> k;
  vector<int> dp(n+102, INF);
  vector<int> h(n);

  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= k; j++) {
      dp[i+j] = min(dp[i+j], dp[i] + abs(h[i]-h[i+j]));
    }
  }

  cout << dp[n-1] << endl;

  return 0;
}


Measured memory_bytes: 1024
//#include <bits/stdc++.h>
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<vector>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)//初期値a,i<bの範囲でループ
#define REP(i,n) FOR(i,0,n)//初期値0,i<nの範囲でループ
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;

int n;
int cnt=0;
char g[20];
string s[10010];
ll ans=0;

int v1[10]={0,0,0,0,0,0,1,1,1,2};
int v2[10]={1,1,1,2,2,3,2,2,3,3};
int v3[10]={2,3,4,3,4,4,3,4,4,4};

int powa(int d,int e){
    if(e<0)return 0;
    return pow(d,e);
}

ll ini[5];

int main(){
    cin>>n;
    REP(i,n){
        cin>>g;
        //g=g.substr(0,1);
        //cout<<g[0];
        if(g[0]=='M'){
            ini[0]++;
        }if(g[0]=='A'){
            ini[1]++;
        }if(g[0]=='R'){
            ini[2]++;
        }if(g[0]=='C'){
            ini[3]++;
        }if(g[0]=='H'){
            ini[4]++;
        }

    }

    int c=0;
    REP(i,5){
        if(ini[i]>0)c++;
    }
    if(c<3){
        cout<<0<<endl;
        return 0;
    }


    REP(i,10){
        ans+=ini[v1[i]]*ini[v2[i]]*ini[v3[i]];
    }


    cout<<ans<<endl;
    
    

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define maxl 200010

using namespace std;

int n,ans;
int a[maxl];

inline void prework()
{
	scanf("%d",&n);
	for(int i=1;i<=2*n-1;i++)
		scanf("%d",&a[i]);
}

inline int small(int i,int j,int k)
{
	return a[i]<=k && a[j]<=k;
}

inline int big(int i,int j,int k)
{
	return a[i]>k && a[j]>k;
}

inline int jug(int mid)
{
	for(int i=0;i<=n-1;i++)
	{
		if(big(n+i,n+i+1,mid) || big(n-i,n-i-1,mid))
			return 0;
		if(small(n+i,n+i+1,mid) || small(n-i,n-i-1,mid))
		return 1;
	}
	return small(1,1,mid);
}

inline void mainwork()
{
	int l=1,r=2*n-1,mid;
	while(l+1<r)
	{
		mid=(l+r)>>1;
		if(jug(mid))
			r=mid;
		else
			l=mid;
	}
	if(jug(r))
		ans=r;
	else
		ans=r-1;
}

inline void print()
{
	printf("%d\n",ans);
}

int main()
{
	prework();
	mainwork();
	print();
	return 0;
}

Measured memory_bytes: 1024
while True:
    n,x = map(int,input().split())
    if n == x == 0: break
    ret = 0
    max = x - 2

    if n <= x: max = n  
    for _ in range(max):
        if max == 2: break
        mid = max - 1
        for _ in range(mid):
            min = x - max - mid

            if min <= 0: mid -= 1
            elif min >= mid:

                break
            else: 
                ret += 1
                mid -= 1
        max -= 1
    print(ret)

Measured memory_bytes: 7608
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N, Q;
    cin >> N >> Q;

    enum Type {
        STOP_END, STOP_START, WALK_START
    };
    struct Query {
        Type type;
        ll time, pos;
        bool operator<(const Query& rhs) const {
            return (time != rhs.time ? time > rhs.time : type > rhs.type);
        }
    };
    priority_queue<Query> pq;

    for (ll i = 0; i < N; i++) {
        ll S, T, X;
        cin >> S >> T >> X;
        pq.push({ STOP_START, S - X, X });
        pq.push({ STOP_END,   T - X, X });
    }

    for (ll i = 0; i < Q; i++) {
        ll D;
        cin >> D;
        pq.push({ WALK_START, D, -1 });
    }

    set<ll> st;
    while (!pq.empty()) {
        auto top = pq.top();
        pq.pop();

        if (top.type == STOP_START) {
            st.insert(top.pos);
        } else if (top.type == STOP_END) {
            st.erase(top.pos);
        } else {
            cout << (st.empty() ? -1 : *st.begin()) << endl;
        }
    }
}

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

#define tc(t) int t; cin>>t; while(t--)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; cin >> s;
    int aa = 0;
    int bb = 0;
    int cc = 0;
    for (int i = 0; i < s.length(); ++i) {
        if(s[i] == 'a') aa++;
        else if (s[i] == 'b') bb++;
        else cc++;
    }
    if( aa == 1 && bb == 1 && cc == 1){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }



}






Measured memory_bytes: 3612
#!/usr/bin/env python3
import sys
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(N: int):
    N = str(N)
    if N[0] == N[2]:
        yes()
    else:
        no()
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


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

const int M=105;
char s[M],t[M];

int main()
{
	scanf("%s%s",s,t);
	int n=strlen(s);
	for(int i=0;i<n;i++)
		if(s[i]!=t[i])
		{
			puts("No");
			return 0;
		}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 3668
import math
a, b, C = map(int, input().split())
rad = C / 180 * math.pi
h = b * math.sin(rad)
S = a * h / 2
c = math.sqrt(h**2 + (a-b*math.cos(rad))**2)
L = a + b + c
print(S, L, h)

Measured memory_bytes: 7912
import java.util.Scanner;

public class Main {
	static Long num;
	static long mod = 1000000007;
	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {
			Long N = Long.parseLong(sc.next());
			long A = pow(10,N);
			long a = pow(9,N);
			long b = pow(9,N);
			long c = pow(8,N);
			long d = (A-a-b+c);
			System.out.println(((d%mod)+mod)%mod);
			
		}
	}
	public static long pow(long a,Long N) {
		long res = 1;
		for(int i=0;i<N;i++) {
			res = res*a%mod;
		}
		return res;
	}
}

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

int main() {
  long long n, m;
  cin >> n >> m;
  
  if(n < m) swap(n, m);
  long long ans = 0, mod = pow(10, 9) + 7;
  if(n - m > 1){
    cout << 0 << endl;
    return 0;
  }
  
  vector<long long> mu(n+1, 1);
  for(int i = 1; i <= n; i++){
    mu.at(i) = i * mu.at(i-1) % mod;
  }
  ans = mu.at(n) * mu.at(m) % mod;
  
  if(n - m == 1) cout << ans << endl;
  else cout << ans * 2 % mod << endl;
}

Measured memory_bytes: 4028
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
using pqueg = priority_queue<int, vector<int>, greater<int>>;
using pquel = priority_queue<int, vector<int>, less<int>>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
int lcm(int a, int b){
  return a / __gcd(a, b) * b;
}
int r_int(int a, int b){
  return rand() % b + a;
}
const lint mod=1e9+7;



int main()
{
  lint n, m;
  cin >> n >> m;
  vector<lint> h(n);
  REP(i,n) cin >> h[i];
  vector<set<lint>> cnct(n);
  REP(i,m){
    lint tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    cnct[tmp1-1].insert(h[tmp2-1]);
    cnct[tmp2-1].insert(h[tmp1-1]);
  }

  lint cnt = 0;
  REP(i,n){
    auto itr = cnct[i].upper_bound(h[i]-1);
    if(cnct[i].size() == 0 || itr == cnct[i].end()) cnt++;
  }

  cout << cnt << "\n";
  return 0;
}


Measured memory_bytes: 17980
#include<stdio.h>
main(){
  char k[2],ans='A';
  while(scanf("%c,%c",&k[0],&k[1])!=EOF){
    if(ans==k[0])
      ans=k[1];
    else if(ans==k[1])
      ans=k[0];
  }
  printf("%c\n",ans);
  return 0;
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    sx,sy,tx,ty = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    ans=""
    tx-=sx;ty-=sy
    for _ in range(tx):
        ans+="R"
    for _ in range(ty):
        ans+="U"
    for _ in range(tx):
        ans+="L"
    for _ in range(ty):
        ans+="D"
    ans+="D"
    for _ in range(tx+1):
        ans+="R"
    for _ in range(ty+1):
        ans+="U"
    ans+="L"
    ans+="U"
    for _ in range(tx+1):
        ans+="L"
    for _ in range(ty+1):
        ans+="D"
    ans+="R"
    print(ans)






if __name__ == "__main__":
    main()

Measured memory_bytes: 78528
#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)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

namespace math { namespace integer {

template<class T> T mod_mul(T x, T k, T m) { if(k == 0) { return 0; } if(k % 2 == 0) { return mod_mul((x + x) % m, k / 2, m); } else { return (x + mod_mul(x, k - 1, m)) % m; } }
template<class T> T mod_pow(T x, T n, T mod) { if(n == 0) { return 1; } if(n % 2 == 0) { return mod_pow(mod_mul(x, x, mod) % mod, n / 2, mod); } else { return mod_mul(x, mod_pow(x, n - 1, mod), mod); } }
template<class T> T extgcd(T a, T b, T& x, T& y) { T d = a; if(b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x;} else { x = 1, y = 0; } return d; }
template<class T> T mod_inverse(T x, T mod) { return mod_pow(x, T(mod - 2), mod); /* use fermat */ }
template<class T> T mod_inverse_composite_num_mod(T a, T mod) { T x, y; extgcd(a, mod, x, y); return (mod + x % mod) % mod; }

}}
using namespace math::integer;

typedef long long ll;
int const inf = INT_MAX / 2;

int const MOD = 1e9 + 7;

int main() {
  int N; cin >> N;
  vector<ll> A(N); cin >> A;
  ll b[60][2] = {};
  rep(k, 60) rep(i, N) {
    b[k][(A[i] >> k) & 1]++;
  }
  ll sum = 0;
  rep(i, 60) {
    sum += mod_mul(b[i][0] * b[i][1] % MOD, 1LL << i, (ll)MOD);
    sum %= MOD;
  }
  cout << sum << "\n";
}


Measured memory_bytes: 2560
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		int[] count = new int[N];
		for(int i=0;i<N;i++) {
			 a[i] = sc.nextInt();
		}
		for(int odd : a) {
		if(odd%2 == 1) {
			System.out.println("0");
			System.exit(0);
		}

		}
			for(int b = 0;b<N;b++) {
				for(int c =0;c<100000000;c++) {
					if(a[b]%2==1) {
						break;
					}
					a[b]=a[b]/2;
					count[b]++;
				}
			}
			int min =1000000000;
		for(int d = 0;d<count.length;d++) {
			min = Math.min(min, count[d]);

		}
			System.out.println(min);
		}
}


Measured memory_bytes: 21844
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;


int main(){
    int h, w, k, firstidx=-1, strwbr=1; cin >> h >> w >> k;
    vector<int> tatekosuu(h, 0);
    vector<vector<bool>> yokozahyou(h, vector<bool>(w, false));
    REP(i, h) REP(j, w){
        char s; cin >> s;
        if(s == '#'){
            if(firstidx == -1) firstidx = i;
            ++tatekosuu[i]; yokozahyou[i][j] = true;
        }
    }
    vector<vector<int>> ans(h, vector<int>(w, 0));
    for(int i = firstidx; i < h; ++i){
        if(tatekosuu[i]){
            int cnt = 0;
            REP(j, w){
                ans[i][j] = strwbr;
                if(yokozahyou[i][j]){
                    ++cnt;
                    if(cnt < tatekosuu[i]) ++strwbr;
                }
            }
            ++strwbr;
        }
        else{
            REP(j, w) ans[i][j] = ans[i-1][j];
        }
    }
    for(int i = firstidx-1; i >= 0; --i){
        REP(j, w) ans[i][j] = ans[i+1][j];
    }

    REP(i, h){
        REP(j, w){
            if(j) cout << " ";
            cout << ans[i][j];
        }
        cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 1152
import java.util.*;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[]k = new int[n];
		int[]s = new int[m];
		int[]count = new int[n];
		for(int i = 0; i < n; i++){
			k[i] = sc.nextInt();
		}
		for(int i = 0; i < m; i++){
			s[i] = sc.nextInt();
		}
		for(int i = 0; i < n; i++){
			count[i] = 0;
		}
		
		for(int i = 0; i < m; i++){
			for(int j = 0; j < n; j++){
				if(s[i] >= k[j]){
					count[j] = count[j] + 1;
					break;
				}
			}
		}
		int h = 0;
		int c = 0;
		int i;
		for(i = 0; i < n; i++){
			if(h > count[i]){
			}else if(h < count[i]){
				h = count[i];
				c = i;
			}
		}
		System.out.println(c + 1);

	}

}

Measured memory_bytes: 25036
#include<stdio.h>

int main(void){
  int i,j;
  char s[101];
  scanf("%s",s);
  
  i=0;
  while(s[i]!=NULL){
    i++;
  }
  
  for(j=0;j<=i-1;j++){
    printf("x");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const double eps=1e-6;

int main(){
    int a,b,c,k;
    scanf("%d%d%d%d",&a,&b,&c,&k);
    if(a>=k){
        printf("%d",k);
    }else if(a+b>=k){
        printf("%d",a);
    }else{
        printf("%d",a-(k-a-b));
    }

  return 0;
}


Measured memory_bytes: 3824
#include <stdio.h>

int main () 
{
    char S[4];
    int ans = 0;
    scanf("%s",S);
    
    if (S[0] == 'R') {
        if (S[1] == 'R') {
            if (S[2] == 'R') {
                ans = 3; // RRR
            } else {
                ans = 2; // RRS
            }
        } else {
            ans = 1; // RSR, RSS
        }
    } else {
        if (S[1] == 'R' && S[2] == 'R') {
            ans = 2; // SRR
        } else if(S[1] == 'S' && S[2] == 'S') {
            ans = 0; // SSS
        } else {
            ans = 1; // SSR, SRS
        }
    }
    
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1732
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

map<long long, int> factorization(long long N) {
	map<long long, int> re;
	while (true) {
		if (N % 2 == 0) {
			N /= 2;
			re[2]++;
			if (N == 1) break;
		}
	}
	if (N > 1) re[N]++;
	for (int loop = 3; (long long)loop * (long long)loop <= N; loop += 2) {
		if (N % loop == 0) {
			N /= loop;
			re[loop]++;
			loop -= 2;
			if (N == 1) break;
		}
	}
	if (N > 1) re[N]++;
	return re;
}

struct Memo {
	long long fact = 0;
	long long fact_inv = 0;
	long long inv = 0;
};
class Combination1 {
private:
	int m_module = 1000000007;
	vector<struct Memo> memo;
public:
	int calculate(int, int);
	Combination1(int, int);
};
int Combination1::calculate(int n, int k) {
	return ((memo[n].fact * memo[k].fact_inv) % m_module * memo[n - k].fact_inv) % m_module;
}
Combination1::Combination1(int memo_max, int module = 1000000007) {
	m_module = module;
	memo.push_back({ 1,1,0 });
	memo.push_back({ 1,1,1 });
	for (int loop = 2; loop <= memo_max; loop++) {
		struct Memo temp;
		temp.fact = (memo[loop - 1].fact * loop) % m_module;
		temp.inv = m_module - (memo[m_module % loop].inv * int(m_module / loop)) % m_module;
		temp.fact_inv = (memo[loop - 1].fact_inv * temp.inv) % m_module;
		memo.push_back(temp);
	}
}

class Combination2 {
private:
	int size = 0;
	bool add(int);
public:
	vector<int> sequence;
	bool next_combination(void);
	Combination2(int, int);
};
bool Combination2::add(int index) {
	if (index == (int)sequence.size() - 1 && sequence[index] == size - 1
		|| index < (int)sequence.size() - 1 && sequence[index] == sequence[index + 1] - 1) {
		if (index == 0) {
			return false;
		}
		else {
			bool re = add(index - 1);
			sequence[index] = sequence[index - 1] + 1;
			return re;
		}
	}
	else {
		sequence[index]++;
		return true;
	}
}
bool Combination2::next_combination(void) {
	return (sequence.size() == 0) ? false : add(sequence.size() - 1);
}
Combination2::Combination2(int n, int r) {
	size = n;
	for (int loop = 0; loop < r; loop++) sequence.push_back(loop);
	return;
}

void A_9x9(void) {

	int A, B; cin >> A >> B;
	
	if (A > 9 || B > 9) cout << -1 << flush;
	else				cout << A * B << flush;
	return;
}

void B_81(void) {

	int N; cin >> N;

	for (int loop = 9; loop > 0; loop--) {
		if (N % loop == 0) {
			N /= loop;
			break;
		}
	}
	cout << ((N <= 9) ? "Yes" : "No") << flush;
	return;
}

int main(void) {

	//A_9x9();
	B_81();
	return 0;
}


Measured memory_bytes: 256
# coding:utf-8
import itertools

N, M, X = map(int, input().split(' '))
books = []
ans = (10 ** 5) * N + 1

maximum = [0 for _ in range(M)]
book_id = [idx for idx in range(N)]

for _ in range(N):
    tmp = list(map(int, input().split(' ')))
    books.append(tmp)
    for idx in range(len(maximum)):
        maximum[idx] += tmp[idx+1]

for mx in maximum:
    if mx < X:
        print('-1')
        exit(0)

for book_num in range(1, N+1):
    combs = list(itertools.combinations(book_id, book_num))
    for comb in combs:
        ab = [0 for _ in range(M)]
        s = 0
        flag = True
        for el in comb:
            s += books[el][0]
            ab = [x + y for (x, y) in zip(ab, books[el][1:])]
        for el in ab:
            if el < X:
                flag = False
        if flag and s < ans:
            ans = s

print(ans)


Measured memory_bytes: 9316
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[200],t[200],t1[200];
    int i,j,k,l,n,c;
    cin>>n;
    cin>>s;
    if(n%2==1)
        cout<<"No"<<endl;
    else
    {
        l=n/2;
        k=0;
        for(i=0;i<l;i++)
        {
            t[k++]=s[i];
        }
        t[k]='\0';
        k=0;
        for(i=0;i<l;i++)
        {
            t1[k]=t[i];
            k++;
        }
        for(i=0;i<l;i++)
        { t1[k]=t[i];
        k++;

        }
        t1[k]='\0';

        if(strcmp(s,t1)==0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;


    }
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> day(m);
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        if (a > m) continue;
        day[m-a].push_back(b);
    }
    int ans = 0;
    priority_queue<int> q;
    for (int i = m-1; i >= 0; i--) {
        for (int b : day[i]) {
            q.push(b);
        }
        if (!q.empty()) {
            ans += q.top(); q.pop();
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5632
def gcd(a, b):
    x = max(a, b)
    y = min(a, b)

    if x % y == 0:
        return y
    else:
        while x % y != 0:
            z = x % y
            x = y
            y = z
        return z


A, B = map(int, input().split())
print(int(A * B/gcd(A, B)))

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


int main(){
    int a;
    int b;
    int c;

    cin >> a >> b >> c;

    int d = a - b;
    int e = c - d;
    
    if( e < 0){
        e = 0;
    }

    cout << e ;

    return 0;


}

Measured memory_bytes: 256
from collections import deque

S = list(input())
Q = int(input())

S = deque(S)

Query = [list(input()) for i in range(Q)]

rev_cnt = 0

for i in range(Q):
    if Query[i][0] == "1":
        rev_cnt += 1
    else:
        if Query[i][2] == "1":
            if rev_cnt % 2 == 1:
                S.append(Query[i][4])
            else:
                S.appendleft(Query[i][4])
        else:
            if rev_cnt % 2 == 1:
                S.appendleft(Query[i][4])
            else:
                S.append(Query[i][4])

if rev_cnt % 2 == 1:
    while len(S) != 0:
        print(S.pop(), end="")
else:
    while len(S) != 0:
        print(S.popleft(), end="")


print()


Measured memory_bytes: 37344
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using E = System.Linq.Enumerable;
using System.IO.Pipes;
using System.Threading;

class Program
{
    static char[] abc = "abcdefghijklmnopqrstuvwxyz".ToCharArray();
    static long mod = 1000000007;
    static void Main(string[] args)
    {
        //var S = Console.ReadLine();
        //var N = long.Parse(Console.ReadLine());
        //var N = long.Parse(Console.ReadLine());
        var inp = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var N = inp[0];
        var A = inp[1];
        var B = inp[2];
        var C = inp[3];
        var D = inp[4];
        var S = Console.ReadLine();
        var ans = true;

        //Can B achieve his goal?
        for (int i = (int)A -1; i <= Math.Max(C - 1,D - 1); i++)
        {
            if(S[i] == '#' && S[i+1] == '#')
            {
                ans = false;
                break;
            }
        }

        if(C > D && ans)
        {
            ans = false;
            for (int i = (int)B -1; i <= D - 1; i++)
            {
                if (S[i] == '.' && S[i + 1] == '.' && S[i - 1] == '.')
                {
                    ans = true;
                    break;
                }
            }
        }


        Console.WriteLine(ans ? "Yes" : "No");

    }

}

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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        String s = sc.next(); String t = sc.next();
        int n = s.length(); int m = t.length();
        int [][] a = new int[n + 1][2];
        int [][] b = new int[m + 1][2];
        for (int i = 1; i <= n; i++) {
            a[i][0] = a[i - 1][0];
            a[i][1] = a[i - 1][1];
            if (s.charAt(i - 1) == 'A') a[i][0]++; else a[i][1]++;
        }
        for (int i = 1; i <= m; i++) {
            b[i][0] = b[i - 1][0];
            b[i][1] = b[i - 1][1];
            if (t.charAt(i - 1) == 'A') b[i][0]++; else b[i][1]++;
        }
        int q = sc.nextInt();
        for (int i = 0; i < q; i++) {
            int ss = sc.nextInt(); int se = sc.nextInt();
            int ts = sc.nextInt(); int te = sc.nextInt();
            int sa = a[se][0] - a[ss - 1][0];
            int sb = a[se][1] - a[ss - 1][1];
            int ta = b[te][0] - b[ts - 1][0];
            int tb = b[te][1] - b[ts - 1][1];
            if (((sa - sb) - (ta - tb)) % 3 == 0) {
                out.println("YES");
            } else {
                out.println("NO");
            }
        }
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 60920
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  string s,t;
  cin >> s >> t;
  ll cnt = 0;
  rep(i,s.size()) {
    if (s[i] != t[i]) {
      cnt++;
    }
  }
  cout << cnt << '\n';
}

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

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

    int n;
    cin >> n;
    int p[n];
    rep(i, n) cin >> p[i];
    int ans = 0;
    rep(i, n-2) {
        if ((p[i]<p[i+1] && p[i+1]<p[i+2]) || (p[i]>p[i+1] && p[i+1]>p[i+2])){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
template<typename T> inline void debug(const vector<T> &xs){
#ifdef DEBUG
	pr(xs);
#endif
}

int main(){
	int N;
	cin >> N;
	vector<ll> H(N);
	for(int i=0; i<N; i++) cin >> H[i];

	ll ans = 0;
	ll cnt = 0;
	for(int i=0; i<N-1; i++){
		if(H[i]>=H[i+1]) cnt++;
		else cnt = 0;
		ans = max(ans, cnt);
	}

	cout << ans << endl;



	return 0;
}


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

//macro
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(int)(b) - 1;i>=(int)(a);i--)
#define RREP(i,n) RFOR(i,0,n)
#define each(i, ctn) for (auto &&i : (ctn))
#define all(a) (a).begin(),(a).end()
#define mp make_pair
#define INF 114514810
#define INFL 1145148100000000000LL
#define EPS (1e-8)
#define MOD 1000000007
#define PI 3.141592653589793
#define equals(a,b)(fabs((a)-(b))<EPS)

//alias
using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vs = vector<string>;
using vvs = vector<vs>;
using P = pair<ll, ll>;
template<class T> using heap = priority_queue<T>;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;

//func
template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H);    REP(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); REP(i, n)os << v[i] << (i == n - 1 ? "" : " "); return os; }
template <class T = int> inline T in() { T x; cin >> x; return x; }
template<class T> inline void print(const T &x) { cout << x; }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } pre__;


int main(void) {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b > c + d) {
		print("Left\n");
	}
	else if (a + b < c + d) {
		print("Right\n");
	}
	else {
		print("Balanced\n");
	}
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main(){
var a,b,c,d int
  fmt.Scanf("%d",&a)
  fmt.Scanf("%d",&b)
  fmt.Scanf("%d",&c)
  fmt.Scanf("%d",&d)
  x:=a
  y:=c
  if a>b {
  x=b
  } 
  if c>d{
  y=d
  }
  fmt.Println(x+y)
}

Measured memory_bytes: 512
def sarch(N):
    if N / 2 % 2 == 0:
        return 0
    else:
        return 1

A, B = map(int, input().split())

B += 1
if A % 2 != 0:
    A -= 1
    A = sarch(A) ^ A
else:
    A = sarch(A)

if B % 2 != 0:
    B -= 1
    B = sarch(B) ^ B
else:
    B = sarch(B)

print(A ^ B)

Measured memory_bytes: 3060
import math

def resolve():
    a, b, x = map(int, input().split())
    met = a ** 2 * b / 2
    if x > met:
        y = 2 * b - 2 * x / a**2
        ans = math.atan2(y, a)
    elif x == met:
        ans = math.pi / 4
    else:
        y = 2 * x / a / b
        ans = math.pi / 2 - math.atan2(y, b)

    print(math.degrees(ans))
    
resolve()

Measured memory_bytes: 9332
import collections

N = int(input())
A = list(map(int, input().split()))
C = collections.Counter(A)

D = collections.defaultdict(int)

for k, v in C.items():
    D[k] += v * (v - 1) // 2

pans = sum(D.values())

for a in A:
    p = (C[a] - 1) * (C[a] - 2) // 2
    ans = pans - D[a] + p

    print(ans)



Measured memory_bytes: 30768
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define S second
#define F first
#define all(x) (x).begin(), (x).end()


using namespace std;

const bool dbg_flg = 1;
#define debug(x) if (dbg_flg) cerr << #x << ' ' << x << '\n'
#define debug_pair(x) if (dbg_flg) cerr << #x << ' ' << x.F << ' ' << x.S << '\n'
 
const int inf = 1e9 + 7;
const int MAXN = 1e6 + 5;
const ll INF = 1e18;

int n, m;
char a[1005][1005];
ll dp[1005][1005];

int main() {
	
	//~ freopen(".in", "r", stdin);
	//~ freopen(".out", "w", stdout);
	
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> a[i][j];
		}
	}
	
	dp[1][1] = 1;
	
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (a[i + 1][j] == '.') {
				dp[i + 1][j] += dp[i][j];
				dp[i + 1][j] %= inf;
			}
			if (a[i][j + 1] == '.') {
				dp[i][j + 1] += dp[i][j];
				dp[i][j + 1] %= inf;
			}
		}
	}
	
	
	cout << dp[n][m];
	return 0;
}


Measured memory_bytes: 9088
import java.util.*;

public class Main {

    public static void main(String[] args) {
        //Compute c1 = new Compute();//calc

        long count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        //StringBuilder answer=new StringBuilder();

        //input
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        int d=c-(a-b);
        if (d<0)
        {
            d=0;
        }
        System.out.println(d);
        //output
        //System.out.println(String.format("%.0f",answer));
    }
}

Measured memory_bytes: 25044
n = int(input())
a = 0
for i in range(n+1):
    if i*(i+1)//2 >= n:
        a = i
        break

b=[]
c = a*(a+1)//2
for i in range(1,a+1):
    b.append(i)


if c > n:
    b.pop(c-n-1)

for i in b:
    print(i)

Measured memory_bytes: 3572
#include<iostream>

using namespace std;

int main(){

  int n;
  while(cin >> n){
    if(n == 0) break;
    
    int suma = 0, sumb = 0;
  
    for(int i = 0; i < n; i++){
      int a, b;
      cin >> a >> b;
      if(a > b) suma+=a+b;
      else if(a < b) sumb+=a+b;
      else {
	suma+=a;
	sumb+=b;
      }
    }
    
    cout << suma << " " <<sumb << endl;
  }

  return 0;
}

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

char c;
int main()
{
	cin >> c;
	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') cout << "vowel" << endl;
	else cout << "consonant" << endl;
    return 0;
}


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

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

    vector<int> vec(4);

    for (int i = 0; i < S.size(); i++) {
        switch (S.at(i)) {
            case 'N':
                vec.at(0)++;
                break;
            case 'W':
                vec.at(1)++;
                break;
            case 'S':
                vec.at(2)++;
                break;
            case 'E':
                vec.at(3)++;
                break;
            default:
                break;
        }
    }

    if (vec.at(0) == 0 && vec.at(2) != 0) {
        cout << "No" << endl;
    } else if (vec.at(0) != 0 && vec.at(2) == 0) {
        cout << "No" << endl;
    } else if (vec.at(1) == 0 && vec.at(3) != 0) {
        cout << "No" << endl;
    } else if (vec.at(1) != 0 && vec.at(3) == 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;

const int N = (int) 4005, mod = (int) 1e9 + 7;
int c[N][N];
int main() {
	for (int i = 0; i < N; ++i)
		for (int j = 0; j <= i; ++j)
			c[i][j] = (j == 0 || i == j) ? 1 : (c[i - 1][j - 1] + c[i - 1][j]) % mod;
	int a, b, res = 0;
	cin >> a >> b;
	for (int bl = 1; bl <= b; ++bl)
		for (int br = 1; br + bl <= b; ++br) {
			int rsz = b - bl;
			int ar = rsz - br;
			int al = b - bl;
			int ways = (LL) c[b - 1][bl - 1] * (br == 0 ? 1 : c[rsz - 1][br - 1]) % mod;
			int rem = a - ar - al;
	//		cout << " hi " << bl << ' ' << br << ' ' << al << ' ' << ar << ' ' << rem << ' ' << ways << endl;
			if (rem < 0) continue;
			int s = 3;
			if (br == 0) s = 2;
			ways = (LL) ways * c[rem + s - 1][s - 1] % mod;
			res = (res + ways) % mod;
		}
	cout << (res + a + 1) % mod << endl;
}







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

struct Node {
  int parent;
  int left;
  int right;
};

Node tree[100010];
int depth[100010];
int height[100010];

// v:頂点, d:深さ
void setDepth(int v, int d) {
  if (v == -1) {
    return;
  }
  depth[v] = d;
  setDepth(tree[v].left, d + 1);
  setDepth(tree[v].right, d + 1);
}

// v:頂点
int setHeight(int v) {
  int h1 = 0;
  int h2 = 0;
  if (tree[v].left != -1) {
    h1 = setHeight(tree[v].left) + 1;
  }
  if (tree[v].right != -1) {
    h2 = setHeight(tree[v].right) + 1;
  }
  height[v] = max(h1, h2);
  return height[v];
}

// 頂点uの兄弟を返す
int getSibling(int v) {
  int p_ = tree[v].parent;
  if (p_ == -1) {
    return -1;
  }
  if (tree[p_].left != v && tree[p_].left != -1) {
    return tree[p_].left;
  }
  if (tree[p_].right != v && tree[p_].right != -1) {
    return tree[p_].right;
  }
  return -1;
}

void print (int v) {
  printf("node %d: ", v);
  printf("parent = %d, ", tree[v].parent);
  printf("sibling = %d, ", getSibling(v));
  int deg = 0;
  if (tree[v].left != -1) {
    deg++;
  }
  if (tree[v].right != -1) {
    deg++;
  }
  printf("degree = %d, ", deg);
  printf("depth = %d, ", depth[v]);
  printf("height = %d, ", height[v]);

  if (tree[v].parent == -1) {
    printf("root\n");
  } else if (tree[v].left == -1 && tree[v].right == -1) {
    printf("leaf\n");
  } else {
    printf("internal node\n");
  }
}


int main() {

  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    tree[i].parent = -1;
  }

  for (int i = 0; i < n; i++) {
    int id, left, right;
    cin >> id >> left >> right;
    tree[id].left = left;
    tree[id].right = right;
    if (left != -1) {
      tree[left].parent = id;
    }
    if (right != -1) {
      tree[right].parent = id;
    }
  }

  int root = 0;

  for (int i = 0; i < n; i++) {
    if (tree[i].parent == -1) {
      root = i;
    }
  }

  setDepth(root, 0);

  setHeight(root);

  for (int i = 0; i < n; i++) {
    print(i);
  }

  return 0;

}


Measured memory_bytes: 3232
//
//  main.cpp
//  B - Common Raccoon vs Monster
//
//  Created by Hashizo on 2020/01/26.
//  Copyright © 2020 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>
#include <cmath>

using namespace std;
 
#undef LONG_MAX
#undef LONG_MIN
 
#define LONG_MAX    9223372036854775807
#define LONG_MIN    (-LONG_MAX  -1)
 
#define ll long long
 
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
 
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())


int main(int argc, const char * argv[]) {
	ll ans = 0;


	ll h,n;
	cin >> h >> n;

	vector<ll> point(n);
	REP(i, n) {
		cin >> point[i];
		ans += point[i];
	}

	if ( h > ans) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	
	
	
	return 0;
}


Measured memory_bytes: 1024
import math


a,b=map(int,input().split())

def isPrime(n):
  if n == 2:
    return True
  if n % 2 == 0:
    return False
  
  # nの平方根まで計算する
  m = math.floor(math.sqrt(n)) + 1
  for p in range(3, m, 2):
      if n % p == 0:
        return False
  return True


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

a=set(make_divisors(a))
b=set(make_divisors(b))

cout=0
for i in a&b:
  if isPrime(i) == True:
    cout+=1

print(cout)

Measured memory_bytes: 5080
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,m;
int d[100007],p[100007],pos[300007];
signed main(){
    ios_base::sync_with_stdio(0);
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>d[i]>>p[i];
    }
    for(int i=m+1;i<=n;i++){
        cin>>d[i];
        p[i]=0;
    }
    int l=0,r=1e9+100;
    int mid=(l+r)/2;
    while(l!=mid && r!=mid){
        for(int i=1;i<=n;i++) pos[i]=1;
        for(int i=1;i<=n;i++){
            if(d[i]>=mid) pos[p[i]]=0;
            else pos[p[i]]=1e8;
        }
        int lef=1,rig=n,cnt=0;
        for(int i=m+1;i<=n;i++){
            if(d[i]>=mid) cnt++;
        }
        while(rig-lef>=2){
            int sum=pos[lef]+pos[lef+1]+pos[lef+2];
            int mx=max(pos[lef],max(pos[lef+1],pos[lef+2]));
            sum-=mx;
            rig++;
            lef+=3;
            pos[rig]=sum;
        }
        if(pos[rig]<=cnt) l=mid;
        else r=mid;
        mid=(l+r)/2;
    }
    cout<<l<<endl;
}

Measured memory_bytes: 5904
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn=2e5+10,mod=998244353;
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
int n,R[maxn],L[maxn];
int b[maxn]={0},c[maxn],d[maxn];
long long f[maxn];
struct Node
{
    int x,d;
}a[maxn];
bool operator <(Node A,Node B) { return A.x<B.x;}

int lowbit(int x) {return x&-x;}
void add(int x,int k)
{
    while(x<=n)
        b[x]=max(b[x],k),x+=lowbit(x);
}
int query (int L, int R) 
{
	int ret = 0, len = R-L+1;
	while (len && R)
    { 
		if (len < lowbit(R)) 
        {
			ret = max (ret, b[R]);
			R--; len--;
		} 
        else 
        {
			ret = max (ret, b[R]);
			len -= lowbit(R); 
			R -= lowbit(R); 
		}
	}
	return ret;
}

int main()
{
    #ifdef __LOCAL__
        freopen("1.in","r",stdin);
        freopen("1.out","w",stdout);
    #endif
    scanf("%d",&n);
    _rep(i,1,n)
        scanf("%d%d",&a[i].x,&a[i].d);
    sort(a+1,a+n+1);

    // R[n]=n;
    // for(int i=1;i<n;i++)
    // {
    //     int j=i,far=a[i].x+a[i].d;
    //     while(far>a[j+1].x&&j<n)
    //     {
    //         far=max(far,a[j+1].x+a[j+1].d);    
    //         j++;
    //     }                
    //     R[i]=j;
    // }

    _rep(i,1,n)
        b[i]=lower_bound(a+1,a+1+n,(Node){a[i].x+a[i].d,0})-a-1;    

    //i~b[i]-1
    // _rep(i,1,n)
    // {
    //     int mx=b[i];
    //     for(int j=i;j<=mx;j++)
    //     {
    //         d[i]=max(d[i],b[j]);
    //         if(b[j]>mx)
    //             mx=b[j];
    //     }
    // }
    // for(int i=1;i<=n;i++)
    //     cout<<R[i]<<" "<<d[i]<<endl;

    for(int i=n;i>=1;i--)
    {
        L[i]=max(i,query(i,b[i]));
        add(i,L[i]);
    }

    // for(int i=n;i>=1;i--)
    //     cout<<i<<" "<<R[i]<<" "<<L[i]<<endl;

    f[n+1]=1;
    for(int i=n;i>=1;i--)
        f[i]=(f[i+1]+f[L[i]+1])%mod;

    cout<<f[1]<<endl;
    return 0;
}

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

vector<vector<int>> dp;

int Max(int a, int b, int c){
    return max(a, max(b, c));
}

int solve(vector<vector<int>>& arr, int curr, int index, int n){
    if(index == 0){
        return arr[curr][index];
    }
    if(dp[curr][index] != -1){
        return dp[curr][index];
    }
    for(int i = 0 ; i < 3; i ++){
        dp[i][index] = arr[i][index] + max(solve(arr, (i+1)%3, index-1, n), solve(arr, (i+2)%3, index-1, n));
    }
    return dp[curr][index];
}


int32_t main(){
    int n;
    cin >> n;
    vector<vector<int>> arr(3, vector<int>(n, 0));
    for(int i = 0 ; i < n ; i ++){
        cin >> arr[0][i] >> arr[1][i] >> arr[2][i];
    }
    dp.assign(3, vector<int>(n, -1));
    dp[0][0] = arr[0][0];
    dp[1][0] = arr[1][0];
    dp[2][0] = arr[2][0];
    solve(arr, 0, n-1, n);
    cout << Max(dp[0][n-1], dp[1][n-1], dp[2][n-1]) << endl;
    return 0;
}


Measured memory_bytes: 15088
#include<iostream>
#include<vector>
#define ll long long int
using namespace std;
vector<ll>divisors[10000000];
int main()
{
	ll n,sum=0;
	cin>>n;
	n--;
	for(int i=1;i<=n;i++)
	{
		for(int j=i;j<=n;j+=i)
		{
			divisors[j].push_back(i);
		}
	}
	for(int i=1;i<=n;i++)
	{
		sum=sum+(divisors[i].size());	
	}
	cout<<sum<<endl;
	return 0;
	
}

Measured memory_bytes: 395356
#include <bits/stdc++.h>
using namespace std;
#define maxn 100010

long long i,n,s,k,m,a[maxn];

int main()
{
    cin>>n;
    m=100000000000;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]<0)
        {
            k++;
            a[i]=-a[i];
        }
        s+=a[i];
        m=min(m,a[i]);
    }
    if(k&1) cout<<s-2*m<<"\n";
    else cout<<s<<"\n";
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long int
#define tc int t; cin>>t; while(t--)
int main() {
 //fastio
ll n,a,b;
cin>>n>>a>>b;
cout<<min(n*a,b);
}





Measured memory_bytes: 256
#include <iostream>
#include <set>

using namespace std;

int main() {
    int N, K;

    cin >> N >> K;

    set<int> sunuke;

    for(int i = 0; i < K; i++) {
        int d;
        cin >> d;
        for(int j = 0; j < d; j++) {
            int A;
            cin >> A;
            sunuke.insert(A);
        }
    }

    int ans = N - sunuke.size();

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define mid ((left + right) >> 1)
#define lson rt << 1, left, mid
#define rson rt << 1 | 1, mid + 1, right

const double pi = acos(-1.0);
const int INF = 1e9 + 1;
const int N = 1e5 + 5;

int n;
int sum[11][11];

int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int val = i;
        int head = -1;
        while (val >= 10) val /= 10;
        head = val;
        int tail = i % 10;
        sum[head][tail] += 1;
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        int val = i;
        int head = -1;
        while (val >= 10) val /= 10;
        head = val;
        int tail = i % 10;
        if (tail == 0) continue;
        ans += sum[tail][head];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N=int(input())
D={}
ans=[]
numlist=list(map(int,input().split()))
for i,j in zip(numlist,range(1,N+1)):
    D.update({i:j})
for k in range(1,N+1):
    ans.append(D[k])
 
a=" ".join(map(str,ans))
print(a)

Measured memory_bytes: 23924
MOD = 10 ** 9 + 7

n,k=map(int, input().split())
a=list(map(int, input().split()))
aplus,aminus=[],[]

for i in range(n):
    if a[i] >= 0: aplus.append(a[i])
    else: aminus.append(a[i])

      
if len(aplus) == 0 and k % 2 == 1:
    asort = sorted(a,reverse=True)
    ans = 1
    for i in range(k):
        ans = (ans * asort[i]) % MOD
    print(ans)
    exit()

if n == k:
    ans = 1
    for i in range(k):
        ans = (ans * a[i]) % MOD
    print(ans)
    exit()

newa = sorted(a,reverse=True,key=abs)
newaplus = sorted(aplus,reverse = True)
newaminus = sorted(aminus)

cntp,cntm,pp,mm=0,0,0,0

for i in range(k):
    if newa[i] >= 0:
        cntp += 1
        pp = i
    else:
        cntm += 1
        mm = i

if cntm % 2 == 1:
    if cntp == 0:
        newa[mm] = newaplus[cntp]
    elif len(newaplus) == cntp:
        newa[pp] = newaminus[cntm]
    elif len(newaminus) == cntm:
        newa[mm] = newaplus[cntp]
    else:
        if newa[pp] * newaplus[cntp] >= newa[mm] * newaminus[cntm]:
            newa[mm] = newaplus[cntp]
        else:
            newa[pp] = newaminus[cntm]

ans = 1
for i in range(k):
    ans = (ans * newa[i]) % MOD
    
print(ans)

Measured memory_bytes: 31792