akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

struct union_find {
  vector<int> data;
  union_find(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
		            if (data[y] < data[x]) swap(x, y);
		            data[x] += data[y]; data[y] = x;
		          }
        return x != y;
      }
  bool findSet(int x, int y) {
        return root(x) == root(y);
      }
  int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
      }
  int size(int x) {
        return -data[root(x)];
      }
};

int main(){
	int n, k;
	cin >> n >> k;
	union_find u(200);
	for(int i=0; i < k; i++){
		int m, a; cin >> m;
		for(int j=0; j < m; j++){ cin >> a;  u.unionSet(100+i, a);}
	}
	bool usa[100];
	fill(usa, usa+100, true);
	int ret = 0;
	cin >> k;
	for(int i=0; i< k; i++){
		int a, b;
		cin >> a >> b;
		if(u.findSet(a, b)){usa[a] = false; usa[b] = false;}
	}
	for(int i=0; i< 100; i++) if(!usa[i]) ret++;
	cout << ret << endl;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
template <typename T>
T pow(T a, ll n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}
 
template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }
 
    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }
 
    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};
 
using mint = ModInt<1000000007>;
using Graph = vector<vector<int>>;
Graph G;
/*------------------------------------------------------------------*/
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll h, n; cin >> h >> n;
    vector<ll> a(n), b(n);
    ll max_a = 0;
    rep(i, n){
        cin >> a[i] >> b[i];
        max_a = max(max_a, a[i]);
    }
    vector<ll> dp(h + max_a);
    ll INF = 1e15;
    rep(i, h + max_a) dp[i] = INF;
    dp[0] = 0;
    
    rep(i, n)rep(j, h){
        if(j + a[i] < h + max_a) dp[j + a[i]] = min(dp[j + a[i]], dp[j] + b[i]);
    }
    ll ans = INF;
    _rep(i, h, h + max_a) ans = min(ans, dp[i]);
    cout << ans << endl;
}

Measured memory_bytes: 3772
#include"bits/stdc++.h"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill( (T*)array, (T*)(array+N), val ); }
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9+7
int main() {
    int n;
    cin >> n;
    ll sum = 1;
    ll sum2 = 1;
    ll sum3 = 2;
    REP(i, n) {
        sum *= 10;
        sum %= mod;
        sum2 *= 8;
        sum2 %= mod;
        sum3 *= 9;
        sum3 %= mod;
    }
    sum += sum2;
    sum %= mod;
    sum -= sum3;
    sum %= mod;
    if (sum < 0)sum += mod;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define FAIL0 {cout << "0\n"; return 0;}
#define FAIL1 {cout << "-1\n"; return 0;}
#define FAILNO {cout << "No\n"; return 0;}
#define YES {cout << "Yes\n"; return 0;}

const int MAXN = 1e5+4;
const int MOD = 1e9+7;

int N,M;
vector<int> P[MAXN];
LL ans;

int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> M;
    fori(i,N) {
        int a,b; 
        cin >> a >> b;
        if (a <= M) P[M-a].pb(b);
    }

    multiset<int> S;
    ford(i,M-1) {
        S.insert(P[i].begin(),P[i].end());
        if (S.size()) {
            auto it = prev(S.end());
            ans += *it;
            S.erase(it);
        }
    }

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


Measured memory_bytes: 7808
n = int(input())
m =  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5]

print(m[n - 1])

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
typedef long long ll;

ll a,b,n;
	
int main()
{
	cin>>a>>b>>n;
	if(n<b)
	{
		cout<<(a*n)/b-a*(n/b);
	}
	else
	{
		cout<<(a*(b-1))/b-a*((b-1)/b);
	}
//	for(ll i=n;i>=0;i--)
//	{
//		if((a*i)/b-a*(i/b)>=0)
//		{
//			cout<<i<<endl;
//			cout<<(a*i)/b-a*(i/b);
//			break;
//		}
//	}
	return 0;
}

Measured memory_bytes: 3572
n = input()
bars = map(int,raw_input().split(' '))
bars.sort()
h1_cand=0
h2_cand=0
h1=0
h2=0
for i in range(n):
  m = n-1-i
  if h1 > 0:
    if h2_cand == bars[m]:
      h2 = h2_cand
      break
    else:
      h2_cand = bars[m]
  else:
	if h1_cand == bars[m]:
    	  h1 = h1_cand
    	  h1_cand = 0
  	else:
    	  h1_cand = bars[m]
 
print h1*h2


Measured memory_bytes: 11320
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

struct XY {
    long double x;
    long double y;
};

