akhauriyash/Code-Regression huggingface dataset:
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int main() {
	stack<int> s1;
	stack<pair<int, int>>s2;
	string s;
	cin >> s;
	int sum = 0;
	REP(i, s.size()) {
		if (s[i] == '\\')s1.push(i);
		else if (s[i] == '/'&&s1.size()) {
			int j = s1.top();
			s1.pop();
			sum += (i - j);
			int a = (i - j);
			while (s2.size() && s2.top().first > j) {
				a += s2.top().second;
				s2.pop();
			}
			s2.push(mp(j, a));
		}
	}
	vector<int> v;
	while (s2.size()) {
		v.emplace_back(s2.top().second);
		s2.pop();
	}
	reverse(ALL(v));
	cout << sum << endl << v.size();
	REP(k, v.size()) {
		cout << " ";
		cout << v[k];
	}
	cout << endl;
}


Measured memory_bytes: 3300
#include "bits/stdc++.h"
#define esc(ret) cout << ret << endl,quick_exit(0)
#define fcout(d) cout << fixed << setprecision(d)
#define repU(i,s,t) for(int i = (int)(s); i <= (int)(t); ++i)
#define repD(i,t,s) for(int i = (int)(t); i >= (int)(s); --i)
#define rep(i,n) repU(i,0,n - 1)
#define rep1(i,n) repU(i,1,n)
#define all(v) begin(v),end(v)
#define vct vector
#define prique priority_queue
#define l_bnd lower_bound
#define u_bnd upper_bound
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second
#define qceil(n,d) ((n) > 0 ? ((n) - 1) / (d) + 1 : (n) / (d))
#define parity(a,b) (a & 1 == b & 1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;

const pii dir[] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int inf32 = (1 << 30) - 1;
const ll inf64 = (1LL << 62) - 1;
const int mod = 1e9 + 7;

template<class Abel> struct UnionFind {
	vector<int> par;
	vector<int> size;
	vector<int> rank;
	vector<Abel> diff_weight;

	UnionFind(int n) {
		init(n);
	}

	void init(int n) {
		par.resize(n);
		size.assign(n,1);
		rank.resize(n);
		diff_weight.resize(n);
		for (int i = 0; i < n; ++i) par[i] = i; 
	}

	int find(int x) {
		if (par[x] == x) {
			return x;
		} else { 
			int r = find(par[x]);
			size[x] = size[r];
			diff_weight[x] += diff_weight[par[x]];
			return par[x] = r;
		}
	}
	
	int scale(int x) {
		return size[find(x)];
	}

	Abel weight(int x) {
		find(x);
		return diff_weight[x];
	} 

	Abel diff(int x, int y) {
		return weight(y) - weight(x);
	} 

	bool is_same(int x, int y) {
		return find(x) == find(y);
	}

	bool unite(int x, int y, Abel w = 0) {
		w += weight(x);
		w -= weight(y);
		x = find(x);
		y = find(y);
		if (x == y) return false;
		if (rank[x] < rank[y]) {
			swap(x,y);
			w = -w;
		}
		if (rank[x] == rank[y]) ++rank[x];
		size[x] += size[y];
		par[y] = x;
		diff_weight[y] = w;
		return true;
	}
};
 
int N,M,a[100100];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> N >> M;
	if(M == N - 1) esc(0);
	if(N < 2 * (N - M - 1)) esc("Impossible");
	UnionFind<int> uf1(N);
	rep(i,N) cin >> a[i];
	rep(i,M){
		int x,y;
		cin >> x >> y;
		uf1.unite(x,y);
	}
	unordered_map<int,prique<int,vct<int>,greater<int>>> mp;
	prique<int,vct<int>,greater<int>> ls;
	rep(i,N){
		mp[uf1.find(i)].push(a[i]);
	}
	ll ans = 0;
	for(auto e : mp){
		ans += e.sec.top();
		e.sec.pop();
		while(!e.sec.empty()){
			ls.push(e.sec.top());
			e.sec.pop();
		}
	}
	rep(i,N - M - 2){
		ans += ls.top();
		ls.pop();
	}
	cout << ans << endl;
}



Measured memory_bytes: 8076
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
//Range Minimum Query

