AIOC Banner

Problem: Chocolate Shop

Want to try solving this problem? You can submit your code online if you log in or register.

Chocolate Shop

Input File: chocin.txt
Output File: chocout.txt
Time Limit: 1.2 seconds

Each weekend you work in a local chocolate shop. The chocolates are stored in boxes with ten chocolates in each box. Each time a customer comes in to buy some chocolates you take them from an already-open box. If there are not enough chocolates in the current box, you completely finish the box before opening a new box. You are not allowed to have any more than one box open at a time, and you cannot open a new box unless a customer has purchased some of the chocolates in that box.

The chocolates in this shop are particularly famous, so every person who comes in buys at least one chocolate. However, as they are very expensive, no one ever buys more than nine.

At the start of the day, there are no open boxes. If at the end of the day the currently open box has chocolates left in it, you are allowed to take them home and share them with your friends (or just eat them yourself if you are feeling greedy). Your task is to write a program that reads in the series of purchases for the day and prints how many chocolates you will get at the end.


The first line of the input file will contain a single integer N, the number of purchases that have taken place during the day ( 0  <= N  <= 10000000). Following this will be N lines listing the day's purchases in the order they took place. Each of these lines will contain a single digit between 1 and 9, inclusive.


Your output file should contain a single integer, giving the number of chocolates you will take home at the end of the day.

Sample Input


Sample Output



The score for each input scenario will be 100% if the correct answer is written to the output file, and 0% otherwise.


Privacy statement
© Australian Mathematics Trust 2001-2018

Page generated: 19 July 2018,  6:23am AEST