akhauriyash/Code-Regression huggingface dataset:
fun main(arg: Array<String>) {
    val (S, T) = listOfString()
    var (A, B) = listOfInt()
    val U = next()
    if (U == S) A -= 1 else B -= 1
    println("${A} ${B}")
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun nextInt(offset: Int = 0) = nextInt() + offset
fun nextLong() = java.lang.Long.parseLong(next())
fun nextLong(offset: Long = 0L) = nextLong() + offset
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }
fun listOfInt(offset: Int = 0) = listOfString().map { Integer.parseInt(it) + offset }
fun listOfLong() = listOfString().map { java.lang.Long.parseLong(it) }
fun listOfLong(offset: Long = 0L) = listOfString().map { java.lang.Long.parseLong(it) + offset }
fun listOfDouble() = listOfString().map { it.toDouble() }

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

using ll = long long;

// Segment-Tree
struct SegmentTree {
  int n;
  vector<ll> dat;
  
  SegmentTree(int _n) {
    init(_n);
  }
  
  void init(int _n) {
    n = 1;
    while (n < _n) n *= 2;
    dat.resize(2 * n - 1, 0);
  }
  
  // i番目の値にxを加算
  void add(int i, int x) {
    i += n - 1; // 葉のノード
    dat[i] += x;
    while (i > 0) { // 更新
      i = (i - 1) / 2;
      dat[i] = dat[2 * i + 1] + dat[2 * i + 2];
    }
  }
  
  // [a, b)の和
  // k:ノードの番号 [l, r)がkに対応づいている
  ll query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1) r = n;
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b) return dat[k];
    else {
      ll vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
      ll vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
      return vl + vr;
    }
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n;
  cin >> n;
  
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  
  ll l = 1, r = 1e9 + 1, total = n * (n + 1) / 2, itadd = 1e5;
  while (r - l > 1) {
    ll mid = (l + r) / 2, count = 0, now = 0;
    SegmentTree st(2e5 + 1);
    st.add(0 + itadd, 1);
    for (int i = 0; i < n; i++) {
      if (a.at(i) >= mid) now++;
      else now--;
      count += st.query(0, now + 1 + itadd);
      st.add(now + itadd, 1);
    }
    if (count >= (total + 1) / 2) l = mid;
    else r = mid;
  }
  
  cout << l << '\n';
}


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

