Harryxun/stf_run huggingface dataset:
n, k = map(int,input().split())
t = [int(input().split()[0]) for i in range(n)]
d = [int(input().split()[1]) for i in range(n)]
def combinationListRecursive(data, r):
  if r == 0 or r > len(data):
    return []

  result = []
  _combinationListRecursive(data, r, 0, [], result)
  return result


def _combinationListRecursive(data, r, start, progress, result):
  if r == 0:
    result.append(progress)
    return

  for i in range(start, len(data)):
    _combinationListRecursive(data, r - 1, i + 1, progress + [data[i]], result)

result = combinationListRecursive(range(len(d)), k)
best = 0
for i in result:
    tarray = []
    dtmp = 0
    for k in range(k):
        dtmp += d[i[k]]
        tarray.append(t[i[k]])
    tlist = list(set(tarray))
    ttmp = len(tlist) ** 2
    if best < dtmp + ttmp:
        best = dtmp + ttmp
print(best)

### FIXED CODE ###

from heapq import heappush, heappop
N, K = map(int, input().split())
TD = [list(map(int, input().split())) for _ in range(N)]
TD.sort(key=lambda x:x[1], reverse=True)
muptiple = set()
hp = []
for t, d in TD:
    flg = 0
    if t not in muptiple:
        muptiple.add(t)
        flg = 1
    heappush(hp, (d*-1, flg))

ret = []
point = 0
vari = 0
total = 0
for i in range(K):
    v = heappop(hp)
    t = v[0]*-1
    vari += v[1]
    point += t
    if not v[1]:
        heappush(ret, t)

total = vari ** 2 + point

while len(hp) > 0 and len(ret) > 0:
    v = heappop(hp)
    if v[1] == 0:
        continue
    pre_t = heappop(ret)
    t = v[0]*-1
    point -= pre_t - t
    vari += 1
    tmp = vari ** 2 + point
    total = max(total, tmp)

print(total)
S = input()
W = input()
if W >= S:
    print('unsafe')
else:
    print('safe')

### FIXED CODE ###

num = map(int,input().split())
a = []
for i in num:
    a.append(i)
if a[0]<a[1]:
    print('unsafe')
elif a[0]>a[1]:
    print('safe')
else:
    print('unsafe')
r = int(input)
print(r**2)

### FIXED CODE ###

r = int(input())
print(r**2)
A,c,B=input().split()
if c=="+":
  print(A+B):
elif c=="-":
  print(A-B)
 

### FIXED CODE ###

A,c,B=input().split()
A=int(A)
B=int(B)
if c=="+":
  print(A+B)
elif c=="-":
  print(A-B)
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

N,P = map(int,input().split())

factor = prime_factors(P)

res_fac = factor[:N]
rem_fac = factor[N:]

index = 0
for i in rem_fac:
    if len(res_fac)-1 < index:
        index = 0
    res_fac[index] *= i
    index += 1

print(gcd_list(res_fac))

### FIXED CODE ###

import traceback
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

class PrimeFractorization:
    def __init__(self):
        self.a = 2

    def decomposit_prime(self, n):
        res = []
        try:
            while n >= self.a * self.a:
                if n % self.a == 0:
                    res.append(self.a)
                    #print(self.a, "* ", end="")
                    n //= self.a
                else:
                    self.a += 1

            res.append(n)
            
            return res

        except Exception as e:
            raise

N,P = map(int,input().split())

obj = PrimeFractorization()
factor = obj.decomposit_prime(P)

res_fac = factor[:N]
amari = factor[N:]

index = 0
for i in amari:
    if len(res_fac)-1 < index:
        index = 0
    res_fac[index] *= i
    index += 1

print(gcd_list(res_fac))
n = int(input())
abc=[]
for i in range(n-1):
    tmp = list(map(int,input().split()))
    abc.append(tmp)
q,k = map(int, input().split())
que = []
for i in range(q):
    tmp = list(map(int,input().split()))
    que.append(tmp)

from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
from scipy.sparse import csr_matrix

