Harryxun/stf_run huggingface dataset:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import combinations_with_replacement
def main():
    s = input()
    t = input()
    if t in s:
        print(0)
        sys.exit()
    lent = len(t)
    com = combinations_with_replacement(range(lent+1), 2)
    res = []
    for come in com:
        tmp = t[come[0]:come[1]]
        if tmp:
            if tmp in s:
                res.append(sum(come))
    res.sort()
    r = res[1]
    print(r)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    s = input()
    t = input()
    if t in s:
        print(0)
        sys.exit()
    if len(s) == 1 and len(t) == 1:
        if t != s:
            print(1)
            sys.exit()
    lens = len(s)
    lent = len(t)
    res = set()
    for i1 in range(lens - lent + 1):
        tmp1 = sum([c1 == c2 for c1, c2 in zip(t, s[i1:i1+lent])])
        res.add(lent - tmp1)
        #print(s[i1:i1+lent], res)
    if res:
        r = min(res)
        print(r)
    else:
        print(lent)

if __name__ == '__main__':
    main()
import sys

a, b, c, k = map(int, input().split())
if a >= k:
    print(k)
    sys.exit()
elif a + b >= k:
    print(a)
    sys.exit()

ones = [1] * a
zeros = [0] * b
negas = [-1] * c

totals = []
totals.extend(ones)
totals.extend(zeros)
totals.extend(negas)

totals = totals[0:k]
print(sum(totals))


### FIXED CODE ###

import sys

a, b, c, k = map(int, input().split())
if a >= k:
    print(k)
    sys.exit()

total = a
k = k - a
if k <= 0:
    print(total)
    sys.exit()

k = k - b
if k <= 0:
    print(total)
    sys.exit()

print(total - k)
a, b= int(input().split())

print(a * b)

### FIXED CODE ###

a, b= input().split()

print(int(a) * int(b))
S = input()
ACGT = ["A", "C", "G", "T"]
count = 0
mx = 0
if S[0] in ACGT:
    count += 1
for i in range(len(S)-1):
    if S[i+1] in ACGT:
        if S[i] in ACGT:
            count += 1
    else:
        ans = max(mx, count)
        count = 0
        mx = ans
print(ans)

### FIXED CODE ###

S = input()
ACGT = ["A", "C", "G", "T"]
K = []
for i in range(len(S)):
    if S[i] in ACGT:
        K.append(i)
if len(K) == 0:
    ans = 0
elif len(K) == 1:
    ans = 1
else:
    count = 0
    mx = 0
    for j in range(len(K)-1):
        if K[j+1]-K[j] == 1:
            count += 2
        else:
            ans = max(count, mx)
            count = 0
            mx = ans
    ans = max(count, mx)
    ans = ans/2 + 1
print(int(ans))
d = {}
S = []
N,K = map(int,input().split())
A = list(map(int,input().split()))
s = 0
for i in range(1,N+1):
    s = (s+A[i-1])%K
    k = (s-i)%K
    if k not in S:
        S.append(k)
        d[k] = 0
    d[k] += 1
ans = 0
for i in range(len(S)):
    x = S[i]
    y = d[x]
    ans += (y*(y-1))//2
ans += d[0]
print(ans)


### FIXED CODE ###

N,K = map(int,input().split())
S = []
d = {}
A = list(map(int,input().split()))
ans = 0
sum =0
for i in range(1,N+1):
    sum += A[i-1] % K
    s = (sum - i) % K
    if i > K:
        x = S.pop(0)
        d[x] -= 1
    elif i < K:
        if s == 0:
            ans += 1
    if s not in d:
        d[s] = 0
    ans += d[s]
    d[s] += 1
    S.append(s)
print(ans)
n, k = map(int, input().split())
k = min(n, k)
v = list(map(int, input().split()))
M = 0

for left in range(k + 1):
    for right in range(k - left + 1):
        hold = []
        hold.extend(v[:left])
        hold.extend(v[n-right:])
        hold.sort()
        total = sum(hold)
        for i in range(k - left - right):
            if i > len(hold):
                break
            if 0 <= hold[i]:
                break
            if hold[i] < 0:
                total -= hold[i]

        M = max(M, total)

