akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

template <class M> class segment_tree{
public:
//	using value_type = M::value_type;
	typedef typename M::value_type value_type;
	size_t n;
	vector<value_type> v;
	value_type e = M::unit();
	segment_tree(size_t size){
		n = 1;
		while(n < size) n <<= 1;
		v.resize(2*n, e);
		for(size_t i=1; i<n+size; ++i) v[i] = e;
	}
	segment_tree(vector<value_type> a){
		size_t size = a.size();
		n = 1;
		while(n < size) n <<= 1;
		v.resize(2*n, e);
		for(size_t i=0; i<size; ++i) v[n+i] = a[i];
		for(size_t i=n-1; i>0; --i) v[i] = M::operate(v[2*i], v[2*i+1]);
	}
	void point_update(size_t x, value_type val){
		x += n;
		v[x] = val;
		x >>= 1;
		while(x > 0){
			v[x] = M::operate(v[2*x], v[2*x+1]);
			x >>= 1;
		}
	}
	void point_operate(size_t x, value_type l){
		x += n;
		v[x] = M::operate(l, v[x]);
		x >>= 1;
		while(x > 0){
			v[x] = M::operate(v[2*n], v[2*n+1]);
			x >>= 1;
		}
	}
	value_type range_get(size_t l, size_t r){ // [l, r)
		value_type lres = e;
		value_type rres = e;
		l += n;
		r += n;
		while(l < r){
			if(l & 1){
				lres = M::operate(lres, v[l]);
				++l;
			}
			if(r & 1){
				--r;
				rres = M::operate(v[r], rres);
			}
			l >>= 1;
			r >>= 1;
		}
		return M::operate(lres, rres);
	}
};
struct plus_monoid{
	using value_type = Int;
	static value_type unit(){
		return 0;
	}
	static value_type operate(value_type l, value_type r){
		return l + r;
	}
};
struct min_monoid{
	using value_type = Int;
	static value_type unit(){
		return (1ll<<31)-1;
	}
	static value_type operate(value_type l, value_type r){
		return min(l, r);
	}
};

// AOJ DSL 2A

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q;
	cin >> n >> q;
	segment_tree<min_monoid> st(n);
	while(q--){
		int t, x, y;
		cin >> t >> x >> y;
		if(t == 0) st.point_update(x, y);
		else cout << st.range_get(x, y+1) << "\n";
	}
}

// AOJ DSL 2B
/*
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q;
	cin >> n >> q;
	segment_tree<plus_monoid> st(n);
	while(q--){
		int t, x, y;
		cin >> t >> x >> y;
		if(t == 0) st.point_operate(x, y);
		else cout << st.range_get(x, y+1) << "\n";
	}
}
*/


Measured memory_bytes: 4956
//       In the name of         ****                      God                     ****

/*

Copyright (C)          JadedBeast

                                   Morocco

created : 8/3/2019

*/

#include <bits/stdc++.h>

using namespace std; 



int main(void){
     int n,k;
    cin >> n >> k ;
    int DP[n],v[n];
    fill(DP,DP+n,INT_MAX);
    for(int i =0 ;i<n ;i++)
        cin >> v[i];
    DP[0]=0;
    for(int i=0;i<n ;i++){
        for(int j=1 ;j<=k && j+i<n ;j++){
           DP[i+j]=min(DP[i]+abs(v[i]-v[i+j]),DP[i+j]);
        }
    }


     cout << DP[n-1];
    
   return 0;
}


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

