akhauriyash/Code-Regression huggingface dataset:
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  n,k=pM(split(readline()))
  a=pM(split(readline()))
  println(cld(n-k,k-1)+1)
end
main()
if isdefined(Base, :mystdin);close(mystdin);end


Measured memory_bytes: 174096
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};

struct HashData {
	int h1, h2;
	bool operator==(const HashData& rhs) const {
		return h1 == rhs.h1 && h2 == rhs.h2;
	}
	bool operator!=(const HashData& rhs) const { return !(*this == rhs); }
};

class RollingHash {
	template<int B, int M>
	class RollingHashPart {
	private:
		size_t len;
		std::vector<int> pow_b, hash;
	public:
		RollingHashPart() {}
		template<typename T>
		RollingHashPart(const T& s) : len(s.size()), pow_b(s.size() + 1), hash(s.size() + 1) {
			pow_b[0] = 1;
			hash[0] = 0;
			for (int i = 0; i < len; i++) {
				pow_b[i + 1] = (ll)pow_b[i] * B % M;
				hash[i + 1] = ((ll)hash[i] * B + s[i]) % M;
			}
		}
		// [l, r)
		int get(int l, int r) const {
			int res = (hash[r] - (ll)hash[l] * pow_b[r - l]) % M;
			if (res < 0) res += M;
			return res;
		}
	};
public:
	RollingHashPart<1033, 1000000007> rh1;
	RollingHashPart<6037, 999999937> rh2;
 
	RollingHash() {}
	template<typename T> RollingHash(const T & s) : rh1(s), rh2(s) {}
	// [l, r)
	HashData get(int l, int r) const {
		return (HashData){ rh1.get(l, r), rh2.get(l, r) };
	}
	// [l1, r1), [l2, r2)
	int lcp(const RollingHash & rhs, int l1, int r1, int l2, int r2) const {
		int lb = 0, ub = std::min(r1 - l1, r2 - l2) + 1;
		while (ub - lb > 1) {
			int md = (lb + ub) >> 1;
			(get(l1, l1 + md) == rhs.get(l2, l2 + md) ? lb : ub) = md;
		}
		return lb;
	}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    string S;
    cin >> S;
    RollingHash r(S);
    ll lv = 0, rv = N+1;
    while(rv - lv > 1){
        ll mid = (rv + lv) / 2;
        bool ok = false;
        rep(i,0,N){
            rep(j,i+1,N){
                if(j - i < mid) continue;
                if(j+mid-1 >= N) continue;
                if(r.get(i, i+mid) == r.get(j, j+mid)){
                    ok = true;
                    break;
                }
            }
            if(ok) break;
        }
        if(ok){
            lv = mid;
        }else{
            rv = mid;
        }
    }
    print(lv);


    
}


