stack<int> s // n, a[n] forn(i, n) while s.size() && a[s.top()] >= a[i] right[s.pop()] = i s.push(i)