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

//6/9コンテスト

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

		int A=a+b;
		int B=a+c;
		int C =c+b;

		int min=A;
		if(B<A) {
			min=B;
			if(C<B) {
				min=C;
			}
		}
		else if(C<A) {
			min=C;
			if(B<C) {
				min=B;
			}
		}

		System.out.println(min);



	}

}


Measured memory_bytes: 21844
W,H,N = map(int,input().split())
ans = [[0 for i in range(W)] for j in range(H)]
for i in range(N):
  x,y,a = map(int,input().split())
  if a == 1:
    for j in range(H):
      ans[j][:x] = [1]*x
  elif a == 2:
    for j in range(H):
      ans[j][x:] = [1]*(W-x)
  elif a == 3:
    for j in range(y):
      ans[j] = [1]*W
  else:
    for j in range(y,H):
      ans[j] = [1]*W
ans_ = 0
for i in range(H):
  ans_ += ans[i].count(0)
print(ans_)

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

using namespace std;

long long n, x;
long long colors[2010], shift[2010];

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

    cin >> n >> x;

    int inicial;
    for(int i = 0; i < n; ++i){
        cin >> colors[i];
        shift[0] += colors[i];
    }

    long long best, aux;
    for(int c = 0; c < n; ++c){
        best = colors[c];
        for(int i = (c - 1 + n) % n, j = 1; i != c; --i, i+= n, i %= n, ++j){
            if(colors[i] < best)
                best = colors[i];
            shift[j] += best;
        }
    }

    long long corrimientos = 0, menor = shift[0];
    for(int i = 1; i < n; ++i){
        if(shift[i] + x * i < menor){
            corrimientos = i;
            menor = shift[i] + x * i;
        }
    }

    cout << menor << endl;

    return 0;
}


Measured memory_bytes: 256
//#pragma comment(linker,"/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
const int INF=0x3f3f3f3f;
#define _for(i, a, b) for (int i = (a); i < (b); ++i)
#define _rep(i, a, b) for (int i = (a); i <= b; ++i)
const int max_number=1000000;



int main()
{
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    cout <<  a[0] <<" "<< a[1] <<" "<< a[2] << endl;
    return 0;
}


Measured memory_bytes: 3160
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[int(input()) for _ in range(n)]
    s=sum(a[0:k])
    ss=[s]
   
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
        
    print(max(ss))


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

int main(){

	string str1, str2;
	int count = 0;

	cin >> str1;
	for(int i=0; i<str1.size(); i++){
		if('A'<=str1[i] && str1[i]<='Z'){
			str1[i] = str1[i] - 'A' + 'a';
		}
	}

	while(cin >> str2){
		if(str2 == "END_OF_TEXT") break;
		for(int i=0; i<str2.size(); i++){
			if('A'<=str2[i] && str2[i]<='Z'){
				str2[i] = str2[i] - 'A' + 'a';
			}
		}
		if(str1 == str2) count++;
	}

	cout << count << endl;
}

Measured memory_bytes: 1192
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007
#define INF 1000000009
typedef long long int lli;

int main(void) {
  char s[4];
  scanf("%s", s);

  rep(i, 0, 2) {
    if (s[i] != s[i+1]) {
      printf("Yes\n");
      return 0;

    }
  }
  printf("No\n");
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

class Main{
	public static void main(String[] ag) {
		Scanner sc=new Scanner(System.in);
		int kosu=sc.nextInt();
		long[] a=new long[kosu];
		for(int i=0; i<kosu; i++) {
			a[i]=sc.nextLong();
		}
		long ans=1;

		for(int i=0; i<kosu; i++) {
			ans=lcm(ans,a[i]);
		}
		System.out.println(ans);

	}


	public static long lcm(long m, long n) {
		return m / gcd(m, n)*n;
	}
	public static long gcd(long m, long n) {
		if(m < n) return gcd(n, m);
		if(n == 0) return m;
		return gcd(n, m % n);
	}
}

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

using namespace std;

typedef long long LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = N; i >= 0; i--)

template<typename Container>
bool include(const Container& c, const typename Container::value_type& v) {
  return ( c.end() != std::find(c.begin(),c.end(),v) );
}

template<class T>
vector<T> unique_vec(const vector<T> &v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  return v;
}

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

  if (X >= 30) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x,a,b,n;
    cin >> x >> a >> b;
    cin >> n;
    string s;
    for (int i=0;i<n;i++) {
        cin >> s;
        if (s=="nobiro") {
            if (x+a<0) {
                x = 0;
            } else {
                x = x + a;
            }
        } else if (s=="tidime") {
            if (x+b<0) {
                x = 0;
            } else {
                x = x + b;
            }
        } else if (s=="karero") {
            x = 0;
        }
    }
    cout << x << endl;
}


