akhauriyash/Code-Regression huggingface dataset:
s = gets.chomp.split(" ").map(&:to_i)

insert = [[]]
count = 0
while(s[0] > count)
    a = ""
    a = gets.chomp.split(" ").map(&:to_i)
    insert[count] = a
    count = count + 1
end

insert = insert.sort { |a, b| b[0] <=> a[0] }.reverse
sum = 0

for i in 0..s[0]-1
    sum += insert[i][1]
    if(sum >= s[1])
        print(insert[i][0])
        break()
    end
end

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

using namespace std;

int dxdy[4][2] = { {-1,0}, {1,0}, {0,1}, {0,-1} };

int fill(vector<vector<char> >& v, int mi, int mj){
    int sum = 0;
    for(int i=0; i < 4; ++i){
        if(v[ mi+dxdy[i][0] ][ mj+dxdy[i][1] ] == '.'){
            sum++;
            v[mi+dxdy[i][0]][mj+dxdy[i][1]] = ':';
            sum += fill(v, mi + dxdy[i][0], mj + dxdy[i][1]);
        }
    }
    return sum;
}

int main(){
    int w, h;
    int mi, mj;
    char c;
    while(true){
        cin >> w;
        cin >> h;
        if(w == 0 && h == 0) break;
        vector<vector<char> > v(w+2, vector<char>(h+2));
        for(int j = 0; j <= h+1; ++j){
            for(int i = 0; i <= w+1; ++i){
                if(i == 0 || j == 0 || i == w+1 || j == h+1 ){
                    v[i][j] = '#';
                } else {
                    cin >> c;
                    if(c == '@') {
                        mi = i, mj = j;
                        c = ':';
                    }
                    v[i][j] = c;
                }
            }
            if( j >= 1 && j <= h ) cin.ignore();
        }

        cout << fill(v, mi, mj) + 1 << endl;
    }
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int gcd( int x, int y ){ return y ? gcd(y, x%y) : x; }
signed main() {
int x=0,y=0,z=0,w=0,n=0,m=0;
int a=0,b=-1,c=0,d=0;
while (true) {
  std::cin >> n;
  if(n==0)break;
  b=-1;
rep(i,n){
  std::cin >> x>>y>>z;
  if(b<y+z){
    a=x;
    b=y+z;
  }
}

        printf("%d %d\n",a,b);
      }
}



Measured memory_bytes: 3216
#include<cstdio>
int i,j,k,o,n,c,s[1<<19];
void g(int l,int m,int r){
  int L[m-l+1],R[r-m+1];
  for(i=0;i<m-l;L[m-l]=R[r-m]=1e9)L[i]=s[l+i++];
  for(i=0;i<r-m;k=l)R[i]=s[m+i++];
  for(i=o=0;k<r;++c)s[k++]=L[i]>R[o]?R[o++]:L[i++];
}
void e(int l,int r){
  int m=(l+r)/2;
  if(l+1<r)e(l,m),e(m,r),g(l,m,r);
}
main(){
  for(scanf("%d",&n);i<n;)scanf("%d",s+i++);
  for(e(0,n);j<n;)printf(j-n?"%d ":"%d\n",s[j++]);
  printf("%d\n",c);
}

Measured memory_bytes: 6572
S =list(str(input()))
S1=S[0:int(((len(S)-1)/2))]
S2=S[int(((len(S)+3)/2)-1):len(S)+1]

if S1==list(reversed(S1)) and S2==list(reversed(S2)) and S1==list(reversed(S2)):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
s = int(input())
T = set()
T.add(s)
for i in range(1000001):
  if s%2:
    s = s*3 + 1
  else:
    s = s // 2
  l = len(T)
  T.add(s)
  if l == len(T):
    print(i+2)
    exit()

Measured memory_bytes: 9188
import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.Queue;
import java.util.Scanner;

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

        while (true) {
            int h = scanner.nextInt(), w = scanner.nextInt();

            if (h == 0 && w == 0) break;

            for (int i = 0; i < h; ++i) {
                for (int j = 0; j < w; ++j) {
                    if ((i + j) % 2 == 0) System.out.print("#");
                    else System.out.print(".");
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 33196
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

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

    vector<int> accum_e(n + 1), accum_w(n + 1);
    for (int i = 0; i < n; i++) {
        accum_e[i + 1] = accum_e[i];
        accum_w[i + 1] = accum_w[i];

        char c = s[i];
        if (c == 'E')
            accum_e[i + 1]++;
        else
            accum_w[i + 1]++;
    }
    int minx = 10000000000;

    for (int i = 0; i < n; i++) {
        int num = accum_w[i] + (accum_e[n] - accum_e[i + 1]);
        minx = min(minx, num);
    }
    cout << minx << endl;

    return 0;
}

Measured memory_bytes: 3076
use std::cmp;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    loop {
        let n: usize = sc.read();
        let m: usize = sc.read();
        if n == 0 {
            return;
        }
        let mut v = vec![0; m];
        for _ in 0..n {
            let d = sc.read::<usize>() - 1;
            let x: usize = sc.read();
            v[d] = cmp::max(v[d], x);
        }

        let ans = v.iter().sum::<usize>();
        println!("{}", ans);
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write_all(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}



Measured memory_bytes: 5052
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		ll a,b,c,d;
		scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
		if(a<b){puts("No");continue;}
		if(d<b){puts("No");continue;}
		ll t=(a-c-1)/__gcd(b,d);
		a=a-t*__gcd(b,d);
		a-=b;
		if(a<0)puts("No");else puts("Yes");
	}
	return 0;
}

Measured memory_bytes: 256
five = 0
seven = 0
gets.chomp.split.each { |n|
    num = n.to_i
    if num == 5
        five += 1
    elsif num == 7
        seven += 1
    end
}

if five == 2 && seven == 1
    puts 'YES'
else
    puts 'NO'
end

Measured memory_bytes: 1788
import java.math.BigDecimal;
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		String A=stdIn.next();
		String B=stdIn.next();
		BigDecimal a = new BigDecimal(A);
		BigDecimal b = new BigDecimal(B);
		System.out.println(a.multiply(b).setScale(0,java.math.RoundingMode.DOWN));
	}
}


