akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int N=2e5+5,YL=1e9+7;
inline int MO(const int &x){return x>=YL?x-YL:x;}
int lst[N],n,f[N],s[N];
inline int in(){int k;cin>>k;return k;}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;f[0]=1;
	for(int i=1;i<=n;++i)
	{
		int c=in();
		if(lst[c]&&lst[c]!=i-1)
			f[i]=MO(f[lst[c]]+f[i-1]);
		else f[i]=f[i-1];lst[c]=i;
	}
	printf("%d\n",f[n]);
	return 0;
}


Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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


int main(){
    string S, key("keyence");
    cin >> S;
    if(S == key){
        cout << "YES" << endl;
        return 0;
    }
    int n(S.length());
    REP(i, n){
        FOR(j, i, n){
            string T("");
            REP(k, n){
                if(k < i || j < k)
                    T += S[k];

            }
            if(T == key){
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
using ll = long long;

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

ll dp[105][100005];

const int INF = 1001001001;

int main() {
  int n, w;
  cin >> n >> w;
  int a[n][2];
  rep(i, n) rep(j, 2) cin >> a[i + 1][j];

  rep(i, 105) rep(j, 100005) dp[i][j] = INF;
  dp[0][0] = 0;

  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= 100005; ++j) {
      dp[i][j] = dp[i - 1][j];
      if (j - a[i][1] >= 0) {
        dp[i][j] = min(dp[i][j], dp[i - 1][j - a[i][1]] + a[i][0]);
      }
    }
  }

  ll ans = 0;
  rep(i, 100005) {
    if (dp[n][i] <= w) ans = i;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 82304
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a>b){
    for(int i=0;i<a;i++)
      cout<<b;
  }
  else{
    for(int i=0;i<b;i++)
      cout<<a;
  }
  return 0;
}

Measured memory_bytes: 256
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

s=int(input())

mod=10**9+7
MAX_N = s+5
fac = [1,1] + [0]*MAX_N
finv = [1,1] + [0]*MAX_N
inv = [0,1] + [0]*MAX_N
for i in range(2, MAX_N):
    fac[i] = fac[i-1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i-1] * inv[i] % mod

def nCk(n,k):
    if n<k:
        return 0
    if n<0 or k<0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod

lim=s//3
ans=0
for i in range(1,lim+1):
  zan=s-3*i
  ans+=nCk(zan+i-1,i-1)
  ans%=mod

print(ans)

Measured memory_bytes: 9148
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        private static CompareInfo ci = new System.Globalization.CultureInfo("ja-JP").CompareInfo;
        private static int Compare(string a, string b) { return ci.Compare(a, b, System.Globalization.CompareOptions.Ordinal); }

        static void Solve(int N, string S, List<string> list)
        {
            char c = (S.Length > 0) ? (char)(S.Max() + 1) : 'a';
            for (char i = 'a'; i <= c; ++i)
            {
                string T = S + i;
                if (T.Length < N)
                {
                    Solve(N, T, list);
                }
                else
                {
                    list.Add(T);
                }
            }
        }

        static void Main(string[] args)
        {
            int N = ReadInt();
            var list = new List<string>();
            Solve(N, "", list);
            foreach (var ans in list)
            {
                Console.WriteLine(ans);
            }
        }
    }
}


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

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
#define OUT(P) cout << (P) << endl
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)

int sum_digits(int num);
template <class T>
vector<T> copy_vector(vector<T> vec);

int main() {
    int times[5];
    cin >> times[0] >> times[1] >> times[2] >> times[3] >> times[4];
    int min_rest = 10;
    int idx = 0;
    for(int i=0; i<5; i++) {
        if(min_rest > times[i] % 10 && times[i] % 10 != 0) {
            min_rest = times[i] % 10;
            idx = i;
        }
    }

    int count = 0;
    for(int i=0; i<5; i++) {
        if(i!=idx) {
            if(times[i] % 10 == 0) {
                count += times[i];
            } else {
                count += (times[i]/10 + 1) * 10; 
            }
        }
    }
    count += times[idx];
    
    cout << count << endl;
    
    return 0;
}

/******************************/
/***** DECRARED FUNCTIONS *****/
/******************************/

int sum_digits(int num) {
    int rtn = 0;
    while(num != 0) {
        int tmp = num % 10; 
        rtn += tmp;
        num /= 10; 
    }   
    return rtn;
}
//int sum_digits(int num) {
//    int rtn = 0;
//    string num_str = to_string(num);
//    for(int i=0; i<num_str.size(); i++) {
//        rtn += num_str[i] - '0';
//    }   
//    return rtn;
//}

