#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 *, int);
int /*<<< orphan*/ scanf(char *, int *, int *, int *, int *);
int main() {
  int s, a, b, c;
  while (1) {
    scanf("%d %d %d %d", &s, &a, &b, &c);
    if (!s && !a && !b && !c)
      break;
    printf("%d\n",
           (120 + (s - a + 40) % 40 + (b - a + 40) % 40 + (b - c + 40) % 40) *
               9);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%r8
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1178 <main+0x58>
cmpl   $0x0,-0xc(%rbp)
jne    1178 <main+0x58>
cmpl   $0x0,-0x10(%rbp)
jne    1178 <main+0x58>
cmpl   $0x0,-0x14(%rbp)
jne    1178 <main+0x58>
jmp    11d2 <main+0xb2>
mov    -0x8(%rbp),%eax
sub    -0xc(%rbp),%eax
add    $0x28,%eax
mov    $0x28,%ecx
cltd
idiv   %ecx
add    $0x78,%edx
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
add    $0x28,%eax
mov    $0x28,%ecx
cltd
idiv   %ecx
mov    -0x1c(%rbp),%eax
add    %edx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
sub    -0x14(%rbp),%eax
add    $0x28,%eax
mov    $0x28,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%eax
add    %edx,%eax
imul   $0x9,%eax,%esi
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
jmp    112f <main+0xf>
xor    %eax,%eax
add    $0x20,%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    0x14(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r13
lea    0x8(%rsp),%rbx
lea    0xec3(%rip),%r14
jmp    11d2 <main+0xb2>
xchg   %ax,%ax
sub    %edx,%esi
add    $0x28,%esi
movslq %esi,%rsi
imul   $0x66666667,%rsi,%rdi
mov    %rdi,%rbp
shr    $0x3f,%rbp
sar    $0x24,%rdi
add    %ebp,%edi
shl    $0x3,%edi
lea    (%rdi,%rdi,4),%edi
sub    %edi,%esi
mov    %eax,%edi
sub    %edx,%edi
add    $0x28,%edi
movslq %edi,%rdx
imul   $0x66666667,%rdx,%rdi
mov    %rdi,%rbp
shr    $0x3f,%rbp
sar    $0x24,%rdi
add    %ebp,%edi
shl    $0x3,%edi
lea    (%rdi,%rdi,4),%edi
sub    %edi,%edx
add    %esi,%edx
sub    %ecx,%eax
add    $0x28,%eax
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
sar    $0x24,%rcx
add    %esi,%ecx
shl    $0x3,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
add    %edx,%eax
lea    (%rax,%rax,8),%esi
add    $0x438,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
lea    0xe27(%rip),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbx,%r8
call   1040 <scanf@plt>
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
mov    0xc(%rsp),%eax
mov    0x8(%rsp),%ecx
test   %esi,%esi
jne    1150 <main+0x30>
test   %edx,%edx
jne    1150 <main+0x30>
test   %eax,%eax
jne    1150 <main+0x30>
test   %ecx,%ecx
jne    1150 <main+0x30>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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