akhauriyash/Code-Regression huggingface dataset:
var input = require('fs').readFileSync('/dev/stdin', 'utf8').split("\n").map(Number);
var part = [];
input.some(function(x) {
  if (x == 0) return true;
  part.push(x);
});
console.log(part.map(function(x, i) {
  return x == 0 ? '' : 'Case ' + (i + 1) + ': ' + x;
}).join('\n'));

Measured memory_bytes: 19488
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    rep(i,N) A[i]-=ll(i+1);
    sort(all(A));
    
    ll mid = A[N/2];
    
    ll ans = 1000000000000000;
    
    ll a = 0;
    rep(i,N){
        a += abs(A[i]-mid);
    }
    ans = min(a, ans);
    
    a = 0;
    rep(i,N){
        a += abs(A[i]-mid-1);
    }
    ans = min(a, ans);
    
    
    
    cout << ans << endl;
    
    
    return 0;
}



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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long

int main(void)
{
    ll n; cin>>n;
    ll a,b,c;
    a=n/500,b=n%500,c=b/5;
    cout<<1000*a+5*c<<endl;
    return 0;
}

Measured memory_bytes: 256
S = input()
for i in range(1,len(S)):
    S_short = S[0:-i]
    if len(S_short)%2!=0:
        continue
    else:
        half = len(S_short)//2
        if S_short[0:half]==S_short[half:]:
            break
        else:
            continue
print(len(S)-i)  

Measured memory_bytes: 8984
import heapq

n = int(input())
a = list(map(int, input().split()))

a1 = a[:n]
a2 = a[n:2*n]
a3 = [-x for x in a[2*n:]]

suma1 = [sum(a1)]
suma3 = [-sum(a3)]

heapq.heapify(a1)
heapq.heapify(a3)

for i in range(n):
    heapq.heappush(a1,a[n+i])
    heapq.heappush(a3,-a[2*n-1-i])
    suma1.append(suma1[-1]+a[n+i]-heapq.heappop(a1))
    suma3.append(suma3[-1]+a[2*n-1-i]+heapq.heappop(a3))

ans = suma1[0]-suma3[-1]
for i in range(n):
    ans = max(ans, suma1[i+1]-suma3[-2-i])
print(ans)


Measured memory_bytes: 120360
class node(object):
    def __init__(self):
        self.left = None
        self.right = None
        self.value = None
        self.parent = None

class Tree(object):
    def __init__(self):
        self.root = None

def insert(T,z):
    y = None
    x = T.root
    while x != None:
        y = x
        if z.value < x.value:
            x = x.left
        else:
            x = x.right
    
    z.parent = y
    if y == None:
        T.root = z
    elif z.value < y.value:
        y.left = z
    else :
        y.right = z

# 先行順巡回
def preorder(node):
    if node is None:
        return 
    print(" "+str(node.value),end="")    
    preorder(node.left)
    preorder(node.right)
    
# 中間順巡回 
def inorder(node):
    if node is None:
        return 
    inorder(node.left)
    print(" "+str(node.value),end="")
    inorder(node.right)
    
def print_all_node(root):
    stack = [root]
    while stack:
        node = stack.pop()
        print("p: ",node.parent,"r:",node.right,"l:",node.left)
        if node.left:
            stack.append(node.left)
        if node.right:
            stack.append(node.right)

if __name__ == "__main__":
    n = int(input())
    T = Tree()
    queries = [input().split() for _ in range(n)]
    for query in queries:
        if query[0] == "print":
            #print_all_node(T.root)
            inorder(T.root)
            print("")
            preorder(T.root)
            print("")

        else:
            command,value = query
            node_z = node()
            node_z.value = int(value)
            if command == "insert":
                insert(T,node_z)



Measured memory_bytes: 244076
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h, w, n, m,k; string s; string sp;
char maze[60][60];
int dis[60][60];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

int main() {
	cin >> n; ll res = 0;
	if (n % 2 == 0) {
		res = n;
	}
	else {
		res = 2 * n;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.shift().split(' ').map(Number);
  buildMaxHeap(arr, n);
  console.log(arr.reduce((s, e) => s += ` ${e}`, ''));
})();

function buildMaxHeap(arr, n) {
  const maxHeapify = (i) => {
    let left, right, largest;
    left = 2 * i + 1;
    right = 2 * i + 2;
    largest = left < n && arr[left] > arr[i] ? left : i;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(n / 2); i > -1; i--) maxHeapify(i);
}



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

int main(){
    long long a,b;
    cin>>a;
    vector<int>v(a);
    vector<int>v1(a,1e9);
    cin>>b;
    for(int i=0;i<a;i++){
        cin>>v[i];
    }
    v1[0]=0;
    for(int i=0;i<a;i++){
        for(int j=1;j<=b;j++){  
          if(i+j<a) v1[i+j]=min(v1[i+j],v1[i]+abs(v[i+j]-v[i]));
        }
    }
    cout<<v1[a-1];

}

Measured memory_bytes: 1024
import math;

def swap(a,b):
    return (b,a)

def gcd(a,b):
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def main():
    n,d = map(int,input().split())
    x = []
    for i in range(n):
        x.append([y for y in map(int,input().split())])
    ans = 0
    for i in range(n):
        for j in range(n):
            if i>=j:
                continue
            res = 0
            for k in range(d):
                res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k])
            res = math.sqrt(res)
            res1 = int(res)
            if res1==res:
                ans += 1
    print(ans)
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include<math.h>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)


