Harryxun/stf_run huggingface dataset:
def main():
    A = [list(map(int, input().split())) for i in range(3)]
    N = int(input())
    b = [int(input()) for i in range(N)]
    
    for i in range(3):
        for j in range(3):
            for k in range(N):
                if (A[i][j] == b(k)):
                    A[i][j] = 0
    
    ans = "No"
    for i in range(3):
        if A[i][0]+A[i][1]+A[i][2]==0:
            ans = "Yes"
        if A[0][i]+A[1][i]+A[2][i]==0:
            ans = "Yes"
    if A[0][0]+A[1][1]+A[2][2]==0:
        ans = "Yes"
    if A[0][2]+A[1][1]+A[2][0]==0:
        ans = "Yes"
    print(ans)
main()

### FIXED CODE ###

def main():
    A = [list(map(int, input().split())) for i in range(3)]
    N = int(input())
    b = [int(input()) for i in range(N)]
    
    for i in range(3):
        for j in range(3):
            for k in range(N):
                if A[i][j] == b[k]:
                    A[i][j] = 0
    
    ans = "No"
    for i in range(3):
        if A[i][0]+A[i][1]+A[i][2]==0:
            ans = "Yes"
        if A[0][i]+A[1][i]+A[2][i]==0:
            ans = "Yes"
    if A[0][0]+A[1][1]+A[2][2]==0:
        ans = "Yes"
    if A[0][2]+A[1][1]+A[2][0]==0:
        ans = "Yes"
    print(ans)
main()
# coding: utf-8

def selectionSort(A, N):
	count = 0
	for i in xrange(N):
		minj = i
		for j in xrange(i, N):
			if A[j] < A[minj]:
				minj = j
		if minj != i:
			A[i], A[minj] = A[minj], A[i]
			count += 1
	return count

def main():
	N = input()
	A = map(int, raw_input().split())
	print selectionSort(A, 6)
	print ' '.join(map(str, A))

if __name__ == '__main__':
	main()

### FIXED CODE ###

# coding: utf-8

def selectionSort(A, N):
	A = A[:]
	count = 0
	for i in xrange(N):
		minj = i
		for j in xrange(i, N):
			if A[j] < A[minj]:
				minj = j
		if minj != i:
			A[i], A[minj] = A[minj], A[i]
			count += 1
	return A, count

def main():
	N = input()
	A = map(int, raw_input().split())
	sorted_, count = selectionSort(A, N)
	print ' '.join(map(str, sorted_))
	print count

if __name__ == '__main__':
	main()
import math
import bisect
import heapq
from collections import deque

n, m = map(int, input().split())

a = list(map(int, input().split()))


def lcm(x, y):
    return x * y // math.gcd(x, y)


def scm(a):
    for i in range(n):
        if a[i] % 2 == 1:
            return 0
    l = 1
    for i in range(n):
        a[i] = a[i] // 2
        l = lcm(l,a[i])

    count = 0
    lc = l
    if not 1 <= l <= m:
        return 0

    for i in range(l, m+1, 2*lc):
        count += 1

    return count

print(scm(a))



### FIXED CODE ###

from fractions import gcd
n, m = map(int, input().split())

a = list(map(int, input().split()))

ans = -1
b = [0] * n
for i in range(n):
    if a[i] % 2 != 0:
        ans = 0
        break

    else:
        b[i] = a[i] // 2


    if i == 0:
        num = format(a[i], 'b')[::-1].find('1')

    else:
        if format(a[i], 'b')[::-1].find('1') != num:
            ans = 0
            break
        else:
            num = format(a[i], 'b')[::-1].find('1')