Measured memory_bytes: 3212
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solve();
	}

	private static void solve() {
		try (Scanner cin = new Scanner(System.in)) {

			String str = cin.next();

			if (str.startsWith("YAKI")) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		} finally {
		}
	}

}


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

int fact(int n){
  int ret = 1;
  for(int i=n; 0<i; i--){
    ret *= i;
  }
  return ret;
}

int main(){
  int n;cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++){
    cin >> a.at(i);
  }
  if(n==2){cout << a.at(0) << ' ' << a.at(1) << endl;return 0;}
  sort(a.begin(),a.end());
  int m = a.at(a.size()-1);
  int ans;
  int MIN = 1000000000;
  for(int i=0; i<n-1; i++){
    if(abs(m/2-a.at(i))<=MIN){
      MIN = abs(m/2-a.at(i));
      ans = i;
    }
  }
  cout << m << ' ' << a.at(ans) << endl;   
}
  


Measured memory_bytes: 640
/*
    A - Can't Wait for Holiday
    https://atcoder.jp/contests/abc146/tasks/abc146_a
*/
#include <bits/stdc++.h>
using namespace std;

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

    map<string, int> mp{
        {"SUN", 7}, {"MON", 6}, {"TUE", 5}, {"WED", 4},
        {"THU", 3}, {"FRI", 2}, {"SAT", 1},
    };
    string s;
    cin >> s;

    cout << mp[s] << endl;
}

Measured memory_bytes: 256
n, m, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
x.append(X)
y.append(Y)
x.sort()
y.sort()
if x[-1] < y[0]:
    print("No War")
else:
    print("War")


Measured memory_bytes: 9112
#pragma GCC optimize("O3")
    #pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize("unroll-loops")
     
    #include <algorithm>
    #include <bitset>
    #include <cassert>
    #include <chrono>
    #include <cmath>
    #include <complex>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <ctime>
    #include <deque>
    #include <functional>
    #include <iomanip>
    #include <iostream>
    #include <iterator>
    #include <limits>
    #include <climits>
    #include <list>
    #include <map>
    #include <numeric>
    #include <queue>
    #include <random>
    #include <ratio>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <string>
    #include <unordered_map>
    #include <unordered_set>
    #include <utility>
    #include <vector>
    using namespace std;
     
    typedef long long ll;
    typedef long double LD;
    #define int ll
    #define double LD
    #define pb push_back
    #define mp make_pair
    #define REP(i,n) for (int i = 0; i < n; i++)
    #define loop(i,n) for (int i = 0; i < n; i++)
    #define FOR(i,a,b) for (int i = a; i < b; i++)
    #define REPD(i,n) for (int i = n-1; i >= 0; i--)
    #define FORD(i,a,b) for (int i = a; i >= b; i--)
    #define remax(a,b) a = max(a,b)
    #define remin(a,b) a = min(a,b)
    #define mem(a, b) memset(a, b, sizeof a)
    #define append push_back
    #define all(v) v.begin(),v.end()
    #define F first
    #define S second
    #define print(x) cout << (x) << endl
    #define PRECISION(x) cout << fixed << setprecision(x)
    #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
     
    const double PI=acos(-1);
    const int MOD = 1000000007;
    const int FMOD = 998244353;
    const double eps = 1e-9;
     
    mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
    
    signed main()
    {
    	
		int a,b,c;
		cin>>a>>b>>c;
		set<int> st;
		st.insert(a);
		st.insert(b);
		st.insert(c);
		if(st.size()==2)
		cout<<"Yes"<<endl;
		else
		cout<<"No"<<endl;
	}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 10000
#define MAP 100
#define Pair pair<int,int>
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int dist[MAP][MAP];
int dp[100100][3] = {0};
int main(){
    ll n; cin >> n;
    ll arr[100100][3];
    for(ll i = 1; i <= n; i++){
        for(ll j = 0; j < 3; j++){
            cin >> arr[i][j];
        }
    }

    for(ll i = 1; i <= n; i++){
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + arr[i][0];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + arr[i][1];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + arr[i][2];
    }
    ll ans = max(dp[n][0], max(dp[n][1], dp[n][2]));
    cout << ans << endl;
}



Measured memory_bytes: 3712
import math

n,d = map(int,input().split())

x_li = []

for i in range(n):
    x = []
    x_in = input().split()
    
    for j in range(d):
        x.append(int(x_in[j]))

    x_li.append(x)

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        total = 0
        for k in range(d):
            total += (x_li[i][k] - x_li[j][k]) ** 2

        if math.sqrt(total) == int(math.sqrt(total)):
            ans += 1

print(ans)





Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/

