akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  200005



ll n,l,r;
vi a(N),seg(4*N);
void build(ll cur,ll st,ll end)
{
    if(st==end)
    {
        seg[cur]=a[st];
        return;
    }
    ll mid=(st+end)>>1;
    build(2*cur,st,mid);
    build(2*cur+1,mid+1,end);
    seg[cur]=max(seg[2*cur],seg[2*cur+1]);    /*  1-change here  */
}
ll query(ll cur,ll st,ll end,ll l,ll r)
{
    if(l<=st&&r>=end)
    return seg[cur];
    if(r<st||l>end)
    return 0;                           /*  2-change here  */
    ll mid=(st+end)>>1;
    ll ans1=query(2*cur,st,mid,l,r);
    ll ans2=query(2*cur+1,mid+1,end,l,r);
    return max(ans1,ans2);                 /*  3-change here  */
}
void update(ll cur,ll st,ll end,ll pos,ll upd)
{
    if(st==end)
    {
        a[pos]=upd;                    /*  4-change here  */
        seg[cur]=upd;                    /*  5-change here  */
        return;
    }
    ll mid=(st+end)>>1;
    if(st<=pos&&pos<=mid)
        update(2*cur,st,mid,pos,upd);
    else
        update(2*cur+1,mid+1,end,pos,upd);
    seg[cur]=max(seg[2*cur],seg[2*cur+1]);    /*  6-change here  */
}
void solve()
{
    cin>>n;
    ll h[n+1],x[n+1];
    rep(i,1,n+1)cin>>h[i];
    rep(i,1,n+1)cin>>x[i];
    build(1,1,n);
    ll ans=0;
    rep(i,1,n+1)
    {
        ll v=query(1,1,n,0,h[i]-1);
        ans=max(ans,v+x[i]);
        update(1,1,n,h[i],v+x[i]);
    }
    // rep(i,1,n+1)
    //     cout<<a[i]<<" ";
    cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 14212
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <cmath>
#include <functional>

typedef long long ll;
using namespace std;


int main(){
    int n;
    cin >> n;
    int start = 599;
    int ans = 8;
    while(1){
        if(n <= start) break;
        ans--;
        start += 200;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
def query(val):
    print ('?', val)
    ans = input()
    if ans == 'Y':
        return True
    return False
LIMIT = 10 ** 9
import sys
if __name__ == "__main__":
    if (query(LIMIT)):
        res = 1
        while (True):
            if(query(2 * res)):
                print ('!', res)
                sys.exit()
            res *= 10
    digit = 10
    res = LIMIT
    while (True):
        if (query(res)):
            break
        res = res // 10
        digit -= 1
    query = 10 ** (digit)
    keta = 0
    while (keta < digit):
        low = query
        high = query * 10
        left = 0
        right = 10
        while (right - left > 1):
            med = (right + left) // 2
            if keta == 0 and med == 0:
                left = med
                continue
            val1 = list(str(low))
            val1[keta] = str(med)
            val1 = int("".join(val1))
            print ("? %d" %(val1))
            ans = input()
            if (ans == "Y"):
                if (keta == digit - 1):
                    query = val1
                right = med
                continue
            else:
                if (keta < digit - 1):
                    query = val1
                left = med
                continue
        keta += 1
    query = query // 10
    print ("! %d" % (query))


Measured memory_bytes: 3404
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>

using namespace std;

int main() {
  int N,M,C;
  cin >> N >> M >> C;
  vector<int> B(M,0);
  vector<int> A(M,0);
  for(int i=0;i<M;i++){
    cin >> B[i];
  }
  int sum;
  int count=0;
  for(int i=0;i<N;i++){
    sum=0;
    for(int k=0;k<M;k++){
      cin >> A[k];
    }
    for(int j=0;j<M;j++){
      sum+=A[j]*B[j];
    }
    if(sum+C>0){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
  int n,i;
  scanf("%d",&n);
  long long a[n+1],total=0;
  for(i=0;i<n;i++){
    scanf("%lld",&a[i]);
    total+=a[i];
  }
  i=1;
  long long sa=total-2*a[0];
  long long min=llabs(sa);
  for(i=1;i<n-1;i++){
    sa-=2*a[i];
    if(llabs(sa)<min)
      min=llabs(sa);
  }
  printf("%lld\n",min);
  return 0;
}

Measured memory_bytes: 3288
#include <cstdio>

int main(){
    int N,K,X,Y;
    scanf("%d %d %d %d",&N,&K,&X,&Y);
    int M = 0;
    for(int i = 1; i <= N; i++){
        if(i <= K){
            M += X;
        }
        if(i > K){
            M += Y;
        }
    }
    printf("%d\n",M);

    return 0;
}

Measured memory_bytes: 760
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}

void main()
{
  long n; readV(n);
  long[] a; readC(5, a);

  auto b = a.reduce!min;
  writeln((n+b-1)/b+4);
}


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

int llintcmp(const void *a, const void *b) {
	long long c = *(long long*)a-*(long long*)b;
	if (c>0LL) return -1;
	else if (c==0LL) return 0;
	else return 1;
}

long long a[300010];

int main(void) {
	int i, N;
	long long T=0LL;

	scanf("%d", &N);
	for (i=0;i<3*N;i++) scanf("%lld", &a[i]);

	qsort(a,3*N,sizeof(long long),llintcmp);
	for (i=0;i<2*N;i+=2) T += a[i+1];
	printf("%lld\n", T);	

	return 0;
}

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

int main(){
    double x;
    double pi = 3.1415;
    scanf("%lf",&x);
    double result = 2 * x * pi;

    printf("%lf",result);    
}

Measured memory_bytes: 3824
import sys
input = sys.stdin.readline
N = int(input())
li_SP = [input().split() for i in range(N)]
for i in range(N):
    li_SP[i][1] = int(li_SP[i][1])
    li_SP[i].append(i+1)
li_SP.sort(key=lambda x:(x[0],-x[1]))
for i in range(N):
    print(li_SP[i][2])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
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; }

struct edge {ll from, to, cost;};


// ----------------------------------
// いつでも使える O(|V|x|E|)
// ----------------------------------

int main(){
    // V:頂点 E:辺
    ll V, E;
    cin >> V >>E;
    // 最短距離
    vector<ll> d(V, INF);
    // 辺
    vector<edge> es(E);

    rep(i, E){
        ll a,b,c;
        cin >> a >> b >> c;
        a--; b--;
        es.at(i) = (edge){a, b, -c};
    }

    fill(d.begin(), d.begin() + V, INF);
    d[0] = 0;
    rep(j, V){
        bool update = false;
        rep(i, E){
            edge e = es.at(i);
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                update = true;

                // 負閉路をチェック
                if(j == V-1 && e.to == V-1){
                    cout << "inf" << endl;
                    return 0;
                }
            }
        }
        if(!update) {
            break;
        }
    }

    
    cout << -d[V-1] << endl;
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int n;
    cin >> n;

    bool ans = true;
    int prev = -1;
    rep(_, 0, n) {
        int h;
        cin >> h;
        if (h < prev) { ans = false; }
        if (h == prev) {
            prev = h;
        } else {
            prev = h - 1;
        }
    }
    cout << (ans ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
n,m,k=map(int,input().split())

a=list(map(int,input().split()))
b=list(map(int,input().split()))

prea=[a[0]]*n
preb=[b[0]]*m

for i in range(1,n):
	prea[i]=prea[i-1]+a[i]

for i in range(1,m):
	preb[i]=preb[i-1]+b[i]


ans=0

tmp=k
ta=0
i=0
while(i<n):
	if(tmp<a[i]):
		break
	tmp-=a[i]
	ta+=1
	i+=1

ans=max(ans,ta)


tmp=k
ta=0
i=0
while(i<m):
	if(tmp<b[i]):
		break
	tmp-=b[i]
	ta+=1
	i+=1

ans=max(ans,ta)

tmp=k

for i in range(n):
	ta=i+1
	rem=tmp-prea[i]
	if(rem<b[0]):
		continue

	low=0
	high=m-1
	val=-1

	while(low<=high):
		mid=(low+high)//2
		if(preb[mid]<=rem):
			val=mid
			low=mid+1
		else:
			high=mid-1
	ta+=val+1
	ans=max(ans,ta)

print(ans)





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

typedef struct node *link;
struct node{
  int key;
  link le,ri,pa;
};
link head;

void insert(int a);
void inorder(link h);
void preorder(link h);

int main(){
  int m,k;
  char op[10];
  int i;

  head=NULL;
  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%s",op);
    if(strcmp(op,"insert")==0){
      scanf("%d",&k);
      insert(k);
    }else if(strcmp(op,"print")==0){
      inorder(head);
      printf("\n");
      preorder(head);
      printf("\n");
    }
  }

  return 0;
}

void insert(int a){
  link x,y,z;
  z=malloc(sizeof(struct node));
  z->key=a; z->le=NULL; z->ri=NULL;
  y=NULL;  x=head;
  while(x!=NULL){
    y=x;
    if(z->key<x->key)   x=x->le;
    else                x=x->ri;
  }
  z->pa=y;

  if(y==NULL)             head=z;
  else if(z->key<y->key)  y->le=z;
  else                    y->ri=z;
}

void inorder(link h){
  if(h==NULL) return;
  inorder(h->le);
  printf(" %d",h->key);
  inorder(h->ri);
}

void preorder(link h){
  if(h==NULL) return;
  printf(" %d",h->key);
  preorder(h->le);
  preorder(h->ri);
}




Measured memory_bytes: 25140
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int ans=0,con=0,pre=0;
    for(int i=0;i<n;i++){
        int h;
        cin>>h;
        if(pre<h)con=0;
        else{
            con++;
        }
        pre=h;
        ans=max(ans,con);
    }
    cout<<ans<<endl;
    return 0;
}


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

#define endl '\n'
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

typedef long long llong;
typedef pair<int, int> pii;


bool valid(int num, vector<bool> &usable){


	while(num > 0){

		int digit = num % 10;
		if(!usable[digit]) return false;

		num /= 10;
	}


	return true;
}

void solve(){

	// string s;
	// cin >> s;

	int start;
	cin >> start;

	int n;
	cin >> n;

	vector<bool> usable(10, true);

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

	vector<int> arr;
	for(int i = 0; i < 10; i++){
		if(usable[i]) arr.push_back(i);
	}

	while(!valid(start, usable)) start++;

	cout << start;

}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifdef LOCAL
		ifstream in("in");
		cin.rdbuf(in.rdbuf());
	#endif

	solve();

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define f first
#define s second
#define MAXN 3010
ll MOD = 1e9+7;

ll A[MAXN];
ll N,K,a,b;
ll E[MAXN];
string S;
vpi V;
ll memo[MAXN][MAXN];
ll overlap[MAXN];
ll fact[MAXN];
ll invfact[MAXN];

ll exp(ll a, ll b){
	if (b==0)return 1;
	ll c = exp(a,b/2);
	c = (c*c)%MOD;
	if (b%2)c=(c*a)%MOD;
	return c;
}

ll inv(ll x){
	return exp(x, MOD-2);
}

ll C(ll a, ll b){
	return ((fact[a] * invfact[a-b]) %MOD) * invfact[b]%MOD;
}

int main(){
	cin>>N>>K>>S;
	fact[0] = 1;
	for (int i=1;i<=N;++i)fact[i] = (fact[i-1]*i)%MOD;
	for (int i=0;i<=N;++i)invfact[i] = inv(fact[i]);

	for (int i=1;i<=N;++i){
		if (S[i-1] == '1')A[i] = 1;
		A[i] += A[i-1];
	}
	for (int i=0;i<K;++i){
		cin>>a>>b;
		E[a] = max(E[a], b);
	}
	V.pb(-1,-1);
	for (int i=1;i<=N;++i)if(E[i]){
		if (SZ(V) && V.back().s >= E[i])continue;
		V.pb(i,E[i]);
	}
	for (int i=1;i<SZ(V)-1; ++i){
		overlap[i] = max(0LL,V[i].s - V[i+1].f + 1);
	}

	// for (int i=1;i<SZ(V);++i)cout<<overlap[i]<<' ';
	// cout<<'\n';
	memo[0][0] = 1;
	for (int i=1;i<SZ(V);++i){
		// cout<<"Hi\n";
		int s = max(V[i].f, V[i-1].s+1);
		int e = V[i].s;
		// cout<<"R "<<s<<' '<<e<<' '<<A[e]-A[s-1]<<'\n';
		int l = V[i].s - V[i].f + 1;
		for (int j=0;j<=overlap[i-1];++j){
			for (int k=0;k<=overlap[i];++k){
				int ones = j + A[e] - A[s-1];
				// cout<<ones<<'\n';
				int zeroes = l - ones;
				if (ones < k)continue;
				if (zeroes < overlap[i] - k)continue;
				memo[i][k] += (memo[i-1][j] * C(l-overlap[i], ones-k))%MOD;
				memo[i][k]%=MOD;
			}
		}
		ll t=0;
		for (int k=0;k<=overlap[i];++k)t=(t+memo[i][k])%MOD;
		if (i+1==SZ(V))cout<<t;
	}
}

Measured memory_bytes: 29440
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int now = 1;
		for (int i = 0; true; i++) {
			if (now > N) {
				System.out.println(i);
				break;
			}
			now *= K;
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define N 100020
#define ll long long
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
	while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return f?x:-x;
}
char ch[520][520], chr[520][520], chb[520][520];
int main(int argc, char const *argv[]) {
	int n = read(), m = read();
	for (int i = 1; i <= n; i++)
		scanf("%s", ch[i] + 1);
	memcpy(chb, ch, sizeof ch);
	memcpy(chr, ch, sizeof ch);
	for (int i = 1; i <= m; i++)
		chr[1][i] = chb[n][i] = '#';
	for (int i = 2; i < n; i++)
		chr[i][m] = chb[i][1] = '#';
	for (int i = 2; i < n; i += 2)
		for (int j = 2; j < m; j++)
			chr[i][j] = '#';
	for (int i = 3; i < n; i += 2)
		for (int j = 2; j < m; j++)
			chb[i][j] = '#';
	for (int i = 1; i <= n; i++)
		printf("%s\n", chr[i] + 1);
	puts("");
	for (int i = 1; i <= n; i++)
		printf("%s\n", chb[i] + 1);
	return 0;
}


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

int main()
{
	int N,Y;
	int a=0,b,c;

	cin >> N >> Y;

	int i;
	int ok=0;
	for(i=0;i<=N;i++)
	{
		b=i;
		if(((Y-1000*N-4000*b)%9000)==0)
		{
			a = (Y-1000*N-4000*b)/9000;
			c=N-a-b;
			if((a>=0) && (c>=0))
			{
				ok=1;
				break;
			}
		}

	}


	if(ok==0)
	{
		a=-1;
		b=-1;
		c=-1;
	}

	cout << a << " " << b << " " << c << endl;

	return 0;
}

Measured memory_bytes: 256
INF = 10**10

def chmax(a, b):
    if(a>b):
        return a
    else:
        return b

def chmin(a, b):
    if(a<b):
        return a
    else:
        return b


N = int(input())

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

dp = N*[INF]
dp[0]=0

for i in range(1,N):
    dp[i] = chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]))
    if(i>1):
        dp[i] = chmin(dp[i], dp[i-2]+abs(h[i]-h[i-2]))

