akhauriyash/Code-Regression huggingface dataset:
#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 ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
ll power(ll a,ll n)
{
    ll p;
    if(n==0)
    {
        return 1;
    }
    p=power(a,n/2);
    p=((p%mod)*(p%mod))%mod;
    if(n%2==1)
    {
        p=(p%mod)*(a%mod);
    }
    return p;
}
int main()
{
	fastIO;
    ll k,x;
    cin>>k>>x;
    deque<ll>v;
    ll val=1,val1;
    val1=x+1;
    v.pb(x);
    while(val<k)
    {
        v.pb(val1);
        val++;
        val1++;
    }
    val=1;
    val1=x-1;
    while(val<k)
    {
        v.push_front(val1);
        val1--;
        val++;
    }
    for(int i=0;i<v.size();i++)
    {
        cout<<v[i]<<' ';
    }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define rlo(i,n) for(int i=n-1;i>=0;i--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define pr(a) {for(auto x:a)cout<<x<<" ";cout<<nl;}
#define yes cout<<"Yes"<<nl
#define no cout<<"No"<<nl
#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

void f()
{
  string s;
  map<string,int>m;
  char c;
  int n;

  cin>>n>>s;

  m[s]++;
  c=s[sz(s)-1];
  for(int i=1;i<n;i++)
  {
    cin>>s;
    m[s]++;
    if(m[s]>1||s[0]!=c)
    {
      no;
      return;
    }
    c=s[sz(s)-1];
  }

  yes;
}

int main()
{
    su;
    f();
    return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <cstring>
#include <algorithm>
#include <functional>
#include <bits/stdc++.h>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <stdlib.h>
#include <deque>
#include <cstdint>
using namespace std;

int main () {
  int a, b, c, d;
  cin >> a >>b >> c >> d;
  if (((c+b-1)/b) > ((a+d-1)/d)){
    cout << "No";
  } else {
    cout << "Yes";
  }
}

Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] data = br.readLine().split(" ");
    int d = Integer.parseInt(data[0]);
    int t = Integer.parseInt(data[1]);
    int s = Integer.parseInt(data[2]);
    br.close();
    System.out.println( s * t >= d ? "Yes" : "No");
  }
}

Measured memory_bytes: 32572
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(Type, ...)  Type __VA_ARGS__; input(__VA_ARGS__)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
inline i64  sigma(i64 n)            { return (n * (n + 1) >> 1); }
inline i64  updiv(i64 a, i64 b)     { return (a + b - 1) / b; }
inline i64  sqr(i64 n)              { return n * n; }
inline string to_string(char c)     { return string(1, c); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}
template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void input() {}
template <class Head, class... Tail>
inline void input(Head &head, Tail&... tail) { cin >> head; input(tail...); }

inline void print() { cout << "\n"; }
template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}

template <typename Func>
struct FixPoint : Func {
    inline constexpr FixPoint(Func &&f) noexcept : Func(forward<Func>(f)) {}

    template <typename... Args>
    inline decltype(auto) operator()(Args &&... args) const {
        return Func::operator()(*this, forward<Args>(args)...);
    }
};

template< typename Func >
inline decltype(auto) makeFixPoint(Func &&f) {
    return FixPoint< Func >{forward< Func >(f)};
}
// }}} End Header

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

    var(int, M, D);

    int cnt = 0;

    reps(i, 1, D) {
        const int a = (i / 10) % 10;
        const int b = i % 10;
        if (a >= 2 && b >= 2 && a * b <= M) ++cnt;
    }

    print(cnt);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  string S;
  cin >> S;
  ll res=0;
  map<char,ll> mp;
  REP(i,S.size())mp[S[i]]++;
  for(char i = 'a';i<='z';i++){
    for(char j=i+1;j<='z';j++){
      res += mp[i]*mp[j];
    }
  }
  cout << res+1 << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define INF 1000000000000
#define MOD 1000000007
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3)                                                 \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << endl
#define debug_4(x1, x2, x3, x4)                                             \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5)                                         \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

using namespace std;
using ll = long long;

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

Measured memory_bytes: 3168
#include <stdio.h>
#include <ctype.h>

