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

N,K = map(int,input().split())
XY = list(list(map(int,input().split()))for i in range(N))

ans = float('inf')

for lx, _ in XY:
    for rx, _ in XY:
        if lx < rx:
            for _, dy in XY:
                for _, uy in XY:
                    if dy < uy:
                        count = 0
                        for x,y in XY:
                            if lx <= x <= rx and dy <= y <= uy:
                                count += 1
                        if count >= K:
                            ans = min(ans,(rx-lx)*(uy-dy))
print(ans)

### FIXED CODE ###

N,K = map(int,input().split())
XY = []

for i in range(N):
    x,y = map(int,input().split())
    XY.append((x,y))


ans = float('inf')

for lx, _ in XY:
    for rx, _ in XY:
        if lx > rx:
            continue
        for _, dy in XY:
            for _, uy in XY:
                if dy > uy:
                    continue
                count = 0
                for x,y in XY:
                    if lx <= x <= rx and dy <= y <= uy:
                        count += 1
                if count >= K:
                    ans = min(ans,(rx-lx)*(uy-dy))
print(ans)
### BUGGY CODE ###

def check(a, b, c):
	if(c<a+b and a<b+c and b<c+a):
		return True
	else:
		return False

n = int(input())
ListL = [int(i) for i in input().split()]

ans = 0
for i in range(n-2):
	a = ListL[i]
	for j in range(i+1, n-1):
		b = ListL[j]
		for k in range(j+1, n):
			c = ListL[k]
			if(check(a, b, c)):
				ans += 1

print(ans)

### FIXED CODE ###

import bisect

n = int(input())
ListL = [int(i) for i in input().split()]

ListL.sort()
ans = 0

for i in reversed(range(2, n)):
	a = ListL[i]
	for j in reversed(range(1, i)):
		b = ListL[j]
		index = bisect.bisect_right(ListL, a-b)
		#print(a, b)
		if (index >= j):
			break
		else:
			ans += j - index

print(ans)
### BUGGY CODE ###

import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
import numpy as np
import bisect

def main():
	h,w=map(int,input().split())
	AB=np.array(read().split(), np.int64)
	
	
	A=AB[:h*w]
	B=AB[h*w:]
	
	A=np.reshape(A, (h,w))
	B = np.reshape(B, (h, w))
	
	G=abs(A-B)
	M=h*w*80
	
	li=[[[]for i in range(w)] for j in range(h)]
	for i in range(h):
		for j in range(w):
			if i==j==0:
				li[i][j].append(G[i][j])
			elif i==0:
				for k in li[i][j-1]:
					if abs(k-G[i][j])<=M:
						li[i][j].append(abs(k-G[i][j]))
					if abs(k+G[i][j])<=M:
						li[i][j].append(abs(k + G[i][j]))
			elif j==0:
				for k in li[i-1][j]:
					if abs(k-G[i][j])<=M:
						li[i][j].append(abs(k-G[i][j]))
					if abs(k+G[i][j])<=M:
						li[i][j].append(abs(k + G[i][j]))
			else:
				for k in li[i-1][j]:
					if abs(k-G[i][j])<=M:
						li[i][j].append(abs(k-G[i][j]))
					if abs(k+G[i][j])<=M:
						li[i][j].append(abs(k + G[i][j]))
				for k in li[i][j-1]:
					if abs(k-G[i][j])<=M:
						li[i][j].append(abs(k-G[i][j]))
					if abs(k+G[i][j])<=M:
						li[i][j].append(abs(k + G[i][j]))
			
	print(min(li[h-1][w-1]))
	
if __name__ == "__main__":
	main()


### FIXED CODE ###

import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np

