akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define arep(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N - 1);
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, N) cin >> B[i];
    rep(i, 0, N - 1) cin >> C[i];
    int ans = 0;
    rep(i, 0, N) {
        ans += B[A[i] - 1];
        if (A[i] + 1 <= N && A[i + 1] == A[i] + 1) {
            ans += C[A[i] - 1];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<58;
 
int main(){
    ll n,m; cin >> n >> m;
    string s, t; cin >> s >> t;
   	ll g = gcd(n, m);
  	ll res = (n * m) / g;
  	n /= g, m /= g;
  	bool ok = true;
  	for(ll i = 0; i < g; ++i){
      if(s[i*n] != t[i*m]) ok = false;
    }
  	if (ok) cout << res << endl;
    else cout << -1<< endl;
}

Measured memory_bytes: 512
a = [int(input()) for i in range(5)]
before = 9
index = 0

for i in range(5):
    if before > (a[i]+9)%10:
        before = (a[i]+9)%10
        index = i
for i in range(5):
    if i != index and a[i]%10 != 0:
        a[i] = (a[i]+10)//10*10

print(sum(a))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
     int N, K;
  	cin >> N >> K;
  
  	int F = 1;
  
  for (int i = 0; i < N; i++) {
  	if (F <= K) {
		F *= 2;
    }
    else {
    	F += K;
    }
  
  }
  
  cout << F << endl;
  
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

typedef long long i64;
typedef pair<i64, i64> pii;

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

string a, b, c;

char solve(char now) {
  string &p = (now == 'A')? a : (now == 'B')? b : c;
  if (p.empty()) return now;
  else {
    char c = toupper(p.back());
    p.pop_back();
    return solve(c);
  }
}

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> a >> b >> c;
  reverse(all(a));
  reverse(all(b));
  reverse(all(c));
  cout << solve('A') << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	ll n, m, x, a;
	cin >> n >> m >> x;
	ll l = 0, r = 0;
	REP(i, m) {
		cin >> a;
		if (a < x) ++l;
		else ++r;
	}
	cout << min(l, r) << endl;
	return 0;
}
 

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

int main()
{
    int n,m;
    cin >> n;
    string s[n];
    int sum[n]={};
    for(int i=0;i<n;i++){
        cin >> s[i];
    }
    cin >> m;
    string t[m];
    for(int i=0;i<m;i++)
        cin >> t[i];
    int max=0;
    for(int i=0;i<n;i++){
        int j=i;
        for(;j<n;j++){
            if(s[i]==s[j]){
                sum[j]++;
            }
        }
        for(int k=0;k<m && s[i]!=s[j];k++){
            if(s[i]==t[k]){
                sum[i]--;
            }
        }
        if(max<=sum[i]){
            max = sum[i];
        }
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
struct edge{ll from,to,cost;};
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,p,a,b,c;
    cin>>n>>m>>p;
    ll d[n];
    bool maki[n];
    memset(maki,0,sizeof(maki));
    vector<edge> g;
    for(int i=1;i<n;i++)d[i]=1e18;
    d[0]=0;
    for(int i=0;i<m;i++){
        cin>>a>>b>>c;
        g.push_back({a-1,b-1,p-c});
    }
    for(int i=0;i<n-1;i++){
        for(int j=0;j<m;j++){
            if(d[g[j].from]!=1e18&&d[g[j].to]>d[g[j].from]+g[j].cost){
                d[g[j].to]=d[g[j].from]+g[j].cost;
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(d[g[j].from]!=1e18&&d[g[j].to]>d[g[j].from]+g[j].cost){
                d[g[j].to]=d[g[j].from]+g[j].cost;
                maki[g[j].to]=true;
            }
            if(maki[g[j].from])maki[g[j].to]=true;
        }
    }
    if(maki[n-1])cout << -1<<endl;
    else cout << max(0LL,-d[n-1]) <<endl;
    return 0;
}


Measured memory_bytes: 576
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    // read in integer 
    string s;
    cin >> s;

    for (int i = 1; i < s.length(); i++) 
        if (s[i] != s[0]){
            cout << "Yes" << endl;
            return 0;
        }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
// I - Coins
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
using DBL = double;

int main(){
	int N; cin>>N;
	DBL P[N+1]; // 1 index
	rp(i, 1, N+1) cin>>P[i];

	DBL dp[N+1][N+1]; // i 枚までで、j 枚表の確率
	rp(j, 1, N+1) dp[0][j] = 0;
	dp[0][0] = 1;

	rp(i, 1, N+1){ // [1,N]
		rp(j, 0, N+1){ // [0,N]
			dp[i][j] = dp[i-1][j] * (1-P[i]); // i: back, ¬pi
			if(0 <= j-1) dp[i][j] += dp[i-1][j-1] * P[i]; // i: front, pi
		}
	}

	DBL ans = 0;
	rp(j, (N+2-1)/2, N+1) ans += dp[N][j]; // dp[N][]: N 枚までで、j=ceil(N/2) 枚以上が表を集計
	cout<<setprecision(10)<<ans<<endl;

	// // print =================
	// cout<<"===\n";
	// cout<<"ans "<<setprecision(12)<<fixed<<ans<<"\n";
	// cout<<"N "<<N<<"\n";
	// rp(i,0,N+1) cout<<setprecision(3)<<fixed<<P[i]<<" ";
	// cout<<"\n";
	// cout<<"---\n";
	// rp(i,0,N+1){
	// 	rp(j,0,N+1) cout<<setprecision(3)<<fixed<<dp[i][j]<<" ";
	// 	cout<<"\n";
	// }
	// cout<<"\n";
	// // =======================

}


Measured memory_bytes: 70528
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int MOD; 
vi adj[111111];

int add(int a, int b)
{
	a+=b;
	a%=MOD;
	if(a<0) a+=MOD;
	return a;
}

int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}

int F[111111];
int G[111111];
int sub[111111];

void prep(int u, int p=-1)
{
	sub[u]=1;
	for(int v:adj[u])
	{
		if(v==p) continue;
		prep(v,u);
		sub[u]+=sub[v];
	}
}
int H[111111];
int pow2[111111];
void dfs(int u, int p)
{
	F[u]=1;
	vector<ll> pre;
	for(int v:adj[u])
	{
		if(v==p) continue;
		dfs(v,u);
		F[u]=mult(F[u],add(F[v],1));
		pre.pb(add(F[v],1));
	}
	vector<ll> suf=pre;
	for(int i=int(suf.size())-1;i>=0;i--)
	{
		if(i+1<suf.size()) suf[i]=mult(suf[i],suf[i+1]);
	}
	for(int i=1;i<pre.size();i++) pre[i]=mult(pre[i],pre[i-1]);
	int c=0;
	for(int v:adj[u])
	{
		if(v==p) continue;
		H[v]=1;
		if(c>0) H[v]=pre[c-1];
		if(c+1<suf.size()) H[v]=mult(H[v],suf[c+1]);
		c++;
	}
}
void dfs2(int u, int p)
{
	for(int v:adj[u])
	{
		if(v==p) continue;
		//G[v]
		G[v]=1;
		G[v]=add(G[v],mult(G[u],H[v]));
		//cerr<<v<<' '<<F[v]<<' '<<G[v]<<'\n';
		dfs2(v,u);
	}
}
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n>>MOD;
	pow2[0]=1;
	for(int i=1;i<=n;i++) pow2[i]=add(pow2[i-1],pow2[i-1]);
	for(int i=0;i<n-1;i++)
	{
		int u,v; cin>>u>>v; u--; v--; adj[u].pb(v); adj[v].pb(u);
	}
	prep(0,-1);
	dfs(0,-1);
	G[0]=1;
	dfs2(0,-1);
	for(int i=0;i<n;i++)
	{
		cout<<mult(G[i],F[i])<<'\n';
	}
}


Measured memory_bytes: 18048
#include<bits/stdc++.h>
using namespace std;
int n,k;
const int maxn=2010;
vector<int> ed[maxn];
int mdis[maxn][maxn];
void bfs(int k)
{
	queue<int> q;
	q.push(k);
	while(!q.empty())
	{
		int now=q.front();
		q.pop();
		for(int i=0;i<ed[now].size();i++)
		{
			int to=ed[now][i];
			if(mdis[k][to] || k==to)continue;
			mdis[k][to]=mdis[k][now]+1;
			q.push(to);
		}
	}
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		ed[u].push_back(v);
		ed[v].push_back(u);
	}
	for(int i=1;i<=n;i++)
		bfs(i);
	int ans=n;
	if(k%2)
	{
		for(int u=1;u<=n;u++)
			for(int i=0;i<ed[u].size();i++)
			{
				int now=0,v=ed[u][i];
				for(int j=1;j<=n;j++)
					if(min(mdis[u][j],mdis[v][j])>k/2)
						now++;
				ans=min(ans,now);
			}
	}
	else
	{
		for(int u=1;u<=n;u++)
		{
			int now=0;
			for(int v=1;v<=n;v++)
				if(mdis[u][v]>k/2)
					now++;
			ans=min(ans,now);
		}
	}
	printf("%d\n",ans);
	return 0;
}
/*
6 3
1 2
3 2
4 2
1 6
5 6
*/

