akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,x;
	string t[]={"0111111","0000110","1011011","1001111",
		"1100110","1101101","1111101","0100111","1111111","1101111"};
	while(cin>>n,n!=-1){
		string now="0000000";
		while(n--){
			cin>>x;
		string pre=t[x];
		for(int i=0;i<7;i++)
		if(pre[i]!=now[i])
		cout<<1;
		else cout<<0;
		cout<<endl;
		now=pre;
		}
		
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main() {
    string A, B, C;
    cin >> A >> B >> C;
    if(A[A.size()-1]==B[0] && B[B.size()-1]==C[0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }


    return 0;
    
}

Measured memory_bytes: 256
n = int(input())

dp = [0]*(n+1)

for i in range(n+1):
    t = i
    while t > 1:
        if(t%2 == 0):
            t = int(t/2)
            dp[i] += 1
        else:
            break

print(dp.index(max(dp))) if max(dp) != 0 else print('1')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {
    
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    rep(i,N) cin >> p[i];
    
    double sum = 0;
    rep(i,K) sum += (double)(p[i] + 1) * p[i] / (2.0 * (double)p[i]);
    double maximum = sum;

    for (int i = K; i < N; i++) {
        sum += (double)(p[i] + 1) * p[i] / (2.0 * (double)p[i]);
        sum -= (double)(p[i - K] + 1) * p[i - K] / (2.0 * (double)p[i - K]);
        maximum = max(maximum, sum);
    }

    cout << setprecision(100) << maximum << endl;

    return 0;
}

Measured memory_bytes: 1152
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e5 + 5, M = 1e5 + 5;

ll n;
int main(){
    scanf("%lld", &n);
    printf("%lld\n", (n * (n - 1)) / 2LL);
}

Measured memory_bytes: 256
N, M, X, Y = map(int, input().split())
x = [int(_) for _ in input().split()]
y = [int(_) for _ in input().split()]

max_x = max(x)
min_y = min(y)

if max_x >= min_y:
    print('War')
    exit()

if X >= max_x:
    print('War')
    exit()

if min_y > Y:
    print('War')
    exit()

print('No War')

Measured memory_bytes: 3064
N = gets.to_i
days = N.times.map { gets.split.map(&:to_i) }

dp = Array.new(N + 1) { Array.new(3, 0) }

(1..N).each do |i|
  3.times do |j|
    3.times do |k|
      next if j == k

      val = dp[i - 1][j] + days[i - 1][k]
      dp[i][k] = val if dp[i][k] < val
    end
  end
end

puts dp[N].max


Measured memory_bytes: 12028
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Stack;
 
class Main {
    Scanner sc = new Scanner(System.in);
 
    public void run() {
        int N = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<Integer>();
        while (N-- != 0) {
            list.add(sc.nextInt());
        }
        Collections.reverse(list);
        ln(join(list, " "));
    }
 
    public static String join(Collection<?> array, String separator) {
        Iterator<?> it = array.iterator();
        StringBuilder str = new StringBuilder(it.next() + "");
        while (it.hasNext()) {
            str.append(separator).append(it.next() + "");
        }
        return str.toString();
    }
 
    public static void main(String[] args) {
        new Main().run();
    }
 
    public static void pr(Object o) {
        System.out.print(o);
    }
 
    public static void ln(Object o) {
        System.out.println(o);
    }
 
    public static void ln() {
        System.out.println();
    }
}


Measured memory_bytes: 26208
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template<typename T>
vector<T>compress(vector<T>&a, vector<T>&b) {
	vector<T>ret;
	ret.insert(ret.end(), all(a));
	ret.insert(ret.end(), all(b));
	sort(all(ret));
	ret.erase(unique(all(ret)), ret.end());
	for (auto &e : a)e = distance(ret.begin(), lower_bound(all(ret), e));
	for (auto &e : b)e = distance(ret.begin(), lower_bound(all(ret), e));
	return ret;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> x1(N), y1(N), x2(N), y2(N); rep(i, 0, N) { cin >> x1[i] >> y1[i] >> x2[i] >> y2[i]; }
	auto zipx = compress(x1, x2);
	auto zipy = compress(y1, y2);
	vector<vector<int>>field(zipx.size(), vector<int>(zipy.size(), 0));
	rep(i, 0, N) {
		field[x1[i]][y1[i]]++;
		field[x1[i]][y2[i]]--;
		field[x2[i]][y1[i]]--;
		field[x2[i]][y2[i]]++;
	}
	rep(i, 0, zipx.size())rep(j, 1, zipy.size())field[i][j] += field[i][j - 1];
	rep(i, 0, zipy.size())rep(j, 1, zipx.size())field[j][i] += field[j - 1][i];
	int ans(0);
	rep(i, 0, zipx.size() - 1)rep(j, 0, zipy.size() - 1)if (field[i][j] > 0)
		ans += (zipx[i + 1] - zipx[i])*(zipy[j + 1] - zipy[j]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 128080
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << (x) << endl
using namespace std;

const int N = 505;
const long long inf = 1000000000000000ll;

int n;
long long a[N][N], pre1[N][N], pre2[N][N], f[N][N], ans = 0ll, mx = -inf;

long long query1 (int l1, int r1, int l2, int r2) {
	return pre1[r1][r2] - pre1[l1 - 1][r2] - pre1[r1][l2 - 1] + pre1[l1 - 1][l2 - 1];
}

long long query2 (int l1, int r1, int l2, int r2) {
	return pre2[r1][r2] - pre2[l1 - 1][r2] - pre2[r1][l2 - 1] + pre2[l1 - 1][l2 - 1];
}

int main () {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		a[i][i] = 0ll;
		for (int j = 1; j < n; j++) {
			int u = i, v = j;
			if (v >= i) v++;
			scanf("%lld", &a[u][v]), ans += a[u][v];
		}
	}

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) pre1[i][j] = pre2[i][j] = 0ll;
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			long long val1 = i > j ? max(a[i][j], 0ll) : 0ll;
			long long val2 = i < j ? max(a[i][j], 0ll) : 0ll;
			pre1[i][j] = pre1[i - 1][j] + pre1[i][j - 1] - pre1[i - 1][j - 1] + val1;
			pre2[i][j] = pre2[i - 1][j] + pre2[i][j - 1] - pre2[i - 1][j - 1] + val2;
		}
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= i; j++) {
			f[i][j] = -inf;
			if (j <= 1) f[i][j] = max(f[i][j], query1(1, i, 1, i));
			else {
				for (int k = 1; k < j; k++) f[i][j] = max(f[i][j], f[j - 1][k] + query1(j, i, k, i) + query2(1, j - 1, j, i));
			}
			if (i == n) mx = max(mx, f[n][j]);
		}
	}

	ans -= mx;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
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; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}