int main()
{
 char str[1200];
 char c;
 int i=0;
 while(1)
 {
  scanf("%c",&c);
  if(c== '\n' || c =='\0')
   break;
  if(isupper(c))
    str[i]=tolower(c);
  else
  {
   if(islower)
     str[i]=toupper(c);
   else
     str[i]=c;
  }
  i++;
 }
 str[i] = '\0';
 printf("%s\n", str);
 return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
#define start_routine cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int begtime = clock();
#define end_routine int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0;
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define int long long
#define mp make_pair
#define fr(i,a,b) for(i=a;i<b;i++)
#define mod 1000000007
#define FILEIO freopen("C:/Users/Aman/Desktop/kachda/input.txt", "r", stdin); freopen("C:/Users/Aman/Desktop/kachda/output.txt", "w", stdout);

using namespace std;

signed main()
{
	//FILEIO
 	start_routine
	int n,k;
	cin>>n>>k;
	int dp[n + 1] = {0};
	int h[n + 1];
	h[0] = mod;
	int i;
	fr(i,1,n + 1)
	{
		cin>>h[i];
	}

	fr(i,2,n + 1)
	{
		int temp = mod;
		for(int j = 1; j <= k && i - j > 0; j++)
		{
			temp = min(temp, dp[i-j] + abs(h[i-j] - h[i]));
		}
		dp[i] = temp;
	}

	cout<<dp[n];
 
 	end_routine
}

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<pair<unsigned long, unsigned long>> u, d, l, r;
    for(unsigned long i{0}; i < N; ++i){
        unsigned long X, Y;
        cin >> X >> Y;
        X += 1000001;
        ++Y;
        char c;
        cin >> c;
        switch(c){
            case 'U':
                u.emplace_back(X, Y);
                break;
            case 'R':
                r.emplace_back(X, Y);
                break;
            case 'D':
                d.emplace_back(X, Y);
                break;
            case 'L':
                l.emplace_back(X, Y);
                break;
        }
    }
    unsigned long ans{numeric_limits<unsigned long>::max()};
    const auto& calc = [&ans](const vector<tuple<unsigned long, unsigned long, bool>>& tp){
        tuple<unsigned long, unsigned long, bool> last{0, 0, false};
        for(const auto& [x, y, f] : tp){
            if(f && get<0>(last) == x)ans = min(ans, y - get<1>(last));
            if(!f)last = {x, y, f};
        }
    };

    // U D
    {
        vector<tuple<unsigned long, unsigned long, bool>> ud;
        for(const auto& [x, y] : u)ud.emplace_back(x, y, false);
        for(const auto& [x, y] : d)ud.emplace_back(x, y, true);
        sort(begin(ud), end(ud));
        calc(ud);
    }
    // L R
    {
        vector<tuple<unsigned long, unsigned long, bool>> lr;
        for(const auto& [x, y] : l)lr.emplace_back(y, x, true);
        for(const auto& [x, y] : r)lr.emplace_back(y, x, false);
        sort(begin(lr), end(lr));
        calc(lr);
    }
    // U R
    {
        vector<tuple<unsigned long, unsigned long, bool>> ur;
        for(const auto& [x, y] : u)ur.emplace_back(x + y, x - y, true);
        for(const auto& [x, y] : r)ur.emplace_back(x + y, x - y, false);
        sort(begin(ur), end(ur));
        calc(ur);
    }
    // D L
    {
        vector<tuple<unsigned long, unsigned long, bool>> dl;
        for(const auto& [x, y] : d)dl.emplace_back(x + y, x - y, false);
        for(const auto& [x, y] : l)dl.emplace_back(x + y, x - y, true);
        sort(begin(dl), end(dl));
        calc(dl);
    }
    // U L
    {
        vector<tuple<unsigned long, unsigned long, bool>> ul;
        for(const auto& [x, y] : u)ul.emplace_back(x - y, x + y, false);
        for(const auto& [x, y] : l)ul.emplace_back(x - y, x + y, true);
        sort(begin(ul), end(ul));
        calc(ul);
    }
    // D R
    {
        vector<tuple<unsigned long, unsigned long, bool>> dr;
        for(const auto& [x, y] : d)dr.emplace_back(x - y, x + y, true);
        for(const auto& [x, y] : r)dr.emplace_back(x - y, x + y, false);
        sort(begin(dr), end(dr));
        calc(dr);
    }
    if(ans + 1)cout << ans * 5 << endl;
    else puts("SAFE");
    return 0;
}

Measured memory_bytes: 17040
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
map<int,map<int,int> >RB;
set<int>s[maxn];
set<int>::iterator it;
int qa[maxn],qb[maxn],fa[maxn],siz[maxn],h=1,e;
int get(int x) {
	return x==fa[x]?x:fa[x]=get(fa[x]);
}
int main() {
	int n,x,y;
	scanf("%d",&n);
	for(int i=1;i<2*n-1;i++) {
		scanf("%d%d",&x,&y);
		s[x].insert(y);
		s[y].insert(x);
		if(x>y)swap(x,y);
		RB[x][y]++;
		if(RB[x][y]==2)qa[++e]=x,qb[e]=y;
	}
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int T=1;T<n;T++) {
		if(h>e) {
			puts("NO");
			return 0;
		}
		while(h<=e&&(x=get(qa[h]))&&(y=get(qb[h++]))&&x==y);
		if(x==y) {
			puts("NO");
			return 0;
		}
		if(s[x].size()>s[y].size())swap(x,y);
		fa[x]=y;
		for(it=s[x].begin();it!=s[x].end();it++) {
			int v=*s[x].find(*it),u=y;
			s[v].erase(s[v].find(x));
			if(v==u)continue;
			s[v].insert(u);
			s[u].insert(v);
			if(v>u)swap(v,u);
			RB[v][u]++;
			if(RB[v][u]==2)qa[++e]=v,qb[e]=u;
		}
	}
	puts("YES");
	return 0;
}

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

