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

int main()
{
  int n;
  cin >> n;
  vector<tuple<int64_t, int, int>> vt(n);
  for (int i = 0; i < n; i++)
  {
    int64_t x, y, h;
    cin >> x >> y >> h;
    vt[i] = make_tuple(h, x, y);
  }
  sort(vt.begin(), vt.end());
  reverse(vt.begin(), vt.end());
  for (int i = 0; i <= 100; i++)
  {
    for (int j = 0; j <= 100; j++)
    {
      int64_t h0, x0, y0;
      tie(h0, x0, y0) = vt[0];
      int64_t H = h0 + abs(x0 - i) + abs(y0 - j);
      if (H <= 0)
      {
        continue;
      }
      bool ok = true;
      for (int k = 0; k < n; k++)
      {
        int64_t hk, xk, yk;
        tie(hk, xk, yk) = vt[k];
        int64_t h = max(H - abs(i - xk) - abs(j - yk), (int64_t)0);
        if (h != hk)
        {
          ok = false;
          break;
        }
      }
      if (ok)
      {
        cout << i << ' ' << j << ' ' << H << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using Weight = int;
using Capacity = int;
struct Edge {
    int src, dst;
    Weight weight;
    Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

class lca {
public:
    int n, segn;
    std::vector<int> path, depth, in_order, out_order;
    std::vector<std::pair<int,int>> dat;
    const std::pair<int,int> INF = std::make_pair(1000000000, 1000000000);

    lca(const Graph &g, int root)
        : n(g.size()),
          path(n * 2 - 1),
          depth(n * 2 - 1),
          in_order(n),
          out_order(n) {
        int k = 0;
        dfs(g, root, -1, 0, k);
        for (segn = 1; segn < n * 2 - 1; segn <<= 1);
        dat.assign(segn * 2, INF);
        for (int i = 0; i < (int)depth.size(); ++i)
            dat[segn + i] = std::make_pair(depth[i], i);
        for (int i = segn - 1; i >= 1; --i)
            dat[i] = min(dat[i * 2], dat[i * 2 + 1]);
    }

    int get(int u, int v) {
        int l = std::min(in_order[u], in_order[v]);
        int r = std::max(in_order[u], in_order[v]) + 1;
        auto res = range_min(1, segn, l, r);
        return path[res.second];
    }

    void dfs(const Graph &g, int v, int p, int d, int &k) {
        in_order[v] = k;
        path[k] = v;
        depth[k++] = d;
        for (auto &e : g[v]) {
            if (e.dst != p) {
                dfs(g, e.dst, v, d + 1, k);
                path[k] = v;
                depth[k++] = d;
            }
        }
        out_order[v] = k - 1;
    }

    std::pair<int,int> range_min(int v, int w, int l, int r) const {
        if (r <= l || w == 0) return INF;
        if (r - l == w) return dat[v];
        int m = w / 2;
        auto rmin = range_min(v * 2, m, l, std::min(r, m));
        auto lmin = range_min(v * 2 + 1, m, std::max(0, l - m), r - m);
        return min(rmin, lmin);
    }
};


using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    Graph g(n);
    for(int i = 0; i < n; ++i) {
        int k;
        cin >> k;
        for(int j = 0; j < k; ++j) {
            int c;
            cin >> c;
            g[i].emplace_back(i, c, 1);
        }
    }
    lca l(g, 0);
    int q;
    cin >> q;
    for(int i = 0; i < q; ++i) {
        int u, v;
        cin >> u >> v;
        cout << l.get(u, v) << '\n';
    }
}

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

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

	int A, B;
	cin >> A >> B;

	if(A == 1) A = 14;
	if(B == 1) B = 14;
	if(A == B) {
		cout << "Draw" << endl;
	}
	else if(A > B) {
		cout << "Alice" << endl;
	}
	else {
		cout << "Bob" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cassert>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++)
        cin >> A[i];

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

    multiset<int> pos, neg;

    for(int i=1; i<N-1; i++)
        if(A[i] >= 0) pos.insert(A[i]);
        else neg.insert(A[i]);

    neg.insert(A[0]);
    pos.insert(A[N-1]);

    vector<pair<int, int>> v;

    auto itr = neg.begin();
    int x = *itr;
    neg.erase(itr);
    itr = pos.begin();
    int y = *itr;
    pos.erase(itr);

    if(pos.empty()) swap(x, y);
    int cur = x - y;
    v.emplace_back(x, y);

    while(pos.size() > 1){
        auto itr = pos.begin();
        int y = *itr;
        pos.erase(itr);
        v.emplace_back(cur, y);
        cur = cur - y;
    }

    if(!pos.empty()){
        int y = *pos.begin();
        v.emplace_back(y, cur);
        cur = y - cur;
    }

    while(!neg.empty()){
        auto itr = neg.begin();
        int y = *itr;
        neg.erase(itr);
        v.emplace_back(cur, y);
        cur = cur - y;
    }
    cout << cur << endl;
    for(auto xy: v)
        cout << xy.first << " " << xy.second << endl;

    return 0;
}

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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;


#define rep(i,n) for(ll i=0;i<n;i++)



int main() {

  cout<<fixed<<setprecision(10);

  string S;
  getline(cin, S);

  rep(i, S.size()){
    if(S[i] >= 'a' && S[i] <= 'z'){
      S[i] += ('A' - 'a');
    }else if(S[i] >= 'A' && S[i] <= 'Z'){
      S[i] += ('a' - 'A');
    }
  }

  cout<<S<<endl;
  
  return 0;
}




//





Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int x, y = 0;
    cin >> x;
    for (int i = 1; ; i++) {
        y += i;
        if (y >= x) {cout << i; return 0;}
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<string>

using namespace std;


int main(){
	
	
	long long int A, B, V, W, T;
	
	cin >> A >> V;
	cin >> B >> W;
	cin >> T;
	
	int R = ( (A > B) ? (A - B) : (B - A) );
	
	if( V > W ){
		if( R <= (V - W) * T ){
			cout << "YES";
		}
		else{
			cout << "NO";
		}
	}
	else{
		cout << "NO";
	}


	return 0;
	
}

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

// ナップサックdp
int main() {
    int n;
    ll W;
    cin >> n >> W;
    vector<ll> weight(n+1);
    vector<ll> value(n+1);

    weight[0] = 0;
    value[0] = 0;

    for(int i=1; i<n+1; i++){
        cin >> weight[i] >> value[i];
    }

    // dp[i][w]: i番目の商品で合計の重さがwを超えない時の最大合計value
    vector<vector<ll> > dp(n+1, vector<ll>(W+1));
    // 初期値: ０番目の時は全て０
    for(int i=0; i<=W; i++){
        dp[0][i] = 0;
    }

    for(int i=1; i<n+1; i++){
        for(ll w=0; w<=W; w++){
            if(w >= weight[i]){
                dp[i][w] = max(dp[i-1][w-weight[i]] + value[i], dp[i-1][w]);
            }else{
                dp[i][w] = max(dp[i-1][w], dp[i][w]);
            }
        }
    }

    cout << dp[n][W] << endl;

    return 0;
}

Measured memory_bytes: 80256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<bitset> 
#include<map>
using namespace std;
const int maxd=998244353,N=100000;
const double pi=acos(-1.0);
typedef long long ll;
int n,m,cnt=0;
ll bin[320];
bitset<320> a[320],p[320];

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

int main()
{
	n=read();m=read();
	int i,j;
	bin[0]=1;
	for (i=1;i<=300;i++) bin[i]=(bin[i-1]*2)%maxd;
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=m;j++) 
		{
			int tmp=read();
			if (tmp) a[i][j]=1;
		}
	}
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=m;j++)
		{
			if (a[i][j])
			{
				if (p[j][j]) a[i]^=p[j];
				else 
				{
					p[j]=a[i];
					cnt++;
					break;
				}
			}
		}
	}
	ll ans=(((bin[n]-bin[n-cnt])*bin[m-1])%maxd+maxd)%maxd;
	printf("%lld",ans);
	return 0;
}
	


