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

using namespace std;

const int MAX = 1e5 + 5 ;
vector< vector< pair<int , int> > >adj(MAX) ;
int vis[MAX] , parent[MAX] , Distance[MAX];

int now , dist = 0 ;

void bfs(int node)
{
    now = node , dist = 0 ;
    queue< pair<int , pair<int , int> > >q ;
    q.push({node , {0 , -1}}) ;
    Distance[node] = 0 ;
    parent[node] = node ;
    while(!q.empty())
    {
        pair<int , pair<int , int> >p = q.front() ;
        q.pop() ;
        int cur = p.first , d = p.second.first , par = p.second.second ;
        vis[cur] = 1 ;
        parent[cur] = par ;
        if(d > dist)
            now = cur , dist = d ;
        for(auto &child : adj[cur])
        {
            if(child.first == par)
                continue;
            Distance[child.first] = child.second ;
            q.push({child.first , {d + child.second , cur}}) ;
        }
    }
    return ;
}

int travelTime(int n , int m , int l , int A[] , int B[] , int T[] )
{
    memset(parent , -1 , sizeof(parent)) ;
    for(int i = 0 ; i < m ; ++i)
    {
        int x = A[i] , y = B[i] , c = T[i] ;
        adj[x].push_back({y , c}) ;
        adj[y].push_back({x , c}) ;
    }
    bfs(0) ;
    bfs(now) ;
    return dist ;
}

int main()
{
    int n  , m;
    cin>>n ;
    m = n-1 ;
    //I won't use l variable.
    int l = 3 ;
    int a[m] , b[m] , t[m] ;
    for(int i = 0 ; i < m ; ++i)
        cin>>a[i]>>b[i]>>t[i] ;
    cout<<travelTime(n , m , l , a , b , t)<<"\n" ;
    return  0 ;
}



Measured memory_bytes: 12040
#include<cstdint>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<iterator>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>
#include<utility>
#include<initializer_list>


#define repi(i,start,end)for(int64_t (i)=(start);(i)<(end);++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x, v) for(auto& (x) : (v))
#define iterate(itr, v) for(auto (itr)=(v).begin();(itr)!=(v).end();++(itr))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vin(v) rep(i,(v).size()) cin >> (v)[i];
#define vpin(v) rep(i,(v).size()) cin >> (v)[i].first >> (v)[i].second

using namespace std;
using pint = tuple<int64_t, int64_t>;
using vint = vector<int64_t>;
using vvint = vector<vint>;
using vpint = vector<pint>;
using vstr = vector<string>;

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; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<"\n";}
template<class T>void println(T a){cout << a << "\n";}
template<class T>void put_line(T &v){iterate(itr,v){cout<<*itr<<(itr==--v.end())?"\n":" ";}}
// auto [x, y] = make_tuple(3, 4); => let (x, y) = (3, 4);

int main(void) {
    int64_t r; cin >> r;
    put_double(2 * r * 3.14159265358);

    return 0;
}


Measured memory_bytes: 3760
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    double min=n/1.08;
    double max=(n+1)/1.08;
    bool flag= true;
    for(int i=0;i<50000;i++){
        if(i>=max){
            break;
        }
        if(i>=min){
            flag=false;
            cout<<i<<endl;
        }
     }
     if(flag){
         cout<<":(";
         

     }


}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  bool num[160001] = {false};
  num[0] = num[1] = true;
  for(int i=2; i<401; i++){
    if(num[i] == false){
      for(int j=i*i; j<160001; j+=i){
	num[j] = true;
      }
    }
  }
  vector<int> tag;
  for(int i=0; i<160001; i++){
    if(!num[i]){tag.push_back(i);}
  }
  int n,p;
  while(cin >>n>>p){
    if(n == -1 && p == -1){break;}
    int at = 0;
    vector<int> add;
    for(int i=0;;i++){if(tag[i]>n){at = i;break;}}
    for(int i=at,x=0;i<at+100;i++){
      for(int j=i;j<at+100;j++){
	add.push_back(tag[i]+tag[j]);
      }
    }
    sort(add.begin(),add.end());
    cout<<add[p-1]<<endl;
  }
  return 0;
}

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

using namespace std;

typedef pair<int,int> P;
typedef long long ll; 

#define int ll

const int MAX_P = 1000001;
bool isprime[MAX_P];

void make_prime(){
	fill(isprime,isprime+MAX_P, true);
	isprime[0] = isprime[1] = false;
	for(int i=2;i<MAX_P;i++){
		while(!isprime[i]&&i<MAX_P) i++;
		for(int j=i*2;j<MAX_P;j+=i) isprime[j] = false;
	}

}

main(){
	make_prime();

	ll n;
	cin >> n;

	int ans = 0;

	for(int p=2;p<MAX_P;p++){
		if(!isprime[p]) continue;
		int e = 0;
		while(n%p==0){
			e++;
			n/=p; 
		}
		int z = 1;
		while(z<=e){
			ans++;
			e-=z;
			z++;
		}
	}

	if(n!=1) ans++;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4564
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i, N) for (int i = 0; i < N; ++i)
typedef long long int LL;

int A,B,C;

