АВТ
Язык:

Дистанционный практикум по программированию

Задачи Online статус Соревнования
Новости Справка СДО
 
Здравствуйте, Гость! Войдите с паролем или зарегистрируйтесь.

1147. Треугольники

Ограничение времени: 5 сек.
Ограничение памяти:65536 КБайт
Баллы:100
Статистика Послать на проверку Задачу добавил debug

Условия с турнира школьников на русском языке

Schoolboy Vasya enjoys challenging geometrical problems. While reading an advanced-level math book he came across the following problem.

Located along the horizontal axis of the Cartesian plane, are k isosceles triangles. Bases of the triangles lie on the X-axis, and the remaining vertexes are in the first quadrant. The sides of adjoining triangles intersect (the right side of triangle i intersects the left side of triangle i+1). The left side of the first triangle intersects the Y-axis, and the right side of the last triangle intersects the line x = n. So, segments of triangle sides form a zigzag connecting the Y-axis on the left and the line x = n on the right.

 

Описание: C:\Igor\Olymp\Rybinsk2012\Tasks\K-Triangles\index.files\image001.png

Let us define peaks as zigzag vertices formed by upper triangle corners, and pits as remaining zigzag vertices, formed by intersections. It is known that the coordinates of all zigzag vertices—peaks and pits—are nonnegative integers.

A question arises—how many different zigzag lines exist for given peak (not pit) coordinates? Help Vasya by writing program that will answer this question.

 

Limitations

1 <= n <= 3 000; 2 <= k <= 500;

1 <= xi <= 3 000; 1 <= yi <= 1 000; xi + 1< xi+1, i = 1…k.

 

Input

The first line contains two space-delimited integers, n (the X-coordinate of the line (x = n), and k (the number of triangles). The following k lines carry space-delimited pairs <xi, yi>, the coordinates of peaks, one pair per line.

 

Output

The output file should contain a single integer k, the number of different zigzag lines modulo 230.

 

Example

Описание: C:\Igor\Olymp\Rybinsk2012\Tasks\K-Triangles\index.files\image002.png

Input

Output

6 2

2 6

4 4

1

 

Input

Output

6 2

2 8

4 6

2

 

 

 

All Rybinsk-2012 problems (in PDF)


Статистика Послать на проверку Обсуждение задачи Автор/источник:
Задачи с соревнований и сборов / Чемпионат мира по программированию (ICPC) / Рыбинск-2012 /
1146. J - Компьютерная сеть 1147.
Задачи с соревнований и сборов / Чемпионат мира по программированию (ICPC) / Школьники-Рыбинск-2012 /
1141. G - Головоломка 1147. 1146. I - Компьютерная сеть
 
время генерации 0.157 сек.
© Copyright ВоГУ, АВТ, Носов Д.А., Андрианов И.А.