akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>

using namespace std;

int main() {
    int n, b, f, r, v, p[5][4][11];
    memset(p, 0, sizeof p);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> b >> f >> r >> v;
        p[b][f][r] += v;
    }
    for (int i = 1; i <= 4; i++) {
        for (int j = 1; j <= 3; j++) {
            for (int k = 1; k <= 10; k++) {
                cout << " " << p[i][j][k];
            }
            cout << endl;
        }
        if (i < 4) cout << "####################" << endl;
    }
    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;

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

	int res;
	if(n % (2 * d + 1) == 0) {;
		res = n / (2 * d + 1);
	} else {
		res = n / (2 * d + 1) + 1;
	}

	cout << res;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long ,long long>pll;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

 long long modpow(long long n, long long k,long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

void solve(){
    int n;cin >> n;
    int cnt = 0,ans = 0;
    for(int i = 0;i<n;i++){
        int a,b;cin >> a >> b;
        if(a==b) cnt++;
        else cnt = 0;
        ans = max(ans,cnt);
    }
    cout <<(ans>=3 ? "Yes" :"No");
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3580
while (line = gets)
  rpn = line.chomp.split(" ")

  stack = []

  for ch in rpn
    if /\d+/ =~ ch
      stack.push ch.to_f
    elsif ch == '+'
      n1 = stack.pop
      n0 = stack.pop
      stack.push n0 + n1
    elsif ch == '-'
      n1 = stack.pop
      n0 = stack.pop
      stack.push n0 - n1
    elsif ch == '*'
      n1 = stack.pop
      n0 = stack.pop
      stack.push n0 * n1
    elsif ch == '/'
      n1 = stack.pop
      n0 = stack.pop
      stack.push n0 / n1
    end
  end

  printf("%.6f\n", stack.pop)
end

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

int main(){
    int n;
    cin >> n;
    int ret = 1<<30;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= 100; i++){
        int tmp = 0;
        for(int j = 0; j < n; j++){
            tmp += (a[j]-i)*(a[j]-i);
        }
        ret = min(ret, tmp);
    }
    cout << ret << endl;
    return 0;
}

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

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            string line;
            while ((line = Console.ReadLine()) != null)
            {
                var n = line.Split(' ').Take(8).Select(double.Parse).ToArray();
                var a = new Rect(n[0], n[1], n[2], n[3]);
                var b = new Rect(n[4], n[5], n[6], n[7]);
                Console.WriteLine(Intersects(a, b) ? "YES" : "NO");
            }
        }

        static bool Intersects(Rect a, Rect b)
        {
            return a.X1 <= b.X2 && b.X1 <= a.X2 &&
                   a.Y1 <= b.Y2 && b.Y1 <= a.Y2;
        }

        class Rect
        {
            public double X1 { get; set; }
            public double Y1 { get; set; }
            public double X2 { get; set; }
            public double Y2 { get; set; }

            public Rect(double x1, double y1, double x2, double y2)
            {
                X1 = x1;
                Y1 = y1;
                X2 = x2;
                Y2 = y2;
            }
        }
    }
}

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


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

  string x;
  cin >> x;
  int s=0;
  int ans=x.size();
  rep(i,x.size()){
    if(x[i]=='S') s++;
    else if(s>0){
      s--;
      ans-=2;
    }
  }
  cout << ans << endl;
  
  return 0;
    

}


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

long double x[55],y[55];

long double get_dist(int i, int j){
    return (long double)(x[i]-x[j]) * (x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]);
}

pair<long double,long double> get_o(int i,int j,int k){
    long double A[2] = {x[i],y[i]}, B[2]={x[j],y[j]}, C[2]={x[k],y[k]};
    long double a = get_dist(k,j), b = get_dist(i,k), c = get_dist(i,j);
    long double p = a*(b+c-a), q=b*(c+a-b), r=c*(a+b-c);
    long double u[2];
    for(int t=0;t<2;t++){
        u[t] = p*A[t] + q*B[t] + r*C[t];
        u[t] /= (p+q+r);
    }
    return {u[0],u[1]};
}

long double get_rad(int ii,int j, int k, pair<long double,long double> o){
    long double r = 0;
    vector<int> v = {ii,j,k};
    for(auto i:v){
        r += (o.first-x[i])*(o.first-x[i]) + (o.second-y[i]) * (o.second-y[i]);
    }
    r /= 3;
    return r;
}

long double eps = 1e-6;

signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);

    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i];
    }
    long double ans = 1e9;
    // 3点選んでよしなにするやつ
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                pair<long double,long double> o = get_o(i,j,k);
                long double r = get_rad(i,j,k,o);
                x[n]=o.first, y[n]=o.second;
                //cerr << "a"<<endl;
                //cerr << i << " " << j << " " << k << " " << o.first << " " << o.second << " " << r << endl;
                bool pos = true;
                for(int u=0;u<n;u++){
                    long double dist = get_dist(u,n);
                    if(dist > r+eps){
                        pos = false;
                        break;
                    } 
                }
                if(pos) ans = min(ans, sqrt(r));
            }
        }
    }

    // 2ten erande yosi!
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            pair<long double, long double> o;
            o.first = (x[i] + x[j])/2.0;
            o.second = (y[i] + y[j])/2.0;
            x[n] = o.first, y[n] = o.second;
            long double r = get_dist(i,n) + get_dist(j,n);
            r /= 2.0;
            bool pos = true;
            for(int k=0;k<n;k++){
                long dist = get_dist(k,n);
                if(dist > r+eps){
                    pos = false;
                    break;
                }
            }
            if(pos) ans = min(ans,sqrt(r));
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
t = 0
for i in range(N + 1):
    t += abs(A[i] - A[i + 1])
for i in range(1, N + 1):
    if A[i - 1] <= A[i] <= A[i + 1] or A[i - 1] >= A[i] >= A[i + 1]:
        print(t)
    else:
        print(t - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1]) + abs(A[i - 1] - A[i + 1]))


