akhauriyash/Code-Regression huggingface dataset:
N,M = map(int, input().split())
ans = 0
while not (N == 0 and M == 0):
 for i in range(1, N+1):
  for j in range(i+1, N+1):
   k = M - i - j
   if ( k > N): pass
   elif  k <= j : break
   else: ans += 1
 print(ans)
 ans = 0
 N,M = map(int, input().split())

Measured memory_bytes: 7712
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    int n,x,ans=0,ct=0;
    cin >> n >> x;
    vector<int> L(n);
    rep(i,n) cin >> L[i];

    rep(i,n+1){
        ans+=L[i];
        ct++;
        if(ans > x)
            break;
    }

    cout << ct << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

int main(){
   string s;
   cin >> s;
   cout << s[0];
   cout << s.size()-2;
   cout << s[s.size()-1] << endl;
   
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
	int X, Y, Z;
	cin >> X >> Y >> Z;
	cout << Z << " " << X << " " << Y <<endl;
  	

    
  	return 0;
}


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

#define ll long long 
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

int main()
{
      ll a,b,k;
      cin>>a>>b>>k;
      ll d=min(a,k);
      a-=d;
      k-=d;
      ll q=min(b,k);
      b-=q;
      k-=q;
      cout<<a<<" "<<b<<"\n";
      return 0;
}

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

Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  map<int,int> m;
  REP(i,N){
    int a;
    cin>>a;
    m[a]+=1;
  }
  lint ans=1;
  REP(j,2){
    auto i=m.rbegin();
    while(i!=m.rend()){
      if(i->second>=2){
        ans*=i->first;
        i->second-=2;
        break;
      }
      ++i;
      if(i==m.rend())ans=0;
    }

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


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

int main() 
{
	long long A,B,C;
	long long ans;
	cin >> A >> B >> C;
	long long mmin = min(A,min(B,C));
	long long mmin2;
	if(A%2 == 0 || B%2 == 0 || C%2 == 0) 
	{
		cout << 0 <<endl;
	} 
	else 
	{
		if(mmin==A) 
		{
			mmin2 = min(B,C);
		} 
		else if(mmin == B) 
		{
			mmin2 = min(A,C);
		} 
		else if(mmin == C)
		{
			mmin2 = min(A,B);
		}
		cout << mmin*mmin2;
	}
}

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


int main(){
	ll n,a[100000]={};
	cin>>n;
	rep(i,n){
	   cin>>a[i];
	}
	sort(a,a+n);
	n/=2;
	
	cout<<(a[n]-a[n-1])<<"\n";
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if (x-r >= 0 && x+r <= W && y-r >= 0 && y+r <= H) cout << "Yes";
    else cout << "No";
    cout << endl;

    return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    ll N,goukei = 0,hako;
    cin >> N;
    vector<ll> A(N);
    set<ll> ss;
    map<ll,ll> mpa;

    for(ll i = 0;i < N;i++){
        cin >> A.at(i);
        ss.insert(A.at(i));
    }

    for(auto x:ss){
        mpa[x] = 0;
    }

    for(ll i = 0;i < N;i++)
        mpa[A.at(i)]++;

    for(auto x:ss){
        if(mpa[x] >= x)
            goukei += mpa[x] - x;
        else
            goukei += mpa[x];
    }

    cout << goukei << endl;
}

Measured memory_bytes: 14424
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

typedef long long ll;
const int mod=1e9+7;

int main(){
	string s;
	int k;
	cin >> s >> k;
	set<char> is;
	set<string> sub;
	for(int i=0; i<s.size(); i++)
		is.insert(s[i]);
	for(auto itr=is.begin(); sub.size()<k; itr++){
		for(int i=0; i<s.size(); i++){
			if(s[i]==*itr){
				string tmp="";
				for(int j=0; i+j<s.size()&&j<k; j++){
					tmp+=s[i+j];
					sub.insert(tmp);
				}
			}
		}
	}
	auto itr=sub.begin();
	for(int i=2; i<=k; i++)itr++;
	cout << *itr << endl;
	return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i32,
        b: i32,
    }
    println!("{}",
        if a <= 8 && b <= 8 {"Yay!"} else {":("});
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "YES" : "NO");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int A, B, X;
  cin >> A >> B >> X;
  printYesNo(A <= X && X <= A + B);
  return 0;
}

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

import math
aS = math.ceil(a / 0.08)
al = math.floor((a + 1) / 0.08)
bs = math.ceil(b / 0.10)
bl = math.floor((b + 1) / 0.10)

flag = True
for i in range(10000):
    if aS <= i < al and bs <= i < bl:
        print(i)
        flag = False
        break
if flag:
    print(-1)


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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define fst first
#define snd second
using ll=long long;using pii=pair<int,int>;
using vb=vector<bool>;using vs=vector<string>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template<typename T>T read(){T t;cin>>t;return t;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){o<<'('<<p.fst<<", "<<p.snd<<')';return o;}

struct UnionFind {
  const int V; // 頂点数
  vector<int> par, rank, cnt; // 親の番号, 木の大きさ, 同じ親の頂点数
  UnionFind(int V) : V(V), par(V), rank(V), cnt(V) { init(); }