// vectorのコピー
template <class T>
vector<T> copy_vector(vector<T> vec) {
    vector<T> rtn;
    rtn.reserve(vec.size());
    copy(vec.begin(), vec.end(), back_inserter(rtn));
    return rtn;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;
bool maps[2004][2004];
int main() {
	while(true){
	for(int i=0;i<2004;i++)
		for(int j=0;j<2004;j++)
			maps[i][j]=false;
	int mask[1001][2][2];//番号/始点か/Xか
	int dx[]={0,1,0,-1};
	int dy[]={-1,0,1,0};
	int w,h,n;
	vector<int> points[2];
	map<int,int>zeep[2];
	queue<pair<int,int> > qoo;
	cin >> w >> h;
	if(w==0)
	break;
	cin >> n;
	for(int i=0;i<n;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<2;k++){
				cin >> mask[i][j][k];
				if(j==0)
				points[k].push_back(mask[i][j][k]);
				else
				points[k].push_back(mask[i][j][k]);
			}
		}
	}
	
	for(int k=0;k<2;k++){
		int now=1;
		sort(points[k].begin(),points[k].end());
		zeep[k].insert( map<int,int>::value_type(0,0) );
		
		for(int i=0;i<points[k].size();i++){
		if((i==0||points[k][i]!=points[k][i-1])&&points[k][i]!=0 &&points[k][i]!=((k==0)?w:h)){
		zeep[k].insert(map<int,int>::value_type(points[k][i],now) );
		//cout << points[k][i] << endl;
		now++;
		}
		}
		int r=(k==0)?w:h;
		if(zeep[k][r]==0){
		zeep[k][r]=now;
		}
	}
	
	for(int i=0;i<n;i++){
		for(int j=zeep[0][mask[i][0][0]];j<zeep[0][mask[i][1][0]];j++)
			for(int k=zeep[1][mask[i][0][1]];k<zeep[1][mask[i][1][1]];k++){
				maps[j][k]=true;
			}
	}
	
	/*map<int,int>::iterator it =zeep[0].begin();
	while(it!=zeep[0].end()){
		cout <<(*it).first << " "<<(*it).second << endl;
		it++;
	}*/

//	cout << zeep[1][h-1] << endl;
/*	for(int i=0;i<zeep[1][h];i++){
		for(int j=0;j<zeep[0][w];j++)
		cout << maps[j][i] ;
		
		cout << endl;
		}*/
		
	int painted=0;
	
	for(int i=0;i<zeep[0][w];i++)
		for(int j=0;j<zeep[1][h];j++){
			if(maps[i][j]==false){
				maps[i][j]=true;
				painted++;
				qoo.push(pair<int,int>(i,j));
				
				//cout << i <<" head "<< j <<  endl;
				int x,y;
				while(!qoo.empty()){
					x=qoo.front().first;
					y=qoo.front().second;
					qoo.pop();
					for(int k=0;k<4;k++){
						
						if(x+dx[k]>=0 && x+dx[k]<zeep[0][w] &&y+dy[k]>=0 && y+dy[k]<zeep[1][h] &&maps[x+dx[k]][y+dy[k]]==false){
						maps[x+dx[k]][y+dy[k]]=true;
						qoo.push(pair<int,int>(x+dx[k],y+dy[k]));
						}
						
					}
					
				}
				
			}	
		}
		
	cout << painted << endl;
}
	return 0;
}

Measured memory_bytes: 5212
from collections import defaultdict,deque
import math
def gcd(a,b):
    return b if not a%b else gcd(b,a%b)
def lcm(a,b):
    return (a*b)//gcd(a,b)

def main():
    n = int(input())
    if(n>=1800):
        print(1)
    elif(n>=1600):
        print(2)
    elif(n>=1400):
        print(3)
    elif(n>=1200):
        print(4)
    elif(n>=1000):
        print(5)
    elif(n>=800):
        print(6)
    elif(n>=600):
        print(7)
    elif(n>=400):
        print(8)

if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef long double ld;

int niz[1000005];

int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout<<fixed;

    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> niz[i];
    }
    ll cost = 0;
    ll mn = 1000000000;
    for(int k=-100; k<=100; k++){
        cost = 0;
        for(int i=1; i<=n; i++){
            cost += (niz[i]-k)*(niz[i]-k);
        }
        mn = min(mn, cost);
    }
    cout << mn;
    return 0;
}


Measured memory_bytes: 256
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let mut a: Vec<_> = (0..n).map(|i| {
		let x: i32 = s.next().unwrap().parse().unwrap();
		let y: i32 = s.next().unwrap().parse().unwrap();
		(x, y, i)
	}).collect();
	let mut edges = vec![vec![]; n];
	a.sort_by_key(|a| a.0);
	for i in 0..n - 1 {
		let (ax, _, ai) = a[i];
		let (bx, _, bi) = a[i + 1];
		let d = bx - ax;
		edges[ai].push((bi, d));
		edges[bi].push((ai, d));
	}
	a.sort_by_key(|a| a.1);
	for i in 0..n - 1 {
		let (_, ay, ai) = a[i];
		let (_, by, bi) = a[i + 1];
		let d = by - ay;
		edges[ai].push((bi, d));
		edges[bi].push((ai, d));
	}

	let mut ans = 0;
	let mut used = vec![false; edges.len()];
	let mut q = std::collections::BinaryHeap::new();
	q.push((0, 0));
	while let Some((cost, to)) = q.pop() {
		let cost = -cost;
		if used[to] {
			continue;
		}
		used[to] = true;
		ans += cost as i64;
		for &(to, cost) in edges[to].iter() {
			q.push((-cost, to));
		}
	}
	println!("{}", ans);
}


