akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main()
{
  int i, sum;
  char data[1024];
  while (1) {
    i = 0;
    for (sum = 0;;++i) {
      scanf("%c", &data[i]);
      if (data[i] == '\n') break;
      if (i == 1 && data[i - 1] == '0') break;
      sum += (int)(data[i] - '0');
    }
    if (i == 1 && data[i - 1] == '0') break;
    printf("%d\n", sum);
  }
  return 0;
}

Measured memory_bytes: 1804
import java.util.Scanner;

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

		int N=sc.nextInt();

		for(int i=0; i<8; i++) {
			iro[i]=0;
		}
		int tmp=0;
		for(int i=0; i<N; i++) {
			tmp=sc.nextInt();
			if(tmp<3200) { iro[tmp/400]++;}
			else {
				tourist++;
			}
		}

		int clr=0;

		for(int i=0; i<8; i++) {
			if(iro[i]>0) {
				clr++;
			}
		}

		System.out.println(Math.max(1, clr)+" "+(clr+tourist));

	}
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 1e9 + 7;

int main() {
    int n;
    cin >> n;
    ll a[n];
    ll s[n+1];
    s[0] = 0;
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        s[i+1] = s[i] + a[i]; 
    }

    for(int i = 0; i < n-1; i++) {
        int j = i + 1;
        ll sum = s[n] - s[j];
        //ans = (ans%M + (((a[i]%M) * (sum%M))%M))%M;
        ans = ans + (((a[i]%M) * (sum%M))%M);
        if(ans > M) {
            ans -= M;
        }
    }

    cout << ans;
}

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

using namespace std;

int main(){
    int n,q;
    cin >> n;
    long long S[n];
    int count=0;
    for(int i=0;i<n;i++)cin>>S[i];
    cin >> q;
    long long T[q];
    int l;
    int r;
    for(int i=0;i<q;i++)cin>>T[i];
    for(int i=0;i<q;i++){
        l=0;
        r=n-1;
        int flag=0;
        int idx;
        while(r-l>1){
            idx = (l+r)/2;
            //cout << l << idx  << r << endl;
            if(T[i]==S[idx]){
                flag=1;
                break;
            }
            if(T[i]>S[idx]){
                l = l+round((r-l)/2);
            }
            if(T[i]<S[idx]){
                r = r + round((l-r)/2);
            }
        }
        if(S[l]==T[i] || S[r]==T[i])flag=1;
        count += flag;

    }

cout << count << endl;
}


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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

int main()
{
    string s, t;
    cin >> s >> t;

    cout << t << s << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
    int count = 1, temp = 0;
    bool flag= true;
    for (int i = 0; i < 5; i++) {
        cin >> temp;
        if (flag) {
            if (temp == 0) {
                flag = false;
            } else {
                count++;
            }
        }
    }
    cout << count;
}

