Given a natural number n, a peak in n are three consecutive digits of the representation in base 10 of n such that the one in the middle is strictly greater than the other two surrounding it.
Write a program that reads input numbers and counts how many peaks there are in each of them.
For example, with input 192056423 it must print 2.
Input
The input has an arbitrary number of cases. Each case has a positive natural number in one line.
Output
For each case, there is one line with the corresponding number of peaks.
Observation
It is not allowed to use any massive storage data structure, not even string. Please solve this exercise by just using type int and manipulating integers with the basic operators (+,-,*,/,%).
Assessment over 10 points:
We understand as fast solution one being correct, with linear cost and able to overcome both the public and private tests. We understand as slow solution one not being fast, but correct and able to overcome the public tests.
Input
1 5 10 111 121 983702120 132436475 123456789 987654321 35102 785902 1010101 101010 10101 30219834 123321233 410938 899999995 999999 113311 13221 2 3 1234567890
Output
0 0 0 0 1 3 4 0 0 1 2 2 2 1 2 0 1 0 0 0 1 0 0 1
Input
391430 783080367 109 2 29 2145601 3 8634 29449099 5292 5594 601921 43 425002 66332951 584707801 360981924 38480663 8882 5 4165874 57193 6 121277986 4844 7836 705250 6818 72153 99939 9622733 50215 991627275 201 4 52250 239189939 8 3239 6153 10523787 49 939488 4478644 12 89 418191 929814854 125886 11047
Output
2 2 0 0 0 1 0 0 2 1 1 1 0 1 1 3 3 2 0 0 2 2 0 2 1 1 2 1 1 0 1 1 3 0 0 1 1 0 0 1 2 0 1 1 0 0 2 2 0 0