akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeindex>
#include <typeinfo>
#include <vector>
#include <boost/dynamic_bitset.hpp>

using namespace std;

#define DEBUG(x) cout << #x << ": " << x << endl
#define INFILE() freopen("input.txt", "r", stdin)

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_i = pair<ll, int>;
using i_ll = pair<int, ll>;
using d_i = pair<double, int>;
using ll_ll = pair<ll, ll>;
using d_d = pair<double, double>;

constexpr ll LL_MOD = 1000000009;
constexpr int I_MOD = 1000000007;
constexpr double EPS = numeric_limits<double>::epsilon();
constexpr double PI = 3.14159265358979323846264338327950288;

template <class T> void scan(vector<T> &v);
void scan(vector<string> &v, bool isWord = true);
boost::dynamic_bitset<> scan(char trueValue = 'o');

int main(int argc, char *argv[]) {
  // INFILE();
	int n, m;
	cin >> n >> m;

	vector<string> nmap(n);
	vector<string> mmap(m);

	scan(nmap);
	scan(mmap);

	int diff = n - m;
	for (int i = 0; i <= diff; i++) {
		for (int j = 0; j <= diff; j++) {
			bool judge = true;

			for (int k = 0; k < m; k++) {
				for (int l = 0; l < m; l++) {
					if (nmap[i + k][j + l] != mmap[k][l]) {
						judge = false;
					}
				}
			}

			if (judge) {
				cout << "Yes\n";
				return 0;
			}
		}
	}
	cout << "No\n";
  return 0;
}

template <class T> void scan(vector<T> &v) {
  map<type_index, const char *const> m = {{typeid(int), "%d"},
                                          {typeid(ll), "%lld"},
                                          {typeid(double), "%lf"},
                                          {typeid(char), "%c"}};

  auto tFormat = m[typeid(T)];

  for (T &n : v) {
    scanf(tFormat, &n);
  }
}

void scan(vector<string> &v, bool isWord) {
	if (isWord) {
		for (auto &n : v) {
			cin >> n;
		}
		return;
	}

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

boost::dynamic_bitset<> scan(char trueValue) {
	string s;
	getline(cin, s);

	if (s.size() == 0) {
		getline(cin, s);
	}

	for_each(begin(s), end(s), [trueValue](char &c) { c = (c == trueValue) ? '1' : '0'; });
	return boost::dynamic_bitset<>(string(rbegin(s), rend(s)));
}


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

int main(){
  int N, K, x;
  int sum = 0;
  cin >> N >> K;
  
  for(int i = 0; i < N; i++){
    cin >> x;
    if(x >= K - x){
      sum += 2*(K - x);
    }
    else{
      sum += 2*x;
    }
  }
  cout << sum << endl;
}
  


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int n,cnt1=0,cnt2=0,cnt3=0,cnt4=0;
	cin>>n;
	string s[100005];
	for(int i=0;i<n;i++){
		cin>>s[i];
		if(s[i]=="AC")
			cnt1++;
		if(s[i]=="WA")
			cnt2++;
		if(s[i]=="TLE")
			cnt3++;
		if(s[i]=="RE")
			cnt4++;
	}
	cout<<"AC x "<<cnt1<<endl;
	cout<<"WA x "<<cnt2<<endl;
	cout<<"TLE x "<<cnt3<<endl;
	cout<<"RE x "<<cnt4<<endl;
} 

Measured memory_bytes: 6748
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#include <numeric>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
const double EPS = 1e-10;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

struct Segmenttree {
	static const int N = 1 << 18;
	vector<ll>seg;
	vector<ll>idx;
	void st(ll p, ll v) {
		p += N - 1;
		seg[p] = v;
		idx[p] = p - N + 1;
		while (p > 0) {
			p = (p - 1) / 2;
			seg[p] = max(seg[2 * p + 1], seg[2 * p + 2]);
			if (seg[2 * p + 1] < seg[2 * p + 2])idx[p] = idx[2 * p + 2];
			else if (seg[2 * p + 1] > seg[2 * p + 2])idx[p] = idx[2 * p + 1];
			else idx[p] = min(idx[2 * p + 1], idx[2 * p + 2]);
		}
	}
	pair<ll, ll> query(ll l, ll r, ll a, ll b, ll k) {
		if (r <= a || b <= l)return { -inf,inf };
		if (l <= a && b <= r)return { seg[k],idx[k] };
		ll m = (a + b) / 2;
		auto p1 = query(l, r, a, m, 2 * k + 1);
		auto p2 = query(l, r, m, b, 2 * k + 2);
		if (p1.first > p2.first) return p1;
		else if (p1.first < p2.first)return p2;
		else return { p1.first,min(p1.second,p2.second) };
	}

