#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ Insert(int *, int);
int /*<<< orphan*/ Sort(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int sum = 0;
  scanf("%d", &sum);
  int *ropes = (int *)malloc(sum * sizeof(int));
  for (int i = 0; i < sum; ++i) {
    scanf("%d", &ropes[i]);
  }
  Sort(ropes, 0, sum - 1);
  for (int i = sum - 1; i > 0; --i) {
    ropes[i - 1] = (ropes[i - 1] + ropes[i]) / 2;
    Insert(ropes, i - 1);
  }
  printf("%d\n", ropes[0]);
  free(ropes);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xe83(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1080 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d5 <main+0x75>
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe3e(%rip),%rdi
call   1080 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a0 <main+0x40>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1040 <Sort@plt>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    124b <main+0xeb>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rdx
add    (%rcx,%rdx,4),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
sub    $0x1,%esi
call   1060 <Insert@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    11ef <main+0x8f>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xdab(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
lea    0xe8a(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
mov    0x4(%rsp),%edi
shl    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    0x4(%rsp),%edx
test   %edx,%edx
jle    11cd <main+0x6d>
xor    %ebp,%ebp
lea    0xe60(%rip),%r15
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
add    $0x1,%rbp
movslq 0x4(%rsp),%rdx
add    $0x4,%rbx
cmp    %rdx,%rbp
jl     11b0 <main+0x50>
add    $0xffffffff,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <Sort@plt>
mov    0x4(%rsp),%ebx
cmp    $0x2,%ebx
jl     1221 <main+0xc1>
lea    -0x2(%rbx),%ebp
add    $0x1,%rbx
nopw   0x0(%rax,%rax,1)
lea    -0x2(%rbx),%eax
mov    %ebp,%ecx
mov    (%r14,%rax,4),%eax
add    (%r14,%rcx,4),%eax
mov    %eax,%edx
shr    $0x1f,%edx
add    %eax,%edx
sar    %edx
mov    %edx,(%r14,%rcx,4)
mov    %r14,%rdi
mov    %ebp,%esi
call   1060 <Insert@plt>
add    $0xffffffff,%ebp
add    $0xffffffffffffffff,%rbx
cmp    $0x2,%rbx
ja     11f0 <main+0x90>
mov    (%r14),%esi
lea    0xdd8(%rip),%rdi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 4
%10 = trunc i64 %9 to i32
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32*
store i32* %12, i32** %3
store i32 0, i32* %4
br label %13
13: ; preds = %23, %0
%14 = load i32, i32* %4
%15 = load i32, i32* %2
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = load i32*, i32** %3
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %21)
br label %23
23: ; preds = %17
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %13
26: ; preds = %13
%27 = load i32*, i32** %3
%28 = load i32, i32* %2
%29 = sub nsw i32 %28, 1
%30 = call i32 @Sort(i32* %27, i32 0, i32 %29)
%31 = load i32, i32* %2
%32 = sub nsw i32 %31, 1
store i32 %32, i32* %5
br label %33
33: ; preds = %59, %26
%34 = load i32, i32* %5
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %62
36: ; preds = %33
%37 = load i32*, i32** %3
%38 = load i32, i32* %5
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %37, i64 %40
%42 = load i32, i32* %41
%43 = load i32*, i32** %3
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
%47 = load i32, i32* %46
%48 = add nsw i32 %42, %47
%49 = sdiv i32 %48, 2
%50 = load i32*, i32** %3
%51 = load i32, i32* %5
%52 = sub nsw i32 %51, 1
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %50, i64 %53
store i32 %49, i32* %54
%55 = load i32*, i32** %3
%56 = load i32, i32* %5
%57 = sub nsw i32 %56, 1
%58 = call i32 @Insert(i32* %55, i32 %57)
br label %59
59: ; preds = %36
%60 = load i32, i32* %5
%61 = add nsw i32 %60, -1
store i32 %61, i32* %5
br label %33
62: ; preds = %33
%63 = load i32*, i32** %3
%64 = getelementptr inbounds i32, i32* %63, i64 0
%65 = load i32, i32* %64
%66 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %65)
%67 = load i32*, i32** %3
%68 = call i32 @free(i32* %67)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = shl i32 %4, 2
%6 = call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i32*
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %18, %0
%11 = phi i32 [ %8, %0 ], [ %23, %18 ]
%12 = add nsw i32 %11, -1
%13 = call i32 @Sort(i32* %7, i32 0, i32 %12)
%14 = load i32, i32* %1
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %26
16: ; preds = %10
%17 = zext i32 %14 to i64
br label %30
18: ; preds = %0, %18
%19 = phi i64 [ %22, %18 ], [ 0, %0 ]
%20 = getelementptr inbounds i32, i32* %7, i64 %19
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %20)
%22 = add nuw nsw i64 %19, 1
%23 = load i32, i32* %1
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %22, %24
br i1 %25, label %18, label %10
26: ; preds = %30, %10
%27 = load i32, i32* %7
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = call i32 @free(i32* %7)
ret i32 0
30: ; preds = %16, %30
%31 = phi i64 [ %17, %16 ], [ %33, %30 ]
%32 = trunc i64 %31 to i32
%33 = add nsw i64 %31, -1
%34 = add nsw i32 %32, -2
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %7, i64 %35
%37 = load i32, i32* %36
%38 = and i64 %33, 4294967295
%39 = getelementptr inbounds i32, i32* %7, i64 %38
%40 = load i32, i32* %39
%41 = add nsw i32 %40, %37
%42 = sdiv i32 %41, 2
store i32 %42, i32* %36
%43 = call i32 @Insert(i32* %7, i32 %34)
%44 = icmp ugt i64 %31, 2
br i1 %44, label %30, label %26
}