Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):

def resolve():
    import sys
    input = sys.stdin.readline
    k = int(input().rstrip())

    if k <= 9:
        # print(k)
        sys.exit()

    def judge(number_list, index, total):
        if index == len(number_list) - 2:  # 最後から2番目の桁
            num = number_list[index]
            add_num = 2 if num in (0, 9) else 3
            if (total + add_num) < k:
                total += add_num
                return total
            else:
                if num == 0:
                    right_nums = [num, num + 1]
                elif num == 9:
                    right_nums = [num-1,num]
                else:
                    right_nums = [num-1,num,num+1]
                number_list[-1] = right_nums[k-total-1]
                # print("".join(number_list))
                print(*number_list,sep="")
                sys.exit()
        else:  # 最後から２番目の桁じゃない
            num = number_list[index]
            if num == 0:
                right_nums = [num, num + 1]
            elif num == 9:
                right_nums = [num - 1, num]
            else:
                right_nums = [num - 1, num, num + 1]

            for right_num in right_nums:
                number_list[index+1] = right_num
                total = judge(number_list, index+1, total)
            return total

    total = 9
    num_list = [9]
    while True:
        num_list = [0 for _ in range(len(num_list)+1)]
        for left in [1,2,3,4,5,6,7,8,9]:
            num_list[0] = left
            # print(num_list, 0, total)
            total = judge(num_list, 0, total)




if __name__ == "__main__":
    resolve()


Fixed submission:

def resolve():
    import sys
    input = sys.stdin.readline
    s = input().rstrip().split()
    print(s[2], s[0], s[1])
   
resolve()

Buggy python submission (verdict: Runtime Error):

def resolve():
    import sys
    input = sys.stdin.readline
    n, k = [int(x) for x in input().rstrip().split()]
    n_set = set()
    while n not in n_set:

        n_set.add(n)
        if n == 0:
            break

        n = abs(k-n)
        if k < n:
          n = n - k*(abs(k-n)//k)
        # print(n)
        # print(n_set)

    print(min(n_set))

resolve()


Fixed submission:

def resolve():
    import sys
    input = sys.stdin.readline
    s = input().rstrip().split()
    print(s[2], s[0], s[1])
   
resolve()
Buggy python submission (verdict: Time Limit Exceeded):
import math


def resolve():
    import sys
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    x = int(input().rstrip())

    def get_sieve_of_eratosthenes(n: int):
        candidate = [i for i in range(2, n + 1)]

        primes = []
        while len(candidate) > 0:
            prime = candidate[0]
            candidate = [num for num in candidate if num % prime != 0]
            primes.append(prime)
        return primes

    # xまでの素数
    primes = get_sieve_of_eratosthenes(x)

    ans = x
    if not x in primes:
        while True:
            if any([ans % prime == 0 for prime in primes]):
                ans += 1
                continue
            break

    print(ans)




if __name__ == "__main__":
    resolve()


Fixed submission:
import math


def resolve():
    import sys
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    x = int(input().rstrip())

    def get_sieve_of_eratosthenes(n: int):
        candidate = [i for i in range(2, n + 1)]

        primes = []
        while len(candidate) > 0:
            prime = candidate[0]
            candidate = [num for num in candidate if num % prime != 0]
            primes.append(prime)
        return primes

    # xまでの素数
    primes = get_sieve_of_eratosthenes(x)

    ans = x
    if not x in primes:
        while True:
            if any([ans % prime == 0 for prime in primes]):
                ans += 1
                continue
            break

    print(ans)




if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):

def resolve():
    import sys
    import string
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    n, k, q = [int(x) for x in input().rstrip().split(" ")]

    scores = [k for _ in range(n)]

    for i in range(q):
        a = int(input().rstrip())
        scores = [score - 1 if i != a-1 else score for i, score in enumerate(scores)]

    for score in scores:
        if score <= 0:
            print("No")
        else:
            print("Yes")

if __name__ == "__main__":
    resolve()


Fixed submission:

def resolve():
    import sys
    import string
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    n, k, q = [int(x) for x in input().rstrip().split(" ")]

    scores = [k - q for _ in range(n)]

    for i in range(q):
        a = int(input().rstrip())
        scores[a-1] += 1


    for score in scores:
        if score <= 0:
            print("No")
        else:
            print("Yes")

if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):
import math


