akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    val (N, A, B, C) = listOfInt()
    val L = (0 until N).map { nextInt() }
    var ans = Int.MAX_VALUE
    fun calc(V: IntArray) {
        var mp = 0
        var a = 0
        var b = 0
        var c = 0
        for (n in 0 until N) {
            when (V[n]) {
                0 -> { if (a > 0) mp += 10; a += L[n] }
                1 -> { if (b > 0) mp += 10; b += L[n] }
                2 -> { if (c > 0) mp += 10; c += L[n] }
            }
        }
        mp += Math.abs(a - A) + Math.abs(b - B) + Math.abs(c - C)
        if (a == 0 || b == 0 || c == 0) mp = 1001001001
        ans = Math.min(ans, mp)
    }
    fun dfs(d: Int, v: IntArray) {
        if (d == N) calc(v)
        else for (n in 0 until 4) {
            v[d] = n
            dfs(d + 1, v)
        }
    }
    val v = IntArray(N)
    dfs(0, v)
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)

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

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

  int n;
  cin>>n;
  double p[n+1];
  for (int i = 1; i <= n; ++i)
  {
  	cin>>p[i];
  }

  double dp[n+1][n+1], sum=0.0;
   memset(dp, 0.0, sizeof(dp));
  dp[0][0]=1.0;

  for (int i = 1; i <= n; ++i)
  {
  	for(int j=0; j<=i; j++)
  	{
  		if(j==0)
  			dp[i][j] = dp[i-1][j] * (1.0-p[i]);
  		else
  			dp[i][j] = dp[i-1][j] * (1.0-p[i]) + dp[i-1][j-1] * p[i] ;

  		// if(j>=(n+1)/2 && i==n)
    //      sum+= dp[i][j];
  	}
  }
  
  for (int i = (n+1)/2; i <= n; ++i)
  {
  	sum += dp[n][i];
  }
  cout<<fixed<<setprecision(9)<<sum;

  return 0;
}

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

