problem_id
stringclasses
428 values
submission_id
stringlengths
10
10
status
stringclasses
2 values
code
stringlengths
5
816
p03804
s486839897
Accepted
N, M = map(int, input().split()) A = [input() for a in range(N)] B = [input() for b in range(M)] ans = False for h in range(N - M + 1): for w in range(N - M + 1): if ans == True: break for m in range(M): if A[h + m][w:w + M] == B[m]: pass else: ...
p03721
s330630319
Accepted
N,K = map(int,input().split()) ls = [list(map(int,input().split())) for _ in range(N)] ls.sort(key=lambda x: x[0]) s = 0 for i in range(N): s += ls[i][1] if s >= K: break print(ls[i][0])
p03665
s091785117
Accepted
N,P = map(int,input().split()) A = list(map(int,input().split())) odd = 0 for v in A: if v % 2: odd += 1 even = N-odd if odd != 0: print((2**even)*int(2**(odd-1))) else: if P == 0: print(2**N) else: print(0)
p02630
s083813624
Accepted
from collections import defaultdict from typing import DefaultDict from collections import defaultdict N = int(input()) A = [int(i) for i in input().split()] di_A = defaultdict(int) for a in A: di_A[a] += 1 Q = int(input()) now_sum = sum(A) ans = [] for _ in range(Q): b, c = [int(i) for i in input().split(...
p03720
s293523221
Accepted
n,m = map(int,input().split()) lst = [[] for i in range(n)] for _ in range(m): a,b = map(int,input().split()) lst[a-1].append(b-1) lst[b-1].append(a-1) for v in lst: print(len(v))
p03785
s989127767
Wrong Answer
n,C,T=map(int,input().split()) t=[int(input()) for i in range(n)] t.sort() res=t[0]+T cnt=1 ans=0 for i in range(n): if t[i]<=res and cnt<C: cnt+=1 elif t[i]>res or cnt==C: ans+=1 res=t[i]+T cnt=1 print(ans+1)
p04033
s379177142
Accepted
a, b = map(int, input().split()) if a <= 0 <= b: print("Zero") elif b < 0 and (b - a) % 2 == 0: print("Negative") else: print("Positive")
p02792
s769340791
Accepted
#D import math import numpy as np n = int(input()) num = np.zeros((10, 10)) for i in range(1, n + 1): a = i // pow(10, (int(math.log10(i)))) b = i % 10 num[b][a] += 1 ans=0 for i in range(10): for j in range(10): ans += num[i][j] * num[j][i] print(int(ans))
p03127
s973961787
Accepted
n = int(input()) a = list(map(int, input().split())) i = 0 while i < n-1: x = a[i+1] % a[i] a[i+1] = a[i] a[i] = x if a[i] == 0: i += 1 print(a[i])
p03339
s968645451
Wrong Answer
n=int(input()) s=list(input()) sw=[0] se=[0] swc=0 sec=0 for i in range(n): if s[i]=='W': swc+=1 else: sec+=1 sw.append(swc) se.append(sec) m=n for i in range(n): m=min(m,sw[i]+se[-1]-se[i]) print(m)
p02696
s438363563
Wrong Answer
a, b, n = map(int, input().split()) cand = [] def calc(n): return int(a*n/b)-a*int(n/b) cand.append(calc(0)) cand.append(calc(n)) cand.append(calc(n-1)) cand.append(max(0, calc(b*(n//b) - 1))) cand.append(max(0, calc(b*(n//b) - 2))) cand.append(calc(min(n, b-1))) cand.append(calc(min(n, b-2))) print(max(cand))
p02996
s971170858
Accepted
n = int(input()) ab = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[1]) t = 0 for a,b in ab: t += a if t > b: print("No") exit() print("Yes")
p02552
s867213813
Accepted
import sys def input(): return sys.stdin.readline()[:-1] def main(): x = int(input()) if x == 1: print(0) else: print(1) if __name__ == "__main__": main()
p03695
s702715658
Wrong Answer
import sys input = sys.stdin.readline def main(): scores = [i*400 for i in range(1, 8)] scores.reverse() scores_d = {} input() god = [] for a in map(int,input().split()): if a >= 3200: god.append(a) for i in scores: if a >= i: scores_d[i]...
p03672
s491912132
Accepted
import sys from collections import Counter from collections import deque def input(): return sys.stdin.readline().strip() def mp(): return map(int,input().split()) def lmp(): return list(map(int,input().split())) s=input() s=s[:-1] while len(s)>0: if s[:len(s)//2]==s[len(s)//2:]: print(len(s)) exit...
p02719
s146714254
Accepted
N,K=map(int,input().split()) x=N%K if x<=K/2: print(x) else: print(K-x)
p02993
s641386645
Accepted
s = input() print('Bad' if any(s[i] == s[i+1] for i in range(3)) else 'Good')
p03673
s379388064
Wrong Answer
N = int(input()) A = list(map(int, input().split())) mae = [] usiro = [] #0の時に前 1の時に後ろ Flag = 0 for i in reversed(range(0,N,1)): if Flag == 0: # 前の時 mae.append(str(A[i])) Flag = 1 else: usiro.insert(0,str(A[i])) Flag = 0 moziretu = (mae + usiro) moziretu = ''.join(mozire...
p03544
s567657667
Accepted
l=[2,1] n=int(input()) i=0 while i!=n: l.append(l[i]+l[i+1]) i+=1 print(l[n])
p02628
s405963063
Accepted
n,m = map(int,input().split()) l = list(map(int,input().split())) l.sort() a=0 for i in range(m): a+=l[i] print(a)
p03437
s369041083
Accepted
x, y = map(int, input().split()) if x % y == 0: print(-1) else: print(x)
p03284
s058590280
Accepted
n,k=map(int,input().split()) print(0 if n%k==0 else 1)
p02711
s983320669
Accepted
n = input() if '7' in n: print('Yes') else: print('No')
p02723
s135024978
Accepted
S = input() print('Yes' if S[2] == S[3] and S[4] == S[5] else 'No')
p02791
s193576462
Wrong Answer
n = int(input()) p = list(map(int,input().split())) miss = 0 max = p[0] for i in range(1,n): #s = p[0:i] #if not s: # continue if p[i] > p[i-1]: miss += 1 continue if max < p[i]: max = p[i] if p[i] > max: miss += 1 continue #s = sorted(s,reverse=Tr...
p02996
s833998554
Accepted
from operator import itemgetter N = int(input()) T = [] for _ in range(N): T.append(tuple(map(int, input().split()))) T.sort(key=itemgetter(1)) A = [i[0] for i in T] B = [i[1] for i in T] sum = 0 for i in range(N): sum += A[i] if sum > B[i]: print('No') exit() print('Yes')
p03637
s040518041
Wrong Answer
n = int(input()) arr = list(map(int, input().split())) num_4_multi = len(arr) // 2 cnt4 = len([i for i in arr if i % 4 == 0]) cnt2 = len([i for i in arr if i % 2 == 0]) cnt8 = len([i for i in arr if i % 8 == 0]) cnt = cnt2 - cnt4 + cnt8 if len(arr) % 2 == 0: cnt += arr.count(2) // 2 else: cnt += arr.count(2) / ...
p03698
s606519681
Accepted
s = input() print('yes' if len(set(s)) == len(s) else 'no')
p03761
s180970046
Accepted
from collections import Counter n = int(input()) l = [{} for _ in range(n)] for i in range(n): l[i] = Counter(input()) for i in range(26): w = chr(ord("a") + i) c = 51 for j in range(n): c = min(c, l[j][w]) print(w * c, end = "") print()
p02743
s609950598
Wrong Answer
import math a, b, c = map(lambda x: math.sqrt(x), map(int, input().split())) if a + b - c < 0: print('Yes') else: print('No')
p02831
s019487027
Accepted
from fractions import gcd def lcm(a, b): return a * b // gcd(a, b) def solve(): a, b = list(map(int, input().split())) print(lcm(a, b)) if __name__ == "__main__": solve()
p03038
s126682050
Wrong Answer
n,m=map(int,input().split()) a=sorted(list(map(int,input().split()))) l=[list(map(int,input().split())) for i in range(m)] x=[] x_l=0 for b,c in l: x+=[c]*b x_l+=b if x_l>n: break x=sorted(x,reverse=True) ans=0 for i in range(n): if i<x_l: ans+=max(a[i],x[i]) else: ans+=a[i] print(ans)
p03852
s335737600
Accepted
from collections import defaultdict,deque import math def main(): s = input() v = ["a","i","u","e","o"] if(s in v): print("vowel") else: print("consonant") if __name__ == '__main__': main()
p03625
s201141070
Accepted
from collections import defaultdict n = int(input()) d = defaultdict(int) nums = [] for num in input().split(): num = int(num) d[num] += 1 # 同じ長さの棒が4本ある場合に対応するためこのような方法をとる if d[num] == 2: d.pop(num) nums.append(num) nums = sorted(nums) if len(nums) >= 2: print(nums[-1] * nums[-2]) ...
p02663
s975191117
Accepted
A,B,C,D,E = map(int,input().split()) print(max(0,-60*A-B+(60*C+D))-E)
p02909
s521110063
Accepted
S=input() if S=='Sunny': print('Cloudy') elif S=='Cloudy': print('Rainy') else: print('Sunny')
p03545
s789875333
Accepted
S = input() N = len(S) - 1 for i in range(2**N): num = int(S[0]) op = ["+","+","+",] for j in range(N): if i >> j & 1: op[-1-j] = "-" num -= int(S[-1-j]) else: num += int(S[-1-j]) if num == 7: print(S[0],op[0],S[1],op[1],S[2],op...
p03852
s261537821
Wrong Answer
c=str(input()) if c=='a' or 'e' or 'i' or 'o' or 'u': print('vowel') else:print('consonant')
p02971
s668593276
Wrong Answer
N = int(input()) A = [int(input()) for i in range(N)] sorted_A = list(reversed(sorted(A))) maxiuam = sorted_A[0] is_there_tow_maximum = A.count(maxiuam) >= 2 if is_there_tow_maximum: answer = (str(maxiuam) + "\n") * N print(answer) second = None for Ai in sorted_A: if Ai < maxiuam: second = Ai ...
p03103
s480770751
Accepted
N,M = map(int,input().split()) k = [] now = 0 ans = 0 for i in range(N): a,b = map(int,input().split()) k.append([a,b]) k.sort() for i in range(N): if (now+k[i][1])<M: ans += k[i][0]*k[i][1] now += k[i][1] else: ans += k[i][0]*(M-now) print(ans) break
p03282
s596275091
Accepted
s = input() k = int(input()) if k == 1: print(int(s[0])) elif s[0] == "1": cnt = 0 while cnt < len(s) and s[cnt] == "1" : cnt += 1 if cnt >= k: print(1) elif cnt == len(s): print("1") else: print(s[cnt]) else: print(int(s[0]))
p02645
s715205293
Wrong Answer
S = str(input()) print(S[0:2])
p03944
s593504206
Accepted
import numpy as np W, H, N = map(int, input().split()) g = np.zeros((H, W)) for i in range(N): x, y, a = map(int, input().split()) if a == 1: g[:, :x] = 1 elif a == 2: g[:, x:] = 1 elif a == 3: g[abs(H-y):, :] = 1 else: g[:abs(H-y), :] = 1 print(np.count_nonzero(g =...
p02702
s494424302
Accepted
n = input() countArray = [0] * 2019 count = 0 countArray[0] += 1 nums=0 for i in range(len(n))[::-1]: nums = nums + int(n[len(n)-1-i])*pow(10,i,2019) countArray[nums%2019]+=1 for i in countArray: count += (i * (i - 1)) // 2 print(count)
p04044
s586500762
Wrong Answer
N,L = map(int,input().split()) li = [] for i in range(N): li.append("".join(sorted(input()))) li.sort() print("".join(li))
p02640
s639639590
Accepted
import sys sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): X, Y = [int(x) for x in input().split()] for i in range(101): for j in range(101): if i + j == X and (i * 2 + j * 4 == Y or i * 4 + j * 2 == Y): print("Yes") return prin...
p03679
s437564975
Wrong Answer
x, a, b = map(int, input().split()) if a <= b: print('delicious') elif b - a >= x + 1: print('dangerous') else: print('safe')
p02860
s434994057
Accepted
S=int(input()) T=input() S=int(S) print('Yes' if T[:S//2]==T[S//2:] else 'No')
p02742
s583055021
Accepted
h, w = map(int, input().split()) if h == 1 or w == 1: print(1) elif h*w % 2 == 0: print(int(h*w/2)) else: print(int(h*w//2) + 1)
p02859
s367681473
Accepted
import math r = int(input()) pi = int(math.pi) a = (pi * (r)**2) ans = a / pi print(int(ans))
p03478
s101850417
Accepted
N,A,B = map(int, input().split()) print(sum(i for i in range(1,N+1) if A<=sum(map(int, str(i)))<=B))
p03854
s542068655
Wrong Answer
data = ['dream','dreamer','erase','eraser'] word = input() for i in data: while i in word: word = word.replace(i,"") if word == "": print("YES") else : print("NO")
p02910
s995593920
Wrong Answer
S = input() l = ['L', 'R', 'U', 'D'] ans='Yes' for i, s in enumerate(S): if i+1 % 2 == 0: if s not in ['L', 'U', 'D']: ans='No' break elif i+1 % 2 != 0: if s not in ['R', 'U', 'D']: ans='No' break print(ans)
p04005
s797461355
Accepted
cubic = list(map(int, input().split())) sort_cubic = sorted(cubic, reverse=True) a = sort_cubic[0] b = sort_cubic[1] c = sort_cubic[2] red = (a // 2 ) * b * c blue = (a - a//2) * b * c print(abs(red - blue))
p03043
s260880805
Accepted
N,K=map(int,input().split()) P=[1] for k in range(17): P.append(P[-1]/2) Q=0 for i in range(1,N+1): u=0 x=i while x<K: u+=1 x*=2 Q+=P[u] print(Q/N)
p02995
s459843921
Accepted
import math A,B,C,D=map(int,input().split()) g=(C*D)//math.gcd(C,D) print((B-A+1)-(B//C--(-A//C)+1)-(B//D--(-A//D)+1)+(B//g--(-A//g)+1))
p02583
s964612702
Wrong Answer
N=int(input()) import itertools A = list(map(int, input().split())) count=0 if len(A)<=2: print(0) else: for t in itertools.combinations(A, 3): if t[2]<t[0]+t[1] and t[1]<t[0]+t[2] and t[0]<t[1]+t[2] and t[0]!=t[1]!=t[2]!=t[0]: print(t) count+=1 print(count)
p03665
s819517448
Accepted
def main(): N, P = (int(i) for i in input().split()) A = [int(i) % 2 for i in input().split()] from collections import Counter c = Counter(A) ans = 0 if P == 0: ans = 2**c[0] if c[1]: ans *= 2**(c[1]-1) else: if c[1]: ans = 2**(c[1]-1) ...
p02678
s874512908
Wrong Answer
print('No')
p02933
s762150326
Wrong Answer
S = int(input()) T = input() if 2800 <= S > 3200: print("red") else: print(T)
p02897
s824237331
Wrong Answer
N = int(input()) if N % 2 == 0: print((N/2-1)/(N/2)) else: print(0.5)
p02993
s306160780
Wrong Answer
s = input() for i in range(3): if s[i] == s[i+1]: print('Bad') break print('Good')
p03545
s662605662
Wrong Answer
s=input() op=['+', '-'] for op1 in op: for op2 in op: for op3 in op: tmp=s[0]+op1+s[1]+op2+s[2]+op3+s[3] if eval(tmp)==7: print(tmp) break
p03282
s854615382
Accepted
s = input() k = int(input()) - 1 for i in range(len(s)): if s[i] != "1" or i == k: break print(s[i])
p03076
s705365126
Accepted
# Problem B - Five Dishes import itertools import math # input process cost_list = [] for i in range(5): cost_list.append(int(input())) # initialization min_ans = 1000 # count process perm_list = list(itertools.permutations(cost_list)) for p in perm_list: p = list(p) # cost calc tmp = 0 for i in...
p03264
s679796335
Accepted
n = int(input()) print((n//2)**2) if n%2 == 0 else print((n//2) * (n//2+1))
p02615
s822209395
Wrong Answer
N = int(input()) a = list(map(int,input().split())) # print(N,a) a_sort = sorted(a, reverse=True) a_sum = a_sort[0] if N-2 % 2 == 0: for i in range((N-2)/2): a_sum += 2*a_sort[i+1] else: for i in range((N-2)//2): a_sum += 2*a_sort[i+1] print(a_sum)
p03106
s962403481
Wrong Answer
a,b,k=map(int,input().split()) d=[] for i in range(1,100): if a%i==0 and b%i==0: d.append(i) print(d[-1*k])
p03105
s514708020
Wrong Answer
a,b,c = map(int,input().split()) if a*c < b: print(int(c)) if a*c > b: print(int(b/a)) else: print(0)
p02726
s900491032
Accepted
n,x,y=map(int,input().split()) ans=[0]*(n-1) for i in range(1,n): for j in range(i+1,1+n): d=min(j-i,abs(x-i)+abs(y-j)+1) ans[d-1]+=1 for i in ans: print(i)
p02829
s651601181
Wrong Answer
a = int(input()) b = int(input()) print(a, b) ans = [c for c in range(1, 4) if c not in [a, b]] for i in ans: print(i)
p02873
s340059294
Wrong Answer
import collections s = list(input()) s_count = collections.Counter(s) max_s = max(s_count[">"], s_count["<"]) ans = sum(range(1, max_s + 1)) print(ans)
p02646
s597295851
Accepted
a,v=map(int,input().split()) b,w=map(int,input().split()) t=int(input()) print('YES' if abs(a-b)<=t*(v-w) else 'NO')
p04031
s725480159
Accepted
n = int(input()) AS = list(map(int,input().split())) cost = float('inf') for i in range(min(AS),max(AS)+1): c = 0 for a in AS: c += (i-a)**2 if c < cost: cost = c print(cost)
p03838
s774006409
Wrong Answer
x, y = map(int, input().split()) x_, y_ = x, y ans = 0 def sign(n): if n == 0: return 0 else: return int(n / abs(n)) if abs(x) > abs(y): if x > 0: x_ = -x_ ans += 1 else: if x < 0: x_ = -x_ ans += 1 ans += abs(abs(x) - abs(y)) if sign(x_) != sign(y): ...
p03371
s185077536
Wrong Answer
S = input().split(" ") A = int(S[0]) B = int(S[1]) C = int(S[2]) X = int(S[3]) Y = int(S[4]) def calculate(a,b,c,x,y): s1 = a * x + b * y base = min([x,y]) values = [s1] for i in range(base): index = (i + 1) tmp = s1 - (A + B) * index + 2 * C * index values.append(tmp) ...
p03673
s267763358
Wrong Answer
import numpy as np n = int(input()) a = [int(i) for i in input().split()] begin = a[0::2] end = a[1::2] if n%2 == 0: end = end[:-1] ans = end+begin else: begin = begin[::-1] ans = begin+end Ans = '' for i in range(len(ans)): if i == len(ans)-1: Ans = Ans + str(ans[i]) else: ...
p03472
s065206382
Accepted
N, H = map(int, input().split()) A = [0]*N B = [0]*N for i in range(N): A[i], B[i] = map(int, input().split()) A.sort() B.sort() max_a = A[-1] ans = 0 b_i = len(B) - 1 while H > 0: b = B[b_i] if b <= max_a: break H -= b ans += 1 b_i -= 1 if b_i < 0: break if H <= 0: pri...
p02615
s360245853
Accepted
#abc173d n=int(input()) l=list(map(int,input().split())) l.sort(reverse=True) res=0 for i in range(1,n): res+=l[i//2] print(res)
p03633
s678428459
Accepted
def lcm(a): import math x = a[0] for i in range(1, len(a)): x = (x * a[i]) // math.gcd(x, a[i]) return x def resolve(): N = int(input()) T = [int(input()) for _ in range(N)] print(lcm(T)) resolve()
p02963
s213247781
Accepted
s = int(input()) v = 1000000000 x = (v-s%v)%v y = (s+x)//v print(0, 0, 1000000000, 1, x, y)
p02795
s148184943
Accepted
h, w, n = map(int, [input() for _ in range(3)]) print((n-1)//max(h, w)+1)
p02972
s554075274
Wrong Answer
N, *A = map(int, open(0).read().split()) A = [0] + A B = [0] * (N + 1) sum_B = 0 for i in range(N, 0, -1): if sum(B[j] for j in range(i, N + 1, i)) != A[i]: B[i] = 1 sum_B += 1 print(sum_B) print(*[i for i, b in enumerate(B) if b])
p03633
s823019091
Accepted
from fractions import gcd def lcm(m, n): return (m * n) // gcd(m, n) def lcm_list(a): x = a[0] for i in range(1, len(a)): x = (x * a[i]) // gcd(x, a[i]) return x N = int(input()) T = [int(input()) for _ in range(N)] print(lcm_list(T))
p02594
s866902967
Accepted
x = int(input()) if x>= 30: print('Yes') else: print('No')
p03103
s706437265
Accepted
N, M = map(int, input().split()) pAc = [list(map(int, input().split())) for _ in range(N)] pAc.sort() count = 0 price = 0 for p,c in pAc: if count + c >= M: print(price+(M-count)*p) exit() count += c price += p*c
p03379
s756153882
Wrong Answer
N = int(input()) X = list(map(int, input().split())) A = sorted(X) mid = A[N//2] for x in X: if x == mid: print(A[N//2-1]) else: print(mid)
p02862
s598450008
Accepted
X,Y=map(int,input().split()) mod=10**9+7 MAX=X+Y+1 fac=[1,1] inv_t=[0,1] finv=[1,1] for i in range(2,MAX): fac.append(fac[-1]*i%mod) inv_t += [inv_t[mod % i] * (mod - mod // i) % mod] finv.append(finv[i-1]*inv_t[i]%mod) x=2*X-Y y=2*Y-X if x%3!=0 or y%3!=0 or x*y<0: print(0) else: x=x//3 y=y//...
p04033
s911443321
Wrong Answer
if __name__ == '__main__': a = [int(i) for i in input().split()] b = 1 if a[0]<= 0 and a[1]>=0: b=0 elif b<0: c = abs(a-b) if c %2 ==1: b=-1 if b >0: print("Positive") elif b ==0: print("Zero") else: print("Negative")
p02779
s368345780
Accepted
n = int(input()) a = list(map(int, input().split())) if n == len(set(a)): print("YES") else: print("NO")
p02777
s497453817
Accepted
S,T=input().split() A,B=map(int,input().split()) U=input() if U == S: print(A-1,B) elif U == T: print(A,B-1)
p03485
s040629426
Accepted
def resolve(): a, b = map(int,input().split()) x = (a+b) / 2 if x % 1 == 0: print(int(x)) else: print(int(x)+1) resolve()
p04033
s452527486
Accepted
a,b = map(int,input().split()) if a > 0: print('Positive') else: if b >= 0: print('Zero') else: if (b-a) % 2 == 0: print('Negative') else: print('Positive')
p02695
s331261915
Wrong Answer
n,m,s=map(int,input().split()) a=[] q=[[0]] while q: x=q.pop() if len(x)<=n: for j in range(x[-1],m+1): c=x+[j] q.append(c) else: a.append(x) li=[tuple(map(int,input().split())) for _ in range(s)] ans=0 for A in a: s=0 for i,j,k,l in li: if A[j]-A[i]==k: s+=l ans=max(ans,s) p...
p02729
s425620923
Accepted
nCr = {} def cmb(n, r): if n == 0: return 0 if r == 0 or r == n: return 1 if r == 1: return n if (n,r) in nCr: return nCr[(n,r)] nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1) return nCr[(n,r)] s = input().split() print(cmb(int(s[0]),2) + cmb(int(s[1]),2))
p02699
s464912174
Wrong Answer
S,W = input ().split() if S>W: print("safe") else: print("unsafe")
p03481
s694967703
Accepted
x, y = map(int, input().split()) ans = 0 while (x <= y): x *= 2 ans += 1 print(ans)
p02571
s705656982
Wrong Answer
S = input() T = input() len_T = len(T) len_S = len(S) output = len_T for i in range(len_S-len_T): diff = 0 for j in range(len_T): if T[j] != S[i+j]: diff += 1 output = min(output, diff) print('output',output)
p03862
s116455029
Accepted
N,x=map(int,input().split()) a=list(map(int,input().split())) cnt=0 for i in range(N-1): l=a[i]+a[i+1] if(l>x): cnt+=l-x if(a[i+1]>=l-x): a[i+1]-=l-x else: a[i+1]=0 print(cnt)
p03419
s182737471
Wrong Answer
N, M = map(int, input().split()) ans = (N - 2) * (M - 2) print(ans)