int main()
{
	in>>A>>B>>C;
	if(A==B&&B!=C){out<<C<<std::endl;}
	if(C==B&&B!=A){out<<A<<std::endl;}
	if(A==C&&B!=C){out<<B<<std::endl;}
	
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	static class Team implements Comparable<Team> {
		int number;
		int corrects;
		boolean[] accepted;
		int[] worngs;
		int penalty;

		@Override
		public String toString() {
			return number + " " + corrects + " " + penalty;
		}

		@Override
		public int compareTo(Team arg0) {
			if (arg0.corrects != this.corrects) {
				return arg0.corrects < this.corrects ? -1 : 1;
			}

			if (arg0.penalty != this.penalty) {
				return arg0.penalty < this.penalty ? 1 : -1;
			}

			return arg0.number < this.number ? 1 : -1;
		}
	}

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);

		while (true) {

			final int T = sc.nextInt();
			final int P = sc.nextInt();
			final int R = sc.nextInt();

			if(T == 0 && P == 0 && R == 0){
				return;
			}
			
			Team[] teams = new Team[T];
			for (int i = 0; i < T; i++) {
				teams[i] = new Team();
				teams[i].number = i + 1;
				teams[i].corrects = 0;
				teams[i].accepted = new boolean[P];
				teams[i].worngs = new int[P];
				teams[i].penalty = 0;
			}

			for (int i = 0; i < R; i++) {
				final int team = sc.nextInt() - 1;
				final int problem = sc.nextInt() - 1;
				final int time = sc.nextInt();
				String str = sc.next();

				if (teams[team].accepted[problem]) {
					continue;
				}

				if ("CORRECT".equals(str)) {
					teams[team].corrects++;
					teams[team].penalty += teams[team].worngs[problem] * 1200 + time;
					teams[team].accepted[problem] = true;
				} else {
					teams[team].worngs[problem]++;
				}
			}

			Arrays.sort(teams);

			for (Team t : teams) {
				System.out.println(t);
			}
		}

	}

}

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

int main(){
	int n, k;
	cin>>n>>k;
	vector<int> v(n);
	int mn = 0, mx = 0;
	for (int i = 0; i<n; i++){
		cin>>v[i];
		if (v[i]>mx)
			mx = v[i]; 
	}
	mx+=10;
	int M, cnt;
	while(mn+1<mx){
		cnt = 0;
		M = (mn+mx)/2;
		for(auto u : v)
			cnt+=(u-1)/M;
		if(cnt<=k) mx = M;
		else mn = M;
	}
	cout<<mx;
}


Measured memory_bytes: 4044
IDENTIFICATION DIVISION.
program-id. kyopuro.

data division.
working-storage section.
01 in-str pic x(13).
01 n pic 9(6).
01 k pic 9(5).
01 res pic 9(11).
01 t pic 9(5).
01 view-res pic z(18)9.
01 q pic 9(5).
01 r pic 9(5).
01 i pic 9(6).

procedure division.
main.
    accept in-str.
    unstring in-str delimited by all SPACE
    into n k.
    
    if k = 0
    then
        compute view-res = n * n
    else
    compute i = k + 1
    compute t = n - k
        perform t times
            divide n by i giving q remainder r
            compute res = res + (i - k) * q + function max(r - k + 1, 0)
            add 1 to i
        end-perform
        move res to view-res
    end-if.
    
    display view-res.
    stop run.


Measured memory_bytes: 636
#include<iostream>
#include<bits/stdc++.h>
#include<vector>
using namespace std;
#define fo(i,b,n) for(int i=b;i<n;i++)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sll(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define endl "\n"
#define PI 3.1415926535897932384626
const int mod = 1000000007;
/*===========================================================================*/


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  float n, k; cin>>n>>k;
  float ans = ceil((n-1)/(k-1));


  cout<<ans;



  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//二項係数の計算
int nCr(int A, int B) {
    ll ans = 1;
    for (int i = 0; i < B; i++) {
        ans *= A - i;
    }
    for (int i = 0; i < B; i++) {
        ans /= i + 1;
    }
    return ans;
}
int main(){
int a,b;
  cin>>a>>b;
  cout<<(b-a)*(b-a-1)/2-a<<endl;
}



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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def build_grid(H, W, intv, _type, space=True, padding=False):
    # 入力がスペース区切りかどうか
    if space:
        _input = lambda: input().split()
    else:
        _input = lambda: input()
    _list = lambda: list(map(_type, _input()))
    # 余白の有無
    if padding:
        offset = 1
    else:
        offset = 0
    grid = list2d(H+offset*2, W+offset*2, intv)
    for i in range(offset, H+offset):
        row = _list()
        for j in range(offset, W+offset):
            grid[i][j] = row[j-offset]
    return grid

H, W = MAP()
grid = build_grid(H, W, '*', str, space=0, padding=1)

# dp[i][j] := マス(i, j)に到達するための最小コスト
dp = list2d(H+2, W+2, INF)
if grid[1][1] == '.':
    dp[1][1] = 0
else:
    dp[1][1] = 1
for i in range(H+1):
    for j in range(W+1):
        # 白から黒への移動のみコストがかかる
        if grid[i][j] == '.' and grid[i][j+1] == '#':
            dp[i][j+1] = min(dp[i][j+1], dp[i][j] + 1)
        else:
            dp[i][j+1] = min(dp[i][j+1], dp[i][j])  
        if grid[i][j] == '.' and grid[i+1][j] == '#':  
            dp[i+1][j] = min(dp[i+1][j], dp[i][j] + 1)
        else:
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
ans = dp[H][W]
print(ans)


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

//create arrays outside of main()
int N = 10;
int steps[100] = {};

string input;
stack<char> s;
stack<char> d;

int main() {


    cin >> input;

    for(int i=0; i<input.length(); i++){
        if(input[i]=='0'|| input[i]=='1'){
            s.push(input[i]);
        } 
        else if(input[i]=='B'){
            if(!s.empty()){
                s.pop();
            }
        }
    }

    while(!s.empty()){
        d.push(s.top());
        s.pop();
    }

    while(!d.empty()){
        cout << d.top();
        d.pop();
    }

    return 0;
}