Measured memory_bytes: 20112
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    while(n!=0)
    {
        if(n%10==9)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
        n=n/10;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import math
N, D = map(int, input().split())
X = []

for i in range(N):
  buf = list(map(int, input().split()))
  X.append(buf)

cnt = 0

for i in range(N-1):
  for j in range(i+1,N):
    dist2 = 0
    for index in range(D):
      dist2 += (X[i][index] - X[j][index]) ** 2
    dist = math.sqrt(dist2)
    if dist == float(int(dist)):
      cnt += 1

print(cnt)

Measured memory_bytes: 3064
from copy import deepcopy
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools
import copy


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

#n, m = map(int, input().split())
#tmp = [None]*n
# for i in range(n):
#    tmp[i] = [None]*2
# for i in range(n):
#    tmp[i] = readints()
# print(tmp)
#tmp_so = sorted(tmp, key=lambda x: x[0])
# print(tmp_so)
#cnt = 0
#okane = 0
# for i in range(n):
r, g, b, m = map(int, input().split())
cnt = 0
for i in range(3001):
    for j in range(3001):
        if r*i+g*j <= m:
            tmp = m-(r*i+g*j)
            if tmp % b == 0:
                cnt += 1
print(cnt)


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

int main(){
	int H,W,i,j;
	while(1){
		cin>>H>>W;
			if(H==0&&W==0)break;
		for(j = 0;j < W;j++){
			cout<<"#";
		}
		cout<<endl;
		for(i=2;i<H;i++){
			cout<<"#";
			for(j = 2;j < W;j++){
				cout<<".";
			}
			cout<<"#";
			cout<<endl;
		}
		for(j = 0;j < W;j++){
			cout<<"#";
		}
	cout<<endl<<endl;
	}
return 0;
}



Measured memory_bytes: 2992
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1000000007;
const long long INF = 1LL << 60;
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n,k;
    string s;
    cin >> n >> k >> s;
    int x = 0;
    rep(i,n-1){
        if(s[i] == s[i+1]) x++;
    }
    x += 2 * k;
    cout << ((x < n -1)? x:n - 1) << endl;

    return 0;
}

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

int main() {
  int64_t N;
  cin >> N;
  vector<int64_t> A(N);
  for(int i = 0; i < N; i++){
      cin >> A.at(i);
  }

  int64_t tmp_max = A.at(0);
  int64_t ans = 0;
  for(int i = 0; i < N - 1; i++){
      if(tmp_max > A.at(i + 1)){
          ans += tmp_max - A.at(i + 1);
      }else{
          tmp_max = A.at(i + 1);
      }
      tmp_max = max(tmp_max, A.at(i + 1));
  }

  cout << ans << endl;
}

Measured memory_bytes: 4832
#http://abc079.contest.atcoder.jp/
# -*- coding: utf-8 -*-
import sys

a,b,c,d = list(map(int,list(input())))

operator = ['+','-']

for op1 in operator:
    for op2 in operator:
        for op3 in operator:
            tmp = a   + b if op1=='+' else a - b
            tmp = tmp + c if op2=='+' else tmp - c
            tmp = tmp + d if op3=='+' else tmp - d
            if tmp == 7:
                print('{0}{1}{2}{3}{4}{5}{6}=7'.format(a,op1,b,op2,c,op3,d))
                sys.exit()

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

int sharhad(int n){
  int sum = 0;
  for(int i = 1;i <= n;i *= 10){
    sum += (n%(i*10))/i;
  }
  return sum;
}

