402344: GYM100733 I The Cool Monkeys

Memory Limit:256 MB Time Limit:4 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

I. The Cool Monkeystime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

The first mafia on planet Earth was actually composed of a bunch of cool jumping monkeys. The name of that group was pretty simple - Monkafia - and they dominated the food chain and the transport systems in the biggest tropical forest of the world at the time.

Tha typical Monkafia squadron was composed of a group of m monkeys. They had headquarters - usually composed of two trees. We will call those trees A and B. The monkeys slept on the highest branches of tree A, and, during morning, used to climb down to the lowest branches of tree B, alternating between branches of trees A and B. They could jump multiple times between the two trees.

Monkeys in the Monkafia are very irritating and don't like sharing, so they could never jump on a branch that another monkey had already jumped or been that morning.

We know that each branch of trees A and B has a certain height, H. It is possible for a monkey to jump from a branch Ga to a branch Gb only if |HGa - HGb| < T, where T is the height a single monkey can jump.

It is not always possible for two arbitrary trees to have all monkeys of a Monkafia squadron jump down from the topmost branches of one of the trees to the bottommost branches of the other without breaking the rules. Given that, your job here is the following: given a pair o trees, with the heights of their branches and the distance T, find out if it is possible for the squadron to do the morning descend considering all the constraints. Any of the trees can be tree A (the starting tree) or tree B (the ending tree).

Input

The input begins with four numbers, m, nA, nB e T (1 ≤ m ≤ nA, nB ≤ 500, 1 < T ≤ 108), the number of monkeys, the number of branches in one tree, the number of branches in the other tree and the distance the monkeys can jump. Follow na lines, each with the height of a branch from the first tree (1 ≤ HGa ≤ 108). Then follows nb lines, each with the height of a branch from the second tree (1 ≤ HGb ≤ 108).

Output

Answer 'S' if it is possible to use that pair of trees and 'N' otherwise.

ExamplesInput
1 2 2 3
1
3
2
1
Output
S
Input
1 2 3 2
1
3
2
1
1
Output
S
Input
2 2 3 2
1
3
2
1
1
Output
S
Input
2 6 7 4
8
4
5
2
9
11
2
2
8
3
12
3
12
Output
N

Source/Category

加入题单

算法标签: