Reverse BWT by Arjun Rao

from ctypes import *\x0d
import sys\x0d
#file = open(sys.argv[1])\x0d
#fileContents = file.read()\x0d
fileContents = sys.stdin.readlines()\x0d
#for line in fileContents.splitlines():\x0d
for line in fileContents:\x0d
    splitLine = line.split()\x0d
    position = int(splitLine[0])\x0d
    test = splitLine[1]\x0d
    stringAsList = list(test)\x0d
    listOfLists = list()\x0d
    def mapTest(list1,string):\x0d
        list1.insert(0,string)\x0d
    i = 0\x0d
    originalList = list()\x0d
    for s in stringAsList:\x0d
        newList = list(s)\x0d
        if i == position:\x0d
            originalList = newList\x0d
        listOfLists.append(newList)\x0d
        i = i+1\x0d
    listOfLists.sort();\x0d
    for i in range(0,len(test)-1):\x0d
        map(mapTest,listOfLists,stringAsList)\x0d
        listOfLists.sort();\x0d
    print ''.join(originalList)\x0d
\x0d

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return top