akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int t[MAXn], x[MAXn], y[MAXn];
int main(){
  IOS();
  int n;
  cin>>n;
  REP(i,n) cin>>t[i]>>x[i]>>y[i];
  int nowx = 0, nowy = 0, nowt = 0;
  REP(i,n){
    int tx = x[i], ty = y[i], tt = t[i];
    debug("HI");
    if( abs(nowx-tx) + abs(nowy-ty) > tt-nowt ) return cout<<"No"<<endl,0;
    int tmp = tt-nowt-abs(nowx-tx)-abs(nowy-ty);
    debug(tmp);
    if( tmp&1 ) return cout<<"No"<<endl,0;
    nowx = tx, nowy = ty, nowt = tt;
  }
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 1408
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var TX = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (T, X) = (TX[0], TX[1]);

        var ans = (double)T / X;

        WriteLine(ans);
    }
}


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

using namespace std;
#define int long long
vector <int> operator +(vector <int> a,vector <int> b)
{
    vector <int> c;
    for(int i=0;i<a.size();++i)
    {
        c.push_back(a[i]);
    }
    for(int j=0;j<b.size();++j)
    {
        c.push_back(b[j]);
    }
    return c;
}
const int maxn=50;
vector <int> a[maxn];
vector <int> b[maxn];
int d[maxn][maxn];
bitset <maxn> is[maxn][maxn];
int po[63];
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int u=1;
    for(int i=0;i<63;++i)
    {
        po[i]=u;
        u*=2;
    }
    for(int i=0;i<maxn;++i)
    {
        for(int j=0;j<maxn;++j)
        {
            if(i==j)
            {
                d[i][j]=0;
            }
            else
            {
                d[i][j]=1e18;
            }
        }
    }
    int n;
    cin>>n;
    for(int i=0;i<(n-1);++i)
    {
        int x,y;
        cin>>x>>y;
        x--;y--;
        a[x].push_back(y);a[y].push_back(x);
        b[x].push_back(i);b[y].push_back(i);
        d[x][y]=1;
        is[x][y][i]=1;;
        d[y][x]=1;
        is[y][x][i]=1;
    }
    for(int cyc=0;cyc<maxn;++cyc)
    {
    for(int i=0;i<maxn;++i)
    {
        for(int j=0;j<maxn;++j)
        {
            if((d[i][cyc]+d[cyc][j])<d[i][j])
            {
                d[i][j]=(d[i][cyc]+d[cyc][j]);
                is[i][j]=(is[i][cyc] | is[cyc][j]);
            }
        }
    }
    }
    int m;
    cin>>m;
    pair <int,int> a[m];
    for(int i=0;i<m;++i)
    {
        cin>>a[i].first>>a[i].second;
        a[i].first--;a[i].second--;
    }
    int ans=0;
    int sz=(1<<m);
    for(int mask=0;mask<sz;++mask)
    {
        int curr=1;
        bitset <maxn> t;
        for(int j=0;j<m;++j)
        {
            if(mask & po[j])
            {
                curr*=(-1);
                t |= is[a[j].first][a[j].second];
            }
        }
        int z=t.count();
        int ans1=po[n-1-z];
        ans+=(curr*ans1);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define ll long long
ll gcd(ll a,ll b){
    if (a == 0)
        return b;
    if (b == 0)
        return  a;
    ll r = a % b;
    while(r > 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}
ll max(ll a,ll b){return a>b?a:b;}
int main(){
    int n;
    scanf("%d",&n);
    ll a[n];
    for (int i = 0; i < n; i++)
        scanf("%lld",&a[i]);
    ll L[n], R[n];
    L [0] = R[0] = 0;
    for (int i = 0; i < n; i++){
        L[i + 1] = gcd(L[i], a[i]);
        R[i + 1] = gcd(R[i], a[n - i - 1]);
    }
    ll ans = 0;
    for (int i = 0; i < n; i++)
        ans = max(ans, gcd(L[i], R[n - i - 1]));
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 2560
n = gets.to_i
w = x = y = z = 0
n.times do |i|
  s = gets.chomp
  if s[0] == "B"
    if s[-1] == "A"
      x += 1
    else
      y += 1
    end
  elsif s[-1] == "A"
    z += 1
  end
  w += s.scan("AB").size
end
if x > 1
  w += x - 1
  x = 1
end
if [x, y, z].max == y
  w += x
  w += z
elsif [x, y, z].max == z
  w += x
  w += y
end
puts w

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String s = in.next();

        for (int i = 0; i < s.length(); i++) {
            System.out.print((char)((s.charAt(i) - 'A' + n) % 26 + 'A'));
        }
        System.out.println();
    }
}


Measured memory_bytes: 24788
N = int(input())
S = input()

new_alph = [i for i in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ']
new_S = [i for i in S]

for i in range(len(new_S)):
    try:
        new_S[i] = new_alph[new_alph.index(new_S[i])+N]
    except:
        new_S[i] = new_alph[new_alph.index(new_S[i])+N-26]
        
ans = ''.join(new_S)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    int k,n;
    cin >> k >> n;
    vector<int> vec;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        vec.push_back(a);
    }
    sort(vec.begin(),vec.end());
    int ans = k;
    for(int i=1; i<n; i++){
        ans = min(ans, k-(vec[i]-vec[i-1]));
    }
    ans = min(ans,(vec[n-1]-vec[0]));
    cout << ans <<endl;
}

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

