akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int n, a, b;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> a >> b;
	cout << min(n * a, b) << "\n";
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;

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

int main(){
    int i;
    int output;
    cin >> i;
    output = 1000 - (i % 1000);
    if(output == 1000){
        output = 0;
    }
    cout << output << endl;

    return 0;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for(ll i = 0;i < n;i++)
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int cnt = 0;
  rep(i, n) {
    cnt += a[i]%2;
  }
  if (cnt&1) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
}


Measured memory_bytes: 640
hh,n = map(int,raw_input().split(' '))
spells = [map(int, raw_input().split(' ')) for _ in range(n)]
h = [+float('inf')] * (hh+1)
h[0] = 0
for health in range(1, hh+1):
	for u,v in spells: h[health] = min(h[health], h[max(0,health - u)] + v)

print h[hh]

Measured memory_bytes: 33512
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    let ss = get!(String; n);

    let mut ab = 0usize;
    let mut a = 0;
    let mut b = 0;
    let mut abo = 0;
    for s in ss {
        let s = s.chars().collect::<Vec<_>>();
        for i in 0..s.len()-1 {
            if s[i] == 'A' && s[i+1] == 'B' {
                ab += 1;
            }
        }
        if s[0] == 'B' {
            if s[s.len()-1] == 'A' {
                abo += 1;
            }else {
                b += 1;
            }
        } else if s[s.len()-1] == 'A' {
            a += 1;
        }
    }
    let res = ab + if abo <= a {
        if abo <= b {
            abo*2+min!(a-abo, b-abo)
        } else {
            b+abo
        }
    } else {
        if abo <= b {
            a+abo
        } else {
            if a == 0 && b == 0 {
                abo-1
            } else {
                abo+min!(a,b)
            }
        }
    };
    println!("{}", res);
}


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

typedef long long ll;
const ll MOD = 1000000007LL;
ll N,M,K;
ll F[300000];

ll extgcd(ll a, ll b, ll &x, ll &y){
  ll g = a;
  x = 1;
  y = 0;
  if(b != 0){
    g = extgcd(b, a%b, y, x);
    y -= (a / b) * x;
  }
  return g;
}

ll modinv(ll a, ll m){
  ll x,y;
  if(extgcd(a,m,x,y) == 1) return (x + m) % m;
  return -1; 
}

ll mult( ll a, ll b ){
  return a*b % MOD;
}

void add( ll &a, ll b){
  if( a < 0 ) a+=MOD;
  if( b < 0 ) b+=MOD;
  a += b;
  a %= MOD;
}

ll minu( ll a, ll b ){
  b %= MOD;
  a -= b;
  if( a < 0 ) a += MOD;
  return a;
}

ll comb( ll a, ll b ){
  return mult( mult( F[a] , modinv( F[a-b], MOD ) ), modinv( F[b], MOD ) );
}

void init(){
  F[0] = 1;  
  for(ll i=1;i<300000;i++)
    F[i] = mult(F[i-1], i);
}

int main(){
  init();
  cin >> N >> M >> K;
  ll res = 0;
  for(ll L=0;L<=K;L++){
    ll R = K-L;
    ll mt = comb( N+M+2*K, N+2*L );
    ll lk = 1;
    if( L ) lk = minu( comb( N + 2*L , L ), comb( N + 2*L , L-1 ) );
    ll rk = 1;
    if( R ) rk = minu( comb( M + 2*R , R ), comb ( M + 2*R, R-1 ) );
    add( res, mult( mt, mult( lk, rk ) ) );
  }
  cout << res << endl;
}

Measured memory_bytes: 3504
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    int a[100000];
    for(int i=0;i<N;i++)
        cin >> a[i];
    
    // 昇順ソート
    sort(a, a + N);
    int i, num = 1, ans = 0;
    for(i=1;i<N;i++){
        if(a[i-1] == a[i]){
            num++;
        }else if(num < a[i-1]){
            ans += num; // すべて取り除く
            num = 1;
        }else{
            ans += num - a[i-1];    // 差分だけ取り除く
            num = 1;
        }
    }
    // 最後の数字の処理
    if(num < a[i-1])
        ans += num;
    else
        ans += num - a[i-1];

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

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int N;
int A[205];

int main(void)
{
	cin >> N;
	for(int i = 0; i < N; i++) cin >> A[i];
	
	int ans = 100, cnt;
	for(int i = 0; i < N; i++){
		cnt = 0;
		for(; !(A[i] & 1); A[i] /= 2) cnt++;
		ans = min(ans, cnt);
	}
	
	cout << ans << endl;
	return 0;
}

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

