peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]

d = {num for num in range(1, n + 1)}
for i in range(m):
    if h[ab[i][0] - 1] > h[ab[i][1] - 1]:
        d.discard(ab[i][1])
    elif h[ab[i][0] - 1] < h[ab[i][1] - 1]:
        d.discard(ab[i][0])
    elif h[ab[i][0] - 1] == h[ab[i][1] - 1]:
        d.discard(ab[i][1])
        d.discard(ab[i][0])

print(len(d))
# Judge status: Accepted
d,n=map(int,input().split())
minus=n//100
print((n+minus)*(100**d))
# Judge status: Wrong Answer
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
import bisect
ans = 0
for i in range(N):
    b = B[i]
    x = bisect.bisect_left(A,b)
    y = bisect.bisect_right(C,b)
    if y == 0:
        break
    ans += x*y
print(ans)
# Judge status: Accepted
import sys

sys.setrecursionlimit(1000000)

import bisect
import math
import collections
import heapq

cache = {}
M = 10**9 + 7
def solve(S):
    if S < 3:
        return 0
    if S < 6:
        return 1
    if S in cache:
        return cache[S]
    ans = 1
    for remaining in range(S - 3, 2, -1):
        ans += solve(remaining)
        ans %= M
    cache[S] = ans
    return ans


if __name__ == "__main__":
    S = int(input())
    print(solve(S))
# Judge status: Wrong Answer
import sys
stdin = sys.stdin
from itertools import accumulate

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

n = ni()
h = na()
f = h[0]
b = False
for hi in h[1:]:
    if hi >= f:
        f = hi
        continue
    elif hi == f - 1 and not b:
        f = hi
    else:
        print("No")
        quit()
    if hi == f:
        b = True
print("Yes")
# Judge status: Wrong Answer
x = int(input())
a = x // 100
b = x - a * 100
c=[1,2,3,4,5]
f=False

while b >= 5:
	b = b - 5
	a -= 1
	if b == 0:
		f=True
if a>1:
	print(1)
else:
	print(0)
# Judge status: Accepted
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    ans = sum(A)
    counter = Counter(A)

    for _ in range(Q):
        b, c = map(int, input().split())
        ans -= counter[b] * b
        ans += counter[b] * c
        counter[c] += counter[b]
        counter[b] = 0
        print(ans)


if __name__ == "__main__":
    main()
# Judge status: Accepted
def makelist(n, m):
    return [[0 for i in range(m)] for j in range(n)]

a = int(input())
s = input()

if a < 3200:
    print("red")
else:
    print(s)
# Judge status: Accepted
N,M = map(int,input().split())

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

ans =[1]*N

for i in range(M):
    a,b = map(int,input().split())
    a=a-1
    b=b-1

    if Peaks[a]>Peaks[b]:
        ans[b]=0
    elif Peaks[a]<Peaks[b]:
        ans[a]=0
    else:
        ans[a]=0
        ans[b]=0

print(sum(ans))
# Judge status: Wrong Answer
# input
N = int(input())
X = list(map(int, input().split()))

# check
center = N // 2 - 1
for ind in range(N):
    if ind == 0:
        target = X[1:]
    elif ind == N - 1:
        target = X[:ind]
    else:
        target = X[:ind] + X[ind + 1:]
    
    print(target[center])
# Judge status: Wrong Answer
n = int(input())
cnt2 = 0
cnt4 = 0
A = list(map(int, input().split()))
for a in A:
    if a % 4 == 0:
        cnt4 += 1
    elif a % 2 == 0:
        cnt2 += 1

if 2*cnt4 < (n - cnt2 // 2 - cnt4):
    print("No")
else:
    print("Yes")
# Judge status: Accepted
import math
from collections import defaultdict

N = int(input())

rr = defaultdict(lambda: 0)
for i in range(1, N + 1):
    x = int(i / (10 ** int(math.log10(i))))
    y = i % 10
    rr[(x, y)] += 1

r = 0
for u in range(1, 10):
    for l in range(1, 10):
        r += rr[(u, l)] * rr[(l, u)]
print(r)
# Judge status: Accepted
# 幅優先探索（行きがけ）
import collections
import sys


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N = I()
    Aarray = LI()
    cnt = 0
    for i in range(N):
        if i % 2 == 0 and Aarray[i] % 2 != 0:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()
# Judge status: Accepted
import math

def prime_factorize(n):
	ret = []
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			cnt = 0
			while n % i == 0:
				cnt += 1
				n = n // i
			ret.append([i, cnt])
	if n != 1:
		ret.append([n, 1])
	if len(ret) == 0:
		ret.append([n, 1])

	return ret

def main():
	A, B = [int(x) for x in input().split(" ")]
	g = math.gcd(A, B)
	pg = prime_factorize(g)
	if pg[0][0] == 1:
		print(1)
	else:
		print(len(pg) + 1)

main()
# Judge status: Wrong Answer
import math

a=input()
a=sorted(a)
print("Yes" if a=="abs" else "No")
# Judge status: Accepted
import os, sys, re, math

N = int(input())

ret = 0
for i in range(N+1):
    ret += i

print(ret)
# Judge status: Accepted
# 2020/04/24
# AtCoder Beginner Contest 042 - B

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

for i in range(n):
    s.append(input())

s.sort()

# Output
print(''.join(s))
# Judge status: Wrong Answer
k = ['R','U','D']
g = ['L','U','D']

s = input()
for i in range(len(s)):
  if i == 'U' or i == 'D':
    continue
  else:
    if i%2 == 0:
      if i != 'L':
        print("No")
        exit()
    else:
      if i != 'R':
        print("No")
        exit()
print("Yes")
# Judge status: Accepted
n = int(input())

for i in range(1,10):
    if int(n)>int(str(i)*3):
        continue
    print(str(i)*3)
    break
# Judge status: Accepted
import sys
 
L, R = map(int, input().split())
 
if R-L >= 2019:
  print('0')
  sys.exit()
 
L = L % 2019
R = R % 2019
if L > R:
  print('0')
 
mmin = 2019
for i in range(L, R):
  for j in range(i+1, R+1):
    mmin = min(mmin, (i*j)%2019)
print(mmin)
# Judge status: Accepted
n = list(map(int, input()))
l = [sum(n)]
for i in range(1, len(n)):
    n[-i] = 9
    n[-i-1] -= 1
    l.append(sum(n)) 
print(max(l))
# Judge status: Wrong Answer
n, m = map(int, input().split())
x = list(map(int, input().split()))

del x[m:]
x.sort()
d = []

for i in range(len(x) - 1):
  d.append(x[i+1] - x[i])

d.sort()
del d[:(m-n)]

print(sum(d))
# Judge status: Accepted
n=int(input())
if n<600:
    print(8)
elif n<800:
    print(7)
elif n<1000:
    print(6)
elif n<1200:
    print(5)
elif n<1400:
    print(4)
elif n<1600:
    print(3)
elif n<1800:
    print(2)
else:
    print(1)
# Judge status: Wrong Answer
A,B,M=map(int,input().split())
vecA=list(map(int,input().split()))
vecB=list(map(int,input().split()))
matX=[input().split() for k in range(M)]
price = 10**6
for i in range(0,M):
    pricecom = int(vecA[int(matX[i][0]) -1]) + int(vecB[int(matX[i][1]) -1]) - int(matX[i][2])
    if pricecom<= price:
        price=pricecom
    else:
        pass
print(price)
# Judge status: Accepted
n,m = map(int,input().split())
stds = [tuple(map(int,input().split())) for _ in range(n)]
points = [tuple(map(int,input().split())) for _ in range(m)]

def d(s,p):
  return abs(s[0]-p[0]) + abs(s[1] - p[1])

for std in stds:
  ans = (-1, float('inf'))
  for i, pnt in enumerate(points):
    dst = d(std,pnt)
    if dst < ans[1]:
      ans = (i, dst)
  print(ans[0]+1)
# Judge status: Accepted
X = int(input())

ok = 10**9 # 解が存在する値
ng = 0 # 解が存在しない値
def bisearch(function, ok, ng):
    while abs(ok-ng) > 1:
        mid = (ok + ng)//2
        if function(mid):
            ok = mid
        else:
            ng = mid
    return ok

def check(mid):
    return mid*(mid+1)/2 >= X
    
print(bisearch(check, ok, ng))
# Judge status: Wrong Answer
import bisect
N = int(input())
X = list(map(int, input().split()))
Y = sorted(X.copy())
for x in X:
    print(Y[N//2-1] if bisect.bisect(Y, x) >= N//2 else Y[N//2])
# Judge status: Accepted
n,h=map(int,input().split())
ab=[]
ans=0
for i in range(n):
  aa,bb=map(int,input().split())
  ab.append([aa,bb])

ab.sort(key=lambda x: x[0],reverse=True)
katana=ab[0][0]
ab.sort(key=lambda x: x[1],reverse=True)
cnt=0
# print(ab)
for a,b in ab:
  if b>katana:
    cnt+=1

for i in range(cnt):
  if h<=0:break
  h-=ab[i][1]
  ans+=1
if h>0:
  ans+=(h-1)//katana+1
print(ans)
# Judge status: Accepted
import math

if __name__ == "__main__":
    N = int(input())
    ret = math .floor(N / 2)
    if N % 2 == 1:
       ret = ret + 1
    print(ret)
# Judge status: Wrong Answer
string = str(input())

def test(string):
    string.split()
    if string[2] == string[3] and string[4] == string[5]:
        return "Yes"
    else:
        return "No"
# Judge status: Accepted
s=input()
l=[i for i in s]
for i in range(len(s)):
	if(s[i]=='?'):
		l[i]='D'
for i in l:
	print(i,end="")
print()
# Judge status: Accepted
n = int(input())
a = []
for i in range(n):
    a.append(int(input()) - 1)

visited = [False] * n
f = 0
visited[f] = True
cnt = 0
while True:
    cnt += 1
    t = a[f]
    if t == 1:
        flg = True
        break
    if visited[t]:
        flg = False
        break
    visited[t] = True
    f = t
print(cnt) if flg else print(-1)
# Judge status: Accepted
P, Q, R = map(int, input().split())

a = P + Q
b = Q + R
c = P + R
l = [a, b, c]
print(min(l))
# Judge status: Accepted
A = list(map(int, input().split()))
print("bust" if sum(A)>=22 else "win")
# Judge status: Wrong Answer
N, A, B =map(int,input().split())
d = abs(B-A)
ans = 0
if d % 2 == 0:
    ans = int(d / 2)
else:
    if N - B >= A - 1:
        ans = B - 1
    else:
        ans = N - A

print(ans)
# Judge status: Wrong Answer
n = int(input())

t = False
for i in range(1,10):
    for j in range(1, 10):
        if n == i*j:
            t = True
            quit()

if t:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
h,n,*t=map(int,open(0).read().split())
d=[0]+[10**18]*h
print(d)
print(*[iter(t)])
for a,b in zip(*[iter(t)]*2):
    for j in range(h+1):
        k=j-a
        if k<0:k=0
        c=d[k]+b
        if c<d[j]:d[j]=c
print(d[h])
# Judge status: Accepted
n,m,x,y = map(int,input().split())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))
if max(X) < y and max(X) < min(Y) and min(Y) > x:
    print("No War")
else:
    print("War")
# Judge status: Accepted
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7

n, a, b = map(int, input().split())

ans = pow(2, n, mod) - 1

def fur(n,r):
    p,q = 1,1
    for i in range(r):
        p = p*(n-i)%mod
        q = q*(i+1)%mod
    return p * pow(q,mod-2,mod) % mod

print((ans - fur(n, a) - fur(n, b)) % mod)
# Judge status: Accepted
S = str(input())

ans = []
for i in range(len(S)):
  if S[i] == "B":
    if ans == []:
      continue
    else:
      ans = ans[:-1]
  else:
    ans.append(S[i])
  #print(ans)
#print(ans)  

for i in range(len(ans)):
  print(ans[i], end = "")
# Judge status: Wrong Answer
X, Y = map(int, input().split())
twoLine = [X*(2 ** i) for i in range(61)]
# 2分探索で調べる
left = -1
right = len(twoLine)
while right - left > 1:
    middle = (right + left) // 2
    if twoLine[middle] > Y:
        right = middle
    else:
        left = middle
print(middle)
# Judge status: Wrong Answer
S = list(input())
 
left = [0]*(len(S)+1)
 
right = [0]*(len(S)+1)
 
for i in range(len(S)):
    if S[i] == '<':
        left[i+1] += 1+left[i]
 
for i in range(len(S)-1,-1,-1):
    if S[i] == '>':
        right[i] = right[i+1]+1
 
ans = [0]*(len(S)+1)
for i in range(len(S)+1):
    ans[i] = max(left[i],right[i])
print(sum(ans)+1) #+1
# Judge status: Accepted
a, b, k = [int(i) for i in input().split()]

lim_1 = min(a + k, b)
lim_2 = max(b - k + 1, a)
ans = set(list(range(a, lim_1)) + list(range(lim_2, b + 1)))

for n in ans:
    print(n)
# Judge status: Wrong Answer
import collections
N = int(input())
A = list(map(int, input().split()))
indices = collections.defaultdict(list)
for i, a in enumerate(A):
  indices[a].append(i)
Q = int(input())
for _ in range(Q):
  B, C = map(int, input().split())
  print(B, C)
  for i in indices[B]:
    indices[C].append(i)
    A[i] = C
  print(sum(A))
# Judge status: Accepted
K,X=map(int,input().split())
if X<=500*K:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
W,H,N=map(int,input().split())
x=[0]*N
y=[0]*N
a=[0]*N
H_min=0
H_max=H
W_min=0
W_max=W

for i in range(N):
  x[i],y[i],a[i] = map(int,input().split())
  if a[i]==1:
    W_min=x[i]
  elif a[i]==2:
    W_max=x[i]
  elif a[i]==3:
    H_min=y[i]
  else:
    H_max=y[i]

height = max(0,H_max-H_min)
width = max(0,W_max-W_min)
print(height*width)
# Judge status: Wrong Answer
n,k = map(int, input().split())
r, s, p =map(int,input().split())
t = list(input())
wins = []
cnt = 0
minus = 0
for out in t:
    if out == "r":
        wins.append(p)
    elif out == "s":
        wins.append(r)
    else:
        wins.append(s)
    if cnt > k - 1:
        if wins[cnt] == wins[cnt-k]:
                wins[cnt] = 0
    cnt = cnt + 1

print(sum(wins))
# Judge status: Accepted
def main():
    n, l = map(int, input().split())
    ss = [list(input()) for _ in range(n)]

    for i in range(l-1, -1, -1):
        ss = sorted(ss, key=lambda x: x[i])

    ans = ''
    for i in range(n):
        for j in range(l):
            ans += ss[i][j]
    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
a,b,c=map(int,input().split())
print(b,a,c)
# Judge status: Accepted
D,T,S = map(int,input().split())
print("Yes" if D/S<=T else "No")
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

MAX = 10 ** 6

A.sort()
s = set()
ans = N
for i in range(N):
    a = A[i]
    if a in s:
        ans -= 1
        continue
    if i < N - 1 and A[i + 1] == a:
        ans -= 1
    n = MAX // a
    for i in range(1, n + 1):
        s.add(a * i)
print(ans)
# Judge status: Accepted
from statistics import median

n = int(input())
a = [None] * n
b = [None] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

if n % 2 == 1:
    print(abs(median(b) - median(a)) + 1)
else:
    print(int(abs(median(b) - median(a)) * 2) + 1)
# Judge status: Wrong Answer
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, t = rm()
min_ = inf
for _ in range(n):
  a, b = rm()
  if b <= t:
    min_ = min(min_, a)
print(min_)
# Judge status: Wrong Answer
s = input()
ans = ''
for i in range(len(s)):
  s_i = s[i]
  if s_i == '?':
    if i < len(s) - 1:
      if (s[i + 1] == 'D') | (s[i + 1] == '?'):
        ans += 'P'
        continue
      else:
        ans += 'D'
        continue
    else:
      ans += 'D'
      continue
  ans += s_i
print(ans)
# Judge status: Wrong Answer
s = input()
k = int(input())
cnt = 0
ans = ''
for i in range(len(s)):
    if i == len(s) - 1:  # 最後の文字の時
        diff = (k - cnt) % 26
        ans += chr((ord(s[i]) - ord('a') + (k - cnt)) % 26 + ord('a'))
    elif ord('z') - ord(s[i]) + 1 <= k - cnt:  # 'a'に変更可能な時
        cnt += ord('z') - ord(s[i]) + 1
        ans += 'a'
    else:
        ans += s[i]
print(ans)
# Judge status: Wrong Answer
x, n = map(int,input().split())

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

p.append(x)

d =100
num = 0

if n == 0:
    num = x
else:
    for i in range(-1,102):
        if i not in p:
            d_temp = abs(x-i)
            if d_temp < d:
                d = d_temp
                num = i
print(num)
# Judge status: Accepted
c = str(input())
if "9" in c:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
N=int(input())
A=list(map(int,input().split()))
L=[0 for i in range(200010)]
R=[0 for i in range(200010)]
for i in range(N):
    if A[i]+i<100010:
        L[A[i]+i]+=1
    if -A[i]+i>0:
        R[-A[i]+i]+=1
ans=0
for i in range(200010):
    ans+=L[i]*R[i]
print(ans)
# Judge status: Accepted
N, M, X = [int(n) for n in input().split()]

CA = [list(map(int, input().split())) for n in range(N)]

ans = 10**10

for i in range(2**N):
  cost = 0
  skills = [0] * M
  for j in range(N):
    if ((i >> j) & 1):
      #print(i, j)
      for k in range(M):
        skills[k] += CA[j][1+k]
      cost += CA[j][0]
  #print("skills", skills)
  if all([n >= X for n in skills]):
  	ans = min(ans, cost)
  #print("ans", ans)
if ans == 10**10:
  print(-1)
else:
  print(ans)
# Judge status: Accepted
n, m = map(int, input().split())

g = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

for first in g[0]:
    if n-1 in g[first]:
        print("POSSIBLE")
        exit()
else:
    print("IMPOSSIBLE")
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))

