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)

ll L;
//ワーシャルフロイド
//頂点数（と隣接行列）を引いて全点間最短距離を返す
//O(V^3)
ll cost[310][310];
ll dddd[310][310];
ll cccc[310][310];
void waasharuhuroido(ll n){
	rep(i,0,n)rep(j,0,n)if(i!=j){
		if(cost[i][j]&&cost[i][j]<=L){
			dddd[i][j]=cost[i][j];
		}else{
			dddd[i][j]=cccc[i][j]=INF;
		}
	}
	rep(_,0,3)rep(k,0,n)rep(i,0,n)rep(j,0,n){
		ll tempc=cccc[i][k]+cccc[k][j];
		ll tempd=dddd[i][k]+dddd[k][j];
		if(!(tempc==0&&tempd<=L)){
			tempc++;
			tempd=dddd[k][j];
		}
		
		if(cccc[i][j]>tempc||(cccc[i][j]==tempc&&dddd[i][j]>tempd)){
			cccc[i][j]=tempc;
			dddd[i][j]=tempd;
		}
//		rep(i,0,n){rep(j,0,n)printf("(%2d,%2d) ",cccc[i][j]==INF?99:cccc[i][j],dddd[i][j]==INF?99:dddd[i][j]);puts("");}puts("");
	}
}

int main(){
	ll n,m;
	scanf("%lld%lld%lld",&n,&m,&L);
	rep(i,0,m){
		ll x,y,z;
		scanf("%lld%lld%lld",&x,&y,&z);
		x--,y--;
		cost[x][y]=cost[y][x]=z;
	}
	waasharuhuroido(n);
	ll q;
	scanf("%lld",&q);
	while(q--){
		ll x,y;
		scanf("%lld%lld",&x,&y);
		x--,y--;
		ll ans=cccc[x][y];
		printf("%lld\n",ans==INF?-1: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	L
	.bss
	.align 8
	.type	L, @object
	.size	L, 8
L:
	.zero	8
	.globl	cost
	.align 32
	.type	cost, @object
	.size	cost, 768800
cost:
	.zero	768800
	.globl	dddd
	.align 32
	.type	dddd, @object
	.size	dddd, 768800
dddd:
	.zero	768800
	.globl	cccc
	.align 32
	.type	cccc, @object
	.size	cccc, 768800
cccc:
	.zero	768800
	.text
	.globl	waasharuhuroido
	.type	waasharuhuroido, @function
waasharuhuroido:
.LFB11:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -72(%rbp)
	movq	$0, -64(%rbp)
	jmp	.L20
.L25:
	movq	$0, -56(%rbp)
	jmp	.L21
.L24:
	movq	-64(%rbp), %rax
	cmpq	-56(%rbp), %rax
	je	.L22
	movq	-64(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cost(%rip), %rax
	movq	(%rdx,%rax), %rax
	testq	%rax, %rax
	je	.L23
	movq	-64(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cost(%rip), %rax
	movq	(%rdx,%rax), %rdx
	movq	L(%rip), %rax
	cmpq	%rax, %rdx
	jg	.L23
	movq	-64(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cost(%rip), %rax
	movq	(%rdx,%rax), %rax
	movq	-64(%rbp), %rdx
	imulq	$310, %rdx, %rcx
	movq	-56(%rbp), %rdx
	addq	%rcx, %rdx
	leaq	0(,%rdx,8), %rcx
	leaq	dddd(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
	jmp	.L22
.L23:
	movq	-64(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cccc(%rip), %rax
	movabsq	$4611686016279904256, %rsi
	movq	%rsi, (%rdx,%rax)
	movq	-64(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cccc(%rip), %rax
	movq	(%rdx,%rax), %rax
	movq	-64(%rbp), %rdx
	imulq	$310, %rdx, %rcx
	movq	-56(%rbp), %rdx
	addq	%rcx, %rdx
	leaq	0(,%rdx,8), %rcx
	leaq	dddd(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
.L22:
	addq	$1, -56(%rbp)
.L21:
	movq	-56(%rbp), %rax
	cmpq	-72(%rbp), %rax
	jl	.L24
	addq	$1, -64(%rbp)
.L20:
	movq	-64(%rbp), %rax
	cmpq	-72(%rbp), %rax
	jl	.L25
	movq	$0, -48(%rbp)
	jmp	.L26
.L37:
	movq	$0, -40(%rbp)
	jmp	.L27
.L36:
	movq	$0, -32(%rbp)
	jmp	.L28
.L35:
	movq	$0, -24(%rbp)
	jmp	.L29
.L34:
	movq	-32(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cccc(%rip), %rax
	movq	(%rdx,%rax), %rcx
	movq	-40(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cccc(%rip), %rax
	movq	(%rdx,%rax), %rax
	addq	%rcx, %rax
	movq	%rax, -16(%rbp)
	movq	-32(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	dddd(%rip), %rax
	movq	(%rdx,%rax), %rcx
	movq	-40(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	dddd(%rip), %rax
	movq	(%rdx,%rax), %rax
	addq	%rcx, %rax
	movq	%rax, -8(%rbp)
	cmpq	$0, -16(%rbp)
	jne	.L30
	movq	L(%rip), %rax
	cmpq	%rax, -8(%rbp)
	jle	.L31
.L30:
	addq	$1, -16(%rbp)
	movq	-40(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	dddd(%rip), %rax
	movq	(%rdx,%rax), %rax
	movq	%rax, -8(%rbp)
.L31:
	movq	-32(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cccc(%rip), %rax
	movq	(%rdx,%rax), %rax
	cmpq	%rax, -16(%rbp)
	jl	.L32
	movq	-32(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cccc(%rip), %rax
	movq	(%rdx,%rax), %rax
	cmpq	%rax, -16(%rbp)
	jne	.L33
	movq	-32(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	dddd(%rip), %rax
	movq	(%rdx,%rax), %rax
	cmpq	%rax, -8(%rbp)
	jge	.L33
.L32:
	movq	-32(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rcx
	leaq	cccc(%rip), %rdx
	movq	-16(%rbp), %rax
	movq	%rax, (%rcx,%rdx)
	movq	-32(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rcx
	leaq	dddd(%rip), %rdx
	movq	-8(%rbp), %rax
	movq	%rax, (%rcx,%rdx)
.L33:
	addq	$1, -24(%rbp)
.L29:
	movq	-24(%rbp), %rax
	cmpq	-72(%rbp), %rax
	jl	.L34
	addq	$1, -32(%rbp)
.L28:
	movq	-32(%rbp), %rax
	cmpq	-72(%rbp), %rax
	jl	.L35
	addq	$1, -40(%rbp)
.L27:
	movq	-40(%rbp), %rax
	cmpq	-72(%rbp), %rax
	jl	.L36
	addq	$1, -48(%rbp)
.L26:
	cmpq	$2, -48(%rbp)
	jle	.L37
	nop
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE11:
	.size	waasharuhuroido, .-waasharuhuroido
	.section	.rodata
.LC0:
	.string	"%lld%lld%lld"
.LC1:
	.string	"%lld"
.LC2:
	.string	"%lld%lld"
.LC3:
	.string	"%lld\n"
	.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	$64, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-56(%rbp), %rdx
	leaq	-64(%rbp), %rax
	leaq	L(%rip), %rcx
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$0, -24(%rbp)
	jmp	.L39
.L40:
	leaq	-32(%rbp), %rcx
	leaq	-40(%rbp), %rdx
	leaq	-48(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-48(%rbp), %rax
	subq	$1, %rax
	movq	%rax, -48(%rbp)
	movq	-40(%rbp), %rax
	subq	$1, %rax
	movq	%rax, -40(%rbp)
	movq	-40(%rbp), %rax
	movq	-48(%rbp), %rdi
	movq	-32(%rbp), %rdx
	imulq	$310, %rax, %rcx
	addq	%rdi, %rcx
	leaq	0(,%rcx,8), %rsi
	leaq	cost(%rip), %rcx
	movq	%rdx, (%rsi,%rcx)
	movq	-48(%rbp), %rdx
	movq	-40(%rbp), %rsi
	imulq	$310, %rax, %rax
	addq	%rdi, %rax
	leaq	0(,%rax,8), %rcx
	leaq	cost(%rip), %rax
	movq	(%rcx,%rax), %rax
	imulq	$310, %rdx, %rdx
	addq	%rsi, %rdx
	leaq	0(,%rdx,8), %rcx
	leaq	cost(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
	addq	$1, -24(%rbp)
.L39:
	movq	-56(%rbp), %rax
	cmpq	%rax, -24(%rbp)
	jl	.L40
	movq	-64(%rbp), %rax
	movq	%rax, %rdi
	call	waasharuhuroido
	leaq	-48(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L41
.L44:
	leaq	-32(%rbp), %rdx
	leaq	-40(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-40(%rbp), %rax
	subq	$1, %rax
	movq	%rax, -40(%rbp)
	movq	-32(%rbp), %rax
	subq	$1, %rax
	movq	%rax, -32(%rbp)
	movq	-40(%rbp), %rax
	movq	-32(%rbp), %rdx
	imulq	$310, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cccc(%rip), %rax
	movq	(%rdx,%rax), %rax
	movq	%rax, -16(%rbp)
	movabsq	$4611686016279904256, %rax
	cmpq	%rax, -16(%rbp)
	je	.L42
	movq	-16(%rbp), %rax
	jmp	.L43
.L42:
	movq	$-1, %rax
.L43:
	movq	%rax, %rsi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L41:
	movq	-48(%rbp), %rax
	leaq	-1(%rax), %rdx
	movq	%rdx, -48(%rbp)
	testq	%rax, %rax
	jne	.L44
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L46
	call	__stack_chk_fail@PLT
.L46:
	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
	.p2align 4
	.globl	waasharuhuroido
	.type	waasharuhuroido, @function
waasharuhuroido:
.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
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	L(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	testq	%rdi, %rdi
	jle	.L19
	leaq	dddd(%rip), %r15
	movq	%rdi, %r13
	leaq	cccc(%rip), %r9
	xorl	%esi, %esi
	movq	%r15, %r10
	leaq	cost(%rip), %r8
	movabsq	$4611686016279904256, %rdi
.L21:
	movq	%r10, %rdx
	xorl	%eax, %eax
	jmp	.L24
	.p2align 4,,10
	.p2align 3
.L47:
	cmpq	%rbp, %rcx
	jg	.L23
	movq	%rcx, (%rdx)
.L22:
	leaq	1(%rax), %rcx
	addq	$8, %rdx
	cmpq	%rcx, %r13
	je	.L46
.L36:
	movq	%rcx, %rax
.L24:
	cmpq	%rsi, %rax
	je	.L22
	movq	(%r8,%rax,8), %rcx
	testq	%rcx, %rcx
	jne	.L47
.L23:
	leaq	1(%rax), %rcx
	movq	%rdi, (%rdx)
	addq	$8, %rdx
	movq	%rdi, (%r9,%rax,8)
	cmpq	%rcx, %r13
	jne	.L36
.L46:
	leaq	1(%rsi), %rdx
	addq	$2480, %r10
	addq	$2480, %r9
	addq	$2480, %r8
	cmpq	%rsi, %rax
	je	.L25
	movq	%rdx, %rsi
	jmp	.L21
	.p2align 4,,10
	.p2align 3
.L49:
	subq	$2480, %r9
	leaq	2480(%rax), %r11
	addq	$2480, %r10
	addq	$2480, %rbx
	cmpq	%r13, %r9
	jne	.L33
	subq	$8, %r12
	addq	$2480, %rsi
	cmpq	%r14, %r12
	jne	.L34
	subq	$1, -8(%rsp)
	jne	.L35
.L19:
	popq	%rbx
	.cfi_remember_state
	.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
.L25:
	.cfi_restore_state
	movq	$3, -8(%rsp)
	movq	%r13, %r14
	movq	%r15, %rax
	negq	%r14
	imulq	$-2480, %r13, %r13
	salq	$3, %r14
	subq	%r14, %rax
	movq	%rax, -16(%rsp)
.L35:
	xorl	%r12d, %r12d
	xorl	%esi, %esi
	.p2align 4,,10
	.p2align 3
.L34:
	leaq	cccc(%rip), %r10
	movq	%r15, %rbx
	movq	-16(%rsp), %r11
	xorl	%r9d, %r9d
	subq	%r12, %r10
	subq	%r12, %rbx
	.p2align 4,,10
	.p2align 3
.L33:
	leaq	(%r11,%r14), %rax
	leaq	(%r10,%r12), %rdx
	jmp	.L30
	.p2align 4,,10
	.p2align 3
.L50:
	addq	%r8, %rdi
	cmpq	%rbp, %rdi
	jg	.L26
	movq	%rdi, %r8
	cmpq	%rcx, (%rdx)
	jg	.L28
.L51:
	je	.L48
.L29:
	addq	$8, %rax
	addq	$8, %rdx
	cmpq	%r11, %rax
	je	.L49
.L30:
	leaq	(%r9,%rdx), %rcx
	leaq	(%r9,%rax), %r8
	movq	(%rbx), %rdi
	movq	(%r8,%rsi), %r8
	movq	(%rcx,%rsi), %rcx
	addq	(%r10), %rcx
	je	.L50
.L26:
	addq	$1, %rcx
	cmpq	%rcx, (%rdx)
	jle	.L51
.L28:
	movq	%rcx, (%rdx)
	movq	%r8, (%rax)
	jmp	.L29
	.p2align 4,,10
	.p2align 3
.L48:
	cmpq	%r8, (%rax)
	jle	.L29
	movq	%rcx, (%rdx)
	movq	%r8, (%rax)
	jmp	.L29
	.cfi_endproc
.LFE56:
	.size	waasharuhuroido, .-waasharuhuroido
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%lld%lld%lld"
.LC1:
	.string	"%lld"
.LC2:
	.string	"%lld%lld"
.LC3:
	.string	"%lld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB57:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	L(%rip), %rcx
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	.LC0(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%r12, %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdx
	movq	%rsp, %rsi
	leaq	16(%rsp), %r15
	call	__isoc99_scanf@PLT
	cmpq	$0, 8(%rsp)
	jle	.L53
	xorl	%r13d, %r13d
	leaq	32(%rsp), %rbp
	leaq	24(%rsp), %rbx
	leaq	16(%rsp), %r15
	leaq	cost(%rip), %r14
	.p2align 4,,10
	.p2align 3
.L54:
	movq	%rbp, %rcx
	movq	%rbx, %rdx
	movq	%r15, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addq	$1, %r13
	call	__isoc99_scanf@PLT
	movq	24(%rsp), %rdi
	movq	16(%rsp), %rax
	movq	32(%rsp), %rsi
	leaq	-1(%rdi), %rdx
	subq	$1, %rax
	imulq	$310, %rdx, %rcx
	addq	%rax, %rcx
	imulq	$310, %rax, %rax
	movq	%rsi, (%r14,%rcx,8)
	addq	%rdx, %rax
	movq	%rsi, (%r14,%rax,8)
	cmpq	%r13, 8(%rsp)
	jg	.L54
.L53:
	movq	(%rsp), %rdi
	call	waasharuhuroido
	movq	%r15, %rsi
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movq	16(%rsp), %rax
	leaq	-1(%rax), %rdx
	movq	%rdx, 16(%rsp)
	testq	%rax, %rax
	je	.L55
	leaq	32(%rsp), %rbp
	leaq	24(%rsp), %rbx
	movabsq	$4611686016279904256, %r12
	leaq	.LC2(%rip), %r14
	leaq	cccc(%rip), %r13
	leaq	.LC3(%rip), %r15
	.p2align 4,,10
	.p2align 3
.L58:
	movq	%rbp, %rdx
	movq	%rbx, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movq	24(%rsp), %rax
	movq	32(%rsp), %rcx
	subq	$1, %rax
	leaq	-1(%rcx), %rdx
	movq	%rax, 24(%rsp)
	imulq	$310, %rax, %rax
	movq	%rdx, 32(%rsp)
	addq	%rdx, %rax
	movq	0(%r13,%rax,8), %rdx
	cmpq	%r12, %rdx
	jne	.L56
	movq	$-1, %rdx
.L56:
	movq	%r15, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	16(%rsp), %rax
	leaq	-1(%rax), %rdx
	movq	%rdx, 16(%rsp)
	testq	%rax, %rax
	jne	.L58
.L55:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L70
	addq	$56, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	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
.L70:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE57:
	.size	main, .-main
	.globl	cccc
	.bss
	.align 32
	.type	cccc, @object
	.size	cccc, 768800
cccc:
	.zero	768800
	.globl	dddd
	.align 32
	.type	dddd, @object
	.size	dddd, 768800
dddd:
	.zero	768800
	.globl	cost
	.align 32
	.type	cost, @object
	.size	cost, 768800
cost:
	.zero	768800
	.globl	L
	.align 8
	.type	L, @object
	.size	L, 8
L:
	.zero	8
	.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
	.p2align 4
	.globl	waasharuhuroido
	.type	waasharuhuroido, @function
waasharuhuroido:
.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
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	L(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	testq	%rdi, %rdi
	jle	.L19
	leaq	dddd(%rip), %r15
	movq	%rdi, %r13
	leaq	cccc(%rip), %r9
	xorl	%esi, %esi
	movq	%r15, %r10
	leaq	cost(%rip), %r8
	movabsq	$4611686016279904256, %rdi
.L21:
	movq	%r10, %rdx
	xorl	%eax, %eax
	jmp	.L24
	.p2align 4,,10
	.p2align 3
.L47:
	cmpq	%rbp, %rcx
	jg	.L23
	movq	%rcx, (%rdx)
.L22:
	leaq	1(%rax), %rcx
	addq	$8, %rdx
	cmpq	%rcx, %r13
	je	.L46
.L36:
	movq	%rcx, %rax
.L24:
	cmpq	%rsi, %rax
	je	.L22
	movq	(%r8,%rax,8), %rcx
	testq	%rcx, %rcx
	jne	.L47
.L23:
	leaq	1(%rax), %rcx
	movq	%rdi, (%rdx)
	addq	$8, %rdx
	movq	%rdi, (%r9,%rax,8)
	cmpq	%rcx, %r13
	jne	.L36
.L46:
	leaq	1(%rsi), %rdx
	addq	$2480, %r10
	addq	$2480, %r9
	addq	$2480, %r8
	cmpq	%rsi, %rax
	je	.L25
	movq	%rdx, %rsi
	jmp	.L21
	.p2align 4,,10
	.p2align 3
.L49:
	subq	$2480, %r9
	leaq	2480(%rax), %r11
	addq	$2480, %r10
	addq	$2480, %rbx
	cmpq	%r13, %r9
	jne	.L33
	subq	$8, %r12
	addq	$2480, %rsi
	cmpq	%r14, %r12
	jne	.L34
	subq	$1, -8(%rsp)
	jne	.L35
.L19:
	popq	%rbx
	.cfi_remember_state
	.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
.L25:
	.cfi_restore_state
	movq	$3, -8(%rsp)
	movq	%r13, %r14
	movq	%r15, %rax
	negq	%r14
	imulq	$-2480, %r13, %r13
	salq	$3, %r14
	subq	%r14, %rax
	movq	%rax, -16(%rsp)
.L35:
	xorl	%r12d, %r12d
	xorl	%esi, %esi
	.p2align 4,,10
	.p2align 3
.L34:
	leaq	cccc(%rip), %r10
	movq	%r15, %rbx
	movq	-16(%rsp), %r11
	xorl	%r9d, %r9d
	subq	%r12, %r10
	subq	%r12, %rbx
	.p2align 4,,10
	.p2align 3
.L33:
	leaq	(%r11,%r14), %rax
	leaq	(%r10,%r12), %rdx
	jmp	.L30
	.p2align 4,,10
	.p2align 3
.L50:
	addq	%r8, %rdi
	cmpq	%rbp, %rdi
	jg	.L26
	movq	%rdi, %r8
	cmpq	%rcx, (%rdx)
	jg	.L28
.L51:
	je	.L48
.L29:
	addq	$8, %rax
	addq	$8, %rdx
	cmpq	%r11, %rax
	je	.L49
.L30:
	leaq	(%r9,%rdx), %rcx
	leaq	(%r9,%rax), %r8
	movq	(%rbx), %rdi
	movq	(%r8,%rsi), %r8
	movq	(%rcx,%rsi), %rcx
	addq	(%r10), %rcx
	je	.L50
.L26:
	addq	$1, %rcx
	cmpq	%rcx, (%rdx)
	jle	.L51
.L28:
	movq	%rcx, (%rdx)
	movq	%r8, (%rax)
	jmp	.L29
	.p2align 4,,10
	.p2align 3
.L48:
	cmpq	%r8, (%rax)
	jle	.L29
	movq	%rcx, (%rdx)
	movq	%r8, (%rax)
	jmp	.L29
	.cfi_endproc
.LFE56:
	.size	waasharuhuroido, .-waasharuhuroido
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%lld%lld%lld"
.LC1:
	.string	"%lld"
.LC2:
	.string	"%lld%lld"
.LC3:
	.string	"%lld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB57:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	L(%rip), %rcx
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	.LC0(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%r12, %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdx
	movq	%rsp, %rsi
	leaq	16(%rsp), %r15
	call	__isoc99_scanf@PLT
	cmpq	$0, 8(%rsp)
	jle	.L53
	xorl	%r13d, %r13d
	leaq	32(%rsp), %rbp
	leaq	24(%rsp), %rbx
	leaq	16(%rsp), %r15
	leaq	cost(%rip), %r14
	.p2align 4,,10
	.p2align 3
.L54:
	movq	%rbp, %rcx
	movq	%rbx, %rdx
	movq	%r15, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addq	$1, %r13
	call	__isoc99_scanf@PLT
	movq	24(%rsp), %rdi
	movq	16(%rsp), %rax
	movq	32(%rsp), %rsi
	leaq	-1(%rdi), %rdx
	subq	$1, %rax
	imulq	$310, %rdx, %rcx
	addq	%rax, %rcx
	imulq	$310, %rax, %rax
	movq	%rsi, (%r14,%rcx,8)
	addq	%rdx, %rax
	movq	%rsi, (%r14,%rax,8)
	cmpq	%r13, 8(%rsp)
	jg	.L54
.L53:
	movq	(%rsp), %rdi
	call	waasharuhuroido
	movq	%r15, %rsi
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movq	16(%rsp), %rax
	leaq	-1(%rax), %rdx
	movq	%rdx, 16(%rsp)
	testq	%rax, %rax
	je	.L55
	leaq	32(%rsp), %rbp
	leaq	24(%rsp), %rbx
	movabsq	$4611686016279904256, %r12
	leaq	.LC2(%rip), %r14
	leaq	cccc(%rip), %r13
	leaq	.LC3(%rip), %r15
	.p2align 4,,10
	.p2align 3
.L58:
	movq	%rbp, %rdx
	movq	%rbx, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movq	24(%rsp), %rax
	movq	32(%rsp), %rcx
	subq	$1, %rax
	leaq	-1(%rcx), %rdx
	movq	%rax, 24(%rsp)
	imulq	$310, %rax, %rax
	movq	%rdx, 32(%rsp)
	addq	%rdx, %rax
	movq	0(%r13,%rax,8), %rdx
	cmpq	%r12, %rdx
	jne	.L56
	movq	$-1, %rdx
.L56:
	movq	%r15, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	16(%rsp), %rax
	leaq	-1(%rax), %rdx
	movq	%rdx, 16(%rsp)
	testq	%rax, %rax
	jne	.L58
.L55:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L70
	addq	$56, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	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
.L70:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE57:
	.size	main, .-main
	.globl	cccc
	.bss
	.align 32
	.type	cccc, @object
	.size	cccc, 768800
cccc:
	.zero	768800
	.globl	dddd
	.align 32
	.type	dddd, @object
	.size	dddd, 768800
dddd:
	.zero	768800
	.globl	cost
	.align 32
	.type	cost, @object
	.size	cost, 768800
cost:
	.zero	768800
	.globl	L
	.align 8
	.type	L, @object
	.size	L, 8
L:
	.zero	8
	.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)

ll L;
//ワーシャルフロイド
//頂点数（と隣接行列）を引いて全点間最短距離を返す
//O(V^3)
ll cost[310][310];
ll dddd[310][310];
ll cccc[310][310];
void waasharuhuroido(ll n){
	rep(i,0,n)rep(j,0,n)if(i!=j){
		if(cost[i][j]&&cost[i][j]<=L){
			dddd[i][j]=cost[i][j];
		}else{
			dddd[i][j]=cccc[i][j]=INF;
		}
	}
	rep(_,0,3)rep(k,0,n)rep(i,0,n)rep(j,0,n){
		ll tempc=cccc[i][k]+cccc[k][j];
		ll tempd=dddd[i][k]+dddd[k][j];
		if(!(tempc==0&&tempd<=L)){
			tempc++;
			tempd=dddd[k][j];
		}
		
		if(cccc[i][j]>tempc||(cccc[i][j]==tempc&&dddd[i][j]>tempd)){
			cccc[i][j]=tempc;
			dddd[i][j]=tempd;
		}
//		rep(i,0,n){rep(j,0,n)printf("(%2d,%2d) ",cccc[i][j]==INF?99:cccc[i][j],dddd[i][j]==INF?99:dddd[i][j]);puts("");}puts("");
	}
}

int main(){
	ll n,m;
	scanf("%lld%lld%lld",&n,&m,&L);
	rep(i,0,m){
		ll x,y,z;
		scanf("%lld%lld%lld",&x,&y,&z);
		x--,y--;
		cost[x][y]=cost[y][x]=z;
	}
	waasharuhuroido(n);
	ll q;
	scanf("%lld",&q);
	while(q--){
		ll x,y;
		scanf("%lld%lld",&x,&y);
		x--,y--;
		ll ans=cccc[x][y];
		printf("%lld\n",ans==INF?-1:ans);
	}
}

4 0 0
1
2 1
 5 4 4
1 2 2
2 3 2
3 4 3
4 5 2
20
2 1
3 1
4 1
5 1
1 2
3 2
4 2
5 2
1 3
2 4
4 3
5 3
1 4
2 4
3 4
5 4
1 5
2 5
3 5
4 5
 5 4 4
1 2 2
2 3 2
3 4 3
4 5 2
20
2 1
3 1
3 1
5 1
1 2
3 2
4 2
5 2
1 3
2 3
4 3
5 3
1 4
2 4
3 4
5 4
1 5
2 5
3 5
4 5
 3 2 5
1 2 3
2 2 3
2
3 2
1 3
 5 4 4
1 2 4
2 3 2
3 4 3
4 5 2
20
2 1
3 1
4 1
5 1
1 2
3 2
4 2
5 2
1 3
2 4
4 3
5 3
1 4
2 4
3 4
5 4
1 5
2 5
3 5
4 5
 5 4 4
1 2 2
2 3 0
3 4 3
4 5 2
20
2 1
3 1
4 1
5 1
1 2
3 2
4 2
5 2
1 3
2 3
4 3
5 3
1 4
2 4
3 4
5 4
1 5
2 5
3 5
4 5
 5 4 4
1 2 4
2 3 2
3 4 3
4 5 2
20
2 1
3 1
4 1
5 1
1 4
3 2
4 2
5 2
1 3
2 4
4 3
5 3
1 4
2 4
3 4
5 4
1 5
2 5
3 5
4 5
 5 4 4
2 2 2
2 3 0
3 4 3
4 5 2
20
2 1
3 1
4 1
5 1
1 2
3 2
4 2
5 2
1 3
2 3
4 3
5 3
1 4
2 4
3 4
5 4
1 5
2 5
3 5
4 5
 5 4 4
2 2 2
2 3 0
3 4 3
4 5 2
20
2 1
3 1
4 1
5 1
1 2
3 2
4 2
5 2
1 3
2 5
4 3
5 3
1 4
2 4
3 4
5 4
1 5
2 5
3 5
4 5
 5 4 4
1 2 2
2 3 2
3 4 3
4 5 2
20
2 1
3 1
4 1
5 1
1 2
5 2
4 2
5 2
1 3
2 3
4 3
5 3
1 4
2 4
3 4
5 4
1 5
2 5
3 5
4 5

-1
 0
0
1
2
0
0
1
2
0
1
0
1
1
1
0
0
2
2
1
0
 0
0
0
2
0
0
1
2
0
0
0
1
1
1
0
0
2
2
1
0
 -1
-1
 0
1
2
3
0
0
1
2
1
1
0
1
2
1
0
0
3
2
1
0
 0
-1
-1
-1
0
-1
-1
-1
-1
-1
0
1
-1
-1
0
0
-1
-1
1
0
 0
1
2
3
2
0
1
2
1
1
0
1
2
1
0
0
3
2
1
0
 -1
-1
-1
-1
-1
-1
-1
-1
-1
-1
0
1
-1
-1
0
0
-1
-1
1
0
 -1
-1
-1
-1
-1
-1
-1
-1
-1
-1
0
1
-1
-1
0
0
-1
-1
1
0
 0
0
1
2
0
2
1
2
0
0
0
1
1
1
0
0
2
2
1
0

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)

ll L;
//ワーシャルフロイド
//頂点数（と隣接行列）を引いて全点間最短距離を返す
//O(V^3)
ll cost[310][310];
ll dddd[310][310];
ll cccc[310][310];
void waasharuhuroido(ll n){
	rep(i,0,n)rep(j,0,n)if(i!=j){
		if(cost[i][j]&&cost[i][j]<=L){
			dddd[i][j]=cost[i][j];
		}else{
			dddd[i][j]=cccc[i][j]=INF;
		}
	}
	rep(_,0,3)rep(k,0,n)rep(i,0,n)rep(j,0,n){
		ll tempc=cccc[i][k]+cccc[k][j];
		ll tempd=dddd[i][k]+dddd[k][j];
		if(!(tempc==0&&tempd<=L)){
			tempc++;
			tempd=dddd[k][j];
		}
		
		if(cccc[i][j]>tempc||(cccc[i][j]==tempc&&dddd[i][j]>tempd)){
			cccc[i][j]=tempc;
			dddd[i][j]=tempd;
		}
//		rep(i,0,n){rep(j,0,n)printf("(%2d,%2d) ",cccc[i][j]==INF?99:cccc[i][j],dddd[i][j]==INF?99:dddd[i][j]);puts("");}puts("");
	}
}

int main(){
	ll n,m;
	scanf("%lld%lld%lld",&n,&m,&L);
	rep(i,0,m){
		ll x,y,z;
		scanf("%lld%lld%lld",&x,&y,&z);
		x--,y--;
		cost[x][y]=cost[y][x]=z;
	}
	waasharuhuroido(n);
	ll q;
	scanf("%lld",&q);
	while(q--){
		ll x,y;
		scanf("%lld%lld",&x,&y);
		x--,y--;
		ll ans=cccc[x][y];
		printf("%lld\n",ans==INF?-1: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	L
	.bss
	.align 8
	.type	L, @object
	.size	L, 8
L:
	.zero	8
	.globl	cost
	.align 32
	.type	cost, @object
	.size	cost, 768800
cost:
	.zero	768800
	.globl	dddd
	.align 32
	.type	dddd, @object
	.size	dddd, 768800
dddd:
	.zero	768800
	.globl	cccc
	.align 32
	.type	cccc, @object
	.size	cccc, 768800
cccc:
	.zero	768800
	.text
	.globl	waasharuhuroido
	.type	waasharuhuroido, @function
waasharuhuroido:
.LFB11:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -72(%rbp)
	movq	$0, -64(%rbp)
	jmp	.L20
.L25:
	movq	$0, -56(%rbp)
	jmp	.L21
.L24:
	movq	-64(%rbp), %rax
	cmpq	-56(%rbp), %rax
	je	.L22
	movq	-64(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cost(%rip), %rax
	movq	(%rdx,%rax), %rax
	testq	%rax, %rax
	je	.L23
	movq	-64(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cost(%rip), %rax
	movq	(%rdx,%rax), %rdx
	movq	L(%rip), %rax
	cmpq	%rax, %rdx
	jg	.L23
	movq	-64(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cost(%rip), %rax
	movq	(%rdx,%rax), %rax
	movq	-64(%rbp), %rdx
	imulq	$310, %rdx, %rcx
	movq	-56(%rbp), %rdx
	addq	%rcx, %rdx
	leaq	0(,%rdx,8), %rcx
	leaq	dddd(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
	jmp	.L22
.L23:
	movq	-64(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cccc(%rip), %rax
	movabsq	$4611686016279904256, %rsi
	movq	%rsi, (%rdx,%rax)
	movq	-64(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cccc(%rip), %rax
	movq	(%rdx,%rax), %rax
	movq	-64(%rbp), %rdx
	imulq	$310, %rdx, %rcx
	movq	-56(%rbp), %rdx
	addq	%rcx, %rdx
	leaq	0(,%rdx,8), %rcx
	leaq	dddd(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
.L22:
	addq	$1, -56(%rbp)
.L21:
	movq	-56(%rbp), %rax
	cmpq	-72(%rbp), %rax
	jl	.L24
	addq	$1, -64(%rbp)
.L20:
	movq	-64(%rbp), %rax
	cmpq	-72(%rbp), %rax
	jl	.L25
	movq	$0, -48(%rbp)
	jmp	.L26
.L37:
	movq	$0, -40(%rbp)
	jmp	.L27
.L36:
	movq	$0, -32(%rbp)
	jmp	.L28
.L35:
	movq	$0, -24(%rbp)
	jmp	.L29
.L34:
	movq	-32(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cccc(%rip), %rax
	movq	(%rdx,%rax), %rcx
	movq	-40(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cccc(%rip), %rax
	movq	(%rdx,%rax), %rax
	addq	%rcx, %rax
	movq	%rax, -16(%rbp)
	movq	-32(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	dddd(%rip), %rax
	movq	(%rdx,%rax), %rcx
	movq	-40(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	dddd(%rip), %rax
	movq	(%rdx,%rax), %rax
	addq	%rcx, %rax
	movq	%rax, -8(%rbp)
	cmpq	$0, -16(%rbp)
	jne	.L30
	movq	L(%rip), %rax
	cmpq	%rax, -8(%rbp)
	jle	.L31
.L30:
	addq	$1, -16(%rbp)
	movq	-40(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	dddd(%rip), %rax
	movq	(%rdx,%rax), %rax
	movq	%rax, -8(%rbp)
.L31:
	movq	-32(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cccc(%rip), %rax
	movq	(%rdx,%rax), %rax
	cmpq	%rax, -16(%rbp)
	jl	.L32
	movq	-32(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cccc(%rip), %rax
	movq	(%rdx,%rax), %rax
	cmpq	%rax, -16(%rbp)
	jne	.L33
	movq	-32(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	dddd(%rip), %rax
	movq	(%rdx,%rax), %rax
	cmpq	%rax, -8(%rbp)
	jge	.L33
.L32:
	movq	-32(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rcx
	leaq	cccc(%rip), %rdx
	movq	-16(%rbp), %rax
	movq	%rax, (%rcx,%rdx)
	movq	-32(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rcx
	leaq	dddd(%rip), %rdx
	movq	-8(%rbp), %rax
	movq	%rax, (%rcx,%rdx)
.L33:
	addq	$1, -24(%rbp)
.L29:
	movq	-24(%rbp), %rax
	cmpq	-72(%rbp), %rax
	jl	.L34
	addq	$1, -32(%rbp)
.L28:
	movq	-32(%rbp), %rax
	cmpq	-72(%rbp), %rax
	jl	.L35
	addq	$1, -40(%rbp)
.L27:
	movq	-40(%rbp), %rax
	cmpq	-72(%rbp), %rax
	jl	.L36
	addq	$1, -48(%rbp)
.L26:
	cmpq	$2, -48(%rbp)
	jle	.L37
	nop
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE11:
	.size	waasharuhuroido, .-waasharuhuroido
	.section	.rodata
.LC0:
	.string	"%lld%lld%lld"
.LC1:
	.string	"%lld"
.LC2:
	.string	"%lld%lld"
.LC3:
	.string	"%lld\n"
	.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	$64, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-56(%rbp), %rdx
	leaq	-64(%rbp), %rax
	leaq	L(%rip), %rcx
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$0, -24(%rbp)
	jmp	.L39
.L40:
	leaq	-32(%rbp), %rcx
	leaq	-40(%rbp), %rdx
	leaq	-48(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-48(%rbp), %rax
	subq	$1, %rax
	movq	%rax, -48(%rbp)
	movq	-40(%rbp), %rax
	subq	$1, %rax
	movq	%rax, -40(%rbp)
	movq	-40(%rbp), %rax
	movq	-48(%rbp), %rdi
	movq	-32(%rbp), %rdx
	imulq	$310, %rax, %rcx
	addq	%rdi, %rcx
	leaq	0(,%rcx,8), %rsi
	leaq	cost(%rip), %rcx
	movq	%rdx, (%rsi,%rcx)
	movq	-48(%rbp), %rdx
	movq	-40(%rbp), %rsi
	imulq	$310, %rax, %rax
	addq	%rdi, %rax
	leaq	0(,%rax,8), %rcx
	leaq	cost(%rip), %rax
	movq	(%rcx,%rax), %rax
	imulq	$310, %rdx, %rdx
	addq	%rsi, %rdx
	leaq	0(,%rdx,8), %rcx
	leaq	cost(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
	addq	$1, -24(%rbp)
.L39:
	movq	-56(%rbp), %rax
	cmpq	%rax, -24(%rbp)
	jl	.L40
	movq	-64(%rbp), %rax
	movq	%rax, %rdi
	call	waasharuhuroido
	leaq	-48(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L41
.L44:
	leaq	-32(%rbp), %rdx
	leaq	-40(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-40(%rbp), %rax
	subq	$1, %rax
	movq	%rax, -40(%rbp)
	movq	-32(%rbp), %rax
	subq	$1, %rax
	movq	%rax, -32(%rbp)
	movq	-40(%rbp), %rax
	movq	-32(%rbp), %rdx
	imulq	$310, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cccc(%rip), %rax
	movq	(%rdx,%rax), %rax
	movq	%rax, -16(%rbp)
	movabsq	$4611686016279904256, %rax
	cmpq	%rax, -16(%rbp)
	je	.L42
	movq	-16(%rbp), %rax
	jmp	.L43
.L42:
	movq	$-1, %rax
.L43:
	movq	%rax, %rsi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L41:
	movq	-48(%rbp), %rax
	leaq	-1(%rax), %rdx
	movq	%rdx, -48(%rbp)
	testq	%rax, %rax
	jne	.L44
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L46
	call	__stack_chk_fail@PLT
.L46:
	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	L
	.bss
	.align 8
	.type	L, @object
	.size	L, 8
L:
	.zero	8
	.globl	cost
	.align 32
	.type	cost, @object
	.size	cost, 768800
cost:
	.zero	768800
	.globl	dddd
	.align 32
	.type	dddd, @object
	.size	dddd, 768800
dddd:
	.zero	768800
	.globl	cccc
	.align 32
	.type	cccc, @object
	.size	cccc, 768800
cccc:
	.zero	768800
	.text
	.globl	waasharuhuroido
	.type	waasharuhuroido, @function
waasharuhuroido:
.LFB11:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -72(%rbp)
	movq	$0, -64(%rbp)
	jmp	.L20
.L25:
	movq	$0, -56(%rbp)
	jmp	.L21
.L24:
	movq	-64(%rbp), %rax
	cmpq	-56(%rbp), %rax
	je	.L22
	movq	-64(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cost(%rip), %rax
	movq	(%rdx,%rax), %rax
	testq	%rax, %rax
	je	.L23
	movq	-64(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cost(%rip), %rax
	movq	(%rdx,%rax), %rdx
	movq	L(%rip), %rax
	cmpq	%rax, %rdx
	jg	.L23
	movq	-64(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cost(%rip), %rax
	movq	(%rdx,%rax), %rax
	movq	-64(%rbp), %rdx
	imulq	$310, %rdx, %rcx
	movq	-56(%rbp), %rdx
	addq	%rcx, %rdx
	leaq	0(,%rdx,8), %rcx
	leaq	dddd(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
	jmp	.L22
.L23:
	movq	-64(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cccc(%rip), %rax
	movabsq	$4611686016279904256, %rsi
	movq	%rsi, (%rdx,%rax)
	movq	-64(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cccc(%rip), %rax
	movq	(%rdx,%rax), %rax
	movq	-64(%rbp), %rdx
	imulq	$310, %rdx, %rcx
	movq	-56(%rbp), %rdx
	addq	%rcx, %rdx
	leaq	0(,%rdx,8), %rcx
	leaq	dddd(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
.L22:
	addq	$1, -56(%rbp)
.L21:
	movq	-56(%rbp), %rax
	cmpq	-72(%rbp), %rax
	jl	.L24
	addq	$1, -64(%rbp)
.L20:
	movq	-64(%rbp), %rax
	cmpq	-72(%rbp), %rax
	jl	.L25
	movq	$0, -48(%rbp)
	jmp	.L26
.L37:
	movq	$0, -40(%rbp)
	jmp	.L27
.L36:
	movq	$0, -32(%rbp)
	jmp	.L28
.L35:
	movq	$0, -24(%rbp)
	jmp	.L29
.L34:
	movq	-32(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cccc(%rip), %rax
	movq	(%rdx,%rax), %rcx
	movq	-40(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cccc(%rip), %rax
	movq	(%rdx,%rax), %rax
	addq	%rcx, %rax
	movq	%rax, -16(%rbp)
	movq	-32(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	dddd(%rip), %rax
	movq	(%rdx,%rax), %rcx
	movq	-40(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	dddd(%rip), %rax
	movq	(%rdx,%rax), %rax
	addq	%rcx, %rax
	movq	%rax, -8(%rbp)
	cmpq	$0, -16(%rbp)
	jne	.L30
	movq	L(%rip), %rax
	cmpq	%rax, -8(%rbp)
	jle	.L31
.L30:
	addq	$1, -16(%rbp)
	movq	-40(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	dddd(%rip), %rax
	movq	(%rdx,%rax), %rax
	movq	%rax, -8(%rbp)
.L31:
	movq	-32(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cccc(%rip), %rax
	movq	(%rdx,%rax), %rax
	cmpq	%rax, -16(%rbp)
	jl	.L32
	movq	-32(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cccc(%rip), %rax
	movq	(%rdx,%rax), %rax
	cmpq	%rax, -16(%rbp)
	jne	.L33
	movq	-32(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	dddd(%rip), %rax
	movq	(%rdx,%rax), %rax
	cmpq	%rax, -8(%rbp)
	jge	.L33
.L32:
	movq	-32(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rcx
	leaq	cccc(%rip), %rdx
	movq	-16(%rbp), %rax
	movq	%rax, (%rcx,%rdx)
	movq	-32(%rbp), %rax
	imulq	$310, %rax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rcx
	leaq	dddd(%rip), %rdx
	movq	-8(%rbp), %rax
	movq	%rax, (%rcx,%rdx)
.L33:
	addq	$1, -24(%rbp)
.L29:
	movq	-24(%rbp), %rax
	cmpq	-72(%rbp), %rax
	jl	.L34
	addq	$1, -32(%rbp)
.L28:
	movq	-32(%rbp), %rax
	cmpq	-72(%rbp), %rax
	jl	.L35
	addq	$1, -40(%rbp)
.L27:
	movq	-40(%rbp), %rax
	cmpq	-72(%rbp), %rax
	jl	.L36
	addq	$1, -48(%rbp)
.L26:
	cmpq	$2, -48(%rbp)
	jle	.L37
	nop
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE11:
	.size	waasharuhuroido, .-waasharuhuroido
	.section	.rodata
.LC0:
	.string	"%lld%lld%lld"
.LC1:
	.string	"%lld"
.LC2:
	.string	"%lld%lld"
.LC3:
	.string	"%lld\n"
	.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	$64, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-56(%rbp), %rdx
	leaq	-64(%rbp), %rax
	leaq	L(%rip), %rcx
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$0, -24(%rbp)
	jmp	.L39
.L40:
	leaq	-32(%rbp), %rcx
	leaq	-40(%rbp), %rdx
	leaq	-48(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-48(%rbp), %rax
	subq	$1, %rax
	movq	%rax, -48(%rbp)
	movq	-40(%rbp), %rax
	subq	$1, %rax
	movq	%rax, -40(%rbp)
	movq	-40(%rbp), %rax
	movq	-48(%rbp), %rdi
	movq	-32(%rbp), %rdx
	imulq	$310, %rax, %rcx
	addq	%rdi, %rcx
	leaq	0(,%rcx,8), %rsi
	leaq	cost(%rip), %rcx
	movq	%rdx, (%rsi,%rcx)
	movq	-48(%rbp), %rdx
	movq	-40(%rbp), %rsi
	imulq	$310, %rax, %rax
	addq	%rdi, %rax
	leaq	0(,%rax,8), %rcx
	leaq	cost(%rip), %rax
	movq	(%rcx,%rax), %rax
	imulq	$310, %rdx, %rdx
	addq	%rsi, %rdx
	leaq	0(,%rdx,8), %rcx
	leaq	cost(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
	addq	$1, -24(%rbp)
.L39:
	movq	-56(%rbp), %rax
	cmpq	%rax, -24(%rbp)
	jl	.L40
	movq	-64(%rbp), %rax
	movq	%rax, %rdi
	call	waasharuhuroido
	leaq	-48(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L41
.L44:
	leaq	-32(%rbp), %rdx
	leaq	-40(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-40(%rbp), %rax
	subq	$1, %rax
	movq	%rax, -40(%rbp)
	movq	-32(%rbp), %rax
	subq	$1, %rax
	movq	%rax, -32(%rbp)
	movq	-40(%rbp), %rax
	movq	-32(%rbp), %rdx
	imulq	$310, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,8), %rdx
	leaq	cccc(%rip), %rax
	movq	(%rdx,%rax), %rax
	movq	%rax, -16(%rbp)
	movabsq	$4611686016279904256, %rax
	cmpq	%rax, -16(%rbp)
	je	.L42
	movq	-16(%rbp), %rax
	jmp	.L43
.L42:
	movq	$-1, %rax
.L43:
	movq	%rax, %rsi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L41:
	movq	-48(%rbp), %rax
	leaq	-1(%rax), %rdx
	movq	%rdx, -48(%rbp)
	testq	%rax, %rax
	jne	.L44
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L46
	call	__stack_chk_fail@PLT
.L46:
	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:
