akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
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>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m;
	string s;cin>>s;
	n = s.length();
	char core = s[(n-1)/2];
	int l = 0;
	if(n %2==1){
		l = -1;
		for(int i = (n-1)/2;i>=0;i--){
			if(s[i]==core&&s[n-1-i]==core){
				l+=2;
			}else{
				break;
			}
		}
		cout << (n-l)/2+l << endl;
	}else{
		l = 0;
		for(int i = (n-1)/2;i>=0;i--){
			if(s[i]==core&&s[n-1-i]==core){
				l+=2;
			}else{
				break;
			}
		}
		cout << (n-l)/2 + l << endl;
	}
	return 0;
}


Measured memory_bytes: 512
# coding: utf-8
# Your code here!
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
sa=sorted(a)
ma=max(a)
ma_2=0
n_ma=0
for i in range(n):
    target = sa[n-1-i]
    if target==ma:
        n_ma+=1
    else:
        ma_2=target
        break
for i in a:
    if i==ma and n_ma>=2:
        print(ma)
    elif i==ma and n_ma==1:
        print(ma_2)
    else:
        print(ma)

Measured memory_bytes: 14112
let readInt _ = stdin.ReadLine() |> int

let rec solve num count add =
    match count with
    | 0 -> num
    | c -> if num < add then solve (num + num) (c - 1) add else solve (num + add) (c - 1) add

(readInt (), readInt ())
|> fun (count, add) -> solve 1 count add
|> printfn "%d"


Measured memory_bytes: 29876
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
map<string,int> times;
struct node
{
    string ss;
    int t;
    bool operator<(const node &b) const
    {
        if(t!=b.t) return t>b.t;
        return ss<b.ss;
    }
};
vector<node> all;
vector<string> ans;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        string ss;
        cin>>ss;
        if(!times.count(ss)) times[ss]=0;
        times[ss]++;
    }
    for(map<string,int>::iterator it=times.begin();it!=times.end();it++)
        all.push_back((node){
            it->first,it->second
        });
    sort(all.begin(),all.end());
    int maxx=all[0].t;
    for(int i=0;i<all.size();i++)
    {
        if(all[i].t==maxx) ans.push_back(all[i].ss);
        else break;
    }
    for(int i=0;i<ans.size();i++)
        cout<<ans[i]<<endl;
    return 0;
}


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

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

    for (int i = 0; i < M; i++) {
        N -= A.at(i);
    }

    if (N < 0) {
        cout << -1 << endl;
    }
    else {
        cout << N << endl;
    }

    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    ll N;
    cin >> N;
    vector<ll> F(N+1);
    for(int i=1;i<=N;i++){
        for(int j=i;j<=N;j+=i){
            F[j]++;
        }
    }
    ll ans = 0;
    rep(i,N+1){
        ans+=i*F[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 81396
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    def digsum(n):
        res = 0
        while n:
            res += n%10
            n //= 10
        return res
    res = 1000000
    for i in range(1, n):
        a = i
        b = n-i
        res = min(res, digsum(a)+digsum(b))
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
void dice1();
void dice2();
void dice3();
class DICE{
	int face[6],a;
public:
	bool operator==(const DICE&di)const{
		int cont=0;
		for(int i=0;i<6;++i){
			if(face[i]==di.face[i]){
				cont++;
			}
		}
		if(cont==6){
			return true;
		}
		else{
			return false;
		}
	}
	bool operator!=(const DICE&di)const{
		return !(*this==di);
	}
	void set(int&f,int&f1,int&f2,int&f3,int&f4,int&f5){
		face[0]=f;face[1]=f1;face[2]=f2;face[3]=f3;face[4]=f4;face[5]=f5;
	}
	void N(){
		a=face[0];
		face[0]=face[1];
		face[1]=face[5];
		face[5]=face[4];
		face[4]=a;
	}
	void E(){
		a=face[0];
		face[0]=face[3];
		face[3]=face[5];
		face[5]=face[2];
		face[2]=a;
	}
	void S(){
		a=face[0];
		face[0]=face[4];
		face[4]=face[5];
		face[5]=face[1];
		face[1]=a;
	}
	void W(){
		a=face[0];
		face[0]=face[2];
		face[2]=face[5];
		face[5]=face[3];
		face[3]=a;
	}
	void output(){
		cout<<face[0]<<endl;
	}
	int up(){
		return face[0];
	}
	void turn(){
		a=face[1];
		face[1]=face[3];
		face[3]=face[4];
		face[4]=face[2];
		face[2]=a;
	}
	int front(){
		return face[1];
	}
	int right(){
		return face[2];
	}
	void allout(){
		for(int i=0;i<6;++i){
			cout<<face[i]<<" ";
		}
		cout<<endl;
	}
	void toupper(int n){
		if(n<=3){
			a=face[0];
		face[0]=face[1];
		face[1]=face[5];
		face[5]=face[4];
		face[4]=a;
		}
		else if(n==4){
			a=face[0];
		face[0]=face[3];
		face[3]=face[5];
		face[5]=face[2];
		face[2]=a;
		}
		else if(n==5){
			a=face[0];
		face[0]=face[3];
		face[3]=face[5];
		face[5]=face[2];
		face[2]=a;
		a=face[0];
		face[0]=face[3];
		face[3]=face[5];
		face[5]=face[2];
		face[2]=a;
		}

	}
};
bool judge(DICE,DICE);
int main(){
	DICE a;
	dice3();
	return 0;
}
void dice1(){
	DICE a;
	int d[6];string str;
	for(int i=0;i<6;++i){
		cin>>d[i];
	}
	a.set(d[0],d[1],d[2],d[3],d[4],d[5]);
	getline(cin,str);
	getline(cin,str);
	for(int i=0;i<str.size();++i){
		if(str[i]=='E'){
			a.E();
		}
		else if(str[i]=='S'){
			a.S();
		}
		else if(str[i]=='W'){
			a.W();
		}
		else if(str[i]=='N'){
			a.N();
		}
	}
	a.output();
	return;
}
void dice2(){
	DICE a;
	int d[6],p,u;
	for(int i=0;i<6;++i){
		cin>>d[i];
	}a.set(d[0],d[1],d[2],d[3],d[4],d[5]);
	int n;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>p>>u;
		int k=0;
		while(1){
			k++;
			if(k<=5){
				a.E();
			}
			else{
				a.N();
			}
			if(p==a.up()){
				break;
			}
		}
		k=0;
		while(1){
			k++;
			a.turn();
			if(u==a.front()){
				break;
			}
		}
		cout<<a.right()<<endl;
	}
	return;
}
void dice3(){
	DICE a,b;
	int d[6][2];
	for(int i=0;i<2;++i){
		for(int j=0;j<6;++j){
			cin>>d[j][i];
		}
	}
	a.set(d[0][0],d[1][0],d[2][0],d[3][0],d[4][0],d[5][0]);
	b.set(d[0][1],d[1][1],d[2][1],d[3][1],d[4][1],d[5][1]);
	if(judge(a,b)){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}
bool judge(DICE a,DICE b){
	bool bo1=false,bo2=false;
	for(int i=0;i<6;++i){
		b.toupper(i);
		for(int j=0;j<4;++j){
			if(a==b){
				return true;
			}
			b.turn();
		}

	}
	return false;
}

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

int main() {
    int S, h, x, m, s;

    cin >> S;

    h = S / 3600;
    x = S % 3600;
    m = x / 60;
    s = x % 60;

    cout << h << ":" << m << ":" << s << endl;

    return 0;
}


Measured memory_bytes: 3108
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        char a = s.next().charAt(0);
        char b =s.next().charAt(0);
        int x = a-'0',y=b-'0';
        String res1="",res2="";
        while(x--!=0){
            res1+=b;
        }
        while(y--!=0){
            res2+=a;
        }

        if(res1.compareTo(res2)<=0) System.out.println(res1);
        else System.out.println(res2);
    }
}



