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

#DSU0000039. Stepan và hoán vị (Stepan and Permutation)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Stepan và hoán vị (Stepan and Permutation)

Stepan and Permutation

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given a permutation pp of length nn and two positive integers x,yx,y satisfying x+y≤nx+y\le n. Your goal is to sort the permutation into 1,2,…,n1,2,\ldots,n.

In one operation, choose two positions i,ji,j and swap their current values if the distance between their indices equals xx or yy, that is, ∣i−j∣=x|i-j|=x or ∣i−j∣=y|i-j|=y. The distance concerns position indices, not the difference between stored values. Any number of operations may be performed, including repeated swaps of the same pair.

Determine whether a sequence of allowed operations can sort the initial permutation in increasing order.

Input

The first line contains n,x,yn,x,y; the second contains permutation pp.

Output

Print YES or NO.

Subtasks

  • Subtask 1 (20 points): 2≤n≤402\le n\le40; x,y≥1x,y\ge1, x+y≤nx+y\le n; pp is a permutation of 1,2,…,n1,2,\ldots,n.
  • Subtask 2 (30 points): 2≤n≤50002\le n\le5000; x,y≥1x,y\ge1, x+y≤nx+y\le n; pp is a permutation of 1,2,…,n1,2,\ldots,n.
  • Subtask 3 (50 points): 2≤n≤2⋅1052\le n\le2\cdot10^5; x,y≥1x,y\ge1, x+y≤nx+y\le n; pp is a permutation of 1,2,…,n1,2,\ldots,n.

Examples

Input

5 2 3
5 4 3 2 1

Output

YES

Explanation

For n=5n=5, the permitted index differences are 22 and 33. Position 11 can be swapped with positions 33 or 44, and those positions connect it to the remaining indices. Thus all values can be moved to the required positions, making the identity permutation reachable. The result is YES.