signed main() {
  int N, M;
  cin >> N >> M;
  
  int cnt = M/N;
  while( true ){
    if( cnt*N <= M && (M-cnt*N)%cnt == 0 ){
      cout << cnt << endl;
      return 0;
    }
    cnt--;
  }
  
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

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

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) os << "[" << el.first << " " << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) os << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,K;
vector<int> A;

void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> N >> K;
    for (int i = 0; i < N; i++)
    {
      int a;
      cin >> a;
      A.push_back(a);
    }
    
}

int dp[110000];
bool used[110000];

int grundy(int x){
  if(used[x]) return dp[x];
  vector<int> next;
  for(auto a:A) if(x-a>=0) next.push_back(x-a);
  set<int> se;
  for(int y:next){
    se.insert(grundy(y));
  }
  if(se.size()==0) return dp[x] = 0;
  int ret=0;
  while(se.find(ret)!=se.end()) ret++;
  used[x] = true;
  return dp[x] = ret;
}

// 足す順番を間違えたせいで全く機能しなかった。
int solve(){
  cout << (grundy(K)?"First":"Second") << endl; 
  return 0;
}

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


Measured memory_bytes: 67456
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
//6,5,6,5,6,5,6,5,6.....
int main(){
	long long x;	cin>>x;
	long long ret=x/11*2;
	x%=11;
	if(x)	ret+=(x>6?2:1);
	cout<<ret<<endl;
	return 0;
}


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