ll n, m;
string s, t;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> m;
    cin >> s >> t;
    vll sa, ta;
    ll ans = lcm(n, m);
    ll a = ans / n, b = ans / m;
    rep(i, 0, n) {
      sa.pb(i * a + 1);
    }
    rep(j, 0, m) {
      ta.pb(j * b + 1);
    }
    rep(k, 0, n) {
      int pos_t = distance(ta.begin(), lower_bound(ALL(ta), sa[k]));
      if (pos_t - 1 < m && sa[k] == ta[pos_t]) {
        if (s[k] != t[pos_t]) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 2804
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  int n;
  double ans;
  cin>>n;
  ans=(double)(n-(n/2))/(double)(n);
  cout<<fixed<<setprecision(6)<<ans<<endl;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    map<string,int> mp;
    string tmp;
    for(int i = 0; i < n; i++){
        cin >> tmp;
        if(mp.find(tmp) == mp.end())
            mp[tmp] = 1;
        else
            mp[tmp]++;
    }
    int m;
    cin >> m;
    for(int i = 0; i < m; i++){
        cin >> tmp;
        if(mp.find(tmp) == mp.end())
            mp[tmp] = -1;
        else
            mp[tmp]--;
    }
    int max = 0;
    for(auto val: mp){
        if(val.second > max)
            max = val.second;
    }
    cout << max;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i)
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define dis distance
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define pub push_back
#define sec second
#define fir first

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9+7;
const int INF = (1 << 30);
const double PI = acos(-1);

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int k,t;
	cin >> k >> t;
	REP(i,t){
		int a;
		cin >> a;
		if((k+1)/2 < a){
			if(k%2==0){
				cout << (a-(k+1)/2)*2-1 << endl;
			}else{
				cout << a-(k+1) << endl;
			}
			return 0;
		}
	}
	cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
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++)
typedef long long ll;

