akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int a,b;
	cin >> a >> b;
	cout << max(max(a + b,2 * a - 1),2 * b - 1) << endl;
}


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

using namespace std;

#define ll long long
#define rep(cnt,a,n) for(ll cnt=a;cnt<n+a;cnt++) //aから始めてn回ループ
#define vector2(type,name,a,b) vector<vector<type>> name(a, vector<type>(b))
#define PI 3.141592653589793



int main() {
    ll a;
    cin >> a;
    a = a + a * a + a * a * a;
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 3592
#include<stdio.h>

int Abs(int i) {
	if (i >= 0)return i;
	else return -i;
}

int main() {
	int H, W;
	int A[25][25];
	int score, min;
	scanf("%d %d", &H, &W);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			scanf("%d", &A[i][j]);
		}
	}
	for (int I = 0; I < H; I++) {
		for (int J = 0; J < W; J++) {
			score = 0;
			for (int x = 0; x < H; x++) {
				for (int y = 0; y < W; y++) {
					if (x == I || y == J)continue;
					else if (Abs(x - I) == Abs(y - J)) {
						score += A[x][y] * Abs(x - I);
					}
					else if (Abs(x - I) > Abs(y - J)) {
						score += A[x][y] * Abs(y - J);
					}
					else if (Abs(x - I) < Abs(y - J)) {
						score += A[x][y] * Abs(x - I);
					}
				}
			}
			if ((I == 0 && J == 0) || (score < min))min = score;
		}
	}
	printf("%d\n", min);

	return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pll=pair<ll,ll>;
using plll=pair<ll,pll>;

const ll MOD=1000000007;

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1){
      ret*=a;
    }
    a*=a;
    if(a>=p)a%=p;
    b=b>>1;
  }
  return ret;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

int ord(ll a,ll p){
  int i=0;
  while(a%p==0){
    a/=p;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  int i;
  ll ret=1;
  for(i=0;i<n;i++){
    ret=ret*(i+1);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll binom(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1,fact=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    fact*=i+1;
    if(ret>=p)ret%=p;
    if(fact>=p)fact%=p;
  }
  return (ret*modRev(fact))%p;
}

int dist(pll v,pll w){
  return abs1(v.first-w.first)+abs1(v.second-w.second);
}

int main(){
  int i,j,k;ll cnt=0;
  int h,w,d;
  cin>>h>>w>>d;
  int a[h][w];
  for(i=0;i<h;i++)for(j=0;j<w;j++)cin>>a[i][j];
  int q;
  cin>>q;
  int r[q],l[q];
  for(i=0;i<q;i++)cin>>l[i]>>r[i];
  vector<plll> v;
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      v.push_back(plll(a[i][j],pll(i,j)));
    }
  }
  sort(v.begin(),v.end());
  int p[h*w-d];
  for(i=0;i<h*w-d;i++)p[i]=0;
  for(i=0;i<h*w-d;i++){
    p[i]=dist(v[i].second,v[i+d].second);
  }
  int s[h*w+d];
  for(i=0;i<d;i++){
    s[i]=0;
    for(j=1;i+d*j<h*w+d;j++){
      s[i+d*j]=s[i+d*(j-1)]+p[i+d*(j-1)];
    }
  }
  for(i=0;i<q;i++){
    cout<<s[r[i]-1]-s[l[i]-1]<<endl;
  }
}


Measured memory_bytes: 6004
n = int(input())
s = [input() for _ in range(n)]

cnt_AB = 0
cnt_last_A = 0
cnt_start_B = 0
cnt_start_B_last_A = 0

for i in range(n):
    cnt_AB += s[i].count('AB')
    st = s[i][0]
    la = s[i][-1]
    if st == 'B' and la == 'A':
        cnt_start_B_last_A += 1
    elif st == 'B':
        cnt_start_B += 1
    elif la == 'A':
        cnt_last_A += 1

if cnt_start_B_last_A == 0:
    print(cnt_AB + min(cnt_start_B, cnt_last_A))
else:
    if cnt_start_B + cnt_last_A > 0:
        print(cnt_AB + cnt_start_B_last_A + min(cnt_start_B, cnt_last_A))
    else:
        print(cnt_AB + cnt_start_B_last_A - 1)


Measured memory_bytes: 3700
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

template<typename T>
constexpr T det2(const T &a1, const T &a2, const T &b1, const T &b2) {
  return a1 * b2 - b1 * a2;
}

void solve() {
  int n;
  cin >> n;
  rep(i, n) {
    double x1, y1, x2, y2, x3, y3;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    double d1 = x1 * x1 + y1 * y1, d2 = x2 * x2 + y2 * y2, d3 = x3 * x3 + y3 * y3;
    double npx = det2(d1, d2, y1, y2) + det2(d2, d3, y2, y3) + det2(d3, d1, y3, y1);
    double npy = det2(d2, d1, x2, x1) + det2(d3, d2, x3, x2) + det2(d1, d3, x1, x3);
    double dp  = 2 * (det2(x1, x2, y1, y2) + det2(x2, x3, y2, y3) + det2(x3, x1, y3, y1));
    double px = npx / dp, py = npy / dp;
    double r = hypot(px - x1, py - y1);
    printf("%.3f %.3f %.3f\n", px, py, r);
  }
}

Measured memory_bytes: 3272
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <cmath>
#include <bits/stdc++.h>

using namespace std;




int main()
{
    string s;
    cin>>s;
    for (int i=0;i<s.length();i++)
    {
        s[i]='x';
    }
    cout<<s;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define reps(i,s,n) for(int i=s; i<n; i++)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector< vector<int> > vvi;

int h, w, color;
bool checked[10][10];

void fill(int x, int y, int f, int t, vvi& panel) {
	panel[y][x] = t;
	if( 0<=x-1 && panel[y][x-1]==f ) {
		fill(x-1, y, f, t, panel);
	}
	if( x+1<w && panel[y][x+1]==f ) {
		fill(x+1, y, f, t, panel);
	}
	if( 0<=y-1 && panel[y-1][x]==f ) {
		fill(x, y-1, f, t, panel);
	}
	if( y+1<h && panel[y+1][x]==f ) {
		fill(x, y+1, f, t, panel);
	}
}

int count(int x, int y, vvi& p) {
	int cnt = 1;
	checked[y][x] = true;
	if( 0<=x-1 && p[y][x-1]==p[y][x] && !checked[y][x-1] ) {
		cnt += count(x-1, y, p);
	}
	if( x+1<w && p[y][x+1]==p[y][x] && !checked[y][x+1] ) {
		cnt += count(x+1, y, p);
	}
	if( 0<=y-1 && p[y-1][x]==p[y][x] && !checked[y-1][x] ) {
		cnt += count(x, y-1, p);
	}
	if( y+1<h && p[y+1][x]==p[y][x] && !checked[y+1][x] ) {
		cnt += count(x, y+1, p);
	}
	return cnt;
}

int dfs(int lp, vvi& panel) {
	if( lp==0 ) {
		vvi p = panel;
		if(color == p[0][0]) return 0;
		fill(0, 0, p[0][0], color, p);
		memset(checked, 0, sizeof(checked));
		return count(0, 0, p);
	}
	int res = 0;
	for(int c=1; c<=6; c++) {
		if(c == panel[0][0]) continue;
		vvi p = panel;
		fill(0, 0, p[0][0], c, p);
		res = max(res, dfs(lp-1, p));
	}
	return res;
}

int main() {
	while( cin >> h >> w >> color, h||w||color ) {
		vvi panel(h);
		rep(y, h) {
			panel[y].resize(w);
			rep(x, w) {
				cin >> panel[y][x];
			}
		}
		cout << dfs(4, panel) << endl;
	}
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define BIG_PRIME 1000000007

typedef long long ll;

signed main()
{
    int n,k; cin >> n >> k;
    ll ans = 0L;
    for (ll i = k; i <=n; ++i){
        ll min = (i-1)*i/2L;
        ll max = (n-i+1+n)*i/2L;
        ll tmp = max-min+1;
        ans += tmp;
        ans %= BIG_PRIME; 
    }
    ++ans;
    ans %= BIG_PRIME;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3676
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a,b,gcd=2;
		a=scan.nextInt();
		b=scan.nextInt();
		if(a>=b){
			GCD(a,b);
		}
		else{
			GCD(b,a);
		}
	}
	public static void GCD(int a,int b){
		if(a>0 && b>0){
			a=a%b;
			GCD(b,a);
		}
		else {
			System.out.println(a);
			return;
		}
	}
}


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

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

    int count;
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                if (x - (500*i + 100*j + 50*k) == 0) count++;
            }
        }
    }
    cout << count << endl;
    
    return 0;
}

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

int main()
{
	int n;
	int a[100000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	int num[100000] = { 0 };
	int num_sum[100000] = { 0 };

	for (int i = 0; i < n; i++) {
		num[a[i]]++;
	}

	for (int i = 0; i < 99998; i++) {
		num_sum[i] = num[i] + num[i + 1] + num[i + 2];
	}

	int max = 0;
	for (int i = 0; i < 100000; i++) {
		if (max < num_sum[i]) {
			max = num_sum[i];
		}
	}

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

Measured memory_bytes: 1408
<?php
$n = trim(fgets(STDIN));//7

$max   = 0;
$max_i = 0;

for ($i = 1; $i <= $n; $i++) {//7回ループする
    $j     = $i;//1
    $count = 0;
    while ($j % 2 === 0) {//$jが0になるまでループを続ける
        $j = $j / 2;//2で割る
        $count++;//$countを1プラスする
    }
    if ($count >= $max) {//もしカウントがマックスより大きければ
        $max   = $count;//maxの値を更新
        $max_i = $i;//$max_iの値を更新
    }
}

print $max_i;


Measured memory_bytes: 3700
//
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
//
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// solution 
#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input!{
        N: usize,
        A: [i64; N],
    }
    A.insert(0, 0);
    A.insert(N+1, 0);
    let sum = A.iter().fold((0,0), |(sum, pre), &nex| (sum + (nex - pre).abs(), nex));
    let sum = sum.0;

    for ind in 1..N+1 {
        println!("{}", sum - (A[ind+1] - A[ind]).abs() - (A[ind] - A[ind-1]).abs() + (A[ind+1] - A[ind-1]).abs());
    }
}


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

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
const int INF = INT_MAX/3;
const double EPS = 1e-14;

template<typename U, typename T>
void chmin(U &x, T y) { x = min(x, y); }

template<typename U, typename T>
void chmax(U &x, T y) { x = max(x, y); }

typedef long long int lli;

double abs(double x, double y) {
  return (x > y ? x - y : y - x);
}

int main() {
  int n, m;
  cin >> n >> m;
  cout << fixed << setprecision(12);
  double ans = -INF;
  int k = -1;
  REP(i, n + 1) {
    double avg = 1.0 * i * m / n;
    double mid;
    if (n % 2 == 0) {
      if (i > n / 2) mid = m;
      else if (i == n / 2) mid = m / 2.0;
      else mid = 0;
    } else {
      mid = (i > n / 2 ? m : 0);
    }
    if (abs(mid, avg) > ans) {
      ans = abs(mid, avg);
      k = i;
    }
  }
  REP(i, n) {
    if (i > 0) cout << " ";
    cout << (i < k ? m : 0);
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,a,b) for(int i=(a); i<(b); i++)
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<vi> vii;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007




const int MAX_V = 10000;


struct edge{ int to, cost; };


int V;
vector<edge> G[MAX_V];
int d[MAX_V];


void dijkstra(int s){
	//greater<pii>????????????????????¨??§first????°???????????????????????????????????????????
	priority_queue<pii, vector<pii>, greater<pii> > que;
	fill(d, d + V, INF);
	d[s] = 0;
	que.push(pii(0, s));

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


int main(){
	int n, m;
	cin>>n>>m;
	V = m;
	int a[4];
	edge tmp;
	rep(i,m){
		scanf("%d,%d,%d,%d",&a[0],&a[1],&a[2],&a[3]);
		// for(int j=0; j<4; j++){
		// 	cout<<" "<<a[j];
		// }
		// cout<<endl;
		a[0]--;
		a[1]--;
		tmp.to = a[1];
		tmp.cost = a[2];
		G[a[0]].pb(tmp);
		tmp.to = a[0];
		tmp.cost = a[3];
		G[a[1]].pb(tmp);
	}
	int x1,x2,y1,y2;
	scanf("%d,%d,%d,%d",&x1,&x2,&y1,&y2);
	int ans = y1 - y2;
	x1--;
	x2--;
	dijkstra(x1);
	ans-=d[x2];
	// for(int i = 0; i < n; i++){
	// 	cout<<i+1<<":"<<d[i]<<endl;
	// }
	dijkstra(x2);
	ans-=d[x1];
	cout<<ans<<endl;
}

Measured memory_bytes: 1500
k = gets.to_i
queue = [1,2,3,4,5,6,7,8,9]
a = 1
k.times do |i|
    a = queue[0]
    queue.shift
    if a % 10 != 0
        queue.push(a*10+ a%10 - 1)
    end
    queue.push(a*10 + a%10)
    if a % 10 != 9
        queue.push(a*10 + a%10 +1)
    end
end
puts a

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

bool x_dp[4001][50000];
bool y_dp[4001][50000];

int main(){
    string s;
    int X, Y;
    cin >> s >> X >> Y;
    vector<int> cnt;
    int temp = 0;
    for(int i = 0; i < s.length(); ++i){
        if(s[i] == 'F'){
            ++temp;
        }
        else{
            cnt.push_back(temp);
            temp = 0;
        }
    }
    cnt.push_back(temp);
    
    int n = cnt.size();
    
    const int dif = 25000;
    x_dp[0][cnt[0] + dif] = true;
    y_dp[0][dif] = true;
    
    int yn = n / 2;
    int xn = n - yn;
    
    // 原点を25000とする
    for(int i = 1; i < xn; ++i){
        int d = cnt[2 * i];
        for(int x = -8000; x <= 8000; ++x){
            x_dp[i][x+dif] = x_dp[i-1][x-d+dif] || x_dp[i-1][x+d+dif];
        }
    }
    for(int i = 0; i < yn; ++i){
        int d = cnt[2 * i + 1];
        for(int y = -8000; y <= 8000; ++y){
            y_dp[i+1][y+dif] = y_dp[i][y-d+dif] || y_dp[i][y+d+dif];
        }
    }
    
    if(x_dp[xn-1][X+dif] && y_dp[yn][Y+dif]){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
}

Measured memory_bytes: 371968
#include <cstdio>
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define REP(i,a,b) for(int i=a;i<b;++i)
#define SIZE 1000002
#define MOD 1000000007

using namespace std;

int main(){
	ll a,b,c,d;
	ll ans=-1e18;

	cin>>a>>b>>c>>d;
	ans = max(ans,a*d);
	ans=max(ans,a*c);
	ans = max(ans,b*d);
	ans=max(ans,b*c);
	cout<<ans;
} 

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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;}
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int ddx[6]={0,1,0,-1,1,-1},ddy[6]={-1,0,1,0,1,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll ww[1510000];
ll hh[1510000];
ll w[1510];
ll h[1510];
ll n,m;
vector<ll> anst;
int main(){
	while(1){
		cin>>n>>m;
		if(n==0&&m==0)break;
		memset(ww,0LL,sizeof ww);
		memset(hh,0LL,sizeof hh);
		memset(w,0LL,sizeof w);
		memset(h,0LL,sizeof h);
		REP(i,n){
			cin>>h[i];
		}
		REP(j,m){
			cin>>w[j];
		}
		ll t=0;
		for(ll i=0;i<n;i++){
			t=0;
			for(ll j=i;j<n;j++){
				t+=h[j];
				hh[t]++;
			}
		}
		for(ll i=0;i<m;i++){
			t=0;
			for(ll j=i;j<m;j++){
				t+=w[j];
				ww[t]++;
			}
		}
		ll ans=0;
		for(ll i=1;i<1510000;i++){
			ans+=(ll)hh[i]*ww[i];
		}
		anst.push_back(ans);
	}
	REP(i,anst.size())
		cout<<anst[i]<<endl;
	return 0;
}


Measured memory_bytes: 26692
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N,A,flag = 0;
    
    scanf("%d",&N);
    for(int i = 0; i < N && flag == 0; i++)
    {
        scanf("%d",&A);
        if(A%2 == 0)
        {
            if(!(A%3 == 0 || A%5 == 0))
            {
                flag = 1;
            }
        }
    }
    
    printf("%s\n",(flag == 0)? "APPROVED":"DENIED");
}


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

void swap(int *a,int *b){
    int t = *a;
    *a = *b;
    *b = t;
}
int main() {
    int n,ans=0,i,j,m;
    cin>>n;
    vector<int> a(n);
    for (i=0;i<n;i++) cin>>a[i];
    for (i=0;i<n-1;i++) {
        m=i;
        for (j=i;j<n;j++)if(a[j]<a[m])m=j;
        if(i!=m){swap(a[i],a[m]);ans++;}
        cout<<a[i]<<" ";
    }
    cout<<a[n-1]<<endl;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <cfenv>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>

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

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

    vector<long> h(n);
    vector<long> dp(n, 0);

    rep(i, n) cin >> h[i];

    for(int i = 1; i < n; ++i) {
        if(i == 1) 
            dp[i] = abs(h[i]-h[i-1]);
        else 
            dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
    }

    cout << dp.back() << endl;
}

Measured memory_bytes: 1792
N,K=map(int,input().split())
ab=[[0]*2 for i in range(N)]
for i in range(N):
  ab[i]=list(map(int,input().split()))
  
ab=sorted(ab,key=lambda x:x[0])
i=-1
while(K > 0):
  i+=1
  K -= ab[i][1]

print(ab[i][0])

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

int main() {
    string s;
    cin >> s;
    int mojisuu =0;
    mojisuu = s.size();
    char saisho, owari;
    saisho = s.at(0);
    mojisuu--;

    owari = s.at(mojisuu);
    mojisuu--;

    cout << saisho << mojisuu << owari << endl;
    
    
    
}

Measured memory_bytes: 256
/*
 * 16-10-29_AGC006_B.cpp
 *
 *  Created on: 2016/10/29
 *      Author: ryoma
 */

#include<iostream>
#include<algorithm>

using namespace std;

int main() {
	int N, x, a[200001];
	cin >> N >> x;
	if (x == 1 || x == 2 * N - 1) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
		if (N == 2) {
			for (int i = 1; i <= 2 * N - 1; i++)
				cout << i << endl;
		} else {
			a[N - 1] = x;
			int j = 1, NN = 2 * N - 1;
			if (x == 2)
				for (int i = 1; i <= N; i++) {
					a[(N - i + NN - 1) % NN] = (x + i * j + NN-1) % NN + 1;
					a[(N + i - 1) % NN] = (x - i * j + NN-1) % NN + 1;
					j *= -1;
				}
			else
				for (int i = 1; i <= N; i++) {
					a[(N - i + NN - 1) % NN] = (x - i * j + NN-1) % NN + 1;
					a[(N + i - 1) % NN] = (x + i * j + NN-1) % NN + 1;
					j *= -1;
				}
			for (int i = 0; i < 2 * N - 1; i++)
				cout << a[i] << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 2304
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
// #define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr double EPS = 1e-9;




int main() {

    ll a,b;
    cin>>a>>b;
    if(b-a>=2019){
        fin(0);
    } else {
        ll ans=LLINF;
        for(ll i=a;i<=b;i++){
            for(ll j=i+1;j<=b;j++){
                chmin(ans,i*j%2019);
            }
        }
        fin(ans);
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
const int N = 1e5 + 10 , M = 5e5+10 ,  MOD = 1e9+7;
const int OO = 0x3f3f3f3f;
const double EPS = 1e-3;
 
#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define ALL(v) ((v).begin()) , ((v).end())
#define SZ(v)  ((int)((v).size()))
typedef pair <int,int> pii ;
typedef vector < pii > vii ;
typedef vector < int > vi;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
 


int n , mons[N] , hero[N];

 
int main()
{
	
   // ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 
    
    scanf("%d",&n);
    for(int i = 0 ; i <= n ; ++i)
        scanf("%d", mons+i);

    for(int i = 0 ; i < n ; ++i)
        scanf("%d",hero+i);

    ll total = 0;
    for (int i = 0; i < n ; i++)
    {
        int ba2y = hero[i];
        int mn = min(ba2y , mons[i]);
        total += mn;
        ba2y -= mn;
        mons[i] -= mn;
        mn = min(ba2y , mons[i+1]);
        total += mn;
        ba2y -= mn;
        mons[i+1] -= mn;
    }
    cout << total << "\n";


    return 0;
}

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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
//int in() { int x; scanf("%d", &x); return x; }
//ll lin() { ll x; scanf("%lld", &x); return x; }
void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

int main(void){

	ll n;
	cin >> n;

	ll a[n+1], b[n];
	FOR(i, n+1){
		cin >> a[i];
	}

	FOR(i, n){
		cin >> b[i];
	}

	ll ans = 0;
	FOR(i, n){
		if(b[i] - a[i] > 0){
			if((b[i] - a[i]) - a[i+1] >= 0){
				ans += a[i] + a[i+1];
				a[i+1] = 0;
			} else {
				ans += b[i];
				a[i+1] = a[i+1] - (b[i] - a[i]);
			}
		} else {
			ans += b[i];
		}
	}

	cout << ans;

    return 0;
}


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

int main()
{
	int a, b;
	cin >> a >> b;

	int n = b - a;

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

	cout << s - b << endl;
	return 0;
}

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

int main() {
  long long int n, k, a, b, count=0;
  array<long long int, 100000> nums;
  cin >> n >> k;
  for (long long int i=0; i<100000; i++) {
    nums[i]=0;
  }
  for (long long int i=0; i<n; i++) {
    cin >> a >> b;
    nums[a-1]+=b;
  }
  for (long long int i=0; i<100000; i++) {
    count+=nums[i];
    nums[i]=count;
  }
  for (long long int i=0; i<100000; i++) {
    if (k<=nums[i]) {
      cout << i+1;
      break;
    }
  }
  return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 2e5+23;

int a[N];
map<int, int> m;

void solve() {
  int n; scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a+i);
    ++m[a[i]];
  }
  sort(a, a+n, greater<int>());
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (!m[a[i]]) continue;
    for (int j = 1<<30; j >= a[i]; j >>= 1) {
      int t = 1;
      if (j-a[i] == a[i]) {
	t = 2;
      }
      if (m.count(j-a[i]) && m[j-a[i]] >= t) {
	++ans;
	--m[a[i]];
	--m[j-a[i]];
	break;
      }
    }
  }
  printf("%d", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 13876
import java.util.*;

public class Main {

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

        int sum = 0;
        for (int i = 0; i < n; i++) {
            int left = sc.nextInt();
            int right = sc.nextInt();

            sum += (right-left) + 1;
        }

        System.out.println(sum);
    }
}


Measured memory_bytes: 27756
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
     	int s[] = new int[n];
		for(int i=0; i<n; i++) {
			s[i] = sc.nextInt();
		}
		int hp = 0;
		for(int i=0; i<n; i++) {
			for(int j=i+1; j<n; j++) {
				hp +=s[i]*s[j];
			}
		}
		System.out.println(hp);
	}
}

Measured memory_bytes: 21844
#!/usr/bin/env python3
import random
n = int(input())
a = list(map(int, input().split()))
k1, k2, k4 = 0, 0, 0
for a_i in a:
    if a_i % 4 == 0:
        k4 += 1
    elif a_i % 2 == 0:
        k2 += 1
    else:
        k1 += 1
t = min(k1, k4)
k1 -= t
k4 -= t
result = k1 == 0 or (k1 == 1 and not k2)
print([ 'No', 'Yes' ][result])


Measured memory_bytes: 15404
#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long
const int maxn=2e5+5;
int a[maxn];
int main()
{
    int n;
    ll k;
    scanf("%d%lld",&n,&k);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int l=1,r=1000000000;
    while(l<r)
    {
        int mid=(l+r)/2;
        ll cnt=0;
        for(int i=1;i<=n;i++)
            cnt+=(ll)((a[i]+mid-1)/mid-1);
        if(cnt>k) l=mid+1;
        else r=mid;
    }
    printf("%d\n",l);
    return 0;
}


Measured memory_bytes: 2460
FAST_IO = 0
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()

    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
rrmm = lambda n: [rrm() for _ in xrange(n)]

####
MOD = 998244353
YES, NO, IMP = "YES", "NO", "IMPOSSIBLE"
from collections import defaultdict as ddic


def solve(N, X, M):
    seen = {X: 0}
    t = 0
    while True:
        t += 1
        if t == N:
            return sum(seen)
        X2 = X*X%M
        if X2 not in seen:
            seen[X2] = t
            X = X2
            continue
        break

    base = sum(seen)
    N -= t
    u = seen[X2]
    mu = t - u
    period = sum(k for k,v in seen.items() if v >= u)
    Q, R = divmod(N, mu)
    #print("YO", base, N, u, mu, period, Q, R, ';', X)
    
    base += Q * period

    X = X2
    while R:
        base += X
        X *= X
        X %= M
        R -= 1

    return base

def brute(N, X, M):
    A = [X]
    while len(A) < N:
        A.append(A[-1] ** 2 % M)
    #print(A)
    
    return sum(A)
#N, X, M = 3,2,7
#print(brute(N,X,M))
#ans = solve(N,X,M)
#print ans

if 0:
    for n in xrange(1, 100):
        for x in xrange(1, 10):
            for m in xrange(x + 1, 100):
                if solve(n,x,m) != brute(n,x,m):
                    print("!", n,x,m, ';',solve(n,x,m), brute(n,x,m))
                    break
            
print solve(*rrm())


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

using namespace std;


int N, M;
bool edge[50][50] = {};
int a[50], b[50];
bool visited[50];

void check_dfs(int v) {
    if (visited[v]) {
        return;
    }

    visited[v] = true;

    for (int i = 0; i < N; i++) {
        if (edge[v][i]) {
            check_dfs(i);
        }
    }
}

int main() {
    int ans = 0;

    cin >> N >> M;

    for (int i = 0; i < M; i++) {
        cin >> a[i] >> b[i];
        edge[a[i]-1][b[i]-1] = true;
        edge[b[i]-1][a[i]-1] = true;
    }

    for (int i = 0; i < M; i++) {
        for (int j = 0; j < N; j++) {
            visited[j] = false;
        }

        edge[a[i]-1][b[i]-1] = false;
        edge[b[i]-1][a[i]-1] = false;

        check_dfs(0);

        bool connected = true;
        for (int j = 0; j < N; j++) {
            if (!visited[j]) {
                connected = false;
                break;
            }
        }
        if (!connected) {
            ans++;
        }

        edge[a[i]-1][b[i]-1] = true;
        edge[b[i]-1][a[i]-1] = true;
    }

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



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

int main(){
	int n, k;
	int ans=0;
	std::vector<int> lList;

	std::cin>>n>>k;
	lList.resize(n);

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

	std::stable_sort(lList.begin(), lList.end(), [](int x, int y){return x>y;});

	for(int i=0; i<k; i++)
		ans+=lList[i];

	std::cout<<ans<<std::endl;

	return 0;
}

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

const lli e5 = 100009;

lli n;
lli a[2*e5];

int main(){
	cin >> n;
	for(lli i = 0;i < n;i++) cin >> a[i];
	for(lli i = 0;i < n;i++) a[i] -= i+1;
	sort(a,a+n);
	lli a_n_2 = a[n/2];
	for(lli i = 0;i < n;i++){
		cerr << a[i] << endl;
		a[i] -= a_n_2;
	}
	lli ans = 0;
	for(lli i = 0;i < n;i++){
		cerr << a[i] << " " << abs(a[i]) << endl;
		ans += abs(a[i]);
	}
	cout << ans << endl;
}


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

const int N = 201000, MOD = 1e9 + 7;

namespace {
  int Mul(int x, int y) { return 1LL * x * y % MOD; }
  int Kissme(int x, int y) {
    int c = 1;
    while(y) {
      if(y & 1) c = Mul(c, x);
      x = Mul(x, x);
      y >>= 1;
    }
    return c;
  }
}

struct Node {
  int c, w;

  bool operator < (const Node &rhs) const {
    return c != rhs.c ? c < rhs.c : w < rhs.w;
  }
}a[N];

int fac[N], inv[N], n, X, Y, tmp[N], fa[N], siz[N];
map<int, int> mp;

void Init(void) {
  fac[0] = 1;
  for(int i = 1; i <= n; i++)
    fac[i] = Mul(fac[i - 1], i);
  inv[n] = Kissme(fac[n], MOD - 2);
  for(int i = n - 1; i >= 0; i--)
    inv[i] = Mul(inv[i + 1], i + 1);
}

int C(int x, int y) {
  return Mul(Mul(fac[x], inv[y]), inv[x - y]);
}

int Find(int x) {
  return fa[x] == x ? x : fa[x] = Find(fa[x]);
}

void Merge(int x, int y) {
  x = Find(x), y = Find(y);
  fa[y] = x;
  siz[x] += siz[y];
}

int main(void) {
  scanf("%d%d%d", &n, &X, &Y);
  Init();
  for(int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i].c, &a[i].w);
  }
  sort(a + 1, a + n + 1);
  for(int i = 1; i <= n; i++) {
    if(a[i].c != a[i - 1].c)
      mp[a[i].w]++;
    fa[i] = i, siz[i] = 1;
  }
  for(int i = 1; i <= n; i++) {
    int j = i;
    while(a[j + 1].c == a[j].c) j++;
    for(int k = i; k <= j; k++)
      tmp[k] = a[k].w;
    if(!--mp[a[i].w]) mp.erase(a[i].w);
    int lim = max(X - a[i].w, Y - mp.begin()->first);
    int ind = upper_bound(tmp + i + 1, tmp + j + 1, lim) - tmp - 1;
    for(int k = i + 1; k <= ind; k++)
      Merge(i, k);
    mp[a[i].w]++;
    i = j;
  }
  int lim = mp.begin()->first, root, Ans = 1, all = 0;
  for(int i = 1; i <= n; i++)
    if(fa[i] == i && a[i].w == lim) {
      root = i, all = siz[i];
      break;
    }
  lim = Y - lim;
  for(int i = 1; i <= n; i++)
    if(fa[i] == i && a[i].w <= lim && i != root && a[i].c != a[root].c) {
      Ans = Mul(Ans, C(all + siz[i], all));
      all += siz[i];
    }
  cout << Ans << endl;
}


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

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

	int n,d;

	cin >> n >> d;
	
	cout << ceil((n*1.0)/(2*d+1)) << '\n';
	return 0;
}



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

using namespace std;

int main(){
  
  cout << fixed << setprecision(12);

  int n;
  int s[1000]={};
  double m;
  double sum = 0;

  while(1)
    {
      cin >> n;
      if(n == 0) break;
      sum = 0;

      for(int i=0;i < n;i++)
	{
	  cin >> s[i];
	  sum += s[i];
	}

      m = sum / n;
      double sgn = 0.0;
  
      for(int j=0;j < n;j++)
	{
	  sgn += pow(s[j]-m,2);
	}
      
      cout << sqrt(sgn/n) << endl;
    }
  return 0;
}
  



Measured memory_bytes: 3236
N=int(input())
A=list(map(int,input().split()))
d={1:0,2:0,3:0}
for a in A:
    d[a]+=1
dp=[[[0]*(N+1) for j in range(d[2]+d[3]+1)] for i in range(d[3]+1)]
for i in range(d[3]+1):
    for j in range(d[2]+d[3]-i+1):
        for k in range(N-i-j+1):
            if i+j+k==0:continue
            dp[i][j][k]=N
            if i>0:
                dp[i][j][k]+=dp[i-1][j+1][k]*i
            if j>0:
                dp[i][j][k]+=dp[i][j-1][k+1]*j
            if k>0:
                dp[i][j][k]+=dp[i][j][k-1]*k
            dp[i][j][k]/=i+j+k
print(dp[d[3]][d[2]][d[1]])

Measured memory_bytes: 500744
// finish date: 2018/01/20
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000


int main() {
    int x,a,b;
    cin>>x>>a>>b;
    if(abs(x-a)>abs(x-b)) cout<<"B"<<endl;
    else cout<<"A"<<endl;
    return 0;
}


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

int n;
vector<ll> a;

ll calc(ll x){
    ll res = 0;
    rep(i,n){
        res += abs(a[i]-x);
    }
    return res;
}

int main(void){
    cin>>n;
    a.resize(n);
    rep(i,n){
        cin>>a[i];
        a[i] -= i+1;
    }
    sort(all(a));
    ll l = a[0], r = a[n-1];
    while(l + 2 < r){
        ll m1 = (l*2+r)/3, m2 = (l+r*2)/3;
        if(calc(m1) < calc(m2)) r = m2;
        else l = m1;
    }
    cout<<min({calc(l),calc((l+r)/2),calc(r)})<<endl;
    return 0;
}


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

const int len = 393;
int main(){
  int n;
  cin >> n;
  vector<int> dp(len+1,-1);
  dp[0] = 0;

  rep(i,n){
    int s,l,p;
    cin >> s >> l >> p;
    rep(j,len+1){
      if(dp[j]<0)continue;
      for(int t=s;t<=l;t++){
	if(j+t<=len){
	  dp[j+t] = max(dp[j+t], dp[j] + p);
	}
      }
    }
  }

  int m;
  cin >> m;
  vector<int> ans(m);
  rep(i,m){
    int w;
    cin >> w;
    if(dp[w]<0){
      cout << -1 << endl;
      return 0;
    }
    ans[i] = dp[w];
  }
  rep(i,m)cout << ans[i] << endl;
}

Measured memory_bytes: 1196
class Counter(dict):
  def __missing__(self, i):
    return 0

n = int(input())

s = Counter()

for _ in range(n):
  i = input()
  s[i] += 1

s = list(sorted(s.items(), key=lambda x: -x[1]))
m = s[0][1]

ans = []
for key, value in s:
  if value == m:
    ans.append(key)
  else:
    break

ans.sort()

print('\n'.join(ans))


Measured memory_bytes: 43228
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define MOD 1000000007
#define INT long long int
using namespace std;
const long long INF = numeric_limits<long long>::max();


int main()
{
    int N;
    cin >> N;
    string s;
    int val = N;
    while (val != 0){
        s += to_string(abs(val%2));
        if (val < 0 && abs(val%2) == 1){
            val /= -2;
            val += 1;
        }else{
            val /= -2;
        }
    }
    reverse(s.begin(),s.end());
    if (s.empty()) s += "0";
    cout << s << endl;
    return 0;
}

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

using namespace std;

//typedef pair<int,int> P;



int main(){
	int N;
	int a[100];

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

	sort(a,a+N);
	reverse(a,a+N);

	int alice = 0;
	int bob = 0;
	for(int i=0;i<N;i++){
		if(i%2==0) alice += a[i];
		else bob += a[i];
	}

	printf("%d\n", alice - bob);

	return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10**9 + 7

dp = [[0] * (K + 1) for _ in range(N + 1)]  # dp[child][candy] 残りcandy個の場合の数
dp[0][K] = 1

for child in range(1, N + 1):
    sumDp = [0] * (K + 2)
    for i in range(1, K + 2)[:: -1]:
        sumDp[i - 1] += sumDp[i] + dp[child - 1][i - 1]

    for candy in range(K + 1):
        dp[child][candy] = (sumDp[candy] - sumDp[min(K, candy + A[child - 1]) + 1]) % MOD

print(dp[N][0] % MOD)

Measured memory_bytes: 135844
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#include <cctype>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)

#define AAA (1000000007) 


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;
typedef vector<int> vecI;

ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i = 0; i < b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}


int main() {
	int i, j, k;
	int N, M, K;

	string S;
	cin >> S;
	N = S.size();
	j = 0;
	rep(i, 0, N) {
		j += S[i] - '0';
		j %= 9;
	}
	cout << (j == 0 ? "Yes" : "No");

	return 0;
}


Measured memory_bytes: 3728
use proconio::input;
use std::cmp::max;

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    let mut dp = vec![vec![i64::min_value() / 2; 3]; n + 2];
    dp[0][0] = 0;
    dp[1][0] = 0;

    for i in 0..n {
        dp[i + 2][0] = dp[i][0] + a[i];
        dp[i + 2][1] = max(dp[i + 1][0], dp[i][1] + a[i]);
        dp[i + 2][2] = max(dp[i + 1][1], dp[i][2] + a[i]);
    }

    let ans = if n % 2 == 0 {
        max(dp[n + 1][1], dp[n + 1][0])
    } else {
        max(dp[n + 1][1], dp[n + 1][2])
    };

    println!("{}", ans);
}


