akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

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)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D, w) for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

const char en = '\n';

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

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

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

	string s,t; cin >> s >> t;
	
	s += s;

	map<char,vector<ll>> sIx;
	rep(i,s.size()) for (char c = 'a'; c <= 'z'; ++c) {
	  if (s[i] == c) sIx[s[i]].push_back(i);
	}

	vector<vector<ll>> chIx(s.size(), vector<ll>(26,-1));
	chIx[s.size() - 1][s[0] - 'a'] = 0;
	rrep(i, s.size()-1) {
	  chIx[i][s[i+1] - 'a'] = i+1;
		if (i < s.size() - 2) {
			for (char c = 'a'; c <= 'z'; ++c) if (c != s[i+1]) chIx[i][c - 'a'] = chIx[i+1][c - 'a'];
		}
	}

	ll nowIx = - 1, ans = -1;
	rep(i, t.size()) {
	  if (nowIx < 0) nowIx += (ll) s.size() / 2;
		nowIx %= (s.size() / 2);
	  if (chIx[nowIx][t[i] - 'a'] == -1) { cout << -1 << endl; return 0; }
	  ans   += chIx[nowIx][t[i] - 'a'] - nowIx;
		nowIx += chIx[nowIx][t[i] - 'a'] - nowIx;
	}

	cout << ans+1 << endl;
}


Measured memory_bytes: 50792
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[][] ab = new int[N][2];
        for(int i=0;i<N;i++){
            ab[i][0] = sc.nextInt();
            ab[i][1] = sc.nextInt();
        }
        int[][] pt = new int[M][2];
        for(int j=0;j<M;j++){
            pt[j][0] = sc.nextInt();
            pt[j][1] = sc.nextInt();
        }
        for(int i=0;i<N;i++){
            int a = ab[i][0];
            int b = ab[i][1];
            int ans = Integer.MAX_VALUE;
            int idx = -1;
            for(int j=0;j<M;j++){
                int dis = Math.abs(a-pt[j][0])+Math.abs(b-pt[j][1]);
                if(dis<ans){
                    ans = dis;
                    idx = j+1;
                }
            }
            System.out.println(idx);
        }
        //System.out.println(ans);
    }
}


Measured memory_bytes: 23380
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e18;
const ll mod=1e9+7;