def resolve():
    import sys
    import string
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    n = int(input().rstrip())
    a_list = [int(input().rstrip()) * -1 for i in range(n)]

    import numpy
    indices = numpy.argsort(a_list)
    max_num = a_list[indices[0]] * -1
    second_max_num = a_list[indices[1]] * -1

    for i in range(len(a_list)):
        if i != indices[0]:
            print(max_num)
        else:
            print(second_max_num)


if __name__ == "__main__":
    resolve()


Fixed submission:
import math


def resolve():
    import sys
    import string
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    n = int(input().rstrip())
    a_list = [int(input().rstrip()) * -1 for i in range(n)]

    import numpy
    indices = numpy.argsort(a_list)
    max_num = a_list[indices[0]] * -1
    second_max_num = a_list[indices[1]] * -1

    for i in range(len(a_list)):
        if i != indices[0]:
            print(max_num)
        else:
            print(second_max_num)


if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    import sys
    input = sys.stdin.readline
    import functools
    import operator

    n = int(input().rstrip())


    result = functools.reduce(operator.mul, list(range(1, n + 1)))
    print(result % 1000000007)



if __name__ == "__main__":
    resolve()


Fixed submission:
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()
# row = [int(input().rstrip()) for _ in range(n)]

def resolve():
    import sys
    input = sys.stdin.readline
    import functools
    import operator

    n = int(input().rstrip())

    ans = 1
    for i in range(1, n+1):
        ans *= i
        ans = ans % 1000000007

    print(ans)



if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)
n, m = map(int, input().split())

root = [-1]*n

def find(n):
    if root[n] < 0:
        return n
    else:
        root[n] = find(root[n])
        return root[n]

def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    else:
        root[x] += root[y]
        root[y] = x

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    unite(a, b)

print(-min(root))

Fixed submission:
d, t, s = map(int, input().split())
if d/s <= t:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

ans = 0
for i in range(n - 1):
    ans += a[i] * sum(a[i + 1:])
    
ans %= 10**9 + 7
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a = [i % (10**9 + 7) for i in a]
val = sum(a[1:])
l = [val]
for i in range(1, n):
    val -= a[i]
    l.append(val)
ans = 0
for i in range(n - 1):
    ans += a[i]*l[i]
    ans %= 10**9 + 7
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
a = [i % (10**9 + 7) for i in a]
ans = 0
for i in range(n - 1):
    ans += a[i]*(sum(a[i+1:])%(10**9 + 7))
    ans %= 10**9 + 7
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a = [i % (10**9 + 7) for i in a]
val = sum(a[1:])
l = [val]
for i in range(1, n):
    val -= a[i]
    l.append(val)
ans = 0
for i in range(n - 1):
    ans += a[i]*l[i]
    ans %= 10**9 + 7
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
    ans += a[i]*sum(a[i+1:])
    ans %= 10**9 + 7
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a = [i % (10**9 + 7) for i in a]
val = sum(a[1:])
l = [val]
for i in range(1, n):
    val -= a[i]
    l.append(val)
ans = 0
for i in range(n - 1):
    ans += a[i]*l[i]
    ans %= 10**9 + 7
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())

m = 7%k
ans = 1
jud = True
p = 70%k
while m != 0:
    m = (m + p)%k
    ans += 1
    p = p*10%k
    if p == 0:
        jud = False
        break
if jud:
    print(ans)
else:
    print(-1)


Fixed submission:
k = int(input())

m = 0
for i in range(k):
    m = (m*10 + 7)%k
    if m == 0:
        ans = i + 1
        break

if m == 0:
    print(ans)
else:
    print(-1)

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

m = 7%k
ans = 1
i = 1
jud = True
p = 70%k
while m != 0:
    m = (m + p)%k
    ans += 1
    i += 1
    p = p*10%k
    if p == 0:
        jud = False
        break
if jud:
    print(ans)
else:
    print(-1)


Fixed submission:
k = int(input())

m = 0
for i in range(k):
    m = (m*10 + 7)%k
    if m == 0:
        ans = i + 1
        break

if m == 0:
    print(ans)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

def div(k):
    i = 1
    ans = 0
    while i**2 <= k:
        if k%i == 0:
            ans += 2
        if i**2 == k:
            ans -= 1
        i += 1
    return ans

an = 0
for i in range(1, n+1):
    an += i*div(i)

print(an)


Fixed submission:
n = int(input())

def cal(i):
    s = (i + i*(n//i))*(n//i)*0.5
    return s

ans = 0
for i in range(1, n+1):
    ans += cal(i)
    
print(int(ans))

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

def div(k):
    i = 1
    ans = 0
    while i**2 <= k:
        if k%i == 0:
            ans += 2
        if i**2 == k:
            ans -= 1
        i += 1
    return ans

an = 0
for i in range(1, n+1):
    an += i*div(i)

print(an)


Fixed submission:
n = int(input())

def cal(i):
    s = (i + i*(n//i))*(n//i)*0.5
    return s

ans = 0
for i in range(1, n+1):
    ans += cal(i)
    
print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
q = int(input())

ans = 0
for i in A:
    ans += i

for i in range(q):
    b, c = map(int, input().split())
    d = c - b
    cnt = 0
    for j in range(len(A)):
        if A[j] == b:
            A[j] = c
            cnt += 1
    ans += d*cnt
    print(ans)


Fixed submission:
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
q = int(input())

ans = sum(A)
dic = Counter(A)
for i in range(q):
    b, c = map(int, input().split())
    cnt = dic[b]
    dic[b] = 0
    dic[c] += cnt
    ans -= cnt*b
    ans += cnt*c
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
B = []
C = []
D = []
for i in range(q):
    ans = 0
    b, c = map(int, input().split())
    for j in range(len(A)):
        if A[j] == b:
            A[j] = c
            ans += c
        else:
            ans += A[j]
    print(ans)


Fixed submission:
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
q = int(input())

ans = sum(A)
dic = Counter(A)
for i in range(q):
    b, c = map(int, input().split())
    cnt = dic[b]
    dic[b] = 0
    dic[c] += cnt
    ans -= cnt*b
    ans += cnt*c
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
ans = 1

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


Fixed submission:
n = int(input())
A = list(map(int, input().split()))
ans = 1

if 0 in A:
    ans = 0
else:
    for i in A:
        ans *= i
        if ans >10**18:
            ans = -1
            break
        
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
n = n%10
if n == 3:
    print("bon")
if n == 0 or n == 1 or n == 6 or n == 8):
    print("pon")
else:
    print("hon")

Fixed submission:
n = int(input())
n = n%10
if n == 3:
    print("bon")
elif n == 0 or n == 1 or n == 6 or n == 8:
    print("pon")
else:
    print("hon")
Buggy python submission (verdict: Runtime Error):
k = int(input())
s = list(input())
an_lis = []
if len(s) <= k:
    ans = "".join(s)
    print(ans)
else:
    for i in range(k):
        an_lis.append(s[i])
    an_lis.append("...")
    ans = "".join(an_lis)
    print(ans)


Fixed submission:
a, b, h, m = map(int, input().split())
import math

a_ang = (h/12 + (1/12)*(m/60))*2*math.pi
b_ang = (m/60)*2*math.pi
ax = a*math.cos(a_ang)
bx = b*math.cos(b_ang)
ay = a*math.sin(a_ang)
by = b*math.sin(b_ang)

x = ax - bx
y = ay - by
ans = (x**2+y**2)**0.5
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
h = list(map(int, input().split()))
p = [False] + [True]*n
A = []
B = []
for i in range(m):
    a, b = map(int,input().split())
    A.append(a)
    B.append(b)

for i in range(m):
    if h[A[i] - 1] > h[B[i] - 1]:
        p[B[i]] = False
    if h[A[i] - 1] < h[B[i] - 1]:
        p[A[i]] = False
    else:
        p[A[i]] = False
        p[B[i]] = False

ans = [i for i in range(n + 1) if p[i]]

print(len(ans))


Fixed submission:
s = input()

if s == "ABC":
    print("ARC")
else:
    print("ABC")

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
m = [True]*n

for i in range(k):
    d = int(input())
    a = (list(map(int, input().split())))
    for j in a:
        m[j-1] = False
        
ans = [i for i in range(n) if m[i]]
print(len(ans))


Fixed submission:
s = input()

if s == "ABC":
    print("ARC")
else:
    print("ABC")
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
h = list(map(int, input().split()))
p = [False] + [True]*n
A = []
B = []
for i in range(m):
    a, b = map(int,input().split())
    A.append(a)
    B.append(b)

for i in range(m):
    if h[A[i] - 1] > h[B[i] - 1]:
        p[B[i]] = False
    if h[A[i] - 1] < h[B[i] - 1]:
        p[A[i]] = False
    if h[A[i] - 1] == h[B[i] - 1]:
        p[A[i]] = False
        p[B[i]] = False
    print(p)
ans = [i for i in range(n + 1) if p[i]]

print(len(ans))


Fixed submission:
n, m = map(int, input().split())
h = list(map(int, input().split()))
p = [False] + [True]*n
A = []
B = []
for i in range(m):
    a, b = map(int,input().split())
    A.append(a)
    B.append(b)

for i in range(m):
    if h[A[i] - 1] > h[B[i] - 1]:
        p[B[i]] = False
    if h[A[i] - 1] < h[B[i] - 1]:
        p[A[i]] = False
    if h[A[i] - 1] == h[B[i] - 1]:
        p[A[i]] = False
        p[B[i]] = False
    
ans = [i for i in range(n + 1) if p[i]]

print(len(ans))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
h = list(map(int, input().split()))
p = [False] + [True]*n
A = []
B = []
for i in range(m):
    a, b = map(int,input().split())
    A.append(a)
    B.append(b)

for i in range(m):
    if h[A[i] - 1] > h[B[i] - 1]:
        p[B[i]] = False
    elif h[A[i] - 1] < h[B[i] - 1]:
        p[A[i]] = False
    else:
        p[A[i]] = False
        p[B[i]] = False
    print(p)
ans = [i for i in range(n + 1) if p[i]]

print(len(ans))


Fixed submission:
n, m = map(int, input().split())
h = list(map(int, input().split()))
p = [False] + [True]*n
A = []
B = []
for i in range(m):
    a, b = map(int,input().split())
    A.append(a)
    B.append(b)

for i in range(m):
    if h[A[i] - 1] > h[B[i] - 1]:
        p[B[i]] = False
    if h[A[i] - 1] < h[B[i] - 1]:
        p[A[i]] = False
    if h[A[i] - 1] == h[B[i] - 1]:
        p[A[i]] = False
        p[B[i]] = False
    
ans = [i for i in range(n + 1) if p[i]]

print(len(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import copy
n = int(input())
a = list(map(int, input().split()))

l = a.copy()

a.sort()
ans = 0
i = 0
while True:
    cnt = 0
    while a[i + cnt] == a[i]:
        cnt += 1
        if i + cnt == n:
            break
    ans += cnt*(cnt - 1)//2
    i += cnt
    if i == n:
        break

for i in range(n):
    num = l[i]
    del l[i]
    ac = l.count(num)
    print(ans - ac)
    l.insert(0, num)

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))

d = Counter(a)
key = d.keys()
ans = 0
for i in key:
    ans += (d[i]*(d[i]  - 1))//2

for i in a:
    print(ans - d[i] + 1)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
n = int(input())
a = list(map(int, input().split()))

l = a.copy()

a.sort()
ans = 0
i = 0
while True:
    cnt = 0
    while a[i + cnt] == a[i]:
        cnt += 1
        if i + cnt == n:
            break
    ans += cnt*(cnt - 1)//2
    i += cnt
    if i == n:
        break

for i in range(n):
    num = l[i]
    del l[i]
    ac = l.count(num)
    print(ans + (ac*(ac - 1) - ac*(ac + 1))//2)
    l.insert(0, num)

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))

d = Counter(a)
key = d.keys()
ans = 0
for i in key:
    ans += (d[i]*(d[i]  - 1))//2

for i in a:
    print(ans - d[i] + 1)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
n = int(input())
a = list(map(int, input().split()))

l = []
for i in range(n):
    num = a[i]
    del a[i]
    ac = a.count(num)
    l.append((ac*(ac - 1) - ac*(ac + 1))//2)
    a.insert(0, num)

a.sort()
ans = 0
i = 0
while True:
    cnt = 0
    while a[i + cnt] == a[i]:
        cnt += 1
        if i + cnt == n:
            break
    ans += cnt*(cnt - 1)//2
    i += cnt
    if i == n:
        break

for i in l:
    print(ans + i)

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))

d = Counter(a)
key = d.keys()
ans = 0
for i in key:
    ans += (d[i]*(d[i]  - 1))//2

for i in a:
    print(ans - d[i] + 1)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
n = int(input())
a = list(map(int, input().split()))

def cul(l):
    l.sort()
    ans = 0
    i = 0
    while True:
        cnt = 0
        while l[i + cnt] == l[i]:
            cnt += 1
            if i + cnt == len(l):
                break
        ans += cnt*(cnt - 1)//2
        i += cnt
        if i == len(l):
            break
    return ans

for i in range(n):
    num = a[i]
    del a[i]
    l = a.copy()
    print(cul(l))
    a.insert(0, num)

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))

