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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

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

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

    ll ans = 0;
    REP(i,K){
        ans += A[i];
    }

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


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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

pair<int, int> AB(int64_t N)
{
    int p;
    p = N % 10;
    while (N >= 10)
    {
        N /= 10;
    }
    pair<int, int> tmp(p, N);
    return tmp;
}

int main()
{
    int N;
    cin >> N;
    vector<vector<int>> list(10, vector<int>(10, 0));
    for (int i = 1; i <= N; i++)
    {
        auto tmp = AB(i);
        int p = tmp.first, q = tmp.second; //末尾、先頭
        list[p][q]++;
    }
    int ans = 0;
    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            ans += list[i][j] * list[j][i];
        }
    }
    cout << ans;
}

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

#define select(_1, _2, x, ...) x

#define repn(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, ...) select(__VA_ARGS__, repr, repn)(i, __VA_ARGS__)

#define rrepn(i, n) for (int i = (n - 1); i >= 0; i--)
#define rrepr(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define rrep(i, ...) select(__VA_ARGS__, rrepr, rrepn)(i, __VA_ARGS__)

#define umax(m, x) (m = max(m, x));
#define umin(m, x) (m = min(m, x));

#define rng(v) v.begin(), v.end()
#define rrng(v) v.rbegin(), v.rend()

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

using ll = long long int;

using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;

using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;

const int INF = 1e9;
const ll LINF = 1e18;

inline void yn(bool f) { cout << (f ? "Yes" : "No") << endl; }


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

    vi a(n);
    rep(i, n) cin >> a[i];

    int q;
    cin >> q;

    vi m(q);
    rep(i, q) cin >> m[i];

    vb ans(q, false);

    rep(bit, 1 << n) {
        ll sum = 0;
        rep(i, n) {
            if (bit >> i & 1)
                sum += a[i];
        }

        rep(i, q) {
            if (m[i] == sum)
                ans[i] = true;
        }
    }

    rep(i, q)
        cout << (ans[i] ? "yes" : "no") << endl;

    return 0;
}



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

int main(){
    int a, b;
    cin >> a >> b;
    if (a < b) {
        for (int i = 0; i < b; i++) cout << a;
    }else {
        for (int i = 0; i < a; i++) cout << b;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
	char s[100];
	scanf("%s",s);
	if (strlen(s)==2) puts(s);
	else
	{
		putchar(s[2]);putchar(s[1]);putchar(s[0]);
	}
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
#define PI 3.14159265358979323846264338327950288

using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;


char ch[1003][1003] ;
bool visited[1003][1003] ;
int dist[1003][1003] ;
int N , M  ;
void bfs( int x , int y ){
    deque<pair<int , int> > dq ;
    dist[x][y] = 0 ;
    dq.push_back({x , y}) ;
    
    while( !dq.empty() ){
        pair<int, int> p = dq.front() ;
        int X = p.first , Y = p.second ;
        dq.pop_front() ;
        for( int i = -2 ; i <= 2 ; i++ ){
            for( int j = -2 ; j <= 2 ; j++ ){
                int currx = X + i , curry = Y + j ;
                if( currx == X && curry == Y )
                    continue ;
                if( currx < 1 || curry < 1 || currx > N || curry > M || ch[currx][curry] == '#' )
                    continue ;
                int D = 1 ;
                if( (abs( currx - X ) == 1 && abs(curry - Y ) == 0) || ( abs( curry - Y ) == 1 && abs( currx - X ) == 0 ) )
                    D = 0 ;
                if( dist[currx][curry] > D + dist[X][Y] ){
                    dist[currx][curry] = D + dist[X][Y] ;
                    if( D == 0 )
                        dq.push_front({currx , curry }) ;
                    else
                        dq.push_back({ currx , curry }) ;
                }
            }
        }
    }
}

int main(){
    FAST_IO ;
    cin >> N >> M ;
    int A , B , C , D ; cin >> A >> B >> C >> D ;
    for( int i = 1 ; i <= N ; i++ ){
        for( int j = 1 ; j <= M ; j++ ){
            cin >> ch[i][j] ;
        }
    }
    
    for( int i = 1 ; i <= N ; i++ ){
        for( int j = 1 ; j <= M ; j++ ){
            dist[i][j] = 1e8 ;
        }
    }
    bfs(A, B) ;
    if( dist[C][D] == 1e8 )
        dist[C][D] = -1 ;
    cout << dist[C][D] << endl ;
    
    return 0 ;
  }


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

int main() {
  int N;
  cin >> N;
  vector<int> card(N);
  for (int i=0; i<N; i++) {
  cin >> card.at(i);
  }
  
  sort (card.begin(), card.end());
  reverse (card.begin(), card.end());
  
  int Alice = 0;
  int Bob = 0;
  for (int i=0; i<N; i++) {
    if (i%2 == 0) Alice += card.at(i);
    if (i%2 == 1) Bob += card.at(i);
  }
  
  cout << Alice-Bob << endl;
}


Measured memory_bytes: 256
from Queue import deque


n, c = map(int, raw_input().split())
h = map(int, raw_input().split())

dp = [0] * n
lines = deque([(-2 * h[n - 1], h[n - 1] ** 2)])
for i in range(n - 2, -1, -1):
    x = h[i]
    while len(lines) > 1:
        m1, n1 = lines[0]
        m2, n2 = lines[1]

        if m1 * x + n1 >= m2 * x + n2:
            lines.popleft()
        else:
            break

    mb, nb = lines[0]
    dp[i] = x * x + c + mb * x + nb

    mn = -2 * x
    nn = dp[i] + x * x
    while len(lines) > 1:
        m1, n1 = lines[-2]
        m2, n2 = lines[-1]
        if (nn - n2) * (m2 - m1) <= (n2 - n1) * (mn - m2):
            lines.pop()
        else:
            break
    lines.append((mn, nn))
print(dp[0])


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  int zenkai=1,count=0;
  bool a=false;
  for(int i=0;i<N;i++){
    count++;
    if(A.at(zenkai-1)==2){
      a=true;
      break;
    }
    else{
      zenkai=A.at(zenkai-1);
    }
  }
  if(a){
    cout << count << endl;
  }
  else{
    cout << -1 << endl;
  }
}

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

using namespace std;

const int md = int(1e9) + 7;

inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}

