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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; read(n);
	vector<ll> v(n + 1), nodes(n + 1), ps(n + 1);
	rep(i, 0, n + 1) read(v[i]);
	rep(i, 1, n + 1) ps[i] = ps[i - 1] + v[i];

	if (n == 0) {
		if (v[0] == 1) die(1);
		else die(-1);
	}
	if (v[0] != 0) die(-1);
	if (v[1] > 2) die(-1);

	{
		ll cnt = 0;
		for (int i = n; i >= 1; i--) {
			cnt = (cnt + v[i] + 1) / 2;
		}
		if (cnt > 1) {
			//printf("BAD COUNT: %d\n", cnt);
			die(-1);
		}
	}

	nodes[0] = 1;
	
	const ll MAX = 1e16;
	for (int i = 1; i <= n; i++) {
		nodes[i] = MAX;
		chmin(nodes[i], (nodes[i - 1] - v[i - 1]) * 2);
		chmin(nodes[i], ps[n] - ps[i] + v[i]);
		//printf("%d: %d\n", i, nodes[i]);
	}

	ll ans = 0;
	rep(i, 0, n + 1) ans += nodes[i];
	die(ans);
}


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


int gcd(int a, int b) 
{ 
    // Everything divides 0  
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
   
    // base case 
    if (a == b) 
        return a; 
   
    // a is greater 
    if (a > b) 
        return gcd(a-b, b); 
    return gcd(a, b-a); 
} 

int main()
{int n;
	// string s;
	cin>>n;
	int sum=0;
	int x,b;
	// vector<tuple<int ,int ,int>>v1; 
	int ar1[n],ar2[n],ar3[n];
	for(int i=1;i<=n;i++)
		{for(int j=1;j<=n;j++)
		     { for(int k=1;k<=n;k++)
		          {  //cout<<i<<j<<k<<endl;   
		          	 x=gcd(i,j);
		          	 b=gcd(x,k);
                     sum+=b;


		         

		                       }
		                   }

		               }

		
		cout<<sum;




}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
void dump(){cout<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cout<<h<<", ";dump(forward<Ts>(t)...);}
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

void solve1();void solve2();
int main(){
  solve1();
  return 0;
}

void solve1(){

  ll n,t;
  cin>>n>>t;
  using pll = pair<ll,ll>;
  vector<pll> a(n);
  cin>>a;

  sort(a.begin(),a.end());
  auto dp = make_vector<ll>(6010,6010);
  rep(i,n){
    rep(j,t){
      if(i>0)chmax(dp[i][j],dp[i-1][j]);
      if(j>0)chmax(dp[i][j],dp[i][j-1]);
      if(i>0&&j>0)chmax(dp[i][j],dp[i-1][j-1]);
      chmax(dp[i+1][j+a[i].first],dp[i][j]+a[i].second);
    }
  }

  ll ans = 0;
  for(auto y:dp)for(auto x:y)chmax(ans,x);

  cout<<(ans)<<endl;

}

Measured memory_bytes: 282880
N = gets.to_i
a = gets.split.map {|i| i.to_i}

cnt = 0

0.upto(N - 1) do |i|
	minj = i
	i.upto(N - 1) do |j|
		minj = j if a[j] < a[minj]
	end
	if i != minj
		a[i], a[minj] = a[minj], a[i]
		cnt += 1
	end
end

puts a.join(" ")
puts cnt

Measured memory_bytes: 8612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int A,B,X;
  cin >> A >> B >> X;
  if(A <= X && X <= A+B) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define NIL -1
typedef struct{
  int p;
  int l;
  int r;
  int id;
} Tree;

Tree tree[1000000];
int depth(int u){
  int depth = 0;
  while(tree[u].p != NIL){
    ++depth;
    u = tree[u].p;
  }
  return depth;
}
void print_child(int i){
  if(tree[i].l == NIL){
    printf("[]");
    return;
  }
  printf("[");
  int child = tree[i].l;
  while(1){
    printf("%d", tree[child].id);
    child = tree[child].r;
    if(child == NIL)
      break;
    else
      printf(", ");
  }
  printf("]");
}
void print_node(int i){
  if(tree[i].p == -1){
    printf("root, ");
    print_child(i);
  }
  else if(tree[i].l != -1){
    printf("internal node, ");
    print_child(i);
  }
  else
    printf("leaf, []");
}
void print(int n){
  for(int i = 0; i < n; ++i){
    printf("node %d: parent = %d, ", tree[i].id, tree[i].p);
    printf("depth = %d, ", depth(i));
    print_node(i);
    printf("\n");
  }
}
int main(){
  int n, id, k, c[100000];
  scanf("%d", &n);
  for(int i = 0; i < n; ++i){
    tree[i].p = NIL;
    tree[i].l = NIL;
    tree[i].r = NIL;
  }
  
  for(int i = 0; i < n; ++i){
    scanf("%d%d", &id, &k);
    tree[id].id = id;
    for(int j = 0; j < k; ++j){
      scanf("%d", &c[j]);
      tree[c[j]].p = id;
      if(j == 0)
        tree[id].l = c[j];
      else
        tree[c[j-1]].r = c[j];
    }
  }
  print(n);
  return 0;
}



