#C12191. Moving Average Calculator

    ID: 41591 Type: Default 1000ms 256MiB

Moving Average Calculator

Moving Average Calculator

You are given a sequence of integers and a window size. Your task is to calculate the moving averages of the sequence using a sliding window. The moving average for a window of size \(w\) is computed using the formula:

\(\text{average} = \frac{a_i + a_{i+1} + \cdots + a_{i+w-1}}{w}\)

where \(a_i\) is the \(i\)-th integer in the sequence. You must read input from standard input (stdin) and output the results to standard output (stdout), with each moving average printed on a separate line. If the average is an integer, print it without a decimal point.

inputFormat

The input consists of two lines:

  • The first line contains a single integer \(w\) (window size).
  • The second line contains a space-separated list of integers.

You are guaranteed that the number of integers is at least \(w\).

outputFormat

Output the moving averages computed over every contiguous subsequence of \(w\) integers, with each average printed on a new line. If the computed average is an integer, output it without a decimal point; otherwise, output it as a floating-point number.

## sample
2
1 2 3 4 5
1.5

2.5 3.5 4.5

</p>