int main() {
    int N;
    cin >> N;
    
    vector<vector<long double> > COSTS(N, vector<long double>(N, 0));
    vector<XY> pos(N);
    vector<int> num(N);
    long double SUM=1;
    for(int n=0; n<N; n++) {
        cin >> pos[n].x >> pos[n].y;
        num[n] = n;
        SUM *= (n+1);
    }

    // cout << SUM << endl;
    
    for(int n1=0; n1<N-1; n1++) {
        for(int n2=n1+1; n2<N; n2++) {
            COSTS[n1][n2] = sqrtl(powl(pos[n1].x-pos[n2].x, 2)+powl(pos[n1].y-pos[n2].y, 2));
            COSTS[n2][n1] = sqrtl(powl(pos[n1].x-pos[n2].x, 2)+powl(pos[n1].y-pos[n2].y, 2));
        }
    }
    
    
    long double ans=(long double)0;
    do {
        for(int n1=0; n1<N-1; n1++) {
            ans += COSTS[num[n1]][num[n1+1]];
        }
    } while(next_permutation(num.begin(), num.end()));
    
    cout << setprecision(20) << ans/SUM << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  int A, B;
  int a[10];
  cin >> A >> B;
  
  int cnt=0;
  for(int i=A; i<=B; i++){
    int rep = i;
    for(int j=0; j<5; j++){
      a[j] = rep%10;
      rep = rep/10;
    }
    if(a[0] == a[4] && a[1] == a[3]) cnt++;
  }
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int>P;
#define PI 3.14159265359
#define MOD 1000000007
const int MAX = 510000;

int main(){
  int N;cin >>N;
  vector<string>a(N);
  map<string,ll>mp;
  rep(i,N){
    string s;cin>>s;
    sort(s.begin(),s.end());
    a[i]=s;
    mp[s]++;
  }
  ll ans=0;
 	for(auto p : mp){
        ans += p.second*(p.second-1)/2;
    }
  cout<<ans;
}

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

int N, arr[201], cnt;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    for(int i = 1; i <= 200; i++) {
        for(int j = 1; j <= 200; j+=2)
            if(j % i == 0) arr[j]++;
    }
    cin>>N;
    for(int i = 1; i <= N; i++) {
        if(arr[i] == 8) {
            cnt++;
        }
    }
    cout<<cnt<<'\n';

    return 0;
}

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

namespace ConsoleApp15
{
    class Class189
    {
        static void Main()
        {
            var HN = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            int H = HN[0], N = HN[1];
            var dp = Enumerable.Repeat(int.MaxValue, H + 1).ToArray();
            dp[0] = 0;
            for(int i = 0; i < N; i++)
            {
                var ab = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
                int a = ab[0], b = ab[1];
                for(int j = 0; j < H; j++)
                {
                    if (dp[j] != int.MaxValue)
                    {
                        var v = Math.Min(H, j+a);
                        dp[v] = Math.Min(dp[v], dp[j] + b);
                    }
                }
            }
            Console.WriteLine(dp[H]);
        }
    }
}


Measured memory_bytes: 13340
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
using namespace std;

