Harryxun/stf_run huggingface dataset:
#

array = list(map(int, input().strip().split(' ')))


N =  array[0]

T =  array[1]


#print(N)
#print(T)

if N < 1:
    sys.exit()

if N > 100:
    sys.exit()


if T < 1:
    sys.exit()

if T > 1000:
    sys.exit()



c_min = 9999


for i in range(N):
    array1 = list(map(int, input().strip().split(' ')))
    cN =  array1[0]

    tN =  array1[1]

    if cN < 1:
        sys.exit()

    if cN > 1000:
        sys.exit()

    if tN < 1:
        sys.exit()

    if tN > 1000:
        sys.exit()
    
    if tN <= T:
        if c_min > cN:

            c_min = cN

if c_min == 0:
    print("TLE")

else:
    print(c_min)

    


### FIXED CODE ###

n = int(input())


if n == 1:
    print("Hello World")

elif n == 2:

     a = int(input())
     b = int(input())

     c = a + b
     print(c)
from collections import Counter
s=list(input())
L_1=Counter(s).most_common()
print("Yes" if L_1[0][1]==L_1[1][1]==2 else "No")

### FIXED CODE ###

S=list(input())
print("Yes" if len(set(S))==2 else "No")
x,y=map(str,input().split())
"A"="1"
"B"="2"
"C"="3"
"D"="4"
"E"="5"
"F"="6"
if int(x)<int(y):
    print(<)
elif x==y:
    print(=)
else:
    print(>)

### FIXED CODE ###

x,y=map(str,input().split())
x=int(x,16)
y=int(y,16)
if x<y:
    print("<")
elif x==y:
    print("=")
else:
    print(">")
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def bit_add(a, i, n, x):
    while i < n:
        a[i] += x
        i += i & -i
def bit_add2(a, i, j, n, x):
    while i < j:
        while i < j:
            a[i] += x
            i += i & -i
        while j < i and j < n:
            a[j] -= x
            j += j & -j
def bit_sum(a, i):
    res = 0
    while i > 0:
        res += a[i]
        i ^= i & -i
    return res
def bit_select(a, i):
    if i & 1: return a[i]
    return a[i] - a[i-1]

def resolve():
    it = map(int, sys.stdin.read().split())
    X = 19
    N, Q = next(it), next(it)
    X = Q.bit_length()
    b1, br, bc = (1 << X)-1, 2*X+1, 1<<X

    if Q == 3:
        raise 1

    Aa = [next(it)-1 for i in range(N)]
    Aq = [0] * Q
    Ac = [0] * Q
    for i in range(Q):
        l, r = next(it), next(it)
        Aq[i] = r<<X | i
        Ac[i] = l

    Aq.sort()
    dp = [1] * N
    N1 = N+1
    bit = [0] * N1

    ans = [0] * Q
    offset = 0
    for arg in Aq:
        r = arg >> X
        i = arg & b1

        for j in range(offset, r):
            ci = Aa[j]
            j += 2

            j0 = dp[ci]
            #bit_add2(bit, j0, j, N1, 1)
            bit_add(bit, j0, N1, 1)
            bit_add(bit, j, N1, -1)

            dp[ci] = j

        offset = r
        l = Ac[i]

        ans[i] = bit_sum(bit, l)

    print(*ans, sep="\n")


if __name__ == "__main__":
    resolve()


### FIXED CODE ###

#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    X = 19
    N, Q = next(it), next(it)
    X = Q.bit_length()
    b1, br, bc = (1 << X)-1, 2*X+1, 1<<X

    Aa = [next(it)-1 for i in range(N)]
    Aq = [0] * Q
    Ac = [0] * Q
    for i in range(Q):
        l, r = next(it)-1, next(it)-1
        Aq[i] = r<<X | i
        Ac[i] = l

    Aq.sort()
    dp = [0] * N

    N1 = (2*N+1)//2
    dp2 = [0] * (N1*2)

    ans = [0] * Q
    offset = 0
    for arg in Aq:
        r = arg >> X
        i = arg & b1

        for j in range(offset, r+1):
            ci = Aa[j]

            lo = N1 + dp[ci]
            hi = N1 + j

            while lo < hi:
                if lo & 1:
                    dp2[lo] += 1
                    lo += 1
                if not hi & 1:
                    dp2[hi] += 1
                    hi -= 1
                lo >>= 1; hi >>= 1;

            if lo == hi: dp2[lo] += 1

            dp[ci] = j + 1
        offset = r+1
        l = Ac[i]

        num = 0
        j = l + N1
        while j > 0:
            num += dp2[j]
            j >>= 1
        ans[i] = num

    print(*ans, sep="\n")


if __name__ == "__main__":
    resolve()
n, m = map(int, input().split())
a = [[] for i in range(n)]
for i in range(m):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    a[l].append((r, d))
    a[r].append((l, -d))

bio = [None for i in range(n)]
def dfs(x):
    for y, d in a[x]:
        if bio[y] is None:
            bio[y] = bio[x] + d
            if not dfs(y):
                return False
        elif bio[y] != bio[x] + d:
            return False
    return True

for i in range(n):
    if bio[i] is None:
        bio[i] = 0
        if not dfs(i):
            print('No')
            exit(0)
print('Yes')


### FIXED CODE ###

import sys
sys.setrecursionlimit(200002)

n, m = map(int, input().split())
a = [[] for i in range(n)]
for i in range(m):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    a[l].append((r, d))
    a[r].append((l, -d))

bio = [None for i in range(n)]
def dfs(x):
    for y, d in a[x]:
        if bio[y] is None:
            bio[y] = bio[x] + d
            if not dfs(y):
                return False
        elif bio[y] != bio[x] + d:
            return False
    return True

for i in range(n):
    if bio[i] is None:
        bio[i] = 0
        if not dfs(i):
            print('No')
            exit(0)
print('Yes')
def number(c):
    c = str(c)
    ans = 0
    s = "0123456789"
    for i in range(10):
        if c == s[i]:ans = 1
    return ans

A,B = map(int,input().split())
S = input()
flag = 1
for i in range(A):
    if(number(S[i]) != 1):flag = 0
if S[A] != "-":flag = 0
for j in range(B):
    if(number(S[A+1+i]) != 1):flag = 0
if flag:print("Yes")
else:print("No")


### FIXED CODE ###

def number(c):
    c = str(c)
    ans = 0
    s = "0123456789"
    for i in range(10):
        if c == s[i]:ans = 1
    return ans

A,B = map(int,input().split())
S = input()
flag = 1
for i in range(A):
    if(number(S[i]) != 1):flag = 0
if S[A] != "-":flag = 0
for j in range(B):
    if(number(S[A+1+j]) != 1):flag = 0
if flag:print("Yes")
else:print("No")
a, b, k = map(int, input().split())
if a >= k:
    a -= k
elif a < k and a + b >= k:
    b = b - (k-a)
    a = 0
else:
    a = 0
    b = 0
print(a, b)

### FIXED CODE ###

s, t = input().split()
print(t+s)
A,B = map(int,input().split())

