akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;


int main() {
	int P;
	cin >> P;
	vector<int>Ans(P);
	for (int i = 0; i < P; ++i) {
		int num;
		cin >> num;
		if (1 == num) {
			Ans[P - 1]+=1;
			int memo = 1;
			for (int j = 0; j < P; ++j) {
				Ans[j] -= memo;
				Ans[j] += P;
				Ans[j] %= P;
				memo *= i;
				memo %= P;
			}
		}
	}
	for (int i = 0; i < P; ++i) {
		if (0 != i) {
			cout << " ";
		}
		cout << Ans[P - 1 - i];
	}
	return 0;
}

Measured memory_bytes: 3604
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(string, N);
    ll K = N.size();
    vvi dp(K + 1, vi(2));
    dp[0][1] = 1;
    REP1(i, K)
    {
        ll x = N[i - 1] - '0';
        dp[i][0] = min(dp[i - 1][0] + x, dp[i - 1][1] + 10 - x);
        dp[i][1] = min(dp[i - 1][0] + x + 1, dp[i - 1][1] + 9 - x);
    }
    OUT(dp[K][0]);
}


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

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	bool st = true;
	for(int i = 0;i<n/2;i++)
	{
		if(s[i]!=s[n-i-1])st = false;
	}
	string t = s.substr(0,(n)/2);
	
	 n = t.size();
	for(int i = 0;i<n/2;i++)
	{
		if(t[i]!=t[n-i-1])st = false;
	}
	t = s.substr((s.size()+1)/2,s.size());
	for(int i = 0;i<n/2;i++)
	{
		if(t[i]!=t[n-i-1])st = false;
	}
	if(st)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import math

def make_divisors(n):
  divisors = []
  for i in range(1, int(math.sqrt(n))+1):
    if n % i == 0:
      x = i
      y = n // i
      divisors.append([x, y])

  return divisors

def list_sum(t_list):
  return t_list[0] + t_list[1]

n = int(input())
yakusu = make_divisors(n)

data = list(map(list_sum, yakusu))
print(min(data) - 2)


Measured memory_bytes: 3720
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
MOD = 10**9 + 7

fact = [1]

for i in range(1, 110000):
    fact.append(fact[-1] * i % MOD)

def rev(x):
    return pow(x, MOD-2, MOD)
    
def c(i, k):
    if(i < k):return 0
    return fact[i] * rev(fact[k]) * rev(fact[i-k]) % MOD

def calc():
    result = 0
    for i in range(n):
        result += a[i] * c(i, k-1)
        result %= MOD
    return result

ans = calc()
a = a[::-1]

ans -= calc()
ans %= MOD
if ans < 0:ans += MOD

print(ans)

Measured memory_bytes: 14416
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define int int64_t
#define pcnt __builtin_popcount
#define pb push_back
#define ALL(x) (x).begin(),(x).end()
#define vec vector<int>
#define mat vector<vector<int>> //mat データ名(縦,vec(横));
int64_t INF = 1000000000000000001; //10^18+1
int MOD = 1000000007; //10^9+7
//cout << fixed << setprecision(15); (小数点以下表示)


void next(vec &A,int M,int i){
  if(A[i]>=M){
    next(A,M,i-1);
    int siz=A.size();
    for(int j=i;j<siz;j++){
      if(j>0){
        A[j]=A[j-1];
      }else{
        A[0]++;
      }
    }
  }else{
    A[i]++;
  }
}