print(M)



### FIXED CODE ###

n, k = map(int, input().split())
v = list(map(int, input().split()))
M = 0

for left in range(k + 1):
    for right in range(k - left + 1):
        if left + right > n:
            break
        hold = []
        hold.extend(v[:left])
        hold.extend(v[n-right:])
        hold.sort()
        total = sum(hold)
        for i in range(min(k - left - right, left + right)):
            if 0 <= hold[i]:
                break
            total -= hold[i]
        M = max(M, total)

print(M)
abc = [int(input().split())]
print(sum(abc) - max(abc))


### FIXED CODE ###

abc = list(map(int, input().split()))
print(sum(abc) - max(abc))
a=input()
b=a*a*a
print(b)

### FIXED CODE ###

a=input()
a=int(a)
b=a*a*a
print(b)
a = input().split(" ")
m = len(a)
b = 0
while b < m :
    if a[b]=="0"
    print(b)
    b = b + 1

### FIXED CODE ###

a = input().split(" ")
m = len(a)
b = 0
while b < m :
    if a[b] == "0":
        print(b + 1)
    b = b + 1
from fractions import gcd
n=int(input())
a=[int(i) for i in input().split()]

class SegmentTree:
    # 初期化処理
    # f : SegmentTreeにのせるモノイド
    # default : fに対する単位元
    def __init__(self, size, f=lambda x,y : gcd(x,y), default=0):
        self.size = 2**(size-1).bit_length() # 簡単のため要素数Nを2冪にする
        self.default = default
        self.dat = [default]*(self.size*2) # 要素を単位元で初期化
        self.f = f

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])

    def query(self, l, r):
        l += self.size
        r += self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1

            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres) # モノイドでは可換律は保証されていないので演算の方向に注意
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res
    
tree = SegmentTree(n)
for i in range(n):
    tree.update(i,a[i])

max_=tree.query(1,n+1)
for i in range(1,n-1):
    max_=max(max_,gcd(tree.query(0,i+1),tree.query(i+1,n+1)))
max_=max(max_,tree.query(0,n))
print(max_)

### FIXED CODE ###

import fractions
n=int(input())
a=[int(i) for i in input().split()]

class SegmentTree:
    # 初期化処理
    # f : SegmentTreeにのせるモノイド
    # default : fに対する単位元
    def __init__(self, size, f=lambda x,y : fractions.gcd(x,y), default=0):
        self.size = 2**(size-1).bit_length() # 簡単のため要素数Nを2冪にする
        self.default = default
        self.dat = [default]*(self.size*2) # 要素を単位元で初期化
        self.f = f

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])

    def query(self, l, r):
        l += self.size
        r += self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1

            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres) # モノイドでは可換律は保証されていないので演算の方向に注意
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res
    
tree = SegmentTree(n)
for i in range(n):
    tree.update(i,a[i])

max_=tree.query(1,n)
for i in range(1,n-1):
    max_=max(max_,fractions.gcd(tree.query(0,i),tree.query(i+1,n)))
max_=max(max_,tree.query(0,n-1))
print(max_)
cards = int(input())
i = 0
cardlist = []
while(i < cards):
    cardlist.append(list(map(str,input().split())))
    i += 1
SP = [0] * 13
HR = [0] * 13
CL = [0] * 13
DY = [0] * 13
    
for i in cardlist:
    num = int(i[1])
    if  (i[0] == "S"):
        SP[num] = 1
    elif(i[0] == "H"):
        HR[num] = 1
    elif(i[0] == "C"):
        CL[num] = 1
    elif(i[0] == "D"):
        DY[num] = 1

c = 0
for i in SP:
    c += 1
    if i == 1:
        print("S %d" %c)
c = 0
for i in HR:
    c += 1
    if i == 1:
        print("H %d" %c)
c = 0
for i in CL:
    if i == 1:
        print("C %d" %c)
c = 0
for i in DY:
    if i == 1:
        print("D %d" %c)
print()


### FIXED CODE ###

cards = int(input())
i = 0
cardlist = []
while(i < cards):
    cardlist.append(list(map(str,input().split())))
    i += 1
SP = [False] * 13
HR = [False] * 13
CL = [False] * 13
DY = [False] * 13

for i in cardlist:
    num = int(i[1])-1
    if  (i[0] == "S"):
        SP[num] = True
    elif(i[0] == "H"):
        HR[num] = True
    elif(i[0] == "C"):
        CL[num] = True
    elif(i[0] == "D"):
        DY[num] = True

c = 0
for i in SP:
    c += 1
    if i == False:
        print("S %d" %c)
c = 0
for i in HR:
    c += 1
    if i == False:
        print("H %d" %c)
c = 0
for i in CL:
    c += 1
    if i == False:
        print("C %d" %c)
c = 0
for i in DY:
    c += 1
    if i == False:
        print("D %d" %c)
import sys
sys.setrecursionlimit(2000000)
N,K = map(int,input().split())
A = list(map(int,input().split()))
def gcd(a,b):
    return a if b==0 else gcd(b,a%b)
g = gcd(A[0],A[1])
for i in range(2,N):
    g = gcd(g,A[i])
if K <= max(A) and K%g==0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

### FIXED CODE ###

import sys
sys.setrecursionlimit(2000000)
N,K = map(int,input().split())
A = list(map(int,input().split()))
def gcd(a,b):
    return a if b==0 else gcd(b,a%b)
if N ==1:
    g = A[0]
else:
    g = gcd(A[0],A[1])
    if N > 2:
        for i in range(2,N):
            g = gcd(g,A[i])
