akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main(){
    int A[1000],N,M,i;
    int sum,count;
    sum=0;count=0;
    scanf("%d%d",&N,&M);
    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
        sum+=A[i];
    }
    for(i=0;i<N;i++){
        if(A[i]*4*M>=sum)
            count++;
        if(count>=M){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");

    

return 0;
}

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

int n;
map<int, int> cnt;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for(int i = 0; i < n; i++){
		int val;
		cin >> val;
		cnt[val]++;
	}
	bool dist = true;
	for(auto i : cnt)
		if(i.second > 1) dist = false;
	cout << (dist ? "YES\n" : "NO\n");
	return 0;
}

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

N = int(input().split()[0])
h_list = list(map(int, input().split()))

# 最小値を求める問題なので、infで初期化する
dp_list = [float("inf") for _ in range(N)]
dp_list[0] = 0

for i in range(1, N):
    if i - 1 >= 0:
        cost_1 = abs(h_list[i - 1] - h_list[i])
        min_cost = min(dp_list[i], dp_list[i - 1] + cost_1)

    if i - 2 >= 0:
        cost_2 = abs(h_list[i - 2] - h_list[i])
        min_cost = min(min_cost, dp_list[i - 2] + cost_2)

    dp_list[i] = min_cost

ans = dp_list[N - 1]
print(ans)


Measured memory_bytes: 13908
N = int(input())
AB = sorted([[int(_) for _ in input().split()] for _ in range(N)],
            key=lambda x: x[1],
            reverse=True)
CD = sorted([[int(_) for _ in input().split()] for _ in range(N)])
 
for i in range(N):
    for j in range(len(AB)):
        if AB[j][0] < CD[i][0] and AB[j][1] < CD[i][1]:
            AB.pop(j)
            break
print(N - len(AB))

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
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;}

struct UnionFind {
    
    vector < int > node;
    UnionFind(int n) : node(n, -1) {}
    
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (node[y] < node[x]) swap(x, y);
            node[x] += node[y];
            node[y] = x;
        }
        return x != y;
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    int root(int x) {
        return node[x] < 0 ? x : node[x] = root(node[x]);
    }
    
    int size(int x) {
        return -node[root(x)];
    }
    
};
/*
 usage:
 
 初期化:
 UnionFind  UF(N);//ノードの数
 unite(x,y);// xとyノード連結
 same(a,b);// aとbが同じ所属かどうかを判別
 root(a); //aのルートのノードを計算
 */

vector<ll> grouproot;
vector<ll> p;
map<ll, vector<ll> > memb;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N, M; cin >> N >> M ;
    UnionFind UF(N);

    rep(i,N){
        ll inp; cin >> inp;
        inp--;
        p.pb(inp);
    }
    
    
    rep(i,M){
        int x, y;
        cin >> x >> y;
        x--; y--;
        UF.unite(x, y);
    }
    
    rep(i,N){
        ll head = UF.root(i);
        grouproot.pb(head);
        memb[head].pb(i);
    }
    
    rmsame(grouproot);
    
    ll ans = 0;
    rep(i,grouproot.size()){
        vector<ll> num;
        ll head = grouproot[i];
        rep(j, memb[head].size()){
            num.pb(memb[head][j]);
            num.pb(p[memb[head][j]]);
        }
        ll si = num.size();
        rmsame(num);
        ans += si- num.size();
    }

    cout << ans << endl ;
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


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

using ll = long long;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (ll i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (ll i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

template<typename T> using pop_max = std::priority_queue<T>;
template<typename T> using pop_min = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T> void LOG(const T& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T> void LOG(const vector<vector<T>>& a) { for (const auto& x : a) LOG(x); }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

ll ceil(ll a, ll b) { return a > 0 ? (a - 1) / b + 1 : a / b; }
ll gcd(ll a, ll b) { while (b != 0) { ll t = b; b = a % b; a = t; } return a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll gcd(const vector<ll>& v) { return accumulate(v.begin(), v.end(), 1LL, static_cast<ll(*)(ll, ll)>(gcd)); }
ll lcm(const vector<ll>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<ll(*)(ll, ll)>(lcm)); }
ll pow(ll x, ll y, ll z) { ll a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
ll inv(ll x, ll m) { return pow(x, m - 2, m); }

template<typename T> bool chmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<typename T> bool chmin(T& x, const T& y) { return x > y ? x = y, true : false; }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_cpp;

const ll INF = inf<ll>;
using P = pair<ll, ll>;
const ll M = 1000000007;
signed main() {
    ll n;
    cin>>n;
    vector<ll> A(n);
    cin>>A;
    vector<ll> C(n+1);
    for(ll a:A){
        C[a]++;
    }
    ll s=0;
    for(ll a=1;a<=n;a++){
        s+=C[a]*(C[a]-1)/2;
    }
    for(ll k=1;k<=n;k++){
        cout<<(s-C[A[k-1]]+1)<<endl;
    }
}


Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <algorithm>
#include <utility> 
#include <unordered_set>
#include <vector>
#include <list> 
#include <string>
#include <iterator> 
#include <deque>
#include <array>
#include <forward_list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <bitset>
#include <numeric>
using namespace std;


const long double PI = 3.14159265358979323846264338327950;
const int N = 1e5+5;

template <class T>
T gcd(T a, T b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int n, x, y, m, d;
	cin >> n;
	vector<int> p(n), q(n);
	vector<int> arr(n);
	for (int i = 0; i < n; ++i)
		cin >> p[i];
	for (int i = 0; i < n; ++i) {
		cin >> q[i];
		arr[i] = i + 1;
	}
	
	x = y = -1;
	m = 1;
	do {
		if (x == -1) {
			d = 0;
			for (int i = 0; i < n; ++i)
				d += abs(arr[i] - p[i]);
			if (d == 0) x = m;
		}

		if (y == -1) {
			d = 0;
			for (int i = 0; i < n; ++i)
				d += abs(arr[i] - q[i]);
			if (d == 0) y = m;
		}

		if (x > 0 && y > 0)
			break;
		++m;
	} while (next_permutation(arr.begin(), arr.end()));

	cout << abs(x - y) << '\n';
}
		

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  string ans;
  while(A > 0 && C > 0) {
    C -= B;
    if (C <= 0) {
      ans = "Yes";
      break;
    }
    A -= D;
    if (A <= 0) {
      ans = "No";
      break;
    }
  }
  cout << ans << endl;
}

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

int main()
{
    int n, s, cnt=0;
    cin >> n >> s;
    for(int i = 0; i <= n; i++)
    {
        for(int j = 0; j <= n; j++)
        {
            int sum=i+j;
            if(n>=s-sum and s-sum>=0) cnt++;
        }
    }
    cout << cnt;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
vector<int>v[MAX];
string make(int a)
{

    string s;
    int sz=0;
    while(a>0)
    {
        s+=(a%10)+48;
        a/=10;
        sz++;
    }
    reverse(all(s));
    string ans="";
    for(int i=0; i<6-sz; i++)
        ans+='0';
    ans+=s;
    return ans;
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,m;
    cin>>n>>m;
    vector<pair<int,int> >st;
    for(int i=0; i<m; i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        st.push_back({a,b});
    }
    for(int i=1; i<=n; i++)
        sort(all(v[i]));
    map<pair<int,int>,string>mp;
    for(int i=1; i<=n; i++)
    {
        string x,y,z;
        x=make(i);
        for(int j=1; j<=v[i].size(); j++)
        {
            y=make(j);
            int a=v[i][j-1];
            mp[{i,a}]=x+y;
        }
    }
    for(int i=0; i<m; i++)
    {
        cout<<mp[{st[i].first,st[i].second}]<<endl;
    }



    return 0;
}


Measured memory_bytes: 38264
k = int(input())

chart = [[0 for _ in range(10)] for __ in range(9)]
chart.insert(0,[1 for _ in range(10)])

for i in range(1,10): # 桁
    for j in range(10): # 最初の数
        if j == 0:
            chart[i][j] = chart[i-1][j] + chart[i-1][j+1]
        elif j == 9:
            chart[i][j] = chart[i-1][j-1] + chart[i-1][j]
        else:
            chart[i][j] = chart[i-1][j-1] + chart[i-1][j] + chart[i-1][j+1]

sum_list = [sum(row[1:]) for row in chart]

count = 0
for i,elem in enumerate(sum_list):
    count += elem
    if count > k:
        idx = i
        diff = k-sum(sum_list[:i]) # idx桁目のdiffばんめ
        break

digit = ''
start = 0
end = 10
first = True

while idx >= 0:
    # print(idx,diff,chart[idx][start:end],start,end)
    count = 0
    if first:
        target_row = chart[idx][start:end]
        target_row[0] = 0
        first = False
    else:
        target_row = chart[idx][start:end]
    for i,num in enumerate(target_row):
        count += num
        if count >= diff:
            digit += str(start+i)
            diff = diff - (count - num)
            idx -= 1
            if start + i == 0:
                start = 0
                end = 2
            elif start + i == 9:
                start = 8
                end = 10
            else:
                s = start
                start = s + i - 1
                end = s + i + 2
            break
        
print(digit)


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,m;
  while(cin>>n>>k>>m,n){
    vector<int> v;
    for(int i=0;i<n;i++)v.push_back(i+1);
    m--;
    k--;
    while(v.size()>1){
      v.erase(v.begin()+m);
      m+=k;
      m%=v.size();
    }
    cout<<v[0]<<endl;
  }
  return 0;
}



Measured memory_bytes: 3244
import qualified Data.Vector.Unboxed as V
main=do
 [n,x]<-map read.words<$>getLine
 let tv=V.iterateN (n+1) ((+3).(*2)) 1
 let pv=V.iterateN (n+1) ((+1).(*2)) (1::Int)
 print$f tv pv n x
f tv pv n x
 |x<=0=0
 |n==0=1
 |x<=(tv V.! n)`div`2=f tv pv (n-1) (x-1)
 |otherwise=(pv V.! (n-1)) + 1 + f tv pv (n-1) (x-2-tv V.! (n-1))

Measured memory_bytes: 508
N = int(input())
S = input()
answer = 0
for i in range(1, N):
    # print(S[:i], S[i:])
    x = list(set(S[:i]))
    y = list(set(S[i:]))
    # print(x)
    # print(y)
    count = 0
    for j in range(len(x)):
        if x[j] in y:
            count += 1
    if answer <= count:
        answer = count

print(answer)

Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
	unsigned long long a,b,a1,b1,c;
	while(scanf("%llu%llu",&a,&b)!=EOF)
	{
		if(a<b)
		{
			a1=b;
			b1=a;
		}
		else
		{
			a1=a;
			b1=b;
		}
		while(1)
		{
			c=a1%b1;
			if(c==0)
				break;
			else
			{
				a1=b1;
				b1=c;
			}
		}
		cout<<b1<<" "<<a*b/b1<<endl;
	}	
	return 0;
}

Measured memory_bytes: 3132
(n,m),*s,p=[list(map(int,t.split()))for t in open(0)]
a=0
for i in range(1<<n):
 c=[0]*m
 for j in range(n*m):c[j%m]^=i>>j//m&(j//m+1in s[j%m][1:])
 a+=c==p
print(a)

Measured memory_bytes: 3060
n = int(input())
a = list(map(int,input().split()))
a.sort()
amax = a[-1]
flags = [True] * amax

prev = -1

cnt = 0
for idx in range(n):
    i = a[idx]
    if prev == i: continue
    if flags[i-1]: 
        cnt += 1
        if idx < n-1:
            if i == a[idx+1]:
                cnt -= 1
    ax = i + i
    while ax <= amax:
        flags[ax-1] = False
        ax += i
    prev = i
print(cnt)


Measured memory_bytes: 32224
mod = 10**9+7

n = int(input())
s = input()
# 配るDPの初期値を入れておく
dp = [1]*n
for i in range(n-1):
    nxt = [0]*(n+1)
    # 前の相対順位は
    # [0, n-1-i]
    # 次の相対順位は
    # [0, n-2-i]
    # 今の順位がjのとき、
    # < → [i, n-2-i]に加算
    # > → [0, j-1]に加算
    for j in range(n-i):
        if s[i] == "<":
            left = j
            right = n-1-i
        else:
            left = 0
            right = j
        if left >= right:
            continue
        nxt[left] += dp[j]
        nxt[right] -= dp[j]
    for j in range(n):
        nxt[j+1] += nxt[j]
        nxt[j+1] %= mod
    dp = nxt
ans = sum(dp)%mod
print(ans)


Measured memory_bytes: 43996
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

#define MAX_LEN 1000

int LevenshteinDistance(string str1, string str2) {
	int dp[MAX_LEN+1][MAX_LEN+1];
	int i1, i2, cost = 0;
	for (int i = 0; i <= str1.length(); i++)
		dp[i][0] = i;
	for (int i = 0; i <= str2.length(); i++)
		dp[0][i] = i;

	for (i1 = 1; i1 <= str1.length(); i1++) {
		for (i2 = 1; i2 <= str2.length(); i2++) {
			cost = (str1[i1] == str2[i2]) ? 0 : 1;
			dp[i1][i2] = min(dp[i1-1][i2] + 1,			// insert
							 min(dp[i1][i2 - 1] + 1,	// delete
							 	 dp[i1-1][i2-1] + cost)	// replace
							);
		}
	}
	return dp[str1.length()][str2.length()];
}

int minimum(int a, int b, int c)
{
	return a > b ? (b > c ? c : b) : (a > c ? c : a);
}

int LevenshteinDistance2(string str1, string str2) {
	int lenstr1 = str1.length();
	int lenstr2 = str2.length();
	int d[lenstr1+1][lenstr2+1];
	int i1 = 0, i2 = 0, cost = 0;

	for (;i1 <= lenstr1; i1++) d[i1][0] = i1;
	for (;i2 <= lenstr2; i2++) d[0][i2] = i2;

	for (i1 = 1; i1 <= lenstr1; i1++) {
		for (i2 = 1; i2 <= lenstr2; i2++) {
			cost = str1[i1 - 1] == str2[i2 - 1] ? 0 : 1;
			d[i1][i2] = minimum(d[i1 - 1][i2] + 1, d[i1][i2 - 1] + 1, d[i1 - 1][i2 - 1] + cost);
		}
	}

	return d[lenstr1][lenstr2];
}

int main() {
	string str1, str2;
	cin >> str1 >> str2;

	cout << LevenshteinDistance2(str1, str2) << endl;

	return 0;
}

Measured memory_bytes: 5104
// Ref : https://book.mynavi.jp/ec/products/detail/id=35408

#include <iostream>
#include <algorithm>
#include <limits.h>
using namespace std;

static const int N = 100;;

int main() {
	int n; cin >> n;
	int p[N + 1], m[N + 1][N + 1]; // m_ij is partial LCS between i to j.
	for (int i = 1; i <= n; i++) cin >> p[i - 1] >> p[i];

	for (int i = 1; i <= n; i++) m[i][i] = 0;
	for (int l = 2; l <= n; l++) { // l is a length of partial LCS.
		for (int i = 1; i <= n - l + 1; i++) {
			int j = i + l - 1;
			m[i][j] = INT_MAX;
			for (int k = i; k <= j - 1; k++) {
				m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[j] * p[k]);
			}
		}
	}
	cout << m[1][n] << endl;

	return 0;
}


Measured memory_bytes: 3128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long llong;
int main(){
    llong a, b, k;
    cin >> a >> b >> k;

    if (a > k){
        a -= k;
        k = 0;
    }
    else{
        k -= a;
        a = 0;
    }
    if (b > k) b -= k;
    else b = 0;
    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<(n);i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll
#define MAX 100001
#define INF (int)1e18

template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.F<<','<< P.S<<')';}


int modpow(int a,int n)
{
	int ans=1;
	while(n)
	{
		if(n%2)
			ans=(ans*a)%mod;
		a=(a*a)%mod;
		n/=2;
	}
	return ans;
}

int inv(int a)
{
	return modpow(a,mod-2);
}

int fact[MAX],ifact[MAX];
void ini_fact()
{
	fact[0]=ifact[0]=1;
	for(int i=1;i<MAX;i++)
	{
		fact[i]=(fact[i-1]*i)%mod;
		ifact[i]=inv(fact[i]);
	}
}

int c(int n,int r)
{
	if(r>n)
		return 0;
	return (((fact[n]*ifact[r])%mod)*ifact[n-r])%mod;
}


signed main()
{
	fio
	ini_fact();
	inp(n)
	inp(k)
	inpa(a,n)
	map<int,int> m;
	fo(i,n)
		m[a[i]]++;
	int tot=0;
	int ans=0;
	for(pair<int,int> i:m)
	{
		tot+=i.S;
		ans=(ans+(i.F*(c(tot,k)-c(tot-i.S,k)))%mod)%mod;
	}
	// cerr<<ans<<'\n';
	m.clear();
	fo(i,n)
		m[-a[i]]++;
	tot=0;
	for(pair<int,int> i:m)
	{
		tot+=i.S;
		ans=(ans+(i.F*(c(tot,k)-c(tot-i.S,k)))%mod)%mod;
		// if(tot>=k)
			// ans=(ans+(i.F*c(tot,k))%mod)%mod;
	}
	ans=(ans+mod)%mod;
	cout<<ans<<'\n';
	printclock;
}

Measured memory_bytes: 8320
#include <iostream>

int main()
{
    int h[10];

    for (int i = 0; i < 10; i++)
    {
        std::cin >> h[i];
    }

    for (int i = 0; i < 9; i++)
    {
        for (int n = 0; n < 9 - i; n++)
        {
            if (h[n] < h[n+1])
            {
                std::swap(h[n], h[n+1]);
            }
        }
    }
    
    for (int i = 0; i < 3; i++)
    {
        std::cout << h[i] << std::endl;
    }

    return 0;
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)

int main() {
  string s; cin >> s;
  ll n; cin >> n;
  bool flag = 1;
  rep(i, n) {
    if (s.at(i) != '1') {
      cout << s.at(i) << endl;
      flag = 0;
      break;
    }
  }
  if (flag) cout << 1 << endl;
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define INF 2000000000000000000LL
#define EPS 1e-9
#define debug(a) cerr<<#a<<"="<<(a)<<"\n"
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL);

typedef long long ll;
typedef unsigned long long ull;
typedef complex<double> cd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

void printArray(const int *arr, int n);
void printArray(const vector<int> &arr);

const ll mod = 1e9+7;
const double PI = acos(-1);

int n,i,j,k,t;
int m;
vector<int> adj[100002];
int par[100002];

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

bool union_set(int a, int b){
    a = find_set(a);
    b = find_set(b);
    if(a != b){
        par[b] = a;
        return true;
    }
    return false;
}

int main(){
	scanf("%d %d", &n, &m);
    for(int i=0;i<n;++i)
        par[i] = i;
    int ans = n;
    for(int i=0;i<m;++i){
        int a,b,c;
        scanf("%d %d %d", &a, &b, &c);
        --a, --b;
        adj[a].pb(b);
        adj[b].pb(a);
        if(union_set(a, b)){
            ans--;
        }
    }
    printf("%d\n", ans);
	return 0;
}

/* Template Function */
void printArray(const int * a, int n){
	for(int i=0;i<n;++i){
		printf("%d ", a[i]);
	}
	puts("");
}

void printArray(const vector<int> &arr){
	for(int x : arr){
		printf("%d ", x);
	}
	puts("");
}

Measured memory_bytes: 6520
// https://atcoder.jp/contests/abc123/tasks/abc123_c

#include <iostream>

using namespace std;

using ll = long long;

int main() {
    ll N,A,B,C,D,E;
    cin >> N >> A >> B >> C >> D >> E;
    ll mi = min(min(min(min(A, B), C), D), E);

    // time / people in 6
    // 0 0
    // 1 0
    // 2 0
    // 3 0
    // 4 0
    // 5 mi
    // 6 mi*2
    // 7 mi*3
    auto groups = (N + mi - 1) / mi;
    // (time - 4) == groups
    auto time = groups + 4;
    cout << time << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,m,a[N],f[N];
char s[N];
int getf(int x){return f[x]==x?x:f[x]=getf(f[x]);}
int main()
{
    scanf("%s",s+1);
    n=strlen(s+1);
    for(int i=1;i<=n+1;i++)
        a[i]=(s[i]-s[i-1]+26)%26,f[i]=i;
    n++;
    for(int i=1,j=n;i<j;i++,j--)
    {
        int fi=getf(i),fj=getf(j);
        a[fi]=(a[fi]+a[fj])%26;
        f[fj]=fi;
    }
    scanf("%d",&m);
    while(m--)
    {
        int u,v;scanf("%d%d",&u,&v);v++;
        u=getf(u);v=getf(v);
        if(u==v) continue;
        a[u]=(a[u]+a[v])%26;
        f[v]=u;
    }
    for(int i=1;i<=n;i++)
        if(f[i]==i&&a[i]!=0)
    {
        printf("NO\n");return 0;
    }
    printf("YES\n");
}


Measured memory_bytes: 1152
# https://atcoder.jp/contests/abc136/tasks/abc136_b

N = input()
len_n = len(N)
N = int(N)

count = 0

if len_n % 2 == 1:
    current_len_min_val = 10 ** (len_n - 1)
    count += N - current_len_min_val + 1

for i in range(1, len_n, 2):
    count += 10 ** i - 10 ** (i-1)


print(count)


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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()
#define SIZE(a,n) (a).resize(n)
#define SORT(a) sort(ALL(a))
#define VSORT(a, type) sort(ALL(a),greater<type>())
#define MAPIN(a,i,j) (a).insert(make_pair(i,j))

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

using namespace std;

typedef unsigned long long lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > Matrix;

int main() {
    vector<ipair>a;
    int i,j,n;

    cin>>n;
    SIZE(a,n);
    rep(i,n){
        cin>>j;
        a[i]=make_pair(j,i);
    }
    VSORT(a,ipair);
    rep(i,n){
        if(a[0].second==i){
            cout<<a[1].first<<endl;
        }
        else{
            cout<<a[0].first<<endl;
        }
    }
	
	return 0;
}


Measured memory_bytes: 3200
/* ABC065 D - 連結 / Connectivity */
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
template<class T>
class UnionFind
{
private:
	vector<T> parentNo;
	vector<T> parentRank;
	vector<T> parentSize;

public:
	// コンストラクタ
	UnionFind(int n) 
	{
		parentNo.resize(n);
		parentRank.resize(n, 0);
		parentSize.resize(n, 1);
		for (int i = 0; i < n; i++) {
			// 始めは全部ROOT
			parentNo[i] = i;
		}
	}

	int root(T x) 
	{
		if (parentNo[x] == x) {
			return x;
		} else {
			T rootParentNo = root(parentNo[x]);
			parentNo[x] = rootParentNo;
			return rootParentNo;
		}
	}

	bool same(T x, T y) 
	{
		return root(x) == root(y);
	}

	int size(T x) 
	{
		return parentSize[root(x)];
	}

	void unite(T xc, T yc) 
	{
		T xr = root(xc);
		T yr = root(yc);
		if (xr == yr) {
			return;
		}
		if (parentRank[xr] < parentRank[yr]) {
			parentNo[xr] = yr;
			parentSize[yr] += parentSize[xr];
		} else {
			parentNo[yr] = xr;
			parentSize[xr] += parentSize[yr];
			if (parentRank[xr] == parentRank[yr]) {
				parentRank[xr]++;
			}
		}
	}
};


int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> p(N);
	REP(i, N) {
		cin >> p[i];
		p[i]--;
	};
	
	UnionFind<int> uFind(N);
	REP(i, M) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		uFind.unite(x, y);
	}

	int ans = 0;
	REP(i, N) {
		if (uFind.same(p[i], i)) ans++;
	}
	cout << ans << endl; 
	return 0;
}



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

int calc_energy(int pos, vector<int> x)
{
    int sum=0;
    for (int i=0; i<x.size(); ++i) {
        sum += pow(x[i] - pos, 2);
    }
    return sum;
}

int main(void)
{
  int n; cin >> n;
  vector<int> x(n);
  for (int i=0; i<n; ++i) {
    cin >> x[i];
  }
  int energy_sum, result=1000000;
  for (int p=1; p <= 100; ++p) {
    energy_sum = calc_energy(p, x);
    result = min(result, energy_sum);
  }
  cout << result << endl;
  return 0;
}


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

int main(){
	int H[25565] = {0};
	int W[25565] = {0};
	int i;
	do{
		cin >> H[i] >> W[i];
		i++;
		}while(H[i-1] != 0 && W[i-1] != 0);
	i = 0;
	do{
		for(int j=0;j<W[i];j++){
			cout << "#";
		}
		cout << endl;
		for(int j=0;j<H[i]-2;j++){
			cout << "#";
			for(int k=0;k<W[i]-2;k++){
				cout << ".";
			}
			cout << "#" << endl;
		}
		for(int j=0;j<W[i];j++){
			cout << "#";
		}
		cout << endl << endl;
		i++;
	}while(H[i] != 0 && W[i] != 0);
}

Measured memory_bytes: 1360
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	var n int
	var m int
	var k int
	var count int
	var countTmp int
	var tmp int
	var aArr []int
	var bArr []int

	sc.Split(bufio.ScanWords)
	n = nextInt()
	m = nextInt()
	k = nextInt()

	countTmp = 0
	aArr = append(aArr, countTmp)
	for i := 0; i < n; i++ {
		tmp = nextInt()
		countTmp = countTmp + tmp
		aArr = append(aArr, countTmp)
	}

	countTmp = 0
	bArr = append(bArr, countTmp)
	for i := 0; i < m; i++ {
		tmp = nextInt()
		countTmp = countTmp + tmp
		bArr = append(bArr, countTmp)
	}

	count = 0
	tmp = m
	for i := 0; i < n+1; i++ {
		if aArr[i] > k {
			break
		}
		for j := tmp; j >= 0; j-- {
			if aArr[i]+bArr[j] <= k {
				if i + j > count {
					count= i + j
				}
				tmp = j
				break
			}
		}
	}

	fmt.Printf("%d\n", count)
}



Measured memory_bytes: 12288
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(int argc, char const *argv[]) {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int ans = 0;
    if (A + B < C*2) {
        ans += min(X, Y) * (A + B);
    } else {
        ans += min(X, Y) * C*2;
    }

    int over_c, over_n;
    if (X > Y) {
        if (A < C*2) {
            ans += (X - Y) * A;
        } else {
            ans += (X - Y) * C*2;
        }
    } else {
        if (B < C*2) {
            ans += (Y - X) * B;
        } else {
            ans += (Y - X) * C*2;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 50021

static
char p[ N + 1 ] = { 1, 1, 0 };

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int i, j;
  int n;

  for ( i = 2; i <= N; ++i )
  {
    if ( p[ i ] ) continue ;

    for ( j = i * 2; j <= N; j += i )
    {
      p[ j ] = 1;
    }
  }

  while ( scanf ( "%d", &n ) == 1 )
  {
    for ( i = n - 1; ; --i )
    {
      if ( !p[ i ] )
      {
        printf ( "%d ", i );
        break ;
      }
    }
    for ( i = n + 1; ; ++i )
    {
      if ( !p[ i ] )
      {
        printf ( "%d\n", i );
        break ;
      }
    }
  }

  return ( 0 );
}

Measured memory_bytes: 0
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int M = sc.nextInt();
		int s = (100 * (N - M) + 1900 * M) * (int) Math.pow(2, M);
		System.out.println(s);

	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

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

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 21204
// Example program
#include <iostream>
#include <string>
using namespace std;
int main()
{
  int n; cin >> n;
  int ans = 0;
  for (int i = 1; i < n; i ++) {
    int target = n - i;
    int cnt = 0;
    for (int j = 1; j * j<= target; j ++) {
        if (target % j == 0) {
            if (target / j == j) {
                cnt ++;
            }
            else {
                cnt += 2;
            }
        }
    }
    ans += cnt;
  }
  cout << ans;
}


Measured memory_bytes: 3572
def main():
    from itertools import combinations_with_replacement,permutations
    n, k = map(int, input().split())
    *d, = input().split()
    m = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"} - set(d)
    m = list(m)
    m.sort()
    mm = ""
    if m[0] != "0":
        mm = m[0]
    else:
        mm = m[1]

    l = len(str(n))
    t = set()
    for s in combinations_with_replacement(m, l):
        for xx in permutations(s):
            w = "".join(xx)
            ww = mm + w
            t.add(int(w))
            t.add(int(ww))

    t = list(t)
    t.sort()
    for x in t:
        if x >= n:
            print(x)
            break


if __name__ == '__main__':
    main()


Measured memory_bytes: 4080
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

ll gcd(ll a,ll b){while(a^=b^=a^=b%=a);return b;}

void solve() {
  VAR(ll, A, B);
  ll ans = 1;
  ll g = gcd(A, B);
  for (ll i = 2; i * i <= g; ++i) {
    if (g % i == 0) {
      ans++;
      while (g % i == 0) g /= i;
    }
  }
  if (g > 1) ans++;
  print(ans);
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    Scanner sc = new Scanner(System.in);
	    System.out.println(sc.nextInt()*sc.nextInt()/2);
	}
}


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

int main() {
  int N; cin >> N;
  int A[N]; for (int i = 0; i < N; i++) cin >> A[i];
  int B[N]; for (int i = 0; i < N; i++) B[i] = A[i];
  sort(B, B+N, greater<int>());
  for (int i = 0; i < N; i++) {
    if (A[i] == B[0]) cout << B[1] << endl;
    else cout << B[0] << endl;
  }
}

Measured memory_bytes: 3200
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] K = new int[N];
    int[][] A = new int[N][M];
    int[] count = new int[M];
    int ans =0;
    for (int i=0; i<N; i++) {
      K[i] = sc.nextInt();
      for (int j=0; j<K[i]; j++) {
        A[i][j] = sc.nextInt();
      }
    }
    for (int i=1; i<=M; i++) {
      for (int j=0; j<N; j++) {
        for (int k=0; k<K[j]; k++) {
          if(A[j][k] == i) {
            count[i-1]++;
          }
        }
      }
    }
    for (int i=1; i<=M; i++) {
      if (count[i-1] == N) ans++;
    }
    System.out.println(ans);
  }
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;