Measured memory_bytes: 3748
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using uint64 = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
#define dbg(vec) for (size_t _ = 0; _ < vec.size(); ++_){std::cerr << #vec << "[" << _ << "] : " << vec[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;  // 1.073741823e9
const int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
const int MOD = 1000000007;

const double pi = 3.141592653589793;
vector<double> x(101), y(101);
int n; 

inline double naiseki(const double& x1, const double& y1, const double& x2, const double& y2) {
  return x1 * x2 + y1 * y2;
}

// 角度 theta の方向を最終的に向くとして計算
// theta は radian
double calc(const double& theta) {
  double res = 0.0;
  double dx = cos(theta), dy = sin(theta);
  for (int i = 0; i < n; ++i) {
    res += max(0.0, naiseki(dx, dy, x[i], y[i]));
  }
  return res;
}

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

  auto start = chrono::system_clock::now();

  cin >> n;
  rep(i, n) cin >> x[i] >> y[i];

  int step = 7777777;

  double ans = 0.0;

  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<> r(0, step);

  auto msec = 0.0;

  do {
    double theta = 2.0 * pi * r(mt) / step;
    chmax(ans, calc(theta));
    auto end = chrono::system_clock::now();
    auto dur = end - start;
    msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
  } while (msec <= 1997);

  cout << setprecision(15) << ans << '\n';

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  set<int> kinds;
  for (int i = 0; i < N; i++) {
    int d;
    cin >> d;
    kinds.insert(d);
  }
  
  cout << kinds.size() << endl;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = a; i >= (b); --i)
#define trav(a, x) for(auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;



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

  ll n, x, m;
  cin >> n >> x >> m;
  x %= m;
  vi v{(int)x}, hash(m);
  ll cycle = -1, l = x, i = 1;
  hash[x] = 1;
  for (; i < n; i++) {
    ll t = (l * l) % m;
    if (hash[t]) {
      for (int k = 0; k < sz(v); k++) {
        if (v[k] == t) {
          cycle = k;
          break;
        }
      }
      break;
    }
    hash[t] = 1;
    l = t;
    v.push_back(t);
  }

  if (cycle == -1) {
    ll res = 0;
    for (auto e : v)
      res += e;
    cout << res;
    return 0;
  }
  
  ll res = 0;
  for (int j = 0; j < cycle; j++)
    res += v[j];
  ll len = i - cycle;
  ll t = (n - cycle) / len;
  ll r = n, tmp = 0;
  r -= cycle + t * len;

  for (int j = 0; j < len; j++) {
    if (j < r) {
      res += v[cycle + j];
    }
    tmp += v[cycle + j];
  }

  res += tmp * t;
  cout << res;
}

Measured memory_bytes: 3964
N, L = map(int, input().split())
import copy
j_sum = 0
absum = 0
j_sum_max = 0
ab = 0
for i in range(1, N+1):
    ab += L+i-1
for i in range(1, N+1):
    for j in range(1, N+1):
        if j != i:
            j_sum += L+j-1
    if i == 1:
        absum = abs(ab-j_sum)
        j_sum_max = copy.copy(j_sum)
        j_sum = 0
    else:
        if absum > abs(ab-j_sum):
            absum = abs(ab-j_sum)
            j_sum_max = copy.copy(j_sum)
            j_sum = 0
print(j_sum_max)

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

