akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;
using UL = unsigned int;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(UL i=0; i<n; i++)

string QL = "NESW";
UL to[4][6] = {
	{ 4, 0, 2, 3, 5, 1 },
	{ 2, 1, 5, 0, 4, 3 },
	{ 1, 5, 2, 3, 0, 4 },
	{ 3, 1, 0, 5, 4, 2 }
};

UL C[6];

int main(){
	rep(i, 6) cin >> C[i];
	string S; cin >> S;
	for (char c : S){
		UL tmp[6];
		UL q = QL.find(c);
		rep(i, 6) tmp[to[q][i]] = C[i];
		rep(i, 6)C[i] = tmp[i];
	}
	cout << C[0] << endl;
	return 0;
}


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


class UnionFind {
    std::vector<int> p;

public:
    UnionFind(int n) : p(n, -1) {}

    int root(int x) { return p[x] < 0 ? x : p[x] = root(p[x]); }

    bool same(int x, int y) { return root(x) == root(y); }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (p[y] < p[x]) std::swap(x, y);
        if (p[x] == p[y]) --p[x];
        p[y] = x;
        return true;
    }
};

int main() {
    int n, m;
    while (cin >> n >> m && n) {
        UnionFind uf(n);
        bool hasLoop = false;
        vector<int> deg(n, 0);
        for (int i = 0; i < m; i++) {
            int a, b;
            cin >> a >> b;
            --a, --b;
            deg[a]++;
            deg[b]++;
            hasLoop |= !uf.unite(a, b);
        }
        if( *max_element(deg.begin(), deg.end()) > 2 || hasLoop ){
            cout << "no" << endl;
        }else{
            cout << "yes" << endl;
        }
    }

}


Measured memory_bytes: 3540
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll N,A,B,C;
  cin >> N >> A >> B >> C;
  vector<string> S(N);
  vector<char> a(N);
  rep(i,N){
    cin >> S.at(i);
  }
  rep(i,N){
    if(S.at(i)=="AB"){
      if(i!=N-1&&A==1&&B==1){
        if(S.at(i+1)=="BC"){
          A--;
          B++;
          a.at(i)='B';
        }else{
          A++;
          B--;
          a.at(i)='A';
        }
      }else if(A==0&&B==0){
        cout <<"No" << endl;
        return 0;
      }else if(A>=B){
        A--;
        B++;
        a.at(i)='B';
      }else{
        A++;
        B--;
        a.at(i)='A';
      }
    }else if(S.at(i)=="BC"){
      if(i!=N-1&&B==1&&C==1){
        if(S.at(i+1)=="AB"){
          B++;
          C--;
          a.at(i)='B';
        }else{
          B--;
          C++;
          a.at(i)='C';
        }
      }else if(C==0&&B==0){
        cout <<"No" << endl;
        return 0;
      }else if(C>=B){
        C--;
        B++;
        a.at(i)='B';
      }else{
        C++;
        B--;
        a.at(i)='C';
      }
    }else{
      if(i!=N-1&&A==1&&C==1){
        if(S.at(i+1)=="BC"){
          A--;
          C++;
          a.at(i)='C';
        }else{
          A++;
          C--;
          a.at(i)='A';
        }
      }else if(A==0&&C==0){
        cout <<"No" << endl;
        return 0;
      }else if(A>=C){
        A--;
        C++;
        a.at(i)='C';
      }else{
        A++;
        C--;
        a.at(i)='A';
      }
    }
  }
  cout << "Yes" << endl;
  rep(i,N){
    cout << a.at(i) << endl;
  }
}
        

Measured memory_bytes: 6432
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<vector<int>> num(N,vector<int>(2));
    for(int i = 0;i < N;i++){
      for(int j = 0;j < 2;j++){
        cin >> num[i][j];
      }
    }
  int sum = 0;
   for(int i = 0;i < N;i++){
        sum += num[i][1] - num[i][0] + 1;
   }
  
  cout << sum << endl;
  
  
   
}

Measured memory_bytes: 3640
<?php
    $input_lines = trim(fgets(STDIN));
    $input_lines = str_replace("g","0",$input_lines);
    $input_lines = str_replace("p","1",$input_lines);
    $sIn = str_split($input_lines);
    $iSumInput = array_sum($sIn);
    $iMaxP = (int)floor(count($sIn)/2);
    echo $iMaxP - $iSumInput
?>


Measured memory_bytes: 21064
S=input()
ans='Yes'
O=''
E=''

for i in range(len(S)):
    if i%2==0:
        O+=S[i]
    else:
        E+=S[i]

if 'L' in O:
    ans='No'

if 'R' in E:
    ans='No'

print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::vector<int> primes;
    bool used[100000] = {};
    for (int i = 2; i < 100000; i++) {
        if (used[i]) continue;
        primes.push_back(i);
        int w = i;
        while (w < 100000) {
            used[w] = true;
            w += i;
        }
    }
    int cnt = 0;
    for (int p : primes) {
        if (p % 5 != 1) continue;
        std::cout << p << " \n"[cnt++ == n - 1];
        if (cnt >= n) break;
    }
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
string s;
set<char> st;
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
		st.insert(s[i]);
	if(st.size()==2)
		puts("Yes");
	else	
		puts("No");
	return 0; 
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    string s;
    cin >> s;
    set<char> letras;

    for ( auto l : s ) letras.insert(l);

    cout << (s.size() == letras.size() ? "yes\n" : "no\n");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N, M;
