akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

#define y1 dmytxdy
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef pair<ld,int> pdi;

template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

ll n,X,m,ans,tot;
ll a[55],v[55],nxt[55],h[55],b[55],d[55][125005],rem[55];
pdi p[55];

void addedge(int x,int y){v[++tot]=y; nxt[tot]=h[x]; h[x]=tot;}

void dfs(int u){
	b[u]=1;
	for(int p=h[u];p;p=nxt[p]) dfs(v[p]),a[u]+=a[v[p]],b[u]+=b[v[p]];
}

void calcd(){
	memset(d,0x3f,sizeof(d));
	d[0][0]=0;
	for(int i=1;i<=n;i++)
		for(int j=0;j<=n*n*n;j++)
			for(int l=0;l<=min(n,rem[i]);l++)
				if(j>=l*b[i])
					chkmin(d[i][j],d[i-1][j-l*b[i]]+l*a[i]);
}

int main(){
	n=readint(); X=readint(); m=readint();
	a[1]=readint();
	for(int i=2;i<=n;i++) a[i]=readint(),addedge(readint(),i);
	dfs(1);
	for(int i=1;i<=n;i++) p[i]=mp((ld)b[i]/a[i],i);
	sort(p+1,p+n+1);
	rem[1]=X/a[1];
	for(int i=2;i<=n;i++) rem[i]=min(m,X/a[i]);
	calcd();
	for(int i=1;i<=n;i++) rem[i]-=min(n,rem[i]);
	for(int i=0;i<=n*n*n;i++){
		ll tmp=X-d[n][i],now=i;
		for(int j=n;j>=1;j--){
			if(tmp<0) break;
			int u=p[j].se;
			chkmax(ans,now+min(rem[u],tmp/a[u])*b[u]);
			now+=rem[u]*b[u],tmp-=rem[u]*a[u];
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 54016
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N, M;
    cin >> N >> M;
    cout << N * M << endl;
}



Measured memory_bytes: 3100
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	private static Scanner in;
	
	private static int n;
	private static int k;
	private static int[] a;
	private static long[][] dp;
	private static final int MOD = (int)1e9+7;
	
	public static void main(String[] args) {
		in = new Scanner(System.in);
		n = in.nextInt();
		k = in.nextInt();
		a =  new int[n];
		for(int i=0; i<n; i++) {
			a[i] = in.nextInt();
		}
		
		dp = new long[n+1][k+1];
		
//		for(int i=0; i<dp.length; i++)
//			Arrays.fill(dp[i], -1);
		
		
		
//		System.out.println(solve(0, n-1, 0));
	
		dp[n][0]=1;
		
		for(int i=n-1; i>=0; i--) {
			long[] prefix = new long[k+1];
			prefix[0] = dp[i+1][0];
			for(int j=1; j<=k; j++) {
				prefix[j] = (prefix[j-1]+dp[i+1][j])%MOD;
			}
			for(int kLeft=0; kLeft<=k; kLeft++) {
				dp[i][kLeft] = (prefix[kLeft]-(kLeft-a[i]-1>=0?prefix[kLeft-a[i]-1]:0)+MOD)%MOD;
			}
			
			
		}
		
		System.out.println(dp[0][k]);
		
	}
	

}


Measured memory_bytes: 169300
import heapq as h

N,M=map(int,input().split())
hen={(i,j):[] for i in range(0,N) for j in range(0,3)}
for i in range(0,M):
    u,v=map(int,input().split())
    hen[(u-1,0)].append((v-1,1))
    hen[(u-1,1)].append((v-1,2))
    hen[(u-1,2)].append((v-1,0))

S,T=map(int,input().split())

start=(S-1,0)
goal=(T-1,0)

distance={(i,j):-1 for i in range(0,N) for j in range(0,3)}

q=[]
q.append(start)
distance[start]=0
h.heapify(q)
sub=[]
h.heapify(sub)
while q!=[]:
    while q!=[]:
        x=h.heappop(q)
        for p in hen[x]:
            if distance[p]==-1:
                h.heappush(sub,p)
                distance[p]=distance[x]+1
        #何らかの操作
        #ここでsubキューに次に使うものを格納
        if q==[]:
            q=sub
            sub=[]
            h.heapify(sub)
            break

if distance[goal]==-1:
    print(-1)
else:
    print(distance[goal]//3)

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

int gcd(int a, int b) {
    if(b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

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

    int ans = 0;
    for(int i = 1; i <= K; ++i) {
        for(int j = 1; j <= K; ++j) {
            int tmp = gcd(i, j);
            for(int k = 1; k <= K; ++k) {
                ans += gcd(tmp, k);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
fun main() = Thread(null, ::abc169e, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun abc169e() {
    val n = readLine()!!.toInt()
    val abList = Array(n) {
        val (a, b) = readLine()!!.split(' ').map { it.toLong() }
        a..b
    }

    val sortByFirst = abList.sortedBy { it.first }
    val sortByLast = abList.sortedBy { it.last }

    val answer = if (n % 2 == 0) {
        val leftMin = sortByFirst.take(n / 2).map { it.first }.max()!!
        val rightMin = sortByFirst.take(n / 2 + 1).map { it.first }.max()!!
        val leftMax = sortByLast.takeLast(n / 2 + 1).map { it.last }.min()!!
        val rightMax = sortByLast.takeLast(n / 2).map { it.last }.min()!!

        (leftMax + rightMax) - (leftMin + rightMin) + 1
    } else {
        val max = sortByLast[n / 2]
        val min = sortByFirst[n / 2]
        max.last - min.first + 1
    }

    println(answer)
}


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

using namespace std;

int main() {
  string s;
  cin >> s;
  int size = s.size();
  int cnt_red = 0, cnt_blue = 0;

  for ( int i = 0; i < size; i++ ) {
    if ( s[i] == '0' ) cnt_red++;
    else cnt_blue++;
  }
  cout << min(cnt_red, cnt_blue) * 2 << endl;
  return 0;
}

Measured memory_bytes: 512
import sys
from collections import deque
MOD = 10 ** 9 + 7

n, k, *ab = map(int, sys.stdin.read().split())
graph = [[] for _ in range(n)]
for a, b in zip(*[iter(ab)] * 2):
  a -= 1; b -= 1
  graph[a].append(b)
  graph[b].append(a)

def main():
  for i in range(n):
    if len(graph[i]) + 1 > k:
      print(0)
      return
  
  cnt = [None] * n; cnt[0] = k
  parent = [None] * n
  stack = [0]
  while stack:
    u = stack.pop()
    c = k - 2 if not parent[u] is None else k - 1
    for v in graph[u]:
      if v == parent[u]: continue 
      parent[v] = u
      cnt[v] = c
      c -= 1
      stack.append(v)

  res = 1
  for c in cnt:
    res *= c
    res %= MOD
  print(res)

if __name__ == '__main__':
  main()

Measured memory_bytes: 36052
#include <iostream>
#include <string>
#include <stack>

using namespace std;

char wa(char a, char b);
char seki(char a, char b);
char naraba(char a, char b);
char not_k(char a);

bool kaiseki(string b) {
	stack<char> stk1;
	stack<char> stk2;
	char aa, bb;
	for (int i = 0; i < b.size(); i++) {
		if (b[i] == '=') {
			aa = stk2.top();
			stk2.pop();
		} else {
			if (b[i] == '0' || b[i] == '1') {
				while (!stk1.empty() && stk1.top() == '-') {
					stk1.pop();
					b[i] = not_k(b[i]);
				}
				stk2.push(b[i]);
			} else if (b[i] == '+' || b[i] == '*' || b[i] == '>' || b[i] == '(') {
				stk1.push(b[i]);
			} else if (b[i] == ')') {
				char p = stk2.top();
				stk2.pop();
				char q = stk2.top();
				stk2.pop();
				char k = stk1.top();
				stk1.pop();
				if (k == '+') {
					p = wa(p, q);
				} else if (k == '*'){
					p = seki(p, q);
				} else if (k == '>') {
					p = naraba(q, p);
				} else {
					stk2.push(q);
					p = not_k(p);
				}
				stk1.pop();
				while (!stk1.empty() && stk1.top() == '-') {
					stk1.pop();
					p = not_k(p);
				}
				stk2.push(p);
			} else if (b[i] == '-') {
				if (b[i+1] == '>') {
				} else {
					if (!stk1.empty() && stk1.top() == '-') {
						stk1.pop();
					} else {
						stk1.push(b[i]);
					}
				}
			}
		}
	}
	bb = stk2.top();
	stk2.pop();
	return aa == bb;
}

char wa(char a, char b) {
	if (a == '0' && b == '0') {
		return '0';
	} else {
		return '1';
	}
}

char seki(char a, char b) {
	if (a == '1' && b == '1') {
		return '1';
	} else {
		return '0';
	}
}

char naraba(char a, char b) {
	if (a == '1' && b == '0') {
		return '0';
	} else {
		return '1';
	}
}

char not_k(char a) {
	if (a == '0') {
		return '1';
	} else {
		return '0';
	}
}

int main() {
	string a;
	string abc = "abcdefghijk";
	while (cin >> a) {
		if (a == "#") {
			break;
		}
		int counter = 1;
		counter <<= 11;
		string b;
		bool hantei = true;
		for (int i = 0; i < a.size(); i++) {
			if (a[i] == 'T') {
				a[i] = '1';
			} else if (a[i] == 'F') {
				a[i] = '0';
			}
		}
		for (int i = 0; i < counter; i++) {
			b = a;
			for (int j = 0; j < 11; j++) {
				if ((i&(1<<j)) != 0) {
					while (b.find(abc[j]) != string::npos) {
						b[b.find(abc[j])] = '1';
					}
				} else {
					while (b.find(abc[j]) != string::npos) {
						b[b.find(abc[j])] = '0';
					}
				}
			}
			if (!kaiseki(b)) {
				hantei = false;
				break;
			}
		}
		if (hantei) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1200
# n : ノード数
# m : パス数
n, m = map(int, input().split())

# iノード, jノードにパスがある場合はconn[i][j] = conn[j][i] = True
conn = []
for _ in [0]*n:
    conn.append([False]*n)

# iノードに訪れたことがある場合はvisited[i] = True
visited = [False] * n

# グラフ入力
# ノード番号から-1して0始まりにしておく
v = []
for _ in [0]*m:
    line = map(int, input().split())
    v.append([x-1 for x in line])

# connテーブルを初期化
for start, end in v:
    conn[start][end] = conn[end][start] = True


def dfs(now, depth):
    if visited[now]: return 0
    if depth == n - 1: return 1
    
    visited[now] = True
    ret = 0

    for i in range(0, n):
        if conn[now][i]: ret += dfs(i, depth+1)
    
    visited[now] = False

    return ret

print(dfs(0, 0))

Measured memory_bytes: 42716
#include <stdio.h>
#include <stdlib.h>
 
int main(int argc, const char * argv[]) {
    int a1=0,a2=0,a3=0,a4=0,dice[7],i=0,x=0,y=0,a=0,z=0;
     
    for(i = 1;i <= 6;i++){
        scanf("%d",&dice[i]);
    }
     
    scanf("%d",&a);
    for(i=0;i<a;i++){
        scanf("%d %d",&x,&y);
        while(1){
            z = rand()%4;
            if(z==0){
                a1=dice[1];
                a2=dice[3];
                a3=dice[4];
                a4=dice[6];
                dice[1]=a3;
                dice[3]=a1;
                dice[4]=a4;
                dice[6]=a2;
            }else if(z==1){
                a1=dice[1];
                a2=dice[2];
                a3=dice[5];
                a4=dice[6];
                dice[1]=a2;
                dice[2]=a4;
                dice[5]=a1;
                dice[6]=a3;
            }else if(z==2){
                a1=dice[1];
                a2=dice[2];
                a3=dice[5];
                a4=dice[6];
                dice[1]=a3;
                dice[2]=a1;
                dice[5]=a4;
                dice[6]=a2;
            }else if(z==3){
                a1=dice[1];
                a2=dice[3];
                a3=dice[4];
                a4=dice[6];
                dice[1]=a2;
                dice[3]=a4;
                dice[4]=a1;
                dice[6]=a3;
            }
            if(dice[1]==x && dice[2]==y){
                break;
            }
    }
    printf("%d\n",dice[3]);
    }
    return 0;
}

Measured memory_bytes: 596
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	n, _ := strconv.Atoi(input())

	ans := n - 1
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			q := n / i
			ans = min(ans, i+q-2)
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

ll H(ll n) { return n * (n + 1) / 2; }

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  vector<int> C(N); rep(i, N) cin >> C[i], C[i]--;
  vector<vector<int>> G(N);
  rep(i, N - 1) {
    int u, v; cin >> u >> v; u--; v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  vector<ll> ans(N, (ll)N * (N + 1) / 2);
  vector<map<int, ll>> dp(N);
  vector<int> size(N);
  auto dfs = [&](auto dfs, int u, int p) -> void {
    size[u] = 1;
    for (int v : G[u]) if (v != p) {
      dfs(dfs, v, u);
      size[u] += size[v];
      if (dp[u].size() < dp[v].size()) swap(dp[u], dp[v]);
      for (auto [k, e] : dp[v]) {
        dp[u][k] += e;
      }
    }
    dp[u][C[u]] = size[u];
    if (p != -1) {
      ans[C[p]] -= H(size[u] - dp[u][C[p]]);
    }
  };
  dfs(dfs, 0, -1);
  rep(i, N) {
    ans[i] -= H(size[0] - dp[0][i]);
    cout << ans[i] << '\n';
  }
}

Measured memory_bytes: 88100
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int n;
  cin>>n;
  int p[n];
  rep(i,0,n ) cin>>p[i];
  sort(p,p+n,greater<int>());
  ll ans=p[0]/2;
  rep(i,1,n) ans+= p[i];
  cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

int main() {
    cin>>N;
    vec a(N);
    ll sum = 0;
    rep(i,N) {
        cin>>a[i];
        sum = sum ^ a[i];
    }
    rep(i,N){
        cout<<(sum ^ a[i])<<" \n"[i == N - 1];
    }
}

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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int a, b; cin >> a >> b;

    if (a == b) {
        puts("Draw");
        return 0;
    }

    if (a == 1) {
        puts("Alice");
        return 0;
    }

    if (b == 1) {
        puts("Bob");
        return 0;
    }

    if (a > b) {
        puts("Alice");
        return 0;
    } else {
        puts("Bob");
        return 0;
    }
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
////////////////////////////

int main(){
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll ans=0;
    rep(x,1,n-2){
        ll lpos=x,rpos=n-1-x;
        ll sum=0;
        while(x<rpos){
            sum+=a[lpos]+a[rpos];
            Max(ans,sum);
            lpos+=x;
            rpos-=x;
            if(rpos%x==0&&rpos<=lpos)break;
        }
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
ll n,ans;
ll Exgcd(ll a,ll b,ll &x,ll &y){
	if(!b){
		x=1,y=0;
		return a;
	}
	ll ret=Exgcd(b,a%b,x,y);
	ll t=x;x=y,y=t-(a/b)*y;
	return ret;
}
void Do(ll i,ll j){
	ll a,b;
	Exgcd(i,j,b,a);
	b=(b%j+j)%j;
	ans=min(ans,i*b-1);
}
int main(){
	ll x;
	cin>>x;
	if(x==1)return puts("1"),0;
	x*=2,n=x,ans=x-1;
	for(ll i=2;i*i<=x;i++){
		if(x%i)continue;
		if(__gcd(i,x/i)>1)continue;
		Do(i,x/i),Do(x/i,i);
	}
	cout<<ans;
    return 0;
}


Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define pb push_back
#define all(S) S.begin(), S.end()
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
lli power(lli x, lli y, lli p){
    lli res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
lli solve(){
    lli x, y, a, b, c;
    cin>>x>>y>>a>>b>>c;
    vll R(a), G(b), C(c);
    loop(i, 0, a)
        cin>>R[i];
    loop(i, 0, b)
        cin>>G[i];
    loop(i, 0, c)
        cin>>C[i];
    sort(all(R), greater<lli>());
    sort(all(G), greater<lli>());
    sort(all(C), greater<lli>());
    lli ans = 0;
    loop(i, 0, x)
        ans += R[i];
    loop(i, 0, y)
        ans += G[i];
    lli i = x-1, j = y-1, k = 0;
    while( k < c ){
        if(i < 0){
            if(j < 0)
                break;
            else{
                if(G[j] < C[k]){
                    ans = ans - G[j] + C[k];
                    j--;
                    k++;
                }
                else
                    break;
            }
        }
        else if(j < 0){
            if(i < 0)
                break;
            else{
                if(C[k] > R[i]){
                    ans = ans - R[i] + C[k];
                    k++;
                    i--;
                }
                else
                    break;
            }
        }
        else{
            if(R[i] >= G[j]){
                if(G[j] >= C[k])
                    break;
                else{
                    ans = ans - G[j] + C[k];
                    k++;
                    j--;
                }
            }
            else{
                if(R[i] >= C[k])
                    break;
                else{
                    ans = ans - R[i] + C[k];
                    k++;
                    i--;
                }
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}
int main(){
    fastio;
    lli t;
    // cin>>t;
    t = 1;
    while(t>0){
        t--;
        solve();
    }
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <math.h>

using namespace std;


int main(){
    string tmp;
    cin >> tmp;
    int arr[4];
    for (int i=0; i<4; i++){
        arr[i] = tmp[i] - '0';
    }


    for (int s=0; s < pow(2, 3); s++) {
        int sum = arr[0];
        for (int i=0; i<3; i++){
            if(s & (1<<i)) {
                sum += arr[i+1];
            } else {
                sum -= arr[i+1];
            }
        }
        if (sum == 7){
            cout << arr[0];
            for(int i=0; i<3; i++){
                if (s & (1<<i)) {
                    cout << "+";
                } else {
                    cout << "-";
                }
                cout << arr[i+1];
            }
            cout << "=7" << endl;
            return 0;
        }
    }

    return 1;
}

Measured memory_bytes: 256
import sys
import math
import itertools as it
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    x, y = I2()
    cnt = 0
    while x <= y:
        x *= 2
        cnt += 1
    print(cnt)

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int r, d, x;

int main(void) {
  // Here your code !
  scanf("%d %d %d", &r, &d, &x);

  for (int i = 1; i <= 10; ++i) {
    x = r * x - d;

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

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int i,cnt = 0, N, A[100], tmp, j, minj;

  scanf("%d",&N);
  for(i = 0; i < N; i++){
    scanf("%d",&A[i]);
  }

  for(i = 0; i < N-1; i++){
    minj = i;
    for(j = i; j < N; j++){
      if(A[j] < A[minj]){
	minj = j;
      }
    }
    tmp = A[i];
    A[i] = A[minj];
    A[minj] = tmp;
    if(i != minj)cnt++;
  }

  for(i = 0; i < N; i++){
    if(i > 0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",cnt);
  
  return 0;
}




Measured memory_bytes: 2104
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
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; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    ll a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    ll ans = INF;
    rep(i,100001){
        ans=min(ans,c*2*i+max(0ll,x-i)*a+max(0ll,y-i)*b);
    }

    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3652
# -*- coding: utf-8 -*-

S_dash = input()
T = input()

S_dash_list = list(S_dash)
T_list = list(T)

ei = len(S_dash_list)
si = ei - len(T_list)

insert_flag = False
while si >= 0:
    #print('si: {}, ei: {}'.format(si, ei))
    target = S_dash_list[si:ei]
    flag = True
    for i in reversed(range(len(T_list))):
        if S_dash_list[si + i] != T_list[i] and S_dash_list[si + i] != '?':
            flag = False
            # ここでsiとeiを更新
            ei -= 1
            si = ei - len(T_list)
            break
    if flag:
        for i in range(len(T_list)):
            S_dash_list[si + i] = T_list[i]
        insert_flag = True
        break

if not insert_flag:
    print('UNRESTORABLE')
else:
    ans = ''.join(S_dash_list)
    #print(ans)

    # '?'をaで埋める
    print(ans.replace('?', 'a'))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fi 			first
#define se 			second
#define pb 			push_back
#define pf 			push_front
#define mod 		1000000007
//#define mod 998244353
//#define mod 1000000009
#define Pi 			3.14159265359
#define eps 		1e-9
#define all(v) 		v.begin(),v.end()
#define sz(v) 		((int)(v).size())
#define each(x, v)  for (auto &x : v)
#define pii         pair<int,int>
#define vi          vector<int>
#define vvi         vector<vi>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define endl        '\n'
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
typedef long long ll;
ll pw(ll a, ll b)
{
    ll ans = 1;
    while(b)
    {
        if(b & 1)
            ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}
void Solution();

int main(){
    int T = 1;
//    ios::sync_with_stdio(false);
//    cin.tie(0);
//    cout.tie(0);
   // cin>>T;
    while(T--){
        Solution();
    }
    return 0;
}
void Solution(){
    ll s;
    cin>>s;
    ll bs = 100;
    int t = 0;
    while(bs<s){
        bs=floor(bs*1.01);
        t++;
    }
    cout<<t<<endl;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;


signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int R;
	cin >> R;
	cout << fixed << setprecision(10);
	cout << 2* R * 3.14159265 << endl;
}

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

const ll MOD = 998244353;
template<ll MOD> struct ModInt {
    ll value;
    ModInt() : value(0) {}
    ModInt(const ll& v) : value(v % MOD) {
        if ( value < 0 ) value += MOD;
    }
    ModInt<MOD>& operator=(const ModInt& o) {
        value = o.value;
        return *this;
    }
    inline bool operator==(const ModInt& o) {
        return value == o.value;
    }
    inline bool operator!=(const ModInt& o) {
        return value != o.value;
    }
    ModInt<MOD>& operator+=(const ModInt& o) {
        value += o.value;
        if ( value >= MOD ) value -= MOD;
        return *this;
    }
    ModInt<MOD>& operator-=(const ModInt& o) {
        value += MOD - o.value;
        if (value >= MOD ) value -= MOD;
        return *this;
    }
    ModInt<MOD>& operator*=(const ModInt& o) {
        value *= o.value;
        value %= MOD;
        return *this;
    }
    ModInt<MOD>& operator/=(const ModInt& o) {
        value *= inverse(o.value);
        value %= MOD;
        return *this;
    }
    ModInt<MOD> operator-() {
        return ModInt<MOD>(-value);
    }
    ModInt<MOD> operator+(const ModInt& o) {
        ModInt<MOD> r(*this);
        r += o;
        return r;
    }
    ModInt<MOD> operator-(const ModInt& o) {
        ModInt<MOD> r(*this);
        r -= o;
        return r;
    }
    ModInt<MOD> operator*(const ModInt& o) {
        ModInt<MOD> r(*this);
        r *= o;
        return r;
    }
    ModInt<MOD> operator/(const ModInt& o) {
        ModInt<MOD> r(*this);
        r /= o;
        return r;
    }
    ModInt<MOD> pow(ll n) {
        ModInt<MOD> t(*this), r = 1;
        while ( n > 0 ) {
            if ( n & 1 ) r *= t;
            t *= t;
            n >>= 1;
        }
        return r;
    }
private:
    ll inverse(ll a) {
        ModInt<MOD> t(a);
        return t.pow(MOD - 2).value;
    }
};
using Int = ModInt<MOD>;

ll solve() {
    ll N, S;
    cin >> N >> S;
    vector<ll> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }
    Int ans = 0;
    vector<vector<Int>> dp(N+1, vector<Int>(S+1));
    dp[0][0] = 1;
    for ( int i = 1; i <= N; i++ ) {
        dp[i][0] = 1;
        for ( int j = 0; j <= S; j++ ) {
            dp[i][j] += dp[i-1][j];
            ll k = j - A[i-1];
            if ( k >= 0 ) {
                dp[i][j] += dp[i-1][k];
            }
        }
        ans += dp[i][S];
    }
    return ans.value;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 70784
#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.at(i);
    
    vector<int> passed(n);
    int on = 1;
    for (int i = 0; i < n; i++) {
        if (passed.at(on - 1) == 0) {
            if (a.at(on - 1) == 2) {
                cout << i + 1 << endl;
                break;
            }
            else {
                passed.at(on - 1)++;
                on = a.at(on - 1);
            }
        }
        else {
            cout << -1 << endl;
            break;
        }
    }
}


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

using namespace std;

typedef long long ll;

int main()
{
	ll l, r;
	cin >> l >> r;

	if (r - l >= 2019) {
		cout << 0 << endl;
		return 0;
	}
	else {
		ll a = 2018 * 2017;
		for (ll i = l; i <= r - 1; i++) {
			for (ll j = l + 1; j <= r; j++) {
				a = min((i * j) % 2019, a);
			}
		}
		cout << a << endl;
	}
	
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(H: int, W: int, S: "List[str]"):
    for i in range(H):
        for j in range(W):
            if S[i][j] == "#":
                print("#", end="")
                continue
            n = 0
            if i - 1 >= 0:
                if S[i - 1][j] == "#":
                    n += 1
                if j + 1 < W and S[i - 1][j + 1] == "#":
                    n += 1
                if j - 1 >= 0 and S[i - 1][j - 1] == "#":
                    n += 1
            if i + 1 < H:
                if S[i + 1][j] == "#":
                    n += 1
                if j + 1 < W and S[i + 1][j + 1] == "#":
                    n += 1
                if j - 1 >= 0 and S[i + 1][j - 1] == "#":
                    n += 1
            if j + 1 < W and S[i][j + 1] == "#":
                n += 1
            if j - 1 >= 0 and S[i][j - 1] == "#":
                n += 1
            print(n, end="")
        print()
    return


# Generated by 1.1.7.1 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()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [list(next(tokens)) for _ in range(H)]  # type: "List[str]"
    solve(H, W, S)


if __name__ == "__main__":
    main()


Measured memory_bytes: 74468
#include <stdio.h>

int main(){
  int n, i, max;
  int h[100];
  int ans=1;
  scanf("%d", &n);
  scanf("%d", &h[0]);
  for (i = 1;i < n; i++) {
    scanf(" %d", &h[i]);
  }
  max = h[0];
  for (i = 1; i < n; i++) {
    if (h[i] >= max) {
      max = h[i];
      ans += 1;
    }
  }
  printf("%d", ans);

  return 0;
}


Measured memory_bytes: 128
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let K: usize = sc.get();
    let T: usize = sc.get();
    let mut a: Vec<usize> = sc.vec(T);
    let mut prev = T;
    for now in 0..K {
        let mut max = 0;
        let mut maxi = 0;
        for i in 0..T {
            if prev != i && max < a[i] {
                max = a[i];
                maxi = i;
            }
        }
        if max == 0 {
            println!("{}", K-now);
            return;
        }
        a[maxi] -= 1;
        prev = maxi;
    }
    println!("0");
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m, c;
    cin >> n >> m >> c;
    int b[m];
    for( int i = 0; i < m; ++i ) {
        cin >> b[i];

    }
    int ans = 0;
    for( int i = 0; i < n; ++i ) {
        int tmp = 0;
        for( int j = 0; j < m; ++j ) {
            int a;
            cin >> a;
            tmp += a * b[j];
        }
        tmp += c;
        if( tmp > 0 ) ++ans;
    }

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int A, B, X;
    cin >> A >> B >> X;

    for (int i = 0; i < B; i++){
        if (A + i == X){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  ll c=0;
  ll h,a;cin>>h>>a;
  while(h>0){
    h-=a;
    c++;
  }

  cout<<c;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>

using namespace std;

int mod = 1000000007;
int n, m;
long long dist[2][100000];
long long count[2][100000];
vector <pair<int, int> > v[100000];

void calc(int s, long long *dist, long long *count) {
    int i;
    priority_queue <pair<long long, int> > q;
    
    for (i = 0; i < n; i++) dist[i] = 1e18;
    
    dist[s] = 0;
    count[s] = 1;
    q.push(make_pair(0, s));
    
    while (!q.empty()) {
        int x = q.top().second;
        long long d = -q.top().first;
        
        q.pop();
        
        if (dist[x] != d) continue;
        
        for (i = 0; i < v[x].size(); i++) {
            int nx = v[x][i].first;
            long long nd = d + v[x][i].second;
            
            if (dist[nx] > nd) {
                dist[nx] = nd;
                count[nx] = count[x];
                q.push(make_pair(-nd, nx));
            } else if (dist[nx] == nd) {
                count[nx] += count[x];
                if (count[nx] >= mod) count[nx] -= mod;
            }
        }
    }
}

int main() {
    int s, t, i;
    long long sum, ans;
    vector <pair<int, pair<int, int> > > w;
    
    scanf("%d %d", &n, &m);
    scanf("%d %d", &s, &t);
    
    s--;
    t--;
    
    for (i = 0; i < m; i++) {
        int x, y, z;
        
        scanf("%d %d %d", &x, &y, &z);
        
        x--;
        y--;
        
        v[x].push_back(make_pair(y, z));
        v[y].push_back(make_pair(x, z));
        w.push_back(make_pair(x, make_pair(y, z)));
    }
    
    calc(s, dist[0], count[0]);
    calc(t, dist[1], count[1]);
    
    sum = dist[0][t];
    ans = count[0][t] * count[1][s] % mod;
    
    for (i = 0; i < n; i++) {
        if (dist[0][i] + dist[1][i] == sum && dist[0][i] == dist[1][i]) {
            ans -= count[0][i] * count[0][i] % mod * count[1][i] % mod * count[1][i] % mod;
            if (ans < 0) ans += mod;
        }
    }
    
    for (i = 0; i < m; i++) {
        int x = w[i].first;
        int y = w[i].second.first;
        int z = w[i].second.second;
        
        if (dist[0][x] + z + dist[1][y] == sum && dist[0][x] < dist[1][x] && dist[1][y] < dist[0][y]) {
            ans -= count[0][x] * count[0][x] % mod * count[1][y] % mod * count[1][y] % mod;
            if (ans < 0) ans += mod;
        }
        
        if (dist[0][y] + z + dist[1][x] == sum && dist[0][y] < dist[1][y] && dist[1][x] < dist[0][x]) {
            ans -= count[0][y] * count[0][y] % mod * count[1][x] % mod * count[1][x] % mod;
            if (ans < 0) ans += mod;
        }
    }
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 17804
N = int(input())
F = [list(map(int, input().split(" "))) for _ in range(N)]
P = [list(map(int, input().split(" "))) for _ in range(N)]

res = []
for i in range(1, 2**10 + 1):
    index = list("0000000000")
    binary = list(bin(i)[2:])
    index[-len(binary):] = binary
    index = list(map(int, index))
    kaburi = [sum([i * f for i, f in zip(index, F[n])]) for n in range(N)]
    res.append(sum([P[n][k] for n, k in zip(range(N), kaburi)]))

print(max(res))


Measured memory_bytes: 3064
import std.stdio, std.algorithm, std.conv, std.array, std.string;

int[(10^^5)*2] AS;

void main()
{
    auto N = readln.chomp.to!int;
    foreach (i; 0..N) AS[i] = readln.chomp.to!int;

    if (AS[0]) {
        writeln("-1");
        return;
    }

    long cnt;
    foreach (i; 1..N) {
        if (AS[i] > AS[i-1]+1) {
            writeln("-1");
            return;
        }

        if (AS[i] == AS[i-1]+1) {
            ++cnt;
        } else {
            cnt += AS[i];
        }
    }

    writeln(cnt);
}

Measured memory_bytes: 2044
// https://atcoder.jp/contests/abc157/tasks/abc157_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

struct UnionFind {
    vector<int> par; // 親の番号
    UnionFind(int size) : par(size, -1) {}
    // xとyの木を併合
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (par[y] < par[x])
                swap(x, y);
            par[x] += par[y];
            par[y] = x;
            return true;
        } else {
            return false;
        }
    }
    // 2つのデータx, yが属する木が同じならtrueを返す
    bool same(int x, int y) { return root(x) == root(y); }
    // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    int root(int x) { return par[x] < 0 ? x : par[x] = root(par[x]); }
    // 頂点 v が属するグループと同じグループに属する頂点数を得る
    int size(int x) { return -par[root(x)]; }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M, K;
    cin >> N >> M >> K;
    UnionFind uf(N);
    // set<pair<int, int>> st;
    set<int> st[N];
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf.unite(a, b);
        st[a].insert(b);
        st[b].insert(a);
    }
    REP(i, K) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        if (uf.same(a, b)) {
            st[a].insert(b);
            st[b].insert(a);
        }
    }
    REP(i, N) {
        cout << uf.size(i) - st[i].size() - 1 << (i == N - 1 ? "\n" : " ");
    }

    return 0;
}


Measured memory_bytes: 25088
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
template<class T>
void dump(vector<T> &vec){
	for(int i=0;i<vec.size();i++){
		cout << vec[i];
		if(i+1<vec.size())cout << ' ';
		else cout << endl;
	}
	return;
}
template<class T>
struct imos{
	vector<T> vec;
	vector<T> rui;
	imos(){}
	imos(vector<T> v){
		vec = v;
		init();
	}
	void init(){
		rui = vec;
		for(int i=1;i<rui.size();i++){
			rui[i] += rui[i-1];
		}
	}
	T sum(int l,int r){
		if(l==0)return rui[r];
		else return rui[r]-rui[l-1];
	}
};
int N;
vector<ll> A;
int main(){
	cin >> N;	
	A.resize(N);
	for(int i=0;i<N;i++){
		cin >> A[i];
	}
	sort(all(A));
	imos<ll> rui(A);
	rui.init();
	int r = -1;
	for(int i=0;i<N-1;i++){
		ll s = rui.sum(0,i);
		if(s*2ll<A[i+1])r=i;
	}
	cout << N-1-r << endl;
	return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,m,k;
  cin >> n >> m >> k;
  rep(i,n+1) {
    rep(j,m+1) {
      if(i*m+n*j-i*j*2==k) {
        pr("Yes");
        return;
      }
    }
  }
  pr("No");
}

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


Measured memory_bytes: 256