akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 1e5 + 2;

int n, l, t, pos[N], dir[N];
vector<int>pos_set;
int shift;
void intersect(int idx) {
	int diff, res;
	if (dir[0] == 1) {
		diff = pos[idx] - pos[0];
		if (dir[idx] == -1) {
			int val = 2 * t - diff;
			if (val >= 0) {
				shift += 1 + val / l;
				shift %= n;
			}
		}
	}
	else {
		if (dir[idx] == 1) {
			diff = l - pos[idx] + pos[0];
			int val = 2 * t - diff;
			res = 1 + val / l;
			if (val >= 0) {
				shift += res;
				shift %= n;
			}
		}
	}
}

int32_t main() {
	//freopen("oj.in", "r", stdin);
	cin >> n >> l >> t;
	int v0 = 0;
	for (int i = 0; i < n; ++i) {
		cin >> pos[i] >> dir[i];
		if (dir[i] == 2)dir[i] = -1;
		int ad = (l + pos[i] + (t % l) * dir[i]) % l;
		if (!i) v0 = ad;
		pos_set.push_back(ad);
	}
	for (int i = 1; i < n; ++i)
		intersect(i);
	int start = 0;
	if (dir[0] == -1)
		shift=(n-shift)%n;
	sort(pos_set.begin(), pos_set.end());
	for (int i = 0; i < pos_set.size(); ++i) {
		if (pos_set[i] == v0) {
			rotate(pos_set.begin(), pos_set.begin() + i, pos_set.end());
			break;
		}
	}
	if (dir[0] == 1 && pos_set[0] == pos_set[1])
		rotate(pos_set.begin(), pos_set.begin() + 1, pos_set.end());
	vector<int>ans(n);
	for (int i = 0; i < pos_set.size(); ++i) {
		ans[(i + shift) % n] = pos_set[i];
	}
	for (int i = 0; i < n; ++i) {
		cout << ans[i] << '\n';
	}
}


Measured memory_bytes: 4468
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
typedef pair <int, int> P;

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

    int n;
    cin >> n;

    vector <P> vec(n);
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        vec[i] = P(b, a);
    }

    sort(vec.begin(), vec.end());

    bool f = true;
    int tmp = 0;
    for (int i = 0; i < n; i++) {
        tmp += vec[i].second;
        if (tmp > vec[i].first) {
            f = false;
            break;
        }
    }

    cout << (f ? "Yes" : "No") << "\n";
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
int N;
cin >> N;
vector<double> vec(N);
double count = 0;
for (int i = 0;i < N;i++) {
    double a;
    cin >> vec.at(i);
    a = 1/vec.at(i);
    count += a;
}
count = 1/count;
cout << count << endl;

return 0;
}


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

using namespace std;

const int MAXN = 100;
bool isBlack[MAXN][MAXN];
int dp[MAXN][MAXN];