int main() {
  int N, T, min = 1001;
  cin >> N >>T;
  int c[N], t[N];
  for(int i = 0; i < N; i++) {
    cin >> c[i] >> t[i];
    if(min > c[i] && T >= t[i]) min = c[i];
  }
  if(min == 1001) cout << "TLE";
  else cout << min;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
c = 0
c_1 = 0
for i in range(N):
    if A[i] % 2 == 0:
        c += 1
        if A[i] % 3 == 0 or A[i] % 5 == 0:
            c_1 += 1
if c == c_1:
    print("APPROVED")
else:
    print("DENIED")


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

int main(void)
{
	int N, A, B;
	cin >> N >> A >> B;
	if (N*A < B)
	{
		cout << N*A << endl;
	}
	else
	{
		cout << B << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import kotlin.math.ceil

//

fun main() {
    msolutions2020b()
}

fun msolutions2020b() {
    val (a, b, c) = readLine()!!.split(" ").map { it.toInt() }
    val k = readLine()!!.toInt()
    var t = b
    var i = 0
    while (t <= a) {
        t *= 2
        i++
    }
    var v = c
    while (v <= t) {
        v *= 2
        i++
    }
    println(if (i <= k) "Yes" else "No")
}


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

int SumDigit(int i) {
  int res=0;
  while (i>0) {
    res+=i%10;
    i/=10;
  }
  return res;
}
int Calc(int i, int a, int b) {
  int x=SumDigit(i);
  if (a <= x && x <=b) return i;
  return 0;
}
int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int ans=0;
  for (int i=1; i<=N; i++) {
    ans+=Calc(i, A, B);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n;
  cin >> n;
  vector<int> a(n);
  for(long long i=0;i<n;i++){
    cin >> a[i];
  }
  
  long long m=1000, b=0;
  for(int i=0;i<n-1;i++){
    
    if(a[i] > a.at(i+1) && i != n){
      m += a.at(i) * b;
      b=0;
    }
    if(a[i] < a.at(i+1) && i != n){
      b += m / a.at(i);
      m %= a[i];
    }
      
  }
   if(b>0)m += b*a[n-1];
  cout << m << endl;
}

Measured memory_bytes: 3596
#include<cstdio>
int n,s[11];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%s",s);
		if (s[0]=='Y')
		{
			printf("Four");
			return 0;
		}
	}
	printf("Three");
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;

int n;
int a[500];
int main(){
  scanf("%d",&n);
  rep(i,n) scanf("%d",&a[i]);

  int max=a[0];
  rep(i,n){
    if(max <= a[i]) max=a[i];
  }
  int min=a[0];
  rep(i,n){
    if(min>=a[i]) min=a[i];
  }

  lli res=100000000000000;
  reg(i,min,max){
    int cnt=0;
    rep(j,n){
      cnt+=abs((i-a[j])*(i-a[j]));
    }
//    printf("i:%d cnt:%d\n",i,cnt);
    if(cnt<=res) res=cnt;
  }

  printf("%lld\n",res);


  return 0;

}


Measured memory_bytes: 256
h, w = map(int, input().split())
a = [''] * h
for i in range(h):
	a[i] = input()

row = [False] * h
col = [False] * w
for i in range(h):
	for j in range(w):
		if a[i][j] == '#':
			row[i] = True
			col[j] = True

for i in range(h):
	if row[i]:
		for j in range(w):
			if col[j]:
				print(a[i][j], end = '')
		print()


Measured memory_bytes: 4468
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll,pair<ll, ll>> lpll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;

const ld PI = (acos(-1));
const ld EPS = 0.0000000001;

// unionfind tree
struct UnionFind{
    vector<int> p;
    UnionFind(int n){
        p.resize(n, -1);
    }

    int find(int x){
        if(p[x] == -1)return x;
        else return p[x] = find(p[x]);
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y)return;
        p[x] = y;
    }
};

int main() {
    // input, ready
    int N,M,K;
    cin >> N >> M >> K;
    UnionFind uf(N+1);
    map<int,vector<int>> group;
    vector<vector<int>> friends(N+1);
    vector<vector<int>> blocks(N+1);
    for (int i=1; i<=N; i++) {
        vector<int> tmp;
        group[i] = tmp;
        friends[i] = tmp;
        blocks[i] = tmp;
    }
    for (int i=0; i<M; i++) {
        int a,b;
        cin >> a >> b;
        uf.unite(a,b);
        friends[a].push_back(b);
        friends[b].push_back(a);
    }
    for (int i=1; i<=N; i++) group[uf.find(i)].push_back(i);


    for (int i=0; i<K; i++) {
        int c,d;
        cin >> c >> d;
        if (uf.find(c) == uf.find(d)) {
            blocks[c].push_back(d);
            blocks[d].push_back(c);
        }
    }

    // output
    for (int i=1; i<=N; i++) {
        int ans = group[uf.find(i)].size() - friends[i].size() - blocks[i].size() -1;
        cout << ans << " ";
    }
    cout << endl;
    // cout << fixed << setprecision(10) << middle << endl;

    return 0;
}


Measured memory_bytes: 20728
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD (long long)1e9+7
#define LINF (long long)4e18

int main(){
    int N,W;
    cin >> N >> W;
    vector<int> w(N),v(N);
    rep(i,N) cin >> w[i] >> v[i];
    vector<vector<long long>> dp(N+10,vector<long long>(W+100));
    rep(i,N){
        repr(j,1,W+1){
            dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
            if(j >= w[i]){
                dp[i+1][j] = max(dp[i+1][j],dp[i][j-w[i]] + v[i]);
            }
        }
    }
    cout << dp[N][W] << endl;
}
   

Measured memory_bytes: 87296
#include<iostream>
#include<vector>
#include<bitset>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<list>
#include<queue>
#include<map>
using namespace std;

int main(){
   int n; cin>>n;
   vector<int>a(n);
   for(int i=0;i<n;i++){
     cin>>a[i];
   }
   int q;
   cin>>q;
   for(int i=0;i<q;i++){
     int b,e;
     cin>>b>>e;
     reverse(a.begin()+b,a.begin()+e);
   }
   for(int i=0;i<n-1;i++){
     cout<<a[i]<<" ";
   }
   cout<<a[n-1]<<endl;
   return 0;
}


Measured memory_bytes: 3096
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, a[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) cin >> a[i];
    int sum = 0;
    FOR(i,1,n) sum ^= a[i];
    FOR(i,1,n) cout << (sum ^ a[i]) << ' ';
    return 0;
}


Measured memory_bytes: 4372
import math
from functools import reduce

# reduce(function, iterable, initializer)
def gcd(*number):
    return reduce(math.gcd, number)

def gcd_list(number):
    return reduce(math.gcd, number)

def main():
    sum = 0
    K = int(input())
    for i in range(1,K+1):
        for j in range(1,K+1):
            tmp = math.gcd(i, j)
            for k in range(1,K+1):
                sum += math.gcd(tmp, k)
    print(sum)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9568
