Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np

def solve(n, a, lst):
  m = max(max(lst), a)
  ans = np.zeros((n+1, n+1, n*m+1))
  #ans[i][j][k] : lst[:i]までの中からj枚選んで合計kにする選び方
  for i in range(n+1):
    for j in range(n+1):
      for k in range(n*m+1):
        if i == 0 and j == 0 and k == 0:
          ans[i][j][k] = 1
        elif i >= 1 and k < lst[i-1]:
          ans[i][j][k] = ans[i-1][j][k]
        elif i >= 1 and lst[i-1] <= k and j >= 1:
          ans[i][j][k] = ans[i-1][j-1][k-lst[i-1]] + ans[i-1][j][k]
        else:
          ans[i][j][k] = 0
  ret = 0
  for i in range(1,n+1):
    ret += ans[-1][i][i*a]
  return int(ret)

if __name__ == "__main__":
  n, a = map(int,input().split())
  x_list = [int(i) for i in input().split()]
  ans = solve(n,a,x_list)
  print(ans)


Fixed submission:
def solve(n, a, lst):
  m = max(max(lst), a)
  ans = [[[0]*(n*m+1) for i in range(n+1)] for j in range(n+1)]
  #ans[i][j][k] : lst[:i]までの中からj枚選んで合計kにする選び方
  for i in range(n+1):
    for j in range(n+1):
      for k in range(n*m+1):
        if i == 0 and j == 0 and k == 0:
          ans[i][j][k] = 1
        elif i >= 1 and k < lst[i-1]:
          ans[i][j][k] = ans[i-1][j][k]
        elif i >= 1 and lst[i-1] <= k and j >= 1:
          ans[i][j][k] = ans[i-1][j-1][k-lst[i-1]] + ans[i-1][j][k]
        else:
          ans[i][j][k] = 0
  ret = 0
  for i in range(1,n+1):
    ret += ans[-1][i][i*a]
  return int(ret)

if __name__ == "__main__":
  n, a = map(int,input().split())
  x_list = [int(i) for i in input().split()]
  ans = solve(n,a,x_list)
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

def solve(n, a, lst):
  m = max(max(lst), a)
  ans = np.zeros((n+1, n+1, n*m+1))
  #ans[i][j][k] : lst[:i]までの中からj枚選んで合計kにする選び方
  for i in range(n+1):
    for j in range(n+1):
      for k in range(n*m+1):
        if i == 0 and j == 0 and k == 0:
          ans[i][j][k] = 1
        elif i >= 1 and k < lst[i-1]:
          ans[i][j][k] = ans[i-1][j][k]
        elif i >= 1 and lst[i-1] <= k and j >= 1:
          ans[i][j][k] = ans[i-1][j-1][k-lst[i-1]] + ans[i-1][j][k]
        else:
          ans[i][j][k] = 0
  ret = 0
  for i in range(1,n+1):
    ret += ans[-1][i][i*a]
  return int(ret)

if __name__ == "__main__":
  n, a = map(int,input().split())
  x_list = [int(i) for i in input().split()]
  ans = solve(n,a,x_list)
  print(ans)


Fixed submission:
def solve(n, a, lst):
  m = max(max(lst), a)
  ans = [[[0]*(n*m+1) for i in range(n+1)] for j in range(n+1)]
  #ans[i][j][k] : lst[:i]までの中からj枚選んで合計kにする選び方
  for i in range(n+1):
    for j in range(n+1):
      for k in range(n*m+1):
        if i == 0 and j == 0 and k == 0:
          ans[i][j][k] = 1
        elif i >= 1 and k < lst[i-1]:
          ans[i][j][k] = ans[i-1][j][k]
        elif i >= 1 and lst[i-1] <= k and j >= 1:
          ans[i][j][k] = ans[i-1][j-1][k-lst[i-1]] + ans[i-1][j][k]
        else:
          ans[i][j][k] = 0
  ret = 0
  for i in range(1,n+1):
    ret += ans[-1][i][i*a]
  return int(ret)

if __name__ == "__main__":
  n, a = map(int,input().split())
  x_list = [int(i) for i in input().split()]
  ans = solve(n,a,x_list)
  print(ans)
Buggy python submission (verdict: Runtime Error):
import math

def func(b,n):
  if b > n:
    return n
  else:
    return func(b, math.floor(n/b)) + (n % b)

