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

public class Main{
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int Z = sc.nextInt();
        int N = X + Y + Z;
        int [] A = new int [N];
        int [] B = new int [N];

        long ans = 0;

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

        System.out.println(ans + calcAns(X,Y,N,A,B));
    }

    public static long calcAns(int X, int Y, int N, int [] A,int [] B) {
        // sort the items
        Item [] items = new Item [N];
        for(int i = 0; i < N; i++) {
            items[i] = new Item(A[i],B[i]);
        }
        Arrays.sort(items);

        // System.out.println(Arrays.toString(items));

        // use priority queue to calculate the ans
        long [] max = new long [N];
        long sum = 0;
        PriorityQueue < Integer > current = new PriorityQueue<>();
        for(int i = 0; i < N; i++) {
            sum += items[i].a;
            current.add(items[i].a);
            if(i >= X) {
                sum -= current.poll();
            }
            max[i] = sum;
        }

        current.clear();
        sum = 0;
        long ret = Long.MIN_VALUE;
        for(int i = 0; i < N; i++) {
            int idx = N - i - 1;
            sum += items[idx].b;
            current.add(items[idx].b);
            if(i >= Y) {
                sum -= current.poll();
            }
            if((N - idx >= Y) && (idx >= X)) {
                long sol;
                sol = sum + max[idx - 1];
                if(sol > ret) {
                    ret = sol;
                }
            }
        }
        return ret;
    }

    static class Item implements Comparable < Item > {
        int a,b;
        int diff;

        Item(int a, int b) {
            this.a = a;
            this.b = b;
            diff = b - a;
        }

        @Override
        public int compareTo(Item item) {
            return diff - item.diff;
        }

        @Override
        public String toString(){
            return "a:" + a + " b:" + b;
        }
    }
}


