Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
num = int(input())
lis = list(map(int,input().split()))
sum = 0
min = list[0]
max = list[0]
for i in range(num):
    if(min > list[i]):min = list[i]
    if(max < list[i]):max = list[i]
    sum = sum+list[i]
    
print("%d %d %d" %(min,max,sum))


Fixed submission:
num = int(input())
lis = list(map(int,input().split()))
sum = 0
min = lis[0]
max = lis[0]
for i in range(num):
    if(min > lis[i]):min = lis[i]
    if(max < lis[i]):max = lis[i]
    sum = sum+lis[i]
    
print("%d %d %d" %(min,max,sum))
Buggy python submission (verdict: Runtime Error):
while True:
    num = list(map(int,input().split()))
    if(num[0] == 0 and num[1] == 0): break
    else:
        flag = False
        for i in range(num[0]):
            str = ""
            if(i == 0 or i == num[0]-1): flag=True
            else: flag=False
            for j in range(num[1]):
                if(j == 0 or j == num[1]-1 or flag=True):
                    str = str + "#"
                else:
                    str = str + "."
            print(str)
        print()
                    


Fixed submission:
while True:
    num = list(map(int,input().split()))
    if(num[0] == 0 and num[1] == 0): break
    else:
        flag = False
        for i in range(num[0]):
            str = ""
            if(i == 0 or i == num[0]-1): flag=True
            else: flag=False
            for j in range(num[1]):
                if(j == 0 or j == num[1]-1 or flag):
                    str = str + "#"
                else:
                    str = str + "."
            print(str)
        print()
Buggy python submission (verdict: Runtime Error):
function check(n):
    i = 1
    print(" ",end="")
    while(i != n):
        if  (i % 3 == 0):
            print(i,end="")
        elif(i % 10 == 3):
            print(i,end="")
            i = i / 10
        


Fixed submission:
n = int(input())

for  i in range(1,n+1):
    if i%3 == 0 or str(i).find("3") != -1:
        print(" %d" %i ,end="")
print()

Buggy python submission (verdict: Runtime Error):
function check(n):
    i = 1
    print(" ",end="")
    while(i != n):
        if  (i % 3 == 0):
            print(i,end="")
        elif(i % 10 == 3):
            print(i,end="")
            i = i / 10
        
check(30)


Fixed submission:
n = int(input())

for  i in range(1,n+1):
    if i%3 == 0 or str(i).find("3") != -1:
        print(" %d" %i ,end="")
print()

Buggy python submission (verdict: Runtime Error):
inp = int(input())

function check(n):
    i = 1
    print(" ",end="")
    while(i != n):
        if  (i % 3 == 0):
            print(i,end="")
        elif(i % 10 == 3):
            print(i,end="")
            i = i / 10

check(inp)


Fixed submission:
n = int(input())

for  i in range(1,n+1):
    if i%3 == 0 or str(i).find("3") != -1:
        print(" %d" %i ,end="")
print()

Buggy python submission (verdict: Time Limit Exceeded):
inp = int(input())

def check(n):
    i = 1
    print(" ",end="")
    while(i != n):
        if  (i % 3 == 0):
            print(i,end="")
        elif(i % 10 == 3):
            print(i,end="")
            i = i / 10

check(inp)


Fixed submission:
n = int(input())

for  i in range(1,n+1):
    if i%3 == 0 or str(i).find("3") != -1:
        print(" %d" %i ,end="")
print()

Buggy python submission (verdict: Time Limit Exceeded):
inp = int(input())

def check(n):
    i = 1
    print(" ",end="")
    while(i != n):
        if  (i % 3 == 0):
            print(i,end="")
        elif(i % 10 == 3):
            print(i,end="")
            i = i / 10
        i = i + 1
        

check(inp)


Fixed submission:
n = int(input())

for  i in range(1,n+1):
    if i%3 == 0 or str(i).find("3") != -1:
        print(" %d" %i ,end="")
print()

Buggy python submission (verdict: Runtime Error):
inp = int(input())

for  i in range(1,n+1):
    i = 1
    x = i
    if(x%3 == 0):
        print(" %d", end="")
    else:
        while(x):
            if(x%10 == 3):
                print(" %d", end="")
                break
            else:
                x //= 10

        
        

check(inp)


Fixed submission:
n = int(input())

for  i in range(1,n+1):
    if i%3 == 0 or str(i).find("3") != -1:
        print(" %d" %i ,end="")
