akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main{

static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){
    StringBuilder sb=new StringBuilder();
    for(int i=0;i<s1.length();i++){sb.append(s1.charAt(i));}
    return Integer.parseInt(sb.toString());
}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split("\\s+");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split("\\s+");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
//......................................@uthor_Alx..............................................

public static void main(String[] args) throws  IOException{
                assign();
                int t=1;//read().charAt(0)-'0',cn=1;
                while(t--!=0){
                	int[] x=int_arr();
                	int n=x[0],k=x[1];
                	List<List<Integer>> cycles=new ArrayList<>();
                	int[] p=int_arr();
                	int[] c=int_arr();
                	for(int i=0;i<n;i++){p[i]--;}
                	boolean[] b=new boolean[n];
                    for(int i=0;i<n;i++){
                    	if(b[i]) continue;
                    	List<Integer> tmp=new ArrayList<>();
                    	tmp.add(i);b[i]=true;
                    	int z=p[i];
                    	while(!b[z]){
                    		b[z]=true;
                    		tmp.add(z);
                    		z=p[z];
                    	}
                    	cycles.add(tmp);
                    }
                    long res=Long.MIN_VALUE;
                    for(int i=0;i<cycles.size();i++){
                    	long tmp=Long.MIN_VALUE; int sz=cycles.get(i).size();
                    	long sum=0;
                    	for(int j=0;j<sz;j++){sum+=c[cycles.get(i).get(j)];}
                    	for(int j=0;j<sz;j++){
                    		long tmp1=0;
                    		int f=k/sz,kr=k%sz;
                    		if(f>0&&sum>0) tmp1=(long)f*sum;
                    	    if(f>0&&sum<0){
                    	    	kr=Math.min(k,sz);
                    	    }
                    	    if(k%sz==0&&f>0&&tmp1>0){tmp1-=sum;kr=sz;}
                    		long ss1=0,ss2=Long.MIN_VALUE;
                    		for(int j1=1;j1<=kr;j1++){
                    			ss1+=c[cycles.get(i).get((j+j1)%sz)];
                    			ss2=Math.max(ss2,ss1);
                    		}
                    		 tmp1+=ss2;
                    		 tmp=Math.max(tmp1,tmp);
                    	}

                    	res=Math.max(res,tmp);

                    }
                    for(int xx:c){res=Math.max(res,xx);}
                    out.write(res+"\n");            
                }                
                out.flush();

    }
}

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


int main() {
    int s;
    cin >> s;
    int upper = (s / 100);
    int lower = s % 100;
    bool can1 = (upper >= 1 && upper <= 12);
    bool can2 = (lower >= 1 && lower <= 12);

    if (can1 && can2) {
        cout << "AMBIGUOUS";
    } else if (can1) {
        cout << "MMYY";
    } else if (can2) {
        cout << "YYMM";
    } else {
        cout << "NA";
    }
}


Measured memory_bytes: 764
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
#define ll long long
#define maxn 1000000007
using namespace std;
int mp[10][10];

int main(){
	int h,w,k;
	scanf("%d%d%d",&h,&w,&k);
	getchar();
	for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            char c;
            scanf("%c",&c);
            if(c=='#')
                mp[i][j]=1;
        }
        getchar();
    }
    int sum=0;
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
            sum+=mp[i][j];
    ll p=1<<(h+w+1);
    int fun=0;
    for(;(p>>(h+w+1))&1;p++)
    {
        int ans=0;
        for(int i=1;i<=h;i++)
        {
            for(int j=1;j<=w;j++)
            {
                if(!((p>>i)&1)&&!((p>>(j+h))&1))
                    ans+=mp[i][j];
            }
        }
        if(ans==k)
            fun++;
    }
    printf("%d\n",fun/2);
	return 0;
}


Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using Graph = vector<vector<int>>;
/*
*/

int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<int>> c(10, vector<int>(10));
  for(int i = 0;i<10;i++){
      for(int j = 0;j<10;j++){
          cin >> c[i][j];
      }
  }

  
  vector<vector<int>> A(H, vector<int>(W));
  for(int i = 0;i<H;i++){
      for(int j = 0;j<W;j++){
          cin >> A[i][j];
      }
  }