if ans != 0:
    g = b[0]
    for i in range(1,n):

        g = (g*b[i]) // gcd(b[i],g)

    if g > m: ans = 0
    else:
        ans = (1 + (m-g)//(2*g))

print(ans)
n,d=map(int,input().split())
count=0
for i in range(n):
  x[i],y[i] = map(int, input().split())
  if x[i]**2+y[i]**2<=d**2:
   count=+1
print(count)

### FIXED CODE ###

import math
 
n,d=map(int,input().split())
count=0
for i in range(n):
  x,y = map(int, input().split())
  if math.sqrt((x**2)+(y**2))<=d:
   count+=1
print(count)
N, M = map(int, input().split())
L = []*M
R = []*M
for i in range(M):
  L[i], R[i] = map(int, input().split())
  
ans = min(R)-(max(L)-1)

print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
L = [0 for i in range(M)]
R = [0 for i in range(M)]
for i in range(M):
  L[i], R[i] = map(int, input().split())
  
ans = min(R)-(max(L)-1)

print(max(ans,0))
#f = open("input.txt")
#N, K = [int(x) for x in f.readline().split(' ')]
#lines = f.readlines()

import sys
N, K = [int(x) for x in sys.stdin.readline().split(' ')]
lines = sys.stdin.readlines()
f.close()

schedule = [0]*N
for line in lines:
    strs = line.split(' ')
    schedule[int(strs[0])-1] = int(strs[1])

number = [0]*9
for i in range(9):
    l1 = i // 3
    l2 = i % 3
    if(schedule[0]!=l1+1 and schedule[0]!=0):
        number[i] = 0
    elif(schedule[1]!=l2+1 and schedule[1]!=0):
        number[i] = 0
    else:
        number[i] = 1


for s in schedule[2:]:
    new_number = [0]*9
    for i in range(9):
        l1 = i // 3
        l2 = i % 3
        for j in range(3):
            new_number[i] += number[l2*3 + j] if((s==0 or s==l1+1) and  not (l2==j and l1==j)) else 0
    for i in range(9):
        number[i] = new_number[i] % 10000
      
sum = 0
for n in number:
    sum += n
print(sum % 10000)

### FIXED CODE ###

#f = open("input.txt")
#N, K = [int(x) for x in f.readline().split(' ')]
#lines = f.readlines()
#f.close()
from sys import stdin
N, K = [int(x) for x in stdin.readline().split(' ')]
lines = stdin.readlines()

schedule = [0]*N
for line in lines:
    strs = line.split(' ')
    schedule[int(strs[0])-1] = int(strs[1])

number = [1]*9
for i in range(9):
    (l1,l2) = divmod(i,3)
    if   schedule[0]!=l2+1 and schedule[0]!=0:
        number[i] = 0
    elif schedule[1]!=l1+1 and schedule[1]!=0:
        number[i] = 0

for s in schedule[2:]:
    tmp = [0]*9
    for i in range(9):
        (l1,l2) = divmod(i,3)
       	tmp[i] = [number[l2*3+j] for j in range(3) \
                 if (s==0 or s==l1+1) and  not (l2==j and l1==j)]
    number = [sum(tmp_i) for tmp_i in tmp]
print(sum(number) % 10000)
N = int(input())
happy = []
result = [[0 for i in range(3)] for j in range(N)]

for i in range(3):
    t = list( map( int, input().split() ) )
    happy.append(t)

for i in range(3):
    result[0][i] = happy[0][i] 

for i in range(1,N):
    for j in range(3):
        result[i][j] = max( [ result[i-1][k] + happy[i][j] for k in range(3) if k != j ] )

print( max( result[N-1] ) )

### FIXED CODE ###

N = int(input())
happy = []
result = [[0 for i in range(3)] for j in range(N)]

for i in range(N):
    t = list( map( int, input().split() ) )
    happy.append(t)

for i in range(3):
    result[0][i] = happy[0][i] 

for i in range(1,N):
    for j in range(3):
        result[i][j] = max( [ result[i-1][k] + happy[i][j] for k in range(3) if k != j ] )

print( max( result[N-1] ) )
N, M = [int(i) for i in input().split()]
s = [0] * M
c = [0] * M
for i in range(N):
  s[i], c[i] = map(int, input().split())

ans = 1000
for i in range(1000):
  S = str(i)
  if len(S) != N:
    continue
  
  is_ok = True
  for j in range(M):
    if S[s[j]] != c[j]:
      is_ok = False
      
  if is_ok:
    ans = min(ans, i)

if ans == 1000:
  print(-1)
else:
  print(ans)


### FIXED CODE ###

N, M = [int(i) for i in input().split()]
s = [0] * M
c = [0] * M
for i in range(M):
  s[i], c[i] = map(int, input().split())

ans = 1000
for i in range(1000):
  S = str(i)
  if len(S) != N:
    continue
  
  is_ok = True
  for j in range(M):
    if S[s[j]-1] != str(c[j]):
      is_ok = False
      
  if is_ok:
    ans = min(ans, i)

if ans == 1000:
  print(-1)
else:
  print(ans)
A = int(input())

B = int(input())

if A<=9 and B<=9:
	print(A*B)
else:
	print(-1)

### FIXED CODE ###

a,b=map(int,input().split())
 
if a<=9 and b <=9:
  print(a*b)
else:
  print(-1)
INPUT = list(map(int, input().split()))
processes = [input() for _ in range(INPUT[0])]
for i in range(INPUT[0]):
    processes[i].split()
head, tail, n, quantum = 0, len(processes), INPUT[0], INPUT[1]


def enqueue(x):
    global processes, tail
    processes.append(0)
    processes[tail] = x
    tail += 1


def dequeue():
    global head
    head += 1


for i in range(n):
    int(processes[i][1])

time, count = 0, 0
while count < n:
    y = processes[head][1] - quantum
    if y < 0:
        print(str(processes[head][0]) + " " + str(time + processes[head][1]))
        dequeue()
        time += y
        count += 1
    else:
        processes[head][1] -= quantum
        enqueue(processes[head])
        dequeue()

    time += quantum



### FIXED CODE ###

def parse(l):
    name, time = l.split()
    a = [name, int(time)]
    return a


n, quantum = map(int, input().split())
queue = []
for i in range(n):
    queue.append(parse(input()))
head = 0


def enqueue(x):
    global queue
    queue.append(x)


def dequeue():
    global head
    head += 1


total_time, count = 0, 0
while count < n:
    y = queue[head][1] - quantum
    if y <= 0:
        print(str(queue[head][0]) + " " + str(total_time + queue[head][1]))
        dequeue()
        total_time += y
        count += 1
    else:
        queue[head][1] -= quantum
        enqueue(queue[head])
        dequeue()

    total_time += quantum
# -*- coding: utf-8 -*-
def main():
    S = list(input())
    state = 0
    CNT = 0
    while(state != 1):
    # for x in range(50):
        first_W = 0
        for i in range(len(S)):
            if state == 0:
                if S[i] == 'B':
                    B_cnt = 1
                    state = 1
                else:
                    first_W += 1
            elif state == 1:
                if S[i] == 'B':
                    B_cnt += 1
                else:
                    W_cnt = 1
                    state = 2
            elif state == 2:
                if S[i] == 'W':
                    W_cnt += 1
                else:
                    state = 0
                    break
        # print(state)
        if state == 2:
            state = 0
            S = ['W']*(W_cnt+first_W) + ['B']*B_cnt
        else:
            CNT += W_cnt*B_cnt
            S = ['W']*(W_cnt+first_W) + ['B']*B_cnt + S[i:]
        # print(S)
    print(CNT)
        
if __name__ == '__main__':
    main()

    # S = list(input())
    # check = 0
    # cnt = 0
    # i = 0
    # while(check == 0) :
    #     check = 1
    #     for i in range(len(S)-1):
    #         if S[i] == 'B' and S[i+1] == 'W':
    #             S[i], S[i+1] = 'W', 'B'
    #             cnt += 1
    #             check = 0
    #             break
    # print(cnt)

### FIXED CODE ###

# -*- coding: utf-8 -*-
def main():
    S = list(input())
    Bcnt = 0
    ans = 0
    for i in range(len(S)):
        if S[i] == 'B':
            Bcnt += 1
        else:
            ans += Bcnt
    print(ans)
if __name__ == '__main__':
    main()
s = input()
str_list = ["eraser","erase","dreamer","dream"]
for e in str_list:
    s = s.replace(e)
ans = "YES" if s == "" else "NO"
print(ans)

### FIXED CODE ###

s = input()
str_list = ["dream","dreamer","erase","eraser"]
for i in range(len(s) // 5):
    if s[-7:] == "dreamer":
        s = s[:-7]
    elif s[-6:] == "eraser":
        s = s[:-6]
    elif s[-5:] == "dream" or s[-5:] == "erase":
        s = s[:-5]
ans = "YES" if s == "" else "NO"
print(ans)
x,y = map(int,input().split())
li = list(map(int,input().split()))
from collections import deque
l = []
for i in range(len(li)):
    l.append((1+ li[i])/2)
from itertools import accumulate
a = list(accumulate(l))
M = a[y-1]
for i range(len(a)-y):
    m = a[i+y] - a[i]
    if m > M:
        M = m
print(M)

### FIXED CODE ###

x,y = map(int,input().split())
li = list(map(int,input().split()))
from collections import deque
l = []
for i in range(len(li)):
    l.append((1+ li[i])/2)
from itertools import accumulate
a = list(accumulate(l))
M = a[y-1]
for i in range(len(a)-y):
    m = a[i+y] - a[i]
    if m > M:
        M = m
print(M)
import math
from functools import reduce
n = int(input())
arr = list(map(int, input().split()))

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

ans = gcd_list(arr)
print(ans)

### FIXED CODE ###

from functools import reduce
n = int(input())
arr = list(map(int, input().split()))
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def gcd_list(numbers):
    return reduce(gcd, numbers)

ans = gcd_list(arr)
print(ans)
s = input()
k = int(input())
a=1
for i in range(min(len(s),k)):
	if s[i] == '1':
		pass
	else:
		a = a[i]
		break
print(a)

### FIXED CODE ###

s = input()
k = int(input())
a=1
for i in range(min(len(s),k)):
	if s[i] == '1':
		pass
	else:
		a = s[i]
		break
print(a)
s=input()
a=s[0]
b=s[1]
c=s[2]
d=s[3]

if a+b+c+d==7:
  print('a+b+c+d=7')
elif a-b+c+d==7:
  print('a-b+c+d=7')
elif a-b-c+d==7:
  print('a-b-c+d=7')
elif a-b+c-d==7:
  print('a-b+c-d=7')
elif a-b-c-d==7:
  print('a-b-c-d=7')
elif a+b-c+d==7:
  print('a+b-c+d=7')
elif a+b-c-d==7:
  print('a+b-c-d=7')
else:
  print('a+b+c-d=7')


### FIXED CODE ###

s=str(input())
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])

if a+b+c+d==7:
  print('{}+{}+{}+{}=7'.format(a,b,c,d))
elif a-b+c+d==7:
  print('{}-{}+{}+{}=7'.format(a,b,c,d))
elif a-b-c+d==7:
  print('{}-{}-{}+{}=7'.format(a,b,c,d))
elif a-b+c-d==7:
  print('{}-{}+{}-{}=7'.format(a,b,c,d))
elif a-b-c-d==7:
  print('{}-{}-{}-{}=7'.format(a,b,c,d))
elif a+b-c+d==7:
  print('{}+{}-{}+{}=7'.format(a,b,c,d))
elif a+b-c-d==7:
  print('{}+{}-{}-{}=7'.format(a,b,c,d))
else:
  print('{}+{}+{}-{}=7'.format(a,b,c,d))
import math
n, m, r = map(int, input().split())
a = r - n * m
if a < 0:
    print(0)
else:
    b = 1
    if n - 1 > a:
        for i in range(a):
            b *= a + n - 1 - i
        for i in range(1, a + 1):
            b /= i
    else:
        for i in range(n - 1):
            b *= a + n - 1 - i
        for i in range(1, n):
            b /= i
    print(int(b))


### FIXED CODE ###

import math
n, m, r = map(int, input().split())
a = r - n * m
def combination(p, q):
    if q < 0 or p < q:
        return 0
    return math.factorial(p) // math.factorial(q) // math.factorial(p - q)