print()
Buggy python submission (verdict: Runtime Error):
import numpy as np

r,c = map(int,input().split())
table = [[0]*c for i in range(r)]




Fixed submission:
r,c = map(int,input().split())
table = [[0]*(c+1) for i in range(r+1)]

for i in range(r):
    table[i] = list(map(int,input().split()))
    table[i].append(sum(table[i]))
    for j in range(c+1):
        table[r][j] += table[i][j]

for i in range(r+1):
    for j in range(c+1):
        if(j == c):
            print("%d" %(table[i][j]),end="")
        else:
            print("%d " %(table[i][j]),end="")
    print()
Buggy python submission (verdict: Runtime Error):
n,m,l = map(int,input().split())
a = [[0]*m for i in range(n)]
b = [[0]*l for i in range(m)]
c = []
for i in range(n):
    a[i] = list(map(int,input().split()))

for i in range(m):
    b[i] = list(map(int,input().split()))

for k,v in a:
    tmp = []
    for kk,vv in zip(*b):
        tmp.append(k * kk + v * vv)
    c.append(tmp)

for i in range(n):
    for j in range(l):
        print("%d" %c[i][j],end="")
        if(j < l-1): print(" ",end="")
        else: print()


Fixed submission:
n,m,l = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(n)]
b = [list(map(int,input().split())) for _ in range(m)]

[print(*x) for x in [[sum(j*k for j,k in zip(x,y)) for y in zip(*b)]for x in a]]

Buggy python submission (verdict: Runtime Error):
n,m,l = map(int,input().split())
a = [[0]*m for i in range(n)]
b = [[0]*l for i in range(m)]
c = []
for i in range(n):
    a[i] = list(map(int,input().split()))

for i in range(m):
    b[i] = list(map(int,input().split()))

for k,v in a:
    tmp = []
    for kk,vv in zip(*b):
        tmp.append(k * kk + v * vv)
    c.append(tmp)

for i in range(n):
    for j in range(l):
        print("%d" %c[i][j],end="")
        if(j < l-1): print(" ",end="")
        else: print()


Fixed submission:
n,m,l = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(n)]
b = [list(map(int,input().split())) for _ in range(m)]

[print(*x) for x in [[sum(j*k for j,k in zip(x,y)) for y in zip(*b)]for x in a]]
Buggy python submission (verdict: Runtime Error):
print(input().swapcase()))



Fixed submission:
print(input().swapcase())
Buggy python submission (verdict: Runtime Error):
while True:
    num = input()
    ret = 0
    for i in num:
        ret += num
    print(num)


Fixed submission:
while True:
    num = input()
    if(num == "0"): break
    ret = 0
    for i in num:
        ret += int(i)
    print(ret)

Buggy python submission (verdict: Runtime Error):
while True:
    num = input()
    ret = 0
    for i in num:
        ret += int(i)
    print(num)


Fixed submission:
while True:
    num = input()
    if(num == "0"): break
    ret = 0
    for i in num:
        ret += int(i)
    print(ret)

Buggy python submission (verdict: Runtime Error):
while True:
    num = input()
    if(num == 0): break
    ret = 0
    for i in num:
        ret += int(i)
    print(ret)


Fixed submission:
while True:
    num = input()
    if(num == "0"): break
    ret = 0
    for i in num:
        ret += int(i)
    print(ret)

Buggy python submission (verdict: Runtime Error):
while True:
    num = str(input())
    if(num == 0): break
    ret = 0
    for i in num:
        ret += int(i)
    print(ret)


Fixed submission:
while True:
    num = input()
    if(num == "0"): break
    ret = 0
    for i in num:
        ret += int(i)
    print(ret)
Buggy python submission (verdict: Runtime Error):
str = input()
for i in range(0x61,0x7b):
    print("%c : %d", %(i,str.count(str(i))))


Fixed submission:
import sys

data = sys.stdin.read()
for i in range(0x61,0x7b):
    print("%c : %d"  %(i,data.lower().count(chr(i))))

Buggy python submission (verdict: Runtime Error):
st = input()
for i in range(0x61,0x7b):
    print("%c : %d", %(i,st.count(str(i))))


Fixed submission:
import sys

data = sys.stdin.read()
for i in range(0x61,0x7b):
    print("%c : %d"  %(i,data.lower().count(chr(i))))

Buggy python submission (verdict: Runtime Error):
st = input()
for i in range(0x61,0x7b):
    print("%c : %d", %(i,st.count(chr(i))))


