using System;
using System.Collections.Generic;
public class Test
{
enum CurveState {
GoingDown=0, EqGoingDown=1, NotGoingDown=2
}
private static IList<int> GetValleys(IList<int> a) {
var res = new List<int>();
if (a.Count < 2) {
return res;
}
int lastEq = 0;
CurveState s = CurveState.NotGoingDown;
for (var i = 1 ; i != a.Count ; i++) {
switch(Math.Sign(a[i]-a[i-1])) {
case -1:
s = CurveState.GoingDown;
break;
case 0:
if (s == CurveState.GoingDown) {
lastEq = i;
}
s = (s==CurveState.NotGoingDown) ? CurveState.NotGoingDown : CurveState.EqGoingDown;
break;
case 1:
if (s == CurveState.GoingDown) {
res.Add(i-1);
} else if (s == CurveState.EqGoingDown) {
res.Add((lastEq+i-1)/2);
}
s = CurveState.NotGoingDown;
break;
}
}
return res;
}
public static void Main()
{
int[] data = new[] {0,0,1,2,4,7,9,6,4,4,2,1,0,0,0,0,0,3,5,5,10,3,2,1,4,5,7,7,12,11,8,4,2,
1,1,1,2,4,9,4,2,2,0,1,3,6,13,11,5,5,2,2,3,4,7,11,8};
IList<int> x = GetValleys(data);
for (var i=0 ; i != data.Length ; i++ ) {
Console.WriteLine("{0} {1}", data[i], x.IndexOf(i) >= 0 ? "*" : "");
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKCnB1YmxpYyBjbGFzcyBUZXN0CnsKCWVudW0gQ3VydmVTdGF0ZSB7CgkJR29pbmdEb3duPTAsIEVxR29pbmdEb3duPTEsIE5vdEdvaW5nRG93bj0yCgl9Cglwcml2YXRlIHN0YXRpYyBJTGlzdDxpbnQ+IEdldFZhbGxleXMoSUxpc3Q8aW50PiBhKSB7CgkJdmFyIHJlcyA9IG5ldyBMaXN0PGludD4oKTsKCQlpZiAoYS5Db3VudCA8IDIpIHsKCQkJcmV0dXJuIHJlczsKCQl9CgkJaW50IGxhc3RFcSA9IDA7CgkJQ3VydmVTdGF0ZSBzID0gQ3VydmVTdGF0ZS5Ob3RHb2luZ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