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

int main(){
    long N;cin>>N;
    vector<long> array(N);
    for(int i=0;i<N;i++)cin>>array[i];
    sort(array.begin(),array.end());
    if(array[0]==0){
        cout<<0<<endl;
        return 0;
    }
    long K=1;
    for(int i=0;i<N;i++){
        if(array[i]>1000000000000000000/K){
            cout<<-1<<endl;
            return 0;
        }
      K*=array[i];
    }
    cout<<K<<endl;
}

Measured memory_bytes: 3992
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll h,w,ar[82][82],br[82][82]; ll dp[82][82][161*81+10];
ll minval(ll i,ll j,ll cur_val){
	if(i>h||j>w) return 1e18;
	if(dp[i][j][cur_val]!=-1){
		return dp[i][j][cur_val];
	}
	if(i==h&&j==w){
		ll a=abs(cur_val+(ar[i][j]-br[i][j]));
		ll b=abs(cur_val+(br[i][j]-ar[i][j]));
		return dp[i][j][cur_val]=min(a,b);
	}

	ll a,b,c,d;
	a=minval(i+1,j,(cur_val+abs(ar[i][j]-br[i][j])));
	b=minval(i+1,j,abs(cur_val-abs(ar[i][j]-br[i][j])));
	c=minval(i,j+1,(cur_val+abs(ar[i][j]-br[i][j])));
	d=minval(i,j+1,abs(cur_val-abs(ar[i][j]-br[i][j])));
	return dp[i][j][cur_val]=min(min(a,b),min(c,d));
}
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l;
	cin>>h>>w;
	memset(dp,-1,sizeof(dp));
	for(i=1;i<=h;i++){
		for(j=1;j<=w;j++){
			cin>>ar[i][j];
		}
	}
	for(i=1;i<=h;i++){
		for(j=1;j<=w;j++){
			cin>>br[i][j];
		}
	}
	ll an=minval(1,1,0);
	cout<<an;
	return 0;
}

Measured memory_bytes: 686080
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL n;
    cin>>n;
    VL b(n);
    REP(i,n-1)cin>>b[i];
    b[n-1] = b[n-2];
    LL ans = b[0];
    FOR(i,1,n){
        ans += min(b[i-1], b[i]);
    }
    PUTS(ans);
}

