akhauriyash/Code-Regression huggingface dataset:
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e18
#define N 100100
typedef pair<ll,ll> pll;
ll power(ll a,ll b)
{
    if(b==1)return a;
    if(b==0)return 1;
    ll temp=power(a,b/2);
    ll ans=temp*temp;
    if(b&1)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%p;
    if(b&1)
        ans=(a*ans)%p;
    return ans%p;
}
ll inv(ll a,ll m)
{
    return power(a,m-2,m);
}
//code begins
signed main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    ll a,b,c,d;cin>>a>>b>>c>>d;
    bool flag=true;
    while(a>0 && c>0)
    {
        if(flag)
        {
            c-=b;
            if(c<=0)
            {
                cout<<"Yes\n";
                return 0;
            }
        }
        else
        {
            a-=d;
            if(a<=0)
            {
                cout<<"No\n";
                return 0;
            }
        }
        flag=!flag;
    }
    return 0;
}


Measured memory_bytes: 3668
#include <utility>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <numeric>
#include <limits>
#include <queue>
#include <cstdint>


#define ll long long int
#define rep(i,rept) for (ll i = 0; i < rept; i++)
#define Yes(b) std::cout<< (b ? "Yes" : "No")<<std::endl
#define YES(b) std::cout<< (b ? "YES" : "NO")<<std::endl
#define fr first
#define se second
#define se second
#define lolo 92233720368547757
#define susu 1000000007

using namespace std;
int main() {
	
	int n;
	cin >> n;
	cout << (n < 1200 ? "ABC" : (n < 2800 ? "ARC" : "AGC"));

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I=ll(A);I<ll(B);++I)

int main(){ 
	ll n,q,rn,bn;
	cin >> n >> q;
	rn = sqrt(n);
	bn = ceil((double)n/rn);
	vector<ll> a(n,0),ba(bn,0),bs(bn,0);
	while(q--){
		ll com;
		cin >> com;
		if(com==0){//add
			ll s,t,x;
			cin >> s >> t >> x;
			s--;t--;
			FOR(i,s,t+1){
				if(i%rn==0 && (i+rn-1)<=t){
					ba[i/rn] += x;
					i += rn - 1;
				}else{
					a[i] += x;
					if((i+1)%rn==0 || i==t){
						ll bi = i/rn;
						bs[bi] = 0;
						FOR(j,rn*bi,(bi+1)*rn){
							bs[bi] += a[j];
						}
					}
				}
			}
		}else{//getsum
			ll s,t;
			cin >> s >> t;
			s--;t--;
			ll ans = 0;
			FOR(i,s,t+1){
				if(i%rn==0 && (i+rn-1)<=t){
					ans += bs[i/rn]+rn*ba[i/rn];
					i += rn-1;
				}else{
					ans += a[i]+ba[i/rn];
				}
			}
			cout << ans << endl;
		}
	}
}


Measured memory_bytes: 3616
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;
int a[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, m;
	cin >> n >> m;
	if (abs(n - m) > 1) puts("0"), exit(0);
	LL ans = 1;
	for (int i = 1; i <= n; i++) ans = ans * i % INF;
	for (int i = 1; i <= m; i++) ans = ans * i % INF;
	if (n == m) ans = ans * 2 % INF;
	cout << ans << endl;
	return 0;
}

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

#define sz(x) int(x.size())
#define pii pair<int, int>
#define All(x) (x).begin(), (x).end()
#define mp make_pair
#define Task "abc"

typedef long long ll;
const int maxn = 1e5 + 10;
const ll mod = 1e9 + 7;

ll f[maxn], cnt[maxn];

ll Pow(ll x, ll y){
  if (y == 0) return 1;
  ll tmp = Pow(x, y / 2);
  tmp = tmp * tmp; tmp %= mod;
  if (y % 2) return (tmp * x) % mod;
  return tmp;
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(NULL);
//  freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout);
  int n, k; cin >> n >> k;

  for (int i = 1; i <= k; ++i)
    for (int j = i; j <= k; j += i) ++cnt[i];

  ll ans = 0;
  for (int i = k; i > 0; --i){
    f[i] = Pow(cnt[i], n);
    for (int j = i * 2; j <= k; j += i) {
      f[i] = f[i] - f[j] + mod;
      f[i] %= mod;
    }
    ans = ans + f[i] * i;
    ans = ans % mod;
  }
  cout << ans;

return 0;
}




Measured memory_bytes: 5200
import static java.lang.String.*;

import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = null;
		try{
			scan =new Scanner(System.in);
			int a ,b;
			while(true){
				a = scan.nextInt();
				b = scan.nextInt();
				if(a == 0 && b==0)break;
				if(a < b){
					System.out.println(a +" "+b);
				}else
					System.out.println(b +" "+a);
			}
			}finally{
			if(scan !=null)scan.close();
		}

	}
}

Measured memory_bytes: 27160
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;}
const long long MOD = 1000000007;
typedef long long ll;

ll n,a;
string t,u;
set<ll> s;

int main() {
  cin >> n;
  rep(i,n) cin >> a, s.insert(a);
  cout << ((ll)s.size()==n ? "YES" : "NO") << endl;
}

Measured memory_bytes: 9600
#157 c
n,m=map(int,input().split())
num=[-1,-1,-1]
flag=True
for i in range(m):
    x,y=map(int,input().split())
    if x==1 and y==0 and n!=1:
        flag=False

    if num[x-1]!=y and num[x-1]!=-1:
        flag=False
    else:
        num[x-1]=y
ans=""
for i in range(n):
    if i==0 and num[i]==-1:
        num[i]=1
    elif num[i]==-1:
        num[i]=0
    ans+=str(num[i])
