akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int N, hx, hy, dx, dy;
vector<PII> pos;
vector<double> visited;
double dist[30][30];

void init(){
  REP(i,N) REP(j,N)
	dist[i][j] =
	sqrt((pos[i].first - pos[j].first)*(pos[i].first - pos[j].first)
		 + (pos[i].second - pos[j].second)*(pos[i].second - pos[j].second));

  REP(i,N){
 	dist[i][N] = dist[N][i]
	  = sqrt((pos[i].first - hx)*(pos[i].first - hx)
			 + (pos[i].second - hy)*(pos[i].second - hy));
 	dist[i][N+1] = dist[N+1][i]
	  = sqrt((pos[i].first - dx)*(pos[i].first - dx)
			 + (pos[i].second - dy)*(pos[i].second - dy));
  }
}

bool dfs(int idx, int cnt){
  if(cnt == 0) return true;
  for(int i=0;i<N;++i){
	if(visited[i] >= 0) continue;
	if(visited[idx] + dist[i][idx] >= dist[i][N+1]){
	  return false;
	}
  }

  for(int i=0;i<N;++i){
	if(visited[i] > 0) continue;
	visited[i] = visited[idx] + dist[i][idx];
	if(dfs(i, cnt-1)) return true;
	visited[i] = -1;
  }
  
  return false;
}

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

  while(cin >> N >> hx >> hy >> dx >> dy, N){
	PII m(dx, dy);
	pos.assign(N, PII());
	visited.assign(N+1, -1);
	visited[N] = 0;
	
	fill((double*) dist,(double*)dist+30*30, 0);
	REP(i,N){
	  cin >> pos[i].first >> pos[i].second;
	}
	init();
	
	bool ok = false;
	if(dfs(N, N)){
	  ok = true;
	}

	cout << (ok? "YES": "NO") << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
#define mk make_pair
#define pb push_back
#define pf push_front
typedef pair<int, int> pii;
#define INF (1 << 30)
#define INFL (1ll << 60ll);
#define mod 1000000007

int N, M, C;
int b[100];

signed main()
{
    cin >> N >> M >> C;
    for(int i = 0; i < M; i++){
        cin >> b[i];
    }
    int ans = 0ll;
    for(int i = 0; i < N; i++){
        int sum = 0;
        for(int j = 0; j < M; j++){
            int a;
            cin >> a;
            sum += b[j] * a;
        }
        if(sum + C > 0ll){
            ans++;
        }
    }
    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  do {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
  } while (false);
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int idx = 0, ans = -1;
  while (ans == -1) {
    int even = 0;
    for (int i = 0; i < n; i++) {
      if (arr[i] % 2 == 0) {
        even++;
      }
    }
    if (even & 1) {
      ans = idx;
    } else {
      idx ^= 1;
      if (even != n - 1) {
        ans = idx;
      } else {
        int g = 0;
        for (int i = 0; i < n; i++) {
          if (arr[i] == 1) {
            ans = idx;
            break;
          }
          if (arr[i] & 1) {
            arr[i]--;
          }
          if (!g) {
            g = arr[i];
          } else {
            g = __gcd(g, arr[i]);
          }
        }
        if (!g) {
          break;
        }
        for (int i = 0; i < n; i++) {
          arr[i] /= g;
        }
      }
    }
  }
  if (!ans) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a==b){
		cout<<"-1"<<endl;
	}
	
	else if(a%b==0){
		cout<<"-1"<<endl;
	}
	
	else if(a%b!=0){
		cout<<a<<endl;
	}
	
}

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

