funcmax(nums...int)int{ans:=nums[0]fori:=1;i<len(nums);i++{ifnums[i]>ans{ans=nums[i]}}returnans}funccandy(ratings[]int)int{n:=len(ratings)left:=make([]int,n)left[0]=1fori:=1;i<n;i++{ifratings[i]>ratings[i-1]{left[i]=left[i-1]+1}else{left[i]=1}}// ans is initially left[n-1] instead of 1
right,ans:=1,left[n-1]fori:=n-2;i>=0;i--{ifratings[i]>ratings[i+1]{right++}else{right=1}ans+=max(right,left[i])}returnans}