Harryxun/stf_run huggingface dataset:
N,X,M=map(int,input().split())
t=[]
t.append(X)
temp=X
ans=X
for i in range(10**5+100):
    temp=temp**2%M
    if temp in t:
        firstindex=t.index(temp)
        currentindex=len(t)
        firstsum=0
        for i in range(firstindex-1):
            firstsum+=t[i]
        repeatsum=0
        for i in range(firstindex,currentindex):
            repeatsum+=t[i]
        repetition=(n-firstindex)//(currentindex-firstindex)
        lastrep=        (n-firstindex)%(currentindex-firstindex)
        lastsum=0
        for i in range(firstindex,firstindex+lastrep):
            lastsum+=t[i]

    else:
        t.append(temp)
    

print(firstsum+repetition*repeatsum+lastsum)


### FIXED CODE ###

N,X,M=map(int,input().split())
t=[]
t.append(X)
temp=X
ans=X
for i in range(10**5+100):
    temp=temp**2%M
    if temp in t:
        firstindex=t.index(temp)
        currentindex=len(t)
        firstsum=0
        for i in range(firstindex):
            firstsum+=t[i]
        repeatsum=0
        for i in range(firstindex,currentindex):
            repeatsum+=t[i]
        repetition=(N-firstindex)//(currentindex-firstindex)
        lastrep=        (N-firstindex)%(currentindex-firstindex)
        lastsum=0
        for i in range(firstindex,firstindex+lastrep):
            lastsum+=t[i]
        print(firstsum+repetition*repeatsum+lastsum)
        exit()

    else:
        t.append(temp)
N, L = map(int, input().split())
for _ in range(N):
    tmp += L
    L += 1
if tmp == 0:
    print(0)
elif tmp > 0:
    if L=< 0:
        print(tmp)
    else:
        print(tmp-L)
else:
    if N > L:
        print(tmp)
    else:
        print(tmp-(N+L-1))
        

### FIXED CODE ###

N, L = map(int, input().split())
tmp = 0
i = L
for _ in range(N):
    tmp += i
    i += 1
if tmp == 0:
    print(0)
elif tmp > 0:
    if L < 1:
        print(tmp)
    else:
        print(tmp-L)
else:
    if N+L == 0:
        print(tmp+1)
    elif N + L > 0:
        print(tmp)
    else:
        print(tmp - N - L + 1)
import math
A, B = input()
A = int(A)
B = float(B)
print(math.floor(A*B))

### FIXED CODE ###

def multiply(num1, num2): 
    len1 = len(num1) 
    len2 = len(num2) 
    if len1 == 0 or len2 == 0: 
        return "0"
  
    # will keep the result number in vector 
    # in reverse order 
    result = [0] * (len1 + len2) 
      
    # Below two indexes are used to  
    # find positions in result. 
    i_n1 = 0
    i_n2 = 0
  
    # Go from right to left in num1 
    for i in range(len1 - 1, -1, -1): 
        carry = 0
        n1 = ord(num1[i]) - 48
  
        # To shift position to left after every 
        # multiplication of a digit in num2 
        i_n2 = 0
  
        # Go from right to left in num2 
        for j in range(len2 - 1, -1, -1): 
              
            # Take current digit of second number 
            n2 = ord(num2[j]) - 48
          
            # Multiply with current digit of first number 
            # and add result to previously stored result 
            # at current position. 
            summ = n1 * n2 + result[i_n1 + i_n2] + carry 
  
            # Carry for next iteration 
            carry = summ // 10
  
            # Store result 
            result[i_n1 + i_n2] = summ % 10
  
            i_n2 += 1
  
            # store carry in next cell 
        if (carry > 0): 
            result[i_n1 + i_n2] += carry 
  
            # To shift position to left after every 
            # multiplication of a digit in num1. 
        i_n1 += 1
          
        # print(result) 
  
    # ignore '0's from the right 
    i = len(result) - 1
    while (i >= 0 and result[i] == 0): 
        i -= 1
  
    # If all were '0's - means either both or 
    # one of num1 or num2 were '0' 
    if (i == -1): 
        return "0"
  
    # generate the result string 
    s = "" 
    while (i >= 0): 
        s += chr(result[i] + 48) 
        i -= 1
  
    return s 
  