int main(){
    ll n;
    cin >> n;
    ll ans=0;
    while(n){
        ll r=n%10;
        if(r==2) ans++;
        n/=10;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

int main(){
    ll N,ma=-100,x,k;
    cin >> N;
    if(N==1){
        cout << 1 << endl;
    }
    else if(N<=3){
        cout << 2 << endl;
    }
    else if(N<=7){
        cout << 4 << endl;
    }
    else if(N<=15){
        cout << 8 << endl;
    }
    else if(N<=31){
        cout << 16 << endl;
    }
    else if(N<=63){
        cout << 32 << endl;
    }
    else if(N<=100){
        cout << 64 << endl;
    }
}

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

int main(){
	int n;
	scanf("%d", &n);
	int hight[n+1];
	int max=0, idou=0;
	scanf("%d", &hight[1]);
	for(int i=2; i<=n; i++){
		scanf("%d", &hight[i]);
		if(hight[i]<=hight[i-1]){
			idou++;
			if(max<idou) max=idou;
		}
		else{
			idou=0;
			if(max<idou) max=idou;
		}
	}
	printf("%d", max);
	
	
	return 0;
}

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

const int maxn = (int) 2e5 + 20;
const int MOD = (int) 1e9 + 7;

int n, m;
int fac[maxn];
int inv[maxn];

LL fp(LL a, LL n, LL m)
{
    LL res = 1;
    while(n)
    {
        if(n & 1) res = res * a % m;
        a = a * a % m;
        n >>= 1;
    }
    return res;
}

int isprime[maxn];
int primes[maxn];
int get_primes()
{
    int m = 0;
    for(int i = 2; i < maxn; i++)
    {
        if(!isprime[i]) isprime[i] = primes[m++] = i;
        for(int j = 0; j < m; j++)
        {
            if(primes[j] * i >= maxn) break;
            isprime[primes[j] * i] = primes[j];
            if(i % primes[j] == 0) break;
        }
    }
    return m;
}


void work()
{
    fac[0] = 1;
    for(int i = 1; i < maxn; i++) fac[i] = (LL) fac[i - 1] * i % MOD;
    inv[maxn - 1] = fp(fac[maxn - 1], MOD - 2, MOD);
    for(int i = maxn - 2; i >= 0; i--) inv[i] = (LL) inv[i + 1] * (i + 1) % MOD;
    int pm = get_primes();
//    for(int i = 0; i < 26; i++) cout <<primes[i] <<endl;
    cin >>n >>m;

    LL ans = 1;
//    cout <<m <<endl;
    for(int i = 0; i < pm; i++)
    {
        int p = primes[i], c = 0;
        while(m % p == 0)
        {
            m /= p;
            c++;
        }
        if(c == 0) continue;

//        cout <<m <<" " <<p <<" " <<c <<endl;
        LL pp = ((LL)fac[c + n - 1] * inv[n - 1] % MOD) * inv[c] % MOD;
        ans = ans * pp % MOD;

//        ans = ans * inv[c] % MOD;
    }
    if(m != 1) ans = ((LL)ans * n) % MOD;

    cout <<ans <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
    work();
    return 0;
}


Measured memory_bytes: 2688
#include<iostream>
#include<string>
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  std::string str1 = std::string(b,a+'0');
  std::string str2 = std::string(a,b+'0');
  
  if (str1 < str2){
    cout << str1 <<endl;
  }
  else{
    cout << str2 << endl;
  }
  return 0;
}
    
    
  


Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
const int INF = 1e17;
/* libraries */

constexpr int MOD = 1e9+7;
struct mint
{
	int v;
	mint():v(0){}
	mint(int v):v((v+MOD)%MOD){}
	mint operator-()const{ return mint(0) - *this; }
	mint& operator+=(const mint& a){ if((v+=a.v)>=MOD) v-=MOD; return *this; }
	mint& operator-=(const mint& a){ if((v+=MOD-a.v)>=MOD) v-=MOD; return *this; }
	mint& operator*=(const mint& a){ (v*=a.v)%=MOD; return *this; }
	mint& operator/=(const mint& a){ (*this) *= a.inv(); return *this; }
	mint operator+(const mint& a)const{ return mint(*this) += a; }
	mint operator-(const mint& a)const{ return mint(*this) -= a; }
	mint operator*(const mint& a)const{ return mint(*this) *= a; }
	mint operator/(const mint& a)const{ return mint(*this) /= a; }
	bool operator<(const mint& a)const{ return v < a.v; }
	bool operator==(const mint& a)const{ return v == a.v; }
	mint pow(int k)const{ mint r(1),t(v); while(k){ if(k&1) r*=t; t*=t; k>>=1; } return r; }
	mint inv()const{ return pow(MOD-2); }
	static mint comb(int n, int k) {
		if(n-k<k) k=n-k;
		mint num(1), dom(1);
		for(int i=0;i<k;i++) { num*=n-i; dom*=i+1; }
		return num/dom;
	}
};
std::istream& operator>>(std::istream&i,mint&a){ int t; i>>t; a=mint(t); return i; }
std::ostream& operator<<(std::ostream&o,const mint&a){ o<<a.v; return o; }


void f(std::vector<mint>& a) {
	int n=a.size();
	for(int i=1;i<n;i++) {
		for(int j=2;j*i<n;j++) {
			a[i]+=a[i*j];
		}
	}
}

void finv(std::vector<mint>& a) {
	int n=a.size();
	for(int i=n-1;i>0;i--) {
		for(int j=2;j*i<n;j++) {
			a[i]-=a[i*j];
		}
	}
}


signed main() {
	int n,k;
	std::cin >> n >> k;

	std::vector<mint> x(k+1,1);
	f(x);
	for(int i=1;i<=k;i++) x[i]=x[i].pow(n);
	finv(x);
	mint ans=0;
	for(int i=1;i<=k;i++) ans+=mint(i)*x[i];
	print(ans);

	return 0;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for (int i=1; i<=n; i+=2) {
        int dn = 0;
        rep1(j, i) {
            if (i%j==0) ++dn;
        }
        if (dn==8) ++ans;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 1000005
#define MAX_H 1005
#define MAX_W 1005

int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
int INF = 1e8;
struct state{
  int y,x,cost;
  bool operator < (const state &p)const{
    return cost > p.cost;
  }
};

int H,W,N;
int si,sj,ti,tj;
char a[MAX_N];
int b[MAX_N];
set<int> c[4];

char t[MAX_H][MAX_W];
int d[MAX_H][MAX_W];

int func(int k,int dir){
  set<int> :: iterator it;
  it=c[dir].lower_bound(k);
  if(it==c[dir].end())return INF;
  else return *it;
}

bool solve(){
  fill( (int*)d[0], (int*)d[MAX_H] , INF );
  priority_queue< state > Q;
  Q.push( (state){si,sj,0} );
  d[si][sj]=0;
  while(!Q.empty()){
    state s=Q.top();Q.pop();
    if(s.cost > d[s.y][s.x])continue;
    if(t[s.y][s.x]=='G')return true;
    for(int ndir=0;ndir<4;ndir++){
      int ncost=func(s.cost,ndir);
      if(ncost==INF)continue;
      int ny=s.y+dy[ndir];
      int nx=s.x+dx[ndir];
      if(ny<0 || nx<0 || ny>=H || nx>=W )continue;
      if(t[ny][nx]=='#')continue;
      if(ncost < d[ny][nx]){
        d[ny][nx]=ncost; 
        Q.push( (state){ny,nx,ncost} );
      }
    }
  }
  return false;
}

int main(){
  while(1){
    scanf("%d %d %d",&H,&W,&N);
    if(H==0&&W==0&&N==0)break;
    for(int i=0;i<4;i++)c[i].clear();
    
    scanf("%s",a);
    for(int i=0;i<N;i++){
      b[i+1]=b[i]+(a[i]=='L'?3:1);
      if(b[i+1]>=4)b[i+1]-=4;
    }
    for(int i=0;i<=N;i++)c[ b[i] ].insert(i);
    
    for(int i=0;i<H;i++){
      scanf("%s",t[i]);
      for(int j=0;j<W;j++){
        if(t[i][j]=='S')si=i,sj=j;
      }
    }
    printf(solve() ? "Yes\n" : "No\n" );
  }
  return 0;
}

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

void normalize(vector<int>& v){
	const int minim = *min_element(begin(v), end(v));
	transform(begin(v), end(v), begin(v), [minim](const int x){
			return x - minim + 1; }); }

int main(){
	int n;
	cin >> n;
	vector<int> p(n);
	for(auto& x : p) cin >> x, --x;

	vector<int> s_part_a(n, 1), s_part_b(n+1, -1);

	s_part_b[0] = n;

	for(int i = 0; i < n; ++i){
		s_part_a[p[i]] += i;
		s_part_b[p[i]+1] -= i; }

	partial_sum(begin(s_part_a), end(s_part_a), begin(s_part_a));
	partial_sum(begin(s_part_b), end(s_part_b), begin(s_part_b));
	s_part_b.pop_back();
	normalize(s_part_a), normalize(s_part_b);


	for(const auto x : s_part_a) cout << x << ' ';
	cout << endl;
	for(const auto x : s_part_b) cout << x << ' ';
	cout << endl;

	return 0; }


Measured memory_bytes: 896
#import<vector>
#import<set>
#import<cstdio>
using namespace std;
int main(){
	long long H,W;
	int N,h,w,h0,w0,z,t;
	scanf("%lld%lld%d",&H,&W,&N);
	vector<long long>v(10);
	set<pair<int,int>>points;
	v[0]=(H-2)*(W-2);
	for(;N--;){
		scanf("%d%d",&h,&w),h--,w--,points.emplace(h,w);
		for(h0=-1;h0<2;h0++)for(w0=-1;w0<2;w0++)if(1<=h+h0&&h+h0<H-1 && 1<=w+w0&&w+w0<W-1){
			for(t=z=0;z<9;z++)t+=points.find({h+h0+z/3-1,w+w0+z%3-1})!=points.end();
			v[t-1]--,v[t]++;
		}
	}
	for(auto &e:v)printf("%lld\n",e);
}

Measured memory_bytes: 4864
#include <iostream>
#include <cstring>
#include <string>
using namespace std;

int main(){
	int n,k;
	int x,m;
	int a[11];
	int ans[10];
	
	memset(a,1,sizeof(a));
	cin >> n >> k;
	for(int i = 0;i < k;i++){
		cin >> x;
		a[x] = 0;
	}
	
	while(1){
	
		int i = 0;
		m = n;
		while(n){
			ans[i++] = n%10;
			n/=10;
		}
		int flag = 0;
		for(int j = 0;j < 10;j++){
			for(int k = 0;k < i;k++){
				if(!a[j]&&ans[k]==j){
					m++;
					n = m;
					flag = 1;
					break;
				}
			}
			if(flag){
				break;
			}
		}
		
		if(!n){
			break;
		}
	}
	cout << m;	
}

Measured memory_bytes: 256
//【ライブラリここから】
// 1. 入力の容易化（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 $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")
    };
}
//【ライブラリここまで】

fn main() {
    input! {
        s: String
    }
    if s == "SSS" {
        println!("{}", 0);
        return;
    }
    if s == "RRS" {
        println!("{}", 2);
        return;
    }
    if s == "SRR" {
        println!("{}", 2);
        return;
    }
    if s == "RRR" {
        println!("{}", 3);
        return;
    }
    println!("{}", 1);
    return;
}


Measured memory_bytes: 2092
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int m, n, a[100][100], b[100];
    int i, j, sum[100]={0};
    scanf("%d %d", &n, &m);
    for (i=0;i<n ;i++ ) {
        for (j=0; j<m; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    for (i=0; i<m; i++) {
        scanf("%d", &b[i]);
    }
    for (i=0; i<n; i++) {
        for (j=0; j<m; j++) {
            sum[i]+=a[i][j]*b[j];
            //printf("%d\n", a[i][j]);
        }
    }

    for (i=0; i<n; i++) {
        printf("%d\n", sum[i]);
    }
    return 0;
}



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

using namespace std;

#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container), element) != container.end())
#define INF 0x3f3f3f3f
#define f1(n) for(int i=0 ; i<n ; i++)
#define f2(m) for(int j=0 ; j<m ; j++)
#define ll long long
typedef pair<int, int> iPair;
const double epsilon = 1e-7;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int x, y;
  cin >> x >> y;
  bool ok = false;
  for (int i=0; i<=x; ++i) {
    if (2 * i + 4 * (x - i) == y) {
      ok = true;
      break;
    }
  }
  if (ok) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define int long long


signed main(){
	int n;cin>>n;
	vector<int> a(n+1,0);
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<n;i++)a[i+1]+=a[i];
	map<int,int>cnt;
	for(auto&& w:a)cnt[w]++;
	int sum=0;
	for(auto&& w:cnt)sum+=w.second*(w.second-1)/2;
	cout<<sum<<endl;
//  	for(auto&& w:cnt)cerr<<w.first<<" "<<w.second<<endl;
  //	cerr<<endl;
  	//for(auto&& w:a)cerr<<w<<" ";
  
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;  
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define repr(i, a, b) for(ll i = b-1; i >= a; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
// const ll INF = 1LL << 60;
const ll INF = 100000000000;
#define pp pair<ll, pair<ll, ll>> 
// #define fi first
// #define se second

void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif          // -D_DEBUG をつけて実行 cf)可変引数
 
// rep(i, 0, sz(v)) cout << v[i] << " \n"[i==sz(v)-1];
 
////////////////////////////////////////////////////////

class PF{
	public:
	ll MAXR;
	vector<ll> PN_chk;

	PF(ll n){
		MAXR = n;
		PN_chk.resize(n+1);
		rep(i, 0, n+1) PN_chk[i] = 1;
	}

	//O(MAXR)
	void se(){
		ll MAXRR=sqrt(MAXR)+1;
		PN_chk[0]=0;PN_chk[1]=0;
		Rep(i,2,MAXRR){
			if(PN_chk[i]==1) Rep(j,i,ll(MAXR/i)){PN_chk[j*i]=i;}
		}
	}

	//O(logn)
	set<ll> prime;

	void primeClear(){
		prime.clear();
	}

	void prime_factorize(ll n){
		if(n<=1) return;
		if(PN_chk[n]==1){prime.insert(n);return;}
		prime.insert(PN_chk[n]);
		prime_factorize(ll(n/PN_chk[n]));
	}
};


ll b[1000005];

int main() {
	PF pf = PF(1000001);
	pf.se();
	ll n; cin >> n;
	Vl a(n);
	rep(i, 0, n) cin >> a[i];

	rep(i, 0, n){
		pf.primeClear();
		pf.prime_factorize(a[i]);
		for(auto it : pf.prime) b[it]++;
	}
	int f = 1;
	Rep(i, 1, 1000000){
		if(b[i] == n){
			f = 3;
			break;
		}
		if(b[i] >= 2) f = 2;
	}
	if(f == 1) co("pairwise coprime");
	else if(f == 2) co("setwise coprime");
	else if(f == 3) co("not coprime");

    return 0;
}

Measured memory_bytes: 26572
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+5;
const int p=1e9+7;

int read()
{
	int s=0;
	char c=getchar(),lc='+';
	while (c<'0'||'9'<c) lc=c,c=getchar();
	while ('0'<=c&&c<='9') s=s*10+c-'0',c=getchar();
	return lc=='-'?-s:s;
}
void write(int x)
{
	if (x<0)
	{
		putchar('-');
		x=-x;
	}
	if (x<10) putchar(x+'0');
	else
	{
		write(x/10);
		putchar(x%10+'0');
	}
}
void print(int x,char c='\n')
{
	write(x);
	putchar(c);
}
int power(int a,int b)
{
	a%=p;
	int ret=1;
	while (b)
	{
		if (b&1) ret=ret*a%p;
		a=a*a%p;
		b/=2;
	}
	return ret;
}
int fact[N],SUM=0,dp[N],sum[N];

signed main()
{
	int n=read(),h=read(),d=read();
	fact[0]=1;
	sum[0]=dp[0]=1;
	for (int i=1;i<=n;i++)
	{
		fact[i]=fact[i-1]*i%p;
		SUM=(SUM+fact[i])%p;
	}
	for (int i=1;i<=h;i++)
	{
		dp[i]=(sum[i-1]-(i-d-1>=0?sum[i-d-1]:0)+p)%p*SUM%p;
		sum[i]=(sum[i-1]+dp[i])%p;
	}
	print(dp[h]*fact[n]%p*power(SUM,p-2)%p);

	return 0;
}

Measured memory_bytes: 27020
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

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, a = li()
x = list(li())

dp = [[[0]*(50*50+1) for _ in range(n+1)] for _ in range(n+1)]
dp[0][0][0] = 1

for i in range(1, n+1):
    for j in range(n+1):
        for k in range(50*50 + 1):
            dp[i][j][k] += (dp[i-1][j-1][k-x[i-1]] if (j-1 >= 0 and k-x[i-1] >= 0) else 0)\
                            + dp[i-1][j][k]

ans = 0
for i in range(1, n+1):
    ans += dp[n][i][a*i]

print(ans)

Measured memory_bytes: 93148
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX=200000;

int main(void){
	int R[MAX],n;
	
	cin>>n;
	for(int i=0;i<n;i++)cin>>R[i];
	
	int maxv=-2000000000;
	int minv=R[0];
	
	for(int i=1;i<n;i++){
		maxv=max(maxv,R[i]-minv);
		minv=min(minv,R[i]);
	}
	cout<<maxv<<endl;
	return 0;
}

Measured memory_bytes: 3872
#!python3

iim = lambda: map(int, input().rstrip().split())
from collections import deque

def resolve():
    N = int(input())
    S = "abcdefghij"

    q = deque([("", 0, 0)])
    ans = []
    while q:
        #print(q)
        s1, i1, i2 = q.popleft()
        #print(s1, i1, i2)

        if i1 == N:
            ans.append(s1)
            continue
        for i in range(i2):
            q.append((s1+S[i], i1+1, i2))
        q.append((s1+S[i2], i1+1, i2+1))

    print(*ans, sep="\n")


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 23960
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int i;
		ArrayList<Double> v = new ArrayList<>();
		for(i = 0; i < n; i++) {
			v.add(scan.nextDouble());
		}

		while(v.size() > 1) {
			Collections.sort(v);
			v.add((v.get(0) + v.get(1)) / 2);
			v.remove(0);
			v.remove(0);
		}
		System.out.println(v.get(0));
	}
}

Measured memory_bytes: 23380
/*
 _  __    _   _   _ ____ _____ 
| |/ /   / \ | | | / ___|_   _|
| ' /   / _ \| | | \___ \ | |  
| . \  / ___ \ |_| |___) || |  
|_|\_\/_/   \_\___/|____/ |_|  
*/
#include <bits/stdc++.h>
#include <fstream>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb push_back
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
int main()
{
    CIN;
    int n,k;
    cin >> n >> k;
    vl v(n),v1(n);
    rep(i,0,n){
        cin >> v[i] >> v1[i];
    }
    ll dp[n+1][k+1];
    rep(i,0,n+1){
        rep(j,0,k+1){
            dp[i][j] = -1;
        }
    }
    dp[0][0]=0;
    ll maxi = 0;
    rep(i,0,n){
        rep(j,0,k+1){
            if(dp[i][j]==-1)continue;
            dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
            if(j+v[i]<=k)
            dp[i+1][j+v[i]] = max(dp[i+1][j+v[i]],dp[i][j]+v1[i]);
        }
    }
    rep(i,0,k+1){
        maxi = max(maxi,dp[n][i]);
    }
    cout << maxi;
}


Measured memory_bytes: 79232
import Data.List
  ( findIndex, minimumBy )

main = do
  _ <- getLine
  [t,a] <- map read . words <$> getLine
  hs <- map read . words <$> getLine
  
  let ws = map (f t a) hs
  print . findIndex4Minimum $ ws

-- f :: Int -> Int -> Int -> Int
f :: Double -> Double -> Double -> Double
f t a h = abs( (t-h*0.006) - a )

findIndex4Minimum :: [Double] -> Int
findIndex4Minimum ws = snd . minimumBy c . zip ws $ [1..]
  where
    c x y = compare (fst x) (fst y)


Measured memory_bytes: 1276
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		int n = Integer.parseInt(line1);

		ArrayList<int[]> D = new ArrayList<int[]>();

		for (int i = 0; i < n; i++) {
			String line = sc.nextLine();
			int[] kari = Dice.Diceget(line);
			D.add(kari);
		}
		
		int breakcount = 0;
		String answer = "Yes";

		for (int i = 0; i < n - 1; i++) {
			for (int j = 0; j < n - i - 1; j++) {
				if (Dice.Dicejudge(D.get(i), D.get(j + i + 1))) {
					answer = "No";
					breakcount++;
					break;
				}
			}
			if (breakcount == 1) {
				break;
			}
		}
		
		System.out.println(answer);

	}

}