  // 初期化する
  void init() {
    for (int i = 0; i < V; i++) par[i] = i;
    fill(rank.begin(), rank.end(), 0);
    fill(cnt.begin(), cnt.end(), 1);
  }

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

  // x と y の属する集合を併合
  // 併合前は違う集合だったら true を返す
  bool unite(int x, int y) {
    if ((x = find(x)) == (y = find(y))) return false;
    cnt[y] = cnt[x] = cnt[x] + cnt[y];

    if (rank[x] < rank[y]) par[x] = y;
    else {
      par[y] = x;
      if (rank[x] == rank[y]) rank[x]++;
    }
    return true;
  }

  // x と y が同じ集合に属するか否か
  bool same(int x, int y) {
    return find(x) == find(y);
  }

  // x と同じ集合にいる頂点数を返す
  int count(int x) {
    return cnt[find(x)];
  }
};


void Main() {
  int n = read<int>();
  int k = read<int>();
  int l = read<int>();

  UnionFind uf1(n), uf2(n);

  rep(i, k) {
    int p = read<int>() - 1;
    int q = read<int>() - 1;
    uf1.unite(p, q);
  }
  rep(i, l) {
    int r = read<int>() - 1;
    int s = read<int>() - 1;
    uf2.unite(r, s);
  }

  map<pii, int> co;
  rep(i, n) {
    int g1 = uf1.find(i);
    int g2 = uf2.find(i);
    co[{g1, g2}]++;
  }

  rep(i, n) {
    int g1 = uf1.find(i);
    int g2 = uf2.find(i);
    cout << co[{g1, g2}] << endl;
  }
}
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }


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

int main() {

  int N,M;
  cin >> N >> M;

  int L,R;
  int left = 1,right = N;

  for(int i = 0; i < M;i++) {
    cin >> L >> R;
    left = max(left,L);
    right = min(R,right);
  }

if(right >= left) {
  cout << right - left + 1 << endl;
}else {
  cout << 0 << endl;
}
}

Measured memory_bytes: 256
import math 
D, G = map(int, input().split())
K = [list(map(int, input().split())) for _ in range(D)]
G //= 100
def settify(i):
  s = []
  t = []
  for j in range(D):
    if i % 2 == 0:
      t.append(j)
    else:
      s.append(j)
    i = i>>1
    
  return s,t

ans = 10**20  
for i in range(2**D):
  s, t = settify(i)
  pt = sum([K[j][0]*(j+1)+K[j][1]//100 for j in s])
  tmp = sum([K[j][0] for j in s])
  #print(pt, G)
  #print(t)
  while pt < G and t:
    #print(min(K[t[-1]][0]-1,math.ceil((G-pt)/(t[-1]+1))),t[-1])
    tmp += min(K[t[-1]][0]-1,math.ceil((G-pt)/(t[-1]+1)))
    pt += min(K[t[-1]][0]-1,math.ceil((G-pt)/(t[-1]+1)))*(t[-1]+1)
    t.pop()
  #print(tmp,s,pt) 
  if pt < G:
    continue
  ans = min(ans, tmp)
    
print(ans)
    

  
  

Measured memory_bytes: 69556
#include <cstdio>
#include <algorithm>
//dp[i%2][j]=100i点問題まで手をつけたときにちょうど100j点もらえるような問題数の最小値
int dp[2][105501];
int const infty=10000;
int main(){
	int d,g,p,c;
	scanf("%d%d",&d,&g);
	g/=100;
	for(int i=0;i<=105500;i++){
		dp[0][i]=infty;
		dp[1][i]=infty;
	}
	dp[0][0]=0;
	for(int i=1;i<=d;i++){
		scanf("%d%d",&p,&c);
		c/=100;
		for(int j=0;j<=105500;j++){
			if(dp[(i-1)%2][j]<infty){
				for(int k=0;k<p;k++){
					dp[i%2][j+i*k]=std::min(dp[i%2][j+i*k],dp[(i-1)%2][j]+k);
				}
				dp[i%2][j+i*p+c]=std::min(dp[i%2][j+i*p+c],dp[(i-1)%2][j]+p);
			}
		}
	}
	int ans=infty;
	for(int i=g;i<=105500;i++){
		ans=std::min(ans,dp[d%2][i]);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int N;
	vector<int> kushi;
	cin >> N;
	N *= 2;
	kushi.resize(N);
	int minNum[2] = { 0, 0 };
	for (int n = 0; n < N; n++) {
		cin >> kushi[n];
	}

	sort(kushi.begin(), kushi.end());
	int sum = 0;

	for (int n = 0; n < N; n += 2) {
		sum += kushi[n + 1] - abs(kushi[n] - kushi[n + 1]);
	}
	cout << sum << endl;
	return 0;
}

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

using namespace std;

int main(void) {
  int N; cin >> N;
  vector<int> A;

  for (int i = 0; i < N; i++) {
    int a; cin >> a;
    A.push_back(a);
  }
  if (N&1) {
    A.push_back(0);
    N++;
  }

  sort(A.begin(), A.end(), greater<int>());

  int ans = 0;
  for (int i = 0; i < N/2; i++) {
    ans += A[2*i] - A[2*i + 1];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
/* 163-A.cpp
 *     Created on : Apr 19, 2020 
 *     Time       : 5:57:48 PM
 *     Author     : null_ptr
 */
#include<bits/stdc++.h>

using namespace std;

const double pi=acos(-1);

int main()
{
	int n;
	cin>>n;
	cout<<setprecision(9)<<fixed<<(pi*2.0*n);
}


Measured memory_bytes: 3784
import re
while 1:
	n,m = map(int,raw_input().split())
	if n == m == 0: break
	R = [0]*n
	for i in range(n):
		p,s,d = raw_input().replace("?","[0-9]").split()
		R[i] = [re.compile(s+d), 1 if p[0] == "p" else 0]
	ans = []
	for i in range(m):
		s,d,name = raw_input().split()
		for r,p in R[::-1]:
			if r.search(s+d):
				if p:ans.append([s,d,name])
				break
	print len(ans)
	for s,d,name in ans:
		print s,d,name

Measured memory_bytes: 5456
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

template<class T> inline bool chmin(T& a,T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if (a < b) {a = b; return true;} return false;}

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int A, B; cin >> A >> B;

  int ans = 0;
  int n_tap = 1;
  while(1){
    if (n_tap >= B) break;
    n_tap += A - 1;
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin>>s;
	if(s[0]==s[1]&&s[0]==s[2]) cout<<"No\n";
	else cout<<"Yes\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//F6編譯，右上三角形執行，ctrl+c強制停止執行  F5開啟exe
#define ll long long
#define maxn 100005
#define mod 1000000007
using namespace std;

typedef pair<int, int> P;

int n;
vector<P> v[20];

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        for (int j = 0; j < a; j++)
        {
            int x, y;
            cin >> x >> y;
            x--;
            v[i].push_back(P(x, y));
        }
    }
    int ans = 0;
    for (int S = 0; S < (1 << n); S++)
    {
        bitset<20> b = S;
        bool ok = 1;
        for (int i = 0; i < n; i++)
        {
            if (b[i] == 0)
                continue;
            for (P p : v[i])
            {
                int x = p.first;
                int y = p.second;
                if (b[x] != y)
                    ok = 0;
            }
        }
        if (ok)
            ans = max(ans, (int)b.count());
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
template<typename T> inline void debug(const vector<T> &xs){
#ifdef DEBUG
	pr(xs);
#endif
}

struct mint {
	typedef long long ll;
	ll x, m;
	mint(ll x=0, ll m=1e9+7): x(x%m), m(m) {}
	mint operator-() const { return mint(m-x, m); }
	mint operator+(const mint o) const { return mint(x+o.x, m); }
	mint operator-(const mint o) const { return mint(x-o.x+m, m); }
	mint operator*(const mint o) const { return mint(x*o.x, m); }
	mint& operator+=(const mint o) { x = (x+o.x)%m; return *this; }
	mint& operator-=(const mint o) { x = (x-o.x+m)%m; return *this; }
	mint& operator*=(const mint o) { x = x*o.x%m; return *this; }
	bool operator==(const mint o) const { return x==o.x; }
	bool operator!=(const mint o) const { return x!=o.x; }
	template<typename T> mint& operator=(const T o) { x = o%m; return *this; }
	template<typename T> mint operator+(const T o) const { return mint(x+o, m); }
	template<typename T> mint operator-(const T o) const { return mint(x-((ll)o)%m+m, m); }
	template<typename T> mint operator*(const T o) const { return mint(x*o, m); }
	template<typename T> mint& operator+=(const T o) { x = (x+(ll)o%m)%m; return *this; }
	template<typename T> mint& operator-=(const T o) { x = (x-((ll)o)%m+m)%m; return *this; }
	template<typename T> mint& operator*=(const T o) { x = x*((ll)o%m)%m; return *this; }
	template<typename T> bool operator==(const T o) const { return x==o%m; }
	template<typename T> bool operator!=(const T o) const { return x!=o%m; }

	mint pow(ll k) const {
		if(k==0) return mint(1, m);
		if(k%2) return pow(k-1)*x;
		mint z = pow(k/2);
		return z*z;
	}

	mint inv() const { return pow(m-2); }
};

int main(){
	int N;
	string S;
	cin >> N >> S;

	mint ans(1);
	int cur = 0;
	for(int i=0; i<2*N; i++){
		if(cur%2==0){
			if(S[i]=='B') cur++;
			else {
				if(cur==0) {
					cout << 0 << endl;
					return 0;
				} else {
					ans *= cur;
					cur--;
				}
			}
		} else {
			if(S[i]=='W') cur++;
			else {
				if(cur==0) {
					cout << 0 << endl;
					return 0;
				} else {
					ans *= cur;
					cur--;
				}
			}
		}
		debug(any{cur, ans.x});
	}
	if(cur > 0){
		cout << 0 << endl;
		return 0;
	}

	for(int i=0; i<N; i++){
		ans *= i+1;
	}

	cout << ans.x << endl;

	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int N=1e7+5,mod=998244353;
typedef long long ll;
ll f[N],invf[N],p[N];
int n;
ll C(ll n,ll m)
{
    return f[n]*invf[n-m]%mod*invf[m]%mod;
}
ll qpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans;
}
int main()
{
    f[0]=p[0]=f[1]=invf[0]=invf[1]=1;
    for(int i=2;i<N;i++)
    {
        f[i]=f[i-1]*i%mod;
        invf[i]=(mod-mod/i)*invf[mod%i]%mod;
    }
    for(int i=2;i<N;i++) invf[i]=invf[i]*invf[i-1]%mod;
    for(int i=1;i<N;i++) p[i]=p[i-1]*2%mod;
    int n;scanf("%d",&n);
    ll ans=qpow(3,n),res=0;
    for(int i=n/2+1;i<=n;i++)
        res=(res+C(n,i)*p[n-i])%mod;
    ans=(ans-res*2)%mod;
    ans=(ans+mod)%mod;
    printf("%lld\n",ans);
}


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

public class Main {

    public static void main(String[] args) {
        Scanner in=new Scanner (System.in);
        PrintWriter out=new PrintWriter(System.out);
        TreeSet<Integer> set=new TreeSet<>();
        int q=Integer.parseInt(in.next());
        for(int i=0;i<q;i++) {
            int odr=Integer.parseInt(in.next());

            switch(odr) {
            case 0:
            	int x0=Integer.parseInt(in.next());
            	if(!set.contains(x0)) set.add(x0);
            	out.println(set.size());
            	break;

            case 1:
            	int x1=Integer.parseInt(in.next());
            	out.println(set.contains(x1)? 1:0);
            	break;
            	
            case 2:
            	int x2=Integer.parseInt(in.next());
            	set.remove(x2);
            	break;
            }

        }
        out.flush();
    }

}


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

int main(){

  int a, b; cin >> a >> b;
  int ans = a * b;
  if(ans % 2 == 0) cout << "Even" << endl;
  else cout << "Odd" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int A[100005];
int dot[100005];

int main() {

	int N;

	scanf("%d",&N);

	int i;

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

	i = 0;

	while (1) {
		if (i >= N - 1) { break; }

		int cnt = 0;
		int start;
		while (1) {
			if (i >= N - 1) { break; }
			if (cnt == 0) {
				if (A[i] < A[i + 1]) {
					start = 0;
				}
				else if (A[i] > A[i + 1]) {
					start = 1;
				}
				else {
					while (1) {
						if (i >= N - 1 || A[i] != A[i + 1]) { break; }
						i++;
					}

					if(i<N-1){
						if (A[i] < A[i + 1]) {
							start = 0;
						}
						else if (A[i] > A[i + 1]) {
							start = 1;
						}
					}

				}
			}
			else {
				if (start == 0 && A[i] > A[i+1]) {
					dot[i] = 1;
					i++;
					break;
				}
				if (start == 1 && A[i] < A[i + 1]) {
					dot[i] = 1;
					i++;
					break;
				}
			}
			cnt++;
			i++;
		}


	}

	int ans = 1;
	for (i = 0; i < N - 1; i++) {
		if (dot[i] == 1) { ans++; }
	}

	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 896
#include<cstdio>
    #include<cstring>
    #include<iostream>
    using namespace std;
    int main()
    {
    	int N,K;
    	ios::sync_with_stdio(false);
    	cin>>N>>K;
    	int t=1;
    	int ans=1;
    	for(int i=0;i<N;i++)
    	{
    		if(K>t)
    		{ 
    			ans+=t;
    			t=t*2;
    		}
    		else 
    		{
    			ans+=K;
    		}
    	}
    	cout<<ans<<endl;
    	return 0;
    }

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

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



// Main Code

int main()
{
  double x, y;
  cin>>x>>y;
  cout<<round((x+y)/ 2)<<endl;
}


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

int main() {
  int H,N;
  int sum = 0;
  cin >> H >> N;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    sum += A;
  }
  if (sum >= H)
    cout << "Yes";
  else
    cout << "No";
  cout << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;

class Problem {
    private int N;
    private int M;
    private int[] As;

    Problem() {
        Scanner sc = new Scanner(System.in);

        N = sc.nextInt();
        M = sc.nextInt();

        As = new int[M];
        for (int i = 0; i < N; i++) {
            int K = sc.nextInt();
            for (int k = 0; k < K; k++) {
                int A = sc.nextInt();
                As[A-1] += 1;
            }
        }
    }

    int solve() {
        int ans = 0;
        for (int i = 0; i < M; i++){
            if (As[i] == N){
                ans += 1;
            }
        }
        return ans;
    }
}

public class Main {
    public static void main(String[] args) {
        System.out.println(new Problem().solve());
    }
}


Measured memory_bytes: 22612
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define inf LLONG_MAX>>2
#define MAX 1000000
#define mod 1000000007
#define pb push_back
#define f(i,a,n,x) for ((i)=(a);(i)<(n);(i)+=(x))
#define fd(i,a,n,x) for ((i)=(a);(i)>=(n);(i)-=(x))
#define fi first
#define se second
#define mk make_pair
#define pi pair
#define vt vector
#define ms multiset
#define is insert
using namespace std;
void read(vt<ll> &a,ll n){ll i,temp;f(i,0,n,1){cin>>temp;a.pb(temp);}}
ll fa[MAX];
ll power(ll p,ll q){
    ll res=1;
    p%=mod;
    while(q){
        if (q&1)
            res=(res*p)%mod;
        q>>=1;
        p=(p*p)%mod;
    }
    return res;
}
ll fact(ll n){
    if (n<=1)
        return fa[n]=1;
    if (fa[n])
        return fa[n];
    return fa[n]=(n*fact(n-1))%mod;
}
ll ncr(ll n,ll r){
    if (!r)
        return 1;
    return (((fact(n)*power(fact(n-r),mod-2))%mod)*power(fact(r),mod-2))%mod;
}
void solve(){
    ll n,i,n1,j,count=0;
    vt<ll> a;
    cin>>n;
    if (n==2){
        cout<<1<<endl;
        return;
    }
    n1=n;
    for (i=2;i*i<=(n-1);i++)
        if (!((n-1)%i))
            if ((n-1)/i==i)
                count++;
            else
                count+=2;
    count++;
    for (i=2;i*i<=n;i++)
        if (!(n%i))
            if (n/i==i)
                a.pb(i);
            else{
                a.pb(i);
                a.pb(n/i);
            }
    a.pb(n);
    f(i,0,a.size(),1){
        n1=n;
        while(!(n1%a[i]))
            n1/=a[i];
        if (n1%a[i]==1)
            count++;
    }
    f(j,0,12000000,1);
    cout<<count<<endl;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            String s = sc.next();
            if (s.equals("-")) {
                break;
            }
            int time = sc.nextInt();
            for (int i = 0; i < time; i++) {
                int shuffle = sc.nextInt();
                s = s.substring(shuffle) + s.substring(0, shuffle);
            }
            System.out.println(s);
        }
    }
}

Measured memory_bytes: 26296
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll H, W, N, sr, sc;
    cin >> H >> W >> N >> sr >> sc;
    string S, T;
    cin >> S >> T;

    string dir = "LRUD";
    string r_dir = "RLDU";

    bool ans = true;

    {
        //右に出る
        ll x = sc;
        for (ll i = 0; i < N; i++) {
            if (S[i] == 'R') {
                if (++x > W) {
                    ans = false;
                }
            }
            if (T[i] == 'L' && x > 1) {
                x--;
            }
        }
    }
    {
        //左に出る
        ll x = sc;
        for (ll i = 0; i < N; i++) {
            if (S[i] == 'L') {
                if (--x <= 0) {
                    ans = false;
                }
            }
            if (T[i] == 'R' && x < W) {
                x++;
            }
        }
    }
    {
        //上に出る
        ll y = sr;
        for (ll i = 0; i < N; i++) {
            if (S[i] == 'U') {
                if (--y <= 0) {
                    ans = false;
                }
            }
            if (T[i] == 'D' && y < H) {
                y++;
            }
        }
    }
    {
        //下に出る
        ll y = sr;
        for (ll i = 0; i < N; i++) {
            if (S[i] == 'D') {
                if (++y > H) {
                    ans = false;
                }
            }
            if (T[i] == 'U' && y > 1) {
                y--;
            }
        }
    }

    cout << (ans ? "YES" : "NO") << endl;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
using namespace std;
int main(){
    long long a,b,k;
    cin>>a>>b>>k;
    f(i,a,b+1){
        if(i-a+1<=k||b-k+1<=i){
            cout<<i<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3440
#include <iostream>
#include <vector>
#include <string>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

int main(){

    bool firstope = 0;
    vector<int> num(3);
    vector<bool> pari(3);
    
    REP(i,3){
        cin >> num[i];
    }

    
    {
        int tmp;

        if(num[0]>num[1]){
            tmp = num[1];
            num[1] = num[0];
            num[0] = tmp;
        }
        if(num[1]>num[2]){
            tmp = num[2];
            num[2] = num[1];
            num[1] = tmp;
        }
        if(num[0]>num[1]){
            tmp = num[1];
            num[1] = num[0];
            num[0] = tmp;
        }
    }

    REP(i,3){
        pari[i] = num[i] % 2;
    }
    

    if(pari[0]!=pari[1]){
        if(pari[0]==pari[2]){
            firstope=1;
            num[0]++;
            num[2]++;
        }else if(pari[1]==pari[2]){
            firstope=1;
            num[1]++;
            num[2]++;
        }
    }
    

    cout<<firstope+(num[2]-num[1])+((num[1]-num[0])/2)<<endl;

    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
//#define int unsigned long long
#define all(x) (x).begin(), (x).end()
#define double long double

using namespace std;

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

int MOD = 1e9 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;


multiset<int>mada;
int A[100020];
priority_queue<int, vector<int>, greater<int>>que;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N; cin >> N;
	REP(i, N) {
		cin >> A[i];
		//mada.insert(A[i]);
	}
	mada.insert(INF);
	mada.insert(-INF);
	int cnt = 0;
	que.push(A[0]);
	REP(i, N) {
		auto itr = mada.lower_bound(A[i]);
		itr--;
		if (itr == mada.begin()) {
			cnt++;
			mada.insert(A[i]);
		}
		else {
			mada.erase(itr);
			mada.insert(A[i]);
		}
	}
	print(cnt);
}


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

int main() {
    std::size_t n{};
    std::cin >> n;
    std::vector<int> ds(n, 0);
    for(std::size_t i = 0; i < n; ++i)
        std::cin >> ds[i];
    std::sort(std::begin(ds), std::end(ds));
    const auto m = ds.size() / 2;
    const auto c = ds[m] - ds[m - 1];
    std::cout << c << std::endl;
    return 0;
}

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

const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    int N;
    cin >> N;
    vector<ll> A(N), S(N);
    for (int i=0; i<N; ++i) {
        cin >> A[i];
        S[i] = i + 1 + A[i];
    }
    sort(S.begin(), S.end());

    ll cnt = 0;
    for (int i=0; i<N; ++i) {
        auto it_1 = lower_bound(S.begin(), S.end(), (i+1) - A[i]);
        auto it_2 = upper_bound(S.begin(), S.end(), (i+1) - A[i]);
        cnt += it_2 - it_1;
        if (S[i] == (i+1) - A[i]) cnt --;
    }
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 6424
def cut_and_count(N: int, S: str) -> int:
    l, r = {}, {}
    for c in S:
        if c not in r:
            r[c] = 1
        else:
            r[c] += 1

    max_len = 0
    for c in S:
        if c not in l:
            l[c] = 1
        else:
            l[c] += 1
        r[c] -= 1

        ls = set(k for k, v in l.items() if v > 0)
        rs = set(k for k, v in r.items() if v > 0)

        temp = len(ls & rs)
        max_len = max(max_len, temp)

    return max_len


if __name__ == "__main__":
    N = int(input())
    S = input()
    ans = cut_and_count(N, S)
    print(ans)


Measured memory_bytes: 3064
from collections import deque

h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
direction = [(1, 0), (0, 1), (-1, 0), (0, -1)]

max_step = 0
for i in range(h):
    for j in range(w):
        largest_step = 0
#        print("start: ", i, j)
        if maze[i][j] == "#":
            continue
        visited = [[False] * w for _ in range(h)]
        plan = deque()
        step = 1
        plan.appendleft((i, j, step))
        visited[i][j] = True
        while plan:
            y, x, step = plan.pop()
            for next_direction in direction:
                next_y = y + next_direction[0]
                next_x = x + next_direction[1]
                if -1 == next_x or next_x == w or -1 == next_y or next_y == h or maze[next_y][next_x] == "#" or visited[next_y][next_x]:
                    continue
                visited[next_y][next_x] = True
                if step > largest_step:
                    largest_step = step
                plan.appendleft((next_y, next_x, step + 1))
        if largest_step > max_step:
            max_step = largest_step

print(max_step)


Measured memory_bytes: 45532
a,b,c,d = list(input())
a = int(a)
b = int(b)
c = int(c)
d = int(d)

def plus(x,y):
    return x+y

def minus(x,y):
    return x-y

pm_list = [plus,minus]
print_list = ["+","-"]

for i,method in enumerate(pm_list):
#     print("1;",i,method)
    goukei1 = method(a,b)
    for j,method2 in enumerate(pm_list):
#         print("2;",j,method2)
        goukei2 = method2(goukei1,c)
        for k,method3 in enumerate(pm_list):
#             print("3;",k,method3)
            goukei3 = method3(goukei2,d)
            
            if goukei3 == 7:
                kw = str(a)+print_list[i]+str(b)+print_list[j]+str(c)+print_list[k]+str(d)+"=7"
                print(kw)
                break
        if goukei3 ==7:
            break
            
    if goukei3 ==7:
        break


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

template <typename T, const T id>
class convex_hull_trick {
	struct line {
		T a, b;
		line(T a_ = 0, T b_ = 0) : a(a_), b(b_) {}
		T get(T x) const { return a * x + b; }
	};
	const int n;
	const vector<T> pos;
	vector<line> data;
	void modify(int p, int lb, int ub, line& l) {
		if (data[p].a == id) {
			data[p] = l;
			return;
		}
		if (data[p].get(pos[lb]) >= l.get(pos[lb]) && data[p].get(pos[ub]) >= l.get(pos[ub])) return;
		if (data[p].get(pos[lb]) <= l.get(pos[lb]) && data[p].get(pos[ub]) <= l.get(pos[ub])) {
			data[p] = l;
			return;
		}
		int c = (lb + ub) >> 1;
		if (data[p].get(pos[c]) < l.get(pos[c])) swap(data[p], l);
		if (data[p].get(pos[lb]) <= l.get(pos[lb]))
			modify(p << 1, lb, c, l);
		else
			modify((p << 1) | 1, c + 1, ub, l);
	}
	T sub(int p, int lb, int ub, int t) const {
		if (data[p].a == id) return id;
		if (ub - lb == 0) return data[p].get(pos[t]);
		int c = (lb + ub) >> 1;
		if (t <= c) return max(data[p].get(pos[t]), sub(p << 1, lb, c, t));
		return max(data[p].get(pos[t]), sub((p << 1) | 1, c + 1, ub, t));
	}
public:
	convex_hull_trick(const vector<T>& pos_) : n(pos_.size()), pos(pos_), data(n << 2, line(id, id)) {}
	void insert(T a, T b) {
		line l(a, b);
		modify(1, 0, n - 1, l);
	}
	T get(T x) const {
		int t = lower_bound(pos.begin(), pos.end(), x) - pos.begin();
		assert(t < n && pos[t] == x);
		return sub(1, 0, n - 1, t);
	}
};

int main()
{
	int N;
	ll C;
	cin >> N >> C;
	vector<ll> h(N);
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	auto hs = h;
	sort(hs.begin(), hs.end());
	hs.erase(unique(hs.begin(), hs.end()), hs.end());
	convex_hull_trick<ll, LLONG_MIN> cht(hs);
	vector<ll> dp(N);
	cht.insert(h[0] * 2, -h[0] * h[0]);
	for (int i = 1; i < N; i++) {
		dp[i] = -cht.get(h[i]) + h[i] * h[i] + C;
		cht.insert(h[i] * 2, -(dp[i] + h[i] * h[i]));
	}
	cout << dp.back() << endl;
	return 0;
}


Measured memory_bytes: 18944
while True:
    try:
        N = int(input())
        A = list(map(int, input().split()))
        B = list(map(int, input().split()))
        C = list(map(int, input().split()))
        A.insert(0, 0)
        B.insert(0, 0)
        C.insert(0, 0)
        
        res = B[A[1]]
        for i in range(2, len(A)):
            res += B[A[i]]
            if A[i-1]+1 == A[i]:
                res += C[A[i-1]]
        print(res)
    except:
        break

Measured memory_bytes: 3064
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
    string a;
    int sum=0;
    cin>>a;
    for(int i=1;i<a.length();i++){
        if(a[i]!=a[i-1]){
            sum++;
        }
    }
    cout<<sum<<endl;
}

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

int main() {
	int n;
	cin >> n;
	int a[n];

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

	for (int i = 0; i < n; i++) {
		cout << a[n - 1 - i] ;
		if (i != n - 1)	cout << " ";
	}

	cout << endl;
	return 0;
}

Measured memory_bytes: 1160
void main() {
	auto ip = readAs!(int[]), a = ip[0], b = ip[1];
	if(a < b) writeln("a < b");
	else if(a > b) writeln("a > b");
	else writeln("a == b");
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 2448
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
flag=0
ky=abs(a-b)
if b==a:
    flag=1
elif w>=v:
    pass
elif abs((b-a)/(v-w))<=t:
    flag=1
if flag==1:
    print('YES')
else:
    print('NO')

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

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

	int count = 0;
	for (int i = 1; i <= N; i++) {
		string n_str = to_string(i);
		if (n_str.length() % 2 == 1) {
			count++;
		}
	}

	cout << count << endl;
}






Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }

int n;
V<int> p;
VV<int> g;

array<int, 2> chk(const V<int> &a, int v) {
    set<int> s;
    for (int d: g[v]) s.insert(a[d]);
    array<int, 2> ans;
    int u = 0;
    while (s.count(u)) u++;
    ans[0] = u;
    u++;
    while (s.count(u)) u++;
    ans[1] = u;
    return ans;
}

V<int> pre(const V<int> &b) {
    V<int> a = b;
    queue<int> q;
    V<ll> deg = V<ll>(n);
    for (int i = 0; i < n; i++) {
        if (a[i] != -1) continue;
        for (int d: g[i]) if (a[d] == -1) deg[i]++;
        if (deg[i] == 0) {
            q.push(i);
        }
    }
    while (!q.empty()) {
        int v = q.front(); q.pop();
        a[v] = chk(a, v)[0];
        if (a[p[v]] != -1) continue;
        deg[p[v]]--;
        if (!deg[p[v]]) q.push(p[v]);
    }
    return a;
}

bool solve() {
    scanf("%d", &n);
    p = V<int>(n);
    g = VV<int>(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &(p[i])); p[i]--;
        g[p[i]].push_back(i);
    }
    auto a = pre(V<int>(n, -1));
    int v = -1;

    for (int i = 0; i < n; i++) {
        if (a[i] == -1) {
            v = i;
            break;
        }
    }
    
    auto p = chk(a, v);
    a[v] = p[0];
    if (chk(pre(a), v)[0] == a[v]) {
        return true;
    }
    a[v] = p[1];
    if (chk(pre(a), v)[0] == a[v]) {
        return true;
    }
    return false;
}

int main() {
    if (!solve()) {
        cout << "IM";
    }
    cout << "POSSIBLE" << endl;
}


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

const int N = 2e5 + 5, mod = 1e9+7;
int n, c[N], dp[N], last[N];


int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n;
    int cnt = 1, temp;
    for (int i = 1; i <= n; i++){
        cin>>temp;
        if(temp!=c[cnt-1]){
            c[cnt++] =temp;
        }
    }
    
    
    dp[0] = 1;
    for (int i = 1; i < cnt; i++){
        dp[i] = dp[i-1];
        if(last[c[i]]!=0)(dp[i] += dp[last[c[i]]])%=mod;
        last[c[i]] = i;
    }
    cout<<dp[cnt-1]<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 2560
def p_num(n,x):
    #print("_",n,x)

    m = 2**(n+1)-1
    #print("m",m,2*m-1)

    if n==0:
        return 1
    else:
        if x==1:
            return 0
        elif x==2*m-1:
            return m
            
        if x < m:
            #print("::1")
            return p_num(n-1, x-1)
        elif x > m:
            #print("::2")
            return (m-1)//2 + 1 + p_num(n-1, x-m)
        else:
            #print("::3")
            return (m-1)//2 + 1


n, x = map(int, input().split())

print(p_num(n,x))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define PI 3.141592653
  
float circumference(double r) 
{ 
    float cir = 2*PI*r; 
    return cir; 
} 
  
int32_t main() 
{
      double r;
      cin>>r;
      cout<<circumference(r);
      
	return 0;
}


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

bool d[266];

int main() {
	char s[1055];

	scanf("%s", s);

	int n = strlen(s);

	for (int i = 0; i < n; i++) d[s[i]] = true;

	if ((d['N'] ^ d['S']) || (d['W'] ^ d['E'])) {
		puts("No");
		return 0;
	}

	puts("Yes");

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<int> v(N);
  int sum = 0;
  rep(i,N){
    cin >> v[i];
    sum+=v[i];
  }
  int M;cin >> M;
  rep(i,M){
    int j,x;cin >> j >> x;
    --j;
    cout << sum - v[j] + x << endl;
  }
  return 0;
}


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

using namespace std;

int main()
{
  int N, Command, Val;
  string Key, LB, UB; 
  cin >> N;

  multimap<string, int> MultiMap;

  for(int i = 0; i < N; ++i)
  {
    cin >> Command >> Key;

    if(Command == 0)
    {
      cin >> Val;   
      //MultiMap[Key] = Val;
      MultiMap.insert(make_pair(Key, Val));
    }
    else if(Command == 1)
    {
      auto ite1 = MultiMap.lower_bound(Key);
      auto ite2 = MultiMap.upper_bound(Key);

      while(ite1 != ite2)
      {
	cout << ite1->second << endl;
	++ite1;
      }
    }
    else if(Command == 2)
    {
      auto ite1 = MultiMap.lower_bound(Key);
      auto ite2 = MultiMap.upper_bound(Key);
      MultiMap.erase(ite1, ite2); 
    }
    else if(Command == 3)
    {
      LB = Key;
      cin >> UB;

      auto ite1 = MultiMap.lower_bound(LB);
      auto ite2 = MultiMap.upper_bound(UB);

      while(ite1 != ite2)
      {
	cout << ite1->first << " " << ite1->second << endl;
	++ite1;
      }
 

    }


  
  }

  return 0;
}


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

int main()
{
    int n;cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int ans=0;
    for(int i=1;i<n-1;i++)
        if((a[i]>a[i-1]&&a[i]<a[i+1])||(a[i]<a[i-1]&&a[i]>a[i+1]))
            ans++;
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,k,t,x[100005],y[100005],cnt[2005];
char c[100005];
int main()
{
	cin>>n>>k;t=k<<1;
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i]>>c[i];
		x[i]%=t;
		y[i]%=t;
	}
	int ans=0;
	for(int i=0;i<t;i++){
		int cur=0;
		memset(cnt,0,sizeof(cnt));
		for(int j=0;j<n;j++){
			int f=((x[j]-i<0?x[j]-i+t:x[j]-i)<k);
			if(f^(y[j]<k))cur+=c[j]=='B';
			else cur+=c[j]=='W';
			cnt[y[j]]+=(f^(c[j]=='W'))?1:-1;
		}
		for(int j=0;j<t;j++){
			ans=max(ans,cur);
			cur+=cnt[j]-cnt[(j+k)%t];
		}
	}
	cout<<ans;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
string ds="NESW";
int H,W,L;
char fld[111][111];

int T[111][111][4];

signed main(){
    while(cin>>H>>W>>L,W||H||L){
        rep(i,H)cin>>fld[i];
        memset(T,-1,sizeof(T));
        int y,x,d;
        rep(i,H)rep(j,W){
            if(fld[i][j]!='.'&&fld[i][j]!='#'){
                y=i;x=j;
                d=find(all(ds),fld[i][j])-ds.begin();
            }
        }

        T[y][x][d]=0;
        while(true){
            int ny,nx,nd=d;
            while(true){
                ny=y+dy[nd],nx=x+dx[nd];
                if(ny>=0&&ny<H&&nx>=0&&nx<W&&fld[ny][nx]!='#')break;
                nd=(nd+1)%4;
            }
            int c=T[y][x][d]+1;
            if(c==L){
                cout<<ny+1<<" "<<nx+1<<" "<<ds[nd]<<endl;
                break;
            }
            if(T[ny][nx][nd]!=-1){
                L-=T[ny][nx][nd];
                int t=c-T[ny][nx][nd];
                L%=t;
                L+=T[ny][nx][nd];
                rep(i,H)rep(j,W)rep(k,4){
                    if(T[i][j][k]==L){
                        cout<<i+1<<" "<<j+1<<" "<<ds[k]<<endl;
                    }
                }
                break;
            }
            T[ny][nx][nd]=c;
            y=ny;x=nx;d=nd;
        }
    }
    return 0;
}

Measured memory_bytes: 3492