#K39207. Restore Arithmetic Progression

    ID: 26369 Type: Default 1000ms 256MiB

Restore Arithmetic Progression

Restore Arithmetic Progression

You are given an integer n and a sequence of n integers in which exactly one entry is missing and is denoted by -1. The task is to determine the number of valid ways to replace the missing value with an integer between 1 and n (inclusive) that is not already present in the sequence such that the resulting sequence forms an arithmetic progression.

An arithmetic progression is a sequence of numbers in which the difference between consecutive terms is constant. The common difference can be positive, negative, or zero.

Note: The missing element (-1) appears exactly once in the input sequence.

inputFormat

The input is read from stdin in the following format:


a1 a2 a3 ... an

Where:

  • n is the number of elements in the sequence.
  • a1, a2, ..., an is the sequence of integers. Exactly one of these numbers will be -1 indicating the missing value.

outputFormat

Output a single integer to stdout representing the number of valid ways to replace the missing element such that the sequence becomes an arithmetic progression.

## sample
5
1 -1 3 4 5
1