Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

from itertools import combinations
import bisect
import copy

def move(positions, tmp_X, N, tmp_ans):
  min_dif = float('inf')
  min_idx = None
  min_x = None
  for x in tmp_X:
    idx = bisect.bisect_left(positions,x)
    if idx == N:
      tmp_dif = abs(x-positions[idx-1])
      tmp_idx = idx -1
    elif idx == 0:
      tmp_dif = abs(x-positions[idx])
      tmp_idx = idx
    else:
      dif1, dif2 = abs(x-positions[idx-1]), abs(x-positions[idx])
      if dif1 >= dif2:
        tmp_dif = dif2
        tmp_idx = idx
      else:
        tmp_dif = dif1
        tmp_idx = idx - 1

    if min_dif > tmp_dif:
      min_dif = tmp_dif
      min_idx = tmp_idx
      min_x = x
  
  del positions[min_idx]
  idx = bisect.bisect_left(positions, min_x)
  positions.insert(idx, min_x)

  tmp_X.remove(min_x)
  return tmp_ans + min_dif

N,M = map(int,input().split())
X = list(map(int,input().split()))

if N >= M:
  print(0)
  exit()

ans = float('inf')
for cmb in combinations(X,N):
  tmp_ans = 0
  tmp_X = copy.deepcopy(X)
  positions = sorted(list(cmb))
  for position in positions: tmp_X.remove(position)
  
  while len(tmp_X) > 0:
    tmp_ans = move(positions, tmp_X, N, tmp_ans)
  ans = min(tmp_ans, ans)
print(ans)

### FIXED CODE ###

N,M = map(int,input().split())
if M == 1:
  print(0)
  exit()

X = sorted(list(map(int,input().split())))
difX = [0] + [X[i+1]-X[i] for i in range(M-1)]
difX.sort(reverse=True)
print(sum(difX)-sum(difX[:N-1]))
### BUGGY CODE ###

def resolve():
    import sys
    sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
    to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
    print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

    # 入力を整数に変換して受け取る
    def input_int():
        return int(input())

    def map_int_input():
        return map(int, input())

    MII = map_int_input

    def MII_split():
        return map(int, input().split())

    def MII_to_index():
        return map(to_index, input())

    def MII_split_to_index():
        return map(to_index, input().split())

    # 入力全てを整数に変換したものの配列を受け取る
    def list_int_inputs():
        return list(map(int, input()))

    LII = list_int_inputs

    def LII_split():
        return list(map(int, input().split()))

    # 2次元リスト化
    def LII_2D(rows_number):
        return [LII() for _ in range(rows_number)]

    def LII_split_2D(rows_number):
        return [LII_split() for _ in range(rows_number)]

    N = input_int()
    As = LII_split()

    for a in As:
        if a > 10 ** 9 + 7:
            a %= 10 ** 9 + 7

    s = 0
    for i in range(N):
        for j in range(i+1, N):
            s += As[j] * As[i]
            if s > 10 ** 9 + 7:
                s %= 10 ** 9 + 7
    print(s)
    
resolve()

### FIXED CODE ###

def resolve():
    import sys
    sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
    to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
    print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

    # 入力を整数に変換して受け取る
    def input_int():
        return int(input())

    def map_int_input():
        return map(int, input())

    MII = map_int_input

    def MII_split():
        return map(int, input().split())

    def MII_to_index():
        return map(to_index, input())

    def MII_split_to_index():
        return map(to_index, input().split())

    # 入力全てを整数に変換したものの配列を受け取る
    def list_int_inputs():
        return list(map(int, input()))

    LII = list_int_inputs

    def LII_split():
        return list(map(int, input().split()))

    # 2次元リスト化
    def LII_2D(rows_number):
        return [LII() for _ in range(rows_number)]

    def LII_split_2D(rows_number):
        return [LII_split() for _ in range(rows_number)]

    N = input_int()
    A = LII_split()

    s = 0
    right_sum = 0
    for i in reversed(range(N - 1)):
        right_sum += A[i + 1]
        s += A[i] * right_sum

        # 2乗は死ぬので累積和を使う（使えることは式を書き出せばわかる）
        # for j in range(i + 1, N):
        #     s += As[j] * As[i]
        if s > 10 ** 9 + 7:
            s %= 10 ** 9 + 7

    print(s)
    
resolve()
### BUGGY CODE ###

import collections

n = int(input())
s = input()

s1 = s[:n]
s2 = s[-1:-(n + 1):-1]

