akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

struct ShortestPath {
    struct edge { int to, cost; };
    const int inf = 1 << 28;
    int v;
    vector<vector<edge> > g;
    ShortestPath(int _v): v(_v), g(v) {}
    void add_edge (int from, int to, int cost) {
        g[from].push_back((edge){to, cost});
    }
    vector<int> shortest_path(int init) {
        vector<int> min_cost(v, inf);
        priority_queue<pair<int, int> > q;
        min_cost[init] = 0;
        q.push(make_pair(0, init));
        while (not q.empty()) {
            int cost = -q.top().first;
            int pos = q.top().second;
            q.pop();

            for (int i = 0; i < g[pos].size(); ++i) {
                int npos = g[pos][i].to;
                int ncost = cost + g[pos][i].cost;
                if (ncost < min_cost[npos]) {
                    min_cost[npos] = ncost;
                    q.push(make_pair(-ncost, npos));
                }
            }
        }
        return min_cost;
    }

    int shortest_path(int s, int t) {
        return shortest_path(s)[t];
    }
};


typedef pair<li, li> state;

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

    li n, m;
    cin >> n >> m;
    map<state, int> states;
    auto add_node = [&](const state& s) {
        if (states.find(s) == states.end()) {
            const int id = states.size();
            states[s] = id;
        }
    };
    for (int i = 0; i < n; ++i) {
        add_node(state(i, 0));
    }

    vector<vector<state>> g(n);
    for (int i = 0; i < m; ++i) {
        li fr, to, c;
        cin >> fr >> to >> c;
        fr--; to--;
        g[fr].emplace_back(to, c);
        g[to].emplace_back(fr, c);
        add_node(state(to, c));
        add_node(state(fr, c));
    }

    ShortestPath sp(states.size());

    for (auto&& st : states) {
        const li pos = st.first.first;
        const li color = st.first.second;
        const li id = st.second;
        if (color != 0) {
            li zero_id = states[state(pos, 0)];
            sp.add_edge(id, zero_id, 0);
            sp.add_edge(zero_id, id, 1);
        }
    }

    for (int fr = 0; fr < n; ++fr) {
        for (auto&& next : g[fr]) {
            const li to = next.first;
            const li color = next.second;
            const li fr_id = states[state(fr, color)];
            const li to_id = states[state(to, color)];
            sp.add_edge(fr_id, to_id, 0);
            sp.add_edge(to_id, fr_id, 0);
        }
    }

    li ans = sp.shortest_path(states[state(0, 0)], states[state(n - 1, 0)]);
    if (ans == sp.inf) {
        ans = -1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 87032
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;
using MIte = multimap<long, long, greater<long> >::iterator;

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

	int N, K;
	cin >> N >> K;
	string S;
	cin >> S;

	int diff = 0;
	int same = 0;
	for (int i = 0; i != N-1; ++i) {
		if (S[i] != S[i + 1]) {
			diff++;
		}
		else {
			same++;
		}
	}

	diff = min(diff, 2 * K);

	cout << same + diff << endl;

	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>

int main()
{
	long long int H, W;
	
	scanf("%ld %ld", &H, &W);
	
	if(H==1 || W==1) printf("1");
	
	else	if(H%2 == 1 && W%2 == 1) printf("%ld", H*W/2 + 1);
	
	else	printf("%ld", H*W/2);
	
	return 0;
}


Measured memory_bytes: 128
/// Author: Sarfaraz Alam
# include <bits/stdc++.h>
# define pb push_back
# define ll long long

# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define DEBUG
typedef unsigned long long int ull;
using namespace std;
#include<string>
#include<cmath>
const int N = 1e5 + 7;
const int mod = 1e9 + 7;


int main()
{
    speed;
    #ifdef DEBUGfd
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif // DEBUG

    //Code begins
    int n;
    cin>>n;
    int a[n];

    for(int i  = 0; i<n; i++)
    cin>>a[i];
    vector<int> ten;
    ull sum = 0;
    ull sum_t = 0;
    vector<int> a1;
    for(int i = 0; i<n; i++)
    {
      if(a[i] % 10 == 0)
      sum_t += a[i];
      else
      {
        a1.push_back(a[i]);
        sum += a[i];
      }

    }

    sort(a1.begin(), a1.end());


  //  cout<<sum_t<<endl;
  //  cout<<sum<<endl;


    for(auto x: a1)
    {
      if(sum % 10 == 0)
      {
        sum -= x;
      }
      else if(sum %10 != 0)
      break;
    }


    if(sum!= 0)
    sum += sum_t;
    cout<<sum<<endl;





    return 0;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "5", "1 4 3 5 2" ].parse.expand.solve == 2 );
	assert( [ "2", "1 2" ].parse.expand.solve == 1 );
	assert( [ "2", "2 1" ].parse.expand.solve == 0 );
	assert( [ "9", "1 2 4 9 5 8 7 3 6" ].parse.expand.solve == 3 );
	
	assert( [ "6", "1 2 3 4 5 6" ].parse.expand.solve == 3 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	as[] -= 1;
	return tuple( as );
}