print(dp[N-1])

Measured memory_bytes: 20568
#include<iostream>
using namespace std;
int main(){
  long long a;
  cin>>a;
  long long A[a];
  long long sum=0;
  for(long long i=0;i<a;i++){
    cin>>A[i];
    sum+=A[i];
  }
  long long min=0;
  for(long long i=1;i<a;i++){
    if(A[min]>A[i]){
      min=i;
    }
  }
  long long max=0;
  for(long long i=1;i<a;i++){
    if(A[max]<A[i]){
      max=i;
    }
  }
  cout<<A[min]<<" "<<A[max]<<" "<<sum<<endl;
 return 0;
}


Measured memory_bytes: 3148
mod = 10**9+7
N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
dp = [0]*(1<<N)
dp[0] = 1
for s in range(1, 1<<N):
    women = []
    for i in range(N):
        if (1<<i)&s:
            women.append(i)
    m = len(women)-1
    for w in women:
        if a[m][w] == 1:
            dp[s]+=dp[s^(1<<w)]
            dp[s]%=mod
print(dp[-1])

Measured memory_bytes: 59740
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include<bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;




#define pf                  printf
#define sf(a)               scanf("%d",&a)
#define sfl(a)              scanf("%lld",&a)
#define sff(a,b)            scanf("%d %d",&a,&b)
#define sffl(a,b)           scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)         scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)        scanf("%lld %lld %lld",&a,&b,&c)
#define sffff(a,b,c,d)      scanf("%d %d %d %d",&a,&b,&c,&d)
#define sffffl(a,b,c,d)     scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define sfffff(a,b,c,d,e)   scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
#define sfffffl(a,b,c,d,e)  scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)
#define sfc(a)              scanf("%c",&a)
#define pii                 pair<int,int>
#define ms(a,b)             memset(a,b,sizeof(a))
#define pb(a)               push_back(a)
#define pbp(a,b)            push_back({a,b})
#define db                  double
#define ft                  float
#define ll                  long long
#define ull                 unsigned long long
#define pii                 pair<int,int>
#define ff                  first
#define ss                  second
#define sz(x)               x.size()
#define all(x)              x.begin(),x.end()
#define CIN                 ios_base::sync_with_stdio(0); cin.tie(0)
#define max3(a, b, c)       max(a, b) > max(b, c) ? max(a, b) : max(b, c)
#define min3(a, b, c)       min(a, b) < min(b, c) ? min(a, b) : min(b, c)
#define for0(i,n)           for(int i=0;i<n;i++)
#define for1(i,n)           for(int i=1;i<=n;i++)
#define forrev(i,n)         for(int i=n-1; i>=0; i--)
#define forab(i,a,b)        for(int i=a;i<=b;i++)
#define forba(i,b,a)        for(int i=b;i>=a;i--)
#define stlloop(x)          for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define gcd(a, b)           __gcd(a, b)
#define lcm(a, b)           ((a)*((b)/gcd(a,b)))
#define case1(z)            cout<<"Case "<<z<<": "
#define case2(z)            printf("Case %d: ",z)
#define PI                  acos(-1) //3.14159265358979323846264338328
#define valid(tx,ty)        tx>=0 && tx<row && ty>=0 && ty<col
#define intlim              2147483648
#define N                   200007
#define inf                 100000008
#define mod                 1000000007

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

