Shifty sort

Ayumu the chimp is given the task of sorting a group of integers a0,a1,a2,a3..a_{0},a_{1},a_{2},a_{3}.. into a non-decreasing order. Unfortunately Ayumu can only perform one operation,a single shift. That is,he can only move the last element of a sequence to the beginning. a0,a1,a2anan,a0,a1an1a_{0},a_{1},a_{2} \ldots a_{n} \rightarrow a_{n},a_{0},a_{1} \ldots a_{n-1} Let F(a)F(a) be the minimum number of times Ayumu has to do the single shift so that the sequence aa is sorted. If aa cannot be sorted with the shift operation then F(a)F(a) is equal to 1-1.

This text file contains 100 lines and in each line there is a sequence aa. Find the sum of F(a)F(a) for all the sequences in the text file.

Explicit examples

  • For the sequence a=[2,1]a=[2,1] , F(a)=1F(a)=1.

  • If a=[1]a=[1] , F(a)=0F(a)=0

  • If a=[1,3,2]a=[1,3,2] , F(a)=1F(a)=-1

  • If a=[1,2]a=[1,2] , F(a)=0F(a)=0


Problem Loading...

Note Loading...

Set Loading...