# Driver code 
str1, str2 = input().split()
str2 = str2.replace(".", "")
# print(str1)
# print(str2)
if((str1[0] == '-' or str2[0] == '-') and 
   (str1[0] != '-' or str2[0] != '-')): 
    print("-", end = '') 
  
  
if(str1[0] == '-' and str2[0] != '-'): 
    str1 = str1[1:] 
elif(str1[0] != '-' and str2[0] == '-'): 
    str2 = str2[1:] 
elif(str1[0] == '-' and str2[0] == '-'): 
    str1 = str1[1:] 
    str2 = str2[1:]
res = multiply(str1, str2)
if len(res)>2:
    print(multiply(str1, str2)[:-2]) 
else:
    print(0)
N, X = (int(_) for _ in input().split())
L = list(map(int, input().split()))
D = 0
ans = 0
while (D < X or ans < N):
    D = D + L[ans]
    ans += 1
if D == X:
    print(ans)
else:
    print(ans - 1)

### FIXED CODE ###

N, X = (int(_) for _ in input().split())
L = list(map(int, input().split()))
D = [0 for i in range(N + 1)]
ans = 0
for i in range(N):
    D[i + 1]= D[i] + L[i]
for i in range(N + 1):
    if D[i] <= X:
        ans += 1
print(ans)
N, M = map(int,input().split())
s = [0]*M
c = [0]*M

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

ans = [0]*N
if N != 1:
    ans[0] = 1
error = 0

assign = [0]*M
for i in range(M):
    assign[s[i]- 1] += 1

    if assign[s[i] - 1] > 1 and ans[s[i] - 1] != c[i]:
        error += 1

    ans[s[i] - 1] = c[i]
    


if ans[0] == 0 and N != 1:
    error += 1 

if error == 0:
    for i in range(N):
        print(ans[i], end = "")
    print()
else:
    print(-1)


### FIXED CODE ###

N, M = map(int,input().split())
s = [0]*M
c = [0]*M

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

ans = [0]*N
if N != 1:
    ans[0] = 1
error = 0

assign = [0]*N
for i in range(M):
    assign[s[i]- 1] += 1

    if assign[s[i] - 1] > 1 and ans[s[i] - 1] != c[i]:
        error += 1

    ans[s[i] - 1] = c[i]
    


if ans[0] == 0 and N != 1:
    error += 1 

if error == 0:
    for i in range(N):
        print(ans[i], end = "")
    print()
else:
    print(-1)
N=int(input())
lamps=[]
for a in range(N):
    _=int(input())
    lamps.append(_)

if lamps.count(2)==0:
    print("-1")
    exit()

# no2=[i for i , x in enumerate(lamps) if x==2]
PressedButton=[]

num=2
while lamps[0]!=num:
    a=lamps.index(num)
    if PressedButton.count(a)==0:
        PressedButton.append(a)
        num=a
    else:
        print("-1")
        exit()
print(PressedButton)

### FIXED CODE ###

N=int(input())
lamps=[]
for a in range(N):
    _=int(input())
    lamps.append(_)
lamps.insert(0,"aaa")

PressedButtons=[False]*int(N+1)

a=1
count=0

if lamps.count(2)==0:
    print("-1")
    exit()

while PressedButtons[a]==False :
    PressedButtons[a]=True
    count+=1
    a=lamps[a]
    if a==2:
        print(count)
        exit()
print('-1')
def searchAokiGetCard(xi, A):
    Adistance = list(map(lambda ai: abs(ai-xi), A))
    Adismin = min(Adistance)
    geta = xi - Adismin
    if geta not in A:
        geta = xi + Adismin
    A.remove(geta)
    return A


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

X = []
for i in range(Q):
    X.append(int(input()))

A.sort()
for xi in X:
    sum = 0
    A = Aorig.copy()
    for _ in A:
        At = A.pop()
        sum = sum + At
        if A != []:
            A = searchAokiGetCard(xi, A)

    if A != []:
        print(sum + max(A))
    else:
        print(sum)

### FIXED CODE ###

N = int(input())
H = int(input())
W = int(input())

print((N-H+1)*(N-W+1))
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
# odd = []
# even = []
# for i in range(len(v)):
#     if(i % 2 == 0):
#         even.append(v[i])
#     else:
#         odd.append(v[i])
odd = v[::2]
even = v[1::2]

c_even = Counter(even).most_common(2)
c_odd = Counter(odd).most_common(2)


if(c_even[0][0] != c_odd[0][0]):
    print(n - c_even[0][1] - c_odd[0][1])
elif(len(c_even) != 1 and len(c_odd) != 1):
    second = max[c_even[1][1], c_odd[1][1]]
    print(n - c_even[0][1] - second)
else:
    print(min([c_even[0][1], c_odd[0][1]]))

### FIXED CODE ###

from collections import Counter
    
n = int(input())
v = list(map(int, input().split()))
odd = v[::2]
even = v[1::2]
    
c_even = Counter(even).most_common(2)
c_odd = Counter(odd).most_common(2)

    
if(c_even[0][0] != c_odd[0][0]):
    print(n - c_even[0][1] - c_odd[0][1])
else:
    if(len(c_even) == 1):
        print(n//2)
    else:
        # second = max[c_even[1][1], c_odd[1][1]]
        # print(n - c_even[0][1] - second)
        print(n - max(c_even[0][1] + c_odd[1][1], c_even[1][1] + c_odd[0][1]))
h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]

def calc(s):
    res = []
    for v in s:
        v.append('-')
        tmp = []
        nc = ''
        nn = 0
        for c in v:
            if nc == '':
                nc = c
                nn += 1
                continue
            if nc == c:
                nn += 1
                continue
            else:
                if nc == '#':
                	tmp.extend([0 for _ in range(nn)])
                else:
                	tmp.extend( [nn for _ in range(nn)])
        res.append(tmp)
    return res

def calc2(s):
    res = []
    for j in range(w):
        tmp = []
        nc = ''
        nn = 0
        for i in range(h+1):
            if i == h:
                c = '-'
            else:
                c = s[i][j]
            if nc == '':
                nc = c
                nn += 1
                continue
            if nc == c:
                nn += 1
                continue
            else:
                if nc == '#':
                	tmp.extend([0 for _ in range(nn)])
            	else:
                	tmp.extend( [nn for _ in range(nn)])
                nc = c
                nn = 1
        res.append(tmp)
    return res

tate = calc2(S)
yoko = calc(S)
print(max([tate[j][i] + yoko[i][j] for i in range(h) for j in range(w) if tate[j][i] * yoko[i][j] != 0]) - 1)


### FIXED CODE ###

h, w = map(int, input().split())
S = [input() for _ in range(h)]

def calc(s):
    res = []
    for v in s:
        v = v + '-'
        tmp = []
        nc = v[0]
        nn = 0
        for c in v:
            if nc == c:
                nn += 1
                continue
            else:
                if nc == '#':
                    tmp.extend([0 for _ in range(nn)])
                else:
                    tmp.extend( [nn for _ in range(nn)])
                nc = c
                nn = 1
        res.append(tmp)
    return res

def calc2(s):
    res = []
    for j in range(w):
        tmp = []
        nc = s[0][j]
        nn = 0
        for i in range(h):
            c = s[i][j]
            if nc == c:
                nn += 1
                continue
            else:
                if nc == '#':
                    tmp.extend([0 for _ in range(nn)])
                else:
                    tmp.extend( [nn for _ in range(nn)])
                nc = c
                nn = 1
        if nc == '#':
            tmp.extend([0 for _ in range(nn)])
        else:
            tmp.extend( [nn for _ in range(nn)])
        res.append(tmp)
    return res

tate = calc2(S)
yoko = calc(S)