Measured memory_bytes: 256
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/random.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::integer;
namespace rnd = boost::random;

using ll = long long;
namespace bst = boost;
namespace icl = boost::icl;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<ll> D;

  invec<int> c(26);
  vector<vector<int>> s(D, vector<int>(26));
  for (auto&& i : s)
    for (auto&& j : i)
      cin >> j;
  vector<int> t, highest(D);
  ll high = -9999999999, cost = 0;
  rnd::mt19937 mt;
  rnd::uniform_int_distribution rnd_plan(1, 26);
  rnd::uniform_real_distribution<> dist2(0.0, 1.0);

  REP(i, 26) {
    cost += c[i];
  }

  const int tier = cost;
  const int ITER = 1077721600 / D;
  for (int i : bst::irange(1, (int)D))
    highest[i] = rnd_plan(mt);
  t = highest;
  double temp = 1.0;
  const double temp_down = pow(0.0, 1.0 / (double)ITER);
  
  REP(loop, ITER) {
    int r = 0;
    int last[26] = {0};
    
    const int update = loop % D;
    const int told = t[update];
    t[update] = rnd_plan(mt);
    
    REP(i, D) {
      const int plan = t[i] - 1;
      r += s[i][plan];
      cost -= c[plan] * (i + 1 - last[plan]);
      last[plan] = i + 1;
      r -= cost;
      cost += tier;
    }
    
    if (r > high) {
      high = r;
      highest[update] = t[update];
    }
    else /*if (dist2(mt) > exp((double)(r - high) / temp))*/
      t[update] = told;
    cost = tier;
    temp *= temp_down;
  }
  
  for (auto i : highest)
    cout << i << endl;
}

template<typename T> void plot(const T& func) { cout << setprecision(9) << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}




Measured memory_bytes: 3892
#include <iostream>
#include <map>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n; cin>>n;
    struct data {
        data(){}
        string name;
        bool operator<(const data& r) const {
            if(name.size() != r.name.size())
                return name.size() < r.name.size();
            return name < r.name;
        }
    };

    map<data,int> m;
    rep(i,n){
        data d; int n;
        cin>>d.name>>n;
        m[d]+=n;
    }
    for(const auto& e:m){
        cout<<e.first.name<<" "<<e.second<<endl;
    }
}

Measured memory_bytes: 1224
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// conversion
#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) (INT((x).size()))
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
// const ll MOD = 1e9 + 7;
// const int INF = 1<<25;
// const ll INF = 1LL<<50;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;

#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


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


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

  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  cout << min(K, N) * X + max(0, (N - K)) * Y << endl;
  return 0;
}

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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
//constexpr long long MOD = (ll) 1e9 + 7;
constexpr long long MOD = 998244353LL;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
    string s;
    cin>>s;
    set<char> st;
    REP(i,3) st.insert(s[i]);
    cout<<(st.size()==3?"Yes":"No")<<en;
}

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

    solve();
    //ll t;cin>>t;REP(i,t) solve();

    return 0;
}

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

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

    string S[H];
    for (int x = 0; x < H; ++x) {
        cin >> S[x];
    }

    int pat[H - 1][W];
    for (int x = 0; x < H - 1; ++x) {
        for (int y = 0; y < W - 1; ++y) {
            int cnt = 0;
            for (int i = x; i <= x + 1; ++i) {
                for (int j = y; j <= y + 1; ++j) {
                    cnt += (S[i][j] == '#');
                }
            }
            pat[x][y] = 1 - cnt % 2;
        }
        pat[x][W - 1] = 0;
    }

    for (int x = 1; x < H - 1; ++x) {
        for (int y = 0; y < W; ++y) {
            if (pat[x][y] > 0) pat[x][y] += pat[x - 1][y];
        }
    }

    int ans = max(H, W);

    for (int x = 0; x < H - 1; ++x) {
        vector<pair<int, int>> recs;
        for (int y = 0; y < W; ++y) {
            if (recs.empty() || recs.back().second < pat[x][y]) {
                recs.push_back(make_pair(y, pat[x][y]));

            } else if (recs.back().second > pat[x][y]) {
                auto pre = recs.back();

                while (!recs.empty() && recs.back().second > pat[x][y]) {
                    auto p = recs.back();
                    recs.pop_back();
                    int S = (y - p.first + 1) * (p.second + 1);
                    ans = max(ans, S);
                    pre = p;
                }

                if (recs.empty() || recs.back().second < pat[x][y]) {
                    recs.push_back(make_pair(pre.first, pat[x][y]));
                }
            }
        }
    }

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


Measured memory_bytes: 19968
from functools import lru_cache
import sys
sys.setrecursionlimit(10**7)

T = int(input())
INF = 10**18

for _ in range(T):
    N, A, B, C, D = map(int, input().split())
    V = set()

    @lru_cache(maxsize=None)
    def search(now):
        if now == 0:
            return 0

        ret = INF
        for div, cost in zip((2, 3, 5), (A, B, C)):
            q, r = divmod(now, div)
            ret = min(
                ret,
                search(q) + cost + r * D,
                search(q + 1) + cost + (div - r) * D if q + 1 < now else INF,
                now * D
            )
        return ret

    print(search(N))


Measured memory_bytes: 11716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n,x;
  cin>>n;
  x=1;
  int a[500000];
  for(int i=0;i<n;i++){cin>>a[i];}
  for(int i=0;i<n;i++){
  if(a[i]==x)x=x+1;
  } 
  if(x==1) cout<<-1;
  if(x>1) cout<<n-x+1;
  return 0;
}

Measured memory_bytes: 1024
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

use std::collections::BTreeSet;

fn main() {
    let s: String = read();
    let cv: Vec<char> = s.chars().collect();
    let acgt: BTreeSet<_> = ['A', 'C', 'G', 'T'].iter().cloned().collect();
    let mut ans: u32 = 0;
    let mut tmp: u32 = 0;
    for c in cv {
        if acgt.contains(&c) {
            tmp += 1;
            if tmp > ans {
                ans = tmp;
            }
        } else {
            tmp = 0;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
char arr[n][n];
char arr1[m][m];
    for(int i=0; i<n; i++)
        scanf("%s",arr[i]);
 
    for(int i=0; i<m; i++)
        scanf("%s",arr1[i]);
 
 
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            int cnt=0;
            for(int a=0;a<m;a++)
            {
                for(int b=0;b<m;b++)
                {
                    if(arr1[a][b]==arr[i+a][j+b])
                        cnt++;
                }
 
            }
            if(cnt==(m*m))
            {
                printf("Yes\n");
                return 0;
            }
 
        }
    }
    printf("No\n");
 
}


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

std::string S, T;

int main() {
	std::cin >> S >> T;
	int t = T.size();
	int s = S.size();
	for (int i = S.size()- t; i >= 0; i--) {
		bool kk = true;
		for (int j = 0; j < t; j++) {
			if (S[i+j] == '?') {
				continue;
			}
			else if (S[i + j] != T[j]) {
				kk = false;
			}
		}
		if (kk) {
			for (int k = 0; k < i; k++) {
				if (S[k] == '?')std::cout << 'a';
				else std::cout << S[k];
			}
			for (int k = 0; k < t; k++) {
				std::cout << T[k];
			}
			for (int k = i + t; k < s; k++) {
				if (S[k] == '?')std::cout << 'a';
				else std::cout << S[k];
			}
			std::cout << std::endl;
			return 0;
		}
	}
	std::cout << "UNRESTORABLE" << std::endl;
	return 0;
}

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

