Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.root=[-1]*n
        self.rank=[-1]*n

    def Find_Root(self,x):
        if self.root[x]<0:return x
        else:
            self.root[x]=self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self,x,y):
        x=self.Find_Root(x)
        y=self.Find_Root(y)

        if x==y:return
        elif self.rank[x]>self.rank[y]:
            self.root[x] +=self.root[y]
            self.root[y]=x
        else:
            self.root[y] +=self.root[x]
            self.root[x]=y
            if self.rank[x]==self.rank[y]:
                self.rank[y] +=1

    def isSameGroup(self,x,y):
        return self.Find_Root(x)==self.Find_Root(y)

    def Count(self,x):
        return -self.root[self.Find_Root(x)]

    def members(self,x):
        root=self.Find_Root(x)
        return [i for i in range(self.n) if self.Find_Root(i)==root]

    def address(self):
        return[i for i,j in enumerate(self.root) if j<0]

    def group_members(self):
        return {i:len(self.members(i)) for i in self.address()}


n,m=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(m)]
UnionFind=UnionFind(n)
count=[]

for a,b in AB[::-1]:
    cnt,point=0,0
    for i in UnionFind.group_members().values():
        point +=i*(n-i-cnt)
        cnt +=i
    count.append(point)
    UnionFind.Unite(a-1,b-1)

for i in count[::-1]:
    print(i)

Fixed submission:
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.root=[-1]*n
        self.rank=[-1]*n

    def Find_Root(self,x):
        if self.root[x]<0:return x
        else:
            self.root[x]=self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self,x,y):
        x=self.Find_Root(x)
        y=self.Find_Root(y)

        if x==y:return
        elif self.rank[x]>self.rank[y]:
            self.root[x] +=self.root[y]
            self.root[y]=x
        else:
            self.root[y] +=self.root[x]
            self.root[x]=y
            if self.rank[x]==self.rank[y]:
                self.rank[y] +=1

    def isSameGroup(self,x,y):
        return self.Find_Root(x)==self.Find_Root(y)

    def Count(self,x):
        return -self.root[self.Find_Root(x)]

    def members(self,x):
        root=self.Find_Root(x)
        return [i for i in range(self.n) if self.Find_Root(i)==root]

    def address(self):
        return[i for i,j in enumerate(self.root) if j<0]

    def group_members(self):
        return {i:self.members(i) for i in self.address()}

    def size(self,x):
        return -self.root[self.Find_Root(x)]

    def same(self,x,y):
        return self.Find_Root(x)==self.Find_Root(y)


n,m=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(m)]
UnionFind=UnionFind(n)
N=n*(n-1)//2
count=[N]

for a,b in AB[::-1]:
    if UnionFind.same(a-1,b-1):
        count.append(count[-1])
    else:
        s,t=UnionFind.size(a-1),UnionFind.size(b-1)
        count.append(count[-1]-s*t)
    UnionFind.Unite(a-1,b-1)

for i in count[::-1][1:]:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
AB=[list(map(int,input().split())) for i in range(n)]

flag=1
A,B=0,0
for i in range(n):
    if flag==1:
        AB=sorted(AB, key=lambda x:x[0])
        A +=AB.pop()[0]
        flag *=-1
    else:
        AB=sorted(AB, key=lambda x:x[1])
        B +=AB.pop()[1]
        flag *=-1

print(A-B)

Fixed submission:
n=int(input())
AB=[list(map(int,input().split())) for _ in range(n)]

A,B=[],[]
for i,j in AB:
    A.append(i+j)
    B.append(-j)

