Problem: Given is a string S. Let T be the concatenation of K copies of S. We can repeatedly perform the following operation: choose a character in T and replace it with a different character. Find the minimum number of operations required to satisfy the following condition: any two adjacent characters in T are different.

Submission attempts (in order):
S = input()
K = input()


# for s in S:
#     if s.isupper():
#         exit()
#     try:
#         float(s)
#     except ValueError:

#     else:
#         exit()
# try:

# except ValueError:
#     exit()
# else:
#     if not float(K).is_integer():
#         exit()

# if not (1 <= len(S) and len(S) <= 100):
#     exit()
# if not (1 <= int(K) and int(K) <= 10**9):
#     exit()
L = []
tmp = []
pre = ""
for s in S:
    if len(tmp) == 0:
        pre = s
        tmp.append(s)
    elif pre == s:
        tmp.append(s)
    else:
        L.append(tmp)
        pre = s
        tmp = [s]
L.append(tmp)
# print(L)

count = 0
for l in L:
    count += int(len(l)/2)
    print(l)
    print(int(len(l) / 2))

print(count*int(K))



S = input()
K = input()

# if not(1 <= len(S) and len(S) <= 100):
#     exit()
# if not (S.isalpha() and S.islower()):
#     exit()
# if not float(K).is_integer():
#     exit()
# if not (1 <= int(K) and int(K) <= 10 ** 9):
#     exit()



L = []
tmp = []
pre = ""
for s in S:
    if len(tmp) == 0:
        pre = s
        tmp.append(s)
    elif pre == s:
        tmp.append(s)
    else:
        L.append(tmp)
        pre = s
        tmp = [s]
L.append(tmp)

count = 0
for l in L:
    count += int(len(l) / 2)

count *= int(K)
if len(L) == 1:
    print(count)
    exit()
if L[0][0] == L[len(L) - 1][0]:
    if len(L[0]) % 2 == 1 and len(L[len(L)]) % 2 == 1:
        count = count + 1 * int(K) - 1
print(count)


S = input()
K = input()


for s in S:
    if s.isupper():
        exit()
    try:
        float(s)
    except ValueError:
        exit()
try:
    float(K)
except ValueError:
    exit()
else:
    if not float(K).is_integer():
        exit()

if not (1 <= len(S) and len(S) <= 100):
    exit()
if not (1 <= int(K) and int(K) <= 10**9):
    exit()
pre = ""
count = 0
first = S[0]
flag = False
for i in range(len(S)):
    if i == (len(S) - 1):
        if pre != S[i] and first == S[i]:
            flag = True
    if pre != S[i]:
        pre = S[i]

    elif pre == S[i]:
        count += 1
        pre = ""


count *= int(K)
if flag:
    count = count + 1*int(K) -1
print(count)


S = input()
K = input()

if not(1 <= len(S) and len(S) <= 100):
    exit()
if not (S.isalpha() and S.islower()):
    exit()
if not float(K).is_integer():
    exit()
if not (1 <= int(K) and int(K) <= 10 ** 9):
    exit()



L = []
tmp = []
pre = ""
for s in S:
    if len(tmp) == 0:
        pre = s
        tmp.append(s)
    elif pre == s:
        tmp.append(s)
    else:
        L.append(tmp)
        pre = s
        tmp = [s]
L.append(tmp)

count = 0
for l in L:
    count += int(len(l) / 2)

count *= int(K)
if len(L) == 1:
    print(count)
    exit()
if L[0][0] == L[len(L) - 1][0]:
    if len(L[0]) % 2 == 1 and len(L[len(L)]) % 2 == 1:
        count = count + 1 * int(K) - 1
print(count)


S = input()
K = input()

L = []
tmp = []
pre = ""
for s in S:
    if len(tmp) == 0:
        pre = s
        tmp.append(s)
    elif pre == s:
        tmp.append(s)
    else:
        L.append(tmp)
        pre = s
        tmp = [s]
L.append(tmp)

count = 0
for l in L:
    count += int(len(l) / 2)
    # print(l)
count *= int(K)
if len(L) == 1:
    if len(L[0]) == 1:
        count = int(int(K) / 2)
    elif len(L[0]) % 2 == 1:
        count += int(int(K) / 2)

elif L[0][0] == L[len(L)-1][0]:
    if len(L[0]) % 2 == 1 and len(L[len(L)-1]) % 2 == 1:
        count = count + int(K) - 1
print(count)


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Accepted