Rational Bubble Sort

You are given a sequence of integers. In one operation you may choose an adjacent pair and replace both values with their average. Formally, pick an index i and set both a[i] and a[i+1] to (a[i] + a[i+1]) / 2. The values are rational numbers after an operation, so later averages stay exact.

Determine whether a finite number of operations can make the sequence non-decreasing. Return 1 if it is possible and 0 otherwise.

The total sum of the sequence never changes, because the operation preserves the sum of the chosen pair and therefore the sum of the whole sequence.

Examples
Input: [0,0,0]
Output: 1
Hints

Rational Bubble Sort

You are given a sequence of integers. In one operation you may choose an adjacent pair and replace both values with their average. Formally, pick an index `i` and set both `a[i]` and `a[i+1]` to `(a[i] + a[i+1]) / 2`. The values are rational numbers after an operation, so later averages stay exact.