signed main () {
  int A,B,N,ans;
  cin >> A >> B >> N;
  if(N>=B-1){
    ans=B-1;
  }else{
    ans=N;
  }
  cout << (A*ans/B)-A*(ans/B) << endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 40) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    vector<string> c(h);
    auto l = make_v<int>(h, w);
    auto r = make_v<int>(h, w);
    auto u = make_v<int>(h, w);
    auto d = make_v<int>(h, w);
    for(int i = 0; i < h; i++) {
        cin >> c[i];
    }
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(c[i][j] == '#') {
                l[i][j] = 0;
            } else {
                if(j > 0) {
                    l[i][j] = l[i][j - 1] + 1;
                } else {
                    l[i][j] = 1;
                }
            }
        }
    }
    for(int i = 0; i < h; i++) {
        for(int j = w - 1; j >= 0; j--) {
            if(c[i][j] == '#') {
                r[i][j] = 0;
            } else {
                if(j < w - 1) {
                    r[i][j] = r[i][j + 1] + 1;
                } else {
                    r[i][j] = 1;
                }
            }
        }
    }
    for(int j = 0; j < w; j++) {
        for(int i = 0; i < h; i++) {
            if(c[i][j] == '#') {
                u[i][j] = 0;
            } else {
                if(i > 0) {
                    u[i][j] = u[i - 1][j] + 1;
                } else {
                    u[i][j] = 1;
                }
            }
        }
    }
    for(int j = 0; j < w; j++) {
        for(int i = h - 1; i >= 0; i--) {
            if(c[i][j] == '#') {
                d[i][j] = 0;
            } else {
                if(i < h - 1) {
                    d[i][j] = d[i + 1][j] + 1;
                } else {
                    d[i][j] = 1;
                }
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(c[i][j] == '.') {
                chmax(ans, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 67328
MOD = 10 ** 9 + 7

def solve():
  N, K = map(int, input().split())
  space = N - K + 1
  ans = 1
  b = space
  c = 1
  for i in range(1, K + 1):
    ans = b * c
    ans %= MOD
    b *= space - i
    b //= i + 1
    c *= K - i
    c //= i
    print(ans)

solve()


Measured memory_bytes: 3316
#include <cstdio>
#include<iostream>

using namespace std;
 
int main(void){

	int n;
	int ans[10001];
	ans[1]=2;

	for(int i=2;i<=10000;i++){
		ans[i]=ans[i-1]+i;
	}

	while(cin>>n){
		cout<<ans[n]<<endl;
	}

    return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N;
  cin >> N;
  vector<double> vec(N);

  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }
  
  sort(vec.begin(), vec.end());
  
  double ans = 0;
  ans = (vec[0]+vec[1])/2;
  
  for ( int i = 2; i < N; i++){
      ans =(ans+vec[i])/2;
  }
  cout << ans << endl;
}
    

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

typedef long long ll;
const long long LINF = 1LL << 60;
const long long LMINF = 1LL << 63;
const int INF = 1 << 30;

#define REP(i,n) for(int i = 0;i < n;++i)
#define REPS(i,x) for(int i = 1;i <= (int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i >= 0;i--)
#define RREPS(i,x) for(int i=((int)(x));i > 0;i--)
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << x << "\n"

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(){
    ios::sync_with_stdio(false);cin.tie(0);

    string a,b,c;
    cin >> a >> b;
    c = a + b;
    int d = stoi(c);
    int e = sqrt(d);
    if(e * e == d){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3672
N=int(input())
B=list(map(int,input().split()))

def min(x,y):
	if x>=y:
		return y
	else:
		return x
s=B[0]
for i in range(0,N-2):
    s=s+min(B[i],B[i+1])
print(s+B[N-2])



Measured memory_bytes: 2940
import math
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,k=INTM()
    d=[]
    a=set([])
    for i in range(k):
        d.append(INT())
        a=a | set(LIST())
    print(n-len(a))
    #print(a)
    
if __name__ == '__main__':
    do()

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

void Main() {
  int n;
  string s;
  cin >> n >> s;
  int x=0;
  rep(i,s.size()) {
    if(s[i]=='E') x++;
  }
  int ans=MAX;
  rep(i,n) {
    if(s[i]=='E') x--;
    else x++;
    if(s[i]=='W') ans=min(ans,x-1);
    else ans=min(ans,x);
  }
  pr(ans);
}

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


Measured memory_bytes: 720
import math


    
def deffer(A,B):
    sum = 0
    for i in range(len(A)):
        sum += (A[i]-B[i])**2
    sum = math.sqrt(sum)
    return sum


N,D= map(int,input().split())
listA = [list(map(int,input().split())) for i in range(N)]
ans =0
for i in range(N):
    for j in range(i +1,N):
        D = deffer(listA[i],listA[j])
        
        if D.is_integer():
            ans +=1
            
print(ans)

    
def deffer(A,B):
    sum = 0
    for i in range(len(A)):
        sum += (A[i]-B[i])**2
    sum = math.sqrt(sum)
    print("sum is {}".format(sum))
    return sum


Measured memory_bytes: 3064
//let's do it
 #include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 1000000000000
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S second
#define F first
#define boost1 ios::sync_with_stdio(false);
#define boost2 cin.tie(0);
#define mem(a,val) memset(a,val,sizeof a)
#define endl "\n"
#define maxn 100001

ll a[maxn];
int main()
{
    boost1;boost2;
    ll i,j,n,x,y,f=0,ans=0,o=0,e=0;
    string s;
    char ch;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        if(x%2)
        o++;
        else
        e++;
    }
    if(n==1)
    {
        cout<<"YES";
        return 0;
    }
    if(e==0)
    {
        if(n%2)
        {
            cout<<"NO";
        }
        else
        cout<<"YES";
        return 0;
    }
    if(o%2)
    {
        cout<<"NO";
    }
    else
    cout<<"YES";
    return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

constexpr int MAX_S = (1<<12) + 1;
constexpr int MAX_T = 1001;
int dp[MAX_S];//[MAX_T];

int main() {
  rep(i, MAX_S) dp[i] = inf; //rep(j, MAX_T) dp[i][j] = inf;
  int N, M; cin >> N >> M;
  vector<int> a(M);//, b(M);
  vector<int> c(M);
  rep(i, M) {
    int b;
    cin >> a[i] >> b;
    rep(j, b) {
      int cbit; cin >> cbit; cbit--;
      c[i] |= 1 << cbit;
    }
  }

  dp[0] = 0;

  rep(S, 1 << N) {
    if (dp[S] == inf) { continue; }
    rep(key_id, M) {
      auto next_S = S | c[key_id];
      dp[next_S] = min(dp[next_S], dp[S] + a[key_id]);
    }
  }

  const auto ans = dp[(1 << N) - 1];
  if (ans == inf) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
/* #define int long long */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define MOD 1000000007
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; }

signed main(){
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3540
import itertools
from collections import deque
from sys import stdin
input = stdin.readline


def main():
  H, W = list(map(int, input().split()))

  M = [input()[:-1] for _ in range(H)]

  def bfs(start):
    dist = [[float('inf')]*W for _ in range(H)]
    dist[start[0]][start[1]] = 0

    q = deque([start])
    max_ = 0

    while len(q):
      now_h, now_w = q.popleft()
      if M[now_h][now_w] == '#':
        return
      for next_h, next_w in ((now_h+1, now_w),
                             (now_h-1, now_w),
                             (now_h, now_w-1),
                             (now_h, now_w+1)):

        if not(0 <= next_h < H) or not(0 <= next_w < W) or \
           (dist[next_h][next_w] != float('inf')) or \
           M[next_h][next_w] == '#':
          continue

        temp = dist[now_h][now_w] + 1
        dist[next_h][next_w] = temp
        if max_ < temp:
          max_ = temp
        q.append((next_h, next_w))
    return max_

  max_ = 0
  for h in range(H):
    for w in range(W):
      if M[h][w] == '.':
        max_ = max(bfs((h, w)), max_)

  print(max_)


if(__name__ == '__main__'):
  main()


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

int main() {
  string r, g, b;
  cin >> r >> g >> b;
  int num = 100*stoi(r)+10*stoi(g)+stoi(b);
  if (num%4==0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   String n = sc.next();
   Boolean flg;
   //add per Keta
   int total = 0;
   for(int i = 0; i < n.length(); i++){
     total += Character.getNumericValue(n.charAt(i));
     //System.out.println(n.charAt(i));
   }
   //System.out.println(total);
   
   if((Integer.parseInt(n) % total ) == 0){
       flg = true;
   }else{
       flg = false;
   }
   
   if(flg == true){
    System.out.print("Yes"); 
   }else{
     System.out.print("No");
   }
 }
}

Measured memory_bytes: 25684
import std.algorithm, std.array, std.conv, std.range, std.stdio, std.string;
void main()
{
    auto buf = readln.chomp.split.to!(long[]);
    solve(buf[0], buf[1], buf[2]).writeln;
}
long solve(in long n, in long a, in long b)
{
    if ((b - a) & 1)
        return min(a, n - b + 1) + (b - a) / 2;
    return (b - a) / 2;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n-1);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n-1) cin >> c[i];
    int bsum = 0;
    for(int i = 0; i < n; i++){
        bsum += b[i];
    }
    for(int i = 0; i < n - 1; i++){
        if(a[i+1] == a[i] + 1){
            bsum += c[a[i]-1];
        }
    }
    cout << bsum << endl;
}

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

int main(){
  string str;
  int sum;
  while(getline(cin,str)){
    sum = 0;
    for(auto c : str){
      sum += c - '0';
    }
    if(sum) printf("%d\n",sum);
  }
  return 0;
}

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

#define endl '\n'
#define mod 1e7 

using ll = long long;
using namespace std;

const long long INF = 1e18L + 5;

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

    long long n,W;
    cin >> n >> W;
    vector<long long> weight(n), value(n);
    
    for(auto i=0;i<n;i++) cin >> weight[i] >> value[i];
    
    int MAX_VALUE = 0;
    for(auto x : value) MAX_VALUE += x;

    vector<long long> dp(MAX_VALUE + 1, INF);

    dp[0] = 0;
    //dp[i] -> stores the minimum total WEIGHT of items with total VALUE exactly 1

    for(auto i = 0; i < n; i++) {
        for(auto j = MAX_VALUE - value[i] ; j >=0 ;--j) {
            dp[j + value[i]] = min(dp[j + value[i]], weight[i] + dp[j]);
        }
    }

    long long answer = 0;
    for(auto i= 0 ;i <= MAX_VALUE ;i++) { 
        if(dp[i] <= W) {
            answer = max(answer, (ll) i);
        }
    }

    cout << answer << endl;



    

    return 0;
}

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

int main() {
    const long long MOD = 1e9+7;
    int n;
    cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x.at(i);
    }

    long long ans = 1;
    long long cnt = 1;
    for (int i = 0; i < n; i++) {
        if (x.at(i) < 2 * cnt - 1) {
            ans *= cnt;
            ans %= MOD;
        }
        else cnt++;
    }
  
    for (long long i = 2; i <= cnt - 1; i++) {
        ans *= i;
        ans %= MOD;
    }

    cout << ans << endl;
}

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

struct dice {
    int face1;
    int face2;
    int face3;
    int face4;
    int face5;
    int face6;
};

struct dice move_W(struct dice d);
struct dice move_S(struct dice d);
struct dice move_E(struct dice d);
struct dice move_N(struct dice d);

int main()
{
    struct dice d;
    scanf("%d %d %d %d %d %d",
            &d.face1, &d.face2, &d.face3, &d.face4, &d.face5, &d.face6);

    char command[101];
    scanf("%s", command);

    int i;
    for (i = 0; i < strlen(command); i++) {
        switch (command[i]) {
          case 'W':
              d = move_W(d);
              break;
          case 'S':
              d = move_S(d);
              break;
          case 'E':
              d = move_E(d);
              break;
          case 'N':
              d = move_N(d);
              break;
          default:
              break;
        }
    }

    printf("%d\n", d.face1);

    return 0;
}

struct dice move_W(struct dice d) {
    struct dice d_tmp;
    d_tmp.face1 = d.face3;
    d_tmp.face2 = d.face2;
    d_tmp.face3 = d.face6;
    d_tmp.face4 = d.face1;
    d_tmp.face5 = d.face5;
    d_tmp.face6 = d.face4;
    return d_tmp;
}

struct dice move_S(struct dice d) {
    struct dice d_tmp;
    d_tmp.face1 = d.face5;
    d_tmp.face2 = d.face1;
    d_tmp.face3 = d.face3;
    d_tmp.face4 = d.face4;
    d_tmp.face5 = d.face6;
    d_tmp.face6 = d.face2;
    return d_tmp;
}

struct dice move_E(struct dice d) {
    struct dice d_tmp;
    d_tmp.face1 = d.face4;
    d_tmp.face2 = d.face2;
    d_tmp.face3 = d.face1;
    d_tmp.face4 = d.face6;
    d_tmp.face5 = d.face5;
    d_tmp.face6 = d.face3;
    return d_tmp;
}

struct dice move_N(struct dice d) {
    struct dice d_tmp;
    d_tmp.face1 = d.face2;
    d_tmp.face2 = d.face6;
    d_tmp.face3 = d.face3;
    d_tmp.face4 = d.face4;
    d_tmp.face5 = d.face1;
    d_tmp.face6 = d.face5;
    return d_tmp;
}



Measured memory_bytes: 2056
# -*- coding: utf-8 -*-
line = input().split()
a = int(line[0]) #水100a[g]
b = int(line[1]) #水100b[g]
c = int(line[2]) #砂糖c[g]
d = int(line[3]) #砂糖d[g]
e = int(line[4]) #水100gに溶ける砂糖e[g]
f = int(line[5]) #質量f[g]

ra = 2
rb = -1
for ai in range(f//(100*a)+2):
    for bi in range(f//(100*b)+2):
        if 100*a*ai+100*b*bi>f:
            break
        for ci in range(f//c+2):
            if 100*a*ai+100*b*bi+c*ci>f:
                break
            elif c*ci>(a*ai+b*bi)*e:
                break
            for di in range(f//d+2):
                sa = 100*a*ai+100*b*bi
                sb = c*ci+d*di
                if sa+sb>f:
                    break
                elif sb>(a*ai+b*bi)*e:
                    break
                elif sa+sb==0:
                    continue
                if sb/(sa+sb) > rb/(ra+rb):
                    ra = sa
                    rb = sb
                    # print(rb/(ra+rb))
                    # print("---")
                    # print(ra,rb)
                    # print(ai,bi,ci,di)

print(ra+rb,rb)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<cmath>
#define SZ(x) ((int)x.size())
#include<vector>
#include<set>
#include<map>
#define ll long long
#define lli long long int
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#include<string>
#include<cctype>
#include<queue>
#define ii pair<int,int>
#include <sstream>
#define lli long long int
#define pairs pair<int,int>
#define mod 1000000007
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
ll pows(ll a,ll n,ll m)
{
	ll res=1;
	while(n)
	{
	if(n%2!=0)
	{
		res=(res*a)%m;
		n--;
		}
		else
		{
			a=(a*a)%m;
			n=n/2;
			}	
	}
	return res%m;
}
ll  gcd(ll a,ll b)
{
	if(b==0)
	return a;
	else 
	return gcd(b,a%b);
}
bool isprime(ll n)
{
	if(n==1)
	{
		return false;
	}
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
bool istrue(string s)
{
	int i=0;
	int j=s.size()-1;
	while(i<j)
	{
	if(s[i]==s[j])
	{
		i++;
		j--;
		}
		else
		{
			return false;
			}	
	}
	return true;
}
ll n;
ll w;
ll dp[105][100005];
ll weight[105];
ll val[105];
ll getans(ll idx,ll wl)
{
	if(wl==0)
	{
		return 0;
	}
	if(wl<0)
	{
		return -mod;
	}
	if(idx==n+1)
	{
		return -mod;
	}
	if(dp[idx][wl]!=-1)
	{
		return dp[idx][wl];
	}
	ll ans=0;
	ans=max(getans(idx+1,wl),getans(idx+1,wl-weight[idx])+val[idx]);
	return dp[idx][wl]=ans;
}
int main()
{
ios::sync_with_stdio(false);
	 cin.tie(0);
    cout.tie(0);
memset(dp,-1,sizeof(dp));
cin>>n;
cin>>w;
for(ll i=1;i<=n;i++)
{
	cin>>weight[i]>>val[i];
}
ll ans=0;
for(ll i=1;i<=w;i++)
{
	ll v=getans(1,i);
	if(v>ans)
	{
		ans=v;
	}
}
cout<<ans<<endl;
}





Measured memory_bytes: 85668
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

const double PI=3.141592653589323;

int main(){
    int N;
    cin>>N;
    vector<double> x(N),y(N);
    REP(i,N) cin>>x[i]>>y[i];
    double ans=(double)INF;
    double x1,x2,y1,y2,x3,y3,x4,y4,cx,cy,r;
    double ex,ey,fx,fy;
    double alpha,beta;
    bool ok;
    REP(i,N){
        REP2(j,i+1,N){
            if(i==j) continue;
            x1=x[i];
            x2=x[j];
            y1=y[i];
            y2=y[j];


            cx=(x1+x2)/2;
            cy=(y1+y2)/2;
            r=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))/2;
            ok=true;
            REP(l,N){
                if(l==i||l==j) continue;
                x4=x[l];
                y4=y[l];
                if((x4-cx)*(x4-cx)+(y4-cy)*(y4-cy)-r*r>0){
                    ok=false;
                    break;
                }
            }
            if(ok) ans=min(r,ans);
            
        }
    }

    REP(i,N){
        REP2(j,i+1,N){
            REP2(k,j+1,N){
                if(i==j||j==k||k==i) continue;

                x1=x[i];
                x2=x[j];
                x3=x[k];
                y1=y[i];
                y2=y[j];
                y3=y[k];

                if((x3-x1)*(y2-y1)==(x2-x1)*(y3-y1)) continue;
                
                ex=(x1+x2)/2;
                ey=(y1+y2)/2;
                fx=(x2+x3)/2;
                fy=(y2+y3)/2;
                
                alpha=atan((y2-y1)/(x2-x1))+PI/2;
                beta=atan((y3-y2)/(x3-x2))+PI/2;

                cx=(ey-fy-ex*tan(alpha)+fx*tan(beta))/(tan(beta)-tan(alpha));
                cy=ey-(ex-cx)*tan(alpha);
                r=sqrt((x1-cx)*(x1-cx)+(y1-cy)*(y1-cy));
                ok=true;
                
                
                REP(l,N){
                    if(l==i||l==j||l==k) continue;
                    x4=x[l];
                    y4=y[l];
                    if((x4-cx)*(x4-cx)+(y4-cy)*(y4-cy)-r*r>0){
                        ok=false;
                        break;
                    }
                }
                if(ok) ans=min(r,ans);
            }
        }
    }

    printf("%.16f\n",ans);
}

Measured memory_bytes: 4440
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll K;
    cin >> K;
    //配列を降順だったとして
    //(s,s,s,...,0,0)
    //(s-N+1)*N - m (mは0の要素数)
    //N=50と固定してもよい。
    ll N = 50;
    ll q = K/N;
    // (s-N)*N+N-m;
    ll r = K%N;//sの要素数
    ll s = N-1+q;
    vector<ll> ans(N,s);
    rep(i,r){
        ans[i] += N+1-r;
    }
    REP(i,r,N){
        ans[i] -= r;//max(s-50-1,0LL);
    }
    cout << N << endl;
    PR(ans,N);
}

Measured memory_bytes: 3596
X,Y,A,B,C=map(int,input().split())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
R=list(map(int,input().split()))
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)
P.append(float("inf"))
Q.append(float("inf"))
ans=sum(P[:X]+Q[:Y])
rfinish=False
gfinish=False
r,g,f=X-1,Y-1,0
while f<C and (R[f]>P[r] or R[f]>Q[g]):
    if P[r]<Q[g]:
        ans=ans-P[r]+R[f]
        r-=1
        f+=1
    else:
        ans=ans-Q[g]+R[f]
        g-=1
        f+=1
print(ans)



Measured memory_bytes: 23328
N = int(input())
task = []
for i in range(N):
    A, B = map(int, input().split())
    task.append([A,B])

task = sorted(task,key=lambda x:x[1])

time = 0
for i in range(len(task)):
    time += task[i][0]

    if time > task[i][1]:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 39700
import scala.io.StdIn.readInt

object Main extends App {
  println {
    Iterator.continually(readInt).takeWhile(_ != -1).map { w =>
                val w3 = if(w>30) w-30 else 0
      val w2 = if(w>20) w - w3 -20 else 0
      val w1 = if(w>10) w - w3 - w2 - 10 else 0
      4280 - (1150 + w1*125 + w2*140 + w3*160)
    }.mkString("\n")
  }
}

Measured memory_bytes: 43632
#include <bits/stdc++.h>
using namespace std;
static const long long INF = 1ll<<60;

int main(){
    int n;
    cin>>n;
    vector<int> x(n);
    for(int i=0; i<n; i++) cin>>x[i];
    long long ans = INF;

    for(int i=1; i<=100; i++){
        long long sum = 0;
        for(int j=0; j<n; j++){
            sum += (x[j]-i)*(x[j]-i);
        }

        ans = min(sum,ans);
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
n, T = list(map(int, input().split()))

ct = [list(map(int, input().split())) for i in range(n)]

cost = []

for c, t in ct:
    if t <= T:
        cost.append(c)

if len(cost) == 0:
    print("TLE")
else:
    print(min(cost))

Measured memory_bytes: 9180
import fractions

"""
def gcd(a,b):
    if a>b:swap(a,b)
    if a==0:return b
    return gcd(b%a,a)
"""

a,b=map(int,input().split())
g=fractions.gcd(a,b)
#print(g)
ans=1
i=2
while i*i<=g:
    if(g%i==0):
        ans+=1
        while g%i==0:
            g/=i
    i=i+1
if(g!=1):ans+=1
print(ans)

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


int main(void)
{
	//変数の宣言
	int n,a,b;
	int x[100010];
	int i,j,k;
	long int ans=0;
	
	//データの読み込み
	scanf("%d %d %d",&n,&a,&b);
	
	for(i=0;i<n;i++){
		scanf("%d",&x[i]);
	}
	
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	for(i=1;i<n;i++){
		if((long)(x[i]-x[i-1])*a<b){
			ans=ans+(long)(x[i]-x[i-1])*a;
		}else{
			ans=ans+b;
		}
	}
		
		
//	printf("計算部分終了\n");
	
	//出力
	
		printf("%ld",ans);
	
//	printf("結果の出力終了\n");
	
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rap(i,n) for(int i=0;i<n;++i)
using namespace std;
signed main(){
  int n,a[1000000],b=1,z=0;
  cin>>n;
  rap(i,n){
    cin>>a[i];
  }
  rap(i,n){
    if(a[i]==b){
      b++;
    }else{
      z++;
    }
  }
  if(z==n){
	cout<<"-1\n";
  }else{
    cout<<z<<"\n";
  }
}

Measured memory_bytes: 3072
import sys
sys.setrecursionlimit(10**6)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sum_lr_b = [0]*n
for i in range(n):
    sum_lr_b[i] = b[(i - 1) % n] + b[(i+1) % n]

ans = [0]
def solve(i):
    if b[i] < sum_lr_b[i]:
        return
    tmp = b[i] - a[i]
    cnt = tmp // sum_lr_b[i]
    b[i] = b[i] - sum_lr_b[i]*cnt
    ans[0] += cnt
    sum_lr_b[(i-1) % n] -= sum_lr_b[i]*cnt
    sum_lr_b[(i+1) % n] -= sum_lr_b[i]*cnt
    solve((i-1) % n)
    solve((i+1) % n)

for i in range(n):
    solve(i)

if b == a:
    print(ans[0])
else:
    print(-1)

Measured memory_bytes: 118904
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int a[] = new int[n];
    int c[] = {0,0,0,0,0,0,0,0,0};
    
    for(int i = 0 ; i < n ; ++i){
      a[i] = sc.nextInt();
            
      if(a[i] < 400) c[0]++;
      else if(a[i] < 800) c[1]++;
      else if(a[i] < 1200) c[2]++;
      else if(a[i] < 1600) c[3]++;
      else if(a[i] < 2000) c[4]++;
      else if(a[i] < 2400) c[5]++;
      else if(a[i] < 2800) c[6]++;
      else if(a[i] < 3200) c[7]++;
      else c[8]++;
    }
    
    int min = 0;
    
    for(int i = 0 ; i < 8 ; ++i){
      if(c[i] != 0){
        min++;
      }
    }
    
    int max = min + c[8];
    if(min == 0) min++;
    
    System.out.println(min+" "+max);

  }
}

Measured memory_bytes: 38724
#include<bits/stdc++.h>
#define N 
using namespace std;
bool cur1;
int n;
inline void Rd(int &res){
	char c;res=0;
	while(c=getchar(),c<48);
	do res=(res<<3)+(res<<1)+(c^48);
	while(c=getchar(),c>47);
	return;
}
bool cur2;
int main(){
//	printf("%lf MB\n",(&cur2-&cur1)/1024.0/1024);
	Rd(n);
	printf("%lld\n",1ll*3*n*n);
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    while(1){
        int n; cin >> n;
        if (n == 0) return 0;

        vector<int> diagram(100000,0);
        REP(i,n){
            string s,t;
            cin >> s >> t;
            int s_seconds = (s[7]-'0') + 10*(s[6]-'0') + 60*((s[4]-'0') + 10*(s[3]-'0')) + 3600*((s[1]-'0') + 10*(s[0]-'0'));
            int t_seconds = (t[7]-'0') + 10*(t[6]-'0') + 60*((t[4]-'0') + 10*(t[3]-'0')) + 3600*((t[1]-'0') + 10*(t[0]-'0'));
            diagram[s_seconds]++;
            diagram[t_seconds]--;
        }
        int ans = 0;
        REP(i,90000){
            diagram[i+1] += diagram[i];
            ans = max(ans, diagram[i]);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
#define len length
#define ret0 return 0
#define ret return 

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)

#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN 100001

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

    ll l, r;
    cin>>l>>r;
    if(r-l>=2019){
        print(0);
    }
    else {
        ll ans=inf;
        for(ll i=l; i<=r; i++){
            for(ll j=i+1; j<=r; j++){
                ans = min(ans, (i%2019 * j%2019)%2019);
            }
        }
        print(ans);
    }
        
    
}



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

namespace AtTest.C_Challenge
{
    class ABC_044
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int a = int.Parse(input[1]);
            input = Console.ReadLine().Split(' ');
            var xs = new int[n];
            for (int i = 0; i < n; i++)
            {
                xs[i] = int.Parse(input[i]) - a;
            }
            int nx = n*50;
            var dp = new long[n, 2 * nx + 1];
            for(int i = 0; i < 2 * nx + 1; i++)
            {
                dp[0, i] = 0;
            }
            dp[0, xs[0] + nx] = 1;
            for (int i = 1; i < n; i++)
            {
                //string s = "";
                for (int j = 0; j < 2 * nx + 1; j++)
                {
                    dp[i, j] = dp[i - 1, j];
                    if (0 <= j - xs[i] && j - xs[i] < 2 * nx + 1)
                    {
                        dp[i, j] += dp[i - 1, j - xs[i]];
                    }
                    if (j - nx == xs[i])
                    {
                        dp[i, j]++;
                    }
                    //s += dp[i, j].ToString();
                }
                //Console.WriteLine(s);
            }
            Console.WriteLine(dp[n - 1, nx]);
        }

        static long Factorial(long n)
        {
            if (n == 0) return 1;

            return n * Factorial(n - 1);
        }
    }
}


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

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, ac = 0, wa = 0, tle = 0, re = 0; cin >> n;
    string s;
    while (n--)
    {
        cin >> s;
        if(s == "AC") ac++;
        else if(s == "WA") wa++;
        else if(s == "TLE") tle++;
        else re++;
    }
    cout << "AC x " << ac << "\nWA x " << wa << "\nTLE x " << tle << "\nRE x " << re << '\n';
    return 0;
}

Measured memory_bytes: 3672
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline

N, M = map(int, input().split())
X = []
for _ in range(M):
    a, b = map(int, input().split())
    X.append((a-1, b-1))
X = X[::-1]
    
P = [-1] * N
CT = [1] * N
def pr(i):
    if P[i] < 0:
        return i
    t = pr(P[i])
    P[i] = t
    return t

ANS = [0] * M
ans = N * (N-1) // 2
ANS[-1] = ans
for m in range(M-1):
    a, b = X[m]
    pa = pr(a)
    pb = pr(b)
    
    if pa != pb:
        ans -= CT[pa] * CT[pb]
        P[pa] = pb
        CT[pb] += CT[pa]

    ANS[-m-2] = ans

for a in ANS:
    print(a)


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

int main() {
  vector<int> a(3);
  cin >> a.at(0) >> a.at(1) >> a.at(2);
  sort(a.begin(), a.end());
  cout << (a.at(2) - a.at(1)) + (a.at(1) - a.at(0)) << endl;
}

Measured memory_bytes: 256
N = int(input())
l =[]
#deal with error
for i in range(N):
    l.append(int(input()))
    if i == 0 and l[i]!=0:
        print(-1)
        exit()
    if i>=1:
        if l[i]-l[i-1]>1 :
            print(-1)
            exit()
 
ans = 0
pre = -1
for a in l[::-1]:
    if pre - 1 != a:
        ans += a
    pre = a
print(ans)

Measured memory_bytes: 12616
#include<iostream>
#define N 2000001
using namespace std;
int a[N],b[N],c[N],n;

void Csort(int k){
  for(int i=0;i<=k;i++)c[i]=0;

    for(int j=1;j<=n;j++)c[a[j]]++;
  
  for(int i=1;i<=k;i++)c[i]+=c[i-1];
  for(int j=n;j>0;j--) b[c[a[j]]]=a[j],c[a[j]]--;
}

int main(){
  cin>>n;
  int k=0;
  for(int i=1;i<=n;i++)cin>>a[i];
  for(int i=1;i<=n;i++)if(k<a[i])k=a[i];
  Csort(k);
  for(int i=1;i<n;i++)cout<<b[i]<<" ";
  cout<<b[n]<<endl;

  return 0;
}

Measured memory_bytes: 18500
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	//縦と横の長さ0になるまでの繰り返し	
		while(true){
			
	//入力の読み込み

			
			
			int H = sc.nextInt(); //縦の長さ
			int W = sc.nextInt(); //横の長さ
			
	//縦と横の長さ0ならばプログラム終了

			if(H==0&&W==0)break;
			
	//一行に何文字出力するか
	for ( int i = 0; i < H; i++ ){
		//何行出力するか
		    for ( int j = 0; j < W; j++ ){
		    	//偶数行の時で奇数番目の時と奇数行の時で偶数番目の時に出力
		        if( i%2==0&&j%2==1||i%2==1&&j%2==0){
		            System.out.print(".");
		        } else {
		            System.out.print("#");
		        }
		    }
		    //改行
		    System.out.println("");
		}
	 //空白行
	System.out.println("");

	
	}
	
	}
	
}


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


int insertionSort(int * A, int n, int g) {
    int cnt = 0;
    for (int i = g; i < n; i++) {
        int val = A[i];
        int j = i - g;
        while (j >= 0 && A[j] > val) {
            A[j + g] = A[j];
            j -= g;
            cnt++;
        }
        A[j + g] = val;
    }
    return cnt;
}

void shellSort(int * A, int n) {
    int cnt = 0;

    std::vector<int> G;
    for (int h = 1;;) {
        if (h > n) break;
        G.emplace_back(h);
        h = 3 * h + 1;
    }

    int m = G.size();
    for (int i = m - 1; i >= 0; i--) {
        cnt += insertionSort(A, n, G[i]);
    }

    std::cout << m << std::endl;
    for (int i = m - 1; i > 0; i--) {
        std::cout << G[i] << " ";
    }
    std::cout << G[0] << std::endl;

    std::cout << cnt << std::endl;

    for (int i = 0; i < n; i++) {
        std::cout << A[i] << std::endl;
    }
}

int main() {
    int N;
    std::cin >> N;
    int A[N];
    for (int i = 0; i < N; i++) {
        std::cin >> A[i];
    }
    shellSort(A, N);
}



Measured memory_bytes: 6964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll a,b;
    cin >> a >> b;
    if(a+b==15){
        cout << "+" << endl;
    }
    else if(a*b==15){
        cout << "*" << endl;
    }
    else{
        cout << "x" << endl;
    }
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <limits.h>
#include <float.h>
#include <numeric>
#include <queue>
#include <typeinfo>
#include <memory>


using namespace std;

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

#define fs first
#define sc second



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

    int s = 0;
    for(int i = 1; i <= n; i++){
        s += l + i - 1;
    }
    if(l < 0 && l + n - 1 > 0){
        s -= 0;
    }
    else if(l > 0){
        s -= l;
    }
    else if(l + n - 1 < 0){
        s -= l + n - 1;
    }

    cout << s << endl;




    return 0;
}


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

