QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 1024 MB 満点: 10

#17389. Addition [C]

統計

Bajtek is learning to add numbers using the column addition method. He has placed three numbers of the same length $n$ one below the other. He is now wondering for how many pairs $(i, j)$, where $1 \le i \le j \le n$, the fragments of these numbers from the $i$-th to the $j$-th digit form a correct sum (i.e., the considered fragment of the third number is the sum of the fragments of the first and second numbers). Leading zeros are allowed in all numbers.

Input

The input consists of three lines, each containing one integer (which may potentially start with zeros). Each of these three numbers consists of the same number of digits $n$ ($1 \le n \le 10^6$).

Output

Output a single integer representing the number of pairs $(i, j)$ for which the fragment from column $i$ to column $j$ constitutes a correct addition.

Examples

Input 1

037523
040834
978367

Output 1

4

Note

Explanation of the example: Correct sums are obtained for the pairs $(2, 2)$ (because $3+4 = 7$), $(2, 4)$ (because $375+408 = 783$), $(3, 4)$ (because $75 + 8 = 83$), and $(6, 6)$ (because $3 + 4 = 7$). Note that the fragments for pairs $(2, 2)$ and $(6, 6)$ are the same, yet we count them twice. We do not count sums of fragments that are not aligned directly below each other, such as $3 + 3 = 6$.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download
#1358EditorialOpen题解Milmon2026-03-31 16:26:48View

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.