CodeEff/ECCO huggingface dataset:
# Original solution
n, m, x, y = list(map(int, input().split()))
X = [int(i) for i in input().split()]
Y = [int(i) for i in input().split()]
X.append(x)
Y.append(y)

if max(X) < min(Y):
    print('No War')
else:
    print('War')

# Optimized solution
n, m, x, y = list(map(int, input().split()))
X = [int(i) for i in input().split()]
Y = [int(i) for i in input().split()]

X.append(x)
Y.append(y)

X.sort()
Y.sort()

print(('War' if max(X) >= min(Y) else 'No War'))
# Original solution
# https://beta.atcoder.jp/contests/abc110/tasks/abc110_b


def solve():
    _, _, x, y = list(map(int, input().split()))
    Xn = max(list(map(int, input().split())))
    Ym = min(list(map(int, input().split())))

    for z in range(x + 1, y + 1):
        if Xn < z <= Ym:
            print('No War')
            exit()
    else:
        print('War')


if __name__ == '__main__':
    solve()


# Optimized solution
# https://beta.atcoder.jp/contests/abc110/tasks/abc110_b


def solve():
    _, _, X, Y = list(map(int, input().split()))
    xn = max(list(map(int, input().split())))
    ym = min(list(map(int, input().split())))

    Z = xn + 1

    if X < Z <= Y and xn < Z <= ym:
        print('No War')
        exit()
    else:
        print('War')


if __name__ == '__main__':
    solve()
# Original solution
n,m,x,y=input().split()
n,m,x,y=int(n),int(m),int(x),int(y)
x1=input().split()
x2=[]
for i in range(n):
    x2.append(int(x1[i]))
y1=input().split()
y2=[]
for i in range(m):
    y2.append(int(y1[i]))

s="War"
if y>x:
    for i in range(y-x):
        if x+i+1>max(x2) and min(y2)>=x+i+1:
            s="No War"

print(s)


# Optimized solution
n,m,x,y=list(map(int,input().split()))
X=max(list(map(int,input().split())))
Y=min(list(map(int,input().split())))
for z in range(x+1,y+1):
    if X<z<=Y:
        print("No War")
        break
else:
    print("War")
# Original solution
while 1:
    n,a,b,c,x=list(map(int,input().split()))
    if n==0:break
    reel=list(map(int,input().split()))
    roop,i=-1,0
    while i<n:
        roop+=1
        if roop>10000:
            roop=-1
            break
        if x==reel[i]:
            i+=1
        x=(a*x+b)%c
    print(roop)

# Optimized solution
while True:
  N,A,B,C,X = list(map(int,input().split()))
  if N == A == B == C == X == 0:break
  sum = 0
  Z = 0
  Y = [int(x) for x in input().split()]
  if X == Y[0]:
      Y.pop(0)
      if len(Y) == 0:
          Z = 1
  while Z == 0:
      if sum == 10000:
          sum = -2
          Z = 1
      sum += 1
      X = (A*X+B)%C
      if X == Y[0]:
          Y.pop(0)
          if len(Y) == 0:
              Z = 1
  print(sum)
# Original solution
import copy
from itertools import combinations
N=int(eval(input()))
S=list(input()[0] for _ in range(N))
cS=copy.deepcopy(S)
ans=0
for i in cS:
    if i not in ['M', 'A', 'R', 'C', 'H']:
        S.remove(i)
P=list(combinations(S,3))
for i in P:
    if len(set(i))==3:
        ans+=1
print(ans)

# Optimized solution
N=int(eval(input()))
S=list(input()[0] for _ in range(N))
m=S.count('M')
a=S.count('A')
r=S.count('R')
c=S.count('C')
h=S.count('H')
print((m*a*r+m*a*c+m*a*h
      +m*r*c+m*r*h
      +m*c*h
      +a*r*c+a*r*h
      +a*c*h
      +r*c*h))
# Original solution
# ABC089C - March
from itertools import combinations


