akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<LL>A(N);
  for (int i = 0; i < N; i ++) cin >> A[i];
  sort(A.begin(), A.end());
  vector<LL>sum(N + 1);
  sum[0] = A[0];
  for (int i = 1; i < N; i ++) sum[i] = sum[i - 1] + A[i];
  sum[N] = 1e16;
  int mi = 0;
  int ma = N - 1;
  while (mi != ma) {
    int mu = (ma + mi) / 2;
    LL now = A[mu];
    bool ok = true;
    while (now != sum[N - 1]) {
      int s = mu;
      int l = N;
      while (s != l) {
        int m = (s + l) / 2;
        if (A[m] > now * 2) l = m;
        else s = m + 1;
      }
      if (now == sum[l - 1]) {
        ok = false;
        break;
      }
      now = sum[l - 1];
    }
    if (ok) ma = mu;
    else mi = mu + 1;
  }
  cout << N - ma << endl;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

class BIT {
    int n;
    vector<ll> node;

public:
    BIT(int N) : n(N), node(N + 1) {}
    void add(int i, ll x) {
        for (++i; i <= n; i += i & -i) { node[i] += x; }
    }
    ll sum(int i) {
        ll s = 0;
        for (; i > 0; i -= i & -i) { s += node[i]; }
        return s;
    }
};
class RSQ {
    int n;
    BIT a, b;

public:
    RSQ(int N) : n(N), a(N), b(N) {}
    void add(int l, int r, ll x) {
        int t = r - l;
        a.add(l, -l * x);
        a.add(r, r * x);
        b.add(l, x);
        b.add(r, -x);
    }
    ll sum(int i) { return a.sum(i) + i * b.sum(i); }
};

class Main {
    int N, K;
    vector<int> A;
    void input() {
        cin >> N >> K;
        A.resize(N);
        REP(i, N) { cin >> A[i]; }
    }
    void output() {
        REP(_, K) {
            RSQ rsq(N);
            REP(i, N) { rsq.add(max(0, i - A[i]), min(N, i + A[i] + 1), 1); }
            REP(i, N) { A[i] = rsq.sum(i + 1) - rsq.sum(i); }
            if (*min_element(A.begin(), A.end()) == N) break;
        }
        REP(i, N) { cout << A[i] << " "; }
        cout << endl;
    }

public:
    Main() {
        input();
        output();
    }
};

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

    Main();

    return 0;
}


Measured memory_bytes: 7140
#include <bits/stdc++.h>
using namespace std;
#define null NULL
#define mp make_pair
#define pb(a) push_back(a)
#define sz(a) ((int)(a).size())
#define all(a) a.begin() , a.end()
#define fi first
#define se second
#define relaxMin(a , b) (a) = min((a),(b))
#define relaxMax(a , b) (a) = max((a),(b))
#define SQR(a) ((a)*(a))
#define PI 3.14159265358979323846
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

const int MAXN = 100010;
const string FIRST = "First";
const string SECOND = "Second";

void Say(const string& w){
  cout << w << '\n';
  exit(0);
}

int n;
vi fo[MAXN];
int deg[MAXN];

bool dead[MAXN];
set<int> cq, nq;

void Kill(int vr){
  if(dead[vr]) return;
  dead[vr] = true;
  for(int o : fo[vr]){
    if(dead[o]) continue;
    --deg[o];
    if(deg[o] <= 1) nq.insert(o);
  }
}

int main(){
  scanf("%d", &n);
  for(int i = 1;i < n;++i){
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    fo[a].pb(b), fo[b].pb(a);
  }

  for(int i = 0;i < n;++i)
    deg[i] = sz(fo[i]);

  for(int i = 0;i < n;++i)
    if(deg[i] <= 1) cq.insert(i);

  while(!cq.empty()){
    vi rem;
    for(int vr : cq)
      if(dead[vr]) rem.pb(vr);
    for(int vr : rem)
      cq.erase(vr);

    if(cq.empty()) break;

    nq.clear();

    set<int> conn;
    for(int vr : cq){
      int cnt = 0;
      for(int o : fo[vr])
        if(!dead[o]){
          ++cnt;
          if(conn.count(o)) Say(FIRST);
          conn.insert(o);
        }
      if(cnt == 0) Say(FIRST); // !
    }
    for(int vr : cq) conn.insert(vr);
    for(int vr : conn) Kill(vr);

    cq.swap(nq);
  }

  Say(SECOND);

  return 0;
}


Measured memory_bytes: 13056
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>

using namespace std;

#define mod 1000000007

class UF
{
private:
	vector<long long int> root;

public:
	UF(int n)
	{
		root = vector<long long int>(n + 1, -1);
	}

	int getroot(int x)
	{
		if(root[x] == -1) return x;
		return root[x] = getroot(root[x]);
	}

	void add(int x, int y)
	{
		// x = getroot(x);
		// y = getroot(y);
		// if(x == y) return;
		if(x > y) swap(x, y);
		root[y] = x;
		return;
	}
};