class Dice {
	public static int[] Diceget(String line) {
		int[] set = new int[7];
		String[] s = line.split(" ");
		for (int i = 1; i <= 6; i++) {
			set[i] = Integer.parseInt(s[i - 1]);
		}
		return set;
	}

	public static int[] DiceE(int[] d) {
		int[] dd = new int[7];
		dd[1] = d[4];
		dd[2] = d[2];
		dd[3] = d[1];
		dd[4] = d[6];
		dd[5] = d[5];
		dd[6] = d[3];
		return dd;
	}

	public static int[] DiceN(int[] d) {
		int[] dd = new int[7];
		dd[1] = d[2];
		dd[2] = d[6];
		dd[3] = d[3];
		dd[4] = d[4];
		dd[5] = d[1];
		dd[6] = d[5];
		return dd;
	}

	public static int[] DiceS(int[] d) {
		int[] dd = new int[7];
		dd[1] = d[5];
		dd[2] = d[1];
		dd[3] = d[3];
		dd[4] = d[4];
		dd[5] = d[6];
		dd[6] = d[2];
		return dd;
	}

	public static int[] DiceW(int[] d) {
		int[] dd = new int[7];
		dd[1] = d[3];
		dd[2] = d[2];
		dd[3] = d[6];
		dd[4] = d[1];
		dd[5] = d[5];
		dd[6] = d[4];
		return dd;
	}