if K <= max(A) and K%g==0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
n=int(input())
n,k=map(int,input().split())
l=[int(i) for i in input().split()]
cnt=[0]*9
ans=0
for i in l:
    if i>3199:
        i=3200
    cnt[i//400]+=1
for p in range(n-1):
    i=cnt[p]
    if i!=0:
        ans+=1
print(ans if ans!=0 else 1,ans+cnt[-1])

### FIXED CODE ###

n=int(input())
l=[int(i) for i in input().split()]
cnt=[0]*9
ans=0
for i in l:
    if i>3199:
        i=3200
    cnt[i//400]+=1
for p in range(8):
    i=cnt[p]
    if i!=0:
        ans+=1
print(ans if ans!=0 else 1,ans+cnt[-1])
import sys 
import numpy as np

N = int(sys.stdin.readline())
P = np.array([int(x) for x in sys.stdin.readline().split()])

SUM = np.sum([np.sum([np.min(P[l:r+1]) for r in range(l, N)]) for l in range(N)])

print(SUM)

### FIXED CODE ###

line = input()

ori = len(line)

count = 0 

T = 0 
S = 0 

for i in line:
    if i is "S":
        S += 1
    else:
        if S is not 0:
            S -= 1
            count += 1

print(ori - count * 2)
N, M = map(int, input().split())
list = list(map(int, input().split()))

m=0
for i in range (0, len(list)):
	m=m+list[i]

if N-m>=0:
print(N-m)
elif N-m<0:
print(-1)

### FIXED CODE ###

R=input()
R=int(R)
print(R*2*3.14)
N, M = map(int, input().split())
a_list = list(map(int, input().split()))

items = {
    1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6
}
dp = [0] * (N + 1)

b_list = []
for a in a_list:
    need = items[a]
    if need <= N:
        dp[need] = a
        b_list.append(a)

M = len(b_list)
b_list.sort()
for i in range(N + 1):
    for b in b_list:
        if i - items[b] >= 0:
            if dp[i - items[b]] != 0:
                if dp[i - items[b]][0] < b:
                    cnt = 0
                    num = dp[i - items[b]]
                    while num != 0:
                        cnt += 1
                        num //= 10
                    tmp = max(b * (10 ** cnt) + dp[i - items[b]], dp[i - items[b]] * 10 + b)
                    dp[i] = max(tmp, dp[i])
                else:
                    dp[i] = max(dp[i], dp[i - items[b]] * 10 + b)


print(dp[N])


### FIXED CODE ###

N, M = map(int, input().split())
a_list = list(map(int, input().split()))

items = {
    1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6
}

dp = [-float("inf")] * (N + 1)
b_list = []
for a in a_list:
    need = items[a]
    if need <= N:
        dp[need] = 1
        b_list.append(a)

M = len(b_list)
dp[0] = 0
for i in range(N + 1):
    for b in b_list:
        if i - items[b] >= 0:
            if dp[i - items[b]] != -float("inf"):
                dp[i] = max(dp[i], dp[i - items[b]] + 1)

b_list.sort(reverse=True)
ans = ""

for i in range(dp[N]):
    for b in b_list:
        if dp[N - items[b]] == dp[N] - 1:
            ans += str(b)
            N -= items[b]
            break
print(ans)
n = int(input())

l_prev = l0
l_next = l1

l_new = 0
for i in range(2, n+1):
    l_new = l_prev + l_next
    l_prev = l_next
    l_next = l_new
print(l_new)


### FIXED CODE ###

n = int(input())

l = [2, 1]
for i in range(2, n+1):
    l.append(l[i - 2] + l[i - 1])
print(l[n])
n,m=map(int,input().split())
a=list(map(int,input().split()))
a[0]%=m
for i in range(1,n):
	a[i]+=a[i-1]
	a[i]%=m
a.sort()
p=0
s=0
for i in range(1,n):
	if a[i]-a[p]:
		p=i-p
		s+=p*(p-1)/2
		p=i
p=n-p
s+=p*(p+1)/2
print(s)n,m=map(int,input().split())
a=list(map(int,input().split()))
a[0]%=m
for i in range(1,n):
	a[i]+=a[i-1]
	a[i]%=m
a.sort()
l=0
p=0
s=0
for i in range(0,n):
	if a[i]-l:
		p=i-p
		s+=p*(p+1)/2
		p=i
		l=a[p]
p=n-p
s+=(p+1)*(p+2)/2
print(s/2)

### FIXED CODE ###

n,m=map(int,input().split())
a=[0]+list(map(int,input().split()))
a[0]%=m
for i in range(1,n+1):
	a[i]+=a[i-1]
	a[i]%=m
a.sort()
p=0
s=0
for i in range(1,n+1):
	if a[i]-a[p]:
		l=a[i]
		p=i-p
		s+=p*(p-1)
		p=i
p=n-p
s+=p*(p+1)
print(int(s/2))
X=int(input())
for i in range(2,X):
  if(X%i==0):
    X+=1
    break
  else:
    if(i<X):
      continue
    else
      print(X)

### FIXED CODE ###

def isPrime(x):
  if x < 2:
    return False
  for i in range(2,x):
    if x%i == 0:
      return False
  return True

num = int(input())

for i in range(num,100004):
  if isPrime(i):
    print(i)
    break
n = int(input())
a_list = list(map(int,input().split))
reversed_a_list = a_list.reverse()
a = ' '.join(reversed_a_list)
print(a)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))[::-1]
print(' '.join(map(str,a)))
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

X = n()

dp = [0] * (X+1)
dp[1] = 1
for i in range(2, X+1):
    j = dp[i-1]
    if dp[i - j] < dp[i-1]:
        dp[i] = dp[i-1]
    else:
        dp[i] = dp[i-1]+1
print(dp[X])


### FIXED CODE ###

nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

X = n()

for x in range(1, X):
    if x * (x + 1) // 2 >= X:
        print(x)
        import sys
        sys.exit()

print(X)
import sys
print(sys.argv[1])

### FIXED CODE ###

i = int(raw_input())
print(i ** 3)
s = input()
print("ARC" if input()=="ABC" else "ABC")

### FIXED CODE ###

s = input()
print("ABC" if s== "ARC" else "ARC")
n = int(input())
list = list(map(int, input().split()))
for i in range(len(list)-1):
  copy_list = list.copy()
  copy_list.pop(i)
  copy_list.sort()
  print(copy_list[int(n/2-1)])

### FIXED CODE ###

a, b, x = map(int, input().split())