int main()
{
	int n, q;
	cin >> n >> q;
	long long int edge[400001];
	// edge[i] : 頂点iと頂点i + 1をつなぐ辺の重みのうち最小のもの
	for(int i = 0; i < 2 * n; i++){
		edge[i] = mod + 2 * n;
	}
	priority_queue<pair<long long int, pair<int, int> > > qu;
	for(int i = 0; i < q; i++){
		long long int a, b, c;
		cin >> a >> b >> c;
		qu.push(make_pair(-c, make_pair(a, b)));
		edge[a] = min(edge[a], c + 1);
		edge[b] = min(edge[b], c + 2);
	}
	for(int i = 1; i < 2 * n; i++){
		edge[i] = min(edge[i], edge[i - 1] + 2);
	}
	for(int i = 0; i < n; i++){
		qu.push(make_pair(-min(edge[i], edge[i + n]), make_pair(i, (i + 1) % n)));
	}
	UF uf(n);
	long long int ans = 0;
	while(!qu.empty()){
		long long int cost = -(qu.top()).first;
		int a = ((qu.top()).second).first;
		int b = ((qu.top()).second).second;
		qu.pop();
		// cout << a << " " << b << " " << cost << endl;
		int ra = uf.getroot(a);
		int rb = uf.getroot(b);
		if(ra == rb) continue;
		ans += cost;
		uf.add(ra, rb);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 13676
def selection_sort(a, n):

    swap_count = 0
    for i in range(0, n):
        min_j = i
        for j in range(i, n):
            if a[j] < a[min_j]:
                min_j = j
        a[i], a[min_j] = a[min_j], a[i]
        if i != min_j:
            swap_count += 1

    print(' '.join(map(str, a)))
    print(swap_count)


def main():
    n = int(input())
    a = list(map(int, input().split(' ')))
    selection_sort(a, n)


if __name__ == "__main__":
    main()



Measured memory_bytes: 5600
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  ll n;
  cin>>n;
  
  vector<ll> A(n+1);
  rep(i,n) cin>>A[i+1];
  
  vector<pair<ll,ll>> dp(n+1);
  dp[0]={1000,0};
  for(int i=1;i<n;i++){
    if(A[i]<A[i+1]){
      ll a=dp[i-1].first/A[i];
      dp[i]={dp[i-1].first-a*A[i],dp[i-1].second+a};
    }
    else if(A[i]>A[i+1]){
      ll b=dp[i-1].second*A[i];
      dp[i]={dp[i-1].first+b,0};
    }
    else dp[i]=dp[i-1];
  }
  ll ans=dp[n-1].first+dp[n-1].second*A[n];
  
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner cd = new Scanner(System.in);
		String[] fd = cd.nextLine().split("");

		int co=1;
		String h = "";
		for(int i=0;i<fd.length;++i) {
			if(co%2==1) System.out.print(fd[i]);;
			++co;
		}
		System.out.println();
	}

}


Measured memory_bytes: 35688
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

template<typename T>
vector<T> gen_v(size_t a) { return vector<T>(a); }
template<typename T, typename ...Ts>
auto gen_v(size_t a, Ts... ts) { return vector<decltype(gen_v<T>(ts...))>(a, gen_v<T>(ts...)); }
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s, t; cin >> s >> t;
	cout << t << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll k,n;
  cin>>k>>n;
   vector<ll> v(n);
   vector<ll> v1(n+1);
   for(int i=0;i<n;i++)
     cin>>v[i];
      v1[0]=v[0]-0;
    for(int i=1;i<n;i++)
     {  
        v1[i]=v[i]-v[i-1];
     }
     v1[n]=k-v[n-1]+v[0];
    
     ll Max=-1;
     for(int i=0;i<=n;i++)
       {
           Max=max(v1[i],Max);
       }
     cout<<k-Max;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001