	public static boolean Dicejudge(int[] d1, int[] d2) {

		boolean judge = false;

		int breakcount = 0;

		for (int j = 0; j < 4; j++) {

			for (int k = 0; k < 4; k++) {

				for (int l = 0; l < 4; l++) {

					for (int m = 0; m < 4; m++) {
						d2 = Dice.DiceW(d2);
						if (d1[1] == d2[1] && d1[2] == d2[2] && d1[3] == d2[3]
								&& d1[4] == d2[4] && d1[5] == d2[5] && d1[6] == d2[6]) {
							breakcount++;
							break;
						}

					}
					if (breakcount >= 1) {
						break;
					}
					d2 = Dice.DiceS(d2);
					if (d1[1] == d2[1] && d1[2] == d2[2] && d1[3] == d2[3]
							&& d1[4] == d2[4] && d1[5] == d2[5] && d1[6] == d2[6]) {
						breakcount++;
						break;

					}
				}

				if (breakcount >= 1) {
					break;
				}

				d2 = Dice.DiceE(d2);
				if (d1[1] == d2[1] && d1[2] == d2[2] && d1[3] == d2[3]
						&& d1[4] == d2[4] && d1[5] == d2[5] && d1[6] == d2[6]) {
					breakcount++;
					break;
				}

			}

			if (breakcount >= 1) {
				break;
			}

			d2 = Dice.DiceN(d2);
			if (d1[1] == d2[1] && d1[2] == d2[2] && d1[3] == d2[3]
					&& d1[4] == d2[4] && d1[5] == d2[5] && d1[6] == d2[6]) {
				breakcount++;
				break;
			}
		}

		if (breakcount == 1) {
			judge = true;
		}
		return judge;
	}
}

