akhauriyash/Code-Regression huggingface dataset:
// Author := Abhishek Giri

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define V(type) vector<(type)>
#define all(c) ((c).begin(),(c).end())
#define in(var) cin>>(var)
#define out(var) cout<<(var)
#define on(var) cout<<var<<"\n"
#define f(i,n) for(ll i = 0 ; i < n ;i++)
#define mfor(i,init,n,b) for(ll i = (init) ; i < (n) ; i+= (b))
#define cfor(i,c) for(auto i = (c).begin() ; i!= (c).end(); i++)
#define el "\n"
#define ret return
#define F first
#define S second

/*##################################################################################*/

/*
int prime[100000] ;
vector < int > pr;
void calculateprime()
{
    prime[0] = prime[1] = 1 ;
    for(int i = 2 ; i <= 100000 ; i++)
    {
        if(prime[i] == 0)
        {
            pr.pb(i);
            for(ll j = i*2 ; j <= 100000 ; j += i )
            {
                prime[j] = 1 ;
            }
        }
    }
}
*/


void customrun(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

bool isprime(ll n)
{
    for(ll i = 2 ; (ll) i*i <= n ; i++)
    {
        if(n % i == 0){
            return false;
        }
    }
    return true;
}

ll fib(int n)
{
    ll a = 0, b = 1, c, i;
    if( n == 0)
        return a;
    for (i = 2; i <= n; i++)
    {
        c = (a + b);
        a = b;
        b = c;
    }
    return b;
}


ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll extendedgcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = extendedgcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

ll findgrouplcm(vector<int> &arr, int n)
{
    ll ans = arr[0];

    for (ll i = 1; i < n; i++)
        ans = (arr[i] * (ans/(gcd(arr[i], ans))));

    return ans;
}


ll powerwithmod(ll x, unsigned ll y, ll p)
{
    ll res = 1;

    x = x % p;

    if (x == 0) return 0;

    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;

        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}


bool comp(const pair < long,long > &a, const pair < long ,long > &b){
    if(a.first == b.first) return a.second < b.second;
    return a.first < b.first;
}

void solve();

int main() {
    clock_t begin = clock();

    fast();
    customrun();
    ll t = 1;
    //cin>>t;
    //calculateprime();
    mfor(i,1,t+1,1)
    {
        //cout<<"Case #"<<i<<": \n";
        solve();
    }
    clock_t end = clock();
    double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
    //cout<<"\ntime spent is "<<time_spent;
    return 0;
}


void solve(){
    ll n;
    in(n);

    ll arr[n] ,sum = 0 ;
    f(i,n) in(arr[i]);

    mfor(i,1,n,1){
        if(arr[i] < arr[i-1]){
            sum += (arr[i-1]-arr[i]);
            arr[i] = arr[i-1];
        }
    }

    out(sum);
}

Measured memory_bytes: 5216
#include "bits/stdc++.h"
using namespace std;

int main(void) {
	vector<int> a(5);
	int k;
	int ans = 0;

	for (int i = 0; i < 5; ++i) {
		cin >> a[i];
	}
	cin >> k;
	sort(a.begin(), a.end());
	if (a[4] - a[0] <= k) {
		cout << "Yay!";

	}
	else {
		cout << ":(";

	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int N,A[200],ans=200;
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  for(int i=0;i<N;i++){
    int dmin=0;
    while(A[i]%2==0){
      A[i]/=2;
      dmin++;
    }
    ans=min(dmin,ans);

  }
  printf("%d",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w",stdout);
    #endif
    ll n;
    cin>>n;
    vector<ll> vec(n);
    for(ll& i: vec){
        cin>>i;
    }
    sort(vec.begin(),vec.end(),greater<ll>());
    ll items_counted = 1;
    ll ans = vec[0];
    ll j = 1;
    ll i = 2;
    while(i<vec.size()){
        if(i+1 == vec.size()){
            ans += vec[j];
            break;
        }else{
            ans+= 2*vec[j];
            j++;
            i+=2;
            
        }
    }



    cout<<ans<<endl;
    
}

Measured memory_bytes: 4776
N = int(input())
ok = True
for a in [int(x) for x in input().split(' ')]:
  if a % 2 == 0:
    if a % 3 != 0 and a % 5 != 0:
      ok = False
      break
if ok:
  print('APPROVED')
else:
  print('DENIED')

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

typedef long long ll;
typedef double ld;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <vi> vii;

#define pb push_back
#define mp make_pair
#define all(_c) _c.begin(), _c.end()

const int MOD = 1e9 + 7;

vii mexp(int n, ll k, vii g) {

    auto mul = [&n] (vii a, vii b) {
        vii c(n, vi(n));
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                for (int k = 0; k < n; k++)
                    c[i][j] = (c[i][j] + ll(a[i][k])*b[k][j] % MOD) % MOD;
        return c;
    };

    vii res(n, vi(n));
    for (int i = 0; i < n; i++)
        res[i][i] = 1;

    for (; k; k >>= 1, g = mul(g, g))
        if (k & 1)
            res = mul(res, g);
    
    return res;
}

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

    int n; ll k;
    cin >> n >> k;

    vii g(n, vi(n));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> g[i][j];
    
    g = mexp(n, k, g);
    
    int ans = 0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            ans = (ans + g[i][j]) % MOD;
    
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 384
//Keep working hard :)
#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

const int N = 1e5+5;
int a[N];

void fileIO()
{
        #ifndef ONLINE_JUDGE
        freopen("int.txt","r",stdin);
        freopen("out.txt","w",stdout);
        #endif
}
int main()
{
	IOS;
//        fileIO();
        int a,p;
        cin >> a >> p;
        cout << (3*a+p)/2;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void) {
	char s[4];
	int count = 0;

	cin >> s;

	for (int i = 0; i <= 2; i++) {
		if (s[i] == 'o') {
			count++;
		}
	}

	cout << 700 + 100 * count << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

// go run ./main.go < in

func main() {
	var a string
	fmt.Scan(&a)

	inputs := strings.Split(a, "")

	for i := 0; i < 3; i++ {
		fmt.Printf("%s", inputs[i])
	}

}

Measured memory_bytes: 1824
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define mod 1000000007
#define lli long long
#define fi first
#define se second
#define pb emplace_back
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(x,v) for(auto x : v)
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define MAXC 200005
// %

int main(int argc, char **argv)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector < lli > v(n), pref(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        pref[i] = v[i];
        if (i) {
            pref[i] += pref[i-1];
            pref[i] %= mod;
        }
    }
    lli ans = 0;
    for (int i = n-1; i > 0; i--) {
        ans += pref[i-1] * v[i];
        ans %= mod; 
    }
    cout << ans << '\n';
}

Measured memory_bytes: 6360
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define FPEN2 freopen("out.txt", "w", stdout);
#else
#define FPEN
#define FPEN2
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
 public:
  vector<int> V[maxn];
  int ans[maxn];
  void solve() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
      int u, v;
      cin >> u >> v;
      V[u].push_back(v);
      V[v].push_back(u);
    }
    vector<int> que;
    memset(ans, -1, sizeof ans);
    que.push_back(1);
    ans[1] = 1;
    for (int i = 0; i < que.size(); ++i) {
      for (int j : V[que[i]]) {
        if (ans[j] == -1) {
          ans[j] = que[i];
          que.push_back(j);
        }
      }
    }
    if (que.size() != n) {
      cout << "No\n";
    } else {
      cout << "Yes\n";
      for (int i = 2; i <= n; ++i) cout << ans[i] << '\n';
    }
  }
} NSPACE;
int main() {
  FPEN;
  FPEN2;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}