int main(void) {
	int n; cin >> n;
	vi b(n); rep(i,n-1) cin >> b[i];
	b[n-1] = INF;
	vi a(n);
	a[0] = b[0];
	rep2(i,1,n) a[i] = min(b[i-1],b[i]);
	int ans = 0;
	rep(i,n) ans += a[i];
	out(ans);
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define inf 1e8
using namespace std;

vector<int> seg(4*(2e5+7),inf);

void modify(int i,int val,int l,int r,int ind){
	if(l==r){
		seg[ind]=val;
		return;
	}
	int mid=(l+r)/2;
	if(i<=mid) modify(i,val,l,mid,2*ind);
	else modify(i,val,mid+1,r,2*ind+1);
	seg[ind]=min(seg[2*ind],seg[2*ind+1]);
	return;
}

int mn(int lb,int rb,int l,int r,int ind){
	if(lb<=l && r<=rb) return seg[ind];
	int mid=(l+r)/2;
	if(rb<=mid) return mn(lb,rb,l,mid,2*ind);
	else if(lb>mid) return mn(lb,rb,mid+1,r,2*ind+1);
	else return min(mn(lb,rb,l,mid,2*ind),mn(lb,rb,mid+1,r,2*ind+1));
}

int main(){
	IOS;
	string str;
	cin >> str;
	int s=str.size(),word=0,val=0,mns=0;
	vector<char> now;
	vector<vector<int>> counting(4e5+14);
	vector<int> *zero=&counting[2e5+7];
	long long int ans=0;
	zero[0].push_back(0);
	modify(0,0,0,2e5+7,1);
	for(int i=0;i<s;i++){
		if(str[i]=='('){
			val++;
			word++;
			now.push_back('(');
			int l=-1,r=word;
			while(r-l>1){
				int mid=(l+r)/2;
				if(mn(mid,word-1,0,2e5+7,1)>=val) r=mid;
				else l=mid;
			}
			ans+=zero[val].end()-upper_bound(zero[val].begin(),zero[val].end(),l);
			zero[val].push_back(i+1-mns);
			modify(word,val,0,2e5+7,1);
		}
		else if(str[i]==')'){
			val--;
			word++;
			now.push_back(')');
			int l=-1,r=word;
			while(r-l>1){
				int mid=(l+r)/2;
				if(mn(mid,word-1,0,2e5+7,1)>=val) r=mid;
				else l=mid;
			}
			ans+=zero[val].end()-upper_bound(zero[val].begin(),zero[val].end(),l);
			zero[val].push_back(i+1-mns);
			modify(word,val,0,2e5+7,1);
		}
		else{
			mns+=2;
			zero[val].pop_back();
			int l=-1,r=word;
			while(r-l>1){
				int mid=(l+r)/2;
				if(mn(mid,word-1,0,2e5+7,1)>=val) r=mid;
				else l=mid;
			}
			ans-=zero[val].end()-upper_bound(zero[val].begin(),zero[val].end(),l);
			modify(word,inf,0,2e5+7,1);
			word--;
			if(now.back()=='(')	val--;
			else val++;
			now.pop_back();
		}
		cout << ans << '\n';
	}
	return 0;
}



Measured memory_bytes: 22020
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(m);
  vector<int> y(m);
  vector<int> num[n+1];
  // vector<vector<int>> num(n, vector<int>(1));
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    num[p[i]].push_back(y[i]);
  }
  for (int i = 1; i <= n; i++) {
    sort(num[i].begin(), num[i].end());
  }
  for (int i = 0; i < m; i++) {
    int it = int(lower_bound(num[p[i]].begin(), num[p[i]].end(), y[i]) - num[p[i]].begin()) + 1;
    cout << setfill('0') << setw(6) << right << p[i];
    cout << setfill('0') << setw(6) << right << it << endl;
  }
  return 0;
}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){FIN;
	int k; cin>>k;
	string s; cin>>s;
	cout<<s.substr(0,k);
	if(SZ(s)>k)cout<<"...";
	cout<<"\n";
}

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

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main() {
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  combination c(n + k);
  mint ans = 0;
  rep(i, k + 1) {
    mint now = mint(26).pow(k - i);
    now *= mint(25).pow(i);
    now *= c(i + n - 1, n - 1);
    ans += now;
  }
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 35596
#include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

int main(){
    ll r,b,n;
    cin>>n>>b>>r;
    ll ans=b*(n/(r+b))+min(b,n%(r+b));
    cout<<ans<<endl;
    
}
   



Measured memory_bytes: 256
p = (500, 100, 50, 10, 5, 1)
while True:
    n = int(raw_input())
    if n == 0:
        break
    n = 1000 - n
    r = 0
    while n != 0:
        n -= [i for i in p if i <= n][0]
        r += 1
    print r

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

int main() {
  
  int n ;
  cin>>n ;
  int l,r ;
  int ans = 0 ;

  for (int i = 0; i < n; i++)
  {
        cin >> l >> r ;
        ans += r-l+1 ;
  } 

  cout << ans << endl ;

 return 0 ;

}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <stdlib.h>
using namespace std;
int main()
{
	string a,b;
	cin>>a>>b;
	a=a+b;
	int num = atoi(a.c_str());
	if(sqrt(num)==int(sqrt(num)))
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
int A[200000];
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	map<LL, int> cnt;
	LL sum = 0;
	LL ans = 0;
	for (int i = 0; i < N; i++) {
		sum += A[i];
		if (sum == 0) ans++;
		ans += cnt[sum];
		cnt[sum]++;
	}
	cout << ans << endl;
}

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

using namespace std;

long long combination(long long n){
  return n * (n - 1) / 2;
}

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

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

  vector<int> bucket(n + 1, 0);
  for(int idx = 0; idx < n; idx++){
    bucket[a[idx]] += 1;
  }

  long long sum_combination = 0;
  for(int idx = 1; idx <= n; idx++){
    sum_combination += combination(bucket[idx]);
  }

  for(int idx = 0; idx < n; idx++){
    long long old_combination = combination(bucket[a[idx]]);
    long long new_combination = combination(bucket[a[idx]] - 1);
    std::cout << sum_combination - old_combination + new_combination << '\n';
  }

  return 0;
}