s_1 = collections.defaultdict(int)
s_2 = collections.defaultdict(int)
for i in range(2 ** n):
    bin_i = bin(i + 2 ** n)
    sequence1 = ""
    sequence1_inverse = ""
    sequence2 = ""
    sequence2_inverse = ""
    for j in range(n):
        if bin_i[j + 3] == "1":
            sequence1 += s1[j]
            sequence2 += s2[j]
        else:
            sequence1_inverse += s1[j]
            sequence2_inverse += s2[j]
    s_1[(sequence1, sequence1_inverse)] += 1     
    s_2[(sequence2, sequence2_inverse)] += 1
ans = 0

for i in dict(s_1):
    ans += s_1.get(i, 0) * s_2.get(i, 0)
    '''
    if i in dict(s_2):
        ans += dict(s_1)[i] * dict(s_2)[i]
    '''
print(ans)


### FIXED CODE ###

import collections

n = int(input())
s = input()

s1 = s[:n]
s2 = s[-1:-(n + 1):-1]

s_1 = collections.defaultdict(int)
s_2 = collections.defaultdict(int)

strlist = []

for i in range(2 ** n):
    bin_i = bin(i + 2 ** n)
    sequence1 = ""
    sequence1_inverse = ""
    sequence2 = ""
    sequence2_inverse = ""
    for j in range(n):
        if bin_i[j + 3] == "1":
            sequence1 += s1[j]
            sequence2 += s2[j]
        else:
            sequence1_inverse += s1[j]
            sequence2_inverse += s2[j]
    s_1[sequence1 + "-" + sequence1_inverse] += 1     
    s_2[sequence2 + "-" + sequence2_inverse] += 1
ans = 0

for i in dict(s_1):
    ans += s_1.get(i, 0) * s_2.get(i, 0)
    '''
    if i in dict(s_2):
        ans += dict(s_1)[i] * dict(s_2)[i]
    '''
print(ans)
### BUGGY CODE ###

from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
lcm = 1
for i in range(n):
    lcm = a[i] * lcm // gcd(a[i], lcm)
b = [lcm // a[i] for i in range(n)]
print(sum(b) % (10**9+7))

### FIXED CODE ###

from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
lcm = 1
for i in range(n):
    lcm = a[i] * lcm // gcd(a[i], lcm)
b = [lcm // a[i] for i in range(n)]
print(sum(b) % (10**9+7))
### BUGGY CODE ###

MOD = 10 ** 9 + 7
fac = [1] * (10 ** 5 * 3)


def nCr(n, r):
    return fac[n] * pow(fac[n - r], MOD - 2, MOD) * pow(fac[r], MOD - 2, MOD) % MOD


for i in range(len(fac) - 1):
    fac[i + 1] = fac[i] * (i + 1) % MOD
b, w = map(int, input().split())
n = b + w
p = [0] * n
q = [0] * n
for i in range(b, n):
    p[i] = (p[i - 1] + nCr(i - 1, b - 1) *
            pow(pow(2, i, MOD), MOD - 2, MOD)) % MOD
for i in range(w, n):
    q[i] = (q[i - 1] + nCr(i - 1, w - 1) *
            pow(pow(2, i, MOD), MOD - 2, MOD)) % MOD
for i in range(n):
    print((q[i] + (1 - p[i] - q[i]) * pow(2, MOD - 2, MOD)) % MOD)


### FIXED CODE ###

MOD = 10 ** 9 + 7
fac = [1] * (10 ** 5 * 3)


def nCr(n, r):
    return fac[n] * pow(fac[n - r], MOD - 2, MOD) * pow(fac[r], MOD - 2, MOD) % MOD


for i in range(len(fac) - 1):
    fac[i + 1] = fac[i] * (i + 1) % MOD
b, w = map(int, input().split())
n = b + w
p = [0] * n
q = [0] * n
for i in range(b, n):
    p[i] = (p[i - 1] + nCr(i - 1, b - 1) *
            pow(pow(2, i, MOD), MOD - 2, MOD)) % MOD
for i in range(w, n):
    q[i] = (q[i - 1] + nCr(i - 1, w - 1) *
            pow(pow(2, i, MOD), MOD - 2, MOD)) % MOD
t = pow(2, MOD - 2, MOD)
for i in range(n):
    print((q[i] + (1 - p[i] - q[i]) * t) % MOD)
### BUGGY CODE ###

N = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        s = l[i]+l[j]
        if s <= l[j+1]:
            continue
        if s > l[N-1]:
            ans += (N-j-1) * (N-j) //2
            break
        start = j+1
        end = N
        while start != end:
            center = (start + end)//2
            if s <= l[center]:
                end = center
            else:
                start = center + 1
        ans += end-j-1
print(ans)

### FIXED CODE ###

N = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
max = l[N-1]
tc = N
st = [j+1 for j in range(N-1)]
for i in range(N-2):
    if l[i]+l[i+1] > max:
        k = N-i-1
        ans += ((k-1)*k*(k+1))//6
        break
    for j in range(i+1,N-1):
        if j == tc:
            ans += tp
            break
        s = l[i]+l[j]
        if s <= l[j+1]:
            continue
        if s > max:
            tc = j 
            tp = (N-j-1) * (N-j) //2 #これをiの中でできないか
            ans += tp
            break
        start = st[j]
        if s <= l[start]:
            ans += start-j-1
            continue
        end = N
        while start != end:
            center = (start + end)//2
            if s <= l[center]:
                end = center
            else:
                start = center + 1
        st[j] = end
        ans += end-j-1
print(ans)
### BUGGY CODE ###

import bisect
N = int(input())
L = list(map(int, input().split()))

L.sort()

ans = 0
for i in range(N):
    for j in range(i+1,N):
        ans += bisect.bisect_left(L[j+1::], L[i]+L[j])
print(ans)

### FIXED CODE ###

import bisect
N = int(input())
L = list(map(int, input().split()))
index = [-1 for i in range(2001)]
L.sort()

ans = 0
for i in range(N):
    for j in range(i+1,N):
        if index[L[i]+L[j]] == -1:
            index[L[i]+L[j]] = bisect.bisect_left(L, L[i]+L[j])
        ans += max(0, index[L[i]+L[j]]-j-1)
print(ans)
### BUGGY CODE ###

import math
q = int(input())

Carm = [561, 1105, 1729, 2465, 2821, 6601, 8911, 10585, 15841, 29341, 41041, 46657, 52633, 62745, 63973, 75361]

def isPrime(q):
  if q == 2:
    return True
  if q == 1 or q in Carm:
    return False
  return pow(2, q-1, q) == 1


C = []
for i in range(q):
  ran = list(map(int, input().split()))
  if ran[0] % 2 == 0:
    j = ran[0]+1
  else:
    j = ran[0]
  count = 0
  while j <= ran[1] :
    if isPrime(j) and isPrime((j+1)//2):
      count += 1
    j += 2
  C.append(count)

for i in range(q):
  print(C[i])


### FIXED CODE ###

primes = [True]*100000
for i in range(2,100000):
  if primes[i] == False:
    continue
  for j in range(2*i, 100000, i):
    primes[j] = False

c = [0]*100000

for i in range(3,100000):
  if primes[i] and primes[(i+1)//2] == True:
    c[i] = c[i-1]+1
  else:
    c[i] = c[i-1]


q = int(input())
ran = []
for i in range(q):
  ran.append(list(map(int, input().split())))
for i in range(q):
  print(c[ran[i][1]]-c[ran[i][0]-1])
### BUGGY CODE ###

N = int(input())
S = input()
r = S.count("R")
g = S.count("G")
b = S.count("B")

ret = r * g * b
for i in range(N - 2):
    for j in range(1, N):
        if N > i + j + j:
            a = S[i]
            b = S[i + j]
            c = S[i + j + j]
            if a != b and b != c and c != a:
                ret -= 1
print(ret)


### FIXED CODE ###

N = int(input())
S = input()
r = 0
g = 0
b = 0
for s in S:
    if s == "R":
        r += 1
    elif s == "G":
        g += 1
    else:
        b += 1

ret = r * g * b

for i in range(N):
    for d in range(N):
        j = i + d
        k = j + d
        if k >= N:
            break
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            ret -= 1

print(ret)
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline
    n,m,l = map(int,input().split())
    E = [[] for i in range(n)]
    for i in range(m):
        a,b,c = map(int,input().split())
        E[a-1].append((b-1,c))
        E[b-1].append((a-1,c))

    import heapq

    def dijkstra(s):
        dist = [[float("INF")]*2 for _ in range(n)]
        
        dist[s] = [0,l]
        q = []
        heapq.heappush(q, (0,s,l))
        
        while q:
            count,cur,fuel = heapq.heappop(q)
            for nex, nex_len in E[cur]:
                if fuel >= nex_len:
                    nex_fuel = fuel - nex_len
                    if dist[nex][0] > count or (dist[nex][0]==count and nex_fuel > dist[nex][1]):
                        heapq.heappush(q, (count,nex,nex_fuel))
                        dist[nex] = [count,nex_fuel]
                else:
                    if l >= nex_len:
                        nex_fuel = l-nex_len
                        nex_count = count+1
                        if dist[nex][0] > nex_count or (dist[nex][0]==nex_count and nex_fuel > dist[nex][1]):
                            heapq.heappush(q, (nex_count,nex,nex_fuel))
                            dist[nex] = [nex_count,nex_fuel]

        return dist


    ans = []
    for i in range(n):
        ans.append(dijkstra(i))
    
    x = int(input())
    for i in range(x):
        s,g = map(int,input().split())
        if ans[s-1][g-1][0] == float("INF"):
            print(-1)
        else:
            print(ans[s-1][g-1][0]) 
if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    n,m,l = map(int,input().split())
    E = [[float("INF")]*n for i in range(n)]
    for i in range(m):
        a,b,c = map(int,input().split())
        E[a-1][b-1] = c
        E[b-1][a-1] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                E[i][j] = min(E[i][j],E[i][k]+E[k][j])
    wa = [[float("INF")]*n for i in range(n)]
    for i in range(n):
        for j in range(n):
            if E[i][j] <= l:
                wa[i][j] = 1
    for k in range(n):
        for i in range(n):
            for j in range(n):
                wa[i][j] = min(wa[i][j],wa[i][k]+wa[k][j])
    
    x = int(input())
    for i in range(x):
        s,g = map(int,input().split())
        if wa[s-1][g-1] == float("INF"):
            print(-1)
        else:
            print(wa[s-1][g-1]-1)

    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

MOD = 10 ** 9 + 7

s = str(input())

cur = [0] * 13

if s[0] != "?":
    cur[int(s[0])] = 1
else:
    for j in range(10):
        cur[j] = 1

for i in range(1,len(s)):
    pre = cur[:]
    cur = [0] * 13
    if s[i] != "?":
        for j in range(13):
            q = (j * 10 + int(s[i])) % 13
            cur[q] += pre[j] % MOD
    else:
        for j in range(13):
            for k in range(10):
                p = (j * 10 + k) % 13
                cur[p] += pre[j] % MOD

print(cur[5] % MOD)

### FIXED CODE ###

MOD = 10 ** 9 + 7
 
s = str(input())
 
s = list(s)
 
cur = [0] * 13
 
if s[0] != "?":
    cur[int(s[0])] = 1
else:
    for j in range(10):
        cur[j] = 1
 
for i in range(1,len(s)):
    pre = cur[:]
    cur = [0] * 13
    if s[i] != "?":
        for j in range(13):
            q = (j * 10 + int(s[i])) % 13
            cur[q] += pre[j] % MOD
    else:
        for j in range(13):
            for k in range(10):
                p = (j * 10 + k) % 13
                cur[p] += pre[j] % MOD
 
print(cur[5] % MOD)
### BUGGY CODE ###

import collections
b=[]
c=[]
n=int(input())
a=list(map(int,input().split()))
q=int(input())
d=collections.Counter(a)
for i in range(q):
    x,y=map(int,input().split())
    b.append(x)
    c.append(y)
for i in range(q):
    tmp=d[b[i]]
    d[b[i]]=0
    d[c[i]]+=tmp
    sum=0
    for key,val in d.items():
        sum+=key*val
  
    print(sum)


### FIXED CODE ###

import collections
b=[]
c=[]
n=int(input())
a=list(map(int,input().split()))
q=int(input())
d=collections.Counter(a)
for i in range(q):
    x,y=map(int,input().split())
    b.append(x)
    c.append(y)
sum=0
for i in range(n):
    sum+=a[i]
for i in range(q):
    tmp=d[b[i]]
    d[b[i]]=0
    d[c[i]]+=tmp
    sum=sum-b[i]*tmp+tmp*c[i]
    print(sum)
### BUGGY CODE ###

n = int(input())
collections = []
ans = 0

for _ in range(n):
  s = input()
  if s in collections:
    continue
  ans += 1
  collections.append(s)

print(ans)

### FIXED CODE ###

n = int(input())
collections = {}
ans = 0

for _ in range(n):
  s = input()
  collections[s] = 1


print(sum(collections.values()))
### BUGGY CODE ###

n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]
for i in range(1,n):
    l = []
    for j in range(1,min(len(dp),k)+1):
        l.append(dp[i-j] + abs(h[i]-h[i-j]))
    dp.append(min(l))
print(dp[n-1])

### FIXED CODE ###

n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]
for i in range(1,n):
    l = []
    for j in range(1,min(len(dp),k)+1):
        l.append(dp[i-j] + abs(h[i]-h[i-j]))
    dp.append(min(l))
print(dp[n-1])
### BUGGY CODE ###

import math
import bisect

N, K = map(int, input().split())
leng = list(map(int, input().split()))
leng.sort()
cut = [0] * N
# A = [maruta(a, 0) for a in A_tmp]
for a in range(K):
    new_cut = cut.pop() + 1
    new_leng = leng.pop() * (new_cut / (new_cut + 1))
    idx = bisect.bisect_left(leng, new_leng)
    leng.insert(idx, new_leng)
    cut.insert(idx, new_cut)
    # print(new_leng, new_cut)
print(math.ceil(leng[-1]))


### FIXED CODE ###

import math

def check(d):
    cut_num = 0
    for i in leng:
        cut_num += math.ceil(i / d) - 1
    if cut_num <= K:
        return True
    return False


N, K = map(int, input().split())
leng = list(map(int, input().split()))

d_min = 0
d_max = max(leng)
d = math.ceil(d_max / 2)

while d_max - d_min > 1:
    if check(d):
        d_max = d
        d = math.ceil((d_max + d_min) / 2)
    else:
        d_min = d
        d = int((d_max + d_min) / 2)
    # print(d, d_max, d_min)

print(d_max)
### BUGGY CODE ###

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
target = [list(map(int, input().split())) for i in range(M)]

'''
4 4
1 3
2 2
1 1
2 4


'''
A.sort()
#print(A)
for t in target:
    #print(t)
    for i, e in enumerate(A[0:t[0]]):
        if e < t[1]:
            A[i] = t[1]
            #print(i)
            #print(e)
        else:
            break
    A.sort()
#print(A)
print(sum(A))


### FIXED CODE ###

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
target = [list(map(int, input().split())) for i in range(M)]
target = sorted(target, key = lambda x:x[1], reverse=True)
# print(target)

'''
4 4
1 3
2 2
1 1
2 4


'''


for t in target:
    A.extend([t[1]] * t[0])
    if len(A) > N * 2:
        break
A.sort(reverse=True)

print(sum(A[:N]))
### BUGGY CODE ###

h, w = (int(i) for i in input().split()) 
s = []

for i in range(h):
  tmp = input()
  s.append(tmp)

#左にいくつあるか
l = [[0 for i in range(w)] for j in range(h)]

for i in range(h):
  for j in range(w):
    if s[i][j] == "#":
      l[i][j] = 0
    else:
      if j == 0:
        l[i][j] = 1
        continue
      l[i][j] = l[i][j-1] + 1
#print(l)
      
#上
d = [[0 for i in range(w)] for j in range(h)]

for j in range(w):
  for i in range(h):
    if s[i][j] == "#":
      d[i][j] = 0
    else:
      if i == 0:
        d[i][j] = 1
        continue
      d[i][j] = d[i-1][j] + 1  
#print(d)      

#右にいくつあるか
r = [[0 for i in range(w)] for j in range(h)]

for i in range(h):
  for j in range(w)[::-1]:
#    print(i,j)
    if s[i][j] == "#":
      r[i][j] = 0
    else:
      if j == w-1:
#        print("aa")
        r[i][j] = 1
        continue
      r[i][j] = r[i][j+1] + 1
      
#print(r)

#下
u = [[0 for i in range(w)] for j in range(h)]

for j in range(w):
  for i in range(h)[::-1]:
    if s[i][j] == "#":
      u[i][j] = 0
    else:
      if i == h-1:
        u[i][j] = 1
        continue
      u[i][j] = u[i+1][j] + 1

#print(u)


#足し合わせ
for i in range(h):
  for j in range(w):
    l[i][j] += r[i][j] + u[i][j] + d[i][j] -3

   
import numpy as np
l = np.array(l)
#print(l)
print(l.max())

### FIXED CODE ###

h, w = (int(i) for i in input().split()) 
s = []

for i in range(h):
  tmp = input()
  s.append(tmp)

#左にいくつあるか
l = [[0 for i in range(w)] for j in range(h)]

for i in range(h):
  for j in range(w):
    if s[i][j] == "#":
      l[i][j] = 0
    else:
      if j == 0:
        l[i][j] = 1
        continue
      l[i][j] = l[i][j-1] + 1
#print(l)
      
#上
d = [[0 for i in range(w)] for j in range(h)]

for j in range(w):
  for i in range(h):
    if s[i][j] == "#":
      d[i][j] = 0
    else:
      if i == 0:
        d[i][j] = 1
        continue
      d[i][j] = d[i-1][j] + 1  
#print(d)      

#右にいくつあるか
r = [[0 for i in range(w)] for j in range(h)]

for i in range(h):
  for j in range(w)[::-1]:
#    print(i,j)
    if s[i][j] == "#":
      r[i][j] = 0
    else:
      if j == w-1:
#        print("aa")
        r[i][j] = 1
        continue
      r[i][j] = r[i][j+1] + 1
      
#print(r)

#下
u = [[0 for i in range(w)] for j in range(h)]

for j in range(w):
  for i in range(h)[::-1]:
    if s[i][j] == "#":
      u[i][j] = 0
    else:
      if i == h-1:
        u[i][j] = 1
        continue
      u[i][j] = u[i+1][j] + 1

#print(u)


#足し合わせ
for i in range(h):
  for j in range(w):
    l[i][j] += r[i][j] + u[i][j] + d[i][j] -3

unko = []
for i in range(h):
  mm = max(l[i])
  unko.append(mm)

print(max(unko))
### BUGGY CODE ###

# -*- coding: utf-8 -*-

import sys
import os

N = 50001
lst = [True] * N
lst[0] = False
lst[1] = False
for i in range(2, int(N ** 0.5) + 1):
    if lst[i]:
        for j in range(2, N):
            index = i * j
            if index < N:
                lst[i * j] = False
print('len', len(lst))

for s in sys.stdin:
    n = int(s)
    if n == 0:
        break

    if n % 2 == 1:
        if lst[n - 2]:
            print(1)
        else:
            print(0)
    elif n == 4:
        print(1)
    else:
        counter = 0
        for i in range(1, n // 2 + 1, 2):
            prime0 = i
            prime1 = n - i
            if prime0 <= prime1 and lst[prime0] and lst[prime1]:
                #print(prime0, prime1)
                counter += 1
        print(counter)

### FIXED CODE ###

import sys

N = 50001
lst = [True] * N
lst[0] = False
lst[1] = False
for i in range(2, int(N ** 0.5) + 1):
    if lst[i]:
        for j in range(i * i, N, i):
            lst[j] = False

primes = [i for i in range(1, N) if lst[i]]

for s in sys.stdin:
    n = int(s)
    if n == 0:
        break
    elif n % 2 == 1:
        if lst[n - 2]:
            print(1)
        else:
            print(0)
    elif n == 4:
        print(1)
    else:
        counter = 0
        for prime0 in primes:
            prime1 = n - prime0
            if prime0 <= prime1 and lst[prime1]:
                #print(prime0, prime1)
                counter += 1
        print(counter)
### BUGGY CODE ###

H,W,M = [int(x) for x in input().split()]
hw = []
hNum = [0]*H
wNum = [0]*W

for i in range(M):
    h,w = [int(x) for x in input().split()]
    hw.append([h,w])
    hNum[h-1]+=1
    wNum[w-1]+=1

hmax = max(hNum)
hMaxList = []
wmax = max(wNum)
wMaxList = []

for i in range(H):
    if(hmax == hNum[i]):
        hMaxList.append(i)
for i in range(W):
    if(wmax == wNum[i]):
        wMaxList.append(i)

ans = wmax + hmax
for w in wMaxList:
    for h in hMaxList:
        for k in hw:
            if(not([h+1,w+1] in hw)):
                print(ans)
                exit()
print(ans -1)


### FIXED CODE ###

H,W,M = [int(x) for x in input().split()]
hw = []
hNum = [0]*H
wNum = [0]*W

for i in range(M):
    h,w = [int(x) for x in input().split()]
    hw.append([h,w])
    hNum[h-1]+=1
    wNum[w-1]+=1

hmax = max(hNum)
hMaxList = []
wmax = max(wNum)
wMaxList = []

for i in range(H):
    if(hmax == hNum[i]):
        hMaxList.append(i)
for i in range(W):
    if(wmax == wNum[i]):
        wMaxList.append(i)

ans = wmax + hmax
count = 0
for i in hw:
    if(hNum[i[0]-1] == hmax and wNum[i[1]-1] == wmax):
        count += 1
if(hNum.count(hmax) * wNum.count(wmax) == count):
    ans -= 1
print(ans)