Measured memory_bytes: 13360
#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
using namespace std;

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

  while (1) {
    if (x >= y) {
      ans = y;
      x = x % y;
      if (x == 0) {
        break;
      }
    } else {
      ans = x;
      y = y % x;
      if (y == 0) {
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3092
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (1) {
		int M, T, P, R;
		cin >> M >> T >> P >> R;
		if (!M)break;
		vector<vector<bool>> ac(T, vector<bool>(P, false));
		vvi pen(T, vi(P, 0));
		vvi last(T, vi(P, 0));
		REP(i, R) {
			int m, t, p, j;
			cin >> m >> t >> p >> j;
			if (j == 0) {
				ac[t - 1][p - 1] = true;
				last[t - 1][p - 1] = m;
			}
			else pen[t - 1][p - 1] += 20;
		}
		vector<pair<pii,ll>> point(T);
		REP(i, T) {
			int acc = 0, time = 0;
			REP(j, P) {
				if (ac[i][j]) {
					time += last[i][j] + pen[i][j];
					acc--;
				}
			}
			point[i] = { { acc,time },-i };
		}
		sort(ALL(point));
		string ret = "";
		REP(i, T - 1) {
			ret += to_string((-1)*point[i].second+1);
			if (point[i].first == point[i + 1].first)ret += '=';
			else ret += ',';
		}
		ret += to_string((-1)*point[T-1].second + 1);
		cout << ret << endl;
	}


	return 0;
}

Measured memory_bytes: 3240
stdin.ReadLine()
|> fun x -> x.Split(' ')
|> Array.map float
|> fun x -> (x.[0], x.[1])
|> fun (n, m) ->
  (
    [0.0..(2. ** n - 1.)]
    |> List.map int,
    [1.0..m]
    |> List.map (fun _ -> stdin.ReadLine() |> fun x -> x.Split(' ').[1..] |> Array.map (int >> (+) -1))
    |> List.mapi (fun i x -> i, x),
    stdin.ReadLine() |> fun x -> x.Split(' ') |> Array.map int
  )
|> fun (ns, ms, ps) ->
  ns
  |> Seq.filter (
    fun switches ->
      ms
      |> Seq.forall (
        fun (i, si) -> (si |> Seq.sumBy (fun sii -> switches >>> sii &&& 1)) % 2 = ps.[i]
      )
  )
|> Seq.length
|> printfn "%d"


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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a-b>=c){
    cout << 0 << endl;
  }
  else{
    cout << c-a+b << endl;
  }
  
  return 0;
}

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