Measured memory_bytes: 384
fn main() {
    let n: usize = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line);
        line.trim().parse().unwrap()
    };
    let a: Vec<usize> = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line);
        line.split_whitespace().map(|a|a.parse().unwrap()).collect()
    };
    let b: Vec<usize> = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line);
        line.split_whitespace().map(|a|a.parse().unwrap()).collect()
    };
    let c: Vec<usize> = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line);
        line.split_whitespace().map(|a|a.parse().unwrap()).collect()
    };
    let mut sum = b.iter().fold(0, |sum, &b| sum + b);
    for i in 0..n-1 {
        if a[i] + 1 == a[i + 1] {
            sum += c[a[i] - 1];
        }
    }
    println!("{}", sum);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); 
    _LL n, k; cin >> n >> k;
    _LL ans = 0;
    _LL knum = n / k;
    ans += knum * knum * knum;
    if( k % 2 == 0 )
    {
        _LL k2num = (n + (k / 2)) / k;
        ans += k2num * k2num * k2num;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3552
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;
static const int max_n = 10010;
// static const llong max_cost = 2000000000000000;
// // vector<vector<llong>> matrix(max_n, vector<llong>(max_n, 0));
// // vector<vector<llong>> adj_matrix(max_n, vector<llong>(max_n, max_cost));
// vector<vector<pair<llong, int>>> adj_list(max_n);
// vector<llong> distance_table(max_n, max_cost);
// set<pair<llong, int>> points_sort_x;
// set<pair<llong, int>> points_sort_y;
vector<ll> homework_list(max_n);
// int N;



int main(){
    // int u, v;
    // bool updated = false;
    ll A, B, C, D;
    scanf("%lld %lld %lld %lld", &A,&B,&C,&D);
    // printf("%lld\n", total_num);
    ll num_attack_a = A/D;
    if(A%D>0){
        num_attack_a ++;
    }
    ll num_attack_b = C / B;
    if(C%B>0){
        num_attack_b ++;
    }
    if(num_attack_b<=num_attack_a){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;

}

Measured memory_bytes: 3248
/*  CREATED BY
    STREAM_CIPHER
    29-aug-2020
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define debug1(a) cout<<#a<<"="<<(a)<<"\n"
#define debug2(a,b) cout<<#a<<"="<<(a)<<","<<#b<<"="<<(b)<<"\n"
#define debug3(a,b,c) cout<<#a<<"="<<(a)<<","<<#b<<"="<<(b)<<","<<#c<<"="<<(c)<<"\n"
#define fix_precision(n) cout << fixed << setprecision(n)
#define all(a) a.begin(),a.end()
const double pi=acos(-1.0);
int inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int mx=5*1000000;
int can=0;
bool vis[mx];
vector<int>g[mx];
void dfs(int start)
{
	vis[start]=1;
	can++;
	for(auto i:g[start])
		if(!vis[i])
			dfs(i);
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);
    #endif
        int n,m;
        cin>>n>>m;
        map<pair<int,int>,int>edge;
        for(int i=0;i<m;i++)
        {
        	int u,v;
        	cin>>u>>v;
        	u--,v--;
        	edge[{u,v}]++;
        	if(edge[{u,v}]==1)
        	{
        		g[u].push_back(v);
        		g[v].push_back(u);
        	}
        }
    	int ans=0;
    	for(int i=0;i<n;i++)
    	{
    		if(!vis[i])
    		{
    			can=0;
    			dfs(i);
    			ans=max(ans,can);
    		}
    	}
    	cout<<ans<<endl;
}

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

adj = [None]
for i in range(n):
    adj_i = list(map(int, input().split()[2:]))
    adj.append(adj_i)

# searched or not, number of vertex, discovery time and finishing time.
sndf = [None]
for i in range(1, n + 1):
    sndf.append([False, i])

path = []

time = 0

def dfs(u):
    global time
    sndf[u][0] = True
    time += 1
    sndf[u].append(time)

    for v in adj[u]:
        if not sndf[v][0]:
            dfs(v)
    sndf[u][0] = True
    time += 1
    sndf[u].append(time)


for i in range(1, n + 1):
    if not sndf[i][0]:
        dfs(i)

for x in sndf[1:]:
    print(*x[1:])

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

int main(){
  string s;
  cin >> s;
  int p = s.size();
  while(true){
  //cout << p << endl;
  //cout << s.substr(p-5,5) << endl;
  //cout << s.substr(p-6,6) << endl;
  if(0<=p-5&&(s.substr(p-5,5)=="dream"||s.substr(p-5,5)=="erase")){
    //cout << "hoge" << endl;
    p -= 5;
  }else if(0<=p-6&&s.substr(p-6,6)=="eraser"){
    //cout << "hogehoge" << endl;
    p -= 6;
  }else if(0<=p-7&&s.substr(p-7,7)=="dreamer"){
    p -= 7;
  }else{cout << "NO" << endl;return 0;}
    //cout << p << endl;
    if(p==0){cout << "YES" << endl;return 0;}
    //else if(p<0){cout << "NO" << endl;return 0;}
  }
}

    


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
#define PAI 3.14159265358979
// ver1.8
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(14);
  int n;
  cin >> n;
  int ans = 0,now = 0;
  int l = leng(n);
  int nagasa;
  int memo=0,ct=0;
  Vi a(1,1);
  
  while(n!=0){
    int memomemo=0;
    ans *= 2;
    now = n%10;
    n /= 10;
    nagasa = a.size();
    rep(i,0,nagasa) memomemo += a[i]*pow(10,nagasa-1-i);
    ans += now*memomemo;
    memo = pow(2,ct);
    ct++;
    a.pb(memo);
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n,a,b = gets.chomp.split.map(&:to_i)
ans = 0
(1..n).each do |i|
	temp = i
	sum = 0
	while temp > 0
		sum += temp % 10
		temp /= 10
	end
	if sum >= a && sum <= b
		ans += i
	end
end

puts ans

Measured memory_bytes: 1788
#include<iostream>
#include<cstring>
using namespace std;
const int MAXN = 100005;
int dp[MAXN], h[MAXN];
int main(){
	int n;
	int k;
	scanf("%d%d", &n, &k);
//	int h[n + 1];
//	int dp[n + 1];
//	memset(h,0,sizeof h);
	memset(dp,0x3f,sizeof dp);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &h[i]);
	
	dp[1] = 0;
	for(int i = 2; i <= n; i++){
		for(int j = max(i - k, 1); j < i; j++){
			dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
		}
	}
	printf("%d", dp[n]);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}// char to int
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}//MAX
int lcm(ll a,ll b){return a*b/gcd(a,b);}//MIN
 
int  main(){
ll n;
cin >> n;
ll ki=0;
for(ll i=0;i<n;i++){
    int z;
    cin >> z;
    if(z%2==1)ki++;
}
if(ki%2==0)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
 


Measured memory_bytes: 256
#include <cstdio>

const int MAXN = 6005;

template<typename _T>
void read( _T &x )
{
	x = 0;char s = getchar();int f = 1;
	while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
	x *= f;
}

template<typename _T>
void write( _T x )
{
	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
	if( 9 < x ){ write( x / 10 ); }
	putchar( x % 10 + '0' );
}

int f[MAXN][MAXN << 1];
int N, M;

void add( int &x, const int v ) { x += v; if( x >= M ) x -= M; }

int main()
{
	read( N ), read( M );
	int t = N * 3;
	f[0][t] = 1;
	for( int i = 1 ; i <= t ; i ++ )
		for( int j = - t ; j <= t ; j ++ )
		{
			if( j > -t ) add( f[i][j + t], f[i - 1][j + t - 1] ); //长度为1
			if( j < t && i >= 2 ) add( f[i][j + t], 1ll * f[i - 2][j + t + 1] * ( i - 1 ) % M ); //长度为2
			if( i >= 3 ) add( f[i][j + t], 1ll * f[i - 3][j + t] * ( i - 1 ) % M * ( i - 2 ) % M ); //长度为3 
		}
	int ans = 0;
	for( int i = 0 ; i <= t ; i ++ ) add( ans, f[t][i + t] );
	write( ans ), putchar( '\n' );
	return 0;
}

Measured memory_bytes: 282916
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
#define fprint(NUM,X) cout << fixed << setprecision(NUM) << (X) << endl
#define fprints(NUM,X,Y) cout << fixed << setprecision(NUM) << (X) << " " << (Y) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[550][550];
double w[1000],v[1000];
double box[200010];

#define MAX 10000
struct Edge{int to,cost;};
vector<Edge> G[MAX];
int mincost[MAX];
bool used[MAX];

int prim(){
  int res = 0;
  rep(i,0,n){
    mincost[i] = INF;
    used[i] = false;
  }
  mincost[0] = 0;
  while(1){
    int v = -1;
    rep(i,0,n){
      if(!used[i] && (v == -1 || mincost[i] < mincost[v]))v = i;
    }
    if(v == -1)break;
    used[v] = true;
    res += mincost[v];
    rep(i,0,G[v].sz){
      mincost[G[v][i].to] = min(mincost[G[v][i].to],G[v][i].cost);
    }
  }
  return res;
}

int main(){
  int m;
  int p,q,r;
  cin >> n >> m;
  rep(i,0,m){
    int p,q,r;
    cin >> p >> q >> r;
    G[p].pb(Edge{q,r});
    G[q].pb(Edge{p,r});
  }
  cout << prim() << endl;
  return 0;
}



Measured memory_bytes: 6024
#include "bits/stdc++.h"

using namespace std;

vector<int> parents;
vector<int> ranks;

void init(int n) {
    parents = vector<int>(n, 0);
    ranks = vector<int>(n, 0);
    for (int i = 0; i < n; ++i) {
        parents[i] = i;
    }
}

int find(int x) {
    if (parents[x] == x) {
        return x;
    }
    else {
        parents[x] = find(parents[x]);
        return parents[x];
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) {
        return;
    }
    if (ranks[x] > ranks[y]) {
        parents[y] = x;
    }
    else if (ranks[y] > ranks[x]) {
        parents[x] = y;
    }
    else {
        parents[x] = y;
        ++ranks[x];
    }
}

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

void Main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> edges(M, make_pair(0, 0));
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        edges[i] = make_pair(a, b);
    }

    int ans = 0;
    for (int i = 0; i < M; ++i) {
        init(N);
        for (int j = 0; j < M; ++j) {
            if (i == j) {
                continue;
            }
            unite(edges[j].first, edges[j].second);
        }
        bool connected = true;
        for (int j = 1; j < N; ++j) {
            if (!same(0, j)) {
                connected = false;
                break;
            }
        }
        if (!connected) {
            ++ans;
        }
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

int main(void) {
    int N;
    cin>>N;
    double p = (N % 2 == 0) ? (N / 2.0) / N: ((N + 1) / 2.0) / N;
    printf("%.6f\n", p);
    return 0;
}

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

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

using namespace std;


int main()
{
long long int Q,H,S,D,N;
long long int ans=0;
cin>>Q>>H>>S>>D>>N;
H=2*Q<H?2*Q:H;
S=2*H<S?2*H:S;
D=2*S<D?2*S:D;
while(N>=2){
    N-=2;
    ans+=D;
}
if(N==1){
    ans+=S;
}
cout<<ans<<endl;
}


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

ll powll(ll a,ll n){
  if(n==0)
  {
    return 1;
  }
  return powll(a,n-1)*a;
}


int main() {
   ll i,j,k;
   double l;
   cin >>l; 
   
   cout << std::fixed;
std::cout << std::setprecision(12) << l*l*l/27;
  //  cout<< l*l*l/27 <<endl;
}

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

using namespace std;

int main() {
  int n; cin >> n; 
  long long a, b; cin >> a >> b; n--;
  for (int i = 0; i < n; i++) {
    long long p, q; cin >> p >> q;
    long long x = max((a + p - 1) / p, (b + q - 1) / q);
    a = p * x;
    b = q * x;    
  }  
  cout << a + b << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
long long n, a[100005], sum, b[100005];
int main(){
	cin >> n;
	memset(a,0,sizeof(a));
	for (int i=0;i<n;i++)
		cin >> a[i];
	b[1]=abs(a[1]-a[0]);
	for (int i=2;i<n;i++){
		b[i]=min(b[i-2]+abs(a[i]-a[i-2]), b[i-1]+abs(a[i]-a[i-1]));
	} 
	cout << b[n-1];	
} 

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	int s[]{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int K;cin>>K;K--;
	cout<<s[K]<<endl;
}

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

int main(){
  long n,m,k;
  cin >> n >> m >> k;
  long a[n],b[m];
  rep(i,n)cin >> a[i];
  rep(i,m)cin >> b[i];
  long suma = 0,sumb = 0;
  long ka = 0,kb = 0;
  long ai = 0;
  rep(i,n){
    if(ka+a[i]<=k){
      suma++;
      ka += a[i];
      ai++;
    }
    else break;
  }
  long bi = 0;
  rep(i,m){
    if(ka+b[i]<=k){
      suma++;
      ka += b[i];
      bi++;
    }
    else break;
  }
  long ans = suma;
  long nsuma = suma;
  while(ai>0){
    ka -= a[ai-1];
    ai -= 1;
    nsuma -= 1;
    while(ka+b[bi]<=k && bi<m){
      ka += b[bi];
      nsuma += 1;
      bi++;
    }
    if(ans<nsuma)ans = nsuma;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6700
/******************************************
* AUTHOR : kamesh_11 *
* INSTITUTION : GVPCOE *
******************************************/

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

#define pi 3.141592653589793
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define bs binary_search
#define endl '\n'
#define start_clock clock_t beginn=clock()
#define end_clock clock_t endd=clock()
#define cal_exec_time double time_spent=(double)(endd-beginn)/CLOCKS_PER_SEC
#define print_exec_time cout<<endl<<time_spent<<" secs"

typedef long long int ll;

const ll MOD = 1000000007;

ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

ll calculate(ll arr[], ll n, ll i, ll j, ll taro, vector<vector<vector<ll>>>& dp){
	if(i>j || i>=n || j<0)
		return 0;

	if(dp[i][j][taro] != -1)
		return dp[i][j][taro];

	if(taro){
		ll l = arr[i] + calculate(arr, n, i+1, j, !taro, dp);
		ll r = arr[j] + calculate(arr, n, i, j-1, !taro, dp);
		return dp[i][j][taro] = max(l, r);
	}
	if(!taro){
		ll l = -arr[i] + calculate(arr, n, i+1, j, !taro, dp);
		ll r = -arr[j] + calculate(arr, n, i, j-1, !taro, dp);
		return dp[i][j][taro] = min(l, r);
	}
}

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

	ll n;
	cin>>n;
	ll arr[n];
	for(ll i=0;i<n;i++)
		cin>>arr[i];

	vector<vector<vector<ll>>>dp(n, vector<vector<ll>>(n, vector<ll>(2, -1)));
	cout<<calculate(arr, n, 0, n-1, 1, dp);

	return 0;
}

Measured memory_bytes: 493056
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    ll x, a, b;
    cin >> x >> a >> b;
    if ( b - a > x ) {
        cout << "dangerous" << endl;
    }
    else if ( b - a <= 0) {
        cout << "delicious" << endl;
    }
    else {
        cout << "safe" << endl;
    }
    return 0;
}


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