def modulo_summation(N: int, A: list)->int:
    """f(n) = (n % a1) + ... + (n % aN) の最大値を求める。
    f(n) の各項の最大値を考えると `ai - 1` である。
    lcm(a1, a2, ..., aN) - 1 = M を考えると、任意の i について
    M = ai x M' - 1 = ai x (M' - 1) + (ai - 1)
    となり、M % ai = ai - 1 となることがわかる。したがって、n = M
    とすることで f(n) の各項は最大となり、当然 f(n) も最大となる。

    以上より、f(n) の最大値は sum(a - 1 for a in A)
    """
    return sum(a - 1 for a in A)


if __name__ == "__main__":
    N = int(input())
    A = map(int, input().split())
    ans = modulo_summation(N, A)
    print(ans)


Measured memory_bytes: 3188
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

template <class T>
class bit {
    public:
    bit(int n);
    ~bit();
    void clear();
    void add(int x, T value);
    T get(int x) const; // [0, x]
    
    private:
    int size;
    T* data;
};

template <class T> bit<T>::bit(int n) : size(n + 1) {
    data = (T *)calloc(size, sizeof(T));
}

template <class T> bit<T>::~bit() {
    free(data);
}

template <class T> void bit<T>::clear() {
    for (int i = 0; i < size; i++) data[i] = 0;
}

template <class T> void bit<T>::add(int x, T value) {
    for (x++; x < size; x += x & -x) data[x] += value;
}

template <class T> T bit<T>::get(int x) const {
    T value = 0;
    for (x++; x > 0; x -= x & -x) value += data[x];
    return value;
}

int a[40000];
int b[40000];
int c[40000];
int d[40000];

double calc(int n) {
    int i, j;
    double l = -1e9, r = 1e9, m = (l + r) / 2;
    vector <pair<double, int> > v, w;
    
    for (i = 0; i < n; i++) v.push_back(make_pair(-(double)a[i] / b[i], i));
    
    sort(v.begin(), v.end());
    
    for (i = 0; i < n; i++) d[v[i].second] = i;
    
    bit <long long> bt(n + 1);
    w.resize(n);
    
    for (i = 0; i < 100; i++) {
        int sum = 0;
        
        for (j = 0; j < n; j++) {
            w[j].first = (-(double)a[j] * m + c[j]) / b[j];
            w[j].second = d[j];
        }
        
        sort(w.begin(), w.end());
        
        bt.clear();
        
        for (j = 0; j < n; j++) {
            sum += bt.get(w[j].second);
            bt.add(w[j].second, 1);
        }
        
        if (n * (n - 1) / 2 % 2 == 0) {
            if (sum >= n * (n - 1) / 4) {
                r = m;
                m = (l + r) / 2;
            } else {
                l = m;
                m = (l + r) / 2;
            }
        } else {
            if (sum > n * (n - 1) / 4) {
                r = m;
                m = (l + r) / 2;
            } else {
                l = m;
                m = (l + r) / 2;
            }
        }
    }
    
    return m;
}

int main() {
    int n, i;
    double x, y;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%d %d %d", &a[i], &b[i], &c[i]);
    
    x = calc(n);
    
    for (i = 0; i < n; i++) swap(a[i], b[i]);
    
    y = calc(n);
    
    printf("%.12lf %.12lf\n", x, y);
    
    return 0;
}


Measured memory_bytes: 2572
<?php
	list($n, $m) = explode(" ", trim(fgets(STDIN)));

	$a = array();
	for ($i = 0; $i < $n; $i++) {
		$a[] = explode(" ", trim(fgets(STDIN)));
	}

	$b = array();
	for ($i = 0; $i < $m; $i++) {
		$b[] = explode(" ", trim(fgets(STDIN)));
	}

	$c = array();
	for ($i = 0; $i < $n; $i++) {
		$sum = 0;
		for ($j = 0; $j < $m; $j++) {
			$sum += $a[$i][$j] * $b[$j][0];
		}
		$c[] = $sum;
	}

	foreach ($c as $row) {
		echo $row . "\n";
	}

Measured memory_bytes: 8440
class SizedUnionFind
  def initialize(n)
    # 親の番号を格納
    # ただし、rootの位置には、-(その集合のサイズ)を格納
    @parent = Array.new(n, -1)
  end

  def root(x) # xのrootの番号を返す
    return x if @parent[x] < 0
    @parent[x] = root(@parent[x])
    return @parent[x]
  end

  def size(x) # xの属するグループのサイズを返す
    return -@parent[root(x)]
  end

  def merge(x, y)
    x, y = root(x), root(y)
    return false if x == y
    # 大きい方(x)に小さい方(y)をくっつけたい
    x, y = y, x if size(x) < size(y)
    @parent[x] += @parent[y]
    @parent[y] = x
    return true
  end

  def same?(x, y)
    root(x) == root(y)
  end
end

N,M=gets.split.map(&:to_i)
uf=SizedUnionFind.new(N)

M.times do
  x,y,z = gets.split.map(&:to_i)
  uf.merge(x-1, y-1)
end

cnt = {}
N.times do |i|
  cnt[uf.root(i)]=1
end

p cnt.size


Measured memory_bytes: 9084
#include<stdio.h>

int main(){
  int p,q,r;
  scanf("%d%d%d",&p,&q,&r);
  int ans;
  if(p<=r && q<=r){
    ans = p+q;
  }else if(p<=q && r<=q){
    ans = p+r;
  }else{
    ans = q+r;
  }
  printf("%d",ans);

  return 0;
}


Measured memory_bytes: 128
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    r = INT()
    print(r ** 2)

if  __name__=='__main__':
    main()


Measured memory_bytes: 5716
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef pair<int,int>   ii;
typedef vector<int>     vi;
typedef set<int>        si;

template<typename T> T sgn (T x)      {return x<0? -1:x!=0; }
template<typename T> T gcd (T a, T b) {return a ? gcd (b % a, a) : b; }
//pi=acos(-1)
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define clr(x,v) memset(x,v,sizeof x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define popcount __builtin_popcount
#define eb emplace_back
#define emp emplace
#define ss second
#define ff first
#define MOD ((int)1e9+7)
#define N ((int)2e5+123)
void reads(string& x){ char kk[N]; scanf("%s",kk); x = kk;}

ll a, b, ans;
string s;
ll v(char c){
    return c-'0';
}
void solve(){
    scanf("%lld", &a);
    reads(s);
    b = v(s[0])*100 + v(s[2])*10 + v(s[3]);
    ans = a*b/100;
    printf("%lld\n",ans);
}

int main(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;//scanf("%d",&t);
    while(t--)solve();
}

Measured memory_bytes: 3868
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
int main() {
    int a,b,c;cin >> a >> b >> c;
    int ans = c-(a-b);
    if(ans <= 0){
        ans = 0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print(max(0, a - 2 * b))
    return

#B
def B():
    n = II()
    d = LI()
    ans = 0
    for i in range(n):
        for k in range(i+1, n):
            ans += d[i] * d[k]
    print(ans)
    return

#C
def C():
    n = II()
    s = S()
    i = 0
    ans = 1
    for i in range(1, n):
        if s[i - 1] == s[i]:
            continue
        ans += 1
    print(ans)
    return

#D
def D():
    n = II()
    l = LI()
    l.sort()
    ans = 0
    for i in range(n - 1, 0, -1):
        for k in range(i - 1, -1, -1):
            ab = l[i] - l[k]
            c = max(0, k - bisect_right(l, ab))
            ans += c
    print(ans)
    return

#E
def E():
    n, m, l = LI()
    dist = [[inf] * n for i in range(n)]

    for _ in range(m):
        a, b, c = LI_()
        c += 1
        if c > l:
            continue
        dist[a][b] = c
        dist[b][a] = c

    supply = [[n] * n for i in range(n)]
    for k in range(n):
        distk = dist[k]
        for i in range(n):
            if i == k:
                continue
            disti = dist[i]
            distik = dist[i][k]
            for j in range(i + 1, n):
                if distik + distk[j] < disti[j]:
                    disti[j] = distik + distk[j]
                    dist[j][i] = disti[j]

    lis = [[] for i in range(n)]
    for i in range(n):
        for j in range(i + 1, n):
            if dist[i][j] <= l:
                supply[i][j] = 0
                supply[j][i] = 0
                lis[i].append(j)
                lis[j].append(i)

    for i in range(n):
        q = []
        for k in lis[i]:
            heappush(q, (0, k))
        supplyi = supply[i]

        while q:
            time, p = heappop(q)
            for k in lis[p]:
                if supplyi[k] > time + 1:
                    supplyi[k] = time + 1
                    heappush(q, (time + 1, k))

    q = II()
    for _ in range(q):
        s, t = LI_()
        if dist[s][t] == inf:
            print(-1)
            continue
        else:
            print(supply[s][t])
    return


#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 40432
n=gets.chomp.to_i

if n<=111
  puts "111"
elsif n<=222
  puts "222"
elsif n<=333
  puts "333"
elsif n<=444
  puts "444"
elsif n<=555
  puts "555"
elsif n<=666
  puts "666"
elsif n<=777
  puts "777"
elsif n<=888
  puts "888"
else
  puts "999"
end


Measured memory_bytes: 1788
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ttgl, null_type,less<ttgl>, rb_tree_tag,tree_order_statistics_node_update>*/
 
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
const ll root = 62;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 1000001;
ll fact[mxN];
ll ifact[mxN];
ll f[mxN];
ll g[mxN];
ll ans = 0;
int n;
ll nCr(int n, int r) {
    if(r>n)return 0;
    return ((fact[n]*ifact[r])%MOD*(ifact[n-r]))%MOD;
}
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>n;
    if(n==2) {
        cout<<"1\n";
        exit(0);
    }
    fact[0] = 1;
    ifact[0] = 1;
    owo(i, 1, mxN) {
        fact[i] = (fact[i-1]*i)%MOD;
        ifact[i] = (ifact[i-1]*modInv(i))%MOD;
    }
    owo(i, 2, n) {
        f[i] = (nCr(i-1, n-i-1)*fact[i])%MOD;
        f[i] = (f[i]*fact[n-i-1])%MOD;
        g[i] = (f[i] - f[i-1] + MOD)%MOD;
        ans = (ans + g[i]*i)%MOD;
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 34828
nhw = gets.split

nhw.map!{|a| a.to_i}

n=nhw[0]
h=nhw[1]
w=nhw[2]
array = Array.new
for i in (0..n-1)
    ab=gets.split.map{|a|a.to_i}
    array.push(ab)
end

m=0
array.each do |a|
  if (a[0] >=h && a[1]>= w)
    m +=1
  end
end
p m


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <stdlib.h>
using namespace std;

int main(){
    long long A,B,C,D;
    cin >>A >>B >>C >>D;
    long long num =B-A+1;
    long long num_C,C_s=A/C,C_e=B/C;
    if(C_s*C<A){
        C_s++;
    }
    num_C =C_e-C_s+1;
    long long num_D,D_s=A/D,D_e=B/D;
    if(D_s*D<A){
        D_s++;
    }
    num_D =D_e-D_s+1;
    long long x,tmp,r,a=C,b=D;
      x = a * b;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
        }
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    long long max_K=x/b;
    long long num_K,K_s=A/max_K,K_e=B/max_K;
    if(K_s*max_K<A){
        K_s++;
    }
    num_K =K_e-K_s+1;
    cout<<num-num_C-num_D+num_K<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int n,q,S[10000],T[10000],i,j=0,t=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){scanf("%d",&S[i]);}
  scanf("%d",&q);
  for(i=0;i<q;i++){scanf("%d",&T[i]);}
  for(i=0;i<q;i++){    
    for(j=0;j<n;j++){
      if(T[i]==S[j]){
	t++;
	break;
      }
    }
  }
  printf("%d\n",t);
  return 0;
}



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

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int X = sc.nextInt();

		int[] x = new int[N];

		x[0] = sc.nextInt();

		int max = x[0];

		int min = x[0];

		int ansMax = 0;	//答えになりうる値の最大値

		for(int i=1;i<N;i++) {

			x[i] = sc.nextInt();

			if(max < x[i]) {

				max = x[i];

			}

			if(min > x[i]) {

				min = x[i];
			}

		}



		ansMax = Math.min(Math.abs(X-max), Math.abs(X-min));


		boolean flag;

		//System.out.println(ansMax);

		for(int i = ansMax;i>0;i--) {	//D

			flag = true;

			for(int j=0;j<x.length;j++) {

				if(i %2 == 0 && (Math.abs(x[j])-X)%2 != 0) {

					flag = false;

					break;
				}

				if(Math.abs(x[j] - X ) < i ) {

					flag = false;

					break;

				}




				if(Math.abs(x[j] - X) % i != 0) {

					flag = false;

					break;
				}
			}

			if(flag == true) {

				System.out.println(i);

				break;
			}


		}

	}

}


