#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 /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int n, a, b;
  scanf("%d %d", &n, &a);
  if (n == 1) {
    if (a == 0) {
      printf("UP");
    } else if (a == 15) {
      printf("DOWN");
    } else {
      printf("-1");
    }
    return 0;
  }
  scanf("%d", &b);
  a += 2 * (b < a) * (15 - a) + n - 1;
  a %= 30;
  if (a <= 14) {
    printf("UP");
  } else {
    printf("DOWN");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    11a2 <main+0x82>
cmpl   $0x0,-0xc(%rbp)
jne    116a <main+0x4a>
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
jmp    1196 <main+0x76>
cmpl   $0xf,-0xc(%rbp)
jne    1185 <main+0x65>
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
jmp    1191 <main+0x71>
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
jmp    1196 <main+0x76>
movl   $0x0,-0x4(%rbp)
jmp    1211 <main+0xf1>
lea    0xe5a(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
setl   %al
and    $0x1,%al
movzbl %al,%eax
shl    $0x1,%eax
mov    $0xf,%ecx
sub    -0xc(%rbp),%ecx
imul   %ecx,%eax
add    -0x8(%rbp),%eax
sub    $0x1,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x1e,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
cmpl   $0xe,-0xc(%rbp)
jg     1205 <main+0xe5>
lea    0xe0b(%rip),%rdi
call   1030 <printf@plt>
jmp    1211 <main+0xf1>
lea    0xdfd(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xed5(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x1,0x10(%rsp)
jne    116b <main+0x4b>
mov    0xc(%rsp),%eax
cmp    $0xf,%eax
lea    0xeb8(%rip),%rcx
lea    0xeb6(%rip),%rdx
cmove  %rcx,%rdx
test   %eax,%eax
lea    0xea1(%rip),%rdi
cmovne %rdx,%rdi
jmp    11e4 <main+0xc4>
lea    0xe91(%rip),%rdi
lea    0x14(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
xor    %ecx,%ecx
cmp    %eax,0x14(%rsp)
setl   %cl
mov    $0xf,%edx
sub    %eax,%edx
add    0x10(%rsp),%eax
imul   %ecx,%edx
lea    (%rax,%rdx,2),%ecx
lea    (%rax,%rdx,2),%eax
add    $0xffffffff,%eax
cltq
imul   $0xffffffff88888889,%rax,%rdx
shr    $0x20,%rdx
add    %edx,%ecx
add    $0xffffffff,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x4,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x5,%edx
mov    %ecx,%esi
sub    %edx,%esi
add    %ecx,%esi
add    %esi,%eax
mov    %eax,0xc(%rsp)
cmp    $0xf,%eax
lea    0xe2d(%rip),%rax
lea    0xe29(%rip),%rdi
cmovl  %rax,%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

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

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