akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int n; cin >> n;
    vector<int> c(n), s(n), f(n);
    repeat(i, n) cin >> c[i] >> s[i] >> f[i];

    repeat(i, n) {
        int t = 0;
        repeat_from(j, i, n - 1) {
            //cout << "sts "; dump(i); dump(j); dump(n); dump(t); dump(c[j]); dump(s[j]); dump(f[j]); el;
            if (t < s[j]) {
                t = s[j];
            }
            else {
                t = ((t + f[j] - 1) / f[j]) * f[j];
            }
            t += c[j];
            //cout << "end "; dump(i); dump(j); dump(n); dump(t); dump(c[j]); dump(s[j]); dump(f[j]); el;
        }
        cout << t << endl;
    }
    
}

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

int main() {
  int N, X;
  cin >> N >> X;
  int L[N];
  for (int i = 0; i < N; i++) {
    cin >> L[i];
  }

  int D = 0;
  bool flag = 1;
  for (int i = 2; i <= N + 1; i++) {
    D = D + L[i - 2];
    if (D > X) {
      cout << i - 1 << endl;
      flag = 0;
      break;
    }
  }

  if (flag) {
    cout << N + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main{
	public static void main(String[] args) {
		Scanner scan =new Scanner(System.in);
		while(scan.hasNext()){
		int f=0;
		int n=scan.nextInt();
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				for(int k=0;k<10;k++){
					for(int l=0;l<10;l++){
						if(i+j+k+l==n){
							f++;
						}
					}
				}
			}
		}
		System.out.println(f);
		}
	}

}

Measured memory_bytes: 19328
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define Rep(i,a,b) for(ll i=a;i<b;i++)
#define pb emplace_back
#define allv v.begin(),v.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
#define FASTio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<(#x)<<" "<<x<<endl
ll mod=1e9+7;
template<typename t>
ll Max(ll a,ll b)
{
    return (a>b)?a:b;
    
}
ll Min(ll a,ll b)
{
    return (a>b)?b:a;
}
ll Power(ll a,ll b)
{
    ll p=1;
    a=a;
    b=b;
    while(b)
    {
        if(b&1)
        {
            p=((p)*(a));
        }
        a=((a)*(a));
        b=(b/2);
    }
    return p;
}
ll power(ll a,ll b)
{
    if(b==0)
    return 1;
    ll p=power(a,b/2)%mod;
    p=(p*p)%mod;
    if(b&1)
    p=(p*a)%mod;
    return p;
}
ll gcd(ll a,ll b)
{
    if(a==0)
    return b;
    return gcd(b%a,a);
}
/*void dfs(ll i)
{
    visited[i]=true;
   // provinces.pb(i);
    for(auto it:adj[i])
    {
        if(!visited[it] && choices[it])
        dfs(it);
    }
}*/
ll prod(ll a,ll b)
{
    return ((a%mod)*(b%mod))%mod;
}
ll add(ll a,ll b)
{
    return ((a%mod)+(b%mod))%mod;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    ll total=1,A=1,B=1,AinB=1;
    total=power(10,n);
    A=power(9,n);
    B=A;
    AinB=power(8,n);
    ll AunB=(add(A,B)%mod - (AinB%mod) + mod)%mod;
    ll ans=((total%mod) - (AunB)%mod + mod)%mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define mod (int)(998244353)
#define debugVec(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << " ";
    err(++it, args...);
}

signed main(){

    fastIO

    string s, t;
    cin >> s >> t;
    if (t.length() - 1 != s.length()){
    	cout << "No\n";
    }else{
    	string tmp = t.substr(0, s.length());
    	if (tmp == s){
    		cout << "Yes\n";
    	}else{
    		cout << "No\n";
    	}
    }
    
    return 0;
}

Measured memory_bytes: 3644
n = int(input())
a = list()
for i in range(120):
    a.append(0)
for i in range(n):
    b, f, r, v = map(int, input().split())
    a[(b - 1) * 30 + (f - 1) * 10 + (r - 1)] += v
for i in range(4):
    if i >= 1:
        print("#" * 20)
    for j in range(3):
        for k in range(10):
            print(' ', end = '')
            print(a[i * 30 + j * 10 + k], end = '')
        print()


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

int main(){
  int N, D, X;
  cin >> N >> D >> X;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  int choco = 0;
  for(int j=0; j<N; j++){
    if(D %vec.at(j) == 0){
     choco = choco + (D / vec.at(j));
    }
    else{
    choco = choco + (D / vec.at(j) + 1);
    }
  }
  
  cout << choco + X << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
using namespace std;
#define int long long
#define V vector
#define vel V<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp make_pair
#define pin pair<int,int>
pin solve(V<pin>& ab, int ex) {
	if (!ex) { return mkp(0, 0); }
	V<V<pin>> qab(2);
	int sz = ab.size();
	qab[0].reserve(sz);
	qab[1].reserve(sz);
	for (pin& x : ab) {
		qab[x.second & 1].push_back(mkp(x.first / 2, x.second / 2));
		if (x.first & 1) { qab[(x.second + 1) & 1].push_back(mkp(x.first / 2, (x.second + 1) / 2)); }
	}
	int c = 0;
	for (pin& x : qab[0]) {
		int qc = 2 * x.first + x.second + 1;
		qc = (qc & (0xffffffff)) + ((qc & (0x7fffffff00000000)) >> 32);//qc<=1ffffffff
		qc = (qc & (0xffff)) + ((qc & (0x1ffff0000)) >> 16);//qc<=2ffff
		qc = (qc & (0xff)) + ((qc & (0x3ff00)) >> 8);//qc<=3ff
		qc = (qc & (0x1f)) + ((qc & (0x3e0)) >> 5);//qc<=3e
		qc = (qc & 7) + ((qc & 56) >> 3);//qc<=14
		qc = (qc & 3) + ((qc & 12) >> 2);
		qc = (qc & 3) + ((qc & 4) >> 2);
		c ^= qc;
	}
	if (!c) {
		pin ans = solve(qab[1], ex - 1);
		ans.first *= 2; ans.second *= 2; ans.second++;
		return ans;
	}
	pin ans = solve(qab[0], ex - 1);
	c = 0;
	int d = 0;
	for (pin& x : qab[1]) {
		int w = ans.second - x.second - 1;
		if ((w & x.first) == w) { c ^= 1; }
		w++;
		if ((w & x.first) == w) { d ^= 1; }
	}
	ans.first *= 2; ans.second *= 2;
	ans.first += (c | d); ans.second -= c;
	return ans;
}
int per(int qc) {
	qc = (qc & (0xffffffff)) + ((qc & (0x7fffffff00000000)) >> 32);//qc<=1ffffffff
	qc = (qc & (0xffff)) + ((qc & (0x1ffff0000)) >> 16);//qc<=2ffff
	qc = (qc & (0xff)) + ((qc & (0x3ff00)) >> 8);//qc<=3ff
	qc = (qc & (0xf)) + ((qc & (0x3f0)) >> 4);//qc<=4e
	qc = (qc & (0xf)) + ((qc & (0x7e)) >> 4);//qc<=18
	qc = (qc & 3) + ((qc & 28) >> 2);
	qc = (qc & 3) + ((qc & 4) >> 2);
	return qc;
}
int qsum(int i) {
	if (i == 0) { return 0; }
	return i % 10 + qsum(i / 10);
}
signed main() {
	int n, a, b; cin >> n >> a >> b;
	int ans = 0;
	rep(i, n+1) {
		if (a <= qsum(i) && qsum(i) <= b) { ans+=i; }
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    v = list(map(int,input().split()))
    while len(v)>1:
        v.sort()
        v1 = v.pop(0)
        v2 = v.pop(0)
        v.append((v1+v2)/2)
    print(v[0])

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
S = input()
K = int(input())

# 2の5000兆乗はlog10をとると5000*log_10(2) ~ 1500となり明らかに10**18より大きいと分かる
# よってSを左から見て1以外の数値がK番目以内にあればそれが答え。そうでなければ1が答え

for i in range(K):
    if int(S[i]) != 1:
        print(int(S[i]))
        exit()
print(1)

Measured memory_bytes: 2940
N,T = map(int, input().split())
imos = [0]*(T+1)
for i in range(N):
	s,e = map(int, input().split())
	imos[s] += 1
	imos[e] -= 1
m = 0
num = 0
for i in imos:
	num += i
	m = max(num, m)
print(m)
#abaaksa



Measured memory_bytes: 6392
use proconio::{fastout, input};
use std::io::*;
use std::str::FromStr;

use std::cmp::{max, min};
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};

fn main() {
    input! {
        n: usize,
        m: usize,
        ab: [(usize, usize); m],
    }
    let mut uf = UnionFind::new(n);

    for i in 0..ab.len() {
        let i = ab[i];
        uf.unite(i.0 - 1, i.1 - 1);
    }

    let mut cnt = vec![0; n];
    for i in 0..n {
        cnt[uf.root(i)] = 1;
    }

    println!("{}", cnt.iter().sum::<i64>() - 1);
}

struct UnionFind {
    parent: Vec<usize>,
    size: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        // initialize
        let mut v: Vec<usize> = vec![];
        for i in 0..n + 1 {
            v.push(i)
        }
        let mut s: Vec<usize> = vec![1; n + 1];

        UnionFind { parent: v, size: s }
    }

    fn root(&self, x: usize) -> usize {
        if self.parent[x] == x {
            return x;
        } else {
            return self.root(self.parent[x]);
        }
    }

    fn size(&self, a: usize) -> usize {
        let ra = self.root(a);
        self.size[ra]
    }

    fn unite(&mut self, a: usize, b: usize) {
        let mut ra = self.root(a);
        let mut rb = self.root(b);
        if ra == rb {
            return;
        }
        if self.size[ra] < self.size[rb] {
            std::mem::swap(&mut ra, &mut rb)
        };
        self.size[ra] += self.size[rb];
        self.parent[rb] = ra;
    }

    fn same(&self, a: usize, b: usize) -> bool {
        let ra = self.root(a);
        let rb = self.root(b);
        ra == rb
    }
}


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

#define check cout<<"-------"<<endl
#define debug(x) cout<<x<<endl;
#define loop(i,x,n) for(int i = x; i < n; i++)
#define lop(i,n) repi(i,0,n)
#define fix(x) cout<<fixed<<setprecision(x);

int main() {
    
    while(1) {
        int h, w;
        cin>>h>>w;
        if(h == 0 && w == 0) break;
        
        for(int i = 1; i <= h; i++) {
            for(int j = 1; j <= w; j++) {
                if((i+j) % 2 == 0) cout<<'#';
                else cout<<'.';
            }
            cout<<endl;
        }
        cout<<endl;
    }
    
    return 0;
}



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


int32_t main()
{
    string odd,even;
    cin>>even>>odd;
    for(int i=0;i<max(odd.size(),even.size());i++)
    {
        if(i<even.size())
        cout<<even[i];
        if(i<odd.size())
        cout<<odd[i];
    }
}

Measured memory_bytes: 3556
from collections import defaultdict
N, K = [int(x) for x in input().split()]
snukes = defaultdict(list)
for i in range(K):
    d, = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]
    for x in A:
        snukes[x].append(i)
count = 0
for i in range(1, N + 1):
    if len(snukes[i]) == 0:
        count += 1
print(count)

Measured memory_bytes: 68268
#include<stdio.h>
#include<string.h>
char t[102][102],p[5]="v<^>";
int n,m,f[102][102],i,g[5]={1,0,-1,0,1};
void d(int r,int c)
{
	int j;
	if(f[r][c])
	{
		puts("LOOP");
		return;
	}
	if(t[r][c]=='.')
	{
		printf("%d %d\n",c,r);
		return;
	}
	f[r][c]=1;
	for(j=0;j<4;j++)
		if(t[r][c]==p[j])
			d(r+g[j],c+g[j+1]);

}
int main()
{
	for(;scanf("%d%d",&n,&m),n;)
	{
		memset(f,0,sizeof(f));
		for(i=0;i<n;i++)
			scanf("%s",t[i]);
		d(0,0);
	}
	return 0;
}

Measured memory_bytes: 692
//boom diggy diggy boom boom
/*
freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
      */
#include<bits/stdc++.h>
#define ull unsigned long long int 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define mod 1000000007
#define F first
#define S second
#define ll long long 
#define ld long double 

int power(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int ncr(int n,int r){int res=1;if(r>n-r)r=n-r;for(int i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
int gcd(int a,int b){if (a==0)return b;return gcd(b%a,a);}
int lcm(int a,int b){return (a/gcd(a,b)*b);}int max(int a,int b){int ans=a>b?a:b;return ans;}

using namespace std;

int main()
{
 int n;
 cin>>n;
 int a[n+1],b[n+1]={};
 for (int i = 1; i <= n; ++i)
    {
      cin>>a[i];
    }   
    b[2]=abs(a[2]-a[1]);
    
  for (int i = 3; i <= n; ++i)
  {
    int x=abs(a[i]-a[i-1])+b[i-1];
    int y=abs(a[i]-a[i-2])+b[i-2];
    b[i]=min(x,y);
  }
  cout<<b[n];
  
return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define INF (1<<30)
#define LLINF (1ll<<60)
typedef long long ll;

int main(void){
	int n,y,i,b,c,p,q;
	bool flag = false;
	cin >> n >> y;
	y /= 1000;
	for(i=0; i<=n; i++){
		p = y - 10*i;
		q = n - i;
		if((p-q)%4 == 0 && (p-q)/4 <= q && (p-q)/4 >= 0){
			b = (p-q)/4;
			c = q - b;
			cout << i << " " << b << " " << c << endl;
			flag = true;
			break;
		}
	}
	if(!flag){
		cout << "-1 -1 -1" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<string>
#include<tuple>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
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;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
long dfs(vector<long> A,long n,long N,long s){
  if(n==N)return s%2==0?1:0;
  long res=0;
  res+=dfs(A,n+1,N,s*(A[n]-1));
  res+=dfs(A,n+1,N,s*A[n]);
  res+=dfs(A,n+1,N,s*(A[n]+1));
  return res;
}
inline void solve(void){
  long N;
  in(N);
  vector<long> A(N);
  rep(i,N)in(A[i]);
  out(dfs(A,0,N,1));
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const long long INF = INT_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define REP1(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 ll long long int
using namespace std;
ll ans = 0, sum = 0, n, k, cnt = 0, w, h;
string s;
vector<ll> v;
vector<ll> v1;
vector < pair<ll, ll > > vp;
vector<vector<ll> > vv(50, vector<ll>(50, INF));
vector<string> vs;
vector<char> vc;
set<ll> st;
map<char, ll> mp;

/*--------------------template--------------------*/

int main()
{
	cin >> n;
	k = sqrt(n);
	w = 1;
	RREP(i,k+1)
	{
		if(n%i==0)
		{
			w = i;
			break;
		}
	}
	cout << max((to_string(w).length()), (to_string(n/w).length())) << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a;
  int b;
  int c;
  bool result=false;
  cin>>a>>b>>c;
  if(a==b&&a!=c){
    result=true;
  }else if(a==c&&a!=b){
    result=true;
  }else if(b==c&&b!=a){
    result=true;
  }
  if(result){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  ld ans = 0;
  FOR(i, 1, N+1){
    int now = i;
    ld ret = 1;
    while(now < K){
      now *= 2;
      ret /= 2;
    }
    ans += ret/N;
  }

  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    int n; ll w; cin >> n >> w;
    vector<vector<int> > ob(4);
    int a,b; cin >> a >> b;
    a--;
    ob[0].push_back(b);
    rep(i,n-1){
        int o; int v; cin >> o >> v;
        ob[o-a-1].push_back(v);
    }
    rep(i,4){
        sort(all(ob[i]));
        reverse(all(ob[i]));
    }

    int ans=0;

    rep(i,ob[0].size()+1){
        rep(j,ob[1].size()+1){
            rep(z,ob[2].size()+1){
                rep(k,ob[3].size()+1){
                    int tmp=0;
                    rep(ii,i) tmp+=ob[0][ii];
                    rep(jj,j) tmp+=ob[1][jj];
                    rep(zz,z) tmp+=ob[2][zz];
                    rep(kk,k) tmp+=ob[3][kk];
                    ll tmpw=((ll)i*(a+1))+((ll)j*(a+2))+((ll)z*(a+3))+((ll)k*(a+4));
                    if(tmpw<=w) ans=max(ans,tmp);
                }
            }
        }
    }

    cout << ans << endl;
return 0;
}



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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

const ll N = 333;
ll n;
double dp[N][N][N];

double rec(ll c1, ll c2, ll c3) {
	double c = c1+c2+c3;
	if (c == 0) return 0;
	if (dp[c1][c2][c3] > 0) return dp[c1][c2][c3];
	
	double res = n/c;
	if (c1) res += c1/c * rec(c1-1,c2,c3);
	if (c2) res += c2/c * rec(c1+1,c2-1,c3);
	if (c3) res += c3/c * rec(c1,c2+1,c3-1);
	return dp[c1][c2][c3] = res;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	ll c1 = 0, c2 = 0, c3 = 0;

	FOR(i,0,n) {
		ll a; cin >> a;
		if (a == 1) c1++;
		if (a == 2) c2++;
		if (a == 3) c3++;
	}
	cout << fixed << setprecision(20) << rec(c1,c2,c3) << endl;
}



Measured memory_bytes: 260224
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int r = Integer.parseInt(sc.next());
        
        if(n >= 10){
            System.out.println(r);
        }else{
            System.out.println(r + 100*(10-n));
        }
    }
}

Measured memory_bytes: 21844
#include <stdio.h>

int main(void)
{
        int v,n,i,a[i],b,s=0;

        scanf("%d",&n);
        v=n;
        b = n%10;

        for (i=0;i<3;i++){
                a[i]=n%10;
                n=n/10;
        }

        for (i=2;i>=0;i--){
                if (a[i]!=b){
                        b=-1;
                        break;
                }
        }

        if (b==-1){
                 s=a[2]*100+a[2]*10+a[2];

                if (v>s)
                        printf("%d\n",s+111);
                else
                        printf("%d\n",s);
        }
        else
                printf("%d\n",v);

        return 0;
}

Measured memory_bytes: 128
s, t = Array.new(2) { gets.chomp }
h = Hash.new { |h, k| h[k] = [] }

s.each_char.with_index { |c, idx| h[c] << idx }

pred = -1
count = 0
tally = Hash.new(0)

t.each_char do |c|
  if h[c].empty?
    puts -1
    exit
  end

  if (idx = h[c].drop(tally[c]).bsearch_index { |e| pred < e })
    pred = h[c][tally[c] += idx]
    tally[c] += 1
  else
    count += 1
    tally.clear
    pred = h[c][0]
    tally[c] = 1
  end
end

puts s.size * count + pred + 1

Measured memory_bytes: 16044
from itertools import combinations_with_replacement
N, M, Q = map(int,input().split())
ls = []
for _ in range(Q):
    a,b,c,d = map(int,input().split())
    ls.append((a-1,b-1,c,d))
ans = -1
for A in combinations_with_replacement(range(1,M+1),r=N):
    sm = 0
    for a,b,c,d in ls:
        if A[b]-A[a] == c:
            sm += d
    ans = max(ans, sm)
print(ans)

Measured memory_bytes: 9212
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax = 1e5;
int N, M, B[Nmax];
ll A[Nmax];

int main(){
	cin >> N >> M;
	for(int i=0; i<N; i++) cin >> A[i] >> B[i];

	vector<pair<ll, int> > xs(N);
	for(int i=0; i<N; i++) xs[i] = {A[i], B[i]};
	sort(xs.begin(), xs.end());

	ll sum = 0;
	for(int i=0; i<N; i++){
		ll a = xs[i].first;
		int b = xs[i].second;
		if(M>b){
			sum += a*b;
			M -= b;
		} else {
			sum += a*M;
			break;
		}
	}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000
int MOD=1000000007;
int n;
int dp[1001][1001];
signed main() {
cin>>n;
rep(ii,n){
  rep(p,1001){
    rep(q,1001){
      dp[p][q]=0;
    }
  }
  string x,y;
  cin>>x>>y;
  rep(i,x.size()){
    rep(j,y.size()){
      if(x[i]==y[j]){dp[i+1][j+1]=1+dp[i][j];}
      else dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
    }
  }
cout<<dp[x.size()][y.size()]<<endl;
 }
}



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

int main() {
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  if (x - r < 0 || x + r > W || y - r < 0 || y + r > H) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}



Measured memory_bytes: 3100
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,ans=0,cnt,a[100005]={};
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  for(int i=0; i<n-1; i++) {
    ans+=a[i]/2;
    if(a[i]%2&&a[i+1]!=0) {
      ans++;
      a[i+1]--;
    }
  }
  ans+=a[n-1]/2;
  cout << ans << endl;
}



Measured memory_bytes: 1152
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M=map(int,input().split())
uf=UnionFind(N)
for i in range(M):
    A,B=map(int,input().split())
    uf.union(A-1,B-1)
ans=0
for i in range(N):
    ans=max(ans,uf.size(i))

print(ans)


Measured memory_bytes: 14628
N=int(input())
f=[0]*N
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            n=x**2+y**2+z**2+x*y+y*z+z*x
            if n<=N:
                f[n-1]+=1
for i in range(N):
    print(f[i])

Measured memory_bytes: 9216
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int h, n;
  scanf("%d %d", &h, &n);
  int a[MAX];
  rep(i, 0, n) scanf("%d", &a[i]);

  int sum = 0;
  rep(i, 0, n) sum += a[i];
  printf(sum >= h ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
  int L,A,B,C,D,day=0,endA=0,endB=0,ans;

  scanf("%d", &L);
  scanf("%d", &A);
  scanf("%d", &B);
  scanf("%d", &C);
  scanf("%d", &D);

  for(;;){
    if(A>0){
      A=A-C;
    } else {
      endA++;
    }
    if(B>0){
      B=B-D;
    } else {
      endB++;
    }
    if(endA>0&&endB>0) break;
    day++;
  }

  ans=L-day;
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 596
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void run(){
		int left[] = new int[4];
		int right[] = new int[4];
		double[] border ={0.15,0.55,1.05,3.5};
		for(;sc.hasNextDouble();){
			double l = sc.nextDouble();
			int i = 0;
			for(;border[i] < l;i++){
			}
			
			left[i]++;
			double r = sc.nextDouble();
			i = 0;
			for(;border[i] < r;i++){
			}
			right[i]++;
		}
		for(int i = 3; i >= 0; i--){
			System.out.println(left[i] + " "+ right[i]);
		}
	}
	public static void main(String[] args){
		Main m = new Main();
		m.run();
	}
}

Measured memory_bytes: 0
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;


class Program
{
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);

        var n = Read();
        bool b = false;
        for(int i = 1; i < 10; i++)
        {

            if (n % i == 0)
            {
                long a = n / i;
                if (a < 10)
                    b = true;
            }
        }
        if (b)
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");


        Console.Out.Flush();
    }
}

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

using namespace std;

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

int main(void)
{
  int n;
  cin >> n;
  vec<int> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) b[i] = a[i];

  sort(b.begin(), b.end());
  rep(i, n) {
    if (a[i] == b[n - 1]) cout << b[n - 2] << endl;
    else cout << b[n - 1] << endl;
  }
  return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 2e5 + 10;
char s[M];
int b[M], vis[M], vis1[M];
int cnt;
int main(){
    int n, k, c;
    scanf("%d%d%d", &n, &k, &c);
    scanf("%s", s + 1);
    int sum = 0;
    for(int i = 1; i <= n; ) {
        if(s[i] == 'x') i++;
        else {
            sum++;
            b[sum] = i;
            i += c + 1;
        }
        if(sum == k) break;
    }
    //for(int i = 1; i <= k; i++) printf("%d\n", b[i]);
    for(int i = n; i >= 1; ) {
        if(s[i] == 'x') i--;
        else if(b[sum] == i) vis[b[sum]] = 1, sum--, i--;
        else if((sum == k || (b[sum + 1] - i) > c) && (sum == 1 || (i - b[sum - 1]) > c)){
            b[sum] = i;
            sum--;
            i -= c + 1;
        }
        else i--;
        if(sum == 0) break;
    }
    for(int i = 1; i <= k; i++) if(vis[b[i]]) printf("%d\n", b[i]);
    return 0;
}


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

def main():
    N = int(input())
    a = list(map(int, input().split()))

    ans = int(1e10)
    for t in a:
        tmp = 0
        while not t&1:
            t //= 2
            tmp += 1
        ans = min(ans, tmp)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int N, M;

int main() {

    while (cin >> N >> M) {
        int l_max = 1, r_min = N;
        int L[M], R[M];
        for (int i = 0; i < M; i++) {
            cin >> L[i] >> R[i];
            l_max = max(l_max, L[i]);
            r_min = min(r_min, R[i]);
        }
        int ret = r_min - l_max + 1;
        if (ret < 0) {
            ret = 0;
        }
        cout << ret << endl;
    }

    return 0;
}


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

int main(void){
/*  char tmp[12];
  char year[5];
  char month[3];
  char day[3];*/
  int y, m, d;
//  scanf("%s", m);
//  printf("aaaaa");
//  y = 2019;
//  m = 03;
//  d = 16;
//  year = strncpy(year, tmp, 4);
//  month = strncpy(month, tmp+5, 2);
//  day = strncpy(day, tmp+8, 2);
  scanf("%d/%d/%d", &y, &m, &d);

//  y = atoi(year);
//  m = atoi(month);
//  d = atoi(tmp);
  
  if(y > 2019){
    printf("TBD");
  }else if( y < 2019){
    printf("Heisei");
  }else if( m > 4){
    printf("TBD");
  }else if(m < 4){
    printf("Heisei");
  }else if(d > 30){
    printf("TBD");
  }else{
    printf("Heisei");
  }
    
 return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <int> :: iterator sitr;
typedef set <ll> :: iterator sltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef mset <int> :: iterator msitr;
typedef mset <ll> :: iterator msltr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template
ll md = 1000000007;
ll n,m,k,temp;
ll p (ll a, ll b){
    if(b==0)return 1;
    else if(b==1)return a;
    else{
        ll temp = p (a,b/2);
        ll t = ((temp % md) * (temp % md))%md;
        if(b%2==1){ t = ((t%md) * (a%md))%md; }
        return t;
    }
}
ll ans = 0,occ;
ll choose (ll a, ll b){
    if(a<b)return 0;
    else if(b==0)return 1;
    else if(b==1)return 2;
    else{
        ll c = a-b;
        if(b<c)swap(b,c);

        vll up,down;
        for(int i=a;i>max((ll)1,b);i--)up.pb(i);
        for(int i=2;i<=c;i++)down.pb(i);

        ll u,d;
        u = 1;
        d = 1;
        for(int i=0;i<up.size();i++){
            u = ((u%md) * (up[i]%md))%md;
        }
        for(int i=0;i<down.size();i++){
            d = ( (d%md) * (down[i]%md) ) % md;
        }
        ll inverse = p (d , md-2);
        inverse %= md;

        ll total = ((u % md) * (inverse % md))%md;
        return total;
    }

}
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m>>k;
    occ = choose (n*m - 2 , k - 2);

    for(int i=1;i<m;i++){
        temp = ((n*n)%md * (m-i)%md)%md;
        temp = ((i%md)*(temp%md))%md;
        ans = ((ans%md) + (temp%md))%md;
    }

    for(int i=1;i<n;i++){
        temp = ( (m*m)%md * (n-i)%md )%md;
        temp = ((i%md)*(temp%md))%md;
        ans = ((ans%md) + (temp%md))%md;
    }

    ans = ((ans%md) * (occ%md))%md;
    cout<<ans<<newl;

}


Measured memory_bytes: 2292
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

const int MAX_N = 1e+5 + 1;

ll X[MAX_N];

int main() {
    int N, M;
    ll sum = 0;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> X[i];
    }
    if (N >= M) {
        cout << 0 << endl;
        return 0;
    }
    sort(X, X + M);
    vector<ll> a;
    for (int i = 0; i < M - 1; i++) {
        a.push_back(X[i + 1] - X[i]);
        sum += X[i + 1] - X[i];
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    for (int i = 0; i < N - 1; i++) {
        sum -= a[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 2168
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct tagItem Item;
struct tagItem {
    int value;
    Item *prev;
};

void push(Item **sp, int value)
{
    //printf("push %d\n", value);
    Item *item = (Item *)malloc(sizeof(Item));
    item->value = value;
    item->prev = *sp;
    *sp = item;
}

int pop(Item **sp)
{
    Item *item = *sp;
    if (item != NULL) {
        int value = item->value;
        *sp = item->prev;
        free(item);
        //printf("pop %d\n", value);
        return value;
    }
    //printf("pop error\n");
    return 0;
}

int main(void)
{
    Item *stack = NULL;
    char s[1000];
    char *tk;
    int v1, v2;
    fgets(s, 999, stdin);
    s[strlen(s) - 1] = '\0';

    tk = strtok(s, " ");
    while (tk != NULL) {
        //printf("tk=[%s]\n", tk);
        if (strcmp(tk, "+") == 0) {
            v2 = pop(&stack);
            v1 = pop(&stack);
            push(&stack, v1 + v2);
        }
        else if (strcmp(tk, "-") == 0) {
            v2 = pop(&stack);
            v1 = pop(&stack);
            push(&stack, v1 - v2);
        }
        else if (strcmp(tk, "*") == 0) {
            v2 = pop(&stack);
            v1 = pop(&stack);
            push(&stack, v1 * v2);
        }
        else if (strcmp(tk, "/") == 0) {
            v2 = pop(&stack);
            v1 = pop(&stack);
            push(&stack, v1 / v2);
        }
        else {
            push(&stack, atoi(tk));
        }
        tk = strtok(NULL," .");
    }
    v1 = pop(&stack);
    printf("%d\n", v1);

    return 0;
}


Measured memory_bytes: 2108
import itertools
N,M = map(int,input().split())
B = {}
for i in range(1,M+1):
    row = list(map(int,input().split()))
    row.pop(0)
    B[i] = row
P = list(map(int,input().split()))
P.insert(0,-1)
cnt = 0
for x in itertools.product((0,1),repeat=N):
    ind = 1
    for i in range(1,M+1):
        sw = 0
        for j in B[i]:
            if x[j-1]==1:
                sw += 1
        if sw%2!=P[i]:
            ind = 0
            break
    if ind==1:
        cnt += 1
print(cnt)

Measured memory_bytes: 3064
r, c = gets.split.map(&:to_i)
last = Array.new( c, 0 )
r.times do
  line = gets.split.map(&:to_i)
  puts line.join(" ")+" "+line.inject(:+).to_s
  last = last.zip( line ).map{ | x, y | x + y }
end
puts last.join(" ")+" "+last.inject(:+).to_s

Measured memory_bytes: 6124
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int m = input.nextInt();
        int k = input.nextInt();
        
        for(int i = 0; i<=n; i++)
        {
            for(int j = 0; j<=m; j++)
            {
                if(i*m + j*n - 2*i*j == k)
                {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 23764
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define pli pair<long long , int>
#define pil pair<int ,long long>
#define pi acos(-1)
#define pb push_back
#define mkp make_pair
#define all(a) a.begin(), a.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;




int main(){
    IOS
    //freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    double arr[n];

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

    sort(arr,arr+n);

    for(int i=1;i<n;i++){
        arr[i]=(arr[i]+arr[i-1])/2.0;
    }
    cout<<fixed<<setprecision(5)<<arr[n-1];
}


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

#define x first
#define y second
#define rs resize
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define rep(i,a,b) for(auto i=(a);i!=(b); ++i)
#define REP(i,n) rep(i,0,n)
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
template<class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;

template<class T1, class T2>
ostream& operator<<(ostream &out, const pair<T1,T2> &a) { return out << '(' << a.x << ", " << a.y << ')'; }
template<class T1, class T2>
istream& operator>>(istream &in, pair<T1,T2> &a) { return in >> a.x >> a.y; }

const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;

// lambda-expression: [] (args) -> retType { body }

void run() {
	int n;
	cin >> n;

	vector<int> cnt0(64, 0), cnt1(64, 0);

	while (n--) {
		ll x;
		cin >> x;

		REP(i, 64) {
			if (x & 1)
				cnt0[i]++;
			else
				cnt1[i]++;
			x >>= 1;
		}
	}

	const ll mod = 1e9 + 7;
	ll answer = 0;

	ll p2 = 1LL;
	REP(i, 64) {
		answer += ((p2 * cnt0[i] % mod) * cnt1[i] % mod);
		answer %= mod;
		p2 = (2LL * p2) % mod;
	}
	cout << answer << endl;

}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cerr << boolalpha;
	(cout << fixed).precision(10);

	run();

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 1020000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << "debug: " << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << "debug: " << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	int h,w; cin >> h >> w;
	vl a(h), b(h);
	rep(i,h) cin >> a[i] >> b[i], a[i]--, b[i]--;
	vector<int> val(w,0);
	set<int> se;
	multiset<int> mse;
	rep(i,w) mse.insert(0);
	rep(i,w) se.insert(i);
	rep(i,h){
		auto itr = se.lower_bound(a[i]);
		vector<int> era;
		for(auto it = itr; it != se.end(); it++){
			if(*it > b[i]) break;
			int tmp = val[*it] + b[i] + 1 - *it;
			if(b[i]+1 != w){
				if(val[b[i]+1] > tmp){
					mse.erase(mse.find(val[b[i]+1]));
					mse.insert(tmp);
					chmin(val[b[i]+1], tmp);
				}
			}
			mse.erase(mse.find(val[*it]));
			mse.insert(inf);
			val[*it] = inf;
			era.push_back(*it);
		}
		for(auto j : era) se.erase(j);
		if(b[i] + 1 < w) se.insert(b[i]+1);
		int ans = *mse.begin();
		if(ans == inf) cout << -1 << "\n";
		else cout << ans + i + 1 << "\n";
	}
}

Measured memory_bytes: 25952
#include <bits/stdc++.h>
using namespace std;
 
#define rep for(int i = 0;i<n;i++)
const int MOD = 1000000007;
 
int main(){
    int n; cin >> n;
   int a[n-1];for(int i = 0;i<n-1;i++){
       cin >> a[i];
   }
   int ans = a[0]+a[n-2];
    for(int i = 1;i<n-1;i++){
        ans += min(a[i-1],a[i]);
    }
    cout << ans << endl;
}

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

using namespace std;
using ll = long long;


int main()
{
    int n, m; cin >> n >> m;
    vector<vector<int>> hen(n);
    for(int i = 0; i < m; i++) {
        int a, b; cin >> a >> b; a--, b--;
        hen[a].push_back(b);
        hen[b].push_back(a);
    }
    vector<int> a(n);
    iota(a.begin(), a.end(), 0);
    int cnt = 0;
    do {
        if(a.front() != 0)continue;
        bool res = true;
        for(int i = 0; i < n - 1; i++) {
            bool fff = false;
            for(auto j : hen[a[i]])if(j == a[i + 1])fff = true;
            if(!fff)res = false;
        }
        cnt += res;

    }while(next_permutation(a.begin(), a.end()));
    cout << cnt << endl;
}

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

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

int main(){
    ll n,x;
    cin >> n >> x;
    vector<ll> y(n);
    int in;
    for(int i=0;i<n;i++){
        cin >> in;
        y[i] = abs(x-in);
    }
    ll d = y[0];
    for(int i=1;i<n;i++){
        d = gcd(d,y[i]);
    }
    cout << d << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cout << #x << " " << x << endl;

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}
template<typename... T>
void write_space(T... a){
    ((cout << a << " "),...);
}

void solve(){
    int n;
    read(n);
    vi a(n);
    REP(i,n){
        cin >> a[i];
        a[i]--;
    }     
    vi c(n);
    int cur = 0;
    while(true){
        if (c[cur] > 1){
            break;
        }else{
            c[cur]++;
            if( cur == 1) break;
            cur = a[cur];
        }
    }
    if( c[1] == 0){
        cout << -1 << endl;
    }else{
        int move = 0;
        for(const auto & m : c){
            move += m;
        }
        cout << move - 1 << endl;
    }
} 

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 2;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}

//Thanks to CSES problemset
// I am trained with this kind of problem

Measured memory_bytes: 3972
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;


int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans = 0;
	while (true) {
		for (int i = 0; i < n; i++) {
			if (a[i] % 2 != 0) {
				cout << ans << endl;
				return 0;
			}
			a[i] /= 2;
		}
		ans++;
	}
	return 0;
}

Measured memory_bytes: 256