akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

typedef struct {
    int ldata, rdata;
    int left, right;
    int parent;
} BINARY;

BINARY tree[101];

int gcd(int a, int b)
{
    if (a < b){
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return (b == 0 ? a : gcd(b, a % b));
}

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

int postorder(int root)
{
    int l, r, x, y;
    int cd;
    
    if (tree[root].left){
        l = postorder(tree[root].left);
    }
    else {
        l = 1;
    }
    
    if (tree[root].right){
        r = postorder(tree[root].right);
    }
    else {
        r = 1;
    }
    
    if (tree[root].right + tree[root].left == 0){
        cd = gcd(tree[root].ldata, tree[root].rdata);
        return (tree[root].ldata / cd + tree[root].rdata / cd);
    }
    
    l *= tree[root].ldata;
    r *= tree[root].rdata;
    cd = gcd(l, r);
    x = r / cd;
    y = l / cd;
    l *= x;
    r *= y;
    return (l / tree[root].ldata + r / tree[root].rdata);
}

int main(void)
{
    int i;
    int n;
    int p, q, r, b;
    int root;
    
    while (1){
        
        scanf("%d", &n);
        
        if (n == 0){
            break;
        }
        
        memset(tree, 0, sizeof(tree));
        for (i = 1; i <= n; i++){
            scanf("%d%d%d%d", &p, &q, &r, &b);
            tree[i].ldata = p;
            tree[i].rdata = q;
            tree[i].left = r;
            tree[i].right = b;
            tree[r].parent = tree[b].parent = i;
        }
        
        for (i = 1; i <= n; i++){
            if (tree[i].parent == 0){
                root = i;
            }
            
        }
        printf("%d\n", postorder(root));
    }
    
    return (0);
}

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

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

using namespace std;

template<class G>
class Fenwick_tree_dual{
	vector<G> a;
public:
	Fenwick_tree_dual(int n):a(n){}
	void add(int l,int r,G val){
		if(l==0){
			for(;r>0;r-=r&-r) a[r-1]+=val;
			return;
		}
		add(0,r,val);
		add(0,l,-val);
	}
	G sum(int i)const{
		G res{};
		for(i++;i<=a.size();i+=i&-i) res+=a[i-1];
		return res;
	}
};

int main(){
	int n; scanf("%d",&n);

	Fenwick_tree_dual<int> A(n),B(n);
	rep(i,n){
		A.add(i,i+1,i+1);
		B.add(i,i+1,n-i);
	}
	rep(i,n){
		int p; scanf("%d",&p); p--;
		A.add(p,n,i);
		B.add(p+1,n,-i);
	}

	int a_min=1e9,b_min=1e9;
	rep(i,n){
		a_min=min(a_min,A.sum(i));
		b_min=min(b_min,B.sum(i));
	}
	A.add(0,n,1-a_min);
	B.add(0,n,1-b_min);

	rep(i,n) printf("%d%c",A.sum(i),i<n-1?' ':'\n');
	rep(i,n) printf("%d%c",B.sum(i),i<n-1?' ':'\n');

	return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
	string input;
	cin>>input;
	string patokan = "AKIHABARA";
	bool valid = 1;
	if(input != patokan)
	{
		map <string , bool > cek;
		cek["KIHBR"] = 1;
		cek["AKIHBR"] = 1;
		cek["KIHABR"] = 1;
		cek["KIHBRA"] = 1;
		cek["KIHBAR"] = 1;
		cek["AKIHABR"] = 1;
		cek["AKIHABR"] = 1;
		cek["AKIHBAR"] = 1;
		cek["AKIHBRA"] = 1;
		cek["KIHABRA"] = 1;
		cek["KIHBARA"] = 1;		
		cek["AKIHABRA"] = 1;
		cek["AKIHBARA"] = 1;
		cek["AKIHABRA"] = 1;
		cek["AKIHABAR"] = 1;
		if(cek[input])
		{
			cout<<"YES\n";
		}
		else
		cout<<"NO\n";
		
		
	}
	else
	cout<<"YES\n";
	return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 100001


int main() {
    int n;
    int d[MAXN];

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

    sort(d, d+n);

    int ans;
    ans = d[n/2] - (d[n/2-1]+1) +1;
    if ( ans < 0 )  ans = 0;
    cout << ans << endl;

}



Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    vector<int> a(3);
    for (int i = 0; i < 3; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    int il;
    cin >> il;
    cout << a[2] * (1 << il) + a[0] + a[1];
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    readLine()
    var list = readLine()!!.split(" ").map(String::toInt)
    var count = 0
    while (true) {
        var existsOdd = false
        for (a in list) {
            if (a % 2 != 0) existsOdd = true
        }
        if (existsOdd) break
        list = list.map { it/2 }
        count++
    }
    println(count)
}

Measured memory_bytes: 37932
n = int(input())


here = list( map(int, input().split()) )
can = here[0] >= (here[1]+here[2])

for i in range(n-1):

    next = list(map(int, input().split()) )

    t = next[0] - here[0]

    d = abs( next[1] + next[2] - (here[1]+ here[2] ) )

    cond = t >= d and t % 2 == d % 2
    if not cond:
        can = False
        break

    here = next

print("Yes" if can else 'No')

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int K = sc.nextInt();

		if (N % K == 0){
			System.out.println(0);
		} else {
			System.out.println(1);
		}
	}
}

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

int main() {
  int S;
  int s1,s2,s3;
  cin >> S;
  s3=S%10;
  s2=(S-s3)/10%10;
  s1=(S-s2*10-s3)/100;
  cout << s1+s2+s3 <<endl;
}  

Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

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


Measured memory_bytes: 3620
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans = 0;
    ans += min(a, k);
    k -= min(a, k);
    k -= min(b, k);
    ans -= k;
    cout << ans << endl;
}


Measured memory_bytes: 3640
H, W, K = map(int, input().split())
S = [list(map(int, list(input()))) for _ in range(H)]

ans = H*W

def countWhite(ytop, ybottom, xleft, xright):
    ret = sum([sum(s[xleft:xright]) for s in S[ytop:ybottom]])
    return ret
    

for h_div in range(1 << H-1):
    count = 0
    cut = [0]
    for i in range(H):
        if h_div >> i & 1:
            cut.append(i+1)
            count += 1
    cut.append(H)
    if count > ans:
        continue
    
    left = 0
    # ここどんなふうに縦に切っても条件を満たさない場合がある
    for right in range(1, W+1):
        white = 0
        for i in range(len(cut)-1):
            white = max(white, countWhite(cut[i], cut[i+1], left, right))
        
        if white > K:
            if left == right - 1: # 条件を満たす縦の切り方がなかった場合
                break
            left = right - 1
            count += 1
            if count > ans:
                break
    else:
        if count < ans:
            ans = count

print(ans)

Measured memory_bytes: 50140
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;

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

  int result = 1;
  rep(i, N) {
    if (result < K) {
      result *= 2;
    } else {
      result += K;
    }
  }

  cout << result << endl;
}


Measured memory_bytes: 3564
#pragma GCC optimize("O4")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF (1e17)
#define int ll
#define EPS (1e-6)
#define DB(x) #x<<" "<<x<<" "
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p){
	b%=MOD;
	int ans=1;
	while(p>0){
		if(p&1) ans=(ans*b)%MOD;
		p/=2;
		b=(b*b)%MOD;
	}
	return ans;
}

int dp[10010];

int32_t main() {
#ifdef LOCAL_TEST
	freopen("D:\\input.in","r",stdin);
	freopen("D:\\output.out","w",stdout);
	freopen("D:\\error.out","w",stderr);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);

	//code...
	int h,n; cin>>h>>n;
	vector<pii> v(n);
	for(auto &i:v)
		cin>>i.F>>i.S;
	fill(dp,dp+10010,INF);
	dp[0]=0;
	For(i,1,h){
		for(auto &j:v){
			if(j.F>i) dp[i]=min(dp[i],j.S);
			else dp[i]=min(dp[i],dp[i-j.F]+j.S);
		}
	}
	cout<<dp[h]<<"\n";
	return 0;
}


Measured memory_bytes: 384
import java.util.*;
import java.io.*;

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

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        String[] input = br.readLine().split(" ");
        int n = Integer.parseInt(input[0]);
        int a = Integer.parseInt(input[1]);
        int b = Integer.parseInt(input[2]);
        int ans = 0;
        
        for(int i = 1; i <= n; i++){
            
            int num = i;
            int total = 0;
            
            while(num > 0){
                total += num % 10;
                num /= 10;
            }
            
            if(a <= total && total <= b){
                ans += i;
            }
            
        }
        
        out.println(ans);
        out.close();
        
    }
}

Measured memory_bytes: 32716
import fractions
A,B=list(map(int,input().split()))
gcd=fractions.gcd(A,B)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
so=factorization(gcd)
ans=[i[0] for i in so]
#print(ans)
if 1 in ans:
    print(len(so))
else:
    print(len(so)+1)

Measured memory_bytes: 5084
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  std::string s; std::cin >> s;
  int da[4], db[4];
  da[0] = db[0] = da[3] = -1;
  da[1] = db[1] = db[3] = 1;
  int a = 0, b = 0, m = 0, M = 0;
  int c0 = a-b, c1 = c0 + 1, c2 = c0 + 1, c3 = c0 + 2;
  for(auto c: s) {
    a += da[c&3]; if(a < 0) { a += 1; m ^= 1; }
    b += db[c&3]; if(b > 0) { b -= 1; M ^= 1; }
    c0 = std::max(c0, a-b+m+M);
    c1 = std::max(c1, a-b+m+(M^1));
    c2 = std::max(c2, a-b+(m^1)+M);
    c3 = std::max(c3, a-b+(m^1)+(M^1));
  }
  fin(std::min(std::min(c0, c1), std::min(c2, c3)));
  return 0;
}


