In this problem the goal is to implement a program managing an elevator designed especially for mathematicians.
The elevator can go to any of N floors numbered from 1 to N and it can carry an arbitrary number of people at one time.
Initially the elevator is at floor 1, without any people inside, and it can go to any floor from 1 to N at any time. The total distance the elevator travels is defined as the sum of distances between the consecutive floors it went to in the whole process, and the distance between two floors and is defined as .
In addition, there are Q events which are about to happen consecutively starting from now. There are two types of events to handle:
The elevator must handle events in the order they come, and must handle only the events which are possible.
An entry event is possible if and only if is a prime number.
An exit event is possible if and only if has odd number of divisors.
If the elevator being currently on floor has to handle an event taking place on floor , it must first go from floor to floor moving up and/or down in any possible way, and it can handle the event only while it is at floor .
The task in this problem is to print the minimum distance that the elevator has to travel to handle all possible events in the order they come and the number of people inside the elevator after handling the last possible event. Since the total distance can be very large, output it modulo .
Constraints:
Input format:
In the first line there are two integers N and Q denoting the number of floors and the number of events. In the following Q lines the descriptions of Q events in the order they come are given. Each single event is given by 3 space separated integers , where T is either 1 or 2 and denotes the type of the event (1 stands for an entry event, 2 stands for an exit event), F denotes the number of floor where this event has to be handled if it is a possible event, and K denotes the number of people in this event.
Output format:
In a single line output two space separated integers denoting the minimum total distance the elevator travels to handle all possible events taken modulo , and the number of people in the elevator after the last handled event.
Initially the elevator is at floor 1 with no people inside. The first event is an event at floor 2 with 3 people wanting to enter the elevator. Is is a possible event, because is a prime number, so the elevator must go to the floor to handle this event. However, the second event is not possible, because it is an event and has 4 divisors, which is an even number. Finally, the elevator must handle only the first event, and the minimal distance it need to cover to do that is 1 and the number of people after handling this event inside the elevator is 3.