akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

const int N = 2e3 + 10;

int n, K, ans, siz[N];
int f[N][N], h[N];
vector<int> g[N];

void dfs(int u, int fa) {
  siz[u] = 1;
  for (auto v : g[u]) {
    if (v == fa) continue;
    dfs(v, u);
    for (int i = 0; i <= min(K, siz[u]); i++) {
      h[i] = min(h[i], f[u][i] + siz[v]);
      for (int j = 0; j <= min(K, siz[v]); j++) {
        if (i + j + 1 <= K) {
          h[max(i, j + 1)] = min(h[max(i, j + 1)], f[u][i] + f[v][j]);
        }
      }
    }
    siz[u] += siz[v];
    for (int k = 0; k <= min(K, siz[u]); k++) {
      f[u][k] = h[k];
      h[k] = n;
    }
  }
  // cout<<u<<"+++"<<endl;
  for (int k = 0; k <= K; k++) {
    // cout<<k<<" "<<f[u][k]<<" "<<n - siz[u]<<endl;
    ans = min(ans, f[u][k] + n - siz[u]);
  }
}

int main() {
  scanf("%d %d", &n, &K);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      f[i][j] = n;
    }
  }
  for (int i = 0; i <= n; i++) {
    h[i] = n;
  }
  ans = n;
  dfs(1, 0);
  printf("%d\n", ans); 
  return 0;
}

Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//

int main() {
	int n, a;
	cin >> n >> a;
	cout << n * n - a << endl;
	return 0;
}

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

string join(const deque<string>& v, const char* delim = 0) {
  string s;
  if (!v.empty()) {
    s += v[0];
    for (decltype(v.size()) i = 1, c = v.size(); i < c; ++i) {
      if (delim) s += delim;
      s += v[i];
    }
  }
  return s;
}

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
   	string s,c;
    int q,t,f;
    bool left_begin = true;
    cin >> s >> q;
    deque<string> left;
    deque<string> right;
    for(int i = 0; i < q; ++i){
        cin >> t;
        if (t == 1){
            left_begin = !left_begin;
        }else{
            cin >> f >> c;
            if ((left_begin && f == 1) || (!left_begin && f == 2)){
                left.push_front(c);
            } else{
                right.push_back(c);
            }
        }
    }
    s = join(left) + s + join(right);
    if (!left_begin){
        reverse(s.begin(),s.end());
    }
    cout << s;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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 mod = 1e9+7;