Measured memory_bytes: 35864
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class A_ABCSwap_161
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            long x = inputLongArray[0];
            long y = inputLongArray[1];
            long z = inputLongArray[2];

            long a = x;
            x = y;
            y = a;

            long b = x;
            x = z;
            z = b;

            long[] result = new long[3] { x, y, z };


            Console.WriteLine(string.Join(" ",result));

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28276
#include <iostream>
#include <cstdio>

inline int read() {
	register int x = 0, v = 1;
	register char ch = getchar();
	while(!isdigit(ch)) {
		if(ch == '-') v = -1;
		ch = getchar();
	}
	while(isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * v;
}

int main() {
	int a = read(), b = read(), c = read();
	if(a + b >= c - 1) printf("%d\n", b + c);
	else if(a + b < c - 1) printf("%d\n", b + a + b + 1);
	return 0;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

n, k = MAP()
if k == 0:
    print(n ** 2)
    exit()
ans = 0
for b in range(k + 1, n + 1):
    qmax = n // b
    ans += (b - k) * qmax
    t = n % b
    ans += max(0, t - k + 1)
print(ans)

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


int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    b[i]=a[i];
  }

sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int t=a[0];
  for(int i=0;i<n;i++){
    if(b[i]!=t){
      cout<<t<<endl;
    }
    else{
      cout<<a[1]<<endl;
    }
  }
}

Measured memory_bytes: 3200
#include <iostream>
#include <set>
using namespace std;
const int max_size = (int)1e5*2 + 1;
constexpr int max(int a, int b){ return a>b?a:b;}
int parent[max_size];
int ranking[max_size];
int set_size[max_size];
int n,m;

void init(){
    for(int i = 0 ; i < max_size ; ++i){
        parent[i] = i;
        ranking[i] = 0;
        set_size[i] = 1;
    }
}

int find(int x){
    if(parent[x] == x) return x;
    return parent[x] = find(parent[x]);
}
void merge(int p, int q){
    p = find(p);
    q = find(q);
    if(p == q) return;
    if (ranking[p] < ranking[q]){
        parent[p] = q;
        set_size[q] += set_size[p];
    }else{
        parent[q] = p;
        set_size[p] += set_size[q];
        if (ranking[p] == ranking[q]){
            ranking[p]++;
        }
    }
}

int main(){
    init();
    int n,m;
    scanf("%d%d", &n,&m);
    for(int i = 0,a,b;i < m ; ++i){
        scanf("%d%d", &a, &b);
        merge(a,b);
    }
    
    int ans = 0;
    for(int i = 1; i <= n ; ++i){
        ans = max(ans, set_size[i]);
    }
    cout << ans;

    return 0;
}

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

