akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<auto>& a,int n);
double PI = 3.14159265358979;
int n;
int gcd(int u, int v) {
  int r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}

signed main(){
    cin >> n;
    vec(a,n);
    input(a,n);
    vec(x,n);
    vec(y,n);
    x[0] = a[0];
    FOR(i,1,n){
        x[i] = gcd(x[i-1],a[i]);
    }
    y[n-1] = a[n-1];
    for(int i = n-2;i > 0;i--){
        y[i] = gcd(y[i+1],a[i]);
    }
    int ans = max(x[n-2],y[1]);
    FOR(i,1,n-1){
        ans = max(ans,gcd(x[i-1],y[i+1]));
    }
    print(ans);
    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}

//key以上の初めてのitr
int nibul(auto a,auto b){return lower_bound(All(a),b) - a.begin();}
//key以下の最後のitr
int nibuu(auto a,auto b){return upper_bound(All(a),b) - a.begin()-1;}

void input(vector<auto>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define per(i,n) for(int i=(n)-1; i>=0; i--)
using namespace std;
using vi = vector<int>;
using vv = vector<vi>;

int main(){
    int n,k,s;cin>>n>>k>>s;
    
    int buf = 1000000000;
    if(s==buf)buf = 1;
    for(int i=0; i<n; i++){
        if(i<k)cout<<s;
        else cout << buf;
        if(i!=n-1)cout << " ";
        else cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3548
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] c = sc.next().toCharArray();
        Arrays.sort(c);
        if((c[0] == c[1] && c[2] == c[3]) && c[0] != c[2]){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23764
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define SZ(x) ((ll)(x).size())
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    string s;
    cin >> s;
    string t = s;
    reverse(all(t));
    put((ll)t.size()-(find(all(t),'Z')-t.begin())-(find(all(s),'A')-s.begin()));
    return 0;
}


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

int main() {
  
	int L;	
	cin >> L;
	double a, b, c, S;
	a = L/3.0;
	b = L/3.0;
	c = L/3.0;
	S = a * b * c;
	cout << fixed << setprecision(12);
	cout << S << endl;

}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

memo = {}
for i in range(N-1):
    Si = A[i]
    try:
        memo[Si] += 1
    except:
        memo[Si] = 1

for i in range(1, N+1):
    try:
        print(memo[i])
    except:
        print(0)


Measured memory_bytes: 33524
#include <iostream>
#include <string>
#include <stack>
#include <queue>
using namespace std;

int main(){
    int n1, n2;
    stack<int> nums;
    string tmp;
    while(cin>>tmp){
        if((tmp == "+")||(tmp == "-")||(tmp == "*")||(tmp == "/")){
            n2 = nums.top();
            nums.pop();
            n1 = nums.top();
            nums.pop();
            if(tmp == "+"){
                nums.push (n1+n2);
            }
            if(tmp == "-"){
                nums.push (n1-n2);
            }
            if(tmp == "*"){
                nums.push (n1*n2);
            }
            if(tmp == "/"){
                nums.push (n1/n2);
            }
        }
        else{
            nums.push(stoi(tmp));
        }
    }
        cout << nums.top() << endl;
}


Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin >> s;
  map<char, int> a;
  for (int i = 0; i < s.size(); i++) {
	if (a.find(s[i]) == a.end()) {
	  a.emplace(s[i], 1);
	}
	else {
	  cout << "no" << endl;
	  return 0;
	}
  }
  cout << "yes" << endl;
  return 0;
}



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

int main() {
  long long N; cin >> N;
  vector<long long> A(N);
  map<long long, long long> map;
  for (long long i = 0; i < N; i++) {
    long long a; cin >> a;
    A[i] = a;
    map[a]++;
  }
  long long all = 0;
  for (auto iter = map.begin(); iter != map.end(); iter++) {
    all += iter->second * (iter->second - 1) / 2;
  }
  for (long long k = 0; k < N; k++) {
    long long sub = map[A[k]] - 1;
    cout << (all - sub) << endl;
  }
}


Measured memory_bytes: 11008
#include<cstdio>
#include<algorithm>
using namespace std;
inline char tc(void){
	static char fl[10000],*A=fl,*B=fl;
	return A==B&&(B=(A=fl)+fread(fl,1,10000,stdin),A==B)?EOF:*A++;
}
inline int read(void){
	int a=0;static char c;
	while((c=tc())<'0'||c>'9');
	while(c>='0'&&c<='9')a=a*10+c-'0',c=tc();
	return a;
}
int n,a[201],ans;
int main(void){
	register int i;
	n=read()<<1;
	for(i=1;i<=n;++i)
		a[i]=read();
	sort(a+1,a+n+1);
	n>>=1;
	for(i=1;i<=n;++i)
		ans+=a[(i<<1)-1];
	printf("%d",ans);
	return 0;
}

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

const int MAX = 210000;
const int MOD = 998244353;

ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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

ll modpow(ll a, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    ll n, m, k;
    COMinit();
    cin >> n >> m >> k;
    ll ans = 0;
    for (ll i = 0; i <= k; i++) {
        ll tmp = (m * COM(n - 1, i)) % MOD;
        ans += tmp * modpow(m - 1, n - i - 1);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8540
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
map<int,int>m;
m[n]++;
for(int i=1;;i++){
    if(n%2==0)n=n/2;
    else n=n*3+1;
    m[n]++;
    if(m[n]==2){
        cout<<i+1;
        return 0;
    }
}

return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main { 
	public static int[][] map;
	public static ArrayDeque<Data> que;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			que = new ArrayDeque<Data>();
			int t = stdIn.nextInt();
			int n = stdIn.nextInt();
			if(t == 0 && n == 0) break;
			map = new int[150][150];
			for(int i = 0; i < 150; i++) {
				for(int j = 0; j < 150; j++) {
					map[i][j] = -1;
				}
			}
			for(int i = 0; i < n; i++) {
				int x = stdIn.nextInt();
				int y = stdIn.nextInt();
				map[y+75][x+75] = 9999999;
			}
			
			int x = stdIn.nextInt();
			int y = stdIn.nextInt();
			que.add(new Data(x+75,y+75,t));
			while(!que.isEmpty()) {
				Data a = que.poll();
				if(a.x < 0 || a.y < 0 || a.x >= 150|| a.y >= 150) continue;
				if(map[a.y][a.x] == 9999999) continue;
				if(map[a.y][a.x] >= a.t) continue;
				
				map[a.y][a.x] = a.t;
				if(a.t-1 == -1) continue;
				que.add(new Data(a.x+1,a.y+1,a.t-1));
				que.add(new Data(a.x+1,a.y,a.t-1));
				que.add(new Data(a.x,a.y+1,a.t-1));
				que.add(new Data(a.x,a.y-1,a.t-1));
				que.add(new Data(a.x-1,a.y,a.t-1));
				que.add(new Data(a.x-1,a.y-1,a.t-1));
			}
			
			int c = 0;
			for(int i = 0; i < 150; i++) {
				for(int j = 0; j < 150; j++) {
					if(map[i][j] != -1 && map[i][j] != 9999999) {
						c++;
					}
				}
			}
			System.out.println(c);
		}
	}
}

class Data {
	int x;
	int y;
	int t;
	public Data(int a, int b, int c) {
		x = a;
		y = b;
		t = c;
	}
}

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

using namespace std;

int n, k;
long long a[20],need[20];
long long premax = 0;

long long ans = LONG_LONG_MAX, mincost = 0;

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

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

    int comb = ( 1 << k ) - 1;
    while(comb < 1 << n){
        mincost = 0,premax = 0;
        int tem = comb,j = 0;
        while(tem > 0){

            if(tem & 1){
                if(a[j]<=premax){
                    mincost+=(premax-a[j]+1);
                    premax++;
                }
            }
            premax = max(premax,a[j]);
            j++;
            tem = tem >> 1;
        }
        ans=min(ans,mincost);


        int x = comb & (-comb), y = comb + x;
        comb = ((comb & ~y) / x >> 1) | y;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll = long long;
using p = pair<ll, ll>;

constexpr ll INF = 1LL << 62;

ll N, C;
vector<p> sushi;

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> C;

    for (ll i = 0; i < N; i++) {
        ll x, v;
        cin >> x >> v;
        sushi.push_back(p(x, v));
    }
    
    sushi.push_back(p(0, 0));
    sort(sushi.begin(), sushi.end());
    sushi.push_back(p(0, 0));

    vector<ll> cwsum(N + 2, 0), ccwsum(N + 2, 0);
    cwsum[0] = sushi.front().second;
    for (ll i = 1; i <= N; i++) {
        cwsum[i] = cwsum[i - 1] + sushi[i].second;
    }
    ccwsum[N + 1] = sushi.back().second;
    for (ll i = N; i >= 1; i--) {
        ccwsum[i] = ccwsum[i + 1] + sushi[i].second;
    }

    vector<ll> f(N + 1, 0);
    vector<ll> f2(N + 1, 0);
    for (ll i = 0; i <= N; i++) {
        f[i] = cwsum[i] - sushi[i].first;
        f2[i] = cwsum[i] - 2 * sushi[i].first;
    }
    vector<ll> g(N + 1, 0);
    vector<ll> g2(N + 1, 0);
    for (ll i = 1; i <= N; i++) {
        g[i] = max(g[i - 1], f[i]);
        g2[i] = max(g2[i - 1], f2[i]);
    }

    ll ans = 0;
    for (ll i = 1; i <= N + 1; i++) {
        ll d = C - sushi[i].first;
        if (d == C) {
            d = 0;
        }

        ans = max(ans, max(g[i - 1] + ccwsum[i] - 2 * d, g2[i - 1] + ccwsum[i] - d));
    }

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



Measured memory_bytes: 6512
using System;
using System.IO;

class Program{
    static void Main(string[] args){
        var arr = Console.ReadLine().Split();
        var N = int.Parse(arr[0]);
        var M = int.Parse(arr[1]);
        var C = int.Parse(arr[2]);
        var B = Console.ReadLine().Split();
        var answer = 0;
        for (int i = 1; i <= N; i++){
            var A = Console.ReadLine().Split();
            var sum = 0;
            for (int j = 0; j < M; j++){
                sum += int.Parse(A[j]) * int.Parse(B[j]);}
            if (sum + C > 0) answer++;}
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 27460
#include <iostream>
using namespace std;
int main() {
    //数字のカードの変数
    int a = 0;
    int b = 0;
    int c = 0;

    cin >> a >> b >> c;

    int ans = 0;

    int d = 10*a + b + c;
    ans = max(d,ans);
    int e = 10*a + c + b;
    ans = max(e,ans);
    int f = 10*b + a + c;
    ans = max(f,ans);
    int g = 10*b + c + a;
    ans = max(g,ans);
    int h = 10*c + a + b;
    ans = max(h,ans);
    int i = 10*c + b + a;
    ans = max(i,ans);

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
n,x=map(int, input().split())

total=[1]
paty=[1]
for i in range(n):
    total.append(total[i]*2+3)
    paty.append(paty[i]*2+1)

def rec(N, X): 
    if N==0 and X<=0:
        return 0 
    elif N==0 and X>0:
        return 1
    elif X<=1+total[N-1]:
        return rec(N-1, X-1)
    else:
        return paty[N-1] + 1 + rec(N-1, X-2-total[N-1])

print(rec(n, x))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int 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; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    vector<int> a(5);
    rep(i,5)cin >> a[i];
    rep(i,5)if(a[i] == 0)cout << i + 1 << endl;
}

Measured memory_bytes: 3684
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		long answer = 0;

		try {

			int N = sc.nextInt();
			int max = 0;

			for(int i = 0; i < N; i++) {
				int t = sc.nextInt();
				//既出の最大値の方が大きいとき
				if(max >= t) {
					//最大値更新せず
				}else {
					//最大値更新
					max = t ;
				}
				//最大値との差が必要な高さ
				answer += max - t;
			}

		}finally {
			sc.close();
			System.out.println(answer);
		}
	}

}


Measured memory_bytes: 48808
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "

int main(void){
    int n,k,tmp;cin>>n>>k;
    vector<int> h;
    ll ans=0;
    rep(i,n){cin>>tmp;h.emplace_back(tmp);}
    sort(h.begin(), h.end(), greater<int>());
    rep(i, n){if(i>=k)ans+=h[i];}
    co(ans);
}


Measured memory_bytes: 1400
N = int(input())
S = input()
if N <= 1 or (N % 2) == 1:
    print("No")
else:
    S1 = S[:int((N / 2))]
    S2 = S[int((N / 2)):]
    if S1 == S2:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
long long a,k,x[100005],ans=999999999999999;
int main()
{
	cin>>a>>k;
	for(int i=1;i<=a;i++)
	{
		cin>>x[i];
		if(i>=k)
		{
			if(x[i]<=0&&x[i-k+1]<=0)
				ans=min(ans,-x[i-k+1]);
			else if(x[i]>0&&x[i-k+1]<=0)
			{
				if(x[i]>(-x[i-k+1]))
				{
					ans=min(ans,x[i]-x[i-k+1]*2);
				}
				else 
				{
					ans=min(ans,x[i]*2-x[i-k+1]);
				}
			}	
			else if(x[i]>=0&&x[i-k+1]>=0)
				ans=min(ans,x[i]);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
module Main where

import           Data.List (nub, sort)

main :: IO ()
main = do
  n <- readLn
  putStrLn $ if f n then "Yes" else "No"

f :: Int -> Bool
f = (`elem` prices)

prices :: [Int]
prices = nub $ sort $ filter (100 >=) $ (+) <$> [0,4..100] <*> [0,7..100]


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

int main() {
	int N;
	cin >> N;
	vector<int> w(N);
	int sum=0;
	for(int i=0; i<N; ++i){
	    cin >> w[i];
	    sum += w[i];
	}
	int ans=1000000, now=0;
	for(int i=0; i+1<N; ++i){
	    now += w[i];
	    ans=min(ans, abs(now-(sum-now)));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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; }

int main(){
  string s;
  cin >> s;
  rep(i,sz(s)){
    cout << 'x';
  }
  cout << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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 double PI = acos(-1);

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    double a, b, x;
    cin >> a >> b >> x;
    x /= a;
    double rad;
    if(x <= a*b/2) rad = atan2(b*b,2*x);
    else rad = atan2(2*(a*b-x), a*a);
    double ans = rad / (2*PI) * 360;
    cout << fixed << setprecision(12) << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/rope>
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;
//
//template<class T> using Tree = tree<T, null_type, less<T>, rb_t_tag,t_order_statistics_node_update>;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;
//const long long mod = 998244353;

// watch this
//using ll = long long;
//typedef long long LL;
#define ll long long
#undef ll

const int mxN = 100010;

int main(int argc, char** argv) {
//#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
//#endif

	int N;
	cin >> N;
	vector<long long> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		if (a[i] > i) {
			cout << "-1\n";
			return 0;
		}
	}
	long long res = a[N - 1] != 0;
	for (int i = N - 2; i >= 0; i--) {
		res += a[i] != 0;
		if (a[i] >= a[i + 1] && a[i + 1] != 0)
			res += a[i + 1] - 1;
		if (a[i] < a[i + 1] - 1) {
			res = -1;
			break;
		}
//		cerr << res << '\n';
	}
	cout << res << '\n';
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	int n = 1;
	while (1) {
		if (n * 2 > N) break;
		else n *= 2;
	}

	cout << n << endl;
}

Measured memory_bytes: 3592
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

long long gcd(long long x, long long y)
{
	if(y == 0)
		return x;
	
	return gcd(y, x%y);
}

int main(void)
{
	int N;
	long long X;
	cin >> N >> X;

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

	for(int i=0; i<N; i++)
		x[i] = abs(x[i] - X);

	sort(x.begin(), x.end());

	long long ret = x[0];
	for(int i=1; i<N; i++)
		ret = gcd(x[i], ret);

	cout << ret << endl;

	return 0;
}


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

#define fi first
#define se second
#define CLR(A, X) memset(A, X, sizeof(A))
typedef long long LL;
typedef pair<int, int> PII;

int main() {
    LL a[5], n;
    scanf("%lld%lld%lld%lld%lld", &a[0], &a[1], &a[2], &a[3], &n);
    n *= 4;
    LL ans = 0;
    for(int i = 0; i < 50; i++) {
        if((1LL<<i) & n) {
            LL ret = -1;
            for(int j = 0; j < 4; j++) if(i >= j) {
                if(ret==-1 || ret>(1LL<<(i-j))*a[j]) {
                    ret = (1LL<<(i-j))*a[j];
                }
            }
            ans += ret;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 384
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
 
class Program {
    static List<int>[] Sub;
    static int[] Salary;
    
    
    static void Main(string[] args){
        var N = int.Parse(Console.ReadLine());
        var A  = Console.ReadLine().Split().Select(a => long.Parse(a)).ToArray();
        
        var B = new long[N+1];
        var C = new List<long>();
        var M = 0L;
        for(int i = (N/2)+1;i <= N;i++){
            B[i] = A[i-1];
            if(B[i] == 1){
                C.Add(i);
                M++;
            }
        }
        
        
        for(int i = (N/2);i > 0;i--){
           var tmp = i;
           var org = tmp;
           var sum = 0L;
           while(tmp <= N){
               sum += B[tmp];
               tmp += org;
           }
           
           if(sum%2 != A[i-1]){
               B[i] = 1;
               M++;
               C.Add(i);
           }
        }
      // var C = new long[N];
      // Array.Copy(B, 1, C, 0, B.Length - 1);
       var D = C.ToArray();
       Array.Sort(D);
       Console.WriteLine(M);
       Console.WriteLine(String.Join(" ",D
       ));
    }
         
}


Measured memory_bytes: 33500
/***     
 * When I wrote this
 * only God & I understood
 * what I was doing
 * Now, God only knows 
 /***/ 
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip>
#include<map>
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
//fixed<< setprecision(2)
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll n,k;
    while(cin>>n>>k)
    {
    ll *p=new ll[n+5];
    for(int i=0;i<n;i++)
    {
        cin>>p[i];
        
    }
    
    for(int i=k;i<n;i++)
    {
        if(p[i]>p[i-k])cout<<"Yes\n";
        else cout<<"No\n";
    }
    }
}

Measured memory_bytes: 4688
S,T = input(),input()

convert = dict()

bl = True
for s,t in zip(S,T):
  if s in convert and convert[s] != t:
    bl = False
    break
  convert[s] = t

# 変換先の重複チェック
after = convert.values()
if len(after) != len(set(after)):
  bl = False

print('Yes' if bl else 'No')


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

using namespace std;
using namespace std::chrono;

#define rep(i,a,b) for(int i = a;i<(b);++i)
#define trav(a,v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

ll big = 1000000007ll;
ll big2 = 1000000009ll;
ll n,m,k,q,p,w,h,x;

vector<ll> Z;
vector<ll> B;
vector<ll> Y;
vector<ll> C;

vector<ll> T;

vector<ll> A;
vector<ll> TI;

ll bs(ll t){
    ll l = 0;
    ll r = k;
    if(t >= T[k-1])return k-1;
    while(l < r-1){
        ll mid = (l+r)/2;
        if(t >= T[mid]){
            l = mid;
        }
        else{
            r = mid;
        }
    }
    return l;
}

ll fix(ll i){
    if(i > x)i = x;
    if(i < 0)i = 0;
    return i;
}

int main()
{
   // freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,d,e;


    cin >> x >> k;
    T.push_back(0);
    for(ll c1 = 0; c1 < k; c1++){
        cin >> a;
        T.push_back(a);
    }
    k++;
    Z.push_back(0);
    B.push_back(0);

    Y.push_back(x);
    C.push_back(x);

    for(ll c1 = 1; c1 < k; c1++){
        ll y,z;
        if(c1%2 == 0){
            ll l = T[c1]-T[c1-1];
            c = min(x, C[c1-1]+l);
            if(C[c1-1]+l > x){
                y = max(Z[c1-1], Y[c1-1] - (C[c1-1]+l-x));
            }
            else{
                y = Y[c1-1];
            }
            b = min(B[c1-1]+l,x);
            z = min(y,Z[c1-1]);
        }
        else{
            ll l = T[c1]-T[c1-1];
            b = max(0ll, B[c1-1]-l);
            if(B[c1-1]-l < 0){
                z = min(Y[c1-1], Z[c1-1] + (l-B[c1-1]));
            }
            else{
                z = Z[c1-1];
            }
            c = max(0ll, C[c1-1]-l);
            y = max(z, Y[c1-1]);
        }
        Z.push_back(z);
        B.push_back(b);
        Y.push_back(y);
        C.push_back(c);
    }

    cin >> q;

    for(ll c1 = 0; c1 < q; c1++){
        cin >> b >> a;
        ll i = bs(b);
        ll l = b-T[i];
        ll mul = 1;
        if(i%2 == 0)mul = -1;
       // cout << i << "   t\n";
        if(a < Z[i]){
            cout << fix(B[i]+mul*l) << "\n";
        }
        else{
            if(a > Y[i]){
                cout << fix(C[i]+mul*l) << "\n";
            }
            else{
                cout << fix(a-Z[i]+B[i]+mul*l) << "\n";
            }
        }
    }

    return 0;
}


Measured memory_bytes: 7796
#include<bits/stdc++.h> 
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void){
    int n;
    cin >> n;
    VI a(n+1);
    REP(i, n) cin >> a.at(i+1);
    VI b(n+1);
    for(int i = n; i >= 1; --i){
        int sum = 0;
        for(int j = i+i; j <= n; j += i ){
            sum ^= b[j]; 
        }
        b[i] = sum ^a[i];
    }
    VI ans;
    REP(i,n){
        dump(a[i+1])
    }
    REP(i, n){
        if(b.at(i + 1)) ans.push_back(i+1);
    }
    cout << ans.size() << endl;
    REP(i, ans.size()){
        cout << ans.at(i) << endl;
    }
    return 0;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

vi C(26), Last(26, -1), T(365);
vector<vi> S(365, vi(26));
vector<vi> table(365, vi(26));
ll ans = 0;
int D, M;

void Query(int d, int q) {
  int prev;
  prev = T.at(d);
  T.at(d) = q;
  ll sabun = 0;
  sabun += (S.at(d).at(q) - S.at(d).at(prev));

  sabun += table.at(d).at(q);
  table.at(d).at(q) = 0;
  for (int i = d + 1; i < D && table.at(i).at(q) != 0; i++) {
    sabun += table.at(i).at(q);
    table.at(i).at(q) = table.at(i - 1).at(q) + C.at(q);
    sabun -= table.at(i).at(q);
  }
  /*
  cout << "table " << q << ": ";
  REP(i, D) cout << table.at(i).at(q) << " ";
  cout << "\n";
  */

  table.at(d).at(prev) =
      (d == 0) ? C.at(prev) : table.at(d - 1).at(prev) + C.at(prev);
  sabun -= table.at(d).at(prev);
  for (int j = d + 1; j < D && table.at(j).at(prev) != 0; j++) {
    sabun += table.at(j).at(prev);
    table.at(j).at(prev) = table.at(j - 1).at(prev) + C.at(prev);
    sabun -= table.at(j).at(prev);
  }
  /*
  cout << "table " << prev << ": ";
  REP(i, D) cout << table.at(i).at(prev) << " ";
  cout << "\n";
  cout << "sabun = " << sabun << endl;
*/
  ans += sabun;
  // cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"

  cin >> D;
  REP(i, 26) cin >> C.at(i);
  REP(i, D) REP(j, 26) cin >> S.at(i).at(j);

  REP(i, D) { T.at(i) = i % 26; }

  for (int i = 0; i < D; i++) {
    REP(j, 26) {
      if (j == T.at(i)) {
        Last.at(j) = i;
        table.at(i).at(j) = 0;
      } else {
        table.at(i).at(j) = C.at(j) * (i - Last.at(j));
      }
    }
    // cout << count << endl;

    // cout << "T = " << T.at(i) << " S = " << S.at(i).at(T.at(i)) << endl;
    ans += S.at(i).at(T.at(i));
  }

  REP(i, D) {
    REP(j, 26) { ans -= table.at(i).at(j); }
  }
  /*
    REP(i, 26) {
      cout << "table " << i << ": ";
      REP(j, D) cout << table.at(j).at(i) << " ";
      cout << "\n";
    }
    cout << ans << endl;
  */

  random_device rnd;
  mt19937 mt((int)time(0));
  uniform_int_distribution<> rand365(0, 364);
  uniform_int_distribution<> rand26(0, 25);

  // Query
  REP(i, 100000) {
    ll pans = ans;
    vector<vi> oldtable = table;
    int d = rand365(mt), q = rand26(mt);
    // cout << d << " " << q << endl;
    int oq = T.at(d);
    Query(d, q);
    if (ans < pans) {
      ans = pans;
      T.at(d) = oq;
      table = oldtable;
    }
  }

  REP(i, D) cout << T.at(i) + 1 << endl;
  /*
std::random_device rnd;  // 非決定的な乱数生成器を生成
std::mt19937 mt(
    rnd());  //  メルセンヌ・ツイスタの32ビット版、引数は初期シード値
std::uniform_int_distribution<> rand100(0, 99);  // [0, 99] 範囲の一様乱数
for (int i = 0; i < 20; ++i) {
  std::cout << rand100(mt) << "\n";
}*/
}


Measured memory_bytes: 3772
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

int main() {
  ll n, a, b;
  cin >> n >> a >> b;

  if (a == 0) {
    puts("0");
    return 0;
  }
  ll c = (n / (a + b));
  ll ans = c * a + min(n - c * (a + b), a);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
k = [0] * M
s = [0] * M
for i in range(M):
    ks = list(map(int,input().split()))
    for j,x in enumerate(ks):
        if j == 0:
            k[i] = x
            continue
        s[i] += 1 << x-1
p = [int(i) for i in input().split()]

answer = 0
for i in range(2**N):
    count = [0] * M
    for j in range(M):
        tmp = s[j] & i
        while tmp:
            if tmp & 1:
                count[j] += 1
            tmp >>= 1

        # j番目の電球が光る場合 count[j] = 1
        if count[j] % 2 == p[j]:
            count[j] = 1
        else:
            count[j] = 0

    # 全ての電球が点灯する場合
    if not 0 in count:
        answer += 1

print(answer)

Measured memory_bytes: 41968
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}




const int N=105;
char s[N];
int n;

bool f(int l,int r){
	for(;l<=r;l++,r--) if(s[l]!=s[r]) return 0;
	return 1;
}

signed main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	if(f(1,n-1>>1)&&f(n+3>>1,n)&&f(1,n)) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#define N 1002
using namespace std;
int bfs(pair<int,int>,pair<int,int>);
int h,w,d[N][N];
string str[N];
int main(){
  int n,i,j,sum;
  pair<int,int> P[10];
  cin >> h >> w >> n;
  for(i=0;i<=w+1;i++) str[0]+='X',str[h+1]+='X';
  for(i=1;i<=h;i++) cin >> str[i],str[i]='X'+str[i]+'X';
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      if(str[i][j]=='S') P[0].first=i,P[0].second=j;
      if('1'<=str[i][j]&&str[i][j]<='9'){
	P[str[i][j]-'0'].first=i;
	P[str[i][j]-'0'].second=j;
      }
    }
  }
  sum=bfs(P[0],P[1]);
  for(i=1;i<n;i++) sum+=bfs(P[i],P[i+1]);
  cout << sum << endl;
}
int bfs(pair<int,int> s,pair<int,int> g){
  int i,j,ret;
  pair<int,int> t;
  pair<int,int> u;
  queue< pair<int,int> > Q;
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      d[i][j]=-1;
    }
  }
  Q.push(s);
  d[s.first][s.second]=0;
  while(Q.empty()!=1){
    u=Q.front();
    if(str[u.first][u.second]==str[g.first][g.second]){
      ret=d[u.first][u.second];
      break;
    }
    Q.pop();
    if(d[u.first][u.second-1]==-1&&str[u.first][u.second-1]!='X'){
      d[u.first][u.second-1]=d[u.first][u.second]+1;
      t.first=u.first;
      t.second=u.second-1;
      Q.push(t);
    }
    if(d[u.first][u.second+1]==-1&&str[u.first][u.second+1]!='X'){
      d[u.first][u.second+1]=d[u.first][u.second]+1;
      t.first=u.first;
      t.second=u.second+1;
      Q.push(t);
    }
    if(d[u.first-1][u.second]==-1&&str[u.first-1][u.second]!='X'){
      d[u.first-1][u.second]=d[u.first][u.second]+1;
      t.first=u.first-1;
      t.second=u.second;
      Q.push(t);
    }
    if(d[u.first+1][u.second]==-1&&str[u.first+1][u.second]!='X'){
      d[u.first+1][u.second]=d[u.first][u.second]+1;
      t.first=u.first+1;
      t.second=u.second;
      Q.push(t);
    }
  }
  return ret;
}

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

mt19937_64 llrand(random_device{}());

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
#define gcd(x, y) __gcd((x), (y))

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector<int> vi;
typedef vector<vi> vii;

const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 2e5+5;

ll st[4*N];

ll query (int p, int l, int r, int i, int j) {
    if (r < i or j < l) return 0;
    if (i <= l and r <= j) return st[p];
    ll x = query(2*p, l, (l+r)/2, i, j);
    ll y = query(2*p+1, (l+r)/2+1, r, i, j);
    return max(x, y);
}

void update (int p, int l, int r, int x, ll v) {
    if (x < l or r < x) return;
    if (l == r and l == x) {st[p] = v; return;}
    update (2*p, l, (l+r)/2, x, v);
    update (2*p+1, (l+r)/2+1, r, x, v);
    if (l != r) st[p] = max(st[2*p], st[2*p+1]);
}

ll n, h[N], a[N];

int main () {
    scanf("%lld", &n);
    for (int i = 1; i <= n; i++) scanf("%lld", &h[i]);
    for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
    for (int i = 1; i <= n; i++) {
        ll mx = query(1, 1, n, 1, h[i]-1);
        update(1, 1, n, h[i], a[i]+mx);
    }
    printf("%lld\n", query(1, 1, n, 1, n));

    return 0;
}


Measured memory_bytes: 8448
// inputに入力データ全体が入る
function Main(input) {
  var input = input.split(" ");
  var a = parseInt(input[0],10);
  var b = parseInt(input[1],10);

  // 偶数
  if((a*b) % 2 == 0) {
    console.log("Even")
    // 奇数
  } else {
    console.log("Odd")
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <cstdio>
#include <set>
#include <algorithm>

int as[200005];

int invert(int X){
  int k=0;
  while((1<<k)<=X) k++;
  //printf("invert(%d)=%d\n",X,(1<<k)-X);
  return (1<<k)-X;
}

int main(){
  int N;
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%d",&as[i]);
  }
  std::sort(as,as+N);
  std::multiset<int> look;
  int match=0;
  for(int i=N-1;i>=0;i--){
    if(look.count(as[i])){
      look.erase(look.find(as[i]));
      match++;
    }else{
      look.insert(invert(as[i]));
    }
  }
  printf("%d\n",match);
  return 0;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }
    sort(A, A + N, greater<ll>());
    ll a = 0, b = 0;
    REP(i, N - 1) {
        if (A[i] == A[i + 1]) {
            if (a == 0) {
                a = A[i];
                i += 1;
            }
            else {
                b = A[i];
                break;
            }
        }
    }
    cout << a * b << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int n;
unsigned int a[200000], s;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%u", a + i);
		s ^= a[i];
	}
	for (int i = 0; i < n; i++) {
		if (i < n - 1)printf("%u ", a[i] ^ s);
		else printf("%u\n", a[i] ^ s);
	}
}

Measured memory_bytes: 3204
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  ll N, M;
  cin >> N >> M;
  pli p[N];
  ll a[N]; int b[N];
  rep(i, N){
    cin >> a[i] >> b[i];
    p[i] = {a[i], b[i]};
  }
  sort(p, p+N);
  ll ans = 0;
  rep(i, N){
    ans += (p[i].first)*min((ll) p[i].second, M);
    M -= min((ll) p[i].second, M);
  }
  cout << ans << endl;
  
}
    

Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
#include <set>
#include <list>
#include <map>
#include<queue>

const int INF = 1 << 28;
using namespace std;
using Graph = vector<vector<int>>;

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

vector<int> seen(50,-1);
int counter_for_dfs = 0;
void dfs(Graph &G, int v) {
	seen[v] = counter_for_dfs;
	counter_for_dfs++;
	for (auto v_next : G[v]) {
		if (seen[v_next]>=0)continue;

		dfs(G, v_next);
	}
}

void bfs(Graph &G) {
	vector<int> dist(G.size(), -1);
	queue<int> que;
	
	dist[0] = 0;
	que.push(0);
	while (!que.empty()) {
		int v = que.front();
		que.pop();

		for (int g : G[v]) {
			if (dist[g] != -1)continue;
			dist[g] = dist[v] + 1;
			que.push(g);
		}
	}
	for (auto i : dist) {
		cout << i << " ";
	}
}

int main()
{
	int n;
	double sum = 0;
	int a[105];
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		sum += (1 / double(a[i]));
	}
	sum = 1 / sum;

	std::cout << sum;

}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
before = N
result = 0
for i in range(N):
  result += B[A[i] - 1]
  if before + 1 == A[i] - 1:
    result += C[before]
  before = A[i] - 1
print(result)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e6+5;
#define mod 2147483648
#define inf 0x7fffffff
int main(){
    int x;
    scanf("%d",&x);
    if(x>=400&&x<=599) printf("8\n");
    else if(x>=600&&x<=799) printf("7\n");
    else if(x >= 800&&x<=999) printf("6\n");
    else if(x>=1000&&x<=1199) printf("5\n");
    else if(x>=1200&&x<=1399) printf("4\n");
    else if(x>=1400&&x<=1599) printf("3\n");
    else if(x>=1600&&x<=1799) printf("2\n");
    else if(x>=1800&&x<=1999) printf("1\n");
    return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(int (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define INF 1000000007
#define LINF 1000000000000000007
typedef long long ll;
using namespace std;

int main(){
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  int dx = tx - sx;
  int dy = ty - sy;
  FOR(i,0,dx)cout << 'R';
  FOR(i,0,dy)cout << 'U';
  FOR(i,0,dx)cout << 'L';
  FOR(i,0,dy+1)cout << 'D';
  FOR(i,0,dx+1)cout << 'R';
  FOR(i,0,dy+1)cout << 'U';
  cout << 'L' << 'U';
  FOR(i,0,dx+1)cout << 'L';
  FOR(i,0,dy+1)cout << 'D';
  cout << 'R' << endl;
}


Measured memory_bytes: 256
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm_list(list):
    return reduce(lcm_base, list, 1)

N = int(input())
T = [int(input()) for i in range(N)]

print(lcm_list(T))


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

// T := c | [opTT]
int eval(string &s, string &pas, int &i){
    if(isalpha(s[i])){
        int pos = s[i]-'a';
        i++;
        return pas[pos]-'0';
    }
    assert(s[i] == '[');
    i++; // [
    char op = s[i]; i++;
    int x = eval(s,pas,i);
    int y = eval(s,pas,i);
    i++; // ]
    if(op == '+') return x | y;
    if(op == '*') return x & y;
    if(op == '^') return x ^ y;
    assert(false);
}

int main(void){
    string s;
    while(cin>>s, s != "."){
        string p;
        cin>>p;
        int index = 0;
        int hash = eval(s,p,index);
        int cnt = 0;
        rep(i,10000){
            index = 0;
            string str = to_string(i);
            while((int)str.size() < 4){
                str = "0"+str;
            }
            if(eval(s,str,index) == hash) cnt++;
        }
        cout<<hash<<" "<<cnt<<endl;
    }

}


Measured memory_bytes: 3256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  string s;
  cin >> s;

  rep (i, s.size() - 1) {
    if (s[i] == s[i+1]) {
      cout << i+1 << " " << i+2 << endl;
      return;
    }
  }

  rep (i, s.size() - 2) {
    if (s[i] == s[i+2]) {
      cout << i+1 << " " << i+3 << endl;
      return;
    }
  }

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

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    int n;
    cin >> n;
    int count[26][50] = {0};
    rep(i, n){
        string s;
        cin >> s;
        rep(j, s.size())count[s[j]-'a'][i]++;
    }
    rep(i, 26)sort(count[i], count[i]+n);

    string ans = "";
    rep(i, 26){
        rep(j, count[i][0])ans += 'a'+i;
    }
    cout << ans << endl;
}

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

using namespace std;

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

	vector<string> s(n);
	for(int i = 0; i < n; ++i) {
		cin >> s[i];
	}

	vector<int> col(n, -1);
	bool ok = true;

	function<void(int, int)> dfs = [&] (int u, int cur) {
		col[u] = cur;
		for(int v = 0; v < n; ++v) {
			if(s[u][v] == '1') {
				if(col[v] != -1) {
					if(col[v] == col[u]) {
						ok = false;
					}			
				} else {
					dfs(v, cur ^ 1);
				}
			}
		}
	};

	dfs(0, 0);

	if(!ok) {
		cout << -1 << '\n';
		exit(0);
	}

	vector<vector<int> > d(n, vector<int> (n));

	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			d[i][j] = (s[i][j] == '0' ? n : 1);
		}
	}

	for(int i = 0; i < n; ++i) {
		d[i][i] = 0;
	}

	for(int k = 0; k < n; ++k) {
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < n; ++j) {
				if(d[i][j] > d[i][k] + d[k][j]) {
					d[i][j] = d[i][k] + d[k][j];
				}
			}
		}
	}

	int ans = 0;

	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			ans = max(ans, d[i][j]);
		}
	}

	cout << ans + 1 << '\n';

	return 0;
}

Measured memory_bytes: 512
n = int(input())
s = input()
t = input()
ans = 2*n
for i in range(n):
    check = True
    for j in range(n-i):
        if s[i+j] != t[j]:
            check = False
            break
    if check:
        ans = min(ans,i+n)
print(ans)

Measured memory_bytes: 9132