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

/* Forward declarations */

/* Type definitions */
typedef scalar_t__ int16_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, scalar_t__);
scalar_t__ scanf(char *, ...);
int main() {
  int16_t t, j, n, s;
  char x[10];
  while (scanf("%d %d", &t, &j) && t != 0) {
    s = 0;
    while (t--) {
      scanf("%s %d", x, &n);
      s += n;
    }
    printf("%d\n", j * 3 - s);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x33(%rbp)
je     1162 <main+0x42>
cmpq   $0x0,-0x10(%rbp)
setne  %al
mov    %al,-0x33(%rbp)
mov    -0x33(%rbp),%al
test   $0x1,%al
jne    1172 <main+0x52>
jmp    11d4 <main+0xb4>
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
cmp    $0x0,%rax
je     11ba <main+0x9a>
lea    -0x32(%rbp),%rsi
lea    0xe68(%rip),%rdi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    117a <main+0x5a>
imul   $0x3,-0x18(%rbp),%rsi
sub    -0x28(%rbp),%rsi
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
jmp    112f <main+0xf>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xecb(%rip),%rdi
mov    %rsp,%rsi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
test   %rax,%rax
je     11e6 <main+0xc6>
mov    (%rsp),%rax
test   %rax,%rax
je     11e6 <main+0xc6>
lea    0xea5(%rip),%r14
lea    0x1e(%rsp),%r15
lea    0x10(%rsp),%rbx
mov    %rsp,%rbp
lea    0x8(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0xffffffffffffffff,%rax
mov    %rax,(%rsp)
xor    %r13d,%r13d
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
add    0x10(%rsp),%r13
subq   $0x1,(%rsp)
jae    1190 <main+0x70>
mov    0x8(%rsp),%rax
lea    (%rax,%rax,2),%rsi
sub    %r13,%rsi
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
lea    0xe35(%rip),%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
test   %rax,%rax
je     11e6 <main+0xc6>
mov    (%rsp),%rax
test   %rax,%rax
jne    1180 <main+0x60>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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