typedef long long ll;
ll n, i, j, ans, z;
int main()
{
	ll n;
	cin >> n;
	i = n;
	z = 1;
	while (i >= 10) {
		ans += 9;
		if (i % 10 < 9) z = 0;
		i /= 10;
	}
	if (z) ans += i;
	else ans += i - 1;
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
import math

a, b, x = map(int, input().split())

if a**2*b >= 2*x:
  l, r = 0-10**(-9), 90-math.degrees(math.atan(b/a))+10**(-9)
  while r-l > pow(10, -7):
    k = (r+l)/2
    if x <= a*b*b*math.tan(math.radians(k))/2:
      r = k
    else:
      l = k
  ans = 90-(r+l)/2
else:
  l, r = 0-10**(-9), math.degrees(math.atan(b/a))+10**(-9)
  while r-l > pow(10, -7):
    k = (r+l)/2
    if a**2*b-x <= a**3*math.tan(math.radians(k))/2:
      r = k
    else:
      l = k
  ans = (r+l)/2
print(ans)





Measured memory_bytes: 3064
N=int(input())
A=list(map(int, input().split()))+[0]

i=0
kane=1000
kabu=0
while i<N:
  if kabu==0:
    if A[i]<A[i+1]:
      kabu=kane//A[i]
      kane=kane%A[i]
    else:
      pass
  else:
    if A[i]>A[i+1]:
      kane=kane+kabu*A[i]
      kabu=0
    else:
      pass
  i+=1
  
print(kane)

Measured memory_bytes: 9196
#include <iostream>
#include <stdio.h>

using namespace std;

int main(){
	int n[102], tn=0,ni=0,all = 0, i = 0,h=0;
	int data[1024][10];
	int tdata[10] = { 0 };
	
	//input
	while (1){
		cin >> n[ni];
		if (n[ni] == 0)break;
		tn += n[ni];

		for (; i < tn; i++){
			for (int j = 0; j < n[ni]; j++){
				cin >> data[i][j];
			}
		}
		ni++;
	}


	//output
	for (int k = 0; k < ni; k++){
		for (int i=0; i < n[k]; i++, all = 0,h++){
			for (int j = 0; j < n[k]; j++){
				printf("%5d", data[h][j]);
				all += data[h][j];
				tdata[j] += data[h][j];
			}
			printf("%5d\n", all);
		}

		all = 0;
		for (int i = 0; i < n[k]; i++){
			printf("%5d", tdata[i]);
			all += tdata[i];
		}
		printf("%5d\n", all);

		for (int i = 0; i < n[k]; i++){
			tdata[i] = 0;
		}
		all = 0;
	}
	return 0;
}

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

int main(){
    char str[4];
    scanf("%s",str);
    int ans=0;
    for(int i=0;i<4;i++){
        if(str[i]=='+'){
            ans++;
        }else{
            ans--;
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 128
import itertools

a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0
for aa, bb, cc in itertools.product(range(a + 1), range(b + 1), range(c + 1)):
    s = aa * 500 + bb * 100 + cc * 50
    if s == x:
        count += 1

print(count)


Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>

int main() {
  int a[3];
  for(int i=0; i<3; ++i) {
    scanf("%d", a+i);
  }
  std::sort(a, a+3);
  printf("%s", a[0]==5&&a[1]==5&&a[2]==7?"YES":"NO");
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <ios>
using namespace std;
 
int cnt = 0;
void insertionSort(vector<long>& A, int n, int g){
    long i, j, v;
    for (i = g; i < n; ++i){
        v = A[i];
        j = i - g;
        while ( j >= 0 && A[j] > v){
            A[j + g] = A[j];
            j = j - g;
            ++cnt;
        }
        A[j + g] = v;
    }
}
 
int main()
{
    ios::sync_with_stdio(false);
 
    long n, i, j = 13;
    vector<long> A;
 
    cin >> n;
    A.resize(n, 0);
    for (i = 0; i < n; ++i)
        cin >> A[i];
 
    long G[13] = { 1, 4, 13, 40, 121, 364, 1093, 3280, 9841, 29524, 88573, 265720, 797161 };
    for (i = 12; i >= 0; --i){
        if (G[i] >= n){
            j = i;
            continue;
        }
 
        insertionSort(A, n, G[i]);
    }
    if (0 == j)
        j = 1;
 
    cout << j << "\n";
    for (i = j - 1; i >= 0; --i){
        cout << G[i];
        if (i != 0)
            cout << " ";
    }
    cout << "\n" << cnt << "\n";
 
    for (i = 0; i < n; ++i)
        cout << A[i] << "\n";
 
    return 0;
}

Measured memory_bytes: 8984
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    string S;
    cin >> S;
    S += ".";
    vector<pair<char, int> > v;
    int cnt = 1;
    for (int i = 0; i < S.size() - 1; i++) {
        if (S[i] == S[i+1]) cnt++;
        else {
            v.push_back(make_pair(S[i], cnt));
            cnt = 1;
        }
    }
    cout << v.size() - 1 << '\n';
}


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

void solve(long long N, long long A, std::vector<long long> x) {
    vector<vector<vector<long long>>> dp(N+1, vector<vector<long long>>(N+1, vector<long long>((N+1)*A, 0)));
    x.insert(x.begin(), 0);
    dp[0][0][0] = 1;
    for (int j = 0; j <= N; j++) {
      for (int k = 0; k <= N; k++) {
        for (int s = 0; s <= N * A; s++) {
          if (j >= 1 and s < x[j]) {
	      dp[j][k][s] = dp[j-1][k][s];
          } else if (j >= 1 and k >= 1 and s >= x[j]) {
	      dp[j][k][s] = dp[j-1][k-1][s-x[j]] + dp[j-1][k][s];
          }
        }
      }
    }
    long long res = 0;
    for (int k = 1; k <= N; k++) {
	res += dp[N][k][k*A];
    }
    cout << res << endl;
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);
  long long A;
  scanf("%lld", &A);
  std::vector<long long> x(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &x[i]);
  }
  solve(N, A, std::move(x));
  return 0;
}


Measured memory_bytes: 53248
N = int(input())
A = list(map(int, input().split()))

A = [None] + A
B = [0] * (N + 1)

for n in range(N, 0, -1):
    s = sum(B[i] for i in range(n + n, N + 1, n))
    B[n] = 0 if A[n] == s % 2 else 1

B = [i for i, b in enumerate(B) if b == 1]
print(len(B))
for i in B:
    print(i)

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

typedef long long ll;
typedef pair <int, int> pii;

const int N = 5e3 + 5;

ll n, a[N], ans[N], in[N], tp[N], cur;
bool mark[N];
vector <int> adj[N];
vector <pii> g[N];

void dfs(int v) {
	tp[cur++] = v;
	mark[v] = true;
	for (auto e : g[v]) {
		int u = e.second;
		if(!mark[u]) {
			dfs(u);
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);	
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++)
			if(__gcd(a[i], a[j]) > 1)
				g[i].push_back({a[j], j}), g[j].push_back({a[i], i});;
	for (int i = 0; i < n; i++)
		sort(g[i].begin(), g[i].end());
	for (int i = 0; i < n; i++)
		if(!mark[i])
			dfs(i);
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int x = tp[i], y = tp[j];
			if(__gcd(a[x], a[y]) > 1) {
				adj[x].push_back(y);
				in[y]++;
			}
		}
	}
	priority_queue <pii> pq;
	for (int i = 0; i < n; i++) {
		if(!in[i])
			pq.push({a[i], i});
	}
	int cnt = 0;
	while(!pq.empty()) {
		pii p = pq.top();
		pq.pop();
		ans[cnt++] = p.first;
		int v = p.second;
		for (auto u : adj[v]) {
			in[u]--;
			if(!in[u])
				pq.push({a[u], u});
		}
	}
	for (int i = 0; i < n; i++)
		cout << ans[i] << " ";
	cout << "\n";
}