int main() {
	vector<int> A = {1, 1, 1, 2, 1, 2, 1, 5,
					 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2,
					 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int K;
	cin >> K;

	cout << A.at(K - 1) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    char s[5];
    int i,sum=700;
    for(i=0;i<3;i++)
        scanf("%c",&s[i]);
    for(i=0;s[i];i++)
    {
        if(s[i]=='o')
            sum=sum+100;
    }
    printf("%d\n",sum);
}


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

using namespace std;

#define vit vector<int>::iterator
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fr first
#define sc second
#define skip continue
#define PI 3.14159265

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const ll MAXN = 3e5 + 3;
const int  M   =   1e9+7;

void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

bool cmp(const string& a, const string& b) {
    return (a + b) < (b + a);
}

void solve(){
    string s;
    cin >> s;
    int l, r;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'A'){
            l = i;
            break;
        }
    }
    for(int i = s.size(); i >= 0; i--){
        if(s[i] == 'Z'){
            r = i;
            break;
        }
    }
    cout << r - l + 1;
}


int main(){
    //freopen("slalom.in","r",stdin);
    //freopen("slalom.out","w",stdout);
    //faster();
    int n = 1;
    //cin >> n;
    while(n--){
        solve();
        cout << endl;
    }
    //fclose(stdout);
}


Measured memory_bytes: 3724
#include<stdio.h>
#include<limits.h>
#include<string.h>
#include<stdlib.h>

int main(){
  int m[100][100],n,i,j,k,l;
  int rc,cr;
  char buf[1000],*ind,*prev;
  do{
    fgets(buf,1000,stdin);
    n=atoi(buf);
    if(!n) break;
    for(i=0;i<n;i++){
      fgets(buf,1000,stdin);
      prev=ind=buf;
      j=0;
      while((ind=strchr(ind,' '))!=NULL){
	*ind='\0';
	ind++;
	m[i][j++]=atoi(prev);
	prev=ind;
      }
      m[i][j]=atoi(prev);
    }
    for(i=0,rc=0,cr=INT_MAX;i<n;i++){
      for(j=0,k=INT_MAX,l=0;j<n;j++){
	if(k>m[i][j]) k=m[i][j];
	if(l<m[j][i]) l=m[j][i];
      }
      if(rc<k) rc=k;
      if(cr>l) cr=l;
    }
    if(rc==cr)
      printf("%d\n",rc);
    else
      printf("0\n");
  }while(1);
  return 0;
}

Measured memory_bytes: 0
import sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    import os
    import re
    with open(__file__) as f:
        source = f.read().split('###''nbacl')
    for s in source[1:]:
        s = re.sub("'''.*", '', s)
        sp = s.split(maxsplit=1)
        if os.path.dirname(sp[0]):
            os.makedirs(os.path.dirname(sp[0]), exist_ok=True)
        with open(sp[0], 'w') as f:
            f.write(sp[1])
    from nbmodule import cc
    cc.compile()
import numpy as np
from numpy import int64
from nbmodule import solve


f = open(0)
N, K = [int(x) for x in f.readline().split()]
A = np.fromstring(f.read(), dtype=int64, sep=' ')
ans = solve(N, K, A)
print(ans)

