akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(){
char S[4]={};
  int m=0;
  for(int i=0;i<4;i++){
    cin >> S[i];
  }
  for(int i=0;i<4;i++){
    if(S[i]=='+'){
      m++;
    }
    else{
      m--;
    }
    
  }
  cout<< m << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <numeric> // next_parmutation
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); i++)

using namespace std;

int main() {

 int ll N;
 cin >> N;
 ll a=0, b=0, c=0, d=0;
 string str;
 rep(i, N){
     cin >> str;
     if(str == "AC") a++;
     if(str == "WA") b++;
     if(str == "TLE") c++;
     if(str == "RE") d++;

 }

 cout << "AC x " << a << endl;
 cout << "WA x " << b << endl;
 cout << "TLE x " << c << endl;
 cout << "RE x " << d << endl;

}

Measured memory_bytes: 3628
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 100010
using namespace std;
char s[N];int t[N];
inline int gabs(int x)
{
	return x>0?x:-x;
}
int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1),m=0;
	for(int i=1;i<=n;i++)
		if(s[i]^'x') t[++m]=i;
	for(int i=1;i<=m;i++)
		if(s[t[i]]^s[t[m-i+1]])
			return !printf("-1\n");
	int ans=0;t[0]=0,t[m+1]=n+1;
	for(int i=1;i<=(m-1)/2+1;i++)
		ans+=gabs(t[m-i+2]+t[i-1]-t[m-i+1]-t[i]);
	printf("%d\n",ans);return 0;
}

Measured memory_bytes: 768
//2022022022
#include <iostream>
#include <string>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n;
int a[1000000];
int b[1000000];

signed main() {
	int i;
	
	cin >> n;
	string s; cin >> s;
	rep(i, n) {
		a[i] = s[i] - '0';
		a[i]--;
	}
	
	rep(i, n) {
		b[i] = a[i] % 2;
	}
	
	int hoge = 0;
	rep(i, n) {
		if (((n - 1) & i) == i) { hoge ^= b[i]; }
	}
	if (hoge == 1) { cout << 1 << endl; return 0; }
	
	rep(i, n) { if (a[i] == 1) break; }
	if (i < n) { cout << 0 << endl; return 0; }
	
	rep(i, n) {
		b[i] = a[i];
	}
	hoge = 0;
	rep(i, n) {
		if (((n - 1) & i) == i) { hoge ^= b[i]; }
	}
	cout << hoge << endl;
	return 0;
}

Measured memory_bytes: 17028
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 100010