signed main(){
	int n;cin>>n;
	vi a(n),b(n);
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];

	int suma=0,sumb=0;
	rep(i,n)suma+=a[i];
	rep(i,n)sumb+=b[i];
	if(suma<sumb){
		cout<<-1<<endl;
		return 0;
	}

	vi x;
	int ans=0;
	int diff=0;
	rep(i,n){
		if(a[i]>b[i]) x.pb(a[i]-b[i]);
		if(a[i]<b[i]){
			ans++;
			diff+=b[i]-a[i];
		}
	}
	sort(allr(x));

	int i=0;

	while(diff>0){
		diff-=x[i];i++;
		ans++;
	}
	cout<<ans<<endl;


	return 0;


}


Measured memory_bytes: 5340
function Main (input) {
  const a = parseInt(input.split(' ')[0])
  const b = parseInt(input.split(' ')[1])
  if (a / 2 === Math.floor(a / 2) || b / 2 === Math.floor(b / 2)) {
    console.log('Even')
  } else {
    console.log('Odd')
  }
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
#include <stdio.h>
#define MAX 2000000
void heap(int i,int A[]);
int H;
int A[MAX+1];
int main(void){
	int i;
	scanf("%d",&H);
	int A[H];
	for(i=1;i<=H;i++){
		scanf("%d",&A[i]);
	}
	
	for(i=H/2;i>=1;i--){
		heap(i,A);
	}
	
	for(i=1;i<=H;i++){
		printf(" ");
		printf("%d",A[i]);
	}
	printf("\n");
	return 0;
}

void heap(int i,int A[]){
	int max;
	int a,b;
	int tmp;
	a=2*i;
	b=2*i+1;
	if(a<=H && A[a]>A[i]){
		max=a;
	}
	else {
		max=i;
	}
	
	if(b<=H && A[b]>A[max]){
		max=b;
	}
	if(max!=i){
		tmp=A[i];
		A[i]=A[max];
		A[max]=tmp;
		heap(max,A);
	}
}


Measured memory_bytes: 3680
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
A, B = MAP()
print("Possible" if A%3 == 0 or B%3 == 0 or (A+B)%3 == 0 else "Impossible")

Measured memory_bytes: 5396
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,x,y,d;cin>>n>>x>>y;x--,y--;
  map<ll,ll> dist;
  for(ll i=1;i<n;++i) dist[i]=0;
  for(ll i=0;i<n-1;++i) {
    for(ll j=i+1;j<n;++j) {
      d=min(j-i,abs(i-x)+abs(j-y)+1ll);
      dist[d]++;
    }
  }
  for(auto v:dist) print(v.second);
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	int A, B, C, K;
	cin >> A >> B >> C >> K;
	int res = 0;
	res += min(A, K);
	K -= A;
	K -= B;
	K = max(0, K);
	res -= min(C, K);
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int a,b;
	cin>>a>>b;
	cout<<(a-1)*(b-1)<<endl;
	return 0;
}


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

#define ll long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010
 
void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}

void swapl(ll* a,ll* b){ll tmp=*a;*a=*b;*b=tmp;}
ll absl(ll a){if(a<0)return -a;return a;}
ll dupl(ll a,ll d){if(a%d==0)return a/d;else return a/d+1;}
ll modl(ll a,ll m){if(a<0)return a%m+m;else return a%m;}

