QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 10

#11648. Byteland Lottery

Statistics

One of the most popular games organized by Byteland Lottery is "Huge blend". The rules of this game are simple. From the container with a fixed number of balls in it (each of them has a natural number assigned), some number of balls are chosen. In the next step the product of all numbers from the chosen balls is calculated. That product is the winning number. The person who guesses the right number wins the main prize. Before the drawing, it is known how many balls will take part in it. The numbers written on the balls are also known. It is not known however, how many balls will be selected - maybe all of them, or maybe only one.

ByteGuy always wanted to win "Huge blend", however years of fruitless attempts caused that he started to wonder about the chances of winning. He decided to count the number $ n $ - the sum of all possible results of draws. Unfortunately, ByteGuy's computer overheated during calculations, so he asked you to help him calculate something simpler - the value of $ F(n) $, where $ F $ is a function defined as follows:

  • $ F(k) = k $, $ k ≤ 9$
  • $ F(k) = F(\text{the sum of all digits of } k )$, $ k ≥ 10$

For example: $F(9) = 9$, $F(123) = 6$, $F(9876) = F(30) = 3$.

Write a program which:

  • reads from the standard input the number $ l $ (the number of balls taking part in a draw) and $l$ natural numbers $ w_{1}, w_{2}, \ldots, w_{l} $ (numbers printed on the balls),
  • computes the value of $ F(n) $, where $ n $ is the sum of all possible results of draws,
  • writes the answer to the standard output.

Input Format

The first line of the standard input contains a natural number $ l $ - the number of balls taking part in a draw, $1 ≤ l ≤ 10^{6}$. In the second line there are $ l $ natural numbers $ w_{m} $, $0 ≤ w_{m} ≤ 10^{8}$ - numbers written on the balls. They are separated with single spaces.

Output Format

One integer is to be written to the standard output. This integer should be the value of $ F(n)$.

Example

Input

3
10 13 12

Output

3

Discussions

About Discussions

The discussion section is only for posting: Editorials, 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. Submitting multiple issues may cause your account to be banned.
  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.