I spent a few minutes staring at this and I still have no idea what it's for. What is `a[idx]` that makes it different from `res`?