akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leading zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
string text="abcdefghijklmnopqrstuvwxyz";
const int maxn=1e6+7;
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    multiset<int>s;
    int a[n+2];
    for(int i=0;i<n;i++){
        cin>>a[i];
        s.insert(a[i]);
    }
    for(int i=0;i<n;i++){
        int x=a[i];
        s.erase(s.find(x));
        cout<<*s.rbegin()<<endl;
        s.insert(x);
    }
}


Measured memory_bytes: 13768
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
Apparently, the tree supports the same operations as the set 
(at least I haven't any problems with them before), but also there are two new features — 
find_by_order() — The first returns an iterator to the k-th largest element (counting from zero)
order_of_key() — the number of items in a set that are strictly smaller than our item. 
https://codeforces.com/blog/entry/11080
using namespace __gnu_pbds; */
using namespace std;
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ld long double
#define endl '\n'
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    int res = 1;
    while(b > 0){
        if(b&1) res = m(m(res)*m(a));
        a = m(m(a)*m(a));
        b >>= 1;
    }
    return res;
}
int inv(int n){
    return p(n, MOD-2);
}
vector<int> fact;
vector<int> invFact;
int nCr(int n, int r){
    // if(r == 0)  return 1;
    return m(m(m(fact[n])*m(invFact[r]))*m(invFact[n-r]));
}
signed main(){
    fast();
    string s;
    int k;
    cin >> k;
    cin >> s;
    int n = k+s.length();
    fact.resize(n+1);
    invFact.resize(n+1);
    fact[0] = 1;
    invFact[0] = inv(fact[0]);
    for(int i=1; i<=n; i++){
        fact[i] = m(m(fact[i-1])*m(i));
        invFact[i] = inv(fact[i]);
    }
    int z = 26;
    int ans = p(z,n), f = 0;
    for(int i=0; i<s.length(); i++){
        f = m(m(nCr(n, i))*m(p(z-1, n-i)));
        ans = m(m(ans)-m(f));
    }
    // cout << f << endl;
    cout << ans << endl;
    cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
}

Measured memory_bytes: 35680
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()
#define ADD(a, b) a = (a + b) % MOD

// x^n
ll mod_pow(ll x, ll n) {
  if (n == 0) return 1;
  ll res = mod_pow(x * x % MOD, n / 2);
  if (n & 1) res = res * x % MOD;
  return res;
}

// x^{-1}
ll inv(ll x) { return mod_pow(x, MOD - 2); }

ll fact[200001];
ll fact_inv[200001];

void init_fact() {
  fact[0] = fact_inv[0] = 1;
  REP(i, 200000) {
    fact[i + 1] = fact[i] * (i + 1) % MOD;
    fact_inv[i + 1] = fact_inv[i] * inv(i + 1) % MOD;
  }
}

ll nCr(ll n, ll r) {
  if (n < r || n < 0 || r < 0) return 0;
  return fact[n] * fact_inv[r] % MOD * fact_inv[n - r] % MOD;
}

ll nPr(ll n, ll r) { return nCr(n, r) * fact[r] % MOD; }

int main() {
  init_fact();
  ll n, m, k;
  cin >> n >> m >> k;
  ll ans = 0;
  for (ll d = 1; d < n; ++d) {
    ADD(ans, d * (n - d) % MOD * m % MOD * m % MOD);
  }
  for (ll d = 1; d < m; ++d) {
    ADD(ans, d * (m - d) % MOD * n % MOD * n % MOD);
  }
  ans *= nCr(n * m - 2, k - 2);
  ans %= MOD;
  cout << ans << endl;
  return 0;
}

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

ll mypow(ll a,ll b){
	ll num=1;
	while(b>0){
		b--;
		num*=a;
	}
	return num;
}

int main(){
	ll n,p;cin>>n>>p;
	vector<ll> a(n);
	
	ll even=0,odd=0,ans;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		a[i]%=2;
		if(a[i]==1){odd++;}
		else{even++;}
	}

	if(even==n){
		if(p==0){ans=mypow(2,n);}
		else{ans=0;}
	}else{ans=mypow(2,n-1);}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int mod=(1e9)+7;