if x >= a and x <= a + b:
  print('YES')
else:
  print('NO')
import math

N = int(input())
answer = []
b = 0
for a in range(1,round(sqrt(N))+1):
  if N%a == 0:
    b = N//a
    answer.append(max(len(str(a)), len(str(b))))
print(min(answer))


### FIXED CODE ###

import math

N = int(input())
answer = []
b = 0
for a in range(1,round(math.sqrt(N))+1):
  if N%a == 0:
    b = N//a
    answer.append(max(len(str(a)), len(str(b))))
print(min(answer))
n,p=map(int,input().split())
s=input()[::-1]
A=[0]*n
D=[0]*n
M=[0]*n
ans=0
if p==2 or p==5:
    for i in range(n):
        if int(s[i])%p==0:
            ans+=i+1
else:
    for i in range(n):
        tmp=int(s[i])*10**i
        A[i]=tmp%p
    D[0]=A[0]
    M[D[0]]+=1
    for i in range(1,n):
        D[i]=(D[i-1]+A[i])%p
        M[D[i]]+=1
        ans+=(M[D[i]]-1)
    ans+=D.count(0)
print(ans)

### FIXED CODE ###

n,p=map(int,input().split())
s=input()
ans=0
if p==2 or p==5:
    for i in range(n):
        if int(s[i])%p==0:
            ans+=i+1
else:
    M=[0]*p
    M[0]=1
    tmp=0
    for i in range(n):
        tmp+=(int(s[-i-1])*pow(10,i,p))
        tmp%=p
        ans+=M[tmp]
        M[tmp]+=1
print(ans)
a, b =[int(x) for x in input().split()]
import numpy as np
n=a*b
A = np.array(a)
B = np.array(b)
if np.gcd(A, B) == 1:
  print(n)

elif a > b:
  for i in range(a, n+1):
    if (i%a == 0)and(i%b == 0):
      print(i)
      break
else:
  for i in range(b, n+1):
    if (i%a == 0)and(i%b == 0):
      print(i)
      break

### FIXED CODE ###

a, b = [int(x) for x in input().split()]
# a = [int(input()) for _ in range(m)]
# a = [int(x) for x in input().split()]

from fractions import gcd



