akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<sstream>
#include<fstream>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<string>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define mem(a,b) memset(a,b,sizeof(a))
#define random(a,b) (rand()%(b-a+1)+a)
#define ll long long
#define ull unsigned long long
#define e 2.71828182
#define Pi acos(-1.0)
#define ls(rt) (rt<<1)
#define rs(rt) (rt<<1|1)
#define lowbit(x) (x&(-x))
using namespace std;
int read()
{
	int s=1,x=0;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') s=-1;ch=getchar();}
	while(isdigit(ch)) {x=10*x+ch-'0';ch=getchar();}
	return x*s;
}
const int MAXN=1e5+5;
int a[MAXN],n,m;
priority_queue<int,vector<int>,less<int> > que;
int main()
{
	n=read(),m=read();
	for(int i=1;i<=n;++i) 
	a[i]=read(),que.push(a[i]);
	while(m--)
	{
		int t=que.top();que.pop();
		que.push(t/2);
		if(t==0) break;
	}
	ll sum=0;
	while(!que.empty())
	{
		//cout<<que.top()<<' ';
		sum+=que.top();
		que.pop();
	}
	cout<<sum<<endl;
}


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

int main()
{
    int S[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;
    cout << S[K-1] << endl;



}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int A = 26;
int a[A];
char s[10000];

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%s", s);
		for (int j = 0; j < m; j++)
			a[(int)s[j] - 'a']++;
	}
	int B, C, D;
	D = (n & 1) * (m & 1);
	B = (n / 2) * (m / 2);
	C = (n * m - B * 4 - D) / 2;

	for (int i = 0; i < A; i++) {
		if (a[i] & 1) {
			if (D == 0) {
				printf("No\n");
				return 0;
			}
			D--;
			a[i]--;
		}
		a[i] /= 2;
	}
	if (D != 0) throw;
	for (int i = 0; i < A; i++) {
		if (a[i] & 1) {
			if (C == 0) {
				printf("No\n");
				return 0;
			}
			C--;
			a[i]--;
		}
	}
	printf("Yes\n");

	return 0;
}


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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back


class UnionFind{
    public:
        vector<int> uni;
        UnionFind(int s) : uni(s, -1) { }
 
       //頂点aが所属するグループを調べる
        int root(int a)
        {
            if (uni[a] < 0) return a;
            return uni[a] = root(uni[a]);
        }
    
        //頂点aと頂点bを繋ぐ。もともと同じグループの時falseを返す
        bool connect(int a,int b)
        {
            a = root(a);
            b = root(b);
            if (a == b) return false;
    
            if (uni[a] > uni[b])
            {
                a ^= b;
                b ^= a;
                a ^= b;
            }
    
            uni[a] = uni[a] + uni[b];
            uni[b] = a;
            return true;
        }
    
        //頂点a,bが同じグループであるかを調べる
        bool isConnect(int a,int b)
        {
            return root(a) == root(b);
        }
    
        //頂点aを含むグループの頂点数を調べる
        int size(int a)
        {
            return -uni[root(a)];
        }
    
    };


int main(){
    ll n, m; cin >> n >> m;
    vector<ll> alis(m), blis(m);
    vector<ll> ans(m);
    UnionFind un(n+1);
    ans[m-1] = (n * (n-1)) / 2;
    REP(i, 0, m){
        cin >> alis[i] >> blis[i];
    }
    for(int i = m-1; i >= 1; i--){
        int a = alis[i], b = blis[i];
        int f = 0;
        if(!un.isConnect(a, b)){
            f = un.size(a) * un.size(b);
        }
        ans[i-1] = ans[i] - f;
        un.connect(a, b);
    }
    REP(i, 0, m){
        cout << ans[i] << endl;
    }
}

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


int main() {
  int w,h,n;
  cin >> w >> h >> n;
  int max_x=w,min_x=0,max_y=h,min_y=0;
  for(int i=0;i<n;i++){
      int x,y,a;
      cin >> x >> y >> a;
      switch(a){
          case 1:
            min_x=max(min_x,x);
            break;
          case 2:
            max_x=min(max_x,x);
            break;
          case 3:
            min_y=max(min_y,y);
            break;
          case 4:
            max_y=min(max_y,y);
            break;
      }
  }
  cout << max(0,max_x-min_x)*max(0,max_y-min_y) << endl;
}

Measured memory_bytes: 256
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

A,B,C,D = inpl()

if A+B > C+D:
	print('Left')
elif A+B == C+D:
	print('Balanced')
else:
	print('Right')


Measured memory_bytes: 4212
import java.util.*;
public class Main{
	public static void main(String args[]){
    	Scanner s = new Scanner(System.in);
    	int n = s.nextInt();
    	long sum = 0;
    	for(int i = 1 ; i <= n ; i++) {
    		if(i % 3 != 0 && i % 5 != 0) {
    			sum += i;
    		}
    	}
    	System.out.println(sum);
    }
}