Measured memory_bytes: 35968
Tree = {}
Parents = {}

gets.to_i.times do
  i, *c = gets.split(' ').map(&:to_i)
  Tree[i] = c
  c.each{|e| Parents[e] = i}
end

preorder = -> i do
  l = Tree[i][0]
  r = Tree[i][1]
  print " #{i}"
  preorder.(l) if l != -1
  preorder.(r) if r != -1
end

inorder = -> i do
  l = Tree[i][0]
  r = Tree[i][1]
  inorder.(l) if l != -1
  print " #{i}"
  inorder.(r) if r != -1
end

postorder = -> i do
  l = Tree[i][0]
  r = Tree[i][1]
  postorder.(l) if l != -1
  postorder.(r) if r != -1
  print " #{i}"
end

Parents[-1] = nil
root = Tree.keys.reject{|i| Parents.include? i}.first

puts "Preorder"
preorder.(root)
puts "\nInorder"
inorder.(root)
puts "\nPostorder"
postorder.(root)
puts "\n"


Measured memory_bytes: 6880
// JAI SHREE RAM
#pragma GCC optimize("O3")
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define sec second
#define fir first
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define repe(i,m,n) for(ll (i)=(m);(i)<(n);(i)++)
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int pre_sum[5000009] ;
void solve()
{
int  n;
cin>>n;
int r=n%10;
if(r==3)
{
	cout<<"bon\n";
	return ;
}	
if( r==0 || r== 1 || r==6 || r== 8)
{
	cout<<"pon\n";
	return;
}
else
cout<<"hon\n";
}


int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fast
	int T;
	T = 1;
	// cin >> T;
	while (T--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3652
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
typedef struct { int x, y; } p2;
vector<vector<int>> A;
vector<p2> tA;
int d;
int main()
{
	int h, w, q, l, r;
	cin >> h >> w >> d;
	A.resize(h, vector<int>(w));
	tA.resize(h * w + 10);
	rep(i, 0, h) {
		rep(i2, 0, w) {
			cin >> A[i][i2];
			tA[A[i][i2]] = {i2+1, i+1};
		}
	}
	vector<int> cost(w * h + 1);
	rep(i, 0, h * w + 1 - d) {
		cost[i + d] = cost[i] + abs(tA[i].x - tA[i+d].x) + abs(tA[i].y-tA[i+d].y);
	}
	cin >> q;
	rep(i, 0, q) {
	cin >> l >> r;
	printf("%d\n", cost[r] - cost[l]);
	}
	return 0;
}


Measured memory_bytes: 4608
n = int(input())
x = n
import math
for i in range(int(math.sqrt(n))):
        if n%(i+1) == 0:
            if i+1 + n/(i+1) < x:
                x = i+1 + n/(i+1)
if x == n:
    print(x-1)
else:
    print(int(x-2))

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <array>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))


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

    int N;
    int t;
    vector<int> d;
    cin >> N;
    for (size_t i = 0; i < N; i++)
    {
        cin >> t;
        d.push_back(t);
    }

    sort(d.begin(), d.end());
    int N2 = N / 2;
    int median = d[N2];

    int K = 0;
    int count = 1;
    int i = 1;
    int j = 1;
    int tmp = 0;
    int larger = median;
    int smaller = median;

    if (median == d[N2 - 1])
    {
        cout << 0 << "\n";
    } else {
        while (true)
        {
            if (median - i > d[N2 - 1])
            {
                count++;
                i++;
            } else {
                break;
            }
        }
        cout << count << "\n";
    }


	return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int ans[500][500];
