Given the following C code and unoptimized assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int n;
int a[100010];
ll ans;

ll f(int d,ll R){
	if(R<a[d]){
		puts("-1");
		exit(0);
	}
	if(d==n){
		ans+=a[d];
		return a[n];
	}
	
	
	ll nex=f(d+1,min((R-a[d])*2,1000000000000000000));
	ll crr=min(R-a[d],nex)+a[d];
	ans+=crr;
	return crr;
}

int main(){
	scanf("%d",&n);
	rep(i,0,n+1)scanf("%d",a+i);
	
	f(0,1);
	printf("%lld",ans);
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	upll
	.type	upll, @function
upll:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	jl	.L2
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	setg	%al
	movzbl	%al, %eax
	jmp	.L4
.L2:
	movl	$-1, %eax
.L4:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	upll, .-upll
	.globl	downll
	.type	downll, @function
downll:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	jl	.L6
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	jle	.L7
	movl	$-1, %eax
	jmp	.L10
.L7:
	movl	$0, %eax
	jmp	.L10
.L6:
	movl	$1, %eax
.L10:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	downll, .-downll
	.globl	sortup
	.type	sortup, @function
sortup:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movq	%rdi, -8(%rbp)
	movl	%esi, -12(%rbp)
	movl	-12(%rbp), %eax
	movslq	%eax, %rsi
	movq	-8(%rbp), %rax
	leaq	upll(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	sortup, .-sortup
	.globl	sortdown
	.type	sortdown, @function
sortdown:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movq	%rdi, -8(%rbp)
	movl	%esi, -12(%rbp)
	movl	-12(%rbp), %eax
	movslq	%eax, %rsi
	movq	-8(%rbp), %rax
	leaq	downll(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.size	sortdown, .-sortdown
	.globl	pom
	.type	pom, @function
pom:
.LFB10:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -24(%rbp)
	movq	%rsi, -32(%rbp)
	movl	%edx, -36(%rbp)
	movq	$1, -8(%rbp)
	movl	-36(%rbp), %eax
	movslq	%eax, %rcx
	movq	-24(%rbp), %rax
	cqto
	idivq	%rcx
	movq	%rdx, -24(%rbp)
	jmp	.L14
.L17:
	movq	-32(%rbp), %rax
	andl	$1, %eax
	testq	%rax, %rax
	je	.L16
	movq	-8(%rbp), %rax
	imulq	-24(%rbp), %rax
	movl	-36(%rbp), %edx
	movslq	%edx, %rcx
	cqto
	idivq	%rcx
	movq	%rdx, -8(%rbp)
.L16:
	movq	-24(%rbp), %rax
	imulq	%rax, %rax
	movl	-36(%rbp), %edx
	movslq	%edx, %rcx
	cqto
	idivq	%rcx
	movq	%rdx, -24(%rbp)
	movq	-32(%rbp), %rax
	movq	%rax, %rdx
	shrq	$63, %rdx
	addq	%rdx, %rax
	sarq	%rax
	movq	%rax, -32(%rbp)
.L14:
	cmpq	$0, -32(%rbp)
	jne	.L17
	movq	-8(%rbp), %rax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE10:
	.size	pom, .-pom
	.globl	n
	.bss
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 400040
a:
	.zero	400040
	.globl	ans
	.align 8
	.type	ans, @object
	.size	ans, 8
ans:
	.zero	8
	.section	.rodata
.LC0:
	.string	"-1"
	.text
	.globl	f
	.type	f, @function
f:
.LFB11:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movl	%edi, -20(%rbp)
	movq	%rsi, -32(%rbp)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	cmpq	%rax, -32(%rbp)
	jge	.L20
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
	movl	$0, %edi
	call	exit@PLT
.L20:
	movl	n(%rip), %eax
	cmpl	%eax, -20(%rbp)
	jne	.L21
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	movslq	%eax, %rdx
	movq	ans(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, ans(%rip)
	movl	n(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	jmp	.L22
.L21:
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	movslq	%eax, %rdx
	movq	-32(%rbp), %rax
	subq	%rdx, %rax
	leaq	(%rax,%rax), %rdx
	movabsq	$1000000000000000000, %rax
	cmpq	%rax, %rdx
	cmovle	%rdx, %rax
	movl	-20(%rbp), %edx
	addl	$1, %edx
	movq	%rax, %rsi
	movl	%edx, %edi
	call	f
	movq	%rax, -16(%rbp)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	movslq	%eax, %rcx
	movq	-32(%rbp), %rax
	subq	%rcx, %rax
	movq	%rax, %rdx
	movq	-16(%rbp), %rax
	cmpq	%rax, %rdx
	cmovle	%rdx, %rax
	movq	%rax, %rcx
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	addq	%rcx, %rax
	movq	%rax, -8(%rbp)
	movq	ans(%rip), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, ans(%rip)
	movq	-8(%rbp), %rax
.L22:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE11:
	.size	f, .-f
	.section	.rodata
.LC1:
	.string	"%d"
.LC2:
	.string	"%lld"
	.text
	.globl	main
	.type	main, @function
main:
.LFB12:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$0, -8(%rbp)
	jmp	.L24
.L25:
	movq	-8(%rbp), %rax
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -8(%rbp)
.L24:
	movl	n(%rip), %eax
	addl	$1, %eax
	cltq
	cmpq	%rax, -8(%rbp)
	jl	.L25
	movl	$1, %esi
	movl	$0, %edi
	call	f
	movq	ans(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE12:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
```

Only output the optimized assembly code. Do not include any other text. Do not write any comments in the assembly code. Wrap the assembly code in ```assembly``` tags.
user
	.file	"temp.c"
	.text
	.p2align 4
	.globl	upll
	.type	upll, @function
upll:
.LFB51:
	.cfi_startproc
	endbr64
	movq	(%rsi), %rax
	cmpq	%rax, (%rdi)
	movl	$-1, %edx
	setg	%al
	movzbl	%al, %eax
	cmovl	%edx, %eax
	ret
	.cfi_endproc
.LFE51:
	.size	upll, .-upll
	.p2align 4
	.globl	downll
	.type	downll, @function
downll:
.LFB52:
	.cfi_startproc
	endbr64
	movq	(%rsi), %rdx
	movl	$1, %eax
	cmpq	%rdx, (%rdi)
	jl	.L5
	setg	%al
	movzbl	%al, %eax
	negl	%eax
.L5:
	ret
	.cfi_endproc
.LFE52:
	.size	downll, .-downll
	.p2align 4
	.globl	sortup
	.type	sortup, @function
sortup:
.LFB53:
	.cfi_startproc
	endbr64
	movslq	%esi, %rsi
	leaq	upll(%rip), %rcx
	movl	$8, %edx
	jmp	qsort@PLT
	.cfi_endproc
.LFE53:
	.size	sortup, .-sortup
	.p2align 4
	.globl	sortdown
	.type	sortdown, @function
sortdown:
.LFB54:
	.cfi_startproc
	endbr64
	movslq	%esi, %rsi
	leaq	downll(%rip), %rcx
	movl	$8, %edx
	jmp	qsort@PLT
	.cfi_endproc
.LFE54:
	.size	sortdown, .-sortdown
	.p2align 4
	.globl	pom
	.type	pom, @function
pom:
.LFB55:
	.cfi_startproc
	endbr64
	movq	%rdi, %rax
	movslq	%edx, %r8
	movl	$1, %r9d
	cqto
	idivq	%r8
	movq	%rdx, %rcx
	testq	%rsi, %rsi
	je	.L10
	.p2align 4,,10
	.p2align 3
.L13:
	testb	$1, %sil
	je	.L12
	movq	%r9, %rax
	imulq	%rcx, %rax
	cqto
	idivq	%r8
	movq	%rdx, %r9
.L12:
	imulq	%rcx, %rcx
	movq	%rcx, %rax
	cqto
	idivq	%r8
	movq	%rsi, %rax
	shrq	$63, %rax
	addq	%rax, %rsi
	sarq	%rsi
	movq	%rdx, %rcx
	jne	.L13
.L10:
	movq	%r9, %rax
	ret
	.cfi_endproc
.LFE55:
	.size	pom, .-pom
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"-1"
	.text
	.p2align 4
	.globl	f
	.type	f, @function
f:
.LFB56:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movslq	%edi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	a(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movslq	0(%rbp,%r13,4), %r8
	cmpq	%rsi, %r8
	jg	.L23
	movq	ans(%rip), %rax
	movl	n(%rip), %edx
	addq	%r8, %rax
	cmpl	%edi, %edx
	je	.L22
	movabsq	$1000000000000000000, %rax
	movq	%rsi, %rbx
	subq	%r8, %rsi
	leaq	(%rsi,%rsi), %r12
	leal	1(%rdi), %ecx
	cmpq	%rax, %r12
	movslq	%ecx, %r15
	cmovg	%rax, %r12
	movslq	0(%rbp,%r15,4), %rax
	cmpq	%rax, %r12
	jl	.L23
	cmpl	%ecx, %edx
	je	.L29
	movq	%r12, %r10
	leal	2(%rdi), %r11d
	movabsq	$1000000000000000000, %rcx
	subq	%rax, %r10
	leaq	(%r10,%r10), %r14
	cmpq	%rcx, %r14
	cmovg	%rcx, %r14
	movslq	%r11d, %rcx
	movslq	0(%rbp,%rcx,4), %r9
	cmpq	%r9, %r14
	jl	.L23
	cmpl	%r11d, %edx
	je	.L30
	movq	%r14, %rsi
	movq	%rcx, 8(%rsp)
	movabsq	$1000000000000000000, %rax
	subq	%r9, %rsi
	addq	%rsi, %rsi
	cmpq	%rax, %rsi
	cmovg	%rax, %rsi
	addl	$3, %edi
	call	f
	movq	8(%rsp), %rcx
	movslq	0(%rbp,%r13,4), %r8
	movq	%r12, %r10
	movq	ans(%rip), %rdx
	movslq	0(%rbp,%rcx,4), %r9
	subq	%r9, %r14
	cmpq	%rax, %r14
	cmovg	%rax, %r14
	movslq	0(%rbp,%r15,4), %rax
	subq	%r8, %rbx
	movq	%rbx, %rsi
	addq	%r14, %r9
	subq	%rax, %r10
	addq	%r9, %rdx
.L27:
	cmpq	%r10, %r9
	cmovg	%r10, %r9
	addq	%r9, %rax
	addq	%rax, %rdx
.L25:
	cmpq	%rsi, %rax
	cmovg	%rsi, %rax
	addq	%rax, %r8
	leaq	(%r8,%rdx), %rax
.L22:
	movq	%rax, ans(%rip)
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movq	%r8, %rax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L23:
	.cfi_restore_state
	leaq	.LC0(%rip), %rdi
	call	puts@PLT
	xorl	%edi, %edi
	call	exit@PLT
	.p2align 4,,10
	.p2align 3
.L29:
	movq	ans(%rip), %rdx
	addq	%rax, %rdx
	jmp	.L25
	.p2align 4,,10
	.p2align 3
.L30:
	movq	ans(%rip), %rdx
	addq	%r9, %rdx
	jmp	.L27
	.cfi_endproc
.LFE56:
	.size	f, .-f
	.section	.rodata.str1.1
.LC1:
	.string	"%d"
.LC2:
	.string	"%lld"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB57:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC1(%rip), %r12
	leaq	n(%rip), %rsi
	xorl	%eax, %eax
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%r12, %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	call	__isoc99_scanf@PLT
	movl	n(%rip), %eax
	testl	%eax, %eax
	js	.L32
	leaq	a(%rip), %rbp
	xorl	%ebx, %ebx
	.p2align 4,,10
	.p2align 3
.L33:
	movq	%rbp, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addq	$1, %rbx
	call	__isoc99_scanf@PLT
	movl	n(%rip), %eax
	addq	$4, %rbp
	addl	$1, %eax
	cltq
	cmpq	%rbx, %rax
	jg	.L33
.L32:
	movl	$1, %esi
	xorl	%edi, %edi
	call	f
	movq	ans(%rip), %rdx
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	movl	$1, %edi
	call	__printf_chk@PLT
	popq	%rbx
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE57:
	.size	main, .-main
	.globl	ans
	.bss
	.align 8
	.type	ans, @object
	.size	ans, 8
ans:
	.zero	8
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 400040
a:
	.zero	400040
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

rule
	.file	"temp.c"
	.text
	.p2align 4
	.globl	upll
	.type	upll, @function
upll:
.LFB51:
	.cfi_startproc
	endbr64
	movq	(%rsi), %rax
	cmpq	%rax, (%rdi)
	movl	$-1, %edx
	setg	%al
	movzbl	%al, %eax
	cmovl	%edx, %eax
	ret
	.cfi_endproc
.LFE51:
	.size	upll, .-upll
	.p2align 4
	.globl	downll
	.type	downll, @function
downll:
.LFB52:
	.cfi_startproc
	endbr64
	movq	(%rsi), %rdx
	movl	$1, %eax
	cmpq	%rdx, (%rdi)
	jl	.L5
	setg	%al
	movzbl	%al, %eax
	negl	%eax
.L5:
	ret
	.cfi_endproc
.LFE52:
	.size	downll, .-downll
	.p2align 4
	.globl	sortup
	.type	sortup, @function
sortup:
.LFB53:
	.cfi_startproc
	endbr64
	movslq	%esi, %rsi
	leaq	upll(%rip), %rcx
	movl	$8, %edx
	jmp	qsort@PLT
	.cfi_endproc
.LFE53:
	.size	sortup, .-sortup
	.p2align 4
	.globl	sortdown
	.type	sortdown, @function
sortdown:
.LFB54:
	.cfi_startproc
	endbr64
	movslq	%esi, %rsi
	leaq	downll(%rip), %rcx
	movl	$8, %edx
	jmp	qsort@PLT
	.cfi_endproc
.LFE54:
	.size	sortdown, .-sortdown
	.p2align 4
	.globl	pom
	.type	pom, @function
pom:
.LFB55:
	.cfi_startproc
	endbr64
	movq	%rdi, %rax
	movslq	%edx, %r8
	movl	$1, %r9d
	cqto
	idivq	%r8
	movq	%rdx, %rcx
	testq	%rsi, %rsi
	je	.L10
	.p2align 4,,10
	.p2align 3
.L13:
	testb	$1, %sil
	je	.L12
	movq	%r9, %rax
	imulq	%rcx, %rax
	cqto
	idivq	%r8
	movq	%rdx, %r9
.L12:
	imulq	%rcx, %rcx
	movq	%rcx, %rax
	cqto
	idivq	%r8
	movq	%rsi, %rax
	shrq	$63, %rax
	addq	%rax, %rsi
	sarq	%rsi
	movq	%rdx, %rcx
	jne	.L13
.L10:
	movq	%r9, %rax
	ret
	.cfi_endproc
.LFE55:
	.size	pom, .-pom
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"-1"
	.text
	.p2align 4
	.globl	f
	.type	f, @function
f:
.LFB56:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movslq	%edi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	a(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movslq	0(%rbp,%r13,4), %r8
	cmpq	%rsi, %r8
	jg	.L23
	movq	ans(%rip), %rax
	movl	n(%rip), %edx
	addq	%r8, %rax
	cmpl	%edi, %edx
	je	.L22
	movabsq	$1000000000000000000, %rax
	movq	%rsi, %rbx
	subq	%r8, %rsi
	leaq	(%rsi,%rsi), %r12
	leal	1(%rdi), %ecx
	cmpq	%rax, %r12
	movslq	%ecx, %r15
	cmovg	%rax, %r12
	movslq	0(%rbp,%r15,4), %rax
	cmpq	%rax, %r12
	jl	.L23
	cmpl	%ecx, %edx
	je	.L29
	movq	%r12, %r10
	leal	2(%rdi), %r11d
	movabsq	$1000000000000000000, %rcx
	subq	%rax, %r10
	leaq	(%r10,%r10), %r14
	cmpq	%rcx, %r14
	cmovg	%rcx, %r14
	movslq	%r11d, %rcx
	movslq	0(%rbp,%rcx,4), %r9
	cmpq	%r9, %r14
	jl	.L23
	cmpl	%r11d, %edx
	je	.L30
	movq	%r14, %rsi
	movq	%rcx, 8(%rsp)
	movabsq	$1000000000000000000, %rax
	subq	%r9, %rsi
	addq	%rsi, %rsi
	cmpq	%rax, %rsi
	cmovg	%rax, %rsi
	addl	$3, %edi
	call	f
	movq	8(%rsp), %rcx
	movslq	0(%rbp,%r13,4), %r8
	movq	%r12, %r10
	movq	ans(%rip), %rdx
	movslq	0(%rbp,%rcx,4), %r9
	subq	%r9, %r14
	cmpq	%rax, %r14
	cmovg	%rax, %r14
	movslq	0(%rbp,%r15,4), %rax
	subq	%r8, %rbx
	movq	%rbx, %rsi
	addq	%r14, %r9
	subq	%rax, %r10
	addq	%r9, %rdx
.L27:
	cmpq	%r10, %r9
	cmovg	%r10, %r9
	addq	%r9, %rax
	addq	%rax, %rdx
.L25:
	cmpq	%rsi, %rax
	cmovg	%rsi, %rax
	addq	%rax, %r8
	leaq	(%r8,%rdx), %rax
.L22:
	movq	%rax, ans(%rip)
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movq	%r8, %rax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L23:
	.cfi_restore_state
	leaq	.LC0(%rip), %rdi
	call	puts@PLT
	xorl	%edi, %edi
	call	exit@PLT
	.p2align 4,,10
	.p2align 3
.L29:
	movq	ans(%rip), %rdx
	addq	%rax, %rdx
	jmp	.L25
	.p2align 4,,10
	.p2align 3
.L30:
	movq	ans(%rip), %rdx
	addq	%r9, %rdx
	jmp	.L27
	.cfi_endproc
.LFE56:
	.size	f, .-f
	.section	.rodata.str1.1
.LC1:
	.string	"%d"
.LC2:
	.string	"%lld"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB57:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC1(%rip), %r12
	leaq	n(%rip), %rsi
	xorl	%eax, %eax
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%r12, %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	call	__isoc99_scanf@PLT
	movl	n(%rip), %eax
	testl	%eax, %eax
	js	.L32
	leaq	a(%rip), %rbp
	xorl	%ebx, %ebx
	.p2align 4,,10
	.p2align 3
.L33:
	movq	%rbp, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addq	$1, %rbx
	call	__isoc99_scanf@PLT
	movl	n(%rip), %eax
	addq	$4, %rbp
	addl	$1, %eax
	cltq
	cmpq	%rbx, %rax
	jg	.L33
.L32:
	movl	$1, %esi
	xorl	%edi, %edi
	call	f
	movq	ans(%rip), %rdx
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	movl	$1, %edi
	call	__printf_chk@PLT
	popq	%rbx
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE57:
	.size	main, .-main
	.globl	ans
	.bss
	.align 8
	.type	ans, @object
	.size	ans, 8
ans:
	.zero	8
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 400040
a:
	.zero	400040
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int n;
int a[100010];
ll ans;

ll f(int d,ll R){
	if(R<a[d]){
		puts("-1");
		exit(0);
	}
	if(d==n){
		ans+=a[d];
		return a[n];
	}
	
	
	ll nex=f(d+1,min((R-a[d])*2,1000000000000000000));
	ll crr=min(R-a[d],nex)+a[d];
	ans+=crr;
	return crr;
}

int main(){
	scanf("%d",&n);
	rep(i,0,n+1)scanf("%d",a+i);
	
	f(0,1);
	printf("%lld",ans);
}
4
0 0 0 0 2
 3
0 1 1 1
 10
0 0 1 0 2 3 5 8 13 21 34
 2
0 3 2
 10
0 0 1 0 2 3 5 8 13 23 34
 10
0 0 1 0 3 3 5 8 13 23 34
 2
-1 3 2
 10
0 0 1 1 3 3 5 8 13 23 34
 2
-2 3 2
 4
0 1 0 1 2

9 6 294 -1
 298 284 7 236 8 10
Given the following C code and unoptimized assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int n;
int a[100010];
ll ans;

ll f(int d,ll R){
	if(R<a[d]){
		puts("-1");
		exit(0);
	}
	if(d==n){
		ans+=a[d];
		return a[n];
	}
	
	
	ll nex=f(d+1,min((R-a[d])*2,1000000000000000000));
	ll crr=min(R-a[d],nex)+a[d];
	ans+=crr;
	return crr;
}

int main(){
	scanf("%d",&n);
	rep(i,0,n+1)scanf("%d",a+i);
	
	f(0,1);
	printf("%lld",ans);
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	upll
	.type	upll, @function
upll:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	jl	.L2
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	setg	%al
	movzbl	%al, %eax
	jmp	.L4
.L2:
	movl	$-1, %eax
.L4:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	upll, .-upll
	.globl	downll
	.type	downll, @function
downll:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	jl	.L6
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	jle	.L7
	movl	$-1, %eax
	jmp	.L10
.L7:
	movl	$0, %eax
	jmp	.L10
.L6:
	movl	$1, %eax
.L10:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	downll, .-downll
	.globl	sortup
	.type	sortup, @function
sortup:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movq	%rdi, -8(%rbp)
	movl	%esi, -12(%rbp)
	movl	-12(%rbp), %eax
	movslq	%eax, %rsi
	movq	-8(%rbp), %rax
	leaq	upll(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	sortup, .-sortup
	.globl	sortdown
	.type	sortdown, @function
sortdown:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movq	%rdi, -8(%rbp)
	movl	%esi, -12(%rbp)
	movl	-12(%rbp), %eax
	movslq	%eax, %rsi
	movq	-8(%rbp), %rax
	leaq	downll(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.size	sortdown, .-sortdown
	.globl	pom
	.type	pom, @function
pom:
.LFB10:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -24(%rbp)
	movq	%rsi, -32(%rbp)
	movl	%edx, -36(%rbp)
	movq	$1, -8(%rbp)
	movl	-36(%rbp), %eax
	movslq	%eax, %rcx
	movq	-24(%rbp), %rax
	cqto
	idivq	%rcx
	movq	%rdx, -24(%rbp)
	jmp	.L14
.L17:
	movq	-32(%rbp), %rax
	andl	$1, %eax
	testq	%rax, %rax
	je	.L16
	movq	-8(%rbp), %rax
	imulq	-24(%rbp), %rax
	movl	-36(%rbp), %edx
	movslq	%edx, %rcx
	cqto
	idivq	%rcx
	movq	%rdx, -8(%rbp)
.L16:
	movq	-24(%rbp), %rax
	imulq	%rax, %rax
	movl	-36(%rbp), %edx
	movslq	%edx, %rcx
	cqto
	idivq	%rcx
	movq	%rdx, -24(%rbp)
	movq	-32(%rbp), %rax
	movq	%rax, %rdx
	shrq	$63, %rdx
	addq	%rdx, %rax
	sarq	%rax
	movq	%rax, -32(%rbp)
.L14:
	cmpq	$0, -32(%rbp)
	jne	.L17
	movq	-8(%rbp), %rax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE10:
	.size	pom, .-pom
	.globl	n
	.bss
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 400040
a:
	.zero	400040
	.globl	ans
	.align 8
	.type	ans, @object
	.size	ans, 8
ans:
	.zero	8
	.section	.rodata
.LC0:
	.string	"-1"
	.text
	.globl	f
	.type	f, @function
f:
.LFB11:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movl	%edi, -20(%rbp)
	movq	%rsi, -32(%rbp)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	cmpq	%rax, -32(%rbp)
	jge	.L20
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
	movl	$0, %edi
	call	exit@PLT
.L20:
	movl	n(%rip), %eax
	cmpl	%eax, -20(%rbp)
	jne	.L21
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	movslq	%eax, %rdx
	movq	ans(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, ans(%rip)
	movl	n(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	jmp	.L22
.L21:
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	movslq	%eax, %rdx
	movq	-32(%rbp), %rax
	subq	%rdx, %rax
	leaq	(%rax,%rax), %rdx
	movabsq	$1000000000000000000, %rax
	cmpq	%rax, %rdx
	cmovle	%rdx, %rax
	movl	-20(%rbp), %edx
	addl	$1, %edx
	movq	%rax, %rsi
	movl	%edx, %edi
	call	f
	movq	%rax, -16(%rbp)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	movslq	%eax, %rcx
	movq	-32(%rbp), %rax
	subq	%rcx, %rax
	movq	%rax, %rdx
	movq	-16(%rbp), %rax
	cmpq	%rax, %rdx
	cmovle	%rdx, %rax
	movq	%rax, %rcx
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	addq	%rcx, %rax
	movq	%rax, -8(%rbp)
	movq	ans(%rip), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, ans(%rip)
	movq	-8(%rbp), %rax
.L22:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE11:
	.size	f, .-f
	.section	.rodata
.LC1:
	.string	"%d"
.LC2:
	.string	"%lld"
	.text
	.globl	main
	.type	main, @function
main:
.LFB12:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$0, -8(%rbp)
	jmp	.L24
.L25:
	movq	-8(%rbp), %rax
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -8(%rbp)
.L24:
	movl	n(%rip), %eax
	addl	$1, %eax
	cltq
	cmpq	%rax, -8(%rbp)
	jl	.L25
	movl	$1, %esi
	movl	$0, %edi
	call	f
	movq	ans(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE12:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
```

Only output the optimized assembly code. Do not include any other text. Do not write any comments in the assembly code. Wrap the assembly code in ```assembly``` tags.
train
	.file	"temp.c"
	.text
	.globl	upll
	.type	upll, @function
upll:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	jl	.L2
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	setg	%al
	movzbl	%al, %eax
	jmp	.L4
.L2:
	movl	$-1, %eax
.L4:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	upll, .-upll
	.globl	downll
	.type	downll, @function
downll:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	jl	.L6
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	jle	.L7
	movl	$-1, %eax
	jmp	.L10
.L7:
	movl	$0, %eax
	jmp	.L10
.L6:
	movl	$1, %eax
.L10:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	downll, .-downll
	.globl	sortup
	.type	sortup, @function
sortup:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movq	%rdi, -8(%rbp)
	movl	%esi, -12(%rbp)
	movl	-12(%rbp), %eax
	movslq	%eax, %rsi
	movq	-8(%rbp), %rax
	leaq	upll(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	sortup, .-sortup
	.globl	sortdown
	.type	sortdown, @function
sortdown:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movq	%rdi, -8(%rbp)
	movl	%esi, -12(%rbp)
	movl	-12(%rbp), %eax
	movslq	%eax, %rsi
	movq	-8(%rbp), %rax
	leaq	downll(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.size	sortdown, .-sortdown
	.globl	pom
	.type	pom, @function
pom:
.LFB10:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -24(%rbp)
	movq	%rsi, -32(%rbp)
	movl	%edx, -36(%rbp)
	movq	$1, -8(%rbp)
	movl	-36(%rbp), %eax
	movslq	%eax, %rcx
	movq	-24(%rbp), %rax
	cqto
	idivq	%rcx
	movq	%rdx, -24(%rbp)
	jmp	.L14
.L17:
	movq	-32(%rbp), %rax
	andl	$1, %eax
	testq	%rax, %rax
	je	.L16
	movq	-8(%rbp), %rax
	imulq	-24(%rbp), %rax
	movl	-36(%rbp), %edx
	movslq	%edx, %rcx
	cqto
	idivq	%rcx
	movq	%rdx, -8(%rbp)
.L16:
	movq	-24(%rbp), %rax
	imulq	%rax, %rax
	movl	-36(%rbp), %edx
	movslq	%edx, %rcx
	cqto
	idivq	%rcx
	movq	%rdx, -24(%rbp)
	movq	-32(%rbp), %rax
	movq	%rax, %rdx
	shrq	$63, %rdx
	addq	%rdx, %rax
	sarq	%rax
	movq	%rax, -32(%rbp)
.L14:
	cmpq	$0, -32(%rbp)
	jne	.L17
	movq	-8(%rbp), %rax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE10:
	.size	pom, .-pom
	.globl	n
	.bss
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 400040
a:
	.zero	400040
	.globl	ans
	.align 8
	.type	ans, @object
	.size	ans, 8
ans:
	.zero	8
	.section	.rodata
.LC0:
	.string	"-1"
	.text
	.globl	f
	.type	f, @function
f:
.LFB11:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movl	%edi, -20(%rbp)
	movq	%rsi, -32(%rbp)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	cmpq	%rax, -32(%rbp)
	jge	.L20
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
	movl	$0, %edi
	call	exit@PLT
.L20:
	movl	n(%rip), %eax
	cmpl	%eax, -20(%rbp)
	jne	.L21
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	movslq	%eax, %rdx
	movq	ans(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, ans(%rip)
	movl	n(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	jmp	.L22
.L21:
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	movslq	%eax, %rdx
	movq	-32(%rbp), %rax
	subq	%rdx, %rax
	leaq	(%rax,%rax), %rdx
	movabsq	$1000000000000000000, %rax
	cmpq	%rax, %rdx
	cmovle	%rdx, %rax
	movl	-20(%rbp), %edx
	addl	$1, %edx
	movq	%rax, %rsi
	movl	%edx, %edi
	call	f
	movq	%rax, -16(%rbp)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	movslq	%eax, %rcx
	movq	-32(%rbp), %rax
	subq	%rcx, %rax
	movq	%rax, %rdx
	movq	-16(%rbp), %rax
	cmpq	%rax, %rdx
	cmovle	%rdx, %rax
	movq	%rax, %rcx
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	addq	%rcx, %rax
	movq	%rax, -8(%rbp)
	movq	ans(%rip), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, ans(%rip)
	movq	-8(%rbp), %rax
.L22:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE11:
	.size	f, .-f
	.section	.rodata
.LC1:
	.string	"%d"
.LC2:
	.string	"%lld"
	.text
	.globl	main
	.type	main, @function
main:
.LFB12:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$0, -8(%rbp)
	jmp	.L24
.L25:
	movq	-8(%rbp), %rax
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -8(%rbp)
.L24:
	movl	n(%rip), %eax
	addl	$1, %eax
	cltq
	cmpq	%rax, -8(%rbp)
	jl	.L25
	movl	$1, %esi
	movl	$0, %edi
	call	f
	movq	ans(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE12:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