int main()
{
	ll n;
	cin >> n;
	vector<ll> count(n+1,0);
	// O(N)しかない
	ll ans = 0;
	for(int i = 1; i <= n; i++){
		ans += i*(count[i]+1);
		for(int j = i; j <= n; j += i){
			count[j]++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 81400
#include <stdio.h>

void printArr(int *arr, int size)
{
	for (int i = 0; i < size; i++)
	{
		if (i != 0)printf(" ");
		printf("%d", arr[i]);
	}
	printf("\n");
}

void insertionSort(int *arr,int size)
{
	for (int i = 1; i < size; i++)
	{
		int j = i-1;
		int v = arr[i];
		while (j >= 0 && arr[j]>v)
		{
			arr[j + 1] = arr[j];
			j--;
		}
		arr[j + 1] = v;
		printArr(arr, size);
	}
}

int main()
{
	int arr[100];
	int N = 0;
	
	scanf("%d", &N);
	for (int i = 0; i < N; i++)scanf("%d", &arr[i]);

	printArr(arr,N);
	insertionSort(arr, N);

    return 0;
}

Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define M 1000000007
#define fors(i,n) for(int i=0;i<n;++i)
#define fore(i,a,b) for(int i=a;i<=b;++i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vv vector<int>
#define endl "\n"
#define test(i) cout<<i<<endl
#define tests(i) cout<<"i: "<<i<<endl;
#define itrt int t; cin>>t; fors(i,t)
#define itr1 int t; cin>>t;
#define ff first
#define ss second
#define pb push_back
#define vmp make_pair
#define ppb pop_back
#define sorta(a,n) sort(arr,arr+n)
#define sortv(x) sort(x.begin(),x.end())
void file(){
    #ifdef LOCAL
    freopen("demo.in","r",stdin);
    freopen("demo.out","w",stdout);
    #endif
}
bool sortdes(const pair<int,int> &a, const pair<int,int> &b){return a.ss<b.ss;}
bool sortasc(const pair<int,int> &a, const pair<int,int> &b){return a.ss>b.ss;} 
int gcd(int x,int y){return __gcd(x,y);}
// lld fact(lld n);
// lld nCr(lld n,lld r){return fact(n) / (fact(r) * fact(n - r));}
// lld fact(lld n){ lld res = 1; for(lld i = 2; i <= n; i++){res = res * i;}return res;} 
// const int maxi = 1e6+10;
// vector<int> v[maxi];
// long long a[maxi];
// void dfs(int x,int y){
//     a[x]+=a[y];
//     for(int i:v[x]){
//         if(i!=y){
//             dfs(i,x);
//         }
//     }
// }

void test_case(){
    int n;
    cin>>n;
    vv v(n);
    for(int i=0;i<n;++i){
        cin>>v[i];
    }
    int flag=1;
    if(v[0]<v[1]){--v[1];}
    for(int i=2;i<n;++i){
        if(v[i-1]<v[i]){
            --v[i];
            // break;
        }
    }
    for(int i=0;i<n-1;++i){
        if(v[i]>v[i+1]){
            flag=0;
            break;
        }
    }
    if(flag){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}

int main(){
    fastio;
    file();
    int T=1;
    // int T;
    // cin>>T;
    for(int nr=1;nr<=T;++nr) {
        // cout<<"Case #"<<nr<<": ";
		test_case();
    }
}

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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c)

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

int has[1005];

int a[6][6];

int main()
{
  ios::sync_with_stdio(0);
  
  for(int i = 0 ; i < 3; i++)
    for(int j = 0; j < 3; j++)
      cin >> a[i][j];
  int n;
  cin >> n;
  for(int i= 0; i < n; i++)
  {
    int b;
    cin >> b;
    has[b] = 1;
  }

  string ans = "No";

  for(int i = 0 ; i < 3; i++)
  {
    if(has[a[i][0]] && has[a[i][1]] && has[a[i][2]])
      ans = "Yes";
    if(has[a[0][i]] && has[a[1][i]] && has[a[2][i]])
      ans = "Yes";
  }

  if(has[a[2][0]] && has[a[1][1]] && has[a[0][2]])
    ans = "Yes";

  
  if(has[a[2][2]] && has[a[1][1]] && has[a[0][0]])
    ans = "Yes";

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
use proconio::input;
use std::fmt::Write;

fn main() {
    input! {
        n: usize,
    }

    let mut sum = 0;
    let mut diff = None;
    let mut max = None;
    for i in 1..=n {
        sum += i;
        if sum >= n {
            diff = Some(sum - n);
            max = Some(i);
            break;
        }
    }

    let mut ans = String::new();
    if let (Some(diff), Some(max)) = (diff, max) {
        for i in 1..=max {
            if i == diff {
                continue;
            }
            writeln!(ans, "{}", i).unwrap();
        }
    }
    print!("{}", ans);
}


Measured memory_bytes: 2136
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstdio>
#include<climits>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
	bool f=0;int x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return !f?x:-x;
}
#define MAXN 100000
#define INF 0x3f3f3f3f
int fa[MAXN+5];
vector<int> G[MAXN+5];
int Find(int u){return fa[u]==u?u:fa[u]=Find(fa[u]);}
int out[MAXN+5];
void DFS(int u,int f){
	for(int i=0;i<(int)G[u].size();i++){
		int v=G[u][i];
		if(v==f) continue;
		DFS(v,u);
		if(out[v]&1){
			out[v]++;
			printf("%d %d\n",v,u);
		}
		else{
			out[u]++;
			printf("%d %d\n",u,v);
		}
	}
	return ;
}
int main(){
	int n=read(),m=read();
	if(m&1){
		puts("-1");
		return 0;
	}
	for(int i=1;i<=n;i++)
		fa[i]=i;
	for(int i=1;i<=m;i++){
		int u=read(),v=read();
		if(Find(u)!=Find(v)){
			G[u].push_back(v);
			G[v].push_back(u);
			fa[Find(u)]=Find(v);
		}
		else{
			out[u]++;
			printf("%d %d\n",u,v);
		}
	}
	DFS(1,0);
	return 0;
}


Measured memory_bytes: 14208
#include <bits/stdc++.h>
using namespace std;
long long n,i,s;
pair <long long,long long> mas[1000001];
int main() {
    cin>>n;
    for (i=1;i<=n;i++)
        cin>>mas[i].second>>mas[i].first;
    sort(mas+1,mas+n+1);
    for (i=1;i<=n;i++) {
        s+=mas[i].second;
        if (s>mas[i].first)
        {

            cout<<"No"<<endl;return 0;
        }
    }cout<<"Yes"<<endl;
}


Measured memory_bytes: 4352
import java.util.*;
import java.util.Collections;
public class Main {
	public static void main(String[] args){
 
      Scanner sc = null;
      sc = new Scanner(System.in);
      int N = sc.nextInt();
      int K = sc.nextInt();
      long sumPrice = 0;
      ArrayList<Integer> pList = new ArrayList<Integer>();
      while(sc.hasNextInt()){
        pList.add(sc.nextInt());
      }
      Collections.sort(pList);
      for(int i=0; i < K; i++){
        sumPrice += pList.get(i);
      }
      System.out.println(sumPrice);
    }
}

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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 2e5 + 5;

int arr[maxr];
int32_t main()
{
	GO;
	int n;
	cin >> n;
	set<int> s;
	unordered_map<int, int> mp;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
		s.insert(arr[i]);
		mp[arr[i]]++;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int x = arr[i];
		bool found = false;
		for (int j = 1; j <= sqrt(x); j++) {
			if (x % j == 0) {
				if (j != x && s.find(j) != s.end() || j == x && mp[j] > 1)
					found = true;
				if (x / j != x && s.find(x / j) != s.end() || x / j == x && mp[x / j] > 1)
					found = true;
			}
		}
		if (!found)
			ans++;
	}
	cout << ans << endl;
	return 0;
}

//!

Measured memory_bytes: 22576
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))
mod = 10 ** 9 + 7
S = sum(A)

