PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#QHD0000070. Hệ tiền chuẩn tắc (Canonical Coin Systems)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Hệ tiền chuẩn tắc (Canonical Coin Systems)

Canonical Coin Systems

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

A coin system consists of strictly increasing, distinct denominations c1<c2<⋯<cnc_1<c_2<\cdots<c_n, with c1=1c_1=1, and unlimited supply of each coin. A greedy cashier repeatedly chooses the largest denomination not exceeding the remaining amount.

A system is canonical if this greedy algorithm uses the minimum possible number of coins for every positive integer amount. It is non-canonical if at least one counterexample exists. For example, with denominations 1,3,41,3,4, amount 66 is a counterexample: greedy uses 4+1+14+1+1 while two 33 coins suffice.

Determine whether the input system is canonical. Print only the required lowercase word; no counterexample or coin list is requested. Your algorithm must justify checking a finite, sufficient range rather than an arbitrary set of small amounts.

Input

The first line contains nn. The second line contains the strictly increasing denominations c1,…,cnc_1,\ldots,c_n.

Output

Print canonical if greedy is always optimal, otherwise print non-canonical.

Subtasks

  • Subtask 1 (20 points): 2≤n≤122\le n\le 12; c1=1<c2<⋯<cn≤100c_1=1<c_2<\cdots<c_n\le 100; unlimited coins of every denomination.
  • Subtask 2 (30 points): 2≤n≤352\le n\le 35; c1=1<c2<⋯<cn≤20000c_1=1<c_2<\cdots<c_n\le 20000; unlimited coins of every denomination.
  • Subtask 3 (50 points): 2≤n≤1002\le n\le 100; c1=1<c2<⋯<cn≤1000000c_1=1<c_2<\cdots<c_n\le 1000000; unlimited coins of every denomination.

Examples

Input

3
1 3 4

Output

non-canonical

Explanation

At amount 66, greedy returns 4+1+14+1+1 (three coins), but 3+33+3 uses only two. Thus a counterexample exists.