akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n;
    ans=1;
    rep(i,n){
        ans*=(i+1);
        ans%=MOD;
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const long long mod = 1000000007;
struct mint {
  long long x;
  mint(ll x = 0):x(x%mod) {}
  mint& operator+=(const mint a) {
    (x += a.x) %= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    (x += mod-a.x) %= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint ret(*this);
    return ret += a;
  }
  mint operator-(const mint a) const {
    mint ret(*this);
    return ret -= a;
  }
  mint operator*(const mint a) const {
    mint ret(*this);
    return ret *= a;
  }
  mint pow(ll t) const {
    if(t==0) return mint(1);
    mint a = pow(t>>1);
    a *= a;
    if(t&1) a *= *this;
    return a;
  }
  
  //for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint ret(*this);
    return ret /= a;
  }
};
ostream &operator<<(ostream& os, const mint& x) {
  os << x.x;
  return os;
}
class modutils {
  vector<mint> fact, invfact;
public:
  modutils(int n = 200005):fact(n+1),invfact(n+1) {
    fact[0] = 1;
    for(int i=1; i<=n; i++) fact[i] = fact[i-1] * i;
    invfact[n] = fact[n].inv();
    for(int i=n; i>=1; i--) invfact[i-1] = invfact[i] * i;
  }
  mint pow(mint x, ll n) {
    return x.pow(n);
  }
  mint comb(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[k] * invfact[n-k];
  }
  mint perm(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[n-k];
  }
  mint fac(ll n) {
    return fact[n];
  }
};
modutils mutil;


int main(){
  int N, K;
  cin >> N >> K;

  mint ret(0);
  rep(x,min(N,K+1)){
    ret += mutil.comb(N,x) * mutil.comb(N-1,x);
  }

  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 3328
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

struct UnionFind{
    vector<int> par,rank;
    
    //初期化
    UnionFind(int n){
        for(int i=0;i<=n;++i){
            par.push_back(i);
            rank.push_back(0);
        }
    }

    //根をFind
    int find(int i){
        if(par[i]==i)return i;

        return par[i]=find(par[i]);
    }

    //Union
    void unite(int x,int y){
        int rx=find(x);
        int ry=find(y);

        if(rx==ry)return;

        if(rank[rx]>rank[ry])par[ry]=rx;
        else{
            par[rx]=ry;
            if(rank[rx]==rank[ry])
                rank[ry]++;
        }
    }

    //同じ木に属するか判定
    bool same(int x,int y){
        return find(x)==find(y);
    }
};

struct edge{int from,to,cost;};

bool comp(const edge& e1,const edge& e2){
    return e1.cost<e2.cost;
}

vector<edge> G;
//頂点数と辺数
int N,E;

int kruskal(void){
    sort(G.begin(),G.end(),comp);
    UnionFind UF(N);
    int res=0;
    for(auto e:G){
        if(!UF.same(e.from,e.to)){
            UF.unite(e.from,e.to);
            res+=e.cost;
        }
    }
    return res;
}

int main(){
    cin>>N;
    tuple<int,int,int> px[100010],py[100010];
    int x,y;
    for(int i=0;i<N;i++){
        cin>>x>>y;
        px[i]=make_tuple(x,y,i);
        py[i]=make_tuple(y,x,i);
    }
    sort(px,px+N);sort(py,py+N);
    for(int i=0;i<N-1;i++){
        G.push_back((edge){get<2>(px[i]),get<2>(px[i+1]),get<0>(px[i+1])-get<0>(px[i])});
        G.push_back((edge){get<2>(py[i]),get<2>(py[i+1]),get<0>(py[i+1])-get<0>(py[i])});
    }
    cout<<kruskal()<<endl;
    return 0;

}

Measured memory_bytes: 7284
H, W = gets.chomp.split.map(&:to_i)
N = gets.to_i
a = gets.chomp.split.map(&:to_i)
grid = Array.new(H).map{Array.new(W, 0)}
idx = 0
num = 0
H.times do |i|
  col = [*0...W]
  col.reverse! if i.odd?

  col.each do |j|
    grid[i][j] = idx + 1
    num += 1
    if num == a[idx]
      idx += 1
      num = 0
    end
  end
end
grid.each { |row| puts row.join(' ')}

Measured memory_bytes: 15056
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
#define FOR(i,l,r) for (int i = (l); i < (r); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<int,int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
static const double EPS = 1e-10;
static const double PI  = acos(-1.0);
// static const ll MOD = 1000000007;
static const ll MOD = 998244353;
static const int INF = 1 << 30;
// static const ll INF = 1LL << 62;
// --------------------------------------------------------


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);

    int N, K; cin >> N >> K;

    VLL A(N + 1, 0);
    A[1] = 1;

    VI L(K), R(K);
    REP(i, K) cin >> L[i] >> R[i];

    FOR(i, 1, N) {
        A[i] = (A[i] + A[i - 1]) % MOD;
        ll a = A[i];
        REP(j, K) {
            int l = i + L[j];
            if (l > N) continue;
            A[l] = (A[l] + a) % MOD;
            int r = i + R[j] + 1;
            if (r > N) continue;
            A[r] = (MOD + A[r] - a) % MOD;
        }
    }
    ll ans = A[N];
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 4776
n,m,l = [int(x) for x in input().split()]
matrix_a = [[int(x) for x in input().split()] for _ in range(n)]
matrix_b = [[int(x) for x in input().split()] for _ in range(m)]
matrix_ab = [[0 for a in range(l)] for b in range(n)]
for i in range(n):
    for j in range(l):
        for k in range(m):
            matrix_ab[i][j] += matrix_a[i][k]*matrix_b[k][j]