def solve(n,s):
  for b in range(2,math.floor(math.sqrt(n))+1):
    if func(b,n) == s:
      return b

  for p in range(1,math.floor(math.sqrt(n))+1):
    if (n-s) % p == 0:
      b = int((n-s)/p)+1
      if func(b, n) == s:
        return b

  return -1

if __name__  == "__main__":
  n = int(input())
  s = int(input())
  ans = solve(n,s)
  print(ans)


Fixed submission:
import math

def func(b,n):
  if b > n:
    return n
  else:
    return func(b, math.floor(n/b)) + (n % b)

def _func(b,n):
  x = n
  ret = 0
  while True:
    if b > x:
      return ret + x
    else:
      ret += x % b
      x = math.floor(x/b)

def solve(n,s):
  if n == s:
    return n+1
  ans = float('inf')
  for b in range(2,math.floor(math.sqrt(n))+1):
    if _func(b,n) == s:
      return b

  for p in range(1,math.floor(math.sqrt(n))+1):
    if (n-s) % p == 0:
      b = int((n-s)/p)+1
      if b < 2:
        continue
      if _func(b, n) == s:
        ans = min(ans, b)

  if ans < float('inf'):
    return ans
  else:
    return -1

if __name__  == "__main__":
  n = int(input())
  s = int(input())
  ans = solve(n,s)
  print(ans)

Buggy python submission (verdict: Runtime Error):
import math

def func(b,n):
  if b > n:
    return n
  else:
    return func(b, math.floor(n/b)) + (n % b)

def solve(n,s):
  for b in range(2,math.floor(math.sqrt(n))+1):
    if func(b,n) == s:
      return b

  for p in range(1,math.floor(math.sqrt(n))+1):
    if (n-s) % p == 0:
      b = int((n-s)/p)+1
      if func(b, n) == s:
        return b

  return -1

if __name__  == "__main__":
  n = int(input())
  s = int(input())
  ans = solve(n,s)
  print(ans)


Fixed submission:
import math

def func(b,n):
  if b > n:
    return n
  else:
    return func(b, math.floor(n/b)) + (n % b)

def _func(b,n):
  x = n
  ret = 0
  while True:
    if b > x:
      return ret + x
    else:
      ret += x % b
      x = math.floor(x/b)

def solve(n,s):
  if n == s:
    return n+1
  ans = float('inf')
  for b in range(2,math.floor(math.sqrt(n))+1):
    if _func(b,n) == s:
      return b

  for p in range(1,math.floor(math.sqrt(n))+1):
    if (n-s) % p == 0:
      b = int((n-s)/p)+1
      if b < 2:
        continue
      if _func(b, n) == s:
        ans = min(ans, b)

  if ans < float('inf'):
    return ans
  else:
    return -1

if __name__  == "__main__":
  n = int(input())
  s = int(input())
  ans = solve(n,s)
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9+7

def modpow(base, pow, mod):
  res = 1
  while pow > 0:
    if pow & 1:
      res = res * base % mod
    base = base**2 % mod
    pow >>= 1
  return res

def modmul(a, b, mod):
  return a*b % mod

def solve(h,w,a,b):
  fact = [1]
  fact_inv = [1]
  for i in range(1, h+w):
    fact.append(fact[-1]*i % MOD)
    fact_inv.append(modpow(fact[-1], MOD-2, MOD))

  ans = 0
  for col_idx in range(b, w):
    before_checkpoint = modmul(modmul(fact[h-a-1+col_idx], fact_inv[h-a-1], MOD), fact_inv[col_idx], MOD)
    from_checkpoint = modmul(modmul(fact[(a-1) + (w-col_idx-1)], fact_inv[w-col_idx-1], MOD), fact_inv[a-1], MOD)
    ans = (ans + modmul(before_checkpoint, from_checkpoint, MOD)) % MOD

  return ans

if __name__ == "__main__":
  h,w,a,b = map(int, input().split())
  print(solve(h,w,a,b))


Fixed submission:
MOD = 10**9+7

def modpow(base, pow, mod):
  res = 1
  while pow > 0:
    if pow & 1:
      res = res * base % mod
    base = base**2 % mod
    pow >>= 1
  return res

def modmul(a, b, mod):
  return a*b % mod