int main(){
    string a,b;
    cin>>a>>b;
    if(a==b) cout<<"EQUAL";
    else if(a.size()>b.size()) cout<<"GREATER";
    else if(a.size()<b.size()) cout<<"LESS";
    else {
        for(int i=0; i<a.size(); i++) {
            if(a[i]-'0'>b[i]-'0') {
                cout<<"GREATER";
                break;
            }
            else if(a[i]-'0'<b[i]-'0') {
                cout<<"LESS";
                break;
            }
        }
    }
}

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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;
  vector<ll> va(3 * n);
  for (int i = 0; i < va.size(); ++i) {
    cin >> va[i];
  }

  priority_queue<ll> rq;
  vector<ll> r(n + 1);
  for (auto it = va.rbegin(); it != va.rbegin() + n; it++) {
    r[0] += *it;
    rq.push(*it);
  }

  ll s = r[0];
  for (int i = 1; i < r.size(); ++i) {
    rq.push(*(va.rbegin() + n + i - 1));
    s += *(va.rbegin() + n + i - 1);
    ll m = rq.top();
    rq.pop();
    s -= m;
    r[i] = s;
  }

  priority_queue<ll, vector<ll>, greater<ll>> q;
  vector<ll> f(n + 1);
  for (auto it = va.begin(); it != va.begin() + n; it++) {
    f[0] += *it;
    q.push(*it);
  }

  s = f[0];
  for (int i = 1; i < f.size(); ++i) {
    q.push(*(va.begin() + n + i - 1));
    s += *(va.begin() + n + i - 1);
    ll m = q.top();
    q.pop();
    s -= m;
    f[i] = s;
  }

  ll ans = f.front() - r.back();
  for (int i = 0; i < f.size(); ++i) {
    ll score = f[i] - r[r.size() - i - 1];
    ans = max(ans, score);
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 9552
#include<iostream>
#include<algorithm>
#include<iomanip>
using lint=int64_t;
using namespace std;

int main()
{
	double W,H;
	double x,y;

	cin >> W >> H;
	cin >> x >> y;

	cout << fixed << setprecision(10);
	cout << W*H/2 << endl;
	if(x==W/2 && y==H/2)
		cout << 1;
	else 
		cout << 0;
	cout << endl;
	return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	char s[1000001];
	scanf("%s",&s);
	int len=strlen(s);
	int flag=1;
	if(len%2==1)
	{
		printf("No\n");
		return 0;
	}
	for(int i=0;i<=len/2+1;i++)
	{
		if(s[i]=='d')
		{
			if(s[len-1-i]!='b')
			{
				flag=0;
				break;
			}
		}
		if(s[i]=='b')
		{
			if(s[len-1-i]!='d')
			{
				flag=0;
				break;
			}
		}
		if(s[i]=='p')
		{
			if(s[len-1-i]!='q')
			{
				flag=0;
				break;
			}
		}
		if(s[i]=='q')
		{
			if(s[len-1-i]!='p')
			{
				flag=0;
				break;
			}
		}
	}
    if(flag==0)printf("No\n");
    else printf("Yes\n");
    return 0;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())
ans = 0

def digitsum(j):
    s = str(j)
    array = list(map(int, s))
    return sum(array)

for i in range(1, n+1):
    if(a <= digitsum(i) and digitsum(i) <= b):
        ans += i
print(ans)

Measured memory_bytes: 3060
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>
#include <random>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ll x;
    cin >> x;
    cout << !x << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
int main()
{
  char n;
  for(int i=0;i<3;i++)
  {
    cin>>n;
    (n=='1') ? cout<<9 :cout<<1;
  }
  cout<<endl;
}

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

#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define TRACE(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << endl;}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << "[" << *it << " = " << a << "]";
	err(++it, args...);
}

#define MAXN ((ll)2e5+5)
#define MOD ((ll)1e9 + 7)
#define INF ((ll)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define LOG(x) if(DEBUG) cerr << x << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<ll,ll>
#define mid ((l+r)/2)

ll n;
ll d[MAXN];

signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> n;
	for (ll i = 0; i < n; ++i)
		cin >> d[i];
	sort(d, d+n);

	ll ans = d[n-1];
	ll t = n-2;
	ll it = n-2;
	while(t > 1)
	{
		t -= 2;
		ans += 2*d[it];
		it--;
	}
	if(t)
		ans += d[it];

	cout << ans << endl;
}

/* stuff you should look for
	* ll overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

Measured memory_bytes: 5172
#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

#n! = a p^eとしたときのeを求める (O(logp n)
def mod_e(n,p):
    res = 0
    while n >= p:
        res += n//p
        n = n//p
    return res

#n! = a p^eとしたときのa mod pを求める  (O(logp n)
def mod_fact(n,p):
    if n==0:
        return 1
    
    
    res = mod_fact(n//p,p)
    
    if n//p %2 != 0:
        return res*(p-fact[n%p])%p
    return res*fact[n%p]%p
    
######################################################

#nCk mod p
def mod_comb(n,k):
    if n < 0 or k < 0 or n<k:
        return 0
    e1 = mod_e(n,p)
    e2 = mod_e(k,p)
    e3 = mod_e(n-k,p)
    #pで割り切れる場合
    if e1 > e2 + e3:
        return 0

    #pで割り切れない場合
    a1 = mod_fact(n,p)
    a2 = mod_fact(k,p)
    a3 = mod_fact(n-k,p)
    return a1 * mod_inv(a2*a3%p,p) %p
######################################################

h,w,a,b = map(int,input().split())
#pは素数とする
p = 10**9+7
#fact[i] : i! modp (0<= i <p) O(p)
fact = [1]
k = 1
for i in range(1,10**6+10):
    k = k*i%p
    fact.append(k)

res = 0
for i in range(h-a):
    res += mod_comb(i+b-1,b-1)*mod_comb(h-i-1+w-b-1,w-b-1)
    res = res%p
print(res)

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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, VL, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18 + 1;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll N, K;
VL D;
vector<bool> ava(10, true);

bool judge(ll x) {
    while(x) {
        if(!ava[x % 10]) return false;
        x /= 10;
    }
    return true;
}

signed main() {
    cin >> N >> K;
    REP(i, K) ava[IN()] = false;
    FOR(i, N, N * 10 + 10) {
        if(judge(i)) {
            cout << i << "\n";
            return 0;
        }
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);
		
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();

		if((a <= c) &&(c <= b)){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef std::uint64_t u64;
typedef std::int64_t  i64;
typedef std::uint32_t u32;
typedef std::int32_t  i32;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl

#define YesNo(x) if(x) cout << "Yes" << endl; else cout << "No" << endl;
#define YESNO(x) cout << ((x) ? "YES" : "NO") << endl

bool graph[8][8];

u64 n;

/* 
 *  s: 始点の番号
 *  v: v[i] = iをすでに通っているかどうか
 */
