akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string str1;
    while(cin >> str1) {
        int cnt1 = 0, cnt2 = 0, flag = 0;
        for(int i=0,len=str1.length()-2;i < len;++i) {
            if (str1[i] == 'J' || str1[i] == 'I') {
                (str1[i] == 'J') ? flag = 1 : flag = 0;
                if (str1[i+1] == 'O') {
                    if (str1[i+2] == 'I') {
                        (flag) ? ++cnt1 : ++cnt2;
                    } else continue;
                } else continue;
            } else continue;
        }
        
        printf("%d\n%d\n", cnt1, cnt2);
    }

    return 0;
}

Measured memory_bytes: 1192
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

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

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

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

int main(){
	LL n;cin>>n;
	VLL a(n+1),b(n);
	rep(i,n+1)cin>>a.at(i);
	rep(i,n)cin>>b.at(i);
	LL ans=0;
	rep(i,n){
		if(a.at(i)>=b.at(i)){
			ans+=b.at(i);
			a.at(i)-=b.at(i);
			continue;
		}
		ans+=a.at(i);
		b.at(i)-=a.at(i);
		if(a.at(i+1)>=b.at(i)){
			ans+=b.at(i);
			a.at(i+1)-=b.at(i);
			continue;
		}
		ans+=a.at(i+1);
		a.at(i+1)=0;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 998244353;
const double pi = 3.141592653589793;

ll n, k, sum_a, ans;
VLL a, f;

bool solve(ll limit, ll tk)
{
    REP(i,n) {
        //cerr<<i<<"_"<<tk<<"  ";
        if (tk < 0) {
            return false;
        } else if (a[i] * f[n-i-1] <= limit) {
            continue;
        } else {
            ll tmp = (a[i] * f[n-i-1] - limit + f[n-i-1] - 1) / f[n-i-1];
            tk -= tmp;
        }
    }
    //cerr<<endl;

    return tk >= 0;
}

int main()
{
    cin>>n>>k;
    a.resize(n);
    f.resize(n);
    REP(i,n) {
        cin>>a[i];
        sum_a += a[i];
    }
    REP(i,n) {
        cin>>f[i];
    }
    SORT(a);
    SORT(f);

    ll l = 0, r = 1e12 + 1, mid;
    REP(i, 100) {
        debug(mid);
        if (l == r) {
            break;
        }

        mid = (l + r) / 2;
        bool feasible = solve(mid, k);
        if (feasible) {
            r = mid;
            cerr<<"true"<<endl;
        } else {
            l = mid;
            cerr<<"false"<<endl;
        }

    }

    cout<<r<<endl;

    return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>
#include <math.h>
int main(void){
   
    int n[100000],count,count2= 0,x,len,ect = 0;
    char str[101],f,e;
    
    scanf("%d", &count);
    int i = 0;
    for(i = 0; i < count; i++) {
        scanf("%d", &n[i]);
        if(n[i] % 4 == 0) count2++;
        else if(n[i] % 2 == 0) ect++;
    }
    
    if(ect == 1)ect = 0;
    
    if(count2 >= 1) len = 3;
    len = (count2-1) * 2 + len;
    len = count - len + 1;
    
    x = count / 2;
    
    if(x <= count2){
        printf("Yes\n");
        return 0;
    }
    
    if(len <= ect) {
        printf("Yes\n");
        return 0;
    }
    printf("No\n");
    return 0;
}


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

const int mod = 1e9 + 7;

template <const int32_t MOD>
struct modint {
    int32_t value;
    modint() = default;
    modint(int32_t value_) : value(value_) {}
    inline modint<MOD> operator + (modint<MOD> other) const { int32_t c = this->value + other.value; return modint<MOD>(c >= MOD ? c - MOD : c); }
    inline modint<MOD> operator - (modint<MOD> other) const { int32_t c = this->value - other.value; return modint<MOD>(c <    0 ? c + MOD : c); }
    inline modint<MOD> operator * (modint<MOD> other) const { int32_t c = (int64_t)this->value * other.value % MOD; return modint<MOD>(c < 0 ? c + MOD : c); }
    inline modint<MOD> & operator += (modint<MOD> other) { this->value += other.value; if (this->value >= MOD) this->value -= MOD; return *this; }
    inline modint<MOD> & operator -= (modint<MOD> other) { this->value -= other.value; if (this->value <    0) this->value += MOD; return *this; }
    inline modint<MOD> & operator *= (modint<MOD> other) { this->value = (int64_t)this->value * other.value % MOD; if (this->value < 0) this->value += MOD; return *this; }
    inline modint<MOD> operator - () const { return modint<MOD>(this->value ? MOD - this->value : 0); }
    modint<MOD> pow(uint64_t k) const { modint<MOD> x = *this, y = 1; for (; k; k >>= 1) { if (k & 1) y *= x; x *= x; } return y; }
    modint<MOD> inv() const { return pow(MOD - 2); }  // MOD must be a prime
    inline modint<MOD> operator /  (modint<MOD> other) const { return *this *  other.inv(); }
    inline modint<MOD> operator /= (modint<MOD> other)       { return *this *= other.inv(); }
    inline bool operator == (modint<MOD> other) const { return value == other.value; }
    inline bool operator != (modint<MOD> other) const { return value != other.value; }
    inline bool operator < (modint<MOD> other) const { return value < other.value; }
    inline bool operator > (modint<MOD> other) const { return value > other.value; }
};
template <int32_t MOD> modint<MOD> operator * (int64_t value, modint<MOD> n) { return modint<MOD>(value) * n; }
template <int32_t MOD> modint<MOD> operator * (int32_t value, modint<MOD> n) { return modint<MOD>(value % MOD) * n; }
template <int32_t MOD> istream & operator >> (istream & in, modint<MOD> &n) { return in >> n.value; }
template <int32_t MOD> ostream & operator << (ostream & out, modint<MOD> n) { return out << n.value; }

using mint = modint<mod>;

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	cout << mint(10).pow(n) - mint(9).pow(n) * 2 + mint(8).pow(n) << '\n';
    return 0;
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

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

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename T >
T extgcd(T a, T b, T &x, T &y) {
  T d = a;
  if(b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}

int main() {
  int a, b, x, y;
  cin >> a >> b;
  extgcd(a, b, x, y);
  cout << x << " " << y << endl;
}






Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll n, k;
bool calc(int x, vector<int> &a){
    ll cnt = 0;
    For(i,0,n){
        cnt += (a[i] - 1) / x;
    }
    return cnt <= k;
}
void Main(){
    cin >> n >> k;
    vector<int> a(n);
    For(i,0,n) cin >> a[i];
    int ok = 1e9 + 10, ng = 0;
    while(ok > ng + 1){
        int mid = (ok + ng) / 2;
        if(calc(mid, a)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

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

using namespace std;

int n;
int four;
int two;
int main() {
  cin >> n;

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

    if(a % 4 == 0) {
      four++;
      continue;
    }

    if(a % 2 == 0) {
      two++;
      continue;
    }
  }

  if(2 * four + 1 >= n) cout << "Yes" << endl;
  else if(2 * four + two >= n) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr ll INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld PI = acos(-1);
constexpr ld EPS = 1e-11;

int main(void){
	ll n, p;
	cin >> n >> p;
	string s;
	cin >> s;
	Vec t(n);
	rep(i, n) t[i] = s[i] - '0';
	Vec pos(n);
	pos[n - 1] = 1;
	repr(i, n - 1){
		pos[i] = pos[i + 1] * 10 % p;
	}

	if(p == 2){
		ll ans = 0;
		repr(i, n){
			if(t[i] % 2 == 0) ans += i + 1;
		}
		co(ans);
		return 0;
	}

	if(p == 5){
		ll ans = 0;
		repr(i, n){
			if(t[i] % 5 == 0) ans += i + 1;
		}
		co(ans);
		return 0;
	}

	Vec cnt(p);
	cnt[0]++;
	ll ans = 0;
	ll r = 0;
	repr(i, n){
		r = (r + t[i] * pos[i]) % p;
		ans += cnt[r];
		cnt[r]++;
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 3716
import sys

n, y = map(int, input().split())
y /= 1000
for i in range(n + 1):
    for j in range(n + 1):
        k = n - i - j
        if(k >= 0 and (i * 10 + j * 5 + k) == y):
            print(i, j, k)
            exit(0)
print("-1 -1 -1")


Measured memory_bytes: 40940
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;

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

int main() {
  int n;
  while(cin>>n,n) {
    int a[n+1][n+1];
    REP(y,n) {
      int sum=0;
      REP(x,n) {
        cin >> a[x][y];
        sum += a[x][y];
      }
      a[n][y] = sum;
    }
    int sum2 = 0;
    REP(x,n) {
      int sum =0;
      REP(y,n) {
        sum+=a[x][y];
      }
      a[x][n] = sum;
      sum2+=sum;
    }
    a[n][n] = sum2;
    REP(y,n+1) {
      REP(x,n+1) {
        printf("%5d",a[x][y]);
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 0
#include<string>
    #include<iomanip>
    #include<iostream>
    #include<math.h>
    using namespace std;
    #define NUM 100001
     
    int main() {
    	int A,B;
    	
    	cin >> A >> B;
     
    	if (A > 12) {
    		cout << B << endl;
    	}
    	if (6 <= A && A <= 12) {
    		cout << B/2 << endl;
    	}
    	if (A <= 5) {
    		cout << 0 << endl;
    	}
    	
     
    	return 0;
    }

Measured memory_bytes: 256
N = int(input())
count = [0]*4
for i in range(N):
    s = input()
    if s == 'AC':
        count[0] += 1
    elif s == 'WA':
        count[1] += 1
    elif s == 'TLE':
        count[2] += 1
    else:
        count[3] += 1

print('AC x',count[0])
print('WA x',count[1])
print('TLE x',count[2])
print('RE x',count[3])


Measured memory_bytes: 9176
N = int(input())
H = list(map(int,input().split()))

current = H[0]
count = 0
max_count = 0

current_start = 0
for index in range(1, len(H)):
    if current < H[index]:
        if count > max_count:
            max_count = count

        current_start = index
        count = 0
        current = H[index]

    else:
        current = H[index]
        count += 1
        
# last check
if count > max_count:
    max_count = count


print(max_count)


Measured memory_bytes: 63984
#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>
#include <list>
#include <set>
#include <random>
#include <deque>
#include <unordered_set>

using namespace std;
using ll = long long;
const int BIG = 1000000007;


int main() {
    ll n;
    cin >> n;
    vector<ll> a(1000001,0);
    bool pc = true;
    bool sc = true;
    for(ll i = 0;i < n;++i){
        ll l;
        cin >> l;
        ++a[l];
    }

    for(ll i = 2;i < a.size();++i){
        ll j = i * 2;
        ll k = a[i];
        while (j < a.size()){
            if(a[j]){
                k += a[j];
            }
            j += i;
        }
        if(k >= 2)pc = false;;
        if(k == n)sc = false;
    }

    if(pc){
        cout << "pairwise coprime" << endl;
    }
    else if(sc){
        cout << "setwise coprime" << endl;
    }
    else{
        cout << "not coprime" << endl;
    }

}




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

int main() {
  int a;
  cin>>a;
  char b[a];
  bool c=false;
  for(int i=0;i<a;i++){
    cin>>b[i];
    if(b[i]=='Y') c=true;
  }
  if(c) cout<<"Four"<<endl;
  else cout<<"Three"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
typedef __int128_t lll;
using namespace std;

int main(int argc, char const *argv[]) {
  ld x, n, k;std::cin >> n >> k;
  vector<ld> a(n), s(n);
  re(i, n){
    std::cin >> x;
    a[i] = (x+1.0)/2.0;
    s[i] = (i==0?0:s[i-1]) + a[i];
  }
  ld ans = 0;
  for(int i=0;i<=n-k;i++){
    ld left = (i==0?0:s[i-1]);
    ld right = s[i+k-1];
    ans = max(ans, right - left);
  }
  std::cout << fixed << setprecision(20) << ans << '\n';
  return 0;
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,ans;
  string s;
  cin >> n >> s;
  ans = 0;
  for(int i=0;i<n-2;i++){
    if(s.at(i) == 'A' && s.at(i+1) == 'B' && s.at(i+2) == 'C')
      ans++;
  }
  cout << ans << endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<ll> a(n + 1);
    rep (i, n + 1) cin >> a[i];
    if (n == 0) {
        if (a[0] != 1) cout << -1 << endl;
        else cout << 1 << endl;
        return 0;
    }
    if (n > 0 && a[0] != 0) {
        cout << -1 << endl;
        return 0;
    }
    
    // 下からの条件
    vector<ll> lower(n + 1);
    lower[n] = a[n];
    for (int i = n - 1; i > 0; --i) lower[i] = lower[i + 1] + a[i];

    ll res = 0;
    ll cur = 1;
    FOR (i, 1, n + 1) {
        cur *= 2;
        cur = min(cur, lower[i]);
        if (a[i] > cur) {
            cout << -1 << endl;
            return 0;
        }
        res += cur;
        cur -= a[i];
    }
    cout << res + 1 << endl;
    
    return 0;
}



Measured memory_bytes: 4732
/*
可以用一颗有根树来描述题目给定的过程。这颗有根树的每个非叶子节点有恰好K个儿子，描述了一次合并。叶子共有N + M个，N个点权是0，M个点权是1
每个非叶节点的点权是所有孩子点权和的平均值。题目所要求的就是根节点的点权有多少种可能的取值
可以发现，根节点的点权取决于所有叶子对其的贡献。叶子u对根节点点权的贡献是V[u] / K^Deep[u]，Deep[u]是u到根节点需要经过的边数
*/
/*
性质1：Sum{1 / K^Deep[u]   |   u是一个叶子} = 1
       这可以归纳证明：合并过程的任意时刻，每个根节点r的Sum{1 / K^Deep[u]   |   u是r子树中的叶子} = 1。这里Deep[u]是u到r需要经过的边数
                       初始该条件显然成立。每次合并的时候，新的根有K个儿子，每个儿子对其的贡献都是1 / K，所以该条件仍然成立。那么也就证明了该结论
性质2：如果确定了最终每个叶子的深度，那么只要满足Sum{1 / K^Deep[u]   |   u是一个叶子} = 1，就一定可以构造出满足条件的树
       给出构造的过程：当只有1个Deep = 0的点的时候，构造直接完成
                       否则选出Deep[u]最大的点，显然Deep[u] >= 1。这些点的个数一定是K的倍数，否则考虑K进制，Sum{1 / K^Deep[u]} = 1一定不满足
		       那么直接选出K个点合并成为一个深度为Deep[u] - 1的根节点的儿子，继续按照该过程构造即可
根据以上两条性质，可以得出，一个确定每个叶子深度的方案是合法的   <=>   Sum{1 / K^Deep[u]   |   u是一个叶子} = 1
*/
/*
回到题目，设根节点的权值为s，s = Sum{1 / K^Deep[u]   |   u是一个叶子且V[u] = 1}，那么有1 - s = Sum{1 / K^Deep[u]   |   u是一个叶子且V[u] = 0}
只要能找到恰好M个u满足Sum{1 / K^Deep[u]} = s、恰好N个u满足Sum{1 / K^Deep[u]} = 1 - s，就说明s是可行的
判断能否找到恰好X个K的负次幂使得它们的和 = S，是一个经典问题，按照如下两个步骤构造即可：
(1)考虑S在K进制下的数位和D，显然需要有D <= X，令X的初始值X' = D
(2)当0 < X' < X时，可以把1个K^(-e)拆成K个K^(-e - 1)使得X' += K - 1，故需要满足D = X(mod K - 1)
直接dp在K进制下s的值，F[i][j]表示考虑到了K^(-i)，s当前数位和为j的方案数，根据j可以推算出1 - s的数位和
*/

#include <cstdio>
#include <cstring>

using namespace std;
const int Max_N(2050);
const int MOD(1000000000 + 7);

constexpr int Add(int a, int b)
{
	return a + b >= MOD ? a + b - MOD : a + b;
}

constexpr int Sub(int a, int b)
{
	return a - b < 0 ? a - b + MOD : a - b;
}

int N, M, K, Ans, F[Max_N], Pre[Max_N];

inline bool check(int X, int D)
{
	return D == X || (0 < D && D <= X && D % (K - 1) == X % (K - 1));
}

int main()
{
	scanf("%d%d%d", &N, &M, &K);
	Ans = (check(M, 1) && check(N, 0));
	F[0] = 1;
	for (int i = 1;(K - 1) * i + 1 - M <= N;++i)
		for (int j = 0;j <= M;++j)
		{
			if (j == 0)
				Pre[j] = 0;
			else
				Pre[j] = Pre[j - 1];
			Pre[j] = Add(Pre[j], F[j]);
			if (j)
				F[j] = Sub(Pre[j - 1], j - K >= 0 ? Pre[j - K] : 0);
			else
				F[j] = 0;
			if (check(M, j) && check(N, (K - 1) * i + 1 - j))
				Ans = Add(Ans, F[j]);
			F[j] = Add(F[j], Sub(Pre[j], j >= 1 ? Pre[j - 1] : 0));
		}
	printf("%d", Ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    int A[105], P[105], X[105];

    cin >> n;
    REP(i, n) cin >> A[i];

    int m;
    cin >> m;
    REP(i, m) cin >> P[i] >> X[i];

    LL ans = 0;
    REP(i, n) ans += A[i];

    REP(i, m) {
        cout << ans - A[P[i]-1] + X[i] << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define EPS 1e-9
using namespace std;
const int N=1e5,OO=0x3f3f3f3f;
typedef  long long ll;
int main() {
  ll n=100,x; scanf("%lld",&x); int ans=0;
  while(n<x)
   n+=(n/100),ans++;
  printf("%lld",ans);
}

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

int main() {
	vector<ll> V;
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int p;
		cin >> p;		
		if (p == 0) {
			ll x;
			cin >> x;
			V.push_back(x);
		}
		else if (p == 1) {
			ll x;
			cin >> x;
			cout << V[x] << endl;
		}
		else if (p == 2)
			V.pop_back();
	}
}



Measured memory_bytes: 4972
import bisect
import itertools
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

*perm, = itertools.permutations(list(range(1, n+1)), n)
a = bisect.bisect_right(perm, p)
b = bisect.bisect_right(perm, q)

print(abs(a-b))


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

typedef long long ll;
const long double pi = acos(-1);
ll X1,Y1,X2,Y2,n,a[200020],d[200020],len;
map<ll,ll> x,y;

int main(){
    ios::sync_with_stdio(false);
    cin >> X1 >> Y1 >> X2 >> Y2 >> n;
    if(X2 < X1){
        swap(X1,X2);
        swap(Y1,Y2);
    }
    for(int i = 1,u,v;i <= n;++i){
        cin >> u >> v;
        x[u] = v;
        y[v] = u;
    }
    long double qc = 5.0 * pi, ans = 0.0;
    if(X1 == X2){
        int p = min(Y1,Y2), q = max(Y1,Y2);
        ans = 100.0 * (q - p);
        if(x.count(X1) && x[X1] > p && x[X1] < q) ans += 2*qc - 20.0;
        cout << fixed << setprecision(12) << ans << endl;
        return 0;
    }
    if(Y1 == Y2){
        int p = min(X1,X2), q = max(X1,X2);
        ans = 100.0 * (q - p);
        if(y.count(Y1) && y[Y1] > p && y[Y1] < q) ans += 2*qc - 20.0;
        cout << fixed << setprecision(12) << ans << endl;
        return 0;
    }

    ll cnt = 0, mny = min(Y1,Y2), mxy = max(Y1,Y2);
    ans = 100.0 * (X2 - X1 + mxy - mny);
    for(auto p: x){
        if(p.first < X1 || p.first > X2) continue;
        if(p.second >= mny && p.second <= mxy) a[++cnt] = (Y1 < Y2 ? 1 : -1) * p.second;
    }

    for(int i = 1;i <= cnt;++i){
        int pos = lower_bound(d+1,d+1+len,a[i]) - d;
        if(pos == len + 1) len++;
        d[pos] = a[i];
    }

    ans -= 20*len - pi * (5 * len);
    if(len > min(X2 - X1,mxy - mny)) ans += qc;

    cout << fixed << setprecision(12) << ans << endl;

    return 0;
}


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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

typedef long long int ll;

int main() {

	IOS

	int a;
	cin >> a;

	cout << a + a*a + a*a*a;

	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
using namespace std;
#define REP(i,n); for(int i = 0;i < (int)(n);i++)

int main() {
	int n,count=0;
	string s;
	cin >> s;
	n = s.length();
	REP(i,n){
		if(i%2){
			if(s[i]=='0')count++;
		}else{
			if(s[i]=='1')count++;
		}
	}
	if(count > (n/2))cout << n-count;
	else cout << count;
	return(0);
}

Measured memory_bytes: 512
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}

int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}
// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}


#pragma endregion


// 123 C-Five Transportations
int main(void) {
	ll n, a, b, c, d, e, ans;

	scanf("%lld %lld %lld %lld %lld %lld", &n, &a, &b, &c, &d, &e);
	ll min;
	min = _min(a, _min(_min(b, c), _min(d, e)));
	//printf("%lld\n", min);
	ans = n / min + 5 - ((n % min) ? 0 : 1);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2156
import sys

X=int(input())
five=[]

for i in range(-1000,1001):
    five.append(i**5)
l=len(five)


for j in range(l):
    for k in range(j+1,l):
        if five[k]-five[j]==X:
            print(-1000+k,-1000+j)
            sys.exit()

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

int main() {
  int n,k;
  cin >> n >> k;
  int a=1;
  int count = 0;
  while(a<=n){
    a *=k;
    count ++;
  }
  cout << count << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<limits.h>
#include<stdlib.h>
typedef long long int lli;
int lli_compare(const void *a,const void *b){return *(lli*)a-*(lli*)b;}
int main(void)
{
    lli n;
    lli a[100000];
    lli cnt=0;
    lli ans=0;

    scanf("%lld",&n);
    for(lli i=0;i<n;i++){
        scanf("%lld",&a[i]);
    }
    qsort(a,n,sizeof(lli),lli_compare);
    for(lli i=0;i<n;i++){
        if(a[i]==a[i+1])cnt++;
        else {
            cnt++;
            if(a[i]<cnt)ans+=cnt-a[i];
            else if(a[i]>cnt)ans+=cnt;
            cnt=0;
        }
        //printf(">%lld\n",cnt);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1660
#include<iostream>
using namespace std;;
int main(){
int a,b,n;
cin >> n>> a >> b;
int sum=0;
for(int i=1;i<=n;i++){
int j=i;
int sum1=0;
while(j>9){
sum1+=j%10;
j=j/10;
}
sum1+=j;
if(a<=sum1&&sum1<=b){
sum+=i;
}
}
cout << sum;
return 0;
}

Measured memory_bytes: 256
def half(xs):
    count = 0
    while True:
        for i in range(len(xs)):
            if xs[i] % 2 != 0 or xs[i] == 0:
                return count
            xs[i] /= 2
        else:
            count += 1
    return count


def main():
    _num = input()
    xs = [int(i) for i in input().split()]
    res = half(xs)
    print(res)


if __name__ == "__main__":
    main()


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

using namespace std;

int main(){
	string str;
	while(cin>>str,str!="#"){
		bool flag=true;
		int co=0;
		switch(str[0]){
				case 'a':
				case 'q':
				case 'z':
				case 'x':
				case 's':
				case 'w':
				case 'e':
				case 'd':
				case 'c':
				case 'v':
				case 'f':
				case 'r':
				case 't':
				case 'g':
				case 'b':
					flag=true;
					break;				
				case 'n':
				case 'h':
				case 'y':
				case 'u':
				case 'j':
				case 'm':
				case 'k':
				case 'i':
				case 'o':
				case 'l':
				case 'p':
					flag=false;
					break;
			}
		for(int i=1;i<str.size();i++){
			switch(str[i]){
				case 'a':
				case 'q':
				case 'z':
				case 'x':
				case 's':
				case 'w':
				case 'e':
				case 'd':
				case 'c':
				case 'v':
				case 'f':
				case 'r':
				case 't':
				case 'g':
				case 'b':
					if(flag==false){
						co++;
					}
					flag=true;
					break;					
				case 'n':
				case 'h':
				case 'y':
				case 'u':				
				case 'j':
				case 'm':
				case 'k':
				case 'i':
				case 'o':
				case 'l':
				case 'p':
					if(flag==true){
						co++;
					}
					
					flag=false;
					break;
			}
		}
		cout<<co<<endl;
	}
}
	

Measured memory_bytes: 1184
N=[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]
S=int(input())
print(N[S-1])

Measured memory_bytes: 3060
import functools
import sys
import math
input = lambda :sys.stdin.readline()
@functools.lru_cache(maxsize=10000)

def Main():
    N, A, B = map(int,input().split())
    Arr = list(map(int, input().split()))
    sm = 0
    for i in range(0, len(Arr) - 1):
        zemi = abs(Arr[i] - Arr[i + 1])
        # print(zemi)
        sm += min((zemi*A), B)

    print(sm)

if __name__ == '__main__':
    Main()

Measured memory_bytes: 14668
N = int(input())
p = list(map(int, input().split()))

result = 0
for i in range(N - 1):
    if p[i] != i + 1:
        continue
    result += 1
    p[i], p[i + 1] = p[i + 1], p[i]
if p[N - 1] == N:
    result += 1
print(result)


Measured memory_bytes: 14008
n = int(input())
x = [float(i) for i in input().split()]
y = [float(i) for i in input().split()]

b = [abs(x[i] - y[i]) for i in range(n)]

print(sum(b))
print(sum([i ** 2 for i in b]) ** (1 / 2))
print(sum([i ** 3 for i in b]) ** (1 / 3))
print(max(b))


Measured memory_bytes: 5668
N, M = map( int, input().split() )
params = []
for i in range(N):
    x, y, z = map( int, input().split() )
    params.append( [x,y,z] )


ans = 0
# どれを最大化するか8通り全部試す
for i in range(8):
    b = [0]*N
    for j in range(N):
        for k in range(3):
            if i//(1<<k) % 2 == 0: b[j] += params[j][k]
            else: b[j] -= params[j][k]
    b.sort(reverse=True)
    ans = max( ans, sum(b[:M]) )

print(ans)

Measured memory_bytes: 3188
import math
N=int(input())#数字のinputはintつけよう
x=[0]*N
y=[0]*N
for i in range(0,N):
    x[i],y[i]=map(int,input().split())
sum=0
count=0
for i in range(0,N):
    for j in range(0,N):
        sum+=math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)
        count+=1
print(sum*N/count)

Measured memory_bytes: 3064
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

const int N=1e7+19;

int A[N],n;

int main(){
	n=IN();
	for (int i=1,s=0;!A[n];i++){
		for (int j=s+1;j<=s+i&&j<=n;j++) A[j]=i;
		s+=i;
	}
	while (n){
		printf("%d\n",A[n]);
		n-=A[n];
	}
}

Measured memory_bytes: 39296
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int main() {
	int N;
	string S;
	cin >> N >> S;
	int ans=0;
	for(int i=0; i+2<N; ++i){
		if(S.substr(i, 3)=="ABC") ++ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

N = int(input())
W = [0]*N
for i in range(N):
    W[i] = input()
tail = W[0][-1]
past = [W[0]]
for i in range(1,N):
    head = W[i][0]
    if tail == head and not (W[i] in past):
        tail = W[i][-1]
        past.append(W[i])
    else:
        print('No')
        sys.exit()
print('Yes')

Measured memory_bytes: 3064
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>

using namespace std;

using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

int main(void){
   
   int n,m;
   cin>>n>>m;

   vector<string> a(n);
   vector<string> b(m);

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

   if(n==1 && m==1){
       if(a[0] == b[0]){
           cout<<"Yes"<<endl;
           return 0;
       }else{
           cout<<"No"<<endl;
           return 0;
       }
   }

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            int ans = a[i].compare(j,m,b[0]);
           // cout<<ans<<endl;
            if(ans==0){
                int b_c = 1;
                int a_c = i+1;
                while(b_c<m && a_c < n){
                    ans = a[a_c].compare(j, m, b[b_c]);
                    //cout<<"enter"<<ans<<endl;
                    if(ans == 0){
                        b_c++;
                        a_c++;
                    }else{
                        break;
                    }
                    if(b_c == m){
                        cout<<"Yes"<<endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, x, m;
  cin >> n >> x >> m;
  
  vector<vector<ll>> G(m);
  ll now = x, cyclelen, cycleacc, taillen, tailacc, keep;
  vector<ll> d(m, -1), acc(m);
  d[x] = 0;
  acc[x] = x;
  while (true) {
    ll next = (now * now) % m;
    if (d[next] == -1) {
      d[next] = d[now] + 1;
      acc[next] = acc[now] + next;
      now = next;
    }
    else {
      cyclelen = d[now] - d[next] + 1;
      cycleacc = acc[now] - acc[next] + next;
      keep = next;
      now = next;
      taillen = d[now];
      tailacc = acc[now] - now;
      break;
    }
  }
  
  ll ans = 0, res = n;
  if (res < taillen) {
    keep = x;
    while (res > 0) {
      ans += keep;
      res--;
      keep = keep * keep % m;
    }
  }
  else {
    ans += tailacc;
    res -= taillen;
    ll times = res / cyclelen;
    ans += cycleacc * times;
    res %= cyclelen;
    while (res > 0) {
      ans += keep;
      res--;
      keep = keep * keep % m;
    }
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 7136
l, r = map(int, input().split())
x = l % 2019
y = r % 2019
if x > y:
    y += 2019
ans = 10 ** 7
for i in range(x, y + 1):
    for j in range(x, y + 1):
        if ans > (i * j) % 2019 and i != j:
            ans = (i * j) % 2019
if l + 2019 < r:
    ans = 0
print(ans)

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W; cin >> H >> W;
    vector<string> S(H),T(H),U(H),V(W,""),X(W);
    for (int i=0;i<H;++i) cin >> S[i];
    for (int i=0;i<H;++i){
        T[i]=S[i]; sort(T[i].begin(),T[i].end());
    }
    int cnt=0,center=1,ok=1;
    vector<int> sym(H,-1);
    for (int i=0;i<H;++i){
        if (sym[i]>=0) continue;
        for (int j=i+1;j<H;++j){
            if (sym[j]>=0) continue;
            if (T[i]==T[j]){
                sym[j]=H-1-cnt;
                sym[i]=cnt++;
                break;
            }
        }
        if (sym[i]==-1){
            if (!center||!(H&1)) ok=0;
            else sym[i]=(H-1)/2,center=0;
        }
    }
    if (!ok){
        cout << "NO" << '\n';
        return 0;
    }
    for (int i=0;i<H;++i) U[sym[i]]=S[i];
    for (int i=0;i<W;++i){
        for (int j=0;j<H;++j) V[i]+=U[j][i];
        X[i]=V[i]; reverse(X[i].begin(),X[i].end());
    }
    center=-1; sym.assign(W,0);
    for (int i=0;i<W;++i){
        if (sym[i]) continue;
        for (int j=i+1;j<W;++j){
            if (sym[j]) continue;
            if (V[i]==X[j]){
                sym[i]=sym[j]=1;
                break;
            }
        }
        if (!sym[i]){
            if (center!=-1) ok=0;
            else center=i;
        }
    }
    if (center>=0&&V[center]!=X[center]) ok=0;
    cout << (ok?"YES":"NO") << '\n';
}

Measured memory_bytes: 256
# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


N, K = invr()
A = []
for i in range(N):
    A.append(inp())
A = sorted(A)
res = A[N-1] - A[0]
for i in range(N-K+1):
    d = A[i+K-1] - A[i]
    res = min(d, res)
print(res)


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

bool dp[510][510];

int main(void){
	string s;
	cin >> s;
	int n=s.size();
	for(int i=0;i<=n;++i) dp[i][i]=true;

	for(int d=3;d<=n;d+=3){
		for(int i=0;i<=n-d;++i){
			if(s[i]!='m') continue;
			if(s[i+d-1]!='w') continue;
			for(int j=i+1;j<i+d-1;++j){
				if(s[j]!='e') continue;
				dp[i][i+d]|=(dp[i+1][j]&&dp[j+1][i+d-1]);
			}
		}
	}
	if(dp[0][n])
		cout << "Cat" << endl;
	else
		cout << "Rabbit" << endl;
	return 0;
}

Measured memory_bytes: 1432
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

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

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;
    S.erase( unique(S.begin(), S.end()), S.end() );
    cout << SIZE(S) << endl;

    return 0;
}


Measured memory_bytes: 512
// Rustで競技プログラミングの入力をスッキリ記述するマクロ
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i64,
        a: [i64; n],
        q: i64,
        m: [i64; q],
    };
    fn calc(index: i64, a: &Vec<i64>, now: i64, i: i64) -> bool {
        if now == i {
            true
        } else if now > i {
            false
        } else if index < 0 {
            false
        } else {
            calc(index - 1, a, now + a.get(index as usize).unwrap(), i) || calc(index - 1, a, now, i)
        }
    }

    for i in m.iter() {
        println!("{}", if calc(n-1, &a, 0, *i) { "yes" } else { "no" });
    }
}



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

ll gcd(ll a, ll b)//最大公約数
{
  return b != 0 ? gcd(b, a % b) : a;
}


int main(void)
{
    int n;
    cin >> n;
    double ans = n;
    repd(i, 2, n+1)
    {
        if(n % (int)i == 0)
        {
            while(n % (int)i == 0)
            {
                n /= i;
            }
            ans *= (1 - 1/i);
        }
        //cout << ans << endl;
    }
    cout << (int)ans << endl;
}



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

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

  int out = 1;

  for (int i=1; i < N; i++){
    // i番目の山から海が見えるかどうか
    int visivle = 1;
    for (int j=0; j < i; j++){
      if (H[j] > H[i]){
        visivle = 0;
        break;
      }
    }
    if (visivle == 1){
      out += 1;
    }
  }

  cout << out << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

// x^n
int powmod(int x, int n) {
    constexpr int mod = 13;
    int ret = 1LL;
    int t = x % mod;
    while (n > 0) {
        if (n & 1LL) {
            ret *= t;
            ret %= mod;
        }
        t *= t;
        t %= mod;
        n >>= 1;
    }
    return ret;
}

int main() {
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    vector<vector<ll>> dp(s.size(), vector<ll>(13));
    if (s.front() == '?') {
        for (int i = 0; i < 10; ++i) {
            dp.front()[i] = 1;
        }
    } else
        dp.front()[s.front() - '0'] = 1;

    constexpr ll mod = 1000000007LL;
    for (int i = 1; i < s.size(); ++i) {
        for (int j = 0; j < 13; ++j) {
            if (s[i] == '?') {
                for (int k = 0; k < 10; ++k) {
                    int l = powmod(10, i) * k % 13;
                    dp[i][j] += dp[i - 1][((j - l) % 13 + 13) % 13];
                    dp[i][j] %= mod;
                }
            } else {
                int l = powmod(10, i) * (s[i] - '0') % 13;
                dp[i][j] = dp[i - 1][((j - l) % 13 + 13) % 13];
            }
        }
    }

    cout << dp.back()[5] << endl;
    return 0;
}

Measured memory_bytes: 15616
import java.util.Scanner;
public class Main {
    public static void main(String[] defargs) {
        Scanner scanner = new Scanner(System.in);
        int x,y;
        while(true){
           x = scanner.nextInt();
           y = scanner.nextInt();
          if ( x == 0 && y == 0 ) break;
        if(x > y){
            System.out.println(y + " " + x);
        }else{
            System.out.println(x + " " + y);
        }
      }
    }
}


Measured memory_bytes: 36480
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
int a[3],sum1,sum2;
int main()
{
	cin>>a[0]>>a[1]>>a[2];
	for(int i=0;i<3;i++)
	{
		if(a[i]==5)
			sum1++;
		if(a[i]==7)
			sum2++;
	}
	if(sum1!=2||sum2!=1)
		cout<<"NO"<<endl;
	else 
		cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 256