akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O2") // "Ofast" for REAL FAST
// #pragma GCC optimization ("unroll-loops")

// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"

#include <bits/stdc++.h>
#define DEBUG 0

using namespace std;

#define rep(i, a, b) for (i = (a); i < (b); i++)
#define trav(a, x) for (auto & a : x)
#define all(x) (x).begin (), (x).end ()
#define rall(x) (x).rbegin (), (x).rend ()
#define sz(x) (int) (x).size ()
#define FASTIO cin.sync_with_stdio (0); cin.tie (0); cin.exceptions (cin.failbit);

typedef long long ll;

typedef pair <int, int> pii;
#define f first
#define s second
#define mp(x, y) make_pair (x, y)

typedef vector <int> vi;
#define pb(x) push_back (x)

#define ddcout if (DEBUG) cout
#define ddprintf(fmt, ...) if (DEBUG) printf (fmt, ##__VA_ARGS__)

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x3f3f3f3f3f3f3f3f;
const int  INFi  =  0x3f3f3f3f;
const ll   MAXN  =  1e+6+7; // UPDATE

vi idl ('s' + 1, 0), pts ('s' + 1, 0), mm = {'r', 's', 'p'};

int main ()
{
    int i, j, n, k, sum = 0;
    string t;
    idl['r'] = 'p';
    idl['p'] = 's';
    idl['s'] = 'r';
    cin >> n >> k >> pts['r'] >> pts['s'] >> pts['p'] >> t;
    vi pls (n, 'a');
    sort (all (mm), [] (auto & a, auto & b) { return pts[a] > pts[b]; });
    for (int itt = 0; itt < 3; itt++)
    {
        for (i = 0; i < t.length (); i++)
        {
            if (idl[t[i]] == mm[itt])
            {
                if (!(k <= i && pls[i - k] == idl[t[i]]))
                {
                    pls[i] = idl[t[i]];
                    sum += pts[idl[t[i]]];
                }
            }
        }
    }
    trav (a, pls)
        ddcout << (char) a;
    ddcout << "\n";
    cout << sum << "\n";



    return 0;
}


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

const ll INF = 1001001001;

const double PI=3.141592653;

const ll sosu = 1000000007;//大きい素数

//提出のときに言語がc＋＋似合っていることを確認する

//絶対値の関数
int z(int a,int b){
  if(a>b) return a-b;
  else return b-a;
}

int main(){
  int n,k;
  cin>>n>>k;
  vector<int>p(n);
  for(int i=0;i<n;i++){
    cin>>p[i];
  }
  sort(p.begin(),p.end());
  int ans=0;
  for(int i=0;i<k;i++){
    ans+=p[i];
  }
  cout<<ans<<endl;
  
}



Measured memory_bytes: 3624
q=1
while(1):

    n=int(raw_input())
    if n==0:    break
    A=[[0 for i in range(n)] for i in range(n)]
    up=1
    m=1
    for i in range(n):
        for j in range(i+1):
            if up:
                A[i-j][j]=m
            else:
                A[j][i-j]=m
            m+=1
        up=not up
    for i in range(n,(n-1)*2+1):
        for j in range(i-n+1,n):
            if up:
                A[i-j][j]=m
            else:
                A[j][i-j]=m
            m+=1
        up=not up
    print 'Case '+str(q)+':'
    for a in A:
        print ''.join([ '  '+str(x) if x<10 else ' '+str(x) for x in a])
    q+=1

Measured memory_bytes: 6428
import heapq

N,M=[int(s) for s in input().split()]
baito = []
for i in range(N):
  a,b=[int(s) for s in input().split()]
  heapq.heappush(baito, (-a,-b))
job=[]

while baito:
  x, y = heapq.heappop(baito)
  r = M-len(job)
  if -x > r:
    heapq.heappush(job, -y)
    heapq.heappop(job)       #より高給の仕事（ｙが高い）だった場合、他のを押し出す
  else:
    heapq.heappush(job, -y)
print(sum(job))  

Measured memory_bytes: 81368
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <cmath>
using namespace std;

typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// 0 <= unsigned int <= 4.2e9

int main()
{
    int N; cin >> N;
    if ((N%2) == 0) {
        cout << N/2 << endl;
    }
    else {
        cout << N/2 + 1 << endl;
    }
}


Measured memory_bytes: 256
import math

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    m = sum(A)/N
    ceil_eval = sum((a-math.ceil(m))**2 for a in A)
    floor_eval = sum((a-math.floor(m))**2 for a in A)
    ret = min(ceil_eval, floor_eval)
    print(ret)
    
solve()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <string>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	REP(i, t) fact[i+1]=fact[i]*(i+1)%MOD;
	fact_inv[t]=power(fact[t], MOD-2);
	FORR(i, 0, t) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である

    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }

    return true;
}
  