int main() {
  int N;
  cin>>N; 
  vector<int> l(N),r(N);  
  rep(i,N){
    cin>>l.at(i)>>r.at(i);
  }
  vector<bool>a(100001,true);
  vector<int>p(100001);
  int pr=0;
  a.at(0)=false;
  a.at(1)=false;
  rep2(i,2,100001){
    if(a.at(i)){
      for(int j=i*2;j<100001;j+=i){
        a.at(j)=false;
      }
    }
  }
  
  for(int i=99999;i>=3;i-=2){
    if(a.at(i)){
      if(!a.at((i+1)/2)){
        a.at(i)=false;
      }
    }
  }
  
  rep2(i,3,100001){
    if(a.at(i)){
      pr++;
    }
    p.at(i)=pr;
  }
  
  rep(i,N){
    cout << p.at(r.at(i))-p.at(l.at(i)-1)<< endl;
  }
  
}

Measured memory_bytes: 1792
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ld long double
#define ll long long
#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int ans[101];
int32_t main(){
	boost;
	int n;
	cin>>n;
	v vec(n-1);
	memset(ans,-1,sizeof ans);
	for(auto& it:vec)cin>>it;
	for (int i = 0; i < n-1; ++i)
	{
		ans[i+1]=vec[i];
		if(ans[i]==-1)ans[i]=vec[i];
		else if(ans[i]>vec[i])ans[i]=vec[i];
	}
	ll sum=0;
	for (int i = 0; i < n; ++i)
		sum+=ans[i];
	cout<<sum;
	return 0;
}
//long long
//array bounds
//special cases
//binary search

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int gcd2(int a, int b){
    if(b == 0)
       return a;

    return gcd2(b, a%b);
}

int gcd3(int a, int b, int c){
    return gcd2(gcd2(a, b), c);
}

int main(void){
    int k, ii1, ii2, ii3, sum;
    sum=0;
    scanf("%d", &k);
    for(ii1=1; ii1<=k; ii1++){
        for(ii2=1; ii2<=k; ii2++){
            for(ii3=1; ii3<=k; ii3++){
                sum += gcd3(ii1, ii2, ii3);
            }
        }
    }

    printf("%d\n", sum);
}


Measured memory_bytes: 1736
#include <stdio.h>

int main(){
    int n, m, l, i, j, k;
    int A[100][100], B[100][100];
    long C[100][100] = {0};
    scanf("%d%d%d", &n, &m, &l);
    for(i=0; i<n; i++) for(j=0; j<m; j++) scanf("%d", &A[i][j]);
    for(i=0; i<m; i++) for(j=0; j<l; j++) scanf("%d", &B[i][j]);
    for(i=0; i<n; i++) for(j=0; j<l; j++) for(k=0; k<m; k++) C[i][j] += A[i][k] * B[k][j];
    for(i=0; i<n; i++){
        for(j=0; j<l-1; j++) printf("%ld ", C[i][j]);
        printf("%ld\n", C[i][j]);
    }
    return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
int num[1000010];
int book[1000010];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		scanf("%d",&num[i]);
		book[num[i]]++;
	}
	int tmp=0;
	int res=0;
	if(n==1) cout<<1<<endl;
	else{
		for(int i=1;i<1000010;i++){
			tmp=book[i]+book[i-1]+book[i+1];
			if(tmp>res) res=tmp;
		}
		cout<<res<<endl;
	}
}

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

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

const int INF = 10000000;
const int MAX_V = 10;
int d[MAX_V][MAX_V];
int E;

void init() {
    REP(i, MAX_V) {
        REP(j, MAX_V) {
            if (i == j) d[i][j] = 0;
            else        d[i][j] = INF;
        }
    }
}

void make() {
    REP(i, E) {
        int u, v, c;
        cin >> u >> v >> c;
        d[u][v] = c; d[v][u] = c;
    }
}

