akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Map.Entry;


public class  Main{
    public static void main(String[] args) throws Exception{
    	MScanner sc = new MScanner(System.in);
        //MScanner sc = new MScanner("reduce.in");
        PrintWriter pw=new PrintWriter(System.out);
        //int n=sc.nextInt();
        //Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=sc.nextInt();
        char[]in=sc.nextLine().toCharArray();for(int i=1;i<4;i++)if(in[i]==in[i-1]) {pw.println("Bad");pw.flush();return;}
        pw.println("Good");
        pw.flush();
    }
    static StringBuilder tosb(int[]in) {
    	StringBuilder s=new StringBuilder();
    	for(int i=0;i<in.length;i++) {
    		s.append(in[i]+" ");
    	}
    	return s;
    }
    static StringBuilder tosb(long[]in) {
    	StringBuilder s=new StringBuilder();
    	for(int i=0;i<in.length;i++) {
    		s.append(in[i]+" ");
    	}
    	return s;
    }
    
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 21076
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int n,ma,mb;
int INF=100000;
int a[41],b[41],c[41];
int dp[41][401][401];

int main(){
  cin>>n>>ma>>mb;
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
  }

  for(int i=0;i<=n;i++){
    for(int j=0;j<=400;j++){
      for(int k=0;k<=400;k++){
        dp[i][j][k]=INF;
      }
    }
  }
  dp[0][0][0]=0;

  for(int i=0;i<n;i++){
    for(int j=0;j<=400;j++){
      for(int k=0;k<=400;k++){
        if(dp[i][j][k]==INF) continue;
        dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]);
        dp[i+1][j+a[i]][k+b[i]]=min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
      }
    }
  }

  int ans=INF;
  for(int i=1;i<=400;i++){
    for(int j=1;j<=400;j++){
      if(i*mb==j*ma) ans=min(ans,dp[n][i][j]);
    }
  }
  if(ans==INF) ans=-1;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 25984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    ll n;
    cin >> n;
    vi a(n+1);
    vi b(n);
    ll sum = 0;
    rep(i,n+1){
        cin >> a[i];
        sum += a[i];
    }
    rep(i,n){
        cin >> b[i];
    }

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

    
    ll nokori=0;
    rep(i,n+1){
        nokori += a[i];
    }

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

Measured memory_bytes: 1152
#include<list>
#include<iostream>
using namespace std;
int main(){
  int i;
  int n;
  long long c;
  for(;;){
    cin>>n;
    if(n==0)
      break;
    list<int> t;
    c=0;
    for(i=0;i<n;i++){
      int tmp;
      cin>>tmp;
      t.push_back(tmp);
    }
    t.sort();
    list<int>::iterator it=t.begin();
    for(i=0;i<n-1;i++){
      c+=(*it)*(n-i-1);
      it++;
    }
    cout<<c<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N,M; //都市の数、道路の数
cin >>N >>M;
int a,b; //都市の番号
vector<int> count(N); //その都市から出ている道路の数

//数を数える
for(int i=0;i<M;i++)
{
cin >>a >>b; //その道路が結んでいる都市を入力
count.at(a-1)++;
count.at(b-1)++;
}
//数えた数を出力
for(int i;i<N;i++)
{
cout <<count.at(i) <<endl;
}


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n, q; string s; cin >> n >> s >> q;
    map<char, set<ll>> d;
    rep(i, n) d[s[i]].insert(i);
    rep(i, q){
        ll cmd; cin >> cmd;
        if(cmd == 1){
            ll idx; char c;
            cin >> idx >> c; idx--;
            if(s[idx] == c) continue;
            d[s[idx]].erase(idx);
            s[idx] = c;
            d[c].insert(idx);
        }
        else if(cmd == 2){
            ll l, r, cnt = 0; cin >> l >> r; l--; r--;
            for(auto &p: d){
                auto it = p.second.lower_bound(l);
                if(it == p.second.end()) continue;
                if(*it <= r) cnt++;
            }
            cout << cnt << endl;
        }
    }
}


Measured memory_bytes: 27192
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
#define PI 3.14159265358979323846264338327950L
typedef unsigned long long uint64;
using namespace std;
using ll = long long;
int main(){
  long int a;
  long double b;
  cin >> a>> b;
  int y = (b*100)+0.5;
  cout << (a*y)/100 << endl;
   return 0;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << c << " " << a << " " << b << endl;
}


Measured memory_bytes: 256
6# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N,M,Q=map(int,input().split())
    x=[[0]*N for _ in range(N)]
    for i in range(M):
        L,R=map(lambda x: int(x)-1,input().split())
        x[L][R]+=1
    S=[[0]*(N+1) for _ in range(N)]
    for i in range(N):
        for j in range(N):
            S[i][j+1]=S[i][j]+x[i][j]
    for _ in range(Q):
        ans=0
        p,q=map(lambda x: int(x)-1,input().split())
        for i in range(p,q+1):
            ans+=S[i][q+1]-S[i][p]
        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 57564
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
 
int main() {
  int n,Y;
  cin >> n >> Y;
  Y = Y/1000;
  int a,b,c;
  bool x = false;
  bool y = false;
  
  for(int i=0;i<Y;i++){
    for(int j=0;j<Y;j++){
      a=i;b=j;
      c =n-a-b;
      int sum = 10*a + 5*b + c;
      if(a+b+c==n && sum==Y && c>=0){
        cout<<a<<" "<<b<<" "<<c<<endl;
        x = true;
        y = true;
        break;
      }
    }
    if(x)
      break;
  }
  if(!y)
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> L(n);
    copy_n(istream_iterator<int>(cin), n, L.begin());
    sort(L.begin(), L.end());

    int64_t ans = 0;
    for (int i = 0; i < n; i++){
        for (int j = i + 1; j < n; j++){
            auto r = lower_bound(L.begin() + j + 1, L.end(), L[i] + L[j]);
            ans += r - (L.begin() + j + 1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
     
void sclcS(int a, int b) {
    int S, L;
    S = a * b;
    L = a * 2 + b * 2;
    printf("%d %d\n", S, L);
}
     
int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    sclcS(a, b);
    return 0;
}

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

int main() {
  int d;
  cin >> d;
  vector<int> c(26);
  vector<int> sum(26, 0);
  rep(i, 26) cin >> c[i];
  vector<vector<int>> s(d, vector<int>(26));
  rep(i, d)
    rep(j, 26)
      cin >> s[i][j];
  rep(i, d){
    int maxhuman = 0;
    int maxindex;
    rep(j, 26){
      sum[j] += c[j];
      if(maxhuman < sum[j]){
        maxhuman = sum[j];
        maxindex = j;
      }
    }
    int biggest = 0;
    int bigday;
    rep(j, 26){
      if(biggest < s[i][j]){
      	biggest = s[i][j];
        bigday = j;
      }
    }
    if(maxhuman < biggest){
      cout << bigday+1 << endl;
      sum[bigday] = 0;
    }else{
      cout << maxindex+1 << endl;
      sum[maxindex] = 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3684
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

a,b,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
xyc=[list(map(int,input().split())) for i in range(m)]

ans=float('inf')
ans=min(ans,min(a)+min(b))
for i in range(m):
    x,y,c=xyc[i]
    ans=min(ans,a[x-1]+b[y-1]-c)
print(ans)

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

#define col first
#define cn second

typedef pair<int, int> PR;

pair<int, int> puyo[10000+10] , tmp;

int sum;


int chek(int , /*PR[10000 + 10],*/ int ,int,int);


int main()
{
	int n;
	int pn=0;

	int a;

	int i;

	int sa=0;

	while (cin >> n, n != 0)
	{
		sa = 0;
		sum = n;
		pn = 0;

		cin >> a;
		puyo[pn].col = a;
		puyo[pn].cn = 1;


		for (i = 1; i < n; i++)
		{
			cin >> a;

			if (puyo[pn].col == a)
			{
				puyo[pn].cn++;
			}
			else
			{
				pn++;
				puyo[pn].col = a;
				puyo[pn].cn = 1;
			}
		}

		pn++;

		for (i = 1; i < pn - 1; i++)
		{

			if (puyo[i].cn == 3)
			{
				if (puyo[i + 1].col == puyo[i - 1].col && puyo[i + 1].cn + puyo[i - 1].cn >= 5)
				{
					//tmp = puyo[i + 1];
					//puyo[i + 1].cn--;

					sa = 3 + puyo[i + 1].cn + puyo[i - 1].cn;

					sum = min(sum, n - chek(pn, i - 2, i + 2, sa));
					//puyo[i + 1] = tmp;
				}
			}

			if( puyo[i+1].cn==1 && puyo[i].col == puyo[i+2].col )
			{
				if (puyo[i].cn + puyo[i + 2].cn >= 3)
				{
					//puyo[i + 1].cn--;
					sa = 1 + puyo[i].cn + puyo[i + 2].cn;

					sum = min(sum, n - chek(pn, i - 1, i + 3, sa));
					
				}
			}
/*
			if (puyo[i - 1].cn == 1 && puyo[i].col == puyo[i - 2].col)
			{
				if (puyo[i].cn + puyo[i - 2].cn >= 3)
				{
					//puyo[i - 1].cn--;
					sa = 1 + puyo[i].cn + puyo[i - 2].cn;

					sum = min(sum, n - chek(pn, i - 3, i + 1, sa));
				}
			}
*/
			
		}
		
		cout << sum << endl;
	}
	return 0;
}


int chek(int pn/*, PR tp[10000 + 10]*/, int go, int ba , int sa)
{
	if (puyo[go].col == puyo[ba].col && puyo[go].cn + puyo[ba].cn >= 4)
	{
		sa += puyo[go].cn + puyo[ba].cn;

		if (go - 1 >= 0 && ba + 1 < pn)
		{
			return chek(pn, go - 1, ba + 1, sa);
		}

	}

	return sa;
}

Measured memory_bytes: 3168
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>    
#define inf 100000000
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
double dmax(double a,double b){
    return a>b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct
#define N 100000
int rank[N],p[N];

void initialize(int n){
    int i;
    rep(i,n){
        p[i]=i;
        rank[i]=0;
    }
}

int find_set(int x){
    if(x!=p[x])
        p[x]=find_set(p[x]);
    return p[x];
}

void link(int x,int y){
    if(rank[x]>rank[y])
        p[y]=x;
    else{
        p[x]=y;
        if(rank[x]==rank[y])
            rank[y]++;
    }
}
void unite(int x,int y){
    link(find_set(x),find_set(y));
}

int same(int x,int y){
    return find_set(x)==find_set(y);
}

int main(void){
    int n=in(),q=in(),a,b,t,i;
    initialize(n);
    rep(i,q){
        t=in(),a=in(),b=in();
        if(t==0)unite(a,b);
        else print(same(a,b));
    }
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin>>s;
  int n=s.size();
  int x=753;

  int ans=50000;
  for(int i=0;i+2<n;i++){
    int tmp=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0')*1;
    ans=min(ans,abs(x-tmp));
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
def check_w(arr):
    a = 0
    if len(arr) % 2 != 0:
        return False
    else:
        for i in range(len(arr)-1):
            a += 1
            if arr[i] != arr[i+1]:
                if a % 2 != 0:
                    return False
                a = 0
    return True

w = list(input())
w.sort()
if check_w(w):
    print("Yes")
else:
    print("No")


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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int i = 'a';
  int k = 'A';
  int h = i-k;
  for(int j=0;j<s.size();j++){
    s.at(j) += n;
    if(s.at(j) >= k+26){
      s.at(j) -= 26;
    }
  }
  cout << s << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

signed main(){
  int n;
  cin>>n;
  int c[4]={};
  REP(i,n){
    char a;
    cin>>a;
    if(a=='P')c[0]=1;
    else if(a=='W')c[1]=1;
    else if(a=='G')c[2]=1;
    else if(a=='Y')c[3]=1;
  }
  if(c[3]==1){
    cout<<"Four"<<endl;
  }else{
    cout<<"Three"<<endl;
  }
   return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {
	int n, m, x, y, maxx, miny;
	cin >> n >> m >> x >> y;
	maxx = x, miny = y;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		maxx = max(maxx, x);
	}
	for (int i = 1; i <= m; i++) {
		int x;
		cin >> x;
		miny = min(miny, x);
	}
	if (maxx < miny) cout << "No War" << endl;
	else cout << "War" << endl;
	//getchar(); getchar(); getchar();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
    ios_base::sync_with_stdio(0); cin.tie(0); 
    freopen((s+".in").c_str(),"r",stdin);
    freopen((s+".out").c_str(),"w",stdout);
}
ll pwrTwo[800001],pwrTwo1[800001];
ll getMod(string str, ll n, ll k)  
{    
    pwrTwo[0] = 1 % k;  
    for (ll i = 1; i < n; i++)  
    {  
        pwrTwo[i] = pwrTwo[i - 1] * (2 % k);  
        pwrTwo[i] %= k;  
    }  
    ll res = 0;  
    ll i = 0, j = n - 1;  
    while (i < n)  
    {  
        if (str[j] == '1')  
        {  
            res += (pwrTwo[i]);  
            res %= k;  
        }  
        i++;  
        j--;  
    }  
    return res;  
} 
ll getModi(string str, ll n, ll k)  
{    
    pwrTwo1[0] = 1 % k;  
    for (ll i = 1; i < n; i++)  
    {  
        pwrTwo1[i] = pwrTwo1[i - 1] * (2 % k);  
        pwrTwo1[i] %= k;  
    }  
    ll res = 0;  
    ll i = 0, j = n - 1;  
    while (i < n)  
    {  
        if (str[j] == '1')  
        {  
            res += (pwrTwo1[i]);  
            res %= k;  
        }  
        i++;  
        j--;  
    }  
    return res;  
}
int main()
{
  flash;
  ll n;
  string x;
  cin>>n;
  cin>>x;
  ll y=0;
  for (ll i = 0; i < sz(x); ++i)
  {
      if(x[i]=='1')y++;
  }
  ll f=y+1,z=y-1;
  ll yo=1,ko=1;
  ll rem=0,rem1=0;
  if(f>0)rem=getMod(x,sz(x),f);
  if(z>0)rem1=getModi(x,sz(x),z);
  reverse(all(x));
  ve ans;
  for (ll i = 0; i < sz(x); ++i)
  {
    ll yo=0;
    if(z==0 && x[i]=='1'){
        ans.pb(0);
    }
    else{
        if(x[i]=='1'){
        if(z>0)yo=(rem1-pwrTwo1[i]+z)%z;
    }
    else{
        if(f>0)yo=(rem+pwrTwo[i])%f;
    }
    ll cur=yo;
    ll ans1=0;
    while(cur){
        ll nb=0;
        for (ll j = 0; j <= log2(cur)+3; ++j)
        {
            if((cur&(ll)(pow(2,j))))nb++;
        }
        if(nb!=0)
            cur=cur%nb;
        ans1++;
    }
    ans.pb(ans1+1);
    }  
  }
  reverse(all(ans));
  for(auto it:ans)cout<<it<<'\n';
  return 0;
}
//code the AC sol !
// BS/queue/map

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

using namespace std;

int k, cnt = 0; long long ans;

void dfs(long long x, int n)
{
  if (n > 12) {
    ++cnt;
    if (cnt == k+1) ans = x;
  } else if (!x) {
    for (int i = 0; i <= 9; ++i) dfs(x*10+i, n+1);
  } else {
    if (x%10 != 0) dfs(x*10+x%10-1, n+1);
    dfs(x*10+x%10, n+1);
    if (x%10 != 9) dfs(x*10+x%10+1, n+1);
  }
}

int main()
{
  cin >> k;
  
  dfs(0, 0);
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
//  cout.precision(15); cout << fixed;

typedef pair<ll, ll> P;

int main() {
  int n, k; cin >> n >> k;
  vector<int> A(n); loop(i,0,n) cin >> A[i];
  sort(A.rbegin(), A.rend());
  int total = 0;
  loop(i,0,min(k,n)) total += A[i];
  cout << total << endl;
  return 0;
}


Measured memory_bytes: 3588
#include<iostream>
using namespace std;
#include<string>
#define REP(i,a,b) \
for(int i=a; i<b; i++)
#include<bits/stdc++.h>
#include<algorithm>
#define ll long long int
typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define tr(c,i) for(typeof(c.begin()) i = (c).begin(); i != (c).end();i++)

void solve(string &s, string &t, int i, int j, vector<int> *dp)
{
	if(i == 0 || j == 0)
		dp[i][j] = 0;
	else if(dp[i][j] >= 0)
		return;
	else
	{
		solve(s,t,i-1,j,dp);
		solve(s,t,i,j-1,dp);
		solve(s,t,i-1,j-1,dp);
		int extra = 0;
		if(s[i-1] == t[j-1])extra = 1;
		dp[i][j] = max(dp[i-1][j],max(dp[i][j-1],extra+dp[i-1][j-1]));
	}
}

int main()
{
	string s,t;
	cin >> s >> t;
	int n = s.length(), m = t.length();
	vector<int> dp[n+1];
	REP(i,0,n+1)dp[i].resize(m+1,-1);
	solve(s,t,n,m,dp);
	int i=n, j=m;
	string ans = "";
	while(i>0 && j>0)
	{
		if(s[i-1] == t[j-1])
		{
			ans = ans + s[i-1];
			i--;
			j--;
		}
		else if(dp[i-1][j] > dp[i][j-1])
			i--;
		else
			j--;
	}
	reverse(ans.begin(),ans.end());
	cout << ans;
}






Measured memory_bytes: 36096
#include <iostream>
using namespace std;
typedef long long ll;
int main(void){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
        if(a>b)swap(a,b);
        ll ans;
        ll s=0;
        ll g=1<<30;
        ll mid;
        while(g-s>1){
            mid=(s+g)/2;
            if(b-a<mid)g=mid;
            else{
                if(mid%2==1){
                    if(((mid+1)/2+a)*((mid+1)/2+a-1)<a*b)s=mid;
                    else g=mid;     
                }
                else{
                    if((mid/2+a)*(mid/2+a-1)<a*b && (mid/2+a+1)*(mid/2+a)<a*b)s=mid;
                    else g=mid;
                }
            }
            //if(i==1)cout<<s<<g<<endl;
        }
        
                if(g%2==1){
                    if(((g+1)/2+a)*((g+1)/2+a-1)<a*b)ans=g;
                    else ans=s;     
                }
                else{
                    if((g/2+a)*(g/2+a)<a*b && (g/2+a+1)*(g/2+a-1)<a*b)ans=g;
                    else ans=s;
                }
        cout<<2*(a-1)+ans<<endl;
    }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;


int main()
{
  ll n; cin>>n;
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i, n) cin>>a[i];
  rep(i, n) cin>>b[i];
  vector<pair<ll, ll>> c(n);
  ll asum = 0;
  ll bsum = 0;
  ll sum = 0;
  rep(i, n) {
    asum += a[i];
    bsum += b[i];
    sum += max(0LL, a[i] - b[i]);
    c[i] = make_pair(a[i]-b[i], i);
  }
  if (asum < bsum) {
    cout << -1 << endl;
    return 0;
  }
  sort(c.begin(),c.end());
  vector<ll> d = b;
  rep(i, n) {
    ll idx = c[i].second;
    ll t = min(sum, abs(c[i].first));
    sum -= t;
    d[idx] += t;
  }
  ll ans = 0;
  rep(i, n) {
    if (a[i] != d[i]) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 7144
def sum_digits(n):
    total = 0
    while n > 0:
        total += n % 10
        n //= 10
    return total


N, A, B = map(int, input().split())
ans = 0

for i in range(1, N + 1):
    n = sum_digits(i)
    if n >= A and n <= B:
        ans += i

print(ans)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
 
using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;
 
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")


#define lli long long int 
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define loopb(i,a,b) for (lli i=a;i>=b;i--)
#define pb push_back
#define mod 1000000007
#define fast() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) (__gcd((a),(b)))
#define lcm(a,b)(((a)*(b))/gcd((a),(b)))
#define ma 1e18
#define bc __builtin_popcountll
#define vi vector<lli>
#define pr pair<lli,lli>
#define vp vector<pr>
#define F  first
#define S   second
#define lld long double 
lli h[100002];
lli dp[100002];
lli n,k;
lli solve(lli num)
{lli i;
if(dp[num]!=ma)
{return dp[num];
}
else
{if(num==n)
{dp[num]=0;
return 0;
}
else
{for(i=1;(i<=k && num+i<=n);i++)
{dp[num]=min(dp[num],solve(num+i)+abs(h[num+i]-h[num]));}
return dp[num];
}
}
}
int main()
{fast();
cin>>n>>k;
loop(i,1,n+1)
{dp[i]=ma;}
loop(i,1,n+1)
{cin>>h[i];
}
cout<<solve(1)<<"\n";
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
const ld PI=3.141592653589;
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    cout << 2 * n * PI << endl;
    return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
int main(){
    
    int n;
    cin>>n;
    vector<int >v(n,0);
    for(int i=0;i<n;i++)cin>>v[i];
    sort(v.begin(),v.end());
    float gini = v[0];
    for(int i=1;i<n;i++){
        gini = (gini+v[i])/2;
    }
    cout<<gini;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; i++) cin >> v[i];

  int ans = 1;
  int height = v[0];
  for (int i = 1; i < N; i++) {
    if (height <= v[i]) ans++;
    height = max(v[i], height);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define P 1000000007

uint32_t nextpint(void){ char c=getchar_unlocked(); while(c<'0'||'9'<c) c=getchar_unlocked(); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return x; }

uint32_t d[101][4][4][4];
int main(void){
	uint32_t n=nextpint();
	d[0][0][0][0]=1;
	for(uint32_t m=0; m<n; m++){
		for(uint8_t c3=0; c3<4; c3++){
			for(uint8_t c2=0; c2<4; c2++){
				for(uint8_t c1=0; c1<4; c1++){
					if(d[m][c3][c2][c1]==0) continue;
					for(uint8_t a=0; a<4; a++){
						if(c2==1&&c1==2&&a==3)continue;
						if(c2==2&&c1==1&&a==3)continue;
						if(c2==1&&c1==3&&a==2)continue;
						if(c3==1&&c2==2&&a==3)continue;
						if(c3==1&&c1==2&&a==3)continue;
						d[m+1][c2][c1][a] += d[m][c3][c2][c1];
						d[m+1][c2][c1][a] %= P;
					}
				}
			}
		}
	}
	uint64_t ans=0;
	for(uint8_t c3=0; c3<4; c3++){
		for(uint8_t c2=0; c2<4; c2++){
			for(uint8_t c1=0; c1<4; c1++){
				ans += d[n][c3][c2][c1];
			}
		}
	}
	ans %= P;
	printf("%"PRIu64"\n", ans);
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-

def max_ingredients(L):
    work_L = L
    ing = 0
    while work_L:
        ing += work_L[-1]
        work_L = work_L[:-2]
    return ing

def main():
    N = int(input())
    L = [int(l) for l in input().split(" ")]
    print( max_ingredients( sorted( L, reverse=True ) ) )

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define scani(x) scanf("%d",&x)
#define scanc(x) scanf("%s",x)
#define printi(x) printf("%d",x)
#define printin(x) printf("%d\n",x)
#define printd(x) printf("%.8f",x)
#define printc(x) printf("%s",x)
#define repd(i,n,m) for(int i = n; i > m; i--)
#define repu(i,n,m) for(int i = n; i < m; i++)
#define allprintu(i,n,m,a) for(int i = n; i < m; i++){if(i != m-1){printf("%d ",a[i]);}else{printf("%d\n",a[i]);}}
#define allprintd(i,n,m,a) for(int i = n; i > m; i--){if(i != 0){printf("%d ",a[i]);}else{printf("%d\n",a[i]);}}


int x;
double pp1[2] = {0,0}, pp2[2] = {100,0};

void kock(int n, double p1[], double p2[]){
	if(n == 0){
		return;
	}
	double s[2] = {(2*p1[0]+1*p2[0])/3,
				(2*p1[1]+1*p2[1])/3};
	double t[2] = {(1*p1[0]+2*p2[0])/3,
				(1*p1[1]+2*p2[1])/3};
	double u[2] = {(t[0]-s[0])*cos(M_PI/3) - (t[1]-s[1])*sin(M_PI/3) + s[0],
				(t[0]-s[0])*sin(M_PI/3) + (t[1]-s[1])*cos(M_PI/3) + s[1] };
	kock(n-1,p1,s);
	repu(i,0,2){
		printd(s[i]);
		printf(" ");
	}
	printf("\n");

	kock(n-1,s,u);
	repu(i,0,2){
		printd(u[i]);
		printf(" ");
	}
	printf("\n");

	kock(n-1,u,t);
	repu(i,0,2){
		printd(t[i]);
		printf(" ");
	}
	printf("\n");
	kock(n-1,t,p2);
}
int main(void){
	scani(x);
	repu(i,0,2){
		printd(pp1[i]);
		printf(" ");
	}
	printf("\n");
	kock(x,pp1,pp2);
	repu(i,0,2){
		printd(pp2[i]);
		printf(" ");
	}
	printf("\n");

	return 0;
}


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

#define mod 1000000007

typedef long long ll;

#define rep(i, n) for(ll i=1; i<=n; ++i)

using namespace std;
const long long INF = 1LL << 60;
 
int main(void){
	
	ll N;
    cin >> N;

    ll ans = INF;

    for(ll i = 1; i * i <= N; i++){
        if(N % i != 0)
            continue;
        ll num = max(i, N / i);
        ll F = 1;
        while(1){
            if(num / 10 >= 1){
                num /= 10;
                F++;
            }else
                break;
        }
        ans = min(ans, F);
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef long long ll;
//typedef pair<int, int> mpair;
using namespace std;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	bool b[101] = {false};
    rep(i, 3){
        int a;cin>>a;
        b[a] = true;
    }
    int cou = 0;
	rep(i, 101){
        if(i==0)continue;
        if(b[i]){cou++;}
    }
    cout << cou << endl;
	return 0;
}


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

int main(){
    long double a,b,h,m;
    cin >> a >> b >> h >> m;
    long double th,tm,theta,ans,tmp;
    if(m==0) th = double(30*h);
    else th = double(30*h+m*0.5);
    tm = double(6*m);
    theta = th-tm;
    //if(theta>180) theta-=180.0;

    tmp = pow(a,2.0)+pow(b,2.0)-2*a*b*cosl(theta*PI/180.0);
    ans = sqrtl(tmp);
    cout << fixed << setprecision(15) << ans << endl;

}

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

n=int(input())
a= [list(map(int, input().split())) for i in range(n-1)]

b = [[] for i in range(n)]

for i in range(n-1):
    b[a[i][0]-1].append((a[i][1]-1,a[i][2]))
    b[a[i][1]-1].append((a[i][0]-1,a[i][2]))

import collections
from collections import deque

INF = -10 ** 9
dis = [INF for i in range(n)]
ans = [-1]*n
def bfs(s):
    d = deque()
    d.append(s)
    dis[s]=0
    ans[s]=0
    flag = True

    while len(d):
        x = d.popleft()

        for i in range(len(b[x])):
            y=b[x][i][0]
            if dis[y] == INF:
                d.append(y)
                dis[y]=dis[x]+b[x][i][1]
                if dis[y]%2==0:
                    ans[y]=0
                else:
                    ans[y]=1
    return ans
z=bfs(0)

for i in range(n):
    print(z[i])


Measured memory_bytes: 86620
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,v.size())
#define all(v)(v).begin(),(v).end()
#define bit(n)(1ll<<(n))
#define uniq(v)sort(all(v));v.erase(unique(all(v)),v.end())
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,T&&t,U&&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(T&&...t){_print(cout,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#else
template<class...T>void dprint(T&&...t){_print(cerr,t...);}
#endif
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<<(ostream&o,const multiset<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(10);
    string s,t;
    cin>>s>>t;
    int a=0;
    REP(i,3){
        if(s[i]==t[i])a++;
    }
    cout<<a<<endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

signed main(void)
{
  int a, b, ans = INF;
  cin >> a >> b;
  a *= 10; b *= 10;
  int tmp1, tmp2;
  FOR(i, -1800, 1801) {
    //cout << i << endl;
    tmp1 = a+i, tmp2 = b-i;
    if(tmp1 < 0) tmp1 += 3600; if(tmp2 < 0) tmp2 += 3600;
    if(tmp1 >= 3600) tmp1 -= 3600; if(tmp2 >= 3600) tmp2 -= 3600;
    //if(i == 810) cout << tmp1 << " " << tmp2 << " " << ans << endl;
    if(tmp1 == tmp2 && abs(ans) > abs(i)) {
      //cout << tmp1 << " " << tmp2 << endl;
      ans = i;
    }
  }
  int ret = a+ans;
  if(ret < 0) ret += 3600; if(ret >= 3600) ret -= 3600;
  cout << fixed << setprecision(6) << (double)(ret)/10 << endl;
  return 0;
}

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

using i64 = int64_t;

constexpr i64 MOD = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    vector<i64> v;
    for(int i=0;i<n;++i){
        i64 a;
        cin >> a;
        v.push_back(a);
    }
    vector<vector<i64>> cumsum(60, vector<i64>(n+1));
    for(int i=0;i<60;++i){
        for(int j=1;j<=n;++j){
            cumsum[i][j] = cumsum[i][j-1] + ((v[j-1]>>i)&1ll);
        }
    }

    i64 ans = 0;
    for(int i=0;i<n-1;++i){
        i64 c = 0, tmp = 0;
        for(int j=0;j<60;++j){
            i64 d = cumsum[j][n] - cumsum[j][i+1];
            if((v[i]>>j)&1ll)d = (n-i-1)-d;
            d += c;
            tmp |= ((d&1ll)<<j);
            c = d / 2;
        }
        ans += tmp;
        ans %= MOD;
        ans += ((c%MOD)*((1ll<<60ll)%MOD))%MOD;
        ans %= MOD;
        //cerr << ans << endl;
    }
    cout << ans << endl;

    return 0;
}


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

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

    while (true) {
        int H, W;
        cin >> H >> W;

        if (H == 0 && W == 0)
            break;

        rep(i, H) {
            rep(j, W) cout << "#";
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


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

#define int long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (long long)1000000007
#define f first
#define s second
#define debug1(x) cerr<<x<<"\n"
#define debug2(x,y) cerr<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<"\n"
#define nl cerr<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cerr<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 500005


int32_t main(){
sp;
    int n,d;
    cin>>n>>d;
    int ans=1;
    int diff=d+d+1;
    ans=(n+diff-1)/diff;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
///----------------------///
///---Code Written by----///
///-----Al-Shahreyaj-----///
///----------------------///

///PRAGMA
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>

///PBDS
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;

//PBDS_SET
//Index of Value - .order_of_key()
//Value at Index - .find_by_order()
//typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds_set; 
//typedef tree<int, null_type, lessorequal<int>, rb_tree_tag,tree_order_statistics_node_update> pbds_multiset; 

#define mem(a, x) memset(a, x, sizeof(a))
#define MP make_air
#define inf 1e8
#define INF 1e18
#define CP(x) printf("Case %d: ", x);
#define unq(v) v.erase(unique(all(v)),v.end())
#define one(x) __builtin_popcount(x)
#define onel(x) __builtin_popcountll(x)
#define ll long long
#define endl "\n"
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define matrix vector<vector<ll> >
#define F first
#define S second
#define pb push_back
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define INT ini()
#define LONG inl()
#define M 1000000007
#define N 3005

int ini(){int x;scanf("%d",&x);return x;}
ll inl(){ll x;scanf("%lld",&x);return x;}

ll big_mod(ll a, ll b)
{
	if(b == 0) return 1LL;
	if(b == 1) return a;
	ll res = big_mod(a, b / 2LL);
	res = (res * res) % M;
	if(b & 1LL) res = (res * a) % M;
	return res;
}

ll dp[N];
ll cal[200005];

ll ncr(ll n, ll r)
{
	//cout << n << " " << r << endl;
	return (cal[n] * big_mod((cal[r] * cal[n - r]) % M, M - 2)) % M;
}

int main()
{
	/*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif*/

    cal[0] = 1;
	for(int i = 1; i <= 200002; i++) cal[i] = (cal[i - 1] * i) % M;

    int h = INT, w = INT, n = INT;
    vector<pii> v;
    for(int i = 1; i <= n; i++) v.pb({INT, INT});
    v.pb({h, w});
	sort(all(v));
	for(int i = 0; i < v.size(); i++)
	{
		dp[i] = ncr(v[i].F + v[i].S - 2, v[i].F - 1);
		for(int j = 0; j < i; j++)
		{
			if(v[j].F <= v[i].F && v[j].S <= v[i].S){
			dp[i] = (dp[i] - (dp[j] * ncr(v[i].F - v[j].F + v[i].S - v[j].S, v[i].F - v[j].F)) % M + M) % M;
		}
		}
	}
	cout << dp[n] << endl;	
	return 0;
}





Measured memory_bytes: 1920
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    void solve(){
        int n,k;
        cin>>n>>k;
        if(k>(n-1)*(n-2)/2){
            cout<<-1;
            return;
        }
        int dif=(n-1)*(n-2)/2-k;
        vector<pair<int,int>>ans;
        for(int u=2;u<=n;u++)ans.push_back({1,u});
        for(int u=2;u<n&&dif>0;u++){
            for(int v=u+1;v<=n&&dif>0;v++){
                ans.push_back({u,v});
                dif--;
            }
        }
        cout<<ans.size()<<'\n';
        for(auto p:ans)cout<<p.first<<" "<<p.second<<'\n';
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

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

#define ll long long int
#define pb push_back
#define f(i,x,y) for(i=x;i<y;i++)
#define vll vector<ll>
#define fast    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl



void solve()
{
    ll n;
    cin>>n;
    
    ll i=1;
    ll ans=0;
    for(i=1;i<n;i++)
    {
        if(n%i==0)
            ans+=(n/i-1);
        else
            ans+=n/i;
    }
    cout<<ans<<endl;
}

int main()
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
using namespace std;
int N, V;
int X[200005];
//vector <int> Colour[20][200005];
//int C[20][200005];
int Log2[200005];
int MaxL[20][200005], MaxR[20][200005];
int L[(1 << 20) + 5], R[(1 << 20) + 5];
int Val[30];
bool Use[200005];
void Read()
{
    cin >> N >> V;
    for(int i = 1; i <= N; i++)
        cin >> X[i];
}

void precalcLog2()
{
    Log2[1] = 1;
    for(int i = 2; i <= V; i++)
        Log2[i] = Log2[i / 2] + 1;
    int l = Log2[V], x = V;
    while(x > 0)
    {
        Val[l] = x;
        x /= 2;
        --l;
    }
}

void precalcColour()
{
    for(int j = 0; j <= Log2[V]; j++)
    {
        int Max = 0;
        int c = 1;
        int last = 1;
        for(int i = 1; i <= N; i++)
        {
            if(Max > Val[j])
            {
                //++c;
                Max = 0;
                last = i;
            }
            MaxL[j][i] = last;
            Max = max(Max, X[i + 1] - X[i]);
        }
        Max = 0;last = N;
        for(int i = N; i >= 1; i--)
        {
            if(Max > Val[j])
            {
                //++c;
                Max = 0;
                last = i;
            }
            MaxR[j][i] = last;
            Max = max(Max, X[i] - X[i - 1]);
        }
    }
}
void precalcLR()
{
    int limit = (1 << (Log2[V]));
    for(int i = 0; i < limit; i++)
    {
        R[i] = N + 1;
        for(int j = 0; j < Log2[V]; j++)
        {
            if((i & (1 << j)) != 0)
            {
                L[i] = max(L[i], MaxR[j][L[(i ^ (1 << j))] + 1]);
                R[i] = min(R[i], MaxL[j][R[(i ^ (1 << j))] - 1]);
            }
        }
    }
}

void checkPos(int pos)
{
    int left = MaxL[Log2[V]][pos];
    int right = MaxR[Log2[V]][pos];
    int mask = (1 << (Log2[V])) - 1;
    int ans = 0;
    int dist = right - left + 1;
    for(int i = 0; i < (1 << (Log2[V])); i++)
    {
        int c = (mask ^ i);
        int x = N - R[c] + 1;
        if(L[i] >= left - 1 && R[c] <= right + 1)
        {
            ans = 1;
            break;
        }
    }
    for(int i = left; i <= right; i++)
    {
        Use[i] = 1;
        if(ans == 1)
            cout << "Possible\n";
        else
            cout << "Impossible\n";
    }
}
int Solve()
{
    for(int i = 1; i <= N; i++)
        if(Use[i] == 0)
    {
        checkPos(i);
    }
}
int main()
{
    Read();
    precalcLog2();
    precalcColour();
    precalcLR();
    Solve();
    return 0;
}


Measured memory_bytes: 38656