int main(){
	ll s;
	cin >> s;
	ll max = 1000000000;
	
	ll d = s/max + 1;
	if(d == max + 1){
		cout << "0 0 1000000000 1 " << 0 << " " << max << endl;
	}else{
		ll c = max- s%max;
		cout << "0 0 1000000000 1 " << c << " " << d << endl;
		return 0;
	}
}


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

int main(void) {

	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;

	int need = A*X+B*Y;

	for (int i = 0; i <= max(X,Y); i++) {
		need = min(need, C * 2 * i + A*max((X - i),0) + B*max(0,(Y - i)));
	}
	cout << need;
	return 0;
}

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

int max(int a, int b)
{
    return (a > b ? a : b);
}

int main(void)
{
    int books[10][2001];
    int dp[10][2001];
    int cost, group;
    int n, k;
    int i, j, l;
    int num[10];
    
    scanf("%d%d", &n, &k);
    
    memset(num, 0, sizeof(num));
    memset(books, 0, sizeof(books));
    
    for (i = 0; i < n; i++){
        scanf("%d%d", &cost, &group);
        num[group - 1]++;
        for (j = num[group - 1]; j >= 1; j--){
            books[group - 1][j] = max(books[group - 1][j], books[group - 1][j - 1] + cost);
        }
    }
    
    memset(dp, 0, sizeof(dp));
    for (i = 1; i <= num[0]; i++){
        dp[0][i] = books[0][i] + i * (i - 1);
    }
    
    for (i = 1; i < 10; i++){
        memcpy(dp[i], dp[i - 1], sizeof(dp[i - 1]));
        for (j = 1; j <= num[i]; j++){
            for (l = k; l - j >= 0; l--){
                if (dp[i][l] < dp[i - 1][l - j] + books[i][j] + j * (j - 1)){
                    dp[i][l] = dp[i - 1][l - j] + books[i][j] + j * (j - 1);
                }
            }
        }
    }
    
    printf("%d\n", dp[9][k]);
    
    return (0);
}

