Under construction

Still being built. Things may change

Bowing to Parents

Time limit2sMemory limit1024 MB

Summary
Given N shuffled integers, decide whether they can be rearranged into a sequence that decreases by a constant step and then increases by a constant step.
Level

Medium6 of 10

Topics
Sorting, Implementation, Math
Solved
No attempts yet

Problem

Wookje bowed deeply to his parents before leaving for military training. When he was young, his parents used to tell him:

"Wookje, remember this. Agent's bow must be artistic."

Today, however, his parents were very disappointed in him, because they did not think his bow was artistic. A bow is artistic when the following conditions hold.

  1. The bow is represented by a sequence of integers a1,…,aNa_1, \ldots, a_N of length NN.
  2. The sequence must first decrease by a constant amount and then increase by a constant amount. That is, there is an index ii with 2≤i≤N−12 \le i \le N-1 such that a1,…,aia_1, \ldots, a_i is an arithmetic sequence with common difference x<0x < 0, and ai,…,aNa_i, \ldots, a_N is an arithmetic sequence with common difference y>0y > 0.

You must judge whether the sequence representing Wookje's bow is artistic.

Alas! The soccer player Messi shuffled the sequence. Given the shuffled sequence in no particular order, determine whether the original bow could have been artistic.

Input

The first line contains the length NN of the sequence.

The second line contains the sequence a1,…,aNa_1, \ldots, a_N representing Wookje's bow, shuffled into arbitrary order, with the numbers separated by spaces.

Output

If the sequence can be rearranged into a sequence representing an artistic bow, print Yes. Otherwise, print No.

Constraints

  • 3≤N≤402,0003 \le N \le 402,000
  • 1≤ai≤1091 \le a_i \le 10^9

Examples2

  1. Example 1

    Input
    5
    8 2 4 6 5
    
    Expected output
    Yes
    
  2. Example 2

    Input
    5
    8 6 7 3 5
    
    Expected output
    No