akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N,K; cin >> N >> K;
    veci A(N); REP(i,N) cin >> A[i];
    if((N-1)%(K-1) == 0) cout << (N-1)/(K-1) << endl;
    else cout << (N-1)/(K-1)+1 << endl;
}

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

int main() {
    int ans, h, w, m;
    cin >> h >> w >> m;
    int a, b;
    //vector<int>r(h,0),c(w,0);
    //vector<vector<bool>>v(h,vector<bool>(w,0));
    vector<pair<int, int>>bomb(m);
    vector<int>p1(h, 0),p2(w, 0);
    rep(i, m) {
        cin >> a >> b;
        a--;
        b--;
        p1[a]++;
        p2[b]++;
        bomb[i] = make_pair(a, b);
    }
    ll cr = 0,cc = 0;
    int maxR,maxC;
    maxR = p1[0];
    rep(i, h) maxR = max(maxR,p1[i]);
    rep(i, h) {
        if (maxR == p1[i]) {
            cr++;
        }
    }
    maxC = p2[0];
    rep(i, w) maxC = max(maxC,p2[i]);
    rep(i, w) {
        if (maxC == p2[i]) {
            cc++;
        }
    }
    int cb = 0;
    rep(i, m) {
        if (p1[bomb[i].first]==maxR && p2[bomb[i].second]==maxC) {
            cb++;
        }
    }
    if (cr*cc > cb) {
        ans = maxC + maxR;
    }else {
        ans = maxC + maxR - 1;
    }
    cout << ans << endl;
    return 0;
}



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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    static int p[250001], pinv[250001], dist[250001];

    cin >> n;
    for(int i=1;i<=n*n;++i){
        cin >> p[i];
        pinv[p[i]] = i;
        int x = (i-1) / n, y = (i-1) % n;
        dist[i] = min({x, y, n-1-x, n-1-y});
    }
    
    int64_t ans = 0;

    for(int i=1;i<=n*n;++i){
        int j = p[i];
        int x = (j-1) / n, y = (j-1) % n;
        int c = dist[j];
        if(x   > 0) c = min(c, dist[j-n] + (pinv[j-n] > i ? 1 : 0));
        if(x+1 < n) c = min(c, dist[j+n] + (pinv[j+n] > i ? 1 : 0));
        if(y   > 0) c = min(c, dist[j-1] + (pinv[j-1] > i ? 1 : 0));
        if(y+1 < n) c = min(c, dist[j+1] + (pinv[j+1] > i ? 1 : 0));
        ans += dist[j] = c;
        queue<int> q;
        q.push(j);
        while(!q.empty()){
            int v = q.front();
            int vx = (v-1) / n, vy = (v-1) % n;
            q.pop();
            int cc = dist[v] + (pinv[v] > i ? 1 : 0);
            if(vx   > 0 && dist[v-n] > cc){ q.push(v-n); dist[v-n] = cc; }
            if(vx+1 < n && dist[v+n] > cc){ q.push(v+n); dist[v+n] = cc; }
            if(vy   > 0 && dist[v-1] > cc){ q.push(v-1); dist[v-1] = cc; }
            if(vy+1 < n && dist[v+1] > cc){ q.push(v+1); dist[v+1] = cc; }
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 6504
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
using namespace std;

int main(){
    double a,b,h;
    
cin >> a >> b >> h;
    
    cout << ((a+b)/2) * h << endl;

    return 0;

}

Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 13.01.2020 23:29:32       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    --p[i];
  }
  vector<int> a(n);
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    a[i] = i * n + 1;
    b[i] = (n - 1 - i) * n + 1;
  }
  for (int i = 0; i < n; i++) {
    a[p[i]] += i;
  }
  for (int i = 0; i < n; i++) {
    if (i > 0) {
      cout << " ";
    }
    cout << a[i];
  }
  cout << '\n';
  for (int i = 0; i < n; i++) {
    if (i > 0) {
      cout << " ";
    }
    cout << b[i];
  }
  cout << '\n';
  return 0;
}


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