vector<ll>v,c;

int main()
{
    ll n,ans,i,x,y;
    cin>>n;
    for1(i,n)
    {
        cin>>x>>y;
        v.pb(x+y);
        c.pb(x-y);
    }
    sort(all(v));
    sort(all(c));
    ans = v[n-1]-v[0];
    ans = max(ans,c[n-1]-c[0]);
    cout<<ans<<endl;
    //main();
    return 0;
}





















Measured memory_bytes: 6480
N, P = list(map(int, input().split()))

def max_gcd(N,P):
  if N==1:
    return P
  else:
    for i in range(2, int(P**(1/N))+2):
      for _ in range(N):
        if P%i:
          break
        else:
          P = P//i
      else:
        return i * max_gcd(N,P)
    return 1
  
print(max_gcd(N,P))

Measured memory_bytes: 3064
d=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for _ in range(d)]
prev=0
se=set()
for i in range(d):
    lis=[]
    if i//26>prev:
        se=set()
        prev=i//26
    for j in range(26):
        lis.append((s[i][j]-c[j],j))
    lis.sort(reverse=True)
    print(lis[0][1]+1)

Measured memory_bytes: 9400
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
ll mod=1e9+7;
#define input_from_file  freopen("input.txt", "r", stdin);
int main()
{
    // input_from_file;
  // int t; cin>>t;
  // while(t--){
    ll n,k;cin>>n>>k;
    // k=2;
    vector<ll> vec(n,0),dp(n,1e10);
    for(int i=0;i<n;i++)  cin>>vec[i];
    dp[0]=0;if(n>1) dp[1]=abs(vec[0]-vec[1]);
    for(ll i=2;i<n;i++) { 
      for(ll j=i-1;j>=0 && j>=i-k;j--)
        dp[i]=min(dp[j]+abs(vec[j]-vec[i]),dp[i]);
    
    }
    cout<<dp[n-1];
  // }  
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int sum = 0;
		for(int x = a;x <= b;x++){
			if(c % x == 0){
				sum++;
			}
		}
		System.out.println(sum);
		sc.close();
	}
}

Measured memory_bytes: 26336
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
#define PI 3.141592653589793
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

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

	ll i,j,k,l,n,x,t;
	cin>>n>>x>>t;
	k=((n+(x-1))/x);
	cout<<t*k<<endl;
	return 0;	
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <ctime>


#ifndef M_PI
#define M_PI 3.141592653589
#endif
#define int long long
#define double long double
#define f(variable, start, end) for (int variable = start; variable < end; ++variable)
#define be(a) a.begin(), a.end()
#define no cout << "NO\n"
#define yes cout << "YES\n"
#define nor cout << "NO\n"; return
#define yesr cout << "YES\n"; return
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>


using namespace std;


template<typename T, typename E>
vector<T> &operator>>(vector<T> &v, E a) {
    v.push_back(a);
    return v;
}

//pair output
template<typename E>
ostream &operator<<(ostream &os, pair<E, E> &t) {
    os << t.first << ' ' << t.second;
    return os;
}

//"map" pair output
template<typename E>
ostream &operator<<(ostream &os, pair<const E, E> &t) {
    os << t.first << ' ' << t.second;
    return os;
}

//vector output
template<typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
    for (T i : vec) {
        os << i << ' ';
    }
    return os;
}

//2 dimensional vector output
template<typename T>
ostream &operator<<(ostream &os, vector<vector<T> > &vec) {
    for (vector<T> i : vec) {
        os << i << '\n';
    }
    return os;
}

//vector<pair<T, E>> output
template<typename T, typename E>
ostream &operator<<(ostream &os, vector<pair<T, E>> &vec) {
    for (pair<T, E> i : vec) {
        os << i.first << ' ' << i.second << '\n';
    }
    return os;
}


int count(vector<vector<char>> &a) {
    int bl = 0;
    f(i, 0, a.size()) {
        f(j, 0, a[i].size()) {
            if (a[i][j] == '#') {
                bl += 1;
            }
        }
    }
    return bl;
}

int32_t main() {
    cin.tie(NULL);
    cout.tie(NULL);
    cout.setf(ios::fixed);
    cout.precision(10);
    ios_base::sync_with_stdio(false);
#ifdef TIME
    int32_t start = clock();
#endif

    int h, w, k;
    cin >> h >> w >> k;
    int bl = 0, wh = 0;
    vector<vector<char>> a(h, vector<char>(w, 0));
    f(i, 0, h) {
        f(j, 0, w) {
            cin >> a[i][j];
            if (a[i][j] == '.') {
                wh += 1;
            } else {
                bl += 1;
            }
        }
    }

    vector<vector<char>> b(h, vector<char>(w, 0));


    int mask = 0;
    int ans = 0;

//    cout << (1ll << (h * w)) << '\n';

    for (mask = 0; mask < (1ll << (h + w)); mask++) {
        b = a;
//        cout << mask << "\n";
        int i = 0;
        for(i = 0; i < h; ++i) {
            if (mask >> i & 1) {
                f(ii, 0, w) {
                    b[i][ii] = '$';
                }

            }
        }
        f(j, h, h + w) {
            if (mask >> j & 1) {
                f(ii, 0, h) {
                    b[ii][j - h] = '$';
                }
            }
        }
//        cout << b;
        if (count(b) == k) {
            ans += 1;
        }
    }

    cout << ans;




#ifdef TIME
    cout << "\ntime: " << (clock() - start) / (CLOCKS_PER_SEC * 1.0);
#endif

    return 0;
}

Measured memory_bytes: 3600
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

def main():
    n,m,x = i2()
    a = intl()
    c1,c2 = 0,0
    for i in range(x,n+1):
        #print(i)
        if i in a:
            c1 += 1
    for i in range(0,x+1):
        #print(i)
        if i in a:
            c2 += 1
    print(min(c1,c2))
if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	s, _ := readLine()
	fmt.Printf("%d\n", solve(s))
}

func solve(s string) int {
	count := 0
	blackCount := 0
	for _, l := range s {
		if string(l) == "B" {
			blackCount++
		} else {
			count += blackCount
		}
	}

	return count
}

var rdr = bufio.NewReaderSize(os.Stdin, 100000)

/**
 * 長い文字列はfmt.Scanfだと時間がかかる
 */
func readLine() (string, error) {
	buf := make([]byte, 0, 100000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			return "", e
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf), nil
}

//** DEBUG **/
const DEBUG_ENABLE = false

func debug(format string, a ...interface{}) (n int, err error) {
	if DEBUG_ENABLE {
		return fmt.Fprintf(os.Stdout, format, a...)
	} else {
		return 0, nil
	}
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S; cin >> S;
  vector<int> memo(100,0);
  int count = 0;
for(int i = 0; i < S.size(); i++) {
  if((S[i] == 'A' || S[i] == 'T' || S[i] == 'C' || S[i] == 'G') && i==S.size()-1)
  {count++; memo[i] = count;}
  else if(S[i] == 'A' || S[i] == 'T' || S[i] == 'C' || S[i] == 'G')
    count++;
  
  else {
    memo[i] = count; count = 0;
  }
}
   sort(memo.rbegin(), memo.rend());
   cout << memo[0] << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N= keyboard.nextInt();
		long[] a = new long[N];
		
		for(int i =0; i<N; i++) {
			a[i] = keyboard.nextLong();			
		}
		Arrays.sort(a);
		
		long cons = 1000000000000000000L;
		long ans = 1 ;
		
		for(int j=0; j<N; j++) {
			if(a[j] !=0) {
				if(a[j]<=cons && a[j] <= cons/ans) {
					ans = ans*a[j];	
				}else {
					ans = -1;
					break;
				}
			}else{
				ans = 0;
				break;
			}
		}
		
		System.out.print(ans);
		keyboard.close();	
		
	}
}


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

int main(){
  int n,k;
  cin >> n >> k;
  int num;
  if((n-1)%(k-1)==0)
    num=(n-1)/(k-1);
  else num=(n-1)/(k-1)+1;
  cout << num << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		Map<Integer, Problem> map = new HashMap<>();

		for(int i = 0; i < m; i++) {
			int p = sc.nextInt();
			String s =  sc.next();

			Problem problem;
			if(map.containsKey(p)) {
				problem = map.get(p);

			} else {
				problem = new Problem();
				map.put(p, problem);
			}
			problem.provideAns(s);
		}

		int ac = 0;
		int wa = 0;
		for(Entry<Integer, Problem> entry : map.entrySet()) {
			Problem problem = entry.getValue();
			ac += problem.getAs();
			wa += problem.getWa();
		}
		System.out.println(ac + " " + wa);
	}

}

class Problem {
	private static final String AC = "AC";
	private static final String WA = "WA";
	private int ac;
	private int wa;

	public Problem() {
		ac = 0;
		wa = 0;
	}

	public void provideAns(String str) {
		if(ac == 0) {
			if(AC.equals(str)) {
				ac = 1;
			} else if(WA.equals(str)){
				wa++;
			}
		}
	}

	public int getAs() {
		return this.ac;
	}

	public int getWa() {
		if(ac == 0) {
			return 0;
		}
		return this.wa;
	}
}

Measured memory_bytes: 71980
#include<stdio.h>

int n, M[100][100];
int color[100], d[100], f[100], tt;

void dfs_visit(int u) {
    int v;
    color[u] = 1;
    d[u] = ++tt;
    for ( v = 0; v < n; v++ ) {
        if ( M[u][v] == 0 ) continue;
        if ( color[v] == 0 ) dfs_visit(v);
    }
    color[u] = 2;
    f[u] = ++tt;
}

void dfs() {
    int u;
    for ( u = 0; u < n; u++ ) color[u] = 0;
    tt = 0;
    for ( u = 0; u < n; u++ ) if ( color[u] == 0 ) dfs_visit(u);
    for ( u = 0; u < n; u++ ) printf("%d %d %d\n", u + 1, d[u], f[u]);
}

int main(void) {
    int i, j, k, a, b;
    scanf("%d", &n);
    for ( a = 0; a < n; a++ ) {
        for ( b = 0; b < n; b++ ) M[a][b] = 0; 
    }

    for ( a = 0; a < n; a++ ) {
        scanf("%d %d", &i, &k);
        i--;
        for ( b = 0; b < k; b++ ) {
            scanf("%d", &j);
            j--;
            M[i][j] = 1;
        }
    }

    dfs();

    return 0;
}

Measured memory_bytes: 1820
import sys
from math import ceil

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n, x, t = LI()
    print(ceil(n / x) * t)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9048
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    vector<int> a(3);
    rep(i,3) cin >> a[i];
    sort(a.begin(),a.end());

    cout << a[2] *10 + a[1] + a[0] ;

    return 0;
}

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

namespace
{
char S[ 100010 ];
char T[ 100010 ];
}


int main( int argc, char *argv[] )
{
int i;
int j;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> S;

	i = 0;
	j = 0;
	while( S[ i ] != '\0' )
	{
		if( i % 2 == 0 )
		{
			T[ j ] = S[ i ];
			j++;
		}

		i++;
	}

	T[ j ] = '\0';
	cout << T << endl;

	return 0;
}




Measured memory_bytes: 512
/**
 *  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_A
 */
#include <iostream>
#include <sstream>
#include <vector>
#include <limits>

using namespace std;

void
printv(const vector<int> a)
{
    stringstream ss;
    for (auto it = a.cbegin(); it != a.cend(); it++) {
        if (it != a.begin()) {
            ss << ' ';
        }
        ss << *it;
    }
    cout << ss.str() << endl;
}

int
merge(vector<int> &a, const int left, const int mid, const int right)
{
    vector<int> L(a.begin() + left, a.begin() + mid);
    L.push_back(numeric_limits<int>::max());

    vector<int> R(a.begin() + mid, a.begin() + right);
    R.push_back(numeric_limits<int>::max());

    int i = 0;
    int j = 0;
    int count = 0;
    for (int k = left; k < right; k++) {
        a[k] = L[i] <= R[j] ? L[i++] : R[j++];
        count++;
    }

    return count;
}

int
mergeSort(vector<int> &a, const int left, const int right)
{
    if (left + 1 >= right) return 0;

    int count = 0;
    int mid = (left + right) / 2;
    count += mergeSort(a, left, mid);
    count += mergeSort(a, mid, right);
    count += merge(a, left, mid, right);
    return count;
}

int
main()
{
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n; cin.ignore();

    vector<int> S(n);
    for (int i = 0; i < n; i++) {
        cin >> S[i]; cin.ignore();
    }

    int count = mergeSort(S, 0, n);
    printv(S);
    cout << count << endl;

    return 0;
}

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

int main()
{
	long N,M,ans;
	cin>>N>>M;
	if(N==1&&M==1){ans=1;}
	if((N==1&&M>2)||(N>2&&M==1)){ans=(N*M)-2;}
	if(N>=2&&M>=2){ans=N*M-((2*N)+(2*M)-4);}
	cout<<ans<<endl;
 
	fflush(stdin);
	getchar();
	return 0;
	
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = Integer.parseInt(in.nextLine());
		String[] tokens = in.nextLine().split(" ");
		List<Integer> L = new ArrayList<>(N);
		for (int i = 0; i < N; ++i) {
			L.add(Integer.parseInt(tokens[i]));
		}
		in.close();
		Collections.sort(L);
		long sum = 0;
		for (int i = 0; i < N - 1; ++i) {
			sum += L.get(i);
		}
		if (sum > L.get(L.size() - 1)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 23636
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let a: usize = iterator.next().unwrap().parse().unwrap();
    let b: usize = iterator.next().unwrap().parse().unwrap();

    let mut i_a: usize = 1;
    let mut i_b: usize = 1;

    loop {
        let mul_a = a * i_a;
        let mul_b = b * i_b;
        if mul_a == mul_b {
            return mul_a.to_string();
        } else if mul_a > mul_b {
            i_b += 1;
        } else {
            i_a += 1;
        }
    }
}

#[test]
fn test() {
    assert_eq!(
        solve(
            r"2 3"
        ),
        "6"
    );
    assert_eq!(
        solve(
            r"123 456"
        ),
        "18696"
    );
    assert_eq!(
        solve(
            r"100000 99999"
        ),
        "9999900000"
    );
}


Measured memory_bytes: 4352
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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

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

ll gcd(const ll a, const ll b) {
    assert(a <= b);
    if (a == 0) return b;
    return gcd(b % a, a);
}

ll lcm(const ll a, const ll b) {
    assert(a <= b);
    return a * b / gcd(a, b);
}

ll calc(const ll A, const ll B, const ll m) {
    ll x = ((A + m - 1) / m) * m;
    if (x <= B) {
        return (B - x) / m + 1;
    } else {
        return 0LL;
    }
}

int main(void) {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    if (D < C) {
        swap(C, D);
    }

    ll g1 = calc(A, B, C);
    ll g2 = calc(A, B, D);
    ll g3 = calc(A, B, lcm(C, D));

    ll dividable = g1 + g2 - g3;
    cout << (B - A + 1) - dividable << endl;

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

def sankakuteiri(a, b, c):
    #a > b > cにする
    list = [a, b, c]
    list.sort(reverse=True)

    if (list[0] == list[1]) or (list[1] == list[2]):
        return False
    elif(list[1] + list[2] > list[0]):
        return True
    else:
        return False


n = int(input())
numbers = input().split(" ")
l = [int(x) for x in numbers]


r = 0
if len(l) >= 3:
    for i in range(len(l)):
        for j in range(i + 1, len(l)):
            for k in range(j + 1, len(l)):
                if sankakuteiri(l[i], l[j], l[k]):
                    r += 1

print(r)


Measured memory_bytes: 9156
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, d;
    cin >> n >> d;
    vector<vector<int>> xs(n, vector<int>(d)); cin >> xs;
    int ans = 0;
    printde(xs);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < i; j++){
            int dist = 0;
            for(int k = 0; k < d; k++){
                dist += pow(xs[i][k] - xs[j][k], 2);
            }
            ans += dist == pow((int)sqrt(dist), 2);
        }
    }
    cout << ans << '\n';
}


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

using namespace std ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	long long a , b ;
	cin>>a>>b ;
	long long n = __gcd(a , b) ;
	int ans = 0 ;
	for(long long i = 2ll ; i * i <= n ; ++i)
	{
		if(n%i == 0)
			ans++ ;
		while(n%i == 0)
			n /= i ;
	}
	if(n > 1)
		ans++ ;
	return cout<<ans+1<<"\n" , 0 ;
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
count = 0
s = 1
i = 0
A.sort()
A.reverse()

while i < N-1 and count < 2:
  if A[i] == A[i+1]:
    s = s * A[i]
    count += 1
    i += 2
  else:
    i += 1

if count >= 2:
  print(s)
else:
  print(0)

Measured memory_bytes: 62704
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 3e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

ll A[MAXN];
ll cal[110];

int main()
{
    ll n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    ll cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;

    for(int i=0;i<n;i++){
        cin>>A[i];
        cur = A[i];
        for(int j=0;j<60;j++){
            cal[j]+=(cur&1);
            cur>>=1;
        }
    }

    ll res = 0;
    ll bi = 1;

    for(int i=0;i<60;i++){

        cur = cal[i]*(n-cal[i]);
        cur %= MOD;
        res+=(bi*cur);
        res%=MOD;
        bi<<=1;
        if(bi>=MOD)bi-=MOD;
    }

    cout<<res<<"\n";

    return 0;
}


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

// D - Floor Function
int main() {
    long long A, B, N;
    cin >> A >> B >> N;

    long long x = B - 1;
    x = min(x, N);
    long long result = floor(A * x / B) - A * floor(x / B);
    cout << result;
}


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

int main(){
  std::string s;
  
  std::cin >> s;
  
  int counter = 0;
  
  if(s[0] == '1'){counter++;}
    if(s[1] == '1'){counter++;}
    if(s[2] == '1'){counter++;}

  std::cout << counter;
  
  return 0;
}


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

signed main() {
	int N, P;
	string S;
	cin >> N >> P >> S;

	if (P == 2 or P == 5) {
		int ans = 0;
		for (int r = 0; r < N; r++) {
			if ((S[r] - '0') % P == 0) {
				ans += r + 1;
			}
		}
		cout << ans << endl;
		return 0;
	}

	vector<int> digit(N+1);
	int ten = 1;
	for (int i = N - 1;i >= 0; i--) {
		digit[i] = ((S[i] - '0') * ten) % P;
		ten *= 10;
		ten %= P;
	}

	for (int i = N - 1; i >= 0; i--) {
		digit[i] += digit[i+1];
		digit[i] %= P;
	}

	int ans = 0;
	map<int, int> cnt;
	for (int i = N; i >= 0; i--) {
		ans += cnt[digit[i]];
		cnt[digit[i]]++;
	}

	cout << ans << endl;

}

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

