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

#define REP(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define fi first
#define sc second
#define pb push_back
#define double long double
#define all(x) x.begin(), x.end()

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int>> vpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<int, int> pii;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

const i64 MOD = 998244353;
const i64 INF = 2e15;

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

	string s;
	cin >> s;

	int n = s.size();
	int indL = -1, indR = -1;
	int c0 = 0, c1 = 0;
	vi ans(n, 0);

	for (int i = 0; i < n; i++) {
		if (s[i] == 'R' && indR != -1) {
			if (indR % 2 == 0) {
				ans[indR] = c0;
				ans[indL] = c1;
			}
			else {
				ans[indR] = c1;
				ans[indL] = c0;
			}

			indR = -1;
			indL = -1;
			c0 = 0;
			c1 = 0;
		}
		else if (s[i] == 'L' && indL == -1) {
			indL = i;
			indR = i - 1;
		}
		if (i % 2 == 0) c0++;
		else c1++;
	}
		
	if (indR != -1) {
		if (indR % 2 == 0) {
			ans[indR] = c0;
			ans[indL] = c1;
		}
		else {
			ans[indR] = c1;
			ans[indL] = c0;
		}
	}

	for (int i = 0; i < n; i++) cout << ans[i] << " ";
	cout << endl;

	return 0;
}

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

int main()
{
    int a;
    cin >> a;
    int l = a / 100;
    int r = a % 100;
    if (1 <= l && l <= 12)
    {
        if (1 <= r && r <= 12)
            cout << "AMBIGUOUS" << endl;
        else
            cout << "MMYY" << endl;
    }
    else
    {
        if (1 <= r && r <= 12)
            cout << "YYMM" << endl;
        else
            cout << "NA" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int X;
  cin >> X;

  int ans = 0;
  
  int p1 = X % 500;
  int ans1 = (X-p1)/500;
  int p2 = p1 % 5;
  int ans2 = (p1-p2)/5;
  cout << ans1 * 1000 + ans2 * 5 << endl;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
vector<int> E[101010];
int dist[101010][2];

void dfs(int cur,int pre,int id,int d) {
	dist[cur][id]=d;
	FORR(r,E[cur]) if(r!=pre) dfs(r,cur,id,d+1);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
		E[y-1].push_back(x-1);
	}
	dfs(0,0,0,0);
	dfs(N-1,N-1,1,0);
	
	int A=0,B=0;
	FOR(i,N) {
		if(dist[i][0]<=dist[i][1]) A++;
		else B++;
	}
	
	if(A>B) return _P("Fennec\n");
	else _P("Snuke\n");
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 12800
using System;
class Program
{
    static void Main(string[] args)
    {
        string a = Console.ReadLine(); //標準入力


        int N = int.Parse(a);

        decimal count = 0;

        for (int i = 1; i<N;i++)
        {
            if (N % i == 0)
            {
                count += (decimal)(N / i - 1);
            }
            else
            {
                count += (decimal)(N / i);
            }
        }

        Console.WriteLine("{0}", count);
    }

}

Measured memory_bytes: 27600
//i ll be the king
#include<bits/stdc++.h>
#define ll long long int
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_orde(ind)
using namespace std;
int main()
{
	sync;
	ll n,m,x,y;
	cin>>n>>m>>x>>y;
	ll a[n],b[m];
	input(a,n);
	input(b,m);
	int flag=0;
	ll maxm=*min_element(b,b+m),minm=*max_element(a,a+n)+1;
	for(ll i=minm;i<=maxm;i++)
	if(x<i&&i<=y)
	flag=1;
	if(flag)
	cout<<"No War";
	else
	cout<<"War";
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] p = new int[n];
		for (int i=0;i<n;i++) {
			p[i] = sc.nextInt()-1;
		}
		
		int[] dp = new int[n];
		int max = 0;
		
		for (int i=0;i<n;i++) {
			dp[p[i]] = p[i]==0 ? 1 : dp[p[i]-1]+1;
			max = Math.max(max, dp[p[i]]);
		}
		
		System.out.println(n-max);

	}

}


Measured memory_bytes: 66520
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val ab = Array(m) { sc.nextInt() to sc.nextInt() }

    val group = IntArray(n + 1) { it }
    val rank = LongArray(n + 1)
    val count = LongArray(n + 1) { 1 }

    fun find(index: Int): Int {
        return if (group[index] == index) {
            index
        } else {
            group[index] = find(group[index])
            group[index]
        }
    }

    fun unite(x: Int, y: Int) {
        val nx = find(x)
        val ny = find(y)

        if (nx == ny) return

        if (rank[nx] < rank[ny]) {
            group[ny] = nx
        } else {
            group[nx] = ny
            if (rank[nx] == rank[ny]) rank[nx]++
        }
    }

    val ret = LongArray(m + 1)
    (0 until ab.size).reversed().forEach { index ->
        val x = ab[index].first
        val y = ab[index].second

        val gx = find(x)
        val gy = find(y)

        if (gx == gy) {
            ret[index] = ret[index + 1]
            return@forEach
        }

        unite(gx, gy)
        (count[gx] * count[gy]).let {
            ret[index] = ret[index + 1] + it
            count[find(gx)] = count[gx] + count[gy]
        }
    }

    ret.drop(1).forEachIndexed { index, v ->
        println(ret.first() - ret[index + 1])
    }


}

