akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

uint64_t func(uint64_t A, uint64_t B, uint64_t x) {
  return (A * x) / B - A * (x / B);
}

int main() {
  uint64_t A = 0, B = 0, N = 0;
  std::cin >> A >> B >> N;

  std::cout << func(A, B, B <= N ? B - 1 : N) << std::endl;

  return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>
int main()
{
	int n, a[100], count = 0, i, j;

	scanf("%d",&n);
	for(i = 0; i < n; i++)
	{
		scanf("%d",&a[i]);

	}
	for(i = 0; i < n; i++)
	{
		for(j = i+1; j<n; j++)
		{
			count += a[i] * a[j];

		}
	}
	printf("%d\n",count);

}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e10;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)
typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;

int gcd(ll x, ll y) {
    if (x < y) swap(x, y);
    if (y == 0) {
        return x;
    }
    return gcd(y, x % y);
}

vector<pair<ll, int >> factorize(ll n) {
    vector<pair<ll, int >> res;

    for (ll i = 2; i * i <= n; i++) {
        if (n % i != 0) {
            continue;
        }
        res.emplace_back(i, 0);
        while (n % i == 0) {
            n /= i;
            res.back().second++;
        }
    }

    if (n != 1) res.emplace_back(n, 1);
    return res;

}


int main() {
    ll n;
    cin >> n;
    vector<pair<ll, int>> n_kaijo_soinsu_list;
    {
        map<ll, ll> n_kaijo_soinsu_map;
        for (ll i = 2; i <= n; i++) {
            vector<pair<ll, int>> i_soinsu_list = factorize(i);
            for (auto p : i_soinsu_list) {
                n_kaijo_soinsu_map[p.first] += p.second;
            }
        }
        for (auto sosu : n_kaijo_soinsu_map) {
            pair<ll, int> p(sosu.first, sosu.second);
            n_kaijo_soinsu_list.push_back(p);
        }
        cout << endl;

    }

    int ans = 0;

    for (int p = 0; p < n_kaijo_soinsu_list.size(); p++) {
        for (int q = p + 1; q < n_kaijo_soinsu_list.size(); q++) {
            for (int r = q + 1; r < n_kaijo_soinsu_list.size(); r++) {
                int pe = n_kaijo_soinsu_list[p].second;
                int qe = n_kaijo_soinsu_list[q].second;
                int re = n_kaijo_soinsu_list[r].second;

                if (pe >= 4 && qe >= 4 && re >= 2) {
                    ans++;
                }
                if (pe >= 4 && qe >= 2 && re >= 4) {
                    ans++;
                }
                if (pe >= 2 && qe >= 4 && re >= 4) {
                    ans++;
                }

            }
        }
    }

    for (int p = 0; p < n_kaijo_soinsu_list.size(); p++) {
        for (int q = p + 1; q < n_kaijo_soinsu_list.size(); q++) {
            int pe = n_kaijo_soinsu_list[p].second;
            int qe = n_kaijo_soinsu_list[q].second;

            if (pe >= 14 && qe >= 4) {
                ans++;
            }
            if (pe >= 4 && qe >= 14) {
                ans++;
            }
            if (pe >= 24 && qe >= 2) {
                ans++;
            }
            if (pe >= 2 && qe >= 24) {
                ans++;
            }

        }
    }

    for (int p = 0; p < n_kaijo_soinsu_list.size(); p++) {
        int pe = n_kaijo_soinsu_list[p].second;
        if (pe >= 74) {
            ans++;
        }

    }


    cout << ans << endl;

}



Measured memory_bytes: 256
// --------------
// Tejas Pandey  |
// 07 - 07 - 19  |
// ABC #133      |
// --------------

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

#define mod 1000000007
#define vi vector<int>
typedef long long int ll;
int main (void)
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ll l,r;
	cin >> l >> r;
	ll le = l%2019 ? l + 2019 - l%2019 : l;
	if(le > r)
	{
		ll ans = INT_MAX;
		for(ll i = l;i < r;i++)
		for(ll j = i+1;j <= r;j++)
		{
			ans = min(ans,((i%2019)*(j%2019))%2019);
		}
		cout << ans << "\n";
	}
	else
	cout << "0";
	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);
		// 整数の入力
		int N = sc.nextInt();
		int K = sc.nextInt();
		
		int ans = 0;
		for(int i = 1;i <= N;i++) {
			int h = sc.nextInt();
			if(K<=h) {
				ans ++;
			}
		}

		System.out.println(ans);

   		sc.close();
        return ;

    }
    
}


Measured memory_bytes: 45788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll a[100010];