#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 repll(i, a, b) for (ll i = a; i < b; i++)

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

  int n;
  cin >> n;

  vi a(n - 1);
  rep(i, 0, n - 1) cin >> a[i];

  vi answer(n);
  rep(i, 0, n - 1) answer[a[i] - 1]++;

  rep(i, 0, n) cout << answer[i] << endl;

  return 0;
}


Measured memory_bytes: 4784
import bisect

n, l = map(int, input().split())
Ts = [l+i for i in range(n)]
Ts.sort()

zero = bisect.bisect_left(Ts, 0)

if n-1 >= zero:
    if abs(Ts[zero-1]) > abs(Ts[zero]):
        ans = sum(Ts) - Ts[zero]
else:
    ans = sum(Ts) - Ts[zero-1]
print(ans)




Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int n, m; cin >> n >> m;
	vector<int> h(n);
	for (auto& e : h) cin >> e;
	vector<vector<int> > G(n);
	for (int i = 0; i < m; ++i) {
		int a, b; cin >> a >> b;
		--a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int j;
		for (j = 0; j < G[i].size(); ++j)
			if (h[i] <= h[G[i][j]]) break;
		if (j == G[i].size()) ++ans;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 8792
#include "bits/stdc++.h"
using namespace std;
int main() {
	string s, ss;
	int n, m;
	while (true) {
		cin >> s;
		if(s=="-"){return 0;}
		cin >> n;
		for (int i = 0; i < n; ++i) {
			cin >> m;
			s.insert(s.length(), s.substr(0, m));
			s.erase(0,m);
		}
		cout << s << endl;
	}
}



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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define sz(x) int(x.size())
const ll mod = 1000000007;
const int INF = 100100100;

int main() {
    int n,q; scanf("%d %d", &n, &q);
    fenwick_tree<ll> fw(n);
    rep(i,n) {
        int a; scanf("%d", &a);
        fw.add(i,a);
    }

    rep(i,q) {
        int t; scanf("%d", &t);
        if (!t) {
            int p,x; scanf("%d %d", &p, &x);
            fw.add(p,x);
        } else {
            int l,r; scanf("%d %d", &l, &r);
            printf("%lld\n", fw.sum(l,r));
        }
    }
    return 0;
}

Measured memory_bytes: 8212
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (abs(a - c) <= d || abs(a - b) <= d && abs(b - c) <= d)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BGoldenApple solver = new BGoldenApple();
        solver.solve(1, in, out);
        out.close();
    }

    static class BGoldenApple {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int d = in.nextInt();
            out.println((long) Math.ceil(((double) n) / (2 * d + 1)));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21460
def main(N, A):
    div = 10 ** 9 + 7
    s = sum(A)
    ans = 0
    for a in A:
        s = s - a
        mult = ((s % div) * a) % div
        ans += mult
    print(ans % div)

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    main(N, A)

Measured memory_bytes: 31624
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))