for i in range(n):
    for j in range(l):
        if j < l-1:
            print(matrix_ab[i][j], "", end="")
        elif j == l-1:
            print(matrix_ab[i][j])

Measured memory_bytes: 9008
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define SZ(a) (int)((a).size())
using namespace std;
typedef long long ll;
typedef double db;
typedef pair <int, int> Pii;
typedef pair <ll, int> Pli;
typedef unsigned long long ull;
const double eps = 1e-8;
const ll infll = 0x7fffffffffffffff;
const int mod = (int)(1e9) + 7;
const int inf = 0x7fffffff;
const int maxn = (int)(2e5) + 7;
const int maxm = 300;

ll n;

int main() {

	// freopen("in.in", "r", stdin);
	scanf("%lld", &n);
	ll res = 0;
	for (ll i = 1; i <= n; i++) {
		ll x = n / i;
		res += i * x + x * (x - 1) / 2 * i;
	}
	printf("%lld\n", res);

	return 0;
}

Measured memory_bytes: 3824
N = int(input())
Hs = [int(x) for x in input().split()]


# 右端から見て, 単調減少/同じにできればいい.
# 右端から見て, 右側より大きければ1つ減らす.
# その上で比較していく. もし単調減少/同じにできなければ'No'を返す.

def is_yes(Hs):
    max = 0
    for H in Hs:
        # print("H: " + H)
        if H > max:
            max = H
        # print("max: " + max)
        if max - H >= 2:
            return False
    return True

if is_yes(Hs):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 14396
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,x=0,y=0,z=0,w;
  cin >> n >> a >> b;
  for(int i=0;i<n;i++){
    cin >> w;
    if(w<=a)x++;
    else if(w<=b)y++;
    else z++;
  }
  cout << min(x,min(y,z)) << endl;
}

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

int main(){
    string str;
    int n, h, count;
    h = 0;
    
    while(1){
        count = 0;
        cin >> str;
        
        if(str == "-") break;
        cin >> n;
        
        while(count < n){
            cin >> h;
            for(int i = 0; i < h; i++){
                char temp = str[0];
                
                for(int j = 0; j < str.size(); j++){
                    if(j == (str.size() - 1)) str[j] = temp;
                    else str[j] = str[j+1];
                }
            }
            count++;
        }
        
        cout << str << endl;
    }
}


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

#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
using i32 = int32_t;
using i64 = int64_t;
using f32 = float;
using f64 = double;
using P = pair<int, int>;

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

template <class T>
void dump_vec(const vector<T>& v) {
    auto len = v.size();
    rep(i, 0, len) {
        cout << v[i] << (i == (int)len - 1 ? "\n" : " ");
    }
}

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} FASTIO;

//---------------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------------

set<i64> memo;

void dfs(i64 cur) {
    rep(i, 0, 10) {
        auto a = cur % 10L;
        if (abs(a - i) > 1) {
            continue;
        }
        auto next = cur * 10L + i;
        if (next > 3234566667L) {
            return;
        }
        memo.insert(next);
        dfs(next);
    }
}

signed main() {
    int K;
    cin >> K;
    rep(i, 1, 10) {
        memo.insert(i);
        dfs(i);
    }
    int cnt = 0;
    for (const auto& a : memo) {
        cnt++;
        if (cnt == K) {
            cout << a << "\n";
            return 0;
        }
    }
}


