#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 */
typedef int uint64_t;
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int32_t n;
  scanf("%d", &n);
  if (n == 1) {
    scanf("%d", &n);
    printf("%d\n", n);
  } else {
    uint64_t total = 0;
    int32_t max = -1;
    while (n--) {
      int next;
      scanf("%d", &next);
      if (next > max)
        max = next;
      total += next;
    }
    uint64_t rest = total - max;
    printf("%llu\n", rest < max ? max << 1 : total);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    116d <main+0x4d>
lea    0xeb0(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%esi
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
jmp    11f7 <main+0xd7>
movl   $0x0,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     11bf <main+0x9f>
lea    0xe6a(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    11b1 <main+0x91>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    117b <main+0x5b>
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11e2 <main+0xc2>
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e8 <main+0xc8>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe15(%rip),%rdi
call   1030 <printf@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
lea    0xed2(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
mov    (%rsp),%eax
cmp    $0x1,%eax
jne    1159 <main+0x39>
lea    0xebb(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
mov    (%rsp),%esi
lea    0xeac(%rip),%rdi
jmp    11af <main+0x8f>
sub    $0x1,%eax
mov    %eax,(%rsp)
jae    116a <main+0x4a>
xor    %ebp,%ebp
mov    $0xffffffff,%ebx
jmp    119c <main+0x7c>
mov    $0xffffffff,%ebx
xor    %ebp,%ebp
lea    0xe88(%rip),%r14
lea    0x4(%rsp),%r15
nopl   (%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    %ebx,%eax
cmovg  %eax,%ebx
add    %eax,%ebp
subl   $0x1,(%rsp)
jae    1180 <main+0x60>
mov    %ebp,%eax
sub    %ebx,%eax
lea    (%rbx,%rbx,1),%esi
cmp    %ebx,%eax
cmovge %ebp,%esi
lea    0xe58(%rip),%rdi
call   1030 <printf@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"
@.str.2 = [6 x i8] c"%llu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%12 = load i32, i32* %2
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %45
14: ; preds = %0
store i32 0, i32* %3
store i32 -1, i32* %4
br label %15
15: ; preds = %26, %14
%16 = load i32, i32* %2
%17 = add nsw i32 %16, -1
store i32 %17, i32* %2
%18 = icmp ne i32 %16, 0
br i1 %18, label %19, label %30
19: ; preds = %15
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%21 = load i32, i32* %5
%22 = load i32, i32* %4
%23 = icmp sgt i32 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = load i32, i32* %5
store i32 %25, i32* %4
br label %26
26: ; preds = %24, %19
%27 = load i32, i32* %5
%28 = load i32, i32* %3
%29 = add nsw i32 %28, %27
store i32 %29, i32* %3
br label %15
30: ; preds = %15
%31 = load i32, i32* %3
%32 = load i32, i32* %4
%33 = sub nsw i32 %31, %32
store i32 %33, i32* %6
%34 = load i32, i32* %6
%35 = load i32, i32* %4
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %40
37: ; preds = %30
%38 = load i32, i32* %4
%39 = shl i32 %38, 1
br label %42
40: ; preds = %30
%41 = load i32, i32* %3
br label %42
42: ; preds = %40, %37
%43 = phi i32 [ %39, %37 ], [ %41, %40 ]
%44 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %42, %10
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [6 x i8] c"%llu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp eq i32 %5, 1
br i1 %6, label %12, label %7
7: ; preds = %0
%8 = add nsw i32 %5, -1
store i32 %8, i32* %1
%9 = icmp eq i32 %5, 0
br i1 %9, label %27, label %10
10: ; preds = %7
%11 = bitcast i32* %2 to i8*
br label %16
12: ; preds = %0
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%14 = load i32, i32* %1
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %35
16: ; preds = %10, %16
%17 = phi i32 [ 0, %10 ], [ %23, %16 ]
%18 = phi i32 [ -1, %10 ], [ %22, %16 ]
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%20 = load i32, i32* %2
%21 = icmp sgt i32 %20, %18
%22 = select i1 %21, i32 %20, i32 %18
%23 = add nsw i32 %20, %17
%24 = load i32, i32* %1
%25 = add nsw i32 %24, -1
store i32 %25, i32* %1
%26 = icmp eq i32 %24, 0
br i1 %26, label %27, label %16
27: ; preds = %16, %7
%28 = phi i32 [ -1, %7 ], [ %22, %16 ]
%29 = phi i32 [ 0, %7 ], [ %23, %16 ]
%30 = sub nsw i32 %29, %28
%31 = icmp slt i32 %30, %28
%32 = shl i32 %28, 1
%33 = select i1 %31, i32 %32, i32 %29
%34 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %27, %12
ret i32 0
}