akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

using ll = long long;
int N,x;

int main(){
    cin >> N >> x;
    vector<ll> a(N,0);
    ll ans = 0;
    ll tmp;
    for(int d = 0;d < N ;d++) cin >> a[d]; 
  
    if(a[0] > x) {
        ans = a[0]-x;
        a[0] = x;
    }

    for(int i = 0; i < N-1;i++){
        if(a[i] + a[i+1] > x){//超えている分はa[i+1]+a[i]-x
            tmp = (a[i]+a[i+1]-x);
            ans += tmp;
            a[i+1] -= tmp;
        }
    }
    /*
    for(auto e : a){
        cout << e << " " ;
    }
    cout << endl;
*/
    cout << ans << endl;
    return 0;
}

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

int main(){
	int n;
	scanf("%d", &n);
	int ans = 1;
	while(true) {
		ans *= 2;
		if(ans > n) {
			ans /= 2;
			break;
		}
	}
	printf("%d\n", ans);
}


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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const ll NN = 1e10 + 7;
const int N = 2e5 + 7;
const int M = 6;
const int mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;
const int B = sqrt(N);

int n;
int p[N];
ll a[N];
int l[N];
int r[N];
set < pair < ll , ll > > ss;

int get( int x )
{
    return (p[x] == x ? x : p[x] = get(p[x]));
}

