akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

class Car{
public:
  int id, in_time, rem_time;
  Car(){}
  Car(int a, int b, int c): id(a), in_time(b), rem_time(c){}
};

const int INF = (1<<28);

int m, n;
queue<Car> que;
Car pa[20];
vector<int> ans;

void init(){
  for(int i=0;i<m*2;i++) pa[i] = Car(-1, -1, -1);
  while(!que.empty()) que.pop();
  ans.clear();
}

bool is_full(){
  for(int i=0;i<m*2;i++) if(pa[i].id == -1) return false;
  return true;
}

void car_into(int t){
  while(!que.empty()){
    Car c = que.front();
    if(c.in_time > t || is_full()) break;
    int pos = -1;
    for(int i=1;i<m*2;i+=2){
      if(pos == -1 && pa[i].id == -1 && pa[i-1].id == -1) pos = i;
    }
    if(pos != -1){
      pa[pos] = c;
      que.pop();
      continue;
    }
    int valm = INF;
    pos = -1;
    for(int i=0;i<m*2;i+=2){
      if(pa[i].id != -1) continue;
      if(pa[i+1].rem_time >= c.rem_time){
        if(valm > abs(pa[i+1].rem_time - c.rem_time)){
          valm = abs(pa[i+1].rem_time - c.rem_time);
          pos = i;
        }
      }
    }
    if(pos != -1){
      pa[pos] = c;
      que.pop();
      continue;
    }
    valm = INF;
    pos = -1;
    for(int i=0;i<m*2;i+=2){
      if(pa[i].id != -1) continue;
      if(valm > abs(pa[i+1].rem_time - c.rem_time)){
        valm = abs(pa[i+1].rem_time - c.rem_time);
        pos = i;
      }
    }
    if(pos != -1){
      pa[pos+1].rem_time = c.rem_time;
      pa[pos] = c;
      que.pop();
      continue;
    }
  }
}

void put_out(int t){
  while(1){
    int valm = INF;
    int ex_pos = -1;
    for(int i=0;i<m*2;i++){
      if(pa[i].id == -1) continue;
      if(pa[i].rem_time > 0) continue;
      if(valm > pa[i].rem_time){
        valm = pa[i].rem_time;
        ex_pos = i;
      }
    }
    if(ex_pos == -1) break;
    ans.push_back(pa[ex_pos].id);
    pa[ex_pos] = Car(-1, -1, -1);
  }
}

bool is_empty(){
  for(int i=0;i<m*2;i++) if(pa[i].id != -1) return false;
  return true;
}

main(){
  while(cin >> m >> n && (m|n)){
    init();
    for(int i=0;i<n;i++){
      Car in = Car(i+1, i*10, 0);
      cin >> in.rem_time;
      que.push(in);
    }
    for(int t=0;;t+=1){
      if(t > 0 && is_empty()) break;
      for(int i=0;i<m*2;i++){
        if(pa[i].id == -1) continue;
        pa[i].rem_time -= 1;
      }
      put_out(t);
      car_into(t);
    }
    cout << ans[0];
    for(int i=1;i<ans.size();i++) cout << " " << ans[i];
    cout << endl;
  }
}

Measured memory_bytes: 3076
fn main() {
    let s: Vec<char> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim().chars().collect()
    };
    let t: Vec<char> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim().chars().collect()
    };

    let ma = s.len() - t.len() + 1;
    let mut ans = t.len();
    for start in 0..ma {
        let mut cnt = 0;
        for i in 0..t.len() {
            if t[i] != s[i + start] {
                cnt += 1;
            }
        }
        ans = if ans > cnt { cnt } else { ans };
    }
    println!("{}", ans)
}


Measured memory_bytes: 2140
import sys
from collections import *
from heapq import *
INF = 500000
mod = 10**9+7

def dijkstra(s):
    dist = defaultdict(lambda : INF)
    dist[s], h = 0, []
    heappush(h, (0, s))
    while (len(h)):
        dv, v = heappop(h)
        if dv > dist[v]:
            continue
        for u in es[v]:
            tmp = dv+1
            if tmp < dist[u]:
                dist[u] = tmp
                heappush(h, (tmp, u))
    return dist

H, W = map(int, input().split())
f = [input() for i in range(H)]
V = []
for i in range(H):
    for j in range(W):
        if f[i][j] == '.':
            V.append((i, j))
es = defaultdict(list)
for i in range(H):
    for j in range(W-1):
        if f[i][j] == '.' and f[i][j+1] == '.':
            es[(i, j)].append((i, j+1))
            es[(i, j+1)].append((i, j))
for i in range(H-1):
    for j in range(W):
        if f[i][j] == '.' and f[i+1][j] == '.':
            es[(i, j)].append((i+1, j))
            es[(i+1, j)].append((i, j))
ans = 0
for v in V:
    ans = max(ans, max(dijkstra(v).values()))
print(ans)


Measured memory_bytes: 63452
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		try {
			int correctNum = scanner.nextInt();
			int correctYen = scanner.nextInt();

			for (int x = correctNum; x >= 0; x--) {
				if (calc(x,0,0)> correctYen) {
					continue;
				}
				for (int y = 0; y <= correctNum - x; y++) {
					int z = correctNum - (x + y);
					int sumYen = 10000 * x + 5000 * y + 1000 * z;
					if (sumYen == correctYen) {
							System.out.print(String.valueOf(x) + " " + String.valueOf(y) + " " + String.valueOf(z));
							return;
					}
				}
			}
			System.out.print("-1 -1 -1");
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			scanner.close();
		}
	}

	private static int calc(int x, int y, int z) {
		return 10000 * x + 5000 * y + 1000 * z;
	}
}


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


int main(){
    int n,m,a,b;
    cin >> n >> m;
    set<int>ans;
    vector<long long>h(n);
    vector<vector<int>> rute(n);
    for(int i = 0;i < n;i++){
        cin >> h[i];
        ans.insert(i);
    }
    for(int i = 0;i < m;i++){
        cin >> a >> b;
        if(h[a - 1] < h[b - 1])ans.erase(a - 1);
        else if (h[a - 1] == h[b - 1])ans.erase(a - 1),ans.erase(b - 1);
        else ans.erase(b - 1);
    }
    cout << ans.size() << endl;

}

Measured memory_bytes: 11172
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b)for(int i=a;i<b;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define clr1(arr) memset(arr,-1,sizeof(arr));
#define clr0(arr) memset(arr,0,sizeof(arr));
#define pi pair<int,int>
#define pii pair<int,pi>
#define all(v) v.begin(),v.end()
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
/*
2d pointer array
int **dp;
in main function
int row,col;
dp=new int*[n];
rep(i,n)dp[i]=new int[m]
*/
int32_t main()
{
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  fastio
  int a,b,c,d;
  string s;
  char z;
  cin>>s;
  //s=" "+s;
  int flag=0;
  //repre(i,1,s.size())cout<<i<<" "<<s[i]<<endl;U
  rep(i,s.size())
  {
    if(i%2==0){
      if(s[i]=='R' || s[i]=='U' || s[i]=='D')continue;
      else
      {
        flag=1;
        break;
      }
    }
    else
    {
      if(s[i]=='L' || s[i]=='U' || s[i]=='D')continue;
      else
      {
        flag=1;
        break;
      }
    }
  }
  if(flag)cout<<"No\n";
  else cout<<"Yes\n";
  return 0;
}


Measured memory_bytes: 256
def main():

    N, K = map(int, input().split())
    S = input()
    ans = 0
    for i in range(N - 1):
        if S[i] == S[i + 1]:
            ans += 1
    print(min((ans + 2 * K), N - 1))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
n,m = map(int,input().split())
h=[]
h.extend(input().split())
h=list(map(int,h))
cnt = [0]*n
cnt2 = [0]*n
ans = 0

for i in range(m):
  a,b = map(int,input().split())
  if h[a-1] > h[b-1]:
    cnt[a-1] += 1  
  if h[a-1] < h[b-1]:
    cnt[b-1] +=1
  cnt2[a-1] +=1
  cnt2[b-1] +=1

for p in range(n):
  if cnt[p]==cnt2[p]:
    ans += 1
print(ans)


Measured memory_bytes: 20056
#include <iostream>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a<=0&&0<=b)cout<<"Zero"<<endl;
    else if(a>0||abs(a-min(b,-1)+1)%2==0)cout<<"Positive"<<endl;
    else cout<<"Negative"<<endl;
}

Measured memory_bytes: 256
n=int(input())
ans=[0,0,0,0]
for i in range(n):
  a=str(input())
  if a=="AC":
    ans[0]+=1
  elif a=="WA":
    ans[1]+=1
  elif a=="TLE":
    ans[2]+=1
  else:
    ans[3]+=1

print("AC x "+str(ans[0]))
print("WA x "+str(ans[1]))
print("TLE x "+str(ans[2]))
print("RE x "+str(ans[3]))
    

Measured memory_bytes: 9212
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

int initNeed[300][300];

class State {
private:
	int processNum;
	int resourceNum;
	int need[300][300];
	int needSum[300];
	int rest[300];
	int terminate[300];
public:
	void initialize(int p, int r){
		processNum = p;
		resourceNum = r;
		for(int i=0;i<r;i++) cin >> rest[i];
		for(int i=0;i<p;i++){
			for(int j=0;j<r;j++) cin >> need[i][j];
			needSum[i] = 0;
			for(int j=0;j<r;j++) needSum[i] += need[i][j];
		}
		memcpy(initNeed, need, sizeof(need));
		for(int i=0;i<p;i++) terminate[i] = 0;
	}
	void progress(int P, int R){
		--need[P][R];
		--needSum[P];
		--rest[R];
		if(needSum[P] == 0){
			for(int i=0;i<resourceNum;i++){
				rest[i] += initNeed[P][i];
			}
			terminate[P] = 1;
		}
	}
	bool valid(){
		while(true){
			bool update = false;
			for(int i=0;i<processNum;++i){
				if(terminate[i]) continue;
				bool ok = true;
				for(int j=0;j<resourceNum;j++){
					if(need[i][j] > rest[j]){ ok = false; break; }
				}
				if(ok){
					terminate[i] = 1;
					for(int j=0;j<resourceNum;++j){
						rest[j] += initNeed[i][j] - need[i][j];
					}
					update = true;
				}
			}
			if(!update) break;
		}
		for(int i=0;i<processNum;++i) if(!terminate[i]) return false;
		return true;
	}
};

int main(){
	int p, r, t;
	while(cin >> p >> r >> t){
		State s; s.initialize(p, r);
		vector<int> P(t), R(t);
		for(int i=0;i<t;i++){
			cin >> P[i]; --P[i];
			cin >> R[i]; --R[i];
		}
		s.progress(P[0], R[0]);
		State m, v;
		int low = 0, high = t;
		while(high - low > 1){
			int mid = (low+high)/2;
			m = s;
			for(int i=low+1;i<=mid;i++){
				m.progress(P[i], R[i]);
			}
			v = m;
			if(v.valid()){
				low = mid;
				s = m;
			} else {
				high = mid;
			}
		}
		cout << (low==t-1 ? -1 : low+2) << endl;
	}
}

Measured memory_bytes: 4060
k, a, b = map(int, input().split())
if a+ 1 >= b:
    ans = k + 1
else:
    if k - a - 1 <  0:
        ans = k + 1
    else:
        n = (k - a - 1) // 2
        m = (k - a - 1) % 2
        ans = b + n * (b - a) + m


print(int(ans))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
#define vecout(V) for(int i=0;i<V.size();i++) {cout<<V[i]<<endl;}
typedef long long ll;

int main(void){
    ll a, b, k;
    cin>>a>>b>>k;
    ll ans1, ans2;
    if(k<=a) {
        ans1=a-k;
        ans2=b;
    }
    else if(k<=a+b){
        ans1=0;
        ans2=b-(k-a);
    }
    else {
        ans1=0;
        ans2=0;
    }
    cout<<ans1<<" "<<ans2<<endl;
    return 0;
}

Measured memory_bytes: 256
/*2019/08/25 */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
#define MIN 999999999
#define MAX -999999999
typedef long long int ll;
typedef unsigned long long int ull;
void llswap(ll *x,ll *y){ll temp;temp=*x;*x=*y;*y=temp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){return *(int*)a-*(int*)b;}
int desc(const void *a,const void *b){return *(int*)b-*(int*)a;}
int llasc(const void *a,const void *b){return *(ll*)a-*(ll*)b;}
int lldesc(const void *a,const void *b){return *(ll*)b-*(ll*)a;}
/*
int asc_t(const void *a,const void *b){return ((struct_t*)a)->member - ((struct_t*)b)->member;}
int desc_t(const void *a,const void *b){return ((struct_t*)b)->member - ((struct_t*)a)->member;}
*/
int main(){
    int n,m;
    static int stair[200000]={},a[200000];
    static ull dp[200000]={};

    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        scanf("%d",&a[i]);
        stair[a[i]-1]=1;
    }
    dp[0]=1;
    if(stair[0]!=1){
        dp[1]=1;
    }
    for(int i=1;i<n;i++){
        if(stair[i]!=1){
            dp[i+1]=dp[i]+dp[i-1];
        }
        if(dp[i+1]>=MOD){
            dp[i+1]%=MOD;
        }
    }
    printf("%llu\n",dp[n]%MOD);
    return 0;
}

Measured memory_bytes: 1536
from itertools import product
def myketa(num):
  cc = 0
  while num > 0:
    num //= 10
    cc += 1
  return cc

n = int(input())
keta = myketa(n)
lst = []
for k in range(1, keta+1):
  lst += [''.join(i) for i in product('357', repeat=k)]
print(sum([int(x) <= n and len(set(x)) == 3 for x in lst]))

Measured memory_bytes: 5288
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define P pair<ll, ll>
#define V vector<ll>
#define C vector<char>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mod 1000000007
#define rep(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++)


