You are given a sequence of n integers x1,x2,…,xn, each of them from the set {−1,0,1}. The bytecomputer is a device that allows one operation on the sequence: choose an index i with 1≤i<n and increase xi+1 by xi. The range of integers the bytecomputer can store is unlimited, so in principle each xi can become arbitrarily small or arbitrarily large.
You want the sequence to be non-decreasing, that is, x1≤x2≤⋯≤xn. Find the minimum number of operations needed.
The first line contains one integer n, the length of the sequence (1≤n≤1000000).
The second line contains the n elements of the sequence x1,x2,…,xn in order, separated by single spaces (xi∈{−1,0,1}).
Print on one line the minimum number of operations that make the sequence non-decreasing. If no sequence of operations achieves that, print BRAK instead. BRAK is Polish for none.
Three operations turn the sequence −1,1,0,−1,0,1 into −1,−1,−1,−1,0,1.