akhauriyash/Code-Regression huggingface dataset:
N = int(input())
W = [input() for i in range(N)]
count = 0
for i in range(N-1):
    if W[i][-1] != W[i+1][0]:
        count += 1

count += len(W)- len(set(W))

if count == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
(n, m) = map(int, input().split())
cities = []
for _ in range(m):
    cities.append(list(map(int, input().split())))

city_dict = {}
for i, city in enumerate(cities):
    if not city[0] in city_dict:
        city_dict[city[0]] = []
    city_dict[city[0]].append([i, city[1], ""])

ans = []
for key, value in city_dict.items():
    value.sort(key=lambda x: x[1])
    for i, v in enumerate(value):
        v[2] = "{}{}".format(str(key).zfill(6), str(i+1).zfill(6))
    ans.extend(value)
ans.sort(key=lambda x:x[0])
for a in ans:
    print(a[2])

Measured memory_bytes: 62240
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
#include<atcoder/dsu>

using namespace std;
using namespace atcoder;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
	if (x >= m)x %= m;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 19;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}

int gcd(int a, int b) {
	if (a < b)swap(a, b);
	while (b) {
		int r = a % b; a = b; b = r;
	}
	return a;
}

void solve() {
	int n, q; cin >> n >> q;
	dsu d(n);
	rep(i, q) {
		int t, a, b; cin >> t >> a >> b;
		if (t == 0) {
			d.merge(a, b);
		}
		else {
			if (d.same(a, b)) {
				cout << 1 << "\n";
			}
			else {
				cout << 0 << "\n";
			}
		}
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(15);
	//init_f();
	//init();
	//expr();
	//int t; cin >> t; rep(i, t)
	solve();
	return 0;
}


Measured memory_bytes: 12144
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 100005
#define MOD 20190823
#define eps 1e-8
#define mp make_pair
#define INF 1000000000+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
template<class T> inline void read(T &f){
	f=0;
    T x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
}
template<class T> T gcd(T x,T y){
	T temp;
	while(y!=0) {
		temp=x%y;
		x=y;
		y=temp;
	}
	return x;
}
ll a[DMAX];
ll pre[DMAX],suf[DMAX];
int main(){
	ll n;
	read(n);
	for(ll i=1;i<=n;i++)
	{
		read(a[i]);	
	}
	pre[1]=a[1];
	for(ll i=2;i<=n;i++){
		pre[i]=gcd(pre[i-1],a[i]);
	}
	suf[n]=a[n];
	for(ll i=n-1;i>=1;i--){
		suf[i]=gcd(suf[i+1],a[i]);
	}
	ll ans=0;
	for(ll i=1;i<=n;i++){
		ans=max(ans,gcd(suf[i+1],pre[i-1]));
	}
	ans=max(ans,gcd(suf[1],pre[n-1]));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    long long int ans = 0;
    int tmp;
    int n;
    cin >> n;
    int dp[10][10] = {};
    REP(i, 10) dp[0][i] = 1;
    REP1(i, 9){
        REP(j, 10){
            if(j > 0) dp[i][j] += dp[i-1][j-1];
            dp[i][j] += dp[i-1][j];
            if(j < 9) dp[i][j] += dp[i-1][j+1];
            
        }
    }
    /*
    REP(i, 10){
        REP(j, 10){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    */
    int rui[10][10] ={};
    int pre = 0;
    REP(i, 10){
        REP1(j, 9){
            rui[i][j] += dp[i][j] + pre;
            pre = rui[i][j];
        }
    }
    /*
    REP(i, 10){
        REP(j, 10){
            cout << rui[i][j] << " ";
        }
        cout << endl;
    }
    */

    int target = n,now = 0, keta = 0;
    //cout << dp[1][1] + dp[1][2] << endl;
    //while (target > 0)
    
    for (int i = 0; i <= 9; i++){
        REP1(j, 9){
            if(rui[i][j] >= target){
                ans += pow(10, i) * (j);
                if(j > 1) target -= rui[i][j-1];
                else target -= rui[i-1][9];
                // cout << ans << " " << target << endl;
                keta = i;
                now = j;
                break;
            }
        }
        if(ans!=0) break;
    }
    for (int i = keta-1; i >= 0; i--){
        for(int j = max(0, now - 1); j <= min(9, now + 1); j ++){
            if(target > dp[i][j]){
                target -= dp[i][j];
            }
            else
            {
                ans += pow(10, i) * (j);
                now = j;
                // cout << ans << " " << target << endl;
                break;
                
            }
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import deque
k = int(input())
que = deque([1,2,3,4,5,6,7,8,9])
for i in range(k):
    ans=que.popleft()
    if ans%10!=0:
        que.append(10*ans+ans%10-1)
    que.append(10*ans+ans%10)
    if ans%10!=9:
        que.append(10*ans+ans%10+1)
print(ans)


Measured memory_bytes: 40816
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;

namespace abc_99.c
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            const int nmax = 100001;
            var list = new List<int>();
            list.Add(1);

            /* 100000を超えない6の累乗の数を入れてく */
            int tmp=6;
            int cnt=1;
            while(Pow(tmp,cnt)<=100000){
                list.Add((int)Pow(tmp,cnt));
                cnt++;
            }

            /* 100000を超えない9の累乗の数を入れてく */
            tmp=9;
            cnt=1;
            while(Pow(tmp,cnt)<=100000){
                list.Add((int)Pow(tmp,cnt));
                cnt++;
            }

            //コイン問題dp
            int[] dp = new int[nmax];
            for(int i=0; i<nmax; i++)dp[i] = int.MaxValue;
            dp[0] = 0;

            for(int i=0; i<list.Count; i++){
                for(int j=0; j+list[i] <= n; j++){
                    dp[j+list[i]] = Min(dp[j+list[i]], dp[j]+1);
                }
            }
            WriteLine(dp[n]);
        }

        /// 値のスワップ
        static void Swap<T>(ref T lhs, ref T rhs)
        {
            T temp;
            temp = lhs;
            lhs = rhs;
            rhs = temp;
        }


    }
}

Measured memory_bytes: 13124
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main() {
    string s,t;
    cin >> s >> t;
    vector<int> start(26,-1);
    vector<int> goal(26,-1);
    for(int i = 0; i < s.size();i++){
        int a = s[i] - 'a';
        int b = t[i] - 'a';
        if(start[a] != -1 || goal[b] != -1){
            if(start[a] != b || goal[b] != a){
                cout << "No" << endl;
                return 0;
            }
        }
        start[a] = b;
        goal[b] = a;
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define rep(i, n) for (int i = 0; i <= (int)(n); i++)

int main(){
	
    
   int x,y,z;
   cin >> x >> y >> z;
   cout << z << " " << x << " " << y ;
    return 0;

}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n;
	cin >> n;
	vll x(n);
	for (ll i = 0; i < n; i++) cin >> x[i];

	vll v = x;
	sort(all(v));
	ll l = v[n / 2 - 1], r = v[n / 2];
	for (ll i = 0; i < n; i++) {
		if (x[i] <= l) cout << r << endl;
		else cout << l << endl;
	}
}


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

bool canDoit(string &s,int k) {
   queue<int> q;
   for(int i=0;i<s.size();++i) {
      int bit = s[i]-'0';
      int pos = q.size()%2;

      if(i + k-1 >= s.size()) {
         if(bit^pos) {
            if(q.size()==0) {
               return false;
            }
            if(q.front() +k<=i) {
               q.pop();
            } else {
               return false;
            }
         }
      } else {
         if( bit^pos) {
            q.push(i);
         } else {
            q.push(i);
            q.push(i);
         }
      }
   }
   return true;
}
void solve() {
   string s;
   cin>>s;
   int l = 1,r = s.size(),mid;
   while(l<r) {
      mid = (l+r+1)/2;
      if(canDoit(s,mid)) {
         l = mid;
      } else {
         r = mid-1;
      }
   }
   printf("%d\n", l);
}

int main() {
   //freopen("input.txt","r",stdin);
   solve();
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	// ios::sync_with_stdio(false);
	// cin.tie(0);
	double n, m, d;
	scanf("%lf%lf%lf", &n, &m, &d);
	printf("%0.10lf\n", (d==0 ? n : 2*(n-d))*(m-1)/(n*n));
	return 0;
}


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

#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define abs(x) (((x)<0)?(-(x)):(x))

using namespace std;

int main(){
    int a=0,b=0,c=0,d=0;
    for(int i=0;i<4;i++){
        int k; cin >> k;
        if(k==1){
            a++;
        }
        else if(k==9){
            b++;
        }
        else if(k==7){
            c++;
        }
        else if(k==4){
            d++;
        }
        else{
            cout << "NO";
            return 0;
        }
    }
    
    if(a==1 && b==1 && c==1 && d==1){
        cout << "YES";
    }
    else{
        cout << "NO";
    }
    
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

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

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    let mut a = get!([usize]);

    if a.iter().all(|&e| e == 0) {
        println!("Yes");
        return;
    }

    if n%3 > 0 {
        println!("No");
        return;
    }

    a.sort();
    let mut avec = vec![Vec::new(); 3];
    avec[0] = a.drain(0..n/3).collect::<Vec<_>>();
    avec[1] = a.drain(0..n/3).collect::<Vec<_>>();
    avec[2] = a;
    
    if !avec.iter().all(|ref e| e.iter().all(|&v| v == e[0])) {
        println!("No");
        return;
    }

    if avec[0][0] ^ avec[1][0] == avec[2][0] {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 10620
(* O(h w) *)
let h, w = Scanf.scanf " %d %d" @@ fun a b -> a, b
let sss = Array.init h @@ fun _ -> Scanf.scanf " %s" @@ fun s -> s
let _ =
  for i = 0 to h - 1 do
    for j = 0 to w - 1 do
      if sss.(i).[j] = '#' then
        let is_ok = ref false in
        let f (dy, dx) =
          let y, x = i + dy, j + dx in
          if 0 <= y && y < h && 0 <= x && x < w && sss.(y).[x] = '#' then is_ok := true in
        List.iter f [-1, 0; 0, -1; 1, 0; 0, 1];
        if not !is_ok then (print_endline "No"; exit 0)
    done
  done;
  print_endline "Yes"

Measured memory_bytes: 768
n = int(input())
strings = []
for _ in range(n):
    strings.append(input())

end_a = 0
start_b = 0
end_a_start_b = 0
for s in strings:
    if s[0] == 'B':
        start_b += 1
    if s[-1] == 'A':
        end_a += 1
    if s[0] == 'B' and s[-1] == 'A':
        end_a_start_b += 1

if end_a_start_b == 0:
    ans = min(end_a, start_b)
else:
    ans = end_a_start_b - 1
    ans += int(end_a - end_a_start_b > 0) + int(start_b - end_a_start_b > 0)
    ans += max(min(end_a - end_a_start_b - 1, start_b - end_a_start_b - 1), 0)


for s in strings:
    ans += s.count('AB')

print(ans)


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

int main() {
    int n;
    cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (i%3 == 0 || i%5 == 0) continue;
        else ans += i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m, q;
	cin >> n >> m >> q;
	vvi v(n+1, vi(n, 0));
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		v[a+1][b]++;
	}
	REP(i, n)REP(j, n-1)v[i][j + 1] += v[i][j];
	REP(i, n)REP(j, n) {
		v[i + 1][j] += v[i][j];
	}

	REP(i, q) {
		int a, b;
		cin >> a >> b;
		cout<< v[b][b-1] - v[a - 1][b-1] << endl;
	}

}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1000000007;

int quickpow(int x,int y)
{
	long long res=1,base=x;
	while(y)
	{
		if(y&1) res*=base,res%=mod;
		y>>=1; base*=base,base%=mod;
	}
	return res;
}
int inv(int x){return quickpow(x,mod-2);}

int prod[1000001];
int iprod[1000001];
int c(int n,int m){return 1ll*prod[n]*iprod[n-m]%mod*iprod[m]%mod;}

int solve2(int n,int m,int s,int l,int r)
{
	s-=m*r;
	if(s<0) return 0;
	int ans=0;
	for(int i=0;i<=n-m&&s-i*l>=0;i++)
	{
		ans=ans+1ll*((i%2==0)?1:-1)*c(s-i*l+n,n)*c(n-m,i)%mod;
		ans%=mod;
	}
	return 1ll*(ans+mod)*c(n,m)%mod;
}

int solve(int n,int m,int s)
{
	int ans=c(s+n,n);
	for(int i=0;i<=s;i++)
		ans=(ans-solve2(n,m,s,i,i)+solve2(n,m,s,i,i+1))%mod;
	return 1ll*(ans+mod)%mod%mod;
}
signed main()
{
	int n,m,l,r;
	scanf("%lld%lld%lld%lld",&n,&m,&l,&r);
	
	prod[0]=1,iprod[0]=1;
	for(int i=1;i<=1000000;i++)
	{
		prod[i]=1ll*prod[i-1]*i%mod;
		iprod[i]=inv(prod[i]);
	}
	printf("%lld",(solve(n,m,r)-solve(n,m,l-1)+mod)%mod);
	return 0;
}


Measured memory_bytes: 15872
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[] ls = new int[N];

        for (int i=0; i<N; i++) {
            ls[i] = sc.nextInt();
        }
        Arrays.sort(ls);

        int sum = 0;
        for (int i=0; i<K; i++) {
            sum += ls[N-1-i];
        }
        System.out.println(sum);
    }
}



Measured memory_bytes: 24276
<?php
$result = array();
while(true){
    $array = explode(' ', trim(fgets(STDIN)));
    if($array[0] == 0 && $array[1] == 0){
        break;
    }else{
        sort($array);
        $result[] = implode(' ', $array);
    }
}
echo implode("\n", $result);
?>

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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n,a,b;
  scanf("%d%d%d",&n,&a,&b);
  printf("%d %d\n",MIN(a,b),MAX(0,a+b-n));
}

int main(void){
  run();
  return 0;
}


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

using namespace std;

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

const int N = 1e5 + 5;
const int M = 4000;

int n, k;
int a[M][M];

int f(int x, int y) {
	if(x < 0 or y < 0)
		return 0;
	return a[x][y];
}

int f(int x1, int y1, int x2, int y2) {
	return f(x2, y2) - f(x2, y1 - 1) - f(x1 - 1, y2) + f(x1 - 1, y1 - 1);
}

int main() {

	scanf("%d %d", &n, &k);

	for(int i = 1; i <= n; i++) {
		int x, y;
		char c;
		scanf("%d %d %c", &x, &y, &c);
		x%=2*k;
		y%=2*k;
		if(c == 'W') {
			a[x][y]++;
		}
		else {
			a[(x+k)%(2*k)][y]++;
		}
	}

	int t=k<<1;

	for(int i = 0; i < 2 * k; i++) {
		for(int j = 0; j < 2 * k; j++) {
			// printf("%d ", a[i][j]);
			a[i+t][j]=a[i][j+t]=a[i+t][j+t]=a[i][j];
		}
	}

	for(int i = 0; i < M; i++) {
		for(int j = 0; j < M; j++) {
			a[i][j] += f(i - 1, j) + f(i, j - 1) - f(i - 1, j - 1);
		}
	}

	int ans = 0;

	for(int i = 0; i < 2 * k; i++) {
		for(int j = 0; j < 2 * k; j++) {
			int res = 0;
			res += f(i, j, i + k - 1, j + k - 1);
			res += f(i + k, j + k, i+k+k-1,j+k+k-1);
			if(res > ans) {
				ans = res;
				// printf("i = %d j = %d res = %d\n", i, j, res);
			}
		}
	}

	printf("%d\n", ans);

    return 0;

}



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

