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

N, M = map(int, input().split())
S = input()
T = input()
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
 
def lcm(x, y):
    return (x * y) // gcd(x, y)
X = lcm(N ,M)
 
if S[0] != T[0]:
    print(-1)
elif X == N*M:
    print(N*M)
else:
    for i in range(1,(N*M//X)+1):
        L = X * i
        match = lcm(  L // N,  L // M)
        for j in range( (L // match)-1 ,0,-1):
            if S[j * N * match // L] != T[ j * M * match // L]:
                L = -1
                break
        if L == X * i:
            break
    print(L)

### FIXED CODE ###

N, M = map(int, input().split())
S = str(input())
T = str(input())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
 
def lcm(x, y):
    return (x * y) // gcd(x, y)
X = lcm(N ,M)
 
if S[0] != T[0]:
    print(-1)
elif X == N*M:
    print(N*M)
else:
        L = X
        match = lcm(  L // N,  L // M)
        for j in range(1, (L // match) ):
            if S[j * N * match // L] != T[ j * M * match // L]:
                L = -1
                break
        if L == X :
            print(L)
        else:
            print(-1)
### BUGGY CODE ###


k = int(input())

gcd_dict = {}

ans = 0
for n in range(k, 0, -1):
   for a in range(n, k + 1, n):
        for b in range(n, k + 1, n):
            for c in range(n, k + 1, n):
                if (a, b, c) not in gcd_dict.keys():
                    gcd_dict[(a, b, c)] = n
                    ans += n

print(ans)


### FIXED CODE ###


k = int(input())

gcd_cnt = {}

for n in range(k, 0, -1):
    div_all = (k // n) ** 3
    div_dup = 0
    for m in range(n * 2, k + 1, n):
        div_dup += gcd_cnt[m]
    gcd_cnt[n] = div_all - div_dup

ans = 0
for gcd in gcd_cnt.keys():
    ans += gcd * gcd_cnt[gcd]

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

n, k = map(int, input().split())
a = [int(x)-1 for x in input().split()]

inds = {}
y = [0]*n

for i in range(n):
    if a[i] in inds:
        y[inds[a[i]][-1]] = i+1 - inds[a[i]][-1]
        inds[a[i]].append(i)
    else:
        inds[a[i]] = [i]

for lst in inds.values():
    y[lst[-1]] = n+lst[0]+1 - lst[-1]

length = (n*k).bit_length()

db = [y]
for m in range(length):
    next_y = [0]*n
    for i in range(n):
        next_y[i] = db[-1][i] + db[-1][(i+db[-1][i]) % n]
    db.append(next_y)

cur = 0
i = length

while cur < n*k:
    while i > -1 and cur + db[i][cur % n] > n*k:
        i -= 1
    if i == -1:
        break
    cur = cur + db[i][cur % n]

ans = []
while cur < n*k:
    if cur + db[0][cur % n] > n*k:
        ans.append(cur)
        cur += 1
    elif cur + db[0][cur % n] == n*k:
        break
    else:
        cur = cur + db[0][cur % n]

print(*map(lambda x: a[x % n]+1, ans))


### FIXED CODE ###

from bisect import bisect_right
n, k = map(int, input().split())
a = [int(x) for x in input().split()]

d = {}
for i in range(n):
    if a[i] in d:
        d[a[i]].append(i)
    else:
        d[a[i]] = [i]


def simulate(k):
    if k == 0:
        return 0, []
    lap = 1
    res = [0]
    while True:
        s = res.pop()
        nxt = d[a[s]][bisect_right(d[a[s]], s) % len(d[a[s]])] + 1
        if nxt == n:
            if lap == k and s == n-1:
                res.append(s)
            if s == n-1:
                lap += 1
            return lap, res
        elif nxt <= s+1:
            if lap == k:
                res.append(s)
                if s == n-1:
                    return lap, res
                res.append(s+1)
                if s+1 == n-1:
                    return lap, res
            else:
                res.append(nxt)
                lap += 1
        else:  # s+1 < nxt
            s = nxt
            res.append(s)
    return 0


period, ans = simulate(k)

if period != k:
    lap, ans = simulate(k % period)

print(*[a[x] for x in ans])
### BUGGY CODE ###

N = int(input())
A = [0] + [int(_) for _ in input().split()]


def is_possible(K):
    mp = {}
    for i in range(N):
        if A[i] >= A[i + 1]:
            for key in sorted(mp.keys(), reverse=True):
                if key >= A[i + 1]:
                    del mp[key]
                else:
                    break
            flag = True
            for j in range(A[i + 1] - 1, -1, -1):
                if mp.get(j, 0) < K - 1:
                    mp[j] = mp.get(j, 0) + 1
                    flag = False
                    break
                elif j in mp:
                    del mp[j]
            if flag:
                return False
    return True


def bis(x, y):
    if y == x + 1:
        return y
    elif is_possible((x + y) // 2):
        return bis(x, (x + y) // 2)
    else:
        return bis((x + y) // 2, y)


print(bis(0, N))


### FIXED CODE ###

import random
input()
A = [int(_) for _ in input().split()]
A = [A[0]] + [j for i, j in zip(A, A[1:]) if i >= j]
N = len(A)


def cut(array, index):
    if index < 1:
        return []
    if index <= array[0][0]:
        return [(index, array[0][1])]
    for _ in range(len(array)-1, 0, -1):
        if array[_ - 1][0] < index:
            return array[:_] + [(index, array[_][1])]


def is_possible(K):
    dp = [(A[0], 0)]
    for a in A[1:]:
        if a <= dp[-1][0]:
            dp = cut(dp, a)
        else:
            dp += [(a, 0)]
        is_added = False
        for j in range(len(dp) - 1, -1, -1):
            if dp[j][1] < K - 1:
                dp = cut(dp, dp[j][0] - 1) + [(dp[j][0], dp[j][1] + 1)]
                if dp[-1][0] < a:
                    dp += [(a, 0)]
                is_added = True
                break
        if not is_added:
            return False
    return True


def bis(x, y):
    if y == x + 1:
        return y
    elif is_possible((x + y) // 2):
        return bis(x, (x + y) // 2)
    else:
        return bis((x + y) // 2, y)


print(bis(0, N))
### BUGGY CODE ###

n = int(input())
p,mod = 1,1000000007
for i in range(1,n+1):
    p = p*i
print(p%mod)


### FIXED CODE ###

n = int(input())
p,mod = 1,1000000007
for i in range(1,n+1):
    p = p*i%mod
print(p)
### BUGGY CODE ###


S = input()
P = tuple(map(int, input().split()))

dis = abs(P[0]) + abs(P[1])
forward = S.count("F")

S = S.split("T")

def add(p, d, L):
    return (p[0] + L * d[0], p[1] + L * d[1])

if dis > forward or (forward - dis) % 2 == 1:
    print("No")

else:
    now = {((0, 0), (1, 0), forward)} # (X, Y), dir
    for s in S:
        ne = set()
        L = len(s)
        for p, d, f in now:
            #Fのとき
            f -= L
            p = add(p, d, L)
            dis = abs(P[0] - p[0]) + abs(P[1] - p[1])

            if dis <= forward:
                #ne = ne | {(p, d, f)}
                ne = ne | {(p, (d[1], -d[0]), f), (p, (-d[1], d[0]), f) }
        now = ne
    
    for p,d,f in now:
        if p == P:
            print("Yes")
            break
    else:
        print("No")

### FIXED CODE ###

import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    S = input().strip()
    X, Y = read_values()
    F = list(map(len, S.split("T")))

    S = {F[0]}
    if len(F) >= 2:
        for x in F[2::2]:
            SS = set()
            for s in S:
                SS.add(s + x)
                SS.add(s - x)
            S = SS

    if not X in S:
        print("No")
        return
    
    S = {0}
    if len(F) >= 1:
        for x in F[1::2]:
            SS = set()
            for s in S:
                SS.add(s + x)
                SS.add(s - x)
            S = SS
    
    if not Y in S:
        print("No")
        return 
    
    print("Yes")


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

n,k = map(int,input().split())
mod = 10**9+7
v = [0]*(k+1)
ans = 0
for i in range(k,0,-1):
    if v[i] == 0:
        v[i] = ((k//i)**n-sum(v[i::i])) % mod
        ans += v[i]*i
        ans %= mod
print(ans)

### FIXED CODE ###

n,k = map(int,input().split())
mod = 10**9+7
v = [0]*(k+1)
ans = 0
for i in range(k,0,-1):
    if v[i] == 0:
        v[i] =  (pow(k//i,n,mod)-sum(v[i::i])) % mod
        ans += (v[i]*i) % mod
        ans %= mod
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

c = input()
c = c[:len(c)-1]
q = int(input())

num = len(c)

hantei = 1

for i in range(q):
    q_i= list(input())
    #print(q_i)
    if q_i[0] == '1':
        hantei *= -1
    elif (q_i[2] =='1' and hantei == 1) or (q_i[2] == '2' and hantei == -1):
            c = q_i[4] +c
    elif (q_i[2] =='2' and hantei == 1) or (q_i[2] == '1' and hantei == -1):
            c += q_i[4]

if hantei == -1:
    c = c[::-1]


print(c)


### FIXED CODE ###

import sys
input = sys.stdin.readline

c = input()
c = c[:len(c)-1]
q = int(input())

num = len(c)
c_mae = ''
c_ato = ''

hantei = 1

for i in range(q):
    q_i= list(input())
    #print(q_i)
    if q_i[0] == '1':
        hantei *= -1
    elif (q_i[2] =='1' and hantei == 1) or (q_i[2] == '2' and hantei == -1):
        c_mae = q_i[4] + c_mae
    else:
        c_ato += q_i[4]

print(c_mae+c+c_ato if hantei == 1 else (c_mae+c+c_ato)[::-1])
### BUGGY CODE ###

N = int(input())
S = list(input())

ans_list = {}

for i in range(N):
    for j in range(i+1, N):
        if not S[j + 1:N]:
            continue
        elif S[i] + S[j] not in ans_list:
            ans_list[S[i] + S[j]] = S[j + 1:N]
        else:
            ans_list[S[i] + S[j]].extend(S[j+1:N])
count = 0
# print(ans_list)
ans_len_list = [len(set(value)) for value in ans_list.values()]
print(sum(ans_len_list))

### FIXED CODE ###

N = int(input())
S = list(input())
visited = {}

count = 0

for i, s in enumerate(S):
    if s in visited:
        continue
    visited[s] = []
    for j, s2 in enumerate(S[i+1:N-1]):
        # print(s, s2, S[i + j + 2:N])
        if s2 in visited[s]:
            continue
        count += len(set(S[i + j + 2:N]))
        visited[s].append(s2)
        # print(s, s2, set(S[j + 1:N]))
print(count)
### BUGGY CODE ###

n=int(input())
s=[''.join(sorted(input())) for i in range(n)]
ans=0
#dict={}

# for i in s:
#   if i in dict:
#     ans+=dict[i]
#     dict[i]+=1
#   else:
#     dict[i]=1

# print(dict)
for i in range(n-1):
  for j in range(i+1,n):
    if s[i] == s[j]:
      ans += 1

print(ans)


### FIXED CODE ###

n = int(input())
s = ["".join(sorted(str(input()))) for i in range(n)]
d = {}
ans = 0
for i in s:
    if i not in d:
        d[i] = 0
    else:
        d[i] += 1
        ans += d[i]
print(ans)
### BUGGY CODE ###

from operator import itemgetter
import sys
sys.setrecursionlimit(10**5)

def f(x, po, h, t, ple):
    if po=='h':
        ple+=B[x][1]*abs(B[x][0]-h)
        h+=1
    else:
        ple+=B[x][1]*abs(B[x][0]-t)
        t-=1
    if h>t:
        return ple
    
    ans1=f(x+1, 'h', h, t, ple)
    ans2=f(x+1, 't', h, t, ple)
    return max(ans1, ans2)

N=int(input())
A=list(map(int, input().split()))
B=[[i, A[i]] for i in range(N)]
B=sorted(B, key=itemgetter(1), reverse=True)
h=0
t=N-1
ans1=f(0, 'h', h, t, 0)
ans2=f(0, 't', h, t, 0)
print(max(ans1, ans2))

### FIXED CODE ###

from operator import itemgetter
N=int(input())
A=list(map(int, input().split()))
B=[[i, A[i]] for i in range(N)] 
B=sorted(B, key=itemgetter(1), reverse=True)

dp=[[0]*(N+1) for _ in range(N+1)]

for x in range(N):
    dp[x+1][0]=dp[x][0]+B[x][1]*abs(B[x][0]-x)
    
for y in range(N):
    dp[0][y+1]=dp[0][y]+B[y][1]*abs(N-1-y-B[y][0])
    
for z in range(2, N+1):
    for x in range(1, z):
        y=z-x
        dp[x][y]=max(dp[x][y-1]+B[z-1][1]*abs(N-y-B[z-1][0]), dp[x-1][y]+B[z-1][1]*abs(x-1-B[z-1][0]))
        
print(max([dp[x][N-x] for x in range(N+1)]))
### BUGGY CODE ###

n, x, y = map(int,input().split())
d = {}
for i in range(1, n+1):
    for j in range(i+1, n+1):
        l = min(abs(j-i), abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(j-x))
        d[l] = 1 if l not in d else d[l] + 1
for i in range(1, n):
    if i in d:
        print(d[i])
    else:
        print(0)


### FIXED CODE ###

n, x, y = map(int,input().split())
li = [0] * (n - 1)
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        k = min(j - i, abs(i - x) + abs(j - y) + 1)
        li[k - 1] += 1
for i in li:
    print(i)
### BUGGY CODE ###

# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    S = input().rstrip()

    N = len(S)

    res = 0

    for d in range(4,N):
        for i in range(N-d+1):
            temp = S[i:i+d]
            temp = int(temp)
            if temp % 2019 == 0:
                res += 1

    print(res)



main()


### FIXED CODE ###

import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
from numba import njit, i8


# @njit(i8[:](i8,i8,i8[:]))
@njit
def loof(a,N):
    M = np.zeros(2019,dtype=np.int16)
    M[0] += 1
    T = 0
    r = 1
    T += a[-1] * r
    T %= 2019
    M[T] += 1
    for i in range(N-2,-1,-1):
        r *= 10
        r %= 2019
        T += a[i] * r
        T %= 2019
        M[T] += 1
    return M


# @njit
# def pow_mod(a,n,mod):
#     memo = np.array([1])
#     if n >= 1:
#         for i in range(n-1):
#             memo = np.append(memo,memo[-1]*a%mod)
#         return memo
#     else:
#         return memo[0]


def main():
    S = input().rstrip()
    S = list(map(int,list(S)))
    a = np.array(S)

    N = len(a)

    # memo = pow_mod(10,N,2019)
    M = loof(a,N)

    res = 0

    for m in M:
        res += m * (m-1) // 2

    print(res)


main()
### BUGGY CODE ###

import numpy as np
if __name__ == "__main__":
  n, m = list(map(int, input().split())) 
  A = list(map(int, input().split()))
  A = np.array(A)

  for i in range(m):
    a = np.argmax(A)
    A[a] = A[a] // 2

  print(np.sum(A))

### FIXED CODE ###

import heapq
if __name__ == "__main__":
  n, m = list(map(int, input().split()))
  A = list(map(int, input().split()))
  A_inv = [-a for a in A]
  heapq.heapify(A_inv)
  for i in range(m):
    max_inv = heapq.heappop(A_inv)
    heapq.heappush(A_inv, -(-max_inv//2))
  print(-sum(A_inv))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 7)

def solve(index: int, dp: list, footing: list, K: int) -> int:
    if dp[index] != -1:
        return dp[index]

    if index == 0:
        return 0
    elif index == 1:
        return abs(footing[1]-footing[0])

    tmp = 10 ** 10
    for k in range(1, min(K+1,index+1)):
        tmp = min(tmp, solve(index-k, dp, footing, K)+abs(footing[index]-footing[index-k]))

    #print(f'{tmp=}')
    dp[index] = tmp
    return tmp

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

dp = [-1] * N

ans = solve(N-1, dp, footing, K)

print(ans)


### FIXED CODE ###

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


dp = [10 ** 10] * N
dp = dp + [10 ** 10] * 1000
dp[0] = 0

footing = footing + [0] * 1000
# give
'''
for i in range(N-1):
    for k in range(1, K+1):
        if dp[i+k] > dp[i] + abs(footing[i+k] - footing[i]):
            dp[i+k] = dp[i] + abs(footing[i+k] - footing[i])

print(dp[N-1])
'''
# get
for i in range(1,N):
    for j in range(1,min(K+1, i+1)): 
        dp[i] = min(dp[i],dp[i-j] + abs(footing[i]-footing[i-j])) 

print(dp[N-1])
### BUGGY CODE ###

x = input()
while True:
    if "ST" in x:
        i = x.index("ST")
        x = x[:i] + x[i+2:]
    else:
        print(len(x))
        exit()


### FIXED CODE ###

x = input()
stack = []
for s in x:
    if s == "S":
        stack.append(s)
    elif s == "T" and len(stack) == 0 or stack[-1] == "T":
        stack.append(s)
    elif s == "T" and stack[-1] == "S":
        stack.pop()
print(len(stack))
### BUGGY CODE ###

N,Q = map(int,input().split())
S = input()
cnt = []
lrs = []
for i in range(Q):
        lrs.append(list(map(int,input().split())))

for k in range(len(S) - 1):
    if S[k] == 'A':
            if S[k+1] == 'C':
                    cnt.append(1)
    else:
            cnt.append(0)



for lr in lrs:
    print(sum(cnt[lr[0]-1:lr[1]-1]))  

### FIXED CODE ###

N,Q = map(int,input().split())
S = input()
cnt = [0] * (N + 1)
lrs = []
for i in range(Q):
        lrs.append(list(map(int,input().split())))

for i in range(N):
        cnt[i+1] = cnt[i] + (1 if S[i:i+2] == "AC" else 0)
for lr in lrs:
        print(cnt[lr[1] - 1] - cnt[lr[0] - 1])
### BUGGY CODE ###

n= int(input())
a = list(map(int, input().split()))
q = int(input())
b = [list(map(int,input().split())) for i in range(q)]
# print(b)
a_replace = a
for i in range(q):
  if b[i][0] in a_replace:
    a_replace = [b[i][1] if j==b[i][0] else j for j in a_replace]
  # print(a_replace)
  print(sum(a_replace))

### FIXED CODE ###

n= int(input())
a = list(map(int, input().split()))
q = int(input())
b = [list(map(int,input().split())) for i in range(q)]
num = [0]*(10**5+1)
for i in a:
  num[i] += 1
sum_a = sum(a)

for i in range(q):
  dif = b[i][1]-b[i][0]
  #print(dif)
  sum_a += dif*num[b[i][0]]
  num[b[i][1]] += num[b[i][0]]
  num[b[i][0]] = 0
  print(sum_a)
### BUGGY CODE ###

import collections
N = int(input())
A = list(map(int , input().split()))
a = collections.Counter(A)
S = len(a)
k = 0
for j in range (S):
    b = a.most_common()[j][1]
    if b > 1:
        k += b * (b-1)/2
    

for i in range(N):
    s = A[i]
    p = a[s]
    print(int(k - p + 1))

### FIXED CODE ###

import collections
N = int(input())
A = list(map(int , input().split()))
a = collections.Counter(A)
k = 0
def comb(n):
    return n * (n - 1) // 2
for j in a.values():
    k += comb(j)
    
for i in range(N):
    s = A[i]
    p = a[s]
    print(int(k - p + 1))
### BUGGY CODE ###

n = int(input())
a_list = list(map(int, input().split()))

ans = 1
for i in a_list:
              ans *= i
              
if ans > pow(10,18):
              print(-1)
else:
              print(ans)

### FIXED CODE ###

n = int(input())
a_list = list(map(int, input().split()))
ans = 1
for i in a_list:
  ans *= i
  if ans > 1000000000000000000:
    break

if ans > 1000000000000000000 and 0 not in a_list:
              print("-1")
elif 0 in a_list:
              print(0)
else:
              print(ans)
### BUGGY CODE ###

# https://beta.atcoder.jp/contests/agc014/submissions/1268295

from collections import deque

INF = float('inf')


def solve():
    H, W, K = map(int, input().split())
    a = [[False for _ in range(W)] for _ in range(H)]
    visited = [[False for _ in range(W)] for _ in range(H)]

    sy, sx = -1, -1
    for r in range(H):
        s = input()
        for c, x in enumerate(s):
            if x == '.':
                a[r][c] = True
            elif x == 'S':
                a[r][c] = True
                sy, sx = r, c

    q = deque()
    q.append((sy, sx, 0))
    t = INF
    n = 1
    while n > 0:
        r, c, k = q.popleft()
        n -= 1
        visited[r][c] = True
        t = min(t, r, H - 1 - r, c, W - 1 - c)

        if t == 0:
            print(1)
            return

        for dr, dc in (-1, 0), (1, 0), (0, -1), (0, 1):
            nr, nc = r + dr, c + dc
            if 0 <= nr < H and 0 <= nc < W and a[nr][nc] and not visited[nr][nc] and k + 1 <= K:
                q.append((nr, nc, k + 1))
                n += 1

    ans = 1 + (t + K - 1) // K

    print(ans)


if __name__ == '__main__':
    solve()


### FIXED CODE ###

# https://beta.atcoder.jp/contests/agc014/submissions/1268295
from collections import deque

dr = (0, 1, 0, -1)
dc = (1, 0, -1, 0)


def solve():
    H, W, K = map(int, input().split())
    a = [[False for _ in range(W)] for _ in range(H)]

    sy, sx = -1, -1
    for r in range(H):
        s = input()
        for c, x in enumerate(s):
            if x == '.':
                a[r][c] = True
            elif x == 'S':
                a[r][c] = True
                sy, sx = r, c

    visited = [[False for _ in range(W)] for _ in range(H)]
    visited[sy][sx] = True

    t = max(H, W)
    q = deque([(sy, sx, 0)])
    while q:
        r, c, k = q.popleft()

        t = min(t, r, H - 1 - r, c, W - 1 - c)
        # print(t)
        if t == 0:
            print(1)
            return

        for d_i in range(4):
            nr, nc = r + dr[d_i], c + dc[d_i]
            if 0 <= nr < H and 0 <= nc < W and a[nr][nc] and not visited[nr][nc] and k + 1 <= K:
                visited[nr][nc] = True
                q.append((nr, nc, k + 1))

    ans = 1 + (t + K - 1) // K

    print(ans)


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

N=int(input())
S=input()
#print(N,S)

count=0

for n1 in range(10):
 for n2 in range(10):
  string=''
  for i in range(N-2):
    if n1==int(S[i]):
       for j in range(i+1,N-1):
         if n2==int(S[j]):
          #print(n1,n2,S[j+1:])
          string +=S[j+1:]           
  count+=len(set(string))
     
    
print(count)


### FIXED CODE ###

N=int(input())
S=input()
#print(N,S)

count=0


for n1 in range(10):
 cond=0
 for i in range(N-2):
   if n1==int(S[i]):
      p1=i
      cond=1
      break
 if cond==1:
  for n2 in range(10):
    for j in range(p1+1,N-1):
      if n2==int(S[j]):
        p2=j
        cond=2
        break
    if cond==2:
     for n3 in range(10):
       #print(n3,S[p2+1:],str(n3) in S[p2+1:] )
       if str(n3) in S[p2+1:]:
        #print(n1,n2,n3)
        count+=1
        cond=0
      
              
print(count)
### BUGGY CODE ###

def main():
    N, K = map(int, input().split())
    XY = [tuple(map(int, input().split())) for _ in range(N)]
    XY.sort()
    XY = tuple(XY)

    def count(x_min, x_max, y_min, y_max, i, j):
        OK = 0
        # NG = 0
        for m in XY[i:j + 1]:
            if y_min <= m[1] <= y_max:
                OK += 1
        if OK >= K:
            return True
        return False

    ans = 10 ** 20
    for i, val_i in enumerate(XY[:N - 1]):
        a = val_i[0]
        for j in range(i + K - 1, N):
            b = XY[j][0]
            e = b - a
            # print (e, i, j)
            for k in XY:
                c = k[1]
                for l in XY:
                    d = l[1]
                    if c < d:
                        if count(a, b, c, d, i, j):
                            # print ('A')
                            ans = min(ans, e * (d - c))
    print (ans)
    return

if __name__ == '__main__':
    main()


### FIXED CODE ###

#PythonだとTLEする
N, K = map(int, input().split())
X = [0] * N
Y = [0] * N
for i in range(N):
    x, y = map(int, input().split())
    X[i] = x
    Y[i] = y

def count(x_min, x_max, y_min, y_max):
    cnt = 0
    for i in range(N):
        if x_min <= X[i] <= x_max and y_min <= Y[i] <= y_max:
            cnt += 1
    return cnt

ans = 10 ** 20
for i in range(N):
    for j in range(N):
        for k in range(N):
            for l in range(N):
                # print ('i, j , k, l = ', i, j, k, l)
                if X[i] < X[j] and Y[k] < Y[l]:
                    if count(X[i], X[j], Y[k], Y[l]) >= K:
                        # print ('A')
                        ans = min(ans, (X[j] - X[i]) * (Y[l] - Y[k]))
print (ans)