int N;

int main()
{
    cin >> N;
    vector<long long> A(N);
    long long accum = 0;
    map<long long, long long> shukei;
    shukei[0]++;
    for (int i = 0; i<N; i++)
    {
        cin >> A[i];
        accum += A[i];
        shukei[accum]++;
    }

    long long ans = 0;
    for (auto i : shukei)
    {
        ans += (i.second) * (i.second - 1) / 2;
    }
    cout << ans << "\n";
    return 0;
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  int n, m;
  cin >> n >> m;

  // d[i][j]: i-jの最短距離
  // next[i][j]: i-jの最短経路中のiの次の点
  // indeces[i][j]: i-jを直接つなぐ辺のインデックス
  vector<vector<int>> d(n, vector<int>(n, -1)), next(n, vector<int>(n, -1)),
      indeces(n, vector<int>(n, -1));
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    d[a][b] = c;
    d[b][a] = c;
    next[a][b] = b;
    next[b][a] = a;
    indeces[a][b] = i;
    indeces[b][a] = i;
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (d[j][i] < 0 || d[i][k] < 0) {
          continue;
        }

        int new_dist = d[j][i] + d[i][k];
        if (d[j][k] < 0 || new_dist < d[j][k]) {
          d[j][k] = new_dist;
          next[j][k] = next[j][i];
        }
      }
    }
  }

  vector<bool> used(m, false);
  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j) {
      // i-jの最短経路を復元
      int cur = i;
      while (cur != j) {
        if (indeces[cur][next[cur][j]] != -1) {
          used[indeces[cur][next[cur][j]]] = true;
        }
        cur = next[cur][j];
      }
    }
  }

  cout << count(used.begin(), used.end(), false) << '\n';
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

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

const char newl = '\n';

const ll mod = 1000000007;
//const ll mod = 998244353;

const int MAX_N = 500010;
ll fact[MAX_N],fact_inv[MAX_N],inv[MAX_N];

ll pow_mod(ll a,ll b) {
    ll ret;
    if (b < 0) ret = pow_mod(a,mod+b-1);
    else if (b == 0) ret = 1;
    else if (b == 1) ret = a;
    else {
        ll c = pow_mod(a,b/2);
        if (b%2) ret = (c*c)%mod*a%mod;
        else ret = c*c%mod;
    }
    return ret;
}

void init(int x) {
    fact[0] = 1;fact[1] = 1;
    for (int i = 2;i <= x;++i) fact[i] = fact[i-1]*i%mod;
    fact_inv[x] = pow_mod(fact[x],-1);
    for (int i = x;i > 0;--i) fact_inv[i-1] = fact_inv[i]*i%mod;
    for (int i = 1;i <= x;++i) inv[i] = fact_inv[i]*fact[i-1]%mod;
}

ll combi(ll a, ll b) {
    return fact[a]*fact_inv[b]%mod*fact_inv[a-b]%mod;
}

ll permu(ll a, ll b) {
    return fact[a]*fact_inv[a-b]%mod;
}

int main() {
    int n,m;
    cin >> n >> m;
    init(m);
    ll ans = 0;
    for (int i = 0;i < n+1;++i) {
        (ans += (i&1 ? -1 :1)*combi(n,i)*permu(m,i)%mod*permu(m-i,n-i)%mod*permu(m-i,n-i)%mod) %= mod;
    }
    cout << (ans+mod)%mod << endl;
}

Measured memory_bytes: 15252
// dile a la jardinera que traigo flores

#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define sz(x) int(x.size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define IFR(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;


int main(){	
	fastio;
	map<char,char>M;
	M['A']='T';
	M['T']='A';
	M['C']='G';
	M['G']='C';
	string s;cin>>s;
	for(char c: s)cout<<M[c];
	cout<<endl;


	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll m1, d1;
  ll m2, d2;
  cin >> m1 >> d1;
  cin >> m2 >> d2;

  if (m1 == m2) {
    cout << 0 << endl;
  } else {
    cout << 1 << endl;
  }
  return 0;
}

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

int main() {
    char a;
    cin >> a;
    if(isupper(a)) cout << "A" << endl;
    else cout << "a" << endl;
}

Measured memory_bytes: 3592
#include <cstdio>
#include <cstring>
#include <algorithm>

using std::max;

const int maxV = (int)1E5 + 1;

int n;
int d[2][maxV];
int m[2][2];
int mv[2][2];

