Log inSign up
Problems / B019

Sum of the vending machine record

100 ptsCases 16Set by dongbinna
Added October 30.
1 solved1 attempted1 submissionssolvers took 1.0 tries on average

Statement

A vending machine counts how many drinks are sold each day and leaves a record. The machine holds few drinks, so at most 9 are sold in a day. The number sold in a day is therefore always written as a single digit from 0 to 9.

To save paper, the record is written as one joined line, with no space and no comma. The left end is the first day, and later days run to the right. For example, if 2, 0, and 7 drinks were sold over three days in order, the record is written as 207. A day with no sales is written as 0, and the first digit of the record can be 0 because the first day was 0.

Given the number of recorded days N and the record for those N days, write a program that prints the total number of drinks sold over the N days. The record is not one number but single digits joined together, so the digits have to be taken apart one at a time and added. Reading the record as one number drops a leading 0, and then the number of days no longer matches.

For example, suppose the record for N=5 days is 54321. Taking the number sold on each day apart gives the table below.

Day12345
Number sold54321

Adding from the left in order, and writing the total up to that point, gives the following.

Day12345
Total up to that day59121415

Adding the numbers sold on the five days gives 5 + 4 + 3 + 2 + 1 = 15. So the answer for this example is 15.

If every digit of the record is 0, nothing was sold on any day, so the answer is 0. If every digit is 9, the answer is 9 times N. N is at most 100 and the number sold in one day is at most 9, so the answer never goes above 900.

Input and Output Examples

Example 1

Input

5
54321

Output

15

Example 2

Input

2
09

Output

9

Example 3

Input

1
0

Output

0

Input

  • First, the number of recorded days N is given on the first line. N is a natural number between 1 and 100.

  • Next, the second line gives the record for the N days. The record is a string of N digits joined with no space, and each digit is a number between 0 and 9. The first digit may be 0. The length of the record is always equal to N, so there is no need to count the length of the line separately.

Output

  • Print the total number of drinks sold over the N days, on one line. Write one number and break the line. Do not attach any other character or space before or after it.

Requirements

  • Read the input from standard input and write the answer to standard output
  • The second line is not one number but a string of joined digits. You have to take the digits apart one at a time and add them
  • The first digit may be 0. Reading it as a number can make a digit disappear, so handling it as a string is safer
  • The output is one number and a newline, nothing else
  • Grading compares the output with the expected value down to the last character
  • You must write a program that reads from standard input and writes to standard output
  • Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
  • The languages you can use are Python and JavaScript
  • The memory limit is 256MB. The browser does not measure it, it only states it
  • The time limit is set by measuring the setter's reference solution on the same runtime
  • On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
  • There are 16 cases, and 3 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
  • You have to pass all 16 cases to solve this.
Read the requirements carefully before solving. Tampering with the grading to make a submission look like a pass can get you sanctioned if caught. The code you submit is published on the leaderboard along with the result.

Examples

3 public cases. Judging also uses hidden cases. You have to pass all 16 cases to solve this.

Input
Expected output
5
54321
15
1
0
0
2
09
9

Solution

Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.

0 chars1 lineMemory 256MB (recorded only)Reference 2.0ms

Submitting requires you to log in. Running against the public cases works without one.

You can test with 3 public cases. Submitting runs the hidden cases too.

People who solved this problem

The time shown is the time spent solving. Input reading time is outside the solver's control, so it is excluded. And since each device reports this value itself, we record which device measured it.

1bampal267ms187 charsPythonLinux / Chrome/158.0.8127.18 / 2코어 / 16GB

Log in and you can see the code once you solve this problem.