int main() {
  int n,sum;
  cin >> n;
  sum = sharhad(n);
  if(n%sum == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<set>
#include<algorithm>
#include<iomanip>

using namespace std;

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    while (true) {
        C -= B;
        if (C <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
        A -= D;
        if (A <= 0) {
            cout << "No" << endl;
            return 0;
        }
    }

}

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

int main() {
  int N,A,B,p;
  
  cin >> N >> A >> B ;
  
  p=N*A;
  
  if (p>B) {
    cout << B << endl;
    }
  else {
    cout << p << endl;
    }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	int a,b;
	int ma;
	cin >> a >> b;
	ma = a +b;
	ma = max(ma, a-b);
	ma = max (ma, a*b);
	cout << ma << endl;
	return 0;
}


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

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	int n, m;
	cin >> n >> m;
	print((n - 1)*(m - 1));
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
  string s;
  cin >> s;
  if((s[0] == 'a' && ((s[1] == 'b' && s[2] == 'c') || (s[1] == 'c' && s[2] == 'b'))) ||
     (s[0] == 'b' && ((s[1] == 'a' && s[2] == 'c') || (s[1] == 'c' && s[2] == 'a'))) ||
     (s[0] == 'c' && ((s[1] == 'b' && s[2] == 'a') || (s[1] == 'a' && s[2] == 'b'))) )
    cout << "Yes";
  else
    cout << "No";
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		int d = scanner.nextInt();

		System.out.println(Math.min(a, b) + Math.min(c, d));
	}
}


