akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const int MOD = 1e9 + 7;

int main(){
	ll n, x;
	cin >> n >> x;

	vector<ll> a(n);

	rep(i, 0, n) {
		cin >> a[i];
	}

	ll ans = 0LL;
	rep(i,1,n) {
		if (a[i] + a[i - 1] > x) {
			ans += a[i] + a[i - 1] - x;
			if (a[i] + a[i - 1] - x <= a[i]) {
				a[i] -= a[i] + a[i - 1] - x;
			}
			else {
				a[i] = 0;
			}
		}
	}

	cout << ans << endl;
}



Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a%b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << c - (d - b) << " " << d + (c - a) << " " << a - (d - b) << " " << b + (c - a) << endl;
	return 0;
}


Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BC
import qualified Data.IntMap.Strict    as IM
import           Data.Maybe            (fromJust)

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- readInts
  print $ solve n as

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

solve n as = IM.foldrWithKey' folder 0 counter where
  counter = foldr (IM.alter countup) IM.empty as
  countup Nothing  = Just 1
  countup (Just x) = Just $ x + 1
  folder k v s
    | k < v = s + (v - k)
    | k > v = s + v
    | otherwise = s


Measured memory_bytes: 16764
#include<cstdio>
#include<iostream>
using namespace std;
string a;
int ans;
int main()
{
	cin>>a;
	int l=a.size();
	if(l&1)
	{
		for(int i=0;i<(l>>1);i++)
		if(a[i]!=a[l-i-1]) ans++;
	}
	else
	{
		for(int i=0;i<(l>>1);i++)
		if(a[i]!=a[l-i-1]) ans++;
	}
	printf("%d",ans);
	return 0;
}

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

int main() {
    //input
    int n;cin >> n;
    vector<int> a(n);
    vector<int> c(100);
    for(int i = 0; i < 100; i++) c[i]= 0;
    for(int i = 0; i < n; i++) cin >> a[i];
    
    //compute
    int counter = 0;
    int mi,ma,sum;
    mi = 0;
    ma = 0;
    sum = 0;

    for(int i = 0; i < n;i++){
        if(a[i] >= 1 && a[i] <= 399 ){
            c[0] = 1;
        }else if(a[i] >= 400 && a[i] <= 799){
            c[1] = 1;
        }else if(a[i] >= 800 && a[i] <= 1199){
            c[2] = 1;
        }else if(a[i] >= 1200 && a[i] <= 1599){
            c[3] = 1;
        }else if(a[i] >= 1600 && a[i] <= 1999){
            c[4] = 1;
        }else if(a[i] >= 2000 && a[i] <= 2399){
            c[5] = 1;
        }else if(a[i] >= 2400 && a[i] <= 2799){
            c[6] = 1;
        }else if(a[i] >= 2800 && a[i] <= 3199){
            c[7] = 1;
        }else if(a[i] >= 3200){
            counter += 1;
        }
    }

    for(int i = 0; i < 8; i++) {
        sum += c[i];
    }

    ma = sum + counter;
    mi = max(sum , 1);

    //output
    cout << mi << " " << ma << endl;

}

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

int main(void){
    int A, B, C;
    cin >> A >> B >> C;

    if(((A==B)&&(A!=C))||((B==C)&&(A!=B))||((A==C)&&(A!=B))){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false) cin.tie(NULL) cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define f first 
#define s second
#define int long long
using namespace std;

const int nax=1e5+5;
vector<int>adj[nax];
const int mod=1e9+7;
const int inf=1e18+7;

signed main(){
	int n;
	cin>>n;
	int f=0;
	for(int i=1;i<=9; i++){
		for(int j=1; j<=9; j++){
			if(i*j==n) f=1;
		}
	}
	if(f==1) cout<<"Yes"<<endl;
	else{
		cout<<"No"<<endl;
	}
	return 0;
}



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

int Partition(vector<int>& A)
{
    int x = A.back();
    int part = 0;
    for (int j = 0; j < A.size(); ++j) {
        if (A[j] <= x) {
            iter_swap(A.begin()+part, A.begin()+j);
            ++part;
        }
    }
    return part;
}

int main() {
    int n; 
    cin >> n;
    vector<int> vec(n);
    for (auto& v : vec) {
        cin >> v;
    }
    const int x = vec.back();
    const int partition = Partition(vec);
    for (int i = 0; i < n; ++i) {
        if (i == partition - 1) {
            cout << "[" << vec[i] << "]";
        }
        else {
            cout << vec[i];
        }
        if (i < n-1)  {
            cout << " ";
        }
    }
    cout << endl;
}


Measured memory_bytes: 3104
#ifndef __cplusplus
    cat << EOF
#endif
#include <bits/stdc++.h>
using namespace std;

typedef long long lint;
constexpr int inf = (1 << 30) - 1;
constexpr lint linf = (1ll << 60) - 1;

#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define overload_rep(arg0, arg1, arg2, name, ...) name
#define all(box) box.begin(), box.end()

template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }

int main() {

    string S, T;
    cin >> S >> T;
    cout << T << S << '\n';

}


Measured memory_bytes: 256
n, m = gets.chomp.split.map(&:to_i)
# 全て自然数にして並び替え
x_a = gets.chomp.split.map{|x| x.to_i + 10 ** 5}.sort_by{|x| x}

result = 0
# n >= mならば最初の時点で完了している
if n >= m
  puts result
  exit
end

# 間隔が前からどのくらいあるのか
diff_map = []
x_a.each_cons(2) do |x1, x2|
  diff_map << x2 - x1
end

diff_stack = diff_map.sort_by{|diff| diff}
diff_stack.slice(0, m - n).each do |diff|
  result += diff
end
puts result

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

int main(){
	int N,T,A;
	double optV;
	int optI;
	cin >> N;
	cin >> T >> A;
	{
		int H;
		cin >> H;
		optV=abs(T-H*0.006-A);
		optI=1;
	}
	for(int i=2;i<=N;i++){
		int H;
		cin >> H;
		double V=abs(T-H*0.006-A);
		if(optV>V){
			optV=V;
			optI=i;
		}
	}
	cout << optI << endl;
	return 0;
}


Measured memory_bytes: 256
import Control.Applicative
main = do _ <- getLine
          xs <- map read . words <$> getLine
          ys <- map read . words <$> getLine
          let d1 = dis 1.0 xs ys
              d2 = dis 2.0 xs ys
              d3 = dis 3.0 xs ys
              d  = maximum [abs(x-y) | (x,y) <- zip xs ys]
          putStr . unlines . map show $ [d1,d2,d3,d]

dis :: Double -> [Double] -> [Double] -> Double
dis n xs ys = (sum [(abs(x-y))**n | (x,y) <- zip xs ys])**(1/n)

Measured memory_bytes: 4424
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
	long long a,b;
	cin >> a >> b;
	a=__gcd(a,b);
	int ans=0;
	for(long long i=2;i*i<=a;i++)
	{
		if(a%i==0) ans++;
		while(a%i==0) a/=i;
	}
	if(a>1) ans++;
	cout << ans+1 << endl;
}

Measured memory_bytes: 256
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*
import kotlin.comparisons.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val s = read().toList()
    val originalSize = s.size
    val distinctSize = s.distinct().size
    println(if(originalSize==distinctSize) "yes" else "no")
    pw.flush()
}