auto solve( long[] as )
{
	auto ans = 0L;
	
	// 1回の入れ替えで2個解消できるところを優先して入れ替える
	foreach( i; 0L .. as.length.signed - 1 )
	{
		if( as[ i ] != i || as[ i + 1 ] != i + 1 ) continue;
		as.swapAt( i, i + 1 );
		ans++;
	}
	
	// 残りを入れ替える
	foreach( i; 0L .. as.length.signed - 1 )
	{
		if( as[ i ] != i && as[ i + 1 ] != i + 1 ) continue;
		as.swapAt( i, i + 1 );
		ans++;
	}
	
	return ans;
}


Measured memory_bytes: 4540
#include<stdio.h>
#define MAX 5000
void cal(void);
int ten;
int v[MAX][MAX];

main(){
  int a,b,k,i,j,p,q;
 
  scanf("%d",&ten);
  for(i = 0;i < ten;i++){
    scanf("%d%d",&q,&p);
    for(j = 0;j < p;j++){
    scanf("%d",&b);
    v[q-1][b-1] = 1;
    }
    }
  cal();
  return 0;
}

void cal(void){
  int i;
  int j;
for(i = 0;i < ten;i++){
    for(j = 0;j <ten-1; j++){
      printf("%d ",v[i][j]);
    }
    printf("%d\n",v[i][j]);
  }
}

Measured memory_bytes: 1004
#include <iostream>

using namespace std;

int main()
{
    int r, g, b;

    cin >> r >> g >> b;

    r = r * 100 + g * 10 + b;

    if (r % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import itertools
n = int(input())
l = list(map(int,input().split()))
li = [i for i in range(n)]

a = []
for i in range(n):
    a.append([l[i],i])
a.sort(reverse = True)

dp = [[-1]*(n+1) for i in range(n+1)]
dp[0][0] = 0
for i in range(n):
    for j in range(i+1):
        le = j
        ri = i-le
        dp[le+1][ri] = max(dp[le+1][ri],dp[le][ri]+a[i][0]*abs(a[i][1]-le))
        dp[le][ri+1] = max(dp[le][ri+1],dp[le][ri]+a[i][0]*abs(n-1-a[i][1]-ri))

ans = 0
for i in range(n+1):
    j = n-i
    ans = max(ans,dp[i][j])
print(ans)

Measured memory_bytes: 100424
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

s = input()[:-1]
t = input()[:-1]

co = len(s)

for i in range(len(s)):
	if s[i] == t[i]:
		co -= 1
print(co)

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (n - 1); i > (a - 1); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define Unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define updiv(a, b) ((a + b - 1) / b)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, 1, -1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main(void) {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> x(n);
  arep(i, x) cin >> i;
  sort(all(x));

  int cnt = 0;
  rep(i, 0, n) {
    rep(j, i + 1, n) {
      rep(k, j + 1, n) {
        if (x[i] == x[j] || x[j] == x[k] || x[i] == x[k]) continue;
        if (x[i] + x[j] > x[k] && x[i] + x[k] > x[j] && x[k] + x[j] > x[i])
          ++cnt;
      }
    }
  }
  cout << cnt << '\n';
  return 0;
}

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

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
#define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vllin3(a,b,c,n) vll (a)(n);vll (b)(n);vll (c)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >>(x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;}
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define says(x) cout<<(x)<<(' ');
#define sas cout<<(' ');
#define sayR(x) cout<<fixed<<setprecision(10)<<(x);
#define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;

signed main(){
        llin(w);
        llin(h);
        llin(x);
        llin(y);
        says(double(w*h)/2.0)
        if(x*2==w&y*2==h){
                sal(1)
        }else{
                sal(0)
        }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;


int main() { 
    ll N,K;
    cin>>N >> K;
    vector<ll> h(N);
    ll DP[N];
    REP(i,N){
        cin >> h.at(i);
        DP[i] = INF;
    }
    DP[0] = 0;
    DP[1] = abs(h.at(1) - h.at(0));
    FOR(i,2,N){
        ll x;
        if(i>K){
            x = K;
        }
        else{x = i;}
        FOR(j,1,x+1){
            if(DP[i] > DP[i-j]+abs(h.at(i)-h.at(i-j))){
                DP[i] = DP[i-j]+abs(h.at(i)-h.at(i-j));
            }    
        }   
        
    }
    cout << DP[N-1] << endl;
    
}


Measured memory_bytes: 1792
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define fst first
#define snd second
using ll = long long;
using I = pair<int, int>;

ll ax, ay, az;

void f(ll N, ll t, ll mk) {
  for (ll dk = -5; dk <= 5; dk++) {
    ll k = mk + dk;
    ll x = 4 * k + t;
    ll y = -9 * k - 2 * t;
    if (x >= 0 && y >= 0 && x + y <= N) {
      ax = x;
      ay = y;
      az = N - x - y;
    }
  }
}

int main() {
  ll N, Y;
  while (cin >> N >> Y) {
    ll t = Y / 1000 - N;
    ax = ay = az = -1;
    f(N, t, -t / 4);
    f(N, t, -2 * t / 9);
    cout << ax << " " << ay << " " << az << endl;
  }
  return 0;
}


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

double dp[303][303][303];
int n;

void calc(int i, int j, int k) {
    if (dp[i][j][k] >= 0) return;
    if (i) calc(i - 1, j, k);
    if (j) calc(i + 1, j - 1, k);
    if (k) calc(i, j + 1, k - 1);

    dp[i][j][k] = (i ? dp[i - 1][j][k] * i : 0) +
                    (j ? dp[i + 1][j - 1][k] * j : 0) +
                    (k ? dp[i][j + 1][k - 1] * k : 0) +
                    n;
    dp[i][j][k] *= 1.0 / (i + j + k);
}

int main() {
    std::cin >> n;
    std::vector<int> cnt(5);
    int a;
    for (int i = 0; i < n; i++) {
        std::cin >> a;
        cnt[a]++;
    }

    memset(dp, -1, sizeof dp);
    dp[0][0][0] = 0.0;
    calc(cnt[1], cnt[2], cnt[3]);
    printf("%.10lf\n", dp[cnt[1]][cnt[2]][cnt[3]]);

    return 0;
}

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

using namespace std;

#define endl '\n'

typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;

const double eps = 1e-9;
const int oo = 0x3f3f3f3f;
const int mod = 1000000007;

struct three_set{
    map<int,int> a;

    bool insert(int x){
        a[x]++;
        return a.size() <= 3;
    }

    vector<pii> get() {
        vector<pii> b(a.begin(), a.end());
        return b;
    }
};

void yes(){
    cout << "Yes" << endl;
    exit(0);
}

void no(){
    cout << "No" << endl;
    exit(0);
}

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

    int n; cin >> n;

    three_set ts;

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

        if (!ts.insert(a)){
            cout << "No" << endl;
            return 0;
        }
    }

    auto a = ts.get();

    sort(a.begin(), a.end(), [&](pii x, pii y){
        return x.second < y.second;
    });

    // equal
    if (a.size() == 1 && a[0].first == 0)
        yes();

    // 2
    if (a.size() == 2){
        if (a[0].first != 0)
            no();

        if (a[0].second * 2 != a[1].second)
            no();

        yes();
    }

    if (a.size() != 3)
        no();


    if (a[0].second != a[2].second)
        no();

    if ((a[0].first ^ a[1].first ^ a[2].first) != 0)
        no();

    yes();

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    ll A;
    double B;
    cin >> A >> B;
    B = round(100 * B);
    int C = (int)B;
    ll ans = A * C / 100;
    cout << ans << '\n';
    return 0;
}

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

const long long MOD=998244353;
const long long MAXA=1123456;
long long C[MAXA];
long long inv[MAXA];

void tr(long long a) {
  std::cout<<a<<std::endl;
}

int main() {
  inv[0]=inv[1]=1;
  for (int i=2;i<MAXA;++i) {
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
  }

  for (int i=1;i<MAXA;++i) {
    C[i]=(C[i]+inv[i])%MOD;
    for (int j=2*i;j<MAXA;j+=i) {
      C[j]=(C[j]-C[i]+MOD)%MOD;
    }
  }
  
  int N;
  std::cin>>N;
  std::vector<long long > A(N);
  for (int i=0;i<N;++i) {
    std::cin>>A[i];
  }
  std::sort(A.begin(), A.end());

  long long ans=0;
  std::vector<long long> cnt(MAXA, 0);
  for (int i=0;i<N;++i) cnt[A[i]]++;
  for (int i=1;i<MAXA;++i) {
    long long s2=0;
    for (int j=i;j<MAXA;j+=i) {
      s2=(s2+cnt[j]*j)%MOD;
    }
    ans=(ans+s2*s2%MOD*C[i]%MOD)%MOD;
  }
  for (int i=0;i<N;++i) ans=(ans-A[i]+MOD)%MOD;
  ans=ans*inv[2]%MOD;
  std::cout<<ans<<std::endl;

  
  return 0;
}


Measured memory_bytes: 28160
// 133_B_Good_Distance.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <float.h>

using namespace std;

int main()
{
	int N, D = 0;

	cin >> N >> D;

	vector<vector<int>> X;

	for (int i = 0; i < N; i++)
	{
		vector<int> row;

		for (int j = 0; j < D; j++)
		{	
			int value = 0;
			cin >> value;
			row.push_back(value);
		}

		X.push_back(row);
	}

	int count = 0;

	//計算
	for (int i = 0; i < N; i++)
	{
		vector<int> row1 = X.at(i);

		for (int j = i + 1; j < N; j++) {

			vector<int> row2 = X.at(j);

			int sum = 0;
			for (int k = 0; k < D; k++)
			{
				//2乗和
				sum += (row1.at(k) - row2.at(k)) * (row1.at(k) - row2.at(k));
			}

			double distance = sqrt((double)sum);
			double distance_float = floor(distance);

			//整数判定（誤差考慮）
			if (fabs(distance - distance_float) <= DBL_EPSILON * fmax(1, fmax(fabs(distance), fabs(distance_float))))
			{
				count++;
			}
		}
	}

	cout << count;

	return 0;
}


Measured memory_bytes: 512
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7
    
    # u高橋, s青木
    n,u,s = map(int, input().split())
    adj = [[] for _ in range(n)] #頂点数, 場合によって変える
    for _ in range(n-1):
        a,b = map(int, input().split())
        adj[a-1].append(b-1)
        adj[b-1].append(a-1)
    ta = [-1]*n
    ao = [-1]*n

    d = deque([s-1])
    ao[s-1] = 0
    while d:
        v = d.popleft()
        for nv in adj[v]:
            if ao[nv] == -1:
                ao[nv] = ao[v] + 1
                d.append(nv)

    d = deque([u-1])
    ta[u-1] = 0
    while d:
        v = d.popleft()
        for nv in adj[v]:
            if ta[nv] == -1:
                ta[nv] = ta[v] + 1
                d.append(nv)

    res = 0
    for i in range(n):
        if ta[i] < ao[i]:
            res = max(res, ao[i]-1)
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 62624
using System;
using System.Text;

namespace ALDS1_2_D
{
    class Program
    {
        static int counter;
        static StringBuilder sb = new StringBuilder();
        
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] numbers = new int[n];

            for (int i = 0; i < n; i++)
                numbers[i] = int.Parse(Console.ReadLine());

            ShellSort(numbers, n);

            foreach (var num in numbers)
            {
                sb.AppendLine(num.ToString());
            }
            Console.WriteLine(sb);
        }
        static void InsertionSort(int[] numbers, int n, int g) //挿入ソート
        {
            for (int i = g; i < n; i++)
            {
                int v = numbers[i];
                int j = i - g;
                while (j >= 0 && numbers[j] > v)
                {
                    numbers[j + g] = numbers[j];
                    j = j - g;
                    counter++;
                }
                numbers[j + g] = v;
            }
        }

        static void ShellSort(int[] numbers, int n)
        {
            counter = 0;
            int h = 1;
            int m = 0;

            do
            {
                m++;
                h = h * 3 + 1;
            } while (h < n);

            int[] G = new int[m];

            for (int i = m - 1, x = 0; i >= 0; i--)
            {
                x = x * 3 + 1;
                G[i] = x;
            }

            for (int i = 0; i < m; i++)
            {
                InsertionSort(numbers, n, G[i]);
            }

            sb.AppendLine(m.ToString());
            sb.AppendLine(string.Join(" ", Array.ConvertAll(G, g => g.ToString())));
            sb.AppendLine(counter.ToString());
        }

    }
}



