akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstdio>

using namespace std;

const long long INF = 100000000;
const long long MOD = 1000000007;

int gcd(int a,int b){
    if(a<b)
      swap(a, b);

    if(a%b==0)
      return b;

    return gcd(a % b, b);
}
int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  //cout << gcd(a, b);
  if (c % gcd(a,b) == 0)
  {
    cout << "YES" << endl;
  }
  else
    cout << "NO" << endl;
}


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

const int N = 100005;
bool ac[N] = {};
int wa[N] = {};
int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int a;
        string s;
        cin >> a >> s;
        if(s == "AC") {
            if (!ac[a]) {
                ac[a] = true;
            }
        }
        else
        {
            if(!ac[a])
                wa[a]++;
        }
    }
    int ans1 = 0, ans2 = 0;
    for (int i = 1; i <= n; i++) {
        if(ac[i]) {
            ans1++;
            ans2 += wa[i];
        }
    }
    cout << ans1 << ' ' << ans2 << endl;
    return 0;
}

Measured memory_bytes: 768
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a1[] = new int[n+2];
        int a2[] = new int[n+1];
        a1[0] = 0;
        a2[0] = 0;
        int sum = 0;
        int subsum = 0;
        int sum1 = 0;
        int sum2 = 0;
        for(int i=1;i<=n;i++){
            a1[i] = sc.nextInt();
        }
        sum1 = a1[1];
        a1[n+1] = 0;
        for(int i=1;i<=n;i++){
            a2[i] = sc.nextInt();
            sum2 += a2[i];
        }
        for(int i=1;i<=n;i++){
            subsum = sum1+sum2;
            if(subsum>sum){
                sum = subsum;
            }
            sum1 += a1[i+1];
            sum2 -= a2[i];
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 21844
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception{
		// TODO ?????????????????????????????????????????????
		String str[], ans;
		int a, b, c;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        str = br.readLine().split(" ");
        a = Integer.parseInt(str[0]);
        b = Integer.parseInt(str[1]);
        c = Integer.parseInt(str[2]);

        if(a < b && b < c){
        	ans = "Yes";
        }else{
        	ans = "No";
        }
        System.out.println(ans);

	}

}