AA = A*100//8
AF = (A+1)*100//8 + 1 if (A+1)*100%8!=0 else (A+1)*100//8
BB = B*10
AAA = [i for i in range(AA,AF]
BBB = [i for i in range(BB,(B+1)*10)]
AB_list = list(set(AAA)&set(BBB))

ans = min(AB_list) if AB_list and (12<min(AB_list)<=1000) else -1
print(ans)

### FIXED CODE ###

A,B = map(int,input().split())

AA = A*100//8 + 1 if A*100%8!=0 else A*100//8
AF = (A+1)*100//8 + 1 if (A+1)*100%8!=0 else (A+1)*100//8
BB = B*10
AAA = [i for i in range(AA,AF)]
BBB = [i for i in range(BB,(B+1)*10)]
AB_list = list(set(AAA)&set(BBB))

ans = min(AB_list) if AB_list and (12<min(AB_list)<=1000) else -1
print(ans)
count = input()
numbers = [int(num) for num in input().split()]

counter = 0
while True:
  tmp = 0
  for item in numbers:
    tmp += item % 2
  if tmp > 0:
    break
  counter ++
  numbers = [item / 2 for item in numbers]
print(counter)

### FIXED CODE ###

count = int(input())
numbers = [int(num) for num in input().split()]

counter = 0
while True:
  tmp = 0
  for item in numbers:
    tmp += item % 2
  if tmp > 0:
    break
  counter += 1
  numbers = [item / 2 for item in numbers]
print(counter)
hpi = input()
k = list(map(int, input().split(" ")))
for c in range(int(hpi) - 1):
  jo = "yes"
  n = k[:c + 2]
  for co in range(len(n) - 1):
    if n[co] > k[c]:
      jo = "no"
    else:
      pass
  if jo == "yes":
    count += 1
print(count + 1)

### FIXED CODE ###

hpi = input()
count = 1
k = list(map(int, input().split(" ")))
for c in range(int(hpi) - 1):
  jo = "yes"
  n = k[:c + 2]
  for co in range(len(n) - 1):
    if n[co] > k[c + 1]:
      jo = "no"
    else:
      pass
  if jo == "yes":
    count += 1
print(count)
n = input()
h = [int(i) for i in input().sprit()]

max = 0
y = 1
for i in range(n):
    if h[i] > max:
        max = h[i]
    else if h[i] < max-1:
        y = 0
        break
    
if y:
    print("yes")
else:
    print("no")


### FIXED CODE ###

n = input()
h = [int(i) for i in input().split()]

max = 0
i = 0
y = 1
for i in range(int(n)):
    if h[i] > max:
        max = h[i]
    elif h[i] < max-1:
        y = 0
    
if y==1:
    print("Yes")
else:
    print("No")
flag=0
i=0
while flag==0:
    num=input()
    if num==0 or num=="":
        flag=1
    else:
        print("Case {0}: {1}".format(i + 1, num))
        i = i + 1
        num = int(input())

### FIXED CODE ###

flag=0
i=0
while flag==0:
    num=int(input())
    if num==0:
        flag=1
    else:
        print("Case {0}: {1}".format(i + 1, num))
        i = i + 1
n = int(input())
aa = [int(i) for i in input().split()]
e = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = [int(i) - 1 for i in input().split()]
    e[a].append(b)
    e[b].append(a)

dp = [10 ** 18] * (n + 10)
dp[0] = 0
ans1 = [0] * n
ans2 = [0] * n


def dfs(i=0, r=-1):
    mi = 0
    ma = n
    while mi != ma:
        mm = (mi + ma) // 2
        if dp[mm] >= aa[i]:
            ma = mm
        else:
            mi = mm + 1

    be = dp[mi]
    dp[mi] = min(dp[mi], aa[i])
    ans1[i] = mi
    ans2[i] = max(ans1[i], ans2[r])

    for j in e[i]:
        if j == r:
            continue
        dfs(j, i)

    dp[mi] = be


dfs()
for i in ans2:
    print(i)


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)


def input():
    return sys.stdin.readline()


n = int(input())
aa = {}
for j,i in enumerate(map(int,input().split())):
    if i in aa:
        aa[i].append(j)
    else:
        aa[i] = [j]
a = [0] * n
for k,i in enumerate(sorted(list(aa))):
    for j in aa[i]:
        a[j] = k+1


class SegmentTree:
    def __init__(self, a, func=max, one=-10 ** 18):
        self.logn = (len(a) - 1).bit_length()
        self.n = 1 << self.logn
        self.func = func
        self.one = one

        self.b = [self.one] * (2 * self.n - 1)
        for i, j in enumerate(a):
            self.b[i + self.n - 1] = j
        for i in reversed(range(self.n - 1)):
            self.b[i] = self.func(self.b[i * 2 + 1], self.b[i * 2 + 2])

    def get_item(self, i):
        return self.b[i + self.n - 1]

    def update(self, index, x):
        i = index + self.n - 1
        self.b[i] = x
        while i != 0:
            i = (i - 1) // 2
            self.b[i] = self.func(self.b[i * 2 + 1], self.b[i * 2 + 2])

    def update_func(self, index, x):
        i = index + self.n - 1
        self.b[i] = self.func(self.b[i], x)
        while i != 0:
            i = (i - 1) // 2
            self.b[i] = self.func(self.b[i * 2 + 1], self.b[i * 2 + 2])

    def get_segment(self, l, r):
        l += self.n
        r += self.n
        s = self.one
        while l < r:
            if r & 1:
                r -= 1
                s = self.func(s, self.b[r - 1])
            if l & 1:
                s = self.func(s, self.b[r - 1])
                l += 1
            l >>= 1
            r >>= 1
        return s