Measured memory_bytes: 92912
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int x1 = 0, x2 = 0;
    int ans = 0;
    rep(i, n - 1)
    {
        if (s[i] != s[i + 1])
        {
            x2++;
        }
        else
        {
            ans++;
        }
    }

    while (k != 0 && x2 > 0)
    {
        if (x2 == 1)
        {
            ans++;
            x2 = 0;
            k--;
        }
        else
        {
            ans += 2;
            k--;
            x2 -= 2;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, k;
    string s;
    cin >> n >> s >> k;
    rep(i, n) {
        if(s[k-1] != s[i]) {
            s[i] = '*';
        }
    }
    out(s);
    re0;
}

Measured memory_bytes: 256
table = {}
def memoize(f):
    global table
    def func(*args):
        if not args in table:
            table[args]=f(*args)
        return table[args]
    return func

@memoize
def func(n):
    if n == 1:
        return 0
    if n%2 == 1:
        return 1+func(n*3+1)
    else:
        return 1+func(n/2)

while True:
    n = input()
    if n == 0:
        break
    print func(n)

Measured memory_bytes: 4324
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> a(m);
    rep(i,m) cin >> a[i];
    sort(a.begin(),a.end(),greater<int>());

    int num[10] = {0,2,5,5,4,5,6,3,7,6};
    int dp[10009] = {0};
    int dig_num[10009] = {0};

    rep(i,n)
    {
        int max_cnt = -INF;
        for(auto aj:a)
        {
            if(i+1-num[aj] < 0) continue;
            int tmp_cnt = dp[i+1-num[aj]] + 1;
            if(tmp_cnt > max_cnt)
            {
                max_cnt = tmp_cnt;
                dig_num[i+1] = aj;
            }                
        }
        dp[i+1] = max_cnt;
    }

    int cur = n;
    rep(i,dp[n])
    {
        cout << dig_num[cur];
        cur -= num[dig_num[cur]];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(2e5) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()


template <typename Monoid>
struct SegmentTree{
private:
    using F = function<Monoid(Monoid, Monoid)>;
    int N;
    vector<Monoid> node;
    F f;
    Monoid e;  // identity element

public:
    SegmentTree(){}
    SegmentTree(F f, Monoid e):f(f), e(e){}
    void init(int sz){
        N = 1;
        while(N < sz) N <<= 1;
        node.assign(2*N-1, e);
    }
    void build(vector<Monoid>& v){
        int sz = int(v.size());
        init(sz);
        for(int i=0; i<sz; i++){
            node[i+N-1] = v[i];
        }
        for(int i=N-2; i>=0; i--){
            node[i] = f(node[i*2+1], node[i*2+2]);
        }
    }
    void update(int k, Monoid x){
        k += N-1;
        node[k] = x;
        while(k > 0){
            k = (k-1)/2;
            node[k] = f(node[2*k+1], node[2*k+2]);
        }
    }
    // [a,b)
    Monoid query(int a, int b){return query(a, b, 0, 0, N);}
    Monoid query(int a, int b, int k, int l, int r){
        if(b <= l || r <= a) return e;
        if(a <= l && r <= b) return node[k];
        Monoid vl, vr;
        vl = query(a, b, 2*k+1, l, (l+r)/2);
        vr = query(a, b, 2*k+2, (l+r)/2, r);
        return f(vl, vr);
    }
};

auto f = [=](int a, int b){return min(a, b);};
auto g = [=](int a, int b){return max(a, b);};
SegmentTree<int> rmin(f,IINF), rmax(g,-IINF);

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> p(n), a(n+1);
    for(int i=0;i<n;i++) cin >> p[i];
    for(int i=0;i<n-1;i++){
        if(p[i] < p[i+1]) a[i+1] = a[i] + 1;
    }
    rmin.build(p);
    rmax.build(p);
    int ans = 1;
    bool sorted = (a[k-1]-a[0] == k-1);
    for(int i=0;i<n-k;i++){
        if(rmin.query(i,i+k) != p[i] || rmax.query(i+1,i+1+k) != p[i+k]){
            if(a[i+k]-a[i+1] == k-1 && sorted) continue;
            sorted |= a[i+k]-a[i+1] == k-1;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6016
#!/Users/takahiro.kida/git/atcorder/venv/bin/python

import numpy as np
import scipy

from collections import defaultdict
from pprint import pprint

N, A, B = [int(x) for x in input().split(" ")]

ans1 = min(A,B)
if A+B <= N:
    ans2 = 0
else:
    ans2 = A + B - N
print("{} {}".format(ans1,ans2))


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

int main(){
  int r=0;
  int m=10;
  for(int i=0;i<5;i++){
    int a; cin >> a;
    if(a%10>0){
      m = min(a%10,m);
    }
    if(a%10==0){
      r += a;
    }else{
      a /= 10;
      a += 1;
      a *= 10;
      r += a;
    }
  }
  r -= (10-m);
  cout << r << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MP make_pair
#define INF 0x3f3f3f3f
#define sz(x) (x).size()
#define fi first
#define se second
ll m[10005];
const int N = 1e5 + 5;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
  ll a,b,c;
  cin>>a;
for(ll i=2;i*i<=2*a;i++)
    for(ll j=2;j*j+i*i<=2*a;j++)
    for(ll k=2;k*k+j*j+i*i<=2*a;k++)
    {
        if(((i+j+k)%2==0)&&((i-j+k)>1)&&((i+j-k))>1&&((j+k-i))>1)
         m[(k*k+j*j+i*i)/2]++;
    }

    for(ll i=1;i<=a;i++)
        cout<<m[i]<<endl;

    return 0;
}



Measured memory_bytes: 3656
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::{min, max};

fn main() {
    input!{
        s: chars
    }
    let n = s.len();
    if (s[0] == s[n - 1]) ^ (n % 2 == 1) {
        println!("First");
    } else {
        println!("Second");
    }
}


Measured memory_bytes: 4352
N = int(input())
A = list(map(int, input().split()))

if N == 0:
    if A[0] == 1:
        print(1)
    else:
        print(-1)
    exit()

if A[0] != 0:
    print(-1)
    exit()

ans = 1
prev = 1
P = []
for a in A[1:]:
    P.append(prev)
    mx = prev * 2

    if mx < a:
        print(-1)
        exit()

    ans += mx
    prev = mx - a

while prev and P:
    ans -= prev
    pr = P.pop()
    prev = max(0, prev - pr)

print(ans)


Measured memory_bytes: 669632
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long a = in.nextLong();
            long b = in.nextLong();
            long c = in.nextLong();
            long d = in.nextLong();
            long ans = (b - a + 1) - (f(a, b, c) + f(a, b, d) - f(a, b, lcm(c, d)));
            out.println(ans);
        }

        private long f(long l, long r, long val) {
            long u = (l + val - 1) / val;
            long d = r / val;
            return d - u + 1;
        }

        private long gcd(long a, long b) {
            if (b == 0)
                return a;
            else
                return gcd(b, a % b);
        }

        private long lcm(long a, long b) {
            return a / gcd(a, b) * b;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 21460
/*@sh*/
#include<bits/stdc++.h>
using namespace std;
#include<cstdio>
#define pi 3.141592653589
#define pb push_back
#define ld long double
#define rem 1000000007
#define F first
#define S second
#define pii pair<long long,long long>
#define el "\n"
#define sp " "
typedef long long ll;
ll  p = 1000000007;
ll Pow(ll,ll,ll);
ll Pow(ll a,ll b,ll p){
	if(b==0) return 1;
	return !(b%2) ? (Pow(a,b/2,p)%p)*(Pow(a,b/2,p)%p)%p : (a%p)*(Pow(a,b-1,p))%p;
}   
main()
{ 
	// fast io
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);ll i; 
	ll n,k;
	cin>>n>>k;
	vector <ll> a(n),dp(n,1e15);
	for(i=0;i<n;i++)
	cin>>a[i];
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	//cout<<dp[1]<<sp;
	for(i=2;i<n;i++)
	{
		for(ll j=1;j<=min(i,k);j++)
		dp[i]=min(dp[i-j]+abs(a[i]-a[i-j]),dp[i]);
		//cout<<dp[i]<<sp;
	}
	cout<<dp[n-1];
}


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

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

  int d1, d2, d3, d4, d5; // 各桁の数字
  int rev; // 反転した数字
  int total = 0;

  for (int i = A; i <= B; i++) {
    d1 = i % 10;
    d2 = i % 100 / 10;
    d3 = i % 1000 / 100;
    d4 = i % 10000 / 1000;
    d5 = i % 100000 / 10000;

    rev = d1 * 10000 + d2 * 1000 + d3 * 100 + d4 * 10 + d5;    

    if (i == rev) {
       total++;
    }
  }

  cout << total << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

using P = pair<ll,ll>;
ll ans1,ans2;

int main(){
    int N; cin >> N;
    vector<P> a(N);
    ll mx=-1,mn=(1ll<<32);
    rep(i,N){
        cin >> a[i].fi >> a[i].se;
        if(a[i].fi > a[i].se) swap(a[i].fi,a[i].se);
        chmax(mx,a[i].se);
        chmin(mn,a[i].fi);
    }
    sort(all(a));

    ll Rmax = mx;
    // Bmin = mn
    {
        ll Bmin = mn;
        vector<int> x,y;
        rep(i,N) x.pb(a[i].fi);
        rep(i,N) y.pb(a[i].se);
        ll Bmax = *max_element(all(x));
        ll Rmin = *min_element(all(y));
        ans1 = (Rmax-Rmin) * (Bmax-Bmin);
    }

    // Rmin = mn
    {
        ans2 = 1e9 * 1e9;
        ll Rmin = mn;
        vector<ll> ymin(N,1ll<<29),ymax(N,0);
        vector<ll> rymin(N,1ll<<29),rymax(N,0);
        ymin[0] = ymax[0] = a[0].se;
        for(int i=1;i<N;i++){
            ymin[i] = min(ymin[i-1],a[i].se);
            ymax[i] = max(ymax[i-1],a[i].se);
        }
        rymin[N-1] = rymax[N-1] = a[N-1].se;
        for(int i=N-2;i>=0;i--){
            rymin[i] = min(rymin[i+1],a[i].se);
            rymax[i] = max(rymax[i+1],a[i].se);
        }

        for(int i=0;i<N;i++){
            ll Rmin = a[0].fi;
            ll Rmax = max(a[i].fi,rymax[i+1]);
            ll Bmin = min(a[i+1].fi,ymin[i]);
            ll Bmax = max(a[N-1].fi,ymax[i]);
            if(Rmin == mn and Rmax == mx){
                chmin(ans2,(Rmax-Rmin)*(Bmax-Bmin));
            }
        }
    }

    cout << min(ans1,ans2) << endl;
}


Measured memory_bytes: 9812
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define ALL(container) (container).begin(), (container).end()
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

int T, n, m;

vector<ll> count(ll x){	// count [0, x)
	vector<ll> ans;
	ll sum = 0;
	RREP(i, n + 1){
		if(1 & (x >> i)){
			x -= 1ll << i;
			ans.pb(sum + x);
			sum += (1ll << i) / 2;
		}else ans.pb(sum);
	}
	reverse(ALL(ans));
	return ans;
}

void check(vector<ll> &d, ll l, ll r, vector<pll> &ans){ // check [0, r)
	if(l <= 0 || r <= 0 || r <= l || r > 1000000000000000001ll) return;
	auto rv = count(r);
	auto lv = count(l);
	d.pb(0);
	if([&](){
		REP(i, d.size()) if(d[i] != rv[i] - lv[i]) return 0;
		return 1;
	}()) ans.eb(l, r);
	d.pop_back();
}

int main(int argc, char *argv[]){
	while(scanf("%d", &n), n){
		vector<ll> d(n);
		REP(i, n) scanf("%lld", &d[i]);
		while(!d.empty() && d.back() == 0) d.pop_back();
		n = d.size();
		vector<pll> ans;
		if(!n || n > 60){
			puts("None"); continue;
		}
		
		REP(i, 3){
			ll r = (1ll<<(n-1)) + d[n-1];
			ll w = d[0] * 2 - 1 + i;
			check(d, r - w, r, ans);
		}
		
		ll w = d.back();
		ll r = (1ll<<(n-1));
		if(abs(w / 2 - d[0]) <= 1){
			RREP(i, n-1)if(d[i]){
				r += 1ll << i;
				if(d[i] == w) continue;
				r += d[i];
				check(d, r - w, r, ans);
				break;
			}
		}
		if(w == 1) check(d, r, r + 1, ans);
		sort(ALL(ans)); UNIQUE(ans);
		if(ans.empty()) puts("None");
		else if(ans.size() > 1) puts("Many");
		else printf("%lld %lld\n", ans[0].first, ans[0].second - 1);
	}
	return 0;
}

Measured memory_bytes: 1204
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int[] d = new int[n];
		for(int i = 0;i < n;i++){
			d[i] = saori.saori_hayami();
		}
		Arrays.sort(d);
		int num = n/2 -1;
		if(d[num] == d[num+1]){
			System.out.println(0);
		} else {
			System.out.println(d[num+1] - d[num]);
		}
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

int N,M;
long long ans;
struct info{
	long long a, b;
}drink[100005];

bool cmp(const info &x, const info &y)
{
	return x.a < y.a;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> N >> M;
	for(int i = 0; i < N; ++i) cin >> drink[i].a >> drink[i].b;
	sort(drink,drink+N,cmp);
	for(int i = 0; i < N; i++){
		if(drink[i].b <= M){
			ans += drink[i].b * drink[i].a;
			M -= drink[i].b;
		}else{
			ans += drink[i].a * M;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define all(v) v.begin(), v.end()
#define ar array

#define F first
#define S second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pll = pair <ll, ll>;
using ld = long double;

const int mod = 1e9 + 7;
// const int mod = 998244353;
const ll inf = 2e9;
const ll INF = 1e18;
const ld EPS = 1e-7;

const int N = 1e5 + 5;

ll a[N];

void solve () {
	int n, k;
	cin >> n >> k;
	for (int i = 1 ; i <= n ; ++ i) {
		cin >> a[i];
	}
	ll best = 0;
	for (int all = 0 ; all <= k ; ++ all) {
		for (int l = 0 ; l <= all ; ++ l) {
			multiset <ll> s;
			int r = max (l + 1, n + 1 - (all - l));
			ll sum = 0;
			for (int i = 1 ; i <= n ; ++ i) {
				if (i <= l || i >= r) {
					s.insert (a[i]);
					sum += a[i];
				}
			}
			ll left = k - all;
			while (s.size() && *s.begin() < 0 && left) {
				sum -= *s.begin();
				s.erase (s.begin());
				left--;
			}
			best = max (best, sum);
		}
	}
	cout << best;
}

int main () {
	ios;
	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
		cout << "\n";
	}
}




Measured memory_bytes: 256
/*
 * @Author: Wa_King 
 * @Date: 2019-11-23 19:58:12 
 * @Last Modified by: Wa_King
 * @Last Modified time: 2019-11-23 21:56:26
 */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define fi first
#define se second
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
const int mod = 1e9 + 7;
const int maxn = 2e7 + 10;
const int inf = 0x3f3f3f3f;
char ans[300];
int n;
void ask(int pos)
{
    //cout<<1<<'\n';
    cout<<"? ";
    rep(i,pos,pos+n-1) cout<<i<<' ';
    cout<<endl;
    fflush(stdout);
}
void ask2(int x,int pos)
{
    //cout<<2<<'\n';
    cout<<"? ";
    cout<<x<<' ';
    rep(i,pos+1,pos+n-1) cout<<i<<' ';
    cout<<endl;
    fflush(stdout);
}
vector<int> p;
void ask3(int x)
{
    //cout<<3<<'\n';
    cout<<"? ";
    cout<<x<<' ';
    for(auto y:p) cout<<y<<' ';
    cout<<endl;
    fflush(stdout);
}
int main()
{
    cin>>n;
    if(n==1)
    {
        string now;
        cout<<"? 1"<<endl;
        fflush(stdout);
        cin>>now;
        ans[1]=now[0];
        cout<<"? 2"<<endl;
        fflush(stdout);
        cin>>now;
        ans[2]=now[0];
        cout<<"! ";
        rep(i,1,2*n) cout<<ans[i];
        fflush(stdout);
        return 0;
    }
    int l=1,r=n;
    string a,b;
    ask(l);
    cin>>a; 
    if(a=="Red") b="Blue";
    else b="Red";
    string now;
    while(l+1<r)
    {
        int mid=(l+r)>>1;
        ask(mid);
        cin>>now;
        if(now==a) l=mid;
        else r=mid-1;
    }
    ask(r);
    cin>>now;
    if(now==a) l=r;
    ans[l]=a[0];
    ans[l+n]=b[0];
    for(int i=1;i<=l-1;i++)
    {
        ask2(i,l);
        cin>>now;
        if(now==a) ans[i]=a[0];
        else ans[i]=b[0];
    }
    for(int i=l+n+1;i<=2*n;i++) 
    {
        ask2(i,l);
        cin>>now;
        if(now==a) ans[i]=a[0];
        else ans[i]=b[0];
    }
    int numa=0,numb=0;
    rep(i,1,2*n)
    {
        if(ans[i]=='R'&&numa<n/2) p.pb(i),numa++;
        if(ans[i]=='B'&&numb<n/2) p.pb(i),numb++;
    }
    rep(i,1,2*n) 
    {
        if(ans[i]!='R'&&ans[i]!='B')
        {
            ask3(i);
            cin>>now;
            if(now==a) ans[i]=a[0];
            else ans[i]=b[0];
        }
    }
    cout<<"! ";
    rep(i,1,2*n) cout<<ans[i];
    fflush(stdout);
    return 0;
}


Measured memory_bytes: 724
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()

void Calc();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr); cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

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

template<class T, class B, class...V>struct Vec {
  typedef Vec<T, V...>A; typedef vector<typename A::t>t; t nvec(B a, V...b) { return t(a, A().nvec(b...)); }
};
template<class T, class B>struct Vec<T, B> { typedef vector<T>t; t nvec(B a) { return t(a); } };
template<class T>tuple<T>Init(T t) { return tuple<T>(t); }
template<class T, class C>struct Vec<T, tuple<C>> { using t = T; T nvec(tuple<C> a) { return get<0>(a); } };
template<class T = int, class...B> typename Vec<T, B...>::t nvec(B...b) { return Vec<T, B...>().nvec(b...); }



void Calc() {

  int n, ma, mb;
  in, n, ma, mb;

  struct Data {
    int a, b, c;
    void In() {
      in, a, b, c;
    }
    bool operator<(const Data&d)const {

    }
  };
  vector<Data> d(n);
  for (auto& i : d) {
    i.In();
  }
  const int INF = 1e9 - 1;

  auto dp = nvec(n + 1, n * 11, n * 11, Init(INF));
  dp[0][0][0] = 0;
  rep(nn, n) rep(j, n * 11) {
    rep(k, n * 11) {
      if (dp[nn][j][k] == INF) continue;
      auto p = d[nn];
      err(j, k, p.a, p.b);
      auto& tmp = dp[nn + 1][j + p.a][k + p.b];
      amin(tmp, dp[nn][j][k] + p.c);
      amin(dp[nn + 1][j][k], dp[nn][j][k]);
    }
  }

  auto mini = INF;
  rep(i, 1, n * 11) {
    if (i*ma >= n * 11 || i*mb >= n * 11)break;
    err(i*ma, dp[n][i * ma][i * mb]);
    if (dp[n][i * ma][i * mb] != INF) amin(mini, dp[n][i*ma][i*mb]);
  }
  cout << (mini == INF ? -1 : mini) << endl;

}


Measured memory_bytes: 32768
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define vll vector<ll>

using namespace std;

const ll N = 3e5+100;
const ll MOD = 1e9+7;

struct data
{	
	ll sumr;
	ll sumb;
	ll ans;
};

ll a[90][90];
ll b[90][90];
data dp[90][90][2];



int main()
{

	ll x,y;
	cin >> x >> y;

	ll ans = 0;
	ll n = x;

	while(n<=y){
		ans++;
		n*=2;
	}cout<<ans<<endl;


	return 0;
	
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define INF LONG_LONG_MAX
#define MOD 1000000007
#define yn(f) cout << (f ? "Yes" : "No") << endl;
#define YN(f) cout << (f ? "YES" : "NO") << endl;

int n,ans;
vector<pair<int,int>> v;
set<int> s;

signed main() {
    cin >> n;
    rep(i,n) {
        int a;
        cin >> a;
        v.pb(mp(a,i));
    }
    sort(all(v));
    s.insert(-1);
    s.insert(n);
    rep(i,n) {
        int a = v[i].fi, idx = v[i].se;
        int l = (idx - *(--s.lower_bound(idx)));
        int r = (*s.upper_bound(idx) - idx);
        ans += l*r*a;
        s.insert(idx);
    }
    cout << ans << endl;
}




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

int main ()
{
  int K, S;
  cin >> K >> S;
  int ans = 0;
  for (int x = 0; x <= K; x++)
  {
    for (int y = 0; y <= K; y++)
    {
      int z = S - x - y;
      if (0 <= z && z <= K)
        ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY 3000
int n,M[MAX][MAX];

int main(){
  int i,j,e,d,sum;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      if(e==-1){
	M[i][j]=INFTY;
      }else{
	M[i][j]=e;
      }
    }
  }
  sum=prim();
  printf("%d\n",sum);
  return 0;
}

int prim(){
  int u,minv,i,j,v,sum=0;
  int d[MAX],p[MAX],color[MAX];
  for(i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  }
  d[0]=0;

  while(1){
    minv=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i] && color[i]!=BLACK){
	u=i;
	minv=d[i];
      }
    }
    if(u==-1)break;
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v]!=BLACK && M[u][v]!=INFTY){
	if(d[v]>M[u][v]){
	  d[v]=M[u][v];
	  p[v]=u;
	  color[v]=GRAY;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    if(p[i]!=-1)
      sum+=M[i][p[i]];
  }
  return sum;
}

Measured memory_bytes: 636
#define MOD 1000000007
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define FOR(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define mp make_pair
#define has(set, x) set.find(x) != set.end()
#define nohas(set, x) set.find(x) == set.end()
#define inc(mpp, x) {if(has(mpp, x)) mpp[x]++; else mpp.insert(mp(x,1));}
#define decc(mpp, x) {if(has(mpp, x)) {if(mpp[x] > 1) mpp[x]--; else mpp.erase(x);}}
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define um unordered_map
#define us unordered_set
#include <iostream>
#include <list>
#include <queue>
#include <vector>
#include <map>
#include <string>
#include <unordered_map>
#include <iomanip>
#include <set>
#include <unordered_set>
#include <fstream>
#include <algorithm>
using namespace std;
const int INF = 1 << 29;
typedef long long ll;
typedef unsigned long long ull;
inline int two(int n) { return 1 << n; }
ll extgcd(ll a, ll b, ll& x, ll& y) { if (b == 0) { x = 1; y = 0; return a; } else { int g = extgcd(b, a%b, y, x); y -= a / b * x; return g; } }
ll modpow(ll a, ll b) { ll res = 1; a %= MOD; for (; b; b >>= 1) { if (b & 1)res = res * a%MOD; a = a * a%MOD; }return res; }

ll arr[100000];
ll res[100000];

int main() {
	fast;
	ifstream in("input.txt");
	ofstream out("output.txt");
	int t, n;
	ll mx = -1e12;
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int suit2num(char suit){
        switch(suit) {
        case 'S':
                return 0;
        case 'H':
                return 1;
        case 'C':
                return 2;
        case 'D':
                return 3;
        }
        return -1;
}

char num2suit(int i){
        switch(i) {
        case 0:
                return 'S';
        case 1:
                return 'H';
        case 2:
                return 'C';
        case 3:
                return 'D';
        }
        return ' ';
}

int main(void){
        int n;
        int card[4][13]={0};
        int number;
        char suit;
        cin>>n;
        for(int i=0; i<n; i++) {
                cin>>suit>>number;
                card[suit2num(suit)][number-1]=1;
        }
        for(int i=0; i<4; i++) {
                for(int j=0; j<13; j++) {
                        if(card[i][j]==0) {
                                cout<<num2suit(i)<<" "<<j+1<<endl;
                        }
                }
        }
        return 0;

}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a, odd=0;
	cin>>a;
	for(int i=1; i<=a; ++i){
		if(i%2 != 0){
			odd++;
		}
	}
	cout<<fixed<<setprecision(10);
	cout<<(double)odd/a<<'\n';
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define out(a) cout<<fixed<<setprecision((a))
 

int main(){ 
	ll a,b,c;
	string s;
	cin >> a >> b;
	cout << max({a+b,a-b,a*b}) << endl;
}


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

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

  vector<int> f(q,-1);
  vector<char> c(q);

  for (int i = 0; i < q; i++)
  {
    int t;
    cin >> t;
    if(t==1) continue;
    int fi;
    cin >> fi >> c[i];
    f[i] = fi-1;
  }

  string head="",tail=s;
  for (int i = 0; i < q; i++)
  {
    if(f[i]==-1) {
      swap(head,tail);
    }
    else{
      if(f[i]){
        tail += c[i];
      }
      else{
        head += c[i];
      }
    }
  }
  reverse(head.begin(),head.end());
  string ans = head + tail;
  cout << ans << endl;
}

Measured memory_bytes: 2524
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

template <class T> class MultiArray2
{
    public:
        T* _a;
        int _w;
        int _h;
        MultiArray2(int w, int h, bool clr = false)
        {
            _w = w; _h = h;
            _a = new T[_w * _h];
            if(clr) memzero();
        }

        void memzero()
        {
            memset(_a, 0, _w * _h * sizeof(T));
        }

        ~MultiArray2()
        {
            delete _a;
        }

        T* operator[](int i)
        {
            return _a + (i * _h);
        }

        void print()
        {
            for( int j = 0; j < _h; j++ )
            {
                for( int i = 0; i < _w; i++ )
                {
                    cout << (*this)[i][j] << " ";
                }
                cout << endl;
            }
        }
};

bool check(int n, char *group, MultiArray2<bool> &s)
{
    rep(i, n) group[i] = 0;
    group[0] = 1;
    rep(k, n)
    {
        bool flag = true;
        rep(i, n)
        {
            if( group[i] == 0 )
            {
                flag = false;
                continue;
            }
            rep(j, n)
            {
                if( i == j ) continue;
                if( s[i][j] )
                {
                    if( group[j] == 0 )
                    {
                        group[j] = -group[i];
                    }
                    else
                    {
                        if( group[j] != -group[i] ) return false;
                    }
                }
            }
        }
        if( flag ) return true;
    }
    return false; // 連結でない。通らないはず
}

int getmaxwidth(int start, int *len, MultiArray2<bool> &s, int n )
{
    rep(i, n) len[i] = -1;
    len[start] = 0;
    int ans = 0;
    queue<int> que;
    que.push(start);
    while(!que.empty())
    {
        int i = que.front();
        que.pop();
        ans = len[i] + 1;
        rep(j, n)
        {
            if( s[i][j] && len[j] < 0 )
            {
                len[j] = len[i] + 1;
                que.push(j);
            }
        }
    }
    return ans;
}

// o(n^3)
int getmax(int n, MultiArray2<bool> &s)
{
    int maxsize = 0;
    int *len = new int[n];
    rep(i, n)
    {
        maxsize = max(maxsize, getmaxwidth(i, len, s, n));
    }
    delete len;
    return maxsize;
}

int main()
{
    int n; cin >> n;
    MultiArray2<bool> s(n, n , true);
    rep(i, n)
    {
        string st; cin >> st;
        rep(j, n)
        {
            if( st[j] == '1' )
            {
                s[i][j] = true;
                s[j][i] = true;
            }
        }
    }

    char *group = new char[n];
    if( !check(n, group ,s) )
    {
        cout << -1;
        return 0;
    }

    int ans = getmax(n, s);
    cout << ans;

    delete group;
    return 0;    
}



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

int main() {

  int n; cin >> n;
  
  vector<int> vec(n);
  for(int i=0; i<n; i++){
    cin >>vec.at(i);
  }
  
  int m; cin >> m;
  for(int i=0; i<m; i++){
    int p, x; cin >> p >> x;
    int ans = 0;
    for(int j=0; j<n; j++){
      if (j == p-1) {
        ans += x;
      } else {
        ans += vec.at(j);
      }
    }
    cout << ans << endl;
  }
  
 
  
  
}


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

int main(){
    int x,t;
    cin >> x >> t;
    cout << (x-t>0?x-t:0) << endl;
    return 0;
}



Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

alias sread = () => readln.chomp();

void main()
{
    long N = lread();
    auto A1 = aryread();
    auto A2 = aryread();

    foreach (i; 1 .. N)
    {
        A1[i] = A1[i] + A1[i - 1];
        A2[i] = A2[i] + A2[i - 1];
    }

    long result = 0;

    // writeln(A1, A2);

    foreach (i; 0 .. N)
    {
        long tmp = A1[i] + A2[$ - 1] - ((i == 0) ? 0 : A2[i - 1]);
        result = result.max(tmp);
    }

    result.writeln();

}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
	int key;
	Node *next, *prev;
};

Node *nil;

Node* listSearch(int key) {
	Node *cur = nil->next;
	while ( cur != nil && cur->key != key ) {
		cur = cur->next;
	}
	return cur;
}

void init() {
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void printList() {
	Node *cur = nil->next;
	int isf = 0;
	while ( 1 ) {
		if ( cur == nil ) break;
		if ( isf++ > 0 ) printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

void deleteNode(Node *t) {
	if ( t == nil ) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst() {
	deleteNode(nil->next);
}

void deleteLast() {
	deleteNode(nil->prev);
}

void deleteKey(int key) {
	deleteNode(listSearch(key));
}

void insert(int key) {
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

int main() {
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for ( i = 0; i < n; i++ ) {
		scanf("%s%d", com, &key);
		if ( com[0] == 'i' ) { insert(key); np++; size++; }
		else if ( com[0] == 'd' ) {
			if ( strlen(com) > 6 ) {
				if ( com[6] == 'F' ) deleteFirst();
				else if ( com[6] == 'L' ) deleteLast();
			} else {
		        deleteKey(key); nd++;
			}
			size--;
		}
	}
	
	printList();
	
	return 0;
}


Measured memory_bytes: 33964
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int k = sc.nextInt();
        int[] a = new int[N];
        int[] b = new int[N-1];
        for(int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        for(int i = 1; i< N; i++) {
            b[i-1] = a[i] - a[i-1];
        }
        int min, result, minI;
        min = 2147483647;
	minI = 0;
        for(int i = 0; i < N; i++) {
            if(N < i+k) break;
            result = 0;
            for(int j = 0; j <k-1; j++) {
                result = result + b[i+j];
            }
	    if(min > result){
                min = result;
                minI = i;
            }
        }
        result = a[minI+k-1] - a[minI];
        System.out.println(result);


    }
}

Measured memory_bytes: 62148
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e6+10;
char s[N];
int main() {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
    }
    int ans=1;
    for(int i=1;i<n;i++)
    {
        if(s[i]!=s[i+1]) {
            ans++;
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 384
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑

long long a, b, k[575][575], ans;
int main() {
	cin >> a >> b;
	for (int i = 0; i < a; ++i) {
		for (int j = 0; j < b; ++j) {
			cin >> k[i][j];
			ans += k[i][j] * (i + 1)*(j + 1)*(a - i)*(b - j);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 5352
#include "bits/stdc++.h"
using namespace std;

int n,a,mn=0,mx=0;
map<string, int> color;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	color["gray"]=0;
	color["brown"]=0;
	color["green"]=0;
	color["cyan"]=0;
	color["blue"]=0;
	color["yellow"]=0;
	color["orange"]=0;
	color["red"]=0;
	color["above"]=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		switch(a){
			case 1 ... 399:
				color["gray"]++;
				break;
			case 400 ... 799:
				color["brown"]++;
				break;
			case 800 ... 1199:
				color["green"]++;
				break;
			case 1200 ... 1599:
				color["cyan"]++;
				break;
			case 1600 ... 1999:
				color["blue"]++;
				break;
			case 2000 ... 2399:
				color["yellow"]++;
				break;
			case 2400 ... 2799:
				color["orange"]++;
				break;
			case 2800 ... 3199:
				color["red"]++;
				break;
			case 3200 ... 4800:
				mx++;
				break;
		}
	}

	for(auto it=color.begin();it!=color.end();++it){
		if(it->first != "above" && it->second != 0)
			mn++;
	}

	if(mn==0)
		cout<<1<<' '<<mn+mx;
	else
		cout<<mn<<' '<<mn+mx;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const double pi = 2*acos(0.0);
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    double r, ans=0.0; cin >> r;
    ans = 2.0*pi*r;
    cout<<fixed<<setprecision(20)<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3816
#include<iostream>
#include<vector>

using namespace std;

int main(){
  long long int n,i,j;
  vector <long long int> v;
  
  cin>>n;
  v.push_back(2);
  v.push_back(1);
  
  for(i=2;i<n+1;i++){
    j=v[i-1]+v[i-2];
    v.push_back(j);
  }
  cout<<v[n]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
    int N;
    cin >> N;
    int x, y;
    x = N /4;
    y = N /7;

    for(int i = 0; i <= x; i++){
        for(int j = 0; j <= y; j++){
            int X = 4*i + 7*j;
            if(N == X){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define c(n) cin>>n
#define co(n) cout<<n<<endl
using namespace std;

int main(){
  long a,b=2,c=0,d=0,e,n,m=0,x;
  string s,t;
  cin >> s >> t;
  n=s.size();
  rep(i,0,n){
    rep(j,0,n){
      a=(i+j)%n;
      if(s[a]==t[j]) c++;
    }
    if(c==n){
      d++;
      break;
    }
    else c=0;
  }
  if(d==1) co("Yes");
  else co("No");
  
  return 0;
}

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

int main()
{
    int N;
    int count = 0;
    int ans = 0;


    cin >> N;

    for (int i = 1; i < N; i++) {
        ans += (N - 1) / i;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628