/****** Declared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }


// Extensions
fun<T> List<T>.toBuckets(bucketKeys: List<T>): Map<T, Int> {
    val buckets = bucketKeys.associate { t -> Pair(t, 0) }.toMutableMap()
    this.forEach { t ->
        buckets[t] = buckets[t]!! + 1
    }
    return buckets
}

fun <K, V> Map<K, V>.toMutableMap(): MutableMap<K, V> = HashMap(this)

// Util Functions
fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j]) % MOD
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun Double.isDecimal(): Boolean = ((this - Math.floor(this)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


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


int main() {
  ll ans=1;
  int n;
  cin >> n;
  ll a[n+1]={};
  a[0]=3;

  rep(i,n){
      int q;
      cin >> q;
      if(a[q]>0){
          ans=ans*a[q]%mod;
          a[q]--;
          a[q+1]++;
        }else{
          cout << 0 << endl;
          return 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;

int main(){

  int N, H;
  cin >> N;
  int ans = 0;
  vector<int> vec(N);

  for (int i = 0; i < N; i++){
    cin >> H;
    vec.at(i) = H;
  }

  
  for (int i = N-1; i >= 0; i--) {
    bool flag = true;
    for (int j = i; j >= 0; j--) {
      if(vec.at(i) - vec.at(j) < 0) flag = false;
      if(flag == false) break;
    }
    if(flag == true) ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static public void Main(string[] args)
    {
        string input = Console.ReadLine();
        input += '\t';
        char[] ans = new char[20];

        int j = 0;
        for(int i = 0; input[i] != '\t'; i++)
        {
            if (input[i] != 'B')
            {
                ans[j] = input[i];
                j++;
            }else
            {
                if (j != 0) j--;
            }
        }

        ans[j] = '\t';

        for(int i = 0; ans[i] != '\t'; i++)
        {
            Console.Write(ans[i]);
        }

        Console.WriteLine();

    }
}

Measured memory_bytes: 2648
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long cnt = 0;
        if(x % 11 != 0){
            long mod = x % 11;
            if(mod <= 6){
            cnt = 2 * (x / 11) + 1;
            }
            else{
            cnt = 2 * (x / 11) + 2;
            }
        }
        else{
            cnt = 2 * (x / 11);
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 21844
import java.util.Scanner;
 
public class Main{
  public static void main(String[] args){
 
    Scanner sc = new Scanner(System.in);
 
    int N = sc.nextInt();
    int count = 0;
 
    for(int i = 0; i < N; i++){
      int a = sc.nextInt();
      while(true){
      if(a % 2 == 0){
        a = a / 2;
        count = count + 1;
      }else{
        break;
      }
    }
  }
 
   System.out.println(count);
  }
}

Measured memory_bytes: 34144
class Node:
    def __init__(self, p=-1, l=-1, r=-1):
        self._p = p
        self._l = l
        self._r = r

T = []

def pre_parse(index):
    if index == -1:
        return
    print(' %d'%index, end='')
    pre_parse(T[index]._l)
    pre_parse(T[index]._r)

def in_parse(index):
    if index == -1:
        return
    in_parse(T[index]._l)
    print(' %d'%index, end='')
    in_parse(T[index]._r)

def post_parse(index):
    if index == -1:
        return
    post_parse(T[index]._l)
    post_parse(T[index]._r)
    print(' %d'%index, end='')

if __name__ == '__main__':
    n = int(input())

    for i in range(n):
        T.append(Node(-1, -1, -1))

    for i in range(n):
        index, l_child, r_child = map(int, input().split())
        T[index]._l = l_child
        T[index]._r = r_child
        if l_child != -1:
            T[l_child]._p = index
        if r_child != -1:
            T[r_child]._p = index

    root = -1
    for i in range(n):
        if T[i]._p == -1:
            root = i
            break

    print('Preorder')
    pre_parse(root)
    print('\nInorder')
    in_parse(root)
    print('\nPostorder')
    post_parse(root)
    print()



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

int main() {
  int64_t n, h;
  std::cin >> n >> h;
  std::vector<int64_t> a(n), b(n);
  for (int64_t i = 0; i < n; i++) {
    std::cin >> a[i] >> b[i];
  }

  const auto a_max = *std::max_element(a.cbegin(), a.cend());
  std::sort(b.begin(), b.end(), std::greater<int64_t>());

  int64_t sum = 0, count = 0;

  for (const auto i : b) {
    if (i <= a_max) {
      break;
    }
    sum += i;
    count++;
  }

  if (h <= sum) {
    int64_t sum = 0, count = 0;
    for (const auto i : b) {
      sum += i;
      count++;
      if (h <= sum) {
        break;
      }
    }
    std::cout << count << std::endl;
  } else {
    std::cout << (h - sum - 1) / a_max + 1 + count << std::endl;
  }
  return 0;
}


Measured memory_bytes: 1792
//
//  main.cpp
//  ABC152B
//
#include <iostream>
#include<math.h>
using namespace std;
int main(int argc, const char * argv[]) {
    int a,b;
    cin>>a>>b;
    int ans=0;
    if (a>b) {
        for (int i=0; i<a; i++) {
            ans+=b*(int)pow(10,i);
        }
    }else{
        for (int i=0; i<b; i++) {
            ans+=a*(int)pow(10,i);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sci1(a) scanf("%d",&a)
#define sci2(a,b) scanf("%d %d",&a,&b)
#define sci3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define scs(s) scanf("%s",s)
#ifndef GET_MACRO

#define GET_MACRO(__1,__2,__3,NAME,...) NAME

#endif // GET_MACRO

#define sci(...) GET_MACRO(__VA_ARGS__,sci3,sci2,sci1)(__VA_ARGS__)
#define ll long long
#define pii pair<int,int>
#define mp(a,b) make_pair(a,b)
#define LSB(i) ((i)&(-i))
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)
#define infl 0x7ffffffffffffff
#define infi  0x7fffffff
#define fill_(a,b) fill(a.begin(),a.end(),b)
#define pb push_back
#define xx first
#define yy second
int main(){
    int n,i,j,tn;
    sci(n);
    tn=n-(n%2);
    vector<pii> edge;
    for(i=1;i<tn;i++){
        for(j=i+1;j<=tn;j++){
            if((i+j)!=(tn+1)){
                edge.pb(mp(i,j));
            }
        }
    }
    if(n%2){
        for(i=1;i<=tn;i++){
            edge.pb(mp(i,n));
        }
    }
    printf("%d\n",(int)edge.size());
    for(auto e:edge){
        printf("%d %d\n",e.first,e.second);
    }
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>


#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
int main(){
  int n,m,i;
  cin >> n;
  string blue[n];

  for(i=0;i<n;i++){
	cin >> blue[i];
  }
  cin >> m;
  string red[m];

  for(i=0;i<m;i++){
	cin >> red[i];
  }

  map<string,int> bluemap,redmap;

  for(i=0;i<n;i++){
	if(bluemap.find(blue[i]) == bluemap.end()){
	  bluemap[blue[i]] = 1;
	}
	else{
	  bluemap[blue[i]] += 1;
	}
  }

  for(i=0;i<m;i++){
	if(redmap.find(red[i]) == redmap.end()){
	  redmap[red[i]] = 1;
	}
	else{
	  redmap[red[i]] += 1;
	}
  }
  
  int max=0;
  int cur;

  
  for(auto it : bluemap){
	//cout << "key:" << it.first << "val:" << it.second << endl;

	if(redmap.find(it.first) == redmap.end()){
	  cur = it.second;
	}
	else{
	  cur = it.second - redmap[it.first];
	}
	
	if(cur > max){
	  max = cur;
	}
  }

  cout << max << endl;

  return 0;
  
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef pair<P, int> PP;
int par[100000];
int rank1[100000];
void init(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
		rank1[i] = 0;
	}
}
int find1(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find1(par[x]);
	}
}
void unite1(int x, int y) {
	x = find1(x);
	y = find1(y);
	if (x == y)return;
	if (rank1[x] < rank1[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank1[x] == rank1[y])rank1[x]++;
	}
}
bool same(int x, int y) {
	return find1(x) == find1(y);
}
struct edge { int u, v;ll cost; };
//最大全域木にしたい場合は<を>にする
bool comp(const edge&e1, const edge&e2) {
	return e1.cost < e2.cost;
}
edge es[200000];
int V, E;
ll kruskal() {
	sort(es, es + E, comp);
	init(V);
	ll res = 0;
	for (int i = 0; i < E; i++) {
		edge e = es[i];
		if (!same(e.u, e.v)) {
			unite1(e.u, e.v);
			res += e.cost;
		}
	}
	return res;
}
int main(){
	cin >> V; E = 2 * (V - 1);
	pair<ll,int> x[100000],y[100000];
	rep(i, V) {
		ll a, b; cin >> a >> b;
		x[i] = { a,i }; y[i] = { b,i };
	}
	sort(x, x + V); sort(y, y + V);
	rep(i, V-1) {
		es[i] = { x[i].second,x[i + 1].second,x[i + 1].first - x[i].first };
	}
	rep(i, V - 1) {
		es[V - 1 + i] = { y[i].second,y[i + 1].second,y[i + 1].first - y[i].first };
	}
	cout << kruskal() << endl;
	return 0;
}

Measured memory_bytes: 7296
var
	n,ans:Longint;
procedure f(x:int64;a,b,c:Longint);
begin
	if x>n then exit;
	inc(ans,a*b*c);
	f(x*10+3,1,b,c);
	f(x*10+5,a,1,c);
	f(x*10+7,a,b,1);
end;
begin
	read(n);
	f(0,0,0,0);
	writeln(ans);
end.

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

using namespace std;

const double INF = 1e9;

int main(void) {
    int D, E;
    while (cin >> D >> E, D) {
        int x, y;
        double ans = INF;
        for (int i = 0; i <= D; i++) {
            x = i; y = D - i;
            ans = min(ans, abs(sqrt(x * x + y * y) - (double)E));
        }
        printf("%.10f\n", ans);
    }
    return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
int main(){
    ll N,M;
    cin >> N >> M;
    ll ans = M;
    rep(i,N - 1)ans *= (M - 1);
    cout << ans << endl;
}

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

bool p[1000001];

void sieve(){
    for(int i=0;i<1000001;i++)p[i] = true;
    p[0] = p[1] = false;
    for(int i=2;i<1000001;i++){
        if(p[i]){
            for(int j=2*i;j<1000001;j+=i)p[j] = false;
        }
    }
}

int main(){
    int n, x;
    sieve();

    while(1){
        cin>>n>>x;
        if(!n && !x)break;
        bool dp[1000001]= {false};
        int dish[31];
        for(int i=0;i<n;i++){
            cin>>dish[i];
            dp[dish[i]] = true;
        }
    
        for(int i=0;i<n;i++){
            for(int j=0;j<=1000000;j++){
                if(dp[j] && j+dish[i] <= 1000000)
                    dp[j+dish[i]] = true;
            }
        }
    
        int max=0;
        for(int i=0;i<=x;i++){
            if(dp[i] && p[i])max = i;
        }

        if(max) cout<<max<<endl;
        else cout<<"NA"<<endl;
    }

    return 0;
}

Measured memory_bytes: 5028
package main

import "fmt"

func main(){
	var N int;
	var S string;

	fmt.Scan(&N, &S);
	//var ans []string;

	// ans = S;
	c := 1;
	
	for i:=0; i<N-1 ;i++{
		if S[i] != S[i+1] {
		 c++;	
		}
	}
	
	fmt.Println(c);
}

Measured memory_bytes: 1280
N,K=[int(x) for x in input().rstrip().split()]

ans=[0 for i in range(N)]
l=[]

for i in range(K):
  d=int(input())
  A=[int(x) for x in input().rstrip().split()]
  for j in A:
    ans[j-1]+=1


cnt=0

for i in ans:
  if i==0:
    cnt+=1
print(cnt)



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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int n, m;
  cin >> n >> m;

  vector<int> h(n);
  vector<int> cur(n, -2);
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }

  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;

    --u; --v;
    cur[u] = max(cur[u], h[v]);
    cur[v] = max(cur[v], h[u]);
  }

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (h[i] > cur[i])  ans++;
  }

  cout << ans << '\n';
}



Measured memory_bytes: 3956
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define mod 1000000007
#define INF2 9999999999
#define INF (1 << 30)
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)

using namespace std;
using ll = __int64_t;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int DX[] = {1, 1, 0, -1, -1, -1, 0, 1};
int DY[] = {0, -1, -1, -1, 0, 1, 1, 1};

void solve(){
    ll a, b;
    cin >> a >> b;
    if((a <= 0 && b > 0) && (a < 0 && b >= 0)){
        cout << "Zero" << endl;
    }else if((a > 0 && b > 0) || ((abs(a)+abs(b))%2 != 0)){
        cout << "Positive" << endl;
    }else{
        cout << "Negative" << endl;
    }
}

int main() {
    solve();
    return 0;
}

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

#define max 100

//qsort(d, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}

int main()
{
    int n, x, i, j, d, cnt;
    int l[max];
    
    scanf("%d %d", &n, &x);
    for (i=0; i<n; i++) {
        scanf("%d", &l[i]);
    }
    
    d=0;
    cnt=1;
    
    for(i=0; i<n; i++){
        d=d+l[i];
        if(d<=x&&cnt<n+1){
            cnt++;
        }else{
            break;
        }
    }
    
    printf("%d", cnt);
    
    return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;  cin >> n;
    vector<int> v;

    for (int i = 0; i < n; i++) {
        int d;  cin >> d;
        v.push_back(d);
    }

    sort(v.begin(), v.end(), greater<int>());

    int ret = 1;
    for (int i = 1; i < n; i++) if (v[i] < v[i - 1]) ret++;

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
using System;

namespace ABC_106_A_Csharp_ver
{
    class Program
    {
        static void Main(string[] args)
        {
            var word = Console.ReadLine().Split(' ');
            int A = int.Parse(word[0]);
            int B = int.Parse(word[1]);
            Console.WriteLine((A - 1) * (B - 1));
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
import java.io.*;
import java.util.Arrays;
    
public class Main {
  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] inputs = br.readLine().split(" ");
    Arrays.sort(inputs);
    System.out.println(String.join(" ", inputs));
  }
}

Measured memory_bytes: 24268
#include <bits/stdc++.h>
using namespace std;
 
#define MAXN (int)(2*1e5 + 1)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define MOD2 (lli) 998244353  
#define lli long long int
#define sz(a) int(a.size())
#define M_PI 3.1415
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};

lli pd[1000001][13];
string s;

lli modFexp(lli x, lli y, lli p){ //Calcula x^y%p em Log Y
	int ans = 1;
	while(y > 0){
		if(y&1) ans = (ans*x) % p;
		y = y >> 1;
		x = (x*x) % p;
	}
	return ans;
}

lli solve(int pos , int rem){
  if(pos == sz(s)) return (rem == 5);

  lli &ans = pd[pos][rem];
  if(ans != -1) return ans;
  lli a = 0;
  if(s[pos] == '?'){
    for(int i=0;i<=9;i++)
      a = (a + solve(pos+1, (rem*10 + i)%13 ))%MOD;
  } else {
    a = solve(pos+1, (rem*10 + (s[pos]-'0'))%13)%MOD;
  }

  return ans = a%MOD;
}


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

  cin >> s;

  memset(pd, -1, sizeof pd);

  // for(int i=1;i<=99;i++){
  //   if(i%13 == 5){
  //     cout << i << endl;
  //   }
  // }

  cout << solve(0, 0)%MOD << endl;


  return 0;
}

Measured memory_bytes: 109904
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>

using namespace std;
typedef long long ll ;

ll a[200010] ;

int main()
{
    ll n ;
    scanf("%lld",&n) ;
    ll sum=0 ;
    for (int i=0 ; i<n ; i++)
    {
        scanf("%lld",&a[i]) ;
        sum+=a[i] ;
    }
    ll csum=0 ;
    ll ans=1000000000000 ;
    for (int i=0 ; i<n-1 ; i++)
    {
        csum+=a[i] ;
        sum-=a[i] ;
        ll def=abs(csum-sum) ;
        ans=min(ans,def) ;
    }
    printf("%lld\n",ans) ;
    return 0;
}


Measured memory_bytes: 1792
import numpy as np
n = int(input())
a = np.array([int(a) for a in input().split()])
q = int(input())
bc = np.array([[int(a) for a in input().split()] for j in range(q)])

u, c = np.unique(a, return_counts=True)
dica = dict(zip(u, c))
#print(dica)

keys = dica.keys()

tmp = sum([ k*dica[k] for k in dica.keys()])


for i in range(q):
  t1, t2 = bc[i]
  if not t1 in keys:
    dica[t1] = 0
  if not t2 in keys:
    dica[t2] = 0

  tmp += dica[t1] * (t2 - t1)
  print(tmp)
  
  dica[t2] = dica[t1] + dica[t2]
  dica[t1] = 0
  






Measured memory_bytes: 46272
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n],b[n],c[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i]>>c[i];
	}
	
	int d[n][3]={0};
	for(int i=0;i<n;i++)
	{
		for (int j=0;j<3;j++)
		{
			if(i==0)
			{
				if(j==0)
				d[i][j]=a[i];
				if(j==1)
				d[i][j]=b[i];
				if(j==2)
				d[i][j]=c[i];
			}
			else
			{
				for(int k=0;k<3;k++)
				{
					if(j==k)continue;
					if(j==0)d[i][j]=max(d[i][j],d[i-1][k]+a[i]);
					else
					if(j==1)
					d[i][j]=max(d[i][j],d[i-1][k]+b[i]);
					else
					d[i][j]=max(d[i][j],d[i-1][k]+c[i]);
				}
			}
		}
	}
	int ans=0;
	ans=max(ans,d[n-1][0]);
	ans=max(ans,d[n-1][1]);
	ans=max(ans,d[n-1][2]);
	cout<<ans;
	
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
 
signed main(){

	lli x,a,b;
	cin>>x>>a>>b;

	if(b-a<=0)cout<<"delicious"<<endl;
	else if(b-a<=x)cout<<"safe"<<endl;
	else cout<<"dangerous"<<endl;

	return 0;
 
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	int N, M, a, b;
	cin >> N >> M;
	vector<int>A(N, 0);
	for (int i = 0; i < M; i++)
	{
		cin >> a >> b;
		A[a-1]++;
		A[b-1]++;
	}
	for (int i = 0; i < N; i++)
	{
		cout << A[i] << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen("testcase.dat", "r", stdin);
	int n;
	vector <int> res(10, 0);
	int i;

	for (i = 0; i < 10; ++i){
		cin >> n;
		res[i] = n;
	} // end for

	sort (res.begin(), res.end(), greater<int>() );
	
	for (i = 0; i < 3; ++i){
		cout << res[i] << endl;
	} // end for
		
	return 0;
}

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

const long long mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;

  vector<vector<long long>> dp(n+1, vector<long long>(4, 0)); // 0:(ok), 1:(0 in A), 2:(9 in A), 3:(no 0&9 in A)
  dp[0][3] = 1;

  for ( int i = 1; i <= n; i++ ) {
    // 3
    dp[i][3] += (dp[i-1][3] * 8) % mod;  dp[i][3] %= mod;
    // 2
    dp[i][2] += dp[i-1][3];              dp[i][2] %= mod;
    dp[i][2] += (dp[i-1][2] * 9) % mod;  dp[i][2] %= mod;
    // 1
    dp[i][1] += dp[i-1][3];              dp[i][1] %= mod;
    dp[i][1] += (dp[i-1][1] * 9) % mod;  dp[i][1] %= mod;
    // 0
    dp[i][0] += dp[i-1][2];              dp[i][0] %= mod;
    dp[i][0] += dp[i-1][1];              dp[i][0] %= mod;
    dp[i][0] += (dp[i-1][0] * 10) % mod; dp[i][0] %= mod;
  }

  cout << dp[n][0] << endl;
  return 0;
}


Measured memory_bytes: 73312
def BellmanFord(edges,num_v,source):
    #グラフの初期化
    inf=float("inf")
    dist=[inf for i in range(num_v)]
    dist[source-1]=0
    flag = False

    #辺の緩和
    for i in range(num_v):
        for edge in edges:
          if edge[0] != inf and dist[edge[1]-1] > dist[edge[0]-1] + edge[2]:
            dist[edge[1]-1] = dist[edge[0]-1] + edge[2]
            if i==num_v-1:
                if edge[1] == num_v:
                    return -1
                else:
                    dist[edge[1]-1] = -inf
                    flag = True
    if flag:
        for i in range(num_v):
            for edge in edges:
                if dist[edge[1]-1]>dist[edge[0]-1] + edge[2]:
                    dist[edge[1]-1] = dist[edge[0]-1] + edge[2]
                    if edge[1] == num_v :
                        return -1

    return dist

N,M,P = [int(x) for x in input().split()]
gp = []
for _ in range(M):
    A,B,C = [int(x) for x in input().split()]
    gp.append([A,B,P-C])

li = BellmanFord(gp,N,1)
if(li==-1):
    print(-1)
else:
    print(max(0,-li[N-1]))


Measured memory_bytes: 48364
using System;
using System.Linq;

namespace ABC
{
    using System.Collections.Generic;
#if USE_STUB
    using static Stub.Console;
#else
    using static System.Console;
#endif
    using static System.Math;
    public class Program
    {
        private const int MOD = 1000000007;

        static long H;
        static long W;
        static char[][] S;

        static void Main(string[] args)
        {
            WriteLine(Solve());
        }

        public static object Solve()
        {
            var hw = ReadLine().Split().Select(int.Parse).ToArray();
            H = hw[0];
            W = hw[1];
            S = new char[H][];
            for (int i = 0; i < H; i++)
            {
                S[i] = ReadLine().ToCharArray();
            }

            var points = new Dictionary<int, int>();
            for (int h = 0; h < H; h++)
            {
                var l = new List<int>();
                for (int w = 0; w < W; w++)
                {
                    Validate(points, h, w, l);
                }
                CountUp(points, l);
            }
            for (int w = 0; w < W; w++)
            {
                var l = new List<int>();
                for (int h = 0; h < H; h++)
                {
                    Validate(points, h, w, l);
                }
                CountUp(points, l);
            }

            return points.Values.Max();
        }

        private static void Validate(Dictionary<int, int> points, int i, int j, List<int> l)
        {
            if (S[i][j] == '.')
            {
                l.Add((i << 16) + j);
            }
            else
            {
                CountUp(points, l);
            }
        }

        private static void CountUp(Dictionary<int, int> points, List<int> l)
        {
            foreach (var item in l)
            {
                if (!points.ContainsKey(item))
                    points.Add(item, l.Count);
                else
                    points[item] += l.Count - 1;
            }
            l.Clear();
        }
    }
}


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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define print(x) cout << x << endl

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

ll MOD = 1000000007;


int main()
{
    ll N;
    cin >> N;
    ll sum = 0;
    rep(i, N)
    {
        if ((i+1) % 3 != 0 && (i+1) % 5 != 0)
            sum += i + 1;
    }
    print(sum);
    return 0;
}


Measured memory_bytes: 3560
#include <iostream>

using namespace std;

int main(){
    int N;
    while(cin >> N){
        int best = N+1;
        int res = 0;
        for(int i=0;i<N;i++){
            int A; cin >> A;
            if(best > A){
                ++res;
                best = A;
            }
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    int N;
    cin >> N;
    int a  = N;
    ll sum = 0;
    while (a != 0) {
        sum += a % 10;
        a /= 10;
    }
    if (N % sum == 0) {
        print("Yes");
    } else {
        print("No");
    }

    return 0;
}

Measured memory_bytes: 892
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(long long N, std::vector<long double> x, std::vector<std::string> u){
    long double ans=0.;
    rep(i, N){
        if(u[i]=="BTC")
            ans += 380000.0*x[i];
        else
            ans += x[i];
    }
    cout << setprecision(15) << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long double> x(N);
    std::vector<std::string> u(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%Lf",&x[i]);
        std::cin >> u[i];
    }
    solve(N, std::move(x), std::move(u));
    return 0;
}


Measured memory_bytes: 256
const input = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\n/);
for (let i=0; i<input.length; i+=2) {
    if (input[i] === '0') {
        break;
    }
    let num = input[i+1].split(/\s/).map(Number);
    let tmp = 0;
    for (let j=0; j<num.length; j++) {
        tmp += num[j]; 
    }
    let ave = tmp / input[i];
    let tmp2 = 0;
    for (let j=0; j<num.length; j++) {
        tmp2 += Math.pow(ave-num[j], 2); 
    }
    let dev = (Math.sqrt(tmp2 / input[i])).toFixed(8);
    console.log(dev);
}




Measured memory_bytes: 16700
require 'pp'

def gets; ARGF.gets; end

def rot90(v)
  [-v[1], v[0]]
end

def main
  x1, y1, x2, y2 = gets.split.map(&:to_i)

  v12 = [x2 - x1, y2 - y1]
  # pp v12

  # 時計回りに90°回転
  v23 = rot90(v12)
  x3, y3 = [x2 + v23[0], y2 + v23[1]]

  v34 = rot90(v23)
  x4, y4 = [x3 + v34[0], y3 + v34[1]]

  puts "#{x3} #{y3} #{x4} #{y4}"
end

if __FILE__ == $0
  main
end


Measured memory_bytes: 2172
//
// Created by yamunaku on 2019/07/14.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a%2+b%2+c%2>=2){
        cout << "Hom" << endl;
    }else{
        cout << "Tem" << endl;
    }
    return 0;
}




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

#define ll unsigned long long
#define INF 1234567890
#define N (int)(1e5 + 5)
#define pi acos(-1)

void solve()
{
   int dp[4];
   int n;
   cin >> n;
   for(int i = 1; i <= 3; ++i) cin >> dp[i];
   for(int i = 2; i <= n; ++i)
   {
       int cost[4], new_dp[4];
       for(int j = 1; j <= 3; ++j) cin >> cost[j], new_dp[j] = -INF;
       for(int j = 1; j <= 3; ++j)
        for(int k = 1; k <= 3; ++k)
        if(j != k)
            new_dp[j] = max(new_dp[j], cost[j] + dp[k]);
       for(int j = 1; j <= 3; ++j)
        dp[j] = new_dp[j];
   }
   cout << max(dp[1], max(dp[2], dp[3]));
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
long long a,b,c,d,ans,n;
long long pq[10];
int main()
{
	scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&d,&n);
	pq[1]=a*4;pq[2]=b*2;pq[3]=c;
	sort(pq+1,pq+4);
	if (d<=a*8 && d<=b*4 && d<=c*2) 
	{
		if (n&1) cout<<d*(n/2)+pq[1]<<endl;
		else cout<<d*(n/2)<<endl;
	}
	else cout<<pq[1]*n<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vector<int>>;

void svtr(vector<int> &a){
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
}

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

  if(s.size()%2==1){
    cout << "No";
    return 0;
  }

  rep(j,s.size()){
    if(s[j]=='h' && j%2==0)
      continue;
    if(s[j]=='i' && j%2==1)
      continue;
    else{
      cout << "No";
      return 0;
    }
  }

  cout << "Yes";
  return 0;
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(100001);
	int ans=0;
	rep(i,n){
		int x;
		cin >> x;
		if(x<=100000) a.at(x)++;
		else ans++;
	}
	rep(i,100001){
		if(a.at(i)){
			if(a.at(i)<i) ans+=a.at(i);
			else ans+=a.at(i)-i;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
/* ****Tciitb**** */
                     
