akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;


int res[500][500];
int main(){
    int h, w, k;
    cin >> h >> w >> k;
    vector<string>s(h);
    rep(i, h)cin >> s[i];

    vector<bool>none(h, true);
    rep(i, h){
        bool f = true;
        rep(j, w){
            if(s[i][j] == '#')f = false;
            res[i][j] = -1;
        }
        if(f)none[i] = false;
    }

    int now = 1;
    rep(i, h){
        if(!none[i])continue;
        bool f = true;
        rep(j, w){
            if(f && s[i][j] == '#'){
                f = false;
            }
            else if(!f && s[i][j] == '#'){
                now++;
            }
            res[i][j] = now;
        }
        now++;
    }


    rep(j, w){
        rep(i, h - 1){
            if(res[i + 1][j] == -1 && res[i][j] != -1){
                res[i + 1][j] = res[i][j];
            }
        }
    }

    rep(j, w){
        for(int i = h - 1; i > 0; i--){
            if(res[i - 1][j] == -1 && res[i][j] != -1){
                res[i - 1][j] = res[i][j];
            }
        }
    }
    rep(i, h){
        rep(j, w)cout << res[i][j] << " ";
        cout << endl;
    }
}

Measured memory_bytes: 1536
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        Integer d[] = new Integer[N];
        for (int i = 0; i < N; i++) {
            d[i] = Integer.parseInt(sc.next());
        }

        Arrays.sort(d, Comparator.naturalOrder());

        int count = 0;
        for (int i = 0; i < N-1; i++) {
            if (d[i] != d[i+1]) {
                count++;
            }
        }
        System.out.println(count + 1);
    }
}


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

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


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);

int main() {
    ll n, q;
    string s;
    cin >> n >> q;
    cin >> s;
    vector<ll> a(n);

    a[0] = 0;
    frep(i, 1, n-1) {
        if(s[i-1] == 'A' && s[i] == 'C') a[i] = (a[i-1]+1);
        else a[i] = a[i-1];
    }

    rep(i, q) {
        ll l, r;
        cin >> l >> r;
        l--; r--;
        cout << a[r]-a[l] << endl;
    }

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        ret %= MOD;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}



Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int N,candy[2][105],ans,l[2][2]={{1,0},{0,1}};
void F(int x,int y,int tot)
{
	if(x==1 && y==N-1)
	{
		ans=max(ans,tot+candy[x][y]);
		return;
	}
	for(int i=0;i<2;i++)
	{
		int sx=x+l[i][0],sy=y+l[i][1];
		if(sx>=2 || sy>=N) continue;
		F(sx,sy,tot+candy[x][y]);
	}
}
int main()
{
	scanf("%d",&N);
	for(int i=0;i<2;i++)
		for(int j=0;j<N;j++)
			scanf("%d",&candy[i][j]);
	F(0,0,0);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
	int i=700;
	char a,b,c;
	scanf("%c%c%c",&a,&b,&c);
	if(a=='o') i=i+100;
	if(b=='o') i=i+100;
	if(c=='o') i=i+100;
	printf("%d",i);
	return 0;
}

Measured memory_bytes: 128
def main():
    temp = map(int,raw_input().split())
    a = map(int,raw_input().split())
    n = 0
    cnt = 1
    for i in a:
        n = n + i
        if temp[1] >= n:
            cnt = cnt + 1
        else:
            break

    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2568
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    set<int> s;
    imfor(i, n) {
        int d;
        cin >> d;
        s.insert(d);
    }
    cout << s.size() << endl;
}

Measured memory_bytes: 256
import sys
inputs = sys.stdin.readlines()

n = int(inputs[0])
Y = []
for s in inputs[1:]:
    x, l = map(int, s.split())
    Y.append((x-l, x+l))
Y.sort(key=lambda x: x[1])

cnt = 1
_, r0 = Y[0]
for i in range(1, n):
    l, r = Y[i]
    if r0 <= l:
        cnt += 1
        r0 = r
    
print(cnt)

Measured memory_bytes: 69084
n = int(input())
a = list(map(int,input().split()))

if all(i == 0 for i in a):
    print('Yes')
    exit()

p = n // 3
if n % 3 != 0:
    print('No')
    exit()

if 0 in a:
    a = sorted(a)
    zero = a.count(0)
    if zero != p:
        print('No')
        exit()
    if a[p] != a[-1]:
        print('No')
        exit()
    print('Yes')
    exit()

a = sorted(a)
if a.count(a[0]) != p or a.count(a[p]) != p or a.count(a[-1]) != p:
    print('No')
else:
    if a[0] ^ a[p] == a[-1]:
	    print('Yes')
    else:
        print('No')


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string n; cin >> n;
    ll size = n.size();
    ll now = 0;
    for(int i=0;i<size;i++) now += (n[i] - '0');
    ll nines = 0;
    nines += (n[0] - '0' - 1);
    nines += 9*(size - 1);
    // cout << now << " " << nines << endl;
    cout << max(now, nines) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  vector<int>dp(k+1,0);
  dp[0]=1;
  for(int i=0;i<n;i++){
    if(arr[i]<=k)
      dp[arr[i]]=1;
    if(arr[i]==k){
      cout<<"First"<<endl;
      return 0;
    }
  }
  for(int i=1;i<=k;i++){
    if(dp[i]==1)continue;
    int fl=0;
    for(int j=0;j<n;j++){
      if(i<arr[j])continue;
      if(dp[i-arr[j]]==0){
        dp[i]=1;
        fl=1;break;
      }
    }
    if(fl==0)
      dp[i]=0;
  }
  if(dp[k]==1)
    cout<<"First"<<endl;
  else
    cout<<"Second"<<endl;
}