Measured memory_bytes: 16128
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	int ans = 1;
	int n = 1;
	Int sum = 7 % K;
	for (int i = 0; i < 10000000; ++i) {
		if (sum % K == 0) {
			cout << ans << endl;
			return 0;
		}
		(n *= 10) %= K;
		(sum += 7 * n) %= K;
		++ans;
	}
	cout << "-1\n";

	return 0;
}


Measured memory_bytes: 3632
import math
N = int(input())
XY = []
for _ in range(N):
    XY.append(list(map(int,input().split())))
Dists = dict()
c = 0
ans = 0.
for i in range(N):
    for j in range(N):
        if i < j:
            ans += math.sqrt((XY[i][0]-XY[j][0])**2+(XY[i][1]-XY[j][1])**2)
            c += 1
print((ans/c)*(N-1))


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.Arrays;

public class Main {
    private static final int MOD = 1_000_000_007;

    public static void main(String[] args) {
        try (CustomReader in = new CustomReader()) {
            new Main().execute(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void execute(CustomReader in) throws IOException {
        int[] nm = in.readLineAsIntArray();
        final int N = nm[0];
        final int M = nm[1];
        Requirement[] requirements = new Requirement[M];
        for (int i = 0; i < M; i++) {
            int[] r = in.readLineAsIntArray();
            requirements[i] = new Requirement(r[0], r[1]);
        }

        Arrays.sort(requirements, (Requirement r1, Requirement r2) -> r1.right - r2.right);
        int count = 0;
        int pos = 0;
        for(int i=0; i<M; i++){
            if(pos>requirements[i].left){
                continue;
            }
            pos = requirements[i].right;
            count++;
        }
        System.out.println(count);

    }

    class Requirement{
        public final int left;
        public final int right;

        public Requirement(int l, int r) {
            this.left = l;
            this.right = r;
        }
    }




    static class CustomReader extends BufferedReader {

        private static final int DEFAULT_BUF_SIZE = 2048;
        // private static final int DEFAULT_BUF_SIZE = 4096;
        // private static final int DEFAULT_BUF_SIZE = 8192;
        //private static final int DEFAULT_BUF_SIZE = 16384;
        // private static final int DEFAULT_BUF_SIZE = 1048576;

        public CustomReader() throws IOException {
            super(new InputStreamReader(System.in), DEFAULT_BUF_SIZE);
        }

        public int[] readLineAsIntArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            int[] intArray = new int[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                intArray[i] = Integer.parseInt(strArray[i]);
            }
            return intArray;
        }

        public int[][] readAsIntMatrix(int rows, int columns) throws IOException {
            int[][] matrix = new int[rows][columns];
            for (int i = 0; i < rows; i++) {
                String[] r = this.readLine().split(" ");
                for (int j = 0; j < columns; j++) {
                    matrix[i][j] = Integer.parseInt(r[j]);
                }
            }
            return matrix;
        }
    }
}

Measured memory_bytes: 49192
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;
  rep(i, n) {
    if(i==0)continue;
    if(a[i-1] <= a[i]) continue;
    ans += a[i-1] - a[i];
    a[i] = a[i-1];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3992
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <stdlib.h>
#include <stdio.h>

using namespace std;

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 abs_A(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

int abs_B(long long num, long long numb) {
    if (num - numb >= 0)
        return num - numb;
    else
        return -1 * (num - numb);
}

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

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

bool permutation(vector<int>& vec,vector<int>& P) {
    bool ok = true;
    for (int i = 0; i < vec.size(); i++) {
        //cout << vec.at(i);
        if (vec.at(i) != P.at(i)) {
            ok = false;
        }
    }
    return ok;
}

/*bool nibu(vector<int>& retu,int key) {
    
}*/

const long long MOD = 1000000007;
const int INF = 1001001001;

int main() {
    vector<vector<int>> B(3, vector<int>(3));
    for (int i = 0; i < 3 ; i++) {
        for (int j = 0; j < 3 ; j++) {
            cin >> B.at(i).at(j);
        }
    }
    int N;
    cin >> N;
    vector<int> retu(N);
    for (int i = 0; i < N; i++) {
        cin >> retu.at(i);
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (retu.at(i) == B.at(j).at(k)) {
                    B.at(j).at(k) = 111;
                }
            }
        }
        
    }
    if (B.at(0).at(0) == B.at(0).at(1) && B.at(0).at(2) == B.at(0).at(1) || B.at(1).at(0) == B.at(1).at(1) && B.at(1).at(2) == B.at(1).at(1) || B.at(2).at(0) == B.at(2).at(1) && B.at(2).at(2) == B.at(2).at(1) || B.at(0).at(0) == B.at(1).at(0) && B.at(1).at(0) == B.at(2).at(0) || B.at(1).at(1) == B.at(2).at(1) && B.at(2).at(1) == B.at(0).at(1) || B.at(0).at(2) == B.at(1).at(2) && B.at(1).at(2) == B.at(2).at(2) || B.at(0).at(0) == B.at(1).at(1) && B.at(1).at(1) == B.at(2).at(2) || B.at(0).at(2) == B.at(1).at(1) && B.at(2).at(0) == B.at(1).at(1)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}



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

int main()
{
    long a, b;
    cin >> a >> b;
    if (a == b) {
        cout << 0 << endl;
    } else if ((a + b) % 2 == 0) {
        cout << (a + b) / 2 << endl;
    } else {
        cout << "IMPOSSIBLE";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,t,x,y,z,d;
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>t>>x>>y;
        if(!(x+y<=t&&(t-x-y)%2==0)){
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Yes\n";
    return 0;
}

Measured memory_bytes: 384
// 6/28 バーチャル参加
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main() {
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    int n,m;
    cin>>n>>m;
    string a,b;
    for(int i=0;i<m;i++) a.push_back(n+'0');
    for(int j=0;j<n;j++) b.push_back(m+'0');
     if(a>b)cout<<b<<endl;
    else cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ull  unsigned long long
int main()
{
    string n;
    cin>>n;
     ull sum=0;
    for(ull i=0;i<n.size();i++)
    {
        sum=sum+(n[i]-48);
    }
    if(sum%9==0)
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
}


Measured memory_bytes: 3672
n,y = gets.split.map(&:to_i)

(0..n).each do |a|
  (0..n - a).each do |b|
    c = n - (a + b)
    if y == 10000*a + 5000*b + 1000*c
      puts "#{a} #{b} #{c}"
      exit
    end
  end
end

puts "-1 -1 -1"

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int ara[102];

int main()
{
    long long n,k;
    cin>>n>>k;
    if(n==k)printf("0\n");
    else if(n<k)printf("%lld\n",min(n,k-n));
    else
    {
        n%=k;
        printf("%lld\n",min(n,k-n));
    }
    return 0;
}


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

int main() {
double N;
  int K;
  int in;
  int count=0;
 double ans=0;
 
  cin >> N >> K;
    vector<double> prob(N);
  for (int i=1; i<=N; i++){
    in = i;
    count =0;
  while( in < K){
  in= 2* in;
    count++;
  }
    prob.at(i-1)=pow(0.5, count);

  }
  for (int i =1; i<=N ; i++){
  ans = ans + (prob.at(i-1));
  }

  cout<<std::setprecision(10)<< ans / N<<endl;
  return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

  
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int n,m;
  cin >> n >> m;
  char c[n][3];
  rep(i,n){
    int w=0,b=0,r=0;
    rep(j,m){
      cin>>c[i][j];
      if(c[i][j]=='W')w++;
      if(c[i][j]=='B')b++;
      if(c[i][j]=='R')r++;
    }
    c[i][0]=w;
    c[i][1]=b;
    c[i][2]=r;
  }
  vector<vector<int>>sum(n+1,vector<int>(3));
  sum[0][0]=0;
  sum[0][1]=0;
  sum[0][2]=0;
  rep(i,n){
    rep(j,3){
      sum[i+1][j]=sum[i][j]+c[i][j];
    }
  }
  int ans=2500;
  rep(i,n-2){
    for(int j=i+1;j<n-1;j++){
      int res=0;
      res+=(i+1)*m-sum[i+1][0];
      res+=(j-i)*m-(sum[j+1][1]-sum[i+1][1]);
      res+=(n-(j+1))*m-(sum[n][2]-sum[j+1][2]);
      ans=min(ans,res);
    }
  }
  cout << ans << endl;
}



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

int main(void) {
    int a, b, c;
    int count = 0;
    
    cin >> a >> b >> c;
    
    for(int i = a; i <= b; ++i) {
        if(c % i == 0) {
            ++count;
        }
    }
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 3096
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;

bool BellmanFord(vvP graph, int start, vll &cost, int V) {
	//vi prev(V);
	vb visitable(V, false);
	int k = 0;
	int visitable_num = 0;

	stack<int> st;
	st.push(start);
	while (!st.empty()) {
		int pos = st.top();
		st.pop();
		visitable[pos] = true;
		rep(i, graph[pos].size()) {
			if (!visitable[graph[pos][i].first]) {
				st.push(graph[pos][i].first);
			}
		}
	}

	rep(i, V) {
		if (visitable[i])visitable_num++;
	}

	fill(cost.begin(), cost.end(), INFL);
	cost[start] = 0;

	ll ans = -INFL;
	while (true) {
		bool flag = true;
		rep(i, V)rep(j, graph[i].size()) {
			// 全辺(i->graph[i][j].first)に対して
			if (visitable[i] && cost[graph[i][j].first] > cost[i] + graph[i][j].second) {
				cost[graph[i][j].first] = cost[i] + graph[i][j].second;
				//prev[graph[i][j].first] = i;
				flag = false;
				break;
			}
		}
		if (flag)break;
		if (k >= visitable_num) {
			if (cost[V - 1] < ans) {
				return false;
			}
			else {
				if (k >= visitable_num * 2) {
					return true;
				}
				ans = cost[V - 1];
			}
		}
		k++;
	}
	return true;
}

int main() {
	/*
	ifstream ifs(".in");
	ofstream ofs("A1.txt");
	cin.rdbuf(ifs.rdbuf());
	cout.rdbuf(ofs.rdbuf());
	*/
	int N, M;
	cin >> N >> M;
	vvP G(N);
	rep(i, M) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		G[a].push_back(mp(b, -c));
	}

	vll cost(N);

	if (BellmanFord(G, 0, cost, N)) {
		cout << -cost[N - 1] << endl;
	}
	else {
		cout << "inf" << endl;
	}

	return 0;
}

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

using namespace std;

string first,second;
string output ("");

int dp[3003][3003];
int lcs(int i, int j){
    if(i == first.size() || j == second.size()){
        return 0;
    }
    if(dp[i][j] == -1) {
        if (first[i] == second[j]) {
            dp[i][j] = 1 + lcs(i + 1, j + 1);
            return dp[i][j];
        }
        dp[i][j] = max(lcs(i + 1, j), lcs(i, j + 1));
        return dp[i][j];
    }
    return dp[i][j];
}

int main() {
    cin >> first >> second;
    for(int i = 0; i < 3003; i++){
        for(int j = 0; j < 3003; j++){
            dp[i][j] = -1;
        }
    }

    int index = lcs(0,0);
    /*if(index == 0){
        cout << "";
        return 0;
    }*/
    string lcsstring("");
    int i = 0,j = 0;
    while(i < first.size() && j < second.size()){
        if(first[i] == second[j]){
            lcsstring += first[i];
            i++, j++;
        }
        else if(dp[i+1][j] > dp[i][j+1]){
            i++;
        }
        else{
            j++;
        }
    }
    cout << lcsstring << endl;
    return 0;
}

Measured memory_bytes: 35712
def judge(S:str) -> str:
    lenS = len(S)
    # 1.両端が同じなら、残り文字3になるまで続く
    if S[0] == S[-1]:
        if (lenS-3)%2 == 1:
            return "First"
        else:
            return "Second"
        
    # 2.両端が違うなら、最初に交互になっている両端の文字が最終状態
    else:
        last = S[0]
        flag = 1
        for i in range(1,lenS):
            # 最後の文字を発見
            if flag and S[i]==S[-1]:
                last = last + S[-1]
                flag = 0
                
            # 最初の文字を発見
            elif (not flag) and S[i]==S[0]:
                last = last + S[0]
                flag = 1
                
        # 奇数手ならfirstの勝ち
        if (lenS - len(last))%2 == 1:
            return "First"
        else:
            return "Second"
        
S = input()
print(judge(S))

Measured memory_bytes: 3316
n, k = map(int, input().split())

array = []

s = 0
for i in range(k):
  d = int(input())
  array += list(map(int, input().strip().split()))

array = set(array)

for j in range(1,n+1):
  if j not in array:
    s += 1
print(s)  


Measured memory_bytes: 9152
/*
Look at the star
Look at the shine for U
*/
#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define sl(x) scanf("%lld",&x)
using namespace std;
const int N = 1e6+5;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
ll s[N];
int main()
{
	ll n,i,j,k;
	sl(n);
	ll sum = 0;
	for(i = 0;i < n;i++)
		sl(s[i]),sum+=s[i];
	double ave = sum*1.0/n;
	double maxx = 1e18;
	ll pos = 0;
	for(i = 0;i < n;i++)
	{
		if(fabs(s[i]-ave) < maxx)
		{
			maxx = fabs(s[i]-ave);
			pos = i;
		}
	}
	printf("%lld\n",pos);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,-1,1,1,-1};
int dy[]={0,1,0,-1,-1,-1,1,1};

int M_N = 1000000;

vector<LL> fact;
vector<LL> inver(M_N+1);
 
LL combi(int n,int r){
    if(n<r||n<0||r<0) return 0;
    return fact[n]%mod*inver[n-r]%mod*inver[r]%mod;
}
 
 
LL fpow(LL a, LL n){
    LL x = 1;
    while(n > 0){
        if(n&1){
            x=x*a%mod;
        }
        a=a*a%mod;
        n >>= 1;
    }
    return x;
}
 
void set_combi(){
    LL s=1;
    fact.push_back(1);
    for(int i=1;i<=M_N;i++){
        s*=i;
        s%=mod;
        fact.push_back(s);
    }
    inver[M_N]=fpow(fact[M_N],mod-2);
    for(int i=M_N-1;i>=0;i--){
        inver[i]=inver[i+1]*(i+1)%mod;
    }
}
 
LL hcombi(int n,int r){
    return combi(n+r-1,r); 
}


int main(){
    set_combi();
    LL n,m;cin >> n >> m;
    LL ans = combi(m, n) * fact[n] %mod;
    LL s = 0;
    for (int i = 0; i <= n; i++) {
        s = (s + (i%2?-1:1) * combi(n, i) %mod * combi(m - i, n - i) %mod * fact[n - i] %mod)%mod;
        s = (s + mod)%mod;
    }
    cout << s * ans % mod << endl;
    return 0;
}


Measured memory_bytes: 19312
#include <iostream>

using namespace std;

const int MOD = 1000000007;

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

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

  long long a = pow(10, N) ;
  long long b = (long long)pow(9, N) * 2 % MOD;
  long long c = pow(8, N);
  int ans = (a - b + MOD + c) % MOD;
  cout << ans << endl;
}

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

    int main (void){
        int x, y;
        
        while(true){
            cin >> x;
            cin >> y;
            if(x == 0 && y == 0){
                break;
            }
            
            if(x < y){
                cout << x << " " << y << endl;
            }
            else{
                cout << y << " " << x << endl;
            }
        }
    
    }


Measured memory_bytes: 3084
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 50;
struct edge { ll from; ll to; ll cost; };

vector<vector<char>>t_d;
int n, q;
string s;

int simulate(int p){
	int now = p;
	rep(i, 0, q) {
		if (s[now] == t_d[i][0]) {
			if (t_d[i][1]== 'R')now++;
			else now--;
		}
		if (now < 0)return 0;
		else if (now >= n)return 1;
	}
	return 2;
}

int bisectL() {
	if (simulate(0) != 0)return 0;
	else if (simulate(n - 1) == 0)return n;

	int ok = 0;
	int ng = n - 1;
	while (ng - ok > 1) {
		int mid = (ng + ok) / 2;
		if (simulate(mid)==0)ok = mid;
		else ng = mid;
	}
	return ok + 1;
}
int bisectR() {
	if (simulate(n-1) != 1)return 0;
	else if (simulate(0) == 1)return n;

	int ok = n-1;
	int ng = 0;
	while (ok - ng > 1) {
		int mid = (ng + ok) / 2;
		if (simulate(mid) == 1)ok = mid;
		else ng = mid;
	}
	return n - ok;
}


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

	rep(i, 0, q) {
		char t, d;
		cin >> t >> d;
		t_d.pb({t,d});
	}

	int l = bisectL();
	int r = bisectR();
	cout << n - l - r << endl;
	return 0;
}

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

int main(){
    int R[3];
    int m=0,n=0;
    for(int i=0;i<3;i++) cin >> R[i];

    for(int i=0;i<3;i++){
        if(R[i]==5){
            m+=1;
        }
        if(R[i]==7){
            n+=1;
        }
    }

    if(m==2&&n==1){
        cout << "YES"<< endl;    
    }else{
        cout<< "NO"<< endl;
    }

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 200005
#define MOD 1000000007
#define INF 10000000

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

ll power(ll a, ll b){
    if(b == 0) return 1;
    ll r  = power(a, b/2);
    r = (r*r)%MOD;
    if(b%2 == 1) r = (r*a)%MOD;
    return r;
}

ll fact(ll a){
    ll r = 1;
    for(ll i = 1; i <= a; i++){
        r *= i; r %= MOD;
    }
    return r;
}

ll inv(ll x){
    return power(x, MOD-2);
}

ll c(ll n, ll r){
    ll k = min(r, n-r);
    ll res = 1;
    for(ll i = 1; i <= k; i++){
        res *= inv(i); res %= MOD;
        res *= (n-i+1); res %= MOD;
    }
    return res;
}
void solve(){
    ll n, a, b;
    cin >> n >> a >> b;  //cout << fact(6);
    ll ans =(power(2, n)-1+MOD)%MOD;
    ans = (ans - c(n, a) + MOD)%MOD;
    ans = (ans - c(n, b) + MOD)%MOD;
    cout << ans;

}

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

/*
5
1 2
2 3
3 4
3 5
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    while(N != 0){
        vector<P> A(N+1);
        N--;
        A[0] = P(0,0);
        vector<int> x = {-1,0,1,0};
        vector<int> y = {0,-1,0,1};
        for(int i=1; i<=N; i++){
            int n,d;
            cin >> n >> d;
            int nx = A[n].first + x[d];
            int ny = A[n].second + y[d];
            A[i] = P(nx,ny);
        }
        int u,d,l,r;
        u = d = l = r = 0;
        for(int i=0; i<=N; i++){
            chmax(u,A[i].second);
            chmin(d,A[i].second);
            chmax(r,A[i].first);
            chmin(l,A[i].first);
        }
        cout << r-l+1 << " " << u-d+1 << endl;
        cin >> N;
    }
    return 0;
}


Measured memory_bytes: 3044
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: i64 = input();

    let y = n / 100;
    let m = n % 100;
    println!(
        "{}",
        if 1 <= y && y <= 12 && 1 <= m && m <= 12 {
            "AMBIGUOUS"
        } else if 1 <= y && y <= 12 {
            "MMYY"
        } else if 1 <= m && m <= 12 {
            "YYMM"
        } else {
            "NA"
        }
    );
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;
using ll = long long;



int main() {
	ll n, a, b,cnt=0,mod=0;
	cin >> n >> a >> b;
	cnt = n / (a + b);
	mod = n % (a + b);
	if (mod >= a) mod = a;
	cout << a * cnt + mod << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
    #include<cstdio>
    #include<vector>
    #include<algorithm>
    using namespace std;
    int ns[510][3];
    int main()
    {
        int n;
        int i,j;
        scanf("%d",&n);
        n--;
        for(i=0;i<n;i++)
            scanf("%d%d%d",&ns[i][0],&ns[i][1],&ns[i][2]);
        for(i=0;i<n;i++)
        {
            int ti=0;
            ti = ns[i][1]+ns[i][0];
            for(j=i+1;j<n;j++)
            {
                if(ti < ns[j][1])
                    ti = ns[j][1];
                if(ti%ns[j][2] != 0)
                {
                    ti += (ns[j][2]-ti%ns[j][2]);
                }
                ti += ns[j][0];
            }
            printf("%d\n",ti);
        }
        printf("0\n");
        return 0;
    }

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<map>
#include<stack>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<sstream>

#define reps(i,f,n) for(int i = f; i < int(n); i++)
#define rep(i,n) reps(i,0,n)
#define PP pair< int,PII >
#define Sort(t) sort(t.begin(), t.end())

using namespace std;
typedef pair<int,int> PII;

priority_queue<PII,vector< PII > , greater< PII > > pq;

int main(void){
	int n;
	while(scanf("%d", &n),n){
		rep(i,n){
			int id;
			cin >> id;
			int sum = 0, x;
			rep(j,8){
				cin >> x;
				sum += j%2==0?x*60:x;
			}
			pq.push( pair<int,int>(sum,id));
		}
		/*
		while(!pq.empty()){
			printf("%d %d\n",pq.top().first, pq.top().second);
			pq.pop();
		}*/
		printf("%d\n", pq.top().second);pq.pop();
		printf("%d\n", pq.top().second);pq.pop();
		while(pq.size() > 2)pq.pop();
		printf("%d\n", pq.top().second);pq.pop();
		pq.pop();
	}
	
	return 0;
}

Measured memory_bytes: 1332
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr int  mod = 1e9 + 1;
int main() {
	int k, l, r;
	cin >> k >> l >> r;
	int f = 0;
	for (int i = l; i <= r; ++i) {
		if (i % k == 0) {
			f = 1; break;
		}
	}
	if (f)puts("OK");
	else puts("NG");
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
#define F first
#define S second
#define pb push_back
#define ld  double
#define ll long long
#define int long long
 
 
using namespace std;
 
const int MAXN = 301 * 1001  , MOD = 1e9 + 7 , sq = 333  ;
 
unordered_map < int , int > d[MAXN] , mark2[MAXN];
 
unordered_map < int , vector < int>  > adj2[MAXN] ;
 
int dis[MAXN] ;
 
int mark[MAXN] ;
 
vector < pair < int , int > > adj[MAXN];
 
int32_t main()
{
   ios::sync_with_stdio(0);cin.tie(0);
   int n ,m ;
   cin >> n >> m ;
   for(int i = 0 ; i < m ; i ++ )
   {
       int x ,y , z ;
       cin >> x >> y >> z ;
       adj[x].pb({y,z});
       adj[y].pb({x,z});
       adj2[x][z].pb(y);
       adj2[y][z].pb(x);
   }
 
   dis[1] = 1 ;
   deque<pair<int,int> > q ;
   for(auto u : adj[1])
   {
       q.push_back({u.F,u.S}) ;
       q.push_back({1,u.S})  ;
       d[u.F][u.S] = 1  ;
       d[1][u.S] = 1 ;
   }
   while(q.size())
   {
       int x = q.front().F ;
       int c = q.front().S ;
       q.pop_front() ;
       if(!dis[x])
        dis[x] = d[x][c] ;
        if(dis[x]==d[x][c]&&!mark2[x][c])
        {
            mark2[x][c] = 1 ;
            for(auto u : adj2[x][c])
            {
                pair<int,int> v = {u,c};
                if(d[v.F][v.S]>d[x][c]||!d[v.F][v.S])
                {
                    d[v.F][v.S] = d[x][c] ;
                    q.push_front({v.F,v.S});
                }
            }
        }
       if(dis[x]>d[x][c]||mark[x]>2)
        continue ;
       mark[x] ++ ;
       for(auto v : adj[x] )
       {
           if(v.S==c)
           {
               if(d[v.F][v.S]>d[x][c]||!d[v.F][v.S])
               {
                   d[v.F][v.S] = d[x][c] ;
                   q.push_front({v.F,v.S});
               }
           }
           else
           {
               if(d[v.F][v.S]>d[x][c] + 1||!d[v.F][v.S])
               {
                   d[v.F][v.S] = d[x][c] + 1 ;
                   q.push_back({v.F,v.S});
               }
           }
       }
 
   }
   if(!dis[n])
    return cout<<-1,0;
   cout<<dis[n] ;
 
 
}

Measured memory_bytes: 134164
// https://atcoder.jp/contests/abc169/tasks/abc169_b

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

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

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

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

#ifndef TEST
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll N;
  cin >> N;

  VL as(N);
  rep(i, N) cin >> as[i];

  auto is_zero = [](ll a) { return a == 0; };

  if (any_of(all(as), is_zero)) {
    drop(0);
  }

  __int128_t acc = 1;

  rep(i, N) {
    if (acc * as[i] > 1e18) drop(-1);
    acc *= as[i];
  }

  ll LIMIT = 1e18;
  if (acc > LIMIT) drop(-1);

  cout << (ll)acc << "\n";
}


Measured memory_bytes: 3984
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
using namespace std;
using ll = long long;
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

ll solve(int h, int w, vector<string> const & s) {
    static const int dy[4] = { -1, 1, 0, 0 };
    static const int dx[4] = { 0, 0, 1, -1 };
    auto used = vectors(h, w, false);
    function<array<ll, 2> (int, int)> go = [&](int y, int x) {
        used[y][x] = true;
        array<ll, 2> k = {};
        k[s[y][x] == '#'] += 1;
        REP (i, 4) {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if (0 <= ny and ny < h and 0 <= nx and nx < w) {
                if (s[ny][nx] != s[y][x] and not used[ny][nx]) {
                    auto k1 = go(ny, nx);
                    k[0] += k1[0];
                    k[1] += k1[1];
                }
            }
        }
        return k;
    };
    ll answer = 0;
    REP (y, h) REP (x, w) if (not used[y][x]) {
        auto k = go(y, x);
        answer += k[0] * k[1];
    }
    return answer;
}

int main() {
    int h, w; cin >> h >> w;
    vector<string> s(h);
    REP (i, h) cin >> s[i];
    cout << solve(h, w, s) << endl;
    return 0;
}


Measured memory_bytes: 18048
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn=10000000;
bool is_prime[maxn];
int solve(int n){
	for(int i=0;i<=n;i++)is_prime[i]=true;
	int ans=0;
	for(int i=2;i<=n;i++){
		if(is_prime[i]){
			ans++;
			for(int j=i*2;j<=n;j+=i)is_prime[j]=false;
		}
	}
	return ans;
}


int main(){
	int n;
	while(cin>>n){
		cout<<solve(n)<<endl;
	}
	return 0;
}

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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
template <typename Val>
Val gcd(Val a, Val b) {
//use ll or int for gcd
    if (b==0) return a;
    else return gcd(b, a%b);
}
template <typename Val>
Val vec_max(vector<Val> v){
  return *max_element(v.begin(),v.end());
}
template <typename Val>
Val vec_min(vector<Val> v){
  return *min_element(v.begin(),v.end());
}
//---------------------------------------------------------------
int main(){
  ll A,B,C,K,ans;
  cin>>A>>B>>C>>K;
  if(A>=K){
    ans = K;
  }else if(A+B>=K){
    ans = A;
  }else{
    ans = A - (K-A-B);
  }


  cout<<ans<<endl;




}


Measured memory_bytes: 3632
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    if (i > 0) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main() {
  int n, i, j;
  int A[N+1];
  scanf("%d", &n);
  for ( i = 0; i < n; i++) scanf("%d", &A[i]);
  trace(A, n);
  for (i = 1; i < n; i ++) {
	  int key = A[i];
	  int j = i - 1;
	  while (j >= 0 && A[j] > key) {
		  A[j+1] = A[j];
		  j --;
	  }
	  A[j+1] = key;
	  trace(A, n);
  }
  return 0;
}

Measured memory_bytes: 1032
S = input()
K = int(input())

if len(list(set(S))) == 1:
  print((len(S) * K) // 2)
  exit()

def nasu(L):
  ans = 0
  N = len(L)
  t = L[0]
  cnt = 1
  for i in range(1, N):
    if t == L[i]:
      cnt += 1
    else:
      ans += cnt // 2
      cnt = 1
    t = L[i]
  ans += cnt // 2
  return ans 

a = nasu(S)
b = nasu(S + S)

print(a + (b - a) * (K - 1))

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1L << 30
#define long long long

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

long H, N;

vector<int> A(100000, 0);
vector<int> B(100000, 0);
//vector<vector<int>> dp(10001, vector<int>(10001, INF));
vector<int> dp(100000, INF);

int main(){
	cin >> H >> N;
	rep(i, N) cin >> A.at(i) >> B.at(i);
	
  	dp.at(0) = 0;
	rep(i, N){
		rep(sum_h, H+1){
          	//if (dp.at(i) == INF) continue;
            //int k = 0;
			//while (A.at(i)*k < H ){
              //int k = ceil(sum_h/A.at(i));
             int temp = max(sum_h - A.at(i), 0);
         	 chmin(dp.at(sum_h), dp.at(temp) + B.at(i));
             //k += 1;
			//}
          //Debug
          //cout << dp.at(i+1).at(sum_h) << endl;
		}
      //Debug
      //cout << "----" << endl;
	}
	cout << dp.at(H) << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const signed INF_=1001001001; const ll INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

pii solve() {
    int K=IN;
    vector<int> a(K);
    cin>>a;
    int mn=2;
    int mx=2;
    REPR(i,K-1) {
        if((a[i]<mn && mx<a[i]*2) || mx<a[i]) {
            return {-1,-1};
        }
        mn=(mn+a[i]-1)/a[i]*a[i];
        mx=(mx/a[i]+1)*a[i]-1;
        if(mn>mx) {
            return {-1,-1};
        }
    }
    return {mn,mx};
}
signed main() {
    pii ans=solve();
    if(ans.first==-1)cout<<-1<<endl;
    else cout<<ans.first<<" "<<ans.second<<endl;
    return 0;
}


Measured memory_bytes: 1024