class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25164
#include <bits/stdc++.h>
#define re return
#define ll long long
#define oo 1e9
#define mm(o,k) memset(o,k,sizeof o)
using namespace std;
ll m,n,k,a[500000],ans,x,z,o,zz,y   ;
string s;
int main()
{
     cin>>n;
    for (int i=0;i<n;++i){
        cin>>x>>y;
        ans+=((y-x)+1);
    }
    cout<<ans;
    return 0;
}


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

int main(void)
{
  char step[150];
  gets(step);

  int i,j,count=0;
  i=strlen(step);

  for(j=1;j<=i;j++){
    if(j%2==1){
      if(step[j-1]=='L'){
        count=1;
        break;
      }
    }else
    {
      if(step[j-1]=='R'){
        count=1;
        break;
      }
    }
  }

  if(count==1)
    printf("No\n");
  else
    printf("Yes\n");

  return 0;
}


Measured memory_bytes: 128
p1 = "#."
p2 = ".#"
while True:
    
    H,W = map(int,input().split())

    if H == 0 and W == 0:
        break
            
    if  W == 1:
        for i in range(H):
            if i&1 == 0:
                print("#")
            else:
                print(".")
            
    elif W&1 == 0:
        for i in range(H):
            if i&1 == 0:
                print(p1*(W//2))
            else:
                print(p2*(W//2))
        
    elif W&1 == 1:
        for i in range(H):
            if i&1 == 0:
                print(p1*(W//2)+"#")
            else:
                print(p2*(W//2)+".")
                
    print()


Measured memory_bytes: 5608
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	int a;
	int b;
	cin >> a >> b;
	vector<int>c;
	c.resize(a);
	int d = 0;
	for (int i = 0;i < a;i++) {
		cin >> c[i];
	}
	sort(c.begin(), c.end());
	int x = a - b-1;
	long long int y = 0;
	if (x < 0) {
		cout << 0;
	}
	else {
		while (x >= 0) {
			y += c[x];
			x--;
	}
		cout << y;
	}
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  string S;
  cin>>A>>B>>S;
  bool flag=true;
  if(S.at(A)!='-'){
    flag=false;
  }
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='-'&&i!=A){
      flag=false;
    }
  }
  if(flag){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    
  int i,j,flag,A[100],x,y,N,cnt=0;
    
  scanf("%d",&N);
  for(i = 0;i < N;i++) scanf("%d",&A[i]);
  
    flag = 1; // 逆の隣接要素が存在する
    while (flag){
      flag = 0;
      for(j = N-1;j >= 1;j--){
        if(A[j] < A[j-1]){
	  x = A[j];
	  y = A[j-1];
	  A[j] = y;
	  A[j-1] = x;
	  cnt++;
	  flag = 1;
	}
      }
    }
    for(i = 0;i < N;i++){
      printf("%d",A[i]);
      if(i < N-1) printf(" ");
      else printf("\n");
    }
    printf("%d\n",cnt);

    return 0;
}



Measured memory_bytes: 2104
#include<iostream>

using namespace std;

int main()
{
	long a,b,c,x,y,z;
	
	cin>>a>>b>>c;
	
	if((a*b*c)%2==0){
		cout<<"0\n";
	}else{
		x=a*b;
		y=b*c;
		z=c*a;
		if(x<=y){
			if(x<=z){
				cout<<x<<"\n";
			}else{
				cout<<z<<"\n";
			}
		}else{
			if(y<=z){
				cout<<y<<"\n";
			}else{
				cout<<z<<"\n";
			}
		}
	}
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
#define N (1000000000+7)
int num[101] = { 0 };
int main(void) {
	int n, k, ans = 1;
	cin >> n >> k;
	ans = k;
	for (int i = 0;i < n - 1;i++)ans *= (k - 1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

string s;
ll k;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> s >> k;
  ll d = 0;
  while (d < s.size() && s[d] == '1') d++;
  if (d == s.size()) {
    cout << 1 << endl;
    return 0;
  }
  int last = s[d] - '0';
  if (k <= d) {
    cout << 1 << endl;
    return 0;
  }
  cout << last << endl;

  return 0;
}

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

using namespace std;

int main () {
	int N, idx, cnt;
	cin >> N;
	bool flag = false;

	idx = 1;
	cnt = 0;
	for (int i=0; i<N; i++) {
		int tmp;
		cin >> tmp;
		if (tmp==idx) {
			flag = true;
			idx ++;
		} else {
			cnt ++;
		}
	}
	
	if (flag)
		cout << cnt << endl;
	else
		cout << -1 << endl;

	return 0;
}

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

#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
#define popcount(x) __builtin_popcountll(x)
#define pll pair<ll,ll> 
#define ld long double

const int M=1000000007;
const int MM=998244353;
const long double PI = acos(-1);

ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p)
{ 
    return os<<'('<<p.F<< ","<<p.S<<')'; 
}

int _runtimeTerror_()
{
    ll n;
    cin>>n;
    cout<<(n%1000?1000-n%1000:0);
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef runSieve
        sieve();
    #endif
    #ifdef NCR
        initialize();
    #endif
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--)
        _runtimeTerror_();
    return 0;
}

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


int mp[5005][5005],n,m;

int t[5005][5005];

vector<int> x,y;

vector<int> compress(vector<int> v){
  vector<int> copy=v;
  sort(v.begin(), v.end());
  v.erase( unique( v.begin(), v.end()) , v.end() );
  vector<int> res;
  for(int i=0;i<(int)copy.size();i++){
    int num=lower_bound( v.begin(),v.end(), copy[i] ) - v.begin();
    res.push_back( num );
  }
  return res;
}

int sum(int sx,int sy,int gx,int gy){
  return t[gx][gy]-t[sx][gy]-t[gx][sy]+t[sx][sy];
}

int main(){
  cin>>n>>m;
  x.resize(n),y.resize(n);
  for(int i=0;i<n;i++)cin>>x[i]>>y[i];
  vector<int> X,Y;
  X=compress(x),Y=compress(y);
  for(int i=0;i<n;i++)mp[X[i]][Y[i]]++;

  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      t[i+1][j+1]=mp[i][j] + t[i+1][j] + t[i][j+1] - t[i][j];
  
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  x.erase( unique( x.begin(), x.end()) , x.end() );
  y.erase( unique( y.begin(), y.end()) , y.end() );
  while(m--){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int sx=lower_bound(x.begin(),x.end(),a)-x.begin();
    int sy=lower_bound(y.begin(),y.end(),b)-y.begin();
    int gx=upper_bound(x.begin(),x.end(),c)-x.begin();
    int gy=upper_bound(y.begin(),y.end(),d)-y.begin();
    cout<<sum(sx,sy,gx,gy)<<endl;
  }
  return 0;
}

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

/*
ll modpow(ll a, ll n){
  ll res = 1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll inverse(ll a, ll b){
    ll t = 1;
    while(b) {
        if(b & 1) t = (t * a) % mod;
        a *= a;
        a %= mod;
        b >>= 1;
    }
    return t % mod;
}*/

ll f[1000000];
//---------------------------------------------------------------------------------------------------
ll inv(ll x) {
    ll res = 1;
    ll k = mod - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % mod;
        y = (y * y) % mod;
        k /= 2;
    }
    return res;
}
//---------------------------------------------------------------------------------------------------
ll C(int n, int k) {
    ll a = f[n]; // = n!
    ll b = f[n-k]; // = (n-k)!
    ll c = f[k]; // = k!

    ll bc = (b * c) % mod;

    return (a * inv(bc)) % mod;
}


ll H(int n, int k) {
    return C(n + k - 1, k);
}

int main(){
  f[0] = 1;
  rep(i,1000000) f[i+1] = (f[i] * (i+1)) % mod;
  ll X, Y;
  cin >> X >> Y;
  if((X+Y)%3!=0 || max(X,Y)-min(X,Y)>min(X,Y)){
    cout << 0 << endl;
    return 0;
  }
  ll ans = 0;
  if(X>Y){
    ll tmp = X;
    X = Y;
    Y = tmp;
  }
  int turn = (X+Y)/3;
  int a=turn;
  int b=0;
  while((a+2*b) != X || (a*2+b) != Y){
    a--;
    b++;
  }

  // cout << a << " " << b << endl;
  ll si=1,bo=1;

  rep(i,a+b){
    si *= (i+1);
    si %= mod;
  }
  rep(i,a){
    bo *= (i+1);
    bo %= mod;
  }
  rep(i,b){
    bo *= (i+1);
    bo %= mod;
  }
  ans = si*inv(bo);

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


Measured memory_bytes: 8064
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    string s;
    cin >> s;
    int n = s.size();
    int K;
    cin >> K;
    int dp[105][2][105];
    // i桁目に0でない数字がj個ある数字の数。
    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    for (int i = 0; i < n; i++) {
        int ni = s[i] - '0';
        for (int j = 0; j < 105; j++) {
            dp[i + 1][1][j + 1] += dp[i][1][j] * 9;
            dp[i + 1][1][j] += dp[i][1][j];
            if (ni == 0) {
                dp[i + 1][0][j] += dp[i][0][j];
            } else if (ni != 0) {
                dp[i + 1][1][j + 1] += dp[i][0][j] * (ni - 1);
                dp[i + 1][1][j] +=
                    dp[i][0]
                      [j]; // i桁目が0でないのでi桁目が0の時必ず小さくなる。
                dp[i + 1][0][j + 1] += dp[i][0][j];
            }
        }
    }

    ll ans = dp[n][1][K] + dp[n][0][K];
    cout << ans << endl;
}

Measured memory_bytes: 3744
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



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

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; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b;cin>>a>>b;
  cout<<max({a+b,a-b,a*b})<<endl;
  return 0;

}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9

using namespace std;
typedef long long int lli;
typedef long long ll;

int main() {
    string s;
    cin >> s;
    sort(all(s));

    cout << (s == "abc"?"Yes":"No") << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
div = []
for i in range(1, M + 1):
    if i * i > M:
        break
    if M % i == 0:
        div.append(i)
    if M % i == 0 and i != M // i:
        div.append(M // i)
div.sort()
div.reverse()
for i in div:
    if M // i >= N:
        print(i)
        break


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

int main(){
	int a,b,c,d,e,k;
	cin>>a>>b>>c>>d>>e>>k;
	int buf[5];
	buf[0]=a;
	buf[1]=b;
	buf[2]=c;
	buf[3]=d;
	buf[4]=e;
	bool flag=false;
	for(int i=0;i<5;i++){
		for(int j=0;j<5;j++){
			if(abs(buf[i]-buf[j])>k){
				flag=true;
			}
		}
	}
	if(flag){
		cout<<":("<<endl;
	}else{
		cout<<"Yay!"<<endl;
	}
}


Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)

if n >= m
  puts(0)
else
  xs = gets.split.map(&:to_i)

  xs.sort!

  if n == 1
    puts(xs[-1] - xs[0])
  else
    gap = (xs.size - 1).times.map { |i| xs[i + 1] - xs[i] }
    skip = gap.sort[(-(n - 1))..-1].reduce { |m, i| m + i }

    puts(xs[-1] - xs[0] - skip)
  end
end

Measured memory_bytes: 10488
#include <iostream>
#include <string>
using namespace std;
int main(){
 string s;
  cin>>s;
  int len=s.length();
  int identifier=1;
  int i;
 for(i=0;i<(len+1)/2;i++){
    if (s[i]!=s[len-i-1]){
      identifier=0;break;}}
  for(i=0;i<(len+1)/4;i++){
    if (s[i]!=s[(len-1)/2-i-1]){
      identifier=0;break;}}
  for (i=(len+3)/2-1;i<len;i++){
    if (s[i]!=s[len-i-1]){
      identifier=0;break;}}
  if (identifier==0) cout<<"No";
  if (identifier==1) cout<<"Yes";}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
int pow(int v,int k){int r(1),t(v);while(k){if(k&1)r*=t;t*=t;k>>=1;} return r;}

const int MOD = 1e9+7;

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

	int n;
	std::cin >> n;
	std::string s;
	std::cin >> s;

	if(s[0]=='W') {
		print(0);
		return 0;
	}

	// 0=L, 1=R
	std::vector<int> side(2*n);
	side[0]=0;
	rep(i,2*n-1) {
		if(s[i]==s[i+1]) side[i+1]=(side[i]+1)%2;
		else side[i+1]=side[i];
	}


	int count = 1;
	int Lcount = 0;
	int Rcount = 0;
	for(auto i:side) {
		if(i==1) count=count*(Lcount-Rcount)%MOD;
		if(i==0) Lcount++;
		else Rcount++;
	}

	if(Lcount!=Rcount) {
		print(0);
		return 0;
	}

	for(int i=1;i<=n;i++) count=count*i%MOD;

	print(count);

	return 0;
}


Measured memory_bytes: 2196
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
int n,k;
int main()
{
    scanf("%d%d",&n,&k);
    printf("%d\n",n%k==0?0:1);
    return 0;
}


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

int N,A,B,C,m=100000000;
int S[3],cnt[3];
int L[8];

void dfs(int i){
    if(i==N){
        if(cnt[0]>0 && cnt[1]>0 && cnt[2]>0){
            m = min(m,10*(cnt[0]+cnt[1]+cnt[2]-3)+abs(A-S[0])+abs(B-S[1])+abs(C-S[2]));
        }
        return;
    }
    rep(j,3){
        S[j] +=L[i];cnt[j]++;
        dfs(i+1);
        S[j] -=L[i];cnt[j]--;
    }
    dfs(i+1);
    return;
}



int main(void){
    cin >> N >> A >> B >>C;
    rep(i,N)cin >> L[i];
    dfs(0);
    cout << m << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(hoge) hoge.begin(),hoge.end()
const long long INF = 1LL << 60;


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;
}

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size() - 1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min + (max - min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

//約数求める //約数
void divisor(ll n, vector<ll> &ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());

}
//階乗
long long factorial(long long n, long long mod) {
	long long ret = 1;
	for (long long i = 1; i <= n; i++) {
		ret = (ret * i) % mod;
	}
	return ret;
}
//モジュラ逆数
long long inv_mod(long long n, long long mod) {
	long long a = n % mod, b = mod - 2, ret = 1;
	while (b > 0) {
		if (b & 1) ret = (ret * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ret;
}

long long nPr(long long n, long long r, long long mod) {
	long long ret = 1;
	for (long long i = n; i >= n - r + 1; i--) {
		ret = ret * (i % mod) % mod;
	}
	return ret;
}

long long nCr(long long n, long long r, long long mod) {
	return nPr(n, r, mod) * inv_mod(factorial(r, mod), mod) % mod;
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {//降順second
	if (a.second != b.second) {
		return a.second > b.second;
	}
	else {
		return a.first > b.first;
	}
}

bool compare_by_a(pair<ll, ll> a, pair<ll, ll> b) {//降順first
	if (a.first != b.first) {
		return a.first > b.first;
	}
	else {
		return a.second > b.second;
	}
}

ll gcd(ll m, ll n) {
	if (n == 0)return m;
	return gcd(n, m%n);
}//gcd


int main() {
	string s;
	cin >> s;
	map<char, ll> ma;
	ll ans = (s.size() - 1)*s.size() / 2;
	rep(i, s.size()) {
		ans -= ma[s[i]];
		ma[s[i]]++;
	}
	cout << ans + 1;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;

const int mod=1e9+7;
const int MA=201010;

ll fact[MA], rfact[MA];

ll mod_pow(ll x, ll n, ll mod) {
    ll a = 1LL;
    while (n) {
        if (n%2) a = ((a%mod)*(x%mod))%mod;
        x = ((x%mod)*(x%mod))%mod;
        n /= 2LL;
    }
    return a;
}

ll mod_inverse(ll a, ll m) {
    return mod_pow(a, m-2, m);
}


ll ncr(int n, int r) {
    if (n < r) return 0;
    return fact[n] * (rfact[r] * rfact[n-r] % mod) % mod;
}

int main() {

    fact[0] = rfact[0] = 1;
    for (int i=1; i<MA; ++i) {
        fact[i] = (fact[i-1] * i) % mod;
        rfact[i] = mod_inverse(fact[i], mod);
    }

    int n;
    cin >> n;
    vector<int> d(n);

    int l, r;
    int p[MA];
    fill(p, p+MA, -1);
    rep(i, n+1) {
        cin >> d[i];
        if (p[d[i]] == -1) p[d[i]] = i+1;
        else {
            l = p[d[i]];
            r = i+1;
        }
    }

    int pos = r - l + 1;
    for (int k=1; k<=n+1; ++k) {
        ll t = ncr(n+1, k) - ncr(n+1-pos, k-1);
        if (t < 0) t += mod;
        cout << t << endl;
    }
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int n, m, l;
	cin >> n >> m >> l;
	vector<vector<ll>> dist1(n, vector<ll>(n, LINF));
	rep(i,n) dist1[i][i] = 0;
	rep(i,m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		dist1[a][b] = c;
		dist1[b][a] = c;
	}
	int q;
	cin >> q;
	vector<pii> v(q);
	rep(i,q) {
		cin >> v[i].first >> v[i].second;
		v[i].first--, v[i].second--;
	}
	
	rep(k,n) {
		rep(i,n) {
			rep(j,n) {
				dist1[i][j] = min(dist1[i][j], dist1[i][k] + dist1[k][j]);
			}
		}
	}

	vector<vector<ll>> dist2(n, vector<ll>(n, LINF));
	rep(i,n) {
		rep(j,n) {
			dist2[i][j] = (dist1[i][j] <= l ? 1: LINF);
		}
	}
	rep(k,n) {
		rep(i,n) {
			rep(j,n) {
				dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]);
			}
		}
	}
	rep(i,q) {
		if (dist2[v[i].first][v[i].second] == LINF) cout << -1 << endl;
		else cout << dist2[v[i].first][v[i].second] - 1 << endl;
	}
}

Measured memory_bytes: 5208
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int r,D,x,i;
	cin>>r;
	cin>>D;
	cin>>x;
	for(i=0;i<10;i++)
	{
		x=r*x-D;
		cout<<x<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#from numpy import* #import numpy as np
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) #dijkstra #floyd_warshall
#from scipy.sparse import csr_matrix

from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！

class UNION_FIND(object):
    def __init__(self,n):
        self.parent=[-1 for i in range(n)]
        
    def root(self,x):
        if self.parent[x]<0:
            return x
        else:
            self.parent[x]=self.root(self.parent[x])
            return self.parent[x]
 
    def size(self,x):
        return -self.parent[self.root(x)]
    def union(self,x,y):
        x=self.root(x)
        y=self.root(y)
        if x==y:
            return False
        if self.size(x)<self.size(y):
            x,y=y,x
        self.parent[x]+=self.parent[y]
        self.parent[y]=x
        return True

def KRUSKAL(n, edges, TF_of_maximize):
    edges.sort(key=lambda x: x[2],reverse=TF_of_maximize)
    uf = UNION_FIND(n)
    cost = []
    for (a,b,c) in edges:
        if uf.root(a)!= uf.root(b):
            uf.union(a,b)
            cost.append(c)
    return cost


def main():
    n=int(input())
    inp=[[i]+list(map(int,input().split()))for i in range(n)]
    inpX=sorted(inp,key=lambda x:x[1])
    inpY=sorted(inp,key=lambda x:x[2])
    edges=[]
    for i in range(1,n):
        a,b,c=inpX[i]
        d,e,f=inpX[i-1]
        edges.append((a,d,min(abs(b-e),abs(c-f))))
        a,b,c=inpY[i]
        d,e,f=inpY[i-1]
        edges.append((a,d,min(abs(b-e),abs(c-f))))
    
    print(sum(KRUSKAL(n, edges, 0))) #頂点数 辺(コスト) #最大化するか否か 
    

if __name__ == '__main__':
    main()

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

int main() {
	int n;
	cin>>n;
	int a[n],o[n];
	for (int i=0; i<n; i++) {
		cin>>a[i];
	}
	int s;
	for (int i=0; i<n; i++) {
		o[a[i]-1]=i+1;
	}
	for (int i=0; i<n; i++) {
		if (i==0) {
			cout<<o[i];
		} else {
			cout<<" "<<o[i];
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 4364
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
const char newl = '\n';
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL<<60;
int main(){
    int X,Y;cin >> X >> Y;
    int x = (4*X-Y)/2;
    
    int y = X-x;
    if(y>=0&&x>=0&&2*x+4*y==Y) cout << "Yes" << endl;
    else cout << "No" << endl;
    /*debug(x);
    debug(y);*/
}

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

int main() {
  int n;
  long long cnt = 0;
  cin >> n;
  map<string,int>mp;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    mp[s]++;
  }
  for (auto& p : mp) {
    int s = p.second;
    cnt += (long long)s * (s-1) / 2;
  }  
  cout << cnt;
}

Measured memory_bytes: 11136
#include<string>
#include<iostream>
using namespace std;
int main(){
	int a,b,p,m,k,w;
	char op;
	while(1){
	cin>>a>>op>>b;
	if(op == '?')break;
	else if(op == '+'){
		p=a+b;
		cout<<p<<endl;
	}
	else if(op == '-'){
		m=a-b;
		cout<<m<<endl;
	}
	else if(op == '*'){
		k=a*b;
		cout<<k<<endl;
	}
	else if(op == '/'){
		w=a/b;
		cout<<w<<endl;
	}}

return 0;
}


Measured memory_bytes: 3120
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}
ll gcd(ll a, ll b)
{
	if (a % b == 0)
		return b;
	else
	{
		return gcd(b, a % b);
	}
}
ll a[100001];
vector<pair<ll, ll>>v;
void solve()
{
	ll sol = 0;
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a, a + n);
	for (int i = 0; i < m; i++)
	{
		ll b,c;
		cin >> b>> c;
		v.pb(MP(c, b));
	}
	sort(v.begin(), v.end());
	int i = 0, j = m - 1;;
	while (1)
	{
		ll co = v[j].second;
		while (co > 0&&j>=0)
		{
			ll val = v[j].first;
			if (a[i] < val)
			{
				a[i] = val;
				co--;
				i++;
				if (i >= n)
				{
					for (int i = 0; i < n; i++)
					{
						sol = sol + a[i];
					}
					cout << sol;
					return;
				}
			
			}
			else
			{
				for (int i = 0; i < n; i++)
				{
					sol = sol + a[i];
				}
				cout << sol;
				return;
			}
		}
		j--;
		if (j < 0)
		{
			for (int i = 0; i < n; i++)
			{
				sol = sol + a[i];
			}
			cout << sol;
			return;
		}
	}
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
	return(0);
}

Measured memory_bytes: 3188
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>

long long evalmod(long long a, long long b){
  long long maxval = std::max(a, b);
  long long minval = std::min(a, b);
  if (minval==0){
    return maxval;
  } else {
    return evalmod(minval, maxval%minval);
  }
}

int main(){
  int N;
  long long X;
  scanf("%d", &N);
  scanf("%lld", &X);
  std::vector<long long > x(N);
  for (int i=0; i<N; i++){
    scanf("%lld", &x[i]);
  }
  long long ans = abs(X-x[0]);
  for (int i=1; i<N; i++){
    ans = evalmod(ans, abs(X-x[i]));
  }
  printf("%lld\n", ans);
  return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int a[N];
int n, m, ans, mx;

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        m = max(m, a[i]);
    }
    for (int i = 0; i < n; ++i) {
        int k = min(a[i], m - a[i]);
        if (k > mx) {
            mx = k;
            ans = a[i];
        }
    }
    cout << m << ' ' << ans << endl;
    return 0;
}


Measured memory_bytes: 3960
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,l,i;
    string s;
    cin>>k>>s;
    l=s.length();
    if(l<=k)
        cout<<s;
    else
    {
        for(i=0;i<k;i++)
        cout<<s[i];
            cout<<"...";
    }

return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define endl "\n"
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define S second
typedef long long int ll;
const int INF = 1e9;

using namespace std;

void solve()
{
    ll i, n;
    cin>>n;
    ll product = 1;
    ll temp;
    ll limit = 1e18;
    bool compute = true;
    for(i=0; i<n; ++i)
    {
        cin>>temp;
        if(temp==0)
        {
            cout<<0<<endl;
            return;
        }
        if(compute)
        {
            if(temp > 1e18/product)
            {
                compute = false;
                continue;
            }
            product*=temp;
            if(product > limit) compute = false;
        }
    }
    if(compute) cout<<product<<endl;
    else cout<<-1<<endl;
    
}
 
int main()
{
    FASTIO
    solve();
    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

set<int> ans;
string line; 
int len;

int apply(char opr, int a, int b) {
    if (opr == '+') return a + b;
    if (opr == '-') return a - b;
    if (opr == '*') return a * b;
    if (opr == '/') return a / b;
}

int reduce(stack<int>& N, stack<char>& O) {
    char opr = O.top(); O.pop();
    int v = N.top(); N.pop();
    int w = N.top(); N.pop();
    if (opr == '/' && !v) return 0;
    N.push(apply(opr, w, v));
    return 1;
}

void read(int i, stack<int> N, stack<char> O) {
    if (i == len) {
        while (O.size()) if (!reduce(N, O)) return;
        ans.insert(N.top());
        return;
    }
    if (line[i] >= '0') {
        int v = 0;
        while (i < len && line[i] >= '0') v *= 10, v += line[i++] - '0';

        N.push(v);
        read(i, N, O);
        while (!O.empty() && O.top() != '(' && reduce(N, O)) read(i, N, O);
        return;
    }
    if (line[i] == ')') {
        while (O.top() != '(') if (!reduce(N, O)) return;
        O.pop();
        read(i+1, N, O);
        while (!O.empty() && O.top() != '(' && reduce(N, O)) read(i+1, N, O);
        return;
    }
    O.push(line[i]);
    read(i+1, N, O);
    return;
}

int main()
{
    while (1) {
        ans.clear();
        cin >> line;
        len = line.length();
        if (line == "#") break;
        read(0, stack<int>(), stack<char>());
        cout << ans.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 3212
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static class Task {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();

            int ans = k;
            for (int i = 1; i < n; i++) {
                ans *= (k - 1);
            }

            out.println(ans);
        }
    }

    private static void sort(double[] arr) {
        Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(int[] arr) {
        Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(long[] arr) {
        Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        task.solve(1, in, out);
        out.close();
    }

    public static void main(String[] args) {
        new Thread(null, () -> solve(), "1", 1 << 26).start();
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

    }

}

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a, b; cin >> a >> b;
  if(max(a, b) >= 10) {
    cout << -1 << '\n';
  } else {
    cout << a * b << '\n';
  }
  return 0;
}


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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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; }

void Main(){
    int N; cin >> N;
    VL x(N), y(N); REP(i,N) cin >> x[i] >> y[i];
    VI p(N); REP(i,N) p[i] = i;

    auto c1 = [&](int i, int j){
        if(y[i] == y[j]) return x[i]<x[j];
        else return y[i]<y[j];
    };
    auto c2 = [&](int i, int j){
        if(y[i] == y[j]) return x[i]>x[j];
        else return y[i]<y[j];
    };

    ll ans = 0, mn = LINF;

    sort(ALL(p), c1);
    for(int i : p){
        chmax(ans, x[i]+y[i] - mn);
        chmin(mn, x[i]+y[i]);
    }

    mn = LINF;
    sort(ALL(p), c2);
    for(int i : p){
        chmax(ans, y[i]-x[i] - mn);
        chmin(mn, y[i]-x[i]);
    }

    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

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

int main() {
    int N, M, count = 0;
    long long tmp1, tmp2, sum = 0;
    vector<pair<long long, long long> > v;
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> tmp1 >> tmp2;
        v.push_back(make_pair(tmp1, tmp2));
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); i++) {
        if (v[i].second > M - count) {
            sum += v[i].first * (M - count);
            break;
        }
        else {
            sum += v[i].first * v[i].second;
            count += v[i].second;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 2420
/**
 * @author: pr4shan7 (प्रशांत)
 */
// #define _DEBUG

#ifndef _DEBUG
#define NDEBUG
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

// #define int long long
// #define double long double

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_set;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define ln '\n'
#define x first
#define y second
#define cai static_cast<int>
#define cal static_cast<long long>
#define cad static_cast<long double>
#define deb(z) cout << "// " << #z << " = " << z << '\n';
const int N = 1e5 + 5;
const int INF = 1e9;
const int MV = 1e9 + 7;

struct move2 {
	int d, c;
};

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

#ifdef _DEBUG
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif

	int h, n; cin >> h >> n;
	move2 ar[n];
	for (int i = 0; i < n; ++i) {
		cin >> ar[i].d >> ar[i].c;
	}
	sort(ar, ar + n, [](const move2& a, const move2& b) { return a.d < b.d; });
	int lim = h + ar[n - 1].d + 1;
	int dp[lim];
	dp[0] = 0;
	int ans = INF;
	for (int i = 1; i < lim; ++i) {
		dp[i] = INF;
		for (int j = 0; j < n; ++j) {
			if(ar[j].d > i) break;

			dp[i] = min(dp[i], dp[i - ar[j].d] + ar[j].c);
		}
		if(i >= h) ans = min(ans, dp[i]);
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 384