Measured memory_bytes: 0
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
   int H, W, h, w;
   cin >> H >> W;
   cin >> h >> w;

   cout << (H - h) * (W - w) << endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	getline(cin,s);
	if(s=="SUN") {
	    cout<<"7"; return 0;
	}
	if(s=="MON") {
	    cout<<"6"; return 0;
	}
	if(s=="TUE") {
	    cout<<"5"; return 0;
	}
	if(s=="WED") {
	    cout<<"4"; return 0;
	}
	if(s=="THU") {
	    cout<<"3"; return 0;
	}
	if(s=="FRI") {
	    cout<<"2"; return 0;
	}
	if(s=="SAT") {
	    cout<<"1"; return 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define REP(i, n) for(int i = 0; i < n; i++)
#define max(v) *max_element(v.begin(), v.end())
#define min(v) *min_element(v.begin(), v.end())
using namespace std;
 
int main(void){
  int n, k;
  cin>>n>>k;
  if((n+1)/2 >= k)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

n = INT()
a = LIST()
b = 0 #0: 未定 1: 非減少 2: 非増加
ans = 0
arr = []
for aa in a:
    if len(arr) == 0:
        arr.append(aa)
        ans += 1
        b = 0
        continue
    if b == 0:
        arr.append(aa)
        if arr[-2] < arr[-1]:
            b = 1
        elif arr[-2] > arr[-1]:
            b = 2
    if b == 1:
        if arr[-1] <= aa:
            arr.append(aa)
        else:
            arr = [aa]
            ans += 1
            b = 0
    if b == 2:
        if arr[-1] >= aa:
            arr.append(aa)
        else:
            arr = [aa]
            ans += 1
            b = 0
print(ans)

Measured memory_bytes: 84076
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
//const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    string s; cin >> s;
    rep(i,s.size()){
        if (s[i] == '?') s[i] = 'D';
    }
    cout << s << endl;
}

Measured memory_bytes: 3756
// #include <bits/stdc++.h>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<string>
#include<tuple>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
long N,M,L,R,l=1,r;
inline void solve(void){
  in(N,M);
  r=N;
  rep(i,M){
    in(L,R);
    chmax(l,L);
    chmin(r,R);
  }
  if(l<=r)out(r-l+1);
  else out(0);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)

















using vec = vector<ll>;
using mat = vector<vec>;

mat mul(mat a, mat b, ll m){
    mat c(a.size(), vec(b[0].size()));
    
    for(ll i = 0; i < a.size(); i++){
        for(ll k = 0; k < b.size(); k++){
            for(ll j = 0; j < b[0].size(); j++){
                c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % m;
            }
        }
    }
    
    return c;
}

mat POW(mat a, ll n, ll m){
    mat b(a.size(), vec(a.size()));
    
    for(ll i = 0; i < a.size(); i++){
        b[i][i] = 1;
    }
    while(n > 0){
        if(n & 1){
            b = mul(b, a, m);
        }
        a = mul(a, a, m);
        n >>= 1;
    }
    
    return b;
}

ll len(ll x){
    ll res = 0;
    while(x > 0){
        x /= 10;
        res++;
    }
    return res;
}

ll f(ll l, ll a, ll b){
    ll z = len(a);
    ll le = 0, ri = l;
    while(le < ri){
        ll m = (le + ri) / 2;
        if(z == len(a + b * m)){
            le = m + 1;
        }
        else{
            ri = m;
        }
    }
    return le;
}
 
int main(){
    ll l, a, b, m;
    cin >> l >> a >> b >> m;
    
    ll sum = 0;
    while(l > 0){
        ll k = f(l, a, b);
        ll p = 1;
        REP(i, len(a)){
            p *= 10;
            p %= m;
        }
        vec r = {sum, a % m, 1};
        mat x = {{p, 0, 0},
                 {1, 1, 0},
                 {0, b % m, 1}};
        x = POW(x, k, m);
        vec t(3);
        t[0] = (r[0] * x[0][0] + r[1] * x[1][0] + r[2] * x[2][0]) % m;
        t[1] = (r[0] * x[0][1] + r[1] * x[1][1] + r[2] * x[2][1]) % m;
        t[2] = (r[0] * x[0][2] + r[1] * x[1][2] + r[2] * x[2][2]) % m;
        
        sum = t[0];
        l -= k;
        a += b * k;
    }
    cout << sum << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll sum_a = 0;
    rep(i, 0, n) cin >> a[i], sum_a += a[i];

    ll sum_one = (1+n)*n/2;

    if (sum_a % sum_one != 0)
    {
        cout << "NO" << endl;
        return 0;
    }
    ll num_op = sum_a / sum_one;

    a.push_back(a[0]);
    rep(i, 0, n)
    {
        ll diff = a[i+1] - a[i];
        ll now = num_op - diff;
        if (now % n != 0 or now < 0 or num_op < now / n )
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
#include <cmath>
#include <cfloat>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

class UnionFind {
 private:
  vector<ll> parents;

 public:
  UnionFind(ll n) : parents(n, -1) {}

  bool issame(ll x, ll y) { return root(x) == root(y); }

  bool merge(ll x, ll y) {
    if (issame(x, y)) return false;

    ll rx = root(x);
    ll ry = root(y);
    if (parents[rx] > parents[ry]) swap(rx, ry);
    // サイズ情報を更新
    parents[rx] += parents[ry];
    // yの親を更新
    parents[ry] = rx;

    return true;
  }

  ll size(ll x) { return -parents[root(x)]; }

 private:
  ll root(ll x) {
    if (parents[x] < 0) return x;
    // 根の親の値に木の(-)サイズの情報を入れる
    return parents[x] = root(parents[x]);
  }
};

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  ll a, b, c;
  cin >> a >> b >> c;

  ll x = a + b;

  if ((c - x > 0) && (c * c - 2 * c * x + x * x - 4 * a * b) > 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)


def main():
    a,b,c = LI()
    r = [c]
    for i in range(10):
        r.append(a*r[-1]-b)

    return '\n'.join(map(str, r[1:]))


print(main())



Measured memory_bytes: 7748
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    String ans = "YES";
    int atc = Integer.parseInt(s.replaceAll(" ", ""));
    if (atc % 4 != 0)
      ans = "NO";
    System.out.println(ans);
  }
}

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

using namespace std;

const vector<string> strings = {"dream", "dreamer", "erase", "eraser"};

bool checkEqual(const string &text, int p, const string &pattern){
    int i = 0;
    
    while (i < pattern.size()){
        if (text[p + i] != pattern[i])
            return false;
            
        i++;
    }
    
    return true;
}

int main()
{   
    ios_base::sync_with_stdio(false);
    
    string text;
    cin >> text;
    
    const int N = text.size();
    
    text = " " + text;
    
    vector<bool> dp(N + 1, false);
    dp[0] = true;
    
    for (int i = 0; i <= N; i++)
        if (dp[i]){
            for (auto &s: strings)
                if (i + s.size() <= N)
                    dp[i + s.size()] = dp[i + s.size()] || checkEqual(text, i + 1, s);
        }
        
    if (dp[N])
        cout << "YES\n";
    else
        cout << "NO\n";
    
    return 0;
}

Measured memory_bytes: 640
a, b = map(int, input().split())
honsu = b-a

def f(x):
    return x

def sigma(func, frm, to):
    result = 0;
    for i in range(frm, to+1):
        result += func(i)
    return result

height = sigma(f, 1, honsu)
print(height-b)


Measured memory_bytes: 2940
#define _USE_MATH_DEFINES

#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

int main(){
	
	int P = 41;
	
	int K = P + 1;
	int N = 1 + P * (P + 1);
	
	cout << N << " " << K << endl;
	
	K--;
	
	int num[P + 1][P];
	
	for(int i = 2; i <= N; i++){
		num[(i - 2) / P][(i - 2) % P] = i;
	}
	
	for(int i = 0; i <= K; i++){
		cout << 1;
		for(int j = 0; j < P; j++){
			cout << " " << num[i][j];
		}
		cout << endl;
	}
	
	for(int i = 0; i < P; i++){
		for(int j = 0; j < P; j++){
			cout << num[0][i];
			for(int k = 1; k <= P; k++){
				cout << " " << num[k][(j + k * i) % P];
			}
			cout << endl;
		}
	}
	
	return 0;
}

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

int main(void){
    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 <bits/stdc++.h>
#define MOD 998244353

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n;
long long a[100001],t=1,d[100001],ma=0;

long long moe(long long a,long long b)
{
    if (b==0) return 1;
    if (b%2==0) return moe((a*a)%MOD,b/2);
    return (a*moe((a*a)%MOD,b/2))%MOD;
}

void nhap()
{
    scanf("%d",&n);
    for (int i=1;i<=n;++i)
    {
        scanf("%lld",&a[i]);
        if (a[1]!=0)
        {
            cout<<0;
            return;
        }
        if (a[i]==0 && i!=1)
        {
            cout<<0;
            return;
        }
        d[a[i]]++;
        ma=max(ma,a[i]);
    }
    long long pa=1;
    for (int i=1;i<=ma;++i)
    {
        if (d[i]==0)
        {
            cout<<0;
            return;
        }
        t=(t*moe(pa,d[i]))%MOD;
        pa=d[i];
    }
    cout<<t;
}

int main()
{
    nhap();
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define NN 1000007
bool is_prime[NN];
std::vector<int>primes;
int gcd(int a, int b){	
	return !a?b: gcd(b % a, a);
}
void sieve() {
	for (int x = 2; x < NN; x++) {
		if (!is_prime[x]) {
			primes.push_back(x);
			for (int z = x + x; z < NN; z += x) {
				is_prime[z] = 1;
			}
		}
	}
}
std::set<int> factors(int number){
	std::set<int>fa;
	int q = 0;
	int f = primes[q];
	while (f * f <= number) {
		while (number % f == 0) {
			fa.insert(f);
			number /= f;
		}
		f = primes[++q];
	}
	if (number != 1)fa.insert(number);

	return fa;
}
int main() {
	sieve();
	int num; std::cin >> num;
	std::vector<int>arr;
	for (int x = 0; x < num; x++) {
		int l; std::cin >> l;
		arr.push_back(l);
	}
	std::map<int, int>mp;
	for (auto x : arr) {
		std::set<int>st = factors(x);
		for (auto z : st) mp[z]++;
	}
	bool tr = true;
	for (auto x : mp) {
		if (x.second > 1) { tr = false; break; }
	}
	if (tr) {
		std::cout << "pairwise coprime";
		return 0;
	}
	int secondPlane = arr[0];
	for (int x = 1; x < num; x++) {
		secondPlane = gcd(secondPlane, arr[x]);
	}
	if (secondPlane == 1)std::cout << "setwise coprime";
	else {
		std::cout << "not coprime";
	}


}



Measured memory_bytes: 12060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  string w[n];
  int s=0;
  for(int i=0;i<n;i++) cin>>w[i];
  for(int i=1;i<n;i++){
    for(int j=0;j<i;j++){
      if(w[i][0]!=w[i-1][w[i-1].size()-1] || w[i]==w[j]){
        s=1;
        break;
      }
    }
    if(s==1){
      cout<<"No"<<endl;
      break;
    }
  }
  if(s==0) cout<<"Yes"<<endl;
}

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

using namespace std;
vector<int> V;
vector<int> resposta;
int vis[1001000];

int crivo(int limite, int ind){
    int cont = 0;
    for (int i=0; i<ind; i++){
        if(vis[V[i]] == 0){
            vis[V[i]] = 2;
            cont++;
            for (int j=2*V[i]; j<=limite; j+=V[i]) vis[j] = 1;
        }else if (vis[V[i]] == 2){ //Ja foi contado
            vis[V[i]] = 3;
            cont--;
        }
    }
    return cont;
}

int main(){

    int n;
    cin >> n;

    int limite = 0;
    for (int i=0; i<n; i++){
        int num;
        cin >> num;
        if (num > limite) limite = num;
        V.push_back(num);
    }

    sort(V.begin(), V.end());
    cout << crivo(limite, n) << endl; 
    return 0;
}


Measured memory_bytes: 7920
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define deb(x) cout << #x << " = "<< x << "\n"; 

signed main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	
	int n; cin >> n;
	map<int, int> m;
	int a[n];
	for(int i = 0; i<n; i++)
	{
		cin >> a[i];
		m[a[i]]++;
	}
	int ans = 0;
	for(auto it : m)
	{
		ans += (it.second * (it.second-1) / 2);
	}
	for(int i = 0; i < n; i++)
	{
		int cur = m[a[i]];
		int before = cur * (cur-1)/2;
		cur--;
		int after = cur * (cur-1)/2;
		cout << ans - before + after << "\n";
		
	}
	


	
} 


Measured memory_bytes: 11008
import sys
input = sys.stdin.readline

INF = float('inf')
MOD = 10 ** 9 + 7


def nCr_mod(n, r):
    p, q = 1, 1
    for i in range(r):
        p = p * (n - i) % MOD
        q = q * (i + 1) % MOD
    return p * pow(q, MOD - 2, MOD) % MOD


def main():
    N, A, B = map(int, input().split())
    total = pow(2, N, MOD)
    print((total - nCr_mod(N, A) - nCr_mod(N, B) - 1) % MOD)


if __name__ == '__main__':
    main()

Measured memory_bytes: 38512
import std.stdio, std.string, std.algorithm, std.array, std.range, std.conv,
    std.typecons, std.math, std.container, std.format;

long n;
long[] as;

void main(string[] args)
{
    readf("%d\n", &n);
    as = readln.strip.split(" ").to!(long[]);
    as[] -= 1;

    long cur = 0;
    long bad = 0;
    for (long i = 0; i < n; i++)
    {
        if (as[i] == cur)
        {
            cur++;
        }
        else
        {
            as[i] = -1;
            bad++;
        }
    }

    if (bad >= n)
    {
        writeln(-1);
    }
    else
    {
        writeln(bad);
    }
}


Measured memory_bytes: 11408
#include <stdio.h>

int main(){
    int A,B;
    scanf("%d %d",&A,&B);
    if(((1<=A)&&(A<=9))&&((1<=B)&&(B<=9))){
        printf("%d\n",A*B);
    }else{
        printf("-1\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[6][1010];//動的計画法
int prime[10000001];
char str[1010][1010];
vector<pair<int,int> > pc[100001];
int ABS(int a){return max(a,-a);}
int kai(int n){
	if(n==0) return 1;
	int ans;
	ans=n*kai(n-1);
	return ans;
}
int main(){
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a*b>=c*d) cout<<a*b<<endl;
	else cout<<c*d;
	return 0;
}

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

namespace cswork
{
    class Program
    {
        class Scanner
        {
            string[] s;
            int i;

            char[] cs = new char[] { ' ' };

            public Scanner()
            {
                s = new string[0];
                i = 0;
            }

            public string next()
            {
                if (i < s.Length) return s[i++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();

                s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
                i = 0;
                return next();
            }

            public int nextInt()
            {
                return int.Parse(next());
            }

            public long nextLong()
            {
                return long.Parse(next());
            }

            public double nextDouble()
            {
                return double.Parse(next());
            }
        }

        public Program() { }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }

        public static List<long> GeneratePrime(long max)
        {
            long prime;
            double sqrtMax = Math.Sqrt(max);
            var primeList = new List<long>();

            List<long> searchList = new List<long>();
            for (long i = 2; i <= max - 1; i++)
            {
                searchList.Add(i);
            }

            do
            {
                prime = searchList.First();
                primeList.Add(prime);
                searchList.RemoveAll(n => n % prime == 0);
            } while (prime < sqrtMax);

            primeList.AddRange(searchList);

            return primeList;
        }

        void Omame()
        {
            cin = new Scanner();
            List<int> list = new List<int>();
            list.Add(1);
            list.Add(2);
            list.Add(3);

            list.RemoveAt(list.IndexOf(cin.nextInt()));
            list.RemoveAt(list.IndexOf(cin.nextInt()));

            Console.WriteLine(list[0]);
        }
    }
}


Measured memory_bytes: 13152
#include<stdio.h>


int main(){
 int i,j,n;
 int table[100][100];

 while(1){

      scanf("%d",&n);
      if(n==0)break;

      for(i=0;i<=n;i++){
         for(j=0;j<=n;j++){
             table[i][j]=0;
         }
      }




      for(i=0;i<n;i++){
          for(j=0;j<n;j++){
              scanf("%d",&table[i][j]);
          }
      }

      for(i=0;i<n;i++){
         for(j=0;j<n;j++){
              table[i][n]+=table[i][j];
         }
      }

      for(i=0;i<=n;i++){
          for(j=0;j<n;j++){
              table[n][i]+=table[j][i];
          }
      }


      for(i=0;i<=n;i++){
          for(j=0;j<=n;j++){
              printf("%5d",table[i][j]);
          }
          printf("\n");
      }

 }

return 0;
}


Measured memory_bytes: 2000
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a) ? "Yes" : "No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return 1;
	}
	return 0;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 20;
const double PI       = acos(-1);
int main() {
	int n, ma, mb;
	cin >> n >> ma >> mb;
	vector<tuple<int, int, int>> data(n);
	int a, b, c;
	int per;
	int ans = INF;
	rep(i, n) {
		cin >> a >> b >> c;
		data[i] = make_tuple(a, b, c);
	}
	vector<vector<vector<int>>> dp(n + 1, VVi(420, Vi(420, INF)));
	dp[0][0][0] = 0;
	rep(i, n) {
		for (int a = 0; a <= 405; a++) {
			for (int b = 0; b <= 405; b++) {
				if (1) {
					chmin(dp[i + 1][a][b], dp[i][a][b]);
				}

				chmin(dp[i + 1][a + get<0>(data[i])][b + get<1>(data[i])],
				      dp[i][a][b] + get<2>(data[i]));
				/*if (dp[i][a][b] != INF) {
				    clog << i << " " << a << " " << b << "::" << dp[i][a][b]
				         << endl;
				}*/
			}
		}
	}
	for (int i = 1; max(ma, mb) * i < 410; i++) {
		chmin(ans, dp[n][i * ma][i * mb]);
		/*	if (dp[n][ma * i][ma * i] != INF) {
		        clog << n << " " << ma * i << " " << mb * i
		             << "::" << dp[n][ma * i][mb * i] << endl;
		    }*/
	}
	/*
	dp[at][yen]=per(a,b)
	init:(-1,-1), [0][0]=(0,0)
	transsit:[at][yen]=[at-1][yen]
	40*400*400 10^6*64
	dp[at][a][b]=yen
	intit: inf, [0][0][0]=0;
	trinssit; [at][a][b]=min([at-1][a][b],[at-1][a-data][b-data]+data)
	find; at[i][j]; i;j = ma:mb;

	*/
	if (ans == INF) {
		cout << -1 << endl;

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

Measured memory_bytes: 32820
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>
#include <random>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  string s;
  cin >> s;
  if (s[0] == s[1] && s[1] == s[2])
    cout << "No" << endl;
  else
    cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
  int D=0;

  cin >> D;
  if(D<=25) cout << "Christmas";
  if(D<=24) cout << " Eve";
  if(D<=23) cout << " Eve";
  if(D<=22) cout << " Eve" << endl;

  return 0;
}

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

ll k[1000*1001/2+100], aaa[1000*1001/2+100];

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    int cur = 0;
    for (int l=0; l<N; ++l) {
        ll sum = A[l];
        k[cur++] = sum;
        for (int r=l+1; r<N; ++r) {
            sum += A[r];
            k[cur++] = sum;
        }
    }

    if (K == 1) {
        ll ma = 0;
        rep(i, cur) ma = max(ma, k[i]);
        cout << ma << endl;
        return 0;
    }
    else if (K == cur) {
        ll ma = k[0];
        rep(i, cur) ma &= k[i];
        cout << ma << endl;
        return 0;
    }

    ll ng = 1000;
    while (cur > K) {

        map<ll, ll> mp;

        rep(i, cur) {
            for (int j=0; j<=60; ++j) {
                if (k[i] & (1LL<<j)) mp[j]++;
            }
        }

        ll ma = -1;
        for (auto& tmp : mp) {
            if (ng > tmp.first and tmp.second >= K and ma < tmp.first) {
                ma = tmp.first;
            }
        }
        // 
        // cout << ng << ", " << ma << ", " << mp[0] << endl;
        // rep(i, cur) {
        //     cout << k[i] << endl;
        // }
        // cout << endl;

        if (ma == -1) {
            break;
        }

        int tmpcur = 0;
        rep(i, cur) {
            if (k[i]&(1LL<<ma)) aaa[tmpcur++] = k[i];
        }

        memcpy(k, aaa, sizeof(aaa));
        ng = ma;
        cur = tmpcur;

        // cout << ng << ", " << ma << ", " << mp[0] << endl;
        // rep(i, cur) {
        //     cout << k[i] << endl;
        // }
        // cout << endl;
    }

    sort(k, k+cur);
    reverse(k, k+cur);

    ll ans = k[0];
    for (int i=0; i<K; ++i) {
        ans &= k[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 6912
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class T> int arrCountVal(int N, T A[], T val){
  int i;
  int res = 0;
  for(i=(0);i<(N);i++){
    if(A[i]==val){
      res++;
    }
  }
  return res;
}
template<class T> inline int Cmod2(T n, T k){
  if((n&k)==k){
    return 1;
  }
  return 0;
}
int N;
char S[1000000+2];
int main(){
  int i;
  int m = 0;
  int mul = 1;
  rd(N);
  rd(S);
  for(i=(0);i<(N);i++){
    S[i] -= '1';
  }
  if(arrCountVal(N,S,(char)1)==0){
    mul = 2;
    for(i=(0);i<(N);i++){
      S[i] /= 2;
    }
  }
  for(i=(0);i<(N);i++){
    m = (m + S[i] * Cmod2(N-1,i)) % 2;
  }
  wt_L(mul * m);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200322-1 [beta]

// --- original code ---
// int N;
// char S[1d6+2];
// 
// {
//   int m = 0, mul = 1;
//   rd(N,S);
//   rep(i,N) S[i] -= '1';
// 
//   if(arrCountVal(N,S,(char)1)==0){
//     mul = 2;
//     rep(i,N) S[i] /= 2;
//   }
// 
//   rep(i,N) m = (m + S[i] * Cmod2(N-1,i)) % 2;
//   wt(mul * m);
// }


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}


int main(void) {
    int64 N;
    cin >> N;
    vector<int64> a(N);
    REP(i, N) cin >> a[i];

    vector<int64> res(N, 0);
    bool ok = 1;
    vector<int64> r;
    for (int64 i = N;i >= 1;i--) {
        int64 cnt = 0;
        for (int64 j = i*2; j <= N; j+=i) {
            cnt += res[j-1];
        }
        if (cnt % 2 != a[i-1]) {
            res[i-1] = 1;
            r.push_back(i);
        }
    }
    cout << r.size() << endl;
    REP(i, r.size()) {
        cout << r[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 4980