akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long k = in.nextLong();
            int n = 50;
            long[] a = new long[n];
            long r = (k + n - 1) / n;
            for (int i = 0; i < n; ++i) {
                a[i] = r + i;
            }
            int rem = (int) (r * n - k);
            for (int i = 0; i < rem; ++i) {
                a[i]--;
            }
            out.println(n);
            for (int i = 0; i < n; ++i) {
                out.print(a[i] + " ");
            }
            out.println();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



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


int main() {
	
	vector<int> a(3);
	for(auto &i : a) cin >> i;
	sort(a.begin(),a.end());
	int cnt = 0;
	cnt += (a.at(2) - a.at(0)) / 2;
	cnt += (a.at(2) - a.at(1)) / 2;
	a.at(0) += (a.at(2) - a.at(0)) /2 *2;
	a.at(1) += (a.at(2) - a.at(1)) /2 *2;
	int b = a.at(2) *2 - a.at(0) - a.at(1);
	if(b==0) cout << cnt << endl;  
	if(b==1) cout << cnt+2 << endl;  
	if(b==2) cout << cnt+1 << endl;  
	
	
}

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

using namespace std;

int SZ;

struct query {
  int l, r, id;

  query(int _l = 0, int _r = 0, int _id = 0) : l(_l), r(_r), id(_id) {}

  const bool operator < (const query& q) const {
    if (l / SZ != q.l / SZ) {
      return l < q.l;
    }
    return r < q.r;
  }
};

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

  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  unordered_map<int, int> pos;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    pos[a[i]] = -1;
  }
  vector<int> prv(n), nxt(n, n);
  for (int i = 0; i < n; ++i) {
    if (pos[a[i]] != -1) {
      nxt[pos[a[i]]] = i;
    }
    prv[i] = pos[a[i]];
    pos[a[i]] = i;
  }
  SZ = n / int(sqrt(q) + 1) + 1;
  vector<int> ans(q);
  vector<query> qr;
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    qr.emplace_back(l - 1, r - 1, i);
  }
  sort(qr.begin(), qr.end());
  int l = 0, r = 0, cur = 1;
  auto addLeft = [&]() {
    --l;
    if (nxt[l] > r) {
      ++cur;
    }
  };
  auto delLeft = [&]() {
    if (nxt[l] > r) {
      --cur;
    }
    ++l;
  };
  auto addRight = [&]() {
    ++r;
    if (prv[r] < l) {
      ++cur;
    }
  };
  auto delRight = [&]() {
    if (prv[r] < l) {
      --cur;
    }
    --r;
  };
  for (int i = 0; i < q; ++i) {
    while (l > qr[i].l) {
      addLeft();
    } while (r < qr[i].r) {
      addRight();
    } while (l < qr[i].l) {
      delLeft();
    } while (r > qr[i].r) {
      delRight();
    }
    ans[qr[i].id] = cur;
  }
  for (int i = 0; i < q; ++i) {
    cout << ans[i] << '\n';
  }

  return 0;
}

Measured memory_bytes: 40204
#include<stdio.h>
#define min(x,y) ((x<y)?x:y)
int main(){
	int a,b,c,d,e;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	printf("%d\n",min(a,min(b,c))+min(d,e)-50);
	return 0;
}

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