Measured memory_bytes: 256
def fold(x,m):
    y = 0
    for _ in range(m):
        y |= x&1
        y <<= 1
        x >>= 1
    return x|y

lmi = lambda: list(map(int, input().split()))

h,w = lmi()
a = [lmi() for _ in range(2*h)]
g = [[abs(a[i][j] - a[i+h][j]) for j in range(w)] for i in range(h)]

mask = (1<<12801) - 1

dp = [[0]*(w+1) for _ in range(h+1)]
dp[0][0] = 1
for i in range(h):
  for j in range(w):
    cur,par = g[i][j],dp[i][j]
    pos = (par<<cur)|fold(par,cur)
    pos &= mask
    dp[i+1][j] |= pos
    dp[i][j+1] |= pos
for i in range(12801):
  if dp[-1][-2]&(1<<i):
    print(i)
    break


Measured memory_bytes: 9816
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}


int main(){
	int n;
	ll h;
	cin>>n>>h;
	vector<int> a(n),b(n);
	rep(i,n){
		cin>>a[i]>>b[i];
	}
	sort(a.begin(),a.end());
	reverse(a.begin(),a.end());
	sort(b.begin(),b.end());
	reverse(b.begin(),b.end());
	int aa=a[0];
	ll x=0;
	int ans=0;
	while(x<h){
		ans++;
		if(b.empty()){
			x+=aa;
		}else if(b[0]>aa){
			x+=b[0];
			b.erase(b.begin());
		}else{
			x+=aa;
		}
	}
	cout<<ans<<endl;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  while (true) {
    C -= B;
    if (C <= 0) return cout << "Yes" << "\n", 0;
    A -= D;
    if (A <= 0) return cout << "No" << "\n", 0;
  }
}

Measured memory_bytes: 3588
#include <iostream>
#include <set>
#define BurstStream ios_base::sync_with_stdio(false); cin.tie(0);
using namespace std;

int main()
{
    BurstStream
    int n;
    while (cin >> n)
    {
        long long mxside[] = {0, 0};
        set<long long> s;

        while (n--)
        {
            long long temp;
            cin >> temp;

            if (s.find(temp) == s.end()) s.insert(temp);
            else
            {
                s.erase(temp);
                if (temp > mxside[0])
                {
                    mxside[1] = mxside[0];
                    mxside[0] = temp;
                }
                else if (temp > mxside[1]) mxside[1] = temp;
            }
        }
        cout << mxside[0] * mxside[1] << '\n';
    }
    return 0;
}


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

int main() {

  int A, B;
  cin >> A >> B;
  int count = 0;
  for (int i = A; i <= B; i++) {
    int s = i % 10;
    int t = (i / 10) % 10;
    int tt = (i / 1000) % 10;
    int ss = (i / 10000) % 10;
    
    if (s == ss && t == tt) {
      count++;
    }
  }
  cout << count << endl;

}


Measured memory_bytes: 256
#include <stdio.h>


int main(void){
char s[100000];
int i;
int count1=0;
int count2=0;
scanf("%s",s);

for(i=0;s[i]!=NULL;i++){
if(i%2==0)
 if(s[i]=='0')count1++;
if(i%2==1)
 if(s[i]=='1')count1++;
}
for(i=0;s[i]!=NULL;i++){
if(i%2==1)
 if(s[i]=='0')count2++;
if(i%2==0)
 if(s[i]=='1')count2++;
}
printf("%d",(count1>count2)?count2:count1);
  return 0;
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	vector<int> rev(n);
	for (int i = 0; i < n; ++i) {
		rev[a[i] - 1] = i + 1;
	}
	for (int i = 0; i < n; ++i) {
		cout << rev[i] << " ";
	}
	cout << '\n';
	
	return 0;
}


Measured memory_bytes: 1664
import java.util.*;

public class Main{
	public static void main(String[] args) {
     
      Scanner in =new Scanner(System.in);
      int n=in.nextInt();
      int k=in.nextInt();
      
      if (n%2==1){
        if (k>n/2+1)System.out.println("NO");
        else System.out.println("YES");
      }
      else if (k>n/2)System.out.println("NO");
      else System.out.println("YES");
      return;
    }
}


Measured memory_bytes: 21588
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>
#include <bitset>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
ll dp[2001][2001];

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  ll x;
  cin >> x;
  vector<ll> a;
  for(int i = 0; i < n; i++){
    ll y;
    cin >> y;
    a.pb(y);
  }
  for(int i = 0; i < n; i++){
    dp[i][i] = a[i];
    for(int j = i + 1; j < n; j++){
      dp[i][j] = min(dp[i][j-1], a[j]);
    }
  }

  ll mini = linf;
  for(int k = 1; k <= n; k++){
    ll tmp = 0;
    for(int i = 0; i < n; i++){
      ll tmin;
      if(i - k + 1 >= 0)tmin = dp[i-k + 1][i];
      else{
        tmin = dp[0][i];
        tmin = min(tmin, dp[n - k + i + 1][n - 1]);
      }
      tmp += tmin;
    }
    mini = min(mini, tmp + (k - 1) * x);
  }
  cout << mini << endl;
	return 0;
}


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