ll GCD(ll a,ll b){ll c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
ll LCM(ll a,ll b){return a*b/GCD(a,b);}

ll factorial(ll n, ll m) {return n < m ? 1 : n*factorial(n-1, m);}

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct 
{
    ll index;
    ll a;
} qwe;


int cmp_qwe(const void*a, const void*b){return ((qwe*)b)->a - ((qwe*)a)->a;}

ll dp[3000][3000];
qwe u[2000];

int main(){
  ll n, b, ans=0;
  ll a;

  scanf("%lld", &n);

  for (int i = 0; i < n; i++)
  {
      scanf("%lld", &a);
      u[i].index = i;
      u[i].a = a;
  }
  
  qsort(u, n, sizeof(qwe), cmp_qwe);

  dp[0][0] = 0;
  for (int i = 0; i < n; i++)
  {
      for (int j = 0; i + j + 1 <= n; j++)
      {
        dp[i+1][j] = MAX(dp[i+1][j], dp[i][j] + u[i+j].a * (u[i+j].index - i));
        dp[i][j+1] = MAX(dp[i][j+1], dp[i][j] + u[i+j].a * (n - 1 - j - u[i+j].index) );
      }
  }
  for (int i = 0; i <= n; i++)
  {
      ans = MAX(ans, dp[i][n-i]);
  }
  printf("%lld", ans);
  
  return 0;
}

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

using namespace std;

int main( void ){
  
  int a, b;
  vector<int> vi;
  cin >> a >> b;
  
  vi.push_back(a);
  vi.push_back(a-1); 
  vi.push_back(b);  
  vi.push_back(b-1);
  sort(vi.begin(), vi.end());
  int sum = vi[3]+vi[2];
  cout << sum << endl;
  return 0;
}

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

using namespace std;

#define all(x) (x).begin(),(x).end()

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


int main(void){

    int h, w;
    cin >> h >> w;
    P s, g;
    cin >> s.first >> s.second >> g.first >> g.second;

    vector<string> G(h);
    for (int i = 0; i < h; ++i) {
        cin >> G[i];
    }

    s.first--; s.second--;
    vector<vector<int>> dist(h, vector<int>(w, -1));
    dist[s.first][s.second] = 0;

    deque<P> q;
    q.push_front(s);
    while(!q.empty()){
        P p = q.front(); q.pop_front();
        int y = p.first, x = p.second;

        for(int i = 0; i < 5; ++i){
            for(int j = 0; j < 5; ++j){
                int a = y+i-2, b = x+j-2;
                if(a < 0 || a >= h || b < 0 || b >= w || G[a][b] == '#') continue;

                if(dist[a][b] == -1){
                    dist[a][b] = dist[y][x] + 1;
                    q.push_back(P(a, b));
                }
                if(abs(i-2) + abs(j-2) == 1 && dist[a][b] > dist[y][x]){
                    dist[a][b] = dist[y][x];
                    q.push_front(P(a, b));
                }
            }
        }
    }

//    for(int i = 0; i < h; ++i){
//        for(int j = 0; j < w; ++j){
//            cout << dist[i][j] << " ";
//        }
//        cout << "\n";
//    }

    cout << dist[g.first-1][g.second-1] << "\n";

    return 0;
}


Measured memory_bytes: 9520
<?php
$a = trim(fgets(STDIN));
$a = explode(' ', $a);

$a[0] -= $a[4];
$a[1] -= $a[4];

if ($a[2] >= $a[4] && $a[3] >= $a[4] && $a[2] <= $a[0] && $a[3] <= $a[1]) {
  echo 'Yes';
} else {
  echo 'No';
}
echo PHP_EOL;

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    set<char> x, y;
    for (int j = 0; j < i; j++) x.insert(s[j]);
    for (int j = i; j < n; j++) y.insert(s[j]);
    int cnt = 0;
    for (auto &j : x) if (y.count(j)) cnt++;
    ans = max(ans, cnt);
  }
  cout << ans << '\n';
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll a,b,c;
    cin>>a>>b>>c;
    ll ans=min(c,b/a);
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
using namespace std;

#define int long long
#define inf 1000000000
typedef pair<int, int> P;//to,1=cost

signed main() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int l, r;
		cin >> l >> r;
		ans += r - l + 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main (){
	long long n,m,a[150][150],b[150];
	cin >> n >> m;
	for (int i=1; i<=n; i++){
		for (int j=1; j<=m; j++){
			cin >> a[i][j];
		}
	}
	for (int i=1; i<=m; i++)cin >> b[i];	
	for (int i=1; i<=n; i++){
		long long jum=0;
		for (int j=1; j<=m; j++){
			jum+=a[i][j]*b[j];
		}
		cout << jum << endl;
	}
}


Measured memory_bytes: 3216
#include<stdio.h>
#include<stdbool.h>

bool next_permu(int array[static 2],size_t len){
    int index_1,index_2;
    for(index_1 = len - 2;index_1 >= 0;index_1--){
        if(array[index_1] < array[index_1 + 1])break;
        if(!index_1)return false;
    }

    for(index_2 = len - 1;index_2 >= 0;index_2--){
        if(array[index_2] > array[index_1])break;
        if(!index_2)return false;
    }

    int tmp = array[index_1];
    array[index_1] = array[index_2];
    array[index_2] = tmp;

    for(int i = index_1 + 1;i < len - (i - index_1);i++){
        int tmp = array[i];
        array[i] = array[len - (i - index_1)];
        array[len - (i - index_1)] = tmp;
    }
    return true;
}

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

    int p[n],q[n];
    for(int i = 0;i < n;i++)scanf("%d",&p[i]);
    for(int i = 0;i < n;i++)scanf("%d",&q[i]);
    int p_c = 0,q_c = 0;

    int base[n];
    for(int i = 0;i < n;i++)base[i] = i + 1;
    
    do{
        for(int i = 0;i < n;i++)if(base[i] != p[i]){
            p_c++;
            break;
        }else if(i == n - 1)goto end_p;
    }while(next_permu(base,n));
    end_p:

    for(int i = 0;i < n;i++)base[i] = i + 1;
    do{for(int i = 0;i < n;i++)if(base[i] != q[i]){
            q_c++;
            break;
        }else if(i == n - 1)goto end_q;
    }while(next_permu(base,n));
    end_q:

    printf("%d",(p_c < q_c ? q_c - p_c : p_c - q_c));
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
#define mod(int)(1000000007)
using namespace std;
int ok[213456];
signed main() {
	int n, m, a, b, ans = 0; cin >> n >> m;
	for (int h = m / n; h > 0; h--) {
		if (m % h == 0) {
			cout << h << endl; return 0;
		}
	}
}