print(max([tate[j][i] + yoko[i][j] for i in range(h) for j in range(w) if tate[j][i] * yoko[i][j] != 0]) - 1)
n=int(input())
li = [int(input()) for _ in range(n)]  # li = ['hoge', 'bar', 'foo']

m = li.sort()[0]
ans = 0
if n % m == 0:
    ans += n//m
else:
    ans += n//m + 1
ans += 4
print(ans)

### FIXED CODE ###

n=int(input())
li = [int(input()) for _ in range(5)]  # li = ['hoge', 'bar', 'foo']

li.sort()
m = li[0]
ans = 0
if n % m == 0:
    ans += n//m
else:
    ans += n//m + 1
ans += 4
print(ans)
N=int(input())
pages=N // 2
if N % 2==0:
  else:
    pages=pages+1
print(pages)

### FIXED CODE ###

N=int(input())
pages=N // 2
if N % 2==0:
        pass
else:
    pages=pages+1
print(pages)
n,k=map(int,input().split())
s=list(input())
s[k-1]=s[k-1].lower()
print("".join())

### FIXED CODE ###

n,k=map(int,input().split())
s=list(input())
s[k-1]=s[k-1].lower()
print("".join(s))
n = int(input())
d = int(input())
p = 10**9+7
DP = {}
DP[-1] = [0]*d
DP[0] = [0]*d
DP[0][0] = 1
def dp(i):
    try:
        return DP[i]
    except:
        pass
    q, r = i//10, i % 10
    DP[i] = []
    for j in range(d):
        tmp = 0
        for k in range(r+1):
            tmp += dp(q)[(j-k) % d]
        for k in range(r+1, 10):
            tmp += dp(q-1)[(j-k) % d]
        DP[i].append(tmp)
    return DP[i]
print((dp(n)[0]-1) % p)


### FIXED CODE ###

n = int(input())
d = int(input())
p = 10**9+7
if d == 1:
    print(n % p)
    exit()
N = [int(i) for i in list(str(n))]
DP0 = [0] * d
DP1 = [0] * d
DP1[0] += 1
for i in N:
    DP0_ = [0] * d
    DP1_ = [0] * d
    for r in range(d):
        for j in range(i):
            DP0_[r] += DP1[(r-j) % d]
            DP1_[r] += DP1[(r-j) % d]
        DP0_[r] += DP0[(r-i) % d]
        DP1_[r] += DP1[(r-i) % d]
        for j in range(i+1, 10):
            DP0_[r] += DP0[(r-j) % d]
            DP1_[r] += DP0[(r-j) % d]
        DP0_[r], DP1_[r] = DP0_[r] % p, DP1_[r] % p
    DP0, DP1 = DP0_, DP1_
print((DP1[0]-1+p) % p)
s=input()
t=input()

dp=[[-1]*(len(t)+1) for x in range(len(s)+1)]
arr = ""
def func(i,j):
    if i>=len(s) or j>=len(t):
        return 0
    if dp[i][j]!=-1:
        return dp[i][j]
    if s[i]==t[j]:
        dp[i][j] = func(i+1,j+1)+1
        return dp[i][j]
    if s[i]!=t[j]:
        dp[i][j] = max(func(i+1,j),func(i,j+1))
        return dp[i][j]
l=func(0,0)
i,j=0,0
while len(arr)<l:
    if s[i] == t[j]:
        arr=arr+s[i]
        i+=1
        j+=1
    else:
        if dp[i+1][j]>dp[i][j+1]:
            i+=1
        else:
            j+=1

print(arr)

### FIXED CODE ###

s=input()
t=input()

dp=[[-1]*(len(t)+1) for x in range(len(s)+1)]
arr = ""
for i in range(len(s),-1,-1):
    for j in range(len(t),-1,-1):
        if i>=(len(s)) or j>=(len(t)):
            dp[i][j] = 0
        else:
            if s[i] == t[j]:
                dp[i][j] = dp[i+1][j+1] + 1
            else:
                dp[i][j] = max(dp[i+1][j],dp[i][j+1])