int main() {

	int n, m; cin >> n >> m;
	vector<int> p(m),y(m);
	for (int i = 0; i < m; i++) {
		cin >> p[i] >> y[i];
		p[i]--;
	}

	vector<vector<int>> vals(n);
	for (int i = 0; i < m; i++) {
		vals[p[i]].emplace_back(y[i]);
	}

	for (int v = 0; v < n; v++) {
		sort(vals[v].begin(), vals[v].end());
	}

	for (int i = 0; i < m; i++) {
		int v = p[i];
		printf("%06d", v + 1);

		int id = lower_bound(vals[v].begin(), vals[v].end(), y[i]) - vals[v].begin();
		printf("%06d", id + 1);
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 9496
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int dp[N];
int dgin[N];
vector< int > g[N];
queue< int > q;
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=1,u,v;i<=m;i++)   scanf("%d %d",&u,&v),g[u].push_back(v),++dgin[v];
    for(int i=1;i<=n;i++)   if(!dgin[i])    q.push(i);
    while(!q.empty())
    {
        int nowi = q.front(); q.pop();
        for(auto &x:g[nowi])
        {
            --dgin[x];
            dp[x] = max(dp[x],dp[nowi]+1);
            if(!dgin[x])    q.push(x);
        }
    }
    int mx = 0;
    for(int i=1;i<=n;i++)   mx = max(mx,dp[i]);
    printf("%d\n",mx);
    return 0;
}


Measured memory_bytes: 6528
a, b = input().split()


if int(a) == 1 and int(b) != 1:
    print("Alice")
elif int(a) != 1 and int(b) == 1:
    print("Bob")
elif int(a) > int(b):
    print("Alice")
elif int(a) < int(b):
    print("Bob")
elif int(a) == int(b):
    print("Draw")

Measured memory_bytes: 9060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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 D;
vector<int> c(26+1);
vector<vector<int>> s;

int compute_score(vector<int> t) {
    vector<vector<int>> last(D+1,vector<int>(26+1,0));
    int ans = 0;
    for(int d = 1; d <= D; d++) {
        last[d][t[d]] = d;
        ans += s[d][t[d]];
        for(int i = 1; i <= 26; i++) {
            if(i == t[d]) continue;
            last[d][i] = last[d-1][i];
            ans -= c[i]*(d-last[d][i]);
        }
    }
    return 0;
}

vector<int> greedy() {
    vector<int> t(D+1);
    vector<vector<int>> last(D+1,vector<int>(26+1,0));
    for(int d = 1; d <= D; d++) {
        int best_i;
        int best_score_diff = -INT32_MAX;
        for(int i = 1; i <= 26; i++) {
            int score_diff = s[d][i] - c[i]*(d-last[d][i]);
            if(score_diff >= best_score_diff) {
                best_i = i;
                best_score_diff = score_diff;
            }
        }
        for(int i = 1; i <= 26; i++) {
            if(i == best_i) {
                last[d][i] = d;
                t[d] = i;
            } else {
                last[d][i] = last[d-1][i];
            }
        }
    }
    return t;
}

int main(){
    ios::sync_with_stdio(false);
    cin >> D;
    s.assign(D+1,vector<int>(26+1,0));
    for(int i = 1; i <= 26; i++) cin >> c[i];
    for(int d = 1; d <= D; d++) for(int i = 1; i <= 26; i++) cin >> s[d][i];

    vector<int> t = greedy();
    for(int d = 1; d <= D; d++) cout << t[d] << endl;
}


Measured memory_bytes: 3724
#include<iostream>
using namespace std;
int main(){
    int n;
    int as[5];
    int bs[5];
    int l = 0;
    while(cin >> n){
        as[l] = bs[l] = 0;
        for(int i = 0;i < n;i++){
            int a;
            int b;
            cin >> a >> b;
            if(a > b){
                as[l] += a + b;
            }
            else if(a == b){
                as[l] += a;
                bs[l] += b;
            }
            else{
                bs[l] += a + b;
            }
        }
        l++;
    }
    for(int i = 0;i < l - 1;i++){
        cout << as[i] << " " << bs[i] <<endl;
    }
    return 0;
}


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

signed main(){
#ifdef _DEBUG
	//freopen("_in" , "r", stdin );
	//freopen("_out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	for (int i = 1; i <= 9; i++) {
		if (n % i == 0 && n / i >= 1 && n / i <= 9) {
			cout << "Yes\n";\
			return 0;
		}
	}
	cout << "No\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =998244353;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
    


  int main(){
     lint n;
     cin>>n;
     vector<lint> b;
     rep(i,10000){
          lint h=n%26;
         if(h==0)h+=26;
         if(n<=26){
               b.push_back(h);
               break;
         }
         n-=h;
         n/=26;
         b.push_back(h);
     }
     string ans;
     rep(i,b.size())ans+=('a'-1+b[i]);
     reverse(all(ans));
     cout<<ans<<endl;
     }
     

  
 
  
      
      
    
 
  
          
  

Measured memory_bytes: 3720
#include<iostream>

using namespace std;
int S[1000000];
int T[1000000];

bool serch(int n,int* T,int size){
	int left,right,mid;
	left=0;
	right=size;

	while(left<right){
		mid=(left+right)/2;
		if(T[mid]==n)return true;
		else if(T[mid]>n){
			right=mid;
		}
		else left=mid+1;
	}
	return false;
}


