public long process() {
        Collections.sort(_list, new Comparator<Num>() {
            @Override
            public int compare(Num o1, Num o2) {
                if (o1.num != o2.num)
                    return o1.num < o2.num ? 1 : -1;
                return o1.index < o2.index ? 1 : -1;
            }
        });
        int p = 0;
        long sum = 0;
        long prevSum = 0;
        long prevIndex = -1;
        while (true) {
            Num num = _list.get(p);
            if (num.index < prevIndex) {
                p++;
                continue;
            }
            sum += (num.index - prevIndex - 1) * num.num - (num.prevSum - prevSum);
            prevSum = num.prevSum + num.num;
            prevIndex = num.index;
            p++;
            if (num.index == _n - 1)
                break;
        }
        return sum;
    }