typedef pair<int,int> pii;
const int N=40010;
struct Edge{int from,to,next;} e[N<<5];
int h[N<<2],sum=0;
int low[N<<2],pre[N<<2];
int scc[N<<2],dfn,cnt;
int a[2][N],n;
pii Hash[N<<1];
stack<int> stk;
int node[N<<4],tot;

void add_edge(int u,int v)
{
    if(u==v) return;
    e[++sum].to=v;
    e[sum].from=u;
    e[sum].next=h[u];
    h[u]=sum;
}

void Build(int o,int l,int r)
{
    if(l==r)
    {
        node[o]=Hash[l].second;
        return;
    }
    node[o]=++tot;
    int mid=(l+r)/2;
    Build(o<<1,l,mid);
    Build(o<<1|1,mid+1,r);
    add_edge(node[o],node[o<<1]);
    add_edge(node[o],node[o<<1|1]);
}

void link(int o,int l,int r,int nl,int nr,int u)
{
    if(nl>nr) return;
    if(l>=nl&&r<=nr)
    {
        add_edge(u,node[o]);
        return;
    }
    int mid=(l+r)/2;
    if(nl<=mid) link(o<<1,l,mid,nl,nr,u);
    if(nr>mid) link(o<<1|1,mid+1,r,nl,nr,u);
}

void Init()
{
    for(int i=1;i<=n;i++)
    {
        Hash[2*i-1].first=a[0][i];
        Hash[2*i-1].second=i+n;
        Hash[2*i].first=a[1][i];
        Hash[2*i].second=i;
    }
    sort(Hash+1,Hash+1+2*n);
}

void Tarjan(int u)
{
    stk.push(u);
    low[u]=pre[u]=++dfn;
    for(int tmp=h[u];tmp;tmp=e[tmp].next)
        if(!pre[e[tmp].to])
        {
            Tarjan(e[tmp].to);
            low[u]=min(low[u],low[e[tmp].to]);
        }
        else if(!scc[e[tmp].to]) low[u]=min(low[u],pre[e[tmp].to]);
    if(pre[u]==low[u])
    {
        int o;cnt++;
        do{
            o=stk.top();
            stk.pop();
            scc[o]=cnt;
        }while(o!=u);
    }
}

bool check(int x)
{
    sum=dfn=cnt=0;tot=2*n;
    memset(h,0,sizeof(h));
    Build(1,1,2*n);
    for(int i=1;i<=n;i++)
        for(int k=0;k<2;k++)
        {
            int l=lower_bound(Hash+1,Hash+1+2*n,pii(a[k][i]-x+1,0))-Hash;
            int r=upper_bound(Hash+1,Hash+1+2*n,pii(a[k][i]+x-1,2*n+1))-Hash-1;
            int m=lower_bound(Hash+1,Hash+1+2*n,pii(a[k][i],(k^1)*n+i))-Hash;
            link(1,1,2*n,l,m-1,k*n+i);
            link(1,1,2*n,m+1,r,k*n+i);
        }
    while(!stk.empty()) stk.pop();
    memset(pre,0,sizeof(pre));
    memset(low,0,sizeof(low));
    memset(scc,0,sizeof(scc));
    for(int i=1;i<=tot;i++)
        if(!pre[i]) Tarjan(i);
    for(int i=1;i<=n;i++)
        if(scc[i]==scc[i+n]) return 0;
    return 1;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&a[0][i],&a[1][i]);
    Init();
    int l=0,r=int(1e9),mid;
    while(l<r)
    {
        mid=(l+r)/2;
        if(check(mid)) l=mid+1;
        else r=mid-1;
    }
    printf("%d\n",check(l)?l:l-1);
    return 0;
}

Measured memory_bytes: 16384
#include <iostream>
#include <stdio.h>


using namespace std;



int main(){
  int a,b;
  std::cin >> a>>b;
  if(a>b){
    std::cout << "a > b" << '\n';
  }else if(a<b){
    std::cout << "a < b" << '\n';
  }else {
    std::cout << "a == b" << '\n';
  }

}

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

///@Tanvir

///template from: profile/hitman623
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,p,a[100005],f[100005],g[100005];

/**********************************
: players who have already arrived there should form a circle,
and a player who has just arrived there should cut into the circle somewhere.
*/
void solve(){
    cin>>n;
    vi a(n,0);
    for(int i=0; i<n; i++) cin>>a[i];

    sort(a.begin(), a.end(), greater<int>());

    int idx = 1;
    int val_curr = a[0];

    for(int i=1, j=1; i<n; j++, idx++)
    {
        ///cout<<"#idx="<<idx<<"\n";
        if(idx==(n-1)) break;
        //if(curr==n) break;
        ///curr++;

        val_curr += a[i];

        if(!(j&1)){

            i++;
        }

        ///cout<<"#val_curr="<<val_curr<<"\n";

        /* code */
    }
    cout<<val_curr<<"\n";


}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


/*
9
20 15 12 10 8 6 5 4 2
*/


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

int main() {
  // 入力を受け取る
  int N, A;
  cin >> N >> A;

  // 計算
  
  // 500円玉で行けるところまでいき、あまりを考えたい
  int mod = N % 500;
  
  // 出力
  if (mod <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    string n;
    cin >> n;
    rep(i,3){
        if(n[i]=='1') n[i]='9';
        else n[i]='1';
    }
    cout << n << endl;



}


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

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

    int a, b;
    cin >> a >> b;
    if(a >= 13){
        cout << b << endl;
    }else if(a >= 6 and a <= 12){
        cout << b / 2 << endl;
    }else{
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256