def solve(h,w,a,b):
  fact = [0]*(h+w+1)
  fact[0] = 1
  fact_inv = [0]*(h+w+1)
  fact_inv[0] = 1
  for i in range(1, h+w):
    fact[i] = fact[i-1]*i % MOD
    fact_inv[i] = modpow(fact[i], MOD-2, MOD)

  ans = 0
  for col_idx in range(b, w):
    before_checkpoint = modmul(modmul(fact[h-a-1+col_idx], fact_inv[h-a-1], MOD), fact_inv[col_idx], MOD)
    from_checkpoint = modmul(modmul(fact[(a-1) + (w-col_idx-1)], fact_inv[w-col_idx-1], MOD), fact_inv[a-1], MOD)
    ans = (ans + modmul(before_checkpoint, from_checkpoint, MOD)) % MOD

  return ans

if __name__ == "__main__":
  h,w,a,b = map(int, input().split())
  print(solve(h,w,a,b))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import numpy as np

r = int(input())

ans = r * 2 * np.pi()

print(ans)

Fixed submission:
# -*- coding: utf-8 -*-
#import numpy as np

r = int(input())

ans = r * 2 * 3.14159265

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import numpy as np

n = int(input())
a = np.array(input().split(), dtype='int')

ans = ''
count_all = 0

for j in range(n):
    num = a[0]
    if len(a[a == num]) != 1:
        ans = 'NO'
        break
    a = np.delete(a, 0)
    
if ans == 'NO':
    print(ans)
else:
    print('YES')

Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np

n = int(input())
a = np.array(input().split(), dtype='int')

a_sort = np.sort(a)
ans = ''

for i in range(n - 1):
    if a_sort[i] == a_sort[i + 1]:
        ans = 'NO'
        break
    
if ans == 'NO':
    print(ans)
else:
    print('YES')

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import numpy as np

n = int(input())
a = np.array(input().split(), dtype='int')

ans = ''
count_all = 0

for j in range(n):
    num = a[j]
    if len(a[a == num]) != 1:
        ans == 'NO'
        break
    a = np.delete(a, j)

if ans == 'NO':
    print(ans)
else:
    print('YES')

Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np

n = int(input())
a = np.array(input().split(), dtype='int')

a_sort = np.sort(a)
ans = ''

for i in range(n - 1):
    if a_sort[i] == a_sort[i + 1]:
        ans = 'NO'
        break
    
if ans == 'NO':
    print(ans)
else:
    print('YES')

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import numpy as np

n = int(input())
a = np.array(input().split(), dtype='int')

ans = ''
count_all = 0

for j in range(n):
    num = a[j]
    count = 0
    for i in range(n):
        if a[i] == num:
            count += 1
    if count != 1:
        ans = 'NO'
        break
    count_all += count
    if count_all >= n:
        break

if ans == 'NO':
    print(ans)
else:
    print('YES')

Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np

n = int(input())
a = np.array(input().split(), dtype='int')

a_sort = np.sort(a)
ans = ''

for i in range(n - 1):
    if a_sort[i] == a_sort[i + 1]:
        ans = 'NO'
        break
    
if ans == 'NO':
    print(ans)
else:
    print('YES')
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import numpy as np

def main():
    n = int(input())
    h = np.array(input().split(), dtype='int')

    ans = 0

    for i in range(n - 1):
        times_move = 0
        for j in range(n - i - 1):
            if h[i + j] < h[i + j + 1]:
                break
            else:
                times_move += 1
        if times_move > ans:
            ans = times_move
        if n - i - 1 <= ans:
            break

    print(ans)


main()

Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np

def main():
    n = int(input())
    h = np.array(input().split(), dtype='int')

    ans = 0
    i = 0

    while i < n:
        times_move = 0
        for j in range(n - i - 1):
            if h[i + j] < h[i + j + 1]:
                break
            else:
                times_move += 1
        if times_move > ans:
            ans = times_move
        if n - i - 1 <= ans:
            break
        i += times_move + 1

    print(ans)


main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import numpy as np

def main():
    n = int(input())
    h = np.array(input().split(), dtype='int')

    ans = 0

    for i in range(n - 1):
        times_move = 0
        for j in range(n - i - 1):
            if h[i + j] >= h[i + j + 1]:
                times_move += 1
            else:
                break
        if times_move > ans:
            ans = times_move
        if n - i - 1 <= ans:
            break

    print(ans)


main()

Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np

def main():
    n = int(input())
    h = np.array(input().split(), dtype='int')

    ans = 0
    i = 0

    while i < n:
        times_move = 0
        for j in range(n - i - 1):
            if h[i + j] < h[i + j + 1]:
                break
            else:
                times_move += 1
        if times_move > ans:
            ans = times_move
        if n - i - 1 <= ans:
            break
        i += times_move + 1

    print(ans)