if a < 0:
    print(0)
else:
    print(int(combination(a + n - 1, a)))
A = input('A=: ')
B = input('B=: ')
if not((1<=int(A)<=100) and (1<=int(B)<=100)):
    print("1<=A,B<=100")
    A = input('A=: ')
    B = input('B=: ')

length = int(A) - 2 * int(B)
if length < 0:
    print(0)
else:
    print(length)

### FIXED CODE ###

A,B=input().split()
length = int(A) - 2 * int(B)
if length < 0:
    print(0)
else:
    print(length)
import sys

# sys.setrecursionlimit(2000)

tmp=input().split(" ")
n = int(tmp[0])
m = int(tmp[1])

node_groups = [ i for i in range(n)]
group_sizes = [ 1 for _ in range(n)]

edges = []
for i in range(m):
    tmp=input().split(" ")
    edges.append([int(tmp[0])-1, int(tmp[1])-1])

hubensa_list = [0] * (m + 1)
hubensa_list[m] = n*(n-1)//2

def root(i):
    if node_groups[i] == i:
        #print(i, "is root.")
        return i
    else:
        #_1 = node_groups[i]
        node_groups[i] = root(node_groups[i])
        #_2 = node_groups[i]
        #print ("root: ", _1, _2)
        return node_groups[i]

