akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
//using i128 = __int128_t;
//using u128 = __uint128_t;
using i128 = i64;
using u128 = u64;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

ll exgcd(ll a, ll b, ll &x, ll &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll px, py;
	ll d = exgcd(b, a%b, px, py);
	x = py;
	y = px-a/b*py;
	return d;
}

template<class T>
inline void freshmin(T &a, const T &b)
{
	if (a > b) a = b;
}

template<class T>
inline void freshmax(T &a, const T &b)
{
	if (a < b) a = b;
}

//#define getchar getchar_unlocked
//#define putchar putchar_unlocked

int inp() {
	int x = 0, f = 0; char ch;
	for(ch = getchar(); !isdigit(ch); ch = getchar())
		if(ch == '-') f = 1;
	for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	return f ? -x : x;
}

ll inp_ll() {
	ll x = 0; int f = 0; char ch;
	for(ch = getchar(); !isdigit(ch); ch = getchar())
		if(ch == '-') f = 1;
	for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	return f ? -x : x;
}

template<class T>
bool read(T &x)
{
	x = 0;
	char ch = getchar();
	if (ch == EOF) return 0;
	for(; !isdigit(ch); )
	{
		ch = getchar();
		if (ch == EOF) return 0;
	}
	for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	return 1;
}

template<class T>
void write(T x)
{
	static char s[22];
	static char *it = s+20;
	static char *end = s+20;
	if (!x)
		*-- it = '0';
	while (x)
	{
		*-- it = x%10+'0';
		x /= 10;
	}
	for (; it < end; ++ it)
		putchar(*it);
}

template<class T>
void writeln(T x)
{
	write(x);
	putchar('\n');
}

const int MOD = 1000000007;
const int INF = 100000000;
const int MAXN = 110;
const int MAXV = 500510;
const int K = 3;
const f80 eps = 1e-10;
const f64 alpha = 0.75;

int a[MAXN][MAXN];

