How many nines?

Availability is often promised as a number of nines: "three nines" means the system is up at least 99.9% of the time. Here you measure it from a list of outages.

What to build

Read the length of a period and its outages, then print the downtime, the availability and how many nines it reaches.

Requirements

  • The period has days days of 1440 minutes each.
  • Print downtime X min, the total of the outage minutes.
  • Print availability P%, where P is the up time as a percentage with exactly 3 decimal places.
  • Print nines K: the largest K (0 to 5) such that availability is at least 100 − 10^(2−K) percent, so 1 nine is 90%, 2 is 99%, 3 is 99.9%, and so on. Use whole-number arithmetic for this test so rounding cannot change the answer.

Input

Line 1: the number of days. Each following line: one outage, in whole minutes.

Output

Three lines: downtime, availability and nines.

Constraints

1 to 366 days. 0 to 100 outages, each 1 to 100000 minutes, and their total is never more than the period.

Example

Input:

30
20
15

Output:

downtime 35 min
availability 99.919%
nines 3

Why it works

Availability K nines means the down share is at most 10^−K. Down minutes ≤ total minutes ÷ 10^K is the same as down × 10^K ≤ total, which needs no decimals, so it is exact.

Examples

Example 1 · Input
30
20
15
Expected output
downtime 35 min
availability 99.919%
nines 3
Example 2 · Input
365
Expected output
downtime 0 min
availability 100.000%
nines 5

Hints

Hint 1

Total minutes = days × 1440.

Hint 2

For nines, test down × 10^K ≤ total for K = 5, 4, 3, 2, 1 and stop at the first that holds; otherwise 0.

Hint 3

toFixed(3) prints 3 decimal places.

Solution

Show one correct solution (try it yourself first)
const days = Number(prompt());
let down = 0;
let line = prompt();
while (line !== null) {
  if (line.trim() !== "") down += Number(line);
  line = prompt();
}
const total = days * 1440;
console.log(`downtime ${down} min`);
console.log(`availability ${(((total - down) / total) * 100).toFixed(3)}%`);
let nines = 0;
for (let k = 5; k >= 1; k--) {
  if (down * 10 ** k <= total) { nines = k; break; }
}
console.log(`nines ${nines}`);

▶ Open this solution in the compiler, then press Visualize to watch it run step by step

Lesson: What security protects: the CIA triad →