akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(void){
  int N,dup=0;
  cin >> N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  for(int i=1;i<N;i++){
    if(vec.at(i-1)==vec.at(i)){
      dup++;
    }
  }
  cout << N-dup << endl;
  return(0);
}
    

Measured memory_bytes: 256
import numpy as np
def main():
  N = int(input())
  ans = 30
  for i in range(1, int(np.sqrt(N))+2):
    if N % i == 0:
      ans = min(ans, max(len(str(i)), len(str(N//i))))
  print(ans)
if __name__ == "__main__":
  main()

Measured memory_bytes: 20968
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

template<typename T> using maximum_heap = std::priority_queue<T, std::vector<T>, std::less<T>>;
template<typename T> using minimum_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
std::istream& operator>>(std::istream &is, std::vector<T> &v)
{
  for (typename std::vector<T>::size_type i = 0; i < v.size(); ++i) {
    is >> v[i];
  }
  return is;
}

namespace IntegerMath
{
  int64_t floor_div(int64_t x, int64_t y) {
    return x / y;
  }

  int64_t ceil_div(int64_t x, int64_t y) {
    return (x / y) + std::min(static_cast<int64_t>(1), x % y);
  }

  int64_t sqrt(int64_t x) {
    return static_cast<int64_t>(
      ::floorl( ::sqrtl( 
        static_cast<long double>(x)
      ) )
    );
  }

  int64_t log2(int64_t x) {
    return static_cast<int64_t>(
      ::floorl( ::log2l( 
        static_cast<long double>(x)
      ) )
    );
  }    

  int64_t log10(int64_t x) {
    return static_cast<int64_t>(
      ::floorl( ::log10l( 
        static_cast<long double>(x)
      ) )
    );
  }

  int64_t number_of_digits(int64_t x) {
    return static_cast<int64_t>(
      ::ceill( ::log10l( 
        static_cast<long double>(x + 1)
      ) )
    );
  }
};

using namespace std;

uint64_t seq_sum(uint64_t n)
{
  if (n % 2 == 0) {
    return (n >> 1) * (n + 1);
  } else {
    return n * ((n + 1) >> 1);
  }
}

int main()
{
  uint64_t N;
  cin >> N;

  uint64_t S = 0;
  for (uint64_t n = 1; n <= N; ++n) {
    S += n * seq_sum(N / n);
  }
  cout << S << endl;

  return 0;
}

Measured memory_bytes: 3680
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  vP ps(n);
  rep(i, n){
    ll a;
    cin >> a;
    ps[i] = {a, i};
  }
  ps.emplace_back(0, 0);
  rSort(ps);
  vll ans(n, 0);

  ll idx = n;
  rep(i, n){
    chmin(idx, ps[i].second);
    ans[idx] += (i+1)*(ps[i].first - ps[i+1].first);
  }

  rep(i, n) cout << ans[i] << endl;

  return 0;
}


Measured memory_bytes: 6432
N, Q = map(int, input().split())
S = str(input())
cnt = 0
L = []
L.append(0)

for i in range(N-1):
    A = S[i]
    B = S[i + 1]
    if A == "A" and B == "C":
        cnt += 1
    L.append(cnt)

for x in range(Q):
    f, r = map(int, input().split())
    print(L[r-1] - L[f-1])

Measured memory_bytes: 6104
N = gets.to_i
arr = gets.split.map(&:to_f)
nn = (N + 1) / 2
dp = Array.new(nn + 1, 0)
dp[0] = 1
N.times do |i|
  (nn - 1).downto(0) do |j|
# dp[j+1],,,i回中少なくともj+1回表が出る確率合計
# dp[j] - dp[j+1],,,少なくともj回表 - 少なくともj+1回表＝ちょうどj回表の確率合計
# (dp[j] - dp[j+1]) * arr[i],,,ちょうどj回表の確率合計に現在のコインの表の確率を加味すると現在のコインによってちょうどj+1回の確率合計が求まる。
# dp[j+1] += ((dp[j] - dp[j+1]) * arr[i]),,,前回迄の確率合計に累積する。
    dp[j+1] += ((dp[j] - dp[j+1]) * arr[i])
  end
end
# p dp
puts dp[nn]

Measured memory_bytes: 4220
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string s;
  cin >> s;
  rep(i, 0, s.size()) {
    if (i % 2 == 0)
      cout << s[i];
  }
  cout << endl;
}


Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
 int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int N,a,A[100001];;
    cin>>N;
    for(int i=1;i<=N;i++){
    	cin>>a;
           A[a]=i;
    }
    for(int i=1;i<=N;i++){
        printf("%d ",A[i]);
    }
}


Measured memory_bytes: 1280
while 1:
    res = ""
    check = []
    try:
        s = input()
        for i in range(len(s)):
            if i in check:
                continue
            elif s[i] == "@":
                res = res + s[i+2] * int(s[i+1])
                check.append(i+1)
                check.append(i+2)
            else:
                res = res + s[i]
        print(res)
    except EOFError:
        break

Measured memory_bytes: 7672
#include <bits/stdc++.h>
using namespace std;
#define int64_t long long
constexpr int64_t MOD=1e9+7;

int a[510];
int n,k;
bool c(int64_t d){
    vector<int>r;
    int64_t total=0;
    for(int i=0;i<n;++i){
        r.push_back(a[i]%d);
        total+=r.back();
    }
    int64_t dd=total/d;
    int64_t ret=0;
    sort(r.begin(),r.end());
    for(int i=0;i<n-dd;++i){
        ret+=r[i];
    }
    return ret<=k;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin>>n>>k;
    int64_t sum=0;
    for(int i=0;i<n;++i){
        cin>>a[i];
        sum+=a[i];
    }
    int64_t ans=0;
    for(int64_t d=1;d*d<=sum;++d){
        if(sum%d)continue;
        if(c(d))ans=max(d,ans);
        if(c(sum/d))ans=max(sum/d,ans);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
while True :
 n, x = map(int, input().split())
 if(n == 0 and x == 0) :
   break
 else :
   s = 0
   for i in range(1, n + 1) :
     for j in range(1, i) :
       for k in range(1, j) :
         if(i + j + k == x) :
           s += 1
         else :
           pass
   print(s)


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

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

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

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


int N, M;
vector<pll> drink;

signed main(){
    ll A, B;
    cin >> N >> M;
    REP(i, N){
        cin >> A >> B;
        drink.push_back(pll(A, B));
    }
    sort(ALL(drink));
    ll money = 0, num = 0;
    for(auto i : drink){
        A = i.first; B = i.second;
        if(B >= M - num){
            money += A * (M - num);
            num = M;
            break;
        }else{
            money += A * B;
            num += B;
        }
    }
    PRINT(money);
    return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    int x;
    for(int i=0; i<5; i++){
        std::cin >> x;
        if(x==0){
            std::cout << i+1;
        }
    }
    return 0;
}


Measured memory_bytes: 3596
s=readline()
f=0;
for c=97:122
	b=0
	for i=1:endof(s)
		if Int(s[i])==c
			b=1
			break
		end
	end
	if b==f==0
		f=1
		print(Char(c))
	end
end
if f==0
	print("None")
end


Measured memory_bytes: 166628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long a[] = new long[26];
		String s = sc.next();
		long count =0;
		for (int i=0;i<s.length();i++) {
			long temp =1;
			for(int j=0;j<26;j++) {
				if (a[j]!=0&&j!=s.charAt(i)-'a') {
					temp =(temp *(a[j]+1))%1000000007;
				}
			}
			count =(count+temp)%1000000007;
			a[s.charAt(i)-'a']++;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 39632
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define FIR first
#define SEC second
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=2e5+10;
vector<int> d[2];
vector<int> G[N];
int dep[N],n;
void dfs(int u,int last) {
	dep[u]=dep[last]+1;
	d[dep[u]%2].PB(u);
	for(int v : G[u]) if(v!=last)
		dfs(v,u);
}
int ans[N],vis[N];
void gao() {
	int j=1;
	for(int i=1;i<=n;++i) if(!ans[i]) {
		while(vis[j]) ++j;
		ans[i]=j;
		++j;
	}
}
int main() {
	rd(n);
	for(int i=1,x,y;i<n;++i) rd(x),rd(y),G[x].PB(y),G[y].PB(x);
	dfs(1,0);
	if(d[0].size()>d[1].size()) swap(d[0],d[1]);
	if(d[0].size()<=n/3) {
		int v=3;
		for(int u : d[0])
			vis[ans[u]=v]=1,v+=3;
	} else {
		int v=1;
		for(int u : d[0]) {
			vis[ans[u]=v]=1,v+=3;
			if(v>n) break;
		}
		v=2;
		for(int u : d[1]) {
			vis[ans[u]=v]=1,v+=3;
			if(v>n) break;
		}
	}
	gao();
	for(int i=1;i<=n;++i) printf("%d ",ans[i]);
	return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n, d, x;cin >> n >> d >> x;
    vector<int> a(n);
    inc(i, 0, n) cin >> a[i];
    inc(i, 0, n){
        for(int j=0;j*a[i]+1 <= d;j++){
            x++;
        }
    }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Text.RegularExpressions;

class Program
{
    static void Main(string[] args)
    {
        var ary = Console
            .ReadLine()
            .Split(' ')
            .Select(x => int.Parse(x))
            .ToArray();
        var a = ary[0];
        var b = ary[1];
        var k = ary[2];

        var c = Math.Min(a, b);
        var count = 0;
        for (int i = c; i > 0; i--)
        {
            if (a % i == 0 && b % i == 0)
            {
                count++;
                if (count == k)
                {
                    Console.WriteLine(i);
                    return;
                }
            }
        }
    }
}

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

int main() {
    int n; cin >> n;
    vector<int> a(n+1);
    vector<int> b(n);
    rep(i, n+1) {
        cin >> a.at(i);
    }
    rep(i, n) {
        cin >> b.at(i);
    }

    ll ans = 0;
    rep(i, n) {
        int tmp = 0;
        ans += min(a.at(i), b.at(i));
        b.at(i) = b.at(i) - min(a.at(i), b.at(i));
        ans += min(b.at(i), a.at(i+1));
        a.at(i+1) = max(a.at(i+1)-b.at(i), 0);
    }

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

Measured memory_bytes: 1024
n, m = map(int, input().split())
h = list(map(int, input().split()))
i = [0] * n

for j in range(m):
  a, b = map(int, input().split())
  if h[a - 1] >= h[b - 1]:
    i[b - 1] += 1
  if h[a - 1] <= h[b - 1]:
    i[a - 1] += 1

print(i.count(0))

Measured memory_bytes: 19980
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----

#include<bits/stdc++.h>
using namespace std;

#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define dloop(i,n) for(int i=n-1;i>=0;i--)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define ld long double
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

int32_t main(){
	NINJA;

	char c; cin >> c;
	// string s; cin >> s;
	if(c>=65 and c<=91) cout << 'A' << endl;
	else cout << 'a' << endl;
	
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#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, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define ALLR(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EMP emplace
#define EMPB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
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; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

int comb[1010][1010];
void make_comb(int n, int m = MOD) {
  for (int i = 0; i <= n; i++) {
    comb[i][0] = 1;
    for (int j = 1; j <= i; j++)
      comb[i][j] += (comb[i-1][j-1]+comb[i-1][j]) % m;
  }
}

int N, A, B;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  make_comb(50, Bit(60));
  cin >> N >> A >> B;
  vector<int> v(N);
  REP(i, N) cin >> v[i];
  sort(ALLR(v));

  double ave = 0;
  REP(i, A) ave += v[i];
  ave /= A;

  int s = 0, cnt = 0;
  REP(i, N) if (v[i] == v[A-1]) s++;

  if (v[0] != v[A-1]) {
    int t = 0;
    REP(i, A) if (v[i] == v[A-1]) t++;
    cnt = comb[s][t];
  } else {
    FOR(i, A, B+1) {
      cnt += comb[s][i];
    }
  }
  cout << ave << endl;
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,ans=1e18,num=0,m=0;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        m+=a[i];
        if(i%2==0){
            if(m<=0){
                num+=(1-m);
                m=1;
            }
        }
        else{
            if(m>=0){
                num+=(m+1);
                m=-1;
            }
        }
    }
    ans=min(ans,num);
    num=m=0;
    for(int i=0;i<n;i++){
        m+=a[i];
        if(i%2==0){
            if(m>=0){
                num+=(m+1);
                m=-1;
            }
        }
        else{
            if(m<=0){
                num+=(1-m);
                m=1;
            }
        }
    }
    cout <<min(ans,num)<<endl;
    return 0;
}




Measured memory_bytes: 1024
import java.util.*;

public class Main {

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

        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n - i; j++) {
                int k = n - i - j;
                if (i*10000 + j*5000 + k*1000 == y) {
                    System.out.println(i + " " + j + " " + k);
                    return;
                }

            }
        }
        System.out.println("-1" + " " + "-1" + " " + "-1");

    }
}


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

public static partial class Program
{
    public static void Main()
    {
        var nk = CRL().ArrayLongs();
        var n = nk[0];
        var k = (int)nk[1];
        var s = CRL();

        var conts = new List<long>();
        var which = new List<bool>();

        var buff = s[0];
        conts.Add(1);
        which.Add(s[0] == '1' ? true : false);
        for (int i = 1; i < s.Length; i++)
        {
            if (buff == s[i])
            {
                conts[conts.Count - 1]++;
            }
            else
            {
                conts.Add(1);
                which.Add(s[i] == '1' ? true : false);
                buff = s[i];
            }
        }

        //累積和
        var accum = new List<long>();
        accum.Add(0);
        accum.Add(conts[0]);
        for (int i = 1; i < conts.Count; i++)
        {
            accum.Add(accum.Last() + conts[i]);
        }

        long max = 0;
        for (int l = 0; l < conts.Count; l++)
        {
            var r = (which[l] ? 2 * k + 1 : 2 * k) + l;
            if (r > conts.Count)
            {
                r = conts.Count;
            }
            max = Math.Max(max, accum[r] - accum[l]);
        }

        CWL(max);
    }
}

public static partial class Program
{
    //テンプレここから
    private static long ToInt(this string str) => long.Parse(str);
    private static long[] ToInt(this IEnumerable<string> strs) => strs.Select(x => x.ToInt()).ToArray();
    public static long[] ArrayLongs(this string str, char opr = ' ') => str.Split(opr).ToInt();
    public static string CRL() => Console.ReadLine();
    public static void CWL(object obj) => Console.WriteLine(obj);
    public static long Diff(long a, long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static long Sign(this long i) => Math.Sign(i);
    public static bool IsEven(this long i) => i % 2 == 0;
    public static bool IsEven(this int i) => i % 2 == 0;
    public static long[] dx = new long[] { 0, -1, 0, 1 };
    public static long[] dy = new long[] { -1, 0, 1, 0 };
    public static long mod = 1000000007;
    public static string alphabet = "abcdefghijklmnopqrstuvwxyz";
    public static long ToLong(this char c) => c.ToString().ToInt();
    public static long[] Sort(this long[] array)
    {
        var list = array.ToList();
        list.Sort();
        return list.ToArray();
    }
    public static long GCD(long a, long b) => b == 0 ? a : GCD(b, a % b);
    public static long LCM(long a, long b) => a * b / GCD(a, b);
    //テンプレここまで
}


Measured memory_bytes: 17376
import java.util.*;

public class Main {

  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {

    int A = sc.nextInt();
    int B = sc.nextInt();

    if (B % A == 0) {
      System.out.println(A+B);
    } else {
      System.out.println(B-A);
    }

  }

}

Measured memory_bytes: 21972
r=lambda x:p[x]>=0and r(p[x])or x
(n,m,k),*t=[map(int,t.split())for t in open(0)]
p,f=[-1]*-~n,[-1]*-~n
for a,b in t[:m]:
  x,y=r(a),r(b)
  if x!=y:
    if x>y:x,y=y,x
    p[x]+=p[y]
    p[y]=x
  f[a]-=1
  f[b]-=1
a=[f[i]-p[r(i)]for i in range(n+1)]
for c,d in t[m:]:
  if r(c)==r(d):
    a[c]-=1
    a[d]-=1
print(*a[1:])

Measured memory_bytes: 97624
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def calcTwoPointDistance(x1, y1, x2, y2):
    return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    XY = [il() for _ in range(N)]

    ret = 0
    for x1, y1 in XY:
        for x2, y2 in XY:
            ret += calcTwoPointDistance(x1, y1, x2, y2)
    print(ret/N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10300
N = int(input())
A = [int(i) for i in input().split()]

L = []
for i in range(N-1):
    if A[i] < A[i+1]:
        L.append(i)

M = 1000
for i in L:
    k = M // A[i]
    M -= k * A[i]
    M += k * A[i+1]
print(M)

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

long long N;

void rec(long long current, int use_flag, long long &counter)
{
    if (N < current)
        return;
    if (use_flag == 0b111)
        counter++;

    rec(current * 10 + 7, use_flag | 0b001, counter);
    rec(current * 10 + 5, use_flag | 0b010, counter);
    rec(current * 10 + 3, use_flag | 0b100, counter);
}

int main()
{
    cin >> N;
    long long res = 0;
    rec(0, 0, res);
    cout << res << endl;
    return 0;
}

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

const int N=6010;
int a[N][N];
int main()
{
    int n, k, k2; cin>>n>>k;
    k2=k+k;
    for(int x, y; n--; ) {
        char c;
        cin>>x>>y>>c;
        if (c%2) x+=k;
        x%=k2, y%=k2;
        for(int i=0; i<4; ++i) {
            for(int j=0; j<4; ++j) {
                if (i%2!=j%2) continue;
                ++a[y+i*k][x+j*k];
                --a[y+i*k][x+j*k+k];
                --a[y+i*k+k][x+j*k];
                ++a[y+i*k+k][x+j*k+k];
            }
        }
    }
#define rep(i, a) for(int i=a; i<N; ++i)
    rep(i, 0) rep(j, 1) a[i][j]+=a[i][j-1];
    rep(i, 1) rep(j, 0) a[i][j]+=a[i-1][j];

    int res=0;
    rep(i, 0) rep(j, 0) res=max(res, a[i][j]);
    cout<<res<<endl;
}


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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = m - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  bool judge = true;
  ll n,k;cin>>n>>k;
  vector<ll>a(n);
  rep(i,0,n)cin>>a[i];
  vector<ll>f(n);
  rep(i,0,n)cin>>f[i];
  sort(ALL(a));
  sort(ALLR(f));
  ll l=-1,r=INF;
  while(r-l>=2){
    ll mid=(l+r)/2;
    ll sumbuf=0;
    rep(i,0,n){
      sumbuf+=max(0LL,a[i]-mid/f[i]);
    }
    if(sumbuf<=k)r=mid;
    else l=mid;
  }
  cout<<r<<endl;
  return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
int M,D;
cin>>M>>D;
int ans=0;
for(int i=1;i<=M;++i){
  for(int j=22;j<=D;++j){
    if(j%10<2){
      continue;
    }
    else{
      if((j/10)*(j%10)==i){
        ans+=1;
      }
    }
  }
}
cout<<ans<<"\n";
return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

i64 minmax(i64 x, i64 y, i64 z) {
    i64 m = min(min(x, y), z);
    i64 M = max(max(x, y), z);
    return M - m;
}

int main() {
    i64 H, W; cin >> H >> W;

    auto solve = [](i64 H, i64 W) {
        i64 mind = 1e15;
        for (i64 y1 = 0; y1 <= H; y1++) {
            i64 S1, S2, S3, y2, y3, x2, x3;
            S1 = y1 * W;

            y2 = (H - y1) / 2;
            y3 = H - (y1 + y2);
            chmin(mind, minmax(S1, y2 * W, y3 * W));

            y2 = H - y1;
            x2 = W / 2;
            x3 = W - x2;
            chmin(mind, minmax(S1, y2 * x2, y2 * x3));
        }
        return mind;
    };

    i64 ans = min(solve(H, W), solve(W, H));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int H, W, K;
string A[810];
int memo[810][810];
int sy, sx;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
void solve(){
	bool used[810][810];
	rep(i, 810)rep(j, 810) used[i][j] = 0;
	queue<tuple<int, int, int>> que;
	// rep(i, H)rep(j, W)if(memo[i][j] == tar) que.pb(mp(i, j));
	rep(y, H)rep(x, W){
		if(memo[y][x] != 0){
			que.push(make_tuple(0, y, x));
		}
	}
	while(!que.empty()){
		int kaisu, y, x;
		tie(kaisu, y, x) = que.front(); que.pop();
		if(kaisu < K){
			rep(k, 4){
				int ny = y + dy[k], nx = x + dx[k];
				if(!(0 <= ny && ny < H && 0 <= nx && nx < W)) continue;
				if(used[ny][nx]) continue;
				// if(A[ny][nx] != '#') continue;
				A[ny][nx] = '.';
				used[ny][nx] = 1;
				que.push(make_tuple(kaisu + 1, ny, nx));
			}
		}
	}
}

int main(void){
	cin >> H >> W >> K;
	rep(i, H) cin >> A[i];
	rep(i, H)rep(j ,W) if(A[i][j] == 'S') sy = i, sx =j;
	// priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>> > q;
	int ans = 0;
	memo[sy][sx] = 1;
	while(1){
		ans++;
		queue<tuple<int, int, int>> q;
		rep(i, H)rep(j, W) if(memo[i][j] != 0)q.push(make_tuple(0, i, j));
		while(!q.empty()){
			int kaisu, y, x;
			tie(kaisu, y, x) = q.front(); q.pop();
			if(kaisu < K){
				rep(k, 4){
					int ny = y + dy[k], nx = x + dx[k];
					if(!(0 <= ny && ny < H && 0 <= nx && nx < W)) continue;
					if(memo[ny][nx] != 0) continue;
					if(A[ny][nx] != '.') continue;
					// printf("%d %d %d\n", ans, ny, nx);
					q.push(make_tuple(kaisu + 1, ny, nx));
					memo[ny][nx] = 1;
					if(ny == 0 || nx == 0 || ny == H - 1 || nx == W - 1){
						printf("%d\n", ans);
						return 0;
					}
				}
			}else{
				break;
			}
		}
		solve();
		// rep(i, H)cout << A[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 7220
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const ll MOD2=998244353;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  string n;
  cin >> n;
  ll k=n.size();
  bool b=false;
  rep(i,k-1){
    if(n[i+1]!='9'){
      b=true;
    }
  }
  if(b){
    cout << (n[0]-'0')+9*(k-1)-1 << endl;
  }
  else{
    cout << (n[0]-'0')+9*(k-1) << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <limits.h>
#include <list>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;

typedef vector<lint> vl;
typedef pair<lint,lint> pll;

//const int di[4] = {-1, 0, 1, 0};
//const int dj[4] = {0, -1, 0, 1};


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

    int n; cin>>n;
    vi p(n*n);
    for (int & i : p) cin>>i;

    vector<vi> _mp(n, vi(n));

    for (int i=0; i<n*n; ++i){
        int c = p[i]-1;
        _mp[c/n][c%n] = i;
    }
    const vector<vi> mp = _mp;

    vector<vi> ans(n, vi(n, INT_MAX));

//    deque<pii> bfs;



    for (int i=0; i<= n-1; i++){
        for (int j=0; j<=n-1; j ++){
            int a = min(i, j);
            int na = min(n-1-i, n-1-j);
            ans[i][j] = min(a, na) +1;
        }
    }
    int res = 0;
    vector<vi> dirs({{0,1}, {0,-1}, {-1,0}, {1,0}});

    vector<pii> bfs;
    for (int i=0; i<n*n; ++i){
        int c = p[i]-1;
        res += ans[c/n][c%n]-1;
        ans[c/n][c%n]--;

        bfs.clear();
        bfs.push_back({c/n, c%n});

        int cur = mp[c/n][c%n];

        for (int i=0; i<bfs.size(); ++i){
            pii pos = bfs[i];

            for (auto & dir : dirs){
                int len = ans[pos.first][pos.second];

                int nx = pos.first + dir[0];
                int ny = pos.second + dir[1];
                if (nx >=0 && nx <n && ny>=0 && ny < n){
                    if (mp[nx][ny] < cur){
                        if (ans[nx][ny] > len){
                            ans[nx][ny] = len;
                            bfs.emplace_back(nx, ny);
                        }
                    } else {
                        if (ans[nx][ny] > len+1){
                            ans[nx][ny] = len+1;
                            bfs.emplace_back(nx, ny);
                        }
                    }
                }
            }
        }

    }


//    while(!bfs.empty()){
//        pii pos = bfs.front(); bfs.pop_front();
//        for (vi dir : dirs){
//            int nx = pos.first + dir[0];
//            int ny = pos.second + dir[1];
//            int len = ans[pos.first][pos.second];
//            if (nx >=0 && nx <n && ny>=0 && ny < n){
//                if (mp[nx][ny] < mp[pos.first][pos.second]){
//                    push({nx, ny}, len+1, 1);
//                } else {
//                    push({nx, ny}, len, 0);
//                }
//            }
//        }
//    }

//    int res = 0;
//    for (vi & va : ans){
//        for (int i : va) res += i;
//    }
    cout<<res;


}


Measured memory_bytes: 9288
import sys

for a0 in range(1):
    n,m,x = input().strip().split(' ')
    n,m,x = [int(n),int(m),int(x)]
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    a.reverse()
    b.reverse()
    total = 0
    atmp = []
    for i in range(n):
        val = a.pop()
        if total + val > x:
            break
        total += val 
        atmp.append(val)

    max_count = len(atmp)
    cur_count = max_count
    while m:
        if total + b[-1] <= x:
            total += b.pop() 
            m -= 1
            cur_count += 1
            if cur_count > max_count:
                max_count = cur_count
            continue
        if not len(atmp):
            break
        aval = atmp.pop()
        total -= aval
        cur_count -= 1
    print (max_count)


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

template <typename T, typename U>
vector<U> make_vector(T&& n, U&& val) {
  return vector<U>(forward<T>(n), forward<U>(val));
}
template <typename T, typename... Args>
decltype(auto) make_vector(T&& n, Args&&... args) {
  return vector<decltype(make_vector(forward<Args>(args)...))>(forward<T>(n), make_vector(forward<Args>(args)...));
}

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

void solve() {
  int n;
  cin >> n;
  i64 ans = 0;
  rep(i, n) {
    ans += (i64) (i + 1) * (n - i);
  }
  rep(i, n - 1) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    if (u > v) swap(u, v);
    ans -= (i64) (u + 1) * (n - v);
  }
  cout << ans << endl;
}


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

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a; cin>>a;
	string s; cin>>s;
	if (a>=3200) cout<<s;
	else cout<<"red"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int k, i, total;
    scanf("%d", &k);

    if (k % 2 == 0)
    {
        for (i = 1; i < k / 2; i++)
        {
            total += i;
        }
        total = total * 2 + i;
    }
    if (k % 2 != 0)
    {
        for (i = 1; i < (k + 1) / 2; i++)
        {
            total += i;
        }
        total *= 2;
    }
    printf("%d", total);
    return 0;
}


Measured memory_bytes: 128
def main():
    N = int(input())
    p = [int(a) for a in input().split()]
    p_ = sorted(p)
    cnt = 0
    for i in range(N):
        if p[i] != p_[i]:
            cnt += 1
    if cnt <= 2:
        print("YES")
    else:
        print("NO")
main()

Measured memory_bytes: 2940
#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 main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> plus,minus;
    rep(i,n) {
        int x,y;
        cin >> x >> y;
        plus.push_back(x+y);
        minus.push_back(x-y);
    }
    sort(plus.begin(), plus.end());
    sort(minus.begin(), minus.end());
    int ans = max(plus.back() - plus.front(), minus.back() - minus.front());
    cout << ans << endl;
}


Measured memory_bytes: 5144
import collection.mutable.{ArrayBuffer, Queue}

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, m = sc.nextInt
  val e = List.fill(m)((sc.nextInt-1, sc.nextInt-1))

  val adj = ArrayBuffer.fill(n)(List[Int]())
  for ((a,b) <- e) {
    adj(a) ::= b
    adj(b) ::= a
  }

  val ans = ArrayBuffer.fill(n)(-1)
  ans(0) = 0
  val queue = Queue(0)
  while (queue.nonEmpty) {
    val u = queue.dequeue()
    for (v <- adj(u) if ans(v) == -1) {
      ans(v) = u + 1
      queue.enqueue(v)
    }
  }

  println("Yes")
  ans.tail.foreach(println)
}

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

using namespace std;

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

  for (int i = 0, next = a[0]; i < N; ++i) {
    if (next == 1) {
      cout << i+1;
      return 0;
    }
    next = a[next];
  }

  cout << -1;
}

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

int power(int x, int n) {
	if( x == 0 ) return 0;
	if( n == 0 ) return 1;
	if( n == 1 ) return x;
	if( n % 2 == 0 ) { 
		int y = power( x, n / 2 );
		return y * y;
	} else {
		int y = power( x, (n - 1)/2 );
		return y * y * x;
	}
	return 0;
}

int main(void){
   //FILE* fp_in = freopen("data.txt", "r", stdin);

	
	while( 1 ) {
		string s;
		cin >> s;
		if( s == "#" ) break;

		vector<bool> d;

		for(int i = 0; i < s.length(); ) {
			if( s[i] == 'w' ) {
				d.push_back( true );
				i += 4;
			} else if( s[i] == 'n' ){
				d.push_back( false );
				i += 5;
			}
		}

		int nume = 0;			//分子
		int deno = d.size() - 1;//分母

		for(int i = d.size() - 1; i >= 0; i--) {
			if( d.at(i) == true ) {
				nume *= 2;
				nume += 90;
			} else {
				nume *= 2;
				nume -= 90;
				if( nume < 0 ) nume = 0;
			}
		}

		while( nume % 2 == 0 && deno > 0 ) {
			deno --;
			nume /= 2;
		}

		if( deno == 0 ) {
			cout << nume << endl;
		} else {
			cout << nume << "/" << power(2,deno) << endl;
		}

	}


	//while(1){}
 
   return 0;
}

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

int main() {
    int r,b,ans;
    string S;
    cin >> S;
    r =0;
    b = 0;
    rep(i,S.length())
    {
        if(S.at(i) == '0')
            r += 1;
        else
            b += 1;
    }
ans = S.length() - abs(r-b);
cout << ans << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
int a[100],n;
void insertionSort(){
    int i,v,j;
    for(i=1;i<n;++i){
	v=a[i];
	j=i-1;
	while(j>=0&&a[j]>v){
	    a[j+1]=a[j];
	    --j;
	}
	a[j+1]=v;
        for(j=0;j<n;++j){
	    if(j) printf(" ");
	    printf("%d",a[j]);
	}
	printf("\n");
    }
}
int main(){
    int i;
    scanf("%d",&n);
    for(i=0;i<n;++i) scanf("%d",&a[i]);
    for(i=0;i<n;++i){
	    if(i) printf(" ");
	    printf("%d",a[i]);
    }
    printf("\n");
    insertionSort();
    return 0;
}
	


Measured memory_bytes: 2088
import sys
# import math
input = sys.stdin.readline


def int_array():
    return list(map(int, input().strip().split()))


def str_array():
    return input().strip().split()


def lower_letters():
    lowercase = [chr(i) for i in range(97, 97+26)]
    return lowercase

def how_frequent(lis):
	last = None
	count = []
	each = 1
	for i in range(len(lis)):
		if last != None:
			last = lis[i-1]
		if last == lis[i]:
			each += 1
		else:
			count.append(each)
			each = 0
		last = lis[i]
	return max(count)


def upper_letters():
    uppercase = [chr(i) for i in range(65, 65+26)]
    return uppercase

######################### TEMPLATE ENDS HERE ##################################


n = int(input())
ac,tle,re,wa= 0,0,0,0
for i in range(n):
	s = input().strip()
	if s == "AC":
		ac+=1
	elif s == "TLE":
		tle +=1
	elif s == "RE":
		re+=1
	else:
		wa+=1

print(f"AC x {ac}\nWA x {wa}\nTLE x {tle}\nRE x {re}\n")

Measured memory_bytes: 73680
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
int main(void){
  int d,n;
  scanf("%d%d",&d,&n);
  switch(d){
    case 0:
      if(n==100) printf("101");
      else printf("%d",n);
      break;
    case 1:
      if(n==100) printf("%d",101*n);
      else printf("%d",n*100);
      break;
    case 2:
      if(n==100) printf("%d",10100*n);
      else printf("%d",n*10000);
      break;
  }
  return 0;
}

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

int main() {
	
	int N, L;

	cin >> N >> L;
	int totalSum = 0;
	for (int i = 0; i < N; i++) {
		totalSum += L + i; 
	}
	int best = -1, diff = 1e9;
	for (int i = 0; i < N; i++) {
		int newSum = totalSum - (L + i);
		if (abs(totalSum - newSum) < diff) {
			best = newSum;
			diff = abs(totalSum - newSum);
		}
	}
	cout << best << "\n";
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#endif

#define ITER(c)         __typeof__((c).begin())
#define FOREACH(it, c)  for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)        __typeof__((c).rbegin())
#define RFOREACH(it, c) for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)       REPEAT(i, 0, n)
#define REPEAT(i, k, n) for (int i = (k); i < (n); ++i)
#define REVREP(i, n)    for (int i = ((n)-1); i >= 0; --i)
#define FIND(c, n)      std::find((c).begin(), (c).end(), (n));
#define BSEARCH(c, n)   std::binary_search((c).begin(), (c).end(), (n))
#define LLPOW(p1,p2)    ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)      (sizeof(A)/sizeof((A)[0]))
#define MIN(p1,p2)      (((p1)<(p2))?(p1):(p2))
#define MAX(p1,p2)      (((p1)>(p2))?(p1):(p2))
#define CIN_NO_SYNC     do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)       fgets((p), sizeof(p), stdin)
#define CHOMP(p)        do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n') *_q = 0; } while(0)

typedef double D;
inline D sign(D d){ return (d<0)?-1:d>0?1:0; }

int main(){
    int n;
    cin >> n;
    int p1 = 0, p2 = 0;

    REP(i,n){
        string a,b;
        cin >> a >> b;
        switch((int)sign(a.compare(b))){
        case -1:
            p1 += 3; break;
        case 0:
            p1++; p2++; break;
        case 1:
            p2 += 3; break;
        }
    }
    cout << p2 << " " << p1 << endl;
    return 0;
}

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

using namespace std;

int main()
{
    string s = "MARCH";
    int c[5] = {0,0,0,0,0};

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        string t;
        cin >> t;
        for (int j = 0; j < 5; j++) {
            if (t[0] == s[j]) {
                c[j]++;
            }
        }
    }

    long long ans = 0LL;
    for (int i = 0; i < 5; i++) {
        for (int j = i + 1; j < 5; j++) {
            for (int k = j + 1; k < 5; k++) {
                ans += 1LL * c[i] * c[j] * c[k];
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256