akhauriyash/Code-Regression huggingface dataset:
/*
Mangal bhavan amangal haari
Drabahu su Dasharath achar Bihari
Raam Siya Raam Siya Raam jai jai Raam
Raam Siya Raam Siya Raam jai jai Raam
Ho hoi hai wohi jo Raam rachi raakha
Ko kari tarak badhave saakha
Raam Siya Raam Siya Raam jai jai Raam
Ho dheeraj dharam mitra aru naari
Aapad kaal parakhiye chaari
Ho jehike jehi par satya sanehu
So tehi milay na kachhu sandehu
Ho jaaki rahi bhawana jaisi
Prabhu murati dekhi tin taisi
Ho Raghukul reet sada chali aayi
Praan jaaye par vachan na jaayi
Raam Siya Raam Siya Raam jai jai Raam, Raam
Raam Siya Raam Siya Raam jai jai Raam
Ho hari anant hari katha ananta
Kahahi sunahi bahuvidhi sab santa
Raam Siya Raam Siya Raam jai jai Raam, Raam
Raam Siya Raam Siya Raam jai jai Raam
Raam Siya Raam Siya Raam jai jai Raam
*/


#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
//auto->.
//map<int,int>::iterator i
vector<int> sieve(ll n) 
{ 
//cout<<":";
    vector<bool> prime(n+1,true); 
       
    prime[0] = false; 
    prime[1] = false; 
    int m = n; 

    for (int p=2; p<=m; p++) 
    { 
    
        if (prime[p]) 
        { 
         
            for (int i=p*2; i<=n; i += p) 
            prime[i] = false; 
        } 
    }  
    vector<int> ans; 
    for (int i=0;i<n;i++) 
        if (prime[i]) 
            ans.push_back(i);  
}

int gcd(int a,int b)
{
	if(b==0) return a;
	return gcd(b,a%b);
}
int mod = 1e9 + 7;
int power(int a , ll b)
{
	int res = 1;
	while(b)
	{
		if(b & 1)
			res = 1LL * res * a ;//% mod;
		a = 1LL * a * a ;//% mod;
		b >>= 1;
	}
	return res;
}
ll min(int a,ll b)
{
	if(a>b)
	return b;
	return a;
}
ll max(int a,ll b)
{
	if(a>b)
	return a;
	return b;
}
#define PI 3.141592653589793
ll lcm(ll a,ll b)
{
	return a*b/__gcd(a,b);
	//return t*c/__gcd(t,c);
}
bool isprime(ll n)
{
	for(int i=2;i*i<=n;i++)
	{
		if(n%i==0)
		return false;
	}
	return true;
}
ll v(ll n)
{
	if(isprime(n))
	return 1;
	for(int i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return max(i,n/i);
		}
	}
}
void solve()
{
ll a,b,c;
cin>>a>>b>>c;
ll k;
cin>>k;
if(b>a&&c>b)
{
	cout<<"Yes";
	return ;
}
	while(a>=b&&k>0)
	{
		b*=2;
		k--;
	}
	if(a>=b)
	{
		cout<<"No";
		return ;
	}
while(b>=c&&k>0)
{
	c*=2;
	k--;
}
if(b>=c)
{
	cout<<"No";
	return ;
}
cout<<"Yes";
}

int main()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
int mul=0;
if(mul==1)
{
 int t;
    cin>>t;
   while(t--)
    {
    //	cout<<"Case #"<<i<<": ";
		solve();
	cout<<"\n";
    }
}
else
{
	solve();
}
}

Measured memory_bytes: 3652
n,m,k=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))

from itertools import accumulate
a_acc=list(accumulate(a))
b_acc=list(accumulate(b))
a_acc.insert(0,0)
b_acc.insert(0,0)

ans=0
j=m

for i in range(n+1):
    nokori=k-a_acc[i]
    if nokori<0:
        break
    while b_acc[j]>nokori:
        j-=1
    ans=max(ans,i+j)
    # print(ans, i, j)

print(ans)


Measured memory_bytes: 47548
N, D = gets.split(' ').map(&:to_i)
pts = N.times.map { gets.split(' ').map(&:to_i) }
 
cnt = 0
 
pts.combination(2) do |p1, p2|
  d = Math.sqrt(D.times.inject(0) { |s, i| s + ((p1[i] - p2[i]) ** 2) })
  cnt += 1 if d == d.floor
end
 
puts cnt

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

int solve(vector<int> &arr){
    int n = arr.size();
    vector<int> dp(n, 0);
    
    // Base Cases
    dp[n-1] = 0;
    dp[n-2] = abs(arr[n-1]-arr[n-2]);
    
    // Filling the dp table
    for(int i = n-3 ; i >= 0 ; i--){
        dp[i] = min(abs(arr[i+1]-arr[i])+dp[i+1], abs(arr[i+2]-arr[i])+dp[i+2]);
    }
    
    return dp[0];
}