Measured memory_bytes: 3164
#include<bits/stdc++.h>
#define ls p<<1
#define rs p<<1|1 
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define mm make_pair
#define pi 2*acos(0.0)
#define lcm(a,b) (a*b)/__gcd(a,b)
#define Case(i,ans) cout<<"Case "<<i<<": "<<ans<<endl;
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout.precision(i);cout<<fixed<<ans<<endl;
#define pb(x) push_back(x)
#define lowbit(x) (x)&(-x)
#define out(x) {cout<<x<<endl;return 0;} 
#define all(v) v.begin(),v.end() 
#define mem(x,i) memset(x,i,sizeof(x)) 
#define eps 1e-8 
#define ull unsigned long long
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
ll gcd(ll x,ll y){if(y==0) return x;else return gcd(y,x%y);} 
ll ksm(ll a,ll b){ll r=1;while(b){if(b&1) r=(r*a)%mod;a=a*a%mod;b>>=1;}return r;} 
const int maxn=1e5+100;
ll x2,y2,x3,y3,s;
int main()
{
	cin>>s;
	if(s!=1e18) x2=y3=(ll)sqrt(s)+1;
	else x2=y3=(ll)sqrt(s);
	ll base=x2*y3-s;
	x3=1;y2=base;
	cout<<"0 0 "<<x2<<" "<<y2<<" "<<x3<<" "<<y3<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#define REP(i, n) for(int i=0;i<n;++i)
#define INF 100000000
#define ll long long

using namespace std;

typedef pair<int, int> P;

string str;
int a[4];
char ans[3];

int main(){
    cin >> str;
    REP(i, 4){
        char c = str[i];
        a[i] = c - '0';
    }

    for(int bit=0; bit < (1<<3); ++bit){
        int tmp = a[0];

        for(int i=0; i<3; ++i){
            if(bit & (1<<i)){
                tmp += a[i+1];
                ans[i] = '+';
            } else {
                tmp -= a[i+1];
                ans[i] = '-';
            }
        }

        if(tmp == 7){
            break;
        }
    }

    REP(i, 3){
        cout << a[i] << ans[i];
    }
    cout << a[3] << "=7" << endl;

	return 0;
}


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

int n, k, q, a, s[100010], ans;

int main(){

	scanf("%d%d%d", &n, &k, &q);
	for(int i = 1; i <= q; i++){
		scanf("%d", &a);
		s[a]++;
	}
	for(int i = 1; i <= n; i++)
		if(s[i] - q + k <= 0)
			puts("No");
		else
			puts("Yes");
	
	return 0;
}

Measured memory_bytes: 896
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int x, a;
    cin >>x >>a;
    if(x < a)
        cout <<0;
    else 
        cout <<10;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    
	    Scanner sc = new Scanner(System.in);  //標準入力の宣言

		int A = sc.nextInt();  //標準入力をAに代入
		int B = sc.nextInt();  //標準入力をBに代入
		int C = sc.nextInt();  //標準入力をCに代入
        int N;  //答えを代入する変数
		
        if (A-B <= C) {
          N = C-(A-B);
        } else {
                  N = 0;
               }

        System.out.println(N);

  }
}

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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define INF 1000000001
#define INFL (1LL << 60)
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main() {
  string s;
  cin >> s;
  int a = 700;
  a += (s[0] == 'o'?100:0);
  a += (s[1] == 'o'?100:0);
  a += (s[2] == 'o'?100:0);
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(17) << res << endl;                                                    
int main() {
  ll n;
  cin >> n;
  vector<ll> A(n+1);
  for (auto & a : A) cin >> a;

  ll total = 0;
  for (auto a : A) total += a;


  ll res = 0;
  ll cur = 1;
  for (ll i = 0; i <= n; ++i) {
    if (cur < A[i]) {
      cout << -1 << endl;
      return 0;
    }
    res += min(cur, total);
    cur = min(cur, total) - A[i];
    total -= A[i];
    cur *= 2;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 4064
input_list = input().split()
input_list2 = list(map(int, input().split()))
delete_ball = input()
for ind, n in enumerate(input_list):
  if n == delete_ball:
    input_list2[ind] -= 1
ans = ""
for m in input_list2:
  ans += str(m) + " "
print(ans.rstrip())

Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N; cin >> N;
    bool isOK = true;
    for (int i = 0; i < N; ++i)
    {
        int Ai; cin >> Ai;
        if (Ai % 2 == 0)
        {
            if (Ai % 3 != 0 && Ai % 5 != 0)
            {
                isOK = false;
                break;
            }
        }
    }
    if (isOK) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> tinko(N);
  int i = 0;
  int j = 0;
  
  for(; i < N; i++) {
    cin >> tinko.at(i);
  }
  
  for(int i = 0; j < N; j++) {
    i = tinko.at(i) - 1;
    
    if ( i == 1 ) {
      break;
    }
  }
  
  if ( j == N ) {
    cout << -1 << endl;
  }
  
  else {
    cout << j + 1 << endl;
  }
    
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m,s=0; cin>>n>>m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s+=a[i];
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  double d=s*0.25/m;
  for(int i=0;i<m;i++){
    if(a[i]<d){
      cout<<"No"<<endl;
      exit(0);
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cassert>
#include <string.h>

using namespace std;
#define  rep(i,n) for(int i=0;i<n;i++)
#define  REP(i,a,b) for(int i=a;i<b;i++)
typedef long long int lld;
typedef vector<lld> vl;
typedef vector<int> vi;
typedef vector<string> vs;



//int arr[N]
////sort(arr,arr +N)

//vector <int> hoge
////sort(hoge.begin(),hoge.end());

int main() {


	int ans=0;
	int n,k;
	cin>>n>>k;
	vi x(n,0);
	rep(i,n){
		cin>>x[i];
	}
	rep(i,n){
		if(x[i]>=abs(x[i]-k))
			ans+=abs(x[i]-k);
		else
			ans+=x[i];
	}
	cout<<ans*2;
	return  0;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2147483647
#define SYOU(x) setprecision(x)
#define abs(x,y) max(x,y)-min(x,y)
using namespace std;
long long i[10000000];
long long u[1111111];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=1,f=0;
  string s[4];
  for(int n=0;n<3;n++) cin >>s[n];
  s[0][0]=s[0][0]-32,s[1][0]=s[1][0]-32,s[2][0]=s[2][0]-32;
  cout <<s[0][0]<<s[1][0]<<s[2][0]<<'\n';
  return (0);
}


Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    int A, B; cin >> A >> B;

    int cnt = 1;
    int tap = 0;
    while(cnt<B) {
        cnt += A - 1;
        tap++;
    }

    int ans = tap;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;

int main(){
  string t;
  cin >> t;
  int l = t.length();
  vector<char> ans(l);
  rep(i,l){
    /*if(t[i]=='?'){
      if(i!=l-1&&i!=0){
        if(t[i+1]=='D') ans[i]='P';
        else if(t[i+1]=='D'&&ans[i-1]=='D') ans[i]='P';
        else if(t[i+1]=='?'&&ans[i-1]=='D') ans[i]='P';
        else ans[i] = 'D';
      }else if(i==l-1){
        ans[i] = 'D';
      }else{
        if(t[i+1]=='D'||t[i+1]=='?') ans[i]='P';
        else ans[i] = 'D';
      }
    }*/
    if(t[i]=='?'){
      ans[i]='D';
    }
    else{
      ans[i]=t[i];
    }
  }
  rep(i,l) cout << ans[i];
}

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

int main(){
    int n;
    while(cin >> n){
        int appear[7] = {}, domino[7] = {};
        int a;

        for(int i = 0; i < n; i++){
            cin >> a;
            appear[a/10]++;
            appear[a%10]++;
            domino[a/10]++;
            if(a/10 != a%10)    domino[a%10]++;
        }

        int odd = 0;
        for(int i = 0; i < 7; i++){
            if(appear[i]%2 || (appear[i]%2 == 0 && domino[i] == 1)) odd++;
        }

        if(n == 1 || odd == 0 || odd == 2){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3096
import collections
import bisect
n,m=map(int,input().split())
p=[[int(j) for j in input().split()] for i in range(m)]
a=collections.defaultdict(list)
for x,y in sorted(p):
  a[x]+=[y]
for x,y in p:
  z=bisect.bisect(a[x],y)
  print("%06d%06d"%(x,z))

Measured memory_bytes: 41012
import java.util.Arrays;
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt(),gcd=0;
    int[] a=new int[n];
    for(int i=0;i<n;i++)a[i]=sc.nextInt();
    Arrays.sort(a);
    gcd=GCD(a[0],a[1]);
    for(int i=2;i<n;i++) {
    	gcd=GCD(gcd,a[i]);
    }
    System.out.println(gcd);
  }
	public static int GCD(int min,int max) {
		if(max%min==0)return min;
		else return GCD(max%min,min);
	}
}


Measured memory_bytes: 49728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

template <class T>
struct fenwick {
    vector<T> node;
    int n;
    fenwick(int _n)
        : n(_n) {
        node.resize(n);
    }
    void add(int x, T v) {
        while (x < n) {
            node[x] += v;
            x |= (x + 1);
        }
    }
    T get(int x) {
        T v = 0;
        while (x >= 0) {
            v += node[x];
            x = (x & (x + 1)) - 1;
        }
        return v;
    }
    T get(int a, int b) {  // [a, b]
        return get(b) - (a ? get(a - 1) : 0);
    }
    int lower_bound(T v) {
        int x = 0;
        int h = 1;
        while (n >= (h << 1)) {
            h <<= 1;
        }
        for (int k = h; k > 0; k >>= 1) {
            if (x + k <= n && node[x + k - 1] < v) {
                v -= node[x + k - 1];
                x += k;
            }
        }
        return x;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, k;
    cin >> n >> k;
    vector<int> a(n);
    map<int, vector<int>> mp;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]].emplace_back(i);
    }
    vector<int> order(1);
    vector<int> p(1);
    int cur = 0;
    while (cur != n) {
        int nxt = upper_bound(mp[a[cur]].begin(), mp[a[cur]].end(), cur) - mp[a[cur]].begin();
        p.emplace_back(p.back());
        if (nxt == mp[a[cur]].size()) {
            nxt = 0;
            p.back()++;
        }
        cur = mp[a[cur]][nxt] + 1;
        order.emplace_back(cur);
    }
    p.back()++;
    debug(order);
    debug(p);
    k %= p.back();
    if (k == 0) {
        return 0;
    }
    cur = lower_bound(p.begin(), p.end(), k) - p.begin();
    cur--;
    int pos = order[cur];
    vector<int> ans;
    set<int> st;
    for (int i = pos; i < n; i++) {
        if (st.count(a[i])) {
            while (ans.back() != a[i]) {
                st.erase(ans.back());
                ans.pop_back();
            }
            st.erase(a[i]);
            ans.pop_back();
        } else {
            st.emplace(a[i]);
            ans.emplace_back(a[i]);
        }
    }
    for (int i : ans) {
        cout << i << " ";
    }
    cout << '\n';
    return 0;
}


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

int count_num;

void Merge(int* A, int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  int array_l[n1 + 1];
  int array_r[n2 + 1];
  for (int i = 0; i < n1; i++) {
    array_l[i] = A[left + i];
  }
  for (int i = 0; i < n2; i++) {
    array_r[i] = A[mid + i];
  }
  array_l[n1] = INT_MAX;
  array_r[n2] = INT_MAX;
  int i = 0;
  int j = 0;
  for (int k = left; k < right; k++) {
    if (array_l[i] <= array_r[j]) {
      A[k] = array_l[i];
      i = i + 1;
    } else {
      A[k] = array_r[j];
      j = j + 1;
    }
    count_num++;
  }
}

void MergeSort(int* A, int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    MergeSort(A, left, mid);
    MergeSort(A, mid, right);
    Merge(A, left, mid, right);
  }
}

int main() {
  int n;
  cin >> n;
  int A[n];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  MergeSort(A, 0, n);
  for (int i = 0; i < n; i++) {
    if (i != 0) cout << " ";
    cout << A[i];
  }
  cout << endl << count_num << endl;
  return 0;
}


Measured memory_bytes: 6952
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int main() {
    lint n, q;
    cin >> n >> q;

    vector<tuple<lint, lint, lint>> query; // (time, type, info)
    for(lint i=0; i<n; i++) {
        lint s, t, x;
        cin >> s >> t >> x;
        query.emplace_back(s-x, 1, x);
        query.emplace_back(t-x, -1, x);
    }

    for(lint i=0; i<q; i++) {
        lint d;
        cin >> d;
        query.emplace_back(d, 2, -1); // info: dummy
    }

    sort(begin(query), end(query));

    multiset<lint> ms;
    for(auto e : query) {
        lint time, type, info;
        tie(time, type, info) = e;
        if(type == -1)  ms.erase(ms.find(info));
        if(type == 1)  ms.insert(info);
        if(type == 2) cout << (ms.empty() ? -1 : *ms.begin()) << endl;
    }
}

Measured memory_bytes: 26984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string a,b;cin>>a >>b;
    cout << b << a << endl;
    
    
}




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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int h, w;
  cin >> h >> w;
  
  map<int, int> mp; // mp[now] = start
  multiset<int> ms; // multiset of (now - start)
  for (int i = 0; i < w; i++) {
    mp[i] = i;
    ms.insert(0);
  }
  mp[2e8] = 1e8; // sentinel
  ms.insert(1e8); // sentinel
  
  for (int i = 0; i < h; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    auto it1 = mp.lower_bound(a);
    auto it2 = mp.lower_bound(b);
    if (it1 != it2) {
      int start, now;
      auto it = it1;
      while (it != it2) {
        start = it->second;
        now = it->first;
        int start2 = it->second, now2 = it->first;
        ms.erase(ms.find(now2 - start2));
        it = mp.erase(it);
      }
      if (b < w) {
        now = b;
        if (mp.find(now) == mp.end()) {
          mp[now] = start;
          ms.insert(now - start);
        }
      }
    }
    if (*(ms.begin()) == 1e8) cout << -1 << '\n';
    else cout << *(ms.begin()) + i + 1 << '\n';
  }
}

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

using namespace std;

int main(){
	int A, B, C;
  	cin >> A >> B >> C;
  	int count = 0;
  	while(B > 0){
        B -= A;
        if(B >= 0) count++;
        if(count == C) break;
    }
  	cout << count << endl;
}

Measured memory_bytes: 256
<?php
//error_reporting(0);
//$N = trim(fgets(STDIN));
list($N,$M) =  explode(" ",trim(fgets(STDIN)));
//$X = explode(" ",trim(fgets(STDIN)));
$res = array();
for($i=0;$i<$N;$i++) {
  $A = explode(" ",trim(fgets(STDIN)));
  unset($A[0]);
  $K=array_count_values($A);;
  foreach($K as $k=>$v) {
    if (isset($res[$k])) {
      $res[$k]+=$v;
    }
    else {
      $res[$k]=$v;
    }
  }
}
$ret = 0;
foreach($res as $v) {
  if ($v==$N) $ret++;
}
printf("%d\n",$ret);


Measured memory_bytes: 4728
//wait for sh
    #pragma GCC optimize("Ofast")
    #include <bits/stdc++.h>
    using namespace std;

    #define int long long int
    #define pb push_back
    #define mp make_pair
    #define loop(i,st,end) for(int i=st;i<end;i++)
    #define itr(it,v)  for(auto it=v.begin();it!=v.end();++it)
    #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define debug(x) cout << "[ " << #x  << " : " << x << " ]" << endl ;
    #define mod (int)(1e9+7)
    const int maxn=5001;


    void solve()
      {
        int n,k;
        cin>>n>>k;

        int dp[n+1][k+1],predp[k+1];
        memset(dp,0,sizeof(dp));
        dp[0][0]=1;

       
        loop(i,0,k+1)
        predp[i]=1;

         int a[n+1];
        loop(i,1,n+1)
        cin>>a[i];

        loop(i,1,n+1)
        { 
          int prefix[k+1];
          loop(j,0,k+1)
          {
            int kk=max(1LL*0,j-a[i]);
            //debug(predp[j]); debug(j);
            if(kk==0)
            {
              dp[i][j]=predp[j];
            }
            else
              dp[i][j]=(predp[j]-predp[kk-1]+mod)%mod;;


            if(j==0)
            {
              prefix[j]=dp[i][j];
            }

            else
            {
              prefix[j]=(prefix[j-1]+dp[i][j])%mod;
            }
          }

          loop(j,0,k+1)
            predp[j]=prefix[j];
        }

        cout<<dp[n][k];
 
      }

    int32_t main()
    { IOS


      int t;
      t=1;
      //cin>>t;

      loop(i,0,t)
      {  //cout<<"Case #"<<(i+1)<<": ";
          solve();
      }

      return 0;
    }


Measured memory_bytes: 80768
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
 
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979
 
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

int N;
int result;
vector<P> ve;

void Erase(int counter[60],int i){
	int target=0;
	REP(j,(int)ve.size()){
		if(ve[j].first==i)
			target=ve[j].second;
		else if(ve[j].second==i)
			target=ve[j].first;
		if(target!=0){
			counter[i]--;
			counter[target]--;
			ve.erase(ve.begin()+j);
			break;
		}
	}
}

void check(int counter[60]){
	FOR(i,1,N+1){
		if(counter[i]==1){
			result++;
			Erase(counter,i);
			i=0;
		}
	}
}

int main(void){
	int M,a,b;
	int counter[60]={};
	result=0;

	cin>>N>>M;
	
	REP(i,M){
		cin>>a>>b;
		ve.pb(P(a,b));
		counter[a]++;
		counter[b]++;
	}
	
	check(counter);

	print(result);	
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n;
	cin>>n;
	long long int res[46];
	long long int sum[46];
	long long int sum2[46];
	int mark[46];
	for (int i=0;i<46;i++){
		mark[i]=0;
		res[i]=(1ll<<i);
		if (i%2==1)res[i]=-res[i];
	}
	sum[0]=1;
	sum2[0]=0;
	for (int i=1;i<46;i++){
		sum[i]=max(sum[i-1],sum[i-1]+res[i]);
		sum2[i]=min(sum2[i-1],sum2[i-1]+res[i]);
	}
	long long int temp=0;
	int fir=-1;
	for (int i=45;i>=0;i--){
		if (abs(n-(temp+res[i]))<=abs(n-temp)||(n-temp>0&&res[i]>0&&(sum[i]-res[i])<n-temp)
			||(n-temp<0&&res[i]<0&&(sum2[i]-res[i])>n-temp)){
			mark[i]=1;
			temp+=res[i];
			if (fir==-1){
				fir=i;
			}
		}
	}
	if (fir==-1)fir=0;
	for (int i=fir;i>=0;i--){
		printf ("%d",mark[i]);
	}
}

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

int main() {
	//input
	int H1, M1, H2, M2, K;
	cin >> H1 >> M1 >> H2 >> M2 >> K;

	//calculation
	int output = (H2 - H1) * 60 + M2 - M1 - K;


	//output
	cout << output << endl;


	return 0;
}


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

int main() {
  ll x, y, z;
  cin >> x >> y >> z;
  
  cout << z << " " << x << " " << y << endl;;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}

int main(){
  int N;
  cin >> N;
  int count=0;
  
  vector<int> p(N);
  cin >> p; //vectorもシンプルにinできる
	
  int d1, d2;
  
  for(int i=1; i<N-1; i++){
    d1 = (p[i]-p[i-1]) / abs(p[i]-p[i-1]);
    d2 = (p[i+1] - p[i]) / abs(p[i+1]-p[i]);
    if(d1*d2==1){
      count++;
    }
    
  }   
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
string D = "UDLR";
void fail(){
    cout << "NO" << endl;
    exit(0);
}
 
int main(){
    int H, W, N;
    cin >> H >> W >> N;
    int sr, sc;
    cin >> sr >> sc;
    sr--; sc--;
    string Ss, Ts;
    cin >> Ss >> Ts;
    int S[200000], T[200000];
    for(int i=0; i<N; i++){
        S[i] = D.find(Ss[i]);
        T[i] = D.find(Ts[i]);
    }
 
    for(int t=0; t<2; t++){
        int add = 2*t+1, sub = 2*t;
        int start = (t==0 ? sr : sc);
        int X = (t==0 ? H : W);
        int mx = X-1, mn = 0;
        for(int i=N-1; i>=0; i--){
            if(T[i] == sub){
                mx = min(X-1, mx+1);
            }else if(T[i] == add){
                mn = max(0, mn-1);
            }
            if(S[i] == add){
                mx--;
            }else if(S[i] == sub){
                mn++;
            }
            if(mn > mx) fail();
        }
        if(!(mn <= start && start <= mx)) fail();
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 2312
n_matches, k = map(int, input().split())
point_r, point_s, point_p = map(int, input().split())
ts = list(input())

total_point = 0
t_of_mine = []

for i in range(len(ts)):
    t = ts[i]

    if i < k:
        k_prev = '*'
    else:
        k_prev = t_of_mine[i - k]

    if t == 'r' and k_prev != 'p':
        total_point = total_point + point_p
        t_of_mine.append('p')
    elif t == 's' and k_prev != 'r':
        total_point = total_point + point_r
        t_of_mine.append('r')
    elif t == 'p' and k_prev != 's':
        total_point = total_point + point_s
        t_of_mine.append('s')
    else:
        t_of_mine.append('*')

print(total_point)


Measured memory_bytes: 4792
#include<stdio.h>
#define N 1000000
#define M -1

typedef struct { int p, l, r; }Node;
Node Tree[N];
int A[N];

int rec(int u,int p) {
	A[u] = p;
	if (Tree[u].r != M) {
		rec(Tree[u].r, p);
	}
	if (Tree[u].l != M) {
		rec(Tree[u].l, p+1);
	}
}
int main(void) {
	int i, j, n,v,d, c, l, r,a=0;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		Tree[i].p = M;
		Tree[i].r = M;
		Tree[i].l = M;
	}
	for (i = 0; i < n; i++) {
		scanf("%d%d", &v, &d);
		for (j = 0; j < d; j++) {
			scanf("%d", &c);
			if (j == 0) {
				Tree[v].l = c;
			}
			else {
				Tree[l].r = c;
			}
			l = c;
			Tree[c].p = v;
		}
	}
	for (i= 0; i < n; i++) {
		if (Tree[i].p == M) {
			r = i;
		}
	}
	rec(r, 0);
	for (i = 0; i < n; i++) {
		printf("node %d: parent = %d, depth = %d, ",i, Tree[i].p, A[i]);
		if (Tree[i].p == M) {
			printf("root, ");
		}
		else if (Tree[i].l == M) {
			printf("leaf, ");
		}
		else {
			printf("internal node, ");
		}

		a = Tree[i].l;
		printf("[");
		for (j = 0; a != M; j++, a = Tree[a].r) {
			if (j) {
				printf(", ");
			}
			printf("%d", a);
		}
		printf("]\n");
	}
	return 0;
}


Measured memory_bytes: 6408
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        Long b = sc.nextLong();
        Long c = sc.nextLong();
		Long [] in = new Long [a];
        for(int i=0;i<a;i++){if(i<b){in[i] = c;}
                             else{if(c<1000000000){in[i] = c+1;}
                                 else{in[i]=c-1;}
                                 }
                            }      
		for(int i=0;i<a;i++){System.out.println(in[i]);}
	}
}

Measured memory_bytes: 54412
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string S;
	cin >> S;

	//010101...
	int ans1 = 0;
	for (int i = 0; i < S.size(); ++i)
	{
		if ((i % 2 == 0)&&(S.substr(i,1) == "1"))
		{
			ans1 += 1;
		}
		if ((i % 2 == 1)&&(S.substr(i,1) == "0"))
		{
			ans1 += 1;
		}
	}

	//101010...
	int ans2 = 0;
	for (int i = 0; i < S.size(); ++i)
	{
		if ((i % 2 == 0)&&(S.substr(i,1) == "0"))
		{
			ans2 += 1;
		}
		if ((i % 2 == 1)&&(S.substr(i,1) == "1"))
		{
			ans2 += 1;
		}
	}

	cout << min(ans1,ans2);
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int cnt1 = 0;
    int cnt0 = 0;
    rep(i,n){
        if(s[i]=='0')cnt0++;
        else cnt1++;
    }
    cout << 2*min(cnt1,cnt0) << endl;
    return 0;
}


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

