akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;


namespace Test1 {

    class ClassMain {

        public static bool[] primes = Enumerable.Repeat(true, 1000000+ 1).ToArray();

        public static void sieve() {
            primes[0] = false; primes[1] = false;
            for (int i = 2; i < primes.Length/2+1; i++) {
                if (primes[i]) {
                    for (int j = 2; j * i < primes.Length; j++) {
                        primes[i * j] = false;
                    }
                }
            }
        }


        public static void Main(String[] args) {
            sieve();

            string line;
            while ((line = Console.ReadLine()) != null) {
                int[] ints = line.Split(' ').Select(int.Parse).ToArray();
                int n = ints[0]; 
                //int n = int.Parse(line);                
                if(n==0){break;}
                //int m = ints[1];
                int d = ints[1];
                int ban = ints[2];
                int cnt = 0;
                for (int i = 0; ; i++) {
                    if (primes[n+d*i]) { cnt++; }
                    if (cnt == ban) {
                        Console.WriteLine(n+d*i);
                        break;
                    }
                }
                



            }   
        }   
    }
}

Measured memory_bytes: 8564
//
//  main.cpp
//  Contest
//
//  Created by котя on 31.12.2019.
//  Copyright © 2019 quarkus. All rights reserved.
//

#include <iostream>
#include <string>
using namespace std;

int main(int argc, const char * argv[])
{

    string t = "ABC";
    string str;
    size_t index = -1;
    int cnt = 0;
    int n;
   	
  cin >> n;
	
  cin>>str;
  
    do
    {
        index += 1;
        cnt++;
        index = str.find(t, index);
            
    } while (index < str.length());
    
    cout<<cnt - 1<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    int n; cin>> n;
    vector<int> v;
    vector<int> c;

    rep(i, n){
        int t; cin>>t;
        v.push_back(t);
    }
    rep(i, n){
        int t; cin>>t;
        c.push_back(t);
    }

    int ans = 0;
    for(int bit=0; bit<(1<<n); bit++){
        int vsum = 0;
        int csum = 0;
        for(int i=0;i<n; i++){
            if(bit & (1<<i)) {
                vsum += v[i];
                csum += c[i];
            }
        }
        ans = max(ans, vsum-csum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int maxn=5010;

int k,n,tot;
char c[maxn];
string s[maxn*5];

int main()
{
	scanf("%s",c+1);
	scanf("%d",&k);
	n=strlen(c+1);
	for(int i=1;i<=n;i++)
	{
		string tmp="";
		for(int j=i;j<=min(n,i+k-1);j++)
		{
			tmp+=c[j];
			s[++tot]=tmp;
		}
	}
	
	sort(s+1,s+tot+1);
	int pos=1,cnt=1;
	while(cnt<k)
	{
		if (s[pos]!=s[pos+1]) cnt++;
		pos++;
	}
	
	for(int i=0;i<s[pos].length();i++)
		printf("%c",s[pos][i]);
	puts("");
	return 0;
} 

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
const double pi = acos(-1);
long double f(long double a, long double b, long double x) {
    if(a * a * b / 2.0 <= x) return atan(2 * (a * a * b - x) / (a * a * a));
    else return pi / 2 - atan(2 * x / (a * b * b));
}
int main()
{
    Hello
    long double a, b, x;
    cin >> a >> b >> x;
    cout << fixed << setprecision(6) << f(a, b, x) * 180.0/pi;
    return 0;
}


Measured memory_bytes: 3848
#include <stdio.h>

int main(){
  int a[10000];
  int b[10000];
  int n,m,i,j,cnt=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%d",&b[i]);
  }
  for(i=0;i<m;i++){
    for(j=0;j<n;j++){
      if(a[j]==b[i]){
        cnt++;
        break;
      }
      else continue;
    }
  }
  printf("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{

    int R; cin >> R;

    cout << defaultfloat << setprecision(10);
    cout << 2*PI*R << endl;

    return 0;
}


Measured memory_bytes: 3764
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String m = sc.next();
		String n = sc.next();
		String o = sc.next();
		System.out.println(m.substring(0, 1).toUpperCase()+n.substring(0, 1).toUpperCase()+o.substring(0, 1).toUpperCase());
		sc.close();
	}


}

Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int x;
    cin >> x;
    int ans = 8;
    if (x < 600) {
        ans = 8;
    } else if (x < 800) {
        ans = 7;
    } else if (x < 1000) {
        ans = 6;
    } else if (x < 1200) {
        ans = 5;
    } else if (x < 1400) {
        ans = 4;
    } else if (x < 1600) {
        ans = 3;
    } else if (x < 1800) {
        ans = 2;
    } else {
        ans = 1;
    }

    cout << ans << endl;
}

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

using namespace std;
#define lint long long
#define P pair<int, int>

void Euc(lint& a, lint& b){
    lint large, small;
    if(a > b){
        large = a;
        small = b;
    } else {
        large = b;
        small = a;
    }
    
    if(small !=0){
        lint sup;
        sup = large % small;
        a = sup;
        b = small;
    } else {}
    
}

lint GCD(lint a, lint b){
    while(true){
        Euc(a, b);
        if(a == 0){
            return b;
        } else if(b == 0){
            return a;
        }
    }
}

