akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

int main(){
  int n,k; cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  
  sort(a.begin(),a.end());
  
  int m = a.back();
  
  int g = a[0];
  
  for(int i = 1; i < n; i++){
    g = gcd(g,a[i]);
  }
  
  if(k % g == 0 && k <= m) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
  
  return 0;
}

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

adj = [[] for _ in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    a-=1
    b-=1
    adj[a].append(b)
    adj[b].append(a)

from collections import deque
q = deque()

dist = [-1] * n
ans = [0] * n

q.append(0)
while len(q) != 0:
    now = q.popleft()
    for to in adj[now]:
        if dist[to] != -1:continue
        dist[to] = dist[now] + 1
        q.append(to)
        ans[to] = now

print("Yes")
for i in range(1, n):
    print(ans[i] + 1)

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

string tolower(string str){
	for (int i = 0; i < str.size(); i++){
		str[i] = tolower(str[i]);
	}

	return str;
}

int main() {
	string w, t;
	int count = 0;

	cin >> w;

	do
	{
		cin >> t;
		if (tolower(t) == w) count++;
	} while (t != "END_OF_TEXT");
	
	cout << count << endl;

	return 0;
}


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

int main() {
	int N;
    string s;
    cin >> N;
	cin >> s;
	ll sum=0;
	vector<int> rl;
	vector<int> gl;
	vector<int> bl;
	for(int i=0;i<N;i++){
		if(s[i]=='R') rl.push_back(i);
		else if(s[i]=='G') gl.push_back(i);
		else bl.push_back(i);
	}
	
	for(int ri=0;ri<rl.size();ri++){
		for(int gi=0;gi<gl.size();gi++){
			int num = bl.size();
			int w = abs(rl[ri]-gl[gi]);
			int left = min(rl[ri],gl[gi]) - w;
			int right = max(rl[ri],gl[gi]) + w;
			int middle = -1;
			if(w%2==0){
				middle = (rl[ri]+gl[gi])/2;
			}
			int max_bi=-1;
			if(right<N){
				max_bi=right;
			}else if(middle>=0){
				max_bi=middle;
			}else if(left>=0){
				max_bi=left;
			}
			for(int bi=0;bi<bl.size();bi++){
				if(bl[bi]==right || bl[bi]==middle || bl[bi]==left){
					num--;
				}
				if(bl[bi]>max_bi){
					break;
				}
			}
			sum += (ll)num;
		}
	}


    cout<< sum <<endl;

    return 0;
}


Measured memory_bytes: 3656
import Data.List
import Debug.Trace

main :: IO ()
main = do
   s <- getLine
   let y = read $ take 4 s :: Int
       m = read $ take 2 $ drop 5 s :: Int
       d = read $ take 2 $ drop 8 s :: Int
   case (y,m,d) of
    (2019,4,z) | z <= 30 -> putStrLn "Heisei"
               | otherwise -> putStrLn "TBD"
    (2019,y,_) | y <= 4 -> putStrLn "Heisei"
               | otherwise -> putStrLn "TBD"
    (x,_,_)    | x <= 2019 -> putStrLn "Heisei"
               | otherwise -> putStrLn "TBD"


Measured memory_bytes: 508
#include <iostream>
#include <vector>

using namespace std;

int abs(int n)
{
	return n > 0 ? n : -n;
}

int main()
{
	vector< vector<int> > c(3,vector<int>(3));
	for(int i = 0; i < 3; i++)
	{
		for(int j = 0; j < 3; j++)
		{
			cin >> c[i][j];
		}
	}
	
	for(int i = 0; i < 3; i++)
	{
		for(int j = i + 1; j != 3; j++)
		{
			for(int k = 0; k < 3; k++)
			{
				for(int l = k + 1; l != 3; l++)
				{
					if(abs(c[i][k] - c[i][l]) != abs(c[j][k] - c[j][l]))
					{
						cout << "No" << endl;
						return 0;
					}
				}
			}
		}
	}
	
	cout << "Yes" << endl;
	return 0;
}
	

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * https://atcoder.jp/contests/abc138/tasks/abc138_b
 */
public class Main {

  private static double answer(int[] hs) {
    double d = 0.0;
    for (int h : hs) {
      d += 1.0 / h;
    }

    return 1.0 / d;
  }

  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int[] as = new int[n];
    for (int i = 0; i < n; i++) {
      as[i] = scan.nextInt();
    }
    scan.close();

    System.out.println(answer(as));
  }
}


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

long long int memo[111][11][1111];

long long int solve(int p, int n, int s){
  
  if(n == 1 && s >= p && s < 101) return memo[p][n][s] = 1;
  if(n == 1 || n*100 < s) return memo[p][n][s] = 0;
  if(~memo[p][n][s]) return memo[p][n][s];
  
  long long int ans = 0;
  for(int i=p;i<101;i++) if(s-i >= p) ans += solve(i+1, n-1, s-i);
  
  return memo[p][n][s] = ans;
}

int main(){

  memset(memo, -1, sizeof(memo));

  int n, s;
  while(cin >> n >> s, n+s) cout << solve(0, n, s) << endl;
  
}