Measured memory_bytes: 35564
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <functional>
 
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){cout << a << " " << b << " " << c << endl;}
#define INT_MAX 1<<30;
const int MAX = 1020000;
const double EPS = 1e-6;
const int mod = 1e9+7;
 
int main(){
    ll n,a,b; cin >> n >> a >> b;
    ll ans = 0;
    rep(i,n+1){
        ll tmp = i;
        ll sum = 0;
        while(tmp>0){
            sum += tmp % 10;
            tmp /= 10;
        }
        if(a<=sum && sum<=b) ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for (int n = 0; n < N; ++n) {
        cin >> A[n] >> B[n];
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    
    int Min, Max;
    if (N%2 == 0) {
        Min = A[N/2-1] + A[N/2];
        Max = B[N/2-1] + B[N/2];
    } else {
        Min = A[(N-1)/2];
        Max = B[(N-1)/2];
    }
    cout << Max - Min + 1 << endl;

    return 0;
}


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

using namespace std;





int main(){


	int n; cin >> n;


	for(int i = 1; i < 10; i++){
		for(int j = 1; j < 10; j++){
			if(i * j == n){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}



	cout << "No" << endl;


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N=1000100;
int n,m,o[3],c[3],pr[N],nx[N],a[N];
char s[N],t[N];
bool cmp(int x,int y){return c[x]<c[y];}
void ini(){
	scanf("%s",s+1);
	n=strlen(s+1);
	FOR(i,1,n)if(s[i]!=t[m]) t[++m]=s[i];
	n=m;
	FOR(i,1,n) s[i]=t[i];
	FOR(i,1,n) c[s[i]-'A']++;
	FOR(i,0,2) o[i]=i;
	sort(o,o+3,cmp);
	FOR(i,0,2)FOR(j,1,n)if(s[j]-'A'==o[i]) a[j]=i;
	sort(c,c+3);
	FOR(i,0,n) pr[i+1]=i,nx[i]=i+1;
	a[0]=-1;a[n+1]=-2;
}
void opt(){for(int x=nx[0];x<=n;x=nx[x]) cout<<"ABC"[o[a[x]]];cout<<'\n';}
void adj(){
	int x,y,z;
	for(x=nx[0];c[2]>c[1] && x<=n;x=nx[x])if(a[x]==2 && a[pr[x]]!=a[nx[x]])
		nx[pr[x]]=nx[x],pr[nx[x]]=pr[x],c[2]--;
	for(x=nx[0];c[2]>c[1] && x<=n;x=nx[x])if(a[x]==2 && a[pr[x]]==0)
		y=pr[pr[x]],z=nx[x],pr[z]=y,nx[y]=z,c[2]--,c[0]--;
	for(x=nx[0];c[1]>c[0] && x<=n;x=nx[x])if(a[x]+a[pr[x]]==3){
		int y=pr[pr[x]],z=nx[x];
		if(a[y]==a[z]) continue;
		pr[z]=y,nx[y]=z;c[2]--;c[1]--;
	}
}
int main(){
	//freopen("1.in","r",stdin);
	ini();adj();opt();
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

// constexpr int INF = 1e9;
constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;

int main(){
  ll X;
  cin >> X;
  map<ll, int> mp;
  for(ll i = -1000; i <= 1000; i++){
    ll x = i*i*i*i*i;
    mp[x] = i;
  }
  for(ll i = -1000; i <= 1000; i++){
    ll A = i*i*i*i*i;
    ll B = -(X - A);
    if(mp[B]){
      cout << i << " " << mp[B] << endl;
      return 0;
    }
    else if(B==0){
      cout << i << " " << 0 << endl;
    }
  }


  return 0;
}


Measured memory_bytes: 3788
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;//例: VVI dp(10, vector<int>(10, INF);
typedef priority_queue<int, vector<int>, less<int> > QUE_int;
const int INF = 2 * pow(10, 9) + 1;//+1しないとREになるかも(out of rangeになるんかな?? )

vector<int> dx = { -1, 0, 1, 0, -1, -1, 1, 1 };
vector<int> dy = { 0, -1, 0, 1, -1, 1, -1, 1 };

ll max(ll a, ll b) { return (a > b) ? a : b; }
ll min(ll a, ll b) { return (a < b) ? a : b; }

////////////////////////////////////////////////////////////////

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = pow(10, 9) + 7;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
};


////////////////////////////////////////////////////////////////

int main(void) {
	
	int N, M;
	cin >> N >> M;

	vector<int> A(N);
	double all = 0;
	for(int i=0; i<N; i++){
		cin >> A[i];
		all += A[i];
	} 

	double thresh = all / (4.0 * M);

	int num = 0;
	for(int i=0; i<N; i++){
		if(A[i] < thresh) continue;
		num++;
	}

	if(num >= M) cout << "Yes" << endl;
	else cout << "No" << endl;

}




Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

//#define debug(x) ;
#define debug(x) cerr << #x << " = " << x << "\n";

ostream& operator<<(ostream& cerr, vector<ll> aux) {
    cerr << "[";
    for (auto e : aux) cerr << e << ' ';
    cerr << "]";
    return cerr;
}

const int maxN = 10011;

ll n, k, cnt, act;
char s[maxN], best;
string answer;

void fullOf(char c) {
    for (int i = 1; i <= n; i++)
        printf("%c", c);
    exit(0);
}

void check(int l, int r) {
    ll mini = cnt * (1LL << (k - 1));
    ll rem = n - mini;

    string aux = "";
    for (int i = 1; i <= mini; i++) aux.pb(best);
    for (int i = 0; i < rem; i++) aux.pb(s[r - cnt - i]);
    if (aux < answer) answer = aux;
}

int main()
{
    //freopen("test.in","r",stdin);

    scanf("%lld%lld\n%s", &n, &k, s + 1);
    best = s[1];
    for (int i = 1; i <= n; i++) { 
        s[2 * n - i + 1] = s[i];
        best = min(best, s[i]);
        answer.pb('z');
    }

    for (int i = 1; i <= 2 * n; i++) {
        if (s[i] == best) 
            cnt = max(cnt, ++act);
        else
            act = 0;
    }

    ll aux = cnt;
    for (int i = 1; i < k; i++) {
        aux <<= 1;
        if (aux >= n) fullOf(best);
    }

    act = 0;
    for (int i = 1; i <= 2 * n; i++) {
        if (s[i] == best)
            act++;
        else
            act = 0;

        if (act == cnt && i >= n)
            check(i - n + 1, i);
    }

    cout << answer;

    return 0;
}


Measured memory_bytes: 256
import math

A, B = map(int, input().split())
flag = True
count = 0
for i in range(A, B+1):
    for j in range(int(math.ceil(len(str(A)))/2)):
        if str(i)[j] != str(i)[-1-j]:
            count -= 1
            break
    count += 1
print(count)

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

int main() {
  int n; cin>>n;
  int a[n];
  deque<int> v;
  rep(i,n) cin>>a[i];
  
  rep(i,n){
    int p=lower_bound(v.begin(),v.end(),a[i])-v.begin();
    if(p==0){
      v.push_front(a[i]);
    }
    else{
      v[p-1]=a[i];
    }
  }
  
  cout<<v.size()<<endl;
    
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
 String s = sc.next();
 char[] alp = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
 if(s.length() < 26) {
	 char ad = 0;
	 for(int i = 0;i < 26;i++) {
		 boolean dif = true;
		 for(int j = 0;j < s.length();j++) {
			 if(alp[i] == s.charAt(j)) {
				 dif = false;
				 break;
			 }
			 else dif = true;
			 }if(dif) {
				 ad = alp[i];
				 break;
			 }
			 }
	 System.out.print(s);
	 System.out.println(ad);
		 }
 else if(s.length() == 26) {
	 if(s.equals( "zyxwvutsrqponmlkjihgfedcba"))System.out.println("-1");
	 else {
		 int swap = -1;
		 for(int i = 25;i > 0;i--) {
			 int a = -1;
			 int b = -1;
			 for(int j = 0;j < 26;j++) {
				 if(s.charAt(i) == alp[j]) {
					 a = j;
					 break;
				 }
			 }
			 for(int j = 0;j < 26;j++) {
				 if(s.charAt(i-1) == alp[j]) {
					 b = j;
					 break;
				 }
			 }
			 if(a > b) {
				 swap = i-1;
				 break;
			 }
			 
		 }
		 int min = 25;
		 if(swap == 0) {min = 25;
		 int swapin = -1;
		 for(int j = 0;j < 26;j++) {
			 if(s.charAt(swap) == alp[j]){
				 swapin = j;
			 }
		 }
		 for(int i = swap+1;i < 26;i++) {
			 for(int j = 0;j < 26;j++) {
				 if(s.charAt(i) == alp[j]){
					 if(j > swapin)
					 min = Math.min(min,j);
				 }
			 }
		 }
			 System.out.println(alp[min]);
		 }
		 else {
			 min = 25;
			 int swapin = -1;
			 for(int j = 0;j < 26;j++) {
				 if(s.charAt(swap) == alp[j]){
					 swapin = j;
				 }
			 }
			 for(int i = swap+1;i < 26;i++) {
				 for(int j = 0;j < 26;j++) {
					 if(s.charAt(i) == alp[j]){
						 if(j > swapin)
						 min = Math.min(min,j);
					 }
				 }
			 }
			 System.out.print(s.substring(0,swap));
			 System.out.println(alp[min]);
	 }
	 }
	 
 }
	 }
 }


Measured memory_bytes: 21972
def solve(x1, y1, x2, y2):
    d1, d2 = x1 - x2, y1 - y2
    x3, y3 = x2 + d2, y2 - d1
    x4, y4 = x3 + d1, y3 + d2
    return '{} {} {} {}'.format(x3, y3, x4, y4)

_x1, _y1, _x2, _y2 = map(int, input().split())
print(solve(_x1, _y1, _x2, _y2))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  double A,B;
  double H,M;
  cin>>A>>B>>H>>M;
  
  double sw;
  
  if(30*H+M/2<=6*M){
    sw=6*M-30*H-M/2;
  }else{
    sw=30*H+M/2-6*M;
  }
  
  if(sw>180){
    sw=360-sw;
  }
  
  double sw1;
  
  sw1=sqrt(A*A+B*B-2*A*B*cos(M_PI*sw/180));
  
  cout << fixed << setprecision(10);
  
  cout<<sw1<<endl;
  
}



  

Measured memory_bytes: 4136
from sys import stdin
def input():
    return stdin.readline().strip()

h, w = map(int, input().split())
s = [input() for _ in range(h)]

def check(x, y, up, down, left, right):
    if s[x][y] == '.':
        return 0
    if up and s[x-1][y] == '#':
        return 0
    if down and s[x+1][y] == '#':
        return 0
    if left and s[x][y-1] == '#':
        return 0
    if right and s[x][y+1] == '#':
        return 0
    else:
        print('No')
        exit()

# (0, y)
check(0, 0, False, True, False, True)
for y in range(1, w-1):
    check(0, y, False, True, True, True)
check(0, w-1, False, True, True, False)

# (x, y)
for x in range(1, h-1):
    check(x, 0, True, True, False, True)
    for y in range(1, w-1):
        check(x, y, True, True, True, True)
    check(x, w-1, True, True, True, False)

# (h-1, y)
check(h-1, 0, True, False, False, True)
for y in range(1, w-1):
    check(h-1, y, True, False, True, True)
check(h-1, w-1, True, False, True, False)

print('Yes')

Measured memory_bytes: 9224
import java.io.*;

class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();

    int x, y;

    while (true){
      String line = br.readLine();
      String[] data = line.split(" ");
      x = Integer.parseInt(data[0]);
      y = Integer.parseInt(data[1]);
      if (x == 0 && y == 0) {break;}
      else if(x > y){
      sb.append(data[1] + " ").append(data[0]).append("\n");
      }
      else
      sb.append(data[0] + " ").append(data[1]).append("\n");
    }
    System.out.print(sb);
  }
}

Measured memory_bytes: 27280
N=int(input())
B=list(map(int,input().split()))
A=[0]*(N+1)
a=B[-1]
A[N]=a
for i in range(N-2,-1,-1):
  if B[i]<a:
    A[i+1]=B[i]
  A[i]=B[i]
  a=B[i]
print(sum(A))

Measured memory_bytes: 9196
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a = int(readline())
b = int(readline())
ans = [1, 2, 3]
for i in ans:
    if i != a and i != b:
        print(i)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define INF 100000005
#define MAX 100001
#define ll long long
#define dmp make_pair
#define dpb push_back
#define P pair<int,int>
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
const int inf = 2147483647;

int n, dat[3*MAX];
void init(int m){
	n = 1;
	while(n < m)n *= 2;
	for(int i = 0;i < 2*n;i++)dat[i] = inf;
}

void change(int x, int y){
	x += n-1;
	dat[x] = y;
	while(x > 0){
		x = (x-1)/2;
		dat[x] = min(dat[x*2+1], dat[x*2+2]);
	}
}

int query(int a, int b, int k, int l, int r){
	if(b <= l || r <= a)return inf;
	if(a <= l && r <= b)return dat[k];
	int vl = query(a, b, 2*k+1, l, (l+r)/2);
	int vr = query(a, b, 2*k+2, (l+r)/2, r);
	return min(vl, vr);
}

int main(){
	int m, q, c, x, y, ans;
	scanf("%d%d", &m, &q);
	init(m);
	while(q--){
		scanf("%d%d%d", &c, &x, &y);
		if(!c)change(x, y);
		else printf("%d\n", query(x, y+1, 0, 0, n));
	}
	return 0;
}

Measured memory_bytes: 4252
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int x=a+b+c;
    if(x>=22){
        cout<<"bust";
    }
    else{
        cout<<"win";
    }
}