Measured memory_bytes: 4224
#include<stdio.h>
#include<stdlib.h>
int main()
{
	long int L, R, i, j, min_temp ;
	int min= 2019;

	scanf("%ld", &L);
	scanf("%ld", &R);

	if(R-L >= 2019){
		min = 0;
		printf("%d", min);
		return 0;
	}

	for(i=L; i<=R; i++){
		for(j=i+1; j<=R; j++){
			min_temp = (i*j)%2019;
			if(min_temp < min){
				min = min_temp;
			}
		}
	}
	
	printf("%d", min%2019);		

	return 0;
}


Measured memory_bytes: 128
n,k = map(int,input().split())

if k > (n-1)*(n-2)//2:
    print(-1)
else:
    tar = ( (n-1)*(n-2)//2 ) -k
    m = n-1
    m += tar
    print(m)
    for i in range(1,n):
        print(i,n)

    v = 1
    while tar >0:
        for i in range(v+1,n):
            print(v,i)
            tar = tar-1
            if tar == 0:
                break
        v += 1


Measured memory_bytes: 42736
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INFLL = 1LL << 60;
const long long MOD = 1e9 + 7;

int main() {
    ll N, K;
    cin >> N >> K;
    cout << min(N % K, K - (N % K)) << endl;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    cout << ((h2 * 60 + m2) - (h1 * 60 + m1) - k) << endl;
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair

using namespace std;

int main()
{
   FAST/**/
   
   ll n;
   cin>>n;
   
   ll arr[n];
   for(ll i=0;i<n;i++)
        cin>>arr[i];
   
   ll ans = 0;
   
   for(ll i=0;i<n;i++)        
        for(ll j=i+1;j<n;j++)
            ans+=arr[i]*arr[j];
   cout<<ans;            
   
   return 0;
}

Measured memory_bytes: 256
n = int(input())
if n == 2:
  a, b = map(str,input().split())
  print(b + " " + a)
else:
  L = list(map(int, input().split()))
  M = sorted(L)
  c = (n + 1) // 2 - 1
  a = M[c + 1]
  b = M[c]
  for l in L:
    if l> b:
      print(b)
    else:
      print(a)

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

int main (){
  
  string s;
  cin >> s ;
  
  int a = 700;
    
  if (s[0]=='o') a+=100;
  if (s[1]=='o') a+=100;
  if (s[2]=='o') a+=100;
  
  cout << a << endl;
  
}


Measured memory_bytes: 256
n,k=map(int,input().split())
Mod=10**9+7
f=[1]*(2*n+1)
for i in range(2,2*n+1):
    f[i]=f[i-1]*i%Mod
def f_inverse(i):
    return pow(f[i],Mod-2,Mod)
f_inv=[f_inverse(i) for i in range(2*n+1)]
def comb(n,i):
    return f[n]*f_inv[i]*f_inv[n-i]%Mod

Ans=0
for x in range(0,min(k+1,n)):
    Ans=(Ans+comb(n,x)*comb(n-1,x))%Mod
print(Ans)

Measured memory_bytes: 34760
#!/usr/bin/env python3
from collections import Counter
 
n, *d = map(int, open(0).read().split())
c = Counter(d[1:])
c = [(0, 1)] + sorted(c.items())
ans = d[0] == 0
for i in range(1, len(c)):
    if i != c[i][0]:
        ans = 0
        break
    ans *= c[i - 1][1]**c[i][1]
    ans %= 998244353
print(ans)

Measured memory_bytes: 26408
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <vector>
#include <cstdlib>
using namespace std;
int a[100+10],n,m,k,t,ans;
int main()
{
    scanf("%d",&n);
    ans=0;
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
   for(int i=1;i<=n-1;++i)
        printf("%d ",a[i]);
        printf("%d\n",a[n]);
   for(int i=2;i<=n;++i)
   {
    k=a[i];
    int j=i-1;
        while(j>=1&&a[j]>k)
        {
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=k;
    for(int i=1;i<=n-1;++i)
        printf("%d ",a[i]);
        printf("%d\n",a[n]);
   }
    return 0;
}



Measured memory_bytes: 3200
n, x = map(int, input().split())

s = [1] * (n+1)
for i in range(1, n+1):
    s[i] = 2 * s[i-1] + 3

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


def solve(i, j):
    if j in dp[i]:
        return dp[i][j]

    if i == 0:
        return dp[i][j]

    if j == 0:
        return 0

    val = 0
    if s[i] <= j:
        val = solve(i-1, s[i-1]) * 2 + 1
    elif s[i-1] + 2 <= j:
        val = solve(i-1, s[i-1]) + 1 + solve(i-1, j-s[i-1]-2)
    else:
        val = solve(i-1, j-1)

    dp[i][j] = val
    return val


print(solve(n, x))


Measured memory_bytes: 3064
/******************************************
* AUTHOR : AMAN SAXENA *
* "There's some good in this world, and it's worth fighting for." *
* INSTITUTION : KIET Group of Institutions *
******************************************/
#include <bits/stdc++.h>

const long long MODULO=1000000007;
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define FOR1(i,a,n) for(int i=a;i<=n;i++)
#define FOR2(i,a,n) for(int i=a;i>=n;i--)
#define pb push_back
#define mp make_pair
#define ll long long 
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pi 3.14159265359

using namespace std;

template <typename TYPE> void in(TYPE &x){cin>>x;}

void solve()
{
    int x,n;
    cin>>x>>n;
    set<int> p;
    for (int i=0;i<n;i++) {
        int a;
        cin>>a;
        p.insert(a);
    }
    int m=0;
    for (int i=0;i<=101;i++)
        m = (abs(x-i) < abs(x-m) && !p.count(i) ? i : m);
    cout<<m<<endl;
}

void test()
{
    int t;
    cin>>t;
    while(t--) //for(int j=1;j<=t;j++) cout << "Case #" << j << ": ";
    {
        solve();
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    // test();
    solve();
    
    return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	while(cin>>n){
		vector<int>out;
		rep(i,10)if(n>=pow(2,9-i)){
			out.pb(pow(2,9-i));
			n-=pow(2,9-i);
		}
		sort(all(out));
		rep(i,out.size()){
			if(i)cout<<" ";
			cout<<out[i];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1256
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
bool flag[100000];
int main()
{
	int num;
	scanf("%d", &num);
	vector<ll>vec;
	for (int i = 0; i < num; i++)
	{
		int z;
		scanf("%d", &z);
		vec.push_back(z);
	}
	vector<ll>dif;
	for (int i = 0; i < num - 1; i++)dif.push_back(vec[i + 1] - vec[i]);
	int kai;
	ll gen;
	scanf("%d%lld", &kai, &gen);
	vector<int>v;
	for (int i = 0; i < num - 1; i++)v.push_back(i);
	for (int i = 0; i < kai; i++)
	{
		int z;
		scanf("%d", &z);
		swap(v[z - 2], v[z - 1]);
	}
	vector<int>ans;
	ans.resize(num - 1);
	for (int i = 0; i < num - 1; i++)
	{
		if (!flag[i])
		{
			vector<int>z;
			int now = i;
			for (;;)
			{
				if (flag[now])break;
				flag[now] = true;
				z.push_back(now);
				now = v[now];
			}
			for (int i = 0; i < z.size(); i++)
			{
				ans[z[i]] = z[(gen + i) % z.size()];
			}
		}
	}
	printf("%lld\n", vec[0]);
	ll now = vec[0];
	for (int i = 1; i < num; i++)
	{
		now += dif[ans[i - 1]];
		printf("%lld\n", now);
	}
}

Measured memory_bytes: 4012
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void){
  int n;
  cin >> n;
  VI a(1 << n);
  REP(i, 0, 1 << n) {
    cin >> a[i];
  }
  REP(k, 0, n) {
    VI b(1 << (n - k - 1));
    REP(bits, 0, 1 << (n - k - 1)) {
      int x = a[2 * bits];
      int y = a[2 * bits + 1];
      if (x > y) {
	swap(x, y);
      }
      if (x < y) {
	b[bits] = y - x;
      } else {
	b[bits] = x;
      }
    }
    a = b;
  }
  cout << a[0] << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
struct fastio{fastio(){std::ios::sync_with_stdio(false);std::cin.tie(nullptr);}}_fast_io_;
template<class T> bool chmin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> bool chmax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }

int main() {
	int x;
	std::cin >> x;
	if (x >= 30) std::cout << "Yes" << '\n';
	else std::cout << "No" << '\n';
	return 0;
}

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

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

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

using namespace std;

#define MAX_N 21
#define MAX_M 150001
#define INF (1<<29)
typedef long long ll;

double dp[MAX_N][MAX_M];

int main()
{
    int N;
    cin >> N;
    vector<double> v(N);
    for (int i = 0; i < N; i++) {
        cin >> v[i];
    }

    fill(dp[0], dp[MAX_N], INF);
    dp[0][1] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = MAX_M-1; j >= 0; j--) {
            if (dp[i][j] == INF) continue;
            for (int k = 1; k <= MAX_M; k++) {
                ll nv = (ll)j * k; 
                if (nv >= MAX_M) break;
                dp[i+1][nv] = min(dp[i+1][nv],
                                  max(dp[i][j], abs(v[i]-nv) / v[i]));
            }

        }
    }
    double res = INF;
    for (int i = 0; i < MAX_M; i++) {
        res = min(res, dp[N][i]);
    }
    printf("%.15f\n", res);
    return 0;
}

Measured memory_bytes: 25848
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {

	public class Activity implements Comparable<Activity> {
		int start;
		int end;
		public Activity(int start, int end) {
			this.start = start;
			this.end = end;
		}
		@Override
		public int compareTo(Activity o) {
			if (this.start != o.start) {
				return this.start - o.start;
			}
			return this.end - this.end;
		}
		
		public String toString() {
			return String.format("%d-%d", start, end);
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		Activity[] activities = new Activity[n];
		for (int i = 0; i < n; i++) {
			StringTokenizer st = new StringTokenizer(reader.readLine());
			int start = Integer.parseInt(st.nextToken());
			int end = Integer.parseInt(st.nextToken());
			activities[i] = new Activity(start, end);
		}
		reader.close();
		
		Arrays.sort(activities);
		Stack<Activity> stack = new Stack<Activity>();
		stack.push(activities[0]);
		for (int i = 1; i < n; i++) {
			Activity last = stack.peek();
			Activity acti = activities[i];
			if (acti.start > last.end) {
				stack.push(acti);
			} else if (acti.end < last.end) {
				stack.pop();
				stack.push(acti);
			}
		}
		System.out.println(stack.size());
	}
}


Measured memory_bytes: 58692
n = int(input())
a = list(map(int, input().split()))

from collections import defaultdict

cnt = defaultdict(int)
for i in range(n):
    cnt[a[i]] += 1
# print(cnt)

for key, val in list(cnt.items()):
    if val < 2:
        cnt.pop(key)
# print(cnt)

total = 0
for val in cnt.values():
    if val >= 2:
        total += val*(val-1)//2

for i in range(n):
    diff = 0
    if a[i] in cnt:
        y = (cnt[a[i]]-1)*cnt[a[i]]//2
        x = (cnt[a[i]]-1)*(cnt[a[i]]-2)//2
        diff = y - x
    print(total - diff)
        
        

# for i in range(n):
#     flag = False
#     if a[i] in cnt:
#         cnt[a[i]] -= 1
#         flag = True
#     # print(cnt)
#     ans = 0
#     for val in cnt.values():
#         if val >= 2:
#             ans += val*(val-1)//2
#     print(ans)
#     if flag:
#         cnt[a[i]] += 1

Measured memory_bytes: 94796
#include<iostream>

int main(){
	int k, a, b;
	std::cin >> k >> a >> b;

	for(int i=a; i<=b; i++){
		if(i % k == 0){
			std::cout << "OK" << std::endl;
			return 0;
		}
	}
	std::cout << "NG" << std::endl;
	return 0;
}

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

#define NIL NULL

struct node{
  int d;
  struct node *p;
  struct node *r;
  struct node *l;
};
typedef struct node *NP;

NP root;

void my_insert(NP);
void my_inorder_print(NP);
void my_preorder_print(NP);
NP my_find(NP,int);
NP my_successor(NP);
NP my_min(NP);
void my_delete(NP);
NP make_node(int);

int main(){
  int i,n,input;
  char in[7];
  NP z;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%s",in);
    if(strcmp(in,"insert")==0){
      scanf("%d",&input);
      //INSERT
      z=make_node(input);
      my_insert(z);
    }
    if(strcmp(in,"print")==0){
      //PRINT
      my_inorder_print(root);
      printf("\n");
      my_preorder_print(root);
      printf("\n");
    }
    if(strcmp(in,"find")==0){
      scanf("%d",&input);
      //FIND
      if(my_find(root,input)!=NIL) printf("yes\n");
      else printf("no\n");
    }
    if(strcmp(in,"delete")==0){
      scanf("%d",&input);
      //DELETE
      z=my_find(root,input);
      my_delete(z);
    }
  }
  return 0;
}

void my_insert(NP z){
  NP x,y;
  y=NIL;
  x=root;
  while(x!=NIL){
    y=x;
    if(z->d<x->d) x=x->l;
    else x=x->r;
  }
  z->p=y;

  if(y==NIL){
    root=z;
  }else if(z->d<y->d){
    y->l=z;
  }else{
    y->r=z;
  }
}

void my_inorder_print(NP p){
  if(p!=NIL){
    my_inorder_print(p->l);
    printf(" %d",p->d);
    my_inorder_print(p->r);
  }
}

void my_preorder_print(NP p){
  if(p!=NIL){
    printf(" %d",p->d);
    my_preorder_print(p->l);
    my_preorder_print(p->r);
  }
}

NP make_node(int key){
  NP p;
  p=(NP)malloc(sizeof(struct node));
  p->d=key;
  p->p=NIL;
  p->r=NIL;
  p->l=NIL;
  return p;
}

NP my_find(NP x,int k){
  if(x==NIL || x->d==k) return x;
  if(k<x->d) return my_find(x->l,k);
  else return my_find(x->r,k);
}

void my_delete(NP z){
  NP x,y;
  if(z->l==NIL || z->r==NIL) y=z;
  else y=my_successor(z);

  if(y->l!=NIL) x=y->l;
  else x=y->r;

  if(x!=NIL) x->p=y->p;

  if(y->p==NIL) root=x;
  else if(y==y->p->l) y->p->l=x;
  else y->p->r=x;

  if(y!=z) z->d=y->d;
}

NP my_successor(NP x){
  NP y;
  if(x->r!=NIL) return my_min(x->r);
  y=x->p;
  while(y!=NIL && x==y->r){
    x=y;
    y=y->p;
  }
  return y;
}

NP my_min(NP z){
  while(z->l!=NIL) z=z->l;
  return z;
}



Measured memory_bytes: 20488
#include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return x;}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

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

	char N=in<char>();
	
	if(N>='a' && N<='z') out('a');
	else out('A');
	return 0;
}


Measured memory_bytes: 3552
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] dp = new int[100010];
        dp[0] = 0;
        for(int i = 1; i <= 100000; i++) {
            dp[i] = Integer.MAX_VALUE;
            int power = 1;
            while(power <= i) {
                dp[i] = Math.min(dp[i], dp[i - power] + 1);
                power *= 6;
            }
            power = 1;
            while(power <= i) {
                dp[i] = Math.min(dp[i], dp[i - power] + 1);
                power *= 9;
            }
        }
        System.out.println(dp[n]);
    }
}