#define za ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod %1000000007
#define moz 1000000007
#define nl "\n"
#define S second
#define F first
#define PB push_back
#define MP make_pair
#define V vector
//#define P pair
#define LEN length()
#define SZ size()
#define loop(i,a,b) for(int i=(a);i<=(b);i++)
typedef long long ll;
typedef complex<ll> P;
#define X real()
#define Y imag()


int main()
{
    za ;
    int a, b;
    cin >> a >> b ;
    cout << max(0,a-b) << nl;
}


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

int main(){
  int sum=0;
  int n,i,j;
  cin >> n;
  int a[n+2];
  a[0]=0;
  a[n+1]=0;
  for(i=1;i<=n;i++){
    cin >> a[i];
    sum+=abs(a[i]-a[i-1]);
  }
  sum+=abs(a[i]-a[i-1]);
  for(i=1;i<=n;i++){
    cout << sum - abs(a[i-1]-a[i]) - abs(a[i] - a[i+1]) + abs(a[i-1] - a[i+1]) << endl;
  }
  return 0;
}


Measured memory_bytes: 1664
import collections
n=int(input())
t = list(map(int,input().split()))
fir = []
sec = []
for i in range(n): 
    if (i+1)%2==1:
        fir.append(t[i])
    else:
        sec.append(t[i])