int main()
{
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            char c;
            cin >> c;
            isBlack[i][j] = c == '#';
        }
    }
    dp[0][0] = isBlack[0][0];
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (i == 0 && j == 0)
                continue;
            dp[i][j] = MAXN * MAXN * MAXN;
            if (i - 1 >= 0)
            {
                if (isBlack[i][j] && !isBlack[i - 1][j])
                    dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
                else
                    dp[i][j] = min(dp[i][j], dp[i - 1][j]);
            }
            if (j - 1 >= 0)
            {
                if (isBlack[i][j] && !isBlack[i][j - 1])
                    dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
                else
                    dp[i][j] = min(dp[i][j], dp[i][j - 1]);
            }
            //cout << i << " " << j << " " << dp[i][j] << endl;
        }
    }
    cout << dp[h - 1][w - 1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <cstring>
#include <string>
#include <tuple>
#include <climits>
#include <cmath>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
const int INF = 987654321;
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
char arr[10][10];
int n,m,k;
int cache[10000];
int dfs(int bit,int cnt){
    //printf("%u %d\n",bit, cnt);
    int& ret = cache[bit];
    if(cnt == k)
        ret = 1;
    else
        ret = 0;
    for(int i = 0;i<n;i++){
        if(bit& (1<<i))
            continue;
        int tmp = bit | (1<<i);
        //cout << tmp << endl;
        if(cache[tmp] != -1)
            continue;
        int tot = 0;
        for(int j = 6;j<m+6;j++)
            if((!(bit&(1<<j))) && arr[i][j-6] == '#')
                tot++;
        ret += dfs(tmp,cnt-tot);
    }
    for(int i = 6;i<m+6;i++){
        if(bit & (1<<i))
            continue;
        int tmp = bit | (1<<i);
        if(cache[tmp] != -1)
            continue;
        int tot = 0;
        for(int j = 0;j<n;j++)
            if((!(bit&(1<<j))) && arr[j][i-6] == '#')
                tot++;
        ret += dfs(tmp,cnt-tot);
    }
    return ret;
}
int main(){
    cin >> n >> m >> k;
    for(int i = 0;i<n;i++){
        cin>>arr[i];
    }
    int cnt = 0;
    for(int i = 0;i<n;i++){
        for(int j = 0;j<m;j++){
            if(arr[i][j] == '#')
                cnt++;
        }
    }
    for(int i = 0;i<10000;i++)
        cache[i] = -1;
    cout << dfs(0,cnt) << endl;
}

Measured memory_bytes: 3680
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

#define INF 1010001000
#define EPS 1e-10
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef pair<int, int> i_i;
typedef long long int llong;
typedef pair<llong, llong> ll_ll;
typedef struct edge {int f, t;}Edge;


int main()
{
    int n;
    while (cin >> n, n) {
        vector<int> data(n);
        rep(i, n) {
            cin >> data[i];
        }
        sort(data.begin(), data.end());
        int ans = 1010001000;
        rep(i, n-1) {
            ans = min(ans, data[i+1] - data[i]);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
struct edge {int to,cost;};
typedef pair<int,int> P;
const int MAX_V=100000,INF=1000000000;
vector<edge>G[MAX_V];
int d[MAX_V];
int N,X,Y;

void dijkstra(int s){
  fill(d,d+N,INF);
  d[s]=0;
  priority_queue<P,vector<P>,greater<P>>q;
  q.push(P(0,s));
  while(!q.empty()){
    P p=q.top();q.pop();
    int v=p.second;
    if(d[v]<p.first)continue;
    for(int i=0;i<(int)G[v].size();i++){
      edge e=G[v][i];
      if(d[e.to]>d[v]+e.cost){
        d[e.to]=d[v]+e.cost;
        q.push(P(d[e.to],e.to));
      }
    }
  }
}

int main(){
  scanf("%d %d %d",&N,&X,&Y);
  for(int i=0;i<N-1;i++){
    edge e;
    e.to=i+1;e.cost=1;
    G[i].push_back(e);
    e.to=i;
    G[i+1].push_back(e);
  }
  X--;Y--;
  edge e;
  e.to=Y;
  e.cost=1;
  G[X].push_back(e);
  e.to=X;
  G[Y].push_back(e);
  map<int,int>cnt;
  for(int i=0;i<N;i++){
    dijkstra(i);
    for(int j=i+1;j<N;j++)cnt[d[j]]++;
  }
  for(int k=1;k<N;k++)cout<<cnt[k]<<endl;
  return 0;
}


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


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

    int ans;
    if (A == 1) {
        if (B == 2) {
            ans = 3;
        } else {
            ans = 2;
        }
    }

    if (A == 2) {
        if (B == 1) {
            ans = 3;
        } else {
            ans = 1;
        }
    }

    if (A == 3) {
        if (B == 2) {
            ans = 1;
        } else {
            ans = 2;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int N;
int counter(int bit){
    if(bit == 0) return 0;
    int cnt = 0;
    for(int i = 0; i < N; i++)if(bit & (1 << i)) cnt++;
    return cnt;
}

int main(){
    cin >> N;
    vector<vector<pair<int,int>>> T(N);
    for(int i = 0; i < N; i++){
        int A;
        cin >> A;
        T[i].resize(A);
        for(int j = 0; j < A; j++){
            cin >> T[i][j].fi >> T[i][j].se;
        }
    }
    int max_n = 0;
    for(int bit = 0; bit < (1 << N); bit++){
        bool ok = true;
        for(int i = 0; i < N; i++){
            if(!(bit & (1 << i))) continue;
            for(int j = 0; j < (int)T[i].size(); j++){
                if(((bit >> (T[i][j].fi - 1)) & 1) ^ T[i][j].se) ok = false;
            }
        }
        if(ok) max_n = max(max_n, counter(bit));
    }
    cout << max_n << endl;
}

Measured memory_bytes: 256
def main():
    s = input()
    k = int(input())
    n = len(s)
    ans = set()
    for i in range(n):
        for j in range(i+1, i+k+1):
           ans |= {s[i:j]}
    print(list(sorted(ans))[k-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 4600
// import std = require('tstl')

{
  type Print = void | string | number | string[] | number[]
  let outs: Print[] = []

  const main = (): Print => {
    const r = _io()
    const [a, av] = r.nn()
    const [b, bv] = r.nn()
    const [T] = r.nn()

    const d = Math.abs(a - b)
    const vd = av - bv

    if (vd <= 0) return 'NO'
    // 5 3
    return d / vd <= T ? 'YES' : 'NO'
  }

  const _io = (i = 0) => {
    const str = require('fs').readFileSync('/dev/stdin', 'utf8')
    const lines = str.trim().split('\n')
    const s = () => lines[i++] || ''
    const n = () => Number(s())

    const mn = (v: string[]) => v.map(Number)
    const sp = (v: string) => v.split(' ')

    const ss = () => sp(s())
    const nn = () => mn(ss())
    const nls = () => mn(lines.slice(i))
    const nnls = () => lines.slice(i).map((v) => mn(sp(v)))

    return { lines, s, n, ss, nn, nls, nnls }
  }

  outs.push(main())

  console.log(
    outs
      .map((line) => (typeof line === 'object' ? line.join(' ') : String(line)))
      .join('\n')
  )
}


Measured memory_bytes: 29632
#include<iostream>
#include<string>
using namespace std;
int main(){
string w;
string t;
cin >> w;
int i;
for(i=0;i<w.size();i++) {
  if('A'<=w[i]&&w[i]<='Z') w[i]+='a'-'A';
}
int o=0;
cin >> t;
while(t!="END_OF_TEXT"){

  for(i=0;i<t.size();i++) {
    if('A'<=t[i]&&t[i]<='Z') t[i]+='a'-'A';
  }
  if(w==t) o++;
  cin >> t;
}
cout << o << endl;
}


Measured memory_bytes: 3224
#include <iostream>
#include <string>
using namespace std;
int main() {
  int r,d,x;
  int sum=0;
    cin>>r>>d>>x;
    for(int i=1;i<=10;i++){
        x=r*x-d;
sum=x;
            cout<<sum<<endl;}

    return 0;
}

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

int main() {
  string S;
  cin >> S;
  int ans = 0;
  for(int i=0; i<S.size()-1; i++){
    if(S.at(i) != S.at(i+1)){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

struct S {
    ll id;
    string name;
    ll score;
    
    bool operator<(const S &b) {
        if (name == b.name) {
            return score > b.score;
        }
        return name < b.name;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<S> vs(n);
    rep(i, n) {
        cin >> vs[i].name >> vs[i].score;
        vs[i].id = i;
    }
    sort(all(vs));
    rep(i, n) printf("%lld\n", vs[i].id + 1);
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define F first
#define S second
//#define biGinf 9e+18
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define inpv(v) for(auto &x:v) cin>>x
#define otpv(v) for(auto &x:v) cout<<x<<nwl
#define otpv2(v) for(auto &x:v) cout<<x<<" "
#define CASES int tt;cin>>tt; while(tt--)
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define forr(i,r,n) for(int i=r; i<=n; i++)
#define forj(j,n) for(int j=n; j>=0; j--)
#define forx(x,v) for(auto &x:v)
#define sz(v) (int)(v).size()
#define rz(n) resize(n)
#define vec(x) vector < x >
using int64 = long long;
using vi = vector < int >;
using vi64 = vector < int64 >;
using mii = map <int , int >;
using vvi = vector < vi >;
using pii = pair < int , int >;
using vpii = vector < pii >;
const int inf = 2e9 + 7;
const char nwl = '\n';
const int mxx = 1e6 + 3;
int64 sumV(vi &v) {
	int64 s = 0;
	for (int x : v) {
		s += (int64)x;
	}
	return s;
}
int gcd(int a, int b) {
	if (!b) return a;
	return gcd(b, a % b);
}
//const int64 biGinf = 9e+18;
//const string yo = "Yes\n", no = "No\n";
int arr[mxx];

void fctr(int x) {
	if (x % 2 == 0) {
		arr[2] += 1;
		while (x % 2 == 0) x /= 2;
	}
	for (int i = 3; i <= sqrt(x); i = i + 2) {
		if (x % i == 0) {
			arr[i]++;
			while (x % i == 0)x /= i;
		}
	}
	if (x > 2)
		arr[x]++;
}


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

	int n;
	cin >> n;
	vi v(n);
	inpv(v);
	int d = 0;
	forx(x, v) {
		d = max(d, x);
		fctr(x);
	}
	bool f = 0;
	for (int i = 2; i <= d; i++) {
		if (arr[i] == n) {
			f = 1;
			break;
		}
	}
	if (f) {
		cout << "not coprime";
	} else {
		f = 0;
		for1(i, d) {
			arr[i] = 0;
		}
		for (int i = n - 1; i >= 0; i--) {
			int x = v[i];
			if (x % 2 == 0) {
				if (arr[2]) f = 1;
				else arr[2] = 1;
				while (x % 2 == 0) x /= 2;
			}
			for (int i = 3; i <= sqrt(x); i = i + 2) {
				if (x % i == 0) {
					if (arr[i]) f = 1;
					else arr[i] = 1;
					while (x % i == 0) x /= i;
				}
			}
			if (x > 2) {
				if (arr[x]) f = 1;
				else arr[x] = 1;
			}
			if (f) break;
		}
		if (f) cout << "setwise coprime";
		else cout << "pairwise coprime";
	}





	return 0;
}


Measured memory_bytes: 11020
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;

int main(){
    string com;
    ll n;
    priority_queue<ll> q;
    while(1){
        cin >> com;
        if(com == "end")break;
        if(com == "insert"){
            cin >> n;
            q.push(n);
        }
        else {
            cout << q.top() << endl;
            q.pop();
        }
    }    
    return 0;
}


Measured memory_bytes: 11240
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(max(a,b)>=9)
	{
		cout<<":("<<endl;
	}
	else
	{
		cout<<"Yay!"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const A = parseInt(arg[0].split(" ")[0]);
    const B = parseInt(arg[0].split(" ")[0]);
    const M = parseInt(arg[0].split(" ")[0]);
    
    const freezer = arg[1].split(" ").map(n=>parseInt(n));
    const renzi   = arg[2].split(" ").map(n=>parseInt(n));
    
    const xyc = arg.slice(3, M + 4);
    
    const minFreeze = Math.min(...freezer);
    const minRenzi = Math.min(...renzi);
    
    let temp = minFreeze + minRenzi;
    
    for(let i in xyc) {
        let x = parseInt(xyc[i].split(" ")[0]);
        let y = parseInt(xyc[i].split(" ")[1]);
        let c = parseInt(xyc[i].split(" ")[2]);
        
        let cost = freezer[x-1] + renzi[y-1] - c;
        
        if(cost <= temp) {
            temp = cost;
        }
    }
    
    console.log(temp);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 59520
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
typedef long long ll;
const int INF = 1e9;
const ll LLINF = 1e18;

int main() {
    int N, x;
    cin>>N>>x;
    
    int nums[N+5], nums2[N+5];
    rep(i,N){
        int x;
        cin>>x;
        nums[i]=x;
        nums2[N-1-i]=x;
    }
    
    ll cnt=0;
    if(nums[0]>x){
        cnt += nums[0]-x;
        nums[0] = x;
    }
    
    rep(i,N-1){
        if(nums[i]+nums[i+1]>x){
            cnt += nums[i]+nums[i+1]-x;
            nums[i+1] -= nums[i]+nums[i+1]-x;
        }
    }
    
    ll cnt2=0;
    if(nums2[0]>x){
        cnt2 += nums2[0]-x;
        nums2[0] = x;
    }
    
    rep(i,N-1){
        if(nums2[i]+nums2[i+1]>x){
            cnt2 += nums2[i]+nums2[i+1]-x;
            nums2[i+1] -= nums2[i]+nums2[i+1]-x;
        }
    }
    cout1(min(cnt,cnt2));
}

Measured memory_bytes: 1024
#include <stdio.h>
int main()
{
    int a,b,c;
    char n;
    scanf("%d",&a);
    getchar();
    scanf("%c",&n);
    getchar();
    scanf("%d",&b);
    if(n=='+')
    {
        c=a+b;

        printf("%d",c);
    }
    else
    {
        c=a-b;

        printf("%d", c);
    }
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5;
signed main()
{
    int n;
    cin>>n;
    int c=n;
    if(n==1)
        cout<<'a'<<endl;
    else{
    int anx=n;
    string s="";
    int o=1;
    while(anx>0)
    {
        s+='a';
    anx-=pow(26,o++);
    }
    int sum=0;
    int flag=0;
    while(n>0)
    {
        int c=n%26-1;
        if(c<0)
            c=25;
        s[s.size()-1-sum]+=c;
        sum++;
        n=(n-1)/26;
    }
    cout<<s<<"\n";
}}


Measured memory_bytes: 4088
import java.util.Scanner;

public class Main{
	 static int N,M;
	 static int []candle;
	 static int minLength;
	 public static void main(String[] args) {
		 Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        candle = new int[N];
        int position = 0;
        int flagLength = Integer.MAX_VALUE;
        for(int i=0;i<N;i++) {
        	candle[i] = sc.nextInt();
        	if(candle[i]<0) {
        		position++;
        	}
        }
        
        if(M!=0){
    		int low = 0;
    		int high = 0;
    		int totalHandle;
    		int minLengthTemp = 0;
    		//判断下位
    		if(position-M<0){
    			low = 0;
    		}else{
    			low =  position - M;
    		}
    		//判断上位
    		if(position+M-1>=candle.length){
    			high = candle.length-1;
    		}else{
    			high = position+M-1;
    		}
    		//确定循环次数
    		if(candle.length>position){
    			totalHandle = position+1;
    		}else{
    			totalHandle = position;
    		}
    		
    		for(int i = low; i < totalHandle; i++) {	
    			int handleHigh = i+M-1;
    			int down = 0;
    			int up = 0;
    			if(handleHigh>high){
    				break;
    			}
    			
    			if(i < position) {
    				down = candle[i];
				}				
				
				if(handleHigh >= position) {
					up = candle[handleHigh];
				}
    			
    			minLengthTemp = lengthCandle(down,up);
    			
    			if(minLengthTemp<flagLength) {
    				flagLength = minLengthTemp;
    			}
    		}
    		
    		minLength = flagLength;
        		
        }else{
        	minLength = 0;
        }
        
        System.out.println(minLength);
        sc.close();
	 }
	 
	 private static int distanceV(int a,int b) {
        int dis = Math.abs(a-b);
        return dis;
	 }
	 
	 private static int lengthCandle (int minCandle,int maxCandle) {
	        int length = 0;
	        if(minCandle>=0 && maxCandle>=0) {
	            length = distanceV(0,maxCandle);
	        }else if(minCandle<0 && maxCandle>=0){
	            int minCandleDistance = distanceV(0,minCandle);
	            int maxCandleDistance = distanceV(0,maxCandle);
	            if(minCandleDistance <= maxCandleDistance) {
	                length = 2*minCandleDistance+maxCandleDistance;
	            }else {
	                length = minCandleDistance+maxCandleDistance*2;
	            }
	        }else {
	            length = distanceV(minCandle,0);
	        }
	        return length;
	    }
}




Measured memory_bytes: 50836
/* Author rumoisen */
/* created 2018/11/08 */

#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <iostream>

using namespace std;
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

void no(){cout<<"No"<<endl;exit(0);}
void yes(){cout<<"Yes"<<endl;exit(0);}
void No(){cout<<"NO"<<endl;exit(0);}
void Yes(){cout<<"YES"<<endl;exit(0);}

using namespace std;

int main(void)
{
    string n;
    cin>>n;
    if(n[0]==n[1]&&n[1]==n[2]) yes();
    else if(n[1]==n[2]&&n[2]==n[3]) yes();
    else no();
    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 11451419194545;

int main(){

    ll N, T; cin >> N >> T;

    vector<pi> AB;

    for(ll i = 0; i < N; i++){
        ll A, B; cin >> A >> B;
        AB.push_back(make_pair(A, B));
    }

    sort(AB.begin(), AB.end());

    vector<vector<ll > > dp(N+1010, vector<ll >(T+3010, 0));
    dp[0][0] = 0;

    ll ans = -1;
    for(ll i = 0; i < N; i++){
        for(ll j = 0; j <= T-0.5; j++){
            if(dp[i][j] != -1){
                dp[i+1][j] = max(dp[i][j], dp[i+1][j]);
                dp[i+1][j+AB[i].first] = max(dp[i][j]+AB[i].second, dp[i+1][j+AB[i].first] );
                ans = max(ans, dp[i+1][j+AB[i].first]);
            }
        }
    }
    cout << ans << endl;
}

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

int six[6] = {6, 36, 216, 1296, 7776, 46656};
int nine[5] = {9, 81, 729, 6561, 59049};

int func(int num, int ans){
    if(num <= 8) return ans + num / 6 + num % 6;
    int i6, i9;
    i6 = (int)(upper_bound(six, six + 6, num) - six) - 1;
    i9 = (int)(upper_bound(nine, nine + 5, num) - nine) - 1;
    ans++;
    return min(func(num - six[i6], ans), func(num - nine[i9], ans)); 
} 

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

    int n;
    cin >> n;

    cout << func(n, 0) << endl;

    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============

int main()
{
    int X, Y;
    cin >> X >> Y;
    rep(turtle, X + 1) {
        int crane = X - turtle;
        int foot = crane * 2 + 4 * turtle;
        if (foot == Y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3612
n = gets.to_i
a = gets.split.map(&:to_i)
f = 0
cnt = 1
0.upto(n - 2) do |i|
  if a[i] < a[i + 1]
    if f == -1
      cnt += 1
      f = 0
    else
      f = 1
    end
  elsif a[i] > a[i + 1]
    if f == 1
      cnt += 1
      f = 0
    else
      f = -1
    end
  end
end
puts cnt

Measured memory_bytes: 8452
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)

int main(){
    ll N, K;
    vector<ll> A;
    ll res = 0, resN = 0, sumK=0;
    cin >> N >> K;
    rep(i,0,N){
        ll temp;
        cin >> temp;
        A.pb(temp);
    }
    sumK = ((K * (K + 1))/2)%1000000007;
    ll sumK_1 = ((K * (K - 1))/2)%1000000007;
    rep(i, 0, N)
    {
        ll temp = A[i];
        rep(j,0,N){
            if(temp > A[j] && j < i){
                //二週目以降考える
                resN++;
            }
            else if(temp > A[j] && j>i){
                //一週目以降
                res++;
            }
        }
    }
  
    res = sumK * res;
    resN = sumK_1 * resN;
    cout << (res + resN) % 1000000007 << endl;
}

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

int main(void)
{
    using namespace std;
    string W, T;
    cin >> W;

    int cnt = 0;
    while (true) {
        cin >> T;
        if (T == "END_OF_TEXT") {
            break;
        }
        transform(T.begin (), T.end (), T.begin (), ::tolower);

        if (W == T) {
            cnt++;
        }

    }

    printf("%d\n", cnt);
    return 0;
}


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

int main() {
    string x;
    cin >> x;
    int len = x.length();
    int min = 1000;

    for (int i = 0; i < len - 2; i++) {
        int diff = abs(753 - (100 * (x[i] - '0') + 10 * (x[i + 1] - '0') +
                              (x[i + 2] - '0')));
        if (diff < min) {
            min = diff;
        }
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag, D; vll path;
//***********//
int main() {

	cin >> N;
	ll A = N % 10;
	if (A == 0 || A == 1 || A == 6 || A == 8) cout << "pon";
	else if (A == 3) cout << "bon";
	else cout << "hon";
}

Measured memory_bytes: 3676
//fold
#ifndef KHALIL
#include <bits/stdc++.h>
#else
#include "header.h"
#endif
#define endl '\n'
#define mp make_pair
#define tostr(x) static_cast<ostringstream&>((ostringstream()<<dec<<x)).str()
#define rep(i,begin,end) for(auto i = begin;i < end;i++)
#define repr(i,begin,end) for(auto i = begin-1;i >= end;i--)
#define pb push_back
#define sz(a) ((int)(a).size())
#define fi first
#define se second
#define abs(a) ((a) < (0) ? (-1)*(a) : (a))
#define SQ(a) ((a)*(a))
#define eqd(a,b) (abs(a-b)<1e-9)
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename t> t in(t q){cin >> q;return q;}
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v){os << "[";for (int i = 0; i < sz(v); ++i) { os << v[i]; if (i != sz(v) - 1) os << ",";}os << "]";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const map<T, S>& v){for (auto it : v)os << "(" << it.first << ":" << it.second << ")";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const pair<T, S>& v){os << "(" << v.first << "," << v.second << ")";return os;}
const long double PI = acosl(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
//endfold
#define  N  (200'005)
#define MOD (1'000'000'007ll)
#define OO (1'050'000'000)
#define OOL (1'100'000'000'000'000'000ll)

//global
ll x[N];
ll y[N];

int main(){
	//fold
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << setprecision(10);
	//endfold
	ll n;
	cin >> n;
	map<pair<ll,ll>,ll> m;
	rep(i,0,n){
		cin >> x[i] >> y[i];
	}
	rep(i,0,n){
		rep(j,0,i){
			pair<ll,ll> w = {x[i]-x[j],y[i]-y[j]};
			if(w.first < 0){
				w.first *= -1;
				w.second *= -1;
			}
			if(w.first == 0 && w.second < 0){
				w.second *= -1;
			}
			m[w]++;
		}
	}
	ll mx = 0;
	for(auto e:m){
		mx = max(mx,e.second);
	}
	cout << n-mx << endl;
	return 0;
}

Measured memory_bytes: 384
package main

import (
	"fmt"
	"log"
)


const (
	MinN int = 2
	MaxN int = 8
)

var (
	ErrN      = fmt.Errorf("%d≤N≤%d", MinN, MaxN)
	ErrLength = fmt.Errorf("%s", "P, Q は⼤きさ N の順列である")
)

type Solution struct {
	N    int
	P, Q []int
}

func New(N int, P, Q []int) *Solution {
	return &Solution{
		N: N,
		P: P,
		Q: Q,
	}
}

func (s *Solution) Validate() error {
	if !s.inRange(s.N, MinN, MaxN) {
		return ErrN
	}
	if len(s.P) != s.N {
		return ErrLength
	}
	if len(s.Q) != s.N {
		return ErrLength
	}
	return nil
}

func (s *Solution) Distance() int {
	num := make([]int, 0)
	for i := 1; i <= s.N; i++ {
		num = append(num, i)
	}
	table := s.permute(num)
	p, _ := s.indexOf(s.P, table)
	q, _ := s.indexOf(s.Q, table)
	return s.abs(p - q)
}

func (s *Solution) permute(num []int) [][]int {
	if len(num) == 0 {
		return nil
	}
	if len(num) == 1 {
		return [][]int{num}
	}
	result := make([][]int, 0)
	// For instance, num = [1, 2, 3]
	// pick 1:
	// 1 + permute([2, 3])
	// => 1 + [[2, 3], [3, 2]]
	// => [[1, 2, 3], [1, 3, 2]]
	// pick 2:
	// 2 + permute([1, 3])
	// => 2 + [[1, 3], [3, 1]]
	// => [2, 1, 3], [2, 3, 1]]
	// etc.
	for i := 0; i < len(num); i++ {
		picked, remain := s.pick(num, i)
		children := s.permute(remain)
		for _, list := range children {
			result = append(result, append([]int{picked}, list...))
		}
	}
	return result
}

func (s *Solution) abs(v int) int {
	if v < 0 {
		return -v
	}
	return v
}

func (s *Solution) indexOf(target []int, table [][]int) (int, bool) {
	for i, list := range table {
		if s.equal(list, target) {
			return i, true
		}
	}
	return -1, false
}

func (s *Solution) equal(a, b []int) bool {
	if len(a) != len(b) {
		return false
	}
	for i, v := range a {
		if v != b[i] {
			return false
		}
	}
	return true
}

func (s *Solution) pick(num []int, i int) (int, []int) {
	picked := num[i]
	remain := append([]int{}, num[:i]...)
	remain = append(remain, num[i+1:]...)
	return picked, remain
}

func (s *Solution) inRange(x, min, max int) bool {
	return x >= min && x <= max
}


func main() {
	var n int
	_, _ = fmt.Scanf("%d", &n)
	p := make([]int, 0, n)
	for i := 0; i < n; i++ {
		var x int
		_, _ = fmt.Scanf("%d", &x)
		p = append(p, x)
	}
	q := make([]int, 0, n)
	for i := 0; i < n; i++ {
		var x int
		_, _ = fmt.Scanf("%d", &x)
		q = append(q, x)
	}

	var s Solution
	s.N = n
	s.P = p
	s.Q = q

	if err := s.Validate(); err != nil {
		log.Fatalln(err)
	}
	fmt.Printf("%d", s.Distance())
}


Measured memory_bytes: 11308
/**
*    author:  yuya1234
*    created: 27.06.2020 20:57:50
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define ALL(x) x.begin(),x.end()
#define SORT(x) sort(x.begin(),x.end())
#define SORTD(x) sort(x.rbegin(),x.rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define SZ(x) ll(x.size())

#define MEMSET(v, h) memset((v), h, sizeof(v))

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

  int a;
  cin>>a;

  cout<<a+a*a+a*a*a<<endl;

  return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>

int main(void)
{       
        int a,b,c;
        scanf("%d",&a);
        scanf("%d",&b);
        scanf("%d",&c);
        int d,e;
        d=a-b;
        e=c-d;
        if(e<0){
                printf("0");
        }else{
                printf("%d",e);
        }
        return 0;
}


Measured memory_bytes: 128
import collections
n,m = map(int, input().split())
hy = map(int, input().split())
h = list(hy)
count = [0]*n
for _ in range(m):
    a,b = map(int, input().split())
    if h[a-1] > h[b-1]:
        count[b-1] = 1
    if h[a-1] < h[b-1]:
        count[a-1] = 1
    if h[a-1] == h[b-1]:
        count[a-1] = 1
        count[b-1] = 1
c = collections.Counter(count)
print(c[0])


Measured memory_bytes: 20452
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 998244353;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

ll modadd(ll x, ll y) {
    return ((x + y) % mod + mod) % mod;
}

ll modminus(ll x, ll y) {
    return (x - y + mod) % mod;
}

ll multiply(ll x, ll y) {
    return (x % mod) * (y % mod) % mod;
}

ll modpower(ll x, ll y) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else if (y % 2 == 0) {
        ll p = modpower(x, y / 2);
        return p * p % mod;
    } else {
        ll p = modpower (x, y / 2);
        return (p * p) % mod * (x % mod) % mod;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll D[N];
    REP(i, 0, N) {
        cin >> D[i];
    }
    ll num[N];
    fill(num, num + N, 0);
    REP(i, 0, N) {
        num[D[i]]++;
    }
    ll ans = 1;
    if (D[0] != 0 || num[0] > 1) {
        ans = 0;
        cout << ans << endl;
        return 0;
    }
    REP(i, 1, N) {
        if (num[i] != 0) {
            ans = multiply(ans, modpower(num[i - 1], num[i]));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
# -*- coding: utf-8 -*-

n = int(input())
S = [ input() for i in range(n) ]

chrs = {}
for i in range(n):
    tmp_chrs = {}
    for j in range(len(S[i])):
        tmp_chrs[S[i][j]] = tmp_chrs[S[i][j]] + 1 if S[i][j] in tmp_chrs else 1

    if i == 0:
        chrs = tmp_chrs
    else:
        new_chrs = {}
        for c in chrs:
            if c in tmp_chrs:
                new_chrs[c] = tmp_chrs[c] if tmp_chrs[c] < chrs[c] else chrs[c]
        chrs = new_chrs

if len(chrs) == 0:
    print('')
else:
    string = [ c * chrs[c] for c in chrs ]
    string.sort()
    print(''.join(string))

Measured memory_bytes: 3064
#include <stdio.h>

int main(){
	long long int N;
	long long int i,hoge,ans=0;
	
	scanf("%lld",&N);
	
	for(i=0;i<N;i++){
		scanf("%lld",&hoge);
		ans+=hoge-1;
	}
	
	printf("%lld",ans);
	
	return 0;
}

Measured memory_bytes: 128
import java.lang.Math

val MOD: Int = 1000000000 + 7
val MODL: Long = MOD.toLong()

fun main(args: Array<String>)
{
    val (n, x) = readLine()!!.split(" ").map{it.toInt()}
    val pos = readLine()!!.split(" ").map{Math.abs(it.toInt() - x)}.toIntArray()

    var ans = pos[0]
    for (i in 1 until n) {
        ans = gcd(ans, pos[i])
    }

    println(ans)
}

fun gcd(a: Int, b: Int): Int {
    if (b == 0) return a
    return gcd(b, a % b)
}


Measured memory_bytes: 51748
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main() {
	int n;
	cin >> n;
	if (n % 111 == n % 10 || (n % 1000) % 111 == 0 || n % 1111 == 0)
		cout << "Yes" << "\n";
	else
		cout << "No" << "\n";
}

Measured memory_bytes: 3636
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int temp = a + b;
        if (temp % 2 == 0) {
            System.out.println(Math.abs(temp / 2));
        } else {
            System.out.println("IMPOSSIBLE");
        }
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int n,w;
    while(1){
        cin >> n >> w;
        if(n==0 and w==0) break;
        vector<int> V(n,0);
        rep(i,n) cin >> V[i];
        int ma = -1;
        rep(i,n) if(V[i]>ma) ma  = V[i];
        // cout << "max is " << ma << endl;
        int colmuns=(ma+1 + w -1) / w;
        // if(ma % w == 0 ) colmuns = (ma+1)/w +1;
        // else colmuns = (ma+w-1) / w;
        // cout << "columns are  " << colmuns << endl;
        vector<int> H(colmuns,0);
        rep(i,n){
            // cout << "to " << V[i]/w << endl;
            H[V[i]/w]+=1;
        }
        double ma2 = -1;
        rep(i,colmuns){
            if(H[i]>ma2) ma2 = H[i];
        }
        vector<double> H_1(colmuns,0.0);
        rep(i,colmuns){
            // cout << "ma2 " <<ma2 << endl;
            H_1[i] = (H[i]*1.0) / ma2;
            // cout << "aa" << H_1[i] << endl;
        }
        
        double nodo = 1.0/(colmuns-1);

        // rep(i,colmuns){
        //     cout << H_1[i] << ", ";
        // }
        // cout << endl;
        
        // cout << "Nodo is " << nodo << endl;
        double total_ink = 0;
        for(int i=0; i<colmuns; i++){
            // cout << (1 - nodo*(i)) << " * " << H_1[i] << endl;
            total_ink+=H_1[i]*(1 - nodo*(i));
        }
        cout<< setprecision(15) <<total_ink + 0.01 << endl;
        // cout << total_ink +0.1 << endl;
    }
    return 0;
}


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

// aを常に小さい値にする　大きい値にする
template<class T> bool chmin(T &a, T b){
    if(a>b) {
        a = b;
        return true;
    }
    return false;

}
template<class T> void chmax(T &a, T b){ if(a<b) a = b; }

// 二分探索 前方のindexを返すもの（自分自身を含む） 前方: -INF側のこと
template<class T> int former(const vector<T> &v, T x){
    return upper_bound(v.begin(), v.end(), x) - v.begin() -1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す
}
// 二分探索 後方のindexを返すもの（自分自身を含む）後方: INF側のこと
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : key以上の要素の内の一番左側のイテレータを返す
}

// 最大公約数を求める GCD
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

using Data = pair<ll, vector<int>>;

int main() {

    ll X, Y, Z, K;
    cin >> X >> Y >> Z >> K;

    vector<ll> A(X), B(Y), C(Z);
    rep(i,X) cin >> A[i];
    rep(i,Y) cin >> B[i];
    rep(i,Z) cin >> C[i];

    sort(A.begin(),A.end(), greater<ll>());
    sort(B.begin(),B.end(), greater<ll>());
    sort(C.begin(),C.end(), greater<ll>());

    priority_queue<Data> que;
    set<Data> se; // 同じ組み合わせが使われないように使ったものは集合として保存していく

    Data insert;
    insert = make_pair(A[0] + B[0] + C[0], vector<int>({0, 0, 0}));
    que.push(insert);


    rep(i,K){
        // 出力
        auto c = que.top();que.pop();
        cout << c.first << endl;

        // 次の三候補をpush

//        A のみ index を 1 個進めて足したもの
        if (c.second[0] + 1 < X) {
            ll sum = c.first - A[c.second[0]] + A[c.second[0] + 1];
            auto num = c.second;
            num[0]++;
            auto d = Data(sum, num);

            // すでに push されたもの以外
            if (!se.count(d)) se.insert(d), que.push(d);
        }

//        B のみ index を 1 個進めて足したもの
        if (c.second[1] + 1 < Y) {
            ll sum = c.first - B[c.second[1]] + B[c.second[1] + 1];
            auto num = c.second;
            num[1]++;
            auto d = Data(sum, num);

            // すでに push されたもの以外
            if (!se.count(d)) se.insert(d), que.push(d);
        }

//        C のみ index を 1 個進めて足したもの
        if (c.second[2] + 1 < Z) {
            ll sum = c.first - C[c.second[2]] + C[c.second[2] + 1];
            auto num = c.second;
            num[2]++;
            auto d = Data(sum, num);

            // すでに push されたもの以外
            if (!se.count(d)) se.insert(d), que.push(d);
        }
    }

}

Measured memory_bytes: 1408
while True:
    h,w = map(int,input().split())
    if h == w == 0:
        break
    for i in range(h):
        for j in range(w):
            if (i % 2) == 0:    
                if (j % 2) == 0:
                    print("#",end="")
                else:
                    print(".",end="")
            else:    
                if (j % 2) == 0:
                    print(".",end="")
                else:
                    print("#",end="")
        print()
    print()


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    bool flag = true;
    rep(i, n) {
        cin >> a.at(i);
        if((a.at(i) % 2 == 0) && (a.at(i) % 6 && a.at(i) % 10)) flag = false;
    }
    if(flag) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

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

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

using namespace std;


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

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  vector<int> B(N);
  REP(i, N) cin >> B[i];

  int ok = 0;
  vector<int> sum(N);
  REP(i, N){
    sum[i] = B[i]-A[i];
    if(sum[i] > 0){
      ok += sum[i]/2;
    }else{
      ok += sum[i];
    }
  }

  if(ok >= 0) Yes;
  else No;

  return 0;
}

Measured memory_bytes: 512
from collections import defaultdict


def main():
    S = input()
    while len(S) != 0:
        change = False
        for s in ["dream", "dreamer", "erase", "eraser"]:
            if S.endswith(s):
                S = S[:-len(s)]
                change = True
                break
        if not change:
            break

    print("YES" if len(S) == 0 else "NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

map<long long, long long> numMap;
//i--表示数值为几，numCount[i]表示此时会增加多少数据 

long long h;

long long doSearch(long long num) {
	if (numMap.find(num) != numMap.end()) {
		return numMap[num];
	}
	
	long long d = num / 2;
	long long ans = doSearch(d) * 2 + 1;
	numMap[num] = ans;
	return numMap[num];
}

int main()
{
	scanf("%lld", &h);
	
	numMap.clear();
	
	numMap[0] = 0;
	numMap[1] = 1;
	
	doSearch(h);
	long long ans = numMap[h];
	
	printf("%lld\n", ans);
	
	
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int K, N, A[200005], m, x, i;
    scanf("%d%d", &K, &N);
    for (i=0; i<N; i++) scanf("%d", &A[i]);
    m=A[N-1]-A[0];
    // printf("%d\n", m);
    for (i=1; i<N; i++) {
        x=A[i-1]-A[i]+K;
        // printf("%d\n", x);
        if (x<m) m=x; 
    }
    printf("%d", m);
    return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b>c+d) cout<<"Left"<<'\n';
  else if(a+b<c+d) cout<<"Right"<<'\n';
  else cout<<"Balanced"<<'\n';
  return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
  ll n, ans = 0, x;
  cin >> n;
  unordered_map<ll, int> mp;
  for (int i = 1; i <= n; ++i) scanf("%lld", &x), ans += mp[i - x], mp[i + x]++;
  printf("%lld", ans);
  return 0;
}


Measured memory_bytes: 18564