Measured memory_bytes: 20632
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	s := Scan()
	ans := ""
	for _, r := range s {
		if string(r) == "0" {
			ans = ans + "0"
		} else if string(r) == "1" {
			ans = ans + "1"
		} else {
			if ans != "" {
				ans = ans[:len(ans)-1]
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1776
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
      solve();
  }
}

// 0 indexed
int n;
int bit[1000010];
void add(int a, int w) {
  for (int x = a; x < n; x |= x + 1) bit[x] += w;
}
int sum(int a) { // [0, a)
  int ret = 0;
  for (int x = a - 1; x >= 0; x = (x & (x + 1)) - 1) {
    ret += bit[x];
  }
  return ret;
}


// youtube editorial
void solve() {
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  vector<int> d = a;
  sort(all(d));

  map<int, int> mp;
  rep(i, n) mp[d[i]] = i;
  // for (auto e : mp) cout << e.F << " " << e.S << endl;

  int cnt = 0;
  rep(i, n) if (i % 2 != mp[a[i]] % 2) cnt++;
  cout << cnt / 2 << endl;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll MOD = 1e9 + 7;
ll H, N, M, L, K, W, X, Y, Z;
ll ans = 0;
int main() {
	int A, B;
	cin >> A >> B;
	if ((A*B) % 2)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int N;
int A[112345];

int main() {
	cin >> N;
	REP(i, N) scanf("%d", A + i);
	
	ll ans = 1;
	int p[3];
	memset(p, -1, sizeof(p));
	REP(i, N) {
		int c = 0, pos = -1;
		REP(j, 3) {
			if (A[i] == p[j] + 1) {
				c++;
				pos = j;
			}
		}
		if (pos == -1) {
			puts("0");
			return 0;
		}
		ans = ans * c % MOD;
		p[pos]++;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(4100000)

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)

from copy import copy

def resolve():
    N = [int(x) for x in sys.stdin.readline().split()][0]
    p_list = [int(x) for x in sys.stdin.readline().split()]

    

    is_broken = False
    old = p_list[0]
    for p in p_list[1:]:
        if old > p:
            is_broken = True
            break
        old = p

    if not is_broken:
        print("YES")
        return

    for i in range(N):
        for j in range(N):
            if i >= j:
                continue
            p_list_alt = copy(p_list)
            p_list_alt[i], p_list_alt[j] = p_list[j], p_list[i]

            is_broken = False
            old = p_list_alt[0]
            for p in p_list_alt[1:]:
                if old > p:
                    is_broken = True
                    break
                old = p

            if not is_broken:
                print("YES")
                return

    print("NO")

            
            

import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """5
5 2 3 4 1"""
        output = """YES"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """5
2 4 3 5 1"""
        output = """NO"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """7
1 2 3 4 5 6 7"""
        output = """YES"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """2
1 2"""
        output = """YES"""
        self.assertIO(input, output)
    def test_入力例_5(self):
        input = """2
2 1"""
        output = """YES"""
        self.assertIO(input, output)





if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる



Measured memory_bytes: 5680
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a,q,m;
    cin>>n;
    std::deque<int> deq;
    for (int i=0;i<n;i++) {
        cin>>a;
        deq.emplace_back(a);
    }
    std::map<int, int> map;
    for (int bit=0;bit<(1<<n);bit++) {
        int sum=0;
        for (int j=0;j<n;j++) {
            if (bit&(1<<j)) {
                sum+=deq[j];
            }
        }
        map[sum]++;
    }
    cin>>q;
    for (int i=0;i<q;i++) {
        cin>>m;
        if (map[m]!=0) {
            cout<<"yes"<<endl;
        } else {
            cout<<"no"<<endl;
        }
    }
}


Measured memory_bytes: 3128
#![allow(unused_imports)]
 
use proconio::{input, fastout};
use proconio::marker::*;
use std::collections::HashMap;
 
#[fastout]
fn main() {
  input! {
    n: usize,
    m: usize,
    vals: [(usize, usize);m],
  }
  let mut cities: Vec<Vec<usize>> = vec![vec![];n];
  for (i, year) in vals.iter() {
    cities[i-1].push(*year);
  }

  let mut result: HashMap<usize, usize> = HashMap::new();
  let mut index = 0;
  for i in 0..cities.len() {
    cities[i].sort();
    for (ii, v) in cities[i].iter().enumerate() {
      result.insert(*v, (i+1) * 1_000_000 + ii + 1);
    }
  }
  
  for (_, year) in vals {
    let v = result.get(&year).unwrap();
    println!("{:0>width$}", v.to_string(), width = 12); 
  }  
}

Measured memory_bytes: 13944
import java.util.Scanner;

public class Main {

	static int base =0;
	static int point =0;
	static int outs=0;

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int inning = scan.nextInt();
		int[] pointlog = new int[inning];
		String action;
		while(true){
			action = scan.next();
			if(action.equals("HIT")){
				basemove(1);
			}
			if(action.equals("HOMERUN")){
				basemove(2);
			}
			if(action.equals("OUT")){
				outs++;
				if(outs==3){
					outs=0;
					pointlog[pointlog.length-inning]=point;
					point=0;
					base=0;
					inning--;
					if(inning==0){
						for(int i=0; i<pointlog.length; i++)
							System.out.println(pointlog[i]);
						System.exit(0);
					}
				}
			}

		}

	}

	static void basemove(int state){
		//HIT
		if(state==1){
			base = base<<1;
			base++;
			if((base>>3)%2==1){
				base-=8;
				point++;
			}
		}
		//HOMERUN
		if(state==2){
			point+=(base>>2)%2+(base>>1)%2+(base>>0)%2+1;
			base=0;
		}
	}

}

Measured memory_bytes: 12000
import java.util.Scanner;
public class Main {
 public static void main(String[] args){
     Scanner scanner = new Scanner(System.in);
          int j = 0;
          int a = scanner.nextInt();
          int b = scanner.nextInt();
          int c = scanner.nextInt();
          for(int i=a;i<=b;i++){
              int x=c%i;
              if(x==0){
                   j++;
              }
          }      
        System.out.println(j);      
}
}

Measured memory_bytes: 26356
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>

int main() {
	long long n, r;

	std::cin >> n >> r;

	if (n == r) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <stack>
#include <math.h>

using namespace std;

#define T 800

int main(int argc, char const *argv[])
{
	int N,M;
	int r;
	int t,n,m,s;
	int q;
	int ts,te;
	int ans;

	while(1){
		cin>>N>>M;
		if(N+M==0) break;

		map<int,vector<int> > lio;

		for(int i1=0;i1<M;i1++){
			vector<int> v(T);
			fill(v.begin(), v.end(),0);
			lio[i1]=v;
		}

		cin>>r;
		for(int i1=0;i1<r;i1++){
			cin>>t>>n>>m>>s;
			vector<int> v=lio[m-1];
			if(s==1) {
				v[t-540]+=1;
			}
			else if(s==0) v[t-540]+=-1;
			lio[m-1]=v;
			
		}


		for(int i1=0;i1<M;i1++){
			vector<int> v=lio[i1];
			for(int i2=1;i2<T;i2++){
				v[i2]=v[i2-1]+v[i2];
			}
			lio[i1]=v;
		}

		cin>>q;
		for(int i1=0;i1<q;i1++){
			cin>>ts>>te>>m;

			vector<int> v=lio[m-1];
			ans=0;
			for(int i2=ts-540;i2<te-540;i2++){
				if(v[i2]>0) {
					ans++;
					//cout<<i2<<" "<<v[i2]<<" ";
				}
			}
			cout<<ans<<endl;
		}



	}
	return 0;
}

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define LOOP(i, N) for (int i = 1; i <= (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define RLOOP(i, N) for (int i =(int)N; i > 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define pb push_back

typedef long long ll;

typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
//cout<<"Yes"<<endl;
//cout<<"No"<<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;}

int main(){
    int a;
    cin>>a;
    a=a*a+a*a*a+a;
    cout<<a<<endl;
}


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

void ioThings() {
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("err.txt", "w", stderr);
#endif
}

using   ll        = long long;
#define debug(x)    cerr << #x << ": <" << x << ">\n"
#define dotc()      int tcs; if (cin >> tcs) for (int tc = 0; tc < tcs; tc++)
#define sz(x)       (int)x.size()
#define eb          emplace_back
#define pb          push_back
#define all(x)      x.begin(), x.end()
#define rall(x)     x.rbegin(), x.rend()
#define fi          first
#define se          second
#define mod         1000000007

int main() {
    ioThings();

    int n; cin >> n;
    set<int> a;
    while (n--) {
        int m; cin >> m;
        if (a.count(m)) {
            cout << "NO";
            return 0;
        }
        a.insert(m);
    }

    cout << "YES";

    return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;



int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ios_base& scientific (ios_base& str);
ll n;
cin >> n;
float arr[n];
for(int i =0; i<n; i++){
	cin >> arr[i];
}

sort(arr, arr+n);
float ans = (arr[0]+arr[1])/2;
for(int i =2; i<n; i++){
	ans = (ans+arr[i])/2;
}
cout << ans << endl;
return 0;
}



Measured memory_bytes: 256
use proconio::{input, marker::Chars};
use std::collections::VecDeque;

fn main() {
	input! {
		h: isize, w: isize,
		mut field: [Chars; h],
	}

	let mut white_count = 0;
	for line in &field {
		for &c in line {
			if c == '.' { white_count += 1 };
		}
	}

	let mut deque = VecDeque::new();
	deque.push_back((0, 0, 1));
	field[0][0] = '#';
	while let Some((i, j, cost)) = deque.pop_front() {
		if i == h-1 && j == w-1 {
			println!("{}", white_count - cost);
			return;
		}
		for &(di, dj) in [(-1, 0), (0, -1), (1, 0), (0, 1)].iter() {
			let (i1, j1) = (i+di, j+dj);
			if i1 < 0 || j1 < 0 || i1 >= h || j1 >= w { continue };
			if field[i1 as usize][j1 as usize] == '.' {
				field[i1 as usize][j1 as usize] = '#';
				deque.push_back((i1, j1, cost+1));
			}
		}
	}
	println!("{}", -1);
}

Measured memory_bytes: 2136
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll N, A[16] = {}, x[16][15] = {}, y[16][15] = {}, ans = 0;
bool flag = true;

int DFS(ll person,vector<ll> honest) {
	if (person != N) {
		honest[person + 1] = 0;
		DFS(person + 1, honest);
		honest[person + 1] = 1;
		DFS(person + 1, honest);
	}
	else {
		for (int i = 1; i <= N; i++) {
			if (honest[i]) {
				for (int j = 1; j <= A[i]; j++) {
					if (y[i][j] != honest[x[i][j]])return 0;
				}
			}
		}
		ll box = 0;
		for (int i = 1; i <= N; i++) {
			if (honest[i])box++;
		}
		ans = max(ans, box);
	}
}

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		for (int j = 1; j <= A[i]; j++) {
			cin >> x[i][j] >> y[i][j];
		}
	}
	vector<ll> box(N + 1);
	DFS(0, box);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())

#import numpy as np
#arr=np.array([a,b,c,d,e])
#botne=np.argmin(arr)+1
#botne_num=np.min(arr)
botne_num=min([a,b,c,d,e])
if botne_num==1:
  print(4+N//botne_num)
else:
  print(5 + N//botne_num)

Measured memory_bytes: 3064
n = int(input())
a = [0]*n
b = [0]*n

for i in range(n):
    a[i],b[i] = map(int,input().split())

c = 0

for i in range(n):
    for j in range(n):
        c += ((a[j]-a[i])**2 + (b[i]-b[j])**2)**0.5
print(c/n)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define pi 3.141592653589793238
using namespace std;
long double r;
int main(){
	cin>>r;
	cout<<r*2*pi<<endl;
	return 0;
}

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

namespace AtCoder.Contests.ABC169
{
    /// <summary>
    /// 
    /// </summary>
    static class B
    {
        static void Main(string[] args)
        {
            var n = NextInt();
            var aas = ReadLongArray();

            long max = 1_000_000_000_000_000_000;
            long sum = 1;

            if (aas.Contains(0))
            {
                Console.WriteLine(0);
                return;
            }

            for (int i = 0; i < n; i++)
            {
                var a = aas[i];
                if (sum * a > max || sum * a < sum)
                {
                    Console.WriteLine(-1);
                    return;
                }
                sum *= a;
            }
            Console.WriteLine(sum);
        }

        #region Console
        static int _index = 0;
        static string[] _buffer;

        static string Next()
        {
            if (_buffer == null || _index >= _buffer.Length)
            {
                _buffer = Console.ReadLine().Split();
                _index = 0;
            }

            return _buffer[_index++];
        }
        static int NextInt()
        {
            return int.Parse(Next());
        }
        static long NextLong()
        {
            return long.Parse(Next());
        }
        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        static int[] ReadIntArray(int n)
        {
            var a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadInt();
            }
            return a;
        }
        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        static long[] ReadLongArray(int n)
        {
            var a = new long[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadLong();
            }
            return a;
        }
        static List<T> ReadObjects<T>(int n, Func<int[], T> creator)
        {
            var l = new List<T>(n);

            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                l.Add(creator(a));
            }

            return l;
        }

        static int[,] ReadMatrix(int n, int m)
        {
            var r = new int[n, m];
            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                for (int j = 0; j < m; j++)
                {
                    r[i, j] = a[j];
                }
            }
            return r;
        }
        #endregion
    }
}


Measured memory_bytes: 41500
#include <bits/stdc++.h>
#define N 500050
#define INF (1<<29)

#define mid ((l+r)>>1)
#define ls l,mid,t<<1
#define rs mid+1,r,t<<1^1

using namespace std;
inline int rd() {
    int x=0,f=1;char ch=getchar();
    while (ch>'9'||ch<'0') {if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    return x*f;
}

priority_queue<int, vector<int>, greater<int> >q;
int n,k,e[N],a[N],p[N],d[N];
int x,ll,rr,res;
int tr[4*N];
vector<int> E[N];

void query(int l,int r,int t) {
    if (!tr[t]) return ;
    if (l >= ll && r <= rr) {
        if (res == 0 || p[ tr[t] ] < p[res] )
            res = tr[t];
        return ;
    }
    if (ll <= mid) query(ls);
    if (rr > mid) query(rs);
}

void update(int l,int r,int t) {
    if (l > x || r < x) return ;
    if (l == r) {tr[t] = x; return ;}
    update(ls), update(rs);
    if (p[tr[t<<1]] < p[tr[t<<1^1]])
        tr[t] = tr[t<<1];
    else
        tr[t] = tr[t<<1^1];
}


bool cmp(int p1,int p2) {return p[p1] < p[p2];}
int main() {
    n = rd(), k = rd();
    for (int _=1;_<=n;_++) p[_] = rd();
    p[0] = INF;

    for (int _=1;_<=n;_++) e[_] = _;
    sort(e+1,e+n+1,cmp);

    for (int _=n;_>=1;_--) {
        x = e[_];

        ll = x - k + 1, rr = x, res = 0;
        query(1,n,1);
        if (res)
            E[x].push_back(res), d[res]++;

        ll = x, rr = x + k - 1, res = 0;
        query(1,n,1);
        if (res)
            E[x].push_back(res), d[res]++;

        update(1,n,1);
    }

    for (int _=1;_<=n;_++) if (!d[_]) q.push(_);
    for (int _=1;_<=n;_++) {
        int x = q.top(); q.pop();
        a[x] = _;
        for (int i=0;i<(int)E[x].size();i++)
            if (--d[ E[x][i] ]==0) q.push(E[x][i]);
    }

    for (int _=1;_<=n;_++) printf("%d\n",a[_]);
    return 0;
}

Measured memory_bytes: 44416
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)2e9 + 1;
const long long LINF = (long long)9e18 + 1;

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

  int N;
  cin >> N;
  vector<int> seq(N);
  for (int i = 0; i < N - 1; i++) {
    cin >> seq[i];
  }
  seq[N - 1] = INF;

  int ans = seq[0];
  for (int i = 0; i < N - 1; i++) {
    ans += min(seq[i], seq[i + 1]);
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
// Problem : C - Repsept
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")  // disable
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define lll __int128
#define lp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define vec(v, type, sz) vector<type> v(sz)
#define in(v) \
    for (auto &i : v) cin >> i
#define all(v) v.begin(), v.end()
#define prv(v)                         \
    for (auto i : v) cout << i << " "; \
    cout << "\n"
#define MOD 1000000007
#define INF 1000000000
#define INFL 1000000000000000000ll
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vii(v, n, m, val) vector<vector<int>> v(n, vector<int>(m, val))
#define viii(v, i, j, k, val)        \
    vector<vector<vector<int>>> v(i, \
                                  vector<vector<int>>(j, vector<int>(k, val)))
#define pii pair<int, int>
#define pb push_back
#define tos(x) string(1,x)
#define file_io                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define testc   \
    int tcc;    \
    cin >> tcc; \
    for (int tc = 1; tc <= tcc; tc++)
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while (!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
    cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if (idx > 0)
        cerr << ", ";
    else
        cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss;
    ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef DB
#define debug(...) \
    debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
#define int ll

signed main() {
	fast_io;
	int k; cin>>k;
	if(k%2==0 || k%5==0){
		cout<<-1;
		return 0;
	}
	int rem=7,power=7,ans=1;
	while (rem % k != 0) { 
        ans++;
        power = power * 10 % k; 
        rem = (rem + power) % k; 
    } 
    cout<<ans; 
}
// code!=think
// least efficient code to get ac


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int n,a[100000];
	cin>>n;
	for (int i = 1; i <= n; i++){
		cin>>a[i];
	}
	int btn=1,count=0;
	while(1){
		if(btn==2){
			cout<<count<<endl;
			return 0;
		}
		btn=a[btn];
		count++;
		if(count>n+1){
			cout<<-1<<endl;
			return 0;
		}
	}

}



Measured memory_bytes: 640
public class Main {
	public static void main(String args[]){
		System.out.println("1x1=1");
		System.out.println("1x2=2");
		System.out.println("1x3=3");
		System.out.println("1x4=4");
		System.out.println("1x5=5");
		System.out.println("1x6=6");
		System.out.println("1x7=7");
		System.out.println("1x8=8");
		System.out.println("1x9=9");
		System.out.println("2x1=2");
		System.out.println("2x2=4");
		System.out.println("2x3=6");
		System.out.println("2x4=8");
		System.out.println("2x5=10");
		System.out.println("2x6=12");
		System.out.println("2x7=14");
		System.out.println("2x8=16");
		System.out.println("2x9=18");
		System.out.println("3x1=3");
		System.out.println("3x2=6");
		System.out.println("3x3=9");
		System.out.println("3x4=12");
		System.out.println("3x5=15");
		System.out.println("3x6=18");
		System.out.println("3x7=21");
		System.out.println("3x8=24");
		System.out.println("3x9=27");
		System.out.println("4x1=4");
		System.out.println("4x2=8");
		System.out.println("4x3=12");
		System.out.println("4x4=16");
		System.out.println("4x5=20");
		System.out.println("4x6=24");
		System.out.println("4x7=28");
		System.out.println("4x8=32");
		System.out.println("4x9=36");
		System.out.println("5x1=5");
		System.out.println("5x2=10");
		System.out.println("5x3=15");
		System.out.println("5x4=20");
		System.out.println("5x5=25");
		System.out.println("5x6=30");
		System.out.println("5x7=35");
		System.out.println("5x8=40");
		System.out.println("5x9=45");
		System.out.println("6x1=6");
		System.out.println("6x2=12");
		System.out.println("6x3=18");
		System.out.println("6x4=24");
		System.out.println("6x5=30");
		System.out.println("6x6=36");
		System.out.println("6x7=42");
		System.out.println("6x8=48");
		System.out.println("6x9=54");
		System.out.println("7x1=7");
		System.out.println("7x2=14");
		System.out.println("7x3=21");
		System.out.println("7x4=28");
		System.out.println("7x5=35");
		System.out.println("7x6=42");
		System.out.println("7x7=49");
		System.out.println("7x8=56");
		System.out.println("7x9=63");
		System.out.println("8x1=8");
		System.out.println("8x2=16");
		System.out.println("8x3=24");
		System.out.println("8x4=32");
		System.out.println("8x5=40");
		System.out.println("8x6=48");
		System.out.println("8x7=56");
		System.out.println("8x8=64");
		System.out.println("8x9=72");
		System.out.println("9x1=9");
		System.out.println("9x2=18");
		System.out.println("9x3=27");
		System.out.println("9x4=36");
		System.out.println("9x5=45");
		System.out.println("9x6=54");
		System.out.println("9x7=63");
		System.out.println("9x8=72");
		System.out.println("9x9=81");
	}
}

Measured memory_bytes: 16848
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define loop(k) rep(author_is_masa,k)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/

signed main(){
	int a,b;
	cin>>a>>b;
	int ans=0;
	loop(2){
		if(a>b){
			ans+=a;
			a--;
		}else{
			ans+=b;
			b--;
		}
	}
	cout<<ans<<endl;


	return 0;
}



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

int main() {
    int n;
    cin >> n;
    double b = 0;
    rep(i,n) {
        double a = 0;
        cin >> a;
        b+=1.00/a;
    }
    cout << setprecision(7) << 1/b << endl;

    return 0;
}

Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)
Xs, Ys = readlines.map{|l| l.split.map(&:to_i)}
MOD = (1E9 + 7).to_i

xs = (1 .. N).inject(0){|s, i| (s + (2*i - N - 1) * Xs[i - 1]) % MOD}
ys = (1 .. M).inject(0){|s, i| (s + (2*i - M - 1) * Ys[i - 1]) % MOD}
puts xs * ys % MOD

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

int main()
{
  string st;
  cin >> st;
  int price= 700;
  for (size_t i = 0; i < sizeof(st); i++) {

    if(st[i]=='o')
    {
      price=price+100;
    }
  }
  cout << price;

  return 0;
}


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




using namespace std;

const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;

#define DEBUG

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif

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

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


class UnionFind{
    public:
    vector<int> par;
    vector<int> val;
    int root(int input){
        if(par[input]==input) return input;
        return par[input] = root(par[input]);
    }
    void unite(int val1, int val2){
        par[val1] = root(par[val2]);
    }
    bool same(int val1, int val2){
        return root(par[val1]) == root(par[val2]);
    }
    UnionFind(){
        return;
    }
};

ll X,M;

signed main() {
    
    string S,T; cin >> S >>T;
    bool ret = true;
    rep(i, S.length()){
        if(S[i] != T[i]){
            ret = false;
        }
    }
    if(S.length()+1 != T.length()){
        ret = false;
    }
    if(ret){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    ll n; cin >> n;
    vector<ll> a(5);
    ll mi = INF;
    rep(i, 5) cin >> a[i], mi = min(mi, a[i]);
    cout << (n + mi - 1) / mi + 4 << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cassert>
using namespace std;
const long long INF = (1e18);

int main(){
  int N;
  while(cin >> N, N){
    map< pair<long long, long long>, long long > F;
    map< long long, vector< pair<long long, long long> > > M;
    F[{-INF,0}] = -1;
    for(int i = 0; i < N; ++i){
      char c;
      cin >> c;
      if(c == 'W'){
        long long l, s, r = 0;
        cin >> l >> s;
        vector< pair<long long, long long> > V;
        for(auto itr = F.begin(); itr != F.end(); ++itr){
          r = max(r, itr->first.second);
          auto itr_ = itr;
          ++itr_;
          if(itr_ == F.end()) continue;
          if(itr_->first.first != itr->first.second){
            long long n = min(s, itr_->first.first - itr->first.second);
            s -= n;
            V.emplace_back(itr->first.second,itr->first.second+n);
            if(!s) break;
          }
        }
        if(s){
          V.emplace_back(r,r+s);
        }
        for(int j = 0; j < (int)V.size(); ++j){
          F[V.at(j)] = l;
          M[l].push_back(V.at(j));
        }

        sort(M[l].begin(), M[l].end());
        V = {};
        long long x = -2, y = -1;
        for(int j = 0; j < (int)M[l].size(); ++j){
          if(y == M[l].at(j).first){
            F.erase(F.find({x,y}));
            F.erase(F.find(M[l].at(j)));
            y = M[l].at(j).second;
            F[{x,y}] = l;
            V.pop_back();
            V.emplace_back(x,y);
          }else{
            x = M[l].at(j).first;
            y = M[l].at(j).second;
            V.emplace_back(x,y);
          }
        }
        M[l] = V;
        
      }else if(c == 'D'){
        long long l;
        cin >> l;
        for(int j = 0; j < (int)M[l].size(); ++j) F.erase(F.find(M[l].at(j)));
        M[l] = {};
      }else{
        long long p;
        cin >> p;
        auto itr = F.upper_bound({p,INF});
        //cout << itr->first.first << " " << itr->first.second << " " << itr->second << endl;
        assert(itr != F.begin());
        --itr;
        if(itr->first.second <= p) cout << -1 << endl;
        else cout << itr->second << endl;
      }
      //for(auto itr = F.begin(); itr != F.end(); ++itr) cout << "[" << itr->first.first << ", " << itr->first.second << ") =  " << itr->second << endl;
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 35772
N, A, B, C = gets.strip.split.map(&:to_i)
T = [A, B, C]
L = N.times.map { gets.to_i }
INF = 10 ** 9

def solve(index, t)
  if index == N
    if t.min > 0
      return 3.times.map { |i| (T[i] - t[i]).abs }
        .reduce(:+) - 30
    else
      return INF
    end
  end
  tmp = []
  tmp.push(solve(index + 1, [t[0], t[1], t[2]]))
  3.times do |i|
    next_t = 3.times.map do |j|
      # i: 足すところ
      if i == j
        t[j] + L[index]
      else
        t[j]
      end
    end
    tmp.push(solve(index + 1, next_t) + 10)
  end
  tmp.min
end

puts solve(0, 3.times.map{0})


Measured memory_bytes: 2044
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
long double x[2000], y[2000], z[2000], r[2000], a[15], b[15], c[15], d[15], g[15], X, Y, Z; int n, m, p;
vector<int>e[15];
long double dst(long double ax, long double ay, long double az, long double bx, long double by, long double bz) {
	return sqrtl((ax - bx)*(ax - bx) + (ay - by)*(ay - by) + (az - bz)*(az - bz));
}
long double solve(long double ax, long double ay, long double az, long double bx, long double by, long double bz, long double fx, long double fy, long double fz) {
	long double L = (long double)0, R = (long double)1, c1, c2, ret = 1e18;
	long double vx = bx - ax, vy = by - ay, vz = bz - az;
	for (int i = 0; i < 70; i++) {
		c1 = (L + L + R) / 3.0l, c2 = (L + R + R) / 3.0l;
		long double cx = ax + vx*c1, cy = ay + vy*c1, cz = az + vz*c1;
		long double dx = ax + vx*c2, dy = ay + vy*c2, dz = az + vz*c2;
		long double e1 = dst(fx, fy, fz, cx, cy, cz);
		long double e2 = dst(fx, fy, fz, dx, dy, dz);
		if (e1 < e2) { R = c2; }if (e1 > e2) { L = c1; }
		ret = min(ret, min(e1, e2));
	}
	//cout << ax << ' ' << ay << ' ' << az << ' ' << bx << ' ' << by << ' ' << bz << ' ' << fx << ' ' << fy << ' ' << fz << ' ' << ret << endl;
	return ret;
}
int main() {
	while (true) {
		cin >> n >> m >> p; for (int i = 0; i < m; i++)e[i].clear(); if (n + m + p == 0)break;
		for (int i = 0; i < n; i++) { cin >> x[i] >> y[i] >> z[i] >> r[i]; }
		for (int i = 0; i < m; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; }
		cin >> X >> Y >> Z;
		for (int i = 0; i < m; i++) { g[i] = d[i] / pow(dst(X, Y, Z, a[i], b[i], c[i]), 2.0l); }
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				if (solve(X, Y, Z, a[i], b[i], c[i], x[j], y[j], z[j]) <= r[j]) {
					if (dst(X, Y, Z, x[j], y[j], z[j]) <= r[j] && dst(a[i], b[i], c[i], x[j], y[j], z[j]) <= r[j])continue;
					e[i].push_back(j);
				}
			}
		}
		long double maxn = 0.0l;
		for (int i = 0; i < (1 << m); i++) {
			bool used[2000]; for (int j = 0; j < n; j++)used[j] = false;
			for (int j = 0; j < m; j++) {
				if ((i / (1 << j)) % 2 == 0)continue;
				for (int k : e[j])used[k] = true;
			}
			int cnt = 0; for (int j = 0; j < n; j++)cnt += used[j];
			if (cnt <= p) {
				long double w = 0; for (int j = 0; j < m; j++) { if ((i / (1 << j)) % 2 == 1)w += g[j]; }
				maxn = max(maxn, w);
			}
		}
		printf("%.12Lf\n", maxn);
	}
	return 0;
}

Measured memory_bytes: 3412
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
const int maxn=1e6+10;
const int t=1e6+5e5;
int n,x,y,l,r,dis[510][510],dx[5],dy[5];
bool f[510][510];
struct da{int x,y;}q[3*maxn];
long long ans;
inline bool ok(int x,int y)
{
	if (x>=1 && x<=n && y>=1 && y<=n) return 1;
return 0;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) 
	 for (int j=1;j<=n;j++) 
	 {
	 	dis[i][j]=i-1;
	 	dis[i][j]=min(dis[i][j],j-1);
	 	dis[i][j]=min(dis[i][j],n-i);
	 	dis[i][j]=min(dis[i][j],n-j);
	 	f[i][j]=1;
	 }
	//for (int i=1;i<=n;i++,printf("\n"))
	 //for (int j=1;j<=n;j++) printf("%d ",dis[i][j]);
	dx[0]=1; dy[0]=0; dx[1]=-1; dy[1]=0;
	dx[2]=0; dy[2]=1; dx[3]=0; dy[3]=-1;
	for (int i=1;i<=n*n;i++)
	{
		int k; scanf("%d",&k);
		x=(k-1)/n+1; y=(k%n==0?n:k%n); ans+=dis[x][y]; f[x][y]=0;
		//printf("%d %d\n",x,y);
		l=r=t; q[l]={x,y};
		while (l<=r)
		{
			//printf("lala %d\n",i);
			da now=q[l++];
			for (int j=0;j<4;j++) 
			if (ok(now.x+dx[j],now.y+dy[j]) && dis[now.x+dx[j]][now.y+dy[j]]>dis[now.x][now.y]+f[now.x][now.y])
			{
				dis[now.x+dx[j]][now.y+dy[j]]=dis[now.x][now.y]+f[now.x][now.y];
				if (f[now.x][now.y]) q[++r]={now.x+dx[j],now.y+dy[j]};
				else q[--l]={now.x+dx[j],now.y+dy[j]};
			}
		}
	}
	printf("%lld\n",ans);
return 0;
}

Measured memory_bytes: 5936
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Aoj.ALDS.Chapter4B
{
    class Program
    {
        /// <summary>
        /// ????????¢?´¢?????? list??????value??????????????¢??????
        /// ????????????????????´??????-1????????????
        /// </summary>
        public static int BinarySearch<T>(List<T> list, T value) where T : IComparable<T>
        {
            int left = 0;
            int right = list.Count;

            while (left < right)
            {
                int mid = (left + right) / 2;
                int compare = value.CompareTo(list[mid]);
                if (compare == 0)
                    return mid;
                else if (compare < 0)
                    right = mid;
                else
                    left = mid + 1;
            }

            return -1;
        }

        public static void Solve()
        {
            //int n = int.Parse(Console.ReadLine());
            Console.ReadLine();
            var list1 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse).ToList();
            int q = int.Parse(Console.ReadLine());
            var list2 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse).ToList();

            int counter = 0;
            for (int i = 0; i < q; i++)
            {
                if (BinarySearch(list1, list2[i]) >= 0)
                {
                    counter++;
                }
            }

            Console.WriteLine(counter);
        }

        public static void Main()
        {
            // Console.SetIn(new System.IO.StreamReader("Aoj/AlgorithmsAndDataStructures/Input/04_Search_B_01.txt"));
            // var sw = new Stopwatch();
            // sw.Start();

            Solve();

            // Console.WriteLine("{0}ms", sw.ElapsedMilliseconds);
        }
    }
}

Measured memory_bytes: 22216