This page is still under construction.

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

Pirates' Code

Time limit1sMemory limit128 MB

Summary
Given N integers from the foreheads, decide whether the set contains no increasing arithmetic progression of length 3, and if it does, print the lexicographically first witness triple.
Level

Medium6 of 10

Topics
Sorting, Hash map, Brute force, Implementation
Solved
No attempts yet

Problem

Davy Jones has captured another ship and is smiling contentedly under the sun. Today is a good day for him: he will get more souls to serve on his crew. But the day looks so nice, the sun shining brightly and the ocean lying calm, that he decides to be merciful and give the wretched seamen of the captured ship a chance. He plays the following game.

He lines the captives up in front of him and writes a number of his choice on each man's forehead. Then he wants to check whether the set of numbers is 3-free. A set is 3-free when no three of its numbers form an increasing arithmetic progression. A triple (a1,a2,a3)(a_1, a_2, a_3) is an increasing arithmetic progression when a2−a1=a3−a2a_2 - a_1 = a_3 - a_2 and a2−a1>0a_2 - a_1 > 0 — for example {1,2,3}\{1, 2, 3\}, {4,6,8}\{4, 6, 8\}, or {−2,1,4}\{-2, 1, 4\}.

If the set of numbers is 3-free, the whole group goes free (what an irony). Otherwise, the men whose numbers form the lexicographically first witness — the lexicographically first triple that proves the set is not 3-free — will serve on Jones' crew for an eternity.

You are Jones' assistant: for the given group you must decide whether it is 3-free, and if it is not, report the lexicographically first witness. Check right, or you will end up on Jones' crew too.

A triple (a1,a2,a3)(a_1, a_2, a_3) is lexicographically smaller than (b1,b2,b3)(b_1, b_2, b_3) when:

  • a1<b1a_1 < b_1, or
  • a1=b1a_1 = b_1 and a2<b2a_2 < b_2, or
  • a1=b1a_1 = b_1, a2=b2a_2 = b_2 and a3<b3a_3 < b_3.

You always look at triples in increasing order, i.e. a1≤a2≤a3a_1 \le a_2 \le a_3 (together with a2−a1>0a_2 - a_1 > 0 this makes the three numbers distinct and strictly increasing). The numbers on the foreheads are not necessarily given in increasing order.

Input

A single line. The first integer NN is the number of men in the group; it is not part of the sequence. It is followed by the NN integers written on their foreheads.

Output

Print a single line.

If the given numbers are 3-free, print:

Sequence is 3-free.

Otherwise, print:

Sequence is not 3-free. Witness: w1,w2,w3.

where (w1,w2,w3)(w_1, w_2, w_3) is the lexicographically first witness. The three witness numbers are separated by commas with no spaces; there is a single space after the period following 3-free. and a single space after the colon.

Examples2

  1. Example 1

    Input
    4 1 5 6 8
    
    Expected output
    Sequence is 3-free.
    
  2. Example 2

    Input
    7 1 3 5 2 -7 0 -1
    Expected output
    Sequence is not 3-free. Witness: -7,-1,5.