ans=sum(B)
A=sorted(A)[::-1]
for i in range(0,n,2):
    ans +=A[i]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def LCS(X,Y):
    m,n=len(X),len(Y)
    MAP=[[0 for i in range(m)] for j in range(n)]
    for i in range(1,n):
        for j in range(1,m):
            if Y[i]==X[j]:
                MAP[i][j]=MAP[i-1][j-1]+1
            else:
                MAP[i][j]=max(MAP[i][j-1],MAP[i-1][j])

    i,j=n-1,m-1
    ans=""
    while MAP[i][j]!=0:
        if MAP[i][j]==MAP[i-1][j]:i -=1
        elif MAP[i][j]==MAP[i][j-1]:j -=1
        else:
            ans +=Y[i]
            i -=1
            j -=1
    return ans[::-1]


print(LCS(" "+input()," "+input()))

Fixed submission:
def LCS(X,Y):
    m,n=len(X),len(Y)
    MAP=[[0 for i in range(m)] for j in range(n)]
    for i in range(1,n):
        for j in range(1,m):
            if Y[i]==X[j]:
                MAP[i][j]=MAP[i-1][j-1]+1
            else:
                MAP[i][j]=max(MAP[i][j-1],MAP[i-1][j])

    i,j=n-1,m-1
    ans=""
    while MAP[i][j]!=0:
        if MAP[i][j]==MAP[i-1][j]:i -=1
        elif MAP[i][j]==MAP[i][j-1]:j -=1
        else:
            ans +=Y[i]
            i -=1
            j -=1
    return ans[::-1]

print(LCS(" "+input()," "+input()))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
def LCS(X,Y):
    m,n=len(X),len(Y)
    MAP=[[0 for i in range(m)] for j in range(n)]
    for i in range(1,n):
        for j in range(1,m):
            if Y[i]==X[j]:
                MAP[i][j]=MAP[i-1][j-1]+1
            else:
                MAP[i][j]=max(MAP[i][j-1],MAP[i-1][j])

    i,j=n-1,m-1
    ans=""
    while MAP[i][j]!=0:
        if MAP[i-1][j]!=MAP[i][j] and MAP[i][j-1]!=MAP[i][j]:
            ans +=Y[i]
            i -=1
            j -=1
        elif MAP[i-1][j]!=MAP[i][j] and MAP[i][j-1]==MAP[i][j]:
            j -=1
        elif MAP[i-1][j]==MAP[i][j] and MAP[i][j-1]!=MAP[i][j]:
            i -=1
        else:
            i -=1
    return ans[::-1]


print(LCS(" "+input()," "+input()))

Fixed submission:
def LCS(X,Y):
    m,n=len(X),len(Y)
    MAP=[[0 for i in range(m)] for j in range(n)]
    for i in range(1,n):
        for j in range(1,m):
            if Y[i]==X[j]:
                MAP[i][j]=MAP[i-1][j-1]+1
            else:
                MAP[i][j]=max(MAP[i][j-1],MAP[i-1][j])

    i,j=n-1,m-1
    ans=""
    while MAP[i][j]!=0:
        if MAP[i][j]==MAP[i-1][j]:i -=1
        elif MAP[i][j]==MAP[i][j-1]:j -=1
        else:
            ans +=Y[i]
            i -=1
            j -=1
    return ans[::-1]

print(LCS(" "+input()," "+input()))
Buggy python submission (verdict: Runtime Error):
from collections import deque
n=int(input())
A=deque(sorted([int(input()) for i in range(n)]))
B=deque([A.popleft()])

flag,ans=1,0
while len(A)!=0:
    if flag==1:L,R=A.pop(),A.pop()
    else:L,R=A.popleft(),A.popleft()

    if abs(L-B[0])+abs(R-B[-1])>abs(L-B[-1])+abs(R-B[0]):
        ans +=abs(L-B[0])+abs(R-B[-1])
        B.append(R)
        B.appendleft(L)
    else:
        ans +=abs(R-B[0])+abs(L-B[-1])
        B.append(L)
        B.appendleft(R)

    if len(A)==1:
        ans +=max(abs(B[0]-A[0]),abs(B[-1]-A[0]))
        break

    flag=flag*-1