int main()
{
  int i,j;
  int n; cin >> n;
  vector <ll>A(n,0);
  vector <int>B(n,1);
  vector <bool>P(1000001,true);
  rep(i,n){cin >> A[i];}
  std::sort(A.begin(), A.end());
  if(n==1){cout << 1 << endl; return 0;}

  if(A[0]==1){
      if(n>1){
          if(A[1]==1){cout << 0 << endl; return 0;}
          else{cout << 1 << endl; return 0;}
      }
      else{cout << 1 << endl; return 0;}
  }

  rep(i,n){
      if(A[i]>500000){break;}
      for(j=A[i]*2;j<1000001;j+=A[i]){
          P[j] = false;
      }
  }

  FORR(i,0,n){
      if(i != 0){
          if(A[i]==A[i-1]){B[i]=0; B[i-1]=0; continue;}
      }
      if(B[i]==0){continue;}
      if(P[A[i]]==false){B[i]=0;}
  }

  cout << accumulate(B.begin(), B.end(), 0) << endl;

  return 0;
}


Measured memory_bytes: 5640
#include <cstdio>
#include <iostream>

using namespace std;

long long n,a[1000010];

long long f(long long l,long long r,long long x,long long y)
{
  long long ans=1e18;
  if(r-l<=1) return 0;
  for(int i=l+1;i<=r-1;i++) ans=min(f(l,i,x,x+y)+f(i,r,x+y,y)+a[i]*(x+y),ans);
  return ans;
}

int main()
{
  scanf("%lld",&n);
  for(int i=1;i<=n;i++)
  {
    scanf("%lld",&a[i]);
  }
  printf("%lld\n",f(1,n,1,1)+a[1]+a[n]);
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

            StringBuilder out = new StringBuilder();
            while (true) {
                int[] scores = Arrays.stream(in.readLine().split(" "))
                        .mapToInt(Integer::parseInt)
                        .toArray();
                int m = scores[0];
                int f = scores[1];
                int r = scores[2];

                if (m == -1 && f == -1 && r == -1) break;

                String grade;
                if (m == -1 || f == -1) {
                    grade = "F";
                }
                else {
                    int score = m + f;
                    if (80 <= score) grade = "A";
                    else if (65 <= score && score < 80) grade = "B";
                    else if (50 <= score && score < 65) grade = "C";
                    else if (30 <= score && score < 50) {
                        grade = 50 <= r ? "C" : "D";
                    }
                    else grade = "F";
                }

                out.append(grade);
                out.append("\n");
            }
            System.out.print(out);
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.exit(0);
    }
}



Measured memory_bytes: 31024
#include<bits/stdc++.h>
 
/*
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
*/
using namespace std;
 
#define LL long long
#define LD long double
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
const LL MOD = 1000000000 + 7;
const LD EPS = 0.0000001 ;
#define MPP(a, b, c) MP(MP(a, b), c)
#define PII pair<pair<LL,LL>, LL>
 
LL pows(LL a, LL b)
{
	if (b == 0) return 1LL;
	LL temp = pows(a, b / 2);
	temp = (temp * temp) % MOD;
	if (b % 2) temp = (temp * a) % MOD;
	return temp;
}

const int N = 21;

LL dp[N][(1 << N)];
LL arr[N][N];
int n; 

LL solve(int idx, int taken)
{
	if (idx == n) return 1;
	LL &ans = dp[idx][taken];
	if (ans != -1) return ans;
	ans = 0;
	for (int i = 0; i < n; i++){
		if (arr[idx][i] && !(taken & (1 << i))) ans = (ans + solve(idx + 1, taken | (1 << i))) % MOD;
	}
	return ans;
}

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

    cin >> n;
    for (int i = 0; i < n; i++){
    	for (int j = 0; j < n; j++){
    		cin >> arr[i][j];
    	}
    }
    memset(dp, -1, sizeof(dp));
    cout << solve(0, 0) << endl;

	return 0;
}

Measured memory_bytes: 344444
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
#define F first
#define S second

int n, x[105], y[105], h[105];

void solve(){
    cin >> n;
    for(int i = 0; i < n; ++i) cin >> x[i] >> y[i] >> h[i];

    vector<array<int, 3>> possible;
    for(int i = 0; i <= 100; ++i){
        for(int j = 0; j <= 100; ++j){
            set<int> heights;
            for(int k = 0; k < n; ++k){
                if(h[k] == 0) continue;
                int ch = h[k] + abs(x[k]-i) + abs(y[k]-j);
                heights.insert(ch);
            }

            if((int)heights.size() == 1){
                possible.push_back({i, j, *heights.begin()});
            }
        }
    }

    for(auto& a : possible){
        bool ok = true;
        for(int i = 0; i < n; ++i){
            if(h[i] != max(a[2] - abs(x[i]-a[0]) - abs(y[i]-a[1]), 0)){
                ok = false;
                break;
            }
        }
        if(ok){
            cout << a[0] << " " << a[1] << " " << a[2] << '\n';
            return;
        }
    }

    assert(false);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3616
import collections

n=int(input())
ans=[0]*(n+1)
tree=[[] for _ in range(n+1)]
for i in range(n-1):
  u,v,w=map(int,input().split())
  tree[u].append([v,w])
  tree[v].append([u,w])
q=collections.deque([1])
check=[False]*(n+1)
check[1]=True
tmp=tree[1][0]
if tmp[1]%2==0:
  ans[1]=1
  ans[tmp[0]]=1
else:
  ans[1]=1
  ans[tmp[0]]=0
while 1:
  if len(q)==0:
    break
  tmp=q.popleft()
  for i in range(len(tree[tmp])):
    v,w=tree[tmp][i][0],tree[tmp][i][1]
    if check[v]:
      continue
    else:
      check[v]=True
      if w%2==0:
        ans[v]=ans[tmp]
      else:
        ans[v]=abs(1-ans[tmp])
      q.append(v)
for i in range(1,n+1):
  print(ans[i])

Measured memory_bytes: 46128
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int N, M, a, b, ans = 1;
    cin >> N >> M;
    vector<pair<int, int>> req(M);
    vector<int> cut(N);

    for(int i=0; i<M; i++){
        cin >> a >> b;
        req[i] = make_pair(a, b);
    }

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

    int req_min = 1, req_max = N;
    for(int i=0; i<M; i++){
        req_min = max(req_min, req[i].first);
        req_max = min(req_max, req[i].second);
        if(req_min >= req_max){
            ans++;
            i--;
            req_min = 1;
            req_max = N;
        }
    }
    cout << ans << endl;
    return 0;
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
	int n;cin>>n;
	vector<int> d(n);
	int i;
	rep(i,n)cin>>d[i];
	int m;cin>>m;
	vector<int> t(m);
	rep(i,m)cin>>t[i];
	sort(all(d));
	sort(all(t));
	int nowd=0;
	int nowt=0;
	while(nowd<n&&nowt<m)
	{
		if(d[nowd]==t[nowt])
		{
			nowd++;
			nowt++;
		}
		else nowd++;
	}
	if(nowt==m)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}


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