f = collections.Counter(fir)
s = collections.Counter(sec)
#print(f)
if len(list(set(t))) == 1:
    print(n-len(sec))
elif f.most_common()[0][0] == s.most_common()[0][0]:
    print(min(n-f.most_common()[0][1]-s.most_common()[1][1], n-f.most_common()[1][1]-s.most_common()[0][1]))
else:
    print(n-f.most_common()[0][1]-s.most_common()[0][1])

Measured memory_bytes: 77444
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using vv = vector<V<T>>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  int n,k;
  cin >> n >> k;
  cout << (n-1+k-2)/(k-1) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	int n,m;
	cin>>n>>m;
	vector<ll>x(n),y(n),z(n);
	for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>z[i];
    vector<pair<ll, ll>> p1(n),p2(n),p3(n),p4(n),p5(n),p6(n),p7(n),p8(n);
    for(int i=0;i<n;i++) p1[i] = make_pair(x[i] + y[i] + z[i], i);
    for(int i=0;i<n;i++) p2[i] = make_pair(-x[i] + y[i] + z[i], i);
    for(int i=0;i<n;i++) p3[i] = make_pair(x[i] - y[i] + z[i], i);
    for(int i=0;i<n;i++) p4[i] = make_pair(x[i] + y[i] - z[i], i);
    for(int i=0;i<n;i++) p5[i] = make_pair(-x[i] - y[i] + z[i], i);
    for(int i=0;i<n;i++) p6[i] = make_pair(x[i] - y[i] - z[i], i);
    for(int i=0;i<n;i++) p7[i] = make_pair(-x[i] + y[i] - z[i], i);
    for(int i=0;i<n;i++) p8[i] = make_pair(-x[i] - y[i] - z[i], i);
    
    sort(p1.begin(),p1.end());
    reverse(p1.begin(),p1.end());
    sort(p2.begin(),p2.end());
    reverse(p2.begin(),p2.end());
    sort(p3.begin(),p3.end());
    reverse(p3.begin(),p3.end());
    sort(p4.begin(),p4.end());
    reverse(p4.begin(),p4.end());
    sort(p5.begin(),p5.end());
    reverse(p5.begin(),p5.end());
    sort(p6.begin(),p6.end());
    reverse(p6.begin(),p6.end());
    sort(p7.begin(),p7.end());
    reverse(p7.begin(),p7.end());
    sort(p8.begin(),p8.end());
    reverse(p8.begin(),p8.end());
 
 
    vector<vector<ll>> ans(8,vector<ll>(3));
    for(int i=0;i<m;i++)
    {
        vector<ll>ind(8);
        ind[0] = p1[i].second;
        ind[1] = p2[i].second;
        ind[2] = p3[i].second;
        ind[3] = p4[i].second;
        ind[4] = p5[i].second;
        ind[5] = p6[i].second;
        ind[6] = p7[i].second;
        ind[7] = p8[i].second;
        for(int j=0;j<8;j++)
        {
            ans[j][0] += x[ind[j]];
            ans[j][1] += y[ind[j]];
            ans[j][2] += z[ind[j]];
        }
    }
    vector<ll>res(8);
    for(int i=0;i<8;i++)
    {
        res[i] = abs(ans[i][0]) + abs(ans[i][1]) + abs(ans[i][2]);
    }
    sort(res.begin(),res.end());
    cout<<res[7]<<"\n";

}
	


Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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;
}