e = [[] for _ in range(n)]
for _ in range(n - 1):
    aa, bb = [int(i) - 1 for i in input().split()]
    e[aa].append(bb)
    e[bb].append(aa)
seg = SegmentTree([0] * (max(a)+2), max, 0)
ans1 = [0] * n
ans1[0] = 1
ans2 = [0] * n
ans2[0] = 1


def dfs(i=0, r=-1):

    y = seg.get_segment(0, a[i])
    ans1[i] = y + 1
    ans2[i] = max(ans2[r], ans1[i])

    be = seg.get_item(a[i])
    seg.update_func(a[i], ans1[i])
    for j in e[i]:
        if j == r:
            continue
        dfs(j, i)
    seg.update(a[i], be)


dfs()
print("\n".join(map(str,(ans2))))
a, b, c, k = map(int, input().split())
if(k < a):
    pritn(k)
elif(a <= k <= a + b):
    print(a)
else:
    print(a - (k - (a + b)))


### FIXED CODE ###

a, b, c, k = map(int, input().split())
if(k < a):
    print(k)
elif(k <= a + b):
    print(a)
else:
    print(a - (k - (a + b)))
import sys
 
H,W,M = list(map(int, input().split()))
 
hw = [[0] * (W+30) for _ in range(H+30)]
 
w = [0] * (W+1)
h = [0] * (H+1)
mxw = []
mxw_v = 0
mxh = []
mxh_v = 0
 
 
for i in range(M):
    h_i, w_j = list(map(int, input().split()))
    hw[h_i][w_j] = 1
    h[h_i] += 1
    w[w_j] += 1
    if mxw_v < w[w_j]:
        mxw_v = w[w_j]
        mxw = [w_j]
    elif mxw_v == w[w_j]:
        mxw.append(w_j)
 
    if mxh_v < h[h_i]:
        mxh_v = h[h_i]
        mxh = [h_i]
    elif mxh_v == h[h_i]:
        mxh.append(h_i)

a = 0
for i in mxh:
    for j in mxw:
        d = hw[i][j]
        a = max(a, h[i]+w[j]-d)
print(a)

### FIXED CODE ###

H,W,M = list(map(int, input().split()))

hw = set()
w = [0] * 3*10**5
h = [0] * 3*10**5

for i in range(M):
    h_i, w_j = map(int, input().split())
    hw.add((h_i-1) + (w_j-1)*3*10**6)
    h[h_i-1] += 1
    w[w_j-1] += 1

a = 0
d = 1
mxh_v = max(h)
mxw_v = max(w)

x = [i for i,j in enumerate(h) if j == mxh_v]
y = [i for i,j in enumerate(w) if j == mxw_v]

for i in x:
    for j in y:
        if not(i + j*3*10**6 in hw):
            print(mxh_v+mxw_v)
            exit()
print(mxh_v+mxw_v-d)
N=int(input())
A=list(map(int,input().split()))

L=0
C=[]
for i in range(N):
    C.append(A.count(i))
    L+=int(C[i]*(C[i]-1)/2)
    
for i in range(N):
    print(L-C[A[i]]+1)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))

L=0
C=[0]*N

for i in range(N):
    C[A[i]-1]+=1

for i in range(N):
    L+=int(C[i]*(C[i]-1)/2)
    
for i in A:
    print(L-C[i-1]+1)
import math
def GCD(LIST):
	if len(LIST)==2:
		return math.gcd(LIST[0],LIST[1])
	else:
		return GCD([math.gcd(LIST[0],LIST[1])]+LIST[2::])

N,X=map(int,input().split())
x=list(map(int,input().split()))
L=x+[X]
if N==1:
	print(abs(X-x[0]))
else:
	LL=[abs(L[i+1]-L[i]) for i in range(N)]
	print(GCD(LL))


### FIXED CODE ###

from functools import reduce
N,X=map(int,input().split())
x=list(map(int,input().split()))
L=x+[X]
if N==1:
	print(abs(X-x[0]))
