akhauriyash/Code-Regression huggingface dataset:
#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,K;cin >> N >> K;
  vector<int> v(N+2,0);
  v[0] = 1;
  int sum = 0;
  rep(i,N){
    char x;cin >> x;
    if(x=='L') v[i+1] = 0;
    if(x=='R') v[i+1] = 1;
  }
  rep(i,N){
    if(v[i+1] == 0 && v[i] == 0)++sum;
    if(v[i+1] == 1 && v[i+2] == 1)++sum;
  }
  sum += 2*K;
  cout << min(sum,N-1) << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// const ll INF = 1LL <<60;
// const int INF = 10000;

//最大公約数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

const int MAX = 1e6+1;
const int MOD = 1e9+7;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}

long long modpow(long long res,long long a, long long n, long long mod) {
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}
// ここから開始
int main(){
  int n,m;
  cin>>n>>m;
  cout<<(m*1900+(n-m)*100)*pow(2,m)<<endl;
  return 0;
}



Measured memory_bytes: 256
///بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.0)
int main()
{
     ios_base::sync_with_stdio(false);cin.tie(NULL);
     ll int i,n,t,p=INT_MAX,j=0,x,a=0,b,l=1,r=0,y,k,c,sum=0,m,d;
     cin>>n;
     int ara[n]={0};
     for(i=0;i<n-1;i++){
        cin>>p;
        ara[p-1]++;

     }
     for(i=0;i<n;i++){
        cout<<ara[i]<<endl;
     }

     return EXIT_SUCCESS;
}



Measured memory_bytes: 4388
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int>v(n);
	for(int i=0;i<n;++i){
		cin>>v[i];
	}
	int q;
	cin>>q;
	vector<int>w(q);
	for(int i=0;i<q;++i){
		cin>>w[i];
	}
	sort(v.begin(),v.end());
	int ans=0;
	for(int i=0;i<q;++i){
		int left=0,right=v.size();
		while(true){
			if(left == right) break;
			int mid = (left+right)/2;
			if(v[mid] < w[i]) left = mid+1;
			else if(v[mid] > w[i]) right = mid;
			else{
				++ans;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3328
#pragma region Include
#include <bits/stdc++.h>
#pragma endregion

using namespace std;

#pragma region Macros
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define all(c) (c).begin(), (c).end()
#define newl "\n"
#define out(x) cout << (x) << newl
#define dump(x) \
  cout << "Line " << __LINE__ << " : " << #x << " = " << (x) << newl
template <class T>
using VV = vector<vector<T>>;
#define Uni(v) (v).erase(unique((v).begin(), (v).end()), (v).end());

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  os << "[";
  rep(i, vec.size()) os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  os << "]";
  return os;
}

template <typename T>
ostream& operator<<(ostream& os, vector<vector<T>>& mat) {
  os << "[";
  rep(i, mat.size()) os << mat[i] << (i + 1 == mat.size() ? "" : ",\n ");
  os << "]";
  return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x;
  return is;
}

template <typename V, typename H>
void resize(vector<V>& vec, const H head) {
  vec.resize(head);
}

template <typename V, typename H, typename... T>
void resize(vector<V>& vec, const H& head, const T... tail) {
  vec.resize(head);
  for (auto& v : vec) resize(v, tail...);
}
constexpr double EPS = 1e-10;
const int INF = 0x3f3f3f3f;

string tostring(int i, int digit) {
  auto cur = cout.flags();
  stringstream ss;
  ss << setw(digit) << setfill('0') << i;
  string ret = ss.str();
  cout.flags(cur);
  return ret;
}

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

#pragma endregion

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A, B;
  string S, T, U;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  if (S == U) {
    cout << A - 1 << " " << B << endl;
  } else {
    cout << A << " " << B - 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

const ll INF = 1ll<<60;

vvec<int> node(100100, vec<int>());
vec<int> dp(100100, -1);


int main(){
    int n;
    cin >> n;
    vvec<double> dp(3000, vec<double>(3000));
    dp[0][0] = 1;
    for(int i=1; i<=n; i++){
        double p; cin >> p;
        for(int j=0; j<=n; j++) {
            if (j == 0) dp[i][j] = dp[i-1][j] * (1-p);
            else dp[i][j] = dp[i-1][j-1] * p + dp[i-1][j] * (1-p);
        }
        //cout << i << ":";
        //for(int j=0; j<=n; j++) cout << dp[i][j] << " ";
        //cout << endl;
    }
    double ans = 0;
    for (int j=n/2+1; j<=n; j++)  ans += dp[n][j];
    cout << setprecision(10) <<ans << endl;
}

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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    while (cin >> n, n) {
        vector<P> guys;
        rep(i, n) {
            ll m, l; cin >> m >> l;
            ll f = 0;
            rep(j, m) {
                ll s, t; cin >> s >> t;
                rep(k, s, t) {
                    assert(6 <= s && s <= 22);
                    f |= 1LL << (k-6);
                }
            }
            guys.pb({f, l});
        }
        vector<vector<ll>> dp(n+1, vector<ll>(1LL<<16, -linf));
        dp[0][0] = 0;
        rep(i, n) rep(j, 1LL<<16) {
            if (dp[i][j] < 0) continue;
            chmax(dp[i+1][j], dp[i][j]);
            if ((j & guys[i].first) == 0) {
                ll nj = j | guys[i].first;
                chmax(dp[i+1][nj], dp[i][j] + guys[i].second);
            }
        }
        ll ans = 0;
        rep(i, 1LL<<16) {
            chmax(ans, dp[n][i]);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 55076
n = int(input())
a = list(map(int, input().split()))

x = [[0 for _ in range(2)] for _ in range(n)]
for i in range(n):
    x[i][0] = a[i]
    x[i][1] = i+1
    
x.sort()
print(*[x[i][1] for i in range(n)])

Measured memory_bytes: 74732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  rep(i, n) cin >> v[i];

  vector<ll> sl(n + 1);
  rep(i, n) sl[i + 1] = sl[i] + v[i];

  reverse(all(v));
  vector<int> rv(n);
  rep(i, n) rv[i] = v[i];
  reverse(all(v));

  vector<ll> sr(n + 1);
  rep(i, n) sr[i + 1] = sr[i] + rv[i];

  ll ans = 0;
  rep(l, k + 1) rep(r, k - l + 1) {
    if(l + r > n) continue;
    int ret = k - l - r;
    vector<int> hand;
    rep(i, l) hand.push_back(v[i]);
    rep(i, r) hand.push_back(rv[i]);
    sort(all(hand));
    ll now = sl[l] + sr[r];
    rep(i, ret) {
      if(i >= hand.size()) break;
      if(hand[i] > 0) break;
      now -= hand[i];
    }
    ans = max(ans, now);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
using namespace std;

#define ll int64_t
const long MOD = 1e9 + 7;


// 自作のソート関数
// 5で割った余りの大小で比較
bool less_second(const pair<int,long>& lhs, const pair<int,long>& rhs) {
    return lhs.second > rhs.second;
}


int main()
{
  long x,y;
  cin  >> x>>y;

   bool ans=false;
   ans = (abs(x-y) <=1);

   cout << (ans?"Brown":"Alice");

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    ll x, y;
    cin >> x >> y;
    int cnt = 0;
    while(x <= y) {
        x *= 2;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

void solve(long long N, long long X, long long Y)
{
    vector<ll> ans(N - 1);
    for (ll i = 1; i <= N; i++) {
        for (ll j = i + 1; j <= N; j++) {
            if (i < j) {
                auto min_dist = min(j - i, abs(X - i) + abs(Y - j) + 1);
                ans[min_dist - 1]++;
            }
        }
    }
    copy(begin(ans), end(ans), ostream_iterator<ll>(cout, "\n"));
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
// clang-format off
int main(){
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    cin.tie(nullptr);
    cout.tie(nullptr);
	ios_base::sync_with_stdio(false);
    solve(N, X, Y);
    return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

const int MOD = 1e9 + 7;

int main()
{
    int a, b,c;
    cin >> a >> b>>c;

    cout << ((a==b)?c:(b==c)?a:b) << endl;
    return 0;
}


Measured memory_bytes: 3536
#include <stdio.h>
int main(void){
  int r, g, b, n, count = 0;
  scanf("%d %d %d %d", &r, &g, &b, &n);
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= n; j++){
      if(n - i * r - j * g >= 0 && (n - i * r - j * g) % b == 0){
        count++;
      }
    }
  }
  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/

constexpr lnt MOD = 998244353;
struct mint
{
	lnt v;
	mint():v(0){}
	mint(lnt v):v((v+MOD)%MOD){}
	mint operator-()const{ return mint(0) - *this; }
	mint& operator+=(const mint& a){ if((v+=a.v)>=MOD) v-=MOD; return *this; }
	mint& operator-=(const mint& a){ if((v+=MOD-a.v)>=MOD) v-=MOD; return *this; }
	mint& operator*=(const mint& a){ (v*=a.v)%=MOD; return *this; }
	mint& operator/=(const mint& a){ (*this) *= a.inv(); return *this; }
	mint operator+(const mint& a)const{ return mint(*this) += a; }
	mint operator-(const mint& a)const{ return mint(*this) -= a; }
	mint operator*(const mint& a)const{ return mint(*this) *= a; }
	mint operator/(const mint& a)const{ return mint(*this) /= a; }
	bool operator<(const mint& a)const{ return v < a.v; }
	bool operator==(const mint& a)const{ return v == a.v; }
	mint pow(lnt k)const{ mint r(1),t(v); while(k){ if(k&1) r*=t; t*=t; k>>=1; } return r; }
	mint inv()const{ return pow(MOD-2); }
	static mint comb(lnt n, lnt k) { if(n-k<k) k=n-k; mint num(1), dom(1); for(int i=0;i<k;i++) { num*=n-i; dom*=i+1; } return num/dom; }
	static std::vector<mint> construct_comb(int n) {
		std::vector<mint> c(n+1); mint a = 1; c[0] = a; for(int i=1;i<=n;i++) { a = a*mint(n+1-i)/i; c[i] = a; } return c;
	}
	static std::vector<mint> construct_fact(int n) { std::vector<mint> f(n+1,1); for(int i=2;i<=n;i++) f[i]=f[i-1]*i; return f; }
};
std::istream& operator>>(std::istream&i,mint&a){ lnt t; i>>t; a=mint(t); return i; }
std::ostream& operator<<(std::ostream&o,const mint&a){ o<<a.v; return o; }


int main() {
	int n,k;
	std::cin >> n >> k;
	V<std::pair<int,int> > p;
	rep(i,k) {
		int x,y;
		std::cin >> x >> y;
		p.emplace_back(x,y);
	}
	V<mint> dp(n+1,0); // check n-1
	dp[0]=1;
	dp[1]=mint(-1);
	rep(i,n-1) {
		for(auto e:p) {
			int l,r;
			l=e.first;
			r=e.second;
			if(i+l<n) dp[i+l]+=dp[i];
			if(i+r+1<n) dp[i+r+1]-=dp[i];
		}
		dp[i+1]+=dp[i];
	}
	print(dp[n-1]);
}


Measured memory_bytes: 4788
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <cstdio>

using namespace std;

static int query_cnt = 0;
const string ans = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890qwer";
const bool is_debug = false;

int query(const vector<char>& vc){
    cout << "? ";
    for(auto& c : vc) cout << char(c);
    cout << endl;
    if(is_debug){
        ++query_cnt;
        vector<vector<int>> dp(ans.size()+1, vector<int>(vc.size()+1, 100000000));
        dp[0][0] = 0;
        for(int i=0;i<=ans.size();i++){
            for(int j=0;j<=vc.size();j++){
                if(j > 0) dp[i][j] = min(dp[i][j], dp[i][j-1]+1);
                if(i > 0) dp[i][j] = min(dp[i][j], dp[i-1][j]+1);
                if(i > 0 && j > 0) dp[i][j] = min(dp[i][j], dp[i-1][j-1] + (ans[i-1] == vc[j-1] ? 0 : 1));
            }
        }
        return dp.back().back();
    }
    int q; cin >> q;
    return q;
}

int main(){
    vector<char> vc;
    for(int i=0;i<10;i++) vc.push_back('0'+i);
    for(int i=0;i<26;i++) vc.push_back('a'+i);
    for(int i=0;i<26;i++) vc.push_back('A'+i);

    int L = 0;
    auto cmp = [](const vector<char>& a, const vector<char>& b){ return a.size() > b.size(); };
    priority_queue<vector<char>, vector<vector<char>>, decltype(cmp)> qu(cmp);
    for(int i=0;i<vc.size();i++){
        vector<char> cur(128, vc[i]);
        int q = query(cur);
        if(q == 128) continue;
        qu.push(vector<char>(128-q, vc[i]));
        L += 128 - q;
    }

    while(qu.size() >= 2){
        auto a = qu.top(); qu.pop();
        auto b = qu.top(); qu.pop();
        swap(b, a);
        int idx = 0;
        int cur = L - a.size();
        for(int i=0;i<b.size();i++){
            a.push_back(b[i]);
            for(int j=a.size()-2;j>=idx;j--) swap(a[j], a[j+1]);
            while(true){
                ++idx;
                if(idx == a.size()) break;
                int q = query(a);
                if(q == L - a.size()) break;
                swap(a[idx-1], a[idx]);
            }
        }
        qu.push(a);
    }
    auto res = qu.top();
    cout << "! ";
    for(auto& c : res) cout << char(c);
    cout << endl;
    if(is_debug){
        string result = "";
        for(auto& c : res) result += c;
        if(ans != result || query_cnt > 850){
            cerr << query_cnt << endl;
            cerr << ans << endl;
            cerr << result << endl;
        }
    }
}


Measured memory_bytes: 3796
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <tuple>
#include <stdbool.h>
#include <bitset>
#include <string>
#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;
using namespace std;



typedef enum Result {
    Left,Right,Exists,
};
Result solve(const vector<pair<char, int>>& magics, const string& src, int index) {
    for(const auto& magic: magics) {
        if (src[index] == magic.first) {
            index += magic.second;
        }
        if (index < 0) {
            return Result::Left;
        } else if(index >= src.length()) {
            return Result::Right;
        }
    }
    // cout << "[DEBUG] index:" << index << endl; 
    return Result::Exists;
}
int bin_search_left(const vector<pair<char, int>>& magics, const string& src) {
    // 左からどこまで死んでるか求める
    int begin = 0;
    int end = src.length() - 1;
    int old_target = -1;
    Result result;
    int dst = -1;
    while(begin != end) {
        int target = (end - begin) / 2 + begin;
        if(old_target == target) target++;
        // cout << "L:" << begin << "," << end << "," << target << endl;
        result = solve(magics, src, target);
        if(result == Result::Left) {
            dst = target;
            // 答えはもっと右
            if(begin == target) break;
            begin = target;
        } else {
            if(end == target) break;
            end = target;
        }
        old_target = target;
    }
    // にぶたんで見つけられなかったら-1
    return dst;
}
int bin_search_right(const vector<pair<char, int>>& magics, const string& src) {
    int begin = 0;
    int end = src.length() - 1;
    int old_target = -1;
    Result result;
    int dst = -1;
    while(begin != end) {
        int target = (end - begin) / 2 + begin;
        if(old_target == target) target++;
        // cout << "R:" << begin << "," << end << "," << target << endl;
        result = solve(magics, src, target);
        if(result == Result::Right) {
            dst = target;
            if(end == target) break;
            end = target;
        } else {
            if(begin == target) break;
            begin = target;
        }
        old_target = target;
    }
    // にぶたんで見つけられなかったら-1
    return dst;
}
int main(void) {
    int n; // マスの総数
    int q; // 呪文の数
    string s; // 各盤面のidentify
    cin >> n;
    cin >> q;
    cin >> s;

    vector<pair<char, int>> magics(q);
    for(int i = 0 ; i < q ; ++i) {
        char t; // 適用するマス
        char d; // 方向 L or R
        cin >> t;
        cin >> d;
        magics.push_back(make_pair(t, d == 'L' ? -1 : 1));
    }
    auto l = bin_search_left(magics, s);
    auto r = bin_search_right(magics, s);
    int removed = (l + 1) + (r < 0 ? 0 : (s.length() - r));
    int ans = s.length() - removed;
    // cout << l << endl;
    // cout << r << endl;
    // cout << removed << endl;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

int max(int a, int b)
{ return (a > b) ? a : b; }
int min(int a, int b)
{ return (a > b) ? b : a; }

const int MAXN = 2031;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	
	ll a, b;
	cin >> a >> b;
	a = __gcd(a, b);
	int ans = 1;
	for (ll i = 2; i * i <= a; i++)
	{
		if (a % i == 0) ans++;
		while (a % i == 0)
		{
			a /= i;
		}
	}
	if (a > 1) ans++;
	cout << ans;

    return 0;
}


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

int main () {
  string S, T;
  int s, t;
  string A;
  cin >> S >> T >> s >> t >> A;

  if (S == A) {
    s --;
  }
  else if (T == A) {
    t--;
  }
  cout << s << " " << t << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define MOD 1000000007 
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN

ll po(ll x,ll n){
    if(n==0) return 1;
    else if(n%2 == 0) return po((x*x)%MOD,n/2);
    else return (x*po((x*x)%MOD,(n-1)/2))%MOD;
}

void init(){
}

void solve( ll  tst ){
    ll s = 100;
    ll lim ;
    cin>>lim;
    ll ans = 0;
    while( s < lim ){
        s = ( s + s/100 );
        ans++;
    }
    cout<<ans<<"\n";
    return;
}

int main(){
    FAST;
    init();
    //cout<<"init"<<endl;
    ll t = 1;
    //cin>>t;
    for (ll i=1;i<=t;i++ ) solve(i);
    return 0;
} 

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define F first
#define S second
using ll = long long;
const ll mod = 1000000007;
const ll infi = 1000000000000000;
const ll md = 998244353;
using namespace std;
using vl = vector<ll>;
using pll =  pair<ll,ll>;

void  solve(){
    int n,m,x; string y;
    cin>>n>>m;
    map<int,pair<int,vector<string>>> mp;
    for(int i=0;i<m;i++){
        cin>>x>>y;
        mp[x].S.push_back(y);
        if(y=="AC") mp[x].F = 100;
    }
    int cnta=0,cntp=0;
    for(auto it = mp.begin();it!=mp.end();it++){
        if(it->S.F == 100) cnta++;
        if(it->S.F == 100)
        for(int i=0;i<it->S.S.size();i++){
            if(it->S.S[i] == "WA") cntp++;
            else break;
        }
    }
    cout<<cnta<<" "<<cntp;
}
        
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   // int n; cin>>n; for(int i=0;i<n;i++)
        solve();
    return 0;
}

Measured memory_bytes: 15872
s = gets.chomp

def cal(c, a)
  return a if c.empty?
  p = c.shift
  if a.empty?
    return cal(c, [[p]])
  end

  new_a = []
  a.each do |arr|
    new_a << arr + ['+', p]
    new_a << arr + ['-', p]
  end

  cal(c, new_a)
end

pattern = cal(s.chars, [])
ans = pattern.find { |p| eval(p.join) == 7 }
print "#{ans.join}=7"

Measured memory_bytes: 14252
import math
def div(x, y): #x>y
    A = 1
    for i in range(1, int(math.sqrt(x))+1):
        if x % i == 0 and y % i == 0:
            A = max(A, i)
        j = int(x/i)
        if x % j == 0 and y % j == 0:
            A = max(A, j)
    return A
x, y = map(int, input().split(" "))
print(div(x,y))





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

int main() {
    ll n; cin >> n;
    if (n % 2==0) cout << n << endl;
    else cout << n*2 << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import Counter
def solve(A):
    m = min(A)
    cnt = Counter(A)

    if cnt[m] > 2:
        return False

    if cnt[m] == 2:
        d = m-1
    else:
        d = m

    if max(A) > d+m:
        return False

    for i in range(1,d+1):
        if cnt[i+m] < 2:
            return False


    return True




if __name__ == '__main__':
    N = int(input())
    A = list(map(int,input().split()))
    print('Possible' if solve(A) else 'Impossible')

Measured memory_bytes: 64896
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

a = [0] * 2
i = j = 0
while i < N - 1:
    if A[i] == A[i + 1]:
        a[j] = A[i]
        i += 1
        j += 1
    if j == 2:
        break
    i += 1
print(a[0] * a[1])


Measured memory_bytes: 85324
def main():
    s = input()
    chars = list(s)
    length = len(s)
    l = 0
    r = length - 1
    xcount = 0
    while l <= r and 0 <= r and l < length:
        if chars[l] == chars[r]:
            l += 1
            r -= 1
            continue

        if chars[l] == 'x':
            xcount += 1
            l += 1
            continue

        if chars[r] == 'x':
            xcount += 1
            r -= 1
            continue
        print(-1)
        return

    print(xcount)


main()


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

min_b = -((-n) // a)
if not(min_b <= b and a + b <= n + 1):
    print(-1)
    exit()

ans = []
i = 0
while True:
    tmp = []
    break_flag = False
    for j in range(a):
        if i * a + j >= n:
            break_flag = True
            break
        tmp.append(i * a + j + 1)
    if not tmp:
        break
    ans.append(tmp)
    i += 1
    if break_flag:
        break

ans.sort(reverse=True)
nokori_b = b - len(ans)

for i in range(len(ans) - 1):
    cnt_elems = len(ans[i])
    if nokori_b >= len(ans[i]) - 1:
        ans[i].sort(reverse=True)
        nokori_b -= (len(ans[i]) - 1)
    else:
        ans[i] = sorted(ans[i][:nokori_b + 1], reverse=True) + ans[i][nokori_b + 1:]
        break

res = []
for li in ans:
    for num in li:
        res.append(num)
print(*res)

Measured memory_bytes: 122448
#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>;

static char check[5] = {'A','C','G','T'};

bool CheckACGT(char a)
{
    rep(i,5)
    {
        if(a == check[i])
        {
            return true;
        }
    }

    return false;
}

int main()
{

    string S;
    cin >> S;
    int result = 0;
    int tmpCount = 0;
    bool isLoopStart = false;
    for(int i = 0; i < S.size();++i)
    {

        if(isLoopStart)
        {
            if(CheckACGT(S[i]))
            {
                tmpCount++;
                result = max(tmpCount,result);
                continue;
            }else{
                result = max(tmpCount,result);
                tmpCount = 0;
                isLoopStart = false;
                continue;
            }
            
        }


        bool isACGT = CheckACGT(S[i]);
        if(isACGT)
        {
            isLoopStart = true;
            tmpCount = 1;
            result = max(tmpCount,result);
            
        }
    }

    cout << result << endl;

    return 0;

}

Measured memory_bytes: 256
s = input()
start = 2000000
goal = 0
for i in range(len(s)):
    if s[i] == 'A':
        start = i
        break

for i in range(len(s)):
    if s[i] == 'Z':
        goal = i

# print(start, goal)
ans = goal - start + 1

print(ans)

Measured memory_bytes: 3516
class Dice(object):
    def __init__(self, labels):
        self.stat = labels

    def roll_e(self):
        self.stat[0], self.stat[2], self.stat[5], self.stat[3] = self.stat[3], self.stat[0], self.stat[2], self.stat[5]

    def roll_w(self):
        self.stat[0], self.stat[2], self.stat[5], self.stat[3] = self.stat[2], self.stat[5], self.stat[3], self.stat[0]

    def roll_n(self):
        self.stat[0], self.stat[1], self.stat[5], self.stat[4] = self.stat[1], self.stat[5], self.stat[4], self.stat[0]

    def roll_s(self):
        self.stat[0], self.stat[1], self.stat[5], self.stat[4] = self.stat[4], self.stat[0], self.stat[1], self.stat[5]

    def get_top(self):
        return self.stat[0]


dice = Dice(input().split())
commands = input()
for command in commands:
    if command == "E":
        dice.roll_e()
    elif command == "W":
        dice.roll_w()
    elif command == "N":
        dice.roll_n()
    elif command == "S":
        dice.roll_s()
print(dice.get_top())



Measured memory_bytes: 5572
#include <iostream>
#include<vector>

#define MAX 1000000000

using namespace std;
int main() {
    int n,i,j,k;
    bool sameflg=true,flg,lpflg=true;
    long minkazu=MAX,temp,ans,ans2,min,minyakusu=MAX;
    cin>>n;
    vector<int> a(n);
    for(i=0;i<n;i++){
        cin>>a[i];
        if(a[i]<minkazu)minkazu=a[i];
    }

    ans=minkazu;
    while(1) {
        minyakusu=ans;
        for (i = 0; i < n; i++) {
            if (a[i] % minyakusu > 0 && a[i] % minyakusu < ans)
                ans = a[i] % minyakusu;
        }
        if(ans==ans2)break;
        ans2=ans;
    }


    std::cout << ans2 << std::endl;
    return 0;
}

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

int main()
{
  const int inf = 1000000;
  int h, w;
  cin >> h >> w;
  vector<vector<int>> maze(h + 4, vector<int>(w + 4, -1));
  int si, sj, gi, gj;
  cin >> si >> sj >> gi >> gj;
  si++; sj++; gi++; gj++;

  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      maze.at(i + 2).at(j + 2) = s.at(j) == '#' ? -1 : inf;
    }
  }
  maze.at(si).at(sj) = 0;

  deque<pair<int, int>> dq;
  dq.emplace_front(si, sj);

  while (!empty(dq)) {
    auto [i, j] = dq.front();
    dq.erase(begin(dq));
    array<int, 4> di = {0, 1, 0, -1};
    array<int, 4> dj = {1, 0, -1, 0};
    int m = maze.at(i).at(j);
    for (int k = 0; k < 4; k++) {
      int ni = i + di.at(k);
      int nj = j + dj.at(k);
      if (maze.at(ni).at(nj) > m) {
        maze.at(ni).at(nj) = m;
        dq.emplace_front(ni, nj);
      }
    }
    for (int di = -2; di <= 2; di++) {
      for (int dj = -2; dj <= 2; dj++) {
        int ni = i + di;
        int nj = j + dj;
        if (maze.at(ni).at(nj) > m + 1) {
          maze.at(ni).at(nj) = m + 1;
          dq.emplace_back(ni, nj);
        }
      }
    }
  }
  if (maze.at(gi).at(gj) == inf) maze.at(gi).at(gj) = -1;
  cout << maze.at(gi).at(gj) << endl;
}


Measured memory_bytes: 7544
#include<stdio.h>

int main(){
    char s[4],t[4];
    int i,d=0;
    scanf("%s",s);
    scanf("%s",t);
    for(i=0;i<3;i++){
        if(s[i]==t[i]){
            d++;
        }
    }
    printf("%d",d);
}

Measured memory_bytes: 128
#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

s = IS()+"9"
n = len(s)
a, b = -1, -1

for i in range(n-2):
    if s[i] == s[i+1]:
        a, b = i+1, i+2
    if s[i] == s[i+2]:
        a, b = i+1, i+3
print(a, b)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;


int main(){
  int N, M;
  cin >> N >> M;
  int K[40], A[40][40];
  for(int i = 0; i < N; ++i)
  {
    cin >> K[i];
    for(int j = 0; j < K[i]; ++j)
    {
      cin >> A[i][j];
    }
  }
  int cnt = 0;
  bool like = false;
  for (int i = 1; i <= M; i++)
  {
    for(int j = 0; j < N; ++j)
    {
      like = false;
      for(int k = 0; k < K[j]; ++k)
      {
        if(A[j][k] == i)
        {
          like = true;
          break;
        }
      }
      if(like == false) break;
    }
    if (like == true) cnt++;
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#define int long long
using namespace std;

signed main() {
  int N; cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  int r = 0, cur = 0, ret = 0;
  for(int i = 0; i < N; ++i) {
    while(r != N && (cur & A[r]) == 0) cur += A[r], ++r;
    ret += r - i;
    cur -= A[i];
  }
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define INF 1000000007
using namespace std;

int main(void){
	int a,b;
	cin >> a >> b;
	int ans=0;
	for(int i=1; i<b-a; i++){
		ans+=i;
	}
	cout << ans-a << endl;
	return 0;
}


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

NO = "IMPOSSIBLE"  # type: str

def solve(A: int, B: int):
    a = (A + B)* 1.0/2
    if float.is_integer(a):
        print(int(a))
    else:
        print("IMPOSSIBLE")

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = System.Console.ReadLine().Trim();
            long iN = long.Parse(sS);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            long iOut = 0;
            if (iN == 1L) { iOut = 0L; }
            else if (iN == 2L) { iOut = 1L; }
            else
            {
                iOut = ((1 + (iN - 1)) * (iN - 1)) / 2;
            }

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	s = chomp(readline())
	sflg = 0
	count = 0
	lcount = 0
	for i in 1:length(s)
		if sflg == 0
			if s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'
				sflg = 1
				lcount += 1
				count = max(count, lcount)
			end
		else
			if s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'
				lcount += 1
				count = max(count, lcount)
			else
				lcount = 0
				sflg = 0
			end
		end
	end
	println(count)
end
main()

Measured memory_bytes: 166144
#include<cstdio>
#include<cmath>
int main(){
  double a,b,c;
  scanf("%lf %lf %lf",&a,&b,&c);
  printf("%.7f\n",a*b*sin((M_PI*c/180))/2);
  printf("%.7f\n",a+b+sqrt(pow(a,2)+pow(b,2)-2*a*b*cos((M_PI*c/180))));
  printf("%.7f\n",b*sin((M_PI*c/180)));
}


Measured memory_bytes: 2924
#include <iostream>
#include <unordered_set>
#include <algorithm>
using namespace std;


#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); ++i)

int main(void){
    int N;
    cin >> N;
    unordered_set<string> A;
    rep(i, N){
        char c;
        string s;
        cin >> c >> s >> s;
        if(c == 'i')
            A.insert(s);
        else
            cout << (A.find(s) != A.end() ? "yes" : "no") << endl;      
    };
    
    return 0;
}


Measured memory_bytes: 31968
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <cmath>
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

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

  while(A>0){
    C = C - B;
    if(C <= 0){
      cout << "Yes" << endl;
      break;
    }
    A = A - D;
    if(A <=0){
      cout << "No" << endl;
      break;
    }
  }
}


Measured memory_bytes: 3632
import sys
input = sys.stdin.readline

n = int(input())
s = list(str(input()))
s = [{ord(c)-ord('a')} for c in s]

def segfunc(x, y):
    return x | y

def init(init_val):
    # set_val
    for i in range(n):
        seg[i+num-1] = init_val[i]
    # built
    for i in range(num-2, -1, -1):
        seg[i] = segfunc(seg[2*i+1], seg[2*i+2])

def update(k, x):
    k += num - 1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[2*k+1], seg[2*k+2])

def query(p, q):
    if q <= p:
        return ide_ele
    p += num - 1
    q += num - 2
    res = ide_ele
    while q-p>1:
        if p%2 == 0:
            res = segfunc(res, seg[p])
        if q%2 == 1:
            res = segfunc(res, seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res, seg[p])
    else:
        res = segfunc(segfunc(res, seg[p]), seg[q])
    return res

# identity element
ide_ele = set()

# num: n以上の最小の2のべき乗
num = 2**(n-1).bit_length()
seg = [ide_ele]*2*num

init(s)

q = int(input())
for _ in range(q):
    t, x, y = map(str, input().split())
    if t == '1':
        i = int(x)-1
        c = {ord(y)-ord('a')}
        update(i, c)
    else:
        l = int(x)-1
        r = int(y)-1
        print(len(query(l, r+1)))


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


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = 29
val = 0

def lcount(a,b,x):
    """ソート済a,bに対して, a[i]+b[j]<=xなるi,jの個数
    """
    la = len(a)
    lb = len(b)
    j = -1
    ans = 0
    for i in range(la-1, -1, -1):
        while j+1<lb and a[i]+b[j+1]<=x:
            j += 1
        ans += (j+1)
    return ans
for k in range(l):
    # i桁目を求める
    tmp = pow(2, k+1)
    bb = [item%(tmp) for item in b]
    aa = [item%(tmp) for item in a]
    aa.sort()
    bb.sort()
    ans = n**2 - lcount(aa,bb,tmp//2*3-1) + lcount(aa,bb,tmp-1) - lcount(aa,bb,tmp//2-1)
    if ans%2:
        val += pow(2, k)
print(val)

Measured memory_bytes: 224044
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>
#include <stack>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator<< (ostream &out, const vector<int> &b) {
    for (auto k : b) out << k << " ";
    return out;
}

istream& operator>> (istream& in, pii& b) {
    in >> b.first >> b.second;
    return in;
}

ostream& operator<< (ostream& out, const pii& b) {
    out << "{" << b.first << ", " << b.second << "}";
    return out;
}

template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 10;
#else
    #define dbg(x) 57
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 179;
#endif

const ld PI = acos(-1);

#define time clock() / (double) CLOCKS_PER_SEC

// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,sse3,sse4")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("avx2")  
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

const int MAXN = 1e5 + 10;

int n, k;
vector<int> g[MAXN];
int ans = 0;
int d[MAXN];

void dfs(int v) {
    d[v] = 0;
    for (auto u : g[v]) {
        dfs(u);
        if (d[u] == k - 1 && v != 0) {
            ans++;
        } else {
            chkmax(d[v], d[u] + 1);
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    if (k == 1) {
        for (int i = 0; i < n; i++) {
            if (a[i] != 0) {
                ans++;
            }
        }
        cout << ans << "\n";
        return 0;
    }
    if (a[0] != 0) {
        ans++;
        a[0] = 0;
    }
    for (int i = 1; i < n; i++) {
        g[a[i]].pb(i);
    }
    dfs(0);
    cout << ans << "\n";
}
/*

*/

Measured memory_bytes: 16400
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

int main() {
    long long N,M;
    cin >> N >> M;
    vector<long long> L(M),R(M);
    for (int i=0; i<M; i++) {
        cin >> L[i] >> R[i];
    }
    sort(L.begin(), L.end());
    sort(R.begin(), R.end());
    
    if (L[M-1]<=R[0]) {
        cout << R[0]-L[M-1]+1 << endl;
    }
    else{
        cout << 0 << endl;
    }
}


Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;


int main(int argc, const char * argv[]) {
  string s;
  cin >> s;
  int a = stoi(s.substr(0,2));
  int b = stoi(s.substr(2,2));

  if(a <= 12 && a > 0 && b <= 12 && b > 0){
    cout << "AMBIGUOUS" << endl;
  }else if(a <= 12 && a > 0){
    cout << "MMYY" << endl;
  }else if(b <= 12 && b > 0){
    cout << "YYMM" << endl;
  }else{
    cout << "NA" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
//#include <sys/time.h>

using namespace std;

vector<long long> calc_times(long long n){
//    vector< vector<long long> > xc(n, vector<long long>(n));
//    for (long long i = 0; i < n; i++) {
//        for (long long j = 0; j < n; j++) {
//            long long a = min( {i+1, j+1, n-i, n-j} );
//            xc[i][j] = a;
//        }
//    }
    vector<long long> ret(n);
    int prodiff = n;
    ret[0] = n;
    ret[n-1] = n;
    for (int i = 1; 2*i < n; i++) {
        prodiff -= 2;
        ret[i] = ret[i-1] + prodiff;
        ret[n-1-i] = ret[i-1] + prodiff;
    }
//    for (long long i = 0; i < n; i++) {
//        ret.push_back(accumulate(xc[i].begin(), xc[i].end(), 0));
//    }
    return ret;
}

void solve(long long n, long long m, vector<long long> X, vector<long long> Y){
    vector<long long> times_of_x(n-1);
    vector<long long> times_of_y(m-1);
    long long modll = 1000000007;
    times_of_x = calc_times(n-1);
    times_of_y = calc_times(m-1);
    sort(X.begin(),X.end());
    sort(Y.begin(),Y.end());
    long long answer = 0;
    long long sum_X = 0;
    long long sum_Y = 0;
    for (int i = 0; i < n-1; i++) {
        sum_X += (X[i+1]-X[i]) * times_of_x[i] % modll;
        sum_X = sum_X % modll;
    }
    for (int i = 0; i < m-1; i++) {
        sum_Y += (Y[i+1]-Y[i]) * times_of_y[i] % modll;
        sum_Y = sum_Y % modll;
    }
    answer = sum_X * sum_Y % modll;
//    for (long long i = 0; i < n-1; i++) {
//        for (long long j = 0; j < m-1; j++) {
//            answer += (X[i+1]-X[i]) * (Y[j+1]-Y[j]) * times_of_x[i] * times_of_y[j] % 1000000007LL;
////            answer += (X[i+1]-X[i]) * (Y[j+1]-Y[j]) * times_of_x[i] * times_of_y[j];
////            answer = answer % 1000000007LL;
//        }
//    }
//    answer = answer % 1000000007LL;
    cout << answer << endl;
}

int main(){
//    struct timeval start,end;
//    long long span;
    long long n,m;

//    gettimeofday(&start,NULL);
    cin >> n >> m;
    vector<long long> X(n);
    vector<long long> Y(m);
    for (long long i = 0; i < n; i++) {
        cin >> X[i];
    }
    for (long long i = 0; i < m; i++) {
        cin >> Y[i];
    }
    solve(n, m, X, Y);
//    gettimeofday(&end,NULL);
//    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
//    cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 5760