Measured memory_bytes: 59868
#if 1

#include <bits/stdc++.h>
using namespace std;
int n,k;
int a[105];
int ls[105],rs[105];
int b[105];

int main()
{
    scanf("%d %d", &n, &k);
    for(int i = 1;i <= n;i++)
    {
        scanf("%d",&a[i]);
        ls[i] = ls[i-1]+a[i];
    }
    for(int i = n;i >= 1;i--)
    {
        rs[i] = rs[i+1]+a[i];
    }
    int ans,rans = 0;
    int it = min(k,n);
    for(int i = 0;i <= it;i++)
    {
        for(int j = 0;j <= it-i;j++)
        {
            //if(i == 2&&j == 1) printf("??");
            int bp = 1;
            for(int l = 1;l <= n;l++) b[l] = 0;

            for(int l = 1;l <= i;l++)
            {
                b[bp++] = a[l];
            }
            for(int l = 1;l <= j;l++)
            {
                b[bp++] = a[n-l+1];
            }
            ans = ls[i]+rs[n-j+1];
            bp--;
            sort(b+1,b+bp+1);
            for(int l = 1;l <= k-i-j;l++)
            {
                if(b[l] >= 0) break;
                ans -= b[l];
            }
            rans = max(rans,ans);
        }
    }
    printf("%d",rans);
}