l=dp[0][0]
i,j=0,0
while len(arr)!=l:
    if s[i] == t[j]:
        arr=arr+s[i]
        i+=1
        j+=1
    else:
        if dp[i+1][j]>=dp[i][j+1]:
            i+=1
        else:
            j+=1

print(arr)



# def func(i,j):
    # if i>=(len(s)) or j>=(len(t)):
    #     return 0
    # if dp[i][j]!=-1:
    #     return dp[i][j]
    # if s[i]==t[j]:
    #     dp[i][j] = func(i+1,j+1)+1
    #     return dp[i][j]
    # if s[i]!=t[j]:
    #     dp[i][j] = max(func(i+1,j),func(i,j+1))
    #     return dp[i][j]
# l=func(0,0)
def main():
    import sys
    input=sys.stdin.readline   
    sys.setrecursionlimit(100000000)

    n=int(input())
    point=[tuple(map(int,input().split())) for _ in range(n)]
    dic={i:j for i,j in zip(point,range(n))}
    

    ans=10**9
    for i in range(n-1):
        for j in range(i+1,n):
            p=point[j][0]-point[i][0]
            q=point[j][1]-point[i][1]
            cnt=0
            visited=[True]*n

            def dfs(x,y,p,q):
                if (x+p,y+q) in dic:
                    idx=dic[(x+p,y+q)]
                    if visited[idx]:
                        visited[idx]=False
                        dfs(x+p,y+q,p,q)
                if (x-p,y-q) in dic:
                    idx=dic[(x-p,y-q)]
                    if visited[idx]:
                        visited[idx]=False
                        dfs(x-p,y-q,p,q)

            for k in range(n):
                if visited[k]:
                    cnt+=1
                    dfs(point[k][0],point[k][1],p,q)      

            ans=min(ans,cnt)  
    print(cnt)

if __name__=='__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    input=sys.stdin.readline   
    sys.setrecursionlimit(100000000)

    n=int(input())
    point=[tuple(map(int,input().split())) for _ in range(n)]
    dic={i:j for i,j in zip(point,range(n))}
    
    if n==1:
        print(1)
        exit()
        
    ans=10**9
    for i in range(n-1):
        for j in range(i+1,n):
            p=point[j][0]-point[i][0]
            q=point[j][1]-point[i][1]
            cnt=0
            visited=[True]*n

            def dfs(x,y):
                if (x+p,y+q) in dic:
                    idx=dic[(x+p,y+q)]
                    if visited[idx]:
                        visited[idx]=False
                        dfs(x+p,y+q)
                if (x-p,y-q) in dic:
                    idx=dic[(x-p,y-q)]
                    if visited[idx]:
                        visited[idx]=False
                        dfs(x-p,y-q)

            for k in range(n):
                if visited[k]:
                    visited[k]=False
                    cnt+=1
                    dfs(point[k][0],point[k][1])      
        
            ans=min(ans,cnt)  
    print(ans)

if __name__=='__main__':
    main()
n = int(input())
cards = [int(i) for i in input().split()]
sorted = cards.sort(reverse=True)
a = 0
b = 0
for i, num in enumerate(sorted):
    if(i % 2 == 0):
        a = a + num
    else:
        b = b + num
print a - b


### FIXED CODE ###

n = int(input())
cards = [int(i) for i in input().split()]
cards.sort(reverse=True)
a = 0
b = 0
for i, num in enumerate(cards):
    if(i % 2 == 0):
        a = a + num
    else:
        b = b + num
print(a - b)
from collections import deque

n, m = map(int, input().split())
a = [0] * m
b = [0] * m
c = [[-1] * n for i in range(n)]
lead = [0] * n
i_n = [0] * n
for i in range(m):
    a[i], b[i] = map(int, input().split())
    a[i] -= 1
    b[i] -= 1
    c[b[i]][i_n[b[i]]] = a[i]
    c[a[i]][i_n[a[i]]] = b[i]
    i_n[b[i]] += 1
    i_n[a[i]] += 1

d = deque()
d.append(0)

while len(d):
    k = len(d)
    for i in range(k):
        p = d[0]
        for j in range(n):
            if c[p][j] == -1:
                break
            if lead[c[p][j]] == 0:
                lead[c[p][j]] = p + 1
                d.append(c[p][j])
        d.popleft()