Measured memory_bytes: 4740
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>	
#include <cmath>
#include <string>
#include<math.h>
#include<sstream>//���炵���̂Œ���
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;
int mod = 1000000007;


int main()
{
	int n, d; cin >> n >> d;
	vector<vector<double>> x(n,vector<double>(d));
	rep(i, n) {
		rep(j, d) cin >> x[i][j];
	}
	int ans = 0;
	for (int i = 0; i < n - 1; i++) {
		for (int j = i+1; j < n; j++) {
			double sum = 0;
			rep(D, d) { sum += (x[i][D] - x[j][D]) * (x[i][D] - x[j][D]); }
			if (sqrt(sum) - int(sqrt(sum)) == 0)
				ans++;
		}
	}
	cout << ans << endl;

	return 0;
}


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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver2 {
 public:
  int n, k;
  vector<int> a, memo;
  Solver2(LL n, LL k) : n(n), k(k), a(n), memo(k + 1, -1){};

  void solve() {
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    cout << (checkWin(k) ? "First" : "Second") << endl;
  }
  int checkWin(int x) {
    if (memo[x] >= 0) return memo[x];
    for (int i = 0; i < n; ++i) {
      if (x - a[i] >= 0 && !checkWin(x - a[i])) return memo[x] = 1;
    }
    return memo[x] = 0;
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0, k;
  std::cin >> n >> k;

  Problem::Solver2 sol(n, k);
  sol.solve();
  return 0;
}


Measured memory_bytes: 3712
/*    Mohammed Sami Khan
                       মোহাম্মদ সামী খান
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define mp(a,b) make_pair(a,b)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
typedef unsigned long long ull;

bool sortbysecc(const pair<int,int> &a, const pair<int,int> &b){
    return (a.second < b.second);
}

int main()
{
    fastio;
    ll t, n, m, x, y, p, q, r, i, j, d, f=0;
    char *ye="YES", *no="NO";
    cin>>n;
    vector<pair<int, int> > v;
    ll a[n];
    for(i=0;i<n;i++){
        cin>>a[i];

        v.push_back(mp(a[i], i+1));
    }
    sort(v.begin(), v.end());
    for(i=0;i<n;i++){
        cout<<v[i].second<<" ";
    }

}


Measured memory_bytes: 5012
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
3
0 0 1 0 0 1 1 1
0 0 1 0 2 1 1 2
-1 0 1 0 0 1 0 -1

output:
1.0000000000
1.4142135624
0.0000000000
"""

import sys

EPS = 1e-9


class Segment(object):
    __slots__ = ('source', 'target')

    def __init__(self, source, target):
        self.source = complex(source)
        self.target = complex(target)


def cross(a, b):
    return a.real * b.imag - a.imag * b.real


def dot(a, b):
    return a.real * b.real + a.imag * b.imag


def get_distance_lp(l, p):
    return abs(cross(l.target - l.source, p - l.source) / abs(l.target - l.source))


def get_distance_sp(s, p):
    if dot(s.target - s.source, p - s.source) < 0:
        return abs(p - s.source)
    elif dot(s.source - s.target, p - s.target) < 0:
        return abs(p - s.target)
    else:
        return get_distance_lp(s, p)


def check_ccw(p0, p1, p2):
    a, b = p1 - p0, p2 - p0
    if cross(a, b) > EPS:
        flag = 1
    elif cross(a, b) < -1 * EPS:
        flag = -1
    elif dot(a, b) < -1 * EPS:
        flag = 2
    elif abs(a) < abs(b):
        flag = -2
    else:
        flag = 0
    return flag


def check_intersection(p0, p1, p2, p3):
    intersected = (check_ccw(p0, p1, p2) * check_ccw(p0, p1, p3) <= 0) and \
                  (check_ccw(p2, p3, p0) * check_ccw(p2, p3, p1) <= 0)

    return intersected


def calc_distance(_lines):
    for line in _lines:
        line_axis = tuple(map(int, line))
        p0, p1, p2, p3 = (x + y * 1j for x, y in zip(line_axis[::2], line_axis[1::2]))
        s1, s2 = Segment(p0, p1), Segment(p2, p3)
        
        intersected = check_intersection(s1.source, s1.target, s2.source, s2.target)
        if intersected:
            distance = 0
        else:
            distance = min(min(get_distance_sp(s1, s2.source), get_distance_sp(s1, s2.target)),
                           min(get_distance_sp(s2, s1.source), get_distance_sp(s2, s1.target)))
            
        print('{ans:.10f}'.format(ans=distance))
        
    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    questions = int(_input[0])
    lines = map(lambda x: x.split(), _input[1:])
    calc_distance(lines)

Measured memory_bytes: 8032
# https://tenka1-2019-beginner.contest.atcoder.jp/tasks/tenka1_2019_b

import itertools
from collections import Counter
import bisect

def main():
    N = int(input())
    S = input()
    K = int(input())
    K -= 1
    target = S[K]
    ans = ''
    for s in S:
        ans += '*' if s != target else s
    print(ans)


if __name__ == '__main__':
    main()


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

int main()
{
	int n, m, c;
	cin >> n >> m >> c;
	vector<int> bs(m);
	for (auto &b : bs)
	{
		cin >> b;
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		vector<int> as(m);
		for (auto &a : as)
		{
			cin >> a;
		}
		int sum = c;
		for (int j = 0; j < m; j++)
		{
			sum += as[j] * bs[j];
		}
		if (0 < sum)
		{
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 140000
#define mod 1000000007
#define pp pair<ll,ll>
typedef long long int ll;
typedef long double ld;
#define MP make_pair

#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++)     
void fastIO(void);

void decimal(int);
ll modmulti(ll, ll, ll);
ll modadd(ll, ll, ll);
ll modpower(ll, ll, ll);
ll gcd(ll, ll );
ll modinv(ll, ll);




int main()
{  
   ll n;
   cin>>n;
   ll a[n];
   rep(i,n) cin>>a[i];
   a[0]--;
   rep1(i,n){
      if(a[i]>a[i-1])
         a[i]--;
   }
   rep1(i,n){
      if(a[i]<a[i-1]){
         cout<<"No\n";
         return 0;
      }
   }
   cout<<"Yes\n";
}























void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}

void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b, ll m){
   return ((a%m)*(b%m))%m;
}
ll modadd(ll a, ll b, ll m){
   return ((a%m)+(b%m))%m;
}
ll modpower(ll a, ll n, ll m){
   if(n==0)
      return 1;
   ll result = 1;
   while(n>0){
      if(n%2==1)
         result = modmulti(result,a,m);
      a = modmulti(a,a,m);
      n = n/2;
   }
   return result;
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a, ll m){
   return modpower(a,m-2,m);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    int N,D;
    cin >> N >> D;
    
    D = 2 * D + 1;
    if (N % D == 0) cout << N / D << endl;
    else cout << N / D + 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int inf=7+1e9;
int main(){
	long long n; cin >> n; 
    vector<long long> a(n);
    long long mx=0;
    for(int i=0; i<n; ++i){
        cin >> a[i];
        mx = max(mx,a[i]);
    }

    long long ans=0, x=1;
    mx=60;//=log2(mx);
    for(int i=0; i<=mx; ++i){
        long long cnt=0;
        for(int j=0; j<n; ++j){
            cnt += 1&a[j];
            a[j] >>= 1;
        }
        ans = (ans+x%inf*cnt%inf*(n-cnt)%inf)%inf;
        x <<= 1;
    }
	cout << ans << endl;
}

Measured memory_bytes: 2560
import java.util.*;

public class Main {
	boolean isLeapYear(long y) {
		if(y%4==0) {
			if(y%100!=0 || y%400==0) {
				return true;
			}
		}
		
		return false;
	}
	
	long y2d(long y) {
		long day = 365;
		if( isLeapYear(y) ) {
				++day;
		}
		
		return day;
	}
	
	long ally2d(long y) {
		long day = 0;
		for( int i = 0; i < y; ++i ) {
			day += y2d(i);
		}
		
		return day;
	}
	
	long m2d(long y, long d) {
		switch((int)d){
		case 2:
			long day = 28;
			if( isLeapYear(y) ) {
				++day;
			}
			return day;
		case 4:
		case 6:
		case 9:
		case 11:
			return 30;
		default:
			return 31;
		}
	}
	
	long[] miniy = new long[]{ 2, 4, 6, 9, 11 };
	long allm2d(long y, long m) {
		long day = 0;
		for( int i = 1; i < m; ++i ) {
			day += m2d(y, i);
		}
		
		return day;
	}
	
	long cycle;
	long[] d4y;
	
	long[] max_may_n = new long[]{13, 20, 20, 19, 20};
	String usu2may(ArrayList<Integer> list) {
		long day = d4y[list.get(0)];
		day += allm2d(list.get(0), list.get(1));
		day += (long)list.get(2);
		
		day -= cycle;
		
		String ans = "";
		
		for( int i = 0; i < 5; ++i ) {
			if( i > 0 ) {
				ans += ".";
			}
			ans += (day / mayas_day[i])%max_may_n[i];
			day %= mayas_day[i];
		}
		
		return ans;
	}
	
	long ki = 1;
	long w  = 20*ki;
	long t  = 18*w;
	long ka = 20*t;
	long b  = 20*ka;
	long mayas_day[] = {b, ka, t, w, ki};
	String may2usu(ArrayList<Integer> list) {
		long day = 0;
		for( int i = 0; i < 5; ++i ) {
			day += mayas_day[i]*(long)list.get(i);
		}
		
		day += cycle;
		
		long y = 0;
		while(day > y2d(y)) {
			day -= y2d(y);
			++y;
		}
		long m = 1;
		while(day > m2d(y, m)) {
			day -= m2d(y, m);
			++m;
		}
		long d = day;
		
		return y + "." + m + "." + d;
	}
	
	void solve() {
		Scanner sc = new Scanner(System.in);
		
		cycle = 0;
		cycle += ally2d(2012);
		cycle += allm2d(2012, 12);
		cycle += 21;
		
		d4y = new long[10000001];
		d4y[0] = 0;
		for( int i = 1; i <= 10000000; ++i ) {
			d4y[i] = d4y[i-1] + y2d(i-1);
		}
		
		while(true) {
			String str = sc.nextLine();

			if( str.equals("#") ) {
				break;
			}
			
			ArrayList<Integer> list = new ArrayList<Integer>();
			for( String ite : str.split("\\.") ) {
				list.add(Integer.parseInt(ite));
			}
			
			System.out.println(list.size() == 3 ? usu2may(list) : may2usu(list));
		}
		
		sc.close();
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}
	
	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 103508
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;


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

  bool flag = false;
  for (double i = 0; i <= N; i++){
    double now = i * 1.08;
    int A = now;
    if (A == N){
      flag = true;
      cout << i << endl;
      break;
    }
  }
  
  if (flag == false){
    cout << ":(" << endl;
  }
  
  
  return 0;
}


Measured memory_bytes: 256
/**********************************
	author:  mariogzsl
**********************************/

#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,b,a) for(int i=b-1;i>=a;i--)
#define f first
#define s second
#define puts(x) cout<<x<<endl
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N,K;
	string s;
	cin>>K>>N>>s;
	s[N-1]=s[N-1]-'A'+'a';
	cout<<s<<endl;

	return 0;
}


Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	
    	long inf = (long)Math.pow(10, 18);
    	int A = sc.nextInt();
    	int B = sc.nextInt();
    	int Q = sc.nextInt();
    	
    	long[] s = new long[A+2];
    	s[0] = -inf;
    	for( int i = 1; i <= A; i++ ){
    		s[i] = sc.nextLong();
    	}
    	s[A+1] = inf;
    	
    	long[] t = new long[B+2];
    	t[0] = -inf;
    	for( int i = 1; i <= B; i++ ){
    		t[i] = sc.nextLong();
    	}
    	t[B+1] = inf;
    	
    	for( int i = 0; i < Q; i++ ){
    		long x = sc.nextLong();
    		
    		int[] sa = new int[2];
    		int[] ta = new int[2];
    		int temp = Arrays.binarySearch(s, x);
    		sa[1] = (temp + 1) * -1;
    		sa[0] = sa[1] - 1;
    		temp = Arrays.binarySearch(t, x);
    		ta[1] = (temp + 1) * -1;
    		ta[0] = ta[1] - 1;
    		
    		//System.out.println( sa[0] + " " + ta[0] );
    		long min = inf;
    		for( int j = 0; j < 2; j++ ){
    			for( int k = 0; k < 2; k++ ){
    				long c1 = Math.abs( x - s[sa[j]] ) + Math.abs( s[sa[j]] - t[ta[k]] );
    				long c2 = Math.abs( x - t[ta[k]] ) + Math.abs( s[sa[j]] - t[ta[k]] );
    				min = Math.min(min, Math.min(c1, c2));
    			}
    		}
    		System.out.println( min );
    	}
    	
    	sc.close();
    }
} 

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