int main(){
  int A,B,sum;
  cin >> A >> B;
  
  
  for(int i=0;i<2;i++){
    if(A>B){
      sum+=A;
      A-=1;
    }else{
      sum+=B;
      B-=1;
    }
  }
  
  cout << sum << endl;
}
  

  

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		println(n * (n - 1) / 2 + m * (m - 1) / 2);
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 2000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define dum(x) cout<<#x<<'='<<x<<endl
#define dum2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define dum3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl

//ifstream in("Text.txt");cin.rdbuf(in.rdbuf());



int main() {
    string S, T;
    cin >> S >> T;
    int che = 0;
    bool exi = false;
    for (int i = S.size() - 1; i >= 0; i--) {
        rep(j, T.size()) {
            if (S[i + j] != T[j] && S[i + j] != '?')break;
            if (j == T.size() - 1) {
                che = i;
                exi = true;
                goto end;
            }
        }
    }
end:
    if (!exi) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    string Sans;
    rep(i, S.size()) {
        if (i == che) {
            Sans += T;
            i += T.size() - 1;
        }
        else if (S[i] == '?')Sans += 'a';
        else Sans += S[i];
    }
    cout << Sans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    string S = in<string>();
    vector<int> A(S.size());
    int eve = 0;
    int odd = 0;
    int before = 0;
    char be = 'R';
    REP(i,S.size()){
        if(be == 'L' && S[i] == 'R'){
            if(before%2 == 0){
                A[before] = eve;
                A[before+1] = odd;
            }else{
                A[before] = odd;
                A[before+1] = eve;
            }
            odd = 0;
            eve = 0;
        }
        if(be == 'R' && S[i] == 'L'){
            before = i-1;
        }
        if(i % 2 == 0){
            eve++;
        }else{
            odd++;
        }
        be = S[i];
    }
    if(before %2 == 0){
        A[before] = eve;
        A[before+1] = odd;
    }else{
        A[before] = odd;
        A[before+1] = eve;
    }
    REP(i,S.size())cout << A[i] << "\n";
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define rlo(i,n) for(int i=n-1;i>=0;i--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define pr(a) {for(auto x:a)cout<<x<<" ";cout<<nl;}

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

void f()
{
  int x,y;
  cin>>x>>y;
  cout<<x+(y/2)<<nl;
}

int main()
{
    su;
    f();
    return 0;
}


Measured memory_bytes: 3616