print('Yes')
for i in range(n - 1):
    print(lead[i + 1])


### FIXED CODE ###

n = int(input())
n= n %10
if n == 3:
    print('bon')
elif n == 0 or n== 1 or n==6 or n==8:
    print('pon')
else:
    print('hon')
N = input()

if N%4 == 0:
    print("Yes")
    exit()

if N%7 == 0:
    print("Yes")
    exit()

S = N%7
K = (S%4)%2

if K == 0:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

N = int(input())

if N%4 == 0:
    print("Yes")

if N%4 == 1:
    if N < 21:
        print("No")
    else:
        print("Yes")

if N%4 == 2:
    if N < 14:
        print("No")
    else:
        print("Yes")


if N%4 == 3:
    if N < 7:
        print("No")
    else:
        print("Yes")
n=int(input())
h=list(map(int,input().split()))
dp=[]
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
  dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
 print(dp[n-1])

### FIXED CODE ###

n=int(input())
h=list(map(int,input().split()))
dp=[]
dp.append(0)
dp.append(abs(h[1]-h[0]))
for i in range(2,n):
  dp.append(min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2])))
print(dp[n-1])
a=int(inpout())
b=input()
print(b if a>=3200 else "red")

### FIXED CODE ###

a=int(input())
b=input()
print(b if a>=3200 else "red")
n = int(input())
a = list(map(int, input().split()))
d = {1:0, 2:0, 4:0}
for i in a:
  if i % 4 == 0:
    d[4] += 1
  elif i % 2 == 0:
    d[2] += 1
  else:
    d[1] += 1
if d.get(2, 0) >= 1:
  d[1] += 1
if d.get(1, 0) <= d.get(4, 0)+1:
  print("Yes")
else:
  print("No")


### FIXED CODE ###

n, m = map(int, input().split())
print((n-1)*(m-1))
from heapq import heappop, heappush
mod = 10**9+7
n, k = map(int, input().split())
a = [int(x) for x in input().split()]


def sgn(x):
    if x > 0:
        return 0
    elif x < 0:
        return 1
    else:
        return 2


pl = []
mn = []
zr = []

for x in a:
    if x > 0:
        pl.append(x)
    elif x < 0:
        mn.append(-x)
    else:
        zr.append(x)

pl = sorted(pl, reverse=True)
mn = sorted(mn, reverse=True)


b = [(abs(a[i]), sgn(a[i])) for i in range(n)]
b = sorted(b, reverse=True)

c = [0, 0, 0]
for i in range(k):
    c[b[i][1]] += 1
    if c[2] > 1:
        print(0)
        exit()


def solve(c):
    ans = 1
    for i in range(c[0]):
        ans *= pl[i]
        ans %= mod
    for i in range(c[1]):
        ans *= mn[i]
        ans %= mod
    return ans


if c[1] % 2 == 0:
    print(solve(c))
elif c[0] < len(pl):
    c[0] += 1
    c[1] -= 1
    print(solve(c))
elif 0 < c[0] and c[0] == len(pl) and c[1] < len(mn):
    c[0] -= 1
    c[1] += 1
    print(solve())
elif 0 == c[0] and c[1] < len(mn):
    if len(zr) > 0:
        print(0)
        exit()
    else:
        tmp = 1
        for i in range(k):
            tmp *= mn[-i-1]
            tmp %= mod
        print((-tmp) % mod)


### FIXED CODE ###

from heapq import heappop, heappush
mod = 10**9+7
n, k = map(int, input().split())
a = [int(x) for x in input().split()]


def sgn(x):
    if x >= 0:
        return 0
    elif x < 0:
        return 1


pl = []
mn = []

for x in a:
    if x >= 0:
        pl.append(x)
    elif x < 0:
        mn.append(-x)

pl = sorted(pl, reverse=True)
mn = sorted(mn, reverse=True)


b = [(abs(a[i]), sgn(a[i])) for i in range(n)]
b = sorted(b, reverse=True)

c = [0, 0]
for i in range(k):
    c[b[i][1]] += 1


def solve(c):
    ans = 1
    for i in range(c[0]):
        ans *= pl[i]
        ans %= mod
    for i in range(c[1]):
        ans *= mn[i]
        ans %= mod
    if c[1] % 2:
        ans = (-ans) % mod
    return ans


if c[1] % 2 == 0:
    print(solve(c))
    exit()

if len(mn) == n and k % 2:
    tmp = 1
    for i in range(k):
        tmp *= mn[-i-1]
        tmp %= mod
    ans = -tmp
    print(ans % mod)
    exit()

ans = 0

chk1 = False
chk2 = False

if c[0] <= len(pl) - 1:
    chk1 = True

if 0 < c[0] and c[1] <= len(mn)-1:
    chk2 = True

if chk1 and chk2:
    tmp1 = pl[c[0]]*pl[c[0]-1]
    tmp2 = mn[c[1]]*mn[c[1]-1]
    if tmp1 > tmp2:
        c[0] += 1
        c[1] -= 1
        print(solve(c))
    else:
        c[0] -= 1
        c[1] += 1
        print(solve(c))
elif chk1:
    c[0] += 1
    c[1] -= 1
    print(solve(c))
elif chk2:
    c[0] -= 1
    c[1] += 1
    print(solve(c))
else:
    print(solve(c))
a, b = map(int,input().split())
if a == 1:
    if b==1:
    print(b)
    else:
        print(b-2)
else:
    print((a-2) * (b-2))

### FIXED CODE ###

a, b = map(int,input().split())
c = [a,b]
c.sort()
if c[0] == 1:
    if c[1]==1:
        print(1)
    else:
        print(c[1]-2)
else:
    print((c[0]-2) * (c[1]-2))
n=input()
lst=[(a,b) for a in ['S','H','C','D'] for b in range(1,14)]
for i in range(n):
    a,b =input().split()
    lst.remove((a,int(b)))
for (a,b) in lst:
    print(a,b)


### FIXED CODE ###

n=int(input())
lst=[(a,b) for a in ['S','H','C','D'] for b in range(1,14)]
for i in range(n):
    a,b = input().split()
    b = int(b)
    lst.remove((a,b))
for (a,b) in lst:
    print(a,b)
code = list(str, input().split("?"))

for i in code
   ans =ans + i
   ans =ans + "D"
   
print(ans-"D")

### FIXED CODE ###

a= input()
c=""
for i in range(0, len(a)):
    if a[i]=="?":
        c=c+"D"
    else:
        c=c+a[i]
print(c)
n, m, l = [int(i) for i in input().split()]

A = [input(range(n))]
B = [input(range(m))]
C = [[0] * 1 for n in range(n)]


for ni in range(n):
    A.append([int(i) for i in input().split()])

for mi in range(m):
    B.append([int(i) for i in input().split()])
    
C[n][m] = sum([A[n][l] * B[l][m] for l in range(l)])

print(" ".join([str(v) for v in C]))

### FIXED CODE ###

n, m, l = [int(i) for i in input().split()]

A = []
B = []
C = []

for ni in range(n):
    A.append([int(i) for i in input().split()])

for mi in range(m):
    B.append([int(i) for i in input().split()])

for i in range(n):
    C.append([])
    for j in range(l):
        C[i].append(0)
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]

for li in range(n):
    print(" ".join([str(s) for s in C[li]]))
N = input()
List = [input().split()]


ans = 10**18
def rally(p):
    n = 0
    for a in range(N):
        n += (p-List[a])**2
    return n

for i in range(1,101):
    ans = min(rally(i),ans)

print(ans)


### FIXED CODE ###

N = int(input())
List = [int(i) for i in input().split()]


ans = 10**18
def rally(p):
    n = 0
    for a in range(N):
        n += (int(p)-List[a])**2
    return n

for i in range(1,101):
    ans = min(rally(i),ans)

print(ans)
s=input()
print(s[i]-s[-7])

### FIXED CODE ###

s=input()
print(s[:-8])