int main(){
	int n,q;
	cin>>n;
	for(int i=0;i<n;i++)cin>>S[i];
	cin>>q;
	for(int i=0;i<q;i++)cin>>T[i];
	
	int cnt=0;
	for(int i=0;i<q;i++){
		
		if(serch(T[i],S,n))cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
const int inf = 1 << 30;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int l[100010], r[100010];
int N, K;
int P[100010];
vector<int> G[100010];
bool flag = true;
bool came[100010];
bool odd[100010];
void dfs(int v){
    came[v] = true;
    if(P[v] != -1 && P[v] % 2 != odd[v]) flag = false;

    for(auto u : G[v]){
        if(came[u]) continue;
        dfs(u);
        chmax(l[v], l[u] - 1);
        chmin(r[v], r[u] + 1);
    }

    if(l[v] > r[v]) flag = false;
    if(P[v] != -1){
        if(l[v] <= P[v] && P[v] <= r[v]) l[v] = P[v], r[v] = P[v];
        else flag = false;
    }
}

void odd_or_even(int v, int b){
    came[v] = true;
    odd[v] = b;
    for(auto u : G[v]){
        if(came[u]) continue;
        odd_or_even(u, (b + 1) % 2);
    }
}

void fill_in(int v, int num){
    came[v] = true;

    if(l[v] <= num + 1 && num + 1 <= r[v]) P[v] = num + 1;
    else P[v] = num - 1;
    for(auto u : G[v]){
        if(came[u]) continue;
        fill_in(u, P[v]);
    }
}

void solve(){
    for(int i = 1; i <= N; i++){
        if(P[i] != -1){
            odd_or_even(i, P[i] % 2);
            break;
        }
    }
    for(int i = 1; i <= N; i++) came[i] = false;
    
    dfs(1);

    for(int i = 1; i <= N; i++) came[i] = false;

    if(!flag){
        cout << "No" << endl;
        return;
    }else{
        cout << "Yes" << endl;
        fill_in(1, r[1] + 1);
        for(int i = 1; i <= N; i++) cout << P[i] << endl;
    }
}

void input(){
    cin >> N;
    for(int i = 1; i < N; i++){
        int A, B;
        cin >> A >> B;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    for(int i = 1; i <= N; i++){
        l[i] = -inf;
        r[i] = inf;
        P[i] = -1;   
    }
    cin >> K;
    for(int i = 0; i < K; i++){
        int v, p;
        cin >> v >> p;
        P[v] = p;
    }
}

int main(){
    input();
    solve();
    return 0;
}

Measured memory_bytes: 12416
using System;
using System.Collections.Generic;
using System.Linq;

class Solution
{
    static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var a = vals[0];
        var b = vals[1];
        var c = vals[2];
        var d = vals[3];

        var t = Math.Min(b, d) - Math.Max(a, c);
        t = Math.Max(0, t);

        Console.WriteLine(t);
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    string w;
    cin>>w;
    int n;
    n=w.length();
    vector<string> W(n);
    for (int i = 0; i < n; i++){
        W.at(i)=w[i];
    }
    
    vector<string> a{"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
    vector<int> count(26,0);
    for (int i = 0; i < n; i++){
        for (int j = 0; j < 26; j++){
            if(W.at(i)==a.at(j)){count.at(j)+=1;}
        }
    }
    bool flg=true;
    for (int i = 0; i < 26; i++){
        if(count.at(i)%2==1){
            flg=false;
            break;
        }
    }
    if(flg==true){cout<<"Yes";}
    else{cout<<"No";}
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int N, M, X;
	cin >> N >> M >> X;
	vector<int> A(N + 1);
	for (int i = 0; i < M; i++) {
		int tmp;
		cin >> tmp;
		A.at(tmp)++;
	}

	int cost_0 = 0;
	for (int i = 0; i < X; i++) {
		cost_0 += A.at(i);
	}
	cout << min(cost_0, M - cost_0) << endl;
}

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

int main() {
    string n;
    cin >> n; 
   
   if(n[0]==n[1]&&n[1]==n[2]){
       cout<<"Yes"<<endl;
       
   }else if(n[1]==n[2]&&n[2]==n[3]){
       cout<<"Yes"<<endl;
   }else
   cout<<"No"<<endl;

 
}

Measured memory_bytes: 256
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const s = stdin.split('\n')[0]

const mod = 10 ** 9 + 7

const ans = () => {
  let dp = []

  for (let i = 0; i < s.length + 1; i++) {
    let mods = []
    for (let j = 0; j < 13; j++) {
      mods.push(0)
    }
    dp.push(mods)
  }

  dp[0][0] = 1

  for (let i = 0; i < s.length; i++) {
    let num = s[i] === '?' ? -1 : Number(s[i])

    // ?(0~9)を計算
    for (let j = 0; j < 10; j++) {
      if (num != -1 && num != j) continue //?ではなく、該当の数字ではない場合は次のiterationへ飛ばす

      // 現在の数値に対する0~12の余りテーブルを埋める
      for (let ki = 0; ki < 13; ki++) {
        dp[i + 1][(ki * 10 + j) % 13] += dp[i][ki] // (前回の余り * 10 + 数値)%13に前回の余りの合計を追加する
      }
    }

    for (let j = 0; j < 13; j++) {
      dp[i + 1][j] %= mod
    }
  }

  console.log(dp[s.length][5])
}

ans()


Measured memory_bytes: 66636
import java.util.*;

public class Main{

    public static void main(String args[]){

        int[] num = new int[100];
        // スキャナーの宣言
        Scanner sc = new Scanner(System.in);
        // 整数の入力
		int a = sc.nextInt();
        // スペース区切りの整数の入力
        int b = sc.nextInt();
        int k = sc.nextInt();
        int n = 0;
        for(int i = 1; i < Math.min(a, b) + 1; i++){
            if(a % i == 0 && b % i == 0){
                num[n] = i;
                n++;
            }
        }
        // 出力
        System.out.println(num[n - k]);

    }

}

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

int main(){
  stack <int>st;
  st.push(0);
  int n,ans=0;
  cin>>n;
  while(n--){
    int a;
    cin>>a;
    while(st.top()>a)st.pop();
    if(st.top()<a)st.push(a),ans++;
    
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1808
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  int N;
  cin >> N;
  ll now = 1;
  for (int i = 2; i <= N; i++) {
    now *= i;
    now %= 1000000007;
  }
  cout << now << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

N, M = map(int, input().split())
X = list(map(int, input().split()))

d = defaultdict(int)
num = defaultdict(list)
ans = 0
for x in X:
  y = x % M
  num[y].append(x)
  pair = (M - y) % M
  if d[pair] >= 1:
    d[pair] -= 1
    ans += 1
  else:
    d[y] += 1

def count_pair(Z, n):
  res = 0
  dd = defaultdict(int)
  for z in Z:
    if dd[z] >= 1:
      res += 1
      dd[z] -= 1
    else:
      dd[z] += 1
  return min(res, n)

for y in num:
  ans += count_pair(num[y], d[y]//2)

print(ans)

Measured memory_bytes: 33808
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.math.BigInteger;

public class Main {

    // input
    static int n;
    static BigInteger[] a;

    /**
     * input
     */
    static void input(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        a = new BigInteger[n];
        for (int i=0;i<n;i++){
            a[i] = BigInteger.valueOf(sc.nextInt());
        }
        sc.close();
    }
 
    /**
     * solver
     */
    static void solve(){
        BigInteger[] f = new BigInteger[n];
        BigInteger[] g = new BigInteger[n];

        f[0] = a[0];
        g[n-1] = a[n-1];

        for(int i=1;i<n;i++){
            f[i] = f[i-1].gcd(a[i]);
            g[n-i-1] = g[n-i].gcd(a[n-i-1]);
        }

        BigInteger ans = BigInteger.ZERO;

        // 0<i<n-1
        for (int i=0;i<n;i++) {
            BigInteger tmp;

            if (i==0){
                tmp = g[1];
            } else if (i==n-1) {
                tmp = f[n-2];
            } else {
                tmp = f[i-1].gcd(g[i+1]);
            }

            if (tmp.compareTo(ans) >= 0) {
                ans = tmp;
            }
        }

        System.out.println(ans);

    }

    public static void main(String args[]) {

        input();
        solve();
    }
}


Measured memory_bytes: 112388
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
int nmax=200000;
vvec g(nmax);



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    string s;
    cin>>s;
    int n=s.size();
    ll ans=n;
    if(n==1){
        cout<<1<<endl;
        return 0;
    }
    rep(i,n-1){
        if(s[i]!=s[i+1]){
            chmin(ans,max(i+1,n-(i+1)));
        }
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 5248
N=int(input())
L=list(map(int,input().split()))
count=0
sum=0
A=float("inf")
for i in L:
	sum+=abs(i)
	A=min(A,abs(i))
	if i<0:
		count+=1
if count%2==0:
	print(sum)
else:
	print(sum-A*2)

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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> input(120),b(50);
  
  int i,A,B;
  for(i = 0 ; i < m ; i++){
    cin >> A >> B;
    input.at(i * 2) = A;
    input.at(i * 2 + 1) = B;
  }
  
  for(i = 0 ; i < m * 2 ; i++)	b.at( input.at(i) - 1 )++;
  for(i = 0 ; i < n ; i++)	cout << b.at(i) << endl;
  
}

Measured memory_bytes: 256
#include <string>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string.h>
#include <utility>
#include <queue>
#include <stack>
#include <iomanip>
#include <ctype.h>
#include <map>
#include <set>
#include <stdio.h>
#include <assert.h>
#include <ctype.h>
#include <sstream>
#include <math.h>
#include <time.h>
#include <iostream>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <tuple>
#include <cmath>
#include <stdio.h>      /* printf, fgets */
#include <stdlib.h>
#include <fstream>

using namespace std;

typedef long long LL;

#define FOR(i,n) for(int i = 0;i < n;i++)
#define MP make_pair
#define PB push_back
#define ALL(a) (a).begin(),(a).end()
#define PII pair<int, int>
#define PLL pair<long long, long long>
#define CLEAR(a) memset(a, 0, sizeof(a))
#define ERASE(a) memset(a, -1, sizeof(a))
#define INF 2000000007LL
#define y1 uu1
#define y2 uu2
const double EPS = 1E-12;
const double PI = acos(-1.0);
const LL mod = 1000000007;

using namespace std;

int x, y;

int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0);
  cin >> x >> y;
  int ans = 0;
  if (x == 1) ans += 3;
  if (x == 2) ans += 2;
  if (x == 3) ans += 1;

  if (y == 1) ans += 3;
  if (y == 2) ans += 2;
  if (y == 3) ans += 1;
  if(x == 1 && y == 1) ans += 4; 

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


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a[5][30];
	for (int i = 0; i < 4; i++){
		for (int j = 0; j < 13; j++){
			a[i][j] = 0;
		}
	}
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		int x;
		char o;

		cin >> o >> x;
		x--;
		if (o == 'S'){
			a[0][x] = 1;
		}
		if (o == 'H'){
			a[1][x] = 1;
		}
		if (o == 'C'){
			a[2][x] = 1;
		}
			if (o == 'D'){
				a[3][x]=1;
			}
	}
	
	for (int i = 0; i < 4; i++){
		for (int j = 0; j < 13; j++){
			if (a[i][j]==0){
				if (i == 0)cout << 'S' << ' ' << j + 1 << endl;
				if (i == 1)cout << 'H' << ' ' << j + 1 << endl;
				if (i == 2)cout << 'C' << ' ' << j + 1 << endl;
				if (i == 3)cout << 'D' << ' ' << j + 1 << endl;

			}
		}
	}















	return 0;
}

Measured memory_bytes: 3060
#include <stdio.h>
int main(){

	int i;
	int sn;
	int A,B;
	int sumA,sumB;

	while(scanf("%d",&sn)!=EOF){
		if(sn==0)break;
		sumA=0;
		sumB=0;
		for(i=1;i<=sn;i++){
			scanf("%d %d",&A,&B);
			if(A>B)sumA+=(A+B);
			if(A<B)sumB+=(A+B);
			if(A==B){sumA+=A;sumB+=B;}
		}
		printf("%d %d\n",sumA,sumB);
	}
	return 0;
}

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

using namespace std ;

#define sz(v) (int)v.size()
#define ll long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define pf push_front
#define pb push_back
#define fast FastInputOutput() ;
#define Clear( container , value ) memset( container , value , sizeof container )
#define PI acos( -1.0 )
#define forn( t , v , be , n ) for( t v = be ; v < n ; v++ )
#define fore( x , j ) for( auto x : j )
#define se second
#define fr first
//#define c_b fflush(stdin);

const ll Long_max = numeric_limits < ll > :: max() ;
const int Int_max = numeric_limits < int > :: max() ;

void File_input( string pathIn ) {
    freopen( pathIn.c_str(), "r", stdin ) ;
}

void File_output( string pathOut ) {
    freopen( pathOut.c_str(), "w", stdout ) ;
}

int msg() {
    srand( time( 0 ) ) ;
    vector < string > st = {
        "Wish everyone high ratings!",
        "Good luck!",
        "Have fun!",
        "Please, read all the problems!",
        "Go Go fight!"
    } ;
    cerr << st[ rand() % sz( st ) ] ;
    return 0 ;
}


void FastInputOutput() {
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

ll len , n ;

int main(){

   cin >> len >> n ;
   ll init ;
   if( len == 0 ){
     init = 1 ;
   }

   if( len == 1 ){
     init = 100 ;
   }

   if( len == 2 ){
     init = 10000 ;
   }

   for( ll i = init * n ; ; i++ ){
      int nc = 0 ;
      ll j = i ;
      while( i % 100 == 0 ){
         i /= 100 ;
         nc++ ;
      }
      i = j ;
      if( nc == len ){
        cout << i ;
        return 0 ;
      }
   }


   return 0 ;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] str = stdR.readLine().split(" ");
        int H = Integer.parseInt(str[0]);
        int W = Integer.parseInt(str[1]);
        String[] s = new String[H];
        String[] result = new String[H];
        for(int i = 0 ; i < H ; i++) {
            s[i] = stdR.readLine();
        }
        for(int i = 0 ; i < H ; i++) {
            String st = "";
            for(int j = 0 ; j < W ; j++) {
                st += wall(j,i,s);
            }
            result[i] = st;
        }
        for(int i = 0 ; i < H ; i++) {
            System.out.println(result[i]);
        }
        
    }
    
    public static String wall(int x,int y, String[] s) {
        if(s[y].charAt(x) == '#')return "#";
        int[] xs = {-1,0,1,-1,1,-1,0,1};
        int[] ys = {-1,-1,-1,0,0,1,1,1};
        int count = 0;
        for(int i = 0 ; i < xs.length ; i++) {
            if(x + xs[i] >= 0 && x + xs[i] < s[0].length() && y + ys[i] >= 0 && y + ys[i] < s.length && s[y + ys[i]].charAt(x + xs[i]) == '#')count++;
        }
        return String.valueOf(count);

    }
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 212345;
struct RMQStatic {
  int *a;
  int dp_min[20][MAX_N]; // [i][j] := answer index of start_pos == j, len == 2^i
  int log2(int b) {return 31 - __builtin_clz(b);}
  // O(NlogN)
  void build(int* a, int N) {
    this->a = a;
    int M = log2(N) + 1;
    REP(i, N) dp_min[0][i] = i;
    for (int i = 1, len = 1; i < M; i++, len <<= 1) {
      for (int j = 0; j + len < N; j++) {
        {
          int s = dp_min[i - 1][j];
          int t = dp_min[i - 1][j + len];
          dp_min[i][j] = a[s] <= a[t] ? s : t;
        }
      }
    }
  }

  // O(1)
  // [from..to]の間で最小の値の添字を返す。複数ある場合は一番最初のを返す
  int query(int from, int to) {
    int k = log2(to - from + 1);
    int s = dp_min[k][from];
    int t = dp_min[k][to - (1 << k) + 1];
    return a[s] <= a[t] ? s : t;
  }
};

int P[MAX_N];
int E[MAX_N];
int O[MAX_N];

const int INF = 1001001001;
RMQStatic rmq_e;
RMQStatic rmq_o;

struct Part {
  int from, to;
  int x, y;
  Part(int from, int to) : from(from), to(to) { // [from, to]
    if (from % 2 == 0) {
      x = rmq_e.query(from, to);
      y = rmq_o.query(x + 1, to);
    } else {
      x = rmq_o.query(from, to);
      y = rmq_e.query(x + 1, to);
    }
  }
  bool operator < (const Part& o) const {
    if (x != o.x) return P[x] > P[o.x];
    return P[y] > P[o.y];
  }
};

int main2() {
  int N = nextInt();
  REP(i, N) P[i] = nextInt();
  REP(i, N) {
    if (i % 2 == 0) {
      E[i] = P[i];
      O[i] = INF;
    } else {
      E[i] = INF;
      O[i] = P[i];
    }
  }
  rmq_e.build(E, N);
  rmq_o.build(O, N);

  vector<int> ans;
  priority_queue< Part > pq;
  pq.push( Part(0, N-1) );
  while (!pq.empty()) {
    Part top = pq.top(); pq.pop();
    // cout << "[" << top.from << " " << top.to << "] (" << top.x << "," << top.y << ")" << endl;
    {
      int nx = top.from, ny = top.x - 1;
      // cout << nx << " "<< ny << endl;
      if (ny - nx + 1 >= 2) pq.push(Part(nx, ny));
    }
    {
      int nx = top.x + 1, ny = top.y - 1;
      // cout << nx << " "<< ny << endl;
      if (ny - nx + 1 >= 2) pq.push(Part(nx, ny));
    }
    {
      int nx = top.y + 1, ny = top.to;
      // cout << nx << " "<< ny << endl;
      if (ny - nx + 1 >= 2) pq.push(Part(nx, ny));
    }
    ans.push_back(P[top.x]);
    ans.push_back(P[top.y]);
  }

  REP(i, ans.size()) {
    if (i > 0) printf(" ");
    printf("%d", ans[i]);
  }
  printf("\n");

  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 38516
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(m)]

class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.weight = [0] * (n+1)
        self.sizes = [1] * (n+1)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    def union(self, x, y, w=1):
        rx = self.find(x)
        ry = self.find(y)
        if self.rank[rx] < self.rank[ry]:
            self.sizes[ry] += self.size(rx)
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        else:
            self.sizes[rx] += self.size(ry)
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def diff(self, x, y):
        return self.weight[x] - self.weight[y]

    def size(self, x):
        return self.sizes[self.find(x)]

uf=WeightedUnionFind(n)
for a,b in ab:
    uf.union(a,b)

# print(uf.par)
dic={}
for i in range(n):
    pa=uf.find(i+1)
    if pa in dic:
        dic[pa]+=1
    else:
        dic[pa]=1

ans=0
for i in dic.values():
    ans=max(ans,i)
print(ans)

Measured memory_bytes: 122988
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)( 1e9 + 7  ))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define sqrt sqrtl
#define cbrt cbrtl
#define endl '\n'
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef pair<float,float> ff;
typedef vector<ff> vff;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vf> vvf;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<fi> pqfi;
typedef priority_queue <int, vector<int>, greater<int> > rpqi; 
typedef priority_queue <ii, vector<ii>, greater<ii> > rpqii; 
typedef priority_queue <fi, vector<fi>, greater<fi> > rpqfi;

const int N=2e5+5;
int par[N];
int root(int v){return par[v] < 0 ? v : (par[v] = root(par[v]));}
void merge(int x,int y){	
        if((x = root(x)) == (y = root(y)) )    return ;
	if(par[y] < par[x])	
		swap(x, y);
	par[x] += par[y];
	par[y] = x;
}

int32_t main()
{
	IOS
	int a,b;cin>>a>>b;
	int cnt=(b-1)/(a-1);
	if((b-1)%(a-1)!=0)cnt++;
	cout<<cnt<<endl;
			
	
		
	
}
 
 


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int[] ary = new int[n + 1];
        int x=1, y=1, z=1;
        for(x=1; x*x<n; x++){
            for(y=1; x*x+y*y+x*y<n; y++){
                for(z=1; x*x+y*y+z*z+x*y+y*z+z*x<=n; z++){
                    ary[x*x+y*y+z*z+x*y+y*z+z*x]++;
                }
            }
        }
        for(int i=1; i<=n; i++){
            System.out.println(ary[i]);
        }
    }
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll A,B,N;

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

    cin >> A >> B >> N;

    ll xA = N;

    ll ansA = ((A*xA)/B)-(xA/B)*A;

    ll xB = (N/B)*B-1;

    ll ansB;

    if(xB <= 0) ansB = -1;
    else ansB = ((A*xB)/B)-(xB/B)*A;

    cout << max(ansA,ansB) << endl;

    return 0;

}

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