'''
###nbacl nbmodule.py
import numpy as np
from numpy import int64
from numba import njit
from numba.types import i8
from numba.pycc import CC
import nbacl.segtree as seg
cc = CC('nbmodule')


@cc.export('solve', (i8, i8, i8[:]))
@njit
def solve(N, K, A):
    dp = np.zeros(300_001, dtype=int64)
    d = seg.segtree(dp, max, 0)
    for i in range(N):
        x = seg.prod(d, max, (A[i] - K) if A[i] > K else 0, (A[i] + K + 1) if A[i] + K < 300_000 else 300_001) + 1
        seg.set(d, max, A[i], x)
    return seg.all_prod(d)


if __name__ == '__main__':
    cc.compile()
###nbacl nbacl/segtree.py
import numpy as np
from numba import njit
from numba.types import i8


@njit
def ceil_pow2(n):
    x = 0
    while (1 << x) < n:
        x += 1
    return x


@njit
def segtree(a, op, e):
    log = ceil_pow2(a.shape[0])
    size = 1 << log
    d = np.empty(size * 2, dtype=a.dtype)
    d[size:size + len(a)] = a
    d[size + len(a):] = e
    # e
    d[0] = e
    for i in range(size - 1, 0, -1):
        update(d, i, op)
    return d


@njit
def update(d, k, op):
    d[k] = op(d[2 * k], d[2 * k + 1])


@njit
def set(d, op, p, x):
    p += d.shape[0] // 2
    d[p] = x
    while p > 1:
        p >>= 1
        update(d, p, op)


@njit
def get(d, p):
    return d[p + d.shape[0] // 2]


@njit
def prod(d, op, left, right):
    size = d.shape[0] // 2
    sml = d[0]
    smr = d[0]
    left += size
    right += size

    while left < right:
        if left & 1:
            sml = op(sml, d[left])
            left += 1
        if right & 1:
            right -= 1
            smr = op(d[right], smr)
        left >>= 1
        right >>= 1

    return op(sml, smr)


@njit
def all_prod(d):
    return d[1]

'''


Measured memory_bytes: 40944
#include<iostream>
#include<climits>
#define MAX 500001
using namespace std;
void merge(int*, int, int, int);
void mergeSort(int*, int, int);
int count = 0;
int main() {
	int n, A[MAX];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	//cout << INT_MAX<<endl;
	mergeSort(A, 0, n);
	for (int i = 0; i < n; i++) {
		cout << A[i];
		if (i != n - 1) {
			cout << " ";
		}
		else {
			cout << endl;
		}
	}
	cout << count << endl;
}

void merge(int *A, int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	int L[n1+1], R[n2+1];
	//cerr << "L: ";
	for (int i = 0; i < n1; i++) {
		L[i] = A[left + i];
		//cerr << L[i] << " ";
	}
	//cerr << endl << "R: ";
	for (int i = 0; i < n2; i++) {
		R[i] = A[mid + i];
		//cerr << R[i] << " ";
	}
	//cerr << endl;
	L[n1] = INT_MAX;
	R[n2] = INT_MAX;
	int i = 0, j = 0;
	for (int k = left; k < right; k++) {
		count++;
		if (L[i] <= R[j]) {
			A[k] = L[i];
			i++;
		}
		else {
			A[k] = R[j];
			j++;
		}
	}
}


void mergeSort(int *A,int left,int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
}

Measured memory_bytes: 7012
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007; // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const ld PI = acos((ld)-1);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}

ll dp[3010][3010][4]={};

signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  int h,w,kk;cin>>h>>w>>kk;
  VV<ll> v(h,V<ll>(w,0));
  rep(i,0,kk){
    ll g,r,x;cin>>g>>r>>x;
    --g;--r;
    v[g][r]=x;
  }

  rep(i,0,h+2)rep(j,0,w+2)rep(k,0,4)dp[i][j][k]=-LINF;
  dp[0][0][0]=0;
  dp[0][0][1]=v[0][0];


  rep(i,0,h){
    rep(j,0,w){
      rep(k,0,4){
        if(i<h-1)chmax(dp[i+1][j][1],dp[i][j][k]+v[i+1][j]);

        if(j<w-1 && k<3)chmax(dp[i][j+1][k+1],dp[i][j][k]+v[i][j+1]);

        chmax(dp[i+1][j][0],dp[i][j][k]);

        chmax(dp[i][j+1][k],dp[i][j][k]);
      }
      
    }
  }

  ll ans=0;
  rep(i,0,4)chmax(ans,dp[h-1][w-1][i]);
  cout<<ans<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

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

int main() {
    string b;
    string answer;
    cin >> b;
    
    if (b == "A"){
    	cout << "T" << endl;
    } else if (b == "T") {
    	cout << "A" << endl;
    } else if (b == "G") {
    	cout << "C" << endl;
    } else {
    	cout << "G" << endl;
    }

}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    string s,t;
    int i , j ;
    int Num = 0;
    int Collect = 2000;
    cin >> s ;
    cin >> t ;
    
    for(i = 0 ; i <= s.length() - t.length() ; i++){
        for(j = 0 ; j < t.length() ; j++){
            if(s[j + i] != t[j]){
                Num ++ ;
            }
        }
        if(Num < Collect)
            Collect = Num;
        Num = 0;
    }
    
    cout << Collect << endl;
}


Measured memory_bytes: 3188
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int x;
	std::cin >> x;
	std::cout << ((x<30)?"No":"Yes") << std::endl;
	return 0;
}


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

using namespace std;