Measured memory_bytes: 4992
#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; cin >> n;
    vll a(n); for(auto& e : a) cin >> e;

    ll mx = -1LL; int j;
    rep(i, n){
        if(chmax(mx, abs(a[i]))){
            j = i;
        }
    }

    vector<pair<int, int>> res;
    if(a[j] >= 0LL){
        rep(i, 1, n){
            while(a[i-1] > a[i]){
                a[i] += mx;
                res.emplace_back(make_pair(i, j));
            }
            if(chmax(mx, a[i])){
                j = i;
            }
        }
    }
    else {
        rrep(i, n - 1){
            while(a[i] > a[i+1]){
                a[i] -= mx;
                res.emplace_back(make_pair(i, j));
            }
            if(chmax(mx, -a[i])){
                j = i;
            }
        }
    }

    int m = res.size();
    assert(m <= 2 * n);
    cout << m << endl;
    for(auto& e : res){
        cout << e.second + 1 << " " << e.first + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>

using namespace std;

inline int gi()
{
    int f = 1, x = 0;
    char c = getchar();
    while (c < '0' || c > '9')
    {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
    {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return f * x;
}

const int MOD = 1000000007;

int n, a[100005], m, f[100005], v[100005];

int main()
{
	memset(v, 0, sizeof(v));
	n = gi(), m = gi();
	f[0] = 1, f[1] = 1;
	for (int i = 1; i <= m; i++) a[i] = gi(), v[a[i]] = 1;
	if (v[1]) f[1] = 0;
	sort (a + 1, a + 1 + m);
	for (int i = 1; i < m; i++)
	{
		if (a[i] == a[i + 1]) 
		{
			puts("0"); return 0;
		}
	}
	for (int i = 2; i <= n; i++)
	{
		if (!v[i]) f[i] = (f[i - 1] + f[i - 2]) % MOD;
		else f[i] = 0;
	}
	printf("%d\n", f[n] % MOD);
	return 0;
}

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

int main() {
	int H, W;
	cin >> H >> W;

	string s;
	for (int i = 0; i < H; i++) {
		cin >> s;
		for (int j = 0; j < 2; j++) {
			cout << s << endl;
		}
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define LEN 100005

typedef struct Pp{
    char name[100];
    int t;
}P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue(){
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b){
    return a<b ? a:b;
}

int main(){
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);

    for(i=1;i<=n;++i){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1;
    tail = n+1;

    while(head != tail){
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if(u.t > 0) enqueue(u);
        else{
            printf("%s %d\n", u.name, elaps);
        } 
    }

    return 0;
}


Measured memory_bytes: 11860
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<utility>
#include<numeric>
#include<iomanip>

using namespace std;
using ll = long long;

int main() {
    int n, m, k, s, p;
    cin >> n >> m;
    vector<vector<int>> lightToSwitch(m, vector<int>());
    for (int i=0; i<m; ++i) {
        cin >> k;
        for (int j=0; j<k; ++j) {
            cin >> s;
            lightToSwitch[i].push_back(s-1);
        }
    }
    vector<int> cond(m);
    for (int i=0; i<m; ++i) {
        cin >> p;
        cond[i] = p;
    }
    int count = 0;
    for (int bit=0; bit < (1<<n); ++bit) {
        bool flag = true;
        for (int i=0; i<m; ++i) {
            auto light = lightToSwitch[i];
            int mod2 = 0;
            for (auto& sw : light) {
                if (bit & (1<<sw)) mod2 = !mod2;
            }
            if (mod2 != cond[i]) flag = false;
        }
        if (flag) ++count;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define fs first
#define sc second

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


int main(){
    int T;
    cin >> T;
    for(int t = 0; t < T; t++){
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        a -= b;
        if(a < 0){
            cout << "No" << endl;
            continue;
        }
        if(b > d){
            cout << "No" << endl;
            continue;
        }
        if(c >= b-1){
            cout << "Yes" << endl;
            continue;
        }


        a = a % b;
        if(a > c){
            cout << "No" << endl;
            continue;
        }

        ll p = d % b;
        ll q = gcd(d, b);

        ll z1, z2;
        z1 = (c-a)/q+1;
        z2 = (b-a)/q;
        if((b-a)%q == 0){
          z2--;
        }

        if(z1 <= z2){
            cout << "No" << endl;
        }
        else{
            cout << "Yes" << endl;
        }

    }

    return 0;

}


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

int main() {
  int N;
  cin >> N;
  priority_queue<int> cards;
  int a;
  for (int i = 0; i < N; i++) {
    cin >> a;
    cards.push(a);
  }
  int Alice = 0, Bob = 0;
  while (!cards.empty()) {
    Alice += cards.top();
    cards.pop();
    if (cards.size() == 0) {
      break;
    }
    if (cards.size() == 1) {
      Bob += cards.top();
      cards.pop();
      break;
    }
    else if (cards.size() != 1) {
      Bob += cards.top();
      cards.pop();
    }
  }
  cout << Alice - Bob << endl;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;
using Complex = complex<double>;
const double PI = acos(-1);

int main() {
    int K, X;
    cin >> K >> X;
    cout << (K * 500 >= X ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8

import sys
input = sys.stdin.readline

# N = int(input())
# L = [int(x) for x in input().split()]
N, M = map(int, input().split())
# S = input()

ok = [0] * (N + 2)
for i in range(M):
    L, R = map(int, input().split())
    ok[L] += 1
    ok[R + 1] -= 1

ans = 0
tmp = 0
for i in range(1, N + 1):
    tmp += ok[i]
    
    if tmp == M:
        ans += 1

print(ans)


Measured memory_bytes: 3956
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

int main(){

	double x1, y1, x2, y2, d;

	cin >> x1 >> y1 >> x2 >> y2;

	d = sqrt( pow((x1 - x2), 2) + pow((y1 - y2), 2));

	cout << fixed << d << endl;

	return 0;
}

Measured memory_bytes: 1284
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>   
#include <stdio.h>    
 
using namespace std;
     
#define F first
#define S second
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)2e5 + 123;
const ll inf = (ll)3e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, x, y, z, ten[42], S, ans, dp[42][(1 << 17)];

inline int mult (int a, int b) {
   return 1ll * a * b % mod;
}

inline int add (int a, int b) {
   a += b;
   if (a >= mod) a -= mod;
   if (a < 0) a += mod;
   return a;
}                                      

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> n >> x >> y >> z;
   ten[0] = 1;
   int sum = x + y + z;
   int u = (1 << (sum - 1)) | (1 << (sum - x - 1)) | (1 << (z - 1));
   for (int i = 1; i <= n; i ++) ten[i] = mult (ten[i - 1], 10);
   dp[1][0] = 1;
   for (int i = 1; i <= n; i ++) {
      for (int mask = 0; mask < (1 << sum); mask ++) {
         for (int k = 1; k <= 10; k ++) {
            int new_mask = (mask << k) | (1 << (k - 1));
            new_mask &= ((1 << sum) - 1);
            if ((new_mask & u) == u) continue;
            dp[i + 1][new_mask] = add (dp[i + 1][new_mask], dp[i][mask]);
         }                                                 
      }         
   }
   for (int i = 0; i < (1 << sum); i ++) ans = add (ans, dp[n + 1][i]);
   cout << add (ten[n], -ans);

}                                     

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
// cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}


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



int main() { // claudio van
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  int w, h; cin >> h >> w;
  int n; cin >> n; 
  cout << (int) ceil((double) n / max(w, h)) << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)

int main() {
#ifndef ONLINE_JUDGE
//   freopen("input.txt", "r", stdin);
#endif
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   int a , b;
   cin >> a >> b;
   cout << (a <= 9 && b <= 9 ? a * b : -1) << "\n";
}

Measured memory_bytes: 256
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PriorityQueue<Integer> d=new PriorityQueue<>(11, Collections.reverseOrder());
        for (;;) {
            String n = sc.next();
            if(n.equals("end")){
                break;
            }
            if(n.equals("insert")) {
                d.add(sc.nextInt());
            }else if(n.equals("extract")) {
                System.out.println(d.poll());
            }
        }
    }
}



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

int main(){
    int a,b,c,x;

    while(scanf("%d%d%d%d",&a,&b,&c,&x)==4){
        long long cnt = 0;

        for(int i=0; i<=a; i++){
            for(int j=0; j<=b; j++){
                for(int k=0; k<=c; k++){
                    if(i*500 + j*100 + k*50 == x)
                        cnt++;
                }
            }
        }

        printf("%lld\n",cnt);
    }

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<long long> a(n);
    long long cnt = 0;
    for (int i = 0;i < n;i++){
        cin >> a[i];
        cnt += a[i];
    }
    long long rep = cnt,ans = cnt,num = 0;
    long long ans_1 = 0,ans_2;
    for (int i = 0;i < n;i++){
        rep -= a[i];
        num += a[i];
        if (ans > abs(rep-num)){
            ans = abs(rep-num);
            ans_1 = rep;
            ans_2 = num;
        }
    }

    if (ans_1 == ans_2) cout << 0 << endl;
    else cout << abs(ans_1-ans_2) << endl; 
}


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


int main(){
    int n;
    cin>>n;
    ll x=1;
    string s = (n != 0 ? "" : "0");
    while(n!=0){
        if(n%(x*-2)!=0){
            s="1" +s;
            n-=x;
        }
        else s="0"+s;
        x*=-2;
    }
    cout<<s<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF (1e9)
int N,M;
int s[15];
int d[100];
int sum[(1<<15)];
int dp[(1<<15)];

void init(){
  for(int i=0;i<(1<<N);i++){
    sum[i]=0;
    dp[i]=0;
  }
}

int solve(){
  for(int i=0;i<M;i++){
    for(int bit=0;bit<(1<<N);bit++){
      for(int j=0;j<N;j++){
        int nbit=bit|(1<<j);
        dp[nbit]=min(dp[nbit],dp[bit]);
      }
      dp[bit]+=abs(sum[bit]-d[i]);
    }
  }
  int ans=INF;
  for(int bit=0;bit<(1<<N);bit++){
    ans=min(ans,dp[bit]);
  }
  return ans;
}

int main(){
  while(1){
    cin>>N>>M;
    if(N==0&&M==0)break;
    init();
    for(int i=0;i<N;i++)cin>>s[i];
    for(int i=0;i<M;i++)cin>>d[i];
    sort(d,d+M);
    for(int bit=0;bit<(1<<N);bit++)
      for(int i=0;i<N;i++)
        if(bit>>i&1)sum[bit]+=s[i];
    cout<<solve()<<endl;
  }
  return 0;
}

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


int main(){
  long long int A, B;
  cin >> A >> B;
  if((A+B)%2!=0){
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  cout << (A+B)/2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

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

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if (a == b && b == c) {
        if (a % 2) {
            cout << 0 << endl;
        } else {
            cout << -1 << endl;
        }
        return 0;
    }
    int cnt = 0;
    int x,y,z;
    while (a % 2 == 0&& b % 2 == 0 && c % 2 == 0) {
        x = (a+b)/2;
        y = (b+c)/2;
        z = (c+a)/2;
        ++cnt;
        a = x;
        b = y;
        c = z;
    }
    cout << cnt << endl;
    
    return 0;
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int main(){
    ll h;
    cin>>h;
    ll ans = 1;
    while(h){
        ans <<= 1;
        h >>= 1;
    }
    ans--;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import numpy as np
from collections import Counter
n = int(input())
aa = np.array(list(map(int, input().split())))
cnt = 0
pl = aa + np.array(range(n))
ms = -aa + np.array(range(n))
common = set(pl).intersection(set(ms))

dic_pl = Counter(pl)
dic_ms = Counter(ms)

for k in dic_ms.keys():
    cnt += dic_ms[k] * dic_pl.get(k,0)
print(cnt)

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

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

  int n; cin >> n;
  int a, b;
  vector<pair<int, int> > p(n);

  rep(i, n) {
    cin >> a >> b;
    p[i] = {b, a};
  }
  sort(p.begin(), p.end());

  bool flag = true;
  ll sumA = 0;
  rep(i, n) {
    tie(b, a) = p[i];
    sumA += a;
    if(sumA > b) flag = false;
  }

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


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

char mp[410][410];
int flg[410][410];
long long Bl, Wh;
int dx[4]={0, 1, 0, -1};
int dy[4]={1, 0, -1, 0};
void dfs(int y, int x){
    if(flg[y][x])return;
    flg[y][x] = 1;
    if(mp[y][x]=='#')Bl++;
    if(mp[y][x]=='.')Wh++;
    for(int i=0;i<4;i++){
        if(mp[y+dy[i]][x+dx[i]]=='*')continue;
        if(mp[y][x]==mp[y+dy[i]][x+dx[i]])continue;
        if(flg[y+dy[i]][x+dx[i]])continue;
        dfs(y+dy[i], x+dx[i]);
    }
}

int main(){

    for(int i=0;i<410;i++){
        for(int j=0;j<410;j++){
            mp[i][j]='*';
            flg[i][j]=0;
        }
    }

    int H, W;
    cin>>H>>W;
    for(int y=1;y<=H;y++){
        for(int x=1;x<=W;x++){
            cin>>mp[y][x];
        }
    }
    long long ans = 0;
    for(int y=1;y<=H;y++){
        for(int x=1;x<=W;x++){
            if(flg[y][x])continue;
            Bl = 0;
            Wh = 0;
            dfs(y, x);
            ans += Bl*Wh;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>
#include <stack>

using namespace std;


const int dx[]={0,0,-1,1};
const int dy[]={-1,1,0,0};

int main()
{
    int n;
    while(cin>>n,n){
        map<double,set<string> > data;
        for(int i=0;i<n;i++){
            string name;
            int p,a,b,c,d,e,f,s,m;
            cin>>name>>p>>a>>b>>c>>d>>e>>f>>s>>m;
            
            data[((f*s*m)-p)/(double)(a+b+c+m*(d+e))].insert(name);
            
        }
        

        for(auto it=data.rbegin();it!=data.rend();it++){
            for(auto it2=(*it).second.begin();it2!=(*it).second.end();it2++) cout<<*it2<<endl;
        }
        cout<<"#"<<endl;
        
    }
    
    return 0;
}

Measured memory_bytes: 1220
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 1000;
 
ll table[MAX][MAX];
 
// テーブルを作る前処理
void COMinit() {
    table[0][0] = table[0][1] = 1;
    FOR(i, 1, MAX-1){
      FOR(j, 0, i+1){
        if(j==0) table[i][j] = 1;
        else if(j == i+1) table[i][j] = 1;
        else table[i][j] = table[i-1][j-1]+table[i-1][j];
      }
    }
}
 
// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return table[n-1][k];
}

void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}

ll SORT(int n, vector<pair<ll, ll>> &v, int start){
  sort(v.begin()+start, v.end());
  return v[n-1].first;
}

int ans = 0;

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

  vector<ll> h(n);

  REP(i, n){
    ll  x;
    cin>>x;
    h[i] = x;
  }
  sort(h.begin(), h.end());
  ll mini = 1000000000;
  REP(i, n-k+1){
   // cout<<i<<" "<<i+k-1<<endl;
    ll ans = h[i+k-1]-h[i];
    mini = min(mini, ans);
  }
  cout<<mini<<endl;
  return 0;
  

}

Measured memory_bytes: 1024
#include <stdio.h>
#define NUMBER 3000

int main(void){
        int i=0;
        int x[NUMBER];
        int y[NUMBER];
        int z=0;
        for(i=0;i<NUMBER;i++){
                scanf("%d %d", &x[i], &y[i]);
                if(x[i]==0 && y[i]==0)
                        break;
                z++;
        }
        for(i=0;i<z;i++){
                if(x[i]<y[i])
                        printf("%d %d\n", x[i], y[i]);
                else
                        printf("%d %d\n", y[i], x[i]);
        }
        return 0;
}


Measured memory_bytes: 2028
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
signed main(){
  ll n;
  cin >> n;
  string s,t;
  cin >> s >> t;
  for(int i=0;i<n;i++){
    cout << s[i]<<t[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<string>


int main(){
    std::vector<int> tiles;
    std::queue<int> unvisited_tile_q;
    int width, height, counter, pos;
    std::string line;

    while(true){
        std::cin >> width >> height;
        if( width == 0 && height == 0 ) break;
        tiles.resize(width*height);
        pos = 0;
        for( int h = 0; h < height; h++ ){
            std::cin >> line;
            for(std::string::iterator it = line.begin(); it != line.end(); ++it) {
                switch(*it){
                    case '#':
                        tiles[pos] = 0;
                        break;
                    case '@':
                        unvisited_tile_q.push(pos);
                    case '.':
                        tiles[pos] = 1;
                }
                pos++;
            }
        }

        counter = 0;
        while( !unvisited_tile_q.empty() ){
            pos = unvisited_tile_q.front();
            unvisited_tile_q.pop();
            if( tiles[pos] == 1 ){
                counter++;
                tiles[pos] = -1;
            } else continue;
            //left
            if ( pos - 1 >= 0 && pos % width > 0 && tiles[pos-1] == 1 ) unvisited_tile_q.push(pos-1); 
             //right
            if ( pos + 1 <= tiles.size() && pos % width < width - 1 && tiles[pos+1] == 1 ) unvisited_tile_q.push(pos+1);
            //up
            if ( pos - width >= 0 && tiles[pos-width] == 1 ) unvisited_tile_q.push(pos-width);
            //down
            if ( pos + width < tiles.size() && tiles[pos+width] == 1 ) unvisited_tile_q.push(pos+width);
        }
	    //output result
	    std::cout << counter << std::endl;
    }   
    return 0;
}


Measured memory_bytes: 3020
from functools import reduce
l = [int(input()) for _ in range(5)]
r = [i % 10 for i in l if i % 10 != 0]
l = [i if i % 10 == 0 else i // 10 * 10 + 10 for i in l]
print(reduce(lambda a, b: a + b, l) + (min(r) - 10 if r else 0))

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

int main() {
  int n;
  cin >> n;
  int a[n];
  vector<long long> ct(n+1, 0);
  for ( int i = 0; i < n; i++ ) {
    cin >> a[i];
    ct[a[i]]++;
  }
  long long sum = 0;
  for ( int i = 0; i <= n; i++ ) {
    sum += ct[i]*(ct[i]-1)/2;
  }

  for ( int i = 0; i < n; i++ ) {
    long long ans = sum;
    ans -= (ct[a[i]]-1);
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 5800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int /*mod=1000000007,*/MAX=100005,INF=1<<30;
int mod;
ll ans[MAX];
ll dp[MAX][2];
vector<int> G[MAX],tree[MAX];
vector<ll> l[MAX][2],r[MAX][2];

void maketree(int u,int p){
    tree[u].push_back(u);
    for(int to:G[u]){
        if(to==p) continue;
        tree[u].push_back(to);
        maketree(to,u);
    }
    tree[u].push_back(u);
}

void DFS(int u){
    
    dp[u][0]=1;
    dp[u][1]=1;
    
    int M=si(tree[u]);
    
    l[u][0].push_back(1);
    l[u][1].push_back(1);
    
    for(int i=1;i<M-1;i++){
        
        int to=tree[u][i];
        
        DFS(to);
        
        l[u][0].push_back(dp[to][0]);
        l[u][1].push_back((dp[to][0]+dp[to][1])%mod);
    }
    
    l[u][0].push_back(1);
    l[u][1].push_back(1);
    
    r[u][0]=l[u][0];
    r[u][1]=l[u][1];
    
    for(int i=1;i<M;i++){
        for(int j=0;j<2;j++){
            l[u][j][i]*=l[u][j][i-1];
            l[u][j][i]%=mod;
        }
    }
    
    for(int i=M-2;i>=0;i--){
        for(int j=0;j<2;j++){
            r[u][j][i]*=r[u][j][i+1];
            r[u][j][i]%=mod;
        }
    }
    
    dp[u][0]*=l[u][0].back();
    dp[u][0]%=mod;
    
    dp[u][1]*=l[u][1].back();
    dp[u][1]%=mod;
}

void zenn(int u,int p){
    
    int M=si(tree[u]);
    
    ans[u]=dp[u][1];
    
    for(int i=1;i<M-1;i++){
        int to=tree[u][i];
        
        ll a=dp[u][0],b=dp[u][1],c=dp[to][0],d=dp[to][1];
        
        dp[u][0]=l[u][0][i-1]*r[u][0][i+1]%mod;
        dp[u][1]=l[u][1][i-1]*r[u][1][i+1]%mod;
        
        if(p!=-1){
            dp[u][0]*=dp[p][0];
            dp[u][0]%=mod;
            
            dp[u][1]*=(dp[p][0]+dp[p][1]);
            dp[u][1]%=mod;
        }
        
        dp[to][0]*=dp[u][0];
        dp[to][0]%=mod;
        
        dp[to][1]*=(dp[u][0]+dp[u][1]);
        dp[to][1]%=mod;
        
        zenn(to,u);
        
        dp[u][0]=a;
        dp[u][1]=b;
        dp[to][0]=c;
        dp[to][1]=d;
        
    }
}


int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N>>mod;
    for(int i=0;i<N-1;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    maketree(0,-1);
    DFS(0);
    ans[0]=dp[0][1];
    
    zenn(0,-1);
    
    for(int i=0;i<N;i++) cout<<ans[i]<<"\n";
}



Measured memory_bytes: 52696
n, y = list(map(int, input().split()))

done = False

for n_manen in range(0, n+1):
    for n_gosen in range(0, n+1):
        n_sen = n - n_manen - n_gosen
        if n_sen < 0:
            continue
        if n != n_manen + n_gosen + n_sen:
            continue
        total = 10000 * n_manen + 5000 * n_gosen + 1000 * n_sen
        if total == y:
            done = True
            break
    if done:
        break
else:
    n_manen, n_gosen, n_sen = -1, -1, -1

print('{} {} {}'.format(n_manen, n_gosen, n_sen))

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

using namespace std;

const int md = 998244353;

inline int mul(int a, int b) {
  return (long long) a * b % md;
}

int main() {
  ios_base::sync_with_stdio(false);

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

  int maxd = *max_element(d.begin(), d.end());
  vector<int> cnt(maxd + 1);
  for (int i = 0; i < n; i++) {
    cnt[d[i]]++;
  }

  if (d[0] != 0 || cnt[0] != 1) {
    cout << 0 << '\n';
    return 0;
  }
  for (int i = 1; i <= maxd; i++) {
    if (cnt[i] == 0) {
      cout << 0 << '\n';
      return 0;
    }
  }

  int ans = 1;
  for (int i = 1; i <= maxd; i++) {
    for (int j = 0; j < cnt[i]; j++) {
      ans = mul(ans, cnt[i - 1]);
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3960
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

//string S;
//cin >> S;
vector<int> Zalgorithm(string &S)
{
    vector<int> Z(S.size());
    Z[0] = S.size();
    int i = 1, j = 0;
    while (i < S.size())
    {
        while (i + j < S.size() && S[j] == S[i + j])
            j++;
        Z[i] = j;

        if (j == 0)
        {
            i++;
            continue;
        }
        int k = 1;
        while (k < j && k + Z[k] < j)
        {
            Z[i + k] = Z[k];
            k++;
        }
        i += k;
        j -= k;
    }
    return Z;
}
//rep(i, S.size()) cout << Z[i] << " ";
//cout << endl;

signed main(){
    int n;
    string s;
    cin>>n>>s;
    int ans=0;
    for (int i = 0; i < n; i++)
    {
        string t=s.substr(i,n-i);
        vector<int>ret = Zalgorithm(t);
       // show(ret);
        for (int i = 1; i < ret.size(); i++)
        {
            if(ret[i]>=i){
                chmax(ans,i);
            }
            else chmax(ans,ret[i]);
        }
        
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));//入力用オブジェクトの初期化
		StringBuilder str =  new StringBuilder(in.readLine());//文字列を取得してStringBuilder型の変数strに格納
		str.reverse();//文字列の逆順化
		System.out.println(str.toString());//逆順にした文字列の出力
	}
}

Measured memory_bytes: 16860
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#ifdef LOCAL
#define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
#define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/






int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cout.precision(10); cout << fixed;
#ifdef LOCAL
  freopen("../test.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
#endif
  LL a, b, c, d;
  cin >> a >> b >> c >> d;
  LL ret = a*c;
  ret = max(ret, a*d);
  ret = max(ret, b*c);
  ret = max(ret, b*d);
  cout << ret << '\n';






/*---------------------------------------Coding Space End------------------------------------------*/
#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
  return 0;
}
/* author:  txingml */
/* picture is from hamayanhamayan(CF handle) */


Measured memory_bytes: 3196
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  string ans="Yes";
  if(n%2==1) {
    ans="No";
    cout<<ans<<endl;
    return 0;
  }
  rep(i,n/2){
 if( s[i]!=s[n/2+i]) {
   ans="No";
 }
             }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
#define show(x) cout << #x << " is " << x << "\n";
typedef vector<ll> vi;
#define fi first
#define se second
const ll inf = 9e18;
const ll mod = 1e9 + 7;

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//const ll N = 1e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

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

	ll n;
	cin>>n;
	ll a[n];
	ll mina[n];
	ll x;
	
	for(int i=0;i<n;i++){
		cin>>x;

		a[i] = i+x;
		mina[i] = i-x;
	}
	ll ans=0;
	map<ll, ll> mp;
	for(int i=0;i<n;i++){
		mp[a[i]]++;
	}
	for(int i=0;i<n;i++){
		ans+=mp[mina[i]];
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 29472
#include <iostream>
#include <algorithm>
using namespace std ;
using ll = long long ;

int main(){
	ll h,w ;
	cin >> h >> w ;
	ll ans = 100000000000 ;
	for(int i=1;i<h;i++){
		ll a = i*w ;
		ll b = ((h-i)*w%2==0?(h-i)*w/2:((h-i)*w+min(h-i,w))/2) ;
		ll c = h*w-a-b ;
		ans = min(ans,max(a,b)-min(a,c)) ;
	}
	for(int i=1;i<w;i++){
		ll a = i*h ;
		ll b = ((w-i)*h%2==0?(w-i)*h/2:((w-i)*h+min(w-i,h))/2) ;
		ll c = h*w-a-b ;
		ans = min(ans,max(a,b)-min(a,c)) ;
	}
	cout << ans << endl ;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc097a()
}

fun abc097a() {
    val (a, b, c, d) = readLine()!!.split(" ").map { it.toInt() }

    val answer = if (Math.abs(a - c) <= d || (Math.abs(a - b) <= d && Math.abs(b - c) <= d)) "Yes" else "No"

    println(answer)
}


Measured memory_bytes: 37928