akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  int h, n;
  cin >> h >> n;
  int sum =0;
  rep(i, n) {
    int a;
    cin >> a;
    sum += a;
  }
  if(h<=sum) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#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 SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

using ll = long long;
using namespace std;

int main() {
    ll n;
  	vector<pair<ll, ll> > v;
    cin >> n;
  	
  	ll a, b;
  	REP(i, n) {
      	cin >> a >> b;
      	v.push_back(make_pair(b, a));
    }
  	SORTASC(v);
  
  	ll asum = 0;
  	REP(i, n) {
      	asum += v[i].second;
      	if (asum > v[i].first) {
          	cout << "No" << endl;
          	return 0;
        }
    }
  
  	cout << "Yes" << endl;
  
    return 0;
}

Measured memory_bytes: 6384
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <cassert>

using namespace std;

const int mod = 1000000007;

int a[100500], b[100500];
pair<int, int> p[100500];
int k, n;

long long dfs(int pos, unsigned int mask){
    if (pos == -1)
        return 0;
    if (mask > k)
        return 0;
    if (mask + (1 << pos) - 1 > k)
        return dfs(pos - 1, mask);
    long long res = 0;
    for (int i = 0; i < n; i++)
        if (((unsigned int)p[i].first & (~mask)) < (1 << pos))
            res += p[i].second;
    return max(res, dfs(pos - 1, mask + (1 << pos)));
}

int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int m, w;
    unsigned int k;
    cin >> n >> k;
    for (int i = 0; i < n; i++){
        cin >> p[i].first >> p[i].second;
    }
    int st = 0;
    /*if (k == 0){
        long long res = 0;
        for (int i = 0; i < n; i++)
        if (p[i].first == 0)
            res += p[i].second;
        cout << res;
        return 0;
    }*/
    while (k >= 2ll * (1 << st))
        st++;
    int mask = 0;
    long long ans = 0;
    for (int i = 30; i >= 0; i--)
        if (k & (1 << i)){
            long long res = 0;
            for (int j = 0; j < n; j++)
                if ((p[j].first & (~mask)) < (1 << i))
                    res += p[j].second;
            ans = max(ans, res);
            mask |= (1 << i);
        }
    long long res = 0;
    for (int j = 0; j < n; j++){
        if (((unsigned int)p[j].first & (~k)) == 0)
            res += p[j].second;
    }
    cout << max(ans, res);
    //cout << dfs(st, 0);

    #ifdef LOCAL
    cout.flush();
    _Exit(0); //GLIBCXX_DEBUG not working without it
    #endif // local
    return 0;
}



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

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

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

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Map<String, Long> counts = new HashMap<>();
        for (int i = 0; i < n; ++i) {
            String s = scanner.next();
            char[] tmp = s.toCharArray();
            Arrays.sort(tmp);
            s = new String(tmp);
            long count = counts.getOrDefault(s, 0L);
            counts.put(s, count + 1L);
        }
        long pairs = 0;
        for (long count : counts.values()) {
            pairs += (count * (count - 1L) / 2);
        }
        System.out.println(pairs);
    }
}

Measured memory_bytes: 52736
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)

int main(){
    int n, m;
    cin >> n >> m;
    int a[n];
    float total = 0.0;
    rep(i,n){
        cin >> a[i];
        total += a[i];
    }
    int count = 0;
    rep(i,n){
        if(a[i] * 4 * m >= total){
            count += 1;
        }
    }
    if(count < m){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

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

int main(){
    int N,wron=0,a;
    cin >> N;

    vector<int> P(N+1);

    for(int i = 0;i < N;i++){
        cin >>  a;
        P.at(i) = a -1;
    }

    for(int i = 0;i < N;i++){
        if(i != P.at(i) )
            wron++;
    }


    if(wron == 2 || wron == 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.text.*;
import java.util.zip.Adler32;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        int[] a= sc.nextIntArr(n);
        int[] b = sc.nextIntArr(m);
        long[]pre= new  long[n+1];
        TreeMap<Long,Integer>tm= new TreeMap<>();
        int ans=0;
        tm.put(0l,0);
        for (int i =0;i<n;i++){
            pre[i+1]=a[i];
            pre[i+1]+=pre[i];
            tm.put(pre[i+1],i+1);
        }
        long cur=0;
        ans=tm.get(tm.floorKey(1l*k));
        for (int i =0;i<m;i++){
            cur+=b[i];
            if (cur>k)
                break;
            ans=Math.max(ans,i+1+tm.get(tm.floorKey(k-cur)));
        }
        pw.println(ans);
        pw.flush();
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public int[] nextIntArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}

Measured memory_bytes: 75444
S = str(input())
SL = []
count = 0
for i in range(len(S)):
  SL.append(S[i])
for i in range(1,len(SL)):
  if SL[i] == SL[i-1]:
    if SL[i] == '0':
      SL[i] = '1'
    else:
      SL[i] = '0'
    count += 1
print(count)

Measured memory_bytes: 3956
import java.util.Scanner;
public class Main {

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

        if (N % 2 == 0) {
            System.out.println(N);
        } else {
            System.out.println(N * 2);
        }
    }
}


Measured memory_bytes: 23380
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int main()
{
    LL n,x;
    cin>>n>>x;
    LL t=x;
    LL sum=n;
    x=min(t,n-t);
    LL y=max(t,n-t);
    while(x>=1)
    {
        if(y%x==0)
        {
            sum+=(y/x)*2*x;
            sum-=x;
            break;
        }
        else
        {
            sum+=(y/x)*2*x;
            LL te=x;
            x=y%x;
            y=te;
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int N;
int H[100000];
int main(){
  int i;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<(N);Lj4PdHRW++){
      rd(H[Lj4PdHRW]);
    }
  }
  for(i=N-2;i>=0;i--){
    if(H[i]>H[i+1]){
      H[i]--;
    }
  }
  for(i=(1);i<(N);i++){
    if(H[i-1]>H[i]){
      break;
    }
  }
  if(i==N){
    wt_L("Yes");
    wt_L('\n');
  }
  else{
    wt_L("No");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190802-2

// --- original code ---
// int N, H[1d5];
// {
//   int i;
//   rd(N,H(N));
//   for(i=N-2;i>=0;i--) if(H[i]>H[i+1]) H[i]--;
//   rep(i,1,N) if(H[i-1]>H[i]) break;
//   wt(if[i==N,"Yes","No"]);
// }


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

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

    map<llll,int> M;
    for (int i = 0; i < N; i++) {
        M[make_pair(A[i], B[i])] = 1;
    }

    vector<ll> ans(10);
    vector<vector<int>> tmp(5, vector<int> (5));
    ll a, b;
    int cnt;
    int s, t, u, v;
    ll three = 3;
    for (int i = 0; i < N; i++) {
        a = A[i]; b = B[i];
        for (int j = 0; j < 5; j++) {
            fill(ALL(tmp[j]), 0);
        }
        for (int j = a-2; j < a+3; j++) {
            for (int k = b-2; k < b+3; k++) {
                if(M.count(make_pair(j, k))){
                    tmp[j-a+2][k-b+2] = 1;
                }
            }
        }
        s = max(3-a, zero);
        t = min(H-a+1, three);
        u = max(3-b, zero);
        v = min(W-b+1, three);

        for (int j = s; j < t; j++) {
            for (int k = u; k < v; k++) {
                cnt = 0;
                for (int l = 0; l < 3; l++) {
                    for (int m = 0; m < 3; m++) {
                        cnt += tmp[j+l][k+m];
                    }
                }
                ans[cnt]++;
            }
        }
    }
    for (int i = 1; i < 10; i++) {
        ans[i] = ans[i] / i;
    }
    ll su = 0;
    for (int i = 1; i < 10; i++) {
        su = su + ans[i];
    }
    ans[0] = (H-2) * (W-2) - su;
    for (int i = 0; i < 10; i++) {
        printf("%lld\n", ans[i]);
    }

}

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

typedef long long int ll;
void solved(){
	string s;cin>>s;
	int ans = 0;
	map<int,int>mp;
	int cnt = 0;
	mp[0] = 1;
	int p = 1;
	for(int i = s.size() - 1; i >= 0; i--){
		ans = (ans + ll(s[i] - '0') * p)%2019;
		cnt += mp[ans]++;
		p = p * 10 % 2019;
	}
	cout<<cnt<<endl;
}
int main(){
	solved();
	return 0;
} 

Measured memory_bytes: 3716
#include <stdio.h>
#include <string.h>
int main(void){
    char s[100000+5];
    scanf("%s", s);
    int n=strlen(s);
    
    int ans[100000]={0};
    int i=0;
    while(i<n){
        int r=0, l=0;
        while(s[i]=='R')i++, r++;
        int p=i;
        while(s[i]=='L')i++, l++;
        ans[p-1]=(r+1)/2+l/2;
        ans[p]=r/2+(l+1)/2;
    }
    for(int i=0; i<n; i++)printf("%d ", ans[i]);
    return 0;
}


Measured memory_bytes: 2212
use std::vec::Vec;

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 3);
  (v[0], v[1], v[2])
}

fn main() {
    let (n, a, b) = read_touple::<usize>();
    let mut ans = (n / (a + b)) * a;
    let c = n - ((n / (a + b)) * (a + b));
    if c < a {
      ans += c;
    } else if c >= a {
      ans += a;
    }

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


Measured memory_bytes: 4352
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
word = input()
li = [word]
end = word[-1]
ans = 'Yes'
for i in range(n-1):
    word = input()
    if word[0] != end or word in li:
        ans = 'No'
        break
    end = word[-1]
    li.append(word)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<iostream>
#define N int(2e5+1)
#define LL long long int
using namespace std;
int main()
{
	int n,a,i,remove=0,need=1;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a;
		if(a==need)
			need++;
		else
			remove++;
	}
	cout<<(remove==n?-1:remove)<<endl;
	return 0;
}

Measured memory_bytes: 256
N,A,B = map(int, input().split(" "))
S = list(input())
MAX = A + B
nowall = 0
nowfor = 0

for i in range(len(S)):
    if nowall >= MAX:
        print("No")
    elif S[i] == "a":
        nowall += 1
        print("Yes")
    elif S[i] == "b":
        if nowfor < B:
            nowall += 1
            nowfor += 1
            print("Yes")
        else:
            print("No")
    else:
        print("No")


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

int  main() {
  string S;
  cin >> S;
  string head, tail;
  string S_rev = S;
  reverse(S_rev.begin(), S_rev.end());
  
  head = S.substr(0, (S.size()-1)/2);
  tail = S.substr((S.size()+3)/2 - 1, S.size());
//  cout << head << " " << tail << endl;
  string head_rev = head;
  reverse(head_rev.begin(), head_rev.end());
  string tail_rev = tail;
  reverse(tail_rev.begin(), tail_rev.end());
  
//  cout << head << " " << head_rev << endl;
//  cout << tail << " " << tail_rev << endl;
  
  if (S == S_rev && head == head_rev && tail == tail_rev) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}



Measured memory_bytes: 256
def d_sum_of_large_numbers(MOD=10**9 + 7):
    N, K = [int(i) for i in input().split()]
    return (N + 2 - K) * (N**2 + (K + 1) * N - 2 * K**2 + 2 * K + 6) // 6 % MOD

print(d_sum_of_large_numbers())

Measured memory_bytes: 9172
N, M = gets.split(' ').map(&:to_i)
ary = gets.split(' ').map(&:to_i)

line = ary.reduce(&:+) / (4 * M).to_f

count = 0

ary.each do |a|
  count += 1 unless a < line

  break if count >= M
end

if count >= M
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 1788
#include<cstdio>


int main(void)
{
	int a, b, c, d, e, k;

	while(scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &k)==6)
	{
		int ans=((e-a)<=k);

		printf("%s\n", ans?"Yay!":":(");
	}

	return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;


int main() {
	while (true) {
		int N,A,B;cin>>N>>A>>B;
		if(!N)break;
		vector<int>oks(1e6+1);
		oks[0]=true;
		for (int i = 0; i < 1e6; ++i) {
			if (oks[i]) {
				if (i + A <= 1e6) {
					oks[i+A]=true;
				}
				if (i + B <= 1e6) {
					oks[i+B]=true;
				}
			}
		}
		int ans=N-accumulate(oks.begin(),oks.begin()+N+1,0)+1;
		cout<<ans<<endl;
	}
	return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  LL X, Y;
  cin >> X >> Y;

  LL ans = 0;
  while(X <= Y){
	X *= 2;
	++ans;
  }
  cout << ans << 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 <bits/stdc++.h>
using namespace std;


int main()
{ 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    
    long long int n,k;
    
    cin>>n>>k;
    
    if(n==k)
    cout<<0<<endl;
    else if(n<k)
    {
        cout<<min(abs(n-k),n)<<endl;
    }
    else
    {
        long long int x = n%k;
        
        long long int y = abs(x-k);
        
        if(y>x)
        cout<<x<<endl;
        else
        cout<<y<<endl;
    }
    return 0;
}


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


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

void solve(std::string S) {
  int n = S.size();
  vector<int> ans(n);
  rep(ri, 2) {
    // Rについて解く
    int cnt = 0;
    rep(i, n) {
      if (S[i] == 'R')
        cnt++;
      else {
        ans[i] += cnt / 2;
        ans[i - 1] += (cnt + 1) / 2;
        cnt = 0;
      }
    }
    reverse(ans.begin(), ans.end());
    reverse(S.begin(), S.end());
    rep(i, n) {
      if (S[i] == 'L')
        S[i] = 'R';
      else
        S[i] = 'L';
    }
  }
  rep(i, n) { printf("%d%c", ans[i], i == n - 1 ? '\n' : ' '); }
}

int main() {
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


//dp[i] iダメージ与えられるのに最小の魔法力
lli dp[50010];

void func(long long H, long long N, std::vector<long long> A, std::vector<long long> B){

    REP(i,0,50010)dp[i]=INF;
    dp[0]=0;

    REP(i,0,N){
        for(lli j=0;j<=H;j++){
            chmin(dp[j+A[i]],dp[j]+B[i]);
        }
    }

    lli ans = INF;
    REP(i,H,30000){
        chmin(ans,dp[i]);
    }
    cout<<ans<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long H;
    scanf("%lld",&H);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    func(H, N, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        int i,j,k,x,n,co=0;
        Scanner s = new Scanner(System.in);
        while(true){
            n = s.nextInt();
            x = s.nextInt();
            if(n==0&&x==0)break;
            for(i=1;i<=n;i++){
                for(j=i+1;j<=n;j++){
                    for(k=j+1;k<=n;k++){
                        if(i+k+j==x)co++;
                    }
                }
            }
            System.out.println(co);
            co =0;
        }
    }
}


Measured memory_bytes: 26900
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

const string YES = "Yes";
const string NO = "No";

void solve(ll A, ll B, ll C) {
  bool pred = (A == B || B == C || C == A) && !(A == B && B == C);
  cout << (pred ? YES : NO) << endl;
}

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  ll C;
  cin >> C;
  solve(A, B, C);
  return 0;
}


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

#define MAX_V 10000

vector<int> G[MAX_V];
bool use[MAX_V];
int V,E;            // V:????????°   E:????????°
int indeg[MAX_V];   // ??\?¬???°
list<int> out;

void bfs(int s){
    queue<int> que;
    que.push(s);
    use[s]=true;

    while(!que.empty()){
        int u=que.front();
        que.pop();
        out.push_back(u);

        for(int v : G[u]){
            indeg[v]--;
            if(indeg[v]==0 and !use[v]){
                use[v]=true;
                que.push(v);
            }
        }
    }
}

void tsort(){
    for(int i=0;i<V;i++) indeg[i]=0;

    //??\?¬???°????¨????
    for(int u=0;u<V;u++){
        for(int v:G[u]){
            indeg[v]++;
        }
    }

    for(int u=0;u<V;u++){
        if(indeg[u]==0 and !use[u]) bfs(u);
    }

    for(auto v : out){
        cout << v << endl;
    }
}

int main(){
    cin>>V>>E;
    for(int i=0;i<E;i++){
        int u,v;cin>>u>>v;
        G[u].push_back(v);
    }

    tsort();
}

Measured memory_bytes: 4096
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
//function area
string str;
void do_print(int a, int b){
    cout << str.substr(a, b-a+1) << endl;
}
void do_reverse(int a, int b){
    reverse(str.begin()+a, str.begin()+b+1);
}
void do_replace(int a, int b, string s){
    str.replace(a, b-a+1, s);
}
//main area
int main(){
    cin >> str;
    int n;
    cin >> n;
    rep(i,n){
        string check;
        cin >> check;
        if(check == "print"){
            int a, b;
            cin >> a >> b;
            do_print(a, b);
        }
        else if(check == "reverse"){
            int a, b;
            cin >> a >> b;
            do_reverse(a, b);
        }
        else if(check == "replace"){
            int a, b; string s;
            cin >> a >> b >> s;
            do_replace(a, b, s);
        }
    }
}


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

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    sort(ALL(a), greater<ll>());

    int cnt=0;
    ll ans=0;
    ans += a[0];
    int i=1;
    while(cnt < n-2){
        cnt++;
        ans+=a[i];
        if(cnt%2==0) i++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main(){
    int n, mx = 0, count = 0, num = 0;
    cin >> n;
    string s[n], v[n], mem;
    for(int i=0; i<n; i++){
        cin >> s[i];
    }
    sort(s, s+n);
    mem = s[0];
    count = 1;
    for(int i=1; i<n; i++){
        if(s[i] == mem){
            count++;
        }else{
            if(mx < count){
                mx = count;
                num = 0;
                v[num] = mem;
            }else if(mx == count){
                num++;
                v[num] = mem;
            }
            mem = s[i];
            count = 1;
        }
    }
    if(mx < count){
        count = mx;
        num = 0;
        v[num] = mem;
    }else if(mx == count){
        num++;
        v[num] = mem;
    }
    for(int i=0; i<=num; i++){
        cout << v[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 15872
# n = int(sys.stdin.readline())
# a, b = map(int, sys.stdin.readline().split())
# c = list(map(int, sys.stdin.readline().split()))
# s = [list(map(int,list(sys.stdin.readline()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a = 100
# b = 0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋め, 小数点出力桁指定時のときの出力
# 000100-0.987654

import math
import sys
import itertools
import queue

mod = 1000000007


if __name__ == "__main__":
    N, L = map(int, sys.stdin.readline().split())
    origin = 0
    for i in range(N):
        origin += (L + i)
    diffmin = mod

    comp_min = mod
    for i in range(N):
        comp = 0
        for j in range(N):
            if j == i:
                continue
            comp += (L + j)
        if abs(origin - comp) < diffmin:
            diffmin = abs(origin - comp)
            comp_min = comp
    print(comp_min)

Measured memory_bytes: 3952
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
       int count=3000;
       Scanner scan= new Scanner(System.in);

       for(int i=1;i<=count;i++){
           int x=scan.nextInt();
           int y=scan.nextInt();
           if(x==0 && y==0){
               break;
           }else{
               if(x > y){
                   int temp=x;
                   x=y;
                   y=temp;
               }
               System.out.println(x+" "+y);
           }
       }
    }
}



Measured memory_bytes: 36044
s = input()

l = list(s)

p = []
m = 0

for i in range(0,len(l)):
    if l[i] == "A" or l[i] == "T" or l[i] == "G" or l[i] == "C":
        p.append(l[i])
        if len(p) > m:
            m = len(p)
    else:
        p = []

print(m)

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

using namespace std;

#define foru(i, l, r) for (register int i = l; i <= r; i++)
#define ford(i, r, l) for (register int i = r; i >= l; i--)

const int maxn = 2e5 + 5;
char s_1[maxn], s_2[maxn];
int top_1, top_2;

int main() {
  scanf("%s", s_2 + 1);
  top_2 = strlen(s_2 + 1);
  reverse(s_2 + 1, s_2 + top_2 + 1);
  while (top_2) {
    while (top_2 && (!top_1 || s_1[top_1] != 'S' || s_2[top_2] != 'T'))
      s_1[++top_1] = s_2[top_2--];
    if (!top_2 || !top_1) break;
    while (top_1 && top_2 && s_1[top_1] == 'S' && s_2[top_2] == 'T')
      top_1--, top_2--;
  }
  printf("%d\n", top_1 + top_2);
  return 0;
}


Measured memory_bytes: 640
S = input()

BLACK = '0'
WHITE = '1'

white_start = 0
black_start = 0

for i, s in enumerate(S):
    if i % 2 == 0:
        if s == BLACK:
            white_start += 1
        else:
            black_start += 1
    else:
        if s == BLACK:
            black_start += 1
        else:
            white_start += 1
print(min([white_start, black_start]))


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

int main(){
  int N,M,X,Y;
  cin >> N >> M >> X >> Y;
  
  int x,y;
  int max_x = -100 , min_y = 100 ;
  for ( int i = 0 ; i < N ; i++ ){
    cin >> x ;
    max_x = max(max_x,x);
  }
  for ( int i = 0 ; i < M ; i++ ){
    cin >> y ;
    min_y = min(min_y,y);
  }
  bool judge = false;
  for ( int i = X+1 ; i <= Y ; i++ ){
    if ( max_x < i && min_y >= i )
      judge = true;
  }
  
  if(judge)
		cout << "No War" << endl;
  else
        cout << "War" << endl;
}  

Measured memory_bytes: 256
n = int(input())
i = []
for z in range(n):
    i.append([int(s) for s in input().split()])

ur = [ind[0]+ind[1] for ind in i]
ul = [ind[0]-ind[1] for ind in i]
print(max([max(ur)-min(ur), max(ul)-min(ul)]))

Measured memory_bytes: 57800
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  string S;
  cin >> N >> S >> K;

  string moji = S.substr(K-1, 1);

  for(int i = 0; i < N; i++){
    if(S.substr(i, 1) != moji){
      S.replace(i, 1, "*");
    }
  }

  cout << S << endl;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int, list(input().split())))

s = sum(l)
temp = 0
if n == 2:
    print(abs(l[-1] - l[0]))
    exit(0)

for i in range(n):
    if temp >= s - temp:
        print(
            min(abs(2*temp-s), abs(2*(temp-l[i-1])-s))
        )
        exit(0)
    temp += l[i]

print(abs(2*l[-1]-s))


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
  int N;
  cin >> N;
  
  if(N < 600) cout << 8 << endl;
  else if(N < 800) cout << 7 << endl;
  else if(N < 1000) cout << 6 << endl;
  else if(N < 1200) cout << 5 << endl;
  else if(N < 1400) cout << 4 << endl;
  else if(N < 1600) cout << 3 << endl;
  else if(N < 1800) cout << 2 << endl;
  else cout << 1 << endl;
  
  return 0;
}


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

using namespace std;
using ll = long long;
const int MAX = INT_MAX;

int main() {

	int N, X, Y;
	cin>>N>>X>>Y;
	vector<int> cnt(N-1);
	for (int i = 1;i <= N;++i) {
		for (int j = i+1;j <= N;++j) {
			int d = min(min(abs(j-i), abs(X-i)+1+abs(Y-j)), abs(Y-i)+1+abs(X-j));
			cnt[d-1] += 1;
		}
	}

	for (auto const& x : cnt) {
		cout<<x<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
# Wrote in Mar 8, 2020 21:42 by reetok
require 'time'
require 'prime'
require 'bigdecimal'
def inp(type=:to_i,spst=" ")
  return eval("gets.chomp.split(#{spst}).map(&:#{type})")
end
def inpf() return self.inp(:to_f," ") end
def inps() return self.inp(:to_s," ") end
def r_up(a, b) (a/b).ceil end
def r_down(a, b) (a/b).floor end
def sum(a) a.inject(:+) end
def big(a,b) return (a>b)? a:b end
def small(a,b) return (a<b)? a:b end
def minp(n)
  t = [[],[],[]]
  n.times do |i|
    t[0][i],t[1][i],t[2][i] = inp
  end
  return t
end
def yes() puts "Yes" end
def no() puts "No" end
def ynju(bool,yes="Yes",no="No") puts (bool ? yes : no) end
class Integer
  def divisor_list
    devisors = [1]
    2.upto(self/2) do |i|
      devisors << i if self%i == 0
    end
    devisors << self
    return devisors.uniq.sort
  end
end
class Array
  def upper(a) #aより上
    self.sort.select{|n|n>=a}
  end
  def downer(a) #aより下
    self.sort.select{|n|n<=a}
  end
end
#---------------

A,B,M = inp
a = inp
b = inp
x,y,c = minp(M)

results = []

[*1..M].each do |n|
  results.push(a[x[n-1]-1]+b[y[n-1]-1]-c[n-1])
end

[*1..([A,B].min)].each do |n|
  results.push(a[n-1]+b[n-1])
end

results.push(a.min+b.min)

puts results.min



Measured memory_bytes: 38044
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;

int main() {
	for(int N; cin >> N, N;) {
		vector<long long > v(N), w(N);
		for(int i = 0; i < N; i++) {
			cin >> v[i];
		}
		sort(v.begin(), v.end());
		partial_sum(v.begin(), v.end(), w.begin());
		cout << accumulate(w.begin(), w.end() - 1, 0LL) << endl;
	}
}

Measured memory_bytes: 0
# frozen_string_literal: true

def select_index(str, substr)
  i = 0
  indexs = []
  loop do
    index = str.index(substr, i)
    return indexs unless index

    indexs << index
    i = index + 1
  end

  indexs
end

def match_all?(arr, subarr, nth, len)
  index = 0
  subarr.each.all? do |str|
    index += 1
    str == arr[index]&.slice(nth, len)
  end
end

n, m = gets.split(' ').map!(&:to_i)

a = []
b = []
n.times { a << gets.chomp! }
m.times { b << gets.chomp! }

ans = 'No'

first_line = b.shift
a.each.with_index do |a_s, i|
  select_index(a_s, first_line).each do |index|
    ans = 'Yes' if match_all?(a[i..-1], b, index, m)
    break if ans == 'Yes'
  end
  break if ans == 'Yes'
end

puts ans


Measured memory_bytes: 1788
// ABC 118 B
#include<bits/stdc++.h>

using namespace std;
//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#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 SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define PB(a) push_back(a)
#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int func(int n){
  if(n%2==0){
    return n/2;
  }else{
    return 3*n+1;
  }
}

int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------

  int s,ans=-1;
  int max = 1000000;
  cin  >> s;
  int a[max];
  a[0] = s;
  FOR(i,1,max){
    a[i] = func(a[i-1]);
    REP(j,i){
      if(a[i]==a[j]){
        ans=i+1;
      }
    }
    if(ans!=-1) break;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2304
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int n;
ll a, b;
int p[5000];

ll dp[5001][5001];

// smin, smax {{{
template < class T, class U >
inline void smin(T &a, const U &b) {
  a = a < (T) b ? a : b;
}
template < class T, class U >
inline void smax(T &a, const U &b) {
  a = a < (T) b ? b : a;
}
// }}}

constexpr ll inf = 1e18;
int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> n >> a >> b;
  for(int i = 0; i < n; i++) cin >> p[i];
  for(int i = 0; i <= n; i++) for(int j = 0; j <= n; j++) dp[i][j] = inf;
 
  dp[0][0] = 0;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j <= n; j++) {
      if(j < p[i]) {
        smin(dp[i + 1][p[i]], dp[i][j]);
        smin(dp[i + 1][j], dp[i][j] + a);
      } else {
        smin(dp[i + 1][j], dp[i][j] + b);
      }
    }
  }

  ll ans = inf;

  for(int j = 0; j <= n; j++) smin(ans, dp[n][j]);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 195712
# -*- coding:utf-8 -*-

import sys
import math

def solve(x1,y1,x2,y2,x3,y3):
    z1 = -1 * (x1**2 + y1**2)
    z2 = -1 * (x2**2 + y2**2)
    z3 = -1 * (x3**2 + y3**2)

    a11,a12,a13 = x1,y1,1
    a21,a22,a23 = x2,y2,1
    a31,a32,a33 = x3,y3,1
    det = a11*a22*a33 + a21*a32*a13 + a31*a12*a23 - a11*a32*a23 - a31*a22*a13 - a21*a12*a33

    l = ((a22*a33 - a23*a32)*z1 + (a13*a32 - a12*a33)*z2 + (a12*a23 - a13*a22)*z3)/det
    m = ((a23*a31 - a21*a33)*z1 + (a11*a33 - a13*a31)*z2 + (a13*a21 - a11*a23)*z3)/det
    n = ((a21*a32 - a22*a31)*z1 + (a12*a31 - a11*a32)*z2 + (a11*a22 - a12*a21)*z3)/det

    x,y,r = round(-l/2,3),round(-m/2,3),round(math.sqrt((l**2)/4+(m**2)/4-n),3)
    sol = [x, y, r]
    return sol


n,count = int(input()),0
array = []
for i in sys.stdin:
    array.append(i)
    count += 1
    if count == n:
        break

    
for i in range(len(array)):
    x = array[i]
    p = x.split()
    res = solve(float(p[0]),float(p[1]),float(p[2]),float(p[3]),float(p[4]),float(p[5]))
    print('{:.3f} {:.3f} {:.3f}'.format(res[0], res[1], res[2]))

Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

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

#define MAX 101010
#define NIL -1

struct Node{
    int p, l, r;
};
struct Node T[MAX];
int n, D[MAX];

void print(int u){
    int i,c;
    cout<<"node "<<u<<": ";
    cout<<"parent = "<<T[u].p<<", ";
    cout<<"depth = "<<D[u]<<", ";

    if(T[u].p == NIL) cout<<"root, ";
    else if(T[u].l == NIL) cout<<"leaf, ";
    else cout<<"internal node, ";

    cout <<"[";

    for(int i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
        if(i) cout<<", ";
        cout<<c;
    }
    cout<<"]"<<endl;
}

void rec(int u, int p){
    D[u] = p;
    if(T[u].r != NIL) rec(T[u].r, p);
    if(T[u].l != NIL) rec(T[u].l, p+1);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int i,j,d,v,c,l,r;
    cin>>n;
    REP(i,n) T[i].p = T[i].l = T[i].r = NIL;

    REP(i,n){
        cin>>v>>d;
        REP(j,d){
            cin>>c;
            if(j==0) T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }
    REP(i,n) if(T[i].p == NIL) r = i;
    rec(r,0);
    REP(i,n) print(i);
}


Measured memory_bytes: 7704
#include<bits/stdc++.h>
using namespace std;
int len;
long long ans=0;
long long dfs(long long x,long long n)
{
	if(n%x==0)
        return n*2-x;
    ans=n/x*x*2+dfs(n%x,x);
	return ans;
}
int main()
{
	long long n,k;
	scanf("%lld%lld",&n,&k);
	printf("%lld\n",dfs(k,n-k)+n);
}

Measured memory_bytes: 256
/*
 * 	The way if it's all predetermined
 * 		And the way i should go all my life
 * 			I swear to go wherever will be
 * 				'Cause there'll be something to see and to find
 * 	I don't know the meaning of life
 * 		But i know what's truly precious
 * 			The way it's leading me to be in love
 * 				No fear i can find me always in my heart
 * 	The life it's not for comparing things
 * 		So i hold both of light and shadow
 * 			The rays of stars will bring me to you
 * 				Throught the dark night skies
 * 					See the way to be shined
 */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=2e18;
const int infi=1e9;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag,
		tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int powm(int a, int b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

int a[200005];
int lar[21];
void solve() {
	int n;
	cin>>n;
	int ans=0;
	int maxi=0;
	fr(i,1,n) {
		cin>>a[i];
		for(int j=0; j<20; j++) {
			if(a[i]&1) {
				maxi=max(maxi,lar[j]);
				lar[j]=i;
			}
			a[i]>>=1;
		}
		ans+=i-maxi;
	}
	cout<<ans<<endl;
}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cout<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 1792
//include,using,define等
#pragma region header
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>

// ===============================================================
//using系
#pragma region header
using namespace std;
using ll = long long;
using lint = long long;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;
using ui = unsigned int;
using qul = queue<ll>;
using pql = priority_queue<ll>;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr ll mod = 1e9 + 7;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#pragma region header
//#define int long long
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i <= n; i++)
#define INF (ll)10000000000000000
#define mod (ll)1000000007
#define P pair<lint,lint>
template <class T>
bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
template <class T>
bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion
map<lint, lint> s;
void enum_divisors(long long N) {
	for (lint i = 2; i < sqrt(N) + 1; i++) {
		if (N % i == 0) s[i]++;
	}
	return;
}
ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

int main(void) {
	lint n; cin >> n;
	vector<Bint> a(n);
	vector<Bint> r(n);
	Bint ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i != 0) r[i] = r[i - 1] + a[i];
		else r[0] = a[0];
		if (i != 0) {
			ans += a[i] * r[i - 1];
		}
		ans %= mod;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 15684
//BISMILLAHIR RAHMANIR RAHIM
//RABBI ZIDNI ILMA
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define endl "\n"
#define inf (1LL<<61)
#define pi acos(-1)
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(0);cout<< fixed<< setprecision(10);
#define DEBUG(x) cout<<"["<<#x<<": "<<x<<"]\n"
#define DEBUG2(x, y) cout<<"["<<#x<<": "<<x<<"]"<<"  ["<<#y<<": "<<y<<"]\n"
#define DEBUG3(x, y, z) cout<<"["<<#x<<": "<<x<<"]"<<"  ["<<#y<<": "<<y<<"]"<<"  ["<<#z<<": "<<z<<"]\n"
#define DEBUG4(x, y, z, k) cout<<"["<<#x<<": "<<x<<"]"<<"  ["<<#y<<": "<<y<<"]"<<"  ["<<#z<<": "<<z<<"]"<<"  ["<<#k<<": "<<k<<"]\n"

const ll N = 1e3 + 9;

ll r, c,sr,sc,er,ec;
vector<vector<char>> cell(N, vector<char>(N));

bool legal(ll R, ll C)
{
    if(R<1 || R>r || C<1 || C>c || cell[R][C] == '#') return 0;
    return 1;
}

int main()
{
    fastio


    cin>> r>> c >> sr >> sc>> er>> ec;

    for(int i=1; i<=r; i++){
        for(int j=1; j<=c; j++) cin>> cell[i][j];
    }
    vector<vector<ll>> dis(r+1, vector<ll>(c+1, inf));
    vector<vector<bool>> vis(r+1, vector<bool>(c+1));
    deque<ll> rs(1, sr);
    deque<ll> cs(1, sc);
    vis[sr][sc] = 1;
    dis[sr][sc] = 0;
    while(rs.size()){
        ll curr = rs.front(); ll curc = cs.front();
        rs.pop_front(); cs.pop_front();
        ll dx[]={-1, 1, 0, 0};
        ll dy[]={0, 0, -1, 1};
        for(int i=0; i<4; i++){
            ll nr = curr + dx[i];
            ll nc = curc + dy[i];
            if(!legal(nr, nc)) continue;
            if(dis[nr][nc] > dis[curr][curc]){
                dis[nr][nc] = min(dis[curr][curc], dis[nr][nc]);
                vis[nr][nc] = 1;
                rs.push_front(nr); cs.push_front(nc);
            }
        }
        for(int i=curr-2; i<=curr+2; i++){
            for(int j=curc-2; j<=curc+2; j++){
                if(!legal(i, j)) continue;
                if(dis[i][j] > dis[curr][curc]+1){
                    dis[i][j] = min(dis[curr][curc] + 1, dis[i][j]);
                    vis[i][j] = 1;
                    rs.push_back(i); cs.push_back(j);
                }
            }
        }
    }
    if(dis[er][ec] > 2e18) cout<< -1;
    else cout<< dis[er][ec];
}



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

int main()
{
    int n,i,j;
    cin>>n;
    double dp[n+1][n+1],a[n+1];
    for(i=1;i<=n;i++)
        cin>>a[i];
    dp[1][1]=a[1];
    for(i=2;i<=n;i++)
        dp[i][i]=dp[i-1][i-1]*a[i];
    dp[1][0]=1-a[1];
    for(i=2;i<=n;i++)
        dp[i][0]=dp[i-1][0]*(1-a[i]);

    for(i=2;i<=n;i++)
        for(j=1;j<i;j++)
            dp[i][j]=dp[i-1][j-1]*a[i]+dp[i-1][j]*(1-a[i]);
    double ans=0;
    for(i=n/2+1;i<=n;i++)
        ans+=dp[n][i];
    cout<<fixed<<setprecision(10)<<ans<<endl;

}


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

int gcd(int x,int y){
    if(y==0)return x;
    x=x%y;
    gcd(y,x);
}
main()
{
    int n,m;
    cin>>n>>m;
    vector<int>a(n);
    vector<int>b(n);
    map<int,int> mp;
    rep(i,n){
        cin>>a[i]>>b[i];
        mp[a[i]]+=b[i];
    }
    int cnt=0,ans=0;
    auto it=mp.begin();
    while(cnt<m){
        int temp=min(m-cnt,it->second);
        ans+=it->first*temp;
        cnt+=temp;
        it=next(it);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 8064