int solve(){
    int n,k;
    cin>>n>>k;
    vector<int> p(n);
    for (int i = 0; i < n; i++)
    {
        cin>>p[i];
    }

    sort(p.begin(),p.end());
    int res=0;
    for (int i = 0; i < k; i++)
    {
        res+=p[i];
    }
    cout<<res;
    
    return 0;
}

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


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#include <math.h>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int x;
	cin >> x;
    string ans;
    if((x/10)%111==0||(x%1000)%111==0)ans="Yes";
    else ans = "No";
      cout << ans << endl;
}

Measured memory_bytes: 256
/**
*    created: 04.05.2020 07:59:31
**/

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


int main() {
    ll x;
    cin >> x;
    ll a=0LL, b=0LL;
    rep(i,200){
        for (int j = -200; j < 200;j++){
            if(/*i*i*i*i*i-j*j*j*j*j*/pow(i,5)-pow(j,5)==x){
                a = i;
                b = j;
                break;
            }
        }
    }
cout << a<<" "<<b << endl;
}

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

long long int solve(int n)
{
	long long int c=0;
	for(int i = 1 ; i  < n; i++)
			for(int j = 1 ; j < n; j++)
			{
				if(i*j<n)
				{
					c++;
//					cout<<i<<'\t'<<j<<endl;
				}
				else break;
	        }
	return c;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int t; cin>>t;
	cout<<solve(t)<<endl;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i, sz(v)) { if (i) os << " "; os << v[i]; } return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a - mod; }

void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
      solve();
    }
}



int n; ll m;
vector<int> a;
vector<ll> acc;

ll check(int x) {
    ll cnt = 0;
    rep(i, n) { // 左手
      int it = lb(a, x - a[i]);
      cnt += n - 1 - it + 1;
    }
    if (cnt < m) return 0;
    return cnt;
}

template<typename T>
void binary_search(T ok, T ng) {
    while (abs(ng - ok) > 1) {
        T mid = (ng + ok) / 2;
        (check(mid) ? ok : ng) = mid;
    }
    // cout << ok << endl;

    /*
    ちょうど m ペアになるまで ok 捨てる
    ok 捨てて m ペア未満になることはない
    なったら, ok は ok 未満のはず
    */

    ll cnt = check(ok);
    ll ans = 0;
    ans -= (cnt - m) * ok; // ok を捨てる

    // ok 以上の合計
    rep(i, n) {
      int it = lb(a, ok - a[i]);
      if (it == sz(a)) continue;

      ans += 1LL * (n - it) * a[i]; // 左手
      ans += acc[n] - acc[it];
      // cout << i << " " << it << " " << a[i] << " " << acc[n] - acc[it] << endl;
    }
    cout << ans << endl;
}

void solve() {

  cin >> n >> m;
  a.resize(n);
  rep(i, n) cin >> a[i];
  sort(all(a));

  acc.resize(n + 1);
  rep(i, n) acc[i + 1] = acc[i] + a[i];

  binary_search(0, 300000); // m pair, x 以上ができるか
}


Measured memory_bytes: 1536
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>

using namespace std;

struct State {
  size_t pos;
  string str;
};

inline void Push(queue<State>& q, size_t i) {
  q.push({i, "dream"});
  q.push({i, "dreamer"});
  q.push({i, "erase"});
  q.push({i, "eraser"});
}

int main() {
  string S;
  cin >> S;
  const size_t len = S.size();

  queue<State> q;
  Push(q, 0);

  bool found = false;
  while (!q.empty()) {
    auto s = q.front();
    q.pop();
    const auto end = s.pos + s.str.size();
    if (s.pos >= len || end > len) {
      continue;
    }
    if (S.substr(s.pos, end - s.pos) != s.str) {
      continue;
    }

    if (end == len) {
      found = true;
      break;
    }
    Push(q, end);
  }
  if (found)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}


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

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

    for(int a = 1; a <= 3500; ++a) {
        for(int b = 1; b <= 3500; ++b) {
            //(ab + c * (a + b)) * N = 4 * abc
            //ab * N + c * (a + b) * N - 4 * abc = 0
            // c * ((a + b) * N - 4 * ab) = -ab * N
            long long numerator = -1LL * a * b * n;
            long long denom = 1LL * (a + b) * n - 4LL * a * b;
            if(denom == 0)
                continue;
            if(numerator % denom == 0 and numerator / denom  <= 3500 and numerator / denom >= 0) {
                cout << a << " " << b << " " << numerator / denom << "\n";
                return 0;
            }
        }
    }
}

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

class Program
{
    static void Main()
    {
        Console.WriteLine(Solve());
        //Solve();
        return;
    }