//.define
//#define FILE_IN_OUT
#define RET(_x)                       return std::cout << (_x), 0;
#define all(_obj)                     (_obj).begin(), (_obj).end()
#define nfirst(_obj, _n)              (_obj).begin(), (_obj).begin() + (_n)
#define fori(_iterator, _begin, _end) for (int _iterator = (_begin); _iterator < (_end); ++_iterator)
#define forr(_iterator, _begin, _end) for (int _iterator = (_begin); _iterator >= (_end); --_iterator)
#define loop(_n)                      for (int i = 0; i < (_n); ++i)
#define div_ceil(_dividend, _divider) ((_dividend) - 1LL + (_divider)) / (_divider)
#define sz(_obj)                      static_cast<int>((_obj).size())
template<typename Tp>
inline void outarr(Tp _array, const std::size_t _N, const char* _delim = " ") {
    Tp end = _array + _N;
    for (Tp current = _array; current != end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll  = std::int64_t;
using pii = std::pair<int, int>;
constexpr int INF = INT_MAX;
constexpr int MOD = 1e9 + 7;

//.data
const int SIZE = 201;
int towns[SIZE];
int gr[SIZE][SIZE];
int n, m, r;
int cur, ans = INF;

void get(int len = 0) {
    if (len >= r) {
        ans = min(ans, cur);
        return;
    }

    fori(i, len, r) {
        if (len) {
            cur += gr[towns[len - 1]][towns[i]];
        }
        swap(towns[len], towns[i]);
        get(len + 1);
        swap(towns[len], towns[i]);
        if (len) {
            cur -= gr[towns[len - 1]][towns[i]];
        }
    }
}

void FloydWarshall() {
    fori(k, 0, n) {
        fori(i, 0, n) {
            fori(j, 0, n) {
                if (gr[i][k] < INF && gr[k][j] < INF) {
                    gr[i][j] = min(gr[i][j], gr[i][k] + gr[k][j]);
                }
            }
        }
    }
}

//.code
int main() {
#ifdef FILE_IN_OUT
    std::ifstream сin  ("input.txt",  std::ios::in);
    std::ofstream сout ("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif  

    cin >> n >> m >> r;

    fori(i, 0, n) {
        fori(j, 0, n) {
            gr[i][j] = INF;
        }
        gr[i][i] = 0;
    }

    loop(r) {
        int x;
        cin >> x;
        towns[i] = x - 1;
    }
    loop(m) {
        int a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        gr[a][b] = gr[b][a] = c;
    }

    FloydWarshall();

    get();

    cout << ans;

#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>

int main(void) {
  int n, i, j;
  int a[110];
  int sum = 0;
  double average;
  int ave[2];
  int ans[2] = {0};
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    sum += a[i];
  }

  average = sum * 1.0 / n;
  ave[0] = (int)ceil(average);
  ave[1] = (int)floor(average);

  for(i=0;i<2;i++){
    for(j=0;j<n;j++){
      ans[i] += (a[j] - ave[i]) * (a[j] - ave[i]);
    }
  }

  if(ans[0] < ans[1]){
    printf("%d\n", ans[0]);
  } else {
    printf("%d\n", ans[1]);
  }

  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector <long long> a(n + 1), b(n);
    for (int tsumugi = 0; tsumugi < n + 1; tsumugi++){
        cin >> a[tsumugi];
    }
    for (int matsuri = 0; matsuri < n; matsuri++){
        cin >> b[matsuri];
    }

    long long ans = 0;

    //i番目の街について考える
    for (int kaori = 0; kaori < n; kaori++){
        ans += min(a[kaori], b[kaori]);
        if (b[kaori] > a[kaori]){
            b[kaori] -= a[kaori];
            ans += min(a[kaori + 1], b[kaori]);
            if (a[kaori + 1] > b[kaori]){
                a[kaori + 1] -= b[kaori];
            }
            else{
                a[kaori + 1] = 0;
            }
        }
    }

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

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


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

int main(){
  int N;
  cin>>N;
  int kuku[110];
  for(int i=1;i<101;i++){
    kuku[i]=0;
  }
  
  for(int a=1;a<10;a++){
    for(int b=a;b<10;b++){
      kuku[a*b]=1;
    }
  }
  
  if(kuku[N]==1){
    cout<<"Yes"<<endl;
    return 0;
  }
  cout <<"No"<<endl;
  return 0;
}

      

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
main(){
  int x1,y1,x2,y2,x3,y3,x4,y4;
  cin >> x1 >> y1 >> x2 >> y2;
  int dx,dy;
  dx =x2-x1;
  dy =y2-y1;
  x3 =x2-dy;
  y3 =y2+dx;
  x4 =x1-dy;
  y4 =y1+dx;
  cout << x3 << " " << y3 << " " << x4 << " " << y4;
  return 0;
}  

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

Measured memory_bytes: 580
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll h, w;
  cin >> h >> w;
  vector<string> s(h);
  REP(i, h) cin >> s[i];
  vector<vector<ll>> L(h, vector<ll>(w)), R(h, vector<ll>(w)), D(h, vector<ll>(w)), U(h, vector<ll>(w));
  
  REP(i, h){
    REP(j, w){
      if(s[i][j] == '#') L[i][j] = 0;
      else if(j == 0) L[i][j] = 1;
      else L[i][j] = L[i][j-1] + 1;

      if(s[i][w-1-j] == '#') R[i][w-1-j] = 0;
      else if(j == 0) R[i][w-1-j] = 1;
      else R[i][w-1-j] = R[i][w-j] + 1;
    }
  }

  REP(j, w){
    REP(i, h){
      if(s[i][j] == '#') U[i][j] = 0;
      else if(i == 0) U[i][j] = 1;
      else U[i][j] = U[i-1][j] + 1;

      if(s[h-1-i][j] == '#') D[h-1-i][j] = 0;
      else if(i == 0) D[h-1-i][j] = 1;
      else D[h-1-i][j] = D[h-i][j] + 1;
    }
  }

  ll ans = 0;
  REP(i, h) REP(j, w){
    chmax(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 136272
n, k = gets.chomp.split().map(&:to_i)
R, S, P = gets.chomp.split().map(&:to_i)
t = gets.chomp

dp = Array.new(n, 0)

def point(c)
  case c
  when 'r'
    P
  when 's'
    R
  when 'p'
    S
  end
end

n.times do |i|
  if i < k - 1 || t[i-k] != t[i]
    dp[i] = point(t[i])
  else
    if dp[i-k] < point(t[i])
      dp[i-k] = 0
      dp[i] = point(t[i])
    else
      dp[i] = 0
    end
  end
end

# p dp
puts dp.inject(:+)

Measured memory_bytes: 2812
#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;

  int count = 0;
  char last;
  for(int i = 0; i < N; i++) {
    if(S[i] != last) {
      count++;
    }
    last = S[i];
  }

  cout << count;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, rad, dmg;
	cin >> n >> rad >> dmg;
	
	vector<pll> a(n);
	FOR(i,0,n) cin >> a[i].xx >> a[i].yy;
	sort(all(a));
	
	vl add_before(n+1);
	ll sum = 0, res = 0;
	FOR(i,0,n) {
		sum += add_before[i];
		ll h = a[i].yy - sum;
		ll k = h <= 0 ? 0 : (h+dmg-1)/dmg;
		
		res += k;
		sum += k*dmg;
		ll j = lower_bound(all(a),mp(a[i].xx+2*rad+1,-oo)) - begin(a);
		add_before[j] -= k*dmg;
	}
	cout << res << endl;
}



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

const int MAX_LENGTH = 1005;
const int INF = 1001001001;

int main()
{
    string s1, s2;
    cin >> s1 >> s2;
    int dp[MAX_LENGTH][MAX_LENGTH];
    for(int i=0;i<s1.size() + 1;++i)
        for(int j=0;j<s2.size() + 1;++j)
            dp[i][j] = INF;
    dp[0][0] = 0;
    for(int i=0; i<s1.size() + 1; ++i)
    {
        for(int j=0; j<s2.size() + 1; ++j)
        {
            dp[i + 1][j + 1] = min(dp[i+1][j+1], dp[i][j] + int(s1[i] != s2[j]));
            dp[i + 1][j] = min(dp[i+1][j], dp[i][j] + 1);
            dp[i][j + 1] = min(dp[i][j+1], dp[i][j] + 1);
        }
    }
    /*
    for(int i=0;i<s1.size() + 1;++i){
        for(int j=0;j<s2.size() + 1;++j){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    */

    cout << dp[s1.size()][s2.size()] << endl;

}



Measured memory_bytes: 7112
from collections import OrderedDict
N = int(input())
A = list(map(int, input().split()))
# maybe use a dictionary
ball_values = OrderedDict()
for val in A:
  if val not in ball_values:
    ball_values[val] = 1
  else:
    ball_values[val] += 1
# get total pairs of all balls
total_possible_combos = sum(item[1]*(item[1]-1)//2 for item in ball_values.items())
# for each k, take away the loss of pairs due to removing it
k_outputs = [total_possible_combos-(ball_values[val]-1) for val in A]
[print(value) for value in k_outputs]

Measured memory_bytes: 55308
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect

const int N = 2e5 + 7, MOD = 1e9 + 7;

vector <int> g[N];
int n, f[N] = {1}, rf[N] = {1}, dp[N], sz[N], ans[N];

int binpow(int x) {
    int ret = 1, d = MOD - 2;
    while (d) {
        if (d & 1)
            ret = ret * x % MOD;
        x = x * x % MOD;
        d >>= 1;
    }
    return ret;
}

int binom(int n, int k) {
    if (k > n) return 1;
    return f[n] * rf[k] % MOD * rf[n - k] % MOD;
}

void dfs(int v, int p) {
    dp[v] = sz[v] = 1;
    for (int u : g[v])
        if (u != p) {
            dfs(u, v);
            sz[v] += sz[u];
        }
    int calc = sz[v] - 1;
    for (int u : g[v]) 
        if (u != p) {
            dp[v] = dp[v] * dp[u] % MOD * binom(calc, sz[u]) % MOD;
            calc -= sz[u];
        }
}

void calc_ans(int v, int p, int cur) {
    ans[v] = dp[v] * cur % MOD * binom(n - 1, n - sz[v]) % MOD;
    for (int u : g[v])
        if (u != p)
            calc_ans(u, v, ans[v] * binpow(dp[u]) % MOD * binpow(binom(n - 1, sz[u])) % MOD);
}

void solve() {
    loop1(i, N - 1) {
        f[i] = f[i - 1] * i % MOD;
        rf[i] = binpow(f[i]);
    } 
    cin >> n;
    loop(i, n - 1) {
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs(1, 1);
    calc_ans(1, 1, 1);
    loop1(i, n)
        cout << ans[i] << "\n";
}
 
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}


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

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
    int n;
    cin >> n;
    vector<vector<int> > a(3),dp(3);
    for(int i = 0; i < 3; i++){
        a[i].resize(n);
        dp[i].resize(n);
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            cin >> a[j][i];
        }
    }
    for(int i = 0; i < 3; i++){
        dp[i][0] = a[i][0];
    }
    for(int i = 1; i < n; i++){
        dp[0][i] = max(dp[1][i-1],dp[2][i-1]) + a[0][i];
        dp[1][i] = max(dp[2][i-1],dp[0][i-1]) + a[1][i];
        dp[2][i] = max(dp[0][i-1],dp[1][i-1]) + a[2][i];
    }

    cout << max(max(dp[0][n-1],dp[1][n-1]),dp[2][n-1]) << endl;

    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll a, p;
string str;

int main(){
	cin >> a >> p;
	p += 3*a;
	cout << p/2 << endl;
	return 0;
}

Measured memory_bytes: 764
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        for (int i = s.length() - t.length(); i >= 0; i--) {
            String ss = s.substring(i, i + t.length());
            if (check(ss, t)) {
                char[] c = s.toCharArray();
                for (int j = 0; j < c.length; j++) {
                    if (c[j] == '?') {
                        if (j >= i && j < i + t.length()) {
                            c[j] = t.charAt(j - i);
                        } else {
                            c[j] = 'a';
                        }
                    }
                }
                s = new String(c);
                System.out.println(s);
                return;
            }
        }
        System.out.println("UNRESTORABLE");
    }

    static boolean check(String s, String t) {
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '?') {
                continue;
            }
            if (s.charAt(i) != t.charAt(i)) {
                return false;
            }
        }
        return true;
    }
}


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

int main(){
    int N; cin >> N;
    vector<vector<int>> dp(N,vector<int>(3));
    const int a = 0, b = 1, c = 2;

    for( int i = 0; i < N; i++ ){
        int A,B,C; cin >> A >> B >> C;
        if( i == 0 ){
            dp[i][a] = A;
            dp[i][b] = B;
            dp[i][c] = C;
            continue;
        }
        dp[i][a] = max(dp[i-1][b],dp[i-1][c]) + A;
        dp[i][b] = max(dp[i-1][a],dp[i-1][c]) + B;
        dp[i][c] = max(dp[i-1][b],dp[i-1][a]) + C;
    }

    cout << max(  max( dp[N-1][a], dp[N-1][b] ), dp[N-1][c]  ) << endl;
}

Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    string A, B, C; cin >> A >> B >> C;
    cout << "A" << B[0] << "C" << endl;
    return 0;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll N,K;
vector<ll> P,C;
void input(){
    fast_io();
    cin >> N >> K;
    P = fetch_vec<ll>(N);
    C = fetch_vec<ll>(N);
}

int solve(){
    for(auto &x:P) x--;
    ll ans = -(ll)(1e18);
    for (int i = 0; i < N; i++)
    {
        int x = i;
        ll score = 0LL;
        ll T = K;
        ll t = 0LL;
        do{
            x = P[x];
            score += C[x];
            T--;
            t++;
            ans = max(ans, score);
        }while((x!=i) && (T>0));

        ans = max(ans, score);

        if((T>0LL) && (score>0LL)){
            T %= t;
            if((ll)(K/t-1)>1){
                score *= (ll)(K/t-1);
                T += t;
            }
            ans = max(ans, score);
            while(T>0LL){
                x = P[x];
                score += C[x];
                T--;
                t++;
                ans = max(ans, score);
            }
        }
        ans = max(ans, score);
    }
    cout << ans << endl;
    return 0;
}   

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

Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <numeric>


int main()
{
	std::string n;

	std::cin >> n;


	if ((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3])) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int C[10005] , Degree[10005] , Value[10005];
set<int> Graph[10005];
queue<int> Q;

int main(){
    int N , u , v , i , Ans = 0;
    scanf( "%d" , &N );

    for( i = 1 ; i < N ; ++i ){
        scanf( "%d%d" , &u , &v );
        Graph[u].insert( v );
        Graph[v].insert( u );
        ++Degree[u];
        ++Degree[v];
    }

    for( i = 1 ; i <= N ; ++i )
        scanf( "%d" , C + i );

    sort( C + 1 , C + N + 1 );

    for( i = 1 ; i < N ; ++i )
        Ans += C[i];

    for( i = 1 ; i <= N ; ++i )
        if( Degree[i] == 1 ) Q.push( i );
    
    i = 1;

    while( true ){
        u = Q.front();
        Q.pop();
        Value[u] = C[i++];
        v = *Graph[u].begin();
        --Degree[u];
        --Degree[v];
        Graph[u].erase( v );
        Graph[v].erase( u );
        if( Degree[v] == 1 ) Q.push( v );
        if( i == N ){
            Value[v] = C[N]; 
            break;
        }
    }

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

    for( i = 1 ; i <= N ; ++i )
        printf( "%d " , Value[i] );

    puts( "" );
    return 0;
}

Measured memory_bytes: 1920
N=int(input())
h=list(map(int, input().split()))

def p(h):
  if h!=[]:
    minh=min(h)
    if len(h)==1:
      return h[0]
    else:
      mini=h.index(minh)
      return minh+p([i-minh for i in h[:mini]])+p([i-minh for i in h[mini+1:]])
  else:
    return 0

print(p(h))

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

int main() {
    int n;
    cin>>n;
    int fib[100];
    fib[0] = 1;
    fib[1] = 1;

    for (int i = 2; i <= n; ++i) {
        fib[i] = fib[i - 1] + fib[i-2];
    }

    cout<<fib[n]<<endl;
}


Measured memory_bytes: 3108
#include<iostream>
#include<algorithm>
using namespace std;
long long p[200010],q[200010],r[200010],z[200010],sum;
int x,y,a,b,c,cnt;
bool cmp(const long long &u,const long long &v)
{
     return u>v;
}
int main()
{
    int i,t;
    cin>>x>>y>>a>>b>>c;
    for(i=1;i<=a;i++) cin>>p[i];
    for(i=1;i<=b;i++) cin>>q[i];
    for(i=1;i<=c;i++) cin>>r[i];
    sort(p+1,p+a+1,cmp);
    sort(q+1,q+b+1,cmp);
    for(i=1;i<=x;i++) z[++cnt]=p[i];
    for(i=1;i<=y;i++) z[++cnt]=q[i];
    sort(z+1,z+cnt+1,cmp);
    sort(r+1,r+c+1,cmp);
    for(i=1;i<=x+y;i++) sum+=z[i];
    t=0;
    for(i=x+y;i>=1;i--)
    {
        t++;
        if(z[i]<r[t]) sum+=r[t]-z[i]; else break;
    }
    cout<<sum;
    //system("pause");
}
    


Measured memory_bytes: 6272
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	int n;
	cin >> n;
	vector<pii> vp(n);
	rep(i, n) {
		int a;
		cin >> a;
		vp[i] = pii(a, i + 1);
	}
	sort(vp.begin(), vp.end());
	rep(i, n - 1) cout << vp[i].second << ' ';
	cout << vp[n - 1].second << endl;
}