Measured memory_bytes: 24272
#include<bits/stdc++.h>
#include<unordered_set>
using namespace std;
#define ll long long
#define ld long double
#define ss second
#define ff first
#define all(a) a.begin() , a.end()
#define All(a) a.rbegin() , a.rend()
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.precision(10),cout << fixed 
int main()
{
    ios;
    for (int i = 0; i <5; ++i)
    {
        int x;
        cin >> x;
        if (x == 0)
        {
            cout << i + 1 << '\n';
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3544
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>

int main()
{
  int N;
  std::cin >> N;
  std::vector<double> values;
  for(int i=0; i<N; i++)
  {
    int v;
    std::cin >> v;
    values.push_back(v);
  }
  std::sort(values.begin(), values.end());

  double score = values[0];
  for(int i=1; i<values.size(); i++)
  {
    score += values[i];
    score /= 2.0;
  }

  std::cout << std::setprecision(20) << score;
}


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

int main(){
	int n;
	string s, t;
	cin >> n >> s >> t;
	int count = 2 * n;
	for(int i = 0; i < n; i++){
		if(s.substr(i) == t.substr(0, n - i)){
			count = n + i;
			break;
		}
	}
	cout << count << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n,m; cin>>n>>m;
    vector<vector<int>> g(n);
    rep(i,m) {
        int a,b; cin>>a>>b;
        --a,--b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    queue<int> q;
    vector<int> dp(n,INF);
    vector<int> prev(n);
    q.push(0);
    dp[0] = 0;
    prev[0] = INF;

    while (!q.empty()) {
        int cur = q.front(); q.pop();
        for (auto &&e: g[cur]) {
            if (chmin(dp[e], dp[cur]+1)) {
                q.push(e);
                prev[e] = cur+1;
            }
        }
    }

    reverse(prev.begin(), prev.end());
    prev.pop_back();
    reverse(prev.begin(), prev.end());
    cout << "Yes" << '\n';
    print(prev);
    return 0;
}

Measured memory_bytes: 10540
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}



int main(){
  ll N;
  cin>>N;
  vector<ll> A(N);
  cin>>A;
  sort(A.begin(),A.end());
  D ans=A[0];
  for(int i=1;i<N;i++){
    ans+=A[i];
    ans/=2;
  }
  cout<<fixed<<setprecision(12)<<ans<<endl;
  
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
struct point {
    double x, y;
};
void koch(int n, struct point a, struct point b) {
    if ( n == 0) return;
    struct point s, t, u;
    double rad = 3.1415926535897932384626 / 3;
    s.x = ( 2 * a.x + b.x ) / 3;
    s.y = ( 2 * a.y + b.y ) / 3;
    t.x = ( a.x + 2 * b.x ) / 3;
    t.y = ( a.y + 2 * b.y ) / 3;
    u.x = ( t.x - s.x ) * cos(rad) - ( t.y - s.y ) * sin(rad) + s.x;
    u.y = ( t.x - s.x ) * sin(rad) + ( t.y - s.y ) * cos(rad) + s.y;
 
    koch(n - 1, a, s);
    if ( s.x < 0 ) s.x *= -1;
    if ( s.y < 0 ) s.y *= -1;
    printf("%.8f %.8f\n", s.x, s.y);
    koch(n - 1, s, u);
    if ( u.x < 0 ) u.x *= -1;
    if ( u.y < 0 ) u.y *= -1;
    printf("%.8f %.8f\n", u.x, u.y);
    koch(n - 1, u, t);
    if ( t.x < 0 ) t.x *= -1;
    if ( t.y < 0 ) t.y *= -1;
    printf("%.8f %.8f\n", t.x, t.y);
    koch(n - 1, t, b);
}
 
int main(void) {
    struct point p, q;
    int n;
 
    scanf("%d", &n);
 
    p.x = 0;
    p.y = 0;
    q.x = 100;
    q.y = 0;
 
    printf("%.8f %.8f\n", p.x, p.y);
    koch(n, p, q);
    printf("%.8f %.8f\n", q.x, q.y);
 
    return 0;
}

Measured memory_bytes: 1796
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define getcx getchar_unlocked
#define MSV(A,a) memset(A, a, sizeof(A))
#define MP make_pair
#define PB push_back
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12
#define chkbit(s, b) (s & (1<<b))
#define setbit(s, b) (s |= (1<<b))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define MOD 1000000007
#define MAX 100005
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\n';

int main() {

	LL x,t, n,ans = 0;

	cin>>n>>x>>t;

	ans += (t* (n/x));

	if(n % x != 0) ans += t;

	cout<<ans<<en;

	return 0;
}

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

using namespace std;

const int MOD = 1000000007;

typedef long long ll;

int H, W;
char temp;

int main(){
	cin >> H >> W;
	vector<vector<ll>> grid(H, vector<ll>(W, 0)), 
		dp(H+1, vector<ll>(W+1, 0));
	for(int r = 0; r < H; r++){
		for(int c = 0; c < W; c++){
			cin >> temp;
			if (temp == '.') grid[r][c] = 0ll;
			else grid[r][c] = 1ll;
		}
	}
	dp[0][1] = 1;
	for(int r = 1; r<=H; r++){
		for(int c = 1; c<= W; c++){
			if (grid[r-1][c-1] == 0)
				dp[r][c] = (dp[r-1][c] + dp[r][c-1]) % MOD;
		}
	}

	cout << dp[H][W] << endl;

	return 0;
}

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

#define MOD 1000000007
#define fastio std::ios_base::sync_with_stdio(false);
#define ll long long

int calc(int a){
    int k = a;
    int sum = 0;
    while(k > 0){
        sum += k%10;
        k /= 10;
    }
    return sum;
}

int main(){

    fastio;
    
    int n;
    cin >> n;
    int ans = INT_MAX;
    for(int i = 1; i < n; i++){
        ans = min(ans, calc(i) + calc(n-i));
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  int ret = 0;
  ret += N * (N-1) / 2;
  ret += M * (M-1) / 2;
  cout << ret << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
  ll N, M;
  cin >> N >> M;
  vector<pair<ll, ll> > shop(N);
  rep(i, N){
    ll numbers, value;
    cin >> numbers >> value;
    shop[i] = make_pair(numbers, value);
  }
  sort(shop.begin(), shop.end());
  ll ans = 0;
  rep(i,N){
    if(M==0)break;
    while(shop[i].second !=0){
      ans += shop[i].first;
      M--;
      if(M==0)break;
      shop[i].second--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  cin >> N;
  vll X(N);
  REP(i, 0, N) {
    cin >> X[i];
  }
  vll x = X;
  sort(x.begin(), x.end(), less<>());

  ll m0 = x[N / 2 - 1];
  ll m1 = x[N / 2];
  REP(i, 0, N) {
    if (X[i] <= m0) {
      cout << m1 << endl;
    } else {
      cout << m0 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 5376
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#define int long 
using namespace std;

signed main() {
	int N,A,B;
	cin >> N >> A >> B;
	cout << min(N * A,B) << endl;
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    int n;
    cin >> n;
    V<int> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];

    int ans = 0;
    rep(k, 29) {
        int s = 0;
        V<int> vb = b;
        rep(i, n) vb[i] = b[i] & ((1 << (k + 1)) - 1);
        sort(ALL(vb));

        rep(i, n) {
            int x = a[i] & ((1 << (k + 1)) - 1);
            int c = lower_bound(ALL(vb), (1 << k) * 2 - x) -
                    lower_bound(ALL(vb), (1 << k) - x);
            int d = lower_bound(ALL(vb), (1 << k) * 4 - x) -
                    lower_bound(ALL(vb), (1 << k) * 3 - x);
            s = (s + c + d) % 2;
        }
        if (s) {
            ans |= (1 << k);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5536
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;

int N,K,R,S,P,ans;

void solve(char c){
  if(c=='r') ans+=P;
  else if(c=='s') ans+=R;
  else if(c=='p') ans+=S;
}

signed _main(){
  cin >> N >> K >> R >> S >> P;
  string T; cin >> T;
  ans=0;
  rep(i,K){
    int rcnt=0,scnt=0,pcnt=0;
    for(int j=i;j<N;j+=K){
      if(j<K) solve(T[j]);
      else{
        if(T[j]=='r' && ((T[j-K]=='r' && rcnt==1) || T[j-K]!='r')){
          ans+=P;
          rcnt=0;
        }
        else if(T[j]=='r' && (T[j-K]=='r' && rcnt==0)) rcnt=1;
        if(T[j]=='s' && ((T[j-K]=='s' && scnt==1) || T[j-K]!='s')){
          ans+=R;
          scnt=0;
        }
        else if(T[j]=='s' && (T[j-K]=='s' && scnt==0)) scnt=1;
        if(T[j]=='p' && ((T[j-K]=='p' && pcnt==1) || T[j-K]!='p')){
          ans+=S;
          pcnt=0;
        }
        else if(T[j]=='p' && (T[j-K]=='p' && pcnt==0)) pcnt=1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
// Vicfred
// https://atcoder.jp/contests/dp/tasks/dp_d
// dynamic programming
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.stdio;
import std.string;

long N, W;
long[] vs;
long[] ws;

long[][] dp;

long knapsack(long w, int idx) {
    if(idx > N) return 0;
    if(w <= 0) return 0;
    if(ws[idx] > w) return knapsack(w, idx+1);
    if(dp[w][idx] != -(1<<30)) return dp[w][idx];
    dp[w][idx] = max(
            knapsack(w-ws[idx], idx+1) + vs[idx],
            knapsack(w, idx+1)
            );
    return dp[w][idx];
}

void main() {
    readf("%d %d\n", &N, &W);

    ws = new long[N+1];
    vs = new long[N+1];

    dp = new long[][](10^^5+5, 105);

    for(int i = 0; i < (10^^5+5); i++)
        for(int j = 0; j < 105; j++)
            dp[i][j] = -(1<<30);

    foreach(i; 1..N+1)
        readf("%d %d\n", &ws[i], &vs[i]);

    const long ans = knapsack(W, 1);
    ans.writeln;
}



Measured memory_bytes: 107840
import collections
l=list(input())

if len(l)%2!=0:
            print('No')
            exit()

else:
            c=collections.Counter(l)
            c_item=list(c.values())
            for i in range(len(set(l))):
                         if c_item[i] %2 !=0:
                                    print('No')
                                    exit()
print('Yes')    



Measured memory_bytes: 3316
<?php

class Operator
{
    private $operations;
    private $operations_count;

    public function doOperations()
    {
        fscanf(STDIN, '%d', $this->operations_count);
        $this->operations = new \SplDoublyLinkedList();
        for (;$this->operations_count > 0;$this->operations_count -= 1) {
            $operation = explode(' ', trim(fgets(STDIN)));
            if ($operation[0] === 'insert') {
                $this->operations->unshift($operation[1]);
            } elseif ($operation[0] === 'deleteFirst') {
                $this->operations->shift();
            } elseif ($operation[0] === 'deleteLast') {
                $this->operations->pop();
            } elseif ($operation[0] === 'delete') {
                foreach ($this->operations as $key => $element) {
                    if ($element === $operation[1]) {
                        $this->operations->offsetUnset($key);
                        break;
                    }
                }
            }
        }
    }

    public function getAnswer()
    {
        $keys_operated = array();

        while (1) {
            if (count($this->operations) > 0) {
                $keys_operated[] = $this->operations->shift();
            } else {
                break;
            }
        }
        echo implode(' ', $keys_operated), PHP_EOL;
    }
}

$operator = new Operator();
$operator->doOperations();
$operator->getAnswer();



Measured memory_bytes: 136156
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 5 + 5)


def solve(n, links, queries):
    def _query(a, b, data, m0, INF):
        yield INF
        a += m0
        b += m0
        while a < b:
            if b & 1:
                b -= 1
                yield data[b - 1]
            if a & 1:
                yield data[a - 1]
                a += 1
            a >>= 1
            b >>= 1

    def query(u, v):
        fu = first_appear[u]
        fv = first_appear[v]
        if fu > fv:
            fu, fv = fv, fu
        return euler_tour[min(_query(fu, fv + 1, data, m0, INF))[1]]

    def dfs(v, p, dep):
        first_appear[v] = len(euler_tour)
        depth[v] = dep
        euler_tour.append(v)
        for u, _, _ in links[v]:
            if u == p:
                continue
            dfs(u, v, dep + 1)
            euler_tour.append(v)

    def dfs2(v, p, tmp_dists, total_dist):
        for x, arr in v_queries[v].items():
            arr[0] = total_dist - tmp_dists[x][0]
            arr[1] = tmp_dists[x][1]
        for u, uc, ud in links[v]:
            if u == p:
                continue
            tmp_dists[uc][0] += ud
            tmp_dists[uc][1] += 1
            dfs2(u, v, tmp_dists, total_dist + ud)
            tmp_dists[uc][0] -= ud
            tmp_dists[uc][1] -= 1

    # 存在しない範囲は深さが他よりも大きくなるようにする
    INF = (n, None)

    # Euler Tour の構築
    euler_tour = []
    first_appear = [0] * n
    depth = [0] * n

    dfs(0, -1, 0)
    # print(euler_tour)
    # print(first_appear)
    # print(depth)

    # LCAを計算するクエリの前計算
    m = 2 * n
    m0 = 2 ** (m - 1).bit_length()
    data = [INF] * (2 * m0)
    for i, v in enumerate(euler_tour):
        data[m0 - 1 + i] = (depth[v], i)
    for i in range(m0 - 2, -1, -1):
        data[i] = min(data[2 * i + 1], data[2 * i + 2])

    # print(data)

    v_queries = [{} for _ in range(n)]
    lca = []
    for i, (x, y, u, v) in enumerate(queries):
        w = query(u, v)
        lca.append(w)
        v_queries[u][x] = [0, 0]
        v_queries[v][x] = [0, 0]
        if w != 0:
            v_queries[w][x] = [0, 0]

    tmp_dists = defaultdict(lambda: [0, 0])
    dfs2(0, -1, tmp_dists, 0)

    ans = []
    for w, (x, y, u, v) in zip(lca, queries):
        qu = v_queries[u][x]
        qv = v_queries[v][x]
        du = qu[0] + qu[1] * y
        dv = qv[0] + qv[1] * y
        if w == 0:
            ans.append(du + dv)
            continue
        qw = v_queries[w][x]
        dw = qw[0] + qw[1] * y
        ans.append(du + dv - 2 * dw)

    return ans


n, q = list(map(int, input().split()))
links = [set() for _ in range(n)]
lines = sys.stdin.readlines()
for line in lines[:n - 1]:
    a, b, c, d = list(map(int, line.split()))
    a -= 1
    b -= 1
    links[a].add((b, c, d))
    links[b].add((a, c, d))
queries = []
for line in lines[n - 1:]:
    x, y, u, v = map(int, line.split())
    u -= 1
    v -= 1
    queries.append((x, y, u, v))

ans = solve(n, links, queries)

print('\n'.join(map(str, ans)))


Measured memory_bytes: 265456
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        #[allow(unused_mut)]
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: u32,
        cards: [u32; n],
    };
    cards.sort();
    let mut a = 0;
    let mut b = 0;
    for (i, card) in cards.into_iter().rev().enumerate() {
        if i % 2 == 0 {
            a += card;
        } else {
            b += card;
        }
    }
    println!("{}", a - b);
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;

int dp[10][10];

void PUNKS_NOT_DEAD() {
    int ans = 0, n;
    cin >> n;
    for (int x = 1; x <= n; x++) {
        int la = x % 10;
        int fa = x;
        while (fa > 9) {
            fa /= 10;
        }
        dp[fa][la]++;
    }
    for (int f1 = 1; f1 <= 9; f1++) {
        for (int f2 = 1; f2 <= 9; f2++) {
            ans += dp[f1][f2] * dp[f2][f1];
        }
    }
    cout << ans;
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false), cin.tie(0);
    PUNKS_NOT_DEAD();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    string s; cin>>s;
    rep(i,0,s.size()){
        if(s[i]==',') s[i]=' ';
    }
    cout<<s<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

const int MAX = 2001;
bool can[MAX];
int A[20], n;

void rec(int pos, int sum){
  if(sum >= MAX) return;
  can[sum] = true;
  if(pos == n) return;
  rec(pos+1, sum+A[pos]);
  rec(pos+1, sum);
}

int main(){
  memset(can, false, sizeof(can));
  cin >> n;
  for(int i = 0; i < n; i++) cin >> A[i];
  rec(0,0);
  int q;
  cin >> q;
  while(q--){
    int num;
    cin >> num;
    cout << (can[num]?"yes":"no") << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(ReadLine());
        var A = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        var ans = true;

        for (int i = 0; i < N; i++)
        {
            if (A[i] % 2 == 0 && !(A[i] % 3 == 0 || A[i] % 5 == 0))
                ans = false;
        }

        WriteLine(ans ? "APPROVED" : "DENIED");
    }
}


Measured memory_bytes: 28100
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()

def main():
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    while True:
        check = True
        for c in str(N):
            if int(c) in D:
                check = False
        if check:
            print(N)
            return
        N += 1


if __name__ == "__main__":
    main()


Measured memory_bytes: 73480
using System;
using System.Linq;

namespace CF2017qA
{
    class C
    {
        static void Main(string[] args)
        {
            //input
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int H = input[0];
            int W = input[1];

            char[,] HW = new char[H, W];
            int[] cCount = new int[26];
            for (int h = 0; h < H; h++)
            {
                string a = Console.ReadLine();
                for (int w = 0; w < W; w++)
                {
                    HW[h, w] = a[w];
                    //行列に出てくる文字の数を数える
                    cCount[a[w] - 'a']++;
                }
            }

            //hwのパリティを確認する
            //両方とも偶数
            if (H % 2 == 0 && W % 2 == 0)
            {
                for (int i = 0; i < cCount.Length; i++)
                {
                    if (cCount[i] % 4 != 0) { Console.WriteLine("No"); return; }
                }
                Console.WriteLine("Yes"); return;
            }

            //両方が奇数
            if (H % 2 != 0 && W % 2 != 0)
            {
                for (int i = 0; i < cCount.Length; i++)
                {
                    cCount[i] %= 4;
                }

                int ecount = 0;
                int ocount = 0;
                for (int i = 0; i < cCount.Length; i++)
                {
                    if (cCount[i] != 0 && cCount[i] % 2 == 0) ecount++;
                    else if (cCount[i] % 2 != 0) ocount++;
                }

                if (ecount < (W + H) / 2 && ocount == 1)
                {
                    Console.WriteLine("Yes"); return;
                }
                else
                {
                    Console.WriteLine("No"); return;
                }
            }

            //片方が奇数
            if (H % 2 == 0 || W % 2 == 0)
            {
                //eo/oeのときは、文字がでてくる数から4で割った余りを計算して、2の倍数であればOK
                //残っている値が空白のマスの数よりも大きくなったらNG
                for (int i = 0; i < cCount.Length; i++)
                {
                    cCount[i] %= 4;
                }

                int count = 0;
                for (int i = 0; i < cCount.Length; i++)
                {
                    if (cCount[i] != 0 && cCount[i] % 2 == 0) count++;
                    else if (cCount[i] % 2 != 0) { Console.WriteLine("No"); return; }
                }

                if (H % 2 == 0 && count <= H / 2)
                {
                    Console.WriteLine("Yes"); return;
                }
                else if (W % 2 == 0 && count <= W / 2)
                {
                    Console.WriteLine("Yes"); return;
                }
                else
                {
                    Console.WriteLine("No"); return;
                }
            }
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

int64_t func1(int64_t x) {
    return (x - 1 + abs(x - 1)) / 2 + 1;
}

int64_t func2(int64_t x) {
    return (x + 1 - abs(x + 1)) / 2 - 1;
}

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N;
    cin >> N;
    int64_t a;
    cin >> a;
    
    int64_t ans1 = 0, ans2 = 0;
    int64_t partial_sum1 = a, partial_sum2 = a;
    ans1 += abs(func1(partial_sum1) - partial_sum1);
    ans2 += abs(func2(partial_sum2) - partial_sum2);
    partial_sum1 = func1(a);
    partial_sum2 = func2(a);
    
    for (int i = 1; i < N; i++) {
        cin >> a;
        partial_sum1 += a;
        partial_sum2 += a;
        if (i % 2 == 0) {
            ans1 += abs(func1(partial_sum1) - partial_sum1);
            ans2 += abs(func2(partial_sum2) - partial_sum2);
            partial_sum1 = func1(partial_sum1);
            partial_sum2 = func2(partial_sum2);
        }
        if (i % 2 == 1) {
            ans1 += abs(func2(partial_sum1) - partial_sum1);
            ans2 += abs(func1(partial_sum2) - partial_sum2);
            partial_sum1 = func2(partial_sum1);
            partial_sum2 = func1(partial_sum2);
        }
    }
    
    cout << min(ans1, ans2) << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include "stdio.h"
/*ABC 135 A*/
int main (void)
{
  int A,B;
  int i;

  scanf("%d%d", &A, &B);

  if((A - B) % 2 != 0)printf("IMPOSSIBLE\n");
  else printf("%d\n", (A + B) / 2);

  return 0;
}


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

void solve()
{
    int c;
    cin >> c;
    cout << ceil(c / 2.0);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const int MN=200000+5,P=20101009;
using namespace std;
typedef long long ll;
template<typename T>inline T&IN(T&in){
	in=0;char c=getchar();int f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))in=in*10+c-'0',c=getchar();
	return in*=f;
}
int n,m,ans;
int a[MN],bin[MN];
void input(){
	IN(n);int mn=INT_MAX,mx=INT_MIN;
	for(int i=1;i<=n;++i)IN(a[i]),bin[a[i]]++,mn=min(mn,a[i]),mx=max(mx,a[i]);
	int f;
	if(mn*2==mx)f=1;
	else if(mn*2-1==mx)f=0;
	else return puts("Impossible"),void();
	if(f==1&&bin[mn]>1)return puts("Impossible"),void();
	if(f==0&&bin[mn]!=2)return puts("Impossible"),void();
	for(int i=mn+f;i<=mx;++i)if(bin[i]<2)return puts("Impossible"),void();
	puts("Possible");
}
int main(){
	input();
	return 0;
}

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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const ll NN = 1e10 + 7;
const int N = 1e5 + 7;
const int M = 11;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;

void solve1()
{
	ll n, r = 0, g = 0, b = 0, s;
	string a;
	cin >> n >> a;
	for(int i = 0; i < n; i++)
		if(a[i] == 'R')
			r++;
		else if(a[i] == 'G')
			g++;
		else
			b++;
	s = r * g * b;
	for(int i = 1; i < n; i++){
		for(int j = 0; j < n - i - 1; j++){
			if(a[j] != a[j + i] && a[j] != a[j + i + i] && a[j + i] != a[j + i + i] && j + i + i < n){
				s--;
			}
		}
	}
	cout << s;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 3656
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
p, q = 0, 0
for i in range(N):
    if a[i] > b[i]:
        p += a[i] - b[i]
    elif a[i] < b[i]:
        q += (b[i] - a[i]) // 2

if p <= q:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 4596
import sys
sys.setrecursionlimit(300000)
fin = sys.stdin.readline


N, M = [int(elem) for elem in fin().split()]
adj = [[] for _ in range(N)]
for _ in range(M):
    x, y = [int(elem) - 1 for elem in fin().split()]
    adj[x].append(y)

visited = [False] * N
topo_order = []
# topological sort by DFS
def dfs_visit(node):
    visited[node] = True
    for neighbor in adj[node]:
        if not visited[neighbor]:
            dfs_visit(neighbor)
    topo_order.append(node)


for node in range(N):
    dfs_visit(node)
topo_order = topo_order[::-1]

dp = [0] * N
for node in topo_order[:-1]:
    for neighbor in adj[node]:
        dp[neighbor] = max(dp[neighbor], dp[node] + 1)

print(max(dp))


Measured memory_bytes: 152412
N, K = map(int, input().split())
d = []
A = []
for i in range(K):
    d.append(int(input()))
    A.append(list(map(int, input().split())))


count = [0] * N
for i in range(K):
    for j in range(d[i]):
        count[A[i][j]-1] += 1

ans = count.count(0)
print(ans)

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

using namespace std;

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

  int h, w, n;
  cin >> h >> w >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<vector<int>> c(h, vector<int>(w));
  int col_idx = 0;
  for (int i = 0; i < h; ++i) {
    if (i % 2 == 0) {
      for (int j = 0; j < w; ++j) {
        if (a[col_idx] == 0) {
          ++col_idx;
        }
        c[i][j] = col_idx + 1;
        a[col_idx]--;
      }
    } else {
      for (int j = w - 1; 0 <= j; --j) {
        if (a[col_idx] == 0) {
          ++col_idx;
        }
        c[i][j] = col_idx + 1;
        a[col_idx]--;
      }
    }
  }

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (0 < j)
        cout << " ";
      cout << c[i][j];
    }
    cout << "\n";
  }
}


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

class UnionFind{
    public:
        vector<int> rank,parent;
        //?????????????????????
        UnionFind(int n){
            rank.resize(n,0);
            parent.resize(n,0);
            for(int i=0;i<n;i++){
                parent[i]=i;
                rank[i]=0;
            }
        }

        //???????±???????(??£??¨???????±???????)
        int find_root(int x){
            if(parent[x]==x)
                return x;
            else
                return parent[x] = find_root(parent[x]);
        }

        //x??¨y????±??????????????????????
        void unite(int x,int y){
            //x,y???????????????????±??????????????????£??¨????????????
            x = find_root(x);
            y = find_root(y);
            //??£??¨???????????????????????§???????????????
            if(x==y) return;

            if(rank[x]<rank[y]){
                //x??????y?????¨????????????????????????x?????????y?????????
                parent[x]=y;
            }else{
                //x??????y?????¨????????????????????????y?????????x?????????
                parent[y]=x;
                //x??¨y?????¨???????????????????????????x????????????1?¢???????
                if(rank[x]==rank[y]) rank[x]++;
            }
        }

        //x??¨y???????????????????±???????????
        bool same(int x,int y){
            return find_root(x)==find_root(y);
        }
};

int main(){
    int n,q;
    cin >> n >> q;
    UnionFind uf(n);
    for(int i=0;i<q;i++){
        int c,x,y;
        cin>>c>>x>>y;
        if(c==0){
            uf.unite(x,y);
        }else{
            bool f=uf.same(x,y);
            if(f) cout<<1<<endl;
            else cout<<0<<endl;
        }
    }
}

Measured memory_bytes: 3188
x, n =  map(int, input().split())

if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))

    ans_list = []

    for i in range(x, -2, -1):
        if i not in p:
            ans_list.append(i)
            break

    for i in range(x, 102):
        if i not in p:
            ans_list.append(i)
            break

    if len(ans_list) == 1:
        print(ans_list[0])
    elif ans_list[0] == ans_list[1]:
        print(ans_list[0])
    else:
        ans_abs = min(abs(ans_list[0]-x), abs(ans_list[1]-x))
        if abs(ans_list[0]-x) == ans_abs:
            print(ans_list[0])
        else:
            print(ans_list[1])
    



Measured memory_bytes: 9236
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N,M = map(int,input().split())
P = [[] for _ in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    P[a].append(b)
    P[b].append(a)
ans = 0
def dfs(cur,d,num):
    global ans
    if num == N:
        ans += 1
        return
    else:
        li = P[cur]
        for chi in li:
            if d[chi] == 1:
                continue
            c = deepcopy(d)
            c[chi] += 1
            dfs(chi,c,num+1)
        return
d = defaultdict(int)
d[0] += 1
dfs(0,d,1)
print(ans)






    


Measured memory_bytes: 10560
#include <iostream>
#include <string>
#include <stack>
using namespace std;
int main(){
    stack<int> S;
    string word;
    while(cin >> word){
        if(word=="+"){
            int a,b;
            a=S.top();S.pop();
            b=S.top();S.pop();
            S.push(b+a);
        }else if(word=="-"){
            int a,b;
            a=S.top();S.pop();
            b=S.top();S.pop();
            S.push(b-a);
        }else if(word=="*"){
            int a,b;
            a=S.top();S.pop();
            b=S.top();S.pop();
            S.push(b*a);
        }else{
            S.push(stoi(word));
        }
    }
    cout << S.top() << endl;
}



Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int n;
  string s,t;
  cin>>n;
  cin>>s>>t;
  for (int i = 0; i < n; ++i)
  {
    cout<<s[i];
    cout<<t[i];
  }
}

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

int main(void) {
  int A, B, C, X;
  int cnt = 0;
  cin >> A >> B >> C >> X;
  for (int a = 0; a <= A; a++) {
    for (int b = 0; b <= B; b++) {
      for (int c = 0; c <= C; c++) {
        if (500 * a + 100 * b + 50 * c == X) cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n);i++)
#define rep1(i,n) for(int i=1; i<(n); i++)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
const int INF = 1e9;
const LL LLINF = 1e16;


int main(){
    string s;
    cin >> s;
    if(s.find("AC") != string::npos) cout << "Yes" << endl;
    else cout << "No" << endl;
}



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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    ll ans = 1;
    bool flag = false;
    bool zero = false;
    cin >> N;
    rep(i, N) {
        ll prev;
        ll temp;
        cin >> temp;
        prev = ans;
        ans *= temp;
        if(prev > ans || ans > 1000000000000000000) {
            flag = true;
        }
        if(temp == 0) zero = true;
    }
    if(zero) cout << 0 << endl;
    else if(flag) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}


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

int main() {
	int A, B;
	cin >> A >> B;
	A--, B--;
	vector<vector<char>> C(100, vector<char>(100, '#'));
	for (int i = 0; i < 50; i++) for (int j = 0; j < 100; j++) C[i][j] = '.';
	for (int i = 0; i < 49; i += 2) {
		for (int j = 0; j < 100; j += 2) {
			if (B == 0) break;
			C[i][j] = '#';
			B--;
		}
		if (B == 0) break;
	}
	for (int i = 51; i < 100; i += 2) {
		for (int j = 0; j < 100; j += 2) {
			if (A == 0) break;
			C[i][j] = '.';
			A--;
		}
		if (A == 0) break;
	}
	cout << "100 100" << endl;
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++) cout << C[i][j];
		cout << endl;
	}
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m >> n;
  
  int a = 0, b = 0;
  while (m--) {
    int c;
    cin >> c;
    ++(c < n ? a : b);
  }
  cout << min(a, b) << endl; 
}

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

int main (void) {
    int i;
    int n, k, h;
    int ans=0;
    scanf("%d%d", &n, &k);
    for ( i=0; i<n; i++ ) {
        scanf("%d", &h);
        if ( h >= k )
            ans++;
    }

    printf("%d\n", ans);
    return EXIT_SUCCESS;
}


Measured memory_bytes: 128
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define INT_MAX 2147483647
#define LLINT_MAX 9223372036854775807
#define mod 1000000007
#define ll long long int
using namespace std;

string s, t;
bool flag;

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	ll g = gcd(x, y);
	return x / g * y;
}

int main(){
	cin >> s >> t;
	for (int i = s.size() - t.size(); i >= 0; i--) {
		flag = true;
		lop(t.size(), j) {
			if (!(t[j] == s[i + j] || s[i + j] == '?')) {
				flag = false;
				break;
			}
		}
		if (flag) {
			lop(t.size(), j)
				s[i + j] = t[j];
			lop(s.size(), j)
				if (s[j] == '?')
					s[j] = 'a';
			cout << s << endl;
			return 0;
		}
	}
	cout << "UNRESTORABLE" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef __int128_t lll;
ll MOD;
ll powmod(ll a, lll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
vector<vector<ll>> matrixmul(int l, int m, int n, vector<vector<ll>> a, vector<vector<ll>> b){
	vector<vector<ll>> c;
	for(int i=0; i<l; i++){
		vector<ll> v;
		for(int j=0; j<n; j++){
			ll x=0;
			for(int k=0; k<m; k++){
				x+=(a[i][k]*b[k][j]);
				x%=MOD;
			}
			v.push_back(x);
		}
		c.push_back(v);
	}
	return c;
}
vector<vector<ll>> matrixpow(int n, vector<vector<ll>> a, ll k){
	vector<vector<ll>> ap=a, ans;
	for(int i=0; i<n; i++){
		vector<ll> v;
		for(int j=0; j<n; j++){
			if(i==j){
				v.push_back(1);
			}else{
				v.push_back(0);
			}
		}
		ans.push_back(v);
	}
	while(k){
		if(k&1) ans=matrixmul(n, n, n, ap, ans);
		ap=matrixmul(n, n, n, ap, ap);
		k>>=1;
	}
	return ans;
}
int main()
{
    ll l, a, b; cin>>l>>a>>b>>MOD;
    ll p=1;
    lll cnt[20]={};
    ll s[20]={};
    for(int i=0; i<18; i++){
        ll x=(p-a+b-1)/b, y=(10*p-a+b-1)/b;
        y=min(y, l);
        x=max(0ll, x);
        if(x>=l || 10*p-a<=0 || x==y){
            p*=10; continue;
        }
        cnt[i]=y-x;
        vector<vector<ll>> mat;
        vector<ll> v[3];
        for(int j=0; j<3; j++) v[j].resize(3);
        v[0][0]=10*p%MOD, v[0][1]=1, v[0][2]=b%MOD;
        mat.push_back(v[0]);
        v[1][0]=0, v[1][1]=1, v[1][2]=b%MOD;
        mat.push_back(v[1]);
        v[2][0]=v[2][1]=0, v[2][2]=1;
        mat.push_back(v[2]);
        vector<vector<ll>> mp=matrixpow(3, mat, y-x-1);
        ll a1=a+x*b;
        s[i]=(mp[0][0]*(a1%MOD)+mp[0][1]*(a1%MOD)+mp[0][2])%MOD;
        p*=10;
    }
    ll ans=0;
    lll c=0;
    for(int i=17; i>=0; i--){
        ans+=s[i]*powmod(10, c)%MOD;
        c+=cnt[i]*(lll)(i+1);
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256