def same(a, b):
    return root(a) == root(b)

def size(i):
    return group_sizes[root(i)]

def unite(a, b):
    a = root(a)
    b = root(b)

    if a == b:
        return
    
    group_sizes[a] += size(b)
    node_groups[b] = a


for i in range(m-1, -1, -1):
    edge = edges[i]
    # print("edge: ",edge)
    #print("node_groups: ", node_groups)
    node_1 = edge[0]
    node_2 = edge[1]

    root_1 = root(node_1)
    root_2 = root(node_2)
    if root_1 == root_2:
        hubensa_list[i] = hubensa_list[i+1]
        continue

    # 不便さをだす
    hubensa_list[i] = hubensa_list[i+1] - (size(root_1) * size(root_2))

    unite(root_1, root_2)

#print("node_groups: ", node_groups)


for i in range(1, m+1):
    print(hubensa_list[i])

### FIXED CODE ###

import sys

sys.setrecursionlimit(100000)

tmp=input().split(" ")
n = int(tmp[0])
m = int(tmp[1])

node_groups = [ i for i in range(n)]
group_sizes = [ 1 for _ in range(n)]

edges = []
for i in range(m):
    tmp=input().split(" ")
    edges.append([int(tmp[0])-1, int(tmp[1])-1])

hubensa_list = [0] * (m + 1)
hubensa_list[m] = n*(n-1)//2

def root(i):
    if node_groups[i] == i:
        #print(i, "is root.")
        return i
    else:
        #_1 = node_groups[i]
        node_groups[i] = root(node_groups[i])
        #_2 = node_groups[i]
        #print ("root: ", _1, _2)
        return node_groups[i]

def same(a, b):
    return root(a) == root(b)

def size(i):
    return group_sizes[root(i)]

def unite(a, b):
    a = root(a)
    b = root(b)

    if a == b:
        return
    
    group_sizes[a] += size(b)
    node_groups[b] = a


for i in range(m-1, -1, -1):
    edge = edges[i]
    # print("edge: ",edge)
    #print("node_groups: ", node_groups)
    node_1 = edge[0]
    node_2 = edge[1]

    root_1 = root(node_1)
    root_2 = root(node_2)
    if root_1 == root_2:
        hubensa_list[i] = hubensa_list[i+1]
        continue

    # 不便さをだす
    hubensa_list[i] = hubensa_list[i+1] - (size(root_1) * size(root_2))

    unite(root_1, root_2)

#print("node_groups: ", node_groups)