u64 f(u64 s, vector<bool> v) {
	debug(s);
	bool all_visited = true;
	rep(i, n) {
		if(v[i] == false) {
			all_visited = false;
		}
	}
	if(all_visited) {
		cerr << "All nodes are visited." << endl;
		return 1;
	}

	u64 ret = 0;
	rep(i, n) {
		 /* s から i に行けない、もしくは i をすでに通っていれば飛ばす */
		if(graph[s][i] == false) {
			cerr << i << " is skipped. (graph[" << s << "][" << i << "] == false)" << endl;
			continue;
		}

		if(v[i]) {
			cerr << i << " is skipped. (v[" << i << "] == true)" << endl;
			continue;
		}

		/* s から i に行けて、i をまだ通っていなければ探索する */
		cerr << "call: " << s << " -> " << i << endl;
		v[i] = true;
		ret += f(i, v);
		v[i] = false;
	}

	return ret;
}

int main(int argc, const char* argv[]) {
	u64 m;
	cin >> n >> m;

	rep(i, 8) {
		rep(j, 8) {
			graph[i][j] = false;
		}
	}

	rep(i, m) {
		u64 a, b;
		cin >> a >> b;
		graph[--a][--b] = true;
		graph[b][a] = true;
	}

	rep(i, n) {
		rep(j, n) {
			cerr << graph[i][j];
		}
		cerr << endl;
	}

	vector<bool> v(n, false);
	v[0] = true;

	cout << f(0, v) << endl;

	return 0;
}


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

using namespace std;
#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;



int main () {
   SpeedForce;
	cin >> n >> s;
	for (auto it : s) {
		int cur = (it - 'A');
		cur += n;
		cur %= 26;
		cout << char(cur + 'A');
	}
   return Accepted;
}

// B...a

Measured memory_bytes: 18688
import java.util.*;
import java.util.Map.Entry;
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int k = in.nextInt();
		int x = in.nextInt();
		int y = in.nextInt();
		int total = 0;
		if (n>k) {
			total = x*k;
			total+= (n-k)*y;}
		else {
			total = n*x;
		}
		
		System.out.println(total);
            }
		}
	



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


int main() {
  int A,B,C,K;
  cin >> A >> B >> C >> K; 
  // A < B < C を満たすのが条件
  int t = 0;
  while(A >= B){
       B*= 2;
       t++;
  }
  while(B >= C){
      C*= 2;
      t++;
  }
  if(t <= K) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  string s,t;
  cin>>s>>t;

  auto eq = [](string const& a,string const& b){
    int n = a.size();
    rep(i,n){
      if(a[i]!='?'&&a[i]!=b[i])return false;
    }
    return true;
  };

  int n = s.size();
  int m = t.size();
  if(n<m){
    cout<< "UNRESTORABLE" <<endl;
    exit(0);
  }

  auto end = [](string s,string t,int i){
    int m = t.size();
    rep(j,m){
      s[i+j] = t[j];
    }
    int n = s.size();
    rep(i,n){
      if(s[i]=='?')s[i]='a';
    }
    cout<< s <<endl;
    exit(0);
  };

  for(int i=n-m;i>=0;--i){
    if(eq(s.substr(i,m),t)){
      end(s,t,i);
    }
  }
  cout<< "UNRESTORABLE" <<endl;


}

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

#define NIL 2000000001

int n = 0;

int parent(int i){
    return i / 2;
}

int left(int i){
    return 2 * i;
}

int right(int i){
    return 2 * i + 1;
}

void heapIncreaseKey(int *h, int i, int key){
    
    int tmp;

    h[i] = key;
    
    while(i > 1 && h[parent(i)] < h[i]){
        tmp = h[i];
        h[i] = h[parent(i)];
        h[parent(i)] = tmp;
        i = parent(i);
    }
    return;
}

void maxHeapInsert(int *h, int key){
    n = n + 1;
    h[n] = NIL;
    heapIncreaseKey(h, n, key);
}

