akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
using namespace std;

int main() {
	string a;
	cin >> a;
	if (5 < a.size() && any_of(a.begin(), a.end(), [](char& a) { return isdigit(a); }) && any_of(a.begin(), a.end(), [](char& a) { return islower(a); }) && any_of(a.begin(), a.end(), [](char& a) { return isupper(a); })) cout << "VALID";
	else cout << "INVALID";
	cout << endl;
}


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

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

    return 0;
}

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

int main(){
  string S,c;
  cin >> S;
  int s=S.size();
  if(s%2==0){S=S.substr(0,S.size()-2);}
  else{S=S.substr(0,S.size()-1);}
  for(int i=0;i<110;i++){
    if(S.substr(0,S.size()/2)==S.substr(S.size()/2,S.size()/2)){
      cout << S.size() << endl;
      return 0;
    }
    else{S=S.substr(0,S.size()-2);}
  }
}

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

#define sd(a) scanf("%d",&a)
#define ss(a) scanf("%s",a)
#define sl(a) scanf("%lld",&a)
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ll long long

ll gcd(ll a,ll b)
{
	ll t;
	while(b!=0)
	{
		t=b;
		b=a%b;
		a=t;
	}
	return a;
}

int main()
{
	int n,a,i,maxx=0,GCD=0,k;
	sd(n);sd(k);
	for(i=0;i<n;i++)
	{
		sd(a);
		GCD=gcd(GCD,a);
		maxx=max(maxx,a);
	}
	if(k%GCD==0 && k<=maxx)
		printf("POSSIBLE\n");
	else
		printf("IMPOSSIBLE\n");
}

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