def main():
    n = int(eval(input()))
    lst = [input().rstrip() for _ in range(n)]
    cond = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
    for i in lst:
        if i[0] in "MARCH":
            cond[i[0]] += 1
    ans = 0
    for x, y, z in combinations("MARCH", 3):
        ans += cond[x] * cond[y] * cond[z]
    print(ans)


if __name__ == "__main__":
    main()

# Optimized solution
# ABC089C - March
import sys
input = sys.stdin.readline

from itertools import combinations


def main():
    n = int(eval(input()))
    lst = [input().rstrip() for _ in range(n)]
    cond = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
    for i in lst:
        if i[0] in "MARCH":
            cond[i[0]] += 1
    ans = 0
    for x, y, z in combinations("MARCH", 3):
        ans += cond[x] * cond[y] * cond[z]
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
from collections import *
d=Counter()
for _ in range(int(eval(input()))): d[input()[0]]+=1
import itertools as it
print((sum(d[s]*d[t]*d[r] for s,t,r in it.combinations('MARCH',3))))

# Optimized solution
l=[input()[0] for _ in range(int(eval(input())))]
import itertools as it
print((sum(x*y*z for x,y,z in it.combinations([l.count(c) for c in 'MARCH'],3))))
# Original solution
from itertools import combinations
n = int(eval(input()))

march = ("M","A","R","C","H")
d = []
for _ in range(n):
  pre = input()[0]
  if pre in march: d.append(pre)

if len(d) < 3:
  print((0))
  exit()

ans = 0
for i in combinations(d,3):
  if len(set(i)) == 3:
    ans += 1
print(ans)

# Optimized solution
n = int(eval(input()))

march = ("M","A","R","C","H")
prefix = []
d = {}
for _ in range(n):
  pre = input()[0]
  if pre in march:
    if pre not in prefix:
      prefix.append(pre)
      d[pre] = 1
    else:
      d[pre] += 1
      
t = len(prefix)
if t < 3:
  print((0))
  exit()

ans = 0
for i in range(t-2):
  for j in range(i+1, t-1):
    for k in range(j+1,t):
      ans += d[prefix[i]]*d[prefix[j]]*d[prefix[k]]
print(ans)
# Original solution
import sys
from collections import Counter
from itertools import combinations

MARCH = set('MARCH')

n = int(sys.stdin.readline().rstrip())
s = [x[0] for x in sys.stdin.read().split() if x[0] in MARCH]

def main():
    c = Counter(s)
    ways = 0
    for comb in combinations('MARCH', 3):
        res = 1
        for i in comb:
            res *= c.get(i, 0)
        ways += res
    
    return ways

if __name__ == '__main__':
    ans = main()
    print(ans)

# Optimized solution
import sys
from collections import Counter
from itertools import combinations

n, *s = [s[0] for s in sys.stdin.read().split()]

def main():
    c = Counter(s)
    res = 0
    for i, j, k in combinations('MARCH', 3):
        res += c[i] * c[j] * c[k]
    print(res)

if __name__ ==  '__main__':
    main()
# Original solution
import itertools as i,collections as c
b=c.Counter(s[0]for s in open(0).readlines()[1:] if s[0]in"MARCH")
print((sum(p*q*r for p,q,r in i.combinations(list(b.values()),3))))

# Optimized solution
import itertools as i,collections as c;print((sum(p*q*r for p,q,r in i.combinations(list(c.Counter(s[0]for s in open(0).readlines()[1:] if s[0]in"MARCH").values()),3))))
# Original solution
n = int(eval(input()))
m = ["M", "A", "R", "C", "H"]
s = {}
for _ in range(n):
    s_ = input()[0]
    if s_ not in m: continue
    else:
        if s_ not in list(s.keys()):
            s[s_] = 0
        s[s_] += 1
if len(list(s.keys())) <= 2:
    print((0))
    exit()
l = list(s.values())
n = len(l)
a = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            a += l[i] * l[j] * l[k]
print(a)

# Optimized solution
n = int(eval(input()))
m = "MARCH"
l = {}
cnt = 0
for _ in range(n):
    init = input()[0]
    if init not in m:
        continue
    if init not in l:
        cnt += 1
        l[init] = 0
    l[init] += 1
