public int candy(int[] ratings) {
		assert (ratings != null) : "Please input ratings!";

		int len = ratings.length;
		if (len == 0 || len == 1)
			return len;

		int[] dp = new int[len];

		// left -> right
		for (int i = 1; i < len; i++) {
			if (ratings[i] > ratings[i - 1]) {
				dp[i] = dp[i - 1] + 1;
			}
		}

		// right -> left
		for (int i = len - 2; i >= 0; i--) {
			if (ratings[i] > ratings[i + 1] && dp[i] < dp[i + 1] + 1) {
				dp[i] = dp[i + 1] + 1;
			}
		}

		int result = len;
		for (int i = 0; i < dp.length; i++) {
			result += dp[i];
		}

		return result;
	}