public static int candy(int[] ratings) {
		int[] r=ratings;
		if (r.length==0)
			return 0;
		int all=1, seq=1;
		for (int i=1, n=r.length; i<n;) {
			if (r[i]>r[i-1]) {
				all+=++seq;
				++i;
			} else if (r[i]==r[i-1]){
				all+=seq=1;
				++i;
			} else {
				int t=1;
				while (i<n&&r[i]<r[i-1]) {
					if (t==seq)
						++t;
					all+=t++;
					++i;
				}
				seq=1;
			}
		}
		return all;
	}