all = 0
for i in a:
    all = all ^ i

ans = []
for i in a:
    ans.append(all^i)

print(' '.join(map(str,ans)))
# Judge status: Wrong Answer
q,h,s,d=list(map(int, input().split()))
x=int(input())

q=q*4
h=h*2
d=d/2

ans=0
if q<=h and q<=s and q<=d:
	ans=x*q
	x=0
elif h<=q and h<=s and h<=d:
	ans=x*h
	x=0
elif s<=q and s<=h and s<=d:
	ans=x*s
	x=0
else:
	ans=ans+round((x//2)*d*2)
	x=x-((x//2)*2)
if x>0:
	if q<=h and q<=s:
		ans=ans+q
	elif h<=q and h<=s:
		ans=ans+h
	else :
		ans=ans+s
print(ans)
# Judge status: Wrong Answer
N=input()
n=int(N)
x=0
for s in range(n):
  ds1,ds2=input().split()
  Ds1=int(ds1)
  Ds2=int(ds2)
  if Ds1==Ds2:
    x+=1
  else:
    x+=0
if x>3:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
n=int(input())

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

s=0
for i in range(len(a)-1):
    if a[i]>=a[+1]:
        continue
    else:
        s+=a[i+1]-a[i]

print(s)
# Judge status: Wrong Answer

n = int(input())

a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
sum = 0

for i in range(len(a)):
    sum += b[a[i] - 1]
    print("i:{0} sum{1}".format(i, sum))
    if(i != len(a) - 1 and a[i] + 1 == a[i + 1]):
        sum += c[a[i] - 1]
        print("i:{0} sum{1}".format(i, sum))

print(sum)
# Judge status: Wrong Answer
from collections import defaultdict

b = defaultdict(int)
r = defaultdict(int)

n = int(input())
for i in range(n):
    b[input()] += 1
m = int(input())
for i in range(m):
    r[input()] += 1
print(b)
print(b.items())

ans = 0
for k, v in b.items():
    ans = max(ans, v - r[k])
print(ans)
# Judge status: Accepted
k = int(input())
a,b = map(int,input().split())

d = a//k
e = b//k
if d!=e or a%k == 0:
    print('OK')
else:
    print('NG')
# Judge status: Accepted
a, b, c = map(int, input().split())

ans = c - (a - b)
if ans >= 0:
    print(ans)
else:
    print(0)
# Judge status: Wrong Answer
n = int(input())
tsk = []
for i in range(n):
	a,b = map(int,input().split())
	tsk.append([a,b,b-a])

tsk.sort(key = lambda x:x[2])

t = 0
ans = 'Yes'

for i in range(n):
	l = tsk[i]
	t += l[0]
	if l[1]<t:
		ans = 'No'
		break
print(ans)
# Judge status: Accepted
N=int(input())
ans=N
for i in range(N+1):
  cnt=0
  t=i
  while t>0:
    cnt+=t%6
    t//=6
  j=N-i
  while j>0:
    cnt+=j%9
    j//=9
  ans=min(ans,cnt)
print(ans)
# Judge status: Accepted
import sys
from collections import Counter

input = sys.stdin.readline
P = 10**9 + 7


def main():
    N = int(input())
    S = input().rstrip()

    # Editorial AC
    c = Counter(S)
    ans = 1
    for v in c.values():
        ans = (ans * (v + 1)) % P
    ans = (ans - 1) % P

    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
import os,sys

count=0
n=int(input())

for a in range(1,n+1):
    i = n-a
    for b in range(1,i+1):
        j=n-a*b
        for c in range(1,j):
            if a*b+c==n:
                count+=1
print(count)
# Judge status: Accepted
import heapq

n, m = map(int, input().split())
points = [tuple(map(int, input().split())) for _ in range(n)]
points.sort()

ans = 0
i = 0
days = 0
heap = []
while days <= m:
    while i < len(points) and points[i][0] <= days:
        d, p = points[i]
        heapq.heappush(heap, -p)
        i += 1

    days += 1
    if heap: ans += heapq.heappop(heap)

print(-ans)
# Judge status: Accepted
N, M, Q = map(int, input().split())
reqs = [list(map(int, input().split())) for _ in range(Q)]

As = []

def make(A):
  global As, N, M
  # print(A)
  if len(A) == N+1:
    As.append(A)
  else:
    for i in range(A[len(A)-1], M+1):
      make(A+[i])

make([1])

maxs = 0
for A in As:
  score = 0
  for req in reqs:
    if A[req[1]] - A[req[0]] == req[2]:
      score += req[3]
  maxs = max(score, maxs)

print(maxs)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

INF = 10 ** 18
ans = 1
if any([n == 0 for n in a]):
    print(0)
    exit()

for n in a:
    ans *= n
    if ans > INF:
        ans = -1
        break
print(ans)
# Judge status: Accepted
import sys
n=int(input())

ans=[]

if n==1:
    print('1')
    sys.exit()

for i in range(n//2):
    for j in range(n//2):
        if i**j<=n:
            ans.append(i**j)

print(max(ans))
# Judge status: Accepted
n=list(map(int,input().split()))
a=n[0]
b=n[1]
if 500*a>=b:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
n = int(input())
s = input()
d = []
cnt = 0
for i in range(n):
    if s[i] == "(":
        cnt += 1
    else:
        cnt -= 1
    d.append(cnt)
x = min(d)
print("("*(-x)+s+")"*(d[-1]-x))
# Judge status: Wrong Answer
import math
A, B = map(float,input().split())

print(math.floor(A*B))
# Judge status: Accepted
N,M = map(int, open(0).read().split())
if 2 * N > M:
    print(M//2)
else:
    rem = M - 2 * N
    print(N+rem//4)
# Judge status: Wrong Answer
N = int(input())
AA = [0]*N
BB = [0]*N
for i in range(N):
  AA[i], BB[i] = map(int,input().split())
AA_sorted = sorted(AA)
BB_sorted = sorted(BB,reverse=True)
if N%2 == 1:
  idx = int(N/2)
  N_Max = BB_sorted[idx]
  N_Min = AA_sorted[idx]
  print(N_Max-N_Min+1)
else:
  idx = int(N/2)
  N_Max = BB_sorted[idx-1]
  N_Min = AA_sorted[idx-1]
  print((N_Max-N_Min)*2-1)
# Judge status: Accepted
a,b,k=map(int,input().split())
eat1=min(a,k)
k-=eat1
eat2=min(b,k)
print(a-eat1,b-eat2)
# Judge status: Wrong Answer
n = int(input())
b = (int(x) for x in input().split())
a = list(b)
x = 0
for i in range(n):
    if a.count(a[i]) != 1:
        print("Yes")
        x = 1
        break

if x == 0:
    print("No")
# Judge status: Accepted
from operator import itemgetter


n, m = map(int, input().split())
info = [list(map(int, input().split())) + [i] for i in range(m)]

info = sorted(info, key=itemgetter(1))
ans = [0] * m

cnt_ind = [1] * (n + 1)
for i in range(m):
    p, y, ind = info[i]
    cnt = cnt_ind[p]
    cnt_ind[p] += 1
    ans[ind] = ("0000000"+str(p))[-6:] + ("0000000"+str(cnt))[-6:]
for i in ans:
    print(i)
# Judge status: Wrong Answer
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

x, y = map(int, readline().split())
if x <= y:
    if (x > 0 and y > 0) or (x <= 0 and y <= 0):
        ans = y - x
    else:
        ans = y + x + 1
else:
    if (x >= 0 and y >= 0) or (x < 0 and y < 0):
        ans = min(abs(x) + abs(y) + 1, abs(y) - abs(x) + 2)
    else:
        ans = - x - y + 1
print(ans)
# Judge status: Wrong Answer
s = input()

dir = [0 for i in range(4)]
for i in range(len(s)):
    if s[i] == "N":
        dir[0] += 1
    elif s[i] == "W":
        dir[1] += 1
    elif s[i] == "S":
        dir[2] += 1
    elif s[i] == "E":
        dir[3] += 1

if 0 not in dir:
    print("Yes")
elif dir.count(0) == 3:
    print("No")
elif dir[0] == 0 and dir[0] == 0 or dir[1] == 0 and dir[3] == 0:
    print("Yes")
else:
    print("No")