akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

typedef long long ll;

int main() {
    int N, K;
    cin >> N >> K;

    vector<ll> x;
    for(int i = 0; i < N; i++) {
        ll tmp;
        cin >> tmp;
        x.push_back(tmp);
    }

    int left, right;
    ll min_val = 9999999999999999;
    for(int i = 0; i < N - K + 1; i++) {
        left = i;
        right = left + K - 1;

        ll left_path = abs(x[left]) + abs(x[right]-x[left]);
        ll right_path = abs(x[right]) + abs(x[left]-x[right]);
        min_val = min({min_val, left_path, right_path});
    }

    cout << min_val << endl;

}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>

int main()
{
  char S[5];
  for (int i=0; i<4; i++) std::cin >> S[i];
  std::sort(S, S+4);
  if (S[0]==S[1] && S[1] != S[2] && S[2] == S[3]) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
  return 0;
}


Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main(void){
    int n,m;
    cin>>n>>m;
    int a[50]={0},b[50]={0};
    for(int i(0);i<m;i++){
        cin>>a[i]>>b[i];
    }
    int cnt[50]={0};
    for(int i(0);i<m;i++){
        cnt[a[i]-1]++;
        cnt[b[i]-1]++;
    }
    for(int i(0);i<n;i++){
        cout<<cnt[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;
class SocialGame
{
	static void Main(string[] args)
	{
		string[] buf = Console.ReadLine().Split(' ');
		int A = int.Parse(buf[0]);
		int B = int.Parse(buf[1]);
		int C = int.Parse(buf[2]);
		Console.WriteLine(countdays(A, B, C));
	}
 
	static int countdays(int A, int B, int C) 
	{
	    // 1週間は7日間、各日にA個、7日経過後にB個のコインが貰える
	    // Cコイン獲得するために最低何日必要か？
	    int countdays = 0;
	    int countCountedCoins = 0;
	    int oneWeekCoins = A*7+B;
	    
	    int oneWeekCount = C/oneWeekCoins;
	    countdays += oneWeekCount*7;
	    countCountedCoins += oneWeekCount*oneWeekCoins;
	    
	    int remainingCoins = C-countCountedCoins;
	    if (remainingCoins>0) {
	        int remainingDays = 0;
	        if (remainingCoins%A == 0) {
	            remainingDays = remainingCoins/A;
	        }
	        else {
	            remainingDays = (remainingCoins/A)+1;
	        }
    	    if (remainingDays<7) {
    	        countdays += remainingDays;
    	    }
    	    else {
    	        countdays += 7;
    	    }
	    }
	    
	    return countdays;
	}
}


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

#define mainspring cout<<"mainspring\n";
#define barrel cout<<"barrel\n";
#define escapement cout<<"escapement\n";

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second
#define tik(i,a,b) for(int i = a; i < b; i++)
#define tok(i,a,b) for(int i = a; i >= b; i--)
#define error(args...) {string _s = #args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}

typedef long long ll;
typedef unsigned long long ull;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << " ";
    err(++it, args...);
}

ll pow(ll x, ll y) {
	if(y == 0)
	return 1;
	ll temp = pow(x, y/2);
	temp = (temp*temp);
	if(y%2 == 1)
		temp *= x;
	return temp;
}

int main() {
	string s;
	cin >> s;
	int n = sz(s) + 1;
	s = '0' + s;
	string tmp = s;
	string t = s;
	int res = 0;
	for(int i = n - 1; i >= 0; i--) {
		if(tmp[i] > '5' || (tmp[i] == '5' && tmp[i - 1] >= '5')) {
			// error(tmp[i], (int)(tmp[i] - '0'));
			t[i] = '0' + 10 - (int)(tmp[i] - '0');
			s[i] = '0';
			tmp[i - 1] += 1;
		}
		else {
			t[i] = '0';
			s[i] = tmp[i];
		}
	}
	res = 0;
	for(char ch : s) {
		res += ch - '0';
	}
	for(char ch : t) {
		res += ch - '0';
	}
	cout << res;
}


Measured memory_bytes: 3248
n, m = map(int, input().split())

if n >= 2 and m >= 2:
    print((n-2)*(m-2))
elif (n == 1 and m >= 3) or (n >= 3 and m == 1):
    print(max(n, m)-2)
elif (n == 1 and m == 2) or (n == 2 and m == 1):
    print(0)
elif (n == 1 and m == 1):
    print(1)

Measured memory_bytes: 9108
import sys
mod = 10**9 + 7
N=int(input())
S = input()
leftL = 0
leftR = 0
ISR = []
for s in S:
  if s=="B":#leftL-leftRと同符号
    isR = abs(leftL-leftR)
  else:
    isR = int(not bool(abs(leftL-leftR)))
  if isR:
    leftR = (leftR+1)%2
  else:
    leftL = (leftL+1)%2
  ISR.append(isR)

if sum(ISR)!=N:
  print(0)
  sys.exit()

zanki = 0
ans = 1
for i in ISR:
  if zanki<0:
    print(0)
    sys.exit()
  if i:#Rの場合
    ans *= zanki
    zanki -= 1
  else:
    zanki += 1
  ans %= mod

for j in range(1,N+1):
  ans = (ans*j)%mod

print(ans)

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

using namespace std;

int main(){
	int N, K, ans = 0; cin >> N >> K;
	int x;
	for(int i = 0; i < N; ++i){
		cin >> x;
		ans += min(abs(x*2), abs((K-x)*2));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll M, D, ans = 0;

int main() {
	cin >> M >> D;
	for (int i = 1; i <= M; i++) {
		for (int j = 1; j <= D; j++) {
			if (j % 10 >= 2 && j / 10 >= 2 && (j % 10) * (j / 10) == i)ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include "iostream"
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  bool check = false;
  while (2 * n <= m) {
    if (m % n == 0) {
      cout << m / n << endl;
      check = true;
      break;
    }
    n++;
  }
  if (check == false) {
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include<string.h>
#include <math.h>
#include <stack>
#define ll long long
using namespace std;
int a[100010];
int main() {
	int n, m;
	int h, w;
	scanf("%d %d", &n, &m);
	scanf("%d %d", &h, &w);
	int res = n*m - (h*m + n * w - h * w);
	printf("%d\n", res);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n)  for(int i = 0; i < n; i++)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define unique(a)       sort((a).begin(), a.end()), (a).erase(unique((a).begin(), (a).end()),(a).end())
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;

LL gcd(LL a, LL b)
{
	if (!a)return b; return gcd(b%a, a);
}
double intlog(double base, double x) {
	return (double)((double)log(x) / (double)log(base));
}

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

	for(int i=1;i<4;i++)
	{
		if (s[i] == s[i - 1])
		{
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
}













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

using T = int;
const T id = INT_MAX;
T op(T x, T y) {
	return min(x, y);
}

const int MAX = 1 << 17;
T seg[MAX << 1];

void init_seg() {
	fill(seg, seg + (MAX << 1), id);
}
void init_seg(const vector<int>& v) {
	copy(v.begin(), v.end(), seg + MAX);
	for (int i = MAX - 1; i > 0; --i)
		seg[i] = op(seg[i << 1], seg[(i << 1) | 1]);
}
void init_seg(T val) {
	fill(seg + MAX, seg + (MAX << 1), val);
	for (int i = MAX - 1; i > 0; --i)
		seg[i] = op(seg[i << 1], seg[(i << 1) | 1]);
}

void update(int p, T val) {
	for (seg[p += MAX] = val; p > 1; p >>= 1) {
		seg[p >> 1] = op(seg[p], seg[p ^ 1]);
	}
}

T find(int l, int r) {
	T res1 = id, res2 = id;
	for (l += MAX, r += MAX; l < r; l >>= 1, r >>= 1) {
		if (l & 1) res1 = op(res1, seg[l++]);
		if (r & 1) res2 = op(seg[--r], res2);
	}
	return op(res1, res2);
}

int main()
{
	int n, q;
	scanf("%d%d", &n, &q);
	init_seg();
	while (q--) {
		int com, x, y;
		scanf("%d%d%d", &com, &x, &y);
		if (com == 0) {
			update(x, y);
		}
		else {
			printf("%d\n", find(x, y + 1));
		}
	}
	return 0;
}



Measured memory_bytes: 4248
def resolve():
    import numpy as np
    import itertools
    import copy

    H, W, K = map(int, input().split())
    table = []
    for _ in range(H):
        s = list(input())
        table.append(s)

    ans = 0
    for i in range(2**H):
        mask_h = format(i, '0{}b'.format(H))
        for j in range(2**W):
            mask_w = format(j, '0{}b'.format(W))
            black = 0
            for di in range(H):
                for dj in range(W):
                    if mask_h[di] == '0' and mask_w[dj] == '0' and table[di][dj] == "#":
                        black += 1
            if black == K:
                ans += 1
    print(ans)

resolve()

Measured memory_bytes: 27076
#include <iostream>  
int main(){
    int a,b;
    std::cin>>a>>b;
    if(a>b){
    std::cout<<"a > b"<<std::endl;
    }
    else if (a==b){
        std::cout<<"a == b"<<std::endl;
    }

else{
    std::cout<<"a < b"<<std::endl;
    }
    return 0;
}


Measured memory_bytes: 3092
# Binary Search

def isOK(i, key):
    '''
    問題に応じて返り値を設定
    '''
    cnt = 0
    for v in a:
        cnt += (v + i - 1) // i - 1

    return cnt <= key


def binary_search(key):
    '''
    条件を満たす最小/最大のindexを求める
    O(logN)
    '''
    ok = 10 ** 9  # 条件を満たすindexの上限値/下限値
    ng = 0        # 条件を満たさないindexの下限値-1/上限値+1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2

        if isOK(mid, key):  # midが条件を満たすか否か
            ok = mid
        else:
            ng = mid
    
    return ok


n, k = map(int, input().split())
a = list(map(int, input().split()))
 
print(binary_search(k))

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

int main(){
  long double a,b,h,m;
  cin >> a >> b >> h >> m;
  
  long double zi = 0,byou = 0;
  
  zi += 30 * h;
  long double kari = m / 2;
  zi += kari;
  
  byou += 6 * m;
  
  long double kakudo = max(zi,byou) - min(zi,byou);  
  if(kakudo > 180)kakudo = 360 - kakudo;
 
  long double sinkakudo = kakudo * 3.14159265359 / 180;
  
  long double kekka = (a * a) + (b * b) - 2 * a * b * (cos(sinkakudo));
  kekka = sqrt(kekka);
  cout << setprecision(20) << kekka << endl;
}

Measured memory_bytes: 4124
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()
    println(problem155a(a, b, c))
}

fun problem155a(a: Int, b: Int, c: Int): String {
    return if ((a == b && b != c) || (a != b && b == c) || (a == c && b != c)) "Yes" else "No"
}

Measured memory_bytes: 31524
using System;
class Enki
{
  static void Main()
  {
    string b=Console.ReadLine();
    if(b=="A")
      Console.WriteLine("T");
    else if(b=="C")
      Console.WriteLine("G");
    else if(b=="T")
      Console.WriteLine("A");
    else
      Console.WriteLine("C");
  }
}


Measured memory_bytes: 11092
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for i in a:
    d[i] += 1

if len(d) >= 4:
    print("No")
    exit()

if len(d) == 1:
    if 0 in d:
        print("Yes")
        exit()
    else:
        print("No")
        exit()

if len(d) == 2:
    if (N % 3) == 1 and 0 in d and d[0] == N // 3:
        print("Yes")
        exit()
    elif (N % 3) == 2 and 0 in d and d[0] == ((N // 3) + 1):
        print("Yes")
        exit()
    elif (N % 3) == 0 and 0 in d and d[0] == N // 3:
        print("Yes")
        exit()
    else:
        print("No")
        exit()

if len(d) == 3:
    l = list(d.values())
    l.sort()
    if l[0] == l[-1]:
        keys = list(d.keys())
        if keys[0] ^ keys[1] == keys[2]:
            print("Yes")
            exit()

print("No")


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

int main(){
  int N,M;
  cin >> N >> M;
  int L=0;
  int R=1000000;
  rep(i,M){
    int Li,Ri;
    cin >> Li >> Ri;
    if(Li>=L){
      L = Li;
    }
    if(Ri<=R){
      R = Ri;
    }
  }
  if(R-L>=0){cout << R-L+1 << endl;}
  else{cout << "0" << endl;}


  return 0;
}

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

int main() {
  string S;
  cin >> S;

  string ans;
  int i;
  for(i = 0; i < S.size(); i++){
    if((i % 2) == 1){
      if(S.at(i) == 'R'){
        cout << "No" << endl;
        ans = "No";
        break;
      }
    }
    else{
      if(S.at(i) == 'L'){
        cout << "No" << endl;
        ans = "No";
        break;
      }
    }
  }
  if(ans != "No"){
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
n = int(input())
s = [input() for i in range(n)]

d = {}
for str in s:
    d[str] = d.get(str,0) + 1

t = max(d.values())
ans = []
for p in d:
    if d[p] == t : ans.append(p)

ans.sort()
print("\n".join(ans))

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

int n,h[1000];
int main(){
  cin >> n;
  for(int i=0;i<n;i++)cin >> h[i];
  sort(h,h+n,greater<int>());
  long long ans = 0;
  for(int i=0;i<n;i++)ans += max(0,h[i]-i/4);
  cout << ans+1 << endl;
}

Measured memory_bytes: 1180
#include<iostream>
#include<string.h>
using namespace std;
char a[1001];
int main(){
	cin>>a;
	int len=strlen(a),f=0;
	int n=(len - 1) / 2 - 1;
	int m=(len + 3) / 2 - 1;
	//cout<<check(a,0,len-1)<<" ";
	for(int i=0;i<len/2-1;i++){
		if(a[i]!=a[len-i-1]){
			f=1;break;
		}
	}
	if(f==0){
		for(int i=0;i<n/2;i++){
			if(a[i]!=a[n-i]){
				f=1;break;
			}
		}
	}
	if(f==0){
		for(int i=0;i<(len-m)/2;i++){
			if(a[m+i]!=a[len-1-i]){
				f=1;break;
			}
		}
	}
	
	if(f==0){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

#define watch(x) cout << (#x) << " is " << (x) << endl
#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
#define repn(i, st, en) for(int i=st; i>=en; i--)
#define sq(a) (a*a)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll mod = 1e9+7;


ll modularExponentiation(ll x, ll y, ll p = mod){
    if(y==0)
        return 1;
    if(y == 1)
        return x;
    if(y&1){
        /// y is odd, so (x*(x^(y-1)))%p
        return (x*modularExponentiation(x, y-1, p))%p;
    } else {
        /// y is even, so (x^(y/2))^2
        ll c = modularExponentiation(x, y/2, p);
        return (c*c)%p;
    }
}

const int N = 2e5 + 5;
ll fac[N];
ll inv[N];


void fill_(ll n, ll p = mod){
    fac[0] = 1ll;
    rep(i, 1, n) fac[i] = (ll) fac[i-1] * (i) % p;
    inv[n] = modularExponentiation(fac[n], p - 2ll, p);
    repn(i, n-1, 0) inv[i] = (ll) inv[i+1] * (i + 1ll) %p;
}

ll ncr(ll n, ll r, ll p = mod){
    if(n < 0 || r < 0 || r > n) return 0ll;
    return (((fac[n]*inv[n-r])%p)*inv[r])%p;
}

ll paths(ll a, ll b){
    return ncr(a+b, a);
}

void sub_self(ll &a, ll b){
    a -= b;
    if(a < 0) a += mod;
}

ll mul(ll a, ll b){
    return (ll) a * b % mod;
}

bool le(const pll &a, const pll &b){
    return (a.first <= b.first && a.second <= b.second);
}

void solve(){
    ll h, w, n;
    cin>>h>>w>>n;
    vector<pll> points(n+1);
    fr(i, n){
        cin>>points[i].first>>points[i].second;
    }

    fill_(h + w + 1ll);

    points[n] = {h, w}; /// dummy

    sort(points.begin(), points.end(), [&](pll &a, pll &b){
        return a.first + a.second < b.first + b.second;
    });

    vector<ll> dp(n+1, 0ll);
    /// dp[i] = no. of paths till i, such that it is the first forbidden point

    for(int i=0; i<=n; i++){
        dp[i] = paths(points[i].first - 1, points[i].second - 1);

        for(int j = 0; j < i; ++j){
            if(le(points[j], points[i])){
                sub_self(dp[i], mul(dp[j], paths(points[i].first - points[j].first, points[i].second - points[j].second)));
            }
        }
    }
    cout<<dp[n];
}

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

    ll t = 1;
    //  cin>>t;
    while(t--){
        solve();
    }

    return 0;
}



Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif
  int x, y, z; cin >> x >> y >> z;
  cout << z << ' ';
  cout << x << ' ';
  cout << y << ' ';
  return 0;
}


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

int main() {
int a,b,c,d;
cin>>a>>b>>c>>d;
if(abs(a-c)<=d){
  cout<<"Yes"<<endl;
  return 0;
}
if(abs(a-b)<=d && abs(b-c)<=d){
  cout<<"Yes"<<endl;
  return 0;
}

cout<<"No"<<endl;
return 0;


}


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

int main()
{
	int n;
	cin >> n;
	for(int i = 1;i <= 50000;i++){
		if((int)(i * 1.08 )== n){
			printf("%d\n",i);
			return 0;
		}
	}
	printf(":(");
	return 0;
}


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

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.1415926535897932384626

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

int n, m, vis[100005], col[100005];

vector<int> v[100005];

int sz[100005], bicol[100005], p;

LL ans;

void dfs(int id, int C){
	sz[p]++;
	for(auto to: v[id]){
		if(vis[to]){
			if(col[to] == C){
				bicol[p] = false;
			}
		}
		else{
			col[to] = 1 - C;
			vis[to] = true;
			dfs(to, 1 - C);
		}
	}
	return;
}

int codd, ceven, cone;

int main(){
	scanf("%d %d", &n, &m);
	FI(i, 1, m){
		int a, b;
		scanf("%d %d", &a, &b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	
	FI(i, 1, n) if(!vis[i]){
		vis[i] = true;
		bicol[++p] = true;
		col[i] = 0;
		dfs(i, 0);
	}
	
	ans = 0;
	int omg = 0;
	FI(i, 1, p){
		//add self
		if(bicol[i] && sz[i] > 1) ans += 2;
		else ans++;
		
		//with previous
		if(bicol[i] && sz[i] > 1){
			ans += 2 * codd + 4 * ceven + 2 * cone * sz[i];
			ceven++;
		}
		else{
			if(sz[i] == 1){
				ans += 2 * omg;
				cone++;
			}
			else{
				ans += 2 * (codd + ceven + cone * sz[i]);
				codd++;
			}
		}
		
		omg += sz[i];
	}
	
	printf("%lld\n", ans);
	return 0;
}


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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

ll n , a, b; 
string S;
//Write From this Line

int main()
{
	cout << setprecision(10);
	cin >> n ;
	vector<int> b(n);
	vector<int> ans(n,-1);
	rep(i,n){
		cin >> b[i];
		if(b[i] > i + 1 ){
			//i番目にi+1 よりも大きいものが入っていたらダメ
			cout << -1 << endl;
			return 0 ;
			//荘じゃなければ作れる。
		}
	}
	//i番目の削除を削除はv.erase(v.begin() + i );
	int num;
	int del ;
	for(int i = n -1 ; i >= 0 ; i --){//
		for(int j =  0; j  < b.size();j++){
			if(b[j] == j+1 ){
				num = j + 1 ;
				del = j;
			}

		}
		ans[i] = num;
		b.erase(b.begin() + del);
	}
	for(auto x : ans){
		cout << x << endl;
	}

}


Measured memory_bytes: 256
//https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/2/DSL_2_G
#include <bits/stdc++.h>

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

typedef struct lazysegtree{
	int n;
	vector<ll> arr,lazy;
	lazysegtree(){};
	lazysegtree(int n){init(n);};

	void init(int n_){
		n = 1;
		while(n<n_)n*=2;
		arr.resize(2*n-1,0);
		lazy.resize(2*n-1,0);
	}
	void lazyEvaluate(int pos,ll len){
		arr[pos]+=lazy[pos]*len;

		if(pos<n-1){
			lazy[2*pos+1]+=lazy[pos];
			lazy[2*pos+2]+=lazy[pos];
		}
		lazy[pos]=0;
	}

	
	//[a,b)にxを加える
	void update(int a,int b,int k,int l,int r,ll x){
		lazyEvaluate(k,r-l);
		if(r<=a || b<=l)return;
		if(a<=l&&r<=b){
			lazy[k]+=x;
			lazyEvaluate(k,r-l);
			return;
		}
		
		update(a,b,2*k+1,l,(l+r)/2,x);
		update(a,b,2*k+2,(l+r)/2,r,x);
		arr[k] = arr[2*k+1]+arr[2*k+2];

		return;
	}

	ll getSum(int a,int b,int k,int l,int r){
		lazyEvaluate(k,r-l);
		if(r<=a || b<=l)return 0;
		if(a<=l&&r<=b) return arr[k];

		ll left_value  = getSum(a,b,2*k+1,l,(l+r)/2);
		ll right_value = getSum(a,b,2*k+2,(l+r)/2,r);

		return left_value+right_value;
	}

}lazysegtree;

int main()
{
	int n,q;
	cin>>n>>q;
	lazysegtree seg(n);
	rep(qq,q){
		int query;
		cin>>query;
		if(query==0){
			int s,t,x;
			cin>>s>>t>>x;
			s--,t--;
			seg.update(s,t+1,0,0,seg.n,x);
		}else{
			int s,t;
			cin>>s>>t;
			s--,t--;
			cout<<seg.getSum(s,t+1,0,0,seg.n)<<endl;
		}
		// cout<<"current arr"<<endl;
		// rep(i,seg.arr.size())cout<<seg.arr[i]<<" ";
		// cout<<endl;
		// rep(i,seg.lazy.size())cout<<seg.lazy[i]<<" ";
		// cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 6976
/*****************************
Filename: dkljlkfd.cpp
Author: hbb
Create: 2020-04-05 13:36:56
 *****************************/
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<climits>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
const int inf = INT_MAX >> 1;
typedef long long int LL;

char s[maxn];
int main(){
	scanf("%s", s + 1);
	if(s[3] == s[4] && s[5] == s[6]) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;


int main() {
    ll x,y;
    cin >> x >> y;
    bool ok = false;
    for (ll a = 0;a<=x;a++) {
        ll b = x-a;
        if (2*a+4*b==y) {
            ok = true;
        }
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int  N, M;
bool adj[50][50];
bool visited[50];
std::vector< std::pair<int, int> > edge;

void dfs(int v) {
    visited[v] = true;
    for (int u=0; u<N; ++u) {
        if (adj[v][u] && !visited[u]) dfs( u );
    }
}

bool is_connected() {
    for (int i=0; i<N; ++i) visited[i] = false;
    dfs(0);
    for (int i=0; i<N; ++i) {
        if ( !visited[i] )  return false;
    }
    return true;
}

int main() {
    int ans = 0;
    std::cin >> N >> M;
    for (int i=0; i<M; ++i) {
        int a, b;
        std::cin >> a >> b;
        --a; --b;
        adj[a][b] = true;
        adj[b][a] = true;
        edge.push_back( std::make_pair(a, b) );
    }

    for (auto p : edge) {
        adj[p.first][p.second] = false;
        adj[p.second][p.first] = false;
        if ( !is_connected() ) ++ans;
        adj[p.first][p.second] = true;
        adj[p.second][p.first] = true;
    }

    std::cout << ans << std::endl;

    return 0;
}



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

#define int ll
#define FOR(i,n,k) for(int i=n;i<k;i++)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int32_t main()
{
    IOS;
    string s[3];
    cin>>s[0]>>s[1]>>s[2];
    int t = 0;
    while(true)
    {
        if(s[t].size()==0)
        {
            cout<<(char)(t + 'A')<<'\n';
            break;
        }
        int c = s[t][0] - 'a';
        s[t].erase(s[t].begin());
        t = c;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
vector<int>kaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    //if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n,x[200010],y[200010],MIN=INF,MAX=-INF,ans=INF;
signed main(){
    cin>>n;
    rep(i,n){
        cin>>x[i]>>y[i];
        chmin(MIN,x[i]);
        chmin(MIN,y[i]);
        chmax(MAX,x[i]);
        chmax(MAX,y[i]);
    }
    {
        int Rmi=INF,Rma=-INF,Bmi=INF,Bma=-INF;
        rep(i,n){
            int r=x[i],b=y[i];
            if(r>b)swap(r,b);
            chmin(Rmi,r);
            chmax(Rma,r);
            chmin(Bmi,b);
            chmax(Bma,b);
        }
        chmin(ans,(Rma-Rmi)*(Bma-Bmi));
    }
    {
        //(MAX-MIN)
        int ma=-INF;
        priority_queue<P,vector<P>,greater<P>>q;
        rep(i,n){
            int r=x[i],b=y[i];
            if(r>b)swap(r,b);
            q.push({r,b});
            chmax(ma,r);
        }
        chmin(ans,(MAX-MIN)*(ma-q.top().fi));
        rep(i,n){
            P p=q.top();
            q.pop();
            swap(p.fi,p.se);
            q.push(p);
            chmax(ma,p.fi);
            chmin(ans,(MAX-MIN)*(ma-q.top().fi));
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main()
{

        int N;
        cin >> N;

        map<string, int> m;

        for (int i = 0; i < N; ++i) {
                string tmp;
                cin >> tmp;
                m[tmp] += 1;
        }

        int maxv = -1;
        for (auto i : m) {
                if (maxv == -1) {
                        maxv = i.second;
                }
                else if (maxv < i.second) {
                        maxv = i.second;
                }
        }
        for (auto i : m) {
                if (i.second == maxv) {
                        cout << i.first << endl;
                }
        }



}


Measured memory_bytes: 25216
m,d=map(int,input().split())
n,k=map(int,input().split())
ans=chk=0
print(1 if (m in [1,3,5,7,8,10,12] and d==31) or (m in [4,6,9,11] and d==30) or (m==2 and d==28) else 0)

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

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<long long> vll;
typedef long long ll;
typedef vector<int> vi;

const int INF = 1e6;

using namespace std;

#define MOD 998244353 

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    
//    freopen("out.txt", "w", stdout);

    int N, K; cin >> N >> K;

    int v[N+5], L[K], R[K];
    int prefix[N+5];
    fill(v, v + N + 5, 0);
    fill(prefix, prefix + N + 5, 0);
    v[N] = 1;
    prefix[N] = 1;

    for(int i = 0; i < K; i++) cin >> L[i] >> R[i]; 

    for(int j = N-1; j >= 1; j--){
        for(int k = 0; k < K; k++){
            int right = min(N+1, j + R[k]), left = min(N+1, j + L[k]); 
            v[j] = (v[j] + (prefix[left]-prefix[right+1]+MOD)%MOD)%MOD;
        } 
        prefix[j] = (prefix[j+1] + v[j])%MOD;
    }

    cout << v[1];

    return 0;

}


Measured memory_bytes: 5160
#include "bits/stdc++.h"

#define rep(i, a) for (int i = 0; i < (int)a; ++i)
#define REP(i, a, b) for (int i = (a); i < (int)b; ++i)

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

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

void Main() {
  int n;
	cin >> n;
  ll a;
  vector<P> ord;
	for (int i = 0; i < n; i++) {
		cin >> a;
    ord.emplace_back(a, i);
	}

  vector<ll> dp(n+1, 0);
	sort(ord.begin(), ord.end());
  rep(i, n) {
    rep(l, n - i + 1) {
			int r = l + i;
			const auto &[a, pos] = ord[i];
			dp[l] = max(dp[l] + a * abs(pos - r), dp[l + 1] + a * abs(pos - l));
		}
	}

  cout << dp[0] << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define MOD 1e9+7;
using namespace std;
using Graph = vector<vector<int>>;
typedef vector<vector<char>> field_t;
typedef  unsigned long long int ull;
typedef pair<int, int> point_t;
typedef long long ll;
ll chr[100001];



signed main()
{
    char a;
    cin >> a;
    if (isupper(a))
   {
       cout << "A" << endl;
   }
   else
   {
       cout << "a" << endl;
   }

    return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;

vector<pair<ll,ll>> prime_factorize(ll N){
	vector<pair<ll,ll>> res;
	for(ll a = 2; a * a <= N; a++){
		if(N % a != 0) continue;
		ll ex = 0;
		while( N % a == 0){
			ex++;
			N /= a;
		}
		res.push_back(make_pair(a,ex));
	}
	if( N != 1) res.push_back(make_pair(N,1));
	return res;
}


int main()
{
	ll N;
	cin>>N;
	const int MOD = 1000000007;
	vector<ll> ex(N+1,0);
	for(ll n = 2; n <= N; n++){
		auto res = prime_factorize(n);
		for(auto iter = res.begin(); iter != res.end(); iter++){
			ex[iter->first] += iter->second;
		}
	}
	ll ans = 1;
	for(int p = 2; p <= N; p++){
		ans *= ex[p] + 1;
		ans %= MOD;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3164
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{

    public static void Main()
    {
        int N = intRead();
        string ans = "Christmas";
        for (int i = 0; i < 25 - N; i++) ans += " Eve";
        Console.WriteLine(ans);
    }
}


public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static long LCM(long a, long b)
    {
        long c = a * b;
        if (a < b) Swap(ref a, ref b);
        long d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string strReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int intRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
    public static int[] SpIntRead(char c)
    {
        return Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
    }
    public static string ToConvertBit(int N, int e)
    {
        string ret = "";
        int r = 0;
        while (N != 0)
        {
            r = N % e;
            ret += r.ToString();
            N -= r;
            N /= e;
        }
        ret = strReverce(ret);
        return ret;
    }

}


Measured memory_bytes: 11092
N = int(input())
L = list(map(int,input().split()))
L.sort()
M = 0
ans = float('inf')
for i in range(L[0],L[N-1]+1):
  for j in range(N):
    M += (L[j]-i)**2
  if M <= ans:
    ans = M
    M = 0
  else:
    M = 0
print(ans)

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

mod=10**9+7
MAX=2*10**6+100

g1=[1,1]
g2=[1,1]
for i in range(2,MAX+1):
    num_1=g1[-1]*i%mod
    g1.append(num_1)
    g2.append(pow(num_1,mod-2,mod))
    
def cmb(n,r):
    return g1[n]*g2[r]*g2[n-r]%mod

def g(x,y):
    return cmb(x+y+2,y+1)-1

r1,c1,r2,c2=map(int,input().split())

num=(g(r2,c2)-g(r2,c1-1)-g(r1-1,c2)+g(r1-1,c1-1))%mod
print(num)

Measured memory_bytes: 125608
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        long mod = (long)Math.pow(10,9)+7;
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long ans = 1;
        HashMap<Long,Integer> map = new HashMap<Long,Integer>();
        for(long i = 2; i <= n; i++){
            map = factorization(map,i);
        }
        for(Map.Entry<Long,Integer> e : map.entrySet()){
            if(e.getKey() == 1){
                continue;
            }
            ans *= (e.getValue()+1);
            ans %= mod;
        }
        System.out.println(ans);
    }
    
    static HashMap<Long,Integer> factorization(HashMap<Long,Integer> ret, long x) {
        int div2 = 0;
        while (x % 2 == 0) {
            x /= 2;
            div2++;
        }
        if(div2 != 0){
            if(ret.containsKey(2L)){
                ret.put(2L, ret.get(2L)+div2);
            }else{
                ret.put(2L, div2);
            }
            
        }
        long d = 3;
        while (x/d >= d) {
            int cnt = 0;
            while (x % d == 0) {
                cnt++;
                x /= d;
            }
            if(cnt != 0){
                if(ret.containsKey(d)){
                    ret.put(d, ret.get(d)+cnt);
                }else{
                    ret.put(d, cnt);
                }   
            }
            d += 2;
        }
        if(ret.containsKey(x)){
            ret.put(x, ret.get(x)+1);
        }else{
            ret.put(x, 1);
        }
        return ret;
    }
}



Measured memory_bytes: 21716
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll N;
    cin >> N;

    ll a[N + 1];
    REP(i, N){
        cin >> a[i];
    }

    ll lighted[N + 1];
    REP(i, N){
        if(i == 1){
            lighted[i] = 1;
        }else{
            lighted[i] = 0;
        }
    }

    ll p = a[1];
    ll ans = 1;
    bool success = false;
    while(lighted[p] != 1){
        if(p == 2){
            success = true;
            break;
        }
        lighted[p] = 1;
        p = a[p];
        ans++;
    }

    if(success){
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define sz(x) static_cast<int>((x).size())

using LL = long long;
template<class T, size_t D>
struct vec : vector<vec<T, D - 1>> {
  template<class... Args>
  vec(size_t n = 0, Args... args)
    : vector<vec<T, D - 1>>(n, vec<T, D - 1>(args...)) {}
};
template<class T>
struct vec<T, 1> : vector<T> {
  template<class... Args>
  vec(Args... args)
    : vector<T>(args...) {}
};

template<class T>
inline bool asMn(T& a, const T& b) { return a > b ? a = b, true : false; }
template<class T>
inline bool asMx(T& a, const T& b) { return a < b ? a = b, true : false; }
inline int nex(int i, int n) { return i == n - 1 ? 0 : i + 1; }
inline int pre(int i, int n) { return !i ? n - 1 : i - 1; }

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

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

  int n, k; cin >> n >> k;
  vec<int, 1> a(n);
  for (auto& i : a) {
    cin >> i;
  }

  while (k--) {
    vec<int, 1> b(n);
    for (int i = 0; i < n; ++i) {
      ++b[max(i - a[i], 0)];
      if (i + a[i] + 1 < n) {
        --b[i + a[i] + 1];
      }
    }
    for (int i = 1; i < n; ++i) {
      b[i] += b[i - 1];
    }

    if (a == b) {
      break ;
    } else {
      a = b;
    }
  }

  for (auto& i : a) {
    cout << i << ' ';
  }
  cout << '\n';

  return 0;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    sort(a.begin(), a.end());

    cout << a.back() - a[0] << endl;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
A = list(map(int, input().split()))
B = [max(0, a) for a in A]

from itertools import accumulate
A = [0]+A
A = list(accumulate(A))
B = [0]+B
B = list(accumulate(B))

#print(A)
#print(B)

ans = -10**18
for i in range(n-k+1):
    temp = max(0, A[i+k]-A[i])
    temp += B[i]-B[0]
    temp += B[-1]-B[i+k]
    #print(i,  A[i+k]-A[i], B[i]-B[0], B[-1]-B[i+k])
    ans = max(ans, temp)
print(ans)


Measured memory_bytes: 17324
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;

ll a[100001], n, l[100001], r[100001], ans;

int main() {
  cin >> n;
  for (int i = 0; i <= n; i++) {
    cin >> a[i];
  }
  if (a[0] > 1) {
    cout << -1 << endl;
    return 0;
  }
  l[n] = r[n] = a[n];
  for (int i = n - 1; i >= 0; i--) {
    l[i] = a[i] + (l[i + 1] + 1) / 2;
    r[i] = a[i] + r[i + 1];
  }
  l[0] = r[0] = 1;
  for (int i = 0; i < n; i++) {
    ans += r[i];
    if (l[i] - a[i] > r[i + 1] || (r[i] - a[i]) * 2 < l[i + 1]) {
      cout << -1 << endl;
      return 0;
    }
    l[i + 1] = max(l[i + 1], l[i] - a[i]);
    r[i + 1] = min(r[i + 1], (r[i] - a[i]) * 2);
  }
  cout << ans + a[n] << endl;
}

Measured memory_bytes: 5976
#include <stdio.h>
int main(void)
{
    int H,W,a,b;
    
    while(1){
        scanf("%d %d",&H ,&W);
        if( H == 0 && W == 0) break;
        
        for ( a = 0; a < H;  a++ ){
             for ( b = 0; b < W; b++ ){
             if(( a%2 == 0 && b%2 == 0) || (a%2 == 1 && b%2 == 1)){    
                 
            printf("#");
        }
        else { 
            printf(".");
        }
        }
        printf("\n");
        }
    
       printf("\n");
    }                
  return 0;
}
                    


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
 
long long getAnswer(vector< int >& cycle, int* c, int k){
    int lengthOfCycle = cycle.size();
    long long totalSum = 0;
    for(int u : cycle){
        totalSum += c[u];
    }
    int roundTrips = k / lengthOfCycle;
    int remaining = k % lengthOfCycle;
    long long answer = LLONG_MIN;
    if(roundTrips > 1){
        if(totalSum >= 0){
            remaining += lengthOfCycle;
            long long tmp = totalSum * (roundTrips - 1);
            for(int i = 0; i < lengthOfCycle; i++){
                int start = i;
                long long candidate = 0;
                for(int moves = 0; moves < remaining; moves++){
                    answer = max(answer, tmp + candidate);
                    candidate += c[cycle[(start + 1) % lengthOfCycle]];
                    start++;
                }
                answer = max(answer, tmp + candidate);
            }
        }
        else{
            for(int i = 0; i < lengthOfCycle; i++){
                long long candidate = 0;
                int start = i;
                for(int moves = 0; moves < lengthOfCycle; moves++){
                    candidate += c[cycle[(start + 1) % lengthOfCycle]];
                    answer = max(answer, candidate);
                    start++;
                }
            }
        }
    }
    else{
        for(int i = 0; i < lengthOfCycle; i++){
            long long candidate = 0;
            int start = i;
            for(int moves = 0; moves < k; moves++){
                candidate += c[cycle[(start + 1) % lengthOfCycle]];
                answer = max(answer, candidate);
                start++;
            }
        }
    }
    return answer;
 
}
 
int main(){
    int n, k; cin >> n >> k;
    int p[n];
    int *c = new int[n];
    for(int& u : p){
        cin >> u;
        --u;
    }
    for(int i = 0; i < n; i++){
        cin >> c[i];
    }
    bool vis[n]; memset(vis, false, sizeof(vis));
    long long answer = LLONG_MIN;
    for(int i = 0; i < n; i++){
        if(!vis[i]){
            vector< int > cycle;
            while(!vis[i]){
                vis[i] = true;
                cycle.push_back(i);
                i = p[i];
            }
            long long candidate = getAnswer(cycle, c, k);
            answer = max(answer, candidate);
        }
    }
    cout << answer << '\n';
    return 0;
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*b);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}



template <typename T>
class Seg_Tree{
public: // 0-index
	vector<T> dat;
	T initial,M;
	int n;
	T unite(T a,T b){//
		return max(a , b);
	}
	Seg_Tree(int n0_=1,T initial_=1,T M_=1){
		initsize(n0_,initial_,M_);
	}
	void initsize(int n0,T initial_,T M_){
		M = M_;
		initial = initial_;
		int k=1;
		while(1){
			if(n0<=k){
				n=k;
				dat.resize(2*n-1);
				for(int i=0;i<2*n-1;i++)dat[i]=initial;
				break;
			}
			k*=2;
		}
	}
 
	//i banme wo x nisuru
	void update(int i,T x){
		i += n-1;
		dat[i] = x;
		while(i>0){
			i = (i-1) / 2;
			dat[i] = unite(dat[i*2+1],dat[i*2+2]);
		}
	}
 
	//[a,b)
	T query0(int a,int b,int k,int l,int r){
		if(r<=a || b<=l)return initial;
		if(a<=l && r<=b)return dat[k];
		else{
			T vl = query0(a,b,k*2+1,l,(l+r)/2);
			T vr = query0(a,b,k*2+2,(l+r)/2,r);
			return unite(vl,vr);
		}
	}
 
	//return [a,b)
	T query(int a,int b){
		return query0(a,b,0,0,n);
	}
};

int main(){

	ll N,K;
	cin >> N >> K;

	Seg_Tree<ll> sg(3000089,0,9);
	FOR(i,0,N){
		ll a;
		cin >> a;
		ll x = sg.query(a-K,a+K+1)+1;
		sg.update(a,x);
	}
	cout << sg.query(0,3000080) << endl;
}


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

int main()
{
    string text, ans = "";
    cin >> text;
    for (char t : text)
    {
        if (t == '0')
        {
            ans += '0';
        }
        else if (t == '1')
        {
            ans += '1';
        }
        else if (t == 'B')
        {
            if (ans.size() == 0)
            {
                continue;
            }
            else
            {
                ans.erase(ans.size()-1);
            }
        }
    }
    cout << ans << endl;
}

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

int n,ans;
long long sum,num[200005],rox[200005];
int a[200005];

int main(void){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		num[i]=num[i-1]+(a[i]+0ll);
	}
	rox[1]=a[1]+0ll;
	for(int i=2;i<=n;i++) 
	rox[i]=rox[i-1]^(a[i]+0ll);
	for(int i=1;i<=n;i++){
		ans=0;
		int l=i,r=n,mid;
		while(l<=r){
			mid=(l+r)/2;
			long long xx,yy;
			xx=rox[mid]^rox[i-1];
			yy=num[mid]-num[i-1];
			if(xx==yy){
				ans=max(ans,mid);
				l=mid+1;
			}
			else r=mid-1;
		}
		sum+=ans-i+1;
	}
	printf("%lld",sum);
}
/*
4
2 5 4 6
*/

Measured memory_bytes: 4096
use std::io::Read;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let k: usize = iterator.next().unwrap().parse().unwrap();
    let x: Vec<isize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();

    const INF: isize = std::isize::MAX;
    let mut ans = INF;
    for i in 0..n {
        let j = i + k - 1;
        if j >= n {
            break;
        }
        let cost = (x[j] - x[i]).abs();
        ans = min(ans, x[i].abs() + cost);
        ans = min(ans, x[j].abs() + cost);
    }

    return ans.to_string();
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
#define PI 3.141592653589
#define ll long long
using namespace std;

int main(){
  ll a, b, k;
  cin >> a >> b >> k;

  if(a+b <= k){
    a = 0;
    b = 0;
  }

  else if(a+b > k){
    if(a-k >= 0) a -= k;
    else if(a - k < 0){
      b = b -k + a;
      a = 0;
    }
  }
  cout << a << " " << b;
 return 0;
}

Measured memory_bytes: 256