int main (void) {
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  int ans=0;
  for (int i=0; i<=a; i++) {
    for (int j=0; j<=b; j++) {
      for (int k=0; k<=c; k++) {
        if (500*i+100*j+50*k == x) ans=ans+1;
      }
    }
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
L = 0
R = N

for i in range(M):
    L_new, R_new = map(int, input().split())
    if L < L_new:
        L = L_new
    if R_new < R:
        R = R_new

if L > R:
    print(0)
else:
    print(R-L+1)

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

int main(){
  int A,B,C,D;
  cin >> A >> B >>C >>D;
  int AB = A*B;
  int CD = C*D;
  if(AB >= CD) cout << AB;
  else if(AB <CD) cout << CD;

  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> 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; }

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    string s[100];
    REP(i,100) REP(j,100){
        if(i<50) s[i].push_back('.');
        else s[i].push_back('#');
    }
    int cnt=0;
    for(int i=0;i<50;i+=2){
        if(cnt==b-1) break;
        for(int j=0;j<100;j+=2){
            if(cnt==b-1) break;
            s[i][j] = '#';
            cnt++;
        }
    }
    cnt=0;
    for(int i=51;i<100;i+=2){
        if(cnt==a-1) break;
        for(int j=0;j<100;j+=2){
            if(cnt==a-1) break;
            s[i][j]='.';
            cnt++;
        }
    }
    cout<<100<<" "<<100<<endl;
    REP(i,100) cout<<s[i]<<endl;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(!i){
      if(a[i]){
        cout << -1 << endl;
        return 0;
      }
    }
    else{
      if(a[i-1]<a[i]){
        if(a[i-1]+1!=a[i]){
          cout << -1 << endl;
          return 0;
        }
      }
    }
  }
  long long ans=0;
  for(int i=1;i<n;i++){
    if(a[i-1]+1==a[i]){
      ans++;
    }
    else{
      ans+=a[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef unordered_set<ll> uset;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=0;i<=n;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x.begin(),x.end()
#pragma gcc optimize("O3")
#pragma gcc optimize("unroll-loops")
#pragma gcc target("avx2,see4")
#define M 210
int n;
bool thedge(ll a,ll b){//頂点aと頂点bの間に辺があるか
	string s="";
	rep(i,n)s+="0";
	s[a]=s[b]='1';
	cout<<"? "<<s<<"\n"<<flush;
	ll res;
	cin>>res;
	return res==1;
}
bool thedge_set(set<ll> S,ll x){//独立集合Sのいずれかと頂点xの間に辺があるか
	S.insert(x);
	string s="";
	rep(i,n)s+="0";
	for(auto t:S)s[t]='1';
	cout<<"? "<<s<<"\n"<<flush;
	ll res;
	cin>>res;
	return res>=1;
}

vector<ll> FANS_A,FANS_B;//FANS_A[i]とFANS_B[i]の間に辺がある
void dfs(ll x,set<ll> S){//xとSの間の辺を探す(一つはある）
	if(S.size()==1){
		FANS_A.push_back(x);
		FANS_B.push_back(*S.begin());
		return;
	}
	set<ll> L,R;
	bool flag=0;
	for(auto s:S){
		if(flag)L.insert(s);
		else R.insert(s);
		flag=flag^1;
	}
	if(thedge_set(L,x))dfs(x,L);
	if(thedge_set(R,x))dfs(x,R);
}
int main(){
	cin>>n;
	vector<ll> v[M];//v[d]:=0を根として深さdの頂点のidの集合
	{//2000~4500回でv[]を求める
		v[0].push_back(0);
		set<ll> cand;//まだ決まっていないもの
		for(int i=1;i<n;i++)cand.insert(i);
		for(ll d=0;d<M;d++){
			if(cand.size()==0)break;
			set<ll> cur;
			for(auto x:v[d])cur.insert(x);
			for(auto x:cand){
				if(thedge_set(cur,x)){
					v[d+1].push_back(x);
				}
			}
			for(auto x:v[d+1])cand.erase(x);
		}
	}
	{//dとd+1の間の辺を求める
		for(ll d=0;d<M;d++){
			if(v[d+1].size()==0)break;
			set<ll> A,B;
			for(auto x:v[d])A.insert(x);
			for(auto x:v[d+1])B.insert(x);
			for(auto x:B){
				if(thedge_set(A,x))dfs(x,A);
			}
		}
	}
	cout<<"!";
	for(int i=0;i<n-1;i++){
		cout<<" ("<<FANS_A[i]<<","<<FANS_B[i]<<")";
	}
	cout<<"\n"<<flush;
}


Measured memory_bytes: 852
#include <iostream>

using namespace std;
typedef unsigned long long ll;

ll pow(ll v, ll a){
    ll x = 1;
    for(int i=0;i<a;++i){
        x *= v;
    }
    return x;
}

int main()
{
    ll N;
    cin >> N;
    if (N % 2){
        cout << 0 << endl;
    }
    else{
        ll a=1, ans = 0;
        ll i=1;
        while(N / a != 0){
            a = pow(5, i) * 2;
            ans += N / a;
            ++i;
        }
        cout << ans << endl;
    }
}


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

int main(void) {
  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, 0, N) cin >> A[i];
  vector< vector<ll> > E(N);
  REP(i, 0, N - 1) {
    ll A, B;
    cin >> A >> B; A--; B--;
    E[A].push_back(B);
    E[B].push_back(A);
  }

  ll root = 0;
  REP(i, 0, N) if(E[i].size() == 1) root = i;

  function<ll (ll, ll, bool&)> dfs = [&](ll v, ll p, bool &ok) {
    if(v != root && E[v].size() == 1) return A[v];
    vector<ll> c;
    for(ll u : E[v]) if(u != p) c.push_back(dfs(u, v, ok));
    ll sum = accumulate(c.begin(), c.end(), 0LL);
    ll t = A[v] * 2 - sum;
    ok = ok && 0 <= t && t <= A[v];
    REP(i, 0, c.size()) ok = ok && 0 <= c[i] && c[i] <= A[v];
    return t;
  };

  bool ok = true;
  cout << (dfs(root, -1, ok) == A[root] && ok ? "YES" : "NO") << endl;
}


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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
  string s,t;
  cin>>s>>t;
  ll sl=s.size(),tl=t.size();
  vector<vector<ll>> v(26);
  for(ll i = 0LL; i < sl;i++){
    v[s[i]-'a'].push_back(i);
  }
  ll cnt = 0LL;
  ll k = -1LL;
  bool can = true;
  for(ll i = 0LL; i < tl;i++){
    ll n = t[i]-'a';
    if((int)v[n].size()==0) {
      can=false;
      break;
    }
    if(upper_bound(v[n].begin(),v[n].end(),k)==v[n].end()){
      cnt++;
      k=v[n][0];
    }
    else k=*upper_bound(v[n].begin(),v[n].end(),k);
  }
  if(!can) cout<<-1<<endl;
  if(can)cout<<sl*cnt+k+1LL<<endl;
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};


int N;
vector<pint> A;

signed main(){
    cin >> N;
    int a;
    REP(i, N){
        cin >> a;
        A.push_back(pint(a, i));
    }
    sort(ALL(A), greater<pint>());
    REP(i, N){
        if(A[0].second == i){
            PRINT(A[1].first);
        }else{
            PRINT(A[0].first);
        }
    }
    return 0;
}

Measured memory_bytes: 3312
#include<bits/stdc++.h>
using namespace std;
vector<int>v[200001],vv;
pair<int,int>p[200001];
int n,x,y,ans[200001];
void dfs1(int x,int pre,pair<int,int>ma)//走的房间个数跟它父亲结点前缀的最大值有关，找出每个结点的最大前缀
{
    if(x>ma.second) ma.second=x;
    if(ma.second>ma.first) swap(ma.first,ma.second);
    p[x]=ma;
    for(int i=0;i<v[x].size();i++)
        if(v[x][i]!=pre) dfs1(v[x][i],x,ma);
}
void dfs2(int x,int pre)
{
    vv.push_back(x);
    if(x!=1)
    {
        int l=0,r=vv.size()-1,m;
        while(r-l>1)
        {
            m=l+r>>1;
            int t=vv[m];
            if(p[t].first!=t&&p[t].first==p[x].first||p[t]==p[x]) r=m;
            //父亲结点前缀值满足单调性，前缀最大值相同的结点要走的路径只要入口转移，因此二分计算入口结点是哪个，只在入口结点加入要经过点的信息
            else l=m;
        }
        ans[vv[r]]++;
    }
    for(int i=0;i<v[x].size();i++)
        if(v[x][i]!=pre) dfs2(v[x][i],x);
    vv.pop_back();
}
void dfs3(int x,int pre)
{
    ans[x]+=ans[pre];//把入口结点的值转移过来
    for(int i=0;i<v[x].size();i++)
        if(v[x][i]!=pre) dfs3(v[x][i],x);
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<n;i++) scanf("%d%d",&x,&y),v[x].push_back(y),v[y].push_back(x);
    dfs1(1,0,make_pair(0,0));
    dfs2(1,0);
    dfs3(1,0);
    for(int i=2;i<=n;i++) printf(i==n?"%d\n":"%d ",ans[i]);
}


Measured memory_bytes: 31480
// Created by ...Lusifer
#include<bits/stdc++.h>
using namespace std;
 
#define pb 		push_back
#define mp 		make_pair
#define prior   priority_queue
#define MOD 	1000000007
#define INF64 	(long long)1e18
#define INF 	(int)1e9
#define PI 		3.1415926535897932384626433832795 
#define ll      long long
#define ld		long double
#define ret     return
#define NUM 	1000001
const int SIZE = 2e5+4;
void fastio(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

void solveTest(){
	int a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	if(s[a]!='-'){
		cout<<"No"<<endl;
		return;
	}
	for(int i=0;i<s.size();i++){
		if(i!=a){
			int l = (int)s[i]-48;
			//cout<<l<<" ";
			if(l>=0 && l<=9){
				continue;
			}
			else {
				cout<<"No"<<endl;
				return;
			}
		}
	}
	cout<<"Yes"<<endl;	
	return ;
}
 
int main(){
	fastio();

	int t=1;
	//cin>>t;
	while(t--){
		solveTest();
 
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
int gcd(int x, int y, int z){
    return (int)__gcd(x, __gcd(y, z));
}
int main(){
    int n; cin >> n;
    int64 sum = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            for(int k = 1; k <= n; k++){
                sum += gcd(i, j, k);
            }
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <stdio.h>

int main(void){
  int A,B,C;
  scanf("%d%d%d",&A,&B,&C);

  if(A < C && C < B) printf("Yes\n");
  else if(B < C && C < A) printf("Yes\n");
  else printf("No\n");

  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;

const int N = 105;

string s;
int n, a[N], ans;
int main()
{
	cin >> n;
	for(int i = 0; i < n; ++i) cin >> a[i];
	for(int i = 0; i < n; ++i)
		for(int j = i + 1; j < n; ++j)
			for(int k = j + 1; k < n; ++k)
				if(a[i] < a[j] + a[k]) if(a[k] < a[i] + a[j]) if(a[j] < a[k] + a[i])
					if(a[i] != a[j] && a[j] != a[k] && a[k] != a[i])
					++ans;
	cout << ans;
	return 0;
}


Measured memory_bytes: 3612
#!/usr/bin/env python3
def main():
    N, M, K = map(int, input().split())
    m = 10**9+7
    # 方針: ２つの駒の距離だけ考えれば良い、それ以外K-2個の駒の位置が(N*M-2)C(K-2)通りある
    # マンハッタン距離はx方向とy方向を独立に扱える
    ans = 0
    for d in range(1,M):
        ans += (d*(M-d)%m) * pow(N,2,m) % m
        ans %= m

    for d in range(1,N):
        ans += (d*(N-d)%m) * pow(M,2,m) % m
        ans %= m

    # 答えに(NM-2)C(K-2)かける
    # K回しか処理しないから間に合う
    for r in range(K-2):
        ans *= ((N*M%m-2)%m-r)%m
        ans %= m
        ans *= pow(r+1,m-2,m)
        ans %= m
    print(ans)

if __name__ == "__main__":
    main()


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
#define MAX 999999999

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};

typedef long long ll;

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

    int ab, bc, ca;
    cin >> ab >> bc >> ca;
    cout << ab * bc / 2 << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0315
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(RArInt().Sum());
        }
        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}



Measured memory_bytes: 18260
#include <algorithm> // min
#include <cmath> // abs
#include <iostream>
using namespace std;
int main(){
string S;
cin >> S;
int N = S.size();
int ans = 999;
for(int i = 0; i <= N - 3; ++i){
int num = (S[i] - '0') * 100 + (S[i+1] - '0') * 10 + S[i+2] - '0';
ans = min(ans, abs(num - 753));
}
cout << ans << endl;
}


Measured memory_bytes: 256
import math
import copy

n=int(input())

i=int(n**0.5)
j=0
# print(i)

for i in range(i+1,0,-1):
    # print(i)
    if n==i:
        print(n-1)
        break
    if n%i==0:
        j=n/i
        print(int(i+j-2))
        break


Measured memory_bytes: 40172
import java.io.*;
import java.util.*;
import static java.lang.System.in;

public class Main {
    ArrayList<Integer>[] tree;
    long maxN = 1000007;
    int[] edgeColor;
    int maxColor = 1;
    HashMap<Long, Integer> edgeRec = new HashMap<>();
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
//        System.out.println(main.solve());
    }
    long solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        edgeColor = new int[n+1];
        tree = new ArrayList[n+1];
        for(int i=0;i<=n;i++) tree[i] = new ArrayList<Integer>();
        for(int i=0;i<n-1;i++){
            int a = sc.nextInt(), b = sc.nextInt();
            // already know that a<b
            tree[a].add(b); tree[b].add(a);
            edgeRec.put(a*maxN+b, i);
        }
        dfs(1,-1,-1);
        PrintWriter out = new PrintWriter(System.out);
        out.println(maxColor);
        for(int i=0;i<n-1;i++){
            out.println(edgeColor[i]);
        }
        out.flush();
        out.close();
        return 0;
    }
    void dfs(int cur, int from, int fromColor){
        int color = 1;
        for(int to:tree[cur]){
            if(to==from) continue;
            if(color==fromColor) color += 1;
            maxColor = Math.max(maxColor, color);
            long key = Math.min(cur,to)*maxN+Math.max(cur,to);
            int edgeNum = edgeRec.get(key);
            edgeColor[edgeNum] = color;
            dfs(to, cur, color);
            color += 1;
        }
    }
}



Measured memory_bytes: 109376
#include<bits/stdc++.h>
using namespace std;
int a[10];
int num[10];
int cnt;
bool flag(){
  for(int i=0;i<9;i++){
    if(a[i]==-1) return false;
  }
  return true;
}
void dfs(int k){
  for(int i=k;i<9;i++){
    if(a[i]==-1){
      for(int j=1;j<10;j++){
	if(num[j]==0){
	  a[i]=j;
	  num[j]=1;
	  dfs(i);
	  num[j]=0;
	  a[i]=-1;
	}
      }
    }
    if(i==8 && flag()){
      if(a[0]+a[1]*10+a[2]+a[3]*100+a[4]*10+a[5]==a[6]*100+a[7]*10+a[8]){
	//cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<a[3]<<" "<<a[4]<<" "<<a[5]<<" "<<a[6]<<" "<<a[7]<<" "<<a[8]<<endl;
	cnt++;
      }
    }
  }
}
      
int main(){
  for(int i=0;i<9;i++){
    cin>>a[i];
    num[a[i]]=1;
  }
  dfs(0);
  cout<<cnt<<endl;
  return 0;
}
  
  



Measured memory_bytes: 3120
#include <iostream>

using namespace std;

int main() {
  int w, h, n;
  cin >> w >> h >> n;

  int w_max = w;
  int w_min = 0;
  int h_max = h;
  int h_min = 0;

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

    if (a == 1 && x > w_min) {
      w_min = x;
    } else if (a == 2 && x < w_max) {
      w_max = x;
    } else if (a == 3 && y > h_min) {
      h_min = y;
    } else if (a == 4 && y < h_max) {
      h_max = y;
    }   
  }
  if (w_max - w_min < 0 || h_max - h_min < 0) {
    cout << 0 << endl;
    return 0;
  }

  cout << (w_max - w_min) * (h_max - h_min) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    string r=s;
    reverse(r.begin(),r.end());
    int n;
    cin>>n;
    int t,f;
    string ch;
    int flag=0;
    while(n--)
    {
       cin>>t;
       
       if(t==1)
       {
          flag=(flag^1);
       }
       if(t==2)
       {
          cin>>f;
          cin>>ch;
          if(f==1)
          {  if(flag==0)
             { 
              ch+=s;
            
              s=ch;
             }
           else
           {
              s+=ch;
             
           }}
          else
           { if(flag==0){
               s+=ch;
               }
            else
            {
                
              ch+=s;
            
           s=ch; 
            }}
       }
    }
    if(flag==1)
     reverse(s.begin(),s.end());
    cout<<s<<endl;
}