Measured memory_bytes: 79752
#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);
}
using Graph = vector<vector<int>>;
Graph G;
int main() {
    int h, w, k; cin >> h >> w >> k;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    vector<string> t(h);
    int ans = 0;
    for(int bit = 0; bit < (1 << (h + w)); bit++){
        rep(i, h) t[i] = s[i];
        
        for(int i = 0; i < (h + w); i++){
            if(bit & (1 << i)){
                if(i < h){
                    rep(j, w) t[i][j] = 'o';
                }else{
                    rep(j, h) t[j][i - h] = 'o';
                } 
            }
        }
        int count = 0;
        rep(i, h)rep(j, w){
            if(t[i][j] == '#') count++;
        }
        if(count == k) ans++;
    }
    cout << ans << endl;
}

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

namespace ITP1_5_B
{
    class Program
    {
        static void Main(string[] args)
        {
            //縦Hcm、横Wcmの長方形を描く
            //1cm×1cmの正方形を'#'で表す
            //H,Wがともに0の時入力の終了
            //長方形の内側を"．"で表す

            while (true)                                    //以下の処理をbreak条件が与えられるまで繰り返す
            {
                string[] str = Console.ReadLine().Split(' ');
                int H = int.Parse(str[0]);                  //H 長方形の縦
                int W = int.Parse(str[1]);                  //W 長方形の横

                int i1;                                     //以下のfor文にてHに対応して用いる変数
                int i2;                                     //以下のfor文にてWに対応して用いる変数

                if (H == 0 && W == 0)
                {
                    break;                                  //H,Wが0の時、処理の終了
                }

                else
                {
                    for (i1 = 0; i1 < H; i1++)              //縦に以下の処理を何回繰り返すか？
                    {
                        for (i2 = 0; i2 < W; i2++)          //#を書く処理を横に何回繰り返すか？
                        {
                            if (i1 == 0 || i1 == H - 1)     //1行目or最終行の処理
                            {
                                Console.Write("#");         //横にW個の#を表示させる

                            }
                            else　　　　　　　　　　　　　　//1行目or最終行以外の時
                            {
                                if (i2 == 0 || i2 == W - 1)
                                {
                                    Console.Write("#");
                                }

                                else
                                {
                                    Console.Write(".");
                                }
                            }
                        }
                        Console.WriteLine();                //改行する
                    }
                    Console.WriteLine("");
                }
            }
        }
    }
}