for i in range(1, m+1):
    print(hubensa_list[i])
import numpy as np

H, N = map(int, input().split())

x = np.array(list(map(int, input().split())))

x = np.sort(x)[::-1]

if x[0] + x[1] >= H:
	print("Yes")
else:
	print("No")


### FIXED CODE ###

import numpy as np

H, N = map(int, input().split())

x = np.array(list(map(int, input().split())))

if sum(x) >= H:
	print("Yes")
else:
	print("No")
while True:
    n=input()
    if n==0:break
    L=[0]*10
    for i in range(n):
        L[input()]+=1
    for i in range(10):
        print "*"*L[i] if L[i]!=0 else "-"

### FIXED CODE ###

while True:
    try:
        n=input()
        if n==0:break
        L=[0]*10
        for i in range(n):
            L[input()]+=1
        for i in range(10):
            print "*"*L[i] if L[i]!=0 else "-"
    except SyntaxError:pass
a = int(input())
b = int(input())
c = a * b
d = c % 2
if d == 0 :
    print('Even')
else :
    print('Odd')


### FIXED CODE ###

x = input().split()
#x = [3,4]
#x[0] = 3, x[1] = 4

a = int(x[0])
b = int(x[1])
c = a * b
d = c % 2
if d == 0 :
    print('Even')
else :
    print('Odd')
n=int(input())
for i in range(n):
  a,b=map(int,input().split())
  if a==b:
    ct+=1
    if ct==3:
      print("Yes")
      break
  else:
    ct=0
else:
  print("No")

### FIXED CODE ###

n=int(input())
ct=0
for i in range(n):
  a,b=map(int,input().split())
  if a==b:
    ct+=1
    if ct==3:
      print("Yes")
      break
  else:
    ct=0
else:
  print("No")
import sys
import fractions
import functools
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n = INT()
a = LIST()

res = 0
for i in range(n):
    aa = a[:i] + a[i+1:]
    gcd = functools.reduce(math.gcd, aa)
    res = max(res,gcd)

print(res)


### FIXED CODE ###

import sys
import fractions
import functools
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n = INT()
a = LIST()

L = [0]*n
R = [0]*n
L[0] = INF
L[1] = a[0] 
R[n-1] = INF
R[n-2] = a[n-1]

GCDs = [0]*n

for i in range(2, n):
    L[i] = fractions.gcd(L[i-1], a[i-1])

for i in range(n-3,-1,-1):
    R[i] = fractions.gcd(R[i+1], a[i+1])

GCDs[0] = R[0]
GCDs[n-1] = L[n-1]

for i in range(1,n-1):
    GCDs[i] = fractions.gcd(L[i], R[i])

res = max(GCDs)

print(res)
n,k,q=map(int,input().split()) 
print(score)

for a in range(q):
    score[int(input())-1] +=1

for j in range(n):
    if score[j-1] > 0:
        print('Yes')
    else:
        print('No')
        
        

### FIXED CODE ###

n,k,q=map(int,input().split()) 
score=[k-q]*(n)


for a in range(q):
    score[int(input())-1] +=1

for j in range(n):
    if score[j] > 0:
        print('Yes')
    else:
        print('No')
from collections import deque
n,m=map(int,input().split())
g=[[] for _ in range(n)]
for _ in range(m):
    u,v=list(map(int,input().split()))
    g[u-1].append(v-1)
S,T=map(int,input().split())
S-=1;T-=1
INF=10**9
U=[[INF]*n for i in range(3)]
U[0][S]=0
que=deque([(0,S)])
while que:
    t,v=que.popleft()
    u=(t+1)%3
    if t==2:
        U[t][v]+=1
    for w in g[v]:
        if U[u][w]!=INF:
            continue
        que.append((u,w))
        U[u][w]=d
print(U[0][T] if U[0][T]<INF else -1)


### FIXED CODE ###

from collections import deque
n,m=map(int,input().split())
g=[[] for _ in range(n)]
for _ in range(m):
    u,v=list(map(int,input().split()))
    g[u-1].append(v-1)