int main() {
  float n;
  cin >> n;
  float count=0;
  for(int i=1; i<=n; i++){
    if((i%2)==1) {
      count++;
    }
  }
  cout << count/n << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll,P> T; 
const ll INF=2e18;
const ll MOD=1e9+7;

ll X,Y;

ll extgcd(ll a, ll b, ll& x, ll& y) {
  if (b == 0) {
    x = 1, y = 0; return a;
  }
  ll q = a/b, g = extgcd(b, a - q*b, x, y);
  ll z = x - q * y;
  x = y;
  y = z;
  return g;
}

ll invmod (ll a, ll m) { // a^-1 mod m
  ll x, y;
  extgcd(a, m, x, y);
  x %= m;
  if (x < 0) x += m;
  return x;
}

ll nCk(ll n, ll k, ll mod) {
  ll ans = 1;
  for (ll i = n, j = 1; j <= k; i--, j++) ans = (((ans * i) % mod) * invmod(j, mod)) % mod;
  return ans;
}



int main(){
    cin>>X>>Y;
    ll ans=0;
    for(ll i=0;i<=X;i++){//i回横に１、縦に２動く
        if(i*2>Y)break;
        ll x=X-i;
        ll y=Y-2*i;
        if(y*2==x){
            ans=(ans+nCk(y+i,y,MOD))%MOD;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>

using namespace std;
int N;
long long d[3005][3005];
int a[3005];

int main() {
    cin >> N;
    for (int i = 1; i <= N; i++)
        cin >> a[i];
    for (int i = 1; i <= N; i++)
        d[i][i] = a[i];
    for (int k = 2; k <= N; k++)
        for (int i = 1; i <= N - k + 1; i++) {
            int j = i + k - 1;
            d[i][j] = max(a[i] - d[i + 1][j], a[j] - d[i][j - 1]);
        }
    cout << d[1][N];
}

Measured memory_bytes: 70144
#include <iostream>
#include <vector>
using namespace std;
using pci = pair<char, int>;
using vpci = vector<pci>;

int main() {
    vpci card = {pci('S', 1), pci('S', 2), pci('S', 3), pci('S', 4),
                pci('S', 5), pci('S', 6), pci('S', 7), pci('S', 8),
                pci('S', 9), pci('S', 10), pci('S', 11), pci('S', 12), pci('S', 13),
                pci('H', 1), pci('H', 2), pci('H', 3), pci('H', 4),
                pci('H', 5), pci('H', 6), pci('H', 7), pci('H', 8),
                pci('H', 9), pci('H', 10), pci('H', 11), pci('H', 12), pci('H', 13),
                pci('C', 1), pci('C', 2), pci('C', 3), pci('C', 4),
                pci('C', 5), pci('C', 6), pci('C', 7), pci('C', 8),
                pci('C', 9), pci('C', 10), pci('C', 11), pci('C', 12), pci('C', 13),
                pci('D', 1), pci('D', 2), pci('D', 3), pci('D', 4),
                pci('D', 5), pci('D', 6), pci('D', 7), pci('D', 8),
                pci('D', 9), pci('D', 10), pci('D', 11), pci('D', 12), pci('D', 13)};
    int n;
    cin >> n;
    char pic; int num, a;
    for (int i = 0; i < n; i++) {
        cin >> pic >> num;
        a = 0;
        if (pic == 'H') a += 1 * 13;
        else if (pic == 'C') a += 2 * 13;
        else if (pic == 'D') a += 3 * 13;
        a += num - 1;
        card[a].second = 0;
    }
    for (auto x : card)
        if (x.second)
            cout << x.first << ' ' << x.second << endl;
}



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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c;cin >> a >> b >> c;
	int ans=0;
	if(a==b && b==c && a%2==0) cout << -1 << endl;
	else if(a%2==1 || b%2==1 || c%2==1) cout << 0 << endl;
	else{
		int d=0,e=0,f=0;
		while(true){
			ans++;
			d+=b/2+c/2;
			e+=a/2+c/2;
			f+=a/2+b/2;
			a=d;
			b=e;
			c=f;
			if(a%2==1 || b%2==1 || c%2==1){
				cout << ans << endl;
				break;
			}
			d=0;
			e=0;
			f=0;
		}
	}
}

Measured memory_bytes: 256
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

M, K = lr()
if K >= 2 ** M:
    print(-1); exit()
if M == 1:
    if K == 0:
        print("0 0 1 1")
    else:
        print(-1)
    exit()
A = [x for x in range(2 ** M) if x != K]
answer = A + [K] + A[::-1] + [K]
print(*answer)
# 22

Measured memory_bytes: 16268
s=input()
t=input()
ls=len(s)
lt=len(t)
if ls<lt:
    print('UNRESTORABLE')
    exit()
n=ls-lt+1
ans=[]
for i in range(n):
    tt='?'*i+t+'?'*(n-i-1)
    a=''
    for j in range(ls):
        if tt[j]!='?':
            if tt[j]!=s[j] and s[j]!='?':
                break
            a+=tt[j]
        else:
            if s[j]=='?':
                a+='a'
            else:
                a+=s[j]
    else:
        ans.append(a)
if ans:
    ans=sorted(ans)
    print(ans[0])
else:
    print('UNRESTORABLE')

Measured memory_bytes: 3064
#include <iostream>
#include <unordered_map>
#include <string>

using namespace std;

int main(void) {
    unordered_map<string, int> m;
    m["SSS"] = 0;
    m["SRR"] = 2;
    m["RRS"] = 2;
    m["RSR"] = 1;
    m["RRR"] = 3;
    m["SSR"] = 1;
    m["RSS"] = 1;
    m["SRS"] = 1;

    string s;
    cin >> s;
    cout << m[s] << endl;
    return 0;
}

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

#define int long long 

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

int a[maxn],b[maxn],n,ans;
priority_queue<pii > q;

signed main() {
    read(n);
    for(int i=1;i<=n;i++) read(a[i]);
    for(int i=1;i<=n;i++) read(b[i]);
    for(int i=1;i<=n;i++) if(b[i]>a[i]) q.push(mp(b[i],i));
    while(!q.empty()) {
        int x=q.top().sc;q.pop();
        int p=b[(x-1)?x-1:n]+b[x%n+1],t=0;
        // printf("%d %d\n",x,b[x]);
        ans+=(t=(b[x]-a[x])/p),b[x]-=t*p;
        if(!t) return puts("-1"),0;
        if(b[x]>a[x]) q.push(mp(b[x],x));
        // if(b[x]<a[x]) return puts("-1"),0;
        // printf("%d %d\n",x,b[x]);
    }write(ans);
    return 0;
}


Measured memory_bytes: 12016
#include<stdio.h>
int main(){
  int n,x,m[100],i,min=1000,sum=0;
  scanf("%d%d",&n,&x);
  for(i=0;i<n;i++){
    scanf("%d",&m[i]);
    sum+=m[i];
    if(min>m[i]) min=m[i];
  }
  printf("%d",n+(x-sum)/min);
}

Measured memory_bytes: 128
n,m=map(int,input().split())
nn=""
mm=[]
for i in range(n):
    nn+=input()+"\n"
for i in range(m):
    mm.append(input()+"\n")
count=0
for i in range(m):
    if(mm[i] in nn ):
        count+=1

if(count==m):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9+7
int main() {
    ll n;
    cin>>n;
    vector<ll> a(n);
    REP(i,n){
        cin>>a[i];
    }
    sort(all(a));
    bool ans=true;
    REP(i,a.size()-1){
        if(a[i]==a[i+1])ans=false;
    }
    if(ans)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


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


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

  if( b - a <= 2 ){
    cout << k + cntC << endl;
    return 0;
  }

  if(k % 2 == 0){
    cout << cntC + (b-a)*(k/2) << endl;
  }else{
    cout << cntC + (b-a)*(k/2) + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int X;
  cin >> X;
  int ans = 1;
  for(int i=2;i<=1000;i++){
    int b=i*i;
    while(b<=X){
      ans = max(ans,b);
      b *= i;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
bool v[200010];
int main()
{
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int n=read(),ans=0;v[0]=true;
	for(int i=1;i<=n;i++)
	{
		int w=read();
		if(v[w-1]==true)v[w]=true,ans=max(ans,w);
	}
	if(ans==0)puts("-1");
	else pr2(n-ans);
	return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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(void) {
    int N, A;
    cin >> N >> A;

    if (N % 500 <= A) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <locale>

using namespace std;

int main()
{
    int N;
    cin>>N;
    int a, b;
    a = N/100;
    b = N%100;
    if(a>12 && b<=12 && b > 0)
    {
        cout<<"YYMM";
    }
    else if(a==0 && b<=12 && b > 0)
    {
        cout<<"YYMM";
    }
    else if(b>12 && a<=12 && a > 0)
    {
        cout<<"MMYY";
    }
    else if(b==0 && a<=12 && a > 0)
    {
        cout<<"MMYY";
    }
    else if(a<=12 && a > 0 && b<=12 && b > 0)
    {
        cout<<"AMBIGUOUS";
    }
    else
    {
        cout<<"NA";
    }


    return 0;
}


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

using namespace std;

int main(void)
{
    string s;
    cin >> s;

    int l = s.size();
    int si = 0;
    int ei = l;
    for(int i = 0; i < l; ++i)
    {
        if(s[i] == 'A')
        {
            si = i;
            break;
        }
    }
    for(int i = l - 1; i >= 0; --i)
    {
        if(s[i] == 'Z')
        {
            ei = i;
            break;
        }
    }

    cout << ei - si + 1 << endl;
    return 0;
}

Measured memory_bytes: 888
open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f

    let readInts() =
        read string
        |> Seq.toArray
        |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
let print (s: string) = writer.Write s
let println (s: string) = writer.WriteLine s

[<AutoOpen>]
module Util =
    let strRev (s: string): string =
        s
        |> Seq.rev
        |> Seq.map string
        |> String.concat ""

    let inline roundup (x: ^a) (y: ^a): ^a =
        let one = LanguagePrimitives.GenericOne
        (x + y - one) / y

    let inline sameParity (x: ^a) (y: ^a): bool =
        let one = LanguagePrimitives.GenericOne
        (x &&& one) = (y &&& one)

let solve() =
    let [|n;a;b|] = reada int64
    match sameParity a b with
    | true ->
        let ans = (b - a) / 2L
        println (string ans)
    | false ->
        let la = a - 1L
        let ans1 = (b - a - 1L) / 2L + la + 1L
        let rb = n - b
        let ans2 = (b - a - 1L) / 2L + rb + 1L
        let ans = min ans1 ans2
        println (string ans)

    ()

[<EntryPoint>]
let main _ =
    solve()
    writer.Close()
    0 // return an integer exit code


Measured memory_bytes: 13396
#include<stdio.h>

int main(void){
	int warnings = 0;
	while(1){
		int std;
		double wgh,tll;
		double BMI = 0.0;

		if( EOF == scanf("%d,%lf,%lf", &std, &wgh, &tll) ) break;

		BMI = wgh / (tll * tll);

		if( BMI >= 25.0 ){
			printf("%d\n",std);
			warnings++;
		}
	}
	if(warnings == 0) printf("ツ該ツ督鳴づ按つオ\n");
	return 0;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long

typedef pair<lint, lint> P;
const lint MOD = 1e9+7;
const lint INF = MOD * MOD;

int main(){
    int n; cin >> n;
    vector<lint> a;
    rep(i, n*3){
        lint x; cin >> x; a.push_back(x);
    }

    priority_queue<lint, vector<lint>, greater<lint> > pq;
    vector<lint> max_s, min_s;
    rep(i, n*2){
        if(i < n){
            pq.push(a[i]);
            if(i == 0) max_s.push_back(a[0]);
            else max_s.push_back(max_s[i-1] + a[i]); 
            continue;
        }
        pq.push(a[i]);
        max_s.push_back(max_s[i-1] + a[i] - pq.top());
        pq.pop();
    }
    priority_queue<lint, vector<lint>, less<lint> > pr;
    rep(i, n*2){
        int j = n*3 - i - 1;
        if(i < n){
            pr.push(a[j]);
            if(j == n*3 - 1) min_s.push_back(a[j]);
            else min_s.push_back(min_s[i-1] + a[j]); 
            continue;
        }
        pr.push(a[j]);
        min_s.push_back(min_s[i-1] + a[j] - pr.top());
        pr.pop();
    }
    lint ans = -INF;
    rep(i, n + 1){
        int j = i + n - 1, k = n*2 - i - 1;
        ans = max(ans, max_s[j] - min_s[k]);
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int H, W; scanf("%d %d", &H, &W);
  vector<string> C(H);
  for (int i = 0; i < H; ++i) {
    cin >> C[i];
  }
  vector<string> ans;
  for (int i = 0; i < H; ++i) {
    ans.push_back(C[i]);
    ans.push_back(C[i]);
  }
  for (int i = 0; i < (int)ans.size(); ++i) {
    printf("%s\n", ans[i].c_str());
  }
  return 0;
}


Measured memory_bytes: 256
while True:
  a, op, b = input().split()
  a = int(a)
  b = int(b)

  if op == "?":
    break
  if op == "+":
    print(a + b)
  if op == "-":
    print(a - b)
  if op == "*":
    print(a * b)
  if op == "/":
    print(a // b)


Measured memory_bytes: 5592
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int T = sc.nextInt();
		sc.close();
		int result = (N / X) * T;

		if(N % X > 0) {
			result = result + T;
		}

		System.out.println(result);

	}

}

Measured memory_bytes: 27076
#
# File    : B.rb
# Author  : Kazune Takahashi
# Created : 2018-6-16 21:02:12
# Powered by Visual Studio Code
#

d, n = gets.chomp.split(" ").map{|i| i.to_i}

if n < 100
  puts (100 ** d) * n
else
  puts (100 ** d) * (n + 1)
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define F2(i,a,b) for(int i=(a);i<(b);++i)
#define dF(i,a,b) for(int i=(a);i>=(b);--i)
#define dF2(i,a,b) for(int i=(a);i>(b);--i)
#define dF3(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define eF(i,u) for(int i=h[u];i;i=nxt[i])
using namespace std;typedef long long ll;typedef double ld;int INF=0x3f3f3f3f;int INF2=0x7fffffff;ll LNF=0x3f3f3f3f3f3f3f3f;ll LNF2=0x7fffffffffffffff;

int n;
int p[200001],out[200001];

int h[200001],nxt[200005],to[200005],tot;
void ins(int x,int y){nxt[++tot]=h[x];to[tot]=y;h[x]=tot;}

int que[200001],l=1,r;
int a[200001],k[200001];

int s;

bool check(){
	int now=p[s];
	for(;now!=s;now=p[now]){
		eF(i,now) k[a[to[i]]]=1;
		for(int i=0;;++i) if(!k[i]) {a[now]=i; break;}
		eF(i,now) k[a[to[i]]]=0;
	}
	bool ok=1;
	eF(i,s) k[a[to[i]]]=1;
	for(int i=0;;++i) if(!k[i]) {if(a[s]!=i) ok=0; break;}
	eF(i,s) k[a[to[i]]]=0;
	return ok;
}

int main(){
	scanf("%d",&n);
	F(i,1,n) scanf("%d",p+i), ins(p[i],i), ++out[p[i]];
	F(i,1,n) if(!out[i]) que[++r]=i;
	F(i,1,n) a[i]=-1;
	while(l<=r){
		int u=que[l++];
		eF(i,u) k[a[to[i]]]=1;
		for(int i=0;;++i) if(!k[i]) {a[u]=i; break;}
		eF(i,u) k[a[to[i]]]=0;
		if((--out[p[u]])==0) que[++r]=p[u];
	}
	F(i,1,n) if(a[i]==-1) s=i;
	eF(i,s) k[a[to[i]]]=1;
	for(int i=0;;++i) if(!k[i]) {a[s]=i; break;}
	eF(i,s) k[a[to[i]]]=0;
	if(check()) {puts("POSSIBLE"); return 0;}
	k[a[s]]=1;
	eF(i,s) k[a[to[i]]]=1;
	for(int i=0;;++i) if(!k[i]) {a[s]=i; break;}
	eF(i,s) k[a[to[i]]]=0;
	if(check()) {puts("POSSIBLE"); return 0;}
	puts("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define MAXN 100005
#define ll long long
#define pb push_back
#define sortv(v) sort(v.begin(),v.end())
#define tc(t) int t;cin>>t;while(t--)
#define copy copy_n
#define fr(i,a,b) for(long long i=a;i<b;i++)
#define frr(i,a,b) for(long long i=a;i>=b;i--)
#define frn(i,a,b,n) for(long long i=a;i<=b;i=i+n)
#define gcd(x,y) __gcd(x,y)
#define ld long double
#define um unordered_map
#define mkp make_pair
#define b_s binary_search
#define des greater<ll>()
#define fi first
#define se second
ll mul(ll a,ll b,ll p=mod){return ((a%p)*(b%p))%p;}
ll add(ll a,ll b,ll p=mod){return (a%p + b%p)%p;}
void input(ll a[],ll sz){fr(i,0,sz) cin>>a[i];}
void print(ll a[],ll sz){fr(i,0,sz){if(i==sz-1) cout<<a[i]<<"\n";else cout<<a[i]<<" ";}}
ll maxr(ll a[],ll sz){ll ma;fr(i,0,sz){if(i==0) ma=a[i];else if(a[i]>ma) ma=a[i];}return ma;}
ll minr(ll a[],ll sz){ll mi;fr(i,0,sz){if(i==0) mi=a[i];else if(a[i]<mi) mi=a[i];}return mi;}
ll isprm(ll n) {
    if (n <= 1)  return 0; 
    if (n <= 3)  return 1; 
    if (n%2 == 0 || n%3 == 0) return 0; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return 0; 
    return 1;}
/*ll spf[MAXN];
void sieve() 
{
    spf[1]=1; 
    for (ll i=2; i<MAXN; i++) 
        spf[i] = i; 
    for (ll i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for(ll i=3;i*i<MAXN;i++) 
    {
        if (spf[i]==i) 
        {
            for (int j=i*i;j<MAXN;j+=i) 
                if (spf[j]==j) 
                    spf[j]=i; 
        }
    }
}*/
ll power(ll x,ll y,ll p=mod) 
{ 
    ll res = 1;
    x = x % p;
    while (y > 0) 
    {
        if (y & 1) 
            res = (res*x) % p;
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll n,ll p=mod) 
{ 
    return power(n, p-2, p); 
} 
ll ncrMod(ll n,ll r,ll p=mod) 
{
   if (r==0) 
      return 1;
    ll fac[n+1]; 
    fac[0] = 1; 
    for (ll i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}
//a+b=xor(a,b)+2*(a&b)//
bool comp(const pair<int,int> &a, 
              const pair<int,int> &b) 
{
    if(a.fi==b.fi)
    {
        return (a.se>b.se);//second elem in descending
    }
    return (a.first < b.first);//first elem in ascending 
}
ll n,k,h[100005],dp[100005];











int main()
{
	fio;
	cin>>n>>k;
	input(h,n);
	fr(i,0,100005)
	dp[i]=0;
	for(ll i=n-2;i>=0;i--)
	{
	    dp[i]=abs(h[i]-h[i+1])+dp[i+1];
	    fr(j,i+2,min(i+k+1,n))
	    dp[i]=min(dp[i],abs(h[i]-h[j])+dp[j]);
	}
	cout<<dp[0]<<"\n";
	return 0;
}


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

#define ll long long
#define f first
#define s second
#define inf 1e15

#define N 300005

string s;
ll n,m,x,y,d,k;
ll a[N];

ll parent[N];
ll siz[N];

int find(int g){
    
  if(parent[g]!=g){
      parent[g]=find(parent[g]);
  }
  return parent[g];
}
int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
	int t=1;
	//cin>>t;
	while(t--){
	    
	    
	    cin>>n>>m;
	    
	    for(int i=0;i<n;i++){
	        parent[i]=i;
	        siz[i]=1;
	       
	    }
	    
	    for(int i=0;i<m;i++){
	        
	        int x,y;;
	        cin>>x>>y;
	        x--;y--;
	        
	        x=find(x);
	        y=find(y);
	        
	        if(x==y)
	        continue;
	        
	        parent[x]=y;
	        siz[y]+=siz[x];
	        
	    }
	    
	    ll ans=0;
	    for(int i=0;i<n;i++){
	        ans=max(ans,siz[find(i)]);
	    }
	    
	    
	    cout<<ans<<"\n";
	    
	    
	}
	return 0;
}


Measured memory_bytes: 12892
#include <stdio.h>
#include <math.h>
#include <complex.h>
#include <string.h>
#include <stdlib.h>

typedef long long ll;

void swap(char* a, char* b) {
    char  tmp = *a;
    *a = *b;
    *b = tmp;
}
void display(void* array, const size_t total_elems, const size_t size) {
    int i;
    switch (size) {
    case sizeof(char) :
	for(i=0; i<total_elems; i++) 
	    printf ("%d ",*(((char*)array)+i));
	printf ("%\n");
	break;
    case sizeof(int) :
	for(i=0; i<total_elems; i++) 
	    printf ("%d ",*(((int*)array)+i));
	printf ("%\n");
	break;
    case sizeof(long long) :
	for(i=0; i<total_elems; i++) 
	    printf ("%Ld ",*(((long long*)array)+i) );
	printf ("%\n");
	break;
    }

}
void reverse(void *array, const size_t total_elems, const size_t size) {
    int i,j;
    for(i=0; i<total_elems/2; i++) {
	for(j=0; j<size; j++) {
	    swap( ((char*)array)+size*i+j, ((char*)array)+size*(total_elems-i-1)+j );
	}
    }
}

int ll_comp(const void* a, const void* b) {
    ll A = *(ll*)a;
    ll B = *(ll*)b;
    int ans;
    if( A > B )  ans = 1; 
    if( A == B ) ans = 0;
    if( A < B )  ans = -1;
    return ans;
}

int main () {
    ll N;
    ll a[110];
    int i;
    scanf("%Ld",&N);

    for(i=0; i<N; i++) {
	scanf("%Ld",&a[i]);
    }

    qsort(a,N,sizeof(ll),ll_comp);   
    reverse(a,N,sizeof(ll));
    
    ll ans = 0;
    for(int i=0; i<N; i++) {
	if(i%2 == 0)
	    ans += a[i];
	else
	    ans -= a[i];
    }
    printf("%Ld\n",ans);
    return 0;
}


Measured memory_bytes: 128
a=int(input())
b=int(input())
c=int(input())
x=int(input())

count=0

for i in range(a+1):
    for j in range(b+1):
        for s in range(c+1):
            if (i*500+j*100+s*50)==x:
                count+=1
print(count)

Measured memory_bytes: 3060
N=int(input())
while N!=0:
  a=N
  ans=0
  for i in range(1,N):
    for k in range(i,N):
      a=a-k
      if a==0 and N!=k:
        ans+=1
      elif a<0:
        break
    a=N   
  print(ans)
  N=int(input())


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()      //昇順
#define RALL(obj) (obj).rbegin(), (obj).rend()   //降順
#define print(obj) cout << obj << endl
#define scan(obj) cin >> obj

typedef long long ll;

using namespace std;

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    print(a * b / 2);
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using s32 = int;
using u32 = unsigned int;
using s64 = long long int;
using u64 = unsigned long long int;

u32 n, s;
u32 A[200000];

constexpr u32 mod = 998244353;

u32 modpow(u32 a, int n){
  u32 r = 1;
  for(; n; n >>= 1){
    if(n&1) r = (u64) r * a % mod;
    a = (u64) a * a % mod;
  }
  return r;
}

u32 dp[200001];

int main(){
  scanf("%d%d", &n, &s);
  for(int i = 0; i < n; ++i) scanf("%d", A+i);

  dp[0] = 1;
  for(u32 i = 0; i < n; ++i){
    for(int j = s; j >= 0; --j){
      dp[j] = (2 * dp[j] + (j >= A[i] ? dp[j-A[i]] : 0)) % mod;
    }
  }

  printf("%d\n", (u32) dp[s]);

  return 0;
}


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

struct tPoint{
	double x, y;
};

double f( double x, tPoint &a, tPoint &b ){
	return (b.y-a.y)*(x-a.x)/(b.x-a.x) + a.y;
}

int main(){
	tPoint a, b, c, d;
	string in;
	while( getline( cin, in ), in.length() ){
		sscanf( in.c_str(), "%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &a.x, &a.y, &b.x, &b.y, &c.x, &c.y, &d.x, &d.y );
		bool isCrossAC, isCrossBD;
		if( b.x == d.x ){
			isCrossBD = ((a.x>b.x&&c.x<b.x)||(a.x<b.x&&c.x>b.x));
		}else{
			double fa = f( a.x, b, d );
			double fc = f( c.x, b, d );
			isCrossBD = ((a.y>fa&&c.y<fc)||(a.y<fa&&c.y>fc));
		}
		if( a.x == c.x ){
			isCrossAC = ((b.x>a.x&&d.x<a.x)||(b.x<a.x&&d.x>a.x));
		}else{
			double fb = f( b.x, a, c );
			double fd = f( d.x, a, c );
			isCrossAC = ( ((b.y>fb&&d.y<fd)||(b.y<fb&&d.y>fd)) );
		}
		if( isCrossAC && isCrossBD )
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#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>;
const int INF = 1000000000;
const int MOD = 1000000007;

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

int main() {
  long double r;
  cin >> r;
  long double ans = 2 * r * M_PI;
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}


Measured memory_bytes: 3792
n,a,b,c,d = map(int, input().split())
S = input()
SA = S[a-1:c]
SB = S[b-1:d]
if "##" in SA or "##" in SB:
    print("No")
else:
    if c < d:
        print("Yes")
    else:
        if "..." in SB:
            print("Yes")
        else:
            if (b > 1 and S[b-2:b+1] == "...") or (d < n and S[d-2:d+1] == "..."):
                print("Yes")
            else:
                print("No")

Measured memory_bytes: 3572
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll n;
  cin >> n;
  ll d[n][2];
  bool ans = false;
  ll st = 0;
  for(int i=0;i<n;i++){
    cin >> d[i][0] >> d[i][1];
    if(d[i][0]==d[i][1]){
      st++;
    }else{
      st = 0;
    }
    if(st>=3){
      ans = true;
    }
  }
  if(ans) cout <<"Yes\n";
  else cout <<"No\n";
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> As, Bs, Cs;
    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        As.push_back(x);
    }
    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        Bs.push_back(x);
    }

    for(int i = 0; i < n-1; i++)
    {
        int x;
        cin >> x;
        Cs.push_back(x);
    }
    long long ans = Bs[As[0]-1];
    for(int i = 1; i < n; i++)
    {
        if(As[i] == (As[i-1]+1))
        {
            ans += (Bs[As[i]-1] +Cs[As[i]-2]);
        }
        else
        {
            ans += Bs[As[i]-1];
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

#print(lcm(27, 18, 9, 3))
n=int(input())
ab = []
for _ in range(n):
    a= int(input())
    ab.append(a)
print(lcm(ab))

Measured memory_bytes: 5100
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner cd =new Scanner(System.in);
		
		int x = cd.nextInt();
		int y = cd.nextInt();
		int z = cd.nextInt();
		
		int num = (x-z)/(y+z);
		System.out.println(num);
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <bitset>
#include <fstream>
#include <unordered_set>
#include <unordered_map>
#include <ext/pb_ds/assoc_container.hpp>
  
          
using namespace std;
using namespace __gnu_pbds;
 
  
 
/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")*/
      
#define int long long
#define eb emplace_back
#define pb push_back
#define ld long double
#define mp make_pair
#define f first
#define s second
#define deb(a) cerr << #a << " = " << a << '\n';
#define fast() { \
    ios_base::sync_with_stdio(0); \
    cin.tie(0); \
    cout << fixed << setprecision(5); \
    cerr << fixed << setprecision(11); \
}
 
template < typename firstType, typename secondType = null_type, class compare = less < firstType > >
struct sett {
    typedef tree <
        firstType,
        secondType,
        compare,
        rb_tree_tag,
        tree_order_statistics_node_update
    > _ ;
};
 
  
const int INF = 1e9 + 7;
const ld EPS = 1e-10;
const int MAXI = 200000;
const int P = 223; 
const int MOD = 998244353; 
const int MAXST = 2000000;
const ld PI = 3.14159265358979323;
        
ostream &operator<<(ostream &stream, const pair <int, int> &p) {
    stream << p.first << ' ' << p.second << ' ';
    return stream;
}


signed main(){  
    fast();
    srand(time(0));
    #ifdef _LOCAL               
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int x;
    cin >> x;
   	int ans = 100, ans1 = 0;
   	while (ans < x){
   		ans += ans / 100;
   		ans1++;
   	}
   	cout << ans1 << '\n';
    return 0;                   
   	
}

Measured memory_bytes: 3628
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================
//using系

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;
using ld = long double;
using qul = queue<ll>;
using pql = priority_queue<ll>;

// ========================================================================
//define系

//#define int long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)

// ========================================================================


ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a)
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a)
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll mch(ll n) {
	if (n == 1) return 1;
	else return n * mch(n - 1);
}
//1から整数nまでの階乗を出す(INFで割っていない)
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double m = sqrt(a);
	for (int i = 3; i <= m; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}
//素数判定
ll modpow(ll a, ll n, ll mod) {
	ll hi = 1;
	while (n > 0) {
		if (n & 1) hi = hi * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return hi;
}
//いろいろやります（ただの前座）
ll mg(ll a, ll mod) {
	return modpow(a, mod - 2, mod);
}
//割り算の10^9+7等対策で逆元を出します 




// ========================================================================


/*signed*/int main() {
	ll n; cin >> n;
	vector<tuple<string, ll, ll>> d(n);
	for (int i = 0; i < n; i++) {
		string a;
		ll b;
		cin >> a >> b;
		d[i] = make_tuple(a, 100 - b, i + 1);
	}
	sort(d.begin(), d.end());
	for (int i = 0; i < n; i++) cout << get<2>(d[i]) << endl;

	return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <string.h>
#define MAX 1000020

int p[MAX],size;
int flg[MAX];

int isPrime(int x){
	int i;
	for(i=0;p[i]*p[i]<=x;i++){
		if(x % p[i] == 0) return 0;
	}
	return 1;
}

int main(void){
	int i;
	int a,d,n;

	p[0] = 2;
	size = flg[2] = 1;
	flg[0] = flg[1] = 0;

	for(i=3;i<MAX;i++){
		if(isPrime(i)){
			p[size++] = i;
			flg[i] = 1;
		}
		else{
			flg[i] = 0;
		}
	}

	while(scanf("%d%d%d",&a,&d,&n) && (a||d||n)){
		while(1){
			if(flg[a]){
				n--;
				if(n == 0) break;
			}
			a += d;
		}

		printf("%d\n",a);
	}

	return 0;
}

Measured memory_bytes: 4624
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;

int main(){
  int n;
  cin>>n;
  vector<int>l(n);
  rep(i,n)cin>>l[i];
  sort(l.begin(),l.end());
  int sum=0;
  rep(i,n-1)sum+=l[i];
  if(sum>l[n-1])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
  

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

typedef pair<int, int> R;

int main() {
	int w, h;
	while (cin >> h >> w, h || w) {
		R rect(h * h + w * w, h);
		R res(150 * 150 * 2, 150);
		R resR(150, 150);
		for (int i = 1; i <= 150; i++) {
			for (int j = i + 1; j <= 150; j++) {
				R p(i * i + j * j, i);
				if (rect < p && p < res) {
					res = p;
					resR = make_pair(i, j);
				}
			}
		}
		cout << resR.first << ' ' << resR.second << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
from cmath import exp
from math import pi
x1, y1, x2, y2 = map(int, input().split())
v = x2 - x1 + (y2-y1)*1j
v_ = v*exp(pi/2*1j)

x3 = round(x2+v_.real)
y3 = round(y2+v_.imag)

x4 = round(x1+v_.real)
y4 = round(y1+v_.imag)

print(x3, y3, x4, y4)

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

int main()
{
  long long n;
  cin >> n;
  for (long long a = 1; a <= 3500; a++)
  {
    for (long long b = 1; b <= 3500; b++)
    {
      if (4 * a * b - n * a - n * b <= 0 || ((n * a * b) % (4 * a * b - n * a - n * b) != 0))
        continue;
      long long c = (n * a * b) / (4 * a * b - n * a - n * b);
      cout << a << " " << b << " " << c << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M, K = map(int, input().split())

uf = UnionFind(N+1)
AB_list = []

for i in range(M):
    A, B = map(int, input().split())
    AB_list.append([A, B])
    uf.union(A, B)

dame = [[] for i in range(N+1)]
for i in range(M):
    if uf.same(AB_list[i][0], AB_list[i][1]):
        dame[AB_list[i][0]].append(AB_list[i][1])
        dame[AB_list[i][1]].append(AB_list[i][0])

for i in range(K):
    C, D = map(int, input().split())
    if uf.same(C, D):
        dame[C].append(D)
        dame[D].append(C)

ans_list = []
for i in range(1, N+1):
    ans_list.append(uf.size(i) - len(dame[i]) - 1)
    #print(ans, uf.size(i), len(dame[i]))
print(*ans_list)


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

int main() {

    int d,n;

    cin >> d >> n;

    int ans = 1;

    for(int i=0; i<d; i++){
        ans *= 100;
    }

    if(n != 100) {
        ans *= n;
    }
    else if(d == 0 && n == 100){
        ans = 101;
    }
    else if(d == 1 && n == 100){
        ans = 10100;
    }
    else if(d == 2 && n == 100){
        ans = 1010000;
    }

    cout << ans << endl;

    return 0;
}

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

int inputint(void){int n;cin >> n;return n;
}
vector<int> inputvecint(int n){vector<int> vec(n);for(int i=0;i<n;i++)cin>>vec.at(i);return vec;}

int main(){
  int N=inputint();
  vector<int> a=inputvecint(N);
  vector<int> b(N);
  b.at(0) = 1;
  int n=-1;
  for(int i=0;i<N-1;i++) {
    b.at(i+1) = a.at(b.at(i)-1);
    if (b.at(i+1)==2) {
      n=i+1;
      break;
    }
  }
  cout << n << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){
ll n,k;
cin>>n>>k;
ll a[n];
for(int i=0;i<n;i++){
    cin>>a[i];
}
sort(a,a+n,greater<ll>());
ll ans=0;
for(int i=0;i<k;i++){
    ans+=a[i];
}
cout<<ans<<endl;
}












Measured memory_bytes: 256
// ????????¬?????????????????°
// x??§?¨?????????????y??§?¨?????????????????????????????????§????????????????????¨???
// ????????\?????????????????°???????????§????????§???????????¨???????????????????????????
// ?????£??¨??§?????????????????£??????

#include <iostream>
using namespace std;
#define ERROR "Miserable Hokusai!"
int gx,gy,p,x1,y1,x2,y2,dataset,S;
int position[30][30] = {0};
bool Under[30][30] = {true};
bool Right[30][30] = {true};

void initUnderRight () {
  for (int i=0; i<25 ; i++)
    for (int j=0; j<25 ; j++)
      Under[i][j] = true;

  for (int i=0; i<25 ; i++)
    for (int j=0; j<25 ; j++)
      Right[i][j] = true;

  for (int i=0; i<25 ; i++)
    for (int j=0; j<25 ; j++)
      position[i][j] = 0;
}

int main(){
  cin >> dataset;
  for (int j=0; j<dataset; j++) {
    cin >> gx >> gy;
    cin >> p;
    initUnderRight();
    position[0][0] = 1;
    for (int i=0; i<p; i++){
      cin >> x1 >> y1 >> x2 >> y2;
      if (x1 != x2) // right
        Right[min(x1,x2)][y1] = false;
      else // under
        Under[x1][min(y1,y2)] = false;
    }
    // y-coodinate : 0
    for (int x=1; x<=gx ; x++) 
      if (Right[x-1][0]) position[x][0] = position[x-1][0];
    // x-coodinate : 0
    for (int y=1; y<=gy ; y++) 
      if (Under[0][y-1]) position[0][y] = position[0][y-1];

    for (int y=1; y<=gy; y++) {
      for (int x=1; x<=gx ; x++)
        // only under
        if (Under[x][y-1] && !Right[x-1][y]) position[x][y] = position[x][y-1];
        // only right
        else if (!Under[x][y-1] && Right[x-1][y]) position[x][y] = position[x-1][y];
        // no way
        else if (!Under[x][y-1] && !Right[x-1][y]) position[x][y] = 0;
        // right and under
        else position[x][y] = position[x][y-1] + position[x-1][y];
    }
    if (position[gx][gy] == 0) cout << ERROR << endl;
    else cout << position[gx][gy] << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
N = int(input())

ST = []
for _ in range(N):
    s, t = tuple(input().split())
    ST.append((s, int(t)))

X = input()
isSleep = False
T = 0
for s, t in ST:
    if isSleep:
        T += t
    if s == X:
        isSleep = True

print(T)

Measured memory_bytes: 3060
n = int(input())
a = list(map(int, input().split()))
b = [x*x for x in a]

#print(a)
#print(b)

s = sum(a)
s = s * s - sum(b)
s = s // 2
s = s % 1000000007

print(s)

# (a+b+c)^2 = a^2 + b^2 + c^2 + 2ab + 2ac + 2bc

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll H;
    cin >> H;
    ll ans = 1;
    while (H > 1){H /= 2; ans *= 2;}
    cout << 2 * ans - 1 << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
// AtCoder Grand Contest 017
// C - Snuke and Spells

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;


const int MAX_N = 200000;
const int MAX_M = 200000;

int N, M;
int A[MAX_N];
int cnt[MAX_N + 1];
int sec_raw[2 * MAX_N + 2];
int *sec = sec_raw + MAX_N;

int main() {

    int x, y;
    int idx;
    int ans;

    cin >> N >> M;
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        cnt[A[i]]++;
    }
    memset(sec_raw, 0, sizeof(sec_raw));
    for (int i = 1; i <= N; i++) {
        sec[i - cnt[i] + 1]++;
        sec[i + 1]--;
    }
    ans = 0;
    for (int i = -N + 1; i <= N; i++) {
        sec[i] += sec[i - 1];
        ans += (i >= 1 && sec[i] == 0 ? 1 : 0);
    }

    for (int q = 0; q < M; q++) {
        cin >> x >> y; x--;
        idx = A[x] - cnt[A[x]] + 1;
        sec[idx]--;
        ans += (idx >= 1 && sec[idx] == 0 ? 1 : 0);
        cnt[A[x]]--;
        A[x] = y;
        cnt[y]++;
        idx = y - cnt[y] + 1;
        ans -= (idx >= 1 && sec[idx] == 0 ? 1 : 0);
        sec[idx]++;

        cout << ans << endl;
    }

    return 0;

}





Measured memory_bytes: 4608
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K = map(int, read().split())

for i in range(100):
    if (K**i <= N) & (N < K**(i + 1)):
        print(i + 1)


Measured memory_bytes: 2940
n=int(input())
foods = list(map(int,input().split()))
satisfy = list(map(int,input().split()))
chain = list(map(int,input().split()))
ans = 0

for i in range(0,n):
    ans += satisfy[foods[i]-1]
    if  i<n-1 and foods[i] == foods[i+1]-1:
        ans += chain[foods[i]-1]
print(ans)

Measured memory_bytes: 3064