QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 256 MB Total points: 100

#9255. Python Program

Statistics

You need to calculate the output of a Python program. To simplify the problem, the code satisfies the following constraints. The program has exactly 5 lines. The first line of the code is

ans=0

The second and the third lines are of the form

for i in range(a,b,c):
    for j in range(d,e,f):

Here, $i$ and $j$ are loop variables. $i$ and $j$ can be any two different lowercase English letters. $a, b, c, d, e, f$ can be integers without leading zeroes or loop variables that have been introduced before. That is, $d, e$ and $f$ may be $i$. The tokens $c$ or $f$ (or both) can be omitted. When omitted, they equal 1. The fourth line of the code is of the form:

ans+=j

Here, $j$ is the loop variable of the inner loop (note that it can be some letter other than $j$). The fifth line of the code is

print(ans)

For any $c \neq 0$, the statement

for i in range(a,b,c):

in the Python language is interpreted as follows.

  • If $c > 0$, $i$ will take the values of $a, a + c, a + 2c, \dots$ until $a + kc$, where $k$ is the maximum integer such that $a + kc < b$. If $a \geq b$, $i$ won’t take any value.
  • If $c < 0$, $i$ will take the values of $a, a + c, a + 2c, \dots$ until $a + kc$, where $k$ is the maximum integer such that $a + kc > b$. If $a \leq b$, $i$ won’t take any value.

Input

5 lines, representing the code. It is guaranteed that there are no extra spaces at the end of each line. However, there may be extra line feeds at the end of the input file. Please note that each tab is represented by 4 spaces in the input file. It is guaranteed that $1 \leq a, b, |c|, d, e, |f| \leq 10^6$.

Output

One integer representing the output of the program.

Examples

Input 1

ans=0
for a in range(1,3):
    for b in range(5,1,-2):
        ans+=b
print(ans)

Output 1

16

Input 2

ans=0
for q in range(100,50,-1):
    for i in range(q,77,20):
        ans+=i
print(ans)

Output 2

2092

Note

For the first example, $a$ will take the values of 1, 2 in order, and for each value that $a$ takes, $b$ will take the values of 5, 3, so the answer is $2 \times (5 + 3) = 16$. You can test the programs with a Python interpreter.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.