QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100

#3755. 4 Buttons

الإحصائيات

Bobo lives in an infinite chessboard. Initially he locates at $(0, 0)$. There are $4$ buttons.

  • When the first button is pressed, Bobo moves right for at most $a$ cells.
  • When the second button is pressed, Bobo moves up for at most $b$ cells.
  • When the third button is pressed, Bobo moves left for at most $c$ cells.
  • When the fourth button is pressed, Bobo moves down for at most $d$ cells.

Find the number of cells Bobo can reach modulo $(10^9+7)$, if he presses the buttons for no more than $n$ times.

Input

The input consists of several test cases and is terminated by end-of-file.

Each test case contains five integers $n$, $a$, $b$, $c$ and $d$.

  • $1 \leq n, a, b, c, d \leq 10^9$
  • The number of test cases does not exceed $10^5$.

Output

For each test case, print an integer which denotes the result.

Sample Input

1 1 2 3 4
2 1 1 1 1
1000000000 1000000000 1000000000 1000000000 1000000000

Sample Output

11
13
5685

Note

For the first test case, Bobo can reach the following $11$ cells: $(-3, 0)$, $(-2, 0)$, $(-1, 0)$, $(0, -4)$, $(0, -3)$, $(0, -2)$, $(0, -1)$, $(0, 0)$, $(0, 1)$, $(0, 2)$, $(1, 0)$.

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.