Measured memory_bytes: 256
/******************************\
*  Everyone has a different way of thinking, so God Created us
Hope You Respect My Way..,Thank You ):  *
*                            *
*   Created by : Murad   *
\******************************/
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
#include<bits/stdc++.h>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define MP make_pair
#define ff first
#define ss second
#define INF 2147483647
#define _INF -2147483647
#define pq priority_queue
#define MM multimap
#define PB push_back
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
LL MMIN(LL a, LL b)
{
	if (a <= b)
		return a;
	else
		return b;
}
LL MMAX(LL a, LL b) {
	if (a >= b)
		return a;
	else
		return b;
}
LL gcd(LL a, LL b) {
	LL c;
	while (a != 0) {
		c = a;
		a = b % a;
		b = c;
	}
	return b;
}
LL f(LL a, LL mul)
{
	return a / mul;
}
int main()
{
	El3zba;
	string s;
	cin >> s;
	if (s == "Sunny")
		return cout << "Cloudy\n", 0;
	else if (s == "Rainy")
		return cout << "Sunny\n", 0;
	else
		return cout << "Rainy\n", 0;
	return 0;
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, k;
  cin >> n >> k;
  
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  
  vector<ll> b;
  for (int i = 0; i < n; i++) {
    ll sum = 0;
    for (int j = i; j < n; j++) {
      sum += a.at(j);
      b.emplace_back(sum);
    }
  }
  
  ll ans = 0;
  for (ll i = 63; i >= 0; i--) {
    ll keep = pow(2, i), count = 0;
    for (int j = 0; j < b.size(); j++) {
      if (((ans + keep) & b.at(j)) == ans + keep) count++;
    }
    if (count >= k) ans += keep;
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 6384
N,K=map(int,input().split())
p=list(map(int,input().split()))

sum=[0]*N
sum_f=0

for j in range(K):
  sum_f += (p[j]+1)/2
sum[0]=sum_f
  
for i in range(1,N-K+1):
  sum[i]=sum[i-1] - (p[i-1]+1)/2 + (p[i+K-1]+1)/2
  
print(max(sum))

Measured memory_bytes: 25604
"use strict"
let fs = require('fs');
let input = fs.readFileSync("/dev/stdin", "utf8").split(/\s/);
const N = +input[0];
const K = +input[1];
let ans = 1;
if(N > K) {
  for(let i= N - K; i > 0; i -= K - 1) ans++;
}
console.log(ans);


Measured memory_bytes: 25420
#include <utility>
#include <stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define YES(b) std::cout<< (b ? "Yes" : "No")
using namespace std;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64_t n, c, nn[31][31], cc[500][500], p[3][31] = {}, mini = 1000000000;
	cin >> n >> c;
	for (int i = 1; i < c + 1; i++) {
		for (int j = 1; j < c + 1; j++) {
			cin >> nn[i][j];
		}
	}
	REP(i, n) {
		REP(j, n) {
			cin >> cc[i][j];
			for (int k = 1; k < c + 1; k++) {
				p[(i + j + 2) % 3][k] += nn[cc[i][j]][k];
			}
		}
	}
	for (int i = 1; i < c + 1; i++) {
		for (int j = 1; j < c + 1; j++) {
			for (int k = 1; k < c + 1; k++) {
				if (i != j && j != k && i != k) {
					mini = min(p[0][i] + p[1][j] + p[2][k], mini);
				}
			}
		}
	}
	cout << mini;
	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

ll bit[5050505], n;
// sum of[0..i]
ll sum(ll i) {
    ll s = 0;
    while (i > 0) {
        s += bit[i];
        i -= i & -i;
    }
    return s;
}

void add(ll i, ll x) {
    while (i <= n) {
        bit[i] += x;
        i += i & -i;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    int q;
    cin >> n >> q;
    int c[n+1];
    for (i = 1; i <= n; i++) {
        cin >> c[i];
        c[i]--;
    }
    vector<pair<P, int> > w(q);
    for (i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        w[i] = make_pair(P(r, l), i);
    }
    VI ans(q);
    sort(w.begin(), w.end());
    int r = 0;
    VI last(n, -1);
    for (i = 0; i < q; i++) {
        // cout << i << endl;
        while (w[i].fi.fi > r) {
            r++;
            if (last[c[r]] > 0) add(last[c[r]], -1);
            last[c[r]] = r;
            add(last[c[r]], 1);
        }
        ans[w[i].se] = sum(w[i].fi.fi) - sum(w[i].fi.se - 1);
    }
    for (i = 0; i < q; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 29164
#include <iostream>

using namespace std;

int main(void){
	int d;
	cin >> d;
	if(d==25){
		cout << "Christmas" << endl;
	}else if(d==24){
		cout << "Christmas Eve" << endl;
	}else if(d==23){
		cout << "Christmas Eve Eve" << endl;
	}else{
		cout << "Christmas Eve Eve Eve" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

using Flow = int;
struct FlowEdge {
  int src, dst, rev;
  Flow cap;
  FlowEdge(const int s = 0, const int d = 0, const Flow c = 0, const int r = 0) : src(s), dst(d), cap(c), rev(r) {}
};

using FlowEdges = std::vector<FlowEdge>;

class FlowGraph {
  std::vector<FlowEdges> g;

public:
  FlowGraph(const int size = 0) : g(size) {}
  size_t size() const { return g.size(); }
  FlowEdges &operator[](const int i) & { return g[i]; }

  void addEdge(const int src, const int dst, const Flow c = 1) {
    g[src].emplace_back(src, dst, c, g[dst].size());
    g[dst].emplace_back(dst, src, 0, g[src].size() - 1);
  }
};

template<int inf = std::numeric_limits<Flow>::max() / 8> Flow fordFulkerson(FlowGraph g, const int source, const int sink) {
  std::vector<int> used(g.size());
  std::function<int(int, int, int)> dfs = [&](int s, int t, int f) -> int {
    if (s == t) return f;
    used[s] = true;
    for (auto &e : g[s]) {
      if (used[e.dst] || e.cap <= 0) continue;
      int d = dfs(e.dst, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        g[e.dst][e.rev].cap += d;
        return d;
      }
    }
    return 0;
  };
  Flow s = 0;
  for (;;) {
    std::fill(used.begin(), used.end(), false);
    Flow f = dfs(source, sink, inf);
    if (f == 0) return s;
    s += f;
  }
}

main {
  int n, m;
  cin >> n >> m;
  FlowGraph g(n);
  while (m--) {
    int a, b, c;
    cin >> a >> b >> c;
    g.addEdge(a, b, c);
  }
  cout << fordFulkerson(g, 0, n - 1) << endl;
}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define debug(...)                                                             \
    { cerr << "# " << __VA_ARGS__ << "\n"; }
#else
#define debug(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
  public:
    string s[11];
    int n, m, k;
    void solve() {
        cin >> n >> m >> k;
        for (int i = 0; i < n; ++i)
            cin >> s[i];
        int ans = n + m;
        for (int i = 0; i < 1 << (n - 1); ++i) {
            vector<vector<int>> p;
            vector<int> a;
            a.push_back(0);
            for (int j = 0; j < n - 1; ++j) {
                if (i >> j & 1) {
                    p.push_back(a);
                    a.clear();
                    a.push_back(j + 1);
                } else {
                    a.push_back(j + 1);
                }
            }
            p.push_back(a);
            int cur = p.size() - 1;
            vector<int> c(p.size());
            for (int ii = 0; ii < p.size(); ++ii) {
                for (int j : p[ii])
                    if (s[j][0] == '1')
                        c[ii]++;
                if (c[ii] > k)
                    continue;
            }
            bool ok = 1;
            for (int j = 0; j < m - 1; ++j) {
                for (int ii = 0; ii < p.size(); ++ii) {
                    for (int jj : p[ii]) {
                        if (s[jj][j + 1] == '1')
                            c[ii]++;
                    }
                    if (c[ii] > k)
                        ok = 0;
                }
                if (!ok) {
                    cur++;
                    ok = 1;
                    for (int ii = 0; ii < p.size(); ++ii) {
                        c[ii] = 0;
                        for (int jj : p[ii]) {
                            if (s[jj][j + 1] == '1')
                                c[ii]++;
                        }
                        if (c[ii] > k)
                            ok = 0;
                    }
                    if (!ok)
                        break;
                }
            }
            if (ok)
                ans = min(ans, cur);
        }
        cout << ans << "\n";
    }
} NSPACE;
int main() {
    FPEN;
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  cin >> N;
  map<int, int> mp;
  rep(i, N) {
    int a;
    cin >> a;
    if(!mp.count(a)) mp[a] = 1;
    else             mp[a]++;
  }
  vector<pair<int, int> > v;
  for(auto m: mp)
    v.push_back(make_pair(m.first, m.second));
  int n = v.size();
  int l=0, r=n-1;
  int cnt = 0;
  while(l <= r) {
    while(l < n && v[l].second <= 1)  l++;
    while(r >= 0 && v[r].second <= 1) r--;
    if(l <= r) {
      if(l == r) {
        int tmp = v[l].second / 2 * 2;
        cnt += tmp;
        v[l].second -= tmp;
      } else {
        int tmp = min(v[l].second, v[r].second) - 1;
        cnt += tmp * 2;
        v[l].second -= tmp;
        v[r].second -= tmp;
        if(l + 1 == r)
          if(v[l].second == 2 || v[r].second == 2)
            cnt++;
      }
    }
  }
  cout << N - cnt << endl;
  return 0;
}



Measured memory_bytes: 6136
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 入力
// 入力
int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
queue<pair<int, int>> que;

int main() {

    ll X, Y;
    cin >> X >> Y;
    ll num;
    ll count = 1;

    num = X;
    for(;;){
        num = num * 2;
        if(num > Y)break;
        count++;
    }

    cout << count << endl;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

dic = {}
for i in range(len(A)):
    dic[i+1] = A[i]
dic = sorted(dic.items(), key = lambda x:x[1])
st = []
for elem in dic:
    st.append(str(elem[0]))
print(' '.join(st))


Measured memory_bytes: 25944
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
char D[1002][1002]={};

int main() {
	int M,N;
	char E[2][2];
	char b[4]={'S','J','O','I'};
	cin>>M>>N;
	for(int i=1;i<M+1;i++){
		for(int j=1;j<N+1;j++){
			cin>>D[i][j];
		}
	}
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			cin>>E[i][j];
		}
	}
	int a=0;
	for(int i=1;i<M;i++){
		for(int j=1;j<N;j++){
			if(D[i][j]==E[0][0]&&D[i][j+1]==E[0][1]&&D[i+1][j]==E[1][0]&&D[i+1][j+1]==E[1][1]){
				a+=1;
			}
		}
	}
	int c[4];
	int R=0;
	for(int i=1;i<M+1;i++){
		for(int j=1;j<N+1;j++){
			b[0]=D[i][j];
			for(int k=0;k<4;++k){
				D[i][j]=b[k];
				c[k]=0;
				if(D[i][j]==E[0][0]&&D[i][j+1]==E[0][1]&&D[i+1][j]==E[1][0]&&D[i+1][j+1]==E[1][1])c[k]+=1;
				if(D[i][j-1]==E[0][0]&&D[i][j]==E[0][1]&&D[i+1][j-1]==E[1][0]&&D[i+1][j]==E[1][1])c[k]+=1;
				if(D[i-1][j-1]==E[0][0]&&D[i-1][j]==E[0][1]&&D[i][j-1]==E[1][0]&&D[i][j]==E[1][1])c[k]+=1;
				if(D[i-1][j]==E[0][0]&&D[i-1][j+1]==E[0][1]&&D[i][j]==E[1][0]&&D[i][j+1]==E[1][1])c[k]+=1;
			}
			D[i][j]=b[0];
			R=max(R,a+c[1]-c[0]);
			R=max(R,a+c[2]-c[0]);
			R=max(R,a+c[3]-c[0]);
		}
	}


	cout<<R<<endl;
	return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

template<class T,T fun(T,T)> class segtree{
public:
    int n,size_;
    vector<T> dat;
    T id_;
    segtree()=default;
    segtree(int size,T id,T initial_value){ init(size,id,initial_value); }
    void init(int size,T id,T initial_value){
        size_=size;
        id_=id;
        n=1;
        while(n<size) n*=2;
        dat.assign(2*n-1,id);
        for(int i=0; i<size; ++i) update(i,initial_value);
    }
    int size()const{ return size_; }
    void update(int k, T a) {
        k+=n-1; // leaf
        dat[k]=a;
        while(k>0) {
            k=(k-1)/2;
            dat[k]=fun(dat[k*2+1],dat[k*2+2]);
        }
    }
    T at(int index){ return dat[index+n-1]; }
    void add(int k,T a){ update(k,fun(at(k),a)); }
    T query(int a,int b) { return query(a,b,0,0,n); }
    T query(int a,int b,int k,int l,int r) {
        if(r<=a or b<=l) return id_;
        if(a<=l and r<=b) return dat[k];
        int m=(l+r)/2;
        return fun(query(a,b,k*2+1,l,m),query(a,b,k*2+2,m,r));
    }
};

int64_t mod=1000000007;
int64_t add(int64_t a,int64_t b){
    return (a+b+mod)%mod;
}

void solve(){
    int64_t n,a,b;
    cin >> n >> a >> b;
    vector<int64_t> s(n+1),p(n+1),q(n+1);
    rep(i,1,n+1){
        cin >> s[i];
        p[i]=s[i]+a;
        q[i]=s[i]+b;
    }
    
    segtree<int64_t,add> dp_x(n+1,0,0),dp_y(n+1,0,0);
    vector<pair<int,int>> history_x,history_y;
    dp_x.add(0,1);
    history_x.push_back(make_pair(0,1));
    dp_y.add(0,1);
    history_y.push_back(make_pair(0,1));
    rep(i,1,n){
        int64_t tmp0=dp_x.query(0,upper_bound(q.begin(),q.begin()+i+1,s[i+1])-q.begin()), //s[j]+b>s
                       tmp1=dp_y.query(0,upper_bound(p.begin(),p.begin()+i+1,s[i+1])-p.begin());
        
        if(s[i+1]-s[i]<a){
            for(auto &h:history_x) dp_x.add(h.first,-h.second);
            history_x.clear();
        }
        if(s[i+1]-s[i]<b){
            for(auto &h:history_y) dp_y.add(h.first,-h.second);
            history_y.clear();
        }
        dp_y.add(i,tmp0);
        history_y.push_back(make_pair(i,tmp0));
        dp_x.add(i,tmp1);
        history_x.push_back(make_pair(i,tmp1));
    }
    cout << (dp_x.query(0,n+1)+dp_y.query(0,n+1))%mod << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 8560
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  ll ans = stoi(s.substr(0, 3));
  REP(i, 1, s.size() - 2) {
    ll tmp = stoi(s.substr(i, 3));
    if (abs(ans - 753) > abs(tmp - 753)) ans = tmp;
  }
  cout << abs(ans - 753) << endl;
  return 0;
}


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


int main(){
    int i, n, a[MAX];
    cin >> n;
    for(i=0; i<n; i++) cin >> a[i];
    int flg = 1;
    for(i=0; i<n; i++){
        if(a[i] % 2 == 0){
            if(a[i] % 3 != 0 && a[i] % 5 != 0){
                flg = 0;
                break;
            }
        }
    }

    if(flg == 0) cout << "DENIED" << endl;
    else cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long X = sc.nextLong();
        ArrayList<Long> x = new ArrayList<>(); 
        ArrayList<Long> diff = new ArrayList<>(); 

        for (int i = 0; i<N; i++) {
            x.add(sc.nextLong());
        }
        x.add(X);

        Collections.sort(x);

        for (int i = 0; i<x.size()-1; i++) {
            diff.add(x.get(i+1) - x.get(i));
        }

        Long result = diff.get(0);
        for (int i = 1; i<diff.size(); i++) {
            result = calcBGF(result, diff.get(i));
        }

        System.out.println(result);
    }

    static Long calcBGF(Long x, Long y) {
        if (x > y) {
            return calcBGF(y, x);
        }

        if (x == 0) {
            return y;
        }

        return calcBGF(x, y % x);
    }
}


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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)
#define Float(x) OUTN(fixed, setprecision(x));

#ifdef DEBUG
#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);
#else
#define dump(...)
#endif

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }

// DEGUG
template <class T>
void _dump(const char *s, T&& x) {
  clog << '{';
  while(*s != '\0') clog << *(s++);
  clog << ": " << x << '}' << "\n";
}

template <class Head, class... Tail>
void _dump(const char *s, Head&& head, Tail&&... tail) {
  clog << '{';
  while(*s != ',') clog << *(s++);
  clog << ": " << head << "}, ";
  for (++s; !isgraph(*s); ++s);
  _dump(s, forward<Tail>(tail)...);
}
// }}} End

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  VAR(int, N);

  vector<i64> vec;
  map<i64, i64> cnt;
  rep(i, N) {
    VAR(i64, a);
    cnt[a]++;
    if (cnt[a] >= 2) {
      vec.emplace_back(a);
      cnt[a] = 0;
    }
  }

  if (vec.size() <= 1) {
    OUTL(0); return 0;
  }

  sort(all(vec), greater<>());

  OUTL(vec[0] * vec[1]);

  return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main(){
  int N,M,p;
  cin >> N >> M >> p;
  vector<int> d(M);
  rep(i,0,M - 1) cin >> d[i];
  if(M == 1){
    cout << min(N - abs(d[0] - p) , abs(d[0] - p)) * 100 << endl;
    return 0;
  }
  d.push_back(p);
  sort(all(d));
  int start = lower_bound(all(d),p) - d.begin();
  int ans = N;
  for(int i = 0;i < d.size();i++){
    int left = 0;
    if(p < d[i]) left = N - (d[i] - p);
    else left = p - d[i];
    int right = 0;
    int j = (i - 1 + d.size()) % d.size();
    if(p < d[j]) right = d[j] - p;
    else if(p != d[j]) right = N - (p - d[j]);
    else right = 0;
    ans = min(ans , min(left * 2 +  right , left + right * 2));
  }

  cout << ans * 100 << endl;

}



Measured memory_bytes: 3220
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#define pb push_back
#define mod 1000000007
#include <map>
using namespace std;
typedef long long int ll;

int main(void){
  int n;
  cin>>n;
  map<int,int> mp;
  int x;
  for(int i=0;i<n;i++){
    cin>>x;
    if(mp.find(x)==mp.end()) mp[x]=1;
    else mp[x]=mp[x]+1;
  }
  int m;
  cin>>m;
  bool f=true;
  for(int i=0;i<m;i++){
    cin>>x;
    if(mp.find(x)==mp.end()) f=false;
    else if(mp[x]>0) mp[x]=mp[x]-1;
    else f=false;
  }
  if(f) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 9600
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	final long m = (long) 1e9 + 7;

	void run() {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int ans = 1 ^ 2 ^ 3 ^ A ^ B;
		System.out.println(ans);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 21204
N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
if N % 2 == 1:
    p = sorted(a)[N // 2][0]
    q = sorted(a, key = lambda x: x[1])[N // 2][1]
    print(q - p + 1)
else:
    a = sorted(a)
    p1 = a[N // 2 - 1][0]
    p2 = a[N // 2][0]
    a = sorted(a, key = lambda x: x[1])
    q1 = a[N // 2 - 1][1]
    q2 = a[N // 2][1]
    print(q1 + q2 - p1 - p2 + 1)

Measured memory_bytes: 50004
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << "No" << endl;return 0
#define MM <<" "<<
#define Endl endl


signed main(void){
    string S;
    cin >> S;
    int N=S.size();
    int Ans[114514]={};
    vector<int> C;
    REP(i,N-1){
        if(S[i]=='R'&&S[i+1]=='L'){
            C.push_back(i);
        }
    }
    REP(i,N){
        int pos,it;
        if(S[i]=='R'){
            it=lower_bound(C.begin(),C.end(),i)-C.begin();
        }else{
            it=-1+lower_bound(C.begin(),C.end(),i)-C.begin();
        }
        pos=C[it];
        //cout << pos << " ";
        if((pos+i)%2==0){
            Ans[pos]++;
        }else{
            Ans[pos+1]++;
        }
    }
    
    //cout << endl;
    //REP(i,N){cout << S[i] << " ";}cout << endl;
    REP(i,N){
        if(i!=0)cout << " ";
        cout << Ans[i];
    }cout << endl;
    
    /*
    REP(i,N){cout << S[i] << " ";}cout << endl;
    int d[114514],e[114514];
    REP(i,N){d[i]=1;}
    REP(_,20){
        REP(i,N){cout << d[i] << " ";}cout << endl;
        REP(i,N){e[i]=d[i];}
        REP(i,N){d[i]=0;}
        REP(i,N){
            if(S[i]=='L'){
                d[i-1]+=e[i];
            }else{
                d[i+1]+=e[i];
            }
        }
    }*/
    return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

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

    if (N == 0) {
        cout << 0 << endl;
        return 0;
    }

    vector<int> ans;

    while (N != 0) {
        if (N % 2 == 0) ans.push_back(0);
        else {
            ans.push_back(1);
            N -= 1;
        }
        N /= (-2);
    }

    for (int i = ans.size() - 1; i >= 0; i--) {
        cout << ans[i];
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <functional>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

const int MAX_N = 2e5 + 10;
const int MOD = 1e9 + 7;
int N;
int c[MAX_N];

int128_t prev[MAX_N] = {};


int main(int argc, char **argv) {
    std::cin >> N;
    for (int i = 1; i <= N; i++) {
        std::cin >> c[i];
    }

    int128_t ret = 1;
    for (int i = 1; i <= N; i++) {
        if (c[i] != c[i-1]) {
            ret = (ret + prev[c[i]]) % MOD;
        }
        prev[c[i]] = ret;
    }
    
    std::cout << ret << std::endl;
    return 0;
}



Measured memory_bytes: 4224
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int h, w; cin >> h >> w;
	vector<string>field(h); rep(i, h)cin >> field[i];
	rep(i, h) {
		rep(j, w) {
			if (field[i][j] == '#') {
				bool ok = false;
				if (i - 1 >= 0) {
					if (field[i - 1][j] == '#')ok = true;
				}
				if (j - 1 >= 0) {
					if (field[i][j - 1] == '#')ok = true;
				}
				if (i + 1 < h) {
					if (field[i + 1][j] == '#')ok = true;
				}
				if (j + 1 < w) {
					if (field[i][j + 1] == '#')ok = true;
				}
				if (!ok) { cout << "No" << endl; return 0; }
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
const int N=1000010;
int n,m,p[N],q[N],f[N],ans,fg;string a,b;
int main(){
	cin>>n>>a>>b;a=" "+a;b=" "+b;
	ref(i,1,n)fg|=(a[i]!=b[i]);
	if(!fg)return 0*puts("0");
	ref(i,1,n)if(b[i]!=b[i-1])p[++m]=i;
	for(int i=m,j=n;i>0&&j>0;q[i--]=j--)
		while(j>p[i]||j&&a[j]!=b[p[i]])
			f[i]|=(a[j]!=b[p[i]]),j--;
	if(!q[1])return 0*puts("-1");q[m+1]=N;
	ref(i,1,m)if(!f[i])q[i]=min(p[i],q[i+1]-1);
	int j=1;ref(i,1,m){
		while(j<i||q[j]-j<p[i]-i)j++;
		ans=max(ans,j-i);
	}
	cout<<ans+1<<endl;
}

Measured memory_bytes: 13792
#include <bits/stdc++.h>
#define ll long long
#define pf printf
#define sf scanf
using namespace std;
int main(){
 //freopen("input.txt","r",stdin);
 //freopen("output.txt","w",stdout);
 int n,a,i,t(0);
 string s;
 cin>>s;
 n=s.size();
 for(i=0;i<(n/2);i++){
  if(s[i]!=s[n-i-1]){
    s[i]=s[n-i-1];
    t++;
  }
 }
 cout<<t<<"\n";
  


  
  


  
 
 
 
    
 
return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    vector<int> dp(n);
    rep(i,n) {
        cin >> h[i];
        dp [i] = -1;
    }
    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);

    for(int i = 2; i < n; i++){
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]),dp[i-2] + abs(h[i] - h[i-2]));
    }

    cout << dp[n-1] << endl;


    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main(void){
    int a,b,i,ans;
    scanf("%d %d",&a,&b);
    for(i=1; i<11000; i++){
        if(i*2/25==a && i/10==b){
            printf("%d",i);
            return 0;
        }
    }
    printf("-1");
    return 0;
}

Measured memory_bytes: 128
use proconio::input;

fn main(){
    input!{
        n:usize,
        d:i64,
        p:[(i64,i64);n],
    }

    let mut ans=0;
    for (x,y) in p{
        if x*x+y*y<=d*d{
            ans+=1;
        }
    }
    println!("{}",ans);
}

Measured memory_bytes: 7752
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		Set <String> L = new HashSet<String>();
		
		
		String s = sc.next();
		int k = Integer.parseInt(sc.next());
		
		for(int i = 1 ; i <= Math.min(k, s.length()) ;i++) {
			for(int j = 0 ; j <= s.length() - i ; j++) {
				L.add(s.substring(j, j+i));
			}
		}
		String []substring = L.toArray(new String[0]);
		Arrays.sort(substring);
		
		System.out.println(substring[k-1]);
		

	}

}


Measured memory_bytes: 24912
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template <class T> void swap(T& a, T& b) { T t = std::move(a); a = std::move(b); b = std::move(t); }

int main(void)
{
    ll N, N2, count=0, i, ans=0, d;

    cin >> N;

    N2 = N;

    if(N < 2){
        cout << 0 << endl;
    }

    else{
        if(N % 2 == 1){
            cout << 0 << endl;
        }

        else{
            d = 10;
            while(N >= d){
                ans += N/d;
                d *= 5;
            }
            cout << ans << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
int main()
{
    int n, k; cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(ALL(a));
    int ans = 0;
    rep(i, k) ans += a[i];
    pr(ans);
    return 0;}

Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
#define FOR(i,a,b) for(ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
int main(){
  int n,a,b;
  cin >> n >> a >> b;
  vi p(n);
  REP(i,n) cin >> p[i];
  sort(ALL(p));
  int s=0,t=0,u=0;
  REP(i,n){
    if(p[i]<=a) s++;
    else if(p[i]<=b) t++;
    else u++;
  }
  int ans = min(s,min(t,u));
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#define lint unsigned long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++)
#define DUMP(ar) for(auto itd=begin(ar); itd != end(ar); itd++) cout << "["s << itd - begin(ar) << "]:"s << *itd << endl
#define DUMPL(ar) for(auto itd=begin(ar); itd != end(ar); itd++) { cout << *itd; if(end(ar)-itd > 1) cout << ' '; } cout << endl
#define COUT(x) cout << (x) << endl
#define VCIN(ar) for(auto &vcin: (ar)) cin >> vcin
#define ALL(ar) ar.begin(), ar.end()
#define LOOPD(i) cout << "ループ["s << i << "]回目---------------"s << endl
using namespace std;
// lint:64ビット 10^19

int n;
vector<vector<vector<int>>> dp(200, vector<vector<int>>(200, vector<int>(2, -1)));

int rec(string &s, int nonzero_num=0, int k=0, bool tight=true){
    if(k >= (int)s.size()){
        return nonzero_num == n;
    }

    int x = s[k] - '0';
    int r = tight ? x : 9;
    int &res = dp[k][nonzero_num][tight];
    if(res != -1) return res;
    
    res = 0;
    for(int i=0; i<=r; i++){
        res += rec(s, nonzero_num + (i!=0), k+1, tight && i == r);
    }
    return res;
}

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

    string str;
    cin >> str;
    cin >> n;

    int ans = rec(str);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys

sys.setrecursionlimit(1000000)

while True:
    N = input()
    if N == 0:
        break
    p = map(int, raw_input().split())
    d = map(int, raw_input().split())
    E = [[] for i in range(N)]
    leaf = [False for i in range(N)]
    for i in range(N - 1):
        u = i + 1
        v = p[i] - 1
        cost = d[i]
        E[u].append((v, cost))
        E[v].append((u, cost))
    
    for i in range(N):
        leaf[i] = (len(E[i]) < 2)
    
    def func(num, pre, dist):
        if leaf[num]:
            return (0, 0)
        ret = (dist, num)
        for e in E[num]:
            if e[0] != pre:
                hoge = func(e[0], num, dist + e[1])
                if ret[0] < hoge[0]:
                    ret = hoge
        return ret

    for i in range(N):
        if not leaf[i]:
            ret = func(i, -1, 0)
            ret = func(ret[1], -1, 0)
            break
    ans = -2 * ret[0]
    for i in range(N):
        for e in E[i]:
            if leaf[i] or leaf[e[0]]:
                ans += e[1]
            else:
                ans += e[1] * 3
    print ans / 2


Measured memory_bytes: 6060
import java.util.*;
import java.io.*;
 
public class Main {
    static boolean[][] used;
    static int[] ans;
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int[][] map = new int[n][n];
        boolean[][] notCalc = new boolean[n][n];
        int[][] map2 = new int[n][n];
        long ans = 0;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                map[i][j] = map2[i][j] = sc.nextInt();
            }
        }
        for(int k = 0; k < n; k++){
            for(int i = 0; i < n; i++){
                for(int j = 0; j < n; j++){
                    if(map[i][j] > map[i][k]+map[k][j]){
                        System.out.println(-1);
                        return;
                    }else if(map[i][j] == map[i][k]+map[k][j]){
                        if(i != k && k != j) notCalc[i][j] = true;
                    }
                }
            }
        }
        
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                if(!notCalc[i][j]){
                    ans += map[i][j];
                }
            }
        }
        System.out.println(ans);
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

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

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 34460
X, K, D = map(int, input().split())
if X < 0:
    X = -X
step = X//D
X -= D*step
K -= step

if K <= 0:
    print(X-K*D)
    exit()
if K % 2 == 0:
    print(X)
else:
    print(abs(X-D))


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

int main(){
  int stack[10];
  int *head;
  int car_num;

  head=stack;
  while(cin>>car_num){
    if(car_num>0){
      *head=car_num;
      head++;
    }
    else {
      head--;
      printf("%d\n", *head);
    }
  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

namespace solution
{
  string s,t;
  vector<vector<char>> build_table() {
    int n = s.size();
    int m = t.size();
    vector<vector<int>>dp(n + 1, vector<int>(m + 1, 0));
    vector<vector<char>>dir(n + 1, vector<char>(m + 1, 'N'));
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (s[i-1] == t[j-1]) {
          dp[i][j] = dp[i-1][j-1] + 1;
          dir[i][j] = 'D'; // diagonal
        } else {
          if (dp[i-1][j] > dp[i][j-1]) {
            dp[i][j] = dp[i-1][j];
            dir[i][j] = 'U'; // up
          } else {
            dp[i][j] = dp[i][j-1];
            dir[i][j] = 'L'; // left
          }
        }
      }
    }
    return dir;
  }
  string solve() {
    vector<vector<char>>dir = build_table();
    string lcs = "";
    int i = s.size();
    int j = t.size();
    while (i >= 0 && j >= 0) {
      //if (i <= 0 || j <= 0) break;
      char d = dir[i][j];
      if (d == 'D') {
        lcs += s[i-1];
        i--;j--;
      } else if (d == 'L') {
        j-=1;
      } else {
        i-=1;
      }
    }
    reverse(lcs.begin(), lcs.end());
    return lcs;
  }
}

int main() {
  cin >> solution::s >> solution::t;
  cout << solution::solve() << endl;
  return 0;
}

Measured memory_bytes: 44544