def main():
	h, w = map(int, input().split())
	
	G = [[0] * w for i in range(h)]
	A = [0]*h
	B = [0]*h
	
	for i in range(h):
		A[i] = list(map(int, input().split()))
	for i in range(h):
		B[i] = list(map(int, input().split()))
	
	for i in range(h):
		for j in range(w):
			G[i][j]=abs(A[i][j]-B[i][j])

	M = (h + w) * 80

	li = [[[0] * M for i in range(w)] for j in range(h)]
	
	li[0][0][G[0][0]] = 1
	for i in range(h):
		for j in range(w):
			for k in range(M):
				
				if li[i][j][k] == 1:
					if i < h - 1:
						li[i + 1][j][abs(k - G[i+1][j])] = 1
						li[i + 1][j][abs(k + G[i+1][j])] = 1
					if j < w - 1:
						li[i][j + 1][abs(k - G[i][j+1])] = 1
						li[i][j + 1][abs(k + G[i][j+1])] = 1

	for i in range(M):
		if li[h-1][w - 1][i] == 1:
			print(i)
			exit(0)


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

n = int(input())
a = list(map(lambda x: int(x)-1, input()))

f = 1 in a
if f:
    a = [int(i==1) for i in a]
else:
    a = [int(i==2) for i in a]

tmp = 1
ans = 0
for i in range(n):
    ans += tmp*a[i]
    tmp = tmp*(n-i-1)//(i+1)

ans %= 2
if not f:
    ans *= 2

print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(lambda x: int(x)-1, input()))

cnt = [0]
for i in range(1,n+1):
    x = 0
    while i%2==0:
        x += 1
        i //=2
    cnt.append(cnt[-1]+x)

def comb(k):
    left = cnt[n-1]
    right = cnt[k]+cnt[n-1-k]
    return left-right == 0

f = 1 in a
if f:
    a = [int(i==1) for i in a]
else:
    a = [int(i==2) for i in a]

ans = 0
for i in range(n):
    if comb(i):
        ans += a[i]

ans %= 2
if not f:
    ans *= 2

print(ans)
### BUGGY CODE ###

import numpy as np
import re
from sys import stdin

N, Q = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()

def func(Str):
  idx = Str.find("AC")
  return idx

i = 0
ac_idx = []
while i<N:
  a = func(S[i:])
  if a != -1:
    ac_idx.append(a+i)
    i = a+i+2
  else:
    break

ac_idx = np.array(ac_idx)
for j in range(Q):
  l,r = [int(x) for x in stdin.readline().rstrip().split()]
  L = ac_idx >= l-1
  R = ac_idx < r-1
  print(np.sum(np.logical_and(L, R)))
  

### FIXED CODE ###

from sys import stdin

N, Q = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()

ac_idx = [0]
count = 0

for i in range(N-1):
  if S[i]=="A" and S[i+1]=="C":
    count+=1
  ac_idx.append(count)

for j in range(Q):
  l,r = [int(x) for x in stdin.readline().rstrip().split()]
  print(ac_idx[r-1]-ac_idx[l-1])
### BUGGY CODE ###

N = int(input())

def f(a, b):
  return len(list(a)) if len(list(a)) > len(list(b)) else len(list(b))

min_x = len(list(str(N)))