#include <set>
#include <map>
#include <iomanip>

using namespace std;

#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define rrep(i, n) for(long long i = (long long)(n - 1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using ll = long long;

int main()
{
	int n, m;
	cin >> n >> m;
	// e + e = e
	// e + v = v
	// v + v = e

	cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstring>
#include<iostream>
#include<string>
#include<vector>
#include<fstream>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
int n;
int main()
{	
   scanf("%d",&n);
   int e=0,o=0;
   if(n%2)e=1;
   e+=n/2;
   o+=n/2;
   cout<<e*o<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    ll N;
    cin >> N;
    if (N <= 9) {
        cout << 0 << endl;
    } else {
        if (N % 2 == 0) {
            ll tens = 0;
            ll N2 = N/2;
            while (N2 > 0) {
                tens += N2 / 5;
                N2 /= 5;
            }
            cout << tens << endl;
        } else {
            cout << 0 << endl;
        }
    }
    return 0;
}




Measured memory_bytes: 256
S = input()
dp = [0] * (len(S) + 1)
dp[0] = 1

words = ["dream", "dreamer", "erase", "eraser"]
done = 'NO'

for i in range(len(S)):
    if dp[i] == 0:
        continue
    for w in words:
        if S[i:i+len(w)] == w:
            dp[i+len(w)] = 1
    
    if dp[len(S)] == 1:
        done = 'YES'
        break

print(done)

Measured memory_bytes: 41072
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//大小比較(大)
long long int big(long long int a, long long int b) {
	if (a >= b) {
		return a;
	}
	else {
		return b;
	}
}

//大小比較(小)
long long int small(long long int a, long long int b) {
	if (a >= b) {
		return b;
	}
	else {
		return a;
	}
}

main() {
	long long int n, m,k=0;
	char str[5];
	scanf("%s", str);

	if (str[0] == '+') { k++; }
	else { k--; }

	if (str[1] == '+') { k++; }
	else { k--; }
	if (str[2] == '+') { k++; }
	else { k--; }
	if (str[3] == '+') { k++; }
	else { k--; }
	printf("%lld", k);
}


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

int N;
vector<int> Ls;
int ans;

int main() {
  cin >> N;
  int L;
  rep(i, N) {
    scanf("%d", &L);
    Ls.push_back(L);
  }
  sort(Ls.begin(), Ls.end());
  for(int i=N-1; i>=2; i--) {
    int j_last = -1;
    for(int j=i-1; j>=1; j--){
      int k_last = -1;
      for(int k=j-1; k>=0; k--) {
        if(Ls[i] < Ls[j] + Ls[k]) {
          ans++;
        } else {
          k_last = k;
          break;
        }
      }
      if(k_last == j-1) {
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    char s[100001] = {0};
    scanf("%s", s);

    int i;

    for (i = 0; i <= 100001; i += 2) {
        if(s[i] == '\0')
            break;
        printf("%c", s[i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 256
s = input()
q = int(input())

f1 = 1
f2 = 2
cnt = 0
st = ""
se = ""

for _ in range(q):
    q = input().split()
    if int(q[0]) == 1:
        cnt += 1
    elif int(q[0]) == 2:
        if cnt % 2 == 0:
            if int(q[1]) == 1:
                st = q[2] + st
            elif int(q[1]) == 2:
                se += q[2]
        else:
            if int(q[1]) == 1:
                se += q[2]
            elif int(q[1]) == 2:
                st = q[2] + st


ans = st + s + se
if cnt % 2 == 0:
    print(ans)
else:
    ans = list(ans)
    ans.reverse()
    ans = "".join(ans)
    print(ans)

Measured memory_bytes: 12120
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#define LL long long;

using namespace std;
const int N = 1000010;
int n, cnt = 1, a[N];
bool up = false, dn = false;

int main() {
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	int pre = a[0];
	
	for(int i = 1; i < n; i++)
	{
		if(a[i] > pre) up = true;
		
		else if(a[i] < pre) dn = true;
		
		if(up && dn)
		{
			up = false;
			dn = false;
			++cnt;
		}
		pre = a[i];
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 640
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a, b = map(int, readline().split())

    print(max(a + b, a - b, a * b))


if __name__ == '__main__':
    main()


Measured memory_bytes: 61620
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    int l ,r, d; cin >> l >> r >> d;
    int ans = 0;
    repp(i,r+1,l) if (i % d == 0) ans++;
    cout << ans << endl;
}

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll A, B, C;

    cin >> A >> B >> C;
    cout << C << " " << A << " " << B  << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define eb emplace_back
#define precision(n) cout << fixed << setprecision(n);
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
int main()
{
    fast;
    int n;
    char s;
    cin>>s;
    if(isupper(s))
    {
        cout<<'A'<<endl;
    }
    else
    {
        cout<<'a'<<endl;
    }

    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int N , x;
long arr[2005][2005];
vector<int> abc;
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//freopen(".in","r",stdin);
	//entrada
    cin >> N >> x;
    long suma = 0;
    for (int i = 1 ; i <= N ; i++) {cin >> arr[0][i];suma += arr[0][i];}
    arr[0][N+1] = suma;
    suma = 0;
	//solution
	for (int vuelta = 1; vuelta < N ; vuelta++)
    {
        suma = arr[vuelta-1][0] + x;
        arr[vuelta][0] = suma;
        for (int slime = 1 ; slime <= N ;slime++)
        {
            int temp = (slime + vuelta > N) ? (slime + vuelta)%N : slime + vuelta;
            arr[vuelta][slime] = min(arr[vuelta-1][slime], arr[0][temp]);
            suma += arr[vuelta][slime];
        }
        arr[vuelta][N+1] = suma;
    }
    long result = LONG_MAX;
    for (int i = 0 ; i < N ; i++)
        result = min(result , arr[i][N+1]);
	cout << result << "\n";
    return 0;
}


Measured memory_bytes: 31616
import java.util.*;
import java.math.BigDecimal;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);    //scanner
        String str = sc.next();     // 入力文字列
        // 入力操作
        String ans = "";            // 出力文字列
        for(int i=0; i<str.length(); i++){
            if(str.charAt(i)=='0'){         // 0が入力されたら
                ans += "0";                 // 末尾に0を足す
            }
            else if(str.charAt(i)=='1'){    // 1が入力されたら
                ans += "1";                 // 末尾に1を足す
            }
            // Bが入力されたら右から一文字削除する
            else if(ans.length()==1){       // 残り一文字の時
                ans = "";
            }
            else if(ans.length() > 1){      // 2文字以上ある時
                ans = ans.substring(0,ans.length()-1);  // 出力文字列の最後の文字を削る
            }
        }
        System.out.println(ans);    // output
    }
}


Measured memory_bytes: 22868
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef long double ld;

int MOD=1000000007;


int main(){
    ll N,count=1;
    cin >> N;
    string  S[N+10]={};
    for(ll i=0; i<N; i++){
        cin >> S[i];
    }
    sort(S,S+N);
    for(ll i=1; i<N; i++){
        if(S[i]!=S[i-1]) count++;
    }
    cout << count << endl;
    }


Measured memory_bytes: 9884
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=1e5+5;
const int M=2e1+5;
const int INF=0x7fffffff;
const int mod=1e9+7;
const double eps=1e-8;
const double pi=acos(-1);
int n,m;
int f[N];
LL sum[N];
LL g[N];
LL jie[N];
template<class T>
inline void read(T &x)
{
    char c;
    x=1;
    while((c=getchar())<'0'||c>'9')
        if(c=='-')
            x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9')
        res=res*10+c-'0';
    x*=res;
}
LL qpow(LL a,LL n)
{
    if(n==1) return a;
    LL tmp=qpow(a,n>>1);
    if(n&1) return tmp*tmp%mod*a%mod;
    else return tmp*tmp%mod;
}
LL inv(LL p)
{
    return qpow(p,mod-2);
}
int main()
{
    r(n); r(m);
    FOR(i,1,n) r(f[i]);
    sort(f+1,f+n+1);
    FOR(i,1,n) sum[i]=sum[i-1]+f[i];
    FOR(i,m,n){
        g[i]=((sum[n]-sum[i-1])-(sum[n-i+1])+mod)%mod;
//        cout<<g[i]<<endl;
    }
    jie[0]=1;
    FOR(i,1,n){
        jie[i]=jie[i-1]*i%mod;
    }
    LL ans=0;
    FOR(i,m,n){
        int x=i-2;
        int y=m-2;
        ans=(ans+g[i]*jie[x]%mod*inv(jie[x-y])%mod*inv(jie[y])%mod+mod)%mod;
//        cout<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#define INF 99999999
using namespace std;

int main() {
    int n;
    long long c=0;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        if(i % 3 != 0 and i % 5 != 0){
            c+=i;
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 3636
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Main main = new Main();
		main.solveB();
	}

	private void solveB() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] count = new int[N];
		for (int i = 0; i < M; i++) {
			count[sc.nextInt() - 1]++;
			count[sc.nextInt() - 1]++;
		}
		int oddNum = 0;
		for (int num : count) {
			if (num % 2 == 1) {
				oddNum++;
			}
		}
		if (oddNum > 1) {
			System.out.println("NO");
		} else {
			System.out.println("YES");
		}
	}
}

Measured memory_bytes: 66164
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        var nd = Console.ReadLine().Split().Select(long.Parse).ToArray();

        Console.WriteLine(Enumerable.Repeat(0, (int)nd[0]).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).Where(x => x[0] * x[0] + x[1] * x[1] <= nd[1] * nd[1]).Count());
    }
}


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

using namespace std;

int main() {
	int H, W;
	cin >> H >> W;
	char c[100][101];

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

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < 4; j++) {
			cout << c[i]<< endl;
			j++;
		}
	}


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<ll,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int M = (int)3e3+5;
const int Q = 301;
const int logN = 19;

ll dp[55][2505];
vector<pii> v[55][2505];
void solve() {
    int n,m,s,x,y,a,b;
    cin>>n>>m>>s;
    int u = 2500;
    REP(i,1,n) {
        REP(j,0,u) {
            dp[i][j] = lim;
        }
    }
    REP(i,1,m) {
        cin>>x>>y>>a>>b;
        REP(j,a,u) {
            v[x][j].pb({b,{y,j-a}});
            v[y][j].pb({b,{x,j-a}});
        }
    }
    REP(i,1,n) {
        cin>>a>>b;
        REP(j,0,u-a) {
            v[i][j].pb({b,{i,j+a}});
        }
    }
    s = min(s,u);
    priority_queue<pii,vector<pii>,greater<pii>> pq;
    dp[1][s] = 0;
    pq.push({dp[1][s],{1,s}});
    while(!pq.empty()) {
        pii temp = pq.top();
        pq.pop();
        for(auto it:v[temp.second.first][temp.second.second]) {
            if(it.first+temp.first<dp[it.second.first][it.second.second]) {
                dp[it.second.first][it.second.second] = it.first + temp.first;
                pq.push({dp[it.second.first][it.second.second],{it.second.first,it.second.second}});
            }
        }
    }
    REP(i,2,n) {
        ll ans = lim;
        REP(j,0,u) {
            ans = min(ans,dp[i][j]);
        }
        cout<<ans<<"\n";
    }
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        //cout<<"\n";
    }
}


Measured memory_bytes: 24128
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

type item struct{ v, w int }

func parseProblem() int {
	n, c := scanInt(sc), scanInt(sc)
	items := make([]item, n)
	for i := 0; i < n; i++ {
		items[i] = item{
			v: scanInt(sc),
			w: scanInt(sc),
		}
	}
	dp := make([]int, c+1)
	for i := 1; i <= n; i++ {
		for w := 1; w <= c; w++ {
			it := items[i-1]
			if cw := w - it.w; 0 <= cw {
				if cv := dp[cw] + it.v; dp[w] <= cv {
					dp[w] = dp[cw] + it.v
				}
			}
		}
	}
	return dp[c]
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}



Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int f=0,b=0;
  int l=0,r=0;
  for(int i=0;i<n;i++){
    if(s[i]=='('){
      l++;
    }
    if(s[i]==')'){
      r++;
    }
    if(l<r){
      f++;
      l++;
    }
  }
  b=l-r;
  for(int i=0;i<f;i++){
    s='('+s;
  }
  for(int i=0;i<b;i++){
    s=s+')';
  }
  cout << s << endl;
}

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