Measured memory_bytes: 4124
use proconio::input;

fn main() {
  input! {
    n: usize,
    k: usize,
    s: String
  }
  let mut chars: Vec<char> = s.clone().chars().collect();
  
  let mut compresses: Vec<usize> = vec![];
  let mut consective = 1;
  let mut last = chars.remove(0);
  for c in chars {
    if c == last {
      consective += 1;
    } else {
      compresses.push(consective);
      last = c;
      consective = 1;
    }
  }
  compresses.push(consective);
  let len = compresses.len();
  if len <= k * 2 {
    println!("{}", s.len() - 1);
    return
  }
  
  let mut result = k * 2;
  for v in compresses {
    result += v - 1;
  }
  
  println!("{}", result);
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t={"keyence"};
    cin>>s;
    int a=s.size()-7;
    for(int i=0;i<s.size()-a;i++){
        int c=0;
        for(int j=0;j<s.size();j++){
            if(i>j || j>=i+a){
                if(s[j]==t[c]){
                    c++;
                }
            }
        }
        if(c==7){
            cout<<"YES"<<endl;
            return(0);
        }
    }
    cout<<"NO"<<endl;
    return(0);
}

Measured memory_bytes: 3632
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//ABC174D

//ABC174C

//ABC174B

//ABC174A
int main(void) {
  int n, k, i, cou=0, tmp;
  scanf("%d", &n);
  if(n>=30)  printf("Yes");
  else printf("No");
}


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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()
#define SIZE(a,n) (a).resize(n)

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