if n==1 and m==0:
    ans="0"

if flag:
    print(ans)
else:
    print(-1)


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int N; cin >> N;
	string S; cin >> S;
	vector<LL> dp(N,0);
	dp[0] = 1;
	const LL mod = 1e9+7;
	repp(i,0,N-1){
		vector<LL> nx(N,0);
		LL z = 0;
		if(S[i] == '<'){
			repp(k,0,i+1) nx[k+1] = z = (z+dp[k])%mod;
		} else {
			repm(k,i,-1) nx[k] = z = (z+dp[k])%mod;
		}
		swap(dp,nx);
	}
	LL ans = 0;
	repp(i,0,N) (ans += dp[i]) %= mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        int K = sc.nextInt();

        String x = String.valueOf(S.charAt(K-1));
        StringBuffer ret = new StringBuffer();
        for (int i=0; i<N; i++) {
            if (String.valueOf(S.charAt(i)).equals(x)) {
                ret.append(x);
            } else {
                ret.append("*");
            }
        }
        System.out.println(ret);
    }
}


Measured memory_bytes: 21844
function myout(text){console.log(text);}//standard output
function Main(input) {
	//input = parseInt(input);
	//input = input.split(" ");
	input = input.split("\n");
	//input = input.split(" ").map((a)=>Number(a));
	//input = input.split("\n").map((a)=>Number(a));
  var max = 0;
  var incre = 0;
  for(var i = 0; i < parseInt(input[0]); i++){
    var tmp = input[1].slice(i,i+1);
    if(tmp == "I"){
       incre++;
       }else{
       incre--;
       }
    max = Math.max(max,incre);
  }
  myout(max);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 7372
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main(void){
    vector<int> pos(5);
    for(auto & in : pos){
        cin >> in;
    }
    int k;
    cin >> k;
    auto c = 0;
    for(auto i = 0; i < 5; ++i){
        for(auto j = 0; j < 5; ++j){
            if(i >= j){
                continue;
            }
            if(abs(pos[i] - pos[j]) > k){
                c++;
            }
        }
    }
    if(c){
        cout << ":(";    
    } else{
        cout << "Yay!";
    }
}

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

int main(){
  int n,m,x,i,j,k,l,ans,z,h;
  cin >> n >> m >> x;
  int a[n][m+1],b[m+1];
  for(i=0;i<n;i++){
    for(j=0;j<=m;j++){
      cin >> a[i][j];
    }
  }
  l=pow(2,n);
  ans=1200001;
  for(i=1;i<l;i++){
    for(j=0;j<=m;j++){
      b[j]=0;
    }
    z=i;
    for(j=0;j<n;j++){
      if(z%2==1){
        for(k=0;k<=m;k++){
          b[k]+=a[j][k];
        }
      }
      z=z/2;
    }
    h=1;
    for(k=1;k<=m;k++){
      if(b[k]<x)h=0;
    }
    if(h==1){
      ans=min(ans,b[0]);
    }
  }
  if(ans!=1200001){
  	cout << ans;
  }
  else{
    cout << -1;
  }
}

Measured memory_bytes: 4100
import java.util.*;
public class Main {
    Scanner sc = new Scanner(System.in);
    public static void main(String args[]) {
	new Main().doIt();
    }
    void doIt() { C(); } 
    void C() {
	long ans = 0;
	ArrayList<String> s = new ArrayList<String>();
	int N = sc.nextInt();
	for(int i = 0; i < N; i++) {
	    char [] work = sc.next().toCharArray();
	    Arrays.sort(work);
	    s.add(new String(work));
	}
	Collections.sort(s);
	//	for(String ss: s) System.out.println(ss);
	int cnt = 0;
	for(int i = 1; i < N; i++) {

	    if(s.get(i-1).equals(s.get(i))) {
		cnt++;
		ans += cnt;
	    } else cnt = 0;
	}
	System.out.println(ans);


    }
    void B() {
	int K = sc.nextInt(), X = sc.nextInt();
	ArrayList<Integer> ans = new ArrayList<Integer>();
	for(int i = X-(K-1); i <= X+(K-1); i++) ans.add(i);
	//	System.out.println(ans);
	for(Integer i: ans) System.out.print(" " + i);
	System.out.println();
    }
    void A() {
	int A = sc.nextInt(), B = sc.nextInt();
	int ans = A+B;
	ans = Math.max(ans, Math.max(A-B, A*B));
	System.out.println(ans);
    }
}




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

using namespace std;

double dp[301][301][301];
bool vis[301][301][301] = {0};
int n;

double solve(int x, int y, int z)
{
	if (x <= 0 && y <= 0 && z <= 0)
		return 0;
	//cout << x << y << z << endl;
	if (vis[x][y][z])
		return dp[x][y][z];
	vis[x][y][z] = 1;
	double ans = 1.0;
	//cout << x << " ";
	if (x > 0)
	{
		//cout << (double)x / n << " ";
		ans += ((double)x / n) * solve(x - 1, y, z);
		//cout << ans << endl;
	}
	if (y > 0)
		ans += ((double)y / n) * solve(x + 1, y - 1, z);
	if (z > 0)
		ans += ((double)z / n) * solve(x, y + 1, z - 1);
	ans /= ((1.0 - ((double)n - x - y - z) / n));
	//cout << ans << endl;
	return dp[x][y][z] = ans;
}

int main()
{
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int x = 0, y = 0, z = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] == 1)
			x++;
		else if (a[i] == 2)
			y++;
		else if (a[i] == 3)
			z++;
	}
	printf("%.10lf", solve(x, y, z));
	return 0;
}


Measured memory_bytes: 239872
#include<iostream>
using namespace std;
int main(){
  int J,S,R,E,P1,P2;
  cin >> J >> S >> R >> E;
  P1=J+S+R+E;
  cin >> J >> S >> R >> E;
  P2=J+S+R+E;
  if(P1<P2){
    cout << P2 << endl;
  }
  else if(P2<P1){
    cout << P1 << endl;
  }
  else if(P1==P2){
    cout << P1 << endl;
  }
  return (0);
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;
int diff(char a, char b, char c){
	if(a==b&&b==c) return 0;
	if(a==b&&b!=c) return 1;
	if(a==c&&b!=c) return 1;
	if(b==c&&a!=c) return 1;
	return 2;
}
int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int n; cin>>n;
	string s,t,e;
	cin>>s>>t>>e;
	int cnt=0;
	for(int i=0; i<n; i++) {
		cnt+=diff(s[i],t[i],e[i]);
	}
	cout<<cnt<<endl;


	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n,k;cin >> n >> k;
	vector<int> v(n);
	for(int i=0;i<n;i++) cin >> v[i];
	
	//k <= 2*nが前提
	if(k > 2*n){
		k = 2*n;
	}
	// m個戻すとすると、k-m個取ってくることが出来る
	int ans = 0;
	for(int m = 0;2*m <= k;m++){
		int g = k - m; if(g > n) continue;
		//左からl,右からr = g - l個取ってくるとする
		for(int l = 0;l <= g;l++){
			int r = g - l;
			priority_queue<int,vector<int>,greater<int>> q;
			int res = 0;
			for(int i = 0;i < l;i++){ q.push(v[i]);  res += v[i];}
			for(int i = 0;i < r;i++){ q.push(v[n-1-i]); res += v[n-1-i]; }
			ans = max(ans,res);
			
			int j = 0;
			while(j < m && q.top() < 0 && !q.empty()){
				res -= q.top();
				q.pop();
				j++;
			}
			ans = max(ans,res);
		}
	}
	cout << ans << endl; return 0;
}

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

using namespace std;

int rec( int i, int j, const vector<vector<int>>& abc, vector<vector<long long>>* memo )
{
    if ( i == 0 ) return 0;

    if ( ( *memo )[ i ][ j ] != -1 ) return ( *memo )[ i ][ j ];

    long long maxValue = 0;
    for ( int k = 0; k < 3; ++k )
    {
        if ( k == j ) continue;
        int temp = rec( i - 1, k, abc, memo ) + abc[ i - 1 ][ k ];
        if ( temp > maxValue ) maxValue = temp;
    }

    return ( *memo )[ i ][ j ] = maxValue;
}

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

    vector<vector<int>> abc( N, vector<int>( 3 ) );
    for ( int i = 0; i < N; ++i ) cin >> abc[ i ][ 0 ] >> abc[ i ][ 1 ] >> abc[ i ][ 2 ];

    vector<vector<long long>> memo( N + 1, vector<long long>( 3 + 1, -1 ) );
    cout << rec( N, 3, abc, &memo ) << endl;
}

Measured memory_bytes: 20608
while True:
    [H,W] = raw_input().split()
    H = int(H)
    W = int(W)
    if H == 0 and W == 0:
        break

    for y in range(0,H):
        s = ''
        for x in range(0,W):
            k = x + y
            if k % 2 == 0:
                c = '#'
            else:
                c = '.'
            s = s + c
        
        print s
    print ''

Measured memory_bytes: 4212
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    ll K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i, N) {
        cin >> A[i];
        A[i]--;
    }

    set<int> visited;
    vector<int> seq;
    int v = 0;
    do {
        visited.insert(v);
        seq.push_back(v);
        v = A[v];
        K--;
        if (K == 0) {
            write(v + 1);
            return 0;
        }
    } while (visited.find(v) == visited.end());

    int idx = -1;
    rep(i, seq.size()) {
        if (seq[i] == v) {
            idx = i;
            break;
        }
    }

    write(seq[idx + K % ((int)seq.size() - idx)] + 1);
}


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

#define int long long
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;

template<class T>void Add(T &a, const T &b, const T &mod) {
  int val = (a % mod) + (b % mod);
  if (val < 0) { val += mod; }
  a = val;
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

const int MOD = 1e9 + 7;
string K;
int D;

int dp[11111][2][111];

signed main() {
  cin >> K >> D;
  int n = K.size();

  dp[0][0][0] = 1;
  for (int digit = 0; digit < n; digit++) {
    for (int smaller : {0, 1}) {
      int lim = (smaller == 1 ? 9 : K[digit] - '0');
      for (int num = 0; num <= lim; num++) {
        for (int modD = 0; modD < D; modD++) {
          Add(dp[digit+1][smaller || num < lim][(modD + num) % D], dp[digit][smaller][modD], MOD);
        }
      }
    }
  }

  int ans = 0;
  for (int smaller : {0, 1}) {
    Add(ans, dp[n][smaller][0], MOD);
  }
  // print(dp[n][0][0], dp[n][1][0]);
  Add(ans, -1LL, MOD);

  cout << ans << endl;

  return 0;
}


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

kaku = [1/n] * n
for i in range(n):
    point = i + 1
    while point < k:
        kaku[i] /= 2
        point *= 2
kakuritu = 0
for j in range(n):
    kakuritu += kaku[j]

print(kakuritu)


Measured memory_bytes: 3700
//競技プログラミング　テンプレ
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
 
using namespace std;
 
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
 
const int max_v = 300;
const int INF = 1000000;
 
 
 
int main() {
 
	string x,y;
 
  cin >> x >> y; 
  sort(x.begin(),x.end());
  sort(y.begin(),y.end(),greater<char>());
  if(x < y ){ cout << "Yes" << endl; return 0;}
  else {cout << "No" << endl; return 0;}
  //else if(x ==y){ if()return 0;}
  
 
	return 0;
}

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

namespace AOJ0046
{
    class Program
    {
        static void Main()
        {
            var data = ReadInputs().ToArray();
            Console.WriteLine(data.Max() - data.Min());
        }

        public static IEnumerable<double> ReadInputs()
        {
            string line;
            while ((line = Console.ReadLine()) != null)
            {
                yield return double.Parse(line);
            }
        }
    }
}

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

using namespace std;

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
 
int main(){
    int A, B, K;
    vector<int> v;

    cin >> A >> B >> K;

    if(B-A+2 <= K){
        for(int i = A; i <= B; i++) v.push_back(i);
    }else{
        for(int i = A; i < A+K; i++) v.push_back(i);
        for(int i = B-K+1; i <= B; i++) v.push_back(i);
    }

    sort(v.begin(), v.end());

    for(int i = 0; i < v.size(); i++){
        if(v[i] == v[i+1]) continue;
        cout << v[i] << endl;
    }
    


    return 0;
}

Measured memory_bytes: 256
A,B,C=map(int,input().split())
L=[A,B,C]
L=sorted(L)
ans=0
ans+=L[2]-L[1]
L[0]+=L[2]-L[1]
ans+=(L[2]-L[0])//2
L[0]+=((L[2]-L[0])//2)*2
if L[0]!=L[2]:
  ans+=2
print(ans)

Measured memory_bytes: 61812
package main

import "fmt"

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)
	maxCount := 0
	for i := 1; i < n; i++ {
		count := sameKindCount(s[:i], s[i:])
		maxCount = max(count, maxCount)
	}
	fmt.Println(maxCount)
}

