#C14216. Average Age Calculator

    ID: 43841 Type: Default 1000ms 256MiB

Average Age Calculator

Average Age Calculator

Given a JSON array of persons, where each person is represented as an object with properties name (string), age (integer), and location (string), your task is to calculate the average age. The average is defined as

$$\bar{age} = \frac{\sum_{i=1}^{n} age_i}{n}$$

You should read the JSON array from standard input and print the result to standard output rounded to two decimal places. If the JSON array is empty, output ERROR.

inputFormat

The input is provided through standard input as a single line containing a valid JSON array. Each element of the array is an object with the following keys:

  • name: a string representing the person's name.
  • age: an integer representing the person's age.
  • location: a string representing the person's location.

outputFormat

Print the average age as a floating-point number rounded to two decimal places on standard output. If the JSON array is empty, print ERROR instead.

## sample
[{"name": "Alice", "age": 30, "location": "New York"}, {"name": "Bob", "age": 24, "location": "Chicago"}, {"name": "Charlie", "age": 29, "location": "San Francisco"}]
27.67