public static int arithmeticSequence(int[] nums) {
		if (nums == null || nums.length < 3) return 0;
		int res = 0;
		int gap = nums[1] - nums[0];
		int length = 2;
		for (int i = 1; i < nums.length - 1; i++) {
			if (nums[i+1] - nums[i] == gap) {
				length++;
			} else {
				gap = nums[i+1] - nums[i];
				if (length >= 3) res += (length - 1) * (length - 2) / 2;
				if (res > 1000000000) return -1;
				length = 2;
			}
		}
		
		if (length >= 3) res += (length - 1) * (length - 2) / 2;
		return res > 1000000000 ? -1 : res;
	}