inline int mul(int a, int b) {
  return (int) ((long long) a * b % md);
}

inline int power(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int a) {
  a %= md;
  if (a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}


const int N = 55;

struct matrix {
  int a[N][N] = {};
};

int m;

matrix multiply(matrix a, matrix b) {
  matrix c;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      c.a[i][j] = 0;
      for (int k = 0; k < m; k++) {
        add(c.a[i][j], mul(a.a[i][k], b.a[k][j]));
      }
    }
  }
  return c;
}

matrix power(matrix a, long long b) {
  matrix c;
  for (int i = 0; i < m; i++) {
    c.a[i][i] = 1;
  }
  while (b > 0) {
    if (b & 1) {
      c = multiply(c, a);
    }
    a = multiply(a, a);
    b >>= 1;
  }
  return c;
}

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

  long long k;
  cin >> m >> k;
  matrix a;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a.a[i][j];
    }
  }

  matrix res = power(a, k);
  int sum = 0;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      add(sum, res.a[i][j]);
    }
  }
  cout << sum << '\n';
  return 0;
}

Measured memory_bytes: 384
def resolve():
    N, Y = map(int, input().split())
    if Y - (10000 * N) > 0:
        print("-1 -1 -1")
        return
    for x in reversed(range(N+1)):
        if Y - (10000 * x) < 0:
            continue
        if Y - (10000 * x) - (5000 * (N-x)) > 0:
            break
        for y in reversed(range(N-x+1)):
            if Y == 10000 * x + 5000 * y + 1000 * (N-x-y):
                print(x, y, N-x-y)
                return
    print("-1 -1 -1")


resolve()

Measured memory_bytes: 39664
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cfloat>
#include <climits>
#include <cassert>
#include <random>

int main(){
	std::string s, t; std::cin >> s >> t;
	int a, b; std::cin >> a >> b;
	std::string u; std::cin >> u;
	if (s == u) {
		--a;
	}
	else {
		--b;
	}
	std::cout << a << ' ' << b << '\n';
}


Measured memory_bytes: 888
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int m;
    scanf("%d",&m);
    while(m--){
        int g,y,n,ma=0;
        scanf("%d%d%d",&g,&y,&n);
        while(n--){
            int t,x;
            double r;
            scanf("%d%lf%d",&t,&r,&x);
            int z=g;
            if(!t){
                int b=0;
                for(int i=0;i<y;i++){
                    b+=(int)(z*r);
                    z-=x;
                }
                z+=b;
            }else{
                for(int i=0;i<y;i++)z=z+(int)(z*r)-x;
            }
            ma=max(ma,z);
        }
        printf("%d\n",ma);
    }
    return 0;
}

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