Measured memory_bytes: 256
run (function * (write, gets) {
	var h = parseInt(yield, 10), w = parseInt(yield, 10);
	var d = parseInt(yield, 10);
	var n = h * w;
	var location = new Array(h * w);
	var magic = new Array(h * w);

	for (var i=0; i<h; ++i)
	for (var j=0; j<w; ++j) {
		var number = parseInt(yield, 10);
		location[number - 1] = {row: i, column: j};
		magic[number - 1] = 0;
	}

	for (var i=d; i<n; ++i) {
		var previous = location[i - d];
		var current = location[i];
		magic[i] += Math.abs(previous.row - current.row);
		magic[i] += Math.abs(previous.column - current.column);
		magic[i] += magic[i - d];
	}

	var q = parseInt(yield, 10);
	for (var i=0; i<q; ++i) {
		var l = parseInt(yield, 10), r = parseInt(yield, 10);

		write(magic[r - 1] - magic[l - 1]);
	}
});

/**
 * @param {(write: (line: string, end?: string) => void, gets: () => IterableIterator<string|null>) => IterableIterator<any>} main 
 */
function run (main) {
	var istream = process.stdin;
	var ostream = process.stdout;

	/**
	 * @type {[string|null]}
	 */
	var words = [];
	/**
	 * @type {[string]}
	 */
	var lines = [];
	var rest = "";
	var ended = false;
	var INPUT_MODE_LINE = 0;
	var INPUT_MODE_WORD = 1;
	var input_mode = INPUT_MODE_WORD;

	/**
	 * @param {string} line 
	 * @param {string} [end] 
	 */
	function write (line, end) {
		ostream.write(line + (undefined === end ? os.EOL : end));
	}
	function *gets () {
		if (0 < lines.length) {
			return lines.shift();
		} else {
			input_mode = INPUT_MODE_LINE;
			/**
			 * @type {string}
			 */
			var line = yield;
			input_mode = INPUT_MODE_WORD;
			return line;
		}
	}

	var main_itr = main(write, gets);

	/**
	 * @param {string|null} chunk 
	 */
	function get_chunk (chunk) {
		istream.pause();
		if (null === chunk) {
			lines.push(null);
		} else {
			rest += chunk;
			var line_exp = /.*(\r?\n|\r)/g;
			var line_match, lastIndex = 0;
			while (null !== (line_match = line_exp.exec(rest))) {
				lastIndex = line_exp.lastIndex;
				lines.push(line_match[0]);
			}
			rest = rest.substring(lastIndex);
		}
		loop();
	}

	function loop () {
		while (0 < lines.length) {
			switch (input_mode) {
				case INPUT_MODE_LINE:
				{
					words.push(lines.shift());
				}
				break;
				case INPUT_MODE_WORD:
				{
					if (null === lines[0]) {
						words.push(lines.shift());
					} else {
						var word_exp = /[^\s]+/g;
						var line_match;
						if (null !== (line_match = word_exp.exec(lines[0]))) {
							words.push(line_match[0]);
							lines[0] = lines[0].substring(word_exp.lastIndex);
						} else {
							lines.shift();
						}
					}
				}
				break;
			}

			while (0 < words.length) {
				var result = main_itr.next(words.shift());
				if (undefined !== result.value) {
					if ('string' === typeof result.value) {
						write(result.value, "");
					} else {
						write(`${result.value}`, "");
					}
				}
				if (result.done) return;
			}
		}

		ended ? setTimeout(get_chunk, 0, null) : process.stdin.resume();
	}
	istream.on('data', get_chunk);
	istream.on('end', function () {
		ended = true;
		get_chunk(null);
	});

	istream.setEncoding('utf8');
	get_chunk(null);
};

