akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>
#include<map>
#include<cmath>

using namespace std;

map< long long, long long > prime_factor(long long n) {
  map< long long, long long > ret;
  for(long long i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

long long div2(long long x)
{
	long long cnt=0;
	while(true)
	{
		if(x & 1)break;
		x=(x>>1);
		cnt++;
	}
	return cnt;
}

long long gcd(long long a,long long b){ return b ? gcd(b, a%b) : a; }

int main()
{
	long long n,m;
	cin >> n >> m;
	vector<long long> a(n);
	for(long long i=0;i<n;i++)
		cin >> a[i];
	long long cnt=-1;
	for(long long i=0;i<n;i++)
	{
		if(cnt!=-1)
			if(div2(a[i])!=cnt)
			{
				cout << 0 << endl;
				return 0;
			}
		cnt=div2(a[i]);
		a[i]/=pow(2,cnt);
	}

	long long ans=a[0];	
	for(long long i=0;i<n;i++)
	{
		long long nxans=ans*(long long)a[i];
		nxans/=gcd(ans,a[i]);
		ans=nxans;
		if(ans>m)
		{
			cout << 0 << endl;
			return 0;
		}
	}
//	cerr << ans << endl;
	ans*=pow(2,cnt-1);
	cout << ((m)/(ans)+1)/2 << endl;


}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void maxHeapify(int*, int, int);
void insert(int*, int*, int);
int extractMax(int*, int*);
void swap(int *, int *);

main(){
  int h=0, key, S[2000000];
  char txt[8];

  while(1){
    scanf("%s", txt);

    if(strcmp(txt, "end") == 0) break;
    else if(strcmp(txt, "extract") == 0){
      printf("%d\n", extractMax(S, &h));
    }
    else if(strcmp(txt, "insert") == 0){
      scanf("%d", &key);
      insert(S, &h, key);
    }
  }

  return 0;
}

void maxHeapify(int *A, int h, int i){
  int largest = i;
  int l = i*2;
  int r = i*2 + 1;

  if(l<=h && A[l] > A[i]) largest = l;
  if(r<=h && A[r] > A[largest]) largest = r;

  if(largest != i){
    swap(A+largest, A+i);
    maxHeapify(A, h, largest);
  }
}

void insert(int *S, int *h, int key){
  int i;
  int me;

  S[(*h)+1] = key;
  (*h)++;

  me = *h;

  for(i=*h/2; i>=1; i=i/2){
    if(S[me] <= S[i]) break;
    else{
      swap(S+me, S+i);
      me = i;
    }
  }
}

int extractMax(int *S, int *h){
  int res = S[1];

  S[1] = S[*h];
  (*h)--;

  maxHeapify(S, *h, 1);
  return res;
}

void swap(int *a, int *b){
  int tmp;

  tmp = *a;
  *a = *b;
  *b = tmp;
}

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

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

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ((ll)(x).size())

int main() {
  ll N, mod = 1000000000 + 7, result = 0;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];
  ll tmp = 0;
  REP(i, N-1) tmp += A[i];
  for (ll i = N-1; i > 0; i--) {
    result += ((tmp % mod) * (A[i] % mod)) % mod;
    // cout << tmp << " " << result << endl;
    tmp -= A[i-1];
  }
  cout << result % mod << endl;
  return 0;
}

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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int f(int n) {
   int ret = 0;
   while (n > 0) {
      ret += n % 10;
      n /= 10;
   }
   return ret;
}

int main() {
   int n, a, b;
   cin >> n >> a >> b;

   int ans = 0;
   for (int i = 1; i <= n; i++) {
      int sum = f(i);
      if (sum >= a && sum <= b) {
         ans += i;
      }
   }

   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <vector>
#include <map>
using namespace std;

#define cio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define ii pair < int, int >
#define iii pair < int, ii >
#define INF 987654321
#define LINF 987654321987654321

int arr[1005];

int main()
{
	cio;
	int n, k;
	cin >> n >> k;

	for (int i = 0; i < n; i++)
		cin >> arr[i];

	sort(arr, arr + n);

	int tot = 0;
	for (int i = 0; i < k; i++)
		tot += arr[i];

	cout << tot;
}

Measured memory_bytes: 3176
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, a, b; cin >> n >> a >> b;
    vector<ll> X(n);
    for(int i = 0; i < n; i++) cin >> X[i];
    ll ans = 0;
    vector<ll> d(n - 1);
    for(int i = 1; i < n; i++)
    {
        d[i - 1] = abs(X[i] - X[i - 1]);
    }
    for(int i = 0; i < d.size(); i++)
    {
        ans += min(a * d[i], b);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
# # 整数の入力
# a = int(input())
# # スペース区切りの整数の入力
# b, c = map(int, input().split())
# # 文字列の入力
# s = input()
# # 出力
# print("{} {}".format(a+b+c, s))
import numpy as np
N = int(input())
a = []
for _ in range(5):
    a.append(int(input()))
np_a = np.array(a)
k = np_a.argmin()
if N%np_a[k] == 0:
    tmp = N//np_a[k]
else:tmp = N//np_a[k] + 1
print(tmp + 4)

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

using ll = long long;
#define repi(n) for (int i = 0; i < (n); i++)
#define repj(n) for (int j = 0; j < (n); j++)
#define repk(n) for (int k = 0; k < (n); k++)
#define repl(n) for (int l = 0; l < (n); l++)
#define rep(i, n) for (int i = 0; (i) < (n); i++)
#define repr(i, a, b) for (auto i = (a); i < (b); i++)
#define repv(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = max((t), (v)))
#define updatemin(t, v) (t = min((t), (v)))
const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
template <typename T>
T minptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i < *re) re = i;
  }
  return re;
}
template <typename T>
T maxptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i > *re) re = i;
  }
  return re;
}
int __vmax(int x) {
  return INT_MAX;
}
double __vmax(double x) {
  return 1e+300;
}
ll __vmax(ll x) {
  return LLONG_MAX;
}
int __vmin(int x) {
  return INT_MIN;
}
double __vmin(double x) {
  return -1e+300;
}
ll __vmin(ll x) {
  return LLONG_MIN;
}
ll modpow(ll a, ll b, ll m) {
  ll re = 1, k = 1;
  while (k <= b) {
    if (b & k) {
      re *= a;
      re %= m;
    }
    k = k << 1;
    a *= a;
    a %= m;
  }
  return re;
}
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
template <typename T>
vector<T> lis(T begin, T end, bool allowequal = false, bool lds = false) {
  using V = typename iterator_traits<T>::value_type;
  int n = end - begin;
  vector<V> a(n, lds ? __vmin(*begin) : __vmax(*begin));
  vector<int> id(n);
  if (lds && allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (lower_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (lds) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (upper_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = upper_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  } else {
    for (int i = 0; i < n; i++) {
      id[i] = lower_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  }
  int m = *maxptr(id.begin(), id.end());
  vector<T> re(m + 1);
  for (int i = n - 1; i >= 0; i--) {
    if (id[i] == m) re[m--] = begin + i;
  }
  return re;
}

int main() {
  ll n;
  cin >> n;
  cout << n * (n - 1) / 2 << endl;
}


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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    vector<int> v;
    for (int i = 0; i < 3; i++)
    {
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    sort(v.begin(), v.end());
    int cnt = 0;

    // cout << v[0] << " " << v[1] << " " << v[2] << endl;
    if (((v[2] - v[1]) % 2) == 0)
    {
        int tmp = v[0];
        v[0] = v[1];
        v[1] = v[2];
        v[2] = tmp;
    }
    else if (((v[1] - v[0]) % 2) == 0)
    {
    }
    else if (((v[2] - v[0]) % 2) == 0)
    {
        int tmp = v[1];
        v[1] = v[2];
        v[2] = tmp;
    }
    // cout << v[0] << " " << v[1] << " " << v[2] << endl;
    cnt += (v[1] - v[0]) / 2;
    // cout << cnt << endl;
    if (abs(v[1] - v[2]) % 2 == 0)
    {
        cnt += (abs(v[1] - v[2])) / 2;
    }
    else
    {
        cnt++;
        cnt += (abs(v[1] + 1 - v[2])) / 2;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<vector>
//#include<unordered_map> 
#include<map>
using namespace std ;
typedef long long ll ;

int main(){
    long double a ;
   cin >> a ;
   cout << 2*a*3.141592 << endl  ;
   
    return 0 ;
}

Measured memory_bytes: 3804
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int H, W;
vector<string> fi;
int Left[2100][2100], Right[2100][2100], Up[2100][2100], Down[2100][2100];

int main() {
    // 入力
    cin >> H >> W;
    fi.resize(H);
    for (int i = 0; i < H; ++i) cin >> fi[i];

    // 前処理
    for (int i = 0; i < H; ++i) {
        int cur = 0;
        for (int j = 0; j < W; ++j) {
            if (fi[i][j] == '#') cur = 0;
            else ++cur;
            Left[i][j] = cur;
        }
    }
    for (int i = 0; i < H; ++i) {
        int cur = 0;
        for (int j = W-1; j >= 0; --j) {
            if (fi[i][j] == '#') cur = 0;
            else ++cur;
            Right[i][j] = cur;
        }
    }
    for (int j = 0; j < W; ++j) {
        int cur = 0;
        for (int i = 0; i < H; ++i) {
            if (fi[i][j] == '#') cur = 0;
            else ++cur;
            Up[i][j] = cur;
        }
    }
    for (int j = 0; j < W; ++j) {
        int cur = 0;
        for (int i = H-1; i >= 0; --i) {
            if (fi[i][j] == '#') cur = 0;
            else ++cur;
            Down[i][j] = cur;
        }
    }

    // 集計
    int res = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (fi[i][j] == '#') continue;
            res = max(res, Left[i][j] + Right[i][j] + Up[i][j] + Down[i][j] - 3);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 74368
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;


int n, in;
vector<int> v;

bool isPrime(int in){
	if(in == 2) return true;
	if(in<2 || in%2==0) return false;
	bool ans = false;
	int num = sqrt(in);

	int i = 0;
	while(1){
		if((num-i)==1){
			ans = true;
			break;
		}
		if(in%(num-i) == 0)break;
		i++;
	}
	return ans;
}



int main(){
	cin >> n;
	int cnt = 0;
	for(int i=0; i<n; ++i){
		cin >> in;
		v.push_back(in);
	}
	for(int i=0; i<n; ++i){
		if(isPrime(v[i]))cnt++;
	}
	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 3264
#include<iostream>
using namespace std;
int n;
int a[200000+5];
long long sum = 0;
long long sum1 = 0;
long long span = (2e5)*(1e9)+5;
int main(){
	scanf("%d",&n);
	for(int i = 1; i <=n;i++){
		scanf("%d",&a[i]);
		sum = sum + a[i];
	}
	for(int i = 1;i<n;i++){
		sum1 = sum1 + a[i];
		long long m = sum - 2*sum1;
		if(m<0){
			m = -m;
		}
		if(m<span){
			span = m;
		}
	}
	printf("%lld\n",span);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n,k;
cin >> n>>k;
vector<int> x(n);
rep(i, n) cin >> x[i];
int ans = 0;
rep(i,n){
    if(x[i]<k-x[i]){
        ans += 2 * x[i];
    }
    else{
        ans += 2 * (k - x[i]);
    }
}
cout << ans << endl;

//system("pause");
return 0;
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 999999999
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    int a, b, c, d, e, A[n];
    rep(i, n) {
      cin >> a >> b >> c >> d >> e;
      A[i] = a + b + c + e + d;
    }
    sort(A, A + n);
    cout << A[n - 1] << ' ' << A[0] << endl;
  }
  return 0;
}

Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define ll long long
#define ii pair<int, int>
#define pll pair<ll, ll>
#define N 200123
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define vpll vector<pll>
#define pb emplace_back
#define fs first
#define sc second
#define sz(x) ((int)((x).size()))
#define oo 1000000123
#define mod 1000000007LL
#define M 10000123

using namespace std;

int n;
string s;

int main(){
    ios_base::sync_with_stdio(0);
    cin >> n >> s;

    if(sz(s) <= n) cout << s << '\n';
    else cout << s.substr(0, n) << "...\n";
    return 0;
}


Measured memory_bytes: 3600
// AtCoder template
// sabaより胡蝶しのぶさんの方が可愛いのではないか？
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)


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

    ll a, b, c; cin >> a >> b >> c;
    if(c <= a + b) cout << "No" << endl;
    else if(4*a*b < (c-a-b)*(c-a-b)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
s = input()
d = {}

for c in s:
    if c not in d:
        d[c] = 1
    else:
        d[c]+=1

flag = True
if len(d) == 2:
    for key in d.keys():
        if d[key] != 2:
            flag = False
else:
    flag =  False


if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38384
#include <iostream>

using namespace std;

int p[101], dp[101][101];

int main() {
	int n; cin >> n;
	for (int i = 1; i <= n; ++i) cin >> p[i - 1] >> p[i];
	for (int i = 2; i <= n; ++i) {
		for (int j = 1; j <= n - i + 1; ++j) {
			int k = i + j - 1;
			dp[j][k] = 1e9;
			for (int l = j; l <= k - 1; ++l)
				dp[j][k] = min(dp[j][k], dp[j][l] + dp[l + 1][k] + p[j - 1] * p[l] * p[k]);
		}
	}
	cout << dp[1][n] << endl;

	return 0;
}


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

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

    string s;
    cin >> s;
    vector<int> cnt(2);
    for (char c : s) cnt[c - 'A']++;
    if (cnt[0] && cnt[1]) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 256
x = int(input())

max_a = (x // 100) + 1
max_b = (x // 101) + 1
max_c = (x // 102) + 1
max_d = (x // 103) + 1
max_e = (x // 104) + 1

for a in range(max_a):
  for b in range(max_b):
    for c in range(max_c):
      for d in range(max_d):
        for e in range(max_e):
          for_f = x - (a * 100 + b * 101 + c * 102 + d * 103 + e * 104)
          if for_f >= 0 and for_f % 105 == 0:
            # print(a, b, c, d, e, for_f // 105)
            print('1')
            exit(0)
print('0')


Measured memory_bytes: 3064
MAX = 10**5+1

is_prime = [True] * (MAX+1)
is_prime[0] = False
is_prime[1] = False

for i in range(2,MAX+1):
    if is_prime[i]:
        for j in range(i*2, MAX+1, i):
            is_prime[j] = False

likes = [0] * (MAX+1)
for i in range(0, MAX+1):
    if i % 2 == 0: continue
    if is_prime[i] and is_prime[(i+1)//2]:
        likes[i] = 1
    
c = [0] * (MAX+1)
for i in range(MAX):
    c[i+1] = c[i] + likes[i]

Q = int(input())
lr = [list(map(int, input().split())) for _ in range(Q)]

for i in range(Q):
    print(c[lr[i][1]+1] - c[lr[i][0]])







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

int main() {
  int n;
  int result = 0;
  cin >> n;
  vector<int> vec(n);
  for(int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }

  sort(vec.begin(), vec.end(), greater<int>());

  for(int i = 0; i < n; i++) {
    if((i % 2) == 0) {
      result += vec.at(i);
    }
    else {
      result -= vec.at(i);
    }
  }

  cout << result << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned ui;
typedef unsigned long long ul;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef pair<ul, ul> puu;
typedef vector<int> vi;
#define pb push_back
#define fi first
#define se second
#define ls (i << 1)
#define rs (i << 1 | 1)
#define mid (l + r >> 1)
#define enum(i, j, k) for(int i = j; i <= (k); i ++)
#define open(i, j, k) for(int i = j; i <  (k); i ++)
#define dec(i, j, k)  for(int i = j; i >= (k); i --)
#define ae(x) for(node *p = h[x]; p; p = p->nxt)
#define mfil(x, k) memset(x, k, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
#define fio(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout)
template <class T> bool chkmin(T &x, T y)
{ return y < x ? (x = y, true) : false; }
template <class T> bool chkmax(T &x, T y)
{ return y > x ? (x = y, true) : false; }
struct __init { __init()
{
    ios::sync_with_stdio(false); cin.tie(0);
    cout.precision(16); cout << fixed;
    srand(time(0) ^ ui(ul(new char)));
} } static __init__;
/* default code ends here */

const int maxn = 2e5 + 10;
int n, m;
vi h[maxn];
int fa[maxn];
bool ji[maxn];
int getfa(int x)
{
    return fa[x] == x ? x : fa[x] = getfa(fa[x]);
}
void merge(int x, int y)
{
    int f1 = getfa(x), f2 = getfa(y);
    if(f1 != f2)
        fa[f1] = f2;
}

int col[maxn];

void dfs(int x)
{
    for(int v : h[x])
    {
        if(!col[v])
        {
            col[v] = 3 - col[x];
            dfs(v);
        }
        else if(col[v] == col[x])
            ji[getfa(x)] = true;
    }
}

int main()
{
    cin >> n >> m;
    enum(i, 1, n)
        fa[i] = i;
    int u, v;
    enum(i, 1, m)
    {
        cin >> u >> v;
        merge(u, v);
        h[u].pb(v);
        h[v].pb(u);
    }
    enum(i, 1, n)
        if(!col[i])
        {
            col[i] = 1;
            dfs(i);
        }
    
    ll ans = 0, jt = 0, ot = 0;
    enum(i, 1, n)
        if(!h[i].empty() && fa[i] == i)
        {
            if(ji[i])
            {
                ans += jt + ot;
                jt ++;
            }
            else
            {
                ans += jt + 2 * ot;
                ot ++;
            }
        }
    //cerr << jt << ' ' << ot << endl;
    ans *= 2;
    ans += jt + 2 * ot;
    ll tot = 0;
    enum(i, 1, n)
        tot += h[i].empty();
    ans += 2 * tot * n - tot * tot;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 12672
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    string s;
    cin >> s;

    li min_maximum = 0, cur = 0;
    vector<li> min_offset(1, 0);
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '1') {
            cur += 1;
        } else {
            cur -= 1;
        }
        min_offset.emplace_back(cur);
        min_maximum = max(cur, min_maximum);
    }
    vector<li> back_max(s.size() + 1, min_offset.back());
    for (int i = s.size() - 1; i >= 0; --i) {
        back_max[i] = max(back_max[i + 1], min_offset[i]);
    }

    li ans = s.size();
    for (int ub = min_maximum; ub < min_maximum + 2; ++ub) {
        li cur = 0, maximum = 0, minimum = 0;
        for (int i = 0; i < s.size(); ++i) {
            if (s[i] == '0') {
                cur -= 1;
            } else if (s[i] == '1') {
                cur += 1;
            } else {
                if (cur + 1 + max(0LL, back_max[i + 1] - min_offset[i + 1]) > ub) {
                    cur -= 1;
                } else {
                    cur += 1;
                }
            }
            maximum = max(maximum, cur);
            minimum = min(minimum, cur);
        }
        ans = min(ans, maximum - minimum);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 20308
#include <iostream>

using namespace std;

long x,n;

int main ()
{
	cin>>x;
	int x4=int(x%10);
	int x3=int((x/10)%10);
	int x2=int((x/100)%10);
	int x1=int((x/1000)%10);

	if (x1+x2+x3+x4==7)
		cout<<x1<<'+'<<x2<<'+'<<x3<<'+'<<x4<<"=7";
	else if (x1+x2+x3-x4==7)
		cout<<x1<<'+'<<x2<<'+'<<x3<<'-'<<x4<<"=7";
	else if (x1+x2-x3+x4==7)
		cout<<x1<<'+'<<x2<<'-'<<x3<<'+'<<x4<<"=7";
	else if (x1+x2-x3-x4==7)
		cout<<x1<<'+'<<x2<<'-'<<x3<<'-'<<x4<<"=7";
	else if (x1-x2+x3+x4==7)
		cout<<x1<<'-'<<x2<<'+'<<x3<<'+'<<x4<<"=7";
	else if (x1-x2+x3-x4==7)
		cout<<x1<<'-'<<x2<<'+'<<x3<<'-'<<x4<<"=7";
	else if (x1-x2-x3+x4==7)
		cout<<x1<<'-'<<x2<<'-'<<x3<<'+'<<x4<<"=7";
	else if (x1-x2-x3-x4==7)
		cout<<x1<<'-'<<x2<<'-'<<x3<<'-'<<x4<<"=7";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

int main()
{
   int n;
   cin >> n;
   string s;
   cin >> s;
   int ans = 0;
   rep(i,n-2)
   {
      if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
      ans++;
   }
   cout<<ans<<endl;

   return 0;
}

Measured memory_bytes: 256
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int n, a, b;
  scanf("%d%d%d", &n, &a, &b);
  printf("%d\n", MIN(n * a, b));
  return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    long p = 1000000007;
    int N = Integer.parseInt(sc.nextLine());
    int r = 0, g = 0, b = 0;
    long ans = 1;
    for(int i = 0; i < N; i++){
      int M = Integer.parseInt(sc.next());
      int count = 0;
      if(r == M){
        count++;
      }
      if(g == M){
        count++;
      }
      if(b == M){
        count++;
      }
      ans *= count;
      ans %= p;
      if(r == M){
        r++;
      }else if(g == M){
        g++;
      }else if(b == M){
        b++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 47624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a=0,b=0,c=0,d=0;
    cin>>n;
    while(n--)
    {
        string s;

        cin>>s;
        if(s=="AC")
        {
            a++;
        }
        else if(s=="WA")
        {
            b++;
        }
        else if(s=="TLE")
        {
            c++;
        }
        else if(s=="RE")
        {
            d++;
        }

    }
     cout<<"AC x "<<a<<endl;
        cout<<"WA x "<<b<<endl;
        cout<<"TLE x "<<c<<endl;
        cout<<"RE x "<<d<<endl;
}


Measured memory_bytes: 3628
program main
    implicit none
    real(8) a, b, h, m
    real(8) the_a, the_b
    real(8) xa, ya, xb, yb
    real(8) d
    read(*,*) a, b, h, m

    the_a = (h+m/6d1)/1.2d1*2d0*3.14159265358979d0
    the_b = m/6d1*2d0*3.14159265358979d0

    xa = a*cos(the_a)
    ya = a*sin(the_a)

    xb = b*cos(the_b)
    yb = b*sin(the_b)

    d = sqrt((xa-xb)**2d0 + (ya-yb)**2d0)
    
    write(*,*) d

end program

Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
   ll n,y,a,b,c,f=0;
   cin>>n>>y;
   for(int i=0;i<=n;i++)
   {
    for(int j=0;j<=n;j++)
{    
  ///cerr<<(y-(10000*i)-(5000*j))/1000<<"    "<<(n-i-j)<<endl;
  if(((y-(10000*i)-(5000*j))/1000)==(n-i-j)&&(n-i-j)>=0&&((y-(10000*i)-(5000*j))/1000)>=0)
           {
            f=1;
            a=i,b=j,c=n-i-j;
            break;
           }

      
      }
      if(f)
        break;
    }
    
   
   if(f)
    cout<<a<<" "<<b<<" "<<c<<endl;
    else
    {
      cout<<"-1 -1 -1"<<endl;
    } 
}
return 0;
}

Measured memory_bytes: 256
def main():
    N, M, K = map(int, input().split())
    MOD = 998244353

    fac = [0] * 10 ** 6
    inv = [0] * 10 ** 6
    finv = [0] * 10 ** 6

    def COM_init():
        fac[0] = 1
        fac[1] = 1
        inv[1] = 1
        finv[0] = 1
        finv[1] = 1

        for i in range(2, 2 * 10**5 +10):
            fac[i] = fac[i-1] * i % MOD
            inv[i] = -inv[MOD%i] * (MOD//i) % MOD
            finv[i] = finv[i-1]*inv[i]%MOD
        
    def COM(n, k):
        if n < k: return 0
        if n < 0 or k < 0: return 0
        return fac[n] * (finv[n-k] * finv[k] % MOD) % MOD

    COM_init()
    ans = 0
    for i in range(K+1):
        ans += M * pow(M-1, N-i-1, MOD) * COM(N-1, i)
        ans %= MOD

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 51388
#include <stdio.h>

int main() {
	int n, h, maxi = 0;
	bool valid = true;
	scanf("%d", &n);
	while (n--) {
		scanf("%d", &h);
		if (maxi - h > 1) {
			valid = false;
			break;
		}
		if (h > maxi)
			maxi = h;
	}
	if (valid)
		puts("Yes");
	else
		puts("No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	int n, k;
	cin >> n >> k;
	int cnt = 0;
	while(n) {
		n /= k;
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];
#define int long long

signed main(){
    int N; cin >> N;
    vector<int> x(N), y(N), city(N);
    rep(i,N){
        cin >> x[i] >> y[i];
        city[i] = i;
    }
    sort(all(city));
    
    double length = 0;
    int F = 0;
    do{
        F++;
        rep(i,N-1){
            int s = city[i], g = city[i+1];
            length += sqrt(pow(x[s]-x[g],2)+pow(y[s]-y[g],2));
        }
    }while(next_permutation(all(city)));
    
    printf("%.10f\n",length/F);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 #include<iostream>
 using namespace std;
 typedef long long ll;
 int main()
 {
 int a, b, x, y;
 cin>>a>>b>>x>>y;
   int flag=0;
  if(x+x==a&&y+y==b){
    flag = 1;
  }
 printf("%lf %d\n", double(a)*double(b) / 2, flag);
 }

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;class Program
{
	static void Main(string[] args)
	{
        //var exStdIn = new System.IO.StreamReader( "stdin.txt" );System.Console.SetIn( exStdIn );
		int x = int.Parse(Console.ReadLine());
		if(x>=30){
			Console.Write("Yes");
		}else{
			Console.Write("No");
		}
	}
}


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

int N, M;
vector<vector<int>> adj;
vector<int> dp;

int rec(int v)
{
	if (dp[v] != -1)
		return dp[v];
	if (adj[v].empty())
		return dp[v] = 0;
	int ans = 0;
	for (auto it : adj[v])
	{
		ans = max(ans, 1 + rec(it));
	}
	return dp[v] = ans;
}

int main()
{
	ios_base::sync_with_stdio(false);

	cin >> N >> M;
	adj.resize(N);
	for (int i = 0; i < M; i++)
	{
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		adj[x].push_back(y);
	}
	dp.resize(N, -1);
	int answer = 0;
	for (int i = 0; i < N; i++)
	{
		answer = max(answer, rec(i));
	}
	cout << answer;

	return 0;
}

Measured memory_bytes: 11044
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
#include <math.h>
#include <string>
#include <iostream>
#include <functional>
#include <set>
using namespace std;
typedef long long ll;

const int MN = 200000 + 5;
int arr[MN];
set<int> S;

int main()
{
	int N;
	scanf("%d", &N);
	for (int i = 1; i <= N; i++)
	{
		int k;
		scanf("%d", &k);
		if (S.count(k))
		{
			puts("NO");
			return 0;
		}
		S.insert(k);
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define _GLIBCXX_DEBUG
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x;
    cin >> x ;
    printf("%d:%d:%d\n",x/3600,(x/60)%60,x%60);
    }


Measured memory_bytes: 3244
#include <iostream>
#include <string>
using namespace std;
int main() {
	int n;
  	string s;
  	cin >> n;
  	cin >> s;
  	if(n%2 == 1) {
    	cout << "No" << endl;
      	return 0;
    }
  	
  	if(s.substr(0, n/2) == s.substr(n/2, n)) {
    	cout << "Yes" << endl;
    } else {
    	cout << "No" << endl;
    }
}	

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod=1000000007;
//head

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

    int n, weight;
    cin >> n >> weight;
    vll w(n+1);
    vll v(n+1);
    rep(i,1,n+1) cin >> w[i] >> v[i];

    vector<vll> dp(weight+1,vll(n+1,0));

    for(int i = 1; i <= weight; i++) {
        for(int j = 1; j <= n; j++) {
            dp[i][j] = dp[i][j-1];
            if(i - w[j] >= 0) {
                dp[i][j] = max(dp[i][j], dp[i-w[j]][j-1] + v[j]);
            }
        }
    }
    cout << dp[weight][n] << endl;
    return 0;
}


Measured memory_bytes: 82304
#include <bits/stdc++.h>
typedef long long ll;
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define rf(i,a,b) for(ll i=a; i>=b; i--)
typedef std::vector<long long > vi ;
#define F first
#define S second
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 998244353
#define PB push_back
#define MP make_pair
#define PI 3.14159265358979323846
#define all(a) a.begin(),a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define endl '\n'
#define show(a) for(auto el:a)cout<<el<<" "
const ll INF=LLONG_MAX/2;
const ll N=2e5+1;
#define yesno(f) yes(f);no(f);
#define yes(f) if(f)cout<<"YES\n";
#define no(f) if(!f)cout<<"NO\n";
using  namespace std;
ll binarySearch(ll arr[], ll l, ll r,ll x) 
{ 
    if (r >= l) 
    { 
        ll mid = l + (r - l) / 2;  
        if (arr[mid] == x) 
        return mid; 
        if (arr[mid] > x) 
        return binarySearch(arr, l, mid - 1, x); 
        return binarySearch(arr, mid + 1, r, x); 
    }
    return -1; 
} 
int main()
{
    fast;
        ll n,x;
        std::cin >>x>> n;
        ll a[n];
        map<ll,ll>mp;
        fr(i,0,n)
        {
            std::cin >> a[i];
            mp[a[i]]++;
        }
        if(mp.find(x)==mp.end())
        {
            cout<<x<<"\n";
        }
        else
        {
            ll ans,ans1;
            rf(i,x,0)
            {
                if(mp.find(i)==mp.end())
                {
                    ans=i;
                    break;
                }
            }
            fr(i,x,102)
            {
                if(mp.find(i)==mp.end())
                {
                    ans1=i;
                    break;
                }
            }
            if(x-ans>ans1-x)
            cout<<ans1<<"\n";
            else
            cout<<ans<<"\n";
        }
        
}

Measured memory_bytes: 3648
sa = gets.chomp.split('').to_a
sb = gets.chomp.split('').to_a
sc = gets.chomp.split('').to_a
card = sa.shift
while (true)
  if card == "a"
    if sa.size == 0
      puts "A"
      exit
    end
    card = sa.shift
  elsif card == "b"
    if sb.size == 0
      puts "B"
      exit
    end
    card = sb.shift
  else
    if sc.size == 0
      puts "C"
      exit
    end
    card = sc.shift
  end
end

Measured memory_bytes: 1788
n=int(input())
c=input().split();d=c[:]
for i in range(n-1):
 for j in range(0,n-i-1):
  if c[j][1]>c[j+1][1]:c[j],c[j+1]=c[j+1],c[j]
 b=[s[1]for s in d];m=b.index(min(b[i:]),i)
 if b[i]>b[m]:d[i],d[m]=d[m],d[i]
print(*c);print("Stable")
print(*d)
print(["Not stable","Stable"][c==d])


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

const ll MX = 1e18;
const long double PI = acos(-1);

int main()
{
    ll n; cin >> n;
    vector<char> s;
    while(n > 26)
    {
        if(n%26 == 0)
        {
            s.push_back(122);
            n -= 26;
        }
        else
            s.push_back(n%26+96);
        n /= 26;
    }
    s.push_back(n+96);
    reverse(s.begin(), s.end());
    
    rep(i,s.size())
        printf("%c", s[i]);
    cout << endl;
    return 0;
}

Measured memory_bytes: 3604
import Control.Monad
import Data.Ord
import Data.List

main :: IO ()
main = do
  n <- readLn :: IO Int
  dat <- forM [1..n] $ \i -> do
    [s,p] <- words <$> getLine
    return (s,(read::String->Int) p,i)

  let sorted = sortBy (\ (s1,p1,_) (s2,p2,_) -> if compare s1 s2 == EQ then compare p2 p1 else compare s1 s2) dat
  let ans = map (\(_,_,i) -> i) sorted

  mapM_ print $ ans
  


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 100005

ll a , b , x;
ll f(ll n){
    ll ans = 1;
    for(ll i = 0; i < 5; i++){
        ans *= n;
    }
    return ans;
}

int main()
{
    _FastIO;
    cin >> x;
    for(a = 0; a <= 1000; a++){
        for(b = 0; b <= 1000; b++){
            if(f(a) - f(b) == x){
                cout << a << " " << b << endl;
                return 0;
            }
            if(f(a) + f(b) == x){
                cout << a << " " << (-1) * b << endl;
                return 0;
            }
            if((-1) * f(b) - f(a) == x){
                cout << (-1) * a << " " << b << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define MAX  1e18
#define ss 1e15
#define pb push_back

int main() {    
    int n,m;
    cin>>n>>m;
    vector<int> arr[m];
    for(int i=0;i<m;i++){
        int x;
        cin>>x;
        for(int j=0;j<x;j++){
            int p;
            cin>>p;
            p--;
            arr[i].push_back(p);
        }
    }

    int p[m];
    for(int i=0;i<m;i++)cin>>p[i];

    int ans = 0;
    for(int i=0;i<(1<<n);i++){
        vector<int> v;
        for(int j=0;j<n;j++){
            if(((1<<j)&i) > 0){
                v.push_back(1);
            }else{
                v.push_back(0);
            }
        }
        reverse(v.begin(),v.end());
        bool flag = 0;
        for(int j=0;j<m;j++){
            int count = 0;
            for(int k : arr[j]){
                if(v[k])count++;
            }
            if(count%2 != p[j]){
                flag = 1;
            }
        }
        if(flag == 0){
            ans++;
        }
    }
    cout<<ans<<"\n";
    return 0;
}


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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

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

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

const int MAX_N = 200000;
int n;
int h[MAX_N];
int a[MAX_N];
map<int,ll> b;

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> n;

  forn(i,n) cin >> h[i];
  forn(i,n) cin >> a[i];

  forn(i,n) {
    if (!b.empty()) {
      auto it = b.lower_bound(h[i]);
      ll bt;
      if (it == b.begin()) {
        bt = a[i];
      } else {
        it--;
        bt = it->snd + a[i];
      }

      // iより高い花を右端に持ち,btより美しさが小さいような列の情報を削除
      it = b.upper_bound(h[i]);
      while (it != b.end() && it->snd <= bt) it++;
      b.erase(b.upper_bound(h[i]),it);

      b[h[i]] = bt;
    } else {
      b[h[i]] = a[i];
    }
  }

  cout << b.rbegin()->snd << endl;

  return 0;
}


Measured memory_bytes: 14336
// Problem : A - Payment
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	if (n % 1000 == 0) cout << 0 << endl;
	else cout << 1000 - (n % 1000);
	return 0;
}
 


Measured memory_bytes: 3644
#include <stdio.h>
int main(void){
    int i, n;
    int a[1000];
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%d", &a[i]);
    }
    for(i=0; i<(n/2); i++){
        int t=a[i];
        a[i]=a[n-1-i];
        a[n-1-i]=t;
    }
    
    for(i=0; i<n; i++){
        if(i==0){
        printf("%d", a[i]);
    }else{
        printf(" %d", a[i]);
    }
    }
    printf("\n");
    return 0;
    
}



Measured memory_bytes: 2104
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

int[10^^5] HS;

void main()
{
    auto nk = readln.split.to!(int[]);
    auto N = nk[0];
    auto K = nk[1];

    foreach (i; 0..N) HS[i] = readln.chomp.to!int;
    sort(HS[0..N]);

    auto min_h = HS[N-1];
    foreach (i; 0..N-K+1) {
        min_h = min(min_h, HS[i+K-1] - HS[i]);
    }
    writeln(min_h);
}

Measured memory_bytes: 1660
/*
  AOJ 1244
  Title:molecular fomula
  @kankichi573
*/
#include <stdio.h>
#include <string.h>
#include <setjmp.h>

jmp_buf jb;
int atom[26][27];
int stack[80];
int sp;

int reduce_all()
{
  int i,ret;
  for(i=sp-1,ret=0;i>=0;i--)
    ret += stack[i];
  return(ret);
}
void reduce_paren()
{
  int i,ret;
  for(i=sp-1,ret=0;stack[i]>0 && i>=0;i--)
    ret += stack[i];
  stack[i]=ret;
  sp=i+1;
}

int atom2weight(char *a,int len)
{
  int ret;

  if(len==1)
    ret=atom[a[0]-'A'][0];
  else
    ret=atom[a[0]-'A'][a[1]-'a'+1];
  if(ret==0)
    longjmp(jb,1);
  else
    return(ret);
}
void push(int n)
{
  stack[sp]=n;
  sp++;
}
int solve(char *buf)
{
  char *p;
  p=buf;
  sp=0;
  while(*p)
    {
      if(isupper(p[0]))
	{
	  if(islower(p[1]))
	    {
	      push(atom2weight(p,2));
	      p++;
	    }
	  else
	    push(atom2weight(p,1));
	}
      else if(isdigit(p[0]))
	{
	  if(isdigit(p[1]))
	    {
	      stack[sp-1] *= (p[0]-'0')*10+(p[1]-'0');
	      p++;
	    }
	  else
	    stack[sp-1] *= (p[0]-'0');
	}
      else if(p[0]=='(')
	push(0);
      else if(p[0]==')')
	reduce_paren();
      p++;
    }
  return(reduce_all());
}
main()
{
  char buf[20],buf2[82],abuf[3];
  int  w,ret;

  while(fgets(buf,20,stdin) && 0!=strncmp(buf,"END_",4)) 
    {
      sscanf(buf,"%s %d",abuf,&w);
      if(strlen(abuf)==1)
	atom[abuf[0]-'A'][0]=w;
      else
	atom[abuf[0]-'A'][abuf[1]-'a'+1]=w;
      
    }

  while(fgets(buf2,82,stdin) && buf2[0]!='0')
    {
      if(setjmp(jb)==0)
	{
	  ret=solve(buf2);
	  printf("%d\n",ret);
	}
      else
	  printf("UNKNOWN\n");
    }

  return(0);
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, start, end) for(int i = start; i < (int)(end); ++i)

int main(){
    string s, t;
    cin >> s >> t;
    bool flag = true;
    rep(i,0,s.size()){
        if(s[i] != t[i]){
            flag = false;
            break;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>

using namespace std;

signed main(){

   while(1){
      int n;
      cin>> n;
      if(!n) break;

      int w[n];
      for(int i=0; i<n; i++){
         string s;
         cin>> s;
         w[i]=s.size();
      }
      int b[]={5, 7, 5, 7, 7};
      for(int i=0; i<n; i++){
         int a=0, p=0;
         for(int j=i; j<n; j++){
            a+=w[j];
            if(a>b[p]){
               goto turai;
            }else if(a==b[p]){
               p++;
               if(p==5) break;
               a=0;
            }
         }
         if(p==5){
            cout<< i+1<< endl;
            break;
         }
         turai:;
      }

   }

   return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	int a,b,sum=0;
	cin >> a >> b;
	int maxx = max(a,b),minn=min(a,b);
	sum += maxx;
	maxx--;
	sum += max(maxx,minn);
	cout << sum << endl;
	
	
	
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define MAX_N 100000
int dp[MAX_N+1];

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

    int N; cin >> N;
    vei h(N); rep(i,N) cin >> h[i];

    memset(dp, INF, sizeof(dp));

    rep(i,N) {
        if(i == 0) dp[0] = 0;
        else if(i == 1) dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
        else dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
    }
    cout << dp[N-1] << endl;
    return 0;
}



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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

template<typename T>
vector<T> slide_max(vector<T>& v, int k) {
  deque<int> deq;
  vector<T> ret;
  for (int i = 0; i < v.size(); i++) {
    while (!deq.empty() && v[deq.back()] <= v[i]) {
      deq.pop_back();
    }
    deq.push_back(i);
    if (i - k + 1 >= 0) {
      ret.emplace_back(v[deq.front()]);
      if (deq.front() == i - k + 1) deq.pop_front();
    }
  }
  return ret;
}

void solve() {
  int n, k;
  cin >> n >> k;
  vector<double> a(n);
  vi c(1000);
  iota(c.begin(), c.end(), 1);
  vi cum(1001);
  rep(i, 1000) {
    cum[i + 1] = cum[i] + c[i];
  }
  dumpv(cum, 10);
  rep(i, 1000) {
  }
  rep(i, n) {
    int p;
    cin >> p;
    a[i] = (double)cum[p] / (double)p;
  }
  dump(a);
  vector<double> b(n + 1);
  rep(i, n) {
    b[i + 1] = b[i] + a[i];
  }
  double ans = 0.0;
  rep(i, n - k) maxs(ans, b[i + k + 1] - b[i + 1]);
  if (n == k) ans = b[n];
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 3456