void maxHeapify(int* h, int i){
    
    int l, r, x, largest;
    
    l = left(i);
    r = right(i);
    
    if(l <= n && h[l] > h[i]) largest = l;
    else largest = i;
    
    if(r <= n && h[r] > h[largest]) largest = r;
    
    if(largest != i){
        x = h[i];
        h[i] = h[largest];
        h[largest] = x;
        maxHeapify(h, largest);
    }
}

void buildMaxHeap(int* h){
    
    int i;
    
    for(i = n / 2; i > 0; i--) maxHeapify(h, i);
    
}

int heapExtractMax(int *h){
    
    int max;
    
    max = h[1];
    h[1] = h[n];
    n = n - 1;
    
    maxHeapify(h, 1);
    
    return max;
    
}


int main(){
    
    int x;
    int h[2000000];
    char com[10];
    
    while(1){
        scanf("%s", com);
        
        if(com[0] == 'i'){
            scanf("%d", &x);
            maxHeapInsert(h, x);
        }
        else if(com[1] == 'n') break;
        else if(com[0] == 'e')
            printf("%d\n", heapExtractMax(h));
    }
    
    return 0;
    
}

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

int main() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  long long ans = -10000000000000000000000000;
  ans = max(ans, a * c);
  ans = max(ans, a * d);
  ans = max(ans, b * c);
  ans = max(ans, b * d);
  cout << ans << endl;
}


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

const int MAXN = 10101;

int a[MAXN], b[MAXN];
int n;

int main() {
	scanf("%d", &n);
	long long suma = 0, sumb = 0;
	for(int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		suma += a[i];
	}
	for(int i = 1; i <= n; ++i) {
		scanf("%d", &b[i]);
		sumb += b[i];
	}
	if(suma > sumb) {
		puts("No");
		return 0;
	}
	long long key = sumb - suma;
//	cout<<key<<endl;
	long long need = 0, need2 = 0, totadd = 0;
	for(int i = 1; i <= n; ++i) {
		if(a[i] < b[i]) {
			if(need >= b[i] - a[i]) {
				need -= b[i] - a[i];
				if((b[i] - a[i]) % 2)
					need++, totadd++;
			}
			else {
				int delta = b[i] - a[i];
				if(delta & 1)
					need += 2, totadd++, delta++;
				delta -= need;
				need = 0;
				need2 += delta>>1;
				totadd += delta>>1;
			}
		}
		else {
			if(need2 >= a[i] - b[i]) {
				need2 -= a[i] - b[i];
			}
			else {
				int delta = a[i] - b[i];
				delta -= need2;
				need2 = 0;
				need += delta * 2;
				totadd += delta;
			}
		}

	}
	//cout<<totadd<<" "<<need2<<endl;
	if(!need && totadd + need2 == key) 
		puts("Yes");
//	puts("YES");
	else
		puts("No");

	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#define N 44

int main(void) {

  int i,n,F[N];

  scanf("%d",&n);

  F[0] = F[1] = 1;
  for(i=2;i<=n;i++)
    F[i] = F[i-1] + F[i-2];

  printf("%d\n",F[n]);
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
const int N=200010;
const int mod=1e9+7;
typedef long long ll;
int n;
map<int,int>mp;
int a[N],b[N],dp[N];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int t=0;
	for(int i=1;i<=n;i++){
		while(i+1<=n&&a[i]==a[i+1])
			i++;
		b[++t]=a[i];
	}
	dp[0]=1;
	for(int i=1;i<=t;i++){
		dp[i]=(dp[i-1]+mp[b[i]])%mod;
		mp[b[i]]=(mp[b[i]]+dp[i-1])%mod;
	}
	printf("%d\n",dp[t]);
	return 0;
}
/*
6
1 3 1 2 3 2
*/

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

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

    if (a == 0) {
        cout << 1 << endl;
    }
    else if (b == 0) {
        cout << 2 << endl;
    }
    else if (c == 0) {
        cout << 3 << endl;
    }
    else if (d == 0) {
        cout << 4 << endl;
    }
    else if (e == 0) {
        cout << 5 << endl;
    }
}

Measured memory_bytes: 3552
from itertools import accumulate

N, Q = map(int,input().split())
S = list(input())
L = [0] * Q
R = [0] * Q
for i in range(Q):
    L[i], R[i] = map(int,input().split())

S = ['0'] + S
check = [0] * N

for i in range(N):
    if S[i] == 'A':
        if S[i+1] == 'C':
            check[i] = 1

check = list(accumulate(check))
for left, right in zip(L, R):
    print(check[right-1] - check[left-1])


Measured memory_bytes: 17044
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