main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import numpy as np

def main():
    n = int(input())
    h = np.array(input().split(), dtype='int')

    ans = 0

    for i in range(n - 1):
        times_move = 0
        for j in range(n - i - 1):
            if h[i + j] >= h[i + j + 1]:
                times_move += 1
            else:
                break
        if times_move > ans:
            ans = times_move

    print(ans)


main()

Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np

def main():
    n = int(input())
    h = np.array(input().split(), dtype='int')

    ans = 0
    i = 0

    while i < n:
        times_move = 0
        for j in range(n - i - 1):
            if h[i + j] < h[i + j + 1]:
                break
            else:
                times_move += 1
        if times_move > ans:
            ans = times_move
        if n - i - 1 <= ans:
            break
        i += times_move + 1

    print(ans)


main()
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
K = int(input())
ans = 0

for i in range(1, K + 1):
    ans += gcd(gcd(i, i), i)
    for j in range(1, K + 1):
        if i != j:
            ans += gcd(gcd(i, i), j)*3

for i in range(1, K + 1):
    for j in range(i + 1, K + 1):
        for l in range(j + 1, K + 1):
            ans += gcd(gcd(i, j), l)*6

print(ans)


Fixed submission:
from math import gcd
K = int(input())
ans = 0

for i in range(1, K + 1):
    ans += gcd(gcd(i, i), i)
    temp = gcd(i, i)
    for j in range(1, K + 1):
        if i != j:
            ans += gcd(temp, j)*3

for i in range(1, K + 1):
    for j in range(i + 1, K + 1):
        for l in range(j + 1, K + 1):
            ans += gcd(gcd(i, j), l)*6

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())

R = [None] * S.count("R")
G = [None] * S.count("G")
B = [None] * S.count("B")

ri = 0
gi = 0
bi = 0
for i in range(N):
    if S[i] == "R":
        R[ri] = i+1
        ri+=1
    elif S[i] == "G":
        G[gi] = i+1
        gi += 1
    else:
        B[bi] = i+1
        bi += 1

c = 0
for r in R:
    for g in G:
        for d in [(r + g) / 2, 2 * r - g, 2 * g - r]:
            if d in B:
                c += 1

ans = len(R) * len(G) * len(B) - c
print(ans)


Fixed submission:
N = int(input())
S = list(input())

R = [None] * S.count("R")
G = [None] * S.count("G")
B = [None] * S.count("B")

ri = 0
gi = 0
bi = 0
for i in range(N):
    if S[i] == "R":
        R[ri] = i+1
        ri+=1
    elif S[i] == "G":
        G[gi] = i+1
        gi += 1
    else:
        B[bi] = i+1
        bi += 1
R = set(R)
G = set(G)
B = set(B)

c = 0
for r in R:
    for g in G:
        for d in [(r + g) / 2, 2 * r - g, 2 * g - r]:
            if d in B:
                c += 1

ans = len(R) * len(G) * len(B) - c
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())

R = [None] * S.count("R")
G = [None] * S.count("G")
B = [None] * S.count("B")

ri = 0
gi = 0
bi = 0
for i in range(N):
    if S[i] == "R":
        R[ri] = i+1
        ri+=1
    elif S[i] == "G":
        G[gi] = i+1
        gi += 1
    else:
        B[bi] = i+1
        bi += 1

c = 0
for r in R:
    for g in G:
        for d in [(r + g) / 2, 2 * r - g, 2 * g - r]:
            if d in B:
                c += 1

ans = len(R) * len(G) * len(B) - c
print(ans)

Fixed submission:
N = int(input())
S = list(input())

R = [None] * S.count("R")
G = [None] * S.count("G")
B = [None] * S.count("B")

ri = 0
gi = 0
bi = 0
for i in range(N):
    if S[i] == "R":
        R[ri] = i+1
        ri+=1
    elif S[i] == "G":
        G[gi] = i+1
        gi += 1
    else:
        B[bi] = i+1
        bi += 1
R = set(R)
G = set(G)
B = set(B)

c = 0
for r in R:
    for g in G:
        for d in [(r + g) / 2, 2 * r - g, 2 * g - r]:
            if d in B:
                c += 1

ans = len(R) * len(G) * len(B) - c
print(ans)
Buggy python submission (verdict: Runtime Error):
import heapq
l = [1, 2, 3, 4, 5, 6, 7, 8, 9]
heapq.heapify(l)