N = i()
A = l()
num = sum(A)//2
A += A
ans = []
for i in range(1):
    num2 = 0
    for j in range(0,N,2):
        num2 += A[i+j]
    ans.append(abs((num-num2))*2)
    r = abs((num-num2))*2
for i in range(1,N):
    r = A[i-1]*2-r
    ans.append(r)
print(*ans)

Measured memory_bytes: 96876
using System;
using System.Linq;
using static System.Math;

class D
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = new int[n].Select(_ => long.Parse(Console.ReadLine())).ToArray();

		var dp = new int[n + 1].Select(_ => Enumerable.Repeat(1L << 60, 5).ToArray()).ToArray();
		dp[0][0] = 0;

		for (int i = 0, j = 1; i < n; i++, j++)
		{
			var even = a[i] == 0 ? 2 : a[i] % 2;
			var odd = (a[i] + 1) % 2;

			// 0L, 2L, 1, 2R, 0R
			dp[j][0] = Min(dp[j][0], dp[i][0] + a[i]);
			dp[j][1] = Min(dp[j][1], Min(dp[i][0], dp[i][1]) + even);
			dp[j][2] = Min(dp[j][2], Min(dp[i][0], Min(dp[i][1], dp[i][2])) + odd);
			dp[j][3] = Min(dp[j][3], Min(dp[i][0], Min(dp[i][2], dp[i][3])) + even);
			dp[j][4] = Min(dp[j][4], Min(dp[i][2], Min(dp[i][3], dp[i][4])) + a[i]);
		}
		Console.WriteLine(dp[n].Min());
	}
}


