akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int count(int x, int y, int d) {
    return max(min({ x, y, d, x + y - d }), 0);
}

int count(int x, int y, int a, int b, int d) {
    return d == 0 ? 1 : count(a, b, d - 1) + count(a, y - b - 1, d - 1) + count(x - a - 1, b, d - 1) + count(x - a - 1, y - b - 1, d - 1) + (a >= d) + (b >= d) + (x - a > d) + (y - b > d);
}

int main() {
    int x, y, z, a, b, c, n;
    cin >> x >> y >> z >> a >> b >> c >> n;
    vector<long long> cnt(n);
    for (int i = 0; i < x + y - 1; ++i)
        cnt[i % n] += count(x, y, a, b, i);

    for (int i = 0; i < n; ++i) {
        long long sum = 0;
        for (int j = 0; j < n; ++j)
            sum += cnt[(i - j + n) % n] * ((c - j + n) / n + (z - c - 1 - j + n) / n - (j == 0));

        if (i > 0) cout << " ";
        cout << sum;
    }
    cout << "\n";
    return 0;
}



Measured memory_bytes: 3100
#include <iostream>

using namespace std;

int a, b, c, n;

int main() {
    cin >> a >> b >> c >> n;
    int ans = 0;
    for (int i = 0; i <= a; ++i) {
        for (int j = 0; j <= b; ++j) {
            for (int k = 0; k <= c; ++k) {
                if (n == 500 * i + 100 * j + 50 * k) ++ans;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int N;
   cin >> N;
   int ans = 0;
   int l, r;
   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<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<queue>

#define rep(i,x) for(ll i=0;i<(int)(x);i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef std::pair<ll, ll> P;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

using namespace std;

ll n, m;
vector< vector<ll> > v;

void dfs(ll node, vector< vector<ll> > &vs, vector<ll> &color)
{
    rep(i, n){
        if(vs[node][i] == 1 && color[i] == 0){
            color[i] = 1;
            dfs(i, vs, color);
        }
    }
}

int main()
{
    cin >> n >> m;
    vector<P> pv(m);
    v.resize(n);
    rep(i, n){
        v[i].resize(n);
        rep(j, n){
            v[i][j] = 0;
        }
    }

    rep(i, m){
        ll tmp0, tmp1;
        cin >> tmp0 >> tmp1;
        pv[i].first = tmp0-1;
        pv[i].second = tmp1-1;
        v[tmp0-1][tmp1-1] = 1;
        v[tmp1-1][tmp0-1] = 1;
    }

    ll ans = 0;

    rep(i, m){
        vector< vector<ll> > vs = v;
        ll t0, t1;
        t0 = pv[i].first;
        t1 = pv[i].second;
        vs[t0][t1] = 0;
        vs[t1][t0] = 0;
        vector<ll> color(n, 0);
        dfs(0, vs, color);
        rep(i, n){
            if(color[i] == 0){
                ans++;
                break;
            }
        }
    }

    cout << ans;



}

Measured memory_bytes: 256
package main

import (
	"fmt"
	// なぜかひとつだけWAになるためテストで出力あったらすぐ抜けるようにするため
)

func craetea2z() []string {
	alphabet := make([]string, 0)
	for cur := []rune("a"); ; cur[0] += 1 {
		alphabet = append(alphabet, string(cur[0]))
		if alphabet[len(alphabet)-1] == "z" {
			break
		}
	}
	return alphabet
}

func main() {
	var s string
	fmt.Scan(&s)
	// 比較のためにsをsliceにせねばならん
	// 重複を殺しつつ
	d := make(map[string]string)
	// とりあえずアルファベット生成すりゃできんだろ
	alphabet := craetea2z()

	for _, vs := range []rune(s) {
		if _, ok := d[string(vs)]; !ok {
			d[string(vs)] = "もう見た"
			// ss = append(ss, string(vs))
		}
	}
	for _, v := range alphabet {
		if _, ok := d[v]; !ok {
			fmt.Println(v)
			break
		} else if v == "z" {
			fmt.Println("None")
		}
	}
}


Measured memory_bytes: 1664
n, k = (int(x) for x in input().split())
p = [int(x) / 2 + 0.5 for x in input().split()]
ans_i = ans = sum(p[:k])
i = 0
while i < n - k:
    ans_i = ans_i - p[i] + p[i+k]
    ans = max(ans, ans_i)
    i += 1
print(ans)


Measured memory_bytes: 23652
N,M=map(int,input().split())
now=0
a=0
MOD=10**9+7
p=[1,0]#0 humu  1 humazu
A=[int(input()) for i in range(M)]+[-1]
while now<N:
  if now==A[a]-1:
    p=[0,p[0]]
    a+=1
  else:
    p=[(p[0]+p[1])%MOD, p[0]%MOD]
  now+=1
print(p[0]%MOD)

Measured memory_bytes: 7848
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n=scanner.nextInt();
        String string=scanner.nextLine();
        HashSet set=new HashSet();
        for (int i = 0; i <n ; i++) {
           string=scanner.nextLine();
            set.add(string);
        }
        System.out.println(set.size());
    }
}


Measured memory_bytes: 79544
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;
#define int long long

signed main(){
	int N,V,sum=0;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>V; sum += V;
	}
	printf("%lld\n",sum/N);
	return 0;
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  string s;
  cin>>s;
  reverse(s.begin(),s.end());

  const int INF = 1e9;
  int dp[2]={0,INF};
  for(char c:s){
    int k=c-'0';
    int nx[2]={INF,INF};
    // k + a + f
    for(int f=0;f<2;f++)
      for(int a=0;a<10;a++)
        chmin(nx[(k+a+f)/10],dp[f]+a+(k+a+f)%10);
    dp[0]=nx[0];
    dp[1]=nx[1];
  }

  cout<<min(dp[0],dp[1]+1)<<endl;
  return 0;
}


Measured memory_bytes: 1412
#include<stdio.h>
int main(void){
    int n;
    long long int step=0;
    int val;
    scanf("%d",&n);
    int a[n];
    for(int i=0;i<n;++i){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n-1;++i){
        val=a[i]-a[i+1];
        if(0<val){
            step+=val;
            a[i+1]=a[i];
        }
    }
    printf("%ld\n",step);
    return 0;
}

Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
const ll mo = 1000000007;
auto mod = [](ll modx) {modx%=mo;modx+=mo;modx%=mo;return modx; };
const ll MAX = 510000;
const ll MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit()
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < MAX; i++)
  {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(ll n, ll k)
{
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main()
{
ll n , k ;
cin >> n >> k ;
vector<ll> a(n);
rep(i, n){
  cin >> a[i];
}
sort(a.begin(),a.end());
COMinit(); 
rep(i,n-k+1){
  ans=mod(ans+a[n-1-i]*COM(n-1-i,k-1));
  ans=mod(ans-a[i]*COM(n-1-i,k-1));
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 12928
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int i, j, k, cnt = 0;
		int n, x;
		int[] ans = new int[100];
		
		for(i = 0; i < 100; i++){
			ans[i] = 0;
		}
		
		while(true){
			n = sc.nextInt();
			x = sc.nextInt();
			
			if(n == 0 && x == 0){
				break;
			}
			
			for(i = 1; i <= n - 2; i++){
				for(j = i + 1; j <= n - 1; j++){
					for(k = j + 1; k <= n; k++){
						if(i + j + k == x){
							ans[cnt] ++;
						}
					}
				}
			}
			
			cnt ++;
		}
		
		for(i = 0; i < cnt; i++){
			System.out.println(ans[i]);
		}
	}
}

Measured memory_bytes: 26424
#include <stdio.h>
long long int bitwise(int k, int n, int *a, int *b) {
	long long int ans = 0;
	for (int i = 0; i < n; i++)
	{
		if ((k|a[i])==k)	ans += b[i];
	}
	return ans;
}

int main() {
	int n, k, a[100010], b[100010], temp;
	long long int ans, x;
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++)
	{
		scanf("%d %d", &a[i], &b[i]);
	}
	ans = bitwise(k, n, a, b);
	for (int j = 0; j < 30; j++)
	{
		if (k &(1 << j))
		{
			temp = (k&~(1 << j)) | ((1 << j) - 1);
			x = bitwise(temp, n, a, b);
			ans = (ans > x) ? ans : x;
		}
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 896
//  atcodder.xcode
//  main.cpp
//  Created by conan1024hao on 2019/11/11.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリ
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int H,W;
    cin>>H>>W;
    int h,w;
    cin>>h>>w;
    cout<<H*W-h*W-w*H+h*w<<endl;
    
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------



Measured memory_bytes: 256
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define S(i) scanf("%d",i);

int n,D,tmp,d[500001],Q,q,memo[500001],now=1,ans[500001];

main() {
    S(&n)S(&D)
    tmp = D;
    rep(i,n) {
        S(&d[i])
        if (tmp*2 > d[i]) tmp = abs(tmp-d[i]);
        memo[i] = tmp;
    }
    for(int i=n;i>0;--i) {
        if (memo[i-1] >= now) ans[i] = 1;
        if (2*now > d[i]) now += d[i];
    }
    if (D >= now) ans[0] = 1;
    S(&Q)
    rep(i,Q) {
        S(&q)
        if (ans[q-1]) printf("YES ");
        else printf("NO ");
    }
}



Measured memory_bytes: 7680
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

typedef pair<int, int> P;

const int N = 10000;

vector<int> com[N];
int a, b, r, x, y;

main(){
  while(cin >> a >> b >> r && (a|b|r)){
    for(int i=0;i<N;i++) com[i].clear();
    for(int i=0;i<a;i++){
      cin >> x >> y;
      com[y].push_back(x);
    }
    for(int i=0;i<N;i++) sort(com[i].begin(), com[i].end());
    int ans = 0;
    for(int i=0;i<b;i++){
      cin >> x >> y;
      for(int j=-4*r;j<=4*r;j++){
        if(0 <= j + y && j + y < N){
          int t = (int)sqrt(4.0 * r * 4 * r - j * j);
          ans += upper_bound(com[y+j].begin(), com[y+j].end(), x+t) - lower_bound(com[y+j].begin(), com[y+j].end(),x-t);
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 2756
package main

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

func main() {
	n := intStdin()
	a := intStdin()
	fmt.Println(strconv.Itoa(n * n - a))
}

/* template */
var sc = bufio.NewScanner(os.Stdin)
// 文字列を1行取得
func strStdin() (stringInput string) {
	sc.Scan()
	stringInput = sc.Text()
	stringInput = strings.TrimSpace(stringInput)
	return
}

// 整数値1つ取得
func intStdin() (num int) {
	stringInput := strStdin()
	num, _ = strconv.Atoi(strings.TrimSpace(stringInput))
	return
}
/* template */

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

using namespace std;

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

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

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

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

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

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

int n;
int a[125252];
set<int> b[125252];

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%d",a+i),--a[i];
  REP(i,n)b[a[i]].insert(i);
  int ans = 0;
  REP(i,n)if(b[i].count(a[i]))++ans;
  ans/=2;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 11136
#include <iostream>
#include <fstream>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <list>
#include <array>
#include <cstdlib>
#include <stack>
#include <string>
#include <queue>
#include <chrono>
#include <functional>
#include <limits>
#include <cmath>
#include <algorithm>
#include <random>
#include <regex>
#include <tuple>
#include <numeric>
#include <cassert>
#include <utility>
#include <bitset>
#include <complex>
#include <iomanip>
#include <ostream>
#include <sstream>
#include <ctime>
using namespace std;
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define index INDEX
#ifndef ONLINE_JUDGE
#define print(x) PRINT(x, #x)
template<typename T> void PRINT(T VARIABLE, const string& NAME) {
	cerr << NAME << " = " << fixed << VARIABLE << "\n";
}
#else
#define print(x) 0 
#endif
int generate_random() {
	const int MAX_RANDOM = (int)1e6;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	return uniform_int_distribution<int>(0, MAX_RANDOM)(rng);
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll INFLL = 2 * (ll)1e18 + 100;
#define int ll
#ifdef int 
const int INFINT = INFLL;
#else
const int INFINT = 2 * (int)1e9 + 100;
#endif
const double PI = atan(1) * 4;
const double EPS = 1e-6;
const int SEED = (int)1e3 + 7;
const int MOD = (int)1e9 + 7;
const int NMAX = (int)1e5 + 5;

int n, m;
V graf[NMAX];
int dp[NMAX];
int mmax =0 ;
V top_sort;
bool has_parent[NMAX];
bool trecut[NMAX];

void dfs(int nod)
{
    trecut[nod] = 1;
    for(auto i: graf[nod]) if(!trecut[i])
    {
        dfs(i);
    }
    top_sort.pb(nod);
}


int32_t main() {
#ifndef ONLINE_JUDGE
	double START_PROGRAM = clock();
#endif
	srand(time(NULL));
	cout << setprecision(20) << fixed;
	FASTIO;
    cin >> n >> m;
    for1(i, m)
    {
        int a, b;
        cin >> a >> b;
        graf[a].pb(b);
        has_parent[b] = 1;
    }
    for1(i, n) if(!has_parent[i]) dfs(i);
    reverse(all(top_sort));
    for(auto nod: top_sort)
    {
        for(auto i : graf[nod]) dp[i] = max(dp[i], dp[nod] + 1);
    }
    for0(i, NMAX) mmax = max(mmax, dp[i]);
    cout << mmax;






#ifndef ONLINE_JUDGE
	double END_PROGRAM = clock();
	double ELAPSED_TIME = (END_PROGRAM - START_PROGRAM) / CLOCKS_PER_SEC;
	cerr << "\n\nElapsed Time: " << ELAPSED_TIME * 1000 << "\n";
#endif
	return 0;
}







Measured memory_bytes: 12276
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

    string s;
    cin >> s;

    array<int, 10> a;
    vector<decltype(a)> v(n);
    for (int j = 0; j < 10; j++) {
        a[j] = n;
    }
    for (int i = n - 1; i >= 0; i--) {
        a[s[i] - '0'] = i;
        v[i] = a;
    }

    int r = 1000;
    for (int h = 0; h < 1000; h++) {
        int i = 0;
        int t = h;
        for (int j = n - 2; j <= n; j++) {
            i = v[i][t % 10] + 1; t /= 10;
            if (i > j) {
                r--;
                break;
            }
        }
    }

    cout << r << endl;

    return 0;
}

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

Measured memory_bytes: 580
# from geek for geeks
# a^(a+1)^(a+2).....^(a+k) = (a^(a+1))^((a+2)^(a+3))^((a+4)^(a+5)).....((a+k-1)^(a+k))
# we can pair every two adjacent no and their xor will be 1 because of lsb
def main():
	a , b = map(int , input().split())
	a=a-1
	rem = a%4
	x, y =0 ,0
	if rem==0:# this mean no of 1's is even (1 is result of xor of each pair)
		x=a   # and we are left with only a no pair for this element
	elif rem==1:# this means every no is successfully paired and no of ones is odd
		x=1
	elif rem==2: # this means last element is not paired and no of one's is odd and 
		x = a+1		# a is even no so ans 1^a
	else:
		x=0		# every no is succesfully paired and no of 1 is even so xor is 0	
	rem = b%4
	if rem ==0:
		y=b
	elif rem==1:
		y=1
	elif rem==2:
		y=b+1
	else:
		y=0
	print(x^y)
if __name__=="__main__":
	main()

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

int main()
{
int H1,M1,H2,M2,K;    
cin >> H1>> M1 >> H2 >> M2 >> K;   

 
cout <<(H2-H1)*60+(M2-M1)-K <<endl;{
} 
}    
    
    
   

Measured memory_bytes: 3624
#include <stdio.h>

int min(int a, int b){
    return a <= b ? a : b;
}

int main(){
    int N, X;
    scanf("%d%d", &N, &X);
    int m[N], Min = 1001;
    for (int i = 0; i < N; ++i){
        scanf("%d", &m[i]);
        X -= m[i];
        Min = min(m[i], Min);
    }
    int ct = N;
    ct += X / Min;
    printf("%d", ct);

    return 0;
}

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

int main(){
  string S; cin >> S;
  for(int i=0; i<=7; i++){
    string Ssub=S.substr(0,i)+S.substr(S.size()-7+i);
    if(Ssub=="keyence"){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math
def main():
    N,K = map(int,input().split())
    num = 0
    while True:
        if (K**(num-1))<= N < (K**num):
            print(math.ceil(num))
            break
        num+=1
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
    int n;
    cin>>n;
    if(n>=400&&n<=599)cout<<8;
    if(n>=600&&n<=799)cout<<7;
    if(n>=800&&n<=999)cout<<6;
    if(n>=1000&&n<=1199)cout<<5;
    if(n>=1200&&n<=1399)cout<<4;
    if(n>=1400&&n<=1599)cout<<3;
    if(n>=1600&&n<=1799)cout<<2;
    if(n>=1800&&n<=1999)cout<<1;
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  ll n, k;
  cin >> n >> k;
  vector<ll> x(n), y(n), c(n);
  for (int i = 0; i < n; i++){
    char ch;
    cin >> x[i] >> y[i] >> ch;

    if (ch == 'W'){
      c[i] = 0;
    }
    else
      c[i] = 1;
  }
  
  vector<vector<ll>> grid(k + 1, vector<ll>(2*k + 1, 0));

  for (ll i = 0; i < n; i++){
    x[i] = x[i] % (2*k);
    y[i] = y[i] % (2*k);
    if (x[i] >= k && y[i] >= k){
      x[i] -= k;
      y[i] -= k;
    }
    else if (x[i] >= k){
      x[i] -= k;
      c[i] = 1 - c[i];
    }
    else if (y[i] >= k){
      y[i] -= k;
      c[i] = 1 - c[i];
    }

    if (c[i] == 1){
      grid[0][0]++;
      grid[x[i]+1][0]--;
      grid[0][y[i]+1]--;
      grid[x[i]+1][y[i]+1]++;

      grid[x[i]+1][y[i]+1]++;
      grid[k][y[i]+1]--;
      grid[x[i]+1][y[i]+1+k]--;
      grid[k][y[i]+1+k]++;

      grid[0][y[i]+1+k]++;
      grid[x[i]+1][y[i]+1+k]--;
      grid[0][2*k]--;
      grid[x[i]+1][2*k]++;
    }
    else {
      grid[0][0]++;
      grid[k][0]--;
      grid[0][2*k]--;
      grid[k][2*k]++;

      grid[0][0]--;
      grid[x[i]+1][0]++;
      grid[0][y[i]+1]++;
      grid[x[i]+1][y[i]+1]--;

      grid[x[i]+1][y[i]+1]--;
      grid[k][y[i]+1]++;
      grid[x[i]+1][y[i]+1+k]++;
      grid[k][y[i]+1+k]--;

      grid[0][y[i]+1+k]--;
      grid[x[i]+1][y[i]+1+k]++;
      grid[0][2*k]++;
      grid[x[i]+1][2*k]--;
    }

    /*
  for (ll i = 0; i < k+1; i++){
    for (ll j = 1; j < 2*k+1; j++){
      grid[i][j] += grid[i][j-1];
    }
  }
  for (ll j = 0; j < 2*k+1; j++){
    for (ll i = 1; i < k+1; i++){
      grid[i][j] += grid[i-1][j];
    }
  }
    for (ll i = k-1; i > -1; i--){
      for (ll j = 0; j < 2*k; j++){
        cout << grid[i][j] << " ";
      }
      cout << endl;
    }
    cout << endl;
  */

  }

  for (ll i = 0; i < k+1; i++){
    for (ll j = 1; j < 2*k+1; j++){
      grid[i][j] += grid[i][j-1];
    }
  }
  for (ll j = 0; j < 2*k+1; j++){
    for (ll i = 1; i < k+1; i++){
      grid[i][j] += grid[i-1][j];
    }
  }


  ll ans = 0;
  for (ll i = 0; i < k; i++){
    for (ll j = 0; j < 2*k; j++){
      ans = max(ans, grid[i][j]);
    }
  }
  cout << ans << endl;

  return 0;
}


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

int main(){
  int E, Y;
  cin>>E>>Y;

  if( E == 0 ){
    
    if( 1868 <= Y && Y <= 1911 ) cout<<"M"<< (Y - 1867) <<endl;
    if( 1912 <= Y && Y <= 1925 ) cout<<"T"<< (Y - 1911) <<endl;
    if( 1926 <= Y && Y <= 1988 ) cout<<"S"<< (Y - 1925) <<endl;
    if( 1989 <= Y && Y <= 2016 ) cout<<"H"<< (Y - 1988) <<endl;
  }
  
  if( E == 1 ) cout<< (Y + 1867) <<endl;
  if( E == 2 ) cout<< (Y + 1911) <<endl;
  if( E == 3 ) cout<< (Y + 1925) <<endl;
  if( E == 4 ) cout<< (Y + 1988) <<endl;

  return 0;

}



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

#include <iomanip>
void _130() {
    int w, h, x, y;
    cin >> w >> h >> x >> y;

    cout << fixed << setprecision(10);
    cout << (double)w * h / 2 << " " << (2 * x == w && 2 * y == h) << endl;
}

void _131() {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;

    long long count = 0;
    for (long long i = a; i <= b; ++i) {
        if (i % c != 0 && i % d != 0){
            count++;
        }
    }
    cout << count << endl;
}

#include <cmath>
void _131_() {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;

    long long min_baisuu;
    for (long long i = min(c, d); i <= c * d; ++i) {
        if (i % c == 0 && i % d == 0) {
            min_baisuu = i;
            cout << min_baisuu << endl;
            break;
        }
    }

    long long c_baisuu_num = 0;
    long long d_baisuu_num = 0;
    long long cd_baisuu_num = 0;

    c_baisuu_num = abs(a / c - b / c);
    d_baisuu_num = abs(a / d - b / d);
    cd_baisuu_num = abs(a / min_baisuu - b / min_baisuu);

    cout << abs(a - b) + 1 - (c_baisuu_num + d_baisuu_num - cd_baisuu_num) << endl;
}

void _131__() {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;

    long long min_baisuu = 0;
    long long max_yakusuu = 0;
    
    long long amari = 0;
    long long bigger = max(c, d);
    long long smaller = min(c, d);
    while (true) {
        amari = bigger % smaller;
        if (amari == 0) {
            max_yakusuu = smaller;
            break;
        }
        bigger = smaller;
        smaller = amari;
    }
    // cout << max_yakusuu << endl;
    min_baisuu = c * d / max_yakusuu;

    long long b_num = b - b / c  - b / d + b / min_baisuu;
    long long a_num = a - 1 - (a - 1) / c - (a - 1) / d + (a - 1) / min_baisuu;
    // cout << b_num << " " << a_num << endl;
    cout << b_num - a_num << endl;
}

#include <vector>
#include <algorithm>
void _132() {
    int n;
    cin >> n;
    vector<int> d;
    int tmp;
    for (int i = 0; i < n; ++i)  {
        cin >> tmp; 
        d.push_back(tmp);
    }
    sort(d.begin(), d.end());
    
    if (d.size() % 2 == 1) {
        cout << 0 <<endl;
        return;
    }
    int half_index = d.size() / 2 - 1;
    cout << d[half_index + 1] - d[half_index] << endl;

    

}

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



Measured memory_bytes: 892
use std::io::*;
use std::str::FromStr;

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    loop {
        let h: usize = sc.read();
        let w: usize = sc.read();

        if h == 0 && w == 0 {
            break;
        }
        for i in 0..h {
            let row: String = if i == 0 || i == h-1 {
                std::iter::repeat("#").take(w-2).collect()
            } else {
                std::iter::repeat(".").take(w-2).collect()
            };
            println!("#{}#", row);

        }
        println!();
    }
}


Measured memory_bytes: 5028
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a, b = MAP()
c = 0
l = []
# a_num = 0
# b_num = 0
sa = b - a
for i in range(1, 1000):
    c += i
    l.append(c)
# print(l[sa - 1] - b)
print(l[sa - 2] - a)

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

int sq[30], idx = 0;
void rec(int n){
    if(n < 0) return;
    if(n == 0){
        for(int i = 0; i < idx; i++){
            if(i == idx - 1) cout << sq[i] << endl;
            else cout << sq[i] << " ";
        }
    } else {
        for(int i = n; i >= 1; --i){
            if(i <= sq[idx - 1]){
                sq[idx++] = i;
                rec(n - i);
                --idx;
            }
        }
    }
}

int main(){
    
    int n;
    while(cin >> n, n){
        for(int i = n; i >= 1; --i){
            sq[idx++] = i;
            rec(n - i);
            --idx;
        }
    }
}

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

int main(){
  int n;
  long long ans;

  scanf(" %d",&n);

  ans=1;
  for(int i=2;i<=n;i++){
    ans=(ans*(long long)i)%1000000007;
  }

  printf("%lld\n",ans%1000000007);

  return 0;
}


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

void swap(int Array[], int i, int j) {
    int temp;
    temp = Array[i];
    Array[i] = Array[j];
    Array[j] = temp;
}

int partition(int Array[], int pIndex, int rIndex) {
    int x = Array[rIndex];
    int i = pIndex;
    int temp;
    
    for (int j = pIndex; j < rIndex; j++)
        if (Array[j] <= x) {
            swap(Array, i, j);
            i++;
        }

    swap(Array, i, rIndex);
    return i;
}

void printArray(int array[], int n) {
    for (int i = 0; i < n; i++) {
        if (i != 0) printf(" ");
        printf("%d", array[i]);
    };
}

void printArrayHighlight(int array[], int n, int hightlightIndex) {
    for (int i = 0; i < n; i++) {
        if (i != 0) printf(" ");
        if (i == hightlightIndex)
            printf("[%d]", array[i]);
        else
            printf("%d", array[i]);
    };
}

int main(int argc, char** argv) {
    int nArray;
    scanf("%d", &nArray);
    
    int array[nArray], brrby[nArray];
    
    for (int iArray = 0; iArray < nArray; iArray++) {
        scanf("%d", &array[iArray]);
    }
    
    // do the magic
    int index = partition(array, 0, nArray - 1);
    
    printArrayHighlight(array, nArray, index);
    printf("\n");

    return (EXIT_SUCCESS);
}




Measured memory_bytes: 2112
n = gets.to_i

digits = 1
while 10 ** digits <= n
    digits += 1
end

answer = 0
(3...digits).each{|d|
    answer += 3 ** d - 3 * (2 ** d) + 3
}

[3, 5, 7].repeated_permutation(digits){|nums|
    val = nums.inject(0){|acc, it| acc * 10 + it }
    break if val > n
    if [3, 5, 7].all?{|it| nums.include?(it)}
        answer += 1
    end
}
puts answer


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



int main()
{
	int a, b, c, count = 0;
	cin >> a >> b >> c;
	for (int i = a; i <= b; i++){
		if (c % i == 0){
			count++;
		}
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 1160
//   Rishabh Agarwal
#include <bits/stdc++.h>
#define F first
#define S second
#define MAX 10000003
using namespace std;

typedef long long int ll;
const ll mod = 1e18;
const ll INF= 1e18;
long double PI=3.1415926;

ll power(ll a,ll b){
    if(b==0){
        return 1;
    }
    ll temp=power(a,b/2)%mod;
    if(b%2==0){
        return (temp*temp)%mod;
    }
    else{
        return ((a*temp)%mod*temp)%mod;
    }
}

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

vector<vector<ll>> adj(100000); 
vector<ll> visited;
vector<ll> ans;

void dfs(ll v) {
    visited[v] = true;
    for (ll u : adj[v]) {
        if (!visited[u])
            dfs(u);
    }
    ans.push_back(v);
}

void topological_sort(ll n) {
    visited.assign(n, false);
    ans.clear();
    for (ll i = 0; i < n; ++i) {
        if (!visited[i])
            dfs(i);
    }
    reverse(ans.begin(), ans.end());
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    //cin>>t;
    t=1;
    //ll c=1;
    while(t--){
        ll n,m;
        cin>>n>>m;
        vector<vector<ll>>adj2(n+1);
        for(ll x=0; x<m; x++){
            ll y,z;
            cin>>y>>z;
            adj[y-1].push_back(z-1);
            adj2[z].push_back(y);
        }
        topological_sort(n);
        for(ll x=0; x<ans.size(); x++){
            ans[x]++;
        }
        ll dp[n+1]={0};
        ll an=0;
        for(ll x=0; x<ans.size(); x++){
            dp[ans[x]]=0;
            for(ll y=0; y<adj2[ans[x]].size(); y++){
                dp[ans[x]]=max(dp[ans[x]],dp[adj2[ans[x]][y]]+1);
            }
            an=max(an,dp[ans[x]]);
        }
        cout<<an<<"\n";
        adj2.clear();
        adj.clear();
        visited.clear();
        ans.clear();
        //cout<<"Case #"<<c<<": "<<ans<<"\n";
        //c++;
    }
    return 0;
}

Measured memory_bytes: 15228
N = int(input())
P = list(map(int, input().split()))
C = 0
for i in range(N):
    if i == 0 or i == N-1:
        continue
    elif (P[i] > P[i-1] and P[i+1] > P[i]) or (P[i-1] > P[i] and P[i] > P[i+1]):
        C += 1
print(C)

Measured memory_bytes: 2940
#include<iostream>

int main(void) {
	
	int N,A,B;
	std::cin >> N >> A >> B;
	
	if (N*A < B) {
		std::cout << N*A << std::endl;
	}
	else if (N*A > B) {
		std::cout << B << std::endl;
	}
	else if (N*A == B) {
		std::cout << B << std::endl;
	}
	return 0;
}


Measured memory_bytes: 256
judge_num = input()
 
bef = int(judge_num[:2])
aft = int(judge_num[2:])
 
if(bef <= 12 and aft <= 12 and bef >= 1 and aft >= 1):
  print("AMBIGUOUS")
elif(bef <= 12 and bef >= 1):
  print("MMYY")
elif(aft <= 12 and aft >= 1):
  print("YYMM")
else:
  print("NA")

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

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

using namespace std;
typedef long long ll;

ll x[1010], y[1010], z[1010];
ll dp[1010][1010];

ll solve(int n, int m, ll d1, ll d2, ll d3) {
	vector<ll> v(n);
	rep(i, n) v[i] = d1 * x[i] + d2 * y[i] + d3 * z[i];
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	ll ret = 0; 
	rep(i, m) ret += v[i];
	return ret;
}

int main(int argc, char const *argv[])
{
	int n, m; cin >> n >> m;
	rep(i, n) cin >> x[i] >> y[i] >> z[i];

	ll d[] = {1, -1};
	ll ans = -1e18;
	rep(i, 2)rep(j, 2)rep(k, 2) ans = max(ans, solve(n, m, d[i], d[j], d[k]));

	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
package main

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

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

var sc = bufio.NewScanner(os.Stdin)

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

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

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

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

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

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

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

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

	cnt := 0
	c := s[0]
	for i := 1; i < len(s); i++ {
		if c != s[i] {
			cnt++
		}
		c = s[i]
	}
	out(cnt)
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;cin>>s;
  if(s.front() == s.back()){
    if(s.size()%2){
      cout<<"Second"<<endl;
    }else{
      cout<<"First"<<endl;
    }
  }else{
    if(s.size()%2){
      cout<<"First"<<endl;
    }else{
      cout<<"Second"<<endl;
    }
  }
  return 0;
}


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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> a;
    a.push_back(0);
    for(int i=0;i<n;i++){
        int val;
        cin>>val;
        a.push_back(val);
    }
    a.push_back(0);
    long long ans=0ll;
    for(int i=1;i<n+2;i++){
        ans+=abs(a[i]-a[i-1]);
    }
    for(int i=1;i<n+1;i++){
        cout<<ans-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1])<<endl;
    }
    return 0;
}

Measured memory_bytes: 3912
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=200010;
const LL inf=(1LL<<60);
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
int n;LL d,a[Maxn];
struct Node{LL v;int x;Node(LL _v=0,int _x=0){v=_v;x=_x;}};
bool operator<(Node a,Node b){return a.v<b.v;}
struct Seg{int l,r,lc,rc,pos;Node p[5];}tr[Maxn<<1];
int tot;
void up(int x)
{
	int lc=tr[x].lc,rc=tr[x].rc;
	for(int i=0;i<5;i++)
	if(tr[lc].p[i]<tr[rc].p[i])
	{
		tr[x].p[i]=tr[lc].p[i];
		if(i==4)tr[x].pos=tr[lc].pos;
	}
	else
	{
		tr[x].p[i]=tr[rc].p[i];
		if(i==4)tr[x].pos=tr[rc].pos;
	}
	if(tr[lc].p[2].v!=inf&&tr[rc].p[1].v!=inf)
	{
		LL t=tr[lc].p[2].v+tr[rc].p[1].v;
		if(t<tr[x].p[4].v)tr[x].p[4]=Node(t,tr[lc].p[2].x),tr[x].pos=tr[rc].p[1].x;
	}
	if(tr[lc].p[0].v!=inf&&tr[rc].p[3].v!=inf)
	{
		LL t=tr[lc].p[0].v+tr[rc].p[3].v;
		if(t<tr[x].p[4].v)tr[x].p[4]=Node(t,tr[rc].p[3].x),tr[x].pos=tr[lc].p[0].x;
	}
}
void build(int l,int r)
{
	int x=++tot;
	tr[x].l=l;tr[x].r=r;
	for(int i=0;i<5;i++)tr[x].p[i]=Node(inf,0);
	if(l==r)
	{
		if(l!=1)
		{
			tr[x].p[0]=Node(a[l]-(LL)l*d,l);
			tr[x].p[1]=Node(a[l]+(LL)l*d,l);
			tr[x].p[2]=tr[x].p[3]=tr[x].p[4]=Node(inf,0);
		}
		else
		{
			tr[x].p[0]=tr[x].p[1]=tr[x].p[4]=Node(inf,0);
			tr[x].p[2]=Node(a[l]-(LL)l*d,l);
			tr[x].p[3]=Node(a[l]+(LL)l*d,l);
		}		
		return;
	}
	int mid=l+r>>1;
	tr[x].lc=tot+1,build(l,mid);
	tr[x].rc=tot+1,build(mid+1,r);
	up(x);
}
void modify(int x,int p)
{
	for(int i=0;i<5;i++)tr[x].p[i]=Node(inf,0);
	if(tr[x].l==tr[x].r)
	{
		int l=tr[x].l;
		tr[x].p[0]=tr[x].p[1]=tr[x].p[4]=Node(inf,0);
		tr[x].p[2]=Node(a[l]-(LL)l*d,l);
		tr[x].p[3]=Node(a[l]+(LL)l*d,l);
		return;
	}
	int mid=tr[x].l+tr[x].r>>1,lc=tr[x].lc,rc=tr[x].rc;
	if(p<=mid)modify(lc,p);
	else modify(rc,p);
	up(x);
}
int main()
{
	n=read(),d=read();
	for(int i=1;i<=n;i++)a[i]=read();
	build(1,n);
	int m=n-1;LL ans=0;
	while(m--)ans+=tr[1].p[4].v,modify(1,tr[1].pos);
	printf("%lld",ans);
}


Measured memory_bytes: 42496
def main():
    n, threshould = [int(x) for x in input().split()]
    count = 0
    for _ in range(n):
        x, y = [int(x) for x in input().split()]
        # 真偽値は 1 か 0 として足せる。
        count += (x ** 2 + y ** 2) <= threshould ** 2
    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9028
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

const int INF = 1000000000;
int w, h, cost[4], grid[35][35], dp[35][35][4];

void dfs(int y, int x, int dir, int currentcost){
  if(!CH(y,0,h) || !CH(x,0,w)) return;
  if(dp[y][x][dir] <= currentcost) return;
  dp[y][x][dir] = currentcost;
  if((x == w-1 && y == h-1)/* || grid[y][x] == 4*/) return;
  REP(k,0,5){
    if(k == 0){ //????????????
      switch (grid[y][x]) {
        case 0:
          dfs(y + dy[dir], x + dx[dir], dir, currentcost);
          break;
        case 1:
          dfs(y + dy[(dir + 1) % 4], x + dx[(dir + 1) % 4], (dir + 1) % 4, currentcost);
          break;
        case 2:
          dfs(y + dy[(dir + 2) % 4], x + dx[(dir + 2) % 4], (dir + 2) % 4, currentcost);
          break;
        case 3:
          dfs(y + dy[(dir + 3) % 4], x + dx[(dir + 3) % 4], (dir + 3) % 4, currentcost);
          break;
        case 4:
          //return;
          break;
        }
    }else{  //???????????????tk: 0 ~ 3????????????4(halt)???????????????
      int tk = k - 1;
      if(tk == grid[y][x]) continue;
      switch (tk) {
        case 0:
          dfs(y + dy[dir], x + dx[dir], dir, currentcost + cost[tk]);
          break;
        case 1:
          dfs(y + dy[(dir + 1) % 4], x + dx[(dir + 1) % 4], (dir + 1) % 4, currentcost + cost[tk]);
          break;
        case 2:
          dfs(y + dy[(dir + 2) % 4], x + dx[(dir + 2) % 4], (dir + 2) % 4, currentcost + cost[tk]);
          break;
        case 3:
          dfs(y + dy[(dir + 3) % 4], x + dx[(dir + 3) % 4], (dir + 3) % 4, currentcost + cost[tk]);
          break;
        }
    }
  }
  return;
}

int main() {

  while(1){
    cin>>w>>h;
    if(w==0 && h==0) break;
    REP(i,0,h){
      REP(j,0,w){
        cin>>grid[i][j];
      }
    }
    REP(k,0,4) cin>>cost[k];
    //memset(dp, INF, sizeof(dp));
    REP(i,0,h)REP(j,0,w)REP(k,0,4) dp[i][j][k] = INF;

    dfs(0, 0, 0, 0);

    cout<<*min_element(dp[h-1][w-1], dp[h-1][w-1]+4)<<endl;
  }

  return 0;
}

Measured memory_bytes: 3296
#include <iostream>
#include <cstdio>
#include <cctype>
#define il inline
#define vd void
#define rg register
#define mn 605
#define rep(i,x,y) for(rg int i=x;i<=y;++i)
#define drp(i,x,y) for(rg int i=x;i>=y;--i)
using namespace std;
const int Len=2333333;
char buf[Len],*p1=buf,*p2=buf,duf[Len],*q1=duf;
il char gc(); il int rd(); il vd pc(char c); il vd rt(int x); il vd flush();
template<class T> il T Max(T a,T b){return a>b?a:b;}
template<class T> il T Min(T a,T b){return a<b?a:b;}
int n,m,u,v,cnt,h[mn],d[mn];
double ans,dp[mn];
struct E{int to,nxt;}e[180005];
il vd Add(int u,int v){e[++cnt]=(E){v,h[u]},h[u]=cnt;}
il double F(int x){
	drp(i,n-1,1){
		dp[i]=0.0;
		double m=0.0;
		for(rg int j=h[i];j;j=e[j].nxt){int v=e[j].to;
			dp[i]+=dp[v],
			m=Max(m,dp[v]);
		}
		if(i==x) (dp[i]-=m)/=(double)(d[i]-1);
		else dp[i]/=(double)d[i];
		++dp[i];
	}
	return dp[1];
}
int main(){
	n=rd(),m=rd();
	while(m--) u=rd(),v=rd(),Add(u,v),++d[u];
	ans=F(0);
	rep(i,1,n) if(d[i]>1) ans=Min(ans,F(i));
	printf("%.7lf",ans);
	return flush(),0;
}

il char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,Len,stdin),p1==p2)?-1:*p1++;}
il int rd(){char c;
	while(!isdigit(c=gc())&&c!='-');
	int f=c=='-'?c=gc(),1:0,x=c^48;
	while(isdigit(c=gc())) x=((x+(x<<2))<<1)+(c^48);
	return f?-x:x;
}
il vd pc(char c){q1==duf+Len&&fwrite(q1=duf,1,Len,stdout),*q1++=c;}
il vd rt(int x){x<0?pc('-'),x=-x:0,pc((x>=10?rt(x/10),x%10:x)+48);}
il vd flush(){fwrite(duf,1,q1-duf,stdout);}

Measured memory_bytes: 4608
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8
#define MAX_N 200000

using namespace std;
typedef pair<llong, llong> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

llong N, K;
llong A[MAX_N], F[MAX_N];

ipair AF[MAX_N];


template<typename T1, class Tlambda>
T1 super_lower_bound(T1 left, T1 right, Tlambda test, double eps = 1e-8) {

    while(abs(right - left) > eps) {
        T1 mid = left + (right - left) / 2;

        if(test(mid))
            right = mid;
        else
            left = mid + 1;
    }

    return left;
}

template<typename T1, typename T2>
T1 lower_bound_dec(T1 left, T1 right, T2 (*func)(T1), T2 val, double eps = 1e-8) {
    return super_lower_bound<T1>(
        left, 
        right, 
        [func, val](T1 x){ return func(x) <= val; }, 
        eps);
}

llong f(llong x) {
    llong sum = 0;
    for(int i = 0; i < N; ++i)
        if(AF[i].first > x)
            sum += ceil((double)(AF[i].first - x) / AF[i].second);
    return sum;
}

llong solve() {
    //f(x) <= K の範囲でxを最小化する．
    //f(x) : 単調減少
    llong res = lower_bound_dec<llong, llong>(0, 1e12 + 1, f, K);
    return res;
}

int main(int argc, char **argv) {
    cin >> N >> K;
    for(int i = 0; i < N; ++i) cin >> A[i];
    for(int i = 0; i < N; ++i) cin >> F[i];
    
    sort(A, A + N);
    sort(F, F + N);
    reverse(A, A + N);

    for(int i = 0; i < N; ++i)
        AF[i] = make_pair(A[i] * F[i], F[i]);
    
    cout << solve() << endl;
}

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

int main() {
  int n, d, x;
  cin >> n >> d >> x;
  for (int i = 1; i <= n; i++) {
    int t;
    cin >> t;
    for (int j = 1; j <= d; j += t)
      x++;
  }
  cout << x << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
    public static void main(String args[])throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        int i=1;
        while(true){
            int x = Integer.parseInt(br.readLine());
            if(x == 0) break;
            sb.append("Case");
            sb.append(" ");
            sb.append(Integer.toString(i++));
            sb.append(":");
            sb.append(" ");
            sb.append(Integer.toString(x));
            sb.append("\n");
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 26708
#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>;

int main() {
  vector<vector<int>> a(3, vector<int>(3));
  rep(i, 3) rep(j, 3) cin >> a[i][j];
  int n;
  cin >> n;
  vector<int> b(n);
  rep(i, n) cin >> b[i];
  
  bool bingo = false;
  int s;
  rep(i, n) rep(j, 3) rep(k, 3) if (b[i] == a[j][k]) a[j][k] = 0;
  rep(i, 3) {
    s = 0;
    rep(j, 3) s += a[i][j];
    if (s == 0) bingo = true;
    s = 0;
    rep(j, 3) s += a[j][i];
    if (s == 0) bingo = true;
  }
  s = 0;
  rep(i, 3) s += a[i][i];
  if (s == 0) bingo = true;
  s = 0;
  rep(i, 3) s += a[i][2-i];
  if (s == 0) bingo = true;
  if (bingo) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3552
#include <iostream>

using namespace std;

int main()
{
    long int X, A, B, n, x;
    cin >> X;
    n = 100;
    for(int i = 0; i <= n; i++){
        for(int j = i; j <= n; j++){
            A = i;
            B = j;
            x = A * A * A * A * A + B * B * B * B * B;
            if (x == X){
                cout << A << " " << -B;
                goto Exit;
            }
        }
    }
    for(int i = 0; i <= n * 10; i++){
        for(int j = i; j <= n * 10; j++){
            A = j;
            B = i;
            x = A * A * A * A * A - B * B * B * B * B;
            if (x == X){
                cout << A << " " << B;
                goto Exit;
            }
        }
    }
    Exit: ;
}

Measured memory_bytes: 3636
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		boolean bl = true;
		int n = 1;
		int x;
		while(bl){
			x = stdIn.nextInt();
			if(x == 0) break;
			System.out.println("Case " + n + ": " + x);
			n++;
		}
	}

}

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

#define ll long long
#define eb emplace_back
#define fi first
#define se second

using namespace std;

const int nm = 10002;

ll f[nm];

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	ll n;
	cin >> n;
	for (ll x = 1; x * x <= n; ++x) {
		for (ll y = 1; y * y <= n; ++y) {
			for (ll z = 1; z * z <= n; ++z) {
				ll tmp = x * x + y * y + z * z + x * y + y * z + z * x;
				if (tmp <= n) {
					f[tmp]++;
				}
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		cout << f[i] << "\n";
	}
}


Measured memory_bytes: 3640