Grandpa Pepe's Pizza
InterviewTime limit2sMemory limit512 MB
Given N olive positions on a circle of circumference C, decide whether equal sectors of length C/N can each contain exactly one olive.
- Level
Medium5 of 10
- Topics
- Math, Implementation, Sorting
- Solved
- No attempts yet
Problem
Grandpa Pepe's pizzas are perfect circles. Tonight's pizza has a few olives sitting exactly on the rim, at arbitrary positions.
You are given the circumference of the pizza, the number of olives , and the position of every olive. Decide whether the pizza can be cut into circular sectors of equal size so that every slice holds exactly one olive.
One slice holds exactly one olive, so the number of slices is and each slice covers an arc of length . Every cut is a radius from the center to the rim, and a cut can be made at any point of the circumference, not only at an integer position. No olive may lie on a cut. The olives are tiny, so their size is ignored.
The figure below shows (a) a pizza of circumference with three olives and one way to split it into equal slices, and (b) a pizza of circumference with four olives that cannot be split this way.

Input
The first line contains two integers and (, , ). is a multiple of .
The second line contains distinct integers in increasing order (), the positions of the olives. A position is the arc length measured clockwise from a fixed point of the circumference.
Output
Print one line holding a single letter. Print S if the pizza can be cut as described, and N otherwise.