akhauriyash/Code-Regression huggingface dataset:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True


def divisor(n):
    ret = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ret.append(i)
            if n // i != i:
                ret.append(n // i)
    return ret


def sum_arr(a, d, n):
    return (n * (2 * a + (n - 1) * d)) // 2

def divisor_sum(n):
    s = 0
    for i in range(1, n + 1):
        cnt = n // i
        # print(i, cnt, sum_arr(i, i, cnt))
        nxt = sum_arr(i, i, cnt)
        if nxt == 0:
            s += i
        else:
            s += nxt
    return s


def main():
    N = I()

    print(divisor_sum(N))



if __name__ == '__main__':
    main()


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

int n, A[105];

bool check(int x){
  
  int d[105] = {};

  d[1] = 1;

  int update = 1;
  
  while(update){
    
    update = 0;
    
    for(int i=n+2;i>=1;i--) {

      if(d[i]==0) continue;
      
      for(int j=1;j<=x;j++){

	if(i+j>n+2) continue;
	if(A[i+j]==1) continue;
	
	if(d[i+j]==0){
	  update = 1;
	  d[i+j] = 1;
	}
      }
      
    }
    
  }

  return d[n+2];
}

int main(){
  
  cin>>n;
  
  for(int i=0;i<n;i++) cin>>A[i+2];
  
  for(int ans=1;ans<=n+1;ans++){
    
    if(check(ans)){
      cout<<ans<<endl;      
      return 0;
    }
    
  }
  
  return 0;
}



Measured memory_bytes: 3076
#include <iostream>
#include <string>
int main()
{
	std::string s;
	std::cin >> s;
	std::string result;
	for (unsigned int i = 0; i < s.size(); i++)
	{
		if (s[i] == '0')
		{
			result.append("0");
		}
		else if (s[i] == '1')
		{
			result.append("1");
		}
		else if (s[i] == 'B')
		{
			if (result.size() != 0)
			{
				result.pop_back();
			}
		}
	}
	std::cout << result << "\n";
    return 0;
}



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

using str = string;
using ss = stringstream;

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

    str sa,sb,sc;cin>>sa>>sb>>sc;
    deque<int> d[3];
    for(int i=0;i<sa.size();i++)d[0].push_back(sa[i]-'a');
    for(int i=0;i<sb.size();i++)d[1].push_back(sb[i]-'a');
    for(int i=0;i<sc.size();i++)d[2].push_back(sc[i]-'a');

    int t=0;

    char ans='a';

    for(;;)
    {
        if(d[t].size()==0){ans=t+'A';break;}
        int f=t;
        t=d[t][0];
        d[f].pop_front();
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3684
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, double> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;

//to:?????????,cap:??????,rev:???(G[e.to][e.rev]??§??????????§????????????¢???????????§?????????)
struct edge {
	int to, cap, rev;
};

vector<edge> G[1003];
bool used[102];

//???????????????rev???,???????????§??§??????????????????????????????size??§??????????????????????????\?????????????????¨???????????????(i.e ???????????\)???????????????????????????????????§?????????
void add_edge(int from, int to, int cap)
{
	G[from].push_back(edge{ to, cap, (int)G[to].size() });
	G[to].push_back(edge{ from, 0, (int)G[from].size() - 1 });
}

//s??????t????§???????????????????????????????????????§?????????????????????????????????0????????????
int dfs(int v, int t, int f)
{
	if (v == t) return f;
	used[v] = true;
	rep(i, G[v].size()) {
		edge &e = G[v][i];
		if (!used[e.to] && e.cap>0) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

//s??????t???????????§??????????????????
int
max_flow(int s, int t)
{
	int flow = 0;
	while (true) {
		memset(used, 0, sizeof(used));
		int f = dfs(s, t, INF);
		if (f == 0) {
			return flow;
		}
		flow += f;
	}
}

int main() {
	int V, E;
	cin >> V >> E;
	rep(i, E) {
		int u, v, c;
		cin >> u >> v >> c;
		add_edge(u, v, c);
	}

	cout << max_flow(0, V - 1) << endl;

	return 0;
}

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

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

#define P 1000000007

int k[500001];
int rk[500001];

int getk(int a, int x){
	if(x==1) return a;
	int b = getk(a, x/2);
	b = ((long)b)*b%P;
	if((x&1)==0){
		return b;
	}else{
		return ((long)b)*a%P;
	}
}

int comb(int a, int b){
	if(a<b) return 0;
	return ((long)k[a])*rk[b]%P*rk[a-b]%P;
}
int perm(int a, int b){
	if(a<b) return 0;
	return ((long)k[a])*rk[a-b]%P;
}

void comb_init(int n){
	k[0]=1;
	for(int i=1; i<=n; i++){
		k[i]=k[i-1]*((long)i)%P;
	}	
	rk[n]=getk(k[n], P-2);
	for(int i=n-1; i>=0; i--){
		rk[i]=((long)rk[i+1])*(i+1)%P;
	}
}

int main(void){
	int n=nextint();
	int m=nextint();
	comb_init(m);
	long ans=0;
	for(int i=0; i<=n; i++){
		long now = perm(m-i, n-i);
		now = now * now % P;
		now = now * comb(n, i) % P * perm(m, i) % P;
		if(i&1){
			ans-=now;
		}else{
			ans+=now;
		}
	}
	ans = (ans + (long)P * n) % P;
	printf("%ld\n", ans);
}


Measured memory_bytes: 5416
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define LL long long
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

const LL LLINF = 1LL << 60;

int main(void) {
	string s;
	cin >> s;

	int left = 0;
	int right = 0;
	for (int i = 0; i < s.size(); i++){
		if (s[i] == 'A') {
			left = i;
			break;
		}
	}

	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == 'Z') {
			right = i;
		}
	}

	cout << right - left + 1 << endl;

	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(const auto& x : c )cout << x << " "; cout << "\n";
#define PI acos(-1LL)


#ifdef LOCAL
string to_string(const string& s){
    return '"' + s + '"';
}
string to_string(const char* s) {
    return to_string((string) s);
}
string to_string(bool b) {
    return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename T>
string to_string(T v){
    bool first = true;
    string res = "{";
    for(const auto& x: v){
        if(!first) res+=", ";
        first = false;
        res+=to_string(x);
    }
    res+="}";
    return res;
}
void bug() { cerr << endl; }
template<typename Head, typename... Tail>
void bug(Head H, Tail... T) {
    cerr << " " << to_string(H);
    bug(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", bug(__VA_ARGS__);
#else
#define debug(...) 11;
#endif

const int M = 1000000007;
const int N = 2e6 + 5;
const long long INF = 2e18 + 12;

//int dp[2002][2002];
//int fun(int s, int l){
//    if(l == 0 && s == 0){
//        return 1;
//    }
//    if(s < 3 || l <= 0){
//        return 0;
//    }
//    if(dp[s][l] !=-1){
//        return dp[s][l];
//    }
//    int ans = 0;
//    for(int i=3; i<=2000; i++){
//            ans=(ans%M + fun(s - i, l - 1)%M);
//    }
//    dp[s][l] = ans%M;
//    return dp[s][l];
//}

void solve(){
    int n;
    cin >> n;
    int ans =0;
//    memset(dp, -1, sizeof dp);
//    for(int i = 1; i<=2000; i++){
//        int k = fun(n, i);
//        ans=(ans%M + k%M)%M;
//    }
//    cout << ans << endl;
    vector<int> dp(2001, 1);
    dp[0] = dp[1] = dp[2] = 0;
    for(int i=6;i<=2000;i++){
        int sum = 0;
        for(int j=i-3; j>=3; j--){
            sum=(sum + dp[j])%M;
        }
        dp[i] =( dp[i] + sum)%M;
    }
    cout << dp[n]%M << endl;
}
signed main(){
    FAST
#ifdef TIMER
    clock_t start;
    double duration;
    start = clock();
#endif
    int tc = 1;
//    TODO: check for tc
//    cin >> tc;
    for (int tt = 1; tt <= tc; tt++) {
        solve();
    }
#ifdef TIMER
    duration = (clock() - start) / (double) CLOCKS_PER_SEC;
    cerr <<"\n\nTotal time elapsed: "<< duration <<"sec\n";
#endif
}


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


#define INFTY  200006;
int main(){
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i,n) cin >> p[i];
	int min=INFTY;int ans=0;
	rep(i,n){
		if(p[i] < min) min = p[i];
		if(min == p[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}


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

int main()
{
  int n,m,x,y;
  cin >> n>>m>>x>>y;
  int xma = -1000, ymi = 1000;
  int a;
  rep(i, n){
    cin >> a;
    xma = max(xma, a);
  }
  rep(i, m){
    cin >> a;
    ymi = min(ymi, a);
  }
  if(xma < ymi && x < ymi && ymi <= y) {
    cout << "No War" << endl;
  }
  else cout << "War" << endl;
  return 0;
}

Measured memory_bytes: 3624
/*************************************************************************
 > File Name: D.cpp
 > Author: codecode
 > Mail: 2466734364@qq.com
 > Created Time: 2020.1.26.20:13
 ************************************************************************/
#include<bits/stdc++.h>
#define int long long
using namespace std;
int h;
int f(int x){
	if(x==1)return 1;
	return 2*f(x/2)+1;
}
#undef int
int main(){
#define int long long
	cin>>h;
	cout<<f(h);
	return 0;
}


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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {
	cww() { CIN_ONLY{ ios::sync_with_stdio(false); cin.tie(0); } }
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r) { bool a = l>r; if (a)l = r; return a; }
template <typename T>inline bool chmax(T &l, T r) { bool a = l<r; if (a)l = r; return a; }
template <typename T>istream& operator>>(istream &is, vector<T> &v) { for (auto &it : v)is >> it; return is; }

class range { private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n; public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; } };

LL A[112345];
int main() {
	int N;
	while (cin >> N) {
		A[0] = A[N + 1] = 0;
		for (int i : range(1, N + 1)) {
			cin >> A[i];
		}
		LL sum = 0;
		for (int i : range(N + 1)) {
			sum += abs(A[i] - A[i + 1]);
		}
		for (int i : range(1, N + 1)) {
			cout << sum - abs(A[i] - A[i - 1]) - abs(A[i] - A[i + 1]) + abs(A[i - 1] - A[i+1]) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 2048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		if(a==1) {
			a+=13;
		}
		if(b==1) {
			b+=13;
		}
		if(a > b) {
			System.out.println("Alice");
		} else if (a < b) {
			System.out.println("Bob");
		} else {
			System.out.println("Draw");
		}
	}
}



Measured memory_bytes: 23252
package main

import (
        "fmt"
        "sort"
)

func solution(n int, s []int) int {
        sort.Ints(s)
        sum := 0
        for i := range s {
                sum += s[i]
        }

        if sum%10 != 0 {
                return sum
        }

        for i := range s {
                if s[i]%10 != 0 {
                        return sum - s[i]
                }
        }
        return 0
}

func main() {
        var n int
        fmt.Scan(&n)
        s := make([]int, n)
        for i := range s {
                fmt.Scan(&s[i])
        }
        fmt.Println(solution(n, s))
}

Measured memory_bytes: 1844
n=int(input())
q=[]
for _ in range(n):
    d_1,d_2=map(int,input().split())
    if d_1==d_2:
        q.append(1)
    else:
        q.append(0)
for i in range(n-2):
    if q[i]==q[i+1]==q[i+2]==1:
        print("Yes")
        exit()
print("No")

Measured memory_bytes: 61900
#include <iostream>
using namespace std;
int main(){
    int x,y;
    while(cin>>x>>y){        if(x==0&&y==0)break;
        for(int k=1;k<=y;k++){
            cout<<"#";
        }        cout<<endl;
        for(int m=1;m<=x-2;m++){
            cout<<"#";
            for(int j=1;j<=y-2;j++){
                cout<<".";
            }
            cout<<"#"<<endl;
        }
        for(int t=1;t<=y;t++){
            cout<<"#";
        }
        cout<<endl;
cout<<endl;
    }
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

ll n,p,q;
ll c[500010];

int main(void){
	cin >> n >> p >> q;
	rep(i,n) cin  >> c[i];
	rep(i,n) c[i]+=p*(i+1);
	sort(c,c+n),reverse(c,c+n);
	const ll all=p*(n*q+n*(n-1)/2);
	ll sum=0,ans=all;
	rep(i,n){
		sum+=c[i];
		ans=max(ans,all+sum-p*(q+2*n-i-1)*(i+1));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5076
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>

using namespace std;

int main() {
    int n, k;
    char s[n];
    ignore = scanf("%d%d%s", &n, &k, s);

    k--;
    s[k] = tolower(s[k]);
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
///A drunk man will find his way home, but a drunk bird may get lost forever...i
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair <int, int> pii;
#define pb push_back
#define pf push_front
#define f first
#define s second
#define sz(x) (int)x.size()
#define smin(x , y) x = min(x , y)
const int mx = 2000 * 100 + 5;
int a[mx];
int32_t main(){		
	ios_base::sync_with_stdio(false);
    cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	int i = 0, t = 0;
	for(int j = 1; j <= n; j++){
		for(i; i < n; i++){
			if(a[i] == j){
				t++;
				i++;
				break;
			}
		}
	}
	cout << (!t ? -1 : n - t) << endl;
	return 0;
}


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

const int N = 1e5+5;
int cc[N];

void solve() {
    int n;
    scanf("%d",&n);
    int ret = 0;
    for(int i=0;i<n;++i) {
        int a;
        scanf("%d",&a);
        if(a>n) {
            ++ret;
        } else {
            ++cc[a];
        }
    }
    for(int i=1;i<=n;++i) {
        if(cc[i]>=i) {
            ret += cc[i] - i;
        } else {
            ret += cc[i];
        }
    }
    printf("%d\n", ret);
}

int main() {
    //freopen("input.txt","r",stdin);
    solve();
}

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

#define YES cout << "YES" << endl
#define NO  cout << "NO"  << endl
#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 1e18
using namespace std;
typedef long long ll;

int main(){
  int a, b, c;  cin >> a >> b >> c;
  int n = a;
  set<int> rest;
  while(rest.find(n%b) == rest.end()){
    rest.insert(n%b);
    n+=a;
  }
  if(rest.find(c) != rest.end())  YES;
  else  NO;
  return 0;
}


Measured memory_bytes: 256
def BldIn(n):
  Name = [0] * n
  Pos = [0] * n
  segment = {}
  for i in range(n):
    bi, xi, yi = map(int, raw_input().split())
    Name[i] = bi
    Pos[i] = [xi, yi]
    for j in range(i):
      xj, yj = Pos[j]
      tmp = ((xi - xj) ** 2 + (yi - yj) ** 2) ** .5
      segment[(i, j)] = tmp
      segment[(j, i)] = tmp
  return Name, segment

def solve(distance, g):
  for i1, e1 in enumerate(distance):
    d1, p1 = e1
    if d1 != inf and p1 == g: return 1
    x1=[]
    x2=[]
    for i2, e2 in enumerate(distance):
      d2, p2 = e2
      if i1==i2: continue
      dd = segment[(p1, p2)]
      if dd > 50:
        x2.append(e2)
        continue
      if d1 + dd < d2:
        distance[i2][0] = d1 + dd
        Path[p2] = p1
      x1.append(distance[i2])
    if x1: return solve(sorted(x1)+x2, g)
  return 0

def PathOut(g, s):
  x = [Name[g]]
  while g != s:
    g = Path[g]
    x.append(Name[g])
  for e in x[1:][::-1]: print e,
  print x[0]
  return

inf = 1e9
while 1:
  n = int(raw_input())
  if n == 0: break
  Name, segment = BldIn(n)

  m = int(raw_input())
  for _ in [0] * m:
    Path = {}
    s, g = map(Name.index, map(int, raw_input().split()))
    distance = [[inf, i] for i in range(n)]
    distance[s][0] = 0
    if solve(sorted(distance), g): PathOut(g, s)
    else: print "NA"

Measured memory_bytes: 5916
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>


#include <math.h>  /* M_PI */

int main(){

    double r;
    cin >> r;


    printf("%.15f\n", 2* r * M_PI);
}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

signed main() {
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> a(q);
    for (int i = 0; i < q; i++) {
        cin >> a[i];
    }
    vector<int> c(n, k - q);
    for (auto&& x  : a) {
        c[x - 1]++;
    }
    for (auto&& x : c) {
        if (x > 0)
            cout << "Yes" << "\n";
        else
            cout << "No" << "\n";
    }
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, c, k, t[100000], r;

int main() {
	cin >> n >> c >> k;
	rep(i,n) cin >> t[i];
	sort(t, t+n);
	rep(i,n) {
		r++;
		int j = i+1;
		while(j<n && j-i<c && t[j]<=t[i]+k) j++;
		i = j-1;
	}
	cout << r << ln;
}

Measured memory_bytes: 640
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto s = readln.chomp;
  int res, c;
  foreach (e; s) {
    if (e == 'I') {
      c++;
    } else {
      c--;
    }
    res = max(c, res);
  }
  res.writeln;
}


Measured memory_bytes: 256
/*
    Question link: https://cf17-final.contest.atcoder.jp/tasks/cf17_final_d
*/

#include<iostream>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<cstring>
#include<limits>
#include<cmath>

#define LL long long
#define mp make_pair 
#define pb push_back
#define f first
#define s second


using namespace std;

const LL MX = numeric_limits<LL>::max();

struct par{
    int h;
    int p;
}v[5005];


bool cmp(par a, par b){
          return a.h + a.p < b.h + b.p; 
       }

LL dp[5005][5005];



int main(){
    
    int n, ans = 0;
    cin >> n;

    for(int i = 0; i <= n; i++)
        for(int j = 0; j <= n; j++)
                 dp[i][j] = MX;


    for(int i = 1; i <= n; i++){
         cin >> v[i].h >> v[i].p;
      }
    
    sort(v + 1, v + n + 1, cmp);

    for(int i = 0; i <= n; i++) dp[i][0] = 0;

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
             
               dp[i][j] = dp[i-1][j];
               
               if(dp[i-1][j-1] <= v[i].h){
                    dp[i][j] = min(dp[i][j], dp[i-1][j-1] + v[i].p);
                 }
           }
        } 

    
    for(int j = 1; j <= n; j++) if(dp[n][j] != MX) ans = j;

    
    cout << ans;
    
   
  
    return 0;
  }



Measured memory_bytes: 195840
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <deque>
#include <cmath>
#include <iomanip>
#include <cstdio>

using namespace std;

int main(){
    int n; cin >> n;
    int num_mul2=0, num_mul4=0, num_odd=0;
    for(int i=0; i<n; ++i){
        int a; cin >> a;
        if(a%4==0) ++num_mul4;
        else if(a%2==0) ++num_mul2;
        else ++num_odd;
    }
    int ans=num_odd==0 || num_odd<=num_mul4 || (num_odd==num_mul4+1 && num_mul2==0);
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>

int main()
{
    char c;
    scanf ( "%c", &c );
    c++;
    printf ( "%c\n", c );

    return 0;
}


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

const int N = 1e5+2;
const int W = 1e5+2;

void max_val(ll &a, ll b)
{
	a = max(a,b);
}

int main()
{
	int n, w;
	cin >> n >> w;
	int weight, value;
	std::vector<ll> dp(w + 1);

	for(int i = 0; i < n; ++i)
	{
		cin >> weight >> value;
		for(int weight_already = w - weight; weight_already >= 0; --weight_already )
		{
			// cout << "weight_already+weight = " << weight_already+weight << " ";
			// cout << "dp[weight_already+weight] = " << dp[weight_already+weight] << " -> ";
			max_val(dp[weight_already+weight] , (ll)value + dp[weight_already]);
			// cout << dp[weight_already+weight] << "\n";
		}
	}
	ll ans = 0;

	// for(int i = 0; i< w; ++i)
	// 	cout << dp[i] << " ";
	for(int i = 0; i <= w; ++i)
		ans = max(ans, dp[i]);

	cout << ans;


}


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

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> B(N);
	for(int i=0;i<N;i++){
		cin>>A.at(i);
	}
	for(int i=0;i<N;i++){
		cin>>B.at(i);
	}
	long long sum=0;
	int mi=0;
	vector<int> D(N);
	vector<int> E(N);
	for(int i=0;i<N;i++){
		sum+=A.at(i)-B.at(i);
		D.at(i)=A.at(i)-B.at(i);
		E.at(i)=D.at(i);
		if(A.at(i)-B.at(i)<0){
			mi++;
		}
	}
	if(sum<0){
		cout<<-1<<endl;
	}
	else{
		if(mi==0){
			cout<<0<<endl;
		}
		else{
			int ma=N-1;
			sort(D.begin(),D.end());
			sort(E.begin(),E.end());
			for(int i=0;i<mi;i++){
				if(D.at(i)+D.at(ma)>0){
					D.at(ma)+=D.at(i);
					D.at(i)=0;
				}
				else if(D.at(i)+D.at(ma)==0){
					D.at(ma)=0;
					D.at(i)=0;
					ma+=-1;
				}
				else if(D.at(i)+D.at(ma)<0){
					D.at(i)+=D.at(ma);
					D.at(ma)=0;
					ma+=-1;
					i+=-1;
				}
			}
			int count=0;
			for(int i=0;i<N;i++){
				// cout<<"E:"<<E.at(i)<<endl;
				// cout<<"D:"<<D.at(i)<<endl;
				if(D.at(i)!=E.at(i)){
					count++;
				}
			}
			
			cout<<count<<endl;
			
		}
	}
	
	
}



Measured memory_bytes: 1792
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val s = sc.nextLine()
    val count = Array(26) { 0 }
    for (i in 0 until n) {
        count[s[i] - 'a']++
    }
    var ans = 1L
    val mod = 1000000007L
    for (i in 0 until 26) {
        ans *= count[i] + 1
        ans %= mod
    }
    println(ans - 1)
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 34072
import scala.io.StdIn._

object Main extends App {


  val n = readInt()

  def solve() = {
    val ansArr = Array.fill(10001)(0)
    val lim = 100
    for {
      x <- 1 to lim
      y <- 1 to lim
      z <- 1 to lim
    } yield {
      val v = x*x + y*y + z*z + x*y + y*z + z*x
      if(v < 10001) ansArr(v) += 1
    }
    (1 to n).map { i =>
      ansArr(i)
    }.mkString("\n")
  }

  println(solve())

}



Measured memory_bytes: 58928
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int h = sc.nextInt();
		int w = sc.nextInt();
		char[][] map = new char[h][w];
		for (int i = 0; i < h; i++) {
			map[i] = sc.next().toCharArray();
		}
		boolean[][] memo = new boolean[h][w];
		ArrayDeque<Pos> deque = new ArrayDeque<>();
		long ans = 0;
		long bcnt, wcnt;
		int[] dh = { 1, -1, 0, 0 };
		int[] dw = { 0, 0, 1, -1 };
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (!memo[i][j]) {
					memo[i][j] = true;
					deque.add(new Pos(i, j));
					bcnt = 0;
					wcnt = 0;
					if (map[i][j] == '.') {
						wcnt++;
					} else {
						bcnt++;
					}
					while (!deque.isEmpty()) {
						Pos pos = deque.poll();
						for (int k = 0; k < 4; k++) {
							int hh = dh[k] + pos.h;
							int ww = dw[k] + pos.w;
							if (hh >= 0 && hh < h && ww >= 0 && ww < w
									&& map[pos.h][pos.w] != map[hh][ww] && !memo[hh][ww]) {
								memo[hh][ww] = true;
								if (map[hh][ww] == '.') {
									wcnt++;
								} else {
									bcnt++;
								}
								deque.add(new Pos(hh, ww));
							}
						}
					}
					ans += wcnt * bcnt;
				}
			}
		}
		System.out.println(ans);
	}
}

class Pos {
	int h;
	int w;

	public Pos(int h, int w) {
		this.h = h;
		this.w = w;
	}
}


Measured memory_bytes: 33836
import sys

s = input()

i = 0
N = len(s)
while i < N:
    if s[i:i+5] == 'dream':
        i += 5
    elif s[i:i+6] == 'eraser':
        i += 6
    elif s[i:i+5] == 'erase':
        i += 5
    elif s[i:i+2] == 'er' and s[i-5:i] == 'dream':
        i += 2
    else:
        print("NO")
        sys.exit()
print("YES")


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct aaa{
	ll x,y,z,id;
}a[200010];
ll n,n1,n2,n3,ans,xlh,f[200010],g[200010],mlby;
priority_queue<ll>q;
bool cmp(aaa a,aaa b){
	return a.y-a.z>b.y-b.z;
}
int main(){
	ll i;
	scanf("%lld%lld%lld",&n1,&n2,&n3);
	n=n1+n2+n3;
	for(i=1;i<=n;i++){
		a[i].id=i;
		scanf("%lld%lld%lld",&a[i].x,&a[i].y,&a[i].z);
		xlh+=a[i].x;a[i].y-=a[i].x;a[i].z-=a[i].x;
	}
	sort(a+1,a+n+1,cmp);
	ans=0;
	//for(i=1;i<=n;i++)printf("%lld %lld %lld\n",a[i].id,a[i].y,a[i].z);puts("");
	for(i=1;i<=n;i++){
		q.push(-a[i].y);ans+=a[i].y;
		if(i>n2){
			//printf("%lld\n",q.top());
			ans+=q.top();q.pop();
		}
		f[i]=ans;
	}
	while(!q.empty())q.pop();
	ans=0;mlby=-1e18;
	for(i=n;i;i--){
		q.push(-a[i].z);ans+=a[i].z;
		if(n-i+1>n3){
			ans+=q.top();q.pop();
		}
		g[i]=ans;
		if(i-1>=n2&&n-i+1>=n3)mlby=max(mlby,f[i-1]+g[i]);
	}
	printf("%lld",mlby+xlh);
}
/*
选银牌的是从大到小的一段 
*/

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

int gcd(int a, int b) {
  return b ? gcd(b, a % b) : a;
}

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

  LL sum = 0;
  for (int i = 1; i <= x; i ++) {
    for (int j = 1; j <= x; j ++) {
      for (int k = 1; k <= x; k ++) {
        sum += gcd(i, gcd(j, k));
      }
    }
  }

  cout << sum << endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
using tii = tuple<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
//#define INF (ll)1E9
#define INF INT_MAX
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 };

//constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

int main() {
	int a, b;
	cin >> a >> b;
	if (a + b == 15)cout << '+' << endl;
	else if (a*b == 15)cout << '*' << endl;
	else cout << 'x' << endl;
}

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

    from collections import Counter

    n = int(readline())
    a = list(map(int, readline().split()))
    ans = sum(a)
    counter = Counter(a)
    q = int(readline())
    for _ in range(q):
        b, c = map(int, readline().split())
        ans += (c - b) * counter[b]
        counter[c] += counter[b]
        counter[b] = 0
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24536
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf


a,b,h,m = imap()
h += m/60
r1 = 2*PI * (h/12)
r2 = 2*PI * (m/60)
z1 = cma.rect(a, r1)
z2 = cma.rect(b, r2)
ans = abs(z1 - z2)
print(ans)


Measured memory_bytes: 37672
#include <cstdio>
using namespace std;

int main() {
	int n;
	int temp, min=1000000000, p_max=-1000000000;
	scanf("%d",&n);
	scanf("%d",&min);
	for(int i=1; i<n; ++i) {
		scanf("%d",&temp);
		if(temp-min>p_max) p_max=temp-min;
		if(min>temp) min=temp;
	}
	printf("%d\n",p_max);
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll X[101010],Y[101010];
ll C=(1LL<<59)-1;

int hoge(ll N,ll K) {
	if(K<0 || K>N) return 0;
	return ((~N)&K)==0;
}


ll black(ll BY) {
	int b=0;
	int i;
	FOR(i,N) b^=hoge(C-X[i]-Y[i],BY-Y[i]);
	return b;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>X[i]>>Y[i];
	ll cur=0;
	for(i=59;i>=0;i--) if(black(cur+(1LL<<i))) cur+=1LL<<i;
	cout<<C-cur<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n;
  cin>>n;
  cout<<2*n/__gcd(2LL,n)<<endl;


}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int a, b;
	int i, c = 0;
	
	while(scanf("%d %d", &a, &b) != EOF){
		if(a == 0 && b == 0) break;

		if(c > 0){
			putchar('\n');
			c = 0;
		}
		for(i = a; i <= b; i++){
			if(i % 4 == 0 && i %100 != 0){
				printf("%d\n", i);
				c++;
			}else if(i % 400 == 0){
				printf("%d\n", i);
				c++;
			}
		}
		if(c == 0) printf("NA\n");
		c++;
	}
	
	return 0;
}

Measured memory_bytes: 616
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#include<set>
#include<map>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const LL mod = 1e9 + 7;
const int N = 5e5 + 3;
LL a[N];
LL ans;
LL sum[N];
LL q[N];
inline LL read(){
	LL v = 0,c = 1;char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-') c = -1;
		ch = getchar();
	}
	while(isdigit(ch)){
		v = v * 10 + ch - 48;
		ch = getchar();
	}
	return v * c;
}
inline LL quick(LL x,LL y){
	LL res = 1;
	while(y){
		if(y & 1) res = res * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int main(){
	int n = read();
	q[0] = 1;
	for(int i = 1;i <= 60;++i) q[i] = q[i - 1] *2 % mod;
	for(int i = 1;i <= n;++i){

		a[i] = read();
		for(int j = 0;j < 60;++j)
			if(a[i] & (1ll << j)) sum[j]++;
	}
	LL ans = 0;
	for(int i = 1;i <= n;++i){
		for(int j = 0;j < 60;++j){
			if(a[i] & (1ll << j)) ans += 1ll * (n - sum[j]) * q[j] % mod;
			else ans += 1ll * sum[j] * q[j] % mod;
			if(ans >= mod) ans -= mod;
		}
	}
	printf("%lld\n",ans * quick(2,mod - 2) % mod);
	return 0;
}


Measured memory_bytes: 6400
//RGB Triplets

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / __gcd(a, b) * b
#define range(a) (a).begin(),(a).end()
const int inf = 2147483647;

int main (){
    ll N; cin >> N;
    string S; cin >> S;
    ll a=0,b=0,c=0;
    for(int i=0;i<N;i++){
        if(S[i]=='R')a++;
        else if(S[i]=='G')b++;
        else c++;
    }
    ll Ans = a * b * c;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if (S[i] == S[j]) continue;
            if (j*2-i >= N || S[j*2-i] == S[i] || S[j*2-i] == S[j]) continue;
            Ans--;
        }
    }
    cout << Ans << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <memory.h>
#include <math.h>

#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) > (b)) ? (b) : (a))
#define SWAP(t, a, b) do{t c = a; a = b; b = c;}while(0)

int main (int argc, char **argv)
{
  int64_t n = 0;
  int64_t *h= NULL;
  int64_t i = 0;

  scanf("%lld", &n);

  h = (int64_t *)malloc(n * sizeof(int64_t));

  for(i = 0; i < n; i++)
  {
    scanf("%lld", &h[i]);
  }

  for(i = (n - 1); i > 0; i--)
  {
    if(h[i] < (h[i - 1] - 1))
    {
      printf("No\n");
      free(h);
      return 0;
    }
    else if(h[i] == (h[i - 1] - 1))
    {
      h[i - 1]--;
    }
  }

  printf("Yes\n");

  return 0;
}


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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    H,W,N=MI()
    B=set([])
    from collections import defaultdict
    used = defaultdict(int)
    ans=[0]*10
    
    for _ in range(N):
        a,b=MI()
        a-=1
        b-=1
        B.add((a,b))
        
    def cnt(i,j):#i,jが左上の9ます
        if i+2<H and j+2<W:
            temp=0
            for di in range(3):
                for dj in range(3):
                    ii=i+di
                    jj=j+dj
                    if (ii,jj) in B:
                        temp+=1
            used[(i,j)]=1
            return temp
        return -1
    
    def se(i,j):#i,jが中心の25ます
        for di in range(-2,1,1):
            for dj in range(-2,1,1):
                ii=i+di
                jj=j+dj
                if ii>=0 and jj>=0:
                    if not used[(ii,jj)]:
                        cc=cnt(ii,jj)
                        if cc!=-1:
                            #print(ii,jj,cc)
                            ans[cnt(ii,jj)]+=1
                        
    for k in B:
        i,j=k[0],k[1]
        se(i,j)
        
    S=sum(ans)
    ans[0]=(H-2)*(W-2) - S
    for i in range(10):
        print(ans[i])
                    

main()


Measured memory_bytes: 148980
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(){
    int n; cin >> n;
    map<string, ll> mp;
    rep(i,n){
        string s;
        cin >> s;
        sort(ALL(s));
        mp[s]++;
    }
    ll ans = 0;
    for(auto p : mp){
        int s = p.second;
        ans += (ll)s*(s-1)/2;
    }
    cout << ans << endl;
}

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

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

	cin >> a >> b >> c;

	for (int i = a; i <= b; i++) {
		if (c%i == 0) {
			d++;


		}
		
	}
	cout << d << endl;


    return 0;
}




Measured memory_bytes: 3136
#include<stdio.h>

int main(){
  long long int a,b,c,k;

  scanf("%lld %lld %lld",&a,&b,&k);
 
  if(k>0){
      if(a>=k){
	a-=k;
	b=b;
      }
      else if((a<k)&&(b>=k-a)){
	c=k-a;
	a=0;
	b-=c;
      }
      else if((a<k)&&(b<k-a)){
	a=0;
	b=0;
      }
    }
  printf("%lld %lld\n",a,b);

  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
	int s[3];
	int i,j;
	int a,b,k;
	
	scanf("%d %d %d", &a, &b, &k);
	
	for(i=a; i<a+k; i++){
		if(i>b){break;}
		printf("%d\n", i);
	}
	for(j=b-k+1; j<=b; j++){
		if(j<i){continue;}
		printf("%d\n", j);
	}
	
	return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;

class Progaram
{
    static void Main(String[] args)
    {
        var n = Int32.Parse(Console.ReadLine());
        var l = Console.ReadLine().Split(' ');
        var s = l[0].ToCharArray();
        var t = l[1].ToCharArray();
        var res = String.Empty;

        for (var i = 0; n > i; i++)
        {
            res += new String(new Char[2] { s[i], t[i] });
        }
        Console.WriteLine(res);
    }
}

Measured memory_bytes: 11092
N,M = map(int,input().split())
A = list(map(int,input().split()))
Ans = 0
soutoku = sum(A)
for i in range(N):
    if A[i] >= soutoku/(4*M):
        Ans += 1

if Ans >= M:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include<stdio.h>
int main(void) {
	int x, y, z,i,ans = 0;
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	scanf("%d%d%d", &x, &y,&z);
	for(i = 0;i <= y -x;i++){
		if (z % (x + i) == 0) {
			ans++;
		}
	}
	printf("%d\n", ans);
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	return 0;
}


Measured memory_bytes: 2104
#include <cstdio>
#include <cstdlib>
#include <vector>

int main() {
  int n;
  scanf("%d", &n);
  std::vector <std::pair <int, int> > a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &a[i].first, &a[i].second);
  }
  int imin1 = 0, imax1 = 0, imin2 = 0, imax2 = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i].first + a[i].second > a[imax1].first + a[imax1].second) {
      imax1 = i;
    }
    if (a[i].first + a[i].second < a[imin1].first + a[imin1].second) {
      imin1 = i;
    }
    if (a[i].first - a[i].second > a[imax2].first - a[imax2].second) {
      imax2 = i;
    }
    if (a[i].first - a[i].second < a[imin2].first - a[imin2].second) {
      imin2 = i;
    }
  }
  int d1 = abs(a[imin1].first - a[imax1].first) + abs(a[imin1].second - a[imax1].second);
  int d2 = abs(a[imin2].first - a[imax2].first) + abs(a[imin2].second - a[imax2].second);
  int res = std::max(d1, d2);
  printf("%d\n", res);
  return 0;
}


Measured memory_bytes: 4360
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int dp[500][500] = {{}};

    dp[0][0] = 1;

    int n,ma,mb;
    int a[50],b[50],c[50];

    Scd3(n,ma,mb);
    Rep(i,n){
        Scd3(a[i],b[i],c[i]);
    }

    Rep(i,n){
        for(int ai = 403; ai >= 0; ai--){
            for(int bi = 403; bi >= 0; bi--){
                if( dp[ai][bi] ){
                    dp[ai+a[i]][bi+b[i]] = dp[ai+a[i]][bi+b[i]] ? min(dp[ai+a[i]][bi+b[i]] , dp[ai][bi] + c[i] ) : dp[ai][bi] + c[i];
                }
            }
        }
    }

    int ans = INF;

    for (int i = 1; i <= 400; i++){
        if( i*ma > 400 || i*mb > 400 ) break;
        if( dp[i*ma][i*mb] ){
            ans = min( ans, dp[i*ma][i*mb] );
        }
    }

    if( ans == INF ) ans = 0;


    printf("%d\n", ans-1);

    return 0;
}



Measured memory_bytes: 1280