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

#GL0000320. Phủ kín các ô lưới (Grid Covering)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Phủ kín các ô lưới (Grid Covering)

Grid Covering

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A room is an nn-by-mm grid, indexed from 11. Prakul starts at cell (1,1)(1,1) and can perform two kinds of jump:

  • Move aa rows downward, wrapping around after the last row.
  • Move bb columns rightward, wrapping around after the last column.

He may choose the first move, but thereafter he must alternate the two move types: down, right, down, right, ... or right, down, right, down, ... . The starting cell also counts as visited.

Determine whether there is a choice of first move that lets him visit every one of the n⋅mn\cdot m cells after finitely many moves.

Input

One line contains four integers n,m,a,bn,m,a,b.

Output

Print YES if all cells can be visited, and NO otherwise.

Subtasks

  • Subtask 1 (20 points): 1≤n,m,a,b≤101\le n,m,a,b\le10.
  • Subtask 2 (30 points): 1≤n,m,a,b≤1051\le n,m,a,b\le10^5.
  • Subtask 3 (50 points): 1≤n,m,a,b≤1091\le n,m,a,b\le10^9.

Examples

Example 1

Input

2 2 1 1

Output

YES

Explanation

Starting from (1,1)(1,1), go down to (2,1)(2,1), right to (2,2)(2,2), and down (wrapping) to (1,2)(1,2). All four cells are visited.

Example 2

Input

4 2 2 1

Output

NO

Explanation

The downward jump changes the row by 22 modulo 44, so only rows 11 and 33 can be reached; rows 22 and 44 remain unvisited.