Skip to content

Instantly share code, notes, and snippets.

@AvocadosConstant
Created June 30, 2017 14:20
Show Gist options
  • Save AvocadosConstant/21ef955881d00c669b7328f0c77234ce to your computer and use it in GitHub Desktop.
Save AvocadosConstant/21ef955881d00c669b7328f0c77234ce to your computer and use it in GitHub Desktop.
import sys
"""
Solution to http://100.70.19.162:8000/contest/32/7
"""
stack = list(map(int, sys.stdin.read().splitlines()))
del stack[0]
stack = [(i, True) for i in stack]
popped = []
while stack:
val = stack[0][0]
if val >= len(stack) or not stack[val][1]:
popped.append(stack.pop(0)[0])
else:
stack[0], stack[val] = stack[val], (val, False)
print(','.join(map(str, popped)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment