akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
int m,n,kk,d;
int convert(string s)
{
	if(s == "H") return 0;
	if(s == "D") return m+n+1;
	if(s[0] == 'C')
	{
		return (s[1]-'0');
	}
	if(s[0] == 'L')
	{
		int t = 0;
		for(int i=1;i<s.size();i++)
		{
			t = t*10+(s[i]-'0');
		}
		return m+t;
	}
}
int dp[64][110];
int main()
{
	while(1)
	{
		cin >> m >> n >> kk >> d; if(m == 0) return 0;
		vector<P>edge[110];
		int a[10];
		for(int i=0;i<m;i++)
		{
			cin >> a[i];
		}
		for(int i=0;i<d;i++)
		{
			string a;
			string b;
			int dd;
			cin >> a >> b >> dd;
			int s = convert(a);
			int t = convert(b);
			edge[s].pb(mp(t,dd));
			edge[t].pb(mp(s,dd));
		}
		for(int i=0;i<64;i++)
		{
			for(int j=0;j<110;j++)
			{
				dp[i][j] = INF;
			}
		}
		dp[0][0] = 0;
		while(1)
		{
			bool upd = 0;
			for(int i=0;i<(1<<m);i++)
			{
				for(int j=0;j<=n+m+1;j++)
				{
					for(int k=0;k<edge[j].size();k++)
					{
						int x = edge[j][k].fi;
						int y = edge[j][k].sc;
						int mask = i;
						int g = 0;
						if(1<=x && x<=m)
						{
							if(((mask >> (x-1))&1)) continue;
							mask |= (1<<(x-1));
							g = a[x-1];
						}
						if(dp[mask][x] > dp[i][j]+y*kk-g)
						{
							dp[mask][x] = dp[i][j]+y*kk-g;
							upd = true;
						}
					}
				}
			}
			if(!upd) break;
		}
		int res = INF;
		for(int i=0;i<(1<<m);i++) res = min(res,dp[i][m+n+1]);
		cout << res << endl;
	}
}

Measured memory_bytes: 1260
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;
typedef tuple<int,int,int> TP;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}
 
ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}
 
ll RS(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P < 0) {
        return 0;
    }
    if(P%2==0){
        ll t = RS(N, P/2, M);
        return t*t % M;
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    for(int i = 0;i < N;i++) {
        cin >> A.at(i) >> B.at(i);
    }
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    if(N % 2 == 0) {
        int left = A.at(N / 2 - 1) + A.at(N / 2);
        int right = B.at(N / 2 - 1) + B.at(N / 2);
        cout << right - left + 1 << endl;
    }
    else {
        cout << B.at(N / 2) - A.at(N / 2) + 1 << endl;
    }
}

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

struct Dice{
	int f[7];
	int n[100];
	int right[7][7] = { {0, 0, 0, 0, 0, 0, 0},
						{0, 0, 3, 5, 2, 4, 0},
						{0, 4, 0, 1, 6, 0, 3},
						{0, 2, 6, 0, 0, 1, 5},
						{0, 5, 1, 0, 0, 6, 2},
						{0, 3, 0, 6, 1, 0, 4},
						{0, 0, 4, 2, 5, 3, 0} };
	
	void move(char dir){
		int sw;
		switch(dir){
		case 'E':
			sw = f[1];
			f[1] = f[4];
			f[4] = f[6];
			f[6] = f[3];
			f[3] = sw;
			break;
		case 'N':
			sw = f[1];
			f[1] = f[2];
			f[2] = f[6];
			f[6] = f[5];
			f[5] = sw;
			break;
		case 'S':
			sw = f[1];
			f[1] = f[5];
			f[5] = f[6];
			f[6] = f[2];
			f[2] = sw;
			break;
		case 'W':
			sw = f[1];
			f[1] = f[3];
			f[3] = f[6];
			f[6] = f[4];
			f[4] = sw;
			break;
		}
	}
	int getright(int up, int front){
		return f[right[up][front]];
	}
};

int main() {
	Dice dice;
	for(int i = 1; i <= 6; ++i){
		cin >> dice.f[i];
		dice.n[dice.f[i]] = i;
	}
	int n;
	cin >> n;
	int up, front;
	for(int i = 0; i < n; ++i){
		cin >> up; cin >> front;
		cout << dice.getright(dice.n[up], dice.n[front]) << endl;
	}
	return 0;
}

Measured memory_bytes: 3096
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#l = list(map(int, input().split()))


s = input()

n = len(s)
s1 = s[0:(n-1)//2]
s2 = s[(n+3)//2-1:n+1]

if s == s[::-1]:
    if s1 == s1[::-1]:
        if s2 == s2[::-1]:
            print("Yes")
            exit()

print("No")
    



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

int main() {
    int n, ans=0;
    cin >> n;
    vector<int> a(n);
    vector<int> odd(n);
    rep(i,n){
        cin >> a.at(i);
    }
    for(int j=0; j<n; j=j+2){
        if(a.at(j)%2==1){
            ans=ans+1;
        }
    }
    cout << ans << endl;
}


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

int main() {
    using namespace std;
    string N;
    cin >> N;
    unsigned long K;
    cin >> K;
    cout << [rec_impl = [](auto f, auto beg, auto edn, unsigned long K) -> unsigned long {
        if(K == 0)return 1;
        string N(beg, edn);
        if(N.size() < K)return 0;
        unsigned long c{1};
        for(unsigned long i{1}; i < K; ++i)(c *= 9 * (N.size() - i)) /= i;
        return ((N[0] - 49) * K + 9 * (N.size() - K)) * c / K + f(f, find_if_not(N.begin() + 1, N.end(), [](auto t){return t == '0';}), N.end(), K - 1);
    }](string N, unsigned long K){return rec_impl(rec_impl, N.begin(), N.end(), K);}(N, K) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int cnt=0;
  string s;
  cin>>s;
  sort(s.begin(),s.end());
  for(int i=0;i<s.size()-1;i++){
  	if(s.at(i)==s.at(i+1)) cnt++;
  }
  if(cnt==0) cout<<"yes"<<endl;
  else cout<<"no"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int v, e, r;
const long long INF = 1e18;
const int V_MAX = 100010;
struct edge{
    int to;
    long long cost;
};
vector<edge> G[V_MAX];
long long D[V_MAX];

void dijkstra(int start){
    priority_queue<P, vector<P>, greater<P>> q;
    for(int i = 0; i < v; i++){
        D[i] = INF;
    }
    D[start] = 0;
    q.push({start, 0});

    while(!q.empty()){
        P p = q.top();
        q.pop();
        int now = p.first;
        if(D[now] < p.second) continue;
        for(int i = 0; i < G[now].size(); i++){
            edge e = G[now][i];
            if(D[e.to] > D[now] + e.cost){
                D[e.to] = D[now] + e.cost;
                q.push({e.to, D[e.to]});
            }
        }
    }
}

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

    cin >> v >> e >> r;
    for(int i = 0; i < e; i++){
        int s, t, d;
        cin >> s >> t >> d;
        G[s].push_back({t, d});
    }

    dijkstra(r);

    for(int i = 0; i < v; i++){
        if(D[i] == INF) cout << "INF" << endl;
        else cout << D[i] << endl;
    }


    return 0;
}


Measured memory_bytes: 25808
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF (long long) 1e18//1234567890987654321
#define INF 1234567890
#define pb push_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN 300006
#define MAXK 26
#define MAXX 15000006
#define ll long long int
#define ld long double
#define rep0(kk, l1, l2)for(ll kk = l1; kk < l2; kk++)
#define rep1(kk, l1, l2)for(ll kk = l1; kk <= l2; kk++)
#define foritr(itr, A) for(set<ll>::iterator itr = A.begin(); itr != A.end(); itr++)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ii++)
#define cr(x) cerr << #x << " = " << x << "\n";
#define crA(x, A) cerr << #x << " = " << A[x] << "\n";
#define spacing if(db)cout << " ";
#define mmst(x, v) memset((x), v, sizeof ((x)));
#define bg(ms) (*ms.begin())
#define ed(ms) (*prev(ms.end(), 1))
#define addedge(a, b, c, v) v[(a)].pb(pi((b), (c))); v[(b)].pb(pi((a), (c)))
#define ph push
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n, w, dp[100006+1];
vector <pi> items;
int main()
{
	cin >> n >> w;
	FOR(i,0,n)
	{
		ll w, v;
		cin >> w >> v;
		items.emplace_back(w, v);
	}
	FOR(i,0,100006) dp[i] = LLINF;
	dp[0] = 0;
	for(auto i : items)
	{
		ll w = i.f, v = i.s;
		for(ll j = 100006-1; j >= v; j--)
		{
			if(dp[j-v] != LLINF) dp[j] = min(dp[j], dp[j-v] + w);
		}
	}
	ll ans = 0;
	FOR(i,0,100006)
	{
		if(dp[i] <= w) ans = max(ans, i);
	}
	cout << ans << "\n";
}


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

string S;

int main(void) {

	cin >> S;

	int N = S.size();

	int ans = 0;
	int R = 0;
	int B = 0;

	for (int i = N - 1; i >= 0; i--) {
		if (S[i] == '1') { if (R > 0) { R--; ans += 2; } else { B++; } }
		else { if (B > 0) { B--; ans += 2; } else { R++; } }
	}

	cout << ans << endl;

	//system("pause");
	return 0;
}

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

int main(){
  int N=100000;
  vector<int> P(N+1,1);
  P[0]=0;
  P[1]=0;
  for(int i=2;i*i<=N;i++){
    if(P[i]>0){
      for(int j=2*i;j<=N;j+=i){
        P[j]=0;
      }
    }
  }
  vector<int> L(N+1,0);
  for(int i=3;i<=N;i++){
    L[i]=L[i-1]+P[i]*P[(i+1)/2];
  }
  int Q,r,l;
  cin >> Q;
  for(int i=0;i<Q;i++){
    cin >> l >> r;
    cout << L[r]-L[l-1] << endl;
  }
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <complex>	// require complex func
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

// deq notes ½Êô½É¨¯éxNgZ http://www.deqnotes.net/acmicpc/2d_geometry/
typedef complex<double> P;
#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)
// àÏ (dot product) : a&#8901;b = |a||b|cosÆ
double dot(P a, P b) {
	return (a.real() * b.real() + a.imag() * b.imag());
}
// OÏ (cross product) : a~b = |a||b|sinÆ
double cross(P a, P b) {
	return (a.real() * b.imag() - a.imag() * b.real());
}
// _a,bð[_Æ·éüªÆ_cÆÌ£
double distance_ls_p(P a, P b, P c) {
  if ( dot(b-a, c-a) < EPS ) return abs(c-a);
  if ( dot(a-b, c-b) < EPS ) return abs(c-b);
  return abs(cross(b-a, c-a)) / abs(b-a);
}
struct T{
	P tp[3];
};
struct C{
	P cp;
	double r;
};

// ~ÌSªOp`ÉÜÜêé
bool is_cpint (T t, C c )
{
	vector <double> res (3, 0.0 );
	rep (i, 3 ){
		P A = t.tp[i], B = t.tp[(i+1) % 3], C = c.cp;
		res[i] = cross (B-A, C-A );
	} // end rep
	int plus = 0;
	rep (i, 3 ){
		if (res[i] > 0. || abs (res[i] ) < EPS ){
 			plus++;
		} // end if
	} // end rep

	return (plus == 3 || plus == 0 );
}

// ~ªOp`ÉÜÜêé
int is_cint (T t, C c )
{
	if (!is_cpint (t, c ) )
		return 0;

	int res = 0;
	rep (i, 3 ){
		P A = t.tp[i], B = t.tp[(i+1) % 3], C = c.cp;
		double d = distance_ls_p (A, B, C );
		if ( d > c.r || abs (d - c.r ) < EPS )
			res++;
	} // end rep

	return res;
}

// Op`ª~ÉÜÜêéê
int is_tinc (T t, C c )
{
	int res = 0;
	rep (i, 3 ){
		double d = abs (t.tp[i] - c.cp );
		if ( d < c.r || abs (d - c.r ) < EPS )
			res++;
	} // end rep
	
	return res;
}

// ~ªüªÆð··é
bool is_intersect (T t, C c )
{
	rep (i, 3 ){
		P A = t.tp[i], B = t.tp[(i+1) % 3], C = c.cp;
		double d = distance_ls_p (A, B, C );
		if ( d < c.r || abs (d - c.r ) < EPS )
			return true;
	} // end rep

	return false;	
}

int main()
{
	T t;
	C c;
	while (cin >> t.tp[0].real() >> t.tp[0].imag() && t.tp[0].real() != 0.0 && t.tp[0].imag() != 0.0 ){
		for (int i = 1; i < 3; i++ )
			cin >> t.tp[i].real() >> t.tp[i].imag();
		cin >> c.cp.real() >> c.cp.imag() >> c.r;

		int cint = is_cint (t, c );
		int tinc = is_tinc (t, c );
		if (cint == 3 ){	// ~ªOp`ÉÜÜêé	
			cout << 'a' << endl;
		}else 	
		if (tinc == 3 ){	// Op`ª~ÉÜÜêé
			cout << 'b' << endl;
		}else if (cint > 0 || tinc > 0 || is_intersect (t, c ) ){
			cout << 'c' << endl;
		}else{
			cout << 'd' << endl;
		} // end if
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
#if __has_include("noamoa_atcoder_lib.h")
#include "noamoa_atcoder_lib.h"
#else
#include <bits/stdc++.h>
#define endl '\n'
#define all(x) (x).begin(),(x).end()
namespace atcoder {
	using namespace std;
	using ll = long long;
	using intv = vector<int>;
	using charv = vector<char>;
	using boolv = vector<bool>;
	using floatv = vector<float>;
	using doublev = vector<double>;
	using stringv = vector<string>;

	constexpr ll MOD  = 1000000007;
	constexpr ll MOD9 = 1000000009;

	template<typename T>
	void sort(vector<T>& v){
		sort(all(v));
	}
	template<typename T>
	void sortInv(vector<T>& v){
		sort(all(v), greater<T>());
	}

	template<typename T>
	T sum(const vector<T>& v){
		T ret = 0;
		for(const auto& e : v) ret += e;
		return ret;
	}

	template<typename T>
	inline vector<T>& operator+=(vector<T>& v, const T& e){
		v.push_back(e);
		return v;
	}

	template<typename T>
	void in(vector<T>& v){
		for(auto& e : v) cin >> e;
	}

	template<typename T>
	istream& operator>>(istream &stream, vector<T>& v){
		for(auto& e : v) stream >> e;
		return stream;
	}

	template<typename T>
	void out(const vector<T>& v){
		for(const auto& e : v) cout << e << ' ';
		cout << endl;
	}

	template<typename T>
	void outln(const vector<T>& v){
		for(const auto& e : v) cout << e << endl;
	}

	void init(){
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}
using namespace atcoder;
#endif
#define _USE_MATH_DEFINES
int main(){
	init();

	double R;cin>>R;
	cout <<(acos(-1)*R*2);
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
#define MSG(a) cout << #a << " " << a << "\n";


int main(){
    int N,tmp = 0,check = 0; cin >> N;
    vint A(N),ans(N); REP(i,N) {
        cin >> A.at(i);
        ans.at(i) = 0;
    }
    for(int i = N-1; i >=0 ; i--){
        tmp = 0;
        for(int j = i; j < N; j += i + 1){
            
            tmp += ans.at(j);
        }
        if(tmp % 2 != A.at(i)){
            ans.at(i) = 1;
            check += 1;
        }
        
        
    }
    if(check % 2 != A.at(0)) cout << -1 << "\n";
  else{
    int M = accumulate(ALL(ans),0); cout << M << "\n";
    for(int i = 0; i < N; i++){

        if(ans.at(i) == 1) cout << i+1 << "\n";

    }
  }

}

Measured memory_bytes: 2432
N=int(input())
if N <= 9:
  print(N)
elif N <= 99:
  print(9)
elif N <= 999:
  print(N - 99 + 9)
elif N <= 9999:
  print(909)
elif N <= 99999:
  print(N - 9999 + 909)
else:
  print(90909)

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

int main()
{
	int N;
	cin >> N;
	
	vector<int> A, B, C;

	
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		A.push_back(a);
	}

	for (int i = 0; i < N; i++) {
		int b;
		cin >> b;
		B.push_back(b);
	}

	for (int i = 0; i < N-1; i++) {
		int c;
		cin >> c;
		C.push_back(c);
	}

	int ans = 0;
	int before;

	for (int i = 0; i < N ; i++) {


		ans += B[A[i] - 1];

		if (i > 0 && before + 1 == A[i]) {
			ans += C[before - 1];
		}
		before = A[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>
#include<utility>

#define P 1000000007

using namespace std;

long long power(long long n, long long x) {
  if(x == 0) return 1;
  if(x == 1) return n;
  if(x % 2 == 0) return power(n * n, x / 2);
  return n * power(n, x - 1);
}

int main() {

  long long n, m;
  cin >> n >> m;
  long long ans = 0;
  ans = (100 * (n - m) + 1900 * m) * power(2, m);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

    int n;
    cin >> n;

    int res = 0;

    for (int i = 0; i < n; i++){

        int t1, t2;

        cin >> t1 >> t2;

        res += (t2 - t1) + 1;
    }


    cout << res << endl;

    return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		// 入力フェーズ
    int N = int.Parse(Console.ReadLine());
    string A = Console.ReadLine();
    string B = Console.ReadLine();
    string C = Console.ReadLine();

    int step = 0; // A,B,Cを揃えるのに必要な最小ステップ

    // i文字目がそれぞれ、A=B=C:+0, A=B<>C:+1, A<>B<>C:+2
    for(int i=0; i<N; i++){
      if(A[i] != B[i] && A[i] != C[i] && B[i] != C[i]){
        // 全て異なる場合
        step += 2;
      }
      else if(A[i] != B[i] || A[i] != C[i] || B[i] != C[i]){
        // どれかが異なる場合
        step += 1;
      }
      // 全て同じ場合　+= 0;
    }
    
		//出力
		Console.WriteLine(step);
	}
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int main(){
 int n;
  cin>>n;
  int val[n];
  rep(i, n){
    cin>>val[i];}
  
  int dis[n];
  rep(i, n){
    dis[val[i]-1]=i;}
  
  int chmax=0;
  int cnt=0;
  rep(i, n){
    if(i==0){
      cnt++;
      continue ;}
    if(dis[i]<dis[i-1]){
      chmax=max(chmax,cnt);
      cnt=1;}
    if(dis[i]>dis[i-1]){cnt++;}
  }
  
  chmax=max(chmax,cnt);
  
  cout<<n-chmax<<endl;
 return 0;
  
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch ChatInACircle | diff ChatInACircle.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address ChatInACircle.cpp && ./a.out

/*

 7/5/2020

 5:09-5:23 WA
 5:41 give up

 9:46-10:03 figured out that I was misunderstanding the problem...


 https://twitter.com/hanseilimak/status/1279823328539078656

 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N;

void solve() {
  sort(A,A+N);
  LL res=A[N-1];
  priority_queue<LL> Q;
  Q.emplace(A[N-2]),Q.emplace(A[N-2]);
  for(int i=N-3; i>=0; --i) {
    res+=Q.top(),Q.pop();
    Q.emplace(A[i]),Q.emplace(A[i]);
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>N;
  REP(i,N) cin>>A[i];
  solve();

  return 0;
}


Measured memory_bytes: 6896
#include <iostream>

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

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

	rep(i, n) {
		long seq, max = 0, min = 0;
		cin >> seq;
		int num[8];

		rep(j, 8) {
			num[j] = seq % 10;
			seq = (seq - num[j]) / 10;
		}

		rep(j, 8) {
			rep(k, 8 - j) {
				if (num[j + k] > num[j]) {
					swap(num[j], num[j + k]);
				}
			}
		}

		rep(j, 8) {
			max *= 10;
			max += num[j];
			min *= 10;
			min += num[7 - j];
		}

		cout << max - min << endl;
	}
	return 0;
}

Measured memory_bytes: 2980
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int H, W, K; cin >> H >> W >> K;
    vector<string> S(H); for (auto &s : S) cin >> s;
    int ans = 1e9;
    for (int sp = 0; sp < (1 << (H - 1)); sp++) {
        vector<vector<int>> A;
        A.push_back({});
        for (int i = 0; i < H; i++) {
            A.back().push_back(i);
            if (i == H - 1) break;
            if (sp & (1 << i)) A.push_back({});
        }
        vector<int> B(A.size()), C(A.size());
        int num = A.size() - 1;
        for (int j = 0; j < W; j++) {
            for (int k = 0; k < A.size(); k++) {
                C[k] = 0;
                for (auto i : A[k]) if (S[i][j] == '1') C[k]++;
            }
            bool split = false;
            for (int k = 0; k < A.size(); k++) {
                if (C[k] > K) {
                    goto NEXT;
                } else if (B[k] + C[k] > K) {
                    split = true;
                }
            }
            if (split) {
                num += 1;
                for (int k = 0; k < A.size(); k++) B[k] = 0;
            }
            for (int k = 0; k < A.size(); k++) B[k] += C[k];
        }
        ans = min(ans, num);
        NEXT:;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int c1, c2, c3;
	int card[11];
	int i;
	int count;
	
	while (scanf("%d %d %d", &c1, &c2, &c3) != EOF){
		for (i = 1; i <= 10; i++){
			card[i] = 1;
		}
		
		c1 += c2;
		card[c1] = card[c2] = card[c3] = 0;
		count = 0;
		
		for (i = 1; i <= 10; i++){
			if (card[i] && c1 + i <= 20){
				count++;
			}
		}
		
		if (count > 3){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 580
#include<cstdio>

using namespace std;

int main(){
	int w, a, b; scanf("%d %d %d", &w, &a, &b);
	int res = 0;
	if(a + w < b) res = b - a - w;
	if(b + w < a) res = a - b - w;
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;





bool primenum(int p){
  int cnt=2;
  double root;

  if (p ==2){ return true;
  }
    
  if(p<2 or p%2==0){
    
      return false;
  }
  
  root = sqrt((double)p);
    
    while(cnt<=(int)root){

      if(p%cnt ==0){
	return false;
      }
      

      
      cnt++;
    }
    
    return true;
    
}




int main(){
  int prime[10001],i=0,ptot=0;
  
  while(cin>>prime[i]){
    i++;
  }

  

  for(int s=0;s<i;s++){
    if (primenum(prime[s])==true){
      ptot++;


    }
  }
      

  cout <<ptot<<endl;
  
  
  
    return 0;
}




Measured memory_bytes: 3104
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>


#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF		UINT32_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef long long ll;

int main()
{
	ll A = 0;
	ll B = 0;
	ll C = 0;

	cin >> A >> B >> C;

	if ( A <= C && C <= B ) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	// stop
	cin >> A;

	return 0;
}





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

// departing from [j], minimum cost to [n - 1]
int cost_min(int j, std::vector<int> &h, std::vector<int> &dp, int n, int k) {
	int ret;
	if(dp[j] > -1) ret = dp[j];
	else if(j == n - 1) ret = 0;
	else if(j >= n) ret = 20000000;	// invalid value
	else {
		std::vector<int> c(k);
		std::vector<int>::iterator itr;
		for(int i_k = 1; i_k <= k; ++i_k) {
			if(j + i_k >= n) c[i_k - 1] = 10000000;
			else c[i_k - 1] = cost_min(j + i_k, h, dp, n, k) + std::abs(h[j] - h[j + i_k]);
		}
		itr = std::min_element(c.begin(), c.end());
		ret = *itr;
	}
	dp[j] = ret;
	return ret;
}

int main(void) {
	// input
	int n, k;
	std::cin >> n >> k;
	std::vector<int> h(n);
	std::vector<int> dp(n);
	for(int i = 0; i < n; ++i) {
		std::cin >> h[i];
		dp[i] = -1;
	}
	
	// dp
	int cost = cost_min(0, h, dp, n, k);

	std::cout << cost << std::endl;

	return 0;
}



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

using namespace std;

constexpr int mod = 1e9 + 7;

int main(void) {
    string S;
    cin >> S;
    vector<char> R = {'R', 'U', 'D'};
    vector<char> L = {'L', 'U', 'D'};
    bool chk       = true;
    for (int i = 0; i < S.size(); i++) {
        if ((i + 1) % 2 == 1) {
            for (char c : R) {
                if (c == S[i]) chk = false;
            }
        } else {
            for (char c : L) {
                if (c == S[i]) chk = false;
            }
        }

        if (chk) {
            cout << "No" << endl;
            return 0;
        }
        chk = true;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 100100100100100100;
struct edge{ll from;ll to;ll cost;};
edge G[2000];ll d[1000],V,E;
bool BellmanFord_reverse(ll s){//正の閉路が検出されたらtrue
  ll i,j;bool ne[V] = {};
  fill(d,d+V,-inf);d[s] = 0;
  for(i=0;i<V-1;i++){
    for(j=0;j<E;j++){
      if(d[G[j].from]!=-inf && d[G[j].to]<d[G[j].from]+G[j].cost){
        d[G[j].to] = d[G[j].from]+G[j].cost;
      }
    }
  }
  for(i=0;i<V;i++){
    for(j=0;j<E;j++){
      if(d[G[j].from]!=-inf && d[G[j].to]<d[G[j].from]+G[j].cost) ne[G[j].to] = true;
      if(ne[G[j].from]) ne[G[j].to] = true;
    }
  }
  return ne[V-1];
}
int main(){
  ll i;
  scanf("%lld%lld",&V,&E);
  for(i=0;i<E;i++){
    scanf("%lld%lld%lld",&G[i].from,&G[i].to,&G[i].cost);
    G[i].from--;G[i].to--;
  }
  if(BellmanFord_reverse(0)) printf("inf\n");
  else printf("%lld\n",d[V-1]);
}

Measured memory_bytes: 256
class UnionFind
    def initialize(n)
        @have_node_num = Array.new(n, -1)
    end
    def findSet(x)
        return x if @have_node_num[x] < 0
        @have_node_num[x] = findSet(@have_node_num[x])
        return @have_node_num[x]
    end
    def link(x, y)
        return if x == y
        x, y = y, x if @have_node_num[x] > @have_node_num[y]
        @have_node_num[x] += @have_node_num[y]
        @have_node_num[y] = x
    end
    def unite(x, y)
        link(findSet(x), findSet(y))
    end
    def same(x, y)
        findSet(x) == findSet(y)
    end
    def size(idx)
        return -@have_node_num[findSet(idx)]
    end
end

n, m = gets.chomp.split.map(&:to_i)
uf = UnionFind.new(n)

m.times do
    a, b = gets.chomp.split.map(&:to_i)
    uf.unite(a-1, b-1)
end

ans = 0

n.times do |i|
    tmp = uf.size(i)
    ans = tmp if tmp > ans
end

puts ans

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    set<int> S;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        S.insert(a);
    }
    cout << S.size() << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  int count=0;
  
  int x=S.size()-1;
   for(int i=0;i<S.size()/2;i++){
     if(S.at(i)!=S.at(x-i)){
       count++;}
   }
  
    
  cout<<count<<endl;
}

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

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define lp(i, a, b) for (int i=a; i<(b); i++)
#define lpd(i,a,b) for (int i = (b)-1; i >= a; i--)
	
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

vector<int> parent;
vector<ll> size;

int find_set(int v){
    if (v == parent[v]) return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b){
    a = find_set(a);
    b = find_set(b);
    if (a!= b){
        if (size[a] < size[b])
            swap(a, b);
        size[a] += size[b];
        parent[b] = a;
    }
}

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin>>n>>m;

    parent.resize(n+1);
    size.resize(n+1);

    lp(i, 1, n+1){
        size[i] = 1LL;
        parent[i] = i;
    }

    vector<pi> v(m);
    vector<ll> ans;

    int a, b;
    lp(i, 0, m){
        cin>>a>>b;
        v[i] = mp(a, b);
    }

    //ll res = (ll)n*(n-1)/2;
    ll res = (ll)n*(n-1); res /= 2;

    lpd(i, 0, m){
        ans.pb(res);
        int x = find_set(v[i].first);
        int y = find_set(v[i].second);

        if (x != y){
            res -= (size[x]*size[y]);
            union_sets(x, y);
        }
    }

    lpd(i, 0, m) cout<<ans[i]<<endl;

    return 0;
}

Measured memory_bytes: 4212
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b


class cumsum1d:  # 一次元累積和クラス
    def __init__(self, ls: list):
        '''
        1次元リストを受け取る
        '''
        from itertools import accumulate
        self.ls_accum = [0] + list(accumulate(ls))

    def total(self, i, j):
        # もとの配列lsにおける[i,j)の中合計
        return self.ls_accum[j] - self.ls_accum[i]


def two_pointers(ls: list):
    '''すべてのlに対して、条件is_okをみたすls[l:r]の中で
    r - lが最大になるような(l,r)の集合を返す'''
    n_ls = len(ls)
    ret = []

    def append(r, pre_states):
        '''状態にls[r]を考慮して更新する'''
        # 問題によって自分で定義
        return pre_states + ls[r]
        # 掛け算の例 return pre_state*ls[r]

    def pop(l, pre_states):
        '''状態からls[l]を抜く更新をする'''
        # 問題によって自分で定義
        # 掛け算の例 return pre_state//ls[l]
        return pre_states - ls[l]

    def is_ok(r, pre_states):
        # 問題によって自分で定義
        states = append(r, pre_states)
        # 114以下の最長の範囲が知りたい例 return states<=114
        return states <= K

    r = 0
    states = 0
    for l in range(n_ls):
        while r < n_ls and is_ok(r, states):
            # 更新式
            states = append(r, states)
            r += 1
        ret.append((l, r))
        # 抜けるときの更新
        states = pop(l, states)
    return ret


# K冊の組み合わせを試せば良い
# 合計は累積和で高速化
N, M, K = ints()
A = ints()
B = ints()
AB = list(reversed(A)) + B
# AB_cum = cumsum1d(AB)

ans = 0
for l, r in two_pointers(AB):
    if l <= N and N <= r:
        ans = max(ans, r - l)
print(ans)


Measured memory_bytes: 132728
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
  int dx[4] = {-1, 0, 1, 0}; 
  int dy[4] = {0, -1, 0, 1};
  int h, w;
  cin >> h >> w;
  vector<string> S(h);
  rep(i,h) cin >> S[i];

  int ans = 0;
  rep(i,h) rep(j,w) {
    if (S[i][j] == '#') continue;
    queue<P> que;
    que.push(P(i,j));
    vector< vector<int> > dist(h, vector<int>(w, -1));
    dist[i][j] = 0;
    P cur;
    while(!que.empty()) {
      cur = que.front(); que.pop();
      rep(i,4) {
        int y = cur.first + dy[i];
        int x = cur.second + dx[i];
        if (x >= w || y >= h || x < 0 || y < 0) continue;
        if (dist[y][x] != -1) continue;
        if (S[y][x] == '.') {
          que.push(P(y,x));
          dist[y][x] = dist[cur.first][cur.second] + 1;
          ans = max(ans, dist[y][x]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main(){
    string s;
    cin >> s;
    int ans = 0;
    int count = 0;
    for(int i = 0; i < 3; ++i){
        if(s[i] == 'R'){
            count++;
        }else{
            ans = max(ans,count);
            count = 0;
        }
    }

    ans = max(ans,count);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3608
#include <cstdio>
#include <array>
#include <algorithm>

using namespace std;

struct discal
{
    long long dis;
    long long cal;
};

int main()
{
    int n;
    long long c;
    scanf("%d %lld", &n, &c);
    std::array<discal, 100003> a;
    for (int i = 1; i <= n; ++i)
    {
        scanf("%lld %lld", &a[i].dis, &a[i].cal);
    }
    a[0] = {0, 0};
    a[n + 1] = {0, c};
    a[n + 2] = {0, c};

    discal rdiscal = {0, 0}, ldiscal = {0, 0};
    long long max = 0;
    long long dis;

    std::array<discal, 100003> r;
    max = 0;
    for (int i = 1; i <= n; ++i)
    {
        rdiscal = {a[i].dis, rdiscal.cal + a[i].cal};
        //printf("rdiscal dis = %lld cal = %lld\n", rdiscal.dis, rdiscal.cal);
        if (rdiscal.cal - rdiscal.dis > max)
        {
            max = rdiscal.cal - rdiscal.dis;
            dis = rdiscal.dis;
        }
        r[i] = {dis, max};
    }
    std::array<discal, 100003> l;
    max = 0;
    for (int i = n; i > 0; --i)
    {
        ldiscal = {c - a[i].dis, ldiscal.cal + a[i].cal};
        if (ldiscal.cal - ldiscal.dis > max)
        {
            max = ldiscal.cal - ldiscal.dis;
            dis = ldiscal.dis;
        }
        l[i] = {dis, max};
    }
    max = std::max(r[n].cal, l[1].cal);
    for (int i = 1; i < n; ++i)
    {
        if (r[i].cal + l[i + 1].cal - r[i].dis > max)
        {
            max = r[i].cal + l[i + 1].cal - r[i].dis;
        }
        if (r[i].cal + l[i + 1].cal - l[i + 1].dis > max)
        {
            max = r[i].cal + l[i + 1].cal - l[i + 1].dis;
        }
    }
    printf("%lld\n", max);
}

Measured memory_bytes: 4864
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"
n = int(input())
a= list(map(int , input().split()))
s = sum(a)
f = 1
if n == 0:
  if a[0] != 1:
    print(-1)
    exit()
  else:
    print(1)
    exit()
elif a[0]!=0:
  print(-1)
  exit()
ans = 1
node = 1
for i in range(1,n+1):
  node=min(2*node, s)
  ans+=node
  node-=a[i]
  s-=a[i]
  if node < 0:
    print(-1)	
    exit()
if f: print(ans)




Measured memory_bytes: 20392
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef long long ll;
typedef pair<ll,ll> PP;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false

string N;
int K;

int dp[114][2][10];

int keta(int k,bool f,int m){
    if(dp[k][f][m]!=-1){
        return dp[k][f][m];
    }
    if(m<0)return 0;
    if(k>=N.size()){
        int num = (!m?1:0);
        dp[k][f][m]=num;
        return num;
    }
    
    if(f){
        int num=0;
        REP(i,10){
            num+=keta(k+1,1,(i?m-1:m));
        }
        dp[k][f][m]=num;
        return num;
    }else{
        int num=0;
        int s = N[k]-'0';
        REP(i,s){
            num+=keta(k+1,1,(i?m-1:m));
        }
        num+=keta(k+1,0,(s?m-1:m));
        dp[k][f][m]=num;
        return num;
        
    }
    
}


signed main(void){
    cin >> N;
    cin >> K;
    
    REP(i,114){REP(j,2){REP(k,10){dp[i][j][k]=-1;}}}
    
    int Ans = keta(0,0,K);
    cout << Ans << endl;
    
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define STDIO
#define MOD 1000000007
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
#define lowbit(x) ((x)&(-x))
#define INF MOD
using namespace std;
string ss[4];
int len[4];
bool fits[4][4][4001];
bool can_fill_in(char c1,char c2){
	return ((c1=='?')||(c2=='?')||(c1==c2));
}
bool good(int i1,int i2,int kk){
	if(kk>=len[i1])
		return true;
	for(int i=0;i<min(len[i1]-kk,len[i2]);i++){
		if(!can_fill_in(ss[i1][i+kk],ss[i2][i]))
			return false;
	}
	return true;
}
int main(){
	#ifndef STDIO
		freopen("input.in","r",stdin);
		freopen("output.out","w",stdout);
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>ss[1]>>ss[2]>>ss[3];
	for(int i=1;i<=3;i++){
		len[i]=ss[i].size();
	}
	for(int i=1;i<=3;i++){
		for(int j=1;j<=3;j++){
			for(int k=0;k<=4000;k++){
				fits[i][j][k]=good(i,j,k);
			}
		}
	}
	int res=1e9;
	int cand;
	for(int i=1;i<=3;i++){
		for(int j=1;j<=3;j++){
			if(i==j)
				continue;
			for(int k=1;k<=3;k++){
				if((i==k)||(j==k))
					continue;
				for(int p=0;p<=2000;p++){
					if(!fits[i][j][p])
						continue;
					for(int q=0;q<=2000;q++){
						if(!fits[j][k][q])
							continue;
						if(!fits[i][k][p+q])
							continue;
						cand=len[i];
						cand=max(cand,len[j]+p);
						cand=max(cand,len[k]+p+q);
						res=min(res,cand);
					}
				} 
			}
		}
	}
	cout<<res<<endl;
	return 0;
}


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

int main() {
  int n, y; cin >> n >> y;
  for(int a = 0; a <= n; a++) {
    for(int b = 0; b <= n - a; b++) {
      int c = n - a - b;
      if(10000*a + 5000*b + 1000*c == y) {
        cout << a << " " << b << " " << c << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <bitset>
#include <vector>
using namespace std;

#define LL long long

#define fi first
#define se second
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(a,b) (((a)+(b))>>1)
#define maxx(a,b) ((a)<(b)?(b):(a))
#define minx(a,b) ((a)<(b)?(a):(b))
#define absx(a) ((a)<0?-(a):(a))
#define mk(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define itr iterator
#define lowbit(x) ((x)&-(x))

typedef unsigned LL ULL;
typedef unsigned uint;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;

template< typename T > inline void read(T &x) {
    static bool fr_f; static char fr_ch;
    fr_f=0; x=0; fr_ch=getchar();
    while(fr_ch<'0' || '9'<fr_ch) {if(fr_ch=='-') fr_f=1; fr_ch=getchar();}
    while('0'<=fr_ch && fr_ch<='9') {x=(x<<1)+(x<<3)+fr_ch-'0'; fr_ch=getchar();}
    if(fr_f) x=-x;
}

template< typename T > inline void Max (T &a, T &b) {if(a<b) a=b;}
template< typename T > inline void Min (T &a, T &b) {if(b<a) a=b;}
template< typename T > inline void Swap(T &a, T &b) {T c=a;a=b;b=c;}
template< typename T > inline T Abs(T &a) {if(a<0) return -a; else return a;}

const double   pi = acos(-1.0) ;
const int     MOD = (int)1e9+7 ;
const int     INF = (int)0x3f3f3f3f ;
const LL     LINF = (LL)INF<<32|INF ;
const int    SINF = (uint)(-1)>>1 ;
const LL    SLINF = (ULL)(-1)>>1 ;
const double DINF = 1e50 ;
const double  eps = 1e-8 ;
const int    maxn = (int) 2e5+20 ;
const int    maxm = (int) 25000+20 ;
const int    maxk = (int) 1000+20 ;

inline int sig(double x) {return x<-eps?-1:x>eps;}
inline LL fp(LL a,LL n,LL p) {LL res=1; for(;n;n>>=1,a=a*a%p) if(n&1) res=res*a%p; return res;}
template<typename T>inline T gcd(T a,T b) {for(T c;b;c=a%b,a=b,b=c); return a;}

//--------------------start--------------------

LL x,y;

void work()
{
    cin >>x >>y;
    LL z = y / x ;
    int ans = 0 ;
    while(z)
    {
        ans++;
        z>>=1;
    }
    cout <<ans <<endl;
}

//---------------------end---------------------

int main()
{
#ifdef yukihana0416
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif // yukihana0416
    work();
    return 0;
}


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

typedef long long int ll;

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define endl "\n"

int main()
{
     fast;
     int n,i,temp,flag=0;
  	 cin>>n;
  	 for(i=0;i<3;i++)
  	 {
  	 	temp=n%10;
  	 	if(temp==7)
  	 	{
  	 		flag=1;
  	 		break;
  	 	}
  	 	n=n/10;
  	 }
  	 if(flag)
  	 	cout<<"Yes"<<endl;
  	 else
  	 	cout<<"No"<<endl;
  

     return 0;
}

Measured memory_bytes: 3652
#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 (b < a) { a = b; return true; } return false; }
const long long INF = 1LL << 60;
int N, M;
vector<vector<int>> G;
int dp[100100];
int rec(int v) {
	if (dp[v] != -1) return dp[v];
	int  res = 0;
	for (auto nv : G[v]) {
		chmax(res, rec(nv) + 1);
	}
	return dp[v] = res;
}
int main() {
	cin >> N >> M;
	G.assign(N, vector<int>());
	for (int i = 0; i < M; i++) {
		int x, y; cin >> x >> y;
		x--; y--;
		G[x].push_back(y);
	}
	for (int i = 0; i < N; i++) dp[i] = -1;
    int res=0;
	for (int v = 0; v < N; v++) { chmax(res, rec(v)); }
	cout << res << endl;
}

Measured memory_bytes: 8192
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
    

    ll lis[101][101];
    ll n,m;
    cin >> n >> m;
    for (ll i=0;i<n;i++){
        for(ll j=0;j<m;j++){
            cin >> lis[i][j];
        }
    }
    for (ll i=0;i<n;i++){
        for (ll j=0;j<=m;j++){
            if(i != n and j != m){
                cout << lis[i][j] << " ";
            }else if(i != n){
                ll ans = 0;
                for (ll k=0;k<m;k++){
                    ans += lis[i][k];
                }
                cout << ans << endl;
            }
        }
    }
    ll ans = 0;
    for(ll j=0;j<m;j++){
        ll tmp = 0;
        for (ll k=0;k<n;k++){
            tmp += lis[k][j];
        }
        cout << tmp << " ";
        ans += tmp;
    }
    cout << ans << endl;


}





Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    ll n; cin >> n;
    ll cnt = 1;
    rep(i, n) {
        ll a; cin >> a;
        if(a % 2 == 0) cnt *= 2;
    }
    cout << (ll)pow(3, n) - cnt << endl;
}

Measured memory_bytes: 4100