int main() {
    int N;
    lint X;
    
    cin >> N >> X;
    
    lint x[N];
    lint ans = 0;
    
    for(int i = 0; i < N; ++i){
        cin >> x[i];
        x[i] = abs(x[i] - X);
        if(x[i] != 0){
            ans = x[i];
        }
    }
    
    for(int i = 0; i< N; ++i){
        if(x[i] != 0){
            ans = GCD(ans, x[i]);
            //            cout << "ans = " << ans << endl;
        }
    }
    cout << endl << ans << endl;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys


def solve(R: int):
    if R < 1200:
        print('ABC')
    elif R < 2800:
        print('ARC')
    else:
        print('AGC')
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    R = int(next(tokens))  # type: int
    solve(R)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
n = int(input())
li = list(map(int,input().split()))
ans = 100000000000000000

for i in range(1,n):
    if i == 1:
        x = sum(li[:i])
        y = sum(li[i:])
    else:
        x += li[i-1]
        y -= li[i-1]
    z = abs(x-y)
    if z < ans:
        ans = z
    
print(ans)

Measured memory_bytes: 26056
#include <stdio.h>

int main(void)
{
	int a;
	int b;
	char op;
	
	while (1){
		scanf("%d %c %d", &a, &op, &b);
		if(op == '?'){
			break;
		}
		else if(op == '+'){
			printf("%d\n",a + b);
		}
		else if(op == '-'){
			printf("%d\n",a - b);
		}
		else if(op == '/'){
			printf("%d\n", a / b);
		}
		else if(op == '*'){
			printf("%d\n", a * b);
		}
	}
	
	return (0);
}

Measured memory_bytes: 600
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <numeric>
 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll K,N;
ll ans;
string S;
ll a;
ll A[100001];
ll H,M,HH,MM;
ll now;
 
int main(){
    cin>>N;
    for(int i=0;i<N+1;i++){
        cin >> A[i];
        a += A[i];
    }
    if(A[0]==0){
        if(N==0){
            cout << -1 << endl;
            return 0;
        }
        now = 1;
        ans += 1;
    }else if(A[0]==1){
        if(N>0){
            cout << -1 << endl;
            return 0;
        }else{
            cout << 1 << endl;
            return 0;
        }
    }else{
        cout << -1 << endl;
        return 0;
    }
    
    for(int i=1;i<N+1;i++){
        if(a>2*now){
            now = now*2;
        }else{
            now = a;
        }
        ans += now;
        if(now<A[i]){
            cout << -1 << endl;
            return 0;
        }else{
            now -= A[i];
        }
        a -= A[i];
        
    }
    if(a==0){
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }
    
}


Measured memory_bytes: 4404
n,ma,mb=map(int,input().split())
dpn=400001
dp=[10**6]*dpn
dp[0]=0
for i in range(n):
    a,b,c=map(int,input().split())
    for j in range(dpn-1,-1,-1):
        if j==0 or dp[j]!=10**6:
            dp[j+a*1000+b]=min(dp[j+a*1000+b],dp[j]+c)
ans=10**6
s=1000*ma+mb
p=1
while s*p<dpn:
    ans=min(ans,dp[s*p])
    p+=1
if ans==10**6:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 43868
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String A = sc.next();
    String B = sc.next();
    String C = sc.next();
    if((A.charAt(A.length()-1)==B.charAt(0)) && B.charAt(B.length()-1)==C.charAt(0)){
      System.out.println("YES");
    }else{
       System.out.println("NO");
    }
  }
}

Measured memory_bytes: 35576
#include <bits/stdc++.h>
#define int long long
using namespace std;