int N;
string S;

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

  for (char c : S) {
    char cc = ('A' + (c - 'A' + N) % 26);
    cout << cc;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int e[4],i,j,sum;
	for(i=0;i<4;i++){
		scanf("%d",&e[i]);
	}
	for(i=0;i<3;i++){
		for(j=i+1;j<4;j++){
			if(e[i]==e[j]){
				sum++;
			}
		}
	}
	if(sum==2||sum==4){
		printf("yes\n");
	}
	else{
		printf("no\n");
	}
	return 0;
}


Measured memory_bytes: 2092
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define gcd __gcd
#define lcm(n, m) n * m / gcd(n, m)
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define so(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数

int main() {
  int N;
  ci(N);
  ve<int> A(N), B(N);
  rep(i, N){
    ci(A.at(i));
    B.at(i) = A.at(i);
  }
  so(B);
  rep(i, N){
    int a = 0;
    if(B.at(N - 1) == A.at(i)){
      a = B.at(N - 2);
    }
    else{
      a = B.at(N - 1);
    }
    co(a);
  }
}

Measured memory_bytes: 3328
A = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = []
for i in range(n):
    b.append(int(input()))

V = [[False,False,False],[False,False,False],[False,False,False]]

for bb in b:
    for i in range(len(A)):
        for j in range(len(A[i])):
            if(A[i][j] == bb):
                V[i][j] = True


def judge(V):
    for i in range(3):
        if(V[i][0] and V[i][1] and V[i][2]):
            return True
        if(V[0][i] and V[1][i] and V[2][i]):
            return True

    if(V[0][0] and V[1][1] and V[2][2]):
        return True
    if (V[0][2] and V[1][1] and V[2][0]):
        return True
    return False

#print(V)

if(judge(V)):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
import sys
from operator import itemgetter
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy
from collections import Counter, deque
from functools import reduce
sys.setrecursionlimit(200000)
# local only
# if not __debug__:
#     fin = open('in_1.txt', 'r')
#     sys.stdin = fin
# local only
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def fi(): return float(input())
def mfi(): return map(float, input().rstrip().split())
def lmfi(): return list(map(float, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template

import heapq
class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)

    def pop(self):
        return heapq.heappop(self.hq) * self.sign

    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)

    def top(self):
        return self.hq[0] * self.sign

def main():
    N, M = mi()
    A = lmi()
    q = Heapq(A, True)
    for i in range(M):
        x = q.pop()
        q.push(x // 2)
    print(-sum(q.hq))
    return


if __name__ == '__main__':
    if not __debug__:
        import doctest
        doctest.testmod()
    main()


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

int main() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;

    if((abs(a-c)<=d) || (abs(a-b)<=d && abs(b-c)<=d)) {
        cout<<"Yes"<<endl;
    } else{
        cout<<"No"<<endl;
    }
}

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

int main(){
    int N;
    cin >> N;
    double A[100];
    double sigma=0;
    for(int i=0;i<N;i++) cin >> A[i];

    
    for(int i=0;i<N;i++) {
        sigma += 1/A[i];
    }
    cout << 1.0/sigma << endl;
    return 0;
}

Measured memory_bytes: 256
N,M,X = map(int,input().split())
C = [0] * N
A = [None] * N
for i in range(N):
  c,*a = map(int,input().split())
  C[i] = c
  A[i] = a

INF = 10 ** 9
ans = INF
import itertools
for i in range(1,N + 1):
  for comb in itertools.combinations(range(N),i):
    cost = 0
    skills = [0] * M
    for c in comb:
      cost += C[c]
      for j in range(M):
        skills[j] += A[c][j]
    if cost >= ans:
      continue
    for s in skills:
      if s < X:
        break
    else:
      ans = cost

if ans == INF:
  print(-1)
else:
  print(ans)        

Measured memory_bytes: 9260