signed main() {
  ll A, B;
  cin >> A >> B;

  ll ans = 0;
  if (A < B) {
    ans += B;
    B--;
  } else {
    ans += A;
    A--;
  }

  if (A < B) {
    ans += B;
  } else {
    ans += A;
  }
  COUT(ans);

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ELEM(array) (sizeof (array)/sizeof *(array))
#define MAX_N 100
typedef long long ll;
 
int n;
int count_HIT=0, count_OUT=0;
int Point=0;
string S;
 
 
void solve()
{
    while (count_OUT <3)
    {
        cin >> S;
        if (S == "HIT")
        {
            count_HIT++;
            if (count_HIT == 4)
            {
                Point++;
                 
                count_HIT -- ;
            }
        }
        else if (S == "HOMERUN")
        {
            Point += count_HIT + 1;
             
            count_HIT = 0;
        }
        else count_OUT++;
    }
    cout << Point << endl;
    count_OUT = 0; count_HIT = 0;
    Point = 0;
     
    return;
}
 
int main()
{
    cin >> n;
    REP(j, n)
    {
        solve();
    }
 
     
 
    return 0;
}

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

const int M = 1000005;

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

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    vector<int> cnt(M);
    for (auto x : a) {
        if (cnt[x] != 0) {
            cnt[x] = 2;
            continue;
        }
        for (int i = x; i < M; i += x) cnt[i]++;
    }
    int ans = 0;
    for (auto x : a) {
        if (cnt[x] == 1) ans++;
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 7956
#include<bits/stdc++.h>
using namespace std;
int main(){

   int x,a,b,i,c;
   cin>>x>>a>>b;
   c=0;
   for(i=a;i<=b;i++){
        if(i%x==0){
            c++;
            break;
        }
   }
   if(c==0){
    cout<<"NG"<<endl;
   }
   else{
        cout<<"OK"<<endl;
   }



}


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



int main() {
#ifdef HOME
    freopen("in", "r", stdin);
#endif

    int n, m, k;
    while (scanf("%d%d%d", &n, &m, &k) == 3) {
        vector<int> a(k);
        for (int i = 0; i < k; i++) scanf("%d", &a[i]);

        vector<vector<int> > b(n, vector<int>(m));
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                for (int j = 0; j < m; j++) {
                    if (a.back() == 0) a.pop_back();
                    b[i][j] = a.size();
                    a.back()--;
                }
            } else {
                for (int j = m - 1; j >= 0; j--) {
                    if (a.back() == 0) a.pop_back();
                    b[i][j] = a.size();
                    a.back()--;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                printf("%d%c", b[i][j], " \n"[j + 1 == m]);
            }
        }
    }

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()


int main() {
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    rep (i, n) {
        cin >> a[i];
    }
    ll ctr = 0;
    if (a[0] > x) {
        ctr += a[0] - x;
        a[0] = x;
    }
    rep (i, n-1) {
        if (a[i+1] + a[i] > x) {
            ctr += a[i+1] + a[i] - x;
            a[i+1] = x - a[i];
        }
    }
    cout << ctr << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divCeil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << endl; exit(0);}

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

  if (N == 1)
    FINALANS((A.front() == 0) ? 0 : -1);

  ll ans = accumulate(A.begin(), A.end(), 0LL);
  for (ll i = 0; i < N - 1; i++)
  {
    if (A.at(i) > i)
      FINALANS(-1);
    if (A.at(i) < A.at(i + 1) - 1)
      FINALANS(-1);
    if (A.at(i) == A.at(i + 1) - 1)
      ans -= A.at(i);
  }

  cout << ans << endl;
}

Measured memory_bytes: 1792
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

N = int(readline())
D = list(map(int,readline().split()))
M = int(readline())
T = list(map(int,readline().split()))

from collections import defaultdict
d_dict = defaultdict(int)
for t in T:
    d_dict[t] += 1
for d in D:
    if d_dict[d] > 0:
        d_dict[d] -= 1

print('YES' if sum(v for v in d_dict.values()) == 0 else 'NO')


Measured memory_bytes: 41572
import sys

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


N,M,L = map(int,input().split())

A = [list(map(int,input().split())) for i in range(N)] #N*M配列の取得
B = [list(map(int,input().split())) for i in range(M)] #M*L配列の取得
ANS = [[0]*L for i in range(N)] #N*L


for x in range(N):
    for y in range(L):
        for z in range(M):
            ANS[x][y] += B[z][y]*A[x][z]

for row in range(N):
    print("%d"%ANS[row][0],end = "")
    for col in range(1,L):
        print(" %d"%(ANS[row][col]),end = "")
    print()



Measured memory_bytes: 7068
#C
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
n=int(input())
lst=make_divisors(n)
ans=float("inf")
for u in lst:
    ans=min(ans,u+n//u-2)
print(ans)

Measured memory_bytes: 39792
#include <stdio.h>

#define MOD 1000000007

long long powerl (long long p, int n) {
	if (n==0)
		return 1;
	if (n==1)
		return p;
	long long tmp = powerl (p, n/2);
	if (n%2)
		return (((tmp*tmp)%MOD)*p)%MOD;
	else
		return tmp*tmp % MOD;
}

int main () {
	int N, K;
	long long fact[2001], invfact[2001];
	scanf ("%d %d", &N, &K);
	fact[0] = 1;
	for (int i=1; i<=N; i++)
		fact[i] = fact[i-1]*i % MOD;
	invfact[N] = powerl (fact[N], MOD-2);
	for (int i=N-1; i>=0; i--)
		invfact[i] = invfact[i+1]*(i+1) % MOD;

	long long num = fact[K-1]*fact[N-K+1] % MOD;
	for (int i=1; i<=K; i++) {
		if (N-K<i-1) {
			printf ("0\n");
			continue;
		}
		long long tmp = num ;
		tmp *= invfact[K-i];
		tmp %= MOD;
		tmp *= invfact[i];
		tmp %= MOD;
		tmp *= invfact[i-1];
		tmp %= MOD;
		tmp *= invfact[N-K-i+1];
		tmp %= MOD;
		printf ("%lld\n", tmp);
	}
	return 0;
}

Measured memory_bytes: 256
n, m  = gets.chomp.split.map(&:to_i)
number = []
n.times{number << gets.to_i}
1.upto(m){|k|
    1.upto(n-1){|s|
        if number[s-1] % k > number[s] % k
            temp = number[s-1]
            number[s-1] = number[s]
            number[s] = temp
        end        
    }
}
puts number



Measured memory_bytes: 6872
#include<stdio.h>
#define YAGI 3
int main(void){
  int a,b;
  scanf("%d %d",&a,&b);
  int sum = a + b;
  if(a % YAGI == 0 || b % YAGI == 0 || sum % YAGI == 0){
    printf("Possible");
  }else{
    printf("Impossible");
  }
  return 0;
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

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

int main() {
    ll N;
    cin >> N;
    map<ll,ll> mp;
    vector<ll> v;
    ll A[N];
    rep(i,N){
        cin >> A[i];
        if(mp.count(A[i])) mp[A[i]]++;
        else{
            v.push_back(A[i]);
            mp.emplace(A[i],1);
        }
    }
    sort(v.begin(),v.end());
    string out = "No";
    if(v.size()==1&&v[0]==0) out = "Yes";
    else if(N%3==0){
        if(v.size()==2&&v[0]==0&&mp[0]==N/3) out = "Yes";
        else if(v.size()==3&&(mp[v[0]]==mp[v[1]]&&mp[v[1]]==mp[v[2]])){
            if(((v[0]^v[1])^v[2])==0) out = "Yes";
        }
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 6260
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// ABC127 B - Algae
// 2020.07.04

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int r, D, x; cin >> r >> D >> x;
  REP(i, 10){
    x = r*x - D;
    cout << x << endl;
  }
}

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

int main(){
    string N;
    cin >> N;
    int S = 0;
    for(int i=0; i< N.size(); i++){
        S += N[i] - '0';
    }
    if(stoi(N)%S == 0){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

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

using namespace std;
using LLONG = long long;

int main()
{
    for (int i = 0; i < 3; ++i)
    {
        string str;
        cin >> str;
        cout << static_cast<char>(str.front() - 0x20);
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<n;i++)
int main(){
ll n,k;
cin >>n>>k;
ll d[k];
REP(i,k){
cin >>d[i];
}
map<ll,ll> a;
REP(i,k){
a[d[i]]=1;
}
bool flag=true;
while(flag){
ll check=n;
bool flag1=true;
while(check>0){
ll memo=check%10;
if(a[memo]==1){
flag1=false;
}
check=check/10;
}
if(flag1){
cout<<n;
flag=false;
}
n++;
}
return 0;
}

Measured memory_bytes: 256
import java.io.*;
public class Main{
  public static void main(String[]args){
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    try{
    String line = reader.readLine();
    int fi = Integer.parseInt(line);
    System.out.println(fi*fi*fi);
  }catch(IOException e){
    System.out.println(e);
  }catch(NumberFormatException e){
    System.out.println("数字が正しくありません");
  }
  }
}


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

int main()
{
  int N;
  int a[25], b[60], c[60];
  int res=0;
  cin >> N;

  for(int i=0;i<N;i++) cin >> a[i];
  for(int i=0;i<N;i++) cin >> b[i];
  for(int i=0;i<N-1;i++) cin >> c[i];

  int prev=0;
  for(int i=0;i<N;i++){
    int current = a[i];
    res += b[current-1];
    if(i>0 && (current==(prev+1))) {
      res+= c[current-1-1];
    }
    prev = current;
  }
  
  cout << res << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m;
vector<int>g[100005];
vector<int>ans;
int v[100005];
inline void dfs(int x){
	v[x]=1;
	ans.push_back(x);
	for(int i=0;i<g[x].size();i++){
		int k=g[x][i];
		if(v[k]) continue;
		dfs(k);
		return;
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(1);
	reverse(ans.begin(),ans.end());
	int tmp=ans.size();
	dfs(1);
	printf("%d\n",ans.size()-1);
	for(int i=0;i<ans.size();i++){
		if(ans[i]==1&&i!=tmp-1) continue;
		printf("%d ",ans[i]);
	}
	return 0; 
}

Measured memory_bytes: 8312
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int ba[7][7][7];
int n, m;

int d[13][3] = {{1,0,0},{0,1,0},{0,0,1},
                {1,1,0},{0,1,1},{1,0,1},{1,-1,0},{0,1,-1},{-1,0,1},
                {1,1,1},{1,1,-1},{1,-1,1},{-1,1,1}};
bool judge(vector<int> p, int c) {
  // 1-D
  vector<int> a(3);
  REP(i, 13) {
    int cnt = 0;
    for (int k=-10; k<=10; ++k) {
      bool f = 0;
      REP(j, 3) {
        a[j] = p[j] + d[i][j] * k;
        if (a[j] < 0 || a[j] >= n) f = 1;
      }
      if (f) continue;
      if (ba[a[0]][a[1]][a[2]] == c) cnt++;
      else cnt = 0;
      if (cnt == m) return 1;
    }
  }
  return 0;
}

int main() {
  int p;
  string ans[2] = {"Black", "White"};
  while(cin>>n>>m>>p, n||m||p) {
    memset(ba, 0, sizeof (ba));
    int a[p], b[p];
    REP(i, p) {
      cin >> a[i] >> b[i];
      a[i]--; b[i]--;
    }
    bool f = 0;
    int num[n][n];
    memset(num, 0, sizeof(num));
    REP(i, p) {
      vector<int> v(3);
      v[0] = a[i]; v[1] = b[i]; v[2] = num[v[0]][v[1]]++;
      ba[v[0]][v[1]][v[2]] = i%2 + 1;
      if (judge(v,i%2 + 1)) {
        cout << ans[i%2] << " " << i+1 << endl;
        f = 1;
        break;
      }
    }
    if (!f) {
      cout << "Draw" << endl;
    }
  }
}

Measured memory_bytes: 920
package main

import "fmt"

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	ans := 1
	for i := 0; i < N; i++ {
		ans = MinOf(ans+K, ans*2)
	}
	fmt.Println(ans)
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}


Measured memory_bytes: 512
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		String s = sc.next();

		sc.close();

		int hiraki = 0;
		int hiraki2 = 0;
		int toji = 0;
		int toji2 = 0;

		// 左からみていってたりない ) を数える
		for (int i = 0; i < N; i++) {
			if (s.charAt(i) == '(') {
				hiraki++;
			} else {
				if (hiraki == 0) {
					hiraki2++;
				} else {
					hiraki--;
				}
			}
		}
		// 右からみていってたりない ) を数える
		for (int i = N - 1; i >= 0; i--) {
			if (s.charAt(i) == ')') {
				toji++;
			} else {
				if (toji == 0) {
					toji2++;
				} else {
					toji--;
				}
			}
		}

		for (int i = 0; i < hiraki2; i++) {
			out.print("(");
		}
		out.print(s);
		for (int i = 0; i < toji2; i++) {
			out.print(")");
		}
		out.println();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray1origin(Scanner sc, int n) {
		int[] result = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 23508
//AcFreak

#include<bits/stdc++.h>
#define lint long long int 
#define mp make_pair
#define pb push_back
#define f first
#define INF (lint )(1e9)
#define __ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define s second
#define endl '\n'
#define pii pair<int,int >
using namespace std;


int main()
{__
     

		lint n;
		cin>>n;

		vector<lint >arr(n);
		lint i,j;

		for(i=0;i<n;i++)
			cin>>arr[i];

		sort(arr.begin(), arr.end());
		
		lint maxa=*max_element(arr.begin(), arr.end());
		lint ans=0;
		
		for(i=0;i<n;i++)
		{
			ans+=(arr[i]-1);
		}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int a,b,x,y,z,p=-1000000;

    cin>>a>>b;

    x=a+b;
    p=max(p,x);

    x=a-b;
    p=max(p,x);

    x=a*b;
    p=max(p,x);

    cout<<p<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>
#define rep(i, a, b) for (int(i) = (a); i < (b); i++)
using namespace std;

using ll = long long;

typedef pair<int, int> P;

const int INF = 100000000;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;

ll pow_mod(ll x, ll y, ll mod)
{
	ll ans=1;
	for(;y>0;y>>=1){
		if(y&1)(ans*=x)%=mod;
		(x*=x)%=mod;
	}
	return ans;
}

int n;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	//問題文中の添え字が0-indexか1-indexか確認!
	cin >> n;
	cout << 180 * (n - 2);
	return 0;
}

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

int main()
{
	vector<string> x{ "Sunny", "Cloudy", "Rainy" };
	string S;
	cin >> S;
	for (auto iter = x.begin(); iter != x.end() - 1; ++iter)
	{
		if (S == *iter) 
			cout << *(iter + 1) << endl;
		if (S == x[2]) 
        {
          cout << x[0];
          break;
        }
	}
	return 0;
}


Measured memory_bytes: 256
def calcgcd(a, b):
  if a > b:
    a, b = b, a
  while a > 0:
    a, b = b%a, a
  return b
def calclcm(a, b):
  return a*b//calcgcd(a, b)

A, B = map(int, input().split())
r = calclcm(A, B)
print(r)


Measured memory_bytes: 2940
a,b,c,d = map(int,input().split())
count1 = 0
count2 = 0

while c>0:
    c=c-b
    count1+=1

while  a>0:
    a=a-d
    count2+=1

if count1>count2:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 9180
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include <ext/rope>

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define rep(i, n) for (int i=0; i<(n); i++)
#define rep1(i, n) for (int i=1; i<=(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
template<typename _def> using ordered_set=tree<_def, null_type, less<_def>, rb_tree_tag, tree_order_statistics_node_update>;
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie;

vvi adj;
vb vis;
vi part[2];

void dfs(int u, int c) {
    vis[u]=1; part[c].pb(u);
    for(int v: adj[u]) if(!vis[v]) dfs(v, c^1);
}

int32_t main() {
    fastio;
    int n; cin>>n;
    adj.resize(n); vis.assign(n, 0);
    rep(i, n-1) {
        int u, v; cin>>u>>v;
        adj[--u].pb(--v); adj[v].pb(u);
    }
    dfs(0, 0);
    if(part[0].size()>part[1].size()) swap(part[0], part[1]);
    vi ans(n, -1); vb take(n+1, 0); int cur[]={3, 1, 2};
    if(part[0].size()<(n+2)/3) {
        for(int idx: part[0]) ans[idx]=cur[0], take[cur[0]]=1, cur[0]+=3;
    }
    else {
        for(int idx: part[0]) {
            if(cur[1]<=n) ans[idx]=cur[1], take[cur[1]]=1, cur[1]+=3;
            else ans[idx]=cur[0], take[cur[0]]=1, cur[0]+=3;
        }
    }
    int ptr=1;
    for(int idx: part[1]) {
        while(take[ptr]) ptr++;
        ans[idx]=ptr;
        take[ptr]=1;
    }
    for(int it: ans) cout<<it<<' '; cout<<endl;
}


Measured memory_bytes: 25332
#include <iostream>
#include <string>

using namespace std;

int main(void) {
    string n;
    cin >> n;
    for(int i=0; i<3; i++) {
        if(n.at(i) == '1') {
            n.at(i) = '9';
        } else {
            n.at(i) ='1';
        }
    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define forne(i, a, b) for(int i=a; i<=(int)(b); i++)

#define gottagofast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
using namespace std;

#define MAX (int)(2e5)

int tabela[MAX];
vi v;
int k;

int dp(int idx) {
  if(idx == 0)
    return 0;

  if(tabela[idx] != -1)
    return tabela[idx];

  int v1 = abs(v[idx] - v[idx-1]) + dp(idx-1);
  for(int i = 1; i <= k and (idx-i) >= 0; i++) {
    v1 = min(v1, abs(v[idx] - v[idx-i]) + dp(idx-i));
  }


  return tabela[idx] = v1;
}

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

  memset(tabela, -1, sizeof(tabela));

  v.assign(n, 0);
  forn(i, n)
    cin >> v[i];

  cout << dp(n-1) << endl;

  return 0;
}


Measured memory_bytes: 9216
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
#sort = sorted(a)[::-1] 降順
l, r, d= map(int, input().split())
ans =0 

for i in range(l,r+1):
    if i % d == 0:
        ans +=1

print(ans)


Measured memory_bytes: 9152
N,M=[int(i) for i in input().split()]

AC,WA=[False]*N,[0]*N
panel=0
for i in range(M):
    p,s=input().split()
    p=int(p)-1
    if AC[p]:
        continue
    if s=="WA":
        WA[p]+=1
    else:
        AC[p]=True
        panel+=WA[p]

ac=sum(AC)
print(ac,panel)

Measured memory_bytes: 4724
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
int n, q;
vector<int> a(50);
bool func(int m, int id){
  if(m < 0) return false;
  if(m == 0) return true;
  if(id == 0) return false;
  return func(m, id - 1) || func(m - a[id - 1], id - 1);
}

void solve(){
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  cin >> q;
  vector<int> m(q);
  for(int i = 0; i < q; i++){
    cin >> m[i];
  }

  for(int i = 0; i < q; i++){
    if(func(m[i], n) == true) cout << "yes\n";
    else cout << "no\n";
  }
  return;
}

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




Measured memory_bytes: 3108