int main() {
	int a,b,c;
	cin >> a;
	b = a / 10;
	c = a - (a / 10) * 10;
	if (b==9 || c==9) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

#define ALL(V) (V).begin(),(V).end()

using namespace std;

typedef pair<int,int> ii_t;


int main() {
    int n, x, y;
    cin >> n >> x >> y;
    vector<int> vec(n, 0);
    for (int i=1;i<=n;i++) {
        for (int j=i+1;j<=n;j++) {
            if (j <= x) {
                vec[j-i]++;
            } else if (y <= i) {
                vec[j-i]++;
            } else if (x <= i && j <= y) {
                vec[min(j-i, (y-j)+1+(i-x))]++;
            } else if (i <= x && y <= j) {
                vec[(x-i) + 1 + (j-y)]++;
            } else if (i <= x) {
                vec[(x-i) + min(j-x, y-j+1)]++;
            } else if (y <= j) {
                vec[(j-y) + min(y-i, i-x+1)]++;
            }
        }
    }

    for (int i=1;i<n;i++)
        cout << vec[i] << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n,i=0;
        n = sc.nextInt();
        int box[]=new int [n];
        
        for(i=0;i<n;i++){
        	box[i] = sc.nextInt();
        }
        sc.close();
        for(i=(n-1);i>=0;i--){
            System.out.print(box[i]);
            if(i != 0){
                System.out.print(' ');
            }
        }
        System.out.println();
    }
}


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

   int main() {
   int n;
   cin>>n;
   string T,H;
   int pointT=0,pointH=0;
   while(n--){
   cin>>T>>H;
   if(T>H){pointT+=3;}
    else if(T<H){pointH+=3;}
    else{pointT++;pointH++;}}
   cout<<pointT<<" "<<pointH<<endl;
   return 0;
   }


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define all(x) (x).begin(), (x).end() 

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

long long INF=numeric_limits<long long>::max();

vector<pair < string,ii > >str;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    int n,p; 
    cin >> n;
    string s;
    for(int i = 0; i < n; i++){
		cin >> s >> p;
		str.pb(mp(s,mp(p,i+1)));
	}
	sort(all(str));
	int ptr = 0;
	while(ptr < n){
		vi pos;
		pos.pb(str[ptr].se.se);
		while(ptr<n-1&&str[ptr].fi==str[ptr+1].fi){
				pos.pb(str[ptr+1].se.se);
				ptr++;
		}
		ptr++;
		for(int i = pos.size()-1; i>=0; i--)cout << pos[i] << endl;
	}
}	


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

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    if((A < C && C < B) || (B < C && C < A)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    ll a,b,k; cin>>a>>b>>k;
    ll ansa,ansb;
    if(a<=k){
        ansa=0;
        if(b>=k-a)ansb=b-(k-a);
        else b=0;
    }else{
        ansa=a-k;
        ansb=b;
    }
    cout<<ansa<<" "<<ansb<<endl;
}


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

using namespace std;

int n,a,b;
vector <int> h;

bool check(int steps){
    int c=a-b;
    vector <int> t=h;
    for(int i=0;i<n;i++){
        t[i]=max(0LL,t[i]-1LL*steps*b);
    }
    long long req=0;
    for(int i=0;i<n;i++){
        req+=(t[i]+c-1)/c;
    }
    return req<=steps;
}

