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

#GL0000312. Những ngày nghỉ lý tưởng (Ideal Holidays)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Những ngày nghỉ lý tưởng (Ideal Holidays)

Ideal Holidays

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

In the Kingdom of AtCoder, a week consists of A+BA+B days. Days 11 through AA are holidays, and days A+1A+1 through A+BA+B are weekdays. The calendar repeats every week.

Takahashi has NN plans. The ii-th plan takes place DiD_i days after today. The values DiD_i are strictly increasing, but Takahashi has forgotten which day of the week today is.

Determine whether there exists a possible current day of the week such that every plan falls on a holiday.

Input

  • The first line contains three integers N,A,BN,A,B.
  • The second line contains NN strictly increasing integers D1,D2,…,DND_1,D_2,\ldots,D_N.

Output

Print Yes if some choice of the current weekday makes all plans fall on holidays; otherwise print No.

Subtasks

  • Subtask 0 (20 points): 1≤N≤121\le N\le 12; 1≤A,B≤201\le A,B\le 20; 1≤D1<D2<…<DN≤10001\le D_1<D_2<\ldots<D_N\le 1000.
  • Subtask 1 (30 points): 1≤N≤20001\le N\le 2000; 1≤A,B≤1000001\le A,B\le 100000; 1≤D1<D2<…<DN≤1000000001\le D_1<D_2<\ldots<D_N\le 100000000.
  • Subtask 2 (50 points): 1≤N≤2000001\le N\le 200000; 1≤A,B≤10000000001\le A,B\le 1000000000; 1≤D1<D2<…<DN≤10000000001\le D_1<D_2<\ldots<D_N\le 1000000000.

Examples

Example 1

Input

3 2 5
1 2 9

Output

Yes

Explanation

The week has 77 days, with days 11 and 22 off. If today is day 77, the plans after 1,2,91,2,9 days fall on days 1,2,21,2,2, all holidays.

Example 2

Input

2 5 10
10 15

Output

No

Explanation

The two plans are 55 days apart in a 1515-day cycle. No block of 55 consecutive holidays can contain both days, even when the block crosses the end of a week.

Example 3

Input

4 347 347
347 700 705 710

Output

Yes

Explanation

The remainders modulo 694694 are 347,6,11,16347,6,11,16, sorted as 6,11,16,3476,11,16,347. The largest circular gap, from 347347 to 66 in the next period, is 353353 days; the shortest arc containing all plans is 694−353=341<347694-353=341<347 days, so it fits in the holiday block.