akhauriyash/Code-Regression huggingface dataset:
# セグメント木を用いた解法

from fractions import gcd
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


class SegmentTree:
    # セグ木は 1-indexed
    def __init__(self, n, initial=0):
        """
        n: 配列の大きさ
        initial: 単位元 (RMQでは大きな値)
        """
        self.offset = 2**(n-1).bit_length()  # 2進数表記の長さ
        self.initial = initial
        self.seg = [self.initial] * (2 * self.offset)
        

    def build(self, A):
        """
        A: 処理したい配列
        """
        for i, a in enumerate(A, start=self.offset):
            self.seg[i] = a
        for i in range(self.offset-1,0,-1):
            self.seg[i] = gcd(self.seg[i<<1] ,self.seg[(i<<1)+1])

            
    def update(self, k, a):
        """
        k番目の値をaに変更
        """
        k += self.offset
        self.seg[k] = a
        while k:
            k >>= 1
            self.seg[k] = gcd(self.seg[k<<1], self.seg[(k<<1)+1])

            
    def query(self, a, b):
        """
        区間[a, b)に対して最小公倍数を求める
        """
        a += self.offset
        b += self.offset - 1 
        res = self.initial
        while a < b:
            if a & 1:  # 兄弟の右なら
                res = gcd(res, self.seg[a])
                a += 1
            if not b & 1:  # 兄弟の左なら
                res = gcd(res, self.seg[b])
                b -= 1
            a >>= 1
            b >>= 1
        
        if a == b:
            res = gcd(res, self.seg[a])
        
        return res


if __name__ == "__main__":
    N = int(readline())
    A = [int(i) for i in readline().split()]
    seg = SegmentTree(N)
    seg.build(A)

    ans = seg.query(1, N)
    for i in range(N-2):
        tmp = gcd(seg.query(0, i+1), seg.query(i+2, N))
        ans = max(ans, tmp)
    ans = max(ans, seg.query(0, N-1))

    print(ans)

Measured memory_bytes: 16172
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
int A[110];

void solve() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];

	int prev = -1;
	int cnt = 1;
	int res = 0;
	rep(i, 0, N) {
		if(prev != A[i]) {
			res += cnt / 2;
			cnt = 1;
			prev = A[i];
		}
		else cnt++;
	}
	res += cnt / 2;
	cout << res << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k=int(input())
print(l[k-1])