int main() {
  int n;
  cin >> n;
  n = n%10;
  if(n==3) puts("bon");
  else if(n==0|n==1|n==6|n==8) puts("pon");
  else puts("hon");
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define INF 1000000000001
#define DIM 100001
#define mod 1000000007
#define PI 3.1415926535897932384626433
#define se second
#define fi first
#define pb push_back
#define T true
#define F false
#define endl "\n"
#define gg cout<<"OPS"<<endl;
#define qwe return 0;
#define amen exit(0);
typedef char ch;
typedef bool boll;
typedef string st;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef set < string > sst;
typedef set < long long > sll;
typedef queue < long long > que;
typedef deque < long long > deq;
typedef vector < long long > vec;
typedef map < long long, long long > mll;
typedef pair < long long, long long > pll;
typedef vector < pair < long long, long long > > vpl;
typedef pair < long long, unsigned long long > pul;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> sat_set;
ll t,n;
int main()
{
     fast;
     ll k=0;
     st ss;
     ll f1=0,f2=0,f3=0;
     cin>>ss;
     for(int i=ss.size()-1;i>=0;i--){
        if(ss[i]=='2' || ss[i]=='4' || ss[i]=='5' || ss[i]=='7' || ss[i]=='9'){
            f1=1;
        }
        else if(ss[i]=='0' || ss[i]=='1' || ss[i]=='6' || ss[i]=='8'){
            f2=1;
        }
        else {
            f3=1;
        }
        break;
     }
     if(f1==1)cout<<"hon";
     if(f2==1)cout<<"pon";
     if(f3==1)cout<<"bon";
     cout<<endl;
}


Measured memory_bytes: 3616
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 1000000;

int kk[N];

int main() {
	int n; cin >> n;
	for (int a = 1; a < n; a++)
		for (int b = a; b < n; b += a)
			kk[b]++;
	int ans = 0;
	for (int a = 1; a < n; a++)
		ans += kk[a];
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 7500
#include<bits/stdc++.h>
using namespace std;
const int N=100002;
struct node{
	int to,ne;
}e[N<<1];
int h[N],tot,i,n,m,d[N],x,y,cnt;
inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int rd(){
	int x=0,fl=1;char ch=gc();
	for(;ch<48||ch>57;ch=gc())if(ch=='-')fl=-1;
	for(;48<=ch&&ch<=57;ch=gc())x=(x<<3)+(x<<1)+(ch^48);
	return x*fl;
}
void add(int x,int y){e[++tot]=(node){y,h[x]},h[x]=tot;}
void dfs(int u,int fa){
	if (u==x && fa) return;
	if (u==y){
		cnt++;
		return;
	}
	for (int i=h[u],v;i;i=e[i].ne)
		if ((v=e[i].to)!=fa) dfs(v,u);
}
int main(){
	n=rd(),m=rd();
	if (m<n+2) return puts("No"),0;
	for (i=1;i<=m;i++){
		d[x=rd()]++,d[y=rd()]++;
		add(x,y),add(y,x);
	}
	for (i=1;i<=n;i++)
		if (d[i]&1) return puts("No"),0;
	x=y=0;
	for (i=1;i<=n;i++)
		if (d[i]>2){
			if (d[i]>=6) return puts("Yes"),0;
			if (!x) x=i;
			else if (!y) y=i;
			else return puts("Yes"),0;
		}
	dfs(x,0);
	puts(cnt==2?"Yes":"No");
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x = 0, y = 0, z = 0;
  char ch;
  for(int i = 0; i < 3; i++){
    cin >> ch;
    if(ch == 'a') x++;
    else if(ch == 'b') y++;
    else z++;
  }
  printf("%s\n", (x == 1 && y == 1 && z == 1) ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
#define ll long long
#define lg __int128
using namespace std;
const int N=105,mo=998244353;
map<lg,int>f[N];
lg n;
string s;
int get(lg s,int n){
	if(f[n].count(s))return f[n][s];
	int su=(ll)get(s>>1,n-1)*((s&1)+1)%mo;
	fo(i,1,n/2){
		lg g=((lg)1<<i)-1,a=s&g;
		fo(j,2,n/i){
			a&=(s>>i*(j-1))&g;
			su=((ll)get(a,i)*get(s>>i*j,n-i*j)+su)%mo;
		}
	}
	return f[n][s]=su;
}
int main(){
	cin>>s;
	f[0][0]=1;
	f[1][0]=1;
	f[1][1]=2;
	fo(i,0,s.size()-1)n=n*2+s[i]-'0';
	cout<<get(n,s.size());
}

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

char dat[100005];
bool zz[100005];

int main()
{
	int n;
	scanf("%d%s", &n, dat);

	dat[0];

	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			zz[0] = i;
			zz[1] = j;
			for (int k = 1; k < n - 1; k++)
			{
				zz[k + 1] = zz[k - 1] ^ zz[k] ^ (dat[k] == 'x');
			}
			if ((dat[n - 1] == 'x') == (zz[n - 2] ^ zz[n - 1] ^ zz[0]) &&
				(dat[0] == 'x') == (zz[n-1] ^ zz[0] ^ zz[1]))
			{
				for (int k = 0; k < n; k++) printf("%c", zz[k] ? 'W' : 'S');
				printf("\n");
				return 0;
			}
		}
	}
	printf("-1\n");
}

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

int main(){
	int a[3][11][21];
	int n=0;
	int m=0;
	int y[10000][3];
	for(int i=997;i<1000;i++){
		for(int j=1;j<11;j++){
			if(j%2==0 && i%3>0){
				for(int k=1;k<20;k++){
					n++;
					a[i-997][j][k] = n;
				}
			}
			else{
				for(int k=1;k<21;k++){
					n++;
					a[i-997][j][k] = n;
				}
			}
		}
	}
	cin>>m;
	for(int i=0;i<m;i++){
		cin>>y[i][0]>>y[i][1]>>y[i][2];
		cout<<(999-y[i][0])/3*590+591-a[(y[i][0]-1)%3][y[i][1]][y[i][2]]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
//#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)

const int M=1000000007;
const int MM=998244353;


 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(m<=1)return 0;
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}

const ll N=1e5+5;




int main()
{ 

IOS;

ll n;cin>>n;

vl a(n);

ll mx=0;

FOR(i,n){
  cin>>a[i];
  mx=max(mx,a[i]);
}

ll mid=(mx+1)/2;

ll d,val=-1;

FOR(i,n){
 // if(!i)continue;
  if(a[i]==mx)continue;
  ll temp=a[i];
  if(temp>mid)temp=mx-a[i];
  if(temp>val){
    val=temp;
    d=a[i];
  }
}

d2(mx,d);


return 0;
 
}


Measured memory_bytes: 3976
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>

class ACircle {
public:
	void solve(std::istream& in, std::ostream& out) {
        int r;in >> r;
        out <<r*r;
	}
};


int main() {
	ACircle solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main(){
    string symbol;
    cin >> symbol;
    int count =0;

    for(int i = 0; i < symbol.size(); i++){
        if(symbol[i] == '+'){
            count += 1;
        }else{
            count -= 1;
        }
    }
    cout << count;
}

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

template<typename T> class BIT {
private:
    int n,m; vector<vector<T> > bit;
public:
    void add(int i, int j, T val){
        for(int i_ = i+1; i_ < n; i_ += i_ & -i_)
            for(int j_ = j+1; j_ < m; j_ += j_ & -j_)
                bit[i_][j_] += val;
    }
    T sum(int i, int j){
        T s = 0;
            for(int i_ = i+1; i_ > 0; i_ -= i_ & -i_)
                for(int j_ = j+1; j_ > 0; j_ -= j_ & -j_)
                    s += bit[i_][j_];
            return s;
    }
    // [lx, rx)×[ly, ry)の範囲の和を求める
    T sum(int lx, int ly, int rx, int ry){
        return sum(rx-1, ry-1) - sum(lx-1, ry-1) - sum(rx-1, ly-1) + sum(lx-1, ly-1);   
    }
    BIT(int sz1, int sz2){
        n = sz1 + 1, m = sz2 + 1;
        bit.resize(n, vector<T>(m, 0));
    }
    BIT(vector<vector<T> >& v){
        n = (int)v.size()+1, m = (int)v[0].size()+1;
        bit.resize(n, vector<T>(m, 0));
        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++)
                add(i, j, v[i][j]);
    }
    void print_sum(){
        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++)
                cout<< sum(i-1, j-1) << " ";
        cout << "\n";
    }
};

int main()
{
    int m, n, K;
    cin >> m >> n >> K;
    vector<BIT<int> > bt(3, BIT<int>(m, n));
    vector<string> s(m);
    for(int i = 0; i < m; i++){
        cin >> s[i];
        for(int j = 0; j < n; j++){
            if(s[i][j] == 'J'){
                bt[0].add(i, j, 1);
            }else if(s[i][j] == 'O'){
                bt[1].add(i, j, 1);
            }else{
                bt[2].add(i, j, 1);
            }
        }
    }
    // bt[0].print();
    for(int i = 0; i < K; i++){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        --a, --b;
        cout << bt[0].sum(a, b, c, d) << " " << bt[1].sum(a, b, c, d) << " " << bt[2].sum(a, b, c, d) << "\n";
    }
    return 0;
}


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

using namespace std;

#define inf 1<<30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef struct data{
	int now;
	int cost;
}data;

struct edge{
	int start;
	int finish;

	bool operator<(const edge &right) const{
		return finish < right.finish;
	}
	bool operator>(const edge &right) const{
		return finish > right.finish;
	}
};
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};

