ÀÂÒ
Language: Russian
English

Remote Training on Programming

Problems Online status Contests
News FAQ E-learning
For authors:
Register  ||  Login
 
Hello, Guest! Please login or register.

1147. Triangles

Time Limit: 5 seconds
Memory Limit:65536KB
Points:100
View Problem Statistics Submit Problem added 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)


View Problem Statistics Submit Problem discussion Author/source:
Problems from Contests and Camps / World Championship in Programming (ICPC) / Rybinsk-2012 /
1146. J - Computer Network 1147.
Problems from Contests and Camps / World Championship in Programming (ICPC) / School-Rybinsk-2012 /
1141. G - Multiplication puzzle 1147. 1146. I - Computer Network
time generating 0.109 sec.
© Copyright VSU, AVT, Nosov D.A., Andrianov I.A.