# Rohan Banerjee

# Rachel Carson Middle School

# Junior-5

# ACSL Senet

# Python 2.6.4

 

word1 = raw_input("Input 1: ")

word2 = raw_input("Input 2: ")

word3 = raw_input("Input 3: ")

word4 = raw_input("Input 4: ")

word5 = raw_input("Input 5: ")

 

def senetfunction(string,b):

 

    if string == "":

        print "Result " + b + ": "

        return 0

   

    x = 0

    list = string.split()

    while x < (len(list) - 1):

        list[x] = list[x][0:len(list[x])-1]

        list[x] = int(list[x])

        x = x + 1

    list[len(list) - 1] = int(list[len(list) - 1])

 

    count = list[len(list) - 1]

 

    #Creating variable DONE that determines position of pawn

    DONE = list[1] + count

    COMPLETE = 0

   

    #House of Rebirth Check

    if (list[1] < 26) and (list[1] + count > 26):

        DONE = 26

        y = 2

        while y <= list[0]:

                if list[y] == 26:

                    DONE = 0

                    break

                y = y + 1

        COMPLETE = 1

 

    #House of Water

    if (list[1] == 26) and (count == 1):

        y = 2

        DONE = 15

        if list[0] == 1:

            DONE = 15

        else:

            while y <= list[0]:

                if list[y] == 15:

                    DONE = 27

                if list[y] == 27:

                    DONE = 0

                    break

                y = y + 1

        COMPLETE = 1

 

    #If it was already on 27

    if (list[1] == 27) and (count == 4):

        DONE = 1

        COMPLETE = 1

    elif (list[1] == 27) and (count != 4):

        DONE = 0

        COMPLETE = 1

   

    #House of Three Truths Check

    if (list[1] == 28) and (count == 3):

        DONE = 1

        COMPLETE = 1

    elif (list[1] == 28) and (count != 3):

        DONE = 0

        COMPLETE = 1

           

    #House of Re-Atoum Check

    if (list[1] == 29) and (count == 2):

        DONE = 1

        COMPLETE = 1

    elif (list[1] == 29) and (count != 2):

        DONE = 0

        COMPLETE = 1

 

    #Pawn on 30 only moves if count is 1

    if (list[1] == 30) and (count == 1):

        DONE = 1

        COMPLETE = 1

    elif (list[1] == 30) and (count != 1):

        DONE = 0

        COMPLETE = 1

 

   

    if (COMPLETE == 0):

        y = 2

        while y <= list[0]:

                if list[y] == (list[1] + count):

                    DONE = 0

                    break

                y = y + 1

 

    if (DONE == 1):

        print "Result " + b + ": DONE"

    elif (DONE == 0):

        print "Result " + b + ": CANNOT MOVE"

    else:

        print "Result " + b + ": " + str(DONE)

   

senetfunction(word1, '1')

senetfunction(word2, '2')

senetfunction(word3, '3')

senetfunction(word4, '4')

senetfunction(word5, '5')