Fixed submission:
import sys

data = sys.stdin.read()
for i in range(0x61,0x7b):
    print("%c : %d"  %(i,data.lower().count(chr(i))))

Buggy python submission (verdict: Runtime Error):
import sys

data = sys.stdin().read()
for i in range(0x61,0x7b):
    print("%c : %d"  %(i,data.lower().count(chr(i))))


Fixed submission:
import sys

data = sys.stdin.read()
for i in range(0x61,0x7b):
    print("%c : %d"  %(i,data.lower().count(chr(i))))
Buggy python submission (verdict: Runtime Error):
data = input()
target = input()

start = 0
flag = "No"
for i in target:
    if(data[start:].find(i)):
        start = data[start:].find(i)
    elif(data[:start].find(i)):
        start = data.[:start:].find(i)
    else:
        print("No")
        break
    if(i == target[-1]):
        print("Yes")
        break


Fixed submission:
s = input()*2
p = input()
print("Yes" if p in s else "No")

Buggy python submission (verdict: Runtime Error):
data = input()
target = input()

start = 0
flag = "No"
for i in target:
    if(data[start:].find(i)):
        start = data[start:].find(i)
    elif(data[:start].find(i)):
        start = data.[:start].find(i)
    else:
        print("No")
        break
    if(i == target[-1]):
        print("Yes")
        break


Fixed submission:
s = input()*2
p = input()
print("Yes" if p in s else "No")
Buggy python submission (verdict: Runtime Error):
target = input()
data = ""
while True:
    string = input()
    if(string == "END_OF_FILE"): break
    data += string

print("%d" %(data.lower().count(target.lower())))


Fixed submission:
import sys
target = input()
data = sys.stdin.read()

print("%d" %(data.lower().split().count(target.lower())))

Buggy python submission (verdict: Runtime Error):
target = input()
data = ""
while True:
    tmp = input()
    if(tmp == "END_OF_FILE"): break
    data += tmp

print("%d" %(data.lower().count(target.lower())))


Fixed submission:
import sys
target = input()
data = sys.stdin.read()

print("%d" %(data.lower().split().count(target.lower())))
Buggy python submission (verdict: Runtime Error):
while True:
    data = input()
    if(data == "-"):break
    m = int(input())
    tmp = []
    flag = False
    for i in range(m):
        num = int(input())
        if(!flag):
            tmp = data[num:] + data[:num]  
            flag = True
            data = ""
        else:
            data = tmp[num:] + tmp[:num]
            flag = False
            tmp = ""


Fixed submission:
while True:
    data = input()
    if(data == "-"):break
    m = int(input())
    tmp = []

    for i in range(m):
        num = int(input())
        if(len(tmp) == 0):
            tmp = data[num:] + data[:num]
            data = ""
        else:
            data = tmp[num:] + tmp[:num]
            tmp = ""
    if(data): print(data)
    else: print(tmp)
Buggy python submission (verdict: Runtime Error):
n = int(input())
tp = 0
hp = 0
for i in range(n):
    tarou, hanako = map(str,input().split())
    if(tarou > hanko):
        tp += 3
    elif(tarou < hanako):
        hp += 3
    else:
        tp += 1
        hp += 1
print("%d %d" %(tp,hp))


Fixed submission:
n = int(input())
tp = 0
hp = 0
for i in range(n):
    tarou, hanako = map(str,input().split())
    if(tarou > hanako):
        tp += 3
    elif(tarou < hanako):
        hp += 3
    else:
        tp += 1
        hp += 1
print("%d %d" %(tp,hp))
Buggy python submission (verdict: Runtime Error):
n = int(input())
R = [0]*100
for i in range(n):
    R[i] = int(input())
    
minv = R[0]
maxv = R[1] - R[0]
for i in range(1,n):
    maxv = max(maxv, R[i] - minv)
    minv = min(minv, R[i])
print(maxv)


Fixed submission:
n = int(input())
R = [0]*n
for i in range(n):
    R[i] = int(input())
    
minv = R[0]
maxv = R[1] - R[0]
for i in range(1,n):
    maxv = max(maxv, R[i] - minv)
    minv = min(minv, R[i])
print(maxv)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(raw_input())

i, c = 0, 0

while(i<n):
    a = int(raw_input())

    if a==2:
        c+=1

    for x in xrange(2, a):
        if a%x==0:
            break

        if a-1==x and a%x!=0:
            c+=1

    i+=1
