akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
 
import java.io.*;
 
public class Main{
 
    public static long Combination(long n, long r){
        long A = 1;
        long B = 1;
        for(long i = 0; i < r; i++){
            A = A*(n-i);
            B = B*(r-i);
        }
        if(A == 0) return 0;
        return A/B;
    }
 
    public static long solve(int i, int j, boolean check, int N, String S){
        if(i == N){
            if(j == 0){
                return 1;
            }else{
                return 0;
            }
        }
 
        if(j == 0) return 1;
 
        if(check){
            return Combination(N-i, j)*(long)Math.pow(9, j);
        }else{
            if(S.charAt(i) == '0') return solve(i+1, j, false, N, S);
            long Z = solve(i+1, j, true, N, S);
            long A = solve(i+1, j-1, true, N, S)*(S.charAt(i)-'1');
            long P = solve(i+1, j-1, false, N, S);
            return Z+A+P;
        }
 
 
    }
    
    public static long Dflag(long a){
        if(a == 1) return 1;
        long h = Dflag(a/2);
        return h + h + 1;
    }
	public static void main(String[] $){
		Scanner s = new Scanner(System.in);
        int N = s.nextInt();
        int M = s.nextInt();
        int X = s.nextInt();

        int[] C = new int[N];
        int[][] A = new int[N][M];
        
        for(int i = 0; i < N; i++){
            C[i] = s.nextInt();
            for(int j = 0; j < M; j++){
                A[i][j] = s.nextInt();
            }
        }

        int min = Integer.MAX_VALUE;
        for(int i = 0; i < Math.pow(2, N); i++){
            String bin = Integer.toBinaryString(i);
            while(bin.length() != N){
                bin = "0" + bin;
            }
            boolean[] overX = new boolean[M];
            int yen = 0;
            int[] algorithm = new int[M];
            for(int j = 0; j < N; j++){
                if(bin.charAt(j) == '1'){
                    for(int k = 0; k < M; k++){
                        algorithm[k] = algorithm[k] + A[j][k];
                        if(X <= algorithm[k]) overX[k] = true;
                    }
                    yen += C[j];
                }
            }
            boolean result = false;
            for(int j = 0; j < M; j++){
                if(!overX[j]) result = true;
            }
            if(!result){
                if(min >= yen){
                    min = yen;
                }
            } 
        }
        if(min == Integer.MAX_VALUE){
            System.out.println("-1");
        }else{
            System.out.println(min);
        }
	}
} 

Measured memory_bytes: 41108
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vout(v) VOUT(v,z);
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL);
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}


void solve_WA(long long N, long long M, std::vector<long long> p, std::vector<std::string> S){
    ll cntwa=0, cntac=0;
    vector<bool> f(10e5+10, false);
    for (ll i = 0; i < M; i++) {
        ll idx = p[i];
        if(f[idx]==false && S[i]=="WA"){
            cntwa++;
        }else if(f[idx]==false && S[i]=="AC"){
            cntac++;
            f[idx]=true;
        }
    }
    cout << cntac << ' ' << cntwa << "\n";
}

void solve(long long N, long long M, std::vector<long long> p, std::vector<std::string> S){
    ll cntwa=0, cntac=0;
    vector<bool> f(10e5+10, false);
    vector<ll> cntwa_tmp(10e5+10, 0);
    for (ll i = 0; i < M; i++) {
        if(f[p[i]]==false){
            if(S[i]=="WA") cntwa_tmp[p[i]]++;
            if(S[i]=="AC") {
                cntac++;
                cntwa += cntwa_tmp[p[i]];
                cntwa_tmp[p[i]]=0;
                f[p[i]]=true;
            }
        }
    }
    cout << cntac << ' ' << cntwa << "\n";
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> p(M);
    std::vector<std::string> S(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&p[i]);
        std::cin >> S[i];
    }
    solve(N, M, std::move(p), std::move(S));
    return 0;
}


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

const int base = 300;
int dp[330][990], nxt[330][990];

int main(){
  int n,x,y;
  cin >> n >> x >> y;

  memset(dp, -1, sizeof(dp));
  dp[x][base+y] = 0;

  for(int i=0;i<n;i++){
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    memset(nxt, -1, sizeof(nxt));
    for(int j=0;j<=300;j++){
      for(int k=0;k<=900;k++){
	if(dp[j][k]<0)continue;

	nxt[j][k] = max(nxt[j][k], dp[j][k]);
	if(j-a>=0 && k+b<=900){
	  nxt[j-a][k+b] = max(nxt[j-a][k+b], dp[j][k]);
	}
	if(k-c>=0){
	  nxt[j][k-c] = max(nxt[j][k-c], dp[j][k]+d);
	}
      }
    }
    swap(dp, nxt);
  }

  int ans = 0;
  for(int j=0;j<=300;j++){
    for(int k=base;k<=900;k++){
      ans = max(ans,dp[j][k]);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 5668
def is_matched(i, inputS, T):
  for s,t in zip(inputS, T):
    if s == '?': continue
    if s != t: return False
  return True

S, T = input(), input()
lenS, lenT = len(S), len(T)
matched_i = None
for i in range(lenS-lenT+1):
  if is_matched(i, S[i:i+lenT], T):
    matched_i = i
if matched_i is None: print('UNRESTORABLE')
else: print(''.join([s for s in S[:matched_i] + T + S[matched_i+lenT:]]).replace('?', 'a'))


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

using namespace std;

int main()
{
    long long int a,b,k=0;
    cin>>a>>b;

    while(llabs(a-k)!=llabs(b-(k+1)))
    {
        if(llabs(a-k)==llabs(b-k))
        {
            break;
        }
        else
            k++;
    }

    if(llabs(a-k)==llabs(b-k))
    {
        cout<<k<<endl;
    }
    else
        cout<<"IMPOSSIBLE"<<endl;

    return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int 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; }
//https://www.creativ.xyz/dump-cpp-652/
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
 
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

#ifdef DEBUG_
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

signed main(void) { cin.tie(0); ios::sync_with_stdio(false);
    int n; cin>>n;
    priority_queue <pair<int,int>, vector <pair<int,int>>, greater <pair<int,int>>> pq;
    rep(i,n){
        int x,l; cin>>x>>l;
        pq.push({x+l, x-l});
    }
    int cnt = 0;
    int now = -INF;
    while(!pq.empty()){
        auto tmp = pq.top(); pq.pop();
        int r = tmp.F, l = tmp.S;
        if(now <= l){
            cnt++;
            now = r;
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 2420
from collections import Counter
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
n = int(input())
d = dict()
for i in range(2, n + 1):
    c = Counter(prime_factorize(i))
    for j in c:
        if not j in d.keys():
            d[j] = c[j]
        else:
            d[j] += c[j]
ans = 1
for i in d.values():
    ans *= i + 1
print(ans % (10 ** 9 + 7))

Measured memory_bytes: 3572
#include <cstdio>

int main() {
  for(;;) {
    int n; scanf("%d", &n);
    if(n==0) return 0;
    static int st[50010];
    int stlen = 0;
    auto st_ext = [&]() {
      if(stlen == 0) {
        st[stlen++] = 0;
        st[stlen++] = 0;
      }
    };
    for(int i = 0; i < n; ++i) {
      int x; scanf("%d", &x);
      if((stlen & 1) == x) {
        st_ext();
        ++st[stlen-1];
      } else if((i & 1) == 0) {
        st[stlen++] = 1;
      } else {
        st_ext();
        int y = st[--stlen];
        st_ext();
        st[stlen-1] += y + 1;
      }
    }
    int sum = 0;
    for(int i = 1; i < stlen; i += 2) {
      sum += st[i];
    }
    printf("%d\n", sum);
  }
}

Measured memory_bytes: 1012
#include <vector>
#include <iostream>
#include <cstdlib>
#include <string>

static const int INF = 1001001001;

using namespace std;

int main()
{
	int num_odd = 0;
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		if (a % 2 == 1) {
			num_odd++;
		}
	}
	if (num_odd % 2 == 0) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 1016
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL X, t;

int main()
{
	in>>X>>t;
	out<<std::max<LL>(0,X-t)<<std::endl;
	return 0;
}


Measured memory_bytes: 256
import Control.Monad

main :: IO ()
main = do
  n <- readLn
  if n == 0
    then return ()
    else do
      ls <- replicateM n getLine
      let ls' = map (map read . words) ls
      putStrLn (solve ls')
      main

solve :: [[Int]] -> String
solve ls = toStr (foldl1 comp (map toTuple ls))
  where
    toStr :: (Int,Int) -> String
    toStr (a,b) = (show a) ++ " " ++ (show b)

    comp :: (Int,Int) -> (Int,Int) -> (Int,Int)
    comp (a1,b1) (a2,b2)
      | b1 < b2 = (a2,b2)
      | otherwise = (a1,b1)
      
    toTuple :: [Int] -> (Int,Int)
    toTuple [p,d1,d2] = (p,d1+d2)

Measured memory_bytes: 14528
import java.io.*;
import java.util.*;
import java.util.stream.*;

class Main
{
    /**
     * ABC 062 B: Picture Frame
     *     (周囲1ピクセルを'#'で囲む)
     */ 
    public static void main(String[] args) throws IOException
    {
        // 入力
        BufferedReader br = new BufferedReader(
                new InputStreamReader(System.in));
        Stream<String> lines = br.lines();
        
        // データからパラメータを割り出す
        Stream<String> a = lines.filter(item -> item.indexOf(" ") < 0);

        // 変換処理、出力
        int W = 0;
        boolean isFirst = true;
        for (Object item : a.map(item -> "#" + item + "#").toArray()) {
            String out = item.toString();
            if (isFirst) {
                isFirst = false;
                W = out.length();
                System.out.println(new String(new char[W]).replace("\0", "#"));
            }
            System.out.println(out);
        }
        System.out.print(new String(new char[W]).replace("\0", "#"));
    }
}


Measured memory_bytes: 26452
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<set>
#include<fstream>
#include<map>
#include<string>
#include <stdio.h>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<climits>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll>vl;
typedef vector<int>vi;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef vector<char>vc;
typedef vector<string>vs;
#define MP make_pair
#define all(v) v.begin(),v.end()
const ll mod = 1000000007;
const ll OO = (ll)1e18;
const int dx[] = { 0, 1, -1, 0 };
const int dy[] = { 1, 0, 0, -1 };
ll gcd(ll a, ll b){ if (b == 0){ return a; }return gcd(b, a % b); }
ll fast_power(ll base, ll power){
	if (power == 1) return base;
	if (power % 2 == 0) return fast_power((base*base), power / 2);
	else return(base*fast_power((base*base), power / 2));
}
//#pragma warning (disable : 4996)
void Qalbaz()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	
}

int main(){
	//Qalbaz();
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	set<int>st;
	int n;
	cin >> n;
	while (n--)
	{
		int x;
		cin >> x;
		st.insert(x);
	}
	cout << st.size();
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MOD 1000000007

static int power(int x, int n) {
  long long res = 1;
  if (n > 0) {
    res = power(x, n/2);
    if (n % 2 == 0) res = (res * res) % MOD;
    else res = (((res * res) % MOD) * x) % MOD;
  }
  return (int)res;
}

/*
long pow2(long n)
{
  if (n == 0)
    return 1;
  else if (n % 2)
    return pow2(n-1) * 2 % MOD;
  else {
    long fact = pow2(n/2);
    return fact * fact % MOD;
  }
}
*/
int mbk(long long a,int n,int m){return n?(mbk((a*a)%m,n/2,m)*(n%2?a:1))%m:1;}

int inv(int a,int m){return mbk((long long)a,m-2,m);}

static int C(int n, int r, int p)
{
	long long ret = 1;
	while(1){
		if(r == 0)break;
		int N = n % p;
		int R = r % p;
		if(N < R)return 0;
 
		for(int i = 0;i < R;i++){
			ret = ret * (N-i) % p;
		}
		long imul = 1;
		for(int i = 0;i < R;i++){
			imul = imul * (i+1) % p;
		}
		ret = ret * inv(imul, p) % p;
		n /= p; r /= p;
	}
	return (int)ret;
}

int nCr(long n, long r)
{
  if (r == 0 || r == n)
    return 1;
  else
    return (int)(((long)nCr(n-1, r-1) + nCr(n-1, r)) % MOD);
}

int main(void)
{ 
  int n, a, b;
  
  scanf("%d %d %d", &n, &a, &b);
  
  printf("%d", ((long)power(2, n) + MOD * 2 - C(n, a, MOD) - C(n, b, MOD) - 1) % MOD);
  
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
//小さい順にソート
int c[100002];
void merge(int i,int j,int *s){
  if(i!=j){
    merge(i,(i+j)/2,s);
    merge((i+j)/2+1,j,s);
    int a=i,b=(i+j)/2+1;
    int d;
    for(d=i;d<=j;d++){
      if((i+j)/2<a){
        c[d]=s[b];
        b++;
      }
      else if(j<b){
        c[d]=s[a];
        a++;
      }
      else if(s[a]<s[b]){
        c[d]=s[a];
        a++;
      }
      else{
        c[d]=s[b];
        b++;
      }
    }
    for(d=i;d<=j;d++)
      s[d]=c[d];
  }
}

int main(){
  int n,i;
  scanf("%d",&n);
  int d[n+1];
  for(i=0;i<n;i++)
    scanf("%d",&d[i]);
  merge(0,n-1,d);
  printf("%d\n",d[n/2]-d[n/2-1]);
  return 0;
}


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

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

Measured memory_bytes: 3540
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE RecordWildCards       #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString.Char8       as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           Unsafe.Coerce

main :: IO ()
main = do
    [n,m,d] <- map read.words <$> getLine :: IO [Int]
    print $ solve n m d

solve :: Int -> Int -> Int -> Double
solve n m d
    | d == 0 = (dm - 1) / dn
    | otherwise = 2 * (dn - dd) * (dm - 1) / (dn * dn)
  where
    [dn, dm, dd] = map fromIntegral [n,m,d]



Measured memory_bytes: 508
n,m = map(int, input().split())
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

uf = UnionFind(n)

for i in range(m):
    a,b = map(int, input().split())
    a -=1
    b -=1
    uf.union(a,b)
    
res = [0]
for j in  uf.roots():
    res.append(uf.size(j))
print(max(res))

Measured memory_bytes: 19788
let rec for_fold a b f v = if a >= b then v else for_fold (a+1) b f (f v a)
let _ = Scanf.scanf "%d %d" @@ fun n k ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  let sa = Array.init (n+1) (fun i -> if i = 0 then 0 else a.(i-1)) in
  for i = 1 to n do sa.(i) <- sa.(i) + sa.(i-1) done;
  let sp = Array.make (n+1) 0 in
  for i = 1 to n do sp.(i) <- max 0 a.(i-1) + sp.(i-1) done;

  for_fold 0 (n-k+1) (fun s i ->
    max s @@ sp.(i) + max 0 (sa.(i+k) - sa.(i)) + sp.(n) - sp.(i+k)) 0
  |> Printf.printf "%d\n"


Measured memory_bytes: 6144
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main(){
	int n, m; cin >> n >> m;
	ll x[n], y[n], z[n], s[8][n], answer = 0;
	for(int i = 0; i < n; i++){
		cin >> x[i] >> y[i] >> z[i];
		s[0][i] = x[i] + y[i] + z[i];
		s[1][i] = x[i] + y[i] - z[i];
		s[2][i] = x[i] - y[i] + z[i];
		s[3][i] = x[i] - y[i] - z[i];
		s[4][i] = -x[i] + y[i] + z[i];
		s[5][i] = -x[i] + y[i] - z[i];
		s[6][i] = -x[i] - y[i] + z[i];
		s[7][i] = -x[i] - y[i] - z[i];
	}
	for(int i = 0; i < 8; i++){
		ll t[n], k = 0;
		for(int j = 0; j < n; j++){
			t[j] = s[i][j];
		}
		sort(t, t + n, greater<ll>() );
		for(int j = 0; j < m; j++){
			k += t[j];
		}
		answer = max(answer, k);
	}
	cout << answer << endl;
}

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

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = 1LL<<60;
const ll mod = 1000000007;
const int MAX_N = 5e5 + 5;
int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

template <class T = ll> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1; while (b > 0) { if (b & 1) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool A[n + 1]; for (int i = 0; i < n + 1; i++) { A[i] = 1; }for (int i = 2; i < n + 1; i++) { if (A[i]) { prime.pb(i); ll b = i; while (b <= n) { A[b] = 0; b += i; } } } }

vector<vector<pair<int,int>>> Edge;
vector<int> node;

bool bellman_ford(int n,int s) {
	node = vector<int>(n,INF);
	node[s] = 0;
	REP (i,n) {
		REP (j,Edge.size()) {
			REP (k,Edge[j].size()) {
				int from = j,to = Edge[j][k].F;
				int cost = Edge[j][k].S;
				if (node[from] != INF && node[to] > node[from] + cost) {
					node[to] = node[from] + cost;
					if (i == n - 1 && to == n - 1) return true;
				}
			}
		}
	}
	return false;
}

int dp[100000];
int dp2[100000];

signed main() {
	int h,w,a,b;
	cin >> h >> w >> a >> b;
	_nCr();
	int ans = nCr(h + w - 2,h - 1);
	int ng = 0;
	FOR (i,h + b - a - 1,h + b - 1) {
		ng += nCr(i,b - 1) * nCr(h + w - 3 - i,w - b - 1) % mod;
		ng %= mod;
	}
	cout << (ans + mod - ng) % mod << endl;
}


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

int main(){
  int n;cin >> n;
  v p(n);
  rep(i,n)cin>>p[i];
  int ans = 0;
  
  for(int i=1; i<=n-2; i++){
    if(p[i-1]<p[i] && p[i]<p[i+1])ans++;
    if(p[i-1]>p[i] && p[i]>p[i+1])ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import re
a = [input() for i in range(2)]
length, string = int(a[0]), a[1]
pattern = string[0:int(length/2)]
cond1 = len(string) == length and len(string)%2==0
cond2 = re.match(r"^[a-z]+$", string)
cond3 = len(re.findall(pattern, string)) == 2
if cond1 and cond2 and cond3:
  print("Yes")
else:
  print('No')

Measured memory_bytes: 3316
def main():
    x, y, a, b, c = map(int, input().split(" "))
    ps = sorted(list(map(int, input().split(" "))), reverse=True)
    qs = sorted(list(map(int, input().split(" "))), reverse=True)
    rs = sorted(list(map(int, input().split(" "))), reverse=True)

    red_eat = ps[:x]
    blue_eat = qs[:y]

    eats = sorted(red_eat + blue_eat + rs, reverse=True)
    have = eats[:(x+y)]
    points = sum(have)
    print(points)



if __name__ == '__main__':
    main()


Measured memory_bytes: 23600
import java.util.*;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int price1;
        int price2;
        if (X > Y) {
            price1 = (C * 2 * Y) + (A * (X - Y));
            price2 = C * 2 * X;
        } else {
            price1 = (C * 2 * X) + (B * (Y - X));
            price2 = C * 2 * Y;
        }
        int price3 = A * X + B * Y;
        int ans = Math.min(price1, price2);
        ans = Math.min(ans, price3);
        System.out.println(+ans);
    }

}

Measured memory_bytes: 21972
using System;
using System.Linq;
using System.Collections.Generic;

using Point=System.Tuple<long,long>;

public static class Program {
    public static void Main() {
        long[]hn=Console.ReadLine().Split().Select(long.Parse).ToArray();
        long h=hn[0];
        long n=hn[1];

        long[]dp=new long[h+1];
        long inf=long.MaxValue;
        dp[0]=0;
        for(int i=1;i<=h;i++){
            dp[i]=inf;
        }
        for(int i=0;i<n;i++){
            long[]ab=Console.ReadLine().Split().Select(long.Parse).ToArray();
            long a=ab[0];
            long b=ab[1];
            for(int j=0;j<=h;j++){
                if(dp[j]==inf)continue;
                int k=(int)Math.Min(j+a,h);
                dp[k]=Math.Min(dp[k],dp[j]+b);
            }
        }
        Console.WriteLine(dp[h]);
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>

using namespace std;

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a<c && c<=b){
        if(b<d){
            cout << b-c;
        }else{
            cout << d-c;
        }
    }else if(c>=b || d<=a){
        cout << 0;
    }else{
        if(d<=b){
            cout << d-a;
        }else{
            cout << b-a;
        }
    }
    
    return 0;
}

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

void check(int k, int i[]){
    if(i[k]==9){
        i[k]=0;
        check(k-1,i);
    }else{
        i[k]++;
    }
}
int main(){
    int n,a,b,sum=0,i[5];
    cin >> n >> a >> b;
    for(int j=0;j<4;j++){i[j]=0;}
    i[4]=1;
    while(10000*i[0]+1000*i[1]+100*i[2]+10*i[3]+i[4] <= n){
        if(i[0]+i[1]+i[2]+i[3]+i[4] >= a && i[0]+i[1]+i[2]+i[3]+i[4] <= b){
            sum += 10000*i[0]+1000*i[1]+100*i[2]+10*i[3]+i[4];
        }
        check(4,i);
    }
    cout << sum;

    return 0;
}


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

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

  if (a > b) swap(a, b);
  if (b > c) swap(b, c);
  if (a > b) swap(a, b);

  cout<<a<<" "<<b<<" "<<c<<endl;
  return 0;
}



Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int N, a[1000], b[1000], c[1000], i;
	scanf("%d", &N);
	for(i=0;i<N;i++) {
		scanf("%d %d %d", &a[i], &b[i], &c[i]);
		a[i]=a[i]*a[i];
		b[i]=b[i]*b[i];
		c[i]=c[i]*c[i];
	}
	for(i=0;i<N;i++) {
		if(a[i]==b[i]+c[i]||b[i]==c[i]+a[i]||c[i]==a[i]+b[i]) 
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

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

void input(int A[],int N){
  for(int i=0 ; i<N ; i++){
    cin >> A[i] ;
  }
}

void output_space(int A[],int N){
  for(int i=0 ; i<N ; i++){
    if(i != N-1){
      cout << A[i] << " ";
    }else{
      cout << A[i] ;
    }
  }
  cout <<endl;
}
///////////////////////////////////////////////////////
int times;

void bubble_sort(int A[],int N){
  bool flag = 1;
    for(int i=1;flag;i++){
      flag = 0;
      for(int j=N-1;j>=i;j--){
        if(A[j-1]>A[j]){
          swap(A[j-1],A[j]);
          flag = 1;
          times ++;
        }
      }
    }
  output_space(A,N);
  cout << times << endl;
}

int main(){
  int N;
  cin >> N;
  int A[N];
  input(A,N);
  bubble_sort(A,N);
  return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<28;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;

int main(){
	cin>>n;
	cout<<"ABC"<<n<<endl;
}

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

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

    string s, t;
    cin >> s >> t;
    int ans = 0;
    for(int i = 0; i < 3; i++){
        if(s[i] == t[i]){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
int *countingsort(int*,int,int);
int main(){
int i,n,max=INT_MIN;
int *list;
  scanf("%d",&n);
  list=(int*)malloc(n*sizeof(int));
  for(i=0;i<n;i++){
    scanf("%d",list+i);
    if(max<*(list+i))max=*(list+i);
  }
  list=countingsort(list,n,max);
  for(i=0;i<n;i++)printf("%d%c",*(list+i),(i<n-1)?' ':'\n');
  return 0;
}
int *countingsort(int *origin,int n,int m){
int i;
int *countlist,*sortedlist;
  m++;
  countlist=(int*)malloc(m*sizeof(int));
  sortedlist=(int*)malloc(n*sizeof(int));
  for(i=0;i<m;i++)*(countlist+i)=0;
  for(i=0;i<n;i++)*(countlist+*(origin+i))+=1;
  for(i=0;i<m-1;i++)*(countlist+(i+1))+=*(countlist+i);
  for(i=n-1;i>-1;i--){
    *(sortedlist+*(countlist+*(origin+i))-1)=*(origin+i);
    *(countlist+*(origin+i))-=1;
}
  return sortedlist;
}



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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	int N,Q; cin >> N >> Q;
	string S; cin >> S; S= "." + S + ".";
	V<char> t(Q),d(Q);
	for(int i = 0; i < Q; ++i) cin >> t[i] >> d[i];
	
	int ok,ng,md,l,r;
	ok = 0, ng = N+1;
	while(ng - ok > 1){
		md = (ng+ok)/2;
	
		int idx = md;
		for(int i = 0; i < Q; ++i){
			if(t[i] == S[idx]){
				idx += (d[i]=='L'?-1:1);
			}
		}
		(idx == 0?ok:ng) = md;
	}
	l = ok;

	ok = N+1, ng = 0;
	while(ok - ng > 1){
		md = (ng+ok)/2;
	
		int idx = md;
		for(int i = 0; i < Q; ++i){
			if(t[i] == S[idx]){
				idx += (d[i]=='L'?-1:1);
			}
		}
		(idx == N+1?ok:ng) = md;
	}
	r = ok;

	l = l;
	r = N+1 - r;
	
	cout << N - min((l+r),N) << endl;


	return 0;
}


Measured memory_bytes: 896
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,dp[100005]={};
  cin >> n;
  for(int i=1; i<=n; i++) {
    dp[i]=dp[i-1]+1;
    for(int j=6; j<=i; j*=6) {
      dp[i]=min(dp[i],dp[i-j]+1);
    }
    for(int j=9; j<=i;j*=9) {
      dp[i]=min(dp[i],dp[i-j]+1);
    }
  }
  cout << dp[n] << endl;
}



Measured memory_bytes: 640
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>

#include<deque>
#define pi 3.141592653589793238
#include<chrono>

#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f0 get<0>
#define f1 get<1>
#define f2 get<2>
#define db double
using namespace std;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll a ,b;
        cin >> a >> b;
        cout << a *b;
        
    }
    
    return 0;
}


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

typedef long long int ll;
typedef pair<int,int> pi;
priority_queue<pi, vector<pi>, greater<pi> > pq; //min heap

ll mini(ll a,ll b){	return a<b?a:b;}
ll maxi(ll a,ll b){	return a>b?a:b;}
ll gcd(ll a,ll b){	if(b == 0)	return a;return gcd(b,a%b);}
ll binpow(ll n,ll x){	ll ans = 1;while(x){if(x & 1)	ans *= n;n *= n;x >>= 1;}return ans;}

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

    ll n,w;
    cin>>n>>w;
    
    vector<ll> dp[n+1];
    for(ll i=0;i<=n;++i)    dp[i].resize(w+1,0);

    ll row[n+1][2];
    row[0][0] = row[0][1] = 0;
    for(ll i=1;i<=n;++i)    cin>>row[i][0]>>row[i][1];

    for(ll i=1;i<=n;++i){
        for(ll j=1;j<=w;++j){
            if(row[i][0] <= j)  dp[i][j] = max(dp[i-1][j], dp[i-1][j-row[i][0]] + row[i][1]);
            else                dp[i][j] = dp[i-1][j];
        }
    }

    cout<<dp[n][w]<<"\n";

    return 0;
}

Measured memory_bytes: 82212
s = int(input())

slist= [s]
ans = 2

while True:
    if s%2 == 0:
        s = int(s/2)
    else:
        s = 3*s + 1

    if s in slist:
        print(ans)
        break
    else:
        slist.append(s)
        ans += 1

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e4 + 5;
const int maxm = 5e5 + 5;
const ll inf = 2147483647;

int main(){
    int a, b, c, k;
    cin>>a>>b>>c;
    cin>>k;
    while (b <= a){
        b *= 2;
        k--;
    }
    while (c <= b){
        c *= 2;
        k--;
    }
    if(k >= 0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3604
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();
            var x = line[0];
            var n = line[1];
            var str = ReadLine();
            if (n == 0)
            {
                WriteLine(x);
                return;
            }
            var nums = str.Split(' ').Select(value => long.Parse(value)).ToArray();

            var contains = new bool[101];
            foreach(var value in nums)
            {
                contains[value] = true;
            }

            var nearest = Abs(0 - x) <= Abs(101 - x) ? 0 : 101;
            for(var i = 1; i <= 100; i++)
            {
                if(!contains[i] && (Abs(x - nearest) > Abs(x - i) || (Abs(x - nearest) == Abs(x - i) && nearest > i)))
                {
                    nearest = i;
                }
            }

            WriteLine(nearest);
        }
    }
}


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

using namespace std;

const int N = 300 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n;
long long a[N], r[N], sum[N];

bool read() {
    if (!(cin >> n))
        return false;

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

    return true;
}

void solve() {
    sum[1] = r[1] = 1;

    for (int i = 2; i <= n; ++i)
        sum[i] = (sum[i - 1] + (r[i] = (MOD - (MOD / i) * r[MOD % i] % MOD) % MOD)) % MOD;

    auto ans = 0ll;

    for (int i = 0; i < n; ++i)
        ans += a[i] * (sum[i + 1] + sum[n - i] - 1) % MOD;

    for (int i = 1; i <= n; ++i)
        ans = ans * i % MOD;

    cout << ans % MOD << endl;
}

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

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
const int N=1005,P=1e9+7;
int n,m,nxt[N],s[N],f[N][N],g[N];
int main()
{
	scanf("%d%d",&n,&m);n*=2;
	for(int i=1,u,v;i<=m;i++)scanf("%d%d",&u,&v),nxt[u]=v,nxt[v]=u,s[u]=1,s[v]=1;
	for(int i=1;i<=n;i++)s[i]+=s[i-1];
	g[0]=1;for(int i=2;i<=n;i+=2)g[i]=1ll*(i-1)*g[i-2]%P;
	for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j+=2)
	{
		int ff=1;
		for(int k=i;k<=j;k++)if(nxt[k]&&(nxt[k]<i||nxt[k]>j)){ff=0;break;}
		if(!ff)continue;
		for(int k=i+1;k<j;k+=2)f[i][j]=(f[i][j]+1ll*f[i][k]*g[j-k-s[j]+s[k]])%P;
		f[i][j]=(g[j-i+1-s[j]+s[i-1]]-f[i][j]+P)%P;
	}
	m*=2;int ans=0;
	for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j+=2)ans=(ans+1ll*f[i][j]*g[n-(j-i+1)-(m-s[j]+s[i-1])])%P;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
bitset<2000002> b;
int sum,k;
int main(){
	int n,V;
	scanf("%d",&n);
	b[0]=1;
	while(n--){
	int v;
	scanf("%d",&v);
	b|=b<<v;
	sum+=v;
	}
	int i=(sum)/2+1;
	while(i--)
	{
		if(b[i]){
			k=sum-i; break;
		}
	}
	printf("%lld",k);
}



Measured memory_bytes: 1024
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
lli a[2*maxn];
lli b[2*maxn];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=0;lli med1=0ll,med2=0ll;
    cin>>n;
    for(int i=0;i<n;++i)
    {
    	cin>>a[i]>>b[i];
    }
    sort(a,a+n);
    sort(b,b+n);
    if(n%2==0)
    {
    	med1=a[n/2]+a[n/2-1];
    	med2=b[n/2]+b[n/2-1];
    }
    else
    {
    	med1=a[n/2];
    	med2=b[n/2];
    }
    cout<<(med2-med1+1ll)<<endl;
}

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

using namespace std;
typedef long long ll;
#define debug(x) cerr << x << "\n"
#define all(x) (x).begin(),(x).end()
#define exist(s, e)((s).find(e) != (s).end())

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    ll ss = s.size() - 1;
    ll i = 0;
    ll ans = 0;
    while(i < ss) {
        if (s[i] == s[ss]) i++,ss--;
        else if (s[i] == 'x') i++,ans++;
        else if (s[ss] == 'x') ss--, ans++;
        else {
            cout << -1 << '\n';
            return 0;
        }
    }
    
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define uu unsigned
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define pi pair<int,int>
#define pl pair<ll,ll>
#define mkp make_pair
#define ss second
#define ff first
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define pb push_back
#define pf push_front
#define printcas cout<<"Case "<<cas<<": "
#define _ continue;
#define endl '\n'
#define __ cout<<endl;continue;
#define vc4d(nam,type,a,b,c,d,fix) vector<vector<vector<vector<type>>>> nam(a,vector<vector<vector<type>>>(b,vector<vector<type>>(c,vector<type>(d,fix))))
const ll oo=(1ll<<60);
int gg(){
    int x=0,w=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')w=0,ch=getchar();
    while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
    return w?x:-x;
}
ll h,w,ch,cw,dh,dw;
ll X[]={-1,1,0,0},Y[]={0,0,1,-1},xxx[]={-1,-1,1,1,-2,-2,-2,-2,-2,-1,-1,0,0,1,1,2,2,2,2,2},yyy[]={1,-1,-1,1,-2,-1,0,1,2,-2,2,-2,2,-2,2,-2,-1,0,1,2};
bool safe(ll x,ll y)
{
    if(x>-1 and y>-1 and x<h and y<w)return true;
    return false;
}
int main()
{
     io;
    int T=1;
    //T=gg();
    //cin>>T;
    //for(int cas=1;cas<=T;cas++)
    while(T--)
    {
        ll i,j,k,l,cnt=0;
        cin>>h>>w>>ch>>cw>>dh>>dw;
        vector<string> v(h);
        for(auto &x:v)cin>>x;
        ch--,cw--,dh--,dw--;
        queue<pl> qq({{ch,cw}}),pp;v[ch][cw]='#';
        while(1)
        {
            if(!qq.empty())
            {
                while(!qq.empty())
                {
                    pl u=qq.front();
                    if(u.ff==dh and u.ss==dw)
                    {
                        cout<<cnt;
                        return 0;
                    }
                    pp.push(u);
                    qq.pop();
                    for(i=0;i<4;i++)
                    {
                        ll x=u.ff+X[i],y=u.ss+Y[i];
                        if(safe(x,y) and v[x][y]=='.')
                        {
                            v[x][y]='#';
                            qq.push({x,y});
                        }

                    }
                }
            }
            else if(!pp.empty())
            {
                while(!pp.empty())
                {
                    pl u=pp.front();
                    pp.pop();
                    for(i=0;i<20;i++)
                    {
                        ll x=u.ff+xxx[i],y=u.ss+yyy[i];
                        if(safe(x,y) and v[x][y]=='.')
                        {
                            v[x][y]='#';
                            qq.push({x,y});
                        }
                    }

                }
                cnt++;
            }
            else
            {
                cout<<-1;
                return 0;
            }
        }


    }
    return 0;
}


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

int main()
{
	char str[110];
	cin >> str;

	int i = 0;
	bool b = true;
	while (str[i] != '\0')
	{
		if ((i + 1) % 2)
		{
			if (str[i] != 'R' &&
				str[i] != 'U' &&
				str[i] != 'D')
			{
				b = false;
				break;
			}
		}
		else
		{
			if (str[i] != 'L' &&
				str[i] != 'U' &&
				str[i] != 'D')
			{
				b = false;
				break;
			}
		}
		i++;
	}

	if (b)
		cout << "Yes";
	else
		cout << "No";

	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (n, k) = (v[0] as usize, v[1]);
    let a = read_vec::<i64>();
    let a_max = a.iter().max().unwrap();
    if k == 0 {
        println!("{}", a_max);
        return;
    }

    let criterion = |mid: i64| {
        if mid == 0 {
            return true;
        }
        let mut count = 0;
        for &num in &a {
            count += (num + mid - 1) / mid - 1;
            //debug!(count);
        }
        //debug!(count);
        count > k
    };

    debug!(criterion(4));
    debug!(criterion(5));
    let (ok, ng) = binary_search(0, a_max + 1, criterion);
    println!("{}", ng);
}

fn binary_search<F>(lb: i64, ub: i64, criterion: F) -> (i64, i64)
where
    F: Fn(i64) -> bool,
{
    assert_eq!(criterion(lb), true);
    assert_eq!(criterion(ub), false);
    let mut ok = lb;
    let mut ng = ub;
    while ng - ok > 1 {
        let mid = (ng + ok) / 2;
        if criterion(mid) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    (ok, ng)
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 6544
#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,d,e;
    cin>>a>>b;
    c=a+b;
    d=a-b;
    e=a*b;
    cout<<max({c,d,e})<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF=1e5+1;
int dist[INF];
bool visited[INF];
void dfs(vector<int> graph[],int node){
    visited[node]=true;
    for(int i=0;i<graph[node].size();i++){
        if(!visited[graph[node][i]]) dfs(graph,graph[node][i]);
        dist[node]=max(dist[node],1+dist[graph[node][i]]);

    }
}
int main(){
	int n,m;
	cin>>n>>m;
    vector<int> graph[n];
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        graph[u-1].push_back(v-1);
    }
    for(int i=0;i<n;i++){
        if(!visited[i]) dfs(graph,i);
    }
    int maxPath=0;
	for(int i=0;i<n;i++){
        maxPath=max(maxPath,dist[i]);
    }
    cout<<maxPath;
	return 0;
}


Measured memory_bytes: 12984