if cnt <= 2:
    print((0))
    exit()
l = list(l.values())
n = len(l)
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            ans += l[i] * l[j] * l[k]
print(ans)
# Original solution
import itertools
def main():
    N = int(input().strip())
    S = [input().strip() for _ in range(N)]
    MARCH_S = [x[0] for x in S if x[0] in ['M','A','R','C','H']]
    if not MARCH_S:
        return 0

    pat = list(itertools.combinations(MARCH_S, 3));
    pat_len = len(pat)
    
    for x in ['M','A','R','C','H']:
        pat_len -= len([p for p in pat if p.count(x) > 1])

    return pat_len
    
if __name__ == '__main__':
    print((main()))

# Optimized solution
import itertools
def main():
    N = int(input().strip())
    S = []
    for _ in range(N):
        in_s = (input().strip())[0]
        if in_s in ['M','A','R','C','H']:
            S.append(in_s)

    if not S:
        return 0

    pat = itertools.combinations(S, 3);
    
    count = 0
    for x in pat:
        if len(x) == len(set(x)):
            count += 1
    return count
    
if __name__ == '__main__':
    print((main()))
# Original solution
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
args = sys.argv


def dump(*objects):
    if len(args) == 2 and args[1] == "DEBUG":
        print(*objects, file=sys.stderr)

N = int(input())
S =[input() for i in range(N)]

D={'M':[],'A':[],'R':[],'C':[],'H':[]}
for Si in S:
    if Si[0] in D:
        D[Si[0]].append(Si)

dump(D)

ans=0
for x in it.combinations("MARCH", 3):
    x0,x1,x2=x
    dump(x0,x1,x2)
    ans += len(D[x0])*len(D[x1])*len(D[x2])
print(ans)


# Optimized solution
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
args = sys.argv


def dump_impl(*objects):
    print(*objects, file=sys.stderr)
def dump_dummy(*objects):
    print(*objects, file=sys.stderr)
    
dump = dump_impl if len(args) == 2 and args[1] == "DEBUG" else dump_dummy

N = int(input())
S =[input() for i in range(N)]

D={'M':[],'A':[],'R':[],'C':[],'H':[]}
for Si in S:
    if Si[0] in D:
        D[Si[0]].append(Si)

dump(D)

ans=0
for x in it.combinations("MARCH", 3):
    x0,x1,x2=x
    dump(x0,x1,x2)
    ans += len(D[x0])*len(D[x1])*len(D[x2])
print(ans)
# Original solution
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
args = sys.argv


def dump_impl(*objects):
    print(*objects, file=sys.stderr)
def dump_dummy(*objects):
    print(*objects, file=sys.stderr)
    
dump = dump_impl if len(args) == 2 and args[1] == "DEBUG" else dump_dummy

N = int(input())
S =[input() for i in range(N)]

D={'M':[],'A':[],'R':[],'C':[],'H':[]}
for Si in S:
    if Si[0] in D:
        D[Si[0]].append(Si)

dump(D)

ans=0
for x in it.combinations("MARCH", 3):
    x0,x1,x2=x
    dump(x0,x1,x2)
    ans += len(D[x0])*len(D[x1])*len(D[x2])
print(ans)


# Optimized solution
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
args = sys.argv


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if len(args) == 2 and args[1] == "DEBUG" else dump_dummy
N = int(input())
S = [input() for i in range(N)]

D = {'M': [], 'A': [], 'R': [], 'C': [], 'H': []}
for Si in S:
    if Si[0] in D:
        D[Si[0]].append(Si)

dump(D)

ans = 0
for x in it.combinations("MARCH", 3):
    x0, x1, x2 = x
    dump(x0, x1, x2)
    ans += len(D[x0])*len(D[x1])*len(D[x2])
print(ans)
# Original solution
from itertools import combinations
from collections import Counter

n = int(eval(input()))
S = Counter()
for i in range(n):
  S[input()[0]] +=  1 # Counter == dictionary
  
print((sum([S[a]*S[b]*S[c] for a, b, c in combinations("MARCH", 3)])))  