Measured memory_bytes: 1664
"use strict";

const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const A = arg[1].split(" ").map(n=>parseInt(n));
    
    let k = 1;
    
    for(let i in A) {
        if(A[i] % 2 === 0) {
            k *= 2;
        }
    }
    
    console.log(Math.pow(3, N) - k);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
s = input()[::-1] # reversed

cnt = [0] * 2019
cnt[0] = 1

num, d = 0, 1

for c in s:
   num += int(c) * d
   num %= 2019
   d *= 10
   d %= 2019
   cnt[num] += 1

ans = 0
for t in cnt:
   ans += t * (t - 1) // 2

print(ans)


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


#include <cstdlib>
#include <sstream>
#include <climits>
#include <complex>

using namespace std;

#define MP make_pair

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

typedef long long LL;
typedef pair<int,int> PII;

bool is_palid[100000];

int main() {
  REP (i, 10001) {
    stringstream ss;
    ss << i;
    string s = ss.str();
    reverse(s.begin(), s.end());
    if (ss.str() == s) {
      is_palid[i] = true;
    }
  }

  int n;
  cin >> n;

  int up;
  int down;
  REP (i, 10001) {
    if (i <= n && is_palid[i]) {
      down = i;
    }
    if (10000 - i >= n && is_palid[10000 - i]) {
      up = 10000 - i;
    }
  }
  if (n - down <= up - n) {cout << down << endl;}
  else {cout << up << endl;}
}