    public static string Solve()
    {
        int N = ReadInt();
        int[] P = ReadInts();
        int min = P[0];
        int ans = 0;
        for (int i = 0; i < N; i++)
        {
            if (min >= P[i])
            {
                min = P[i];
                ans++;
            }
        }
        return ans.ToString();
    }

    private static string Read() { return Console.ReadLine(); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
}


Measured memory_bytes: 33116
n,k=map(int,input().split())
lambda_1=lambda s:int(s)-1
a=list(map(lambda_1, input().split()))
#print(a)
r=[-1]*n
b=[]
c=0
while True:
	if len(b)==k-1:
		print(a[c]+1)
		exit()
	if r[a[c]]!=-1:
		a0=b.index(a[c])
		k0=(k-1-a0)%(len(b)-a0)+a0
		"""print(k,len(b),a0)
		print("b",b,a[c])
		print("r",r)
		print(a0,k0)"""
		print(b[k0]+1)
		exit()
	b.append(a[c])
	r[a[c]]=c
	c=a[c]

Measured memory_bytes: 31344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll, ll, ll>>>;

// MOD確認

ll N;
char C[2000010];
 
int main(){
   cin >> N;
   ll R = 0,W = 0;
   rep(i,N){
      cin >> C[i];
      if(C[i] == 'R') R++;
      else W++;
   }
   ll cnt1 = 0,cnt2 = 0;
   rep(i,R){
      if(C[i] == 'W') cnt1++;
   }
   FOR(i,R,N){
      if(C[i] == 'R') cnt2++;
   }
   cout << max(cnt1,cnt2) << endl;
}

Measured memory_bytes: 3828
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int X, A; cin >> X >> A;
    if(X < A) {
        cout << 0 << endl;
        return 0;
    }else {
        cout << 10 << endl;
    }
	return 0;
}

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

int in(){int x;scanf("%d",&x);return x;}

int main(){
	int N=in(), M=in();
	map<int,int> V;
	while(M--){
		int l=in(), r=in();
		V[r] = max(V[r], l);
	}
	int ans = 0, R = 0;
	for(auto m:V) if(m.second >= R){ R = m.first; ans++; }
	cout<< ans <<endl;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repp(i,s,n) for(int i=s;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  LL n,z,w;
  cin >> n >> z >> w;
  vector<LL> a(n);
  rep(i,n) cin >> a[n-i-1];
  vector<vector<LL>> dp(n,vector<LL>(2));
  dp[0][0]=dp[0][1]=abs(a[1]-a[0]);
  repp(i,1,n-1){
    dp[i][0]=dp[i][1]=abs(a[i+1]-a[0]);
    rep(j,i){
      dp[i][0]=max(dp[i][0],dp[j][1]);
      dp[i][1]=min(dp[i][1],dp[j][0]);
    }
  }
  LL ans=abs(w-a[0]);
  rep(i,n-1) ans=max(ans,dp[i][1]);
  cout << ans << endl;
  return 0;
}


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

import numpy as np


def solv(n, a_, b_):
    idxs = np.argsort(b_, kind='mergesort')
    t = 0
    for i in idxs:
        t += a_[i]
        if t > b_[i]:
            return 'No'
    return 'Yes'


if __name__ == '__main__':

    n = int(input())
    a_ = np.empty(n, dtype=np.int32)
    b_ = np.empty(n, dtype=np.int32)

    for i in range(n):
        a, b = map(int, input().split())
        a_[i] = a
        b_[i] = b

    ans = solv(n, a_, b_)

    print(ans)

Measured memory_bytes: 16344
import java.util.Scanner;
        
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String s = sc.nextLine();
        String t = sc.nextLine();

        int n = s.length();
        String[] arrayS = new String[n];
        String[] arrayT = new String[n + 1];
        boolean flag = true;

        for (int i = 0; i < n; i++) {
            arrayS[i] = s.substring(i, i + 1);
        }
        for (int i = 0; i < n + 1; i++) {
            arrayT[i] = t.substring(i, i + 1);            
        }
        for (int i = 0; i < n; i++) {
            if (!arrayS[i].equals(arrayT[i])) {
                flag = false;
            }
        }
        if (flag) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35720
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if (A + B == C + D) cout << "Balanced" << endl;
  else if (A + B > C + D) cout << "Left" << endl;
  else cout << "Right" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int solve(int x,int y);
int ax,ay;
int mas[20][20];
int memo[20][20];
int main(){
  while(1){
    int ans=0;
    cin>>ax>>ay;
    if(ax==0 && ay==0) break;
    for(int i=1;i<=ay;i++){
      for(int j=1;j<=ax;j++){
	cin>>mas[i][j];
	memo[i][j]=0;
      }
    }
    for(int i=1;i<=ax;i++){
      if(mas[1][i]!=1){
	ans+=solve(i,1);
      }
    }
    cout<<ans<<endl;
  }
}
int solve(int x,int y){
  if(y>=ay){
    return 1;
  }else if(memo[y][x]!=0){
    return memo[y][x];
  }else if(mas[y][x]==2){
    if(mas[y+2][x]!=1){
      return memo[y][x]=solve(x,y+2);
    } 
    else{
      return 0;
    }
  }
  else if(mas[y][x]==1){
    return 0;
  }
  else{
    int anss=0; 
    if(mas[y+1][x]!=1){
      anss+=solve(x,y+1);
    }
    if(x+1<=ax && 0<x+1 && mas[y+1][x+1]==0){
      anss+=solve(x+1,y+1);
    }
    if(0<x-1 && x-1<=ax && mas[y+1][x-1]==0){
      anss+=solve(x-1,y+1);
    }
    return memo[y][x]=anss;
  }
}

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

using namespace std;

class UF {
public:
    vector<int> p;
    UF(size_t n) : p(n) {
        for(size_t i=0; i<n; i++)
            p[i] = i;
    };
    int find(int x) {
        if(p[x] == x) return x;
        return p[x] = find(p[x]);
    };
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        p[x] = y;
    };
};

