#C14892. Average Salary per Department

    ID: 44591 Type: Default 1000ms 256MiB

Average Salary per Department

Average Salary per Department

You are given CSV data representing employee records. Each record contains the following fields: id, name, department, and salary. Your task is to compute the average salary for each department.

The average salary for a department is computed using the formula:

\( \text{Average} = \frac{\sum_{i=1}^{n} s_i}{n} \)

where \( s_i \) denotes the salary of the \(i\)-th employee in that department.

If any salary value is not a valid number, your program should output Invalid Input and terminate immediately with no further output. The CSV input always includes a header in the first line. Departments must be listed in alphabetical order in the output. In case the input is empty, produce no output.

inputFormat

Input is provided from stdin. The first line is a CSV header: id,name,department,salary. Each following line represents an employee record. Fields are separated by commas.

outputFormat

For valid input, output each department and its average salary on a new line in the format:

<average_salary>

Departments should appear in alphabetical order. The average salary should be computed as a floating point value. If any salary entry is invalid (i.e. cannot be converted to a number), output exactly Invalid Input (followed by a newline) and do not process further input.## sample

id,name,department,salary
1,John Doe,Engineering,50000
2,Jane Smith,Marketing,60000
3,Emily Jones,Engineering,55000
4,Michael Brown,HR,62000
5,Jessica Miller,Marketing,58000
6,Daniel Wilson,Engineering,53000
7,Laura Garcia,HR,61000
Engineering 52666.666666666664

HR 61500.0 Marketing 59000.0

</p>