int main() {
  scanf("%d", &n);
  memset(d, 0, sizeof(d));
  for (int i = 1; i <= n; ++i) {
    int v;
    scanf("%d", &v);
    d[i%2][v]++;
  }
  
  m[0][0] = d[0][1];    mv[0][0] = 1;
  m[0][1] = -1;         mv[0][1] = 0;
  m[1][0] = d[1][1];    mv[1][0] = 1;
  m[1][1] = -1;         mv[1][1] = 0;
  
  for (int i = 0; i < 2; ++i) {
    for (int v = 2; v < maxV; ++v) {
      if (m[i][0] <= d[i][v]) {
        m[i][1] = m[i][0];
        mv[i][1] = mv[i][0];
        m[i][0] = d[i][v];
        mv[i][0] = v;
      }
      else if (m[i][1] < d[i][v]) {
        m[i][1] = d[i][v];
        mv[i][1] = v;
      }
    }
  }

  int result;
  int s;

  if (mv[0][0] != mv[1][0]) {
    s = m[0][0] + m[1][0];
  }
  else {
    s = max(m[0][1] + m[1][0], m[0][0] + m[1][1]);
  }

  result = n - s;
  printf("%d\n", result);
  return 0;
}



Measured memory_bytes: 896
// at_abc153d.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;cin >> n;
    ll temp = log2(n);
    //cout << temp << "\n";
    ll ans = 1;
    for(int i=0;i<temp+1;i++){
        ans *= 2;
    }
    cout << (ll) ans-1<< "\n";
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cstring>
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)

int N, A, B;
vector<int>h;

//k回で殲滅できるか。
//まず全体にB*kのダメージ。
//残ったモンスターに(A-B)の単体攻撃をk回すると考える。

bool check(ll k) {

	ll cnt = 0;
	for (int i = 0; i < N; i++) {
		ll ret = (ll)h[i] - (ll)B*k;

		if (ret > 0) {
			cnt += (ret + (A - B) - 1) / (A - B);
		}

	}

	if (k >= cnt)return true;
	else return false;
}

ll bs() {

	ll ng = -1;
	ll ok = 1e9 + 1;

	while (abs(ok - ng) > 1) {
		ll mid = (ok + ng) / 2;

		if (check(mid)) {
			ok = mid;
		}
		else {
			ng = mid;
		}
	}

	return ok;
}

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

	h.resize(N);

	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}



	cout << bs() << endl;

	return 0;
}

Measured memory_bytes: 640
import collections

N = int(input())
L = list(map(int,input().split()))

LL = []
dic = collections.Counter(L)
ans = 0
for k,v in dic.items():
    if v == 1:
        LL.append(k)
    else:
        ans += k*(v//2)
        if v%2 == 1:
            LL.append(k)

LL = sorted(LL)
for l in LL[::2]:
    ans += l

print(ans)


Measured memory_bytes: 3316
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

const int maxn = (int) 1e5 + 5;
int n;
int a[maxn];

int read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
  	scanf("%d", &a[i]);
  }
  return true;
}

int rec() {
	int sum = 0;
	for (int i = 0; i < n; i++) {
		sum ^= ((a[i] + 1) & 1);
	}
	if (sum & 1) {
		return true;
	}
	int pos = -1;
	for (int i = 0; i < n; i++) {
		if (a[i] & 1) {
			if (pos != -1) {
				return false;
			}
			pos = i;
		}
	}
	if (a[pos] == 1) {
		return false;
	}
	a[pos]--;
	int g = 0;
	for (int i = 0; i < n; i++) {
		g = gcd(g, a[i]);
	}
	for (int i = 0; i < n; i++) {
		a[i] /= g;
	}
	if (!rec()) {
		return true;
	}
	return false;
}

void solve() {
	int res = rec();
	if (res) {
		printf("First\n");
	} else {
		printf("Second\n");
	}
}

int main() {
  precalc();
#ifdef LOCAL
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    string a, b;
    cin >> a >> b;
    int n = a.size();
    vector<int> f1(26);
    for (int i = 0; i < n; ++i)
        f1[a[i] - 'a'] = b[i] - 'a';
    bool odp1 = true;
    for (int i = 0; i < n; ++i)
        if (f1[a[i] - 'a'] != b[i] - 'a')
            odp1 = false;
    vector<int> f2(26);
    for (int i = 0; i < n; ++i)
        f2[b[i] - 'a'] = a[i] - 'a';
    bool odp2 = true;
    for (int i = 0; i < n; ++i)
        if (f2[b[i] - 'a'] != a[i] - 'a')
            odp2 = false;
    if (odp1 && odp2)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 916
import fractions #math.gcdは非対応なので解答にはfractions.gcdを使う
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
lcm = 1
for i in range(n):
    a[i]//=2
    lcm = lcm*a[i]//fractions.gcd(lcm,a[i])
flag = False
loopf = True
while loopf:
    tmp = a[0]%2
    for i in range(1,n):
        if a[i]%2!=tmp:
            flag = True
            loopf = False
            break
    if tmp==1 and loopf:
        loopf = False
    if tmp==0:
        for i in range(n):
            a[i]//=2
        
if flag:
    print(0)
else:
    tmp = m//lcm
    print((tmp+1)//2)

Measured memory_bytes: 16324
N, D= (int(i) for i in input().split())  
X = [[int(i) for i in input().split()] for i in range(N)] 

distance = 0
dis_int = 0

for i in range(N):
	for l in range(i+1, N):
		distance=0
		for g in range(D):
			distance += (X[i][g]-X[l][g])**2
		distance = distance**0.5
		if distance%1==0:
			dis_int+=1

print(dis_int)

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

using namespace std;


template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<1000000007>;


mint dp[105][100005];

void solve() {
    int N, K; cin >> N >> K;
    vector<int> a(N+1);
    for (int i = 1; i <= N; i++) cin >> a[i];

    dp[0][0] = 1;

    for (int i = 1; i <= N; i++) {
        dp[i][0] = 1;
        for (int j = 1; j <= K; j++) {
            dp[i][j] += dp[i-1][j] + dp[i][j-1];
            if (j-a[i]-1 >= 0) dp[i][j] -= dp[i-1][j-a[i]-1];
        }
    }

    cout << dp[N][K] << endl;
}


int main() {
    solve();
    return 0;
}

Measured memory_bytes: 81700
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def mapline(t = int):
    return map(t, sysread().split())
def mapread(t = int):
    return map(t, read().split())

def dfs(c, to, cols, max_counts, pre_col = 0):
    colors = set()
    colors.add(pre_col)
    num = 1
    for idx, n in to[c]:
        if cols[idx]:continue
        for i in range(num, max_counts+1):
            if not i in colors:
                num = i
                cols[idx] = i
                colors.add(i)
                dfs(n, to, cols, max_counts, i)
                break


def run():
    N = int(sysread())
    to = [[] for _ in range(N+1)]
    cols = [0] * (N-1)
    counts = [0 for i in range(N+1)]
    for i in range(N-1):
        a,b = mapline()
        to[a].append((i, b))
        to[b].append((i, a))
        counts[a] += 1
        counts[b] += 1

    max_counts = max(counts)
    print(max_counts)
    dfs(1, to, cols, max_counts)

    for c in cols:
        print(c)

    #print(a ^ b)
if __name__ == "__main__":
    run()


Measured memory_bytes: 112816
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<bitset>
#include<cstdlib>
#include<set>
#include<unordered_map>
#define l(x) (x<<1)
#define r(x) ((x<<1)|1)
#define low(x) (x&(-x))
#define IL inline
#define reg register
#define LL long long
#define N 500010
#define MOD 998244353
#define MO 1000000007
#define INF 0x3f3f3f3f
using namespace std;

int T,n,m,i,j,k,x,y,z,Ans,sum,cnt;
int a[N],b[N];
char c[N],d[N];

struct Data{
	int x,y;
};

IL int Abs(int x){return (x<0)?-x:x;}
IL void Swap(int &a,int &b){a^=b^=a^=b;}
IL int Min(int a,int b){return (a<b)?a:b;}
IL int Max(int a,int b){return (a>b)?a:b;}
IL bool cmp(const Data a,const Data b){return a.x<b.x;}

IL LL Mi(LL x,LL y){
	LL p=x,t=1,Res=1;
	for (;t<=y;(t&y)?Res=(Res*p)%MOD:0,p=(p*p)%MOD,t<<=1);
	return Res;
}

IL int read(){
	int p=0,f=1;	char	c=getchar();
	while (c<48||c>57)	{if (c=='-')	f=-1;	c=getchar();}
	while (c>=48&&c<=57)	p=(p<<1)+(p<<3)+c-48,c=getchar();
	return p*f;
}

int Check(int l){
	reg int i=0,s=0;
	for (i=l;i<=l+y-1;i++){
		if (c[i]!=d[i-l])	s++;
	}
	return s;
}

int main(){
	#ifdef __Marvolo
	freopen("zht.in","r",stdin);
	freopen("zht.out","w",stdout);
	#endif
	scanf("%s",&c);
	scanf("%s",&d);
	x=strlen(c);	y=strlen(d);
	Ans=INF;
	for (i=0;i<x-y+1;i++){
		Ans=Min(Ans,Check(i));
	}
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 3768
X,Y = map(int,input().split())

class Combination(): # nCr mod MOD など
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(10**6)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.fac, self.facinv = self.prepare(n_max)
        #self.modinv = self.make_modinv_list(n_max) ##なくても問題ないので、必要な時のみ使う
        
    def prepare(self,n): # 前処理(コンストラクタで自動的に実行)
        # 1! ~ n! の計算
        factorials = [1]  # 0!の分
        for m in range(1, n+1):
            factorials.append(factorials[m-1]*m%self.mod)
        # n!^-1 ~ 1!^-1 の計算
        invs = [1] * (n+1)
        invs[n] = pow(factorials[n], self.mod-2, self.mod)
        for m in range(n, 1, -1):
            invs[m-1] = invs[m]*m%self.mod
        return factorials, invs # list
    
    def make_modinv_list(self, n): # 0からnまでのmod逆元のリストを返す O(n)
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            # 整数aのMを法とした時の逆元a^-1は、(0<=a<=M-1)
            # a == qM+rであるとき(qは商,rは余り)、
            # a^-1 == -qr^-1 % M で与えられる。
            modinv[i] = (self.mod - self.mod//i)*modinv[self.mod%i]  % self.mod
        return modinv

    def perm_mod(self,n,r): # nPr % self.mod
        if n < r:
            return 0
        if (n < 0 or r < 0):
            return 0
        return (self.fac[n] * self.facinv[n-r]) % self.mod

    def combi_mod(self,n,r): # nCr % self.mod
        if n < r:
            return 0
        if (n < 0 or r < 0):
            return 0
        return (((self.fac[n] * self.facinv[r]) % self.mod) * self.facinv[n-r]) % self.mod


if (X+Y)%3==0:
    d = (X+Y)//3
    if d<=X<=X+Y-d and d<=Y<=X+Y-d:
        C = Combination(d+1)
        print(C.combi_mod(d,abs(d-X)))
    else:
        print(0)
else:
    print(0)

Measured memory_bytes: 91504
n,k = gets.split.map(&:to_i)
a = n.to_s.split('').map(&:to_i)
d = gets.split.map(&:to_i)

(n..99999).each do |f|
  q = f.to_s.split('').map(&:to_i)
  if !q.any? {|y| d.include?(y)}
    p f
    exit
  end
end


Measured memory_bytes: 2044
// Created by Sharat Sachin
#include <bits/stdc++.h>
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(ll i=0;i<(n);++i)
#define repA(i,a,n) for(ll i=a;i<=(n);++i)
#define repD(i,a,n) for(ll i=a;i>=(n);--i)
using namespace std;
using ll = long long;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n,w;
    cin>>n>>w;
    vector<ll> vw(n+1),vv(n+1);
    rep(i,n) cin>>vw[i+1]>>vv[i+1];
    ll mat[n+1][w+1];
    rep(i,n+1) rep(j,w+1) mat[i][j]=0;
    repA(i,1,n){
    	repA(j,1,w){
    		if(j-vw[i]>=0) mat[i][j] = max(mat[i-1][j-vw[i]]+vv[i],mat[i-1][j]);
    		else mat[i][j] = mat[i-1][j];
    	}
    }
    // rep(i,n+1) rep(j,w+1) cout<<mat[i][j]<<" \n"[j==w];
    cout<<mat[n][w];
    return 0;
}

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

int main() {
  int n;
  cin>>n;
  bool frag=false;
  while (n > 0) {
    if (n%10==9) frag=true;
    n/=10;
  }
  if (frag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

int main()
{
    std::string s;
    std::cin >> s;

    std::cout << s.length() / 2 - std::count(s.begin(), s.end(), 'p') << std::endl;
}


Measured memory_bytes: 512
import collections


def main():
    N, K = list(map(int, input().split(' ')))
    A  = list(map(int, input().split(' ')))
    
    where_li = []
    pre = 0
    for i in range(N):
        where_li.append(A[pre])
        pre = A[pre]-1
    
    len_w = len(where_li)
    a = where_li.index(A[pre])
    # print(a)
    mod_s = len_w-a # ループにかかる歩数
    # print(where_li)
    if K<=len_w:
        print(where_li[K-1])
    else:
        nokori = K - len_w
        if nokori % mod_s==0:
            d = mod_s
        else:
            d = nokori % mod_s
        print(where_li[d-1+a])

main()


Measured memory_bytes: 101420
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = LLONG_MAX;
/* テンプレートここまで */

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

  if(a[0] > x) a[0] = x;
  REP(i, N-1){
    ll tmp = a[i+1] + a[i] - x;
    if(tmp <= 0) continue;
    if(tmp <= a[i+1]){
      a[i+1] -= tmp;
    }else{
      a[i+1] = 0;
      a[i] -= tmp - a[i+1];
    }
  }

  REP(i, N){
    sum -= a[i];
  }
  cout << sum << endl;
}


Measured memory_bytes: 1024
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let hw = read_vec::<u64>();
    let mut v:Vec<Vec<char>> = Vec::new();
    for _ in 0..hw[0]{
        v.push(read::<String>().chars().collect());
    }
    for j in 0..hw[0]*2{
        for k in 0..hw[1]{
            let i = (j)/2;
            print!("{}",v[i as usize][k as usize]);
        }
        println!("");
    }
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
struct node
{
    long long a,b;
}s[maxn];
bool cmp(node x,node y)
{
    if(x.a!=y.a) return x.a<y.a;
    else return x.b>y.b;
}
int main()
{
    int n;
    long long k;
    scanf("%d%lld",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%lld%lld",&s[i].a,&s[i].b);
    sort(s,s+n,cmp);
    long long ans=0;
    for(int i=0;i<n;i++)
    {
        ans+=s[i].b;
        if(ans>=k)
        {
            printf("%d\n",s[i].a);
            return 0;
        }
    }
}


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

int main(){
  string N;
  cin >> N;
  if(N[0] >= N[1] && N[0] >= N[2])
    printf("%c%c%c\n", N[0], N[0], N[0]);
  else
    printf("%c%c%c\n", N[0]+1, N[0]+1, N[0]+1);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
        long X = sc.nextLong();

        long money = 100;
        long cou = 0;
        while(money<X){
        money = money/100 + money;
            cou++;
        }
                System.out.println(cou);
        }
}


Measured memory_bytes: 35768
#include<bits/stdc++.h>
using namespace std;
int main() {
int i,j,l,t,a[1000],b,k,p=0,x=100000000,n,m;
 cin>>n;

 for(i=0;i<n;i++){cin>>a[i];}
 sort(a,a+n);
 l=a[n-1];
 for(i=1;i<=l;i++){
        p=0;
    for(j=0;j<n;j++){
        p+=(a[j]-i)*(a[j]-i);
    }
    x=min(p,x);
 }
 cout<<x<<endl;





}


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


int main() {
	int n;
	cin >> n;
	vector<int> b(n);
	for (int i = 1;i <= n - 1;i++) {
		cin >> b[i];
	}
	vector<int> a(n+1);
	for (int i = 2;i <= n - 1;i++) {
		a[i] = min(b[i - 1],b[i]);
	}
	a[1] = b[1];
	a[n] = b[n - 1];
	int cnt = 0;
	for (int i = 1;i <= n;i++) {
		cnt += a[i];
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Stream;

public class Main {
    static  char[][] ret = new char[100][100];
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt() - 1;
        int b = scan.nextInt() - 1;
        for (int i = 0; i < 50; i++) {
            for (int j = 0; j < 100; j++) {
                ret[i][j] = '#';
            }
            for (int j = 0; j < 100; j++) {
                ret[i+50][j] = '.';
            }

        }

        int ar = a / 50;
        int al = a % 50;
        for (int i = 0; i < ar; i++) {
            for (int j = 0; j < 50; j++) {
                ret[2*i][2*j] = '.';
            }
        }
        for (int i = 0; i < al; i++) {
            ret[2*ar][2*i] = '.';
        }

        int br = b / 50;
        int bl = b % 50;
        for (int i = 0; i < br; i++) {
            for (int j = 0; j < 50; j++) {
                ret[2*i+51][2*j] = '#';
            }
        }
        for (int i = 0; i < bl; i++) {
            ret[2*br+51][2*i] = '#';
        }
        System.out.println("100 100");
        for (int i = 0; i < 100; i++) {
            System.out.println(new String(ret[i]));
        }
    }

}


Measured memory_bytes: 24532
INF = float('inf')

n = input()
h = map(int, raw_input().strip().split())
h.append(INF)

dp = [INF for i in xrange(n + 1)]
dp[n - 1] = 0

for i in xrange(n - 2, -1, -1):
    dp[i] = min(abs(h[i + 1] - h[i]) + dp[i + 1], abs(h[i + 2] - h[i]) + dp[i + 2])

print dp[0]

Measured memory_bytes: 42220
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(void)
{
	ll N,K,Q;
	cin>>N>>K>>Q;
	
	ll fre[N+1]={0};
	for(ll i=0;i<Q;i++)
	{
		ll X;
		cin>>X;
		fre[X]++;
	}
	for(ll i=1;i<=N;i++)
	{
		fre[i]=Q-fre[i];
	}
	for(ll i=1;i<=N;i++)
	{
	
	if(fre[i]<K)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
    }
}

Measured memory_bytes: 1408
#include<stdio.h>
#define N 100
void printStatus(int,int[]);
int main(void)
{
  int A[N];//array
  int i,j;//counter
  int tmp;//temporary variable to swap 2 elements
  int count=0;//count how many times sort is done
  int n;//the number of elements
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  for(i=0;i<n;i++)
    {
      for(j=n-1;j>i;j--)
        {
          if(A[j]<A[j-1])
            {
              tmp=A[j];
              A[j]=A[j-1];
              A[j-1]=tmp;
              count++;
            }
        }
    }
  printStatus(n,A);
  printf("%d\n",count);
  return 0;
}
void printStatus(int n,int A[])
{
  int i;
  for(i=0;i<n;i++)
    {
      if(i>0) printf(" ");
      printf("%d",A[i]);
    }
  printf("\n");
}


Measured memory_bytes: 2124
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int M = sc.nextInt();
			
			int[] as = new int[N];
			for(int i = 0; i < N; i++) {
				as[i] = -sc.nextInt();
			}
			Arrays.sort(as);
			int sum = 0;
			for(int i = 0; i < N; i++) {
				as[i] = -as[i];
				sum += as[i];
			}
			
			
			for(int i = 0; i < M; i++) {
				if(as[i] * 4 * M < sum) {
					System.out.println("No");
					return;
				}
			}
			
			System.out.println("Yes");
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 22868
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        sc.close();
        long ti = (n - m) * 100;
        ti += 1900 * m;
        ti *= (int)(Math.pow(2 , m));
        System.out.println(ti);
    }
}

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

int main()
{
    int N, D;
    cin >> N >> D;
    cout << ( (N%(2*D+1) != 0) ? N/(2*D+1) + 1 : N/(2*D + 1) )<< endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())
H = [int(a) for a in input().split()]

flag = 0
count = 0
max_count = 0
for h in H:
    if flag == 0:
        flag = 1
        temp = h
        continue
    if temp >= h:
        count+=1
    else:
        count = 0
    temp = h
    if max_count < count:
        max_count = count
print(max_count)


Measured memory_bytes: 14224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q;
    cin>>n>>q;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    rep(i,q){
      ll x;
      cin>>x;
      ll ans=0,l=0,r=0,sum=0;
      while(true){
        while(r<n && sum<=x){
          //cout<<sum<<endl;
          sum+=a[r];
          //cout<<' '<<sum<<endl;
          if(sum<=x){
            r++;
          }else{
            sum-=a[r];
            break;
          }
        }
        ans+=r-l;
        //cout<<l<<' '<<r<<' '<<sum<<' '<<ans<<endl;
        sum-=a[l++];
        //cout<<sum<<endl;
        if(l==n) break;
      }
      cout<<ans<<endl;
    }
}


Measured memory_bytes: 3628
let judge k = Array.sumBy (fun x -> 2 * min (abs x) (abs (x-k)))

//let input = [| 1, 10, [| 2 |]; 2, 9, [|3; 6|]; 5, 20, [| 11; 12; 9; 17; 12|] |]
//for (_, k, xs) in input do judge k xs |> printfn "%d"
// expected 4; 12; 74

[<EntryPoint>]
let main argv =
    stdin.ReadLine() |> ignore
    let k = stdin.ReadLine() |> int
    let xs = stdin.ReadLine().Split() |> Array.map int
    judge k xs |> printfn "%d"

    0


Measured memory_bytes: 29772
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = || -> 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! { x: usize, y: usize }
    println!("{}", x+y/2);
}

Measured memory_bytes: 4352
open String
let f s=let r=ref[]and j=ref(length s)in for i=length s-1downto 0do if s.[i]=' 'then(r:=sub s(i+1)(!j-i-1)::!r;j:=i)done;sub s 0!j::!r
and g n k a=let rec($)l r=if r<l then l else if h(0,0,0,(l+r)/2)<n then((l+r)/2+1)$r else l$((l+r)/2-1)and h=function(i,j,x,p)->if i=n||j=k then i else if x+a.(i)<=p then h(i+1,j,x+a.(i),p)else h(i,j+1,0,p)in 0$1000000000;;match List.map int_of_string(f(read_line()))with[n;k]->Printf.printf"%d
"(g n k(Array.init n(fun _->read_int())))|_->()

Measured memory_bytes: 5284
#include<iostream>
#include<vector>
using namespace std;
int main(){
	float N;
	cin>>N;
	vector<int>A(N);
	for(int i=0;i<N;++i)cin>>A[i];
	float sum;
	for(int i=0;i<N;++i){
		sum += 1.0/A[i];
	}
	cout<<1/sum;
}

Measured memory_bytes: 256
import numpy as np

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

a = []
for i in range(N):
    a.append(list(map(int,input().split())))
a = sorted(a,key = lambda i:i[0])
sum = 0
b = 0
#print (a)
for i in range(N):
    sum += a[i][1]
    b = a[i][0]
    if sum >= K:
        break

print (b)

Measured memory_bytes: 39900
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
# define int ll
int32_t main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    static int p[1 << 20];
    int n;
    fi>>n;
    for (int i = 1;i <= n;++i)
    {
        fi>>p[i];
    }
    const int C = 20001;
    static int a[1 << 20];
    static int b[1 << 20];
    int cnt = p[1];
    int now = 1e9 / 2 - 1;
    for (int i = cnt;i;--i)
        a[i] = now,now -= C;
    now = 1e9 / 2 - 1;
    for (int i = cnt;i <= n;++i)
        a[i] = now,now += C;
    now = 1e9 / 2 - 1;
    for (int i = cnt;i <= n;++i)
        b[i] = now,now -= C;
    now = 1e9 / 2 - 1;
    for (int i = cnt;i;--i)
        b[i] = now,now += C;
    for (int i = 1;i <= n;++i)
        a[p[i]] += i;
    for (int i = 1;i <= n;++i)
        fo << a[i] << " \n"[i == n];
    for (int i = 1;i <= n;++i)
        fo << b[i] << " \n"[i == n];
    assert(a[1] > 0 && b[n] > 0);
    for (int i = 1;i < n;++i)
        assert(a[i] < a[i + 1]);
    for (int i = 1;i < n;++i)
        assert(b[i] > b[i + 1]);
    for (int i = 1;i < n;++i)
        assert(a[p[i]] + b[p[i]] < a[p[i + 1]] + b[p[i + 1]]);
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}

Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC136_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            int digits = (int)Math.Log10(N) + 1; //桁数
            int ans = 0;
            for (int i = 1; i <= digits; i++)
            {
                if (i != digits && i % 2 != 0)
                {
                    ans += (int)Math.Pow(10, i) - (int)Math.Pow(10, i - 1);
                }
                else if (i == digits)
                {
                    if (i % 2 != 0)
                    {
                        ans += N - (int)Math.Pow(10, i - 1) + 1;
                    }
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	var headTmp = nextLine()
	// fmt.Println(headTmp)
	// fmt.Println(headTmp[0])

	var head = strings.Split(headTmp, " ")
	// fmt.Println(head[0])
	// fmt.Println(head[1])
	if head[0] == head[1] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")

	}

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

vector<int> cities[100005];
bool visited[100005];

void dfs(int i){
    visited[i] = true;
    for (int x : cities[i]){
        if (not(visited[x])){
            dfs(x);
        }
    }
}

int main(){
    int n,m;
    cin>>n>>m;
    while (m--){
        int a,b;
        cin>>a>>b;
        cities[a].push_back(b);
        cities[b].push_back(a);
    }
    int ans = 0;
    for (int i=1;i<=n;i++){
        if (not(visited[i])){
            ans ++;
            dfs(i);
        }
    }
    cout<<ans-1;
}



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

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

    int h, w;
    cin >> h >> w;

    char A[h][w];
    REP(i, h) REP(j, w) cin >> A[i][j];

    REP(i, h + 2){
        REP(j, w + 2){
            if(i == 0 or j == 0 or i == h + 1 or j == w + 1){
                cout << "#";
            }else{
                cout << A[i - 1][j - 1];
            }
        }
        cout << endl; 
    }

    return 0;
}

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

int main()
{
    int W, a, b;
    cin >> W>>a>>b ;
    if((a+W)<b){
        cout << b - (a + W) << endl;
    }
    else if(a>(b+W)){
        cout << a - (b + W) << endl;
    }
    else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256