Measured memory_bytes: 15816
#include <bits/stdc++.h>
//#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}

int a[maxn];

int solve() {
    int n,all=0,b;
    cin>>n;
    for (int i=0;i<n;++i) {
        cin>>b,a[b]++,all=gcd(all,b);
    }
    int flag=1;
    for (int i=2;i<=maxn;++i) {
        int sum=0;
        for (int j=i;j<=maxn;j+=i) sum+=a[j];
        if (sum>1) flag=0;
    }
    return cout<<(flag?"pairwise coprime":all==1?"setwise coprime":"not coprime"),0;
}

signed main() {
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int _ = 1;
//    cin>>_;
    while (_--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 7532
#include <bits/stdc++.h>
 
using namespace std;
 
bool check(vector<int> &s, int N)
{
    int p = 0;
    for (int i = 0; i < N; i++) {
        p += s[i];
        if (p < 0) {
            return 0;
        }
    }
    return (p == 0);
}
 
int main()
{
    int N;
    string str;
    cin >> N;
    vector<int> s(N);
    for (int i = 0; i < N; i++) {
        cin >> str;
        if (str == "A") {
            s[i] = +1;
        } else {
            s[i] = -1;
        }
    }
    cout << (check(s, N) ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 3160
#include <stdio.h>
#include <stdlib.h>

int N;

struct Node {
    int key;
    struct Node *left;
    struct Node *right;
};
typedef struct Node t_Node;

t_Node *root = NULL;

void insert(int key)
{    
    t_Node *node = root;
    t_Node *parent = NULL;
    while (node != NULL) {
        parent = node;
        if (key < node->key) {
            node = node->left;
        }
        else {
            node = node->right;
        }
    }
    
    t_Node *new = (t_Node*)malloc(sizeof(t_Node));
    new->key = key;
    new->left = NULL;
    new->right = NULL;
    
    if (parent == NULL) {
        root = new;
    }
    else if (key < parent->key) {
        parent->left = new;
    }
    else {
        parent->right = new;
    }
}

void inOrder(t_Node *node)
{
    if (node== NULL) {
        return;
    }
      
    if (node->left != NULL) {
        inOrder(node->left);
    }
    printf(" %d", node->key);  
    if (node->right != NULL) {
        inOrder(node->right);
    }
}

void preOrder(t_Node *node)
{
    if (node== NULL) {
        return;
    }
    
    printf(" %d", node->key);    
    if (node->left != NULL) {
        preOrder(node->left);
    }
    if (node->right != NULL) {
        preOrder(node->right);
    }    
}

void print()
{
    inOrder(root);
    puts("");
    preOrder(root);
    puts("");
}

int main()
{
    int i, j, k;    
    int key;
    char cmd[10];
    scanf("%d", &N);
    for (i = 0; i < N; i++) {        
        scanf("%s", cmd);
        switch (cmd[0]) {
            case 'i':
                scanf("%d", &key);
                insert(key);
                break;
            case 'p':
                print();
                break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 16232
from collections import deque
import sys
input = sys.stdin.readline

def bfs():
    st = deque([(0,-1)])
    while st:
        n,par = st.popleft()
        val = cnt[n]   
        for node in A[n]:
            if node == par:
                continue
            else:
                cnt[node] += val
                st.append([node,n])

N,Q = (int(i) for i in input().split())
A = [[] for _ in range(N)]

for _ in range(N-1):
    a,b = (int(i) for i in input().split())
    A[a-1].append(b-1)
    A[b-1].append(a-1)

cnt = [0]*N
for q in range(Q):
   p,x = (int(i) for i in input().split())
   cnt[p-1] += x

bfs()

print(*cnt)

Measured memory_bytes: 105716
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
    int a,b;
    cin >> a >> b;
    if(a > b){
        cout << "-1" << endl;
        return 0;
    } 
    
    //cout << "あ" << endl;
    int x,y;
    x = (a+1) * 100 / 8;
    y = b * 100 / 10;
    
    int ansA,ansB;
    for(int i=y ; i<=x ; i++){
        ansA = i * 8 / 100;
        ansB = i / 10;
        //cout << "i=" << i << " ansA=" << ansA << " ansB=" << ansB << "\n" << endl;
        if(ansA==a && ansB==b){
            cout << i << endl;
            return 0;
        }
    }
    
    //cout << "い" << endl;
    cout << "-1" << endl;
    return 0;
}


Measured memory_bytes: 256
px=0 
py=0 
f=1 
pt=0 
n=int(input())
for i in range(n):
    t,x,y=map(int,input().split())
    z=abs(x-px)+abs(y-py)
    px=x 
    py=y  
  #  pt=t   
   # print(z,t-pt )
    if z<=(t-pt) and z%2==(t-pt)%2:
        pass 
    else:
       # print(i)
        f=0 
    pt=t  
print('Yes' if f else 'No')

Measured memory_bytes: 46056
#include<bits/stdc++.h>
#define forp(x,a,b) for(int x=a; x<b; x++)
#define forn(x,a,b) for(int x=a; x>b; x--)
#define SZ(a) ((int)(a).size())
#define pb push_back
#define vec(x) vector<x>
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int>>
#define umpii unordered_map<int,int>
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a, b, sizeof a)
#define setBits(n) __builtin_popcountll(n)
#define prec(n) fixed<<setprecision(n)
#define ff first
#define ss second
#define print(x) for(auto it:x) cout<<it<<" ";
#define w(x) while(x--)
using namespace std;
typedef long long ll;
const int mod= 1e9 + 7;
 int n, p;
 ll w[100], v[100];
 ll W[100001][101];
 ll pot(ll x,int y){
    if(y==0){
        return 1;
            }
else{
    if(y%2==0){ int k=pot(x,y/2);
        return k*k;
        }
    else{
        return x*pot(x,y-1);
        }    
    }
}


 
void solve(){ 
    
}

int main(){
 ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>p;
    forp(i,0,n){cin>>w[i]>>v[i];}
    forp(i,1,p+1){
        forn(j,n-1,-1){
            W[i][j] = W[i][j+1];
            if(i>=w[j]){W[i][j]=max(W[i-w[j]][j+1]+v[j],W[i][j+1]);}//cout<<W[i][j]<<' ';
            
        }//cout<<endl;
    }
    
    
    cout<<W[p][0];
    
    return 0;}

Measured memory_bytes: 82560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<int,int>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i,n) for (ll i=(ll)n-1;i>=0;i--)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
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; }
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
#define INF 1<<30
#define INFTY 1LL<<60
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}//最大公約数
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}//最小公倍数
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
const int MOD = 1000000007;

inline ll mod_add(ll a,ll b){return (a+b)%MOD;}
inline ll mod_sub(ll a,ll b){return (a+MOD-b)%MOD;}
inline ll mod_mul(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
inline ll mod_pow(ll x,ll n,ll mod=(ll)MOD){ll res=1;while(n>0){
if(n&1)res=res*x%mod;
x=x*x%mod;n>>=1;}return res;}
inline ll mod_inv(ll x){return mod_pow(x,MOD-2);}
inline ll mod_div(ll a, ll b){return mod_mul(a,mod_inv(b));}
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17 -I .
//push_back -> emplace_back

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
   int n,m;cin>>n>>m;
   VI p(n);
   UnionFind tree(n);
   rep(i,n)cin>>p[i],p[i]--;
   rep(i,m){
      int x,y;cin>>x>>y;
      x--;y--;
      tree.merge(x,y);
   }
   int ans=0;
   rep(i,n){
      if(tree.issame(p[i],i))ans++;
   }
   cout<<ans<<endl;
}

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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define int long long
// #define pow mypow

typedef pair<int,int> pii;
const int N = 1e6+5;
const int INF = 1e9+5;
const int MOD = 1e9+7;
int n;

int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n;
	int ans = 0;
	for(int i=2; i*i<=n; i++){
		int cnt = 0;
		while (n%i == 0){
			cnt++;
			n/=i;
		}
		int num = 1;
		while(num <= cnt){
			cnt -= num;
			num++;
			ans++;
		}
	}
	if (n > 1) ans++;
	cout << ans << endl;
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    string s[n];
    for (int i = 0; i < n; i++) cin >> s[i];
    int m;
    cin >> m;
    string t[m];
    for (int i = 0; i < m; i++) cin >> t[i];
    int max_profit = 0; 
    for (int i = 0; i < n; i++)
    {
        int profit = 0;
        for (int k = 0; k < n; k++)
        {
            if (s[i] == s[k]) profit++;
        }
        for (int j = 0; j < m; j++)
        {
            if (s[i] == t[j]) profit--;
        }
        max_profit = max(profit, max_profit);
    }
    cout << max_profit << endl;
}


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

int main() {
  int n; cin>>n; 
  vector<int> v(n);
  rep(i,n){
    cin>>v[i];
    if(v[i]==i+1){v[i]=1;}
    else{v[i]=0;}
  }
  int ans=0;
  rep(i,n-1){
    if(v[i]==1){
      ans++;i++;
      if(i==n-2 &&v[n-1]==1){ans++;}
    }
  }
  
  cout<<ans;
}

Measured memory_bytes: 640
/*  
     author : hursh29    
     g++ : 17.3.20 
*/        
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(i,a,b)        for( i = a ; i < b  ; i++ )
#define debug(x)           cout << #x << " " << x << "\n"
#define speedup            ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll                 long long  
#define p(x) 			   cout << x << "\n" ; 
#define MOD                998244353
#define pi                 pair<ll,ll>
#define vi                 vector <ll>
#define pb                 push_back
#define vp                 vector <pair<ll,ll>>
#define endl               cout << "\n"
#define mi                 map <int,int> 
#define f1                 first 
#define s1                 second    
#define in                 insert
#define all(x)             x.begin(),x.end() 
using namespace std ; 
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set; 
const int N = 2e5+7; 
/*   
    time : 17 : 28      
    date : 20.12.2019
*/    
int n ; 
string S,T,res ; 
int solve(){
	cin >> n   ;  
    cin >> S >> T ; 
    while(S.empty() == 0 ){
    	
    	res.pb(T.back()) ; 
    	T.pop_back() ; 
        res.pb(S.back()) ; 
    	S.pop_back() ; 
    } 
    reverse(all(res));
    cout << res ; 
    return 0 ; 
}
int main() { 
	speedup ;  
    int test  = 1 ; 
	//cin >> test  ; 
	while(test--)
    	solve() ; 
	 
	return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    double a, b, x;
    cin >> a >> b >> x;
    double s = x/a;
    double rad;
    if (s >= a*b/2) {
        double h = (a*b - s)*2/a;
        rad = atan(h/a);
    } else {
        double w = s*2/b;
        rad = atan(b/w);
    }
    double PI = acos(-1);
    double deg = rad/(2*PI)*360;
    printf("%.10f\n", deg);
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>

int main()
{
 char a[255];
 char b[255];
 char c[255];
 scanf("%s %s %s", a, b, c);
 int len = strlen(a);
 int n = strlen(b);
 int s = strlen(c);
 if (a[len - 1] == b[0] && b[n - 1] == c[0]){
  puts("YES");
 }
 else{
  puts("NO");
  }
	
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>

int main()
{
    int r, g, b;
    std::cin >> r >> g >> b;
    if ((r * 100 + g * 10 + b) % 4 == 0)
    {
        std::cout << "YES" << std::endl;
    }
    else
    {
        std::cout << "NO" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3616
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n,m,k = [int(i) for i in readline().split()]
ab = [[int(i) for i in readline().split()] for _ in range(m)]
cd = [[int(i) for i in readline().split()] for _ in range(k)]

class UnionFind():
    def __init__(self, n=0):
        self.d = [-1]*n # 負なら根、非負なら親IDの情報を持たせる。負の値の絶対値で連結成分のサイズを表す（-2なら連結成分サイズ2の根）

    def find(self, x):
        """
        根のIDを返す
        """
        if self.d[x] < 0: return x # 今の頂点が根なら頂点番号を返す
        self.d[x] = self.find(self.d[x]) # 今の頂点が根でないなら親についてfindクエリを投げる. d[x] = find(d[x])で経路縮約できる
        return self.d[x]

    def unite(self, x, y):
        """
        根同士をくっつける
        """
        x = self.find(x); y = self.find(y) # 根同士をくっつける
        if x == y: return False # 根が同じなら何もする必要はない。Falseを返しているのは、くっつけられたかどうかを返した方が便利なときがあるから（MSTなど）
        if self.d[x] > self.d[y]: x,y = y,x # 小さい方の部分木を大きい方の部分木にくっつけるためにswap。dがマイナスなので不等号が逆になる点に注意
        self.d[x] += self.d[y] # 連結成分サイズを更新
        self.d[y] = x # 根をyからxに張り替える
        return True

    def same(self, x, y):
        """
        同じ集合に所属しているかどうか
        """
        return self.find(x) == self.find(y)

    def size(self, x):
        """
        連結成分サイズを返す
        """
        return -self.d[self.find(x)]

MAXN = 100005
deg = [0]*MAXN
to = [[] for _ in range(MAXN)]

uf = UnionFind(n)

for a,b in ab:
    a -= 1
    b -= 1
    deg[a] += 1
    deg[b] += 1
    uf.unite(a, b)

for c,d in cd:
    c -= 1
    d -= 1
    to[c].append(d)
    to[d].append(c)

anss = []
for i in range(n):
    ans = uf.size(i)-1-deg[i] # 連結成分サイズから自分自身と友達を引く
    for u in to[i]:
        if uf.same(i,u): ans -= 1 # 同じ連結成分にあってブロック関係にあったら友達候補にはなれないので-1する
    anss.append(ans)
print(*anss)

Measured memory_bytes: 68192
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	int A, B,T;

	cin >> A >>B>>T;

	cout << B*(T/A) << endl;



	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);

		int N = sc.nextInt();
		int[] a = sc.nextIntArray(N);
		int alice = 0;
		int bob = 0;
		Arrays.sort(a);

		boolean Aflag = true;
		for (int i = N - 1; i >= 0; i--) {
			if (Aflag) {
				 alice += a[i];
			} else {
				bob += a[i];
			}

			Aflag = !Aflag;
		}

		System.out.println(alice - bob);
	}



	static class FastScanner {

		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;

	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }

	}

}


