#K45912. Sum of Prime Numbers in CSV

    ID: 27859 Type: Default 1000ms 256MiB

Sum of Prime Numbers in CSV

Sum of Prime Numbers in CSV

You are given a CSV (Comma Separated Values) formatted string representing a grid of values. Each row in the CSV is separated by a newline character (\n), and each value within a row is separated by a comma. Your task is to compute the sum of all prime numbers present in the CSV. A prime number is an integer \( n \) greater than 1 that has no positive divisors other than 1 and itself, i.e. \( n \) is prime if and only if \( n > 1 \) and for every integer \( a \) satisfying \( 2 \leq a \leq \sqrt{n} \), \( a \) does not divide \( n \).

If any cell in the CSV does not contain a valid integer, your program should output -1. If the input is empty, output 0.

inputFormat

The input is provided via standard input (stdin) as CSV-formatted text. The CSV text may span multiple lines.

outputFormat

Print a single integer to standard output (stdout). This integer is the sum of all primes found in the CSV. If any cell contains an invalid integer, print -1 instead.

## sample
23,10
17,19,20
64