int main(){
    cin >> n >> a >> b;
    h.resize(n);
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    int l=0,r=1e9;
    while(l+1<r){
        int mid = (l+r)>>1;
        if(check(mid)){
            r=mid;
        }
        else{
            l=mid;
        }
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin>>h>>w;
  vector<string> data(h);
  vector<int> del;
  for(int i=0;i<h;i++){
   cin>>data.at(i);
  }
  for(int i=0;i<h;i++){
    int c=0;
    for(int j=0;j<w;j++){
      if(data.at(i).at(j)=='#')
        c=1;
    }
    if(c==0)
        del.push_back(i+1);
  }
  for(int i=0;i<w;i++){
    int c=0;
    for(int j=0;j<h;j++){
      if(data.at(j).at(i)=='#')
        c=1;
    }
    if(c==0)
        del.push_back(-(i+1));
  }
 int M=0;
  for(int x:del){
    if(x<0){
      for(int i=0;i<data.size();i++){
        if(data.at(i)!=""){
          data.at(i).erase(-(x+1+M),1);
          
        }
      }
      M++;
    }
    else{
      data.at(x-1).erase(0);
    }
  }
  for(int i=0;i<data.size();i++){
    if(data.at(i)!="")
    cout<<data.at(i)<<endl;
  }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n;
    cin >> n;
    int ans=10000;
    for(long long i=1;i*i<=n;i++){
        if(n%i==0){
        long long b=n/i;
        long long a=i;
        int digitsb=0;
        int digitsa=0;
        while(b>0){
            b/=10;
            digitsb++;
        }
        while(a>0){
            a/=10;
            digitsa++;
        }
        int s=max(digitsb,digitsa);
        if(ans>s)ans=s;

        }

    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from itertools import product

N = int(input())
cnt = 0
for i in range(3,len(str(N))+1):
  for p in product(["3", "5", "7"], repeat = i):
    if("3" in p and "5" in p and "7" in p):
      if(int("".join(p)) <= N):
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
K = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
a = int(input())
b = K[a-1]

print(b)

Measured memory_bytes: 2940
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-6;
const vi emp;

int ans=0;
string s;

int main(){
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(i%2==1){
			if(s[i]=='g') ans++;
		}
		else{
			if(s[i]=='p') ans--;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define N 100005
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

int n,e,s[2];
vector<int> G[N];
int color[N];

void dfs(int x,int c){
  
  color[x]=c;
  s[c]++;
  
  for(int i=0;i<G[x].size();i++){

    int nx=G[x][i];
    if(color[nx]!=-1){
      
      if(color[x]==color[nx]){
	cout<<-1<<endl;
	exit(0);
      }
      
    }else dfs(nx,!c);

  }
  
}

ll dp[N];
map<int,int> S;

int main(){
    
  cin>>n>>e;
 
  for(int i=0;i<e;i++){
    
    int a,b;
    cin>>a>>b;
    
    G[a-1].push_back(b-1);
    G[b-1].push_back(a-1);
  }

  memset(color,-1,sizeof(color));

  ll sum=0,sum2=0;
  
  for(int i=0;i<n;i++)
    if(color[i]==-1){
      s[0]=s[1]=0;
      dfs(i,0);
      if(s[0]>s[1]) swap(s[0],s[1]);
      sum+=s[1];
      S[abs(s[0]-s[1])]++;
      sum2+=abs(s[0]-s[1]);
    }

  map<int,int>::iterator ite=S.begin();
  
  memset(dp,-1,sizeof(dp));
  
  while(ite!=S.end()){
    
    dp[0]=0;
    
    ll x=(*ite).first;
    
    for(int i=0;i<n;i++)
      if(dp[i]>=0) dp[i]=(*ite).second;
    
    for(int i=0;i<n;i++)

      if(dp[i]>0&&i+x<=n) dp[i+x]=max(dp[i+x],dp[i]-1);

    ite++;
  }
  
  ll ans=0;
  
  for(ll i=0;i<=n;i++)
    if(dp[i]>=0) ans=max(ans,(sum-i)*(sum-(sum2-i)));
  
  cout<<ans-e<<endl;
  
  return 0;
}

Measured memory_bytes: 10376
#include <stdio.h>

int s[100000];
int t[50000];
int n = 0;
int search(int);

int main(){
    int i, q, count = 0;
    scanf("%d", &n);
    for(i=0;i<n;i++)
        scanf("%d", &s[i]);
    scanf("%d", &q);
    for(i=0;i<q;i++)
        scanf("%d", &t[i]);
    for(i=0;i<q;i++)
        if(search(t[i]))
            count++;
    printf("%d\n", count);
    return 0;
}

int search(int key){
    int l=0;
    int r=n;
    int m;
    while(l<r){
        m = (l+r)/2;
        if(s[m]==key)
            return 1;
        else if(key > s[m])
            l = m+1;
        else
            r=m;
    }
    return 0;
}



Measured memory_bytes: 2280
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif

using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::pair;
using std::swap;
using std::sort;
using std::lower_bound;
using std::unique;

using int64 = long long int;
using pii   = pair<int, int>;
using pii64 = pair<int64, int64>;

const int NIL = -1;
const int INF = (int)2e9;
const int64 INF64 = (int64)2e18;

void init_IO() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}

namespace stupid {
	const int MAX_VALUE = 1234;

	int calced[MAX_VALUE][MAX_VALUE];
	int dp[MAX_VALUE][MAX_VALUE];

	int calc(int a, int b) {
		if(calced[a][b] == 0) {
			for(int i = 1; 2 * i <= a; ++i) {
				dp[a][b] |= !calc(a - 2 * i, b + i);
			}

			for(int i = 1; 2 * i <= b; ++i) {
				dp[a][b] |= !calc(a + i, b - 2 * i);
			}
		}

		calced[a][b] = 1;
		return dp[a][b];
	}
};

void solve() {
	int64 a, b;
	cin >> a >> b;

	cout << (abs(a - b) <= 1 ? "Brown\n" : "Alice\n");
}

int main() {
	init_IO();
	solve();

	return 0;
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

enum P = 1000000007;

void main()
{
    auto N = readln.chomp.to!int;
    int a, b, c;
    long r = 1;
    foreach (x; readln.split.to!(int[])) {
        if (x == a && a == b && a == c) {
            r = (r * 3) % P;
            ++a;
        } else if (x == a && a == b) {
            r = (r * 2) % P;
            ++a;
        } else if (x == b && b == c) {
            r = (r * 2) % P;
            ++b;
        } else if (x == a) {
            ++a;
        } else if (x == b) {
            ++b;
        } else if (x == c) {
            ++c;
        } else {
            writeln(0);
            return;
        }
    }
    writeln(r);
}

Measured memory_bytes: 4304
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> a(N+1, 0), ans(N+1, 0);
	for(int i=1; i<=N; ++i) cin >> a[i];
	for(int i=N; i>0; --i){
	    int now=0;
	    for(int j=2; i*j<=N; ++j) now += ans[i*j];
	    now %= 2;
	    if(now!=a[i]) ans[i]=1;
	}
	int cnt=0;
	vector<int> p;
	for(int i=1; i<=N; ++i){
	    cnt += ans[i];
	    if(ans[i]==1) p.push_back(i);
	}
	cout << cnt << endl;
	if(cnt>0){
	    cout << p[0];
	    for(int i=1; i<cnt; ++i) cout << ' ' << p[i];
	    cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
using namespace std;
typedef long long ll;

vector<pair<int, int>> to[100010];
bool visited[100010];
ll dist[100010];
int main() {
    int h,w,k;
    cin>>h>>w>>k;
    vector<string> s(h);
    rep(i,0,h)cin>>s[i];
    int ans = 0;
    rep(is,0,1<<h){
        rep(js,0,1<<w){
            int cnt = 0;
            rep(i,0,h){
                rep(j,0,w){
                    if(is>>i&1)continue;
                    if(js>>j&1)continue;
                    if(s[i][j]=='#')cnt++;
                }
            }
            if(cnt == k){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5976
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#define NN 1000
using namespace std;

int main(){
  char in[NN][NN];
  int k=0,i,j,a[NN],b[NN],l=0,an=0,bn=0,count=0;

  for(i=0;;i++){
    cin >> in[i];
    if(in[i][0] != 'A'  && in[i][0] != 'B')break;
    // cout << strlen(in[i]) << endl;    

    for(l=0;l<strlen(in[i]);l++){
      if(l>0){
	if(in[i][l] == 'A'){
	an++;
	}
	else if(in[i][l] == 'B'){
	  bn++;
	}
      }
    }
    /*
    cout << "**"<< an << " " << bn << endl;
    cout << "%%0 "<< a[0]<<" "<<b[0] <<endl;
    cout << "%%1 "<< a[1]<<" "<<b[1] <<endl;
    cout << "%%2 "<< a[2]<<" "<<b[2] <<endl;
    cout << "%%3 "<< a[3]<<" "<<b[3] <<endl;
    cout << "%%4 "<< a[4]<<" "<<b[4] <<endl;
    cout << "%%5 "<< a[5]<<" "<<b[5] <<endl;
    cout << "%%6 "<< a[6]<<" "<<b[6] <<endl;
    */ 

    if(an>=9&&bn>=9){
      if(an-1 == bn){
	a[k]=an+1;
	b[k]=bn;
	k++;
	an=0;
	bn=0;
	count++;
      }
      else if(an == bn-1){
	  a[k]=an;
	  b[k]=bn+1;
	  k++;
	  an=0;
	  bn=0;
	  count++;
	}
      }
    else if(an == 10){
      a[k]=an+1;
      b[k]=bn;
      k++;
      an=0;
      bn=0;
      count++;
    }
    else if(bn == 10){
      a[k]=an;
      b[k]=bn+1;
      k++;
      an=0;
      bn=0;
      count++;
    }  
    
    
    
    if(count == 3){
      for(j=0;j<3;j++){
	cout << a[j] << " " <<b[j] <<endl;
      }
      k=0;
      count=0;
    }
    
  }
  
  
  
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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 gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;


int main(){
  int n; cin >> n;
  vl a(n); rep(i,n) cin >> a[i];
  ll ans = 0LL;
  for(ll bit = 0LL; bit < 60; bit++) {
    ll cnt_0 = 0LL, cnt_1 = 0LL;
    rep(i,n) {
      if(a[i] & (1LL << bit)) cnt_1++;
      else cnt_0++;
    }
    
    ll mul = (1LL << bit)%MOD;
    mul = (mul * cnt_0)%MOD;
    mul = (mul * cnt_1)%MOD;
    ans = (ans + mul)%MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

int N;
long long int L[100005], R[100005];

vector<pair<long long int, long long int> > V;

multiset<long long int> SA, SB, PA, PB;

int main(void) {

	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> L[i] >> R[i];
		V.push_back(make_pair(L[i], R[i]));
	}

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

	for (int i = 0; i <= N - 3; i++) {
		PA.insert(V[i].first);
		PB.insert(V[i].second);
	}

	SA.insert(V[N - 1].first);
	SB.insert(V[N - 1].second);

	long long int ans = 0;

	for (int i = N - 2; i >= 1; i--) {
		long long int a, b;
		a = V[i].first;
		b = V[i].second;

		long long int bs = *(SB.begin());

		long long int val = *(PB.begin());

		long long int as = *(--SA.end());

		long long int tmp;


	//	cout << "bs= " << bs << endl;
	//	cout << "val= " << val << endl;
	//	cout << "as= " << as << endl;
		//==============
		tmp = max(b - a+1, (long long int) 0) + max(val - as+1, (long long int) 0);
	//	cout << "tmp= " << tmp << endl;
		ans = max(ans, tmp);
		//==============
		tmp = max(val - a+1, (long long int) 0) + max(bs - as+1, (long long int) 0);
	//	cout << "tmp= " << tmp << endl;
		ans = max(ans, tmp);
		//==============


		auto it1 = PA.end(); it1--; PA.erase(it1);
		auto it2 = PB.end(); it2--; PB.erase(it2);

		SA.insert(V[i].first);
		SB.insert(V[i].second);

		//cout << ans << endl;

	}

	long long int tmp=V[0].second-V[0].first+1;

	long long int min_b = 999999999999999;
	for (int i = 1; i <= N - 1; i++) {
		min_b = min(min_b, V[i].second);
	}

	long long int max_a = V[N - 1].first;

	tmp += max(min_b - max_a+1, (long long int) 0);

	ans = max(ans, tmp);


	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 12784
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

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

int main(){

  int H, W;
  cin >> H >> W;

  string a;
  vector<string> arr(H);
  for (int i = 0; i < H; i++){
    cin >> a;
    arr.at(i) = a;
  }

  for (int i = 0; i < H+2; i++) {
    for (int j = 0; j < W+2; j++) {
      if((i > 0 && i <= H) && (j > 0 && j <= W)){
        string ans = arr.at(i-1);
        cout << ans[j-1];
      } else {
        cout << "#";
      }
    }
    cout << "" << endl;
  }

  return 0;
}

Measured memory_bytes: 3628
def check_include3(n)
	until n == 0
		return true if n % 10 == 3
		n/=10
	end
	return false
end

n = gets.strip().to_i
for i in 1..n
	if i % 3 == 0
		print " #{i}"
	elsif check_include3(i)
		print " #{i}"
	end
end
puts ""


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

long long N, A, B, C, dp[5009][5009], fact[5009], factinv[5009], mod = 1000000007;

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 30; i++) {
		if ((b / (1 << i)) % 2 == 1) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}
long long Div(long long a, long long b, long long m) {
	return (a*modpow(b, m - 2, m)) % m;
}
void init() {
	fact[0] = 1; for (int i = 1; i <= 5000; i++) fact[i] = (fact[i - 1] * i) % mod;
	for (int i = 0; i <= 5000; i++) factinv[i] = Div(1, fact[i], mod);

	dp[0][0] = 1;
	for (int i = 1; i <= 5000; i++) {
		for (int j = 0; j <= 5000; j++) dp[i][j] += dp[i - 1][j];
		for (int j = 1; j <= 5000; j++) { dp[i][j] += dp[i][j - 1]; dp[i][j] %= mod; }
	}
}

int main() {
	init();
	cin >> N >> A >> B >> C;
	if (B % 2 == 1) { cout << "0" << endl; return 0; }
	long long sum = 0;
	for (int i = 0; i <= A; i++) {
		for (int j = 0; j <= C; j++) {
			long long a = i, b = (A - i), c = j, d = B / 2, n = (C - b - 3 * c);
			if (a < 0 || b < 0 || c < 0 || d < 0 || n < 0) continue;
			long long X = fact[a + b + c + d];
			X *= factinv[a]; X %= mod;
			X *= factinv[b]; X %= mod;
			X *= factinv[c]; X %= mod;
			X *= factinv[d]; X %= mod;
			X *= dp[d][n]; X %= mod;
			sum += X; sum %= mod;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 195968
class BIT:
    # 1-indexed
    def __init__(self, n):
        self.size = n + 1
        self.bit = [0] * self.size

    def add(self, i, x):
        """Add x to a[i]."""
        while i < self.size:
            self.bit[i] += x
            i += i & -i

    def sumup(self, i):
        """Sum a[1]~a[i]."""
        res = 0
        while i > 0:
            res += self.bit[i]
            i -= i & -i
        return res

    def query(self, i, j):
        """Sum a[i]~a[j]."""
        return self.sumup(j) - self.sumup(i - 1)


N, Q = map(int, input().split())
C = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(Q)]

ans = [0] * Q
last_appeared = [0] * (N + 1)
bit = BIT(N + 1)
rm = 0
for i, (l, r) in sorted(enumerate(X), key=lambda x: x[1][1]):
    for j in range(rm + 1, r + 1):
        if last_appeared[C[j - 1]] > 0:
            bit.add(last_appeared[C[j - 1]], -1)
        last_appeared[C[j - 1]] = j
        bit.add(j, 1)

    rm = r
    ans[i] = bit.query(l, r)

print(*ans, sep="\n")

Measured memory_bytes: 270484
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

using veci = vector<int>;
using pii = pair<int, int>;
using vecii = vector<pii>;
using ll = long long;
using vecl = vector<ll>;
#define fi first
#define se second
#define endl '\n'

void solve() {
    int M;
    cin >> M;

    ll sum = 0;
    ll digit = 0;
    ll d, c;
    for (int i=0; i<M; ++i) {
        cin >> d >> c;
        sum += d*c;
        digit += c;
    }
    cout << (sum-1)/9 + (digit-1) << endl;
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#if defined(LOCAL_TEST)
    (void)argc;
    freopen(string(argv[0]).append("-test.in").c_str(), "r", stdin);
    int tcs;
    cin >> tcs;
    while (tcs-- > 0)
#endif
    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) //fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N = 153; 
int P;

int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
void upd(int &a, int b) { a = add(a, b); } 

int n, k;

namespace Even { 
	int f[N][N], g[N]; 
	void solve() {
		f[0][0] = 1; 
		int l = k / 2;
		lop(i, 0, n) rep(j, 0, l) {
			upd(f[i + 1][0], f[i][j]); 
			if (j + 1 <= l) upd(f[i + 1][j + 1], f[i][j]);; 
		}
		rep(i, 1, n) rep(j, 0, l) upd(g[i], f[i][j]); 
		cout << mul(g[n / 2], g[(n + 1) / 2]) << endl;
	}
}

namespace Odd {
	int f[2][N][N][N], ans; 
	void solve() {
		f[1][1][0][n] = 1;
		rep(i, 1, n) {
			int ii = i & 1, ni = ii ^ 1;
			mem(f[ni], 0);
			rep(x, 1, n) rep(y, 0, n) rep(t, 0, n) if (f[ii][x][y][t]) {
			 	if (2 * x - 3 >= k) { //loop start with the same parity as i
			 		if (t) {
			 			int nt = min(t - 1, y ? (k - 2 * y - 1) / 2 : n);
			 			upd(f[ni][y + 1][x][nt], f[ii][x][y][t]);
			 		}
			 		upd(f[ni][y + 1][0][n], f[ii][x][y][t]);
			 	} else {
			 		int nx = y + 1, nt = t, ny = x;
			 		if (nx * 2 - 3 >= k) nt = min(nt, (k - 2 * ny + 1) / 2); 
			 		upd(f[ni][y + 1][x][nt], f[ii][x][y][t]); 
			 		upd(f[ni][y + 1][0][t], f[ii][x][y][t]); 
			 	}
			 }
		}
		rep(x, 1, n) rep(y, 0, n) rep(t, 0, n) upd(ans, f[(n + 1) & 1][x][y][t]); 
		cout << ans << endl;
	}
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("d.in", "r", stdin); 
#endif
	cin >> n >> k >> P;
	if (k % 2 == 0) {
		Even::solve(); 
		return 0; 
	}
	Odd::solve(); 
	return 0; 
}




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

int main(){

int n,k;

std::cin >> n>>k;

if(n%k==0)
std::cout << 0 << '\n';

else
std::cout << 1 << '\n';






  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var r1 = CalcRank(Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray());
            var r2 = CalcRank(Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray());
            Console.WriteLine(Math.Abs(r1 - r2));

            int CalcRank(int[] nums)
            {
                var head = nums[0];
                var sorted = nums.OrderBy(x => x).ToArray();
                var len = nums.Length;
                var r = 0;
                for (var i = 0; i < len; i++)
                {
                    if (sorted[i] == head) r = len > 2 ? i : i + 1;
                }

                if (len > 2)
                {
                    return Factorial(len - 1) * r + CalcRank(nums.Skip(1).ToArray());
                }
                else
                {
                    return r;
                }
            }

            int Factorial(int num)
            {
                var result = 1;
                for (var i = 2; i <= num; i++)
                {
                    result *= i;
                }
                return result;
            }
        }
    }
}

Measured memory_bytes: 28468
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
  int64_t n;
  cin >> n;

  vector<pair<int64_t, int64_t>> c(n);
  for (auto&& cc : c) {
    cin >> cc.first >> cc.second;
    cc.first += 1L << 30;
    cc.second += 1L << 30;
  }

  int64_t ans = n;
  for (auto i : irange(0L, n)) {
    for (auto j : irange(0L, n)) {
      if (i == j) {
        continue;
      }

      auto p = c[i].first - c[j].first;
      auto q = c[i].second - c[j].second;

      vector<pair<tuple<int64_t, int64_t, int64_t>, int64_t>> d;
      for (const auto& cc : c) {
        d.emplace_back(
            make_tuple(
                p == 0 ? cc.first : cc.first % abs(p),
                q == 0 ? cc.second : cc.second % abs(q),
                ((p == 0 || q == 0) ? 0 : (cc.first / p - cc.second / q))),
            p == 0 ? cc.second / abs(q) : cc.first / abs(p));
      }

      sort(d.begin(), d.end());
      auto key = d.front().first;
      auto pos = d.front().second;
      int64_t count = 1;
      for (auto i : irange(1uL, d.size())) {
          if (d[i].first != key || d[i].second != pos + 1) {
              ++count;
          }
        key = d[i].first;
        pos = d[i].second;
      }
      ans = min(ans, count);
    }
  }

  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    int ans=0;
    rep(i,s.size()){
        if(s[i]=='o'){
            ans++;
        }
    }
    if(15-s.size()+ans>7){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}



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

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

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

ans = 0
for i in range(1, len(a)):
    if a[i] <= a[i - 1]:
        ans += abs(a[i] - a[i - 1])
        a[i] = a[i - 1]
    else:
        ans += 0

print(ans)


Measured memory_bytes: 31996