Measured memory_bytes: 57908
use std::io::{stdin, Read};
use std::str::FromStr;
use std::collections::HashSet;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}
 
fn main() {
    let n: i64 = read().unwrap();
    let m: i64 = read().unwrap();
    let mut a: Vec<Vec<i64>> = Vec::new();
    let mut favors: Vec<HashSet<i64>> = Vec::new();
    for i in 0..m {
        let mut fav: HashSet<i64> = HashSet::new();
        favors.push(fav);
    }
    for i in 0..n {
        let k: i64 = read().unwrap();
        let mut arow: Vec<i64> = Vec::new();
        for j in 0..k {
            let v: i64 = read().unwrap();
            arow.push(v);
            favors[(v - 1) as usize].insert(i as i64);
        }
        a.push(arow);
    }
    let count: usize = favors.iter().filter(|&s| s.len() == (n as usize)).count();
    println!("{}", count);
}


Measured memory_bytes: 2164
def Maximum(R,n):
	Max=-10**9
	Min=R[0]
	for i in range(1,n):
		tmp=R[i]-Min
		if Max<tmp:
			Max=tmp
		if Min>R[i]:
			Min=R[i]
	
	return Max

R=[]
n=int(input())
for i in range(n):
	R.append(int(input()))
	
Max=Maximum(R,n)	