template<typename T>
struct SparseTable {
    using F = function<T(T,T)>;

    F f;
    vector<vector<T>> st;
    
    SparseTable(const vector<T> &v, const F &f_) : f(f_) {
        size_t b = 0;
        while(((size_t)1 << b) <= v.size()) b++;
        st.assign(b, vector<T>(1<<b));
        copy_n(v.begin(), v.size(), st[0].begin());

        for(size_t i=1; i<b; i++)
            for(int j=0; j+(1<<(i-1)) + (1<<(i-1)) < (1<<b); j++)
                st[i][j] = f(st[i-1][j], st[i-1][j + (1<<(i-1))]);
    }

    // [l, r)
    inline T query(size_t l, size_t r) const {
        size_t b = 0;

        while(((size_t)1 << b) <= (r - l)) b++;
        b--;

        return f(st[b][l], st[b][r - (1<<b)]);
    }
};


int main(void) {
    long n, k;
    cin >> n >> k;
    vector<long> p(n);
    for(auto &e: p) cin >> e;

    SparseTable<long> mi(p, [&](long a, long b){return min(a, b);});
    SparseTable<long> ma(p, [&](long a, long b){return max(a, b);});
    UF uf(n+1);

    vector<long> mas(n); // i..mas[i] is sorted
    for(int i=0; i<n; i++) {
        int j = i;
        for(; j+1<n; j++)
            if(p[j] > p[j+1]) break;
        // p[j-1] < p[j] && p[j] > p[j+1]
        for(int k=i; k<=j; k++)
            mas[k] = j;
        i = j;
    }

    auto f = [&](long i, long j) -> bool {
        // i..j-1 sorted
        if(mas[i] < j-1) return false;
        if(mas[i+k] < j+k-1) return false;

        long M = ma.query(i, j);
        long m = mi.query(i+k, j+k);

        if(ma.query(j, i+k) > m) return false;
        if(mi.query(j, i+k) < M) return false;

        return true;
    };

    for(long i=0; i+1<=n-k; i++)
        if(f(i, i+1))
            uf.unite(i, i+1);

    {
        vector<long> scnt(n);
        for(int i=0; i<=n-k; i++)
            if(mas[i] >= i+k-1)
                uf.unite(i, n);
    }

    long r = 0;
    {
        set<int> s;
        for(int i=0; i<=n-k; i++) {
            int t = uf.find(i);
            if(s.count(t)) continue;
            s.insert(t);
            r++;
        }
    }
    cout << r << endl;
}


Measured memory_bytes: 87292
def next_rank_num(nStr):
  if nStr == '3':
    return '5'
  elif nStr == '5':
    return '7'
  elif nStr == '7':
    return '3'

def next_num(nStr):
  length = len(nStr)
  i = 1
  nrn = '3'
  nList = []
  while i <= length and nrn == '3':
    nrn = next_rank_num(nStr[length-i])
    nList.append(nrn)
    if nrn == '3':
      i += 1
  nList.reverse()
  if i > length:
    return '3' + ''.join(nList)
  else:
    return nStr[0:length-i] + ''.join(nList)
   
num = int(input())
count = 0
nStr = "357";
while int(nStr) <= num:
  if len({'3', '5', '7'} - set(nStr)) == 0:
    count += 1
  nStr = next_num(nStr)
print(str(count))

Measured memory_bytes: 3064
#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>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

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


