akhauriyash/Code-Regression huggingface dataset:
class ProcessQueue:
    def __init__(self, N):
        self.MAX = N + 1
        self.Q = [(None, None)] * self.MAX
        self.head = 0
        self.tail = 0

    def isEmpty(self):
        return self.head == self.tail

    def enqueue(self, p):
        self.Q[self.tail] = p
        self.tail += 1
        if self.tail == self.MAX:
            self.tail = 0

    def dequeue(self):
        self.head += 1
        if self.head == self.MAX:
            self.head = 0

        return self.Q[self.head - 1]


N, Q = (int(n) for n in input().split())
processes = ProcessQueue(N)
for i in range(N):
    process = input().split()
    processes.enqueue((process[0], int(process[1])))

time = 0
while not processes.isEmpty():
    process = processes.dequeue()
    if process[1] - Q <= 0:
        time += process[1]
        print(process[0], time)
    else:
        time += Q
        processes.enqueue((process[0], process[1] - Q))



Measured memory_bytes: 13356
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cctype>
#include <iostream>
#include <set>
#include <string>
#include <queue>
#include <map>
using namespace std;
int size(string x){
	string::size_type size=x.size();
	return size;
}
#define fu(l,k) for(int i=l;i<k;i++)
#define fd(l,k) for(int i=l;i>k;i--)
#define fi first
#define se second
typedef  vector<string> vs;
typedef  vector<int> vi;
double pi(){
	return M_PI;
}
typedef set<int> set_i;
typedef set<string> set_s;
int main(){
	int n,ans;
	while(cin>>n){
		ans=0;
		int a=600/n;
		fu(0,a){
			ans+=i*n*n*i*n;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill( (T*)array, (T*)(array+N), val ); }
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9+7
int main() {
    int x,n;
    cin>>x>>n;
    vector<int> p(n);
    REP(i,n){
        cin>>p[i];
    }
    vector<int>::iterator it;
    int ans;
    REP(i,100){
        it=find(all(p),x-i);
        if(it==p.end()){
            ans=x-i;
            break;
        }
        it=find(all(p),x+i);
        if(it==p.end()){
            ans=x+i;
            break;
        }
    }
    if(n==0)ans=x;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3608
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String input = sc.next().replace(",", " ");

        System.out.println(input);
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }
}


Measured memory_bytes: 21716
import sys
input = sys.stdin.readline


class SegTree:
    def __init__(self, size):
        n = 1
        while n < size:
            n *= 2
        self.size = n
        self.data = [0] * (n*2)

    # change the i-th value from a to b
    def update(self, i, a, b):
        i += self.size - 1
        if a >= 0:
            self.data[i] &= ~(1 << a)
        self.data[i] |= 1 << b
        while i > 0:
            i = (i - 1) // 2
            self.data[i] = self.data[i*2+1] | self.data[i*2+2]

    def query(self, a, b):
        return self._query(a, b, 0, 0, self.size)

    def _query(self, a, b, k, l, r):
        if r <= a or b <= l:
            return 0
        if a <= l and r <= b:
            return self.data[k]
        vl = self._query(a, b, k*2+1, l, (l+r)//2)
        vr = self._query(a, b, k*2+2, (l+r)//2, r)
        return vl | vr


N = int(input())
S = list(input().rstrip())
st = SegTree(N)
for i in range(N):
    st.update(i, -1, ord(S[i])-ord('a'))
Q = int(input())
for _ in range(Q):
    t, x, y = input().split()
    if t == '1':
        i = int(x) - 1
        c = y
        st.update(i, ord(S[i])-ord('a'), ord(c)-ord('a'))
        S[i] = c
    else:
        l = int(x) - 1
        r = int(y) - 1
        ans = 0
        bit = st.query(l, r+1)
        for i in range(26):
            ans += (bit >> i) & 1
        print(ans)


Measured memory_bytes: 118568
n = int(input())
a = list(map(int, input().split()))
q = int(input())

count = [0] * (10 ** 5 + 1)
for i in a:
    count[i] += 1

a_sum = sum(a)
for i in range(q):
    b, c = map(int, input().split())
    a_sum += (c - b) * count[b]
    count[c] += count[b]
    count[b] = 0
    print(a_sum)

Measured memory_bytes: 84680
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX  999999
int main(){
    while(true){
    int ans = 0;
    vvi v(100, vi (100 ,INF));
    vc c(100,0);vi d(100,0);
    vi x(100,0); vi y(100,0);
        int m ;cin >>m; if(!m) break;
        int tempx = 10,tempy = 10;rep(i,m){cin >> x[i] >> y[i];v[y[i]][x[i]] = 0;}
    int n; cin >> n; rep(i,n) {cin >> c[i] >> d[i];
        if(c[i] == 'N'){
            for(int k =1;k<=d[i];k++)if(v[tempy+k][tempx] == 0){ans++;v[tempy+k][tempx] =INF;}tempy+=d[i];
        }
        if(c[i] == 'E'){
            for(int k =1;k<=d[i];k++)if(v[tempy][tempx+k] == 0) {ans++;v[tempy][tempx+k] = INF;} tempx+=d[i];
        }
        if(c[i] == 'S'){
            for(int k =1;k<=d[i];k++)if(v[tempy-(k)][tempx] == 0){ans++;v[tempy-k][tempx] = INF;}tempy-=d[i];

        }
        if(c[i] == 'W'){
            for(int k =1;k<=d[i];k++)if(v[tempy][tempx-k] == 0){ans++;v[tempy][tempx-k] = INF;}tempx-=d[i];

        }
    }
        if(ans == m)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;

    }
}

Measured memory_bytes: 3204
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <string.h>
using namespace std;

int main()
{
    char s[22];
    cin >> s;
    string ans;
    for (int i = 0; i < strlen(s); i++)
    {
        if (s[i] == '0')
            ans += '0';
        if (s[i] == '1')
            ans += '1';
        if (s[i] == 'B' && ans.length() > 0)
            ans.pop_back();
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String s = "";
		ArrayList<Integer> list = new ArrayList<Integer>();

		for(int i = 0;i < 4;i++) {
			list.add(0);
		}

		for(int i = 0;i < n;i++) {
			s = scan.next();

			if(s.equals("AC")) {
				list.set(0 , list.get(0) + 1);
			}else if(s.equals("WA")) {
				list.set(1 , list.get(1) + 1);
			}else if(s.equals("TLE")) {
				list.set(2 , list.get(2) + 1);
			}else {
				list.set(3 , list.get(3) + 1);
			}
		}

		System.out.println("AC x " + list.get(0));
		System.out.println("WA x " + list.get(1));
		System.out.println("TLE x " + list.get(2));
		System.out.println("RE x " + list.get(3));
	}
}


Measured memory_bytes: 58256
#include <iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n==1) cout<<"1";
	if(n==2) cout<<"2";
	if(n>2&&n<4) cout<<"2";
	if(n>=4&&n<8) cout<<"4";
	if(n>=8&&n<16) cout<<"8";
	if(n>=16&&n<32) cout<<"16";
	if(n>=32&&n<64) cout<<"32";
	if(n>=64) cout<<"64";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n;i>s;i--)
#define repe_r(i,s,n)for(ll i=n;i>=s;i--)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = (ll)1 << 62;

//////////////////////////////////////////
////the sieves of eratosthenes ///////////
//////////////////////////////////////////
static const ll prime_max = 1e7;
bool p[prime_max] = {};
void eratosthenes() {
	rep(i, 2, prime_max) p[i] = true;
	rep(i, 2, prime_max) {
		if (p[i]) {
			rep(j, 2, prime_max) {
				if (j*i >= prime_max)break;
				p[j*i] = false;
			}
		}
	}
}
map<ll, ll> factor;
void factorization(ll x) {
	ll n = x;
	rep(i, 0, prime_max) {
		while (p[i] && n != 0 && !(n % i)) {
			n /= i;
			factor[i]++;
		};
	}
}

int main() {
	ll n, p; cin >> n >> p;
	if (n == 1) {
		cout << p << endl;
		return 0;
	}

	eratosthenes();
	factorization(p);

	ll ans = 1;

	for (map<ll, ll>::iterator it = factor.begin(); it != factor.end(); it++) {
		if (it->second >= n) {
			rep(k, 0, it->second / n) {
				ans *= it->first;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9984
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,(n))
#define clr(a) memset(a, 0, sizeof(a))
#define Sort(a, len, cmp) sort(a + 1, a + len + 1, cmp)
#define ass(a, sum) memset(a, sum, sizeof(a))

#define ls ((rt) << 1)
#define rs ((rt) << 1 | 1)
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
#define ENDL cout << endl
#define SZ(x) ((int)x.size())

typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi ;
typedef pair <int, int> pii ;
typedef pair <ll, ll> pll ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
typedef map <ll, ll> mll ;

const int N = 100010 ;
const double eps = 1e-8 ;
const int iinf = INT_MAX ;
const ll linf = 2e18 ;
const double dinf = 1e30 ;
const int MOD = 1000000007 ;

inline int read(){
    int X = 0, w = 0 ;
	char ch = 0 ;
    while (!isdigit(ch)) { w |= ch == '-' ; ch = getchar() ; }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar() ;
    return w ? - X : X ;
}

void write(int x){
     if (x < 0) putchar('-'), x = - x ;
     if (x > 9) write(x / 10) ;
     putchar(x % 10 + '0') ;
}

void print(int x) {
	cout << x << endl ;
	exit(0) ;
}

void PRINT(string x) {
	cout << x << endl ;
	exit(0) ;
}

void douout(double x){
	 printf("%lf\n", x + 0.0000000001) ;
}

int n, e[101], ans;

int num(int x) {
    int ret = 0;
    rep(i, n+1) {
        if (e[i] >= x - 1) ret++;
    }
    return ret;
}

int main() {
    cin >> n;
    REP(i, 1, n + 1) {
        int cur = i;
        REP(j, 2, i + 1) {
            while (cur % j == 0) {
                e[j]++;
                cur /= j;
            }
        }
    }

    cout << num(75) + num(25) * (num(3) - 1) + num(15) * (num(5) - 1)
        + num(5) * (num(5) - 1) / 2 * (num(3) - 2) << endl;

    return 0;
}

/*
写代码时请注意：
	1.是否要开Long Long？数组边界处理好了么？
	2.实数精度有没有处理？
	3.特殊情况处理好了么？
	4.做一些总比不做好。
思考提醒：
	1.最大值和最小值问题可不可以用二分答案？
	2.有没有贪心策略？否则能不能dp？
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h, w, i;
  string s;
  cin >> h >> w;
  
  string header(w + 2, '#');
  cout << header << endl;
  for(i=0; i<h; i++){
    cin >> s;
    s.insert(0, "#");
    s.insert(w+1, "#");
    cout << s << endl;
  }
  cout << header << endl;

  return 0;
}

Measured memory_bytes: 3556
h, w, n = map(int, input().split())
xy = sorted([list(map(int, input().split())) for _ in range(n)])
dx = 0
dy = 0
for x, y in xy:
  x -= dx
  y -= dy
  if x == y:
    dx += x-1
    dy += y-2
  elif y < x:
    print(dx+x-1)
    break
else:
  print(h)

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

int main(){
   
    int N;
    cin>>N;
    vector<int> S(N,0);
    for(int i=0;i<N;i++){
        cin>>S[i];
    }
    sort(S.begin(),S.end());
    long long int sum=0;
    if(N%2==0){
    for(int i=0;i<N;i+=2){
        if(S[i]+S[i+1]<=0){
            sum+=(-S[i]-S[i+1]);
        }
        else sum+=(S[i]+S[i+1]);
    }
    }
    else{
        for(int i=0;i<N-1;i+=2){
            if(S[i]+S[i+1]<=0){
                sum+=(-S[i]-S[i+1]);
            }
            else sum+=(S[i]+S[i+1]);
        }
        sum+=S[N-1];
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 640
from itertools import combinations
s = input()
ans = int(s)
li = [combinations([i for i in range(1,len(s))],j) for j in range(1,len(s)+1)]
for i in range(len(s)):
  for v in li[i]:
    tmp = []
    u = 0
    for j in v:
      tmp.append(int(s[u:j]))
      u = j
    tmp.append(int(s[u:]))
    ans += sum(tmp)
print(ans)
    

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>


using namespace std;


int main() {
	int K;
	vector<int> abc;
	abc.resize(3);


	cin >> abc[0] >> abc[1] >> abc[2] >> K;
	sort(abc.begin(), abc.end(), greater<int>());

	for (int i = 0; i < K; i++) {
		abc[0] *= 2;
	}
	int result = 0;
	for (int i = 0; i < 3; i++) {
		result += abc[i];
	}
	cout << result << endl;

	return 0;
}

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

point = [[0] * 2 for _ in range(40)]

for i in range(40):
    tmp = 0
    for a in a_list:
        if (a >> (39 - i)) & 1:
            tmp += 1
    # 上位からiビット目が 0 のときに得られる値
    point[i][0] = tmp * 2 ** (39 - i)
    # 上位からiビット目が 1 のときに得られる値
    point[i][1] = (N - tmp) * 2 ** (39 - i)


dp = [[-float("inf")] * 2 for _ in range(41)]
dp[0][0] = 0

# 上位ビットから決めていったときの暫定値
# dpの2つ目の添字は0のときKに忠実に合わせていく。
# 1のときはKより小さいことがわかっている
for i in range(40):
    x = (K >> (39 - i)) & 1

    # 忠実にKに合わせていく
    dp[i + 1][0] = dp[i][0] + point[i][x]

    # すでにKよりも小さいことがわかっているのでずっとこの遷移をとる
    # 0と１のどちらを選んでも良い
    dp[i + 1][1] = dp[i][1] + max(point[i][0], point[i][1])

    # K の上位iビット目が1のときKに忠実な遷移から小さい遷移(0を選ぶ)に移れる。
    # それが最適とは限らない
    if x == 1:
        dp[i + 1][1] = max(dp[i][0] + point[i][0], dp[i + 1][1])
print(max(dp[40]))


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

struct P
{
    int x,y;

    bool operator<(const P &a)const{
              return x>a.x;
    }

};

vector<int> v[10];
//bitset<4001000> b;
int a,c,i,b,n,m,k,d;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int o[110];
int l[10];
int j[10];
int e;
int dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long x,y,mod=1000000007;
long long z;
double pi=3.14159265;
P u[2];
stack<int> s;

//set<int> s;
queue<int> q;

//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p,p1;
//list<int> l;

string r;
//char r[133];
//deque<int> de;
bool as(P a,P b)
{
    return a.y*b.x<b.y*a.x;
}

long long f(long long a,long long b)
{
    for(;b;)
    {
        long long i=a;
        a=b;
        b=i%b;
    }
    return a;
}

int main()
{
    scanf("%d",&e);
    for(int t=1;t<=e;t++)
    {
        long long a,b,c,d;
        scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
        if(a<b)
        {
            puts("No");
            goto qwe;
        }

        if(d<b)
        {
            puts("No");
            goto qwe;
        }
        if(d==b)
        {
            a%=b;
            if(c<=a&&a<b)
                puts("No");
            else puts("Yes");
            goto qwe;
        }
        //a%=b;
        if(c>=b)
        {
            puts("Yes");
            goto qwe;
        }
        a%=b;
        if(a>c)
        {
            puts("No");
            goto qwe;
        }
        if(c-a<f(b,d)&&f(b,d)<b-a)
        {
            puts("No");
            goto qwe;
        }
        if(((c-a)+f(b,d))/f(b,d)*f(b,d)<b-a)
        {
            puts("No");
            goto qwe;
        }
        else puts("Yes");
        qwe:;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
char p[3][3][4];
char pz[9][4];
 
bool check(char a,char b){
    return (a-32 == b || b-32 == a);
}
 
int rec(int now,int S){
    if(now == 9) return 1;
    int res = 0;
    int X = now%3, Y = now/3;
    for(int s = 0 ; s < 9 ; s++){
        if(S >> s & 1) continue;
        for(int i = 0 ; i < 4 ; i++){
            for(int j = 0 ; j < 4 ; j++){
                p[Y][X][j] = pz[s][(i+j)%4];
            }
            bool can = true;    
            if(X > 0 && !check(p[Y][X][0],p[Y][X-1][2])){
                can = false;
            }
            if(Y > 0 && !check(p[Y][X][1],p[Y-1][X][3])){
                can = false;            
            }
            if(can) res += rec(now+1,S|(1<<s));
        }
    }
    return res;
}
 
int main(){
    int Tc;
    cin >> Tc;
    while(Tc--){
        for(int i = 0 ; i < 9 ; i++){
            for(int j = 0 ; j < 4 ; j++){
                cin >> pz[i][j];
            }
        }
        cout << rec(0,0) << endl;
    }
    return 0;
}

Measured memory_bytes: 3004
#include<bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
vector<string>v;
void dfs(string str,string t="",int cnt=0){
    if(cnt==2){
        v.push_back(t);
        return;
    }else{
        for(int i=0;i<str.size();i++){
            dfs(str,t+str[i],cnt+1);
        }
    }
}
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a[3];
    for(int i=0;i<3;i++){
        cin>>a[i];
    }
    sort(a,a+3);
    cout<<a[2]-a[1]+(a[1]-a[0])<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define len(x) (int) (x.size())
using namespace std;
typedef long long ll;

int main(){
    queue<ll> lunlun_numbers({1, 2, 3, 4, 5, 6, 7, 8, 9});
    int k;
    cin >> k;
    for(int i = 0; i < k-1; i++) {
        ll x = lunlun_numbers.front();
        lunlun_numbers.pop();

        if(x % 10 != 0) {
            lunlun_numbers.push(10*x+(x%10)-1);
        }
        lunlun_numbers.push(10*x+(x%10));
        if(x % 10 != 9) {
            lunlun_numbers.push(10*x+(x%10)+1);
        }
    }
    cout << lunlun_numbers.front() << '\n';

    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int cnt = 0;
    bool check = true;
    while (check) {
        for (int i = 0; i < N; i++) {
            if (A[i] % 2 != 0) {
                check = false;
                break;
            }
            A[i] /= 2;
        }
        if (check) {
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output14.txt", "w", stdout);
#endif
	//ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, W;
	cin >> n >> W;
	long long w[n], p[n];
	for (int i = 0; i < n; i++)
		cin >> w[i] >> p[i];
	vector<vector<long long>> dp(n + 1, vector<long long> (W + 1, 0));
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= W; j++)
		{
			if (w[i - 1] <= j)
			{
				//cout << dp[i - 1][j - w[i - 1]] << "\n";
				dp[i][j] = max(dp[i - 1][j], p[i - 1] + dp[i - 1][j - w[i - 1]]);
			}
			else
				dp[i][j] = dp[i - 1][j];
			///cout << dp[i][j] << "\n";
		}

	}
	cout << dp[n][W] << "\n";
//cout << "\n";
}

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

using namespace std;

typedef long long LL;
#define N 420

const LL mod=998244353;
LL n,m,p,im,ans,a[N],b[N],f[N][N],F[N][N],C[N][N],g[N],poly[N];

void upd(LL &x,LL y){x=(x+y%mod+mod)%mod;}

LL fh(LL x){return x&1?-1:1;}

LL inv(LL x){return x==1?1:(mod-mod/x)*inv(mod%x)%mod;}

LL pw(LL x,LL k){
	if (!k) return 1;
	LL tmp=pw(x*x%mod,k>>1);
	return k&1?tmp*x%mod:tmp;
}

int main(){
	scanf("%lld",&n);
	for (LL i=1;i<=n;++i){
		scanf("%lld%lld",a+i,b+i);
		m+=a[i]; p+=b[i];
	}
	im=inv(m);
	for (LL i=0;i<=400;++i){
		C[i][0]=1;
		for (LL j=1;j<=400;++j)
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
	}
	f[0][0]=-1;
	for (LL i=1;i<=n;++i){
		memcpy(F,f,sizeof F);
		for (LL j=a[i];j<=m;++j)
			for (LL k=0;k<=p;++k)
				for (LL l=0,tmp=1;l<b[i]&&l<=k;++l){
					upd(F[j][k],f[j-a[i]][k-l]*tmp%mod*-C[k][l]);
					tmp=tmp*a[i]%mod*im%mod;
				}
		memcpy(f,F,sizeof f);
	}
	for (LL i=1;i<m;++i){
		LL w=(m-i+mod)*im%mod;
		g[0]=inv((1-w+mod)%mod);
		for (LL j=1;j<=p;++j){
			g[j]=0;
			for (LL k=0;k<j;++k) upd(g[j],(g[k]-(k==0))*C[j][k]*fh(j-k+1));
			g[j]=g[j]*inv((1-w+mod)%mod)%mod;
		}
		poly[0]=1;
		LL ifac=1;
		for (LL j=0;j<=p;++j){
			LL w=(m-i+mod)*im%mod;
			LL tmp=f[i][j]*inv(pw(w,j))%mod;
			for (LL k=0;k<=j;++k)
				upd(ans,tmp*g[k]%mod*poly[k]%mod*ifac);
			poly[j+1]=0;
			for (LL k=j;~k;--k){
				upd(poly[k+1],poly[k]);
				poly[k]=poly[k]*-j%mod;
			}
			ifac=ifac*inv(j+1)%mod;
		}
	}
	for (LL i=0;i<=p;++i) upd(ans,f[m][i]);
	printf("%lld\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 4352
#include<stdio.h>
#define MAX 500000

void maxHeapify(int *Heap,int i,int H){
  int l=2*i;
  int r=2*i+1;
  int largest;
  int tmp;

  if(l<=H && Heap[l]>Heap[i]) largest=l;
  else largest=i;
  if(r<=H && Heap[r]>Heap[largest]) largest = r;
  if(largest!=i){
    tmp=Heap[i];
    Heap[i]=Heap[largest];
    Heap[largest]=tmp;
    maxHeapify(Heap,largest,H);
  }
}
void buildMaxHeap(int *Heap,int H){
  int i;
  for(i=H/2;i>=1;i--)
    maxHeapify(Heap,i,H);
}
void print(int *Heap,int H){
  int i;
  for(i=1;i<=H;i++)printf(" %d",Heap[i]);
  printf("\n");
}
  
int main(){
  int n,i;
  int Heap[MAX];
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d",&Heap[i]);
  buildMaxHeap(Heap,n);
  print(Heap,n);
  return 0;
}

Measured memory_bytes: 2552
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++) 
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;
 
int main() {
	int X,Y;
	cin >> X >> Y;
  cout << X + Y/2 << endl;
}

Measured memory_bytes: 256
let () =
    let split s =
        let rec loop i cur flag acc =
            if i = String.length s then ( if flag then cur :: acc else acc) else (
                match flag, s.[i] with
                | true,  ' ' -> loop (i + 1) "" false (cur :: acc)
                | false, ' ' -> loop (i + 1) "" false acc
                | true,  v   -> loop (i + 1) (Printf.sprintf "%s%c" cur v) true acc
                | false, v   -> loop (i + 1) (Printf.sprintf "%s%c" cur v) true acc
            )
        in
        List.map int_of_string (List.rev (loop 0 "" false []))
    in
    let main () =
        let n = int_of_string (read_line ()) in
        let b = Array.of_list (split (read_line ())) in
        let r = Array.make n 0 in
        r.(0) <- b.(0);
        r.(n - 1) <- b.(n - 2);
        for i = 0 to n - 3 do
            r.(i + 1) <- min b.(i) b.(i + 1)
        done;
        Printf.printf "%d\n" (Array.fold_left (+) 0 r)
    in
    main ()

Measured memory_bytes: 640
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=200005;
#define y1 kuhgahbidlawslgfuhhfiuhs

int N,M,x1,y1,x2,y2;
pair<int,int> P[MAXN];
int dp[MAXN];

int main()
{
	scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&N);
	for(int i=1;i<=N;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		if(min(x1,x2)<=x&&x<=max(x1,x2)&&min(y1,y2)<=y&&y<=max(y1,y2))
			P[++M]=make_pair(x,y);
	}
	if(x1>x2)
	{
		swap(x1,x2);
		swap(y1,y2);
	}
	if(y1>y2)
	{
		for(int i=1;i<=M;i++)
			P[i].second=y2+y1-P[i].second;
		swap(y1,y2);
	}
	
	sort(P+1,P+M+1);
	memset(dp,0x3F,sizeof dp);
	dp[0]=-1;
	int lis=0;
	for(int i=1;i<=M;i++)
	{
		int j=upper_bound(dp,dp+M+1,P[i].second)-dp;
		dp[j]=min(dp[j],P[i].second);
		lis=max(lis,j);
	}
	double ans=0;
	ans=100.0*(x2-x1+y2-y1)-20.0*lis+5.0*lis*acos(-1);
	if(lis==min(y2-y1+1,x2-x1+1))
		ans+=5.0*acos(-1);
	printf("%.15lf\n",ans);
	
	return 0;
}


Measured memory_bytes: 2560
// B - 文字列大好きいろはちゃんイージー
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, L, w, ans = 0, count = 0;
  string t;
  vector<pair<string, pair<lli, lli>>> pr;
  cin >> n >> L;
  vs s(n);
  rep(i, 0, n)
  {
    cin >> s[i];
  }
  SORT(s);
  rep(i, 0, n)
  {
    t += s[i];
  }
  cout << t << endl;
}

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

int main() {
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;

    s[k-1] = s[k-1] + ('a' - 'A');
    cout << s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

vector<pair<int,ll>> G[100005];
int color[100005];

void solve(int idx){
  int c = color[idx];
  rep(i,G[idx].size()){
    int x = G[idx][i].first;
    ll w = G[idx][i].second;

    if(color[x] >= 0) continue;
    
    if(w%2==0){
      color[x] = c;
      solve(x);
    }else{
      color[x] = 1-c;
      solve(x);
    }
  }
}

int main(){
  int N;
  cin >> N;
  rep(i,100005) color[i] = -1;

  int ca, cb;
  ll cc = -1;
  rep(i,N-1){
    int a, b;
    ll c;
    cin >> a >> b >> c;
    G[a].emplace_back(b,c);
    G[b].emplace_back(a,c);
    if(c%2 == 0){
      ca = a;
      cb = b;
      cc = c;
    }
  }

  if(cc == -1){
    color[1] = 0;
    solve(1);
  }else{
    color[ca] = 0;
    color[cb] = 0;
    solve(ca);
    solve(cb);
  }

  REP(i,1,N+1){
    cout << color[i] << endl;
  }
  
  
  return 0;
}


Measured memory_bytes: 13312
def main():
    n = int(input())
    xy = []
    for i in range(n):
        a = int(input())
        xy.append([tuple(map(int, input().split())) for _ in range(a)])

    c = 0
    for i in range(1 << n):
        all_honest = True
        for j in range(n):
            if (1 << j) & i != 0:
                for x, y in xy[j]:
                    x -= 1  # 人の番号をひとつずらす
                    if ((1 << x) & i) >> x != y:
                        all_honest = False
                        break
            if not all_honest:
                break
        if all_honest:
            popcnt = bin(i).count('1')
            if popcnt > c:
                c = popcnt

    print(c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import sys
n = int(input())

#条件満たす数カウント
cn = 0
#約数カウント
cy = 0

if n < 105:
    print(0)
    sys.exit()

for i in range(105, n+1):
    if i % 2 == 0:
        continue

    for j in range(1, i+1):
        if i % j == 0:
            cy += 1
    if cy == 8:
        cn += 1
    cy = 0
print(cn)


Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>

int main()
{
long long n,a,c,d,result,i;
scanf("%lld",&n);
 i=sqrt(n);
for( long long j=(i+1);j>=1;j--)
{
if(n%j==0)
{
a=n/j;
result=a+j-2;
printf("%lld",result);
break;}}
 return 0;}


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

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

  for (int i = 0; i <= n; i++){
    for (int j = 0; j <= n - i; j++){
      if (i * 10000 + j * 5000 + (n - i - j) * 1000 == y){
        printf("%d %d %d\n", i, j, n-i-j);
        return 0;
      }
    }
  }

  printf("-1 -1 -1\n");
  return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

void main() {
    int N;
    scan(N);
    auto a = readln.split.to!(int[]);
    int Q;
    scan(Q);
    auto m = readln.split.to!(int[]);

    auto ok = new bool[](20 * 2000 + 1);

    foreach (s ; 0 .. (1 << N)) {
        int tot;
        foreach (i ; 0 .. N) if (s & (1 << i)) tot += a[i];
        ok[tot] = true;
    }

    foreach (i ; 0 .. Q) {
        writeln(ok[m[i]] ? "yes" : "no");
    }
}









void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}



Measured memory_bytes: 2480
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

const int mod = 1000000007;

int main(){
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    rep(k,60){
        ll x = 0;
        rep(j,n) if(a[j] >> k & 1) ++x;//k桁目にbitが立ってる
        ll now = x * (n-x) % mod;
        rep(j,k) now = now * 2 % mod;//2^k
        ans += now;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    int N ;cin >> N;
    pair<char[17],int> A[107];
    int B[107];
    rep(i,N){
        cin >> A[i].first >> A[i].second;
        B[i]=i+1;
    }
    int j,d,e;
    char c[17];
    rep(i,N){
        rep(j,i){
            if(strcmp(A[j].first,A[i].first)>0|| (strcmp(A[j].first,A[i].first)==0 && A[j].second<A[i].second)){
                strcpy(c,A[i].first);
                d=A[i].second;
                e=B[i];
                for(int k=i;k>j;k--){
                    strcpy(A[k].first,A[k-1].first);
                    A[k].second=A[k-1].second;
                    B[k]=B[k-1];
                }
                strcpy(A[j].first,c);
                A[j].second=d;
                B[j]=e;
                break;
            }
        }
    }
    rep(j,N){
        cout  << B[j] <<endl;
    }
}

Measured memory_bytes: 256
a,b,k=map(int,input().split())
out=[]
for i in range(k):
  if a+i>=b-i:
    if a+i==b-i:
      out.append(a+i)
    break
  out.append(a+i)
  out.append(b-i)
out.sort()
for i in out:
  print(i)

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
const int B = 12345;

int K, L;
int Lnum;
int pB[100001];
int A[100001];
int TA[100001];
string S;

bool g(int pos, string &T) {
  int lo = -1, hi = T.length();
  while (hi - lo > 1) {
    int mid = (lo + hi) / 2;
    // [0, mid]
    int a = (A[pos+mid]+MOD-(pos>0?A[pos-1]:0)) % MOD;
    if (a == (1LL*pB[pos]*TA[mid])%MOD) lo = mid;
    else hi = mid;
  }
  int lcp = lo+1;
  if (lcp == T.length()) return true;
  return S[pos+lcp] <= T[lcp];
}

bool f(string &T) {
  int pos = 0;
  int cl = 0, cr = 0;
  rep(_, K) {
    assert(pos < S.length());
    if (cl < Lnum && g(pos, T)) {
      pos += L;
      cl++;
    }
    else {
      if (cr >= K-Lnum) return false;
      pos += L-1;
      cr++;
    }
  }
  assert(pos == S.length() && cl == Lnum && cl+cr == K);
  return true;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  pB[0] = 1;
  for (int i=1; i<=100000; i++) pB[i] = (1LL*B*pB[i-1]) % MOD;
  cin >> K >> S;
  rep(i, S.length()) A[i] = ((i>0?A[i-1]:0)+1LL*S[i]*pB[i]) % MOD;
  K++;
  L = (S.length()+K-1)/K;
  Lnum = S.length()%K;
  if (S.length()%K==0) Lnum = K;
  string T;
  rep(i, L) {
    int dig = 9;
    for (int c=1; c<=8; c++) {
      string ct(T);
      ct += (char)('0'+c);
      TA[i] = ((i>0?TA[i-1]:0) + 1LL*pB[i]*ct.back()) % MOD;
      if (f(ct)) {
        dig = c;
        break;
      }
    }
    T += (char)('0'+dig);
    TA[i] = ((i>0?TA[i-1]:0) + 1LL*pB[i]*T.back()) % MOD;
  }
  cout << T << "\n";
  return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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

vi to[200005];
vi ans;

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

  int N, Q; cin >> N >> Q;
  REP(i,N-1) {
    int a, b; cin >> a >> b;
    --a; --b;
    to[a].PB(b);
    to[b].PB(a);
  }

  ans.resize(N);
  REP(i,Q) {
    int p, x; cin >> p >> x;
    --p;
    ans[p] += x;
  }

  vector<bool> checked(N,false);
  queue<int> que;
  que.push(0);
  checked[0] = true;

  while (!que.empty()) {
    int node = que.front();
    que.pop();
    for (auto &next : to[node]) {
      if (!checked[next]) {
        ans[next] += ans[node];
        que.push(next);
        checked[next] = true;
      }
    }
  }

  REP(i,N) {
    cout << ans[i] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 15604
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

use std::collections::HashSet;

fn main() {
    let n = get!(usize);
    let ds = get!(i32; n);
    println!("{}", ds.into_iter().collect::<HashSet<_>>().len());
}

Measured memory_bytes: 2164
//----->|try=0; while(!success) try++;|<------
//----->|Belief Yourself,Respect Yourself|<----
//----->|Be Proud Of Yourself,You're Doing Your best|<-----
#include<bits/stdc++.h>
using namespace std;
#define uniq(x)  x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
#define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Upper value search;
#define lower(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Lower value search;
#define max3(a,b,c) max(max(a,b),c)//maximum value find three value;
#define min3(a,b,c) min(min(a,b),c)//minimum value find three value;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, n) for(int i = 1; i <= n; ++i)
#define rep1(i,start,n) for(int i=start;i<n;++i)
#define PI acos(-1.0)//PI Calculation
#define LL long long
#define AND(a,b) ((a) & (b))
#define OR(a,b) ((a)|(b))
#define XOR(a,b) ((a) ^ (b))
#define MP make_pair
#define sqr(x) ((x)*(x))
#define sqrt(x) sqrt(1.0*(x))
#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define MX 1000005
#define MOD 1000000007
template<typename T> T POW(T b,T p)          //Pow calculation
{
    T r=1;
    while(p)
    {
        if(p&1)r=(r*b);
        b=(b*b);
        p>>=1;
    }
    return r;
}

template<typename T> T BigMod(T b,T p,T m) //BigMod Calculation
{
    T r=1;
    while(p)
    {
        if(p&1)r=(r*b)%m;
        b=(b*b)%m;
        p>>=1;
    }
    return r;
}

//||--------------------------->||Main_Code_Start_From_Here||<---------------------------------||
LL ar[200001];
int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    LL n,need;
    while(cin>>n>>need)
    {
        LL ans=0;
        REP(i,n) cin>>ar[i];
        for(int i=1;i<=n;i++)
        {
             if(ar[i]+ar[i-1]>need)
             {
                 ans+=((ar[i]+ar[i-1])-need);
                 ar[i]-=((ar[i]+ar[i-1])-need);
             }
        }
        cout<<ans<<endl;

    }

}




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

int main() {
	int n;
	cin >> n;
	double sm;
	for(int i=0;i<n;i++)
	{
		float a;
		cin >> a;
		sm += 1 / a;
	}
	sm = 1 / sm;
	cout << sm << endl;
}


Measured memory_bytes: 256
function A(x){
  var table={};
  table['A'] = "00000";
  table['B'] = "00001";
  table['C'] = "00010";
  table['D'] = "00011";
  table['E'] = "00100";
  table['F'] = "00101";
  table['G'] = "00110";
  table['H'] = "00111";
  table['I'] = "01000";
  table['J'] = "01001";
  table['K'] = "01010";
  table['L'] = "01011";
  table['M'] = "01100";
  table['N'] = "01101";
  table['O'] = "01110";
  table['P'] = "01111";
  table['Q'] = "10000";
  table['R'] = "10001";
  table['S'] = "10010";
  table['T'] = "10011";
  table['U'] = "10100";
  table['V'] = "10101";
  table['W'] = "10110";
  table['X'] = "10111";  
  table['Y'] = "11000";
  table['Z'] = "11001";
  table[' '] = "11010";
  table['.'] = "11011";
  table[','] = "11100";
  table['-'] = "11101";
  table['\''] = "11110";
  table['?'] = "11111";
  var str="";
  for(var i=0;i<x.length;i++){
   str+=table[x[i]];
  }
  return str;
}
function B(x){
  var table={};
  table["101"] = ' ';
  table["000000"] = '\'';
  table["000011"] = ',';
  table["10010001"] = '-';
  table["010001"] = '.';
  table["000001"] = '?';
  table["100101"] = 'A';
  table["10011010"] = 'B';
  table["0101"] = 'C';
  table["0001"] = 'D';
  table["110"] = 'E';
  table["01001"] = 'F';
  table["10011011"] = 'G';
  table["010000"] = 'H';
  table["0111"] = 'I';
  table["10011000"] = 'J';
  table["0110"] = 'K';
  table["00100"] = 'L';
  table["10011001"] = 'M';
  table["10011110"] = 'N';
  table["00101"] = 'O';
  table["111"] = 'P';
  table["10011111"] = 'Q';
  table["1000"] = 'R';
  table["00110"] = 'S';
  table["00111"] = 'T';
  table["10011100"] = 'U';
  table["10011101"] = 'V';
  table["000010"] = 'W';
  table["10010010"] = 'X';
  table["10010011"] = 'Y';
  table["10010000"] = 'Z';
  var str="";
  var memo="";
  for(var i=0;i<x.length;i++){
    memo+=x[i];
    if(table.hasOwnProperty(memo)){
      str+=table[memo];
      memo="";
    }
  }
  return str;
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.replace(/\n$/,"")).split("\n");
Arr.forEach(function(v){
  v=A(v);
  v=B(v);
  console.log(v);
});

Measured memory_bytes: 10780
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    string s, t;
    cin >> s >> t;
    sort(all(s));
    sort(all(t));
    reverse(all(t));
    yorn(s < t);
    return 0;
}

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

int main(){
   int n; cin >> n;
   int devisor = 0;
   int x = n;
   while(n!=0){
       devisor += n%10;
       n -= n%10;
       n /= 10;
   }
   if(x%devisor==0){
       cout << "Yes" << endl;
   }else{
       cout << "No" << endl;
   }
   
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e15;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

class UnionFind{
private:
  vector<ll> Parent; 
 public:
  UnionFind(ll N){
    Parent = vector<ll>(N, -1);
  }
  
  ll root(ll A){
    if(Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }
  
  ll size(ll A){
    return -Parent[root(A)]; 
  }
  
  bool connect(ll A, ll B){
    A = root(A);
    B = root(B);
    if(A == B){
      return false;
    }
    if(size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
  
  bool isSame(ll A, ll B){
    return root(A) == root(B);
  }
};


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,m; cin>>n>>m;
  UnionFind uf(n);
  vll ans(m);
  ans[0]=n*(n-1)/2;
  vpll ab(m);
  rep(i,m) cin>>ab[i].first>>ab[i].second, ab[i].first--, ab[i].second--;
  reverse(all(ab));
  rep(i,m-1){
    ll a=ab[i].first, b=ab[i].second;
    if(!uf.isSame(a,b)){
      ans[i+1]=ans[i]-uf.size(a)*uf.size(b);
      uf.connect(a,b);
    }else{
      ans[i+1]=ans[i];
    }
  }
  reverse(all(ans));
  rep(i,m){
    cout<<ans[i]<<endl;
  }
  
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
int main () {
    int h, a;
    cin >> h >> a;
    int ans;
    if (h % a != 0){
        ans = h / a + 1;
    }
    else{
        ans = h/a;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
// for copy
// for(int i=0;i<N;++i) {

int main(void) {
  int n;cin>>n;
  for(int i=1;i<10;++i) {
    for(int j=1;j<10;++j) {
      if (i*j==n) {
        pr("Yes");
        return 0;
      }
    }
  }
  pr("No");
  return 0;
}



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

typedef long long LL;

int n, x, y;
map<int,int> MP;

int main(){
	scanf("%d", &n);
	while(n--){
		scanf("%d", &x);
		MP[x]++;
	}
	int a=-1, b=-1;
	while(!MP.empty()){
		x = MP.rbegin()->first;
		y = MP[x];
		MP.erase(x);
		if(a == -1){
			if(y >= 4){
				a = b = x;
				break;
			} else if(y >= 2){
				a = x;
			}
		} else if(y >= 2){
			b = x;
			break;
		}
	}
	if(a==-1 || b==-1)	a = b = 0;
	printf("%lld\n", (long long)a * (long long)b);
	return 0;
}

Measured memory_bytes: 4992