int N, M;
vector<edge> edges;


int main(){
	cin >> N >> M;
	for(int i = 0; i < M; i++){
		edge Edge;
		cin >> Edge.start >> Edge.finish;
		edges.pb(Edge);
	}
	int ans = 0;
	sort(edges.begin(), edges.end());
	while(edges.size()){
		ans++;
		int rm = edges[0].finish-1;
		for(int i = 0; i < edges.size(); i++){
			if(edges[i].start <= rm && rm < edges[i].finish){
				edges.erase(edges.begin()+i);
				i--;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1400
using System;
using System.Linq;
class Program
{
    static void Main()
    {
        //string[] input = Console.ReadLine().Split();
        int a=int.Parse(Console.ReadLine());
        int b = int.Parse(Console.ReadLine());
        //string a = Console.ReadLine();
        Console.WriteLine(b*2-a);
        Console.ReadLine();
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, starter, n) for (int i = (starter); i < (int)(n); i++)

int main(){
    int N;
    string X;
    cin >> N;
    cin >> X;
    int size = X.length();
    string S = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    rep(i,size){
            int basyo = S.find(X.at(i));
            if ((basyo +N )>= 26){
                cout << S.at((basyo+N)-26);

            }else { 
                cout << S.at(basyo + N);
            } 
    }
    cout << endl;
}

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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>
#include <queue>
#include <stack>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;




// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
 ll n, m;
 cin >> n >> m;
 vector<pair<ll, ll>> p(n);
 REP(i, n){
   ll a, b;
   cin >> a >> b;
   p[i].first = a;
   p[i].second = b;
 }
 sort(p.begin(), p.end());
 ll ans = 0;
 ll now = 0;
 while (now < m){
   for (auto v : p){
     ll val = v.second;
     val = min(m-now, val);
     ans += val * v.first;
     now += val;
   }
 }
 cout << ans << endl;
  return 0;
}



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


int main(void)
{
	char strl[6];
	char strr[6];
	scanf("%c%c%c%c",&strl[0],&strl[1],&strr[0],&strr[1]);
	strl[2] = '\0';
	strr[2] = '\0';
	if (atoi(strl) == 0 && atoi(strr)>= 13)
	{
		printf("NA\n");
		return (0);
	}
	else if (atoi(strr) == 0 && atoi(strl) >= 13)
	{
		printf("NA\n");
		return (0);
	}
	else if ((atoi(strl) >= 13 && atoi(strr) >= 13 )||
			(atoi(strl)==0 && atoi(strr)==0))
	{
		printf("NA\n");
		return (0);
	}
	else if (atoi(strl) <= 12 && (atoi(strr) >= 13 || atoi(strr)==0))
	{
		printf("MMYY\n");
		return (0);
	}
	else if ((atoi(strl) >= 13||atoi(strl)==0) && atoi(strr) <= 12)
	{
		printf("YYMM\n");
		return (0);
	}
	else
	{
		printf("AMBIGUOUS\n");
		return (0);
	}
	return(0);
}


Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author YahiaAshraf74
 */

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <complex>
#include <string>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <assert.h>

using namespace std;
#define el  '\n'
#define ll long long
#define clr(a, b)memset(a,b,sizeof(a))
#define sz(a) (int)(a).size()
const long long N = (int) 3e2 + 5, OO = 0x3f3f3f3f, MOD = (int) 1e9 + 7;

double dp[N][N][N];

class JSushi {
public:
    void init() {
        clr(dp,0);
    }

    void solve(istream &cin, ostream &cout) {
        init();
        int n;
        cin >> n;
        vector<int> cnt(4);
        for (int i = 1; i <= n; i++) {
            int x;
            cin >> x;
            cnt[x]++;
        }
        for (int k = 0; k <= n; k++) {
            for (int j = 0; j + k <= n; j++) {
                for (int i = 0; i + j + k <= n; i++) {
                    if (i == 0 && j == 0 && k == 0) {
                        continue;
                    }
                    if (i + j + k > n) {
                        continue;
                    }
                    double wait = 1.0 * n / (i + j + k);
                    double pi = 1.0 * i / (i + j + k);
                    double pj = 1.0 * j / (i + j + k);
                    double pk = 1.0 * k / (i + j + k);
                    if (i != 0) {
                        dp[i][j][k] += pi * dp[i - 1][j][k];
                    }
                    if (j != 0) {
                        dp[i][j][k] += pj * dp[i + 1][j - 1][k];
                    }
                    if (k != 0) {
                        dp[i][j][k] += pk * dp[i][j + 1][k - 1];
                    }
                    dp[i][j][k] += wait;
                }
            }
        }
        cout << fixed << setprecision(10) << dp[cnt[1]][cnt[2]][cnt[3]] << el;
    }
};
int main() {
	ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
	JSushi solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 221952
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>

using namespace std;

int main() {
	string str;
	cin >> str;
	int n = str.length();

	int past[26];
	int maxInterval[26];
	for (int i = 0; i < 26; i++) {
		past[i] = -1;
		maxInterval[i] = -1;
	}
	for (int i = 0; i < n; i++) {
		int c = str[i] - 'a';
		maxInterval[c] = max(maxInterval[c], i - past[c] - 1);
		past[c] = i;
	}

	int m = n * 2;
	for (int i = 0; i < 26; i++) {
		maxInterval[i] = max(maxInterval[i], n - past[i] - 1);
		m = min(m, maxInterval[i]);
	}
	cout << m << endl;
	return 0;
}

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

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int l,k;
  cin>>l>>k;
  vector<Int> dp(1000,0);
  dp[0]=1;
  for(Int i=0;i<l;i++){
    dp[i+2]+=dp[i];
    dp[i+k+1]+=dp[i];
  }
  Int ans=0;
  for(Int i=0;i<l;i++){
    if(i+1<=l) ans+=dp[i];
    if(i+k<=l) ans+=dp[i];
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3220
#include <stdio.h>

int main()
{
	int a,b,s,digit;
	
	while(scanf("%d %d",&a,&b) != EOF){
		s=a+b;
		if(s/10==0){
			digit=1;
		}else{
			digit=2;
		}
		while((s/=10)>9){
			digit++;
		}
		printf("%d\n",digit);
	}
	
	return 0;
}

Measured memory_bytes: 600
#include<stdio.h>

void SelectionSort( int *A, int n ) 
{
	int i,j;
	int tmp;
	int cnt;
	int mini;
	
	cnt=0;
	for( i=0; i<n; i++ ) {
		mini=i;
		for( j=i; j<n; j++ ) {
			if( A[j] < A[mini] ) {
				mini=j;
			}
		}
		if( mini != i ) {
			tmp=A[i];
			A[i]=A[mini];
			A[mini]=tmp;
			cnt++;
		}
	}
	for( i=0; i<n; i++ ) {
		printf( "%d", A[i] );
		if( n-1 != i ) {
			printf( " " );
		}
	}	
	printf( "\n" );	
	printf( "%d\n", cnt );
	
	return;
}

int main( void ) 
{
	int n;
	int A[101];
	int i;

	scanf( "%d", &n );
	for( i=0; i<n; i++ ) {
		scanf( "%d", &A[i] );
	}
	
	SelectionSort( A, n );
	
	return 0;
}

Measured memory_bytes: 604
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(ll i=ini;i<(ll)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e9+7;
const int N = 1e6+7;

 
int main()
{
    ll x;
    lscf(x);

    int flag=1;


    
    rep(i,-1000,1001)
    {rep(j,-1000,1001)
    {
        if(pow(i,5)-pow(j,5)==x&&flag)
        {
            cout<<i<<" "<<j<<"\n";
            flag=0;
        }
        
    }
    }
    
    
}

Measured memory_bytes: 4160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=100005;
ll B,n,X;
struct data{
	ll b,l,u,lj;
}a[N];
bool check(ll mid){
	ll t=mid/X,sy=mid%X,ans=0,mx=0;
	For(i,1,t)ans+=a[i].lj;
	For(i,t+1,n){
		if(sy>=a[i].b)mx=max(mx,a[i].b*a[i].l+(sy-a[i].b)*a[i].u);
		else mx=max(mx,sy*a[i].l);
	}
	For(i,1,t){
		if(sy>=a[i].b)mx=max(mx,a[i].b*a[i].l+(sy-a[i].b)*a[i].u+a[t+1].lj-a[i].lj);
		else mx=max(mx,sy*a[i].l+a[t+1].lj-a[i].lj);
	}
	//if(mid==100)cout<<ans<<" "<<B<<endl;
	return ans+mx>=B;
}
bool cmp(data a,data b){
	return a.lj>b.lj;
}
int main(){
	n=read(),X=read();
	For(i,1,n){
		a[i].b=read(); a[i].l=read(); a[i].u=read();
		a[i].lj=a[i].b*a[i].l+(X-a[i].b)*a[i].u; B+=a[i].l*a[i].b; //cout<<a[i].lj<<" "<<B<<endl;
	}
	sort(&a[1],&a[n+1],cmp);
	ll l=0,r=(ll)n*X;
	while(l<r){
		ll mid=(l+r)>>1;
		if(check(mid))r=mid; else l=mid+1;
	}
	cout<<l<<endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <typeinfo>
#include <cstring>
#include <utility>
#include <vector>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;


int main() {
    double R;
    cin >> R;

    cout << M_PI * R * 2 << endl;
    return 0;
}


Measured memory_bytes: 3788
#include<iostream>
using namespace std;
int main(){
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;
	if(0<=x-r&&x+r<=W&&0<=y-r&&y+r<=H){
		cout<<"Yes"<<endl;
	}
	else {
		cout<<"No"<<endl;
	}	
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  int a,b;
  cin >> a >> b;
  a--;b--;
  vector<vector<char>> data1(50,vector<char>(100,'.'));
  vector<vector<char>> data2(50,vector<char>(100,'#'));
  rep(i,(a/50)+1){
    long tmp;
    if(i == a/50) tmp = a%50;
    else tmp = 50;
    rep(j,tmp){
      data2[i*2][j*2] = '.';
    }
  }
  rep(i,(b/50)+1){
    long tmp;
    if(i == b/50) tmp = b%50;
    else tmp = 50;
    rep(j,tmp){
      data1[i*2][j*2] = '#';
    }
  }
  cout << 100 << " " << 100 << endl;
  rep(i,50){
    rep(j,100) cout << data1[i][j];
    cout << endl;
  }
  rep(i,100) cout << "#";
  cout << endl;
  rep(i,49){
    rep(j,100) cout << data2[i][j];
    cout << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
main(){
int n,k,x,y,a,b,c,d;
scanf("%d %d %d %d",&n,&k,&x,&y);
d=n*x;
n=n-k;
a=k*x;
b=n*y;
if(n>0){c=a+b;}else{c=d;}
printf("%d",c);
return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define inf 1000000000
using namespace std;
typedef long long ll;

int main(){
    int n,ans = 0;
    cin>>n;
    vector<int> b(n),a(n);
    rep(i,n-1) cin>>b[i];
    a[0] = b[0];
    a[n-1] = b[n-2];
    for(int i=1;i<n-1;i++){
        a[i] = min(b[i],b[i-1]);
    }
    rep(i,n){
        ans += a[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF 1145141919
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)

using namespace std;

int main(void){
  int N,M,j=0,p=0;
  cin >> N >> M;
  int A[N];
  rep(i,N) cin >> A[i];
  pair<int,int> B[M];
  rep(i,M) cin >> B[i].second >> B[i].first;
  sort(B,B+M,greater<pair<int,int>>());
  int C[N]={};
  while(p<N && B[M-1].second!=0){
    while(p<N && B[j].second!=0){
      C[p]=B[j].first;
      p++;
      B[j].second--;
    }
    j++;
  }
  int D[2*N];
  rep(i,N) D[i]=A[i];
  for(int i=N;i<2*N;i++) D[i]=C[i-N];
  sort(D,D+2*N,greater<int>());
  unsigned long long int ans=0;
  rep(i,N) ans+=D[i];
  cout << ans << endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int a[1005],n,s1,s2;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
		if(i%2==1) s1+=a[i];
		else s2+=a[i];
	cout<<abs(s1-s2)<<endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math


def check(A,B):
    digit_list=[]
    for num in [A,B]:
        count=0
        tmp_num=num
        while tmp_num != 0:
            tmp_num //= 10
            count += 1
        
        digit_list += [count]
    
    return max(digit_list)

#----------
N = int(input().strip())
#----------
min_f=10
for i in range( 1, math.ceil( N**(1/2) ) + 1 ):
    if (N % i) == 0:
        A,B = i,(N / i)
        digit = check(A,B)
        
        if min_f > digit:
            min_f = digit

print(min_f)


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

using namespace std;

#define int long long 
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int N, res;

int dfs(int n) {
    if(n > N) return res;
    int cnt[10] = {0}, tmp = n;
    while(tmp > 0) {
        ++cnt[tmp % 10];
        tmp /= 10;
    }
    if(cnt[3] > 0 && cnt[5] > 0 && cnt[7] > 0) ++res;
    dfs(n * 10 + 3);
    dfs(n * 10 + 5);
    dfs(n * 10 + 7);

    return res;
}

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

    cin >> N;
    cout << dfs(0) << endl;

    return 0;
} 

Measured memory_bytes: 256
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

int main(){
	int l = ci(), r = ci(), d = ci();
	int ans = 0;
	rep(i,1,r/d) if( d*i>=l && d*i<=r ) ans++;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1600
#!/usr/bin/env python3
import sys

def main():
    def comb(n,k,p):
        from math import factorial
        if n<0 or k<0 or n<k: return 0
        if n==0 or k==0: return 1
        a=factorial(n) %p
        b=factorial(k) %p
        c=factorial(n-k) %p
        return (a*pow(b,p-2,p)*pow(c,p-2,p))%p

    input = sys.stdin.readline
    s = int(input())
    mod = 10 ** 9 + 7
    if s < 3:
        print(0)
    elif 3 <= s < 6:
        print(1)
    else:
        cnt = 0
        ans = 1
        while s > 3:
            s -= 3
            cnt += 1
            ans += comb(s - 3 + cnt, cnt, mod)
            ans %= mod
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 75040
<?php
 
$is_honban = 1;
 
if ($is_honban) {
  //----------------------------------------------------------------------------------
  // Input for honban
  //----------------------------------------------------------------------------------
  $sc = new Scanner();
  $n = $sc->nextInt();
  $a = array();
  $a[] = $sc->nextInt();
  $a[] = $sc->nextInt();
  $a[] = $sc->nextInt();
  $a[] = $sc->nextInt();
  $a[] = $sc->nextInt();
 
//  $t = array();
//  $d = array();
//  for ($i = 0; $i < $n; $i++) {
//    $t[] = $sc->next();
//    $d[] = $sc->next();
//  }
 
 
} else {
  //----------------------------------------------------------------------------------
  // Input for test
  //----------------------------------------------------------------------------------
  error_reporting(E_ERROR | E_WARNING | E_PARSE);
 
  $n = 5;
  $a = array(3,2,4,3,5);
 
 
 
}
//----------------------------------------------------------------------------------
// Main
//----------------------------------------------------------------------------------
 
$ans = 0;
 
$a_min = $a[0];
for ($i = 0; $i < 5; $i++) {
  $a_min = min($a_min, $a[$i]);
}
 
$tmp = floor($n / $a_min);
if ($n % $a_min == 0) { $tmp--; }
$ans = $tmp + 5;
 
//----------------------------------------------------------------------------------
// Output
//----------------------------------------------------------------------------------
out::println($ans);
 
 
 
//----------------------------------------------------------------------------------
// Ref: https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
//----------------------------------------------------------------------------------
class Scanner {
  private $arr = array();
  private $count = 0;
  private $pointer = 0;
  public function next() {
    if($this->pointer >= $this->count) {
      $str = trim(fgets(STDIN));
      $this->arr = explode(' ', $str);
      $this->count = count($this->arr);
      $this->pointer = 0;
    }
    $result = $this->arr[$this->pointer];
    $this->pointer++;
    return $result;
  }
  public function hasNext() {
    return $this->pointer < $this->count;
  }
  public function nextInt() {
    return (int)$this->next();
  }
  public function nextDouble() {
    return (double)$this->next();
  }
}
 
class out {
  public static function println($str = "") {
//    echo $str . PHP_EOL;
    echo sprintf("%d", $str) . PHP_EOL;
  }
}
 
?>

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

using namespace std;

#define all(x) begin(x), end(x)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

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

    ll x;
    cin >> x;

    ll ans = 1000 * (x / 500);
    x %= 500;
    ans += 5 * (x / 5);

    cout << ans << '\n';
    
    return 0;
}


Measured memory_bytes: 256
using System;

namespace AtCoder
{
	public class ProblemA
	{
		public static void Main(string[] args)
		{
			string[] line = Console.ReadLine().Split(' ');
			int n = int.Parse(line[0]);
			int k = int.Parse(line[1]);

			int ans = k * (int)Math.Pow(k - 1, n - 1);

			Console.WriteLine(ans);
		}
	}
}


Measured memory_bytes: 27628
a,b,c,d=map(int,input().split())

if c<=a<=d and c<=b<=d:
    print(b-a)

elif a<=c<=b and a<=d<=b:
    print(d-c)
elif a<=c<=b:
    print(b-c)
elif c<=a<=d:
    print(d-a)
else:
    print(0)


Measured memory_bytes: 2940
#include <iostream>
#include <string>

using namespace std;

int main() {
	// your code goes here
	int n,k,q,a[100001],f[100001];
	cin >> n >> k >> q;
	for (int i=1;i<=q;i++) cin >> a[i];
	for (int i=1;i<=n;i++) f[i]=0;
	for (int i=1;i<=q;i++) f[a[i]]++;
	for (int i=1;i<=n;i++) if (k-q+f[i]>0) cout << "Yes" << endl; 
	else cout << "No" << endl;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;

int main(){
	cin>>n;
	ll res=0;
	for(int i=1;i<n;i++) res+=(n-1)/i;
	cout<<res<<endl;
}

Measured memory_bytes: 3568
n,k = map(int,input().split())
d = []
a_k = []
for i in range(k):
    d.append(int(input()))
    a = list(map(int,input().split()))
    a_k.append(a)
ans = [0] * n
a = []
for i in range(k):
    for j in range(d[i]):
        a.append(a_k[i][j])
print(len(ans)-len(set(a)))

Measured memory_bytes: 9244
W,H,N=map(int,input().split())
xya=[list(map(int,input().split())) for _ in range(N)]

x_l=0
x_h=W
y_l=0
y_h=H

for i in xya:
    if i[2]==1 and x_l<i[0]:
        x_l=i[0]
    elif i[2]==2 and x_h>i[0]:
        x_h=i[0]
    elif i[2]==3 and y_l<i[1]:
        y_l=i[1]
    elif i[2]==4 and y_h>i[1]:
        y_h=i[1]

print(max(0,x_h-x_l)*max(0,y_h-y_l))

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

int N, e = 1;
void dfs(vector<char> &A) {
	if(A.size() == N) {
		for (int i = 0; i < N; i++) cout << A[i];
		cout << endl;
		return;
	}

	for (char v = 'a'; v <= *max_element(A.begin(), A.end())+1; v++)
	{
		A.push_back(v);
		dfs(A);
		A.pop_back();
	}
	
}
int main() {
	cin >> N;
	vector<char> A;
	A.push_back('a');
	dfs(A);
	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n; cin >> n;
	vector<pair<int, int>> vR;
	vector<pair<int, int>> vL;
	int L = 0;
	int R = 0;
	rep(i,n) {
		string s; cin >> s;
		int sn = s.size();
		int r = 0;
		int valr = 0;
		for(int i = 0; i < sn; ++i) {
			if(s[i] == ')') ++r;
			if(s[i] == '(') --r;
			if(r > 0) {
				valr += r;
				r = 0;
			}
		}
		int l = 0;
		int vall = 0;
		for(int i = sn - 1; i >= 0; --i) {
			if(s[i] == '(') ++l;
			if(s[i] == ')') --l;
			if(l > 0) {
				vall += l;
				l = 0;
			}
		}
		if(valr == 0 and vall == 0) continue;
		else if(valr == 0) L += vall;
		else if(vall == 0) R += valr;
		else {
			if(valr < vall) {
				vL.emplace_back(valr, vall);
			} else {
				vR.emplace_back(valr, vall);
			}
		}
	}
	int ans = L;
	sort(vL.begin(), vL.end());
	for(auto e : vL) {
		if(ans - e.first < 0) {
			cout << "No" << '\n';
			return 0;
		}
		ans += e.second - e.first;
	}
	sort(vR.begin(), vR.end());
	reverse(vR.begin(), vR.end());
	for(auto e : vR) {
		if(ans - e.first < 0) {
			cout << "No" << '\n';
			return 0;
		}
		ans += e.second - e.first;
	}
	ans -= R;
	if(ans == 0) {
		cout << "Yes" << '\n';
	} else {
		cout << "No" << '\n';
	}
	return 0;
}

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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,b1[105],b2[105],ans;
string s;
int main(){
	cin>>n;
	cin>>s;
	for(int i=1;i<n;i++){
		int cnt=0; string s1,s2;
		s1=s.substr(0,i);
		s2=s.substr(i,n-i);
		memset(b1,0,sizeof(b1));
		memset(b2,0,sizeof(b2));
		for(int i=0;i<s1.size();i++) if(!b1[s1[i]-'a']) b1[s1[i]-'a']=1;
		for(int i=0;i<s2.size();i++) if(!b2[s2[i]-'a']) b2[s2[i]-'a']=1;
		for(int i=0;i<26;i++) if(b1[i]&b2[i]) cnt++;
		ans=max(ans,cnt);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
a = [1] * (N+1)
for _ in range(M):
  x = int(input())
  a[x] = 0
# a[n] = 0 なら壊れている。1なら壊れていない。
dp = [0] * (N+1)
dp[0] = 1
if a[1] == 1:
  dp[1] = 1
for i in range(2, N+1):
  if a[i] == 0:
    pass
  else:
    dp[i] = (dp[i-1] + dp[i-2]) % 1000000007
print(dp[N])

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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/2;
const ll MOD = 1e9+7;
const double EPS=1e-12;

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;cin>>N;
  ll d[N];
  for(ll i=0;i<N;i++){
    cin>>d[i];
  }
  sort(d,d+N);
  cout<<d[N/2]-d[N/2-1]<<endl;
  return 0;
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

//const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

ll expo(ll x, ll n, ll mod)
{
	ll res=1;
	while(n)
	{
		if(n&1)
			res =(res*x)%mod;
		x =(x*x)%mod;
		n >>= 1;
	}
	return res;
}

int getMod(string &str, int n, int k)  
{    
    int res = 0;  
    int i = 0, j = n - 1;  
    while (i < n)  
    {  
  
        // If current bit is 1  
        if (str[j] == '1')  
        {  
  
            // Add the current power of 2  
            res += expo(2,i,k);  
            res %= k;  
        }  
        i++;  
        j--;  
    }  
    return res;  
}

void solve()
{
	int n;
	string x;
	cin>>n;
	cin>>x;
	int cnt=0;
	for(auto u:x) cnt+=(u=='1');
	if(cnt==0)
	{
		for(int i=1;i<=n;i++) cout<<1<<'\n';
		return;
	}
	int rem=-1,remm=-1;
	if(cnt!=n)
	rem=getMod(x,n,cnt+1);
	if(cnt>1)
	remm=getMod(x,n,cnt-1);
	for(int i=0;i<n;i++)
	{
		int mv=1;
		int newrem=-1;
		if(x[i]=='1')
		{
			if(cnt==1)
			{
				cout<<0<<'\n';
				continue;
			}
			newrem=(remm+cnt-1-expo(2,n-1-i,cnt-1))%(cnt-1);
			while(newrem!=0)
			{
				newrem=newrem%(__builtin_popcount(newrem));
				mv++;
			}
			cout<<mv<<'\n';
		}
		else
		{
			newrem=(rem+expo(2,n-1-i,cnt+1))%(cnt+1);
			while(newrem!=0)
			{
				newrem=newrem%(__builtin_popcount(newrem));
				mv++;
			}
			cout<<mv<<'\n';
		}
	}
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 3732
from itertools import combinations_with_replacement
n,m,q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]

nums = list(range(1, m+1))
ans = 0
for i in combinations_with_replacement(nums, n):
  t = 0
  for j in abcd:
    if i[j[1]-1] - i[j[0]-1] == j[2]:
      t += j[3]
  ans = max(ans, t)
print(ans)

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string Sa, Sb, Sc; cin >> Sa >> Sb >> Sc;
    int Ai = 0,  Bi= 0, Ci = 0;
    char tmp = 'a';
    while (1)
    {
        if (tmp=='a') {
            if (Ai==Sa.size()) {cout << 'A' << endl; break;}
            tmp = Sa[Ai], Ai++;
        }
        if (tmp=='b') {
            if (Bi==Sb.size()) {cout << 'B' << endl; break;}
            tmp = Sb[Bi], Bi++;
        }
        if (tmp=='c') {
            if (Ci==Sc.size()) {cout << 'C' << endl; break;}
            tmp = Sc[Ci], Ci++;
        }
    }
    return 0;
}


Measured memory_bytes: 3540
N,K=map(int, input().split())
D=list(map(int, input().split()))
use=[]
for i in range(10):
    if i not in D:
        use.append(i)
ans = ''

for n in list(map(int, list(str(N)))):
    if n > use[-1]:
        ans+=str(use[0])
    else:
        for i in use:
            if i >= n:
                ans+=str(i)
                break

if str(N)[0] < ans[0]:
    ans = ans[0]+str(use[0])*(len(ans)-1)

if N-int(ans) > 0:
    ans = str(use[0]) + str(use[0])*len(str(N)) if use[0]!=0 else str(use[1])+str(use[0])*len(str(N))



print(ans)



Measured memory_bytes: 3064
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;

fn main() {
    input! {
    n: usize,
    a: [usize; n]
    }
    let mut cul_2a = vec![0; 2 * n + 1];
    for i in 0..2 * n {
        cul_2a[i + 1] = a[i * 2 % n] + cul_2a[i];
    }
    for i in 0..n {
        let k = i / 2 + if i % 2 == 1 { n / 2 + 1 } else {0};
        let p = cul_2a[k + n / 2 + 1] - cul_2a[k];
        let m = cul_2a[k + n] - cul_2a[k + n / 2 + 1];
        print!("{} ", p - m);
    }
}



Measured memory_bytes: 5288
#include <bits/stdc++.h>
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define forr(i, a, b) for (int i = (int)(b); i >= (int)(a); --i)
#define sz(a) (int)((a).size())
 
using namespace std;

const int ooi = INT_MAX;
const long long ool = LLONG_MAX;
const int mod = 1e9 + 7;
const double PI = acos(-1);
 
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int a[500500];

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.precision(10); cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    string s;
    cin >> s;
    int n = sz(s);
    for1(i, n){
        if(s[i - 1] == '<') a[i] = max(a[i], a[i - 1] + 1);
    }
    ford(i, n){
        if(s[i] == '>') a[i] = max(a[i], a[i + 1] + 1);
    }

    i64 res = 0;
    forn(i, n + 1) res += 1ll * a[i];
    cout << res << endl;
}

Measured memory_bytes: 2844
#include <stdio.h>

int checkTri(int a,int b,int c){
	int l,s1,s2;
  
    if(a==b || b==c || c==a){
      return 0;
    }
  

  

  	if(a<=b && b<=c){
      l=c;s1=a;s2=b;
    }else if(a<=b && c<=b){
      l=b;s1=c;s2=a;
    }else if(a>b && a>c){
      l=a;s1=b;s2=c;
    }else{
      l=c;s1=a;s2=b;
    }
  
//   	printf("l :%d\n",l);
//  	printf("s1:%d\n",s1);
//  	printf("s2:%d\n",s2);
    
  	if(l<s1+s2){
      return 1;
    }else{
      return 0;
    }
}

int main(void){
  int i,j,k,N,L[100],ans=0;
  //入力部
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&L[i]);
  }
  
  //計算部
  for(i=0;i<N-2;i++){
    for(j=i+1;j<N-1;j++){
      for(k=j+1;k<N;k++){
        if( checkTri(L[i],L[j],L[k]) ){
//          printf("%d %d %d\n",L[i],L[j],L[k]);
//          printf("%d %d %d\n",i+1,j+1,k+1);
//          printf("\n");
          ans++;
        }
      }
    }
  }
  
  //出力部
  
  printf("%d",ans);
  
  return 0;
}

Measured memory_bytes: 2124
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int n,m,q,a[100],b[100],c[100],d[100],ans=0;
vector <int> v;
 
void dfs(int pos,int x)
{
	if(pos==n)
	{
		int res=0;
		rep(i,q) if(v[b[i]]-v[a[i]]==c[i]) res+=d[i];
		ans=max(ans,res);
		return;
	}
	for(int i=x;i<=m;i++)
	{
		v.push_back(i);
		dfs(pos+1,i);
		v.pop_back();
	}
}

int main(){
    cin >> n >> m >> q;
    rep(i,q)cin >> a[i] >> b[i] >> c[i] >> d[i];
    rep(i,q){
        a[i]--;b[i]--;
    }
    dfs(0,1);
    cout << ans << endl;
}

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

#define F first
#define S second

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

const int max_n = 111, inf = 1000111222;
const ll inff = 1000111222333444;

int n, d, a[max_n][max_n];

ll sqrdist(int i, int q) {
    ll ans = 0;
    for (int w = 0; w < d; ++w) {
        ans += (a[i][w] - a[q][w]) * (a[i][w] - a[q][w]);
    }
    return ans;
}

bool is_sqr(ll a) {
    ll b = sqrt(a);
    if (1LL * (b - 1) * (b - 1) == a || b * b == a || (b + 1) * (b + 1) == a) return true;
    return false;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n >> d;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int q = 0; q < d; ++q) {
            cin >> a[i][q];
        }
        for (int q = 0; q < i; ++q) {
            if (is_sqr(sqrdist(i, q))) {
                ++ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
from bisect import bisect_right
def main():
	N = int(input())
	L = list(map(int, input().split(" ")))
	L.sort()
	k = 0
	for i in reversed(range(2, N)):
		a = L[i]
		for j in reversed(range(1, i)):
			b = L[j]
			index = bisect_right(L, a-b, hi=j)
			k += j - index
	print(k)
if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
ans = 0
count = 0
for c in s:
    if c=="g":
        if count>0:
            ans += 1
            count -= 1
        else:
            count += 1
    else:
        if count>0:
            count -= 1
        else:
            ans -= 1
            count += 1
print(ans)
        

Measured memory_bytes: 73440
/*
[abc131] A - Security
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

string S;

bool solve() {
    char pc = '_';
    for (char c : S) {
        if (c == pc) {
            return false;
        }
        pc = c;
    }

    return true;
}

int main() {
    cin >> S;

    cout << (solve() ? "Good" : "Bad") << endl;

    return 0;
}


Measured memory_bytes: 256