public int candy(int[] ratings) {

		int n = ratings.length;
		if (n <= 1)
			return n;

		int[] ret = new int[n];
		for (int i = 0; i < n; i++) {
			if (i > 0 && ratings[i] > ratings[i - 1])
				ret[i] = ret[i - 1] + 1;
			else
				ret[i] = 1;
		}
		for (int i = n - 1; i >= 1; i--) {
			if (ratings[i - 1] > ratings[i]) {
				ret[i - 1] = Math.max(ret[i] + 1, ret[i - 1]);
			}
		}

		int total = 0;
		for (int i = 0; i < n; i++) {
			total += ret[i];
		}
		return total;
	}