Under construction

Still being built. Things may change

Alphabet Soup

Time limit10sMemory limit128 MB

Summary
Count distinct necklaces (colorings up to rotation by the given rotational symmetry group of the fixed angular positions) with S colors and P beads, using Burnside's lemma modulo a prime.
Level

Hard8 of 10

Topics
Combinatorics, Math, Number theory
Solved
No attempts yet

Problem

Peter is having lunch at home, and unfortunately for him today's meal is soup. Knowing that Peter does not like it very much, his mother has cooked a special soup using pasta pieces shaped like letters of the alphabet, digits, and other characters. With a special knife she can prepare an unlimited supply of pasta pieces, which come in SS different shapes. Each bowl of soup always contains exactly PP pasta pieces, and the soup is so thick that the pieces never move.

Despite her effort, Peter is still unhappy with today's menu and asks how many days of his life he will have to eat soup. His mother promises to prepare a different soup every day: on no day will the dish contain the same shapes in all positions as any soup served before. However, the number PP of pasta pieces and the positions in which they float stay the same every day. Thinking himself clever, Peter realizes this could still make him eat soup for ages, so to reduce the number of configurations he declares that he will also refuse any dish that can be obtained by rotating one of the configurations already seen.

Figure 1: Top view of Peter's dish

Consider the dish as a circle of radius 22 centered at the origin. Every symbol floats in the soup at distance 11 from the origin, at a given angle measured in millidegrees. Two plates are considered equal if you can rotate one of the dishes about its center so that both the positions of the symbols and the symbols themselves match in the two dishes.

Your program is given the number SS of symbols Peter's mother has available and the PP angles (measured clockwise in millidegrees) that determine the location of each pasta piece. Compute the number of different plates Peter's mother can prepare. As this number can be very large, output it modulo 100000007100000007, which is prime.

Input

The input contains several test cases.

The first line of each test case has two integers SS (2≤S≤10002 \le S \le 1000), the number of available shapes, and PP (P>0P > 0), the number of pasta pieces. Each of the next PP lines contains one integer AA (0≤A<3600000 \le A < 360000), the angle of a piece measured clockwise in millidegrees. All PP angles are distinct.

Consecutive test cases are separated by a blank line. A line containing S=P=−1S = P = -1 (that is, the two values -1 -1) follows the last test case and ends the input.

Output

For each test case, output a single line with the number of distinct bowls Peter's mother can prepare, taken modulo 100000007100000007.

Examples1

  1. Example 1

    Input
    2 4
    0
    90000
    180000
    270000
    
    100 5
    0
    45000
    90000
    180000
    270000
    
    -1 -1
    
    Expected output
    6
    99999307