print((a*b)//gcd(a, b))
N = int(input())
lis = list(map(int,input().split()))
x = 0
lis.sort()
for i in range(0,N):
        if lis[i] == lis[i+1]:
                x = 1
                break
if x == 0:
        print("YES")
else:
        print("NO")

### FIXED CODE ###

N = int(input())
lis = list(map(int,input().split()))
lis.sort()
judge = 0
for i in range(1,N):
    if lis[i-1] == lis[i]:
        judge = 1
if judge == 0:
    print("YES")
else:
    print("NO")
N, K = map(int, input().split())
p = list(map(int, input().split()))

calEnd = N - 2
calCount = 0
calRes = 0
calIndex = 0
calCor = 0
calList = []
Counter = 0

for i in range(N - 2):
    calTemp = p[i] + p[i + 1] + p[i + 2]
    if calRes <= calTemp:
       calRes = calTemp
       calIndex = i
    
    calCount += 1

for o in range(K):
    cal = list(range(1, p[calIndex + Counter] + 1))
    Counter += 1
    calList.append(sum(cal) * (1 / len(cal)))

calCor = sum(calList)
print(calCor)

### FIXED CODE ###

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

expectedList = [(1 + s) /  2 for s in p]
cumsum = sum(expectedList[:K])
confirm_cumsum = cumsum

for i in range(K, N):
    cumsum += expectedList[i]
    cumsum -= expectedList[i - K]
    if cumsum > confirm_cumsum:
        confirm_cumsum = cumsum

print(confirm_cumsum)
memof = {}
def f(x,y,i):
    if i==N-1:
        return abs(A[N-1]-y)
    if (x,y,i) in memof:
        return memo[(x,y,i)]
    b = abs(A[N-1]-y)
    for j in range(i,N-1):
        b = max(b,g(A[j],y,j+1))
    memof[(x,y,i)]=b
    return b
memog = {}
def g(x,y,i):
    if i==N-1:
        return abs(x-A[N-1])
    if (x,y,i) in memog:
        return memog[(x,y,i)]
    b = abs(x-A[N-1])
    for j in range(i,N-1):
        b = min(b,f(x,A[j],j+1))
    memog[(x,y,i)] = b
    return b
N,Z,W = map(int,input().split())
A = list(map(int,input().split()))
print(f(Z,W,0))

### FIXED CODE ###

N,Z,W = map(int,input().split())
A = list(map(int,input().split()))
if N>=2:
    print(max(abs(A[-1]-A[-2]),abs(A[-1]-W)))
else:
    print(abs(A[0]-W))
N = int(input())
total = 0
for _ in range(N):
  x, u = input().split()
  i = int(x)
  if u == "JPY":
    tptal += i
  else:
    total += i*380000
print(total)    

### FIXED CODE ###

N = int(input())
total = 0
for _ in range(N):
  x, u = input().split()
  i = float(x)
  if u == "JPY":
    total += i
  else:
    total += i*380000
print(total)
import fractions
import itertools
import math

# nの約数をすべて求める
def make_divisors(n):
    divisors = {}
    #for i in range(1, int(n**0.5)+1):
    for i in itertools.takewhile(lambda i: i**2<=n, itertools.count(1)):
        if n % i == 0:
            divisors.add(i)
            if i != n // i:
                divisors.add(n//i)
    
    return divisors

# 素因数分解
# 素因数とその指数をペアにして配列で返す
def factorize(n):
    # 素因数の候補
    # i=2,...,floor(sqrt(n)) つまりi**2<=nになるまで
    remainder = n
    ret = {}
    for i in itertools.takewhile(lambda i: i**2<=n, itertools.count(2)):
        # 現在の余りをiで割れるだけ割る
        if remainder % i:
            continue
        else:
            # 割れるなら，割れる回数と余りを求める
            p = 0
            while remainder % i == 0:
                remainder //= i
                p += 1

            ret.add((i,p))

    # 2以上の余りが残っていれば，追加
    if remainder > 1: ret.add((remainder,1))

    return ret
        
    
A,B = map(int,input().split())

# 答えの集合は1or素数で構成されるとして良い (a*b,a>1,b>1となる要素があれば，aも公約数だから，a*bをaに置き換えても最適解になるから)
# つまり，A,Bをそれぞれ素因数分解し，共通の素因数の数を数えればよい
# これは，gcd(A,B)の素因数の数と同じ
gcd = fractions.gcd(A,B)
divs = factorize(gcd)
print(len(divs) + 1) # + 1は"1"の数

### FIXED CODE ###

import fractions
import itertools

# nの約数をすべて求める
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

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

# 最大公約数gcd
gcd = fractions.gcd(A,B)
# 公約数=最大公倍数gcdの約数
cd = make_divisors(gcd)
cd = sorted(cd)

# 小さいものから1つずつ
ans = set()
for x in cd:    
    if len(ans) == 0:
        # 集合が空なら
        ans.add(x)
    else:
        # 集合のどの要素ともxが互いに素なら，追加
        if all([fractions.gcd(x,y)==1 for y in ans]):
            ans.add(x)

#print(ans)
print(len(ans))
a=list(input())
o=0
for i in range(4):
  o+=1 if a[i]=='+' else o-=1
print(o)

### FIXED CODE ###

# -*- coding: utf-8 -*-
# input
a = input()
o = 0
for i in range(len(a)):
    if a[i] == '+':
        o += 1
    else:
        o -= 1
print(o)
while 1:
h,w = map(int, raw_input().split())
  if h==w==0
    break

for i in range(0,h/2):
  print ("#." * (w/2) + "#" * (w%2) + "\n")
  print (".#" * (w/2) + "." * (w%2) + "\n")

if h/2 == 1:
  print ("#." * (w/2) + "#" * (w%2) + "\n")

### FIXED CODE ###

while 1:
  h,w = map(int, raw_input().split())
  if h==w==0:
    break

  for i in range(0,h/2):
    print ("#." * (w/2) + "#" * (w%2))
    print (".#" * (w/2) + "." * (w%2))

  if h % 2 == 1:
    print ("#." * (w/2) + "#" * (w%2))

  print ""
N = int(input())

num=0

for s in input():
    if s=="R":
        num+=1
    else:
        num-=1

if num>0:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

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

if A == B and B == C:
    print("Yes")
else:
    print("No")
code = input()
if code = 'A':
	print('T')
elif code = 'T':
    print('A')
elif code = 'G':
    print('C')
elif code = 'C':
    print('G')


### FIXED CODE ###

code = input()
if code == 'A':
	print('T')
elif code == 'T':
    print('A')
elif code == 'G':
    print('C')
elif code == 'C':
    print('G')
A = list(map(int, input().split()))
A = sorted(A)
return sum(A[:2])

### FIXED CODE ###

A = list(map(int, input().split()))
A = sorted(A)
print(sum(A[:2]))
from itertools import accumulate
N,K = map(int,input().split())
td = [tuple(map(int,input().split())) for i in range(N)]

td.sort(key=lambda x:-x[1])
td = [(x[0]-1,x[1]) for x in td]
t = [-1]*N
for i in range(N):
    t[td[i][0]] = 0
tdK = td[td[:K]]
for i in range(K):
    t[tdK[i][0]] = 1

t_used = [i for i in range(N) if t[i]==1]
t_not_used = [i for i in range(N) if t[i]==0]

d_top = [0]*N
d_top_candi = [0]*N
d_rest = []
d_candi = []

for i in range(K):
    if t[td[i][0]] == 1:
        if d_top[td[i][0]] == 0:
            d_top[td[i][0]] = td[i][1]
        else:
            d_rest.append(td[i][1])
for i in range(K,N):
    if t[td[i][0]] == 0:
        if d_top_candi[td[i][0]] == 0:
            d_top_candi[td[i][0]] = 1
            d_candi.append(td[i][1])
l = len(t_used)
ans = l**2+sum(d_top)
d_rest.sort()
d_candi.sort(key=lambda x:-x)

d_rest_cum = list(accumulate(d_rest))
d_candi_cum = list(accumulate(d_candi))

if len(d_rest) == 0:
    print(ans)
else:
    ans += d_rest_cum[-1]

    for k in range(min(len(d_rest),len(d_candi))):
        ans = max(ans + (k+1)*(k+1+2*l) + d_candi_cum[k] - d_rest_cum[k],ans)

    print(ans)

### FIXED CODE ###

from itertools import accumulate
N,K = map(int,input().split())
td = [tuple(map(int,input().split())) for i in range(N)]

td = [(x[0]-1,x[1]) for x in td]
td.sort(key=lambda x:-x[1])

t = [-1]*N
for i in range(N):
    t[td[i][0]] = 0
tdK = td[:K]
for i in range(K):
    t[tdK[i][0]] = 1

t_used = [i for i in range(N) if t[i]==1]
t_not_used = [i for i in range(N) if t[i]==0]

d_top = [0]*N
d_top_candi = [0]*N
d_rest = []
d_candi = []

for i in range(K):
    if d_top[td[i][0]] == 0:
        d_top[td[i][0]] = td[i][1]
    else:
        d_rest.append(td[i][1])
for i in range(K,N):
    if t[td[i][0]] == 0:
        if d_top_candi[td[i][0]] == 0:
            d_top_candi[td[i][0]] = 1
            d_candi.append(td[i][1])
l = len(t_used)
s = sum(d_top)
ans = l**2 + s
d_rest.sort()
d_candi.sort(key=lambda x:-x)

d_rest_cum = list(accumulate(d_rest))
d_candi_cum = list(accumulate(d_candi))

if len(d_rest) == 0:
    print(ans)
else:
    ans += d_rest_cum[-1]
    s += d_rest_cum[-1]
    for k in range(min(len(d_rest),len(d_candi))):
        ans = max((l+k+1)**2 + s + d_candi_cum[k] - d_rest_cum[k],ans)

    print(ans)