Hide

# Problem ABatter Up

Eager to gain every possible advantage in an effort to repeat their World Series Championship, the Chicago Cubs are beginning to embrace the empirical analysis of baseball statistics known as Sabermetrics. Sabermetrics collects and summarizes data to provide more accurate analysis of players and game outcomes.

For example, a player’s batting average is calculated by dividing the total number of hits by the total number of times at bat, or at-bats. One limitation of using the batting average to evaluate players is that it treats all hits equally and does not take into account doubles, triples or home runs.

To account for this discrepancy, a new metric, the slugging average, was created to distinguish between different hit outcomes. To calculate the slugging average, the total number of bases of all hits is divided by the number of at-bats. More specifically, an at-bat can earn $0$, $1$, $2$, $3$ or $4$ bases (strikeout, single, double, triple, or a home run, respectively). For example, if a player hit a triple ($3$ bases), struck out ($0$ bases), and hit a double ($2$ bases), their slugging average would be $\frac{3+0+2}{3}=1.666\dotsm$.

When computing the slugging average, we also have to take into account that a player could make a plate appearance that doesn’t count as an at-bat. For example, a plate appearance that results in a base-on-balls (i.e., a “walk”) is not considered in either the player’s batting average or slugging average. If a player hit a single ($1$ base), walked, and hit a home run ($4$ bases), the slugging average would be $\frac{1 + 4}{2}=2.5$. Notice how, in this case, the player made three plate appearances, but we divide by two (the number of at-bats) because the walk is not considered an at-bat and, thus, does not count towards the slugging average.

## Input

The input is composed of two lines. The first line contains a single positive integer $n$ ($1 \le n \le 100$) that specifies the number of plate appearances. The second line contains the plate appearances, each separated by a single space. Strikeouts, singles, doubles, triples, and home runs are represented as 0, 1, 2, 3, 4, respectively. Walks are represented as -1. You may assume that there will always be at least one at-bat (i.e., at least one plate appearance will not be a walk).

## Output

The output is a single floating point number: the player’s slugging average.

Your output does not have to match our output character by character; it will be enough for the value you print to be accurate to within an absolute or relative error of $10^{-3}$. For example, in the first sample output, if your program prints out 1.66667, this would also be an acceptable answer because the difference with the expected answer is less than $10^{-3}$. To accomplish this, we recommend that you do not format or round the floating point number: simply print it out with a few extra decimal places to ensure your answer is as close as possible to the accepted answer. This can be accomplished in most programming languages by simply printing the floating point number without specifying any particular formatting.

Sample Input 1 Sample Output 1
3
3 0 2

1.6666666666666667

Sample Input 2 Sample Output 2
3
1 -1 4

2.5

Sample Input 3 Sample Output 3
11
-1 -1 -1 -1 0 0 0 0 0 0 1

0.14285714285714285

Hide