int main() {
  ll mod = 998244353;

  int n;
  cin >> n;

  vector<int> d(n);
  vector<int> f(n, 0);
  rep(i,n){
    cin >> d[i];
    if((i==0)!=(d[i]==0)){
      cout<<0<<endl;
      return 0;
    }
    f[d[i]]++;
  }

  ll count = 1;
  rep_in(i,1,n){
    rep(k,f[i]){
      count = count*f[i-1]%mod;
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <fstream>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;


int main() {
    ll n;
    cin >> n;
    ll m;
    cin >> m;
    vector<pair<ll,ll>> x(m);
    vector<vector<ll>> z(n);
    map<ll, vector<ll>> mp;
    for (int i = 0; i < n; i++) {
        ll f;
        cin >> f;
        mp[f].push_back(i);
    }
    for (int i = 0; i < m; i++) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        z[a].push_back(b);
        z[b].push_back(a);
        x[i] = make_pair(min(a, b), max(a, b));
    }
    vector<char> ans(n,'A');
    map<pair<ll, ll>, ll> anss;
    vector<bool> seen(n);
    ll l = 0;
    for (auto h : mp) {
        for (auto s : h.second) {
            seen[s] = true;
        }
        for (auto s : h.second) {
            ll fl = 1;
            if (ans[s] != 'A')continue;
            for (auto d : z[s]) {
                if (seen[d]) {
                    if (ans[d] == 'A')ans[d] = 'B';
                    if (ans[d] == 'B')ans[s] = 'W';
                    else ans[s] = 'B';
                    fl = 0;
                    anss[make_pair(min(s, d), max(s, d))] = h.first;
                    break;
                }
            }
            if (fl == 1)l = -1;
        }
    }
    if (l == -1)cout << l << endl;
    else {
        for (int i = 0; i < n; i++) {
            cout << ans[i];
        }
        cout << endl;
        for (int i = 0; i < m; i++) {
            if (anss.count(x[i])) {
                cout << anss[x[i]] << endl;
            }
            else {
                cout << 1000000000 << endl;
            }
        }
    }
}

Measured memory_bytes: 30808
@$_=$p[$_]=$_ for@N=1..<>;map{unshift@a,@N*$#N/2-$%;$%+=@$A*@$B,@$A>@$B&&($A^=$B^=$A^=$B),map{push@$B,$_;$p[$_]=$B}@$A if($B=$p[$'*/ /])-($A=$p[$`])}reverse<>;print"@a"

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

const int mod = 1'000'000'007;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for(int i = 0; i < n; i++)  cin >> v[i];
    vector<int> dp(k+1, 0);
    dp[0] = 1;
    for(int i = 0; i < n; i++){
        vector<int> ndp(k+1, 0);
        for(int j = 0; j <= k; j++){
            ndp[j] = (ndp[j] + dp[j])%mod;
            if(j+v[i]+1 <= k) ndp[j+v[i]+1] = (ndp[j+v[i]+1]-dp[j]+mod)%mod;
        }
        for(int j = 1; j <= k; j++) ndp[j] = (ndp[j]+ndp[j-1])%mod;
        dp = ndp;
    }
    cout << dp[k] << endl;
    return 0;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

func exec(stdin *Stdin, stdout *Stdout) {
	n := stdin.ReadInt()
	m := stdin.ReadInt()
	s := stdin.Read()

	a := []int{}
	for i := 0; i < n+1; i++ {
		if s[i] == '0' {
			a = append(a, i)
		}
	}

	b := make([]int, n+1)
	for i := n; i >= 0; i-- {
		j := sort.Search(len(a), func(x int) bool {
			return a[x] >= i-m
		})
		b[i] = a[j]
	}

	c := []int{}
	x := n
	for x > 0 {
		if x == b[x] {
			stdout.Println(-1)
			return
		}
		c = append(c, x-b[x])
		x = b[x]
	}

	d := []string{}
	for i := len(c) - 1; i >= 0; i-- {
		d = append(d, strconv.Itoa(c[i]))
	}
	stdout.Println(strings.Join(d, " "))
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}


Measured memory_bytes: 8576
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

bool comp(pair<int, int> p1, pair<int, int> p2) {
    return p1.second < p2.second;
}

int main() {
    int N, M; cin >> N >> M;
    vector<pair<int, int>> v;

    for(int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b;
        v.push_back(make_pair(a, b));
    }

    sort(v.begin(), v.end(), comp);

    int current = 0;
    int c = 0;
    for(auto itr = v.begin(); itr != v.end(); ++itr) {
        if(current < itr->first) {
            current = itr->second-1;
            ++c;
        }
    }

    cout << c << endl;
}


Measured memory_bytes: 1400
def solve(A, B, C, D, E, F):
    sugers = set()
    for i in range(0, F // C + 1):
        for j in range(0, F // D + 1):
            s = (C * i + D * j)
            if s + 100 * s / E <= F:
                sugers.add(C * i + D * j)
            else:
                break
    sugers = sorted(list(sugers))

    waters = set()
    for i in range(0, F // A + 1):
        for j in range(0, F // B + 1):
            if (A * i + B * j) * 100 <= F:
                waters.add(A * i + B * j)
            else:
                break
    waters = sorted(list(waters))

    dense, w_all, w_suger = 0, A * 100, 0
    for s in sugers:
        for w in waters:
            if s + 100 * w <= F and s <= w * E and w + s > 0:
                densei = 100 * s / (100 * w + s)
                if dense < densei:
                    dense = densei
                    w_all = s + 100 * w
                    w_suger = s
                    break
    return " ".join([str(w_all), str(w_suger)])


if __name__ == "__main__":
    A, B, C, D, E, F = map(int, input().split(" "))
    print(solve(A, B, C, D, E, F))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
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; }

long long n, m, q;
vector<long long> a(55, 0);
vector<long long> b(55, 0);
vector<long long> c(55, 0);
vector<long long> d(55, 0);

int main() {
    cin >> n >> m >> q;
    for(int i = 0;  i < q; ++i) {
        cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
        a.at(i)--; b.at(i)--;
    }

    long long mans = 0;
    for(int e = 1; e <= m; ++e) {
        for(int f = e; f <= m; ++f) {
            for(int g = f; g <= m; ++g) {
                for(int h = g; h <= m; ++h) {
                    for(int i = h; i <= m; ++i) {
                        for(int j = i; j <= m; ++j) {
                            for(int k = j; k <= m; ++k) {
                                for(int l = k; l <= m; ++l) {
                                    for(int o = l; o <= m; ++o) {
                                        for(int p = o; p <= m; ++p) {
                                            int A[10];
                                            A[0] = e;
                                            A[1] = f;
                                            A[2] = g;
                                            A[3] = h;
                                            A[4] = i;
                                            A[5] = j;
                                            A[6] = k;
                                            A[7] = l;
                                            A[8] = o;
                                            A[9] = p;
                                            long long ans = 0;
                                            
                                            for(int r = 0; r < q; ++r) {
                                                if(A[b.at(r)] - A[a.at(r)] == c.at(r)) ans += d.at(r);
                                            }
                                            chmax(mans, ans);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    cout << mans << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>

using namespace std;
int sum[2001][2001], ngang[2001][2001], doc[2001][2001], x1, y1, x2, y2, n, m, q, i, j;
char a[2001][2001];

void Init()
{
    cin >> n >> m >> q;
    for (i = 1; i <= n; i++)
        for (j = 1; j <= m; j++)
        {
            cin >> a[i][j];
            sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + (a[i][j] - '0');
            ngang[i][j] = ngang[i - 1][j] + ngang[i][j - 1] - ngang[i - 1][j - 1];
            if (a[i][j] - '0' == 1 && a[i][j - 1] - '0' == 1) ngang[i][j]++;
            doc[i][j]   = doc[i - 1][j]   + doc[i][j - 1]   - doc[i - 1][j - 1];
            if (a[i][j] - '0' == 1 && a[i - 1][j] - '0' == 1) doc[i][j]++;
        }
    /*for (i = 1; i <= n; i++)
    {
        for (j = 1; j <= m; j++) cout << ngang[i][j] << " ";
        cout << endl;
    }
    cout << endl;
    for (i = 1; i <= n; i++)
    {
        for (j = 1; j <= m; j++) cout << doc[i][j] << " ";
        cout << endl;
    }*/
}

void Solve()
{
    //while (q--)
    for (i = 1; i <= q; i++)
    {
        cin >> x1 >> y1 >> x2 >> y2;
        int u = ngang[x2][y2] - ngang[x1 - 1][y2] - ngang[x2][y1] + ngang[x1 - 1][y1];
        int v = doc[x2][y2] - doc[x1][y2] - doc[x2][y1 - 1] + doc[x1][y1 - 1];
        int r = sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];
        cout << r - u - v << '\n';
        //cout << r << " " << u << " " << v << " " << endl;
    }
}

int main()
{
    //freopen("A.inp", "r", stdin);
    //freopen("B.out", "w", stdout);
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);

    Init();
    Solve();
}


Measured memory_bytes: 52608
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

n=int(input())
for i in range(1,10):
    for j in range(1,10):
        if n==i*j:
            print('Yes')
            exit()

print('No')

Measured memory_bytes: 3060
from sys import stdin as I
N = int(I.readline())
H = [[None,None,None]] + [list(map(int,I.readline().split())) for i in range(N)]
DP = H[1]
for i in range(2,N+1):DP = [max(DP[1],DP[2])+H[i][0],max(DP[0],DP[2])+H[i][1],max(DP[0],DP[1])+H[i][2]]
print(max(DP))

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

#define Online 1
// #define multitest 1
#define Debug 1
typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
#define mp make_pair
const long long mod = 1000000007;
const long long High = 1e16;
void ControlIO();
void TimerStart();
void TimerStop();
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

void solve()
{
    int n;
    cin >> n;
    vector<int> A(n),B(n);
    ll sum = 0,maxi = High,p = 0;;
    for(int i=0;i<n;++i)
    {
        cin >> A[i];
        if(A[i]<0) p++;
        maxi = min(maxi,(ll)abs(A[i]));
        sum += abs(A[i]);
    }
    if(p&1) cout << sum - 2*maxi;
    else cout << sum;
}

int main()
{
	ControlIO();
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	TimerStart();
	while (t--)
		solve();
	TimerStop();
	return 0;
}

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

auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();

void TimerStart()
{
#ifndef Online
	TimeStart = chrono::steady_clock::now();
#endif
}

void TimerStop()
{
#ifndef Online
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
#endif
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<algorithm>
int main()
{
	int h,w,i,j,m[64][64]={0};
	char a[64][64];
	scanf("%d%d",&h,&w);
	for(i=0;i<h;++i)scanf("%s",a[i]);
	m[0][0]=a[0][0]-'0';
	for(i=1;i<w;++i)m[0][i]=m[0][i-1]+a[0][i]-'0';
	for(i=1;i<h;++i)m[i][0]=m[i-1][0]+a[i][0]-'0';
	for(i=1;i<h;++i)for(j=1;j<w;++j)m[i][j]=std::min(m[i-1][j],m[i][j-1])+a[i][j]-'0';
	printf("%d\n",m[h-1][w-1]);
	return 0;
}

Measured memory_bytes: 0
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        x: i64, a: i64, b: i64
    }

    println!("{}", if b - a <= 0 {"delicious"} else if b - a <= x {"safe"} else {"dangerous"});
}


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

int main(){

long long  a,b,k,tem;
cin>> a>> b >>k;
if(k<=a)cout << a-k << " " << b << endl;
else if(k<=a+b)cout << 0 << " " << b+a-k << endl;
else cout << 0 << " " << 0<< endl;
}




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

int main() {
	ll N, M, d;
	cin >> N >> M >> d;
	int x = N / d;
	int y = M / d;
	if (N % d == 0)
		cout << y - x + 1 << endl;
	else
		cout << y - x << endl;
}

Measured memory_bytes: 3544
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int maxn = 2e5 + 5;

int n;
pii towns[maxn];

vector<int> vx, vy;

vector<pair<int, pii>> edges;

int lab[maxn];

void read_input()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
    {
        int x, y;
        cin >> x >> y;
        towns[i] = pii(x, y);
        vx.push_back(x);
        vy.push_back(y);
    }
}

int find_set(int u)
{
    return lab[u] < 0 ? u : lab[u] = find_set(lab[u]);
}

void union_sets(int u, int v)
{
    u = find_set(u); v = find_set(v);
    if(u == v) return;
    if(lab[u] < lab[v]) swap(u, v);
    lab[v] += lab[u];
    lab[u] = v;
}

void init()
{
    sort(vx.begin(), vx.end());
    sort(vy.begin(), vy.end());
    vx.erase(unique(vx.begin(), vx.end()), vx.end());
    vy.erase(unique(vy.begin(), vy.end()), vy.end());

    fill(begin(lab), end(lab), -1);

    for(int i = 1; i <= n; ++i)
    {
        int u = lower_bound(vx.begin(), vx.end(), towns[i].fi) - vx.begin();
        int v = lower_bound(vy.begin(), vy.end(), towns[i].se) - vy.begin() + sz(vx);
        union_sets(u, v);
    }

    for(int i = 1; i < sz(vx); ++i)
    {
        int cost = vx[i] - vx[i - 1];
        edges.push_back(make_pair(cost, pii(i - 1, i)));
    }

    for(int i = 1; i < sz(vy); ++i)
    {
        int cost = vy[i] - vy[i - 1];
        edges.push_back(make_pair(cost, pii(i - 1 + sz(vx), i + sz(vx))));
    }

    sort(edges.begin(), edges.end());
}

void solve()
{
    lli ans = 0;
    for(auto&e: edges)
    {
        int cost = e.fi;
        int u = e.se.fi, v = e.se.se;
        u = find_set(u); v = find_set(v);
        if(u != v)
        {
            ans += cost;
            union_sets(u, v);
        }
    }
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    init();
    solve();
}



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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> A_tmp(N);
    for(int i = 0; i < N; ++i) cin >> A[i];
    A_tmp = A;

    sort(A_tmp.begin(), A_tmp.end());
    int first = A_tmp[N - 1];
    int second = A_tmp[N - 2];

    for(int i = 0; i < N; ++i) {
        if(A[i] == first) {
            cout << second << endl;
        } else {
            cout << first << endl;
        }
    }
}


Measured memory_bytes: 3200
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		// ?????????
		final char[] mark = {'S','H','C','D'};
		String[][] cards = new String[4][13];

		try {
			// ????????????????????°?????\???
			int cardNum = Integer.parseInt(br.readLine());

			// ????????????????????\???
			String str;
			for(int i=0;i<cardNum;i++){
				str = br.readLine();
				for(int j=0;j<mark.length;j++){
					if(str.charAt(0) == mark[j]){
						// ??°???????????£?????????????????????
						cards[j][Integer.parseInt(str.substring(2,str.length()))-1] = "";
						break;
					}
				}
			}

			// ?????£?????????????????????????????\
			StringBuilder sb = new StringBuilder();
			for(int i=0;i<mark.length;i++){
				for(int j=0;j<cards[i].length;j++){
					if(cards[i][j] == null)
						sb.append(mark[i]).append(" ").append((j+1)).append("\n");
				}
			}

			// ??????
			System.out.print(sb.toString());

		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			try{
				if(br != null){
					br.close();
				}
			}catch(IOException ioe){
			}

		}
	}
}

Measured memory_bytes: 17028
import itertools
import sys
import numpy as np

N, M, X = map(int, input().split())
C = []
for n in range(N):
    C.append(list(map(int, input().split())))

result = []
for n in range(2 ** N):
    ii = [0] * N
    for i in range(N):
        if (n >> i) & 1:
            ii[i] = 1
    # print(ii)
    tmp = [0] * (M + 1)
    for j in range(len(ii)):
        if ii[j] == 1:
            tmp = (np.array(tmp) + np.array(C[j])).tolist()
    result.append(tmp)


def ex(array):
    for i in array[1:]:
        if i < X:
            return False
    return True


min_value = sys.maxsize
result.sort()
for r in result:
    if ex(r):
        print(r[0])
        exit()

print(-1)


Measured memory_bytes: 28660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
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 int INF = 1<<30;
const ll LINF = 1LL<<58;
const ll mod = 1000000007;

int main(){
    int n;
    string s[2];
    cin >> n >> s[0] >> s[1];
    ll ans = 1;
    int i = 0, cnt;
    bool t = false, p, start = true;
    while(i < n){
        p = t;
        if(s[0][i] == s[1][i]) {
            t = true;
            i++;
        }
        else {
            t = false;
            i += 2;
        }
        if(start){
            start = false;
            if(t) cnt = 3;
            else cnt = 6;
            ans = ans * cnt % mod;
            continue;
        }
        if(t && p) cnt = 2;
        else if(t && !p) cnt = 1;
        else if(!t && p) cnt = 2;
        else cnt = 3;
        ans = ans * cnt % mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
N, K = map(int, input().split())
a = np.array(list(map(int, input().split())))
ans = 0
for i in range(50, -1, -1):
    s = np.sum((a >> i) & 1)
    if N - s > s:
        ans += 2 ** i
    if ans > K:
        ans -= 2 ** i
print(np.sum(ans ^ a))

Measured memory_bytes: 23688
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

int main(void){
    int H,W;
    scanf("%d%d",&H,&W);

    char map[H][W+1];
    for(int i=0;i<H;i++) scanf("%s",map[i]);

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            int flg=0;
            if(map[i][j]=='#'){
                if(i>0 && map[i-1][j]=='#') flg=1;
                if(i<H-1 && map[i+1][j]=='#') flg=1;
                if(j>0 && map[i][j-1]=='#') flg=1;
                if(j<W-1 && map[i][j+1]=='#') flg=1;
                if(!flg){
                    printf("No\n");
                    return 0;
                }
            }
        }
    }
    
    printf("Yes\n");

    return 0;
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static final int MOD = 1_000_000_007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt();
        int[] a = new int[n], b = new int[m];
        for (int i = 0; i < n; i++) a[i] = sc.nextInt();
        for (int i = 0; i < m; i++) b[i] = sc.nextInt();
        Arrays.sort(a);
        Arrays.sort(b);

        int mFoundIndex = 0, nFoundIndex = 0;
        long sum = 1;
        int num = n * m;
        while (num > 0) {
            int aResult = Arrays.binarySearch(a, num);
            int bResult = Arrays.binarySearch(b, num);
            if(aResult >= 0 && bResult >= 0) {
                mFoundIndex++;
                nFoundIndex++;
            } else if(aResult >= 0) {
                sum *= mFoundIndex;
                nFoundIndex++;
            } else if(bResult >= 0) {
                sum *= nFoundIndex;
                mFoundIndex++;
            } else {
                sum *= (nFoundIndex * mFoundIndex - (n * m - num));
            }
            num--;
            sum %= MOD;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 27264
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */
#define mt make_tuple
#define ll long long
#define ld long double
#define eb emplace_back
#define fi first
#define pb push_back
//#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define scanVec(vec) for(int i = 0; i < SZ(vec) ; i++){ cin >> vec[i];}
#define printVec(vec) for(int i = 0; i < SZ(vec) ; i++){ cout<<vec[i]<<" ";}
#define mod(a,b) ((a%b +b)%b)
#define bit(x,i) (x&(1<<i))  //select the bit of position i of x
#define lowbit(x) ((x)&((x)^((x)-1))) //get the lowest bit of x
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) //get the highest bit of x, maybe the fastest
//#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define lastEle(vec) vec[vec.size()-1] 
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) 
#define ll long long 
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define INF 1001001001
//#define PI 3.1415926535897932384626
 
using namespace std;
 using namespace __gnu_pbds;
 template <typename T>
 using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
 
/*
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
 */
//----------------------------------------------------------------------------------------------------------------------
 
void swap(int & a, int & b){
    auto temp = a;
    a = b;
    b = temp;
}
 
const ll MOD = 1e9 + 7;
 
ll inf = 1LL*1e17;
 
void no(){
    cout <<"No" << endl;
   //exit(0);
}
 
void yes(){
    cout <<"Yes" << endl; //exit(0);
}
 
const ll md = 998244353;


void sl(){
	string s;
	cin >> s;
	if(s == "BBB" || s == "AAA") no();
	else yes();	
	
}
 
 
int main(){
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int ts = 0;
    if(ts == 1) cin >> ts;
    else ts = 1;
    while(ts--) sl(); 
    return 0;
} 


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  sort(s.begin(),s.end());
  if ((s[0] == s[1] && s[2] == s[3]) && s[0] != s[2]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x=nxt(),a=nxt(),b=nxt();
    if(b-a<=0)
        cout<<"delicious\n";
    else if(b-a<=x)
        cout<<"safe\n";
    else 
        cout<<"dangerous\n";
    
    return 0;   
}




 
 


Measured memory_bytes: 256
N = 50000
t = [1]*(N)
p = [2]
d = {2:1}
for i in range(3, N, 2):
    if t[i]:
        p.append(i)
        d[i] = 1
        for j in range(3*i, N, 2*i): t[j] = 0

while True:
    n = int(input())
    if n == 0: break

    count = 0
    if n % 2:
        if n - 2 in p: count += 1
    else:
        for p1 in p:
            if 2*p1 > n: break
            if n - p1 in d:
                count += 1
    print(count)

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

int main() {
    //    int myints[3][100000]={};
    vector<int> g1;
    int ints=0;
    cin>>ints;
    int value;
    for (int i=0;i<=ints-1;i++){
        cin>>value;
        g1.push_back(value);
        g1.push_back(value+1);
        g1.push_back(value-1);
    }
    
    map< int, int> dup;
    
    for_each( g1.begin(), g1.end(), [&dup]( int val ){ dup[val]++; } );
    
    long int c=0;
    for( auto p : dup ) {
        if (p.second>c){
            c=p.second;
        }
    }
    cout<<c;
}



Measured memory_bytes: 5872
#include <stdio.h>

int main(void)
{
	int N, M, i;
	scanf("%d%d", &N, &M);
	if (N == 1) printf("%d", M);
	else if (M == 1) puts("1");
	else {
		for (i = 2; i <= M / 2; ++i) {
			if (M % i == 0 && N <= i) break;
		}
		if (i == M / 2 + 1) puts("1");
		else printf("%d", M / i);
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
int main(){
	int n;
	while(~scanf("%d", &n)) {
		int flag = 0;
		int p = (int)sqrt(n);
		if(p == sqrt(n)) flag = 1;
		if(flag == 1) printf("%d\n", n);
		else {
			for(int i = n; i > 0; i--) {
				int q = (int)sqrt(i);
				if(q == sqrt(i)) {
					printf("%d\n", i);
					break;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n, k = mi()
    member = set()
    for _ in range(k):
        d = ii()
        L = lmi_0()
        for person in L:
            member.add(person)
    cnt = 0
    for i in range(n):
        if i not in member:
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9240
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e3+5;

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    list<int> L[maxn];
    int n,q;
    cin>>n>>q;
    while(q--){
        int op;
        cin>>op;
        if(op==0){
            int t,x;cin>>t>>x;
            L[t].push_back(x);
        }else{
            if(op==1){
                int t;cin>>t;
                int cnt=1;
                int len=L[t].size();
                for(auto it=L[t].begin();it!=L[t].end();it++)cout<<*it<<(cnt++==len?'\n':' ');
                if(L[t].empty())cout<<endl;
            }else{
                int s,t;
                cin>>s>>t;
                L[t].splice(L[t].end(),L[s]);
            }
        }
    }
}
/* 
- insert(tt, xx): Insert an integer xx at the end of LtLt.
- dump(tt): Print all elements in LtLt.
- splice(ss, tt):　Transfer elements of LsLs to the end of LtLt. LsLs becomes empty.
3 10
0 0 1
0 0 2
0 0 3
0 1 4
0 1 5
2 1 0
0 2 6
1 0
1 1
1 2
 */


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

int main(){
    int K, X;
    cin >> K >> X;

    int start = X - K + 1;
    int goal = X + K - 1;
    int n = goal - start + 1;

    for (int i = 0; i < n; i++){
        int answer = start + i;

        if (i == n - 1){
            cout << goal << endl;
        }
        else {
            cout << answer << " ";
        }
    }
}


Measured memory_bytes: 256
using System;
 
namespace ConsoleApplication13
{
    class Program
    {
        static void Main(string[] args)
        {
            int a,b;
            int t;
            while(true)
            {
                string[] str = Console.ReadLine().Split(' ');
                a = int.Parse(str[0]);
                b = int.Parse(str[1]);
                if ((a == 0) && (b == 0))
                    break;
 
                if(a>b)
                {
                    t = a;
                    a = b;
                    b = t;
                }
 
                Console.WriteLine("{0} {1}", a, b);
 
            }
        }
    }
}
 

Measured memory_bytes: 9308
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef    long long   ll;
typedef    long double   ld;
//typedef    unordered_set<ll>   usll;
//typedef    unordered_multiset<ll>   umsll;
typedef    multiset<ll>   msll;
typedef    set<ll>   sll;
typedef    vector<ll>   vll;
typedef    pair<ll,ll>   pll;
typedef    vector<pll>   vpll;
typedef    priority_queue<ll>   pqll;
typedef    vector<int>   vi;
typedef    set<int>   si;
typedef    multiset<int>   msi;
//typedef    unordered_multiset<int>   umsi;
//typedef    unordered_set<int>   usi;
typedef     pair<int,int>   pi;
typedef    vector<pi>   vpi;
typedef    set<pi>   spi;
typedef    priority_queue<int>   pqi;
typedef    tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_set;
typedef    tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>   ind_setll;
#define    in   insert
#define    fi   first
#define    se   second
#define    pb   push_back
#define    mp   make_pair
#define    be   begin
#define    en   end
#define    itr   iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define    mo   1000000007
#define    inf  9223372036854775807
#define    ninf   -inf
#define    ima   2147483647
#define    imi   -ima
#define    oncnt    __builtin_popcount
#define    zerobegin   __builtin_clz
#define    zeroend   __builtin_ctz
#define    parity   __builtin_parity
#define    all(x)   x.be(),x.en()
#define    eps   1e-9
#define    coutd   cout<<setprecision(10)<<fixed
#define    mems(dp,x)   memset(dp,x,sizeof(dp))
const    ld   PI=3.1415926535897932384626433832792884197169399375105820974944;
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}
inline ll lcm(ll a,ll b){return ((a*b)/gcd(a,b));}


ll val(ll a,ll b,ll x)
{
	return ((a*x)/b)-(a*(x/b));
}

int main()
{
io
int testcases=1;//cin>>testcases;
while(testcases--)
{
	
	
ll a,b,n;
cin>>a>>b>>n;



ll am=0;
if(n<b)
cout<<val(a,b,n);

else if((n/b)<10000000)
{
	
	for(ll i=b-1;i<=n;i+=b)
	{ll vp=val(a,b,i);
	if(am>vp)
	break;
		am=max(am,vp);
	}
	am=max(val(a,b,n),am);
	cout<<am;
}

else
{
	cout<<val(a,b,n);
}


}return 0;}


Measured memory_bytes: 3648
h,w = map(int, input().split())
field = []
for _ in range(h):
    field.append(input())

# 黒がある行を抽出
hasb_row = []
for hi in range(h):
    for wj in range(w):
        if field[hi][wj] == "#":
            hasb_row.append(hi)
            break

# 黒がある列を抽出
hasb_col = []
for wj in range(w):
    for hi in range(h):
        if field[hi][wj] == "#":
            hasb_col.append(wj)
            break
        
# 再構成
f_ans = [[] for _ in range(len(hasb_row))]
for i, hi in enumerate(hasb_row):
    for j, wj in enumerate(hasb_col):
        f_ans[i].append(field[hi][wj:wj+1])
        
for hi in range(len(hasb_row)):
    print("".join(f_ans[hi]))


Measured memory_bytes: 3188
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<tuple>

using namespace std;

struct UnionFind{
  vector<int> par;
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    for(int i=0;i<n;i++) par[i] = i;
  }

  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }

  long long int size(int x) {
    return sizes[find(x)];
  }
};

int main(){

  int n;
  cin >> n;

  vector<double> p;

  while(n!=0){
    long double x[n],y[n],z[n],r[n];

    for(int i=0;i<n;i++){
      cin >> x[i] >> y[i] >> z[i] >> r[i];
    }

    UnionFind tree(n);
    vector<tuple<long double,int,int> > G;
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
        long double l=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2)+pow(z[i]-z[j],2))-r[i]-r[j];
        if(l<=0)tree.unite(i,j);
        else{
          G.push_back(make_tuple(l,i,j));
        }
      }
    }

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

    double s=0;

    for(int i=0;i<G.size();i++){
      if(tree.same(get<1>(G[i]),get<2>(G[i])));
      else{
        tree.unite(get<1>(G[i]),get<2>(G[i]));
        s+=get<0>(G[i]);
      }
    }

    p.push_back(s);


    cin >> n;
  }

  for(int i=0;i<p.size();i++) printf("%.3lf\n",p[i]);

}


Measured memory_bytes: 3436
#include <stdio.h>
int main()
{
    int x,i,a;
    while(scanf("%d",&x)==1)
    {
        a=0;
        for(i=1;;i++)
        {
            a+=i;
            if(a>=x)break;
        }
        printf("%d\n",i);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int sum = 0;

    for (int i = 0; i <= A; i++) {
        for (int j = 0; j <= B; j++) {
            for (int k =0; k <= C; k++) {
                if (10 * i + 2 * j + k == X / 50) sum++;
            }
        }
    }
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)



int main() {
	ll n;
	bool ret=false;
	in(n);
	
	repeq(i,0,9){
		repeq(j,0,9){
			if(n==i*j){
				ret=true;
			}
		}
	}

	if(ret){
		outn("Yes");
	}
	else{
		outn("No");
	}
	return 0;

}


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

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');
        var a = double.Parse(input[0]);
        var b = double.Parse(input[1]);
        var x = double.Parse(input[2]);

        //三角形かそれ以上か
        if ((a * a * b) / 2 >= x)
        {
            //三角形の時
            //底辺の水がある部分の長さ
            var y = (2 * x) / (b * a);

            //斜めの部分の長さ
            var z = Math.Sqrt(y * y + b * b);

            var sin = b / z;
            var asin = Math.Asin(sin) * (180/Math.PI);

            Console.WriteLine(asin);
            Console.ReadLine();
            return;

        }
        else
        {
            ////それ以上
            var y = (2 * x / (a * a)) - b;
            var z = b - y;

            var c = Math.Sqrt((z * z) + (a * a));

            var cos = a / c;
            var acos = Math.Acos(cos) * (180 / Math.PI);

            Console.WriteLine(acos);
            Console.ReadLine();
            return;

        }
    }
}


Measured memory_bytes: 13140