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>
#define M 100001

int A[M];

long int sumA(void){
    long int sum;
    sum = 0;
    for(int i=0; i<M; i++){
        sum = sum + i*A[i];
    }
    return sum;
}

int main(void){
    for(int i=0; i<M; i++){
        A[M] = 0;
    }

    int N;
    scanf("%d", &N);

    int tmp;

    for(int i=0; i<N; i++){
        scanf("%d", &tmp);
        A[tmp]++;
    }

    long int sum;
    sum = sumA();

    int Q, B, C;
    scanf("%d", &Q);

    for(int i=0; i<Q; i++){
        scanf("%d %d", &B, &C);
        sum += (C-B)*A[B];
        A[C] += A[B];
        A[B] = 0;
        printf("%ld\n", sum);
    }

    return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	A
	.bss
	.align 32
	.type	A, @object
	.size	A, 400004
A:
	.zero	400004
	.text
	.globl	sumA
	.type	sumA, @function
sumA:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	$0, -8(%rbp)
	movl	$0, -12(%rbp)
	jmp	.L2
.L3:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	imull	-12(%rbp), %eax
	cltq
	addq	%rax, -8(%rbp)
	addl	$1, -12(%rbp)
.L2:
	cmpl	$100000, -12(%rbp)
	jle	.L3
	movq	-8(%rbp), %rax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	sumA, .-sumA
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d"
.LC2:
	.string	"%ld\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$48, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -28(%rbp)
	jmp	.L6
.L7:
	movl	$0, 400004+A(%rip)
	addl	$1, -28(%rbp)
.L6:
	cmpl	$100000, -28(%rbp)
	jle	.L7
	leaq	-48(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -24(%rbp)
	jmp	.L8
.L9:
	leaq	-44(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-44(%rbp), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	addl	$1, -24(%rbp)
.L8:
	movl	-48(%rbp), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L9
	call	sumA
	movq	%rax, -16(%rbp)
	leaq	-40(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -20(%rbp)
	jmp	.L10
.L11:
	leaq	-32(%rbp), %rdx
	leaq	-36(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-32(%rbp), %eax
	movl	-36(%rbp), %edx
	subl	%edx, %eax
	movl	%eax, %ecx
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	imull	%ecx, %eax
	cltq
	addq	%rax, -16(%rbp)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-32(%rbp), %eax
	addl	%edx, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	$0, (%rdx,%rax)
	movq	-16(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -20(%rbp)
.L10:
	movl	-40(%rbp), %eax
	cmpl	%eax, -20(%rbp)
	jl	.L11
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.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	sumA
	.type	sumA, @function
sumA:
.LFB39:
	.cfi_startproc
	endbr64
	leaq	A(%rip), %rax
	movdqa	.LC0(%rip), %xmm4
	pxor	%xmm0, %xmm0
	pxor	%xmm5, %xmm5
	movdqa	.LC1(%rip), %xmm6
	leaq	400000(%rax), %rdx
	.p2align 4,,10
	.p2align 3
.L2:
	movdqa	(%rax), %xmm3
	movdqa	%xmm4, %xmm2
	addq	$16, %rax
	paddd	%xmm6, %xmm4
	movdqa	%xmm2, %xmm1
	psrlq	$32, %xmm2
	pmuludq	-16(%rax), %xmm1
	pshufd	$8, %xmm1, %xmm1
	psrlq	$32, %xmm3
	pmuludq	%xmm3, %xmm2
	pshufd	$8, %xmm2, %xmm2
	punpckldq	%xmm2, %xmm1
	movdqa	%xmm5, %xmm2
	pcmpgtd	%xmm1, %xmm2
	movdqa	%xmm1, %xmm3
	punpckldq	%xmm2, %xmm3
	punpckhdq	%xmm2, %xmm1
	paddq	%xmm3, %xmm0
	paddq	%xmm1, %xmm0
	cmpq	%rax, %rdx
	jne	.L2
	imull	$100000, 400000+A(%rip), %eax
	movdqa	%xmm0, %xmm1
	psrldq	$8, %xmm1
	paddq	%xmm1, %xmm0
	movq	%xmm0, %rdx
	cltq
	addq	%rdx, %rax
	ret
	.cfi_endproc
.LFE39:
	.size	sumA, .-sumA
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"%d"
.LC3:
	.string	"%d %d"
.LC4:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB40:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC2(%rip), %rdi
	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
	leaq	A(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	20(%rsp), %rsi
	leaq	24(%rsp), %r12
	movl	$0, 400004+A(%rip)
	call	__isoc99_scanf@PLT
	movl	20(%rsp), %edx
	leaq	.LC2(%rip), %rdi
	testl	%edx, %edx
	jle	.L8
	.p2align 4,,10
	.p2align 3
.L6:
	xorl	%eax, %eax
	movq	%r12, %rsi
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movslq	24(%rsp), %rax
	leaq	.LC2(%rip), %rdi
	addl	$1, 0(%rbp,%rax,4)
	cmpl	%ebx, 20(%rsp)
	jg	.L6
.L8:
	leaq	A(%rip), %rax
	movdqa	.LC0(%rip), %xmm4
	pxor	%xmm0, %xmm0
	pxor	%xmm5, %xmm5
	movdqa	.LC1(%rip), %xmm6
	leaq	400000(%rax), %rdx
	.p2align 4,,10
	.p2align 3
.L7:
	movdqa	(%rax), %xmm3
	movdqa	%xmm4, %xmm2
	addq	$16, %rax
	paddd	%xmm6, %xmm4
	movdqa	%xmm2, %xmm1
	psrlq	$32, %xmm2
	pmuludq	-16(%rax), %xmm1
	pshufd	$8, %xmm1, %xmm1
	psrlq	$32, %xmm3
	pmuludq	%xmm3, %xmm2
	pshufd	$8, %xmm2, %xmm2
	punpckldq	%xmm2, %xmm1
	movdqa	%xmm5, %xmm2
	pcmpgtd	%xmm1, %xmm2
	movdqa	%xmm1, %xmm3
	punpckldq	%xmm2, %xmm3
	punpckhdq	%xmm2, %xmm1
	paddq	%xmm3, %xmm0
	paddq	%xmm1, %xmm0
	cmpq	%rax, %rdx
	jne	.L7
	imull	$100000, 400000+A(%rip), %edx
	movdqa	%xmm0, %xmm1
	leaq	28(%rsp), %rsi
	psrldq	$8, %xmm1
	paddq	%xmm1, %xmm0
	movq	%xmm0, %rax
	movslq	%edx, %rdx
	leaq	(%rdx,%rax), %rbx
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %eax
	testl	%eax, %eax
	jle	.L10
	xorl	%r12d, %r12d
	leaq	36(%rsp), %rcx
	leaq	32(%rsp), %r15
	leaq	.LC3(%rip), %r14
	leaq	.LC4(%rip), %r13
.L9:
	movq	%rcx, %rdx
	movq	%r15, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	movq	%rcx, 8(%rsp)
	addl	$1, %r12d
	call	__isoc99_scanf@PLT
	movslq	32(%rsp), %rsi
	movslq	36(%rsp), %rax
	movl	0(%rbp,%rsi,4), %edi
	movl	%eax, %edx
	addl	%edi, 0(%rbp,%rax,4)
	xorl	%eax, %eax
	subl	%esi, %edx
	movl	$0, 0(%rbp,%rsi,4)
	movq	%r13, %rsi
	imull	%edi, %edx
	movl	$1, %edi
	movslq	%edx, %rdx
	addq	%rdx, %rbx
	movq	%rbx, %rdx
	call	__printf_chk@PLT
	cmpl	%r12d, 28(%rsp)
	movq	8(%rsp), %rcx
	jg	.L9
	.p2align 4,,10
	.p2align 3
.L10:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L23
	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
.L23:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE40:
	.size	main, .-main
	.globl	A
	.bss
	.align 32
	.type	A, @object
	.size	A, 400004
A:
	.zero	400004
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC0:
	.long	0
	.long	1
	.long	2
	.long	3
	.align 16
.LC1:
	.long	4
	.long	4
	.long	4
	.long	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	sumA
	.type	sumA, @function
sumA:
.LFB39:
	.cfi_startproc
	endbr64
	leaq	A(%rip), %rax
	movdqa	.LC0(%rip), %xmm4
	pxor	%xmm0, %xmm0
	pxor	%xmm5, %xmm5
	movdqa	.LC1(%rip), %xmm6
	leaq	400000(%rax), %rdx
	.p2align 4,,10
	.p2align 3
.L2:
	movdqa	(%rax), %xmm3
	movdqa	%xmm4, %xmm2
	addq	$16, %rax
	paddd	%xmm6, %xmm4
	movdqa	%xmm2, %xmm1
	psrlq	$32, %xmm2
	pmuludq	-16(%rax), %xmm1
	pshufd	$8, %xmm1, %xmm1
	psrlq	$32, %xmm3
	pmuludq	%xmm3, %xmm2
	pshufd	$8, %xmm2, %xmm2
	punpckldq	%xmm2, %xmm1
	movdqa	%xmm5, %xmm2
	pcmpgtd	%xmm1, %xmm2
	movdqa	%xmm1, %xmm3
	punpckldq	%xmm2, %xmm3
	punpckhdq	%xmm2, %xmm1
	paddq	%xmm3, %xmm0
	paddq	%xmm1, %xmm0
	cmpq	%rax, %rdx
	jne	.L2
	imull	$100000, 400000+A(%rip), %eax
	movdqa	%xmm0, %xmm1
	psrldq	$8, %xmm1
	paddq	%xmm1, %xmm0
	movq	%xmm0, %rdx
	cltq
	addq	%rdx, %rax
	ret
	.cfi_endproc
.LFE39:
	.size	sumA, .-sumA
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"%d"
.LC3:
	.string	"%d %d"
.LC4:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB40:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC2(%rip), %rdi
	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
	leaq	A(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	20(%rsp), %rsi
	leaq	24(%rsp), %r12
	movl	$0, 400004+A(%rip)
	call	__isoc99_scanf@PLT
	movl	20(%rsp), %edx
	leaq	.LC2(%rip), %rdi
	testl	%edx, %edx
	jle	.L8
	.p2align 4,,10
	.p2align 3
.L6:
	xorl	%eax, %eax
	movq	%r12, %rsi
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movslq	24(%rsp), %rax
	leaq	.LC2(%rip), %rdi
	addl	$1, 0(%rbp,%rax,4)
	cmpl	%ebx, 20(%rsp)
	jg	.L6
.L8:
	leaq	A(%rip), %rax
	movdqa	.LC0(%rip), %xmm4
	pxor	%xmm0, %xmm0
	pxor	%xmm5, %xmm5
	movdqa	.LC1(%rip), %xmm6
	leaq	400000(%rax), %rdx
	.p2align 4,,10
	.p2align 3
.L7:
	movdqa	(%rax), %xmm3
	movdqa	%xmm4, %xmm2
	addq	$16, %rax
	paddd	%xmm6, %xmm4
	movdqa	%xmm2, %xmm1
	psrlq	$32, %xmm2
	pmuludq	-16(%rax), %xmm1
	pshufd	$8, %xmm1, %xmm1
	psrlq	$32, %xmm3
	pmuludq	%xmm3, %xmm2
	pshufd	$8, %xmm2, %xmm2
	punpckldq	%xmm2, %xmm1
	movdqa	%xmm5, %xmm2
	pcmpgtd	%xmm1, %xmm2
	movdqa	%xmm1, %xmm3
	punpckldq	%xmm2, %xmm3
	punpckhdq	%xmm2, %xmm1
	paddq	%xmm3, %xmm0
	paddq	%xmm1, %xmm0
	cmpq	%rax, %rdx
	jne	.L7
	imull	$100000, 400000+A(%rip), %edx
	movdqa	%xmm0, %xmm1
	leaq	28(%rsp), %rsi
	psrldq	$8, %xmm1
	paddq	%xmm1, %xmm0
	movq	%xmm0, %rax
	movslq	%edx, %rdx
	leaq	(%rdx,%rax), %rbx
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %eax
	testl	%eax, %eax
	jle	.L10
	xorl	%r12d, %r12d
	leaq	36(%rsp), %rcx
	leaq	32(%rsp), %r15
	leaq	.LC3(%rip), %r14
	leaq	.LC4(%rip), %r13
.L9:
	movq	%rcx, %rdx
	movq	%r15, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	movq	%rcx, 8(%rsp)
	addl	$1, %r12d
	call	__isoc99_scanf@PLT
	movslq	32(%rsp), %rsi
	movslq	36(%rsp), %rax
	movl	0(%rbp,%rsi,4), %edi
	movl	%eax, %edx
	addl	%edi, 0(%rbp,%rax,4)
	xorl	%eax, %eax
	subl	%esi, %edx
	movl	$0, 0(%rbp,%rsi,4)
	movq	%r13, %rsi
	imull	%edi, %edx
	movl	$1, %edi
	movslq	%edx, %rdx
	addq	%rdx, %rbx
	movq	%rbx, %rdx
	call	__printf_chk@PLT
	cmpl	%r12d, 28(%rsp)
	movq	8(%rsp), %rcx
	jg	.L9
	.p2align 4,,10
	.p2align 3
.L10:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L23
	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
.L23:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE40:
	.size	main, .-main
	.globl	A
	.bss
	.align 32
	.type	A, @object
	.size	A, 400004
A:
	.zero	400004
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC0:
	.long	0
	.long	1
	.long	2
	.long	3
	.align 16
.LC1:
	.long	4
	.long	4
	.long	4
	.long	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>
#define M 100001

int A[M];

long int sumA(void){
    long int sum;
    sum = 0;
    for(int i=0; i<M; i++){
        sum = sum + i*A[i];
    }
    return sum;
}

int main(void){
    for(int i=0; i<M; i++){
        A[M] = 0;
    }

    int N;
    scanf("%d", &N);

    int tmp;

    for(int i=0; i<N; i++){
        scanf("%d", &tmp);
        A[tmp]++;
    }

    long int sum;
    sum = sumA();

    int Q, B, C;
    scanf("%d", &Q);

    for(int i=0; i<Q; i++){
        scanf("%d %d", &B, &C);
        sum += (C-B)*A[B];
        A[C] += A[B];
        A[B] = 0;
        printf("%ld\n", sum);
    }

    return 0;
}
4
1 2 3 3
3
1 2
3 4
2 4
 4
2 1 1 1
3
1 2
2 1
3 5
 4
1 2 3 3
3
1 2
3 4
0 4
 4
0 1 1 1
3
1 2
2 1
3 5
 4
1 3 3 3
3
1 2
3 4
0 4
 4
1 3 4 3
3
1 2
3 4
0 4
 4
0 1 1 1
3
1 4
2 1
5 10
 4
0 2 4 3
3
1 2
3 4
0 4
 4
0 1 1 1
3
1 0
2 1
5 10
 4
0 2 1 1
3
1 0
2 1
5 10

10
12
16
 8
4
4
 10
12
12
 6
3
3
 11
14
14
 12
14
14
 12
12
12
 9
10
14
 0
0
0
 2
1
1

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>
#define M 100001

int A[M];

long int sumA(void){
    long int sum;
    sum = 0;
    for(int i=0; i<M; i++){
        sum = sum + i*A[i];
    }
    return sum;
}

int main(void){
    for(int i=0; i<M; i++){
        A[M] = 0;
    }

    int N;
    scanf("%d", &N);

    int tmp;

    for(int i=0; i<N; i++){
        scanf("%d", &tmp);
        A[tmp]++;
    }

    long int sum;
    sum = sumA();

    int Q, B, C;
    scanf("%d", &Q);

    for(int i=0; i<Q; i++){
        scanf("%d %d", &B, &C);
        sum += (C-B)*A[B];
        A[C] += A[B];
        A[B] = 0;
        printf("%ld\n", sum);
    }

    return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	A
	.bss
	.align 32
	.type	A, @object
	.size	A, 400004
A:
	.zero	400004
	.text
	.globl	sumA
	.type	sumA, @function
sumA:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	$0, -8(%rbp)
	movl	$0, -12(%rbp)
	jmp	.L2
.L3:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	imull	-12(%rbp), %eax
	cltq
	addq	%rax, -8(%rbp)
	addl	$1, -12(%rbp)
.L2:
	cmpl	$100000, -12(%rbp)
	jle	.L3
	movq	-8(%rbp), %rax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	sumA, .-sumA
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d"
.LC2:
	.string	"%ld\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$48, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -28(%rbp)
	jmp	.L6
.L7:
	movl	$0, 400004+A(%rip)
	addl	$1, -28(%rbp)
.L6:
	cmpl	$100000, -28(%rbp)
	jle	.L7
	leaq	-48(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -24(%rbp)
	jmp	.L8
.L9:
	leaq	-44(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-44(%rbp), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	addl	$1, -24(%rbp)
.L8:
	movl	-48(%rbp), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L9
	call	sumA
	movq	%rax, -16(%rbp)
	leaq	-40(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -20(%rbp)
	jmp	.L10
.L11:
	leaq	-32(%rbp), %rdx
	leaq	-36(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-32(%rbp), %eax
	movl	-36(%rbp), %edx
	subl	%edx, %eax
	movl	%eax, %ecx
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	imull	%ecx, %eax
	cltq
	addq	%rax, -16(%rbp)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-32(%rbp), %eax
	addl	%edx, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	$0, (%rdx,%rax)
	movq	-16(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -20(%rbp)
.L10:
	movl	-40(%rbp), %eax
	cmpl	%eax, -20(%rbp)
	jl	.L11
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.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	A
	.bss
	.align 32
	.type	A, @object
	.size	A, 400004
A:
	.zero	400004
	.text
	.globl	sumA
	.type	sumA, @function
sumA:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	$0, -8(%rbp)
	movl	$0, -12(%rbp)
	jmp	.L2
.L3:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	imull	-12(%rbp), %eax
	cltq
	addq	%rax, -8(%rbp)
	addl	$1, -12(%rbp)
.L2:
	cmpl	$100000, -12(%rbp)
	jle	.L3
	movq	-8(%rbp), %rax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	sumA, .-sumA
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d"
.LC2:
	.string	"%ld\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$48, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -28(%rbp)
	jmp	.L6
.L7:
	movl	$0, 400004+A(%rip)
	addl	$1, -28(%rbp)
.L6:
	cmpl	$100000, -28(%rbp)
	jle	.L7
	leaq	-48(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -24(%rbp)
	jmp	.L8
.L9:
	leaq	-44(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-44(%rbp), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	addl	$1, -24(%rbp)
.L8:
	movl	-48(%rbp), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L9
	call	sumA
	movq	%rax, -16(%rbp)
	leaq	-40(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -20(%rbp)
	jmp	.L10
.L11:
	leaq	-32(%rbp), %rdx
	leaq	-36(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-32(%rbp), %eax
	movl	-36(%rbp), %edx
	subl	%edx, %eax
	movl	%eax, %ecx
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	imull	%ecx, %eax
	cltq
	addq	%rax, -16(%rbp)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-32(%rbp), %eax
	addl	%edx, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	$0, (%rdx,%rax)
	movq	-16(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -20(%rbp)
.L10:
	movl	-40(%rbp), %eax
	cmpl	%eax, -20(%rbp)
	jl	.L11
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.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:
