akhauriyash/Code-Regression huggingface dataset:
a, b = map(int, input().split())
def ruiseki_xor(n):
    res = []
    x = 2
    while n*2 >= x:
        #print(n//x, x//2)
        res.append((n//x * x//2 + max(0, n%x - (x//2-1)))%2)
        x *= 2
    res.reverse()
    if n <= 0:
        return "0"
    return "".join(map(str, res))



print(int(ruiseki_xor(a-1), 2)^int(ruiseki_xor(b), 2))


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

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  REP(i,n) cin >> x[i];
  
  int ans = 10000000;

  REP(i,100){
    int y = 0;
    REP(j,n){
      y += (x[j] - i) * (x[j] - i);
    }
    ans = min(ans,y);
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define int long long

using namespace std;

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

    int r, d, x;
    cin >> r >> d >> x;
    for (int i = 0; i < 10; i++)
        x = r * x - d, cout << x << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int ans = 1;
  cin >> N;
  int d[N];
  for(int i = 0; i < N; i++){
    cin >> d[i];
  }
  sort(d,d+N,greater<int>());
  for(int j = 1;j < N; j++){
    if(d[j] != d[j - 1]){
      ans += 1;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a;
vector<pair<int,int> >V;
int ans[234567];
int fix(int k){
	if(k<=(n/2))return V[n/2+1].first;
	else return V[n/2].first;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	V.push_back({-1,-1});
	for(int i=1;i<=n;i++){
		cin>>a;
		V.push_back({a,i});
	}
	sort(V.begin(),V.end());
	for(int i=1;i<=n;i++){
		ans[V[i].second]=fix(i);
	}
	for(int i=1;i<=n;i++)cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 4720
#include<iostream>
#include<algorithm>
using namespace std;
int D=365;
int K=26;
int main()
{
  int d,cc=0,m=0,i,j,r,rj,res=0;
  int c[K],s[D][K],t[D],l[K];
  cin >> d;
  for(i=0;i<K;i++){
    cin >> c[i];
    cc+=c[i];
  }
  for(i=0;i<d;i++)
    for(j=0;j<K;j++)
      cin >> s[i][j];
  for(i=0;i<d;i++){
    cin >> t[i];
    t[i]--;
  }
  fill(l,l+K,-1);
  for(i=0;i<d;i++){
    r=0;
    rj=-1;
    for(j=0;j<K;j++)
      if(s[i][j]+c[j]*(i-l[j])>r){
        r=s[i][j]+c[j]*(i-l[j]);
        rj=j;
      }
    m+=cc-c[rj]*(i-l[rj]);
    t[i]=rj;
    l[rj]=i;
    res+=s[i][rj]-m;
    cout << rj+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{
    flash;
    //sieve();
    ll T=1,t,n,m,q,k,i,j;
    // cin>>T;
    while(T--)
    {
        cin>>n>>k;
        ll a[n];
        FOR(i,0,n)  cin>>a[i];
        FOR(i,k,n)
        {
            if(a[i]>a[i-k])
                cout<<"Yes\n";
            else
                cout<<"No\n";
        }
    }
}

Measured memory_bytes: 5212
#include <bits/stdc++.h>
#include <iterator>
#include <vector>
#include <algorithm>
#include <iomanip>

#define v vector
#define ll long long 
#define vpll vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pci pair<char,int>
#define un unsigned

#define mod 1000000007
#define MAXN 3001
using namespace std; 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)



int main()
{
    fast;
    ll n,k;
    cin>>k>>n;
    ll ans = 0;
    ll max_val = 0;
    v<ll> a(n,0);
    for(ll i = 0 ; i < n ; i++)
    cin>>a[i];
    for(ll i = 1 ; i < n ; i++)
    {
        max_val = max(max_val,a[i]-a[i-1]);
    }
    max_val = max(max_val,k+a[0]-a[n-1]);
    ans = k-max_val;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
int main(){
	int n;
	scanf("%d",&n);
	long long int m=0;
	long long int a=0;
	long long int r=0;
	long long int c=0;
	long long int h=0;
	for(int i=0;i<n;i++){
		char s[20]={};
		scanf("%s",s);
		if(s[0]=='M')m++;
		if(s[0]=='A')a++;
		if(s[0]=='R')r++;
		if(s[0]=='C')c++;
		if(s[0]=='H')h++;
	}
	printf("%lld\n",m*a*(r+c+h)+m*r*(c+h)+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>

inline long long ceil(long long t,long long mod){
    return t % mod == 0 ? t / mod : t / mod + 1;
}
long long seq[10];
int main(){
    long long t,a,b,c,d,e;
    std::cin >> t;
    for(int i = 1; i <= 5; ++ i) std::cin >> seq[i];
    long long mn = 0x3f3f3f3f3f3f3f3f;
    for(int i = 1; i <= 5; ++ i){
        mn = mn > seq[i] ? seq[i] : mn;
    }
    std::cout << ceil(t,mn) + 4;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, count = 0; cin >> N;
  for(int X = 1; X <= N; X += 2) {
    int t = 0;
    for(int i = 1; i < sqrt(X); i++) {
      t += ((X % i == 0) ? 2 : 0);
    }
    if(t == 8) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
from itertools import *
from collections import *
n=int(input())
a=list(map(int,input().split()))
l=[0]+list(accumulate(a))
ans=0
li={}
for i in range(n+1):
    if l[i] in li:
        li[l[i]]+=1
    else:
        li[l[i]]=1
for b in li.values():
    if b>=2:
        ans+=b*(b-1)//2
print(ans)
    
    
    

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

const int N=100005;

int x[N],to[N],q[N];
bool use[N];

int main(){
	int n,m;long long k;
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&x[i]);
		to[i]=i;
	}
	for (int i=n;i;i--) x[i]-=x[i-1];
	scanf("%d%lld",&m,&k);
	for (int i=1;i<=m;i++){
		int a;
		scanf("%d",&a);
		std::swap(to[a],to[a+1]);
	}
	for (int i=1;i<=n;i++)
	if (!use[i]){
		int tot=0;
		use[q[tot++]=i]=1;
		for (int j=to[i];!use[j];j=to[j])
			use[q[tot++]=j]=1;
		for (int j=0;j<tot;j++)
			to[q[j]]=q[(j+k)%tot];
	}
	long long pos=0;
	for (int i=1;i<=n;i++) printf("%lld\n",pos+=x[to[i]]);
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define ll long long
#define lld long double
#define mod 1000000007
#define rep(i,n)    for(ll i=0;i<n;++i)
#define forup(i,a,b)    for(ll i=a;i<=b;++i)
#define all(v)    v.begin(),v.end()
#define inf 1000000010
#define pii pair<ll,ll>
#define vl vector<ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define MAXN 110
#define bsize 555
#define sz(v) v.size()
#define fast  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
ll power(ll x,ll y, ll md){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}

ll h,w;
char grid[1010][1010];
ll ans[1010][1010];

ll solve(ll i,ll j){
    if(i<0||j<0||grid[i][j]=='#')
        return 0;
    if(ans[i][j]!=-1)
        return ans[i][j];
    ans[i][j]=(solve(i-1,j)+solve(i,j-1))%mod;
    return ans[i][j];
}

int main(){
    cin>>h>>w;
    rep(i,h){
        rep(j,w)    cin>>grid[i][j];
    }
    memset(ans,-1,sizeof(ans));
    ans[0][0]=1;
    cout<<solve(h-1,w-1);
}

Measured memory_bytes: 9344
#include <bits/stdc++.h>
using namespace std;
int main() {
  	double a,b,x;
  	cin>>a>>b>>x;
  	bool comp = false;
  	if(a*a*b/2 < x) {
  		double r = atan((2*(a*a*b-x)/(a*a))/a);
  		r = r*180/(atan(1)*4);
  		printf("%.9f",r);
  		exit(0);
  	}
  	double res = atan(2*x/(a*b*b));
  	res = res*180/(atan(1)*4);
  	printf("%.9f",90-res);

}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np

N,K = map(int,input().split())

S = np.array(list(input()), dtype='U1')

x = np.count_nonzero(S[1:] == S[:-1])

x += 2*K
x = min(x, N-1)
print(x)

Measured memory_bytes: 21384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> A(N + 1, 0);
  REP(i, M) {
    int a;
    cin >> a;
    A[a] = 1;
  }
  ll to0 = 0;
  for (int i = X; i > 0; i--) to0 += A[i];
  ll toN1 = 0;
  for (int i = X; i<=N ; i++) toN1 += A[i];
  cout << min(to0, toN1) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  int N = s.size();
  int a = 0, b = 0;
  REP(i, N){
    if(s[i] == '1') a++;
    else b++;
  }

  cout << N-abs(a-b) << "\n";


  return 0;
}

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

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define setIO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)
#define trav(e, x) for (const auto &(e) : (x))
#define pb(x) push_back(x)
#define eb(x...) emplace_back(x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#define lc(i) 2*i
#define rc(i) 2*i+1
//#define int long long
using namespace std;
using ii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vii = vector<ii>;
using vivi = vector<vi>;

const int N = 1e5 + 5, MOD = 1e9 + 7, INF = 1e9 + 5;
vi g[N];
bool vis[N];

void dfs(int u) {
    vis[u] = true;
    trav(v, g[u]) if (!vis[v]) dfs(v);
}

signed main() {
    FAST_IO;
//    setIO("input.txt", "output.txt");

    int n, m;
    cin >> n >> m;
    while (m--) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }
    int ans = 0;
    dfs(0);
    for (int i = 0; i < n; i++) {
        if (!vis[i]) {
            ans++;
            dfs(i);
        }
    }
    cout << ans;
}

Measured memory_bytes: 9656
# coding: utf-8
import sys
import numpy as np
from fractions import gcd

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, X0 = lr()
X = np.array(lr())
Xdiff = np.abs((X-X0)).tolist()
g = Xdiff[0]
for i in range(1, N):
    g = gcd(g, Xdiff[i])

answer = g
print(answer)


Measured memory_bytes: 25008
# https://atcoder.jp/contests/abc097/tasks/arc097_a
# C - K-th Substring

s = input().split()[0]
K = int(input().split()[0])

sub_s_list = []
N = len(s)
sorted_char_list = sorted(list(set(s)))
char_N = len(sorted_char_list)

# Kは最大で5であることに着目する
# 全部列挙する必要はなく、5番目まで見つかればよい
# 最初の1文字目
start_index_list = [i for i, char in enumerate(s) if char == sorted_char_list[0]]
pattern = sorted_char_list[0]
sorted_char_list.remove(pattern)
char_i = 0
j = 1

waiting_list = []

while len(sub_s_list) < 5:
    # print(pattern)
    sub_s_len = len(pattern)
    sub_s_list.append(pattern)
    next_list = [s[i:i+sub_s_len+1]
                for i in start_index_list
                if (i <= N - (sub_s_len + 1)) and (s[i:i+sub_s_len] == pattern)]

    if not next_list:
        if min(start_index_list) + sub_s_len > N:
            # 末尾まで伸びた
            if waiting_list:
                pattern = waiting_list[0]
                waiting_list.remove(pattern)
            elif sorted_char_list:
                pattern = sorted_char_list[0]
                start_index_list = [i for i, char in enumerate(s) if char == sorted_char_list[0]]
                sorted_char_list.remove(pattern)
        else:
            # 末尾まで伸ばす
            next_waiting_list =  [s[i:i+sub_s_len+1] for i in start_index_list
                                    if (i <= N - (sub_s_len + 1))]
            # print(next_waiting_list)
            waiting_list += next_waiting_list
            waiting_list = list(set(waiting_list))

            if waiting_list:
                waiting_list = sorted(waiting_list)
                pattern = waiting_list[0]
                waiting_list.remove(pattern)
            elif sorted_char_list:
                pattern = sorted_char_list[0]
                start_index_list = [i for i, char in enumerate(s) if char == sorted_char_list[0]]
                sorted_char_list.remove(pattern)
    else:
        waiting_list += next_list
        waiting_list = sorted(list(set(waiting_list)))
        pattern = waiting_list[0]
        waiting_list.remove(pattern)
    # print(waiting_list)

sub_s_list = list(set(sub_s_list))
ans = sorted(sub_s_list)[K-1]
print(ans)


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

ll a[200001];
ll k[200001];

int main(){
    ll n; cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
        k[a[i]]++;
    }
    ll sum=0;
    for(int i=1;i<=n;i++){
        sum+=k[i]*(k[i]-1)/2;
    }
    for(int i=0;i<n;i++){
        ll ka=k[a[i]];
        cout << sum-ka*(ka-1)/2+(ka-1)*(ka-2)/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, k;
ll F(ll n, ll k) {
    if (n <= k) {
        return min(n, k - n);
    }
    return F(n % k, k);
}
int main() {
    cin >> n >> k;
    cout << F(n, k);
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int A[20];
    int B[50];
    int C[50];
    int a, i, j, n;
    
    cin >> n;
    
    for(i=0; i < n; ++i){
        cin >> A[i];
    }
    
    for(i=0; i < n; ++i){
        cin >> B[i];
    }
    
    for(i=0; i < n-1; ++i){
        cin >> C[i];
    }
    
    a=0;
    
    for(i=0; i < n; ++i){
        j = A[i];
        a += B[j-1];
            if(A[i-1]==A[i]-1){
                a += C[j-2];
            }
    }
    
    cout << a << endl;
    
    return 0;
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();

		String a[] = new String[N];
		String b[] = new String[N];
		String c[] = new String[N];

		int cnt = 0;
		for (int i = 0; i < N; i++) {
			a[i] = A.substring(i, i+1);
			b[i] = B.substring(i, i+1);
			c[i] = C.substring(i, i+1);

			if (a[i].equals(b[i]) && b[i].equals(c[i])) {
				cnt += 0;
			} else if (a[i].equals(b[i]) || b[i].equals(c[i]) || c[i].equals(a[i])) {
				cnt += 1;
			} else {
				cnt += 2;
			}
		}
		System.out.println(cnt);
	}
}


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

using ll = long long;
using pii = pair<int, int>;

constexpr int mod = 1e9 + 7;

constexpr int rev_tbl[2][4][2] = { // [mir][rot][row/col]
    {{0, 0}, {1, 0}, {1, 1}, {0, 1}},
    {{0, 1}, {1, 1}, {1, 0}, {0, 0}}
};

int main() {
    ll n, q, A, B, C, D, E, F, G;
    cin >> n >> q >> A >> B >> C >> D >> E >> F >> G;

    vector<string> op(q);
    vector<int> w(q), x(q), y(q), z(q);
    for(int i = 0; i < q; ++i) {
        cin >> op[i];
        if(op[i] == "WR") cin >> w[i] >> x[i] >> y[i];
        else if(op[i] == "CP") cin >> w[i] >> x[i] >> y[i] >> z[i];
        else if(op[i] == "SR") cin >> w[i] >> x[i];
        else if(op[i] == "SC") cin >> w[i] >> x[i];
    }

    int mir = 0, rot = 0;
    vector<int> ridx(n), cidx(n);
    iota(begin(ridx), end(ridx), 1);
    iota(begin(cidx), end(cidx), 1);
    auto get_r_idx = [&] (int r) -> int& {
        const int i = (rev_tbl[mir][rot][0] ? n - r : r - 1);
        return rot & 1 ? cidx[i] : ridx[i];
    };
    auto get_c_idx = [&] (int c) -> int& {
        const int i = (rev_tbl[mir][rot][1] ? n - c : c - 1);
        return rot & 1 ? ridx[i] : cidx[i];
    };
    auto get_orig_pos = [&] (int r, int c) {
        if(rot & 1) return make_pair(get_c_idx(c), get_r_idx(r));
        else        return make_pair(get_r_idx(r), get_c_idx(c));
    };
    map<pii, int> v;
    for(int i = 0; i < q; ++i) {
        if(op[i] == "WR") {
            int r, c; tie(r, c) = get_orig_pos(w[i], x[i]);
            v[{r, c}] = y[i];
        } else if(op[i] == "CP") {
            int r1, c1, r2, c2;
            tie(r1, c1) = get_orig_pos(w[i], x[i]);
            tie(r2, c2) = get_orig_pos(y[i], z[i]);
            if(v.count({r1, c1})) {
                v[{r2, c2}] = v[{r1, c1}];
            } else {
                v[{r2, c2}] = (r1 * A + c1 * B) % C;
            }
        } else if(op[i] == "SR") {
            swap(get_r_idx(w[i]), get_r_idx(x[i]));
        } else if(op[i] == "SC") {
            swap(get_c_idx(w[i]), get_c_idx(x[i]));
        } else if(op[i] == "RL") {
            if(mir) rot = (rot + 3) % 4;
            else    rot = (rot + 1) % 4;
        } else if(op[i] == "RR") {
            if(mir) rot = (rot + 1) % 4;
            else    rot = (rot + 3) % 4;
        } else if(op[i] == "RH") {
            mir = !mir;
            rot = (rot + 2) % 4;
        } else if(op[i] == "RV") {
            mir = !mir;
        }
    }

    ll h = 314159265;
    for(int r = D; r <= E; ++r) {
        for(int c = F; c <= G; ++c) {
            int rr, cc; tie(rr, cc) = get_orig_pos(r, c);
            const ll val = v.count({rr, cc}) ? v[{rr, cc}] : (rr * A + cc * B) % C;
            h = (h * 31 + val) % mod;
        }
    }
    cout << h << endl;
}



Measured memory_bytes: 6612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main {
	
	public static void preorder(int cur, int[] n_value, int[] n_left, int[] n_right){
		System.out.print(" " + n_value[cur]);
		if(n_left[cur]  != -1){ preorder(n_left[cur] , n_value, n_left, n_right); }
		if(n_right[cur] != -1){ preorder(n_right[cur], n_value, n_left, n_right); }
	}
	
	public static void inorder(int cur, int[] n_value, int[] n_left, int[] n_right){
		if(n_left[cur]  != -1){ inorder(n_left[cur] , n_value, n_left, n_right); }
		System.out.print(" " + n_value[cur]);
		if(n_right[cur] != -1){ inorder(n_right[cur], n_value, n_left, n_right); }
	}
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		final int q = sc.nextInt();
		
		int[] n_value = new int[q];
		int[] n_left  = new int[q];
		int[] n_right = new int[q];
		Arrays.fill(n_left,  -1);
		Arrays.fill(n_right, -1);
		
		int node_count = 0;
		for(int i = 0; i < q; i++){
			final String ops = sc.next();
			
			if("insert".equals(ops)){
				final int value = sc.nextInt();
				n_value[node_count] = value;
				
				if(node_count != 0){
					int parent  = -1;
					int current =  0;
					
					while(current != -1){
						if(value < n_value[current]){
							parent  = current;
							current = n_left[current];
						}else{
							parent  = current;
							current = n_right[current];
						}
					}
					
					if(value < n_value[parent]){
						n_left[parent]  = node_count;
					}else{
						n_right[parent] = node_count;
					}
				}
				
				node_count++;
			}else if("print".equals(ops)){
				inorder(0, n_value, n_left, n_right);
				System.out.println();
				preorder(0, n_value, n_left, n_right);
				System.out.println();
			}
		}
		
		
	}

	public static class Scanner {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

		public void close() throws IOException {
			br.close();
		}
	}

}

Measured memory_bytes: 165180
#include <iostream>
using namespace std;
int main(){
  int n, k, i, ans=0;
  cin >> n >> k;
  int h[n];
  for(i=0;i<n; i++){
    cin >> h[i];
    if(h[i]>=k) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int a, b, C = ~(1<<31), M = (1<<16)-1;
int r() {
	a = 36969 * (a & M) + (a >> 16);
	b = 18000 * (b & M) + (b >> 16);
  	return (C & ((a << 16) + b)) % 1000000;
}

struct Point {
	int x, y, z;
	Point(int x, int y, int z) : x(x), y(y), z(z) {}
	Point(){}
	bool operator < (const Point &a) const {
		return (x == a.x ? y == a.y ? z > a.z : y > a.y : x < a.x);
	}
};

struct Point2 {
	int y, z;
	Point2(int y, int z) : y(y), z(z) {}
	Point2(){}
	bool operator < (const Point2 &a) const {
		return (y < a.y);
	}
};

int main()
{
	int m, n, A, B;

	while (scanf("%d %d %d %d", &m, &n, &A, &B) && m + n){
		a = A; b = B;
		vector<Point> v(m + n);
        vector<set<Point2>> s(m + n);
		for (int i = 0; i < m; i++){
			int x, y, z;
			scanf("%d %d %d", &x, &y, &z);
			v[i] = Point(x, y, z);
		}
		for (int i = 0; i < n; i++){
			int x = r();
			int y = r();
			int z = r();
			v[i + m] = Point(x, y, z);
		}
		sort(v.begin(), v.end());

        int ans = 1;
        s[0].insert(Point2(v[0].y, v[0].z));
        for (int i = 1; i < m + n; i++){
            int lf = -1, rg = ans - 1;
            while (lf != rg){
                int mid = (lf + rg + 1) / 2;
                auto it = s[mid].lower_bound(Point2(v[i].y, v[i].z));
                if (it != s[mid].begin() && (--it)->z < v[i].z) lf = mid;
                else rg = mid - 1;
            }
            rg++;
            ans = max(ans, rg + 1);

            auto it = s[rg].lower_bound(Point2(v[i].y, v[i].z));
            while (it != s[rg].end() && it->z >= v[i].z) it = s[rg].erase(it);

            if (!s[rg].size()) s[rg].insert(Point2(v[i].y, v[i].z));
            else {
                auto it = s[rg].lower_bound(Point2(v[i].y, v[i].z));
                if (it == s[rg].begin() || (--it)->z != v[i].z) s[rg].insert(Point2(v[i].y, v[i].z));
            }
        }
        printf("%d\n", ans);
	}

	return (0);
}

Measured memory_bytes: 24864
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,k = [int(i) for i in readline().split()]
s = input()

ans = 0
for i,j in zip(s,s[1:]):
    if i == j: ans += 1

#assert (n-1-ans)%2 == 0
print(min(n-1,ans+2*k))


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
long long n,m,k,ans=0,sum=0,cnt=0;
string s; 
int main() 
{
    int N,C;
    cin>>N>>C;
    int d[C][C];
    int a[3][C];
    for(int i=0;i<3;i++)
	{
        for(int j=0;j<C;j++)
		{
            a[i][j]=0;
        }
    }      
    for(int i=0;i<C;i++)
	{
        for(int j=0;j<C;j++)
		{
            cin>>d[i][j];
        }
    }
    for(int i=0;i<N;i++)
	{
        for(int j=0;j<N;j++)
		{
            int c;
            cin>>c;
            for(int k=0;k<C;k++)
			{
                a[(i+1+j+1)%3][k]+=d[c-1][k];
            }
        }
    }
    ans=-1;
    for(int i=0;i<C;i++)
	{
        for(int j=0;j<C;j++)
		{
            for(int k=0;k<C;k++)
			{
                if (i==j||j==k||k==i) continue;
                long long test=a[0][i]+a[1][j]+a[2][k];
                if (ans<0||test<ans) ans=test;
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int n = stdin.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = stdin.nextInt();
        }

        List<Integer> x = new ArrayList<>();
        List<Integer> y = new ArrayList<>();

        if (!isPositive(a) && !isNegative(a)) {
            int max = IntStream.range(0, n).boxed().collect(Collectors.maxBy(Comparator.comparing(i -> a[i]))).get().intValue();
            int min = IntStream.range(0, n).boxed().collect(Collectors.minBy(Comparator.comparing(i -> a[i]))).get().intValue();
            if (Math.abs(a[min]) <= Math.abs(a[max])) {
                for (int i = 0; i < n; i++) {
                    x.add(max);
                    y.add(i);
                    a[i] += a[max];
                }
            } else {
                for (int i = 0; i < n; i++) {
                    x.add(min);
                    y.add(i);
                    a[i] += a[min];
                }
            }
        }

        if (isPositive(a)) {
            for (int i = 0; i < n - 1; i++) {
                x.add(i);
                y.add(i + 1);
            }
        }

        if (isNegative(a)) {
            for (int i = n - 1; i > 0; i--) {
                x.add(i);
                y.add(i - 1);
            }
        }

        System.out.println(x.size());
        for (int i = 0; i < x.size(); i++) {
            System.out.printf("%d %d%n", x.get(i) + 1, y.get(i) + 1);
        }
    }

    public static boolean isPositive(int[] a) {
        return Arrays.stream(a).allMatch(i -> i >= 0);
    }

    public static boolean isNegative(int[] a) {
        return Arrays.stream(a).allMatch(i -> i <= 0);
    }
}

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

int top, S[1000];

void push(int x)
{
	/*topを加算してからその位置へ挿入*/
	S[++top]=x;
}

int pop()
{
	top--;
	/*topが指していた要素を返す*/
	return S[top+1];
}

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


Measured memory_bytes: 2076
import heapq

N, K = map(int, input().split())
dt = [list(map(int, input().split()))[::-1] for i in range(N)]
dt.sort(reverse=True)

ans = 0
t_set = set()
candidates = []
for d, t in dt[:K]:
  if t in t_set:
    heapq.heappush(candidates, [d, t])
    ans += d
  else:
    t_set.add(t)
    ans += d

x = len(t_set)
ans += x**2

if len(candidates) == 0:
  print(ans)
  quit()

ans = [ans]
for d, t in dt[K:]:
  if t in t_set:
    continue
  cand_d, cand_t = heapq.heappop(candidates)
  _ans = ans[-1] - cand_d + d + (2*x+1)
  x += 1
  ans.append(_ans)
  t_set.add(t)
  if len(candidates) == 0:
    break

print(max(ans))

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

#define rep(i, u) for (int i = 0; i < u; i++)

int main() {
  int n;

  cin >> n;
  while (n > 1000) {
    n -= 1000;
  }
  int ans;
  ans = 1000 - n;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>

int main(){
  char a,b,c[10],t;
  scanf("%d",&a);
  scanf("%d",&b);
  if(a>b){
   	t=a;
    a=b;
    b=t;
  }
  c[b]=0;
  b--;
  for(;b>=0;b--){
    c[b]=a+0x30;
  }
  printf("%s",c);
  return 0;
}


Measured memory_bytes: 128
if __name__ == "__main__":
    N, M = map(int, input().split())
    key_data = list()
    INF = 1001001001
    for i in range(M):
        a, b = map(int, input().split())
        c = sum(1 << (ci - 1) for ci in map(int, input().split()))
        key_data.append([a, c])

    dp = [INF] * 2 ** N
    dp[0] = 0

    for j in range(2**N):
        for i in range(M):
            k = j | key_data[i][1]
            cost = dp[j] + key_data[i][0]
            if dp[k] > cost:
                dp[k] = cost

    if dp[2**N - 1] == INF:
        print('-1')
    else:
        print(dp[2**N - 1])


Measured memory_bytes: 44392
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>
using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;
const int INF = 1e9;

long long gcd(long long x, long long y){
			if(x<y){
				long long temp = x;
			x = y;
				y = temp;
			}
			long long r = x % y;
				while(r!=0){
					x = y;
					y = r;
				r = x % y;
	    		}
			return y;
	    }

int main(){
	int H,W;
	cin >> H >> W;
vector<string> s(H);
for(int i = 0; i < H;i++){
		cin >> s[i];
}
int div[4][2] = {{0,1},{1,0},{0,-1},{-1,0}};
for(int i = 0; i < H;i++){
	for(int j = 0; j < W;j++){
		if(s[i][j] == '#'){
			bool ok = false;
			for(int k = 0; k < 4; k++){
					int h = i + div[k][0];
					int w = j + div[k][1];
					if(h<0||h>=H||w<0||w>=W)continue;
					else if(s[h][w]=='#')ok = true;

			}
			if(ok == false){
				cout << "No" << endl;
				return 0;
				}
		}


	}
}
cout << "Yes" << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long int n,sum=0,a;
    cin>>n;
    while(n--)
    {
        cin>>a;
            sum=sum^a;
    }
    if(sum==0)
        cout<<"Yes";
    else
        cout<<"No";

}


Measured memory_bytes: 384
use proconio::{input, fastout};
use std::collections::BTreeMap;

#[fastout]
fn main() {
    input! {
        n: usize, m: usize,
        mut arr: [usize; n],
        rep: [(usize, usize); m],
    }

    arr.sort();

    let mut bset: BTreeMap<usize, usize> = BTreeMap::new();
    for &(b, c) in &rep {
        if bset.contains_key(&c) {
            let bb = bset.get_mut(&c).unwrap();
            *bb += b;
        } else {
            bset.insert(c, b);
        }
    }

    let mut cursor: usize = 0;
    for (&c, &b) in bset.iter().rev() {
        let m = std::cmp::min(n, b+cursor);
        if arr[m-1] >= c {
            for i in cursor..m {
                if arr[i] >= c { break; }
                arr[i] = c;
            }
            break;
        } else {
            for i in cursor..m { arr[i] = c; }
            cursor = m;
        }
    }

    println!("{}", arr.iter().sum::<usize>() );
}


Measured memory_bytes: 10164
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000000+7
using namespace std;
typedef long long ll;

int main(){
  ll N, A; cin >> N >> A;
  ll X=-1;
  vector<ll> x(N+1, 0);
  rep(i, 1, N+1)  {
    cin >> x[i];
    X = max(X, x[i]);
  }
  vector<vector<vector<ll>>> dp(N+1, vector<vector<ll>>(N+1, vector<ll>(N*X+1, 0)));
  rep(j, 0, N+1){
    rep(k, 0, N+1){
      rep(s, 0, N*X+1){
        if(j==0 and k==0 and s==0)          dp[j][k][s] = 1;
        else if(j>=1 and s<x[j])            dp[j][k][s] = dp[j-1][k][s];
        else if(j>=1 and k>=1 and s>=x[j])  dp[j][k][s] = dp[j-1][k][s]+dp[j-1][k-1][s-x[j]];
        else                                dp[j][k][s] = 0;
      }
    }
  }
  ll ans=0;
  rep(i, 1, N+1)  ans+=dp[N][i][i*A];
  cout << ans << endl;
}

Measured memory_bytes: 52224
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

an_list = [a,b,c,d,e]

min_an = min(an_list)
max_an = max(an_list)

if abs(min_an-max_an) <= k:
    print('Yay!')
else:
    print(':(')

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
  int L,R,d;
  cin >> L >> R >> d;
  
  int R_d = R / d;
  int L_d = L / d;
  int result =  R_d - L_d;
  if (L % d == 0) result++;
  cout << result;
}

Measured memory_bytes: 3636
let a = read_line () in
let b = read_line () in
let al = String.length a in
let bl = String.length b in
print_endline @@
if al > bl then "GREATER" else
    if al < bl then "LESS" else
        if a > b then "GREATER" else
            if a < b then "LESS" else
                "EQUAL"

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

import static java.lang.Integer.parseInt;

/**
 * Lottery
 */
public class Main {

	static final int MAX = 1_000_000;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		//primes
		boolean[] ps = primes(MAX);
		int[] count = new int[ps.length];
		for (int i = 1; i < count.length; i++) {
			count[i] = count[i - 1] + (ps[i] ? 1 : 0);
		}


		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = parseInt(line);
			if (n == 0) break;

			int sum = 0;
			for (int i = 0; i < n; i++) {
				line = br.readLine();
				int p, m, s, t;
				p = parseInt(line.substring(0, line.indexOf(' ')));
				m = parseInt(line.substring(line.indexOf(' ') + 1));
				s = p - m - 1;
				t = p + m;
				if (p - m - 1 < 0) s = 1;
				if (p + m > MAX) t = MAX;
				sum += count[t] - count[s] - 1;
			}
			System.out.println(sum);

		} //ene while
	}//end main

	static boolean[] primes(int limit) {

		boolean[] ps = new boolean[limit + 1];
		int _limit = (int) Math.sqrt(ps.length) + 1;

		//2..
		Arrays.fill(ps, 2, ps.length, true);

		for (int i = 2; i <= _limit; i++) {
			if (ps[i]) {
				for (int j = i * 2; j < ps.length; j += i) {
					if (ps[j]) ps[j] = false;
				}
			}
		}
		return ps;
	}
}

Measured memory_bytes: 31760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod=1000000007;
#define pb  push_back
#define FOR(i,n) for(int i=0;i<(n);i++)
#define FORA(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define count_1(n)  __builtin_popcountll(n)
#define parity(n)   __builtin_parityll(n)   //Even parity 0 as output
void show    (int a[], int arraysize) { for (int i = 0; i < arraysize; ++i)  {cout << a[i] << " ";}	cout<<endl;}
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
void sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
int main()
{FAST
ld sum=0;
int n,k,v=0;
cin>>k>>n;
int a[n];
FOR(i,n)
{
	cin>>a[i];
  
}
FOR(i,n-1)
{v=max(abs(a[i]-a[1+i]),v);
  
}
v=max(abs(k+a[0]-a[n-1]),v);

cout<<k-v;

}




Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <stdlib.h>
using namespace std;
typedef struct {
    int a;
    int b;
}Eat;
int comp(const void *a, const void *b){
    Eat c = *(Eat *)a;
    Eat d = *(Eat *)b;
    return c.a - d.a;
}
int main(void){
    int n, t;
    cin >> n >> t;
    Eat eat[3002];
    for(int i=0;i<n;i++){
        cin >> eat[i].a >> eat[i].b;
    }
    qsort(eat,n,sizeof(Eat),comp);
    //cout << eat[1].b << endl;
    int **dp; int h=3001, w=3001;
    dp = (int **)malloc(sizeof (int*) * w);
    for(int i=0;i<=w;i++){
        dp[i] = (int *)malloc(sizeof (int) * h);
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<=t-1;j++){
            if(j>=eat[i].a) dp[i+1][j] = max(dp[i][j-eat[i].a]+eat[i].b,dp[i][j]);
            else dp[i+1][j] = dp[i][j];
        }
    }
    /*for(int i=0;i<n;i++){
        for(int j=0;j<=t-1;j++){
            printf("%d ",dp[i][j]);
        }puts("");
    }*/
    int MAX = 0;
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++)
        MAX = max(dp[i][t-1]+eat[j].b,MAX);
    }
    cout << MAX << endl;
}


Measured memory_bytes: 35452
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);
        int c = int.Parse(input[2]);
        int x = c;
        for(int i = 0; i < 10; i++)
        {
            x = a * x - b;
            Console.WriteLine(x);
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int N=510;

int n, m, k, u, v, x, y, t, a, b;
int A[N], ans[N*N];
int R[N*N];
priority_queue<pii, vector<pii>, greater<pii>> pq;
vector<int> vec[N*N];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	memset(R, 31, sizeof(R));
	cin>>n;
	for (int i=0; i<n; i++){
		cin>>A[i];
		R[i*n+i]=--A[i];
		for (int j=i; j; j--) R[i*n+j-1]=R[i*n+j]-1;
	}
	vec[A[0]].pb(0);
	for (int i=1; i<n; i++) pq.push({R[i*n], i*n});
	
	for (int i=0; i<n*n; i++){
		for (int v:vec[i]) pq.push({R[v], v});
		if (pq.empty()) kill("No")
		int v=pq.top().second;
		pq.pop();
		if (R[v]<i) kill("No")
		int num=v/n, t=v%n;
		ans[i]=num;
		if (t!=n-1){
			t++;
			if (t==num) vec[A[num]].pb(v+1);
			else pq.push({R[v+1], v+1});
		}
	}
	cout<<"Yes\n";
	for (int i=0; i<n*n; i++) cout<<ans[i]+1<<" ";cout<<"\n";
	
	return 0;
}


Measured memory_bytes: 11712
#include <bits/stdc++.h>
using namespace std;
#define doublepr(x) cout<<fixed<<setprecision(10)<<x
double dp[301][301][301];

double solve(int x, int y, int z, int n) {
    if(x < 0 || y < 0 || z < 0) return 0;
    if(x == 0 && y == 0 && z == 0) return 0;
    if(dp[x][y][z] > -0.9) return dp[x][y][z];
    double exp = n + x*solve(x-1, y, z, n) + y*solve(x+1, y-1, z, n) + z*solve(x, y+1, z-1, n);
    return dp[x][y][z] = exp/(x+y+z);
}

int main() {
    int N; cin>>N;
    int one, two, three;
    one = two = three = 0;
    for(int i=0; i<N; i++) {
        int tmp; cin>>tmp;
        if(tmp == 1) one++;
        else if(tmp == 2) two++;
        else three++;
    }
    memset(dp, -1, sizeof dp);
    solve(one, two, three, N);
    doublepr(dp[one][two][three]);
    return 0;
}


Measured memory_bytes: 216804
n,x=map(int,input().split())
x_list=list(map(int,input().split()))
d_list=[]
for i in x_list:
    d_list.append(abs(x-i))
import fractions
if n==1:
    answer=d_list[0]
else:
    answer=fractions.gcd(d_list[0],d_list[1])
    for i in range(2,n):
        answer=fractions.gcd(answer,d_list[i])
print(answer)


Measured memory_bytes: 83732
text = input()
n = int(input())

for _ in range(n):
    command = input().split()
    st = int(command[1])
    en = int(command[2])

    if command[0] == "print":
        print(text[st:en+1])

    elif command[0] == "reverse":
        if st == 0:
            text = text[en::-1] + text[en+1:]
        else:
            text = text[:st] + text[en:st-1:-1] + text[en+1:]

    elif command[0] == "replace":
        text = text[:st] + command[3] + text[en+1:]


Measured memory_bytes: 5616
#include <iostream>

using namespace std;




int main(){
    int int1;
    cin >> int1;
    int p = 0;


    for(int int2 = 1;int2 <= int1;int2++){
        int s = std::to_string(int2).length();
        if(s % 2 == 1){
            p++;
        }
    }
    cout << p << endl;


}

Measured memory_bytes: 256
def uo(x):
    if x == 1:
        return 1
    else:
        uouo = []
        uouo.append(1)
        for i in range(2,x//2+1):
            if x % i == 0:
                uouo.append(i)
        uouo.append(x)

        return len(uouo)

a = 0

for i in [i for i in range(int(input())+1)]:
    if i % 2 == 1 and uo(i) == 8:
        a += 1

print(a)

Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		List<Integer> arr = new ArrayList<>();
		String s = in.nextLine();
		in.close();
		for (int i = 1; i < s.length() + 1; i++) {
			if (s.charAt(i - 1) == '0') {
				arr.add(0);
			} else if (s.charAt(i - 1) == '1') {
				arr.add(1);
			} else {
				if (arr.size() == 0) {
				} else {
					arr.remove(arr.size()-1);
				}
			}
		}
		for (int e : arr) {
			System.out.print(e);
		}
	}
}


Measured memory_bytes: 22612
S = input()
K = int(input())
S_len = len(S)
ans = set()
for i in range(0, K+1):
    for j in range(0, S_len):
        if j + i <= S_len:
            t = S[j:j + i]
            if t != '':
                ans.add(t)
ans = list(ans)
ans.sort()
print(ans[K-1])


Measured memory_bytes: 10260
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

#include <set>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h, w, m;
    cin, h, w, m;

    set<P> st;  // (x,y)
    vector<int> hh(h, 0), ww(w, 0);
    REP(i, 0, m) {
        int a, b;
        cin, a, b;
        a--;
        b--;
        st.emplace(b, a);
        hh[a]++;
        ww[b]++;
    }
    vector<int> hhi(h), wwi(w);
    iota(hhi.begin(), hhi.end(), 0);
    iota(wwi.begin(), wwi.end(), 0);
    sort(hhi.begin(), hhi.end(), [&](int a, int b) {
        return hh[a] > hh[b];
    });
    sort(wwi.begin(), wwi.end(), [&](int a, int b) {
        return ww[a] > ww[b];
    });

    ll ans = 0;
    int maxH = hh[hhi[0]], maxW = ww[wwi[0]];
    REP(i, 0, h) {
        if (hh[hhi[i]] < maxH) break;
        REP(j, 0, w) {
            if (ww[wwi[j]] < maxW) break;
            int posH = hhi[i], posW = wwi[j];
            if (st.count({posW, posH})) {
                ans = ww[posW] + hh[posH] - 1;
            } else {
                ans = ww[posW] + hh[posH];
                print(ans);
                return 0;
            }
        }
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 26696
import java.io.*;
import java.util.*;

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int[] a = new int[n + 1];
		a[0] = -1000000001;
		str = br.readLine().split(" ");
		for(int i = 0; i < n; i++) a[i + 1] = Integer.parseInt(str[i]);
		str = br.readLine().split(" ");
		int q = Integer.parseInt(str[0]);
		for(int i = 0; i < q; i++){
			str = br.readLine().split(" ");
			int k = Integer.parseInt(str[0]);
			int lb = 0;
			int ub = n + 1;
			while(ub - lb > 1){
				int mid = lb + (ub - lb) / 2;
				if(a[mid] >= k) ub = mid;
				else lb = mid;
			}
			System.out.println(ub - 1);
		}
	}
}



Measured memory_bytes: 63624
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  long long k,a[20001],ma,mi,sum[20001];
  fill(sum,sum+20000,LLONG_MAX);
  scanf("%d %d %lld",&n,&m,&k);
  a[0] = 0;
  sum[0] = 0;
  for(int i=1;i<=n;i++){
    scanf("%d",&a[i]);
    ma = a[i];
    mi = a[i];
    sum[i] = sum[i-1] + k+(ma-mi);
    for(int j=1;i-j > 0 && j<m;j++){
      ma = max(ma,a[i-j]);
      mi = min(mi,a[i-j]);
      sum[i] = min(sum[i],sum[i-j-1] + k+(j+1)*(ma-mi));
    }
  }
  cout << sum[n] << endl;
  return (0);
}

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

vector<int>X[100009], Y[100009], G;
int N, M, A[100009], B[100009], deg[100009], topo[100009]; bool used[100009];

void dfs(int pos) {
	used[pos] = true;
	for (int i = 0; i < X[pos].size(); i++) {
		if (used[X[pos][i]] == true) continue;
		dfs(X[pos][i]);
	}
	G.push_back(pos);
}

int main() {
	cin >> N >> M;
	for (int i = 1; i <= N + M - 1; i++) {
		cin >> A[i] >> B[i];
		X[A[i]].push_back(B[i]); deg[B[i]]++;
		Y[B[i]].push_back(A[i]);
	}

	int root = 0;
	for (int i = 1; i <= N; i++) { if (deg[i] == 0) root = i; }

	dfs(root);
	reverse(G.begin(), G.end());
	for (int i = 0; i < G.size(); i++) { topo[G[i]] = i; }

	for (int i = 1; i <= N; i++) {
		pair<int, int>maxn = make_pair(-1, -1);
		for (int j = 0; j < Y[i].size(); j++) {
			if (maxn.first < topo[Y[i][j]]) maxn = make_pair(topo[Y[i][j]], Y[i][j]);
		}
		if (maxn == make_pair(-1, -1)) cout << "0" << endl;
		else cout << maxn.second << endl;
	}
	return 0;
}

Measured memory_bytes: 17020
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define st first
#define nd second
#define turbo ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define qi queue<int>
#define ld long double

using namespace std;

/*---------------------------------------------------------///CODE///---------------------------------------------------------*/

const int N = 3e3;
int dp[N + 10][N + 10];

int main()
{
    turbo

    string s, t; cin >> s >> t;

    for(int i = 1; i <= s.size(); i++)
        for(int j = 1; j <= t.size(); j++)
            if(s[i - 1] == t[j - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
    
    int i = s.size();
    int j = t.size();

    vector<char> ans;

    while(i > 0 && j > 0)
    {
        if(s[i - 1] == t[j - 1])
        {
            ans.pb(s[i - 1]);
            i --;
            j --;
        }
        else if(dp[i - 1][j] > dp[i][j - 1])
            i --;
        else 
            j --;
    }

    reverse(ans.begin(), ans.end());
    for(char& i : ans)
        cout << i;

    return 0;
}

Measured memory_bytes: 35584