#C5785. Arithmetic Progression Checker
Arithmetic Progression Checker
Arithmetic Progression Checker
You are given a sequence of integers. The first integer n represents the number of elements in the sequence. The following n integers form the sequence. Your task is to determine if the sequence forms an arithmetic progression. An arithmetic progression is a sequence in which the difference between any two consecutive numbers is the same. If the sequence is an arithmetic progression, output the common difference; otherwise output NO
.
Note: All formulae must be rendered in LaTeX. For example, the common difference is defined as \(d = a_2 - a_1\), and for all \(i\) from 2 to \(n\), \(a_i - a_{i-1} = d\).
inputFormat
The input is given as a single line via standard input. The first integer represents \(n\), the number of elements in the sequence, followed by \(n\) space-separated integers representing the sequence.
outputFormat
If the sequence is an arithmetic progression, print the common difference; otherwise, print NO
. The output should be written to standard output.
4 2 4 6 8
2