int main() {
	ll n;
	cin>>n;
	for(int i=0;i<n;i++){
		int z;
		cin>>z;
		a[z]++;
	}
	ll flag=true;
	if(n%2==0){
		for(int i=0;i<=n;i+=2){
			if(a[i]!=0){
				flag=false;
			}
		}
		for(int i=1;i<=n;i+=2){
			if(a[i]!=2){
				flag=false;
			}
		}
	}
	else{
		if(a[0]!=1){
			flag=false;
		}
		for(int i=2;i<=n;i+=2){
			if(a[i]!=2){
				flag=false;
			}
		}
	}
	if(flag!=true){
		cout << 0;
		return 0;
	}
	ll ans=1;
	for(int i=1;i<=n/2;i++){
		ans*=2;
		ans%=inf;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int k;
  cin >> k;
  vector<long long> v = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  for (int i = 0; i < k; i++) {
    long long cur = v[i];
    if (cur % 10 != 0) v.push_back(cur * 10 + (cur % 10) - 1);
    v.push_back(cur * 10 + cur % 10);
    if (cur % 10 != 9) v.push_back(cur * 10 + (cur % 10) + 1);
  }
  cout << v[k - 1] << endl;
  return 0;
}

Measured memory_bytes: 2676
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

m = [[0] * 2005 for i in range(4005)]

def f():
    K, N = map(int, raw_input().split())
    MOD = 998244353

    for i in range(4001):
        m[i][0] = 1
    for i in range(2001):
        m[i][i] = 1
    for i in range(1, 4001):
        for j in range(1, 2001):
            m[i][j] = (m[i - 1][j] + m[i - 1][j - 1]) % MOD

    m2 = [1] * 4005
    for i in range(1, 4001):
        m2[i] = (m2[i - 1] * 2) % MOD

    ls = []
    for i in range(2, K + 2):
        ans = 0
        if i % 2 == 0:
            rem = i / 2 - 1
            for j in range(rem + 1):
                ans += m[N + K - 2 - rem * 2][K - 2 - rem * 2 + j] \
                * m[rem][j] * m2[j]
                ans += m[N + K - 3 - rem * 2][K - 2 - rem * 2 + j] \
                * m[rem][j] * m2[j]
                ans %= MOD
        else:
            rem = i / 2
            for j in range(rem + 1):
                ans += m[N + K - 1 - rem * 2][K - 1 - rem * 2 + j] \
                * m[rem][j] * m2[j]
                ans %= MOD
        ls.append(ans % MOD)

    ls += ls[:-1][::-1]

    for num in ls:
        print num

f()


Measured memory_bytes: 97948
#include <iostream>
#include <string>
//#include <algorithm>

using namespace std;

int main(){
    int N;
    cin >> N;
    string S[N];
    bool isFour = false;
    for (int i = 0; i < N; i++){
        cin >> S[i];
        if(S[i] == "Y"){
            isFour = true;
        }
    }

    if(isFour){
        cout << "Four" << endl;
    }else{
        cout << "Three" << endl;
    }
    //cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long count = 0;
        long ansc = 0;
        long ansd = 0;
        long anscd = 0;
        long ans = 0;
        if (a % c != 0) {
            ansc = ((((b / c)) * c     -       ((a / c) + 1) * c) / c) ;
        } else {
            ansc = ((((b / c)) * c - ((a / c) * c)) / c) ;
        }
        if (a % d != 0) {
            ansd = ((b / d) * d -   (((a / d) + 1)* d))   / d;
        } else {
            ansd = (((b / d)) * d - (a / d)  * d) / d ;
        }

//２つの値の最小公倍数
        long lcm = c * d / gcd(c, d);
        if (a % lcm !=0) {
            anscd = ((((b / (lcm)) * (lcm)) - (((a / (lcm)) + 1) * (lcm))) / (lcm))-1;
        }else{
            anscd = ((((b / (lcm)) * (lcm)) - (((a / (lcm))) * (lcm))) / (lcm))-1;
        }
        ans = b - a + 1 - ansc - ansd + anscd;
        System.out.println(ans);
//        for(long i= a; i<=b; i++){
//            if(i%c !=0 && i% d !=0){
//                count++;
//            }
//        }
    }


 //最大公約数を出すメソッド
    private static long gcd(long m, long n) {
        if (m < n) return gcd(n, m);
        if (n == 0) return m;
        return gcd(n, m % n);
    }
}


Measured memory_bytes: 22100
//AUTHOR - NAVEEN KUMAR(@naveen19991124)
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#inlcude<boost/multiprecision/cpp_dec_float.hpp>
#define ll long long
#define pb push_back
#define f(a) for(ll i = 0;i<a;i++)
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define rrep(i,a,b) for(ll i = a;i>b;i--)
#define v vector<ll>
#define mp make_pair
#define fir first
#define sec second
#define _fast_ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
//using boost :: multiprecision :: cpp_int;
//using boost :: multiprecision :: cpp_dec_float_50;
//using boost :: multiprecision :: cpp_dec_float_100;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}

ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1;
a *= a; a %= mod;} return p % mod;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