Measured memory_bytes: 3752
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int cal(string);
string ch(int);
int main(){
  int l,i,j,len,calc,max,min,h,flag;
  string s,s1,s2,st[21];
  while(1){
    flag=0;
    cin >> s >> l;
    st[0]=s;
    if(s=="0"&&l==0) break;
    for(h=1;h<=20;h++){
      len=s.size();
      if(len<l){
	for(i=len;i<l;i++){
	  s=s+'0';
	}
      }
      s1=s;
      s2=s;
      for(i=0;i<l;i++){
	for(j=1;j<l;j++){
	  if(s1[j]>s1[j-1]) swap(s1[j],s1[j-1]);
	}
      }
      max=cal(s1);
      for(i=0;i<l;i++){
	for(j=1;j<l;j++){
	  if(s2[j]<s2[j-1]) swap(s2[j],s2[j-1]);
	}
      }
      min=cal(s2);
      calc=max-min;
      s=ch(calc);
      st[h]=s;
      if(st[h].size()==0) st[h]="0";
      for(i=0;i<h;i++){
	if(st[h]==st[i]){
	  cout << i << ' ' << st[h] << ' ' << h-i << endl;
	  flag=1;
	  break;
	}
      }
      if(flag==1) break;
    }
  }
  return 0;
}
int cal(string change){
  int len,i,ret=0,x=1;
  len=change.size();
  for(i=len-1;i>=0;i--){
    ret+=x*(change[i]-'0');
    x*=10;
  }
  return ret;
}
string ch(int calc){
  string ret,retfi;
  char retf[7];
  int len,i;
  while(calc){
    ret+=calc%10+'0';
    calc/=10;
  }
  len=ret.size();
  for(i=0;i<len;i++){
    retf[i]=ret[len-i-1];
    retfi+=retf[i];
  }
  return retfi;
}

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

using namespace std;

int main()
{
    int n,sum=0,k,var;
    cin>>n >> k;
    for(int i=1; i<=n; ++i){
        cin>> var;
    }
    if((n-k) % (k-1) != 0)
        sum++;
    k=(n-k)/(k-1);

    cout << 1 + k + sum;;
    return 0;
}


Measured memory_bytes: 256
import itertools as it
import collections as col
import bisect

import sys
sys.setrecursionlimit(10000)

def main():
    N, T = [int(x) for x in input().split()]
    constraints = [tuple([int(x) for x in input().split()]) for _ in range(N)]
    legal = [x[0] for x in constraints if x[1] <= T]
    if (legal):
        return min(legal)

    return "TLE"
    
    
if __name__ == '__main__':
    print(main())

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

  #define vi vector<int>
  #define all(v) v.begin(),v.end()
  #define ll long long int
  #define  IOS    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define D1(x) {cerr<<" [" <<#x<<": "<<x<<"]";cout << endl;}
  #define D2(x) {cerr<<" [" <<#x<<": ";for(auto it:x)cerr<<it<< " ";cerr<<"] ";cout << endl;}

  const ll MOD=1e9+7;

  void solve(){
     ll n;
     cin >> n;
     cout << 800LL*(n) - 200*(n/15);
  }


  int main(){
    IOS
       solve();
       cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }
// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


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

using namespace std;

#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'

int n, m;
vector<int> cnt;
string s;

int main()
{
	IOS;
	cin >> n >> m >> s;
	cnt.resize(n+1);
	for (int i = 0; i < n -1 ; i++) {
		cnt[i+1] = cnt[i];
		if (s[i] == 'A' && s[i+1] == 'C') cnt[i+1]++;
	}
	while (m--) {
		int l, r;
		cin >> l >> r;
		l--, r--;
		cout << cnt[r] - cnt[l] << endl;
	}
	return 0;
}



Measured memory_bytes: 1488
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
ll euclidean_lcm(ll a, ll b) {
  return a/euclidean_gcd(a,b)*b;
}

ll binary(ll bina){
    ll ans = 0;
    for (ll i = 0; bina>0 ; i++)
    {
        ans += bina%2;
        bina = bina/2;
    }
    return ans;
}
void revStr(char* str){
	int size = strlen(str);
	int i,j;
	char tmp = {0};
	
	for(i = 0, j = size - 1; i < size / 2; i++, j--){
		tmp = str[i];
		str[i] = str[j];
		str[j] = tmp;
	}
	return;	
}
int main(void){
  ll n;
  cin >> n;
  ll a[n],l=0,ans=0;
  rep(i,n){
    cin >> a[i];
    l=(l+a[i])%1000000007;
  }
  rep(i,n){
    l=(l-a[i]+1000000007)%1000000007;
    ans=(ans+a[i]*l%1000000007)%1000000007;
  }
  cout << (ans+1000000007)%1000000007;
}

Measured memory_bytes: 5132
import bisect,sys
import math
from collections import deque

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac =fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % mod) % mod
        
    return CONV()



sys.setrecursionlimit(200005)


def main():
    K = iRaw()
    if K <= 10:
        return K
    runrun = [1,0]
    leftK = K-10
    while leftK >0:
        leftK-=1
        lenRun = len(runrun)
        digit = lenRun -1
        while digit>0:
            if runrun[digit] <runrun[digit-1]:
                runrun[digit]+=1
                break
            if runrun[digit] == runrun[digit-1] and runrun[digit]!=9:
                runrun[digit]+=1
                break
            digit -=1
        
        if digit==0:
            if runrun[0] < 9:
                runrun[0]+=1
            else:
                runrun = [1]+([0]*lenRun)
                continue
        for idx in range(digit+1,lenRun):
            runrun[idx] = max(runrun[idx-1]-1,0)

    return "".join([str(r) for r in runrun])
    
