akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#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 ll long long
#define INF 999999999
using namespace std;
int main() {
  ll A,B,N;
  std::cin >> A >> B >> N;
  if (N < B-1 ) {
    std::cout << A*N/B-(N/B)*A << '\n';
  }
  else{
   if (A%B == 0) {
     std::cout << A-A/B << '\n';
   }
   else{
     std::cout << A-A/B-1 << '\n';
   }
  }
}


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

int calc(int n){
  int x;
  if(n%2==0) x= n/2;
  else x = 3*n+1;
  return x;
}

int main(){
  int n;
  cin>>n;
  vector<int> num(1000000);
  num[0]=n;
  int i=1;
  while(true){
    int x=calc(n);
    num[i]=x;
    n=x;
    i++;
    for(int j=0;j<i-1;j++){
      if(num[j]==num[i-1]){
        cout<<i<<endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 4096
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
	int ans = 1,n,k;
	scanf("%d %d",&n,&k);
	for(int i = 0;i < n;i++){
		ans += min(ans,k);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,ans=0;
  cin>>n;
  char s[n];
  int red=0;
  for(int i=0;i<n;i++){
  	cin>>s[i];
    if(s[i]=='R') red++;
  }
  for(int i=0;i<red;i++){
  	if(s[i]=='W') ans++;
  }
	cout<<ans;
}

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

using namespace std;

const int N = 2000 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n;
long long a[N], r[N], F[N], rF[N];

bool read() {
    if (!(cin >> n))
        return false;

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

    return true;
}

void solve() {
    F[0] = rF[0] = F[1] = rF[1] = r[1] = 1;

    for (int i = 2; i <= n; ++i) {
        r[i] = (MOD - (MOD / i) * r[MOD % i] % MOD) % MOD;
        F[i] = i * F[i - 1] % MOD;
        rF[i] = r[i] * rF[i - 1] % MOD;
    }

    auto ans = 0ll;

    for (int k = (n + 1) / 2; k < n; ++k)
        ans += F[k] * F[k - 1] % MOD * rF[2 * k - n] % MOD;

    cout << (MOD + F[n] - ans % MOD) % MOD << endl;
}

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

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 28928
#include <iostream>
#include <string>
#include <map>
#include <set>
int main() {
    long long M = 1000000007;
    char acgt[4] = {'A', 'C', 'G', 'T'};
    std::set<std::string> bad = {
        "ACG", "AGC", "GAC",
        "AGAC", "GGAC", "CGAC", "TGAC",
        "CAGC", "GAGC", "AAGC", "AGGC", "ATGC", "TAGC", "AGTC",
        "AACG", "CACG", "TACG", "ACGG"
    };
    int n;
    std::cin >> n;
    std::map<std::string, long long> m0;
    m0["A"] = 1;
    m0["C"] = 1;
    m0["G"] = 1;
    m0["T"] = 1;
    for (int i = 1; i < n; i++) {
        std::map<std::string, long long> m1;
        for (auto &e: m0) {
            const std::string &s0 = e.first;
            long long x0 = e.second % M;
            for (char c: acgt) {
                std::string s1 = (s0.size() == 4 ? s0.substr(1) : s0) + c;
                if (bad.find(s1) == bad.end()) {
                    m1[s1] += x0;
                }
            }
        }
        m0.swap(m1);
    }
    long long ans = 0;
    for (auto &e: m0) {
        ans += e.second;
    }
    std::cout << (ans % M);
}

Measured memory_bytes: 256
character(200) A,B
read*,A,B
if( len_trim(A) > len_trim(B))print"(A)","GREATER"
if( len_trim(A) < len_trim(B))print"(A)","LESS"
if( len_trim(A) == len_trim(B))then
do i=1,len_trim(A)
 if( ichar(A(i:i)) > ichar(B(i:i)))then
   print"(A)","GREATER"
   STOP
 end if
 if( ichar(A(i:i)) < ichar(B(i:i)))then
   print"(A)","LESS"
   STOP
 end if
end do
print"(A)","EQUAL"
endif
end

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int H,W,K;
  cin>>H>>W>>K;
  bool S[H][W];
  REP(h,H)REP(w,W)S[h][w]=0;
  REP(h,H)REP(w,W){
    char c;
    cin>>c;
    if(c=='1')S[h][w]=true;
  }
  int ans=99999;
  REP(i,1<<(H-1)){
    bool c[H-1];
    c[0]=false;
    FOR(h,1,H)c[h]=(i>>(h-1))&1;
    int temp=0;
    REP(h,H)if(c[h])temp++;
    int counter[H];
    REP(h,H)counter[h]=0;
    REP(w,W){
      int d=0,e=0;
      REP(h,H){
        if(c[h]){
          d=0;
          e=0;
        }
        d+=counter[h];
        e+=S[h][w];
        if(e>K){
          temp=99999;
          break;
        }
        if((d+e)>K){
          temp++;
          REP(hh,H)counter[hh]=0;
          break;
        }
      }
      REP(h,H)counter[h]+=S[h][w];
    }
    // REP(h,H)cerr<<c[h];
    // cerr<<endl;
    // cerr<<temp<<endl;
    ans=min(ans,temp);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;

template <typename T>
constexpr bool chmin(
    T &a, T b, function<bool(T, T)> f = [](T a, T b) { return a > b; }) {
  // when f is true, b is more 'smaller'
  if (f(a, b)) {
    swap(a, b);
    return true;
  }
  return false;
}
template <typename T> constexpr bool chmax(T &a, T b) {
  if (a < b) {
    swap(a, b);
    return true;
  }
  return false;
}
template <typename ite> void print_ite(ite start, ite end, char c = ' ') {
  for (auto i = start; i != end; i++)
    cout << i << c;
  cout << endl;
}
template <typename ite> void scan_ite(ite start, ite end) {
  for (auto i = start; i != end; i++)
    cin >> (*i);
}
inline void Yes(bool condition) { cout << (condition ? "Yes\n" : "No\n"); }

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


Measured memory_bytes: 1024
import java.util.Map;
import java.util.HashMap;
import java.util.Scanner;

public class Main{
    
    public static void main(String[] args){

        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
        Scanner sc = new Scanner(System.in);
        int cap;

        int n = sc.nextInt();

        while(n-- > 0){
            cap = sc.nextInt();
            if(!map.containsKey(cap)) map.put(cap, 1);
            else map.put(cap, map.get(cap) + 1);
        }

        int ans = 0;

        for(int key: map.keySet()){
            if(map.get(key) < key) ans += map.get(key);
            else ans += map.get(key) - key;
        }

        System.out.println(ans);
    }

}

Measured memory_bytes: 62772
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}
long long gcd(long long x,long long y){
	return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
	return x/gcd(x,y)*y;
}

// konoshita kara kaku

int main(void){
	int n=in(),i,a[50],fp=0,fn=0,M=0,m=0;
	rep(i,n){
		a[i]=in();
		if(a[i]>=0)fp=1;
		else fn=1;
	}
	if(fp&fn){
		print(2*n-1);
		rep(i,n){
			if(a[i]>a[M])M=i;
			if(a[i]<a[m])m=i;
		}
		if(abs(a[M])>abs(a[m])){
			rep(i,n)print2(M+1,i+1);
			rep(i,n-1)print2(i+1,i+2);
		}
		else{
			rep(i,n)print2(m+1,i+1);
			rev(i,n-1)print2(i+2,i+1);
		}
	}
	else if(fp){
		print(n-1);
		rep(i,n-1)print2(i+1,i+2);
	}
	else{
		print(n-1);
		rev(i,n-1)print2(i+2,i+1);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i = 0; i < n; i++)
#define pb push_back
#define all(c) c.begin(),c.end()



int main()
{
    int n, m;
    cin >> n >> m;
    for(int i =0; i < m; i++)
    {
         int x; cin >> x;
         n-=x;
         if(n <0)
         {
             cout << -1;
             return 0;
         }
    }
    cout << n;


}



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

string lcs(string a, string b) {
    if (a.size() > b.size())
        swap(a, b);
    int n = a.size();
    int m = b.size();
    vector<vector<string>> kek(2, vector<string>(n + 1));

    for (int j = 1; j <= m; ++j)
    for (int i = 1; i <= n; ++i)
        if (a[i - 1] == b[j - 1])
            kek[j % 2][i] = kek[(j + 1) % 2][i - 1] + a[i - 1];
        else {
            auto left = kek[j % 2][i - 1];
            auto up = kek[(j + 1) % 2][i];

            kek[j % 2][i] = left.size() > up.size()
                            ? left
                            : up;
        }

    return kek[m % 2][n];
}

int main(void) {
    string s, t;
    cin >> s >> t;
    cout << lcs(s, t) << endl;
}


Measured memory_bytes: 22080
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n,d,a = nm()
l = [tuple(nm()) for _ in range(n)]
l.sort()
l += [(10**20,10**20)]
r = [0]*(n+3)
rind = 0
ans = 0
for i in range(n):
    x,h = l[i]
    r[i] += r[i-1]
    h -= r[i]
    # print(i,"x,h",x,h)
    if h <= 0: continue
    curd = x + 2*d
    while l[rind+1][0] <= curd:
        rind += 1
    # print(i,"cued,rind",curd,rind)
    cnt = (h-1)//a + 1
    dam = cnt*a
    r[i] += dam
    r[rind+1] -= dam
    ans += cnt
print(ans) 


Measured memory_bytes: 38064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String data = sc.nextLine();
        
        String[] array = data.split(" ");
        int n = Integer.parseInt(array[0]);
        int m = Integer.parseInt(array[1]);
        
        int[][] table = new int[m][2];
        for(int i = 0; i < m; i++)
        {
            for(int j = 0; j < 2; j++)
            {
                table[i][j] = sc.nextInt();
            }
        }
        
        int[] seisu = new int[n];
        
        String[] memo = new String[n];
        
        int result = 0;
        for(int i = 0; i < m; i++)
        {
            int keta = table[i][0];
            int suuji = table[i][1];
            
            if(memo[keta - 1] == null)
            {
                seisu[keta - 1] = suuji;
                memo[keta - 1] = "x";
            }
            else
            {
                if(suuji != seisu[keta - 1])
                result = -1;
            }
        }
        
        if(n >= 2 && memo[0] != "x" && seisu[0] == 0)
        {
            seisu[0] = 1;
        }
        
        if(result != -1)
        {
            String buf = "";
            for(int i = 0; i < n; i++)
            {
                buf = buf + String.valueOf(seisu[i]);
            }
            result = Integer.parseInt(buf);
            int resultlen = String.valueOf(result).length();
            if(resultlen < n)
            {
                result = -1;
            }
        }
        
        System.out.println(result);
    }
}


Measured memory_bytes: 23892
def kazu_up(kosu, a, kazu):
    if a in kazu:
        kazu[a] += kosu
    else:
        kazu[a] = kosu
    
    return kazu

def kazu_down(a, kazu):
    if a in kazu:
        del kazu[a]
            
    return kazu

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC=[]
kazu = {}

for q in range(Q):
    BC.append(list(map(int, input().split())))
    
A_sum = 0
    
for a in A:
    A_sum += a
    kazu = kazu_up(1, a, kazu)

for bc in BC:
    try:
        A_sum += ( bc[1] - bc[0] ) * kazu[bc[0]]
        print(A_sum)
        kazu = kazu_up(kazu[bc[0]], bc[1], kazu)
        kazu = kazu_down(bc[0], kazu)
        
    except:
        print(A_sum)

Measured memory_bytes: 104912
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
#define REP(i,N) for(ll i=0;i<N;++i)

int main() {
	string S; // 1 ... 100
	double K; // 1 ... 10^18
	cin >> S >> K;
	// 5000兆 = 5000 * 10^12 = 5 * 10^15
	// 2 ^ (5*10^15)
	// 2 ^ 10 = 10 ^3 
	// 2 ^ (10^15) = 10^(3*10^14)
	if (K == 1 || S.size() == 1 || S[0] != '1') {
		cout << S[0] << endl;
	} else {
		bool x = false;
		for (int i=0; i<S.size(); ++i) {
			if (S[i] == '1') continue;
			if (K < (i+1)) {
				cout << 1 << endl;
			} else {
				cout << S[i] << endl;
			}
			x = true;
			break;
		}
		if (!x) {
			cout << 1 << endl;
		}
	}	 
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define read(i) scanf("%d",&i)
#define rep(i,s,t) for(int i=s;i<=t;i++)
using namespace std;
typedef long long ll;

int main()
{
    ll a,b,c;
    cin>>a>>b>>c;
    c=min(c,a+b+1);
    cout<<b+c<<endl;
}


Measured memory_bytes: 256
n = input()
h = input().split()

sum_hotel = 0
max_height_mt = 0

for i in range(int(n)):
    if max_height_mt <= int(h[i]):
        sum_hotel += 1
    if max_height_mt <= int(h[i]):
        max_height_mt = int(h[i])

print(sum_hotel)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
const int MN=2e5+5;
int to[MN<<1],nxt[MN<<1],h[MN],cnt;
inline void ins(int s,int t){
	to[++cnt]=t;nxt[cnt]=h[s];h[s]=cnt;
	to[++cnt]=s;nxt[cnt]=h[t];h[t]=cnt;
}
int n,node[2][MN],tot[2],Ans[MN];
bool vis[MN];
void dfs(int st,int col){
	vis[st]=true;node[col][++tot[col]]=st;
	for(reg int i=h[st];i;i=nxt[i])
		if(!vis[to[i]])dfs(to[i],col^1);
}
int main(){
	scanf("%d",&n);
	for(reg int i=1,s,t;i<n;i++)
		scanf("%d%d",&s,&t),ins(s,t);
	dfs(1,0);
	if(tot[0]>tot[1])swap(tot[0],tot[1]),swap(node[0],node[1]);
	for(reg int i=1;i<=n;i++)vis[i]=false;
	if(tot[0]<=n/3){
		for(reg int i=3,j=1;j<=tot[0]&&i<=n;i+=3,j++)
			Ans[node[0][j]]=i,vis[i]=true;
		for(reg int i=1,j=1;i<=n;i++){
			if(vis[i])continue;
			Ans[node[1][j]]=i;j++;
		}
		for(reg int i=1;i<=n;i++)printf("%d%c",Ans[i],i==n?'\n':' ');
		return 0;
	}
	for(reg int i=1,j=1;i<=n;i+=3,j++)Ans[node[0][j]]=i;
	for(reg int i=2,j=1;i<=n;i+=3,j++)Ans[node[1][j]]=i;
	for(reg int j=1,i=3;j<=n;j++){
		if(Ans[j])continue;Ans[j]=i;i+=3;
	}
	for(reg int i=1;i<=n;i++)printf("%d%c",Ans[i],i==n?'\n':' ');
	return 0;
}

Measured memory_bytes: 11392
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
diff=[]
d=0
ans=0
for i in range(N):
  if A[i]<B[i]:
    d+=B[i]-A[i]
    ans+=1
  elif A[i]>B[i]:
    diff.append(A[i]-B[i])

diff=sorted(diff,reverse=True)
diff.append(0)

#print(d)

f=False
for i in range(len(diff)):
  if d<=0:
    ans+=i
    f=True
    break
  d-=diff[i]
  
  

if f:
  print(ans)
else:
  print(-1)
#print(diff)

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

#define F first
#define S second
#define x1 privet1
#define x2 privet2
#define y1 privet3
#define y2 privet4
#define left privet6

using namespace std;
typedef long long ll;

const int max_n = 200011, log_n = 32, max_m = 111, mod = 1000000007, inf = 1000111222;

int n, a[max_n];
ll sum[max_n];

int main() {
    // freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i =0 ; i < n; ++i) {
        cin >> a[i];
        sum[i] = a[i];
        if (i) sum[i] += sum[i - 1];
    }
    ll ans = 1LL * inf * inf;
    for (int i = 0; i < n - 1; ++i) {
        ans = min(ans, abs(sum[i] - (sum[n - 1] - sum[i])));
    }
    cout << ans << endl;
    return 0;
}


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

#define int long long
const int MOD=1e9+7;

signed main(){
  int n;cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  int ans=0,tmp=0;
  for(int i=n-1;i>=0;i--){
    (ans+=v[i]*tmp)%=MOD;
    (tmp+=v[i])%=MOD;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4820
#include<iostream>
#include<math.h>
using namespace std;

int main(){
  int n, base, digit;
  cin >> n >> base;
  if (n == 1)
  {
    cout << 1 << "\n";
    return 0;
  }
  digit = ceil(log(n) / log(base));
  cout << digit << "\n";
  return 0;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
mod = 10**9+7
from functools import lru_cache

@lru_cache(maxsize=1000)
def dfs(n, l):
    rt = 0
    if n == 0:
        return 1
    if l[1:3] == 'AG' or l[1:3] == 'GA' or (l[0] == 'A' and l[2] == 'G') or l[:2] == 'AG':
        pass
    else:
        rt += dfs(n-1, l[1:]+'C')
    if l[1:] != 'AC':
        rt += dfs(n-1,l[1:]+'G')
    rt += dfs(n-1,l[1:]+'T')
    rt += dfs(n-1,l[1:]+'A')
    return rt%mod



print(dfs(n,'TTT')%mod)

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

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

    int cnt[10100] = {};
    for (int x = 1; x * x <= 10000; x++) {
        for (int y = 1; y * y <= 10000; y++) {
            for (int z = 1; z * z <= 10000; z++) {
                int n = x * x + y * y + z * z + x * y + y * z + z * x;
                if (n <= 10000) cnt[n]++;
            }
        }
    }

    for (int i = 1; i <= N; i++) cout << cnt[i] << endl;
}

Measured memory_bytes: 3688
#![allow(unused_imports)]
#![allow(dead_code)]

use std::thread;
use std::io::{ self, Read };
use std::fmt;
use std::iter::Iterator;
use std::cmp::*;
use std::collections::*;
use std::str::*;
use std::mem::*;
use std::cell::*;

#[derive(Default)]
struct Input {
    buf: Vec<String>
}

impl Input {
    fn new() -> Input {
        Input { buf: Vec::new() }
    }

    fn read<T: FromStr>(&mut self) -> T 
    where <T as FromStr>::Err: fmt::Debug {
        self.next().unwrap().parse::<T>().unwrap()
    }

    fn read_2<T: FromStr, U: FromStr>(&mut self) -> (T, U)
    where <T as FromStr>::Err: fmt::Debug,
          <U as FromStr>::Err: fmt::Debug {
        (self.read(), self.read())
    }

    fn read_3<T: FromStr, U: FromStr, V: FromStr>(&mut self) -> (T, U, V)
    where <T as FromStr>::Err: fmt::Debug,
          <U as FromStr>::Err: fmt::Debug,
          <V as FromStr>::Err: fmt::Debug {
        (self.read(), self.read(), self.read())
    }

    fn read_bytes(&mut self) -> Vec<u8> {
        self.next().unwrap().into_bytes()
    }

    fn read_n<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where <T as FromStr>::Err: fmt::Debug {
        let mut v = Vec::new();
        for _ in 0..n { v.push(self.read::<T>()); }
        v
    }
}

impl Iterator for Input {
    type Item = String;
    fn next(&mut self) -> Option<String> {
        while self.buf.is_empty() {
            let mut s = String::new();
            let _res = io::stdin().read_line(&mut s);
            self.buf = s.split_whitespace().map(|s| s.to_owned()).collect::<Vec<_>>();
            self.buf.reverse();
        }
        self.buf.pop()
    }
}

fn lower_bound<T: Ord>(a: &[T], x: &T) -> usize {
    let mut l = -1i64;
    let mut r = a.len() as i64;
    while r - l > 1 {
        let m = (r - l) / 2 + l;
        if x <= &a[m as usize] { r = m; }
        else { l = m; }
    }
    r as usize
} 

fn run() {
    let mut ip = Input::new();
    let n = ip.read();
    let mut a: Vec<i64> = ip.read_n(n);   
    let mut b: Vec<i64> = ip.read_n(n);

    let mut y = 0;
    for i in (0..29).rev() {
        let bit = 1i64 << i;
        for x in &mut a { *x %= bit << 1; }
        for x in &mut b { *x %= bit << 1; }

        b.sort();
        // dbg!(&b);
        for &x in &a {
            let c01 = lower_bound(&b, &(bit - x));
            let c10 = lower_bound(&b, &(2 * bit - x));
            let c11 = lower_bound(&b, &(3 * bit - x));
            let c = c10 - c01 + n - c11;
            // dbg!(c01, c10, c11, n);
            y ^= (c % 2) << i as i64;
        }
    }

    println!("{}", y);    
}

fn main() {
    let _ = thread::Builder::new()
        .stack_size(50 * 1024 * 1024)
        .spawn(run).unwrap()
        .join();
}

Measured memory_bytes: 28320
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[1:]

n = int(input())

a = make_divisors(n-1)

b = make_divisors(n)
count = 0

for kk in b:
    mom = n
    while mom % kk == 0:
        mom //= kk
    if mom % kk == 1:
        count +=1

print(len(a) + count)


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <map>
#include <deque>
#include <cmath>
using namespace std;

int T[5];
int main() {
	int a;
	for(int i=0; i<6; ++i){
	    cin >> a;
	    ++T[a];
	}
	sort(T+1, T+5, greater<int>());
	if(T[1]<3) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 1e9 + 7;

int pos[100005];
int nxt[100005][20];

int main()
{
	int n, l, q;
	scanf("%d", &n);
	rep(i, n) scanf("%d", &pos[i]);
	scanf("%d%d", &l, &q);
	rep(i, n) nxt[i][0] = upper_bound(pos, pos + n, pos[i] + l) - pos - 1;
	rep1(i, 16) rep(j, n) nxt[j][i] = nxt[nxt[j][i - 1]][i - 1];
	rep(i, q) {
		int a, b, ans = 1;
		scanf("%d%d", &a, &b);
		a --; b --;
		if(a > b) swap(a, b);
		for(int j = 16; j >= 0; j --)
		if(nxt[a][j] < b) {
			a = nxt[a][j];
			ans += 1 << j;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
const ll MINF=-1LL*1e9-1;
bool comp(const pll a,const pll b)
{
	if(a.second!=b.second)
	{
		return a.second<b.second;
	}
	return a.first<b.first;
}
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	ll n;
 	cin>>n;
 	pll a[n];
 	for(ll i=0;i<n;i++)
	{
		ll x,l;
		cin>>x>>l;
		a[i].first=x-l;
		a[i].second=x+l;
	}	
	sort(a,a+n,comp);
	ll cur=MINF;
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		if(cur<=a[i].first)
		{
			ans++;
			cur=a[i].second;
		}
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1920
// https://atcoder.jp/contests/abc156/tasks/abc156_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, R;
    cin >> N >> R;
    if (N >= 10) {
        cout << R << endl;
    } else {
        cout << R + 100 * (10 - N) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define endl '\n'

using namespace std; 

main()
{ 
	fast;
	int a,b,c;
	cin>>a>>b;
	c=b*2;
	if (a<c)
		cout<<0<<endl;
	else
		cout<<(a-c)<<endl;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int w,h,mp[101][101];
int dy[6]={-1,-1,0,0,1,1};
int dx[2][6]={
  {0,1,-1,1,0,1},
  {-1,0,-1,1,-1,0}
};


int used[101][101];
int mark(int y,int x){
  if(x<0||y<0||x>=w||y>=h)return 0;
  if(mp[y][x]||used[y][x]++)return 1;

  int res=1;
  for(int i=0;i<6&&res;i++){
    int nx=x+dx[y%2][i],ny=y+dy[i];    
    res*=mark(ny,nx);
  }
  return res;
}

int main(){
  cin>>w>>h;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)cin>>mp[i][j];
  
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      memset(used,0,sizeof(used));
      if(!mp[i][j])mp[i][j]=mark(i,j);
    } 

  int ans=0;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      int cnt=6;
      if(!mp[i][j])continue;
      for(int k=0;k<6;k++){
	int nx=j+dx[i%2][k],ny=i+dy[k];
	if(nx<0||ny<0||nx>=w||ny>=h) continue;
	cnt-=mp[ny][nx];
      }
      ans+=cnt;
    }
  cout <<ans<<endl;
  return 0;
}

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

const int MAXN = 600;
const double INF = MAXN;
std::vector<int> edges[MAXN];
double e[MAXN];

double calc(int n, int block) {
  e[n - 1] = 0;
  for (int u = n - 2; u >= 0; --u) {
    double sum = 0.0, max = 0.0;
    for (const auto &v : edges[u]) {
      sum += e[v];
      if (e[v] > max) max = e[v];
    }
    double num = (int)edges[u].size();
    if (u == block && num > 1) {
      --num;
      sum -= max;
    }
    e[u] = sum / num + 1.0;
  }
  return e[0];
}

double solve(int n) {
  double res = INF;
  for (int i = 0; i < n - 1; ++i) {
    double cur = calc(n, i);
    if (cur < res) res = cur;
  }
  return res;
}

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0, u, v; i < m; ++i) {
    scanf("%d %d", &u, &v);
    edges[u - 1].emplace_back(v - 1);
  }
  printf("%.10lf\n", solve(n));
  return 0;
}


Measured memory_bytes: 1408
import sys

s = input()

num = len(s)

if s[-1] == "1" or s[0] == "0":
    print (-1)
    sys.exit()

s = s[:-1]

for i in range(num // 2):
    
    if s[i] != s[-1-i]:
        print (-1)
        sys.exit()

lis = []
ans = []

for i in range(num-1):

    if i != 0 and s[i] == "1":
        lis.append(i+1)

#print (lis)

now = 1
for i in range(len(lis)):

    while now < lis[i]:
        ans.append([now,lis[i]])
        now += 1

    if i != len(lis)-1:
        ans.append([lis[i],lis[i+1]])
        now += 1

ans.append([num-1,num])


for i in ans:
    print (i[0],i[1])


Measured memory_bytes: 58272
#include <iostream>

int main(int argc, char const* argv[])
{
	int h, w;
	do {
		std::cin >> h >> w;
		for (size_t i = 0; i < h; i++)
		{
			for (size_t j = 0; j < w; j++)
				std::cout << "#";
			std::cout <<  std::endl;
		}
        
		if(h != 0 && w != 0)
			std::cout <<  std::endl;
	} while(h != 0 && w != 0);

	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
using namespace std;
string s;
int N,K;
bool a[2<<17];
main()
{
	cin>>N>>K>>s;
	for(int i=0;i<N;i++)
	{
		a[i]=i+1<N&&s[i]==s[i+1]||i+1==N&&s[i]=='B';
	}
	int cnt=0,now=0;
	bool t=s[0]=='A',f=0;
	while(now<K&&cnt<N)
	{
		if(t)
		{
			t^=1;
			f=1;
		}
		else
		{
			t^=f^a[cnt++];
			f=0;
		}
		now++;
	}
	bool flag=0;
	for(int i=N;--i;)
	{
		s[i]=(s[i]=='A')^(flag^=a[i]^(i+cnt<N&&a[i+cnt]))?'A':'B';
	}
	s[0]=t^(cnt==N&&N%2==1&&(K-now)%2==1)?'A':'B';
	cout<<s<<endl;
}

Measured memory_bytes: 900
int main(void){
    int i,A=0,B=0,x,Num,go=0;
    char InputA[5000];
    char InputB[5000];
    
    scanf("%d",&Num);
    
    for(i=0;i<Num;i++){
        scanf("%s %s",InputA,InputB);
        x=0;
        go=0;
        while(InputA[x] != '\0' || InputB[x] != '\0'){
                if(InputA[x]<InputB[x]){
                    go=1;
                    B+=3;
                    break;
                }else if(InputA[x]>InputB[x]){
                    go=1;
                    A+=3;
                    break;
                }
            x++;
        }
        if(go==0){
            A++;
            B++;
        }
    }
    printf("%d %d\n",A,B);
}


Measured memory_bytes: 2092
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((size_t *)a) > *((size_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static size_t countDivisors(const size_t n)
{
	size_t count = 1;

	for (size_t i = 2; i <= n; i++) {
		if (n%i == 0) {
			count++;
		}
	}

	return count;
}

static size_t rowCount[100];
static size_t colCount[100];

int main(void) {
	size_t H, W;
	char aReal[100][101];
	char *a[100];

	for (size_t idx = 0; idx < 100; idx++) {
		a[idx] = aReal[idx];
	}

	scanf("%zu %zu\n", &H, &W);
	for (size_t idx = 0; idx < H; idx++) {
		rowCount[idx] = 0;
	}
	for (size_t idx = 0; idx < W; idx++) {
		colCount[idx] = 0;
	}
	for (size_t idx = 0; idx < H; idx++) {
		scanf("%s", a[idx]);
		if (idx < H - 1) {
			scanf("\n");
		}

		for (size_t col = 0; col < W; col++) {
			if (a[idx][col] == '.') {
				rowCount[idx]++;
				colCount[col]++;
			}
		}
	}

	size_t h = H;
	size_t w = W;
	
	for (size_t count = 0; count < 2 * MIN(H, W); count++) {
		if (count % 2 == 0) {
			for (size_t row = 0; row < h; row++) {
				if (rowCount[row] == w) {
					for (size_t mvIdx = row; mvIdx < h - 1; mvIdx++) {
						a[mvIdx] = a[mvIdx + 1];
						rowCount[mvIdx] = rowCount[mvIdx + 1];
					}
					for (size_t colIdx = 0; colIdx < w; colIdx++) {
						colCount[colIdx]--;
					}
					h--;
				}
			}
		}
		else {
			for (size_t col = 0; col < w; col++) {
				if (colCount[col] == h) {
					for (size_t rowIdx = 0; rowIdx < h; rowIdx++) {
						for (size_t mvIdx = col; mvIdx < w; mvIdx++) {
							a[rowIdx][mvIdx] = a[rowIdx][mvIdx + 1];
							if (rowIdx == 0 && mvIdx < w - 1) {
								colCount[mvIdx] = colCount[mvIdx + 1];
							}
						}
						rowCount[rowIdx]--;
					}
					w--;
				}
			}

		}
	}

	for (size_t idx = 0; idx < h; idx++) {
		puts(a[idx]);
	}

	return 0;
}


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

int main(void)
{
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n;i++){
        cin >> h.at(i);
    }
    //初めの花の高さをカウント
    int cnt = h.at(0);
    int temp_h = 0;
    for (int i = 0; i < n-1;i++){
        //番号の高さを記録
        temp_h = h.at(i);
        //もし次の番号の高さが今より高いときは加える
        if(temp_h < h.at(i+1)){
            cnt += h.at(i + 1) - temp_h;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


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




Measured memory_bytes: 3560
S = input()
T = input()
list_s = []
list_t = []
counter = 0
for i in range(0, len(S)):
  list_s.append(S[i])
  list_t.append(T[i])
  if S[i] != T[i]:
    list_s[i] = list_t[i]
    counter += 1
print(counter)

Measured memory_bytes: 12360
def main():
    S = list(input())
    k = int(input())
    ans = []
    for s in S:
        if s != 'a' and ord(s) >= 123 - k:
            ans.append('a')
            k -= 123 - ord(s)
        else:
            ans.append(s)
    if k > 0:
        ans[-1] = chr((ord(ans[-1]) + k - 97) % 26 + 97)
    print(''.join(ans))

if __name__ == '__main__':
    main()


Measured memory_bytes: 4920
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int n, ans = 0;
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		int num;
		cin >> num;
		if ((num & 1) == (i & 1) && (i & 1))
			ans ++;
	}
	cout << ans << '\n';
	return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

/* [💭] [💡] [🎈] */

int _a[1000], _b[1000], _c[1000], _d[1000], _e[1000], _f[1000];
vector<int> xs, ys;

int getidx_x(int x) {
    return lower_bound(xs.begin(), xs.end(), x) - xs.begin();
}

int getidx_y(int y) {
    return lower_bound(ys.begin(), ys.end(), y) - ys.begin();
}

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

bitset<7000> bo[7000], vis[7000];

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

    int n, m;
    cin >> n >> m;

    xs.emplace_back(-1.5e9);
    ys.emplace_back(-1.5e9);

    xs.emplace_back(0);
    ys.emplace_back(0);
    for (int i = 0; i < n; i++) {
        cin >> _a[i] >> _b[i] >> _c[i];
        xs.emplace_back(_a[i]), xs.emplace_back(_b[i]), ys.emplace_back(_c[i]);
    }
    for (int i = 0; i < m; i++) {
        cin >> _d[i] >> _e[i] >> _f[i];
        xs.emplace_back(_d[i]), ys.emplace_back(_e[i]), ys.emplace_back(_f[i]);
    }
    sort(xs.begin(), xs.end()), sort(ys.begin(), ys.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end()), ys.erase(unique(ys.begin(), ys.end()), ys.end());

    for (int i = 0; i < n; i++) {
        int az = getidx_x(_a[i]), bz = getidx_x(_b[i]), cz = getidx_y(_c[i]);
        for (int j = az * 2 - 1; j < bz * 2; j++) bo[j][cz * 2 - 1] = true;
    }
    for (int i = 0; i < m; i++) {
        int dz = getidx_x(_d[i]), ez = getidx_y(_e[i]), fz = getidx_y(_f[i]);
        for (int j = ez * 2 - 1; j < fz * 2; j++) bo[dz * 2 - 1][j] = true;
    }

    int s = getidx_x(0) * 2 - 1, e = getidx_y(0) * 2 - 1;

    bool inf = false;

    ll sum = 0;
    queue<pii> q;
    vis[s][e] = true;
    q.emplace(s, e);
    while (q.size()) {
        int x = q.front().first, y = q.front().second;
        if (x == 6999 || y == 6999 || !x || !y) {
            inf = true;
            break;
        }
        q.pop();
        if (!(x % 2) && !(y % 2)) {
            int i = x / 2, j = y / 2;
            sum += (ll)(xs[i + 1] - xs[i]) * (ys[j + 1] - ys[j]);
        }
        for (int d = 0; d < 4; d++) {
            int nx = x + dx[d];
            int ny = y + dy[d];
            if (7000 <= nx || nx < 0) continue;
            if (7000 <= ny || ny < 0) continue;
            if (vis[nx][ny]) continue;
            if (bo[nx][ny]) continue;
            vis[nx][ny] = true;
            q.emplace(nx, ny);
        }
    }

    if (!inf) {
        cout << sum;
    } else {
        cout << "INF";
    }

    return 0;
}

/*
 *
2 2
-1 1 -1
-1 1 1
-1 -1 1
1 -1 1
 */

Measured memory_bytes: 14876
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;
int main()
{
	long long N;
	cin >> N;
	long long sum = 0;
	long long num1, num2;
	for (long long i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			num1 = N / i - 1;
			num2 = i - 1;
			if (num1 != 0 && (N / num1 == N % num1)) {
				sum += num1;
			}
			if (num2 != 0 && (N / num2 == N % num2)) {
				sum += num2;
				if (num1 == num2) {
					sum -= num2;
				}
			}
		}
	}
	cout << sum << endl;
}

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

vector<int> v1,v2;

int main() {
	int n;
	cin >> n;
	if (n==3) {
		cout << "2 5 63\n";
		return 0;
	}
	for (int i = 2; i <= 30000; i++) {
		if (i % 2 == 0) {
			v1.push_back(i);
			n--;	
		}
		else if (i % 3 == 0) {
			v2.push_back(i);
			n--;
		}
		if (n == 0) break;
	}
	int n1 = v1.size(), n2 = v2.size();
	if (n2%2 != 0) {
		n1--;
		v2.push_back(v2[n2-1]+6);
		n2++;
	}
	if (n1 % 3 == 1) v1[n1-1] += 4;
	for (int i = 0; i < n1; i++) cout << v1[i] << " ";
	for (int i = 0; i < n2; i++) cout << v2[i] << " ";
	cout << "\n";
}

Measured memory_bytes: 512
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <queue>
#include <vector>

using namespace std;

int main() {
  int i = 0, x, s[10];
  while (scanf("%d", &x) == 1)
    if (!x)
      printf("%d\n", s[--i]);
    else
      s[i++] = x;
  return 0;
}

Measured memory_bytes: 0
import sys
x = input()
d = {}
dist = {}
for i in range(1, x+1):
    d[i] = []
    dist[i] = 0
for i in range(x-1):
    num1, num2, num3 = map(int, sys.stdin.readline().split())
    d[num1].append((num2, num3))
    d[num2].append((num1, num3))

q, k = map(int, raw_input().split())
vis = set()
vis.add(k)
current = [k]
newnode = []
while True:
    for i in range(len(current)):
        for j in range(len(d[current[i]])):
            if d[current[i]][j][0] not in vis:
                dist[d[current[i]][j][0]] = dist[current[i]]+d[current[i]][j][1]
                vis.add(d[current[i]][j][0])
                newnode.append(d[current[i]][j][0])
    if len(newnode) == 0:
        break
    current = []
    current = newnode
    newnode = []

for i in range(q):
    num1, num2 = map(int, sys.stdin.readline().split())
    hold = 0
    hold1 =0
    print dist[num1] + dist[num2]

Measured memory_bytes: 62300
while line=gets
  (n,x)=line.split().map(&:to_i)
  break if n==0 && x==0
  c=0
  (1..n-2).each do |n1|
    (n1+1..n-1).each do |n2|
      (n2+1..n).each do |n3|
        c+=1 if n1+n2+n3 == x
      end
    end
  end
  puts c
end

Measured memory_bytes: 6104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n, x, y, sum=0;
    cin>>n>>x;
    for(int i = 0; i < x; i++)
    {
        cin>>y;
        sum+=y;
    }
    if(n>sum) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    // int ans = ceil(1.0*n/(1.0*x));
    // cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A,B,C,K;
  cin >> A >> B >> C >> K;
  if (K <= A + B){
    cout << min(K,A);
  }
  else {
    cout << A - (K - A - B);
  }
}


Measured memory_bytes: 3636
resd = {}
def A(h):
    if h == 1:
        return 1
    else:
        if h in resd:
            return resd[h]
        else:
            resd[int(h/2)] = A(int(h/2))*2+1
            return resd[int(h/2)]

H = int(input().strip())
print(A(H))

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

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n,q;
  cin >> n >> q;
  vector<int> count(n+1,0);
  string s;
  cin >> s;
  // cout << 0 SP 0 << " ";
  for(int i=2;i<=n;i++){
    count[i]=count[i-1];
    if(s[i-1]=='C'&&s[i-2]=='A') count[i]++;
    // cout << count[i] << " ";
  }
  // cout << endl;
  int l,r;
  for(int i=0;i<q;i++){
    cin >> l >> r;
    cout << count[r]-count[l] << endl;
  }
  return 0;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<int,int>;

int main()
{
   ll ans=0;
   ll n,k;cin >>n >>k;
   for(int i=k;i<=n+1;i++){
    ans+=(2*n-2*i+2)*i/2;
    ans++;
    ans%=mod;
   }
   cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
    ld n;
    cin>>n;
    int x = n;
    n*=100;
    n/=108;
    n=ceil(n);
    ld cpy = n*1.08;
    cpy=(int)cpy;
    if(cpy==x)cout<<n;
    else cout<<":(";
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 3804
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct aaa{
	int x,y;
}a[500010];
int h,w,n,mx,i,mn[500010];
int main(){
	scanf("%d%d%d",&h,&w,&n);
	for(i=1;i<=h;i++)mn[i]=w+1;
	for(i=1;i<=n;i++){
		scanf("%d%d",&a[i].x,&a[i].y);
		mn[a[i].x]=min(mn[a[i].x],a[i].y);
		//mp[a[i].x][a[i].y]=1;
	}
	mx=1;
	for(i=1;i<h;i++){
		if(mn[i+1]<=mx){
			printf("%d\n",i);return 0;
		}
		if(mn[i+1]>mx+1)mx++;
	}
	printf("%d",h);
}

Measured memory_bytes: 6112
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N,Q; string S; cin>>N>>S>>Q;
  vi M(N+1),C(N+1),dp(N+1);
  rep(i,0,N){
    M[i+1]=M[i];
    if(S[i]=='M') M[i+1]++;
  }
  rep(i,0,N){
    C[i+1]=C[i];
    dp[i+1]=dp[i];
    if(S[i]=='C'){
      dp[i+1]+=M[i+1];
      C[i+1]++;
    }
  }
  rep(_,0,Q){
    int ans=0;
    int X; cin>>X;
    rep(i,0,N){
      if(S[i]=='D'){
        ans+=dp[min(N,i+X)]-dp[i+1]-M[i+1]*(C[min(N,i+X)]-C[i+1]);
      }
    }
    cout<<ans<<endl;
  }
  }



Measured memory_bytes: 24836
import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;

enum int INF = 1 << 28;

alias Node = Tuple!(int, "value", int, "index");
bool comp(Node a, Node b) {
	if (a.value != b.value) {
		return a.value < b.value;
	}
	return a.index < b.index;
}

void main() {
	int n = readln.chomp.to!int;
	auto a = readln.chomp.split.map!(to!int).array;
	Node[] arr = new Node[](n);
	foreach (int i, v; a) {
		arr[i] = Node(v, i);
	}
	std.algorithm.sort!comp(arr);
	debug arr.writeln;
	Node atom = arr[$ - 1];
	auto sorted = arr.assumeSorted!comp;
	int half = (atom.value + 1) / 2;
	auto left = sorted.lowerBound(Node(half + 1, -INF));
	debug left.writeln;
	int best = int.max;
	int ans = -1;
	if (left.length) {
		int v = half - left.back.value;
		if (v < best) {
			best = v;
			ans = left.back.value;
		}
	}
	auto right = sorted.upperBound(Node(half - 1, +INF));
	debug right.writeln;
	if (right.length) {
		int v = right.front.value - half;
		if (v < best) {
			best = v;
			ans = right.front.value;
		}
	}
	writeln(atom.value, " ", ans);
}



Measured memory_bytes: 4416
N , M = (map(int , input().split()))
sc = [list(map(int, input().split())) for i in range(N)]
sorted_cs = sorted(sc,key = lambda x:x[0])
sorted_cs
ans = 0
cnt = 0
for i in range(N):
    for j in range(sorted_cs[i][1]):
        ans += sorted_cs[i][0]
        cnt += 1
        if cnt >= M:
            break
    if cnt >= M:
        break
print(ans)

Measured memory_bytes: 29796
import itertools
d,g=map(int,input().split())
p=[]
c=[]
for i in range(d):
    p1,c1=map(int,input().split())
    p.append(p1)
    c.append(c1//100)
n=list(itertools.permutations(list(range(1,d+1))))
ans=1024
g//=100
for i in range(len(n)):
    cnt=g
    cnt2=0
    for j in range(d):
        num3=n[i][j]
        num4=num3*p[num3-1]
        if num4>=cnt:
            cnt2+=((cnt-1)//num3)+1
            break
        elif num4+c[num3-1]>=cnt:
            cnt2+=p[num3-1]
            break
        else:
            cnt-=num4+c[num3-1]
            cnt2+=p[num3-1]
    ans=min(ans,cnt2)
print(ans)


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

int main(){
    int N, Y;
    int man, gosen, sen;
    int gs, total;

    cin >> N >> Y;

    for(man=0; man<=N; man++){
        gs = N - man;
        for(gosen=0; gosen<=gs; gosen++){
            sen = gs - gosen;
            total = 10000*man + 5000*gosen + 1000*sen;
            if(total == Y){
                cout << man << " " << gosen << " " << sen << endl;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


#[allow(dead_code)]
fn solve(n: u32, k: u32) -> u32 {
    k * (k-1).pow(n -1)
}

fn main() {
    input! {
    n: u32,
    k: u32,
    };

    println!("{}", solve(n, k));
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
const int M=100010;
const int MOD=1000000007;
const int INF=1000000007;
using ll=long long;

int main() {	
	int N,H,a[M],b[M],ans=0;
	ll damage=0;
	cin>>N>>H;
	rep(i,0,N)cin>>a[i]>>b[i];
	sort(a,a+N,greater<int>());
	sort(b,b+N,greater<int>());
	rep(i,0,N){
		if(a[0]<b[i])damage+=b[i],ans++;
		if(damage>=H){
			cout<<ans<<endl;
			return 0;
		}
	}
	while(damage<H){
		ans++;
		damage+=a[0];
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1024