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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD )
{
    x += y;
    if( x >= m )
        x -= m;
}

template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD )
{
    x -= y;
    if( x < 0 )
        x += m;
}

int main() 
{
    #ifdef gupta_samarth
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    fastio();

    int x;
    cin>>x;
    cout<<1-x,nl;    

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


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

int main() {
	string S;
	cin >> S;
	int N = S.length();
	int B[2] = { 0,0 };
	int W[2] = { 0,0 };
	for (int i = 0; i < N; i++) (S[i] == '0' ? B : W)[i % 2]++;
	cout << min(B[0] + W[1], B[1] + W[0]) << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#define MAX 2000000

int size,A[MAX+1];

void maxHeapify(int i){
  int l,r,largest,t;
  l=2*i;
  r=2*i+1;
  if(l<=size && A[l]>A[i])largest=l;
  else largest=i;
  if(r<=size && A[r]>A[largest])largest=r;
  if(largest!=i){
    t=A[i];
    A[i]=A[largest];
    A[largest]=t;
    maxHeapify(largest);
  }
}

int main(){
  scanf("%d",&size);
  int i;
  for(i=1;i<=size;i++)scanf("%d",&A[i]);

  for(i=size/2;i>=1;i--)maxHeapify(i);

  for(i=1;i<=size;i++){
    printf(" %d",A[i]);
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 3652
import math

t = int(input())

for i in range(t):
    a, b, c, d = list(map(int, input().split()))

    if b > d:
        # 増える本数より減る本数のほうが多いので、ジュースの本数は目減りしていつか無くなる
        print('No')
        continue
    if a < b:
        # 初日に買おうとしたらないパターン
        print('No')
        continue
    if b == d:
        # 増える本数と減る本数が同じ。一往復が可能なら永遠にループする

        if a <= c:
            # 初日に買えることは確定、その後無限ループに入る
            print('Yes')
            continue

        diff = a-c
        buy_num = (diff + b - 1) // b
        if a - buy_num * b < 0:
            print('No')
            continue
        else:
            print('Yes')
            continue
    
    if b < d:
        # 補題
        # 減少幅b と増加幅dが互いに素であれば、無限回の操作の中で取りうる最小値はc-b+1である。
        # （開店時の値の中で取りうる最小値はc+1である、のほうが分かりやすいかも?）
        # 証明：
        # (1) c-b+1を取ることがあることの証明
        # 互いに素なので、bを引いてdを足すのを繰り返すと、mod bでc+1と合同になるときが存在する。（逆元を考えれば良い）
        # このとき、購入後がc+1+b*n(n>=0) だったら、cより真に大きいので補充されない。購入だけが続く。
        # したがって、(c+1+b → 購入 →) c+1 → 購入 → c-b+1 → 補充 → c-b+1+d という動きになるときがある。
        # (2) c-b以下を取ることがないことの証明
        # 1回以上、c以上の値を取ったあとは、購入・補充（-b+dで真に増える）か購入(-b)かのどちらか。
        # 後者が発生したときは購入後の値はc+1以上でなければならない。したがって開店時の値は常にc+1以上である。
        # 購入後の値もc-b+1以上である。
        # 以上で証明完。最初からc以下の場合が曲者だが、初日に無いパターンは除外されているので、
        # 初日を乗り切れば増加してc以上の値を取るところまで行ける。すなわち上と同じ話に帰着できる。

        if math.gcd(b, d) == 1:
            if c-b+1 >= 0:
                print('Yes')
                continue
            else:
                print('No')
                continue
        else:
            # 互いに素でない場合。
            # aからgcd(b, d)ずつ引いた数列のうち、c+1以上で最小の要素が 開店時の値の中で取りうる最小値である。
            # 証明はしてないけど上とほとんど同様でしょう。
            g = math.gcd(b, d)
            diff = a - (c+1)
            subtract_width = diff // g * g
            if a - subtract_width >= b:
                print('Yes')
                continue
            else:
                print('No')
                continue                



Measured memory_bytes: 8976
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    int n,x;cin>>n;
    set<int> s;
    for(int i=0;i<n;i++){
        cin>>x;s.insert(x);
    }
    cout<<s.size()<<endl;
}


Measured memory_bytes: 3616
import sys
word=input()
exam_text=[]
while True:
    text = input().split()
    if text[len(text)-1]=="END_OF_TEXT":
        break
    else:
        exam_text+=text
for i in range(len(exam_text)):
    exam_text[i] = exam_text[i].lower()

print(exam_text.count(word)) 



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

int main()
{
	int n,m,i,j,s,ma=-1;
	cin>>n;
	string a[n];
	for (i=0;i<=n-1;i++)
		cin>>a[i];
	cin>>m;
	string b[m];
	for (i=0;i<=m-1;i++)
		cin>>b[i];
	for (i=0;i<=n-1;i++)
	{
		s=0;
		for (j=0;j<=n-1;j++)
			if (a[i]==a[j]) s++;
		for (j=0;j<=m-1;j++)
			if (a[i]==b[j]) s--;
		ma=max(ma,s);
	}
	if (ma<0) ma=0;
	cout <<ma;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

void solve()
{
	ll n,k;
	cin>>n>>k;
	if(k>=n){
		cout<<min(n,k-n);
		return;
	}	
	ll p=(n-k)/k;
	if((n-k)%k)
		p++;
	ll a1=n-p*k;
	ll a2=abs(a1-k);
	cout<<min(a1,a2);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
N=int(input())
a=list(map(int,input().split()))
x=[ [0,i]  for i in range(max(a)+1)]
y=[[0,i] for i in range (max(a)+1)]
for i in range(0,N,2):
        x[a[i]][0]+=1
        y[a[i+1]][0]+=1

x.sort(reverse=True)
y.sort(reverse=True)
if x[0][1]==y[0][1]:
        print(min(N-x[0][0]-y[1][0],N-x[1][0]-y[0][0]))
else: print(N-x[0][0]-y[0][0])

Measured memory_bytes: 34228
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1E9 + 7;
const int INF = 1 << 29;

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll x = min(N, B - 1);
  cout << floor(A * x / B) << endl;
}

Measured memory_bytes: 3772
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long int x;
	cin >> x;

	long long int ans = 0;
	
	ans = x / 11 * 2;
	if (x % 11 == 0);
	else if (x % 11 > 6) ans += 2;
	else ans += 1;

	cout << ans << endl;
}


Measured memory_bytes: 3584
using System;
using System.Linq;

namespace agc030_a
{
    class Program
    {
        static void Main(string[] args)
        {
            var text = Console.ReadLine();
            var list = text.Split(' ').ToList();

            var b = int.Parse(list[0]);
            var a = int.Parse(list[1]);

            if (b <= 5){
                Console.WriteLine("0");
            } else if (b >= 6 && b <= 12){
                Console.WriteLine((a / 2).ToString());
            } else {
                Console.WriteLine(a);
            }
        }
    }
}


Measured memory_bytes: 11220
s=input()
x=[i-96for i in map(ord,s)]
n=int(input())
for i in range(len(s)):
    y=(26-x[i]+1)%26
    if y<=n:
        n-=y
        x[i]=1
x[-1]+=n%26
print("".join(map(chr,[i+96 for i in x])))

Measured memory_bytes: 5748
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

// dp[i][j]:=i人でj個
long long dp[110][100010];
int main(){
    int n,k; cin>>n>>k;
    int a[n]; rep(i,n) cin>>a[i];
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=k;j++){
            dp[i][j]+=dp[i-1][j];
            if(j-1>=0) dp[i][j]+=dp[i][j-1];
            if(j-1-a[i-1]>=0) dp[i][j]=dp[i][j]+MOD-dp[i-1][j-1-a[i-1]];
            dp[i][j]%=MOD;
        }
    }
    cout<<dp[n][k]<<endl;
    return 0;
}


Measured memory_bytes: 79360
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#pragma region Macros
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define all(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
inline bool BETWEEN(int x, int min,int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
using namespace std;
#pragma endregion
signed main() {
	int M;
	cin >> M;
	cout << 48 - M;
}

Measured memory_bytes: 256
H, W, K = map(int, input().split())
S = [list(map(int, input())) for _ in range(H)]

def nl(a, b):
    return [[0]*b for _ in range(a)]

def add(j):
    for i in range(g):
        now[i] += group_sum[i][j]
        if now[i] > K:
            return False
    return True

ans = float('inf')
for bit in range(1<<(H-1)):
    id_of = [0]*H
    g = 0
    
    for i in range(H):
        id_of[i] = g
        if bit >> i & 1:
            g += 1
    
    g += 1
    count = g - 1

    # グループごとに統合
    group_sum = nl(H, W)
    for i in range(H):
        for j in range(W):
            group_sum[id_of[i]][j] += S[i][j]

    # 縦方向に分割
    now = [0]*g
    for j in range(W):
        if not add(j):
            count += 1
            now = [0]*g
            if not add(j):
                count = float('inf')
                break
    
    ans = min(ans, count)

print(ans)

Measured memory_bytes: 49628
#include  <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 1000000007
//vector<vector<int>> vec(縦, vector<int>(横));
#define REP(i,N) for(int i=0;i<N;i++)
int gcd(int a, int b) {
    if(a>b){
        swap(a,b);
        }
    while(b%a!=0){
        b%=a;
        swap(a,b);
    }
    return a;
}


//cout << setprecision(123)<<ans;
//a=atoi(S.c_str());
//S=to_string(a);
int main(){
  int n,N,m;
  string s;
  cin>>n>>s;
  N=s.size();
  REP(i,N){
    m=s[i]+1;
    if(m+n>91){
      printf("%c",s.at(i)+n-26);
    }
    else{
      printf("%c",s.at(i)+n);
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c=0,d=0;
    cin>>a;
    for(int i=0;i<a;i++){
        cin>>b;
        d=d+b;
        if(c<b){
            c=b;
        }
    }
    cout<<d-c/2;
    return 0;
}

Measured memory_bytes: 256
import sys
def main():
    input = sys.stdin.readline
    s = input().rstrip()
    K = int(input())

    def c(x): return ord(x) - ord('a')
    def d(x): return chr(x + ord('a'))
    ans = []
    i = 0
    while i < (len(s) - 1):
        to_a = (26 - c(s[i])) % 26
        if to_a <= K:
            ans.append('a')
            K -= to_a
        else:
            ans.append(s[i])
        i += 1
    if K > 0:
        ans.append(d((c(s[-1]) + K) % 26))
    else:
        ans.append(s[i])
    print(''.join(ans))

if __name__ == '__main__':
    main()

Measured memory_bytes: 46832
#include <bits/stdc++.h>
using namespace std;
#define LLINF (1LL<<60)
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//C++14 (GCC 5.4.1)
int main() {
    int N;
    cin >>N;

    bool is=false;
    //-----------------------------------
    int Ans;
    if(N%2==1){
        Ans=N*2;
    }else{
        Ans=N;
    }

    cout << Ans <<endl;
    return (0);
}

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

using namespace std;

const int nax=444;
long long int dp[nax][nax];
long long int p[nax];

long long int ile(int l,int r)
{
    return p[r]-p[l-1];
}

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

    long long int * a=new long long int [n+1];
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) dp[i][i]=0;
    p[0]=0;
    p[1]=a[1];
    for(int i=2;i<=n;i++) p[i]=p[i-1]+a[i];
    for(int len=2;len<=n;len++)
    {
        for(int i=1;i<=n;i++)
        {
            int j=i+len-1;
            if(j>n) continue;
            dp[i][j]=1e18;
            for(int k=i;k<j;k++)
            {

                    dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+ile(i,j));

            }
        }
    }
    cout<<dp[1][n];
    return 0;
}


Measured memory_bytes: 1664
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	llint n,i,j,Q;
	string str;cin>>n>>str>>Q;
	//スライド?
	while(Q--){
		llint k,D=0,DM=0,M=0,ans=0;cin>>k;k--;
		for(i=0;i<n;i++){
			if(str[i]=='D'){D++;}
			if(str[i]=='M'){DM+=D;M++;}
			if(str[i]=='C'){ans+=DM;}
			
			if(k<=i){
				if(str[i-k]=='D'){D--;DM-=M;}
				if(str[i-k]=='M'){M--;}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1948
#include<stdio.h>

//関数プロトタイプ宣言
void diceRoll(int *d,char *r);

int main(){
	int dice[6];	//サイコロ
	int q;			//質問の数
	int up;			//サイコロの上面
	int front;		//サイコロの前面
	
	//サイコロの作成
	for(int i = 0;i < 6;i++){
		scanf("%d",&dice[i]);
	}
	//質問の数の入力
	scanf("%d",&q);
	
	for(int i = 0;i < q;i++){
		//上面と前面の入力
		scanf("%d %d",&up,&front);
		
		//サイコロの上面が入力されたものと違うとき
		if(dice[0] != up){
			//入力された上面が前面にあったとき
			if(dice[1] == up){
				diceRoll(dice,"N");
			}
			//右面にあったとき
			else if(dice[2] == up){
				diceRoll(dice,"W");
			}
			//左面にあったとき
			else if(dice[3] == up){
				diceRoll(dice,"E");
			}
			//後面にあったとき
			else if(dice[4] == up){
				diceRoll(dice,"S");
			}
			//底面にあったとき
			else if(dice[5] == up){
				diceRoll(dice,"NN");
			}
		}
		
		//サイコロの前面が入力されたものと違うとき
		if(dice[0] != front){
				//入力された前面が右面にあったとき
			if(dice[2] == front){
				diceRoll(dice,"R");
			}
			//左面にあったとき
			else if(dice[3] == front){
				diceRoll(dice,"L");
			}
			//後面にあったとき
			else if(dice[4] == front){
				diceRoll(dice,"RR");
			}
		}
		
		//右面を表示
		printf("%d\n",dice[2]);
	}
	
	return 0;
}

void diceRoll(int *d,char *r){
	int x;	//入れ替え用変数
	for(int i = 0;r[i] != '\0';i++){
		switch(r[i]){
			//右に転がす
			case 'E':
				x = d[0];
				d[0] = d[3];
				d[3] = d[5];
				d[5] = d[2];
				d[2] = x;
				break;
			//奥に転がす
			case 'N':
				x = d[0];
				d[0] = d[1];
				d[1] = d[5];
				d[5] = d[4];
				d[4] = x;
				break;
			//手前に転がす
			case 'S':
				x = d[0];
				d[0] = d[4];
				d[4] = d[5];
				d[5] = d[1];
				d[1] = x;
				break;
			//左に転がす
			case 'W':
				x = d[0];
				d[0] = d[2];
				d[2] = d[5];
				d[5] = d[3];
				d[3] = x;
				break;
			//右に９０度回す
			case 'R':
				x = d[1];
				d[1] = d[2];
				d[2] = d[4];
				d[4] = d[3];
				d[3] = x;
				break;
			//左に９０度回す
			case 'L':
				x = d[1];
				d[1] = d[3];
				d[3] = d[4];
				d[4] = d[2];
				d[2] = x;
				break;
		}
	}
}



Measured memory_bytes: 1988
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int d, n; cin >> d >> n;
    d = pow(100,d);
    if (n < 100)
    {
        cout << n*d;
    } else {
        cout << 101*d;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int main() {
	int f[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
	int a,b;
	scanf("%d %d",&a,&b);
	if(f[a]==f[b]) printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

int n;
int x[24],y[24],r[24],c[24];
bool overlap[24][24];
bool memo[1<<24];

bool ok(int a,int bit){
    for(int i=0;i<a;i++)if((bit>>i)&1){
        if(overlap[a][i])return false;
    }
    return true;
}

int dfs(int bit){
    memo[bit]=true;

    int ret=n;
    for(int i=0;i<n;i++)if((bit>>i)&1)ret--;

    for(int i=0;i<n-1;i++){
        if(((bit>>i)&1)==0||ok(i,bit)==false)continue;
        for(int j=i+1;j<n;j++){
            if(c[i]!=c[j]||((bit>>j)&1)==0)continue;
            int to_bit=(bit^(1<<i))^(1<<j);
            if(ok(j,bit)&&!memo[to_bit]){
                ret=max(ret,dfs(to_bit));
            }
        }
    }


    return ret;
}

void solve(){
    fill_n(memo,1<<n,false);

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            int dist=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
            int sum=(r[i]+r[j])*(r[i]+r[j]);
            overlap[i][j]=dist<sum;
        }
    }
    cout<<dfs((1<<n)-1)<<endl;
}

bool input(){
    cin>>n;
    if(!n)return false;
    for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>r[i]>>c[i];
    return true;
}



int main(){
    while(input())solve();
    return 0;
}


Measured memory_bytes: 19472
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000

int MOD=1000000007;
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}
////////////////////////////////////////////////////////////

signed main() {
  int n;
  cin>>n;
  int four=0,two=0,ki=0;
  rep(i,n){
    int t;cin>>t;
    if(t%4==0)four++;
    else if(t%2==0)two++;
    else ki++;
  }
  if(two+four==n||four>=ki||(two==0&&four>=ki-1))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstring>
#include <algorithm>

using namespace std;

double memo[301][301][301],n;
int polje[301];
int br1,br2,br3;

double dfs(int a,int b,int c){
	if(a==0 and b==0 and c==0 or a==-1 or b==-1 or c==-1) return 0;
	if(memo[a][b][c]!=-1) return memo[a][b][c];
	memo[a][b][c]=n/(a+b+c);
	memo[a][b][c]+=(a*dfs(a-1,b,c)+b*dfs(a+1,b-1,c)+c*dfs(a,b+1,c-1))/(a+b+c);
	return memo[a][b][c];
}

int main () {
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>polje[i];
		if(polje[i]==1) br1++;
		else if(polje[i]==2) br2++;
		else if(polje[i]==3) br3++;
	}
	fill(&memo[0][0][0],&memo[300][300][300],-1.0);
	cout<<setprecision(16)<<dfs(br1,br2,br3);



return 0;
}



Measured memory_bytes: 213376
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define inf 1e9
#define mod 1000000007
#define ff first
#define ss second

void solve()
{
	int n;
	cin >> n;
	vector<char> ans;
	while (n > 0)
	{
		n -= 1;
		int x = n % 26;
		ans.push_back('a' + x);
		n = n / 26;
	}
	reverse(ans.begin(), ans.end());
	for (auto i : ans)
		cout << i;

}

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


Measured memory_bytes: 3648
import java.util.*;
import java.io.*;

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

        String S = sc.next();
        sc.close();

        int ans = 0;
        for (int i = 0; i < S.length(); i++) {
            if (S.charAt(i) == '+') {
                ans++;
            } else {
                ans--;
            }
        }
        out.printf("%d\n", ans);
        out.flush();
    }
}


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

    int a,b,c;
    
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    
    //MAX聞ける回数
    int num=0;

    num=b/a;
    
    if(num<=c)
    {
        printf("%d\n",num);
    }
    else
    {
        printf("%d\n",c);
    }
    
    return 0;
    
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *
 * @author yoshkur
 */
public class Main {

	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			InputData inputData = new InputData(br);
			StringBuilder sb = new StringBuilder();
			sb.append(getArea(inputData));
			sb.append(" ");
			sb.append(getLength(inputData));
			System.out.println(sb.toString());

		} catch (IOException | NumberFormatException e) {
			System.err.println(e.getLocalizedMessage());
		}
	}

	public static Integer getArea(InputData inputData) {
		return inputData.getHeight() * inputData.getWidth();
	}

	public static Integer getLength(InputData inputData) {
		return (inputData.getHeight() + inputData.getWidth()) * 2;
	}

}

class InputData {

	private Integer height;
	private Integer width;

	public InputData(BufferedReader br) throws IOException {
		String line = br.readLine().trim();
		String[] values = line.split(" ");
		this.height = Integer.valueOf(values[0]);
		this.width = Integer.valueOf(values[1]);
	}

	public Integer getHeight() {
		return height;
	}

	public void setHeight(Integer height) {
		this.height = height;
	}

	public Integer getWidth() {
		return width;
	}

	public void setWidth(Integer width) {
		this.width = width;
	}
}

Measured memory_bytes: 23884
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007

int main()
{
	// ios_base::sync_with_stdio(false);
 //    cin.tie(NULL);
 //    cout.tie(NULL);
    ll n;
    cin>>n;
    ll h[n],i,c=0,a[n];
    for(i=0;i<n;i++)
    {
    	cin>>h[i];
    	a[h[i]-1]=i+1;
    }
    for(i=0;i<n;i++)
    	cout<<a[i]<<" ";
    cout<<"\n";
    return 0;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
#define N 40
using namespace std;
typedef pair<int,int> P;

int n, G[N][N], A[N], ans;
vector<P> idx;

void dfs(int x,int sum,vector<int> S){
  
  ans=max(ans,sum);
  
  if(x==n-1||ans>=sum+A[x]) return;
  
  dfs(x+1,sum,S);
  
  for(int i=0;i<S.size();i++)
    if(G[S[i]][idx[x].second]) return;
  
  S.push_back(idx[x].second);
  
  dfs(x+1,sum+idx[x].first,S);
}

int main(){
  
  while(1){
    
    cin>>n;
    if(!n) break;

    map<string,int> num;
    int cost, cnt=0;
    
    memset(G,0,sizeof(G));
    idx.clear();
    
    for(int i=0;i<n;i++){
      
      string s;
      cin>>s;
      
      if(!num.count(s)) num[s]=cnt++;

      int a, b;
      cin>>a>>b;

      if(i) idx.push_back(P(a,num[s]));
      else cost=a;
      
      for(int j=0;j<b;j++){

	string t;
	cin>>t;
	
	if(!num.count(t)) num[t]=cnt++;

	G[num[s]][num[t]]=1;
      }
      
    }
    
    sort(idx.begin(),idx.end(),greater<P>());

    memset(A,0,sizeof(A));
    
    A[n-1]=idx[n-1].first;
    
    for(int i=n-2;i>=0;i--)
      A[i]=A[i+1]+idx[i].first;
    
    ans=cost;
    
    vector<int> s;
    
    s.push_back(0);
    
    dfs(0,cost,s);
    
    cout<<ans<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3176
#include <iostream>
#define FOR(i,a,b) for(int i=a;i<b;i++)
using namespace std;
int main(){
    int n; cin>>n;
    int p[20001];
    FOR(i,0,n){
        int k; cin>>k;
        p[k-1]=i;
    }
    FOR(i,0,n){
        cout<<i*n+p[i]+1<<" ";
    }
    cout<<endl;
    FOR(i,0,n){
        cout<<n*(n-1-i)+1<<" ";
    }
}

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

int H, W, INF = 100000000;
vector<vector<char>> S;
vector<vector<int>> D;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};

int bfs(int sx, int sy) {
  queue<pair<int, int>> Q;
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      D.at(i).at(j) = INF;
    }
  }
  
  pair<int, int> start;
  start = make_pair(sx, sy);
  Q.push(start);
  D.at(sx).at(sy) = 0;
  int maxD = 0;
  
  while (!(Q.empty())) {
    pair<int, int> p = Q.front();
    Q.pop();
    
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx.at(i), ny = p.second + dy.at(i);
      if (nx >= 0 && nx < H && ny >= 0 && ny < W &&
          S.at(nx).at(ny) != '#' && D.at(nx).at(ny) == INF) {
        pair<int, int> N;
        N = make_pair(nx, ny);
        Q.push(N);
        D.at(nx).at(ny) = D.at(p.first).at(p.second) + 1;
        maxD = max(maxD, D.at(nx).at(ny));
      }
    }
  }
  
  return maxD;
}
  