int main(){
	int H,W,h,w;
	cin>>H>>W>>h>>w;
	if(H%h==0 && W%w==0){
		puts("No");
		return 0;
	}
	bool rotated = 0;
	if(W%w==0){
		swap(H,W);
		swap(h,w);
		rotated = 1;
	}
	rep(i,H){
		rep(j,W){
			if(j%w==w-1) ans[i][j] = -1000000*(w-1)-1;
			else ans[i][j] = 1000000;
		}
	}
	puts("Yes");
	if(!rotated){
		rep(i,H){
			rep(j,W) cout<<ans[i][j]<<" ";
			puts("");
		}
	}else{
		rep(i,W){
			rep(j,H) cout<<ans[j][i]<<" ";
			puts("");
		}
	}
}


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

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define vi vector< int > 
#define pii pair< int, int >
#define mii map< int , int > 
#define F(start,stop) for(int i=start; i<stop; i++)
#define FRev(start,stop) for(int i=start; i>=stop; i--)
#define debugVector(v) for(int i = 0; it < v.size(); i++) cout << v[i] << " "; cout << endl;
#define debugArray(arr, n) for(int i=0; i<n; i++) cout << arr[i] << " "; cout << endl;
#define MOD1 1000000007
#define MOD2 998244353


int main()
{

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	IOS

	string s,t;
	cin >> s >> t;
	if(s.length() != t.length() - 1){
		cout << "No\n";
		return 0;
	}

	for(int i=0; i<s.length(); i++){
		if(s[i] != t[i]){
			cout << "No\n";
			return 0;
		}
	}

	cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define int long long
#define endl '\n'

int32_t main()
{
    IOS;
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    sort(arr,arr+n);
    int ans=0;
    for(int i=0;i<k;i++)
        ans+=arr[i];
    cout<<ans;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define line cout<<"\n"
#define ci std ::cin
#define co std ::cout
#define sf scanf
#define sff(n,m) scanf("%d%d",&n,&m)
#define pf printf
#define p_line printf("\n")
#define cas(n) printf("Case %d: ",n++)
#define task return
#define loop(x,n)  for(int x = 0 ; x < n ; x++)
#define constloop(x,a,n) for(int x = a ; x < n ; x++)
#define revloop(x,a,n)  for(int x = a ; x >= n ; x--)
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define pi acos(-1)
#define mx 10000000
/*ll P[mx+5],cnt=1;
bool nP[mx+5];
void sieve(void)
{
    P[0]=2;
    nP[0]=true;
    nP[1]=true;
    for(ll i=3 ; i<=mx ; i+=2)
    {
        if(nP[i]==true)
            continue;
        for(ll j=i+i ; j<=mx ; j+=i)
            nP[j]=true;
        P[cnt++]=i;
    }
}*/
ll dp[100000+5];
ll n;
ll A[100000+5];
ll dpcall(ll pos)
{
	if(pos>=n-1)
		return 0;
	if(dp[pos]!=-1)
		return dp[pos];
	ll r1=INT_MAX,r2=INT_MAX;
	if((pos+1)<n)
		r1=abs(A[pos+1]-A[pos])+dpcall(pos+1);
	if((pos+2)<n)
		r2=abs(A[pos+2]-A[pos])+dpcall(pos+2);
	return dp[pos]=min(r1,r2);
}
void solve()
{
    //Code here
 	memset(dp,-1,sizeof(dp));
 	ci>>n;
 	for(int i=0 ; i<n ; i++)
 	{
 		ci>>A[i];
 	}
 	co<<dpcall(0);
}
int main()
{
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/
	/*ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);*/
	solve();
	return 0;
}

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

int main() {
  bool ans=true;
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    int x;
    cin >> x;
    if(x%2==0&&x%3!=0&&x%5!=0) ans=false;
  }
  if(ans) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
}


Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String result = "yes";
		for(int i = 0; i < s.length() -1 ; i++) {
			for(int j = i + 1; j < s.length(); j++) {
				if(s.charAt(i) == s.charAt(j)) {
					result = "no";
					break;
				}
			}
		}

		System.out.println(result);
	}

}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int N, H;
int A[100010], B[100010];

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

	cin >> N >> H;
	rep(i, 0, N)
	{
		cin >> A[i] >> B[i];
	}

	sort(A, A + N, greater<int>());
	sort(B, B + N, greater<int>());

	int ans = 0;
	rep(i, 0, N)
	{
		if (B[i] < A[0])break;
		ans++;
		H -= B[i];
		if (H <= 0)break;
	}

	if (H > 0)ans += (H + A[0] - 1) / A[0];

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n;
    cin >> n;
    vi as(n);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }

    vvi dp(n, vi(n));
    for (int i = n - 1; i >= 0; i--) {
        for (int j = i; j < n; j++) {
            if (i == j) {
                dp[i][j] = as[i];
                continue;
            }
            dp[i][j] = max(as[i] - dp[i + 1][j], as[j] - dp[i][j - 1]);
        }
    }
    cout << dp[0][n - 1] << endl;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

vi64 a;
vi64 sums;
i64 dp[410][410];

i64 rec(int l, int r) {
  if (dp[l][r]) return dp[l][r];
  if (l + 1 == r) return dp[l][r] = 0;
  if (l + 2 == r) return dp[l][r] = a[l] + a[l + 1];
  i64 ret = 1e18;
  repi(m, l + 1, r) amin(ret, rec(l, m) + rec(m, r) + sums[r] - sums[l]);
  return dp[l][r] = ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int n;
  cin >> n;
  a = vi64(n);
  sums = vi64(n + 1);
  rep(i, n) cin >> a[i];
  partial_sum(all(a), sums.begin() + 1);
  cout << rec(0, n) << endl;
  return 0;
}