using namespace std;

typedef long long int lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > Matrix;



int main() {
	int n, a, b;

	cin >> n >> a >> b;

	cout << min(a*n, b);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n, ma, mb; cin >> n >> ma >> mb;
  vll a(n), b(n), c(n);
  REP(i, n) cin >> a[i] >> b[i] >> c[i];
  V<vvll> dp(n+1, vvll(401, vll(401, HIGHINF)));
  dp[0][0][0] = 0;
  REP(i, n) {
    REP(j, 401) REP(k, 401) {
      chmin(dp[i+1][j][k], dp[i][j][k]); // 使わない時
      if (j+a[i] <= 400 && k+b[i] <= 400)
        chmin(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k] + c[i]); // 使う時
    }
  }

  ll ans = HIGHINF;
  rep(j, 1, 401) {
    if ((mb*j) % ma != 0) continue;
    ll b = mb*j / ma;
    if (b > 400) continue;
    if (dp[n][j][b] >= HIGHINF) continue;
    chmin(ans, dp[n][j][b]);
  }
  if (ans == HIGHINF) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


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

int main(){
  int A , B , K;
  cin >> A >> B >> K;
  for(int i = min(A , B); i >= 1; i--){
    if(A % i == 0 && B % i == 0){
      K--;
      if(K == 0){
        cout << i << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
using namespace std;
typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e18;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

int main(){
    ll a, b, k; cin >> a >> b >> k;
    vl res;
    FOR(i, 1, 101){
        if(a % i == 0 && b % i == 0) res.pb(i);
    }
    sort(res.begin(), res.end(), greater<ll>());
    cout << res[k-1] << endstr;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin >> n;
  vector<int> p(n),q(n),a(n);
  for(int i=0;i<n;i++)cin >> p[i];
  for(int i=0;i<n;i++)cin >> q[i];
  for(int i=0;i<n;i++)a[i]=i+1;
  int s,t,cnt=0;
  do{
    bool e=true,f=true;
    cnt++;
    for(int i=0;i<n;i++){
      if(p[i]!=a[i]){
        e=false;
      }
      if(q[i]!=a[i]){
        f=false;
      }
    }
    if(e)s=cnt;
    if(f)t=cnt;
  }while(next_permutation(a.begin(),a.end()));
  cout << abs(t-s) << endl;
}


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

int main() {
  int mi=1000,mx=0;
  int n;
  cin >> n;
  for ( int i=0; i<n; i++ ) {
	int x;
    cin >> x;
    mi=min(mi,x);
    mx=max(mx,x);
  }
  cout << mx-mi << '\n';
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  int ans=0;
  for(int i=1;i<=N;i++){
    int a;
    cin >> a;
    if((i%2!=0)&&(a%2!=0)){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
tailrec fun calc(h: Long, cur: Long = 0L): Long = if (h == 1L) (1..cur).fold(1L)
        { acc, v -> acc * 2 + 1 }
    else
        calc(h / 2, cur + 1)

fun main(args: Array<String>) {
    readLong().let { calc(it) }.let(::println)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 33508
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using StructLayoutAttribute = System.Runtime.InteropServices.StructLayoutAttribute;
using FieldOffsetAttribute = System.Runtime.InteropServices.FieldOffsetAttribute;

class P
{
    static void Main()
    {
        var abq = Console.ReadLine().Split().Select(int.Parse).ToList();
        List<long> s = Enumerable.Repeat(long.MinValue / 8, 1).Concat(Enumerable.Repeat(0, abq[0]).Select(_ => long.Parse(Console.ReadLine()))).Concat(Enumerable.Repeat(long.MaxValue / 8, 1)).ToList();
        List<long> t = Enumerable.Repeat(long.MinValue / 8, 1).Concat(Enumerable.Repeat(0, abq[1]).Select(_ => long.Parse(Console.ReadLine()))).Concat(Enumerable.Repeat(long.MaxValue / 8, 1)).ToList();
        for (int i = 0; i < abq[2]; i++)
        {
            long query = long.Parse(Console.ReadLine());
            int sres = s.BinarySearch(query);
            if (sres < 0) sres = ~sres;
            int tres = t.BinarySearch(query);
            if (tres < 0) tres = ~tres;
            Console.WriteLine(Min(Min(GetDist(query, s[sres - 1], t[tres - 1]), GetDist(query, s[sres], t[tres - 1])), Min(GetDist(query, s[sres - 1], t[tres]), GetDist(query, s[sres], t[tres]))));

        }
    }
    static long GetDist(long q, long s, long t) => Min(Abs(q - s) + Abs(s - t), Abs(q - t) + Abs(t - s));
}


class PartialPersistentUnionFind
{
    public int Now { get; private set; }
    public int Size { get; private set; }
    int[] Parents;
    int[] Time;
    int[] Sizes;
    List<Tuple<int, int>>[] SizeHistories;

    public PartialPersistentUnionFind(int size)
    {
        Size = size;
        Parents = Enumerable.Range(0, Size).ToArray();
        Time = Enumerable.Repeat(int.MaxValue, Size).ToArray();
        Sizes = Enumerable.Repeat(1, Size).ToArray();
        SizeHistories = Enumerable.Repeat(0, Size).Select(_ => new List<Tuple<int, int>>() { new Tuple<int, int>(0, 1) }).ToArray();
    }

    public bool TryUnite(int x, int y)
    {
        Now++;
        x = Find(x);
        y = Find(y);
        if (x == y) return false;
        if (Sizes[x] < Sizes[y])
        {
            var tmp = x;
            x = y;
            y = tmp;
        }
        Parents[y] = x;
        Time[y] = Now;
        Sizes[x] += Sizes[y];
        SizeHistories[x].Add(new Tuple<int, int>(Now, Sizes[x]));
        return true;
    }
    public int Find(int i, int t = int.MaxValue - 1) => Time[i] <= t ? Find(Parents[i], t) : i;
    public int GetSize(int i, int t = int.MaxValue - 1)
    {
        var root = Find(i, t);
        return SizeHistories[root][~SizeHistories[root].BinarySearch(new Tuple<int, int>(t, int.MaxValue)) - 1].Item2;
    }
}

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

int main() {
    int A, B, counter = 0;
    cin >> A >> B;

    for (int i = A; i <= B; i++) {
        if (i / 10000 == i % 10 && i / 1000 % 10 == i % 100 / 10) counter++;
    }
    cout << counter;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

ll lcm(ll a, ll b){
	return (ll)((a / gcd(a, b)) * b);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, m;
	cin >> n >> m;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	ll lc = 1LL;
	rep(i, n){
		if(lc > m){
			cout << 0 << endl;
			return 0;
		}
		lc = lcm(lc, a[i] / 2);
	}
	rep(i, n) if(lc % a[i] == 0){
		cout << 0 << endl;
		return 0;
	}
	ll l = 0, r = 1.1e9;
	while(l < r){
		ll mid = (l + r + 1) / 2;
		if(((mid * 2 - 1) * lc) <= m) l = mid;
		else r = mid - 1;
	}
	cout << l << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 1024
import math
a , b = map(int,input().split())
res = list(map(int,input().split()))
res2 = []
if len(res) == 1:
    print(0)
else:
    for i in range(len(res)-1):
        aa = res[i+1] - res[i]
        res2.append(aa)
    if res[0] == 0:
        res2.append(a-res[-1])
    else:
        res2.append(res[0] + (a - res[-1]))
print(sum(res2) - max(res2))

Measured memory_bytes: 26444
#include <bits/stdc++.h>
using namespace std;
int main() {

  int s;
  int i = 2;
  int a[1000005];
  int ans;
  int flag = 0;

  cin >> s;

  a[1] = s;

  while ( 1 ) {
    if ( a[i-1] % 2 == 0 ) {
      a[i] = a[i-1]/2;
    } else {
      a[i] = 3*a[i-1]+1;
    }
    for ( int j = 1; j < i; ++j ) {
      if ( a[i] == a[j] ) {
	ans = i;
	flag = 1;
	break;
      }
    }
    if ( flag == 1 ) break;
    ++i;
  }

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 256
import java.util.*;
 
class Main{
    Scanner sc = new Scanner(System.in);
 
    Main(){
    int a=sc.nextInt();
    int b=sc.nextInt();
    System.out.print( (a/b)+" "+(a%b)+" " );
    System.out.printf("%.8f\n", (double)a/b );
    }
 
    public static void main(String[] args){
    new Main();
    }
}


Measured memory_bytes: 26640
import * as fs from 'fs';

//in
// 10
// ZABCDBABCQ
//out
// 2
function main(inp: string): void {
    const n: number = parseInt(inp.split('\n')[0]);
    const s: string = inp.split('\n')[1];

    let ans: number = 0;
    let idx: number = 0;
    while (s.indexOf('ABC', idx) > -1) {
        ans++;
        idx = s.indexOf('ABC', idx) +1;
    }
    console.log(ans);
}

main(fs.readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
using System;
using System.Collections.Generic;
using System.Linq;
using static Constans;

public static class Constans
{
    public const long Mod = (long)1e9 + 7;
}

public class Combination
{
    private readonly long[] Fact;
    private readonly long[] InvFact;  // モジュラ逆数

    public Combination(long n)
    {
        Fact = new long[n + 1];
        InvFact = new long[n + 1];

        long f = 1;
        Fact[0] = f;
        for (long i = 1; i <= n; i++)
        {
            f *= i;
            f %= Mod;
            Fact[i] = f;
        }

        long inv = ModInt.GetInv(f).Num;

        InvFact[n] = inv;
        for (long i = n - 1; i >= 0; i--)
        {
            InvFact[i] = (InvFact[i + 1] * (i + 1)) % Mod;
        }
    }

    // nCr
    public ModInt GetCombination(long n, long r)
    {
        var comb = Fact[n] * InvFact[r] % Mod;
        comb = comb * InvFact[n - r] % Mod;
        return new ModInt(comb);
    }
}

public struct ModInt
{
    public long Num;

    public ModInt(long num)
    {
        Num = num;
    }

    // x^n
    public static long Power(long x, long n)
    {
        long pow = 1;
        while (n > 0)
        {
            if (n % 2 == 0)
            {
                x *= x;
                x %= Mod;
                n /= 2;
            }
            else
            {
                pow *= x;
                pow %= Mod;
                n--;
            }
        }

        return pow;
    }

    public static ModInt GetInv(long f)
    {
        // フェルマーの小定理 a^(-1) = a^(mod-2)
        return new ModInt(Power(f, Mod - 2));
    }

    public ModInt GetInv()
    {
        return GetInv(Num);
    }

    public override string ToString()
    {
        return Num.ToString();
    }

    public static ModInt operator +(ModInt l, ModInt r)
    {
        l.Num += r.Num;
        if (l.Num >= Mod)
        {
            l.Num -= Mod;
        }
        return l;
    }

    public static ModInt operator -(ModInt l, ModInt r)
    {
        l.Num -= r.Num;
        if (l.Num < 0)
        {
            l.Num += Mod;
        }
        return l;
    }

    public static ModInt operator *(ModInt l, ModInt r)
    {
        return new ModInt(l.Num * r.Num % Mod);
    }

    public static implicit operator ModInt(long n)
    {
        n %= Mod;
        if (n < 0)
        {
            n += Mod;
        }
        return new ModInt(n);
    }
}

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var X = vals[0];
        var Y = vals[1];
        // 左下へ
        var ly = X + Y;
        // y = 2x と y = -x + ly の交点を求める
        // 3x = ly
        if (ly % 3 != 0)
        {
            Console.WriteLine(0);
            return;
        }
        var cx = ly / 3;
        var cy = 2 * cx;
        if (!(cx <= X && X <= cy && cx <= Y && Y <= cy))
        {
            Console.WriteLine(0);
            return;
        }
        // パスカルの三角形より値を得る
        var n = cx + 1;
        var k = X - cx + 1;
        var pattern = new Combination(n).GetCombination(n - 1, k - 1);

        Console.WriteLine(pattern);
    }
}

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

using namespace std;

int chmin(int a, int b){
    if(a>b) return b;
    return a;
}


int main(){
    int N; cin >> N;
    vector<int> B(N-1);
    for(int i=0; i<N-1; i++) cin >> B.at(i);
    
    int sum = 0;
    
    for(int i=0; i<N-2; i++){
        sum += chmin(B.at(i), B.at(i+1));
    }
    sum += B.at(0) + B.at(N-2);
    
    cout << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

void Compute(ll h,ll n)
{
    vl v(n);
    ll sum = 0;
    pragi(0,n)
    {
        cin>>v[i];
        sum+=v[i];
    }
    if(sum >= h) cout<<"Yes"<<"\n";
    else cout<<"No"<<"\n";
}
int main()
{
    KAKA
    ll h,n;
    cin>>h>>n;
    Compute(h,n);
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
H,W=map(int,input().rstrip().split())
S=[input().rstrip() for _ in range(H)]
c=[[0 for _ in range(W)] for __ in range(H)]
dx=[0,1,1,1,0,-1,-1,-1]#12時から時計回り
dy=[1,1,0,-1,-1,-1,0,1]

for i in range(H):
    for j in range(W):
        if(S[i][j]=="#"):
            c[i][j]="#"
            continue
        for direction in range(8):
            if(i==0):
                if(i+dy[direction]<0):
                    continue
            if(i==H-1):
                if(i+dy[direction]>=H):
                    continue
            if(j==0):
                if(j+dx[direction]<0):
                    continue
            if(j==W-1):
                if(j+dx[direction]>=W):
                    continue

            if(S[i+dy[direction]][j+dx[direction]]=="#"):
                c[i][j]+=1

for i in range(H):
    s=""
    for j in range(W):
        s+=str(c[i][j])
    print(s)

Measured memory_bytes: 40688