int a, b;
vector <pair<int, int>> ab;
int main(int argc, char* argv[]) {
    scanf("%d %d", &N, &M);
    for(int i = 0; i < M; i++) {
        scanf("%d %d", &a, &b);
        ab.push_back(pair <int, int> (b, a));
    } 
    sort(ab.begin(), ab.end());
    int bridge = ab[0].first - 1;
    int count = 1;
    for(int i = 1; i < M; i++) {
        if(ab[i].second > bridge) {
            bridge = ab[i].first - 1;
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1400
$invNum =0
def merge(left, mid, right)
    leftArr = $arr[left..mid]
    rightArr = $arr[mid+1..right]
    leftArr << 1000000001
    rightArr << 1000000001
    l = r = 0
    (left..right).each {|i|
        if leftArr[l] <= rightArr[r]
            $arr[i] = leftArr[l]
            l += 1
        else
            $arr[i] = rightArr[r]
            r += 1
            $invNum += mid - left - l + 1
        end
    }
end

def mergeSort(left, right)
    mid = (left + right)/2
    if left + 1 < right
        mergeSort(left, mid)
        mergeSort(mid+1, right)
        merge(left, mid, right)
    elsif left + 1 == right
        merge(left, mid, right)
    end
end

N = gets.to_i
$arr = gets.split.map &:to_i
mergeSort(0,N-1)
puts $invNum

Measured memory_bytes: 45892
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
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 << " "  ;p(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {}

int main(void) {
  int p,q,r;cin>>p>>q>>r;
  int max_t=p;
  max_t = max(q,max_t);
  max_t = max(r,max_t);
  pr(p+q+r-max_t);
  return 0;
}


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

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> w(m+1);
	for(int i=0; i<m; i++){
		cin >> w[i];
	}
	w[m] = n+1;
	int q;
	cin >> q;
	vector<int> query(q);
	for(int i=0; i<q; i++){
		cin >> query[i];
	}

	vector<int> loss(n+2,0),num(n+2,0);
	loss[0] += w[0]-1;
	num[0] += m;
	for(int i=0; i<m; i++){
		int len = w[i+1] -w[i];
		loss[0] += len;
		loss[len+1] -= len;
		num[len+1] -= 1;
	}
	for(int i=0; i<n+2; i++){
		loss[i+1] += loss[i];
		num[i+1] += num[i];
	}
	for(int i=0; i<n+2; i++){
		loss[i] -= num[i]*i;
		loss[i] = -loss[i];
	}

	for(int i=0; i<q; i++){
		if(-loss[n+1] > query[i]){
			cout << -1 << endl;
		}else{
			auto itr = lower_bound(loss.begin(), loss.end(), -query[i]);
			int ans = itr -loss.begin();
			cout << max(1, ans) << endl;
		}
	}
	return 0;
}


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

int main() {
  string N;
  int p=0, q;
  cin >> N;
  for (int i=0; i<N.size(); i++) {
    q = (int)N.at(i)-48;
    p += q;
  }
  if (p%9==0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3752
"use strict";
function I(t,i){this._s=t.split("\n"),this._c=0,this._l=0,this._f=i||Number}I.prototype.a=function(t){var i=this._s[this._l];if(i){var s=i.trim().split(" "),h=s[this._c];return this._c++,s.length===this._c&&(this._c=0,this._l++),t?t(h):this._f(h)}},I.prototype.l=function(t){var i=this._s[this._l];if(i)return this._c=0,this._l++,i.split(" ").map(t||this._f)},module.exports=I;

function main(input) {
  var o = new I(input);

  var a = o.a();
  var p = o.a();
  p += 3 * a;
  console.log(Math.floor(p/2));
}


main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 22080
from sys import stdin
N=int(stdin.readline().rstrip())
ans=0
for i in range(1,N+1):
    cnt=0
    for j in range(1,i+1):
        if i % j == 0:
            cnt+=1
    if cnt == 8 and i % 2 != 0:
        ans+=1
print(ans)

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

int serch(char str) {
	if (str == 'I')
		return 1;
	else if (str == 'V')
		return 5;
	else if (str == 'X')
		return 10;
	else if (str == 'L')
		return 50;
	else if (str == 'C')
		return 100;
	else if (str == 'D')
		return 500;
	else
		return 1000;
}
int main() {
	int fron = 0, bac = 0, sum = 0;
	string str;
	while (cin >> str) {
		for (int i = 0; str[i] != '\0'; i++) {
			bac = serch(str[i]);
			if (fron >= bac)
				sum += bac;
			else
				sum += bac - fron * 2;
			fron = bac;
			bac = 0;
		}
		cout << sum << endl;
		sum = 0;
		fron = 0;
	}
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = 0;
    ans = (n/(a+b))*a;
    ll ama = min(n%(a+b), a);
    ans += ama;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
    /*
        Problem URL : http://agc009.contest.atcoder.jp/tasks/agc009_a
        Score  :
        Result :
        Time   : ms
        Memory : KB
     */
 
    ini_set('error_reporting', E_ALL & ~E_NOTICE);
    ini_set('display_errors', 'On');
    // define('DEBUG', true);
    define('DEBUG', false);

    $ans = 0;

    fscanf(STDIN, "%d", $N);
    for ($i = 0; $i < $N; $i++) {
        fscanf(STDIN, "%d %d", $a[$i], $b[$i]);
    }


    for ($i = $N-1; $i >= 0; $i--) {
        // echo "N:{$N}\n";
        // echo $a, $b, PHP_EOL;
        $p = ($a[$i] + $ans) % $b[$i];
        if ($p != 0) {
            $ans += ($b[$i] - $p);
        }
        // echo "{$i} {$ans}\n";
    }

    echo $ans . PHP_EOL;


Measured memory_bytes: 14060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int s = sc.nextInt();
			int a = s / 100;
			int b = s % 100;

			if ((a == 0 && b == 0) || (a == 0 && b > 12) || (a > 12 && b == 0) || (a > 12 && b > 12)) {
				System.out.println("NA");
			} else if ((a == 0 || a > 12) && 1 <= b && b <= 12) {
				System.out.println("YYMM");
			} else if (1 <= a && a <= 12 && (b == 0 || b > 12)) {
				System.out.println("MMYY");
			} else if (1 <= a && a <= 12 && 1 <= b && b <= 12) {
				System.out.println("AMBIGUOUS");
			}
		}
	}
}

Measured memory_bytes: 21332
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

void swap(lli *a, lli *b)
{
  lli tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}


lli modinv(lli a, lli m) {
    lli b = m, u = 1, v = 0;
    while (b) {
        lli t = a / b;
        a -= t * b; swap(&a, &b);
        u -= t * v; swap(&u, &v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(void) {
  lli n, k;
  lli a[MAX];
  scanf("%lld %lld", &n, &k);
  rep(i, 0, n) scanf("%lld", &a[i]);

  qsort(a, n, sizeof(lli), acs);

  lli max = 0, min = 0;
  lli combi = 1;
  rep(ni, k - 1, n) {
    max = (max + (combi * a[ni] % MOD)) % MOD;
    min = (min + (combi * a[n - ni - 1] % MOD)) % MOD;
    combi = (combi * (ni + 1) % MOD) * modinv(ni - k + 2, MOD) % MOD;
  }
  printf("%lld\n", (max - min) % MOD);
  return 0;
}

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

int main(void) {
    int N,M,X,Y;
    cin >> N >> M >> X >> Y;

    vector<int> x(N);
    vector<int> y(M);
    for(int i=0;i<N;i++) {
        cin >> x[i];
    }
    for(int i=0;i<M;i++) {
        cin >> y[i];
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    if((x[x.size()-1] < y[0])
        && (X<y[0])
        && (x[x.size()-1] < Y)
        && X < Y){
        cout << "No War\n";
    } else {
        cout << "War\n";
    }

    return 0;
}


Measured memory_bytes: 256
let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let readln () = read_line () |> split_on_char ' ' |> List.map int_of_string

let find s u =
  let rec doit u =
    if u = s.(u) then u
    else begin
      s.(u) <- doit s.(u);
      s.(u)
    end in
  doit u

let same_p s x y = find s x = find s y

let solve n q =
  let s = Array.init n (fun i -> i) in
  for _ = 0 to q - 1 do
    match readln () with
    | n :: x :: y :: _ ->
      if n = 0 then s.(find s x) <- find s y
      else print_endline (if same_p s x y then "1" else "0")
    | _ -> assert false
  done

let () =
  match readln () with
  | [n; q] -> solve n q
  | _ -> assert false

Measured memory_bytes: 4560
// template version 1.15
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define slice(l, r) substr(l, r-l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
    #include "lib/dump.hpp"
#else
    #define dump(...) 42
    #define dump_1d(...) 42
    #define dump_2d(...) 42
    #define cerrendl 42
#endif
//}}}

signed main() {
    string s;cin>>s;

    int Q;cin>>Q;
    int r = 0;
    bool left = true;
    string sl = "";
    string sr = "";
    rep(q, Q){
        int t;cin>>t;
        if (t==1){
            r++;
            left ^= 1;
        }
        if (t==2){
            int f;cin>>f;
            char c;cin>>c;
            if (f==1){
                if (left) sl+=c;
                else sr+=c;
            }
            if (f==2){
                if (left) sr+=c;
                else sl+=c;
            }
        }
    }

    string ans;
    reverse(all(sl));
    ans += sl;
    ans += s;
    ans += sr;

    if (r%2==1) reverse(all(ans));
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1300
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int h,w;
    cin >> h >> w;
    vector<vector<ll>> dis(10,vector<ll>(10,INF));
    rep(i,10) rep(j,10) cin >> dis[i][j];
    rep(k,10){
        rep(i,10){
            rep(j,10) dis[i][j] = min(dis[i][k] + dis[k][j],dis[i][j]);
        }
    }
    ll ans = 0;
    rep(i,h){
        rep(j,w){
            int a;
            cin >> a;
            if(a==-1) continue;
            ans += dis[a][1];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
from collections import Counter
n = int(input())
l = []
for i in range(n):
  l.append(input())
c = Counter(l)
t = c.most_common()
x = 0
ans = []
for k,v in t:
  if x <= v:
    ans.append(k)
    x = v
ans.sort()
for i in range(len(ans)):
  print(ans[i])

Measured memory_bytes: 121680
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<climits> //INT_MIN/MAX
using namespace std;

#define FOR(i,s,e) for(ll (i)=(s);(i)<(e);(i)++)
#define FORR(i,s,e) for(ll (i)=(s);(i)>(e);(i)--)
#define MOD 1000000007
#define llong long long
#define debug(x) cout<<#x<<": "<<x<<endl
typedef long long ll;
llong N;

/* 2017/01/18 問題 -----  Name/Link ----- */
/* -----解説等-----
問題:


*/

ll ans = 0;
ll x[100001];

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

    ll A, B;
    cin >> N >> A >> B;
    FOR(i, 1, N + 1)
        cin >> x[i];
    FOR(i, 1, N ) {
        ans += min(A*(x[i + 1] - x[i]), B);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=812;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}

int h,w,k;
string s[M+3];
int stx,sty;
int ses=inf;
int dis[M+3][M+3];
bool vis[M+3][M+3];
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int mn(int a,int b,int c,int d,int e)
{
    int ret=min(a,b);
    ret=min(ret,min(c,d));
    ret=min(ret,e);
    return ret;
}
 main()

{
    fast
    cin>>h>>w>>k;
    f(i,0,h-1)
    {
        cin>>s[i];
        f(j,0,w-1)
        {
            if(s[i][j]=='S')
            {
                stx=i;sty=j;
            }
        }
    }
   queue<pi>q;
   q.push({stx,sty});
   vis[stx][sty]=true;
   while(!q.empty())
   {
       pi yo=q.front();
       q.pop();
       int x=yo.fi;
       int y=yo.si;
       ses=mn(ses,x,y,h-x-1,w-y-1);
       if(dis[x][y]==k)continue;
       f(i,0,3)
       {
           int nx=x+dx[i];
           int ny=y+dy[i];
           if(nx<0 || nx>=h || ny<0 || ny>=w)continue;
           if(s[nx][ny]=='#')continue;
           if(vis[nx][ny])continue;
           vis[nx][ny]=true;
           dis[nx][ny]=dis[x][y]+1;
           q.push(mp(nx,ny));
       }

   }
    ses=(ses+k+k-1)/k;
    cout<<ses<<endl;
    return 0;

}













Measured memory_bytes: 6656
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;


int main(){
  string S;
  cin >>  S;
  if(S=="Sunny"){
    cout << "Cloudy" << endl;
  }
  if(S=="Cloudy"){
    cout << "Rainy" << endl;
  }
  if(S=="Rainy"){
    cout << "Sunny" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 0;
    rep(i, 1, n + 1){
        string s = to_string(i);
        if(s.size() % 2) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in

    let rec loop i cur acc =
        if i = n then acc else
            if a.(i) = cur then loop (i + 1) (cur + 1) acc  else
            if a.(i) < cur then loop (i + 1) cur acc else
                loop (i + 1) cur (acc + (a.(i) - 1) / cur)
    in
    loop 1 2 (a.(0) - 1) |> Printf.printf "%d\n"
)

Measured memory_bytes: 6700
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdint>

using namespace std;

int find_not_one(string s) {
  for (int i = 0; i < s.length(); i++) {
    if (s[i] != '1')
      return i;
  }
  return 0;
}

int main() {
  string s;
  int k;
  cin >> s >> k;
  if (k == 1) {
    cout << s[0] << endl;
    return 0;
  }
  int pos = find_not_one(s);
  if (k-1 < pos) {
    cout << '1' << endl;
  } else {
    cout << s[pos] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
  	int H, W, h, w;
	cin >> H >> W;
  	cin >> h >> w;
  	int a;
  	a = H*W;
  	a -= h*W;
  	a -= w*H;
  	a += h*w;
  	cout << a << endl;
  
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define mset(a,x) memset(a,x,sizeof(a))
#define FASTIO() cin.tie(0),ios::sync_with_stdio(0);
#define dbg(x) cout<<#x<<": "<<x<<endl

int n;

int main() {
    cin >> n;
    vector<int> a(n);
    set<int> S;
    rep(i, n) {
        scanf("%d", &a[i]);
        S.insert(a[i]);
    }
    sort(ALL(a));

    ll ans = 0;
    for (auto&& i : S) {
        int x = upper_bound(ALL(a), i) - lower_bound(ALL(a), i);
        if (x < i) {
            ans += x;
        }
        else if (i < x) {
            ans += x - i;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;


int main() {
    int n; cin >> n;
    vector<int> a(100100);
    rep(i,n){
        int b; cin >> b;
        a[b]++;
    }
    int count = 0;
    int max_count = 0;
    _rep(i,1,a.size() ){
        count = a[i - 1] + a[i] + a[i + 1];
        max_count = max(count,max_count);
    }
    print(max_count);
}

Measured memory_bytes: 640
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
L = [0] * N
R = [0] * N
for i in range(N - 1):
    L[i + 1] = gcd(L[i], A[i])
for i in range(N - 1, 0, -1):
    R[i - 1] = gcd(R[i], A[i])
ans = 0
for i in range(N):
    ans = max(gcd(L[i], R[i]), ans)
print(ans)

Measured memory_bytes: 16144
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) begin(v), end(v)
#define REV(v) rbegin(v), rend(v)
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

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

int dist[110][110][4];
char v[110][110];

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

int main(){
	ll n, m, L;
	while (cin >> n >> m >> L, n){
		MEMSET(v, 0);
		FOR(i, 1, n + 1) FOR(j, 1, m + 1) cin >> v[i][j];
		int r, c, d;
		FOR(i, 1, n + 1) FOR(j, 1, m + 1){
			if (v[i][j] != '.' && v[i][j] != '#'){
				rep(dir, 4) if (v[i][j] == "NESW"[dir]) tie(r, c, d) = MT(i, j, dir);
				v[i][j] = '.';
			}
		}

		MEMSET(dist, -1);
		int x = 0;
		dist[r][c][d] = x++;
		bool loop = true;
		while (L){
			while (v[r + dy[d]][c + dx[d]] != '.') d = (d + 1) % 4;
			r += dy[d], c += dx[d];
			L--;
			if (loop && dist[r][c][d] >= 0) L %= (x - dist[r][c][d]), loop = false;
			dist[r][c][d] = x++;

			//for (int i = 1; i <= n; ++i){
			//	for (int j = 1; j <= m; ++j){
			//		cout << (MP(i, j) == MP(r, c) ? "NESW"[d] : v[i][j]);
			//	}cout << '\n';
			//}cout << '\n';
		}
		cout << r << ' ' << c << ' ' << "NESW"[d] << '\n';
	}

	return 0;
}

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

// pbds
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
// gp_hash_table<int, int> table;

using namespace std;

#define vec vector
#define ALL(x) begin(x), end(x)

typedef unsigned long long ull;
typedef unsigned int ui;
typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;

const int inf = 1000 * 1000 * 1000;
const ll inf64 = 1e18;

int main() {

#ifdef debug
    freopen("input.txt", "r", stdin);
#endif

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

    string s;

    cin >> s;

    string t = "keyence";

    if(s == t) {
        cout << "YES\n";
        return 0;
    }

    for(int l = 0;l < (int)s.size();l++) {
        for(int r = l;r < (int)s.size();r++) {
            string tmp = s.substr(0, l) + s.substr(r + 1);
            if(tmp == t) {
                cout << "YES\n";
                return 0;
            }
        }
    }

    cout << "NO\n";

    return 0;
}


Measured memory_bytes: 256
a,b,c = gets.split("\s").map(&:to_i).sort.reverse #aが最大になる

count = 0
count += (a-b)/2 + (a-c)/2

parities = [a,b,c].map { |i| i%2 }
parities.map! { |i| i==0 ? 1 : 0 }  if parities[0] == 0

#p parities

parity = parities.inject(&:+) %3

count += case parity
            when 0
                0
            when 1
                1
            when 2
                2
            end

puts count


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string s;
  cin >> s;
  string t = s;
  reverse(all(s));
  int ans = 0;
  rep(i, 0, len(s) / 2) {
    if (s[i] != t[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

def solve_binary(mid):
  count = 0

  if mid == 0:
    count = (P+M)*zero + P*M + (zero*(zero-1)//2 if zero >= 2 else 0)
    return k <= count

  if mid < 0:
    # jのスタート位置を求める
    # for j in range(P):
    #   if Plus[j]*Minus[0] <= mid: break
    j=0
    for i in range(M):
      while j<P and Plus[j]*Minus[i] > mid:
        j += 1
      count += P-j
    return k <= count

  if mid > 0:
    count += (P+M)*zero + P*M + (zero*(zero-1)//2 if zero >= 2 else 0)
    # Mについて
    # print(count,mid)
    j = 0
    for i in range(M-1,-1,-1):
      while j<M and Minus[j]*Minus[i] > mid:
        j += 1
      count += max(0,i-j)
    # print(count,mid)
    # Pについて
    j = P-1
    for i in range(P):
      while 0<=j and Plus[j]*Plus[i] > mid:
        j -= 1
      count += max(0,j-i)
    # print(count,mid)
    return k <= count
      

def binary_search(n):
    ng=-n-1
    ok=n
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if solve_binary(mid):
            ok=mid
        else:
            ng=mid
    return ok

zero=0
n,k=map(int,input().split())
A=list(map(int,input().split()))
Minus=[]; Plus=[]
for ai in A:
  if ai < 0: Minus.append(ai)
  elif ai == 0 : zero += 1
  elif ai > 0: Plus.append(ai)
Minus.sort(); Plus.sort()
M = len(Minus) ; P = len(Plus)
# print(solve_binary(6))
# print(solve_binary(448283280358331064))
# print(solve_binary(2))
# exit()
X = binary_search(10 ** 18)
print(X)

Measured memory_bytes: 88688
N,M,X,Y = map(int,input().split())
x = [int(i) for i in input().split()]
x.append(X)
y = [int(i) for i in input().split()]
y.append(Y)
mx_x = max(x)
mn_y = min(y)

if mx_x < mn_y:
    print('No War')
    
else:
    print('War')

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define upd(x, y) x=min(x, y)

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=5010, LOG=20;

int n, m, k, u, v, x, y, t, A, B;
int P[MAXN], PP[MAXN];
ll dp[MAXN][MAXN], ans;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	memset(dp, 63, sizeof(dp));
	cin>>n>>A>>B;
	for (int i=1; i<=n; i++) cin>>P[i], PP[P[i]]=i;
	dp[0][0]=0;
	for (int i=0; i<n; i++) for (int j=0; j<=i; j++){
		if (PP[j]<PP[i+1]) upd(dp[i+1][j], dp[i][j]+B);
		if (PP[j]>PP[i+1]) upd(dp[i+1][j], dp[i][j]+A);
		if (PP[j]<PP[i+1]) upd(dp[i+1][i+1], dp[i][j]);
	}
	ans=INF;
	for (int i=0; i<=n; i++) upd(ans, dp[n][i]);
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 196480
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define bug cout<<"AIkahne aise"<<endl
ll A[5000001],B[1000001];
vector<ll>v;
vector<pair<ll,ll> >v2;
/*void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}*/
int main()
{
  ll a,b,t,ans=0,n;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
      cin>>A[i];
  }
  for(int i=1;i<=n;i++)
  {
      cin>>B[i];
  }
  for(int i=1;i<=n;i++)
  {
      if(A[i]-B[i]>0)
      {
          ans+=A[i]-B[i];
      }
  }
  cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;

int main(){
    int n;
    cin >> n;
    vector<P> v(n);
    for(int i=0;i<n;i++) cin >> v[i].first >> v[i].second;
    sort(v.begin(), v.end(), [](const P x, const P y){
        if (x.second == y.second) return x.first < y.first;
        else return x.second < y.second;
    });
    int xtime = 0;
    bool ok = true;
    for(int i=0;i<n && ok;i++){
        xtime += v[i].first;
        if(xtime > v[i].second)
            ok = false;
    }
    cout << (ok?"Yes":"No") << endl;
    return 0;
}

Measured memory_bytes: 1920
import java.util.*;

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

        int n = sc.nextInt();

        if (n % 2 == 0) {
            System.out.println(n / 2);
        } else {
            System.out.println((n / 2) + 1);
        }

    }
}


Measured memory_bytes: 21588
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var x = long.Parse(input.ReadLine());

        var y = 100L;
        var c = 0L;
        while (y < x) {
            y = y + (y / 100);
            c++;
        }

        return c;
    }
}


Measured memory_bytes: 27452
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

def solve(i, m):
  if m == 0:
    return True
  if i >= n :
    return False
  res = solve(i + 1, m) or solve(i + 1, m - A[i])
  return res

for tmp_m in m:
  if sum(A) < tmp_m:
    print('no')
  elif solve(0, tmp_m):
    print('yes')
  else:
    print('no')

Measured memory_bytes: 7792
import math
n,x,y=map(int,input().split())
pairs=[]
for i in range(0,n-1):
    pairs.append(0)
for i in range(1,n):
    for j in range(i+1,n+1):
        if j<=x or i>=y:
            pairs[j-i-1]+=1
        elif i<=x and j>=y:
            pairs[j-i-y+x]+=1
        else:
            if j-i>(abs(y-j)+abs(x-i)+1):
                pairs[abs(y-j)+abs(x-i)]+=1
            else:
                pairs[j-i-1]+=1
for pair in pairs:
    print(pair)

Measured memory_bytes: 3444
#include<iostream>
#include<vector>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<algorithm>


using namespace std;

const int DIFF = 2000;

struct Circle{
  double x,y,r;
  bool operator < (const Circle& c) const{
    return sqrt(x*x+y*y) < sqrt(c.x*c.x+c.y*c.y);
  }
};

double dist(const Circle& c1, const Circle& c2){
  return sqrt((c1.x-c2.x)*(c1.x-c2.x) + (c1.y-c2.y)*(c1.y-c2.y))-c1.r-c2.r;
}

int main(){
  int n;
  while(cin >> n && n){
    vector<Circle> V(n);
    for(int i = 0; i < n; i++) cin >> V[i].r >> V[i].x >> V[i].y;
    
    sort(V.begin(),V.end());

    double ans = 1e50;

    for(int i = 0; i < n; i++)
      for(int j = max(0,i-DIFF); j < min(n, i+DIFF); j++){
	if(i == j) continue;
	ans = min(ans,dist(V[i],V[j]));
      }
   
    printf("%.5f\n",ans);
  }
  return 0;
}

Measured memory_bytes: 3616
// AGC023
// C - Painting Machines

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 1000000;
const ll MOD = 1e9 + 7;

int N;
ll fact[MAX_N + 1];
ll fact_inv[MAX_N + 1];

ll extgcd(ll a, ll b, ll& x, ll& y) {
    ll d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}

ll mod_inv(ll a, ll m) {
    ll x, y;
    extgcd(a, m, x, y);
    return (m + x) % m;
}

void calc_fact() {
    fact[0] = fact_inv[0] = 1;
    for (int i = 1; i <= N; i++) {
        fact[i] = fact[i - 1] * i % MOD;
        fact_inv[i] = mod_inv(fact[i], MOD);
    }
}

ll solve() {
    calc_fact();

    ll ans = 0;
    ll prev_cnt = 0;
    for (int k = (N + 1) / 2; k <= N - 1; k++) {
        ll cnt = fact[k - 1];
        (cnt *= fact_inv[N - 1 - k]) %= MOD;
        (cnt *= fact_inv[2 * k - N]) %= MOD;
        (cnt *= fact[k]) %= MOD;
        (cnt *= fact[N - 1 - k]) %= MOD;
        // cerr << k << " " << cnt << endl;
        (ans += k * (cnt - prev_cnt + MOD)) %= MOD;
        prev_cnt = cnt;
    }
    return ans;
}

int main() {
    cin >> N;

    cout << solve() << endl;

    return 0;
}


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

using namespace std;

int main(void)
{
    unsigned long int N;
    cin >> N;
    stack<char> st;
    while(N != 0){
        N--;
        st.push('a' + N % 26);
        N /= 26;
    }
    while(!st.empty()){
        cout << st.top();
        st.pop();
    }
    cout << endl;
        return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <cstdlib>

using namespace std;

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

int main()
{
    int n, x; cin >> n >> x;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) cin >> v[i];

    vector<int> s(n);
    s[0] = abs(x - v[0]);
    int ans = s[0];
    for (int i = 1; i < n; ++i) {
        s[i] = abs(v[i] - v[i-1]);
        ans = gcd(s[i], ans);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
//v.erase(unique(v.begin(),v.end()),v.end());
 
#define ff first
#define ss second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
 
typedef double ld;
typedef long long ll;
const ll N = 200500;
const ll mod = 1100000007;
const ll INF = 1e+9;
using namespace std;
//using namespace __gnu_pbds;
 
//typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;}
 
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);}
#else
#define trace(...)
#endif

ll ac1[N], ac2[N];
ll xd[N];

ll uwu(ll a, ll b, ll c, ll d){
	//trace(a, b, c, d);
	vector <ll> aea; aea.clear();
	aea.push_back(a); aea.push_back(b); aea.push_back(c); aea.push_back(d);
	sort(aea.begin() ,aea.end());
	if(aea[0] == 0) return 1e+9;
	return aea.back() - aea[0];
}

void solve(){
	ll n; cin >> n;

	for(ll i = 1; i <= n ;i++) cin >> xd[i];
	for(ll i = 1; i <= n; i++) ac1[i] = ac1[i - 1] + xd[i];
	for(ll i = n; i >= 1; i--) ac2[n - i + 1] = ac2[n - i] + xd[i];
	ll mini = 1e+9 + 10;
	for(ll i = 2; i <= n - 2; i++){
		//el corte de mrd
		ll sum1 = ac1[i];
		ll sum2 = ac2[n - i]; 
		ll pos1 = lower_bound(ac1 + 1, ac1 + n + 1, ll(sum1 / 2)) - ac1 - 1;
		if(pos1 > 0 and ac1[pos1 + 1] - sum1 / 2 > sum1 / 2 - ac1[pos1]) pos1--;
		
		ll pos2 = lower_bound(ac2 + 1, ac2 + n + 1, ll(sum2 / 2)) - ac2 - 1;
		if(pos2 > 0 and ac2[pos2 + 1] - sum2 / 2 > sum2 / 2 - ac2[pos2]) pos2--;
		ll ans;
		
		ans = uwu(ac1[pos1 + 1], sum1 - ac1[pos1 + 1], ac2[pos2 + 1], sum2 - ac2[pos2 + 1]);
		//trace(ans);
		mini = min(mini, ans);
	}
	cout << mini << endl;
}
 
int main(){
	fastio;
	ll tc = 1;
	//cin >> tc;

	while(tc--) solve();

	return 0;
}

Measured memory_bytes: 8340
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
int main(){
    int K;
    string S;
    cin >>  K >> S;
    if(S.size() <= K){
        cout << S << endl;
    }
    else{
        for(int i = 0; i < K; i++){
            cout << S.at(i);
        }
        cout << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nya_n "(=^･ω･^=)"
typedef long long ll;
using namespace std;

/*
ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	ll g = gcd(x, y);
	return x / g * y;
}*/

int n;

int main(){
	cin >> n;
	lp(30) {
		LP(20, j) {
			if (i * 4 + j * 7 == n) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{

	static void Main()
	{
    long n = long.Parse(Console.ReadLine());
    long[] nums = new long[n];
    for(long i = 0; i < n; i++)
    {
      nums[i] = long.Parse(Console.ReadLine());
    }
    
		Console.WriteLine(LISlength(nums));
	}

  static int LISlength(long[] nums)
  {//最長狭義(2,3はよいが、同じ2,2は不可)増加部分列の長さを返す。元の列の長さをnとして、O(nlogn)かかる。
    int n = nums.Length;
    long[] rightMin = new long[n];//長さがi+1のときの右端の最小値
    int answer = 1;
    long compareMemo = 0;

    rightMin[0] = nums[0];

    for(long i = 1; i < n; i++)
    {
      if(nums[i] > rightMin[answer-1])
      {
        rightMin[answer] = nums[i];
        answer++;
      }else
      {
        compareMemo = nums[i];
        rightMin[SearchLIS(0, answer-1, rightMin, compareMemo)] = nums[i];//更新位置を二部探索する
      }
    }
    return answer;
  }

  static long SearchLIS(long min, long max, long[] rightMin, long compareMemo)//二分探索法で最小値を求める
  {
    while (true)
    {
      long mid = min + (max - min) / 2;
      if(CheckLIS(mid,rightMin,compareMemo)) max = mid;//さらに大きくても成り立つかも
      else min = mid;

      if(max - min <= 1)
      {
        if(CheckLIS(min,rightMin,compareMemo)) 
        {
          return min;//最小値で成り立つかの確認を優先
        }
        else
        {
          return max;
        }
      break;
      }  
    }
  }

  static bool CheckLIS(long testNum, long[] rightMin, long compareMemo)
  {
    if(rightMin[testNum] >= compareMemo) return true;//同じ数で右端を複数にしないように、等号を含む
    return false;
  }

}


Measured memory_bytes: 23124
N, K = [int(i) for i in input().split()]
Okashi = [[] for _ in range(K + 1)]
for j in range(1, K + 1):
    D = int(input())
    A = [int(i) for i in input().split()]
    for a in A:
        Okashi[j].append(a)

tmp = [0] * (N+1)
for o in Okashi[1:]:
    for b in o:
        tmp[b] += 1

ans = sum([1 for a in tmp[1:] if a==0])
print(ans)

Measured memory_bytes: 9124
#include<iostream>
#include<algorithm>
#include<utility>
using namespace std;
pair<int,int>p[1<<17];
int n;
main()
{
    cin>>n;
    for(int i=0;i<n;i++)cin>>p[i].first>>p[i].second;
    sort(p,p+n);
    for(int i=0;i<n;i++)cout<<p[i].first<<" "<<p[i].second<<endl;
}


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

int main(){
	int h, w;
	while(cin >> h >> w && (h || w)){
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++) cout << "#."[(i + j) % 2];
			cout << endl;
		}
		cout << endl;
	}
}

Measured memory_bytes: 3092
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] count = new int[4];
		for(int i = 0; i < n; i++) {
			String s = sc.next();
			if(s.equals("AC")) count[0]++;
			else if(s.equals("WA")) count[1]++;
			else if(s.equals("TLE")) count[2]++;
			else if(s.equals("RE")) count[3]++;
		}
		System.out.println("AC x "+count[0]);
		System.out.println("WA x "+count[1]);
		System.out.println("TLE x "+count[2]);
		System.out.println("RE x "+count[3]);
	}
}

Measured memory_bytes: 58484
import java.util.*;
public class Main{
	public static void main(String arg[]){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int arr[]=new int[a];
		int count=0,c=1;
		for(int i=0;i<a;i++)
			arr[i]=sc.nextInt();
		for(int i=0;i<a;i++){
			count+=arr[i];
			if(count<=b)
				c++;
		}
		System.out.println(c);
	}
}

Measured memory_bytes: 23764
H, W = map(int, input().split())
A = [list('.'+input()+'.') for _ in range(H)]
if sum(A[i].count('#') for i in range(H)) != H + W -1:
    print('Impossible')
    exit()
A.append('.'*(W+2))
A.insert(0, '.'*(W+2))
h, w = 1, 1
for i in range(H+W-2):
    n = []
    for j in [(0,-1), (0,1), (-1,0), (1,0)]:
        if A[h+j[0]][w+j[1]] == '#':
            n.append(j)
    if i == 0 and len(n) != 1 or i > 0 and len(n) != 2:
        print('Impossible')
        exit()
    if i == 0 or hp != h+n[0][0] or wp != w+n[0][1]:
        j = 0
    else:
        j = 1
    hp, wp = h, w
    h, w = h+n[j][0], w+n[j][1]
if h == H and w == W:
    print('Possible')
else:
    print('Impossible')


Measured memory_bytes: 62180
#include <iostream>

using namespace std;

int main(void){
    int n=0;
    int k=0;
    int x=0;
    int y=0;
    int sum=0;

    cin >> n >> k >> x >> y;

   for(int i=1;i<=n;i++){
       if(i<=k)sum+=x;
       else sum+=y;
   }

   cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
##B
n = int(input())
d1 = [0] * n
d2 = [0] * n

for i in range(n):
    d1[i], d2[i] = map(int, input().split())
answer = "No"
for i in range(n - 2):
    if d1[i] == d2[i] and d1[i + 1] == d2[i + 1] and d1[i + 2] == d2[i + 2]:
        answer = "Yes"
        break
print(answer)





Measured memory_bytes: 9184
n, m, x, y =  (int(i) for i in input().split())
xs = [int(i) for i in input().split()]
ys = [int(i) for i in input().split()]

def is_war(x,y,xs,ys):
    mx = max(xs)
    my = min(ys)
    if my <= x:
        return True
    elif mx >= y:
        return True
    elif my <= mx:
        return True
    else:
        return False

if is_war(x,y,xs,ys):
    print("War")
else:
    print("No War")



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

vector<int> edge[110000];
int color[110000];

bool dfs(int v, int c = 0) {
	color[v] = c;
	for (auto x : edge[v]) {
		if (color[x] != -1) {
			if (color[x] == c) return false;
		} else if (!dfs(x, c ^ 1)) {
			return false;
		}
	}
	return true;
}

int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	fill(color, color + 110000, -1);
	if (dfs(0)) {
		int black = count(color, color + n, 0);
		int white = count(color, color + n, 1);
		cout << long(black) * white - m << endl;
	} else {
		cout << long(n) * (n - 1) / 2 - m << endl;
	}
}

Measured memory_bytes: 9980