Measured memory_bytes: 87716
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll power(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)

//your code here!

int main(void){
    ll sx, sy, tx, ty;
    scanf("%lld %lld %lld %lld", &sx, &sy, &tx, &ty);
    rep(_, ty-sy) printf("U");
    rep(_, tx-sx) printf("R");
    rep(_, ty-sy) printf("D");
    rep(_, tx-sx+1) printf("L");
    rep(_, ty-sy+1) printf("U");
    rep(_, tx-sx+1) printf("R");
    printf("DR");
    rep(_, ty-sy+1) printf("D");
    rep(_, tx-sx+1) printf("L");
    printf("U");
    return 0;
}


Measured memory_bytes: 128
using System;
class Program{
	public static void Main(){
		string[] str = Console.ReadLine().Split(' ');
		int X = int.Parse(str[0]);
		int Y = int.Parse(str[1]);
		int Z = int.Parse(str[2]);
		int n = (X - Z) / (Y + Z);
		Console.WriteLine(n);
	}
}

Measured memory_bytes: 13140
#include <stdio.h>
#include <stdlib.h>

typedef struct{
    int price;
    int num;
} store;

int sort(const void *a, const void *b)
{
    store *A = (store *)a;
    store *B = (store *)b;
    return A->price - B->price;
}

int main(void)
{
  int i, n, m;
  long long sum = 0;
  scanf("%d%d", &n, &m);
  store AB[n];

  for (i = 0; i < n; i++)
    scanf("%d%d", &AB[i].price, &AB[i].num);

  qsort(AB, n, sizeof(AB[0]), sort);

  i = 0;
  while (m > 0)
  {
    if (m <= AB[i].num)
    {
      sum += (long long)m * AB[i].price;
      break;
    }
    else
    {
      m -= AB[i].num;
      sum += (long long)AB[i].price * AB[i].num;
    }
    i++;
    }
    printf("%lld\n", sum);
    return 0;
}

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	set<string>s;
	string op, str;
	bool find[1000000];
	int fn = 0;

	int n;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> op >> str;
		if (op == "insert")
			s.insert(str);
		else if (op == "find")
		{
			if (s.count(str) == 0)
				find[fn] = false;
			else
				find[fn] = true;
			fn++;
		}
	}

	for (int i = 0; i < fn; i++)
	{
		if (find[i])
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}

	return 0;
}