print(Max)



Measured memory_bytes: 13592
#include <bits/stdc++.h> 
using namespace std;
//関数
const long INF=1000000000000000;
const long MOD=1000000007;
bool check=false;


int main(void){
    
    long N;
    cin>>N;
    long ans=INF;
    
    long vari=1;
    while(vari*vari<=N){
        if(N%vari==0){
            ans=min(ans,vari+N/vari-2);
        }
        
        vari++;
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;
typedef vector<int> VI;


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


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

	if (n % 2 == 0) {
		cout << n << endl;
	}
	else {
		cout << 2 * n << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
        int a,b,c;
        cin >> a;
        cin >> b;
        cin >> c;
        if(a<b&&b<c){
            cout << "Yes";
        }
        else {
            cout << "No";
        }
       
        cout << endl;
        
    
}



Measured memory_bytes: 3084
#include <stdio.h>

int main(void){
    int N,D,X;
    scanf("%d%d%d",&N,&D,&X);
    int A[N];
    int count = 0;
    for(int i = 0; i < N; i++){
        scanf("%d",&A[i]);
    }
    for(int i = 0; i < N; i++){
        int j = 0;
        for(int d = 1; d < D+1;d++){
            if(j*A[i]+1 == d){
                count++;
                j++;
            } 
        }
    }
    printf("%d\n",count+X);
    return 0;
}

Measured memory_bytes: 128