def f(x):
    # xの最後の数値だけ取り出す
    min_x = int(list(str(x))[-1])
    if min_x == 0:
        yield int(x + "0")
        yield int(x + "1")
    elif min_x == 9:
        yield int(x + "8")
        yield int(x + "9")
    else:
        yield int(x + str(min_x - 1))
        yield int(x + str(min_x))
        yield int(x + str(min_x + 1))

K = int(input())
ans = 1
for i in range(K):
    if i == K - 1:
        ans = heapq.heappop(l)
        break
    for y in f(heapq.heappop(l)):
        heapq.push(l, y)
print(ans)

Fixed submission:
l = [1, 2, 3, 4, 5, 6, 7, 8, 9]
l_temp = [1, 2, 3, 4, 5, 6, 7, 8, 9]

def f(x):
    temp = list(str(x))
    t = int(temp[-1])
    if t == 0:
        return int(str(x) + str(t)), int(str(x) + str(t + 1))
    elif t == 9:
        return int(str(x) + str(t - 1)), int(str(x) + str(t))
    else:
        return int(str(x) + str(t - 1)), int(str(x) + str(t)), int(str(x) + str(t + 1))
       

while len(l) < 10 ** 5:
    temp = []
    for l_t in l_temp:
        tem = list(f(l_t))
        for t in tem:
            temp.append(t)
    for t in temp:
        l.append(t)
    l_temp = temp

K = int(input())
print(l[K-1])

Buggy python submission (verdict: Runtime Error):
import heapq
l = [1, 2, 3, 4, 5, 6, 7, 8, 9]
heapq.heapify(l)

def f(x):
    # xの最後の数値だけ取り出す
    min_x = int(list(str(x))[-1])
    if min_x == 0:
        yield int(x + "0")
        yield int(x + "1")
    elif min_x == 9:
        yield int(x + "8")
        yield int(x + "9")
    else:
        yield int(x + str(min_x - 1))
        yield int(x + str(min_x)
        yield int(x + str(min_x + 1)))

K = int(input())
ans = 1
for i in range(K):
    if i == K - 1:
        ans = heapq.heappop(l)
        break
    for y in f(heapq.heappop(l)):
        heapq.push(l, y)
print(ans)

Fixed submission:
l = [1, 2, 3, 4, 5, 6, 7, 8, 9]
l_temp = [1, 2, 3, 4, 5, 6, 7, 8, 9]

def f(x):
    temp = list(str(x))
    t = int(temp[-1])
    if t == 0:
        return int(str(x) + str(t)), int(str(x) + str(t + 1))
    elif t == 9:
        return int(str(x) + str(t - 1)), int(str(x) + str(t))
    else:
        return int(str(x) + str(t - 1)), int(str(x) + str(t)), int(str(x) + str(t + 1))
       

while len(l) < 10 ** 5:
    temp = []
    for l_t in l_temp:
        tem = list(f(l_t))
        for t in tem:
            temp.append(t)
    for t in temp:
        l.append(t)
    l_temp = temp

K = int(input())
print(l[K-1])
Buggy python submission (verdict: Runtime Error):
s = input()

cnt = 0
for i in range(len(s)//2):
    if s[i] != s[-i-1]:
        cnt += 1
        s[-i-1] = s[i]
print(cnt)


Fixed submission:
s = input()

cnt = 0
s = list(s)
for i in range(len(s)//2):
    if s[i] != s[-i-1]:
        cnt += 1
        s[-i-1] = s[i]
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

# パターン1
# A = list(enumerate(A))
# A.sort(key = lambda x: x[1])
# for i in range(N):
#     print(A[i][0] + 1, end = " ")

#パターン2
# A = sorted(range(N), key = lambda i: A[i])
# for i in range(N):
#     print(A[i]+1, end = " ")

# パターン3
min_A = sorted(A)
for i in range(N):
    print(A.index(min_A[i]) + 1, end = " ")


Fixed submission:
N = int(input())
A = list(map(int, input().split()))

A = list(enumerate(A))
A.sort(key = lambda x: x[1])

for i in range(N):
    print(A[i][0] + 1, end = " ")
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
N_original = N

ans = 0
isleft = True

def f(n):
    for i in range(N_original - n+1):
        temp = S[i:i+n]
        if temp in S[i+n:]:
            return True
    return False

left = 0
right = N
N = N//4
while True:
    if f(N):
        if left == N:
            ans = left
            break
        left = N
    else:
        if right == N:
            ans = right
            break
        right = N
    N = (left + right)//2
print(ans)


Fixed submission:
S = input()
if S == "Sunny":
    print("Cloudy")
elif S == "Cloudy":
    print("Rainy")
elif S == "Rainy":
    print("Sunny")
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))