void solve1()
{
    cin >> n;
    for( int i = 1; i <= n; i++ ){
        cin >> a[i];
        p[i] = i;
        l[i] = r[i] = i;
        ss.insert({ a[i] , i });
    }
    ll ans = 0;
    for( int i = 1; i <= (n) / 2; i++ ){
        assert( !ss.empty() );
        auto x = *(--ss.end());
        ss.erase(--ss.end());
        ans += x.fi;
        int l1 = get( l[x.se] - 1 );
        int r1 = get( r[x.se] + 1 );
        if( l1 != 0 ){
            ss.erase({ a[l1] , l1 });
        }
        if( r1 != 0 ){
            ss.erase({ a[r1] , r1 });
        }
        int f = get( x.se );
        ll mz = a[l1] + a[r1] - x.fi;
        p[l1] = f;
        p[r1] = f;
        a[f] = mz;
        l[f] = min({ l[f] , l[l1] , l[r1] });
        r[f] = max({ r[f] , r[l1] , r[r1] });
        f = get( f );
        if( l[f] != 0 && r[f] != 0 ){
            ss.insert({ mz , f });
        }
    }
    cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 20020
#include "bits/stdc++.h"
using namespace std;

vector<vector<int>>coaster;
vector < vector<pair<int, int>>>difs;
int main() {
	int C, N; cin >> C >> N;
	{
		vector<vector<int>>field(N, vector<int>(N));
		for (int y = 0; y< N; ++y) {
			string st; cin >> st;
			for (int x = 0; x < N; ++x) {
				field[y][x]=st[x]-'0';
			}
		}
		coaster = field;
		difs.resize(C-1);
		for (int i = 0; i < C-1; ++i) {
			int D; cin >> D;
			while (D--) {
				int y, x; scanf("%d %d", &y, &x); y--; x--;
				difs[i].push_back(make_pair(y, x));
				
			}
		}
	}
	vector<vector<vector<int>>>vs(N / 2, 
		vector<vector<int>>(N / 2,vector<int>( 4)));
	int sum = 0;
	for (int y = 0; y < N; ++y) {
		for (int x = 0; x < N; ++x) {
			if (y >= N / 2 && x >= N / 2)vs[N - y - 1][N - x - 1][3] = coaster[y][x];
			if (y >= N / 2 && x < N / 2)vs[N - y - 1][x][2] = coaster[y][x];
			if (y < N / 2 && x >= N / 2)vs[y][N - x - 1][1] = coaster[y][x];
			if (y < N / 2 && x < N / 2)vs[y][x][0] = coaster[y][x];

		}
	}
	for (int y = 0; y < N / 2; ++y) {
		for (int x = 0; x < N / 2; ++x) {

			sum+= 1-(all_of(vs[y][x].begin(), vs[y][x].end(), [&](const int a) {return a == vs[y][x][0]; }));
		}
	}
	int ans = 0;
	if (!sum)ans++;
	for (int i = 0; i < C-1; ++i) {
		for (auto dif : difs[i]) {
			int y = dif.first;
			int x = dif.second;
			coaster[y][x] = !coaster[y][x];
			int ay = y >= N / 2 ? N - y - 1 : y;
			int ax = x >= N / 2 ? N - x - 1 : x;
			sum-= 1-(all_of(vs[ay][ax].begin(), vs[ay][ax].end(), [&](const int a) {return a == vs[ay][ax][0]; }));
			if (y >= N / 2 && x >= N / 2)vs[N - y - 1][N - x - 1][3] = coaster[y][x];
			if (y >= N / 2 && x < N / 2)vs[N - y - 1][x][2] = coaster[y][x];
			if (y < N / 2 && x >= N / 2)vs[y][N - x - 1][1] = coaster[y][x];
			if (y < N / 2 && x < N / 2)vs[y][x][0] = coaster[y][x];
			sum += 1-(all_of(vs[ay][ax].begin(), vs[ay][ax].end(), [&](const int a) {return a == vs[ay][ax][0]; }));

		}
		if (!sum)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 30824
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

vector<int> divisor(int n){
    vector<int> d;
    for(int i=1; i*i<=n; ++i){
        if(n%i==0){
            d.pb(i);
            if(i != n/i) d.pb(n/i);
        }
    }
    sort(all(d));
    return d;
}

int main(){
    int n;
    scanf(" %d", &n);
    vector<int> t(n);
    rep(i,n) scanf(" %d", &t[i]);

    int T = 0;
    rep(i,n) T = max(T, t[i]);

    vector<int> d = divisor(T);

    int ans = 0;
    rep(i,n) ans += (*lower_bound(all(d), t[i])) - t[i];
    printf("%d\n", ans);
    return 0;
}



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

int main(){
    int n,m;
    cin >> n >> m;
    vector<pii> q(m);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        q[i].first = b;
        q[i].second = a;
    }
    sort(q.begin(),q.end());
    int ans = 1;
    int t = q[0].first;
    rep(i,m){
        if(t <= q[i].second){
            ans++;
            t = q[i].first;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
constexpr auto oorret = 0;
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }

int main() {
	int n,k;
	string s;
	cin >> n >> k;
	cin >> s;
	s[k - 1] = (char)((int)s[k - 1] + 32);
	put(s);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
ai = list(map(int,input().split()))
aj = list(map(lambda x:int(x/400),ai))
rainbow = 0
for e in aj:
  if e >= 8:
    rainbow += 1
ak= set(aj)
ans = 0
for e in ak:
  if e < 8:
    ans += 1
print(max(1,ans) ,end='')
print(' ' ,end = '')
print(ans+ rainbow)

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

using namespace std;

#define int 		long long
#define endl 		"\n"
#define mod			1000000007
#define inf			1e9
#define IOS			ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)


int32_t main() {

	IOS;

	string s;
	cin >> s;

	int ans = 0;

	for (char c : s)
		if (c == 'R')
			ans = 1;

	for (int i = 1; i < 3; i++) {
		if (s[i - 1] == 'R' && s[i] == 'R')
			ans++;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 3636
fun main(args: Array<String>) {
    val (a, b, C) = readLine()!!.split(" ").map(String::toInt)
    val radC = Math.toRadians(C.toDouble())
    val sinC = Math.sin(radC)
    val cosC = Math.cos(radC)

    val S = a * b * sinC / 2
    val L = a + b + Math.sqrt(square(a) + square(b) - 2 * a * b * cosC)
    val h = b * sinC
    println(S)
    println(L)
    println(h)
}

fun square(n: Int): Double = Math.pow(n.toDouble(), 2.0)


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

typedef vector<int> veci;
typedef pair<int, int> pii;
typedef vector<pii> vecii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vecl;
typedef vector<pll> vecll;
#define EPS (1e-9)
#define MOD (1e9 + 7)
#define fi first
#define se second
#define endl '\n'

void solve() {
    int m1, m2;
    int d1, d2;
    cin >> m1 >> d1;
    cin >> m2 >> d2;

    cout << ((m1 == m2) ? 0 : 1) << endl;
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL_TEST
    (void)argc;
    const string strpath = string(argv[0]) + string("-test.in");
    freopen(strpath.c_str(), "r", stdin);
    int tcs;
    cin >> tcs;
    while (tcs-- > 0)
#endif
        solve();
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N;
vector<int> graph[202020]; int par[202020];
int xi[202020];
int ans[202020];

void dfs1(int p, int v, int rt = -1)
{
	xi[p] = v;
	par[p] = rt;
	for (auto q : graph[p]) {
		if (q == rt) continue;
		dfs1(q, max(p, v), p);
	}
}

void forget_sub(set<int> *st, int v, int th)
{
	st->erase(v);
	for (int w : graph[v]) if (w != par[v]) {
		if (st->count(w)) {
			forget_sub(st, w, th);
		}
	}
}

void forget(set<int> *st, int th)
{
	while (!st->empty()) {
		int v = *--(st->end());
		if (v >= th) forget_sub(st, v, th);
		else break;
	}
}

set<int> *dfs2(int p, int rt = -1)
{
	vector<set<int>*> cands;
	for (auto q : graph[p]) {
		if (q == rt) continue;

		set<int> *tmp = dfs2(q, p);
		forget(tmp, xi[p] + 1);
		cands.push_back(tmp);

		ans[q] -= tmp->size();
	}

	set<int> *seed = nullptr;
	for (set<int> *t : cands) {
		if (seed == nullptr || seed->size() < t->size()) seed = t;
	}
	if (seed == nullptr) seed = new set<int>();
	for (set<int> *t : cands) if (t != seed) {
		for (auto v : *t) seed->insert(v);
		delete t;
	}
	ans[p] += seed->size() + 1;
	//printf("%d(%d): %d\n", p + 1, xi[p], ans[p]);
	//for (auto a : *seed) printf("%d ", a); puts("");
	seed->insert(p);
	return seed;
}

void dfs3(int p, int rt = -1)
{
	for (int q : graph[p]) if (q != rt) {
		ans[q] += ans[p];
		dfs3(q, p);
	}
}

int main()
{
	scanf("%d", &N);
	for (int i = 1; i < N; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		--x; --y;
		graph[x].push_back(y);
		graph[y].push_back(x);
	}
	dfs1(0, -1);
	dfs2(0);
	dfs3(0);

	for (int i = 1; i < N; ++i) {
		printf("%d%c", ans[i] - 1, i == N - 1 ? '\n' : ' ');
	}
	
	return 0;
}


Measured memory_bytes: 49280
N = int(input())
A = list(map(int, input().split()))

ans = 0
s = 0

mod = 10**9 + 7

def add(a, b):
    return (a + b) % mod

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

for i in reversed(range(N-1)):
    s = add(s, A[i+1])
    ans = add(ans, mul(A[i], s)) 
    
print(ans)


Measured memory_bytes: 31664
#include<stdio.h>
#include<stdint.h>
 
//0からnまでのXOR
uint64_t XOR(uint64_t n){
	if(n==-1) return 0;
	else if(n%4==1){
		return 1;
	}
	else if(n%4==3){
		return 0;
	}
	else if(n%4==2){
		return 1^n;
	}
	else{
		return n;
	}
}
	
int main(void){
	uint64_t A,B;
	scanf("%llu %llu",&A,&B);
	
	printf("%llu",XOR(A-1)^XOR(B));
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
 
#define array_sort_asc(array,size) sort(array, array+size);
#define array_sort_desc(array,size) sort(array, array+size,greater<>());
 
int main() {
    // input
    int n, d;
    cin >> n >> d;
 
    // logic
    int watchar = n / ((d * 2) + 1);
    // 切り上げ
    if((n % ((d * 2) + 1)) != 0) ++watchar;

    cout << watchar << endl;
}

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

string s;

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> s;
	for (int i = 0; i < s.length(); i++)
		if((i & 1) && s[i] == 'R') {
			cout << "No";
			return 0;
		}
		else if(((i & 1) == 0) && s[i] == 'L') {
			cout << "No";
			return 0;
		}
	cout << "Yes";
	return 0;
}


Measured memory_bytes: 256
n = gets.to_i
x = gets.chomp
xs = x.to_i(2)
xc = x.count('1')
def mpow(n, p, mod)
  return 0 if mod.zero?
  r = 1
  while p > 0
    r = r * n % mod if p & 1 == 1
    n = n * n % mod
    p >>= 1
  end
  r
end
def popcount(u)
  return 0 if u.zero?
  a = u % u.to_s(2).count('1')
  1 + popcount(a)
end
xsp = mpow(xs, 1, xc + 1)
xsm = mpow(xs, 1, xc - 1)
n.times do |i|
  if x[i] == '0'
    y = xsp + mpow(2, n - i - 1, xc + 1)
    y = mpow(y, 1, xc + 1)
  elsif xc == 1
    puts '0'
    next
  else
    y = xsm - mpow(2, n - i - 1, xc - 1)
    y = mpow(y, 1, xc - 1)
  end
  puts popcount(y) + 1
end

Measured memory_bytes: 15392
#include <bits/stdc++.h>
  
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<lol, lol>;
typedef vector<int> vit;
 
/*
struct SegmentTree{
   
  vector<lol> SumV(1000005,0);
  vector<lol> MaxV(1000005,0);
  vector<lol> MinV(1000005,0);
  int N;
   
  void update(int i,int x){
    i += N - 1;
    minv[i] = x;
    maxv[i] = x;
    sumv[i] = x;
    while(i > 0){
      i = (i - 1)/2;
      maxv[i] = max(maxv[i*2+1],maxv[i*2+2]);
      minv[i] = min(minv[i*2+1],minv[i*2+2]);
      sumv[i] = sumv[i*2+1]+sumv[i*2+2];
    }
  }
   
  void add(int i,int x){
    i += N - 1;
    sumv[i] += x;
    maxv[i] += x;
    minv[i] += x;
    while(i > 0){
      i = (i - 1)/2;
      sumv[i] = sumv[i*2+1]+sumv[i*2+2];
      minv[i] = min(minv[i*2+1],minv[i*2+2]);
      maxv[i] = max(maxv[i*2+1],maxv[i*2+2]);
    }
  }
   
  int getmax(int a,int b,int k,int l,int r){
    if(r <= a || b <= l) return -INF;
    if(a <= l && r <= b) return maxv[k];
    else{
      int c1 = getmax(a,b,2*k+1,l,(l+r)/2);
      int c2 = getmax(a,b,2*k+2,(l+r)/2,r);
      return max(c1,c2);
    }
  }
   
  int getmin(int a,int b,int k,int l,int r){
    if(r <= a || b <= l) return INF;
    if(a <= l && r <= b) return minv[k];
    else{
      int c1 = getmin(a,b,2*k+1,l,(l+r)/2);
      int c2 = getmin(a,b,2*k+2,(l+r)/2,r);
      return min(c1,c2);
    }
  }
   
  int getsum(int a,int b,int k,int l,int r){
    if(r <= a || b <= l) return 0;
    if(a <= l && r <= b) return sumv[k];
    else{
      int c1 = getsum(a,b,2*k+1,l,(l+r)/2);
      int c2 = getsum(a,b,2*k+2,(l+r)/2,r);
      return c1+c2;
    }
  }
}
*/
 
//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}
//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

int n, m, ans = 0;
vit edge[10];
bool isvisited[10] = {false};

void nasu(int x, int sum){
  if(isvisited[x]){
    return;
  }
  if(sum + 1 == n){
    ans ++;
    // cout << x << " ";
    return;
  }
  isvisited[x] = true;
  rep(i, edge[x].size()){
    nasu(edge[x][i], sum + 1);
  }
  isvisited[x] = false;
  return;
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  int a, b;
  rep(i, m){
    cin >> a >> b;
    edge[a].pu(b);
    edge[b].pu(a);
  }
  nasu(1, 0);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3604
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)
 
R, C, K = rl()
I = [[0]*(C+2) for _ in range(R+2)]
for i in range(K):
	r, c, v = rl()
	I[r][c] = v
 
dp = [[0]*4 for _ in range(C+2)]
dp2 = [[0]*4 for _ in range(C+2)]
 
for i in range(R+1):
	for j in range(C+1):
		for m in range(4):
			ni, nj = i, j+1
			dp[nj][m] = max(dp[nj][m], dp[j][m])
			if m < 3:
				dp[nj][m+1] = max(dp[nj][m+1], dp[j][m]+I[ni][nj])
			ni, nj = i+1, j
			dp2[nj][0] = max(dp2[nj][0], dp[j][m])
			dp2[nj][1] = max(dp2[nj][1], dp[j][m]+I[ni][nj])
	dp = dp2
	dp2 = [[0]*4 for _ in range(C+2)]
ans = 0
for m in range(4):
	ans = max(ans, dp[C][m])
print(ans)


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

int main(){
  ll n,k;
  cin>>n>>k;
  ll a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n-k;i++){
    cout<<(a[i]<a[i+k] ? "Yes" : "No")<<endl;
  }
}


Measured memory_bytes: 5192
#include <iostream>
#include <algorithm>
using namespace std;
using ll=long long;
int main(void){
    // Your code here!
    int n;
    std::cin >> n;
    int a[100001];
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    sort(a,a+n);
    int r=0,l=0;
    for (int i = 0; i < n-1; i++) {
        if(a[i]==a[i+1]){
            l=r;
            r=a[i];
            i++;
        }
    }
    std::cout << (long long)r*l << std::endl;
}


Measured memory_bytes: 640
#include <map>
#include <set>
#include <cmath>
#include <ctime> 
#include <queue>
#include <stack>
#include <bitset> 
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>
#include <iostream>
#include <algorithm>

#define fi first
#define se second
#define pb push_back
#define MP std::make_pair
#define PII std::pair<int, int>
#define all(x) (x).begin(), (x).end()
#define CL(a, b) memset(a, b, sizeof a)
#define rep(i, l, r) for (int i = (l); i <= (r); ++ i)
#define per(i, r, l) for (int i = (r); i >= (l); -- i)
#define PE(x, a) for (int x = head[a]; x;x = edge[x].next)

typedef long long ll;

template <class T>
inline void rd(T &x) {
    char c = getchar(), f = 0; x = 0;
    while (!isdigit(c)) f = (c == '-'), c = getchar();
    while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
    x = f ? -x : x;
}

const int MAXN = 2e5 + 7;

int a[MAXN], n, k, b[MAXN];

int main() {
    rd(n), rd(k);
    rep(i, 1, n) rd(a[i]);
    while (k--) {
        bool flag = 1;
        rep(i, 1, n) {if (a[i] != n) flag = 0;b[i]=0;}
        if (flag) break;
        rep(i, 1, n) {
            int l = std::max(1, i - a[i]), r = std::min(n, i + a[i]);
            b[l]++, b[r + 1]--;
        }
        
        rep(i, 1, n) b[i] += b[i - 1], a[i] = b[i];
    }
    rep(i, 1, n) printf("%d ", a[i]); puts("");
    return 0;
}

Measured memory_bytes: 5336
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
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;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

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

	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	vi out(n);
	rep(i,n)out[n-1]+=in[i];
	rep(i,n/2)out[n-1]-=in[i*2]*2;
	for(int i=n-2;i>=0;i--){
		out[i]=2*(in[i]-out[i+1]/2);
	}


	show1d(out);
}


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

using namespace std;
typedef long long int ll;
typedef long long unsigned int ull;

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define REPD(i, n) for (int i = 0, i##_len = (n); i < i##_len; i--)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
const int MOD = 1000000007;

void Main()
{
    int a, b;
    std::cin >> a >> b;
    if(a * b % 2 == 1){
        cout << "Odd" << endl;
    }
    else{
        cout << "Even" << endl;
    }
}

int main()
{
    std::ios::sync_with_stdio(false); // printf/scanf を使わない
    std::cin.tie(0);
    std::cout << std::fixed << std::setprecision(15); // 浮動小数点数を小数点表記

    Main();

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int s,m,h,sec;
    	scanf("%d",&sec);
   	 h=(int) sec/3600;
   	 m=(int) (sec-h*3600)/60;
    	s=sec-h*3600-m*60;
   	 printf("%d:%d:%d\n",h,m,s);
   	 return 0;
}





Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define sset(s) cout<<#s<<":";each(i,s)cout <<" "<<i;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 35;

int h,w,s;
int u[MAX_N][MAX_N];
int cnt[MAX_N][MAX_N][MAX_N][MAX_N];
P res[MAX_N][MAX_N][MAX_N][MAX_N];  //??°???????????° ????????????

P dfs(int lx,int ly,int rx,int ry)
{
    if(res[lx][ly][rx][ry].first != 0){
        return res[lx][ly][rx][ry];
    }
    P cand1,cand2;
    P cand = P(1,(s-(cnt[0][0][h-1][w-1]-cnt[lx][ly][rx][ry])));
    for(int i=lx;i < rx;i++){
        if(cnt[0][0][h-1][w-1]-cnt[lx][ly][i][ry] <= s && cnt[0][0][h-1][w-1]-cnt[i+1][ly][rx][ry]<= s){
            P p1 = dfs(lx,ly,i,ry);
            P p2 = dfs(i+1,ly,rx,ry);
            int tmin = min(p1.se,p2.se);
            cand1 = P(p1.fi+p2.fi,tmin);
            cand = max(cand,cand1);
        }
    }
    for(int i=ly;i < ry;i++){
        if(cnt[0][0][h-1][w-1]-cnt[lx][ly][rx][i] <= s && cnt[0][0][h-1][w-1]-cnt[lx][i+1][rx][ry] <= s){
            P p1 = dfs(lx,ly,rx,i);
            P p2 = dfs(lx,i+1,rx,ry);
            int tmin = min(p1.se,p2.se);
            cand2 = P(p1.fi+p2.fi,tmin);
            cand = max(cand,cand2);
        }
    }
    res[lx][ly][rx][ry] = cand;
    return res[lx][ly][rx][ry];
}

int main()
{
    while(1){
        cin >> h >> w >> s;
        if(h == 0){
            break;
        }
        rep(i,h){
            rep(j,w){
                rep(k,h){
                    rep(l,w){
                        res[i][j][k][l] = P(0,0);
                    }
                }
            }
        }
        rep(i,h){
            rep(j,w){
                cin >> u[i+1][j+1];
            }
        }
        rep(i,h){
            u[i][0] = 0;
        }
        rep(j,w){
            u[0][j] = 0;
        }
        rep(i,h+1){
            rep(j,w){
                u[i][j+1] = u[i][j+1] + u[i][j];
            }
        }
        rep(i,h){
            rep(j,w+1){
                u[i+1][j] = u[i+1][j] + u[i][j];
            }
        }
        rep(i,h){
            rep(j,w){
                for(int k = i;k < h;k++){
                    for(int l = j;l < w;l++){
                        cnt[i][j][k][l] = u[k+1][l+1] - u[k+1][j] - u[i][l+1] + u[i][j];
                    }
                }
            }
        }
        P ans = dfs(0,0,h-1,w-1);
        cout << ans.fi << " " << ans.se << "\n";
    }
}

Measured memory_bytes: 19712
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  vector<int> in;
  rep(i,N){
    int a;
    cin >> a;
    in.push_back(a);
  }

  int sum = 0;
  int base = 0;
  rep(i,in.size()){
    sum += abs(base - in[i]);
    base = in[i];
  }
  sum += abs(base);

  rep(i,in.size()){
    int prev = (i==0)?0:in[i-1];
    int next = (i==in.size()-1)?0:in[i+1];

    cout << sum - abs(prev-in[i]) - abs(next-in[i]) + abs(next-prev) << endl;
  }

  
  return 0;
}



Measured memory_bytes: 1784
#include<iostream>    
#include<cstdio>  
#include<stdio.h>  
#include<cstring>    
#include<cstdio>    
#include<climits>    
#include<cmath>   
#include<vector> 
#include<stack>
#include <bitset>  
#include<algorithm>    
#include <queue>  
#include<map> 
#define inf 9999999; 
using namespace std;

int a[105],ll,rr;
//stack<int> qua;
char str[105];
int l,r;
int i,n;
int main()
{
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>str[i];
	}
	l=0;
	r=0;
	int k;
	memset(a,0,sizeof(a));
	ll=rr=1;
//	cout<<1111<<endl;
	for(i=1;i<=n;i++)
	{
		if(str[i]=='(')
		{
			a[++rr]=1;
		}
		if(str[i]==')')
		{
			if(a[rr]==1)
			{
					a[rr]=0;
					rr--;
			}
			else
				l++;
		}
	}
//	cout<<1111<<endl;
	r=rr-ll;
	for(i=1;i<=l;i++)
	{
		cout<<"(";
	}
	for(i=1;i<=n;i++)
	{
		cout<<str[i];
	}
	for(i=1;i<=r;i++)
	{
		cout<<")";
	}
	cout<<endl;
	//cout<<l<<" "<<r<<endl;
}

	


Measured memory_bytes: 256
n = int(input())
a = tuple(map(int,input().split()))
from collections import Counter
c = Counter(a)
ans  = 0
for i in c.values():
    ans += (i*(i-1))//2
for i in a:
    print(ans-c[i]*(c[i]-1)//2+(c[i]-1)*(c[i]-2)//2)


Measured memory_bytes: 25900
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
#define N 200010
#define lowbit(x) (x&-x)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int n,len,a[N],b[N],c[N],s[N],t[N];
inline void add(int x){for(;x<=n+n+1;x+=lowbit(x))t[x]++;}
inline int query(int x){int A=0;for(;x;x-=lowbit(x))A+=t[x];return A;}
inline int check(int k)
{	memset(t,0,sizeof(t)); ll sum=0;
	for(rint i=1;i<=n;i++) c[i]=(a[i]>=k?1:-1),s[i]=s[i-1]+c[i];
	add(n+1); for(rint i=1;i<=n;i++) sum+=query(n+s[i]+1),add(n+s[i]+1);
	return sum*2>=(ll)n*(n+1)/2;
}
int main()
{	cin>>n;
	for(rint i=1;i<=n;i++) scanf("%d",&a[i]),b[i]=a[i];
	sort(b+1,b+n+1); len=unique(b+1,b+n+1)-b-1;
	for(rint i=1;i<=n;i++) a[i]=lower_bound(b+1,b+len+1,a[i])-b;
	int l=1,r=len,ans=-1;
	while(l<=r)
	{	int mid=(l+r)>>1;
		if(check(mid)) ans=mid,l=mid+1;
		else r=mid-1;
	}
	cout<<b[ans];
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

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

    int N;
    cin >> N;
    vector<ll> c(N);
    rep(i, N)cin >> c[i];
    vector<ll> dp(N+1,INFLL);
    rep(i,N){
        int idx = lower_bound(all(dp), c[i]) - dp.begin();
        dp[idx] = c[i];
    }
    int ans = 0;
    rep(i,N+1){
        if(dp[i] == INFLL){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 4364
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
char in[10];
int query(int a){
	printf("%d\n",a);fflush(stdout);
	scanf("%s",in);
	if(in[0]=='V')return -1;
	if(in[0]=='M')return 0;
	return 1;
}
int col[110000];
int main(){
	int a;scanf("%d",&a);
	int L=query(0);
	if(L<0)return 0;
	int R=query(a/2);
	if(R<0)return 0;
	col[0]=col[a]=L;
	col[a/2]=R;
	int left,right;
	if(L==R){
		if(a/2%2){
			left=0;right=a/2;
		}else{
			left=a/2;right=a;
		}
	}else{
		if(a/2%2==0){
			left=0;right=a/2;
		}else{
			left=a/2;right=a;
		}
	}
	while(1){
		int M=(left+right)/2;
		int tmp=query(M);
		if(tmp<0)return 0;
		col[M]=tmp;
		if(M%2==left%2){
			if(col[left]==col[M]){
				left=M;
			}else{
				right=M;
			}
		}else{
			if(col[left]==col[M]){
				right=M;
			}else{
				left=M;
			}
		}
	}
}

Measured memory_bytes: 852
import itertools

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

N_list = [i for i in range(1,N+1)]
conbination = list(itertools.permutations(N_list, N))

a = conbination.index(tuple(P))
b = conbination.index(tuple(Q))

print(abs(a-b))

Measured memory_bytes: 8052
//codeforces
#include <algorithm>
#include <vector>
#include <string>
#include <ctype.h>
#include <set>
#include <map>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<time.h>
#include<string>
#include<stack>
#include<cmath>
#include<iostream>
#include<cstring>
#include<complex>
#include<bitset>
#include <climits>
#include<tr1/unordered_set>
#include<tr1/unordered_map>


#define FOR(i,j,k) for(int i=j;i<k;i++)
#define FORD(i,j,k) for(int i=j;i>=k;i--)
#define ll long long
//Make sure no overflow problems
//#define int long long
#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define VAR(i,n) __typeof(n) i = (n)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();i++)
#define FORDEACH(i,c) for( VAR(i,(c).rbegin()),i!=(c).rend();i++)
#define REP(i,n) FOR(i,0,n)
#define ld long double
const int INF = 1e9+7;
const long long INFLL = (ll)INF * (ll)INF;
const ld EPS = 10e-9;

using namespace std;

class TrieNode{
    public:
    bool isword;
    char c;
    map<char,TrieNode*> m;
    string word;
    public:
    TrieNode(){}
    TrieNode(char ch){
        c=ch;
        isword=false;
    }
};

void insert(TrieNode* root,string word){
    TrieNode* temp=root;
    for(char c:word){
        if(temp->m.find(c)==temp->m.end())
            temp->m[c]=new TrieNode(c);
        temp=temp->m[c];
    }
    temp->isword=true;
    temp->word=word;
}

#pragma GCC optimize ("Ofast")
static auto _ = [] { std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0); std::cerr.tie(0); return 0; } ();

int main() {
    string s,t;
  	cin>>s;
  	cin>>t;
    int n=s.size(),m=t.size();
    vector<vector<int>> dp(n+1,vector<int> (m+1));

    string ans="";

    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            if(i==0 || j==0)
                dp[i][j]=0;
            else if(s[i-1]==t[j-1]){
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else if(s[i-1]!=t[j-1])
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
  
  	
    int i=n,j=m;
    while(i>0 && j>0){
        if(s[i-1]==t[j-1]){
            i--,j--;
            ans+=s[i];
        }
        else if(dp[i][j-1]<dp[i-1][j]){
            i--;
        }
        else
            j--;
    }

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

    cout<<ans;
    return 0;
}


Measured memory_bytes: 38508
#include<iostream>
#include<algorithm>
using namespace std;
void Insertion_Sort(int *A,int n){
    int u,i,j;
    for(i=0;i<n;i++){
        j = i-1;
        u = A[i];
        while(j>=0 && u<A[j]){
            swap(A[j+1],A[j]);
                j--;
                u = A[j+1];
        }
        for(int k=0;k<n;k++){
            if(k>0){
                cout << ' ';
            }
            cout << A[k];
        }
        cout << endl;
    }
}
int main(void){
    int n,*A;
    cin >> n;
    A = new int[n];
    for(int i=0;i<n;i++){
        cin >> A[i];
    }
    Insertion_Sort(A,n);
    delete[] A;
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include <stdint.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define int long long
typedef vector<int> vi;
typedef pair<int, int> pii;
const double PI = acos(-1.0);
const int mod = 1e9 + 7;
int pows(int a , int b){int res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
const int N = 1e9+5;
void init() {
  ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
}

void solve(){
    int n , W ;
    cin >> n >> W ;
    vector<int> wt(n) , val(n);
    rep(i,0,n)  cin >> wt[i] >> val[i] ;
    int dp[n+1][W+1] ;
    for(int i = 0 ; i <= n ; i++){
        for(int j = 0 ; j <= W ; j++){
            if(i==0 || j==0)
                dp[i][j] = 0 ;
            else if(wt[i-1] <= j)
                dp[i][j] = max(val[i-1] + dp[i-1][j-wt[i-1]] , dp[i-1][j]) ;
            else
                dp[i][j] = dp[i-1][j] ;
        }
    }
    cout << dp[n][W] << endl ;
}
int32_t main()
{
    init();
    int t=1;
    //cin>>t;
    clock_t launch=clock();

    while(t--)
    {
        solve();
    }

    clog<<((long double)(clock()-launch)/CLOCKS_PER_SEC)<<"\n";
}


Measured memory_bytes: 79232
#include <iostream>
using namespace std;
#define max 100000
long long int w[1000000];
int n, k;
int c(long long p) {
    int i = 0;
    for (int j = 0; j < k; j++) {
        long long int s = 0;
        while (s + w[i] <= p) {
            s += w[i]; i++;
            if (i == n) return n;
        }
    }
    return i;
}
int main()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++) 
        cin >> w[i];
    long long le, ri ,mid;
    le = 0; ri = max * max;
    long long int ans = 0;
    while (ri - le > 1) {
        mid = (le + ri) / 2;
        int v = c(mid);
        if (v >= n)ri = mid;
        else le = mid;
    }
    ans = ri;
    cout << ans << endl;
}


Measured memory_bytes: 3864
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
using namespace std;
int N, M, root = 1;
bool Use[100005];
vector <int> G[100005];
deque <int> D;
void Read()
{
    cin >> N >> M;
    for(int i = 1; i <= M; i++)
    {
        int x, y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
}

void Solve()
{
    D.push_back(1);
    Use[1] = 1;
    bool ok = 1;
    while(ok == 1)
    {
        ok = 0;
        int node = D.back();
        for(int i = 0; i < G[node].size(); i++)
        {
            int neighb = G[node][i];
            if(Use[neighb] == 0)
            {
                ok = 1;
                D.push_back(neighb);
                Use[neighb] = 1;
                break;
            }
        }
        if(ok == 1)
            continue;
        node = D.front();
        for(int i = 0; i < G[node].size(); i++)
        {
            int neighb = G[node][i];
            if(Use[neighb] == 0)
            {
                ok = 1;
                D.push_front(neighb);
                Use[neighb] = 1;
                break;
            }
        }
    }
    cout << D.size() << "\n";
    for(auto it = D.begin(); it != D.end(); it = next(it))
        cout << *it << " ";
    cout << "\n";
}
int main()
{
    Read();
    Solve();
    return 0;
}


Measured memory_bytes: 6784
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func check(N int, a []int, f [][10]int, p [][11]int) int {
	ans := 0
	// out("-----")
	// out(a)
	for i := 0; i < N; i++ {
		// out(f[i])
		cnt := 0
		for j := 0; j < 10; j++ {
			if f[i][j] == 1 && a[j] == 1 {
				cnt++
			}
		}
		// out(cnt)
		ans += p[i][cnt]
	}
	// out(ans)
	return ans
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	N := getInt()
	f := make([][10]int, N)
	for i := 0; i < N; i++ {
		for j := 0; j < 10; j++ {
			f[i][j] = getInt()
		}
	}
	p := make([][11]int, N)
	for i := 0; i < N; i++ {
		for j := 0; j <= 10; j++ {
			p[i][j] = getInt()
		}
	}
	// out(N)
	// out(f)
	// out(p)
	b := 1 << 10
	ans := -1110000000
	for i := 1; i < b; i++ {
		a := make([]int, 10)
		n := i
		for j := 0; n > 0; j++ {
			a[j] = n % 2
			n /= 2
		}
		ans = max(ans, check(N, a, f, p))
	}
	out(ans)
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<deque>
#include<queue>
using namespace std;
deque<char> q;
int main(){
	int i;
	string s;
	cin>>s;
	int l=s.size();
	for(i=0;i<l;i++){
		if(s[i]=='1'||s[i]=='0')
		q.push_back(s[i]);
		else if(s[i]='B'){
		if(!q.empty())
		q.pop_back(); 
	}
	}
	while(!q.empty()){
    cout<<q.front();
    q.pop_front();
    }
  cout<<endl;
   return 0;
	
} 

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


using namespace std;

using ll   = long long;
using ii   = pair < int , int >;
using i3   = pair < int , ii >;
using li   = pair < ll , int >;
using lii  = pair <  ll,  ii >;
using vi   = vector < int >;
using vl   = vector < ll >;
using vli  = vector < li >;
using vii  = vector < ii >;
using vi3  = vector < i3 >;
using vlii = vector < lii >;

const int N = 2e5 + 5;
const ll INF = 1e17;
const double eps = 1e-12 , PI = acos(-1);

int n , m;

void solve(int cs){
    scanf("%d" , &n);

    if(n == 1){
            printf("%.9f\n" , 1.0);
            return;
    }

    if(n&1){
            printf("%.9f\n" , 1.0 * (n/2 + 1) / (n*1.0) );
    }
    else {
            printf("%.9f\n" , 0.5);
    }
}

main(){
    int t = 1;
    //scanf("%d" , &t);

    for(int cs = 1 ; t -- ; cs ++){
        solve(cs);
    }

    return 0;
}



Measured memory_bytes: 256
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)*}
    };

    ($next:expr, mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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!{
        n: usize
    }
    let d = 1000000007;
    let mut dp: Vec<Vec<usize>> = vec![vec![0; 64]; n + 1];
    for i in 0..64 {
        if !check4((i << 2) | 3) {
            dp[0][i] = 1;
        }
    }
    for i in 0..n {
        for j in 0..64 {
            for k in 0..4 {
                let t = (j << 2) | k;
                if !check4(t) {
                    dp[i + 1][t & 63] = (dp[i + 1][t & 63] + dp[i][j]) % d;
                }
            }
        }
    }
    println!("{}", dp[n][63]);
}

fn check4(s: usize) -> bool {
    let a = s >> 6;
    let b = (s >> 4) & 3;
    let c = (s >> 2) & 3;
    let d = s & 3;
    check3(a, b, c) || check3(b, c, d)
    || check3(b, a, c) || check3(a, c, d)
    || check3(a, c, b) || check3(c, b, d)
    || check3(a, b, d) || check3(b, d, c)
}

fn check3(a: usize, b: usize, c: usize) -> bool {
    a == 0 && b == 1 && c == 2
}


Measured memory_bytes: 4352
import sys

N, M = map(int, input().split())
ab = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
ab.sort(key = lambda x : x[1])

ans = 0
last = -1
for a, b in ab:
    if a < last:
        continue
    else:
        ans += 1
        last = b

print(ans)

Measured memory_bytes: 18188
mod = 10**9+7
n = int(input())
c = [int(x) for x in input().split()]
c = sorted(c)

ans = 0

pow2 = [1]
for i in range(n+1):
    tmp = (pow2[-1]*2)%mod
    pow2.append(tmp)

for i in range(n):
    ans += pow2[n]*pow2[i]*((n-1-i)*pow2[n-2-i] + pow2[n-1-i])*c[i]
    ans %= mod

print(ans)

Measured memory_bytes: 101836
//DFSテンプレート
fun main(args: Array<String>) {
    val N = nextLong()
    tailrec fun g1(n: Long, p: Long): Long {
        if (n == 0L) return 0
        return (n / p) + g1(n / p, p)
    }
    tailrec fun g2(n: Long, p: Long): Long {
        if (n % 2 == 1L) {
            return g1(n, p) - g2(n - 1, p)
        }
        var res = g1(n / 2, p)
        if (p == 2L) res += n / 2
        return res
    }
    val ans =  Math.min(g2(N,2), g2(N,5))
    println(ans)
}
fun next() = readLine()!!
fun nextLong() = next().toLong()

Measured memory_bytes: 31740
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const int MOD = 1e9 + 7;









int main(){
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	rep(i, 0, ty - sy) {
		cout << "U";
	}
	rep(i, 0, tx - sx) {
		cout << "R";
	}
	rep(i, 0, ty - sy) {
		cout << "D";
	}
	rep(i, 0, tx - sx) {
		cout << "L";
	}
	cout << "L";
	rep(i, 0, ty - sy + 1) {
		cout << "U";
	}
	rep(i, 0, tx - sx + 1) {
		cout << "R";
	}
	cout << "D";
	cout << "R";
	rep(i, 0, ty - sy + 1) {
		cout << "D";
	}
	rep(i, 0, tx - sx + 1) {
		cout << "L";
	}
	cout << "U" << endl;
	return 0;
}


Measured memory_bytes: 256
n=int(input())
import fractions
a_list=list(map(int,input().split()))
f_list=[a_list[0]]
r_list=[a_list[n-1]]
for i in range(n-1):
    f=fractions.gcd(f_list[i],a_list[i+1])
    r=fractions.gcd(r_list[i],a_list[n-i-2])
    f_list.append(f)
    r_list.append(r)
Max=max(r_list[n-2],f_list[n-2])
for i in range(n-2):
    number=fractions.gcd(f_list[i],r_list[n-3-i])
    if number>Max:
        Max=number
print(Max)
    

    
    
    




    
        


Measured memory_bytes: 95208
#include<iostream>
#include<stdio.h>
#include<vector>
#include<math.h>
#include<algorithm>
#include<string>
#define ll long long
#define vl vector<ll> 
#define vvl vector<vector<ll> >
#define vb vector<bool> 
#define vvb vector<vector<bool> >
#define INF 1145141919810
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b:i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
using namespace std;

int main(){
	ll a,b; cin>>a>>b;
	cout<<(a+b)%24<<endl;
	return 0;
}

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

int main() {
  int N,K;
  cin >> N >> K;
  int ans=1;
  for (int i=0;i<N;i++){
    if (ans*2>=ans+K)
      ans+=K;
    else
      ans*=2;
  }
  cout <<ans<<endl;
}


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

vector<int> edge[100005];
bool visit[100005];
void dfs(int v) {
	for (int next : edge[v]) {
		if (visit[next] == false) {
			visit[next] = true;
			dfs(next);
		}
	}
}
int main() {
	int n, m;
	cin >> n >> m;
	while (m--) {
		int a, b;
		cin >> a >> b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	int num = -1;
	for (int i = 1; i <= n; i++) {
		if (visit[i] == false) {
			visit[i] = true;
			dfs(i);
			num++;
		}
	}
	cout << num << endl;

}

Measured memory_bytes: 9644
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define ll long long int 
#define ff first
#define ss second
#define ii pair<int,int>
#define lp(x,y) for(ll i=x;i<y;i++)
#define pb push_back
const int N = 200 * 1000 + 11;
 #define prec        cout<<std::setprecision(9)<<std::fixed
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define pi          3.14159265358979323
 
// int n;
// const int N=1e6+5;
// vector<bool> prime(N);
// void sieve(){
//     for(int i=0;i<=N;i++)prime[i]=true;
//     prime[0]=prime[1]=false;
//     for(int i=2;i*i<=N;i++){
//         if(prime[i] and i*i<=N){
//             for(int j=i*i;j<=N;j+=i){
//                 prime[j]=false;
//             }
//         }
//     }
// }
// const int N=1e3+5;
// int a[N];
 
 
int main() 
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll a,b;
    cin>>a;
    while(a--) cout<<"ACL";
    
}

Measured memory_bytes: 3604
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):
    return map(type,input().split())

#%%code

def resolve():
    N,k=pin()
    original=(range(k,k+N))
    temp=0
    min=1000000
    for o in original:
        temp=o
        if min**2>temp**2:
            min=temp
    #print(tuple(original),len(original))
    print(sum(original)-min)
#%%submit!
resolve()

Measured memory_bytes: 3060