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

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, long long);
int /*<<< orphan*/ scanf(char *, long long *, ...);
int main() {
  long long int m, n, sum = 0, x;
  int i;
  while (1) {
    sum = 0;
    scanf("%lld%lld", &n, &m);
    if (n == -1 && m == -1)
      break;
    for (i = n; i >= 1; i--) {
      scanf("%lld", &x);
      sum += (x * i);
    }
    sum *= m;
    printf("%lld\n", sum);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    1170 <main+0x50>
cmpq   $0xffffffffffffffff,-0x10(%rbp)
jne    1170 <main+0x50>
jmp    11d7 <main+0xb7>
mov    -0x18(%rbp),%rax
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jl     11b5 <main+0x95>
lea    0xe7c(%rip),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   %rcx,%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    1177 <main+0x57>
mov    -0x10(%rbp),%rax
imul   -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe3c(%rip),%rdi
call   1030 <printf@plt>
jmp    1137 <main+0x17>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xecb(%rip),%rdi
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x8(%rsp),%rax
mov    (%rsp),%rsi
cmp    $0xffffffffffffffff,%rax
jne    115d <main+0x3d>
cmp    $0xffffffffffffffff,%rsi
je     11fc <main+0xdc>
lea    0xea0(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r13
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
test   %eax,%eax
jle    11c0 <main+0xa0>
mov    %eax,%r12d
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x10(%rsp),%rax
imul   %r12,%rax
add    %rax,%r15
lea    -0x1(%r12),%rax
cmp    $0x1,%r12
mov    %rax,%r12
ja     1190 <main+0x70>
mov    (%rsp),%rsi
jmp    11c3 <main+0xa3>
nopl   (%rax)
xor    %r15d,%r15d
imul   %r15,%rsi
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
lea    0xe26(%rip),%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x8(%rsp),%rax
mov    (%rsp),%rsi
cmp    $0xffffffffffffffff,%rax
jne    1180 <main+0x60>
cmp    $0xffffffffffffffff,%rsi
jne    1180 <main+0x60>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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