#endif // 1++

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int i = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int i = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int i = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).begin(),(v).end(),greater<>()
#define debug(x) cerr << #x << ':' << x << '\n'
#define Pi 3.1415926535
#define MOD 1000000007
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}
void yes(){cout << "Yes" << '\n';}
void no(){cout << "No" << '\n';}

int solve(){
    int n; cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; ++i){
        int a; cin >> a;
        if(i%2 == 1 && a%2 == 1) ++ans;
    }
    cout << ans << endl;

    return 0;
}

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


Measured memory_bytes: 3584
n = int(input())
data = list(map(int, input().split()))

for i in range(1,n):
	print(" ".join(map(str, data)))
	v = data[i]
	j = i-1
	while j >= 0 and data[j] > v:
		data[j+1] = data[j]
		j -= 1
	data[j+1] = v
print(" ".join(map(str, data)))


Measured memory_bytes: 5596
S = list(input())

d = []
d.append(int(S[0]+S[1]))
d.append(int(S[2]+S[3]))

res = []
if(1<= d[0] <= 12):
    res.append('MMYY')
    # MMYY
if(1<= d[1] <= 12):
    res.append('YYMM')
    # YYMM
if(res == []):
    print('NA')
elif(len(res) == 1 and res[0] == 'MMYY'):
    print('MMYY')
elif(len(res) == 1 and res[0] == 'YYMM'):
    print('YYMM')
else:
    print('AMBIGUOUS')

Measured memory_bytes: 3064
#!venv/bin/python
#from collections import defaultdict 
from itertools import combinations
from collections import defaultdict
from pprint import pprint
import math
import datetime
import sys
import fcntl
import time

#N = int(input())
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

smaller = [0] * N
rightSmaller = [0] * N

for i in range(N-1):
    for j in range(i+1,N):
        if A[i] > A[j]:
            rightSmaller[i] += 1

for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            smaller[i] += 1

ans = 0
for i in range(N):
    ans += smaller[i]*K*(K-1)//2 + rightSmaller[i]*K
    ans %= 10**9 + 7

print(ans)



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

int main(){
    ll A,B; cin>>A>>B;
    ll ans[3]={1,2,3};
    for (ll i = 0; i < 3; i++){
        if(ans[i]!=A&&ans[i]!=B){
            cout<<ans[i]<<endl;
            return 0;
        }
    }
    
    
}
    

Measured memory_bytes: 256
use std::cmp::*;
use std::collections::*;
use std::io::*;

use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn main() {
    let n: usize = read();
    let m: usize = read();
    let mut a: Vec<i64> = (0..n).map(|_| read()).collect();
    let mut bc: Vec<(i64, i64)> = Vec::new();
    for _i in 0..m {
        let b: i64 = read();
        let c: i64 = read();
        let t = (c, b);
        bc.push(t);
    }
    bc.sort();
    bc.reverse();
    let mut d: Vec<i64> = vec![0; n];
    let mut _id = 0;
    for _i in 0..bc.len() {
        if _id >= n {
            break;
        } else {
            for _j in 0..bc[_i].1 {
                if _id >= n {
                    break;
                }
                d[_id] = bc[_i].0;
                _id += 1;
            }
        }
    }
    a.sort();
    for _i in 0..n {
        if d[_i] < a[_i] {
            break;
        } else {
            a[_i] = d[_i];
        }
    }
    let mut ans = 0;
    for _i in a {
        ans += _i;
    }
    println!("{}", ans);
}


Measured memory_bytes: 5268
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
 
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 100005;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));

void solve()
{
    ll n;
    cin >> n;
    n %= 1000;
    n = 1000 - n;
    n %= 1000;
    cout<<n;
}