Measured memory_bytes: 21076
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
map<int, int> mp;
map<int, int>mm;
#define ll long long

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

int main(void) {
    ll n,m ;
    string s, t;
    cin >> n >> m >> s >> t;
    ll v = gcd(n, m);
    rep(i, s.size()) {
        if (i % (n / v) == 0) {
            ll e = i / (n / v);
            ll e1 = (n / v)*e;
            ll e2 = (m / v)*e;
            if (s[e1] != t[e2]) {
                cout << "-1" << endl;
                return 0;
            }
        }
    }
    cout << n * m / v << endl;
    return 0;
    
}

Measured memory_bytes: 512
#include <stdio.h>
#include <algorithm>
typedef long long ll;
int A[100000];
int B[100000];
int C[100000];
ll Bcnt[100000];
ll Ccnt[100000];
int N;
int main(){
        scanf("%d",&N);
        for(int j = 0; j < N; j++) scanf("%d",A+j);
        for(int j = 0; j < N; j++) scanf("%d",B+j);
        for(int j = 0; j < N; j++) scanf("%d",C+j);
        std::sort(A,A+N);
        std::sort(B,B+N);
        std::sort(C,C+N);

        for(int i = 0; i < N; i++){
                Bcnt[i]=(std::lower_bound(A,A+N,B[i])-A);
        }
        for(int i = 1; i < N; i++){
                Bcnt[i]+=Bcnt[i-1];
        }
        for(int i = 0; i < N; i++){
                Ccnt[i]=Bcnt[(std::lower_bound(B,B+N,C[i])-B)-1];
        }
        ll ans = 0;
        for(int i = 0; i < N; i++){
                ans += Ccnt[i];
        }
#define NDEBUG
#ifndef NDEBUG
        puts("A[i]:"); for(int i = 0; i < N; i++)printf("%d,",A[i]); puts("");
        puts("B[i]:"); for(int i = 0; i < N; i++)printf("%d,",B[i]); puts("");
        puts("C[i]:"); for(int i = 0; i < N; i++)printf("%d,",C[i]); puts("");
        puts("Bcnt[i]:"); for(int i = 0; i < N; i++)printf("%lld,",Bcnt[i]); puts("");
        puts("Ccnt[i]:"); for(int i = 0; i < N; i++)printf("%lld,",Ccnt[i]); puts("");
#endif
        printf("%lld\n",ans);

}

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