Measured memory_bytes: 23124
a,b,x = map(int, input().split())

if x*(b//x)<a:
  print(0)
elif x*(a//x)<a and x*(a//x+1)<a:
  print(0)
else:
  if x*(a//x)<a:
    min_n=a//x+1
  else:
    min_n=a//x
  
  max_n=b//x
  print(max_n-min_n+1)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main()
{ int n,i;
 float sum=0;
 cin>>n;
 int a[n];
 for(i=0;i<n;i++)
 {cin>>a[i];}
 for(i=0;i<n;i++)
 {sum = sum + (float)1/a[i];}
float result;
 result = (float)1/sum;
cout<<result;
return 0;}

Measured memory_bytes: 256
def ABC051B(k, s):
    count = 0
    for x in range(k+1):
        for y in range(k+1):
            z = s - x - y
            if 0 <= z <= k:
                count += 1
    print(count)

k, s = map(int, input().split())
ABC051B(k, s)


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace StartFinish
{
 
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int[] hw = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();


                if (hw[0] == 0 && hw[1] == 0)
                {
                    break;
                }
                for(int i = 0; i < hw[0]; i++)
                {
                    for (int j = 0; j < hw[1]; j++)
                    {
                        if ((i + j) % 2 == 0)
                        {
                            Console.Write("#");
                        }else
                        {
                            Console.Write(".");
                        }
                    }
                   
                    Console.WriteLine();
                }
                Console.WriteLine();
              
            }
        }
    }
}

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