	void init() {
		seg.resize(2 * N);
		idx.resize(2 * N);
		for (int i = 0; i < 2 * N; i++)seg[i] = -inf;
	}
	//[l,r]
	ll get(int l, int r) {
		return query(l, r + 1, 0, N, 0).first;
	}
	ll getidx(int l, int r) {
		return query(l, r + 1, 0, N, 0).second;
	}
	pair<ll, ll>getp(int l, int r) {
		return query(l, r + 1, 0, N, 0);
	}
};


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

	int N, Q;
	cin >> N >> Q;
	Segmenttree seg = Segmenttree();
	seg.init();
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		seg.st(i,a);
	}

	for (int i = 0; i < Q; i++) {
		int T;
		cin >> T;
		if (T == 1) {
			int X, V;
			cin >> X >> V;
			X--;
			seg.st(X,V);
		}
		else if (T == 2) {
			int L, R;
			cin >> L >> R;
			L--;
			R--;
			puts(seg.get(L, R));
		}
		else {
			int X, V;
			cin >> X >> V;
			X--;
			int ng = X-1, ok = N;
			while (ok - ng > 1) {
				int mid = (ok + ng) / 2;
				if (seg.get(X,mid) >= V)ok = mid;
				else ng = mid;
			}
			puts(ok + 1);
		}
	}
	return 0;
}

Measured memory_bytes: 11400
#include <stdio.h>
#include <string.h>

int main(void)
{
    int n, m;
    double g[100][100];
    double baby[100], baby_next[100];
    int i, j, k;
    double max;
    
    while (1){
        scanf("%d%d", &n, &m);
        if (n == 0 && m == 0){
            break;
        }
        
        for (i = 0; i < n; i++){
            for (j = 0; j < n; j++){
                scanf("%lf", &g[i][j]);
            }
        }
        
        for (i = 0; i < n; i++){
            baby_next[i] = 1.0;
        }
        
        for (k = 0; k < m - 1; k++){
            memcpy(baby, baby_next, sizeof(baby));
            for (i = 0; i < n; i++){
                max = 0.0;
                for (j = 0; j < n; j++){
                    if (max < baby[j] * g[j][i]){
                        max = baby[j] * g[j][i];
//printf("<%d->%d %.2lf>", j+1, i+1,max);
                    }
                }
//printf("|");
                baby_next[i] = max;
            }
//printf("\n");
            
            
            
            
        }
        
        memcpy(baby, baby_next, sizeof(baby));
        max = 0.0;
        for (i = 0; i < n; i++){
            if (max < baby[i]){
                max = baby[i];
            }
        }
        
        printf("%.2lf\n", max);
    }
    return (0);
}

Measured memory_bytes: 740
#include <iostream>
using namespace std;
  
int main (){
int a [10000],n,b;
long long c = 0;
cin >> n;
for (int i = 0; i < n; i++){
cin >> a[i];
}
 
  
for (int i = n-1; i > 0; i--){
for(int j = 0; j < i; j++){
if (a[j] > a[j+1]){
b = a[j];
a[j] = a[j+1];
a[j+1] = b;
}
}
}
  
for(int i = 0; i < n; i++){
c += a[i];
}
cout << a[0] << " " << a[n-1] << " " << c << endl;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

ll H, W;
const ll INF = (1ll<<60);

ll calc(int pos, vector<string> const &C){
	vector<vector<ll>> dp(H+1, vector<ll>(H+1, INF));
	vector<vector<ll>> cost(H+1, vector<ll>(H+1, 0));
	
	REP(i, H+1){
		REP(k, i){
			cost[i-k-1][H-k-1] = cost[i-k][H-k] + (C[H-i+k][pos]==C[k][pos+1]);
		}
	}

	REP(j, H+1){
		REP(k, j){
			cost[H-k-1][j-k-1] = cost[H-k][j-k] + (C[k][pos]==C[H-j+k][pos+1]);
		}
	}



	dp[0][0] = 0;
	REP(i, H+1){
		REP(j, H+1){
			if(i<H)chmin(dp[i+1][j], dp[i][j]+cost[i][j]);
			if(j<H)chmin(dp[i][j+1], dp[i][j]+cost[i][j]);
		}
	}

	/*
	cerr << endl;
	REP(i, H+1){
		REP(j, H+1){ 
			cerr << cost[i][j] << " ";
		}
		cerr << endl;
	}
	cerr << endl;

	cerr << endl;
	REP(i, H+1){
		REP(j, H+1){ 
			cerr << cost_tmp[i][j] << " ";
		}
		cerr << endl;
	}
	cerr << endl;

	
	cerr << endl;
	REP(i, H+1){
		REP(j, H+1){ 
			cerr << dp[i][j] << " ";
		}
		cerr << endl;
	}
	cerr << endl;
	*/

	return dp[H][H];
}

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

    cin >> H >> W;

    vector<string> C(H);
    REP(i, H){
    	cin >> C[i];
    }

    ll res = 0;
    REP(i, W-1){
    	res += calc(i, C);
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1864
import java.util.*;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt(), n = sc.nextInt();
		sc.close();
		long ans = 1;
		for(int i = 0; i < d; ++i)
			ans *= (long)100;
		if(n == 100)n++;
		ans *= (long)n;
		System.out.println(ans);
	}

}


Measured memory_bytes: 20948
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(a) a.begin(),a.end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=10000000000000000;

int par[100010];
int rrank[100010];
void init(int n){
for (int i=0;i<n;i++){
par[i]=i;
rrank[i]=0;
}}
int find(int x){
if (par[x]==x) return x;
else return par[x]=find(par[x]);
}
void unite(int x,int y){
x=find(x);
y=find(y);
if (x==y) return;
if (rrank[x]<rrank[y]) par[x]=y;
else {par[y]=x;
if (rrank[x]==rrank[y]) rrank[x]++;}}
bool same(int x,int y){
return find(x)==find(y);}

