akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
inpl = lambda: list(map(int,input().split()))

P_MAX = 32000
sieve = [1]*P_MAX
sieve[0] = sieve[1] = 0
P = []
for i in range(2,P_MAX):
    sieve = 1
    for p in P:
        if p*p > i:
            break
        elif i % p == 0:
            sieve = 0
            break
    if sieve == 0:
        continue
    else:
        P.append(i)

def factorize(n):
    primes = []
    powers = []
    for p in P:
        if p * p > n:
            break
        elif n % p == 0:
            k = 0
            while n % p == 0:
                n //= p
                k += 1
            primes.append(p)
            powers.append(k)
    if n > 1:
        primes.append(n)
        powers.append(1)
    return primes, powers

N = int(input())
A = inpl()
infty = 100
lowest_powers = defaultdict(lambda: [infty,infty])
bottle_necks = defaultdict(lambda: -1)
all_factors = set()
for n in range(N):
    primes, powers = factorize(A[n])
    prev_primes = list(bottle_necks.keys())
    done = defaultdict(int)
    for i in range(len(primes)):
        done[primes[i]] = 1
        if not primes[i] in all_factors:
            all_factors.add(primes[i])
            if n == 1:
                lowest_powers[primes[i]] = [0,powers[i]]
                bottle_necks[primes[i]] = 0
            elif n == 0:
                lowest_powers[primes[i]] = [powers[i],infty]
                bottle_necks[primes[i]] = 0
        lowest = lowest_powers[primes[i]]
        if powers[i] == lowest[0]:
            lowest[1] = lowest[0]
            bottle_necks[primes[i]] = -1
        elif powers[i] < lowest[0]:
            lowest[1] = lowest[0]
            lowest[0] = powers[i]
            bottle_necks[primes[i]] = n
        elif powers[i] < lowest[1]:
            lowest[1] = powers[i]
    for p in all_factors:
        if done[p] == 0:
            lowest = lowest_powers[p]
            if lowest[0] == 0:
                lowest[1] = 0
                bottle_necks[p] = -1
            else:
                lowest[1] = lowest[0]
                lowest[0] = 0
                bottle_necks[p] = n

bnl = defaultdict(lambda: [])
for p,n in bottle_necks.items():
    if n >= 0:
        lowest = lowest_powers[p]
        bnl[n].append([p,lowest[1]-lowest[0]])
best_n = -1
largest_f = 1
for n in range(N):
    f = 1
    for pp in bnl[n]:
        f *= pp[0]**pp[1]
    if f > largest_f:
        largest_f = f
        best_n = n

ans = 1
bn = bnl[best_n]
pn = [ s[0] for s in bn]
for p in all_factors:
    if p in pn:
        ans *= p**lowest_powers[p][1]
    else:
        ans *= p**lowest_powers[p][0]
print(ans)

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

int main() {
	string s;
	cin >> s;
	ll ans = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s.at(i) == '+')ans++;
		else ans--;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
using namespace std;
inline int read()
{
    int x = 0,f = 1;char ch = getchar();
    for(;!isdigit(ch);ch = getchar())if(ch == '-') f = -f;
    for(;isdigit(ch);ch = getchar())x = 10 * x + ch - '0';
    return x * f;
}
LL S, sum, L[25000009];
const LL LIM = 25000000, mod = 1000000007;
inline LL skr(LL x,LL t)
{
	LL res = 1;
	while(t)
	{
		if(t & 1)res = res * x % mod;
		x = x * x % mod;
		t = t >> 1;
	}return res;
} 
int main()
{
	cin >> S;
	for (int i = 1; i <= LIM; i++)
	{
		int cx = i;
		while (cx >= 1)
		{
			cx /= 10;
			L[i]++;
		}
		L[i] += L[i - 1];
	}
	for (int i = 0; i < 9999999; i++)
	{
		int pos1 = lower_bound(L, L + LIM, L[i] + S) - L;
		if (L[pos1] == L[i] + S) sum++;
	}
	for (int i = S / 8; i >= 1; i--)
	{
		if (S%i == 0) sum += (9LL * skr(10, (S / i) - 1) - i + 1 + mod) % mod;
		else sum++;
	}
	cout << sum%mod << endl;
	return 0;
}

Measured memory_bytes: 195712
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
string s;
cin>>s;
for(int i = 0; i < 7; i++){
	if(s.substr(0 , i) + s.substr(s.size() - 7 + i) == "keyence"){
		cout<<"YES"<<endl;
		return 0;
	}
}
cout<<"NO"<<endl;
return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cmath>
#include <stack>

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

void ABC079C()
{
	string str;
	cin >> str;
	vector<int> num(4);
	for (int i = 0; i < 4; ++i)
	{
		num[i] = stoi(str.substr(i, 1));
	}

	for (int i = 0; i < (1 << 3); ++i)
	{
		stringstream ss;
		int sum = num[0];
		ss << num[0];
		for (int j = 0; j < 3; ++j)
		{
			if (0 == (i & (1 << j)))
			{
				sum += num[j + 1];
				ss << '+' << num[j + 1];
			}
			else
			{
				sum -= num[j + 1];
				ss << '-' << num[j + 1];
			}
		}
		if (sum == 7)
		{
			ss << "=7" << endl;
			cout << ss.str() << endl;
			break;
		}
	}
}

int main()
{
	ABC079C();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
 
int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  
  int N,L; 
  cin >> N >>L;
  
  int eat;
  if(L>=0) eat=L;
  else if(L+N-1<=0) eat=L+N-1;
  else eat=0;
  
  int kekka;
  kekka = N*(2*L+N-1)/2-eat;
  cout << kekka << '\n';
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#define M_PI 3.1415926535897932384626433832795

int main() {
	int n;
	cin >> n;
	vector<int>d(n);
	rep(i, n) {
		cin >> d[i];
	}
	ll sum(0);
	rep(i, n) {
		rep(j, n) {
			if (i != j) {
				sum += d[i] * d[j];
			}
		}
	}
	sum /= 2;
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main()
{
    int n;
    cin >> n;
    int q = n / 1000;
    int r = n % 1000;
    int ans = r == 0 ? 0 : (q + 1) * 1000 - n;
    cout << ans << endl;
    return 0;
}


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

int main() {
  int N,K;
  cin >> N >> K;
  
  int sum = 0;
  
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    int a = x, b = K - x;
    if(a <= b) {
      sum += 2*a;
    }
    else {
      sum += 2*b;
    }
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int n,index_s,num,ans;
string s;

void init(){
  index_s = ans = 0;
}

void find(){
  int pos = 0, pass = 0;
  string ss = "OI";

  while(1){
    if(pos == 2){
      pos = 0;
      pass++;
    }
    if(s[index_s] != ss[pos]) break;
    pos++;
    index_s++;
  }
  ans += max(0,pass-n+1);
}

void solve(){
  while(index_s < num){
    if(s[index_s++] == 'I') find();
  }
}

int main(){
  while(cin >> n && n){
    init();
    cin >> num >> s;
    solve();
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2116
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n;
    cin >> n;
    int64_t lx = INT_MAX, rx = INT_MIN, ly = INT_MAX, ry = INT_MIN;
    for (int i = 0; i < n; i++) {
        int64_t x, y;
        cin >> x >> y;
        lx = min(lx, x + y);
        rx = max(rx, x + y);
        ly = min(ly, x - y);
        ry = max(ry, x - y);
    }
    cout << max(ry - ly, rx - lx) << '\n';
    return 0;
}

Measured memory_bytes: 3620
n = int(input())
pre = list(map(int, input().split()))
ino = list(map(int, input().split()))

d = []
root = pre[0]
pre = iter(pre).__next__

def dfs(l, r):
    global d
    if l >= r:
        return
    c = pre()
    m = ino.index(c)
    dfs(l, m)
    dfs(m+1, r)
    d += [c]
    
dfs(0, len(ino))
print(*d)



Measured memory_bytes: 5600
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N, M;
    cin >> N >> M;

    int ans = 0;

    if (N > 1) ans += N * (N - 1) / 2;

    if (M > 1) ans += M * (M - 1) / 2;

    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

int main(){
    int A,B;
    cin >> A >> B;
    int ans = 0;
    ans += max(A,B);
    if(A>=B)A-=1;
    else B-=1;
    ans += max(A,B);
    cout << ans <<endl;
}


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

bool isnot_allwhite(string str)
{
  bool check = false;
  for(int i = 0; i < str.size(); i++)
  {
    if(str.at(i) == '#')
    {
      check = true;
      break;
    }
  }
  return check;
}

int main()
{
  int H, W;
  cin >> H >> W;
  vector<string> vec(0);
  string tmp;
  for(int i = 0; i < H; i++)
  {
    cin >> tmp;
    if(isnot_allwhite(tmp))
      vec.push_back(tmp);    
  }
  H = vec.size();
  vector<int> del(0);
  int count = 0;
  for(int j = 0; j < W; j++)
  {
    bool all_white = true;
    for(int i = 0; i < H; i++)
    {
      if(vec.at(i).at(j - count) == '#')
      {
        all_white = false;
        break;
      }
    }
    if(all_white)
    {
      for(int k = 0; k < H; k++)
        vec.at(k).erase(j - count, 1);
      count++;
    }
  }
  for(int i = 0; i < H; i++)
  {
    for(int j = 0; j < W - count; j++)
      cout << vec.at(i).at(j);
    cout << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t n, m;
    cin >> n >> m;

    vector<vector<int64_t>> s(m);
    for (auto&& ss : s) {
        int64_t k;
        cin >> k;
        ss.resize(k);
        for (auto&& sss : ss) {
            cin >> sss;
            --sss;
        }
    }

    vector<int64_t> p(m);
    for (auto&& pp : p) {
        cin >> pp;
    }

    int64_t ans = 0;
    for (uint64_t b = 0; b < (1L << n); ++b) {
        bitset<10> flags(b);

        auto r = irange(0L, m);
        auto ok = all_of(r.begin(), r.end(), [&](int64_t i) {
            auto nums = count_if(s[i].begin(), s[i].end(), [&flags] (int64_t idx) {
                return flags[idx];
            });

            return nums % 2 == p[i];
        });

        if (ok) {
            ++ans;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import defaultdict

n = int(input())
V = list(map(int, input().split()))

if len(set(V)) == 1:
    print(n // 2)
    exit()

d0, d1 = defaultdict(int), defaultdict(int)

for i, v in enumerate(V):
    if i % 2 == 0:
        d0[v] += 1
    else:
        d1[v] += 1

d0_ = sorted(d0.items(), key=lambda x: -x[1])
d1_ = sorted(d1.items(), key=lambda x: -x[1])

a0, n0 = d0_[0]
a1, n1 = d1_[0]

if a0 != a1:
    ans = n - n0 - n1
else:
    if n0 > n1:
        m1 = d1_[1][1]
        ans = n - n0 - m1
    elif n0 < n1:
        m0 = d0_[1][1]
        ans = n - m0 - n1
    else:
        m0 = d0_[1][1]
        m1 = d1_[1][1]
        ans = n - n0 - max(m0, m1)

print(ans)

Measured memory_bytes: 22492
import datetime
time_std=datetime.date(2012, 12, 21)
while 1:
    n=input()
    if n=="#":break
    n_len=list(map(int,n.split(".")))
    if len(n_len)==3:
        year_keep=0
        while n_len[0]>9999:
            year_keep+=1
            n_len[0]-=400
        ans=[0]*5
        cal_date=datetime.date(n_len[0], n_len[1], n_len[2])
        date_dif=(cal_date-time_std).days+year_keep*146097
        ans[0]=str(date_dif//(20*20*18*20)%13)
        ans[1]=str(date_dif//(20*18*20)%20)
        ans[2]=str(date_dif//(18*20)%20)
        ans[3]=str(date_dif//(20)%18)
        ans[4]=str(date_dif%(20))
        print(".".join(ans))
    if len(n_len)==5:
        ans=[0]*3
        past_date=(((n_len[0]*20+n_len[1])*20+n_len[2])*18+n_len[3])*20+n_len[4]
        year_keep=past_date//146097
        past_date=past_date%146097
        ans=list(map(str,str(datetime.date(2012, 12, 21)+datetime.timedelta(days=past_date)).split("-")))
        ans[0]=str(int(ans[0])+year_keep*400)
        ans[1]=str(int(ans[1]))
        ans[2]=str(int(ans[2]))
        print(".".join(ans))


Measured memory_bytes: 6068
/* kadai2_3
   reo012 */

#include <stdio.h>

int main(void){
  int n, a;
  // 二つの整数(一列のマス数、白マス数)n,aを受け取り
  scanf("%d", &n);
  scanf("%d", &a);
  // 黒く塗るマス数を計算し、出力
  printf("%d\n", n*n-a);
  
  return 0;
}


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

int main(){
    string s,ans="TBD";
    int y,m,d;
    cin >> s;
    y = stoi(s.substr(0,4));
    m = stoi(s.substr(5,2));
    d = stoi(s.substr(8,2));
    if(y<2019) ans = "Heisei";
    else if(y==2019) {
        if(m<4) ans = "Heisei";
        else if(m==4&&d<=30) ans = "Heisei";
    }
    cout << ans << endl;
    return 0;
}

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


const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;

bool is_prime(int n){
	for(int i=2;i*i<=n;i++){
		if(n%i==0) return false;
	}
	return true;
}

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

	vector<int> x;

	for(int i=2;i<=n;i++) {
		if(is_prime(i)) {
			int t=0;
			int s=i;
			int b = n/s;
			while(b > 0){
				t += b;
				s *= i;
				b = n/s;
			}
			x.push_back(t);
			//cout<<i<<" : "<<t<<endl;
		}
	}
	int ans=1;
	for(int v:x) {
		ans *= v+1;
		ans %= MOD;
	}

	cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int h, w;
char c[110][110];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> h >> w;
    rep(i, 0, h) rep(j, 0, w) cin >> c[i][j];
    vector<int> a, b;
    rep(i, 0, h) {
        bool flag = false;
        rep(j, 0, w) {
            if (c[i][j] == '#') flag = true;
        }
        if (!flag) a.pb(i);
    }
    rep(i, 0, w) {
        bool flag = false;
        rep(j, 0, h) {
            if (c[j][i] == '#') flag = true;
        }
        if (!flag) b.pb(i);
    }
    rep(i, 0, h) {
        if (find(all(a), i) != a.end()) continue;
        rep(j, 0, w) {
            if (find(all(b), j) != b.end()) continue;
            cout << c[i][j];
        }
        cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
using namespace std;
 
map< pair<int,long long>, int>  dp;
vector< long long > e;
 	
//int dp[51][51][51][51][2];
 
void gen_pattern(int pos,int r,long long v){
	if( pos >= 10 ){
		if( r == 0 ){
			e.push_back( v );
		}
		return;
	}
	for(int i = 0 ; r - pos * i >= 0 ; i++){
		gen_pattern(pos+1,r - pos*i,v+((long long)(i)<<((pos-1)*7)));
	}
}
 
int view(long long v){
	for(int i = 0 ; i < 9 ; i++){
		cout << (v >> (7*i) & 127) <<" ";
	}
	cout << endl;
}

int dfs(int pos,long long v){
	if( pos >= e.size() ) return 0;
	if( dp.count(make_pair(pos,v)) ) return dp[make_pair(pos,v)];
	long long V = v;
	int ans = 0 , c = 0;
	while(1){
		ans = max( dfs(pos+1,v) + c , ans);
		c++;
		bool f = true;
		for(int i = 0 ; i < 9 ; i++){
			int s = v >> (7*i) & 127;
			int x = e[pos] >> (7*i) & 127;
			if( s < x ){
				f = false;
				break;
			}
		}
		if( !f ) break;
		v -= e[pos];
	}
	v = V;
	return dp[make_pair(pos,V)] = ans;
}
 
 

int main(){
	int n;
	gen_pattern(1,10,0);
	while(cin >> n && n){
		vector<char> v(10);
		for(int i = 0 ; i < n ; i++){
			int t;
			cin >> t;
			v[t]++;
		}
		int greedy = 0;
		for(int i = 1 ; i < 5 ; i++){
			int u = min(v[i],v[10-i]);
			greedy += u;
			v[i] -= u; 
			v[10-i] -= u;
		}
		greedy += v[5] / 2;
		v[5] %= 2;
		long long enc = 0;
		for(int i = 1 ; i < 10 ; i++){
			enc += (long long)(v[i]) << (7 * (i-1));
		}
		dp.clear();
		cout << dfs(0,enc)+greedy << endl;
	}
}

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

using namespace std;

void rotate90(string *Asqu, string *Bsqu)
{
	for(int k = 0; k < 8; k++)
	{
		string sent;
		for(int i = 7; i >= 0; i--)
		{
			sent += Asqu[i][k];
		}	
		Bsqu[k] = sent;
	}
}

void printC(string *Asqu)
{
	for(int i = 0; i < 8; i++)
	{
		cout << Asqu[i] << endl;
	}
}

int main()
{
	string Asqu[16], Bsqu[16];

	for(int i = 0; i < 8; i++)
	{
		cin >> Asqu[i];
	}
	rotate90(Asqu, Bsqu);
	puts("90");
	printC(Bsqu);

	rotate90(Bsqu, Asqu);
	puts("180");
	printC(Asqu);

	rotate90(Asqu, Bsqu);
	puts("270");
	printC(Bsqu);
	
}

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

int main(void)
{
	int i,n,count;
	char s[105],temp[105];

	scanf("%d",&n);
	scanf("%s",s);

	count = strlen(s);

	if(n < count){
		for(i=0;i<n;i++){
			temp[i]=s[i];
		}
		for(;i<n+3;i++){
			temp[i]= '.';
		}

		temp[i] = '\0';
		strcpy(s,temp);
	}

	printf("%s\n",s);

	return 0;
}


Measured memory_bytes: 1636
#include<bits/stdc++.h>
using namespace std;
int main(void){
    string x,y;
    cin>>x>>y;
    int len_x=x.size();
    int len_y=y.size();
    int dp[len_x+1][len_y+1];
    for(int i=0;i<=len_y;i++)
    dp[0][i]=0;
    for(int i=0;i<=len_x;i++)
    dp[i][0]=0;
    for(int i=1;i<=len_x;i++){
        for(int j=1;j<=len_y;j++){
            if(x[i-1]==y[j-1])
            dp[i][j]=1+dp[i-1][j-1];
            else
            dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
        }
    }
    int i=len_x;
    int j=len_y;
    string ans;
    while(i>0&&j>0){
        if(x[i-1]==y[j-1])
        {
            ans+=x[i-1];
            i=i-1;
            j=j-1;
        }
        else{
            if(dp[i][j-1]>dp[i-1][j])
            j=j-1;
            else
            i=i-1;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}

Measured memory_bytes: 35456
#include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define EPS 1e-08

int N, A;
int x[60];
long long dp[60][60][2600];

int main() {
  cin >> N >> A;
  for (int i=0; i<N; i++) {
    cin >> x[i];
  }
  dp[0][0][0] = 1;
  for (int i=1; i<=N; i++) {
    for (int j=0; j<N; j++) {
      for (int k=0; k<2600; k++) {
        dp[i][j][k]          += dp[i-1][j][k];
        dp[i][j+1][k+x[i-1]] += dp[i-1][j][k];
      }
    }
  }
  long long ans = 0;
  for (int j=1; j<=N; j++) {
    ans += dp[N][j][j*A];
  }
  cout << ans << "\n";
  return 0;
}



Measured memory_bytes: 52224
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
cntA = Counter(A)

if len(A) % 2 == 1:
    if cntA[0] != 1:
        print(0)
        exit()
    cnt = 1
    for i in range(2, N, 2):
        if cntA[i] != 2:
            print(0)
            exit()
        cnt += 2
    if cnt != N:
        print(0)
        exit()
else:
    cnt = 0
    for i in range(1, N, 2):
        if cntA[i] != 2:
            print(0)
            exit()
        cnt += 2
    if cnt != N:
        print(0)
        exit()

print(pow(2, N // 2, 10**9 + 7))


Measured memory_bytes: 14820
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, A[22], B[22], C[22], S = 0;

  std::cin >> N;

  for (int i = 0; i < N; i ++)
    std::cin >> A[i];

  for (int i = 0; i < N; i ++)
    std::cin >> B[i];

  for (int i = 0; i < N - 1; i ++)
    std::cin >> C[i];

  for (int i = 0; i < N; i ++) {
    S += B[A[i] - 1];

    if (i < N - 1)
      if (A[i + 1] == A[i] + 1)
        S += C[A[i] - 1];
  }

  std::cout << S << std::endl;

  return 0;
}


Measured memory_bytes: 256
/*input
3 6 11 50
*/
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    while (cin >> n) {
        int a = n / 2;
        int b = n / 2;
        if (n % 2) a++;

        cout << a * b << '\n';
    }
    return 0;
}

Measured memory_bytes: 764
import re
s=input().replace('?','.')
t=input()
ans='UNRESTORABLE'
for i in range(len(s)-len(t),-1,-1):
    if re.match(s[i:i+len(t)],t):
        s=s.replace('.','a')
        ans=s[:i]+t+s[i+len(t):]
        break
print(ans)

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

class Program
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
       
        if(N==1)
        {
            Console.WriteLine(1);
        }
        else if(N==2)
        {
            Console.WriteLine(8);
        }
        else
        {
            Console.WriteLine(N*N*N);
        }

        
    }
}


Measured memory_bytes: 11092
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(M)]

g = [0 for i in range(N+1)]

for a, b in AB:
    if g[a] < H[b-1]:
        g[a] = H[b-1]
    if g[b] < H[a-1]:
        g[b] = H[a-1]

ans = 0
for i in range(1, N+1):
    if g[i] < H[i-1]:
        ans += 1

print(ans)

Measured memory_bytes: 98872
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define hell  1000000007
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb   push_back


int main()
{
	ios;
	ll n,k,s=0;
	cin>>n>>k;
	ll a[n+10];
	for(ll i=0;i<n;i++)cin>>a[i];
		sort(a,a+n);
	for(ll i=0;i<k;i++)s+=a[i];
		cout<<s;
}

Measured memory_bytes: 3648
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  char c;
  cin>>c;
  c++;
  cout<<c<<endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

var rdr = bufio.NewReaderSize(os.Stdin, 1024)

func readLine() string {
	buf := make([]byte, 0, 1024)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func atoi(s string) int {
	i, e := strconv.Atoi(s)
	if e != nil {
		panic(e)
	}
	return i
}

func readStringArray() []string {
	return strings.Split(strings.TrimSpace(readLine()), " ")
}

func readInt() int {
	return atoi(readLine())
}

func readIntArray() []int {
	var a []int
	sa := readStringArray()
	for _, s := range sa {
		a = append(a, atoi(s))
	}
	return a
}

func min(lhs, rhs int) int {
	if lhs < rhs {
		return lhs
	}
	return rhs
}

func max(lhs, rhs int) int {
	if lhs > rhs {
		return lhs
	}
	return rhs
}

func main() {
	xyzk := readIntArray()
	x := xyzk[0]
	y := xyzk[1]
	z := xyzk[2]
	k := xyzk[3]
	a := readIntArray()
	b := readIntArray()
	c := readIntArray()
	var abScore []int
	for i := 0; i < x; i++ {
		for j := 0; j < y; j++ {
			abScore = append(abScore, a[i]+b[j])
		}
	}
	sort.Ints(abScore)
	var abcScore []int
	cnt := 0
	for i := len(abScore) - 1; i >= 0; i-- {
		for j := 0; j < z; j++ {
			abcScore = append(abcScore, abScore[i]+c[j])
		}
		cnt++
		if cnt > k {
			break
		}
	}
	sort.Ints(abcScore)
	cnt = 0
	for i := len(abcScore) - 1; i >= 0; i-- {
		fmt.Println(abcScore[i])
		cnt++
		if cnt >= k {
			break
		}
	}
}


Measured memory_bytes: 116480
S = input()
Q = int(input())
Query = [list(map(str,input().split())) for _ in range(Q)]
from collections import deque 
flag = True
f = ""
l = ""
#print(Query)
for i in Query:
    if i[0]=="1":
        if flag:
            flag = False
        else:
            flag = True
    else:
        if (flag==True and i[1]=="1") or (flag==False and i[1]=="2"):
            f += i[2] 
        elif (flag==True and i[1]=="2") or (flag==False and i[1]=="1"):
            l += i[2]
S = f[::-1]+S+l
if flag:
    print(S)
else:
    print(S[::-1])

Measured memory_bytes: 40948
using System;
using System.Linq;

class B
{
	static void Main()
	{
		Console.ReadLine();
		Console.WriteLine(Console.ReadLine().Split().Select(int.Parse).All(x => x % 2 != 0 || x % 3 == 0 || x % 5 == 0) ? "APPROVED" : "DENIED");
	}
}


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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  char diff = 'A' - 'a';
  printf("%c%c%c\n", a[0] + diff, b[0] + diff, c[0] + diff);
  return 0;
}

Measured memory_bytes: 256
class Main{
    public static void main(String[] a){
	for (Integer first = 1; first < 10; first++) {
//			System.out.println("first:" + first);
			for (Integer last = 1; last < 10; last++) {
//				System.out.println("last:" + last);
				
				// 掛け算結果
				Integer multiple = first*last;
//				System.out.println("multiple:" + multiple);
				System.out.println(first + "x" + last + "=" + multiple);
			}
		}
    }
}


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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  ll a,b,t;
  cin >> a >> b >> t;
  cout << (t/a) * b << endl;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
string s,t,a;
int l;
int main()
{
	getline(cin,s);
	getline(cin,t);
	if (s==t)
	{
		printf("Yes\n");
		return 0;
	}
	l=s.size();
	for (int i=1;i<l;++i)
	{
		a=s.substr(l-i,i);
		a+=s.substr(0,l-i);
		if (a==t)
		{
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c = LI()
    if b - a == c - b:
        print("YES")
    else:
        print("NO")
    return

#B
def B():
    o = S()
    e = S()
    for i in range(len(e)):
        print(o[i] + e[i], end="")
    if len(e) != len(o):
        print(o[-1], end="")
    print()
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()


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

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

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

g1=[1,1]
for i in range(2,N+1):
    g1.append(g1[-1]*i%mod)
    
lst=[0]
for i in range(1,N+1):
    lst.append((lst[-1]+inv[i])%mod)
    
ans=0
for i in range(N):
    a=A[i]
    
    num=a*g1[N]*(lst[i+1]+lst[N-i]-1)%mod
    ans=(ans+num)%mod

print(ans)

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

enum class Sex {
    Male,
    Female,
};

Sex query(ll num)
{
    cout << num << endl;
    string s;
    cin >> s;
    if (s[0] == 'V') {
        exit(EXIT_SUCCESS);
    }
    return s[0] == 'M' ? Sex::Male : Sex::Female;
}

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

    ll top = 0;
    ll bottom = N;
    auto last_s = query(0);
    auto last_query_num = 0;

    while (true) {
        auto mid = (top + bottom) / 2;
        auto s = query(mid);
        if (abs(mid - last_query_num) % 2 == 0) {
            if (last_s == s) {
                if (mid - last_query_num > 0) {
                    top = mid;
                } else {
                    bottom = mid;
                }
            } else {
                if (mid - last_query_num > 0) {
                    bottom = mid;
                } else {
                    top = mid;
                }
            }
        } else {
            if (last_s == s) {
                if (mid - last_query_num > 0) {
                    bottom = mid;
                } else {
                    top = mid;
                }
            } else {
                if (mid - last_query_num > 0) {
                    top = mid;
                } else {
                    bottom = mid;
                }
            }
        }
        last_query_num = mid;
        last_s = s;
    }
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


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

int main() {
  long N;
  cin>>N;
  vector<long> a(N);

  for(int i=0;i<N;i++) cin>>a[i];
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  long ans=0;
  for(int i=0;i<N-1;i++){
    ans+=a[(i+1)/2];
  }
  cout<<ans<<endl;
  }


Measured memory_bytes: 4820
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using i64 = int64_t;

int H, W, N, a[10101];

void next(int& x, int& y) {
    if (x % 2 == 0) {
        if (y == W-1) {
            ++x;
        } else {
            ++y;
        }
    } else {
        if (y == 0) {
            ++x;
        } else {
            --y;
        }
    }
}

int main() {
    cin >> H >> W >> N;
    for (int j = 0; j < N; ++j) cin >> a[j];

    int b[101][101];
    int x = 0, y = 0;
    for (int j = 0; j < N; ++j) {
        for (int m = 0; m < a[j]; ++m) {
            b[x][y] = j+1;
            next(x, y);
        }
    }

    for (int j = 0; j < H; ++j) {
        for (int k = 0; k < W; ++k) {
            if (k > 0) cout << " ";
            cout << b[j][k];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<set>
using namespace std;

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

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const long long mod=2019;
#define ll long long

int main(){
  int n;
  cin>>n;
  vector<string>s(n);
  rep(i,n){
    cin>>s[i];
    sort(s[i].begin(),s[i].end());
  }
  sort(s.begin(),s.end());
  ll ans=0;
  ll x[100000]={};
  ll num=0;
  rep(i,n-1){
    if(s[i]==s[i+1]){
      x[num]++;
    }
    else{
      num++;
    }
  }
  for(int i=0;i<=num;i++){
    if(x[i]){
      ans+=((x[i]*(x[i]+1))/2);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;


string str;
int cnt[200005][27];
vector<int> bit[200005];
int dp[200005];
int bs[200005];
vector<int> bits;
int dp2[200005];

int main(void){
	cin >> str;
	int n=str.size();
	for(int i=0;i<n;i++){
		cnt[i+1][str[i]-'a']++;
	}
	for(int i=0;i<26;i++){
		for(int j=0;j<n;j++){
			cnt[j+1][i]+=cnt[j][i];
		}
	}
	for(int i=0;i<n;i++){
		int bi=0;
		for(int j=0;j<26;j++){
			if(cnt[i+1][j]%2==1)bi+=(1<<j);
		}
		bs[i+1]=bi;
		bits.push_back(bi);
	}
	bits.push_back(0);
	sort(bits.begin(),bits.end());
	bits.erase(unique(bits.begin(),bits.end()),bits.end());
	bit[0].push_back(0);
	for(int i=0;i<n;i++){
		int v=lower_bound(bits.begin(),bits.end(),bs[i+1])-bits.begin();
		bit[v].push_back(i+1);
	}
	for(int i=0;i<=n;i++){
		dp[i]=n;
	}
	dp[0]=0;
	for(int i=0;i<bits.size();i++){
		dp2[i]=n;
	}
	dp2[0]=0;
	for(int i=1;i<=n;i++){
		int nbit=bs[i];
		int nbit2=lower_bound(bits.begin(),bits.end(),bs[i])-bits.begin();
		if(nbit2!=bits.size() && bits[nbit2]==nbit){
			dp[i]=min(dp2[nbit2]+1,dp[i]);
		}
		for(int j=0;j<26;j++){
			int nnbit=bs[i];
			if(nnbit>>j & 1){
				nnbit-=1<<j;
			}else{
				nnbit+=1<<j;
			}
			int nnbit2=lower_bound(bits.begin(),bits.end(),nnbit)-bits.begin();
			if(nnbit2==bits.size() || bits[nnbit2]!=nnbit)continue;
			dp[i]=min(dp[i],dp2[nnbit2]+1);
		}
		dp2[nbit2]=min(dp2[nbit2],dp[i]);
	}
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 35576
import java.util.*;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		String str = "";
		int[] cnt = new int[26];
		
		while(sc.hasNext()) {
			str = sc.nextLine();
			str = str.toLowerCase();
			char[] c = str.toCharArray();
			for(int i = 0; i < c.length; i++) {
				if('a' <= c[i] && c[i] <= 'z') {
					cnt[c[i] - 'a']++;
				}
			}
		}
		for(int i = 0; i < 26; i++) {
			System.out.println(((char)(i + 'a')) + " : " + cnt[i]);
		}
		//System.out.println();
	}
}

Measured memory_bytes: 26168
#include<iostream>
using namespace std;
int main(){
  int a[3]={1}; 
  char ch[3]={'A','B','C'};
  char d,e,f;
  while(cin>>d>>e>>f)
    for(int i=0;i<3;i++)
      for(int j=0;j<3;j++)
	  if(d==ch[i]&&f==ch[j])
	    swap(a[i],a[j]);

  for(int i=0;i<3;i++)
    if(a[i]==1)
	cout<<ch[i]<<endl;
  return 0;
}

Measured memory_bytes: 1132
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <algorithm>
#include <set>
#include <queue>

using namespace std;
#define ll long long

int main()
{
    //freopen("aa_input.txt", "r", stdin);
    int test=1;
    //cin>>test;

    while(test--){
       int n, k;
       cin>>n>>k;
       int val;
       int ans = 1, sum = 0;
       for(int i=0; i<n; i++){
           cin>>val;
           sum += val;
           if(sum <= k) ans++;
           
       }
       cout<<ans<<endl;
    }
    return 0;
}
/*

riaadmorshed@gmail.com

*/

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n,x;
	scanf("%d%d",&n,&x);
	int consit=0;
	while(n!=0||x!=0){
		for(int i=1;i<=n;i++){
			for(int j=i+1;j<=n;j++){
				for(int k=j+1;k<=n;k++){
					if(i!=j&&i!=k&&j!=k){
						if(i+j+k==x)consit++;
					}
				}
			}
		}
		printf("%d\n",consit);
		scanf("%d%d",&n,&x);
		consit=0;
	}
	return 0;
}


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

using namespace std;

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

int main() {
    int n, cont = 0;

    scanf("%d", &n);

    for (int i=1; i<n; ++i) {
        cont += ((n-1)/i);
    }

    printf("%d\n", cont);

    return 0;
}

Measured memory_bytes: 3820
s = input()
s1 = int(s[:2])
s2 = int(s[2:])
if 0 < s1 < 13:
    if 0 < s2 < 13:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 0 < s2 < 13:
        print("YYMM")
    else:
        print("NA")



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

int64_t mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int64_t K;
    string S;
    cin >> S >> K;
    bool x = true;
    for (int i = 0; i < min((int64_t)S.size(),K); i++)
    {
        if (S[i] != '1')
        {
            cout << S[i];
            x = false;
            break;
        }
    }
    if(x)
        cout << 1;
}

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

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
    ll i, j, k;
    ll N;
    cin >> N;
    vll A(N);
    for(auto &e : A)
        cin >> e;
    priority_queue<ll> q;
    sort(A.rbegin(), A.rend());
    q.push(A[0]);
    ll ans = 0;
    for(i = 1; i < N; i++) {
        ans += q.top();
        q.pop();
        q.push(A[i]);
        q.push(A[i]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6860
N, A, B, C = map(int, input().split())

l_in = []
for i in range(N):
    num = int(input())
    l_in.append(num)


def dfs(cur, a_sum, b_sum, c_sum):
    if cur == N:
        return abs(A-a_sum)+abs(B-b_sum)+abs(C-c_sum)-30 if a_sum*b_sum*c_sum > 0 else 100000000

    pat0 = dfs(cur+1, a_sum, b_sum, c_sum)
    pat1 = dfs(cur+1, a_sum+l_in[cur], b_sum, c_sum)+10
    pat2 = dfs(cur+1, a_sum, b_sum+l_in[cur], c_sum)+10
    pat3 = dfs(cur+1, a_sum, b_sum, c_sum+l_in[cur])+10

    return min(pat0, pat1, pat2, pat3)


print(dfs(0, 0, 0, 0))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
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; }

long long n, W;
vector<long long> w(100100, 0);
vector<long long> v(100100, 0);
long long dp[110][100100];

int main() {
    cin >> n >> W;
    for(int i = 0;  i < n; ++i) {
        cin >> w.at(i) >> v.at(i);
    }

    for(int i = 0; i <= n; ++i) {
        for(int j = 0; j <= W; ++j) {
            dp[i][j] = 0;
        }
    }

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= W; ++j) {
            if(j+w.at(i) <= W) {
                chmax(dp[i+1][j+w.at(i)], dp[i][j]+v.at(i));
            }
            chmax(dp[i+1][j], dp[i][j]);
        }
    }

    cout << dp[n][W] << endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector<ll> vl;
typedef vector< vector<ll> > vvl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector< vii> vvii;

#define INF 1000000007
#define INFLL 1000000000000000000
#define esp 1e-9
#define PI 3.14159265

ll nMod = 1e9 + 7;

inline ll GCD(ll a, ll b) {while (b != 0) {ll c = a % b; a = b; b = c;} return a;};
inline ll LCM(ll a, ll b) {return (a / GCD(a,b)) * b;};

vector < int > a;
map < int , int > ma;

int dp [ 5100 ] [ 5100 ] = { 0 };
int rec ( int i, int j) {
     if (dp [i] [j] != 0 ) return dp [i] [j];
     int val = a [ i] * 2 -a [j];
     if (! ma.count (val)) return  2 ;
     int k = ma [val];
     int res = rec (k, i) + 1 ;
     return dp [i] [j ] = res;
}

void vietnakid () {
    int N; cin >> N;
    a.resize (N);
    for ( int i = 0 ; i <N; ++ i) cin >> a [i];
    sort (a.begin (), a.end ());
    
    for ( int i = 0 ; i <N; ++ i) ma [a [i]] = i;
     int res = 2 ;
     for ( int i = 0 ; i <N; ++ i) {
         for ( int j = i + 1 ; j <N; ++ j) {
            res = max (res, rec (i, j));
        }
    }
    cout << res << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie();
	// #ifdef LOCAL_KID
	// freopen("/Users/macbook/Desktop/MyCPPLibrary/input", "r", stdin);
	// freopen("/Users/macbook/Desktop/MyCPPLibrary/output", "w", stdout);
    // freopen("/Users/macbook/Desktop/MyCPPLibrary/error", "w", stderr);
	// #else
	// // online submission
	// #endif
	vietnakid();
 	// cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


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

int main(){
  int a;
 
    cin>>a;
 
  
  for(int i=a; i>=0;i--){
     for(int j =0;j<32 ;j++){
   if(i == j*j){
     cout << j*j <<endl;
     return 0;
   }
    if(i ==j*j*j){
      cout << j*j*j << endl;
      return 0;
    }
       if(i == j*j*j*j*j){
         cout << i << endl;
         return 0;
       }
       if( i == j*j*j*j*j*j*j){
         cout << i << endl;
         return 0;
       }
     }
  }
    return 0;
  }


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

string generateFormula(string str, int i) {
  bitset<9> bit = i;
  string ret = "";
  ret += str.at(0);
  for (int i=1; i<str.size(); i++) {
    if (bit.test(i-1)) {
      ret += '+';
    }
    ret += str.at(i);
  }
  return ret;
}

int64_t solve(string f) {
  int64_t sum = 0;
  int64_t n = 0;
  for (int i=0;i<20;i++) {
    if (f.at(i) =='+') {
      sum += n;
      n = 0;
    } else {
      n = n*10 + (f.at(i)-'0');
    }
    if (f.size()-1 == i) {
      sum += n;
      break;
    }
  }
  return sum;
}

int main() {
  string str;
  cin >> str;
  
  int bitnum = (int)str.size() - 1;
  int64_t sum=0;
  for (int i = 0; i < (1 << bitnum); i++) {
    sum += solve(generateFormula(str,i));
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int i=0,len1=0,len2=0;
            int state=0;
            int[] x1 = null,y1 = null;
            int[] x2=null,y2=null;
            
            while ((line = br.readLine()) != null) {
            	
            	if(line.equals("0"))break;
            	if(state==0){
            		len1=Integer.parseInt(line);
            		state=1;
            		i=0;
            		x1=new int[len1];
            		y1=new int[len1];
            	}else if(state==2){
            		len2=Integer.parseInt(line);
            		state=3;
            		i=0;
            		x2=new int[len2];
            		y2=new int[len2];
            	}else if(state==1){
            		String[] str=line.split(" ");
            		x1[i]=Integer.parseInt(str[0]);
            		y1[i]=Integer.parseInt(str[1]);
            		i++;
            		if(i==len1){
            			state=2;
            		}
            	}else if(state==3){
            		String[] str=line.split(" ");
            		x2[i]=Integer.parseInt(str[0]);
            		y2[i]=Integer.parseInt(str[1]);
            		i++;
            		if(i==len2){
	            		int x=x1[0],y=y1[0];
	            		int[] xmove=new int[len2];
	            		int[] ymove=new int[len2];
	            		int pit=0,storex=0,storey=0;
	            		for(int j=0;j<len2;j++){
	            			xmove[j]=x2[j]-x;
	            			ymove[j]=y2[j]-y;
	            		}
	            		for(int j=1;j<len2;j++){
	            			pit=0;
	            			for(int k=0;k<len1;k++){
	            				for(int l=0;l<len2;l++){
		            				if(x2[l]==(x1[k]+xmove[j])&&y2[l]==(y1[k]+ymove[j])){
		            					pit++;
		            				}
		            				if(pit==len1){
		            					storex=xmove[j];
		            					storey=ymove[j];
		            					break;
		            				}
		            			}
	            			}
	            			if(pit==len1){
	        					break;
	        				}
	            		}
	            		System.out.println(storex+" "+storey);
	            		state=0;
            		}
            	}
            }
        }
    }

}

Measured memory_bytes: 41032
#include <iostream>
#include <map>
#include <vector>
using namespace std;
using ll = long long;

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

int main() {
  int N;
  cin >> N;
  map<ll, int> ns;
  ll a;
  for(int i = 0; i < N; ++i) {
    cin >> a;
    ns[a]++;
  }
  vector<ll> as;
  for(auto n : ns) {
    for(int i = 0; i < n.second / 2; ++i) {
      as.push_back(n.first);
    }
  }
  if(as.size() < 2) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = 0;
  for(int i = 0; i < as.size() - 1; ++i) {
    for(int j = i + 1; j < as.size(); ++j) {
      chmax(ans, as[i] * as[j]);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6528
const lines=readlines(open("/dev/fd/0"))
let
    state=0
    global input
    input()=lines[state+=1]
end
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
intLine()=map(intSub,split(input()))
function main()
    s=input()
    print(count(c->c=='+',s)-count(c->c=='-',s))
end
main()

Measured memory_bytes: 110432