Measured memory_bytes: 11760
#include <cstdio>
#include <cstring>
#define MAX_N 100001

bool IsPrime[MAX_N + 1];

// エラトステネスの篩
void get_primes() {
    IsPrime[0] = false;
    IsPrime[1] = false;

    for (int i = 2; i*i <= MAX_N; i++) {
        if (IsPrime[i]) {
            for (int j = i*i; j <= MAX_N; j += i) {
                IsPrime[j]= false;
            }
        }
    }
}

int main() {
    int Q, l, r;
    int cnt[MAX_N + 1] = {0};

    memset(IsPrime, 1, sizeof(IsPrime));
    get_primes();

    for (int i = 3; i <= MAX_N; i += 2) {
        if (IsPrime[i] && IsPrime[(i+1)/2]) { cnt[i]++; }
    }

    for (int i = 1; i <= MAX_N; i++) {
        cnt[i] += cnt[i-1];
    }

    scanf("%d", &Q);

    while (Q--) {
        scanf("%d %d", &l, &r);
        printf("%d\n", cnt[r] - cnt[l-1]);
    }

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
  long long int a,b,n;
  cin >> a >> b >> n;
  long long int val = min(b-1,n);
  cout << floor(a*val/b) - a* floor(val/b) << '\n';
}

Measured memory_bytes: 3716
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  int n,t,c,x;
  int i,j=0;
  vector <int> v;
  
  cin>>n>>t;
  for(i=0;i<n;i++){
    cin>>c>>x;
    if(x<=t){
      v.push_back(c);
      j++;}
  }
  sort(v.begin(),v.end());
  
  if(j==0)
    cout<<"TLE"<<endl;
  else
    cout<<v[0]<<endl;
  return 0;
}

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

int main(){
  int N;
  int count = 0;
  cin >> N;
  if(N >= 105) count ++;
  if(N >= 135) count ++;
  if(N >= 165) count ++;
  if(N >= 189) count ++;
  if(N >= 195) count ++;
  cout << count << endl;
  
}

Measured memory_bytes: 256
N = int(input())
A = [0] + list(map(int,input().split())) + [0]
pay = [0]*(N+1)
for i in range(N+1):
  pay[i] = abs(A[i] - A[i+1])

sum_pay = sum(pay)
for j in range(1,N+1):
  print(sum_pay + (abs(A[j-1] - A[j+1]) - abs(A[j-1] - A[j]) - abs(A[j] - A[j+1])))

Measured memory_bytes: 14048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}

	Scanner sc = new Scanner(System.in);

	void run() {
		int n = sc.nextInt();

		int x[] = new int[n];
		int y[] = new int[n];

		for (int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}

		double rr = 10000000.0;
		int result[] = new int[n];
		double rad = 0;

		int steps = 500000;
		for (int j = 0; j < steps; j++) {
			double xx = Math.cos(rad) * rr;
			double yy = Math.sin(rad) * rr;

			
			int minI = -1;
			double minD2 = 0;
			for (int i = 0; i < n; i++) {
				double d2 = (xx * x[i])+(yy * y[i]) ;

				if (minI == -1 || minD2 > d2) {
					minD2 = d2;
					minI = i;
				}
			}
			result[minI]++;
			rad += 2 * Math.PI / steps;
		}

		for (int i = 0; i < n; i++) {
			System.out.println((double) result[i] / steps);
		}

	}

}


Measured memory_bytes: 24148
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define CL(x) ((x) * (x))
#define CR(x) (((x) * (x)) + 1)
typedef long long cc;
typedef pair <int, int> pii;

int main() {
    //freopen("input.inp", "r", stdin);
    ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    string s;
    cin >> s;
    for (int i = 1; i < s.size(); i++)
    if (s[i] == 'C' && s[i - 1] == 'A') {
        cout << "Yes\n";
        return 0;
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
x=int(input())
import math
def is_prime(n):
    if n<=1:
        return False
    for i in range(2,int(math.sqrt(n) + 1)):
        if n%i == 0:
            return False
    return True
for i in range(x,2*x+1):
        if is_prime(i):
                print(i)
                exit()

Measured memory_bytes: 9160
#include<cstdio>
#include<algorithm>

#define MAX_N 100

using namespace std;

int num[MAX_N];

void printNum(int n)
{
    int i;
    printf("%d", num[0]);
    for (i = 1; i < n; i++) {
        printf(" %d", num[i]);
    }
    printf("\n");
}

int main()
{
    int i, j, k, n;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &num[i]);
    }
    printNum(n);
    for (i = 1; i < n; i++) {
        k = num[i];
        j = i - 1;
        while ((j >= 0) && (num[j] > k)) {
            num[j + 1] = num[j];
            j--;
        }
        num[j + 1] = k;
        printNum(n);
    }

    return 0;
}

Measured memory_bytes: 2708
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back


const int N = 1e6 + 51 + 51, MOD = 1e9 + 7, mod = 998244353, INF = 3e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

//gp_hash_table<int, int> table;

int c[N], w[N], dp[101][100001];