d = Counter(a)
key = d.keys()
ans = 0
for i in key:
    ans += (d[i]*(d[i]  - 1))//2

for i in a:
    print(ans - d[i] + 1)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
def cul(x):
    ans = (1 + x)*x/(2*x)
    return ans
p = list(map(cul, list(map(int, input().split()))))
ans = 0
for i in range(n - k + 1):
    cnt = 0
    for j in range(i, i + k):
        cnt += p[j]
    ans = max(ans, cnt)
print(ans)

Fixed submission:
n, k = map(int, input().split())

def cul(x):
    ans = (1 + x)*x/(2*x)
    return ans

p = list(map(cul, list(map(int, input().split()))))
cnt = sum(p[0:k])
ans = cnt
for i in range(k, n):
    cnt += p[i] - p[i - k]
    ans = max(ans, cnt)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k, s = map(int, input().split())
ans = ""
for i in range(k):
    ans += str(s) + " "
if s != 10**9:
    for i in range(n - k):
        ans += str(s + 1) + " "
else:
    for i in range(n - k):
        ans += str(s - 1) + " "
print(ans)

Fixed submission:
n, k, s = map(int, input().split())
ans = []
for i in range(k):
    ans.append(str(s))
if s != 10**9:
    for i in range(n - k):
        ans.append(str(s + 1))