if __name__ == "__main__":
    print(main())


Measured memory_bytes: 43888
n = gets.strip.to_i
a = gets.strip.split.map(&:to_i)
b = gets.strip.split.map(&:to_i)
c = gets.strip.split.map(&:to_i)

s = 0

(1..n).each do |i|
  s += b[a[i-1]-1]
  if i > 1 && ( a[i-1] - a[i-2] ) == 1
    s += c[a[i-2]-1]
  end
end

puts s


Measured memory_bytes: 1788
using System;
class Program{
	static void Main(){
		int n=int.Parse(Console.ReadLine());
		long[] a=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
		Array.Sort(a);
		long ans=1,r=a[0];
		for(int i=1;i<n;i++){
			if(r*2>=a[i]){ans++;}
			else{ans=1;}
			r+=a[i];
		}
		Console.WriteLine("{0}",ans);
	}
}

Measured memory_bytes: 27740
#include<bits/stdc++.h>
using namespace std;
long long int serch(long long int n)
{
    if(n==1)return n;
    return n*serch(n-1);
}
int main()
{
    long long int n;
    cin>>n;
    n=serch(n);
    cout<<n<<endl;
}

Measured memory_bytes: 1156
<?php
list($S)=sscanf(trim(fgets(STDIN)),"%s");
list($T)=sscanf(trim(fgets(STDIN)),"%s");
if((strpos($T,$S) !== FALSE)&&($S[0] == $T[0])&&(strlen($T) == strlen($S) + 1)){
    print("Yes");
}else{
    print("No");
}

Measured memory_bytes: 16188
#include<stdio.h>