using namespace std;

const int N = 10010;

int a[N];
int b[N];

int main() {
  int n;
  scanf("%d", &n);
  long long tot = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    tot -= a[i];
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", b + i);
    tot += b[i];
  }
  if (tot < 0) {
    puts("No");
    return 0;
  }
  long long cnt1 = 0, cnt2 = 0;
  for (int i = 0; i < n; ++i) {
    if (b[i] > a[i]) {
      cnt2 += (b[i] - a[i] + 1) / 2;
      cnt1 += (b[i] - a[i]) % 2;
    } else {
      cnt1 += a[i] - b[i];
    }
  }
  if (cnt1 > tot || cnt2 > tot) {
    puts("No");
    return 0;
  }
  puts(tot - cnt1 == 2 * (tot - cnt2) ? "Yes" : "No");
}


Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	int N, x;
	cin >> N >> x;
	vector<int>a(N);
	rep(i, N)cin >> a[i];
	int ans = 0;
	rep(i, N) {
		if (a[i] > x) {
			ans += a[i] - x;
			a[i] = x;
		}
	}
	rep(i, N - 1) {
		int sum = a[i] + a[i + 1];
		if (sum <= x)continue;
		int num = sum - x;
		a[i + 1] -= num;
		ans += num;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
//by (111110101)2
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
string a,b;
int main()
{
	cin>>a>>b;
	cout<<b<<a<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=500100;
inline int read(){
	int x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10+'0');
}
int a,b;
int main(){
	//freopen("1.out","w",stdout);
	read();a=read();b=read();
	a=abs(a-b);if(a&1)puts("Borys");else puts("Alice");
	return 0;
}

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

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

  bool flg = true;
  int counter = 0;
  while (flg) {
    for (int i=0; i<N; i++) {
      if(A[i] % 2 != 0) {
	flg = false;
	break;
      }
    }
    if (flg == true) {
      counter++;
      for (int i=0; i<N; i++) {
	A[i] /= 2;
      }
    }
  }

  cout << counter << endl;
  
}

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