Measured memory_bytes: 1664
<?php

//文字列の入力
fscanf(STDIN,"%4s",$s);


//数列を２つずつ分割
$a = substr($s,0,1);
$b = substr($s,1,1);
$c = substr($s,2,1);
$d = substr($s,3,1);

if ($a == $b || $b == $c || $c == $d){
    echo "Bad";
}else{
    echo "Good";
}


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
string k;
long long n,d,dp[150][150000][3];
long long f(int sum,int i,int mx)
{
    if(i==n)
    {
        if(sum==0)return 1;
        else return 0;
    }
    if(dp[sum][i][mx]!=-1)return dp[sum][i][mx];
    long long ans=0;
    if(i==0)
    {
        ans=-1;
        for(int j=0;j<=k[i]-'0';j++)
        {
            if(k[i]-'0'!=j)ans+=f((sum+j)%d,i+1,0);
            else ans+=f((sum+j)%d,i+1,1);
            ans%=mod;
        }
    }
    else
    {
        for(int j=0;j<=9;j++)
        {
            if(j>k[i]-'0'&&mx==0)ans+=f((sum+j)%d,i+1,0);
            else if(j<k[i]-'0')ans+=f((sum+j)%d,i+1,0);
            else if(j==k[i]-'0')ans+=f((sum+j)%d,i+1,mx);
            ans%=mod;
        }
    }
    return dp[sum][i][mx]=ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    memset(dp,-1,sizeof dp);
    cin>>k>>d;
    n=k.size();
    cout<<f(0,0,0);
}


Measured memory_bytes: 528384
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ
{
    class Program
    {
        static IEnumerable<double> Read()
        {
            string line;
            while ((line = Console.ReadLine()) != null)
            {
                yield return double.Parse(line);
            }
        }

        static void Main(string[] args)
        {
            var d = Read().ToArray();
            Console.WriteLine(d.Max() - d.Min());
        }
    }
}

Measured memory_bytes: 5972
#標準入力とリストの初期化
a,b,c = map(int,input().split())
count,coin = 0,0

#毎日ログインボーナスを加算し7日ログインしたらボーナスを追加する
while coin < c:
    count += 1
    coin += a
    if count % 7 == 0:coin += b

#かかった日数を出力する
print(count)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
ll dp[100005];
 
int main(){
int n, m;
cin >>n >>m;
vector<bool> ok(n+1, true);
for(int i = 0; i<m; i++){
 int a; cin >> a;
 ok[a] = false;
}
 
dp[0]= 1;
for(int now = 0; now<n; now++){
  for(int next = now+1; next<=min(n, now+2);next++){
     if(ok[next]){
           dp[next] += dp[now];
            dp[next] %= 1000000007;
          }
      }
  }
cout << dp[n] << endl;
return 0;
}


Measured memory_bytes: 4420
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        x: i32,
    }
    println!("{}", if x >= 30 { "Yes" } else { "No" });
}


Measured memory_bytes: 2180
#include <iostream>
#include <string>

using namespace std;

#define rep(i,n) for(int (i)=1;(i)<=(n);(i)++)

int main(){
  char b;
  cin >> b;
  char s[4] = {'A','T','C','G'};
  if(b=='A')cout << s[1] << endl;
  else if(b=='T')cout << s[0] << endl;
  else if(b=='C')cout << s[3] << endl;
  else cout << s[2];
}


Measured memory_bytes: 256
// Vicfred
// https://atcoder.jp/contests/abc130/tasks/abc130_e
// math, combinatorics, counting
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    const long MOD = 10^^9+7;
    long n, m;
    readf("%s %s", &n, &m);
    readln;

    long[] ss = readln.split.map!(to!long).array;
    long[] ts = readln.split.map!(to!long).array;

    long[][] dp = new long[][](n+1, m+1);
    for(int i = 0; i <= n; i++)
        dp[i][0] = 1;
    for(int j = 0; j <= m; j++)
        dp[0][j] = 1;

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1])%MOD;
            if(ss[i-1] != ts[j-1])
                dp[i][j] -= dp[i - 1][j - 1];
            dp[i][j] += MOD;
            dp[i][j] %= MOD;
        }
    }

    dp[n][m].writeln;
}



Measured memory_bytes: 34936
package main