long long k, a, b;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> k >> a >> b;
	if(b - a <= 2 || k <= a - 1){
		cout << k + 1 << "\n";
	}else{
		k -= a - 1;
		long long t = a;
		t += (b - a) * (k / 2);
		k %= 2;
		if(k == 1) ++t;
		cout << t << "\n";
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 505;
int n, dp[MX][MX], a[MX][MX], p[MX * MX], res;
int mx[] = {1, -1, 0, 0};
int my[] = {0, 0, 1, -1};

bool valid (int i, int j) {
	return 0 <= i && i < n && 0 <= j && j < n;
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;
	forn (i, n * n) {
		cin >> p[i];
		p[i]--;
	}

	forn (i, n) forn (j, n) {
		dp[i][j] = min(
			min(i, n - i - 1),
			min(j, n - j - 1)
		);
		a[i][j] = 1;
	}

	forn (_, n * n) {
		int i = p[_] / n;
		int j = p[_] % n;

		res += dp[i][j]; 
		a[i][j] = 0;

		queue<int> qx, qy;
		qx.push(i);
		qy.push(j);

		while (qx.size()) {
			int i = qx.front(); qx.pop();
			int j = qy.front(); qy.pop();
			int w = dp[i][j] + a[i][j];

			forn (l, 4) {
				int x = i + mx[l];
				int y = j + my[l];
			
				if (valid(x, y) && dp[x][y] > w) {
					dp[x][y] = w;
					qx.push(x);
					qy.push(y);
				}
			}
		}
	}

	cout << res << endl;

	return 0;
}


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

int main() {
  char c;
  cin >> c;
  
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
    cout << "vowel" << endl;
  else cout << "consonant" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<queue>
#define ll long long
using namespace std;

const int N=105;
const int M=200005;
const int F=1000000000;
const ll inf=1000000000000000ll;

struct E{
	int to,next,f;
}mem[M];
int num,n,S,T;
ll ans;
int a[N],head[N],lev[N],dep[N];
queue<int> q;

void addedge(int x,int y,int f){
	num++;
	mem[num].to=y; mem[num].next=head[x]; mem[num].f=f;
	head[x]=num;
}

void add(int x,int y,int f){
	addedge(x,y,f); addedge(y,x,0);
}

bool bfs(){
	int k,u,j;
	memset(dep,0,sizeof(dep));
	q.push(S); dep[S]=1;
	while (!q.empty()){
		k=q.front(); q.pop();
		for (j=head[k];j;j=mem[j].next){
			u=mem[j].to;
			if (mem[j].f&&!dep[u]){
				dep[u]=dep[k]+1;
				q.push(u);
			}
		}
	}
	return dep[T];
}

ll dfs(int k,ll flow){
	int u; ll used=0,now;
	if (k==T) return flow;
	for (int j=lev[k];j;j=mem[j].next){
		u=mem[j].to;
		if (dep[u]==dep[k]+1&&mem[j].f){
			now=dfs(u,min(1ll*mem[j].f,flow-used));
			used+=now;
			mem[j].f-=(int)now; mem[j^1].f+=(int)now;
			if (mem[j].f) lev[k]=j;
			if (flow==used) break;
		}
	}
	if (!used) dep[k]=-1;
	return used;
}

void dinic(){
	int i;
	while (bfs()){
		for (i=S;i<=T;i++) lev[i]=head[i];
		ans-=dfs(S,inf);
	}
}

int main(){
	scanf("%d",&n); S=0; T=n+1; num=1;
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if (a[i]<0) add(i,T,-a[i]);
		else add(S,i,a[i]),ans+=1ll*a[i];
	}
	for (int i=1;i<=n;i++)
		for (int j=i+i;j<=n;j+=i) add(j,i,F);
	dinic();
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

string my_readln() { return chomp(readln()); }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto tokens = my_readln.split;
	auto N = tokens[0].to!uint;
	auto a = new ulong[][](N);
	foreach (i; 0..N)
	{
		foreach (j, token; my_readln.split)
		{
			auto x = token.to!(ulong);
			if (x == 0) continue;
			a[i] ~= x << j;
		}
	}

	auto dp = new long[](1<<N);
	dp[0] = 1;

	foreach (j; 1..1<<N)
	{
		auto i = popcnt(j) - 1;
		foreach (e; a[i])
		{
			if ((j & e) == 0) continue;

			auto x = j | e;
			dp[j] = moda(dp[j], dp[j^e]);
		}
	}
	//stderr.writeln(dp[i+1]);
	
	writeln(dp[(1<<N)-1]);
	stdout.flush();
}

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

int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=n-1;i>=0;i-=2) cout<<a[i]<<" ";
	for(int i=(n)%2;i<n;i+=2) cout<<a[i]<<" ";
	return 0;
}

Measured memory_bytes: 2944
#include<stdio.h>
#include<algorithm>
using namespace std;

int main()
{
    char s[10];
    scanf("%s", s);
    if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3])printf("Yes\n");
    else if(s[0] == s[2] && s[2] != s[1] && s[1] == s[3])printf("Yes\n");
    else if(s[0] == s[3] && s[3] != s[1] && s[1] == s[2])printf("Yes\n");
    else printf("No\n");
}


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

using namespace std;

