akhauriyash/Code-Regression huggingface dataset:
//E.H//
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
#define pii pair<int,int>
priority_queue<int,vector<int>,greater<int> >pq;
priority_queue<int>pq2;
ll ps[300005],n,arr[300005],mx[300005],mn[300005];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    for(int i=1;i<=3*n;i++){
        cin>>arr[i];
        ps[i] = ps[i-1] + arr[i];
        if(i<=n) {
            pq.push(arr[i]);
        }
        if(i>2*n) {
            pq2.push(arr[i]);
        }

    }
     mx[n] = ps[n];
    for(int i=n+1;i<=2*n;i++){
        ll x = mx[i-1];
        x+=arr[i];
        pq.push(arr[i]);
        x-=pq.top();
        pq.pop();
        mx[i] = x;
    }
     mn[2*n+1] = ps[3*n]-ps[2*n];
    for(int i=2*n;i>n;i--){
        ll x = mn[i+1];
        x+=arr[i];
        pq2.push(arr[i]);
        x-=pq2.top();
        pq2.pop();
        mn[i] = x;
    }
    ll ans=-1e18;
    for(int i=n;i<=2*n;i++){
        ans = max(ans,mx[i]-mn[i+1]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 10428
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <tuple>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

using T = tuple<ll,ll>;
using Graph = vector<vector<T>>;

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

    ll x, n;
    cin >> x >> n;
    set<ll> p;

    rep(i,0,n)
    {
        ll cache;
        cin >> cache; p.emplace(cache);
    }

    pair<ll,ll> closest(LL_MAX, 0);
    rep(i,-1,105)
        if(p.find(i)==p.end())
        {
            if (abs(x-i) < closest.first)
                closest.second = i, closest.first = abs(x-i);
        }

    cout << closest.second << endl;
 
    return 0;
}


Measured memory_bytes: 3580
n,q=map(int,input().split())
s=input()

lst=[0]
for i in range(1,n):
    if s[i-1]=="A" and s[i]=="C":
        lst.append(lst[i-1]+1)
    else:
        lst.append(lst[i-1])

for i in range(q):
    l,r=map(int,input().split())
    print(lst[r-1]-lst[l-1])

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

using namespace std;

typedef long long ll;

const long long N = 1e5 + 1;

ll n , a[N] , fen[2 * N] , b[N] , ans;

void update(int p , int val){
    for(int i = p ; i < 2 * N ; i += i & (-i)) fen[i] += val;
}

ll get(int p){
   ll res = 0;
   for(int i = p ; i ; i -= i & (-i)) res += fen[i];
   return res;
}

bool check(int mid){
    memset(fen , 0 , sizeof(fen));
    vector<ll> d(n + 1) , f(2 * n + 1);
    ll cnt = 0;
    for(int i = 1 ; i <= n ; i ++) d[i] = d[i - 1] + (a[i] >= b[mid]) , f[i] = 2 * d[i] - i;
    for(int i = 1 ; i <= n ; i ++){
      update(f[i - 1] + n , 1);
      cnt += get(f[i] + n);
    }
    return (2 * cnt >= n * (n + 1) / 2);
}
int main(){
    cin >> n;
    for(int i = 1 ; i <= n ; i ++) cin >> a[i] , b[i] = a[i];
    sort(b + 1 , b + 1 + n);
    int l = 1 , r = n;
    while(l <= r){
      int mid = (l + r) / 2;
      if(check(mid)) l = mid + 1 , ans = b[mid];
      else r = mid - 1;
    }
    cout << ans << endl;
}


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

vector<int> make_prime_5(int max, int number, int q) {
  map<int, int> mp;
  for (int i = 2; i < max; ++i) {
    ++mp[i];
  }
  for (int i = 2; i * i < max; ++i) {
    for (int j = 2; i * j < max; ++j) {
      mp[i * j] = 0;
    }
  }
  int cnt = 0;
  vector<int> prime_array(number, 0);
  for (auto p : mp) {
    if (cnt >= number) {
      break;
    }
    if (p.second == 1 && p.first % q == 1) {
      prime_array[cnt] = p.first;
      ++cnt;
    }
  }
  return prime_array;
}

int main() {
  int n;
  cin >> n;
  vector<int> p = make_prime_5(55555, n, 5);
  for (int i = 0; i < p.size(); ++i) {
    cout << p[i] << " ";
  }
  cout << "\n";
  return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
	//入力
	int a,b,t,ans;
	cin >> a >> b;
  	t = max(a,b);
	//処理
	ans = max(2*t-1,a+b);
	//出力
	cout << ans << endl;
}

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

int main(){
    string S,T;
    cin>>S>>T;
    int ans=0;
    for(int i=0;i<S.size();i++){
        ans+=(S[i]!=T[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,m,r;cin>>n>>m>>r;
    vector<ll> a(r);for(ll i=0;i<r;i++)cin>>a[i],a[i]-=1;
    ll dist[n][n];
    for(ll i=0;i<n;i++)for(ll j=0;j<n;j++)dist[i][j]=1e12;
    for(ll i=0;i<n;i++)dist[i][i]=0;
    for(ll i=0;i<m;i++){
        ll u,v,w;cin>>u>>v>>w;
        dist[u-1][v-1]=dist[v-1][u-1]=w;
    }
    for(ll k=0;k<n;k++)for(ll i=0;i<n;i++)for(ll j=0;j<n;j++)dist[i][j] = min(dist[i][j] , dist[i][k] + dist[k][j]);
    ll ans=1e12;
    sort(a.begin(),a.end());
    do{
        ll cur=0;
        for(ll i=1;i<r;i++)cur+=dist[a[i-1]][a[i]];
        ans=min(ans,cur);
    }while(next_permutation(a.begin(),a.end()));
    cout<<ans;
}


Measured memory_bytes: 640
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/




int main() {
ll N,C,K;
cin>>N>>C>>K;
ll T[N];
rep(i,N){
  cin>>T[i];
}
sort(T,T+N);
ll lim=0,num,count=0;
rep(i,N){
if((lim<T[i])||(num==C)){
  lim=T[i]+K;
  num=1;
  count++;
}
else{
  num++;
}
}
cout<<count<<endl;
return 0;
}

Measured memory_bytes: 4408
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
int num[15][15];
int n,m,x;
int Cost[15];
int all[15];
int ans;
bool check(int *a)
{
    for(int i = 1;i<=m;++i)
        if(a[i]<x)
            return false;
    return true;
}
void dfs(int id,int *a,int cost)
{
    //cout << id << " " << cost << "\n";
    if(cost>=ans)
        return ;
    if(id==n+1)
    {
        if(check(a)&&cost<ans)
            ans = cost;
        return ;
    }
    dfs(id+1,a,cost);
    for(int i = 1;i<=m;++i)
        a[i]+=num[id][i];
    dfs(id+1,a,cost+Cost[id]);
    for(int i = 1;i<=m;++i)
        a[i]-=num[id][i];
    return ;
}
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    cin >> n >> m >> x;
    for(int i = 1;i<=n;++i)
    {
        cin >> Cost[i];
        for(int j = 1;j<=m;++j)
            cin >> num[i][j];
    }
     ans = INF;

    dfs(1,all,0);
    if(ans==INF)
        printf("-1\n");
    else
        cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define sl(n) scanf("%lld",&n)
using namespace std;

string lcs(char *a,char *b){
    int len_a=strlen(a);
    int len_b=strlen(b);
    vector<vector<pair<int,pair<int,int>>>> dp(len_a+1,vector<pair<int,pair<int,int>>>(len_b+1));
    for(int i=0;i<len_a+1;++i){
        for(int j=0;j<len_b+1;++j){
            dp[i][j]={0,make_pair(0,0)};
        }
    }
    for(int i=1;i<=len_a;++i){
        for(int j=1;j<=len_b;++j){
            if(a[i-1]==b[j-1]){
                dp[i][j].first=dp[i-1][j-1].first+1;
                dp[i][j].second.first=i-1;
                dp[i][j].second.second=j-1;
            }
            else if(a[i-1]!=b[j-1]){
                //dp[i][j].first=max(dp[i-1][j].first,dp[i][j-1].first);
                if(dp[i-1][j].first>dp[i][j-1].first){
                    dp[i][j].first=dp[i-1][j].first;
                    dp[i][j].second.first=i-1;
                    dp[i][j].second.second=j;
                }else{
                    dp[i][j].first=dp[i][j-1].first;
                    dp[i][j].second.first=i;
                    dp[i][j].second.second=j-1;
                }
            }
        }
    }
    string ans="";
    int i=len_a;
    int j=len_b;
    int l=0,k=0;
    while(i!=0 || j!=0){
        
        if(dp[i][j].second.first==(i-1) && dp[i][j].second.second==(j-1)){
            //cout<<"hello"<<endl;
            ans.push_back(a[i-1]);
        }
        l=dp[i][j].second.first;
        k=dp[i][j].second.second;
        i=l;j=k;
        //cout<<i<<" "<<j<<endl;
    }
    // cout<<dp[2][1].second.first<<" "<<dp[2][1].second.second<<endl;  
    // for(int i=0;i<=len_a;++i){
    //     for(int j=0;j<=len_b;++j){
    //         cout<<dp[i][j].first<<"->"<<dp[i][j].second.first<<" "<<dp[i][j].second.second<<" ";
    //     }
    //     cout<<endl;
    // }
    if(ans.size()==0)
        return " ";
    reverse(ans.begin(),ans.end());
    return ans;
}

int main() {
    char a[3002],b[3002];
    cin>>a>>b;
    //cout<<a<<" "<<b<<endl;
    cout<<lcs(a,b);
    return 0;
}

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

int main() {
    int64_t n, t;
    cin >> n >> t;
    vector<int64_t> a(n);
    for (auto& e : a) cin >> e;

    int minp = a[0], maxb = 0, c = 0;
    for (int64_t i = 1; i < n; i++) {
        int64_t diff = a[i] - minp;
        if (diff < 0) minp = a[i];
        if (diff == maxb) c++;
        if (diff > maxb) maxb = a[i] - minp, c = 1;
    }

    cout << c << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  vector<pair<int,int>> x(n);
  for(int i=0;i<n;i++){
    cin>>x[i].first;
    x[i].second=i;
  }
  sort(x.begin(),x.end());
  vector<int>b(n);
  for(int i=0;i<n;i++){
    if(i<n/2){
      b[x[i].second]=x[n/2].first;
    }
    
    else{
      b[x[i].second]=x[n/2-1].first;
    }
  }
  for(int i=0;i<n;i++){
    cout<<b[i]<<endl;
  }
}
  

Measured memory_bytes: 4480
def calc(x1,y1,x2,y2):
    return (((x1-x2)**2+(y1-y2)**2))**0.5

def kaijo(n):
    if n == 1:
        return n
    return n * kaijo(n-1)

n = int(input())
lsx = []
lsy = []

for i in range(n):
    x,y = map(int,input().split())
    lsx.append(x)
    lsy.append(y)

num = 0
cnt = 0

for i in range(n):
    for j in range(i+1,n):
        num += calc(lsx[i],lsy[i],lsx[j],lsy[j])
        cnt += 1

print(num*(n-1)/cnt)

Measured memory_bytes: 3064
def S(n):
    k=list(str(n))
    import functools
    return functools.reduce(lambda x,y:x+y,[int(i) for i in k])
k=int(input())
def T(n):
    return n/S(n)
def f(N):
    len_N=len(str(N))
    A=[10**len_N+10**i-1 for i in range(len_N)]
    B=[T(i) for i in A]
    ans1=A[B.index(min(B))]
    i=0
    while True:
        I=10**(len_N-1)+10**i-1
        J=10**(len_N-1)+10**(i+1)-1
        if T(J)<T(I):
            i+=1
        else:
            break
    C=[((N+1)//(10**i))*10**i+j*10**i-1 for j in range(1,11)]
    D=[T(i) for i in C]
    ans2=C[D.index(min(D))]
    if T(ans1)<T(ans2):
        return(ans1)
    else:
        return(ans2)
K=[]
N=1
while len(K)<k:
    K.append(N)
    N=f(N)
for i in range(k):
    print(K[i])
    

Measured memory_bytes: 3680
N,K = map(int,input().split())
A = list(map(int,input().split()))
B = []
for i,a in enumerate(A):
    k = 0
    for c in A[i:]:
        k += c
        B.append(k)

ans = 0
for i in range(40,-1,-1):
    C = []
    for b in B:
        if b&(1<<i):
            C.append(b)
    if len(C) >= K:
        B = C
        ans += 2**i
print(ans)

Measured memory_bytes: 65916
# coding: utf-8
# Your code here!
K=int(input())


alpha=K//50
beta=K%50
#print(alpha,beta)

N=50
A=[49+alpha-beta]*N
for i in range(beta):
    A[i]+=51

print(N)
print(*A)

"""
count=0
for i in range(50):
    if A[i]<50:
        continue
    count+=1
    for j in range(50):
        if i==j:
            A[j]-=N
        else:
            A[j]+=1

print(A)
print(count)
"""

Measured memory_bytes: 2940
#include <stdio.h>
int main()
{
    int n, a[100], i, j, cnt=0, c, mini;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    for(i = 0; i < n; i++){
        mini = i;
        for(j = i; j < n; j++){
            if(a[j] < a[mini]){
                mini = j;
            }
        }
        if(i != mini){
            cnt++;
            c = a[mini];
            a[mini] = a[i];
            a[i] = c;
        }
    }
    for(i = 0; i < n; i++){
        if(i == (n - 1)){
            printf("%d\n", a[i]);
        } else {
            printf("%d ", a[i]);
        }
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
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; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main()
{
    INIT

    string a;

    cin >> a;

    if(a == "AAA" || a == "BBB") {
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <utility>
using namespace std;

template<typename Type>
void chmax(Type &A, Type B) {
    A = max(A, B);
}

const int INF = 1 << 28;
int H, W, S, lim;
int A[40][40], sum[40][40];
pair<int, int> dp[40][40][40][40];

int get_sum(int lx, int ly, int rx, int ry) {
    return sum[rx][ry] - sum[rx][ly] - sum[lx][ry] + sum[lx][ly];
}

// 左上、右下 (半開)
pair<int, int> solve(int lx, int ly, int rx, int ry) {
    // printf("%d, %d, %d, %d\n", lx, ly, rx, ry);
    pair<int, int> &val = dp[lx][ly][rx][ry];
    if(val != make_pair(-1, -1)) return val;

    int cur_sum = get_sum(lx, ly, rx, ry);
    if(cur_sum < lim) {
        return val = make_pair(-1, INF);
    }
    else {
        val = make_pair(1, cur_sum - lim);
    }

    // split (x)
    for(int i=lx+1; i<rx; i++) {
        pair<int, int> vl = solve(lx, ly, i, ry);
        pair<int, int> vr = solve(i, ly, rx, ry);
        int rl = vl.first + vr.first;
        int rr = min(vl.second, vr.second);
        chmax(val, make_pair(rl, rr));
    }

    // split (y)
    for(int i=ly+1; i<ry; i++) {
        pair<int, int> vl = solve(lx, ly, rx, i);
        pair<int, int> vr = solve(lx, i, rx, ry);
        int rl = vl.first + vr.first;
        int rr = min(vl.second, vr.second);
        chmax(val, make_pair(rl, rr));
    }
    return val;
}

int main() {
    while(1) {
        scanf("%d%d%d", &H, &W, &S);
        if(!H) break;

        memset(A, 0, sizeof(A));
        memset(sum, 0, sizeof(sum));
        for(int i=0; i<H; i++) {
            for(int j=0; j<W; j++) {
                scanf("%d", &A[i][j]);
                sum[i+1][j+1] = A[i][j];
            }
        }

        // left -> right
        for(int i=0; i<H; i++) {
            for(int j=0; j<W; j++) {
                sum[i+1][j+1] += sum[i+1][j];
            }
        }

        // up -> down
        for(int j=0; j<W; j++) {
            for(int i=0; i<H; i++) {
                sum[i+1][j+1] += sum[i][j+1];
            }
        }

        lim = get_sum(0, 0, H, W) - S;
        fill(dp[0][0][0], dp[40][0][0], make_pair(-1, -1));
        pair<int, int> ans = solve(0, 0, H, W);
        printf("%d %d\n", ans.first, ans.second);
    }
    return 0;
}


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

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define INF INT64_MAX
#define MOD 1000000007
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool flag, ok;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[8] = { 1,-1,0,0,1,1,-1,-1 }, ddy[8] = { 0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 222222

ll dp[55][55][2555];
int main(void) {
  ll a;
  vll x;
  cin >> n >> a;
  FOR(i, 0, n) {
	cin >> tmp;
	x.pb(tmp);
  }
  dp[0][0][0] = 1;
  FOR(i, 0, n) {
	FOR(j, 0, 51) FOR(k, 0, 2501) dp[i + 1][j][k] = dp[i][j][k];
	FOR(j, 1, 51) {
	  FOR(k, x[i], 2501) {
		dp[i + 1][j][k] += dp[i][j - 1][k - x[i]];
	  }
	}
  }

  FOR(j, 1, 51) {
	FOR(k, 0, 2501) {
	  if (k == j * a) ans += dp[n][j][k];
	}
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 56448
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> p2;
ll hell=pow(10,9)+7;
void solve(){
    ll n;
    cin>>n;
    cout<<ll(ceil(n/2.0));
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    for(ll qc=0;qc<t;qc++)
    solve();
}


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

class Dice {
public:
	int		value  = 1;                    // 上面の値　
	int 	s[7] = {0, 1, 2, 3, 4, 5, 6};  // 各面の値

	void init(int x[]) {
		for(int i=0; i<6; i++ ) s[i+1] = x[i];
		value = s[1];	
	}	 
	
	void dump() {
		for(int i=1; i<=6; i++) {
			cout << "S" << i << ":" << s[i] <<", ";
		}
		cout << endl;
	}	
		
	void flip(char c) {
		switch (c) {
			case 'N':
				flip_N();
				break;
			case 'S':
				flip_S();
				break;
			case 'E':
				flip_E();
				break;
			case 'W':
				flip_W();
				break;
			default:
				break;
		}
	}
	void flips(string cmds) {
		for(int i=0; i<cmds.size(); i++) {
			flip(cmds[i]);
		}	
	} 	
	
	int flip_N() {
		// 面3,4変わらず、面1265 をローテ―トする(x軸ロテーション)
		int x = s[1];
		s[1] = s[2];
		s[2] = s[6];
		s[6] = s[5];
		s[5] = x;

		value  = s[1];
	}
	
	int flip_S() {
		// 面3,4変わらず、面1265 をローテ―トする(x軸ロテーション)
		int x = s[1];
		s[1] = s[5];
		s[5] = s[6];
		s[6] = s[2];
		s[2] = x;

		value  = s[1];
	}
	
	int flip_E() {
		// 面2,5変わらず、面1364 をローテ―トする(y軸ロテーション)
		int x = s[1];
		s[1] = s[4];
		s[4] = s[6];
		s[6] = s[3];
		s[3] = x;

		value  = s[1];
	}

	int flip_W() {
		// 面2,5変わらず、面1364 をローテ―トする(y軸ロテーション)
		int x = s[1];
		s[1] = s[3];
		s[3] = s[6];
		s[6] = s[4];
		s[4] = x;

		value = s[1];
	}

	int rotate_z() {
		// 面1固定で縦軸(z軸)回転
		int x = s[2];
		s[2] = s[4];
		s[4] = s[5];
		s[5] = s[3];
		s[3] = x;
	}
	
	bool same(Dice d2) {
		bool rtn = true;
		for (int i=0; i<=6; i++) {
			if ( s[i] != d2.s[i] ) {
				rtn = false;
				break;
			}
		}
		return rtn;
	}

private:
};




int main() {
	Dice d1,d2;
	int s1[6],s2[6];

	for(int i=0; i<6; i++) cin >> s1[i];
	for(int i=0; i<6; i++) cin >> s2[i];

	d1.init(s1);
	d2.init(s2);

	int x,y;
	cin >> x >> y;

	string command = "NNWWNW";   
	bool found = false;
	for(int j=0;j<command.size(); j++) {
		d2.flip(command[j]);

		if ( d1.s[1] == d2.s[1] ) { // 上面を合わせる
			for(int k=0; k<4; k++) {
				d1.rotate_z();
				if (d1.same(d2)) {
					found = true;            
					goto loop_exit;
				}
			}		
		}
	}
	loop_exit:
	if (found) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3208
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main()
{
    cout.precision(18);

    long long N;
    cin >> N;

    long long k = (1 + sqrt(1 + 8 * N)) / 2;

    if(pow(2 * k - 1, 2) == 1 + 8 * N){
      vector<vector<long long>> c(k, vector<long long>{});
      long long t = 0;
      for(long long i = 0; i < k - 1; i++){
        for(long long j = i + 1; j < k; j++){
          c[i].push_back(t);
          c[j].push_back(t);
          t++;
        }
      }

      cout << "Yes" << endl;
      cout << k << endl;
      for(long long i = 0; i < k; i++){
        cout << k - 1 << ' ';
        for(long long j = 0; j < k - 1; j++){
          cout << c[i][j] + 1;
          if(j < k - 2){
            cout << ' ';
          }
        }
        cout << endl;
      }
    }
    else{
      cout << "No" << endl;
    }

}


Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  char a, b;
  cin >> a >> b;

  // 解答
  cout << (a == b ? "=" : (a < b ? "<" : ">")) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	int ans = 0;
	for(int i=0;i<k;i++) ans+=a[i];
	cout<<ans<<endl;
	return 0;
}

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

int main() {
	int n, k, a, ball[200000] = { 0 }, ans = 0;
	cin >> n >> k;
	rep(i, n) {
		cin >> a;
		ball[a]++;
	}

	sort(ball, ball + n, greater<>());

	rep(i, k) {
		ans += ball[i];
	}

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

Measured memory_bytes: 1024
module Main where

import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.String
import Data.List
import Data.Maybe
import Control.Monad

main :: IO ()
main = do
  x <- fst . fromJust . BS.readInt <$> BS.getLine
  putStrLn $ solve x

solve :: Int -> String
solve x
  | x >= 30 = "Yes"
  | otherwise = "No"


Measured memory_bytes: 3736
////.....KNAPSACK-1.....////

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    }
    public static void main(String[] args) {
       FastReader in = new FastReader();
       int n=in.nextInt();
       int W=in.nextInt();
       int w[]=new int[n];
       int val[]=new int[n];
       for(int i=0;i<n;i++){
           w[i]=in.nextInt();
           val[i]=in.nextInt();
       }
       long dp[][]=new long[n+1][W+1];
       for(int i=0;i<=n;i++){
           dp[i][0]=0;
       }
       for(int i=0;i<=W;i++){
           dp[0][i]=0;
       }
       for(int i=1;i<=n;i++){
           for(int j=1;j<=W;j++){
               dp[i][j]=dp[i-1][j];
               if(j>=w[i-1]){
                   long temp=0;
                   temp=dp[i-1][j-w[i-1]]+val[i-1];

                   if(temp>dp[i][j]){
                       dp[i][j]=temp;
                   }
               }
           }
       }

           System.out.println(dp[n][W]);

    }
}


Measured memory_bytes: 137584
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    long long n;
    cin >> n;
    if (n % 2 == 0) {
        cout << (n / 2) - 1 << endl;
    } else {
        cout << n / 2 << endl;
    }
    return 0;
}

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

ll L;

struct Graph {
    static constexpr ll INF = 1LL << 59;
    struct VertexQ {
        bool operator<(const VertexQ &o) const {
            return c > o.c; // 逆
        }
        int i;
        ll c;
    };
    struct Vertex { int n; ll c; };
    struct Edge { int i, n, c; };
    Graph(int n, int m) : v(n, { -1 }), e(m), n(n), m(0) {}
    void add_edge(int i, int j, int c) {
        if (c > L) return;
        e[m] = { j, v[i].n, c };
        v[i].n = m;
        m++;
    }
    void dijkstra(int i) {
        for (int i = 0; i < n; i++) v[i].c = INF;
        priority_queue<VertexQ> q;
        q.push({ i, v[i].c = 0 });
        while (!q.empty()) {
            auto p = q.top(); q.pop();
            if (p.c > v[p.i].c) continue;
            for (int j = v[p.i].n; j >= 0; j = e[j].n) {
                Edge &o = e[j];
                ll c = p.c + o.c;

                if (c % (1LL << 32) > L) {
                    c = p.c - p.c % (1LL << 32) + (1LL << 32) + o.c;
                }

                if (c < v[o.i].c) q.push({ o.i, v[o.i].c = c });
            }
        }
    }
    vector<Vertex> v;
    vector<Edge> e;
    int n, m;
};

ll p[300][300];

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

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

    Graph g(n, m * 2);
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;

        g.add_edge(a, b, c);
        g.add_edge(b, a, c);
    }

    for (int i = 0; i < n; i++) {
        g.dijkstra(i);
        for (int j = 0; j < n; j++) {
            p[i][j] = g.v[j].c;
        }

    }

    int q;
    cin >> q;

    for (int h = 0; h < q; h++) {
        int s, t;
        cin >> s >> t;
        s--; t--;

        ll x = p[s][t];
        cout << (x == g.INF ? -1 : (x >> 32)) << '\n';
    }

    return 0;
}

Measured memory_bytes: 2176
// --------------
// Tejas Pandey  |
// 28 - 03 - 20  |
// Atcoder BC 160|
// --------------

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

#define mod 998244353
#define vi vector<int>
typedef long long int ll;

int main (void)
{
  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n,x,y;
  cin >> n >> x >> y;
  int ans[n];
  memset(ans,0,sizeof(ans));
  for(int i = 1;i < n;i++)
    for(int j = i + 1;j <= n;j++)
        ans[min(j - i,min(abs(i - x)+1+abs(y - j),abs(i - y)+1+abs(x - j)))]++;
  for(int i = 1;i < n;i++) cout << ans[i] << "\n";
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(200000)
n = int(input())
edges = [[] for _ in range(n)]
for i in range(n-1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append((b, c))
    edges[b].append((a, c))

q, k = map(int, input().split())
k -= 1

visited = [0] * n
d = [0] * n
def dfs(v, c):
    for u, c2 in edges[v]:
        if visited[u] == 0:
            d[u] = c + c2
            visited[u] = 1
            dfs(u, c + c2)

visited[k] = 1
dfs(k, 0)

for i in range(q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    print(d[x] + d[y])


Measured memory_bytes: 136368
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
//#include <conio.h>
using namespace std;

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

#define rep(i,n)	for(ll i=0;i<(n);i++)
#define SZ(x) ((ll)x.size())
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define F first
#define S second
#define int ll
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll MOD = INT_MAX;
const double PI = acos(-1);

void openfile(){
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
}


signed main(){
	IOS
	int a,b,c,d;	cin >> a >> b >> c >> d;
	int x[4];
	x[0] = a*c;
	x[1] = a*d;
	x[2] = b*c;
	x[3] = b*d;
	sort(x,x+4,greater<int>());
	cout << x[0] << endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

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

    int N, A;
    cin >> N >> A;

    vector<vector<ll>> dp(N * 50 + 3, vector<ll>(N + 3));
    dp[0][0] = 1;
    for (int i = 1; i <= N; ++i) {
        int x;
        cin >> x;
        for (int j = i; j > 0; --j)
            for (int k = j * 50; k >= x; --k)
                dp[k][j] += dp[k - x][j - 1];
    }
    ll ans = 0;
    for (int i = 1; i <= N; ++i)
        ans += dp[A * i][i];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

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

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

void solve(string S)
{

    ll ans = INF;
    ll cnt1 = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if ((i % 2) == 0)
        {
            if (S[i] != '0')
            {
                cnt1++;
            }
        }
        else
        {
            if (S[i] != '1')
            {
                cnt1++;
            }
        }
    }

    ll cnt2 = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if ((i % 2) == 0)
        {
            if (S[i] != '1')
            {
                cnt2++;
            }
        }
        else
        {
            if (S[i] != '0')
            {
                cnt2++;
            }
        }
    }
    cout << min(cnt1, cnt2) << endl;
}

int main()
{
    string S;
    cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

 
 
const ll N = 100005;
const ll mod = 1000000007;
const long long int inf = 1e10+5;
#define pp pair<ll,ll>
 
typedef long double ld;
typedef vector<pp> vpl;
#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++) 
#define mtrace(i,a) for(auto i=a.begin();i!=a.end();i++)  cout<<i->first<<" "<<i->second<<endl;   




void fastIO(void);
void decimal(int);
ll modmulti(ll, ll);
ll modadd(ll, ll);
ll modpower(ll, ll);
ll gcd(ll, ll );
ll modinv(ll);




int main(){
    
     
   ll a,b;
   cin>>a>>b;
   if(a==b) cout<<"Yes\n";
   else cout<<"No\n";






   

}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b){
   return ((a%mod)*1ll*(b%mod))%mod;
}
ll modadd(ll a, ll b){
   ll asdfgh =  ((a%mod)+(b%mod)+mod+mod)%mod;
   asdfgh = (asdfgh+mod)%mod;
   return asdfgh;
}
ll modpower(ll a, ll n){
   if(n==0) return 1;
   if(n==1) return a%mod;
   ll b = modpower(a,n/2);
   b = modmulti(b,b);
   if(n%2==0) return b;
   return modmulti(a,b);
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a){
   return modpower(a,mod-2);
}
 

Measured memory_bytes: 256
#include <stdio.h>
int n, A[500001];

void maxHeap(i) {
  if(i > n / 2)
    return;

  int tmp, largest = i, l = i * 2, r = i * 2 + 1;

  if(A[i] > A[l])
    largest = i;
  else
    largest = l;
  if(A[r] > A[largest])
    largest = r;

  if(A[largest] != A[i]) {
    tmp = A[largest];
    A[largest] = A[i];
    A[i] = tmp;
    maxHeap(largest);
  }
}

void buildMaxHeap() {
  int i;
  for(i = n / 2;i > 0;i--)
    maxHeap(i);
}

int main() {
  int i;

  scanf("%d", &n);
  for(i = 1;i < n + 1;i++)
    scanf("%d", &A[i]);

  buildMaxHeap();

  for(i = 1;i < n + 1;i++)
    printf(" %d", A[i]);
  printf("\n");

  return 0;
}



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

using namespace std;

const int MAXN = 100000;

int n, m, s, t;
bool marked[MAXN * 3];
vector<int> adj[MAXN * 3];

int solve() {
    for (int i = 0; i < n * 3; ++i) marked[i] = false;
    queue<pair<int, int>> q;
    q.emplace(s, 0);
    
    while (!q.empty()) {
        auto p = q.front();
        q.pop();
        
        if (p.first == t) return p.second / 3;
        if (marked[p.first]) continue;
        marked[p.first] = true;
        
        for (int x : adj[p.first])
            q.emplace(x, p.second + 1);
    }
    
    return -1;
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int u, v; cin >> u >> v;
        --u; --v;
        adj[u].push_back(v + n);
        adj[u + n].push_back(v + 2 * n);
        adj[u + 2 * n].push_back(v);
    }
    cin >> s >> t;
    --s; --t;

    cout << solve() << endl;
    
    return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  int cnt_A[n + 10] = {};
  rep(i, n) {
    int tmp;
    cin >> tmp;
    cnt_A[tmp - 1]++;
  }

  sort(cnt_A, cnt_A + n);

  int ans = 0;
  for (int i = 0; i < n - k; i++) 
    ans += cnt_A[i];

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


Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <climits>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
constexpr int kMod = 1000000007;
typedef long long LL;

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

  if (b >= c) std::cout << b + c << std::endl;
  else {
    c -= b;

    std::cout << b * 2 + std::min(a+1, c) << std::endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;
 
void getfname(vector<int> &fname){
    string input;
    cin >> input;
    bool isnum = false;
    for(int i=0; i<(int)input.length(); i++){
        if('0' <= input[i] && input[i] <= '9'){
            if(isnum){
                fname.back() *= 10;
                fname.back() += input[i]-'0';
            }else{
                fname.push_back(input[i]-'0');
            }
            isnum = true;
        }else{
            fname.push_back(input[i] +inf);
            isnum = false;
        }
    }
}
 
int main(){
    int n;
    cin >> n;
    vector<vector<int> > fname(n+1);
    getfname(fname[0]);
    for(int i=1; i<n+1; i++){
        getfname(fname[i]);
        if(fname[i] < fname[0]){
            cout << "-" << endl;
        }else{
            cout << "+" << endl;
        }
    }
     return 0;
}


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




ll N;



int main(){
	cin >> N;
	
	vector<string> v(N);
	for ( int i = 0; i < N; i++ ){
		string s;
		cin >> s;
		int len = s.length();
		for ( int j = 0; j < len-1; j++ ){
			for ( int k = j+1; k < len; k++ ){
				if ( s[j] > s[k] )
					swap( s[j], s[k] );
			}
		}
		
		v[i] = s;
		//cout << s << endl;
	}
	
	sort(v.begin(), v.end());
	v.push_back("");
	
	ll result = 0;
	ll samecount = 1;
	for ( int i = 1; i <= N; i++ ){
		if ( v[i] == v[i-1] )
			samecount++;
		else {
			result += samecount * (samecount-1) / 2;
			samecount = 1;
		}
	}
	
	cout << result << endl;
	
	return 0;
}



Measured memory_bytes: 6528
#include <iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
#include<cmath>
#include<iomanip>
#include<queue>
#include<string>
using namespace std;

const double PI  =3.141592653589793238463;
#define pb push_back
#define pf push_front
#define sz(v)  ((int)(v).size());
#define all(v) ((v).begin()),((v).end())
typedef unsigned long long ull;
typedef long long ll;

typedef vector<int> vi;
typedef pair<int,int> pi;
//2 7 3 4 9

void printVec(vi v1)
{
    for(int i=0; i<v1.size(); i++)
        cout<<v1[i]<<" ";
    cout<<endl;
}
ll rec(ll r,ll c){

if(r<=1 || c<=1){
    return 1;
}


return rec(r-1,c)+rec(r,c-1);
}

int main()
{
    ios::sync_with_stdio(false);
    cout.tie(NULL);
    cin.tie(NULL);
ull n;cin>>n;
string str="";
while(n>=1){
    n--;
    str+='a'+(n%26);
    n/=26;
}reverse(str.begin(),str.end());
 cout<<str;
    return 0;
}


Measured memory_bytes: 3600
#include <iostream>

#include <vector>

#include <algorithm>

using std::cin;
using std::cout;
using std::endl;

using std::vector;

using std::sort;

static int
solve(int N, int C, int K, vector<int> &T)
{
  sort(T.begin(), T.end());
  int ret = 0;
  int n = 0;
  while (n < N)
  {
    ret++;
    int end = T[n] + K;
    int c = 1;
    n++;
    while (n < N && c < C && T[n] <= end)
    {
      c++;
      n++;
    }
  }
  return ret;
}

int
main()
{
  int N, C, K;
  cin >> N >> C >> K;
  vector<int> T(N);
  for (int n = 0; n < N; n++)
  {
    cin >> T[n];
  }
  cout << solve(N, C, K, T) << endl;
  return 0;
}


Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		String Hoshina="Hoshina";
		String Hoshino="Hoshino";
		while(N--!=0){
			String ans="";
			String s = br.readLine();
			for(int i = 0; i < s.length();i++){
				//System.out.println(i);
				if(s.length()-i-1 >=Hoshino.length()-1 && Hoshino.equals(s.substring(i,i+Hoshino.length()))){
					ans+=Hoshina;
					i+=Hoshino.length()-1;
				}
				else{
					ans+=s.charAt(i);
				}
			}
			System.out.println(ans);
		}

	}
}

Measured memory_bytes: 10000
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

vector<vector<int>> g;
vector<ll> ans;
vector<ll> v;

void dfs(int now,int pre=-1,ll preval=0){
     ll nval;
     nval=preval+v[now];
     ans[now]=nval;
     for (auto nx:g[now]){
          if (pre == nx) continue;
          dfs(nx,now,nval);
     }
}

int main(){
    int n,q;
    cin >> n >> q;
    g.resize(n);
    ans.resize(n);
    v.resize(n);
    rep(i,n-1){
         int x,y;
         cin >> x >> y;
         x--;y--;
         g[x].push_back(y);
         g[y].push_back(x);
    }
    rep(i,q){
         int x,y;
         cin >> x >> y;
         x--;
         v[x]+=y;
    }
    dfs(0);
    rep(i,n){
         cout << ans[i] << " ";
    }
    cout << endl;
     
     return 0;
}


Measured memory_bytes: 25856
(function() {
    'use strict';
 
    var lines = [];
    require('readline').createInterface({
      input: process.stdin,
      output: process.stdout
    }).on('line', function(line) {
      lines.push(line);
    });
    process.stdin.on('end', function() {
      //lines.forEach(function(line) {
        //var tokens = line.split(' ').map(Number);
        //    console.log(tokens[0] + ' ' + tokens[1]);
      //}
      //)
      ;
      
    // ToDo start
      var inputLine = lines[0].split(" ")
      var tate = inputLine[0]
      var yoko = inputLine[1]
      var anslines = []
    
        for(var i=0;i<tate;i++){
            anslines[i]=""

            for( var j=0;j<yoko;j++){
                if( lines[i+1][j] == "."){
                  var cnt =0
                  for(var tmpi=Math.max(i,0);tmpi<=Math.min(i+2,tate);tmpi++ ){
                      for(var tmpj=Math.max(j-1,0);tmpj<=Math.min(j+1,yoko);tmpj++){
                          if(lines[tmpi][tmpj]=="#"){
                              cnt++
                          }
                      }
                  }
//                  console.log("cnt:" + cnt)
                  anslines[i]= anslines[i]+cnt.toString()
              }else{
                anslines[i] = anslines[i] + "#"
//                console.log("cnt:" + "#")
              }
            }
        }
        for(var i=0;i<tate;i++){
            console.log(anslines[i])
        }
        
    // ToDo end

    });

    
})();
  
  

Measured memory_bytes: 7988
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		for(;;)
		{
			double q = scanner.nextDouble();
			if(q == -1)
			{
				break;
			}
			
			double x = q / 2;
			for(;;)
			{
				x = x - (x*x*x-q)/(3*x*x);
				if(Math.abs(x*x*x - q) < 0.00001*q)
				{
					System.out.printf("%1$.6f\n", x);
					break;
				}
			}		
		}
	}
}

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

using namespace std;
typedef long long ll;

ll n, a, b, c, d;

int main() {
    cin >> n >> a >> b >> c >> d;
    n -= 1;
    b = abs(b - a);

    ll x = d - c;
    bool check = false;
    for (ll i = 0; i <= n; i++) {
        ll j = (n - i);
        ll mid = (i - j) * c;
        ll lo = mid - j * x;
        ll hi = mid + i * x;
        check |= (lo <= b && b <= hi);
    }

    puts(check ? "YES" : "NO");
}


Measured memory_bytes: 256
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s;
        while(null != (s = in.readLine())){
            String[] arr = s.split(" ",0);
            double[] iarr = toDoubleArray(arr);
            calc(iarr);
        }
    }
    private static double[] toDoubleArray(String[] arr){
        double[] result = new double[arr.length];
        for(int i=0;i<arr.length;i++)
            result[i] = Integer.parseInt(arr[i]);
        return result;
    }
    private static void calc(double[] arr){
        double det = arr[0]*arr[4]-arr[1]*arr[3];
        double x = (arr[2]*arr[4]-arr[1]*arr[5])/det+0.0;
        double y = (-arr[2]*arr[3]+arr[0]*arr[5])/det+0.0;
        System.out.printf("%.3f %.3f\n",x,y);
    }
}

Measured memory_bytes: 16984
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define ld long double
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    map<int,int> a;
    ll cnt = 0;
    for (int i = 1; i<=n; i++) {
        int t;
        cin >> t;
        cnt += a[i-t];
        a[i+t]++;
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 20628
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int a, b;

int main() {
	cin >> a >> b;
	
	bool ans = (
		inII(a, 1, 9) &&
		inII(b, 1, 9)
	);
	
	cout << (ans ? a * b : -1) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;


void solve()
{
  bool used[1000010] = {};
    int s; cin >> s;
    int cnt = 1;
    while(true) {
        if (!used[s]) {
            used[s] = true;
            if (s % 2 == 0) s /= 2;
            else s = s * 3 + 1;
        } else {
            cout << cnt << endl;
            return;
        }
        cnt++;
    }
}

signed main(){

      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


Measured memory_bytes: 1280