# Optimized solution
from collections import defaultdict
from itertools import combinations

N = int(eval(input()))
S = [input()[0] for _ in range(N)]
dic_S = defaultdict(int)
for s in S:
  if s in "MARCH":
    dic_S[s] += 1

ans = 0
for a, b, c in combinations(list(dic_S.values()), 3):
  ans += a*b*c
  
print(ans)
# Original solution
from itertools import combinations
from collections import Counter
N = int(eval(input()))
S = Counter()
for _ in range(N):
  S[input()[0]] += 1
print((sum([S[p0]*S[p1]*S[p2] for p0,p1,p2 in combinations('MARCH', 3)])))
quit()


# Optimized solution
from itertools import combinations
N = int(eval(input()))
d = [0]*128
for _ in range(N): d[ord(input()[0])] += 1
print((sum([d[ord(p0)]*d[ord(p1)]*d[ord(p2)] for p0,p1,p2 in combinations('MARCH', 3)])))
# Original solution
N=int(eval(input()))
name=[input()[0] for _ in range(N)]
m,a,r,c,h=name.count("M"),name.count("A"),name.count("R"),name.count("C"),name.count("H")
print((m*a*(r+c+h)+m*r*(c+h)+m*c*h+a*r*(c+h)+a*c*h+r*c*h))

# Optimized solution
N=int(eval(input()))
n=[input()[0] for _ in range(N)]
m,a,r,c,h=n.count("M"),n.count("A"),n.count("R"),n.count("C"),n.count("H")
print((m*a*(r+c+h)+m*r*(c+h)+m*c*h+a*r*(c+h)+a*c*h+r*c*h))
# Original solution
from itertools import*;d={};g=d.get
for t in open(0).read().split():d[t[0]]=g(t[0],0)+1
print((sum(g(p,0)*g(q,0)*g(r,0)for p,q,r in combinations('MARCH',3))))

# Optimized solution
from itertools import*;d=[0]*128
for t in open(0).read().split():d[ord(t[0])]+=1
print((sum(p*q*r for p,q,r in combinations([d[ord(t)]for t in'MARCH'],3))))
# Original solution
from itertools import*;d=[0]*128
for _ in[0]*int(eval(input())):d[ord(input()[0])]+=1
print((sum(p*q*r for p,q,r in combinations([d[ord(t)]for t in'MARCH'],3))))

# Optimized solution
from itertools import*;d=[0]*91
for _ in[0]*int(eval(input())):d[ord(input()[0])]+=1
print((sum(p*q*r for p,q,r in combinations([d[ord(t)]for t in'MARCH'],3))))
# Original solution
from itertools import*;d={}
for t in open(0).read().split():d[t[0]]=d.get(t[0],0)+1
print((sum(p*q*r for p,q,r in combinations([d.get(t,0)for t in'MARCH'],3))))

# Optimized solution
from itertools import*;d={};g=d.get
for t in open(0).read().split():d[t[0]]=g(t[0],0)+1
print((sum(p*q*r for p,q,r in combinations([g(t,0)for t in'MARCH'],3))))
# Original solution
import sys
from itertools import combinations
from collections import Counter
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n = int(input().rstrip())
    s = [input()[0] for _ in range(n)]
    s = [v for v in s if v in 'MARCH']
    c = Counter(s)
    ans = 0
    for x, y, z in combinations(c, 3):
        ans += c[x] * c[y] * c[z]
    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
import sys
from itertools import combinations
from collections import Counter
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n = int(input().rstrip())
    s = [input()[0] for _ in range(n)]
    c = Counter(s)
    ans = 0
    for x, y, z in combinations('MARCH', 3):
        ans += c[x] * c[y] * c[z]
    print(ans)


if __name__ == '__main__':
    main()
# Original solution
import collections
cc = collections.Counter()
for _ in range(int(input())): 
	cc[input()[0]] +=1	

def dfs(i, total ,cumul, cc, k, s):
	if i == len(s) or k == 0:
		if k == 0: total[0] += cumul
		return 
	if k:
		dfs(i+1, total, cumul * cc[s[i]], cc,k - 1, s)

	dfs(i+1, total, cumul, cc, k, s)

