akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

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

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int N, M;
        cin >> N >> M;
        vector<int> A(N), B(M);
        vector<int> col(N * M, -1), row(N * M, -1);

        rep(i, 0, N) {
            cin >> A[i];
            A[i]--;
            col[A[i]] = i;
        }

        rep(i, 0, M) {
            cin >> B[i];
            B[i]--;
            row[B[i]] = i;
        }

        ll ans = 1ll;

        ll c = 0, r = 0; //最大値が置かれている縦と横の数
        for (int i = N * M - 1, t = 0; i >= 0; --i, t++) {
            //tは盤面に埋まったマス
            int cnt = 0;
            if (col[i] != -1) cnt++;
            if (row[i] != -1) cnt++;

            if (cnt == 2) {
                c++;
                r++;
            } else if (cnt == 1) {
                if (col[i] != -1) {
                    c++;
                    ll tmp = r;
                    if (tmp < 0)
                        tmp = 0;
                    ans *= tmp;
                    ans %= MOD;
                } else {
                    r++;
                    ll tmp = c;
                    if (tmp < 0)
                        tmp = 0;
                    ans *= tmp;
                    ans %= MOD;
                }
            } else {
                ll tmp = c * r - t;
                if (tmp < 0)
                    tmp = 0;
                tmp %= MOD;
                ans *= tmp;
                ans %= MOD;

            }
        }
        cout << ans << endl;
    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 8064
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