int N, A, B;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> N >> A >> B;
    cout << min(A, B) << " " << max(A+B-N, 0) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi; 
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int mod = 1e9+7;
const int maxn =2e5+10;
const int inf = 0x3f3f3f3f;
int a[maxn],t[maxn];
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n;
    ll k;
    cin>>n>>k;
    rep(i,1,n) {
        cin>>a[i];
    }
    if(k<=n) {
        int now=1;
        while(k) {
            k--;
            now=a[now];
        }
        cout<<now<<'\n';
    }
    else {
        int now=1;
        memset(t,-1,sizeof(t));
        t[1]=0;
        while(1) {
            k--;
            if(t[a[now]]!=-1) {
                int len=t[now]-t[a[now]]+1;
                k%=len;
                now=a[now];
                while(k) {
                    k--;
                    now=a[now];
                }
                cout<<now<<'\n';
                break;
            }
            t[a[now]]=t[now]+1;
            now=a[now];
        }
    }
    return 0;
}


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

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {

			int n = sc.nextInt();
			int[] l = new int[n];
			
			for(int i = 0 ; i < n ; i++ ) {
				l[i] = sc.nextInt();
			}
			
			Arrays.sort(l);
			
			int result = 0;
			
			for( int i = 0 ; i < n ; i++ ) {
				for( int j = i+1 ; j < n - 1; j++ ) {
					int a = l[i];
					int b = l[j];
					int gap = b - a;
					
					boolean found = false;
					for(int k = j+1 ; k < n ; k++ ) {
						int c = l[k];
						if ( c > gap) {
							found = true;
						}
						if ( found ) {
							if ( c < a + b ) {
								result++;
							}
							else {
								break;
							}
						}
					}
				}
			}
			
			System.out.println(result);
			
		}
	}
}

Measured memory_bytes: 28108
boxes = gets

result = Array.new(boxes.length, 0)
p1 = 0
p2 = nil
boxes.each_char.each_cons(2).with_index{|(prv, nxt), i|
  if prv == nxt
    if p2.nil?
      result[i] = 0
    else
      result[i+1] = 0
    end
  else
    if p2.nil?
      result[i]   = (i - p1)/2 + 1
      result[i+1] = (i - p1 + 1)/2
      p2 = i
    else
      result[p2]   += (i - p2)/2
      result[p2+1] += (i - p2 + 1)/2
      p1 = i + 1
      p2 = nil
    end
  end
}
result.pop()

puts(result.join(' '))


Measured memory_bytes: 3452
#include <bits/stdc++.h>
#define N int(2e5+5)
#define mod 1000000007
using namespace std;
typedef long long ll;
ll ans;

int main(){
    int n, k;
    cin >> n >> k;
    int arr[n];
    for(int i=0; i<n; i++) cin >> arr[i];
    n--;
    if(n%(k-1)) cout << n/(k-1)+1;
    else cout << n/(k-1);
    return 0;
}


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

const int INF = 2e9;

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    vector<int> cnt(26,INF);
    rep(i,n){
        vector<int> re(26,0);
        string a = s[i];
        rep(j,a.size()){
            int num = a[j];
            re[num-97]++;
        }
        rep(i,26){
            cnt[i] = min(cnt[i],re[i]);
        }
    }
    rep(i,26){
        if(cnt[i] == INF)continue;
        else{
            char ans = i + 97;
            rep(j,cnt[i]) cout << ans;
        }
    }
    cout << endl;
}

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

struct edge{
    int to,weight;
    edge(int to,int weight):to(to),weight(weight){}
};
using Graph = vector<vector<int>> ;
using GraphEdge = vector<vector<int>> ;