int main()
{
	
	int n, d;
	cin >> n >> d;
	for (int i = 0; i < n; ++ i)
		for (int j = 0; j < d; ++ j)
			cin >> a[i][j];
	int ans = 0;
	for (int i = 0; i < n; ++ i)
		for (int j = i+1; j < n; ++ j)
		{
			int r = 0;
			for (int k = 0; k < d; ++ k)
				r += (a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			int t = sqrt(r);
			while ((t+1)*(t+1) <= r) ++ t;
			ans += t*t == r;
		}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <stack>
#include <string>
#include <climits>
#include <algorithm>
#include <functional>
#include <string.h>
#include <numeric>
#include <math.h>

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

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using Graph = vector< vector<int> >;

void sayYes() {cout << "Yes" << endl;}
void sayNo() {cout << "No" << endl;}


bool isSekiDay(int m, int d) {
    int d1, d10;
    d1 = d % 10;
    d10 = d / 10;
    return d1 >= 2 && d10 >= 2 && d1*d10 == m;
}


int main() {
    int M, D; cin >> M >> D;

    int result = 0;
    REP(m, M) {
        REP(d, D) {
            if (isSekiDay(m+1, d+1)) ++result;
        }
    }
    cout << result;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 1e5+5;
const int M = 1e6;
const ll INF = (ll)(1e18);
const int inf = 1e9;
const ll MOD = 1000000007LL;

int solve() {
}

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

    double l;
    cin >> l;
    double ans = pow((l / 3), 3);
    cout << fixed << setprecision(8) << ans;






    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,datetime,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))

def main():
    N = int(input())
    Als = inpl()
    sm = sum(Als)
    dd = [0 for _ in range(10**5+1)]
    for a in Als:
        dd[a] +=1
    Q = int(input())
    order = []
    for _ in range(Q):
        b,c = inpl()
        order.append((b,c))

    for item in order:
        o1 = item[0]
        o2 = item[1]
        count = dd[o1]
        dif = count*(o2 - o1)
        sm += dif
        print(sm)
        dd[o1] = 0
        dd[o2] += count

main()


Measured memory_bytes: 87640
#include <cstdio>
#define SIZE 244140625

int Hash(const char* c)
{
    int Hash = 0;
    while(*c){
        Hash *= 5;
        switch(*c){
        case 'A':
            Hash += 1; break;
        case 'C':
            Hash += 2; break;
        case 'G':
            Hash += 3; break;
        case 'T':
            Hash += 4; break;
        }
        ++c;
    }
    return Hash;
}
int main()
{
    bool* dic = new bool[SIZE];
    int n;
    std::scanf("%d\n", &n);
    char str[21];
    for(int i = 0; i < n; ++i){
        std::gets(str);
        if(str[0] == 'i'){
            dic[Hash(str+7)] = true;
        }else{
            std::puts((dic[Hash(str+5)] ? "yes" : "no"));
        }
    }
    return 0;
 }

Measured memory_bytes: 11916
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> bool chmin(T& a,const T& b) {
  if(a>b) {
    a=b;
    return true;
  }
  return false;
}
template<class T> bool chmax(T& a,const T& b) {
  if(a<b){
    a=b;
    return true;
  }
  return false;
}

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;

int main(){

  int cnt[4]={0};
  REP(i,3){
    int a,b;cin>>a>>b;--a;--b;
    ++cnt[a];++cnt[b];
  }
  REP(i,4) if(cnt[i]==3){
    puts("NO");
    return 0;
  }
  puts("YES");


  return 0;
}





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

namespace atcoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            if (N <= 2)
            {
                Console.WriteLine(0);
                return;
            }

            var list = new List<int>();
            var buffer = Console.ReadLine().Split();
            foreach (var v in buffer)
                list.Add(int.Parse(v));

            int ans = 0;
            for (int i = 0; i < N; i++)
            {
                for (int j = i + 1; j < N; j++)
                {
                    for (int k = j + 1; k < N; k++)
                    {
                        if (list[i] != list[j] &&
                            list[j] != list[k] &&
                            list[i] != list[k])
                        {
                            if (list[i] + list[j] > list[k] && list[j] + list[k] > list[i] && list[k] + list[i] > list[j])
                                ans++;
                        }
                    }
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 27828
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <sstream>
using namespace std;

int main() {
    int p, q;
    while (cin >> p >> q) {
        map<int,int> pos;
        stringstream ss;
        int l, r = -1;
        for (int i=0; ; ++i) {
            if (p % q == 0) {
                break;
            }
            if (pos.count(p % q)) {
                l = pos[p % q];
                r = i-1;
                break;
            }
            pos[p % q] = i;
            p = (p % q) * 10;
            ss << p / q;
        }
        string ans = ss.str();

        cout << ans << endl;
        if (r < 0) continue;

        for (int i=0; i<=r; ++i) {
            if (l <= i) {
                cout << "^";
            } else {
                cout << " ";
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1228
def main():
    H, W, N = map(int, input().split())
    retval = H
    blocks = [tuple(map(int, input().split())) for _ in range(N)]
    blocks.sort(lambda x: (x[0], -x[1]))
    t = 0
    for i in range(N):
        x, y = blocks[i]
        if y <= x-t-1:
            retval = min(retval, x-1)
        elif y == x-t:
            t += 1

    print(retval)


if __name__ == "__main__":
    main()


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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define read            freopen("in.txt","r",stdin)
#define write           freopen("out.txt","w",stdout)
#define loop(i,a,b)     for (ll i = a; i <= b; i++)
#define rloop(i,a,b)    for (ll i = a; i >= b; i--)
#define ms(a,x)         memset(a,x,sizeof a)
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd((a),(b))
#define lcm(a,b)        ((a)*(b))/(gcd(a,b))
#define sq(a)           (a)*(a)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)

ll pow(ll x)
{
    ll sum=1;
    loop(i,1,x) sum*=2;
    return sum;
}
int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        ll n;
        cin>>n;
        ll sum=1,cnt=0;
        while(n!=1)
        {
            n/=2;
            cnt++;
        }
        loop(i,1,cnt)
        {
            sum+=pow(i);
        }
        cout<<sum;
    }
    return 0;
}


Measured memory_bytes: 3612
import sys,heapq
input = sys.stdin.buffer.readline

h,w = map(int,input().split())
cx,cy = map(int,input().split())
dx,dy = map(int,input().split())
cx -= 1
cy -= 1
dx -= 1
dy -= 1

start = cx*w + cy
goal = dx*w + dy


s = []
for _ in range(h):
    s.append(list(input()))

dg = 10**7


edge = [[] for _ in range(h*w)]
for xy in range(h*w):
    x,y = divmod(xy,w)
    if s[x][y] == 35:
        continue
    for i in range(-2,3):
        for j in range(-2,3):
            if i == 0 and j == 0:
                continue
            if 0 <= x+i < h and 0 <= y+j < w and s[x+i][y+j] == 46:
                if (i == 0 and abs(j) == 1) or (j == 0 and abs(i) == 1):
                    edge[xy].append( (x+i)*w + y+j )
                else:
                    edge[xy].append(dg + (x+i)*w + y+j )

d = [10**6]*(h*w)
d[start] = 0

tank = []

for e in edge[start]:
    heapq.heappush(tank,e)


while tank:
    now = heapq.heappop(tank)
    cost,xy = divmod(now,dg)
    if d[xy] != 10**6:
        continue
    d[xy] = cost
    if xy == goal:
        break
    for nxt in edge[xy]:
        if nxt >= dg:
            if d[nxt-dg] == 10**6:
                heapq.heappush(tank,(cost+1)*dg + nxt-dg)
        else:
            if d[nxt] == 10**6:
                heapq.heappush(tank,cost*dg + nxt)

if d[goal] == 10**6:
    print(-1)
else:
    print(d[goal])


Measured memory_bytes: 217580
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

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

template <class InputIterator, class T>
bool contains_itr(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class T>
bool contains_set(set<T> st, const T &value)
{
    if (st.find(value) == st.end())
    {
        return false;
    }
    else
    {
        return true;
    }
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// endは排他的(exclusive)なので注意
vector<ll> range(ll begin, ll end)
{
    vector<ll> result;
    for (ll i = begin; i < end; ++i)
    {
        result.push_back(i);
    }
    return result;
}

// =========ここまでテンプレ============

int main()
{
    ll k;
    string s;
    cin >> k;
    cin >> s;
    if (s.size() <= k)
    {
        cout << s << endl;
    }
    else
    {
        cout << s.substr(0, k) << "..." << endl;
    }
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

using namespace std;




int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int n, x, i;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n >> x;

    int ans = 1, cur = 0;
    for(i = 1; i <= n; i++) {
        int d;
        cin >> d;
        cur += d;
        if(cur <= x) {
            ans++;
        }
    }

    cout << ans;

    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 256
#A
"""
a, b, c = map(int, input().split())
print(min(b//a, c))
"""
#B
"""
a, b, k = map(int, input().split())
for i in range(max(a, b), 0, -1):
    if a % i == 0 and b % i == 0:
        k -= 1
        if k == 0:
             print(i)
"""

#C
"""
s = list(input())
an0 = 0
an1 = 0
for i in s:
    if i == "1":
        an1 += 1
    if i == "0":
        an0 += 1
print(min(an0, an1)*2)
"""

#D

n, m = map(int, input().split())
ab = []
for i in range(m):
    ab.append(list(map(int, input().split())))

ab = ab[-1::-1]
size = [1 for _ in range(n)]
height = [1 for _ in range(n)]
par = [i for i in range(n)]
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
def union(x, y):
    s1 = find(x)
    s2 = find(y)
    if s1 != s2:
        if height[s1] < height[s2]:
            par[s1] = s2
            size[s2] += size[s1]
            size[s1] = 0
        else:
            par[s2] = s1
            size[s1] += size[s2]
            size[s2] = 0
            if height[s1] == height[s2]:
                height[s1] += 1
 

ans = [0 for i in range(m)]
ans[0] = n * (n - 1) // 2
for num, i in enumerate(ab):
    if num == m-1:
        break
    a = i[0] - 1
    b = i[1] - 1
    sizea = size[find(a)]
    sizeb = size[find(b)]
    if find(a) == find(b):
        ans[num + 1] = ans[num]
    else:
        ans[num + 1] = ans[num] - (sizea * sizeb)
    union(a,b)
    
    
ans = ans[-1::-1]
for i in ans:
    print(i)

Measured memory_bytes: 39348
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

// -------------------------------------------------------

map<char, int> isect;
int n;

int main() {
  cin >> n;
  string ss;
  cin >> ss;
  for (auto c : ss) {
    ++isect[c];
  }

  rep(i, 0, n - 1) {
    string s;
    cin >> s;
    map<char, int> mp;
    for (auto c : s) {
      ++mp[c];
    }
    for (auto c : isect) {
      isect[c.first] = min(c.second, mp[c.first]);
    }
  }

  bool isblank = true;
  for (auto e : isect) {
    rep(i, 0, e.second) {
      cout << e.first;
      isblank = false;
    }
  }
  if (isblank) {
    cout << endl;
  }
}


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

int main() {
    int N;
    cin>>N;
    bool ans = false;
    for(int i=1;i<10;++i){
        for(int j=1;j<10;++j){
            if(i*j==N)ans = true;
        }
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split(' '))
a = {}
b = 0
c = 0
for q in range(m):
    p, s = map(str, input().split(' '))
    if p not in a:
        if s == 'AC':
            a[p] = [0, 1]
            b += 1
        else:
            a[p] = [1, 0]
    else:
        if a[p][1] == 1:
            continue
        else:
            if s == 'AC':
                a[p][1] = 1
                b += 1
                c += a[p][0]
            else:
                a[p][0] += 1
print(b, c)

Measured memory_bytes: 25276
#include<bits/stdc++.h>
using namespace std;
using li = long long int;
const int MOD = 1000000007;

int N, K;
li dp[2010][2010] = { 0 };

void make_Comb(int N){
    for(int n = 0; n <= N; n++){
        for(int r = 0; r <= N; r++){
            if(r == 0) dp[n][r] = 1;
            else if(n < r) dp[n][r] = 0;  //r > 0 so including n == 0
            else dp[n][r] = (dp[n-1][r-1] + dp[n-1][r]) % MOD;
        }
    }
    return ;
}

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

    for(int i = 1; i <= K; i++)  cout << (dp[K-1][i-1] * dp[N-K+1][i]) % MOD << endl;
    return 0;
}


Measured memory_bytes: 31616
extern crate core;

use std::io::{self, Read};

#[macro_export]
macro_rules! input {
  ($s:expr=>$($t:tt)*) => {
    let mut lines=$s.split("\n");
    $(
        line_parse!(lines,$t);
    )*
  };
}

macro_rules! line_parse {
  ($lines:expr,($($name:ident:$t:tt)*)) => {
    let mut line=$lines.next().unwrap().split_whitespace();
    $(value_def!(line,$name,$t);)*
  };

  //複数行
  ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
    values_def!($lines,$n,$name,$t);
  };
}

macro_rules! value_def {
  ($line:expr, $name:ident, $t:tt) => {
    let $name = value!($line, $t);
  };
}

macro_rules! values_def {
  ($lines:expr, $n:expr, $name:ident, $t:tt) => {
    let $name = {
      let mut vec = Vec::new();
      for i in 0..$n {
        let mut next = $lines.next().unwrap().split_whitespace();
        vec.push(value!(next, $t));
      }
      vec
    };
  };
}

macro_rules! value {
  //配列
  ($line:expr,[$t:tt]) => {
    $line.map(|x|{
      let mut iter=::std::iter::once(x);
      value!(iter,$t)
    }).collect::<Vec<_>>()
  };
  //タプル
  ($line:expr,($($t:tt),*)) => {
    ($(value!($line,$t),)*)
  };
  //文字列
  ($line:expr,#) => {
    $line.next().unwrap()
  };
  //インデックス(-1)
  ($line:expr,@) => {
    $line.next().unwrap().parse::<usize>().unwrap()-1
  };
  //単一値
  ($line:expr,$t:ty) => {
    $line.next().unwrap().parse::<$t>().unwrap()
  };
}

fn main() {
  let mut input = String::new();
  io::stdin().read_to_string(&mut input).unwrap();
  let output = solve(input.trim().to_string());
  println!("{}", output);
}

fn solve(input: String) -> String {
  input!(input=>(n:usize m:i64){n;list:(i64,i64)});
  let mut list = list;
  list.sort();

  let mut m = m;
  let mut res = 0;
  for (a, b) in list {
    let x = std::cmp::min(b, m);
    m -= x;
    res += x * a;

    if m == 0 {
      break;
    }
  }

  res.to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "2 5\n4 9\n2 4\n" => "12\n",
    test2: "4 30\n6 18\n2 5\n3 10\n7 9\n" => "130\n",
    test3: "1 100000\n1000000000 100000\n" => "100000000000000\n",
}


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

typedef long long ll;
const ll MOD = 1e9 + 7;

//http://tutuz.hateblo.jp/entry/2018/08/12/014351
int main() {
  int n;
  cin >> n;
  
  string s = "";
  while(n != 0) {
    if (n % 2 != 0) {
      n--;
      s += "1";
    } else {
      s += "0";
    }
    n /= -2;
    // cout << n << endl;
  }
  
  reverse(s.begin(), s.end());
  if (s == "") {
    s = '0';
  }
  
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define debugArray(x, n)                                      \
  cerr << __LINE__ << ": " << #x << " = {";                   \
  for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];                   \
  cerr << "}" << '\n'
#define debugMatrix(x, h, w)                                         \
  cerr << __LINE__ << ": " << #x << " =\n";                          \
  for (long long hoge = 0; (hoge) < (long long)(h); ++(hoge)) {      \
    cerr << ((hoge ? " {" : "{{"));                                  \
    for (long long fuga = 0; (fuga) < (long long)(w); ++(fuga))      \
      cerr << ((fuga ? ", " : "")) << x[hoge][fuga];                 \
    cerr << "}" << (hoge + 1 == (long long)(h) ? "}" : ",") << '\n'; \
  }
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#define debugMatrix(x, h, w) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  long long N;
  cin >> N;
  long long ans = N;
  if (N == 1) {
    cout << N << '\n';
    return 0;
  }
  vector<long long> ps;
  for (long long p = 2; p * p <= N; p++) {
    if (N % p == 0) {
      long long pw = 1;
      while (N % p == 0) {
        N /= p;
        pw *= p;
      }
      ps.emplace_back(pw);
    }
  }
  if (N > 1) ps.emplace_back(N);
  if (ps[0] % 2 == 0) ps[0] *= 2;
  long long cnt = ps.size();
  for (long long s = 1; s < (1ll << cnt); s++) {
    vector<long long> r(cnt);
    for (long long i = 0; i < cnt; i++) {
      if ((s >> i) & 1)
        r[i] = ps[i] - 1;
      else
        r[i] = 0;
    }
    auto tmp = crt(r, ps);
    ans = min(ans, tmp.first);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3688
import bisect
x = int(input())

def get_prime(n):
  if n <= 1: return []
  limit = int(n**0.5)
  prime = [2]
  data = [i+1 for i in range(2,n,2)]
  while limit >= data[0]:
    prime.append(data[0])
    data = [j for j in data if j % data[0] != 0]
  return prime + data

l = get_prime(10**5+3)
i = bisect.bisect_right(l, x)
if l[i-1] == x: print(x)
else: print(l[i])

Measured memory_bytes: 5400
#include <iostream>
#include <string>
using namespace std;
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int five = 0;
    if (a == 5) five++;
    if (b == 5) five++;
    if (c == 5) five++;
    int seven = 0;
    if (a == 7) seven++;
    if (b == 7) seven++;
    if (c == 7) seven++;
    if (five == 2 && seven == 1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n;
    string s;
    cin >> n >> s;
    vector<int> l(10);
    for(int i = 0; i < n; i++){
        l[s[i] - '0'] = i;
    }
    vector<vector<bool>> u(10, vector<bool>(10));
    int ans = 0;
    for(int i = 0; i < n; i++){
        int a = s[i] - '0';
        for(int j = i + 1; j < n; j++){
            int b = s[j] - '0';
            if(u[a][b]) continue;
            u[a][b] = true;
            for(int k = 0; k < 10; k++){
                if(l[k] > j){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
ans = 0
Cnt = [[0]*10 for _ in range(10)]
for i in range(1, n+1):
    x, y = int(str(i)[0]), int(str(i)[-1])
    Cnt[x][y] += 1
for i in range(1, 10):
    for j in range(1, 10):
        ans += Cnt[i][j]*Cnt[j][i]
print(ans)


Measured memory_bytes: 40428
#include <cmath>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int n,p,t;
long long pre0,pre1,next0,next1;
int main()
{
	scanf("%d%d",&n,&p);
	pre0=1;
	pre1=0;
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&t);
		
		next1=pre1;
		next0=pre0;
		if(t&1){
			next1+=pre0;
			next0+=pre1;
		}
		else
		{
			next1+=pre1;
			next0+=pre0;
		}
		pre1=next1;
		pre0=next0;
	}
	if(p) cout<<next1;
	else cout<<next0;
	return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << " " << y << " " << z << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repa(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define COUT(x) cout << (x) << endl
#define _GLIBCXX_DEBUG

int main(){
  
  int n;
  cin >> n;
  cout << "ABC" << n << endl;

}

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

public class Main {
    public static void main(String[] args) throws Exception {
        String[] lines = getStdin();
        String[] input = lines[0].split(" ");
        int a = Integer.parseInt(input[0]);
        int b = Integer.parseInt(input[1]);
        int c = Integer.parseInt(input[2]);
        System.out.println(Math.min(c,b/a));
    }
    
    private static String[] getStdin() {
        Scanner scanner = new Scanner(System.in);
        ArrayList<String> lines = new ArrayList<>();
        while (scanner.hasNext()) {
            lines.add(scanner.nextLine());
        }
        return lines.toArray(new String[lines.size()]);
    }
}

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

int main() {
  int n; cin >> n;
  vector<int> price(n);
  for (auto &p : price) cin >> p;
  int ans = accumulate(price.begin(), price.end(), 0);
  ans -= *max_element(price.begin(), price.end()) / 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number, count;
    number = Integer.parseInt(sc.next());
    if(number < 9) {
      count = number;
    } else if(number < 100) {
      count = 9;
    } else if(number < 999) {
      count = 9 + (number - 99);
    } else if(number < 10000) {
      count = 909;
    } else if(number < 99999) {
      count = 9 + 900 + (number - 9999);
    } else {
      count = 90909;
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 23764
<?php
  	$inputArray = array();
	fscanf(STDIN, "%d", $N);
	for ($i = 1; $i <= $N; $i++) {
      fscanf(STDIN, "%s", $S);
      $sArray = str_split($S);
      sort($sArray, SORT_STRING);
      $inputArray[] = implode($sArray);
    }

	sort($inputArray, SORT_STRING);

	$count = 0;
	$result = 0;
	for ($i = 1; $i < count($inputArray); $i++) {
      if ($inputArray[$i] === $inputArray[$i-1]) {
        $count++;
      } else {
        $result += $count * ($count+1) / 2;
        $count = 0;
      }
    }

	$result += $count * ($count+1) / 2;

	echo ($result);
?>

Measured memory_bytes: 28404
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n, a, b;
  cin >> n >> a >> b;
  if(a == n && b == 1){
    vi ans(n);
    iota(ALL(ans), 1);
    print(ans);
  }else if(a == 1 && b == n){
    vi ans(n);
    iota(ALL(ans), 1);
    reverse(ALL(ans));
    print(ans);
  }else if(n >= a+b-1 && n <= a*b){
    vvll x(b, vll(1, 0));
    ll cnt = b;
    rep(i, b){
      rep(j, a-1){
        if(cnt >= n) break;
        x[i].emplace_back(0);
        cnt++;
      }
    }
    ll c = 1;
    repb(i, b){
      rep(j, SZ(x[i])){
        x[i][j] = c;
        c++;
      }
    }
    vll ans;
    rep(i, a){
      rep(j, b){
        if(SZ(x[j]) <= i){
          break;
        }
        ans.emplace_back(x[j][i]);
      }
    }
    print(ans);
  }else{
    print(-1);
  }
}


Measured memory_bytes: 15612
open Scanf
open Printf

let flip f x y = f y x

let read_int () = scanf " %d" (fun x -> x)
let rec read_ints n = if n = 0 then [] else let i = read_int () in i :: read_ints (n-1)

let rec rep n f = if n <= 0 then [] else let x = f () in x :: rep (n-1) f

let check1 hp atks =
  let rec f c hp atks = match atks with
    | [] -> None
    | (a::atks') -> if a >= hp then Some c else f (c+1) (hp-a) atks' in
  f 1 hp atks

let () =
  let n = read_int () in let h = read_int () in
  let xs = rep n (fun () ->
    let a = read_int () in let b = read_int () in (a, b)) in
  let a_max = List.fold_left max 0 (List.map fst xs) in
  let b_use = List.sort (flip (-)) @@ List.filter ((<=) a_max) (List.map snd xs) in
  match check1 h b_use with
  | Some c -> printf "%d\n" c
  | None ->
      let pre_c = List.length b_use in
      let rest = h - List.fold_left (+) 0 b_use in
      printf "%d\n" (pre_c + (rest + a_max - 1) / a_max)


Measured memory_bytes: 18176
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

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

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}


int main() {
  ll i,j,k,n,ans=0;cin>>n;
  string s;
  mat G(n),g(n,vec(n));
  vec color(n,-1);
  rep(i,n){
    cin>>s;
    rep(j,n){
      g[i][j]=(s[j]=='1')?1:inf;
      if(g[i][j]==1){
        G[i].pb(j);
      }
    }
    g[i][i]=0;
  }
  color[0]=0;
  queue<datas> que;
  for(auto i:G[0]){
    que.push(datas(i,1));
  }
  while(!que.empty()){
    auto x=que.front();que.pop();
    if(color[x.first]!=-1){
      if(color[x.first]!=x.second){
        cout<<-1<<endl;
        return 0;
      }
      continue;
    }
    color[x.first]=x.second;
    for(auto i:G[x.first]){
      if(color[i]!=-1){
        if(color[i]==x.second){
          cout<<-1<<endl;
          return 0;
        }
      }else{
        que.push(datas(i,1-x.second));
      }
    }
  }
  rep(k,n){
    rep(i,n){
      rep(j,n){
        g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
      }
    }
  }
  rep(i,n){
    ll res=*max_element(all(g[i]));
    ans=max(res,ans);
  }
  cout<<ans+1<<endl;
  return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 2000000000;
constexpr auto MOD = 1000000007;

int main() {
	int h, w;
	cin >> h >> w;
	vvi a(h, vi(w));
	rep(i, h)rep(j, w) cin >> a[i][j];

	rep(i, h) if (i % 2)reverse(all(a[i]));

	vi y = {};
	vi x = {};
	vi yy = {};
	vi xx = {};


	rep(i, h)rep(j, w) {

		if (i == h - 1 && j == w - 1)continue;

		int ni, nj;
		if (j == w - 1) {
			ni = i + 1;
			nj = 0;
		}
		else {
			ni = i;
			nj = j + 1;
		}

		if (a[i][j] % 2) {

			y.push_back(i + 1);
			yy.push_back(ni + 1);

			if (i % 2)x.push_back(w - j);
			else x.push_back(j + 1);

			if (ni % 2)xx.push_back(w - nj);
			else	xx.push_back(nj + 1);

			a[ni][nj]++;
		}
	}

	cout << y.size() << endl;
	rep(i, y.size()) cout << y[i] << " " << x[i] << " " << yy[i] << " " << xx[i] << endl;
}

Measured memory_bytes: 5224
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
firstMax = max(a)
minVal = min(a)
secondMax = max(map(lambda x:x if x != firstMax else minVal, a)) if len(str(a).split(str(firstMax))) == 2 else firstMax
for i in range(len(a)):
    if a[i] < firstMax:
        print(firstMax)
    else:
        print(secondMax)

Measured memory_bytes: 25284
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << "debug "<<i << std::endl;

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  std::string a;
  std::cin>>a;

  ll n=a.size(),ans=n*(n-1)/2;

  std::vector<ll> count(26,0);

  rep(i,0,n)count[a[i]-'a']++;

  rep(i,0,26){
    ans-=count[i]*(count[i]-1)/2;
  }

  ans++;

  std::cout<<ans;

  return 0;
}


Measured memory_bytes: 720
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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 (b < a) { a = b; return 1; } return 0; }

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n;
	cin >> n;
	vector<ll> a(n + 1), b(n);
	ll sum = 0;
	rep(i, n+1)
	{
		cin >> a[i];
	}
	rep(i, n)
	{
		cin >> b[i];
	}

	rep(i,n)
	{
		if (b[i] >= a[i])
		{
			b[i] -= a[i];
			sum += a[i];
			a[i] = 0;
			if (a[i + 1] <= b[i])
			{
				sum += a[i+1];
				a[i + 1] = 0;
			}
			else
			{
				sum += b[i];
				a[i + 1] -= b[i];
			}
		}
		else
		{
			sum += b[i];
			a[i] -= b[i];
		}
	}
	cout << sum << endl;

	debug;

	return 0;
}

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

int main(){

	int n;
	cin >> n;

	vector<int> a(n+1),b(n);

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

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

	long long yoryoku = 0,cnt = 0;

	for ( int i = 0; i < n; i++){
		if ( a[i] >= yoryoku ){
			cnt += yoryoku;
            a[i] -= yoryoku;
			yoryoku = 0;		
		}else{
			cnt += a[i];
			yoryoku = 0;
			a[i] = 0;
		}
		if ( a[i] == 0 ){
			yoryoku = b[i];
			continue;
		}
		if ( a[i] >= b[i] ){
			cnt += b[i];
			yoryoku = 0;
		}else{
			cnt += a[i];
			yoryoku = b[i] - a[i];
		}
	}

	
	if ( a[n] >= yoryoku ){
		cnt += yoryoku;
	}else{
		cnt += a[n];
	}
		
	cout << cnt << endl;

	return 0;

}


Measured memory_bytes: 4036
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;


void solve(std::string T){
	for(int i=0;i<T.size();i++){
		if (T[i]=='?'){
			T[i]='D';
		}
	}
	cout << T << endl;

}

int main(){
    std::string T;
    std::cin >> T;
    solve(T);
    return 0;
}


Measured memory_bytes: 3484
#include <iostream>

using namespace std;

int main()
{
   int A,B,C,D;
   cin>>A>>B>>C>>D;
   int rec1,rec2;
   rec1=A*B;
   rec2=C*D;
   if(rec1>rec2){
       cout<<rec1<<endl;
   }
   else{
       cout<<rec2<<endl;
   }
   
   return 0;
}

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

using namespace std;

#define int long long

#define q first.first
#define x first.second
#define s second.first
#define t second.second

vector<int> A, B;
vector<pair<pair<int,int>,pair<int,int>>> query;
int N, Q, L, R;

int check(int num){
	if(num < 0) return (int)(1ull<<63);
	if(num >= N) return (int)(~(1ull<<63));
	
	int v = A[num];
	
	for(int i = 0; i < Q; i++){
		if(query[i].q == 1){
			if(query[i].x <= v){
				v = query[i].t*(query[i].s+v);
			}
		} else if(query[i].q == 2){
			if(query[i].x >= v){
				v = (v-query[i].s)/query[i].t;
			}
			
		}
		// cout<<"v = "<<v<<endl;
	}
	
	return v;
}

signed main(){

	int al, ar;
	// cout<<(int)(1ull<<63)<<endl;
	// cout<<(int)(~(1ull<<63))<<endl;
	// cout<<(int)(-2.8)<<endl;
	// cout<<(int)(-3/2)<<endl;
	
	cin>>N>>Q>>L>>R;
	
	A.assign(N, 0);
	query.assign(Q, {});
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
	}
	
	B = A;
	
	sort(A.begin(), A.end());
	A.erase(unique(A.begin(), A.end()), A.end());
	
	// for(){
	// }
	for(int i = 0; i < Q; i++){
		
		cin>>query[i].q>>query[i].x>>query[i].s>>query[i].t;
	}
	
	// for(int i = 0; i < N; i++){
		// cout<<"i = "<<i<<" "<<check(i)<<endl;
	// }
	N = A.size();
	
	int l = -1, r = N+1, m;
	
	while(l + 1 < r){
		m = (l+r)/2;
		
		// cout<<l<<" "<<m<<" "<<r<<endl;
		// string hogehoge;
		// cin>>hogehoge;
		
		if(check(m) > R){
			r = m;
		} else {
			l = m;
		}
	}
	
	ar = l;
	
	l = -1, r = N+1, m;
	
	while(l + 1 < r){
		m = (l+r)/2;
		
		if(check(m) >= L){
			r = m;
		} else {
			l = m;
		}
	}
	
	al = r;
	
	// cout<<ar-al<<endl;
	
	int con = 0;
	
	//cout<<"N = "<<N<<endl;
	for(int i = 0; i < B.size(); i++){// cout<<i<<endl;
		//cout<<ar<<" "<<al<<endl;
		
		if(ar == -1 || al == N){ //cout<<"D"<<endl;
		} else if(ar == N && al == -1){ cout<<"A"<<endl;
			con++;
		} else if(A[al] <= B[i] && ar == N){ //cout<<"B"<<endl;
			con++;
		} else if(al == -1 && B[i] <= A[ar]){ //cout<<"C"<<endl;
			con++;
		} else if(A[al] <= B[i] && B[i] <= A[ar]){
			//cout<<A[al]<<" <= "<<B[i]<<" <= "<<A[ar]<<endl;
			con++;
		} else {
			//cout<<"E"<<endl;
			//cout<<A[al]<<" <= "<<B[i]<<" <= "<<A[ar]<<endl;
		}
	}
	cout<<con<<endl;
	return 0;
}


Measured memory_bytes: 12028
p = input().split()

a = int(p[0])
b = int(p[1])
c = int(p[2])

if a > b:
    a, b = b, a
else:
    pass

if b > c:
    b, c = c, b
else:
    pass

if a > b:
    a, b = b, a
else:
    pass

print(a, b, c)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int iinf = 1 << 28;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;

void work() {
    int A,B; cin>>A>>B;
    for (int i = 10*B; i < 10*B + 10; ++i) {
        int x = (8*i) / 100;
        if (x >= A && x < A + 1) {
            cout << i << endl;
            return;
        }
    }
    cout << "-1" << endl;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    work();
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define FOR(i,k,n) for(int (i) = (k); (i) < (n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x,y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template<class T> using vv=vector<vector<T>>;
typedef deque<int> di;
typedef deque<deque<int>> ddi;


int main() {
    while(1){
        int N;
        cin >> N;
        if(N == 0) {
            break;
        }
        int sum = 0;
        FOR(i, 2, sqrt(N * 2)){
            if(i % 2 ==1) {
                if(N % i == 0) {
                    sum++;
                }
            } else {
                if (2 * N % i == 0 && N % i != 0 ) {
                        sum++;
                }
            }
        }

        cout << sum << endl;
    }
	return 0;
}

Measured memory_bytes: 3084