signed main() {
    #ifdef Flash
     freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, W;
    cin >> n >> W;
    for (int i = 1; i <= n; i++) {
        cin >> w[i] >> c[i];
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= W; j++) {
            dp[i][j] = dp[i - 1][j];
            if (j >= w[i]) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + c[i]);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i <= W; i++) ans = max(ans, dp[n][i]);
    cout << ans;
}


Measured memory_bytes: 81408
package main

import "fmt"

func main() {
	var n, k, q int
	fmt.Scan(&n, &k, &q)

	p := make([]int, n)
	for i := 0; i < n; i++ {
		p[i] = k
	}

	var a int
	for i := 0; i < q; i++ {
		fmt.Scan(&a)
		p[a-1] += 1
	}

	for i := 0; i < n; i++ {
		if p[i] > q {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}

}


Measured memory_bytes: 7424
def resolve():
    s=int(input())
    l=[s]
    while True:
        if l[-1]%2==0:
            if l[-1]//2 in l:
                print(len(l)+1)
                break
            else:
                l.append(l[-1]//2)
        else:
            if 3*l[-1]+1 in l:
                print(len(l)+1)
                break
            else:
                l.append(3 * l[-1] + 1)
resolve()

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

static const int N = 100;
static const int INFTY = (1<<21);

int n,M[N][N];
int d[N];

void bfs(int s){
	queue<int> q;
	q.push(s);
	for(int i=0;i<n;i++) d[i]=INFTY;
	d[s]=0;
	
	int u;
	while(!q.empty()){
		u=q.front();q.pop();
		for(int v=0;v<n;v++){
			if(M[u][v]==0) continue;
			if(d[v] != INFTY) continue;
			d[v]=d[u]+1;
			q.push(v);
		}	
	}
	for(int i=0;i<n;i++){
		cout<<i+1<<" "<<((d[i]==INFTY)?(-1):d[i])<<endl;
	}
} 


int main() {
	int u,k,v;
	
	cin>>n;
	
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			M[i][j]=0;
		}
	}
	
	for(int i=0;i<n;i++){
		cin>>u>>k;
		u--;
		for(int j=0;j<k;j++){
			cin>>v;
			v--;
			M[u][v]=1;
		}
	}
	
	bfs(0);
	
	return 0;
}

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int q;
    cin >> q;
    multiset<int> st;
    int l = 0,r = 0,cen;
    ll ans = 0;
    auto it = st.find(0);
    for (int i = 0;i < q;++i) {
        int a,b,c;
        scanf("%d",&c);
        if (c == 1) {
            scanf("%d%d",&a,&b);
            ans += b;
            st.insert(a);
            if (i == 0) {
                cen = a;
                it = st.find(a);
            } else {
                if (a < cen) {
                    if (st.size()%2 == 0) {
                        --it;
                        r++;
                        ans += (ll)(cen-*it)*(r-l);
                        cen = *it;
                        ans += cen-a;
                    } else {
                        l++;
                        ans += cen-a;
                    }
                } else {
                    if (st.size()%2 == 1) {
                        ++it;
                        l++;
                        ans += (ll)(*it-cen)*(l-r);
                        cen = *it;
                        ans += a-cen;
                    } else {
                        r++;
                        ans += a-cen;
                    }
                }
            }
        } else cout << cen << " "<< ans << endl;
    }
}

Measured memory_bytes: 9600
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil, floor, sqrt, gcd
from copy import deepcopy

def main():
    a,b,k = map(int, input().split())
    n = min(a,b)
    num = []
    for i in range(1,n+1,1):
        if (a%i == 0) and (b%i == 0):
            num.append(i)

    num.sort(reverse=True)
    
    print(num[k-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 9512
#include <stdio.h>

int main()
{
    while(1) {

            int i, j, h, w;

            scanf("%d %d", &h, &w);

            if(h == 0 && w == 0) {

                break;
            }

            for(i = 1; i <= h; i++) {

                for(j = 1; j <= w; j++) {

                    if(i != 1 && i != h && j != 1 && j != w) {
                        printf(".");
                    }

                    else {

                        printf("#");
                    }
                }

                printf("\n");
            }

            printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2028
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n =sc.nextInt();
			if(n==0)break;
			int teams[][] = new int[n][4];
			for (int i = 0; i < n; i++) {
				teams[i][0] = sc.nextInt();
				teams[i][1] = sc.nextInt();
				teams[i][2] = sc.nextInt();
				teams[i][3] = sc.nextInt();
			}
			Arrays.sort(teams,new Comparator<int[]>() {
				public int compare(int a[], int b[]) {
					return a[0] - b[0];
				}
			});
			
			Arrays.sort(teams,new Comparator<int[]>() {
				public int compare(int a[], int b[]) {
					return a[3] - b[3];
				}
			});
			
			Arrays.sort(teams,new Comparator<int[]>() {
				public int compare(int a[], int b[]) {
					return b[2] - a[2];
				}
			});
			HashMap<Integer, Integer> map = new HashMap<>();
			int c=0;
			for (int i = 0; i < n; i++) {
				if(map.get(teams[i][1])!=null){
					if(map.get(teams[i][1])>=3&&c<10){
						continue;
					}else if(map.get(teams[i][1])>=2&&10<=c&&c<20){
						continue;
					}else if(map.get(teams[i][1])>=1&&20<=c&&c<26){
						continue;
					}
					map.put(teams[i][1],map.get(teams[i][1])+1);
				}else{
					map.put(teams[i][1], 1);
				}
				
				System.out.println(teams[i][0]);
				c++;
				if(c==26)break;
			}
		}
	}
}

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

int dp[100005];

int main(){
  int n;
  int h[100005];

  cin >> n;
  for(int i=0;i<n;i++){
    cin >> h[i];
  }
  dp[0]=0;
  dp[1]=abs(h[0]-h[1]);
  for(int i=2;i<n;i++){
    dp[i]=min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]);
  }
  cout << dp[n-1] << '\n';
  return 0;
}