int main(){
    string s;
    cin >> s;

    if(s[0] == s[1] && s[1] == s[2]){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define endl "\n"
#endif
using namespace std;
typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> v;
typedef vector<lu> vu;
typedef vector<v> vv;
typedef vector<vu> vvu;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
typedef vector<set<ll>> vsll;
typedef set<pair<ll, ll>> spll;
typedef vector<spll> vspll;
typedef vector<pll> vpll;
typedef pair<lu, lu> puu;
typedef vector<puu> vpuu;
const ll MOD = 1e9 + 7;
const ld PI = 2 * acos(0.0);
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
#define round(x, y) ((x + y - 1) / y)
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define sz(x) (ll) x.size()
#define sq(x) ((x) * (x))
#define cb(x) ((x) * (x) * (x))
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define yesno(f) \
    if (f)       \
        yes else no;
#define noo \
    { no return; }

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template <typename T = ll>
vector<T> ga(ll n, bool oneIndexed = false) {
    vector<T> a = vector<T>(n + oneIndexed);

    for (ll i = 0; i < n; i++) {
        T p;
        cin >> p;
        a[i + oneIndexed] = p;
    }

    return move(a);
}

template <typename T, typename A>
void pa(vector<T, A> const &a, ll begin = 0, ll end = -1) {
    if (end == -1)
        end = sz(a) - 1;
    for (ll i = begin; i <= end; i++) {
        cout << a[i] << " ";
    }
    cout << endl;
}

void solve() {
    string k;
    ll d;
    cin >> k >> d;
    ll n = sz(k);
    vv dp(n, v(d, 0));

    // dp[i][j] = number of ways to form number till i-th position from MSB such
    // that i-th posn par remainder is j
    for (ll i = 0; i < k[0] - '0'; i++) {
        dp[0][i % d] += 1;
    }

    ll sumsofar = k[0] - '0';
    for (ll pos = 1; pos < n; pos++) {
        for (ll prevrem = 0; prevrem < d; prevrem++) {
            for (ll dig = 0; dig < 10; dig++) {
                ll rem = prevrem + dig;
                rem %= d;
                dp[pos][rem] += dp[pos - 1][prevrem];
                dp[pos][rem] %= MOD;
            }
        }

        for (ll i = 0; i < k[pos] - '0'; i++) {
            ll rem = (sumsofar + i) % d;
            dp[pos][rem] += 1;
            dp[pos][rem] %= MOD;
        }

        sumsofar += k[pos] - '0';
    }
    if (sumsofar % d != 0)
        dp[n - 1][0] -= 1;
    dp[n - 1][0] += MOD;
    dp[n - 1][0] %= MOD;

    cout << dp[n - 1][0];
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // freopen("file", "r", stdin);
    // freopen("file", "w", stdout);
    // ll t;cin >> t;while(t--)
    solve();
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll INF = numeric_limits<ll>::max()/2;
const int MOD = 1e9+7;

// BIT
// initialize : FenwickTree(n)
// add(pos, n): data[pos] += n;
// sum(l, r)  : sum [l, r)
template <typename T>
class FenwickTree {
  const int n;
  vector<T> data;
public:
  FenwickTree(int count) : n(count), data(count, 0) {;}

  void add(int pos, const T& value) {
    assert (0 <= pos && pos < n);
    for (int i = pos; i < n; i |= i + 1) data[i] += value;
  }

  T sum(int pos) const {
    assert (0 <= pos && pos <= n);
    T res = 0;
    for (int i = pos - 1; i >= 0; i = (i & (i + 1)) - 1) {
      res += data[i];
    }
    return res;
  }

  T sum(int l, int r) const {
    assert (0 <= l && l <= r && r <= n);
    return sum(r) + (-sum(l));
  }
  using value_type = T;
  using update_type = T;
};

int n,m,q;
vector<vector<ll>> cnt(500,vector<ll>(500,0));// cnt[i][j] := [i,j]の列車数
vector<FenwickTree<ll>> fts(500,FenwickTree<ll>(510));
vector<vector<ll>> res(500,vector<ll>(500,0));

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

    cin>>n>>m>>q;
    for(int i=0;i<m;i++){
        int l,r;cin>>l>>r;l--;r--;
        cnt[l][r]++;
    }
    for(int i=0;i<n;i++)for(int j=i;j<n;j++) {
        if(cnt[i][j]==0) continue;
        for(int st=0;st<=i;st++){
            fts[st].add(j,cnt[i][j]);
        }
    }
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            res[i][j]=fts[i].sum(i,j+1);
        }
    }
    for(int i=0;i<q;i++){
        int st,gt;cin>>st>>gt;st--;gt--;
        cout<<res[st][gt]<<endl;
    }
}


Measured memory_bytes: 6912