int power(ll x, unsigned int y)  
{  
	ll p=mod;
    ll res = 1;      
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    { 
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}  
ll gcdExtended(ll a, ll b, ll *x, ll *y)  
{  
    // Base Case  
    if (a == 0)  
    {  
        *x = 0;  
        *y = 1;  
        return b;  
    }  
  
    ll x1, y1; // To store results of recursive call  
    ll gcd = gcdExtended(b%a, a, &x1, &y1);  
  
    // Update x and y using results of  
    // recursive call  
    *x = y1 - (b/a) * x1;  
    *y = x1;  
  
    return gcd;  
}  

int main()
{
	ll n;
	cin>>n;
	ll ans =0;
	n--;
	ans=(n*(n+1))/2;
	cout<<ans;
	//cout<<"djlk";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
 
#define INF (1e9)
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 

 
int vector_finder(std::vector<int> vec, int number) {
  size_t index = std::distance( vec.begin(), std::find(vec.begin(), vec.end(), number) );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int gcd(int a,int b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}


int N;

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

	int x[N];
	REP(i,N){
		cin >> x[i];
		x[i] = abs(X - x[i]);
		
	}

	int g;
	if(N==1){
		g = x[0];
	}
	else if(N==2){
		g = gcd(x[0], x[1]);
	}
	else{
			g = gcd(x[0], x[1]);
			for (int i = 2; i < N; i++)
			{
				g = gcd(g, x[i]);
		}
	}
	cout <<g << endl;

	return 0;
}

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

#define PI 3.141592653589793238
#define INF 1050000000

using namespace std;



//cout << fixed << setprecision(15) << << endl;
//cout << << endl;

int main() {

	int A, B,C;

	cin >> A >> B >> C;

	bool k = false;

	if (A == 7 && B == 5 && C == 5) {
		k = true;
	}
	if (A == 5 && B == 7 && C == 5) {
		k = true;
	}
	if (A == 5 && B == 5 && C == 7) {
		k = true;
	}

	if (k) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}



	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Output
template<class T, class S> std::ostream& operator <<(std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator <<(std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv)
{
  for (auto& vec : vv){ os << vec << std::endl; }
  os << "--------" << std::endl;
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H&& head){ std::cout << head << std::endl; }
template<typename H, typename... T> void print(H&& head, T&&... tail){
  std::cout << head << " ", print(std::forward<T>(tail)...);
}

void solve()
{
  ll N;
  std::string S;
  std::cin >> N >> S;

  std::vector<ll> r(N+1, 0LL);
  std::vector<ll> g(N+1, 0LL);
  std::vector<ll> b(N+1, 0LL);

  for (ll i = N-1; i >= 0; i--) {
    r[i] = r[i+1];
    g[i] = g[i+1];
    b[i] = b[i+1];
    if (S[i] == 'R') r[i]++;
    if (S[i] == 'G') g[i]++;
    if (S[i] == 'B') b[i]++;
  }

  ll ans = 0LL;
  for (ll i = 0; i < N; i++) {
    for (ll j = i+1; j < N; j++) {
      if ((S[i] == 'R' && S[j] == 'G') || (S[i] == 'G' && S[j] == 'R')) {
        ans += b[j+1]; if (2 * j - i < N && S[2 * j - i] == 'B') ans--;
      }
      if ((S[i] == 'R' && S[j] == 'B') || (S[i] == 'B' && S[j] == 'R')) {
        ans += g[j+1]; if (2 * j - i < N && S[2 * j - i] == 'G') ans--;
      }
      if ((S[i] == 'G' && S[j] == 'B') || (S[i] == 'B' && S[j] == 'G')) {
        ans += r[j+1]; if (2 * j - i < N && S[2 * j - i] == 'R') ans--;
      }
    }
  }

  print(ans);
  return;
}

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

  solve();
  return 0;
}



Measured memory_bytes: 3708
#include<stdio.h>
#include<stdlib.h>

int cmp( const void *p, const void *q ) {
    return -*(int*)p + *(int*)q;
}

int main()
{
    int d[210],a[210000],i,n,j,k,sum=0,suu=1;
	
	scanf("%d%d", &n,&k);
	for(i=0; i<k;i++){
		
		scanf("%d", &d[i]);
      for(j=0;j<d[i];j++){
        scanf("%d",&a[sum]);
        sum++;
      }
	}
   qsort(a,sum,sizeof(int),cmp);
  for(i=1;i<sum;i++){
    if(a[i]!=a[i-1]){
      suu++;
    }
  }
    printf("%d\n",n-suu);
  return 0;
  
}


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

long long x, y;

long long solve();

int main() {
  cin >> x >> y;

  cout << solve() << endl;
  return 0;
}

long long solve() {
  if(x % y == 0) return -1;
  return x * (y - 1);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>

using namespace std;

int V[50];

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

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

    int P = (N > K) ? K : N;

    int result = -10'000'000 * 50;
    for (int nm = 0; nm <= P; nm++)
    {
        for (int n = 0; n <= nm; n++)
        {
            int m = nm - n;
            int p = K - nm;
            int tmp[50];

            for (int i = 0; i < nm; i++)
            {
                int idx = (N - m + i) % N;
                tmp[i] = V[idx];
            }

            sort(tmp, tmp + nm);

            /*cout << ">>";
            for (int i = 0; i < nm; i++)
            {
                cout << tmp[i] << ", ";
            }
            cout << endl;*/

            int discard = -1;
            for (int i = 0; i < p; i++)
            {
                if (tmp[i] >= 0)
                {
                    break;
                }
                discard = i;
            }

            int b = (discard == -1) ? 0 : discard + 1;
            int score = 0;
            for (int i = b; i < nm; i++)
            {
                score += tmp[i];
            }

            /*cout << "re";
            for (int i = b; i < nm; i++)
            {
                cout << tmp[i] << ", ";
            }
            cout << endl;*/
            result = (result < score) ? score : result;
        }
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111
	
	bool isprime(int x){
	for(int i = 2;i*i<=x;i++){
		if(x%i == 0)return false;
	}
	return x!=1;
	}



	void solve(){


		ini(n);
		int tmp =n;
		vi morty;
		for (int  i = 2; i*i<=n; i++)
		{
			if(n%i == 0){
				while (n%i==0)
				{
					n/=i;
					morty.push_back(i);
				}
				
			}
		}
		if(n!=1)morty.push_back(n);
		cout<<tmp<<": ";
		FOR(i,0,morty.size()){
			cout<<morty[i];
			if(i!=morty.size()-1)cout<<" ";
		}
		out();
		
		

		


		
		
	}



	



















int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}



Measured memory_bytes: 3176
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    a[x - 1] = i;
  }
  ll ans = (a[0] + 1) * (n - a[0]);
  set<int> se;
  se.insert(a[0]);
  // cout << ans << endl;
  for (int i = 1; i < n; ++i) {
    auto it = se.lower_bound(a[i]);
    ll l, r;
    if (it == se.end()) {
      r = n;
    } else {
      r = *it;
    }
    if (it == se.begin()) {
      l = -1;
    } else {
      l = *(--it);
    }
    ans += (a[i] - l) * (r - a[i]) * (i + 1);
    se.insert(a[i]);
    // cout << l << r << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
class UnionFindTree
{
    vector<int> parent;
    vector<int> depth;
    vector<int> cnt;

public:
    UnionFindTree(int n) : parent(n), depth(n), cnt(n)
    {
        for (int i = 0; i < n; i++)
        {
            parent[i] = i;
            depth[i] = 0;
            cnt[i] = 1;
        }
    }

    //木の根を求める
    int find(int x)
    {
        if (parent[x] == x)
        {
            return x;
        }
        else
        {
            return parent[x] = find(parent[x]);
        }
    }

    //xとyの属する集合を併合
    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (depth[x] < depth[y])
        {
            parent[x] = y;
            cnt[y] += cnt[x];
        }
        else
        {
            parent[y] = x;
            cnt[x] += cnt[y];
            if (depth[x] == depth[y])
                depth[x]++;
        }
    }
    // 同じ集合に属しているか判定
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
    // 集合のサイズを取得
    int size(int x)
    {
        return cnt[find(x)];
    }
};

int main(){
    int n,k;
    UnionFindTree utree(200100);
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n){
        cin >> p[i];
    }
    int ans = n-k+1;
    set<int> s;
    set<int> s2;
    rep(i,k){
        s.insert(p[i]);
    }
    for(int i=k;i<n;i++){
        s.insert(p[i]);
        if(*--s.end()==p[i] && p[i-k]==*s.begin()){
            utree.unite(i-k,i-k+1);
            ans--;
        }
        s.erase(p[i-k]);
    }
    int now = 0;
    for(int i = 1;i<n;i++){
        if(p[i]>p[i-1]){
            if(i-now>=k-1){
                s2.insert(i-k+1);
            }
        }
        else{
            now = i;
        }
    }
    now = *s2.begin();
    for(auto i:s2){
        if(!utree.same(now,i)){
            ans--;
            utree.unite(now,i);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12800
S = [i for i in input()]
S_len = len(S)
ans = 0
if (S_len % 2 == 0):
    a = S[0:int(S_len / 2)]
    b = S[int(S_len / 2):S_len][::-1]
    for i,j in zip(a,b):
        if not i == j:
            ans += 1
        else:
            continue
else:
    a = S[0:int(S_len / 2)]
    b = S[int(S_len / 2) + 1:S_len][::-1]
    for i,j in zip(a,b):
        if not i == j:
            ans += 1
        else:
            continue
print(ans)

Measured memory_bytes: 3064
n = int(input())
a= list(map(int,input().split()))
c = 1
if 0 in a:
    print(0)
else:
    for x in a:
        if x >10**18:
            print(-1)
            break
        else:
            z = x*c
            c = z
            if z >10**18:
                print(-1)
                break
    else:
        print(z)

Measured memory_bytes: 21556
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL sum = a;
    LL res = 1;
    while(b){
        if(b&1){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}

int main(){
    int n, m;
    while(cin>>n>>m&&n){
        vector<int> N(n), M(m);
        int Nsum=0;
        int Msum=0;
        foreach(i, N){
            cin>>i;
            Nsum+=i;
        }
        foreach(i, M){
            cin>>i;
            Msum+=i;
        }
        int dis = Nsum - Msum;
        if(dis&1){
            cout << -1 << endl;
            continue;
        }
        dis>>=1;
        sort(ALL(N));
        sort(ALL(M));
        bool flag = false;
        foreach(i, N){
            int j = i - dis;
            if(j == *lower_bound(ALL(M), j)){
                cout << i << " " << j << endl;
                flag = true;
                break;
            }
        }
        if(!flag)cout << -1 << endl;
    }
    return 0;
}



Measured memory_bytes: 3112
import java.util.Scanner;
 
public class Main{
 public static void main(String[] args){
  Scanner scanner=new Scanner(System.in);
  int a=scanner.nextInt();
  int b=scanner.nextInt();
  int c=scanner.nextInt();
  int d=scanner.nextInt();
  int e=scanner.nextInt();
  int f=scanner.nextInt();
  scanner.close();
  double concentration=0;
  int total=0;
  int sugar=0;
  for(int na=0;a*na*100<=f;na++)
   for(int nb=0;a*na*100+b*nb*100<=f;nb++)
    for(int nc=0;a*na*100+b*nb*100+c*nc<=f;nc++)
     for(int nd=0;a*na*100+b*nb*100+c*nc+d*nd<=f;nd++)
      if(c*nc+d*nd<=e*(a*na+b*nb)&&(double)(c*nc+d*nd)/(double)(a*na*100+b*nb*100+c*nc+d*nd)>=concentration){
       concentration=(double)(c*nc+d*nd)/(double)(a*na*100+b*nb*100+c*nc+d*nd);
       total=a*na*100+b*nb*100+c*nc+d*nd;
       sugar=c*nc+d*nd;
      }
  System.out.println(total+" "+sugar);
 }
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main
{

	public static class coor
	{
		private int x;
		private int y;
		private int h;
		
		public coor(int x, int y, int h)
		{
			this.x = x;
			this.y = y;
			this.h = h;
		}
		
			
		
	}
	
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		coor[] data = new coor[N];
		
		for(int i = 0; i < N; i++)
			data[i] = new coor(in.nextInt(), in.nextInt(), in.nextInt());

		int guess_x, guess_y = 0, guess_h = 0;
		coor begin = null;
		for(coor begin_test : data)
			if(begin_test.h != 0)
			{
				begin = begin_test;
				break;
			}
						
		flag: for(guess_x = 0; guess_x <= 100; guess_x++)
		{
			for(guess_y = 0; guess_y <= 100; guess_y++)
			{
				guess_h = begin.h + Math.abs(guess_x - begin.x) + Math.abs(guess_y - begin.y);
				int i;
				for(i = 0; i < N; i++)
				{
					int abs_x = Math.abs(guess_x - data[i].x);
					int abs_y = Math.abs(guess_y - data[i].y);
					if(data[i].h != Math.max(0, (guess_h - abs_x - abs_y)))
						break;	
				}
				if(i == N)
					break flag;
			}			
		}
		System.out.println(guess_x + " " + guess_y + " " + guess_h);
	}
}

Measured memory_bytes: 21844
var
  i:longint;
  s:string;
  p,x:boolean;
begin
  read(s);
  for i:=1 to length(s) do
    if s[i]='C' then
      begin
      p:=true; break;
      end;
  if p then
    for i:=i+1 to length(s) do
      if s[i]='F' then
        begin
        x:=true; break;
        end;
  if p and x then write('Yes')
             else write('No');
end.

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define mod 1000000007
#define MOD(x) ((x)%mod)
#define pii pair<int,int>
#define mp(a,b) make_pair(a,b)
using namespace std;
int n,m;
long long a[1005];
long long sum[1005];
long long dp[1005][1005];
int main()
{
	scanf("%d",&n);
	memset(dp,122,sizeof dp);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		sum[i]=sum[i-1]+a[i];
		dp[i][i]=0;
	}
	for(int len=2;len<=n;len++)
	{
		for(int i=1;i+len-1<=n;i++)
		{
			int j=i+len-1;
			for(int k=i;k<j;k++)
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+sum[j]-sum[i-1]);
		}
	}
	printf("%lld",dp[1][n]);
	return 0;
}



Measured memory_bytes: 8192
function Main(input) {
	tmp = input.split(" ");
	ts = parseInt(tmp[0], 10);
  ta = parseInt(tmp[1], 10);
	as = parseInt(tmp[2], 10);
  aa = parseInt(tmp[3], 10);
  for (i=1; ts > 0 && as > 0; i++) {
    if (i % 2 == 0) {
      ts = ts - aa
    } else {
      as = as - ta
    }
  }
  if (as <= 0) {
    console.log('Yes')
  } else {
    console.log('No')
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29448
//101 B - Digit Sums 2018/06/23

#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int S(int64 x){
    int ret=0;
    do {
        ret+=x%10;
        x/=10;
    } while(x!=0);
    return ret;
}

int main(){
    int64 n; cin >> n;
    if(n%S(n)==0) puts("Yes\n");
    else puts("No\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int w, h;
    ll p[112345], q[112345];

    cin >> w >> h;
    REP(i, w)
    cin >> p[i];
    REP(i, h)
    cin >> q[i];

    sort(p, p + w);
    sort(q, q + h);

    p[w] = INT_MAX;
    q[h] = INT_MAX;

    ll res = 0;

    int i = 0;
    int j = 0;

    while (i < w || j < h)
    {
        if (p[i] < q[j])
        {
            res += p[i] * (h + 1 - j);

            i++;
        }
        else
        {
            res += q[j] * (w + 1 - i);

            j++;
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
using namespace std;

int main(){
    int N, M;
    cin >> N;
    string s[N];
    map<string, int> mp;
    for(int i = 0; i < N; i++){
        cin >> s[i];
        mp[s[i]] = 0;
    }
    for(int i = 0; i < N; i++){
        mp[s[i]]++;
    }
    cin >> M;
    string s2[M];
    map<string, int> mp2;
    int ans = 0;
    for(int i = 0; i < M; i++){
        cin >> s2[i];
        mp2[s2[i]] = 0;
    }
    for(int i = 0; i < M; i++){
        mp2[s2[i]]++;
    }
    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        int tmp = mp[itr->first] - mp2[itr->first];
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        w: [chars; n],
    }

    let mut ans = true;

    for i in 0..n {
        for j in i + 1..n {
            if w[i] == w[j] {
                ans = false;
            }
        }
    }

    for i in 0..n - 1 {
        if w[i][w[i].len() - 1] != w[i + 1][0] {
            ans = false;
        }
    }

    let ans = if ans { "Yes" } else { "No" };

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


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;


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

    int s[4];
    int n;
    cin >> n;
    REP(i, 4){
        s[3-i] = n%10;
        n /= 10;
    }
    REP(i, 8){
        int ans = s[0];
        ans = i&0b01 ? ans+s[1] : ans-s[1];
        ans = (i>>1)&0x01 ? ans+s[2] : ans-s[2];
        ans = (i>>2)&0x01 ? ans+s[3] : ans-s[3];
        if(ans == 7){
            cout << s[0]
                 << (i&0b0001 ? "+" : "-") << s[1]
                 << (i&0b0010 ? "+" : "-") << s[2]
                 << (i&0b0100 ? "+" : "-") << s[3]
                 << "=7\n";
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (a) - 1; (i) >= (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
const ll inf = 1e9;

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    rep1(i, k)r = r * n-- / i;
    return r;
}

int main(){
    ll n,m;
    cin >> n >> m;
    vector<pair<ll, ll>> x(m);
    rep0(i, m){
        ll a,b;
        cin >> a >> b;
        x[i] = make_pair(b, a);
    }
    sort(all(x));
    ll ans = 1,c = x[0].first - 1;
    rep1(i, m - 1)if(c < x[i].second){
        ++ans;
        c = x[i].first - 1;
    }
    pf(ans);
    return 0;
}


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

int main()
{
    int numYasumi;
    int numShuku;

    cin >> numYasumi >> numShuku;

    //    vector<int> numDays(numShuku+1, 0);

    int sum = 0;
    int input;

    for (int i = 1; i <= numShuku; i++)
    {
        cin >> input;
        sum = sum + input;
    }

    int ans = numYasumi - sum;

    if (ans >= 0)
    {
        cout << ans << endl;
    }
    else
    {
        cout << "-1" << endl;
    }
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int nxt[200005][30], dp[200005], n, last[30];
char s[200005];
int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	for (int i = 0; i < 26; i ++) nxt[n + 1][i] = n + 1;
	dp[n + 1] = 1;
	for (int i = n; i >= 1; i --) {
		for (int j = 0; j < 26; j ++) nxt[i][j] = nxt[i + 1][j];
		nxt[i][s[i] - 'a'] = i; dp[i] = n + 1;
		for (int j = 0; j < 26; j ++) {
			dp[i] = min(dp[i], dp[nxt[i][j] + 1]);
		} dp[i] ++;
	}
	int t = 1;
	while (t <= n) {
		for (int i = 0; i < 26; i ++) {
			if (nxt[t][i] > n || dp[nxt[t][i] + 1] < dp[t]) {
				putchar('a' + i); t = nxt[t][i] + 1;
				break;				
			}
		}
	} puts("");
	return 0;
}

Measured memory_bytes: 24704
import java.io.PrintWriter;
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();
		sc.close();

		//処理
		int ans = Math.max(c - a + b, 0);
		
		//出力
		PrintWriter out = new PrintWriter(System.out);
		out.println(ans);
		out.flush();
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;cin>>n>>m;
  int ball[n+1];
  for(int i=0;i<n;i++) ball[i]=1;
  bool red[n+1];
  for(int i=0;i<n+1;i++) red[i]=false;
  red[0]=true;
  for(int i=0;i<m;i++){
      int x,y;cin>>x>>y;
      x--;y--;
      ball[x]--;ball[y]++;
      if(red[x]){
          red[y]=true;
      }
      if(ball[x]==0) red[x]=false;
  }
  int res=0;
  for(int i=0;i<n;i++) if(red[i]) res++;
  cout<<res<<endl;
}


Measured memory_bytes: 768
'''ika tako
bit桁ごとに考える。「XORを取り、その後足し算」という計算過程では
他の桁が影響することはないので、桁毎に独立に考えて問題ない。
N = 5
A = {   1   2   3   4   5 }   ↓
    { 001 010 011 100 101 }
たとえば2桁目を取り出すと
       0   1   1   0   0
各ペアでXORを取ると、(0,1)は'1'となり、(0,0)(1,1)は'0'となる。 
0はいくら足しても0なので、(0,1)の数だけわかれば良い。
それは、(0の個数)×(1の個数)で計算できる。
    0が3個、1が2個
→  XORを取ったとき、2桁目について'1'が立っているペア
　　　　　　　　　　　=合計に足される回数は 3x2=6
→  2進数の2桁目は2を表すので、合計に足される値は6x2=12
これを各桁について足し合わせる。
'''
n = int(input())
aaa = list(map(int, input().split()))
 
MOD = 10 ** 9 + 7
ans = 0
m = 1
for _ in range(60):#上限は2＾60なので、60が上限
    bit = sum(a & m for a in aaa)#ｍは何番目のビットが立っているか
    bit //= m
    #bit >>= m これはダメだった。なぜ、だろう？
    non_bit = n - bit
    ans = (ans + bit * non_bit * m) % MOD
    #ｍは上記、2桁目を表す2と同様
    m <<= 1#ビットを１つずつ左シフト
print(ans)

'''
結局この計算は Ai のすべての組み合わせ(Ai 自身同士は含まない)の 
XOR の合計なので、Ai のあるビットの立っている数の合計を c とすると、
Ai のあるビットが0であった場合により計算結果に立つビットの数は 
c、Ai のあるビットが1であった場合により計算結果に立つビットの数は 
N - c になるので、あるビットに関する計算結果は c * (N -c) の
ビットシフトした値になる. 結果として以下の計算で解ける.

N = int(input())
A = list(map(int, input().split()))
 
result = 0
for bit in range(60):
    m = 1 << bit　すべてのビットを調べる
    c = sum(a & m for a in A) >> bit　
    ビット分、戻して、その桁に立っているビット数を算出
    result += (c * (N - c)) << bit　
    ビット分（上記の2桁目の2）調整、イメージとしては2のべき乗倍
    result %= 1000000007
print(result)
'''

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

int main() {
    int N; cin >> N;
    int flag = 1;
    for (int i = 0; i < N; i++) {
        int a; cin >> a;
        if (a % 2) flag = 1 - flag;
    }
    if (flag) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
vector<int>g[110000];
int x[110000];
int y[110000];
int z[110000];
int v[110000][11];
int bfs[110000][11];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		int p,q;scanf("%d%d",&p,&q);
		p--;q--;
		g[p].push_back(q);
		g[q].push_back(p);
	}
	int c;scanf("%d",&c);
	for(int i=0;i<c;i++){
		scanf("%d%d%d",x+i,y+i,z+i);x[i]--;
	}
	priority_queue<pair<int,pair<int,int> > >Q;
	for(int i=0;i<a;i++)for(int j=0;j<11;j++)bfs[i][j]=-1;
	for(int i=0;i<c;i++){
		if(bfs[x[i]][y[i]]>=i)continue;
		bfs[x[i]][y[i]]=i;
		Q.push(make_pair(i,make_pair(x[i],y[i])));
	}
	while(Q.size()){
		int at=Q.top().second.first;
		int rem=Q.top().second.second;
		int col=Q.top().first;
		Q.pop();
		if(v[at][rem])continue;
		v[at][rem]=1;
		if(rem==0)continue;
		for(int i=0;i<g[at].size();i++){
			int to=g[at][i];
			if(v[to][rem-1]||bfs[to][rem-1]>=col)continue;
			bfs[to][rem-1]=col;
			Q.push(make_pair(col,make_pair(to,rem-1)));
		}
	}
	for(int i=0;i<a;i++){
		int ret=-1;
		for(int j=0;j<=10;j++){
			ret=max(ret,bfs[i][j]);
		}
		if(ret==-1)printf("0\n");
		else printf("%d\n",z[ret]);
	}
}

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

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    s = input()
    n = len(s)
    b = [char in ['A', 'T', 'G', 'C'] for char in s]
    ans = 0
    current_streak = 0
    for i in range(n):
        if b[i]:
            current_streak += 1
        else:
            current_streak = 0
        ans = max(ans, current_streak)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
h,w,n=map(int,input().split())
H=[0]*h
W=[0]*w
L=[(0,0)]*n
for i in range(n):
    a,b=map(int,input().split())
    L[i]=(a,b)
    H[a-1]+=1
    W[b-1]+=1
h_max=max(H)
w_max=max(W)
ans=h_max+w_max
cnt=0
for l in L:
    if H[l[0]-1]==h_max and W[l[1]-1]==w_max:
        cnt+=1
if H.count(h_max)*W.count(w_max)==cnt:
    ans-=1
print(ans)

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

using namespace std;
typedef long long ll;
int main()
{
    ll n ;
    cin >> n;
    if(n==7||n==5||n==3)
    {
        cout << "YES\n";
        return 0;
    }
    cout << "NO";
    return 0;
}


Measured memory_bytes: 3552
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<utility>
#include<iostream>
using namespace std;
const int maxn = 2e5 + 233;
int a[maxn],ord[maxn],p[maxn];
bool cmp(const int A,const int B)
{
	return a[A]<a[B];
}
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]),
		ord[i] = i;
	sort(ord+1,ord+1+n,cmp);
	for(int i=1;i<=n;i++)p[ord[i]] = i;
	int t = n>>1;
//	for(int i=1;i<=n;i++)
//	cout<<p[i]<<" ";cout<<endl;
	for(int i=1;i<=n;i++)
	{
		int x = p[i];
		if(x<=t) printf("%d\n",a[ord[t+1]]);
		else printf("%d\n",a[ord[t]]);
	}
	return 0; 
}

Measured memory_bytes: 4480
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));

  $shurui = [];
  for ($i=0; $i<$n; $i++) {
    list($s) = explode(" ", trim(fgets(STDIN)));    
    if(!isset($shurui[$s])){
      $shurui[$s] = true;
    }
  }

  echo count($shurui);

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	int h, w;
	cin >> h >> w;
	char arr[h][w];
	
	int c = 0;
	REP(i, 0, h){
		REP(j, 0, w){
			cin >> arr[i][j];
			if(arr[i][j] == '#') ++c;
		}
	}
	
	int x=0, y=0;
	int ans = 0;
	while(x!= w-1 || y != h-1){
		if(y+1 < h && arr[y+1][x] == '#'){
			++ans;
			++y;
		}
		else if(x+1 < w && arr[y][x+1] == '#'){
			++ans;
			++x;
		}
		else break;
	}
	cout << (ans+1 == c? "Possible":"Impossible");
			

}


Measured memory_bytes: 256