var os = require('os');


Measured memory_bytes: 32640
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
using namespace std;
int a;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>a;
	cout<<a+a*a+a*a*a; 
	return 0;
}



Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  //展望台の高さ
  vector<int> h(n);
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  vector<int> ab(2*m);
  for(int i=0;i<2*m;i++){
    cin>>ab[i];
  }
  //ok
  //goodはよい展望台のこと
  vector<int> good(n);
  for(int i=0;i<n;i++){
    good[i]=1;
  }
  //iはi番目の展望台の探索
  for(int i=0;i<2*m;i+=2){
    if(good[ab[i]-1]==0&&good[ab[i+1]-1]==0){
      continue;
    }
    if(h[ab[i]-1]>h[ab[i+1]-1]){
      good[ab[i+1]-1]=0;
    }
    else if(h[ab[i]-1]<h[ab[i+1]-1]){
      good[ab[i]-1]=0;
    }
    else{
      good[ab[i]-1]=0;
      good[ab[i+1]-1]=0;
    }
  }
  int ans=0;
  for(int i=0;i<n;i++){
    ans+=good[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4844
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)	cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 100005
#define BLOCK 555
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 200005;
const long double epsilon = 1e-9;
inline ll myceil(ll a, ll b) { if (a % b == 0)	return (a / b);	return (a / b + 1);}
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	fast
	ll n;
	cin >> n;
	vl a(n);
	ain(a, n);
	// sort(all(a));
	ll ans = 0;
	loop(i, n)
	{
		FOR(j, i + 1, n - 1)
		{
			FOR(k, j + 1, n - 1)
			{
				vl curr;
				curr.pb(a[i]) , curr.pb(a[j]) , curr.pb(a[k]);
				sort(all(curr));
				if (curr[0] + curr[1] > curr[2] && (curr[0] != curr[1] && curr[1] != curr[2] && curr[0] != curr[2]))
					++ans;
			}
		}
	}
	cout << ans << END;



// #ifndef ONLINE_JUDGE
// 	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
// #endif
	return 0;
}

