akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <map>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
int main()
{
    int n, m;
    cin >> n >> m;
    unordered_map<int, vector<int>> mp;
    for (int i = 1; i <= n; i++)
    {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++)
        {
            int tmp;
            cin >> tmp;
            mp[i].push_back(-tmp);
            mp[-tmp].push_back(i);
        }
    }
    unordered_map<int, int> visited;
    queue<int> que;
    que.push(1);
    while (!que.empty())
    {
        int now = que.front();
        que.pop();
        visited[now]++;
        for (auto next : mp[now])
        {
            if (!visited[next])
            {
                que.push(next);
            }
        }
    }
    ll ans = 0;
    for(auto e:visited){
        ans += e.first > 0;
    }
    if (ans == n)
    {
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 13980
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    ll n;
    cin>>n;
    ll a[n],b[n],c[n];
    for(ll i=0;i<n;i++)cin>>a[i];
    for(ll i=0;i<n;i++)cin>>b[i];
    for(ll i=0;i<n-1;i++)cin>>c[i];
    ll ans=0;
    ans+=b[a[0]-1];
    for(ll i=1;i<n;i++){
        ans+=b[a[i]-1];
        if(a[i]==a[i-1]+1)ans+=c[a[i-1]-1];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const int MAXN=2e3+10;
    int N,Z,W;
    int a[MAXN];
    void solve(){
        cin>>N>>Z>>W;
        for(int u=0;u<N;u++)cin>>a[u];
        int ans=abs(a[N-1]-W);
        if(N>1)ans=max(ans,abs(a[N-2]-a[N-1]));
        cout<<ans;
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  char a[n];
  bool flag = true;
  REP(i,n) cin >> a[i];
  if(n%2 != 0) flag = false;
  
  REP(i,n/2){
    if(a[i] != a[i+n/2]) flag = false;
  }
  
  if(flag == true) cout << "Yes";
  else cout << "No";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

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

ll fac(ll n){
    if (n > 0) {
        return  n * fac(n - 1);
    }else{
        return 1;
    }
}

int main()
{
    string s;
    ll k,cnt,ans;
    cin >> s >> k;
    if (s[0] == '1') {
        cnt = 1;
        rep(i, s.size() - 1){
            if (s[i] == s[i + 1]) {
                ++cnt;
            }else{
                ans = i + 1;
                break;
            }
        }
        if (cnt >= k) {
            cout << 1 << endl;
        }else{
            cout << s[ans] << endl;
        }
    }else{
        cout << s[0] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
<?php
  $s = str_split(trim(fgets(STDIN)));
  $t = str_split(trim(fgets(STDIN)));
  sort($s);
  rsort($t);
  $len = min(count($s),count($t));
  for($i=0; $i<$len; $i++){
      if($s[$i] == $t[$i]){
          unset($s[$i]);
          unset($t[$i]);
      }
  }
  if(count($s) == 0 && count($t)>0){
      echo "Yes";
      exit;
  }
  if(current($s) < current($t)) echo "Yes";
  else echo "No";
 

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

using namespace std;
const int mod = 998244353, N = 3 * 1e5 + 1;
long long fact[N], invfact[N];

int fp(long long a, int p)
{
    long long ans = 1;
    while(p)
    {
        if(p % 2)
            ans *= a, ans %= mod;
        a *= a;
        a %= mod;
        p /= 2;
    }
    return ans;
}

long long cnt(int k, int n)
{
    return fact[n] * invfact[k] % mod * invfact[n - k] % mod;
}

int main()
{
    int n, a, b;
    long long ans(0), k;
    cin >> n >> a >> b >> k;
    if(!k)
        return cout << 1, 0;
    fact[0] = 1; invfact[1] = 1; invfact[0] = 1;
    for(int i = 1; i <= N; i++)
        fact[i] = fact[i - 1] * i % mod;
    for(int i = 2; i <= N; i++)
        invfact[i] = fp(fact[i], mod - 2);
    for(int i = 0; i <= n && 1LL * a * i <= k; i++)
    {
        long long left = k - 1LL * a * i;
        if(left % b != 0 || left / b > n)
            continue;
        //cout << i << " " << cnt(i, n) << " " << left / b << " " << cnt(left / b, n) << '\n';
        ans += cnt(i, n) * cnt(left / b, n) % mod;
        ans %= mod;
    }
    cout << ans;
}


Measured memory_bytes: 4992
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)

for i in a:
    d[i] += 1
    d[i-1] += 1
    d[i+1] += 1
d = sorted(d.items(), key=lambda x:x[1], reverse=True)
print(d[0][1])

Measured memory_bytes: 24176
N = str(input())
if int(N)%9 != 0: print("No")
else:
    if int(N) == 0 :print("Yes")
    else:
        sum = 0
        for ki_tu in N:
           sum += int(ki_tu)
        if sum%9 == 0: print("Yes")
        else: print("No")

Measured memory_bytes: 76044
#include <iostream>

int main() {
  std::string s;
  std::cin >> s;
  for (unsigned i = 0; i < s.size() - 1; ++i) {
    if (s[i] == s[i + 1]) {
      std::cout << i + 1 << " " << i + 2;
      return 0;
    }
  }
  for (unsigned i = 0; i < s.size() - 2; ++i) {
    if (s[i] == s[i + 2]) {
      std::cout << i + 1 << " " << i + 3;
      return 0;
    }
  }
  std::cout << -1 << " " << -1;
  return 0;
}


Measured memory_bytes: 512
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = list(li())
a = [1,9,7,4]
ans = True
for ai in a:
    if not ai in n:
        ans = False
        
print("YES") if ans else print("NO")

Measured memory_bytes: 3064
n = int(input())
w = list(map(int, input().split()))
ans = []
for i in range(n - 1):
  b = [w[j] for j in range(n) if j <= i]
  a = [w[j] for j in range(n) if j > i]
  ans.append(abs(sum(b) - sum(a)))
print(min(ans))

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

using namespace std;
typedef pair<int,int> ii;
typedef pair<ii, int> iii;
#define REP(i,n) for (int i = 0; i < n; ++i)
#define PB push_back
#define MP make_pair

const int MAX = 1010;

int H, W;
bool A[MAX][MAX];
int dx[4] = {-1, 0, 1, 0}; 
int dy[4] = {0, -1, 0, 1}; 

int main() {
    cin >> H >> W;
    int count = H*W;
    queue<iii> q;
    REP (h, H) REP (w, W) {
        char a;
        cin >> a;
        A[h][w] = (a == '#');
        if (A[h][w]) {
            q.push(MP(MP(h,w), 0));
            count--;
        }
    }

    int ans = 0;
    while (count > 0) {
        iii node = q.front(); q.pop();
        int h = node.first.first, w = node.first.second;
        REP (k, 4) {
            int hh = h + dy[k], ww = w + dx[k];
            if (hh >= 0 && hh < H && ww >= 0 && ww < W && !A[hh][ww]) {
                A[hh][ww] = true;
                q.push(MP(MP(hh,ww),node.second+1));
                ans = node.second+1;
                count--;
            }
        }
    }
    cout << ans << endl;
}

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

int main()
{
    long long n,ans;
    std::cin>>n;
    ans = 0;
    std::vector<int> a(n+1); //町ごとのモンスターの数
    std::vector<int> b(n); //倒せる数

    for(int i=0;i<n+1;i++)std::cin>>a[i];
    for(int i=0;i<n;i++)std::cin>>b[i];




    //各勇者について
    for(int i=0;i<n;i++){
        //勇者の倒せる数より優先街でモンスターが多ければ
        if(a[i]>=b[i]){
            ans += b[i];
        }else{
            b[i] -= a[i];
            ans += a[i];
            if(a[i+1]>=b[i]){
                a[i+1] -= b[i];
                ans += b[i];
            }else{
                ans += a[i+1];
                a[i+1] = 0;
            }
        }
    }
    std::cout<<ans<<std::endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define SUM(v) accumulate(v.begin(),v.end(),lli(0))
#define rev(n,d) for(int i=n;i>=d;i--)
#define FOR0(n) for(int i=0;i<n;i++)
#define FOR(a,n) for(int i=a;i<n;i++)
#define FORQ(a,n) for(int i=a;i<=n;i++)
#define inf 1000000009
#define inff 0x3f3f3f3f
#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define mem(ar,x) memset(ar,x,sizeof ar)
#define present(container, element) (container.find(element) != container.end())
#define max3(a,b,c) return (lli(a)>lli(b)?(lli(a)>lli(c)?a:c):(lli(b)>lli(c)?b:c))
#define max4(a,b,c,d) return (max3(a,b,c)>lli(d)?(max3(a,b,c)):d)
#define min3(a,b,c) return (lli(a)<lli(b)?(lli(a)<lli(c)?a:c):(lli(b)<lli(c)?b:c))
#define min4(a,b,c,d) return (max3(a,b,c)<lli(d)?(max3(a,b,c)):d)
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<int,pii>ppii;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<pii>vpii;
const int N=100005;
int dr8[]={0,0,1,-1,1,1,-1,-1};
int dc8[]={1,-1,0,0,-1,1,-1,1};
int dr4[]={0,1,-1,0};
int dc4[]={1,0,0,-1};
int main(){
	fast
	int n,k;
	cin>>n>>k;
	int sm=0;
	int a[n];
	FOR0(n) cin>>a[i];
	sort(a,a+n);
	FOR0(k) sm+=a[i];
	cout<<sm;
}



Measured memory_bytes: 3616
#include<stdio.h>
int main(){
	int H,A;
	
	scanf("%d %d",&H ,&A);
	 
	 if (H%A == 0){
	 	printf("%d",H/A);
	 	
	 }
	else if(H%A !=0){
	   printf("%d",H/A+1);
	}
	return 0;
}

Measured memory_bytes: 1716
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    auto S = sread();
    auto T = ["dreamer", "eraser", "erase", "dream"];
    long i = S.length;
    w: while (0 < i)
    {
        foreach (t; T)
        {
            // writeln(max(0, i - cast(long)t.length), " ", min(i, S.length));
            if (S[max(0, i - cast(long)t.length) .. min(i, S.length)] == t)
            {
                i -= t.length;
                continue w;
            }
        }
        writeln("NO");
        return;
    }
    writeln("YES");
}


Measured memory_bytes: 2556
import java.io.BufferedReader
import java.io.BufferedWriter
import kotlin.math.abs

fun main() = Case().exec(::solve)
//fun main() = TestExecutor.assert(testCase) { Case(it.r, it.w).exec(::solve) }

/** https://atcoder.jp/contests/abc178/tasks/abc178_e **/
fun solve(c: Case) {
    val n = c.long().toInt()
    val points = (0 until n).map { c.longList().let { it[0] to it[1] } }

    val rightTop = points.sortedByDescending { it.first + it.second }.take(1000)
    val rightBottom = points.sortedByDescending { it.first - it.second }.take(1000)
    val leftTop = points.sortedByDescending { -it.first + it.second }.take(1000)
    val leftBottom = points.sortedByDescending { -it.first - it.second }.take(1000)

    var score = Long.MIN_VALUE
    rightTop.forEach { a ->
        leftBottom.forEach { b ->
            score = Math.max(score, abs(a.first - b.first) + abs(a.second - b.second))
        }
    }
    rightBottom.forEach { a ->
        leftTop.forEach { b ->
            score = Math.max(score, abs(a.first - b.first) + abs(a.second - b.second))
        }
    }
    c.println(score.toString())
}

class Case(
    private val input: BufferedReader = System.`in`.bufferedReader(),
    private val out: BufferedWriter = System.out.bufferedWriter()
) {
    fun exec(fn: (Case) -> Unit) = input.use { out.use { execInThread(fn) } }
    private fun execInThread(fn: (Case) -> Unit) =
        Thread(null, { fn(this) }, "solve", 64 * 1024 * 1024)
            .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } }
            .apply { start() }.join()

    fun println(c: CharSequence?) = out.appendln(c)
    fun string(): String = input.readLine().trimEnd()
    fun long(): Long = input.readLine().toLong()
    fun intList(): List<Int> = input.readLine().split(" ").map { it.toInt() }
    fun longList(): List<Long> = input.readLine().split(" ").map { it.toLong() }
}

Measured memory_bytes: 84296
//read by human
// 1 min = 60 sec
// 1 hour = 60 min = 3600 sec

#include <iostream>

using namespace std;

int main()
{
    int i , h , m , s;
    cin >> i;
    h = i / 3600;
    m = i / 60 - h * 60;
    s = i % 60;
   cout << h << ":" << m << ":" << s << endl; 
   
   return 0;
}


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define lint long long

int main() {

	vector<pair<int,int>> A(5);
	for (int i = 0; i < 5; i++)
	{
		int a;
		cin >> a; int b;
		if (a % 10 != 0) {
			b = a % 10;
		}
		A[i] = make_pair(b, a);
	}
	sort(A.begin(), A.end());
	
	int sum = A[0].second;
	for (int i = 1; i < 5; i++)
	{
		if (A[i].second % 10 == 0) {
			sum += A[i].second;
		}
		else {

			int b = A[i].second - (A[i].second % 10) + 10;
			sum += b;
		}

	}

	cout << sum << endl;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, int num=0){
  if(num == 0) num = (int)v.size();
  for(int i=0; i<num; i++){ cout << v[i]; if(i!=num-1) cout << " ";}
  cout << endl;
}

template <typename T>
void print_pairvec(const vector<T> &v, int num=0){
  if(num == 0) num = (int)v.size();
  for(int i=0; i<num; i++){ cout << v[i].first << v[i].second; if(i!=num-1) cout << " ";}
  cout << endl;
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

int main(){

  string s;
  stack<int> st;
  while(cin >> s){
    if(s == "+"){
      int a = st.top(); st.pop();
      int b = st.top(); st.pop();
      st.push(a+b);
    }
    else if(s == "-"){
      int a = st.top(); st.pop();
      int b = st.top(); st.pop();
      st.push(b-a);
    }
    else if(s == "*"){
      int a = st.top(); st.pop();
      int b = st.top(); st.pop();
      st.push(a*b);
    }
    else{
      st.push(stoi(s));
    }
  }
  cout << st.top() << endl;
  return 0;
}




Measured memory_bytes: 3192
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;
struct edge{
    ll to;
    ll w;
};
static const ll max_n = 3010;
// static const ll max_abs_value = 1000000010;
static const ll mod = 998244353;
// vector<vector<ll>>dp(max_n, vector<ll>(max_n, 0));
vector<ll>dp(max_n, 0);
vector<ll> value_list(max_n);
// int N;
ll N, S;

int main(){
    // int u, v;
    // bool updated = false;
    ll ans = 0, u, v;
    scanf("%lld %lld", &N, &S);
    for(ll i=0;i<N;i++){
        scanf("%lld", &u);
        value_list[i] = u;
    }

    // ll ans = 0;

    // dp[0] = 1;
    for(ll i=0;i<N;i++){
        (dp[0] += 1) %= mod;
        vector<ll> dp2(max_n, 0);
        for(ll w=0;w<=S;w++){
            if(w+value_list[i] <= S){
                (dp2[w + value_list[i]] += dp[w]) %= mod;
            }
            ((dp2[w] += dp[w])) %= mod;
        }
        dp = dp2;
        ans += dp[S];
        ans %= mod;
    }
    // ans = dp[S];

    printf("%lld\n", ans);


    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define ld long double 
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007 
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX 10000003
using namespace std;
void solve()
{
    ll n,k;  cin>>n>>k;
    ll arr[n];
    rep(i,0,n) cin>>arr[i];
    vector<bool> dp(k+1,0);
    rep(i,1,k+1)
    {
        rep(j,0,n)
        {
            if(arr[j]>i) break;
            else if(dp[i-arr[j]]==false) { dp[i]=true;  break;  }
        }
    }
    cout<<(dp[k]?"First\n":"Second\n");
}
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1;  //cin>>T;
    while(T--) solve();
    return 0;
}


Measured memory_bytes: 3660
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,siz[200010];
vector<int> G[200010];
ll pow2[200010],inv,p[200010],ans;

struct mod_fac{
    private:
        vector<ll> f,i_f;
        int n;ll MOD;
    public:
        void init(int n,ll m){
            MOD=m;
            f.resize(n+1,0);
            i_f.resize(n+1,0);
            f[0]=1;
            rep(i,n){
                f[i+1]=f[i]*(i+1)%MOD;
            }
            i_f[n]=power(f[n],MOD-2);
            per(i,n){
                i_f[i]=(i_f[i+1]*(i+1))%MOD;
            }
        }
        ll power(ll a ,ll x){
            if (x==0) return 1;
            if (x==1) return a%MOD;
            if (x==2) return (a*a)%MOD;
            if (x%2==1) return (a*power(power(a,(x-1)/2),2))%MOD;
            return (power(power(a,x/2),2))%MOD;
        }
        ll fac(int x){
            return f[x];
        }
        ll invfac(int x){
            return i_f[x];
        }
        ll comb(int m,int k){
            if (m<0 or k<0) return 0;
            if (m<k) return 0;
            return (((f[m]*i_f[k])%MOD)*i_f[m-k])%MOD;
        }
};

void dfs1(int s,int par){
    siz[s]=1;
    for(int t:G[s]){
        if (t==par) continue;
        dfs1(t,s);
        siz[s]+=siz[t];
    }
    //cout << s << " " << siz[s] << endl;
}

void dfs2(int s,int par){
    p[s]=pow2[n-1]-1;
    for(int t:G[s]){
        if (t==par) continue;
        p[s]-=pow2[siz[t]]-1;
        p[s]=(p[s]+mod)%mod;
        dfs2(t,s);
    }
    p[s]-=pow2[n-siz[s]]-1;
    p[s]=(p[s]+mod)%mod;
}

void solve(){
    cin >> n;
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    pow2[0]=1;
    rep(i,n){
        pow2[i+1]=2*pow2[i]%mod;
    }
    mod_fac mo;mo.init(n,mod);
    inv=mo.power(pow2[n],mod-2);
    dfs1(0,-1);
    dfs2(0,-1);
    rep(i,n){
        //cout << i << " " << p[i] << endl;
        ans+=p[i];
        ans%=mod;
    }
    cout << ans*inv%mod << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}


Measured memory_bytes: 27136
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define REP(var,init,cnt) for(int (var)=(init); (var)<=(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) ((flag)?(int)1:(int)0)
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================

constexpr int MOD=1e9+7;

int main(void){
  int N,Q; cin>>N>>Q;
  mat<int> G(N);
  rep(i,N-1){
    int a,b; cin>>a>>b; --a,--b;
    G[a].emplace_back(b),G[b].emplace_back(a);
  }
  vec<int> ans(N,0);
  rep(i,Q){
    int a,b; cin>>a>>b; --a;
    ans[a]+=b;
  }
  vec<bool> used(N,false);
  queue<int> que; que.push(0);
  while(!que.empty()){
    int p=que.front(); que.pop();
    used[p]=true;
    ran(i,G[p]){
      if(used[i]) continue;
      ans[i]+=ans[p];
      que.push(i);
    }
  }
  ran(i,ans) cout<<i<<" ";
}












Measured memory_bytes: 16500
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
macro max!(a,b); esc(:($a=max($a,$b))); end
function main()
  V=zeros(Int,3010,3010)
  dp=zeros(Int,3010,3010,4)
  R,C,K=parse.(Int,split(readline()))
  for i=1:K
    r,c,v=parse.(Int,split(readline()))
    V[r,c]=v
  end
  for i=1:R
    for j=1:C
      for k=1:4
        #sita
        @max!(dp[i+1,j+1,1],dp[i,j+1,k])
        @max!(dp[i+1,j+1,2],dp[i,j+1,k]+V[i,j])
        #migi
        @max!(dp[i+1,j+1,k],dp[i+1,j,k])
        @max!(dp[i+1,j+1,k],k>1 ? dp[i+1,j,k-1]+V[i,j] : 0)
      end
    end
  end
  println(maximum(dp[R+1,C+1,:]))
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

Measured memory_bytes: 575416
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long unsigned int ull;
typedef long long int ll;
typedef pair<ll, ll> P;

int main()
{
    int a,b;
    cin >> a >> b;
    cout << a*b << endl;;   
}

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

int main(){
    string s;
    cin>>s;
    if(s == "MON"){
        cout<<6<<endl;
    } else if(s == "TUE"){
        cout<<5<<endl;
    } else if(s == "WED"){
        cout<<4<<endl;
    } else if(s == "THU"){
        cout<<3<<endl;
    } else if(s == "FRI"){
        cout<<2<<endl;
    } else if(s == "SAT"){
        cout<<1<<endl;
    } else {
        cout<<7<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#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 P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,typename=enable_if_t<iterable<T>::value>>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int negmod(int a, int b){
    dprint(a,'%',b,'=');
    if(!b)return -1;
    if(a>0)return a%b;
    a+=((-a+b-1)/b)*b;
    dprint(a%b);
    return a%b;
}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    cout<<setprecision(10);
    int n,k;
    cin>>n>>k;
    vi a(n);
    cin>>a;
    REP(i,n)a[i]%=k;
    vi c(n+1);
    REP(i,n)c[i+1]=(c[i]+a[i])%k;
    dprint("c",c);
    //vvi d(k);
    map<int, vi> d;
    d[0].push_back(0);
    ll ans=0;
    REP(i,n){

        dprint("===");
        REP(j,k){
            dprint((i+j+1)%k,':',d[j]);
        }
        int jj = negmod(c[i+1]-i-1,k);
        dprint(jj);
        vi& di=d[jj];
        ans += di.end() - upper_bound(all(di), i-k+1);
        di.push_back(i+1);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 23680
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<ll>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  int n,k;
  cin >> n >> k;
  int a[n];
  int b[n];
  rep(i,n)cin >> a[i] >> b[i];
  int c[n];
  int d[n];
  rep(i,n){
    c[i]=a[i];
    d[i]=b[i];
  }
  sort(c,c+n);
  sort(d,d+n);
  ll ans=4000000000000000001;
  rep(i,n){
    rep(j,i){
      rep(o,n){
        rep(p,o){
          //if(i==j||o==p)continue;
          ll minx=(ll)c[j],maxx=(ll)c[i],miny=(ll)d[p],maxy=(ll)d[o];
          int cnt=0;
          rep(i,n){
            if(a[i]>=minx&&a[i]<=maxx&&b[i]<=maxy&&b[i]>=miny)cnt++;
          }
          if(cnt>=k){
            ans=min(ans,(maxx-minx)*(maxy-miny));
          }
        }
      }
    }
  }
  cout << ans << endl;
}   


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

int max(int a, int b) {return a > b ? a : b;}
int min(int a, int b) {return a < b ? a : b;}

int main(){
    int a,b;
    scanf("%d%d", &a, &b);

    int x,y;
    x = max(a,b);
    y = min(a,b);

    for( int i = 1; i <= x; i++ ){
        printf("%d", y);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<queue>
using namespace std;
int dy[]={-2,-2,-2,-1,0,1,2,2,2,-1,0,1};
int dx[]={-1,0,1,-2,-2,-2,-1,0,1,2,2,2};
struct phyon{
    int y,x,cnt;
    phyon(int y_,int x_,int cnt_){
        y=y_;x=x_;cnt=cnt_;
    }
};
int zec(int n){
    if(n<0)n*=-1;
    return n;
}
int main(){
    int sy,sx,n;
    pair<int,int>spr[10];
    while(cin>>sx>>sy&&(sy||sx)){
        cin>>n;
        for(int i=0;i<n;i++)cin>>spr[i].second>>spr[i].first;
        phyon start(sy,sx,-1);
        queue<phyon>Q;
        Q.push(start);
        bool flag=false;
        while(!Q.empty()){
            phyon a=Q.front();
            Q.pop();
            if(a.y<0||a.y>=10||a.x<0||a.x>=10)continue;
            if(a.cnt==n-1){
                flag=true;
                break;
            }
            for(int i=0;i<12;i++){
                int py = a.y+dy[i],px = a.x+dx[i];
                if(py<0 || 9<py || px<0 || 9<px) continue;
                if(zec(py-spr[a.cnt+1].first)>=2)continue;
                if(zec(px-spr[a.cnt+1].second)>=2)continue;
                phyon next(a.y+dy[i],a.x+dx[i],a.cnt+1);
                Q.push(next);

            }
        }
        if(flag)cout<<"OK"<<endl;
        else cout<<"NA"<<endl;
    }
    return 0;
}

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

signed main(){
    int n; cin>>n;
    vector<vector<int>> hp(n,vector<int>(3));
    rep(i,n){
        rep(j,3) cin>>hp.at(i).at(j);
    }
    vector<vector<int>> dp(n,vector<int>(3));
    rep(i,n){
        if(i==0){
            rep(j,3) dp.at(i).at(j)=hp.at(i).at(j);
            continue;
        }
        dp.at(i).at(0)=hp.at(i).at(0)+max(dp.at(i-1).at(1),dp.at(i-1).at(2));
        dp.at(i).at(1)=hp.at(i).at(1)+max(dp.at(i-1).at(0),dp.at(i-1).at(2));
        dp.at(i).at(2)=hp.at(i).at(2)+max(dp.at(i-1).at(0),dp.at(i-1).at(1));
    }
    sort(dp.back().begin(),dp.back().end());
    cout<<dp.back().back()<<endl;
}

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

const int mod=1e9+7;
/*long mem[3005][3005];
bool vis[3005];

long rec(string s, int n, int id, int num)
{
  if(id>=n)
    return 1;
  if(num!=-1&&mem[id][num]!=-1)
    return mem[id][num];
  long ans=0;
  if(id==0)
  {
    if(s[id]=='<')
    {
      for(int i=1;i<n;i++)
      {
      	if(vis[i])
      	  continue;
      	vis[i]=true;
        ans+=rec(s,n,id+1,i);
        ans%=mod;
        vis[i]=false;
      }
    }
    else
    {
      for(int i=2;i<=n;i++)
      {
        if(vis[i])
      	  continue;
      	vis[i]=true;
        ans+=rec(s,n,id+1,i);
        ans%=mod;
        vis[i]=false;
      }
    }
  }
  else if(s[id-1]=='<')
  {
    for(int i=num+1;i<=n;i++)
    {
      if(vis[i])
     	continue;
      vis[i]=true;
      ans+=rec(s,n,id+1,i);
      ans%=mod;
      vis[i]=false;
    }
  }
  else
  {
    for(int i=1;i<num;i++)
    {
      if(vis[i])
      	continue;
      vis[i]=true;
      ans+=rec(s,n,id+1,i);
      ans%=mod;
      vis[i]=false;
    }
  }
  //cout<<id<<' '<<num<<' '<<ans<<endl;
  mem[id][num]=ans;
  return ans;
  
}*/

int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  /*memset(mem,-1,sizeof(mem));
  memset(vis,0,sizeof(vis));
  
  cout<<rec(s,n,0,-1);*/
  
  
  long dp[n+1][n+1]={{0}};
  long prefix[n+1][n+1]={{0}};
  dp[1][1]=1;
  for(int len=2;len<=n;len++)
  {
    for(int i=1;i<=len-1;i++)
      prefix[len-1][i]=(prefix[len-1][i-1]+dp[len-1][i])%mod;
    for(int j=1;j<=len;j++)
    {
      int l,r;
      if(s[len-2]=='<')
        l=1,r=j-1;
      else
        l=j,r=len-1;
      if(l<=r)
      {
        dp[len][j]+=(prefix[len-1][r]-prefix[len-1][l-1]+mod)%mod;
        dp[len][j]%=mod;
      }
      /*
      for(int k=1;k<=len-1;k++)
      {
      	int reala=a;
        if(a>=b)
          reala++;
        if(reala<j != s[len-2]=='<')
          continue;
        dp[len][j]+=dp[len-1][a];
      }
      */
    }
  }
  long ans=0;
  for(int i=1;i<=n;i++)
  {
    ans+=dp[n][i]%mod;
    ans%=mod;
  }
  cout<<ans;
  

}

Measured memory_bytes: 140928
#include <iostream>
using namespace std;
int a[1000];
int b[1000];
int main()
{
    bool x=false;
    int n,m;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    cin>>m;
    for(int i=0;i<m;i++)
        cin>>b[i];
    for(int i=0;i<m&&i<n;i++)
    {
        if(b[i]!=a[i])
        {
            x=true;
            if(b[i]>a[i])
                cout<<1<<endl;
            else
                cout<<0<<endl;
            break;
        }
    }
    if(x!=true)
        cout<< (m>n? 1:0) <<endl;
    return 0;
}



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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  
  int sum, answer;
  
  for ( int i = 0; i < A + 1 ; i++){
    for (int j = 0; j < B + 1 ; j++){
      for (int k = 0; k < C + 1 ; k++){
        sum = 500 * i + 100 * j + 50 * k;
//        cout << sum << endl;
        if ( sum == X){
          answer ++ ;
        }
      }
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
 int b;
  cin >> b;
  long long int sum=0;
  vector<long long int>v(b),ans(b);
  
  for(int i=0;i<b;i++)cin >> v[i];
  ans[0]=v[0];
  for(int i=1;i<b;i++)ans[i]=ans[i-1]+v[i];
  sum = ans[b-1];
  long long int sum1,sum2;
  long long int min1=INT_MAX;
  for(int i=0;i<b;i++){
    sum1 = ans[i];
    sum2=sum-sum1;
    min1 = min(min1,abs(sum1-sum2));
  }    
  cout << min1;
  
  
 
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<stdlib.h>
int main() {
	int n, i;
	long long int sum = 0, max, min;
	int *array;
	scanf("%d", &n);
	array = (int *)malloc(sizeof(int)*n);
	
	for (i = 0; i < n; i++) {
		scanf("%d", &array[i]);
		if (i == 0) max = min = array[i];
		sum += array[i];
		if (max < array[i])max = array[i];
		if (array[i] < min)min = array[i];
	}
	printf("%lld %lld %lld\n", min, max, sum);
	free(array);
	return 0;
}

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

void solve() {
    int n;
    cin >> n;
    vector<double> p(n);
    vector<vector<double>> dp(n + 1, vector<double>(n + 1));
    for (int i = 0; i < n; i++)cin >> p[i];
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++)
        for (int j = 0; j <= i; j++) {
            if (j)dp[i][j] = dp[i - 1][j - 1] * p[i - 1];
            dp[i][j] += dp[i - 1][j] * (1 - p[i - 1]);
        }
    double ans = 0;
    for (int i = 0; i <= n; i++)
        if (i > n - i)ans += dp[n][i];
    cout << fixed << setprecision(12) << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 70784
#include <iostream>
#include <cstdio>

int main()
{
  int n, k;
  std::cin >> n >> k;
  double result = 0.0;
  for (int dice = 1; dice <= n; dice++) {
    int ncoin = 0;
    double p = 1.0 / n;
    int score = dice;
    while (score < k) {
      score = 2 * score;
      p = p / 2.0;
    }
    result += p;
  }
  //std::cout << result << '\n';
  printf("%1.12lf\n", result);
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for(int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  
  int ans = 0, min = n;
  for(int i = 0; i < n; i++) {
    if(vec.at(i) <= min) {
      ans++;
      min = vec.at(i);
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
string s;
cin>>s;
int i,c=0,d=0;
   for(i=0;i<3;i++)
   {
       if(s[i]=='R')c++;
       else d++;
   }
if(c==3)cout<<3;
else if(d==3)cout<<0;
else if(d==2)cout<<1;
else
{
    if(s[1]=='S')cout<<1;
    else
        cout<<2;
}
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <bits/stdc++.h>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>
#include <unistd.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 1e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define line cout << "----------" << endl;


ll mod = 1000000007;
ll rui(ll number1,ll number2){

    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){

    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){

    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){

    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}


//ll fact[800005],rfact[800005];
/*
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
	rfact[800000] = rui(fact[800000],mod - 2);
	for(ll i=800000; i>=1; i--){
	   rfact[i-1] = rfact[i] * i;
	   rfact[i-1] %= mod;
	}
	return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/

ll n,m,num,sum,ans,a,b,c,d,e,g,h,w,i,j,k,q;
ll x[300005],y[300005],z[100005];
char s[300005],t[300005];

int main(){
	cin >> n >> k;
	p((n+2*k)/(1+2*k));
	return 0;
}



Measured memory_bytes: 13952
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	int N;
	cin >> N; --N;
	vector<vector<int> > G(2 * N);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			int x;
			cin >> x;
			if (x == 1) {
				G[i].push_back(N + j);
				G[N + j].push_back(i);
			}
		}
	}
	vector<bool> vis, dec(2 * N, false);
	vector<int> match(2 * N, -1);
	function<bool(int)> find_augment = [&](int pos) {
		vis[pos] = true;
		for (int i : G[pos]) {
			if (!dec[i] && (match[i] == -1 || (!vis[match[i]] && find_augment(match[i])))) {
				match[i] = pos;
				match[pos] = i;
				return true;
			}
		}
		return false;
	};
	int cnt = 0;
	for (int i = 2 * N - 1; i >= N; --i) {
		vis = vector<bool>(2 * N, false);
		if (match[i] == -1 && find_augment(i)) {
			++cnt;
		}
	}
	if (cnt == N) {
		for (int i = N; i < 2 * N; ++i) {
			match[match[i]] = -1;
			match[i] = -1;
			vis = vector<bool>(2 * N, false);
			find_augment(i);
			dec[match[i]] = true;
		}
		cout << "yes" << endl;
		for (int i = 0; i < N; ++i) {
			cout << match[N + i] + 1 << '\n';
		}
	}
	else {
		cout << "no" << endl;
	}
	return 0;
}


Measured memory_bytes: 3312
/////////////////////////   _LeMur_
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

using namespace std;

const int N = 300005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;

int a , b , c;

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


Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BS
import qualified Data.Map.Strict       as M

main :: IO ()
main = do
  n <- readLn
  ss <- BS.lines <$> BS.getContents
  print $ solve n ss

solve :: Int -> [BS.ByteString] -> Int
solve _ ss = sum [M.findWithDefault 0 x cs * M.findWithDefault 0 y cs * M.findWithDefault 0 z cs
                 | x <- "MARCH"
                 , y <- "MARCH"
                 , z <- "MARCH"
                 , x /= y
                 , y /= z
                 , z /= x] `div` 6 where
  cs = M.fromListWith (+) [(BS.head s, 1) | s <- ss]


Measured memory_bytes: 2556
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N;
    cin >> N;
    print((ll)pow(2, floor(log2(N))));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  int w, h, n;
  cin >> w >> h >> n;
  int x1 = 0, x2 = w, y1 = 0, y2 = h;
  rep(i,n) {
    int x, y, a;
    cin >> x >> y >> a;
    if (a == 1) x1 = max(x1, x);
    if (a == 2) x2 = min(x2, x);
    if (a == 3) y1 = max(y1, y);
    if (a == 4) y2 = min(y2, y);
  } 

  int W = max(0, x2-x1);
  int H = max(0, y2-y1);
  
  cout << W * H << endl;
  return 0;
}

Measured memory_bytes: 3616
n, k = map(int, input().split())

if n == 2:
    if k == 0:
        print(1)
        print(1, 2)
    else:
        print(-1)
    exit()

MAX_PAIR = (n-1)*(n-2)//2
if MAX_PAIR < k:
    print(-1)
else:
    m = n-1+MAX_PAIR-k
    print(m)
    for v2 in range(2, n+1):
        print(1, v2)
        m -= 1
    if m == 0:
        exit()

    for v in range(2, n):
        for v2 in range(v+1, n+1):
            print(v, v2)
            m -= 1
            if m == 0:
                exit()


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

typedef pair<int,int> P;

int pic[50][50];

void rotate(int m){
	int tmp[50][50];
	for(int i = 0;i < m;i++){
		for(int j = 0;j < m;j++){
			tmp[i][j] = pic[m - j - 1][i];
		}
	}
	for(int i = 0;i < m;i++){
		for(int j = 0;j < m;j++) pic[i][j] = tmp[i][j];
	}
}

int main(){
	int n,m;
	while(cin >> n >> m,n){
		int field[100][100];
		P mi = P(500,500);
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				cin >> field[i][j];
			}
		}
		for(int i = 0;i < m;i++){
			for(int j = 0;j < m;j++){
				cin >> pic[i][j];
			}
		}
		for(int i = 0;i < 4;i++){
			rotate(m);
			for(int j = 0;j < n - m + 1;j++){
				for(int k = 0;k < n - m + 1;k++){
					bool flag = true;
					for(int l = 0;l < m;l++){
						for(int o = 0;o < m;o++){
							if(!(pic[l][o] == -1 || pic[l][o] == field[j + l][k + o])) flag = false;
						}
					}
					if(flag){
						for(int l = 0;l < m;l++){
							for(int o = 0;o < m;o++){
								if(pic[l][o] != -1){
									mi = min(mi,P(j + l,k + o));
								}
							}
						}
					}
				}
			}
		}
		if(mi == P(500,500)) cout << "NA" << endl;
		else cout << mi.second + 1 << " " << mi.first + 1 << endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    int A[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K; cin >> K;
    cout << A[K-1] << endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
 
/*------------------------------------------------------------------*/
 
int main(){
    ll n; cin >> n;
    vector<ll> b(n - 1);
    rep(i, n - 1) cin >> b[i];
    vector<ll> a(n);
    ll sum = b[0] + b[n - 2];
    _rep(i, 1, n - 1){
        sum += min(b[i], b[i - 1]);
    }
    cout << sum << endl;
}


Measured memory_bytes: 256