#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          int long long
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll ,ll >
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;



int main() {
  io
  
  ll n;
  cin>>n;
  string x;
  cin>>x;
  ll e[n]={0},w[n]={0};
  rep(i,0,n)
  {
     if(i==0)
     {
       if(x[i]=='E')
        e[i]++;
      else
        w[i]++;
     }
     else
     {
      if(x[i]=='E')
        {e[i]=e[i-1]+1;w[i]=w[i-1];}
      else
        {w[i]=w[i-1]+1;e[i]=e[i-1];}

     }
     
  }
  ll ans=1e18;
  rep(i,0,n)
  { 
    if(i==0)
    {
       ll c=abs(e[n-1]-e[0]);
       ans=min(ans,c);
    }
    else if(i==n-1)
    {
       ll c=w[n-2];
       ans=min(ans,c);
    }
    else
       {
         ll c1=abs(e[n-1]-e[i]);
         ll c2=w[i-1];
         ans=min(ans,c1+c2);
       }

  }
  cout<<ans;

  }
  

  


  




Measured memory_bytes: 5396
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=1e9+7;
const int MAXN=600005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
ll ans=0;
int f[MAXN],flag[MAXN],edgenum=0;
struct enode{int u,v,c; } e[MAXN];
int compare(enode x,enode y){ return x.c>y.c; }
int find(int x){return f[x]==x?f[x]:f[x]=find(f[x]); }
void unions(int x,int y,int c)
{
//	cout<<x<<" "<<y<<" "<<c<<endl;
	int xx=find(x),yy=find(y);
	if (xx==yy)
	{
		if (!flag[xx]) ans+=c,flag[xx]=1;
		return;
	}
	if (flag[xx]&&flag[yy]) return;
	f[xx]=yy;
	flag[yy]=flag[yy]|flag[xx];
	ans+=c;
}
int main()
{
    int n=read(),H=read(),W=read();
    for (int i=1;i<=n;i++)
    {
    	int x=read(),y=read()+H,c=read();
    	e[++edgenum]=(enode){x,y,c};
	}
	sort(e+1,e+edgenum+1,compare);
	for (int i=1;i<=H+W;i++) f[i]=i,flag[i]=0;
	for (int i=1;i<=edgenum;i++) unions(e[i].u,e[i].v,e[i].c); 
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6016