long long modinv(long long a, long long m=MOD) {
    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;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
int main(){
    int a[6];
    rep(i,6)cin>> a[i];

    rep(i,5)rep(j,5){
        if(abs(a[i]-a[j]>a[5])){
            cout << ":(" << endl;
            return 0;
        }
    }
    cout << "Yay!" << endl;
    
    return 0;
}

Measured memory_bytes: 3624
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int d,t,s;
	scanf("%d %d %d",&d,&t,&s);
	double p=(double)d/s;
	if(t>=p){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1636
n,m=gets.split.map &:to_i
p=gets.split.map &:to_i
d=$<.map{|l|l.split.map(&:to_i)}

$uf_arr=[]
for k in 0..n
  $uf_arr<<k
end

def get_root(node)
  until node== $uf_arr[node]
    node = $uf_arr[node]
  end
  return node
end

ans=0
d.each{|x,y|
y,x=[get_root(x),get_root(y)].minmax
$uf_arr[x]=$uf_arr[y]}
for k in 1..n
  ans+=1 if get_root(p[k-1])==get_root(k)
end
p ans


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

typedef long long ll;
#define mod 1000000007

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

void solve() {
    int n;
    cin>>n;
    int temp, gc;
    cin>>temp;
    gc = temp;
    for (int i = 0; i < n-1; ++i) {
        cin>>temp;
        gc = __gcd(gc, temp);
    }
    cout<<gc;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    // pre();
    while (t--)
        solve();

    return 0;
}

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

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

    int a, b, q;
    cin >> a >> b >> q;
    vector<ll> s(a + 2), t(b + 2);
    rep(i, a) cin >> s[i + 1];
    rep(i, b) cin >> t[i + 1];
    s[a + 1] = t[b + 1] = 1e11;
    s[0] = t[0] = -1e11;

    rep(i, q)
    {
        ll x;
        cin >> x;
        ll d = 1e12;
        int p = lower_bound(s.begin(), s.end(), x) - s.begin();
        int q = lower_bound(t.begin(), t.end(), x) - t.begin();
        forx(j, p - 1, p + 1) forx(k, q - 1, q + 1)
        {
            d = min(d, abs(s[j] - t[k]) + min(abs(x - s[j]), abs(x - t[k])));
        }
        cout << d << endl;
    }

    return 0;
}


Measured memory_bytes: 2944
// Verified @ GRL_3_A

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v, int size){
	REP(i, size){
		cout << v[i] << " ";
	}
	cout << endl;
}

ll N, M;
vector<ll> G[101010];
vector<ll> dfs_tree[101010];
vector<ll> low(101010);
vector<ll> ord(101010, -1);
ll cnt = 0;

void dfs(ll now, ll par){
	ord[now] = cnt;
	cnt++;
	low[now] = ord[now];
	REP(i, G[now].size()){
		ll next = G[now][i];
		if(ord[next] == -1){
			dfs_tree[now].push_back(next);
			dfs(next, now);
			low[now] = min(low[now], low[next]);
		}else if(next != par){
			low[now] = min(low[now], ord[next]);
		}
	}
	return;
}

vector<pll> enum_bridge(){
	// construct lowlink
	ll root = 0;
	dfs(root, -1);

	// enumerate bridge
	vector<pll> res;
	REP(i, N){
		REP(j, dfs_tree[i].size()){
			if(ord[i] < low[dfs_tree[i][j]]){
				res.push_back({i, dfs_tree[i][j]});
			}
		}
	}
	return res;
}

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

    cin >> N >> M;
    REP(i, M){
    	int s, t;
    	cin >> s >> t;
    	G[s].push_back(t);
    	G[t].push_back(s);
    }

    auto res = enum_bridge();
    REP(i, res.size()) if(res[i].first > res[i].second) swap(res[i].first, res[i].second);
    sort(res.begin(), res.end());
    REP(i, res.size()){
    	cout << res[i].first << " " << res[i].second << endl;
    }

    //vprint(low, N);
    //vprint(ord, N);
    return 0;
}


Measured memory_bytes: 11320
object Main {
  import java.io.PrintStream