func sameKindCount(a, b string) int {
	m1 := map[rune]bool{}
	for _, c := range a {
		m1[c] = true
	}
	m2 := map[rune]bool{}
	for _, c := range b {
		m2[c] = true
	}
	count := 0
	for v := range m1 {
		if _, ok := m2[v]; ok {
			count++
		}
	}
	return count
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

Measured memory_bytes: 640
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();
            long ans = 1;
            boolean isOk = true;
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextLong();
            }

            sort(arr);
            for (int i = 0; i < n; i++) {
                long a = arr[i];
                long ans1 = ans * a;
                if (a != 0 && ans1 / a != ans) {
                    isOk = false;
                } else {
                    ans = ans1;
                }
            }

            if (isOk && ans <= 1000000000000000000L) {
                out.println(ans);
            } else {
                out.println(-1);
            }
        }
    }

    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: 59132
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    
    --a; --b; --c; --d;
    
    string s;
    cin >> s;
    
    vector<ll> obstacle;
    vector<ll> room;
    
    for ( ll i = 0; i < n; i++ ){
        if ( i < n - 1 && s[i] == '#' && s[i+1] == '#' )
            obstacle.push_back(i);
        if ( i < n - 2 && s[i] == '.' && s[i+1] == '.' && s[i+2] == '.' )
            room.push_back(i);
    }
    
    auto itr1 = lower_bound(obstacle.begin(), obstacle.end(), a);
    
    if ( c < d ) {
        if ( (itr1 == obstacle.end() || *itr1 > d )){
            cout << "Yes" << endl;
            return 0;
        }
    } else {
        if ( itr1 == obstacle.end() || *itr1 > c ){
            auto itr3 = lower_bound( room.begin(), room.end(), b-1);
            if ( itr3 != room.end() && *itr3 < d ){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    
    cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>

void solve() {
    int h, w;
    std::cin >> h >> w;

    std::vector<std::vector<int>> dss(h, std::vector<int>(w));
    for (auto& ds : dss) {
        for (auto& d : ds) {
            char c;
            std::cin >> c;
            d = (c == '.' ? 0 : c - '0');
        }
    }

    std::queue<std::tuple<int, int, int>> que;
    for (int x = 0; x < h; ++x) {
        for (int y = 0; y < w; ++y) {
            if (dss[x][y] == 0) que.emplace(x, y, 0);
        }
    }

    int ans = 0;
    while (!que.empty()) {
        int x, y, t;
        std::tie(x, y, t) = que.front();
        que.pop();
        ans = t;

        for (int dx = -1; dx <= 1; ++dx) {
            for (int dy = -1; dy <= 1; ++dy) {
                int nx = x + dx, ny = y + dy;
                if (nx < 0 || h <= nx || ny < 0 || w <= ny) continue;
                if (--dss[nx][ny] == 0) {
                    que.emplace(nx, ny, t + 1);
                }
            }
        }
    }

    std::cout << ans << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}



Measured memory_bytes: 7052
N=int(input())
weights=[1]
pow6=6
while N>=pow6:
    weights.append(pow6)
    pow6*=6
pow9=9
while N>=pow9:
    weights.append(pow9)
    pow9*=9
dp=[1<<28]*(N+1)
dp[0]=0
for i in range(len(weights)):
    for j in range(weights[i],N+1):
        dp[j]=min(dp[j],dp[j-weights[i]]+1)
print(dp[N])

Measured memory_bytes: 6900
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::ascii::AsciiExt;

fn main() {
    input!{
        n:usize,
        k:usize,
        s:chars
    }
    let mut ans = "".to_string();
    for i in 0..n {
        if i==k-1 {
            ans+=&s[i].to_ascii_lowercase().to_string();
            
        }else{
            ans+=&s[i].to_string();
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin >> a;
  int b, c, d;
  b = a / 100;
  c = (a - b * 100) / 10;
  d = a - a / 10 * 10;
  
  cout << b + c + d << endl;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

/*
    1-indexed であることに注意 !! 
*/
template <typename T>
struct BIT{
    int n;
    vector<T> dat;

    BIT(int n) : n(n), dat(n + 1, 0) {}

    T sum(int a){
        T res = 0;
        for(int i = a; i > 0; i -= (i & (-i))) res += dat[i];
        return res;
    }

    T sum(int a, int b){
        return sum(b - 1) - sum(a - 1);
    }

    void add(int k, T x){
        if(k == 0) return;
        for(int i = k; i <= n; i += (i & (-i))) dat[i] += x;
    }

    /*
        a[0] + a[1] + ... + a[res] >= x
    */
    int lower_bound(T x){
        if(x <= 0) return T(0);
        int res = 0, k = 1;
        while(k < n) k <<= 1;
        for(; k > 0; k >>= 1){
            if(res + k <= n && dat[res + k] < x){
                x -= dat[res + k];
                res += k;
            }
        }
        return res + 1;
    }
};

signed main(){
    int n,k;
    cin >> n >> k;
    double p[n];
    rep(i,n){
        cin >> p[i];
    }
    long double sum[n + 1] = {};
    rep(i,n){
        sum[i + 1] = sum[i] + (p[i] + 1.0) / 2.0;
    }
    long double ans = 0.0;
    rep(i,n - k + 1){
        ans = max(ans, sum[i + k] - sum[i]);
    }
    printf("%.10Lf\n", ans);
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
using namespace std;
#define HOUSE 4
#define FLOOR 3
#define ROOM 10
int main() {
	int n, room, floor, house, people;
	int ary[HOUSE][FLOOR][ROOM];
	for (int i = 0; i < HOUSE; i++) {
		for (int j = 0; j < FLOOR; j++) {
			for (int k = 0; k < ROOM; k++) {
				ary[i][j][k] = 0;
			}
		}
	}
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> house >> floor >> room >> people;
		ary[house-1][floor-1][room-1] += people;
	}
	for (int i = 0; i < HOUSE; i++) {
		for (int j = 0; j < FLOOR; j++) {
			for (int k = 0; k < ROOM; k++) {
				cout << " " << ary[i][j][k];
			}
			cout << endl;
		}
		if(i < HOUSE-1)
		    cout << "####################" << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include<iostream>

using namespace std;

int main() {
  int a[] = {1, 0, 0};
  string str;
  while (cin >> str) {
    swap(a[str[0] - 'A'], a[str[2] - 'A']);
  }
  for (int i = 0; i < 3; ++i) if (a[i] == 1) cout << (char)('A' + i) << endl;
  return 0;
}

Measured memory_bytes: 1172
n = int(input())
d = []
u = []
for _ in range(n):
    a, b = map(int, input().split())
    d.append(a)
    u.append(b)

d = sorted(d)
u = sorted(u, reverse=True)
if n % 2 == 0:
    dl = (d[n//2] + d[n//2-1]) / 2
    ul = (u[n//2] + u[n//2-1]) / 2
    ans = int((ul-dl) / 0.5 + 1)
else:
    dl = d[n//2]
    ul = u[n//2]
    ans = ul-dl+1
print(ans)

Measured memory_bytes: 26960
W, H, x, y, r = map(int, input().split())

if (W > 0 and W <= 100 and H > 0 and H <= 100 and x >= -100 and x <= 100 and y >= -100 and y<= 100 and r > 0 and r <= 100):
    if (W < (x+r) or H < (y+r) or (x-r) < 0 or (y-r) < 0):
        print("No")
    else:
        print("Yes")


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

int main() {
  int N;
  cin >> N;
  vector A(N, vector(3, 0));
  vector V = A;
  for (auto &a : A) for (auto &b : a) cin >> b;
  V.at(0) = A.at(0);
  for (int i = 0; i + 1 < N; i++) {
    V.at(i + 1).at(0) = A.at(i + 1).at(0) + max(V.at(i).at(1), V.at(i).at(2));
    V.at(i + 1).at(1) = A.at(i + 1).at(1) + max(V.at(i).at(0), V.at(i).at(2));
    V.at(i + 1).at(2) = A.at(i + 1).at(2) + max(V.at(i).at(0), V.at(i).at(1));
  }
  cout << *max_element(V.back().begin(), V.back().end()) << "\n";
}

Measured memory_bytes: 14328
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
x  = int(input())
#  = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

n = x // 100
mod = x % 100
print(0 if 5 * n < mod else 1)



Measured memory_bytes: 3316
#include <stdio.h>

int main(void) {
	int N, M;
	int base = 1;
	int i, j, l;

	scanf("%d %d", &N, &M);

	for (i = 1;i <= N;i++) {
		base *= 2;
	}

	base--;


	int k[16];
	int a[16][16];
	int b[16][16];
	int s[16];
	int p[16];

	for (i = 1;i <= M;i++) {

		s[i] = 0;
		scanf("%d", &k[i]);
		
		for (j = 1;j <= k[i];j++) {

			scanf("%d", &a[i][j]);
			
			b[i][j] = 1;
			for (l = 1;l <= a[i][j];l++) {
				b[i][j] *= 2;
			}

			s[i] += b[i][j];
		};

		s[i] /= 2;
		
	}

	for (i = 1;i <= M;i++) {

		scanf("%d", &p[i]);
	}

	int count = 0;
	int sbit[M];

	for (j = 0;j <= base;j++) {

		int subcount = 1;

		for (i = 1;i <= M;i++) {
			int scount = 0;
			
			sbit[i] = s[i] & j;
						
			for (l = 1;l <= N;l++) {
				scount += sbit[i] % 2;
				sbit[i] /= 2;
			}
		
			scount %= 2;

			if (scount == p[i]) {}
			else {
				subcount--;
				break;
			}
		}

		if (subcount == 1) {
			count++;
		}
	}

	printf("%d", count);


	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
int l,k;
char s[110];
long long dp0[110][4],dp1[110][4];//可能等于、已经小于,第i位，用了j个非零数字


int main()
{
	//freopen("test.in","r",stdin);
	scanf("%s%d",s,&k);
	l=strlen(s);
	dp1[0][0]=1;//这一位小于，这一位是0
	dp0[0][0]=0;//这一位等于，这一位是0
	dp0[0][1]=1;
	dp1[0][1]=s[0]-'0'-1;
	for(int i=1;i<l;i++)
	{
		dp1[i][0]=1;//0
		for(int j=1;j<=k;j++)
		{
			if(s[i]=='0')
			{
				dp0[i][j]=dp0[i-1][j];//只能填一个0
				dp1[i][j]=dp1[i-1][j]+dp1[i-1][j-1]*9;
			}
			else
			{
				dp0[i][j]=dp0[i-1][j-1];
				dp1[i][j]=dp0[i-1][j-1]*(s[i]-'0'-1)+dp0[i-1][j]+dp1[i-1][j]+dp1[i-1][j-1]*9;
			}
		}
	}
	printf("%lld\n",dp0[l-1][k]+dp1[l-1][k]);
	return 0;
}


Measured memory_bytes: 128
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        int countO=0;
        int countF=0;
        for(int i=0; i<N; i++){
            A[i]=sc.nextInt();
            if(A[i]%4==0){
                countF++;
            }else if(A[i]%2==1){
                countO++;
            }
        }
        String res;
        if(countF>=countO){
            res = "Yes";
        }else if(countO+countF==N && countF==countO-1){
            res = "Yes";
        }else{
            res = "No";
        }
        System.out.println(res);
        
        }
    }

Measured memory_bytes: 59660
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  cin>>n;
  string s;
  cin>>s;
  stack<int> st;
  int a=0;
  rep(i,s.size()){
    if(s[i]=='('){
      st.push(1);
    }else{
      if(st.size())st.pop();
      else a++;
    }
  }
  rep(i,a)cout<<'(';
  cout<<s;
  while(st.size()){
    cout<<')';
    st.pop();
  }
  cout<<endl;
}


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

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

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

#define pb push_back
#define mp make_pair 

using namespace std;

const int INF=INT_MAX/4;
const int MOD=1000000007;
const double EPS=1e-14;

const bool debug_flag=true;

void debug(string str){
	if(debug_flag){
		cout<<str<<endl;
	}
}

void debugs(string str){
	if(debug_flag){
		cout<<str;
	}
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout.precision(10);


	int n;
	cin>>n;
	int cnt=0, l, r;
	for(int i=0; i<n; i++){
		cin>>l>>r;
		cnt+=r-l+1;
	}
	cout<<cnt<<endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define VI vector<int>
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
int x, y, z;
int main(){
	scanf("%d %d %d", &x, &y, &z);
	swap(x,y); swap(x,z);
	printf("%d %d %d\n", x, y, z);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const ll N = 100005;
const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-7;
const double PI = acos(-1.0);

ll n, m;
bool have[N];
ll numBalls[N];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin >> n >> m;
    have[1] = true;
    fill(numBalls, numBalls + n + 1, 1);
    while(m--)  
    {
        int x, y;
        cin >> x >> y;
        if(have[x])
            have[y] = true;
        numBalls[x]--;
        numBalls[y]++;
        if(numBalls[x] == 0)
            have[x] = false;
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++)
        if(have[i])
            ans++;
    cout << ans << endl;
}

Measured memory_bytes: 1152
def main():
	string = str(input())
	dp = [0 for _ in range(26)]
	for i in range(len(string)):
		dp[ord(string[i])-ord('a')]+=1
	for x in dp:
		if x%2!=0:
			print("No")
			return 
	print("Yes")
	return
main()


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

int main(void) {
  int N;
  cin >> N;
  map<string, int> m;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    m[s]++;
  }
  long long ans = 0;
  for (auto itr : m) {
    ans += (long long)itr.second * (long long)(itr.second - 1) / 2;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 11136
package main

import (
	"bytes"
	"fmt"
)

func main() {
	var h, w int
	var s string
	fmt.Scan(&h, &w)
	a := make([]string, h+2)
	var bytes bytes.Buffer
	for i := 0; i < w+2; i++ {
		bytes.WriteString("#")
	}
	a[0] = bytes.String()
	a[len(a)-1] = bytes.String()
	for i := 1; i < h+1; i++ {
		bytes.Reset()
		fmt.Scan(&s)
		bytes.WriteString("#")
		bytes.WriteString(s)
		bytes.WriteString("#")
		a[i] = bytes.String()
	}
	for i := 0; i < h+2; i++ {
		fmt.Println(a[i])
	}
}


Measured memory_bytes: 640
def main():
    n=int(input())
    a=list(map(int,input().split()))
    x=a[0]
    y=sum(a)-a[0]
    ans=abs(x-y)
    for i in range(1,n-1):
        x+=a[i]
        y-=a[i]
        ans=min(abs(x-y),ans)
    print(ans)
if __name__=="__main__":
    main()

Measured memory_bytes: 24812
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    map<int, int> cnt1, cnt2;
    int N, a;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a;
        if (i % 2) cnt1[a]++;
        else cnt2[a]++;
    }
    vector<pii> v;
    for (auto c : cnt1) v.push_back(pii(c.second, c.first));
    for (auto c : cnt2) v.push_back(pii(c.second, c.first));
    sort(v.begin(), v.end(), greater<pii>());
    int ans = N;
    int cnt = -1;
    for (int i = 0; i < v.size(); i++) {
        if (cnt == -1) {
            ans -= v[i].first;
            cnt = v[i].second;
        }
        else {
            if (cnt == v[i].second) continue;
            ans -= v[i].first;
            break;
        }
    }
    cout << ans << '\n';
}

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

int n, x, a[1001], ans, p, c[1001], b[1001];

void Dfs(int x) {
	if(x > n) {
		for(int i = 1; i <= n; i++)
			c[i] = a[i];
		sort(a + 1, a + n + 1);
		int now = 24;
		for(int i = 1; i <= n; i++)
			now = min(now, a[i] - a[i - 1]);
		now = min(now, 24 - a[n]);
		ans = max(ans, now);
		for(int i = 1; i <= n; i++)
			a[i] = c[i];
		return;
	}
	if(!b[24 - a[x]]) {
		a[x] = 24 - a[x];
		b[a[x]] = 1;
		p += (1 << (x - 1));
		Dfs(x + 1);
		b[a[x]] = 0;
		p -= 1 << (x - 1);
		a[x] = 24 - a[x];	
	}
	if(!b[a[x]]) {
		b[a[x]] = 1;
		Dfs(x + 1);
		b[a[x]] = 0;
	}
//	Dfs(x +/ 1);
}

int main(void) {
	scanf("%d", &n);
	if(n > 23) {
		puts("0");
		return 0;
	}
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		if(a[i] == 0) {
			puts("0");
			return 0;
		}
	}
	ans = 0;
	Dfs(1);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
n,a,b=map(int,input().split())
if a*n<b:
    print(a*n)
else:
    print(b)









# import os
# import csv
# 
# stores_path = "店舗コード.csv"
# 
# with open(stores_path, encoding="cp932") as f:
#     reader = csv.reader(f)
#     for row in reader:
#         folder_name = row[0] + '_' + row[1]
#         if not os.path.exists(folder_name):
#             os.mkdir(folder_name)

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

using namespace std;

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

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

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

int dfs( int x, int y );

int h, w;


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

    cin >> h >> w;
    int cnt = 0;
    for( int i = 1; i <= h ; ++i ) {
        string s;
        cin >> s;
        for( int j = 1; j <= w; ++j ) {
            if( s[j - 1] == '#' ) ++cnt;
        }
    }

    if( cnt == h + w - 1 ) cout << "Possible";
    else cout << "Impossible";
    cout << endl;

    return 0;
}


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


int main(){
  int w;
  while(true){
    cin >> w;
    if(w == -1)break;
    int sum = 0,pre = 4280;
    sum += 1150;
    if(w >= 10 && w <= 20)sum += (w-10)*125;
    else if(w >= 20)sum += 10*125;
    if(w >= 20 && w <= 30)sum += (w-20)*140;
    else if(w >= 30)sum += 10*140;
    if(w >= 30)sum += (w-30)*160;
    cout << pre - sum << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int m,n,q,A[20];
int a(int x,int y){
  if(x==0)return 0;
  if(y>=n)return 1;
 
  if(a(x,y+1)==0 || a(x-A[y],y+1)==0)return 0;
  else return 1;
}
 
int main(){ 
  cin>>n; 
  for(int i=0;i<n;i++)cin>>A[i];
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>m;
    if(a(m,0)==0)
      cout<<"yes"<<endl;
    else 
      cout<<"no"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1152
N = int(input())

A = list(map(int,input().split()))

AVE = sum(A)/len(A)
DIFF = 1000.0
Samu = 0
for i in range(N):
    a = A[i]
    if abs(AVE-a) < DIFF:
        DIFF = abs(AVE-a)
        Samu = i
    #print(i,Samu,DIFF)
        
print(Samu)

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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef pair<int, int> pii;

int main(){
    fcin;
    int n, k;
    cin >> n >> k;
    int ans = 0;
    while(n){
        n /= k;
        ans++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<queue>
#include<functional>
using namespace std;

constexpr int INF = 1e9;

struct edge
{
	int from, to, cost;
	bool operator>(const edge& other)
	const{
		return cost > other.cost;
	}
};

using edges= vector<edge>;
using graph = vector<edges>;

void add_edge(graph& g,int from,int to,int cost)
{
	g[from].push_back(edge{ from,to,cost });
	g[to].push_back(edge{ to,from,cost });
}

edges prim(const graph& g)
{
	const int N = g.size();
	vector<bool>used(N);
	used[0] = true;
	priority_queue<edge, vector<edge>, greater<edge>>que;
	for (auto e:g[0])
	{
		que.push(e);
	}
	edges mst;
	while (!que.empty())
	{
		auto e = que.top();
		que.pop();
		if (used[e.to])
		{
			continue;
		}
		mst.push_back(e);
		used[e.to] = true;
		for (auto new_e:g[e.to])
		{
			que.push(new_e);
		}


	}
	return mst;


	
}
int main()
{
	int V, E;
	cin >> V >> E;
	graph g(V);
	for (int i = 0; i < E; i++)
	{
		int s, t, w;
		cin >> s >> t >> w;
		add_edge(g, s, t, w);
	}
	const auto mst = prim(g);
	int ans = 0;
	for (auto& e : mst)
	{
		ans += e.cost;
	}
	cout << ans << endl;
	return 0;
}
/*
メンバ関数（今回は演算子オーバーロードですが同じ）のこの位置にある const の意味は
この関数の呼び出しによって，オブジェクトの内部状態が変わらないという保証になります
つまり今回であれば，operator > が呼び出されても，edge の中身のデータは変わらないよ，ということを，関数の宣言時点で明言しているということです
エラーが出る理由についてですが
std::sort のデフォルトの挙動では，std::less が使われます
（つまり < ですね
std::less<edge> の呼び出し時の引数の型は (const edge& e1, const edge& e2) であり，どちらも const が付いています
つまり，std::less の中で，e1 にも e2 にも変更を加えることが出来ないということを意味します．
もしこの時に，e1 （あるいは e2）の const でないメンバ関数を呼び出すことが出来てしまうと，オブジェクトの状態が変わる可能性があり，e1 が const であることに反し許容できません．
したがってエラーとなります．
const をつけた場合，その関数を呼び出しても内部状態が変わらないことがコンパイラにわかるので，std::less<edge> のなかで e1 < e2 が呼び出されても，問題ないというわけです
多分さっきのコードは greater だったはずなので，less を greater に置き換えて貰えれば同じです
ひえ～長文になってしまった（C++早口オタクじゃん（ごめん
doi [19:01]
　less の引数のe1あるいはe2がconstであることはbool operator>(const edge& other)で引数がconstであることによってしめされないのでしょうか？
suibaka [19:02]
e1 > e2 としたとき，other は e2 になってこっちはいいのですが，e1 はそうじゃないのでダメですね
例えば operator の定義を edge の外に出して，
bool operator>(const edge& e1, const edge& e2) {
return e1.cost > e2.cost;
}
とやれば問題ないです．
suibaka [19:33]
メンバ関数は，暗黙のうちに（僕らには見えないけど）第一引数にそのオブジェクトのポインタが渡されています
w.f(42) なら f(&w, 42) みたいなイメージです
ここまでは大丈夫ですか
doi [19:34]
大丈夫です
suibaka [19:35]
メンバ関数を const 修飾すると，この this ポインタに const が付きます
すると，this ポインタが指す先のデータの変更がダメという意味になりますね
f() は const 修飾されているので，this->data = arg は this が const なのでできません．
g は問題ないです．this は const じゃないから．
#include <iostream>
using namespace std;
class widget {
public:
widget() : data(0) {}
void f(int arg) const {
data = arg; // error
}
void g(int arg) {
data = arg; // ok
}
private:
int data;
};
// widget::f, g はこういう意味だと思うと良い
// void f(const this ポインタ, int arg) {
//	this->data = arg;
//}
// void g(widget* w, int arg) {
// this->data = arg;
//}
//
// メンバ関数の第1引数には，暗黙のうちに this ポインタが渡されている．
// メンバ関数を const 修飾すると，この this ポインタに const がつく．
// だから，this->data = arg は const 修飾されているとエラーになる．
// g の方は const じゃないので，this->data はOK
int main() {
widget w;
w.f(42); // error
w.g(42); // ok
return 0;
}
*/


Measured memory_bytes: 10128
N,M = map(int,input().split())
a = [True] * (N+1)

for _ in range(M):
  a[int(input())] = False

S = [0] * (N+1)
S[0] = 1
for n in range(1, N+1):
    if a[n]==False:
        S[n] = 0
    elif n==1:
        S[n] = 1
    else:
        S[n] = (S[n-1] + S[n-2])%1000000007

print(S[n])

Measured memory_bytes: 7668
def solve():
    K, S = map(int, input().split())
    # print(K, S)

    count = 0
    for x in range(K + 1):
        for y in range(K + 1):
            z = S - (x + y)
            if 0 <= z <= K:
                count += 1
    return count


if __name__ == '__main__':
    res = solve()
    print(res)


Measured memory_bytes: 40940
[H,N] = [int(s) for s in input().rstrip().split(' ')] #HもんすたーのHP,N魔法の種類
L_1 = []
L_2 = []
for i in range(N):
    A_i = [int(s) for s in input().rstrip().split(' ')] #[攻撃力,消費魔力]
    L_1.append(A_i[0])
    L_2.append(A_i[1])
M = [10**8 for x in range(H+max(L_1))] #最小消費魔力
M[0] = 0
for k in range(1,H+max(L_1)):
  for n in range(N):
     M[k] = min(M[k],L_2[n]+M[max(k-L_1[n],0)])
print(min(M[H:]))

Measured memory_bytes: 42816
# -*- coding: utf-8 -*-
"""
Created on Wed May 13 12:19:27 2020

@author: shinba
"""

s = input()

B1 = (s[0] == "0" and s[1] != "0") or (s[0] == "1" and 0 <= int(s[1]) <= 2)
B2 = (s[2] == "0" and s[3] != "0") or (s[2] == "1" and 0 <= int(s[3]) <= 2)

if B1 and B2:
    print("AMBIGUOUS")
elif B1:
    print("MMYY")
elif B2:
    print("YYMM")
else:
    print("NA")


Measured memory_bytes: 3064
l = input().split()
L = [int(c) for c in l]
K = L[0]
N = L[1]
A = [int(b) for b in input().split()]

A_delta = [A[0] + K - A[N-1]]
for n in range(N-1):
  A_delta.append(A[n+1] - A[n])
 
print(K - max(A_delta))

Measured memory_bytes: 26548