Measured memory_bytes: 50212
import Foundation

func main(){
   let n = Int(readLine()!)!
   let a = (readLine()!).split(separator: " ").map({ Int($0)! })
   
   var answer = 0
   for i in 1...n {
      if i % 2 == 1 && a[i-1] % 2 == 1 {
         answer += 1
      }
   }
   print(answer)
}
main()

Measured memory_bytes: 13492
#include <bits/stdc++.h>
using namespace std;
                     
#define int             long long
#define ld              long double
#define mp              make_pair
#define ff              first
#define ss              second
#define pb              push_back
#define fo(i,n)         for(i=0;i<n;i++)
#define fo1(i,n)        for(i=1;i<=n;i++)
#define FO(i,k,n)       for(i=k;k<=n?i<=n:i>=n;k<=n?i++:i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define vpii            vector<pii>
#define vvi             vector<vi>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x)           cout<<setprecision(x)<<fixed;
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define in(a,n)         vi a(n);fo(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);fo1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define sz(v)           (int)v.size()
#define gcd             __gcd
#define lcm(x,y)        x*(y/gcd(x,y))
#define endl            '\n'
#define PI              3.14159265358979323846
const int inf =         1e18;
const int mod =         1e9+7;
void __p(int x) {cout<<x;}
void __p(int32_t x){cout<<x;}
void __p(float x){cout<<x;}
void __p(double x){cout<<x;}
void __p(ld x) {cout<<x;}
void __p(char x){cout <<'\''<<x<<'\'';}
void __p(const char *x){cout <<'\"' <<x<<'\"';}
void __p(const string &x) {cout<<'\"'<<x<<'\"';}
void __p(bool x) {cout<<(x?"true":"false");}
void _p() {cout << "]\n";}
template<typename T,typename V>     void __p(const pair<T,V> &x) {cout<<'{';__p(x.first);cout<<',';__p(x.second);cout<<'}';}
template<typename T>                void __p(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __p(i); cout << "}";}
template <typename T,typename... V> void _p(T t, V... v) {__p(t);if(sizeof...(v))cout<<", ";_p(v...);}
int po(int x,int p,int m = inf) {int ans=1;x%=m;while(p>0){if(p&1)ans=(ans*x)%m;p=p>>1;x=(x*x)%m;}return ans;}
int inv(int x,int m=mod){return po(x,m-2,m)%m;}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_p(x)
#else 
#define dbg(x...)
#endif
//=================================================================================