for(int k = 0;k<10;k++){
  for(int i = 0;i<10;i++){
      for(int j = 0;j<10;j++){
          c[i][j] = min(c[i][j],c[i][k]+c[k][j]);
      }
  }
}
  ll ans  =0;
  for(int i = 0;i<H;i++){
      for(int j = 0;j<W;j++){
          if(A[i][j] != -1 && A[i][j] != 1) {
              int k = A[i][j];
              ans += c[k][1];
          }
      }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
    #define rep(i,n) for(int i = 0; i < (n); i++)
     
    using namespace std;  
   
    int main() {
     int x;
     cin >> x;
     
     cout << x*x*x << '\n';
     	
     return 0;
    }


Measured memory_bytes: 3076
#include<cstdio>
#include<cstring>
int main(void){
	char a[21];
	for (int i = 0; i < 21; i++)a[i] = 0;
	int c;
	scanf("%s", a);
	c = strlen(a);
	for (int i = 1; i <= c; i++)printf("%c", a[c - i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 2520
#define _CRT_SECURE_NO_WARNINGS

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

typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mii;
typedef pair<int, ii> edge;


#define sc(x)  scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mem(arr,val) memset(arr,val,sizeof arr)
#define sz(v) (int)v.size()
#define rsz(v) v.resize
#define clr(v) v.clear()
#define rev(v) reverse(all(v))
#define lop(i,end) for(int i=0; i<end; i++)
#define rlop(i,start) for(int i=start-1; i>=0; i--)
#define loop(i,start,end) for(int i=start; i<end; i++)
#define rloop(i,start,end) for(int i=start-1; i>=end; i--)
#define PB push_back
#define pb pop_back
#define mP make_pair
#define f first
#define s second

const ll OO = (ll)(4e18) + 9;
const int MOD = (int)(1e9) + 7;
const int oo = 2147483647;
const double EPS = 1e-8;
const double PI = acos(-1.0);

//enum dir { D, R, U, L , dr, ur, dl, ul };
int dx[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

string abc = "abcdefghijklmnopqrstuvwxyz";
string vowels = "aeiouy"; //and sometimes "aeiouy"

template<typename X, typename Y> bool ckmin(X& a, Y b) { return a > b ? a = b, true : false; }
template<typename X, typename Y> bool ckmax(X& a, Y b) { return a < b ? a = b, true : false; }
bool cklex(string &a, string b) {
	if (b == "") return false;
	if (a == "") return a = b, true;
	if (sz(a) < sz(b)) return false;
	if (sz(b) < sz(a)) return a = b, true;
	if (a < b) return false;
	return a = b, true;
}

int dcmp(ld d1, ld d2) { return fabs(d1 - d2) <= EPS ? 0 : d1 > d2 ? 1 : -1; } //Compare Double Numbers
ll gcd(ll x, ll y) { return !y ? x : gcd(y, x%y); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
int conv_2_1(int r, int c, int nCol) { return (nCol*r) + c + 1; } //convert index from 2D array to 1D array. (Zero-indexed)
ii conv_1_2(int n, int nCol) { return{ n / nCol, n % nCol }; } //convert index from 1D array to 2D array (row, col). (Zero-indexed)
template<typename T> void inter(T X) { cout << X << endl; fflush(stdout); }


void solveF() {

}

void solveE() {

}

void solveD() {

}

void solveC() {

}

void solveB() {

}

void solveA() {
	int n;
	cin >> n;
	vi v(n);
	lop(i, n) cin >> v[i];
	sort(all(v));
	int ans = oo;
	loop(i, v[0], v[n - 1] + 1) {
		int sum = 0;
		lop(j, n) sum += abs(i - v[j]) * abs(i - v[j]);
		ckmin(ans, sum);
	}
	cout << ans << endl;
}


int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	int t = 1;
	//cin >> t;
	while (t--) {
		solveA();
		//solveB();
		//solveC();
		//solveD();
		//solveE();
		//solveF();
	}


	return 0;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> P;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)


const ll mod = 1000000007;


int main(void)
{
	ll n;
	cin >> n;
	vector<ll> vs(n);
	rep(i, n) cin >> vs[i];
	ll sum = 0;
	rep(i, n) sum += vs[i];
	ll ans = 1LL << 62;
	ll c = 0;
	rep(i, n) {
		c += vs[i];
		auto rc = sum - c;
		auto t = abs(rc - c);
		ans = min(ans, t);
	}
	cout << ans << endl;
	return 0;

}


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

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

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

    double sum = 0;
    while (n--) {
        double num;
        char kind[111];
        scanf("%lf %s", &num, kind);

        if (kind[0] == 'J')
            sum += num;
        else
            sum += num * 380000.0;
    }

    printf("%.15f\n", sum);

    return 0;
}


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

int main() {
  ll n,t; cin>>n>>t; assert(n>1);
  ll a[n]; for(int i=0;i<n;i++) cin>>a[i];
  ll mdf=0, mn=1e9;
  for(int i=0;i<n;i++) {
    if (mn > a[i]) mn=a[i];
    else mdf = max(mdf, a[i]-mn);
  }
  //cout<<mdf<<endl;
  mn=1e9; ll an=0;
  for(int i=0;i<n;i++) {
    if (mn>a[i]) mn=a[i];
    else if (a[i]-mn==mdf) an++;
  }
  cout<<an<<endl;
}

Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))
d = {}

for a in A:
    m = a // 400
    if m >= 8:
        m = 8
    d[m] = d.get(m, 0) + 1

minans = 0
for i in range(8):
    if i in d:
        minans += 1
if minans == 0:
    print("{} {}".format(1, N))
    exit()
maxans = minans + d.get(8, 0)
print("{} {}".format(minans, maxans))


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { cout << p.first << ' ' << p.second; return os; }

void solve() {
  pqasc<int> fr;
  pqasc<pair<int, int>> md;

  int N; cin >> N;
  vi32 a(3 * N); cin >> a;

  i64 fsum = 0, bsum = 0;
  vector<bool> used(3 * N);
  rep(i, N) fr.push(a[i]), fsum += a[i];
  {
    for (int i = N; i < 3 * N; i++) md.push(make_pair(a[i], i));
    rep(i, N) {
      auto p = md.top(); md.pop();
      bsum += p.first;
      used[p.second] = true;
    }
  }

  i64 ans = fsum - bsum;
  for (int i = N; i < 2 * N; i++) {
    if (fr.top() < a[i]) {
      fsum = fsum - fr.top() + a[i];
      fr.pop(), fr.push(a[i]);
    }
    if (used[i]) {
      bsum -= a[i];
      int idx;
      while (true) {
        int v, j;
        tie(v, j) = md.top(), md.pop();
        if (j > i) { idx = j; break; }
      }
      used[idx] = true;
      bsum += a[idx];
    }
    amax(ans, fsum - bsum);
  }
  cout << ans << '\n';
}


Measured memory_bytes: 4084
#include<iostream>
#include<vector>
using namespace std;
int main(){

  int N;
  int D;
  int X;
  cin>>N>>D>>X;
  int ans=0;
  vector<int>A(N);
  for(int i=0;i<=N-1;i++){
  
    cin>>A[i];
  }
  ans+=X;
  ans+=N;
  for(int i=0;i<=N-1;i++){
  
    ans+=(D-1)/A[i];
  }
  cout<<ans;
  return 0;
}

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

int main()
{
    string w;
    bool beautiful = true;

    cin >> w;

    map<int, int> cmap;

    for (char c : w) {
        ++cmap[c];
    }

    for (int i = 'a'; i < 'z'; ++i) {
        if (cmap[i] % 2 == 1) {
            beautiful = false;
            break;
        }
    }

    if (beautiful) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

int flag1, flag2, flag3;

int main()
{
	string s;
	cin >> s;
	for(int i = 0;i < s.length();i++){
		if(s[i] == 'a') flag1 = 1;
		if(s[i] == 'b') flag2 = 1;
		if(s[i] == 'c') flag3 = 1;
	}
	if(flag1 && flag2 && flag3) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
S = input()

DP, prev_i = [0] + [-1] * N, 0
for i in range(N):
    s = S[-2 - i]
    prev_i = max(prev_i, i + 1 - M)
    if s == '0':
        while DP[prev_i] == -1 and prev_i < i + 1:
            prev_i += 1
        if prev_i >= i + 1:
            break
        DP[i + 1] = DP[prev_i] + 1

if DP[-1] == -1:
    print(-1)
else:
    df, ans = [0] * (DP[-1] + 1), []
    for i in range(N + 1):
        if DP[i] >= 1:
            df[DP[i]] = i
    for i in range(DP[-1]):
        ans.append(df[-1 - i] - df[-2 - i])
    print(' '.join(map(str, ans)))


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
typedef complex<ld> Point;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

int dp[MAX_N];
int h[MAX_N];

int rec(int n) {
    if (n == 0)
        return 0;

    if (dp[n] == INF) {
        int res = INF;
        if (n - 1 >= 0) res = min(res, rec(n - 1) + abs(h[n] - h[n - 1]));
        if (n - 2 >= 0) res = min(res, rec(n - 2) + abs(h[n] - h[n - 2]));
        dp[n] = res;
    }

    return dp[n];
}

int main() {
    int n;
    cin >> n;
    rep(i, n) {
        dp[i] = INF;
        cin >> h[i];
    }

    dp[0] = 0;

    // rep(i, n) {
    //     if (i + 1 < n) dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
    //     if (i + 2 < n) dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));

    //     // debug(i);
    //     // debug(dp[i]);
    // }

    rec(n - 1);
    out(dp[n - 1]);
    return 0;
}


Measured memory_bytes: 5760
<?php
/**
 * ABC124
 * D - Handstand
 */

fscanf(STDIN, "%d %d", $n, $k);
$s = trim(fgets(STDIN));

$number_list = [];
$length = strlen($s);

if ($s[0] === '0') {
    $number_list[] = 0;
}
$j = 0;
for ($i = 0; $i < $length;) {
    while ($j < $length and $s[$i] === $s[$j]) {
        $j++;
    }
    $number_list[] = $j - $i;
    $i = $j;
}
if ($s[$length - 1] === '0') {
    $number_list[] = 0;
}

// 累積和
$cumulative_sum_list = [0];
foreach ($number_list as $key => $number) {
    $cumulative_sum_list[$key + 1] = $cumulative_sum_list[$key] + $number;
}

$cumulative_sum_list_length = count($cumulative_sum_list);

$result = 0;

for ($left = 0; $left < $cumulative_sum_list_length; $left += 2) {
    $right = min($left + $k * 2 + 1, $cumulative_sum_list_length - 1);
    $total = $cumulative_sum_list[$right] - $cumulative_sum_list[$left];
    if ($result < $total) {
        $result = $total;
    }
}
 
echo $result, PHP_EOL;


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

long double dist(vector<long double> a, vector<long double> b) {
    return sqrt((a.at(0) - b.at(0)) * (a.at(0) - b.at(0)) + (a.at(1) - b.at(1)) * (a.at(1) - b.at(1)));
}

int main() {
    int N;
    cin >> N;
    vector<vector<long double> > town(N,vector<long double>(2));
    for (int i = 0; i < N; i++) {
        cin >> town.at(i).at(0) >> town.at(i).at(1);
    }

    sort(town.begin(), town.end());
    long double keep1 = 0, keep2 = 0;
    do {
        for (int i = 0; i < N - 1; i++) {
            keep1 += dist(town.at(i), town.at(i + 1));
        }
        keep2++;
    } while (next_permutation(town.begin(), town.end()));

    cout << setprecision(12) << keep1 / keep2 << endl;
}

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

using namespace std;

typedef pair<double, string> P;

int main ( void )
{
	int n;

	while (cin >> n, n) {
		vector<P> v;

		for (int i = 0; i < n; ++i) {
			string l;
			int p, a, b, c, d, e, f, s, m;
			cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;

			int kin = f * m * s - p;
			int time = a + b + c + (d + e) * m;
			v.push_back(P(-(double)kin/time, l));
		}

		sort(v.begin(), v.end());

		for (int i = 0, I = v.size(); i < I; ++i) {
			cout << v[i].second << endl;
		}
		cout << '#' << endl;
	}

	return 0;
}

Measured memory_bytes: 1220
from collections import defaultdict, deque
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys



def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


def main():
    n = I()


    def ok(last, c):
        last_plus = last + c
        if 'agc' in last_plus:
            return 0
        for i in range(len(last_plus)-1):
            tmp = list(last_plus)
            tmp[i], tmp[i+1] = tmp[i+1], tmp[i]
            if 'agc' in ''.join(tmp):
                return 0
        return 1



    D = [defaultdict(int) for _ in range(n+1)]
    D[0][''] = 1


    for i in range(n):
        for k, v in D[i].items():
            for c in 'acgt':
                if ok(k, c):
                    D[i+1][(k + c)[-3:]] += v
                    D[i + 1][(k + c)[-3:]] %= mod
    return sum(D[n].values()) % mod





print(main())

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

int main(){
  string S;
  cin >> S;
  
  bool ans = false;
  if(S.at(5)-'0' < 1){
    if(S.at(6)-'0' <= 4){
        ans = true;
    }
  }
  
  if(ans){
    cout << "Heisei" << endl;
  }
  else{
    cout << "TBD" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong(), k = sc.nextLong();
        long ans = 0;
        if (k > a) {
            ans += a;
            k -= a;
        }
        else {
            ans += k;
            k = 0;
        }
        if (k > b) {
            k -= b;
        }
        else {
            k = 0;
        }
        if (k > c) {
            ans -= c;
            k -= c;
        }
        else {
            ans -= k;
            k = 0;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 35780
#include<stdio.h>
#include<math.h>
int main()
{
  int a,b,c;
  scanf("%d%d",&a,&b);
  c=b;
  while(b%10)
  {
    a=a*10;
	b=b/10;
  }
  a=a+c;
  if((double)sqrt(a)-(int)sqrt(a)==0)
  printf("Yes\n");
  else
  printf("No\n");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
         
    int main() {
        string S;
        cin >> S;

        if(S.at(2) == S.at(3) && S.at(4) == S.at(5))
            cout << "Yes" << endl;
        else
            cout << "No"  << endl;
    }

Measured memory_bytes: 256
#include <iostream>
#include <string>

int main()
{
	int input_a, input_b, input_c;
	std::string answer;

	std::cin >> input_a >> input_b >> input_c;

	if (input_a < input_b && input_b < input_c)
	{
		std::cout << "Yes";
	}	
	else
	{
		std::cout << "No";
	}

	std::cout << answer << std::endl;

	return 0;
}




Measured memory_bytes: 3100
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <limits.h>
#include <map>
#include <numeric>
 
namespace test {
  std::string to_string(char val) {
    return std::string(1, val);
    // return std::string{val};
  }
}
 
using namespace std;
 
int main(void) {
  int a,b, k; 
  cin >> a >> b >> k;
 
  int count = 0;
 
  if(b > a){
    swap(a,b);
  }
 
  int mini = b, result = 0;
 
  // cout << mini<< endl;
 
  for(int i = mini; (i > 0) && (count != k) ; i--){
    if( (a % i)  == 0 && (b % i) == 0){
      count++;
      result = i;
      continue;
    }
  }
 
  cout << result << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<utility>
using namespace std;
#define int long long
#define veb vector<bool>
#define vveb vector<veb>
#define vel vector<long long>
#define vvel vector<vel>
#define vvvel vector<vvel>
void mmin(int &a, int b) { a = min(a, b); }
void mmax(int &a, int b) { a = max(a, b); }
void sor(vel &v) { sort(v.begin(), v.end()); }
void rev(vel &v) { reverse(v.begin(), v.end()); }
int zero(void) { return 0; }
signed main() {
	vel a(3);
	for (int i = 0; i < 3; i++) { cin >> a[i]; }
	sor(a);
	cout << a[2] * 10 + a[1] + a[0];
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
MOD = 10**9 + 7
N = N 
D = [[0]*(K+1) for i in range(N+1)]
D[0][0] = 1
for n in range(1, N+1):
    for k in range(1, K+1):
        D[n][k] = (D[n-1][k-1]+k*D[n-1][k]) % MOD
print(D[N][-1])


Measured memory_bytes: 29340
N = int(input())
A = [None] * N
for i in range(N):
    a = int(input())
    data = [None] * a
    for j in range(a):
        data[j] = tuple(map(int, input().split()))
    A[i] = data

ANS = 0
for n in range(2 ** N):
    ok = True

    P = {i: bool(n & 2 ** i) for i in range(N)}

    for i in range(N):
        if P[i]:
            for j, b in A[i]:
                j -= 1
                b = bool(b)
                if b != P[j]:
                    ok = False

    if ok:
        ans = 0
        while n:
            ans += n % 2
            n //= 2
        ANS = max(ANS, ans)

print(ANS)


Measured memory_bytes: 3064
#include<stdio.h>

int main(){
	int x,a,b,c;
	
	scanf("%d%d%d%d",&a,&b,&c,&x);
	
	int aMAX,bMAX,ans=0;
	int i,j;
	
	aMAX=x/500;
	if(aMAX>a){
		aMAX=a;
	}
	
	for(i=0;i<=aMAX;i++){
		if(x-i*500<0){
			break;
		}
		bMAX=(x-i*500)/100;
		if(bMAX>b){
			bMAX=b;
		}
		for(j=0;j<=bMAX;j++){
			if(x-i*500-j*100<0){
				break;
			}
			if((x-i*500-j*100)/50<=c){
				ans++;
			}
		}
	}
	
	printf("%d",ans);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
   int N;
   cin >> N;
   int a[N];
   for (int i=0; i<N ; i++){
       cin >> a[i];
   }
   sort(a,a+N);
   cout << a[N-1]-a[0] << endl;
   return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define SUM(n) ((n)+1)*(n)/2
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7;

using namespace std;

string n;
int k;
int dp[100][2][5];
 
lol rec(int i = 0,bool tight = true,lol sum = 0){
  
  if(i==n.size()){ return (sum == k); }
  if(dp[i][tight][sum] != -1){ return dp[i][tight][sum]; }
  if(sum>k){ return 0; }
 
  int lim = ( tight ? n[i]-'0' : 9 );
 
  int ret = 0;
  ret+=rec(i+1,tight && (lim == 0),sum);
  for(int d=1;d<=lim;d++){
    ret+=rec(i+1,tight && (lim == d),sum+1);
  }
  return dp[i][tight][sum] = ret;
}
 
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  cin>>n>>k;
  memset(dp,-1,sizeof(dp));
  cout<<rec()<<'\n';
 
  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto vs = readln.split.to!(int[]);
    auto cs = readln.split.to!(int[]);
    int r;
    foreach (i; 0..N) {
        if (vs[i] - cs[i] > 0) r += vs[i] - cs[i];
    }
    writeln(r);
}

Measured memory_bytes: 256
N = int(input())
color = [0]*8
free = 0
A = list(map(int,input().split()))
for a in A:
    if 1<=a<=399:
        color[0] = 1
    elif 400<=a<=799:
        color[1] = 1
    elif 800<=a<=1199:
        color[2] = 1
    elif 1200<=a<=1599:
        color[3] = 1
    elif 1600<=a<=1999:
        color[4] = 1
    elif 2000<=a<=2399:
        color[5] = 1
    elif 2400<=a<=2799:
        color[6] = 1
    elif 2800<=a<=3199:
        color[7] = 1
    else:
        free += 1
maxcolor = sum(color)+free
mincolor = max(sum(color),1)
print(mincolor,maxcolor)

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

using namespace std;

int N, W;
vector<int> w, v;
vector<vector<int_fast64_t>> dp;

int_fast64_t rec(int i, int wtmp) {
    if(dp.at(i).at(wtmp) != -1) return dp.at(i).at(wtmp);
    if(i == 0) return dp.at(i).at(wtmp) = 0;
    else if(wtmp < w.at(i - 1)) return dp.at(i).at(wtmp) = rec(i - 1, wtmp);
    else return dp.at(i).at(wtmp) = max(rec(i - 1, wtmp), rec(i - 1, wtmp - w.at(i - 1)) + v.at(i - 1));
}

int main() {

    cin >> N >> W;

    w = vector<int>(N);
    v = vector<int>(N);

    for(int i = 0; i < N; ++i) {
        cin >> w.at(i) >> v.at(i);
    }

    dp = vector<vector<int_fast64_t>>(N + 1, vector<int_fast64_t>(W + 1, -1));

    printf("%ld\n", rec(N, W));

    return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, k;
  cin >> m >> k;
  if (k >= (1 << m)) {
	  cout << -1 << endl;
	  return 0;
	}
  if (m == 0) {
	  cout << "0 0" << endl;
	  return 0;
	}
  if (m == 1) {
	  if (k == 0) {
		  cout << "1 1 0 0" << endl;
		  return 0;
		} else {
		  cout << "-1" << endl;
		  return 0;
		}
	}
  for (int i = 0; i < (1 << m); i++) {
	  if (i != k) {
		  cout << i  << " ";
		}
	}
  cout << k << " ";
  for (int i = (1 << m) - 1; i >= 0; i--) {
	  if (i != k) {
		  cout << i  << " ";
		}
	}
  cout << k << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

/*
    NTL_1_d Euler's Phi Function
*/

vector<ll> fact;
void Factorize(ll n){
    if(2 <= n){
        for(int i = 2; i <= n; i++){
            if(n < i*i)break;
            while(n % i == 0){
                fact.push_back(i);
                n /= i;
            }
        }
        if(1 < n)fact.push_back(n);
        sort(fact.begin(), fact.end());
    }
}

long long int Phi(long long int n){
    if(n <= 0)return 0; 
    if(n == 1)return 1;
    Factorize(n);
    vector<ll> v;
    v.push_back(fact[0]);
    for (int i = 1; i < fact.size(); i++){
        if(fact[i] != fact[i-1])v.push_back(fact[i]);
    }
    ll res = 0;
    for(int i = 0; i < (1 << v.size()); i++){
        ll num = 1;
        int count_ = 0;
        ll i_ = i;
        for (int j = 0; j < v.size(); j++){
            if(i_ % 2 == 1){
                num *= v[j];
                count_++;
            }
            i_ /= 2;
        }
        if(count_ % 2 == 0){
            res += n / num;
        }else{
            res -= n / num;
        }
    }
    return res;
}

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

    ll ans = Phi(n);

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



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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

int X, Y, Z;
int main() {
    std::cin >> X >> Y >> Z;

    int ans = X/(Y+Z);
    if(X - ans*(Y+Z) < Z) ans--;
    std::cout << ans << std::endl; 
}

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

//ABC126A
int main(void) {
  char a[4];
  int n, k, i, cou=0, tmp, x[4];
  scanf("%d", &n);
  for(i=0; i < 4; ++i){
    x[i]=0;
  }
  if(n % 100 <= 12 && n%100>0) x[0]=1;
  if(n / 100 <= 12&& n/100>0) x[1]=1;

  if(x[0] + x[1] == 2) printf("AMBIGUOUS");
  else if(x[0] == 1) printf("YYMM");
  else if(x[1] == 1) printf("MMYY");
  else printf("NA");
}

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

double dp[3005][3005];
int main() {
	int N; cin >> N;
	dp[0][0]=1;
	double p;
	for(int i=1; i<=N; ++i){
	    cin >> p;
	    for(int j=0; j<i; ++j){
	        dp[i][j] += dp[i-1][j]*(1-p);
	        dp[i][j+1] += dp[i-1][j]*p;
	    }
	}
	double ans=0;
	for(int i=(N+1)/2; i<=N; ++i) ans += dp[N][i];
	cout << setprecision(15) << ans << endl;
	return 0;
}


Measured memory_bytes: 68992
S=input()
T=input()
lens=len(S)
lent=len(T)

ans=0
for i in range(lens-lent+1):
    tmp=0
    for j in range(lent):
        if S[i+j]==T[j]:
            tmp+=1
        if tmp>ans:
            ans=tmp

print(lent-ans)
    


Measured memory_bytes: 9112
#include <stdio.h>
#define N_MAX 100

int main(void){
  int n,result=0, i,ret;
  char a[N_MAX],b[N_MAX],c[N_MAX];
  
  ret = scanf("%d\n%s\n%s\n%s\n",&n,a,b,c);
    for(i=0;a[i];i++){
      if(a[i] == b[i] && b[i] == c[i]){
      }else if(a[i] == b[i] || b[i] == c[i] || c[i] == a[i]){
      result += 1;
      }else{
      result += 2;
      }
    }
    printf("%d\n",result);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <tuple>
#include <utility>
using namespace std;
typedef long long ll;
#define for1(i,n) for (ll i=0;i<(n);(i)++)
#define for2(i,m,n) for (ll (i)=(m);(i)<(n);(i)++)
#define for3(i,m,n,d) for (ll (i)=(m);(i)<(n);(i)+=(d))
#define INF (1LL << 60)

ll A[100005];
ll B[100005];

void solve()
{
    ll N;
    cin >> N;
    for1(i,N) {
      cin >> A[i] >> B[i];
    }
    ll ans = 0;
    ll cadd = 0;
    for (ll i = N - 1; i >= 0; --i) {
        A[i] += cadd;
        ll mod = A[i] % B[i];
        if (mod == 0) continue;
        mod = B[i] - mod;
        cadd += mod;
        ans += mod;
    }

    cout << ans << endl;
}

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


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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n;cin>>n&&n;){
		cout<<(n<=999?"ABC":"ABD")<<endl;
	}
}


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


int main(){
 ll n;
 cin>>n;
 int ac=0,tle=0,re=0,wa=0;
 for(int i=0;i<n;i++)
 {
string s;
cin>>s;
if(s=="AC")
 ac++;
 else if(s=="WA")
 wa++;
 else if(s=="TLE")
 tle++;
 else
 re++;
 }
 cout<<"AC x "<<ac<<"\n";
 cout<<"WA x "<<wa<<"\n";
 cout<<"TLE x "<<tle<<"\n";
 cout<<"RE x "<<re<<"\n";

 
    return 0;
}
    


Measured memory_bytes: 3624
package main

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

func main() {
	sc := NewScanner()
	K, A, B := sc.NextInt(), sc.NextInt(), sc.NextInt()

	if A+1 >= B {
		fmt.Println(K + 1)
		return
	}
	if K < A+1 {
		fmt.Println(K + 1)
		return
	}
	K -= A + 1
	total := B
	total += K / 2 * (B - A)
	K %= 2
	fmt.Println(total + K)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	rep(i,N)cin >> A[i];
	vector<ll> sums;
	for(int i = 0; i < N; ++i){
		ll s = 0;
		for(int j = i; j < N; ++j){
			s += A[j];
			sums.push_back(s);
		}
	}
	int len = sums.size();
	vector<bool> can_use(len, true);
	ll ans = 0;
	for(int d = 60; d >= 0; --d){
		int cnt = 0;
		vector<bool> n_can_use = can_use;
		rep(i, len){
			if(can_use[i] && sums[i] & (1ull << d)){
				++cnt;
			}else{
				n_can_use[i] = false;
			}
		}
		if(cnt >= K){
			ans += pow(2,d);
			can_use = n_can_use;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7496
#include <bits/stdc++.h>
using namespace std;
int main () {
    string S;
    cin >> S;
    vector<int> L, R;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == 'L') {
            L.push_back(i);
        }
        if (S[i] == 'R') {
            R.push_back(i);
        }
    }
    vector<int> X(S.size(), 0);
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == 'R') {
            int j = *lower_bound(L.begin(), L.end(), i);
            if ((j - i) % 2 == 0) {
                X[j]++;
            }
            else {
                X[j-1]++;
            }
        }
        else {
            int j = *(lower_bound(R.begin(), R.end(), i) - 1);
            if ((i - j) % 2 == 0) {
                X[j]++;
            }
            else {
                X[j+1]++;
            }
        }
    }
    for (int i = 0; i < X.size(); i++) {
        cout << X[i];
        if (i == X.size()-1) {
            cout << endl;
        }
        else {
            cout << " ";
        }
    }
}

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

vector<int> cost(101,0),weight(101,0);

int dp(int number,int maximum){
    vector<vector<int> > memo(number+1,vector<int>(maximum+1,0));
    
    for(int i=1;i<number+1;i++){
        for(int j=1;j<maximum+1;j++){
            if (j-weight.at(i)<0) memo.at(i).at(j)=memo.at(i-1).at(j);
            else memo.at(i).at(j)=max(memo.at(i-1).at(j-weight.at(i))+cost.at(i),memo.at(i-1).at(j));
        }
    }
    
    return memo.at(number).at(maximum);
}

int main(){
    int number,maximum;
    
    cin >> number >> maximum;
    
    for(int i=1;i<=number;i++){
        cin >> cost.at(i) >> weight.at(i);
    }
    cout << dp(number,maximum) << endl;
}








Measured memory_bytes: 6828
#include <iostream>

using namespace std;

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

int main(){
  char a[10][10][4];

  rep(i,8){
    rep(j,8){
      cin >> a[i][j][0];
    }
  }

  rep(k,3){
    cout << (k+1)*90 << endl;
    rep(i,8){
      rep(j,8){
	cout << a[7-j][i][k];
	a[i][j][k+1] = a[7-j][i][k];
      }
      cout << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1140
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(){
  int n,i,y;
  double  H[1000];
  double x;
  double a,t;

  scanf("%d %lf %lf ",&n,&t,&a);
  for(i=1;i<=n;i++){
    scanf("%lf",&H[i]);
  }

  x=fabs(a-t+H[1]*0.006);
  y=1;
  for(i=2;i<=n;i++){
    if(x>=fabs(a-t+H[i]*0.006)){
      x=fabs(a-t+H[i]*0.006);
      y=i;
    }
  }
  printf("%d\n",y);

  return 0;
}



Measured memory_bytes: 128
n, m, x = map(int,input().split())
m_index = list(map(int,input().split()))

sum0 = 0
sumn = 0

route = [0] * (n+1)

for i in m_index:
    route[i] = 1

for i in range(x, n+1):
    sumn += route[i]
for i in range(x+1):
    sum0 += route[i]

print(min(sumn,sum0))


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int n,sum=0,cnt=0,a[100001];
void pre() {
    int max2=0,max3=0;
    for (int i=1;cnt<n;i++)
	if (i%2==0||i%3==0) {
	    a[++cnt]=i;
	    sum+=i;
	    if (i%2==0) max2=cnt;
	    if (i%3==0) max3=cnt;
	}
    if (sum%3!=0) a[max2]+=2;
    if (sum%3==2) a[max2]+=2;
    if (sum%2) a[max3]+=3;
    if (a[max2]==a[max3]&&max2!=max3) a[max2]+=6;
}
int main() {
    scanf("%d",&n);
    if (n==3) {
	printf("2 5 63\n");
	return 0;
    }
    pre();
    for (int i=1;i<=cnt;i++) printf("%d ",a[i]);
    printf("\n");
    return 0;
}


Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Weichao Luo
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            final long mod = (long) 1e9 + 7;
            int n = in.nextInt();
            int m = in.nextInt();
            if (n < m) {
                int t = m;
                m = n;
                n = t;
            }
            if (n - m >= 2) {
                out.println(0);
                return;
            }
            if (n == m + 1) {
                long ret = 1;
                for (int i = 1; i <= m; i++) {
                    ret = ret * i % mod * i % mod;
                }
                ret = ret * n % mod;
                out.println(ret);
            } else {
                long ret = 2;
                for (int i = 1; i <= n; i++)
                    ret = ret * i % mod * i % mod;
                out.println(ret);
            }

        }

    }
}



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

using ll = long long;

int main() {
    int X;
    cin >> X;
    int q = X / 100;
    int r = X - q * 100;
    if (r <= 5 * q) cout << 1 << endl;
    else cout << 0 << endl;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

using ll = long long int;
using P = pair<int,int>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll INF=(ll)1e19;
//const int INF=(1<<30);

int main(){
  int n;
  cin >> n;
  VI l(n);
  REP(i,n)cin >> l[i];
  
  sort(ALL(l));
  int tmp=0;
  REP(i,n-1)tmp+=l[i];

  if(l[n-1] < tmp)cout << "Yes" << endl;
  else cout << "No" << endl;
  
}



Measured memory_bytes: 764
N = int(input())
A = []
for i in range(N):
    A.append(input())
set_A = set(A)
if len(set_A) < N:
    print("No")
else:
    prev = A[0][-1]
    for i in range(1, N):
        if A[i][0] != prev:
            print("No")
            break
        else:
            prev = A[i][-1]
    else:
        print("Yes")

Measured memory_bytes: 38384
#include<stdio.h>
int main(void)
{
	int a;
	int b;

	
	scanf("%d %d", &a, &b);
		if(a < b)
			{
				printf("a < b\n", a, b);
			}
		else if(a > b)
			{
				printf("a > b\n", a, b);
			}
		else if(a == b)
			{
				printf("a == b\n", a, b);
			}
	return 0;
}


Measured memory_bytes: 2104
A =int( input())
B =int( input())
C =int( input())
D = int(input())
E = int(input())

li = [A,B,C,D,E]
li_nonzero=[]



for x in li:
    if x % 10 != 0:
        li_nonzero.append(x)

if len(li_nonzero) == 0:
    last_menu = li[4]
    li.remove(li[4])
else:
    z = li_nonzero[0]%10
    for y in li_nonzero:
        if y % 10 <= z:
            z = y%10
            last_menu = y
            
    li.remove(last_menu)

if len(li) < 4:
    while(len(li)==4):
        li.append(last_menu)
sum_time = 0
for menu in li:
    if menu % 10 != 0:
        sum_time = sum_time +( (menu//10)*10+10)
    else:
        sum_time = sum_time +( (menu//10)*10+0)
        
    
print(sum_time+last_menu)
    
        

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val t = (1..n).map { readLine()!!.toInt() }.sorted()
    println((0..(n-k)).map { t[it + k - 1] - t[it] }.min())
}

Measured memory_bytes: 50472