Measured memory_bytes: 3660
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
#define DD 1
#else
#define DD 0
#endif
#define Debug if(DD) printf("line %d\n",__LINE__)
#define deb(x) if(DD) cerr<<#x<<'='<<x<<endl
#define debug if(DD) printf
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void gg1(){write2(-1);exit(0);}
	void gg2(){puts("NO");exit(0);}
	
	const double eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int M=5e6+10;
	ll fac[M],facinv[M];ll C(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,M-1) fac[i]=fac[i-1]*i%MOD;
		facinv[M-1]=invm(fac[M-1]);fd(i,M-1,1) facinv[i-1]=facinv[i]*i%MOD;
	}
	
	const int N=1e6+10;
	int x[N];
	void main()
	{PRE();
		int n=qread();fo(i,1,n) x[i]=qread();ll ans=INF;
		fo(now,0,100)
		{
			ll sum=0;fo(i,1,n) sum+=(x[i]-now)*(x[i]-now);
			chmin(ans,sum);
		}write(ans);
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	#endif
	srand(time(0));
	mine::main();
	if(DD) cerr<<"\n---------------------Zory-------------------\nTime: " <<1.0*clock()/CLOCKS_PER_SEC<<"s";
}

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

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

	if(a>b){
	k=a;
	a=b;
	b=k;						
	}
	if(a>c){
	k=a;
	a=c;
	c=k;
	}
	if(b>c){
	k=b;
	b=c;
	c=k;
	}
	cout<<a<<" "<<b<<" "<<c<<endl;
	
	return 0;
}


