#C12993. Arithmetic Progression Check
Arithmetic Progression Check
Arithmetic Progression Check
Given a sequence of numbers, determine whether the sequence forms an arithmetic progression. A sequence \(a_0, a_1, \ldots, a_{n-1}\) is called an arithmetic progression if either \(n \leq 1\) or there exists a constant difference \(d\) such that for all \(1 \leq i < n\), \(a_i - a_{i-1} = d\).
Note that an empty sequence or a sequence with a single element is considered an arithmetic progression.
Examples:
- Input: [] or [5] → Output: True
- Input: [5, 7, 9, 11, 13] → Output: True, with \(d=2\)
- Input: [1, 2, 4, 5] → Output: False
inputFormat
The first line contains an integer \(n\), denoting the number of elements in the sequence. The second line contains \(n\) space-separated numbers, which can be either integers or floating-point numbers. If \(n = 0\), the sequence is considered empty.
outputFormat
Output a single line containing either True
if the sequence forms an arithmetic progression, or False
otherwise.
0
True