signed main() {
  ll N;
  cin >> N;
  vll a(N);
  rep(i, N) {
    cin >> a[i];
  }

  ll cursor = 1;
  ll count = 0;
  rep(i, N) {
    if (a[i] != cursor) {
      count++;
    } else {
      cursor++;
    }
  }

  if (cursor == 1) {
    COUT(-1);
  } else {
    COUT(count);
  }

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
#define ci(n,a)   vi a(n); rep(i,(n)) cin>>a[i];
#define rep(i,n)  for(ll i = 0; i < (n); ++i)
#define red(i,n)  for(ll i = (n)-1; i >= 0; --i)
#define all(a)    begin(a),end(a)
#define pb(a)     push_back(a)
#define mp(a,b)   make_pair(a,b)
#define yn(a)     cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll INF = 1e9+7, LINF = 1e18;

const ll M = 100000;

int main()
{
    ll n;
    cin>>n;
    ll a[n],b[n];
    rep(i,n){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    rep(i,n){
        if(a[i]==b[n-1])cout<<b[n-2];
        else cout<<b[n-1];
        cout<<"\n";
    }

    return 0;
}


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

bool memo[7368792];

using namespace std;

int main() {
  while (true) {
    int m, n;
    cin >> m >> n;
    if (m + n == 0) {
      break;
    }

    memset(memo, 0, sizeof(memo));

    int a = m;

    int count = 0;
    while (count < n) {
      if (memo[a] == true) {
        a++;
        continue;
      }
      count++;
      memo[a] = true;
      for (int j = 1; ; j++) {
        if (a * j >= sizeof(memo)) {
          break;
        }
        memo[a * j] = true;
      }
      a++;
    }

    for (int i = 0; i < sizeof(memo); i++) {
      if (memo[i] == true) {
        break;
      }
      memo[i] = true;
    }

    for (int i = 0; i < sizeof(memo); i++) {
      if (memo[i] == false) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}

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


int n,ans;
int a[10],a2[10];
void solve(int i,int B[],int ct){
  int b[10];
  rep(j,n){
    b[j]=B[j];
  }
  // rep(j,i) cout<<" ";
  int c=b[i];
  if(i==n){ans=min(ans,ct);}
  else{
    if(b[i]!=0){
      ct++;
      repi(j,i,n){
	b[j]-=c;
	b[j]%=10;
	//cout<<b[0]<<b[1]<<b[2]<<" "<<ct<<endl;
	solve(i+1,b,ct);
      }
    }
    else{
      //cout<<b[0]<<b[1]<<b[2]<<" "<<ct<<endl;
      solve(i+1,b,ct);
    }
  }
}


int main(){
  string s1,s2;
  while(1){
    cin>>n;
    if(n==0) break;
    ans=BIG;
    cin>>s1>>s2;
    rep(i,n){
      a[i]=s1[i]-s2[i];
    }
   
    solve(0,a,0);
    cout<<ans<<endl;
  }
  return 0;
}









Measured memory_bytes: 3016
from sys import stdin
N,A,B=[int(x) for x in stdin.readline().rstrip().split()]
if N==A and A==B and B==N:
    print(N,N)
else:
    if A > B:
        if (A+B) > N:
            print(B,(A+B)-N)
        else:
            print(B,0)
    else:
        if (A+B) > N:
            print(A,(A+B)-N)
        else:
            print(A,0)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iomanip>
using namespace std;
typedef long long ll;

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

    vector<int> p2;

    for (int i = 0; pow(2, i) < 1e6; i++) {
        if (n == pow(2, i)) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    vector<pair<int, int> > ans;
    for (int i = 0; i < (n - 1) / 2; i++) {
        ans.emplace_back(n + (i + 1) * 2, (i + 1) * 2 + 1);
        ans.emplace_back(1, (i + 1) * 2 + 1);
        ans.emplace_back(1, (i + 1) * 2);
        ans.emplace_back((i + 1) * 2, n + (i + 1) * 2 + 1);
    }

    if (n % 2 == 1) ans.emplace_back(n + 1, 2 * n);
    else {
        ans.emplace_back(n + 3, n + 1);
        /* ans.emplace_back(n - 1, n);
        ans.emplace_back(2, 2 * n);*/

        for (int i = 2; i <= n; i++) {
            if (((n - 2) ^ i) == n) {
                ans.emplace_back(n - 1, n);
                ans.emplace_back(i, 2 * n);
                break;
            }
        }
    }



    for (int i = 0; i < ans.size(); i++) 
    cout << ans[i].first << " " << ans[i].second << endl;
    
    //cout << (10 ^ 2) << endl;
}

/*
g++ -std=c++14 agc035/c.cpp
 */

Measured memory_bytes: 3952
n = int(input())
p = [int(input()) for i in range(n)]

q = [0 for _ in range(n)]
for i in range(n):
    q[p[i]-1] = i
q.append(-1)

ans = 0
count = 1
for i in range(1, n+1):
    if q[i-1] < q[i]:
        count += 1
    else:
        ans = max(ans, count)
        count = 1

print(n-ans)

Measured memory_bytes: 24644
eval'N,K,*A='+`dd`.split*?,
A.sort!
b=s=K%2<1?1:A.pop
(K/2).times{x=A[0]*A[1]
s*=x*b>b*A[-1]*A[-2]?(A.shift 2
x):A.pop*A.pop
s%=10**9+7}
p s

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Modulo Summation
            int n = int.Parse(Console.ReadLine());
            var numbers = ReadLine();
            
            int sum = numbers.Sum() - n;
            
            Console.WriteLine(sum);
        }
        
        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 13340
N = int(input())
P = [float(i) for i in input().split()]

dp = [0.0] * (N + 1)
dp[0] = 1.0

for i, p in enumerate(P, 1):
    dp = [p * dp[j - 1] + (1 - p) * dp[j] for j in range(N + 1)]

print(sum(dp[-(-N // 2):]))

Measured memory_bytes: 44764
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b+c>21)pr("bust");
    else pr("win");
}

Measured memory_bytes: 256
fun main (args: Array<String>) {
  val (n, m) = readLine()!!.split(' ').map(String::toInt)
  val a = readLine()!!.split(' ').map(String::toInt)
  val b = a.sum().toDouble() / (4 * m).toDouble()
  println(if (a.filter { it.toDouble() >= b }.count() >= m) "Yes" else "No")
}

Measured memory_bytes: 38156
import sys
sys.setrecursionlimit(10**9)

class Node:
    def __init__(self):
        self.p = -1
        self.l = -1
        self.r = -1

n = int(input())
T = [Node() for _ in range(n)]
D = [0]*n

def rec(u,p):
    D[u] = p
    if T[u].r != -1: rec(T[u].r,p)
    if T[u].l != -1: rec(T[u].l,p+1)

def printinfo(u):
    clst = []
    c = T[u].l
    while c != -1:
        clst.append(c)
        c = T[c].r
    if T[u].p == -1: ntype = "root"
    elif T[u].l == -1: ntype = "leaf"
    else: ntype = "internal node"
    print("node {}: parent = {}, depth = {}, {}, {}".format(u,T[u].p,D[u],ntype,clst))

for i in range(n):
    inp = [int(i) for i in input().split()]
    v = inp[0]
    d = inp[1]
    C = inp[2:]
    for j in range(d):
        c = C[j]
        if j == 0: T[v].l = c
        else: T[l].r = c
        l = c
        T[c].p = v
for i in range(n):
    if T[i].p == -1: r = i

rec(r,0)
for i in range(n): printinfo(i)


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    string O, E;
    cin >> O >> E;

    int N = (int)O.size() + (int)E.size();

    string ans;
    for (int i = 0; i < N; i++) {
        if ((i & 1) == 0)
            ans += O[i / 2];
        else
            ans += E[i / 2];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/*
 A Submission by $%U%$
 at time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FILE_IN "text.out"
#define FILE_OUT "result.out"
#define ofile freopen(FILE_IN,"r",stdin);freopen(FILE_OUT,"w",stdout)
#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define nfio cin.tie(0);cout.tie(0)
#define max(x,y) (((x)>(y))?(x):(y))
#define min(x,y) (((x)<(y))?(x):(y))
#define ord(a,b,c) ((a>=b)and(b>=c))
#define MOD (ll(1000000007))
#define MAX 300001
#define mag 320
#define p1 first
#define p2 second.first
#define p3 second.second
#define fi first
#define se second
#define pow2(x) (ll(1)<<x)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define piii pair<int,pii>
#define For(i,__,___) for(int i=__;i<=___;i++)
#define Rep(i,__,___) for(int i=__;i>=___;i--)
#define ordered_set tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update>
#define bi BigInt
#define pi 3.1415926535897
typedef long long ll;
//------------xúc xích normie tám muoi tám phan tram não----------//
ll n,m,k,l[200001],r[200001],s[200001],t,t1,i,j,minn,maxx,cur,lu,lv,res=1e18;
ll arr[200001];
ll bs1 (ll l, ll r)
{
	if (l==r) return l;
	ll mid=(l+r)/2;
	if (double(s[mid])>=double(s[i])/2) return bs1(l,mid); else return bs1(mid+1,r);
}
ll bs2 (ll l, ll r)
{
	if (l==r) return l;
	ll mid=(l+r)/2;
	if (double(s[mid])>=double(s[n]+s[i])/2) return bs2(l,mid); else return bs2(mid+1,r);
}
int main() {
//	ofile;
	fio;
	cin>>n;
	for (i=1;i<=n;i++){
	cin>>arr[i]; s[i]=s[i-1]+arr[i];}
	for (i=2;i<=n-2;i++)
	{
		ll x=bs1(0,i);
		ll y=x-1;
//		cout<<x<<' '<<y<<endl;
		if (x>=i) l[i]=y;
		else if (y<=0) l[i]=x;
		else if (s[x]-double(s[i])/2<double(s[i]/2)-s[y]) l[i]=x;
		else l[i]=y;
		 x=bs2(i,n);
		 y=x-1;
//		cout<<x<<' '<<y<<endl;
		if (x>=n) r[i]=y;
		else if (y<=i) r[i]=x;
		else if (s[x]-double(s[n]+s[i])/2<double(s[n]+s[i])/2-s[y]) r[i]=x;
		else r[i]=y;
		x=s[l[i]];
		y=s[i]-s[l[i]];
		ll z=s[r[i]]-s[i];
		ll t=s[n]-s[r[i]];
		ll aa=max(max(x,y),max(z,t));
		ll bb=min(min(x,y),min(z,t));
		res=min(res,aa-bb);
//		cout<<i<<' '<<l[i]<<' '<<r[i]<<endl;
	}
	cout<<res;
}


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

int main()
{
  int n;
  std::cin >> n;
  std::vector<int> a(n), b(n), c(n-1);

  for (int i=0 ; i<n ; i++) {
    std::cin >> a[i];
  }
  for (int i=0 ; i<n ; i++) {
    std::cin >> b[i];
  }
  for (int i=0 ; i<n-1 ; i++) {
    std::cin >> c[i];
  }
  
  int s = 0;
  for (int i=0 ; i<n ; i++) {
    s += b[a[i] - 1];
    if (i<n-1 && a[i+1] == a[i]+1) {
      s += c[a[i] - 1];
    }
  }
  std::cout << s << std::endl;
  return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<string> vs;
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  string s;
  cin >> s;

  int c = 0, t = 0;
  re(i, s.size()) {
    if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
      c++;
    } else {
      c = 0;
    }
    t = max(c, t);
  }

  cout << t << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main()
{
	ll a, b; cin >> a >> b;
	ll s = 100;
	char m[100][100] = {};
	rep(i, 0, s / 2)rep(j, 0, s) m[i][j] = '.';
	rep(i, s / 2, s)rep(j, 0, s) m[i][j] = '#';

	b--;
	rep(i, 0, s) {
		if (!b)break;
		rep(j, 0, s) {
			if (!b)break;
			if (!(i & 1) && j & 1) {
				m[i][j] = '#';
				b--;
			}
		}
	}

	a--;
	rep(i, s / 2 + 1, s) {
		if (!a)break;
		rep(j, 0, s) {
			if (!a)break;
			if (!(i & 1) && j & 1) {
				m[i][j] = '.';
				a--;
			}
		}
	}

	cout << 100 << " " << 100 << endl;
	rep(i, 0, s) {
		rep(j, 0, s)cout << m[i][j];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
 
#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)
 
ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
void oi(ll x){ cout << x << " "; }
void od(ld x){ cout << fixed << setprecision(10) << x << " "; }
void os(string x){ cout << x; }
void oie(ll x){ cout << x << endl; }
void ode(ld x){ cout << fixed << setprecision(10) << x << endl; }
void ose(string x){ cout << x << endl; }
void oe(){ cout << endl; }

int main(){
    ll X=ii(),Y=ii(),A=ii(),B=ii(),C=ii(); 
    vector<ll> p,q,r; 
    REP(i,0,A) p.push_back(ii());
    REP(i,0,B) q.push_back(ii());
    REP(i,0,C) r.push_back(ii());
    sort(p.begin(),p.end(),greater<ll>());
    copy(p.begin(),p.begin()+X,back_inserter(r));
    sort(q.begin(),q.end(),greater<ll>());
    copy(q.begin(),q.begin()+Y,back_inserter(r));
    sort(r.begin(),r.end(),greater<ll>());
    oie(accumulate(r.begin(),r.begin()+X+Y,0LL));

    return 0;
}


Measured memory_bytes: 8048
#include<iostream>
#include<algorithm>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int N;
P AB[200000];

int main() {
	
	cin >> N;
	for (int i = 0; i < N; i++)cin >> AB[i].second >> AB[i].first;
	sort(AB, AB + N);
	
	ll T = 0;
	for (int i = 0; i < N; i++) {
		T += AB[i].second;
		if (T > AB[i].first) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

typedef vector<int> vi;
typedef greater<int> gi;

int main() {
  int N;
  cin >> N;
  vector<int> a(3 * N);
  REP(i, 3 * N) cin >> a[i];
  priority_queue<int, vi, gi> que1;
  vector<ll> l(3 * N);
  ll sum = 0;
  REP(i, 3 * N) {
    sum += a[i];
    que1.push(a[i]);
    while (N < que1.size()) {
      sum -= que1.top();
      que1.pop();
    }
    l[i] = sum;
  }
  priority_queue<int, vi> que2;
  vector<ll> r(3 * N);
  sum = 0;
  RREP(i, 3 * N) {
    sum += a[i];
    que2.push(a[i]);
    while (N < que2.size()) {
      sum -= que2.top();
      que2.pop();
    }
    r[i] = sum;
  }
  ll ans = -1 * 1e15;
  for (int k = N - 1; k < 2 * N; ++k) ans = max(ans, l[k] - r[k + 1]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7288
// AUTHOR: ROSHAN SRIVASTAVA
// WEBSITE: https://www.youtube.com/channel/UC6uQdd7kLLOdlHSVklhV7Cw

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int n; 

int dp[2009];

int solve(int s) {
	if(s < 0) return 0;
	if(s == 0) return 1;

	if(dp[s] != -1)
		return dp[s];

	int ans = 0;
	for(int i = 3; i <= s; i++){
		ans += solve(s - i) % mod;
		ans %= mod;
	}

	return dp[s] = ans;
}

int main(){

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

	memset(dp, -1, sizeof dp);

	cin >> n;

	cout << solve(n) % mod << endl;

	return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define INF (1 << 30)
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
const long long mod = 1e9+7;

using namespace std;
using ll = __int64_t;
using ull = unsigned long long;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int DX[] = {1, 1, 0, -1, -1, -1, 0, 1};
int DY[] = {0, -1, -1, -1, 0, 1, 1, 1};

bool comp(const pair<int, ll>& p1, const pair<int, ll>& p2){
    return p1.second > p2.second;
}

void solve(){
    int n, x, res=0;
    int l[100], d[100];
    cin >> n >> x;
    for(int i = 0; i < n; i++){
        cin >> l[i];
    }
    d[0] = 0;
    for(int i = 1; i <= n; i++){
        d[i] = d[i-1] + l[i-1];
    }
    for(int i = 0; i <= n; i++){
        if(d[i] <= x){
            res++;
        }
    }
    cout << res << endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pi>
#define vpl vector<pl>
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005
using namespace std;
const int maxn = 1e5 + 100;
int dp[maxn], h[maxn];
int32_t main() 
{
	ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#ifdef LOCAL_DEFINE
	ifstream cin("input.txt");
#endif
	int N;
	cin >> N;
	for (int i = 1; i <= N; i++)cin >> h[i];
	dp[1] = 0;
	for (int i = 2; i <= N; i++)
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), 
			i == 2 ? INF : dp[i - 2] + abs(h[i] - h[i - 2]));
	cout << dp[N] << "\n";
}


Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	for i := range a {
		if i > 0 {
			fmt.Printf(" ")
		}
		fmt.Printf("%d", a[len(a)-1-i])
	}
	fmt.Printf("\n")
}



Measured memory_bytes: 1128