Measured memory_bytes: 3052
a, b, k = map(int, input().split())

takahashi = a
aoki = b

def turn(me, you):
  if me % 2 == 1:
    me = me - 1
  return me // 2, me // 2 + you

for i in range(0, k):
  if i % 2 == 0:
    takahashi, aoki = turn(takahashi, aoki)
  else:
    aoki, takahashi = turn(aoki, takahashi)

print(str(takahashi) + " " + str(aoki) )

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;

template<typename Abel> struct BIT {
    const Abel UNITY_SUM = 0;
    vector<Abel> dat;
    BIT(int n) : dat(n, UNITY_SUM) { }  // [0, n)
    inline void add(int i, Abel x) {
        while (i < (int)dat.size()) { dat[i] += x; i |= i + 1; }
    }
    inline Abel sum(int i) {    // [0, i]
        Abel res = UNITY_SUM;
        while (i >= 0) { res += dat[i]; i = (i & (i + 1)) - 1; }
        return res;
    }
    inline Abel sum(int a, int b) { return sum(b - 1) - sum(a - 1); }   // [a, b)
    Abel operator[](int i) { return sum(i, i + 1); }
    friend ostream& operator<<(ostream& os, BIT<Abel> &bit) {
        for (int i = 0; i < (int)bit.dat.size(); i++) os << bit[i] << " ";
        return os;
    }
};

template<typename T> struct Compress1D {
    map<T, int> zip; vector<T> unzip; int sz;
    Compress1D(vector<T> a) {
        sort(begin(a), end(a)); a.erase(unique(begin(a), end(a)), end(a));
        sz = a.size(); unzip.resize(sz);
        for (int i = 0; i < sz; i++) zip[a[i]] = i, unzip[i] = a[i];
    }
    int operator[](T x) { return zip[x]; }
    T inv(int idx) { return unzip[idx]; }
    int size() { return sz; }
};

int main() {
    int n, m; cin >> n >> m;
    int q; cin >> q;
    vector<pair<pair<int, int>, int>> events;
    vector<int> vals;
    for (int i = 0; i < m + q; i++) {
        int s, t; cin >> s >> t; s--;
        int id = i < m ? -1 : i - m;
        events.emplace_back(make_pair(t, id), s);
        vals.emplace_back(s), vals.emplace_back(t);
    }
    sort(begin(events), end(events));
    Compress1D<int> comp(vals);
    BIT<int> bit(comp.size() + 1);
    vector<int> ans(q);
    for (auto &p: events) {
        int t = p.first.first, id = p.first.second, s = p.second;
        if (id == -1) bit.add(comp[s], 1);
        else ans[id] = bit.sum(comp[s], comp[t]);
    }
    for (auto &x: ans) cout << x << endl;
    return 0;
}


Measured memory_bytes: 11164
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <functional>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007

using namespace std;