Measured memory_bytes: 1228
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long LL;

const int N = 100010;

int n;
int a[N], b[N], c[N], cnt[N];
LL sum[N];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &b[i]);
    sort(b + 1, b + n + 1);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &c[i]);
    sort(c + 1, c + n + 1);
    for (int i = 1, j = 1; i <= n; ++i) {
        while (j < n && b[i] >= c[j]) ++j;
        if (b[i] >= c[j]) break;
        cnt[i] = n - j + 1;
    }
    for (int i = n; i; --i)
        sum[i] = sum[i + 1] + cnt[i];
    LL res = 0;
    for (int i = 1, j = 1; i <= n; ++i) {
        while (j < n && a[i] >= b[j]) ++j;
        if (a[i] >= b[j]) break;
        res += sum[j];
    }
    printf("%lld\n", res);
    return 0;
}

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

int main(){
	int n; cin>>n;
	vector<int>a(1e6+1,0);
	for(int i=0;i<n;++i){
		int A; cin>>A;
		++a.at(A);
	}
	int ans=0;
	for(int i=0;i<a.size();++i){
		if(a.at(i)==0)continue;
		if(a.at(i)==1)++ans;
		for(int j=i;j<a.size();j+=i){
			a.at(j)=0;
		}
	}
	cout<<ans<<"\n"s;
}

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

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

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

    int i, j, k;
    int n, b, f, r, v;
    vector<vector<int>> tenants(12, vector<int>(10));

    cin>>n;
    rep(i, n) {
        cin>>b>>f>>r>>v; b--; f--; r--;
        tenants[b * 3 + f][r] += v;
    }
    rep(k, 4) {
        rep(j, 3) {
            rep(i, 10) {
                cout<<" "<<tenants[k * 3 + j][i];
            }
            cout<<endl;
        }
        if (k < 3) cout<<"####################"<<endl;
    }
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(long long i = 0; i < (long long)(N); i++)
#define repr(i,N) for(long long i = (long long)(N) - 1; i >= 0; i--)
#define rep1(i,N) for(long long i = 1; i <= (long long)(N) ; i++)
#define repr1(i,N) for(long long i = (N) ; (long long)(i) > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; template<class T = ll> using V = vector<T>;
using vi = V<int>; using vl = V<>; using vvi = V< V<int> >;
constexpr int inf = 1001001001; constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif

#define in2(N,s,t) rep(i,N){in(s[i] , t[i]);}
#define in3(N,s,t,u) rep(i,N){in(s[i] , t[i] , u[i]);}
using vd = V<double>; using vs = V<string>; using vvl = V< V<> >;
template<typename T>using heap = priority_queue< T , V<T> , greater<T> >;

using P = pair<int,int>; using vp = V<P>;
constexpr int MOD = /** 1000000007; //*/ 998244353;
//////////////////

void solve(){
  ini(N , C , K);
  vi t(N); in(t);
  sort(all(t));
  int idx = 0;
  int ans = 0;
  while(idx != N){
    ans += 1;
    int bus = t[idx] + K;
    int cnt = 0;
    while (idx != N)
    {
      if(t[idx] > bus) break;
      idx++; cnt++;
      if(cnt == C) break;
    }
  }
  out(ans);
}

Measured memory_bytes: 640
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int arr[] = new int[n];

        List<Integer> list = new ArrayList<>();

        for (int i=0; i<n; i++) arr[i] = sc.nextInt();

        int z =0;
        for (int i=0; i<n-1; i++){
            if (arr[i]==arr[i+1]) z++;
        }

        if (n==1){
            System.out.println(0);
        }else if((z-1)==arr.length){
            System.out.println(z);
        }else {

            int a = 0;

            for (int i = n - 1; i >= 1; i--) {
                if (arr[i - 1] >= arr[i]) {
                    a++;
                    if (i==1){
                        list.add(a);
                    }
                } else {
                    list.add(a);
                    a = 0;
                }
            }
            Collections.sort(list);
            System.out.println(list.get(list.size() - 1));
        }
    }
}