Measured memory_bytes: 21844
#include "bits/stdc++.h"
using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	ll x,y;
    cin >> x >> y;
    ll ans = 1;
    while(2 * x <= y){
        x *= 2;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;


int H, W, A, B;


#define MOD 1000000007
#define MX 200005

ll fact[MX];
ll invfact[MX];

ll mod_pow(ll x, ll n, ll mod){
  if(n==0) return 1;
  ll res = mod_pow(x * x % mod, n / 2, mod);
  if(n & 1) res = res * x % mod;
  return res;
}
void comb_init(){
  fact[0] = fact[1] = 1;
  for(ll i=2; i<MX; i++) fact[i] = (fact[i-1] * i) % MOD;
  invfact[0] = invfact[1] = 1;
  for(ll i=2; i<MX; i++) invfact[i] = mod_pow(fact[i], MOD-2, MOD);
}
ll mod_comb(ll n, ll k, ll p){
  if(n<0 || k<0 || n<k) return 0;
  return (((fact[n] * invfact[k]) % MOD) * invfact[n-k]) % MOD;
}


ll calc(int py, int px){
  ll a = mod_comb(py+px, px, MOD);
  ll b = mod_comb(H-1-(py+1)+(W-px-1), W-px-1, MOD);
  return a * b % MOD;
}


int main(){
  ios::sync_with_stdio(false);
  comb_init();
  cin >> H >> W >> A >> B;

  ll ret = 0;
  REP(j,B,W){
    ret += calc(H-A-1, j);
    ret %= MOD;
  }
  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 3328
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
using namespace std;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge> >;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> ss, cs;
    for (int i = 0; i < M; ++i)
    {
        int stemp, ctemp;
        cin >> stemp >> ctemp;
        ss.push_back(stemp);
        cs.push_back(ctemp);
    }
    
    int nummin = 0, nummax = 0;
    if (N == 1) nummin = 0, nummax = 9;
    else if (N == 2) nummin = 10, nummax = 99;
    else if (N == 3) nummin = 100, nummax = 999;

    int result = -1;
    for (int num = nummin; num <= nummax; ++num)
    {
        string str = to_string(num);
        bool ok = true;
        for (int m = 0; m < M; ++m)
        {
            int ele = str[ss[m]-1] - 48;
            //cout << num << endl;
            if (ele != cs[m])
            {
                //cout << num << endl;
                ok = false;

                //cout << m << " false" << endl;
                break;
            }
        }
        if (ok)
        {
            // cout << "ok" << endl;
            result = num;
            break;
        }
        //cout << i << endl;
    }

        cout << result << endl;
        return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) (a).begin(), (a).end()
#define pw(x) (1ll<<(x))
#define lb(x) ((x) & -(x))
#define endl "\n"
#define FI(x) freopen(#x".in","r",stdin)
#define FO(x) freopen(#x".out","w",stdout)
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
//typedef uniform_int_distribution<ll> RR;
const int P = 1e9 + 7;
//ll rnd(ll l, ll r) { mt19937 gen(rand()); RR dis(l, r); return dis(gen); }
int add(int a, int b) {if((a += b) >= P) a -= P; return a < 0 ? a + P : a;}
int mul(int a, int b) {return 1ll * a * b % P;}
int kpow(int a, int b) {int r=1;for(;b;b>>=1,a=mul(a,a)) {if(b&1)r=mul(r,a);}return r;}
//----

const int N = 3e5 + 7;
int a[N], p, n, m, ans, u, v; 

int main() {
	//FI(a);
	ios::sync_with_stdio(0);
	cin.tie(0);
	//cout << setiosflags(ios::fixed);
	//cout << setprecision(2);
	cin >> n >> p;
	if (p == 1 || p == n * 2 - 1) {
		cout << "No" << endl;
		return 0;
	} 
	cout << "Yes" << endl;
	a[n] = p;
	int x = p;
	per(i, 1, n) {
		p--;
		if (p == 0) p = n * 2 - 1;
		a[i] = p;
	}
	rep(i, n+1, n*2) {
		x++;
		if (x == n * 2) x = 1;
		a[i] = x;
	}
	rep(i, 1, n * 2) cout << a[i] << " \n"[i == n * 2 - 1];
	return 0;
}



Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
  int n;
  cin >> n;
  int a[n];

  for(int i=0; i<n; i++) cin >> a[i];
  sort(a, a+n);

  int ans;
  for(int i=a[1]; i>=0; i--){
    int count = 0;
    for(int j=0; j<n; j++){
      if(a[j]%i != 0){
        count++;
        if(count == 2) break;
      }
    }
    if(count < 2){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
from collections import defaultdict, Counter
import sys

def root(uft, x):
    if uft[x] == x: return x
    uft[x] = root(uft, uft[x])
    return uft[x]

def union(uft, rank, x, y):
    x = root(uft, x)
    y = root(uft, y)
    if x == y:
        return

    if rank[x] >= rank[y]:
        uft[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1
    else:
        uft[x] = y

def same(uft, x, y):
    return root(uft, x) == root(uft, y)

def answer():
    n, m, k = map(int, input().split())
    friend = defaultdict(int)
    block = defaultdict(int)
    group = defaultdict(set)
    uft = [i for i in range(n+1)]
    rank = [0] * (n+1)
    for i in range(m):
        a, b = map(int, input().split())
        union(uft, rank, a, b)
        friend[a] += 1
        friend[b] += 1
    for j in range(k):
        c, d = map(int, input().split())
        if not same(uft, c, d):
            continue
        block[c] += 1
        block[d] += 1
    for i in range(1, n+1):
        root(uft, i)
    c = Counter(uft)
    return [c[uft[i]]-block[i]-friend[i]-1 for i in range(1, n+1)]

print(*answer())



Measured memory_bytes: 34832
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String s = scanner.next();

        int min=0;
        int current=0;
        //i=0
        for (char c: s.substring(1).toCharArray()){
            if (c=='E'){current++;}
            min = current;
        }
        //i>=1
        for (int i=1; i<n; i++){
            if (s.charAt(i-1)=='W'){current++;}
            if (s.charAt(i)=='E'){current--;}
            min = Math.min(min, current);
        }
        System.out.println(min);
    }
}

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

int main() {
  int N, k = 3;
  cin >> N;

  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    
    if (S == "Y") {
      k = 4;
      break;
    }
  }
  if (k == 4) {
    cout << "Four" << endl;
  }
  else {cout << "Three" << endl;}
}

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

int main(void){
	int m, d;
	cin >> m >> d;
	int ans = 0;
	for(int i = 1; i <= m; ++i){
		for(int j = 20; j <= d; ++j){
			int d1 = j % 10;
			int d2 = j / 10;
			if(d1 >= 2 && d2 >= 2 && d1*d2 == i){
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define f first
#define s second

using namespace std;
const int N = 1e5 + 5;
vector<int> gr[N];
int used[N];

void dfs(int v){
    used[v]++;
    for(auto& e : gr[v]){
        if(!used[e])
            dfs(e);
    }
}


void solve(){
    int n, m; cin >> n >> m;
    for(int i = 0; i < m; i++){
        int u, v; cin >> u >> v;
        gr[u].pb(v);
        gr[v].pb(u);
    }
    vector<int> s;
    for(int i = 1; i <= n; i++){
        if(!used[i]){
            s.pb(i);
            dfs(i);
        }
    }
    cout << (int)s.size() - 1 << endl;
}

int main()
{
    int t = 1;
    while(t--)
        solve();
    return 0;
}
/*
1
5
1 2
2 3
3 4
3 5
1
3
*/


Measured memory_bytes: 10084
n, m = map(int, input().split())

query = [tuple(map(int, input().split())) for _ in range(m)]

numbers = 0
if n == 1:
    numbers = range(10)
if n == 2:
    numbers = range(10, 100)
if n == 3:
    numbers = range(100, 1000)

def check(x, query):
    for s, c in query:
        if str(x)[s-1] != str(c):
            return -1
    return x

for x in numbers:
    ans = check(x, query)
    if ans != -1:
        print(ans)
        exit()
print(-1)

Measured memory_bytes: 3064
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007



int main(int argc, char const *argv[]) {
  int n,a,b,ans=0;;
  std::cin >> n >> a >> b;

  for(int i=1; i<=n; i++){
    int k=i, sum=0,j=100000;
    while(k>0){
      sum+=k/j;
      k%=j;
      j/=10;
    }

    if(sum>=a && sum <=b) ans+=i;
  }

  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  int a,b;
  cin>>a>>b;
  int m = (a+b)/2;
  if(abs(a-m) == abs(b-m)) cout<<m<<"\n";
  else cout<<"IMPOSSIBLE";
  return 0;
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
const double eps = 1e-8;
const int MOD = 1000000007;
//int main() {
//    cin.tie(0);
//    ios::sync_with_stdio(false);
//    cout << fixed << setprecision(10);
//
//}
template<typename T>
struct BIT {
    vector<T> bit;
    int sz;
    BIT(int n) : sz(n+1), bit(n+1) {}
    void add(int i, T x) {
        i += 1;
        while (i < sz) { bit[i] += x; i += i & -i; }
    }
    T sum(int i) {
        i += 1; T s = 0;
        while (i > 0) { s += bit[i]; i -= i & -i; }
        return s;
    }
};
template<typename T>
ll inversion(const vector<T>& a)
{
    map<T,int> mp;
    for (auto e : a) mp[e] = -1;
    int sz = 0;
    for (auto &q : mp) {
        q.second = sz++;
    }
    BIT<int> bit(sz+1);
    ll res = 0;
    for (int i = 0; i < a.size(); ++i) {
        res += i - bit.sum(mp[a[i]]);
        bit.add(mp[a[i]], 1);
    }
    return res;
}
int main()
{
    string s; cin >> s;
    vector<vector<int>> vs;
    vector<int> v;
    for (int i = 0; i <= s.size(); ++i) {
        if (i == s.size()) {
            if (v.size()) vs.push_back(v);
            v.clear();
        } else if (s[i] == 'A') {
            v.push_back(1);
        } else if (i+1 < s.size() && s[i] == 'B' && s[i+1] == 'C') {
            v.push_back(0);
            ++i;
        } else {
            if (v.size()) vs.push_back(v);
            v.clear();
        }
    }
    ll ans = 0;
    for (auto v : vs) {
        ans += inversion(v);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3128
while True:
    n=int(input())
    if n==0:
        break
    else:
        list=[0]*10
        for i in range(n):
            list[int(input())]+= 1
        for i in range(10):
            if list[i]==0:
                print('-')
            else:
                for j in range(list[i]):
                    print('*', end='')
                print()


Measured memory_bytes: 7580
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int x=c-a,y=d-b;
    for(int i=0;i<y;i++)cout<<'U';
    for(int i=0;i<x;i++)cout<<'R';
    for(int i=0;i<y;i++)cout<<'D';
    for(int i=0;i<x;i++)cout<<'L';
    cout<<'L';
    for(int i=0;i<y+1;i++)cout<<'U';
    for(int i=0;i<x+1;i++)cout<<'R';
    cout<<"DR";
    for(int i=0;i<y+1;i++)cout<<'D';
    for(int i=0;i<x+1;i++)cout<<'L';
    cout<<'U'<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int a, b, c; cin >> a >> b >> c;

    dunk(a*b/2);
}

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

int n,mod,ans;
inline int qpow(int d,int z,int t=0,int a=1){
	for(;z;z>>=1,d=1ll*d*d%(mod-t))
		if(z&1) a=1ll*a*d%(mod-t); return a;
}
int fac[3009],inv[3009];
inline int c(int n,int m){return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;}

int g[3009][3009];
inline int f(int i){
	int ret=0;
	for(int j=0;j<=i;++j)
		ret=(ret+1ll*g[i][j]*qpow(2,(n-i)*j)%mod*qpow(2,qpow(2,n-i,1)))%mod;
	return ret;
}
int main(){
	scanf("%d%d",&n,&mod);
	for(int i=fac[0]=1;i<=n;++i) fac[i]=1ll*fac[i-1]*i%mod;
	inv[n]=qpow(fac[n],mod-2);
	for(int i=n;i;--i) inv[i-1]=1ll*inv[i]*i%mod;
	g[0][0]=1;
	for(int i=1;i<=n;++i)
		for(int j=0;j<=i;++j)
			g[i][j]=(g[i-1][j-1]+g[i-1][j]*(j+1ll))%mod;
	for(int i=0;i<=n;++i) ans=(ans+(i&1?mod-1ll:1ll)*c(n,i)%mod*f(i))%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 31376
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

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

vector<long long> divisor(long long n)
{
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++)
  {
    if (n % i == 0)
    {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool isPrime(long long num)
{
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;

  double sqrtNum = sqrt(num);

  for (int i = 3; i <= (int)sqrtNum; i++)
  {
    if (num % i == 0)
      return false;
  }

  return true;
}

int main()
{
  long long A, B;
  cin >> A >> B;
  long long N = gcd(A, B);
  vector<long long> commonDivisor = divisor(N);
  int ans = 0;
  for (int i = 0; i < commonDivisor.size(); i++)
  {
    if (isPrime(commonDivisor[i]))
      ans++;
  }
  cout << ans + 1 << endl;
}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
typedef long double ld;

constexpr int INF = 1e9;
constexpr ll BIGINF = 1e18;
constexpr double EPS = 1e-16;
constexpr int MOD = 1e9 + 7;

void preambule() {
  cin.tie(0);
  cout.precision(16);
  cout << fixed;
}

int n;

vector<int> a;

void input() {
  cin >> n;

  a.resize(n);
  for (auto&& i : a) {
    cin >> i;
  }
}

void solve() {
  sort(a.rbegin(), a.rend());

  int sum = 0;
  for (int i = 1; i < n; ++i) {
    sum += a[i];
  }

  cout << a[0] / 2 + sum;
}

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  preambule();
  input();
  solve();
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
	char str1[101],str2[101],str3[202];
	scanf("%s",str1);
	strcpy(str3,str1);
	strcat(str3,str1);
	scanf(" %s",str2);
	if(strstr(str3,str2)==NULL) puts("No");
	else						puts("Yes");
	return 0;
}

Measured memory_bytes: 540
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

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

  int ans = k;
  rep(i, n - 1) ans *= k - 1;
  cout << ans << endl;




  
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
 
public class Main{
  public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s=br.readLine();
        String[] spl=s.split(" ");
        int a=Integer.parseInt(spl[0]);
        int b=Integer.parseInt(spl[1]);
        int c=Integer.parseInt(spl[2]);
 
 		Arrays.sort(spl);
 		System.out.println(spl[0]+" "+spl[1]+" "+spl[2]);
 
    }
}

Measured memory_bytes: 24368
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0 

using namespace std;
using ll = long long;
vi dp;

int solve(int x) {
	if (x == 0) return 1;
	if (x < 100) return 0;
	if (dp[x] != -1) return dp[x];
	bool res = false;
	rep (i, 100, 105)
		res = res || solve(x-i);
	return dp[x] = res;
}

void testcase() {
    int x;
    cin >> x;
    dp.resize(x+1, -1);
    if (x==0) cout << "0" << endl;
    else
    	cout << solve(x) << endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  long long M=1000000000000000000;
  vector<long long> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  long long sum=1;
  for(int i=0;i<N;i++){
    if(A.at(i)==0){
      cout << 0 << endl;
      return 0;
    }
    if(sum>M/A.at(i)){
      cout << -1 << endl;
      return 0;
    }
    sum*=A.at(i);
  }
  cout << sum << endl;
}
    

Measured memory_bytes: 4016
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
#include <bitset>
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

ll cal(ll times, ll from , ll to ){
    ll ans = 1;
    times -= (from-1);
    ans = from;

    ans += (ll)(times/2) * (to-from);
    times %= 2;
    if(times == 1) ans ++;
    return ans;
}

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

    // A bis = 1 en
    // 1 en = B bis;   A bis -> B bis (2 step)
    ll K, A, B;
    cin >> K >> A >> B;
    /*
    if(A == 0) {
        cout << 1 + B * K << endl;
        return 0;
    }
    */
    cout << max(cal(K, A , B), K + 1);



    //cout << fixed << setprecision(16) << ans << endl;
	return 0;
}

//314159265 35897932 384626433
// 48518828981938099


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  ll N,X;
  cin >> N >> X;
  ll ans=N;
  ll a=N-X;
  ll b=X;
  while(a%b){
    ans+=(a/b*2)*b;
    ll A=a,B=b;
    a=B;
    b=A%B;
  }
  ans+=(a/b*2)*b-b;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long 
const int maxn = 1e5+10;
const int INF = 1e9;
int a[maxn];
int n;
int dp[maxn][3];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	a[n+1]=-1;
	int cnt=0;
	for(int i=1;i<=n;i++)
	if(a[i]!=a[i+1]) a[++cnt]=a[i];
	n=cnt;
	dp[1][2]=1;
	dp[1][0]=dp[1][1]=INF;
	for(int i=2;i<=n;i++)
	{
		dp[i][0]=dp[i][1]=dp[i][2]=INF;
		if(a[i]>a[i-1]) dp[i][2]=min(min(dp[i-1][0],dp[i-1][1]),dp[i-1][2])+1,dp[i][0]=min(dp[i-1][0],dp[i-1][2]);
	    else if(a[i]<a[i-1])
	    dp[i][2]=min(min(dp[i-1][0],dp[i-1][1]),dp[i-1][2])+1,dp[i][1]=min(dp[i-1][1],dp[i-1][2]);
	}
	int ans=INF;
	for(int i=0;i<3;i++) ans=min(ans,dp[n][i]);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
  int n;
  cin >> n;
  int ans = 1110 - n;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2000000000
#define int long long int
#define MOD 1000000007
#define pb push_back
#define cin1(n) (cin >> n)
#define cin2(a,b) (cin >> a >> b)
#define cin3(a,b,c) (cin >> a >> b >> c)
#define cout(n) (cout << n << endl)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define fr first 
#define sc second 
#define EPS (1e-10)

using namespace std;

typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector<pair<int,int>> vpii;
typedef vector<string> vs;
typedef vector<vector<string>> vss;
typedef pair<int,int> pii;

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int n,m;
int a,b;
int p,q;


signed main() {
	int n,k; 
	cin >> n >> k;
	
	int ans = 0;
	rep(i,0,n-1) {
		ans += 1 + ans/(k-1);
	}
	cout(ans);
	return 0;	
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int main(void)
{
  for(;;){
    int n,m,l;
    cin >> n >> m >> l;
    if(!n) return 0;
    vector<vector<tuple<int,int,int> > > ed(n+1);
    REP(i,m){
      int a,b,d,e;
      cin >> a >> b >> d >> e;
      ed[a].push_back(make_tuple(b,d,e));
      ed[b].push_back(make_tuple(a,d,e));
    }
    vector<map<int,int> > cost(n+1);
    //cost[pos][left]=e;
    priority_queue<tuple<int,int,int> > dijk;
    //nege,pos,left
    dijk.push(make_tuple(0,1,l));
    while(!dijk.empty()){
      int nege,pos,left;
      tie(nege,pos,left)=dijk.top();
      dijk.pop();
      if(cost[pos].count(left)) continue;
      cost[pos][left]=-nege;
      REP(i,ed[pos].size()){
	int to,d,e;
	tie(to,d,e)=ed[pos][i];
	dijk.push(make_tuple(nege-e,to,left));
	if(left>=d) dijk.push(make_tuple(nege,to,left-d));
      }
    }
    int answer=33554432;
    REP(i,l+1) if(cost[n].count(i)) answer=min(answer,cost[n][i]);
    cout << answer << endl;
  }
}

Measured memory_bytes: 14644
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int s[20];
int a[60],b[60],c[60],d[60];
int n,m,q,maxn;
void dfs(int now,int val){
    //cout<<now<<" "<<val<<endl;
    s[now]=val;
    if(now==n){
        int ans=0;
        for(int i=0;i<q;i++)
            if(s[b[i]]-s[a[i]]==c[i])
                ans+=d[i];
        maxn=max(ans,maxn);
        return;
    }
    for(int i=val;i<=m;i++)
        dfs(now+1,i);
}
int main()
{
    cin>>n>>m>>q;
    for(int i=0;i<q;i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    }
    dfs(1,1);
    cout<<maxn;
    return 0;
}


Measured memory_bytes: 3612
#include<stdio.h>
int main(){
  int n,ans=20000;
  int w[100];
   int sum1=0,sum2=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&w[i]);
    sum2+=w[i];
  }
  
 
  for(int i=0;i<n;i++){
    sum1+=w[i];
    sum2-=w[i];
    if(abs(sum1-sum2)<ans){
      ans=abs(sum1-sum2);
    }
  }
  printf("%d",ans);
  return 0;
}

    


Measured memory_bytes: 128
n = int(input())
A = list(map(int,input().split()))
A.sort()
B = [0]*(A[-1]+1)
ans = 0
for i,a in enumerate(A):
    if B[a]:
        continue
    else:
        if i+1 == n or A[i+1] != a:
            ans += 1
        x = a
        while x <= A[-1]:
            B[x] = 1
            x += a
print(ans)


Measured memory_bytes: 106332
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2e5 + 10;
int P[maxn], V[maxn], tl[maxn], nxt[maxn];
int c0[maxn], c1[maxn];

struct node {
    int id;
    node(int id = -1) : id(id) {}
    friend bool operator<(node A, node B) {
        if ((LL) c0[A.id] * c1[B.id] != (LL) c0[B.id] * c1[A.id])
            return (LL) c0[A.id] * c1[B.id] > (LL) c0[B.id] * c1[A.id];
        return A.id < B.id;
    }
};
set<node> S;

int fa[maxn];
int Find(int x){
    return fa[x] == x ? x : fa[x] = Find(fa[x]);
}

int main() {
    int N;
    scanf("%d", &N);
    for (int i = 2; i <= N; ++i) scanf("%d", P + i);
    for (int i = 1; i <= N; ++i) {
        fa[i] = tl[i] = i;
        scanf("%d", V + i);
        if (V[i] == 0) c0[i] = 1;
        else c1[i] = 1;
        if(i != 1) S.insert(node(i));
    }
    for (int i = 1; i < N; ++i) {
        node now = *S.begin();
        S.erase(S.begin());
        int x = now.id, y = Find(P[x]);
        nxt[tl[y]] = x, tl[y] = tl[x], fa[x] = y;
        if(y != 1) S.erase(node(y));
        c1[y] += c1[x], c0[y] += c0[x];
        if(y != 1) S.insert(node(y));
    }
    LL ans = 0;
    int p = 1, num = V[1];
    for (int i = 1; i < N; ++i) {
        p = nxt[p];
        if (V[p] == 0) ans += num;
        else num++;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 15232