total = [0]
dfs(0, total, 1 , cc, 3, 'MARCH')
print(total[0])

# Optimized solution
import collections
cc = collections.Counter([input()[0] for _ in range(int(input()))])


def dfs(i, total ,cumul, cc, k, s):
	if i == len(s) or k == 0:
		if k == 0: total[0] += cumul
		return 
	
	dfs(i+1, total, cumul * cc[s[i]], cc,k - 1, s)
	dfs(i+1, total, cumul, cc, k, s)

total = [0]
dfs(0, total, 1 , cc, 3, 'MARCH')
print(total[0])
# Original solution
n,*s=list(map(str,open(0).read().split()))
a=[0]*5
ans=0
for i in s:
    if i[0] in "MARCH":
        a["MARCH".index(i[0])]+=1
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans+=a[i]*a[j]*a[k]
print(ans)

# Optimized solution
from itertools import combinations
n,*s=list(map(str,open(0).read().split()))
a=[0]*5
for i in s:
    if i[0] in "MARCH":
        a["MARCH".index(i[0])]+=1
print((sum([a[x]*a[y]*a[z] for x,y,z in combinations(list(range(5)),3)])))
# Original solution
#coding=utf-8
from itertools import combinations
from collections import Counter

def solve(n, ss):
    filtered_ss = list([x for x in ss if x in "MARCH"])

    gc = Counter(filtered_ss)
    if len(gc) < 3:
        return 0

    ans = 0
    for permutation in combinations("MARCH", 3):
        ans += (gc[permutation[0]] * gc[permutation[1]] * gc[permutation[2]])

    return ans

def main():
    n = int(eval(input()))
    ss = []
    for x in range(n):
        ss = ss + [input()[0]]
    print((solve(n, ss)))

if __name__ == '__main__':
    main()


# Optimized solution
#coding=utf-8
from itertools import combinations
from collections import Counter

def solve(n, gc):
    #filtered_ss = list(filter(lambda x: x in "MARCH", ss))

    #gc = Counter(filtered_ss)
    if len(gc) < 3:
        return 0

    ans = 0
    for permutation in combinations("MARCH", 3):
        ans += (gc[permutation[0]] * gc[permutation[1]] * gc[permutation[2]])

    return ans

def main():
    n = int(eval(input()))
    gc = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for _ in range(n):
        x = input()[0]
        if x in "MARCH":
            gc[x] += 1
    print((solve(n, gc)))

if __name__ == '__main__':
    main()
# Original solution
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N = int(input())
L = [0]*26
for _ in range(N):
    S = input()
    L[ston(S[0],'A')] += 1
s = ['M','A','R','C','H']
ans = 0
for l in [[0,1,2],[0,1,3],[0,1,4],[0,2,3],[0,2,4],[0,3,4],[1,2,3],[1,2,4],[1,3,4],[2,3,4]]:
    x,y,z = map(lambda x:ston(s[x],'A'), l)
    ans += L[x]*L[y]*L[z]
print(ans)


# Optimized solution
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations, product
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N = int(input())
L = [0]*26
for _ in range(N):
    S = input()
    L[ston(S[0],'A')] += 1
s = ['M','A','R','C','H']
ans = 0
for l in combinations(s,3):
    x,y,z = map(lambda x:ston(x,'A'), l)
    ans += L[x]*L[y]*L[z]
print(ans)
# Original solution
import itertools
import collections

def main():
    n = int(eval(input()))
    S = [input()[0] for _ in range(n)]

    array = ['M','A','R','C','H']
    S_after = []
    for s in S:
        if s in array:
            S_after.append(s)
    if len(S_after) < 3:
        print((0))
        return
    S_after_set = set(S_after)
    combs = itertools.combinations(S_after_set, 3)
    coll = collections.Counter(S_after)

    ans = 0
    for comb in combs:
        if comb[0] != comb[1] != comb[2]:
            ans += coll[comb[0]]*coll[comb[1]]*coll[comb[2]]
    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
