#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*/ print_answer(int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int i, n;
  scanf("%d", &n);
  int count_5 = 0;
  int count_0 = 0;
  for (i = 0; i < n; i++) {
    int num;
    scanf("%d", &num);
    if (num == 5)
      count_5++;
    else
      count_0++;
  }
  int find_answer = 0;
  while (1) {
    if (count_5 < 9)
      break;
    if (count_5 * 5 % 9 == 0) {
      find_answer = 1;
      break;
    }
    count_5 = count_5 - count_5 % 9;
  }
  if (find_answer && count_0 > 0) {
    print_answer(count_5, count_0);
    return 0;
  }
  if (count_0 == 0)
    printf("-1\n");
  else
    printf("0\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b4 <main+0x84>
lea    0xe89(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x5,-0x18(%rbp)
jne    1198 <main+0x68>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11a1 <main+0x71>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a6 <main+0x76>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1164 <main+0x34>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x9,-0x10(%rbp)
jge    11ca <main+0x9a>
jmp    1209 <main+0xd9>
imul   $0x5,-0x10(%rbp),%eax
mov    $0x9,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11eb <main+0xbb>
movl   $0x1,-0x1c(%rbp)
jmp    1209 <main+0xd9>
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x9,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%eax
sub    %edx,%eax
mov    %eax,-0x10(%rbp)
jmp    11bb <main+0x8b>
cmpl   $0x0,-0x1c(%rbp)
je     1234 <main+0x104>
cmpl   $0x0,-0x14(%rbp)
jle    1234 <main+0x104>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <print_answer@plt>
movl   $0x0,-0x4(%rbp)
jmp    1262 <main+0x132>
cmpl   $0x0,-0x14(%rbp)
jne    124f <main+0x11f>
lea    0xdbe(%rip),%rdi
call   1030 <printf@plt>
jmp    125b <main+0x12b>
lea    0xdb1(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xebd(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11e6 <main+0xb6>
xor    %r12d,%r12d
lea    0xe9e(%rip),%r14
lea    0xc(%rsp),%r15
xor    %ebp,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
xor    %eax,%eax
xor    %ecx,%ecx
cmpl   $0x5,0xc(%rsp)
setne  %al
sete   %cl
add    %ecx,%ebp
add    %eax,%r12d
add    $0x1,%ebx
cmp    0x8(%rsp),%ebx
jl     1170 <main+0x40>
jmp    11c2 <main+0x92>
nopw   0x0(%rax,%rax,1)
imul   $0x1c71c71d,%ebp,%eax
add    $0xe38e38e,%eax
cmp    $0x1c71c71d,%eax
jb     11d5 <main+0xa5>
mov    %ebp,%eax
imul   $0x38e38e39,%rax,%rax
shr    $0x21,%rax
lea    (%rax,%rax,8),%ebp
cmp    $0x9,%ebp
jae    11a0 <main+0x70>
test   %r12d,%r12d
je     11e6 <main+0xb6>
lea    0xe30(%rip),%rdi
jmp    11ed <main+0xbd>
test   %r12d,%r12d
je     11e6 <main+0xb6>
mov    %ebp,%edi
mov    %r12d,%esi
call   1040 <print_answer@plt>
jmp    11f2 <main+0xc2>
lea    0xe18(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"-1\0A\00"
@.str.2 = [3 x i8] c"0\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %2
br label %9
9: ; preds = %24, %0
%10 = load i32, i32* %2
%11 = load i32, i32* %3
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %27
13: ; preds = %9
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 5
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %23
20: ; preds = %13
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %23
23: ; preds = %20, %17
br label %24
24: ; preds = %23
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
store i32 %26, i32* %2
br label %9
27: ; preds = %9
store i32 0, i32* %7
br label %28
28: ; preds = %27, %38
%29 = load i32, i32* %4
%30 = icmp slt i32 %29, 9
br i1 %30, label %31, label %32
31: ; preds = %28
br label %43
32: ; preds = %28
%33 = load i32, i32* %4
%34 = mul nsw i32 %33, 5
%35 = srem i32 %34, 9
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32
store i32 1, i32* %7
br label %43
38: ; preds = %32
%39 = load i32, i32* %4
%40 = load i32, i32* %4
%41 = srem i32 %40, 9
%42 = sub nsw i32 %39, %41
store i32 %42, i32* %4
br label %28
43: ; preds = %37, %31
%44 = load i32, i32* %7
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %53
46: ; preds = %43
%47 = load i32, i32* %5
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %46
%50 = load i32, i32* %4
%51 = load i32, i32* %5
%52 = call i32 @print_answer(i32 %50, i32 %51)
store i32 0, i32* %1
br label %61
53: ; preds = %46, %43
%54 = load i32, i32* %5
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %53
%57 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %60
58: ; preds = %53
%59 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %60
60: ; preds = %58, %56
store i32 0, i32* %1
br label %61
61: ; preds = %60, %49
%62 = load i32, i32* %1
ret i32 %62
}

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