for i in range(M):
    temp = A.index((max(A)))
    tempM = M
    while temp == A.index((max(A))):
        if tempM > M:
            break
        A[A.index((max(A)))] //= 2
        M -= 1

print(sum(A))


Fixed submission:
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x * (-1), a))
heapq.heapify(a)
while m != 0:
    price = heapq.heappop(a) * (-1)
    price //= 2
    m -= 1
    heapq.heappush(a, (-1) * price)
print(sum(a) * (-1))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))

for i in range(M):
    A[A.index((max(A)))] //= 2

print(sum(A))


Fixed submission:
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x * (-1), a))
heapq.heapify(a)
while m != 0:
    price = heapq.heappop(a) * (-1)
    price //= 2
    m -= 1
    heapq.heappush(a, (-1) * price)
print(sum(a) * (-1))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = list(list(input()))

a = []
temp = S[0]
s = []
ans = 0

if temp == S[1]:
    hantei = True
    a.append(temp)
else:
    hantei = False
    s.append(list(S[0]))


for i in range(1, N):
    if temp == S[i]:
        ans += 1
    if hantei and temp != S[i]:
        s.append(a)
        a = []
        hantei = False
    if temp != S[i] or hantei:
        hantei = True
        a.append(S[i])
        temp = S[i]
s.append(a)

length = len(s)
for i in range(K):
    if length > 2:
        ans += 2
        length -= 2
    elif length == 2:
        ans += 1
        break

print(ans)


Fixed submission:
N, K = map(int, input().split())
S = list(list(input()))

a = []
temp = S[0]
s = []
ans = 0

if len(S) > 1 and temp == S[1]:
    hantei = True
    a.append(temp)
else:
    hantei = False
    s.append(list(S[0]))

for i in range(1, N):
    if temp == S[i]:
        ans += 1
    if hantei and temp != S[i]:
        s.append(a)
        a = []
        hantei = False
    if temp != S[i] or hantei:
        hantei = True
        a.append(S[i])
        temp = S[i]
if len(S) > 1:
    s.append(a)

length = len(s)
for i in range(K):
    if length > 2:
        ans += 2
        length -= 2
    elif length == 2:
        ans += 1
        break

print(ans)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = list(list(input()))

a = []
temp = S[0]
hantei = False
s = []
n = []

for i in range(1, N):
    if hantei and temp != S[i]:
        s.append(a)
        n.append(len(a))
        a = []
    if temp != S[i] or hantei:
        hantei = True
        a.append(S[i])
        temp = S[i]

s.insert(0, list(S[0]))
s.append(list(S[-1]))
ans = 0
for i in range(K):
    ans = ans + 1 + max(n)
    k = n.index(max(n))
    n[k] = 0
print(ans)


Fixed submission:
N, K = map(int, input().split())
S = list(list(input()))

a = []
temp = S[0]
s = []
ans = 0

if len(S) > 1 and temp == S[1]:
    hantei = True
    a.append(temp)
else:
    hantei = False
    s.append(list(S[0]))

for i in range(1, N):
    if temp == S[i]:
        ans += 1
    if hantei and temp != S[i]:
        s.append(a)
        a = []
        hantei = False
    if temp != S[i] or hantei:
        hantei = True
        a.append(S[i])
        temp = S[i]
if len(S) > 1:
    s.append(a)

length = len(s)
for i in range(K):
    if length > 2:
        ans += 2
        length -= 2
    elif length == 2:
        ans += 1
        break

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())

ans =  N(N-1)/2

print(int(ans))


Fixed submission:
N = int(input())

ans =  (N*(N-1)) // 2
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

ans = 0
for i in range(1, N):
    ans += i

print(ans)


Fixed submission:
N = int(input())

ans =  (N*(N-1)) // 2
print(int(ans))
Buggy python submission (verdict: Runtime Error):
N = int(input())
s = [list(input()) for _ in range(N)]
S = []
for i in range(N):
    S.append("".join(sorted(s[i])))
print(S)

cnt = 0
for i in range(N):
    cnt += S.count(S[i]) - 1
print(int(cnt / 2))


Fixed submission:
A, B = map(int, input().split())
print(max(A+B, A-B, A*B))