int main(){
	IOS;
	ll n,m;cin>>n>>m;
	vll v[m];
	rep(i,0,m){
		ll k;cin>>k;
		rep(j,0,k){ll x;cin>>x;x--;v[i].pb(x);}
	}
	ll ans=0;
	ll p[m];rep(i,0,m)cin>>p[i];
	for(ll i=0;i<(1<<n);++i){
		ll a[n];
		rep(j,0,n) a[j]= bool(i&(1<<j));
		bool ok=1;
		rep(j,0,m){
			ll val=0;
			rep(k,0,sz(v[j]))if(a[v[j][k]])val++;
			if((val%2)!=p[j])ok=0;
		}
		if(ok)ans++;
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <string>
#include <climits>
using namespace std;

#define MAX_N  100000
#define MAX_M  100000
#define MAX_Q  10000

int n, m, q, k, kind[MAX_N] = {};
queue<int> Q;

void bf(vector<vector<int> >& sns, int s)
{
    Q.push(s);
    while (!Q.empty()) {
        s = Q.front();
        Q.pop();
        kind[s] = k;
        for (int i = 0; i < sns[s].size(); i++) {
            if (!kind[sns[s][i]]) Q.push(sns[s][i]);
        }
    }
}

int main()
{
    cin >> n >> m;
    vector<vector<int> > sns(n);
    int s, d;
    while (m--) {
        cin >> s >> d;
        sns.at(s).push_back(d);
        sns.at(d).push_back(s);
    }
    k = 0;
    for (int s = 0; s < n; s++) {
        if (!kind[s]) {
            k++;
            bf(sns, s);
        }
    }
    cin >> q;
    while (q--) {
        cin >> s >> d;
        cout << (kind[s] == kind[d] ? "yes" : "no") << endl;
    }
    return 0;
}

Measured memory_bytes: 8836
#累積和で毎回sumしない
N=int(input())
A=sorted(map(int,input().split()))
b=0
c=0
for n in range(N-1):
  b += A[n]
  if b*2 >= A[n+1]:
    c+=1
  else:
    c=0
print(c+1)

Measured memory_bytes: 14320
N = int(input())
A = list(map(int, input().split()))
if min(A) == 0:
  ans = 0
  print(ans)
  quit()

ans = 1
for i in range(N):
  ans = ans * A[i]
  if ans > 10 ** 18:
    print("-1")
    quit()
  
if ans > 10 ** 18:
  print("-1")
  quit()

print(ans)
  


Measured memory_bytes: 21476
import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;
 
void main() {
    const x = [6000, 4000, 3000, 2000];
    int v[4];
    foreach (i; 0 .. 4) {
        int t, n; readf("%d %d\n", &t, &n);
        writeln(n * x[--t]);
    }
}

Measured memory_bytes: 1060
#include <iostream>

using namespace std;

int main(){
  string S,T;
  int min_change(0);
  int change(0);
  cin >> S >> T;
  
  min_change = T.size();
  for (int i= 0; i < S.size() - T.size() + 1 ; ++i)
  {
    change = 0;
  	for(int j = 0; j < T.size() ; ++j)
    {
      if (S[i + j] != T[j]) 
      	change++;
    }
    if (change < min_change)
      	min_change = change;
  }
  cout << min_change << endl;
  
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (a) - 1; (i) >= (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    rep1(i, k)r = r * n-- / i;
    return r;
}

int main(){
    ll h,w;
    cin >> h >> w;
    string s[h];
    ll c1[h][w],c2[h][w];
    rep0(i, h)cin >> s[i];
    rep0(i, h){
        ll cnt = 0;
        rep0(j, w){
            if(s[i][j] == '.'){
                ++cnt;
                if(j == w - 1){
                    rep0(k, cnt){
                        c1[i][j - k] = cnt;
                    }
                }
            }else{
                c1[i][j] = 0;
                rep1(k, cnt){
                    c1[i][j - k] = cnt;
                }
                cnt = 0;
            }
        }
    }
    
    rep0(i, w){
        ll cnt = 0;
        rep0(j, h){
            if(s[j][i] == '.'){
                ++cnt;
                if(j == h - 1){
                    rep0(k, cnt){
                        c2[j - k][i] = cnt;
                    }
                }
            }else{
                c2[j][i] = 0;
                rep1(k, cnt){
                    c2[j - k][i] = cnt;
                }
                cnt = 0;
            }
        }
    }
    ll ans = 0;
    rep0(i, h)rep0(j, w)ans = max(c1[i][j] + c2[i][j] - 1,ans);
    pf(ans);
    return 0;
}


Measured memory_bytes: 66816
// 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;
}

bool get_rucus(int n, int r);

i64 solve(long long n, std::vector<long long> a, bool pri = false){
    auto ori = a;
    int per = 1;
    if(count(a.begin(), a.end(), 1) == 0){
        per = 2;
        for(int i = 0; i < n; ++i)
            if(a[i] == 2)
                a[i] = 1;
    }
    for(int i = 0; i < n; ++i){
        if(a[i] == 2)
            a[i] = 0;
    }
    int sum = 0;
    for(int i = 0; i < n; ++i)
        sum += a[i] * get_rucus(n - 1, i);

    /*
    if(pri){
        for(int i = 0; i < n; ++i)
            cout << a[i] << " ";
        cout << "\n";
    }

    int cnt = 0;
    for(int i = 0; i < n - 1; ++i){
        vector<i64> b(a.size() - 1);
        for(int j = 0; j < b.size(); ++j){
            b[j] = abs(a[j] - a[j + 1]);
            cnt += (b[j] == 0);
        }
        a = move(b);
        if(pri){
            for(int i = 0; i < a.size(); ++i)
                cout << a[i] << " ";
            cout << "\n";
        }
    }
    */
    cout << ((sum % 2) * per) << endl;
    // assert((sum % 2) * per == a.back());
    // return a.back();
    return 0;
}


map<pair<int,int>, int> fls;

bool get_rucus(int n, int r){
    if(fls.find(make_pair(n, r)) != fls.end())
        return fls[make_pair(n, r)];
    for(int i = 0; i < 30; ++i)
        if(!(n & (1 << i)) && (r & (1 << i)))
            return fls[make_pair(n, r)] = false;
    return fls[make_pair(n, r)] = true;
}


signed main(){
    long long N;
    scanf("%lld",&N);

    /*
    for(int N = 10; N <= 20; ++N){
        int th = 1;
        for(int j = 0; j < N; ++j)
            th *= 3;
        for(int j = 0; j < th; ++j){
            vector<i64> arr(N);
            int tmp = j;
            for(int k = 0; k < N; ++k){
                arr[k] = tmp % 3;
                tmp /= 3;
            }
            i64 res_1 = solve(N, arr, true);

            // asssert(res_1 )
            int sum = 0;
            for(int i = 0; i < N; ++i)
                sum += arr[i] * get_rucus(N - 1, i);

            // assert(res_1 == (arr[0] ^ !(N % 2)));
            cout << res_1 << ": ";
            cout << sum % 2 << ": ";
            for(int i = 0; i < N; ++i)
                cout << arr[i] << " \n"[i == N - 1];
            if(res_1 != (sum % 2)){
                cout << N << endl;
                exit(0);
            }
        }
    }
     */

    std::vector<long long> a;
    string s;
    cin >> s;
    for(int i = 0; i < N; ++i)
        a.emplace_back(s[i] - '1');
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 79604
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();
        int tmp;
        tmp = x;
        x = y;
        y = tmp;
        tmp = x;
        x = z;
        z = tmp;
        System.out.println(x+" "+y+" "+z);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int a[200005],b[200005];
int main(void){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    int m=b[n/2-1],M=b[n/2];
    //cout<<m<<" "<<M<<endl;
    for(int i=0;i<n;i++){
        if(a[i]<=m){
            cout<<M<<endl;
        }else{
            cout<<m<<endl;
            //cout<<"A"<<endl;
        }
    }
    
}


Measured memory_bytes: 3712
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;
const int N=1e5+5;
int n;
char str[N];

namespace utils{
	template <class T> inline void apn(T &x,const T y){x>y?x=y:0;}
	template <class T> inline void apx(T &x,const T y){x<y?x=y:0;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	scanf("%s",str+1);
	n=strlen(str+1);
	puts((str[1]==str[n])^(n&1)?"First":"Second");
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while(a>0 || c>0)
    {
        c=c-b;
        a=a-d;

        if(c<=0)
        {
            cout<<"Yes"<<endl;
            break;
        }
        else if(a<=0)
        {
            cout<<"No"<<endl;
            break;
        }
    }
}


Measured memory_bytes: 3556
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(ll i=(x);i<(y);i++)
#define RREP(i,x,y) for(ll i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

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

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class ECrestedIbisVsMonster {
public:
    void solve(std::istream& in, std::ostream& out) {
        int H, N;
        in >> H >> N;
        vector<int> A(N), B(N);
        REP(i,0,N) in >> A[i] >> B[i];

        vector<ll> dp(1e7+1, INT_MAX);
        ll answer = INT_MAX;
        dp[0] = 0;
        REP(hp,0,H+1e4+1) {
            if (dp[hp] == INT_MAX) continue;
            if (hp >= H) answer = min(answer, dp[hp]);
            REP(i,0,N) {
                dp[hp+A[i]] = min(dp[hp+A[i]], dp[hp] + B[i]);
            }
        }
        out << answer << "\n";
    }
};


signed main() {
    ECrestedIbisVsMonster solver;
    std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 78336
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    ll X;
    cin >> X;

    ll balance = 100;
    ll years = 0;
    while (balance < X) {
        years++;
        balance += balance / 100;
    }

    cout << years << endl;

    return 0;
}


Measured memory_bytes: 3576
N = int(input())
S = input()
R = 0
G = 0
B = 0
notToAllow = 0


for i in range(0,N):
    if S[i] == "R":
        R = R + 1
    elif S[i] == "G":
        G = G + 1
    else:
        B = B + 1

total = R*G*B

for i in range(0,N):
    for j in range(0,(N//2)+1):
        if(j+j+i < N):
            if ((S[i] != S[i+j])):
                if(S[i] != S[i+j+j]):
                    if(S[i+j] != S[i+j+j]):
                        notToAllow = notToAllow + 1

print(R*G*B - notToAllow)


Measured memory_bytes: 73572
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;

int main(void){
  int K,X;
  cin >> K >> X;
  for(int i = X-K+1;i < X+K;i++){
    cout << i << ' ';
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
int n;ll a[N],sum,cnt;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%lld",&a[i]),sum+=a[i];
	a[n+1]=a[1];
	cnt=1ll*n*(n+1)/2;
	if (sum%cnt) return puts("NO"),0;
	cnt=sum/cnt;
	for (int i=1;i<=n;i++) a[i]=a[i+1]-a[i];
	for (int i=1;i<=n;i++) a[i]-=cnt;
	for (int i=1;i<=n;i++)
		if (a[i]>0||a[i]%n) return puts("NO"),0;
	puts("YES");
	return 0;
}

Measured memory_bytes: 1024
#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;}

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

int Rank(int x) {
    int rank = 0;
    while(x > 0){
        rank++;
        x = x/10;
    }
    
    return rank;
}


int main(int argc, const char * argv[]) {
    
 
    
    ll n; cin >> n;
    
    vector<ll> H(n);
    vector<ll> copyH(n);
    
    for (int i = 0; i < n; i++) {
        cin >> H[i];
        copyH[i] = H[i];
    }
    
    for (int i = 1; i < n; i++) {
        if( H[i-1] < H[i] ) H[i]--;
    }
    
    bool isAns = true;
    
    for (int i = 1; i < n; i++) {
        if( H[i-1] > H[i]) isAns = false;
    }
    
    if(isAns) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    
    
    
}


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

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

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;


const int SIZE = 1e5+100;
string s,t;
string ans;

int main(){
    cin >> s >> t;

    int ff = 0;
    for(int i = 0; i < s.length(); i++){
        int f = 0;
        for(int j = 0; j < t.length(); j++){
            if(i+j >= s.length()){
                f = 1;
                break;
            }
            if(s[i+j] == '?' || t[j] == s[i+j]){

            }
            else{
                f = 1;
                break;
            }
        }
        if(f == 0){
            ff = 1;
            ans = s;
            for(int j = 0; j < s.length(); j++){
                if(ans[j] == '?') ans[j] = 'a'; 
            }
            for(int j = 0; j < t.length(); j++){
                ans[i+j] = t[j];
            }
        }
    }

    if(ff == 1){
        cout << ans << endl;
    }
    else{
        cout << "UNRESTORABLE\n";
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int i;
  int n;
  unsigned long long num[86] = {2,1};

  scanf("%d",&n);

  for (i = 2; i < n + 1; i++) {
    num[i] = num[i - 1] + num[i - 2];
  }

  printf("%lld\n",num[n]);

  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 10000000

int min(int a, int b) {
	return a < b ? a : b;
}

int min_cost(int *height, int n, int i, int *dp) {
	if (i == n-1) return 0;
	if (dp[i] != -1) return dp[i];

	if (i+1 >= n) {
		dp[i] = min_cost(height, n, i, dp);
		return dp[i];
	}

	if (i+2 >= n) {
		dp[i] = abs(height[i] - height[i+1]) + min_cost(height, n, i+1, dp);
		return dp[i];
	}

	int one_step = abs(height[i] - height[i+1]) + min_cost(height, n, i+1, dp);
	int two_step = abs(height[i] - height[i+2]) + min_cost(height, n, i+2, dp);
	dp[i] = min(one_step, two_step);
	return dp[i];
}

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

	int height[n], dp[n];
	memset(dp, -1, n*sizeof(int));
	for (i = 0; i < n; i++) scanf("%d", &height[i]);

	printf("%d\n", min_cost(height, n, 0, dp));
	return 0;
}

Measured memory_bytes: 8704
from math import gcd, ceil


def lcm(a, b):
    return (a*b)//gcd(a, b)


n, m = map(int, input().split())
a = list(map(int, input().split()))

for i in range(n):
    a[i] = a[i]//2

lcm_v = a[0]
for i in range(1, n):
    lcm_v = lcm(lcm_v, a[i])

ok = True
for aa in a:
    if (lcm_v//aa) % 2 != 1:
        ok = False
        break
ans = 0
if ok:
    ans = ((m//lcm_v)+1)//2
print(ans)


Measured memory_bytes: 20232
// fahadmd16(IIEST Shibpur)
#include<bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#define ll long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define db double
#define pll pair<ll, ll>
#define ALL(a) (a).begin(),(a).end()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define forn(i, n) for (ll i = 0; i < n; i++)
#define forn1(i, n) for (ll i = 1; i < n; i++)
#define forab(i,a,b) for(ll i=a;i<b;i++)
#define clr(x) memset(x, 0, sizeof(x))
#define count_bit(x) __builtin_popcount(x)
#define endl "\n"
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace(v) for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define eps 1e-10
#define nedl endl
const ll sz = 1e6;
const ll mod = 1e9+7;
typedef vector<ll> VL;
typedef vector<pll > VLL;
typedef vector<vector<ll> > VVL;
 
ll power(ll n,ll k,ll m){
    ll ans=1;
    while(k){
        if(k&1)ans=(ans*n)%m;
        k/=2;
        n=(n*n)%m;
    }
    return ans;
}



int main() {
    IOS;
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    ll T=1;//cin>>T;
    
    while(T--){
        ll n,x,y;cin>>n>>x>>y;
        VVL adj(n);

        forn1(i,n){
            adj[i].pb(i-1);
            adj[i-1].pb(i);
        }
        adj[x-1].pb(y-1);
        adj[y-1].pb(x-1);
        ll ans[n]={0};
        forn(i,n){
            queue<ll> q;
            bool vis[n]={0};
            ll disTo[n]={0};
            q.push(i);
            vis[i]=1;
            disTo[i]=0;
            while(!q.empty()){
                ll v=q.front();
                q.pop();
                for(auto w:adj[v]){
                    if(!vis[w]){
                        vis[w]=1;
                        q.push(w);
                        disTo[w]=disTo[v]+1;
                    }
                } 
            }
            forn(i,n){
                ans[disTo[i]]++;
            }
        }
        forn1(i,n)cout<<ans[i]/2<<endl;

    }
    return 0;
}


Measured memory_bytes: 384
import numpy as np
import sys

n,k=map(int,sys.stdin.readline().split())
a=np.array(sys.stdin.readline().split(),dtype=np.int64)

a.sort()
neg=a[a<0]
zero=a[a==0]
pos=a[a>0]

def count(x):
    cnt=0
    if x>=0:
        cnt+=len(zero)*n
    cnt+=np.searchsorted(a,x//pos,side='right').sum()
    cnt+=(n-np.searchsorted(a,(-x-1)//(-neg),side='right')).sum()
    cnt-=np.count_nonzero(a*a<=x)
    return cnt//2


left=-10**18
right=10**18

while left+1<right:
    x=(left+right)//2
    out=count(x)
    if out>=k:
        right=x
    if out<k:
        left=x

print(right)


Measured memory_bytes: 34656
#include <bits/stdc++.h> 
#define ll long long int
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
 
using namespace std; 
 
 
int main() 
{
    int a,b;
    cin>>a>>b;

    if(a+b == 3) cout<<3<<endl;
    if(a+b == 4) cout<<2<<endl;
    if(a+b == 5) cout<<1<<endl;
}

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

int main()
{
    int n, s[15000], t, m[1000], count = 0;
    cin >> n;
    for(int i=0; i<n; i++)
        cin >> s[i];
    cin >> t;
    for(int i=0; i<t; i++)
    {
        cin >> m[i];
        int j = 0;
        s[n] = m[i];
        while(s[j] != m[i])    j++;
        if(j<n)   count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define repeat(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define to_i(c) ((c) - '0');
using namespace std;
typedef long long ll;
typedef pair<int, int> p;

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> door(110000, 0), l(110000, 0), r(110000, 0);
	int result = 0;

	repeat(i, M) {
		cin >> l[i] >> r[i];
	}
	int min = 0, max = 100000;
	repeat(i, M) {
		if (min <= l[i]) min = l[i];
		if (r[i] <= max) max = r[i];
	}
	result = max - min + 1;
	if (result < 0) result = 0;

	cout << result << endl;
	return 0;
}


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




int main() {
    int n,m,c;
    cin>>n>>m>>c;
    int a[30][30], b[30];
    rep(i,m)cin>>b[i];
    rep(i,n)rep(j,m) cin>>a[i][j];

    int ans = 0;
    rep(i,n){
        ll temp = 0;
        rep(j,m){
            temp += a[i][j]*b[j];
        }
        temp += c;
        if(temp > 0) ans++;
    }

    cout<< ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
#define N 100010
//char mp[1000][1000];
//int vis[1000][1000];
//int f[4][2]={1,1,1,-1,-1,1,-1,-1};
//void dfs(int x,int y)
//{
//    vis[x][y]=1;
//    for(int i=0;i<2;i++)
//
//}
//int main()
//{
//    int n;
//    int x,y;
//    scanf("%d",&n);
//    for(int i=1;i<=n;i++)
//        for(int k=1;k<=n;i++)
//        {
//            scanf("%c",&mp[i][k]);
//            if(mp[i][k]=='S')
//                {
//                    x=i;y=k;
//                }
//            if(mp[i][k]=='*')
//
//        }
//        dfs(x,y);
//
//
//    return 0;
//}
struct node
{
    int x,num=0;
};
bool cmp(node a,node b)
{
    return a.num>b.num;
}

node book1[100005],book2[100005];
int a[200005];
int ji,ou;
int mx1=0,mx2=0;
int main()
{
    int n;
    scanf("%d",&n);

    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if(i%2==1)
        {
             book1[a[i]].num++;
             book1[a[i]].x=a[i];
             if(book1[a[i]].num>=mx1)
             {
                 //ji=a[i];
                 mx1=book1[a[i]].num;
             }

        }

        else
        {
            book2[a[i]].num++;
             book2[a[i]].x=a[i];
             if(book2[a[i]].num>=mx2)
             {
                // ou=a[i];
                 mx2=book2[a[i]].num;
             }
        }

    }
    sort(book1+1,book1+100005,cmp);
    sort(book2+1,book2+100005,cmp);
    ji=book1[1].x;
    ou=book2[1].x;
    int ans;
    if(ji==ou)
    {
        ans=min(n-book1[1].num-book2[2].num,n-book2[1].num-book1[2].num);

    }
    else
        ans=n-book1[1].num-book2[1].num;


    //printf("%d %d\n",ji,ou);
//    for(int i=1;i<=n;i++)
//    {
//        if(i%2==1)
//        {
//            if(a[i]!=ji)
//            ans++;
//        }
//        else
//        {
//            if(a[i]!=ou)
//                ans++;
//        }
       // printf("%d %d\n",a[i],ans);

    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

int main(int argc, char const* argv[])
{
	unsigned long long n;
	int i;

	cin >> n;

	for( i = n,n = 1;i >= 1;i-- ) n *= i;

	cout << n << endl;

	return 0;
}

Measured memory_bytes: 0
import numpy as np
h, w = map(int, input().split())
ary = np.array([list(input()) for _ in range(h)])

d_h = []
d_w = []
for i in range(h):
    if "#" not in ary[i]:
        d_h.append(i)
for i in range(w):
    if "#" not in ary[:,i]:
        d_w.append(i)

ary = np.delete(ary, d_h, 0)
ary = np.delete(ary, d_w, 1)

for a in ary:
    print("".join(a))

Measured memory_bytes: 13112
#include <stdio.h>
#include <stdlib.h>
#define limit 11
typedef struct {
	int time;
	char name[limit];
}process_struct;

int main() {
	int i, j, processes, quantum, time;
	scanf("%d %d", &processes, &quantum);

	if (processes > 100000 || quantum > 1000) return 0;

	process_struct* process_array = (process_struct*)malloc(sizeof(process_struct)* processes);
	for (i = 0; i != processes; i++) {
		scanf("%s %d", process_array[i].name, &process_array[i].time);
	}

	i = 0;
	time = 0;
	while (1) {
		for (i = 0; i < processes; i++) {
			process_array[i].time -= quantum;

			if (process_array[i].time <= 0) {
				time += (process_array[i].time + quantum);
				printf("%s %d\n", process_array[i].name, time);
				for (j = i; j < processes - 1; j++) {
					process_array[j] = process_array[j + 1];
				}
				processes--;
				i--;
			}

			else time += quantum;
		}

		if (processes == 0) break;
	}

	free(process_array);
	return 0;
}




Measured memory_bytes: 2216
/* ---- I.T.N.O.G ----  */
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long

const ll MAXlog = 60, MAX = 1e4+1, inf = 1e18+1, mod = 1e9+7;

ll x, y, q,f, n, p[MAX];

ll fnd (int x) {
	return ( p[x] == x ? x : p[x] = fnd(p[x]) );
}

void unt ( int x , int y ) {
	p[fnd(y)] = fnd(x);
}

bool is (int x, int y) {
	return fnd(y) == fnd(x);
}

int main() {
	
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> q;
	for (int i = 0; i < n; i++) p[i] = i;
	while (q--) {
		cin >> f >> x >> y;
		if (!f)
			unt ( x , y );
		else
			cout << (is (x, y) ? 1 : 0) << endl;
	}
	return 0;


}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll sum = 0;
  rep(i, n) sum ^= a[i];
  vector<ll> ans;
  rep(i, n) ans.push_back(sum^a[i]);
  line_out(ans);
}

Measured memory_bytes: 7968
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		sc.close();
		
		int total=0;
		int n = 0;
		
		for(int i=0;i<60;i++) {
			total += a;
			if(n+c <= total) {
				System.out.println(n + c);
				return;
			}
			total += b;
			if(n+c < total) {
				n += 60;
			}
			else {
				continue;
			}
			
			
		}
		
		System.out.println("-1");
	}

}



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

int main() {
    int n, k;
    cin >> n >> k;
    int p[1100];
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    sort(p, p + n);
    int sum = 0;
    for (int i = 0; i < k; i++) {
        sum += p[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  long long x, y;
  cin >> x >> y;
  
  long long ans = 1LL << 60;
  
  if(y >= x) {
    ans = min(ans, y - x);
  }
  
  if(-y >= x) {
    ans = min(ans, -y - x + 1);
  }
  
  if(y >= -x) {
    ans = min(ans, y + x + 1);
  }
  
  if(-y >= -x) {
    ans = min(ans, -y + x + 2);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define maxn (int)(2e5)
#define i64 long long
using namespace std;
int h[maxn+2];
i64 sum[maxn+2];

bool cmp(int val1 , int val2){ return val1 > val2 ; }

int main() {
	// your code goes here
	int n,k;
	while(scanf("%d %d",&n, &k)==2){
		for(int i=0;i<n;i++) {
			scanf("%d",&h[i]);
			//sum[i] = i == 0 ? h[i] : sum[i-1] + h[i];
		}
		sort(h,h+n, cmp);
		
		i64 cost = 0;
		for(int i=k; i<n;i++) cost+=h[i];
		printf("%lld\n", cost);
	}
	return 0;
}

Measured memory_bytes: 1024
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0343"

#include<bits/stdc++.h>
using namespace std;

#define call_from_test
#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
#endif
//BEGIN CUT HERE
template<typename V>
V compress(V v){
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  return v;
}
template<typename T>
map<T, int> dict(const vector<T> &v){
  map<T, int> res;
  for(int i=0;i<(int)v.size();i++)
    res[v[i]]=i;
  return res;
}
map<char, int> dict(const string &v){
  return dict(vector<char>(v.begin(),v.end()));
}
//END CUT HERE
#ifndef call_from_test
//INSERT ABOVE HERE
signed main(){
  return 0;
}
#endif

#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
#endif
//BEGIN CUT HERE
template<typename T>
struct BIT{
  int n;
  vector<T> bit;
  // 1-indexed
  BIT(int n_):n(n_+1),bit(n+1,0){}

  T sum(int i){
    T s(0);
    for(int x=i;x>0;x-=(x&-x))
      s+=bit[x];
    return s;
  }

  void add(int i,T a){
    if(i==0) return;
    for(int x=i;x<=n;x+=(x&-x))
      bit[x]+=a;
  }

  // [l, r)
  T query(int l,int r){
    return sum(r-1)-sum(l-1);
  }

  int lower_bound(int w){
    if(w<=0) return 0;
    int x=0,r=1;
    while(r<n) r<<=1;
    for(int k=r;k>0;k>>=1){
      if(x+k<=n&&bit[x+k]<w){
        w-=bit[x+k];
        x+=k;
      }
    }
    return x+1;
  }

  // 0-indexed
  T sum0(int i){return sum(i+1);}
  void add0(int i,T a){add(i+1,a);}
  T query0(int l,int r){return sum(r)-sum(l);}
};
//END CUT HERE
#ifndef call_from_test
signed main(){
  return 0;
}
#endif

#undef call_from_test

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

  using ll = long long;

  int n,c;
  cin>>n>>c;
  vector<int> ts(c),is(c),ps(c);
  for(int i=0;i<c;i++){
    cin>>ts[i]>>is[i];
    if(ts[i]==0) cin>>ps[i],is[i]--;
  }

  vector<ll> ss(n,0);

  using P = pair<ll, int>;
  vector<P> vp;
  for(int i=0;i<n;i++) vp.emplace_back(-ss[i],i);

  for(int i=0;i<c;i++){
    if(ts[i]==0){
      ss[is[i]]+=ps[i];
      vp.emplace_back(-ss[is[i]],is[i]);
    }
  }
  vp.emplace_back(-ll(1e18),0);
  vp=compress(vp);
  auto dc=dict(vp);

  BIT<int> bit(vp.size());

  fill(ss.begin(),ss.end(),0);
  for(int i=0;i<n;i++) bit.add(dc[P(-ss[i],i)],+1);

  for(int i=0;i<c;i++){
    if(ts[i]==0){
      bit.add(dc[P(-ss[is[i]],is[i])],-1);
      ss[is[i]]+=ps[i];
      bit.add(dc[P(-ss[is[i]],is[i])],+1);
    }
    if(ts[i]==1){
      int k=bit.lower_bound(is[i]);
      cout<<vp[k].second+1<<" "<<-vp[k].first<<"\n";
    }
  }
  return 0;
}



Measured memory_bytes: 21140
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

long long lucas(int n) {
    if (n == 0) return 2;
    if (n == 1) return 1;

    long long l0 = 2, l1 = 1, l2;
    int i = 2;
    while (i <= n) {
        l2 = l1 + l0;
        l0 = l1;
        l1 = l2;
        i++;
    }
    return l2;
}

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

    cout << lucas(n) << endl;
}


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*4
#define REP(a,b) for(long long a = 0;a < b;++a)
int main() {
	long long a, b;
	cin >> a >> b;
	if (a > b) swap(a, b);
	long long ans = 1;
	for (long long i = 2; i <= 1000000; ++i) {
		long long ok = 0;
		while (a % i == 0 && b % i == 0) {
			a /= i;
			b /= i;
			ok = 1;
		}
		ans += ok;
		while (a % i == 0) {
			a /= i;
		}
		while (b % i == 0) {
			b /= i;
		}
	}
	if (a > 1000000 && b % a == 0) {
		ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
n = int(input())
t,a = map(int,input().split())
h_list = list(map(int, input().split()))
diff = 10**8
for i in range(n):
    h_list[i] = t - h_list[i]*0.006
    if abs(h_list[i]-a) < diff:
        diff = abs(h_list[i]-a)
        ind = i

print(ind+1)

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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

using P = pair<ll, ll>;

V<ll> solve(V<ll> v) {
    int n = int(v.size());
    V<ll> ans(n + 1); ans[n-1] = ans[n] = 0;
    V<P> st;
    st.push_back(P(1, TEN(9)));
    ll all_c = 0;
    auto inc = [&](ll x) {
        while (x) {
            P pa = st.back(); st.pop_back();
            ll u = min(x, pa.second);
            all_c += 2 * pa.first * u;
            x -= u;
            pa.second -= u;
            if (pa.second == 0) {
                assert(st.size());
                st.back().first += pa.first;
            } else {
                st.push_back(pa);
            }
        }
    };
    ll bk = v[n - 1];
    for (int i = n-2; i >= 0; i--) {
        //add v[i]
        ll nw = v[i];
        ll c = 0;
        while (bk < nw) {
            c++;
            bk *= 4;
        }
        inc(c);
        c = 0;
        while (4 * nw <= bk) {
            c++;
            nw *= 4;
        }
        st.push_back(P(1, c));
        bk = v[i];
        ans[i] = all_c;
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    V<ll> v;
    for (int i = 0; i < n; i++) {
        ll x;
        cin >> x;
        v.push_back(x);
    }
    auto s1 = solve(v);
    reverse(v.begin(), v.end());
    auto s2 = solve(v);
    reverse(s2.begin(), s2.end());
/*    for (ll d: s1) cout << d << " ";
    cout << endl;
    for (ll d: s2) cout << d << " ";
    cout << endl;*/

    ll ans = TEN(18);
    for (int i = 0; i <= n; i++) {
        ans = min(ans, s1[i] + s2[i] + i);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 14420
#include<bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v) cerr<<#v":[ ";for (auto macro_vi:v){cerr<<macro_vi<< " ";}cerr<<"]"<<endl;
#define ddump(v) cerr<<#v":"<<endl;for(auto macro_row:v) {cerr<<"["; for (auto macro__vi:macro_row){cerr<<macro__vi<< " ";}cerr<<"]"<<endl;}
#define damp(m) for(auto macro_pair:m){cerr<< macro_pair.first<<":"<<macro_pair.second<<endl;}
#define dpair(p) cerr << #p":"<<"(" << p.first << "," << p.second << ")" << endl;
// iterate
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define itr(macro_v,i) macro_v.begin()+i
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v(n,0);
    rep(i,n)cin >> v[i];
    sort(all(v));
    // dump(v)

    ll cnt=0;
    for(int b_i=1; b_i<n; b_i++){
        for(int a_i=0; a_i<b_i; a_i++){
            int left = b_i+1, right = n,val = v[a_i]+v[b_i];
            int ma_c_i = lower_bound(itr(v,left),itr(v,right), val) - v.begin();// valを超える最小のイテレータ
            cnt+= ma_c_i - left;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = str(input())
l = [0] * n
r = [0] * n
for i in range(1, n):
    if s[i-1] == 'W':
        l[i] = l[i-1] + 1
    else:
        l[i] = l[i-1]

for i in range(n-2, -1, -1):
    if s[i+1] == 'E':
        r[i] = r[i+1] + 1
    else:
        r[i] = r[i+1]

ans = 10**6
for i in range(n):
    ans = min(ans, (l[i] + r[i]))
print(ans)


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

int main() {
  int n;
  cin >> n;
  int d[n];
  rep(i,n)
  cin >> d[i];
  sort(d,d+n);
  cout << d[n/2]-d[n/2-1] << endl;
}

Measured memory_bytes: 640
import math

def dist(x,y,d):
    ret = 0.0
    for i in range(d):
        ret += pow(x[i] - y[i], 2)
    return pow(ret, 0.5)

def main():
    n, d = map(int, input().split())

    num_list = [list(map(int, input().split())) for _ in range(n)]

    ans = 0

    for i in range(n):
        for j in range(i+1,n):
            distance = dist(num_list[i],num_list[j],d)
            if math.ceil(distance) == math.floor(distance):
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38640
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

# include <stdio.h>
# include <bits/stdc++.h>


#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

using namespace __gnu_pbds;
using namespace std;
 
typedef
tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;

int main () {
	SpeedForce;
	cin >> n >> m;
	res = n;
	For (i, 1, m) {
		int l, r;
		cin >> l >> r;
		ans = max(l, ans);
		res = min(r, res);
	}	

	cout << max(0, res - ans + 1);

	return Accepted;
}

// B...a

Measured memory_bytes: 18688
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<iomanip>
#include<algorithm>
using namespace std;

int main() {
	int A,B,C;
	cin >> A >> B >> C;
	int oeA=A%2;
	int oeB=B%2;
	int oeC=C%2;
	int counter = 0;
	if (oeA==oeB && oeA==oeC){

	}
	else if (oeA==oeB){
		A++;
		B++;
		counter++;
	}
	else if (oeA==oeC){
		A++;
		C++;
		counter++;
	}
	else{
		C++;
		B++;
		counter++;
	}
	counter += (max({A,B,C})-A)/2 + (max({A,B,C})-B)/2 + (max({A,B,C})-C)/2;
	cout << counter << endl;
	return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
A = []
for h in range(H):
    tmp = list(map(int, input().split()))
    if h % 2 == 0:
        r = range(W)
    else:
        r = range(W)[::-1]

    for w in r:
        A.append((h, w, tmp[w]))

ans = []
for i in range(len(A) - 1):
    if A[i][2] % 2 != 0:
        ans.append((A[i][0] + 1, A[i][1] + 1, A[i + 1][0] + 1, A[i + 1][1] + 1))
        A[i + 1] = (A[i + 1][0], A[i + 1][1], A[i + 1][2] + 1)
        A[i] = (A[i][0], A[i][1], A[i][2] - 1)
print(len(ans))
for x in ans:
    print(*x)


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> card;
    for (int i=1; i<=2*n; ++i) {
        card.push_back(i);
    }
    int k;
    for (int i=0; i<m; ++i) {
        cin >> k;
        if (k == 0) {
            vector<int> t;
            for (int j=0; j<n; ++j) {
                t.push_back(card[j]);
                t.push_back(card[n+j]);
            }
            card = t;
        } else {
            rotate(card.begin(), card.begin()+k, card.end());
        }
    }
    for (int i=0; i<2*n; ++i) {
        cout << card[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define ALL(v) v.begin(),v.end()
typedef long long ll;
int main() {
  int n;
  string s = "No";
  cin >> n;
  for(int i=1; i<=9; i++){
    for(int j=1; j<=9; j++){
    	if(i*j==n){
        	s= "Yes";
        }
    }
  }
  cout << s << endl;
}


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

	
	

int main()
{
	int n;
	cin>>n;
	
	double prob[n];
	
	for(int i=0;i<n;i++)
	cin>>prob[i];
	
	double dp[n+1][n+1];
	dp[0][0]=1.0;
	
	for(int i=1;i<n+1;i++)
	{
		for(int j=0;j<=i;j++)
		{
			if(j==0)
			dp[i][j]=(1.0-prob[i-1])*dp[i-1][j]*1.0;
			else if(j!=i)
			{
				dp[i][j] = dp[i-1][j-1]*1.0*prob[i-1]+dp[i-1][j]*1.0*(1-prob[i-1]);
			}
			else
			dp[i][j]=1.0*dp[i-1][j-1]*prob[i-1];
		}
	}
	
	int st = (n+1)/2;
	double ans=0;
	for(int i=st;i<=n;i++)
	ans+=dp[n][i];
	cout<<setprecision(10)<<ans;
}
	


Measured memory_bytes: 49960
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

c = 0
for i in range(n):
    ai = a[i]
    bi = b[i]
    if ai < bi:
        c += (bi-ai)//2
    else:
        c -= (ai-bi)
print('Yes' if c >= 0 else 'No')


Measured memory_bytes: 41456