using namespace std;
typedef long long ll;

ll N, K;
ll A[200009];

int main(){
    cin >> K >> N;
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    ll max = (K-A[N-1]) + A[0];
    for(int i=1;i<N;i++){
        ll d = A[i] - A[i-1];
        if(d > max) max = d;
    }
    cout << K - max << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ull unsigned long long
using namespace std;

const int mod = 1e9+7;
int main() {
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  int n,k;
  cin>>n>>k;
  int a[n];
  for(int i = 0;i < n;i++) cin>>a[i];
  while(k--) {
    vector<int> b(n+1,0);
    for(int i = 0;i < n;i++) {
      int l = max(0,i-a[i]);
      int r = min(n-1,i+a[i]);
      b[l]++;
      b[r+1]--;
    }
    bool changed = false;
    for(int i = 0;i < n;i++) {
      changed |= (a[i]!=b[i]);
      a[i] = b[i];
      b[i+1] += b[i];
    }
    if(!changed)
      break;
  }
  for(int i = 0;i < n;i++)
    cout<<a[i]<<" ";
  cout<<"\n";
  return 0;
}

Measured memory_bytes: 5144
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;

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

  cin >> n;

  int count = 0;
  REP(i, n) {
    int a;
    cin >> a;
    if(count + 1 == a) count++;
  }

  cout << (count == 0 ? -1 : n - count) << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <tuple>
#include <numeric>
#include <utility>
#include <climits>
#include <float.h>
#include <cmath>
#define _USE_MATH_DEFINES
#include <math.h>
#pragma GCC target ("avx2")

using namespace std;

typedef long long ll;
typedef long double ld;
constexpr ll INF = LLONG_MAX;
constexpr double DINF = DBL_MAX;
constexpr ll mod = 1e9+7;
constexpr ll mod2 = 998244353;
constexpr double PI = M_PI;

template<typename T>
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...));
}