int main() {
	ll a,b,c;
	cin>>a>>b>>c;
	if(a+b>=c){
		cout << b+c << endl;
	}
	else{
		cout << a+2*b+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.0000000001
#define pi acosl(-1)
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
ll ans[200009];
void solve()
{
    ll n,k,c;
    cin>>n>>k>>c;
    string s;
    cin>>s;
    s='*'+s;
    ll pre[n+(2*c)+22]={0};ll post[n+(2*c)+22]={0};
    for(ll i=1+c;i<=n+c;i++)
    {
        if(s[i-c]=='o')
        {
            pre[i]=1;
            i+=c;
        }
    }
    for(ll i=1+c;i<=n+c;i++)
    {
        pre[i]+=pre[i-1];
    }
    for(ll i=n+c;i>0+c;i--)
    {
        if(s[i-c]=='o')
        {
            post[i]=1;
            i-=c;
        }
    }
    for(ll i=n-1+c;i>0+c;i--)
    {
        post[i]+=post[i+1];
    }
    vll ans;
    for(ll i=1+c;i<=n+c;i++)
    {
        if(s[i-c]=='o')
        {
            ll x=pre[i-1]+post[i+1];
            if(x<k)
                ans.pb(i-c);
        }
    }
    for(auto i:ans)
        cout<<i<<endl;
}
int main()
{
    FAST
    #ifdef ayk_16
    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    #endif
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++)
    {
        //cout<<"Case #"<<i+1<<": ";
        solve();
    }
}

Measured memory_bytes: 6856
#include<cstdio>
#include<iostream>
#include<algorithm> 
using namespace std;
typedef long long ll;
const int MAXN = 1010;
const int MAXM = 10010;
const int MAXS = 10010;
int n;
struct node{
	int v, s, w;
}a[MAXN];
ll f[MAXM+MAXS];
inline bool cmp(node x, node y){return x.w+x.s<y.w+y.s;}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d%d",&a[i].w,&a[i].s,&a[i].v);
	sort(a+1, a+n+1, cmp);
	for(int i=1;i<=n;i++)
		for(int j=a[i].s+a[i].w;j>=a[i].w;j--)
			f[j] = max(f[j], f[j-a[i].w]+a[i].v);
	ll ans = 0;
	for(int i=1;i<=20000;i++)
		ans = max(ans, f[i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

//# include <ext/pb_ds/assoc_container.hpp>
//# include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;
using namespace std;
 
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;
//	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//	shuffle(permutation.begin(), permutation.end(), rng);



int main () {
	SpeedForce;

	cin >> n >> m;
	For (i, 1, n) cin >> a[i];
	ll sum = accumulate(a + 1, a + n + 1, 0ll);

	int cnt = 0;
	for (int i = 1; i <= n; ++i) {
		if (a[i] * (ll)4 * (ll)m >= sum) {
			++cnt;
		}
	}
	if(cnt >= m) puts("Yes");
	else puts("No");

	return Accepted;
}

// B...a

Measured memory_bytes: 18688
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,  ans=0;
  cin >> N;

  for(int i=1;i<=N;i++){
    int a, j, x=0;
    cin >> a;
    for(j=0;x==0;j++){
       x=a%2;
      if(x==1) break;
       a/=2;
    }
    if(i==1) ans=j;
    else{
      if(ans>j){
        ans=j;
        if(ans==0) break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(a, b) for (a = 0; a < b; a++) 

//要素が与えられ、Bの中に存在するかを返す
int Youso(int _a, vector<int> _B){
  
  int i;
  rep(i, _B.size()){
    
    if (_a == _B.at(i)) return 1;
  }
  return 0;
}
  
  

int main(){
  
  vector<vector<int>> A(3, vector<int>(3));
  vector<vector<int>> Bingo = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
  
  int a1, a2, a3, a4, a5, a6, a7, a8;
  int i, j;
  rep(i, 3){
    rep(j, 3){
      
      cin >> A.at(i).at(j);
    }
  }
  
  int N;
  cin >> N;
  
  vector<int> B(N);
  rep(i, N){
    
    cin >> B.at(i);
  }
  
  rep(i, 3){
    rep(j, 3){
      
      Bingo.at(i).at(j) = Youso(A.at(i).at(j), B);
    }
  }
 //cout << Bingo.at(0).at(0) << endl;
  
  a1 = Bingo.at(0).at(0) * Bingo.at(0).at(1) * Bingo.at(0).at(2);
  a2 = Bingo.at(1).at(0) * Bingo.at(1).at(1) * Bingo.at(1).at(2);
  a3 = Bingo.at(2).at(0) * Bingo.at(2).at(1) * Bingo.at(2).at(2);
  
  a4 = Bingo.at(0).at(0) * Bingo.at(1).at(0) * Bingo.at(2).at(0);
  a5 = Bingo.at(0).at(1) * Bingo.at(1).at(1) * Bingo.at(2).at(1);
  a6 = Bingo.at(0).at(2) * Bingo.at(1).at(2) * Bingo.at(2).at(2);
  
  a7 = Bingo.at(0).at(0) * Bingo.at(1).at(1) * Bingo.at(2).at(2);
  a8 = Bingo.at(2).at(0) * Bingo.at(1).at(1) * Bingo.at(0).at(2);
    
  if (a1 || a2 || a3 || a4 || a5 || a6 || a7 || a8) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}
  

Measured memory_bytes: 256
def main():
    H, W = (int(i) for i in input().split())
    c = [input() for j in range(H)]
    sh, sw = 0, 0
    gh, gw = H-1, W-1

    from collections import deque
    def bfs():
        que = deque()
        dist = [[-1]*W for i in range(H)]

        dist[sh][sw] = 0
        que.append((sh,sw))
        d = ((1,0),(0,1),(-1,0),(0,-1))
        while que:
            uy,ux = que.popleft()
            for dy, dx in d:
                next_y = uy + dy
                next_x = ux + dx
                if not(0 <= next_y < H and 0 <= next_x < W): continue
                if dist[next_y][next_x] != -1: continue
                if c[next_y][next_x] == '#': continue
                dist[next_y][next_x] = dist[uy][ux] + 1
                que.append((next_y, next_x))
                if next_y == gh and next_x == gw:
                    return dist[gh][gw]
        return -1

    white_cnt = -1
    for i in range(H):
        for j in range(W):
            if c[i][j] == '.': white_cnt += 1
    
    goal = bfs()
    print(white_cnt - goal if goal != -1 else -1)

if __name__ == '__main__':
    main()

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

typedef long long ll;
#define REP(i, n, m) for(int i = n; i < m; i++)
#define REPR(i, n, m) for(int i = n; i >= m; i--)
#define LREP(i, n, m) for(ll i = n; i < m; i++)
#define LREPR(i, n, m) for(ll i = n; i >= m; i--)

#define P pair<int, int >


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



//---functions---//
int gcd(int a, int b){
    if(a < b) swap(a, b);
    return b?gcd(b, a%b):a;
}

int s2i(string num){stringstream ss; ss << num << flush; int n; ss >> n; return n;}
string i2s(int n){stringstream ss; ss << n << flush; return ss.str();}

bool firstCompare(const P& firstElof, const P& secondElof){
    return firstElof.first < secondElof.first;
}
bool secondCompare(const P& firstElof, const P& secondElof){
    return firstElof.second < secondElof.second;
}
//---------------//
//-----class-----//
class UnionFind{
    public:
        vector<ll> par; //parents
        vector<ll> siz; // sizes of set
        vector<ll> rank; // rank of each element 
    UnionFind(ll n): par(n), siz(n, 1LL), rank(n){
        LREP(i, 0, n) par[i] = i;
    }
    //initialization
    /*
    void init(ll n){
        par.assign(n);
        siz.assign(n, 1LL);
        rank.assign(n);
        LREP(i, 0, n) par[i] = i;
    }
    */

    // find the root of x
    ll find(ll x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    //Unite two set including x or y
    void unite(ll x, ll y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(rank[x] < rank[y]){
            par[x] = y;
            siz[y] += siz[x];
        }else{
            par[y] = x;
            siz[x] += siz[y];
            if(rank[x] == rank[y]) rank[x]++;
        }
    }

    //Do x and y belong to the same set?
    bool issame(ll x, ll y){
        return find(x) == find(y);
    }

};

int N, K, Q;

int main(){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K >> Q;
    int points[N];
    REP(i, 0, N) points[i] = K - Q;

    REP(i, 0, Q){
        int A;
        cin >> A;
        --A;
        ++points[A]; 
    }
    REP(i, 0, N){
        if(points[i] > 0) cout << "Yes" << '\n';
        else cout << "No" << '\n';
    }
}


Measured memory_bytes: 1024
import java.util.Scanner;
 
class Main
{
   public static void main(String[] args)
   {
      Scanner stdIn = new Scanner(System.in);
      int a = stdIn.nextInt();
      int b = stdIn.nextInt();
      int c = a*b;
      int d = 2*(a+b);
      System.out.println( c + " " + d );
   }
}

Measured memory_bytes: 26176
#include <algorithm>
#include <cstdio>
#include <map>

using LL = long long;

const LL INF = 1000000000000000000LL;

int main()
{
    int n;
    scanf("%d", &n);
    LL result = 0;
    LL dp[2] = {0, -INF};
    for (int i = 0, a; i < n; ++ i) {
        scanf("%d", &a);
        if (a) {
            result += a - 1 >> 1;
            a = 2 - (a & 1);
        }
        if (a == 0) {
            dp[0] = std::max(dp[0], dp[1]);
            dp[1] = -INF;
        } else if (a == 1) {
            auto todo = std::max(dp[0], dp[1] + 1);
            dp[1] = std::max(dp[0], dp[1]);
            dp[0] = todo;
        } else {
            auto todo = std::max(dp[0], dp[1]) + 1;
            dp[1] = std::max(dp[0], dp[1] + 1);
            dp[0] = todo;
        }
    }
    printf("%lld\n", std::max(dp[0], dp[1]) + result);
}


Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>

using namespace std;
int main()
{
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (auto i = 0; i < n; i++) cin >> a[i];



  long long ret = 0;
  for(auto i = 0; i < n; i++) ret += a[i]-1;
  cout << ret << endl;
  return 0;
}


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

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

    bool isCode[1000] = {false};
    for(int i = 0; i < 1000; i++) {
        string code;
        if(i < 10) {
            code = "00" + to_string(i);
        } else if(i < 100) {
            code = "0" + to_string(i);
        } else {
            code = to_string(i);
        }
        for(int c0 = 0; c0 < s.length() - 2; c0++) {
            bool flag0 = false;
            if(s[c0] == code[0]) {
                flag0 = true;
                for(int c1 = c0 + 1; c1 < s.length() - 1; c1++) {
                    bool flag1 = false;
                    if(s[c1] == code[1]) {
                        flag1 = true;
                        for(int c2 = c1 + 1; c2 < s.length(); c2++) {
                            if(s[c2] == code[2]) {
                                isCode[atoi(code.c_str())] = true;
                                break;
                            }
                        }
                    }
                    if(flag1) break;
                }
            }
            if(flag0) break;
        }
    }

    int ans = 0;
    for(auto v : isCode) {
        if(v) ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#ABC67 C

n = int(input())
a = list(map(int,input().split()))

front = a[0]
back = sum(a[1:])
mi = abs(front - back)
for i in range(1,n-1):
    back -= a[i]
    front += a[i]
    mi = min(mi,abs(front-back))
print(mi)


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

int main(void) {
    ull x,y;
    cin >> x >> y;
    ull a=x;
    ull count=1;
    for(;(a*2)<=y;count++){
        a *=2;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
l,r,d=MI()
count=0
for i in range(l,r+1):
    if i%d==0:
        count+=1
print(count)

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

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

template<class T> inline bool chmin(T& a, T b){
    if(a > b){
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

int main(){

    string s;
    cin >> s;

    int ans = 0;
    for(int i = 0; i < 4; i++){
        if(s[i] == '+') ans++;
        else if(s[i] == '-') ans--;
    }
    cout << ans << endl;
    
    return 0;
}


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

fst_row = list(map(int, input().split(' ')))
snd_row = list(map(int, input().split(' ')))

bottom_sum = sum(snd_row)
opt_sum = fst_row[0] + bottom_sum
upper_sum = fst_row[0]

for i in range(1, N):
    upper_sum += fst_row[i]
    bottom_sum -= snd_row[i - 1]

    opt_sum = max(opt_sum, upper_sum + bottom_sum)

print(opt_sum)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll n, k, m;
map<vi, ll> dp[301];

void debug (vector<int> v) {
    rep(i,v.size()) cout << v[i] << " ";
    cout << endl;
}

int main() {
    cin >> n >> k >> m;
    dp[0][vi()] = 1;
    for (int i = 0; i < n; i++) {
        for (auto it = dp[i].begin(); it != dp[i].end(); it++) {
            vi vec = (*it).first;
            ll val = (*it).second;
            ll len = vec.size();
            //cout << i << ": ";
            //debug(vec);
            rep(_,len+1) {
                if (k >= n || vec.size() < k-1) {
                    vec.push_back(0);
                    rep(j,vec.size()) vec[j]++;
                    if (vec[0] <= k) {
                        dp[i+1][vec] = (dp[i+1][vec] + val) % m;
                    }
                    rep(j,vec.size()) vec[j]--;
                    vec.pop_back();
                }
                
                if (vec.size() > 0) {
                    vec.erase(vec.begin());
                    rep(j,vec.size()) vec[j]++;
                }
            }
        }
    }
    ll ans = 0;
    for (auto it = dp[n].begin(); it != dp[n].end(); it++) {
        ans = (ans + (*it).second) % m;
    }
    cout << ans << endl;
}



Measured memory_bytes: 8492
#include <stdio.h>  
#include <string.h>  
#include <stdlib.h>  
#include <iostream>  
#include <algorithm>  
#include <time.h>  
#include<cstdio>
#include<vector>
#include<functional>


using namespace std;

long long  a[200010];



int main() {
	int N;
	scanf("%lld", &N);
	long long sum=0;
	for (int i = 0; i < N; i++) {
		scanf("%lld", a + i);
		sum += a[i];
	}
	long long x=0, y=0,minx=3000000000;
	for (int i = 0; i < N-1; i++) {
		x += a[i];
		y = sum - x;
		long long t;
		t= max(x, y) - min(x, y);
		if (t < minx)minx = t;
	}
	printf("%lld", minx);

}

Measured memory_bytes: 1792
//最大公約数
tailrec fun gcd(a:Long, b:Long):Long = if(b==0L) a else gcd(b,a%b)

//最小公倍数
fun lcm(a:Long, b:Long):Long = a/gcd(a,b)*b

fun main(args: Array<String>) {
    val n=readLine()!!.toInt()
    val t=(1..n).map{ readLine()!!.toLong() }
    val v=t.fold(1L) { a, b -> lcm(a,b) }
    println(v)
}

Measured memory_bytes: 31928
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll max(ll a, ll b){
    return a > b? a : b;
}
int main()
{
    ll n, m, cnt = 0;;
    cin >> n >> m;
    ll l, r;
    ll a[100000 + 10] = {0};
    for(int i = 0; i < m; i++)
    {
        cin >> l >> r;
        a[l]++;
        a[r+1]--;
    }
    for(int i = 1; i < 1e5 + 10; i++)
        a[i] += a[i - 1];

    for(int i = 0; i < 1e5 + 10; i++)
        if(a[i] == m)
            cnt++;
    cout << cnt;
    return 0;
}

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

// See debug.cc for usage etc
#define DEBUG 0

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#if DEBUG
  #define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DCALL(func, ...)
#endif

ll MOD = 1e9 + 7;

// g = eGCD(a, b, s, t)  --->  sa + tb = g
constexpr ll eGCD(ll a, ll b, ll& s, ll& t) {
  if (a == 0) {
    s = 0;
    t = 1;
    return b;
  }
  ll u = 0;
  ll g = eGCD(b % a, a, t, u);
  s = u - (b / a) * t;
  return g;
}


struct Fp {
  ll val;

  Fp(ll t = 0) :
    val(t < 0 ? MOD + t % MOD : t >= MOD ? t % MOD : t) {}

  Fp& operator +=(const Fp& t) {
    val += t.val;
    if (val > MOD) val -= MOD;
    return *this;
  }

  Fp& operator -=(const Fp& t) {
    val -= t.val;
    if (val < 0) val += MOD;
    return *this;
  }

  Fp& operator *=(const Fp& t) {
    val = (val * t.val) % MOD;
    return *this;
  }

  Fp inv() const {
    if (val == 0) {
      cerr << "inv() is called for zero." << endl;
      exit(1);
    }
    ll u = 0;
    ll v = 0;
    eGCD(val, MOD, u, v);
    return Fp(u);
  }

  Fp& operator /=(const Fp& t) {
    return (*this) *= t.inv();
  }

  Fp operator +(const Fp& t) const { return Fp(val) += t; }
  Fp operator -(const Fp& t) const { return Fp(val) -= t; }
  Fp operator *(const Fp& t) const { return Fp(val) *= t; }
  Fp operator /(const Fp& t) const { return Fp(val) /= t; }
  Fp operator -() const { return Fp(-val); }

  bool operator ==(const Fp& t) const { return val == t.val; }
  bool operator !=(const Fp& t) const { return val != t.val; }
  
  operator ll() const { return val; }

};

string s;
vector<Fp> pow2(100010);

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif

  cin >> s;

  ll cnt = 0;
  for (ll i = 0; i < s.size(); i++) {
    if (s.at(i) == '1')  cnt++;
  }
  pow2.at(0) = Fp(1);
  for (ll i = 1; i <= cnt; i++) {
    pow2.at(i) = pow2.at(i-1) * Fp(2);
  }
  Fp ans = pow2.at(cnt);
  Fp pow3 = Fp(1);
  for (ll p = 0; p < s.size(); p++) {
    if (s.at(s.size() - 1 - p) == '1') {
      cnt--;
      ans += pow3 * pow2.at(cnt);
    }
    pow3 *= Fp(3);
  }
  cout << (ll)ans << endl;

  return 0;
}



Measured memory_bytes: 1280
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){
    for (int i=1;i<=5;i++){
      int a; cin>>a;
      if (a==0) {
        cout << i << endl;
        break;
      }
    }
}

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


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

int main() {
	int N, M;
	cin >> N >> M;
	int lmax = 0;
	int rmin = N;
	for (int i = 0; i < M; ++i) {
		int l, r;
		cin >> l >> r;
		lmax = l < lmax ? lmax : l;
		rmin = r < rmin ? r : rmin;
	}
	cout << max(rmin - lmax + 1, 0) << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace abc046_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int output = 3;
            if (x[0] == x[1] && x[1] == x[2])
            {
                output = 1;
            }
            else if (x[0] == x[1])
            {
                output--;
            }
            else if (x[1] == x[2])
            {
                output--;
            }
            else if (x[2] == x[0])
            {
                output--;
            }
            Console.WriteLine(output);
            Console.ReadLine();
        }
    }
}

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

int n, a, b, color[200005];
vector <int> v[200005], colorv[2];

int main(){
    cin >> n;
    for (int i = 1; i < n; i++){
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    queue <pair<int, int> > q;
    pair<int, int> now;
    q.push({1, 0});
    colorv[0].push_back(1);
    color[1] = 0;
    while (!q.empty()){
        now = q.front();
        q.pop();
        if (color[now.first] == 0){
            for (int i:v[now.first]){
                if (i == now.second) continue;
                color[i] = 1;
                colorv[1].push_back(i);
                q.push({i, now.first});
            }
        }
        else {
            for (int i:v[now.first]){
                if (i == now.second) continue;
                color[i] = 0;
                colorv[0].push_back(i);
                q.push({i, now.first});
            }
        }
    }
    int sz0 = colorv[0].size(), sz1 = colorv[1].size();
    if (sz0 <= n/3 || sz1 <= n/3){
        if (sz0 <= n/3){
            for (int i = 0; i < sz0; i++){
                color[colorv[0][i]] = (i+1) * 3;
            }
            for (int i = (n/3)-sz0-1; i >= 0; i--){
                color[colorv[1][i]] = (sz0+i+1) * 3;
            }
            int num = 1;
            for (int i = (n/3)-sz0; i < sz1; i++){
                if (num % 3 == 0) num++;
                color[colorv[1][i]] = num;
                num++;
            }
        }
        else{
            for (int i = 0; i < sz1; i++){
                color[colorv[1][i]] = (i+1) * 3;
            }
            for (int i = (n/3)-sz1-1; i >= 0; i--){
                color[colorv[0][i]] = (sz1+i+1) * 3;
            }
            int num = 1;
            for (int i = (n/3)-sz1; i < sz0; i++){
                if (num % 3 == 0) num++;
                color[colorv[0][i]] = num;
                num++;
            }
        }
    }
    else{
        int num = 0;
        int cnt1 = n/3, cnt2 = n/3, cnt3 = n/3;
        if (n % 3 == 2) cnt2++;
        if (n % 3 >= 1) cnt1++;
        for (int i = cnt1-1; i >= 0; i--){
            color[colorv[0][i]] = i * 3 + 1;
        }
        for (int i = cnt1; i < sz0; i++){
            color[colorv[0][i]] = cnt3 * 3;
            cnt3--;
        }
        for (int i = cnt2-1; i >= 0; i--){
            color[colorv[1][i]] = i * 3 + 2;
        }
        for (int i = cnt2; i < sz1; i++){
            color[colorv[1][i]] = cnt3 * 3;
            cnt3--;
        }
    }
    for (int i = 1; i <= n; i++){
        cout << color[i] << " ";
    }
    cout << "\n";
}


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

using namespace std;

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

const int N = 505;
int dp[N][N];

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	int n, m, q; cin >> n >> m >> q;

	REPU(i, 0, m) {
		int l, r; cin >> l >> r;
		dp[l][r]++;
	}
	REPU(d, 2, n + 1) REPU(i, 1, n - d + 2) {
		int j = i + d - 1;
		dp[i][j] += dp[i][j - 1] + dp[i + 1][j] - dp[i + 1][j - 1];
	}
	REPU(i, 0, q) {
		int l, r; cin >> l >> r;
		printf("%d\n", dp[l][r]);
	}

	return 0;
}


Measured memory_bytes: 1920
#define _USE_MATH_DEFINES
 
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
 
using namespace std;
 
typedef pair<long long int, long long int> P;
typedef pair<string, string> SS;
long long int INF = 1e18;
long long int MOD = 1000000007;
 
namespace std {
    template <>
    class hash<std::pair<string, string>> {
    public:
        size_t operator()(const std::pair<string, string>& x) const{
            return hash<string>()(x.first) ^ hash<string>()(x.second);
        }
    };
}
 
using namespace std;
 
int main(){
	
	int N;
	cin >> N;
	
	string str, str1, str2;
	cin >> str;
	
	str1 = str.substr(0, N);
	str2 = str.substr(N);
	
	map<SS, int> m1;
	
	for(int i = 0; i < (1 << N); i++){
		string s1 = "", s2 = "", hoge = " ";
		for(int j = 0; j < N; j++){
			hoge[0] = str1[j];
			if(i & (1 << j)){
				s1 = s1 + hoge;
			}else{
				s2 = hoge + s2;
			}
		}
		m1[SS(s1, s2)]++;
	}
	
	long long int ans = 0;
	
	for(int i = 0; i < (1 << N); i++){
		string s1 = "", s2 = "", hoge = " ";
		for(int j = 0; j < N; j++){
			hoge[0] = str2[j];
			if(i & (1 << j)){
				s1 = hoge + s1;
			}else{
				s2 = s2 + hoge;
			}
		}
		ans += m1[SS(s1, s2)];
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 84992
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <list>
#include <sstream>
#include <algorithm>
#include <stack>
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <cmath>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<int, int> vii;
typedef map<string, int> msi;
typedef set<int> si;

#define trvi(c, it) for (vi::iterator it = (c).begin(); it != (c).end(); ++it)
#define trvii(c, it) for (vii::iterator it = (c).begin(); it != (c).end(); ++it)
#define trmsi(c, it) for (msi::iterator it = (c).begin(); it != (c).end(); ++it)
#define trsi(c, it) for (si::iterator it = (c).begin(); it != (c).end(); ++it)


#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,n) for(int i=0;i<(n);++i)
#define fori(i,a,b) for(int i=(a);i<=(b);++i)
#define ford(i,a,b) for(int i=(a);i>=(b);--i)


int main()
{
	//#ifndef ONLINE_JUDGE
	//	freopen("input.txt","r", stdin);
	//	freopen("output.txt", "w", stdout);
	//#endif

    int x;
    cin>>x;

    int arr[1000000];
    rep(i, 1000000)
    {
        arr[i] = -1;
    }

    fori(i, 2, 1000000)
    {
        if(arr[i] == -1)
        {
            for(int j = 2*i; j < 1000000; j+=i)
            {
                arr[j] = 1;
            }
        }
    }
    fori(i, x, 1000000)
    {
        if(arr[i] == -1)
        {
            cout<<i;
            break;
        }
    }

 return 0;
}



Measured memory_bytes: 4096
import java.util.Arrays;
import java.util.Scanner;

/**
 * @author yoshizaki
 *
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        int flower = scanner.nextInt();
        int[] height = new int[flower];
        for(int i = 0; i < flower; i++) height[i] = scanner.nextInt();
        int count = 0;
        while(Arrays.stream(height).max().getAsInt() > 0) {
            boolean iscount = true;
            for(int i = 0; i < flower; i++) {
                if(iscount) {
                    if(height[i] == 0) continue;
                    count++;
                    height[i]--;
                    iscount = false;
                } else {
                    if(height[i] == 0) {
                        iscount = true;
                    } else {
                        height[i]--;
                    }
                }
            }
        }
        System.out.println(count);
    }
}


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

int main(){
  int N;
  vector<int> A(21), B(21), C(21);
  cin >> N;
  for (int i=0; i<N; i++) cin >> A[i];
  for (int i=0; i<N; i++) cin >> B[i];
  for (int i=0; i<N-1; i++) cin >> C[i];

  int ans = 0;
  for (int i=0; i<N-1; i++){
    ans += B[A[i]-1];
    if (A[i+1] == A[i]+1) ans += C[A[i]-1];
  }

  cout << ans + B[A[N-1]-1]<< endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
using namespace std;

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

double const pi=3.1415926535;

int printint(int n){
	cout<<n<<endl;
	return 0;
}

int prints(string s){
	cout<<s<<endl;
	return 0;
}

int main(){
	int n;
	cin>>n;
	int a[114514];
	rep(n)cin>>a[i];
	bool flag[114514];
	rep(n)flag[i]=false;
	int index=1;
	int ans=0;
	while(true){
		if(flag[index]==true){
			cout<<-1<<endl;
			return 0;
		}
		ans++;
		flag[index]=true;
		index=a[index];
		if(index==2){
			cout<<ans<<endl;
			return 0;
		}
	}
}

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

int N,X;
int a[2002];

int memo[2002][2002];
int mmm(int i, int n) {
  return (memo[i][n] = (
    n==1 ? a[i] : min(memo[(i+N-1)%N][n-1], a[i])
//    n==1 ? a[i] : min(memo[i][n-1], a[(i-n+1+N)%N])
  ));
}

signed main() {
  cin>>N>>X;
  for(int i=0;i<N;i++)cin>>a[i];
  int q=1LL<<60;
  for(int t=0;t<N;t++){
    int r=0;
    for(int i=0;i<N;i++){
      r+=mmm((N+i-t)%N, t+1);
    }
    q=min(q,r+X*t);
  }
  cout<<q<<endl;
}

Measured memory_bytes: 31488
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        int n = Integer.parseInt(bf.readLine());
        String s = bf.readLine();
        if(n >= 3200) out.println(s);
        else out.println("red");
        // StringTokenizer st = new StringTokenizer(bf.readLine());
        // int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());
        // int n = Integer.parseInt(st.nextToken());

        out.close(); System.exit(0);
    }
}


Measured memory_bytes: 22356
import java.util.*;

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

        int N = sc.nextInt();
        int[] A = new int[N];

        for(int i=0; i<N; i++){
            A[i] = sc.nextInt();
            if(A[i]%2==0 && A[i]%3!=0 && A[i]%5!=0){
                System.out.println("DENIED");
                break;
            }
            if(i==N-1){
                System.out.println("APPROVED");
            }
            
        }
        
    }
}

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

// 累積積でa^nを計算
ll modpow(ll a, ll n){
    ll res = 1;
    //n&1でnのLSBが1かどうか確認し、1ならその桁の重みの分だけresにaを掛ける。
    //そして1ループごとにnを右シフト(n >>= 1)してnのLSBを1つ左にずらしている。
    while(n>0){
        if(n&1) res = res*a; //nのLSBが1なら(e.g. 45&1 = 00101101 & 00000001のLSBは1)、その桁の重みの分のaをresに掛ける。
        a = a*a; //今注目しているnのLSBにおけるaの重みの更新
        n >>= 1; //右シフト
    }
    return res;
}

void solve(){
    ll H;
    cin >> H;
    ll sum = 0, n = 0;
    while(H>0){
        sum += modpow(2, n);
        n += 1;
        H = H/2;
    }

    cout << sum << endl;


}

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

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

p = list(map(int, input().split()))
q = list(map(int, input().split()))

a = [i+1 for i in range(n)]
cnt = 0
cp = 0
cq = 0
for x in itertools.permutations(a):
    cnt += 1
    if list(x) == p: cp = cnt
    if list(x) == q: cq = cnt
    if cq != 0 and cp !=0: break
print(abs(cp - cq))

Measured memory_bytes: 3064
#include<cstdio>
#define MAX 500000
#define SENTINEL 2000000000
int L[MAX/2+2],R[MAX/2+2];
int cnt = 0;
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;
    int j=0;
    for(int a = left; a<right; a++)
    {
        cnt++;
        if(L[i] <= R[j]){
            A[a] = L[i++];
        }
        else
            A[a] = 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()
{
    int A[MAX];
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
        scanf("%d",&A[i]);
    MergeSort(A,n,0,n);
    for(int i=0; i<n; i++)
    {
        if(i) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
    printf("%d\n",cnt);
}



Measured memory_bytes: 6460
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    sort(all(d));
    int len = d.size();

    int ans;
    if(len%2==0){
        ans = d[(len/2)] - d[(len/2)-1];
    }
    else{
        ans = d[(len/2)+1] - d[(len/2)];
    }
    cout << ans << endl;
}

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

int PointAdd(char machine,int r,int p,int s){
  if(machine=='r'){
    return p;
  }
  else if(machine=='p'){
    return s;
  }
  else if(machine=='s'){
    return r;
  }
}

int main(void){
  int n,k,r,s,p;
  char record[100000];
  char t[100000];
  long long int score=0;
  int i,j;

  scanf("%d%d%d%d%d%s",&n,&k,&r,&s,&p,t);
  for(i=0;i<k;i++){
    if(t[i]=='r'){
      record[i]='p';
      score=score+PointAdd(t[i],r,p,s);
    }
    else if(t[i]=='p'){
      record[i]='s';
      score=score+PointAdd(t[i],r,p,s);
    }
    else if(t[i]=='s'){
      record[i]='r';
      score=score+PointAdd(t[i],r,p,s);
    }

  }
  for(i=k;i<n;i++){
    if(t[i]=='r'&&record[i-k]!='p'){
      record[i]='p';
      score=score+PointAdd(t[i],r,p,s);
    }
    else if(t[i]=='p'&&record[i-k]!='s'){
      record[i]='s';
      score=score+PointAdd(t[i],r,p,s);
    }
    else if(t[i]=='s'&&record[i-k]!='r'){
      record[i]='r';
      score=score+PointAdd(t[i],r,p,s);
    }
    else{
      t[i]='e';
    }
  }
  printf("%lld",score);

  return 0;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> ab(N);
    rep(i, N) {
        cin >> ab[i].first >> ab[i].second;
    }

    sort(ab.begin(), ab.end(), [](const pair<int, int>& a, const pair<int, int>& b)  {
        if (a.second == b.second) {
            return a.first > b.first;
        }
        else return a.second < b.second;
    });

    ll tm = 0;
    bool ok = true;
    rep(i, N) {
        if (tm+ab[i].first <= ab[i].second) {
            tm += ab[i].first;
        }
        else {
            ok = false;
            break;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int NN = 2000 * 2001;
int main() {
	int n;
	scanf("%d", &n);
	bitset<NN> dp;
	dp[0] = 1;
	int sum = 0;
	for (int i = 0; i < n; ++ i) {
		int x;
		scanf("%d", &x);
		sum += x;
		dp |= dp << x;
	}
	for (int i = 0; i <= sum; ++ i) if (i >= sum - i && dp[i]) return 0 * printf("%d\n", i);
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
int mod = 1000000000+7;

int main(){

	int d;
	cin>>d;
	int c[26];
	rep(i,26)cin>>c[i];
	int lastd[26]={};
	int s[d][26];
	rep(i,d){
		rep(j,26)cin>>s[i][j];
	}

	ll ans=0,maxi=0,maxid=0;
	ll ans2=0;
	int t[d]={};
	rep(i,d){
		maxi=0;
		rep(j,26){
			ans=s[i][j];
			rep(k,26){
				if(k==j)continue;
				ans-=c[k]*(i+1-lastd[k]);
			}
			if(ans>maxi){
				maxi=ans;
				maxid=j;
			}
		}
		ans2+=maxi;
		lastd[maxid]=i+1;
		t[i]=maxid;
	}

	rep(i,d)cout<<t[i]+1<<endl;

	//cout<<"ss"<<ans2<<endl;

	return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>

using namespace std;

long long int A, a, n, m, y, s;
string str_1, str_2, str_3;


long long int gcd(int m, int n){
	while (true) {
		if (m%n == 0)return n;
		m %= n;
		if (n%m == 0)return m;
		n %= m;
	}
}



int main() {
	cin >> n >> m;
	cin >> str_1 >> str_2;

	y = gcd(n, m);

	for (int i = 0; i < y; i++) {
		if (str_1[i*n / y] != str_2[i*m / y]) {
			cout << -1 << '\n';
			return 0;
		}
	}
	cout << n * m / y << '\n';
	return 0;
}


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

int main() {
  int n,a,am;
  cin >> n >> a;
  
  am=n%500;

  if(am <= a){
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  
  return(0);
}


Measured memory_bytes: 3592
N = int(input())
T , A = (int(i) for i in input().split())
H_list = [int(h) for h in input().split()]
 
A_list = [abs((T-0.006*H_list[n])-A) for n in range(N)]
 
number = 0
for n ,x in enumerate(A_list):
    if x == min(A_list):
        number = n+1
print(number)

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

constexpr long long int M = 1000000007, m = 79133769, n = 536396504, mask = 1073741823;
 
inline constexpr long long int MR(long long int A){
    long long int ret = (A + M * (m * A & mask)) >> 30;
    return ret - (ret >= M) * M;
}

template<int N>
struct Fact{
  long long int val[N];
  long long int v2[N - 1];
  constexpr Fact() : val(), v2() {
    val[0] = 73741817;
    for(int i = 1; i < N; ++i)val[i] = val[i - 1] * i % M;
    for(int i = 1; i < N; ++i)v2[i] = val[i - 1] * val[i] % M * 73699066 % M;
  }
};

template<int N, long long F>
struct IFact{
  long long int val[N];
  constexpr IFact() : val() {
    val[N - 1] = F * 73741817 % M;
    for(int i = N - 1; i > 0; --i)val[i - 1] = val[i] * i % M;
  }
};

long long int N, ans;
constexpr auto fact = Fact<1000001>();
constexpr auto ifact = IFact<1000001, 397802501>();

int main(){
    scanf("%lld", &N);
    for(int i = N / 2; i < N - 1; ++i){
        ans += MR(fact.v2[i] * ifact.val[i * 2 - N]);
    }
    ans = fact.val[N] - fact.val[N - 1] - ans;
    ans %= M;
    cout << MR(ans > 0 ? ans : M + ans) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
inline int gi()
{
	char c;int num=0,flg=1;
	while((c=getchar())<'0'||c>'9')if(c=='-')flg=-1;
	while(c>='0'&&c<='9'){num=num*10+c-48;c=getchar();}
	return num*flg;
}
#define N 200005
#define LL long long
#define lc i<<1
#define rc i<<1|1
const LL INF=0x3f3f3f3f3f3f3f3fll;
int pos[N],A,B,n,Q;
struct node{
	int l,r;
	LL mi1,mi2,la;
}a[N<<2];
void cal(int i,LL k){a[i].mi1+=k;a[i].mi2+=k;a[i].la+=k;}
void pushdown(int i)
{
	if(a[i].la&&a[i].l<a[i].r){
		cal(lc,a[i].la);cal(rc,a[i].la);
		a[i].la=0;
	}
}
void pushup(int i)
{
	a[i].mi1=min(a[lc].mi1,a[rc].mi1);
	a[i].mi2=min(a[lc].mi2,a[rc].mi2);
}
void build(int i,int l,int r)
{
	a[i].l=l;a[i].r=r;
	if(l==r){
		a[i].mi1=INF;a[i].mi2=INF;
		return;
	}
	int mid=(l+r)>>1;
	build(lc,l,mid);build(rc,mid+1,r);
	pushup(i);
}
void insert(int i,int l,int r,LL k)
{
	if(a[i].l>r||a[i].r<l)return;
	pushdown(i);
	if(l<=a[i].l&&a[i].r<=r){cal(i,k);return;}
	insert(lc,l,r,k);insert(rc,l,r,k);
	pushup(i);
}
void modify(int i,int x,LL k)
{
	if(a[i].l>x||a[i].r<x)return;
	pushdown(i);
	if(x==a[i].l&&a[i].r==x){a[i].mi1=min(a[i].mi1,k-x);a[i].mi2=min(a[i].mi2,k+x);return;}
	modify(lc,x,k);modify(rc,x,k);
	pushup(i);
}
LL query1(int i,int l,int r)
{
	if(a[i].l>r||a[i].r<l)return INF;
	pushdown(i);
	if(l<=a[i].l&&a[i].r<=r)return a[i].mi1;
	return min(query1(lc,l,r),query1(rc,l,r));
}
LL query2(int i,int l,int r)
{
	if(a[i].l>r||a[i].r<l)return INF;
	pushdown(i);
	if(l<=a[i].l&&a[i].r<=r)return a[i].mi2;
	return min(query2(lc,l,r),query2(rc,l,r));
}
LL query(int i)
{
	if(a[i].l==a[i].r)return a[i].mi1+a[i].l;
	pushdown(i);
	return min(query(lc),query(rc));
}
int ab(int x){return x<0?-x:x;}
int main()
{
	int i;LL f;
	n=gi();Q=gi();A=gi();B=gi();
	build(1,1,n);
	pos[0]=A;modify(1,B,0);
	for(i=1;i<=Q;i++){
		pos[i]=gi();
		f=min(query1(1,1,pos[i])+pos[i],query2(1,pos[i]+1,n)-pos[i]);
		insert(1,1,n,ab(pos[i]-pos[i-1]));
		modify(1,pos[i-1],f);
	}
	printf("%lld\n",query(1));
}

Measured memory_bytes: 19456
#include<stdio.h>

int main(void)
{
    int a, b;
    while(1)
    {
        char buffer[256];
        fgets(buffer, 256, stdin);
        sscanf(buffer, "%d %d", &a, &b);
        if((-1000<a && a<1000) &&
        (-1000<b && b < 1000)) break;
    }
    if(a<b) printf("a < b\n");
    else if (a==b) printf("a == b\n");
    else if (a > b) printf("a > b\n");
    
    return(0);
}


Measured memory_bytes: 2040