private static int pos_neg_flat(int[] seq, int start, int type) {
	if (start > seq.length -2) return -1;
	int cd = seq[start+1] - seq[start];

        if (type == 1 && cd <= 0) return -1; // positive
	if (type == 2 && cd >= 0) return -1; // negative
	if (type == 3 && cd != 0) return start; // flat

	int i = start+1;
	while (i < seq.length && seq[i] - seq[i-1] == cd) i++;
	return i;
    }