long long fact(long long n, long long mod){
  long long x = 1;
  while(n > 1ll){
    x = (x * n) % mod;
    n--;
  }
  return x;
}
 
long long expo(long long a, long long p, long long mod){
  if(p == 0ll){
    return 1ll;
  }else if(p % 2ll == 0){
    long long cmp = expo(a, p/2ll, mod);
    return (cmp * cmp) % mod;
  }else{
    return (expo(a, p-1, mod) * a) % mod;
  }
}

int main(){
  	cin.tie(0);
  	cout.tie(0);
  	ios::sync_with_stdio(false);
	
	long long n, k;
	cin >> n >> k;
	vector<ll> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
		a[i]--;
	}
	long long cnt = 0, now = 0, next = 0, start = 0;
	vector<bool>  visited(n, false);
	vector<ll> route, time(n);
	route.push_back(1);
	for(int i = 0; i < n; i++){
		time[now] = cnt;
		visited[now] = true;
		next = a[now];
		cnt++;
		if(visited[next]){
			start = time[next];
			break;
		}
		route.push_back(next + 1);
		now = next;
		if(k == cnt){
			cout << route[k] << endl;
			return 0;
		}
	}
	k -= start;
	cnt -= start;
	cout << route[start + k % cnt] << endl;
	return 0;
}