int main(){
    lli n,m,ans;
//    lli i,j,k;
    cin>>n>>m;
    if((n>1)&&(m>1)){
        ans=(n-2)*(m-2);
    }
    else{
        if(n==1){
            if(m==1){
                ans=1;
            }
            else{
                ans=m-2;
            }
        }
        else{
            ans=n-2;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int n;
    cin >> n;
    int mi = 1e9, ma = -1e9;
    REP(i, n){
        int a;
        cin >> a;
        mi = min(mi, a);
        ma = max(ma, a);
    }
    cout << ma - mi << endl;
    return 0;
}

Measured memory_bytes: 256
s=gets.chomp
t=gets.chomp
diff=0
ans=t.length
(s.length-t.length+1).times do |i|
  diff=0
  t.length.times do |j|
    if t[j] != s[i+j]
      diff+=1
    end
  end
  ans = [ans, diff].min
end
puts ans


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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

int n;
int h[ N ];
int dp[ N ];

int solve( int idx ) {
        if( idx == n ) return 0;
        if( idx > n ) return inf;
        if( dp[idx] != -1 ) return dp[idx];
        int ret = inf;
        ret = min( ret , solve( idx + 1 ) + abs( h[idx+1] - h[idx] ) );
        ret = min( ret , solve( idx + 2 ) + abs( h[idx+2] - h[idx] ) );
        return dp[idx] = ret;
}
int main( ) {
        IO;
        #ifdef LOCAL
            freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        cin >> n;
        for( int i = 1; i <= n; i++ ) cin >> h[i];
        memset( dp , -1 , sizeof( dp ) );
        cout << solve( 1 ) << endl;
        return 0;
}






Measured memory_bytes: 4224
#include <stdio.h>
#include <string.h>
int main(){
  int n,len;
  char s[10000]={0};
  scanf("%d",&n);
  scanf("%s",s);
  len = strlen(s);
  for(int i=0; i<len; i++){
    s[i] += n;
    if( s[i] > 'Z' ){ s[i] = 'A' + s[i] - 'Z' - 1; }
    printf("%c",s[i]);
  }
  return 0;
}

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

int main(void){
    long N;
    cin >> N;
    long n[5];
    long min{1000000000000000};

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

    if(N%min==0)
        cout << N/min+4 << endl;
    else
        cout << N/min+1+4 << endl;
}


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

int main(){
    int a, b, c, count;
    cin >> a >> b >> c;
    count = 0;
    
    while(1){
        count++;
        c -= a;
        if(count%7 == 0) c -= b;
        if(c <= 0) break;
    }
    
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    int a=C/B;
    int b=A/D;
    if(C%B!=0){
        a++;
    }
    if(A%D!=0){
        b++;
    }
    if(a<=b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

int main()
{
    int n,a,res=0,k=1;
    cin>>n;
    for(int i = 0 ; i<n ; i++){
        cin>>a;
        if(a == k){
            res++;
            k++;
        }
    }
    if(res == 0){
        cout<<"-1\n";
        return 0;
    }
    cout<<n-res<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007
#define INF -99999999 
using namespace std;

int main()
{
    int N,A,B;
    cin >> N >> A >> B;
    string S;
    cin >> S;
    int jcnt,ocnt;
    jcnt = ocnt = 0;
    for (int i = 0; i < N; i++)
    {
        if(S[i] == 'a'){
            if(jcnt + ocnt < A+B){
                cout << "Yes" << endl;
                jcnt++;
            }else{
                cout << "No" << endl;
            }
            
        }else if(S[i] == 'b'){
            if(jcnt + ocnt < A+B and ocnt < B){
                cout << "Yes" << endl;
                ocnt++;
            }else{
                cout << "No" << endl;
            }
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 896
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 10){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};



void solve(){
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  vector<ll> cnt(60);
  rep(i, N){
    rep(j, 60){
      if((A[i]>>j)&1) cnt[j]++;
    }
  }

  ll ans = 0;
  rep(i, N){
    rep(j, 60){
      if((A[i]>>j)&1){
        ans += (1LL<<j) % MOD * (N - cnt[j]) % MOD;
        ans %= MOD;
      }else{
        ans += (1LL<<j) % MOD * cnt[j] % MOD;
        ans %= MOD;
      }
    }
  }
  ans *= inverse(2);
  ans %= MOD;
  cout << ans << endl;
}

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


Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}





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

  ll N; cin >> N ;
  vector<ll> A; 
  ll even = 0;

  rep(i,N){
    ll inp; cin >> inp;
    A.pb(inp);
    if(inp%2 == 0) even++;
  }
  cout << pow(3,A.size())-pow(2,even) << endl;
    
  //cout << fixed << setprecision(16) << ans << endl;
  
  return 0;
}


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

int main(){

    string S;
    cin >> S;

    int ans = 0;

    for(int i = 0; i < 4; i++){
        if(S.substr(i,1) == "+"){
            ans++;
        } else{
            ans--;
        }
    }

    cout << ans << endl;
}

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

using namespace std;

int main()
{
    int h,w;
    cin>>h>>w;
    vector<vector<char>> table(h,vector<char>(w));
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>table.at(i).at(j);
        }
    }
    vector<bool>gyou(h);
    vector<bool>retu(w);
    for(int i=0;i<h;i++)
    {
        bool flg = true;
        for(int j=0;j<w;j++)
        {
            if(table.at(i).at(j) == '.')
            {
                flg = flg && true;
            }else{
                flg = flg && false;
            }
        }
        gyou.at(i) = flg;
    }
    for(int i=0;i<w;i++)
    {
        bool flg = true;
        for(int j=0;j<h;j++)
        {
            if(table.at(j).at(i) == '.')
            {
                flg = flg && true;
            }else{
                flg = flg && false;
            }
        }
        retu.at(i) = flg;
    }
    for(int i=0;i<h;i++)
    {
        if(gyou.at(i))
        {
            continue;
        }else{
            for(int j=0;j<w;j++)
            {
                if(retu.at(j))
                {
                    continue;
                }else{
                    cout<<table.at(i).at(j);
                }
            }
        }
        cout<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<(n);i++)
const int MOD = 1e9 + 7 ;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=100005;
bool cmp(pair<string,pii> a,pair<string,pii> b)
{
      if(a.fi==b.fi) return a.se.fi>b.se.fi;
      return a.fi<b.fi;
}
int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int a,p;
      cin>>a>>p;
      cout<<(a*3+p)/2;
}     


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

int main(){
    long N;
    cin >> N;
    N--;
    string name = "";
    char digit = 'a';
    while (N >= 0) {
        if (N % 26 != 0) {
            digit = 'a' + N % 26;
        } else {
            digit = 'a';
            
        }
        name = digit + name;
        N = N / 26 - 1;
        
    }
    cout << name << endl;
}


Measured memory_bytes: 3464
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);while((a%b)!=0){a=b;b=a%b;}return b;}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};