struct asumikana {
	int kazu;
	int kosuu;
};

int asumisu(const void* x, const void* y) {
	int a = *(const int*)x, b = *(const int*)y;
	return a < b ? -1 : a > b;
}

int mizuhasu(const void* x, const void* y) {
	struct asumikana a = *(const struct asumikana*)x, b = *(const struct asumikana*)y;
	if (a.kosuu != b.kosuu) return a.kosuu > b.kosuu ? -1 : 1;
	return a.kazu < b.kazu ? -1 : a.kazu > b.kazu;
}

int n;
int v[114514];

int guNums[114514], kiNums[114514];

int guCount, kiCount;
struct asumikana gu[114514], ki[114514];

int main(void) {
	int i;

	if (scanf("%d", &n) != 1) return 1;
	if (n % 2 != 0) {
		puts("n wa guusuu zya nai to dame!!!!!");
		return 2;
	}
	for (i = 0; i < n; i++) {
		if (scanf("%d", &v[i]) != 1) return 1;
	}

	for (i = 1; i < n; i += 2) {
		guNums[i / 2] = v[i - 1];
		kiNums[i / 2] = v[i];
	}
	qsort(guNums, n / 2, sizeof(*guNums), asumisu);
	qsort(kiNums, n / 2, sizeof(*kiNums), asumisu);

	gu[0].kazu = guNums[0];
	gu[0].kosuu = 1;
	guCount = 1;
	for (i = 1; i < n / 2; i++) {
		if (guNums[i] == gu[guCount - 1].kazu) {
			gu[guCount - 1].kosuu++;
		} else {
			gu[guCount].kazu = guNums[i];
			gu[guCount].kosuu = 1;
			guCount++;
		}
	}
	ki[0].kazu = kiNums[0];
	ki[0].kosuu = 1;
	kiCount = 1;
	for (i = 1; i < n / 2; i++) {
		if (kiNums[i] == ki[kiCount - 1].kazu) {
			ki[kiCount - 1].kosuu++;
		} else {
			ki[kiCount].kazu = kiNums[i];
			ki[kiCount].kosuu = 1;
			kiCount++;
		}
	}
	qsort(gu, guCount, sizeof(*gu), mizuhasu);
	qsort(ki, kiCount, sizeof(*ki), mizuhasu);

	if (gu[0].kazu != ki[0].kazu) {
		printf("%d\n", n - gu[0].kosuu - ki[0].kosuu);
	} else if (guCount == 1 && kiCount == 1) {
		printf("%d\n", n / 2);
	} else if (guCount == 1) {
		printf("%d\n", n / 2 - ki[0].kosuu);
	} else if (kiCount == 1) {
		printf("%d\n", n / 2 - gu[0].kosuu);
	} else if (gu[1].kosuu + ki[0].kosuu >= gu[0].kosuu + ki[1].kosuu) {
		printf("%d\n", n - gu[1].kosuu - ki[0].kosuu);
	} else {
		printf("%d\n", n - gu[0].kosuu - ki[1].kosuu);
	}

	return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);