const int maxn=3010;
int n,dp[maxn][maxn],s[maxn][maxn],tmp,ans;
char S[maxn];
void update(int &x,int y) {
	x+=y; if (x>=mod) x-=mod;
}
int main() {
//	freopen("1.txt","r",stdin);
	read(n);
	scanf("%s",S+1);
	dp[1][1]=s[1][1]=1;
	int l,r;
	for (int i=2;i<=n;i++) {
		for (int j=1;j<=i;j++) {
			if (S[i-1]=='>') {
				//k>=j
				l=j; r=i-1;
			} else {
				//k<j
				l=1; r=j-1;
			}
			dp[i][j]=(s[i-1][r]+mod-s[i-1][l-1])%mod;
			s[i][j]=(s[i][j-1]+dp[i][j])%mod;
			continue;
			for (int k=1;k<i;k++) {
				tmp=k;
				if (k>=j) tmp++;
				if (S[i-1]=='>'&&tmp<j) continue;
				if (S[i-1]=='<'&&tmp>j) continue;
				update(dp[i][j],dp[i-1][k]);
			}
		}
	}
	for (int i=1;i<=n;i++) update(ans,dp[n][i]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 69632
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <string.h>
#include <stdlib.h>

using namespace std;
// vector push_back push front top empty pop make_pair long long insert begin end  
typedef long long ll;
typedef vector<int> vi;
typedef vector<pair <int,int> > vpi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define B begin()
#define RB rbegin()
#define E end()
#define RE rend()
#define Z size()
#define REP(i,a,b) for (int i = a; i < b; i++)
#define L length()
#define show(a) cerr << " *** " << a << endl;
#define show1(a) cerr << " /// " << a << endl;

const int mod = 998244353;

ll mbinp(ll a, ll b){a %= mod;if (b == 0)return 1;ll ans = mbinp(a, b/2);ll tmp = (ans * ans) % mod;if (b % 2)return ((tmp * a) % mod);return ((tmp) % mod);}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	map<int,ll> mp;
	cin >> n;
	REP(i,0,n)
	{
		int x;cin >> x;mp[x]++;
		if ((i == 0 && x != 0) || (i != 0 && x == 0))
		{
			cout << 0;
			return 0;
		}
	}
	ll out = 1;
	for (auto t : mp)
	{
		if (t.F > 0)
		out *= mbinp(mp[t.F -1],t.S);
		out %= mod;
	}
	cout << out;
}


Measured memory_bytes: 6528
#include<iostream>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
using namespace std;

struct node
{
    int next;
    int num;
};


node e[3011];
int edge[1011];
int taile;

int v[1011];
int dp[1011];


int n;


bool f[1011][5011];


void add(int xx,int yy)
{
    e[taile].num=yy;
    e[taile].next=edge[xx];
    edge[xx]=taile++;
}


bool dfs(int now)
{
    int i,j;
    vector<int>g[2];
    g[0].push_back(-1);
    g[1].push_back(-1);
    int tg=0;
    int ss=0;
    for(i=edge[now];i!=-1;i=e[i].next)
    {
        if(dfs(e[i].num)==0)return 0;
        
        tg++;
        g[0].push_back(v[e[i].num]);
        g[1].push_back(dp[e[i].num]);
        
        ss+=g[0][tg]+g[1][tg];
    }
    
    memset(f,0,sizeof(f[0])*(tg+1));
    f[0][0]=1;
    
    for(i=0;i<=tg-1;i++)
    {
        for(j=0;j<=v[now];j++)
        {
            if(f[i][j]==0)continue;
            
            if(j+g[0][i+1]<=v[now])
            {
                f[i+1][j+g[0][i+1]]=1;
            }
            if(j+g[1][i+1]<=v[now])
            {
                f[i+1][j+g[1][i+1]]=1;
            }
        }
    }
    
    /*
    for(i=1;i<=tg;i++)
    {
        for(j=0;j<=v[now];j++)
        {
            cout<<f[i][j]<<' ';
        }
        cout<<endl;
    }
    cout<<"fffffff"<<endl;
    */
    int uu=-1;
    for(i=v[now];i>=0;i--)
    {
        if(f[tg][i]==1)
        {
           uu=i;
           break;
        }
    }
    /*
    cout<<now<<" now   "<<ss<<" ss    "<<uu<<" uu"<<endl;
    for(i=1;i<=tg;i++)
    {
        cout<<g[0][i]<<' '<<g[1][i]<<endl;
    }
    cout<<"ggggg"<<endl;
    */
    
    if(uu==-1)
    {
        return 0;
    }
    //cout<<ss<<' '<<uu<<endl;
    dp[now]=ss-uu;
    //cout<<now<<' '<<dp[now]<<"  !!!"<<endl;
    return 1;
}


int main()
{
    int i,j,k;
    int yy;
    cin>>n;
    
    taile=1;
    memset(edge,-1,sizeof(edge));
    for(i=2;i<=n;i++)
    {
        cin>>yy;
        add(yy,i);
    }
    
    for(i=1;i<=n;i++)
    {
        cin>>v[i];
    }
    
    if(dfs(1)==0)
    {
        cout<<"IMPOSSIBLE"<<endl;
    }
    else
    {
        cout<<"POSSIBLE"<<endl;
    }
    /*
    for(i=1;i<=n;i++)
    {
        cout<<dp[i]<<' ';
    }
    cout<<"dp"<<endl;
    */
    
    return 0;
}


Measured memory_bytes: 5120
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        if (n.indexOf('7') >= 0) {
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35680
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
string d[N];
int n;
char ans[N];
void dfs(int i,int a,int b,int c){
  if(i>n && a>=0 &&b>=0&&c>=0){
    cout<<"Yes\n";
    for(int i=1;i<=n;i++)cout<<ans[i]<<'\n';
    exit(0);
  }
  if(d[i]=="AB"){
    if(b>=1){
      ans[i]='A';
      dfs(i+1,a+1,b-1,c);
    }
    if(a>=1){
      ans[i]='B';
      dfs(i+1,a-1,b+1,c);
    }
  }else if(d[i]=="AC"){
    if(c>=1){
      ans[i]='A';
      dfs(i+1,a+1,b,c-1);
    }
    if(a>=1){
      ans[i]='C';
      dfs(i+1,a-1,b,c+1);
    }
  }else{
    if(c>=1){
      ans[i]='B';
      dfs(i+1,a,b+1,c-1);
    }
    if(b>=1){
      ans[i]='C';
      dfs(i+1,a,b-1,c+1);
    }
  }
}
int a,b,c;

int main() {
  ios::sync_with_stdio(false);
  cin>>n>>a>>b>>c;
  for(int i=1;i<=n;i++){
    cin>>d[i];
  }
  dfs(1,a,b,c);
  cout<<"No\n";
  return 0;
}

Measured memory_bytes: 17748
#include <iostream>
#include <vector>
#include <algorithm>
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());
  A.push_back(-1);
  int count = 0, ans = 0;
  for (int i = 0; i < N; i++) {
    count++;
    if (A[i + 1] != A[i] && count % 2 == 1) {
      ans++;
      count = 0;
    } else if (A[i + 1] != A[i]) count = 0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

struct Dice {
  int top;
  int bottom;
  int front;
  int back;
  int left;
  int right;
  Dice() : top(1), bottom(6), front(2), back(5), left(4), right(3) {}
  Dice(const Dice& d) : top(d.top), bottom(d.bottom), front(d.front), back(d.back), left(d.left), right(d.right) {}
  Dice(istream& is) {
    is >> top;
    is >> front;
    is >> right;
    is >> left;
    is >> back;
    is >> bottom;
  }
  bool operator==(const Dice& d) const {
    Dice tmp(d);
    tmp.Fit(top, front);
    return (top    == tmp.top) &&
           (bottom == tmp.bottom) &&
           (front  == tmp.front) &&
           (back   == tmp.back) &&
           (left   == tmp.left) &&
           (right  == tmp.right);
  }
  void E() {
    int tmp = right;
    right = top; top = left; left = bottom; bottom = tmp;
  }
  void N() {
    int tmp = back;
    back = top; top = front; front = bottom; bottom = tmp;
  }
  void S() {
    int tmp = front;
    front = top; top = back; back = bottom; bottom = tmp;
  }
  void W() {
    int tmp = left;
    left = top; top = right; right = bottom; bottom = tmp;
  }
  void Fit(int t, int f) {
    for (int i = 0; i < 2; ++i) {
      for (int j = 0; j < 4; ++j) {
        if (f == front) break;
        N();
      }
      E();
    }
    if (f == front) {
      for (int i = 0; i < 4; ++i) {
        if (t == top) break;
        E();
      }
    }
  }
};

int main() {
  Dice d1(cin);
  Dice d2(cin);

  cout << ((d1 == d2) ? "Yes" : "No") << endl;
  return 0;
}



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

using namespace std;

const int maxn = 1e5 + 500;
int a[maxn], dp[maxn];

int main(){
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        int b;
        cin >> b;
        a[b] ++;
    }
    dp[0] = a[0] + a[1];
    dp[n - 1] = a[n - 1] + a[n - 2];
    for (int i = 1; i < maxn; i++){
        dp[i] = a[i] + a[i + 1] + a[i - 1];
    }
    int k = 0;
    for (int i = 0; i < maxn; i++)
        k = max(k, dp[i]);
    cout << k << endl;
}



Measured memory_bytes: 1024
#include<iostream>
#include<vector>
using namespace std;
int main(){
 	int n,c=0;
    cin>>n;
   vector<int> v(n);
   for(auto &i: v)
     cin>>i;
   for(int i=0;i<n;i+=2)
		if(v[i]%2!=0)
          c++;
   cout<<c<<endl;
}

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

int main(){
    int A,B; cin >> A >>B;
    string C; cin >> C;
    bool ans=true;
    
    rep(i,A){
        if (!('0'<=C[i] && C[i] <= '9')){
            cout << "No";
            return 0;
        }
    }
    if(C[A]!='-'){
        cout << "No";
        return 0;
    }
    for (int i=A+1; i<A+1+B; i++){
        if(!('0'<=C[i] && C[i] <= '9')){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#define N 200020
using namespace std;

vector<int> e[N];
int d[N], o[N];

void BFS(int s)
{
    int i;
    queue<int> q;

    fill(d, d + N, N);
    d[s] = 0;
    for(q.push(s); !q.empty(); q.pop())
    {
        s = q.front();
        for(i = 0; i < (signed)e[s].size(); i ++)
            if(d[e[s][i]] > d[s] + 1)
            {
                d[e[s][i]] = d[s] + 1;
                o[e[s][i]] = s;
                q.push(e[s][i]);
            }
    }

    return;
}

int main(void)
{
    int n, m, u, v;
    int i;

    scanf("%d %d", &n, &m);
    while(m --)
    {
        scanf("%d %d", &u, &v);
        e[u].push_back(v);
        e[v].push_back(u);
    }
    BFS(1);

    for(i = 1; i <= n; i ++)
        if(d[i] == N)
        {
            printf("No\n");

            return 0;
        }
    printf("Yes\n");
    for(i = 2; i <= n; i ++)
        printf("%d\n", o[i]);

    return 0;
}


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

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 100111, inf = 1000111222, mod = 1000000007;

ll dp[max_n];
bool br[max_n];
int n, bc;


int main()
{
    //freopen("input.txt", "r", stdin);
    cin >> n >> bc;
    for (int i = 0; i < bc; ++i) {
        int a;
        cin >> a;
        br[a] = 1;
    }
    dp[0] = 1;
    for (int i = 1; i <= n; ++i) {
        if (br[i]) continue;
        if (!br[i - 1]) {
            dp[i] += dp[i - 1];
        }
        if (i - 2 >= 0 && !br[i - 2]) {
            dp[i] += dp[i - 2];
        }
        dp[i] %= mod;
    }
    cout << dp[n];

    return 0;
}




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

int main(){

  string tmp[256];
  bool lock;
  string in;
  int n,m;
  
  cin >> n;

  for(int i=0; i<n; i++){
    cin >> tmp[i];
  }
  lock = true;

  
  cin >> m;
  for(int i=0; i<m; i++){
    cin >> in;
    int j;
    for(j=0; j<n; j++){
      if(tmp[j] == in){
	if(lock == true){
	  lock = false;
	  cout << "Opened by " << in << endl;
	}
	else{
	  lock = true;
	  cout << "Closed by " << in << endl;
	}
	
	break;
      }
    }
    if(j==n){ cout << "Unknown " << in << endl; }

  }

  return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  bool flag = false;
  for (int i = 0; i <= s.size() - 2; i++) {
    if (s.substr(i, 2) == "AC") flag = true;
  }
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main(){
    double l;
    cin >> l;
    double maxvol = 0;
    for(double i = l/3 - 0.001; i < l/3 + 0.001; i += 0.000001){
        for(double j = l/3 - 0.001; j < l/3 + 0.001; j += 0.000001){
            double k = l - (i + j);
            double vol =  i * j * k;
            if(maxvol < vol){
                maxvol = vol;
            }
            
        }
    }
    cout << fixed << setprecision(10) << maxvol << endl;
    return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}

import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.ByteString.Char8 as C
import Data.List
import Control.Monad
import Control.Arrow
--import Data.Foldable
--import Data.Char
import qualified Data.IntMap.Strict as IM
--import qualified Data.IntSet as IS
-- import Data.Sequence as Sq

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine




main = do
    [n,k] <- map fromIntegral <$> r' :: IO [Integer]

    as <- U.map fromIntegral <$> r (fromIntegral n)
    reach <- V.thaw $ V.replicate (fromIntegral n) (-1)

    (posS,hdS,repS) <- count as reach 0 1
    -- print (posS,hdS,repS)
    let rm =  (k - hdS) `mod` repS   :: Integer
    -- print rm 
    print $ if k <= hdS then trace as 1 k else trace as posS rm 

count :: U.Vector Int -> VM.IOVector Integer -> Integer -> Int -> IO (Int,Integer,Integer)
count as reach ac pos = do
    h <- VM.read reach (pos-1)
    if h == -1
        then do 
            VM.write reach (pos-1) ac
            count as reach (ac+1) (as U.! (pos-1))
        else return (pos,h,ac-h)

trace :: U.Vector Int -> Int -> Integer -> Int
trace as pos 0 = pos
trace as pos n = trace as (as U.! (pos-1)) (n-1)






Measured memory_bytes: 22164
n,k =map(int,input().split())

syou = n//k

zet = abs(n-k*syou)
if zet == 0:
  print(zet)
else:
  zet1 = abs(n-k*(syou+1))
  if zet > zet1:
    print(zet1)
  else: 
    print(zet)

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <utility>

using namespace std;
using pii = pair<int,int>;
int n,used[700][700];
pii color[700][700];
vector<pii> v;
int dx[4] = {1,1,-1,-1};
int dy[4] = {1,-1,-1,1};

void dfs1(int s,int t, int c,int x){
    used[s][t] = 1;
    if(x==1) color[s][t].first = c;
    if(x==2) color[s][t].second = c;
    for(auto&& p :v){
    	for(int i=0;i<4;i++){
    		int nx = s + dx[i]*p.first, ny = t + dy[i]*p.second;
        	if(nx<0 || nx>=2*n || ny<0 || ny>=2*n || used[nx][ny]!=-1) continue;
        	dfs1(nx,ny,3-c,x);
    	}
    }
}

void dfs2(int d,int x){
    for(int i = 0;i*i<=d;i++){
        int k = d - i*i;
        for(int j = 0;j*j<=k;j++){
            if(j*j==k){
                v.push_back({i,j});
                if(i!=j) v.push_back({j,i});
            }
        }
    }
    for(int i=0;i<2*n;i++){
        for(int j=0;j<2*n;j++){
            used[i][j] = -1;
        }
    }
    for(int i=0;i<2*n;i++){
        for(int j=0;j<2*n;j++){
            if(used[i][j]==-1) dfs1(i,j,1,x);
        }
    }
	v.clear();
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
    int i,j,d,e;
    cin >> n >> d >> e;
    dfs2(d,1); dfs2(e,2);
    vector<pii> sum[4];
    for(i=0;i<2*n;i++){
        for(j=0;j<2*n;j++){
            int x = color[i][j].first,y = color[i][j].second;
        	int z =  max(y*y-x,x-y*y);
        	sum[z].push_back({i,j});
        }
    }
	for(i=0;i<4;i++){
		if(sum[i].size()>=n*n){
			for(j=0;j<n*n;j++){
				cout << sum[i][j].first << " " << sum[i][j].second << endl;
			}
			return 0;
		}
	}
}


Measured memory_bytes: 38904
#include<bits/stdc++.h>
using namespace std;
int n;
long long ans;
char c[20];
string s[100010];
int main(){
	cin>>n;
	for(int i=0;i<n;i++){ 
		for(int j=0;j<10;j++)
			cin>>c[j];
		sort(c,c+10);
		for(int j=0;j<10;j++)
			s[i]=s[i]+c[j];
	}
	sort(s,s+n);
//	for(int i=0;i<n;i++)
//		cout<<s[i]<<endl;
	for(int i=0;i<n;i++)
		ans=ans+max(0,(int)(upper_bound(s,s+n,s[i])-lower_bound(s,s+n,s[i])-1));
	cout<<ans/2;
	return 0;
}

Measured memory_bytes: 7680
# -*- coding: utf-8 -*-

n = input()
p = list(map(int, input().split()))

counter = 0
for i in range(1, int(n) - 1):
    numbers = [p[i-1], p[i], p[i+1]]
    if sorted(numbers)[1] == p[i]:
        counter += 1

print(counter)

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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Yes or No
void yesno(bool ok, string yes = "Yes", string no = "No") {
  cout << (ok ? yes : no) << endl;
}

// Paste snippets here!!

//

void solve(long long N, std::vector<long long> A) {
  rep(i,N){
    A[i] -= i+1;
  }
  sort(all(A));
  ll ret = 0LL;
  rep(i,N) ret += abs(A[i] - A[N/2]);
  cout << ret << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  cout.precision(12);
  long long N;
  std::cin >> N;
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    std::cin >> A[i];
  }
  solve(N, std::move(A));
  return 0;
}


Measured memory_bytes: 4716
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int MOD = 1000000007;

inline ll comb2(int a) { return (a >= 2) ? (ll)a * ((ll)a - 1) / 2 : 0LL; }

map<string, int> m;
int n;

void init()
{
	cin >> n;

	REP(_i, n)
	{
		string s; cin >> s;
		sort(ALL(s));
		m[s]++;
	}
}


int main()
{
	init();

	ll ans = 0;
	for (auto it = m.begin(); it != m.end(); ++it)
		ans += comb2(it->second);
	cout << ans << endl;
}


Measured memory_bytes: 11136
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    int a, b;
    int i;

    a = b = 0;
    for (i = 0; i < 8; i++){
        scanf("%d", &n);

        if (i < 4){
            a += n;
        }
        else {
            b += n;
        }
    }
    printf("%d\n", max(a, b));

    return (0);
}

Measured memory_bytes: 1020
function warshall(){
   for(var k=0;k<n;k++){
      for(var i=0;i<n;i++){
         for(var j=0;j<n;j++){
            C[i][j]=Math.min(C[i][j], C[i][k]+C[k][j]);
         }
      }
   }
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var n=Arr.shift()-0;
var m=Arr.shift()-0;
var C=[];
for(var i=0;i<n;i++){
   C[i]=[];
   for(var j=0;j<n;j++){
      C[i][j]=(i===j)?0:Infinity;
   }
}
for(var i=0;i<m;i++){
   var A=(Arr.shift()).split(",").map(Number);
   C[A[0]-1][A[1]-1]=A[2];
   C[A[1]-1][A[0]-1]=A[3];
}
warshall();
var last=(Arr.shift()).split(",").map(Number);
var cost=C[last[0]-1][last[1]-1]+C[last[1]-1][last[0]-1]+last[3];
console.log(last[2]-cost);

Measured memory_bytes: 7644
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int main()
{
  long long  a, b, c, d, X, Y;
  int D, G;
  //char s[101][101]={};
  char sv[101]={};
  char ss[101]={};
//  char s_temp[101]={};
  char t[101]={};
//  char s[10000000000000000001]={};
  char s[2][100001]={};
  int len=0;
  int N, M;
//  int A[1000000001]={};
  long long  A[101]={};
//  long int A[1001]={};
  long long  B[101]={};
  long long  C[101]={};
  int i,j,k;
  int flag=0;
  int tmp=0;
  int min=0;
  int cnt=0;
  int ans=0;
  int max=0;

  int  Cen_X=0;
  int  Cen_Y=0;
  long long  H=0;
  
  //  int ans=0;
  int str_len=0;
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  int ans_o[100001]={};
  int ans_e[100001]={};
  
  scanf("%lld %lld", &a, &b);
  tmp=b/a;
  for(i=tmp;i>0;i--){
    if((b%i)==0){
      if((i*a)<=b){
        printf("%d\n",i);
        return 0;
      }
    }
  }
    
      
//  if(flag==0)   printf("TLE\n");
//  printf("%d\n",ans);
  
return 0;
}


Measured memory_bytes: 128
from collections import deque
import sys

n=int(input())
ali = list(map(int,input().split()))

ali.sort(reverse=True)

comforts = deque([ali[1], ali[1]])
answer = ali[0]
if len(ali) < 3:
    print(answer)
    sys.exit()

for i in ali[2:]:
    answer += comforts.pop()
    comforts.appendleft(i)
    comforts.appendleft(i)

print(answer)

Measured memory_bytes: 33156
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

ll n, m;
vector<pair<ll, ll>> ab;

void input(){
    cin >> n >> m;
    ab.resize(m);
    for(ll i=0;i<m;i++){
        ll x, y;
        cin >> x >> y;
        ab[i] = make_pair(x, -y);
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    sort(ab.begin(), ab.end());
    ll ans = 1;
    ll l = ab[0].first;
    ll r = -ab[0].second;
    for(ll i=1;i<m;i++){
        l = max(l, ab[i].first);
        r = min(r, -ab[i].second);
        // cout << l << " " << r << endl;
        if(l - r >= 0){
            ans++;
            l = ab[i].first;
            r = -ab[i].second;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
main = do
  [a,b] <- map read . words <$> getLine
  let v = [x | x <- [1,a..1000], x < b]
  print (len v)

len :: [Int] -> Int
len x
  | x == [] = 0
  | tail x == [] = 1
  | otherwise = 1 + len (tail x)


Measured memory_bytes: 508
#include <stdio.h>
#include <limits.h>

int main(void) {
	int num, i, k;
	int M[100][100];
	int g[100], h[100], gn;
	int weight, minimum, index, a;

	scanf("%d", &num);
	for (i = 0; i < num; i++) {
		g[i] = 1;
		h[i] = 0;
		for (k = 0; k < num; k++) {
			scanf("%d", &M[i][k]);
		}
	}

	h[0] = 1;
	g[0] = 0;
	gn = num - 1;
	weight = 0;

	while (gn--) {
		minimum = INT_MAX;

		for (k = 0; k < num; k++) {
			if (!h[k])
				continue;

			for (i = 0; i < num; i++) {
				if (!g[i])
					continue;

				a = M[k][i];
				if (0 <= a && a < minimum) {
					index = i;
					minimum = a;
				}
			}
		}
		h[index] = 1;
		g[index] = 0;
		weight += minimum;
	}
	printf("%d\n", weight);
	return 0;
}



Measured memory_bytes: 2112
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("No"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  df(n); df(x);
  if (x == 1 || x == n*2-1) dame;
  puts("Yes");
  vi ans(n*2-1);
  rep(i,sz(ans)) ans[i] = i+1;
  swap(ans[x-1], ans[n-1]);
  swap(ans[0], ans[n-2]);
  swap(ans.back(), ans[n]);
  rep(i,n*2-1) {
    printf("%d\n",ans[i]);
  }
  return 0;
}







Measured memory_bytes: 2304
//This code is written by Anubhav Srivastava(anubhavsrivastavawebpage.wordpress.com)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c;
    cin >> a>>b>>c;
    cout << c <<" "<< a <<  " " <<b;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;


int main() {
	int A, B, C, D, E, F;
	cin >> A >> B >> C >> D >> E >> F;

	int X = min(A,B);
	int XX = min(C, D);
	int XXX = min(X, XX);

	int XXXX = max(E, F);

	cout << (A + B + C + D) - XXX + XXXX << endl;

	return 0;
}


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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 1005;

intt f (int n) {
	return 1LL * n * n * n * n * n;
}

int main() {

	FAST;

	int x;
	cin >> x;

	// it is enough to check till 120 - as 120 ^ 5 - 119 ^ 5 = 1,019,663,401
	// and it is bigger than 1e9

	for (int i = 120; i >= -120; i --) {
		for (int j = 120; j >= -120; j --) {
			if (f(i) - f(j) == x) {
				cout << i << ' ' << j << '\n';
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3604
from collections import Counter
N, M = map(int, input().split())
mod = 10 **9 + 7


def prime_factorization(n):
    table = []
    for x in range(2, int(n**0.5)+2):
        while n % x == 0:
            table.append(x)
            n //= x
    if n > 1:
        table.append(n)
    return table


def nHk(n, k):
    value = 1
    nk = n + k - 1
    k = min(nk-k, k)
    for i in range(k):
        value = (value * nk) % mod
        nk -= 1
    for x in range(1, k + 1):
        value = (value * pow(x, mod-2, mod)) % mod

    return value


C = Counter(prime_factorization(M))
ans = 1
for v in C.values():
    ans = ans * nHk(N, v) % mod

print(ans)


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int h, w; cin >> h >> w;
	vector<string> s(h);
	vector<int> cnt(26, 0);
	for (int i = 0; i < h; i++) {
		cin >> s[i];
		for (int j = 0; j < w; j++) {
			cnt[s[i][j] - 'a']++;
		}
	}
	if (h & 1) swap(h, w);
	int oc = 0, fc = 0;
	for (int i = 0; i < 26; i++) {
		if (cnt[i] & 1) oc++;
		fc += (cnt[i] >> 2);
	}
	bool ok = false;
	if (h & 1) {
		if (oc == 1) ok = true;
	} else {
		if (w & 1) {
			if (oc == 0) ok = true;
		} else {
			ok = true;
			for (int i = 0; i < 26; i++) if (cnt[i] & 3) ok = false;
		}
	}
	if (fc < (h >> 1) * (w >> 1)) ok = false;
	if (ok) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 3644
# abc177_b.py
S = input()
T = input()

ans = 0
length = len(T)
slen= len(S)
mincnt = 10000
for i in range(slen-length+1):
    tmp = S[i:i+length]
    cnt = 0
    for i in range(length):
        if tmp[i]!=T[i]:
            cnt+=1
    if cnt < mincnt:
        mincnt=cnt
print(mincnt)

Measured memory_bytes: 8940
import collections

n=int(input())
vlist=list(map(int,input().split()))

vlist1=[vlist[2*i] for i in range(n//2)]
vlist2=[vlist[2*i+1] for i in range(n//2)]
#print(vlist1)
#print(vlist2)

vc1=collections.Counter(vlist1).most_common()
vc2=collections.Counter(vlist2).most_common()
#print(vc1)
#print(vc2)

if vc1[0][0]!=vc2[0][0]:
    print(n-vc1[0][1]-vc2[0][1])
elif len(vc1)==1 and len(vc2)==1:
    print(n//2)
elif len(vc1)==1:
    print(n//2-vc2[1][1])
elif len(vc2)==1:
    print(n//2-vc1[1][1])
else:
    if vc1[0][1]>vc2[0][1]:
        print(n-vc1[0][1]-vc2[1][1])
    elif vc1[0][1]<vc2[0][1]:
        print(n-vc1[1][1]-vc2[0][1])
    else:
        max_2nd=max(vc1[1][1],vc2[1][1])
        print(n-vc1[0][1]-max_2nd)

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

int main() {
  int A, B, C, D;
  cin>>A>>B>>C>>D;
  long long mod = 998244353;
  long long dp[C+1][D+1];
  for (int i=0; i<C+1; i++) {
    for (int j=0; j<D+1; j++) {
      dp[i][j] = 0;
    }
  }
  dp[A][B] = 1;
  for (int i=A+1; i<C+1; i++) {
    dp[i][B] = dp[i-1][B] * B;
    dp[i][B] %= mod;
  }
  for (int i=B+1; i<D+1; i++) {
    dp[A][i] = dp[A][i-1] * A;
    dp[A][i] %= mod;
  }
  for (int i=A+1; i<C+1; i++) {
    for (int j=B+1; j<D+1; j++) {
      dp[i][j] = dp[i-1][j] * j + dp[i][j-1] * i;
      dp[i][j] -= dp[i-1][j-1] * (i - 1) * (j - 1);
      if (dp[i][j] < 0) {
        long long tmp = (abs(dp[i][j]) - 1) / mod + 1;
        dp[i][j] += tmp * mod;
      }
      dp[i][j] %= mod;
    }
  }
  // for (int i=0; i<C+1; i++) {
  //   for (int j=0; j<D+1; j++) {
  //     printf("%2d ", dp[i][j]);
  //   }
  //   cout<<endl;
  // }
  cout<<dp[C][D]<<endl;
}

Measured memory_bytes: 73948
s = input()
a = []
b = []
n = 0

if len(s) % 2 == 1:
    for i in range((len(s) // 2) + 1):
        a.append(s[2 * i])
else:
    for i in range(len(s) // 2):
        a.append(s[2 * i])
    
for i in range(len(s) // 2):
    b.append(s[2 * i + 1])
    
for i in range(len(a)):
    if a[i] == "L":
        n += 1
        
for i in range(len(b)):
    if b[i] == "R":
        n += 1
        
if n > 0:
    print("No")
else:
    print("Yes")

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

int top,X[1000];

void push(int);
int pop(void);
int main(){
  int a,b;
  top=0;
  char s[100];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      a=pop();
      b=pop();
      push(a+b);

    } else if ( s[0] == '-' ){
      b=pop();
      a=pop();
      push(a-b);

    } else if ( s[0] == '*' ){
      a=pop();
      b=pop();
      push(a*b);

    } else {
      push(atoi(s));

    }
  }
  printf("%d\n",pop());

  return 0;
}
void push(int x){
  X[++top]=x;
}
int pop(void){
top--;
  return X[top+1];
}



Measured memory_bytes: 2104
class SegmentTree:
    def __init__(self, n, op, e):
        self.n = 1 << (n - 1).bit_length()
        self.op = op
        self.e = e
        self.data = [e] * (2 * self.n)

    def update(self, k, v):
        k += self.n
        self.data[k] = v
        while k > 0:
            k >>= 1
            self.data[k] = self.op(self.data[2 * k], self.data[2 * k + 1])

    def query(self, left, right):
        left += self.n
        right += self.n
        l_res = self.e
        r_res = self.e
        while left < right:
            if left & 1:
                l_res = self.op(l_res, self.data[left])
                left += 1
            left >>= 1
            if right & 1:
                right -= 1
                r_res = self.op(self.data[right], r_res)
            right >>= 1
        return self.op(l_res, r_res)


N, K, *A = map(int, open(0).read().split())
t = SegmentTree(650_000, max, 0)
ans = 0
for a in A:
    t.update(a, 1 + t.query(max(0, a - K), min(a + K, 300_000) + 1))
print(t.query(0, 300_001))


Measured memory_bytes: 161536
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
 
inline int read()
{
    int X=0; bool flag=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
    while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
    if(flag) return X;
    return ~(X-1);
}
 
int n,m;
int p[N];
bool st[N];

int find(int x){
	if(p[x]!=x) p[x]=find(p[x]);
	return p[x];
}

int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;++i) p[i]=i;

    for(int i=1;i<=m;++i){
    	int u,v;
    	cin>>u>>v;
    	int fu=find(u);
    	int fv=find(v);
    	p[fu]=fv;
    }
    int cnt=0;
    for(int i=1;i<=n;++i){
    	int fa=find(i);
    	if(!st[fa]){
    		st[fa]=true;
    		cnt++;
    	}
    }
    cout<<cnt-1<<endl;



    return 0;
}

Measured memory_bytes: 4108
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int n; cin >> n;
    vector<ll> a(n), b(n);
    rep(i, n){
        cin >> a.at(i) >> b.at(i);
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    if(n%2==0){
        ll mi = a.at(n/2-1) + a.at(n/2);
        ll ma = b.at(n/2-1) + b.at(n/2);
        cout << ma - mi + 1 << endl;
    }
    else{
        ll mi = a.at(n/2);
        ll ma = b.at(n/2);
        cout << ma - mi + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 6368
import fractions
N,X=map(int,input().split())
x=list(map(int,input().split()))

x.append(X)
x.sort()
a=x[1]-x[0]
for i in range(1,len(x)-1):
    a=fractions.gcd(a,x[i+1]-x[i])
print(a)

Measured memory_bytes: 16244
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

const ll mod = 1000000007;
const ll INF = 100000010000;

ll kai[100010];
ll bit[700010];

void pres(double A, ll x = 20) { printf("%.20f\n", x); }

/*ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

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

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll y) {
	if (y == 0) return 1;
	if (y % 2 == 1) {
		return x * pow_mod(x, y - 1) % mod;
	}
	else {
		ll half = pow_mod(x, y / 2);
		return half * half % mod;
	}
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

ll com(ll x, ll y) {
	return kai[x] * div_mod(kai[y] * kai[x - y] % mod) % mod;
}

ll H, N, sum;
ll A[100010];

void solve() {
	cin >> H >> N;
	rep(i, N) {
		cin >> A[i];
		sum += A[i];
	}
	if (sum >= H) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

Measured memory_bytes: 1024
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>
using namespace::std;
int main(){
  int A;
  cin>>A;
  int az=0;
  int *N1=new int[A];
  int *N2=new int[A];
  for(int i=0;i<A;i++){
    cin>>N1[i];
    if(N1[i]!=0){
     az=1;
    }
    N2[i]=0;
  }
  
  int num;
  int stack=0;
  
  for(int i=0;i<A;i++){
    num=A-1-i;
    for(int i=2;i*(num+1)<=A;i++){
      stack=stack+N2[i*(num+1)-1];
    }
    stack=stack%2;
    N2[num]=(N1[num]^stack);
   // cout<<stack<<endl;
    stack=0;
  }

  int count=0;
  for(int i=0;i<A;i++){
    if(N2[i]==1){
      count++;
    }
  }

  if(!az){
    cout<<0;
  }else{
    cout<<count<<endl;
    for(int i;i<A;i++){
      if(N2[i]==1){
        cout<<i+1<<endl;
      }
    }
  }
}





Measured memory_bytes: 2432
s = input()
t = input()
n, m = len(s), len(t)
dp = [[0] * (m + 1) for _ in range(n + 1)]

for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = dp[i][j] + 1
        else:
            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])

lcs_str = ''
i, j = n, m
while i >= 1 and j >= 1:
    if s[i - 1] == t[j - 1]:
        lcs_str += s[i - 1]
        i -= 1
        j -= 1
    else:
        if dp[i - 1][j] > dp[i][j - 1]:
            i -= 1
        else:
            j -= 1

print(lcs_str[::-1])

Measured memory_bytes: 112220
//dp+tree
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const int mod = 1e9+7;
const int mx = 1e5+7;
void add_self(int& a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}
int mul(int a, int b){
  return (ll)a * b % mod;
}
vector<int> edges[mx];
pair<int,int> dfs(int a, int parent){
  int all_white = 1, some_black = 0;
  for(int i=0;i<edges[a].size();i++){
    if(edges[a][i]!=parent){
      pair<int,int> p = dfs(edges[a][i],a);
      int memo_white = all_white;
      all_white = mul(all_white,p.second);
      some_black =  (mul(memo_white,p.first)+mul(some_black,p.first+p.second))%mod;
    }
  }
  return make_pair(all_white, (all_white+some_black)%mod);
}
int main(){
  int n;
  scanf("%d", &n);
  for(int i=0;i<n-1;++i){
    int a,b;
    scanf("%d%d", &a,&b);
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  pair<int,int> p = dfs(1,-1);
  int ans = (p.first+p.second)%mod;
  printf("%d", ans);
}


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

typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)

bool is_exist(vector<vint> &G,int v,int nv){
  for (auto k :G[v]){
    if (k==nv) return true;
  }
  return false;
}

int main() {
  int n,m;
  int a,b;
  cin >> n >> m;
  vector<vint> graph(n);
  int arry[n];
  rep(h,n){
    arry[h]=h;
  }
  rep(i,m){
    cin >> a >> b;
    graph.at(a-1).push_back(b-1);
    graph.at(b-1).push_back(a-1);
  }
  int cnt=0;
  do{
     for(int i=0; i < n ;i++){
      if (i==n-1){
        cnt++;
        break;
      }
      if (!is_exist(graph,arry[i],arry[i+1])) break;
     }
  }while(next_permutation(arry+1,arry+n));
          
  cout << cnt << endl;
    
      
  return 0;
}

Measured memory_bytes: 256
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

#define MAXN (1 << 12)

int n, t;
vector<pair<int, int> > v;
int mem[MAXN][MAXN];

int solve(int k, int pos) {
	if ((k >= t) || (pos >= n)) {
		return 0;
	}
	int & ret = mem[k][pos];
	if (ret >= 0) {
		return ret;
	}
	int cur1 = v[pos].second + solve(k + v[pos].first, pos + 1);
	int cur2 = solve(k, pos + 1);
	ret = max(cur1, cur2);
	return ret;
}

int main() {
	memset(mem, -1, sizeof(mem));
	cin >> n >> t;
	for (int i = 0; i < n; i++) {
		int t1, t2;
		cin >> t1 >> t2;
		v.push_back(make_pair(t1, t2));
	}
	sort(v.begin(), v.end());
	cout << solve(0, 0) << endl;
	return 0;
}


Measured memory_bytes: 69284
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner scanner = new Scanner(System.in);
    int numberOfString = scanner.nextInt();
    String strings1 = scanner.next();
    String strings2 = scanner.next();
    for (int i = 0; i < numberOfString; i++) {
      System.out.print(strings1.substring(i, i + 1) + strings2.substring(i, i + 1));
    }
  }

}


Measured memory_bytes: 21844