vector<ll> r;

void d(ll n, ll c){
    r.push_back(n);
    if(c==9){
        return;
    }
    ll l=n%10;
    if(l>0){
        d(n*10+l-1,c+1);
    }
    if(l<9){
        d(n*10+l+1,c+1);
    }
    d(n*10+l,c+1);
}

int main(){
    ll K=ii();
    REP(i,1,10) d(i,0);
    sort(r.begin(),r.end());
    oie(r[K-1]);
    return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
const int MAX_N=2e5+1;
int N;
LL A[MAX_N];
void solve() {
//  LL res=1e18;
  sort(A,A+N);
  LL mid=A[N/2];
  LL res=0;
  REP(i,N) res+=abs(A[i]-mid);
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>N;
  REP(i,N) cin>>A[i],A[i]-=(i+1);
  solve();
  return 0;
}


Measured memory_bytes: 1792
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int d=in.nextInt();
		int [][] a=new int [n][d];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<d;j++)
			{
				a[i][j]=in.nextInt();
			}
		}
		int ans=0;
		for(int i=0;i<n;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				double temp=0;
				for(int k=0;k<d;k++)
				{
					temp=temp+Math.pow((a[i][k]-a[j][k]),2);
				}
				double q=(double)(int)Math.pow(temp,0.5);
				if(Math.pow(temp,0.5)-q<0.0000001)
				{
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
}
	

Measured memory_bytes: 21844
/**************************************************************
	File name: D.cpp
	Author: huhao
	Email: 826538400@qq.com
	Create time: 2019/8/24 下午8:26:45
**************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
const int N=510;
int main()
{
	int n=read();
	fr(i,1,n)
		fr(j,i+1,n)
			fd(k,10,0)
				if((1<<k)&((i-1)^(j-1)))
				{
					printf("%d%c",k+1,j==n?'\n':' ');
					break;
				}
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using lint = long long;
typedef pair<int,int> P;
const lint inf=1e18+7;
const int MOD=1000000007;
class Camel{
    public:
    int k,l,r;
    void input(){
        cin>>k>>l>>r;
    }
};
int solve(){
    int n;cin>>n;
    lint res=0;
    vector<Camel> cam(n);
    rep(i,n){
        cam[i].input();
        res+=min(cam[i].l,cam[i].r);
    }
    vector<P> front;
    vector<P> rear;
    rep(i,n){
        if(cam[i].l>cam[i].r)front.push_back({cam[i].k,cam[i].l-cam[i].r});
        else{
            rear.push_back({cam[i].k,cam[i].r-cam[i].l});
        }
    }
    sort(front.begin(),front.end());
    sort(rear.begin(),rear.end());
    reverse(ALL(front));
    front.push_back({0,inf});
    int cur=0;
    priority_queue<int> que;
    for(int i=front.size()-1;i>0;--i){
        while(front[cur].first>=i){
            que.push(front[cur].second);
            ++cur;
        }
        if(!que.empty()){
            res+=que.top();que.pop();
        }
    }
    priority_queue<int> que2;
    que=que2;
    rear.push_back({inf,inf});
    cur=0;
    for(int i=front.size();i<=n;++i){
        while(rear[cur].first<i){
            que.push(rear[cur].second);
            ++cur;
        }
        if(!que.empty()){
            res+=que.top();que.pop();
        }
    }
    return res;
}
signed main(){
  int t;cin>>t;
  vector<int> res(t);
  rep(i,t){
      res[i]=solve();
  }
  rep(i,t){
      cout<<res[i]<<"\n";
  }
  return 0;
}

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

int main(){
    int x1, x2, x3, x4, x5;
    cin >> x1 >> x2 >> x3 >> x4 >> x5;

    if(x1 == 0) cout << 1 << endl;
    if(x2 == 0) cout << 2 << endl;
    if(x3 == 0) cout << 3 << endl;
    if(x4 == 0) cout << 4 << endl;
    if(x5 == 0) cout << 5 << endl;
}

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

using namespace std;

int main() {
    int k, x;
    cin >> k >> x;

    for (int i = max(-1'000'000, x - k + 1); i <= min(1'000'000, x + k - 1);
         ++i) {
        cout << i << ' ';
    }
    cout << endl;

    return 0;
}


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

int main(){

	int x, list[31] = {0};

	for(int i=0; i<28; i++){
		cin >> x;
		list[x] = 1;
	}

	for(int i=1; i<31; i++){
		if(list[i] == 0) cout << i << endl;
	}

	return 0;

}

Measured memory_bytes: 1160
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.OptionalLong;
import java.util.stream.LongStream;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Comparator;

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

    static class D3NNumbers {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long[] a = IntStream.range(0, n * 3).mapToLong(x -> in.nextInt()).toArray();
            PriorityQueue<Long> first = new PriorityQueue<>();
            long firstSum = LongStream.of(a).limit(n).peek(first::add).sum();
            PriorityQueue<Long> second = new PriorityQueue<>(Comparator.reverseOrder());
            long secondSum = LongStream.of(a).skip(2 * n).sorted().peek(second::add).sum();
            long[] scores = new long[n + 1];
            scores[0] += firstSum;
            scores[n] -= secondSum;
            for (int i = 1; i <= n; i++) {
                firstSum += a[n + i - 1];
                secondSum += a[2 * n - i];
                first.add(a[n + i - 1]);
                second.add(a[2 * n - i]);
                firstSum -= first.poll();
                secondSum -= second.poll();
                scores[i] += firstSum;
                scores[n - i] -= secondSum;
            }
            out.println(LongStream.of(scores).max().orElse(0));
        }

    }
}



Measured memory_bytes: 100676
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)

#define MAXN (100000)
#define MOD (998244353)

int ans[MAXN];
int main(void)
{
    int n,k,q;
    scanf("%d %d %d",&n,&k,&q);

    for(int i=0;i<q;i++)
    {
        int a;
        scanf("%d",&a);
        ans[a-1]++;
    }
    
    for(int i=0;i<n;i++)
    {
        printf("%s\n", k-(q-ans[i]) > 0 ? "Yes" : "No");
    }
    return 0;
}


Measured memory_bytes: 896
#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#ifndef STOPIT
#define debug(...)\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;
#else
#define debug 0;
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

template < template < typename ... > class Container, typename Value >
auto make_z_array(Container< Value > const & s) -> std::vector< int > {
  if (s.empty()) return {};
  auto n = (int)s.size();
  std::vector< int > ret(n);
  ret.at(0) = n;
  auto i = 1, j = 0;
  while (i < n) {
    while (i + j < n && s.at(j) == s.at(i + j))
      { j++; }
    ret.at(i) = j;
    if (j == 0)
      { i++; }
    else {
      auto k = 1;
      while (i + k < n && k + ret.at(k) < j) {
        ret.at(i + k) = ret.at(k);
        k++;
      }
      i += k, j -= k;
    }
  }
  return ret;
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  std::string s; std::cin >> s;
  int n = s.length();
  auto make_per = [n] (auto&& s) {
    auto a = make_z_array(s);
    debug(a);
    std::vector< int > ret(n + 1, false);
    rep(p, 1, n / 2 + 1) {
      for (auto i = p; i + p <= n; i += p) {
        debug(p, i, i + p);
        if (a.at(i) < p)
          { break; }
        ret.at(i + p) = true;
      }
    }
    return ret;
  };
  auto a = make_per(s);
  if (!a.back()) {
    std::cout << 1 << std::endl;
    std::cout << 1 << std::endl;
    return 0;
  }
  std::reverse(all(s));
  auto b = make_per(s);
  std::reverse(all(b));
  auto ret = std::inner_product(all(a), b.begin(), 0,
    [](auto x, auto y){ return x + y; },
    [](auto x, auto y){ return !x & !y; }
  );
  debug(a);
  debug(b);
  if (ret) {
    std::cout << 2 << std::endl;
    std::cout << ret << std::endl;
  } else {
    std::cout << n << std::endl;
    std::cout << 1 << std::endl;
  }
  return 0;
}


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

#define INF 1LL << 60
#define pb push_back
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, b, e) for (int i = (b); i <= (e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

int main() {
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;

    bool isExist = e - a > k;
    string ans = isExist ? ":(" : "Yay!";
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair<int,int> pii;
typedef pair<long long int,long long int> plli;
typedef vector< vi > vvi ;
typedef vector< vlli > vvlli  ;
#define fi(i,a,b) for(int i=a;i<=b;i++)
#define flli(i,a,b) for(long long int i=a;i<=b;i++)
#define bi(i,a,b) for(int i=a;i>=b;i--)
#define blli(i,a,b) for(long long int i=a;i>=b;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pi 2*acos(0.0)
#define pb push_back
#define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
#define present(v,num) (v.find(num)!=v.end())
#define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
#define pq priority_queue
#define mp make_pair
const int inf=INT_MAX;
const lli INF =LLONG_MAX;
const lli mod = 1e9+7;
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast;	
    string s;cin>>s;
    string t;cin>>t;
    lli szs=sz(s);
    lli szt=sz(t);
    lli ans=INF;
    flli(i,0,szs-szt)
    {
    	lli temp=0;
    	flli(j,i,i+szt-1)
    	{
    		if(s[j]!=t[j-i])
    			temp++;
    	}
    	ans=min(ans,temp);
    }
    cout<<ans;
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 3836
n, a, b = gets.split(" ").map(&:to_i)
s = gets.chomp

passed = 0
passed_b = 0

s.length.times do |i|
  if s[i] == "c"
    puts "No"
  elsif s[i] == "b"
    if passed < a+b && passed_b < b
      puts "Yes"
      passed += 1
      passed_b += 1
    else
      puts "No"
    end
  else
    if passed < a+b
      puts "Yes"
      passed += 1
    else
      puts "No"
    end
  end
end


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

using namespace std;

typedef long long int64;
const int64 INF = 1LL << 58;

int64 MinimumCost(vector< int > &A, vector< int > &B)
{
  vector< int > near(B.size());
  int tail = 0;
  for(int i = 0; i < B.size(); i++) {
    while(tail < A.size() && A[tail] < B[i]) ++tail;
    near[i] = tail;
  }
  int sz = (int) B.size() * 2 + 1;
  vector< int64 > dp(sz, 0);
  for(int i = 0; i < B.size(); i++) {
    const int diff = near[i] - (i == 0 ? 0 : near[i - 1]);
    for(int j = 0; j < sz; j++) dp[j] = dp[min(j + diff, sz - 1)];
    vector< int64 > nxt(sz, INF);
    for(int j = 0; j < sz - 1; j++) {
      const int k = near[i] - (int) B.size() + j;
      nxt[j + 1] = min(nxt[j + 1], nxt[j]);
      if(k < 0 || k >= A.size()) continue;
      nxt[j + 1] = min(nxt[j + 1], dp[j] + abs(B[i] - A[k]));
    }
    dp.swap(nxt);
  }
  if(dp.back() == INF) return (-1);
  return (dp.back());
}

int main()
{
  int N, P[4000], D[4000];

  while(scanf("%d", &N), N) {
    if(N == 2) {
      int a, b, c, d;
      cin >> a >> b >> c >> d;
      cout << abs(a - c) << endl;
      continue;
    }
    vector< int > latte, malta;
    for(int i = 0; i < N; i++) {
      scanf("%d %d", &P[i], &D[i]);
      if(D[i] == 1) latte.push_back(i);
      else malta.push_back(i);
    }

    sort(begin(latte), end(latte), [&](int a, int b) -> bool
    {
      return (P[a] < P[b]);
    });
    sort(begin(malta), end(malta), [&](int a, int b) -> bool
    {
      return (P[a] < P[b]);
    });

    for(int i = 1; i < malta.size(); i++) --D[malta[i]];
    for(int i = 0; i + 1 < malta.size(); i++) --D[malta[i]];

    vector< int > beet, vs;
    for(int i : malta) while(D[i]--) beet.push_back(P[i]);
    for(int i : latte) vs.push_back(P[i]);
    if(vs.size() > beet.size()) puts("-1");
    else printf("%lld\n", MinimumCost(beet, vs) + P[malta.back()] - P[malta.front()]);
  }
}

Measured memory_bytes: 68644