void wf() {
    REP(k, MAX_V) {
        REP(i, MAX_V) {
            REP(j, MAX_V) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

void answer() {
    int town = 0, min_sum = INF;

    REP(i, MAX_V) {
        int row_sum = 0;
        REP(j, MAX_V) {
            if (d[i][j] < INF)
                row_sum += d[i][j];
        }

        //row_sum > 0 means i is not isolate
        if (row_sum > 0 && row_sum < min_sum) {
            min_sum = row_sum;
            town = i;
        }
    }

    cout << town << ' ' << min_sum << endl;
}

void solve() {
    while (true) {

        cin >> E;

        if (E == 0) break;

        init();

        make();

        wf();

        answer();
    }
}


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

Measured memory_bytes: 1160
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		String reString = "No";
		
		
		if(a <= b) {
			if(a < c && c < b) {
				reString = "Yes";
			}
		} else {
			if(b < c && c < a) {
				reString = "Yes";
			}
		}
		System.out.println(reString);
	}
}

Measured memory_bytes: 22356
#include <stdio.h>

int main(void){

  long n;
  scanf("%ld", &n);
	long h[n];
	for (long i = 0; i < n; i++) {
		scanf("%ld", &h[i]);
	}

	int flag = 1;
	for (long i = n-1; i > 0; i--) {
		if (h[i-1] > h[i]+1) {
			flag = 0;
			break;
		}
		if (h[i-1] == h[i]+1) {
			h[i-1] = h[i];
		}
	}

	if (flag == 1) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}

  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <ctype.h>
#include <iomanip>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <array>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <array>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
// #include <pair> 
       
using namespace std;
typedef pair<long long int, long long int> ii;
typedef vector<long long int> vi;
typedef vector<ii> vii;
#define INF 100000000
       
#define endl '\n'
#define MOD 1000000007
// #define INF 1ll<<30
// #define MAX 100010
 
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES
 
// long long binpow(long long a,long long b)
// {
//     if (b == 1) return a;
//     long long res = binpow(a, b/2)%MOD;
//     if (b % 2) return (res*((res*a)%MOD))%MOD;
//     else return (res * res)%MOD;
// }
 
// long fact(long a)
// {
//     if(a<=1)
//         return 1;
//     long ans = 1;
//     for(long i=a;i>=1;i--)
//         ans = (ans * i);
//     return ans;
// }
 
// long long int ivmod(long long int a)
// {
//     return binpow(a,MOD-2);
// }
 
// long double ncr(long double a,long double b)
// {
//     long double  pans=1;
//     for(long double i =a;i>max(b,a-b);i--)
//         pans=pans*i;
//     long double div = fact(min(b,a-b));
//     pans = pans/div;
//     return pans;
// }

int n;
long long int solved[506][506];
long long int solve(int rem,int lastsize)
{
    long long int ans = 0;
    if(rem==0)
        return 1;
    else if(rem<=lastsize)
        return 0;
    if(solved[rem][lastsize]!=-1)
        return solved[rem][lastsize];
    else
    {
        for(int i=lastsize+1;i<=rem;i++)
        {
            ans+=solve(rem-i,i);
        }
        return solved[rem][lastsize] = ans;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(1);
    cout<<fixed;

#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif
    int n;
    cin>>n;
    map<int,int> m;
    for(int i=0;i<n;i++)
    {
        int temp;
        cin>>temp;
        m[temp]++;
    }
    int mp;
    cin>>mp;
    for(int i=0;i<mp;i++)
    {
        int temp;
        cin>>temp;
        if(m[temp]>0)
        {
            m[temp]--;
        }
        else
        {
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
#ifndef ONLINE_JUDGE
   cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif

    return 0;
}   


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

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

const ll INF = (ll)1e11;

using namespace std;

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

    int A, B, C;
    cin >> A >> B >> C;
    
    cout << min({A+B, B+C, A+C}) << endl;

    return 0;
}


Measured memory_bytes: 256
//dont try to understand my code i really dont understand it 
#include<iostream>
#include<fstream>
#include<cmath>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<vector>
#include <queue>
#include <stack>
#include<algorithm>
#include<memory.h>
using namespace std;
typedef long long ll;
#define f( i , x , n ) for(int i = x; i < (int)(n); ++i)
#define pb push_back
#define mp make_pair
#define mt make_tuple
typedef pair<int, int> ii;
const double PI = acos(-1.0);
//const int oo = 10e9;
//const ll F = LLONG_MIN;	
const int A = 300002;
typedef long long ll;
// write what you need here : ...

int main() {
	ll b1 = 100e9, b2 = 100e9;
	ll a, b, c, d;
	scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
	
	b2 = min(c * 2, min(d, min(b * 4, a * 8)));

	b1 = min(c, min(b * 2, a * 4));
	//cout << b2 << " " << b1 << endl;
	ll need;
	scanf("%lld", &need);

	if (need % 2 == 0)
		cout << b2 * need / 2;
	else
		cout << (b2 * (need / 2)) + b1;

	return 0;
}	

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

using namespace std;

using int64 = long long;

int main() {
  int N, M;
  cin >> N >> M;
  vector< int > div;
  for(int i = 1; i * i <= M; i++) {
    if(M % i == 0) {
      div.emplace_back(i);
      div.emplace_back(M / i);
    }
  }
  int ret = 0;
  for(auto &p : div) {
    if(1LL * p * N <= M && (M - p * N) % p == 0) ret = max(ret, p);
  }
  cout << ret << endl;
}


Measured memory_bytes: 256
N,A = map(int,input().split())
x2 = list(map(int,input().split()))
x = [i-A for i in x2]
maxx = max(max(x2),A)
dp = [[0 for i in range(2*N*maxx+1)] for j in range(N+1)]
start = N*maxx
dp[0][start] = 1
for i in range(1,N+1):
    for j in range(2*start+1):
        if 2*start >= j - x[i-1] >= 0:
            dp[i][j] = dp[i-1][j-x[i-1]] + dp[i-1][j]
        else:
            dp[i][j] = dp[i-1][j]
print(dp[-1][start]-1)

Measured memory_bytes: 5744
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int mem[9];
bool FNS(){
	for(int i=0;i<9;i++){
		int t[9];
		for(int j=0;j<9;j++)t[j]=mem[j];
		if(t[i]>=2){
			t[i]-=2;
			bool ok=true;
			for(int j=0;j<4;j++){
				int p=0;while(!t[p])p++;
				bool done=false;
				if(!done&&t[p]>=3)t[p]-=3,done=1;
				if(!done&&p<7)if(t[p+1]&&t[p+2])t[p]--,t[p+1]--,t[p+2]--,done=1;
				if(!done){ok=false;break;}
			}
			if(ok)return true;
		}
	}
	return false;
}

int main(){
	string s;
	while(cin>>s){
		for(int i=0;i<9;i++)mem[i]=0;
		for(int i=0;i<s.size();i++)mem[s[i]-'1']++;
		bool done=false;
		for(int i=0;i<9;i++){
			mem[i]++;
			if(mem[i]<5)if(FNS()){
				if(done)cout<<" ";
				cout<<i+1;done=true;
			}
			mem[i]--;
		}
		if(!done)cout<<0;cout<<endl;
	}
	return 0;	
}

Measured memory_bytes: 3076
#include <stdio.h>

long func(long n, long x){
	if(n >= 0)
		return n / x + 1;
	else
		return 0;
}

int main(void) {
	long a, b, x;

	scanf("%ld%ld%ld", &a, &b, &x);

	printf("%ld", func(b, x)-func(a-1, x));

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()

using namespace std;
main(){
    while(1){
        ll n;cin>>n;
        if(!n)break;
        vector<ll> a(n);
        rep(i,n)cin>>a[i];
        ll sum = accumulate(all(a),0LL);
        int cnt = 0;
        rep(i,n){
            cnt += (a[i]*n <= sum);
        }
        cout << cnt <<endl;
    }
}




Measured memory_bytes: 3204
#include <stdio.h>
int z[9999],r[9999];
int f(int a,int b){
	printf("? %d %d\n",a,b);
	fflush(stdout);
	char c[2];
	scanf("%s",c);
	return *c=='Y';
}
int main(){
	int a,b,c=0,q,h;
	scanf("%d%d",&a,&b);
	if(a<=b){puts("Impossible");return 0;}
	q=b+1;
	for(int i=0;i<a+b;i++){
		if(!c||f(z[c-1],i)){
			z[c++]=i;
			if(c>=q)break;
		}else{
			c--;
			q--;
		}
	}
	h=z[c-1];
	for(int i=0;i<a+b;i++){
		r[i]=h==i||f(h,i);
	}
	printf("! ");
	for(int i=0;i<a+b;i++)printf("%d",r[i]);
	puts("");
}

Measured memory_bytes: 720
n,m=map(int,input().split())
s=input()
t=input()
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def lcm(a, b):
    return a * b // gcd (a, b)
if gcd(n,m)==1:
    if s[0]==t[0]:
        print(lcm(n,m))
    else:
        print(-1)
else:
    a,b=n//gcd(n,m),m//gcd(n,m)
    x=[]
    y=[]
    for i in range(0,n,a):
        x.append(s[i])
    for i in range(0,m,b):
        y.append(t[i])
    if x==y:
        print(lcm(n,m))
    else:
        print(-1)

Measured memory_bytes: 3700
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <map>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
	#define debug printf
#else
	#define debug(...)
#endif
bool is_prime(int n)//O(sqrt n)
{
	if(n < 2)
	{
		return 0;
	}
	if(n == 2)
	{
		return 1;
	}
	for(int i = 2;i * i <= n; ++i)
	{
		if(n % i == 0)
		{
			return 0;
		}
	}
	return 1;
}
int n;
int check(int c)
{
	int k = n / c;
	int ans = k;
	while(k)
	{
		k /= c;
		ans += k;
	}
	return ans;
}
vector< pair<int,int> > v;
int main(int argc, char const *argv[])
{
	cin>>n;
	for(int i = 1;i <= n; ++i)
	{
		if(is_prime(i))
		{
			v.push_back({i,check(i)});
		}
	}
	int s = v.size();
	int ans = 0;
	//a^2*b^4*c^4
	for(int i = 0;i < s; ++i)
	{
		for(int j = 0;j < s; ++j)
		{
			for(int k = j + 1;k < s; ++k)
			{
				if(i == j || j == k || i == k)
				{
					continue;
				}
				if(v[i].second > 1 && v[j].second > 3 && v[k].second > 3)
				{
					ans++;
				}
			}
		}
	}

	//a^2*b^24
	for(int i = 0;i < s; ++i)
	{
		for(int j = 0;j < s; ++j)
		{
			if(i == j)
			{
				continue;
			}
			if(v[i].second > 1 && v[j].second > 23)
			{
				ans++;
			}
		}
	}

	//a^4*b^14
	for(int i = 0;i < s; ++i)
	{
		for(int j = 0;j < s; ++j)
		{
			if(i == j)
			{
				continue;
			}
			if(v[i].second > 3 && v[j].second > 13)
			{
				ans++;
			}
		}
	}

	//a^74
	for(int i = 0;i < s; ++i)
	{
		if(v[i].second > 73)
		{
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
long long a[200005],ans=1000000000000000000;
long long x,y;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		y+=a[i];
	}
	for(int i=0;i<n-1;i++){
		x+=a[i];
		y-=a[i];
		ans=min(ans,abs(y-x));
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm> 
#include <cmath> //pow

#define rep(i,n)  for(int (i) = 0; (i) < (n); (i)++)
#define rep1(i,n) for(int (i) = 1; (i) <= (n); (i)++)

using namespace std;

int main(void) {
	int n, c;
	cin >> n >> c;

	vector<vector<int>> d(c,vector<int>(c,0));
	rep(i, c) rep(j,c) {
		cin >> d[i][j];
	}

	vector<vector<int>> field(n,vector<int>(n,0));
	rep(i, n) rep(j,n) {
		cin >> field[i][j];
		field[i][j]--;
	}

	vector<long long int> mod0(3,n*n*1000); 
	vector<int> mod0c(3,31);
	vector<long long int> mod1(3,n*n*1000);
	vector<int> mod1c(3,31);
	vector<long long int> mod2(3,n*n*1000);
	vector<int> mod2c(3,31);

	rep (col, c) {
		int cost0 = 0, cost1 = 0, cost2 = 0;

	  rep(i, n) rep(j, n) {
			switch ((i + j) % 3) {
			case 0: cost0 += d[field[i][j]][col]; break;
			case 1: cost1 += d[field[i][j]][col]; break;
			case 2: cost2 += d[field[i][j]][col]; break;
			}
		}
		
		rep(i, 3) if (cost0 < mod0[i]) { 
			for (int j = 1; j >= i; j--) {
				mod0[j + 1] = mod0[j];
				mod0c[j + 1] = mod0c[j];
			}
			mod0[i] = cost0;
			mod0c[i] = col;
			break;
		}

		rep(i, 3) if (cost1 < mod1[i]) {
			for (int j = 1; j >= i; j--) {
				mod1[j + 1] = mod1[j];
				mod1c[j + 1] = mod1c[j];
			}
			mod1[i] = cost1;
			mod1c[i] = col;
			break;
		}

		rep(i, 3) if (cost2 < mod2[i]) {
			for (int j = 1; j >= i; j--) {
				mod2[j + 1] = mod2[j];
				mod2c[j + 1] = mod2c[j];
			}
			mod2[i] = cost2;
			mod2c[i] = col;
			break;
		}
  }

	long long int ans = n*n*1000;
	rep(i0, 3) rep(i1, 3) rep(i2, 3) {
		if (mod0c[i0] == mod1c[i1] || mod1c[i1] == mod2c[i2] || mod0c[i0] == mod2c[i2]) continue;

		ans = min(ans, mod0[i0] + mod1[i1] + mod2[i2]);
	}

  cout << ans << endl;
}


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

int main()
{
    int n;
    cin >> n;
    map<int, int> mp;
    for (int i = 1; i <= n; i++)
    {
        mp.insert({i, 0});
    }
    for (int i = 0; i < n-1; i++)
    {
        int a;
        cin >> a;
        mp[a]++;
    }
    for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++)
    {
        cout << it -> second << "\n";
    }
    return 0;
}


Measured memory_bytes: 12984
#include <stdio.h>
int main() 
{
    int n,rem=0,m=0;
    scanf("%d",&n);
    m=n;
    while(n!=0)
    {
        rem=rem+ n%10;
        n=n/10;
    }
    if(m%rem==0)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
	return 0;
}

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

int main(){
  long long int h,w;
  cin >> h >> w;
  if(h==1||w==1){
    cout << 1 << endl;
  }else if(h*w%2==0){
    cout << h*w/2 << endl;
  }else{
    cout << (h*w/2)+1 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> d(N);
    for (int i = 0; i < N; i++) cin >> d[i];
    int ans = 0;
    for (int i = 0; i < N - 1; i++){
        for (int j = i + 1; j < N; j++){
            ans += d[i] * d[j];
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3520
#include<bits/stdc++.h>
using namespace std;
long long n[50050],f[100050],zs,a,lefts,rights;
bool b[100050];
int main()
{
	b[0]=1,b[1]=1;
	for(int s=2;s<=100005;s++)
	{
		if(!b[s])
		{
			n[zs++]=s;
		}
		for(int v=0;v<zs;v++)
		{
			if(s*n[v]>100005)break;
			b[n[v]*s]=true;
			if(s%n[v]==0)break;
		}
	}
	cin>>a;
	for(int s=2;s<=100005;s++)
	{
		if(s%2==1&&b[s]==0&&b[(s+1)/2]==0)
		f[s]=1;
		f[s]+=f[s-1];
	}
	while(a--)
	{
		cin>>lefts>>rights;
		cout<<f[rights]-f[lefts-1]<<endl;
	}
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define fi first
#define se second
const int maxn=1e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
priority_queue<int> q;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		q.push(x);
	}
	while(m--)
	{
		int now=q.top();
		q.pop();
		q.push(now/2);
	}
	ll ans=0;
	while(!q.empty()) 
	{
		int now=q.top();
		ans+=now;
		q.pop();
	}
	cout<<ans<<'\n';
	return 0;
}


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

int main (void) {
    int N;
    cin >> N;
    vector<P> coord(N);
    rep(i, N) cin >> coord.at(i).first >> coord.at(i).second;
    
    vector<int> order(N);
    rep(i, N) order.at(i) = i;
    
    double sum = 0;
    int cnt = 0;
    do {
        cnt++;
        rep(i, N-1) {
            ll x = pow(coord.at(order.at(i)).first - coord.at(order.at(i+1)).first, 2);
            ll y = pow(coord.at(order.at(i)).second - coord.at(order.at(i+1)).second, 2);
            sum += sqrt(x + y);
        }
    } while (next_permutation(order.begin(), order.end()));
    
    printf("%.10f\n", sum / cnt);

}


Measured memory_bytes: 256
import sys
#import cython

def main():
    read = lambda: sys.stdin.readline().rstrip()
    import collections
    
    d = collections.defaultdict(int)
    N = int(read())
    A = list(map(int,read().split()))

    cnt = 0
    for i, x in enumerate(A):
        d[i + x] += 1
        if d[i-x] > 0: cnt += d[i-x]
    
    print(cnt)
    


if __name__ == "__main__":
    main()

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

struct strongly_connected_conponent {
private : 
	int scc_size;
	vector<vector<int>> g, revg;
	vector<bool> seen;
	vector<int> order, index;

	void dfs (int v) {
		seen[v] = true;
		for (int u : g[v]) {
			if (not seen[u]) dfs(u);
		}
		order.push_back(v);
	}

	void dfs2 (int v, const int idx) {
		seen[v] = true;
		index[v] = idx;
		for (int u : revg[v]) {
			if (not seen[u]) dfs2(u, idx);
		}
	}

public : 
	strongly_connected_conponent (int n) : 
		g(n), revg(n), index(n), seen(n) { }

	void add_edge (int u, int v) noexcept {
		g[u].push_back(v);
		revg[v].push_back(u);
	}

	int build() {
		order.clear();
		fill(seen.begin(), seen.end(), false);
		for (int v = 0; v < g.size(); v++) {
			if (not seen[v]) dfs(v);
		}
		
		int idx = 0;
		fill(seen.begin(), seen.end(), false);
		reverse(order.begin(), order.end());
		for (int v : order) if (not seen[v]) dfs2(v, idx++);
		return (*max_element(order.begin(), order.end()));
	}

	int operator[] (int v) {
		return (index[v]);
	}

};


int main() {
	int n, m, q;
	cin >> n >> m;
	
	strongly_connected_conponent scc(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		scc.add_edge(a, b);
	}

	scc.build();
	
	cin >> q;
	while (q--) {
		int a, b;
		cin >> a >> b;
		cout << (scc[a] == scc[b]) << '\n';
	}
	
	return 0;
}


Measured memory_bytes: 4500
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
#define ll  long long 
  vector<ll>to[1000005];
int main(){
  ll a,b;cin>>a>>b;
  rep(i,1250){
    if(i==0)i++;
    if(i*8/100==a&&i/10==b){
      cout<<i;
      return 0;
    }
  }
  cout<<-1;
  }


Measured memory_bytes: 23680
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
int n, k;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    if(k>(n-1)*(n-2)/2){
        cout <<-1<<"\n";
        return  0;
    }
    cout <<n-1+(n-1)*(n-2)/2-k<<"\n";
    rep(i,2,n+1){
        cout <<1<<" "<<i<<"\n";
    }
    int res=(n-1)*(n-2)/2-k;
    rep(i,2,n+1){
        rep(j,i+1,n+1){
            if(res==0) return 0;
            cout <<i<<" "<<j<<"\n";
            res--;
        }
    }
}

Measured memory_bytes: 256
n = int(input())
xi = list(map(int, input().split()))
def f(xi, i):
    e = 0
    for x in xi:
        e += abs(x - i) ** 2
    return e
minxi = min(xi)
mine = f(xi, minxi)
for i in range(minxi + 1, max(xi) + 1):
    e = f(xi, i)
    if mine > e : mine = e
    else: break
print(mine)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<string,string> Pss;
const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int f[MAX_N]={};
int b[MAX_N]={};
bool dp[MAX_N]={};
vector<Pss> Vs,Vs2;

int main() {
	int a,b,c,d,e,f,g,h,i;
	int total=0;
	cin>>a>>b>>c>>d>>e>>f>>g>>h>>i;
	rep(j,1000000){
		int j1=j;
		int f1=j1%10;
		j1/=10;
		int e1=j1%10;
		j1/=10;
		int d1=j1%10;
		j1/=10;
		int c1=j1%10;
		j1/=10;
		int b1=j1%10;
		int a1=j1/10;
		int r=a1+c1+b1*10+d1*100+e1*10+f1;
		int g1=r/100;
		int i1=r%10;
		int h1=(r/10)%10;
		if(a!=a1&&a>0)continue;
		if(b!=b1&&b>0)continue;
		if(c!=c1&&c>0)continue;
		if(d!=d1&&d>0)continue;
		if(e!=e1&&e>0)continue;
		if(f!=f1&&f>0)continue;
		if(g!=g1&&g>0)continue;
		if(h!=h1&&h>0)continue;
		if(i!=i1&&i>0)continue;

		int s[9]={a1,b1,c1,d1,e1,f1,g1,h1,i1};
		sort(s,s+9);
		bool flg=true;
		rep(k,9){
			if(s[k]!=k+1)flg=false;
		}
		if(flg)total++;
	}
	cout<<total<<endl;
	return 0;
}



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

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 100005
#define ALL(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)


using namespace std;


int32_t main()
{
    IOS;

    int tt=1;
    //cin>>tt;
    while(tt--)
    {
        //int n; cin>>n; int arr[n]; for(int i = 0; i<n; i++) cin>>arr[i];
		int n,k; cin >> n >> k;
		int a = n % k;
		int b = k - a;
		cout<< min (a,b);
		
		cout<<endl;
    }
    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    vvl a(2, vl(n));
    rep(i, 2) {
        rep(j, n) {
            cin >> a[i][j];
        }
    }

    ll ans = 0;
    rep(x, n) {
        ll now = 0;
        exrep(j, 0, x) {
            now += a[0][j];
        }
        exrep(j, x, n-1) {
            now += a[1][j];
        }
        chmax(ans, now);
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=105;
inline int read(){
	char c=getchar();int t=0,f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n,m,k;
struct node{
	string s;
	int k,id;
}a[maxn];
bool cmp(node a,node b){
	if(a.s==b.s)return a.k>b.k;
	else return a.s<b.s;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++){
		a[i].id=i;
		cin>>a[i].s;
		a[i].k=read();
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++)printf("%d\n",a[i].id);
	return 0;
}


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

struct Card{char suit, value;};

void BubbleSort(struct Card C[], int n){
    for (int i=0;i<n;i++){
        for (int j=n-1;j>=i+1;j--){
            if(C[j].value < C[j-1].value){
                Card t = C[j-1]; C[j-1] = C[j]; C[j] = t;
            }
        }
    }
}
void SelectionSort(struct Card C[], int n){
    
    for (int i=0;i<n;i++){
        int minj = i;
        for(int j=i; j<n;j++){
            if(C[j].value < C[minj].value){
                minj = j;
            }
        }
            Card t = C[i]; C[i] = C[minj]; C[minj] = t;
        
    }
}
void trace(struct Card *A, int n){
    for(int i=0;i<n;i++){
        if(i > 0) cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}
 
bool isStableSort(struct Card C1[], struct Card C2[], int n){
    for(int i=0;i<n;i++){
        if(C1[i].suit != C2[i].suit){
            return false;
        }
    }
    return true;
}

int main(){
  
    Card C1[100];
    Card C2[100];
    int n;

    cin >> n;
    for(int i=0;i<n;i++){
        cin >> C1[i].suit >> C1[i].value;
        C2[i].value = C1[i].value;
        C2[i].suit = C1[i].suit;
    }
    
    BubbleSort(C1,n);
    SelectionSort(C2,n);
    trace(C1,n);
    cout << "Stable" << endl;
    trace(C2,n);
    
    if(isStableSort(C1,C2,n)){
       cout << "Stable" << endl;
    }else
    {
        cout << "Not stable" << endl;;
    }
    return 0;

}


Measured memory_bytes: 3100
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public static readonly long MOD = (long)(1e9) + 7;
  
	public void Solve()
	{
		int N = GetInt();
		int M = GetInt();
		int[] A = Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
		int[] B = Enumerable.Range(0, M).Select(_ => GetInt()).ToArray();

		long[] cntA = new long[N * M + 1];
		long[] csumA = new long[N * M + 1];
		long[] cntB = new long[N * M + 1];
		long[] csumB = new long[N * M + 1];
		for(int i = 0; i < N; i++)
			cntA[A[i]]++;
		
		for(int i = 0; i < M; i++)
			cntB[B[i]]++;

		if(cntA.Any(x => x > 1) || cntB.Any(x => x > 1))
		{
			Console.WriteLine(0);
			return;
		}

		for(int i = 0; i < N * M; i++)
		{
			csumA[i + 1] = csumA[i] + cntA[i + 1];
			csumB[i + 1] = csumB[i] + cntB[i + 1];
		}

		var ans = new ModInt(1);
		for(int x = N * M; x > 0; x--)
		{
			bool inA = (cntA[x] == 1);
			bool inB = (cntB[x] == 1);
			if(inA && (!inB))
			{
				var numB = new ModInt(csumB[N * M] - csumB[x - 1]);
				ans *= numB;
			}
			else if((!inA) && inB)
			{
				var numA = new ModInt(csumA[N * M] - csumA[x - 1]);
				ans *= numA;
			}
			else if((!inA) && (!inB))
			{
				var numA = new ModInt(csumA[N * M] - csumA[x - 1]);
				var numB = new ModInt(csumB[N * M] - csumB[x - 1]);
				var numFixed = new ModInt((long)(N * M - x));
				ans *= numA * numB - numFixed;
			}
		}

		Console.WriteLine(ans.Val);
	}
}


public struct ModInt
{
	public long Mod { get; private set; }
	public long Val { get; private set; }

	public ModInt(long v)
	{
		Mod = 1000000007;
		Val = v;
	}

	public static ModInt operator+(ModInt x, ModInt y)
	{
		long mod = x.Mod;
		long tmp = x.Val + y.Val;
		if(tmp >= mod)
			tmp -= mod;
		return new ModInt(tmp);
	}

	public static ModInt operator-(ModInt x, ModInt y)
	{
		long mod = x.Mod;
		long tmp = x.Val;
		if(tmp < y.Val)
			tmp += mod;
		tmp -= y.Val;
		return new ModInt(tmp);
	}

	public static ModInt operator*(ModInt x, ModInt y)
	{
		long mod = x.Mod;
		return new ModInt((x.Val * y.Val) % mod);
	}

	public static ModInt operator/(ModInt x, ModInt y)
	{
		long mod = x.Mod;
		long pow = mod - 2;
		long yy = y.Val;
		long inv = 1;
		while(pow > 0)
		{
			if((pow & 1) == 1)
				inv = (inv * yy) % mod;
			yy = (yy * yy) % mod;
			pow >>= 1;
		}
		return new ModInt((x.Val * inv) % mod);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
}


Measured memory_bytes: 31580
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include<random>
#include<iostream>
using namespace std;


int main() {
	long long T1, T2;
	long long A1, A2;
	long long B1, B2;

	cin >> T1 >> T2;
	cin >> A1 >> A2;
	cin >> B1 >> B2;

	if(T1*A1 + T2*A2 == T1*B1 + T2*B2){
		cout << "infinity\n";
		return 0;
	}

	if(A1 < B1){
		long long C;
		C = A1;
		A1 = B1;
		B1 = C;

		C = A2;
		A2 = B2;
		B2 = C;
	}

	if(A2 > B2){
		cout << 0 << "\n";
		return 0;
	}

	long long M = T1 * A1 - T1 * B1;
	long long m = T1 * B1 + T2 * B2 - T1 * A1 - T2 * A2;
	if(m<0){
		cout << 0 << "\n";
		return 0;
	}

	long long ans = 1;

	if(M%m == 0){
		ans -= 1;
	}
	
	if(m>=0){
		ans += 2*(long long)(M/m);
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
#define all(x) x.begin(), x.end()
#define fi first
#define se second
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+7;

vector<pair<Int, Int>> G[100001];
Int d[100001];
bool check = true;

void dfs(Int x) {
    for (Int i = 0; i < G[x].size(); i++) {
        pair<Int, Int> p = G[x][i];
        Int to = p.fi;
        Int cost = p.se;
        if (d[to] != INF and d[to] != d[x] + cost) {
            check = false;
            continue;
        }
        if (d[to] == INF) {
            d[to] = d[x] + cost;
            dfs(to);
        }
    }
}

int main() {
    Int n, m;
    cin >> n >> m;
    for (Int i = 0; i < m; i++) {
        Int a, b, c;
        cin >> a >> b >> c;
        G[a].emplace_back(b, c);
        G[b].emplace_back(a, -c);
    }
    for (Int i = 1; i <= n; i++) {
        d[i] = INF;
    }
    for (Int i = 1; i <= n; i++) {
        if (d[i] == INF) {
            d[i] = 0;
            dfs(i);
        }
        if (not check) {
            dump("No");
            return 0;
        }
    }
    dump("Yes");
    return 0;
}

Measured memory_bytes: 16512
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    ll A, B, C, K;
    cin >> A >> B >> C >> K;

    if (K % 2 == 0) cout << A - B << endl;
    else cout << B - A << endl;
    return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)
#define EPS         (1e-10)
#define EQ(a, b)    (abs((a)-(b)) < EPS)

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

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    std::ios::sync_with_stdio(false);

    int n;cin >> n;
    vector<pair<int, int>> v(n);

    for(int i=0;i<n;i++){
        int a, b;cin >> a >> b;
        v[i] = {a, b};
    }

    pair<int, int> mmax = *max_element(v.begin(), v.end());

    cout << mmax.first+mmax.second << endl;

    return 0;
}


Measured memory_bytes: 1024
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        w:chars
    }
    let mut c = vec![0; 26];
    for i in 0..w.len() {
        c[(w[i] as usize) - 97] += 1;
    }
    let mut flag = true;
    for i in 0..26 {
        if c[i] % 2 != 0 {
            flag = false;
        }
    }
    if flag {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)

typedef long long ll;
typedef pair<int, int> point;

const int MAXN = 2e5 + 5;
const int INF = 1e9;
const int off = 1 << 18;

int n, q, cnt;
vector <int> l[MAXN];
int dp[MAXN], a[MAXN];

struct Tournament{
    vector <point> t[2 * off];
    bool bio[2 * off];

    void build(int x){
        bio[x] = true;
        vector <point> v;
        sort(t[x].begin(), t[x].end());

        v.pb(point(0, INF));
        for(auto it : t[x])
            if(it.second < v.back().second)
                v.pb(it);
        t[x] = v;
    }

    void add(int x, int left, int val){
        x += off;
        while(x){
            t[x].pb(point(left, val));
            x >>= 1;
        }
    }

    int get(int x, int left){
        if(!bio[x])
            build(x);

        auto pos = lower_bound(t[x].begin(), t[x].end(), point(left, -INF));
        return (*(--pos)).second;
    }

    int query(int x, int lo, int hi, int a, int b){
        if(lo >= a && hi <= b)
            return get(x, a);
        if(lo >= b || hi <= a)
            return INF;

        int mid = (lo + hi) >> 1;
        int X = query(x * 2, lo, mid, a, b);
        int Y = query(x * 2 + 1, mid, hi, a, b);
        return min(X, Y);
    }
}T;

void load(){
    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> n;
    FOR(i, 1, n + 1)
        cin >> a[i];
    cin >> q;
    REP(i, q){
        int A, B; cin >> A >> B;
        l[B].pb(A);
    }
}

void solve(){
    FOR(i, 1, n + 1){
        cnt += 1 - a[i];

        for(auto it : l[i]){
            int val = min(T.query(1, 0, off, it, i), dp[it - 1]);
            T.add(i, it, val);
        }
        int add = a[i] == 1 ? 1 : -1;
        T.add(i, i + 1, dp[i - 1] + add);
        T.build(i + off);
        dp[i] = T.t[i + off].back().second;
    }
    cout << dp[n] + cnt;
}

int main(){
    load();
    solve();
}


Measured memory_bytes: 110028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = (1e5)+1;
 int n;
vector<pair<ll, ll> > a;
multiset<ll> r, b;
long long ans = LLONG_MAX;
int main() {	
ios::sync_with_stdio(false);
cin.tie(0);	
cin >> n;
a.resize(n);	
for(int i = 0; i < n; i++) {	
	cin >> a[i].first >> a[i].second;		if(a[i].first > a[i].second) 
swap(a[i].first, a[i].second);
	}	
sort(a.begin(), a.end());
	for(auto p: a) {	
	r.insert(p.first);	
	b.insert(p.second);	}	
ans = min((*r.rbegin() - *r.begin()) * (*b.rbegin() - *b.begin()), ans);	
for(auto p: a) {	
	r.erase(r.find(p.first));		b.erase(b.find(p.second));		r.insert(p.second);	
	b.insert(p.first);	
	ans = min((*r.rbegin() - *r.begin()) * (*b.rbegin() - *b.begin()), ans);	}
	cout << ans;}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    long long ans;
    string s;
    cin >> n;
    cin >> s;
    vector<long long> r,g,b;
    ans = 0;
 
    for(int i = 0; i < n; i++){
        if(s[i] == 'R'){
            r.push_back(i);
        }
        else if(s[i] == 'G'){
            g.push_back(i);
        }
        else if(s[i] == 'B'){
            b.push_back(i);
        }
    }
	/*
    for(int i = 0; i < r.size(); i++){
        for(int j = 0; j < g.size(); j++){
            for(int l = 0; l < b.size(); l++){
                if(abs(i - j) != abs(l-j)){
                    ans += 1;
                }
            }
        }
    }
    */
  int count = 0;
  ans = r.size() * g.size() * b.size();
  for(int p = 1; p < n; p++){
    for(int i = 0; i+ 2 * p < n; i++){
      if(s[i] != s[i+p] && s[i] != s[i+2*p] && s[i+p] != s[i+2*p]){
        count++;
      }
        }
    }
  ans -= count;
    cout << ans << endl;
}

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

int main() {
   int n, a, b;
   cin >> n >> a >> b;
   
   cout << min(a * n, b) << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque


n=int(sys.stdin.readline())
M = deque(maxlen=n)
for i in range(n):
    a,b = map(int,sys.stdin.readline().split())
    M.append([a,b])

M = sorted(M,key=lambda x:sum(x))
cnt = 0
for i in range(n):
    if i%2==0:
        cnt += M.pop()[0]
    else:
        cnt -= M.pop()[1]
print(cnt)


Measured memory_bytes: 25640