ll linf=-inf;
ll n;
vector<ll>RMQ(1<<21);
void init(ll n_){
    n=1;
    while(n<n_){
        n*=2;
    }
    rep(i,n*2-1){
        RMQ[i]=linf;
    }
}
void update(ll k,ll a){
    k+=n-1;
    RMQ[k]=a;
    while(k>0){
        k--;
        k/=2;
        RMQ[k]=max(RMQ[2*k+1],RMQ[2*k+2]);
    }
}
//半開区間
ll query(ll a,ll b,ll k,ll l,ll r){
    if(r<=a||l>=b)return linf;
    if(l>=a&&r<=b)return RMQ[k];
    else {
        return max(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
    }
}
signed main(){
    ll n_;cin>>n_;
    vector<pll>a(n_);
    init(n_+1);
    rep(i,n_){
        ll x,d;cin>>x>>d;
        a[i]=mp(x,d);
    }
    sort(all(a));
    a.pb(mp(inf*2,inf*2));
    vector<ll>dp(n_+1);
    dp[0]=1;
    vector<ll>b(n_);
    for(int i=n_-1;i>=0;i--){
        update(i,a[i].first+a[i].second);
        ll q=lower_bound(all(a),mp(a[i].first+a[i].second,-1LL))-a.begin();
        ll s=query(i,q,0,0,n+1);
        update(i,s);
        b[i]=s;
    }
    rep(i,n_){
        dp[i+1]=(dp[i+1]+dp[i])%mod;
        ll p=lower_bound(all(a),mp(b[i],-1LL))-a.begin();
        dp[p]=(dp[p]+dp[i])%mod;
    }
    cout<<dp[n_]<<endl;
}

Measured memory_bytes: 25960
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;
ll mypow(ll x, ll n, ll m) {
	if (n == 0) {
		return 1;
	}
	if (n % 2 == 0) {
		return mypow(x*x%m, n / 2, m);
	}
	else {
		return x * mypow(x, n - 1, m) % m;
	}
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
///////////////////////////////////////

ll dp[200010][4];
//dp[i][j];i個目までみてj個余分なxを入れたときのmax
const ll mod =1e18;
int main() {
	int N; cin >> N;
	vector <ll> a(N);
	REP(i, N) {
		cin >> a[i];
	}
	REP(i, N + 1) {
		REP(j, 4) {
			dp[i][j] = -mod;
		}
	}
	int k = 1 + (N % 2);
	dp[0][0] = 0;
	REP(i, N) {
		REP(j,k+1) {
			dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j]);
			ll now = dp[i][j];
			if ((i + j) % 2 == 0)now += a[i];
			dp[i + 1][j] = max(dp[i + 1][j], now);
		}
	}
	ll ans = -mod;
	if (N % 2 == 0) {
		REP(i, k + 1) {
			ans = max(ans, dp[N][i]);
		}
	}
	else {
		for (int i = 1; i < k + 1; ++i) {
			ans = max(ans, dp[N][i]);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 11180
#!/usr/bin/env python3
import sys
import math
import bisect

def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 # 1は素数ではない

    # エラトステネスのふるい
    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return set(prime for prime in primes if prime != 0)


def is_prime(prime_list,a):
    return a in prime_list

def solve(Q: int, L: "List[int]", R: "List[int]"):
    prime_list = primes(10**5)

    DP = [0] * (10**5)
    for i in range(1,int(10**5)):
        DP[i] = DP[i-1]
        if is_prime(prime_list,i) and is_prime(prime_list,(i+1)//2):
            DP[i] += 1

    for l,r in zip(L,R):
        print(DP[r] - DP[l-1])

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    Q = int(next(tokens))  # type: int
    l = [int()] * (Q)  # type: "List[int]" 
    r = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(Q, l, r)

if __name__ == '__main__':
    main()


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

int main() {
  int n,k; cin >> n;
  ll ans = 0;
  for(int i=1; i<n; i++){
    int a = n-i;
    k = 1;
    for (int i = 2; i <= sqrt(a); i++) {
      int cnt = 0;
      while (a % i == 0) {
        cnt++;
        a /= i;
      }
      k *= (cnt + 1);
      if (a == 1) break;
    }
    if (a != 1) k *= 2;
    ans += k;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3680
n = int(input())

x = n 
nums = []
ans = ''
for i in range(1, 12):
    if 26**i >= n:
        for _ in range(i):
            x -= 1
            l = x % 26
            x //=  26
            nums.append(l)
        break
    else:
        n -= 26**i
        
for _ in nums:
    ans +=(chr(ord('a') + _))
    
print(ans[::-1]) 

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

int main() {
  long long N, ans = 0;
  cin >> N;
  for (int p = 1; N / p - 1 > p; p++) {
    if (N % p == 0) ans += N / p - 1;
  }
  cout << ans << endl;
}

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

using namespace std;

#define int long long

map<char, int> num;
char mcxi[4] = { 'm', 'c', 'x', 'i' };

int ConvertMCXIToNum(string s)
{
	int n = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (isalpha(s[i]))
		{
			int p = 1;
			if (i > 0 && isdigit(s[i - 1])) p = s[i - 1] - '0';
			n += p * num[s[i]];
		}
	}
	return n;
}

string ConvertNumToMCXI(int n)
{
	string s;
	for (int i = 0, w = 1000; w > 0; i++, w /= 10)
	{
		int latte = n / w;
		n %= w;
		if (latte > 1) s += '0' + latte;
		if (latte > 0) s += mcxi[i];
	}
	return s;
}

signed main()
{
	num['m'] = (num['c'] = (num['x'] = (num['i'] = 1) * 10) * 10) * 10;
	int N;
	cin >> N;
	for (int t = 0; t < N; t++)
	{
		string a, b;
		cin >> a >> b;
		cout << ConvertNumToMCXI(ConvertMCXIToNum(a) + ConvertMCXIToNum(b)) << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define dcout cout<<fixed<<setprecision(20)
#define Accepted_MAGIC cin.tie(0);ios::sync_with_stdio(false)

// typedef long long ll;
using Real = long double;
#define int long long

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;
constexpr Real eps = 1e-9, pi = acos(-1);

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

signed main(void){
  Accepted_MAGIC;
  
  string S; cin >> S;
  int N = S.size();
  bool yes = 1;
  REP(i, N){
    yes &= (S[i] == S[N-1-i]);
  }
  REP(i, (N-1)/2){
    yes &= (S[i] == S[(N-1)/2 - 1 - i]);
  }
  RANGE(i, (N+3)/2-1, N){
    yes &= (S[i] == S[(N+3)/2+N-2 - i]);
  }
  if(yes) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <unordered_map>
#include <cmath>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
    for (T &x : vec)
        is >> x;
    return is;
}

ll gcd(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    while (m != n)
    {
        if (m > n)
            m = m - n;
        else
            n = n - m;
    }
    return m;
}

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

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

    bool from[200001]={}, to[200001]={};
    REP(i,m){
        int a,b;
        cin >> a >> b;
        if(a==1) from[b]=true;
        if(b==n) to[a]=true;
    }

    REP(i,m+1){
        if(from[i]&&to[i]){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 640
#if 0
#cflags(-std=c++14 -Wall)
#endif
#include<iostream>
template<typename T>
T input(std::istream& os = std::cin){T t;os >> t;return t;}
 
#include<vector>
#include<string>
#include<queue>
#include<numeric>
 
struct pos{
  int x, y;
  template<typename T>
  auto&& operator[](T&& t)const{return std::forward<T>(t)[y][x];}
};
template<typename F>
struct itr{
  int r;
  std::pair<pos, int> t;
  F shortest;
  bool flag;
  itr& operator++(){++r;flag = true;return *this;}
  int& operator*(){if(flag)t = shortest(r, t.first.x, t.first.y), flag = false;return t.second;}
  bool operator==(const itr& other)const{return r == other.r;}
  bool operator!=(const itr& other)const{return !(*this == other);}
};
template<typename F>
itr<F> make_itr(const pos& p, F&& f){return ++itr<F>{0, {p, 0}, f};}
template<typename F>
itr<F> make_itr(int r, F&& f){return itr<F>{r, {}, f};}
 
int main(){
  const auto H = input<int>();
  const auto W = input<int>();
  const auto N = input<int>();
  const std::vector<std::string> data = [H]{
    std::vector<std::string> data;
    data.reserve(H);
    for(int i = 0; i < H; ++i)
      data.emplace_back(input<std::string>());
    return data;
  }();
  const pos po = [&]{
    pos po;
    for(int j = 0; j < H; ++j)
      for(int i = 0; i < W; ++i)
        if(data[j][i] == 'S')
          po = {i, j};
    return po;
  }();
  auto shortest = [&](int rank, int i, int j){
    std::vector<std::vector<char>> flags(H, std::vector<char>(W));
    std::queue<std::pair<pos, int>> q;
    auto add = [&](const pos& po, int t){
      if(!po[flags])
        if(po[data] != 'X')
          q.push({po, t+1});
       po[flags] = true;
    };
    add({i, j}, -1);
    while(true){
      const auto& d = q.front();
      const auto& p = d.first;
      if(p[data] == rank+'0')
        return q.front();
      for(int a = -1; a <= 1; a += 2)
        if(0 <= p.x + a && p.x + a < W)
          add(pos{p.x+a, p.y}, d.second);
      for(int b = -1; b <= 1; b += 2)
        if(0 <= p.y + b && p.y + b < H)
          add(pos{p.x, p.y+b}, d.second);
      q.pop();
    }
    return q.front();
  };
  std::cout << std::accumulate(make_itr(po, shortest), make_itr(N+1, shortest), 0) << std::endl;
}

Measured memory_bytes: 4816
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	N := sc.nextInt()
	A := sc.nextIntSlice(N + 1)
	B := sc.nextIntSlice(N)
	count := 0
	before := 0
	for i := 0; i < N+1; i++ {
		count += min(A[i], before)
		if A[i] > before {
			A[i] -= before
		} else {
			A[i] = 0
		}
		if i == N {
			break
		}
		count += min(A[i], B[i])
		if A[i] > B[i] {
			A[i] -= B[i]
			B[i] = 0
		} else {
			B[i] -= A[i]
			A[i] = 0
		}
		before = B[i]
	}
	fmt.Println(count)
}


Measured memory_bytes: 4736
n = int(input())
M = 0
ans = 0
for i in range(n):
    a = int(input())
    if M == 0:
        ans += a-1
        M = 1
    elif a <= M+1:
        M = max(M,a)
    else:
        ans += (a-1)//(M+1)
print(ans)


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

int main(){
  int a;
  scanf("%d",&a);
  int b[a];
  for(int i=0;i<a;i++){
    scanf("%d",&b[i]);
  }
  int max = b[0];
  int min = b[0];
  for(int i=1; i<a; i++){
    if(max<b[i]) max=b[i];
    if(min>b[i]) min=b[i];
  }
  
  printf("%d",abs(max-min));
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
struct fastio { fastio () { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } _io;
template<class T, class U> bool chmax(T& a, const U &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> bool chmin(T& a, const U &b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	int x;
	std::cin >> x;
	int ans;
	if (x < 600) ans = 8;
	else if (x < 800) ans = 7;
	else if (x < 1000) ans = 6;
	else if (x < 1200) ans = 5;
	else if (x < 1400) ans = 4;
	else if (x < 1600) ans = 3;
	else if (x < 1800) ans= 2;
	else if (x < 2000) ans = 1;
	std::cout << ans << '\n';
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		while (n-- > 0) {
			long s = Long.parseLong(scanner.next(), 16);
			int x = (int) (s & 0x7fffff80) >> 7;
			double y = (double) ((s & 0x7f) *0.0078125);
			String a = String.valueOf(y).substring(2);
			if (s >> 31 > 0)
				System.out.print("-");
			System.out.printf("%d.%s\n", x, a);
		}
	}
}

Measured memory_bytes: 49916
#include <stdio.h>
int main(void){
    // Your code here!
    int i,j,a,b;
    while(1){
        scanf("%d %d",&a,&b);
        if(a==0&&b==0) break;
        for(i = 0; i < b;i++) printf("#"); printf("\n");
        for(i = 0; i < a-2;i++){
            printf("#");
            for(j = 0 ; j < b-2;j++) printf(".");
            printf("#");printf("\n");
        }
        for(i = 0; i < b;i++) printf("#"); 
        printf("\n\n");
    }
    
    return 0;
}

Measured memory_bytes: 1756
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;

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

int main()
{
    int n,m;
    cin >> n>>m;
    if (n<=m) {
        cout << "unsafe" << endl;
    }else {
        cout << "safe" << endl;
    }
}


Measured memory_bytes: 3624
#include<stdio.h>
#include<stdbool.h>

int main(int argc, char *argv[]){
  int h, w;
  scanf("%d %d", &h, &w);
  //printf("h=%d, w=%d\n", h, w);

  char s[h][w];
  for(int i=0; i<h; i++){
    scanf("%s", s[i]);
  }

  /*
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      printf("%c", s[i][j]);
    }
    printf("\n");
  }
  */

  bool ok = true;
  char mark = '#';
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if(s[i][j] == '#'){
        // top left
        //if(i>0     && j>0     && s[i-1][j-1] == mark){}

        // top center
        if(i>0                && s[i-1][j]   == mark) continue;

        // top right
        //if(i>0     && j<(w-1) && s[i-1][j+1] == mark){}

        // middle left
        if(           j>0     && s[i][j-1]   == mark) continue;

        // middle center

        // middle right
        if(           j<(w-1) && s[i][j+1]   == mark) continue;

        // bottom left
        //if(i<(h-1) && j>0     && s[i+1][j-1] == mark){}

        // bottom center
        if(i<(h-1)            && s[i+1][j]   == mark) continue;

        // bottom right
        //if(i<(h-1) && j<(w-1) && s[i+1][j+1] == mark){}

        ok = false;
        break;
      }
      if(!ok) break;
    }
  }

  if(ok){
    printf("Yes\n");
  }else{
    printf("No\n");
  }


  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
char out[100][101];
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};
int main(){
	int a;
	scanf("%d",&a);
	while(a--){
		int b;
		scanf("%d",&b);
		for(int i=0;i<b;i++){
			for(int j=0;j<b;j++){
				out[i][j]=' ';
			}
			out[i][b]=0;
		}
		if(b==1){
			printf("#\n");
			if(a)printf("\n");
			continue;
		}
		if(b==2){
			printf("##\n# \n");
			if(a)printf("\n");
			continue;
		}
		int row=b-1;
		int col=0;
		int dir=0;
		int len=1;
		out[row][col]='#';
		while(1){
			int nrow=row+dy[dir%4];
			int ncol=col+dx[dir%4];
			if((dir%4==0&&nrow==0)||(dir%4==3&&ncol==0)||(dir%4==2&&nrow==b-1)||(dir%4==1&&ncol==b-1)){
				row=nrow;
				col=ncol;
				out[row][col]='#';
				dir++;
				len=1;
			}else if(out[nrow+dy[dir%4]][ncol+dx[dir%4]]=='#'){
				if(len<3)break;
				dir++;
				len=1;
			}else{
				row=nrow;
				col=ncol;
				out[row][col]='#';
				len++;
			}
		}
		for(int i=0;i<b;i++)printf("%s\n",out[i]);
		if(a)printf("\n");
	}
}

Measured memory_bytes: 0
#include <iostream>
#define int long long
using namespace std;

signed main() {
	int a, b, c;
	cin >> a >> b >> c;
	
	int res = c - a - b;
	if (res < 0) { cout << "No" << endl; }
	else if (4 * a * b < res * res) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
	return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (3e9)

using namespace std;
typedef long long int ll;

long double a, b, c;
int main(void){
    cin >> a >> b>> c;
    if(c > a + b + 2*sqrt(a*b)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
H,N = map(int,input().split())
A = []
B = []
for i in range(N):
    a,b =map(int,input().split())
    A.append(a)
    B.append(b)

G = [0]*(H+1)

for i in range(1,N+1):
    for j in range(1,H+1):
        if i == 1:
            if j-A[i-1]<0:
                G[j] = B[i-1]
            else:
                G[j] = G[j-A[i-1]]+B[i-1]
        elif j-A[i-1]<0:
            G[j] = min(G[j], B[i-1])
        else:
            G[j] = min(G[j], G[j-A[i-1]]+B[i-1])
        
print(G[H])

Measured memory_bytes: 42736
#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;
inline char nc(){ static char buf[100000] , *p1,*p2; return p1 == p2 && (p2 = (p1 = buf) + fread(buf,1,100000,stdin),p1 == p2 ) ? EOF : *p1++;}
template<class T>inline void rd(T & x){ x = 0;char ch = nc(); for(;!isdigit(ch);ch = nc()); for(;isdigit(ch);ch = nc()) x = x * 10 - 48 + ch;}
#define debug(...) fprintf(stderr,__VA_ARGS__)
typedef long long ll;
const int maxn = 100 + 10;
int a[maxn];
int main(){
	int n,m;
	rd(n); rd(m);
	for(int i = 1;i <= n;i++){
		rd(a[i]);
	}
	sort(a + 1,a + n + 1);
	ll sum = 0;
	int ans = 0;
	for(int i = 1;i <= n;i++){
		sum += a[i];
		if(sum <= m) ans = i;
	}
	if(sum < m) ans--;
	printf("%d\n",ans);
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

ll Manacher(const string &_s){
    ll n=_s.length(),i,j;
    string s(2*n+1,'#');
    for(i=0;i<n;i++) s[2*i+1]=_s[i];
    n=2*n+1;
 
    vector<ll> rad(n);
    for(i=j=0;i<n;){
        while(0<=i-j && i+j<n && s[i-j]==s[i+j]) j++;
        rad[i]=j;
 
        ll k;
        for(k=1;i-k>=0 && rad[i-k]<rad[i]-k;k++) rad[i+k]=rad[i-k];
 
        i+=k;
        j=max(j-k,0ll);
    }
	ll ans = 0;
	for(int i=0; i<rad.size(); i++){
		cout << rad[i] - 1 << endl;
		//cout << ((rad[i]-1)+1)/2 << endl;
		//cout << ((rad[i]-2)+1)/2 << endl;
		ans += ((rad[i]-1)+1)/2;
	}
	/*
	for(int i=1; i<rad.size(); i+=2){
		cout << (rad[i] - 2) / 2 << endl;
		ans += (rad[i] - 2) / 2;
	}
	*/
	return ans;
    //return *max_element(rad.begin(),rad.end())-1;
}

ll used[26];
int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	string s;
	cin >> s;
	ll n = s.size();

	for(int i=0; i<s.size(); i++){
		used[s[i] - 'a']++;
	}

	ll ans = n*(n-1)/2;
	for(int i=0; i<26; i++){
		ans -= (used[i]*(used[i]-1))/2;
	}
	cout << ans + 1 << endl;
	/*
	cout << n*(n+1)/2 + 1 - Manacher(s) << endl;
	*/
	
	return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections;

class Program
{
    static void Main(string[] args)
    {
        string x = Console.ReadLine();
        Stack s = new Stack();
        foreach (char c in x)
        {
            if (c == 'S') s.Push(c);
            else if (s.Count > 0 && s.Peek().ToString().Equals("S"))
            {
                s.Pop();
            }
            else s.Push(c);
        }
        Console.WriteLine(s.Count);
    }
}

Measured memory_bytes: 13784
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define mp(a, b) make_pair(a, b)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
ll dp[100010];
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}
map<ll, ll> factor(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a){
    if (n % a == 0){
      ans[a]++;
      n /= a;
    }
    else a++;
  }
  ans[n]++;
  return ans;
}
template<class T> inline bool chmin(T& a, T b){
  if (a > b){
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b){
  if (a < b){
    a = b;
    return true;
  }
  return false;
}

int main(){
  cout << fixed << setprecision(15);
  int n, d; cin >> n >> d;
  vector<pii> s(n);
  rep(i, n){
    int x, y; cin >> x >> y;
    s[i] = mp(x, y);
  }

  ll ans = 0;
  sort(all(s));
  while (d > 0){
    rep(i, n){
      ans += (ll)s[i].first * min(d, s[i].second);
      d -= min(d, s[i].second);
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(){
  int H, W, N;
  cin >> H >> W >> N;
  int A[N];
  for(int i = 0; i < N; ++i) cin >> A[i];
  int ans[H][W], h = 0, w = 0;
  for(int i = 0; i < N; ++i){
    int a = A[i];
    while(a){
      --a;
      ans[h][w] = i+1;
      if(h%2){
	--w;
	if(w < 0){
	  w = 0;
	  ++h;
	}
      }else{
	++w;
	if(w == W){
	  --w;
	  ++h;
	}
      }
    }
  }
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      cout << ans[i][j];
      if(j < W-1) cout << " ";
      else cout << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 2e5 + 5 ;
const ll mod = 1e9 + 7 ;
ll fac[maxn] , inv[maxn] ;
ll qpow(ll a , ll b)
{
   ll ans = 1 ; 
   a %= mod ;
   while(b)
   {
     if(b & 1)  ans = (ans * a) % mod ;
     b >>= 1 , a = (a * a) % mod ;
   }
   return ans % mod ;
}
void init() 
{
   fac[0] = fac[1] = inv[0] = inv[1] = 1 ;
   for(int i = 2 ; i <= 2e5 ; i ++)
   {
     fac[i] = fac[i - 1] * i % mod ;
     inv[i] = -inv[mod % i] * (mod / i) % mod ;
     while(inv[i] < 0) inv[i] += mod ;
   }
   for(int i = 2 ; i <= 2e5 ; i ++)  
   inv[i] = inv[i] * inv[i - 1] % mod ;
}
ll C(ll n , ll m)
{
	return fac[n] * inv[n - m] % mod * inv[m] % mod ;
}
ll solve(ll n , ll m)
{
   return C(n + m - 1 , m - 1) ;
}
int main()
{
	ll n , k ;
	ll ans = 1 ;
	init() ;
	scanf("%lld%lld" , &n , &k) ;
	k = min(k , n) ;
	for(int i = 1 ; i <= n - 1 ; i ++)
	{
		if(i > k)  break ;
		//cout << i << ' ' << C(n , i) * solve(i , n - i) << '\n' ;
		ans += C(n , i) * solve(i , n - i) ;
		ans %= mod ;
	}
	printf("%lld\n" , ans) ;
    return 0 ;
}

Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String length = s.next();
        String targetNum = s.next();
        String stringValue = s.next();
        int a = Integer.parseInt(targetNum) - 1;
        char[] carVals = stringValue.toCharArray();
        carVals[a] =
                Character.toLowerCase(carVals[a]);
        System.out.println(String.valueOf(carVals));
    }
}


Measured memory_bytes: 21588
#include<stdio.h>
int dp[8][64];
int a[10];
int b[10];
int p[7];
int main(){
    int n,m,c=0,t=0;
    int i,j,k;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        char x;
        scanf(" %c",&x);
        if(x=='*'){
            p[c]=i;
            c++;
        }
        else{
            int y=x-'0';
            if((n-i)%2==0){
                y*=2;
                if(y>=10)y=1+y%10;
            }
            t+=y;
        }
    }
    t%=10;
    scanf("%d",&m);
    for(i=0;i<m;i++){
        int x;
        scanf("%d",&x);
        a[i]=x;
        x*=2;
        if(x>=10)b[i]=1+x%10;
        else b[i]=x;
    }
    for(i=0;i<8;i++)for(j=0;j<64;j++)dp[i][j]=0;
    dp[0][0]=1;
    for(i=1;i<=c;i++){
        for(j=0;j<64;j++){
            for(k=0;k<m;k++){
                if((n-p[i-1])%2==0){
                    if(j+b[k]<64)dp[i][j+b[k]]+=dp[i-1][j];
                }else{
                    if(j+a[k]<64)dp[i][j+a[k]]+=dp[i-1][j];
                }
            }
        }
    }
    int ans=0;
    for(i=0;i<64;i++){
        if((t+i)%10==0)ans+=dp[c][i];
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <tuple>
#include <stdlib.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int>A(N);
	int saigo = N - 1;
	for (int i = 0; i < N; i++)cin >> A[i];
	sort(A.begin(), A.end());
	for (int i = 0; i < M; i++)
	{
		int tmp = A[saigo];
		A.pop_back();
		A.insert(lower_bound(ALL(A), int(tmp/2)), tmp / 2);
	}
	long long int ans = 0;
	for (int i = 0; i < N; i++)
	{
		ans += A[i];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
	int n,i;
	float s[40];
	int nz1=0,nz2=0,nz3=0,nz4=0,nz5=0,nz6=0;
	while(scanf("%d",&n)!=EOF){
		for(i=0;i<n;i++){
			scanf("%f",&s[i]);
			if(s[i]<165.0){
				nz1+=1;
			}
			else if(s[i]>=165.0 && s[i]<170.0){
				nz2+=1;
			}
			else if(s[i]>=170.0 && s[i]<175.0){
				nz3+=1;
			}
			else if(s[i]>=175.0 && s[i]<180.0){
				nz4+=1;
			}
			else if(s[i]>=180.0 && s[i]<185.0){
				nz5+=1;
			}
			else if(s[i]>=185.0){
				nz6+=1;
			}
		}
		printf("1:");
		for(i=0;i<nz1;i++){
			printf("*");
		}
		printf("\n");
		printf("2:");
		for(i=0;i<nz2;i++){
			printf("*");
		}
		printf("\n");
		printf("3:");
		for(i=0;i<nz3;i++){
			printf("*");
		}
		printf("\n");
		printf("4:");
		for(i=0;i<nz4;i++){
			printf("*");
		}
		printf("\n");
		printf("5:");
		for(i=0;i<nz5;i++){
			printf("*");
		}
		printf("\n");
		printf("6:");
		for(i=0;i<nz6;i++){
			printf("*");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1048
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)

















int main(){
    ll n, t;
    cin >> n >> t;
    vector<pair<ll, ll>> v(n);
    REP(i, n){
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(), v.end());
    vector<ll> dp(t + 3000);
    REP(i, n){
        vector<ll> tmp(t + 3000);
        REP(j, t){
            tmp[j + v[i].first] = dp[j] + v[i].second;
        }
        REP(j, t + 3000){
            dp[j] = max(dp[j], tmp[j]);
        }
    }
    cout << *max_element(dp.begin(), dp.end()) << endl;
}

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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;
typedef priority_queue< int, vector< int >, greater< int > >  minHeap;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bug(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

inline int addmod(lli x,lli y)
{
    return (x%mod + y%mod)%mod;
}
inline int submod(lli x,lli y)
{
    return (x%mod - y%mod + mod)%mod;
}
inline int mulmod(lli x,lli y)
{
    return (x%mod * y%mod)%mod;
}


inline int nextSubMask(int i, int mask)
{
    return (i-1)&mask;   /// returns next  submask
}

template<typename T>
void we_r_done(T mssg)
{
    cout<<mssg;
    exit(0);
}


int main()
{
    ///freopen("output.txt","w",stdout);
   // freopen("input.txt","r",stdin);
    FastIO;

    lli n,d,a;
    while(cin>>n>>d>>a){
        vector<pii>v;
        for(int i=1,x,h; i<=n; i++){
            cin>>x>>h;
            v.pb({x,h});
        }
        sort(atoz(v));
        vector<lli>cnt(n+5,0);
        lli need = 0;
        for(int i=0; i<n; i++){
            int x = v[i].fi;
            int h = v[i].se;
            if(i) cnt[i] += cnt[i-1];
            h -= cnt[i]*a;
            if(h<=0) continue;

            lli t = h/a + (h%a != 0);

            cnt[i] += t;
            need += t;

            int r = lower_bound(atoz(v),pii(x+2*d+1,-1))-v.begin();
            cnt[r] -= t;
        }
        cout<<need<<endl;
    }

    return 0;
}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///using bs = bitset<MX>; // how many distinct number can be form?
///sort(atoz(v), [](const data x, const data y){return (x.a==y.a?x.b>y.b : x.a<y.a);});


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,v[55];
	double x;
	cin>>n;
	for(int i=0;i<n;i++) cin>>v[i];
	sort(v,v+n);
	x=v[0];
	for(int i=0;i<n;i++){
		x=(v[i]+x)/2;
	}
	cout<<x<<endl;
	return 0;
}


Measured memory_bytes: 256
from sys import stdin, stdout
from collections import deque, defaultdict
import math as m

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n, m = rli()
	tot = sum(rli())
	diff = n - tot
	if diff < 0:
		print("-1")
	else:
		print(diff)
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 68272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
string YES[2] = {"NO", "YES"};
string yes[2] = {"No", "Yes"};

int main(){
    ll n;   cin >> n;
    vector<ll> a(n);
    rep(i, n)   cin >> a[i];
    ll res=0;
    rep(i, n-1){
        if(a[i]+1<a[i+1]) res = -1;
    }
    if(a[0]>0) res = -1;
    if(!res){
        res += a[0];
        rep(i, n-1){
            if(0<a[i+1] && a[i+1]<=a[i]) res += a[i+1]-1;
            if(0<a[i+1]) res += 1;
            //cout << a[i+1] << ' ';
        }
    }
    cout <<res << endl;
}


Measured memory_bytes: 4748
#include<stdio.h>
int main(void)
{
    int a,b,count;
    char s[101];
    // スペース区切りの整数の入力
    scanf("%d %d",&a,&b);
    if(a!=1){count=a-1;}
    if(a<=b){count++;}
    // 出力
    printf("%d",count);
    return 0;
}

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

using namespace std;

const int N = 24;

int n, x[N], y[N], r[N], c[N], p[N];
bool vis[1<<N];

bool lap(int a, int b){
  int d = (x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]);
  return d < r[a] * r[a] + 2 * r[a] * r[b] + r[b] * r[b];
}

int rec(int s){
  int res = 0;
  vis[s] = true;
  for(int i=0;i<n;i++){
    if((s >> i & 1) == 0) continue;
    for(int j=i+1;j<n;j++){
      if((s >> j & 1) == 0) continue;
      if(c[i] != c[j]) continue;
      if((p[i] & s) == 0 && (p[j] & s) == 0){
        s &= ~(1 << i);
        if((p[j] & s) == 0){
          s &= ~(1 << j);
          if(!vis[s]) res = max(res, rec(s));
          s |= 1 << j;
        }
        s |= 1 << i;
      }
    }
  }
  if(s == (1 << n) - 1) return res;
  return res + 2;
}

main(){
  while(cin >> n && n){
    for(int i=0;i<n;i++) cin >> x[i] >> y[i] >> r[i] >> c[i];
    fill(p, p+n, 0);
    fill(vis, vis+(1<<n), false);
    for(int i=0;i<n;i++) for(int j=0;j<i;j++) if(lap(i, j)) p[i] |= 1 << j;
    cout << rec((1<<n)-1) << endl;
  }
}

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

int N, M, Q, L[200009], R[200009], X[509][509], C[509][509];

int main() {
    cin >> N >> M >> Q;
    for (int i = 1; i <= M; i++)
    {
        cin >> L[i] >> R[i]; X[L[i]][R[i]]++;
    }
    for (int i = 1; i <= N; i++)
    {
        for(int j = 1; j <= N; j++) C[i][j] = C[i][j - 1] + X[i][j];
    }
    for (int i = 1; i <= Q; i++)
    {
        int p, q; cin >> p >> q;
        int sum = 0;
        for(int j = p; j <= q; j++) sum += C[j][q] - C[j][p-1];
        cout << sum << endl;
    }
}

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

std::vector<std::array<int, 26>> subsequenceAutomaton(const std::string& S, const char initial_char = 'a')
{
	std::vector<std::array<int, 26>> table(S.size() + 2);
	std::fill(table.back().begin(), table.back().end(), (int)table.size() - 1);
	table[table.size() - 2] = table.back();

	for (int s_i{(int)S.size() - 1}; s_i >= 0; s_i--)
	{
		std::copy(table[s_i + 1].begin(), table[s_i + 1].end(), table[s_i].begin());
		table[s_i][S[s_i] - initial_char] = s_i + 1;
	}
	return std::move(table);
}

int64_t solve();

int main()
{
	printf("%lld\n", solve());

	return 0;
}

int64_t solve()
{
	std::string s, t;
	std::cin >> s >> t;
	auto table{subsequenceAutomaton(s)};
	int now{};
	int64_t ans{};
	for (char& e: t)
	{
		int next{table[now][e - 'a']};
		if (next == (int)table.size() - 1)
		{
			ans += (int)s.size();
			next = table[0][e - 'a'];
		}
		if (next == (int)table.size() - 1)
			return -1ll;
		now = next;
	}
	ans += now;
	return ans;
}

Measured memory_bytes: 10752
#include<bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d",&x);
#define scs(x) scanf("%s",x);
#define scl(x) scanf("%lld",&x);
#define rep(i,s,e) for(int i=s; i<=e; ++i)
#define dep(i,s,e) for(int i=s; i>=e; --i)
typedef long long ll;
using namespace std;
const ll mod=2019;
const int Max=2e5+5;
char s[Max];
ll a[Max],b[Max],cou[3000];
int main()
{
	scs(s+1);
	int n=strlen(s+1);
	ll coun=1,count=0;
	dep(i,n,1){
		a[i]=coun*(s[i]-'0')%mod;
		coun*=10;coun%=mod;
		b[i]=(a[i]+b[i+1])%mod;
		if((s[i]-'0')!=0&&cou[b[i]]!=0)count+=cou[b[i]]+(b[i]==0?1:0);
		cou[b[i]]++;
	}pf("%lld\n",count+(cou[0]==0?0:1));
}


Measured memory_bytes: 7152
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 2e9;
const ll inf64 = 7e18l;
vector<set<int>> g, g2;
vector<int> visited, answer, comp;
int cnt = 0;
int cur = 0;
void dfs(int v) {
	++cnt;
	comp[v] = cur;
	visited[v] = 1;
	for (int u : g[v]) {
		if (!visited[u]) {
			dfs(u);
		}
	}
	answer[v] = cnt - g[v].size() - 1;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n, m, k;
	cin >> n >> m >> k;
	g.resize(n);
	g2.resize(n);
	visited.resize(n);
	answer.resize(n);
	comp.resize(n, -1);
	for (int i = 0; i < m; ++i) {
		int u, v;
		cin >> u >> v;
		--u;
		--v;
		g[u].insert(v);
		g[v].insert(u);
	}
	for (int i = 0; i < k; ++i) {
		int u, v;
		cin >> u >> v;
		--u;
		--v;
		g2[u].insert(v);
		g2[v].insert(u);
	}
	vector<int> sz(n + 1);
	for (int i = 0; i < n; ++i) {
		if (!visited[i]) {
			cnt = 0;
			++cur;
			dfs(i);
			sz[cur] = cnt;
		}
	}
	
	for (int i = 0; i < n; ++i) {
		answer[i] = sz[comp[i]] - 1 - g[i].size();
		for (int v : g2[i]) {
			if (comp[i] == comp[v]) {
				if (g[i].count(v) == 0) {
					--answer[i];
				} else {
					assert(false);
				}
			}
		}
	}			
	for (int i = 0; i < n; ++i) {
		cout << answer[i] << ' ';
	}
	cout << '\n';
 	return 0;
}


Measured memory_bytes: 31744
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <sstream>

#define mp make_pair
#define rep(i,n) for(int i = 0 ; i < n ; i++)

using namespace std;

int main(){
	string s1 , s2;

	while( cin >> s1 >> s2 )
	{
		int hit = 0 , blow = 0;
		if( s1 == "0" && s2 == "0" ) break;
		rep(i,4)
		{
			if( s1[i] == s2[i] ) hit++;
			else if( s1[0] == s2[i] || s1[1] == s2[i] || s1[2] == s2[i] || s1[3] == s2[i] ) blow++;
		}
		cout << hit << " " << blow << endl;
	}
	
	return 0;
}

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

int main(){

  ll n,m;
  cin >> n >> m;
  ll ans;

  if ( 2 * n >= m ) {//cがたらんou ピッタリ
    ans = m / 2;
  } else {
    ans = n;
    m -= 2*n;
    ans += (m/4);
  }

  cout << ans << endl;

}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

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

int main(){
    ll a,b;
    scanf("%lld%lld", &a, &b);
    ll c=gcd(a,b);
    ll s=1;
    for(ll i=2;i*i<=c;i++){
        if(c%i==0){
            while(c%i==0){
                c /= i;
            }
            s++;
        }
    }
    if(c>1) s++;
    printf("%lld\n", s);
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("7");
            //2
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("149696127901");
            //27217477801
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        long x = long.Parse(InputList[0]);

        long Answer = 0;
        long Syou = x / 11;
        Answer += Syou * 2;

        long ModVal = x % 11;
        if (1 <= ModVal && ModVal <= 6) Answer++;
        if (7 <= ModVal && ModVal <= 10) Answer += 2;

        Console.WriteLine(Answer);
    }
}


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

using namespace std;

int main() {
  int n,a,b,c,d; cin >> n >> a >> b >> c >> d;
  int ta,tc;
  if(n%a) ta=n/a*b+b;
  else ta=n/a*b;
  if(n%c) tc=n/c*d+d;
  else tc=n/c*d;
  cout << (ta<tc?ta:tc) << endl;
  
  return 0;
}



Measured memory_bytes: 3112
#include <iostream>
using namespace std;
int main(void){
   int a,b;
   char op;
   while(true){
       cin>>a>>op>>b;
       if(op=='?'){
           break;
       }
       if(op=='+'){
           cout<<(a+b)<<endl;
       }
       if(op=='-'){
           cout<<(a-b)<<endl;
       }
       if(op=='*'){
           cout << (a * b) <<endl;
       }
       if(op=='/'){
           cout<<(a/b)<<endl;
       }
   }
}
      


Measured memory_bytes: 3072