vector<char> solve(string s,ll m,string t1,ll n)
{
    ll dp[m+1][n+1];    
    for(ll i = 0;i<=n;i++)
    {
        dp[0][i] = 0;
    }
    for(ll i = 0;i<=m;i++)
    {
        dp[i][0] = 0;
    }
    for(ll i = 1;i<=m;i++)
    {
        for(ll j = 1;j<=n;j++)
        {
            if(s[i-1] == t1[j-1])
            {
                dp[i][j] = dp[i-1][j-1]+1;
            }
            else
            {
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    ll r = m;
    ll c = n;
    vector<char>ans;
   
    while(r>=1 && c>=1)
    {
        if(dp[r][c] == dp[r-1][c])
        {
            r = r-1;
        }
        else if(dp[r][c] == dp[r][c-1])
        {
            c = c-1;
        }
        else if(dp[r][c] == dp[r-1][c-1]+1)
        {
            ans.pb(s[r-1]);
         //   cout<<s[r-1]<<" "<<t1[c-1]<<"\n";
            r = r-1;
            c = c-1;
        }
    }
    return ans;
}
int main()
{
   // _fast_
    ll t = 1;
  //  cin>>t;
    while(t--){
    string s,t1;
    cin>>s>>t1;
    vector<char>ans;
    ans = solve(s,s.length(),t1,t1.length());
    for(ll i = ans.size()-1;i>=0;i--)
    {
        cout<<ans[i];
    }
    cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 70656
a, b, c, x, y = map(int, input().split())
p1 = a * x + b * y
p2 = 2 * c * (min(x, y))
p3 = 2 * c * (max(x, y))
if x > y:
    p2 += a * (x - y)
elif x < y:
    p2 += b * (y - x)

print(min(p1, p2, p3))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;

int main(){
   int n,h;
   cin>>n>>h;
   vector<int> a(n),b(n);
   vector<pair<int,int>> weapon(n);
   int max_a=0;
   for(int i=0;i<n;i++){
      cin>>a[i]>>b[i];
      max_a=max(max_a,a[i]);
      weapon[i]=make_pair(b[i],a[i]);
   }
   sort(weapon.begin(),weapon.end());
   int ans=0;
   int pos;
   for(int i=n-1;i>=0;i--){
      if(weapon[i].second==max_a)pos=i;
   }
   for(int i=n-1;i>=0;i--){
      if(h<=max(weapon[i].first,weapon[pos].first)){
         ans++;
         cout<<ans<<endl;
         return 0;
      }
      else {
         if(i!=pos && weapon[i].first>=weapon[pos].second){
            h-=weapon[i].first;
            ans++;
         }
         else continue;
      }
   }
   while(h>weapon[pos].first){
      h-=weapon[pos].second;
      ans++;
   }
   ans++;
   cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long H, W, N; cin >> H >> W >> N;
	struct Sqare {
		long long a, b;
	};
	vector<Sqare>  sq(N);
	for (int i = 0; i < N; i++) {
		cin >> sq[i].a >> sq[i].b;
		sq[i].a--;
		sq[i].b--;
	}
	vector<long long > ans(10, 0);
	map<int, map<int, int >> mp;
	ans[0] = (H - 2)*(W - 2);
	auto isOK = [&](int a, int b) {
		return 0 <= a && 0 <= b && a + 3 <= H && b + 3 <= W;
	};
	for (int i = 0; i < N; i++) {
		for (int k = 0; k < 3; k++) {
			for (int l = 0; l < 3; l++) {
				if (isOK(sq[i].a - k, sq[i].b - l)) {
					mp[sq[i].a - k][sq[i].b - l]++;
				}
			}
		}
	}
	for (auto itr = mp.begin(); itr != mp.end(); itr++) {
		for (auto itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++) {
			ans[itr2->second]++;
			ans[0]--;
		}
	}
	for (int i = 0; i < 10; i++) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 72064
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let n = nextInt()
    let [s, t] = next().split(" ")
    let ans = ""
    for(let i = 0; i< s.length; i++){
        ans += s[i]
        ans += t[i]
    }
    console.log(ans)
}
Main()


Measured memory_bytes: 29524
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
using namespace std;
#define NIL -1
const int maxn = 110;
int n,pos;
vector<int> pre,in,post;
void rec(int l,int r){
	if(l>=r) return;
	int root = pre[pos++];
	int m = distance(in.begin(),find(in.begin(),in.end(),root));
	rec(l,m);
	rec(m+1,r);
	post.push_back(root);
}
void solve(){
	pos = 0;
	rec(0,pre.size());
	for(int i=0;i<n;i++){
	    if(i) cout<<" ";
	    cout<<post[i];
	}
		
	cout<<endl;
}
int main() {
	int i,m;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>m;
		pre.push_back(m);
	}
	for(i=0;i<n;i++){
		cin>>m;
		in.push_back(m);
	}
	solve();
	return 0;
}


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

int main(){
  string s;
  cin >> s;
  if((s[0]==s[1]&&s[1]==s[2])||(s[1]==s[2]&&s[2]==s[3])) 
    cout << "Yes" << "\n";
  else 
    cout << "No" << "\n";
  return 0;
}


Measured memory_bytes: 3604
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

int n,d[N];

int main() {
	qr(n);
	for(int i=2,x;i<=n;i++)
		qr(x),d[x]++;
	for(int i=1;i<=n;i++) pr2(d[i]);
	return 0;
}



Measured memory_bytes: 4288
def solve(a,b,c,k):
    ans =0 
    if(a>=k):
        return k
        
    ans+=a
    k-=a
    
    if(b>=k):
        return ans
    
    k-=b
    
    if(c>=k):
        return ans-k
        
    ans-=c
    return ans
    
a, b, c, k = map(int, input().split())

#chosing from a
#how much we choose a 
print(solve(a,b,c,k))

Measured memory_bytes: 9192
#include <iostream>
#include <vector>
#define DIV 1000000007

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<long long> v(n);
    for (int i = 0; i < n; ++i) cin >> v[i];
    long long answer = 0;
    for (int i = 60; i >= 0; --i) {
        int n = 0, m = 0;
        for (long long a : v) {
            if (((a >> i) & 1) > 0) {
                ++n;
            } else {
                ++m;
            }
        }
        answer = (answer * 2 + 1L * n * m) % DIV;
    }
    cout << answer % DIV << endl;
}


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

int main() {
	int N;
	cin >> N;
	vector<ll>a(N);
	vector<ll>b(N);

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

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	int n = 0, m = 0, t = 0, u = 0;

	if (N % 2 == 1) {
		n = a[N / 2];
		m = b[N / 2];
		cout << m - n + 1 << endl;
	}

	else {
		n = a[(N / 2)-1];
		m = b[(N / 2)-1];
		t = a[(N / 2)];
		u = b[(N / 2)];

		cout << u + m - t - n + 1 << endl;
	}

	/*

	if (N % 2 == 1) {
		for (int i = 0; i < (N + 1) / 2; i++) {
			for (int j = 0; j < N - 1 - i; j++) {
				if (a[j] > a[j + 1]) {
					ll p = a[j];
					a[j] = a[j + 1];
					a[j + 1] = p;
				}
				if (b[j] > b[j + 1]) {
					ll q = b[j];
					b[j] = b[j + 1];
					b[j + 1] = q;
				}
			}
			if (i == (N - 1) / 2) {
				n = a[(N - 1) / 2];
				m = b[(N - 1) / 2];
			}
		}
		cout << m - n + 1 << endl;
	}

	else {
		for (int i = 0; i < (N / 2) + 1; i++) {
			for (int j = 0; j < N - 1 - i; j++) {
				if (a[j] > a[j + 1]) {
					ll p = a[j];
					a[j] = a[j + 1];
					a[j + 1] = p;
				}
				if (b[j] > b[j + 1]) {
					ll q = b[j];
					b[j] = b[j + 1];
					b[j + 1] = q;
				}
			}
			if (i == (N / 2)-1) {
				n = a[(N / 2) - 1];
				m = b[(N / 2) - 1];
			}
			else if (i == (N / 2)) {
				t = a[(N / 2)];
				u = b[(N / 2)];
			}

		}

		cout << u + m - t - n + 1 << endl;
	}

	*/

	return 0;
}

Measured memory_bytes: 6388
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
 
int main(){
    int A, B, C;
    scanf("%d %d %d", &A, &B, &C);
 
    int count(0);
    if (A == 5) count++;
    if (B == 5) count++;
    if (C == 5) count++;
    if (count == 2){
        if (A == 7) count++;
        else if (B == 7) count++;
        else if (C == 7) count++;
    }
    else cout << "NO\n";
    if (count == 3) cout << "YES\n";
}

Measured memory_bytes: 3640
/* 
	Author: ankrypt
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 100005
#define PI 3.141592653589793
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fi(a, b, c, d) for(int a = b; a < c; a += d)
#define fl(a, b, c, d) for(ll a = b; a < c; a += d)
#define fei(a, b, c, d) for(int a = b; a <= c; a += d)
#define fel(a, b, c, d) for(ll a = b; a <= c; a += d)
#define quit exit(0)
#define mem(x, a) memset(x, a, sizeof x)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pcl pair<char, ll>
#define psl pair<string, ll>


ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
vector<ll> V;
unordered_map<ll, ll> mp;
set<ll> s;
string S = "";
ll cases;

int main() {
	go;
    cin >> N >> M;
    fi(i, 0, N, 1) {
    	cin >> arr[i];
    }
   	ll ans = 0;
    fi(i, 1, N, 1) {
    	ll val = arr[i];
    	arr[i] = max(0ll, min(arr[i], M - arr[i - 1]));
    	ans += abs(arr[i] - val);
    }
    if(arr[1] + arr[0] > M) {
    	ans += arr[1] + arr[0] - M;
    }
    cout << ans << "\n";
    
	return 0;
}
/*
	Powered by Buggy Plugin
*/




Measured memory_bytes: 4448
#!/usr/bin/perl
use Data::Dumper;

my ($l) = map {$_ - 0} split(/\s+/o,<STDIN>);

my $mx = 1;
my $mx2 = 0;
while(1){
  if( $mx * 2 <= $l ){
    $mx *= 2;
    $mx2 ++;
  } else {
    last;
  }
}

#print "l=$l, mx=$mx, mx2=$mx2\n";
my @p = ();
$#p = $mx2;

my @g = ();
for(my $i = 0; $i<$#p; $i++){
  push(@g,+[$i,$i+1,0]);
  push(@g,+[$i,$i+1,2 ** $i]);
}

my $stack = $mx;

$l -= $mx;
while( $l>0 ){
  my $mx3 = 1;
  my $mx4 = 0;
  while(1){
    if( $mx3 * 2 <= $l ){
      $mx3 *= 2;
      $mx4 ++;
    } else {
      last;
    }
  }
  push(@g,+[$mx4,$#p,$stack]);
  $l -= $mx3;
  $stack += $mx3;
}
#print Dumper(@g);

my $nn = 1+$#p;
my $mm = 1+$#g;
print "$nn $mm\n";
for(my $i=0;$i<=$#g;$i++){
  my $a = 1+$g[$i]->[0];
  my $b = 1+$g[$i]->[1];
  my $c = $g[$i]->[2];
  print "$a $b $c\n";

}

exit(0);



Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for (int i = x, i##_len = (n); i < i##_len; ++i)
#define ALL(n) begin(n), end(n)
typedef long long ll;

int main()
{
  ll N;
  cin >> N;
  vector<ll> lucas(N + 1);
  lucas[0] = 2;
  lucas[1] = 1;
  rep2(i, 2, N + 1)
  {
    lucas[i] = lucas[i - 1] + lucas[i - 2];
  }
  cout << lucas[N] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LINE 8
#define st 1
#define YOKO 17
int main(){
    int N,D,X;
    cin>>N>>D>>X;
    int A[N];
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    int kosu=0;
    for(int k=0;k<N;k++){
        for(int i=1;i<=D;i+=A[k]){
            kosu++;
        }
    }
    kosu+=X;
    cout<<kosu;

    return 0;
}


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

int top, S[10000];

void push(int x)
{
	S[++top] = x;
}

int pop()
{
	top--;
	return S[top + 1];
}

int main()
{
	int a, b;
	top = 0;
	char s[100];

	while(scanf("%s", s) != EOF)
	{
		if(s[0] == '+'){
			a = pop();
			b = pop();
			push(a + b);
		}else if(s[0] == '-'){
			b = pop();
			a = pop();
			push(a - b);
		}else if(s[0] == '*'){
			a = pop();
			b = pop();
			push(a * b);
		}else{
			push(atoi(s));
		}
	}

	printf("%d\n", pop());

	return 0;
}


Measured memory_bytes: 2728
#include<iostream>
#include<bitset>
#include<algorithm>
using namespace std;

const int N = 100001;

int num[N];

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

    for(int i = 1; i <= n; i++) cin >> num[i];

    sort(num + 1, num + n + 1);
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        int cnt = 1;
        while(num[i] == num[i + 1]) {
            cnt++;
            i++;
        }
        if(cnt % 2) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>

int main() {
  std::string s;
  std::cin >> s;
  long long a=0, tmp;
  for(int i=0;i<(1<<(s.size()-1));++i){
    tmp = s[0]-'0';
    for(int j=0; j<s.size()-1;++j){
      if((i>>j)&1) {
        a+=tmp;
        tmp=s[j+1]-'0';
      }
      else{tmp=tmp*10+(s[j+1]-'0');}
    }
    a += tmp;
  }
  std::cout << a << "\n";
}
    

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

namespace AtCorder_170B
{
    class Program
    {
        static void Main(string[] args)
        {
            var countline = Console.ReadLine();
            var count = countline.Split(' ').Select(s => int.Parse(s)).ToArray();
            int x = count[0];
            int y = count[1];

            int ans = 1;

            int max = x * 4;
            int min = x * 2;

            if (min <= y & y <= max & y % 2 == 0)
                ans = 0;


            if (ans == 0)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");

            //Console.ReadKey();

        }
    }
}


Measured memory_bytes: 28264
#include <iostream>
using namespace std;
//
// Created by karayuu on 2018-12-23.
//

int main() {
    while (true) {
        int a, b;
        char op;
        cin >> a >> op >> b;

        int ans = 0;
        if (op == '?') {
            break;
        } else if (op == '+') {
            ans = a + b;
        } else if (op == '-') {
            ans = a - b;
        } else if (op == '*') {
            ans = a * b;
        } else {
            ans = a / b;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;

const ll INF = 1LL << 60;
ll dp[100010][3];
ll a[100010][3];

int main() {
    int N;
    cin >> N;
    rep(i,N) {
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    rep(i,N) {
        rep(j,3) dp[i][j] = 0;
    }
    rep(i,N) {
        rep(j,3)
            rep(k,3)
                if(j != k) chmax(dp[i+1][k],dp[i][j] + a[i][k]);
    }
    ll res = 0;
    rep(i,3) chmax(res,dp[N][i]);
    cout << res << endl;
}

Measured memory_bytes: 4992
//
// Created on 2020/07/21.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    int d;
    cin>>d;
    vector<int>c(26);
    vector<int>last(26,0);
    vector<vector<int>>s(d+1,vector<int>(26));
    for (int i = 0; i < 26; ++i) {
        cin>>c[i];
    }
    for (int i = 1; i <= d; ++i) {
        for (int j = 0; j < 26; ++j) {
            cin>>s[i][j];
        }
    }
    int final_score = 0;
    for (int k = 1; k <= d; ++k) {
        int today_score = 0;
        int t;
        cin>>t;
        t--;
        today_score += s[k][t];
        last[t] = k;
        for (int i = 0; i < 26; ++i) {
            today_score -= c[i] * abs(k - last[i]);
        }
        final_score += today_score;
        cout<<final_score<<endl;
    }

    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define int long long
using namespace std;
main()
{
	//freopen("input.txt","rt",stdin);
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	int s =0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			s += arr[i]*arr[j];
		}
	}
	cout<<s<<endl;
}

Measured memory_bytes: 256
//Solution by Tima
#include <bits/stdc++.h>
 
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
#define y1 sda
#define all(x) x.begin(), x.end()
 
using namespace std;    
const int N = int(3e5) + 12, mod = int(1e9)  + 7; 

int n;

int tin[N], tout[N], t, sz[N];

vector <int> g[N], gr[N], c[N], rb[N];

void dfs(int v, int p = -1){
	tin[v] = ++t;
	sz[v] = 1;
	for(int to : g[v]){
		if(to == p) continue;
	    dfs(to, v);
	    gr[v].pb(to);
	    sz[v] += sz[to];
	}
	tout[v] = ++t;
}

bool cmp(int u,int v){
	return tin[u] < tin[v];
}

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

	for(int i = 1,u,v; i < n; i++){
		scanf("%d%d", &u, &v);
		g[u].pb(v);
		g[v].pb(u);
	}

	dfs(1);

	ll ans = 1ll * n * (n + 1) / 2;

	for(int x = 1; x <= n; x++){
		if((int)c[x].size() == 0){
			puts("0");
			continue;
		}
		sort(c[x].begin(), c[x].end(), cmp);
		int mx = 0;
		int all = n;
		set <pair<int,int> > st;
		for(int i : c[x]){
			if(mx < tout[i]){
				all -= sz[i];
				mx = tout[i];	
			}                           
			else{
				pii p = *st.lower_bound(mp(tout[i],0));
			    rb[p.s].pb(i);
			}
			st.insert(mp(tout[i],i));
		}


		ll cur = ans - 1ll * all * (all + 1) / 2;

		for(int v : c[x]){
			sort(rb[v].begin(), rb[v].end(), cmp);
			reverse(all(rb[v]));
			reverse(all(gr[v]));
			int j = 0;
			for(int u : gr[v]){
				int res = sz[u];
				while(j < rb[v].size() && tin[u] <= tin[rb[v][j]]){
					res -= sz[rb[v][j]];
					j++;
				}
				cur -= 1ll * res * (res + 1) / 2;
			}
		}
		printf("%lld\n",cur);
	}


return 0;
}

Measured memory_bytes: 76160
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;

const uint64_t MOD = 1000000000 + 7;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	bool ok = false;
	for (int i = b; i < 99999999; i += b)
	{
		if ((i + c) % a == 0)
		{
			ok = true;
			break;
		}
	}

	cout << (ok ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,m;
string s[50];
int a[50][50];
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
void dfs(int x,int y,int b)
{
	a[x][y]|=b;
	for(int r=0;r<4;r++)
	{
		int tx=x+dx[r],ty=y+dy[r];
		if(tx<0||tx>=n||ty<0||ty>=m||s[tx][ty]!='.'||a[tx][ty]&b)continue;
		dfs(tx,ty,b);
	}
}
main()
{
	while(cin>>m>>n,n)
	{
		for(int i=0;i<n;i++)
		{
			cin>>s[i];
			for(int j=0;j<m;j++)a[i][j]=0;
		}
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(s[i][j]=='W')dfs(i,j,2);
				else if(s[i][j]=='B')dfs(i,j,1);
			}
		}
		int cntb=0,cntw=0;
		for(int i=0;i<n;i++)for(int j=0;j<m;j++)
		{
			if(s[i][j]!='.')continue;
			if(a[i][j]==1)cntb++;
			else if(a[i][j]==2)cntw++;
		}
		cout<<cntb<<" "<<cntw<<endl;
	}
}



Measured memory_bytes: 3216
#include <iostream>

using namespace std;

int X, A, B;

int main(void)
{
	cin >> X >> A >> B;
	
	if(B-A <= 0) cout << "delicious" << endl;
	else if(B-A <= X) cout << "safe" << endl;
	else cout << "dangerous" << endl;
	
	return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int64 mpow(int64 a, int64 b){
	if(b < 0) return 0;
	if(b == 0) return 1;
	if(b%2) return a*mpow(a, b-1)%mod;
	int64 ret = mpow(a, b/2);
	return ret*ret%mod;
}

int main(void){
	int64 res = 0;
	string s;
	cin >> s;
	vector<int64> ca(s.size()+1), cc(s.size()+1), rq(s.size()+1), lq(s.size()+1);
	REP(i, s.size()){
		ca[i+1] += ca[i]+(s[i] == 'A');
		lq[i+1] += lq[i]+(s[i] == '?');
	}
	for(int32 i = s.size()-1;i >= 0;i--){
		cc[i] += cc[i+1]+(s[i] == 'C');
		rq[i] += rq[i+1]+(s[i] == '?');
	}
	REP(i, s.size()){
		if(s[i] == '?' || s[i] == 'B'){
			int64 a = mpow(3, lq[i]-1)*lq[i]%mod+mpow(3, lq[i])*ca[i]%mod;
			a %= mod;
			int64 c = mpow(3, rq[i]-1)*rq[i]%mod+mpow(3, rq[i])*cc[i]%mod;
			c %= mod;
			cout << a << " " << c << endl;
			res += a*c%mod;
			res %= mod;
		}
	}
	cout << res << endl;
}*/
#include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int main(void){
	int64 res = 0;
	int64 z = 1, a = 0, ab = 0;
	string s;
	cin >> s;
	REP(i, s.size()){
		if(s[i] == 'A'){
			a = (a+z)%mod;
		}else if(s[i] == 'B'){
			ab = (ab+a)%mod;
		}else if(s[i] == 'C'){
			res = (res+ab)%mod;
		}else{
			res = (3*res+ab)%mod;
			ab = (3*ab+a)%mod;
			a = (3*a+z)%mod;
			z = (3*z)%mod;
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long ll;
#define loop(i,j) for(int i=0;i<j;i++)
using namespace std;
int main()
{
  ll N;
  cin>>N;
  ll ans=0;
  ll sum=0;
  ll araisan=0;
  ll mini=LLONG_MAX;
  vector<ll> a(N);
  loop(i,N){
    cin>>a[i];
    sum+=a[i];
  }
  loop(i,N-1){
    ans+=a[i];
    araisan=sum-ans;
    mini=min(mini,abs(ans-araisan));
  }
  cout<<mini<<endl;
}


Measured memory_bytes: 1920
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    vll A(N);
    rep(i, N) cin >> A[i];
    vll B(N);
    vll C(N);
    REP(i, 1, N + 1) {
        B[i - 1] = (A[i - 1] + i);
        C[i - 1] = (i - A[i - 1]);
    }
    sort(C.begin(), C.end());
    ll ans = 0;
    rep(i, N) {
        auto it1 = lower_bound(C.begin(), C.end(), B[i]);
        auto it2 = upper_bound(C.begin(), C.end(), B[i]);
        ans += distance(it1, it2);
    }
    //map<ll, ll> cnt;
    //rep(i, N) cnt[B[i]]++;
    //
    //int m = cnt.size();
    //rep(i, m) {
    //    ans += cnt[i] * (cnt[i] - 1) / 2;
    //}

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

Measured memory_bytes: 7936
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

int gcd(int a, int b){
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll nCm(ll n, ll m){
    if(m == 0 || m == n){
        return 1;
    } else if(m == 1){
        return n;
    }
    return (nCm(n - 1, m) + nCm(n - 1, m - 1));
}

//-----------------------ここから-----------

int main(void){
    int x, a, b;
    cin >> x >> a >> b;

    if(abs(x - a) < abs(x - b)){
        cout << 'A' << endl;
    } else {
        cout << 'B' << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

long long MOD = 1e9+7;

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

  int X;
  cin >> X;
  
   if(X < 600)       cout << 8 << endl;
   else if(X < 800)  cout << 7 << endl;
   else if(X < 1000) cout << 6 << endl;
   else if(X < 1200) cout << 5 << endl;
   else if(X < 1400) cout << 4 << endl;
   else if(X < 1600) cout << 3 << endl;
   else if(X < 1800) cout << 2 << endl;
   else              cout << 1 << endl;

  return 0;
}


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

int main(){

    int n;
    cin >> n;

    string s = to_string(n);
    vector<int> si(s.size()); 

    int sn = 0;
    for(int i = 0; i < s.size(); ++i){

        si[i] = s[i] - '0';
        sn += si[i];

    }

    if(n%sn == 0)cout << "Yes";
    else cout << "No";

    return 0;

}

Measured memory_bytes: 256
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.next());
        int M = Integer.parseInt(scanner.next());
        int[] A = new int[M];
        for (int i = 0; i < M; i++) {
            A[i] = Integer.parseInt(scanner.next());
        }

        if (N >= M) {
            System.out.println(0);
            return;
        }

        Arrays.sort(A);
        int[] B = new int[M - 1];
        for (int i = 0; i < M - 1; i++) {
            B[i] = A[i + 1] - A[i];
        }

        Arrays.sort(B);
        int ans = Arrays.stream(B).limit(B.length - (N - 1)).sum();
        System.out.println(ans);
    }
}



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

int H,W,x,y,z,mv;
char fc[504][500];
int f[504][502];
int dp[2][500][501];

int main(){
    while( cin >> H >> W, H|W ){
        mv = 0;
        for(x = 0; x < H; x++){
            cin >> (fc[x]+1);
            for(y = 0; y <= W; y++){
                f[x][y] = (fc[x][y] == '.');
            }
            for(y = 0; y < W; y++){
                f[x][y+1] += f[x][y];
            }
            for(y = 0; y < W; y++){
                for(z = y+1; z <= W; z++){
                    if( f[x][z] - f[x][y] == z-y ){
                        dp[x%2][y][z] = z-y;
                        if( x ){
                            dp[x%2][y][z] += dp[(x-1)%2][y][z];
                        }
                    }else{
                        dp[x%2][y][z] = 0;
                    }
                    mv = max(mv, dp[x%2][y][z]);
                }
            }
        }
        cout << mv << endl;
    }
    return 0;
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"
#define rep(i,n) for(ll i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define ll long long
struct thisdata{
  ll t;
  ll d;
};
bool cmp(const thisdata &a,const thisdata &b){
  return a.d<b.d;
}
vi par;//親の番号
//n要素で初期化
void init(int n){
  rep(i,n){
    par[i]=i;
  }
}
//木の根を求める
int root(int x){
  if(par[x]=x){
    return x;
  }else{
    return par[x]=root(par[x]);//経路圧縮
  }
}

//x,yが同じ集合に属するか否か
bool same(int x,int y){
  return (root(x)==root(y));
}
//x,yの属する集合を併合
void unite(int x,int y){
  x==root(x);
  y==root(y);
  if(x==y)return;

  par[x] = y;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
int main(void){
  int n,m;
  cin>>n>>m;
  vi a(m),b(m);
  vector<pair<int,int>> ab (m);
  rep(i,m){
    cin>>a[i]>>b[i];
    a[i]--;b[i]--;
    ab[i]={a[i],b[i]};
  }
  sort(ab.begin(),ab.end(),compare_by_b);
  int pre=-1;
  int ans=0;
  rep(i,m){
    if(!(ab[i].first<=pre && pre<ab[i].second)){
      pre=ab[i].second-1;
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    let s = s.trim().split_whitespace();
    let mut i: Vec<isize> = Vec::new();
    for z in s {
        i.push(z.parse().unwrap());
    }

    let a = i[0];
    let b = i[1];
    let c = i[2];
    let d = i[3];

    let mut ans = false;
    if (c - a).abs() <= d {
        ans = true;
    }
    if (a - b).abs() <= d && (b - c).abs() <= d {
        ans = true;
    }

    if ans {
        println!("Yes");
    } else {
        println!("No");
    }
}

Measured memory_bytes: 4352
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, m = sc.nextInt()
  val x = List.fill(n)(sc.nextLong())
  val y = List.fill(m)(sc.nextLong())

  val mod = 1000000007

  def plus(a: Long, b: Long): Long = (a + b) % mod
  def minus(a: Long, b: Long): Long = (a - b + mod) % mod
  def times(a: Long, b: Long): Long = (a * b) % mod

  val c = x.sliding(2).map{
    case List(x1, x2) => x2 - x1
  }.zipWithIndex.map{
    case (e, idx) => times(times(e, idx+1), n-idx-1)
  }.reduceLeft(plus)

  val d = y.sliding(2).map{
    case List(y1, y2) => y2 - y1
  }.zipWithIndex.map{
    case (e, idx) => times(times(e, idx+1), m-idx-1)
  }.reduceLeft(plus)

  println(times(c, d))
}


Measured memory_bytes: 75208
# -*- coding: utf-8 -*-
m, d = map(int, input().split())
cnt = 0

for i in range(1, m + 1):
    for j in range(22, d + 1):
        d10 = j // 10
        d1 = j % 10

        if d10 < 2 or d1 < 2:
            continue

        cnt += 1 if i == d10 * d1 else 0

print(cnt)


Measured memory_bytes: 2940
#include<cstdio>
#include<vector>

#define	pb	push_back

using namespace std;

typedef	vector<int>	vi;

int main(){
	static bool era[1000000];
	for(int i=2;i<100;i++){
		if(!era[i])	for(int j=i*i;j<1000000;j+=i)	era[j]=true;
	}

	vi pr;
	for(int i=2;i<1000000;i++)	if(!era[i])	pr.pb(i);
	int n=pr.size();

	for(long long L;scanf("%lld",&L),L;){
		if(L==1){ puts("1"); continue; }

		vi q;
		int old=-1;
		for(int i=0;i<n&&L>1;){
			if(L%pr[i]==0){
				L/=pr[i];
				if(old==i)	q.back()++;
				else		q.pb(1);
				old=i;
			}
			else	i++;
		}
		if(L>1)	q.pb(1);

		int prod=1;
		for(int i=0;i<q.size();i++)	prod*=(2*q[i]+1);
		printf("%d\n",(prod-1)/2+1);
	}

	return 0;
}

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

template<class t> void vin(vector<t>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int sum[502][502];

int main() {
    int n, m, Q;
    cin >> n >> m >> Q;
    vector<int> l(m), r(m);
    rep(i, m) {
        cin >> l[i] >> r[i];
        sum[--l[i]][--r[i]]++;
    }
    for (int y=0; y<n; ++y) {
        for (int x=0; x<n; ++x) {
            sum[y][x+1] += sum[y][x];
        }
    }
    for (int x=0; x<n; ++x) {
        for (int y=n-1; y>=1; --y) {
            sum[y-1][x] += sum[y][x];
        }
    }
    rep(i, Q) {
        int p, q;
        cin >> p >> q;
        p--; q--;
        cout << sum[p][q] << endl;
    }
    return 0;
}


Measured memory_bytes: 3456
//\\//\\ * * * //\\// ||
#include <bits/stdc++.h> 

#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  ll d;
  cin >> n >> d;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    ans += (x * x + y * y <= d * d);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3612
#include <iostream>


using namespace std;

void big(int arr[]) {
  int a = 2 * arr[0] + arr[1] + arr[2];
  int b = arr[0] + 2 * arr[1] + arr[2];
  int c = arr[0] + arr[1] + 2 * arr[2];
  if (a >= b && a >= c) {
    int temp = arr[0];
    arr[0] = temp * 2;
  }
  else if (b >= a && b >= c) {
    int temp = arr[1];
    arr[1] = temp * 2;
  }
  else if (c >= a && c >= b) {
    int temp = arr[2];
    arr[2] = temp * 2;};
  }

 
int main()
{
  int A, B, C, K;
  int nums[3];
  for (int i = 0; i < 3; i++) {
    cin >> nums[i];
  }
  cin >> K;
  for (int i = 0; i < K; i++) {
    big(nums);
  }
  int sum = 0;
  for (int i = 0; i < 3; i++) {
    sum += nums[i];
  }
  cout << sum;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
     
#define int long long
#define hell 1000000007  
#define endl "\n"
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX_SIZE 1000000000000
#define PI 3.14159265
set<pair<int, int>> divs;

void f(int n)
{
    for(int i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            pair<int, int> t(i, n/i);
            divs.insert(t);
        }
    }
} 


int32_t main()
{   
    io
    
    int a, b, x;
    cin>>a>>b>>x;

    int x1 = (a*a*b);

    if(2*x>=x1)
    {

        int h1 = 2*(a*a*b-x);
        int h2 = a*a*a;

        float h = (1.0*h1)/h2;

        float ans = atan(h);

        ans *= (180.00/PI);
        cout<<setprecision(15)<<fixed<<ans;

    }
    else
    {

        int h1 = a*b*b;
        int h2 =2*x;

        float h = (1.0*h1)/h2;

        float ans = atan(h);

        ans *= (180.00/PI);
        cout<<setprecision(15)<<fixed<<ans;

    }


    

return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18,MOD=1e9+7;
const int iINF=1e9;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int lim=a-b;
    cout<<c-min(lim,c)<<endl;

}

Measured memory_bytes: 256