S,T=map(int,input().split())
S-=1;T-=1
INF=10**9
U=[[INF]*n for i in range(3)]
U[0][S]=0
que=deque([(0,S)])
while que:
    t,v=que.popleft()
    u=(t+1)%3
    if t==2:
        U[t][v]+=1
    for w in g[v]:
        if U[u][w]!=INF:
            continue
        que.append((u,w))
        U[u][w]=U[t][v]
print(U[0][T] if U[0][T]<INF else -1)
# -*- coding: utf-8 -*-
a = int(input())
judge = True
for i in range(a):
  b = int(input())
  if (b % 2 == 0)
    if (b % 3 != 0) or (b % 5 != 0):
      judge = False
# 出力
if judge:
  print("APPROVED")
else:
  print("DENIED")

### FIXED CODE ###

# -*- coding: utf-8 -*-
a = int(input())
lis = list(map(int, input().split()))
for i in range(a):
  judge = True
  if (lis[i] % 2 == 0):
    if (lis[i] % 3 != 0) and (lis[i] % 5 != 0):
      judge = False
      break
# 出力
if judge:
  print("APPROVED")
else:
  print("DENIED")
n,m = list(map(int, input().split(" ")))

A = list(map(int, input().split(" ")))
bc = []
for _ in range(m):
  b,c = list(map(int, input().split(" ")))
  bc_ append((b,c))

count = 0
bc = sorted(bc,key=lambda x:x(1),reverse = True)
big_list = []
for b,c in bc:
  big_list += [c for _ in range(b)]
  count += b
  if count >= N:
    break
print(sum( sorted((A+big_list),reverse=True)[:N] ))

### FIXED CODE ###

n,m = list(map(int, input().split(" ")))

A = list(map(int, input().split(" ")))
bc = []
for _ in range(m):
  b,c = list(map(int, input().split(" ")))
  bc.append((b,c))

count = 0
bc = sorted(bc,key=lambda x:x[1],reverse = True)
big_list = []
for b,c in bc:
  big_list += [c for _ in range(b)]
  count += b
  if count >= n:
    break
print(sum( sorted((A+big_list),reverse=True)[:n] ))
n,z,w=map(int,input().split())
a=list(map(int,input().split()))
print(max(abs(a[-1]-w),abs(a[-2]-a[-1])))

### FIXED CODE ###

n,z,w=map(int,input().split())
a=list(map(int,input().split()))
ans=abs(a[-1]-w)
if n>1:
  ans=max(ans,abs(a[n-2]-a[n-1]))
print(ans)
import copy

n = int(input())
p = int(input().replace(" ", ""))
q = int(input().replace(" ", ""))

def hoge(numbers, s, n_list):

    for i in range(len(numbers)):
        copy_numbers = copy.deepcopy(numbers)
        ss = s+copy_numbers.pop(i)
        if len(copy_numbers) > 0:
            hoge(copy_numbers, ss, n_list)
        else:
            n_list.append(ss)

n_list = []
for i in range(n):
    number_list = [str(i) for i in range(1, n+1)]
    s = number_list.pop(i)
    hoge(number_list, s, n_list)

n_list.sort()

ans = abs((n_list.index(p) + 1) - (n_list.index(q) + 1))
print(ans)


### FIXED CODE ###

import copy

n = int(input())
p = int(input().replace(" ", ""))
q = int(input().replace(" ", ""))

def hoge(numbers, s, n_list):

    for i in range(len(numbers)):
        copy_numbers = copy.deepcopy(numbers)
        ss = s+copy_numbers.pop(i)
        if len(copy_numbers) > 0:
            hoge(copy_numbers, ss, n_list)
        else:
            n_list.append(int(ss))

n_list = []
for i in range(n):
    number_list = [str(i) for i in range(1, n+1)]
    s = number_list.pop(i)
    hoge(number_list, s, n_list)

n_list.sort()

ans = abs((n_list.index(p) + 1) - (n_list.index(q) + 1))
print(ans)