int main(){
    int n,k;
    cin >> n >> k;
    vector<int>p(n);
    for(int i=0;i<n;i++){
        cin >> p.at(i);
    }
    sort(p.begin(),p.end());
    int ans=0;
    for(int i=0;i<k;i++){
        ans+=p.at(i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#!/usr/bin/env python3

#import
#import math
#import numpy as np
#= int(input())
#= input()
N, P = map(int, input().split())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

array = factorization(P)

ans = 1
for a, n in array:
    if n >= N:
        ans *= a ** (n // N)

print(ans)

Measured memory_bytes: 9364
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.out

bool isPrime(int x){
    int i;
    if(x<2)return 0;
    else if(x==2)return 1;
    if(x%2==0)return 0;
    for(i=3;i*i<=x;i+=2)if(x%i==0)return 0;
    return 1;
}

int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    int a,d,n;
    while(1){
        cin>>a>>d>>n;
        if(a==0&&n==0)break;
        for(int i=a;;i+=d){
            if(isPrime(i)){
                n--;
                if(n==0){
                    cout<<i<<endl;
                    break;
                }
            }
        }
    }
    
//////////////////////////////////////////////////////
return 0;}


Measured memory_bytes: 3104
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class ARotation {
public:
	void solve(istream& in, ostream& out) {
        char c[2][3];
        rep(i,2) rep(j,3) in >> c[i][j];

        bool ok = true;
        rep(i,2) rep(j,3) {
            if(c[i][j] == c[1-i][2-j]) continue;
            else ok = false;
        }
        if(ok) out << "YES" << endl;
        else out << "NO" << endl;

	}

};

int main() {
	ARotation solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <sstream>
using namespace std;

bool comp(pair<int,string> a, pair<int,string> b) {
	if(a.first == b.first)
		return a.second < b.second;
	return a.first > b.first;
}

int main() {
	int n;
	while(cin >> n, n) {
		map<string, int> m;
		cin.ignore();
		for(int i = 0; i < n; i++) {
			string li;
			getline(cin, li);
			stringstream sstr(li);
			string s;
			while(sstr >> s) {
				m[s]++;
			}
		}
//		cin.ignore();
		vector<pair<int,string> > v;
		char k;
		cin >> k;
		for(map<string,int>::iterator it = m.begin(); it != m.end(); it++) {
			if(it->first[0] == k)
				v.push_back(pair<int,string>(it->second,it->first));
		}
		sort(v.begin(), v.end(), comp);
		for(int i = 0; i < min(5, (int)v.size()); i++)
			cout << (i==0 ? "" : " ") << v[i].second;
		if(v.size() == 0)
			cout << "NA";
		cout << endl;
	}
}

Measured memory_bytes: 1248
#include <iostream>

using namespace std;

int main() {
  int d,m;
  int rs=0;
  cin >> m >> d;
  for(int i=0;i<=d;i++){
    for(int j=0;j<=m;j++){
      if(i%10 >= 2 && i/10 >= 2){
        if((i%10)*(i/10) == j){
          rs++;
        }
      }
    }
  }

  cout<<rs<<'\n';



  return 0;
}


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

int main(){
  int h, w;
  cin >> h >> w;
  int s[h+1][w+1];
  string val;
  for ( int i = 0; i < h; i++){
    cin >> val;
    for ( int j = 0; j < w; j++){
      s[i][j] = val[j];
    }
  }

  bool flag = true;
  for ( int i = 0; i < h; i++){
    for ( int j = 0; j < w; j++){
      if ( s[i][j] == '.'){continue;}
      else {
        if ( s[i-1][j] == '.' && s[i+1][j] == '.'  && s[i][j-1] == '.' && s[i][j+1] == '.'){
          flag = false;
        }
      }
    }
  }

  if ( flag ){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mod 1000000007LL
#define eps 0.0001

#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ---------------------
    // コーディング開始
    // ---------------------
    string a;

    cin >> a ;
    string ans = "";

    for (int i=0;i<a.size();i++){
        for (int j=i+1;j<=a.size();j++){
            if(a[i]==a[j]) {
                a.erase(j, 1);
                break;
            } else if(j==a.size()){
                pri("No");
                return 0;
            }
        } 
    }
    pri("Yes");

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
const int N = 2e5 + 7, inf = 1e9 + 7;
int n, edc;
int head[N], L[N], R[N], mi[N][2], mx[N][2], g[N], has[N], cnt[N], fh[N];
LL ans;
char s[N];
struct edge { int lst, to;}e[N << 1];
void Add(int a, int b) {
	e[++edc] = (edge){ head[a], b}, head[a] = edc;
	e[++edc] = (edge){ head[b], a}, head[b] = edc;
}
void dfs1(int u, int fa) {
	mi[u][0] = mi[u][1] = inf;
	if(s[u] == '1') has[u] = 1, cnt[u] = 1;
	go(u) if(v ^ fa) {
		dfs1(v, u);
		has[u] |= has[v];
		cnt[u] += has[v];
		if(mx[v][0] + 1 < mi[u][0]) mi[u][1] = mi[u][0], mi[u][0] = mx[v][0] + 1;
		else Min(mi[u][1], mx[v][0] + 1);
		if(mx[v][0] + 1 > mx[u][0]) mx[u][1] = mx[u][0], mx[u][0] = mx[v][0] + 1;
		else Max(mx[u][1], mx[v][0] + 1);
	}
}
void dfs2(int u, int fa) {
	go(u) if(v ^ fa) {
		g[v] = max(g[u], mx[v][0] + 1 == mx[u][0] ? mx[u][1] : mx[u][0]) + 1;
		fh[v] = fh[u] | (has[v] ? cnt[u] > 1 : cnt[u] > 0);
		dfs2(v, u);
	}
//	if((g[u] - 1 <= mx[u][0] && fh[u]) || (mx[u][0] <= g[u] - 1 && has[u])) printf("%d\n", u);
	if(u != 1)
	ans += (g[u] - 1 <= mx[u][0] && fh[u]) || (mx[u][0] <= g[u] - 1 && has[u]);
	if(s[u] == '1') {
		ans += (g[u] >= mx[u][0] ? mx[u][0] : max(mx[u][1], g[u])) + 1;
	}else {
		int R = g[u] >= mx[u][0] ? mx[u][0] : max(mx[u][1], g[u]);
		int L = fh[u] ? g[u] : inf;
		go(u) if(v ^ fa && has[v]) Min(L, mx[v][0] + 1);
		if(L <= R)
		ans += R - L + 1;
	}
}
int main() {
#ifdef fwat
	freopen("data.in", "r", stdin);
	freopen("data.out", "w", stdout);
#endif
	n = gi();
	rep(i, 1, n - 1) Add(gi(), gi());
	scanf("%s", s + 1);
	dfs1(1, 0);
	dfs2(1, 0);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 23168
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  string a,b,c;
  cin>>a>>b>>c;
  cout<<a[0]<<b[1]<<c[2]<<endl;

  return 0;
}



Measured memory_bytes: 384
import itertools

N = int(input().strip())
L = [int(i) for i in input().strip().split(' ')]

cnt = 0
for i in itertools.combinations(L, r=3):
  i = sorted(i)
  if len(set(i)) == 3:
    if sum(i[:2]) > i[2]:
      cnt += 1

print(cnt)


Measured memory_bytes: 9108
from itertools import accumulate
n, k, *a = map(int, open(0).read().split())
acc = [0] + list(accumulate(a))
ps = [acc[j] - acc[i] for i in range(n) for j in range(i + 1, n + 1)]
ans = 0
for i in range(max(ps).bit_length(), -1, -1):
	x = ans + (1 << i)
	c = 0
	for y in ps:
		if y & x == x:
			c += 1
			if c >= k:
				ans = x
				break
print(ans)

Measured memory_bytes: 22984
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int D;
  cin>>D;
  VL C(26);
  rep(i,26) cin>>C[i];
  VVL S(D,VL(26));
  rep(i,D) rep(j,26) cin>>S[i][j];
  VL T(D);
  rep(i,D){
    ll X=0;
    rep(j,26) if(S[i][X]<S[i][j]) X=j;
    T[i]=X+1;
  }
  ll ans=0;
  VL L(26);
  rep(i,D){
    ll tmp=0;
    L[T[i]-1]=i+1;
    rep(j,26) tmp+=C[j]*(i+1-L[j]);
    ans+=S[i][T[i]-1]-tmp;
  }
  
  vector< set<ll> > X(26);
  rep(i,D) X[T[i]-1].insert(i+1);
  rep(i,26) X[i].insert(0);
  rep(i,26) X[i].insert(D+1);
  int M=100000;
  VI d(M),q(M);
  rep(i,M) d[i]=rand()%D+1;
  rep(i,M) q[i]=rand()%26+1;
  rep(i,M){
    ll ans2=ans;
    int prv=T[d[i]-1];
    int nxt=q[i];
    auto itr=ub(all(X[prv-1]),d[i]);
    ll tmp=*itr;
    itr--;
    itr--;
    T[d[i]-1]=q[i];
    auto itr2=ub(all(X[nxt-1]),d[i]);
    ll tmp2=*itr2;
    itr2--;
    ans=ans-S[d[i]-1][prv-1]-C[prv-1]*(d[i]-*itr)*(tmp-d[i]);
    X[prv-1].erase(d[i]);
    ans=ans+S[d[i]-1][nxt-1]+C[nxt-1]*(d[i]-*itr2)*(tmp2-d[i]);
    X[nxt-1].insert(d[i]);
    if(ans<ans2){
      T[d[i]-1]=prv;
      X[prv-1].insert(d[i]);
      X[nxt-1].erase(d[i]);
      ans=ans2;
    }
  }
  rep(i,D) cout<<T[i]<<endl;
}


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

int main()
{
	ll n,m;
    cin>>n;
    
    if(n>=400 && n<=599)
    {
       m=8; 
    }
   else if(n>=600 && n<=799)
   {
       m=7;
   }
  
    else if(n>=800 && n<=999)
    {
        m=6;
    }
    else if(n>=1000 && n<=1199)
    {
       m=5; 
    }
   else if(n>=1200 && n<=1399)
   {
       m=4;
   }
   else if(n>=1400 && n<=1599)
   {
       m=3;
   }
   else if(n>=1600 && n<=1799)
   {
       m=2;
   }
  else if(n>=1800 && n<=1999)
  {
      m=1;
  }
    
    cout<<m;

	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x,y,n;cin >>n;
  vector<long double> a(n);
  vector<long double> b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cin >> b[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  if(n%2==1){
    x=a[n/2];
    y=b[n/2];    
  }else{
    x=(a[n/2]+a[n/2-1]);
    y=(b[n/2]+b[n/2-1]);
  }

    cout<< y-x+1 <<endl;
}

Measured memory_bytes: 9564
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

 

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

  bool jud = false;
  if (a == b){
    jud = true;

  }else
  if (a == c){
    jud = true;
  }else
  if (b == c){
    jud = true;
  }
  if (a == b && b == c && c == a){
    jud = false;

  }


  if (jud == true){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
return 0;
}

Measured memory_bytes: 256
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;

class Program
{
    static void Main(string[] args)
    {
        string n = Console.ReadLine();
        int len = n.Length;
        int sum = 0;
        for(int i = 0; i < len; i++)
        {
            sum += (n[i] - '0');
        }
        if(int.Parse(n) % sum == 0)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}


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

int main(){
    int N;cin>>N;
    vector<int> lst(N,0);
    rep(i,N)cin>>lst[i];
    
    rep(i,N){
        if(lst[i] % 2 == 0){
            if(lst[i] % 3 !=0 && lst[i] % 5 != 0){
                cout<<"DENIED"<<endl;
                return 0;
            }
        }
    }
    cout<<"APPROVED"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <stdint.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
using namespace std;
 
#define int long long
 
 
int gcd(int a, int b){
	
	if(a==0){
		return b;
	}
	
	return gcd(b%a,a);
	
}
 
 int lcm(int a, int b)  
 {  
    return (a*b)/gcd(a, b);  
 }  
 
 
int f(int x){
	
	
	int res = 0;
	
	while( x%2 == 0){
		
		x/=2;
		res++;
	}
	
	return res;
	
}
 
 
int32_t main() {
 
 	int a,b;
 	
 	cin >> a >> b;
 	
  
 
 	cout << lcm(a,b) << endl;
 	
 	
 
 
  
}
 
 
 

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

int main(){
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int l = (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
    int x3, y3, x4, y4;

    for(int x=-300;x<=300;x++){
        for(int y=-300;y<=300;y++){
            int l1 = (x-x1)*(x-x1)+(y-y1)*(y-y1);
            int l2 = (x-x2)*(x-x2)+(y-y2)*(y-y2);
            if(l1==2*l && l2==l){
                //cout << "(x3, y3) : " << x << ", " << y << endl;
                int r = (x1 - x2) * (y - y2) - (y1 - y2) * (x - x2);
                if(r < 0){
                    x3 = x;
                    y3 = y;
                }
            }
            if(l1==l && l2==2*l){
                //cout << "(x4, y4) : " << x << ", " << y << endl;
                int r = (x2 - x1) * (y - y1) - (y2 - y1) * (x - x1);
                if(r > 0){
                    x4 = x;
                    y4 = y;
                }
            }
        }
    }
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
W = [int(_) for _ in input().split()]
ans = 1e10
for i in range(0, N - 1):
    a, b = 0, 0
    for j in range(i + 1):
        a += W[j]
    for j in range(i + 1, N):
        b += W[j]
    ans = min(ans, abs(a - b))
print(ans)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_20190707_1
{    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());

            string OK = "No";

            for(int i = 1; i < 10; i++)
            {
                if(N % i == 0 && N / i < 10)
                {
                    OK = "Yes";
                }
            }

            Console.WriteLine(OK);
        }
    }
}

Measured memory_bytes: 27412
import copy

N = int(input())

A = [0] * N
maxv = 0
maxvi = 0
for i in range(N):
    A[i] = int(input())
    if A[i] > maxv:
        maxv = A[i]
        maxvi = i

B = copy.deepcopy(A)
B.pop(maxvi)

max_v1 = max(A)
max_v2 = max(B)

for i in range(N):
    if A[i] != max_v1:
        print(max_v1)
    else:
        print(max_v2)

Measured memory_bytes: 14560
def putpiece(bitmap,unused,pieces,numans,pcsans,FINFLAG):
    # print(bin(bitmap))
    # print(unused,"***",pieces,"***",numans)
    if FINFLAG:
        return numans,pcsans
    if not unused:
        pcsans = pieces
        return numans + 1, pcsans
    if numans > 1:
        return 2, pieces
    b,k,y,x = unused[-1]
    # print(set([ (k//i,k//(k//i)) for i in range(1,min(X+1,k+1))]))
    for h,w in set([ (k//i,k//(k//i)) for i in range(1,min(X+1,k+1)) if not (k//i)*(k//(k//i)) - k]):
        for pt,qt in product(range(max(0,y-h+1),min(Y-h+1,y+1)),range(max(0,x-w+1),min(X-w+1,x+1))):
            rt,st = pt+h-1, qt+w-1
            piece = 0
            piece2 = 0
            for i in range(st-qt+1): piece |= 1 << i
            for j in range(rt-pt+1): piece2 |= piece << j*X
            piece = piece2
            piece = piece << X-st-1
            piece = piece << (Y-rt-1)*X
            mark = 1
            mark = mark << X-x-1
            mark = mark << (Y-y-1)*X
            if not (bitmap&piece)^mark: numans,pcsans = putpiece(bitmap|piece,unused[:-1],pieces+[[b,k,pt,qt,rt,st]],numans,pcsans,False)
            if numans > 1: return 2, pcsans
        if numans > 1: return 2, pcsans
    else:
        return numans,pcsans


from itertools import product
while(True):
    numans = 0
    pcsans = []
    X,Y,n = map(int,input().split())
    if not X: break
    bk = sorted([list(map(int,input().split())) for _ in range(n)])
    ss = [list(map(int,input().split())) for _ in range(Y)]
    yxs = sorted([ss[i][j],i,j] for i,j in product(range(Y),range(X)) if ss[i][j])
    bkyx = [ bk[i]+yxs[i][1:] for i in range(n)]
    # from pprint import pprint
    # pprint(bk)
    # pprint(ss)
    filled = "".join([ "".join(["1" if ss[i][j] else "0" for j in range(X)]) for i in range(Y)])
    # pprint(filled)
    # pprint([filled[i*X:i*X+X] for i in range(Y)])
    # pprint(bkyx)
    nans,pcs = putpiece(int(filled,2),bkyx,[],0,0,False)
    # print(nans,pcs)
    if nans > 1:
        print("NA")
    elif nans:
        toprint = [[0]*X for _ in range(Y)]
        for i,m,sy,sx,ey,ex in pcs:
            for j in range(sy,ey+1): toprint[j][sx:ex+1] = [i]*(ex-sx+1)
        for a in toprint: print(" ".join(str(b) for b in a))
    else:
        print("NA")
    # print("***********************************::")
    # break


# numans = 0
# mapans = []

# bitmap,[[b1,k1,x1,y1]],[[p,q,r,s]]


# if not len([]):
#  numans += 0
#  mapans = p,q,r,s
#  return None

# pt,qt,rt,st

# if not bitmap & bitpiece
#  bitmap |= bitpeace
#  putpiece(bitmap|bitpiece,[][:-1],[]+[pt,qt,rt,st])
 



Measured memory_bytes: 5712
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define endl '\n'


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

	int x, n, p;
	cin >> x >> n;
	vector<int> v;
	while (n--)
	{
		cin >> p;
		v.push_back(p);
	}
	int l = x, r = x, ansL = (-2147483647 - 1), ansR = (-2147483647 - 1);
	bool found = false;
	while (!found)
	{
		if (find(v.begin(), v.end(), l) == v.end())
		{
			found = true;
			ansL = l;
		}
		if (find(v.begin(), v.end(), r) == v.end())
		{
			found = true;
			ansR = r;
		}
		l--;
		r++;
	}
	if (ansL == (-2147483647 - 1))
		cout << ansR << endl;
	else
		cout << ansL << endl;

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

Measured memory_bytes: 3660
import math

def prime(x):
    limit = math.floor(math.sqrt(x))+1
    for divisor in range(2, limit):
        if x % divisor == 0:
            return False
    return True

x = int(input())
inf = 10**6

for i in range(x, inf):
    if prime(i):
        print(i)
        exit(0)


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

int main() {
	long long  n,i,sum, mi,ma,a;
	mi = 1000000;
	ma = -1000000;

	cin >> n;

	sum = 0;

	for (i = 0; i < n; i++) {
		cin >> a;
		sum += a;

		ma = max(ma, a);
		mi = min(mi, a);
		}
	cout << mi << " " << ma << " " << sum << endl;
	}
	

Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int A, B, C;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> A >> B >> C;
	int ans = C - min(A - B, C);
	cout << ans << endl;
}







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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;

const int INF = 1001001001;

int main() {

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

    cout << max(0, c - (a - b)) << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
 
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
 
using namespace std;
 
typedef long long ll;

ll f(ll x){
  if (x%4 == 0)
  {
   return x; 
  }
  else if (x%2 == 0){
    return x+1;
  }
  else if (x%4 == 1){
      return 1;
  }
  return 0;
}

int main(int argc, char const *argv[])
{
  ll a,b,ans;
  cin >> a >> b;
  cout << (f(b)^f(a-1)) << endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
using namespace std;


int main(void)
{
	int H, W; cin >> H >> W;
	vector<string> C(H);
	rep(i, 0, H)cin >> C[i];
	rep(i, 0, 2 * H) {
		rep(j, 0, W) {
			cout << C[i / 2][j];
		}
		cout << endl;
	}

	return 0;
}

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

#define pr(s) std::cout << s << std::endl

#define prb(s) std::cout << s

using namespace std;





int main() {

  cin.tie(0);

  ios::sync_with_stdio(false);





  char b;

  cin >>  b;



  if (b == 'A') pr("T");

  if (b == 'C') pr("G");

  if (b == 'G') pr("C");

  if (b == 'T') pr("A");



  return 0;

}



Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    char c; cin >> c;
    cout << (char)(c + 1) << endl;
    return 0;
}

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

using namespace std;

int main() {
	int n, x; cin >> n >> x;
	if(x == 1 or x == 2*n-1) {
		cout << "No" << endl;
	}
	else {
		if(n==2) {
			cout << "Yes" << endl;
			cout << 1 << endl;
			cout << 2 << endl;
			cout << 3 << endl;
		}
		else {
			cout << "Yes" << endl;
			vector<int> out;
			if(x+2>2*n-1) {
				out = {x-2, x+1, x, x-1};
			}
			else {
				out = {x+2, x-1, x, x+1};
			}

			int idx = 1;
			int i = 1;

			while(idx <= 2*n-1) {

				if(idx == n-2) {
					for(int o:out) {
						cout << o << endl;
					}
					idx += 4;
					continue;
				}
				else {
					while(find(out.begin(), out.end(), i) != out.end()) {
						i++;
					}
					cout << i << endl;
					i++;
				}

				idx++;
			}
		}
	}

	return 0;
}


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

int main(void){
    int n,i,cnt_ac,cnt_wa,cnt_tle,cnt_re;
    cnt_ac = 0;
    cnt_re = 0;
    cnt_tle = 0;
    cnt_wa = 0;

    cin >> n;

    vector<string> s(n);
    for(i=0; i<n; i++){
        cin >> s.at(i);
        if(s.at(i) == "AC"){
            cnt_ac++;
        }else if(s.at(i) == "RE"){
            cnt_re++;
        }else if(s.at(i) == "TLE"){
            cnt_tle++;
        }else if(s.at(i) == "WA"){
            cnt_wa++;
        }
    }

    cout << "AC x " << cnt_ac << endl;
    cout << "WA x " << cnt_wa << endl;
    cout << "TLE x " << cnt_tle << endl;
    cout << "RE x " << cnt_re << endl;

    return 0;
}

Measured memory_bytes: 6400
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;

int main(){
  string b;
  cin >> b;
  if(b == "A") cout << "T" <<endl;
  else if(b == "T") cout << "A" << endl;
  else if(b == "G") cout << "C" << endl;
  else cout << "G" <<endl;

  return 0;
}

Measured memory_bytes: 384
N = int(input())
S = input()

tmp = 0

for s in S[1:]:
    if s == 'E':
        tmp += 1
  

minimum = tmp

for i in range(1, N):
    if S[i-1] == 'W':
        tmp += 1
    if S[i] == 'E':
        tmp -= 1
    minimum = min(tmp, minimum)

print(minimum)


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define rep(i, l, r) for(int i = (l); i <= (r); i++)
#define per(i, r, l) for(int i = (r); i >= (l); i--)
#define mem(a, b) memset(a, b, sizeof a)

using namespace std;

int k;
int main() {
	for(cin >> k; k--; cout << "ACL");
	return 0;
}

Measured memory_bytes: 3624
(let* ((n (read))
       (a (make-array n))
       (one 0)
       (four 0)
       (two 0))
  (dotimes (i n)
    (let ((ai (read)))
      (if (zerop (mod ai 4))
          (incf four)
          (if (zerop (mod ai 2))
              (incf two)
              (incf one)))
      (setf (aref a i) ai)))
  (format t "~A~%"
          (if (zerop two)
              (if (<= one (1+ four)) "Yes" "No")
              (if (<= one four) "Yes" "No"))))

Measured memory_bytes: 57704
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  long min = 2147483646;
  cin >> N;
  vector<int>X(N);
  for (int i=0; i<N; i++) cin >> X[i];
  for (int P=1; P<=100; P++){
    long sum = 0;
    for (int i=0; i<N; i++){
      sum += (X[i]-P)*(X[i]-P);
    }
    if (sum < min) min = sum;
    else break;
  }
  cout << min << endl;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        n:i64,
        k:i64,
        q:i64,
        aq:[i64;q],
    }
    let mut map = HashMap::new();
    for &a in &aq {
        *map.entry(a).or_insert(0) += 1;
    }
    for i in 1..n+1 {
        let ans = match map.get(&i) {
            Some(v) => if (k+v-q) <= 0 {"No"} else {"Yes"},
            None => if (k-q) <= 0 {"No"} else {"Yes"},
        };
        println!("{}",ans);
    }
}


fn is_prime(x:i64) -> bool {
    if x == 2 {return true;}
    if x < 2 || x % 2 == 0 {return false;}
    let mut j = 3;
    while j <= (x as f64).sqrt() as i64 {
        if x % j == 0 {
            return false;
        }
        j += 2;
    }
    true
}


Measured memory_bytes: 12540
import sys
import math
n=int(input())
if n<=1000:
    print(1000-n)
elif n<=2000:
    print(2000-n)
elif n<=3000:
    print(3000-n)
elif n<=4000:
    print(4000-n)
elif n<=5000:
    print(5000-n)
elif n<=6000:
    print(6000-n)
elif n<=7000:
    print(7000-n)
elif n<=8000:
    print(8000-n)
elif n<=9000:
    print(9000-n)
else:
    print(10000-n)

Measured memory_bytes: 9184
INF = 10 ** 9 + 7

n = gets.to_i
top = [INF, -1]
btm = [-1, INF]
n.times do |_|
  a, b = gets.chomp.split.map(&:to_i)
  if a < top[0]
    top = [a, b]
  end
  if a > btm[0]
    btm = [a, b]
  end
end
puts btm[1] + (btm[0] - top[0] + 1) + (top[0] - 1)

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    int n;cin >>n;
    vector<pair<string,int>>a(n);
    vector<pair<string,int>>b(n);
    for (int i = 0; i < n; ++i) {
        string s;cin >>s;
        int p;cin >>p;
        a[i]={s,-p};
        b[i]={s,-p};
    }
    sort(all(a));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if(a[i]==b[j]){
                cout <<j+1<<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3600
a = int(input())
b = list(map(int,input().split()))
A = []


def selectionSort(b,a):
    count = 0
    for i in range(len(b)-1):
        mini = i
        for j in range(i+1,len(b)):
            if b[mini]>b[j]:
                mini = j
        if b[mini]!=b[i]:
            b[i],b[mini]=b[mini],b[i]
            count += 1
    return b,count

A,B = selectionSort(b,a)
print(*A)
print(B)


Measured memory_bytes: 5604
MOD = 10**9 + 7
N = int(input())
X = list(map(int, input().split()))
D = [dj - di for di, dj in zip(X, X[1:])]

def power(n, r, mod=10**9+7):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def framod(n, a=1, mod=10**9+7):
    for i in range(1,n+1):
        a = a * i % mod
    return a

count_d = []
frac_Nm1 = framod(N-1)
for i in range(1, N):
  count_d.append(frac_Nm1 * power(i, MOD-2) % MOD)

for i in range(1, N-1):
  count_d[i] += count_d[i-1]


ans = sum([d*c % MOD for d, c in zip(D, count_d)]) % MOD
print(ans)

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

using namespace std;

int N;
int DataInfo[100000];
int User[100000];

int solve() {
	int curPos, tmp, sum;

	sum = 0;
	for (int i = 0; i < N; ++i) {
		if (User[i] != 0) {
			continue;
		}
		curPos = i;
		while (User[curPos] == 0) {
			User[curPos] = i + 1;
			curPos = (curPos + DataInfo[curPos]) % N;
		}
		if (User[curPos] != i + 1) {
			continue;
		}
		tmp = curPos;
		do {
			++sum;
			curPos = (curPos + DataInfo[curPos]) % N;
		} while (curPos != tmp);
	}

	return sum;
}

int main() {
	
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> DataInfo[i];
	}
	cout << solve() << endl;

	return 0;
}


Measured memory_bytes: 3860
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

n,m,k = map(int,input().split())
nm = n*m%(10**9+7)
k = k%(10**9+7)
a = (cmb(nm-2,k-2,mod)%(10**9+7))*(nm*(m*(n**2-1)+n*(m**2-1)))//6
print(a%(10**9+7))

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll n;
  cin >> n;

  ll ans = 0;
  vll a(n);
  REP(i, n){
    cin >> a[i];
    if(i == 0){
      if(a[i] != 0){
        cout << -1 << endl;
        return 0;
      }
      else
        continue;
    }

    if(a[i] > i || a[i] - a[i-1] >= 2){
      cout << -1 << endl;
      return 0;
    }
    if(a[i-1] +1 == a[i])
      ans += 1;
    else
      ans += a[i];
  }
  

  cout << ans << endl;

  
}


Measured memory_bytes: 1792
def koch_curve(point1, point2, N):
    if N == 0:
        print('{:8f} {:8f}'.format(point1[0], point1[1]))
        return
    pointS = ((2 * point1[0] + point2[0]) / 3,
              (2 * point1[1] + point2[1]) / 3)
    pointT = ((point2[0] - point1[0]) / 2 - (point2[1] - point1[1]) / 3.46410161514 + point1[0],
              (point2[0] - point1[0]) / 3.46410161514 + (point2[1] - point1[1]) / 2 + point1[1])
    pointU = ((point1[0] + 2 * point2[0]) / 3,
              (point1[1] + 2 * point2[1]) / 3)
    if N > 1:
        koch_curve(point1, pointS, N - 1)
        koch_curve(pointS, pointT, N - 1)
        koch_curve(pointT, pointU, N - 1)
        koch_curve(pointU, point2, N - 1)
    else:
        print('{:8f} {:8f}'.format(point1[0], point1[1]))
        print('{:8f} {:8f}'.format(pointS[0], pointS[1]))
        print('{:8f} {:8f}'.format(pointT[0], pointT[1]))
        print('{:8f} {:8f}'.format(pointU[0], pointU[1]))


N = int(input())
koch_curve((0.0, 0.0), (100.0, 0.0), N)
print('100.00000000 0.00000000')


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

struct data {
  int x, y, id, cnt;
};

long long h, w, n;
int d[4] = {1, 0, -1, 0};
vector<string> r;
string s;
queue<data> qu;
bool memo[55][55][1005] = {0};

bool isvalid(const data &now) {
  return now.x >= 0 && now.x < h && now.y >= 0 && now.y < w;
}

long long solve();

int main() {
  while(1) {
    cin >> h >> w;
    if(h + w == 0) break;
    r.resize(h);
    for(int i = 0; i < h; ++i) cin >> r[i];
    cin >> s;
    n = s.size();
    cout << solve() << endl;
  }
  return 0;
}

long long solve() {
  while(!qu.empty()) qu.pop();
  for(int i = 0; i < h; ++i)
    for(int j = 0; j < w; ++j)
      for(int k = 0; k <= n; ++k) memo[i][j][k] = 0;
  qu.push({0, 0, 0, 0});
  while(!qu.empty()) {
    data now = qu.front();
    qu.pop();
    ++now.cnt;
    if(r[now.x][now.y] == s[now.id]) {
      ++now.id;
      memo[now.x][now.y][now.id] = 1;
      if(now.id == n) return now.cnt;
      qu.push(now);
      continue;
    }
    for(int i = 0; i < 4; ++i) {
      data nextp = now;
      nextp.x += d[i];
      nextp.y += d[i ^ 1];
      if(isvalid(nextp) &&
         !memo[nextp.x][nextp.y][nextp.id]) {
        memo[nextp.x][nextp.y][nextp.id] = 1;
        qu.push(nextp);
      }
    }
  }
  return -1;
}


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

int main()
{  
   int d;
   cin>>d;
   if(d==25) cout<<"Christmas"<<endl;
   else if(d==24) cout<<"Christmas Eve"<<endl;
   else if(d==23) cout<<"Christmas Eve Eve"<<endl;
   else if(d==22) cout<<"Christmas Eve Eve Eve"<<endl;
   
}

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

using namespace std;

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

void suffix_array(string s,int *sa){
	int n=s.size();
	vector<int> rank(n+1,0),tmp(n+1,0);
	rep(i,n+1) sa[i]=i,rank[i]=(i<n?s[i]:-1);

	for(int k=1;k<=n;k<<=1){
		auto cmp=[&](int i,int j){
			if(rank[i]!=rank[j]) return rank[i]<rank[j];
			int ci=(i+k<=n)?rank[i+k]:-1;
			int cj=(j+k<=n)?rank[j+k]:-1;
			return ci<cj;
		};
		sort(sa,sa+n+1,cmp);
		tmp[sa[0]]=0;
		rep(i,n) tmp[sa[i+1]]=tmp[sa[i]]+cmp(sa[i],sa[i+1]);
		rep(i,n+1) rank[i]=tmp[i];
	}
	return;
}

const int nmax=250010;
int sa[nmax],len[nmax];
string s;

int sprase_table[2][nmax][20];

void init(int *a,int n){
	int logn=31-__builtin_clz(n);
	rep(i,n) sprase_table[0][i][0]=sprase_table[1][i][0]=a[i];
	rep(k,logn)rep(i,n+1-(1<<k)){
		sprase_table[0][i][k+1]=min(sprase_table[0][i][k],sprase_table[0][i+(1<<k)][k]);
		sprase_table[1][i][k+1]=max(sprase_table[1][i][k],sprase_table[1][i+(1<<k)][k]);
	}
	return ;
}

int query(int l,int r,int type){
	int i=31-__builtin_clz(r-l);
	if(type==0)
		return min(sprase_table[0][l][i],sprase_table[0][r-(1<<i)][i]);
	else
		return max(sprase_table[1][l][i],sprase_table[1][r-(1<<i)][i]);
}

int b_search(string x,int type,int n){
	int from,to,l,r;

	l=0,r=n;
	while(r-l>1){
		int m=(l+r)/2;
		if(s.substr(sa[m],x.size())<x)
			l=m;
		else
			r=m;
	}

	if(s.substr(sa[r],x.size())!=x) return -1;
	from=r;

	l=1,r=n+1;
	while(r-l>1){
		int m=(l+r)/2;
		if(s.substr(sa[m],x.size())<=x)
			l=m;
		else
			r=m;
	}
	if(s.substr(sa[l],x.size())!=x) return -1;
	to=l;
	if(from>to) return -1;
	return query(from,to+1,type);
}

int main(void){
	cin >> s;
	int n=s.size();
	suffix_array(s,sa);
	rep(i,n+1) len[i]=s.substr(sa[i]).size();
	init(len,n+1);

	int m;
	cin >> m;
	rep(loop,m){
		string x,y;
		cin >> x >> y;
		int from=b_search(x,1,n),to=b_search(y,0,n);
		int ans=0;
		if(from!=-1&&to!=-1&&(from-x.size())>=to-y.size()) ans=from-to+y.size();
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 38612
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <bitset>
#include<iomanip>//小数点以下を精度良く表示
#include <map>
#include<set>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2000000000
#define INF2 1000000000000000000
#define PI 3.1415926535
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> P;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

#define MAX_N 50005//ここにNの最大値を入れる
#define MAX_K 100005



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 ans[200005];
int main() {
    int n, m;
    cin >> n >> m;
    Graph G(n+1);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    rep(i, n) ans[i] = INF;
    
    
    queue<int> q;
    q.push(0);
    ans[0] = 0;
    while (!q.empty()) {
        int v = q.front();
        q.pop();

        for (auto nv : G[v]) {
            if (ans[nv] == INF) {
                q.push(nv);
                ans[nv] = v;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (ans[i] == INF) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for (int i = 1; i < n; i++) {
        cout << ++ans[i] << endl;
    }
    return 0;

}

Measured memory_bytes: 10328
#include<stdio.h>
int main(void){
	int a[100][100],b,i,j,k,m,n[100],l,x[100],r,f;
	char d;
	
	for(i=0;i<100;++i){
		n[i]=0;
		x[i]=0;
	}
	for(i=0;;++i){
		scanf("%d %d",&n[i],&x[i]);
		if(x[i]==0 && n[i]==0)break;
	}
	l=i;
	for(i=0;i<l;++i){
		for(j=0;j<n[i];++j)a[i][j]=j+1;
	}
	for(m=0;m<l;++m){
		for(i=0,r=0;i<n[m];++i){
			for(j=i+1;j<n[m];++j){
				for(k=j+1;k<n[m];++k){
					if(a[m][i]+a[m][j]+a[m][k]==x[m])r=r+1;
				}
			}
		}printf("%d\n",r);
	}

	return 0;
}

Measured memory_bytes: 620
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    vector<ll> V(3);
    cin >> V[0] >> V[1] >> V[2];
    sort(V.begin(), V.end());
    if(V[0] % 2 && V[1] % 2 && V[2] % 2){
        cout << V[0] * V[1] << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
T1, T2 = list(map(int, input().split()))
A1, A2 = list(map(int, input().split()))
B1, B2 = list(map(int, input().split()))

a = (A1-B1)*T1
b = (A2-B2)*T2

if a<0:
  a,b = -a,-b
  
#print(a,b)
  
if a+b>0:
  print(0)

elif a+b ==0:
  print('infinity')

elif a+b<0:
  #print(a//(-b-a),a%(-b-a))
  print(2 *(a//(-b-a)) + bool(a%(-b-a)))
  

Measured memory_bytes: 3064