int main(){
	long n[2];
	long i, j, x, y;
	while(scanf("%d %d",&n[0],&n[1])!=EOF){
		for(i=1;i<=n[1];i++){
			x = n[0]*i;
			if(x%n[1]==0){
				break;
			}
		}
		for(j=1;j<=n[0];j++){
			if(n[0]%j!=0) continue;
			y = n[0]/j;
			if(n[1]%y==0){
				break;
			}
		}
		printf("%d %d\n",y,x);
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (size_t i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (size_t i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define INF 1e7


int main()
{
  string input, ans = "";
  cin>>input;

  REP(i,input.size()) {
    if (input[i] == '0') ans += '0';
    else if (input[i] == '1') ans += '1';
    else ans = ans.substr(0, ans.size()-1);
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int n;
int main(){
  cin >> n;
  int nsqrt = sqrt(n);
  int ret = 1;
  for(int i=2; i<=nsqrt; i++){
    int tmp = 1;
    while(i*tmp <= n) tmp *= i;
    if(tmp != i) ret = max(ret, tmp);
    }
  cout << ret << endl;
  return 0;
  }


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

int main(){
    int n;
    scanf("%d",&n);
    for (int i=3;i<=n;i++) {
        int x=i;
        if (i%3==0 || i%10==3) {
            printf(" %d",i);
        } else {
            while (x>0) {
                if (x%10==3) {
                    printf(" %d",i);
                    break;
                }
                x/=10;
            }
        }
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 3212
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;

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

    vector<pair<int, int>> v;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        v.emplace_back(a, i + 1);
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++) {
        if (i != 0) cout << " ";
        cout << v[i].second;
    }
    cout << endl;
}

Measured memory_bytes: 1780
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

from collections import defaultdict
# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np

def main():
	n=int(input())
	
	d=defaultdict(int)
	
	li=[]
	
	for i in range(n):
		s=input().rstrip().decode('utf-8')
		d[s]+=1
	for k,v in d.items():
		li.append((v,k))
	li.sort(reverse=True)
	
	cnt=li[0][0]
	
	li2=[]
	
	for v,k in li:
		if v==cnt:
			li2.append(k)
	li2.sort()
	
	for i in li2:
		print(i)
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 45664
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
#define per(i,n) for ((i)=n;(i)>=(1);(i)--)
using namespace std;
int n,i,f,pos[200005],ans;
int main(){
	cin>>n;
	rep(i,n){
		int x;cin>>x;
		pos[x]=i; 
	}
	per(i,n-1){
		if(!ans){
			if(pos[i]>pos[i+1]){
				ans=1;
				f=i+1;
				continue;
			}
		}
		if(pos[f]<pos[i]&&pos[i]<pos[i+1]) continue;
		if(pos[i]<pos[i+1]&&pos[i+1]<pos[f]) continue;
		if(pos[i+1]<pos[f]&&pos[f]<pos[i]) continue;
		ans++;f=i+1;
	}
	cout<<ans<<endl;
	return 0;
}

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

void swap(int &a,int &b)
{
    if(b<a)
    {
        int i;
        i=a;
        a=b;
        b=i;
    }
}

int ButtleSort(int n,int *p)
{
    int num=0;
    for(int i=0;i<n-1;i++)
    {
        for(int j=n-1;j>i;j--)
        {
            if(*(p+j)<*(p+j-1))
            {
                swap(*(p+j-1),*(p+j));
                num++;
            }
        }
    }
    return num;
}

int main(int argc, char const *argv[])
{
    int N,*p,num;
    cin>>N;
    p=new int[N];
    for(int i=0;i<N;i++)    cin>>*(p+i);
    num=ButtleSort(N,p);
  // swap(*(p+1),*(p+2));
    for(int i=0;i<N-1;i++)  cout<<*(p+i)<<" ";
    cout<<*(p+N-1)<<endl<<num<<endl;

    delete []p;
    //system("pause");
    return 0;
}



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

typedef pair<int, int> P;

int R, C;
vector<vector<char>> c(1000, vector<char>(1000));
vector<vector<int>> v(1000, vector<int>(1000, 1e9));
queue<P> que;

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
void bfs() {
    while (!que.empty()) {
        P p = que.front();
        que.pop();
        for (int i = 0; i < 4; i++) {
            int y = p.first + dy[i], x = p.second + dx[i];
            int cost = v[p.first][p.second] + 1;
            if (0 <= y && y < R && 0 <= x && x < C && c[y][x] != '#' &&
                v[y][x] > cost) {
                que.push(P(y, x));
                v[y][x] = cost;
            }
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> R >> C;
    for (int i = 0; i < R; i++) {
        for (int j = 0; j < C; j++) {
            cin >> c[i][j];
            if(c[i][j]=='#'){
                que.push(P(i, j));
                v[i][j] = 0;
            }
        }
    }
    bfs();
    int max_cost = 0;
    for (int i = 0; i < R; i++) {
        for (int j = 0; j < C; j++) {
            max_cost = max(max_cost, v[i][j]);
        }
    }
    cout << max_cost << endl;
}

Measured memory_bytes: 13456
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}
 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;
}




int main()
{ 

  IOS;

ll n;cin>>n;

vl a(n);

ll ans=1e18;
ll k=0,s=0;
for(int i=0;i<n;i++){
  cin>>a[i];
  s+=a[i];
 // ans=min({ans,abs(2*k)})
}

for(int i=0;i<n;i++){
k+=a[i];
ans=min({ans,abs(2*k-s),abs(2*s-k)});
}

cout<<ans<<endl;



return 0;
 
}



Measured memory_bytes: 4776
import java.util.Scanner;

public class Main {

	int f(int x) {
		return x+1;
	}
	
	void main() {
		try(Scanner sc = new Scanner(System.in)){
			for(;;) {
				int x = sc.nextInt();
				int y = sc.nextInt();
				if(x == 0 && y == 0)break;
				if(x >= y) {
				System.out.println(y + " " + x);
				}
				else {
					System.out.println(x + " " + y);
				}
				
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().main();
	}

}



Measured memory_bytes: 36108
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
 
using namespace std;
 
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;
 
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  string s;
  cin >> s;
  sort(all(s));
  char pre = '-';
  int j = 0;
  rep(i, (int)s.size()){
    if(pre == s[i]) continue;
    pre = s[i];
    if(s[i] != (char)((int)'a'+j)) break;
    j++;
  }
  if(j < 26) cout << (char)((int)'a'+j) << endl;
  else cout << "None" << endl;
	return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
const long long INF = 9999999999999999999;
const int MOD = 1e9 + 7;
const double pi = 3.141592653589793238;
const int SIZE = 1 << 17;

int main() {
	double a, b;
	cin >> a >> b;
	cout << setprecision(20) << a / b << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <algorithm>
#include <tuple>
#include <numeric>

long gcd(long a, long b)
{
	while (b != 0) {
		a %= b;
		std::swap(a, b);
	}
	return a;
}

int main()
{
	int N;
	std::vector<long> A;

	std::cin >> N;
	A.resize(N);
	for (auto& a : A) {
		std::cin >> a;
	}

	long x = A[0];
	for (int i = 1; i < N; ++i) {
		x = gcd(x, A[i]);
	}

	std::cout << x << "\n";

	return 0;
}


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

#define M 1000000007
#define MM 998244353 
#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define PI 3.1415926536
#define INF 2e18
#define endl "\n"
#define llevel 20
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}

int _runtimeTerror_()
{
	string s;
	cin>>s;
	if(s[2]==s[3] && s[4]==s[5])
	{
		cout<<"Yes";
	}
	else cout<<"No";
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifdef runSieve
		sieve();
	#endif
	#ifdef NCR
		initialize();
	#endif
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
		_runtimeTerror_();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define rep2(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=2e5+7;
void upd(int& x,int y){x+=y;if(x>=mod)x-=mod;} 
int qpow(int a,int b){int aa=a,res=1;for(;b;b>>=1){if(b&1)res=1ll*res*aa%mod;aa=1ll*aa*aa%mod;}return res;}
int bin[N],pin[N];
void init(){bin[0]=pin[0]=1;
	rep(i,1,N-1)bin[i]=1ll*bin[i-1]*i%mod;
	pin[N-1]=qpow(bin[N-1],mod-2);
	rep2(i,N-2,1)pin[i]=1ll*pin[i+1]*(i+1)%mod;
}
int n,X,Y,c[N],w[N],p[N],mi,mi2,sz[N],col[N],dif[N];
int find(int x){
	return p[x]==x ? x : p[x]=find(p[x]);
}
void merge(int x,int y){
	int px=find(x),py=find(y);
	if(px==py)return;
	p[py]=px,sz[px]+=sz[py];
}
bool cmp(int x,int y){return w[x]<w[y];}
vector<int> tu[N]; 
int main(){
	init();
	scanf("%d%d%d",&n,&X,&Y);
	rep(i,1,n){
		scanf("%d%d",&c[i],&w[i]);
		p[i]=i,sz[i]=1;
		col[c[i]]++;
		tu[c[i]].push_back(i);
		if(!mi || w[i]<w[mi])mi=i;
	}
	rep(i,1,n)if(c[i]!=c[mi]){
		if(!mi2 || w[i]<w[mi2])mi2=i;
	}
	rep(i,1,n)if(tu[i].size()){
		sort(tu[i].begin(),tu[i].end(),cmp);
		rep(j,0,tu[i].size()-1){
			int v=tu[i][j];
			if(w[v] + w[tu[i][0]] <= X)merge(v,tu[i][0]);
			if(w[v] + w[mi] <=Y && c[v]!=c[mi])merge(v,mi);
			if(mi2 && w[v] + w[mi2] <=Y && c[v]!=c[mi2])merge(v,mi2);
		}
	}
	int tot=n;
	rep(i,1,n)if(c[i]!=c[find(i)])dif[find(i)]=1;
	rep(i,1,n)if(!dif[find(i)])tot--,col[c[i]]--;
	
	int ans=bin[tot];
	rep(i,1,n)ans=1ll*ans*pin[col[i]]%mod;
	printf("%d\n",ans);
}

Measured memory_bytes: 18048
#include<stdio.h>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=500100,P=998244353;
inline char gc(){
    static char buf[N],*s=buf,*t=buf;
    return s==t&&(t=(s=buf)+fread(buf,1,N,stdin),s==t)?EOF:*s++;
}
inline int read(){
	int x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10+'0');
}
#include<vector>
vector<int>s[N];
int n,a[N],v[N],q[N],f[N],g[N];
inline bool cmp(int x,int y){return f[x]<f[y];}
int main(){
	//freopen("1.out","w",stdout);
	int i,l,r=0,x,y;
	n=read();
	for(i=2;i<=n;i++)
		a[i]=read(),v[a[i]]++,s[a[i]].push_back(i);
	for(i=1;i<=n;i++)if(!v[i])q[++r]=i;
	for(l=1;l<=r;l++){
		x=q[l];
		sort(s[x].begin(),s[x].end(),cmp);
		for(i=0;i<(int)s[x].size();i++){
			y=s[x][i];
			f[x]=max(f[x],f[y])+1;
		}v[a[x]]--;if(!v[a[x]])q[++r]=a[x];
	}printf("%d\n",f[1]);
	return 0;
}

Measured memory_bytes: 22912
from collections import deque
from copy import deepcopy
N, K = map(int, input().split())
#V = list(map(int, input().split()))
V = deque(map(int, input().split()))
ans = 0
for l in range(K + 1):
    for r in range(0 , K - l + 1):
        work_V = deepcopy(V)
        if l + r > N:
            continue
        d = K - (r + l)
        now = 0
        hold = []
        for i in range(l):
            #hold.append(V[i])
            hold.append(work_V.popleft())
        for i in range(N - r , N):
            #hold.append(V[-i])
            hold.append(work_V.pop())
        hold.sort()
        now = sum(hold)
        for i in range(d):
            if i >= len(hold):
                break
            if hold[i] > 0:
                break
            else:
                now -= hold[i]
        ans = max(ans , now)
print(ans)

Measured memory_bytes: 3436
#include<stdio.h>
int main(){
  int n ,i ,x=100000 ,y;
  scanf ( "%d" ,&n );

  for ( i=0 ; i<n ; i++ ){
    x = x * 1.05;
    y = x % 1000;
    if ( y >= 1 ){
      x = x / 1000;
      x = x + 1;
      x = x * 1000;
    }
  }

  printf ( "%d\n" ,x );
  return 0;
}

Measured memory_bytes: 592
from collections import deque

h, w = map(int, input().split())

S = [[] for _ in range(h)]
# まず、最初にある白マスの数を数えておく
ans = 0
for i in range(h):
    S[i] = input()
    ans += S[i].count('.')

direct = [[0, 1], [0, -1], [1, 0], [-1, 0]]

# BFS
# 距離を初期化.
D = [[-1] * w for _ in range(h)]
D[0][0] = 0

# 現在地でキューを初期化.
que = deque([[0, 0]])

# キューがなくなるまで探索を行う.
while que:
    # キュー（右から）を一つ取り出す.
    chi, cwi = que.pop()

    for (dh, dw) in direct:
        # 迷路の範囲外なら探索しない.
        if not (0 <= chi + dh <= h - 1 and 0 <= cwi + dw <= w - 1):
            continue
        # 探索済みや探索不可なところは探索しない.
        if D[chi + dh][cwi + dw] != -1 or S[chi + dh][cwi + dw] == '#':
            continue
        # 距離の計算.
        D[chi + dh][cwi + dw] = D[chi][cwi] + 1
        # 次に探索する場所の追加.
        que.appendleft([chi + dh, cwi + dw])

dist = D[-1][-1]
# もともとあった白マスの数 - (ゴールまでに辿る最小の白マス+スタートの1マス)
if dist != -1:
    print(ans - (dist + 1))
else:
    print(-1)


Measured memory_bytes: 9500
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

def solve(L):
    m = min(L)
    cnt = L.count(m)

    if cnt > 4:
        return False
    for _ in xrange(cnt):
        L.remove(m)
    if cnt in (1, 4):
        if not L.count(m+1) or not L.count(m+2):
            return False
        L.remove(m+1)
        L.remove(m+2)
    elif cnt == 2:
        if L.count(m+1) < 2 or L.count(m+2) < 2:
            return False
        L.remove(m+1)
        L.remove(m+1)
        L.remove(m+2)
        L.remove(m+2)
    return True if not len(L) else solve(L)

for line in stdin:
    data = [int(s) for s in line.strip()]
    data.append(0)
    answers = []

    for i in xrange(1, 10):
        data[-1] = i
        if data.count(i) > 4:
            continue
        for pair in xrange(1, 10):
            if data.count(pair) < 2:
                continue
            L = data[:]
            L.remove(pair)
            L.remove(pair)
            if solve(L):
                answers.append(str(i))
                break
    print(' '.join(answers) if answers else '0')

Measured memory_bytes: 4296
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int solveL(const string& s, const vector<pair<char,char>>& v){
  int lb = 0, ub = s.size();
  while(ub-lb>1){
    int m = (lb+ub)/2;
    {
      int pos = m;
      rep(i,v.size()){
        if(s[pos] == v[i].first){
          if(v[i].second == 'L') pos--;
          else pos++;
        }
        if(pos <= 0) break;
      }
      if(pos <= 0) lb = m;
      else ub = m;
    }
  }
  return ub;
}

int solveR(const string& s, const vector<pair<char,char>>& v){
  int lb = 0, ub = s.size();
  while(ub-lb>1){
    int m = (lb+ub)/2;
    {
      int pos = m;
      rep(i,v.size()){
        if(s[pos] == v[i].first){
          if(v[i].second == 'L') pos--;
          else pos++;
        }
        if(pos >= s.size()-1) break;
      }
      if(pos >= s.size()-1) ub = m;
      else lb = m;
    }
  }
  return lb;
}

int main(){
  int N, Q;
  cin >> N >> Q;
  string s;
  cin >> s;
  s = "*" + s + "*";

  vector<pair<char,char>> v;
  rep(i,Q){
    char t, d;
    cin >> t >> d;
    v.emplace_back(t, d);
  }

  int lpos = solveL(s, v);
  int rpos = solveR(s, v);

  if(lpos >= rpos) cout << 0 << endl;
  else cout << rpos - lpos + 1 << endl;
  
  return 0;
}



Measured memory_bytes: 1240
import java.util.Scanner;
import java.util.ArrayList;
 
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
      ArrayList<String> list = new ArrayList<String>();
      int x_1,x_2,x_3,x_4,x_5;
      int i = 0;
      String an = scan.nextLine();
      String atai[] = an.split(" ",0);
      int num[] = new int[5];
      while(i < 5){
        num[i] = Integer.parseInt(atai[i]);
        i++;
      }
      x_1 = num[0];
      x_2 = num[1];
      x_3 = num[2];
      x_4 = num[3];
      x_5 = num[4];
//      System.out.println(A+","+B+","+H+","+M);
      check(num);
        scan.close();
    }
  
  public static void check(int[] num){
   //System.out.println(num[0]);
    int i = 0;
    while(i<5){
      if(num[i] == 0){
        System.out.println(i+1);
        break;
      }
      i++;
    }
    return;
  }
}

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

string A,B;

int main(){

cin>>A>>B;

if(A.size()>B.size()) puts("GREATER");
else if(A.size()<B.size()) puts("LESS");
else{
    for(int i=0; i<A.size(); i++){
        if(A[i]-'0'>B[i]-'0'){
            puts("GREATER"); return 0;
        }
        if(A[i]-'0'<B[i]-'0'){
            puts("LESS"); return 0;
        }
    }
    puts("EQUAL");
}

}

Measured memory_bytes: 256
O=list(map(int, input().split()))
A=O[0]
B=O[1]
C=O[2]
K=O[3]

s= 0

if K <= A:
    s = K
elif K<=A+B:
    s = A
else:
    s = A-(K-A-B)
    
print(s)

Measured memory_bytes: 9124
# ABC132b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(1, n-1):
    if (p[i - 1] < p[i] < p[i + 1] or p[i - 1] > p[i] > p[i + 1]):
        ans += 1
print(ans)

Measured memory_bytes: 3064
// Author : Radhesh Sarma
   #include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp> 
  #include <ext/pb_ds/tree_policy.hpp>
  #pragma comment(linker, "/stack:200000000")
  #pragma GCC optimize("O3")
  #pragma GCC optimize("Ofast")
  #pragma GCC optimize("unroll-loops")
    using namespace std;
  using namespace __gnu_pbds;
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define endl "\n"
    #define int long long
    #define all(v) v.begin(),v.end()
    #define rep(i,a,b) for(int i = a; i <=b; i++)
    #define rep2(i,a,b) for(int i = a; i>=b; i--)
    #define PB push_back
    #define MP make_pair
    #define db long double
    #define trace1(x)                cerr<<#x<<": "<<x<<endl
    #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
    #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
    #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
    #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
    #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
    #define cases int testcases;cin>>testcases; while(testcases--)
    #define INF 2000000000
    const double PI = acos(-1);
    const int N =  200005;

   int n,m;

   
  int32_t main() 
  {
    IOS

      
     
      int n,k,r,s,p;
      cin >> n >> k >> r >> s >> p;

      string t;
      cin >> t;

      int ans = 0;
      bool ok[n+1];
      rep(i,0,n)
      {
        ok[i] = true;
      }

      for(int i = 1;i <=t.length(); i++)
      {
        if(i <= k)
        {
          if(t[i-1] == 'r')
          {
            ans += p;
          }
          else if(t[i-1] == 's')
          {
            ans += r;
          }
          else if(t[i-1] == 'p')
          {
            ans += s;
          }

        }
        else
        {
          if(t[i-1] == t[i-1-k] and ok[i-k-1])
          {
            ok[i-1] = false;
          }
          else
          {
                  if(t[i-1] == 'r')
                    {
                      ans += p;
                    }
                    else if(t[i-1] == 's')
                    {
                      ans += r;
                    }
                    else if(t[i-1] == 'p')
                    {
                      ans += s;
                    }
          }
        }
      }

      cout << ans;
    return 0;
  }

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,v,b,w,t;cin>>a>>v>>b>>w>>t;
    if(abs(a-b)<=t*(v-w))cout<<"YES";
    else cout<<"NO";
    return 0;
}

Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n;
  
  /*
  string s;cin>>s;
  vi a(n),b(n);
  REP(i,n) cin>>a[i];
  */
  cout<<(n-1)/2<<endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
if sum(A) < sum(B):
  print(-1)
else:
  C = [A[i] - B[i] for i in range(N)]
  D = sorted([c for c in C if c > 0])
  E = [c for c in C if c < 0]
  cnt = 0
  F = sum(E)
  while F < 0:
    F += D.pop()
    cnt += 1
  print(cnt + len(E))

Measured memory_bytes: 19536
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		long[] a=new long[n+1];
		for(int i=1; i<=n; i++){
			a[i]=sc.nextLong()+a[i-1];
		}
		long ans=Long.MAX_VALUE;
		for(int i=3; i<n; i++){
			int left=1;
			int right=i-1;
			int l=0;
			int r=0;
			while(right-left>1){
				int mid=(right+left)/2;
				if(a[i-1]-a[mid-1]>a[mid-1]){
					left=mid;
				}else{
					right=mid;
				}
			}
			if(a[i-1]-a[left-1]-a[left-1]>-a[i-1]+a[right-1]+a[right-1]){
				l=right;
			}else{
				l=left;
			}
			left=i;
			right=n;
			while(right-left>1){
				int mid=(right+left)/2;
				if(a[n]-a[mid-1]>a[mid-1]-a[i-1]){
					left=mid;
				}else{
					right=mid;
				}
			}
			if(a[n]-a[left-1]-a[left-1]+a[i-1]>-a[n]+a[right-1]+a[right-1]-a[i-1]){
				r=right;
			}else{
				r=left;
			}
			long max=Math.max(Math.max(a[l-1],a[n]-a[r-1]),Math.max(a[i-1]-a[l-1],a[r-1]-a[i-1]));
			long min=Math.min(Math.min(a[l-1],a[n]-a[r-1]),Math.min(a[i-1]-a[l-1],a[r-1]-a[i-1]));
			ans=Math.min(ans,max-min);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 90008
#include "bits/stdc++.h"
using namespace std;
int a[200010];

int main(int argc, char const *argv[])
{
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		if(a[i] > i) {
			printf("-1\n");
			exit(0);
		}
	}
	for(int i = 1; i < n; i++) {
		if(a[i - 1] + 1 < a[i]) {
			printf("-1\n");
			exit(0);
		}
	}
	long long ans = 0;
	for(int i = 1; i < n; i++) {
		if(a[i] != a[i - 1] + 1) {
			ans += a[i - 1];
		}
	}
	ans += a[n - 1];
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/perl -w
 
chomp(@lines = <>);
%cards = (
    a => [split //, shift @lines],
    b => [split //, shift @lines],
    c => [split //, shift @lines]
);
 
my $player = 'a';
while (1) {
    my $card = shift @{$cards{$player}};
    if ($card) {
 
        $player = $card;
    } else {
        last;
    }
}
 
print uc $player;

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,dp[100001],a[100001],b;
int main() {
  cin >> n >> m;
  for(int i=0; i<m; i++) {
    cin >> b;
    a[b]=1;
  }
  dp[0]=1;
  for(int i=1; i<=n; i++) {
    if(a[i-1]==0) {
      dp[i]+=dp[i-1];
    }
    if(a[i-2]==0) {
      dp[i]+=dp[i-2];
    }
    dp[i]%=1000000007;
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,Ka;
ll x[1000005],y[1000005];
int c[1000005];
int sum[2][5050][5050];

int main(void){
	scanf("%d%d",&n,&Ka);
	for(int i=0;i<n;i++){
		char col;
		scanf("%d%d%*c%c",&x[i],&y[i],&col);
		if(col=='B')c[i]=0;
		else c[i]=1;
		x[i]%=(Ka*2);
		y[i]%=(Ka*2);
		sum[c[i]][y[i]][x[i]]++;
		sum[c[i]][y[i]][x[i]+Ka]--;
		sum[c[i]][y[i]+Ka][x[i]]--;
		sum[c[i]][y[i]+Ka][x[i]+Ka]++;
		
		sum[c[i]][y[i]][x[i]+2*Ka]++;
		sum[c[i]][y[i]][x[i]+Ka+2*Ka]--;
		sum[c[i]][y[i]+Ka][x[i]+2*Ka]--;
		sum[c[i]][y[i]+Ka][x[i]+Ka+2*Ka]++;

		sum[c[i]][y[i]+2*Ka][x[i]+2*Ka]++;
		sum[c[i]][y[i]+2*Ka][x[i]+Ka+2*Ka]--;
		sum[c[i]][y[i]+Ka+2*Ka][x[i]+2*Ka]--;
		sum[c[i]][y[i]+Ka+2*Ka][x[i]+Ka+2*Ka]++;

		sum[c[i]][y[i]+2*Ka][x[i]]++;
		sum[c[i]][y[i]+2*Ka][x[i]+Ka]--;
		sum[c[i]][y[i]+Ka+2*Ka][x[i]]--;
		sum[c[i]][y[i]+Ka+2*Ka][x[i]+Ka]++;
	}
	for(int i=0;i<2;i++){
		for(int j=0;j<=5*Ka+5;j++){
			for(int k=0;k<=Ka*5+5;k++){
				sum[i][j][k+1]+=sum[i][j][k];
			}
		}
	}
	for(int i=0;i<2;i++){
		for(int j=0;j<=5*Ka+5;j++){
			for(int k=0;k<=Ka*5+5;k++){
				sum[i][k+1][j]+=sum[i][k][j];
			}
		}
	}
	int ans=0;
	for(int k=0;k<2;k++){
		for(int i=0;i<=4*Ka+1;i++){
			for(int j=0;j<=4*Ka+1;j++){
				int tmp=0;
				tmp+=sum[1-k][i][j];
				tmp+=sum[1-k][i+Ka][j+Ka];
				tmp+=sum[k][i+Ka][j];
				tmp+=sum[k][i][j+Ka];
				ans=max(ans,tmp);
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 205056
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
 
using namespace std;
 
typedef long long ll;
const int Maxn = 1e9 + 10;
const int N = 1e5 + 10;
const int INF=(0x7fffffff)/2;
int a[210];
 
int main(){
	int n;
	while(~scanf("%d", &n)){
		for(int i = 0; i < 2 * n; i++)
			cin >> a[i];
		sort(a, a + 2 * n);
		ll sum = 0;
		for(int i = 0; i < 2 * n; i = i + 2)
			sum += a[i];
		printf("%lld\n", sum);
		}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long lli;
const int maxn = 5e5 + 50;
typedef pair<int, int> P;

int arr[maxn];
int a, b, c, d, e, f, g;
void solve();
int main()
{
	int t = 1;
//	cin >> t;
	for(int i=0; i<t; i++)
	{
		solve();
	}
	return 0;
}

// type below

void solve()
{
	int S, W; cin >> S >> W;
	if(S > W) cout << "safe";
	else	  cout << "unsafe";
}


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

using namespace std;
int n, w;
int V[105], W[105];
long long dp[105][100005];

long long solve(int idx, int w) {
    if (idx == n)
        return 0;
    if (dp[idx][w] != -1)
        return dp[idx][w];
    long long ch1 = solve(idx + 1, w);
    long long  ch2 = 0;
    if (W[idx] <= w) {
        ch2 = solve(idx + 1, w - W[idx]) + V[idx];
    }
    long long finalres = max(ch1, ch2);
    dp[idx][w] = finalres;
    return finalres;
}

int main()
{
    long long res = 0;
    cin >> n >> w;
    for (int i = 0; i < n; i++)
        cin >> W[i] >> V[i];
    for (int i = 0; i <= w; i++) {
        dp[0][w] = 0;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= w; j++) {
            dp[i][j] = dp[i - 1][j];
            if (W[i - 1] <= j) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - W[i - 1]] + V[i - 1]);
            }
            res = max(res, dp[i][j]);
        }
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 79360
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
#define int ll
struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}

template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==v.size()?"":" ");
    return os;
}

ll pow_mod(ll x, ll n,ll MOD){
    if(n==0) return 1;
    ll ret=pow_mod((x*x) % MOD, n/2,MOD);
    if(n&1) ret=(ret*x)%MOD;
    return ret;
}



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

    int m=0;
    for(auto c:s){
        if(c=='1') m++;
    }

    int l=m+1;
    m--;
    bool f=false;
    if(m==0) f=true;
    int mm=0,ml=0;
    for(auto c:s){
        if(!f)mm=2*mm+(c-'0');
        ml=2*ml+(c-'0');
        if(!f)mm%=m;
        ml%=l;
    }


    // 増やす->l , 減らす->m
    rep(i,s.size()){
        int d=n-1-i;
        if(s[i]=='1'){
            if(f){
                cout<<0<<endl;
                continue;
            }
            // m
            int k=mm;
            k-=pow_mod(2,d,m);
            if(k<0) k+=m;
            // cout<<"m "<<k<<endl;
            int ans=1;
            while(k){
                ans++;
                k%=__builtin_popcountll(k);
            }
            cout<<ans<<endl;
        }else{
            // l
            int k=ml;
            k+=pow_mod(2,d,l);
            k%=l;
            // cout<<"l "<<k<<endl;

            int ans=1;
            while(k){
                ans++;
                k%=__builtin_popcountll(k);
            }
            cout<<ans<<endl;
        }
    }


    return 0;
}


Measured memory_bytes: 3752
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
broken = set([int(input()) for _ in range(m)]) # ここが'list'だとPypyでも通らない
#print(broken_steps)

def ptn_num(x): # 'x'stepまでのパターン数
    if x == 1:
        print(1)
    else:
        dp = [0] * (x+1) # DP枠_including step'0'
        cnt = 0 # 連続して壊れている階段を記録, '2'でゴール不可
        if 1 in broken: # in case, step'1' broken 
            dp[:2] = 1, 0
        else:
            dp[:2] = 1, 1 # Usually

        for i in range(2, x+1):
            if i in broken: # 階段が壊れている場合...
                cnt += 1
                if cnt == 2: # 2段連続壊れている場合は...
                    print(0)
                    exit()
            else: # 階段が壊れてない場合...
                dp[i] = (dp[i-1] + dp[i-2]) % (10**9+7)
                cnt = 0
        
        print(dp[-1])

ptn_num(n)


Measured memory_bytes: 13212