Measured memory_bytes: 30240
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S,T;
  cin >> S >> T;
  
  vector<char> T2(2*S.size());
  for (int i=0;i<S.size();i++) {
    T2.at(i) = T.at(i);
    T2.at(i+S.size()) = T.at(i);
  }
  
  int match;
  for (int i=0;i<S.size();i++) {
    match=1;
    for (int j=0;j<S.size();j++) {
      if (T2.at(i+j) != S.at(j)) {
        match = 0;
        break;
      }
    }
    if (match == 1) {
      cout << "Yes" << endl;
      break;
    }
  }
  
  if (match == 0) {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

INF = 999999999999999999999999
MOD = 10**9+7

n,*A = get_all_int()

if min(A) == 0:
    print(0)
    exit()

ans = 1
for a in A:
    ans *= a

    if ans > 10**18:
        print(-1)
        exit()

print(ans)


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

int main(){
    while(1){
        int h,w ;
        cin >> h >> w ;
        if(h==w&&h==0) break ;
        bool hight,width ;
        hight = true ;
        for(int i=0;i<h;i++){
            width = hight ;
            for(int j=0;j<w;j++){
                if(width) cout << '#' ;
                else cout << '.' ;
                width = !width ;
            }
            cout << endl ;
            hight = !hight ;
        }
        cout << endl ;
    }
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int D, T, S;
  cin >> D >> T >> S;
  double A = (double)D / T;
  if (A <= S) {
  	cout << "Yes" << endl;
  } 
  else {
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b;
    cin >> a >> b;
    if( a + b == 15 ) cout << '+';
    else if( a * b == 15 ) cout << '*';
    else cout << 'x';
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]

fn main() {
    let (A, B, C): (i64, i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };

    let ans = if A % 2 == 0 || B % 2 == 0 || C % 2 == 0 {
        0
    } else {
        let mut x = vec![A, B, C];
        x.sort();
        x[0] * x[1]
    };

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
using namespace std;
typedef pair<ll,ll> AB;

int main(){
    int n,m;
    cin >> n >> m;
    ll ans = 0;
    vector<AB> vec(n);
    rep(i,n) {
        ll a,b;
        cin >> a >> b;
        vec[i].first = a;
        vec[i].second= b;
    }
    sort(all(vec));
    for(int i=0;i<n;i++){
        if (vec[i].second<=m){
            m -= vec[i].second;
            ans += vec[i].first * vec[i].second;
        }
        else {
            ans += vec[i].first * m;
            cout << ans << endl;
            return 0;
        }
        if (m==0) {
            cout << ans << endl;
            return 0;
        }
    }

}

Measured memory_bytes: 1792
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


def divisors(m: int):
    i = 1
    div = []
    while i * i <= m:
        if m % i == 0:
            div.append(i)
            div.append(m // i)
        i += 1

    return list(set(div))

n = ni()
a = list(li())
b = [0]*n
ans = []
for i in range(n-1, -1, -1):
    if a[i] != b[i]:
        divs = divisors(i+1)
        ans.append(i+1)
        for j in divs:
            b[j-1] += 1
            b[j-1] %= 2

print(len(ans))

if ans:
    print(*ans[::-1])


Measured memory_bytes: 71544
from collections import deque
N=int(input())
Sec=[]
Left1,Right1=[],[]
for i in range(N):
  l,r=map(int,input().split())
  Sec.append((l,r))
  Left1.append((l,i))
  Right1.append((r,i))
Left1.sort()
Right1.sort(reverse=True)
Left2=Left1[:]
Right2=Right1[:]
Used=[False]*N
pos=0
n=0
ans1=0
f_l,f_r=0,0
while Left1 or Right1:
  if n%2==0:
    if not Left1:
      n+=1
      continue
    l,i=Left1[-1]
    if Used[i]:
      Left1.pop()
      continue
    if pos<l:
      ans1+=l-pos
      pos=l
      Used[i]=True
      Left1.pop()
      f_l=0
    else:
      if f_l==1:
        Left1.pop()
        f_l=0
      else:
        f_l=1
    n+=1
  elif n%2==1:
    if not Right1:
      n+=1
      continue
    r,i=Right1[-1]
    if Used[i]:
      Right1.pop()
      continue
    if r<pos:
      ans1+=pos-r
      pos=r
      Used[i]=True
      Right1.pop()
      f_r=0
    else:
      if f_r==1:
        Right1.pop()
        f_r=0
      else:
        f_r=1
    n+=1
  
ans1+=abs(pos)
n=0
ans2=0
Used=[False]*N
f_l,f_r=0,9
pos=0
while Left2 or Right2:
  if n%2==1:
    if not Left2:
      n+=1
      continue
    l,i=Left2[-1]
    if Used[i]:
      Left2.pop()
      continue
    if pos<l:
      ans2+=l-pos
      pos=l
      Used[i]=True
      Left2.pop()
      f_l=0
    else:
      if f_l==1:
        Left2.pop()
        f_l=0
      else:
        f_l=1
    n+=1
  elif n%2==0:
    if not Right2:
      n+=1
      continue
    r,i=Right2[-1]
    if Used[i]:
      Right2.pop()
      continue
    if r<pos:
      ans2+=pos-r
      pos=r
      Used[i]=True
      Right2.pop()
      f_r=0
    else:
      if f_r==1:
        Right2.pop()
        f_r=0
      else:
        f_r=1
    n+=1
    
ans2+=abs(pos)
print(max(ans1,ans2))

Measured memory_bytes: 80856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

P f(int x) {
  int a = x%10;//末尾の位の数
  int b = 0;//先頭の位の数
  while(x){ //xが0以外なら繰りかえす（0は偽，それ以外は真になる）
    b=x;
    x /= 10;
  }
  return P(a,b);
}

int main() {
  int N;
  cin >> N ;
  map<P, int> freq;
  //mapは連想配列といって辞書のようなもの
  //今回はPの型をキーとしてint型の数値が返されるfreqという名前をつくった。
  for(int i = 1; i <= N; i++){
    P p = f(i);
    freq[p]++; 
    //はじめはなにも入力されてないのでカウント0からはじまる。
    //pには（a,b）のpairが入る
    //freq[p]には(1,1)の数,(2,2)の数,・・・が入る
  }
  ll ans = 0;
  //ansは膨大になる可能性があるためlong long型で
  for(int i = 1; i <= N; i++){
    P p = f(i);
    P q(p.second, p.first);
    ans += freq[q];
    /*(1,1)の数+(2,2)の数+・・・
    +(9,9)の数+(1,1)の数+(2,1)の数+・・・が入る*/
  }
  cout << ans << endl;
  return 0;//void型なら必要(戻り値を必要とする関数なら全部)
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(
			new InputStreamReader(System.in));
		try {
			double n = Double.parseDouble(br.readLine());
			if(n % 2 == 0) {
				System.out.println(String.format("%.7f", 1.0 / 2));
			} else {
				System.out.println(String.format("%.7f", ((n + 1) / 2) / n));
			}
			br.close();
		} catch(IOException e) {
			e.printStackTrace();
		}
	}
}


Measured memory_bytes: 23252
/*
 * ITP1_6_B.cpp
 *
 *  Created on: 2016/05/16
 *      Author: suna
 */

#include <iostream>
#include <vector>

using namespace std;

typedef struct Card
{
	char card_picture;	//??????????????????
	int card_val;		//??????????????°???
};

//????¶???????????????????????????????
void output_ShortageCard(char type, bool card[])
{
	for(int i = 0; i < 13; i++)
	{
		if(card[i] == false)
		{
			cout << type << " " << (i+1) << endl;
		}
	}
}

int main(void)
{
	//?????£???????????????????????°
	int card_num;

	//?????????????¨????????????????????????????
	bool card_Spade[13] = {false};
	bool card_Heart[13] = {false};
	bool card_Club[13] = {false};
	bool card_Dia[13] = {false};

	//?????£???????????????????????°?????\???
	cin >> card_num;
	vector<Card> HaveCard;

	//?????£??????????????????????¨?????????\???
	//?¨??????¨??°????????\???
	for(int i = 0; i < card_num; i++)
	{
		char picture;
		int value;
		Card tmp;
		cin >> picture >> value;
		tmp.card_picture = picture;
		tmp.card_val = value;

		HaveCard.push_back(tmp);
	}

	//???????????????????????????????????§????????????
	for(int i = 0; i < card_num; i++)
	{
		char picture;
		char value;
		picture = HaveCard[i].card_picture;
		value = HaveCard[i].card_val;

		if(picture == 'S')
		{
			card_Spade[value-1] = true;
		}
		else if(picture == 'H')
		{
			card_Heart[value-1] = true;
		}
		else if(picture == 'C')
		{
			card_Club[value-1] = true;
		}
		else if(picture == 'D')
		{
			card_Dia[value-1] = true;
		}
	}

	//????¶???????????????????????????????
	output_ShortageCard('S', card_Spade);
	output_ShortageCard('H', card_Heart);
	output_ShortageCard('C', card_Club);
	output_ShortageCard('D', card_Dia);

	return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};

int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    string s;
    cin>>s;
    if(s=="Sunny")
        s="Cloudy";
    else if(s=="Cloudy")
        s="Rainy";
    else
        s="Sunny";
    cout<<s<<endl;

    return 0;
}


Measured memory_bytes: 3588
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
#define N 100010
#define LL long long
int a[N];
vector<LL> q;
int main()
{
    int i,j,k,n,m;
    int x,y,z;
    LL d,t,s;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(i=1;i<=n;i++)
    {
        d=0;
        for(j=i;j<=n;j++)
        {
            d=d+a[j];
            q.push_back(d);
        }
    }
    s=0;
    for(i=40;i>=0;i--)
    {
        d=s|(LL)pow(2,i);
        k=0;
        for(j=0;j<n*(n+1)/2;j++)
        if((q[j]&d)==d)
            k++;
        if(k>=m)
            s=s+(LL)pow(2,i);
    }
    printf("%lld\n",s);
    return 0;
}


Measured memory_bytes: 6384
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;

int main(void)
{
    int n,m,k;
    cin >>n >>m >>k;

    vector<int> group(n, -1);
    vector<vector<int> > edge(n, vector<int>());
    vector<vector<int> > ng(n, vector<int>());
    for(int i = 0; i < m; i++){
        int a,b;
        cin >>a >>b;
        edge[a-1].push_back(b-1);
        edge[b-1].push_back(a-1);
    }
    for(int i = 0; i < k; i++){
        int c,d;
        cin >>c >>d;
        ng[c-1].push_back(d-1);
        ng[d-1].push_back(c-1);
    }

    map<int, int> colorCount;
    // 色塗り
    for(int i = 0; i < n; i++){
        if(group[i] != -1){
            continue;
        }
        queue<int> q;
        group[i] = i;
        q.push(i);
        colorCount[i] = 1;
        while(!q.empty()){
            int current = q.front();
            q.pop();
            for(int j = 0; j < edge[current].size(); j++){
                if(group[edge[current][j]] == -1){
                    group[edge[current][j]] = i;
                    colorCount[i]++;
                    q.push(edge[current][j]);
                }
            }
        }
    }

    bool first = true;
    for(int i = 0; i < n; i++){
        int res = colorCount[group[i]]-1-edge[i].size();
        for(int j = 0; j < ng[i].size(); j++){
            if(group[i] == group[ng[i][j]]){
                res--;
            }
        }
        if(first){
            printf("%d", res);
            first = false;
        }else{
            printf(" %d", res);
        }
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 12800
from collections import Counter
def ABC073C_WriteAndErase():
    N = int(input().strip())
    Ai = [int(input().strip()) for i in range(N)]


    Bi = Counter(Ai)
    count = 0
    for key, val in Bi.items():
        if val % 2 == 1:
            count += 1

    print(count)
    

def main():
    ABC073C_WriteAndErase()

if __name__ == "__main__":
    main()


Measured memory_bytes: 16548
#include<stdio.h>
#define TRUE 1
#define FALSE 0
#define N 20

int calc(int, int, int);

int a[N];

int main(){
  int n, q, m;
  int i;
  
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%d", &a[i]);
  }

  scanf("%d", &q);
  for(i=0;i<q;i++){
    scanf("%d", &m);
    if(calc(0, m, n) == TRUE) printf("yes\n");
    else printf("no\n");
  }
  
  return 0;
}

int calc(int i, int m, int n){
  if(m == 0) return TRUE;
  if(i >= n) return FALSE;

  if(calc(i+1, m, n) == TRUE || calc(i+1, m-a[i], n) == TRUE) return TRUE;
}



Measured memory_bytes: 2104
// https://atcoder.jp/contests/abc171/tasks/abc171_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    vector<int> v(N);
    for (auto &x : v) {
        cin >> x;
    }
    sort(ALL(v));
    cout << accumulate(v.begin(), v.begin() + K, 0LL) << endl;

    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll int arr[1<<18];
 int main()
{
   //#ifndef ONLINE_JUDGE
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  //#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll int n;
  cin>>n;
  

  ll int sum=0;
  for(ll int i=0;i<n;i++)
  {
  	cin>>arr[i];
  	sum=sum+arr[i];
  }
   ll int mini=sum;
  ll int x=0;
  for(int i=0;i<n;i++)
  {
  	x=x+arr[i];
  	mini=min(mini,abs(x-(sum-x)));
  }
  cout<<mini<<endl;
 
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    vector<int> time(5);
    vector<int> time_10(5);
    for(int i = 0; i < 5; i++){
        cin >> time[i];
        int tmp = time[i]%10;
        if(tmp) time_10[i] = time[i] + (10 - tmp);
        else time_10[i] = time[i];
    }
    int ans = INF;
    for(int i = 0; i < 5; i++){
        int cnt = 0;
        for(int j = 0; j < 5; j++){
            if(j == i) cnt += time[j];
            else cnt += time_10[j];
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
----
local DBG = false
local function dbgpr(...)
    if DBG then
        io.write("[dbg]")
        print(...)
    end
end

local function factorial(n)
    local a = 1
    for i=1, n do
        a = a * i
    end
    return a
end

-- C
local N = read.n()
local X, Y = {}, {}
for i=1,N do
    X[i], Y[i] = read.nn()
end

local route_num = factorial(N)
local edges_num = N * (N - 1) / 2
local not_use_edges = edges_num - N + 1
local in_use_edges = edges_num - not_use_edges
local prob = in_use_edges / edges_num
local use_count = prob * route_num

dbgpr("N", N, "R", route_num, edges_num, not_use_edges, "U", in_use_edges, prob, "C", use_count)

local sum = 0

for i=1,N do
    for j=1,N do
        if i ~= j then
            local d = math.sqrt((X[i]-X[j])^2 + (Y[i]-Y[j])^2)
            sum = sum + use_count * d
        end
    end
end

print(sum / route_num / 2)


Measured memory_bytes: 760
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  string s;
  cin>>s;
  if(s.sz==1){
    cout << 0 << endl;
    return 0;
  }
  ll n = s.sz;
  ll mn = 10000000;
  rep(i,0,26){
    char c = 'a'+i;
    string s1 = s;
    ll e = 0;
    rep(j,0,n-1){
      ll flag = 1;
      rep(k,0,s1.sz){
        if(s1[k]!=c)flag = 0;
      }
      if(flag == 1){
        mn = min(mn,e);
        break;
      }
      string s2;
      rep(k,0,s1.sz-1){
        if(s1[k]==c||s1[k+1]==c){
          s2 += ctos(c);
        }
        else{
          s2 += "+";
        }
      }
      s1 = s2;
      e++;
    }
  }
  cout << mn << endl;
  return 0;
}

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

int main(void){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int score=0,out=0;
		stack <int> base;
		while(out<3){
			string S;
			cin >> S;
			if(S=="HIT"){
				base.push(1);
				if(base.size()>=4)
					base.pop(),score++;
			}else if(S=="HOMERUN"){
				score++;
				while(!base.empty())
					score++,base.pop();
			}else if(S=="OUT")
				out++;
		}
		cout << score << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	
	int aki = a - b;
	if (aki >= c)cout << 0 << endl;
	else cout << c - aki << endl;
	return 0;
}

Measured memory_bytes: 256
a=input()
b=int(input())
s=""
zn=0
n=0
nn=0
i=0
aa=[]
ab=[]
abb=0
abc=0

for x in a:
    if aa==[]:
        n+=1
    elif x==s:
        n+=1
    elif x!=s:
        ab.append(n)
        n=1
    s=x
    i+=1
    aa.append(x)
    if i==len(a):
        ab.append(n)
if aa[0]==aa[-1] and len(ab)>2:
    if ab[-1]!=1:
        abb=ab[-1]
        del ab[-1]
    if ab[0]!=1:
        abc=ab[0]
        del ab[0]
    s=aa[0]
    i=0
    for x in aa:
        if aa[i]==s:
            nn+=1
        else:
            break
        i+=1
    i=1
    for x in aa:
        if aa[-i]==s:
            nn+=1
        else:
            break
        i+=1    
for x in ab:
    zn+=(x//2)
if len(a)==1:
    print(b//2)
elif len(ab)==1 and abb==0 and abc==0:
    print((b*ab[0])//2)
else:
    print(zn*b+(nn//2)*(b-1)+abb//2+abc//2)

Measured memory_bytes: 3064
#include<stdio.h>
int main(){

  int i,j,n;
  int flag=0,swap,count=0;
  int minj,data[100];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&data[i]);
  }
  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++){
      if(data[j]<data[minj]){
        flag=1;
	minj=j;
      }
    }
    if(flag==1){
      swap=data[i];
      data[i]=data[minj];
      data[minj]=swap;
      count++;
      flag=0;
    }
  }
  for(i=0;i<n;i++){
    if(i==n-1){
      printf("%d\n",data[i]);
    }
    else{
      printf("%d ",data[i]);
    }
  }
  printf("%d\n",count);
}



Measured memory_bytes: 2140
n,a,b = map(int, input().split(" "))
x = input().split(" ")
sum = 0
for i in range(n):
    x[i] = int(x[i])
for i in range(n-1):
    if a*(x[i+1]-x[i]) > b:
        sum += b
    else:
        sum += a*(x[i+1]-x[i])
print(sum)

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

typedef long long ll;
typedef long double ld;
typedef pair < int , pair < int , int > > mp;

#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
#define per(i , j , n) for(long long i = j ; i >= n ; i--)

const ll N = 123456;
const ld eps = 1e-6;
const ld pi = 3.1415926535;
const int MAX = 123456;
const ll mod = 1e9 + 7;

ll a[N];

ll dp[3333][3333];

ll DP(int t , int l , int r) {
	if(l > r) return 0;
	if(dp[l][r] != -1) return dp[l][r];
	ll temp;
	if(t == 1) {
		temp = DP(1 - t , l , r - 1) + a[r];
		temp = max(temp , DP(1 - t , l + 1 , r) + a[l]);
	}
	else {
		temp = DP(1 - t , l , r - 1) - a[r];
		temp = min(temp , DP(1 - t , l + 1 , r) - a[l]);
	}

	dp[l][r] = temp;
	return temp;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    cout << fixed << setprecision(12);

    int n;
    cin >> n;

    rep(i , 1 , n) cin >> a[i];

    rep(i , 1 , n) rep(j , 1 , n) dp[i][j] = -1;

    cout << DP(1 , 1 , n) << endl;

    return 0;
}


Measured memory_bytes: 80256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(S, s) S.find(s) != string::npos

int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    Rep(i, N) cin >> p[i];
    int ans = 0;
    Rep(i, N - 1) {
        if (p[i] == i + 1) {
            ans++;
            swap(p[i], p[i + 1]);
        }
    }
    if (p[N - 1] == N) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3780
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

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

  int N;
  std::cin >> N;

  std::vector<int> v(N, 0);

  std::vector<int> P(N, 0);
  std::vector<int> Q(N, 0);

  for (int i = 0; i < N; i++) {
    v[i] = i + 1;
    std::cin >> P[i];
  }

  for (int i = 0; i < N; i++) {
    std::cin >> Q[i];
  }

  int p, q;
  int i = 0;
  do {
    if (v == P) p = i;
    if (v == Q) q = i;
    i++;
  } while (next_permutation(v.begin(), v.end()));


  std::cout << std::abs(p - q) << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

ll dp[305];

int main()
{
//	cut here before submit 
//	freopen ("testcase.SC", "r", stdin );
	memset (dp, 0LL, sizeof (dp ) );
//	rep (j, 300 + 1 ){
	dp[0] = 1LL;

	for (int i = 1; i <= 17; i++ ){
		for (int j = 1; j <= 300; j++ ){
			if (j - i*i < 0 ) continue;
			dp[j] += dp[j - i*i];
		} // end for
	} // end for

	int n;
	while (scanf ("%d", &n ), n ){
		printf ("%ld\n", dp[n] );
	} // end loop
		
	return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include <string>
using namespace std;
 
int main(){
 
	int n;
	cin >> n;
	int h[n];
	for(int i=n-1;i>=0;i--){
		cin >> h[i];
	}
	for(int i=0;i<n-1;i++){
		if(h[i] >= h[i+1]){
			continue;
		}else if(h[i]+1 == h[i+1]){
			h[i+1]--;
			continue;
		}else{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
const ll MOD = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	
	cout << min(n * a, b);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
using ll = long long;
int main(){ 
    ll x;
    cin>>x;
    ll a=0,b;
    for(ll i=1;i<1000000000000000;i++){
        a+=i;
        if(a>=x){
            b=i;
            break;
        }
    }
    cout<<b;
    return 0;
}


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

typedef struct {
	char word[ 31 ];
	int page;
} Data;

Data data[ 100 ];

int compare( const void *a, const void *b ) {
	Data at = *(Data *)a, bt = *(Data *)b;

	if ( strcmp( at.word, bt.word ) < 0 )
		return -1;
	else if ( strcmp( at.word, bt.word ) > 0 )
		return 1;
	else
		return at.page - bt.page;
}

int main( void ) {
	int i, j;
	char word[ 31 ];
	int page, cnt;

	for ( cnt = 0; scanf( "%s %d", data[ cnt ].word, &data[ cnt ].page ) != EOF; cnt++ ) ;

	qsort( data, cnt, sizeof(Data), &compare );

	for ( i = 0; i < cnt; i += j ) {
		printf( "%s\n%d", data[ i ].word, data[ i ].page );
		for ( j = 1; i + j < cnt && !strcmp( data[ i + j ].word, data[ i ].word ); j++ )
			printf( " %d", data[ i + j ].page );
		putchar( '\n' );
	}

	return 0;
}

Measured memory_bytes: 664
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long

using namespace::std;

int jo(ll int jxo, ll int jyo){
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){
  return (toxbig-0x20);
}
char tolow(char toxlow){
  return (toxlow+0x20);
}
  


int main(){

  vector<int> a(3);
  rep(i,0,3) cin>>a[i];
  sort(a.begin(),a.end());
  cout<<a[0]+a[1];
  
  
}
// int *p = new int[N];

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <climits>

using namespace std;

int main(void)
{
    int tests;
    tests = 1;
    // cin >> tests;
    for(int test = 0;test < tests;test++)
    {
        int n, m;
        cin >> n >> m;
        int a[m][2];
        for(int i = 0;i < m;i++)
            cin >> a[i][0] >> a[i][1];
        vector <int > one, en;
        for(int i = 0;i < m;i++)
        {
            if(a[i][0] == 1)
                one.push_back(a[i][1]);
            else if(a[i][1] == n)
                en.push_back(a[i][0]);
        }
        sort(one.begin(), one.end());
        sort(en.begin(), en.end());
        int len = one.size();
        for(int i = 0;i < len;i++)
        {
            if(binary_search(en.begin(), en.end(), one[i]))
            {
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}


Measured memory_bytes: 2812
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>

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

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

const ll mod = 1000000007;
const int INF = 1<<29;

bool is_prime(ll N){
  if (N == 1) return false;
  for (int i = 2; i * i <= N; ++i){
    if (N % i == 0) return false;
  }
  return true;
}

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

  vector<bool> f(100001, false);
  vector<int> s(100001 + 1, 0);
  for (int i = 2; i < 100001; ++i) {
    if (is_prime(i)) if(is_prime((i + 1) / 2)) f[i] = true;
  }
  for (int i = 2; i < 100001 + 1; ++i){
    if (f[i]) s[i + 1] = s[i] + 1;
    else s[i + 1] = s[i];
  }

  for (int q = 0; q < Q; ++q){
    int l, r; cin >> l >> r;
    cout << s[r + 1] - s[l] << endl;
  }
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(100000)


class UnionFind:
    def __init__(self, n):
        super().__init__()
        self.par = [i for i in range(n + 1)]
        self.rank = [0 for i in range(n + 1)]

    def root(self, x):
        if self.par[x] == x:
            return x
        else:
            return self.root(self.par[x])

    def is_same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.par[x] = y
            elif self.rank[x] > self.rank[y]:
                self.par[y] = x
            else:
                self.par[x] = y
                self.rank[y] += 1


def distance(cell1, cell2):
    c_dis = 0
    for i in range(3):
        c_dis += (cell1[i] - cell2[i])**2
    c_dis = c_dis**(1 / 2) - (cell1[3] + cell2[3])
    return c_dis if c_dis > 0 else 0


while True:
    n = int(input())
    if n == 0:
        break
    union = UnionFind(n)
    cell_list = [list(map(float, input().split())) for i in range(n)]
    distance_list = []
    for i, b_cell in enumerate(cell_list):
        for j, cell in enumerate(cell_list[i + 1:]):
            distance_list.append([distance(b_cell, cell), i, i + 1 + j])

    distance_list.sort()
    total_dis = 0
    for dis in distance_list:
        if not union.is_same(dis[1], dis[2]):
            union.unite(dis[1], dis[2])
            total_dis += dis[0]

    print(format(total_dis, ".3f"))


Measured memory_bytes: 6552
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <sstream>
#include <vector>

using namespace std;

int main() {
  string s;
  int q;

  cin >> s >> q;

  vector<char> vec;
  copy(s.begin(), s.end(), back_inserter(vec));

  bool should_reverse = false;

  for (int i = 0; i < q; i++) {
    int t;
    cin >> t;

    if (t == 1) {
      should_reverse = !should_reverse;
    } else {
      int f;
      char c;
      cin >> f >> c;

      if ((f == 1 && should_reverse) || (f == 2 && !should_reverse)) {
        vec.push_back(c);
      } else {
        vec.insert(vec.begin(), c);
      }
    }
  }

  if (should_reverse) {
    reverse(vec.begin(), vec.end());
  }

  string res(vec.begin(), vec.end());

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<cmath>
#define _USE_MATH_DEFINES
#include<math.h>

using namespace std;

int main() {
	int dis, deg, theta=90;
	double x = 0, y = 0;
	char d;
	while (true) {
		cin >> dis >> d >> deg;
		if (dis == 0 && deg==0 ) {
			break;
		}
		else {
			x += dis * cos(theta*M_PI/180);
			y += dis * sin(theta*M_PI/180);
		}
		theta -= deg;


	}
	x = int(x);
	y = int(y);
	cout << x << endl;
	cout << y << endl;
}


Measured memory_bytes: 3552
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        StringTokenizer st = new StringTokenizer(br.readLine());
        int h0 = Integer.parseInt(st.nextToken());
        int h1 = Integer.parseInt(st.nextToken());
        if (n==2){
            System.out.println(Math.abs(h0-h1));
            return;
        }
        int h2=Integer.parseInt(st.nextToken());
        int[] prevHeight = new int[2];
        prevHeight[0]=h1;
        prevHeight[1]=h2;
        int[] prevMinCost = new int[2];
        prevMinCost[0]=Math.abs(h0-h1);
        prevMinCost[1]=Math.abs(h0-h2);

        while(st.hasMoreTokens()){
            int curr=Integer.parseInt(st.nextToken());
            int currMinCost=Math.min(prevMinCost[0]+Math.abs(prevHeight[0]-curr),
                    prevMinCost[1]+Math.abs(prevHeight[1]-curr));
            prevHeight[0]=prevHeight[1];
            prevHeight[1]=curr;
            prevMinCost[0]=prevMinCost[1];
            prevMinCost[1]=currMinCost;
        }
        System.out.println(prevMinCost[1]);
    }
}


Measured memory_bytes: 31412
import sys
from collections import defaultdict
n = int(sys.stdin.readline())
for i in range(n):
    s = list(sys.stdin.readline()[:-1])
    m = len(s)
    res = defaultdict(int)
    for i in range(1,m):
        k = s[:i]
        l = s[i:]
        k_ = k[::-1]
        l_ = l[::-1]
        res[tuple(k+l)] += 1
        res[tuple(k+l_)] += 1
        res[tuple(k_+l)] += 1
        res[tuple(k_+l_)] += 1
        res[tuple(l+k)] += 1
        res[tuple(l+k_)] += 1
        res[tuple(l_+k)] += 1
        res[tuple(l_+k_)] += 1
    print(len(list(res.keys())))



Measured memory_bytes: 6252
N = gets.chomp.to_i

fours = []
sevens = []
for i in 0..100 do
  fours << i if i % 4 == 0
  sevens << i if i % 7 == 0
end

totals = []
fours.each do |f|
  sevens.each do |s|
    totals << f + s if f + s <= 100 
  end
end

puts totals.include?(N) ? "Yes" : "No"


Measured memory_bytes: 1788
#include<iostream>
using namespace std;
int main(){
	int a,ans=0;
	cin>>a;
	int arr[a];
	for(int i=0;i<a;i++){
		cin>>arr[i];
	}
	for(int i=1;i<a-1;i++){
		if(arr[i]>arr[i+1]){
			if(arr[i]<arr[i-1]){
				ans++;
			}
		}
		else if(arr[i]<arr[i-1]){
			if(arr[i]>arr[i+1]){
				ans++;
			}
		}
		else if(arr[i]<arr[i+1]){
			if(arr[i]>arr[i-1]){
				ans++;
			}
		}
		else if(arr[i]>arr[i-1]){
			if(arr[i]<arr[i+1]){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  string s,t,a="maerd",b="remaerd",c="esare",d="resare";
  cin >> s;
  for(int i=s.size()-1; i>=0; i--) {
    t+=s[i];
    if(t==a||t==b||t==c||t==d) {
      t="";
    }
  }
  if(t.size()==0) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>


std::vector<int> primes(const int upper_limit) {
	std::vector<bool> is_prime(upper_limit + 1, true);
	for (auto i = 2; i * i <= upper_limit; ++i) {
		if (is_prime[i]) {
			for (auto j = i * i; j <= upper_limit; j += i) {
				is_prime[j] = false;
			}
		}
	}
	std::vector<int> result;
	for (auto i = 2; i <= upper_limit; ++i) {
		if (is_prime[i]) {
			result.push_back(i);
		}
	}
	return result;
}
int main() {
	const auto prime = primes(30000);
	while (true) {
		int n; std::cin >> n;
		if (n == 0) return 0;
		auto count = 0;
		auto greater = std::lower_bound(prime.begin(), prime.end(), n / 3);
		while (greater != prime.end() && *greater * 2 < n) {
			auto mid = std::lower_bound(prime.begin(), prime.end(), (n - *greater) / 2);
			while (*mid <= *greater) {
				if (n - *greater - *mid <= *mid && std::binary_search(prime.begin(), prime.end(), n - *greater - *mid)) {
					++count;
				}
				++mid;
			}
			++greater;
		}
		std::cout << count << std::endl;
	}
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline ll read() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
void fl(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
int main(){
	fast;
	ll n;
	cin>>n;
	ll a[n+1];
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}sort(a+1,a+n+1);
	ll flag=0;
	for(int i=2;i<=n;i++){
		if(a[i]==a[i-1]){
			flag=1;
			break;
		}
	}
	if(flag==0)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}/*『你强归你强，Siyuan比你强』*/





Measured memory_bytes: 1792