int main()
{
    FAST;
    ll t = 1;
  //  cin >> t;
    while(t--)
    {
      solve();
    }
}

Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){
	while(1){
        int n,i;
        cin>>n;
        if(n==0)break;
        for(i=0;n!=1;i++){
            if(n%2==0)n/=2;
            else if(n%2==1)n=n*3+1;
            //cout<<n<<endl;
        }
        cout<<i<<endl;


	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int main() {
    int z,x;
    cin>>z>>x;
     if(z+x==3){
        cout<<z+x<<"\n";
    }
    else if(z>x){
        cout<<z-x<<"\n";
    }
        else if(z>x){
        cout<<z+x<<"\n";
    }
    else if(z<x){
        cout<<x-z<<"\n";
    }
    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))

int main() {
    long long N, x; cin >> N >> x;
    vector<long long> a(N), A(N);
    rep(i, N) { cin >> a[i]; A[i] = a[i]; }

    if (a[0] > x) a[0] = x;
    for (int i = 1; i < N; ++i) {
        long long c = a[i] + a[i - 1];
        if (c > x) {
            long long t = c - x;
            a[i] -= t;
        }
    }

    long long ans = 0;
    rep(i, N) {
        ans += A[i] - a[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 1792
/******************************************
* AUTHOR : HRITIK AGGARWAL *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define F first
#define S second
ll po(ll a, ll x,ll m){ if(x==0){return 1;}ll ans=1;ll k=1;  while(k<=x) {if(x&k){ans=((ans*a)%m);} k<<=1; a*=a; a%=m; }return ans; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  /*#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("result.txt", "w", stdout);
  #endif*/
  double n,r;
  cin>>n>>r;
  r=2*r+1;
  double k = n/r;
  cout<<ceil(k)<<"\n"; 
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>


using namespace std;
int a[5020];
int n,k;
bool d[5020];
bool need(int idx){
    
    if(a[idx]>=k) return true;
    
    memset(d,false,sizeof(d));
    d[0]=true;
    for(int i=0;i<n;i++){
        
        if(i==idx) continue;
        
        for(int j = k-1;j>=0;j--){
            if(!d[j])continue;
            if(j+a[i]<=k) d[j+a[i]]=true;
        }
    }
    
    for(int i=k-a[idx];i<k;i++){
        if(d[i]) return true;
    }
    return false;
}

int main(){
    
    scanf("%d %d",&n,&k);
    
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    
    
    sort(a,a+n);
    
    int l = 0;
    int r = n-1;
    int ans = 100000;
    
    /*
    //출력
    for(int i=0;i<n;i++){
        printf("%d ",need(i));
    }printf("\n");
    */
    
    while(l<=r){
        
        int mid = (l+r)/2;
        
        if(need(mid)){ //필요하다
            r=mid-1;
           ans = min(ans,mid);
        }else{ //불필요하다
            l=mid+1;
            //ans = max(ans,mid);
        }
    }
    
    if(ans ==0) printf("0\n");
    else if(ans==100000) printf("%d\n",n);
    else printf("%d\n",ans);
    
    
    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 MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= 50000; i++) {
    if (floor(i * 1.08) == n) {
      cout << i;
      return 0;
    }
  }
  cout << ":(";
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
using namespace std;
string c2s(char c){
  if(c==' ') return "101";
  if(c=='\'') return "000000";
  if(c==',') return "000011";
  if(c=='-') return "10010001";
  if(c=='.') return "010001";
  if(c=='?') return "000001";
  if(c=='A') return "100101";
  if(c=='B') return "10011010";
  if(c=='C') return "0101";
  if(c=='D') return "0001";
  if(c=='E') return "110";
  if(c=='F') return "01001";
  if(c=='G') return "10011011";
  if(c=='H') return "010000";
  if(c=='I') return "0111";
  if(c=='J') return "10011000";
  if(c=='K') return "0110";
  if(c=='L') return "00100";
  if(c=='M') return "10011001";
  if(c=='N') return "10011110";
  if(c=='O') return "00101";
  if(c=='P') return "111";
  if(c=='Q') return "10011111";
  if(c=='R') return "1000";
  if(c=='S') return "00110";
  if(c=='T') return "00111";
  if(c=='U') return "10011100";
  if(c=='V') return "10011101";
  if(c=='W') return "000010";
  if(c=='X') return "10010010";
  if(c=='Y') return "10010011";
  if(c=='Z') return "10010000"; 
}
char s2c(string x){
  if(x=="00000") return 'A';
  if(x=="00001") return 'B';
  if(x=="00010") return 'C';
  if(x=="00011") return 'D';
  if(x=="00100") return 'E';
  if(x=="00101") return 'F';
  if(x=="00110") return 'G';
  if(x=="00111") return 'H';
  if(x=="01000") return 'I';
  if(x=="01001") return 'J';
  if(x=="01010") return 'K';
  if(x=="01011") return 'L';
  if(x=="01100") return 'M';
  if(x=="01101") return 'N';
  if(x=="01110") return 'O';
  if(x=="01111") return 'P';
  if(x=="10000") return 'Q';
  if(x=="10001") return 'R';
  if(x=="10010") return 'S';
  if(x=="10011") return 'T';
  if(x=="10100") return 'U';
  if(x=="10101") return 'V';
  if(x=="10110") return 'W';
  if(x=="10111") return 'X';
  if(x=="11000") return 'Y';
  if(x=="11001") return 'Z';
  if(x=="11010") return ' ';
  if(x=="11011") return '.';
  if(x=="11100") return ',';
  if(x=="11101") return '-';
  if(x=="11110") return '\'';
  if(x=="11111") return '?';
}
int main(){
  string s;
  while(getline(cin,s)){
    int i;
    string m;
    for(i=0;i<s.size();i++) m+=c2s(s[i]);
    if(m.size()%5!=0){
      m+="0000";
    }
    string o;
    for(i=0;i+5<=m.size();i+=5){
      o+=s2c(m.substr(i,5));
    }
    cout << o << endl;
  }
  return 0;
}

Measured memory_bytes: 1196
N, K = map(int, input().split())
l = [1] * N
A = list(map(int, input().split()))

for i in range(K):
  R = list(map(int, input().split()))
  if A[R[0]-1]==A[R[1]-1]:
    l[R[0]-1]=0
    l[R[1]-1]=0
  elif A[R[0]-1]>A[R[1]-1]:
    l[R[1]-1]=0
  else:
    l[R[0]-1]=0
  
print(sum(l))


Measured memory_bytes: 20832
N = int(input())
A = [int(x) for x in input().split()]

D = {}

for a in A:
    if not a in D:
        D[a] = 1
    else:
        D[a] = D[a] + 1

ret = 0
for k in D.keys():
    if D[k] > k:
        ret += D[k] - k
    elif D[k] < k:
        ret += D[k]

print(ret)


Measured memory_bytes: 17780
S=input()
l=len(S)
dp=[0 for i in range(13)] 
mod=10**9+7
 
if S[0]=='?':
  for i in range(10):
    dp[i]=1
else:
  dp[int(S[0])]=1
  
for i in range(1,l):
  count=[0 for i in range(13)]
  if S[i]=='?':
    for j in range(13):
      for k in range(10):
        count[(10*j+k)%13]+=dp[j]%mod
  else:
    for j in range(13):
      count[(10*j+int(S[i]))%13]+=dp[j]%mod
  dp=count
 
print(dp[5]%mod)

Measured memory_bytes: 74336
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
mod=10**9+7
A.sort(reverse=True)

n_max=2*10**5
F,FI=[0]*(n_max+1),[0]*(n_max+1)
F[0],FI[0]=1,1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod
  FI[i+1]=pow(F[i+1],mod-2,mod)
def comb(x,y):
  return (F[x]*FI[x-y]*FI[y])%mod

ans=0
for i in range(n-k+1):
  ans=(ans+(A[i]-A[n-i-1])*comb(n-i-1,k-1))%mod
print(ans)


Measured memory_bytes: 63344
solve a b x =
  if a `mod` x == 0
    then (b `div` x) - (a `div` x) + 1
    else (b `div` x) - (a `div` x)

main = do
  line <- getLine
  let xs = words line
      [a, b, x] = fmap (read :: String -> Int) xs in
    putStrLn $ show $ solve a b x


Measured memory_bytes: 508
#include<bits/stdc++.h>
#define pb push_back()
#define ll long long
#define pi pair<int,int>
using namespace std;

int main()
{
  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll p1= a*c;
  ll p2=b*d;
  ll p3=a*d;
  ll p4=b*c;
  ll ans = max({p1,p2,p3,p4});
  cout<<ans<<endl;
  return 0;
}


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

struct PotentializedUnionFind{
    vector<int> par,rank,diff_weight;

    //はじめに全てが根であるとしておく
    PotentializedUnionFind(int N):par(N),rank(N,1),diff_weight(N,0){iota(par.begin(),par.end(),0);}

    int root(int x){//根に当たるまで再帰で探す
        if(par[x] == x) return x;
        else{
          	root(par[x]);//これいる？
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = root(par[x]);//根の更新と値を返すのを同時に？
                                        //あんま必要なさそう
        }
    }

    bool unite(int x, int y,int w){//根が同じでなかったらつなげる
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if(x == y) return false; //同じ根なので変動なし(uniteの必要なし)
        if(rank[x] < rank[y]){
            diff_weight[x] -= w;
            par[x] = y;
        }
        else{
            //多分根を0としたときの差分
            //問題で(y - x)の値がwであるとしているのでyにwを足している
            diff_weight[y] += w;//各点ごとに値が存在して、そこに差分を足している
            par[y] = x; //ここで根を変更している
            //ここで結合したと同時に下の行でrank(sizeとも)をインクリメントしている
            if(rank[x] == rank[y]) ++rank[x];
            //少なくともsizeをはかりたいならこうではない。
            //rank[根]にrank[他]を足していく
        }
        return true;
    }

    bool same(int x,int y){//つながっているかどうか判定
        return root(x) == root(y);
    }

    int weight(int x){
        root(x);//xが根ではなかったとき値が更新される？
        return diff_weight[x];
    }

    int diff(int x,int y){
        return weight(y) - weight(x);
    }

    int size(int x){//たぶんこう
        return rank[root(x)];
    }
};

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

    int N,M,L,R,D;
    cin >> N >> M;
    PotentializedUnionFind PUF(N);
    for(int i = 0;i < M;++i){
        cin >> L >> R >> D;
        --L,--R;
        if(PUF.same(L,R)){
            int diff = PUF.diff(L,R);
            if(diff != D){
                cout << "No" << endl;
                return 0;
            }
        }
        else{
            PUF.unite(L,R,D);
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#define int long long
using namespace std;
int a,b;
int aa,bb;
int ans;
signed main()
{
	cin>>a>>b;
	bb=b%4;
	if(bb==1)
		bb=1;
	else if(bb==2)
		bb=4*(b/4+1)-1;
	else if(bb==3)
		bb=0;
	else 
		bb=4*(b/4);
	a--;
	aa=a%4;	
	if(aa==1)
		aa=1;
	else if(aa==2)
		aa=4*(a/4+1)-1;
	else if(aa==3)
		aa=0;
	else 
		aa=4*(a/4);
	ans=aa^bb;
	cout<<ans;
}

Measured memory_bytes: 256
#include<cstdio>
int main(){
    int n,h[20]={},ans=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&h[i]);
    for(int i=0;i<n;i++){
        bool flag=true;
        for(int j=0;j<i;j++){
            if(h[j]>h[i])flag=false;
        }
        if(flag)ans++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128