Measured memory_bytes: 2940
void main() {
	auto ip = readAs!(long[]), H = ip[0], W = ip[1];
	
	if(H % 3 == 0 || W % 3 == 0) {
		writeln(0);
		return;
	}
	
	ulong res = ulong.max;
	if(H >= 3) res = min(res, H);
	if(W >= 3) res = min(res, W);
	foreach(h; 1..H) {
		ulong S1 = h*W, S2 = (H-h)*(W/2), S3 = (H-h)*((W+1)/2);
		res = min(res, max(S1,S2,S3) - min(S1,S2,S3));
		//writefln("%d %d %d", S1, S2, S3);
	}
	
	foreach(w; 1..W) {
		ulong S1 = w*H, S2 = (W-w)*(H/2), S3 = (W-w)*((H+1)/2);
		res = min(res, max(S1,S2,S3) - min(S1,S2,S3));
		//writefln("%d %d %d", S1, S2, S3);
	}
	res.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


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 rfor(i,a,b) for(ll (i) = (a); (i) > (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(a) cout << (a) << endl;
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll 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;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

int main()
{
    string s;
    ll cnt = 0;
    cin >> s;
    rep0(i, s.size() / 2)if(s[i] != s[s.size() - i - 1])++cnt;
    pf(cnt)
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t i64;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  long long r = 0;
  long long g = 0;
  long long b = 0;

  for (char c : S) {
    if (c == 'R') r++;
    if (c == 'G') g++;
    if (c == 'B') b++;
  }

  long long neg = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int k = j * 2 - i;
      if (k >= N) {
        continue;
      }
      if (S.at(i) != S.at(j) && S.at(j) != S.at(k) && S.at(i) != S.at(k)) {
        neg++;
      }
    }
  }

  cout << (r * g * b) - neg << endl;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k,g[200001][71]; 
signed main()
{
	scanf("%lld %lld",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%lld",&g[i][0]);
	for(int l=1;l<=70;l++)
		for(int i=1;i<=n;i++)
			g[i][l]=g[g[i][l-1]][l-1];
	int now=1,cnt=0;
	while(k)
	{
		if(k&1)
			now=g[now][cnt];
		cnt++;
		k/=2;
	}
	cout<<now;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

string s;
ll mem;
ll ans;

int main(){
  cin >> s;
  for(ll i = 0;i < s.size();){
    if(s[i] == 'A'){
      mem++;
      i++;
      continue;
    }else if(s[i] == 'B'){
      if(s[i+1] == 'C'){
        ans += mem;
        i += 2;
        continue;
      }else{
        mem = 0;
        i++;
        continue;
      }
    }else if(s[i] == 'C'){
      mem = 0;
      i++;
      continue;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define pb push_back
const int MAXN = 1e6+7;
set<int> S;
int main(){
    fastio;
    int val,k; cin>>val>>k;
    while(k--){
        int d; cin>>d;
        S.insert(d);
    }
    for(int i=val; i<=MAXN; i++){//se ela pagar i ?
        int j = i;
        bool ok = true;
        while(j>0){
            int di = j%10;
            if(S.find(di) != S.end())ok=false;
            j = j/10;
        }
        if(ok){cout<<i<<endl; return 0;}
    }
}

Measured memory_bytes: 256
object Main {
  var mul_limit = 12000
  var depth_limit = 7
  def dfs(p: Int, q: Int, depth: Int, sub: Int, mul: Int): Int = {
    p match {
      case 0 => 1
      case _ =>
        var ret = 0
        for{
          i <- (sub to mul_limit / mul).takeWhile(x =>
            (depth_limit - depth) * q >= p * x)
          if p * i >= q
        } ret += dfs(p * i - q, q * i, depth + 1, i, mul * i)
        ret
    }
  }
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    var p, q = sc.nextInt
    mul_limit = sc.nextInt
    depth_limit = sc.nextInt
    while(p != 0) {
      println(dfs(p, q, 0, 1, 1))
      p = sc.nextInt
      q = sc.nextInt
      mul_limit = sc.nextInt
      depth_limit = sc.nextInt
    }
  }
}

Measured memory_bytes: 273600
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>

using namespace std;
using ll = long long;
const ll INF = 1e9;

int N;
string P;
vector<char> T(100001);

char inv(char s) {
    return s == 'S' ? 'W' : 'S';
}

bool execute(char one, char two) {
    bool succ;
    T[0] = one;
    T[1] = two;

    for (int i = 1; i < N - 1; i++) {
        if (T[i] == 'S') {
            if (P[i] == 'o') {
                T[i+1] = T[i-1];
            } else {
                T[i+1] = inv(T[i-1]);
            }
        } else {
            if (P[i] == 'o') {
                T[i+1] = inv(T[i-1]);
            } else {
                T[i+1] = T[i-1];
            }
        }
    }
    if (T[0] == 'S') {
        if (P[0] == 'o' && T[N-1] != T[1]) return false;
        if (P[0] == 'x' && T[N-1] == T[1]) return false;
    } else {
        if (P[0] == 'x' && T[N-1] != T[1]) return false;
        if (P[0] == 'o' && T[N-1] == T[1]) return false;
    }
    if (T[N-1] == 'S') {
        if (P[N-1] == 'o') {
            succ = T[N-2] == T[0];
        } else {
            succ = T[N-2] != T[0];
        }
    } else {
        if (P[N-1] == 'o') {
            succ = T[N-2] != T[0];
        } else {
            succ = T[N-2] == T[0];
        }
    }

    return succ;
}

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

    if (execute('S', 'S') || execute('S', 'W') || execute('W', 'S') || execute('W', 'W')) {
        for(int i = 0; i < N; i++) cout << T[i];
        cout << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}

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

int main() {
  int N,X;
  cin >> N >> X;
  int L[N];
  for (int i = 0; i < N; i++)
  {
    cin >> L[i];
  }
  int count = 1;
  int add = 0;
  while(add <= X && count <= N){
    add += L[count-1];
    if(add<=X) count++;
  }
  cout << count << endl;
}

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

#define      ll     long long int

const int N = 200005;
int ara[N];
map<int, int> mp;
map<int, int>::iterator it;
vector< int > v;

int main()
{
    int n, k, i, j, l;
    pair<int, int> p;
    cin >> n >> k;
    for (i = 0; i < n; i++) {
        cin >> ara[i];
        mp[ara[i]]++;
    }
    l = (int) mp.size();
    if (l <= k) {
        cout << "0\n";
    }
    else {
        for (it = mp.begin(); it != mp.end(); it++) {
            v.push_back((*it).second);
        }
        int s = 0;
        sort(v.begin(), v.end());
        for (i = 0; i < (l - k); i++) {
            s += v[i];
        }
        cout << s << '\n';
    }
    return 0;
}

Measured memory_bytes: 11516
/* Bismillahir Rahmanir Rahim */
#include<bits/stdc++.h>
#include<vector>
#include<cmath>
#include<string>
#include<stdlib.h>
#define   mod          1000000007
#define   lp(i,a,b)    for(ll i=a;i<=b;i++)
#define   ll           long long int
#define   ull          unsigned long long int
#define   tst          int t;cin>>t;while(t--)
#define   pb           push_back
#define   vi(v)        vector<int>v;
#define   vl(v)        vector<ll>v;
#define   vs           vector<string>v
#define   rslt(x)      cout<<x<<endl;
#define   mp(x,y)      make_pair(x,y)
#define   yes          rslt("YES");
#define   no           cout<<"NO"<<endl;
#define   srt(v)       sort(v.begin(),v.end())
#define   rvs(v)       reverse(v.begin(),v.end());
#define   AR           ios::sync_with_stdio(false);cin.tie(0);
#define   gcd(a,b)     __gcd(a,b)
#define   lcm(a,b)     (a/gcd(a,b))*b
#define   max          1000007
#define   str          int s[200000];
#define   coutv(v)     for(auto it:v)cout<<it<<' ';cout<<endl;
#define   cinv(v)      for(auto &it:v)cin>>it;
using namespace std;
int main()
{
    ll r;
    cin>>r;
    cout<<3.14159265358979323846264338327950*r*2<<endl;







    return 0;

}



Measured memory_bytes: 3780
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  unordered_map<string, int> ss;
  F0R(i, N) {
    string s;
    cin >> s;
    ss[s]++;
  }

  vector<string> rs = { "AC", "WA", "TLE", "RE" };
  for (auto s : rs) {
    cout << s << " x " << ss[s] << newl;
  }
}
#endif


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n; cin>>n;
  	string s; cin>>s;
  int c=0;
  for(int i=0;i<n;++i) {
  	if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') ++c;
  }
  cout<<c;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void AGC016A();

#if 1
int main()
{
	AGC016A();
	fflush(stdout);
	return 0;
}
#endif

static void AGC016A()
{
	std::string orgs;
	std::cin >> orgs;

	int len = orgs.length();

	std::set<char> chset;
	for (int i = 0; i < len; i++) {
		chset.insert(orgs[i]);
	}

	int maxChar = len;
	for (auto it = chset.begin(); it != chset.end(); it++) {
		int tmp = 0;
		int maxOtherChars = 0;
		for (int i = 0; i < len; i++) {
			if (orgs[i] != *it) {
				tmp++;
			}
			else {
				tmp = 0;
			}
			maxOtherChars = std::max(maxOtherChars, tmp);
		}
		maxChar = std::min(maxChar, maxOtherChars);
	}
	printf("%d\n", std::min(maxChar, len / 2));
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n,m,X,Y;
    cin >> n >> m >> X >> Y;
    vector<int> x(n),y(m);
    REP(i,n)cin >> x[i];
    REP(i,m)cin >> y[i];
    x.push_back(X);
    y.push_back(Y);
    sort(ALL(x));
    sort(ALL(y));
    
    if(x[n] < y[0])cout << "No War" << endl;
    else cout << "War" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define iREP(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;


int main(){

    ll N,K; cin>>N>>K;
    
    ll ans=K;
    REP(i,N-1){
        ans*=(K-1);
    }
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
//const int maxn = 1000 + 10;

int n, a[maxn];
map<int,int> mp;

inline int check(int k) {
  mp.clear();
	for(int i = 2;i <= n;i ++) {
	  if(a[i - 1] >= a[i]) {
		  while(!mp.empty()) {
			  int x = (mp.rbegin())->first;
				if(x > a[i]) mp.erase(mp.find(x));
				else break;
			}
			int j;
			for(j = a[i];j >= 1;j --) {
			  mp[j] ++;
				if(mp[j] == k) mp[j] = 0;
				else break;
			}
			if(!j) return 0;
		}
	}
	return 1;
}

int main() {
  scanf("%d", &n);
	for(int i = 1;i <= n;i ++) scanf("%d", &a[i]);
	int flag = 0;
	for(int i = 2;i <= n;i ++) if(a[i] <= a[i - 1]) flag = 1;
	if(!flag) {
	  puts("1");
		return 0;
	}
	int L = 2, R = n << 1, ans = n << 1;
	while(L <= R) {
	  int mid = (L + R) >> 1;
		if(check(mid)) R = mid - 1, ans = mid;
		else L = mid + 1;
	}
	printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

	int N;
	cin >> N;
	int res = 0;
	REP(i, N) {
		int l, r;
		cin >> l >> r;
		res += r - l + 1;
	}
	cout << res << "\n";

	return 0;
}

Measured memory_bytes: 256
defmodule Main do
  def main do
    [a, b] =
      IO.read(:line)
      |> String.trim
      |> String.split(" ")
    a = String.to_integer(a)
    b = String.to_integer(b)
    IO.puts(Float.round((a + b) / 2) |> floor)
  end
end


Measured memory_bytes: 30776
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

a, b, c, d = wi()

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm_base(x, y):
    return (x * y) // gcd(x, y)
#532105071133627368

s = ((a + c - 1) // c) * c
t = (b // c) * c
kosu1 = (t - s) // c + 1

u = ((a + d - 1) // d) * d
v = (b // d) * d
kosu2 = (v - u) // d + 1

e = lcm_base(c, d)
w = ((a + e - 1) // e) * e
x = (b // e) * e
kosu3 = (x - w) // e + 1

print(b - a + 1 - (kosu1 + kosu2 - kosu3))

Measured memory_bytes: 6480
fn main() {
    let s = read::<String>();

    let mut cnt = 0;
    for c in s.chars() {
        if c == '1' {
            cnt += 1;
        }
    }

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

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

Measured memory_bytes: 4352
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define SZ(x) ((int)(x).size())
typedef long long ll;
using namespace std;

//main
int main(){
  int N,L;
  int gap;
  int a;
  cin >> N >> L;
  vector<int> ans(N);
  int sum = (L-1)*N + N*(N+1)/2;
  rep(i,N){
    gap = L+i;
    if(gap >= 0) a = 1;
    else a = -1;
    ans[i] = abs(gap);
  }
  cout << sum-a*(*min_element(ALL(ans))) << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(ll, N, H);
  vl a(N), b(N);
  rep(i, 0, N) {
    in(a[i], b[i]);
  }

  sort(all(b), greater<>());
  ll maxa = *max_element(all(a));

  ll i = 0;
  while (i < N && b[i] > maxa && H > 0) {
    H -= b[i];
    i++;
  }
  print(i + (ll)ceil((long double)max(H, 0ll) / maxa));
}


Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#define P pair<long long, long long>


using namespace std;
const long long int MOD=1e9+7;

int main(){
  int n, x[109];
  cin >> n;
  for(int i=0;i<n;i++)cin >> x[i];
  int sm=0, mn=10000000;
  for(int i=0;i<n;i++){
    sm += x[i];
  }
  int p=sm/n;
  int var1=0, var2=0;
  for(int i=0;i<n;i++){
    var1 += (p-x[i])*(p-x[i]);
    var2 += (p+1-x[i])*(p+1-x[i]);
  }
  cout << min(var1, var2) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;
typedef long long ll;

typedef pair<int, int> P;

bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.second > secondElof.second;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> A(2 * n);
    for (int i = n; i < 2*n; i++) {
        cin >> A[i];
    }
    vector<P> BC(m);
    for (int i = 0; i < m; i++) {
        cin >> BC[i].first;
        cin >> BC[i].second;
    }

    sort(BC.begin(), BC.end(), pairCompare);
    
    int i = 0;
    bool comp = false;
    for (int j = 0; j < m; j++){
        for (int k = 0; k < BC[j].first; k++) {
            A[i] = BC[j].second;
            i++;
            if (i == n) {
                comp = true;
                break;
            }
        }
        if (comp) break;
    }

    for (int a = i; i < n; i++) A[i] = 0;
    sort(A.begin(), A.end());

    ll sum = 0;
    for (int i = n; i < 2*n; i++) sum += A[i];
    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    char a,b;
    cin >> a >> b;

    if(a=='H'){
        if(b=='H'){
            cout << 'H' << endl;
        }else{
            cout << 'D' << endl;
        }
    }else{
        if(b=='H'){
            cout << 'D' << endl;
        }else{
            cout << 'H' << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define forne(i, a, b) for(int i=a; i<=(int)(b); i++)

#define gottagofast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n";
using namespace std;

#define MAX (int)(1e5+10)

int n;
int tabela[MAX][4];
int v[MAX][4];

int dp(int idx, int usado) {
    if(idx >= n) {
        return 0;
    }
    if(tabela[idx][usado] != -1) {
        return tabela[idx][usado];
    }

    int val = 0;
    for(int i = 0; i <= 2; i++) {
        if(i != usado) {
            val = max(val, v[idx][i] + dp(idx+1, i));
        }
    }

    // cout << "idx = " << idx << " val = " << val;
    return tabela[idx][usado] = val;
}

int main() {
    cin >> n;

    memset(tabela, -1, sizeof(tabela));

    for(int i = 0; i < n; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        v[i][0] = a;
        v[i][1] = b;
        v[i][2] = c;
    }

    cout << dp(0, 3) << endl;;

    return 0;
}


Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;

int main(){
    int a, b, small, big;
    cin >> a >> b;
    small = min(a, b);
    big = max(a, b);
    REP(i, big){
        cout << small;
    }
    return 0;
}


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

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

    int F[n];
    F[0] = F[1] = 1;
    for (int i = 2; i <= n; i++) F[i] = F[i - 2] + F[i - 1];

    cout << F[n] << endl;

    return 0;
}



Measured memory_bytes: 3088
from collections import Counter
# from scipy.special import comb
from scipy.misc import comb
n = int(input())
a = [int(x) for x in input().split()]
aa = Counter(a)
cnt = []
for i in range(1, n + 1):
    cnt.append(comb(aa[i], 2, exact=True))
s = sum(cnt)
for i in range(n):
    print(s - comb(aa[a[i]], 2, exact=True) + comb(aa[a[i]] - 1, 2, exact=True))

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

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

  int ans = 0;

  rep(i,10000){
    a -= b;
    ans ++;
    if (a <= 0) break;
  }
  cout << ans << endl;
}

  

Measured memory_bytes: 256
def uf_init(n):
    return list(range(n))

def uf_root(uf, x):
    update_node_arr = []
    while(uf[x] != x):
        update_node_arr.append(x)
        x = uf[x]
    for y in update_node_arr:
        uf[y] = x
    return x

def uf_same(uf, x, y):
    return uf_root(uf, x) == uf_root(uf, y)

def uf_unite(uf, x, y):
    x = uf_root(uf, x)
    y = uf_root(uf, y)
    if x == y:
        return
    uf[x] = y

N,M = (int(x) for x in input().split())

uf = uf_init(N)

for _ in range(M):
    X,Y,Z = (int(x) for x in input().split())
    uf_unite(uf, X-1, Y-1)

uf_roots = set()
for i in range(N):
    uf_roots.add(uf_root(uf, i))

print(len(uf_roots))



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

#define rep(i,n) for(int i=0;i<(n);++i)
#define int long long
#define pb push_back
#define m_p make_pair
#define m_t meke_tuple
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define debg(a) cout<<#a<<" "<<a<<endl;
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define out(a) cout<<(a)<<endl
typedef long long ll;
typedef string str;
typedef vector<int> V;
typedef pair<int,int> P;
typedef vector<P> VP;
const int INF = 1LL<<60;
const int MOD = 1e9+7;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int n,q;
str s;
vector<char> t,d;

bool simulate(int idx){
  rep(i,q){
    if(t[i]==s[idx]){
      //debg(t[i]);debg(s[idx]);
      if(d[i]=='L'){
        idx--;
      }
      else idx++;
    }
    if(idx==0||idx==n+1)return true;
  }
  return false;
}

signed main(){
  cin>>n>>q>>s;
  s=" "+s;
  rep(i,q){
    char T,D;
    cin>>T>>D;
    t.pb(T);
    d.pb(D);
  }

  int left=0,right=n+1;
  //�E���ɗ����Ȃ����E
  while(right-left!=1){
    int mid=(left+right)/2;
    bool falled;
    falled=simulate(mid);
    //debg(mid);debg(falled);
    if(falled)left=mid;
    else right=mid;
  }
  int L=right;
  //debg(right);debg(left);

  left=0,right=n+1;
  //�����ɗ����Ȃ����E
  while(right-left!=1){
    int mid=(left+right)/2;
    bool falled;
    falled=simulate(mid);
    //debg(mid);debg(falled);
    if(falled)right=mid;
    else left=mid;
  }
  int R=left;

  //debg(right);debg(left);
  //debg(L);debg(R);

  if(L>R)out(0);
  else out(R-L+1);
  
  
  return 0;
}



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

const int INF = 1e9;

int main() {
  int n, k;
  cin>>n>>k;
  char a[n];
  for (int i=0; i<k; i++) cin>>a[i];

  for (int i=n; i<100000; i++) {
    string str_i = to_string(i);
    bool flag = true;
    for (int j=0;j <k; j++) {
      if (str_i.find(a[j]) != string::npos) {
        flag = false;
        break;
      }
    }
    if (flag) {
      cout<<i<<endl;
      break;
    }
  }
}

Measured memory_bytes: 256
fun main(args: Array<String>){
    val haiku : String? = readLine()
    //var hai : List<String> = mutableListOf("1", "1", "1")
    var count5 : Int = 0
    var count7 : Int = 0
    if(haiku != null){
        var hai = haiku.split(" ")
        //println(hai)
        for(i in hai.indices){
            if(hai[i]=="5"){
                count5 = count5 + 1
            }
            else if(hai[i]=="7"){
                count7 = count7 + 1
            }
        }
        val str = if(count5 == 2 && count7 == 1) "YES" else "NO"
        println(str)
    }
}
                                   

Measured memory_bytes: 37868
# D
K = int(input())
A_list = list(map(int, input().split()))

res_min = [2]*(K+1)
res_max = [2]*(K+1)
possible = True
A_list.append(2)

for i in range(K-1, -1, -1):
    # minimum
    if res_min[i+1] % A_list[i] == 0:
        res_min[i] = res_min[i+1]
    else:
        res_min[i] = res_min[i+1] + A_list[i] - res_min[i+1] % A_list[i]
        
    # minimum over
    if (res_min[i] // A_list[i+1]) * A_list[i+1] > res_max[i+1]:
        possible = False
    
    # maximum
    if (res_max[i+1] + A_list[i+1]) % A_list[i] == 0:
        res_max[i] = res_max[i+1] + A_list[i+1] - A_list[i]
    else:
        res_max[i] = ((res_max[i+1] + A_list[i+1]) // A_list[i]) * A_list[i]
        
    # maximum over
    if (res_max[i] // A_list[i+1]) * A_list[i+1] < res_min[i+1]:
        possible = False

        
if A_list[K-1] != 2:
    possible = False
if possible:
    print(res_min[0], res_max[0]+A_list[0]-1)
else:
    print(-1)

Measured memory_bytes: 15044
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		
		double ans = 0;
		for (int i=0; i<N; i++){
			double x = sc.nextDouble();
			String S = sc.next();
			
			if (S.equals("JPY")){
				ans+=x;
			}
			else 
				ans+=x*380000;
			
		}
		System.out.println(ans);

	}

}


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

/*******  All Required define Pre-Processors and typedef Constants *******/
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define Dcout(a) cout << setprecision(20) << a << endl
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using ll = long long;
using PAIR = pair<int, int>;
using Graph = vector<vector<int>>;
//const ll INF = (1LL << 60);
//const double pi=acos(-1.0);
#define debug cout << "line : " << __LINE__ << " debug" << endl
/****** Template of some basic operations *****/
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/**************************************/

/******** User-defined Function *******/




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

/********** Main()  function **********/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n,k; cin >> n >> k;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  sort(all(p));
  int ans = 0;
  rep(i,k){
    ans += p[i];
  }

  cout << ans << endl;
  

  return 0;
}
/********  Main() Ends Here *************/


Measured memory_bytes: 3644
/*input
10 4
40 10 20 70 80 10 20 70 80 60

*/
/*

  ####   #    #    ##    #####    ####           #    #
 #       #    #   #  #   #    #  #    #          #    #
  ####   ######  #    #  #    #  #    #          #    #
      #  #    #  ######  #    #  #    #          # ## #
 #    #  #    #  #    #  #    #  #    #          ##  ##
  ####   #    #  #    #  #####    ####  #######  #    #

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
using namespace std;
#define N  200005
lld dp[N];
lld ht[N];
lld n,k;
void init()
{
	rep(i,0,N)
	{
		dp[i]=-1;
		ht[i]=0;
	}
}
lld func(lld x)
{
	if(x>=n)
	{
		return hell;
	}
	if(x==n-1)
	{
		return 0;
	}
	if(dp[x]!=-1)
	{
		return dp[x];
	}
	lld ans=func(x+1)+abs(ht[x+1]-ht[x]);
	rep(i,2,k+1)
		ans=min(func(x+i)+abs(ht[x+i]-ht[x]),ans);
	dp[x]=ans;
	return dp[x];
}
inline void solve()
{
	cin >> n >> k;
	init();
	rep(i,0,n)
	{
		cin >> ht[i];
	}
	cout << func(0) << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}

Measured memory_bytes: 8064
#include <stdio.h>

int main() {
	int W,H,x,y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if (x + r <= W && x + r >= 0 && x - r >=0)
	{
		if(y + r <= H && y + r >= 0 && y - r >=0)
			printf("Yes\n");
		else
			printf("No\n");
	}
	else
				printf("No\n");
	return 0;
}


Measured memory_bytes: 2148
#include <iostream>

using namespace std;

int main()
{
    int d;
    scanf("%d",&d);
    if(d == 25)
    {
        printf("Christmas\n");
        return 0;
    }
    if(d == 24)
    {
        printf("Christmas Eve\n");
        return 0;
    }
        if(d == 23)
    {
        printf("Christmas Eve Eve\n");
        return 0;
    }
        if(d == 22)
    {
        printf("Christmas Eve Eve Eve\n");
        return 0;
    }

}

Measured memory_bytes: 256
/**
 *   created: 07 December 2019  18:00:06
**/
#include<bits/stdc++.h>
using namespace std;

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

#define int long long
#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int32_t main()
{
	optimizeIO();
	int tt=1;
	//cin>>tt;
	while(tt--){
		int n;
		cin>>n;
		vector<int> v(n);
		rep(i,0,n)
			cin>>v[i];
		vector<int> p(60);
		for(int i=0;i<60;i++)
			p[i] = pow(2,i);
		vector< vector<int> > cnt(2, vector<int>(60, 0));
		for(int i=0;i<n;i++){
			for(int j=0; j<60; j++){
				if((v[i]&(1ll<<j)))
					cnt[1][j]++;
				else
					cnt[0][j]++;
			}
		}
		int ans = 0;
		for(int i=0;i<n;i++){
			for(int j=0; j<60; j++){
				// trace4(cnt[0][j], cnt[1][j], i, j);
				if((v[i]&(1ll<<j))){
					cnt[1][j]--;
					ans = (ans + (p[j]%MOD*cnt[0][j]%MOD)%MOD)%MOD;
				}
				else{
					cnt[0][j]--;
					ans = (ans + (p[j]%MOD*cnt[1][j]%MOD)%MOD)%MOD;
				}
			}
		}
		cout<<ans%MOD;
	}
	return 0;
}


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

using namespace std;

map<int, int> freq;
int n;

int main(){
    scanf("%d", &n);

    bool ans = true;

    for (int i=0;i<n;i++){
        int x;
        scanf("%d", &x);
        if (freq.find(x) == freq.end())
            freq[x] = 1;
        else{
            freq[x]++;
            if (freq[x]>=2)
                ans = false;
        }
    }

    if (ans)
        printf("YES");
    else
        printf("NO");

    printf("\n");

    return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && b == c) {
    cout << 1 << endl;
  }
  else if (a != b && b != c && c != a) {
    cout << 3 << endl;
  }
  else {
    cout << 2 << endl;
  }
}

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

int main(){
	int n,k[100],p[100];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d %d",&k[i],&p[i]);
		printf("%d\n",(k[i]-1)%p[i]+1);
	}
}

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

using namespace std;

int main() {
	int N, odd = 0;
	cin >> N;
	
	if(N % 2 == 0) {
		cout << 0.5 << endl;
	} else {
		for(int i = 1; i <= N; i++) {
			if(i % 2 == 1) odd++;
		}
		cout << (float) odd / N << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	int i,a=2333,b=0;
	char s[233];
	scanf("%s",s);
		for(i=0;i<strlen(s);i++)
		{
			if(s[i]=='C')
			{
				a=i;
				break;
			}
		}
		for(i=a;i<strlen(s);i++)
		{
			if(s[i]=='F')
			b=666;
		}
		if(b==666)
		printf("Yes\n");
		else
		printf("No\n");
		a=2333;
		b=0;
	
	return 0;
}

Measured memory_bytes: 128
N = int(input())
X = list(map(int,input().split()))
saisyou = 10**7
for p in range(1,101):
    tairyoku = 0
    for x in range(N):
        tairyoku += (X[x]-p)**2
    saisyou = min(saisyou, tairyoku)

print(saisyou)


Measured memory_bytes: 9172
#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define int long long
#define inf 1e9
#define mod 1000000007

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

    int sum = 0;

    sum += min(a, k);
    k -= min(a, k);
    if (k > 0)
    {
        k -= b;
    }
    if (k > 0)
    {
        sum -= min(k, c);
    }
    cout << sum;

}

int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 10000000000000000

int main(){
	
	int N;
	cin>>N;
	
	map<string,long long> M;
	
	for(int i=0;i<N;i++){
		string s;
		cin>>s;
		sort(s.begin(),s.end());
		M[s]++;
	}
	
	long long ans = 0;
	
	for(auto a:M){
		ans += a.second*(a.second-1)/2;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long llint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
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};
const double pi = 3.14159265358979323846;

// conversion
inline llint toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  llint ret = v;
  return ret;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//

P conv(llint x) {
  llint f = 0, b;
  b = x % 10;
  while (x) f = x, x /= 10;
  return P(f, b);
}

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

  llint n;
  cin >> n;

  map<P, int> freq;
  for (llint i = 1; i <= n; i++) {
    P p = conv(i);
    freq[p]++;
  }
  llint ans = 0;
  for (llint i = 1; i <= n; i++) {
    P p = conv(i);
    P q(p.second, p.first);
    ans += freq[q];
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
justified=True
S=list(input())
check1=["R","U","D"]
check2=["L","U","D"]
for j in range(len(S)):
    if( j)%2==0:
        if  S[j] in check1:
            continue
        else:
            justified=False
            break
        
    if (j)%2==1:
        if S[j] in check2:
            continue
        else:
            justified=False
            break
if justified:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
def dfs(A):
    global cnt

    if len(A) == n:
        ans = [0 for i in range(m)]
        for i, a in enumerate(A):
            if a:
                for j in range(m):
                    if i+1 in s[j]:
                        ans[j] += 1
        for x, y in zip(p, ans):
            if x != y%2:
                break
        else:
            cnt += 1
        return
    for v in range(2):
        A.append(v)
        dfs(A)
        A.pop()

n, m = map(int, input().split())
s = [list(map(int, input().split()))[1:]  for _ in range(m)]
p = list(map(int, input().split()))
cnt = 0
dfs([])
print(cnt)

Measured memory_bytes: 9164
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;

ll gcd(ll a,ll b) {
    if(a==INF)return b;
    while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
    }
    return a;
}

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N,0);
    for(ll i=0;i<N;i++){
        cin>>A[i]
    ;}
    ll n=sqrt(N);

    //tグループに分割
    ll t=N/n;
    if(N%t)t++;

    vector<ll> gcds(t,0);
    for(ll i=0;i<t;i++){
        ll k=INF;
        for(ll j=i*n;j<n*(i+1)&&j<N;j++){
            k=gcd(k,A[j]);
        ;}
        gcds[i]=k;
    ;}
    ll ans=1;
    for(ll j=0;j<t;j++){
        for(ll i=0;i<n&&j*n+i<N;i++){
            ll d=INF;
            //違うグループ
            for(ll k=0;k<t;k++){
                if(k!=j){
                    d=gcd(d,gcds[k]);
                }
            }
            //同じグループ
            for(ll k=0;k<n&&j*n+k<N;k++){
                if(k!=i)d=gcd(d,A[j*n+k]);
            }
            if(d==INF)continue;
            ans=max(ans,d);
        ;}
    ;}
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <set>
#include <utility>
#include <climits>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>

#define ll long long
#define ull unsigned long long
using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int r;
	cin >> r;
	cout << 3.1415926535 * 2 * r;
}

Measured memory_bytes: 3776