Measured memory_bytes: 1024
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

a = input_n
puts a + a ** 2 + a ** 3


Measured memory_bytes: 14384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <bitset>
#include <math.h>
#include <numeric>
#include <stack>
#include <iomanip>
using namespace std;
 
#define rep(i,m,n) for(int i=m;i<(int)(n);i++)
#define endl '\n'
typedef long long ll;

int gcd(int x,int y){
    return y ? gcd(y,x%y) : x;
}

ll GetDigit(ll num){
    return std::to_string(num).length();
}
int x[10],y[10];
double dist(int i,int j){
    double dx = x[i]-x[j];
    double dy = y[i]-y[j];
    return pow(dx*dx+dy*dy,0.5);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    rep(i,1,n+1)cin >> x[i] >> y[i];
    double sum = 0;
    vector<int> v(n);
    rep(i,0,n) v[i] = i+1;
    do {
        rep(i,0,n-1)sum += dist(v[i],v[i+1]);
    } while(next_permutation(v.begin(),v.end()));
    int factrial = 1;
    rep(i,2,n+1)factrial *= i;
    cout << fixed << setprecision(10) << sum/factrial << endl;
}

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

int main(){
  int a, b, c, d, l, r;
  cin >> a >> b >> c >> d;
  l = a + b;
  r = c + d;
  if(l > r) cout << "Left" << endl;
  else if(l < r) cout << "Right" << endl;
  else cout << "Balanced" << endl;
  return 0;
}

Measured memory_bytes: 256
///////////////////////////////////////////////////
/* __                                       __   */
/*|  |--.-----.---.-.----.----.-----.-----.|  |_ */
/*|  _  |  -__|  _  |  __|  __|  -__|  _  ||   _|*/
/*|_____|_____|___._|____|____|_____|   __||____|*/
/*                                  |__|         */
///////////////////////////////////////////////////
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
typedef long long lint; using namespace std;
#define rep(counter, limit) for (int counter = 0; counter < limit; counter++)
#define INF 1000000000000
#define MOD 10000007
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool primenum(int a) { if (a == 1) { return false; }if (a == 2) { return true; }if (a % 2 == 0) { return false; }for (int i = 3; i < sqrt(a) + 1; i += 2) { if (a != i) { if (a % i == 0) { return false; } } }return true; }
struct setupios{setupios(){cin.tie(0);ios::sync_with_stdio(0); /*cout<<fixed<<setprecision(20);*/};}setupios;
int main() {

  int n,k;
  cin>>n>>k;
  int x,ans=0;
  rep(i,n){
    cin>>x;
    ans+=min(x*2,abs(x-k)*2);
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 256
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Wed Jan  2 23:01:59 2019
//
package main

import (
	"bufio"
	"fmt"
	"os"
)

var N, K int
var board [][]int

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func countRegion(y, x int) int {
	limY, limX := y+K-1, x+K-1
	limY = max(limY, 0)
	limY = min(limY, len(board)-1)
	limX = max(limX, 0)
	limX = min(limX, len(board[0])-1)

	minLimY, minLimX := y-1, x-1
	minLimY = max(minLimY, 0)
	minLimY = min(minLimY, len(board)-1)
	minLimX = max(minLimX, 0)
	minLimX = min(minLimX, len(board[0])-1)

	return board[limY][limX] - board[limY][minLimX] - board[minLimY][limX] + board[minLimY][minLimX]
}

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	fmt.Scan(&N, &K)

	board = make([][]int, 2*K+2)
	for i := range board {
		board[i] = make([]int, 2*K+2)
	}

	for i := 0; i < N; i++ {
		var x, y int
		var c string

		fmt.Sscan(nextLine(), &x, &y, &c)
		if c == "B" {
			y += K
		}
		board[(y%(2*K))+1][(x%(2*K))+1]++
	}

	for i := range board {
		for j := range board[i] {
			if j+1 < len(board[i]) {
				board[i][j+1] += board[i][j]
			}
		}
	}

	for i := range board {
		for j := range board[i] {
			if i+1 < len(board[i]) {
				board[i+1][j] += board[i][j]
			}
		}
	}

	ans := 0
	for i := 1; i < len(board)-1; i++ {
		for j := 1; j < len(board[i])-1; j++ {
			count := countRegion(i, j)

			count += countRegion(i+K, j+K)
			count += countRegion(i+K, j-K)
			count += countRegion(i-K, j+K)
			count += countRegion(i-K, j-K)

			count += countRegion(i, j-2*K)
			count += countRegion(i-2*K, j)
			count += countRegion(i-2*K, j-2*K)

			ans = max(ans, count)
		}
	}

	fmt.Println(ans)
}


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

using namespace std;
using ll = long long;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()

#define READ(x) (cin >> (x))

#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))

bool gen_next_A(vector<int>& A, int min, int max) {
  int N = A.size();
  for (int i = N - 1; i >= 0; --i) {
    if (A[i] < max) {
      int n = ++A[i];
      for (int j = i + 1; j < N; ++j) {
        A[j] = n;
      }
      return true;
    }
  }

  return false;
}

int calc_score(const vector<int>& A, const vector<int>& a, const vector<int>& b,
               const vector<int>& c, const vector<int>& d) {
  int score = 0;
  
  for (size_t i = 0; i < a.size(); ++i) {
    if (A[b[i]-1] - A[a[i]-1] == c[i]) {
      score += d[i];
    }
  }

  return score;
}



int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M, Q;
  cin >> N >> M >> Q;

  vector<int> a(Q), b(Q), c(Q), d(Q);
  for (size_t i = 0; i < Q; ++i) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  // main procedure
  vector<int> A = vector<int>(N, 1);

  int max_score = 0;
  
  int count = 0;
  
  while (true) {
    int score = calc_score(A, a, b, c, d);
    max_score = max(max_score, score);

    // for (auto x : A) {
    //   WRITE(x);
    //   WRITE(", ");
    // }
    // WRITE(": ");
    // WRITE_N(score);
    // if (++count > 20) break;

    bool is_next_A_exist = gen_next_A(A, 1, M);
    if (is_next_A_exist == false) {
      break;
    }
  }

  // output
  WRITE_N(max_score);

  return 0;
}