#define ll long long

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
 
    ll n;
    cin >> n;
    string res;
    while (n) {
        ll curr = (n%26);
        if (curr == 0) {
            res += 'z';
            n = (n/26) - 1;
        } else {
            res += (char)(curr + 'a' - 1);
            n /= 26;
        }
    }
    reverse(res.begin(), res.end());
    cout << res << "\n";
}


Measured memory_bytes: 3612
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long ll;

const int nax = 2e5 + 5;
char s[nax];
long long answer;

int main() {
	scanf("%s", s);
	int n = strlen(s);
	int state = 0;
	int as = 0;
	for(int i = 0; i < n; ++i) {
		if(state == 0) {
			if(s[i] == 'A') {
				as++;
			}
			else if(s[i] == 'B') {
				state++;
			}
			else { // 'C'
				state = as = 0;
			}
		}
		else if(state == 1) {
			if(s[i] == 'A') {
				as = 1;
				state = 0;
			}
			else if(s[i] == 'B') {
				as = state = 0;
			}
			else { // 'C'
				answer += as;
				state = 0;
			}
		}
		else {
			assert(false);
		}
		// if(s[i] == 'A') {
			// as++;
		// }
		
		// if(pref % 3 == 0 && s[i] == 'A') {
			// ++pref;
		// }
		// if(pref % 3 == 1 && s[i] == 'B') {
			// ++pref;
		// }
		// if(pref % 3 == 2 && s[i] == 'C') {
			// ++pref;
		// }
		// if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') {
			// ++answer;
			// s[i] = 'B';
			// s[i+1] = 'C';
			// s[i+2] = 'A';
			// i = max(-1, i - 3);
		// }
	}
	printf("%lld\n", answer);
}


Measured memory_bytes: 384