akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <algorithm>
#define R register
using namespace std;
const int MAXN=300100;
const int MAXM=100100;
int sum[MAXM],n;

template<class T>void read(T &x)
{
	x=0;int ff=0;char ch=getchar();
	while(ch<'0'||ch>'9'){ff|=(ch=='-');ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	x=ff?-x:x;
}

struct seqs
{
	int l,r,d;
	bool operator<(const seqs& aa)const
	{return d<aa.d;}
}seq[MAXN];

int lowbit(int x)
{return x&(-x);}

void change(int x,int pos)
{
	while(pos<=n)
	{
		sum[pos]+=x;
		pos+=lowbit(pos);
	}
}

int getsum(int pos)
{
	int ans=0;
	while(pos)
	{
		ans+=sum[pos];
		pos-=lowbit(pos);
	}
	return ans;
}

int main()
{
	int m;
	read(m),read(n);
	for(R int i=1;i<=m;++i)
	{
		read(seq[i].l),read(seq[i].r);
		seq[i].d=seq[i].r-seq[i].l+1;
	}
	sort(seq+1,seq+1+m);
	int now=1;
	for(R int i=1;i<=n;++i)
	{
		int ans=0;
		while(now<=m&&seq[now].d<i)
		{
			change(1,seq[now].l);
			change(-1,seq[now].r+1);
			++now;
		}
		for(R int j=0;j<=n;j+=i)
		  ans+=getsum(j);
		ans+=m-now+1;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
//#define mp make_pair

ll ans, ya[101010],xa[101010], ay,ax, n, m, x[101010], y[101010];


int main(){

ios::sync_with_stdio(0);
cin.tie(0);

cin >> n >> m;
rep(i,1,n)cin >> x[i];
rep(i,1,m)cin >> y[i];

sort(x+1, x+n+1);
sort(y+1, y+m+1);


rep(i, 1, m-1){
ya[i]= abs(y[i+1]-y[i]);

}

rep(i, 1, n-1){
xa[i]= abs(x[i+1]-x[i]);
}

for(ll i =1; i<=m-1; i++){
ay += (((ya[i]*(m-i))%mod)*(i))%mod;
}

for(ll i =1; i<=n-1; i++){
ax += (((xa[i]*(n-i))%mod)*(i))%mod;
}
ax = ax%mod;
ay = ay%mod;
ans = ay*ax%mod;
cout << ans << endl;

}

/*

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
//#define mp make_pair

ll ans, ya[101010],xa[101010], ay, n, m, x[101010], y[101010];


int main(){

ios::sync_with_stdio(0);
cin.tie(0);

cin >> n >> m;
rep(i,0,n-1)cin >> x[i];
rep(i,0,m-1 )cin >> y[i];

sort(x, x+n);
sort(y, y+m);

rep(i, 0, m-2){
ya[i]= abs(y[i+1]-y[i]);
xa[i]= abs(x[i+1]-x[i]);
}

for(ll i= m-2;i >=0; i++){
ay += (ya[m-i-2]*(i+1))*(m-1-i);
}
cout << ay%mod << endl;

ans = (ay*(x[1]-x[0]))%mod;
rep(i, 1, n-2){
ans+= ((ay*(x[i+1]-x[0])%mod) + (ay*(x[i+1]-x[i])%mod))%mod;
//cout << ans << endl;
}

cout << ans%mod << endl;

}
*/


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

int main() {
    int x, y, s;
    while (cin >> x >> y >> s and (x or y or s)) {
        int ans = 0;
        for (int i=1; i<=1000; ++i) {
            for (int j=1; j<=1000; ++j) {
                int a = i * (100 + x) / 100;
                int b = j * (100 + x) / 100;
                int aa = i * (100 + y) / 100;
                int bb = j * (100 + y) / 100;
                if (a + b == s) {
                    ans = max(ans, aa + bb);
                }
            }
        }
        cout << ans << endl;
    }
}

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

typedef long long ll;

int main() {
    string S;
    cin >> S;
    if (S.back() != 's') cout << S << "s\n";
    else cout << S << "es\n";
}

Measured memory_bytes: 3628
import java.util.*;
import java.util.stream.IntStream;

public class Main {
  public static void main(String[] args) {
    @SuppressWarnings("resource")
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    List<Integer> list = new ArrayList<>();
    IntStream.range(0, N).forEachOrdered(n -> list.add(sc.nextInt()));
    list.sort(Comparator.naturalOrder());

    double value = list.get(0);
    for (int i = 0; i < N - 1; i++) {
      value = (value + list.get(i + 1)) / 2.0;
    }

    System.out.println(value);
  }
}

Measured memory_bytes: 27092
import java.util.*;
//import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		sc.close();
		StringBuilder ans = new StringBuilder();
		for(i=0;i<n.length();i++) {
			switch(n.charAt(i)) {
			case '1':
				ans.append("9");
				break;
			case '9':
				ans.append("1");
				break;
			default:
				ans.append(n.charAt(i));
				break;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21716
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline
n,m= map(int,input().split())
g = [[]for i in range(n)]
for i in range(m):
        a,b = map(int,input().split())
        a-=1;b-=1
        g[a].append(b)
        g[b].append(a)
kyo = [-1]*n
def dfs(x,y,z):
        for i in g[x]:
                if i == y: continue
                if kyo[i] == -1:
                        kyo[i] = (z+1)%2
                        dfs(i,x,z+1)
                else:
                        if kyo[i] !=  (z+1)%2:
                                print(n*(n-1)//2-m)
                                exit()
                
kyo[0] = 0
dfs(0,0,0)
ki = 0
gu = 0
for i in kyo:
        if i %2 == 0:
                gu += 1
        else:
                ki += 1
print(gu*ki-m)

Measured memory_bytes: 237148
from collections import Counter

N = int(input())
S = []
for _ in range(N):
    S.append(input())

cnt = Counter(S)

print("AC x " + str(cnt["AC"]))
print("WA x " + str(cnt["WA"]))
print("TLE x " + str(cnt["TLE"]))
print("RE x " + str(cnt["RE"]))

Measured memory_bytes: 16612
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

Int N;
Int dp[101][4][4][4];

int main(void) {
    cin>>N;
    enum {A,C,G,T};

    dp[0][3][3][3] = 1;
    for(int l = 0;l < N;l++) {
        for(int c1 = 0;c1 < 4;c1++) {
            for(int c2 = 0;c2 < 4;c2++) {
                for(int c3 = 0;c3 < 4;c3++) {
                    if(dp[l][c1][c2][c3] == 0) continue;
                    for(int c4 = 0;c4 < 4;c4++) {
                        if(c2 == A && c1 == G && c4 == C) continue;
                        if(c2 == A && c1 == C && c4 == G) continue;
                        if(c2 == G && c1 == A && c4 == C) continue;
                        if(c3 == A && c1 == G && c4 == C) continue;
                        if(c3 == A && c2 == G && c4 == C) continue;
                        dp[l+1][c4][c1][c2] += dp[l][c1][c2][c3];
                        dp[l+1][c4][c1][c2] %= MOD;
                    }
                }
            }
        }
    }

    int ans = 0;
    for(int c1 = 0;c1 < 4;c1++) {
        for(int c2 = 0;c2 < 4;c2++) {
            for(int c3 = 0;c3 < 4;c3++) {
                ans += dp[N][c1][c2][c3];
                ans %= MOD;
            }
        }
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
import sys

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

A, B = lr()

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

primes = prime_factorize(min(A, B))
answer = set()
for p in primes:
    if A % p == 0 and B % p == 0:
        answer.add(p)

print(len(answer) + 1) # 1をプラス
# 35

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  
  ll r=0;
  ll ans=0;
  ll sum=0;
  rep(l,n){
    while(r<n&&(a[r]+sum)==(a[r]^sum)){
      sum+=a[r];
      r++;
    }
    ans+=r-l;
    if(r==l)r++;
    else sum-=a[l];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
from sys import stdin, stdout

def print(x):
    stdout.write(str(x))

def solve():
    n = int(stdin.readline())
    x = n * 100 // 108
    if x * 108 // 100 == n: 
        print(x)
    elif (x+1) * 108 // 100 == n:
        print(x + 1)
    else:
        print(":(")

def main():
    solve()


if __name__ == "__main__":
    main()

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

int main()
{
    vector<vector<int>> c(3,vector<int>(3));
    for(int i = 0; i < 3; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            cin >> c.at(i).at(j);
        }
    }

    vector<int> a(3);
    vector<int> b(3);
    for(a.at(0) = 0; a.at(0) <= 100; a.at(0)++)
    {
        b.at(0) = c.at(0).at(0) - a.at(0);
        a.at(1) = c.at(1).at(0) - b.at(0);
        b.at(1) = c.at(1).at(1) - a.at(1);
        a.at(2) = c.at(2).at(1) - b.at(1);
        b.at(2) = c.at(2).at(2) - a.at(2);
        for(int i = 0; i < 3; i++)
        {
            for(int j = 0; j < 3; j++)
            {
                if(a.at(i)+b.at(j) != c.at(i).at(j))
                {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#define int long long
typedef vector<int>Vl;
typedef vector<vector<int>>Vn;
typedef pair<int,int>pii;
typedef vector<pii>Vll;
typedef vector<pair<int,pair<int,int> > >Vlll;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) cin>>n 
#define pl(n) cout<<n<<" "
const int Nx=1e6+2;
const int inf=(int)(1e19+10LL);
const int mod=1e9+7;
void solve(){
 string str;
 int k;
 sl(k);sl(str);
 int len=str.length();
 if(len<=k){
 	cout<<str<<endl;
 	return;
 }
 for(int i=0;i<k;i++){
 	cout<<str[i];
 }
cout<<"..."<<endl;
	
 
	
}

signed main(){
  int test=1;
  //sl(test);
  int t=0;
 while(t++<test){
 //	cout<<"Case #"<<t<<": ";
 	solve();
 }
 
}

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

namespace Programminng
{
    class AOJ_Volume0010
    {
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                double x1 = double.Parse(s[0]);
                double y1 = double.Parse(s[1]);
                double x2 = double.Parse(s[2]);
                double y2 = double.Parse(s[3]);
                double x3 = double.Parse(s[4]);
                double y3 = double.Parse(s[5]);
                
                double a1 = 2 * (x2 - x1);
                double b1 = 2 * (y2 - y1);
                double c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;

                double a2 = 2 * (x3 - x1);
                double b2 = 2 * (y3 - y1);
                double c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;

                double x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
                double y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);

                double r_2 = (x1 - x) * (x1 - x) + (y1 - y) * (y1 - y);
                double r = Math.Sqrt(r_2);

                Console.WriteLine("{0:F3} {1:F3} {2:F3}",x,y,r);
            }
        }
    }
}

Measured memory_bytes: 5732
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ppp pair<pii,pii>
#define pdd pair<double, double>
#define f first
#define s second
#define MOD 1000000007
#define mkp make_pair
#define FOR(i,l,r) for (int i=l;i<=r;i++)
#define LOR(i,l,r) for (ll i=l;i<=r;i++)
#define FORD(i,r,l) for (int i=r;i>=l;i--)
#define LORD(i,r,l) for (ll i=r;i>=l;i--)
#define CL(x) memset(x,0,sizeof(x))
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x.size())
#define UI(x) (int)(x-'A')
#define LI(x) (int)(x-'a')
#define DI(x) (int)(x-'0')
#define LL_MAX (1LL<<60)
#define DB 0
#define DBG(x) if(DB)cout << #x << " : " << x << '\n'
#define PRALL(v) if(DB)for(auto it : v)cout<<v<<' '; NL;
#define NL cout<<'\n';
#define FND(S,x) (S.find(x)!=S.end())
#define bit(x,y) (!!(x&(1<<y)))
typedef long long ll;
typedef long double ld;

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

    int A,B;
    cin>>A>>B;
    if( A*2<=B && B<=A*4 && B%2==0 )cout<<"Yes\n";
    else cout<<"No\n";

    return 0;
}


Measured memory_bytes: 3652
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

n = int(input())
nl = make_divisors(n)
nl_m = make_divisors(n-1)
l = sorted(list(set(nl + nl_m)))

ans = 0
for i in range(1, len(l)-1):
    p = n
    k = l[i]
    while p%k == 0:
        p = p // k
    if p%k == 1:
        ans += 1
print(ans+1)

Measured memory_bytes: 4084
package main

import (
	"fmt"
)

func solution(x int) int {
	var c, ans int
	c = x / 500
	ans = c * 1000
	x = x - 500*c
	c = x / 5
	return ans + c*5
}

func main() {
	var x int
	fmt.Scan(&x)
	fmt.Println(solution(x))
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string str;
  int count = 0;
  int max=0;
  cin >> str;
  if (str[0]=='R'&&str[1]=='R'&&str[2]=='R') count=3;
  else if (str[0]=='R'&&str[1]=='R' || str[1]=='R'&&str[2]=='R') count=2;
  else if (str[0]=='R'||str[1]=='R'||str[2]=='R') count=1;
  cout << count;
  return 0;
}

Measured memory_bytes: 3612
from string import ascii_lowercase
def lower_bound(al, key):
    """
    一般に左側が満たしておらず、右側は満たしている判定基準(境目は一つ)ならlower_boundになる
    (条件を満たすもののうち、最小のインデックスを返す)
    単調にさえなっていれば、左右が逆になっていても検索には使える(ng/okも一緒に逆にする必要がある)
    """
    def isOk(a):
        # alの中でkey以上のアイテムのうち最小のインデックスを返す
        # upper_boundにする時にはa>key
        return a>key

    ng = -1
    ok = len(al)

    while abs(ok-ng)>1:
        mid = (ok+ng)//2

        if isOk(al[mid]):
            ok = mid
        else:
            ng = mid

    return ok

s = input()
n = len(s)

d = {}
for c in ascii_lowercase:
    d[c] = []

for i in range(n):
    d[s[i]].append(i)

res = 1
for i in range(n):
    c = s[i]
    j = lower_bound(d[c],i)
    res += (n-i) - (len(d[c])-j) - 1
print(res)

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

int main() {
	int N,M,s;
	char c;
	cin >> N >> M;
	vector<char> t(N,'0');
	string r="";
	set<int> y;

	rep(i,M) {
		cin >> s >> c;
		if(y.count(s) && t.at(s-1)!=c) {
			cout << -1 << endl;
			return 0;
		}
		y.insert(s);
		t.at(s-1) = c;
	}

	rep(i,N)
		r += t.at(i);
	if(r.at(0)=='0') {
		if(N==1) {
			cout << 0 << endl;
			return 0;
		}
		
		if(y.count(1)) {
			cout << -1 << endl;
			return 0;
		} else {
			r.at(0) = '1';
		}
	}

	cout << r << endl;
}

Measured memory_bytes: 256
def Z_algo(S):
    L = len(S)
    lcp = [0]*L
    i = 1
    j = 0
    lcp[0] = L
    while i < L:
        while i+j < L and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        lcp[i] = j
        k = 1
        while i + k < L and k + lcp[k] < j:
            lcp[i+k] = lcp[k]
            k += 1
        i += k
        j -= k
    return lcp

def max2(x,y):
    return x if x > y else y

def min2(x,y):
    return x if x < y else y

res = 0
N = int(input())
S = input()
for i in range(N):
    lcp = Z_algo(S[i:])
    for j, s in enumerate(lcp):
        temp = min2(s, j)
        res = max2(res, temp)
print(res)

Measured memory_bytes: 79020
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F();
		var t = G();
		var v = G().ToList();
		var V = v.Max();
		// dp[n, v] = t[0]+...+t[n-1] を走り終えたときに速度が v/2 である場合の、そこまでの最大の走行距離 * 16
		// それが無理なら dp[n, v]=-1 とする
		// dp[n, v] >= 0 となる v はある区間をなす => 0 <= v <= M[n] とする
		// 答えは dp[N, 0] / 8
		var dp = new int[N + 1, 2 * V + 1];
		dp[0, 0] = 0;
		var M = new int[N + 1];
		for (var i = 1; i <= 2 * V; i++) dp[0, i] = -1;
		for (var n = 0; n < N; n++)
		{
			M[n + 1] = Min(M[n] + 2 * t[n], 2 * v[n]);
			for (var w = M[n + 1] + 1; w <= 2 * V; w++) dp[n, w] = -1;
			for (var w = 0; w <= M[n + 1]; w++)
			{
				for (var u = 0; u <= M[n]; u++)
				{
					if (u - 2 * t[n] > w || u + 2 * t[n] < w) continue;
					var au = 2 * v[n] - u;
					var bw = 2 * v[n] - w;
					var run = 0;
					if (au + bw <= 2 * t[n]) run = 2 * (8 * t[n] * v[n] - au * au - bw * bw);
					else
					{
						var x = 2 * t[n] + u + w;
						run = x * x - 2 * (u * u + w * w);
					}
					dp[n + 1, w] = Max(dp[n + 1, w], dp[n, u] + run);
				}
			}
		}
		WriteLine(dp[N, 0] / 16m);
	}
}


Measured memory_bytes: 13436
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    char a,b;
    cin>>a>>b;
    if(a>b){
        cout<<">"<<endl;
    }else if(a<b){
        cout<<"<"<<endl;
    }else{
        cout<<"="<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9+7;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

const int INF = 2000000000;
    
int solve(int x, int y, int f1, int f2) {
    if (f1) x = -x;
    if (f2 && -y < x) return INF;
    if (!f2 && y < x) return INF;
    
    if (f2) y = -y;
    return f1 + f2 + (y - x);
}

int main() {
    int x, y;
    cin >> x >> y;
    int ans = INF;
    rep(i, 2) rep(j, 2) chmin(ans, solve(x, y, i, j));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
  char s[10]={0};
  scanf("%s",s);
  if	 ( strcmp(s,"Sunny" )==0 ){ printf("Cloudy\n"); }
  else if( strcmp(s,"Cloudy")==0 ){ printf("Rainy\n");  }
  else							  { printf("Sunny\n");  }
  return 0;
}

Measured memory_bytes: 1584
#include<iostream>
using namespace std;
int main(void){
  char c[2][3];
  for(int i(1);i<=2;i++){
    for(int j(1);j<=3;j++){
      cin>>c[i][j];
    }
  }
  int f(0),g(0),h(0);
  if(c[1][1]==c[2][3])f=1;
  if(c[1][2]==c[2][2])g=1;
  if(c[1][3]==c[2][1])h=1;
  if(f==1 && g==1 && h==1)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 256
//#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cstring>
#include <cassert>

using namespace std;

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(...) DBG2::print(#__VA_ARGS__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

class DisjointSet {
   int N;
   int ncomp;
   vector<int> par;
   vector<int> sz;

public:
   DisjointSet(size_t _N) : N(_N), ncomp(_N), par(_N, -1), sz(_N, 1) {}
   int num_comp() const {
      return ncomp;
   }
   int size(int u) {
      return sz[ find_rep(u) ];
   }
   int find_rep(int u) {
      return par[u] < 0 ? u : par[u] = find_rep(par[u]);
   }
   bool union_rep(int u, int v) {
      int u_root = find_rep(u);
      int v_root = find_rep(v);
      if (u_root == v_root)
         return false;
      if (sz[u_root] < sz[v_root])
         swap(u_root, v_root);
      par[v_root] = u_root;
      sz[u_root] += sz[v_root];
      --ncomp;
      return true;
   }
};


int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   int N, M;
   cin >> N >> M;

   DisjointSet dset(N);

   REP(j, M) {
      int u, v;
      cin >> u >> v;
      --u, --v;
      dset.union_rep(u, v);
   }

   int res = 0;
   REP(u, N) {
      res = max(res, dset.size(u));
   }

   cout << res << endl;

   return 0;
}


Measured memory_bytes: 4796
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _h cout<<"here"<<endl;
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i,n) for(int i=0;i<n;i+=1)
#define prarr(a,n) rep(i,n) cout<<a[i]<<" \n"[i==n-1];// printf("%s\n"," " );
#define ff first
#define ss second
#define pu push_back
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T> 
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.ff<<", "<<p.ss<<')';return out;}
template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}
template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
const int inf = 1e9+10;
const ll INF = 1e18+10;
const int MOD = 1e9+7;
const int MAXN = 2e5+10;
int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
void solve()
{
	int n;
	cin>>n;
	cout<<a[n-1]<<endl;
}
int main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin>>t;
	while(t--){
		solve();
	}
	return 0;

}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int inf = 2e17;
const int mod = 1e9 + 7;

const int base = 8000;
const int baseTwo = base * 2 + 100;

signed main() {
    string s;
    int x, y;
    cin >> s >> x >> y;
    bitset<baseTwo> X, Y, tempRight, tempLeft;
    X.set(base);
    Y.set(base);
    bool check = true; // true = x, false = y
    bool change = false;
    int count = 0;
    for (auto one : s) {
        if (one == 'F') {
            if (check) {
                if (count == 0) {
                    tempRight = X;
                    if (change) tempLeft = X;
                }
            } else {
                if (count == 0) {
                    tempRight = Y;
                    tempLeft = Y;
                }
            }
            tempRight <<= 1;
            if (change) tempLeft >>= 1;
            ++count;
        } else {
            if (count != 0) {
                if (check) X = tempRight | tempLeft;
                else Y = tempRight | tempLeft;
            }
            count = 0;
            check = !check;
            change = true;
        }
    }
    if (count != 0) {
        if (check) X = tempRight | tempLeft;
        else Y = tempRight | tempLeft;
    }
    bitset<baseTwo> ansX, ansY;
    ansX.set(base); ansY.set(base);
    if (x < 0) ansX = (ansX>>abs(x));
    else ansX = (ansX<<x);
    if (y < 0) ansY = (ansY>>abs(y));
    else ansY = (ansY<<y);
    if ((X & ansX) == ansX && (Y & ansY) == ansY) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    // cout << X << endl << ansX << endl << Y << endl << ansY << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    A=list(map(int,input().split()))
    print(N+(len(set(A))-N)//2*2)

if __name__ == '__main__':
    main()


Measured memory_bytes: 56172
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
   vector<int> v;
   int q;
   cin >> q;
   for(int i = 0; i < q; i++){
	  int x;
	  cin >> x;
	  if (x == 0){
		  int y;
		  cin >> y;
		  v.push_back(y);  
		}
	  if (x == 1){
		  int y;
		  cin >> y;
		  cout << v[y] << endl; 
		 }
      if (x == 2) v.pop_back();
	}
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



Measured memory_bytes: 5016
//============================================================================
// Name        : hoba.cpp :)
// Author      : (O_O Diab) (Why_not) (el 3AQ)
// Version     :
// Copyright   : please, Don't touch me :(
// Description : problem in C++
// MAIN IDEA   : combinatorics NCR
//============================================================================
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define rw freopen("graphs_as_a_service.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define rep(i,a) lp(i,0,a-1)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace __gnu_pbds;
using namespace std;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int N = 1e5 + 3, mod = (int) 1e9 + 7, INF = 0x3f3f3f3f;
vi v[N], dq;
int a[N];
bool vis[N] = { }, vis2[N] = { };
inline void dfs(int node) {
	vis[node] = true;
	for (auto u : v[node]) {
		if (vis[u])
			continue;
		dfs(u);
	}
	dq.pb(node);
	vis2[a[node]] = true;
}
int main() {
#ifdef ONLINE_JUDGE
	FAST
#endif
	int n, m;
	cin >> n >> m;
	lp(i,1,n)
		cin >> a[i];
	while (m--) {
		int x, y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
	}
	int ans = 0;
	lp(i,1,n)
	{
		if (vis[i])
			continue;
		dq.clear();
		dfs(i);
		for (auto u : dq) {
			if (vis2[u])
				ans++;
		}
		for (auto u : dq)
			vis2[a[u]] = false;
	}
	f(ans);
	return 0;
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    int a;
    string s;
    cin >> a;
    cin >> s;
    if(a>=3200){
        cout << s << endl;
    }else{
        cout << "red" << endl;
    }


    return 0;

}


Measured memory_bytes: 256
import sys
import numpy as np
import scipy.sparse as ss
f=ss.csgraph.floyd_warshall
def main():
  t=np.fromstring(sys.stdin.buffer.read(),int,sep=' ')
  n,m,l=t[:3]
  m=m*3+3
  d=f(f(ss.csr_matrix((t[5:m:3],(t[3:m:3],t[4:m:3])),[n+1]*2),0)<=l)[t[m+1::2],t[m+2::2]]
  d[d>n]=0
  print('\n'.join((d.astype(int)-1).astype(str).tolist()))
main()

Measured memory_bytes: 30980
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  if (min(a, b)<c && c<max(a, b)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
int main(){
  int A,B,M;
  cin >> A >> B >> M;
  int min_a=100000,min_b=100000,fin=1000000;
  int a[A],b[B];
  rep(i,A){
    int tmpa;
    cin >> tmpa;
    a[i]=tmpa;
    if (tmpa<min_a){
      min_a=tmpa;
    }
  }
  rep(i,B){
    int tmpb;
    cin >> tmpb;
    b[i]=tmpb;
    if (tmpb<min_b){
      min_b=tmpb;
    }
  }
  fin=min_a+min_b;
  rep(i,M){
    int c,u,s;
    cin >> u >> s >> c;
    if (a[u-1]+b[s-1]-c<fin){
      fin=a[u-1]+b[s-1]-c;
    }
  }
  cout << fin << endl;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const ll MAX = 10000;
static const ll INFTY = 1e12;
static const ll MOD = 1e9+7;

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



int main() {

  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  ll n1 = a*c;
  ll n2 = a*d;
  ll n3 = b*c;
  ll n4 = b*d;

  cout << max(n1, max(n2, max(n3, n4))) << endl;


 


}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define en "\n"
#define ITER(i,a) for( typeof(a.begin()) i=a.begin();i!=a.end();i++)
#define mod 1000000007
#define mpp make_pair
#define mes(a,b) memset((a),(b),sizeof((a))
typedef map<int,int> MI;
typedef pair<int,int>   PI;
typedef vector<int> VI;
typedef long long int LL;

int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k,x,y;
    cin>>n>>k>>x>>y;
    if(n<k)
    k=n;
    long long int ans=0;
    ans=ans+(k*x);
    n=n-k;
    if(n>0)
    ans=ans+(n*y);
    cout<<ans;
	return 0;
}

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

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = copy(x);cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

constexpr lli MOD = (lli)1e9 + 7;
constexpr lli LIMIT = 1000000000000000000 * 5;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	while (true) {
		c -= b;
		if (c <= 0) {
			cout << "Yes" << endl;
			return 0;
		}
		a -= d;
		if (a <= 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	return 0;
}



Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;


int main()
{
	string s,t;
	cin >> s >> t;
	int cnt;
	for(int i=0;i<3;i++){
		if(s[i]==t[i]) cnt++;
	}
	cout << cnt;
	return 0;
}

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

int main() {
	int N, a, b, c, d;
	cin >> N;
  a = N/1000;
  b = (N - a * 1000)/100;
  c = (N - a * 1000 - b * 100)/10;
  d = N -a * 1000 - b * 100 - c * 10;
  if (a == b && b == c){  
	cout << "Yes" << endl;
  }
  else if (c == d && b == c){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

bool b[100001];
pair<int, int> a[100000];

int main()
{
	int n, k;
	while (scanf("%d %d", &n, &k), n + k){
		memset(b, 0, sizeof(b));
		memset(a, 0, sizeof(a));
		
		int w = 0;
		for (int i = 0; i < k; i++){
			int a;
			scanf("%d", &a);
			if (a) b[a] = true;
			else w++;
		}
		
		int m = 0;
		int dif = 0;
		for (int i = 1; i <= n; i++){
			if (b[i]){
				a[m].first++;
				if (m > 0) a[m].second = max(a[m].second, dif);
				dif = 0;
			}
			else {
				dif++;
				if (m > 0 || a[m].first) m++;
			}
		}
		m++;
		
		//for (int i = 0; i < m; i++){
		//	printf("%d %d\n", a[i].first, a[i].second);
		//}
		
		int l = 0, r = 0, s = a[0].first, x = 0;
		int maxi = 0;
		while (r < m){
			//printf("%d %d %d %d\n", l, r, s, x);
			
			if (x > w){
				x -= a[l + 1].second;
				s -= a[l].first;
				l++;
			}
			else {
				maxi = max(maxi, s + w);
				
				r++;
				x += a[r].second;
				s += a[r].first;
			}
		}
		
		printf("%d\n", maxi);
	}
	
	return 0;
}

Measured memory_bytes: 2076
import heapq
import math
from itertools import combinations


class UnionFind:
    from collections import deque

    def __init__(self, v):
        self.v = v
        self._tree = list(range(v + 1))

    def _root(self, a):
        queue = self.deque()
        while self._tree[a] != a:
            queue.append(a)
            a = self._tree[a]
        while queue:
            index = queue.popleft()
            self._tree[index] = a
        return a

    def union(self, a, b):
        root_a = self._root(a)
        root_b = self._root(b)
        self._tree[root_b] = root_a

    def find(self, a, b):
        return self._root(a) == self._root(b)


while True:
    N = int(input())

    if N == 0:
        break

    V = [tuple(map(float, input().split(' '))) for _ in range(N)]
    E = []
    for i, j in combinations(range(N), r=2):
        xi, yi, zi, ri = V[i]
        xj, yj, zj, rj = V[j]
        d = math.sqrt((xi - xj) ** 2 + (yi - yj) ** 2 + (zi - zj) ** 2)
        c = max(0.0, d - ri - rj)
        heapq.heappush(E, (c, i, j))

    uf = UnionFind(N)
    cost = 0.0
    while E:
        c, i, j = heapq.heappop(E)
        if not uf.find(i, j):
            uf.union(i, j)
            cost += c

    print('{:.3f}'.format(cost))



Measured memory_bytes: 6632
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
using namespace std;

int S[1000000];
bool b_search(const int size, const int key) {
  int left = 0; int right = size;

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

int main() {
  int n;
  cin >> n;
  for(int i=0; i < n; i++) {
    cin >> S[i];
  }
  int q; cin >> q;
  int T[1000000];
  for(int i=0; i<q; i++) {
    cin >> T[i];
  }

  int cnt = 0;
  for(int i=0; i<q; i++) {
    if(b_search(n, T[i])) {
      cnt++;
    }
  }

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



Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
typedef unsigned long long ull; 
typedef unsigned int uint; 
typedef long double ld;

void solve();

void solve()
{
    int n;
    cin >> n;
    ll t;
    ld ans = 1;
    ll limit = 1000000000000000000;
    for (int i = 0; i < n; i++)
    {
        cin >> t;
        if(ans != -1)
            ans *= t;
        if (ans > limit || ans < 0)
            ans = -1;
        if (t == 0)
            ans = 0;
    }
    cout << (ll)ans;
    return;
}
int main()
{
    solve();
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    ll h, w;
    cin >> h >> w;
    if (h == 1 || w == 1) {
        cout << 1 << endl;
    } else {
        cout << (h * w + 1) / 2 << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int n;
    cin >> n;
    vector<pii> x(n);
    forn(i, n) {
        cin >> x[i].fi;
        --x[i].fi;
        x[i].se = i;
    }
    sort(all(x));
    vi ans(n * n, -1);
    vi lft(n, n);
    bool ok = true;
    for (auto w: x) {
        int b = w.se;
        forn(i, w.fi) {
            if (b && ans[i] == -1) {
                ans[i] = w.se;
                --b;
                --lft[w.se];
            }
        }
        if (b) {
            ok = false;
            break;
        }
        ans[w.fi] = w.se;
        --lft[w.se];
    }
    reverse(all(x));
    for (auto w: x) {
        int b = n - w.se - 1;
        ford(i, n * n) {
            if (i <= w.fi) break;
            if (b && ans[i] == -1) {
                ans[i] = w.se;
                --b;
                --lft[w.se];
            }
        }
        if (b) {
            ok = false;
            break;
        }
    }
    if (!ok) {
        cout << "No\n";
    } else {
        cout << "Yes\n";

        int j = 0;
        forn(i, n * n) {
            if (ans[i] == -1) {
                while (!lft[j]) ++j;
                ans[i] = j;
                --lft[j];
            }
        }
        for (int x: ans) cout << x + 1 << ' ';
        cout << '\n';
    }

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
template<typename T>void read(T &x){
	char c=getchar();x=0;int f=1;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}x*=f;
}
int a,b;
int main(){
	read(a);read(b);
	cout<<max(max(a+b,a-b),a*b)<<endl;
}

Measured memory_bytes: 256
/*
 *
 *    I am o0o0oo00.
 *
 */
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll          long long
#define p7          1000000007
#define p9          998244353
#define pb          push_back
#define ff          first
#define ss          second
#define vll         vector<ll>
#define pll         pair<ll,ll>
#define vpll        vector<pll>
#define mll         map<ll,ll>
#define test        ll T;cin>>T;while(T--)
#define ad(a,n)     vll a;a.resize(n);for(ll i=0;i<n;i++)cin>>a[i];
#define as(a,n)     for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<endl;
#define all(x)      x.begin(),x.end()

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll powm(ll x, ll y, ll m = p7) {
    x = x % m; ll res = 1; while (y)
    {if (y & 1)res = res * x; res %= m; y = y >> 1; x = x * x; x %= m;} return res;
}
ll modi(ll a, ll m = p7) {return powm(a, m - 2, m);}
void yesno(bool f) {f ? cout << "YES" << endl : cout << "NO" << endl;}


void ss99()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}


int32_t main()
{
//    ss99();
//    test
    {
        ll n, wmx; cin >> n >> wmx;
        ll w[n + 1] = {0}, v[n + 1] = {0};
        for (ll i = 0; i < n; i++)
            cin >> w[i] >> v[i];
        ll dp[n + 1][wmx + 1];
        for (ll i = 0; i <= n; i++)
        {
            for (ll j = 0; j <= wmx; j++)
            {
                if (i == 0 || j == 0)
                    dp[i][j] = 0;
                else if (w[i - 1] <= j)
                    dp[i][j] = max(v[i - 1] + dp[i - 1][j - w[i - 1]] , dp[i - 1][j]);
                else
                    dp[i][j] = dp[i - 1][j];
            }
        }
        cout << dp[n][wmx] << endl;
    }
    return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

int n;
vector<ll>a,p;

ll solve(int n,ll x){
    if(x==0) return 0;
    if(n==0) return 1;
    if(a.at(n)/2+1<x){
        return p.at(n-1)+1+solve(n-1,x-a.at(n)/2-1);
    }
    else if(a.at(n)/2+1==x){
        return p.at(n-1)+1;
    }
    else{
        return solve(n-1,x-1);
    }
}

int main(){
    cin>>n;
    a.resize(n+1,1);
    p.resize(n+1,1);
    ll x;
    cin>>x;
    rep(i,1,n+1){
        a.at(i)=a.at(i-1)*2+3;
        p.at(i)=p.at(i-1)*2+1;
    }
    cout<<solve(n,x)<<endl;
return 0;
}

Measured memory_bytes: 256