int main(){
    // INPUT
    int n; 
    cin >> n;
    vector<int> arr(n);
    for(auto &ele : arr)
        cin >> ele;
    
    // OUTPUT
    cout << solve(arr);
}

Measured memory_bytes: 3876
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int m1,d1,m2,d2;cin >> m1 >> d1 >> m2 >> d2;
	if(m1 != m2) cout << 1 << endl;
	else cout << 0 << endl;
}


Measured memory_bytes: 892
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <cassert>
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i,n)cin >> a[i];
    vector<P> v;
    rep(i,n){
        v.push_back(make_pair(a[i],i+1));
    }
    sort(v.begin(),v.end());
    rep(i,n){
        cout << v[i].second << " ";
    }
    //cout << endl;
}

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

int main(){
  int N = 0,H = 0,b = 0,a = 0,res = 0;
  cin >> N >> H >> b;
  res = min(N,min(H,b));
  if(res == N){
    a = min(H,b);
  }else if(H == res){
    a = min(N,b);
  }else{
    a = min(N,H);
  }
  res = a*res/2;
  cout << res << endl;
}


Measured memory_bytes: 256
# import bisect
# from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = list(map(int,ipti().split()))
    ab = [[0] * 2 for _ in range(n)]
    for i in range(n):
        ab[i] = list(map(int,ipti().split()))

    ab.sort(key=itemgetter(0))
    ans = 0

    for i in range(n):
        if ab[i][1] < m:
            m -= ab[i][1]
            ans += ab[i][0] * ab[i][1]
        else:
            ans += ab[i][0] * m
            break

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 64544
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;
const ll M = 1e9 + 7;
ll po(ll a, ll b){
    ll res = 1;
    a %= M;
    while(b){
        if(b & 1) res = res * a % M;
        a = a * a % M;
        b >>= 1LL;
    }
    return res;
}
ll mul(ll a, ll b){
    return ((a % M) * (b % M)) % M;
}
ll sub(ll a, ll b){
    return ((a % M) - (b % M) + M) % M;
}
ll ad(ll a, ll b){
    return ((a % M) + (b % M)) % M;
}
ll inv(ll a){
    return po(a, M - 2);
}
ll divi(ll a, ll b){
    return mul(a, inv(b));
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    ll ans = 1;
    for(int i = 1; i <= n; i++){
        ans = mul(ans, i);
    }
    cout << ans;
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

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

int main() {
  int H, W;
  cin >> H >> W;
  
  for (int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;
  
  for (int i = 0; i < H; i++) {
    cout << '#';
    string S;
    cin >> S;
    cout << S << '#' << endl;
  }

  for (int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;
}


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

typedef long long ll;

int main()
{
    int k,a,b;
    cin>>k;
    cin>>a>>b;
    int flag = 0;
    for(int i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            flag = 1;
            break;
        }
            
    }
    if(flag == 1)
        cout<<"OK"<<endl;
    else
        cout<<"NG"<<endl;
    

}

Measured memory_bytes: 3624
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long x){
    unordered_map<i64,i64> v;
    for(i64 a = -1000; a < 1000; ++a)
        v[a * a * a * a * a] = a;
    for(i64 a = -1000; a < 1000; ++a){
        i64 y = x + a * a * a * a * a;
        if(v.find(y) != v.end()){
            cout << v[y] << " " << a << endl;
            return;
        }
    }
    assert(false);
}


signed main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 3796
#include<stdio.h>
int main() {

	
	int n;
	long long int a[110];
	int num = 0;
	

	scanf("%d", &n);
	for (int i = 0;i < n;i++)
	{
		scanf("%lld", &a[i]);
	}
	if (n > 2) {
		for (int i = 0;i < n - 2;i++)
		{
			for (int j = i + 1;j < n - 1;j++)
			{
				if (a[i] == a[j])
				{
					continue;
				}
				for (int k = j + 1;k < n;k++)
				{
					if (a[i] == a[k] || a[j] == a[k])
					{
						continue;
					}
					if (a[k] > a[i] && a[k] > a[j])
					{
						if (a[k] < a[i] + a[j])
							num++;
					}
					else if (a[j] > a[i] && a[j] > a[k])
					{
						if (a[j] < a[i] + a[k])
							num++;
					}
					else
					{
						if (a[i] < a[j] + a[k])
							num++;
					}
				}
			}
		}
	}
	printf("%d", num);
	
	return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> arr(N);
  for(int& a : arr)
    cin >> a;
  long long res = 0;
  for(int i=0;i<N;++i){
    if(i>0&&arr[i-1]&&arr[i]){
      ++res;
      --arr[i];
      --arr[i-1];
    }
    res += arr[i] >> 1;
    arr[i] &= 1;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

static int func(int n){

    int ret = 0;

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

    return ret;
}

int main()
{
    int s,y;
    int a[1000001];
    scanf("%d", &s);

    for(int i = 1; i < 1000000; i++ ){

        if(i == 1){
            a[i] = s;
        }
        else{
            a[i] = func(a[i-1]);
        }
    }

    for(int i = 1; i < 1000001; i++){
        for(int t = i+1; t < 1000001; t++){
            if(a[i] == a[t]){
                printf("%d\n",t);
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 4096
#include<cstdio>
#include<cstring>
using namespace std;
char s[30];
int len;
bool b[30];
int main(void){
	register int i,j;
	scanf("%s",s+1),len=strlen(s+1);
	for(i=1;i<=len;++i)
		b[s[i]-'a']=1;
	for(i=0;i<26;++i)
		if(b[i]==0){
			printf("%s",s+1);
			putchar(i+'a');
			return 0;
		}
	for(i=len;i;--i){
		for(j=0;j<26;++j)
			if(b[j]==0&&j+'a'>s[i]){
				s[i]=j+'a',s[i+1]=0;
				puts(s+1);
				return 0;
			}
		b[s[i]-'a']=0;
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define debug(var) std::cout << #var << ": " << var << "\n"
using ll = long long;
using ull = unsigned long long;
ull mod = 1e9 + 7;
using namespace std;

ll func(int n){
  return n == 1 ? 1 : n * func(n - 1);
}

int main(){

  int N; cin >> N;
  vector<array<int, 2>> pos(N);

  vector<int> indexes(N);
  rep(i, N)indexes[i] = i;

  rep(i, N){
    cin >> pos[i][0] >> pos[i][1];
  }

  double ans = 0;

  //do{
//
  //  for(int i = 0; i < N - 1; i++){
  //    ans += sqrt(abs(pos[i][0] - pos[i + 1][0]) * abs(pos[i][0] - pos[i + 1][0]) + abs(pos[i][1] - pos[i + 1][1]) * abs(pos[i][1] - pos[i + 1][1]));
  //  }
//
  //}while(std::next_permutation(pos.begin(), pos.end()));

  do{

    for(int i = 0; i < N - 1; ++i){
      int fir = indexes[i], sec = indexes[i + 1];

      ans += sqrt(abs(pos[fir][0] - pos[sec][0]) * abs(pos[fir][0] - pos[sec][0]) + abs(pos[fir][1] - pos[sec][1]) * abs(pos[fir][1] - pos[sec][1]));

    }

  }while(std::next_permutation(indexes.begin(), indexes.end()));

  cout << setprecision(10) << ans / func(N);

}

Measured memory_bytes: 256
/*
* @Author: _dp95
* @Date:   2020-04-12 09:25:29
*/
#include "bits/stdc++.h"
using namespace std ;

#define timesaver ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll ;
typedef long double ldb ;

#define mp make_pair
#define pb push_back
#define F first
#define S second
#define nl '\n'

#define all( x ) x.begin(),x.end() 
#define sz( x ) ( int )( x ).size( )
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )

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

const int MAX = 2*1000*1000 + 10 ;
const ll INF = 1e18 ;
const int MOD = 1e9 + 7 ;

signed main( ){
  timesaver ;
  int a, b ;
  char x ;
  cin >> a >> x >> b ;
  if( x == '+' )
    cout << a+b << nl ;
  else
    cout << a-b << nl ;
}

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

const int Mod = 1e9 + 7;
#define N 406
#define M 200005

int n, a[N], X;
long long f[N][M];

inline bool cmp(int x, int y) { return x > y;}

int main() {
    cin >> n >> X;
    for (int i = 1; i <= n; ++i)
        scanf("%d", a + i);
    sort(a + 1, a + n + 1, cmp);
    f[0][X] = 1;
    for (int i = 1; i <= n; ++i)
        for (int j = 0; j <= 1e5; ++j)
            (f[i][j % a[i]] += f[i - 1][j]) %= Mod,
            (f[i][j] += f[i - 1][j] * (n - i) % Mod) %= Mod;
    long long ans = 0;
    for (int i = 0; i <= 1e5; ++i)
        (ans += f[n][i] * i % Mod) %= Mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 312064
N = int(input())

C = []
S = []
F = []

for i in range(N-1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)

ans = [0] * N

for i in range(N-1):
    cnt = i
    ans[i] += S[i] + C[i]
    while cnt<N-2:
        if ans[i]<S[cnt+1]:
            ans[i] = S[cnt+1]
        if ans[i]%F[cnt+1]!=0:
            ans[i] += F[cnt+1] - ans[i]%F[cnt+1]
        ans[i] += C[cnt+1]
        cnt += 1

for i in range(N):
    print(ans[i])

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
const int maxn = 2e5 + 5;
char s[maxn];

int main(){
    int n;
    cin >> n;
    cin >> s;
    int cnt = 0;
    // int w = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'W') ++cnt;
    }
    int t = cnt;
    // prln(cnt);
    for (int i = n - 1; t && i >= 0; --i, --t) {
        if (s[i] == 'W') --cnt;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3816
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 1e9 + 7;

vi num;
int dp[105][5][2],k;

int calc(int pos,int cnt,int f)
{
    if(pos==sz(num))
        return cnt==k;
    if(dp[pos][cnt][f]!=-1)
        return dp[pos][cnt][f];
    int ans=0,mx;
    if(!f)
        mx=num[pos];
    else
        mx=9;
    for(int d=0;d<=mx;d++)
    {
        int nf=f,ncnt=cnt;
        if(!f && d<mx)
            nf=1;
        if(d)
            ncnt++;
        if(ncnt<=k)
            ans+=calc(pos+1,ncnt,nf);
    }
    return dp[pos][cnt][f]=ans;
}

int solve(string s)
{
    for(int i=0;i<sz(s);i++)
    {
        num.pb(s[i]-'0');
    }
    fill(dp,-1);
    int ans=calc(0,0,0);
    return ans;
}

void solve()
{
    string s;
    cin>>s>>k;
    int ans=solve(s);
    cout<<ans<<endl;
}

signed main()
{
    fastio;
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	int n; ll k;
	cin >> n >> k;
	ll ma = 0;
	ll a[100000], b[100000];
	rep(i, n) {
		cin >> a[i] >> b[i];
		if (k == (k | a[i]))ma += b[i];
	}
	per(j, 31) {
		ll key = 1 << j;
		if (k&key) {
			ll sum = 0;
			rep(i, n) {
				if (a[i] == -1)continue;
				if (a[i] < key)sum += b[i];
			}
			ma = max(ma, sum);
			key--;
			rep(i, n) {
				a[i] &= key;
			}
		}
		else {
			rep(i, n) {
				if (a[i] == -1)continue;
				if (a[i] & key) {
					a[i] = -1;
				}
			}
		}
	}
	cout << ma << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define MOD(x) ((x)%mod)
long long n,m,k,a,b;
int cnt;
struct point
{
	int x,y;
	int col;
}p[400005];
int pos(point a)
{
	if(a.x==0&&a.y==0) return 1;
	if(a.x==0&&a.y==m) return 3;
	if(a.x==n&&a.y==m) return 5;
	if(a.x==n&&a.y==0) return 7;
	if(a.x==0) return 2;
	if(a.y==m) return 4;
	if(a.x==n) return 6;
	if(a.y==0) return 8;
}
bool cmp(point a,point b)
{
	int pa=pos(a),pb=pos(b);
	if(pa<pb) return 1;
	if(pa>pb) return 0;
	if(pa==2) return a.y<b.y;
	if(pa==4) return a.x<b.x;
	if(pa==6) return a.y>b.y;
	if(pa==8) return a.x>b.x;
	return 1;
}
int s[400005];
int h,t;
int in[400005];
int top;
int z[400005];
void check()
{
	for(int i=h;i<=t;i++)
	{
		if(in[s[i]])
		{
			if(z[top]!=s[i])
			{
				printf("NO");
				exit(0);
			}
			else top--;
			in[s[i]]=0;
		}
		else
		{
			z[++top]=s[i];
			in[s[i]]=1;
		}
	}
}
int main()
{
	scanf("%lld%lld%lld",&n,&m,&k);
	for(int i=1;i<=k;i++)
	{
		point a,b;
		scanf("%d%d%d%d",&a.x,&a.y,&b.x,&b.y);
		if((a.x==0||a.x==n||a.y==0||a.y==m)&&(b.x==0||b.x==n||b.y==0||b.y==m))
		{
			cnt++;
			p[cnt].x=a.x;
			p[cnt].y=a.y;
			p[cnt].col=i;
			cnt++;
			p[cnt].x=b.x;
			p[cnt].y=b.y;
			p[cnt].col=i;
		}
	}
	sort(p+1,p+1+cnt,cmp);
	for(int i=1;i<=cnt;i++)
		s[i]=p[i].col;
	for(int i=1;i<=cnt;i++)
		s[i+cnt]=p[i].col;
	for(int i=1;i<=cnt;i++)
	{
		if(s[i]==s[i+cnt-1])
		{
			h=i; t=i+cnt-1;
			check();
			printf("YES");
			return 0;
		}
	}
	printf("NO");
	return 0;
}

Measured memory_bytes: 7040
import java.util.Scanner;

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

		int n1 = scan.nextInt();
		String op = scan.next();
		int n2 = scan.nextInt();

		if(op.equals("+")) {
			System.out.println(n1 + n2);
		} else {
			System.out.println(n1 - n2);
		}
	}
}


Measured memory_bytes: 21844
#include <stdio.h>

//2つの整数a,bの小さい/大きい/等しいを判断して出力する
int main(void){
    int a = 0, b = 0;

    scanf("%d %d",&a, &b);
    
    //問題で定義された範囲外の場合入力エラー
    if(a < -1000 || a > 1000 || b < -1000 || b > 1000)
    {
        printf("Input Error");
        return 0;
    }

    if(a < b){          
        printf("a < b\n");
    }
    else if(a > b){
        printf("a > b\n");
    }
    else{
        printf("a == b\n");
    }

    return 0;
}


Measured memory_bytes: 2036
#include <iostream>

using namespace std;

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

    int l = a + b;
    int r = c + d;
    if (r == l)
        cout << "Balanced\n";
    if (r < l)
        cout << "Left\n";
    if (l < r)
        cout << "Right\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int A,B,C,D;
  cin >> A >> B >> C >> D;
  int mtime;
  mtime = max(A / D, C / B);
  int TA = A, AO = C;
  
	for(int i = 0; i < mtime+1; i++){
    	AO -= B;
      if(AO <= 0){
      	cout << "Yes" << endl;
        break;
      }
      	TA -= D;
      if(TA <= 0){
      	cout << "No" << endl;
        break;
      }
    }
}

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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int a[200100];
int f[200100];
int N;
long long K;

bool solve(long long x){
    long long tmp=0;
    for(int i=0;i<N;i++){
        long long res=a[i]-x/f[i];
        if(res<0) continue;
        tmp+=res;
    }
    if(tmp<=K) return true;
    else return false;
}

int main(){
    cin >> N >> K;
    for(int i=0;i<N;i++) cin >> a[i];
    for(int i=0;i<N;i++) cin >> f[i];
    sort(a,a+N);
    sort(f,f+N,greater<int>());
    long long left=0;
    long long right=1e18;
    for(int i=0;i<150;i++){
        long long mid=(right+left)/2;
        if(solve(mid)){
            right=mid;
        }else{
            left=mid;
        }
    }
    cout << right << endl;
}


Measured memory_bytes: 1920
from itertools import*
n=int(input())
a=[input().split()for _ in[0]*n]
for b in a:
 b[3:5]=b[4],b[3]
def g():
 for d,e in combinations(a,2):
  for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):
   f=[d[i]for i in p]
   if f[0::5]==e[0::5]:
    f=f[1:5]*2
    for k in range(4):
     if f[k:k+4]==e[1:5]:return'No'
 return'Yes'
print(g())


Measured memory_bytes: 5656
n = int(input())
nn = n
f = lambda x, y: x + y * nn
g = lambda x: x if x % 2 == 1 else x + nn

# 2の累乗はむり
b = bin(n)
if b.count('0') == len(b) - 2:
    print('No')
    exit(0)

ret = [
    [f(1, 0), f(2, 0)],
    [f(2, 0), f(3, 0)],
    [f(3, 0), f(1, 1)],
    [f(1, 1), f(2, 1)],
    [f(2, 1), f(3, 1)],
]

if n % 2 == 0:
    p = 2 ** (len(b) - 3)
    q = n ^ 1 ^ p
    ret.append([g(p), f(n, 0)])
    ret.append([g(q), f(n, 1)])
    n -= 1

# nは奇数
while n > 3:
    ret.append([f(n - 1, 0), f(n, 0)])
    ret.append([f(n, 0), f(1, 1)])
    ret.append([f(1, 1), f(n - 1, 1)])
    ret.append([f(n - 1, 1), f(n, 1)])
    n -= 2

print('Yes')
for x, y in ret:
    # x = x if x <= nn else x - nn
    # y = y if y <= nn else y - nn
    print(x, y)


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

int getnum() {
  char C;
  while(!isdigit(C = getchar()));
  int n = C - '0';
  while(isdigit(C = getchar())) n = n * 10 + C - '0';
  return n;
}

int main() {
  int N = getnum();
  string S;
  map<string,int> ans{};
  for (int i = 0; i < N; i++) {
    cin >> S;
    ans[S] += 1;
  }
  N = getnum();
  for (int i = 0; i < N; i++) {
    cin >> S;
    ans[S] -= 1;
  }
  int maxans = 0;
  for(auto itr = ans.begin(); itr != ans.end(); ++itr) maxans = max(maxans, ans[itr->first]);
  printf("%d\n", maxans);
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define N 101
#define INFTY 1LL << 32
#define ll long long

using namespace std;

ll dp[N][N];

void floyd (int n) {
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      if (dp[i][k] == INFTY)
        continue;
      for (int j = 0; j < n; j++) {
        if (dp[k][j] == INFTY)
          continue;
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
}

void print (int n) {
  for (int i = 0; i < n; i++) {
    if (dp[i][i] < 0) {
      cout << "NEGATIVE CYCLE" << endl;
      return;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (dp[i][j] == INFTY)
        cout << "INF";
      else
        cout << dp[i][j];
      
      if (j < n - 1)
        cout << " ";
    }
    cout << endl;
  }
}

int main () {
  int n, e, a, b, c;

  cin >> n >> e;

  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      dp[i][j] = (i == j ? 0 : INFTY);

  for (int i = 0; i < e; i++) {
    cin >> a >> b >> c;
    dp[a][b] = c;
  }

  floyd(n);
  print(n);

  return 0;
}


Measured memory_bytes: 3164
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC136D
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            S += "R";
            int L = S.Length;
            Queue<int> henka = new Queue<int>();
            for(int i = 0; i < L - 1; i++)
            {
                if (S[i] != S[i + 1])
                {
                    henka.Enqueue(i + 1);
                }
            }
            //Console.WriteLine(string.Join(" ", henka));
            L -= 1;
            int[] ans = new int[L];
            int j = 0;
            while (henka.Count > 0)
            {
                if (henka.Count % 2 == 0)
                {
                    int h = henka.Dequeue();
                    while (j <= h)
                    {
                        if ((h - j) % 2 != 0)
                        {
                            ans[h - 1] += 1;
                        }
                        else
                        {
                            ans[h] += 1;
                        }
                        j += 1;
                    }
                }
                else
                {
                    int h = henka.Dequeue();
                    int l = j-1;
                    while (j <= h-1) 
                    {
                        if ((j - l) % 2 != 0)
                        {
                            ans[l - 1] += 1;
                        }
                        else
                        {
                            ans[l] += 1;
                        }
                        j += 1;
                    }
                }
            }
            Console.WriteLine(string.Join(" ", ans));
        }
    }
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n,a,b,c;
    n = 0;
    cin >> n;
    deque<long> que;
    for(int i = 0;i < n;++i){
        cin >> a;
        switch(a){
                // insert
            case 0:
                cin >> b >> c;
                if(b == 0){
                    que.insert(que.begin(), c);
                }else{
                    que.insert(que.end(), c);
                }
                break;
                // random access
            case 1:
                cin >> b;
                cout << que.at(b) << endl;
                break;
                // pop
            case 2:
                cin >> b;
                if(b == 0){
                    que.pop_front();
                }
                else{
                    que.pop_back();
                }
                break;
        }
    }
}



Measured memory_bytes: 6200
import sys
import itertools

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

N = INT()
D = LIST()
sumv = 0
for i in itertools.combinations(D, 2):
    sumv += i[0] * i[1]
print(sumv)


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

int main() {
  string S;

  cin >> S;

  if ((S.substr(2,1) == S.substr(3,1)) && (S.substr(4,1) == S.substr(5,1))){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 998244353
#define MAX 100000
#define N 105
int h,w;
string s[N];
int dp[N][N][3];
int solve(int i,int j,int o)
{
    if(i==h-1 && j==w-1)
    {
        if(s[i][j]=='#' && o==0) return 1;
        else return 0;
    }
    if(dp[i][j][o]!=-1) return dp[i][j][o];
    int ans1=MAX;
    int ans2=MAX;
    int ans=0;
    if(s[i][j]=='#' && o==0)
    {
        ans++;
        if(i+1<h) ans1=solve(i+1,j,1);
        if(j+1<w) ans2=solve(i,j+1,1);
        return dp[i][j][o]=ans+min(ans1,ans2);

    }
    if(s[i][j]=='#' && o==1)
    {
        if(i+1<h) ans1=solve(i+1,j,1);
        if(j+1<w) ans2=solve(i,j+1,1);
        return dp[i][j][o]=ans+min(ans1,ans2);

    }
    else if(s[i][j]=='.'){
        if(i+1<h) ans1=solve(i+1,j,0);
        if(j+1<w) ans2=solve(i,j+1,0);
        return dp[i][j][o]=ans+min(ans1,ans2);
    }

}
int main()
{
    fastio;
    cin>>h>>w;
    for(int i=0;i<h;i++) cin>>s[i];
    memset(dp,-1,sizeof dp);
    cout<<solve(0,0,0)<<endl;
}
/*
4 4
..##
...#
..##
####
*/


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>

using namespace std;

int main(){
  int N;
  cin >> N;
  int s = N+1;
  if(N%2==1) s = N;
  vector<pair<int,int>> ans;
  for(int i=1; i<=N; i++){
     for(int j=i+1; j<=N; j++){
        if(i+j!=s) ans.push_back(make_pair(i,j));
     }
  }
  cout << ans.size()<<endl;
  for(int i=0; i< (int)ans.size(); i++){
     cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }


// Returns g=gcd(a,b), and x and y store values with ax+by=g
typedef long long ll;
ll euclid(ll a, ll b, ll &x, ll &y){
	if(b){
		ll d = euclid(b, a % b, y, x);
		return y -= a / b * x, d;
	}
	return x = 1, y = 0, a;
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(ios::badbit | ios::failbit);
	long long n;
	cin >> n, n <<= 1;
	long long res = numeric_limits<long long>::max();
	for(auto d = 1LL; d * d <= n; ++ d){
		if(n % d == 0){
			long long e = n / d, x, y;
			for(auto rep = 0; rep < 2; ++ rep){
				if(euclid(d, e, x, y) == 1){
					if(x >= 0){
						x -= (x / e + 1) * e;
					}
					ctmin(res, -x * d);
				}
				swap(d, e);
			}
		}
	}
	cout << res << "\n";
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 3588
MOD = 10**9+7
n = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))
n_cases = [0]*n
n_cases[0] = n_cases[-1] = 1
height = [0]*n
if T[-1] != A[0]:
    print(0)
    exit()
height[0] = T[0]
height[-1] = A[-1]
for i, (t1, t2) in enumerate(zip(T, T[1:]), 1):
    if t1 != t2:
        n_cases[i] = 1
        height[i] = t2

for i, (a1, a2) in enumerate(zip(A[::-1], A[::-1][1:]), 2):
    if a1 != a2:
        n_cases[-i] = 1
        if height[-i] == a2 or (height[-i] == 0 and a2 <= T[-i]):
            continue
        print(0)
        exit()

for i, (t, a) in enumerate(zip(T, A)):
    if n_cases[i]:
        continue
    n_cases[i] = min(t, a)


ans = 1
for x in n_cases:
    ans *= x
    ans %= MOD
print(ans)

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

int arr[128];
int main() {
  string s; cin >> s;
  for (char c : s) arr[c]++;
  for (int i = 0; i < 128; i++)
    if (arr[i] != 0 && arr[i] != 2) {
      cout << "No" << endl;
      return 0;
    }
  cout << "Yes" << endl;
}

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

x = []
y = []

for i in range(m):
    array = list(map(int, input().split()))
    x.append(array[0])
    y.append(array[1])

a = max(x[:])
b = min(y[:])

print(len(list(range(a, b+1))))


Measured memory_bytes: 12660
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] strs = br.readLine().split(" ");
		int h = Integer.parseInt(strs[0]);
		int w = Integer.parseInt(strs[1]);
		
		for(int i = 0 ; i < w+2 ; i++){
			System.out.print("#");
		}
		System.out.println();
		
		for(int i = 0 ; i < h ; i++){
			System.out.print("#");
			System.out.print(br.readLine());
			System.out.println("#");
		}
		for(int i = 0 ; i < w+2 ; i++){
			System.out.print("#");
		}
	}
}


Measured memory_bytes: 23892
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
using namespace std;


int main ()
{

int a,b,c,d,e,k;
cin >> a >> b >> c >> d >> e >> k;

if(b-a<=k && c-a<=k && d-a<=k && e-a<=k && c-b<=k && d-b<=k && e-b<=k && d-c<=k && e-c<=k && e-d <=k )
{
	cout << "Yay!" << endl;
}
else
{
	cout << ":(" << endl;
}
	return 0;
}











Measured memory_bytes: 3100
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;


namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Read();
        }

        public void Solve(ConsoleInput cin)
        {
            var D = cin.ReadInt;
            var N = cin.ReadInt;

            //var 
            //            string[] N;

            //          N = Console.ReadLine().Split;

//            int A, B;
  //          A = int.Parse(N[0]);
    ///        B = int.Parse(N[1]);

            double result  ;
            if (N == 100)
            {
                result = Math.Pow(100, D) * 101;
            }
            else
            {
                result = Math.Pow(100, D) * N;
            }

            //if (A <= 8 && B <= 8) { result = "Yay!"; }
            //else { result = ":("; }

            Console.WriteLine(result);
            Console.Read();

        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        ///
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 11220
#ifdef loc
    #include "codes/loc_debug.h"
#else
    #include <bits/stdc++.h>
    #define pr(...)
    #define pra(a,n)
    #define praa(a,n,m)
    #define prl()
#endif
using namespace std;

typedef long long ll;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define sz(a) int(a.size())
const int N = 100005;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    map<char, int> a;
    for(auto it : s) {
        a[it]++;
    }
    if(a.size() == 2 && a[s[0]] == 2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

using namespace std;


const int N = 100100;
#define ll long long
#define fr(i,a,n) for (int i=a;i<n;i++)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vipb(v) int x;cin>>x;v.pb(x);
#define vllpb(v) ll x;cin>>x;v.pb(x);
#define in(x) cin>>x;
#define in2(x,y) cin >> x >> y;
#define in3(x,y,z) cin>>x>>y>>z;
#define in4(a,x,y,z) cin>>a>>x>>y>>z;
#define in5(a,b,x,y,z) cin>>a>>b>>x>>y>>z;


typedef vector<int> VI;
typedef vector<ll> VL;


string s;
ll n, m, k;

int main() {
	cin >> n;
	VI v(n+1);
	fr(i, 0, n)
		cin >> v[i];
	int ans = 1e9;
	fr(i, 1, 101) {
		int subans = 0;
		fr(j, 0, n) {
			subans += abs(v[j] - i) * abs(v[j] - i);
		}
		ans = min(ans, subans);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

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

    ll ans[n+10];
    for(ll i=0;i<n+1; i++){
        ans[i] = 0;
    }


    for(ll i=1;i<n; i++){
        ll tmp;
        cin >>tmp;
        ans[tmp]++;
    }

    for(ll i=1;i<n+1; i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 5196
n = gets.to_i
v = gets.split.map(&:to_i)
e = Hash.new(0)
o = Hash.new(0)

v.each_with_index do |i, idx|
  idx.even? ? e[i] += 1 : o[i] += 1
end

e = e.max_by(2) { |k, v| v }
o = o.max_by(2) { |k, v| v }

if e[0][0] == o[0][0]
  e[1] ||= [nil, 0]
  o[1] ||= [nil, 0]
  puts e[1][1] > o[1][1] ? n - e[1][1] - o[0][1] : n - e[0][1] - o[1][1]
else
  puts n - e[0][1] - o[0][1]
end


Measured memory_bytes: 17172
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> lr(m+1, make_pair(0, 0));
    for(int i = 1; i < m+1; i++) {
        cin >> lr[i].first >> lr[i].second;
    }

    int r, l;
    r = lr[1].first;
    l = lr[1].second;
    for(int i = 2; i < m+1; i++) {
        r = max(lr[i].first, r);
        l = min(lr[i].second, l);

    }

    if(l-r < 0) {
        cout << 0 << endl;
    }
    else if(l-r == 0) {
        cout << 1 << endl;
    }
    else {
        cout << l-r+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define whole(x) (x).begin(), (x).end()
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
 
const int N = int(2e5) + 2;
const int LG = 20;
const ll mod = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const ll linf = 1e18; 
const ld pi = acos(-1);
const int base = 10;
const ld EPS = 1e-9;

int n;
map < string, ll > cnt;
int main (){
    cin >> n;
    for (int i = 1; i <= n; ++i){
        string s;
        cin >> s;
        sort (whole(s));
        cnt[s]++;
    }
    ll ans = 0;
    for (auto to : cnt) ans += ((to.se * 1ll * (to.se - 1)) / 2);
    return !printf ("%lld\n", ans);
}

Measured memory_bytes: 11136
#include <cstdio>
#include <cstring>
char s[100005];
int main()
{
 int ans=0;
 scanf("%s",s);
 int len=strlen(s);
 for(int i=0;i<len;i++)
  s[i]-='0';
 for(int i=0;i<len-1;i++)
  if(s[i]==s[i+1])
  {
   s[i+1]=!s[i+1];
   ans++;
  }
 printf("%d\n",ans);
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ENDL '\n'
#define sz(a) (int)(a.size())
#define all(a) begin(a), end(a)
#define deb(a) cout << #a << ": " << a << ENDL
#define fore(i, a, b) for(int i(a), ThkMk(b); i < ThkMk; ++i)
#define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli> ii;
typedef vector<lli> vi;

const int MAX = 2005;

lli dp[MAX];

lli n;

lli MOD = 1e9 + 7;

lli solve(lli v) {
    if(v < 0) return 0;
    if(v == 0) return 1;
    lli &ans = dp[v];
    if(ans != -1) return ans;
    ans = 0;
    fore(i, 3, v + 1) ans = (ans + solve(v - i)) % MOD;
    return ans;
}

int main()
{   _
    fore(j, 0, MAX) dp[j] = -1;
    cin >> n;
    cout << solve(n) << ENDL;
    return 0;
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  long double a,b,c;
  cin >> a >> b >> c;
  if(a + 2*sqrt(a)*sqrt(b)+b < c)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3736
# -*- coding: utf-8 -*-
def main():
    N,K = map(int,input().split())
    ans = 0
    for i in range(1,N+1):
        n = 0
        while i < K:i*=2;n+=1
        ans += ((1/N)*(1/2)**n)
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 2940