// DAME:
int main() {
    ll L, R;
    cin >> L >> R;
    if(L*R<2019){
        cout << L*(L+1) << endl;
        return 0;
    }

    map<ll, ll> mp;
    for(ll i=L; i<=min(L+2019, R) ; i++){
        ll aa = i%2019;
        if(!mp[aa]){
            mp[aa]++;
        }
    }

    int ans = 2019;
    for(int i=0; i<2018; i++){
        if(!mp[i]){
            continue;
        }
        if(i==0){
            cout << 0 << endl;
            return 0;
        }
        for(int j=i+1; j<2019; j++){
            if(!mp[j]){
                continue;
            }
            ans = min(i*j%2019, ans);
        }
    }

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

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

int main(){
  int N, t, s, u, i, n;
  cin >> N;
  t = 0;
  s = 10;
  u = 0;
  i = 0;
  n = N;
    
  while(i < N){
    if(N / s == 0){
      u += 1;
      break;
    }
    else{
      s *= 10;
      u += 1;
    }
    i++;
  }
  for(int l = 0; l < u; l++){
    t += n % 10;
    n = n / 10;
  }
  if(N % t == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}



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

using ll = long long;

int main(){
  int n;
  cin >> n;
  vector<ll> len(n);
  for(int i = 0; i < n; i++){
    cin >> len.at(i);
  }
  ll cnt = 0;
  for(int i = 1; i < n; i++){
    if(len.at(i-1) > len.at(i)){
      cnt = cnt + len.at(i-1) - len.at(i);
      len.at(i) = len.at(i-1);
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 4744
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define int long long
using namespace std;
signed main() {
	int A, B, K;
	cin >> A >> B >> K;

	if (A >= K) {
		cout << A - K << " " << B << endl;
	}
	else if (A + B <= K) {
		cout << 0 << " " << 0 << endl;
	}
	else {
		cout << 0 << " " << B - (K - A) << endl;
	}
}

Measured memory_bytes: 3636
mod = 10**9+7
N = int(input())
if N == 1:
    print(0)
    exit()
plus = 1
minus = 1
cap = 1
for _ in range(N):
    plus *= 10
    minus *= 9
    cap *= 8
    plus %= mod
    minus %= mod
    cap %= mod
print((plus-2*minus+cap)%mod)

Measured memory_bytes: 9184
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int main(){
    long long x;
    cin >> x;

    long long ans;
    if(400 <= x and x <= 599) ans = 8;
    else if(600 <= x and x <= 799) ans = 7;
    else if(800 <= x and x <= 999) ans = 6;
    else if(1000 <= x and x <= 1199) ans = 5;
    else if(1200 <= x and x <= 1399) ans = 4;
    else if(1400 <= x and x <= 1599) ans = 3;
    else if(1600 <= x and x <= 1799) ans = 2;
    else if(1800 <= x and x <= 1999) ans = 1;

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

Measured memory_bytes: 3640
n, m, q = gets.split.map(&:to_i)
abcd = q.times.map {gets.split.map(&:to_i)}

a = Array.new(m) {|i| [i+1]}

(n-1).times do
    x = []
    a.each do |e|
        e[-1].upto(m) {|i| x << e + [i]}
    end
    a = x
end

ans = 0
a.each do |ary|
    sum = 0
    q.times do |i|
        sum += abcd[i][3] if ary[abcd[i][1] - 1] - ary[abcd[i][0] - 1] == abcd[i][2]
    end
    ans = sum if ans < sum
end

puts ans

Measured memory_bytes: 41168
A=int(input())
B=int(input())
C=int(input())

X=int(input())
sumlist=[]

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            sumlist.append(i*500+j*100+k*50)
            # print(sumlist)
            
print(sumlist.count(X))

Measured memory_bytes: 8276
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    N = II()
    A = LMIIS()
    numUsed = [0] * N
    ans = 1
    mod = 10**9 + 7
    for i in range(len(A)):
        if A[i] == 0:
            ans *= 3 - numUsed[0]
            # print(3 - numUsed[0])
            numUsed[0] += 1
        else:
            ans *= (numUsed[A[i]-1] - numUsed[A[i]])
            # print((numUsed[A[i]-1] - numUsed[A[i]]))
            numUsed[A[i]] += 1
        ans %= mod
    print(ans)

    





if __name__ == '__main__':
    main()

Measured memory_bytes: 52972
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  for (int i=0; i<n; i++) cin>>l[i];
  sort(l.begin(),l.end());
  // for (auto i:l)cout<<i<<" ";cout<<endl;

  int ans = 0;
  for (int i=n-1; i>=0; i--) {
    for (int j=i-1; j>=0; j--) {
      auto it = upper_bound(l.begin(),l.end(), l[i]-l[j]);
      ans += max(0, (int)((l.begin()+j) - it));
    }
  }
  cout << ans << endl;
}
/*
1 2 3 4
218 233 389 645 704 728 786 
*/

Measured memory_bytes: 256
#!/usr/bin/env python3

N = int(input())
A = list(map(int, input().split()))

k = sum(A) / sum(range(1, N + 1))
D = [(A[(i + 1) % N] - A[i]) - k for i in range(N)]

cnt = sum(list(filter(lambda x: x < 0 and x % N == 0, D)))
print('YES' if (cnt == -k * N) else 'NO')


Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N; cin >> N;
  vector<int> A(N), B(N), C(N);
  REP(i, N) cin >> A[i];
  REP(i, N) cin >> B[i];
  REP(i, N) cin >> C[i];

  int ans = accumulate(ALL(B), 0);
  REP(i, N-1) {
    if (A[i] == A[i+1]-1) {
      ans += C[A[i]-1];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int T,a,b;
    cin>>T;
    while(T--)
    {
        cin>>a>>b;
        int val=(int)sqrt(1ll*a*b);//cout<<"val:  "<<1ll*a*b<<endl;
		int ans=2*(int)sqrt(1ll*a*b)-1;
		if(1ll*val*val==1ll*a*b && a!=b)ans--;
		if(1ll*val*(val+1)>=1ll*a*b)ans--;
		printf("%d\n",ans);

    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
using ll = long long;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
int main(){
    int n,a,b; cin >> n >> a >> b;
    cout << min(a*n,b) << endl;
}
  



Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::Integer;
#[allow(unused_imports)]
use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp;

#[fastout]
fn main() {
  input! {
    x: i64,
  }
  let mut m = 100;
  for i in 0.. {
    if m >= x {
      println!("{}", i);
      break;
    }
    m += m / 100;
  }
}


Measured memory_bytes: 2196
N = int(input())

list_pop = [0] * 5
for i in range(N):
    s = input()
    if list(s)[0] == 'M':
        list_pop[0] += 1
    if list(s)[0] == 'A':
        list_pop[1] += 1
    if list(s)[0] == 'R':
        list_pop[2] += 1
    if list(s)[0] == 'C':
        list_pop[3] += 1
    if list(s)[0] == 'H':
        list_pop[4] += 1




answer = 0
for i in range(3):
    for j in range(4)[i+1:]:
        for k in range(5)[j+1:]:
            answer += list_pop[i] * list_pop[j] * list_pop[k]
    
    
print(int(answer))

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll is_query = -(1LL<<62);
struct Line {
    ll m, b;
    mutable function<const Line*()> succ;
    bool operator<(const Line& rhs) const {
        if (rhs.b != is_query) return m < rhs.m;
        const Line* s = succ();
        if (!s) return 0;
        ll x = rhs.m;
        return b - s->b < (s->m - m) * x;
    }
};
struct HullDynamic : public multiset<Line> { // will maintain upper hull for maximum
    bool bad(iterator y) {
        auto z = next(y);
        if (y == begin()) {
            if (z == end()) return 0;
            return y->m == z->m && y->b <= z->b;
        }
        auto x = prev(y);
        if (z == end()) return y->m == x->m && y->b <= x->b;
        return (long double)(x->b - y->b)*(z->m - y->m) >= (long double)(y->b - z->b)*(y->m - x->m);
    }
    void insert_line(ll m, ll b) {
        auto y = insert({ m, b });
        y->succ = [=] { return next(y) == end() ? 0 : &*next(y); };
        if (bad(y)) { erase(y); return; }
        while (next(y) != end() && bad(next(y))) erase(next(y));
        while (y != begin() && bad(prev(y))) erase(prev(y));
    }
    ll eval(ll x) {
        auto l = *lower_bound((Line) { x, is_query });
        return l.m * x + l.b;
    }
};
int main(){
  int n; long long c; cin >> n >> c;
  vector<long long> h(n); for(auto & i : h) cin >> i;
  vector<long long> f(n);
  HullDynamic magic;
  magic.insert_line( - 2 * h[n - 1], -1 * (h[n - 1] * h[n - 1] + c));
  for(int i = n - 2; i >= 0; i--){
    long long best = -magic.eval(-h[i]);
    f[i] = best + h[i] * h[i];
    magic.insert_line( -2 * h[i], -1 * (h[i] * h[i] + c + f[i]));
  }
  cout << f[0] << endl;
  return 0;
}


Measured memory_bytes: 22144
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m; cin >> n >> m;
    if(n > m) swap(n, m);

    ll res = 0;
    if(n == 1){
        if(m == 1){
            res = 1;
        }
        else {
            res = m - 2;
        }
    }
    else {
        res = 1LL * (n - 2) * (m - 2);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
n=gets().to_i
s=gets()
dat=[s[0].to_i]
for i in 1...n do
    if s[i]=='1' then
        if dat[-1]==0 then
            dat.<<1
        else
            dat[-1]+=1
        end
    else
        dat.<<0
    end
end
m=dat.length
#dat[i]個全部使える、1個だけ使用、1個のみ残す、全部使えないの4通り
dp=Array.new(m){[0,0,0,0]}
for i in 2...m do
    dp[i][0]=[dp[i][0],dp[i-1].max].max
    if dat[i]>0&&dat[i-1]==0&&dat[i-2]>0 then
        dp[i][1]=[dp[i][1],dp[i-2][0]+dat[i-2],dat[i-2]>1?dp[i-2][1]+dat[i-2]-1:0,dp[i-2][2]+1].max
        dp[i][2]=[dp[i][2],dp[i-2][0]+dat[i]-1,dat[i-2]>1?dp[i-2][1]+dat[i]-1:0,dp[i-2][2]+dat[i]-1].max
        dp[i][3]=[dp[i][3],dp[i-2][0]+dat[i],dat[i-2]>1?dp[i-2][1]+dat[i]:0,dp[i-2][2]+dat[i]].max
    end
end
puts dp[m-1].max

Measured memory_bytes: 74140
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

struct Segmenttree {
	static const int N = 1 << 18;
	vector<ll>seg;
	vector<ll>idx;
	void st(ll p, ll v) {
		p += N - 1;
		seg[p] = v;
		idx[p] = p - N + 1;
		while (p > 0) {
			p = (p - 1) / 2;
			seg[p] = max(seg[2 * p + 1], seg[2 * p + 2]);
			if (seg[2 * p + 1] < seg[2 * p + 2])idx[p] = idx[2 * p + 2];
			else if (seg[2 * p + 1] > seg[2 * p + 2])idx[p] = idx[2 * p + 1];
			else idx[p] = min(idx[2 * p + 1], idx[2 * p + 2]);
		}
	}
	pair<ll, ll> query(ll l, ll r, ll a, ll b, ll k) {
		if (r <= a || b <= l)return { -inf,inf };
		if (l <= a && b <= r)return { seg[k],idx[k] };
		ll m = (a + b) / 2;
		auto p1 = query(l, r, a, m, 2 * k + 1);
		auto p2 = query(l, r, m, b, 2 * k + 2);
		if (p1.first > p2.first) return p1;
		else if (p1.first < p2.first)return p2;
		else return { p1.first,min(p1.second,p2.second) };
	}

	void init() {
		seg.resize(2 * N);
		idx.resize(2 * N);
		for (int i = 0; i < 2 * N; i++)seg[i] = -inf;
	}
	//[l,r]
	ll get(int l, int r) {
		return query(l, r + 1, 0, N, 0).first;
	}
	ll getidx(int l, int r) {
		return query(l, r + 1, 0, N, 0).second;
	}
};

ll p[101010];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int N;
	cin >> N;
	Segmenttree seg = Segmenttree();
	seg.init();
	p[0] = inf;
	seg.st(0, inf);
	for (int i = 1; i <= N; i++) {
		ll P;
		cin >> P;
		seg.st(i,P);
		p[i] = P;
	}		
	seg.st(N+1, inf);
	p[N + 1] = inf;


	ll ans = 0;
	for (int i = 1; i <= N; i++) {
		ll l1, l2, r1, r2;
		int ok1 = 0, ng1 = i;
		while (ng1 - ok1 > 1) {
			int mid = (ng1+ok1) / 2;
			if (seg.get(mid, i - 1) > p[i])ok1 = mid;
			else ng1 = mid;
		}
		l1 = ok1;
		int ok2 = N+1, ng2 = i;
		while (ok2- ng2 > 1) {
			int mid = (ng2 + ok2) / 2;
			if (seg.get(i+1,mid) > p[i])ok2 = mid;
			else ng2 = mid;
		}
		r1 = ok2;

		if (l1 != 0) {
			int ok3 = 0, ng3 = l1;
			while (ng3 - ok3 > 1) {
				int mid = (ng3 + ok3) / 2;
				ll num = seg.get(mid,l1-1);
				if (num > p[i])ok3 = mid;
				else ng3 = mid;
			}
			l2 = ok3;
		}
		else l2 = 0;

		if (r1 != N + 1) {
			int ok4 = N + 1, ng4 = r1;
			while (ok4 - ng4 > 1) {
				int mid = (ng4 + ok4) / 2;
				ll num = seg.get(r1 + 1, mid);
				if (num > p[i])ok4 = mid;
				else ng4 = mid;
			}
			r2 = ok4;
		}
		else r2 = N + 1;

		ans += p[i] * ((l1-l2)*(r1-i) + (r2-r1)*(i-l1));
	}
	puts(ans);

	return 0;
}


Measured memory_bytes: 11136
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    char[] s = sc.next().toCharArray();;
    char[] t = sc.next().toCharArray();;
    Arrays.sort(s);
    String sAfter = new String(s);
    Arrays.sort(t);
    String tAfter = new String(t);
    StringBuffer str = new StringBuffer(tAfter);
    tAfter = str.reverse().toString();
    if(sAfter.compareTo(tAfter)<0){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 35656
// Problem : A - Five Variables
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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


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

    vector<long> a(5);
    for (long i = 0; i < 5; i++) {
        long x;
        cin >> x;
        if (x == 0) cout << i + 1 << "\n";
    }    
    
    return 0;
}


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

int main() {
	int a,b;
	cin>>a>>b;
	char s[a+b+1];
	cin>>s;
	bool flag=1;
	for(int i=0;i<a+b+1;i++){
		if(i==a){
			if(s[i]!='-') flag=0;
		}else{
			if(s[i]=='-') flag=0;
		}
	}
	if(flag){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
vector<int> to(200010,0);
vector<ll> time1[500010];
ll n,k;
void bfs(int i, ll count){
    if(count>n+n+10) return;
    time1[i].push_back(count);
    bfs(to[i],count+1);
}

int main(){
    cin>>n>>k;
    rep(i,n){
        int x;
        cin>>x;
        x--;
        to[i]=x;
    }
    bfs(0,0);
    for(int i=0;i<n;i++){
        bool ok = 0;
        int now = 1;
        while(1){
            if(time1[i].size()==0) break;
            if(now+1>time1[i].size()-1){
                break;
            }

            if(time1[i][now]-time1[i][now-1]==time1[i][now+1]-time1[i][now]){
                ok = 1;
                break;
            }
            now++;
        }
        if(ok){
            ll loop = time1[i][now]-time1[i][now-1];
            if((k-time1[i][now-1])%loop==0){
                if(k>=time1[i][now-1]){
                    cout<<i+1<<endl;
                    return 0;
                }else{
                    rep(i,n){
                        for(auto u : time1[i]){
                            if(u==k){
                                cout<<i+1<<endl;
                                return 0;
                            }
                        }
                    }
                }
            }
        }
    }
    rep(i,n){
        for(auto u : time1[i]){
            if(u==k){
                cout<<i+1<<endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 36000
//-------------
//include
//-------------
#include <map>
#include <list>
#include <cmath>
#include <vector>
#include <string>
#include <cctype>
#include <random>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
//-------------
//typedef
//-------------
typedef long long LL;
typedef  vector<int> VI;
typedef  pair<int, int> PII;
typedef  vector<int, int> VII;
typedef  map<string, int> MSI;
//-------------
//utillty
//-------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MK make_pair
#define PB push_back
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(a) cout<<a<<endl
//-------------
//repetition
//-------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//-------------
//debug
//-------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumpl(c) REP(i,SZ(c))cerr<<#c<<i<<"="<<(c[i])<<endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const int MOD = 1000000007;
int main()
{
	int x, t;
	cin >> x >> t;
	if (x<t)
	{
		COUT(0);
	}
	else
	{
		COUT(x - t);
	}
#ifdef _DEBUG
	while(1);
#endif // _DEBUG

	return 0;
}

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

int main() {

    // input from txt （提出時にこの箇所は削除すること）
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int cnt = 0;
    while(A > 0 && C > 0){
        cnt++;
        if(cnt %2 == 1){
            C -= B;
        }
        else{
            A -= D;
        }
    }
    if(cnt %2 == 1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 3624
const double = Float64
const int = Int64

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

function main()
  a,b,h,m = readint()
  
  x1 = a * cos(2π*(h/12 + m/720))
  y1 = a * sin(2π*(h/12 + m/720))
  x2 = b * cos(2π*m/60)
  y2 = b * sin(2π*m/60)

  println(sqrt((x1-x2)^2 + (y1-y2)^2))

end

main()

Measured memory_bytes: 209420
t=input()
T = 'D'+t+'P'
res = []
flg = 0
for i in range(len(T)-2):
    if T[i]=='D' and T[i+2]=='D':
        if T[i+1]=='?':
            res.append('P')
        else:
            res.append(T[i+1])
    else:
        if T[i+1]=='?':
            res.append('D')
        else:
            res.append(T[i+1])
    
    
    # if T[i]=='D':
    #     res.append('D')
    # elif T[i]=='P':
    #     res.append('P')
    # else:
    #     res.append('D')
res2 = ''.join(res)
print(res2)


Measured memory_bytes: 11296
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int main()
{
	ios::sync_with_stdio(0);
	int n;
	string s="1";
	cin>>n;
	rep(i,n-1)
	{
		int k=0;
		fore(j,s.size()-1,1)
			{
				if(s[j]!=s[j-1]+1&&s[j]!='9')
				{
					k=j;
					break;
				}
			}
		if(s[k]!='9')
		{
			s[k]++;
			forn(j,k+1,s.size()-1)
			{
				if(s[j-1]=='0')s[j]='0';
				else s[j]=s[j-1]-1;
			}
		}
		else
		{
		bool flag=1;
		fore(j,k,0){
				if(flag)s[j]++;
				flag=0;
				if(s[j]=='9'+1){
					s[j]='0';
					flag=1;
				}
				if(!flag)
				break;
			}
			forn(i,k+1,s.size()-1)
			s[i]='0';
			if(flag){
				s='1'+s;
			}
	}
	}
	cout<<s<<endl;
	return 0;
}



Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<P> work(N);
    rep(i, N){
        P tmp;
        cin >> tmp.second >> tmp.first;
        work[i] = tmp;
    }
    sort(all(work));

    int time = 0;
    bool flag = true;
    rep(i, N){
        time += work[i].second;
        if(time > work[i].first){
            flag = false;
            break;
        }
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;


}

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

int main(void)
{
    int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << a[k-1] << endl;
    return 0;
}


Measured memory_bytes: 256
from math import factorial
n = int(input())
p= list(map(int, input().split()))
q = list(map(int, input().split()))

a = 0
als = list(range(1,n+1))
for i in range(n):
    for j in range(len(als)):
        if als[j] == p[i]:
            als.pop(j)
            break
    a += (j)*factorial(n-1-i)

b = 0
bls = list(range(1,n+1))
for i in range(n):
    for j in range(len(bls)):
        if bls[j] == q[i]:
            bls.pop(j)
            break
    b += (j)*factorial(n-1-i)

print(abs(a-b))

Measured memory_bytes: 38256
from math import sqrt
from functools import reduce

def dist(l1, l2):
	if len(l1) != len(l2):
		return False
	sqr_diff = []
	for i in range(len(l1)):
		sqr_diff.append((l1[i] - l2[i]) * (l1[i] - l2[i]))
	return sqrt(reduce(lambda p, c: p + c, sqr_diff))

n, d = map(int, input().split())
x = [[] for j in range(n)]
for i in range(n):
	x[i] = list(map(int, input().split()))

count = 0
for i in range(n):
	for j in range(i + 1, n):
		distance = dist(x[i], x[j])
		# print(distance, int(distance))
		if distance == int(distance):
			count += 1
print(count)


Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const double EPS = 1e-10;
const int INF = 2147483647;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

char ca, cb, cc, cd;
int a, b, c, d;

int main()
{
	cin >> ca >> cb >> cc >> cd;

	a = ca - '0';
	b = cb - '0';
	c = cc - '0';
	d = cd - '0';

	for(int i=0;i<2;i++)
		for(int j=0;j<2;j++)
			for (int k = 0;k < 2;k++) {
				int t = a + pow(-1, i) * b + pow(-1, j) * c + pow(-1, k) * d;

				if (t == 7) {
					char ab;
					char bc;
					char cd;

					if (i == 0) {
						ab = '+';
					}
					else {
						ab = '-';
					}

					if (j == 0) {
						bc = '+';
					}
					else {
						bc = '-';
					}

					if (k == 0) {
						cd = '+';
					}
					else {
						cd = '-';
					}


					cout << a << ab << b << bc << c << cd << d << "=7";
					return 0;
				}
			}

	return 0;
}


Measured memory_bytes: 512
def main():
    n = int(input())
    a = list(map(int, input().split()))

    if 0 in a:
        print(0)
        return

    maks = 10**18
    mnozenje = 1
    for i in a:
        mnozenje *= i

        if mnozenje > maks:
            print(-1)
            return

    print(mnozenje)


if __name__ == '__main__':
    main()


Measured memory_bytes: 21580
#include <iostream>
#include <algorithm>
using namespace std;
#define maxn 100005
int n,ans=0;
int a[maxn];
int main(int argc, const char * argv[]) {
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    if(n%2==1||a[n/2]==a[n/2+1]){
        cout<<"0";
        return 0;
    }
    for(int i=a[n/2]+1;i<=a[n/2+1];i++){
        ans++;
    }
    cout<<ans;
    return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
  gearup;
  int n;cin >> n;
  vl a(n);
  rep(i,n)cin>>a[i];
  vl c(n);
  //|a[i] - (b+(i+1))|
  //|a[i] - (i+1) - b|
  //c[i] = a[i] - (i+1)　とする iは 0-indexed
  rep(i,n){
    c[i] = a[i] - (i+1);
  }
  sort(all(c));
  
  ll res = 0;
  ll b = c[n/2];
  rep(i,n)res += abs(c[i] - b);
  out(res);
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

// Most important thing in CP - Have Fun :)

void solve(){
	//write here
    string s,t;
    cin>>s>>t;
    int n = sz(s) , m = sz(t);
    int dp[n+1][m+1];
    memset(dp,0,sizeof(dp));
    for (int i = 1; i <=n ; i++){
        for (int j = 1 ; j<=m ; j++){
            if (s[i-1] == t[j-1])dp[i][j] = 1 + dp[i-1][j-1];
            else dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
        }
    }
    string ans;
    int i = n , j = m;
    while (i>0 && j>0){
        if (dp[i][j] == dp[i-1][j])i--;
        else if (dp[i][j] == dp[i][j-1])j--;
        else{
            ans += s[i-1];
            i--;
            j--;
        }
    }
    reverse(all(ans));
    cout<<ans<<endl;
}

int main(){
	cin.tie(NULL);
	ios::sync_with_stdio(false);
	//insert code
	
		solve();
	return 0;
}

Measured memory_bytes: 38764
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

const int N=1e6+5;
/* if d*k ends in 7
 * then ans is multiple of d
 * somehow digit dp
 * */
void solve() {
    cini(k);

    int ans=1;
    int mod=7%k;
    while(mod!=0 && ans<N) {
        mod=(mod*10+7)%k;
        ans++;
    }
    if(mod==0)
        cout<<ans<<endl;
    else
        cout<<-1<<endl;
}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


Measured memory_bytes: 3616
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define FOR(i,s,e) for (int i=s;i<e;i++)
#define FOE(i,s,e) for (int i=s;i<=e;i++)
#define FOD(i,s,e) for (int i=s;i>=e;i--)
#define SET(a,e) memset(a,e,sizeof(a))
#define LL long long
#define LD long double
#define pb push_back
#define x first
#define y second
#define PII pair<int,int>
#define PLI pair<LL,int>
#define PIL pair<int,LL>
#define PLL pair<LL,LL>
#define eps 1e-9
#define mp make_pair

int ansx,ansy,tmp,a,b,c,d,e,f;
bool dp[3005][3005];

void recur(int x,int y) {
	dp[x][y]=1;
	if (x+100*a+y<=f && !dp[x+100*a][y]) recur(x+100*a,y);
	if (x+100*b+y<=f && !dp[x+100*b][y]) recur(x+100*b,y);
	if (x+c+y<=f && !dp[x][y+c]) recur(x,y+c);
	if (x+d+y<=f && !dp[x][y+d]) recur(x,y+d);
}

int main () {
	scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
	recur(0,0);
	ansx=100*a;
	ansy=0;
	FOE(i,0,f) {
		FOE(j,0,f) {
			if (dp[i][j] && i/100*e>=j) {
				if (ansy*(i+j)<=(ansx+ansy)*j) {
					ansx=i;
					ansy=j;
				}
			}
		}
	}
	printf("%d %d\n",ansx+ansy,ansy);
	return 0;
}

Measured memory_bytes: 6400
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    switch (d) {
    case 22:
        cout << "Christmas Eve Eve Eve" << endl;
        break;
    case 23:
        cout << "Christmas Eve Eve" << endl;
        break;
    case 24:
        cout << "Christmas Eve" << endl;
        break;
    case 25:
        cout << "Christmas" << endl;
        break;

    default:
        break;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int m, f, r, sum;
	
	while (1) {
		scanf("%d %d %d", &m, &f, &r);
		sum = m + f;
		if (sum + r == -3)
			break;
		else if (m == -1 || f == -1 || sum < 30)
			puts("F");
		else if (sum >= 80)
			puts("A");
		else if (sum >= 65)
			puts("B");
		else if (sum >= 50 || (sum >= 30 && r >= 50))
			puts("C");
		else if (sum >= 30)
			puts("D");
	}
	
	return 0;
}

Measured memory_bytes: 584
#include <stdio.h>

int main(){
  int a, b, c, N;
  
  scanf("%d", &N);
  while( N > 0){
    scanf("%d %d %d", &a, &b, &c);
    if( a*a == b*b + c*c || b*b == a*a + c*c || c*c == a*a + b*b) puts("YES");
    else puts("NO");
    N--;
    }
  return 0;
}

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

int main(){
  int64_t n, d;
  cin >> n >> d;
  int ans = 0;
  for(int i = 0; i < n; i++){
    int64_t x, y;
    cin >> x >> y;
    if(x*x + y*y <= d*d){
      ans++;
    }
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 3592
m_ = [31,28,31,30,31,30,31,31,30,31,30,31]
m_sum = [0]
m_sum.extend([sum(m_[0:i+1]) for i in range(12)])
def mtod(m,d):
    s = m_sum[m-1] + d
    return s
def dtom(s):
    for i in range(13):
        if s < m_sum[i]:
            return i,s - m_sum[i-1]

def minus(a,b):
    if a >= b:
        return a-b
    else:
        return a + 365 - b
    
meiji = 1000*1868 + mtod(9,8)
taisho = 1000*1912 + mtod(7,30)
showa = 1000*1926 + mtod(12,25)
heisei = 1000*1989 + mtod(1,8)

while(1):
    try:
        y,m,d = [int(i) for i in input().split()]
        s = 1000*y + mtod(m,d)
        if s < meiji:
            print("pre-meiji")
        elif s < taisho:
            print("meiji", int(s/1000) -int(meiji/1000) + 1, m ,d)
        elif s < showa:
            print("taisho", int(s/1000) -int(taisho/1000) + 1, m,d)
        elif s < heisei:
            print("showa", int(s/1000) -int(showa/1000) + 1, m,d)
        else:
            print("heisei", int(s/1000) -int(heisei/1000) + 1, m,d)
    except EOFError:
        break


Measured memory_bytes: 5612
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#define mp make_pair
#define F first
#define S second
#define mod ((ll)(1e9+7))
#define ll long long int

using namespace std;

int main()
{
    string s;
    cin >> s;
    for(int i = 0 ;i < s.size() ; i++){
        if(s[i] == ',')cout << ' ';
        else cout << s[i];
    }
    return 0;
}










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

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

    vector<long long int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }

    // cumulative sum
    vector<long long int> sa_all(n+1), sa_positive(n+1);
    for(int i=0; i<n; i++){
        sa_all[i+1] = sa_all[i] + a[i];
        sa_positive[i+1] = sa_positive[i] + max(0LL, a[i]);
    }

    long long int ans = 0;
    for(int i=0; i+k<=n; i++){
        long long int test = sa_positive[i] 
                           + max(0LL, sa_all[i+k] - sa_all[i]) 
                           + (sa_positive[n] - sa_positive[i+k]);
        ans = max(ans, test);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    ll x;
    cin >> x;
    ll a = floor(x/11);
    if(x%11==0){
        cout << 2*a << endl;
        return 0;
    }
    if(x%11<=6){
        cout << 2*a + 1 << endl;
        return 0;
    }
    cout << 2*a+2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x); i<=(y); i++)
#define ll long long
#define N 5005
#define mod 1000000007
#define inv2 500000004
using namespace std;
int n,m,f[2][N]; char s[N];
void upd(int &x,int y){ x+=y; if (x>=mod) x-=mod; }
int main(){
	scanf("%d%s",&m,s+1); n=strlen(s+1);
	//f[i][j]表示第i步，此时有j个数字的方案数
	int nk=0,k=1; f[0][0]=1;
	rep (i,0,m-1){
		nk^=1; k^=1; memset(f[nk],0,sizeof(f[nk]));
		rep (j,0,m){
			upd(f[nk][max(0,j-1)],f[k][j]);
			if (j<m) upd(f[nk][j+1],2ll*f[k][j]%mod);
		}
	}
	int ans=f[nk][n];
	rep (i,1,n) ans=(ll)ans*inv2%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 892
n = STDIN.gets.to_i

cards = {
        'S' => [],
        'H' => [],
        'C' => [],
        'D' => []
}
missing = {
        'S' => [],
        'H' => [],
        'C' => [],
        'D' => []
}

n.times {
        card = STDIN.gets.split(' ')
        cards[card[0]].push(card[1].to_i)
}

cards.each {|k,v| cards[k].sort! }

cards.each {|k,v|
        for i in 1..13
                missing[k].push(i) if ! v.include?(i)
        end
}

missing.each {|k,v|
        v.each {|val|
                puts k.to_s + ' ' + val.to_s
        }
}

Measured memory_bytes: 6108
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){

  int n;
  cin >> n;
  if (n < 1000){
    cout << "ABC" << endl;
  }
  else {
    cout << "ABD" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
while True:
    n, r = [int(x) for x in input().split()]
    if n == 0 and r == 0:
        break
    L = [ n-x for x in range(n)]
    for _ in range(r):
        p, c = [int(x) for x in input().split()]
        p -= 1
        L = L[p:p+c] + L[:p] + L[p+c:]
    print(L[0])
    
    


Measured memory_bytes: 5616
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  string S, T;
  cin >> S >> T;
  ll count = 0;
  for (ll i = 0; i < S.length(); i++) {
    if (S[i] != T[i]) count++;
  }

  cout << count << endl;
  return 0;
}




Measured memory_bytes: 3856
//g++  5.4.0

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

#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int nax = 1e5;
signed main()
{
    fast;
    int  n , W;
    cin >> n >> W;
    int dp[nax+1] ;
    dp[0] = 0;
    for(int i=1 ; i<=nax ; i++ )
        dp[i] = 1e18;
    
    while( n-- )
    {
        int w , v;
        cin >> w >> v;
        for( int j=nax ; j>=v ; j-- )
        {
            if( dp[j-v] != 1e18 )
                dp[j] = min( dp[j] , dp[j-v] + w );
        }
    }
    
    int ans = 0;
    for(int i=0 ; i<=nax ; i++ )
        if( dp[i] <= W ) ans = max( ans , i );
    cout << ans << "\n";
    
   
}





Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 21 23:12:22 2019

@author: Yamazaki Kenichi
"""
import heapq

N, M = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(N)]

AB.sort()

q = [0 for _ in range(max(M,N))]
j = 0
ans = 0
for i in range(1,M+1):
    while j < N and AB[j][0] == i:
        heapq.heappush(q,-AB[j][1])
        j += 1
    ans += (-heapq.heappop(q))
#    print(i,j,ans,q)
print(ans)

Measured memory_bytes: 32020
#include <iostream>
using namespace std;
int n;
long int a[1000000];
long int b[1000000];
int main()
{
	
	long int sum = 0;

	cin >> n;
	for (int i = 0; i < n + 1; i++)
		cin >> a[i];
	for (int i = 0; i < n ; i++)
		cin >> b[i];


	for (int i = n; i >= 1; i--)
	{
		if (a[i] - b[i - 1] >= 0)
		{
			sum = sum + b[i - 1];
		
			b[i - 1] = 0;
		}
		else {
			sum = sum + a[i];
			{if (a[i - 1] <= (b[i - 1] - a[i]))
			{
				sum = sum + a[i - 1];
				b[i - 1] = b[i - 1] - a[i] - a[i - 1];
				
			
				a[i - 1] = 0;

			}
			else
			{
			
				sum = sum + b[i - 1] - a[i];
				a[i - 1] = a[i - 1] - (b[i - 1] - a[i]);
				b[i - 1] = 0;
				
			}
				

			}
		}
	}
	if (a[0] > b[0])
		sum = sum + b[0];
	else
		sum = sum + a[0];

	cout << sum;
	return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
#define ll long long int


int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	string s; cin >> s;
    if(s[s.size() - 1]!='s') s += "s";
    else if(s[s.size()-1]=='s') s+="es";
    cout << s;
}

Measured memory_bytes: 3656
N = int(input())
P = list(map(int, input().split()))

i, count = 0, 0
while i < N:
	#print(i, i + 1, P[i])
	if i + 1 == P[i]:
		count += 1
		i += 2
	else:
		i += 1
print(count)


Measured memory_bytes: 14008
#include <stdio.h>
#include <cstdio>
#include <cmath>
 
using namespace std;
 
typedef long long ll;
	
ll a,b,c;
 
int main()
{
	scanf("%d%d%d",&a,&b,&c);
	if(c-a-b<0)
	{
		printf("No\n");
		return 0;
	}
	ll cnt=4*a*b;
	ll ans=(c-a-b)*(c-a-b);
	if(cnt<ans)
		printf("Yes");
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i<n; i++) a[i] = sc.nextInt();

        Arrays.sort(a);

        if(n%2==0) {
            int num = 1;
            for(int i =0; i<n; i=i+2) {
                if(a[i]!=a[i+1] || a[i] != num) {
                    System.out.println(0);
                    return;
                }
                num += 2;
            }
        } else {
            int num = 2;
            if(a[0] != 0) {
                System.out.println(0);
                return;
            }
            for(int i =1; i<n; i=i+2) {
                if(a[i]!=a[i+1] || a[i] != num) {
                    System.out.println(0);
                    return;
                }
                num += 2;
            }
        }
        long mod = (long)Math.pow(10,9) + 7;
        long ans = 1;
        for(int i = 0; i<n/2; i++) {
            ans *=2;
            ans%=mod;
        }
        System.out.println((long)(ans%mod));

    }
}

Measured memory_bytes: 50972