for i in range(1, N // 2 + 1):
  if N % i == 0:
    min_x = min(min_x, f(str(i), str(N // i)))
    if len(str(i)) >= len(str(N // i)):
      break
print(min_x)


### FIXED CODE ###

import math

def f(a, b):
  return len(list(str(max(a, b))))

N = int(input())

ans = len(str(N))
for i in range(1, int(math.sqrt(N)) + 1):
  if N % i == 0:
    ans = min(ans, f(i, N // i))
print(ans)
### BUGGY CODE ###

n,p=map(int,input().split())
 

def kouyaku(n,p):
    if n==1:
        return p 
    else:
        for i in range(round((p**(1/n)+1)),0,-1):        
            if p%i==0:
                if p%(i**2)==0:
                    if p%(i**n)==0:
                        return i
                        break
 
            
print(kouyaku(n,p))

### FIXED CODE ###

N, P = map(int, input().split())
ans = 1
 
if N >= 45:
  print(ans)
elif N == 1:
  print(P)
  
 
  
else:
  i = 1
  while(i**N <= P):
    if P % (i**N) == 0:
      ans = i
    i += 1
  print(ans)
### BUGGY CODE ###

import sys
n = int(input())

print(0)
sys.stdout.flush()
s = input()

if s == "Vacant":
    exit()

low = 1
high = n-1
tmp = 0
cnt = 1

while low+1 < high:
    mid = (low + high) //2
    
    print(mid)
    sys.stdout.flush()
    t = input()
    cnt += 1
    
    if mid % 2 == 0:
        if t[0] == s[0]:
            low = mid
        elif t[0] == "V":
            exit()
        else:
            high = mid
    else:
        if t[0] == s[0]:
            high = mid
        elif t[0] == "V":
            exit()
        else:
            low = mid
if mid == high:
    print(low)
else:
    print(high)
sys.stdout.flush()
s = input()
exit()

### FIXED CODE ###

import sys
n = int(input())

print(0)
sys.stdout.flush()
s = input()

if s == "Vacant":
    exit()

low = 1
high = n-1
tmp = 0
cnt = 1

while low+1 < high:
    mid = (low + high) //2
    
    print(mid)
    sys.stdout.flush()
    t = input()
    cnt += 1
    
    if mid % 2 == 0:
        if t[0] == s[0]:
            low = mid
        elif t[0] == "V":
            exit()
        else:
            high = mid
    else:
        if t[0] == s[0]:
            high = mid
        elif t[0] == "V":
            exit()
        else:
            low = mid

print(high)
sys.stdout.flush()
s = input()
if s[0] == "V":
    exit()
else:
    print(low)
    sys.stdout.flush()
    s = input()
    exit()
### BUGGY CODE ###

import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    H,W = map(int, input().split())
    visited = [[False]*W for _ in range(H)]
    q = []
    for y in range(H):
        for x, val in enumerate(list(input().rstrip())):
            if val == '#':
                q.append((y,x))
                visited[y][x] = True
    ans = -1
    while q:
        ans += 1
        new_q = []
        for y,x in q:
            if 0 < y and not visited[y-1][x]:
                new_q.append((y-1,x))
                visited[y-1][x] = True
            if y < H-1 and not visited[y+1][x]:
                new_q.append((y+1,x))
                visited[y+1][x] = True
            if 0 < x and not visited[y][x-1]:
                new_q.append((y,x-1))
                visited[y][x-1] = True
            if x < W-1 and not visited[y][x+1]:
                new_q.append((y,x+1))
                visited[y][x+1] = True
        if new_q:
            q = new_q[:]
        else:
            break
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    H, W = map(int,input().split())
    visited = [[False]*W for _ in range(H)]
    q = []
    for y in range(H):
        S = input()
        for x, s in enumerate(S):
            if s == "#":
                q.append((y, x))
                visited[y][x] = True

    ans = -1
    while q:
        ans += 1
        nq = []
        for y, x in q:
            if 0 < x and not visited[y][x-1]:
                visited[y][x-1] = True
                nq.append((y,x-1))
            if x < W-1 and not visited[y][x+1]:
                visited[y][x+1] = True
                nq.append((y,x+1))
            if 0 < y and not visited[y-1][x]:
                visited[y-1][x] = True
                nq.append((y-1, x))
            if y < H-1 and not visited[y+1][x]:
                visited[y+1][x] = True
                nq.append((y+1,x))
        if nq:
            q = nq
        else:
            break

    print(ans)

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

n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n):
    if min(p[:i + 1]) == p[i]:
        ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))
cnt = 1
m = p[0]
for i in range(1, n):
    if p[i] <= m:
        cnt += 1
        m = p[i]
print(cnt)
### BUGGY CODE ###



d = input()



Q = int(input())

for q in range(Q):
    ls = input().split()

    if ls[0] == '1':
        
        d = d[::-1]

    else:
        if (ls[1]== '1'):
            d = ls[2] + d
        else:
            d = d + ls[2]



print (d)


### FIXED CODE ###

from collections import deque
d = deque()
s = input()
d.append(s)
rev = 0

Q = int(input())

for q in range(Q):
    ls = input().split()
    #print (ls)
    if ls[0] == '1':
        rev = (rev + 1) % 2
    else:
        if (int(ls[1]) + rev) % 2 == 0:
            d.append(ls[2])
        else:
            d.appendleft(ls[2])

ans = ''.join(list(d))
if rev == 1:
    ans = ans[::-1]
print (ans)
### BUGGY CODE ###

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

def CalExVal(x):
    return (1/2*(x+1))

Ex = list(map(CalExVal, A))
adjlist = [0]*(len(A)-K+1)
for i in range(len(A)-K + 1):
    adjlist[i] = sum(Ex[i:(K+i)])
         
print(max(adjlist))

### FIXED CODE ###

def main():
  def CalExVal(x):
    return (1/2*(x+1))
  N, K = map(int, input().split())
  A = list(map(int, input().split()))


  Ex = list((map(CalExVal, A)))
  #temp = len(A)-K + 1
  #adjlist = [0]*(temp)
  #adjlist = [sum(list(map(CalExVal, A))[i:(K+i)]) for i in range(temp)]
  tem = sum(Ex[:K])
  res = tem
  for i in range(0,N-K):
      tem = tem - Ex[i] + Ex[i+K]
      if res < tem:
      	res = tem
  print(res)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

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

if sum(A) < K:
  print(0)
  exit(0)

#import random
#N = 3000
#A = [random.randint(1, 10**9) for _ in range(N)]
dp = [[0] * (K+1) for _ in range(N+1)]
dp[-1][0] = 1
M = 10**9 + 7
for i in range(N):
  a = A[i]
  for j in range(a+1):
    for k in range(K-j+1):
      dp[i][k+j] += dp[i-1][k]
      dp[i][k+j] %= M

#for r in dp:
#  print(r)
print(dp[N-1][K])



### FIXED CODE ###

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

# import random
# N = 100
# K = 10**5
# A = [K] * N

if sum(A) < K:
  print(0)
  exit(0)

t0 = [0] * (K+1)
t0[0] = 1

M = 10**9 + 7
for i in range(N):
    a = A[i]
    t1 = [0] * (K+1)
    st0 = [0]
    for t in t0:
        st0.append((t + st0[-1]) % M)
    for k in range(K+1):
        l = max(0, k-a)
        t1[k] = (st0[k+1] - st0[l]) % M
    t0 = t1

print(t0[K])
### BUGGY CODE ###

import collections

N = int(input())
As = list(map(int,input().split()))
Cs = collections.Counter(As)
#rlt = [Cs[i]*(Cs[i]-1)//2 for i in Cs]
#print(Cs)
for i in range(N):
  Cs2 = Cs.copy()
  rlt = (Cs[As[i]] - 1)*(Cs[As[i]] - 2)//2
  del Cs2[As[i]]
  for key in Cs2:
    rlt = rlt + Cs2[key]*(Cs2[key] - 1)//2
  print(rlt)

### FIXED CODE ###

import collections

N = int(input())
As = list(map(int,input().split()))
Cs = collections.Counter(As)

s = 0
for key in Cs:
  s = s + Cs[key]*(Cs[key] - 1)//2
  
for i in range(N):
  rlt = s - Cs[As[i]]*(Cs[As[i]] - 1)//2 + (Cs[As[i]] - 1)*(Cs[As[i]] - 2)//2
  print(rlt)
### BUGGY CODE ###

import sys
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

DP = [0 for k in range(K+1)] #和がkとなる部分集合の数
DP[0] = 1
for a in A:
  for k in range(K-a,-1,-1):
    DP[k+a] += DP[k]

"""
for k in range(1,2*K+1): #累積和へ変換
  DP[k] += DP[k-1]
print(DP)
"""
"""
if sum(DP[0:K]) == 2**N:
  print(N)
  sys.exit()
"""
#print(DP)  
ans = 0
DP_rev = [0 for _ in range(K)] #戻すDP!!!
for a in A:
  flag = True
  if a >= K: break
  for i in range(K):
    DP_rev[i] = DP[i] 
    if i-a >= 0:
      DP_rev[i] -= DP_rev[i-a]
    if i >= K-a and DP_rev[i] > 0:
      flag = False
      break
  if flag:
    ans += 1
  #print(a, DP_rev)
    
print(ans)
  
  
  
  


### FIXED CODE ###

import sys
N, K = map(int, input().split())
A = list(map(int, input().split()))
#A = [i for i in range(1,2)] + [i for i in range(2,1001)] * 4
A.sort()

DP = [0 for k in range(K+1)] #和がkとなる部分集合の数
DP[0] = 1
for a in A:
  for k in range(K-a,-1,-1):
    DP[k+a] += DP[k]

"""
for k in range(1,2*K+1): #累積和へ変換
  DP[k] += DP[k-1]
print(DP)
"""
"""
if sum(DP[0:K]) == 2**N:
  print(N)
  sys.exit()
"""
#print(DP)  


def det(t):
  a = A[t]
  if a >= K:
    return False
  DP_rev = [0 for _ in range(K)] #戻すDP!!!
  ans = True
  for i in range(K):
    DP_rev[i] = DP[i] 
    if i-a >= 0:
      DP_rev[i] -= DP_rev[i-a]
    if i >= K-a and DP_rev[i] > 0:
      ans = False
      break
  del DP_rev
  return ans

lt = 0
rt = N-1
if not det(lt):
  print(0)
  sys.exit()
if det(rt):
  print(rt+1)
  sys.exit()

while rt - lt > 1:
  ct = (lt + rt) // 2
  if det(ct):
    lt = ct
  else:
    rt = ct
print(rt)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
b = set()
c = [0]*n

for i in range(n):
  if a[n-1-i] != c[n-1-i]%2:
    b.add(n-i)
    for j in range(1, int((n-i)**0.5)+1):
      if (n-i)%j == 0:
        c[j-1] += 1
        if (n-i)//j != j:
          c[(n-i)//j -1] += 1

print(len(b))
if len(b)>0:
  print(*b)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = set()

for i in range(n-1):
  if a[n-1-i]&1:
    b.add(n-i)
    for j in range(2, int((n-i)**0.5)+1):
      if (n-i)%j == 0:
        a[j-1] += 1
        if (n-i)//j != j:
          a[(n-i)//j -1] += 1
if a[0] != len(b)%2:
  b.add(1)
          
print(len(b))
if len(b)>0:
  print(*b)
### BUGGY CODE ###

inputs = list(map(int, input().split()))
K = inputs.pop()

if inputs[0] == inputs[1] == inputs[2]:
    print(0)
else:
    for k in range(K):
        total = sum(inputs)
        inputs = [total-inputs[i] for i in range(3)]

        if abs(inputs[0] - inputs[1]) > 10 ** 18:
            print(-1)
            break
    else:
        print(inputs[0] - inputs[1])


### FIXED CODE ###

A, B, C, K = map(int, input().split())

def judge(n):
    if abs(n) > 10**18:
        print('Unfair')
    else:
        print(n)

if K % 2 == 0:
    judge(A-B)
else:
     judge(B-A)
### BUGGY CODE ###

# coding: utf-8

N = int(input())

pushed = []
button = [0] * (N + 1)

for i in range(1, N+1):
    button[i] = int(input())

push_button = 1
for _ in range(1, N+1):
    if push_button in pushed:
        print("-1")
        exit(0)
    elif push_button == 2:
        print(len(pushed))
        exit(0)
    else:
        pushed.append(push_button)
        push_button = button[push_button]


### FIXED CODE ###

# coding: utf-8

N = int(input())

pushed = []
button = [0] * (N + 1)

for i in range(1, N+1):
    button[i] = int(input())

push_button = 1
for _ in range(1, N+1):
    if push_button == 2:
        print(len(pushed))
        exit(0)
    else:
        pushed.append(push_button)
        push_button = button[push_button]

print("-1")
### BUGGY CODE ###

X,Y,A,B,C=map(int, input().split())
P=list(map(int, input().split()))
Q=list(map(int, input().split()))
R=list(map(int, input().split()))
R.sort(reverse=True)
if X > A:
    get_P= P.extend(R[:X-A+1])
    get_P.sort(reverse=True)
    R=R[X-A+1:]
else:
    P.sort(reverse=True)
    get_P=P[:X]
if Y > B:
    get_Q= Q.extend(Q[:Y-B+1])
    R=R[Y-B+1]
    get_Q.sort(reverse=True)
else:
    Q.sort(reverse=True)
    get_Q=Q[:Y]

while(min(P)<R[0] or min(Q)<R[0]):
    if min(get_P)<min(get_Q):
        get_P[get_P.index(min(get_P))] = R.pop(0)
    else:get_Q[get_Q.index(min(get_Q))] = R.pop(0)
    if R==[]:break
#print(get_P)
#print(get_Q)
print(sum(get_P)+sum(get_Q))

### FIXED CODE ###

from collections import deque
import math
import sys

x,y,a,b,c = list(map(int,sys.stdin.readline().split()))
p = sorted(list(map(int,sys.stdin.readline().split())), reverse=True)
q = sorted(list(map(int,sys.stdin.readline().split())), reverse=True)
r = sorted(list(map(int,sys.stdin.readline().split())), reverse=True)
eat=[]

if x<len(p):
    [eat.append(red) for red in p[:x]]
else:
    [eat.append(red) for red in p]
if y<len(q):
    [eat.append(green) for green in q[:y]]
else:
    [eat.append(green) for green in q]
[eat.append(apple) for apple in r]
eat = sorted(eat, reverse=True)
#print(sum(eat[:x + y]))
ans = 0
for taste in eat[:x + y]:
    ans += taste 
print(ans)
### BUGGY CODE ###

semester, K = map(int, input().split())

score = input().split()

result1 = 1
result2 = 1

for i in range(semester - K + 1) :
    if i == 0 :
        for j in range(K) :
            result1 = result1 * int(score[K - 1 - j])
        loopCount = K
        continue
    
    result2 = result1 / int(score[K - loopCount]) * int(score[K - 1 + i])
    result2 = int(result2)
    loopCount -= 1

    if result1 < result2 :
        print("Yes")
    else :
        print("No")
    
    result1 = result2
    result2 = 1




### FIXED CODE ###

semester, K = map(int, input().split())

score = input().split()

for i in range(semester - K + 1) :
    if i == 0 :
        continue    

    if int(score[K - K + i - 1]) < int(score[K - 1 + i]) :
        print("Yes")
    else :
        print("No")
### BUGGY CODE ###

H, W, M = map(int, input().split())
h = [0] * (H+1)
w = [0] * (W+1)
l = []
for i in range(M):
  x, y = map(int, input().split())
  h[x] += 1
  w[y] += 1
  l.append([x, y])
  
a = []
b = []
c = max(h)
d = max(w)
for i in range(H+1):
  if h[i] == c:
    a.append(i)
for i in range(W+1):
  if w[i] == d:
    b.append(i)

flag = False
for s in a:
  for t in b:
    if [s, t] not in l:
      flag = True
      break
if flag:
  ans = c+d
else:
  ans = c+d-1
print(ans)

### FIXED CODE ###

H, W, M = map(int, input().split())
h = [0] * (H+1)
w = [0] * (W+1)
l = set()
for i in range(M):
  x, y = map(int, input().split())
  h[x] += 1
  w[y] += 1
  l.add((x, y))
  
c = max(h)
d = max(w)
a = [i for i, x in enumerate(h) if x == c]
b = [i for i, x in enumerate(w) if x == d]

flag = False
for s in a:
  for t in b:
    if (s, t) not in l:
      flag = True
      break
  if flag:
    break
ans = c+d
if not flag:
  ans -= 1
print(ans)
### BUGGY CODE ###

n = int(input())
X = input()
pc = X.count('1')
nx = int(X, 2)

def f(n):
    c = 0
    while n > 0:
        n = n%bin(n).count('1')
        c += 1
    return c

tmp = pow(2, n)
for i in range(n-1, -1, -1):
    # ibit目を反転させる # つまり2**iを引く
    tmp //= 2
    if (nx>>i)&1:
        if nx-tmp == 0:
            print(0)
            continue
        r = (nx-tmp)%(pc-1)
    else:
        r = (nx+tmp)%(pc+1)

    if r > 0:
        print(f(r) + 1)
    else:
        print(1)
    

### FIXED CODE ###

n = int(input())
X = input()
pc = X.count('1')
nx = int(X, 2)

def f(n):
    c = 0
    while n > 0:
        n %= bin(n).count('1')
        c += 1
    return c

nxp = nx%(pc+1)
nxm = nx%(pc-1) if pc > 1 else 0
for i in range(n-1, -1, -1):
    if (nx>>i)&1:
        # 2**iを引く
        if pc-1 == 0:
            print(0)
            continue
        p = pow(2, i, pc-1)
        r = (nxm-p)%(pc-1)
    else:
        # 2**iを足す
        r = (nxp+pow(2, i, pc+1))%(pc+1)

    print(f(r) + 1)
### BUGGY CODE ###

def pow(x, n):
    ans = 1
    while n:
        if n%2:
            ans*=x
        x*=x
        n>>=1
    return ans
n,p=map(int,input().split())
if n==1:
	print(p)
	exit()
ans=1
for i in range(2,int(p**0.5)+2):
	if p<pow(i,n):
		break
	while p%(pow(i,n))==0:
		if p%(pow(i,n))==0:
			ans*=i
			p//=(pow(i,n))
print(ans)
	



### FIXED CODE ###


n,p=map(int,input().split())
ans=[]
for i in range(2,int(p**0.5)+1):
	cnt=0
	while p%i==0:
		p//=i
		cnt+=1
	if cnt>0:
		ans.append([i,cnt])
ans.append([p,1])
ret=1
for i in range(len(ans)):
	ret*=pow(ans[i][0],(ans[i][1]//n))
print(ret)
### BUGGY CODE ###

N = int(input())
A = sorted(map(int, input().split()))
ans = sum(A)
nums = [A.count(num) for num in range(10 ** 5 + 1)]

Q = int(input())
for _ in range(Q):
    B, C = map(int, input().split())
    ans += (C - B) * nums[B]
    nums[C] += nums[B]
    nums[B] = 0
    print(ans)

### FIXED CODE ###

import collections

N = int(input())
A = sorted(map(int, input().split()))

cnt = collections.defaultdict(int)
for a in A:
    cnt[a] += 1
ans = sum(A)

Q = int(input())
for _ in range(Q):
    B, C = map(int, input().split())
    ans += (C - B) * cnt[B]
    cnt[C] += cnt[B]
    cnt[B] = 0
    print(ans)
### BUGGY CODE ###

s=input()
q=int(input())

for _ in range(0,q):
  n=input()
#  print(n[0:1])
  if n[0:1]=="1":
#    print("!")
    s = s[::-1]
  else:
    m=n.split()
    if m[1]=="1":
      s=m[2]+s
    else:
      s=s+m[2]
print(s)
      

### FIXED CODE ###

s=input()
q=int(input())

rev=1

sf=""
sb=s

for _ in range(0,q):
  n=input().split()
  if n[0]=="1":
    rev*=-1
  else:
    if (n[1]=="1" and rev==1) or (n[1]=="2" and rev==-1):
      sf+=n[2]
    else:
      sb+=n[2]

s=sf[::-1]+sb

if rev==1:
  print(s)
else:
  print(s[::-1])
### BUGGY CODE ###

s = list(input())
count = 0
for i in range(len(s)):
    for j in range(len(s)-1):
        if(s[j]=='B'):
            if(s[j + 1]=='W'):
                s[j]="W"
                s[j+1]="B"
                count += 1
            else:
                continue
        else:
            continue
print(count)

### FIXED CODE ###

s = list(input())
t=len(s)
count = 0
a = 0
for j in range(t):
    if(s[j]=='W'):
        count += j-a
        a += 1
print(count)