int main(){
    string s,t,ans;
    cin >> s;
    cin >> t;
    ans = "Yes";

    rep(i, s.size()){
        if(s[i]!=t[i]){
            ans="No";
            break;
        }
    }

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

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll arr[10000];
int main(){
	for(ll i=0;i<=1000;i++){
		arr[i]=i*i*i*i*i;
	}
	ll x;
	cin>>x;
	for(int i=0;i<=1000;i++){
		for(int j=0;j<=1000;j++){
			if(arr[i]-arr[j]==x) {
				cout<<i<<" "<<j<<endl;
				return 0;
			}
			if(-arr[i]-arr[j]==x){
				i=-i;
				cout<<i<<" "<<j<<endl;
				return 0;
			}
			if(arr[i]+arr[j]==x){
				j=-j;
				cout<<i<<" "<<j<<endl;
				return 0;
			}
			if(-arr[i]+arr[j]==x){
				i=-i;j=-j;
				cout<<i<<" "<<j<<endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
int main(void){
	int n,k;
	char a[50];
	scanf("%d %d",&n,&k);
	scanf("%s",a);
	
	if(a[k-1]=='A') a[k-1]='a';
	if(a[k-1]=='B') a[k-1]='b';
	if(a[k-1]=='C') a[k-1]='c';
	
	printf("%s\n",a);
	return 0;
}

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

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vp vector<pair<int, int>>
#define vll vector<long long>
#define inf 1000000100
#define infll 1LL << 50

ll gcd(ll a, ll b)
{
    if(b == 0)
    {
        return a;
    }
    return gcd(b, a%b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a/g * b; //prevent overflow
}

/////////////////////////  END OF TEMPLATE ////////////////////////////////////////


int main()
{
    string s;
    cin >> s;
    set<char> v;
    for(int i = 0 ; s[i]; ++i)
    {
        v.insert(s[i]);
    }

    if(v.size() == 26)
    {
        cout << "None" << endl;
    }
    else
    {
        char ans = 'a';
        for(int i = 0; i < 26; ++i)
        {
            if(!v.count(ans+i))
            {
                ans += i;
                break;
            }

        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 512
N = int(input())
prev = [False, False, False]
for n in range(N):
    D1, D2 = list(map(int, input().split(' ')))
    prev = prev[1:] + [D1 == D2]
    if all(prev):
        print('Yes')
        import sys
        sys.exit()

print('No')

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

using namespace std;

typedef long long ll;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
#ifdef sweety_candy
	freopen("input.txt","rt",stdin);
	freopen("ouput.txt","w",stdout);
#endif	
	ll n, k;
	cin >> n >> k;   
	ll ans1 = (n/k)*(n/k)*(n/k);
	ll ans2 = ((k%2 == 0) ? ((n+k/2)/k)*((n+k/2)/k)*((n+k/2)/k) : 0);
	cout <<	ans2 + ans1;    	
		
#ifdef sweety_candy
	cout << " Time elapsed: " << 1.0*clock() / LOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 256
x = int(input())
pr = [2]
if x == 2:
    print(2)
else:
    for i in range(3,100009,2):
        fr = 0
        for j in pr:
            if i % j == 0:
                fr += 1
                break
        if fr == 0:
            if i >= x:
                print(i)
                break
            pr.append(i)
    

Measured memory_bytes: 42096
S = list(input())
T = list(input())

flag = 0
dic1 = {}
dic2 = {}

for i in range(len(S)):
    if dic1.get(S[i]) == None:
        dic1[S[i]] = T[i]
    elif dic1[S[i]] != T[i]:
        print("No")
        exit()
    
    if dic2.get(T[i]) == None:
        dic2[T[i]] = S[i]
    elif dic2[T[i]] != S[i]:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 6704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<int, ll> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
const ll MAXN = 200005;

int n, m;
pii rng[MAXN];
pii rbt[MAXN];

void mrg (int x, int y) {
    pii nr = pii(min(rng[x].X, rng[y].X), max(rng[x].Y, rng[y].Y));
    rng[x] = rng[y] = nr;
}
/********** Good Luck :) **********/
int main () {
    TIME(main);
    IOS();

    cin >> n >> m;
    REP (i, m) {
        cin >> rbt[i].X >> rbt[i].Y;
    }
    sort(rbt, rbt + m);

    REP1 (i, n) {
        rng[i] = pii(i, i);
    }

    REP (i, m) {
        mrg(rbt[i].Y, rbt[i].Y+1);
    }

    REP1 (i, n) {
        cout << rng[i].Y - rng[i].X + 1 << " \n"[i==n];
    }

    return 0;
}



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

 class Main{
    public static void main(String[] args){
    try{
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String str = reader.readLine();
        String[] arr  = str.split(" ");
        int a = Integer.parseInt(arr[0]);
        int b = Integer.parseInt(arr[1]);
        int c = Integer.parseInt(arr[2]);
        if(a<b && b<c){
           System.out.println("Yes");          
         }else{
           System.out.println("No");
        }
    }catch(IOException e){
     e.printStackTrace();
    }
}
}

Measured memory_bytes: 24428
#include<iostream>
#include<stdio.h>
using namespace std;
int main (){
  int a,b,d,r;
  double f;
    cin >>  a >> b;
    d = a/b;
    r = a%b;
    f = 1.0*a/b;
    cout << d << " " << r << " " ;
    printf("%.5lf\n",f);
    return 0 ;
}


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

char s[9][17];
int a,b,sumx[9],sump[9];

int main(){
	int i;
	for( i = 0;i < 9;i++ ){
		cin >> s[i] >> a >> b;
		sumx[i] = a+b;
		sump[i] = a*200+b*300;
	}
	for( i = 0;i < 9;i++ ){
		cout << s[i] << " " << sumx[i] << " " << sump[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  lol n;
  cin >> n;
  lol a[n + 5];
  rep(i, n){
    cin >> a[i];
  }
  sort(a, a +n, greater<lol>());
  cout << a[0] << " ";
  lol ans = a[1];
  for(int i = 2;i < n;i ++){
    if(min(a[0] - ans, ans) < min(a[0] - a[i], a[i])){
      ans = a[i];
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1024
N,W = map(int,input().split())
w = [0]*N
v = [0]*N
for i in range(N):
    w[i], v[i] = map(int,input().split())

sumv = sum(v)
inf = float('inf')
#dp = [[inf]*110000 for _ in range(N+1)]
dp = [[inf]*(sumv+1) for _ in range(N+1)]
for row in range(N+1):
    dp[row][0] = 0


for i in range(N):
    for j in range(sumv+1):
        dp[i+1][j] = min(dp[i][j],dp[i][j-v[i]]+w[i]) #i番目の商品までで価値jを達せられる重さの最小値
# print(dp)
# for i in range(N):
#     print(dp[i])

ans = 0
for i in range(N+1):
    for j in range(sumv+1):
        if dp[i][j] <= W: # 重さ制約を満たすあ時に価値が上回っていたら更新
            ans = max(ans,j)
print(ans)
# 3 50
# 1 2
# 2 3
# 3 4

Measured memory_bytes: 383276
#include<cstdio>
#include<cstring>
using namespace std;
char S[101];
int OK,ok;
int main()
{
	scanf("%s",&S);
	for(int i=0;i<strlen(S);i++)
	{
		if(S[i]=='C'||OK)
		{
			OK=1;
			if(S[i]=='F')
			ok=1;
		}
	}
	if(OK&&ok)
	printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

int main(){
    int x;
    cin >> x;
    int a;
    cin >> a;
    int b;
    cin >> b;
    int ans = 0,k = 0;
    ans = x - a;
    while(1){
        k++;
        if(ans >= 0){
            ans = x - a;
            ans = ans - b * k;
        }else{
            ans = x - a;
            ans = ans - b * (k - 2);
            break;
        }
    }

    cout << ans ;

}

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

bool judge(int a, int b, int n){
    int tmp = 0;
    while(true){
        if(n < 10){
            tmp += n;
            break;
        }
        tmp += n % 10;
        n /= 10;
    }

    if(a <= tmp && tmp <= b){
        return true;
    }
    else{
        return false;
    }
}

int main(){
    int n, a, b;
    cin >> n >> a >> b;

    int ans = 0;
    for(int i = 1; i <= n; i++){
        bool flag = judge(a, b, i);
        if(flag){
            ans += i;
        }    
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N,ans=-114514,num;
int main(){
  cin >> N;
  for(int i=1;i<=N;i++){
    int count=0;
    int tmp=i;
    while(1){
      tmp=tmp/2;
      if(tmp==0) break;
      count++;
    }
    if(ans<count) num=i;
    ans=max(ans,count);
  }
  cout << num << endl;
  return 0;
}


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

int main() 
{
    int N;
    ll T;
    scanf("%d %lld", &N, &T);
    ll query[N];
    for(int i = 0; i < N; ++i) scanf("%lld", &query[i]);
    sort(query, query +  N);
    vector<pair<ll, ll>> tm;
    tm.push_back(make_pair(query[0], query[0] + T));
    for(int i = 1; i < N; ++i) {
        ll t = query[i];
        ll lst = tm[tm.size()-1].second;
        if(t <= lst) tm[tm.size()-1].second = t + T;
        else tm.push_back(make_pair(t, t + T));
    }
    ll res = 0;
    for(int i = 0; i < tm.size(); ++i)
        res += tm[i].second - tm[i].first;

    printf("%lld\n", res);
    return 0;
}

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

#define all(x) x.begin(),x.end()
#define pb(x) emplace_back(x)
#define forn(i,N) for(int i=0;i<N;i++)
#define form(i,x,N) for(int i=x;i<N;i++)

using namespace std;
using ll=long long int;
using ld=long double;
using umap=unordered_map<int,int>;
using uset=unordered_set<int>;

int main() {
//freopen("input.txt","rt",stdin);
ios::sync_with_stdio(false);
cin.tie(nullptr);

int N,L;
cin>>N>>L;
vector<string> v(N);
for(auto& x: v)
  cin>>x;
sort(all(v));
for(auto& x: v)
  cout<<x;
cout<<endl;
return 0;
}


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

int main(void){
  int n, i, count = 0;
  cin >> n;
  int a[n] = {};
  for(i = 0; i < n; i++){
    cin >> a[i];
  }
  while(true){
    for(i = 0; i < n; i++){
      if(a[i]%2 != 0){
        cout << count << endl;
        return 0;
      }
      a[i] /= 2;
    }
    count++;
  }
}


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

void func_A() {
    bool f = false;
    int K, A, B;
    cin >> K;
    cin >> A >> B;
    for(int i = A; i <= B; i++) {
        if(i % K == 0) f = true;
    }
    if(f) {
        cout << "OK";
    } else {
        cout << "NG";
    }
}
void func_B() {}
void func_C() {}
void func_D() {}
int main() {
    func_A();
    return 0;
}

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

using namespace std;

int main()
{
    vector< vector<int> > v (3, vector<int>(3,0));
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            int t;
            cin>>t;
            v[i][j]=t;
        }
    }
    int n;
    cin>>n;
    int b[n];
    for(int i=0;i<n;i++)
     cin>>b[i];
     vector<int> :: iterator it;
     for(int i=0;i<n;i++)
     {
          it=find(v[0].begin(),v[0].end(),b[i]);
          if(it!=v[0].end())
           v[0][it-v[0].begin()]=-1;
           it=find(v[1].begin(),v[1].end(),b[i]);
          if(it!=v[1].end())
           v[1][it-v[1].begin()]=-1;
            it=find(v[2].begin(),v[2].end(),b[i]);
          if(it!=v[2].end())
           v[2][it-v[2].begin()]=-1;
     }
    if(count(v[0].begin(),v[0].end(),-1)==3)
     cout<<"Yes";
     else if(count(v[1].begin(),v[1].end(),-1)==3)
     cout<<"Yes";
     else if(count(v[2].begin(),v[2].end(),-1)==3)
     cout<<"Yes";
     else if(v[0][0]==-1 && v[1][1]==-1 && v[2][2]==-1)
     cout<<"Yes";
     else if(v[0][2]==-1 && v[1][1]==-1 && v[2][0]==-1)
     cout<<"Yes";
     else if(v[0][0]==-1 && v[1][0]==-1 && v[2][0]==-1)
     cout<<"Yes";
     else if(v[0][1]==-1 && v[1][1]==-1 && v[2][1]==-1)
     cout<<"Yes";
     else if(v[0][2]==-1 && v[1][2]==-1 && v[2][2]==-1)
     cout<<"Yes";
     else
     cout<<"No";
   
   
   return 0;
}

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

int main()
{
    int l,r,d,ans;
    cin >> l >> r >> d;
    if(l%d==0)
    {
        ans = r/d - l/d + 1;
    }
    else{
        ans = r/d - l/d;
    }
    cout << ans;
}


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

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

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

    int cnt = 0;
    for (int i = 0; i < N; i++) {
        // find min
        int minj = i;
        for (int j = i; j < N; j++) {
            if (A.at(minj) > A.at(j)) {
                minj = j;
            }
        }
        
        // swap
        if (i != minj) {
            int tmp = A.at(i);
            A.at(i) = A.at(minj);
            A.at(minj) = tmp;
            cnt++;
        }
    }

    // output
    for (int i=0; i<N-1; i++) cout << A.at(i) << " ";
    cout << A.at(N-1) << endl;
    cout << cnt << endl;

    return(0);
}


Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
int main(void){
  long long n; cin>>n;
  long long res=0;
  if((n&1)==0){
    long long five=5,i;
    while(i=n/five/2) res+=i,five*=5;
  }
  cout<<res;
  return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,a,ans = 0;
  cin >> N;
  for(int i = 0;i < N;i++){
    cin >> a;
    while(a%2 == 0){
      ans++;
      a/=2;
    }
  }
  cout << ans << endl;
}


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

int main(void){
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    int time = 0, temp = a;
    if (a < 0) {
        for (temp = a; temp < 0; temp++) {
            time += c;
            
        }
        temp = 0;
        time += d;
    }
    for(; temp < b; temp++) {
        time += e;
    }
    cout << time << endl;
}



Measured memory_bytes: 3120
x=[]
y=[]
N,M,X,Y=[int(i) for i in input().split()]
x=[int(i) for i in input().split()]
y=[int(i) for i in input().split()]
if max(x)<min(y) and X<Y:
    if min(y)>X:
        if max(x)<Y:
            print("No War")
        else:
            print("War")
    else:
        print("War")
else:
    print("War")


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

int main(){
    string s;
    cin >> s;
    int cnt = 1;
    rep(i,s.size()-1){
        if(s[i] != s[i+1]) cnt++;
    }
    cout << cnt - 1 << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10,mod=1e9+7;
int n,m,cnt,a[N],b[N],tmpx[N],tmpy[N],c1,c2;
struct node {
	int x, y;
	bool operator < (const node &T) const {
		return x==T.x?y>T.y:x<T.x;
	}
}A[N];
struct Tree {
	int s[N];
	void update(int x, int y){for(;x<=c2;x+=x&-x)(s[x]+=y)%=mod;}
	int query(int x){int res=0;for(;x;x-=x&-x)(res+=s[x])%=mod;return res;}
}T;
int main() {
	int x; priority_queue<int, vector<int>, greater<int> > q;
	cin>>n>>m;
	for(int i=1;i<=n;++i)cin>>x,q.push(x);
	for(int i=1;i<=m;++i)cin>>b[i];
	n=0;
	while(!q.empty()) {
		int k=q.top(),pos=lower_bound(b+1,b+m+1,k)-b;q.pop();
		if(k<=b[1]||k >= b[m]||b[pos]==k) continue;
		A[++cnt].x=b[pos]-k;A[cnt].y=k-b[pos-1];
		tmpx[++c1]=A[cnt].x,tmpy[++c2]=A[cnt].y;
	}
	sort(tmpx + 1, tmpx + c1 + 1), sort(tmpy + 1, tmpy + c2+1);
	c1=unique(tmpx+1,tmpx+c1+1)-tmpx-1;
	c2=unique(tmpy+1,tmpy+c2+1)-tmpy-1;
	for(int i = 1; i <= cnt; ++i){
		A[i].x=lower_bound(tmpx+1,tmpx+c1+1,A[i].x)-tmpx;
		A[i].y=lower_bound(tmpy+1,tmpy+c2+1,A[i].y)-tmpy;
	}
	sort(A+1,A+cnt+1);
	int ans=1;
	for(int i=1;i<= cnt;++i) {
		if(A[i].y==A[i-1].y&& A[i].x==A[i-1].x) continue;
		int now = T.query(A[i].y-1)+1;
		(ans+=now)%=mod;
		T.update(A[i].y,now);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2808
import math
while True:
    n = int(input())
    if n == 0:
        break

    s = list(map(int, input().split()))
    m = sum(s) / n
    z = sum([(float(s[i])-m)**2 for i in range(n)])
    b = z / n
    print("{0:.8f}".format(math.sqrt(b)))

Measured memory_bytes: 5712
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define first fi
#define second se
#define MOD 1000000007
#define MAXN 1000006
#define endl "\n"
#define readln(x) getline(cin, x);
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
ll fpow(ll x, ll n, ll mod){if (n==0) return 1%mod; ll u = fpow(x, n/2, mod); u = (u*u)%mod; if (n%2==1)u = (u*x)%mod;return u;}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

ll N, A, B, total = 0;
int main(){
    //freopen("data.txt","r",stdin);
    cin >> N >> A >> B;
    ll mod = (N)%(A+B);
    ll div = N/(A+B);
    total += div*A;
    if (A> mod) total += mod;
    else total += A;
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> a(H);
    for(int i = 0; i < H; i++) cin >> a[i];
    int dH[H], dW[W];
    for(int i = 0; i < H; i++) dH[i] = 0;
    for(int i = 0; i < W; i++) dW[i] = 0;

    for(int i = 0; i < H; i++) {
        bool allwhite = true;
        for(int j = 0; j < W; j++) {
            if(a[i][j] == '#') {
                allwhite = false;
                break;
            }
        }
        if(allwhite) dH[i] = 1;
    }

    for(int i = 0; i < W; i++) {
        bool allwhite = true;
        for(int j = 0; j < H; j++) {
            if(a[j][i] == '#') {
                allwhite = false;
                break;
            }
        }
        if(allwhite) dW[i] = 1;
    }

    for(int i = 0; i < H; i++) {
        bool flag = false;
        for(int j = 0; j < W; j++) {
            if(dH[i] == 0 && dW[j] == 0) {
                cout << a[i][j];
                flag = true;
            }
        }
        if(flag) cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

signed main(){
    int A,B; cin >> A >> B;
    cout << 6 - A - B << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>

std::vector<long long> v;

bool isprime() {
	v.push_back(2);
	for (long long i = 3; i * i <= 1000000000000LL; i += 2)
	{
		bool flag = true;
		for (long long j = 3; j * j < i; j += 2)
		{
			if (j % i == 0) {
				flag = false;
			}
		}

		if (flag) {
			v.push_back(i);
		}

	}
	return true;
}

int main() {
	long long n;
	long long p;

	std::cin >> n >> p;

	if (n == 1) {
		std::cout << p << std::endl;
		return 0;
	}

	long long ans = 1;

	int count = 0;

	while (p % 2 == 0) {
		count++;
		p /= 2;
	}
	isprime();

	ans *= pow(2, (count / n));
	count = 0;
	int index = 1;

	for (long long i = 0; i < v.size(); i++)
	{
		while (p % v[i] == 0) {
			count++;
			p /= v[i];
		}
		ans *= pow(v[i], (count / n));
		count = 0;
	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 6384
// ABC167B - 

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

typedef unsigned long long int ull;
typedef long long int ll;

int main() {
	int A, B, C, K;
	cin >> A >> B >> C >> K;

	if (A >= K) {
		cout << K << endl;
	} else if (A + B >= K) {
		cout << A << endl;
	} else {
		cout << A - (K - (A + B)) << endl;
	}

	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
#include <fstream>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;
#define MOD 1000000007

int judge(int n) {
    ll t = 2;
    REP(i,30) {
        if((t<<i)-1 == n) return i;
    }
    return -1;
}

int main() {
    
    int N; cin >> N;
    vector<int> a(N);
    REP(i,N) cin >> a[i];
    
    int x = 0;
    REP(i,N) x ^= a[i];
    
    bool exist[32];
    REP(i,32) exist[i] = false;
    
    REP(i,N) {
        int t = a[i] ^ (a[i] - 1);
        if(judge(t) != -1) exist[judge(t)] = true;
    }
    
    int cnt = 0;
    for(int i=30;i>=0;i--) {
        if((x>>i)&1) {
            if(exist[i]) {
                x ^= ((2<<i)-1);
                cnt++;
            }
        }
    }
    
    if(x == 0) cout << cnt << endl;
    else cout << -1 << endl;
    
    return 0;
}


Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = 6000000;
const int K = 250;
int p[N], a[N], s[N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n >> p[0];
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        if (abs(p[i - 1] - a[i]) < p[i - 1]){
            p[i] = abs(p[i - 1] - a[i]);
        } else p[i] = p[i - 1];
    }
    for (int i = n; i >= 1; i--){
        if (a[i] <= 2 * s[i + 1] + 1){
            s[i] = s[i + 1] + a[i];
        } else s[i] = s[i + 1];
    }
    int q;
    cin >> q;
    while(q--){
        int k;
        cin >> k;
        if (p[k - 1] <= s[k + 1]){
            cout << "NO" << endl;
        } else{
            cout << "YES" << endl;
        }
    }
}


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

int main() {
    int N;
    cin >> N;
    vi A(N);
    rep(i, N) {
        cin >> A[i];
    }

    vi ans;
    for (int i = N - 1; i >= 0; i -= 2) {
        ans.push_back(A[i]);
    }
    if (N % 2 == 0) { 
        for (int i = 0; i < N; i += 2) {
            ans.push_back(A[i]);
        }
    } else {
        for (int i = 1; i < N; i += 2) {
            ans.push_back(A[i]);
        }
    }

    rep(i, ans.size()) {
        cout << ans[i];
        if (i != ans.size() - 1) {
            cout << " ";
        }
    }
    cout << endl;
}

Measured memory_bytes: 5092
n = int(input())
a = input()
b = input()
C = input()
ans = 0
c  ={}
for i in range(n):
    if a[i] not in c:  c[a[i]] = 1
    else:c[a[i] ] +=1
    if b[i] not in c:  c[b[i]] = 1
    else:c[b[i] ] +=1
    if C[i] not in c:  c[C[i]] = 1
    else:c[C[i]] +=1
    ans += len(c)-1
    c = {}
print(ans)

    
    

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main()
{
    cout.precision(18);

    long long N, K;
    set<long long> D;

    cin >> N >> K;
    for (long long i = 0; i < K; i++)
    {
        long long t;
        cin >> t;
        D.insert(t);
    }

    long long i = N;
    while (true)
    {
        long long j = i;
        bool f = false;
        while (j > 0)
        {
            if (D.find(j % 10) != D.end()) // found
            {
                f = true;
                break;
            }
            j /= 10;
        }

        if (f == false)
        {
            cout << i << endl;
            return 0;
        }

        i++;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;
constexpr int dy[4] = { 0,1,0,-1 }; constexpr int dx[4] = { 1,0,-1,0 };

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

    vector<ll> asum(N + 1);
    rep(i, N) asum[i + 1] = asum[i] + a[i];

    vector<ll> b;
    rep(i, 0, N) rep(j, i + 1, N + 1) {
        b.push_back(asum[j] - asum[i]);
    }

    ll ans = 0;
    for (int i = 39; i >= 0; --i) {
        int cnt = 0;
        rep(j, b.size()) {
            if ((b[j] & ans) == ans) cnt += (b[j] >> i) & 1;
        }

        if (cnt >= K) {
            ans |= 1LL << i;
        }
    }

    write(ans);
}

Measured memory_bytes: 5872
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#define ll long long int

int compare_longlong(const void *a, const void *b) {long long *A = (long long *)a;long long *B = (long long *)b;if (*A > *B) return 1;if (*A < *B) return -1;return 0;}
int main(void){
	int n,ans=0,i;
	scanf("%d",&n);
	ll a[n],b[n],ba=0;
	for(i=0;i<n;i++)scanf("%lld",&a[i]);
	for(i=0;i<n;i++){
		scanf("%lld",&b[i]);
		if(a[i]<b[i]){
			ans++;
			ba += b[i]-a[i];
		}
	}
	if(ans==0)ans=0;
	else{
		ll d[n];
		for(i=0;i<n;i++)d[i]=a[i]-b[i];
		qsort(d,n,sizeof(ll),compare_longlong);
		ll s=0;
		for(i=0;i<n;i++){
			if(d[n-1-i]>=0){
				s+=d[n-1-i];
				if(s>=ba){
					ans+=i+1;
					break;
				}
			}
		}
		if(s<ba && i==n)ans=-1;
	}
	printf("%d",ans);
	
	return 0;
}

Measured memory_bytes: 3324
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string.h>
#include <cassert>
#include <string.h>
#include <tuple>

using namespace std;
#define  rep(i,n) for(int i=0;i<n;i++)
#define  rrep(i,n) for(int i=n-1;i>=0;i--)///n-1番目からn回
#define  REP(i,a,b) for(int i=a;i<=b;i++) ///a番目からb回
#define  RREP(i,a,b) for(int i=a;i<b;i--)
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pair_t;
#define MOD 1000000007

//int arr[N]
////sort(arr,arr +N)

//vector <int> hoge
////sort(hoge.begin(),hoge.end());
///*min_element(hoge.begin(),hoge.end();　最小値　　　最大値はmax_element();
///(10-(n%10))%10  10-(1桁目)取得 12->8 20->0

#define Ru(n)  ( ((n)+9)/10*10  ) //切りあげ
#define Rd(n)  ( ((n)-10)/10*10 +10 )	切り捨て


ll gcd(ll a,ll b);
size_t length(const std::string& str) {
	return str.length();
}
bool comp(const pair_t &a, const pair_t &b) {
	return a.first < b.first;
}

int main() {
	ll  a,b,GCD,ans=0;
	cin>>a>>b;
	GCD=gcd(a,b);
	if(GCD==1){
		cout<<1;
		return 0;
	}
	double stop=sqrt(GCD);
	vector<ll> x;
	for(ll i=1;i<=stop;i++){
		if(GCD%i==0) {
			x.push_back(i);
			if(i!=GCD/i)
				x.push_back(GCD / i);
		}

	}
	cout<<"\n";
	for(int i=0;i<x.size();i++){
		ll p=x[i];
		int flag=0;
		for(ll k=1;k<=sqrt(p);k++){
			if(p%k==0){
				flag++;
			}
		}
		if(flag==1) {
			ans++;
			//cout << p << endl;
		}
	}

	cout<<ans<<endl;

	return 0;

}


ll gcd(ll a,ll b){
	if(b==0) return a;
	return gcd(b,a%b);
}


Measured memory_bytes: 384
/** Which of the favors of your Lord will you deny ? **/

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

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define F first
#define S second

#define ALL(x)      (x).begin(), (x).end()
#define READ        freopen("alu.txt", "r", stdin)
#define WRITE       freopen("vorta.txt", "w", stdout)

#ifndef ONLINE_JUDGE
#define DBG(x)      cout << __LINE__ << " says: " << #x << " = " << (x) << endl
#else
#define DBG(x)
#endif

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int nmax = 2e5+7;

int main()
{
    optimizeIO();

    int tc =1 ;

    while(tc--)
    {
        int r,g,b;
        int k;
        cin>>r>>g>>b>>k;

        int c = 0;

        while(g<=r)
        {
            g *= 2;
            c++;
        }

        while(b<=g)
        {
            b *= 2;
            c++;
        }

        if(c<=k) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;

    }

    return 0;
}

/**

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}




Measured memory_bytes: 3632
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int area = a*b ;
        int length = 2*(a+b);
        System.out.println(area + " " +length);
    }
}


Measured memory_bytes: 26232
#include <stdio.h>
#include <stdlib.h>

typedef struct{
    long long num;
    long long mul;
}set;
int compare(const void *a,const void *b){
    set x=*(set *)a,y=*(set *)b;
    long long  tmp1=x.num,tmp2=y.num; 
    if(tmp1>tmp2)return 1;
    return -1;
}
int main()
{   long long n,k;
    scanf("%lld%lld",&n,&k);
    set a[n];
    for(int i=0;i<n;i++){
        scanf("%lld%lld",&a[i].num,&a[i].mul);
    }
    qsort(a,n,sizeof(set),compare);
    //for(int i=0;i<n;i++)printf("%lld %lld\n",a[i].num,a[i].mul);
    long long cnt=0,i=0;
    while(cnt<k){
        cnt+=a[i].mul;
        //printf("cnt=%lld\n",cnt);
        i++;
    }
    printf("%lld",a[i-1].num);

    return 0;
}


Measured memory_bytes: 3324
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
a=list(map(int,input().split()))

s=0
e=1
ans=n
acc=[0]*(n+1)
for i in range(n):
  acc[i+1]=acc[i]+a[i]
while True:
    if s==e:
      e+=1
      continue
    if s==n-1:
      
      break
    res=acc[e]-acc[s]
    for i in range(20):
        if res&(1<<i)!=0 and a[e]&(1<<i)!=0:
            s+=1
            ans+=(e-s)
            break
    else:
        e+=1
    if e==n:
      s+=1
      ans+=(e-s)
      e=n-1
print(ans)

Measured memory_bytes: 103692
use std::io;

fn main() {

	let  mut number = String::new();
	let  mut letter = String::new();  
	io::stdin().read_line(&mut number).unwrap();
	io::stdin().read_line(&mut letter).unwrap();
	//println!("{:?}",number );
	letter.pop();
	let mut v: String = letter.chars().collect();
	//println!("{:?}",v );
	let number: usize = number.trim().parse()
		.expect("number please");
	//println!("{:?}",number );
	if v.len() > number {
		v.split_off(number);
		//let v: char = v.to_string()
		println!("{}",v + "...");
	} else {
		//let v: char = v
		let v = v.to_string();
		println!("{}",v);
	}
	//println!("{:?}",len );





}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  int sum = 0;
  for (int i = 0; i < m; ++i) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  if (sum > n) cout << -1 << endl;
  else cout << n-sum << endl;
  
}


Measured memory_bytes: 3632