arr = [[0 for i in range(n)] for j in range(n)]
for a in abc:
    arr[a[0]-1][a[1]-1] = a[2]
    arr[a[1]-1][a[0]-1] = a[2]

dist = dijkstra(csr_matrix(arr),indices=[k-1])

for tmp in que:
    print(int(dist[0][tmp[0]-1] + dist[0][tmp[1]-1]))

### FIXED CODE ###

n = int(input())
abc=[]
for i in range(n-1):
    tmp = list(map(int,input().split()))
    abc.append(tmp)
q,k = map(int, input().split())
que = []
for i in range(q):
    tmp = list(map(int,input().split()))
    que.append(tmp)

link = [[] for _ in range(n)]
for tmp in abc:
    link[tmp[0]-1].append([tmp[1]-1,tmp[2]])
    link[tmp[1]-1].append([tmp[0]-1,tmp[2]])

dist=[-1]*n

from collections import deque
Q = deque()
Q.append([k-1,0])

while Q:
    now,now_d=Q.popleft()

    for nxt in link[now]:
        if dist[nxt[0]]!=-1:
            continue
        nxt_d =nxt[1] + now_d
        dist[nxt[0]]=nxt_d
        Q.append([nxt[0],nxt_d])

for tmp in que:
    print(dist[tmp[0]-1] + dist[tmp[1]-1])
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
TA=10**5+1
num=0
for i in range(n):
    if TA>abs(a-(t-h[i]*0.006))>0:
        num=i+1
        TA=abs(a-(t-h[i]*0.006))
 
print(num)

### FIXED CODE ###

x,y=map(int,input().split())
print(int(x+y/2))
n,m = map(int,input().split())
dp = [0]*(n+1)
dp[1],dp[2] = 1,1

for _ in range(m):
  a = int(input())
  dp[a] = -1

for i in range(1,n-1):
  if dp[i+2]==-1:
    continue
  if dp[i]==-1 and dp[i+1]==-1:
    dp[i+2] = -1
  elif dp[i]==-1:
    dp[i+2] = dp[i+1]
  elif dp[i+1]==-1:
    dp[i+2] = dp[i]
  else:
    dp[i+2] = dp[i] + dp[i+1]
    
print(dp[n]%(10**9+7) if dp[n]!=-1 else 0)

### FIXED CODE ###

n,m = map(int,input().split())
def Fib(n):
  seq = []
  a,b = 0,1
  for i in range(1,n+10):
    if i == 1:
      seq.append(0)
    elif i == 2:
      seq.append(1)
    else:
      a, b = b, a + b
      seq.append(b)
  return seq
table = Fib(n)
temp = -1
route = 1
mod = 10**9+7
for _ in range(m):
  a = int(input())
  dif = a-temp-1
  temp = a
  route = route*table[dif]%mod