import (
	"fmt"
	"strings"
)

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	ss := make([]string, h)
	st := []string{}
	for i := range ss {
		fmt.Scan(&ss[i])
	}
	for i := range ss {
		if strings.Count(ss[i], ".") != w {
			st = append(st, ss[i])
		}
	}
	ans := make([]string, len(st))
	for i := 0; i < w; i++ {
		white := true
		for j := 0; j < len(st); j++ {
			if string(st[j][i]) != "." {
				white = false
				break
			}
		}
		if !white {
			for j := 0; j < len(st); j++ {
				ans[j] = ans[j] + string(st[j][i])
			}
		}
	}
	for i := range ans {
		fmt.Println(ans[i])
	}
}


Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int a,b;
	int e;
	cin >> a >> b;
	int s;
	s = (1 + (b - a))*(b - a) / 2;
	cout << s - b << "\n";
	cin >> e;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int x[n], y[n];
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i];

    long long ans = 0;
    for (long long s : {1, -1}) {
        long long ub = -(1LL<<60), lb = 1LL<<60;
        for (int i = 0; i < n; i++) {
            ub = max(ub, x[i] + s * y[i]);
            lb = min(lb, x[i] + s * y[i]);
        }
        ans = max(ans, ub - lb);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4752
#include <iostream>
#include <vector>
#define N_MAX 100000
using namespace std;
//cube[k]:k-1個目のブロックを1,-1で表現する。
vector<int> cube;
 
int main(){

  int i,k;
  char S[N_MAX+1];
  //入力
  cin>>S;
  for(i=0;S[i]!='\0';i++){
    if(S[i]=='0')cube.push_back(1);
    else cube.push_back(-1);
  } 
  cube.push_back(0);
  
  //貪欲的に前から処理する。
  int sum=0;
  for(i=0;i<cube.size();i++){
      if(cube[i]*cube[i+1]==-1){
        sum+=2;
        cube.erase(cube.begin()+i,cube.begin()+i+2);
        i=max(i-2,-1);
      }
  }
  
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1020
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N; cin >> N;
	int ans = 1;
	REP(i, N) {
		int a; cin >> a;
		if (a == 0) {
			cout << 0 << endl;
			return 0;
		}
		if (ans == -1 || ans > INF / a) {
			ans = -1;
		}
		else ans *= a;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3668
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, input().split())
H = list(map(int, input().split()))

INF = 10 ** 10
dp = [INF] * (10 ** 5 + 10)
H += [H[-1] * K]

dp[0] = 0

for i in range(N):
    for k in range(1, K + 1):
        if i + k <= N:
            dp[i + k] = min(dp[i + k], dp[i] + abs(H[i + k] - H[i]))


print(dp[N-1])


Measured memory_bytes: 52448
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

MOD = 1000000007

N = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip()
T = sys.stdin.readline().rstrip()

ans = 1
# 次横だったら掛ける何通りするか
next_h = 6
# 次縦だったら
next_v = 3
i = 0
while i < N:
    s, t = S[i], T[i]
    if s != t:
        # 横
        ans *= next_h
        next_h = 3
        next_v = 1
        i += 2
    else:
        # 縦
        ans *= next_v
        next_h = 2
        next_v = 2
        i += 1
    ans %= MOD

print(ans)


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const double PI=acos(-1);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for (int i=(a);i<=(b);i++)
#define per(i,a,b) for (int i=(a);i>=(b);i--)
#define Rep(i,a,b) for (int i=(a);i<(b);i++)
#define Per(i,a,b) for (int i=(a);i>(b);i--)
#define travel_set(it,a) for (set<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define travel_map(it,a) for (map<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define travel_vec(it,a) for (vector<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define p(x) cout << x << endl;
#define def cout << "find" << endl;
#define what_is(x) cout << #x << " is " << x << endl;
template <class T>T sqr(T x){return x*x;}
template <class T>T alex(T x){return (x>0)?x:-x;}
template <class T>void read(T&x){
	x=0;T f=1;char ch=getchar();
	while ((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if (ch=='-')f=-1,ch=getchar();
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=f;
}

//---------------------------------------------------head---------------------------------------------------

#define maxn 300005
#define all 23333333
int n,q;int rot[maxn];
vector<int>ins[maxn];
struct Tree{
	int l,r,c;
}T[all];
int cnt;
int Newnode(int lst){T[++cnt]=T[lst];return cnt;}
void insert(int&rot,int l,int r,int p){
	rot=Newnode(rot);T[rot].c++;if (l==r)return;int mid=(l+r)>>1;
	if (p<=mid)insert(T[rot].l,l,mid,p);else insert(T[rot].r,mid+1,r,p);
}
int query(int rot,int l,int r,int p){
	if (l>=p)return T[rot].c;int mid=(l+r)>>1;
	if (p<=mid)return query(T[rot].l,l,mid,p)+query(T[rot].r,mid+1,r,p);
	else return query(T[rot].r,mid+1,r,p);
}
int solve(int ind){
	int res=0;
	for (int i=ind,lst=0;i<=n;i+=ind,lst+=ind){
		res+=query(rot[i],1,n,i)-query(rot[lst],1,n,i);
	}
	return res;
}
int main(){
	// freopen("E.in","r",stdin);
	// freopen("E.out","w",stdout);
	read(n);read(q);swap(n,q);
	rep(i,1,q){
		int l,r;read(l);read(r);
		ins[l].pb(r);
	}
	rep(i,1,n){
		rot[i]=rot[i-1];
		Rep(k,0,ins[i].size())insert(rot[i],1,n,ins[i][k]);
	}
	rep(i,1,n)printf("%d\n",solve(i));return 0;
}

Measured memory_bytes: 75648
# https://atcoder.jp/contests/abc138/tasks/abc138_d

import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline


class Graph:
    def __init__(self, n, dictated=False, edge=[]):
        self.n = n
        self.dictated = dictated
        self.conj = [set() for _ in range(self.n)]
        self.visit = set()
        self.second_visit = set()
        for x, y in edge:
            self.add_edge(x,y)

    def add_edge(self,x,y):
        self.conj[x].add(y)
        if self.dictated == False:
            self.conj[y].add(x)

    def dfs(self, info, start=0, goal=None, use_visit=False):
        """
        :param start: スタート地点
        :param goal: ゴール地点
        :param use_visit: 前回の探索結果を保持するかどうか
        :return: ゴール地点までの距離。存在しなければ -1
        """
        if use_visit == False:
            self.visit = set()
            self.second_visit = set()
        self.visit.add(start)

        past_p = None
        next_set = [(start, past_p, 0)]
        next_full_set = [next_set]
        while sum(map(lambda x: x!=[], next_full_set)) != 0:
            next_set = next_full_set.pop()
            p, past_p, t = next_set.pop()
            for q in self.conj[p]:
                if p == past_p:
                    # 逆流した際の処理
                    continue
                if q in self.visit:
                    continue
                if q == goal:
                    # ゴール時の処理
                    # return t+1
                    continue
                # p から q への引継ぎ処理
                info[q] += info[p]
                self.visit.add(q)
                next_set.append((q, p, t + 1))
            if not next_set:
                self.second_visit.add(p)
                # 帰り際の処置（壊した道を元に戻す等)
                # visit.discard(p)
            else:
                next_full_set.append(next_set)
        return info


######################################################################################################

N, Q = map(int, input().split())  # N:頂点数, Q: クエリの数
M = N-1

graph = Graph(N, dictated=False)

for _ in range(M):
    x, y = map(int, input().split())
    x -= 1                                    # デクリメントが不要な場合は消す
    y -= 1
    graph.add_edge(x,y)

info = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    info[p - 1] += x

print(*graph.dfs(info, start=0))


Measured memory_bytes: 214160
// code.begin();
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back 
#define what_is(x) cerr<<#x<<" is "<<x<<endl;
#define print(v) for(auto i:v) cout<<i<<" ";cout<<endl;
#define my_time ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long 
#define endl "\n"
#define MOD 1000000007
const long long int INF=1e18;
#define mod 1000000007
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    ordered_set; 
//find_by_order(x)
//order_of_key(x)  


int power(int x,unsigned int y)
{
    int res=1;
    
    while(y>0)
    {
        // if y is odd multiply with result
        if(y&1)
        res=res*x;
        
        y=y>>1; // y=y/2;
        x=x*x;
        
    }
    return res;
}

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

ll  max3(ll  a, ll  b, ll c)
{
    return max(c, max(a, b));
}
int min3(int a, int  b, int  c)
{
    return min(a, min(b, c));
}

int  powermod(int  x, int  y, int p )
{
    int res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res % p;
}
int logg(int  a)
{
    int  x = 0;
    while (a > 1)
    {
        x++;
        a /= 2;
    }
    return x;
}


int modinv(int x)
{
    return powermod(x, mod - 2, mod);
}

double dp[3100][3100];double p[3100];
int  main(){
	my_time;

int t;
t=1;
//cin>>t;int test=0;
while(t--)
{
   
   int a;
   scanf("%d",&a);
   
   for(int i=0;i<a;i++)
   {
       scanf("%lf",p+i);
       
   }
   
   dp[0][0]=1;
  
  for(int i=1;i<=a;i++)
  {
      for(int j=0;j<=i;j++)
      {
          if(j)
          dp[i][j]+=dp[i-1][j-1]*p[i-1];
          dp[i][j]+=dp[i-1][j]*(1-p[i-1]);
      }
  }
  
  
  double ret=0;
  for(int i=0;i<=a;i++)
  {
      if(i>a-i)
      ret+=dp[a][i];
  }
  
  printf("%.10f",ret);
  
  
}
    return 0;
}


//code.end();





Measured memory_bytes: 50244
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

void solve() {
    int n, m;
    cin >> n >> m;
    string a;
    string b;
    a = "";
    b = "";
    for (int i = 0 ; i < n; ++i) {
        string ai;
        cin >> ai;
        a += ai;
    }
    for (int i = 0; i < m; ++i) {
        string bi;
        cin >> bi;
        b += bi;
    }
    string ans = "No";
    for (int i=0; i <= n-m; ++i) {
        for (int j=0; j <= n-m; ++j) {
            for (int p=0; p < m; ++p) {
                for (int q=0; q < m; ++q) {
                    if (a[i * n + j + p * n + q] != b[p*m + q]) {
                        goto out;
                    }
                }
            }
            ans = "Yes";
            goto out2;
            out: ;
        }
    }
out2:
    cout << ans;



}

int main() {

    solve();
    return 0;
}


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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 2000000000;
constexpr auto MOD = 1000000007;

int main() {

	int a,b;
	cin >> a >> b;
	int n = 0;
	while ((a - 1)*(n - 1) + a < b)n++;

	cout << n << endl;
}

Measured memory_bytes: 256