```
class Solution(object):
def lastRemaining(self, n):
"""
each round the remaining list can be represented as (start,count,step)
:type n: int
:rtype: int
"""
start, count, step = 1, n, 1
while count > 1:
end = start + (count - 1) * step
# compute the next round
start = end - (count % 2) * step
count /= 2
step *= -2
return start
```