print(ans)

Fixed submission:
n=int(input())
a=[int(input())for _ in range(n)]
if n==2:print(abs(a[0]-a[1]));exit()
f=[-1]
for i in range(1,n-1-(n%2==0)):
  if i%2:f.append(2)
  else:f.append(-2)
if n%2:f+=[-1]
else:f+=[-2,1]
b=[]
c=[]
for i in f:
  b.append(i)
  c.append(-i)
b.sort()
c.sort()
sb=sc=0
a.sort()
for i in range(n):
  sb+=a[i]*b[i]
  sc+=a[i]*c[i]
print(max(sb,sc))

Buggy python submission (verdict: Runtime Error):
from collections import deque
n=int(input())
A=deque(sorted([int(input()) for i in range(n)]))
B=deque([A.popleft()])

flag,ans=1,0
while len(A)!=0:
    if flag==1:L,R=A.pop(),A.pop()
    else:L,R=A.popleft(),A.popleft()

    if abs(L-B[0])>abs(R-B[-1]):
        ans +=abs(L-B[0])+abs(R-B[-1])
        B.append(R)
        B.appendleft(L)
    else:
        ans +=abs(R-B[0])+abs(L-B[-1])
        B.append(L)
        B.appendleft(R)

    if len(A)==1:
        ans +=max(abs(B[0]-A[0]),abs(B[-1]-A[0]))
        break

    flag=flag*-1

print(ans)

Fixed submission:
n=int(input())
a=[int(input())for _ in range(n)]
if n==2:print(abs(a[0]-a[1]));exit()
f=[-1]
for i in range(1,n-1-(n%2==0)):
  if i%2:f.append(2)
  else:f.append(-2)
if n%2:f+=[-1]
else:f+=[-2,1]
b=[]
c=[]
for i in f:
  b.append(i)
  c.append(-i)
b.sort()
c.sort()
sb=sc=0
a.sort()
for i in range(n):
  sb+=a[i]*b[i]
  sc+=a[i]*c[i]
print(max(sb,sc))

Buggy python submission (verdict: Runtime Error):
from collections import deque
n=int(input())
A=deque(sorted([int(input()) for i in range(n)]))
B=deque([A.popleft()])

flag,ans=1,0
while len(A)!=0:
    if flag==1:L,R=A.pop(),A.pop()
    elif flag==-1:L,R=A.popleft(),A.popleft()

    if abs(L-B[0])>abs(R-B[-1]):
        ans +=abs(L-B[0])+abs(R-B[-1])
        B.append(R)
        B.appendleft(L)
    else:
        ans +=abs(R-B[0])+abs(L-B[-1])
        B.append(L)
        B.appendleft(R)

    if len(A)==1:
        ans +=max(abs(B[0]-A[0]),abs(B[-1]-A[0]))
        break

    flag=flag*-1

print(ans)

Fixed submission:
n=int(input())
a=[int(input())for _ in range(n)]
if n==2:print(abs(a[0]-a[1]));exit()
f=[-1]
for i in range(1,n-1-(n%2==0)):
  if i%2:f.append(2)
  else:f.append(-2)
if n%2:f+=[-1]
else:f+=[-2,1]
b=[]
c=[]
for i in f:
  b.append(i)
  c.append(-i)
b.sort()
c.sort()
sb=sc=0
a.sort()
for i in range(n):
  sb+=a[i]*b[i]
  sc+=a[i]*c[i]
print(max(sb,sc))
Buggy python submission (verdict: Runtime Error):
from fractions import gcd


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


n,m=map(int,input().split())
s,t=input(),input()
lcm=lcm(n,m)

if s[::(lcm/m)]!=t[::(lcm/n)]:
    print(-1);exit()

print(lcm)

Fixed submission:
from fractions import gcd


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