int main(){
  int n,m; cin>>n>>m;
  if(n==m)
  puts("Yes");
  else
  puts("No");


  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fi first
#define se second
int main(){
    int a, b, c, k;
    cin>>a>>b>>c>>k;
    while (b<=a){
        b*=2;
        k--;
    }
    while (c<=b){
        c*=2;
        k--;
    }
    if (k>=0) cout<<"Yes\n";
    else cout<<"No\n";
}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdio.h>
#include <set>
#include <vector>
using namespace std;

int main(){
    string s;
    cin>>s;
    vector<char> v;
    for(auto i: s){
        if(i=='0'){
            v.push_back('0');
        }
        else if(i=='1'){
            v.push_back('1');
        }
        else{
            if(v.size()>0){
                v.pop_back();
            }
        }
    }
    for(auto i:v){
        cout<<i;
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
from math import cos
from math import sqrt
from math import radians
A,B,H,M=map(int, input().split())

hour=360*(H/12)+30*((M)/60)
minu=360*(M/60)


deg=min(abs(hour-minu), 360-abs(hour-minu))
if deg==0:
    print(abs(A-B))
    exit()
ans2=A**2+B**2-2*A*B*cos(radians(deg))

print(sqrt(ans2))

Measured memory_bytes: 9520
#include<bits/stdc++.h>
using namespace std;
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
#define bug(a)       cerr << #a << " : " << a << endl;
template<class T>void ExEuclid(T n, T m, T &a, T &b, T &gcd){if(m==0){gcd=n;a=1;b=0;return;}ExEuclid(m,n%m,a,b,gcd);T x=a;a=b;b=x-(n/m)*a;}
template<class T>T gcd(T n, T m){if(m==0){return n;}gcd(m,n%m);}
template<class T>T lcm(T n, T m){return (n*m)/gcd(n,m);}
template<class T>string to_string(T n){string s="";while(n)s+=((n%10)+'0'),n/=10;reverse(s.begin(),s.end());return s;}
template<class T>ll to_int(T s){ll num=0,power=0;for(int i=s.size()-1; i>=0; i--)num+=(pow(10.0,power++)*(s[i]-'0'));return num;}
template<class T>bool is_mod(T n, T m){if(n%m==0)return true;return false;}
template<class T>bool is_upper(T s){for(int i=0; i<s.size(); i++)if(s[i]>90 || s[i]<65)return false;return true;}
template<class T>bool is_lower(T s){for(int i=0; i<s.size(); i++)if(s[i]>122 || s[i]<97)return false;return true;}
template<class T>T mod(T n, T m){return ((n%m)+m)%m;}
template<class T>T Big_mod(T base, T power, T MOD){
    if(power==1)return base;
    if(power & 1)return ((base%MOD)*(Big_mod(base,power-1,MOD))%MOD)%MOD;
    else {T temp=(Big_mod(base,power>>1,MOD));return ((temp%MOD)*(temp%MOD))%MOD;}
}



int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    faster_io;
    int n,m,c;
    cin>>n>>m>>c;
    int a[m+5],cnt=0;
    for(int i=0; i<m; i++)cin>>a[i];
    while(n--){
        int x,s=0;
        for(int j=0; j<m; j++){
            cin>>x;
            s+=(x*a[j]);
        }
        if((s+c)>0)cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256