int main(void){
	long long countA,countB,ans;
	string S;
	cin>>S;
	countA=countB=ans=0;
	for(long long i=0;i<S.size();i+=2){
	    if(S[i]=='0'){
	        countA++;
	    }
	}
	for(long long i=1;i<S.size();i+=2){
	    if(S[i]=='0'){
	        countB++;
	    }
	}
	if(countA>countB){
	    for(long long i=1;i<S.size();i+=2){
	        if(S[i]=='1'){
	            countA++;
	        }
	    }
	    ans=S.size()-countA;
	}
	else{
	    for(long long i=0;i<S.size();i+=2){
	        if(S[i]=='1'){
	            countB++;
	        }
	    }
	    ans=S.size()-countB;
	}
	cout<<ans<<endl;
}
	
	
	
	

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

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

    bool even = (k % 2 == 0);
    if (abs(a-b) > 1000000000000000000) {
        cout << "Unfair" << endl;
    } else {
        if (even) {
            cout << a - b << endl;
        } else {
            cout << b - a << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    int n;
    cin>>n;
    if(n>=24){
        cout<<0<<endl;
        return 0;
    }
    int d[n];
    rep(i,n)cin>>d[i];
    int ans=0;
    rep(s,1<<n){
        int cnt[24]={1};
        bool flag=true;
        rep(i,n){
            if(s&(1<<i)){
                if(cnt[d[i]]){
                    flag=false;
                }
                ++cnt[d[i]];
            }
            else{
                if(d[i]==0||cnt[24-d[i]]){
                    flag=false;
                }
                ++cnt[24-d[i]];
            }
        }
        if(!flag)continue;
        int mn=inf;
        int mx=0;
        for(int i=1;i<=23;++i){
            if(cnt[i]){
                mn=min(mn,i-mx);
                mx=i;
            }
        }
        mn=min(mn,24-mx);
        ans=max(ans,mn);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define x first
#define y second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

int main()
{
	int x,y;scanf("%d%d",&x,&y);
	if (abs(x)==abs(y))
	{
		printf("%d\n",x!=y);return 0;
	}
	if (abs(x)<abs(y))
	{
		printf("%d\n",abs(y)-abs(x)+(x<0)+(y<0));
		return 0;
	}
	printf("%d\n",abs(x)-abs(y)+(x>0)+(y>0));
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	string s;
	cin >> s;
	
	int ret = 99;
	for(int i = 0 ; i < 26 ; i ++){
		char c = 'a'+i;
		int pre = -1;
		int cnt = 0;
		for(int j = 0 ; j < s.size() ; j ++){
			if(s[j] == c){
				cnt = max ( cnt , j-pre );
				pre = j;
			}
		}
		cnt = max ( cnt , (int)s.size()-pre );
		ret = min ( ret , cnt-1 );
	}
	cout << ret << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()


int main(){
    ll h, w;
    cin >> h >> w;
    vector<string> s(h);
    REP(i, h){
        cin >> s.at(i);
    }

    const bool start_is_black = s.at(0).at(0) == '#';
    const bool end_is_black = s.at(h - 1).at(w - 1) == '#';
    if(start_is_black){
        REP(i, h){
            REP(j, w){
                if(s.at(i).at(j) == '#'){
                    s.at(i).at(j) = '.';
                }else{
                    s.at(i).at(j) = '#';
                }
            }
        }
    }

    vector<vector<ll>> dist(h, vector<ll>(w, numeric_limits<ll>::max()));
    dist.at(0).at(0) = 0;
    REP(i, h){
        REP(j, w){
            if(i > 0){
                if(s.at(i - 1).at(j) == '.' && s.at(i).at(j) == '#'){
                    dist.at(i).at(j) = min(
                        dist.at(i).at(j), dist.at(i - 1).at(j) + 1);
                }else{
                    dist.at(i).at(j) = min(
                        dist.at(i).at(j), dist.at(i - 1).at(j));
                }
            }

            if(j > 0){
                if(s.at(i).at(j - 1) == '.' && s.at(i).at(j) == '#'){
                    dist.at(i).at(j) = min(
                        dist.at(i).at(j), dist.at(i).at(j - 1) + 1);
                }else{
                    dist.at(i).at(j) = min(
                        dist.at(i).at(j), dist.at(i).at(j - 1));
                }
            }
        }
    }
    cout << dist.at(h - 1).at(w - 1) + (end_is_black && start_is_black) << endl;
    return 0;
}


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

int main()
{
	int n;
	scanf("%d", &n);
	std::vector<long double> prob(n + 1);
	prob[0] = 1.0;
	for (int i{}; i < n; i++)
	{
		long double p;
		std::cin >> p;
		for (int j{i + 1}; j > 0; j--)
			prob[j] = p * prob[j - 1] + (1.0 - p) * prob[j];
		prob[0] *= 1.0 - p;
	}
	long double ans{};
	for (int i{n / 2 + 1}; i <= n; i++)
		ans += prob[i];
	printf("%.10Lf\n", ans);

	return 0;
}

Measured memory_bytes: 384
n = int(input())
List = [[0 for i in range(3)] for j in range(n)]
for i in range(n):
    robot, arm = map(int, input().split())
    List[i][0] = robot - arm # LeftEnd
    List[i][1] = robot # Center
    List[i][2] = robot + arm # RightEnd

sorted_List = sorted(List, key=lambda x: x[2])

now_rightend = sorted_List[0][2]
counter = 1

for i in range(n):
    if sorted_List[i][0] >= now_rightend:
        now_rightend = sorted_List[i][2]
        counter += 1

print(counter)

Measured memory_bytes: 26792
#include<stdio.h>
#define N 101
  
int main()
{
  int i,j,n,count=0,v,c,c1,v1;
  int G[N][N],col[N],d[N],pi[N],min,i2;
  
  for(i = 0; i < N; i++){
  
    for(j = 0; j < N; j++)
      G[i][j] = -1;
  
  }
  
  scanf("%d",&n);
  
  for(i = 0; i < n; i++){
  
    scanf("%d%d",&v,&c);
  
    for(j = 0; j < c; j++){
      scanf("%d%d",&v1,&c1);
      G[v][v1] = c1;
    }
  
  }
   
  for(i = 0; i < n; i++){
  
    col[i] = 0;
    pi[i] = -1;
    d[i] = 10000001;
  
  }
  
  d[0] = 0;
   
  while(1){
  
    min = 10000001;
  
    for(i = 0; i < n; i++){
  
      if(col[i] != 2 && d[i] < min){
        min = d[i];
        i2 = i;
      }
  
    }
  
    if(min == 10000001)break;
  
    col[i2] = 2;
  
    for(i = 0; i < n; i++){
  
      if(G[i2][i] != -1 && col[i] != 2 && (G[i2][i]+d[i2]) < d[i]){
    pi[i] = i2;
    d[i] = G[i2][i] + d[i2];
    col[i] = 1;
      }
  
    }
  
  }
  
  for(i = 0; i < n; i++)printf("%d %d\n",i,d[i]);
  
  return 0;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;

}

signed main() {
	ll n, m;
	ll ans = INF;

	cin >> n >> m;

	vector<ll> v(m, 0);

	REP(i, m) {
		cin >> v[i];
	}

	vector<ll> dp(n + 1, 0);

	REP(i, m) {
		dp[v[i]] = -1;
	}

	dp[0] = 1;

	FOR(i, 1, n + 1) {
		if (dp[i] == -1) {
			continue;
		}

		if (dp[i - 1] != -1) {
			dp[i] += dp[i - 1];
			dp[i] %= MOD;
		}
		if (i > 1 && dp[i - 2] != -1) {
			dp[i] += dp[i - 2];
			dp[i] %= MOD;
		}
	}

	cout << dp[n] % MOD << endl;
}

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

int main(){
  long n,k,s;
  cin >> n >> k >> s;
  if(k==n){
    for(int i; i<n; i++){
      cout << s << " ";
    }
  cout << endl;
  }
  else{
  vector<int> ans(n,0);
    if(s>5){
      for(int i=0; i<k+1; i=i+2){
    ans[i]=s-1;
  }
  for(int j=1; j<k+1;j=j+2){
    ans[j] = 1;
  }
      for(int p=k+1; p<n;p++){
        ans[p]=s-2;
      }
    }
    else{
    for(int y=0;y<k;y++){
      ans[y]=s;
    }
   for(int z=k;z<n;z++){
     ans[z]=100;
   }
    }
    for(int x; x<n;x++){
      cout << ans[x] << " ";
    }
  cout << endl;
  }


}


Measured memory_bytes: 1664
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

S = list(s())
S.sort()
if S == ['a','b','c']:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9980
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cout << a[i] << " "; cout << "\n"; }
ll dbgt = 1; void err() { cout << "passed " << dbgt++ << "\n"; }
template<class H, class... T> void err(H&& h,T&&... t){ cout<< h << (sizeof...(t)?" ":"\n"); if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll A[200005], dp[200005][4], amax[3];
int main() {
    init();
    ll N;
    cin >> N;
    rep(i, N) cin >> A[i];
    rep(i, N + 2) fill(dp[i], dp[i] + 4, -INF);

    ll b = 1 + (N & 1);
    dp[0][0] = 0;
    rep(i,N){
        rep(j,b+1){
            chmax(dp[i + 2][j], dp[i][j] + A[i]);
            chmax(dp[i + 1][j + 1], dp[i][j]);
        }
    }
    rep(j, b) chmax(dp[N + 1][j + 1], dp[N][j]);

    cout << dp[N+1][b] << endl;
}

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

int main(){
    int a[3];
    for(int i = 0; i < 3;i++)cin >> a[i];
    sort(a,a+3);

    int ans = 0;
    for(int i = 1;i < 3; i++){
	ans += abs(a[i]-a[i-1]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
R, G, B, N = map(int, input().split())
ans = 0
r, g = 0, 0
rmax = N // R
gmax = N // G

if R * G * B == 1:
  for i in range(N + 1):
    ans += N + 1 - i
  print(ans)
  exit()

for i in range(rmax + 1):
  for j in range(gmax + 1):
    if (N - i * R - j * G) < 0:
      break
    if (N - i * R - j * G) % B == 0:
      ans += 1
#      print(ans, i, j)
print(ans)


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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch) {
    if (ch == 'A')  return 1;
    else if (ch == 'C')  return 2;
    else if (ch == 'G')  return 3;
    else if (ch == 'T')  return 4;
    else return 0;
}

long long getKey(char str[]) {
    long long sum = 0, p = 1, i;
    for (i = 0; i < strlen(str); i++) {
        sum += p * (getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int hash1(int key) {    return key % M; }
int hash2(int key) {    return 1 + (key % (M-1));   }

int find(char str[]){
    long long key, h, i;
    key = getKey(str);
    for (i = 0;; i++){
        h = (hash1(key) + i * hash2(key)) % M;
        if ( strcmp(H[h], str ) == 0 )  return 1;
        else if ( strlen(H[h]) == 0 ) return 0;
    }
    return 0;
}

int insert(char str[]) {
    long long key, h, i;
    key = getKey(str);
    for (i = 0;; i++){
        h = (hash1(key) + i * hash2(key)) % M;
        if ( strcmp(H[h], str ) == 0 )  return 1;
        else if ( strlen(H[h]) == 0 ) {
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}

int main() {
    int n, h;
    char str[L], com[9];
    for (int i = 0; i < M; i++) H[i][0] = '\0';
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> com >> str;
        if (com[0] == 'i') {
            insert(str);
        }
        else {
            if (find(str))  cout << "yes" << endl;
            else    cout << "no" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 17396
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 

//O(ElogV)のdijkstra
long long INF=1000000000; // コストの影響のでない十分な値10^10;
struct edge {long long to,cost;};//操作始点sから各場所へのコスト表示法
int V;//頂点の数
vector <edge> G[2000010];//各頂点(0~V-1)からのびる辺
long long d[2000010];//sを始点とする最短経路

void dijkstra(int s){
    //小さい順に取り出せるpriority_queue
    priority_queue < P, vector<P>, greater<P> > que;
    fill(d,d+V,INF);
    d[s]=0;
    que.push(P(0,s));

    while(!que.empty()){
        P p=que.top(); que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;//下を読まずに次へ。
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

int main()
{ 
    //連結成分に関するダイクストラ法の応用。
    //頂点V(from0toV-1)と辺Eが与えられた時、kを含む連結成分の最小頂点を返す。
    int n;//頂点数
    int m;//辺数
    int conn=0;//連結数
    cin>>n>>m;
    V=n+1;
    for(int i=0;i<m;i++){
        int v1,v2,z;
        cin>>v1>>v2>>z;
        edge e;
        e.to=v2;
        e.cost=0;
        G[v1].push_back(e);
        e.to=v1;
        G[v2].push_back(e);
    }
    for(int i=1;i<=n;i++){
        edge e;
        e.to=i;
        e.cost=i;
        G[0].push_back(e); 
    }
    dijkstra(0);
    for(int i=1;i<=n;i++){
        if(i==d[i]){conn++;}
    }
    cout<<conn<<endl;
    return 0;
}

Measured memory_bytes: 58480
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int X=(a+d-1)/d;
    int Y=(c+b-1)/b;
    if(X>=Y)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}


Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
vector<int>v1,v2;
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++)
	{
		int x,y;cin>>x>>y;
		v1.push_back(x+y);
		v2.push_back(x-y);
	}
	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());
	cout<<max(v1.back()-v1.front(),v2.back()-v2.front())<<endl;
}

Measured memory_bytes: 5092
#include <cstdio>
#include <iostream>
using namespace std;
int a[100001];
int main()
{
    int n,c1=0,c2=0,c3=0;
    scanf("%d",&n);
    getchar();
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%4==0) c1++;
        if(a[i]%2==0) c2++;
        
    }
    c2-=c1;
    n=n-c2+(c2>=1);
    if((c1)>=n/2) printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 640
#include <stdio.h>
 
int gcd(int a,int b)
{
  if(b==0)
      return a;
  
  else
      return gcd(b,a%b);
}

int main()
{
 
  int n;
  scanf("%d",&n);
  int a[n],i;
  for(i=0;i<n;++i)
       scanf("%d",&a[i]);
  
  int ans=a[0];
  int sum=0;
  for(i=1;i<n;++i)
  {
    ans=(ans*a[i])/(gcd(ans,a[i]));
  }
  
  for(i=0;i<n;++i)
  {
    sum+=ans/a[i];
  }
  
  double ans1=(double)ans/sum;
  
  printf("%lf",ans1);
  
}


Measured memory_bytes: 128
from collections import defaultdict
N = int(input())
cards = []
card_cnt = defaultdict(int)

cards = input().split()
for i in range(0, N):
    cards[i] = int(cards[i])
    card_cnt[cards[i]] = card_cnt[cards[i]]+1

cards = sorted(cards)

if N == len(card_cnt.keys()):
    print(N)
else:
    begin = 0; end = N-1
    while(begin < end):

        while card_cnt[cards[begin]] == 1 and begin+2 < end:
            #print(begin)
            begin = begin + 1
        while card_cnt[cards[end]] == 1 and begin+2 < end:
            #
            end = end - 1

        if(begin < end):
            card_cnt[cards[begin]] = card_cnt[cards[begin]]-1
            card_cnt[cards[end]] = card_cnt[cards[end]]-1
            begin = begin + 1
            end = end - 1

    print(sum(card_cnt.values()))


Measured memory_bytes: 19948
#include <bits/stdc++.h>
#define ll long long
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(0);
    ll a, b, n; cin >> a >> b >> n;
    chmin(n, b-1);
    cout << floor(1.0*a*n/b) - a * floor(1.0*n/b) << endl;
}

Measured memory_bytes: 3772
#include <stdio.h>
#include <string.h>

int main(void) {
	int max,data;
	int num;
	int cut_i;
	
	char hebi[201];
	scanf("%d",&max);
	
	for(data=0;data<max;data++) {
		scanf("%s",hebi);
	
		if(strlen(hebi)<2 || hebi[0]!='>') {
			puts("NA");
			continue;
		}
		
		if(hebi[1]=='\'') {
			num=0;
			cut_i=2;
		
			while(hebi[cut_i]=='=') {
				cut_i++;
				num++;
			}
			
			if(hebi[cut_i]!='#' || num<=0){
				puts("NA");
			}
			else {
				cut_i++;
				
				while(hebi[cut_i]=='=') {
					cut_i++;
					num--;
				}

				if(num!=0){
					puts("NA");
				}
				else if(hebi[cut_i]!='~' || hebi[cut_i+1]!=0){
					puts("NA");
				}
				else {
					puts("A");
				}
			}
		} 
		
		else if(hebi[1]=='^') {
			cut_i=2;
			while(hebi[cut_i]=='Q' && hebi[cut_i+1]=='='){
				cut_i+=2;
			}

			if(cut_i==2){
				puts("NA");
			}

			else if(hebi[cut_i]!='~' || hebi[cut_i+1]!='~' || hebi[cut_i+2]!=0){
				puts("NA");
			}
			else {
				puts("B");
			}
		} else {
			puts("NA");
		}
	}
	return 0;
}

Measured memory_bytes: 1016
#include <bits/stdc++.h>
using namespace std;
int d[100005][5],n;
int a[100005][5];

int main()
{
    scanf("%d",&n);
    for(int i = 1;i <= n;i++)
    {
        for(int j = 1;j <= 3;j++)
        {
            scanf("%d",&a[i][j]);
        }
    }
    for(int i = 1;i <= n;i++)
    {
        d[i][1] = max(d[i-1][2],d[i-1][3])+a[i][1];
        d[i][2] = max(d[i-1][1],d[i-1][3])+a[i][2];
        d[i][3] = max(d[i-1][2],d[i-1][1])+a[i][3];
    }
    printf("%d",max(d[n][1],max(d[n][2],d[n][3])));
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define EFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i, n) FOR(i,0,n)

int main(void){
    ll N, K;
    cin >> N >> K;
    ll minus = abs(N%K - K);
    ll plus = abs(N%K);
    if(minus < plus) cout << minus << endl;
    else cout << plus << endl;
    return 0;
}

Measured memory_bytes: 3620
def main():
    S = input()

    if S == "SUN":
        print(7)
    elif S == "MON":
        print(6)
    elif S == "TUE":
        print(5)
    elif S == "WED":
        print(4)
    elif S == "THU":
        print(3)
    elif S == "FRI":
        print(2)
    elif S == "SAT":
        print(1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    long l, r;
    Scanner scanner = new Scanner(System.in);
    l = scanner.nextInt();
    r = scanner.nextInt();
    
    if(r - l >= 2019){
      System.out.println(0);
    }else{
      long min = 2018;
      for(long i = l; i <= r - 1; i++){
        for(long j = i + 1; j <= r; j++){
          long ij = (i * j) % 2019;
          if(ij < min){
            min = ij;
          }
        }
      }
      System.out.println(min);
    }
  }
}


Measured memory_bytes: 21972
import collections
N = int(input())


table = collections.defaultdict(list)

for i in range(10):
    table[i] = [0]*10


def get_initial(n):
    while(n // 10 > 0):
        n = n // 10
    return(n % 10)


for i in range(1, N+1):
    k = get_initial(i)
    table[k][i % 10] += 1
ans = 0
for i in range(1, 10):
    if i not in table:
        continue
    for j in range(1, 10):
        ans += table[i][j] * table[j][i]

print(ans)


Measured memory_bytes: 3316
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;


long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<long long int>v(N+1);
	for (int i = 1; i <= N; i++) {
		cin >> v[i];
	}
	vector<vector<int>>sum(20, vector<int>(N + 2));
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < 20; j++) {
			sum[j][i] = (v[i] >> j) & 1;
		}
	}
	for (int i = 0; i < 20; i++) {
		for (int j = 1; j <= N; j++) {
			sum[i][j] += sum[i][j - 1];
		}
	}
	for (int i = 0; i < 20; i++) {
		sum[i][N + 1] = MOD;
	}
	long long int ans = 0;
	for (int i = 1; i <= N; i++) {
		L = i;
		R = N + 1;
		while (R - L > 1) {
			bool flag = true;
			int mid = (R + L + 1) / 2;
			for (int j = 0; j < 20; j++) {
				if (sum[j][mid] - sum[j][i - 1] > 1)flag = false;
			}
			if (flag)L = mid;
			else R = mid;
		}
		ans += R - i;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 18304
//\\//\\ * * * //\\// ||
#include <bits/stdc++.h> 

#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;

const int N = (int) 1e7 + 10;

int d[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      ++d[j];
    }
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += (ll) i * d[i];
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 42692
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int n = 0;

  cin >> n;

  vector<int> a(n);

  for(int i = 0; i < n; i++)
    cin >> a[i];

  int ans = 0;

  for(int i = 0; i < n; i++)
    for(int j = 0; j < i; j++)
      for(int k = 0; k < j; k++) {
        if(a[i] != a[j] && a[i] != a[k] && a[j] != a[k])
          ans += (a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[j] + a[k] > a[i]);
      }

  cout << ans;

  return 0;
}
/*

*/


Measured memory_bytes: 3684
#include <iostream>
#include <vector>
#include <tuple>
using namespace std;
const int maxSize=4000;
bool visited[maxSize][maxSize];
int distances[maxSize][maxSize], amount, diameter;
vector<int> graph[maxSize];
vector<tuple<int, int>> connectedDots;
template<typename Type>
void showContent(Type input)
{
	for(auto item : input)
	{
		cout<<get<0>(item)<<" : "<<get<1>(item)<<endl;
	}
	return;
}
void fillingGraph()
{
	cin>>amount>>diameter;
	int vertex0, vertex1;
	for(int i=1; i<amount; ++i)
	{
		cin>>vertex0>>vertex1;
		graph[vertex0].push_back(vertex1);
		graph[vertex1].push_back(vertex0);
		connectedDots.push_back(make_tuple(vertex0, vertex1));
	}
	return;
}
void dfs(int root, int current, int distance)
{
	visited[root][current]=true;
	for(int next : graph[current])
	{
		if(!visited[root][next])
		{
			dfs(root, next, distance+1);
		}
	}
	distances[root][current]=distance;
	return;
}
void usingDfs()
{
	for(int point=1; point<=amount; ++point)
	{
		dfs(point, point, 0);
	}
	if(diameter%2==0)
	{
		int evenCounter=0, evenMinimum=4000;
		for(int i=1; i<=amount; ++i)
		{
			evenCounter=0;
			for(int j=1; j<=amount; ++j)
			{
				if(distances[i][j]>diameter/2)
				{
					++evenCounter;
				}
			}
			evenMinimum=min(evenMinimum, evenCounter);
		}
		cout<<evenMinimum;
	}
	if(diameter%2!=0)
	{
		int oddCounter=0, oddMinimum=4000;
		for(auto item : connectedDots)
		{
			oddCounter=0;
			for(int i=1; i<=amount; ++i)
			{
				int temporary=min(distances[get<0>(item)][i], distances[get<1>(item)][i]);
				if(temporary>diameter/2)
				{
					++oddCounter;
				}
			}
			oddMinimum=min(oddMinimum, oddCounter);
		}
		cout<<oddMinimum;
	}
	return;
}
int main()
{
	fillingGraph();
	usingDfs();
	//showContent(connectedDots);
	return 0;
}

Measured memory_bytes: 35284
X, Y, A, B, C = map(int, input().split())
red_apple = list(map(int, input().split()))
green_apple = list(map(int, input().split()))
transparent_apple = list(map(int, input().split()))
red_apple.sort(reverse=True)
green_apple.sort(reverse=True)
red_apple = red_apple[:X]
green_apple = green_apple[:Y]
transparent_apple.extend(red_apple)
transparent_apple.extend(green_apple)
transparent_apple.sort(reverse=True)
print(sum(transparent_apple[:X+Y]))


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

using namespace std;

using ll = long long;

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

    ll num_0 = 0;
    ll num_k_2 = 0;
    for (ll i = 1; i <= N; ++i) {
        if (i % K == 0) { ++num_0; }
        if (i % K == K / 2) { ++num_k_2; }
    }

    if (K % 2 == 0) {
        cout << num_0 * num_0 * num_0 + num_k_2 * num_k_2 * num_k_2 << endl;
    } else {
        cout << num_0 * num_0 * num_0 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <bitset>
#include <queue>
#include <map>
#include <utility>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define MOD 10000000000　+　7    //10億　= 10^9になってる
#define juu 100000               //10万 10e5
#define hyaku 1000000            //100万　10e6
#define mINF -922337200085470000 //llのmax-1桁の小さい方
#define pINF 922337203600070000  //llのmax-1桁のデカい方
#define uINF 1844674407300000000 //ullのmax-1桁してる
#define pi 3.1415926535897932384
ll factor[300];
ll memory[300];
/*素朴法で計算
factorは必ずmemset(factor,0,sizeof(factor));
グローバルであるmemoryに個数を書き込む
memory配列の走査にはfactorの要素を使う*/
void primefac(ll num)
{
    int i = 0, kosuu = 0;
    while (*(factor + i) != 0)
    {
        while (num % *(factor + i) == 0)
        {
            num /= *(factor + i);
            memory[*(factor + i)] += 1;
        }
        if (num == 1)
            break;
        i++;
    }
}
/*グローバルにあるfactorに素数書き込む.個数を返すので配列は-1しろforは<*/
int elast(ll number)
{
    ll tmp = 0;
    int flag = 0;
    *factor = 2;
    for (int i = 3; i <= number; i++)
    {
        flag = 0;
        for (int j = 0; j <= tmp; j++)
        {
            if (i % (*(factor + j)) == 0)
            {
                flag = 1;
                break;
            }
        }
        if (flag)
            continue;
        tmp += 1;
        *(factor + tmp) = i;
    }
    return tmp + 2;
}
/*整数をqsortする為だけのもの*/
long long compare(const long long *a, const long long *b)
{
    if (*a < *b)
        return -1;
    else if (*a > *b)
        return 1;
    return 0;
}
/*intで収まる範囲であってくれ*/
ll nCr(int n, int r)
{
    ll val = 1;
    int i;
    if (r == 0)
        return 1;
    for (i = 0; i < n - r; i++)
    {
        val *= (n - i);
        val /= (i + 1);
    }
    return val;
}
/*intで収まる範囲であってくれ*/
ll nPr(int n, int r)
{
    ll val = 1;
    int i;
    for (i = 0; i < r; i++)
    {
        val *= (n - i);
    }
    return val;
}

void chmin(ll &a, ll b)
{
    if (a > b)
        a = b;
}
void chmax(ll &a, ll b)
{
    if (a < b)
        a = b;
}

/*
qsort(array,length,sizeof(int),(int(*)(const int*, const int*))compare);
使う時これをコピペ
*/


int main()
{
    ll N,K;
    cin >> N >> K;
    ull ans=K;
    for(int i=1;i<N;i++)
    {
    	ans *= (K-1);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
# include<bits/stdc++.h>
# include<iostream>
using namespace std;
const long long MAX=1e5+10;
long long a[MAX];
long long n;
int main ()
{
    cin>>n;
    for(long long i=1; i<=n; i++)
        cin>>a[i];
    sort(a+1,a+1+n);
    long long t=a[n]/2;
    if(a[n]%2==1)
        t++;
    long long s;
    long long min1=1e9;
    for(long long i=1; i<=n-1; i++)
    {
        if(abs(t-a[i])<min1||abs(t-a[i]+1)<min1)
        {
            //cout<<i<<endl;
            min1=min(abs(t-a[i]),abs(t-a[i]+1));
            s=i;
        }
    }
    cout<<a[n]<<" "<<a[s]<<endl;
    return 0;
}


Measured memory_bytes: 1024