res = 0
for i in range(N):
    S -= A[i]
    res += (S % mod) * (A[i] % mod) % mod

print(res % mod)


Measured memory_bytes: 31288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(int I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl

string LCS(string x,string y){
    ll xs,ys;
    xs=x.size();ys=y.size();
    P pa[xs+1][ys+1];
    ll dp[xs+1][ys+1];
    FOR(i,0,xs+1)FOR(j,0,ys+1)dp[i][j]=0;
    FOR(i,0,xs+1){
        FOR(j,0,ys+1){
            if(i==0||j==0)dp[i][j]=0;
            else{
                if(x[i-1]==y[j-1]){
                	dp[i][j]=dp[i-1][j-1]+1;
                	pa[i][j] = {i-1,j-1};
                }else{
                	dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
                	pa[i][j]={i,j-1};
                	if(dp[i-1][j]>dp[i][j-1])pa[i][j]={i-1,j};
                }
            }
        }
    }
    string ans;
    if(x[xs-1]==y[ys-1])ans+=x[xs-1];
    while(1){
    	ll xx = pa[xs][ys].first;
    	ll yy = pa[xs][ys].second;
    	if(xx==0||yy==0)break;
    	if(x[xx-1]==y[yy-1])ans+=x[xx-1];
    	xs = xx;
    	ys = yy;
    }
    REV(ans);
    return ans;
}


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

	string s1,s2;
	cin >> s1 >> s2;
	cout << LCS(s1,s2) << endl;

}

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

struct edge {
  int from, to, cost;
  edge(int f = -1, int t = -1, int c = 0) : from(f), to(t), cost(c) {}
};

