#CCBCHMUOI0000020. Bộ số có mã kết thúc (Command Stream with Stop Code)
Bộ số có mã kết thúc (Command Stream with Stop Code)
Command Stream with Stop Code
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
A stream contains n integer codes from 0 to 3. Codes 1, 2 and 3 contribute 2, 3 and 5 respectively. Code 0 stops processing: do not add its value or consider later codes. If no zero appears, sum all n codes.
Input
The first line contains integer n. The second line contains exactly n integer codes c1...cn, each from 0 through 3, in processing order.
Output
Print the sum of the prices of the codes before the first zero, or all codes if there is no zero.
Subtasks
- Subtask 1 (20%): 1 <= n <= 5 and every code is 1 or 2.
- Subtask 2 (30%): 1 <= n <= 50 and every code is 0..3.
- Subtask 3 (50%): 1 <= n <= 1000 and every code is 0..3.
Examples
Example 1
Input
5
1 3 0 2 1
Output
7
Explanation
Code 1 adds 2, code 3 adds 5; zero stops processing before the remaining codes. The sum is 7.
Example 2
Input
4
2 1 2 3
Output
13
Explanation
There is no zero, so all four prices sum to 13.