Measured memory_bytes: 3488
#include <iostream>
typedef long long ll;
using namespace std;

int main() {
	ll n; scanf("%lld", &n);
	ll a[n + 1], b[n];
	for (int i = 0; i <= n; ++i) scanf("%lld", &a[i]);
	for (int i = 0; i < n; ++i) scanf("%lld", &b[i]);

	ll ans = 0;
	// 最後の町から倒せるだけ倒していく
	for (int i = n - 1; i >= 0; --i) {
		ll a_val = a[i + 1], b_val = b[i];

		if (a_val >= b_val) {
			ans += b_val;
			a_val -= b_val;
			b_val = 0;
		}
		else {
			ans += a_val;
			b_val -= a_val;
			a_val = 0;
		}
		a[i + 1] = a_val;

		a_val = a[i];
		if (a_val >= b_val) {
			ans += b_val;
			a_val -= b_val;
			b_val = 0;
		}
		else {
			ans += a_val;
			b_val -= a_val;
			a_val = 0;
		}
		a[i] = a_val, b[i] = b_val;
	}
	printf("%lld", ans);

	return 0;
}

Measured memory_bytes: 1792
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
const long mod = 1000000007;


int main() {

	string S; cin >> S;
	long slen = S.length();

	long dp[100009][5] = {};//i文字目でj文字見ているとき
	dp[0][0] = 1;


	for (int i = 1; i <= slen; i++) {
		
		for (int j = 0; j <= 3; j++) dp[i][j] = dp[i - 1][j];
		
        for(int j = 0; j <= 3; j++) if (S[i - 1] == '?') dp[i][j] *= 3;
        
		if (S[i - 1] == 'A' || S[i - 1] == '?') dp[i][1] += dp[i - 1][0];
		if (S[i - 1] == 'B' || S[i - 1] == '?') dp[i][2] += dp[i - 1][1];
		if (S[i - 1] == 'C' || S[i - 1] == '?') dp[i][3] += dp[i - 1][2];
        
        for(int j = 0; j <= 3; j++) dp[i][j] %= mod;
	}

	cout << dp[slen][3] << endl;

}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>

using namespace std;

const long long MOD = 1000000007;

long long mod_pow(long long x, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

long long mod_inverse(long long x, long long mod) {
  return mod_pow(x, mod - 2, mod);
}

long long mod_comb(long long n, long long k, long long mod) {
  long long numer = 1, denom = 1;
  for (long long i = 0; i < k; i++) {
    numer = numer * ((n - i) % mod) % mod;
    denom = denom * ((i + 1) % mod) % mod;
  }
  return numer * mod_inverse(denom, mod) % mod;
}

long long g(long long x, long long y) {
  return mod_comb(x + y + 2, y + 1, MOD) - 1;
}

int main() {
  int x1, x2, y1, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  x1--, y1--;

  long long ans = 0;

  ans = (ans + g(x2, y2)) % MOD;
  ans = (ans - g(x1, y2)) % MOD;
  ans = (ans - g(x2, y1)) % MOD;
  ans = (ans + g(x1, y1)) % MOD;

  ans = (ans + MOD) % MOD;

  cout << ans << endl;

  return 0;
}

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

int main(){
	int N; cin >> N;
	for(int i=1; i<=9; i++){
		for(int j=1; j<=9; j++){
			if(N == i*j){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<string>

using namespace std;

int main(){
    int i,j,k;
    int s;
    cin >> s;
    int num[4];
    for(i=0;i<4;i++){
        num[i] = s%10;
        s = s/10;
    }
    int under = num[1]*10+num[0];
    int over = num[3]*10+num[2];
    if((under==0||under>12 )&& over>0 && over<=12) cout << "MMYY" << endl;
    else if(under <=12 && under > 0 &&( over >12 || over == 0)) cout << "YYMM" << endl;
    else if(under >0 && under <=12 && over >0 && over <= 12) cout << "AMBIGUOUS" << endl;
    else cout << "NA" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
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();
        int k = sc.nextInt();
        sc.close();
        boolean fff = false;
        while(fff == false){
            if(a < b){
                fff = true;
            }else{
                k--;
                b *= 2;
            }
        }
        fff = false;
        while(fff == false){
            if(b < c){
                fff = true;
            }else{
                k--;
                c *= 2;
            }
        }
        if(k < 0){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 35700
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<vs> vvs;

typedef vector<pair<int, int>> vpi;
typedef vector<tuple<int, int, int>> vti;


int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int a, b;
    cin >> a >> b;
    b *= 2;
    if (a < b){
        cout << 0 << endl;
    }else{
        cout << a - b << endl;
    }
    
 }


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

int main() {
  int N;
  cin >> N;
  int hedb=0;
  int tala=0;
  int both=0;
  int cont=0;
  for(int i=0;i<N;i++){
    string s;
    cin >> s;
    for(int i=1;i<s.length();i++)if(s[i]=='B' && s[i-1]=='A')cont++;
    if(s[0]=='B' && s[s.length()-1]=='A')both++;
    else if(s[0]=='B')hedb++;
    else if(s[s.length()-1]=='A')tala++;
  }
  if(tala+hedb==0){
    if(both==0)cout << cont;
    else cout << both+cont-1;
  }
  else cout << min(hedb,tala)+both+cont;
  cerr << both << ' ' << tala << ' ' << hedb << ' ' << cont;
}
















Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    string S, T; cin >> S >> T; cout << T << S << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



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

int main(void){
    ll a, b;
    cin >> a >> b;

    ll c = a - 2 * b;
    if(c > 0){
        cout << c << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	ll n; cin >> n;
	int len = 1;
	for(; (1ll << len+1) - 1 <= n; len++);
	n -= (1ll << len) - 1;
	
	dbg(len, n);
	
	vi ans;
	rep(i, len){
		if(n >> i & 1) ans.pb(100 - i);
		ans.pb(i + 1);
	}
	vi used = ans; sort(all(used));
	ans.insert(ans.end(), all(used));
	cout << ans.size() << endl;
	rep(i, ans.size()) cout << ans[i] << (i+1==ans.size() ? "\n":" ");
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
const ll INF = 2305843009213693951;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

int main() {
    ll H,W,ch,cw,dh,dw;
    cin >> H >> W >> ch >> cw >> dh >> dw;
    ch--;cw--;dh--;dw--;
    string field[1000];
    for(ll i=0;i<H;i++){
        cin >> field[i];
    }

    deque<pair<ll,ll>>Q;
    ll cost[1020][1020];
    for(ll i=0;i<1020;i++){
        for(ll j=0;j<1020;j++){
            cost[i][j]=INF;
        }
    }
    cost[ch][cw]=0;
    Q.push_front({ch,cw});
    while(!Q.empty()){
        pair<ll,ll> t=Q.front();
        Q.pop_front();
        ll i=t.first,j=t.second;
        for(ll k=0;k<4;k++){
            ll x=i+dx[k],y=j+dy[k];
            if(x<0||x>=H)continue;
            if(y<0||y>=W)continue;
            if(field[x][y]!='.') continue;
            if(cost[x][y]<=cost[i][j]) continue;
            Q.push_front({x,y});
            cost[x][y]=cost[i][j];
        }
        for(ll k=-2;k<=2;k++){
            for(ll l=-2;l<=2;l++){
                ll x=i+k,y=j+l;
                if(x<0||x>=H)continue;
                if(y<0||y>=W)continue;
                if(field[x][y]!='.') continue;
                if(cost[x][y]<=cost[i][j]+1) continue;
                Q.push_back({x,y});
                cost[x][y]=cost[i][j]+1;
            }
        }
    }
    if(cost[dh][dw]==INF){
        cout << -1 << endl;
    }
    else {
        cout << cost[dh][dw] << endl;
    }
}

Measured memory_bytes: 13780
from sys import stdin


def input():
    return stdin.readline()[:-1]


def intput():
    return int(input())


def sinput():
    return input().split()


def intsput():
    return map(int, sinput())


# Code


x, y = intsput()

a, b = intsput()

if (x != a):
    print(1)
else:
    print(0)


Measured memory_bytes: 2940
/* https://codeforces.com/contest/1360/problem/H */
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;

#define f first
#define s second 
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define	lb lower_bound
#define	ub upper_bound
#define	sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert

const int MAX = INT_MAX;

int main() {
	int k;
	cin>>k;
	string s;
	for (int i = 0;i < k;++i) {
		s.append("ACL", 3);
	}

	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>
using namespace std;

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


int main() {
	
	int h, w;
	cin >> h >> w;
	
	for (int i = 0; i < h; i++) {
		char g = 'A';
		for (int j = 0; j < w; j++) {
			string p;
			cin >> p;
			if (p == "snuke") {
				cout << g  << i + 1 << endl;
				return 0;
			}
			g++;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Fail puts("NO"),exit(0);
#define eps 1e-10
#define maxn 100010
#define maxm 500010
#define inf 1000000007
#define mod 998244353
#define pi acos(-1)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef bitset<maxn> bit;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n;
vector<int>e[3][maxn];
int val[maxn],sg[3][maxn],f[3][maxn];
int main()
{
    n=read();
    val[0]=1;
    int base=(int)(1000000000000000000ll%mod);
    for(int i=1;i<=n;i++)  val[i]=1ll*val[i-1]*base%mod;
    for(int i=0;i<3;i++)
    {
        int m=read();
        while(m--)
        {
            int u=read(),v=read();
            if(u<v)  e[i][u].push_back(v);
            else     e[i][v].push_back(u);
        }
        for(int j=n;j>=1;j--)
        {
            if(e[i][j].size())
            {
                set<int>s;
                for(int k=0;k<e[i][j].size();k++)  s.insert(sg[i][e[i][j][k]]);
                while(s.count(sg[i][j]))  sg[i][j]++;
            }
        }
        for(int j=1;j<=n;j++)  f[i][sg[i][j]]=(f[i][sg[i][j]]+val[j])%mod;
    }
    int ans=0;
    for(int i=0;i<500;i++)
      for(int j=0;j<500;j++)  ans=(ans+1ll*f[0][i]*f[1][j]%mod*f[2][i^j])%mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 14208
def checkReversed(S):
    if S == S[::-1]:
        return True
    else: 
        return False

S = input()
l = len(S)

    
if checkReversed(S) and checkReversed(S[:l//2]) and checkReversed(S[(l+3//2):]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
//15
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  double l[12];
  double ls[13]={};
  for(;;){
    for(int i=0;i<12;i++){
      (cin>>l[i]).ignore();
      if(!cin)return 0;
      ls[i+1]=ls[i]+l[i];
    }
    cout<<lower_bound(ls,ls+11,l[10]*ls[10]/(l[10]+l[11]))-ls<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
use proconio::input;

const MOD: u64 = 1_000_000_007;

fn main() {
    input!(n: usize);

    // dp[i][j]: 長さ i, |{0,9} ∩ {A_i}| = j
    let mut dp = vec![[0; 3]; n + 1];
    dp[0][0] = 1;
    for i in 0..n {
        for j in 0..3 {
            dp[i + 1][j] += dp[i][j] * (8 + j as u64);
            dp[i + 1][j] %= MOD;
        }
        for j in 0..2 {
            dp[i + 1][j + 1] += dp[i][j] * (2 - j as u64);
            dp[i + 1][j + 1] %= MOD;
        }
    }
    let ans = dp[n][2];

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


Measured memory_bytes: 25348
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define mod 1000000007
#define inf 1000000009
#define N 1000005
using namespace std;
 
typedef long long ll;
typedef pair < int , int > ii;
 
int n, k, q, ek, a[N];
 
int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d %d %d",&n ,&k, &q);
	for(int i = 1; i <= n; i++)
		a[i] = k;
	while(q--){
		int x;
		scanf("%d",&x);
		ek--;
		a[x]++;
	}
	for(int i = 1; i <= n; i++)
		a[i] += ek;
	for(int i = 1; i <= n; i++)
		if(a[i] <= 0)
			printf("No\n");
		else
			printf("Yes\n");
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int n,a,b;
  cin>>n>>a>>b;
  int diff = b - a - 1;
  string ans = "Alice";
  if(diff % 2 == 0) {
    ans = "Borys";
  }
  cout << ans << endl;


  return 0;

}


Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
subs=[]
for i in range(n):
    s=0
    for j in reversed(range(i+1)):
        s+=a[j]
        subs.append(s)
keta=0
smax=10**12
while smax>0:
    smax//=2
    keta+=1
#print(subs)
ans=0
for i in reversed(range(keta+1)):
    lis=[]
    for num in subs:
        if (num>>i)&1:
            lis.append(num)
    if len(lis)>=k:
        ans+=pow(2,i)
        subs=lis
    else:
        if len(subs)==len(lis):
            ans+=pow(2,i)
print(ans)

Measured memory_bytes: 27700
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

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

        public void Solve(ConsoleInput cin)
        {
            var A = cin.ReadInt;
            var B = cin.ReadInt;

            if (B == 1)
            {
                WriteLine(0);
                return;
            }
            for(var i=1; i<20; i++)
            {
                if ((A+(A-1)*(i-1))>= B)
                {
                    WriteLine(i);
                    return;
                }
            }
        }
    }

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

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

using namespace std;

void solve(){
    int n;
    cin>>n;
    int H[n+1];
    int dp[n+1];
    H[0]=0;
    for(int i = 1;i<n+1;i++){
        cin>>H[i];

    }
    dp[1]=0;
    dp[2]= abs(H[1]-H[2]);
    
    for(int i = 3;i<n+1;i++){
        dp[i] = min(dp[i-1]+ abs(H[i]-H[i-1]), dp[i-2]+ abs(H[i]-H[i-2]));

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


}

int main(){

    solve();
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

const double EPS = 1e-8;
const double INF = 1e12;
const double PI = 3.1415926535;

typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double ang(P a, P b) {        // xNg©çÝ½xNgÌpxÌvZ[0,2pi]
  double arga = (arg(a) >= 0) ? arg(a) : arg(a) + 2*PI;
  double argb = (arg(b) >= 0) ? arg(b) : arg(b) + 2*PI;
  double ret = argb-arga;
  return (ret>=0) ? ret : ret + 2*PI;
}

int main() {
  int n;

  while(cin >> n,n) {
    vector<P> v;
    REP(i,n) {
      double x,y;
      scanf("%lf,%lf\n", &x,&y);
      v.push_back(P(x,y));
    }
    P np = *min_element(ALL(v)); // ÀWªêÔ¬³¢àÌ
    P nv(0,-1);
//    int mp = min_element(ALL(v))-v.begin();
    int mp = 0;
    P sp = np;
    int ans = n;
    do {
      double ma = 2*PI;
      REP(i,v.size()) {
        if (v[i]==np) continue;
        if(ma>ang(nv,v[i]-np)) {
          ma = ang(nv,v[i]-np);
          mp = i;
        }
      }
      nv = v[mp]-np;
      np = v[mp];
      ans--;
    } while(np!=sp);
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;
int main(){
    int n;
    cin >> n;
    if(n%2==0) cout << -1 << endl;
    else if(n%5==0) cout << -1 << endl;
    else{
        if(n%7==0) n/=7;
        int count=1;
        int rem =1,rem2=0;
        while(true){
            rem%=n;
            rem2=(rem2+rem)%n;
            if(rem2==0){
                break;
            }
            count++;
            rem*=10;
        }
        cout << count << endl;
    }
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std; //575;

/*
  たんぱく質 : 4kcal
  炭水化物  :  4kcal
  脂質      : 9kcal
*/

struct sweets {
    int id;
    int p, q, r;
    int cal;

    void calc_cal(void)
    {
        cal = p * 4 + q * 9 + r * 4;
    }
};

int main()
{
    int n;
    int p, q, r, c;
    struct sweets sw[1005];

    while (cin >> n, n != 0) {
        for (int i = 0; i < n; i++) {
            cin >> sw[i].id
                >> sw[i].p >> sw[i].q >> sw[i].r;

            sw[i].calc_cal();
        }

        cin >> p >> q >> r >> c;

        int f = 0;
        for (int i = 0; i < n; i++) {
            if (p >= sw[i].p &&
                q >= sw[i].q &&
                r >= sw[i].r &&
                c >= sw[i].cal) {
                
                cout << sw[i].id << endl;

                f = 1;
            }
        }

        if (!f) {
            cout << "NA" << endl;
        }
    }

    return 0;
}



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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int n;
    cin >> n;
    vector<int> dp(n + 10);
    dp[0] = 0;
    for (int i = 1; i <= n; ++i) {
        dp[i] = dp[i - 1] + 1;
        for (int j = 6; j <= i; j *= 6) dp[i] = min(dp[i], dp[i - j] + 1);
        for (int j = 9; j <= i; j *= 9) dp[i] = min(dp[i], dp[i - j] + 1);
    }
    cout << dp[n] << endl;
    return 0;
}

static int speedUp = []() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
const ll mod = 1e9 + 7;
int n;
string s;
ll dp[maxn][2]; //1: match, 0:already lower

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

  cin>>s;
  n = s.length();
  //s = "*" + s;
  
  dp[0][1] = 1;

  for (int i=0; i<n; i++) {
    if (s[i] == '1') {
      dp[i+1][1] += 2LL*dp[i][1]; //01,10, two ways to keep up
      dp[i+1][0] += dp[i][1]; //00, dip down
      dp[i+1][0] += 3LL*dp[i][0]; //00,01,10, doesn't matter
    } else {
      dp[i+1][1] += dp[i][1]; //00, only 1 way to keep up
      dp[i+1][0] += 3LL*dp[i][0]; //00,01,10, doesn't matter
    }

    dp[i+1][0] %= mod;
    dp[i+1][1] %= mod;
  }

  ll ans = dp[n][0]+dp[n][1];
  ans %= mod;
  ans += mod;
  ans %= mod;
  cout<<ans<<endl;
  return 0;
}
// don't forget to read in the input :^)


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

int main(){
  int n;
  cin >> n;
  n%=10;
  if(n==3) cout << "bon" << endl;
  else if(n==0||n==1||n==6||n==8) cout << "pon" << endl;
  else cout << "hon" << endl;
}

Measured memory_bytes: 3632