int main(){
    int n;
    cin >> n;
    vector<pp> x(n),y(n);
    vector<pair<int,pp>> a(0);
    rep(i,n){
        int f,g;
        cin >> f >> g;
        x.at(i)=make_pair(f,i);
        y.at(i)=make_pair(g,i);
    }
    sort(all(x));
    sort(all(y));
    rep(i,n-1){
        a.push_back(make_pair(x.at(i+1).first-x.at(i).first,make_pair(x.at(i).second,x.at(i+1).second)));
        a.push_back(make_pair(y.at(i+1).first-y.at(i).first,make_pair(y.at(i).second,y.at(i+1).second)));
    }
    init(n);
    sort(all(a));
    int ans=0;
    rep(i,a.size()){
        if (same(a.at(i).second.first,a.at(i).second.second)) continue;
        unite(a.at(i).second.first,a.at(i).second.second);
        ans+=a.at(i).first;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6516
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

	cout << (N / 100 == N % 10 ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
"use strict";
const Main = (input) =>{
   let xs = input.trim().split('\n');
   let N = parseInt(xs[0].split(' ')[0]); 
   let T = parseInt(xs[0].split(' ')[1]);
   let t = xs[1].split(' ').map(v=>parseInt(v,10));
   let ans = 0;
   
   for(let i=1; i<N; i++){
      ans = ans + Math.min(t[i]-t[i-1],T)
   }
   console.log(ans+T);
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

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

int h[200000000];
int H;

void HEAP(int h[], int i) {
	int l, r, a, b, MAX;
	l = i * 2;
	r = i * 2 + 1;
	if (h[l] > h[i] && l<=H) {
		MAX = l;
	}
	else {
		MAX = i;
	}
	if (h[MAX] < h[r] && r<=H) {
		MAX = r;
	}
	if (MAX != i) {
		a = h[i];
		b = h[MAX];
		h[i] = b;
		h[MAX] = a;
		HEAP(h, MAX);
	}
}

void HEAP2(int h[]){
	for (int i = H / 2; i >= 1; i--) {
		HEAP(h, i);
	}
}

int main() {
	cin >> H;
	for (int i = 1; i <= H; i++) {
		cin >> h[i];
	}
	HEAP2(h);
	for (int i = 1; i <= H; i++) {
		cout << ' ';
		cout << h[i];
	}
	cout << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int x;
    cin>>x;
    if(x==3 || x==5 || x==7)
    {
        cout<<"YES\n";
    }
    else
    {
        cout<<"NO\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, a;
    cin >> n >> a;
    string ans = "No";
    for(int i = 0; i<=a; i++){
        if((n-i)%500 == 0){
            ans = "Yes";
            break;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 3544
{-# LANGUAGE OverloadedStrings #-}
import Data.Array.Unboxed
import qualified Data.ByteString.Char8 as B
main = B.getLine >>= main' . breads
    where
        main' [n, d] = B.getLine >>= main'' . array (1, n) . zip [1..n] . build d . breads
        main'' arr = B.getLine >> B.getLine >>= mapM_ (B.putStrLn . toStr . ((arr :: UArray Int Bool) !)) . breads
        toStr b
            | b = "YES"
            | otherwise = "NO"

        breads = check . B.readInt
            where
                check (Just (n, bs))
                    | B.null bs = [n]
                    | otherwise = n : breads (B.tail bs)
                check _ = []

build :: Int -> [Int] -> [Bool]
build d ds = fst $ calc d (tail ds) (0 : ds)
    where
        calc acc (x : xs) (y : ys) = ((next <= acc') : zs, next)
            where
                (zs, b) = calc acc' xs ys
                acc' = min acc . abs $ acc - y
                next
                    | b > x `div` 2 = b + x
                    | otherwise = b
        calc acc _ (y : _) = ([1 <= min acc (abs $ acc - y)], 1)


Measured memory_bytes: 119164
//JSD
#include<iostream>
#include<vector>
#include<cmath>
#include<set>
#include<algorithm>
#define ll long long 
using namespace std;
int main(){
	ll n,l;
	cin>>n>>l;
	int a[n],b[n];
	ll sum=0;
	for(int i=0;i<n;i++){
		a[i]=abs(l+i);
		b[i]=(l+i);
		sum+=b[i];
	}
	int mi=0;
	for(int i=0;i<n;i++){
		if(a[mi]>a[i]){
			mi=i;
		}
	}
	sum-=b[mi];
	cout<<sum;
	ll ans=0;
	return  0;
}


Measured memory_bytes: 256
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]

# point[mask] : 
# maskで1が立っているbitに対応するうさぎだけで
# 1つのグループを作ったときの、そのグループの得点
point = [0] * (2**N)
for mask in range(2**N):
  mask_str = bin(mask)[2:].zfill(N)
  for i in range(N):
    if mask_str[i] == '1':
      for j in range(i+1, N):
        if mask_str[j] == '1':
          point[mask] += A[i][j]


# dp[mask] :
# maskで1が立っているbitに対応するうさぎだけで
# 最適にグループ分けしたときの得点
# maskの部分集合を_maskとすると、dpの遷移は以下
# dp[mask] = max_{_mask in mask}(dp[mask^_mask] + point[_mask])
dp = [-10**19 * 16] * (2**N)
dp[0] = 0
for mask in range(1, 2**N):
  dp[mask] = point[mask] # 一旦全員同じグループ
  _mask = (mask-1) & mask # maskの最も低い桁の1を0にしたもの
  while _mask > 0:
    dp[mask] = max(dp[mask], dp[mask^_mask] + point[_mask]) # 更新
    _mask = (_mask-1) & mask # この操作を繰り返すことでmaskの部分集合を列挙できる


print(dp[-1])

Measured memory_bytes: 45916
s = raw_input()
a = 700
if s == "ooo":
    print a + 300
elif s == "xxx":
    print a
elif s == "xox":
    print a + 100
elif s == "oxx":
    print a + 100
elif s == "xxo":
    print a + 100
else:
    print a + 200

Measured memory_bytes: 2568
maisu = int(input())
arucard = []
suto = ["S","H","C","D"]
kazu = ["1","2","3","4","5","6","7","8","9","10","11","12","13"]
trump = []
for a in suto:
    for b in kazu:
        card = (a+" "+b)
        trump.append(card)
#print(trump)
for n in range(maisu):
    nakusi = input()
    arucard.append(nakusi)
for x in arucard:
    trump.remove(x)
for y in trump:
    print(y)


Measured memory_bytes: 5596
m = []
f = []
r = []
while(True):
    M,F,R=map(int,input().split())
    if M == -1 and F == -1 and R == -1:
        break
    else:
        m.append(M)
        f.append(F)
        r.append(R)
for i in range(len(m)):
    score = m[i]+f[i]
    if (m[i] == -1 or f[i] ==-1) or score<30:
        print("F")
    elif score>=80:
        print("A")
    elif 65<=score<80:
        print("B")
    elif 50<=score<65:
        print("C")
    elif 30<=score<50 and r[i]>=50:
        print("C")
    elif 30<=score<50:
        print("D")


Measured memory_bytes: 5600
import java.util.*;
public class Main {
	public static void main (String[] args) {
      Scanner sc = new Scanner(System.in);
      int A = sc.nextInt(), B = sc.nextInt(), 
          C = sc.nextInt(), D = sc.nextInt();
      int left = A+B, right = C+D;
      String ans = (left > right)?"Left" : (left < right)?"Right" : "Balanced";
      System.out.println(ans);
    }
}

Measured memory_bytes: 35740
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

long solve(long x, long k, long d)
{
  if (x < 0) d = -d;
  auto a = std::abs(x / d);
  if (x % d) ++a;

  if (a > k) return std::abs(x - d * k);

  const auto b = x - d * a;
  return std::abs((k - a) % 2 ? b + d : b);
}

int main()
{
  long x, k, d;
  std::cin >> x >> k >> d;

  std::cout << std::setprecision(20);
  std::cout << solve(x, k, d) << std::endl;
}


Measured memory_bytes: 3616
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

enum MOD = (10 ^^ 9) + 7;

void main()
{
    long N, M;
    scan(N, M);
    long[] A = new long[](N);
    long[] B = new long[](N);
    foreach (i; 0 .. N)
    {
        scan(A[i], B[i]);
    }
    sort(zip(A, B));
    long result;
    loop: foreach (i; 0 .. N)
    {
        // writeln(A[i]);
        if (M <= B[i])
        {
            result += M * A[i];
            break loop;
        }
        else
        {
            result += B[i] * A[i];
            M -= B[i];
        }
    }
    writeln(result);
}


Measured memory_bytes: 4604
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if( abs( a-c ) <= d )
		Yes;
	else if( abs(a-b) <= d && abs(b-c) <= d){
		Yes;
	}
	else 
		No;
	ret 0;
}

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

int a[100010];

signed main()
{
	ios::sync_with_stdio(false);
	int h,n;
	cin>>h>>n;
	int sum=0ll;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	if(sum<h) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}

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

int main() {
	int N, COUNT = 0;;
	cin >> N;
	for (int i = 1; i <= N; i++) {
		int X = log10(i);
		if (X % 2 == 0) COUNT++;
	}
	cout << COUNT << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define per(i,a,n) for (int i=(n)-1;i>=(a);i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef long double DB;
mt19937 mrand(random_device{}()); 
const LL mod=1000000007;
int rnd(int x) { return (int)mrand() % x;}
LL powmod(LL a,LL b) { LL res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
LL gcd(LL a,LL b) { return b?gcd(b,a%b):a;}
// head

int a[5];
int main() {
	rep(i,0,5) scanf("%d",a+i);
	rep(i,0,5) if (a[i]==0) {
		printf("%d",i+1);
		break;
	}
}


Measured memory_bytes: 3740
N, M = map(int, input().split())

A = list(range(M))
B = list(range(M, 2*M))[::-1]
B = [-2-i for i in range(M//2)] + B[M//2:]

for a, b in zip(A, B):
    print(a % N + 1, b % N + 1)


Measured memory_bytes: 18780
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n, k;
string s;

int main() {
    cin >> n;
    V<Pii> v(n);
    REP(i, n) {
        int x,y; cin >> x >> y;
        v[i] = {x, y};
    }

    double res = 0;
    int cnt = 0;
    Vi p(n);
    REP(i, n) p[i] = i;
    do {
        cnt++;
        double sum = 0;
        REP(i, n-1) {
            sum += hypot(v[p[i]].first - v[p[i+1]].first, v[p[i]].second - v[p[i+1]].second);
        }
        res += sum;
    } while(next_permutation(ALL(p)));
    printf("%.8f\n", res/cnt);

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3


def next_line():
    return input()


def next_int():
    return int(input())


def next_int_array_one_line():
    return list(map(int, input().split()))


def next_int_array_multi_lines(size):
    return [int(input()) for _ in range(size)]


def next_str_array(size):
    return [input() for _ in range(size)]


def main():
    x, k, d = map(int, input().split())
    f = False
    if x < 0:
        f = True
        x = -x
    min_to_eq = x // d
    res = 0
    if min_to_eq >= k:
        # 同じ方向に動き続けるだけ
        res = x - d * k
    else:
        k -= min_to_eq
        x = x - d * min_to_eq
        if k % 2 != 0:
            res = x - d
        else:
            res = x
    if f:
        res = -res
    print(abs(res))


if __name__ == '__main__':
    main()


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

int main(){
  int n;
  int p1,p2;
  while(1){
    cin >> n;
    if(n==0) break;
    int ans1=0,ans2=0;
    for(int i=0;i<n;i++){
      cin >> p1 >> p2;
      if(p1 > p2){
	ans1 += p1 + p2;
      }
      else if(p1 < p2){
	ans2 += p1 + p2;
      }
      else{
	ans1 += p1;
	ans2 += p2;
      }
    }
    cout << ans1 << " " << ans2 << endl;
  }
}

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

using namespace std;

int main()
{
    #ifdef LOCAL_EXEC
    #else
    ios_base::sync_with_stdio();
    cin.tie(NULL);
    #endif // LOCAL_EXEC
    long long int x,y,i,n,d,ans=0;
    cin>>n>>d;
    for(i=0;i<n;i++){
        cin>>x>>y;
        if(x*x+y*y<=d*d)
            ans+=1;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,K,R,S,P;
  string T;
  cin>>N>>K>>R>>S>>P>>T;
  map<char,int> A;
  A['r']=P;A['s']=R;A['p']=S;
  int ans=0;
  for(int i=0;i<N;i++){
    if(i<K || T[i]!=T[i-K])ans+=A[T[i]];
    else T[i]='a';
  }
  cout<<ans<<endl;
}

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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>

const int INF = 1e9;
const int MOD = 1e9+7;

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i++)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)


//library----------------------------------------------

//最大公約数
ll GCD(ll a,ll b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
//最小公倍数
ll LCM(ll a,ll b){
    return a*b/GCD(a,b);
}

signed main(){
    LCIN(A,B);
    ll ans = LCM(A,B);
    printf("%lld\n",ans);
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>

using namespace std;

struct Node{
	int key;
	Node *p,*l,*r;
}; 

Node *root,*NIL;

void insert(int k){
	Node *x = root;
	Node *y = NIL;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->l = NIL;
	z->r = NIL;
	
	while(x!=NIL){
		y=x;
		if(z->key<x->key){
			x = x->l;
		}else{
			x= x->r;
		}
	}
		
		z->p = y;
		if(y==NIL){
			root = z;
		}else {
			if(z->key<y->key){
				y->l=z;
			}else{
				y->r = z;
			}
		}
	}
	
	Node *find(Node *u, int k)
	{
		while(u!=NIL&&u->key!=k){
			if(u->key>k){
				u = u->l;
			}else{
				u = u->r;
			}
		}
		return u;
	}
	
	
		Node *getMin(Node *u){
		while(u->l!=NIL){
			u=u->l;
		}
		return u;
	}
	
	
		Node* getSuccessor(Node *u){
		if(u->r!=NIL){
			return getMin(u->r);
		}
		
		Node *k;
		k = u->p;
		while(k!=NIL&&u==k->r){
			u=k;
			k=k->p;
		}
		return k;
	}
	

	
	
	
	void deleteNode(Node *z){
		Node *y;
		Node *x; //y???????????? 
		if(z->l==NIL||z->r==NIL){
			y=z;
		}else{
			y=getSuccessor(z);
		}
		
		if(y->l!=NIL){
			x=y->l;
		} else{
			x=y->r;
		}
		
		if(x!=NIL){
			x->p = y->p;
		}
		
		if(y->p==NIL){
			root=x;
		}else{
			if(y==y->p->l){
				y->p->l = x;
			}else{
				y->p->r = x;
			}
		}
		
		if(y!=z){
			z->key = y->key;
		}
		
		free(y);
	} 
	

		
	void inorder(Node *u){
		if(u==NIL) return;
		inorder(u->l);
		printf(" %d",u->key);
		inorder(u->r);
	}
	
	
	
	void preorder(Node *u){
		if(u==NIL) return;
		printf(" %d",u->key);
		preorder(u->l);
		preorder(u->r);
	}
	
	
	int main(){
		int n,i,x;
		string com;
		
		scanf("%d",&n);
		
		for(int i=0;i<n;i++){
			cin>>com;
			if(com=="insert"){
				scanf("%d", &x);
				insert(x);
			}else if(com=="find"){
				scanf("%d", &x);
				Node *p = find(root,x);
				if(p!=NIL) printf("yes\n");
				else printf("no\n");
			}else if(com=="delete"){
				scanf("%d",&x);
				Node *p = find(root,x);
				deleteNode(p);
			}
			else if(com=="print"){
				inorder(root);
				printf("\n");
				preorder(root);
				printf("\n");
			}
		}
		
		
		return 0;
}

Measured memory_bytes: 21944
n = int(input())
A = [int(x) for x in input().split()]


class Student:
    def __init__(self, attendance_number, time_order):
        self.attendance_number = attendance_number
        self.time_order = time_order


oder_list = []
for index, a in enumerate(A):
    oder_list.append(Student(index+1, a))

oder_list.sort(key=lambda x: x.time_order)

print(' '.join([str(x.attendance_number)for x in oder_list]))


Measured memory_bytes: 34316
num = []
n = input()

while n!= 0:
  num.append(n%10)
  n /= 10
num.reverse()

#print(num)

for i in range(len(num)):
  if num[i] == 1:
    num[i] = 9
  elif num[i] == 9:
    num[i] = 1
#print(num)

ans = ""
for j in range(len(num)):
  ans += str(num[j])
print(ans)

Measured memory_bytes: 2568
#include<iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main(){

  const int w=10,h=3,bn=4;
  int x[w*h*bn] = {0};

  int n;

  cin >> n;

  int b,f,r,p;
  for(int i=0;i<n;i++){
    cin>>b>>f>>r>>p;

    int idx = (b-1)*30 + (f-1)*10 + (r-1);
    x[idx] += p;
  }

  for(int i=0; i<w*h*bn; i++){
    cout << " " << x[i] ;
    if((i+1)%w == 0) cout<<endl;
    if((i+1)%(w*h) == 0 && i != w*h*bn-1){
      for(int j=0; j<20; j++) cout << "#";
      cout <<endl;
    }
  }

}



Measured memory_bytes: 3064
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1000000;
const int mod = 998244353;
const ll INF = 1LL << 60;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
int main() {
	double n, m, d,ans;
	cin >> n >> m >> d;
	ans = (n - d) * 2 / n / n*(m-1);
	if (d == 0)ans /= 2;
	cout <<fix(10)<< ans << endl;
	return 0;
}

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

const int INF = 1001001001;

int main(){
    int N, h[100000], dp[100000];
    cin >> N;
    rep(i, N) {
        cin >> h[i];
    }

    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);

    for (int i = 2; i < N; i++) {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }

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

    return 0;
}

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

const int N = 100010;
int x[N], v[N];
int r[N], l[N];

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

  memset(x, 0, sizeof(x));
  memset(v, 0, sizeof(v));
  memset(r, 0, sizeof(r));
  memset(l, 0, sizeof(l));

  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> v[i];
  }

  for (int i = 1; i <= n; i++) {
    r[i] = r[i - 1] + v[i];
  }

  for (int i = n; i >= 1; i--) {
    l[i] = l[i + 1] + v[i];
  }

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    r[i] = max(r[i] - x[i], r[i - 1]);
    ans = max(ans, r[i]);
  }

  for (int i = n; i >= 1; i--) {
    l[i] = max(l[i] - (c - x[i]), l[i + 1]);
    ans = max(ans, l[i]);
  }

  // r to l
  for (int i = 0; i <= n - 1; i++) {
    int tmp = l[i + 1] + r[i] - x[i];
    ans = max(ans, tmp);
  }

  // l to r
  for (int i = n; i >= 1; i--) {
    int tmp = r[i - 1] + l[i] - (c - x[i]);
    ans = max(ans, tmp);
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3328
// https://atcoder.jp/contests/abc070/tasks/abc070_c

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

ll N, T, m;

ll gcd(ll a, ll b)
{
  return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
  return a / gcd(a, b) * b;
}

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

  m = T;
  REP(i, N - 1)
  {
    cin >> T;
    m = lcm(m, T);
  }

  cout << m << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

map<int, int> ma;

int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	while (n--)
	{
		int t;
		scanf("%d", &t);
		ma[t] = n;
	}
	vector<pair<int, int> > ans;
	for (auto p: ma)
		ans.push_back({p.second, p.first});
	sort(ans.begin(), ans.end());
	for (int i = 0; i < ans.size() && i < m; ++i)
		printf("%d\n", ans[i].second);
	return 0;
}

Measured memory_bytes: 8068
// review
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
typedef long long ll;
const int MAXN = 300000;
bool isPrime[MAXN];
vector<int> prime;
vector<int> one, two, three, four;

int n;

bool check(int x) {
  for(int i=0;i<four.size();i++) {
    if (isPrime[four[i] + prime[x]]) {
      return false;
    }
  }

  for (int i=0;i<three.size();i++) {
    four.push_back(three[i] + prime[x]);
  }
  for (int i=0;i<two.size();i++) {
    three.push_back(two[i] + prime[x]);
  }
  for (int i=0;i<one.size();i++) {
    two.push_back(one[i] + prime[x]);
  }
  one.push_back(x);
  return true;
}

void solve() {
  for (int i=2;i<MAXN;i++) {
    isPrime[i] = true;
  }
  for (int i=2;i<=sqrt(MAXN);i++) {
    if (isPrime[i]) {
      for (int j=i*2;j<MAXN;j+=i) {
        isPrime[j] = false;
      }
    }
  }
  for (int i=0;i<=55555;i++) {
    if (isPrime[i]) {
      prime.push_back(i);
    }
  }
  int cnt = 0;
  for (int i=0;i<prime.size();i++) {
    if (prime[i] % 5 == 1) {
      cout << (cnt != 0 ? " " : "") << prime[i];
      cnt++;
    }
    if (cnt == n) {
      break;
    }
  }
  cout << endl;
}

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,d;
	cin>>a>>b;
if(b>a)
	{
		b=b-a;
		--a;
	}
else if(b==1)
{
		cout<<0<<endl;
		return 0;
}
else
{
	cout<<1<<endl;
	return 0;
}
	
	if(b%a!=0)
	{
	d=(b/a)+2;	
	}
	else
	{
		d=(b/a)+1;
	}
	cout<<d<<endl;
	
	
}


Measured memory_bytes: 3620
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll X;cin >> X;
  ll ans = 1;
  for(ll i=2;i<1000;i++){
    ll p=i*i;
    while(p<=X){
      ans=max(ans, p);
      p*=i;
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = a; i < (b + a); i++)
#define W1 while (1)
#define COUT(x) cout << x << endl
using namespace std;
using ll = long long;
using ld = long double;
#define ALL(x) x.begin(),x.end()
#define P pair<int,int>
#define mod 1000000007
#define PB push_back
#define F first
#define S second

int main() {
  int n;
  string tmp;
  map<string,int> s;
  vector<string> ans;
  int maxcount = 0;
  cin >> n;
  rep(i, n) {
    cin >> tmp;
    s[tmp]++;
    maxcount = max(maxcount, s[tmp]);
  }
  for (auto i : s) {
    if (i.S == maxcount) ans.PB(i.F);
  }
  sort(ans.begin(), ans.end());
  rep(i, ans.size()) {
    COUT(ans[i]);
  }

  return 0;
}


Measured memory_bytes: 27124
N = int(input())
A, B = map(int, input().split())
P = list(map(int, input().split()))

first_question_num = 0
second_question_num = 0
third_question_num = 0
for p in P:
    if p <= A:
        first_question_num += 1
    elif p <= B:
        second_question_num += 1
    else:
        third_question_num +=1
        
print(min(first_question_num,second_question_num, third_question_num))

Measured memory_bytes: 3064
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }   
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int X = sc.nextInt();
        int Y = sc.nextInt();

        int min = Integer.MAX_VALUE;
        for (int i = 0; i <= Math.max(X, Y); i++) {
            int CA = Math.max(0, (X - i) * A); 
            int CB = Math.max(0, (Y - i) * B); 
            int CC = 2 * i * C;
            min = Math.min(min, CA + CB + CC);
        }   

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

}

Measured memory_bytes: 35756
#include <bits/stdc++.h>
 
typedef long long ll;

using namespace std;
using Graph = vector<vector<int>>;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;

const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

const double PI=3.14159265358979323846; // or M_PI


void Main() {
    ll n, in_a;

    cin >> n;
    vector<ll> ans(n, 0);
    FOR(i, 2, n) {
        cin >> in_a;
        ans[in_a - 1]++;
    }

    REP(i, n) {
        COUT(ans[i]);
    }
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}

/*
4 3
1 2 3 4
1 3
2 3
2 4
*/

Measured memory_bytes: 4756
import java.util.*;


/**
 * Created by Seiya on 2016/10/16.
 */

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        long t = scanner.nextInt();

        long ans = 0;
        long old = scanner.nextLong();
        for (int i = 0; i < n - 1; i++) {
            long temp = scanner.nextLong();
            ans += Math.min(temp - old, t);
            old = temp;
        }
        System.out.println(ans + t);


    } // mainMethod


} // MainClass


Measured memory_bytes: 61524
from bisect import bisect_left

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    B = tuple(map(int, input().split()))

    surplus = []
    need = 0
    ans = 0
    for a, b in zip(A, B):
        diff = a - b
        if diff > 0:
            surplus.append(diff)
        if diff < 0:
            need += -diff
            ans += 1

    surplus.sort(reverse=True)
    cusum = [0] * (len(surplus) + 1)
    for i, sur in enumerate(surplus):
        cusum[i+1] = cusum[i] + sur

    plus = bisect_left(cusum, need)
    ans += plus
    if need and plus == len(cusum):
        print(-1)
    else:
        print(ans)
    
if __name__ == "__main__":
    main()

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

long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}

int main() {
  int x, y;
  cin >> x >> y;

  //if (y > x) swap(x, y);
  cout << GCD(x, y) << endl;
}


Measured memory_bytes: 3080
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
/* struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
}; */

/** Problem1318 : Long Distance Taxi **/
const int MAX_V = 6010;
const int MAX_CAP = 2010;

int N, M, cap;

int idx;
map<string, int> idx_list;
bool LPG[MAX_V];
int d[MAX_V][MAX_CAP];
int target;

struct Node {
	int v, c, d;
	Node (int _d, int _v, int _c) : v(_v), c(_c), d(_d){}
	bool operator<(const Node &n)const{return d>n.d;}
};

struct Edge {
	int to; int cost;
	Edge(int t, int c) :  to(t), cost(c){}
};
vector<Edge> G[MAX_V];

int toIdx(string name)
{
	if (idx_list.count(name)) {
		return idx_list[name];
	} else {
		idx_list[name] = idx++;
		return idx_list[name];
	}
}

void dijkstra(int s)
{
	fill(d[0], d[0]+MAX_V*MAX_CAP, INF);
	d[s][cap] = 0;
	
	priority_queue<Node> Q;
	Q.push(Node(0, s, cap));
	
	while (Q.size()) {
		Node p = Q.top(); Q.pop();
		int v = p.v, c = p.c;
		if (v == target) break;
		
		if (LPG[v])
			c = cap;
		//cerr << v << " " << c << " " << p.d << endl;
		
		bool ok=true;
		for (int i=c; i<=cap; i++) {
			if (d[v][i] < p.d) ok=false;
		}
		if (!ok) continue;
		
		for (int i=0; i<G[v].size(); i++) {
			Edge e = G[v][i];
			int nc = c - e.cost;
			if (nc<0) continue;
			
			if (d[e.to][nc] > p.d + e.cost) {
				d[e.to][nc] = p.d + e.cost;
				Q.push(Node(d[e.to][nc], e.to, nc));
			}
		}
	}
}

int main()
{
	while (cin >> N >> M >> cap, N||M||cap) {
		for (int i=0; i<MAX_V; i++) G[i].clear();
		idx_list.clear(); idx=0;
		cap *= 10;
		fill(LPG, LPG+MAX_V, false);
		
		string from, to;
		cin >> from >> to;
		
		for (int i = 0; i < N; i++) {
			string a, b; int c;
			cin >> a >> b >> c;
			int ia = toIdx(a), ib = toIdx(b);
			G[ia].push_back(Edge(ib, c));
			G[ib].push_back(Edge(ia, c));
		}
		
		for (int i = 0; i < M; i++) {
			string a; cin >> a;
			LPG[toIdx(a)] = true;
		}
		
		target = toIdx(to);
		dijkstra(toIdx(from));
		
		int ans = INF;
		for (int i=0; i<MAX_CAP; i++) {
			ans = min(ans, d[toIdx(to)][i]);
		}
		if (ans==INF) cout << -1 << endl;
		else cout << ans << endl;
	}
}

Measured memory_bytes: 57204
#include <iostream>
#include <string>

using namespace std;

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    string com = "Yes";
    if(n % 2 == 0){
        if(s.substr(0, n/2) != s.substr(n/2, n/2)){
            com = "No";
        }
    }else{
        com = "No";
    }

    cout << com;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define INF 4000000000000000000
int dx8[8]={-1,0,1,1,1,0,-1,-1};
int dy8[8]={1,1,1,0,-1,-1,-1,0};
int dx4[4]={-1,0,1,0};
int dy4[4]={0,-1,0,1};
int gcd(int a,int b){
    if(b==0)return a;
    return abs(gcd(b,a%b));
}
int uni[100010];
int root(int a){
    if(uni[a]<0)return a;
    return uni[a]=root(uni[a]); 
}
bool connect(int a,int b){
    a=root(a);
    b=root(b);
    if(a==b)return false;
    if(uni[a]>uni[b]){
        swap(a,b);
    }
    uni[a]=uni[a]+uni[b];
    uni[b]=a;
    return true;
}
signed main(void){
    int n;cin>>n;
    if(n%2==1){
        cout<<0<<endl;
        return 0;
    }
    n/=2;
    int ans=0;
    while(n>0){
        ans+=n/5;
        n/=5;
    }
    cout<<ans<<endl;
}
        


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.TreeMap;

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

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());
        String s;
        Map<String, Integer> map = new TreeMap<>();
        int max = 0;
        for (int i = 0; i < n; i++) {
            s = br.readLine();
            int val = map.containsKey(s) ? map.get(s) + 1 : 1;
            map.put(s, val);
            max = Math.max(max, val);
        }

        br.close();

        final int MAX = max;
        map.forEach((key, val) -> {
            if (val == MAX) {
                System.out.println(key);
            }
        });

    }
}

Measured memory_bytes: 74308
/**
 *      AGC 12 A
 *      author  : kyomukyomupurin
 *      created : 2018-10-08 18:15:54
**/

#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#define int64 long long
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N; cin >> N;
    int a[3 * N] = {};

    for (auto i = 0; i < 3 * N; ++i) {
        cin >> a[i]; 
    }

    sort(a, a + 3 * N, greater<int>());
    int64 ans = 0;

    for (auto i = 1; i <= 2 * N; i += 2) {
        ans += a[i];
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1408