Measured memory_bytes: 51576
#include<bits/stdc++.h>
using namespace std;
main(){
  int n,r=0;
  cin>>n;
  vector<string> s(n);
  for(auto &str:s)cin>>str;

  for(int i=0;i<n;++i){
    bool m=true;
    for(int j=0;m&&j<n;++j){
      for(int k=0;m&&k<n;++k)
        if(s[(k+j)%n][(i+j)%n]!=s[j][(i+j+k)%n])m=false;
    }
    r+=m*n;
  }
  cout<<r;
}

Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<cstdio>
#include<string>

typedef long long LL;

using namespace std;

int main()
{
	string s1;
	string s2;
	cin >> s1;
	cin >> s2;
	int flag = 1;
	for(int i = 0;i < s1.size();i++)
	{
		if(s1[i] != s2[i])
		{
			flag = 0;
			break;
		}
	}
	if(!flag)
		printf("No\n");
	else
		printf("Yes\n");
	return 0;
} 

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MAX=200005;
const int INF=0x3f3f3f3f;
int n,a[MAX];
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    for(int i=n-1;i>=0;i-=2) printf("%d ",a[i]);
    for(int i=n%2;i<n;i+=2) printf("%d ",a[i]);
    return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 2e7 + 9, M = 1e7, OO = 0x3f3f3f3f;