else:
    for i in range(n - k):
        ans.append(str(s - 1))
print(" ".join(ans))
Buggy python submission (verdict: Runtime Error):
s = list(input())
l = [-1]
i = 0
large = False
small = False

while i < len(s):
    if s[i] == "<":
        l.append(l[i] + 1)
    if s[i] == ">":
        cnt = 1
        while s[i + cnt] == ">":
            if i + cnt == len(s) -1:
                cnt += 1
                break
            cnt += 1
        if l[i] < cnt:
            l.append(cnt)
        else:
            l.append(l[i] + 1)
        i += cnt
        cnt -= 1
        while cnt != -1:
            l.append(cnt)
            cnt -= 1
    i += 1
if s[len(s) -1] == "<":
    l.append(l[i] + 1)
del l[0]
ans = sum(l)
print(ans)

Fixed submission:
s = list(input())
l = [-1]
i = 0

while i < len(s):
    if s[i] == "<":
        l.append(l[i] + 1)
    if s[i] == ">":
        cnt = 0
        while s[i + cnt] == ">":
            if i + cnt == len(s) -1:
                cnt += 1
                break
            cnt += 1
        if l[i] < cnt:
            l.append(cnt)
        else:
            l.append(l[i] + 1)
        i += cnt
        cnt -= 1
        while cnt != -1:
            l.append(cnt)
            cnt -= 1
    i += 1
if s[len(s) -1] == "<":
    l.append(l[i] + 1)
del l[0]
ans = sum(l)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j+ 1, n):
            if l[i] + l[j] > l[k]:
                ans += 1
            else:
                break
print(ans)

Fixed submission:
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        ans += bisect_left(l, l[i] + l[j]) - j - 1

print(ans)
Buggy python submission (verdict: Runtime Error):
s = list(input())
k = int(input())
ans = 0
for i in range(1, len(s)):
    if s[i] == s[i -1]:
        ans += 1
        s[i] = ""
j = 0
if s[-1] == s[0]:
    if s[-1] != s[-2]:
        j = 1

print(ans*k - j*(k - 1))

Fixed submission:
s = list(input())
k = int(input())
n = len(s)

if s == [s[0]]*n:
    print(n*k//2)
else:
    ss = s*2
    ans1 = 0
    for i in range(1, n):
        if s[i] == s[i -1]:
            s[i] = ""
            ans1 += 1
    ans2 = 0
    for i in range(1, 2*n):
        if ss[i] == ss[i - 1]:
            ss[i] = ""
            ans2 += 1
    j = ans2 - ans1
    print(ans1 + j*(k - 1))