#C14745. Sum List Values

    ID: 44428 Type: Default 1000ms 256MiB

Sum List Values

Sum List Values

You are given a JSON object representing a dictionary with string keys and corresponding values. Each value may be a list of integers. Your task is to compute a new dictionary where for each key:

  • If the value is a list of integers, output the sum of the integers. That is, compute \(\sum_{i=1}^{n} a_i\).
  • If the value is not a list, output Error: contains non-list value.
  • If the value is a list but it contains any non-integer element, output Error: contains non-integer elements.

Print the resulting dictionary as a JSON object. The input and output are to be handled via standard input (stdin) and standard output (stdout) respectively.

inputFormat

The input is a single line containing a JSON object. The JSON object has string keys and values that are either arrays (i.e. lists) or other types. For example:

{"a": [1, 2, 3], "b": [4, 5], "c": [6]}

outputFormat

Output a single line which is a JSON object representing the result. For each key:

  • If its value is a list of integers, output the sum.
  • If the value is not a list, output Error: contains non-list value.
  • If the value is a list but contains any non-integer element, output Error: contains non-integer elements.

The output should be in JSON format with no extra spaces.

## sample
{"a": [1, 2, 3], "b": [4, 5], "c": [6]}
{"a":6,"b":9,"c":6}