akhauriyash/Code-Regression huggingface dataset:
#[macro_use]
pub mod basic_stdin {
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    use std::io::stdin;
    use std::io::Read;

    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed parsing")
}

}

#[macro_export]
macro_rules! test_function {
    (func = $func:expr, $($input:expr => $output:expr),* $(,)*) => {
        $(
            assert_eq!($func(std::io::Cursor::new($input)) , $output);
        )*
    };
}

#[macro_export]
macro_rules! input_macro {
    (string = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    (reader = $s:expr, $($r:tt)*) => {
        let reader = std::io::BufReader::new($s);
        let mut bytes = std::io::Read::bytes(reader);
        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_export]
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_export]
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() {
    let stdin = std::io::stdin();
    let ret = solve(stdin.lock());

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

fn solve<T: std::io::Read>(reader: T) -> u32 {
    input_macro! {
        reader = reader,
        k: u32,
        s: u32,
    }

    let mut count = 0;

    for x in 0..(k + 1) {
        for y in 0..(k + 1) {
            if let Some(z) = s.checked_sub(x + y) {
                if z <= k {
                    count += 1;
                }
            }
        }
    }

    return count;
}

#[cfg(test)]
mod tests {

    #[test]
    fn test_solve_function() {
        atcorder::test_function! {
            func = super::solve,
            "2 2\n" => 6,
            "5 15\n" => 1,
        }
    }
}


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

typedef long long ll;
const int N = 262154, mod = 998244353;

int n, ALL;
int f[N], p[N];

inline int & reduce(int &x) {return x += x >> 31 & mod;}
inline void add(int &x, const int y) {x += y - mod, x += x >> 31 & mod;}
ll PowerMod(ll a, int n, ll c = 1) {for (; n; n >>= 1, a = a * a % mod) if (n & 1) c = c * a % mod; return c;}

void FWT(int *a) {
	int i, j, k, r, len = 1;
	for (i = 0; i < n; ++i, len <<= 1)
		for (j = 0; j <= ALL; j += len << 1)
			for (k = j; k < j + len; ++k)
				r = a[k + len], reduce(a[k + len] = a[k] - r), add(a[k], r);
}

int main() {
	int i; ll s = 0;
	scanf("%d", &n), ALL = ~(-1 << n);
	for (i = 0; i <= ALL; ++i) scanf("%d", p + i), s += p[i];
	s = PowerMod(s, mod - 2);
	for (i = 0; i <= ALL; ++i) p[i] = p[i] * s % mod;
	s = 0, FWT(p);
	for (i = 1; i <= ALL; ++i) s += f[i] = PowerMod(mod + 1 - p[i], mod - 2, mod - 1);
	reduce(*f = -s % mod), FWT(f);
	for (i = 0; i <= ALL; ++i) printf("%d\n", f[i]);
	return 0;
}

Measured memory_bytes: 4864
s3=s=input()[::-1]
l=["maerd","remaerd","esare","resare"]
s2=""
for i in range(len(s)):
 s2+=s[i]
 if s2 in l:
  s3=s3[len(s2):]
  s2=""
print("YES"if s2==""else "NO") 

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;


int main(){

    int K,S,ans=0;
    cin >> K>>S;

    for(int x=0;x<=K;x++){
        for(int y=0;y<=K;y++){
            int z = S-x-y;
            if(z>=0&&z<=K)ans++;
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
import numpy as np
a,b = map(int,input().split(' '))
if np.sign(a)==1 and np.sign(b) == 1:
    print('Positive')
elif np.sign(a) == -1 and np.sign(b) == 1:
    print('Zero')
elif np.sign(a) == -1 and np.sign(b) == -1:
    if (b - a + 1) % 2 == 0:
        print('Positive')
    else:
        print('Negative')

Measured memory_bytes: 21612
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

const double INF = 1e18;

int se(vector<double> &d, vector<bool> &chk){
  double mn = INF;
  int ans = -1;
  rep(i, d.size()){
    if(chk.at(i) == true) continue;
    if(mn > d.at(i)){
      mn = d.at(i);
      ans = i;
    }
  }
  return ans;
}

double fc(vector<vector<pair<int, double>>> &gr, int n){
  vector<double> d(n+2, INF);
  vector<bool> chk(n+2, false);
  chk.at(n) = true;
  d.at(n) = 0;
  int now = n;
  rep(i, n+2){
    for(auto p : gr.at(now)){
      if(chk.at(p.first) == true) continue;
      auto &cg = d.at(p.first);
      cg = min(cg, d.at(now)+p.second);
    }

    now = se(d, chk);
    // rep(i, n+2){
    //   cerr << d.at(i) << " ";
    // }
    // cerr << endl;
    if(now == -1) break;
    chk.at(now) = true;
  }
  return d.at(n+1);
}

int main(){
  int xs, ys, xt, yt;
  cin >> xs >> ys >> xt >> yt;
  int n;
  cin >> n;
  vector<tuple<int, int, int>> vt(n);
  rep(i, n){
    int x, y, r;
    cin >> x >> y >> r;
    vt.at(i) = make_tuple(x, y, r);
  }
  vt.push_back(make_tuple(xs, ys, 0));
  vt.push_back(make_tuple(xt, yt, 0));

  vector<vector<pair<int, double>>> gr(n+2, vector<pair<int, double>>());
  rep(i, n+2){
    int ix, iy, ir;
    tie(ix, iy, ir) = vt.at(i);
    rep(j, n+2){
      if(i == j) continue;
      int jx, jy, jr;
      tie(jx, jy, jr) = vt.at(j);
      double d = hypot(ix-jx, iy-jy);
      d = d - ir - jr;
      if(d < 0) d = 0;
      gr.at(i).push_back(make_pair(j, d));
    }
  }
  // rep(i, n+2){
  //   rep(j, n+1){
  //     if(i == j) continue;
  //     cerr << i << " " << j << " " << gr.at(i).at(j).first << " " << gr.at(i).at(j).second << endl;
  //   }
  // }
  double ans = fc(gr, n);
  printf("%.10f\n", ans);
  
  return 0;
}

Measured memory_bytes: 16384
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 100005;
const long long INF = (1LL<<60);

int n, a[N];
long long dp[N][2];

int main() {
	while (~scanf("%d", &n)) {
		long long ans = 0;
		memset(dp, 0, sizeof(dp));
		for (int i = 1; i <= n; i++) {
			scanf("%d", &a[i]);
		}
		dp[0][0] = 0;
		dp[0][1] = -INF;
		for (int i = 1; i <= n; i++) {
			dp[i][0] = dp[i][1] = -INF;
			dp[i][0] = max(dp[i][0], dp[i - 1][0] + a[i] / 2);
			if (a[i]) {
				dp[i][0] = max(dp[i][0], dp[i - 1][1] + (a[i] - 1) / 2 + 1);
				dp[i][1] = max(dp[i][1], dp[i - 1][0] + (a[i] - 1) / 2);
				if (a[i] >= 2) dp[i][1] = max(dp[i][1], dp[i - 1][1] + (a[i] - 2) / 2 + 1);
			}
		}
		printf("%lld\n", max(dp[n][0], dp[n][1]));
	}
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  int a[n];

  const int mxnum = 1000001;
  int num[mxnum];
  for (int i = 0; i < mxnum; i++) {
    num[i] = 0;
  }

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

  bool pw = true;
  for (int i = 2; i < mxnum; i++) {
    int multi_cnt = 0;
    for (int j = i; j < mxnum; j += i) {
      multi_cnt += num[j];
    }
    if (multi_cnt > 1) {
      // iの倍数が２つ以上ある
      pw = false;
      break;
    }
  }

  if (pw) {
    puts("pairwise coprime");
    return 0;
  }

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

  if (gcd_all == 1) {
    puts("setwise coprime");
    return 0;
  }

  puts("not coprime");
  return 0;
}

Measured memory_bytes: 11400
#!/usr/bin/env python3
def main():
    _ = int(input())
    X = [int(x) for x in input().split()]

    ans = 10 ** 6
    for i in range(1, 101):
        res = 0
        for x in X:
            res += (x - i) ** 2
        ans = min(ans, res)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9068
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;

    return 0;
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main(){
    gearup;
    ll n,T;cin>>n>>T;
    vl t(n);
    rep(i,n)cin>>t[i];
    ll res = 0;
    rep(i,n-1){
        res += min(T,t[i+1]-t[i]);
    }
    out(res + T);
}



Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
int main(void){
    int i,len,sum,num[100];
    char fig[100];
    
    while(scanf("%s",fig) != EOF){
        len=strlen(fig);
        
        for(i=0;i<len;i++){
            switch(fig[i]){
                case 'I' :num[i]=1;break;
                case 'V' :num[i]=5;break;
                case 'X' :num[i]=10;break;
                case 'L' :num[i]=50;break;
                case 'C' :num[i]=100;break;
                case 'D' :num[i]=500;break;
                case 'M' :num[i]=1000;break;
            }
        }
        for(i=0;i<len-1;i++){
            if(num[i]<num[i+1]){
                num[i+1]-=num[i];
                num[i]=0;
            }
        }
        sum=0;
        for(i=0;i<len;i++){
            sum+=num[i];
        }
        printf("%d\n",sum);
    }
    
    return 0;
}

Measured memory_bytes: 536
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void) {
	int a,b;
	scanf("%d %d",&a,&b);
	if (a < b) printf("a < b\n");
	else if (a > b) printf("a > b\n");
	else printf("a == b\n");
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
using namespace std;
int cnt[105];
int main()
{
	int n,mx=0;
	scanf("%d",&n);
	while (n--)
	{
		int a;
		scanf("%d",&a);
		mx=max(mx,a);
		cnt[a]++;
	}
	int h=(mx+1)/2;
	for (int i=1;i<h;i++)
	{
		if (cnt[i])
		{
			printf("Impossible");
			return 0;
		}
	}
	for (int i=h;i<mx;i++)
	{
		if (!cnt[i])
		{
			printf("Impossible");
			return 0;
		}
	}
	if ((mx%2 && cnt[h]>2) || (mx%2==0 && cnt[h]>1))
	printf("Impossible");
	else
	printf("Possible");
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import collections
input = sys.stdin.readline
def ii(): return int(input().rstrip())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def fi(): return float(input().rstrip())
def mfi(): return map(float, input().rstrip().split())
def lmfi(): return list(map(float, input().rstrip().split()))
def li(): return list(input().rstrip())
def exit(*arg): print(*arg); sys.exit()
# template


def main():
    n = ii()
    g = [[] for i in range(n)]
    for i in range(n - 1):
        a, b = mi()
        g[a - 1].append((b - 1, i))
        g[b - 1].append((a - 1, i))
    color = max(*map(len, g))
    print(color)
    q = collections.deque()
    ans = [-1 for i in range(n - 1)]
    idx = 0
    q.append((0, 0))
    while len(q):
        t, idx = q.popleft()
        for e in g[t]:
            if ans[e[1]] != -1:
                continue
            idx += 1
            ans[e[1]] = idx
            q.append((e[0], idx))
    print(*map(lambda x: x % color + 1, ans), sep="\n")
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 76576
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
void YN(bool f){ cout << (f ? "YES" : "NO");}
void yn(bool f){ cout << (f ? "yes" : "no");}
void YeNo(bool f) {cout << (f ? "Yes" : "No");}
bool check(vector<int>&v){
    for(size_t i = 0; i < v.size(); ++i){
        if(i > 0 and (v[i] - v[i-1]) > 1)
            return false;
        if(i < v[i])
            return false;
    }
    return true;
}
signed main(){
    int n;
    cin >> n;
    vector<int>v(n);
    for(auto & e : v) cin >> e;
    if(!check(v)) {
        cout << "-1" << endl; return 0;
    }
    int ans = 0;
    bool inc = true;
    for(size_t i = 1; i < v.size(); ++i){
        if(v[i] - v[i-1] == 1){
            inc = true; ++ans;
        } else {
            ans += v[i];
        }
    }
    cout << ans << endl;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define MOD 1000000007

typedef long long ll;

ll dp[55][55][2555];
void mod_add(ll &a, ll b){
	a += b;a %= MOD;
}

int main(){
	ll n, score;cin >> n >> score;
	dp[0][0][0] = 1;
	ll nj, x;
	REP(i, n){
		REP(j, i+1)REP(k, score + 1){
			nj = j;mod_add(dp[i + 1][nj][k + 2 * nj], dp[i][j][k]);
			nj = j + 1;mod_add(dp[i + 1][nj][k + 2 * nj], dp[i][j][k]);
			nj = j;x = 2 * j;mod_add(dp[i + 1][nj][k + 2 * nj], dp[i][j][k] * x);
			nj = j - 1;x = j * j;if(j)mod_add(dp[i + 1][nj][k + 2 * nj], dp[i][j][k] * x);
		}
	}
	cout << dp[n][0][score] << endl;
	return 0;
}


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

int main(){
    using namespace std;
    string S;
    cin >> S;
    unsigned long amaru{1}, amarazu{0};
    for(const auto& c : S){
        auto tmp{amaru};
        amaru = min(amarazu + c - 47, tmp + 57 - c);
        amarazu = min(amarazu + c - 48, tmp + 58 - c);
    }
    cout << min(amaru + 1, amarazu) << endl;
    return 0;
}

Measured memory_bytes: 1412
#include<bits/stdc++.h>
using namespace std;
int main(){
    // data loader
    string s;
    cin>>s;
    
    //main
    long long n=s.length();
    long long dp[100005][13]={0};
    dp[0][0]=1;
    for (int i=0;i<n;i++){
        int c;
        if (s[i]=='?'){
            c=-1;
        }else{
            c=s[i]-'0';
        }
        for (int j=0;j<10;j++){
            if (c==-1 || c==j){
                for (int k=0;k<13;k++){
                    dp[i+1][(k*10+j)%13]+=dp[i][k];
                }
            }
        }
        for (int j=0;j<13;j++){
            dp[i+1][j]%=1000000007;
        }
    }
    cout<<dp[n][5]<<endl;
}


Measured memory_bytes: 10624
/*ABIDSTIC*/
#include <bits/stdc++.h>
/*---------------------------------PB_DS---------------------------------*/
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// #define ordered_multiset tree<pair<int, int>, null_type,less<pair<int, int> >, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(k) = returns an iterator to the k-th largest element (counting from zero)
// order_of_key(k) = the number of items in a set that are strictly smaller than k.
/*-----------------------------------------------------------------------*/

#define fill(a,b)           memset(a, (b), sizeof(a))
#define debug(x)            cout<<#x<<" "<<x<<'\n';
#define sfc(a)              scanf("%c",&a)
#define pb(a)               push_back(a)
#define X                   first
#define Y                   second
#define sz(x)               x.size()
#define pii                 pair<int,int>
#define pli                 pair<long long int,int>
#define mp(a,b)             make_pair(a,b)
#define fr(i,x,n)           for(int i=x;i<n;i++)
#define rfr(i,x,n)          for(int i=x;i>n;i--)
#define Lcm(a, b)           ((a)*((b)/Gcd(a,b)))
#define endl                '\n'
template<typename T>T Abs(T a) {return a < 0 ? -a : a;}
template<typename T>T Max(T a, T b) {return a > b ? a : b;}
template<typename T>T Min(T a, T b) {return a < b ? a : b;}
template<typename T>T Gcd(T a, T b) {return (!b) ? a : Gcd(b, a % b);}
template<typename T>T Pow(T a, T b) {if (!b)return 1; T t = Pow(a, b / 2); return b % 2 ? a * t * t : t * t;}
template<typename T>inline void read(T &x) {
    T f = 1; char c; x = 0;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())if (c == '-')f = -1;
    for (; c >= '0' && c <= '9'; c = getchar())x = x * 10 + c - '0';
    x *= f;
}
using fl = float;
using db = double;
using ll = long long;
using ull = unsigned long long;
const int mx = 1000005;
const int inf = 99999999;
const int intlim = 2147483648;
const db PI = acos(-1); //3.14159265358979323846264338328
/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};           // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};          // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/
//#ifndef ONLINE_JUDGE
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
//#endif
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int n;
    cin>>n;
    ll sum=0;
    sum=n+(n*n)+(n*n*n);
    cout<<sum<<endl;
}



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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

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


int main(){
	
	ll n, x;cin >> n >> x;
	vector<ll> v(n);REP(i, n)cin >> v[i];
	ll ans = max(0LL, v[0] - x);
	v[0] = min(v[0], x);
	
	for(int i = 1;i < n;i++){
		ll tmp = max(0LL, v[i-1] + v[i] - x);
		ans += tmp;
		v[i] -= tmp;
	}
	
	cout << ans << endl;
		
	
	
	return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#define MAXN 200

int n;
int num[MAXN];
int sum=0;

void solve(){
	if(sum%10!=0){
		printf("%d\n",sum);
		return;
	}
	std::sort(num+1,num+n+1);
	int i,loc=0;
	for(i=1;i<=n;i++){
		if(num[i]%10!=0){
			loc=i;
			break;
		}
	}
	if(loc==0)
		num[loc]=sum;
	printf("%d\n",sum-num[loc]);
}

int main(){
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++){
		scanf("%d",&num[i]);
		sum+=num[i];
	}
	solve();
	return 0;
}


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

using namespace std;

int main(){
  string s;
  cin>>s;
  int a[26];
  memset(a,0,sizeof(a));
  for(int i = 0;i<s.size();i++){
    a[s[i]-'a']++;
  }
  for(int i = 0;i<26;i++){
    if(a[i] % 2 != 0){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
      


  return 0;
}


Measured memory_bytes: 256
N,M = map(int, input().split())
PY=[]
for i in range(M):
    _list=list(map(int, input().split()))
    _list.append(i)
    PY.append(_list)
    #PY.extend([list(map(int, input().split()))])
    ##PY = [list(map(int, input().split())) for _ in range(M)]
PY.sort(key=lambda x: (x[0], x[1]))
#print(PY)
cnt=0
for i in range(M):
    if i==0:
        cnt=1
        forward = (6-len(str(PY[i][0])))*'0'+str(PY[i][0])
        backward = (6-len(str(cnt)))*'0'+str(cnt)
        PY[i].append(forward+backward)
        #print(forward+backward)
    else:
        if PY[i][0]==PY[i-1][0]:
            cnt+=1
            forward = (6-len(str(PY[i][0])))*'0'+str(PY[i][0])
            backward = (6-len(str(cnt)))*'0'+str(cnt)
            PY[i].append(forward+backward)
            #print(forward+backward)
        else:
            cnt=1
            forward = (6-len(str(PY[i][0])))*'0'+str(PY[i][0])
            backward = (6-len(str(cnt)))*'0'+str(cnt)
            PY[i].append(forward+backward)
            #print(forward+backward)
#print(PY)
PY.sort(key=lambda x: x[2])
for i in range(M):
    print(PY[i][3])

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

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

int main() {
  int H, A;
  cin >> H >> A;
  if (H % A == 0)
    cout << H / A << endl;
  else
    cout << H / A + 1 << endl;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0; i < (end); i += 1)
#define all(x) (x).begin(),(x).end()
//#define len(array)  (sizeof(array)/sizeof((array)[0]))
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;
void _mod(ll &x){x = mod(x, MOD);}
//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;

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


//#define int ll

class AKenkenRace {
public:
        int Rock[202020];
void solve(std::istream& cin, std::ostream& cout) {
    int N,A,B,C,D;
    cin >> N >> A >> B >> C >> D;
    A--,B--,C--,D--;
    string s;
    cin >> s;
    _for(i,N)Rock[i] = (s[i] == '#');
    Rock[N] = 1;
    int m = max(C,D);
    rep(i,A,m)if(Rock[i+1] == Rock[i] && Rock[i] ==1){
        cout << "No" << endl;
        return;
    }
    if(C < D){cout << "Yes" << endl;return;}
    else{
        int mi = min(C,D);
        rep(i,B,mi+1)if(Rock[i+1] == Rock[i] && Rock[i] == Rock[i-1] && Rock[i] == 0){
                cout << "Yes" << endl;
                return;
            }
    }
    cout << "No" << endl;

}
};


#undef int
int main() {
	AKenkenRace solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

void main_()
{
    ll N, M;
    vector<ll> Ds, Ts;
    cin >> N;
    copy_n(istream_iterator<ll>(cin), N, back_inserter(Ds));
    cin >> M;
    copy_n(istream_iterator<ll>(cin), M, back_inserter(Ts));

    sort(begin(Ds), end(Ds));
    sort(begin(Ts), end(Ts));

    vector<ll> rs;
    rs.reserve(Ts.size());
    set_intersection(begin(Ds), end(Ds), begin(Ts), end(Ts), back_inserter(rs));

    cout << ((Ts == rs) ? "YES" : "NO") << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 5104
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <unordered_map>
#include <queue>
using namespace std;

int main () {
	int a, b;
	cin >> a >> b;
	if (b % a == 0)
		cout << b + a;
	else
		cout << b - a;
	

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    ll ans = 0;
    ll j = 1;
    rep(i,N) {
        if(a[i] == j) j++;
    }
    if(j==1) cout << -1 << endl;
    else cout << N - (j-1) << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.io.*;
import java.util.*;


public class Main {
	public static void main(String[] args) throws Exception {
		MScanner sc = new MScanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		if(sc.nextInt()+sc.nextInt()+sc.nextInt()>=22) {
			pw.println("bust");
		}
		else {
			pw.println("win");
		}
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;

		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int[] takearr(int n) throws IOException {
			int[] in = new int[n];
			for (int i = 0; i < n; i++)
				in[i] = nextInt();
			return in;
		}

		public long[] takearrl(int n) throws IOException {
			long[] in = new long[n];
			for (int i = 0; i < n; i++)
				in[i] = nextLong();
			return in;
		}

		public Integer[] takearrobj(int n) throws IOException {
			Integer[] in = new Integer[n];
			for (int i = 0; i < n; i++)
				in[i] = nextInt();
			return in;
		}

		public Long[] takearrlobj(int n) throws IOException {
			Long[] in = new Long[n];
			for (int i = 0; i < n; i++)
				in[i] = nextLong();
			return in;
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 24404
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N, M = read_ints()
    A = read_ints()
    total = sum(A)
    threshold = total/(4*M)
    if sum(1 for a in A if a >= threshold) >= M:
        return 'Yes'
    return 'No'


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
  int n,x,l[100],i,sum=0,b=0;
  scanf("%d %d",&n,&x);
  for(i=1;i<=n;i++)
    scanf("%d",&l[i]);
  for(i=1;i<=n;i++){
    sum=sum+l[i];
    if(sum<=x)
    b++;
    }
    printf("%d",b+1);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <tuple>
#include <queue>
#include <vector>
#include <cmath>
#include <random>
#include <math.h>
#include <random>



#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define rREP(i, n) for(int (i) = (n) - 1; (i) >= 0; --(i))
#define ALL(TheArray) TheArray.begin(), TheArray.end()

using lli = long long int;
using pii = std::pair<int, int>;

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

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



constexpr int ALPHA_SIZE = 'z' - 'a' + 1;
std::bitset<ALPHA_SIZE> A;

constexpr int MAX_SIZE = 26;
char str[MAX_SIZE+10];

int main(void){
    scanf("%s", str);
    int n = strlen(str);
    REP(i, n) A[str[i] - 'a'] = true;
    char s = 'X';
    REP(i, ALPHA_SIZE) if(not A[i]){
        s = 'a' + i; break;
    }
    if(s != 'X'){printf("%s", str); putchar(s); putchar('\n'); return 0;}

    int k;
    for(k = n - 1; k - 1 >= 0; --k){
        int i = str[k] - 'a', j = str[k-1] - 'a';
        A[i] = false;
        if(j <= i) break;
    }
    if(k == 0) {puts("-1"); return 0;}

    int Q = str[k-1];
    REP(i, ALPHA_SIZE){
        if('a' + i > Q and not A[i]){
            s = 'a' + i;
            break;
        }
    }
    REP(i, k-1) putchar(str[i]);
    putchar(s); putchar('\n');
    

    



    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main () {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int ta = (A - 1) / D;
  int ao = (C - 1) / B;
  cout << (ta >= ao ? "Yes" : "No") << endl;
}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define endl '\n'
#define debug(X) cout << #X << " = " << X << endl

using namespace std;

const int MN = 200010;

long long a[MN];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	#ifdef UTP
	freopen("input.txt", "r", stdin);
	#endif
	int n; cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 1; i < n; i++)
		a[i] += a[i - 1];
	long long ans = 1e18;
	for (int i = 1; i + 2 < n; i++) {
		int p1 = lower_bound(a, a + n, a[i] / 2) - a;
		int p2 = lower_bound(a, a + n, (a[n - 1] + a[i]) / 2) - a;
		if (p1 - 1 >= 0 && abs(a[i] - 2 * a[p1 - 1]) < abs(a[i] - 2 * a[p1])) p1--;
		if (p2 - 1 > i && abs((a[n - 1] - a[i]) - 2 * (a[p2 - 1] - a[i])) < abs((a[n - 1] - a[i]) - 2 * (a[p2] - a[i]))) p2--;
		long long l1 = a[p1], l2 = a[i] - a[p1];
        long long r1 = a[p2] - a[i], r2 = a[n - 1] - a[p2];
        long long mx = max(max(l1, l2), max(r1, r2));
        long long mn = min(min(l1, l2), min(r1, r2));
        // cout << l1 << " " << l2 << " " << r1 << " " << r2 << endl;
        ans = min(ans, mx - mn);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

ll my_pow(ll m, ll n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return my_pow(m*m, n/2); }
    return my_pow(m, n-1) * m;
}
//cout << fixed << setprecision(10);

int main() {
    ll N;
    ll res = INF;
    vector<ll> S(3);
    cin >> N;
    for(int i=0;i<3;i++) cin >> S[i];
    vector<ll> L(N);
    for(int i=0;i<N;i++) cin >> L[i];
    vector<ll> cat(N);
    for(int i=0;i<(my_pow(3,N));i++){
        ll tmp = i;
        set<ll> se;
        vector<vector<ll>> pat(3,vector<ll>());
        for(int j=0;j<N;j++){
            cat[j] = tmp%3;
            tmp/=3;
            se.insert(cat[j]);
            pat[cat[j]].push_back(L[j]);
        }
        if(se.size()!=3)continue;
        
        else{
            ll tmpas=0;
            for(int l=0;l<3;l++){
                ll as=INF;
                for(int k=1;k<(1<<pat[l].size());k++){
                    ll sum = 0;
                    ll csum = 0;
                    bool jg = false;
                    ll tp=k;
                    for(int m=0;m<pat[l].size();m++){
                        if(tp%2 == 1){
                            sum+=pat[l][m];
                            if(jg==true){
                                csum+=10;
                            }
                            jg = true;
                        }
                        tp/=2;
                    }
                    if(sum == 0)continue;
                    else{
                        csum+=llabs(sum-S[l]);
                    }
                    as = min(as,csum);
                }
                tmpas+=as;
            }
            //cout << tmpas << " " << res << endl;
            res = min(res,tmpas);
            se.clear();
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
#include<stack>
#include<algorithm>
using namespace std;
int str[105];
int main()
{
	int n,m;
	cin>>n>>m;
	int t=0;
	for(int i=1;i<=n;i++)
	{
		cin>>str[i];
		t+=str[i];
	} 
	float te=(1.0*t)/4;
	te=(1.0*te)/m;
	int count=0;
	for(int i=1;i<=n;i++)
	{
		if(str[i]>=te)
		count++;
	}
	if(count>=m) cout<<"Yes"<<endl;
	else cout<<"No"<<endl; 
}

Measured memory_bytes: 256
mark = []
number = []
spade = []
heart = []
club = []
diamond = []
n = 0

count = gets.to_i

for i in 0..count-1 do

	mar , num = gets.split(" ") 
	mark << mar
	number << num.to_i

end

mark.each do |str|

	case str
	
	when "S" then
		spade[number[n]] = 1 
	when "H" then
		heart[number[n]] = 1 
	when "C" then
		club[number[n]] = 1 
	when "D" then
		diamond[number[n]] = 1 
	end

	n += 1

end

for i in 1..13 do
	if spade[i] != 1 then
		puts "S #{i}"
	end
end

for i in 1..13 do
	if heart[i] != 1 then
		puts "H #{i}"
	end
end

for i in 1..13 do
	if club[i] != 1 then
		puts "C #{i}"
	end
end

for i in 1..13 do
	if diamond[i] != 1 then
		puts "D #{i}"
	end
end








 

Measured memory_bytes: 8684
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  int sum = 0;
  vector<int> T(N);
  REP(i, N){
    cin >> T[i];
    sum += T[i];
  }

  int M;
  cin >> M;

  int P, X;
  REP(i, M){
    cin >> P >> X;
    cout << sum-T[P-1]+X << "\n";
  }

  return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = LIST()
a = [abs(x) for x in A] #Aの絶対値

n = sum([A[i] != a[i] for i in range(N)]) #Aの中で負のものは何個あるか

if n%2:
	print(sum(a) - 2*min(a))
else:
	print(sum(a))


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

int main()
{
  char A;
  cin >> A ;
  
  if(A>='A'&&A<='Z'){
    cout << "A" << endl;
  }
  else{
    cout << "a" << endl;
  }
  
  
return 0;
}

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

struct seg_tree{
    int st[800005];
    void update(int n, int s, int e, int i, int v){
        if(s == e) st[n] = v;
        else{
            int mid = (s+e)/2;
            if(i <= mid) update(n+n, s, mid, i, v);
            else update(n+n+1, mid+1, e, i, v);
            st[n] = max(st[n+n], st[n+n+1]);
        }
    }
    int query(int n, int s, int e, int l, int r){
        if(s > r || l > e) return 0;
        if(l <= s && e <= r) return st[n];
        int mid = (s+e)/2;
        return max(query(n+n, s, mid, l, r), query(n+n+1, mid+1, e, l, r));
    }
}st[2];

int main(){
    int n, q;
    scanf("%d%d", &n, &q);
    long long ans = (n-2)*1ll*(n-2);
    st[0].update(1, 1, n, n, n);
    st[1].update(1, 1, n, n, n);
    for(int i=1;i<=q;i++){
        int t, x;
        scanf("%d%d", &t, &x);
        if(t == 1){
            int lo = 1, hi = n, result;
            while(lo <= hi){
                int mid = (lo+hi)/2;
                if(st[1].query(1, 1, n, 1, mid) >= x) result = mid, hi = mid-1;
                else lo = mid+1;
            }
            ans -= result-2;
            st[0].update(1, 1, n, x, result-1);
        }
        else{
            int lo = 1, hi = n, result;
            while(lo <= hi){
                int mid = (lo+hi)/2;
                if(st[0].query(1, 1, n, 1, mid) >= x) result = mid, hi = mid-1;
                else lo = mid+1;
            }
            ans -= result-2;
            st[1].update(1, 1, n, x, result-1);
        }
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 7848
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
     while(t--){
       long long int n;
       cin>>n;
       string ans;
       while(n!=0){
       	  int rem=n%26;
          char c;
       	  if(rem==0)
       	  {c='z';
			 n=n-26;
			 }
       	  else
       	  c=rem-1+'a';
       	  ans=c+ans;
       	  n=n/26;
	   }
	   cout<<ans<<"\n";
	}
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define MOD 1000000007
#define PI 3.14159265
#define endl '\n'

#define MAX 100001
ll psum[MAX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n , k;
    cin >> n >> k;
    ll v;
    vector <ll> vec;
    for (int i = 0; i < n; i++) {
        cin >> v;
        vec.pb(v);
    }
    sort(all(vec));
    for (int i = 1; i < n; i++) {
        psum[i + 1] = psum[i] + (vec[i] - vec[i - 1]);
    }
    ll ans = 1e18;
    for (int i = k; i <= n; i++) {
        ans = min(ans , psum[i] - psum[i - k + 1] + min(abs(vec[i - 1]) , abs(vec[i - k])));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1908
a,b,c,x,y=map(int,input().split())
if a+b>c*2:
    if x>y and (x-y)*2*c>(x-y)*a:
        print(2*c*y+(x-y)*a)
    elif x>y and (x-y)*2*c<=(x-y)*a:
        print(2*c*x)
    elif x<=y and (y-x)*2*c>(y-x)*b:
        print(2*c*x+(y-x)*b)
    else:
        print(2*c*y)
else:
    print(a*x+b*y)

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

typedef long  long ll;
#define FF first
#define SS second
#define INF 2000000000


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

    int n;
    string s;
    cin >> n >> s;

    int ans = 0;
    for(int i = 0; i < n; ++i){
        if(s[i] == 'A'  && s[i+1] == 'B' && s[i+2] == 'C'){
            ans++;
        }
    }
    cout << ans << "\n";

}


Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;


void main() {
    auto N = readln.chomp.to!int;
    auto AB = N.iota.map!(_ => readln.split.map!(to!long).array).array;
    if (AB.filter!(a => a[0] > a[1]).empty) {
        0.writeln;
    } else {
        writeln(AB.map!(a => a[1]).sum - AB.filter!(a => a[0] > a[1]).map!(a => a[1]).reduce!min);
    }
}


Measured memory_bytes: 3580
#include<iostream>
#include<string>

using namespace std;

int main(void) {
	int n, i;
	int y, m, d, res;
	int a[3] = { 0,395,200 }, b[2] = { 0,19 };

	cin >> n;

	for (i = 0; i < n; i++) {
		cin >> y >> m >> d;
		y; m; d;
		res = (999 - y) / 3 * 590 + a[y % 3];
		if (y % 3 == 0) {
			res += (10 - m) * 20;
		}
		else {
			res += (10 - m) / 2 * 39 + b[m % 2];
		}
		res += 20 - d + !((y % 3 != 0) && (m % 2 == 0));
		cout << res << endl;
	}

	return 0;
}

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



int main() {
	int S[110], T[110],TT[110], x, cun=0, s1, t1, A, tt, q;
	string s, t;

	cin >> s >> t;

	for (int i = 0; i < s.size(); i++) {
		S[i] = s[i] - 'a';
	}
	for (int i = 0; i < t.size(); i++) {
		T[i] = t[i] - 'a';
	}
	s1 = s.size();
	t1 = t.size(); 
	tt = t1;
	sort(S, S + s1);
	sort(T, T + t1);
	for (int i = 0; i <t.size()/2 ; i++) {
		A = T[i];
		T[i]=T[t1-1];
		T[t1-1] = A;
		t1--;
	}
	x = min(s1, tt);
	for (int i = 0; i < x; i++) {
		if (S[i] < T[i]) {
			cout << "Yes" << endl;
			return 0;
		}
		if (S[i] == T[i])cun++;
	}
	
	if (cun == x) {
		if (s.size() < t.size()) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 384
import sys
N,M=map(int,input().split())
d={}
for i in range(M):
    a,b=map(int,input().split())
    if a==1 and b==0 and N>1:
        print(-1)
        sys.exit()
    if not a in d:
        d[a]=b
    elif d[a]!=b:
        print(-1)
        sys.exit()
A=[0]*N
for i in d:
    A[i-1]=d[i]
A=[str(A[i]) for i in range(len(A))]
if A[0]=="0" and N!=1:
  A[0]="1"
print("".join(A))

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

#define INF (INT32_MAX/2)

int main()
{
	int H, W;
	cin >> H >> W;
	vector<string> s( H );
	for( int i = 0; i < H; i++ ) {
		cin >> s[i];
	}

	int dirh[2] = { 1, 0 };
	int dirw[2] = { 0, 1, };
	vector<vector<int>> dp( H, vector<int>( W, INF ) );
	int d = 0;
	if( s[0][0] == '#' ) d = 1;
	dp[0][0] = d;
	queue<pair<int, int>> que;
	que.push( make_pair( 0, 0 ) );
	while( !que.empty() ) {
		int y, x;
		tie( y, x ) = que.front();
		que.pop();
		for( int i = 0; i < 2; i++ ) {
			int ny = y + dirh[i];
			int nx = x + dirw[i];
			if( ny >= H || nx >= W ) continue;
			d = 0;
			if( s[y][x] != '#' && s[ny][nx] == '#' ) d = 1;
			if( dp[ny][nx] > dp[y][x] + d ) {
				dp[ny][nx] = dp[y][x] + d;
				que.push( make_pair( ny, nx ) );
			}
		}
	}
	int ans = dp[H - 1][W - 1];


	cout << ans << endl;
}


Measured memory_bytes: 256
/**
>>> In The Name Of GOD
**/
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

#define pb push_back
#define pp pop_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define bs binary_search
#define smin(x,y) (x) = min((x) ,(y))
#define smax(x,y) (x) = max((x) ,(y))
#define sz(x) (int)(x).size()
#define ssz(x) (int)(x).length()
#define all(x) (x).begin(),(x).end()

//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);

///ifstream fin("input.txt");
///ofstream fout("output.txt");


bool cmp_pair_F_2(pair <int,int> x, pair <int,int> y)
{
    return x.F>y.F;
}
bool cmp_pair_S_2(pair <int,int> x, pair <int,int> y)
{
    return x.S>y.S;
}
bool cmp_pair_S_1(pair <int,int> x, pair <int,int> y)
{
    return x.S<y.S;
}

bool cmp(int x, int y)
{
	return x>y;
}



int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //int i,j;
	int n,m;
	cin >> n >> m;
	int l=0,r=n+1;
	for (int i=0;i<m;i++)
    {
        int x,y;
        cin >> x >> y;
        smax(l,x);
        smin(r,y);
    }
    cout << max(r-l+1,0);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int k, s;
	scanf("%d %d", &k, &s);

	int i, j, t, count = 0;
	for(i = 0; i <= k; i++) {
		for(j = 0; j <= k; j++) {
			t = s - i - j;
			if(0 <= t && t <= k) {
				count++;
			}
		}
	}
	printf("%d", count);
	return 0;
}

Measured memory_bytes: 128
MOD = 10**9 + 7

N, K = map(int, input().split())

A = [0] * (K + 1)
for d in range(1, K + 1):
    A[d] = pow(K // d, N, MOD)

for d in range(K, 0, -1):
    for i in range(2, K // d + 1):
        A[d] -= A[d * i]

answer = sum(d * x for d, x in enumerate(A))
print(answer % MOD)

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

const ll mod = 1e9 + 7;
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    ll n;
    cin >> n;
    ll ans = modpow(10, n, mod) - modpow(9, n, mod) * 2 + modpow(8, n, mod);
    ans%=mod;
    cout << (ans+mod)%mod << endl;
    return 0;
}

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


int main(){
  int n, k ;
  cin>>n>>k;
  int x = k;
  int keta =1;
  while(n>=x){
    x*=k;
    keta++;
  }
  cout <<keta<<endl;

}


Measured memory_bytes: 256