Measured memory_bytes: 256
n = int(input())
B = list(map(int, input().split()))
A = []

A.append(B[0])

if n >= 2:
    A.append(B[0])
    for i in range(1, n-1):
        #print(A, B)
        if A[i] != B[i]:
            #A.append(B[i])
            if A[i] > B[i]:
                A[i] = B[i]
        
        A.append(B[i])
    #print(A)
    print(sum(A))

else:
    print(sum(A))


Measured memory_bytes: 3064
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from math import factorial 
def main():
    n, m, k = map(int, readline().split())
    P = int(1e9)+7

    def C(n, m, p):
        a = 1
        for i in range(m):
            a *= (n-i)
            a %= p
        b = factorial(m)%p 
        b = pow(b, p-2, p)
        return a*b%p

    c = C(n*m-2, k-2, P)
    s_x = 0
    for d in range(1, m):
        s_x += d*(m-d)*n*n
        s_x %= P
    s_y = 0
    for d in range(1, n):
        s_y += d*(n-d)*m*m
        s_y %= P

    ans = (s_x+s_y)*c%P
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;

bool is_prime(ll n){
    for(ll i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return n != 1;
}

void solve(long long X){
    ll x = X;
    for(ll i = 0; i < INF; ++i){
        if(is_prime(x)) break;
        x = X + i;
    }
    cout << x << endl;
    return;
}

int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 3764
a,b,m = gets.split.map(&:to_i)
yfre = gets.split.map(&:to_i)
ymicro = gets.split.map(&:to_i)
chicket = []
m.times {
    chicket.push gets.split.map(&:to_i)
}

min = yfre.min + ymicro.min

nyens = []
for i in chicket do
    nyens.push(yfre[i[0]-1] + ymicro[i[1]-1] - i[2])
end
min = nyens.min < min ? nyens.min : min

puts min


Measured memory_bytes: 19228
#include <tuple>
#include <vector>
#include <map>
#include <set>
#include <iostream>
#include <limits>


template<class... Ts> using tuple_t = std::tuple<Ts...>;
template<class T, class U> using map_t = std::map<T, U>;
template<class T, class U> using pair_t = std::pair<T, U>;
template<class T> using vector_t = std::vector<T>;
template<class T> using set_t = std::set<T>;

uint64_t digit(uint64_t num, uint64_t base = 10)
{
	uint64_t i = 0;
	while(num)
	{
		++i;
		num /= base;
	}
	return i;
}

uint64_t digit_sum(uint64_t num, uint64_t base = 10)
{
	uint64_t i = 0;
	while(num)
	{
		i += num % base;
		num /= base;
	}
	return i;
}

int min(vector_t<int> nums)
{
	int min_ = std::numeric_limits<int>::max();
	for(auto& i :nums)
		if(min_ > i)
			min_ = i;
	return min_;
}
int max(vector_t<int> nums)
{
	int max_ = std::numeric_limits<int>::min();
	for(auto& i :nums)
		if(max_ < i)
			max_ = i;
	return max_;
}
int first_min(vector_t<int> nums, int start = 0)
{
	int min_ = min(nums);
	for(int i = start; i < nums.size(); ++i)
		if(nums[i] == min_)
			return i;
	return 0;
}

int main()
{
	int a, b;
	std::cin >> a>>b;
	if(a + b == 15)
		std::cout << "+" << std::endl;
	else if(a * b == 15)
		std::cout << "*" << std::endl;
	else
		std::cout << "x" << std::endl;

	return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
	int n, h;
	cin >> n >> h;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];

    int a_max = *max_element(all(a));
    sort(all(b));
    reverse(all(b));

    int ans = 0;
    rep(i, n) {
        if (b[i] > a_max) {
            h -= b[i];
            ++ans;
            if (h<=0) break;
        } else break;
    }

    if (h>0) ans += (h + (a_max-1)) / a_max;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<stack>
#include<iostream>
#include<sstream>
#define x first
#define y second
#define lson u<<1
#define rson u<<1|1
#define pb push_back
#define pu pushup
#define mk make_pair
using namespace std;
#define ll long long
#define mod 1000000007
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
int gcd(int a,int b)
{
	return b?gcd(b,a%b):a;
}
int a[1000010];
bool cnt[1010000];
int prime[1010];
int cntt;
bool isprime(int n)
{
	for(int i=2;i*i<=n;i++)
		if(n%i==0)
			return false;
		return true;
}
int main()
{
	int n;
	cin>>n;
	int g=0;
	for(int i=1;i<=n;i++)
		cin>>a[i],g=gcd(g,a[i]);
	for(int i=2;i<=1000;i++)
		if(isprime(i))
			prime[cntt++]=i;

	{
		bool flag=true;
		for(int i=1;i<=n;i++)
			{
			for(int j=0;j<cntt&&prime[j]*prime[j]<=a[i];j++)
					{
						int pj=prime[j];
						if(a[i]%pj==0)
						{
							if(cnt[pj])
							{
								flag=false;
								break;
							}
							cnt[pj]=true;
							while((a[i]%pj)==0)
								a[i]/=pj;
						}
						
						if(!flag)
							break;
					}
					if(a[i]!=1)
						{
							if(cnt[a[i]])
								flag=false;
							cnt[a[i]]=true;
						}
					if(!flag)
						break;
					}
		if(!flag && g==1)
			cout<<"setwise coprime"<<endl;
		else if(flag)
			cout<<"pairwise coprime"<<endl;
		else
			cout<<"not coprime"<<endl;
	}
}

Measured memory_bytes: 7524
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>









ll n;





void solve()
{
	cin>>n;
	for(ll i=1,j;;i++)
	{
		j=(i*(i+1))/2;
		if(j>=n)
		{
			for(ll k=1;k<=i;k++)
			{
				if(k==(j-n))continue;
				cout<<k<<"\n";
			}
			return;
		}
	}
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int b = scan.nextInt();
        

        System.out.print(a * b);
        
        System.out.print(" ");

        System.out.println((a * 2) + (b * 2));
    }  
}



