akhauriyash/Code-Regression huggingface dataset:
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    ll N; cin >> N;
    vl A(N+1,0); FOR(i, 1, N+1) cin >> A[i];

    vl s(N + 1, 0);
    FOR(i,1,N+1) {
        s[i] = s[i - 1] + A[i];
    }

    map<ll, ll> mp;
    FOR(i,0,N+1) {
        mp[s[i]]++;
    }

    ll ans = 0;
    for (auto kv : mp) {
        ans += kv.second * (kv.second - 1) / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 15872
//by Sshwy
//#define DEBUGGER
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define FOR(i,a,b) for(long long i=(a);i<=(b);++i)
#define ROF(i,a,b) for(long long i=(a);i>=(b);--i)

#ifdef DEBUGGER

#define log_prefix() { fprintf(stderr, "\033[37mLine %-3d [%dms]:\033[0m  ", __LINE__,(int)clock()/1000);  }
#define ilog(...)    { fprintf(stderr, __VA_ARGS__); }
#define llog(...)    { log_prefix(); ilog(__VA_ARGS__); }
#define log(...)     { log_prefix(); ilog(__VA_ARGS__); fprintf(stderr,"\n");  }
#define red(...)     { log_prefix(); ilog("\033[31m"); ilog(__VA_ARGS__); ilog("\033[0m\n"); }
#define green(...)   { log_prefix(); ilog("\033[32m"); ilog(__VA_ARGS__); ilog("\033[0m\n"); }
#define blue(...)    { log_prefix(); ilog("\033[34m"); ilog(__VA_ARGS__); ilog("\033[0m\n"); }

#else

#define log_prefix() ;
#define ilog(...)    ;
#define llog(...)    ;
#define log(...)     ;
#define red(...)     ;
#define green(...)   ;
#define blue(...)    ;

#endif

namespace RA{
    long long r(long long p){return 1ll*rand()*rand()%p;}
    long long r(long long L,long long R){return r(R-L+1)+L;}
}/*}}}*/
/******************heading******************/

long long n;

string calc(long long x,long long y,long long k){//2^0,2^1,...,2^k
    if(k==-1)return "";
    long long f1=x<0,f2=y<0;
    x=abs(x),y=abs(y);
    string s;
    if(x>y)s='R'+calc(x-(1<<k),y,k-1);
    else s='U'+calc(x,y-(1<<k),k-1);
    if(f1)for(auto & c:s){
        if(c=='L')c='R';
        else if(c=='R')c='L';
    }
    if(f2)for(auto & c:s){
        if(c=='U')c='D';
        else if(c=='D')c='U';
    }
    return s;
}

void check(string s,vector<long long> d,pair<int,int> p){
    assert(s.size() == d.size());
    long long px=0,py=0;
    for(long long i=0;i<s.size();i++){
        if(s[i]=='L')px-=d[i];
        if(s[i]=='R')px+=d[i];
        if(s[i]=='U')py+=d[i];
        if(s[i]=='D')py-=d[i];
        //printf("%d %d\n",px,py);
    }
    assert(px==p.fi && py==p.se);
}
signed main(){
    long long n;
    cin>>n;
    vector< pair<int,int> > v;
    FOR(i,1,n){
        long long x,y;
        cin>>x>>y;
        if(v.size() && abs(v.back().fi+v.back().se)%2 != abs(x+y)%2){
            cout<<-1<<endl;
            return 0;
        }
        v.pb({x,y});
    }

    vector<long long> d;

    if(abs(v.back().fi+v.back().se)%2==0){
        d.pb(1);
        ROF(i,30,0)d.pb(1ll<<i);
        cout<<d.size()<<endl;
        for(auto x:d)cout<<x<<" ";
        cout<<endl;
        for(auto p:v){
            auto ans=('R'+calc(p.fi-1,p.se,30));
            cout<<ans<<endl;
            check(ans,d,p);
        }
    }else {
        ROF(i,30,0)d.pb(1ll<<i);
        cout<<d.size()<<endl;
        for(auto x:d)cout<<x<<" ";
        cout<<endl;
        for(auto p:v){
            auto ans=calc(p.fi,p.se,30);
            cout<<ans<<endl;
            check(ans,d,p);
        }
    }
    return 0;
}


Measured memory_bytes: 256
import numpy as np
N, M = (int(x) for x in input().split())
x, y, z = np.zeros(N, dtype=int), np.zeros(N, dtype=int), np.zeros(N, dtype=int)
for i in range(N):
    x[i], y[i], z[i] = (int(x) for x in input().split())
temp = []
for sx in (-1, 1):
    for sy in (-1, 1):
        for sz in (-1, 1):
            _x, _y, _z = sx*x, sy*y, sz*z
            T = np.sort(_x+_y+_z)[::-1][:M].sum()
            temp.append(T)

print(max(temp))


Measured memory_bytes: 12928
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
using namespace std;
typedef long long ll;
const int maxn = 200005;

int g[1<<26];

int main() {
#ifdef suiyuan2009
  freopen("in.cpp","r",stdin);
#endif // suiyuan2009
  string s;
  cin>>s;
  int mask=0,ret;
  for(int i=0; i<s.size(); i++) {
    mask^=(1<<(s[i]-'a'));
    ret=i+1;
    int cnt=0;
    if(g[mask])ret=min(ret,g[mask]+1);
    for(int j=0; j<26; j++) {
      if(mask&(1<<j))cnt++;
      int tmask=mask^(1<<j);
      if(g[tmask])ret=min(ret,g[tmask]+1);
    }
    if(cnt<=1)ret=1;
    if(g[mask]==0)g[mask]=ret;
    else g[mask]=min(g[mask],ret);
  }
  cout<<ret<<endl;
  return 0;
}



Measured memory_bytes: 262404
#include <stdio.h>

main()
{
  int a, b, n;

  scanf("%d %d", &a, &b);

  if(a < b)
    {
      n = a;
      a = b;
      b = n;
    }

  while(b > 0)
    {
      n = a % b;
      a = b;
      b = n;
    }

  printf("%d\n", a);
  return 0;
}

Measured memory_bytes: 592
from collections import deque

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

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

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

queue = deque([0])
d = [None]*n
d[0] = 0
while queue:
    v = queue.popleft()
    for i in g[v]:
        if d[i] == None:
            d[i] = v + 1
            queue.append(i)
            
if all(type(i) is int for i in d):
    print('Yes')
    for i in d[1:]:
        print(i)
else:
    print('No')


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

int main(){
  int n; cin >> n;
  vector<int> h(n);  
  int count=0,max_reg=0;
  cin >> h[0];
  for(int i=1; i<n; i++){
    cin >> h[i];
    if(h[i]<=h[i-1]){
      count++;
      max_reg=max(count,max_reg);
    } else {
      count=0;
    }
  }
  cout << max_reg << endl;
  return 0;
}

Measured memory_bytes: 640
s=input()
if s == "SUN" :
  print(7)
if s == "MON":
  print(6)
if s == "TUE":
  print(5)
if s == "WED":
  print(4)
if s == "THU":
  print(3)
if s == "FRI":
  print(2)
if s == "SAT":
  print(1)


Measured memory_bytes: 3060
#include <stdio.h>

int		main(void)
{
	long N, K, a;
	scanf("%ld%ld",&N,&K);
	if (N >= K)
		N %= K;
	if (N < K)
	{
		a = K - N;
		a > N ? printf("%ld", N) : printf("%ld", a);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
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(){
    int n;
    cin >> n;
    int k = 1;
    while(true) {
        int t = k * (k+1) / 2;
        if(t == n) {
            // 作成できる
            cout << "Yes" << endl;
            cout << k+1 << endl;
            break;
        }
        else if(t > n) {
            cout << "No" << endl;
            return 0;
        }
        k++;
    }
    // 要素数:k+1 一つの要素の個数:k
    vector<int> start(k+1);
    vector<int> end(k+1);
    start[0] = 0;
    start[1] = k;
    int sc = k-1;
    rep2(i, 2, k+1) {
        start[i] = start[i-1] + sc;
        sc--;
    }
    end[0] = k;
    int ec = k-1;
    rep2(i, 1, k+1) {
        end[i] = end[i-1] + ec;
        ec--;
    }
    rep(i, k+1) {
        cout << k << " ";
        if(i == 0) {
            rep2(j, start[i]+1, end[i]+1) {
                cout << j << " ";
            }
            cout << endl;
            continue;
        }
        rep2(j, start[i], end[i]+1) {
            cout << j << " ";
        }
        if(i-2 < 0) {
            cout << endl;
            continue;
        }
        int count = 1;
        for(int j = i-2; j >= 0; j--) {
            cout << start[j] + count << " ";
            count++;
        }
        cout << endl;
    }
}

Measured memory_bytes: 3632
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys

sys.setrecursionlimit(1000000)

while True:
    n = input()
    if n == 0:
        break
    
    lst = []
    x_lst = []
    y_lst = []

    for loop in range(n):
        l, t, r, b = map(int, raw_input().split())
        lst.append((l, t, r, b))
        x_lst += [l, r]
        y_lst += [t, b]

    x_lst = sorted(list(set(x_lst)))
    y_lst = sorted(list(set(y_lst)))

    mx = {}
    my = {}

    for i in range(len(x_lst)):
        mx[x_lst[i]] = 2 * i + 1

    for i in range(len(y_lst)):
        my[y_lst[i]] = 2 * i + 1

    wall = {}

    def func(x, y):
        if (x, y) in wall:
            return
        if x < 0 or y < 0 or x > 5 * n or y > 5 * n:
            return
        wall[(x, y)] = 1
        func(x - 1, y)
        func(x + 1, y)
        func(x, y - 1)
        func(x, y + 1)

    for sq in lst:
        sx = mx[sq[0]]
        gx = mx[sq[2]]
        sy = my[sq[3]]
        gy = my[sq[1]]
        for x in range(sx, gx + 1):
            wall[(x, sy)] = 1
            wall[(x, gy)] = 1
        for y in range(sy, gy + 1):
            wall[(sx, y)] = 1
            wall[(gx, y)] = 1

    ans = 0

    for y in range(5 * n):
        for x in range(5 * n):
            if not (x, y) in wall:
                ans += 1
                func(x, y)

    print ans



Measured memory_bytes: 67560
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef unsigned long long int ull;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set; 

#define     int                 ll
#define     pb                  push_back
#define     mp                  make_pair
#define     xx                  first
#define     yy                  second    
#define     all(a)              a.begin(),a.end()
#define     vi                  vector<int>
#define     vpi                 vector<pii>
#define     pii                 pair<int, int>
#define     present(DT, val)    (DT.find(val) != DT.end()) //for set and map
#define     cpresent(DT, val)   (find(all(DT),val) != DT.end()) //vectors
#define     input               "/home/pollution/Desktop/WorkSpace/C++/Files/input.txt"
#define     output              "/home/pollution/Desktop/WorkSpace/C++/Files/output1.txt"
#define     error               "/home/pollution/Desktop/WorkSpace/C++/Files/error.txt"
#define     IO()                ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     INF                 2e18
#define     MOD                 1000000007
#define     clr(x)              memset(x, 0, sizeof(x))
#define     init(x, a)          memset(x, a, sizeof(x))
#define     out(a)              for (auto i: a) cout<<i<<' '; cout<<'\n'
#define     cpy(a,b)            memcpy(a,b,sizeof(b))
#define     is(a)               to_string(a)
#define     ci(a,c)             a-c
#define     debug(i)            cout<<"point :"<<i<<'\n';
#define     setd(val,n)         cout<<fixed<<setprecision(n)<<val<<'\n'

void solve(){
    int n,k; cin>>k>>n;
    int mn = 0;
    vi a(n+1,0);
    for(int i = 1; i <= n; ++i) cin>>a[i];
	mn = a[n]-a[1];
	// out(a);
    for(int i = 2; i <= n; ++i){
    	mn = min(mn,a[i-1]+k-a[i]);
    }
    cout<<mn<<'\n';
}

signed main() { 
    IO();
    
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0; 
}

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

int n,t;
typedef pair <int,int> P;

int res = 0;
int dp[3005][3005];
int main(){
    cin >> n >> t;
    vector<P> p(n);
    for(int i = 0;i<n;i++){
        cin >> p[i].first >> p[i].second;
    }
    sort(p.begin(),p.end());
    for(int i = 0;i<n;i++){
        for(int j = 0;j<t;j++){
            dp[i+1][j] = max(dp[i][j],dp[i+1][j]);
            int tmp = j + p[i].first;
            if(tmp < t) dp[i+1][tmp] = max(dp[i+1][tmp],dp[i][j] + p[i].second);
        }
        res = max(res,dp[i][t-1] + p[i].second);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 38836
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#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 < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define inf 10000000000

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

    ll n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;
}


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

#define int long long
#define rep(n, i) for (int i = 0; i < n; i++)
#define rep2(m, n, i) for (int i = m; i < n; i++)
#define rep_r(n, i) for (int i = n - 1; i >= 0; i--)

const int INF = 1LL << 60;
const int MOD = 1e9 + 7;

signed main() {
    int n, m;
    cin >> n >> m;
    int s[n + 1], t[m + 1];
    rep2(1, n + 1, i) {
        cin >> s[i];
    }
    rep2(1, m + 1, i) {
        cin >> t[i];
    }
    int sum[n + 1][m + 1];
    int dp_sum = 0;
    rep(n + 1, i) {
        rep(m + 1, j) {
            if (i == 0 || j == 0) {
                sum[i][j] = 0;
                continue;
            }
            int dp;
            if (s[i] != t[j]) {
                dp = 0;
            } else {
                dp = sum[i - 1][j - 1] + 1;
            }
            sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp + MOD;
            sum[i][j] %= MOD;
        }
    }
    cout << (sum[n][m] + 1) % MOD << endl;    
    return 0;
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(),i.end()
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll H,W;
  cin>>H>>W;
  char a[H][W];
  rep(i,H){
    rep(j,W){
      cin>>a[i][j];
    }
  }
  bool b[H];
  bool c[W];
  rep(i,H) b[i]=true;
  rep(i,W) c[i]=true;
  rep(i,H){
    rep(j,W){
      if(a[i][j]=='#'){
        b[i]=false;
        c[j]=false;
      }
    }
  }
  rep(i,H){
    if(!b[i]){
      rep(j,W){
        if(!c[j]){
          cout<<a[i][j];
        }
      }
      cout<<endl;
    }
  }
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <utility>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;


class segtree
{
	public:
	int depth;//セグ木の深さ(最上部が0）
	int size;
	vector<int> node;//セグ木本体

	//コンストラクタ
	segtree(int n)
	{
		depth=0;
		size=1;
		while(n>size)
		{
			size*=2;
			depth++;
		}
		size*=2;
		node.resize(size,0);
		//最下段に値を入れたあとに、下の段から順番に値を入れる
		//値を入れるには自分の子の2値を参照する
		/*
		for(int i=0;i<n;i++)
			node[i+(1<<depth)]=v[i];
		
		for(int i=depth-1;i>=0;i--)
			node[i]=calc(node[i*2],node[i*2+1]);*/
	}

	//値の更新
	//node[k]にaを加える
	void update(int k,int a)
	{
		k+=(1<<depth);//セグ木上のインデックスに読み替え
		node[k]+=a;
		while(k>1)
		{
			k/=2;
			node[k]=node[k*2]+node[k*2+1];
		}
		return;
	}
	
	//値の取得
	//閉区間[a,b]に値はいくつあるか
	int get(int a,int b)
	{
		a+=(1<<depth);
		b+=(1<<depth);
		if(a==b)
			return node[a];
		int nowa=node[a];
		int nowb=node[b];
		while(a/2<b/2)
		{
			//cerr<<depth<<" "<<a<<" "<<b<<endl;
			//左側はより右側を見る
			if((a&1)==0)
				nowa+=node[a+1];
			//右側はより左側を見る
			if((b&1)==1)
				nowb+=node[b-1];
			a/=2;
			b/=2;
		}
		int ret=nowa+nowb;
		return ret;
	}

	//n番目のノードを探す
	int find(int n)
	{
		int ret=1;
		for(int i=0;i<depth;i++)
		{
			//cerr<<ret-(1<<i)<<" "<<node[ret]<<endl;
			if(n<=node[ret*2])
				ret=ret*2;
			else{
				if(node[ret*2+1]==0)
					ret=ret*2;
				else{
					n-=node[ret*2];
					ret=ret*2+1;
				}
			}
		}
		return ret-(1<<depth);
	}
};

int main()
{
	int n,q;
	cin>>n>>q;
	segtree seg=segtree(n+1);
	for(int i=0;i<q;i++)
	{
		int op,x,y;
		cin>>op>>x>>y;
		if(op==0)
		{
			seg.update(x,y);
		}else{
			cout<<seg.get(x,y)<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3884
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>

using namespace std;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<ll, ll> pll;

ll n = 0, m = 0, k = 0, ans = 0, sum = 0, cnt = 0, temp = 0;
string s;
bool flag;

//----------------------------------------------------------------------

#define MAX 1100

int main(void) {
  cin >> n;
  vs MM, AA, RR, CC, HH;

  FOR(i, 0, n) {
	cin >> s;
	if (s[0] == 'M') {
	  MM.push_back(s);
	}
	else if (s[0] == 'A') {
	  AA.push_back(s);
	}
	else if (s[0] == 'R') {
	  RR.push_back(s);
	}
	else if (s[0] == 'C') {
	  CC.push_back(s);
	}
	else if (s[0] == 'H') {
	  HH.push_back(s);
	}
  }

  ll m, a, r, c, h;
  m = MM.size();
  a = AA.size();
  r = RR.size();
  c = CC.size();
  h = HH.size();

  ans = m * r*a + m * a*c + m * a*h + m * r*c + m * r*h + m * c*h + a * r*c + a * r*h + a * c*h + r * c*h;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5748
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

int main() {
	int N;
	cin >> N;
	vector<int>X(N+1);
	vector<int>Y(N+1);
	X[0] = 0;
	Y[0] = 0;
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		X[i + 1] = X[i] + a;
	}
	for (int i = 0; i < N; ++i) {
		int b;
		cin >> b;
		Y[i + 1] = Y[i] + b;
	}
	int ans = 0;
	for (int i = 1; i <= N; ++i) {
		int sum = X[i] + Y[N] - Y[i - 1];
		ans = max(ans, sum);
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int n,m;
  cin>>n>>m;
  if(n<13) m/=2;
  if(n<6) m=0;
  cout<<m<<endl;
  return 0;
}





Measured memory_bytes: 256
// https://atcoder.jp/contests/abc127/tasks/abc127_b
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
    int current_algae, rate, bias;
    cin >> rate >> bias >> current_algae;
    for (int i = 0; i < 10; i++)
    {
        current_algae = rate * current_algae - bias;
        cout << current_algae << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
a = input()
strs = input()
temp = []
for char in strs:
    if char == 'E':
        temp.append(0)
    else:
        temp.append(1)

subsum1 = [0]
subsum2 = [0]
for num in temp[:-1]:
    subsum1.append(subsum1[-1]+num)
for num in temp[:0:-1]:
    subsum2.append(subsum2[-1]+num)
subsum2 = subsum2[::-1]

minturn = sys.maxsize
for i in range(len(temp)):
    minturn = min(minturn, subsum1[i]-subsum2[i]+len(temp)-1-i)

print(minturn)

Measured memory_bytes: 33192
#include <bits/stdc++.h>
using namespace std;
int n;
pair<int,int>arr[109];
long long  dp[155][100009];
bool st(pair<int,int>a,pair<int,int>b)
{
    return ((double)a.first/a.second)<((double)b.first/b.second);
}
int main()
{
    int w;
    cin>>n>>w;
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i].first>>arr[i].second;
    }
    memset(dp,-1,sizeof(dp));
    dp[0][0]=0;
   for (int i=1;i<=n;i++)
   {
       for (int j=0;j<=w;j++)
       {
            if (dp[i-1][j]==-1) continue;
            if (j+arr[i].first<=w) dp[i][j+arr[i].first]=max(dp[i][j+arr[i].first],dp[i-1][j]+arr[i].second);
            dp[i][j]=max(dp[i][j],dp[i-1][j]);

       }
   }
   long long ans=0;
   for (int i=0;i<=w;i++) ans=max(ans,dp[n][i]);
   cout<<ans;
}


Measured memory_bytes: 121344
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int main()
{
	int n;
	char s[110];
	scanf("%d\n", &n);
	scanf("%s\n", s);
	int szS = strlen(s);
	
	int p = 0;
	while (p < n) {
		printf("%c", s[p]);
		p++;
		if (p >= szS)
			break;
	}
	
	if (n < szS) {
		printf("...\n");
	}
	
	
	return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        //List<int> values = new List<int>(Console.ReadLine().Split(' ').Select(s => int.Parse(s)));
        //List<int> values = new List<int>();

        string input = Console.ReadLine();
        int n = int.Parse(input.Split(' ')[0]);
        int m = int.Parse(input.Split(' ')[1])-1;
        int k = int.Parse(input.Split(' ')[2])-1;

        List<string> ss = new List<string>();
        int a = 0;

        for (int i = 0; i < n; i++)
        {
            ss.Add(Console.ReadLine());
        }
        for (int i = 0; i < n; i++)
        {
            if (int.Parse(ss[i].Split(' ')[0]) > m)
            {
                if (int.Parse(ss[i].Split(' ')[1]) > k)
                {
                    a++;
                }
            }

        }



        Console.WriteLine(a); return;



    }
}

Measured memory_bytes: 13248
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define pi 3.14159265358979323846
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

int main()
{

  int a,b,c; cin >> a >> b >> c;
  cout << min(b/a,c) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int N, K;
    cin >> N >> K;

    int now = 1;
    while(N>0) {
        now = min(now*2, now+K);
        N--;
    }

    cout << now << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

i64 a,b,k;

int main() {
  cin >> a >> b >> k;
  int c = 0;
  for(int i = a;i >= 1;i--) {
    if(a % i == 0 && b % i == 0) {
      c++;
      if(k == c) {
        cout << i << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define FOR(i,x,y) for(int i = x; i <= y; ++i)
#define rFOR(i,x,y) for(int i = x; i >= y; --i)
#define MS(a,x) memset(a,x,sizeof a)
#define pb push_back

using namespace std;

string str;

int main()
{
    cin >> str;
    int ck = str.find("YAKI");
    if(ck == -1 || ck > 0) printf("No\n");
    else printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define pb push_back
#define fi first
#define se second
 
const ll MOD = 1000000007;
const string RGB = "RGB"; 

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

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

using namespace std;

int main(){
  int N,X;
  cin >> N >> X;
  int L[N];

  for(int i = 0; i < N; i++){
    cin >> L[i];
  }

  int d[N + 1] = {0};
  int count = 1;
  for(int i = 1; i <= N; i++){
    d[i] = d[i - 1] + L[i - 1];
    if(d[i] > X){ break; }
    else count++;
  }

  cout << count;
}





Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
const long long INF = 1e15;
using namespace std;
long long a,ans;
int main()
{
    scanf("%lld",&a);
    ans = INF;
    for (long long i = 1;i * i <= a;i++)
        if (a % i == 0)
            ans = min(ans,a / i + i - 2);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
// mai iss duniyaa ka sbse bada chutiyaaa huu

#include<bits/stdc++.h> 
#include <chrono> 
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#define mod 1000000007
#define mod2 998244353
#define int long long
#define endl '\n'
#define p_b push_back
#define m_p make_pair
#define fastIO ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
using namespace __gnu_pbds;
using namespace std::chrono; 

template <class T> 
using _ost = tree<
		T, 
		null_type, 
		less_equal<T>, 
		rb_tree_tag, 
        tree_order_statistics_node_update>;

char alphabet[26] = {'a','b','c','d','e','f','g','h','i',
       'j','k','l','m','n','o','p','q','r','s','t','u','v',
       'w','x','y','z'};

// rectangle intersection
// x5 = max(x1, x3);
// y5 = max(y1, y3);
// x6 = min(x2, x4);
// y6 = min(y2, y4); 

const int mx = 500005;

// char get_next(char c) {
// 	for(int i=0; i<25; i++) if(c == alphabet[i]) return alphabet[i+1];
// 	return 'a';
// }

// struct no {
// 	int l, r, id;
// }q[mx];

// int bl[mx];
// int col[mx];
// int mp[mx];

// void get_blocks(int n) {
// 	int sqroot = sqrt(n)+1;
// 	for(int i=0; i<=n; i++) bl[i] = i/sqroot;
// }
// bool mo_sort(no a, no b) {
// 	return bl[a.l] == bl[b.l] ? a.r < b.r : bl[a.l] < bl[b.l];
// }
// int diff = 0;
// void add(int id) {
// 	if(!mp[col[id]]) diff++;
// 	mp[col[id]]++;
// }
// void rem(int id) {
// 	mp[col[id]]--;
// 	if(mp[col[id]] == 0) diff--;
// }
int32_t main() {
 	fastIO;
	int tc;
	// cin >> tc;
	tc = 1;
	while(tc --) {
		int k;
		cin >> k;
		k /= __gcd(k, 1LL*7);
		int cur = 1;
		int i;
		for(i=1; i<=1000005; i++) {
			if(cur % k == 0) break;
			cur = cur * 10 + 1;
			cur %= k;
		}
		if(i > 1000000) cout << -1 << endl;
		else cout << i << endl;
  	}     
}



Measured memory_bytes: 3616
//提出時は下二行と一番下のコメントアウトを外す。
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

/// 空白で区切られた複数の値の読み込む。
/// # Example
/// ```ignore
/// use cp_template::*;
///
/// let (a,b):(usize,usize);
/// input!(a,b);
/// ```
#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

/// 文字列を一行読み込む
/// # Example
/// ```ignore
/// use cp_template::*;
///
/// let s = input_line_str();
/// ```
#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

/// 一つの変数を出力する。
/// ```
/// use cp_template::*;
///
/// let a=100;
/// p(a);
/// //上と下は等価です。
/// println!("{}",a);
/// ```
#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

/// 指定した行数を読み込み、二次元配列に変換する。
/// # Examples
/// ```ignore
/// use cp_template::*;
///
/// //10行読み込む。
/// let v = input_vector2d::<usize>(10);
/// ```
#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

/// 一行読み込み、配列(Vec)に変換する。
/// # Examples
/// ```ignore
/// use cp_template::*;
///
/// let v=input_vector::<usize>();
/// ```
#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

/// String(str)を配列(Vec<char>)に変換する。
/// # Examples
/// ```ignore
/// use cp_template::*;
///
/// let s = String::from("abc");
/// let v = str2vec(&s);
/// let v = str2vec(&input_line_str());
/// ```
#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}

}

#[allow(unused_imports)]
use input::*;

fn main() {
    let m: usize;
    input!(m);
    p(24 - m + 24);
}


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

using namespace std;

typedef long long ll;

ll n,s;
ll ans = 1e14;

ll f(ll b, ll n) {

  if(n < b) return n;
  return f(b,n / b) + (n % b);
}


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

  if(n == s) {
    cout << n + 1 <<endl; return 0;
  }
  for(ll i = 2; i * i <= n; i++) {
    ll tmp = f(i,n);
    // cout << tmp <<endl;
    if(tmp == s) {
      cout << i << endl;
      return 0;
    }
  }

  for(ll i = 1; i * i <= n; i++) {
    ll b = (n-s) / i + 1;
    if(b < 2) continue;
    if(f(b,n) == s) ans = min(ans,b);
 
  }
  if(ans == 1e14) cout <<"-1"<<endl;
  else cout << ans <<endl;
}
  

  
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int, int>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) FOR(i, 0, n)
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define FILLINF(a) memset(a, 0x3f, sizeof(a))
#define POW(n) (1LL << (n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i, a, b) ((a) <= (i) && (i) <= (b))
using namespace std;
template <typename T> inline bool CHMIN(T& a, T b) { if(a > b) { a = b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a, T b) { if(a < b) { a = b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(begin(a), end(a)); }
template <typename T> inline void REV(T& a) { reverse(begin(a), end(a)); }
template <typename T> inline void UNI(T& a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }
template <typename S, typename T> inline T LB(S& v, T a) { return *lower_bound(begin(v), end(v), a); }
template <typename S, typename T> inline int LBP(S& v, T a) { return lower_bound(begin(v), end(v), a) - begin(v); }
template <typename S, typename T> inline T UB(S& v, T a) { return *upper_bound(begin(v), end(v), a); }
template <typename S, typename T> inline int UBP(S& v, T a) { return upper_bound(begin(v), end(v), a) - begin(v); }
template <typename S, typename T> ostream& operator << (ostream& os, const pair<S, T>& p) { os << p.first << " " << p.second; return os; }
template <typename S, typename T> istream& operator >> (istream& is, pair<S, T>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator << (ostream& os, const vector<T>& v) { for (int i = 0; i < v.size(); ++i) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator >> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) { for(auto &e : t) fill_v(e, v); }
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const lint MOD = 1000000007;

void _main() {
    int A, B;
    cin >> A >> B;
    cout << A * B << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second

const int mod = 1e9+7;

int Pow(int a, int b)
{
	int x = 1;
	for (; b > 0; b >>= 1)
	{
		if (b&1) x = (ll)x * a % mod;
		a = (ll)a * a % mod;
	}
	return x;
}

int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int r1, c1, r2, c2;
	cin >> r1 >> c1 >> r2 >> c2;

	const int N = 2e6+5;
	vector<int> fac(N), ifac(N);
	fac[0] = ifac[0] = 1;
	for (int i = 1; i < N; ++i)
	{
		fac[i] = (ll)fac[i-1] * i % mod;
		ifac[i] = Pow(fac[i], mod-2);
	}

	auto comb = [&](int n, int k)
	{
		return (ll)fac[n] * ifac[n-k] % mod * ifac[k] % mod;
	};

	int ans = 0;
	for (int i = r1; i <= r2; ++i)
	{
		ans = (ans + comb(i + c2 + 1, c2)) % mod;
		ans = (ans + mod - comb(i + c1, c1 - 1)) % mod;
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
map<long long,long long> dp;
long long n;
long long dfs(long long x){
	if(dp[x])return dp[x];
	else{
		return dp[x]=(dfs(x/2)%mod+dfs((x-1)/2)%mod+dfs((x-2)/2)%mod)%mod;
	}
}
int main(){
	cin>>n;
	dp[0]=1;
	dp[1]=2;
	cout<<dfs(n);
	return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A + B < C + D){
    cout << "Right" <<endl;
  }
  
  else if (A + B > C + D){
    cout << "Left" <<endl;
  }
  
  else {
    cout << "Balanced" <<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N[9]; int d[6];
  bool a = false; bool b = false;
  for(int i=0;i<9;++i) {
    cin >> N[i];
  }
  d[0] = N[1] - N[0];
  d[1] = N[2] - N[1];
  d[2] = N[4] - N[3];
  d[3] = N[5] - N[4];
  d[4] = N[7] - N[6];
  d[5] = N[8] - N[7];
  if(d[0] == d[2] && d[2] == d[4]) a = true;
  if(d[1] == d[3] && d[3] == d[5]) b = true;
  if(a == true && b == true) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define  pb(x) push_back(x)
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define mod 1000000007
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
int main()
{
	sync;
	string s;
	cin>>s;
	ll ans=s.length();
	for(ll i=1;i<s.length();i++)
	{
		if(s[i]==s[i-1])
		{
			ans--;
			i+=2;
		}
	}
	cout<<ans;
}

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

int main(int argc, char const *argv[])
{
	int health, sumDamage, count;
	sumDamage = 0;
	cin >> health >> count;
	int currentDamage;
	for (int i = 0; i < count; ++i)
	{
		cin >> currentDamage;
		sumDamage += currentDamage;
	}
	if (sumDamage >= health) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    int N;ll A,B;cin>>N>>A>>B;
    ll X[100010],dX[100010];
    cin>>X[0];
    for(int i=1;i<N;i++){
        cin>>X[i];
        dX[i]=X[i]-X[i-1];
    }
    ll ans=0;
    for(int i=1;i<N;i++)
       ans+=min(B,A*dX[i]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
n, a, b= map(int, input().split())
ALlsum = 0

for i in range(1, n+1):
    sum = 0
    i = str(i)
    i_len = len(i)
    for j in range(i_len):
        sum += int(i[j])
    if a<=sum and sum<=b :
        ALlsum += int(i)


print(ALlsum)

Measured memory_bytes: 3060
package main

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

func main() {
	N, W := ReadInt(), ReadInt()
	v := make([]int, N)
	w := make([]int, N)
	for i := 0; i < N; i++ {
		v[i], w[i] = ReadInt(), ReadInt()
	}
	fmt.Println(KnapsackForSmallN(N, W, v, w))
}

// 01ナップサック問題 (重さと価値が大きく、Nが小さい場合) O(n * 2^(n/2)), Memory:O(2^(n/2))
func KnapsackForSmallN(N, W int, v, w []int) int {
	type Item struct {
		w, v int
	}
	// 半分列挙
	n := uint(N / 2)
	half := make([]*Item, 0)
	for S := 0; S < 1<<n; S++ {
		sumW, sumV := 0, 0
		for i := uint(0); i < n; i++ {
			if S>>i&1 == 1 {
				sumW += w[i]
				sumV += v[i]
			}
		}
		if sumW > W {
			continue
		}
		half = append(half, &Item{
			w: sumW,
			v: sumV,
		})
	}
	sort.Slice(half, func(i, j int) bool {
		return half[i].w < half[j].w
	})
	for i := 0; i < len(half)-1; i++ {
		if half[i].v >= half[i+1].v {
			half[i+1].v = half[i].v
		}
	}

	// rest
	v, w = v[n:], w[n:]
	n = uint(len(v))
	ans := 0
	for S := 0; S < 1<<n; S++ {
		sumW, sumV := 0, 0
		for i := uint(0); i < n; i++ {
			if S>>i&1 == 1 {
				sumW += w[i]
				sumV += v[i]
			}
		}
		if sumW > W {
			continue
		}
		i := sort.Search(len(half), func(i int) bool {
			return sumW+half[i].w > W
		})
		ans = Max(ans, sumV+half[i-1].v)
	}
	return ans
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }



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

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};


const int MOD = 1000000007;
using mint = Fp<MOD>;

int main(void)
{
    int S;

    cin >> S;

    vector<mint> ans(2000+1, 0);
    ans[3] = 1;

    for(int i = 4; i <= S; ++i)
    {
        ans[i] = 1;
        for(int j = 0; j <= i-3; ++j)
        {
            ans[i] += ans[j];
        }
    }

    cout << ans[S] << endl;

    return 0;
}



Measured memory_bytes: 3640
#include <iostream>

using namespace std;


#define MAX 500000
#define SENTINEL 2000000000

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

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

void mergeSort(int A[],int n,int left,int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int main(void) {
  int A[MAX], n, i;
  cnt = 0;

	cin >> n;
  for(i=0;i<n;i++) cin >> A[i];

  mergeSort(A, n, 0, n);
  for(i=0;i<n;i++) {
    if(i)cout << " ";
  	cout << A[i];
  }
  cout << endl;

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 6976
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n,ans=0,tmp=1;
    scanf("%lld",&n);
    while(n)
    {
        ans+=tmp;
        n/=2;
        tmp*=2;
    }
    printf("%lld",ans);
    return 0;
}

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

int H, W, A, B;

int main() {
    cin >> H >> W >> A >> B;

    int S[H][W];
    pair<int, int> ver[W];
    for (int i = 0; i < W; i++) ver[i] = make_pair(0, 0);

    for (int i = 0; i < H; i++) {
        pair<int, int> zo = make_pair(0, 0);
        for (int j = 0; j < W; j++) {
            if (zo.first >= A && ver[j].first >= B) {
                S[i][j] = 1;
                zo.second++;
                ver[j].second++;
            }
            else if (zo.second >= A && ver[j].second >= B) {
                S[i][j] = 0;
                zo.first++;
                ver[j].first++;
            }
            else if (zo.first >= A || ver[j].first >= B) {
                S[i][j] = 1;
                zo.second++;
                ver[j].second++;
            }
            else if (zo.second >= A || ver[j].second >= B) {
                S[i][j] = 0;
                zo.first++;
                ver[j].first++;
            }
            else {
                S[i][j] = 1;
                zo.second++;
                ver[j].second++;
            }
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cout << S[i][j];
        }
        cout << endl;
    }


    return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define per(i,a,b) for(int i=(b),i##_end=(a);i>=i##_end;--i)
#define For(i,a,b) for(int i=(a),i##_end=(b);i<i##_end;++i)
#define foe(i,a) for(__typeof(a.begin())i=a.begin();i!=a.end();++i)
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef double ld;
typedef long long L;
typedef vector<int> VI;
typedef pair<int,int> pa;
#ifdef flukehn
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
const int N=1e5+11;
vector<int> g[N];
int Eu[N],Ev[N];
int n,m,d[N],fa[N],dep[N],st[N],cnt;
void dfs(int x){
	st[x]=++cnt;
	for(int y:g[x]){
		if(!fa[y]){
			fa[y]=x;
			dep[y]=dep[x]+1;
			dfs(y);
		}
	}
}
set<L> s;
void add(L x){
	if(s.count(x))s.erase(x);
	else s.insert(x);
}
void gao(int x,int y){
	if(dep[x]<dep[y]) swap(x,y);
	for(;dep[x]>dep[y];x=fa[x]){
		add(1ll*N*x+fa[x]);
		add(1ll*N*fa[x]+x);
	}
	for(;x^y;x=fa[x],y=fa[y]){
		add(1ll*N*x+fa[x]);
		add(1ll*N*fa[x]+x);
		add(1ll*N*y+fa[y]);
		add(1ll*N*fa[y]+y);
	}
}
int p[N],t;
int main(){
#ifdef flukehn
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
#endif
	cin>>n>>m;
	int x,y;
	rep(i,1,m){
		cin>>x>>y;
		Eu[i]=x;
		Ev[i]=y;
		++d[x];
		g[x].pb(y);
		g[y].pb(x);
	}
	rep(i,1,n)if(d[i]%2) p[++t]=i;
	if(t%2){
		puts("-1");
		return 0;
	}
	dfs(1);
	sort(p+1,p+t+1,[&](int i,int j){
		return st[i]<st[j];
	});
	for(int i=1;i<=t;i+=2){
		gao(p[i],p[i+1]);
	}
	rep(i,1,m){
		if(s.count(1ll*N*Eu[i]+Ev[i])){
			s.erase(1ll*N*Eu[i]+Ev[i]);
			s.erase(1ll*N*Ev[i]+Eu[i]);
			swap(Eu[i],Ev[i]);
		}
		//swap(Eu[i],Ev[i]);
		printf("%d %d\n",Eu[i],Ev[i]);
	}
}
	

Measured memory_bytes: 18816