const int N=1e6+6;
int n,m,k,x,y,z,a,b,c,d,i,j,l,r,f;








void sol()
{   
    cin>>n;
    
    n%=1000;
    if(n==0)cout<<0;
    else 
    cout<< 1000-n<<endl;
}





int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //sp(10);
    // w(t)
    sol();
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define REP(i, n) for (decltype(n) i = 0; i < n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define readvec(vec)    \
  for (auto& e : vec) { \
    cin >> e;           \
  }
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<string> vecstr;
typedef vector<char> vecchar;
typedef vector<bool> vecbool;
typedef vector<vector<bool>> vec2bool;
typedef vector<vector<int>> vec2int;
typedef vector<vector<double>> vec2d;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
////////////////////////////////////////////////
void prime(vector<int>& v, int n) {
  v.clear();
  for (int i = 2; i <= n; i++) {
    bool ok = true;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        ok = false;
        break;
      }
    }
    if (ok) v.push_back(i);
  }
}
////////////////////////////////////////////////
int main() {
  init();
  int n;
  cin >> n;
  vecint v;
  prime(v, n);
  // REP(i, v.size()) { cout << v[i] << endl; }
  vec2int mp(n, vecint(v.size(), 0));
  vecint tot(v.size(), 0);
  for (int i = 2; i <= n; i++) {
    int x = i;
    // cout << x << " ";
    REP(j, v.size()) {
      int tmp = 0;
      while (x % v[j] == 0) {
        x /= v[j];
        tmp++;
      }
      // cout << tmp << endl;
      // mp[i][j] = tmp;
      tot[j] += tmp;
    }
  }
  // REP(i, v.size()) { cout << tot[i] << endl; }
  int num3 = 0;
  int num5 = 0;
  int num15 = 0;
  int num25 = 0;
  int num75 = 0;
  REP(i, v.size()) {
    if (tot[i] + 1 >= 75) {
      num75++;
    }
    if (tot[i] + 1 >= 25) {
      num25++;
    }
    if (tot[i] + 1 >= 15) {
      num15++;
    }
    if (tot[i] + 1 >= 5) {
      num5++;
    }
    if (tot[i] + 1 >= 3) {
      num3++;
    }
  }
  // cout << num75 << endl;
  // cout << num25 << endl;
  // cout << num15 << endl;
  // cout << num5 << endl;
  // cout << num3 << endl;
  cout << num75 + num25 * (num3 - 1) + num15 * (num5 - 1) +
              num5 * (num5 - 1) * (num3 - 2) / 2
       << endl;
  // REP(i, v.size()) { cout << tot[i] << endl; }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int main(){
    int n;
    scanf("%d", &n);
    lint cnt[MAX];
    memset(cnt, 0LL, sizeof(cnt));
    lint ans = 0;
    rep(i, n){
        int a;
        scanf("%d", &a);
        ++cnt[a];
        ans += a;
    }

    int q;
    scanf("%d", &q);
    rep(_, q){
        int b, c;
        scanf("%d%d", &b, &c);
        ans += cnt[b] * (c-b);
        cnt[c] += cnt[b];
        cnt[b] = 0;
        printf("%lld\n", ans);
    }
}

Measured memory_bytes: 4572
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	var s string
	fmt.Scan(&s)

	rs := []rune(s)
	n := len(rs)
	ans := n
	for i := 0; i < n-1; i++ {
		if rs[i] != rs[i+1] {
			continue
		}
		ans--
		i += 2
	}
	fmt.Println(ans)
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n], b = 0, c = 0; // b[n], c[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i] % 2 ? b++ : c++;
}
cout << (b % 2 ? "NO\n" : "YES\n" );
return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