Measured memory_bytes: 26180
#include <iostream>
#include <iomanip>
#include <queue>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <bitset>

#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x, y) memset(x, y, sizeof(x))
#define pb push_back
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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 (a > b) {
      a = b;
      return 1;
   }
   return 0;
}

using namespace std;
using ll = long long;

const int kInf = 2e9;
const ll kLInf = 2e18;

int gcd (int a, int b) {
   return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
   cout << fixed << setprecision(10);
   string S;
   cin >> S;
   int ans=0;
   string prev = "";
   string now = "";
   REP(i, SZ(S)) {
      now += S[i];
      if (now == prev) {
         continue;
      }
      prev = now;
      now = "";
      ans++;
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>
#define NMAX 2*1000*1000
#define AMAX 10000

void CountingSort(int A[], int n){
    int i;
    int B[NMAX], Count[AMAX];
    
    //count配列の初期化
    for(i=0; i<=AMAX; i++){
        Count[i]=0;
    }
    //数える
    for(i=0; i<n; i++){
        Count[A[i]]++;
    }
    //累積の配列にする
    for(i=0; i<AMAX; i++){
        Count[i+1]+=Count[i];
    }
    //コピーする。後ろから見ていくので注意。
    for(i=n-1; i>=0; i--){
        B[Count[A[i]]-1]=A[i];
        --Count[A[i]];
    }
    //元の配列にソートした配列を代入する
    for(i=0; i<n; i++){
        A[i]=B[i];
    }
}

int main(){
    
    int i,n;
    
    scanf("%d", &n);
    int A[NMAX];
    
    for(i=0; i<n; i++){
        scanf("%d", &A[i]);
    }
    
    CountingSort(A, n);
    
    for(i=0; i<n; i++){
        if(i) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
    
    return 0;
}



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

long cd(int c,int d){
  long C,D;
  C = max(c,d);
  D = min(c,d);
  long ans = 0;
  long e = 0;
  while(C%D != 0){
    e = C%D;
    C = D;
    D = e;
  }
  e = c/D;
  ans = d*e;
  return ans;
}

int main(){
  long a,b,ans,ansC,ansD,ansCD,total,f;
  int c,d;
  cin >> a >> b >> c >> d;
  ans = 0; ansC = 0; ansD = 0; ansCD = 0;
  total = 0; f = 0;
  ansC = b/c - a/c;
  ansD = b/d - a/d;
  if(a%c == 0){
    ansC++;
  }
  if(a%d == 0){
    ansD++;
  }
  f = cd(c,d);

  ansCD = b/f - a/f;
  if(a%f == 0){
    ansCD++;
  }
  total = b - a + 1;
  ans = total - (ansC + ansD) + ansCD;  
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;



int main(){
    ll n,m;
    cin >> n >> m;
    vector<ll> L(m),R(m);
    REP(i,m){
        cin >> L[i] >> R[i];
    }
    sort(L.begin(),L.end());
    sort(R.begin(),R.end());
    ll ans = 0;
    if(L[m-1] <= R[0]){
        ans =  R[0] - L[m-1] + 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
import itertools

N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(M)]

lis = [i for i in range(1, N+1)]
T = itertools.permutations(lis)

ans = 0

for t in T:
    if t[0] == 1:
        for i in range(N-1):
            A = [list(t)[i], list(t)[i+1]]
            B = [list(t)[i+1], list(t)[i]]
            if not (A in L or B in L):
                break
        else:
            ans += 1
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

int main(){

    char s[4];

    scanf("%s",s);

    if(s[0] == s[1] && s[2] == s[3] && s[0] != s[2]){
        printf("Yes\n");
    }else if(s[0] == s[2] && s[1] == s[3] && s[0] != s[1]){
        printf("Yes\n");
    }else if(s[0] == s[3] && s[1] == s[2] && s[0] != s[1]){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 128
def main():
    n, m, x, y = map(int, input().split())
    xs = [x] + list(map(int, input().split()))
    ys = [y] + list(map(int, input().split()))
    if max(xs) < min(ys):
        print('No War')
    else:
        print('War')


if __name__ == '__main__':
    main()


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

int main(){
    int a[5];
    int t;
    cin>>t;
    while(t--){
        for(int i=0;i<3;++i){
            cin>>a[i];
        }
        sort(a,a+3);
        int t1,t2,t3;
        t1 = a[2];
        t2 = a[1];
        t3 = a[0];
        if(t1*t1 == t2*t2 + t3*t3){
            cout << "YES" << endl;
        }
        else cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

int gcd(int A, int B) {
	if (A < B) return gcd(B, A);
	else if (B == 0) return A;
	else return gcd(B, A % B);
}


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


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

	string S, T;
	cin >> S >> T;

	ll kotae = 1ll * S.size() * T.size() / gcd(S.size(), T.size());

	int OK = 1;
	ll kankaku = kotae / S.size();
	ll kankakuT = kotae / T.size();
	rep(i, S.size()) {
		if (1ll * i * kankaku % kankakuT == 0) {
			if (S[i] != T[1ll * i * kankaku / kankakuT]) OK = 0;
		}
	}
	if (OK) co(kotae);
	else co(-1);

	Would you please return 0;
}

Measured memory_bytes: 640
j = list(map(int,input().split(" ")))
k = j[0]
n = j[1]
a = list(map(int,input().split(" ")))
# print(k)
# print(n)
# print(a)

difn = []
difn.append(k-a[n-1]+a[0])

for i in range(1,n):
    difa = a[i]-a[i-1]
    difn.append(difa)
    # print(difn)
difn.sort(reverse = True)
# print(difn)
print(k-difn[0])

Measured memory_bytes: 26060
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	set<int> st;
	rep(i,n){
		int d;
		cin >> d;
		st.insert(d);
	}
	cout << st.size() << endl;
	return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
int K;
LL A[1145];
LL imos[1145];

int main() {
  scanf("%d%d", &N, &K);
  rep(i, N) {
    scanf("%lld", &A[i]);
  }

  rep(i, N) {
    imos[i+1] = imos[i] + A[i];
  }

  vector<LL> ps;
  rep(l, N) {
    reps(r, l+1, N+1) {
      ps.eb(imos[r] - imos[l]);
    }
  }

  int M = ps.size();
  LL ans = 0;
  rrep(i, 42) {
    vector<LL> nxt;
    int cnt = 0;
    rep(j, M) {
      cnt += (ps[j] >> i & 1);
    }

    if (cnt >= K) {
      ans += 1LL << i;
      nxt.reserve(cnt);
      rep(j, M) {
        if (ps[j] >> i & 1) nxt.eb(ps[j]);
      }
      ps.swap(nxt);
      M = ps.size();
    }
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 6384
import sys


# N, M = map(int, input().split())
# nums = list(map(int, input().split()))
# nums_2d = [list(map(int, input().split())) for _ in range(N)]


def main():
    S, T = input().split()
    A, B = map(int, input().split())
    U = input()

    if S == U:
        A -= 1
    else:
        B -= 1

    print(A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
from collections import deque
q = deque()
ans = {}
K = int(input())
q.append((1,1))
while len(q):
  resid,total = q.popleft()
  if resid in ans:
    continue
  ans[resid] = total
  q.appendleft((resid*10%K,total))
  q.append(((resid+1)%K,total+1))
print(ans[0])

Measured memory_bytes: 24300
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#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<long double, long double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int MOD = 1000000007;
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(){
    int n; cin >> n;
    set<string> s;
    set<string>::iterator ite;;
    rep(i,n){
        string t; cin >> t;
        ite = s.find(t);
        if (ite == s.end()) s.insert(t);
    }
    cout << s.size() << endl;
}

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

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

  int n = s.size();
  s = s + s;

  bool flag = false;
  for (int i = 0; i <= n; i++) {
    string tmp = s.substr(i, n);
    if(tmp == t) {
      flag = true;
      break;
    }
  }

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

  return 0;
}

Measured memory_bytes: 3648
/*
 * 求数组Ａ＝{5,3,6,2,1,4}的逆序数，设k为下标,在A[k]左侧且大于a[k]的元素数为C[k]。
 * C[k]的和即为数组A的逆序数.
 * A  5  3  6  2  1  4
 * C  0  1  0  3  4  2
 * 逆序数为10.
 * 这里应用归并排序的思路.
 */


#include<cstdio>
using namespace std;

#define MAX 200000
#define SENTINEL 2000000000
typedef long long llong;

int L[MAX/2+2],R[MAX/2+2];

llong merge(int A[],int n,int left,int mid,int right){
    int i,j,k;
    llong cnt = 0;
    int n1= mid - left;
    int n2= right - mid;
    for(i=0; i<n1; i++) L[i] = A[left+i];
    for(i=0; i<n2; i++) R[i] = A[mid +i];
    L[n1] = R[n2] = SENTINEL;
    i=j=0;
    for(k=left;k<right;k++){

        if(L[i]<=R[j]) {
            A[k] = L[i++];
        }else {
            A[k] = R[j++];
            cnt +=n1-i;
        }

    }
    return cnt;
}


llong mergeSort(int A[], int n, int left,int right){
    int mid;
    llong v1,v2,v3;
    if(left + 1 <right){
        mid = (left + right) /2;
        v1 = mergeSort(A,n,left,mid);
        v2 = mergeSort(A,n,mid,right);
        v3 = merge(A,n,left,mid,right);
        return v1+v2+v3;

    }else return 0;
}

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

    llong ans = mergeSort(A,n,0,n);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 4324
//#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second

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

const int N = 2e5 + 5;

/***************************************************************************/

int A[N];
int F[N];

inline int& f(int a) {
	return a >= 0 ? F[a] : F[N + a];
}

ll solve(int x, int n) {
	memset(F, 0, sizeof F);
	f(0) = 1;

	ll ans = 0;
	int c = 0, sum = 1;

	for(int i=1; i<=n; i++) {
		if(A[i] >= x) sum += f(++c);
		else sum -= f(c--);
		ans += sum;
		f(c)++;
		sum++;
	}
	return ans;
}

int main() {

	boost;
	int n; cin>>n;
	for(int i=1; i<=n; i++) {
		cin>>A[i];
	}
	ll total = (n * 1LL * (n+1)) >> 1;

	int la = 1, ra = 1e9;
	while(la < ra) {
		int m = (la + ra + 1) >> 1;
		ll nos = solve(m, n);
		if(nos >= total - nos) {
			la = m;
		}
		else ra = m - 1;
	}
	cout<<la<<"\n";

	return 0;
}

Measured memory_bytes: 1408
N = int(input())
A = [[0] + list(map(int, input().split())) for _ in '12']
for i in range(1, N+1):
    A[0][i] += A[0][i-1]
    A[1][i] += max(A[0][i], A[1][i-1])
print(A[1][N])

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

ll gcd(ll x, ll y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̒萔 (10��9��)
const int mod = 1000000007;

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

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    vector<vector<int> > c(3, vector<int> (3));
    rep(i, 3)rep(j, 3) cin >> c[i][j];

    for (int i = -10; i <= 100; i++) {
        for (int j = -10; j <= 100; j++) {
            for (int k = -10; k <= 100; k++) {
                int flag = 0;
                vector<int> v = { i, j, k };
                vector<int> n = { c[0][0] - i, c[0][1] - i, c[0][2] - i};
                for (int m = 0; m < 3; m++) {
                    int num = v[m];
                    for (int l = 0; l < 3; l++) {
                        if (c[m][l] == num + n[l]) {
                            flag++;
                        }
                    }
                }
                if (flag == 9) {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "No" << endl;
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
ll gcd(ll x, ll y) {
    ll num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 3660
n = int(input())
a = list(map(int, input().split()))
mn = a[0]
mx = a[0]
sum = a[0]
for i in range(1, n):
    mn = min(mn, a[i])
    mx = max(mx, a[i])
    sum += a[i]
print(mn, mx, sum)


Measured memory_bytes: 6596