print(route*table[n-temp]%mod)
y,m,d = map(int,input().split("/")

if y >= 2020:
    print("TBD")
elif y == 2019:
    if m >= 5:
    print("TBD")
else:
    print("Heisei")

### FIXED CODE ###

y,m,d = map(int,input().split("/"))

if y >= 2020:
    print("TBD")
elif y == 2019:
    if m >= 5:
        print("TBD")
    else:
        print("Heisei")   
else:
    print("Heisei")
l=list(map(int,input().split()))
l2=sort(l)
print(10*l2[2]+l2[1]+l2[0])

### FIXED CODE ###

l=list(map(int,input().split()))
l2=sorted(l)
print(10*l2[2]+l2[1]+l2[0])
def op_print(data,a,b):
    for i in range(a,b):
        print(data[i],end="")
    print()
def op_reverse(data,a,b):
    return data[:a] + data[::-1][-b:-a] + data[:b]
def op_replace(data,a,b,q):
    return data.replace(data[a:b],q) 

data = input()
q = int(input())
for _ in range(q):
    op = list(map(str,input().split()))
    if(op[0] == "print"):
        op_print(data,int(op[1]),int(op[2]-1))
    elif(op[0] == "reverse"):
        data = op_reverse(data,int(op[1]),int(op[2]))
    elif(op[0] == "replace"):
        data = op_replace(data,int(op[1]),int(op[2]),op[3])


### FIXED CODE ###

s=input()
for _ in range(int(input())):
    o=input().split()
    a,b=map(int,o[1:3]);b+=1
    c=o[0][2]
    if c=='p':s=s[:a]+o[3]+s[b:]
    elif c=='i':print(s[a:b])
    elif c=='v':s=s[:a]+s[a:b][::-1]+s[b:]
import math
a, b = map(int, input().split())

print(int((a*b)//math.gcd(a, b)))

### FIXED CODE ###

x = int(input())

ans = 0

for _ in range(10**5):
    if x == 2:
        print(x)
        break
    for i in range(2, int(x**0.5) + 1):
        if (x % i) == 0:
            break
        elif i == int(x**0.5): # ループの最後
            ans = x
        else:
            pass

    if ans != 0:
        print(ans)
        break
    else:
        x += 1
import sys, os
import collections

MOD = 10 ** 9 + 7

def solve(input_stream):
  pass

def read_ints(input_stream):
  return [i for i in map(int, input_stream.readline().strip().split())]

def read_int(input_stream):
  return int(input_stream.readline().strip())


if __name__ == "__main__":
    outputs = solve(sys.stdin)
    for line in outputs:
      print(line)

### FIXED CODE ###

import sys, os
import collections

MOD = 10 ** 9 + 7

def solve(input_stream):
  table = {
    "SUN": 7,
    "MON": 6,
    "TUE": 5,
    "WED": 4,
    "THU": 3,
    "FRI": 2,
    "SAT": 1
  }

  target = input_stream.readline().strip()
  return [str(table[target])]

def read_ints(input_stream):
  return [i for i in map(int, input_stream.readline().strip().split())]

def read_int(input_stream):
  return int(input_stream.readline().strip())


if __name__ == "__main__":
    outputs = solve(sys.stdin)
    for line in outputs:
      print(line)
s=input()
for i in range(len(s)):
    if i>=1:
        if s[i]==s[i-1]:
            print(i-1 + ' ' + i)
            exit()
    if i>=2:
        if s[i]==s[i-2]:
            print(i-2 + ' ' + i)
            exit()
print(-1 -1)

### FIXED CODE ###

s=input()
for i in range(len(s)):
    if i>=1:
        if s[i]==s[i-1]:
            print(i, i+1)
            exit()
    if i>=2:
        if s[i]==s[i-2]:
            print(i-1, i+1)
            exit()
print(-1, -1)
while True:
    N = int(input())
    if N == 0: break
    W,H = map(int,input().split())
    fld = [[0 for w in range(W)] for h in range(H)]
    for i in range(N):
        x,y = map(lambda s:int(s)-1,raw_input().split())
        fld[y][x] = 1
    cums = [[0 for w in range(W+1)] for h in range(H+1)]
    for y in range(H):
        for x in range(W):
            cums[y+1][x+1] = fld[y][x] + cums[y][x+1] + cums[y+1][x] - cums[y][x]
    S,T = map(int,input().split())
    ans = 0
    for y in range(H-T+1):
        for x in range(W-S+1):
            ans = max(ans, cums[y+T][x+S] - cums[y+T][x] - cums[y][x+S] + cums[y][x])
    print(ans)

### FIXED CODE ###

while True:
    N = int(input())
    if N == 0: break
    W,H = map(int,input().split())
    fld = [[0 for w in range(W)] for h in range(H)]
    for i in range(N):
        x,y = map(lambda s:int(s)-1,input().split())
        fld[y][x] = 1
    cums = [[0 for w in range(W+1)] for h in range(H+1)]
    for y in range(H):
        for x in range(W):
            cums[y+1][x+1] = fld[y][x] + cums[y][x+1] + cums[y+1][x] - cums[y][x]
    S,T = map(int,input().split())
    ans = 0
    for y in range(H-T+1):
        for x in range(W-S+1):
            ans = max(ans, cums[y+T][x+S] - cums[y+T][x] - cums[y][x+S] + cums[y][x])
    print(ans)
N,M=map(int,input().split())
X=[int(i) for i in input().split()]
X.sort()
count=[]
sum=0
if n<=m:
  for i in range(M):
    if i != 0:
      count.append(X[i]-get)
      sum+=count[i-1]
    get=X[i]
  count.sort(reverse=True)
  if count != []:
    for i in range(N-1):
      sum-=count[i]
print(sum)

### FIXED CODE ###

N,M=map(int,input().split())
X=[int(i) for i in input().split()]
X.sort()
count=[]
sum=0
if N<M:
  for i in range(M):
    if i != 0:
      count.append(X[i]-get)
      sum+=count[i-1]
    get=X[i]
  count.sort(reverse=True)
  if count != []:
    for i in range(N-1):
      sum-=count[i]
print(sum)
total, tar = list(map(int, input().split()))
dice_array = list(map(int, input().split()))

dice_total = [0]

for i in range(total):
  dice_total.append(dice_array[i] + dice_total[i])

ans = dice_total[tar]
tar_num = tar
for i in range(total - tar):
  tmp = dice_total[i + 1 + tar] - dice_total[i + 1]
  if ans < tmp:
    tmp = ans
    tar_num = i + 1

sum_data = 0
cnt = 0
for x in range(tar_num, tar + tar_num):
  cnt = sum(list(range(1, dice_array[x] + 1)))
  sum_data += (cnt / dice_array[x])
  
print(sum_data)


### FIXED CODE ###

total, tar = list(map(int, input().split()))
dice_array = list(map(int, input().split()))

hope_array = [0.0] * total
for i in range(total):
   hope_array[i] = (dice_array[i] * (dice_array[i] + 1)) / 2 / dice_array[i]

dice_total = [0]
 
for i in range(total):
  dice_total.append(hope_array[i] + dice_total[i])
 
ans = dice_total[tar]
tar_num = tar
for i in range(total - tar):
  tmp = dice_total[i + 1 + tar] - dice_total[i + 1]
  if ans < tmp:
    ans = tmp

print(ans)
S=input()
T='AKIHABARA'
i=0;j=0
while 1:
    if S[i]==T[j]:i+=1;j+=1
    elif 'A'==T[j]:j+=1
    else:break
    if i>=len(S):break
print('YES'if i==len(S) else 'NO')

### FIXED CODE ###

S=input()
N=len(S)
K,I,H,B,R=S.find('K'),S.find('I'),S.find('H'),S.find('B'),S.find('R')
f = (K==0 or K==1) and K==I-1==H-2 and (H+1==B or S[H+1]=='A') and (B+1==R or S[B+1]=='A') and (R==N-2 and S[R+1]=='A' or R==N-1)
T='AKIHABARA'
i=0;j=0;g=True
while 1:
    if S[i]==T[j]:i+=1;j+=1
    elif T[j]=='A':j+=1
    else:g=False;break
    if i==len(S):break
    elif j==9:g=False;break
print('YES'if f and g else 'NO')
n = int(input())
a_list = list(map(int, input().split()))
result = [0]
for i in range(n - 1):
    if a_list[i] + result[i] > a_list[i + 1]:
        result.append(a_list[i] + result[i] - a_list[i + 1])
print(sum(result))

### FIXED CODE ###

n = int(input())
a_list = list(map(int, input().split()))
result = [0]
for i in range(n - 1):
    if a_list[i] + result[i] > a_list[i + 1]:
        result.append(a_list[i] + result[i] - a_list[i + 1])
    else:
        result.append(0)
print(sum(result))
import sys

N = int(input())
nums = list(map(int, input().split(' ')))

output = 1

if 0 in nums:
  print(0)
  sys.exit()
  
else:
  for x in nums:
    output *= x

    if output > 10**18:
      print('-1')
      sys.exit()

  print(output)

### FIXED CODE ###

N, M = input().split(' ')
N, M = int(N), int(M)

print(N*M)
n,k = map(int, input().split())
h = list(map(int, input().split()))

dp = [10**10]*(n+1)
dp[0] = 0

for i in range(n):
  for j in range(1,k+1):
    if i+j==n:
      break
    dp[i+j] = min(dp[i+j], dp[i] + abs(h[i]-h[i+j]))
  print(dp)
  
print(dp[n-1])

### FIXED CODE ###

n,k = map(int, input().split())
h = list(map(int, input().split()))

dp = [0]*(n)
dp[0] = 0

for i in range(1, n):
  j = max(0, i-k)
  dp[i] = min([dpk + abs(h[i]-hk) for dpk, hk in zip(dp[j:i], h[j:i])])
  
print(dp[n-1])
import sys

lines = sys.stdin.readlines()

a, b, k = map(int, lines[0].split())

if a => k:
    a = 0
    k = k - a
    if b => k:
        b = 0
        k = k - b
else:
    a = a - k

print(a, b)

### FIXED CODE ###

import sys

lines = sys.stdin.readlines()

a, b, k = map(int, lines[0].split())

if a <= k:
    k = k - a
    a = 0
    if b <= k:
        k = k - b
        b = 0
    else:
        b = b - k
else:
    a = a - k

print(a, b)
import sys

i = 0
x = 1

while x != 0:
  x = sys.stdin.readline()
  i += 1

  print 'Case %d: %s', %(i,x)
  

### FIXED CODE ###

i = 0
d = 0

while d == 0:
    x = input()
    if x != 0:
        i += 1
        print("Case %d: %d" %(i, x))
    else:
        d = 1
from collections import defaultdict

def readInput():
	return [int(i) for i in input().split(" ")]

(R, C) = readInput()
N = int(input())
rowIdx = set() 
grid = defaultdict(lambda:None)
rowGrid = defaultdict(set)
for i in range(N):
	(r, c, a) = readInput()
	r -= 1
	c -= 1
	rowGrid[r].add(c)
	grid[(r, c)] = a 
	rowIdx.add(r)

pairIdx = rowIdx.copy	
for i in rowIdx:
	pairIdx.remove(i)
	for j in pairIdx:
		tempRow = rowGrid[i]
		tempPair = rowGrid[j]
		mark = 1
		for k in tempRow:
			if (grid[(j, k)] != None):
				diff = grid[(i, k)] - grid[(j, k)]
				mark = 0 
		if (mark is 1):
			continue
		for m in tempRow:
			anchor = grid[(i, m)]
			anchorP = grid[(j, m)]
			if (anchorP is None and anchor < diff):
				print('No')
				exit()
			elif (anchorP is not None and anchor - anchorP != diff):
				print('No')
				exit()
		for n in tempPair:
			anchor = grid[(j, n)]
			anchorP = grid[(i, n)]
			if (anchorP is None and anchor < -diff):
				print('No')
				exit()
print('Yes')

### FIXED CODE ###

#A-Codefestival 2016
str=input()
str1=str[:4]+" "+str[4:]
print(str1)
s = list(input())
print("yes" is len(s) == len(set(s)) else "no")


### FIXED CODE ###

s = list(input())
print("yes" if len(s) == len(set(s)) else "no")
s = list(map(int, list(input())))
k = int(input())

cnt1 = 0
if s[0]==1:
    cnt1 += 1
    
for i in range(1, len(s)):
    if s[0] == 1 and s[i-1] == 1 and s[i] == s[i-1]:
        cnt1 += 1
        
if k <= cnt1:
    print(1)
elif cnt1 == 0:
    print(s[0])
else:
    print(s[cnt1])

### FIXED CODE ###

import sys
n = int(input())

#条件満たす数カウント
cn = 0
#約数カウント
cy = 0

if n < 105:
    print(0)
    sys.exit()
    
for i in range(105, n+1):
    if i % 2 == 0:
        continue

    for j in range(1, i+1):
        if i % j == 0:
            cy += 1
    if cy == 8:
        cn += 1
    cy = 0
print(cn)
# Square869120Contest #4 B - Buildings are Colorful!　
 
import sys
 
N, K = map(int, sys.stdin.readline().strip().split())
a = list(map(int, sys.stdin.readline().strip().split()))

if K == 0:
  break
 
def dfs(height=a[0], cost=0, target=K, can_see=1, i=1):
    if can_see >= target:
        # print('height', height)
        # print('can_see', can_see)
        # print('cost', cost)
        return cost
 
    # 端まで探索したとき
    if i == len(a):
        return float('inf')
 
    # 建物 i を選ばない場合
    if height >= a[i]:
        cost1 = dfs(height=height, cost=cost, target=K, can_see=can_see, i=i+1)
    else:
        cost1 = dfs(height=a[i], cost=cost, target=K, can_see=can_see+1, i=i+1)
    # print('cost1', cost1, 'can_see', can_see, 'i', i)
 
    # 建物　i を選んだ場合
    cost += max(0, height + 1 - a[i])
    height = max(a[i], height + 1)
    cost2 = dfs(height=height, cost=cost, target=K, can_see=can_see+1, i=i+1)
    # print('cost2', cost2)
 
    return min(cost1, cost2)
 
 
print(dfs(a[0], cost=0, target=K, can_see=1, i=1))

### FIXED CODE ###

# Square869120Contest #4 B - Buildings are Colorful!　

import sys

N, K = map(int, sys.stdin.readline().strip().split())
a = list(map(int, sys.stdin.readline().strip().split()))


def dfs(height=a[0], cost=0, target=K, can_see=1, i=1):
    if can_see >= target:
        # print('height', height)
        # print('can_see', can_see)
        # print('cost', cost)
        return cost

    # 端まで探索したとき
    if i == len(a):
        return float('inf')

    # 建物 i を選ばない場合
    if height >= a[i]:
        cost1 = dfs(height=height, cost=cost, target=K, can_see=can_see, i=i+1)
    else:
        cost1 = dfs(height=a[i], cost=cost, target=K, can_see=can_see+1, i=i+1)
    # print('cost1', cost1, 'can_see', can_see, 'i', i)

    # 建物　i を選んだ場合
    cost += max(0, height + 1 - a[i])
    height = max(a[i], height + 1)
    cost2 = dfs(height=height, cost=cost, target=K, can_see=can_see+1, i=i+1)
    # print('cost2', cost2)

    return min(cost1, cost2)


print(dfs(a[0], cost=0, target=K, can_see=1, i=1))
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))

def lcm(a,b): return a*b//gcd(a,b)

l = A[0]
for i in range(1,N):
    l = lcm(l,A[i])
l -= 1

ans = 0
for a in A: ans += l % a
print(ans)

### FIXED CODE ###

A = sorted(map(int,input().split()))
ans = 0
for i in range(2): ans += A[i+1] - A[i]
print(ans)
print(["No","Yes"][input().sort()=="abc"])

### FIXED CODE ###

print(["No","Yes"]["".join(sorted(input()))=="abc"])
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools

COSTS = (99, 2, 5, 5, 4, 5, 6, 3, 7, 6)


def main():
  remain, _ = list(map(int, input().split()))

  costs = list(map(int, input().split()))
  costs = [(c, COSTS[c]) for c in costs]
  costs.sort(key=lambda x:x[1])

  num, cost = costs[0]
  costs.sort(key=lambda x:-x[0])

  nums = [num] * (remain // cost)
  remain -= cost * len(nums)

  if remain != 0:
    new_costs = []
    exists = set([0])

    for n, c in costs:
      nc = c - cost

      if nc <= remain and nc not in exists:
        new_costs.append((n, nc))

    max_repeat = min(remain // min(v[1] for v in new_costs), len(nums))
    rep_nums_list = []

    for repeat in range(1, max_repeat + 1):
      for idxs in itertools.product(range(len(new_costs)), repeat=repeat):
        nc = sum(new_costs[i][1] for i in idxs)

        if nc != remain:
          continue

        rep_nums_list.append([new_costs[i][0] for i in idxs])

    max_nums = [0] * len(nums)

    for rep_nums in rep_nums_list:
      uns = [v for v in rep_nums if v > num]
      lns = [v for v in rep_nums if v < num]
      new_nums = nums[:]

      if len(uns) > 0:
        new_nums = uns + new_nums[len(uns):]

      if len(lns) > 0:
        new_nums = new_nums[:-len(lns)] + lns

      if new_nums > max_nums:
        max_nums = new_nums

    nums = max_nums

  print(''.join(str(v) for v in nums), flush=True)


if __name__ == '__main__':
  main()



### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools

COSTS = (99, 2, 5, 5, 4, 5, 6, 3, 7, 6)


def gen(base_digit, base_cost, base_length, digits, remain):
  number = [base_digit] * base_length
  remain -= base_cost * base_length

  if remain == 0:
    print(''.join(str(d) for d in number), flush=True)
    return True

  digits = [(d, c - base_cost) for d, c in digits if d != base_digit and c - base_cost <= remain]

  if len(digits) == 0:
    return False

  max_repeat = min(remain // min(digits, key=lambda x: x[1])[1], len(number))
  numbers = []

  for repeat in range(1, max_repeat + 1):
    for idxs in itertools.product(range(len(digits)), repeat=repeat):
      if sum(digits[i][1] for i in idxs) != remain:
        continue

      replaces = [digits[i][0] for i in idxs]
      uppers = [d for d in replaces if d > base_digit]
      lowers = [d for d in replaces if d < base_digit]

      num = number[:]

      if len(uppers) > 0:
        num = uppers + num[len(uppers):]

      if len(lowers) > 0:
        num = num[:-len(lowers)] + lowers

      numbers.append(num)

  if len(numbers) == 0:
    return False

  number = max(numbers)

  print(''.join(str(d) for d in number), flush=True)

  return True


def main():
  remain, _ = list(map(int, input().split()))

  digits = {}

  for d in map(int, input().split()):
    if COSTS[d] not in digits or digits[COSTS[d]] < d:
      digits[COSTS[d]] = d

  digits = [(d, c) for c, d in digits.items()]
  base_digit, base_cost = min(digits, key=lambda x: x[1])

  for length in range(remain // base_cost, -1, -1):
    if gen(base_digit, base_cost, length, digits, remain):
      break


if __name__ == '__main__':
  main()
import heapq
import numpy as np

N, M = [int(x) for x in input().split(" ")]

e = {i: [] for i in range(N)}
for _ in range(M):
  a, b = [int(x)-1 for x in input().split(" ")]
  e[a] = e[a] + [b]
  e[b] = e[b] + [a]

# roots = [[int(x) for x in input().split(" ")] for _ in range(M)]

d = np.ones(N, dtype=int) * -1
# prev = np.ones(N, dtype=int) * -1
# q = [(d[0], 0)]
# heapq.heapify(q)

# while len(q) != 0:
#   c, u = heapq.heappop(q)
#   for nv in e[u]:
#     alt = d[u] + 1
#     if d[nv] > alt:
#       d[nv] = alt
#       prev[nv] = u
#       heapq.heappush(q, (alt, nv))

q = [d[0]]
while len(q) != 0:
  v = q.pop(0)
  for ne in e[v]:
    if d[ne] == -1:
      d[ne] = v
    q.append(ne)

print("Yes")
# for p in prev[1:]:
#   print(p+1)
print("\n".join([str(p+1) for p in d[1:]]))


### FIXED CODE ###

import numpy as np
N, M = map(int, input().split(" "))

goto = {i: [] for i in range(1, N+1)}
sign = np.zeros(N, dtype=int)
for _ in range(M):
  A, B = map(int, input().split(" "))
  goto[A].append(B)
  goto[B].append(A)

# print(goto)

visited = set([1])
queue = [1]
while len(queue) > 0:
  v = queue.pop(0)
  for nex in goto[v]:
    if nex in visited:
      continue
    sign[nex-1] = v
    queue.append(nex)
    visited.add(nex)
print("Yes")
for s in sign[1:]:
  print(s)
n=len(S)
ans=0
for i in range(n//2):
    if S[i]!=S[n-i-1]:
        ans+=1
print(ans)

### FIXED CODE ###

S=input()
n=len(S)
ans=0
for i in range(n//2):
    if S[i]!=S[n-i-1]:
        ans+=1
print(ans)