void dfs(int u, int num, auto& used, const auto& g) {
    used[u] = num;
    for (int v : g[u]) {
        if (used[v]) continue;
        dfs(v, num, used, g);
    }
}
signed main() {
    int N, M;
    cin >> N >> M;

    vector<int> p(N);
    for (int& x : p) cin >> x;

    vector<int> x(M), y(M);
    vector<vector<int>> g(N + 1);
    for (int i = 0; i < M; i++) {
        cin >> x[i] >> y[i];

        g[x[i]].push_back(y[i]);
        g[y[i]].push_back(x[i]);
    }

    vector<int> used(N + 1);
    int num = 0;
    for (int i = 1; i <= N; i++) {
        if (used[i]) continue;
        dfs(i, ++num, used, g);
    }

    vector<set<int>> gr(N + 1), gr2(N + 1);
    for (int i = 1; i <= N; i++) {
        gr[used[i]].insert(i);
        gr2[used[i]].insert(p[i - 1]);
    }

    int ans = 0;
    for (int i = 1; i <= N; i++) {
        for (int x : gr[i]) {
            ans += (gr2[i].find(x) != gr2[i].end());
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 30592
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
const int MAX_N = 500000;
const int MOD = 1000000007;

void Add(ll& a, ll b)
{
    a = (a + b) % MOD;
}

void _main()
{
    int N;
    cin >> N;
    vector<ll> a(N);
    rep(i, 0, N) cin >> a[i];
    vector<ll> b(N + 1);
    b[0] = 0;
    rep(i, 0, N) b[i + 1] = b[i] ^ a[i];
    vector<ll> zeroNums(N + 2, 0);
    rep(i, 0, N + 1) zeroNums[i + 1] = zeroNums[i] + (b[i] == 0);
    vector<vector<int>> indice(1 << 20);
    rep(i, 0, N + 1) indice[b[i]].push_back(i);

    ll ans = 0;

    if (b[N] == 0)
    {
        ans = 1;
        rep(i, 0, zeroNums[N + 1] - 2)
        {
            ans *= 2;
            ans %= MOD;
        }
    }

    set<ll> s;
    rep(i, 0, N + 1) if (b[i] != 0) s.insert(b[i]);

    for (const ll X : s)
    {
        if ((b[N] != 0) && (b[N] != X))
        {
            continue;
        }

        const int NN = indice[X].size();

        if (NN == 0)
        {
            continue;
        }

        vector<vector<ll>> dp(NN + 1, vector<ll>(2, 0));
        dp[0][0] = 1;

        rep(i, 0, NN)
        {
            const ll zeroNum = zeroNums[indice[X][i]] - (i > 0 ? zeroNums[indice[X][i - 1] + 1] : 0);
            Add(dp[i + 1][0], dp[i][0] + dp[i][1] * zeroNum);
            Add(dp[i + 1][1], dp[i + 1][0] + dp[i][1]);
        }

        if (b[N] == 0)
        {
            Add(ans, dp[NN][1]);
        }
        else
        {
            Add(ans, dp[NN][0]);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 59636
"""
    Author: _YL_
"""
a, b = map(int, input().split())

l = a / 0.08
u = int((a+0.99) / 0.08)

if l == int(l):
    l = int(l)
else:
    l = int(l) + 1

i = l
while i <= u:
    if int(i * 0.1) == b:
        break
    else:
        i += 1
if i <= u:
    print(i)
else:
    print("-1")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

int dx[] = {0, -1, 1, 0};
int dy[] = {-1, 0, 0, 1};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    int n;
    cin >> s >> n;
    int pos = 0;
    while( 1 ) {
        if( pos + 1 == n ) {
            cout << s[pos] << endl;
            break;

        }
        if( s[pos] != '1' ) {
            cout << s[pos] << endl;
            break;

        }
        ++pos;

    }
    return 0;
}



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

//#pragma gcc optimize("O3,unroll-loop")
//#pragma gcc target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
#define int long long
//#define double long double

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

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

    int ans = -9e18;
    if (a < 0 && c < 0)
        ans = max(ans, a * c);
    if (b > 0 && d > 0)
        ans = max(ans, b * d);
    if (a <= 0 && 0 <= b)
        ans = max(ans, 0LL);
    if (c <= 0 && 0 <= d)
        ans = max(ans, 0LL);
    ans = max(ans, b * c);
    ans = max(ans, a * d);
    cout << ans << '\n';

    return 0;
}

//      *   *  *****  *   *  *   *   ****  ****    ****     **    **
//     *   *  *      **  *  *   *  *      *   *  *        * *   * *
//    *****  *****  * * *  *   *  *      ****   *       *  *     *
//   *   *      *  *  **  *   *  *      *  *   *       *****    *
//  *   *  *****  *   *   ***    ****  *   *    ****     *   *****

//      *****  *****  *   *  *      *****  *   *  *****  *****
//        *   *   *  *   *  *        *    **  *    *    *   *
//       *   *   *  *****  *        *    * * *    *    *****
//   *  *   *   *    *    *        *    *  **    *    *
//  ****   *****    *    *****  *****  *   *    *    *


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

int main() {
    int n, q, t;
    string s;
    queue<pair<string,int> > Q;
    cin >> n >> q;
    for (int i=0; i<n; i++) {
        cin >> s >> t;
        Q.push(make_pair(s,t));
    }
    pair<string,int> u;
    int ans=0, a;
    while (!Q.empty()) {
        u=Q.front();
        Q.pop();
        a=min(u.second,q);
        u.second-=a;
        ans+=a;
        if (u.second>0) {
            Q.push(u);
        } else {
            cout << u.first << " " << ans << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 6304
from sys import setrecursionlimit
setrecursionlimit(1000000)

def permute(a, idx):
    if idx == len(a):
        permutations.append(a[::])
    for i in range(idx, len(a)):
        a[i], a[idx] = a[idx], a[i]
        permute(a, idx + 1)
        a[i], a[idx] = a[idx], a[i]

def doit(a, b, c, idx):
    if (a, b, c, idx) in memo:
        return memo[a, b, c, idx]
    if idx == len(unused):
        return abs(a - needA) + abs(b - needB) + abs(c - needC)
    memo[a, b, c, idx] = min(
        doit(a, b, c, idx + 1),
        doit(a + unused[idx], b, c, idx + 1) + 10,
        doit(a, b + unused[idx], c, idx + 1) + 10,
        doit(a, b, c + unused[idx], idx + 1) + 10
    )
    return memo[a, b, c, idx]

n, needA, needB, needC = map(int, input().split())
a = [int(input()) for _ in range(n)]
ret = float('inf')
for mask in range(1 << n):
    if bin(mask).count('1') != 3:
        continue
    abc = [a[i] for i in range(n) if (mask >> i) & 1]
    unused = [a[i] for i in range(n) if not (mask >> i) & 1]
    permutations = []
    permute(abc, 0)
    for p in permutations:
        memo = {}
        ret = min(ret, doit(p[0], p[1], p[2], 0))
print(ret)

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <cmath>
#include <ctime>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector< vector<int> > vvi;
typedef vector<ll> vl;
typedef vector< vector<ll> > vvl;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define forv(i, v) forn(i, v.size())
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back

int main() {
#ifdef NEREVAR_PROJECT
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll a, b, c;
    cin >> a >> b >> c;
    if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
        cout << 0 << endl;
    } else {
        cout << min(a * b, min(a * c, b * c)) << endl;
    }
    return 0;
}


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

int main() {
    int n,k,x,y;
    cin >> n >> k >> x >> y;
    int ans = min(n,k)*x;
    n -= k;
    if(n > 0) ans += n*y;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

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


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

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

int main(){
    int n;
    cin >> n;
    vector<vector<int>> a(2, vector<int>(n));
    rep(i, 2) rep(j, n) cin >> a[i][j];
    vector<vector<int>> accum(2, vector<int>(n+1, 0));
    rep(i, 2) rep(j, n) {
        accum[i][j+1] = accum[i][j] + a[i][j];
    }
    int ans = 0;
    for ( int i = 1; i <= n; ++i ) {
        ans = max(ans, accum[1][n] - accum[1][i-1] + accum[0][i] - accum[0][0]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>

using namespace std;

vector<vector<int> > path;
queue<int> q;
vector<bool> seen;

typedef long long ll;

ll countv = 0;
ll K = 0;


#define MOD (1000000007)

void push(int num, int idx) {
    if(seen[num] != true) {
        q.push(num);
        seen[num] = true;
        //cout << idx<< endl;
        countv = (countv * (K-2 - idx)) %MOD;
    }
}


int main() {
    int N;
    cin >> N >> K;

    path.assign(N, vector<int>());
    seen.assign(N, false);

    for(int i = 0; i < N-1; i++) {
        int a, b;
        cin >> a >> b;
        a--;b--;
        path[a].push_back(b);
        path[b].push_back(a);
    }

    seen[0] = true;
    countv = K;



    for(int i = 0; i < path[0].size(); i++) {
        if(seen[path[0][i]] == true) continue;
        seen[path[0][i]] = true;
        q.push(path[0][i]);
        countv = (countv * (K - i - 1)) % MOD;
        //cout << countv << endl;
    }
    
    while(q.size() >= 1) {
        int current = q.front();q.pop();
        int idx = 0;
        for(int i = 0; i < path[current].size(); i++) {
            if(seen[path[current][i]] == true) continue;
            
            push(path[current][i], idx++);
        }
    }

    cout << countv << endl;

}


Measured memory_bytes: 6520
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
 
int main(){
  ll N,P;
  string S;
  cin >> N >> P >> S;

  if(P==2 || P==5){
    ll answer=0;
    rep(i,N){
      if((S[i]-'0')%P == 0){
        answer+=i+1;
      }
    }
    cout << answer << endl;
    return 0;
  }

  vector<int> d(N+1);
  ll count=1;
  for(int i=N-1; 0<=i; i--){
    int a = (S[i]-'0') * count % P ;
    d[i]=(d[i+1]+a)%P;
    count*=10;
    count%=P;
  }

  vector<int> sum(P);
  ll answer=0;
  for(int i=N; 0<=i; i--){
    answer+=sum[d[i]];
    sum[d[i]]++;
  }

  cout << answer << endl;
  
 
}

Measured memory_bytes: 1412
module Main where
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.List
import qualified Text.Printf
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString as BC

------------------------------------------

main :: IO ()
main = do
  [x, y] <- readInts
  print $ x - if x > y then 1 else 0

------------------------------------------

{- Int input -}

parseInt :: BC.ByteString -> Int
parseInt = fst . fromJust . BC.readInt

parseInts :: BC.ByteString -> [Int]
parseInts = map parseInt <$> BC.words

readInt :: IO Int
readInt = parseInt <$> BC.getLine

readInts :: IO [Int]
readInts = parseInts <$> BC.getLine

{- Double Formatting -}

doubleFmt :: Double -> String
doubleFmt = Text.Printf.printf "%.12f"


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

const int MAX = 200001;


ll fac[MAX], finv[MAX], inv[MAX];

long long bin_pow(long long x, int n){
    long long res = 1;
    while(n > 0){
        if(n & 1)res = res * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

ll fact(ll n, ll a){
    ll res = 1;
    for(ll i = n-a+1; i<=n; i++){
        res *= i;
        res %= MOD;
    }
    return res;
}

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i=2; i<MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

int main(){
    ll n, a, b, res;
    cin >> n >> a >> b;
    res = bin_pow(2, n);
    COMinit();
    if(n < 3){
        cout << 0;
        return 0;
    }
    res = res - (fact(n, a)*finv[a]%MOD) + MOD;
    res %= MOD;
    res = res - (fact(n, b)*finv[b]%MOD) + MOD - 1;
    res %= MOD;
    cout << res;
    return 0;
}

Measured memory_bytes: 4992
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        String[] A = new String[N];
        String[] B = new String[M];

        for(int i=0; i<N; i++){
            A[i] = sc.next();
        }
        for(int i=0; i<M; i++){
            B[i] = sc.next();
        }

        loop1:for(int i=0; i<N-M+1; i++){
            for(int j=0; j<N-M+1; j++){
                if(A[i].charAt(j)==B[0].charAt(0)){
                loop2:for(int k=0; k<M; k++){
                        for(int l=0; l<M; l++){
                            if(A[i+k].charAt(j+l)!=B[k].charAt(l)){
                                break loop2;
                            }
                        }
                        if(k==M-1){
                            System.out.println("Yes");
                            break loop1;
                        }
                    }
                }
            }
            if(i==N-M){
                System.out.println("No");
            }
        }
    }
}

Measured memory_bytes: 22740
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main () {
    int n; cin >> n;
    vector<vector<double>> d(n, vector<double>(n));
    vector<double> x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];
    rep(i, n) rep(j, n) {
        int dx = x[i] - x[j], dy = y[i] - y[j];
        d[i][j] = d[j][i] = sqrt(dx*dx + dy*dy);
    }

    vector<int> vec(n);
    rep(i, n) vec[i] = i;
    double ans = 0;
    do {
        rep(i, n-1) ans += d[vec[i]][vec[i+1]];
       
    } while (next_permutation(all(vec)));

    auto factorial = [&] (int n) {
        int res = 1;
        rep(i, n) res *= (i+1);
        return res;
    };
    ans /= factorial(n);
    printf("%.10lf\n", ans);

    return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var X = int.Parse(Console.ReadLine());

            while (!IsPrime(X))
            {
                X++;
            }

            Console.WriteLine(X);
        }
        public static bool IsPrime(int num)
        {
            if (num < 2) return false;
            else if (num == 2) return true;
            else if (num % 2 == 0) return false;

            double sqrtNum = Math.Sqrt(num);
            for (int i = 3; i <= sqrtNum; i += 2)
            {
                if (num % i == 0)
                {
                    return false;
                }
            }

            return true;
        }
    }
}


Measured memory_bytes: 13140
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

const int N = 1111;


int n;
vector<int> r;
vector<int> w;

int nupsuck(int t, vector<int>& w){

	int dp[N][N]={0};

	int ret = 0;
	rep(i,w.size()){
		rep(j,t){
			dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
			dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i][j]+w[i]);
		}
	}	
	rep(i,w.size()+1){
		rep(j,t+1)ret = max(ret, dp[i][j]);
	}

	rep(i,w.size()+1){
		rep(j,t+1){}
	}

	return ret;
}


bool input(){
	cin>>n;
	if(n==0)return false;

	r.clear();w.clear();


	rep(i,n){
		int a,b;
		cin>>a>>b;
		r.push_back(a);
		w.push_back(b);
	}

	return true;
}


int solve(){
	int wsum = 0, rsum =0;
	int len = 0;
	int lenx = 0;
	rep(i,n){
		wsum += w[i];
		rsum += r[i];
		len = max(len, r[i]);
		if(len==r[i])lenx = i;
	}


	if(len*2 > rsum){
		vector<int> w2 = w;
		w2.erase(w2.begin() + lenx);
		int np = nupsuck(len-(rsum-len), w2);
		//cout<<len<<" "<<wsum<<" "<<rsum<<" "<<np<<endl;
		return 2*len + wsum - np;
	}
	return rsum+wsum;
}


int main(){

	while(input()){
		cout<<solve()<<endl;
	}
}

Measured memory_bytes: 6060
/**
 *    author:  ismail
 *    created: 20.01.2020  21:50:51
 **/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define w(a) std::cerr << #a << " : " << (a) << "\n";

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  cout << (n == m ? "Yes" : "No") << "\n";

  return 0;
}

Measured memory_bytes: 256
import itertools
import copy

H,W,K = map(int,input().split())
c = [list(str(input())) for i in range(H)]
ans = 0
H_bit = list(itertools.product([0,1], repeat=H))
W_bit = list(itertools.product([0,1], repeat=W))

def mark(h,w,board):
    for i,n in enumerate(h):
        if n==1:
            board[i] = ["R"]*W
    for j,n in enumerate(w):
        if n==1:
            for k in range(H):
                board[k][j] = 'R'
    return board

for i in H_bit:
    for j in W_bit:
        check = copy.deepcopy(c)
        li = mark(i,j,check)
        if sum(a.count("#") for a in li)==K:
            ans += 1
print(ans)


Measured memory_bytes: 9276
import java.util.Scanner


object Main {
  def read() = {
    val sc = new Scanner(System.in)
    val s = sc.next()
    s
  }

  def solve(s: String): Int = {
    // 0-origin
    // 0101... (偶数番目0)
    // 1010... (偶数番目1)

    val start0 = s.zipWithIndex.count{
      // 偶数番目に1, 奇数番目に0があるものをカウント
      case (c, i) => if (i % 2 == 0) c == '1' else c == '0'
    }
    val start1 = s.zipWithIndex.count{
      // 偶数番目に0, 奇数番目に1があるものをカウント
      case (c, i) => if (i % 2 == 0) c == '0' else c == '1'
    }
    Math.min(start0, start1)
  }


  def main(args: Array[String]): Unit = {
    val s = read()
    println(solve(s))
  }
}

Measured memory_bytes: 38136
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int xa,ya,xb,yb;
  cin >> xa >> ya>>xb>>yb;
  int hx,hy;
  if(xa  > xb){
    hx = xa - xb;
    if(ya> yb){
      hy = ya - yb;
      cout <<  xb + hy<< " "  << yb - hx << " "<< xa + hy << " "<< ya - hx << endl;
    }else{
      hy = yb - ya;
      cout <<  xb - hy  << " "<< yb - hx<< " " << xa - hy<< " " << ya - hx << " "<< endl;
    }
  }else{
      hx = xb-xa;
      if(ya> yb){
        hy = ya - yb;
        cout <<  xb + hy<< " "  << yb + hx << " "<< xa + hy << " "<< ya + hx << endl;
      }else{
        hy = yb - ya;
        cout <<  xb - hy  << " "<< yb + hx<< " " << xa - hy<< " " << ya +hx << " "<< endl;
    }
     
  }
}

Measured memory_bytes: 256
H, W, K = map(int, input().split())
S = [0] * H

for h in range(H):
    S[h] = list(input())


def check(divH):
    MAP = [0] * H
    BitDivH = "".join(["{:0", str(H - 1), "b}"]).format(divH)
    cnt = 0
    for i, bit in enumerate(BitDivH):
        if bit == "1":
            cnt += 1
            MAP[i + 1] = cnt
        else:
            MAP[i + 1] = cnt
    after_tmp = [0] * (MAP[-1] + 1)
    cnt = 0
    out = 0
    for w in range(W):
        for h in range(H):
            after_tmp[MAP[h]] += int(S[h][w])
        for af in after_tmp:
            if af > K:
                out = 1
                break
        else:
            after_tmp = [0] * (MAP[-1] + 1)
    if out == 1:
        return 1000000
    else:
        for w in range(W):
            for h in range(H):
                after_tmp[MAP[h]] += int(S[h][w])
            for af in after_tmp:
                if af > K:
                    cnt += 1
                    after_tmp = [0] * (MAP[-1] + 1)
                    for h2 in range(H):
                        after_tmp[MAP[h2]] += int(S[h2][w])
                    break
        return cnt + MAP[-1]

MIN = 1000000
for i in range(2**(H - 1)):
    MIN = min(MIN, check(i))

print(MIN)


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


bool judge(std::vector< std::vector<bool> > image){
    for(int i=1; i<image.size()-1; i++){
        for(int j=1; j<image[i].size()-1; j++){
            if(image[i][j]){
                if(!image[i+1][j] && !image[i-1][j] && !image[i][j+1] &&!image[i][j-1]){
                    return false;
                }
            }
        }
    }
    return true;
}

int main(){
    std::vector< std::vector<bool> > image;
    int w,h;

    std::cin >> h >> w;
    for(int i=0;i<h;i++){
        std::vector<bool> row(w);
        for(int j=0; j<w; j++){
            char buff;
            std::cin >> buff;
            if(buff=='#')       row[j] = true;
            else if(buff=='.')  row[j] = false;
        }
        image.push_back(row);
    }
    if(judge(image)) std::cout <<"Yes" << std::endl;
    else             std::cout <<"No" << std::endl;

    return 0;
}

Measured memory_bytes: 256
o= input()
e= input()
P = ''

if len(o)==len(e):
    for i in range(len(o)):
        P += o[i]
        P += e[i]
else:
    for i in range(len(o)-1):
        P += o[i]
        P += e[i]
    P += o[len(o)-1]
print(P)

Measured memory_bytes: 2940
#[allow(dead_code)]
fn main() {
    let a = i::u();
    let b = i::s();
    let c = a * (b[0] as usize - '0' as usize) * 100
        + a * (b[2] as usize - '0' as usize) * 10
        + a * (b[3] as usize - '0' as usize);
    println!("{}", c / 100);
  //  dbg!(a, b, c);
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }
    pub fn str() -> String {
        read()
    }
    pub fn s() -> Vec<char> {
        str().chars().collect()
    }
    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn u4() -> (usize, usize, usize, usize) {
        (read(), read(), read(), read())
    }

    pub fn u5() -> (usize, usize, usize, usize, usize) {
        (read(), read(), read(), read(), read())
    }

    pub fn u6() -> (usize, usize, usize, usize, usize, usize) {
        (read(), read(), read(), read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn iv3(n: usize) -> Vec<(i64, i64, i64)> {
        (0..n).map(|_| iv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn uv4(n: usize) -> Vec<(usize, usize, usize, usize)> {
        (0..n)
            .map(|_| uv(4))
            .map(|a| (a[0], a[1], a[2], a[3]))
            .collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
//#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)

using namespace std;
//using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef pair<int, int> ii;
typedef pair<long long, pair<int, int>> iii;
typedef pair<ii, ii> iiii;

const double PI = acos(-1.0), EPS = 1e-6;
const int N = 200005, M = 100005, mod = 998244353 , mxLog = 20;

int cnt[N];

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(6), cout << fixed;

    int n, m;
    cin >> n >> m;

    for (int i = 0; i < n; ++i) {
        int k;
        cin >> k;
        int a;
        while (k--) {
            cin >> a;
            ++cnt[a];
        }
    }

    int ans = 0;
    for (int i = 1; i <= m; ++i) {
        ans += cnt[i] == n;
    }

    cout << ans << '\n';


    return 0;
}


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

int data[N+1], n;

void swap(int* a, int* b){
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

void maxHeapify(i){
  int l = 2*i;
  int r = 2*i+1;
  int valM;
  if(l <= n && data[l] > data[i]) valM = l;
  else valM = i;
  if(r<=n && data[r] > data[valM]) valM = r;
  if(valM != i){
    swap(&data[i], &data[valM]);
    maxHeapify(valM);
  }
}

void buildMaxHeap(){
  int i;
  for(i=n/2;i>0;i--) maxHeapify(i);
}

main(){
  int i;
  scanf("%d", &n);
  for(i=1;i<=n;i++) scanf("%d", &data[i]);
  buildMaxHeap();
  for(i=1;i<=n;i++) printf(" %d", data[i]);
  printf("\n");
  return 0;
}

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

using namespace std;

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

    bool z = false;
    for (int i = 1; i <= 9; i++) {
        if (z)
            break;
        for (int j = 1; j <= 9; j++)
        {
            if (i * j != n)
                continue;

            z = true;
            break;
        }
    }

    cout << (z ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	s = readline() |> chomp
	f = 0
	for i in 1:length(s)-1
		if s[i:i+1] == "AC"
			f = 1
			break
		end
	end
	println(f==1?"Yes":"No") 
end

main()

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

int main()
{
  int **arr;
  int h, w;
  int temp = 0;
  int num;
  int temp2 = 0;
  scanf("%d %d", &h, &w);
  
  arr = (int**)malloc(sizeof(int*)*h+1);
  for(int i = 0; i < h+1; i++)
    {
      arr[i] = (int*)calloc(w+1, sizeof(int));
    }
  for(int  i = 0; i < h; i++)
  {
    for(int j = 0; j < w; j++)
      {
	scanf("%d", &num);
	arr[i][j] = num;
	temp += num;
      }
    arr[i][w] = temp;
    temp = 0;
  }
  for(int i = 0; i < w; i++)
    {
      for (int j = 0; j < h; j++)
	{
	  temp += arr[j][i];
	}
      arr[h][i] = temp;
      temp2 += temp;
      temp = 0;
    }
  arr[h][w] = temp2;

  for(int i = 0; i<h+1; i++)
    {
      for(int j = 0; j<w; j++)
	{
	  printf("%d ", arr[i][j]);
	}
      for(int k = 0; k < 1; k++)
	{
	  printf("%d", arr[i][w]);
	}
      printf("\n");
    }
}



Measured memory_bytes: 2080
#include <iostream>
#include<algorithm>
using namespace std;
#define ll long long int
int main()
{
    ll n;
    cin>>n;
    ll a[100005]={};
    ll temp;
    ll i;
    ll sum =0;
    for(i=0;i<n;i++){
        cin>>temp;
        a[temp]++;
        sum = sum + temp;
    }
    ll q;
    cin>>q;
    ll x,y;
    while(q--){ 
        cin>>x>>y;
        ll diff = y-x;
        ll num = a[x];
        a[y] = a[y]+a[x];
        a[x]=0;
        sum = sum+diff*num;
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 4400
#include <iostream>
using namespace std;
int main(void){
    long long n,x,a[2000],b[2000];
    long long y=0;
    cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i];
        y+=a[i];
    }
    for(long long i=0;i<n;i++){
        long long z=x*i;
        for(int j=0;j<n;j++){
            b[j]=min(a[(j-i+n)%n],b[j]);
            z+=b[j];
        }
        y=min(y,z);
    }
    cout<<y<<endl;
}


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

using namespace std;


/******************************************************************************
	Main
******************************************************************************/
int main()
{
	string s = "";
	cin >> s ;
	assert(s.size() == 3);

	string answer = (s == "AAA" || s == "BBB")? "No": "Yes";
	cout << answer << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define debug(x) cerr << #x << " " << x << endl;
#define debug_p(x) cerr << #x << " [" << x.fi << " " << x.se << "]"<<endl;
#define debug_v(x) {cerr << #x << " "; for (auto ioi : x) cerr << ioi << " "; cerr << endl;}
#define debug_vp(x) {cerr << #x << " "; for (auto ioi : x) cerr << '[' << ioi.fi << " " << ioi.se << ']'; cerr << endl;}
#define debug_v_v(x) {cerr << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cerr << ioi2 << " "; cerr << '\n';} cerr << "*/" << #x << endl;}
#define gen_clock(x) ll x = clock(); cerr << "Clock " << #x << " created" << endl;
#define check_clock(x) cerr << "Time spent in " << #x << ": " << (double)(clock() - x)/CLOCKS_PER_SEC << endl; x = clock();
#define reset_clock(x) x = clock()

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	int n,i;
	cin>>n;
	unsigned ll maxx=1e18;
	unsigned ll ans=1,a[n];
	
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	if(a[0]==0)
	{
		cout<<0;
		return;
	}
	for(i=0;i<n;i++)
	{
		if(a[i] <= maxx/ans)
		ans*=a[i];
		else
		{
			cout<<-1;
			return;
		}
	}
	cout<<ans;
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 4388
#include<bits/stdc++.h>
#define N 100005
using namespace std;
int n,m,cnt,tot,fst[N],pnt[N<<1],nxt[N<<1],ans[N],dp[N][11];
void add(int x,int y){
	pnt[++tot]=y; nxt[tot]=fst[x]; fst[x]=tot;
}
int main(){
	scanf("%d%d",&n,&m);
	int i,j,x,y;
	for (i=1; i<=m; i++){
		scanf("%d%d",&x,&y);
		add(x,y); add(y,x);
	}
	scanf("%d",&cnt);
	for (i=1; i<=cnt; i++){
		scanf("%d%d%d",&x,&y,&ans[i]); dp[x][y]=i;
	}
	for (i=9; i>=0; i--)
		for (x=1; x<=n; x++){
			dp[x][i]=max(dp[x][i],dp[x][i+1]);
			for (j=fst[x]; j; j=nxt[j]) dp[x][i]=max(dp[x][i],dp[pnt[j]][i+1]);
		}
	for (i=1; i<=n; i++) printf("%d\n",ans[dp[i][0]]);
	return 0;
}

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

using namespace std;
#define int long long
const int N = 1e5 + 10;
int dp[N][3];
/*
r == 0
s == 1
p == 2
*/

int32_t main()
{
    int n, k, r, s, p; cin >> n >> k >> r >> s >> p;
    string S; cin >> S;
    for (int i = 0; i < k; i++) {
        if (S[i] == 'r') dp[i][2] = p;
        if (S[i] == 's') dp[i][0] = r;
        if (S[i] == 'p') dp[i][1] = s;
    }
    for (int i = k; i < n; i++) {
        if (S[i] == 'r') {
            dp[i][0] = max(dp[i - k][1], dp[i - k][2]);
            dp[i][1] = max(dp[i - k][0], dp[i - k][2]);
            dp[i][2] = max(dp[i - k][0], dp[i - k][1]) + p;
        }
        if (S[i] == 's') {
            dp[i][0] = max(dp[i - k][1], dp[i - k][2]) + r;
            dp[i][1] = max(dp[i - k][0], dp[i - k][2]);
            dp[i][2] = max(dp[i - k][0], dp[i - k][1]);
        }
        if (S[i] == 'p') {
            dp[i][0] = max(dp[i - k][1], dp[i - k][2]);
            dp[i][1] = max(dp[i - k][0], dp[i - k][2]) + s;
            dp[i][2] = max(dp[i - k][0], dp[i - k][1]);
        }
    }
    int ans = 0;
    for (int i = n - 1; i >= max(0ll, n - k); i--) ans += max(dp[i][0], max(dp[i][1], dp[i][2]));
    cout << ans << "\n";
}


Measured memory_bytes: 2816
import java.util.*;
import java.io.*;
class Main {
    static long MOD = (long)(1e9+7);
    static long prefSum(long[] a, int left, int right) {
        long ans = a[right];
        if(left-1>=0)
            ans = ((ans-a[left-1])%MOD+MOD)%MOD;
        return ans;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i<n; i++)
            a[i] = sc.nextInt();
        long[][] dp = new long[n+1][k+1];
        for(int i = 0; i<=n; i++)
            dp[i][0] = 1;
        long[][] pref = new long[n+1][k+1];
        for(int i = 0; i<=n; i++)
            pref[i][0] = 1;
        for(int i = 1; i<=k; i++)
            pref[0][i] = pref[0][i-1];
        for(int i = 1; i<=n; i++) {
            for(int j = 1; j<=k; j++) {
                int numCandies = Math.min(a[i-1], j);
                dp[i][j] = prefSum(pref[i-1], j-numCandies, j);
                pref[i][j] = (pref[i][j-1] + dp[i][j])%MOD;
            }
        }
        System.out.println(dp[n][k]);
    }
}

Measured memory_bytes: 243028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()



int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  
  string s;
  ll x, y;
  cin >> x >> y;
  
  bool ans = false;  
  rep(i, 0, 101) {
    rep(j, 0, 101) {
      if(i+j==x and 2*i+4*j==y) {
        ans = true;
        break;
      }
    }
  }  
  
  cout << ( ans ?"Yes" :"No") << "\n";

}

Measured memory_bytes: 3636
#include <math.h>

#include <algorithm>

#include <iostream>

#include <string>

using namespace std;
#define endl '\n'

//////////////////////////////////////////////////////////////////////////
/* Custom function starts here */

/* Custom function ends here: */
//////////////////////////////////////////////////////////////////////////////

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);

  /* MAIN Code STARTS here: */
    string s;
    cin >> s;
    int size = s.size();
    for(int i = 0; i < size; i++){
        s[i] = 'x';
    }
    cout << s << endl;

  /* MAIN Code ENDS here: */
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3168
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n, = map(int,readline().split())
*a, = map(int,readline().split())
q,*bc = map(int,read().split())

from collections import Counter
d = Counter(a)
res = sum(a)


m = iter(bc)
for b,c in zip(m,m):
    if b in d:
        v = d[b]
        d[b] = 0
        d[c] += v
        res += (c-b)*v
    print(res)






Measured memory_bytes: 36212