int main() {
	int n, m;
	ll sum = 0;
	cin >> n >> m;
	vector<pair<ll, int>>a(n);
	REP(i, n) {
		cin >> a[i].first >> a[i].second;
	}
	sort(a.begin(), a.end());
	int i = 0;
	while (m > 0) {
		if (m >= a[i].second) {
			m -= a[i].second;
			sum += a[i].first*a[i].second;
		}
		else {
			sum += a[i].first*m;
			m = 0;
		}
		i++;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1920
#include <stdio.h>

// greatest common divisor
int gcd(int a,int b) {
	int r;

	if (a == 0 || b == 0) {
		return 0;
	}
	while (r = a%b) {
		a = b;
		b = r;
	}
	return b;
}

int main(void) {
	int a,b;

	scanf("%d%d",&a,&b);
	printf("%d\n",gcd(a,b));
	return 0;
}

Measured memory_bytes: 592
#include<stdio.h>
#define N 10000

int main(){
  int a,i,j,b[N],count,flag;
  count=0;
  flag=0;
  
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&b[i]);
  }

  for(i=0;i<a;i++){
    if(b[i]<2){
      continue;
    }
    for(j=2;j*j<=b[i];j++){  
      if(b[i]%j==0){
	flag=1;
	break;
      }
    }
    if(flag==0){
      count++;
    }
    flag=0;
  }

  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2064
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<random>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> as(n); cin >> as;
    int acc = accumulate(as.begin(), as.end(), 0ll);
    int mini = M;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int val = abs(as[i] * n - acc);
        if(val < mini){
            mini = val;
            ans = i;
        }
    }
    cout << ans << '\n';
}


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

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))

typedef long long ll;

int main() {
    int a, b, k;
    vector<int> nums;
    
    cin3( a, b, k);
    
    rep(i,k) {
        if ( a > b ) break;
        if( a==b ) {
            nums.push_back(a);
            break;
        }
        nums.push_back(a++);
        nums.push_back(b--);
    }
    
    sort( nums.begin(), nums.end());
    
    rep(i,nums.size()) {
        prtd1( nums[i]);
    }
}

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

ll min(ll a, ll b){
    if (a < b) return a;
    else return b;
}

ll max(ll a, ll b){
    if (a > b) return a;
    else return b;
}

int main(void){
    int N; cin >> N;
    int A[N-1]; for(int i = 0; i < N-1; i++) cin >> A[i];
    
    map<int, int> mp;
    for(int i = 0; i < N-1; i++){
        mp[A[i]-1]++;
    }
    
    for(int i = 0; i < N; i++){
        cout << mp[i] << endl;
    }
}


Measured memory_bytes: 13788
using System;
using System.Collections.Generic;
using System.Linq;

public class Prog
{
    public void run()
    {
        var input = Console.ReadLine().Split();
        int L = int.Parse(input[0]);
        int l = L % 2019;
        int R = int.Parse(input[1]);
        int r = R % 2019;
        int LL = (L - l) / 2019;
        int RR = (R - r) / 2019;
        int ans = 2018;
        if (LL == RR)
        {
            for(int i = l; i < r; i++)
            {
                for(int j = i + 1; j <= r; j++)
                {
                    ans = Math.Min(ans,(i * j) % 2019);
                }
            }
        }
        else if (l == 0 || r == 0)
        {
            ans = 0;
        }
        else
        {
            ans = 0;
        }
        Console.WriteLine(ans);
    }
    public static void Main()
    {
        var prog = new Prog();
        prog.run();
    }
    /*
    最小公倍数
    public static long Lcm(long a, long b)
    {
        return a * b / Gcd(a, b);
    }

    // ユークリッドの互除法 
    public static long Gcd(long a, long b)
    {
        if (a < b)
            // 引数を入替えて自分を呼び出す
            return Gcd(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }
    */
    //a<=c, b<=d;
}

//Array.ConvertAll(int.Parse)
//str.IndexOf("Stage",System.StringComparison.CurrentCulture)


Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
long mod = (int) 1e9 + 7;

int main(){
    
    string s;
    cin >> s;
    if(s == "ABC") cout << "ARC";
    if(s == "ARC") cout << "ABC";

    
    return 0;
}



Measured memory_bytes: 3052
use std::cmp::{max, min};

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let s = sc.chars();
    let n = s.len();
    let mut ans = n;
    for i in 1..n {
        if s[i - 1] != s[i] {
            let m = max(i, n - i);
            ans = min(ans, m);
        }
    }
    println!("{}", ans);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352