int main()
{
string array[7]={ "SUN", "MON", "TUE", "WED", "THU", "FRI","SAT"};
string day;
cin>>day;
int i,pos;
for(i=0;i<7;++i){
    if(day==array[i]){
        pos=i;
        break;
    }
}
cout<<7-pos;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>

using namespace std;

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

    int n; cin >> n;
    long double x[n], y[n];
    for(int i = 0; i < n; ++i) cin >> x[i] >> y[i];

    long double dist[n][n];
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            dist[i][j] = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));

    int ord[n]; for(int i = 0; i < n; ++i) ord[i] = i;
    int cnt = 0;
    long double sum = 0;
    do
    {
        ++cnt;
        for(int i = 1; i < n; ++i)
            sum += dist[ord[i - 1]][ord[i]];
    }while(next_permutation(ord, ord + n));

    cout << setprecision(20) << sum / cnt;
    return 0;
}


Measured memory_bytes: 256
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N = 10**6     #出力の制限
mod = 10**9+7 
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

X ,Y = map(int, input().split())
n = 2 * Y - X
m = 2 * X - Y
r = 1
if n % 3 != 0:
    r = 0
elif m % 3 != 0:
    r = 0
else:
    r = cmb(n//3+m//3,n//3,mod)
print(r)

Measured memory_bytes: 122108
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main()
{
    int R[MAX], n;

    cin >> n;

    for (int i = 0; i < n; i++) cin >> R[i];

    int maxv = -2000000000;
    int minv = R[0];

    for (int i = 1; i < n; i++) {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }

    cout << maxv << endl;
    return 0;
}



Measured memory_bytes: 3864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll n, k;
	cin>>n>>k;
	vector<ll> a(n);
	map<ll, ll> index;
	for(int i = 0; i < n; ++i)
	{
		cin>>a[i];
		// count[a[i]]++;
	}
	// vector<pair<ll, ll> > v(n), temp1(n);
	
	vector<ll> temp(n);
	temp = a;
	sort(temp.begin(), temp.end());
	// temp.erase(unique(temp.begin(), temp.end()), temp.end());
	// for(int i = 0 ; i < temp.size(); i++)
	// {
	// 	temp1[i].first = temp[i];
	// 	temp1[i].second = i;
	// }
	for(int i = temp.size()-1; i >=0 ; i--)
	{
		index[temp[i]] = i;
	}
	// sort(v.begin(), v.end());
	// temp1=v;
	// temp1.erase(unique(temp1.begin(), temp1.end()), temp1.end());

	// for(int i = 0; i < temp1.size(); i++)
	// {
	// 	cout<<temp1[i].first<<"  "<<temp1[i].second<<endl;
	// }
	vector<ll> ans(n, 0);
	for(int i = 0; i < n; i++)
	{
		for(int j = i+1; j < n; j++)
		{
			if(a[i]>a[j])
			{
				ans[i]++;
			}
		}
	}
	// for(int i = 0; i < n; i++)
	// {
	// 	cout<<ans[i]<<endl;
	// }
	ll f_ans = 0, mod = 1000000007;
	for(int i = 0; i < n; i++)
	{
		// cout<<
		// ll t = (k%mod)*((2* ans[i]%mod)+(((k-1+mod)%mod)*(index[a[i]]%mod)%mod)%mod)%mod;
		ll z = ((k*(k-1))/2)%mod;
		ll t = ((k%mod * ans[i]%mod)%mod + (z%mod * index[a[i]]%mod)%mod)%mod;
		// t/=2;
		// cout<<"t "<<t<<endl;
		f_ans=(t%mod+f_ans%mod)%mod;
		// f_ans/=2;
	}
	cout<<f_ans%mod<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>

using namespace std;

int func(string &s, vector<pair<char, char> > &vp, int pos)
{
  int N = s.size();
  int Q = vp.size();
  for (int i = 0; i < Q; ++i) {
    char t = vp[i].first;
    char d = vp[i].second;
    if (s[pos] == t) {
      if (d == 'L') --pos;
      else ++pos;
      if (pos < 0) return -1;
      if (pos >= N) return N;
    }
  }
  return pos;
}

int myfind(string &s, vector<pair<char, char> > &vp, int num)
{
  int N = s.size();
  if (func(s, vp, 0) >= num) return 0;
  if (func(s, vp, N - 1) < num) return N;
  int L = 0;
  int R = N - 1;
  while (R - L > 1) {
    int M = (L + R) / 2;
    if (func(s, vp, M) < num) {
      L = M;
    }
    else {
      R = M;
    }
  }
  return R;
}

int main()
{
  int N, Q;
  cin >> N >> Q;
  string s;
  cin >> s;
  vector<pair<char, char> > vp;
  for (int i = 0; i < Q; ++i) {
    char t, d;
    cin >> t >> d;
    vp.push_back(make_pair(t, d));
  }

  int begin = myfind(s, vp, 0);
  int end = myfind(s, vp, N);
  cout << end - begin << endl;
  
  return 0;
}


Measured memory_bytes: 1024