else:
	LL=[abs(L[i+1]-L[i]) for i in range(N)]
	def gcd(a,b):
		while b>0:
			a,b=b,a%b
		return a
	print(reduce(gcd,LL))
from collections import defaultdict
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

changes = defaultdict(int)
for i in range(M):
    b, c = map(int, input().split())
    changes[c] += b

changes = sorted(changes.items(), key = lambda x:x[0], reverse=True)

d = []
len_d = 0
for v in changes:
    d += [v[0]]*v[1]
    len_d += v[1]
    if len_d >= N:
        d = d[0:N]
        break

res = 0
i = 0
while i < min(len(d), N):
    if A[i] <= d[i]:
        res += d[i]
    else:
        res += A[i]
    i += 1

if i < N:
    for j in range(i, N):
        res += A[j]

print(res)


### FIXED CODE ###

from collections import defaultdict
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [(A[i], 1) for i in range(N)]

changes = [None] * M
for i in range(M):
    b, c = map(int, input().split())
    changes[i] = (c, b)

allVals = A + changes

allVals.sort(key = lambda x:x[0], reverse = True)
# print(allVals)

i = 0
j = -1
res = 0
while True:
    j += 1
    res += allVals[j][0] * allVals[j][1]
    i += allVals[j][1]

    if i >= N:
        res -= allVals[j][0] * (i - N)
        break



print(res)
N = int(input())
L = list(map(int,input().split()))
 
L.sort()
 
target_num = int(N/2)
if L[target_num-1] = L[target_num]:
	ans = 0
else:
  	ans= L[target_num]-L[target_num-1]

print(ans)


### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))

l.sort()
print(l[int(n/2)]-l[int(n/2)-1])
a,b = input().split()
if (a%2==0) | (b%2==0):
  print("Even")
else:
  print("Odd")

### FIXED CODE ###

a,b = map(int, input().split())
if (a%2==0) | (b%2==0):
  print("Even")
else:
  print("Odd")
if __name__=="__main__":
    [s] = map(int,input().split())
    if(s < 1200):
	print("ABC")
    else:
        print("ARC")

### FIXED CODE ###

if __name__=="__main__":
    s = int(input())
    if(s < 1200):
        print("ABC")
    else:
        print("ARC")
n=input()
mk=input().split()
m=[]
t=0
s=0
for k in mk:
  pk=int(k)
  t+=pk
  s+=(pk**2)
  m.append(pk)
px=round(t/n)
ans=s+n*(px**2)-2*px*t
print(ans)

### FIXED CODE ###

n=int(input())
mk=input().split()
t=0
s=0
ans=0
for k in mk:
  pk=int(k)
  t+=pk
  s+=(pk**2)
px=round(t/n)
ans+=s+n*(px**2)-2*px*t
print(ans)
import math 
while 1 :
	e = int(raw_input())
	if e == 0:
		break
	z = 0
	m = e
	while math.pow(z,3) <= e:
		y = 0
		while y ** 2 <= e - math.pow(z,3):
			m = min(e + y + z - y**2 - math.pow(z,3), m)
			y += 1
		z += 1
	print int(m)
quit()

### FIXED CODE ###

from math import sqrt
while 1 :
	e = int(raw_input())
	if e == 0:
		break
	z = 0
	m = float("inf")
	while z ** 3 <= e:
		y = int(sqrt(e - z**3))
		m = min(m, e  - y**2 - z**3 + y + z)
		z += 1
	print int(m)
n, m = map(int, input().split())
a = m // n

for i in range(2, a + 1):
    if m % i == 0:
        ans = i
        
print(ans)

### FIXED CODE ###

n, m = map(int, input().split())
a = m // n
ans = 0