Measured memory_bytes: 8464
# coding: utf-8
# Your code here!
import sys
mybingo = []

for n in range(3):
    mybingo += [list(map(int, input().split()))]
#print(mybingo)

N = int(input())
for n in range(N):
    mynum = int(input())
    for m in mybingo:
        if mynum in m:
            m[m.index(mynum)] = 0
#print(mybingo)

#横check
for m in mybingo:
    if len(set(m)) == 1 and m[0] == 0:
        print('Yes')
        sys.exit()
#縦
for w in range(3):
    mycnt = 0
    for h in range(3):
        if mybingo[h][w] == 0:
            mycnt += 1
        else:
              break
    if mycnt == 3:
        print('Yes')
        sys.exit()
#斜め
h = [0,1,2]
w = [0,1,2]
mypos = 0 
mycnt = 0
while mypos < 3:
    if mybingo[h[mypos]][w[mypos]] == 0:
        mycnt += 1
    mypos += 1
if mycnt == 3:
    print('Yes')
    sys.exit()

h = [0,1,2]
w = [2,1,0]
mypos = 0 
mycnt = 0
while mypos < 3:
    if mybingo[h[mypos]][w[mypos]] == 0:
        mycnt += 1
    mypos += 1
if mycnt == 3:
    print('Yes')
    sys.exit()
    
print("No")

Measured memory_bytes: 3188