template<typename T> bool chmax(T &a,const T b){if(a < b){a=b; return true;} return false;}
template<typename T> bool chmin(T &a,const T b){if(a > b){a=b; return true;} return false;}

struct Edge {
    long long from;
    long long to;
    long long cost;
};
vi reach, seen;
vii adj;

void dfs(int v){
    seen[v]=true;
    for(auto nv: adj[v]){
        if(seen[nv]) continue;
        dfs(nv);
    }
    return;
}

bool bellman_ford(const vector<Edge> &Es, int V, int s, vector<long long> &dis) {
    dis.resize(V, LINF);
    dis[s] = 0;
    int cnt = 0;
    while (cnt < V) {
        bool end = true;
        for (auto e : Es) {
            if(!reach[e.from] || !reach[e.to]) continue;
            if (dis[e.from] != LINF && dis[e.from] + e.cost < dis[e.to]) {
                dis[e.to] = dis[e.from] + e.cost;
                end = false;
            }
        }
        if (end) break;
        cnt++;
    }
    return cnt==V;
}


int main(){
    int n, m, p;
    cin >> n >> m >> p;
    vector<Edge> Es(m);
    adj.assign(n, vi(0));
    for(int i=0; i<m; i++){
        cin >> Es[i].from >> Es[i].to >> Es[i].cost;
        Es[i].from--, Es[i].to--;
        Es[i].cost=-Es[i].cost+p;
        adj[Es[i].from].push_back(Es[i].to);
    }
    reach.assign(n, 0);
    for(int i=0; i<n; i++){
        seen.assign(n, 0);
        dfs(i);
        reach[i]=seen[n-1];
    }
    vector<ll> dis;
    ll ans;
    if(bellman_ford(Es, n, 0, dis)) ans=-1;
    else ans=max(0LL, -dis[n-1]);
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
const ll mod = 1e9 + 7;
const int MAXN = 1e5 + 1;
int n, m;
ll dp[MAXN];
bool visit[MAXN];

ll solve(int pos) {
	
	if (pos == n) return 1;
	if (visit[pos] || pos>n) return 0;

	ll& ret = dp[pos];

	if (ret != -1) return ret;

	ret = 0;

	ret += solve(pos + 1)%mod;
	ret += solve(pos + 2)%mod;

	return ret % mod;
}

int main() {

	cin >> n >> m;

	for (int i = 0; i < m; i++) {
		int val;
		cin >> val;
		visit[val] = true;
	}

	memset(dp, -1, sizeof(dp));

	cout << solve(0) % mod << "\n";

	return 0;
}

Measured memory_bytes: 4224
'use strict'

const main = (INPUT) => {
  const input = INPUT.split('\n')[0].split(' ').map(n => Number(n))
  const A = input[0]
  const B = input[1]
  const C = input[2]
  let ans
  if (C <= A + B) {
    ans = C + B
  } else {
    ans = (C + B) - (C - B - A) + 1
  }
  console.log(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 21064
import java.util.*;
public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int opt=0;
        for(int i=1;i<4;i++) if(S.charAt(i-1)==S.charAt(i)) opt++;
        if(opt==0) System.out.println("Good");
        else System.out.println("Bad");
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
using graph = vector<vector<ll>>;


int main() {
	ll a, b, k;
	cin >> a >> b >> k;
	if (a > k) {
		cout << a - k << " " << b << endl;
	}
	else if(a+b>k) {
		cout << 0 << " " << b + a - k << endl;
	}
	else {
		cout << 0 << " " <<0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 500005

char s[N], x;
int a[N];

int main()
{	 
	int i, j, n, f, k, t; 
	long long ans = 0;
	
	scanf("%s", s);
	f = (s[0] == '<');
	for(i = a[0] = 0; x = s[i]; i = j, f = !f){
		for(j = i + 1; s[j] == x; j++);
		if(f){
			for(k = i, t = 0; k <= j; k++, t++) a[k] = t;
		}
		else{
			for(k = j, t = 0; k > i; k--, t++) a[k] = t;
			if(t > a[i]) a[i] = t;
		}
	}
	for( ; i >= 0; i--) ans += a[i];
	printf("%lld\n", ans);	
		
	return 0;
}

Measured memory_bytes: 4136
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE

void DFS(int N,int depth,int num,string str,vector<string> &vec)
{
  if(depth == N)
  {
    // DEBUG(num,str);
    vec.push_back(str);
    return;
  }
  for (int i = 0; i < num+1; i++)
  {
    string str2 = str + char('a' + i);
    if(char('a' + i) >= 'a' + depth+1) return;
    DFS(N,depth+1,max(num,i+1),str2,vec);
  }
  

}
void solve(void)
{
  int N;
  cin>>N;
  string str = "a";
  vector<string> vec;
  DFS(N,1,1,str,vec);
  sort(ALL(vec));
  for (int i = 0; i < vec.size(); i++)
  {
    cout<<vec[i]<<endl;
  }
  
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 7796
#include<bits/stdc++.h>
using namespace std;
int lg(int a) {
  int k = 1;
  int kj = 10;
  while (a >= kj) {
    k ++;
    kj *= 10;
  }
  return k;
}
int main () {
  int N, M;
  cin >> N >> M;
  vector<tuple<int, int, int>>P(M);
  vector<pair<int, int>>ans(M);
  for (int i = 0; i < M; i ++) {
    int p, x;
    cin >> p >> x;
    P[i] = make_tuple(p, x, i);
  }
  sort(P.begin(), P.end());
  int j = 0;
  for (int i = 1; i <= N; i ++) {
    int al = 1;
    while (j < M && get<0>(P[j]) == i) {
      int p, y, kj;
      tie(p, y, kj) = P[j];
      ans[kj] = make_pair(p, al);
      al ++;
      j ++;
    }
  }
  for (int i = 0; i < M; i ++) {
    int p, y;
    tie(p, y) = ans[i];
    int a = lg(p);
    int b = lg(y);
    for (int j = 0; j < 6 - a; j ++) cout << 0;
    cout << p;
    for (int j = 0; j < 6 - b; j ++) cout << 0;
    cout << y << endl;
  }
  //cout << lg(N) << endl;
  //cout << lg(M) << endl;
}



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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

const int INF = 1 << 29;
// const ll INF = 1LL << 62;
// const int MOD = 1000000007;

int main() {
  int N, M, R;
  cin >> N >> M >> R;

  vector<int> r(R);
  rep (i, R) {
    cin >> r[i];
    r[i]--;
  }

  int d[N][N];
  rep (i, N) rep (j, N) d[i][j] = (i == j) ? 0 : INF;

  rep (i, M) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    d[a][b] = d[b][a] = c;
  }

  rep (k, N) rep (i, N) rep (j, N) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

  sort(all(r));
  int ans = INF;

  do {
    int sum = 0;
    rep (i, R - 1) sum += d[r[i]][r[i + 1]];
    ans = min(ans, sum);
  } while (next_permutation(all(r)));

  cout << ans << endl;
}


Measured memory_bytes: 384
def main():
  from collections import deque
  k=int(input())
  e=[[]for _ in range(k)]
  for i in range(k):
    e[i].extend([(i*10%k,0),(-~i%k,1)])
  q=deque([1])
  p,l,r=q.pop,q.appendleft,q.append
  f=[10**18]*k
  f[1]=1
  while q:
    v=p()
    for w,d in e[v]:
      c=f[v]+d
      if f[w]>c:
        (r,l)[d](w)
        f[w]=c
  print(f[0])
main()

Measured memory_bytes: 35316
#include<cstdio>
#include<vector>
#include<utility>
#include<algorithm>

using namespace std;

typedef pair<int,int> P;

const int inf=1<<29;

int xs[100100],ys[100100];

P ps[2][100100];

int N;

vector<int> tmp;

bool judge(int M)
{
	int t=-1;
	if(ps[0][N-1].first-ps[0][0].first>M) t=0;
	if(ps[1][N-1].first-ps[1][0].first>M) t=1;
	if(t==-1) return true;
	int x=ps[t][0].first,y=ps[t][N-1].first;
	int i1,i2;
	for(int i=0;i<N;i++) if(ps[t][i].first<=x+M) i1=i;
	for(int i=N-1;i>=0;i--) if(ps[t][i].first>=y-M) i2=i;
	if(i2>=i1+2) return false;
	int ma=inf,Ma=-inf,mb=inf,Mb=-inf;
	for(int i=0;i<i2;i++)
	{
		ma=min(ma,ps[t][i].second);
		Ma=max(Ma,ps[t][i].second);
	}
	for(int i=N-1;i>i1;i--)
	{
		mb=min(mb,ps[t][i].second);
		Mb=max(Mb,ps[t][i].second);
	}
	if(Ma-ma>M||Mb-mb>M) return false;
	if(i2==i1+1)
	{
		return true;
	}
	if(ma>mb)
	{
		swap(ma,mb);
		swap(Ma,Mb);
	}
	tmp.clear();
	for(int i=i2;i<=i1;i++)
	{
		int a=ps[t][i].second;
		if(ma<=a&&a<=Ma) continue;
		if(mb<=a&&a<=Mb) continue;
		tmp.push_back(ps[t][i].second);
	}
	if(tmp.empty()) return true;
	sort(tmp.begin(),tmp.end());
	int mm=tmp[0],MM=tmp[tmp.size()-1];
	if(mb<=Ma)
	{
		int la=min(mm,ma),ra=max(MM,Ma);
		if(ra-la<=M) return true;
		la=min(mm,ma),ra=Ma;
		int lb=mb,rb=max(MM,Mb);
		if(ra-la<=M&&rb-lb<=M) return true;
		la=ma,ra=max(MM,Ma);
		lb=min(mm,mb),rb=Mb;
		if(ra-la<=M&&rb-lb<=M) return true;
		la=ma,ra=Ma;
		lb=min(mm,mb),rb=max(Mb,MM);
		if(ra-la<=M&&rb-lb<=M) return true;
		return false;
	}
	if(Mb<=mm)
	{
		if(MM-mb<=M) return true;
		return false;
	}
	else if(Ma<=mm&&mm<=mb)
	{
		int i3=-1;
		for(int i=0;i<tmp.size();i++)
		{
			if(tmp[i]-ma<=M) i3=i;
		}
		if(i3==tmp.size()-1) return true;
		int lb=min(tmp[i3+1],mb),rb=max(Mb,tmp[tmp.size()-1]);
		if(rb-lb<=M) return true;
		return false;
	}
	else
	{
		
		if(Ma-mm>M) return false;
		int i3;
		for(int i=0;i<tmp.size();i++)
		{
			if(tmp[i]-mm<=M) i3=i;
		}
		if(i3==tmp.size()-1) return true;
		int lb=min(tmp[i3+1],mb),rb=max(Mb,tmp[tmp.size()-1]);
		if(rb-lb<=M) return true;
		return false;
	}
}

int main()
{
	scanf("%d",&N);
	for(int i=0;i<N;i++)
	{
		scanf("%d%d",xs+i,ys+i);
		ps[0][i]=P(xs[i]+ys[i],xs[i]-ys[i]);
		ps[1][i]=P(xs[i]-ys[i],xs[i]+ys[i]);
	}
	sort(ps[0],ps[0]+N);
	sort(ps[1],ps[1]+N);
	int lb=0,ub=400200;
	//int lb=0,ub=6;
	//for(int i=0;i<N;i++)
	//{
	//	printf("%d %d %d %d\n",ps[0][i].first,ps[0][i].second,ps[1][i].first,ps[1][i].second);
	//}
	while(ub-lb>1)
	{
		//(lb,ub]
		int mid=(lb+ub)/2;
		//printf("judge %d\n",mid);
		if(judge(mid)) ub=mid;
		else lb=mid;
	}
	printf("%d\n",ub);
	return 0;
}

Measured memory_bytes: 3528
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

ll V;
vector<vector<ll>> G;
vector<ll> match;
vector<int> used;

void add_edge(ll u, ll v) {
	G[u].push_back(v);
	G[v].push_back(u);
}

bool dfs(ll v) {
	used[v] = 1;
	for (int i = 0; i < G[v].size(); i++) {
		ll u = G[v][i], w = match[u];
		if (w < 0 || ((used[w] == 0) && dfs(w))) {
			match[v] = u;
			match[u] = v;
			return true;
		}
	}
	return false;
}

ll bipartite_matching() {
	ll res = 0;
	for (int i = 0; i < (int)match.size();i++)match[i] = -1;
	for (int v = 0;v < V;v++) {
		if (match[v] < 0) {
			for (int i = 0; i < (int)used.size();i++)used[i] = 0;
			if (dfs(v))res++;
		}
	}
	return res;
}

/* use example */
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll X, Y, E; cin >> X >> Y >> E;
	V = X + Y + 2; // initialize V [0..index]
	G.resize(V); used.resize(V); match.resize(V); // initialize G used match
	for (int i = 0; i < E;i++) {
		ll x, y; cin >> x >> y;
		add_edge(x, y + X);
	}
	cout << bipartite_matching() << endl;
	return 0;
}



Measured memory_bytes: 3252
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,q;

int main(){
  ll ans=0;
  cin >> n;
  vi a(n),an(100001);//an[x]はxという数をいくつ持っているか
  REP(i,n) cin>>a[i];

  ll gw=0;
  for(ll i=0;i<n;i++){
    an[a[i]]++;
    gw+=a[i];
  }

  cin >> q ;
  vi b(q),c(q);
  REP(i,q) cin>>b[i]>>c[i];



  for(ll i=0;i<q;i++){
    ll num=an[b[i]];
    an[b[i]]=0;
    an[c[i]]+=num;
    gw+=(c[i]-b[i])*num;

    cout<<gw<<endl;
  }



  
  return 0;
}

Measured memory_bytes: 6424
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <math.h>
#include <map>
#include <numeric>
using namespace std;
typedef long long int ll;

int num(string s){
	int res=0;
	int t=1;
	for(char c:s){
		if('2'<=c&&c<='9'){
			t=c-'0';
		}
		else{
			if(c=='m'){
				res+=t*1000;
			}
			else if(c=='c'){
				res+=t*100;
			}
			else if(c=='x'){
				res+=t*10;
			}
			else{
				res+=t;
			}
			t=1;
		}
	}
	return res;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int q; cin >> q;
	while(q--){
		string s,t; cin >> s >> t;
		int res=num(s)+num(t);
		if(res>=1000){
			int t=res/1000;
			if(t>1)cout << t;
			cout << 'm';
			res%=1000;
		}
		if(res>=100){
			int t=res/100;
			if(t>1)cout << t;
			cout << 'c';
			res%=100;
		}
		if(res>=10){
			int t=res/10;
			if(t>1)cout << t;
			cout << 'x';
			res%=10;
		}
		if(res>=1){
			int t=res/1;
			if(t>1)cout << t;
			cout << 'i';
			res%=1;
		}
		cout << endl;
	}

}


Measured memory_bytes: 3200
#include <iostream>
using namespace std;
using ll = long long;
int n;
ll t;
int a[200002];
void inp()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        if (a[i] < a[i-1])
        {
            t += a[i-1]-a[i];
            a[i] = a[i-1];
        }
    }
}
void process()
{
    cout << t;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("test.inp","r", stdin);
    inp();
    process();
    return 0;
}


Measured memory_bytes: 4428
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main(){
	int N;
	cin >> N;
	int T[N];
	for(int i = 0; i < N; i++){
		cin >> T[i];
	}
	int sum = 0;
	for(int i = 0; i < N; i++){
		sum += T[i];
	}
	int M = 0;
	cin >> M;
	for(int i = 0; i < M; i++){
		int P, X;
		cin >> P >> X;
		cout << sum-T[P-1]+X << "\n";
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <set>
#include <map>
#include <list>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define MOD 1000000007
#define PI 3.1415926535897932
#define rep(i, n) for (int i = 0; i < n; i++)
#define repe(i, j, n) for (int i = j; i < n; i++)
#define repi(i, n) for (int i = 0; i <= n; i++)
#define repie(i, j, n) for (int i = j; i <= n; i++)
#define all(x) x.begin(), x.end()
#define println() cout << endl
#define P pair<int, int>
#define fi first
#define se second

typedef long long ll;

long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

void solve1()
{
    int n; cin >> n;

    ll ans = 0;
    if(n <= 1) {
       ans = 0;
    } else {
        ans = 1;
        ll d1 = 1;
        ll d2 = 1;
        for(int i = 0; i < n; i++) {
            ans *= 10;
            ans %= MOD;
            d1 *= 9;
            d1 %= MOD;
        }
        d1 *= 2;
        d1 %= MOD;

        for (int i = 0; i < n; i++)
        {
            d2 *= 8;
            d2 %= MOD;
        }
        d2 %= MOD;

        ll d = d1 - d2;
        if(d < 0) {
            d += MOD;
        }
        ans -= d;
        if(ans < 0) {
            ans += MOD;
        }
    }

    cout << ans << endl;



}

int main()
{
    solve1();
}


Measured memory_bytes: 3628
import java.math.BigInteger;
import java.util.Scanner;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;

public class Main {
 public static void main(String[] args) {
	Pattern pattern = Pattern
	  .compile("([0-9X]+)\\+([0-9X]+)=([0-9X]+)");
	Scanner in = new Scanner(System.in);
	while (in.hasNext(pattern)) {
	 in.next(pattern);
	 MatchResult mr = in.match();
	 String a = mr.group(1);
	 String b = mr.group(2);
	 String c = mr.group(3);
	 int num = 0;
	 if ((a.startsWith("X") && (a.length() > 1)) ||
		 (b.startsWith("X") && (b.length() > 1)) ||
		 (c.startsWith("X") && (c.length() > 1))) {
		num++;
	 }
	 char cnum = 'N';
	 for (; num <= 9; num++) {
		cnum = Character.forDigit(num, 10);
		BigInteger ia = new BigInteger(a.replace('X', cnum));
		BigInteger ib = new BigInteger(b.replace('X', cnum));
		BigInteger ic = new BigInteger(c.replace('X', cnum));
		if (ia.add(ib).equals(ic)) {
		 break;
		} else {
		 cnum = 'N';
		}
	 }
	 if (cnum == 'N') {
		System.out.println("NA");
	 } else {
		System.out.println(cnum);
	 }
	}
 }
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    bool ans=false;
    for(int i=1;i<=b;i++){
        if(i*a%b==c){
            ans=true;
            break;
        }
    }
    if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	//soal F
	long long int N; //test case
	long long int g = 1; //buat hasil perkalian
	scanf("%lld", &N);
	long long int h[N]={}; //array buat menampung angka

		for(long long int i=0;i<N;i++){
			scanf("%lld", &h[i]);  
		} 
		for(int j=0;j<N;j++){
			if (h[j] == 0){
	 			printf("0");
 				return 0;
			}
		}
		for(int k=0;k<N;k++){
 			if (h[k] <= 1000000000000000000/g){
 			g *= h[k];
		} else {
			printf("-1");
			return 0;
		}
	}	
		printf("%lld",g);
	return 0;
}
/*
cek inputan sekarang dia > 10^18
inputan ->10^18 / total

long long tc;
long long hasil = 1;
scanf("%lld", &n);

long long input[tc];
for (int i=0;i<tc;i++){
scanf("%lld", input)
}

for(int i=0;i<tc;i++){
 if (input[i] == 0){
 		printf("0");
 		return 0;
}
for(int i=0;i<tc;i++){
 if (input[i] > 1000000/hasil){
 		hasil *= input[i]
} else {
	}

*/

Measured memory_bytes: 2496
N = gets.to_i
A = gets.split.map &:to_i
puts A*' '
for i in (1...N)
  v = A[i]
  j = i - 1
  while j >= 0 && A[j] > v
    A[j+1] = A[j]
    j -= 1
  end
  A[j + 1] = v
  puts A*' '
end



Measured memory_bytes: 6892
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
#define ll long long
#define dd double
#define vi vector<int> 
#define li list<int> 
#define pb push_back
// int a[200009];
 	// int b[200009];
 	// int c[200009];
 int main()
 {
 	char c;
 	cin >> c;

 	if(c >= 'A' && c <= 'Z' ) cout << "A" << endl;
 	else cout << "a" << endl;

 	return 0;
 }

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 998244353LL;

const int N = 1e6;
ll fac[N], ifac[N];

ll qpow(ll a, ll n){
	if(n==1) return a;
	ll ans = qpow(a, n/2);
	ans = (ans*ans)%MOD;
	return n%2==0 ? ans : (ans*a)%MOD;
}

ll comb(int n, int a){
	ll ans = fac[n];
	ans = (ans*ifac[a])%MOD;
	ans = (ans*ifac[n-a])%MOD;
	return ans;
}

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

	ll n, a, b, k;
	cin >> n >> a >> b >> k;

	fac[0] = 1;
	ifac[0] = 1;

	for(int i=1; i<=n; i++){
		fac[i] = (fac[i-1] * i) % MOD;
		ifac[i] = (ifac[i-1] * qpow(i, MOD-2)) % MOD;
	}

	ll ans = 0;

	for(int i=0; i<=n; i++){
		ll ta = i;
		ll tb = (k-ta*a) / b;

		if(ta*a+tb*b == k && 0 <= tb && tb <= n){
			ans += (comb(n, ta) * comb(n, tb)) % MOD;
			ans %= MOD;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 8448
#include <cstdio>
#include <algorithm>
long long n, k, a[100005];
int main() {
	int i;
	scanf("%d", &n);
	for(i=1; i<=n; i++) scanf("%d", a+i);
	std::sort(a+1, a+n+1);
	for(i=1; i<n-1; i++) {
		a[i] += a[i-1];
		if(a[i]*2 < a[i+1]) k = i;
	}
	printf("%d", n-k);
	return 0;
}

Measured memory_bytes: 896
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<ll> par;
//     vector<ll> siz;
    
//     UnionFind(ll N): par(N), siz(N,1) {
//         for (ll i=0;i<N;i++) par[i] = i;
//     }

//     ll root(ll x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         if (rx == ry) return;
//         // if (siz[rx] < siz[ry]) swap(rx,ry);
//         par[rx] = ry;
//         siz[ry] += siz[rx];
//     }

//     bool same(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         return rx == ry;
//     }

//     ll size(ll x) {
//         return siz[root(x)];
//     }
// };

//     vector<ll> par;
//     vector<ll> siz;
    
//     UnionFind(ll N): par(N), siz(N,1LL) {
//         for (ll i=0;i<N;i++) par[i] = i;
//     }

//     ll root(ll x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//         siz[ry] += siz[rx];
//     }

//     bool same(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         return rx == ry;
//     }

//     ll size(ll x) {
//         return siz[root(x)];
//     }
// };

vector<ll> p;

void init(void) {
    p.push_back(2);
    for (int i=3;i<=1000000;i++) {
        bool flag = true;
        for (int j=2;j*j<=i;j++) {
            if (i%j == 0) {
                flag = false;
                break;
            }
        }
        if (flag) p.push_back(i);
    }
}

int main(void) {
    init();
    ll N;
    cin >> N;
    map<int,int> q;
    vector<int> r(20);
    for (int i=0;i<20;i++) r[i] = i*(i+1)/2;
    for (auto itr: p) {
        if (N%itr == 0) {
            while (N) {
                q[itr]++;
                N /= itr;
                if (N%itr) break;
            }
        }
    }
    if (N>1) q[N]++;
    ll res = 0;    
    for (auto itr: q) {
        // cout << itr.second << endl;
        res += upper_bound(r.begin(),r.end(),itr.second) - r.begin() - 1;
    }
    cout << res << endl;


    return 0;
}


Measured memory_bytes: 4124
N = int(input())
h = [int(i) for i in input().split()]

dp = [0]*N
dp[0] = 0
dp[1] = abs(h[0]-h[1])

for i in range(2, N):
    dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]), dp[i-1]+abs(h[i]-h[i-1]))
print(dp[N-1])

Measured memory_bytes: 13928
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
            int a,b,c;
            a = sc.nextInt();
            b = sc.nextInt();
            c = sc.nextInt();
            if(a<b&&b<c){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }
    }
}


Measured memory_bytes: 26324
//Total Time
#include <iostream>

using namespace std;

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int t, x, y;
    t = A + B + C + D;
    x = t / 60;
    y = t % 60;
    cout << x << endl;
    cout << y << endl;

    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define int long long

using namespace std;

vector<pair<int, int> > l1;
priority_queue<int, vector<int>, greater<int> > q1;
vector<pair<int, int> > l2;
priority_queue<int, vector<int>, greater<int> > q2;

signed main() {
	int t, n, k, l, r, s1, s2;
	cin >> t;
	while(t--) {
		s1 = 0;
		s2 = 0;
		int n;
		cin >> n;
		for(int i = 0; i < n; i++) {
			cin >> k >> l >> r;
			if(l < r) {
				l2.push_back({n-k, r-l});
			}
			else l1.push_back({k, l-r});
			s1 += min(l, r);
		}
		sort(l1.begin(), l1.end());
		sort(l2.begin(), l2.end());
		for(int i = 0; i < l1.size(); i++) {
			if(l1[i].first == 0) continue;
			if(q1.size() < l1[i].first) q1.push(l1[i].second);
			else if(q1.size() == l1[i].first && q1.top() < l1[i].second) {
				q1.pop();
				q1.push(l1[i].second);
			}
		}
		while(q1.size()) {
			s1 += q1.top();
			q1.pop();
		}
		for(int i = 0; i < l2.size(); i++) {
			if(l2[i].first == 0) continue;
			if(q2.size() < l2[i].first) q2.push(l2[i].second);
			else if(q2.size() == l2[i].first && q2.top() < l2[i].second) {
				q2.pop();
				q2.push(l2[i].second);
			}
		}
		while(q2.size()) {
			s1 += q2.top();
			q2.pop();
		}
		cout << s1 << '\n';
		vector<pair<int, int> >().swap(l1);
		vector<pair<int, int> >().swap(l2);
	}
}

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

int main() {
    int n;
    std::cin >> n;

    auto b = std::vector<int>();
    b.reserve(n - 1);

    for(int i = 0; i < n - 1; ++i) {
        int bi;
        std::cin >> bi;
        b.push_back(bi);
    }

    int answer = b[0] + b[n - 2];

    for(int i = 0; i < n - 2; ++i) {
        answer += std::min(b[i], b[i + 1]);
    }

    std::cout << answer;

    return 0;
}


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

 main()
{
  int a, s, d;
  cin >> a >> s >> d;
   if(a>d){
     cout<<"NO"<<endl;
     return 0;
   }
  if(s>=d-a)
    cout << "YES" << endl;
    else
      cout << "NO" << endl;

}


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

int main(){
  int n;
  cin >> n;
  rep(i,n-1) {
    for(int  j = i+1; j < n; j++) {
      int a = j - i;
      int k = 1;
      while(a % 2 == 0) {
        a /= 2;
        k++;
      }
      cout << k << " ";
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 512
object Main extends App {                                                                                                                                      val sc = new java.util.Scanner (System.in)
  val m,n = sc.nextInt
  def prod(x:Int):BigInt = if (x <= 1) BigInt(1) else BigInt(x) * prod(x - 1)
  def comb(num:Int,r:Int):Int= if( r <= num ) (prod(num) / ( prod(num-r) * prod(r))).intValue() else 0
  val result = comb(m,2) + comb(n,2)
  println(result)
}

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

int main(){
    int N,M,C,count=0;
    cin>>N>>M>>C;
    int B[M],A[N][M];
    for(int i=0;i<M;i++){
        cin>>B[i];
    }
    for(int j=0;j<N;j++){
        int tmp = 0;
        for(int k=0;k<M;k++){
            cin>>A[j][k];
            tmp += A[j][k] * B[k];
        }
        tmp += C;
        if(tmp>0) count++;
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 764
#include<stdio.h>

int main() {

   int a[20] = {0};
   int box[2001][21] = {0};
   int m[200] = {0};
   int n, q, i, j, swap;

   scanf("%d", &n);

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

      scanf("%d", &q);

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


   for(i = 0; i < n; i++){
      for(j = 1; j <= 2000; j++){

         if(j - a[i] >= 0 && (box[j - a[i]][i] + a[i] ) >= box[j][i]){
            box[j][i+1] = box[j - a[i]][i] + a[i];
         } else {
            box[j][i+1] = box[j][i];
         }


      }
   }


   for(i = 0; i < q; i++){
      if(box[m[i]][n] == m[i]){
         printf("yes\n");
      } else {
         printf("no\n");
      }
   }

   return 0;
}

Measured memory_bytes: 2760