int c, n, m, s, d;
int dis[110][11];
vector<edge> g[110];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> c >> n >> m >> s >> d, c) {
    s--, d--;
    for (int i = 0; i < n; i++) g[i].clear();
    for (int i = 0; i < m; i++) {
      int a, b, f;
      cin >> a >> b >> f;
      a--, b--;
      g[a].emplace_back(a, b, f);
      g[b].emplace_back(b, a, f);
    }
    fill_n((int*)dis, 110 * 11, 1 << 30);
    dis[s][c] = 0;
    using P = tuple<int, int, int>;
    priority_queue<P, vector<P>, greater<P>> que;
    que.emplace(0, s, c);
    while (!que.empty()) {
      P u = que.top(); que.pop();
      int dist, curr, tic;
      tie(dist, curr, tic) = u;
      if (dist > dis[curr][tic]) continue;
      for (auto e : g[curr]) {
        int next = e.to;
        if (dis[next][tic] > dis[curr][tic] + e.cost) {
          dis[next][tic] = dis[curr][tic] + e.cost;
          que.emplace(dis[next][tic], next, tic);
        }
        if (tic > 0 && dis[next][tic - 1] > dis[curr][tic] + e.cost / 2) {
          dis[next][tic - 1] = dis[curr][tic] + e.cost / 2;
          que.emplace(dis[next][tic - 1], next, tic - 1);
        }
      }
    }
    int ans = 1 << 30;
    for (int i = 0; i <= c; i++) {
      ans = min(ans, dis[d][i]);
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3172
#! /usr/bin/env python3

Q, H, S, D = list(map(int, input().split()))
N = int(input())
n = N * 4
ans = 0
l = sorted([(Q, 1), (H, 2), (S, 4), (D, 8)], key = lambda x : x[0]/x[1])
for i, j in l:
    if j <= n:
        a = n // j
        n %= j
        ans += a * i
print(ans)



Measured memory_bytes: 3060
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define DEBUG 0 
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;

int main(){
    int r;
    cin>>r;
    cout<<r*r<<endl;
    return 0;
}

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

long long mod = 1000000007LL;

typedef pair<long long, long long> ii;
int main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	string u, t; cin >> u >> t;
	int a, b; cin >> a >> b;
	string s; cin >> s;
	if(s ==  u) a--;
	else b--;
	
	cout << a << " " << b;
	
}


Measured memory_bytes: 256
# coding: utf-8

from collections import Counter, defaultdict

II = lambda: int(input())
MI = lambda: map(int, input().split())


def main():
    N, K = MI()
    C = Counter(MI())
    return N - sum((c for _, c in C.most_common(K)))


if __name__ == "__main__":
    print(main())


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


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


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

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

  int N, K, h, c = 0;

  std::cin >> N >> K;

  for (int i = 0; i < N; i ++) {
    std::cin >> h;

    if (h >= K)
      c ++;
  }

  std::cout << c << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;

const ll mod = 1e9+7;
const int INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;


int main(void){
    ll n; cin >> n; ll ke = 0; int flag = 1;
    while(n >= 10){
        if(n%10!=9)flag = 0;
        n /= 10;
        ke++;
    }
    if(ke == 0)printf("%lld\n", n);
    else {
        if(flag)printf("%lld\n", n + ke * 9);
        else printf("%lld\n", n-1 + ke * 9);
    }
	return 0;
}


Measured memory_bytes: 764
#include <iostream>

using namespace std;

int main(){
    string s;
    cin>>s;
    for(int i=0;i<s.size();i+=2){
        if(s[i]!='h'||s[i+1]!='i'){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 3592
/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>

using namespace std;

#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define Str(x) to_string(x)
#define len(s) (int)s.size()

typedef long long ll;
typedef long double lld;
typedef string str;
typedef unsigned long long ull;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < 1000; i++) {
        string t = to_string(i);
        while (len(t) < 3) {
            t = "0" + t;
        }
        int uk = 0;
        for (auto it : s) {
            if (uk != 3) {
                if (t[uk] == it)
                    uk++;
            }
        }
        cnt += (uk == 3);
    }
    cout << cnt;


    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include <iomanip>

using namespace std;

int main(){
  double x, h, s;

  while(1){
    cin >> x >> h;
    if(x == 0 && h == 0) break;

    s = x*x + 2*x*sqrt(h*h + (x/2)*(x/2));

    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(6);
    cout << s << endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include <cmath>
#include <cstdio>

#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>

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

using namespace std;
typedef long long int ll;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n+2);
  a.at(0) = 0;
  a.at(n+1) = 0;
  rep(i, n) cin >> a.at(i+1);
  vector<ll> sa(n+1);
  rep(i, n+1){
    sa.at(i)=abs(a.at(i)-a.at(i+1));
  }
  ll sum=0;
  for (auto i: sa) sum += i;

  rep(i, n){

    cout << sum  -sa.at(i) -sa.at(i+1) +abs(a.at(i)-a.at(i+2)) << endl;
  }



  return 0;
}

Measured memory_bytes: 2816
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int s = sc.nextInt();

        int count = 0;

        for (int x = 0; x <= k; x++) {
            for (int y = 0; y <= k; y++) {
                int z = s - x - y;
                if (z >= 0 && z <= k)
                    count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21716
n,d=map(int, input().split())

c=[]
for i in range(n):
    tmp1,tmp2=map(int, input().split())
    c.append([tmp1,tmp2])
cnt=0
import math
for i in c:
    cnt+=1 if math.sqrt(i[0]**2+i[1]**2) <= d else 0
print(cnt)

Measured memory_bytes: 39060
#include<bits/stdc++.h>
#include <algorithm> 
#define pb push_back
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
#define skip continue
#define NAME "code"

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef long double ld;

void faster(){
  	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
	cout.tie(NULL);
}

const int MAXN = 5e1 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

ll n, a[4], ans;

int main(){
	faster();

	for(int i = 0; i < 4; ++i){
		cin >> a[i];
		if(i > 0) a[i] = min(a[i - 1] * 2, a[i]);
	}

	cin >> n;

	n *= 4;

	for(int i = 3; i >= 0; --i){
		ans += (n / (1 << i)) * a[i];
		n %= (1 << i);
	}

	cout << ans;

	return 0;
}

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

std::vector<std::vector<long long>> comb(int n) {
  std::vector<std::vector<long long>> v(n + 1,std::vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int main()
{
  int n, a, b;
  std::vector<long long> v;
  
  std::cin >> n >> a >> b;
  
  for(int i = 0; i < n; ++i) 
  {
    long long _v;
    std::cin >> _v;
    v.push_back(_v);
  }
  
  std::sort(v.begin(), v.end(), std::greater<long long>());
  long long s = 0;
  for(int i = 0; i < a; ++i)
  {
    s += v[i];
  }
  //std::cout << (double)s / a << "\n";
  printf("%.6lf\n", (double)s / a);
  
  int l, r;
  {
    auto range = std::equal_range(v.begin(), v.end(), v[a - 1], std::greater<long long>());
    l = std::distance(v.begin(), range.first);
    r = std::distance(v.begin(), range.second);
  }

  long long combination = 0;
  int nn = r - l;
  auto c = comb(nn);
  if(v[0] != v[a - 1])
  {
    int rr = a - l;
    combination += c[nn][rr];
  }
  else
  {
    int e = std::min(b, r);
    for(int aa = a; aa <= e; ++aa)
    {
      int rr = aa - l;
      combination += c[nn][rr];
    }
  }
  std::cout << combination;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/




int N, K; ll X[101010];
vector<ll> mi, pr;
ll sm_mi[101010], sm_pr[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> K;
    rep(i, 0, N) cin >> X[i];

    rep(i, 0, N) {
        if (X[i] <= 0) mi.push_back(-X[i]);
        else pr.push_back(X[i]);
    }
    sort(all(mi));
    sort(all(pr));

    int n = mi.size();
    sm_mi[0] = 0;
    rep(i, 0, n) sm_mi[i + 1] = mi[i];

    int m = pr.size();
    sm_pr[0] = 0;
    rep(i, 0, m) sm_pr[i + 1] = pr[i];

    ll ans = infl;
    rep(i, 0, n + 1) {
        int j = K - i;
        if (0 <= j and j <= m) chmin(ans, sm_mi[i] * 2 + sm_pr[j]);
    }
    rep(i, 0, m + 1) {
        int j = K - i;
        if (0 <= j and j <= n) chmin(ans, sm_pr[i] * 2 + sm_mi[j]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3188
package main

import "fmt"

func main() {
	var k, s int
	fmt.Scan(&k, &s)

	var ans int
	for x := 0; x <= k; x++ {
		if x == s {
			ans++
			break
		}
		for y := 0; y <= k; y++ {
			if z := s - x - y; 0 <= z && z <= k {
				ans++
			}
		}
	}
	fmt.Println(ans)
}


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

int main(){
  int s1,s2,g1,g2;
  cin >> s1 >> s2 >> g1 >> g2;

  int dx= g1- s1;
  int dy= g2- s2;
  
  for(int i=0; i<dx; i++){
    cout << "R";
  }
  for(int i=0; i<dy; i++){
    cout << "U";
  }
  for(int i=0; i<dx; i++){
    cout << "L";
  }
  for(int i=0; i<dy; i++){
    cout << "D";
  }
  cout << "D";
  for(int i=0; i<dx; i++){
    cout << "R";
  }
  cout << "RU";
  for(int i=0; i<dy; i++){
    cout << "U";
  }
  cout << "LU";
  for(int i=0; i<dx; i++){
    cout << "L";
  }
  cout << "LD";
  for(int i=0; i<dy; i++){
    cout << "D";
  }
  cout << "R" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int x, y, r, a;

  scanf("%d %d",&x, &y);

  if(x < y){
    a = x;
    x = y;
    y = a;
  }
  
  r = x % y;

  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }

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

  return 0;
}

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

//var 
long long N,W,dp[101][100001],w[101],v[101],ms = 0,ans;

int main(){
	cin >> N >> W;
	for(int i = 1; i<=N; i++){
		cin >> w[i] >> v[i];
		ms += v[i];
	}
	for(int i = 0; i<=N; i++)for(int j = 0; j<=ms; j++)dp[i][j] = INT_MAX;
	for(int i = 0; i<=N; i++){
		for(int vs = 0; vs<=ms; vs++){
			//cout << i << " " << vs << endl;
			if(vs==0)dp[i][vs] = 0;
			if(i==0)continue;
			dp[i][vs] = dp[i-1][vs];
			if(vs-v[i]<0)continue;
			if(dp[i-1][vs-v[i]]<INT_MAX)dp[i][vs] = min(dp[i][vs],dp[i-1][vs-v[i]]+w[i]);
			//cout << i << " " << vs << " " << dp[i][vs] << endl;
		}
	}for(int i = 0; i<=ms; i++){
		if(dp[N][i]<=W)ans = i;
		//cout << dp[N][i] << endl;
	}cout << ans << endl;
}

Measured memory_bytes: 79232
input = gets.chomp.to_i
person = []
person_name = []
sum = Hash.new(0)
com = []
input.times do |i|
    person[i] = gets.chomp
    person_name[i] = person[i].split(//)
    if person_name[i][0] =~ /[MARCH]/
    sum[person_name[i][0]] += 1
end
end

#p person,sum

count = "MARCH".split("").combination(3).map do |a,b,c|
  sum[a] * sum[b] * sum[c]
  end.inject(:+)
  
 puts count

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

using namespace std;
#define ll long long
#define ld long double
const int N=2e5 + 5;
const ll mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    ll a, b, n;
    cin >> a >> b >> n;
    ll x = min(b - 1, n);
    cout << (ll)(floor(a*x/b) - a*floor(x/b));
    return 0;
}


Measured memory_bytes: 3604
import math
a,b,h,m = map(int,input().split())

k_a = 0.5*m + 30*h
k_b = 6*m
c = math.radians(abs(k_a-k_b))
l = (a**2+b**2-2*a*b*math.cos(c))**.5
print(l)


Measured memory_bytes: 9492
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#define PI acos(-1.0)
using namespace std;
int main(){
	int n;
	cin >> n;
	int ans = n % 10;
	if(ans == 3){
		cout << "bon";
	}
	else if( ans == 0 || ans == 1 || ans == 6 || ans == 8){
		cout << "pon";
	} else{
		cout << "hon";
	}
	return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>

int c[2000001];
int d[2000001];
int main(void){
	int N,M;
	scanf("%d%d",&N,&M);
	int i,j;
	int a[M],b[M];
	int ccount = 0,dcount=0;
	for(i=0;i<M;i++){
		scanf("%d%d",&a[i],&b[i]);
		//1からいける島をc[i]に保存する
		//Nからいける島をd[i]に保存する
		if(a[i]==1)c[b[i]]=1;
		if(b[i]==N)d[a[i]]=1;
	}
	for(i=1;i<=N;i++){
		if(c[i]==d[i]&&c[i]==1){
			printf("POSSIBLE");
			return 0;
		}
	}
	printf("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#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 rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    vector<int> x(5);
    rep(i,5) cin >> x[i];
    rep(i,5){
        if(x[i]==0) cout << i+1 << endl;
    }
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

#define frs first
#define scn second
#define phb push_back
#define ppb pop_back
#define mkp make_pair

using namespace std;

typedef pair< int, int > Pr;
typedef pair< int, Pr > Trp;

int N, M;
string txt[10], ptr[10];

void read();
void soups_on();
vector< int > yee_haw(vector< Trp >, string [], int);

bool not_dot(const char &);

int main() {
  ios::sync_with_stdio(false);
  while (cin >> N >> M, N + M)
    read(), soups_on();

  return 0;
}

void read() {
  for (int i = 0; i < N; ++i)
    cin >> txt[i];
  for (int i = 0; i < M; ++i)
    cin >> ptr[i];
}

void soups_on() {
  vector< int > p, q, t;
  vector< Trp > tmp, res;

  for (int i = 0; i < N; ++i)
    p.phb(int(find_if(txt[i].begin(), txt[i].end(), not_dot) - txt[i].begin()));

  for (int i = 1; i <= 20; ++i)
    for (int j = 1; j <= 20; ++j)
      for (int k = 1; k <= 20; ++k) {
        tmp.phb(mkp(i, mkp(j, k)));
        t = yee_haw(tmp, txt, N);

        bool is_valid = true;
        for (int c = 0; c < N && is_valid; ++c)
          if (p[c] != t[c])
            is_valid = false;
        if (is_valid)
          res.phb(mkp(i, mkp(j, k)));

        tmp.ppb();
      }

  q = yee_haw(res, ptr, M);
  for (int i = 0; i < M; ++i) {
    if (i > 0) cout << " ";
    cout << q[i];
  }
  cout << "\n";
}

vector< int > yee_haw(vector< Trp > t, string p[], int k) {
  vector< int > ret;
  int c[3], f;

  fill(&c[0], &c[3], 0);
  for (int i = 0; i < k; ++i) {
    vector< int > pv;

    for (int j = 0; j < int(t.size()); ++j) {
      f = c[0] * t[j].frs + c[1] * t[j].scn.frs + c[2] * t[j].scn.scn;
      pv.phb(f);
    }

    stable_sort(pv.begin(), pv.end());
    pv.erase(unique(pv.begin(), pv.end()), pv.end());

    if (int(pv.size()) > 1)
      ret.phb(-1);
    else
      ret.phb(pv[0]);

    c[0] += count(p[i].begin(), p[i].end(), '(');
    c[0] -= count(p[i].begin(), p[i].end(), ')');
    c[1] += count(p[i].begin(), p[i].end(), '[');
    c[1] -= count(p[i].begin(), p[i].end(), ']');
    c[2] += count(p[i].begin(), p[i].end(), '{');
    c[2] -= count(p[i].begin(), p[i].end(), '}');
  }

  return ret;
}

bool not_dot(const char &rc) {
  return rc != '.';
}

Measured memory_bytes: 1380
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<pi,null_type,less<pi>,rb_tree_tag,tree_order_statistics_node_update> indexed_set_pair;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)1e7+5;
const int M = (int)1e3+5;
const int Q = 102;
const int logN = 19;

const double pie = acos(-1);

int sieve[N];
void solve() {
    REP(i,1,N-1) {
        for(int j=i;j<N;j+=i) {
            sieve[j]++;
        }
    }
    int n;
    cin>>n;
    ll ans = 0;
    REP(i,1,n) {
        ans += (ll)i*sieve[i];
    }
    cout<<ans;
}
int main() {
    //freopen("./sort/b2.in","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 42696
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
#ifndef __COMBINATIONS_INCLUDED_
#define __COMBINATIONS_INCLUDED_
ll C(ll n, ll k) {
    if(k < 0) return 0;
    if(k == 0 or k == n) return 1;
    if(n >= 0) k = min(k, n - k);
    ll ans = 1, j = 2;
    for(ll i = 0; i < k; i++) {
        ans *= n - i;
        while(j <= k and ans % j == 0) {
            ans /= j;
            j++;
        }
    }
    return j == (k + 1) ? ans : 0;
}
#endif
ll pow(int x, int y) {
    int ans = 1;
    while(y--) {
        ans *= x;
    }
    return ans;
}
int nonzeros(int n) {
    return int(n % 10 != 0) + int(n / 10 % 10 != 0) + int(n / 100 % 10 != 0);
}
int get(string& N, ll K) {
    int ans = 0;
    for(int i = 0; i < K; i++) {
        ans *= 10;
        ans += N[i];
    }
    return ans;
}
ll solve(std::string N, long long K) {
    if(K == 0) {
        return 1;
    } else if(N.size() < K) {
        return 0;
    } else {
        ll ans = 0;
        for(int i = 0; i < pow(10, K); i++) {
            int nonzero_left = K - nonzeros(i);
            if(i < get(N, K)) {
                ans += C(N.size() - K, nonzero_left) * pow(9, nonzero_left);
            } else if(i == get(N, K)) {
                ans += solve(N.substr(K), nonzero_left);
            }
        }
        return ans;
    }
}
int main() {
    std::string N;
    std::cin >> N;
    for(char& c : N) {
        c -= '0';
    }
    long long K;
    scanf("%lld",&K);
    cout << solve(N, K) << endl;
    return 0;
}


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



int main() {
    int n;
    cin >> n;
    vector<int> L;
    for(int i = 0;i<n;i++){
      int yomi;cin>>yomi;
      L.push_back(yomi);
    }
    sort(L.begin(), L.end());
    reverse(L.begin(),L.end());
    int a,b,c;
    int ko;
    for(int i = 0;i<n-2;i++){
        c = L[i];
    	for(int j = i+1;j<n-1;j++){
          b= L[j];
        	for(int h = j+1;h<n;h++){
              a=L[h];
              if(c <(a+b)) ko++;
              else break;                
            }
        
        } 
    }
    cout<<ko;
    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 x = scan.nextInt();
		boolean f = false;
		if (a <= x && a+b >= x) {
			f = true;
		}
		if (f) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 21972
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<sstream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<bitset>
#include<set>
#include<stack>
#include<queue>
#include<iomanip>
#include<memory.h>
#include<complex>
using namespace std;  

// type
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tuple<int,int> tii;

// define & const valur
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-9;
const double PI = M_PI; 
#define DIV int(1e9+7)
// for debug 
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
// useful func
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
 
/* Coding Space*/
const ll target = ll(1e12) * 2;
int main(){
  int n,k; cin >> n >> k;
  int ans = 1;
  rep(i,n){
    if(ans * 2 - ans > k)
      ans += k;
    else
      ans *= 2;
  }
  cout << ans << endl;
}

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

namespace ABC075B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var h = input[0];
            var w = input[1];

            var board = new List<char[]>();
            var dummy = new char[w + 2];
            for(int i = 0; i < w + 2; i++)
            {
                dummy[i] = '.';
            }

            board.Add(dummy);
            for(int i = 0; i < h; i++)
            {
                board.Add($".{Console.ReadLine()}.".ToCharArray());
            }
            board.Add(dummy);

            var result = new int[h, w];
            for(int i = 1; i <= h; i++)
            {
                for(int j =1;j<= w; j++)
                {
                    result[i - 1, j - 1] = 0;
                    if(board[i][j] == '#')
                    {
                        result[i - 1, j - 1] = -1;
                        continue;
                    }

                    for(int k = -1; k <= 1; k++)
                    {
                        for (int l = -1; l <= 1; l++)
                        {
                            if(board[i+k][j+l] == '#')
                            {
                                result[i - 1, j - 1]++;
                            }
                        }
                    }
                }
            }

            for(int i = 0; i < h; i++)
            {
                for(int j = 0; j < w; j++)
                {
                    Console.Write(result[i, j] == -1 ? "#" : result[i, j].ToString());
                }
                Console.WriteLine();
            }
        }
    }
}


Measured memory_bytes: 13268
// 6/14 リアルタイム参加
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
// char alphabet[26] = {'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y'};

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

    // N--;
    // while (N >= 26) {
    //     a.push_back(N%26);
    //     N /= 26;
    // }
    // N--;

    // a.push_back(N%26);
    // if (a[0] == 0) a[0] = 25;
    // N /= 26;
    // N -= 1;

    // N--;

    while (N > 0) {
        // if (N==26) {
        //     // a.push_back();
        //     break;
        // }
        N--;
        a.push_back(N % 26);
        // N -= (N % 26);
        N /= 26;
        // N--;
    }

    reverse(a.begin(), a.end());

    for (int i = 0; i < a.size(); i++) {
        // if (a[i] == 0) cout << alphabet[25] << endl;
        // cout << a[i] << endl;
        cout << alphabet[a[i]];
    }

    cout << endl;
    



}


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

using namespace std;

#define ll long long
#define rep(i,N) for(ll i=0; i<N; i++)
const int mx = 2e5;

int main(){
  ll n,R=0,G=0,B=0;
  string S;
  cin >> n;
  cin >> S;
  
  rep(i,n){
    if(S[i]=='R') R++;
    if(S[i]=='G') G++;
    if(S[i]=='B') B++;
  }
  
  ll kazu=0;
  rep(i,n-2){
    for(ll j=i+1; j<n-1; j++){
      ll k = j + (j-i);
      if(k<n){
        if(S[i]!=S[j] && S[j]!=S[k] && S[k]!=S[i]) kazu++;
      }
    }
  }
  
  //cout << R<<" "<<G<<" "<<B<<" "<<kazu;
  cout << R*G*B-kazu;
  
  return 0;
}


Measured memory_bytes: 3588
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(S, s) S.find(s) != string::npos

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int mi = min({ a,b,c }), ma = max({ a,b,c });
	cout << mi << " " << a + b + c - mi - ma << " " << ma << endl;
	return 0;
}


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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var calculator = new Calculator(N, 3);

            for (int i = 0; i < N; i++)
            {
                var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
                for (int j = 0; j < 3; j++)
                {
                    calculator.Values[i, j] = input[j];
                }
            }

            Console.WriteLine(calculator.Ans());
        }
    }

    class Calculator
    {
        private int maxDay;
        private int[,] dp;
        public int[,] Values { get; set; }

        public Calculator(int N, int type)
        {
            maxDay = N - 1;
            dp = new int[N, type];
            Values = new int[N, type];
        }

        private int Calc(int day, int type)
        {
            if (day > maxDay) return 0;
            if (dp[day, type] != 0) return dp[day, type];

            if (type == 0) dp[day, type] = Math.Max(Calc(day + 1, 1), Calc(day + 1, 2)) + Values[day, type];
            if (type == 1) dp[day, type] = Math.Max(Calc(day + 1, 0), Calc(day + 1, 2)) + Values[day, type];
            if (type == 2) dp[day, type] = Math.Max(Calc(day + 1, 0), Calc(day + 1, 1)) + Values[day, type];

            return dp[day, type];
        }

        public int Ans()
        {
            return Math.Max(Calc(0, 0), Math.Max(Calc(0, 1), Calc(0, 2)));
        }
    }
}


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

#ifdef _LOCAL
  #include <debug.hpp>
  #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
  #define debug(...) 42
#endif

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vl2;
const bool multiple_queries = false;
#define rep(i, n) for(ll i = 0; i < (n) ; ++i)
#define For(i, a, b) for(ll i = (a); i < (b) ; ++i)
#define revrep(i, n) for(ll i = (n) - 1; i >= 0 ; --i)
#define revFor(i, b, a) for(ll i = (b) - 1; i >= (a) ; --i)
#define all(v) v.begin(), v.end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(i) __builtin_popcountl((i))
#define substring(s, start, end) s.substr((start), (end) - (start) + 1)

void print(){cout;}
void println(){cout << endl;}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T>& vs){
  for (auto v: vs){
    cout << v;
    if (&v != &vs.back()) cout << " ";
  }
  cout << endl;
}

template <class Head, class... Tail>
void println(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  println(forward<Tail>(tail)...);
}

template <class T>
void println(vector<T>& vs){for (auto v: vs) cout << v << endl;}

void solve(){
  ll ans = 0, n;
  cin >> n;

  For(i, 1, n + 1)
    for (int v = i; v <= n; v += i)
      ans += v;

  debug(ans);
  println(ans);
}

void test(ll num = 0, bool verbose = false){
  rep(i, max(1LL, num)){
    ll t = clock();
    if (verbose) cout << "\n#####" << " " << i + 1 << " " << "#####" << " " << "\n## Answer ##\n";
    solve();
    if (verbose) {cout << "\nElapsed Time:" << " " << 1000.0 * (clock() - t) / CLOCKS_PER_SEC << " " << "[ms]" << endl;}
  }
}

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  #ifdef _LOCAL
    test(6, true);
  #else
    ll t = 0;
    if (multiple_queries) cin >> t;
    test(t, false);
  #endif
  return 0;
}

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

void dfs(ll a,ll b,ll c,ll k,bool *f){
    if(k==0){
        if(a<b&&b<c) *f=1;
    }else{
        dfs(a*2,b,c,k-1,f);
        dfs(a,b*2,c,k-1,f);
        dfs(a,b,c*2,k-1,f);
    }
}

int main(){
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    bool f=0;
    dfs(a,b,c,k,&f);
    if(f) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3632