int main(){
  ll H,W;
  cin >> H >> W;

  ll ans = INF;
  FOR(i,1,H){
    ll s1 = i * W;
    ll s2, s3;
    // 縦割り
    s2 = (H-i) * (W/2);
    s3 = (H-i) * (W-(W/2));
    ans = min(ans, max(s1, max(s2,s3)) - min(s1, min(s2,s3)));

    // 横割り
    s2 = (H-i)/2 * W;
    s3 = (H-i-(H-i)/2) * W;
    ans = min(ans, max(s1, max(s2,s3)) - min(s1, min(s2,s3)));    
  }

  ll tmp;
  tmp = H; H = W; W = tmp;

  FOR(i,1,H){
    ll s1 = i * W;
    ll s2, s3;
    // 縦割り
    s2 = (H-i) * (W/2);
    s3 = (H-i) * (W-(W/2));
    ans = min(ans, max(s1, max(s2,s3)) - min(s1, min(s2,s3)));

    // 横割り
    s2 = (H-i)/2 * W;
    s3 = (H-i-(H-i)/2) * W;
    ans = min(ans, max(s1, max(s2,s3)) - min(s1, min(s2,s3)));    
  }

  cout << ans << endl;
}





Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N, M = map(int, input().split())
uf = UnionFind(N)
for i in range(M):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)
ans = 0
for i in range(N):
    ans = max(ans, uf.size(i))
print(ans)

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

typedef long long ll;
const int mod = 1e9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;

void solve()
{
  int ans=0;

  int n, m; cin >> n >> m;

  ans += (n-m)*100;
  ans += m*1900;
  ans *= pow(2,m);

  cout << ans << endl;
}

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


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

using namespace std;


int main() {
    int n, u, k; cin >> n;
    vector<vector<int> > v(n);
    for (int i = 0; i < n; ++i) {
        cin >> u >> k;
        vector<int> v0(k);
        for (int j = 0; j < k; ++j) {
            cin >> v0[j];
            --v0[j];
        }
        v[u-1] = v0;
    }
    queue<pair<int, int> > q;
    vector<bool> visited(n, false);
    q.push(make_pair(0, 0));
    visited[0] = true;
    vector<int> ans(n, -1);
    ans[0] = 0;
    while(!q.empty()) {
        pair<int, int> x = q.front(); q.pop();
        int cnt = x.second + 1;
        for (int i = 0; i < v[x.first].size(); ++i) {
            int j = v[x.first][i];
            if (!visited[j]) {
                q.push(make_pair(j, cnt));
                visited[j] = true;
                ans[j] = cnt;
            }
        }
    }
    for (int i = 0; i < n; ++i) cout << i + 1 << " " << ans[i] << endl;
    return 0;
}



Measured memory_bytes: 3172
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import math


def inputIntList():
  return [int(s) for s in input().split()]


def inputInt():
  return int(input())


def main():
  N, K = inputIntList()
  H = inputIntList()
  H = sorted(H, reverse=True)[K:]
  ans = sum(H)
  return ans


if __name__ == "__main__":
  print(main())


Measured memory_bytes: 25764