n,m=map(int,input().split())
s=input()
t=input()
lcm=lcm(n,m)
S=[(i,int(i*(lcm/n)+1)) for i in range(n)]
L=[(i,int(i*(lcm/m)+1)) for i in range(m)]
left,right=0,0
ans=[]
while left!=n and right!=m:
    if S[left][1]==L[right][1]:
        ans.append([S[left][0],L[right][0]])
        right +=1
        left +=1
    elif S[left][1]>L[right][1]:
        right +=1
    elif S[left][1]<L[right][1]:
        left +=1
for l,r in ans:
    if s[l]==t[r]:continue
    else:print(-1);exit()
print(lcm)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
for i in reversed(range(m//n+1)):
    if m%i==0:print(i);break

Fixed submission:
N, M = map(int, input().split())

ans = 1
for i in range(1,int(M ** 0.5) + 1):
    if M % i == 0:
        if i >= N:
            ans = max(ans, M // i)
        if M // i >= N:
            ans = max(ans, i)
print(int(ans))

Buggy python submission (verdict: Runtime Error):
import math
def get_primenumber(number):
    prime_list = []
    search_list = list(range(2,number+1))
    while True:
      if search_list[0] > math.sqrt(number):
        prime_list.extend(search_list)
        break
      else:
        head_num = search_list[0]
        prime_list.append(head_num)
        search_list.pop(0)
        search_list = [num for num in search_list if num % head_num != 0]
    return prime_list


n,m=map(int,input().split())
A=get_primenumber(m//n)
ans=2
for i in A:
    if m%i==0:ans=i
print(ans if m%n!=0 else m//n)

Fixed submission:
N, M = map(int, input().split())

ans = 1
for i in range(1,int(M ** 0.5) + 1):
    if M % i == 0:
        if i >= N:
            ans = max(ans, M // i)
        if M // i >= N:
            ans = max(ans, i)
print(int(ans))
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(h)]

B=[]
for i in range(h):
    flag=1 if i%2==0 else -1
    for j in range(w)[::flag]:
        if A[i][j]%2==1:
            if 0<=j+flag<w:
                B.append([i,j,i,j+flag])
                A[i][j+flag] +=1
            else:
                B.append([i,j,i+1,j])
                A[i+1][j] +=1

print(len(B))
for i in B:
    print(*list(map(lambda x:x+1,i)))

Fixed submission:
h,w=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(h)]

C=[]
for i in range(h):
    flag=1 if i%2==0 else -1
    for j in range(w)[::flag]:
        if A[i][j]%2==1:
            if 0<=j+flag<w:
                C.append([i+1,j+1,i+1,j+flag+1])
                A[i][j+flag] +=1
            elif 0<=i+1<h:
                C.append([i+1,j+1,i+2,j+1])
                A[i+1][j] +=1

print(len(C))
for i in C:print(*i)

Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(h)]

C=[]
for i in range(h):
    flag=1 if i%2==0 else -1
    for j in range(w)[::flag]:
        if A[i][j]%2==1:
            if 0<=j+flag<w:
                C.append([i,j,i,j+flag])
                A[i][j+flag] +=1
            else:
                C.append([i,j,i+1,j])
                A[i+1][j] +=1
print(len(C))
for i in C:print(*i)

Fixed submission:
h,w=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(h)]

C=[]
for i in range(h):
    flag=1 if i%2==0 else -1
    for j in range(w)[::flag]:
        if A[i][j]%2==1:
            if 0<=j+flag<w:
                C.append([i+1,j+1,i+1,j+flag+1])
                A[i][j+flag] +=1
            elif 0<=i+1<h:
                C.append([i+1,j+1,i+2,j+1])
                A[i+1][j] +=1

print(len(C))
for i in C:print(*i)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
box=[]
for i in range(1,101):
    if i%11==0 or i%4==0 or i%7==0:
        box.append(i)

for i in box:
    if i+4 not in box:
        box.append(i+4)
    if i+7 not in box:
        box.append(i+7)
    if i+11 not in box:
        box.append(i+11)
        
print("Yes" if n in box else "No")

Fixed submission:
n=int(input())
for i in range(n//7+1):
    for j in range(n//4+1):
        if 7*i+4*j==n:
            print("Yes")
            exit()
print("No")
Buggy python submission (verdict: Runtime Error):
n=input()
box=[int(input())-1 for i in range(int(n))]
print(sum(box))

Fixed submission:
n=int(input())
s=list(map(int,input().split()))
print(sum(s)-n)

Buggy python submission (verdict: Runtime Error):
import math
n=int(input())
box=list(map(int,input().split()))
count=box[0]

for i in range(1,n):
    count=(box[i]*count)//math.gcd(box[i],count)

point=0
count -=1
for i in box:point +=count%i

print(point)

Fixed submission:
n=int(input())
s=list(map(int,input().split()))
print(sum(s)-n)

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce
n=int(input())
box=list(map(int,input().split()))

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

def lcm_list(numbers):
    return reduce(lcm_base,numbers,1)

point=0
count=lcm_list(box)-1
for i in box:
    point +=count%i

print(point)

Fixed submission:
n=int(input())
s=list(map(int,input().split()))
print(sum(s)-n)
Buggy python submission (verdict: Runtime Error):
import statistics
n=int(input())
box=list(map(int,input().split()))
box_another=sorted(list(y-(x+1) for x,y in enumerate(box)))
median=int(statistics.median(box_another))
count=0
for x,y in enumerate(box):
    count +=abs(y-(x+1+median))
print(count)

Fixed submission:
import statistics
n=int(input())
box=list(map(int,input().split()))
box_another=sorted(list(y-(x+1) for x,y in enumerate(box)))
median=int(statistics.median(box_another))
count=0
for x,y in enumerate(box):
    count +=abs(y-(x+1+median))
print(count)

Buggy python submission (verdict: Runtime Error):
import statistics
n=int(input())
box=list(map(int,input().split()))
box_m=sorted(list(y-(x+1) for x,y in enumerate(box)))
median=int(statistics.median(box_m))
count=0
for x,y in enumerate(box):
    count += abs(y-(median+x+1))
print(count)

Fixed submission:
import statistics
n=int(input())
box=list(map(int,input().split()))
box_another=sorted(list(y-(x+1) for x,y in enumerate(box)))
median=int(statistics.median(box_another))
count=0
for x,y in enumerate(box):
    count +=abs(y-(x+1+median))
print(count)

Buggy python submission (verdict: Runtime Error):
import statistics
n=int(input())
box=list(map(int,input().split()))
box_m=sorted(list(y-(x+1) for x,y in enumerate(box)))
median=int(statistics.median(box_m))
count=0
for x,y in enumerate(box):
    count +=abs(y-(median+x+1))
print(count)

Fixed submission:
import statistics
n=int(input())
box=list(map(int,input().split()))
box_another=sorted(list(y-(x+1) for x,y in enumerate(box)))
median=int(statistics.median(box_another))
count=0
for x,y in enumerate(box):
    count +=abs(y-(x+1+median))
print(count)

Buggy python submission (verdict: Runtime Error):
import statistics
n=int(input())
box=list(map(int,input().split()))
box_m=sorted([y-(x+1) for x,y in enumerate(box)])
median=int(statistics.median(box_m))
count=0
for x,y in enumerate(box):
    count +=abs(y-(median+x+1))
print(count)

Fixed submission:
import statistics
n=int(input())
box=list(map(int,input().split()))
box_another=sorted(list(y-(x+1) for x,y in enumerate(box)))
median=int(statistics.median(box_another))
count=0
for x,y in enumerate(box):
    count +=abs(y-(x+1+median))
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
a=[sum(a[:i])+a[i] for i in range(len(a))]
j=0
k=2
ans=10**9

for i in range(1,n-1):
    while abs(a[j]*2-a[i])>abs(a[j+1]*2-a[i]):
        j+=1
    while abs(a[k]*2-a[i]-a[n-1])>abs(a[k+1]*2-a[i]-a[n-1]):
        k+=1
    t=[a[j],a[i]-a[j],a[k]-a[i],a[n-1]-a[k]]
    ans=min(ans,max(t)-min(t))
print(ans)

Fixed submission:
n=int(input())
a=[int(i) for i in input().split()]

for i in range(n-1):
    a[i+1]+=a[i]

j=0
k=2
ans=10**9

for i in range(1,n-1):
    while abs(a[j]*2-a[i])>abs(a[j+1]*2-a[i]):
        j+=1
    while abs(a[k]*2-a[i]-a[n-1])>abs(a[k+1]*2-a[i]-a[n-1]):
        k+=1
    t=[a[j],a[i]-a[j],a[k]-a[i],a[n-1]-a[k]]
    ans=min(ans,max(t)-min(t))
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
box=list([map(int,input().split())] for i in range(n))
ans = 0
for i in (1,-1):
    for j in (1,-1):
        for k in (1,-1):
            cost=sorted(list(i*x+j*y+z*k for x,y,z in box))
            ans=max(ans,sum(cost[-m:]))
print(ans)

Fixed submission:
n,m=map(int,input().split())
box=list(list(map(int,input().split())) for i in range(n))
ans = 0
for i in (1,-1):
    for j in (1,-1):
        for k in (1,-1):
            cost=list(i*x+j*y+z*k for x,y,z in box)
            cost.sort(reverse=True)
            ans=max(ans,sum(cost[:m]))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
K=int(input())
length=len(s)

word=[]
for i in range(26):
    t=chr(97+i)
    for j,k in enumerate(s):
        if t==k:
            add=j
            while add<length:
                w="".join(s[j:add+1])
                if w not in word:
                    word.append(w)
                add +=1
    if len(word)>K:break

print(sorted(word)[K-1])

Fixed submission:
s=list(input())
words=[]
for i in range(len(s)):words.append("".join(s[i:]))
words=sorted(words)

record=[]
k=int(input())
for i in words:
    for j in range(len(i)):
        if "".join(i[:j+1]) not in record:
            record.append("".join(i[:j+1]))
    if len(record)>=k:
        print(record[k-1])
        exit()
Buggy python submission (verdict: Runtime Error):
n=int(input())
x=[map(int,input().split())]
y=sorted(x)
xr,xl=y[n//2],y[n//2-1]
for i in x:
    print(xr if i<=xl else xl)

Fixed submission:
n=int(input())
x=list(map(int,input().split()))
y=sorted(x)
xr,xl=y[n//2],y[n//2-1]
for i in x:
    print(xr if i<=xl else xl)

Buggy python submission (verdict: Runtime Error):
n=int(input())
x=[map(int,input().split())]
y=sorted(x)
xr,xl=y[n//2],y[n//2-1]
for i in x:print(xr if i<=xl else xl)

Fixed submission:
n=int(input())
x=list(map(int,input().split()))
y=sorted(x)
xr,xl=y[n//2],y[n//2-1]
for i in x:
    print(xr if i<=xl else xl)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
n=int(input())
box=list(map(int,input().split()))
box_sort=sorted(box)
for i in box:
    ano_box=copy.copy(box_sort)
    ano_box.remove(i)
    print(ano_box[n//2-1])

Fixed submission:
n=int(input())
x=list(map(int,input().split()))
y=sorted(x)
xr,xl=y[n//2],y[n//2-1]
for i in x:
    print(xr if i<=xl else xl)
Buggy python submission (verdict: Time Limit Exceeded):
import copy
n=int(input())
box=list(map(int,input().split()))
for i in range(n):
    box_ano=copy.copy(box)
    del box_ano[i]
    count=abs(box_ano[0])+abs(box_ano[-1])
    for j in range(len(box_ano)):
        try:
            count +=abs(box_ano[j]-box_ano[j+1])
        except:continue
    print(count)

Fixed submission:
import copy
n=int(input())
box=list(map(int,input().split()))
box.insert(0,0)
box.append(0)
count=0
for i in range(n+1):count +=abs(box[i]-box[i+1])
for j in range(1,n+1):
    print(count-(abs(box[j-1]-box[j])+abs(box[j]-box[j+1]))+abs(box[j-1]-box[j+1]))
Buggy python submission (verdict: Runtime Error):
import numpy as np
h,q=map(int,input().split())
#動きの確認code,0が裏,1を表
"""
box=[["*"]+["1"]*h+["*"] for i in range(q)]
box.insert(0,["*"]*(h+2))
box.append(["*"]*(h+2))
print(np.array(box))
for i in range(1,q+1):
    for j in range(1,h+1):
        try:
            seat=[[0,0],[0,1],[0,-1],[1,0],[1,1],[1,-1],[-1,0],[-1,1],[-1,-1]]
            for x,y in seat:
                xx=i+x
                yy=j+y
                if box[xx][yy]=="1":
                    box[xx][yy]="0"
                elif box[xx][yy]=="0":
                    box[xx][yy]="1"
                elif box[xx][yy]=="*":continue
        except:continue
print(np.array(box))
"""
if h==2 or q==2:print(0)
elif h==1 or q==1:
    if h!=1:print((h-2)*1)
    elif q!=1:print((q-2)*1)
    else:print(1)
else:
    print((h-2)*(q-2))

Fixed submission:
h,q=map(int,input().split())

if h==2 or q==2:print(0)
elif h==1 or q==1:
    if h!=1:print((h-2)*1)
    elif q!=1:print((q-2)*1)
    else:print(1)
else:
    print((h-2)*(q-2))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())

print(0)
zero=input()
if zero=="Vacant":exit()

left,right=0,n
while left<right:
    mid=(left+right)//2
    print(mid)
    ans=input()
    if ans=="Vacant":exit()

    if (ans==zero and mid%2==1) or (ans!=zero and mid%2==0):left=mid+1
    else:right=mid

Fixed submission:
n=int(input())

print(0)
zero=input()
if zero=="Vacant":exit()

left,right=0,n
while left<right:
    mid=(left+right)//2
    print(mid)
    ans=input()
    if ans=="Vacant":exit()

    if (ans==zero and mid%2==1) or (ans!=zero and mid%2==0):right=mid+1
    else:left=mid

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())

print(0)
zero=input()
if zero=="Vacant":exit()

left,right=0,n
while left+1<right:
    mid=(left+right)//2
    print(mid)
    ans=input()
    if ans=="Vacant":exit()

    if (ans==zero and mid%2==1) or (ans!=zero and mid%2==0):left=mid
    else:right=mid

Fixed submission:
n=int(input())

print(0)
zero=input()
if zero=="Vacant":exit()

left,right=0,n
while left<right:
    mid=(left+right)//2
    print(mid)
    ans=input()
    if ans=="Vacant":exit()

    if (ans==zero and mid%2==1) or (ans!=zero and mid%2==0):right=mid+1
    else:left=mid
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())

for n in range(1,3501):
    for h in range(1,3501):
        up,down=N*n*h,4*h*n-N*(h+n)
        if down!=0:
            if up%down==0 and up//down>0:
                print(h,n,(N*n*h)//(4*n*h-N*(h+n)))
                exit()

Fixed submission:
N=int(input())

for n in range(1,3501):
    for h in range(1,3501):
        up,down=N*n*h,4*h*n-N*(h+n)
        if down!=0:
            if up%down==0 and up//down>0:
                print(h,n,(N*n*h)//(4*n*h-N*(h+n)))
                exit()