int main() {
	long n,a,b,i,ans,cur;
	cin >> n >> a >> b;
	if((b-a)%2==0){
		cout << (b-a)/2 << endl;
	}else{
		cout << min(a-1,n-b)+(b-a+1)/2 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef unsigned long long ll;
vector<ll > vec;
vector<vector<ll > > vec2;

ll sum(ll a, ll b){
    ll ans = 0;
    for(ll i = a; i <= b; i++){
        ans+=i;
    }
    return ans;
}

int main(){

    string s;
    cin >> s;
    //圧縮
    for(ll i = 0; i < s.length();){
        ll j = i;
        //一緒の間ループを回し続けて，切れ目を探す
        while(j < s.length() && s[j] == s[i]){
            ++j;
        }
        vec.push_back(j - i);
        //次の始点へすっ飛ばす
        i = j;
    }

    ll ans = 0;
    ll idx = 0;
    //1つ飛ばす
    if(s[0] == '>'){
        ans += sum(0, vec[0]);
        idx = 1;
    }
    //番兵
    if((vec.size() + idx) % 2 != 0){
        vec.push_back(1);
    }
    for(ll i = 1 + idx; i < vec.size(); i+=2){
        if(vec[i] >= vec[i-1]){
            ans +=  ((vec[i-1]-1) * vec[i-1]) / 2;
            ans +=  (vec[i] * (vec[i] + 1)) / 2;
        }else{
            ans +=  (vec[i-1]* (vec[i-1]+1)) / 2;
            ans +=  ((vec[i]-1) * vec[i]) / 2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
int z(int a) {
  if(a < 0) {
    return -a;
  }
  return a;
}

int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  for(int i = 0; i < N; i++) {
    cin >> h.at(i);
  }
  vector<int> cost(N);
  cost.at(0) = 0;
  cost.at(1) = z(h.at(1) - h.at(0));
  for(int i = 2; i < N; i++) {
    cost.at(i) = min((z(h.at(i) - h.at(i - 1)) + cost.at(i - 1)), (z(h.at(i) - h.at(i - 2)) + cost.at(i - 2)));
  }
  cout << cost.at(N - 1) << endl;
  /*for(int i = 0; i < N; i++) {
    cout << cost.at(i) << " = cost" << i << endl;
  }*/
}

Measured memory_bytes: 1024
R,G,B,N = list(map(int,input().split()))

cnt = 0
sum = 0

for r in range(int(N/R)+1):
    sum = R*r
    for g in range(3001):
        if sum + G*g > N:
            break
        if (N-sum-(G*g))%B == 0:
            cnt += 1

print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

int main() {
  int n, k;
  cin >> n >> k;
  vector<long long> h(n);

  for (long long& hi : h) {
    cin >> hi;
  }

  sort(h.begin(), h.end(), greater<>());

  long long ret = 0;
  for (int i = k; i < n; ++i) {
    ret += h[i];
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 4808
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		BigInteger A = sc.nextBigInteger();
		BigInteger B = sc.nextBigInteger();
		if (A.compareTo(B) > 0) {
			System.out.println("GREATER");
		} else if (A.compareTo(B) < 0) {
			System.out.println("LESS");
		} else {
			System.out.println("EQUAL");
		}
		sc.close();
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX_N 200010
#define lb lower_bound //[2,4)=lb(4)-lb(2);

int main()
{
   ll N,A,B;cin>>N>>A>>B;
   ll ans;
   ll mid;
   ll m;
   
   if ((B-A)%2==0 && B-A>1)
   {
     //cout<<"--"<<endl;
     ans = abs(A-B)/2;
     cout<<ans<<endl;
     return (0);
   }
   else if ((B-A)%2==1 && B-A>1)
   {
     //cout<<"=="<<endl;
     ans = min(A-1,N-B)+1+(B-A-1)/2;
     cout<<ans<<endl; 
     return (0);
   }
  else if (B-A==1)
  {
    m = min(A-1,N-B);
    cout<<m+1<<endl;
    return (0);
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

int main(){
    int x;
    scanf("%d" ,&x);
    cout<<(x>=1200?"ARC":"ABC")<<endl;
}


Measured memory_bytes: 256
import sys
from itertools import product

input = sys.stdin.readline

N = int(input())
F = [[int(x) for x in input().split()] for _ in range(N)]
P = [[int(x) for x in input().split()] for _ in range(N)]

ans = float('-inf')
for ptn in product([0, 1], repeat=10):
    if sum(ptn) == 0:
        continue

    res = 0
    for i in range(N):
        cnt = 0
        for j in range(10):
            cnt += F[i][j] * ptn[j]
        res += P[i][cnt]
    ans = max(ans, res)
print(ans)


Measured memory_bytes: 3188
mod = 10**9+7
frac = [1]*200001
for i in range(2,200001):
    frac[i] = i * frac[i-1]%mod
fraci = [None]*200001
fraci[-1] = pow(frac[-1], mod -2, mod)
for i in range(-2, -200001-1, -1):
    fraci[i] = fraci[i+1] * (200001 + i + 1) % mod
def comb(a, b):
    if not a >= b >= 0:
        return 0
    return frac[a]*fraci[b]*fraci[a-b]%mod

def count(a, b):
    (r1, c1), (r2, c2) = RC[a], RC[b]
    if c2 < c1:
        return 0
    return comb(r2-r1 + c2-c1, r2-r1)

H, W, N = map(int, input().split())

RC = [list(map(int, input().split())) for _ in range(N)] + [[1, 1], [H, W]]
RC.sort()

dpe = [0]*(N+2)
dpo = [0]*(N+2)
dpe[0] += 1

for i in range(1, N+2):
    rese = 0
    reso = 0
    for k in range(i):
        t = count(k, i)
        if not t:
            continue
        rese = (rese + t*dpo[k]) % mod
        reso = (reso + t*dpe[k]) % mod
    dpe[i] = rese
    dpo[i] = reso

print((dpo[-1] - dpe[-1]) % mod)


Measured memory_bytes: 55292
def resolve():
    h,w,m = map(int, input().split())
    mine = []
    mineh = [0]*h
    minew = [0]*w
    for i in range(m):
        a,b = map(int, input().split())
        a -= 1
        b -= 1
        mine.append((a,b))
        mineh[a] += 1
        minew[b] += 1
    mine = set(mine)
    maxh = max(mineh)
    hnum = []
    maxw = max(minew)
    wnum = []
    for i in range(h):
        if mineh[i] == maxh:
            hnum.append(i)
    for i in range(w):
        if minew[i] == maxw:
            wnum.append(i)
    hnum = set(hnum)
    wnum = set(wnum)
    NO = 0
    for i, j in mine:
        if i in hnum and j in wnum:
            NO += 1
    if len(hnum)*len(wnum) > NO:
        print(maxw+maxh)
    else:
        print(maxw+maxh-1)
resolve()

Measured memory_bytes: 218296
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> void vdebug(vector<T> v){ cout << "vdebug" << endl; for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], ll n){ cout << "adebug" << endl; reps(i, 0, n){ cout << arr[i] << " "; } cout << endl; }
template<typename T1, typename T2> void mdebug(map<T1, T2> mp){ cout << "mdebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mldebug(multimap<T1, T2> mp){ cout << "mldebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mdebugr(map<T1, T2, greater<T1>> mp){ cout << "mdebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mldebugr(multimap<T1, T2, greater<T1>> mp){ cout << "mldebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    ll res = 0;
    int n;
    ll tmpa;
    vector<ll> a;

    cin >> n;
    rep(i, n){
        cin >> tmpa;
        a.push_back(tmpa);
    }

    vsort(a);

    ll asum[100010];
    asum[0] = 0;
    reps(i, 0, n-1){
        asum[i+1] = a[i] + asum[i];
    }

    reps(i, 1, n-1){
        if(a[i] <= asum[i]*2){
            res++;
            //cout << asum[i] << endl;
        }
        else res = 0;
    }
    res++;

    //vdebug(a);
    //adebug(asum, n);

    cout << res << endl;

    return 0;
}


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

string str1,str2;
int main(){
int i=0;
cin>>str1;
for(int i2=0; i2<str1.size() ;i2++)
		{
		if('A'<=str1[i2] && str1[i2]<='Z') str1[i2]+=32;
		}
while(1)
{	
	cin>>str2;
	if(str2=="END_OF_TEXT") break;
	{for(int i2=0; i2<str2.size() ;i2++)
		{
		if('A'<=str2[i2] && str2[i2]<='Z') str2[i2]+=32;
		}
	if(str1!=str2) 1;
	else i++;
	}
}
cout<<i<<endl;
return 0;
}


Measured memory_bytes: 3180
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cstdlib>

using namespace std;
int main()
{
	char X,Y;
	scanf("%c %c",&X,&Y);
	if(X < Y) printf("<\n");
	else if(X > Y) printf(">\n");
	else printf("=\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
	char s[5];
	scanf("%s",s);

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

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

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int n,a[21],b[21],c,d[21]={},sum=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(int i=0;i<n-1;i++){
    if(a[i]+1==a[i+1]){
      d[a[i]-1]=1;
    }
  }/*
  for(int i=0;i<n-1;i++){
    printf("%d",d[i]);
  }
  puts("");*/

  for(int i=0;i<n;i++){
    scanf("%d",&b[i]);
    sum+=b[i];
  }

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

}


Measured memory_bytes: 128
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        
        if(A+B > C+D){
            System.out.println("Left");
        }else if(A+B == C+D){
            System.out.println("Balanced");
        }else if(A+B < C+D){
            System.out.println("Right");
        }
    }
}

Measured memory_bytes: 21844
L, R = map(int, input().split())
amari_list =[]
count = 0
for i in range(R-L+1):
  (L+i)
  amari_list.append((L+i) % 2019)
  count += 1
  if count > 2019:
    break   
answer_list =[]
for i in range(len(amari_list)):
  for j in range(len(amari_list)-i-1):
    answer_list.append((amari_list[i]*amari_list[len(amari_list)-j-1])%2019)
print(min(answer_list))
    
  

Measured memory_bytes: 75592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

void solve() {
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int N;cin>>N;
    int fmul=0;
    int tmul=0;
    int nomul=0;
    vector<int>a(N);
    rep(i,N){
        cin>>a.at(i);
        if(a.at(i)%4==0)fmul++;
        else if(a.at(i)%2==0)tmul++;
    }
    nomul=N-fmul-tmul;
    if(2*fmul+1>=N){
        cout<<"Yes"<<endl;
        return 0;
    }else if(fmul>=nomul){
        cout<<"Yes"<<endl;
        return 0;
    }else{
        cout<<"No"<<endl;
        return 0;
    }





}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;
const long long INFL = 1LL<<60;


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

  ll w, h, x, y;
  cin >> w >> h >> x >> y;

  printf("%.10f %d\n", (w * h) / 2.0, (x == w/2.0 && y == h / 2.0) ? 1 : 0);

  return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
mod = 1000000007
sum = 0
for i in range(k, n + 2):
    tempSum1 = (n * (n + 1)) / 2
    tempSum2 = ((n - i) * (n - i + 1)) / 2
    tempSum3 = (i * (i - 1)) / 2
    sum += (tempSum1 - tempSum2 - tempSum3 + 1) % mod
print(int(sum % mod))

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

#define REP(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using ll = long long;

int main()
{
    int n, m; // n:スイッチの個数, m:電球の個数
    cin >> n >> m;

    VVI bulbs_switches; // 電球iに対応するスイッチ
    REP(i, m)
    {
        int k;
        cin >> k;
        VI switches;
        REP(j, k)
        {
            int s;
            cin >> s;
            switches.push_back(s-1); // スイッチの番号を配列の添え字0番スタートに合わせるため、s-1としている
        }
        bulbs_switches.push_back(switches);
    }

    VI vp; // 電球iにおけるp(0or1)のリスト 電球iに対応する、onであるスイッチ数の偶奇がpであるとき、電球iは点灯する
    REP(i, m)
    {
        int p;
        cin >> p;
        vp.push_back(p);
    }

    int ans = 0;
    // n個のスイッチ全てのon/off状態についてのループ O(2^n)
    for (int i = 0; i < (1 << n); i++)
    {

        int now[n] = {0}; // 現在のスイッチの状態

        // 2進数iのj桁目が立っていたら、その桁番号のスイッチの状態をonにする
        REP(j, n)
        {
            if ((1 << j) & i)
                now[j] = 1;
        }
        
        bool isLight = true; // 全ての電球が点灯しているかを表す
        // 各電球について、電球が点灯するかをチェックする
        REP(j, m)
        {

            int on_switches = 0; // 電球jに対応し、onになっているスイッチの数
            VI j_bulb_switches = bulbs_switches[j];

            // 電球jに対応するすべてのスイッチについてのループ
            FOR(index, j_bulb_switches)
                on_switches += now[index];

            // 現在点灯している電球の数が、pに対応しているかをチェックしている
            if (on_switches % 2 != vp[j])
                isLight = false;

        }

        // すべての電球が点灯していたら、答えをインクリメントする
        if (isLight)
            ans++;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
char s[100000];char a[10];
int main()
{
     while(scanf("%s",s)==1)
     {
          int bbb=1;
          for(int i=0;i<strlen(s);)
           {
             int l=0;
             memset(a,0,sizeof(a));
             for(int j=i;j<i+7;j++)
               if(j<strlen(s))a[l++]=s[j];
             else
             {
                  a[l++]='l';
                  continue;
             }
             a[l]='\0';
             if(strcmp(a,"dreamer")==0)
            {
                if(s[i+7]=='a') 
                i=i+5;
                else i=i+7;
                continue;
            }
            a[6]='\0';
            if(strcmp(a,"eraser")==0)
            {
                i=i+6;
                continue;
            }
            a[5]='\0';
            if(strcmp(a,"dream")==0||strcmp(a,"erase")==0)
            {
                i=i+5;
                continue;
            }
            bbb=0;
            if(bbb==0) break;
          }
      if(bbb==1)printf("YES\n");
      else printf("NO\n");
     }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

bool is_palindromic(int n)
{
    string S = to_string(n);
    deque<char> deque;
    rep (i, 0, S.size()) deque.push_back(S[i]);
    while (deque.size() != 1) {
        if (deque.front() != deque.back()) return false;
        deque.pop_front();
        deque.pop_back();
    }
    return true;
}

int main()
{
    int A, B, ans = 0; cin >> A >> B;
    rrep (i, A, B) if (is_palindromic(i)) ans++;
    cout << ans << endl;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	int h, a;
	cin >> h >> a;
	cout << (h + a - 1) / a << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<bitset>
using namespace std;
typedef long long ll;
vector<ll> v;
void primefactorization(ll n){
	ll a=2;
	while(n>=a*a){
		if(n%a==0){
			v.push_back(a);
			n/=a;
		}else a++;
	}
	v.push_back(n);
}

int digitnum(ll n){
	int a=0;
	while(n>0){
		n/=10;
		a++;
	}
	return a;
}

int main(){
	ll n;
	cin >> n;
	primefactorization(n);
	int flag=1;
	int ans=100;
	while(flag<=(1<<(v.size()-1))){
		ll left=1,right=1;
		for(int i=0;i<v.size();i++){
			if((flag>>i)&1) {
			left*=v[i];
			}else right*=v[i];
		}
		int tmp;
		if(left>=right) tmp=digitnum(left);
		else tmp=digitnum(right);
		ans=min(ans,tmp);
		flag++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
//Finite Disappointment and Infinite Hope
#include <bits/stdc++.h>
using namespace std;
#define help ios_base:: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.first<<","<<v.second<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    for(auto &x:c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
const ll N=2e5+5,MOD=1e9+7;
pair<ll,ll> arr[N];
ll seg[4*N],lazy[4*N];
void build(ll l,ll r,ll node){
    if(l==r){
        seg[node]=arr[l].second;
        return;
    }
    ll mid=(l+r)>>1;
    build(l,mid,2*node);
    build(mid+1,r,2*node+1);
    seg[node] = seg[2*node] + seg[2*node+1];
}
void push(ll l,ll r,ll node){
    if(!lazy[node])return;
    seg[node]=seg[node] - (r-l+1)*lazy[node];
    if(l!=r){
        lazy[2*node]+=lazy[node];
        lazy[2*node+1]+=lazy[node];
    }
    lazy[node]=0;
}
void update(ll l,ll r,ll node,ll ql,ll qr,ll val){
    push(l,r,node);
    if(r<ql || qr<l)return;
    if(ql<=l && r<=qr){
        lazy[node]+=val;
        push(l,r,node);
        return;
    }
    ll mid=(l+r)>>1;
    update(l,mid,2*node,ql,qr,val);
    update(mid+1,r,2*node+1,ql,qr,val);
    seg[node]=seg[2*node]+seg[2*node+1];
}
ll query(ll l,ll r,ll node,ll ql,ll qr){
    push(l,r,node);
    if(r<ql || qr<l)return 0;
    if(ql<=l && r<=qr)return seg[node];
    ll mid=(l+r)>>1;
    return query(l,mid,2*node,ql,qr) + query(mid+1,r,2*node+1,ql,qr);
}

int main(){
help
    ll n,d,a;cin>>n>>d>>a;
    for(ll i=0;i<n;i++)cin>>arr[i].first>>arr[i].second;
    sort(arr,arr+n);
    ll last[n];
    ll pos=0;
    for(ll i=0;i<n;i++){
        while(pos<n && (arr[pos].first-arr[i].first)<=2*d )pos++;
        last[i]=pos-1;
    }
    build(0,n-1,1);
    ll ans=0;
    for(ll i=0;i<n;i++){
        ll val= query(0,n-1,1,i,i);
        if(val<=0)continue;
        ll times=(val+a-1)/a;
        ans+=times;
        val = times*a;
        update(0,n-1,1,i,last[i],val);
    }

    cout<<ans;
}


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

int main() {
    long long N;
    cin >> N;
    vector<long long> A(N);
    long long sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        sum += A[i];
    }
    long long m = N * (N + 1) / 2;
    if (sum % m != 0) {
        cout << "NO" << endl;
        return 0;
    }
    long long num = sum / m;

    for (int i = 0; i < N; i++) {
        long long gap = 0;
        if (i != N - 1) {
            gap = A[i + 1] - A[i] - num;
        } else {
            gap = A[0] - A[N - 1] - num;
        }
        if (gap % N != 0 || gap > 0) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
}

Measured memory_bytes: 1024
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

struct Nde{
    int to, cost;
};

struct cmp{
    bool operator()(const pair<int, int>&a, const pair<int, int> &b){
        if(a.first == b.first) return a.second < b.second;
        return a.first < b.first;
    }
};
LL d[110][110];
int main() {
    //cout << fixed << setprecision(8);
    int n, m, s, g1, g2;
    while(cin >> n >> m >> s >> g1 >> g2) {
        if (n == 0) break;

        vector<vector<pair<int, int>>> G(1010);

        s--;
        g1--;
        g2--;
        REP(i,110){
            REP(j, 110){
                if(i!=j)
                    d[i][j] = 1e9;
                else d[i][j]=0;
            }
        }
        REP(i, m) {
            int b1, b2, c;
            cin >> b1 >> b2 >> c;
            b1--;
            b2--;
            d[b1][b2] = c;
        }


        for(int k=0; k<n; ++k){
            for(int i=0; i<n; ++i){
                for(int j=0; j<n; ++j){
                    d[i][j]= min(d[i][j], d[i][k]+d[k][j]);
                }
            }
        }

        LL ans = 1e9;
        for(int i=0; i<n; ++i){
            ans = min(ans, d[s][i]+d[i][g1]+d[i][g2]);
        }
        cout << ans << endl;
    }

    return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int a, b, c;
  cin >> a >> b >> c;
  if((b-a) == (c-b)){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
//03
#include<iostream>
#include<string>

using namespace std;

int main(){
  for(string s;cin>>s,s!="#";){
    int p[][2]={{1,2},{6,3},{1,6},{4,5},{5,2},{2,1},{6,6}};
    int c=0;
    for(int i=0;i<s.size();i++){
      c=p[c][s[i]-'0'];
    }
    cout<<((c==5)?"Yes":"No")<<endl;
  }
  return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<int> p(n);
  for(int i=0;i<n;i++)cin>>p[i];
  
  int m=p[0], ans=0;
  for(int i=0;i<n;i++){
    if(p[i]<=m){
      ans++;
      m=p[i];
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

const int D=365,A=26,K=3;

int d;
int c[A],s[D][A],last[A];

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>d;
    for(int j=0;j<A;j++)
        cin>>c[j],
        last[j]=-1;
    for(int i=0;i<d;i++)
        for(int j=0;j<A;j++)
            cin>>s[i][j];
    for(int i=0;i<d;i++)
    {
        int best=0;
        for(int j=0;j<A;j++)
            if(s[i][j]+c[j]*(i-last[j])*min(K,d-i)>
               s[i][best]+c[best]*(i-last[best])*min(K,d-i))
                best=j;
        last[best]=i;
        cout<<best+1<<"\n";
    }
}


Measured memory_bytes: 3720
<?php
$b=trim(fgets(STDIN))-1;
$a=explode(' ',trim(fgets(STDIN)));
for($i=1;$i<=$b;$i++)$a[$i]+=$a[$i-1];
$c=1<<31;
for($i=0;$i<$b;$i++)$c=min($c,abs($a[$b]-2*$a[$i]));
echo $c.PHP_EOL;

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

int main() {
  int N;
  cin>>N;
  vector<int> p(100001);
  vector<int> q(100001);
  vector<int> t(100001);
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    if(i%2==1){
      p.at(a)++;
    }
    else{
      q.at(a)++;
    }
    t.at(a)++;
  }
  sort(p.begin(), p.end());
reverse(p.begin(), p.end());
    sort(q.begin(), q.end());
reverse(q.begin(), q.end());
  sort(t.begin(), t.end());
reverse(t.begin(), t.end());
  if(t.at(0)==p.at(0)+q.at(0)){
    cout<<N-max(p.at(0)+q.at(1),p.at(1)+q.at(0))<<endl;
  }
  else{
    cout<<N-p.at(0)-q.at(0)<<endl;
  }
 
}

Measured memory_bytes: 4536
var
    n,p,m,i,j:longint;
    x,y,d:array[0..1010] of longint;
begin
    readln(n);
    readln(x[1],y[1]);
    p:=abs(x[1]+y[1]) mod 2;
    for i:=2 to n do
        begin
            readln(x[i],y[i]);
            if p<>abs(x[i]+y[i]) mod 2 then 
                begin
                    writeln(-1);exit;
                end;
        end;
    m:=31+1-p;writeln(m);d[31]:=1;
    for i:=30 downto 1 do d[i]:=d[i+1]*2;
    if m=32 then d[32]:=1;
    for i:=1 to m do write(d[i],' ');writeln;
    for i:=1 to n do 
        begin 
            for j:=1 to m do
                if abs(x[i])>abs(y[i]) then
                    if x[i]>0 then begin dec(x[i],d[j]);write('R');end
                    else begin inc(x[i],d[j]);write('L');end
                else 
                    if y[i]>0 then begin dec(y[i],d[j]);write('U');end
                    else begin inc(y[i],d[j]);write('D');end;
            writeln;
        end;
end.

Measured memory_bytes: 128
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int h,w;
bool checkTate(vector<vector<char>> &a, int x){
  rep(i, h){
    if(a[i][x] == '#') return false;
  }
  return true;
}
bool checkYoko(vector<vector<char>> &a, int y){
  rep(i, w){
    if(a[y][i] == '#') return false;
  }
  return true;
}
int main(){
  cin >> h >> w;
  vector<vector<char>> a(h, vector<char>(w));
  rep(i, h) rep(j, w) cin >> a[i][j];
  rep(i, h){
    if(checkYoko(a, i)) continue;
    rep(j, w){
      if(checkTate(a, j)) continue;
      cout << a[i][j];
    }
    cout << endl;
  }
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    map<ll, ll> mp;
    ll N;
    cin >> N;
    vector<ll> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        mp[A[i]]++;
    }
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());
    ll beki[32];
    beki[0] = 1;
    for(ll i = 1; i <= 30; i++) {
        beki[i] = beki[i - 1] * 2;
    }
    ll ans = 0;
    ll index = A.size();
    index--;
    for(ll i = 30; i >= 0; i--) {
        //cout << index << " " << i << " " << ans << endl;
        ll val;
        while(index >= 0) {
            val = A[index];
            if(val < beki[i]) {
                i--;
                continue;
            }
            if(mp[val] == 0 || val >= 2 * beki[i]) {
                index--;
            } else break;
        }
        if(index == -1) break;
        if(val == beki[i]) {
            ans += mp[val] / 2;
            index--;
            i++;
            continue;
        }
        ll delta = min(mp[val], mp[2 * beki[i] - val]);
        mp[2 * beki[i] - val] -= delta;
        ans += delta;
        index--;
        i++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 26752
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

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

	int m,d;
	cin>>m>>d;
	int t=0;
	loop(i,1,m+1)loop(j,1,d+1){
		int d1=j%10,d10=j/10;
		if(d1>=2&&d10>=2&&d1*d10==i)t++;
	}
	cout<<t<<endl;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> rs(n);
    
    for (int i=0; i<n; i++){
        cin >> rs.at(i);
    }
    
    int tempmax = rs.at(n-1);
    vector<int> rmaxs(n-1);
    rmaxs.at(n-2) = tempmax;
    
    for (int i=n-2; i>0; i--){
        if (rs.at(i) > tempmax)
          tempmax = rs.at(i);
        rmaxs.at(i-1) = tempmax;
    }
    
    int ans = rmaxs.at(0) - rs.at(0);
    
    for (int i=0; i<n-1; i++){
        if (rmaxs.at(i) - rs.at(i) > ans)
          ans = rmaxs.at(i) - rs.at(i);
    }
    
    cout << ans << endl;
    
  }




Measured memory_bytes: 4432