print c

Fixed submission:
import math

n = int(raw_input())

def isPrime(a):
    if a==2 or a==3:
        return 1
    if a<2 or a%2==0:
        return 0
        
    i = int(math.sqrt(a))+1
    for x in xrange(3,i):
        if a%x==0:
            return 0
    return 1

cnt = 0
for _ in xrange(n):
    a = int(raw_input())
    cnt += isPrime(a)
print cnt

Buggy python submission (verdict: Time Limit Exceeded):
n = int(raw_input())

c = 0

pn = []

for i in xrange(n):

    a = int(raw_input())

    if a==2:
        c+=1
        pn.append(a)
        continue

    for x in pn:
        if a==x:
            c+=1
            pn.append(a)
            break

    for x in xrange(2, a):
        if a%x==0:
            break

        if a-1==x and a%x!=0:
            c+=1

print c

Fixed submission:
import math

n = int(raw_input())

def isPrime(a):
    if a==2 or a==3:
        return 1
    if a<2 or a%2==0:
        return 0
        
    i = int(math.sqrt(a))+1
    for x in xrange(3,i):
        if a%x==0:
            return 0
    return 1

cnt = 0
for _ in xrange(n):
    a = int(raw_input())
    cnt += isPrime(a)
print cnt
Buggy python submission (verdict: Runtime Error):
n = int(raw_input())

rt = [int(raw_input()) for x in xrange(n)]

i_max = rt.index(max(rt))
i_min = rt.index(min(rt))

a = rt[i_max] - min(rt[1:i_max])
b = max(rt[i_min:]) - rt[i_min]

print a if a > b else b

Fixed submission:
n = int(raw_input())

_min, dif = 10**10, -10**10
for x in xrange(n):
    a = int(raw_input())
    if a -_min > dif:
        dif = a - _min
    if a < _min:
        _min = a
print dif
Buggy python submission (verdict: Runtime Error):
n = raw_input()
A = map(int, raw_input().split())
cnt = 0
for i in xrange(len(A)-1):
    mini = i
    for j = i in xrange(len(A)-1):
        if A[j] < A[mini]
            mini = j
    A[i], A[mini] = A[mini], A[j]
    cnt += 1
for x in A:
	print x,
print
print cnt

Fixed submission:
n = raw_input()
A = map(int, raw_input().split())
cnt = 0
for i in xrange(len(A)):
    mini = i
    for j in xrange(i, len(A)):
        if A[j] < A[mini]:
            mini = j
    if A[i]!=A[mini]:
	    cnt += 1
	    A[i], A[mini] = A[mini], A[i]
for x in A:
	print x,
print
print cnt

Buggy python submission (verdict: Runtime Error):
n = raw_input()
A = map(int, raw_input().split())
cnt = 0
for i in xrange(len(A)-1):
    mini = i
    for j in xrange(i, len(A)-1):
        if A[j] < A[mini]
            mini = j
    A[i], A[mini] = A[mini], A[j]
    cnt += 1
for x in A:
	print x,
print
print cnt

Fixed submission:
n = raw_input()
A = map(int, raw_input().split())
cnt = 0
for i in xrange(len(A)):
    mini = i
    for j in xrange(i, len(A)):
        if A[j] < A[mini]:
            mini = j
    if A[i]!=A[mini]:
	    cnt += 1
	    A[i], A[mini] = A[mini], A[i]
for x in A:
	print x,
print
print cnt
Buggy python submission (verdict: Runtime Error):
import sys

for line in sys.stdin.readlines():
    S = map(int, line.strip().split())

    h = S/60

    S1 = S%h
    m = S1/60

    s = S1/m

    print "%d:%d:%d", h, m, s

Fixed submission:
S =input()
h = int(int(S / 60) / 60)
m = int(S/60) % 60
s = S % (60*60) % 60
print "%d:%d:%d" % (h, m, s)

Buggy python submission (verdict: Runtime Error):
import os
import sys
 
# for line in sys.stdin.readlines():
    S = map(int, line.strip().split())

    h, m, s = 0, 0, 0

    h = S/3600

    S1 = S-h*3600

    if S1:
        m = S1/60
    elif S1 == 0:
        m = 0

    if m:
        s = S1-m*60
    elif m == 0:
        s = S1

    print "%d:%d:%d" % (h, m, s)

Fixed submission:
S =input()
h = int(int(S / 60) / 60)
m = int(S/60) % 60
s = S % (60*60) % 60
print "%d:%d:%d" % (h, m, s)

Buggy python submission (verdict: Runtime Error):
import os
import sys
  
for line in sys.stdin.readlines():
    S = map(int, line.strip().split())
 
    h, m, s = 0, 0, 0
 
    h = S/3600
 
    S1 = S-h*3600
 
    if S1:
        m = S1/60
    elif S1 == 0:
        m = 0
 
    if m:
        s = S1-m*60
    elif m == 0:
        s = S1
 
    print "%d:%d:%d" % (h, m, s)

Fixed submission:
S =input()
h = int(int(S / 60) / 60)
m = int(S/60) % 60
s = S % (60*60) % 60
print "%d:%d:%d" % (h, m, s)

Buggy python submission (verdict: Runtime Error):
import os
import sys
   
for line in sys.stdin.readlines():
    S = map(int, line.strip().split())
  
    h, m, s = 0, 0, 0
  
    h = S/3600
  
    S1 = S-h*3600
  
    if S1 == 0:
        m = 0
    else:
        m = S1/60
  
    if m == 0:
        s = S1
    else:
        s = S1 - m*60
  
    print "%d:%d:%d" % (h, m, s)

Fixed submission:
S =input()
h = int(int(S / 60) / 60)
m = int(S/60) % 60
s = S % (60*60) % 60
print "%d:%d:%d" % (h, m, s)
Buggy python submission (verdict: Runtime Error):
import sys

for line in sys.stdin.readline():
 a, b, c = map(int, line.strip().split())

 if (a < b) and (b < c):
  print "Yes"
 else:
  print "No"

Fixed submission:
a,b,c = raw_input().split()
if a<b<c:
    print 'Yes'
else:
    print 'No'

Buggy python submission (verdict: Runtime Error):
import sys

for line in sys.stdin.readlines():
 a, b, c = map(int, line.strip().sprit())
 if (a<b) and (b<c):
  print "Yes"
 else:
  print "No"

Fixed submission:
a,b,c = raw_input().split()
if a<b<c:
    print 'Yes'
else:
    print 'No'

Buggy python submission (verdict: Runtime Error):
a, b, c = input_raw().split()
if a<b<c:
    print "Yes"
else:
    print "No"

Fixed submission:
a,b,c = raw_input().split()
if a<b<c:
    print 'Yes'
else:
    print 'No'
Buggy python submission (verdict: Runtime Error):
lists = list(int, raw_input().split())
print sorted(lists) 

Fixed submission:
l = map(int, raw_input().split())
a, b, c = sorted(l)
print a, b, c

Buggy python submission (verdict: Runtime Error):
a,b,c = map(int, raw_input().split())
lists = [a,b,c]
new_list = sorted(lists)
print new_lists[0], new_lists[1], new_lists[2]

Fixed submission:
l = map(int, raw_input().split())
a, b, c = sorted(l)
print a, b, c
Buggy python submission (verdict: Runtime Error):
import os
import sys

for i,n in enumerate(int(sys.stdin.readlines())):
    if n!=0:
        print "Case %d: %d" % (i, n)

Fixed submission:
import sys

i = 1

while(1):
    a = raw_input()
    if('0'==a):
        break
    else:
        print "Case %d: %s" % (i, a)
        i += 1

Buggy python submission (verdict: Runtime Error):
import os
import sys

lists = []
for n in sys.stdin.readlines()):
    lists.append(int(n))

for i, n in enumerate(lists):
    if n!=0:
        print "Case %d: %d" % (i, n)

Fixed submission:
import sys

i = 1

while(1):
    a = raw_input()
    if('0'==a):
        break
    else:
        print "Case %d: %s" % (i, a)
        i += 1

Buggy python submission (verdict: Runtime Error):
import sys

lists = sys.stdin().readlines()

for i, int(line) in enumerate(lists):
 if(line[i]!=0):
  print "Case %d: %d" % (i, line[i])
 else:
  break

Fixed submission:
import sys

i = 1

while(1):
    a = raw_input()
    if('0'==a):
        break
    else:
        print "Case %d: %s" % (i, a)
        i += 1
Buggy python submission (verdict: Time Limit Exceeded):
def is_prime(num):
    for i in range(2, num):
        if num % i == 0:
            return False
    return True

n = int(input())
nums = [int(input()) for _ in range(n)]
print(sum(map(is_prime, nums)))

Fixed submission:
def is_prime(num):
    for i in range(2, int(num ** 0.5) + 1):
        if num % i == 0:
            return False
    return True

n = int(input())
nums = [int(input()) for _ in range(n)]
print(sum(map(is_prime, nums)))
Buggy python submission (verdict: Runtime Error):
import collections
n = int(input())
que = collections.deque()
for _ in range(n):
    command = input()
    if 'insert' in command:
        command, num = command.split()
        que.appendleft(int(num))
    elif 'deleteFirst' in command:
        que.popleft()
    elif 'deleteLast' in command:
        que.pop()
    elif 'delete' in command:
        command, num = command.split()
        que.remove(int(num))
print(' '.join(map(str, que)))

Fixed submission:
import sys
import collections
n = int(input())
que = collections.deque()

for _ in range(n):
    command = sys.stdin.readline()
    if 'i' == command[0]:
        command, num = command.split()
        que.appendleft(num)
    elif 'deleteFirst\n' == command:
        que.popleft()
    elif 'deleteLast\n' == command:
        que.pop()
    else:
        command, num = command.split()
        try:
            que.remove(num)
        except ValueError:
            pass
print(' '.join(map(str, que)))

Buggy python submission (verdict: Time Limit Exceeded):
import collections
n = int(input())
que = collections.deque()
for _ in range(n):
    command = input()
    if 'insert' in command:
        command, num = command.split()
        que.appendleft(int(num))
    elif 'deleteFirst' in command:
        que.popleft()
    elif 'deleteLast' in command:
        que.pop()
    elif 'delete' in command:
        command, num = command.split()
        if int(num) in que:
            que.remove(int(num))
print(' '.join(map(str, que)))

Fixed submission:
import sys
import collections
n = int(input())
que = collections.deque()

for _ in range(n):
    command = sys.stdin.readline()
    if 'i' == command[0]:
        command, num = command.split()
        que.appendleft(num)
    elif 'deleteFirst\n' == command:
        que.popleft()
    elif 'deleteLast\n' == command:
        que.pop()
    else:
        command, num = command.split()
        try:
            que.remove(num)
        except ValueError:
            pass
print(' '.join(map(str, que)))

Buggy python submission (verdict: Runtime Error):
import sys
import collections
n = int(input())
que = collections.deque()

for _ in range(n):
    command = sys.stdin.readline().strip()
    if 'i' == command[0]:
        command, num = command
        que.appendleft(num)
    elif 'deleteFirst\n' == command:
        que.popleft()
    elif 'deleteLast\n' == command:
        que.pop()
    else:
        command, num = command.split()
        try:
            que.remove(num)
        except ValueError:
            pass
print(' '.join(map(str, que)))

Fixed submission:
import sys
import collections
n = int(input())
que = collections.deque()

for _ in range(n):
    command = sys.stdin.readline()
    if 'i' == command[0]:
        command, num = command.split()
        que.appendleft(num)
    elif 'deleteFirst\n' == command:
        que.popleft()
    elif 'deleteLast\n' == command:
        que.pop()
    else:
        command, num = command.split()
        try:
            que.remove(num)
        except ValueError:
            pass
print(' '.join(map(str, que)))
Buggy python submission (verdict: Runtime Error):
axis_1 = '0154' * 2  # 2 -> 3
axis_2 = '0253' * 2  # 4 -> 1
axis_3 = '3124' * 2  # 0 -> 5

right = [axis_3, axis_2[::-1], axis_1, axis_1[::-1], axis_2, axis_3[::-1], ]
a = list(map(int, input().split()))
n = int(input())
for _ in range(n):
    top, front = map(a.index, map(int, input().split()))
    x = '%d%d' % (top, front)
    for i, axis in enumerate(right):
        if x in axis:
            print(a[i])
            break
    else:
        print('------------------')
        print(x)

Fixed submission:
a = list(map(int, input().split()))
commands = input()
for command in commands:
    if command == 'N':
        a[0], a[1], a[5], a[4] = a[1], a[5], a[4], a[0]
    elif command == 'S':
        a[0], a[1], a[5], a[4] = a[4], a[0], a[1], a[5]
    elif command == 'W':
        a[0], a[3], a[5], a[2] = a[2], a[0], a[3], a[5]
    elif command == 'E':
        a[0], a[3], a[5], a[2] = a[3], a[5], a[2], a[0]
print(a[0])