This page is still under construction.

Parts of this page are still being built. What you see may change.

Number Game

Time limit1sMemory limit128 MB

Summary
With Ellie's responses fixed by a1..a20, decide if the first player can force reaching 0 in a subtraction game.
Level

Medium6 of 10

Topics
Game theory, Dynamic programming, Implementation
Solved
No attempts yet

Problem

Carl and Ellie are on a road trip across Canada. They have just arrived in Saskatchewan, right in the middle of the Canadian prairies, and have discovered that all the rumours about it being dreadfully flat are true:

It's so flat, a boy can watch his dog run away!

It's so flat, it's impossible to jump to your death!

To fight off boredom at the wheel, Carl invents a simple game with the following rules:

  • Carl picks an integer NN with 1≤N≤1091 \le N \le 10^9.
  • Carl and Ellie take turns subtracting an integer between 11 and 2020 from the current number. Carl moves first, and the player who subtracts to reach exactly 00 wins.

For example, suppose Carl picks 5050. He subtracts 55, leaving 4545; Ellie subtracts 1717, leaving 2828; Carl subtracts 88, leaving 2020; finally Ellie subtracts 2020, reaching 00 and winning. (This only illustrates the moves; it is not Ellie's fixed strategy described below.)

Ellie would rather sleep than play, so she reprograms the GPS to choose for her. Its rule is:

  • On Ellie's turn, if the current number is 2020 or less, she subtracts all of it and wins immediately.
  • Otherwise (the current number exceeds 2020), her move is completely determined by Carl's last move. Before the game, Ellie fixes twenty numbers with 1≤a1,a2,…,a20≤201 \le a_1, a_2, \ldots, a_{20} \le 20. Whenever Carl subtracts kk, Ellie subtracts aka_k.

Given NN and a1,a2,…,a20a_1, a_2, \ldots, a_{20}, determine whether Carl has a strategy that guarantees a win.

Input

The input consists of several test cases. Each test case has NN on its own line, followed by a line with a1,a2,…,a20a_1, a_2, \ldots, a_{20} separated by spaces. Input terminates with a line containing a single 00.

Constraints: 1≤N≤1091 \le N \le 10^9 and 1≤ai≤201 \le a_i \le 20.

Output

For each test case, print Carl can win if Carl has a winning strategy, or Carl can't win otherwise, each on its own line.

Hint

When N=42N = 42 and ak=21−ka_k = 21 - k, Carl has no winning strategy: whatever number kk he subtracts first, Ellie subtracts ak=21−ka_k = 21 - k, always leaving 42−k−(21−k)=2142 - k - (21 - k) = 21. Then whatever Carl subtracts next leaves a value between 11 and 2020, and Ellie wins.

Examples3

  1. Example 1

    Input
    42
    20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
    0
    
    Expected output
    Carl can't win
    
  2. Example 2

    Input
    1
    1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    0
    
    Expected output
    Carl can win
    
  3. Example 3

    Input
    42
    20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
    50
    20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
    63
    20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
    0
    
    Expected output
    Carl can't win
    Carl can win
    Carl can't win