for i in range(1, a + 1):
    if m % i == 0:
        ans = i
        
        if (m // i) > i and (m // i) <= a:
            ans = m // i
            break
        
print(ans)
n = int(input())
h = [int(i) for i in input().split()]
ans = []
i = 0
while i < n-1:
    count_min = 0
    while i<n-1 and h[i]<h[i+1]:
        i += 1
    while i<n-1 and h[i]>=h[i+1]:
        count_min += 1
        i += 1
    ans.append(count_min)
print(max(ans))

### FIXED CODE ###

n = int(input())
h = [int(i) for i in input().split()]
ans = []
i = 0
if n ==1:
    ans.append(0)
else:
    while i < n-1:
        count_min = 0
        while i<n-1 and h[i]<h[i+1]:
            i += 1
        while i<n-1 and h[i]>=h[i+1]:
            count_min += 1
            i += 1 
        ans.append(count_min)
print(max(ans))
import math
N=int(input())
A=list(map(int,input().strip().split(' ')))
if N==1:
    print(A[0])
else:    




    GG=[0]*N
    GG[0]=A[0]
    for i in range(1,N):
        GG[i]=math.gcd(GG[i-1],A[i])

    GG2=[0]*N
    GG2[-1]=A[-1]

    for i in range(2,N+1):
        GG2[-i]=math.gcd(GG2[-(i-1)],A[-i])

    ans=[0]*N

    ans[0]=GG2[1]
    ans[-1]=GG[N-1]
    #print(GG)
    #print(GG2)

    for i in range(1,N-1):
        ans[i]=math.gcd(GG[i-1],GG2[i+1])
    #print(ans)  
    print(max(ans))    

### FIXED CODE ###

N=int(input())
A=list(map(int,input().strip().split(' ')))

def gcd(x, y): 
  
   while(y): 
       x, y = y, x % y 
  
   return x 
  

GG=[0]*N
GG[0]=A[0]
for i in range(1,N):
    GG[i]=gcd(GG[i-1],A[i])

GG2=[0]*N
GG2[-1]=A[-1]

for i in range(2,N+1):
    GG2[-i]=gcd(GG2[-(i-1)],A[-i])

ans=[0]*N

ans[0]=GG2[1]
ans[-1]=GG[N-2]
#print(GG)
#print(GG2)
#print(ans)


temp=ans[0]
for i in range(1,N-1):
    ans[i]=gcd(GG[i-1],GG2[i+1])
    if ans[i]>temp:
        temp=ans[i]
if ans[-1]>temp:
    temp=ans[-1]


print(temp)
n=int(input())
A=sorted((map(int,input().split())))
G=sorted([2*(i+1) for i in range(n//2)]*2+[0])
K=sorted([(2*i+1) for i in range(n//2)]*2)
if n%2:
	if A!=G:
		print(0)
		exit()
else:
	if A!=K:
		print(0)
		exit()
print(2**(n//2)%(10**9+7)

### FIXED CODE ###

n=int(input())
A=sorted((map(int,input().split())))
G=sorted([2*(i+1) for i in range(n//2)]*2+[0])
K=sorted([(2*i+1) for i in range(n//2)]*2)
if n%2:
	if A!=G:
		print(0)
		exit()
else:
	if A!=K:
		print(0)
		exit()
print(2**(n//2)%(10**9+7))
a, b = map(int, input().split())

if a > b:
    print('GREATER')
elif b > a:
    print('LESS')
else:
    print('EQUAL')

### FIXED CODE ###

a = int(input())
b = int(input())

if a > b:
    print('GREATER')
elif b > a:
    print('LESS')
else:
    print('EQUAL')
N, M = map(int, input().split())
A = list(map(int, input().split()))

import numpy as np
Cumsum = np.cumsum(A)
counter = 0
for l in range(0, N):
    for r in range(l, N):
        if l == r:
            if A[l] % M == 0:
                counter += 1
        elif l != r and l == 0:
            if Cumsum[r] % M == 0:
                counter += 1
        elif l != r and l >= 1:
            if (Cumsum[r] - Cumsum[l-1]) % M == 0:
                counter += 1


print(counter)

### FIXED CODE ###

from collections import defaultdict
N, M = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
hash = defaultdict(int)
hash[0] = 1
i = 0
for a in A:
    i = (i+a) % M
    hash[i] += 1
for h in list(hash.keys()):
    ans += hash[h] * (hash[h]-1) // 2

print(ans)
n,*s=map(int,open(0).read().split());s,t,f,g=[s[i*n:i*n+n]for i in range(4)];r=range(n);a=[n*[0]for _ in r]
e=enumerate
for b in range(64):
 y=1<<b;u=[k&y for k in f];v=[k&y for k in g];l=[0]*n;m=l[:]
 for i,k in e(u):
  for j,l in e(v):
   if(k&l)|((s[i]^1)*k)|((t[j]^1)*l):a[i][j]|=y;l[i]+=1;m[j]+=1
 for i in r:
  if(l[i]==0)*s[i]*u[i]:
   for j in r:
    if(t[j]^1)*(n-m[j]>1):a[i][j]|=y;m[j]+=1;break
  if(m[i]==0)*t[i]*v[i]:
   for j in r:
    if(s[j]^1)*(n-l[j]>1):a[j][i]|=y;l[j]+=1;break
h=a[0][:];w=[i[0]for i in a]
for i,k in e(a):
 for j,l in e(k):w[i]=(l|w[i]if s[i]else w[i]&l);h[j]=(l|h[j]if t[j]else h[j]&l)
if(g!=h)|(f!=w):print(-1);exit() 
for i in a:print(*i)

### FIXED CODE ###

n=int(input())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
u=list(map(int,input().split()))
v=list(map(int,input().split()))
ans=[n*[0]for _ in range(n)]
ss=[u[i]if s[i]==0 else 0 for i in range(n)]
tt=[v[i]if t[i]==0 else 0 for i in range(n)]
son=[[]for _ in range(n)]
ton=[[]for _ in range(n)]
sno=[[n-1]*64 for _ in range(n)]
tno=[[n-1]*64 for _ in range(n)]
for i in range(n):
  for j in range(n):
    ans[i][j]=u[i]&v[j]
    if s[i]==0:
      ans[i][j]|=u[i]
      ss[i]&=ans[i][j]
    else:
      ss[i]|=ans[i][j]
    if t[j]==0:
      ans[i][j]|=v[j]
      tt[j]&=ans[i][j]
    else:
      tt[j]|=ans[i][j]
    if s[i]==0 or t[i]==0:
      for k in range(64):
        if ans[i][j]&1<<k:
          if s[i]==0:sno[i][k]-=1
          if t[j]==0:tno[j][k]-=1
    if j==n-1:
      if s[i]==1:
        if ss[i]|u[i]>u[i]:print(-1);exit()
        if ss[i]!=u[i]:
          for k in range(64):
            if u[i]&1<<k:
              if (ss[i]&1<<k)==0:
                son[i].append(k)
          ss[i]=1
        else:ss[i]=0
      else:
        if ss[i]!=u[i]:print(-1);exit()
        else:ss[i]=2
    if i==n-1:
      if t[j]==1:
        if tt[j]|v[j]>v[j]:print(-1);exit()
        if tt[j]!=v[j]:
          for k in range(64):
            if v[j]&1<<k:
              if (tt[j]&1<<k)==0:
                ton[j].append(k)
          tt[j]=1
        else:tt[j]=0
      else:
        if tt[j]!=v[j]:print(-1);exit()
        else:tt[j]=2
for i in range(n):
  for k in son[i]:
    for j in range(n):
      if t[j]==0:
        if tno[j][k]>0:
          ans[i][j]|=1<<k
          tno[j][k]-=1
          break
      if j==n-1:print(-1);exit()
for j in range(n):
  for k in ton[j]:
    for i in range(n):
      if s[i]==0:
        if sno[i][k]>0:
          ans[i][j]|=1<<k
          sno[i][k]-=1
          break
      if i==n-1:print(-1);exit()
for i in range(n):
  if s[i]==0:uu=ans[i][0]
  else:uu=0
  for j in range(n):
    if s[i]==0:uu&=ans[i][j]
    else:uu|=ans[i][j]
  if uu!=u[i]:print(-1);exit()
for j in range(n):
  if t[j]==0:vv=ans[0][j]
  else:vv=0
  for i in range(n):
    if t[j]==0:vv&=ans[i][j]
    else:vv|=ans[i][j]
  if vv!=v[j]:print(-1);exit()
for i in ans:print(*i)
k=["MON","TUE","WED","THU","FRI","SAT"]
s=input()
j="SUN"
if(s==j):
  print(7)
else:
  for a,i in enumerate k:
    if(s==i):
      print(6-a)

### FIXED CODE ###

k=["MON","TUE","WED","THU","FRI","SAT"]
s=input()
j="SUN"
if(s==j):
  print(7)
else:
  for a,i in enumerate (k):
    if(s==i):
      print(6-a)