  def main(args: Array[String]): Unit = {
    val s = new Main()
    val ps = new PrintStream(Console.out)
    Console.withOut(ps) {
      s.solve()
    }
    ps.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag
  import scala.Console

  val MOD = 1000000007

  def solve(): Unit = {
    val N = ni()
    val A = na(N)

    def calc: Long = {
      var pre = 1e9.toInt
      var ans = 0L
      rep_r(N) { i =>
        val cur = i - A(i)
        if (cur > pre || cur < 0) return -1
        if (cur != pre) ans += A(i)
        pre = cur
      }
      ans
    }
    
    println(calc)
  }


  class InputReader(reader: BufferedReader) {
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(Console.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    rep(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    rep(n) { i =>
      rep(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    rep(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Int](as.length + 1)
    rep(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

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

#define all(s) s.begin(), s.end()
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second
#define bit(x, y) ((x >> y) & 1)
#define sz(s) ((int) (s).size())

int ans[2000][2000];

void solve(int x, int y, int u, int v) {
    if (u == 0 || v == 0) return;
    ans[x + (1 << (u - 1))][y + (1 << (v - 1))] = 1;
    solve(x, y, u - 1, v - 1);
    solve(x + (1 << (u - 1)), y, u - 1, v - 1);
    solve(x, y + (1 << (v - 1)), u - 1, v - 1);
    solve(x + (1 << (u - 1)), y + (1 << (v - 1)), u - 1, v - 1);
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); 
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    solve(0, 0, n, m);
    for (int i = 1; i < (1 << n); i++) {
        for (int j = 1; j < (1 << m); j++) {
            cout << ans[i][j];
        }
        cout << '\n';
    }
    return 0;
}

Measured memory_bytes: 9472
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
double x,y,q;
while(cin>>q){
if(q==-1)break;
x=q*0.5;
for(;;){
y=x*x*x-q;
if(fabs(y)<0.00001*q)break;
x-=y/(3*x*x);
}
printf("%.6f\n",x);
}
return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
int digit(int n) {
    if(n < 10) return 1;
    return 1 + digit(n / 10);
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int ans = 0;
    for(int i = 1; i <= N; i++) {
        if(digit(i) % 2 == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n;
	while(cin >> n , n){
		int dp[100000] = {0};
		int pos = 0;
		rep(i,n){
			int c; cin >> c;
			if((i+1)%2 == 1){ //odd
				if(dp[pos] == 0){
					if(c)dp[pos]++; else dp[pos]--;
					continue;
				}
				if(c == 1 && dp[pos] > 0){
					dp[pos]++;
				}else if(c == 0 && dp[pos] < 0){
					dp[pos]--;
				}else{
					pos++;
					if(c == 1)dp[pos]++;
					else dp[pos]--;
				}
			}else{
				if(c == 1 && dp[pos] > 0){
					dp[pos]++;
				}else if(c == 0 && dp[pos] < 0){
					dp[pos]--;
				}else{
					if(pos == 0){
						dp[pos] *= -1;
					}else{
						dp[pos-1] -= dp[pos];
						dp[pos] = 0;
						pos--;
					}
					if(c == 1) dp[pos]++;
					else dp[pos]--;
				}
			}
		}
		int sum = 0;
		rep(i,100000){
			if(dp[i] < 0)sum += dp[i];
		}
		cout << -sum << endl;
	}
}

Measured memory_bytes: 1256
<?php
$str = trim(fgets(STDIN));
$l = strlen($str);
$MOD = 10**9+7;
$equal[0] = 1;
$under[0] = 0;
for($i = 1; $i <= $l; $i++){
  if($str[$i-1] == 0){
    $equal[$i] = $equal[$i-1] % $MOD;
    $under[$i] = $under[$i-1] * 3 % $MOD;
  }else{
    $equal[$i] = $equal[$i-1] * 2 % $MOD;
    $under[$i] = ($under[$i-1] * 3 + $equal[$i-1]) % $MOD;
  }
}
echo ($equal[$l] + $under[$l]) % $MOD;


Measured memory_bytes: 14840
#coding: utf-8
#ALDS1_1A
import sys

n=int(raw_input())
a=map(int,raw_input().split())

for i in xrange(n):
  print a[i],
print
for i in xrange(1,n):
 v=a[i]
 j=i-1
 while j>=0 and a[j]>v:
  a[j+1]=a[j]
  j-=1
 a[j+1]=v
 for k in xrange(n):
  print a[k],
 print

Measured memory_bytes: 6340
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <utility>
using namespace std;

int main() {
	int N;
	cin >> N;
	long long T;
	cin >> T;
	long long ans=T;
	
	int pre;
	cin >> pre;
	
	int now=0;
	for(int i=1; i<N; i++){
		pre=now;
		cin >> now;
		
		if(now-pre <T){
			ans+=now-pre;
		}else{
			ans+=T;
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;
 
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
typedef long long int ll;
typedef long double ld;
const ll N = 1e5+9;
// const ll m = 1e9 + 7;
// const ll inf= 1e14;
const ll mod =998244353;
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define pld pair<ld,ld>
ll powm(ll a, ll b) { a = a%mod;ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
    #endif  
    int t = 1;
    // cin>>t;
    while(t--){
        string s;cin>>s;
        ll n = s.size();
        ll ct[26];
        memset(ct,0,sizeof(ct));
        for(int i = 0;i<n;i++){
            ct[s[i]-'a']++;
        }
        ll ans = (n*(n-1))/2;
        for(int i = 0;i<26;i++){
            ans-=((ct[i]*(ct[i]-1))/2);
        }
        cout<<ans+1<<'\n';
    }
}

Measured memory_bytes: 3724
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;

	
	public static void Main(string[] args)
	{
		var s = Console.ReadLine();
		var n = s.Length;
		long wa = 0;
		for(int bit = 0; bit < (1 << s.Length-1); bit++)
		{
			int l = 0;
			long tmp = 0;
			for(int i = 0; i < s.Length-1; i++)
			{
				if(((bit >> i) & 1) == 1)
				{
					string t = s.Substring(l,i-l+1);
					tmp += t.ToLong();
					l = i+1;
				}
			}
			
			string u = s.Substring(l,s.Length-l);
			tmp += u.ToLong();
			wa += tmp;
		}
		Console.WriteLine(wa);
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(a, b) for (int i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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(){
    int n;
    cin >> n;
    if(n%2==1){
        cout << n/2+1 << endl;
    }
    else{
        cout << n/2 << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int R, G, B, N; cin >> R >> G >> B >> N;
  int ans = 0;
  rep(i, N/R + 1) {
      rep(j, (N - i * R)/G + 1) {
          int k;
          if( (N - i*R - j*G) % B == 0) {
              k = (N - i*R - j*G) / B;
              ans ++;
          }
      }
  }
  cout << ans << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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; }

int main(){
  string s;
  cin >> s;
  if(s=="ABC"){
    print("ARC");
  }
  else{
    print("ABC");
  }
}

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

struct node{
  struct node *p;
  struct node *l;
  struct node *r;
  int key;
};

typedef struct node *Node;

Node Root = NULL;

void insert(int k){

  Node y = NULL;
  Node x = Root;
  Node new;

  new = malloc(sizeof(struct node));
  new->key = k;
  new->l = NULL;
  new->r = NULL;

  while(x != NULL){
    y = x;
    if(new->key < x->key) x = x->l;
    else x = x->r;
  }

  new->p = y;
  if(y == NULL) Root = new;
  else if(new->key < y->key) y->l = new;
  else y->r = new;
}

void inorder(Node v){
  if(v->l != NULL){
    inorder(v->l);
  }
  printf(" %d",v->key);
  if(v->r != NULL){
    inorder(v->r);
  }
}
void preorder(Node v){
  printf(" %d",v->key);
  if(v->l != NULL){
    preorder(v->l);
  }
  if(v->r != NULL){
    preorder(v->r);
  }
}

Node Find(Node v,int k){
  if(v == NULL || k == v->key) return v;
  else if(k < v->key) return Find(v->l,k);
  else return Find(v->r,k);
}

int main(void){
  int n,i,x;
  char in[10];
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",in);
    if (in[0] == 'f'){
      scanf("%d",&x);
      Node t = Find(Root,x);
      if(t != NULL) printf("yes\n");
      else printf("no\n");
    }
    else if (in[0] == 'i'){
      scanf("%d",&x);
      insert(x);
    }else if(in[0] == 'p'){
      inorder(Root);
      printf("\n");
      preorder(Root);
      printf("\n");
    }

  }
  return 0;
}

Measured memory_bytes: 19364
n = int(input())
nums = list(map(int, input().split()))

count = 0
for i in range(1, n - 1):
    if (nums[i - 1] < nums[i] < nums[i + 1]) or (nums[i + 1] < nums[i] <
                                                 nums[i - 1]):
        count += 1
print(count)

Measured memory_bytes: 38384
n,m = map(int,input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

ans = ['0'] * n
if n > 1:
    ans[0] = '1'
ok = True
rep = {}

for s, c in sc:
    ans[s-1] = str(c)
    if s in rep and rep[s] != c:
        ok = False
    rep[s] = c

if n > 1 and ans[0] == '0':
    ok = False

if ok:
    print("".join(ans))
else:
    print("-1")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007;//998244353;
bool dp[100001];
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n, k; cin >> n >> k;
   vector<int> a(n);
   rep(i,n)cin>>a[i];
   for (int i = 1; i <= k; i++){
      bool exist = false;
      for (auto &&ai : a){
         if ((i-ai) < 0)continue;
         if (dp[i-ai]==false)exist = true;
      }
      dp[i] = exist;
   }
   if(dp[k])cout << "First" << endl;
   else cout << "Second" << endl;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> tmp;
    vector<ll> tmp1;
    for(i = 2;i <= 1e5;++i){
        ll tmp2 = i*(i-1)/2;
        if(tmp2 > n){
            break;
        }
        tmp.push_back(i);
        tmp1.push_back(tmp2);
    }
    ll k = lower_bound(all(tmp1), n) - tmp1.begin();
    if(k == tmp1.size() || tmp1.at(k) != n){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    cout << tmp.at(k) << endl;
    ll b = tmp.at(k);
    vector<vector<ll>> ans(b);
    k = 1;
    for(i = 0;i < b-1;++i){
        for(j = i+1;j < b;++j){
            ans.at(i).push_back(k);
            ans.at(j).push_back(k);
            ++k;
        }
    }
    for(i = 0;i < ans.size();++i){
        cout << ans.at(i).size() << " ";
        rep(j, ans.at(i).size()-1){
            cout << ans.at(i).at(j) << " ";
        }
        cout << ans.at(i).at(j) << endl;
    }
    return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll x;
  cin >> x;
  ll ans=1;
  FOR(i,2,sqrt(x)+1){
    ll z=i;
    while(x>=z){
      ans=max(ans,z);
      z*=i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{   
    int a,b;
    char op;
    cin >> a >> op >> b;
    if(op == '+') cout << a + b << endl;
    else cout << a - b << endl;
    return 0;   
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define print(x) cout << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T> >
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

ll a, b, c, d;

ll gcd(ll _a, ll _b) { return _b ? gcd(_b, _a % _b) : _a; }
ll lcm(ll _a, ll _b) { return _a / gcd(_a, _b) * _b; }

ll f(ll x) {
  ll e = lcm(c, d);
  ll res = 0;
  res += x / c + x / d - x / e;
  return x-res;
}

int main() {
  cin >> a >> b >> c >> d;
  ll ans = f(b)-f(a-1);
  cout<<ans<<endl;
  return 0;
}

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

int main(int argc, char const *argv[])
{
    int k, x;
    cin >> k >> x;
    int first = x - k + 1;
    for (int i = 0; i < 2 * k -1; i++)
    {
        if(i == 0) {
            cout << first;
        } else {
            cout << " " << first + i;
        }
    }
    cout  << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n; cin >> n; int k; cin >> k;
	int sum = 0;
	for (int i = 0; i< n; i++) {
		int a; cin >> a;
		if (a >= k)
			++sum;
	}
	cout << sum << endl;
}

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

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;++i){
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    ll ans = 0;
    vector<int> v(1, a[0]+a[1]);
    priority_queue<int, vector<int>, greater<int>> que;
    que.push(a[0] + a[1]);
    for(int j=2;j<n;++j) {
        while(!que.empty() && que.top() <= a[j]) que.pop();
        ans += ll(que.size());

        for(int i=0;i<j;++i) {
            que.push(a[i]+a[j]);
        }
    }

    cout << ans << endl;
}


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

int main(){
 int a[5];
 int ans;
for(int i= 0;i<5;i++) cin >> a[i];
for(int i= 0;i<5;i++) {
    if(a[i]==0) ans = i+1;
 }
 cout << ans << endl;
 return 0;
}

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;


int main(){
  ll l,r;
  cin>>l>>r;
  ll tmp=r/2019;
  tmp=tmp*2019;
  int ans=2018;
  //cout<<l<<" "<<tmp;
  if(l<=tmp){
    cout<<0<<endl;
  }else{
    l=l%2019;
    r=r%2019;
    for(int i=l;i<r;i++){
      for(int j=i+1;j<=r;j++){
        tmp=(i*j)%2019;
        if(tmp<=ans){
          ans=tmp;
        }
      }
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 256
n,d=map(int,input().split())
x=[]

for _ in range(n):
    x.append(list(map(int,input().split())))

cnt=0

i=0
while i<n-1:
    j=i+1
    while j<n:
        temp=0
        for k in range(d):
            temp+=(x[i][k]-x[j][k])**2
        if temp==int(temp**(1/2))*int(temp**(1/2)):
            cnt+=1
        
        j+=1
    i+=1    

print(cnt)


Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
	int h, w;
	cin >> h >> w;
	string a[h];
	rep (i, h) cin >> a[i];

	int mp[26] = {};
	rep (i, h) rep (j, w) mp[a[i][j] - 'a']++;

	int cnt2 = 0, cnt4 = 0, cnt1 = 0;
	rep (i, 26) {
		if (mp[i] >= 4) {
			cnt4 += mp[i] / 4;
			mp[i] -= mp[i] / 4 * 4;
		}
		if (mp[i] >= 2) {
			cnt2 += mp[i] / 2;
			mp[i] -= mp[i] / 2 * 2;
		}
		if (mp[i] >= 1) cnt1++;
	}

	int need4 = (h / 2 * 2) * (w / 2 * 2);
	if (cnt4 * 4 >= need4 && cnt1 == (h % 2 && w % 2)) yn

	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]

use std::cmp::{max, min};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let (n, a, b): (i64, i64, i64) = input_three();
    let ans = (b - a) * (n - 2) + 1;
    println!("{}", max(0, ans));
}

pub fn input<T: FromStr>() -> Result<T, T::Err> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    Ok(buf.trim().parse().ok().unwrap())
}

pub fn input_vec<T: FromStr>() -> Result<Vec<T>, T::Err> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    Ok(buf
        .trim()
        .split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect::<Vec<_>>())
}

pub fn input_two<T: FromStr, U: FromStr>() -> (T, U) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
    )
}

pub fn input_three<T: FromStr, U: FromStr, V: FromStr>() -> (T, U, V) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
        s[2].parse::<V>().ok().unwrap(),
    )
}

pub fn input_four<T: FromStr, U: FromStr, V: FromStr, W: FromStr>() -> (T, U, V, W) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse().ok().unwrap(),
        s[1].parse().ok().unwrap(),
        s[2].parse().ok().unwrap(),
        s[3].parse().ok().unwrap(),
    )
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <string.h>

int map[10][10];

int min(int a,int b){return a<b?a:b;}

int cmp(int i,int j,int k){
  if(map[i][j]==-1){
    if(map[i][k]>=0 && map[k][j]>=0)
      return map[i][k]+map[k][j];
    else
      return -1;
  }else
    if(map[i][k]==-1 || map[k][j]==-1)
      return map[i][j];
    else
      return min(map[i][j],map[i][k]+map[k][j]);
}

int main(){
  int n;
  for(;scanf("%d",&n),n;){
    int m=0,i,j,k;
    memset(map,-1,sizeof(map));

    for(;n--;){
      int a,b,c;
      scanf("%d %d %d",&a,&b,&c);
      m=m>a?m:a;m=m>b?m:b;
      map[a][b] = map[b][a] = c;
    }

    for(i=0; i<=m; i++)
      map[i][i] = 0;

    for(k=0; k<=m; k++)
      for(i=0; i<=m; i++)
	for(j=0; j<=m; j++)
	  map[i][j] = cmp(i,j,k);

    int num,sum=-1;
    for(i=0; i<=m; i++){
      int tsum=0;
      for(j=0; j<=m; j++)
	tsum += map[i][j];
      if(sum==-1||tsum<sum){
	num=i; sum=tsum;
      }
    }

    printf("%d %d\n",num,sum);
  }
}

Measured memory_bytes: 0
//2017-11-7
//miaomiao
//
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
 
using namespace std;
 
#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define Forr(i, a, b) for(int i = (a); i >= (int)(b); --i)

#define N (100+5)

char s1[N], s2[N];

int main(){
	int n;
	scanf("%d%s%s", &n, s1+1, s2+1);
	
	int p;
	bool flag;

	Forr(len, n, 0){
		p = 0; flag = true;
		For(i, n-len+1, n){
			++p;
			if(s1[i] != s2[p]){flag = false; break;}
		}

		if(flag){
			printf("%d\n", 2*n-len); return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
// https://ei1333.github.io/luzhiled/
// http://beet-aizu.hatenablog.com/entry/2017/01/04/113233
// http://www.prefield.com/algorithm/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<ld>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
using Graph = vector<vector<ll>>;
const ll INF = 1LL << 60;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
const ll tl= 1000000007;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << endl;} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#define in1(A) REP(i,A.size()) in(A[i]);
#define in2(A,B) REP(i,A.size()) in(A[i],B[i]);
#define in3(s,t,u) REP(i,sz(s)){in(s[i] , t[i] , u[i]);}
#define in4(s,t,u,v) REP(i,sz(s)){in(s[i] , t[i] , u[i] , v[i]);}
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
struct Point{ ld x,y; };
ld dist(Point a, Point b){return sqrt(abs(a.x-b.x)*abs(a.x-b.x)+abs(a.y-b.y)*abs(a.y-b.y));} // ２点間の距離 
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;} 
ll fact(ll n){ if(n < 2) return 1; return (n * fact(n-1))%tl; } //階乗
inline ll updiv(ll a,ll b){ return (a + b - 1) / b; } //切り上げ
template<typename T,typename U>ll ceil(T a,U b){return (a + b - 1) / b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
//-------------------------------------------------------------------------------------------------
int main(){
    init();
    inl(n,m);
    vl A(m); in1(A); 
    ll sum= accumulate(all(A),0ll);

    out(((n-sum>=0)?n-sum:-1));
}

Measured memory_bytes: 3724