import itertools
import collections

def main():
    n = int(eval(input()))
    S = [input()[0] for _ in range(n)]

    array = ['M','A','R','C','H']
    combs = itertools.combinations(array, 3)
    coll = collections.Counter(S)

    ans = 0
    for comb in combs:
        ans += coll[comb[0]]*coll[comb[1]]*coll[comb[2]]
    print(ans)


if __name__ == '__main__':
    main()
# Original solution
n,k = list(map(int, input().split()))

ans = k
for i in range(1, n):
    ans *= k-1

print(ans)

# Optimized solution
n,k = list(map(int, input().split()))
print((k * (k-1) ** (n-1)))
# Original solution
import math
N,K=list(map(int,input().split()))
print((K*((K-1)**(N-1))))

# Optimized solution
n,k=list(map(int,input().split()))
print((k*(k-1)**(n-1)))
# Original solution
def main():
    n, k = list(map(int, input().split()))
    print((k * pow(k - 1, n - 1)))


if __name__ == '__main__':
    main()



# Optimized solution
def main():
    n, k = list(map(int, input().split()))
    print((k * (pow(k - 1, n - 1))))


if __name__ == '__main__':
    main()
# Original solution
N, K = list(map(int,input().split()))
pat = K*((K-1)**(N-1))
print(pat)

# Optimized solution
N, K = list(map(int,input().split()))
print((K*((K-1)**(N-1))))
# Original solution
import itertools
N,K=[int(i) for i in input().split()]
seq=[i for i in range(K)]
lst=[]
for i in itertools.product(seq, repeat=N):
    lst.append(i)

ans=[]
for tup in lst:
    f=0
    for ind,color in enumerate(tup):
        if(ind==len(tup)-1):
            break
        if(tup[ind+1]==color):
            f=1
            break
    if(f==0):
        ans.append(tup)
print((len(ans)))

# Optimized solution
import itertools
N,K=[int(i) for i in input().split()]
seq=[i for i in range(K)]
lst=[]
'''for i in itertools.product(seq, repeat=N):
    lst.append(i)

ans=[]
for tup in lst:
    f=0
    for ind,color in enumerate(tup):
        if(ind==len(tup)-1):
            break
        if(tup[ind+1]==color):
            f=1
            break
    if(f==0):
        ans.append(tup)
print(len(ans))'''

print((K*(K-1)**(N-1)))
# Original solution
import itertools
N,K=[int(i) for i in input().split()]
seq=[i for i in range(K)]
lst=[]
'''for i in itertools.product(seq, repeat=N):
    lst.append(i)

ans=[]
for tup in lst:
    f=0
    for ind,color in enumerate(tup):
        if(ind==len(tup)-1):
            break
        if(tup[ind+1]==color):
            f=1
            break
    if(f==0):
        ans.append(tup)
print(len(ans))'''

print((K*(K-1)**(N-1)))

# Optimized solution
n,k=[int(i) for i in input().split()]
print(((k*1)*((k-1)**(n-1))))
# Original solution
n, k = list(map(int, input().split()))
ans = k*((k-1)**(n-1))
print(ans)    


# Optimized solution
n, k = list(map(int, input().split()))
print((k*(k-1)**(n-1)))
# Original solution
N, K = list(map(int, input().split()))
print((K * (K-1) ** (N-1)))

# Optimized solution
n, k = list(map(int, input().split()))
print((k * (k-1) ** (n-1)))
# Original solution
N, K = list(map(int, input().split()))

print((K * (K-1) ** (N-1)))

# Optimized solution
import sys

n, k = list(map(int, sys.stdin.readline().split()))

def main():
    ans = k * (k - 1)**(n-1)
    return ans

if __name__ == '__main__':
    ans = main()
    print(ans)
# Original solution
N,K = list(map(int,input().split()))
S = K
while(1):
    if N==1:
        break
    S *= (K-1)
    N-=1
print(S)

# Optimized solution
N,K = list(map(int,input().split()))
ans = 0
for i in range(N):
    if i==0:
        ans = K
    else:
        ans *= (K-1)
print(ans)