Measured memory_bytes: 16700
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {

	str := getStdin()
	list := strings.Split(str, ",")

	rtn := ""
	for _, val := range list {
		if len(rtn) != 0 {
			rtn += " "
		}
		rtn += val
	}

	fmt.Printf("%s\n", rtn)
}

func getStdin() string {
	sc.Scan()
	return sc.Text()
}
func getStdinInt() int {
	sc.Scan()
	rtn, _ := strconv.Atoi(sc.Text())
	return rtn
}
func getStdinIntArr() []int {
	sc.Scan()
	str := sc.Text()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}


Measured memory_bytes: 640
#include <stdio.h>
#define MAX 2000001
#define N 10000

int main(){

int C[N];
int A[MAX];
int B[MAX];
int i,j,num;


scanf("%d",&num);
for(i=1;i<=num;i++){
  scanf("%d",&A[i]);
}


for(i=0;i<N;i++){
  C[i] = 0;
  }

for(j=1;j<=num;j++){
  C[A[j]]++;
}

for(i=1;i<=N;i++){
  C[i] = C[i] + C[i-1];
}

for(j=num;j>0;j--){
  B[C[A[j]]] = A[j];
  C[A[j]]--;
}
for(i=1;i<num;i++){
printf("%d ",B[i]);
}
printf("%d\n",B[num]);

}

Measured memory_bytes: 18372
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x;
  cin >> x;
  x -= 400;
  cout << 8-x / 200 << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  int r = 0,l = 0;
  for(int i = 0;i<S.size();i++){
    if(i == S.size()-1 && S.at(i) == 'R'){
      cout << r << endl;
    }
    else if(S.at(i) == 'R' && S.at(i+1) == 'R' && i != S.size()-1){
      cout << 0 << " ";
      r++;
    }
    else if(S.at(i) == 'R' && S.at(i+1) == 'L'){
      r++;
      while( i<S.size()-1 && S.at(i+1) == 'L'){
        l++;
        i++;
      }
      cout << l/2+r-r/2 << " " << r/2+l-l/2 << " ";
      for(int k = 0;k<l-1;k++){
        cout << 0 << " ";
      }
      r = 0;
      l = 0;
    }
  }
  return 0;
}

Measured memory_bytes: 640
#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);
    ll arr[120];
    ll nCr(ll n, ll r)
    {
        ll C[r+1];
        memset(C, 0, sizeof(C));
        C[0] = 1;
        for (ll i = 1; i <= n; i++)
        {
            for (ll j = min(i, r); j > 0; j--)
                C[j] = (C[j] + C[j-1]);

        }
        return C[r];
    }
    int main()
    {
    //    FastRead
        //freopen("output.txt", "w", stdout);
        ll tot=0;
        long double ans=0,sum=0,cnt=0;
        map<ll,int>N,R;
        int n,a,b;
        cin>>n>>a>>b;
        for(int i=0; i<n; i++)
            cin>>arr[i],N[arr[i]]++;
        sort(arr,arr+n);
        ll last ;
        for(int i=n-1; i>=0; i--)
        {
            sum+=arr[i];
            R[arr[i]]++;
            cnt++;
            if(cnt>b)
                break;
            if(cnt==a)
            {
                last = arr[n-1];
                ans=sum/cnt;
            }
            if(cnt>=a)
            {
                long double cur=(sum/cnt);
                if(cnt==a)
                    {tot+=nCr(N[arr[i]],R[arr[i]]);
                     //cout << N[arr[i]] << " " << R[arr[i]] << " " << arr[i] <<endl;
                    }
                else if(arr[i]==last)
                {
                 tot+=nCr(N[arr[i]],R[arr[i]]);
                }
            }
        }
        cout<<setprecision(18)<<fixed<<ans<<endl;
        cout<<tot<<endl;
        return 0;
    }


Measured memory_bytes: 3804