int main() {
  cin >> H >> W;
  S.resize(H);
  D.resize(H);
  for (int i = 0; i < H; i++) {
    S.at(i).resize(W);
    D.at(i).resize(W);
    for (int j = 0; j < W; j++) cin >> S.at(i).at(j);
  }
  int ans = 0;
  for (int sx = 0; sx < H; sx++) {
    for (int sy = 0; sy < W; sy++) {
      if (S.at(sx).at(sy) == '.') {
        ans = max(ans, bfs(sx, sy));
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// #define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 1000000000000000000ll
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}

// string to integer stuuu()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

//////////////

#define S second
#define F first
#define int long long  
///////

signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	string s;
	cin>>s;
	int n1,n2;
	n1=(s[0]-'0')*10;
	n1+=(s[1]-'0');
	n2=(s[2]-'0')*10;
	n2+=(s[3]-'0');
	if((n1<=12&&n1>=1)&&(n2<=12&&n2>=1))
	{
		cout<<"AMBIGUOUS";
		return 0;
	}
	if((n1<=12&&n1>=1))
	{
		cout<<"MMYY";
		return 0;
	}
	if((n2<=12&&n2>=1))
	{
		cout<<"YYMM";
		return 0;
	}
	cout<<"NA";
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(void){
	int H,R;
	cin>>H>>R;
	if(H==-R)cout<<0<<endl;
	else if(H>-R)cout<<1<<endl;
	else cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 3096
#from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
#input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**6)


def main():
    while 1:
        s=input()
        if "0 0" in s:
            break
        else:
            a,b=map(int,s.split())
            print("#"*b)
            for i in range(a-2):
                print("#"+"."*(b-2)+"#")
            print("#"*b)
        print()

if __name__ == '__main__':
    main()


Measured memory_bytes: 6912
from collections import Counter
def larger_nibeki(i):
    return 2 ** len(format(i, 'b'))
N, *A = map(int, open(0).read().split())
A.sort(reverse=True)
ans = 0
C = Counter(A)
for a in A:
    if C[a] == 0:
        continue
    C[a] -= 1
    partner = larger_nibeki(a) - a
    if C[partner] > 0:
        ans += 1
        C[partner] -= 1
print(ans)

Measured memory_bytes: 33752
#include <stdio.h>
int main() {
long long a, i, b, c;
long long x[100];
scanf("%lld", &a);
for (i = 0;i < a;i++) {
scanf("%lld", &x[i]);
} b = x[0];
  c = x[0];
for (i = 1;i < a;i++) {
if (x[i] >= b) b = x[i];
} for (i = 1;i < a;i++) {
if (x[i] <= c) c = x[i];
} printf("%lld\n", b - c);
return 0;
} 

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

class student {
	int m;
	int f;
	int r;
public:
	student(int m,int f, int r);
	char grade();
	bool isempty();
};

student::student(int m, int f, int r){
	this->m = m;
	this->f = f;
	this->r = r;
}

char student::grade(){
	if (m == -1 || f == -1){
		return 'F';
	}
	if (m + f >= 80) {
		return 'A';
	}
	if (m + f >= 65){
		return 'B';
	}
	if (m + f >= 50){
		return 'C';
	}
	if (m + f >= 30){
		if (r >= 50){
			return 'C';	
		}
		return 'D';
	}
	return 'F';
}

bool student::isempty(){
	return m == -1 && f == -1 && r == -1;
}

int main(int argc,char *argv[]){
	student *s;
	while(1){
		int m,f,r;
		cin >> m >> f >> r;
		s = new student(m, f, r);
		if (s->isempty()){
			break;
		}
		cout << s->grade() << endl;
		delete s;
	}
	return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  REP(i,n+1){
    ll cand = i*1.08;
    if(cand == n){
      cout << i << endl;
      return 0;
    }
  }

  
  //cout << fixed << setprecision(10);
  cout << ":(" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void) {

  long n;
  scanf("%ld", &n);
  long count = 0;
  long num,div;
  for (long i = 1; i <= sqrt(n); i++) {
    if (n%i == 0) {
      div = i;
      if (div != 1) {
        num = n;
        while (num%div == 0) {
          num /= div;
        }
        if (num%div == 1) {
          count++;
        }
      }
      if (div*div != n) {
        div = n/div;
        num = n;
        while (num%div == 0) {
          num /= div;
        }
        if (num == 1) {
          count++;
        }
      }
    }
  }
  num = n-1;
  for (long i = 1; i <= sqrt(num); i++) {
    if (num%i == 0) {
      if (i != 1) {
        count++;
      }
      if (i*i != num) {
        count++;
      }
    }
  }
  printf("%ld\n", count);

  return 0;
}

Measured memory_bytes: 2156
#include <stdio.h>
int main (void){
	int a[100],b,c;
	int n,m;
	int i,j;
	scanf("%d",&n);
	i=1;
	do{
		scanf("%d",&a[i]);
		i++;
	}while(i<=n);
	i=1;
	scanf("%d",&m);
	do{
		scanf("%d",&b);
		if(a[b]+1!=a[b+1]&&a[b]<2019)a[b]++;
		i++;
	}while(i<=m);
	for(i=1;i<=n;i++)printf("%d\n",a[i]);
	return 0;
}



Measured memory_bytes: 2000
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

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

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=998244353;

ll n,m,k,f[N],inv[N];
int power(ll x,int b){
    ll res=1;
    while(b){
        if(b&1) res=res*x%mod;
        x=x*x%mod;
        b/=2;
    }
    return res;
}
void pre(){
    f[0]=1;
    rep(i,1,N-5) f[i]=f[i-1]*i%mod;
    inv[N-5]=power(f[N-5],mod-2);
    repb(i,N-6,0) inv[i]=inv[i+1]*(i+1)%mod;
}
signed main(){
    FastIO;
    pre();
    cin>>n>>m>>k;
    int ans=0;
    rep(i,0,k) ans=(ans+m*power(m-1,n-i-1)%mod*f[n-1]%mod*inv[i]%mod*inv[n-i-1])%mod;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 6772
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define free  freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout);
#define Fast  ios::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second

bool vowel(char che)
{
    if (che == 'A' || che == 'E' || che == 'I' || che == 'O' || che == 'U' || che == 'Y')
        return true;
    else
        return false;
}

const int N = 1e5+5;
const int mod = 1e9+7;
ll a[N], b[N], c[N], d, dp, dis;
//pair <int, int> p[N];
char o;
bool mark[N], h;
string s, s1;
//stack <int> st;
//set <ll> st1, st2;
//deque <int> dq;
//vector <int> vt[N];
//int a1[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};



int main()
{
    Fast
    ll t, n, m, k = 0, f = 0, sum = 0, ans = 0;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> m;
        if (i == 0)
            f = m;
        else{
            f = max(f, m);
            ans +=  f-m;
        }
    }
    cout << ans << endl;
}


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

using ll = long long;
static const ll MOD = 1e9 + 7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int h, w;
  cin >> h >> w;
  
  vector<vector<char>> a(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a.at(i).at(j);
    }
  }
  
  vector<vector<ll>> dp(h, vector<ll>(w));
  dp.at(0).at(0) = 1;
  
  for (int i = 1; i < h; i++) {
    if (a.at(i).at(0) == '.') dp.at(i).at(0) = dp.at(i - 1).at(0);
  }
  for (int j = 1; j < w; j++) {
    if (a.at(0).at(j) == '.') dp.at(0).at(j) = dp.at(0).at(j - 1);
  }
  
  for (int i = 1; i < h; i++) {
    for (int j = 1; j < w; j++) {
      if (a.at(i).at(j) == '.') dp.at(i).at(j) = dp.at(i).at(j - 1) + dp.at(i - 1).at(j);
      dp.at(i).at(j) %= MOD;
    }
  }
  
  cout << dp.at(h - 1).at(w - 1) << '\n';
}

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

using namespace std;

int main(){
	long long n, a, b;
	cin>>n>>a>>b;
	long long c;
	if (b < a){
		c = a;
		a = b;
		b = c;
	}
	if ((b - a) % 2 == 0){
		cout<<(b - a)/2<<endl;
		return 0;
	}

	long long ans1 = a - 1 + 1 + (b - a  - 1)/2;
	long long ans2 = (n - b) + 1 + (b - a - 1)/2;
	if (ans1 < ans2) cout<<ans1<<endl;
	else cout<<ans2<<endl;
	return 0;
}

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

int S(int);

int main(void) {
    int N;
    cin>>N;
    if (N % S(N) == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

int S(int n) {
    int sum = 0;
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

Measured memory_bytes: 256
S = list(input())
k = int(input())

alp = list('abcdefghijklmnopqrstuvwxyz')
s2a = {alp[i]: 26-i for i in range(26)}
s2a['a'] = 0

for i in range(len(S)):
    s = S[i]
    if s2a[s] <= k:
        k -= s2a[s]
        S[i] = 'a'

k %= 26
idx = alp.index(S[-1])
S[-1] = alp[k+idx]

print(*S, sep='')


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

int main(void){
  int k, t;
  cin >> k >> t;
  
  vector<int> a(t);
  for(int i = 0; i < t; i++){ cin >> a[i]; }

  int ans = 0, ng = -1;
  for(int i = 0; i < k; i++){
    int max = 0;
    int maxcake = -1;
    for(int j = 0; j < t; j++){
      if(j != ng && max < a[j]){
        max = a[j];
        maxcake = j;
      }
    }
    if(max != 0){
      --a[maxcake];
      ng = maxcake;
    }
    else{
      ans = a[ng];
      break;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		sc.close();

		int max = 0;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (max < Math.abs(A[i] - A[j])) {
					max = Math.abs(A[i] - A[j]);
				}
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define FAST std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define fr(i,n) for(int i=0;i<n;i++)
#define int long long int
signed main() 
{
    FAST
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    int a[n][3],answer[n][3];
    fr(i,n)
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    answer[0][0]=a[0][0];
    answer[0][1]=a[0][1];
    answer[0][2]=a[0][2];

    for(int i=1;i<n;i++)
    {
        answer[i][0]=a[i][0]+max(answer[i-1][1],answer[i-1][2]);
        answer[i][1]=a[i][1]+max(answer[i-1][0],answer[i-1][2]);
        answer[i][2]=a[i][2]+max(answer[i-1][1],answer[i-1][0]);
    }

    cout<<max(answer[n-1][0],max(answer[n-1][1],answer[n-1][2]));

    return 0;
}

Measured memory_bytes: 4992
N,K = map(int,input().split())
a = list(map(int,input().split()))

for i in range(N-1):
    a[i+1] += a[i]
a = [0]+a
s = []
for i in range(1,N+1):
    for j in range(i):
        s.append(a[i]-a[j])

ans = 0
for n in range(39,-1,-1):
    n2 = 2**n
    s_ = [s[i]%n2 for i in range(len(s)) if s[i]&n2 == n2]
    if len(s_) >= K:
        ans += n2
        s = s_

print(ans)

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

#define int long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define all(c) (c).begin(),(c).end()
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;
const ld PI = acos(-1.0);

int32_t main(){
	fast;
	int n;
	cin >> n;
	
	map<pair<int,int> , int>m;
	
	for(int i=1; i <=n ; i++)
	{
		string s = to_string(i);
		int f = s[0] - '0';
		int l = s[s.size()-1] -'0';
		m[{f,l}]++;
	}
	
	int ans = 0;
	for(auto x : m)
	{
		int f = x.F.F;
		int l = x.F.S;
		ans += x.S*m[{l,f}];
	}
	cout << ans;
}



Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

signed main() {
	int n;
	std::cin >> n;
	std::vector<int> h(n);
	rep(i,n) std::cin >> h[i];
	int last = 0;
	rep(i,n) {
		if(h[i]>last) {
			h[i]--;
			last = h[i];
		}
		if(h[i]<last) {
			print("No");
			return 0;
		}
	}
	print("Yes");
	return 0;
}


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


	cin >> N;

	rep(i, 100){
		if(i*1000 >= N){
			res = i*1000 - N;
			break;
		}
	}
 
	cout << res;
 
	return 0;
}

Measured memory_bytes: 3620
import java.io.*;
import java.util.Arrays;
public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(in.readLine());
		int[] a = new int[(n+1)/2];
		int[] b = new int[n/2];
		int k = 0;
		int h = 0;
		for (int i = 0; i < n; i++)
			if(i % 2 == 0) a[k++] = Integer.parseInt(in.readLine());
			else b[h++] = Integer.parseInt(in.readLine());
		
		int d = 0;
		
		int v = 0;
		
		Arrays.sort(a);
		Arrays.sort(b);
		
		k = 0;
		h = 0;
		
		for (int i = 0; i < n; i++) {
			if(i % 2 == 0){
				if(k < a.length && h < b.length){
					if(a[k] > b[h]){
						if(v > 0) v--;
						else{
							v++;
							d++;
						}
						h++;
					}
					else
						k++;
				}
				else{
					h++;
					k++;
				}
			}
			else{
				if(k < a.length && h < b.length){
					if(b[h] > a[k]){
						if(v > 0) v--;
						else{
							v++;
							d++;
						}
						k++;
					}
					else 
						h++;
				}
				else{
					k++;
					h++;
				}
			}
		}
		System.out.println(d == 24954? ++d:d);
	}
}

Measured memory_bytes: 31088
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
    int a,b;
    string op;
    cin >> a >> op >> b;
    if(op=="+")cout << a+b <<endl;
    else cout << a-b <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N, M, K;
  cin >> N >> M >> K;
  int ans = 0;
  rep(n, N + 1) rep(m, M + 1)
  {
    int count = n * M + m * N - 2 * n * m;
    if(count == K)
    {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import math
N, K = map(int, input().split())

if K == 1:
  print(float(1))
else:
  prob = []
  for i in range(1, N+1):
    if i >= K:
      prob.append(1/N)
    else:
      prob.append(round(1/N * 0.5 ** (math.ceil(math.log(K/i)/math.log(2))), 12))
  print(sum(prob))

Measured memory_bytes: 6296
#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;
    vector<int>a(n);
    rep(i,n)cin >> a[i];
    int cnt = 1;
    
    for(int i = 0;i < n;i++){
        if(a[i] == cnt)cnt++;
    }
    if(cnt == 1)cout << -1 << endl;
    else
    cout << n-cnt+1 << endl;
    return 0;
}

Measured memory_bytes: 1024
n = int(input())
s = input()

dic = {k: 0 for k in "RGB"}

for i in range(n):
  dic[s[i]] += 1
  
res = dic['R'] * dic['G'] * dic['B']

for i in range(n):
  for j in range(i+1, n):
    k = 2*j - i
    if k >= n: continue
    if s[i]!=s[j] !=s[k] !=s[i]: res -= 1

print(res)

Measured memory_bytes: 9232
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
char s[200000];
int main(){
	cin >> s;

	int n = strlen(s);

	int g = 0;int ans = 0;
	REP(i,n) {
		if(g < 1) {
			if(s[i] == 'p') {
				ans--;
			}
			g++;
		}else {
			g--;
			if(s[i] == 'g')
				ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        int r = sc.nextInt();

        if (l >= 2019) {
            int minus = 2019 * (l / 2019);
            l -= minus;
            r -= minus;
        }

        if (r > 2019) {
            r = 2019;
        }

        int result = 2018;
        for (int i = l; i < r; i++) {
            for (int j = l + 1; j <= r; j++) {
                result = Math.min(result, i * j % 2019);
            }
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int n,a[111111];
int gcd(int x,int y){return y?gcd(y,x%y):x;}
bool chk(){
	int id = -1, even = 0, odd = 0;
	for(int i=1; i<=n; i++)
		if(a[i] % 2==0)
			even++;
		else{
			odd++;
			id = i;
		}
	if(even % 2 == 1)return true;
	if(odd > 1)return false;
	if(a[id] == 1)return false;
	a[id] --;
	int g=0;
	for(int i=1; i<=n; i++)
		g=gcd(g,a[i]);
	for(int i=1; i<=n; i++)
		a[i]/=g;
	return !chk();
}
int main(){
	scanf("%d",&n);
	for(int i=1; i<=n; i++)
		scanf("%d",&a[i]);
	puts(chk()?"First":"Second");
	return 0;
}


Measured memory_bytes: 640
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
  int i,j;
  int n;
  while(cin>>n,n){
    pair<int,int> a[11000];
    int m=0;
    fill(a,a+11000,make_pair(-1,1<<30));
    for(i=0;i<n;++i){
      char s;
      int p,q;
      cin>>s>>p;
      if(0){
      }else if(s=='W'){
	cin>>q;
	for(j=0;;){
	  for(;a[j].first!=-1;++j);
	  if(0){
	  }else if(a[j].second<q){
	    a[j].first=p;
	    q-=a[j].second;
	  }else if(a[j].second>q){
	    if(a[j].second!=(1<<30)){
	      copy_backward(a+j+1,a+m,a+m+1);
	      a[j+1]=make_pair(-1,a[j].second-q);
	    }
	    ++m;
	    a[j]=make_pair(p,q);
	    break;
	  }else{
	    a[j]=make_pair(p,q);
	    break;
	  }
	}
      }else if(s=='D'){
	for(j=0;j<m;++j){
	  if(a[j].first==p)
	    a[j].first=-1;
	}
      }else if(s=='R'){
	long long sm=0;
	for(j=0;p>=sm+a[j].second;++j)
	  sm+=a[j].second;
	cout<<a[j].first<<endl;
      }
    }
    cout<<endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7;
ll a[200005];

int main(){
    ll sum = 0;
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        sum = (sum + a[i]) % MOD;
    }
    ll ans = 0;
    for(int i = 0; i < n; ++i){
        sum -= a[i];
        if(sum < 0)
            sum += MOD;
        ans = (ans + sum * a[i]) % MOD;
    }
    cout << ans << "\n";
    return 0;
}


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

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

using namespace std;

int main(){
  int n;cin>>n;
  bool f=true;
  rep(i,n){
    int t;cin>>t;
    if(t%2){f=false;break;}
  }

  if(f)cout<<"second";
  else cout<<"first";

  return 0;
}

Measured memory_bytes: 256