Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03804 (python)

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

gridA = [[v for v in input()] for _ in range(N)]
gridB = [[v for v in input()] for _ in range(M)]

for x_A in range(N):
    for y_A in range(N):
        ok = True
        for x_B in range(M):
            for y_B in range(M):
                if x_A+x_B >= N or y_A+y_B >= N:
                    break
                if gridA[x_A+x_B][y_A+y_B] == gridB[x_B][y_B]:
                    continue
                else:
                    ok = False
                    break
            else:
                continue
            break
        else:
            print("Yes")
            exit()
print("No")

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())

gridA = [[v for v in input()] for _ in range(N)]
gridB = [[v for v in input()] for _ in range(M)]

for x_A in range(N):
    for y_A in range(N):
        ok = True
        for x_B in range(M):
            for y_B in range(M):
                if x_A+x_B > N or y_A+y_B > N:
                    break
                if gridA[x_A+x_B][y_A+y_B] == gridB[x_B][y_B]:
                    continue
                else:
                    ok = False
                    break
            else:
                continue
            break
        else:
            print("Yes")
            exit()
print("No")

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())

gridA = [[v for v in input()] for _ in range(N)]
gridB = [[v for v in input()] for _ in range(M)]

for x_A in range(N):
    for y_A in range(N):
        ok = True
        for x_B in range(M):
            for y_B in range(M):
                if gridA[x_A+x_B][y_A+y_B] == gridB[x_B][y_B]:
                    continue
                else:
                    ok = False
                    break
            else:
                continue
            break
        else:
            print("Yes")
            exit()
print("No")
Problem p02624 (python)

Fixed submission:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
ans = [0] * (n+1)
for i in range(1,n+1):
    for j in range(1,n+1):
        if i*j > n: break
        ans[i*j] += 1
res = 0
for i in range(1,n+1):
    res += i*ans[i]
print(res)

Buggy submission (verdict: Runtime Error):
は？

Buggy submission (verdict: Runtime Error):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

def sieve_of_erastosthenes(num):
    input_list = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)]
    input_list[0] = input_list[1] = False
    input_list[2] = input_list[3] = input_list[5] = True
    sqrt = math.sqrt(num)

    for serial in range(3, num, 2):

        if serial >= sqrt:
            return input_list

        for s in range(serial ** 2, num, serial): 
            input_list[s] = False

n = inp()
if n == 1:
    print(1)
    quit()
cnt = 1
res = 1
ans = [-1] * (n+1)
ans[1] = 1 
pp = sieve_of_erastosthenes(n)
# print(pl)
pl = []
for x in range(1,n):
    if not pp[x]: continue
    # print(x)
    cnt += 1
    ans[x] = 2
    res += 2*x
    c = 2
    while pow(x,c) <= n:
        now = pow(x,c)
        if ans[now] == -1:
            ans[now] = c+1
            res += now*(c+1)
            cnt += 1
        c += 1
# print(ans)
while cnt < n:
    for i in range(2,n+1):
        for j in range(i+1,n+1):
            if i * j > n: break
            if math.gcd(i,j) != 1 or ans[i*j] != -1: continue
            if ans[j] == -1: continue
            ans[i*j] = ans[i] * ans[j]
            res += (i*j) * ans[i*j]
            cnt += 1
# print(ans)
# for i in range(1,n+1):
#     res += ans[i] * i
#     if ans[i] < -1:
#         print(i)
print(res)
Problem p02629 (python)

Fixed submission:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
keta = 1
su = 0
while True:
    su += 26**keta
    if su >= n:
        break
    keta += 1
n -= su - pow(26,keta) + 1
# print(n)
res = []
for i in range(keta):
    now = keta-i-1
    d,m = divmod(n,pow(26,now))
    res.append(chr(ord('a') + d))
    n = m
print(''.join(res))

Buggy submission (verdict: Runtime Error):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

A = ord('a') - 1
n = inp()
if n == 1:
    print(a)
c = 0
while n >= pow(26,c):
    c += 1
res = []
for i in range(c):
    now = c-i-1
    nnn,m = divmod(n,pow(26,now))
    res.append(chr(A + nnn))
    n = m
print(''.join(res))
Problem p02879 (python)

Fixed submission:
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a,b = inpl()
if a < 10 and b < 10:
    print(a*b)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().sprit())
if a < 10 and b< 10:
  print(a*b)
else:
  print(-1)
Problem p02881 (python)

Fixed submission:
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
res = 10**13+4
for i in range(1,2*10**6):
    if (n/i).is_integer():
        res = min(res, i + n/i)
print(int(res-2))

Buggy submission (verdict: Runtime Error):
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
res = float('inf')
for i in range(1,math.sqrt(n)):
    if n%i == 0:
        res = min(res, i + n/i)
print(int(res-2))
Problem p02954 (python)

Fixed submission:
import sys,fractions
a = input()
n = len(a)
t = []
ans = [0] * n
cnt = 0
tmp = a[0]
for i in range(n):
    if a[i] == tmp:
       cnt += 1 
    else:
        t.append(cnt)
        tmp = a[i]
        cnt = 1
t.append(cnt)
N = len(t)
len = 0
for i in range(N)[::2]:
    tmp_len = t[i] + t[i+1]
    #R
    ans[len + t[i] - 1] += int((t[i]+1)/2)
    ans[len + t[i]] += int(t[i]/2)
    #L
    ans[len + t[i] - 1] += int(t[i+1]/2)
    ans[len + t[i]] += int((t[i+1]+1)/2)
    len += tmp_len
L = [str(i) for i in ans]
print(" ".join(L))

Buggy submission (verdict: Runtime Error):
import sys
A = input()
N = len(A)
B = [0] * len(A)
k = 0
tmp= 0
for i in range(len(A)):
    if A[i] == 'R':
        tmp += 1
        for j in range(i+1,N):
            if A[j] == 'R':
                tmp += 1
            else:
                k = j
                break
        if tmp % 2 ==0:
            B[k] += 1
        else:
            B[k-1] += 1
        tmp = 0
    else:
        tmp += 1
        for j in range(1,i)[::-1]:
            if A[j] == 'L':
                tmp += 1
            else:
                k = j
                break
        if tmp % 2 ==0:
            B[k] += 1
        else:            
            B[k+1] += 1
        tmp = 0
L = [str(i) for i in B]
print(" ".join(L))

Buggy submission (verdict: Runtime Error):
import sys
A = input()
N = len(A)
B = [0] * len(A)
k = 0
tmp= 0
for i in range(len(A)):
    if A[i] == 'R':
        tmp += 1
        for j in range(i+1,N):
            if A[j] == 'R':
                tmp += 1
            else:
                k = j
                break
        if tmp % 2 ==0:
            B[k] += 1
        else:
            B[k-1] += 1
        tmp = 0
    else:
        tmp += 1
        for j in range(1,i)[::-1]:
            if A[j] == 'L':
                tmp += 1
            else:
                k = j
                break
        if tmp % 2 ==0:
            B[k] += 1
        else:            
            B[k+1] += 1
        tmp = 0
L = [str(i) for i in B]
L = " ".join(L)
print(L)
Problem p02955 (python)

Fixed submission:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,k = inpl()
a = inpl()
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(reverse = True)
    return divisors
pr = make_divisors(sum(a))
def sol(p):
    mo = []
    pl = []
    for i in a:
        if i%p != 0:
            mo += [i%p]
            pl += [p-i%p]
    mo.sort(); pl.sort()
    m = 0; c = sum(pl)
    ln = len(mo)
    for i in range(ln):
        m += mo[i]
        c -= pl[ln-i-1]
        if max(m,c) <= k and m == c:
            return True
    return False
for p in pr:
    if sol(p):
        res = p
        break
else:
    res = 1
print(res)

Buggy submission (verdict: Runtime Error):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,k = inpl()
a = inpl()
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

pr = make_divisors(sum(a))
pr = sorted(list(set(pr)), reverse = True)
def sol(p):
    mo = []
    pl = []
    for i in a:
        if i%p != 0:
            mo += [i%p]
            pl += [p-i%p]
    mo.sort(); pl.sort()
    m = 0; c = sum(pl)
    ln = len(mo)
    for i in range(ln):
        m += mo[i]
        c -= pl[ln-i-1]
        if max(m,c) <= k and m == c:
            return True
    return False
for p in pr:
    if sol(p):
        res = p
        break
print(res)
Problem p02990 (python)

Fixed submission:
from math import factorial as fa
def con(a,b):
    if a < b:
        return 0
    elif a < 0:
        return 1
    else:
        return int(fa(a)) // int(fa(b) * fa(a-b))
    
n,k = map(int,input().split())
for i in range(1,k+1):
    r_tmp = con(n-k+1,i)
    b_tmp = con(k-1,i-1)
    if r_tmp:
        print((r_tmp * b_tmp) % (10**9+7))
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
from math import factorial as fa
n,k = map(int,input().split())
for i in range(1,k+1):
    r_tmp = fa(n-k+1) / (fa(i) * fa(n-k+1-i))
    b_tmp = fa(k-1) / (fa(i-1) * fa(k-i))
    print(int(r_tmp * b_tmp) % (10**9+7))
Problem p03013 (python)

Fixed submission:
import sys,math
N,M = map(int,input().split())
a = [int(input()) for i in range(M)]
b = set(a)
dp = [0] * (N+1)
mod = 10**9+7
for i in range(N,-1,-1):
    if i in b:
        continue
    elif i == N or i == N-1:
        dp[i] = 1
    else:
        dp[i] = (dp[i+1] + dp[i+2])%mod
print(dp[0])

Buggy submission (verdict: Runtime Error):
import sys,math
N,M = map(int,input().split())
a = []
cnt = 0
ans = 1
fi = []
fi.append(1)
fi.append(1)
fi.append(1)
for i in range(3,10*5+2):
    tmp = fi[i-1]+fi[i-2]
    fi.append(tmp)
for i in range(M):
    a.append(int(input()))
for i in range(N+1):
    if i in a:
        if cnt == 0:
            print(0)
            sys.exit()
        else:
            ans *= fi[cnt]
            cnt = 0
    else:
        cnt += 1
ans *= fi[cnt]

print(ans % 1000000007)

Buggy submission (verdict: Runtime Error):
import sys,math
N,M = map(int,input().split())
a = []
cnt = 0
ans = 1
fi = []
fi.append(1)
fi.append(1)
fi.append(1)
for i in range(3,10*5+1):
    tmp = fi[i-1]+fi[i-2]
    fi.append(tmp)
for i in range(M):
    a.append(int(input()))
for i in range(N+1):
    if i in a:
        if cnt == 0:
            print(0)
            sys.exit()
        else:
            ans *= fi[cnt]
            cnt = 0
    else:
        cnt += 1
ans *= fi[cnt]

print(ans % 1000000007)
Problem p03017 (python)

Fixed submission:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,a,b,c,d = inpl()
s = input()
def chk(i):
    if s[i] == s[i+1] == '#':
        print('No')
        quit()
    return True
def cc(i):
    if s[i] == s[i+1] == s[i+2] == '.':
        return True
    return False

if c < d:
    for i in range(b-1,d-1):
        chk(i)
    for i in range(a-1,c-1):
        chk(i)
else:
    for i in range(b-2,d-1):
        if cc(i):
            break
    else:
        print('No')
        quit()
    for i in range(a-1,c-1):
        chk(i)
print('Yes')

Buggy submission (verdict: Runtime Error):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,a,b,c,d = inpl()
s = input()
def chk(i):
    if s[i] == s[i+1] == '#':
        print('No')
        quit()
    return True
def cc(i):
    if s[i] == s[i+1] == s[i+2] == '.':
        return True
    return False

if c < d:
    for i in range(b-1,d-1):
        chk(i)
    for i in range(a-1,c-1):
        chk(i)
else:
    for i in range(b-1,d):
        if cc(i):
            break
    else:
        print('No')
        quit()
    for i in range(a-1,c-1):
        chk(i)
print('Yes')
Problem p03038 (python)

Fixed submission:
from collections import Counter,defaultdict
import sys,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n,m = inpl()
a = inpl()
sum_a = sum(a)
bc = []
for i in range(m):
    b,c = inpl()
    bc.append([b,c])
a.sort()
bc.sort(key=lambda x:x[1],reverse=True)

start = 0
flag = True
for i,q in enumerate(bc):
    end = start+q[0]
    if end >= n:
        flag = False
        end = n
    for j in range(start,end):
        if a[j] < q[1]:
            a[j] = q[1]
        else:
            flag = False
            break
    start += q[0]
    if not flag:
        break
print(sum(a))

Buggy submission (verdict: Runtime Error):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
a = inpl()
a.sort()
bc = [inpl() for _ in range(m)]
bc.sort(key=lambda x:x[1], reverse = True)
ind = -1
now = -1
cnt = 0
for i in range(n):
    if cnt == 0:
        ind += 1
        cnt, now = bc[ind]
    if a[i] >= now:
        break
    a[i] = now
    cnt -= 1
print(sum(a))
Problem p03127 (python)

Fixed submission:
def gcd(a,b):
    while b:
        a,b = b,a % b
    return a
def monsters(li,n):
    t = temp
    for i in range(n-1):
        t = gcd(li[i+1],t)
    return t

n = int(input())
li_a = list(map(int,input().split()))
temp = li_a[0]
print(monsters(li_a,n))

Buggy submission (verdict: Runtime Error):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
res = a[0]
for i in range(n-1):
    res = math.gcd(res,a[i+1])
print(res)

Buggy submission (verdict: Runtime Error):
import fraction
def monsters(li,n):
    t = temp
    for i in range(1,n-1):
        t = fraction.gcd(t,li[i+1])
    return t

n = int(input())
li_a = list(map(int,input().split()))
temp = li_a[0]
print(monsters(li_a,n))

Buggy submission (verdict: Runtime Error):
import math 
def monsters(li,n):
    t = temp
    for i in range(1,n-1):
        t = math.gcd(t,li[i+1])
    return t

n = int(input())
li_a = list(map(int,input().split()))
temp = li_a[0]
print(monsters(li_a,n))

Buggy submission (verdict: Runtime Error):
import math 
def monsters(li,n):
    t = temp
    for i in range(1,n-1):
        t = math.gcd(t,li[i+1])
    return t

n = int(input())
li_a = list(map(int,input().split()))
temp = li_a[0]
print(monsters(li_a,n))
Problem p02633 (python)

Fixed submission:
X=int(input())
import math
a=360*X//math.gcd(360,X)
print(a//X)

Buggy submission (verdict: Runtime Error):
X=int(input())
import math
print(360*X//math.gcd(360,X)
Problem p02659 (python)

Fixed submission:
a,b=input().split()
r=''
x=0
for i in b:
  if i=='.':
    r=r
  elif i!='0':
    x=1
    r=r+i
  elif x==1 and i=='0':
    r=r+i
if len(r)==0:
  r='0'
A=int(a)
B=int(r)
print(A*B//100)

Buggy submission (verdict: Runtime Error):
a,b=input().split()
r=''
x=0
for i in b:
  if i=='.':
    r=r
  elif i!='0':
    x=1
    r=r+i
  elif x==1 and i=='0':
    r=r+i
A=int(a)
B=int(r)
print(A*B//100)
Problem p02763 (python)

Fixed submission:
from bisect import bisect_left,bisect_right
import string 

dic = {c:[] for c in string.ascii_lowercase}

n = int(input())
s = list(input())
q = int(input())

for i,c in enumerate(s,start=1):
  dic[c].append(i)
  
for i in range(q):
  p,l,r = map(str,input().split())
  if p =='1':
    j = int(l)
    if r == s[j-1]:
      continue
    c = s[j-1]    
    dic[c].pop(bisect_left(dic[c],j))
    dic[r].insert(bisect_left(dic[r],j),j)
    s[j-1] = r
  else:
    ans = 0
    l = int(l)
    r = int(r)
    for c in string.ascii_lowercase:
      pl = bisect_left(dic[c],l)
      if pl < len(dic[c]):
        if dic[c][pl] <= r:
          ans += 1
    print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
import string 

dic={c:[] for c in string.ascii_lowercase}
N=int(input())
S=list(input())
Q=int(input())
for i in range(len(S)):
  dic[S[i]].append(i+1)
  
for i in range(Q):
  a,b,c=map(str,input().split())
  if a=='1':
    if S[int(b)-1]==c:
      continue
    b=int(b)
    f=S[b-1]
    d=bisect_left(dic[f],b)
    e=bisect_left(dic[c],b)
    dic[f].pop(d)
    dic[c].insert(e,b)
  else:
    ans=0
    b,c=int(b),int(c)
    for j in string.ascii_lowercase:
      d=bisect_left(dic[j],b)
      if d<len(dic[j]):
        if dic[j][d]<=c:
          ans+=1
    print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
import string 

dic={c:[] for c in string.ascii_lowercase}
N=int(input())
S=list(input())
Q=int(input())
for i in range(len(S)):
  dic[S[i]].append(i+1)
for i in range(Q):
  a,b,c=map(str,input().split())
  if a=='1':
    if S[int(b)-1]==c:
      continue
    d=bisect_left(dic[S[int(b)-1]],int(b))
    e=bisect_left(dic[c],int(b))
    dic[S[int(b)-1]].pop(d)
    dic[c].insert(e,int(b))
  else:
    ans=0
    b,c=int(b),int(c)
    for j in string.ascii_lowercase:
      d=bisect_left(dic[j],b)
      if d<len(dic[j]):
        if dic[j][d]<=c:
          ans+=1
    print(ans)
Problem p02833 (python)

Fixed submission:
N=int(input())
if N%2==1:
  print(0)
else:
  n=N//2
  A=n
  a=0
  b=0
  while A>=5**a:
    a+=1
  while A>=2**b:
    b+=1

  cntfive=0  
  cnttwo=0
  for i in range(1,a):
    cntfive+=n//(5**i)
  for j in range(1,b):
    cnttwo+=n//(2**j)

  ans=min(cntfive,cnttwo+n)
  print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
if N%2==1:
  print(0)
else:
  n=N//2
  A=n
  a=0
  b=0
  while A>=5**a:
    a+=1
  while A>=2**b:
    b+=1

cntfive=0  
cnttwo=0
for i in range(1,a):
  cntfive+=n//(5**i)
for j in range(1,b):
  cnttwo+=n//(2**j)

ans=min(cntfive,cnttwo+n)
print(ans)
Problem p02862 (python)

Fixed submission:
X,Y=map(int,input().split())

def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod

Z=((X+Y)//3)

if (X+Y)%3==0 and abs(X-Y)<=Z:
  ans=(comb(Z, X-Z,(10**9+7)))
  print(ans)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
X,Y=map(int,input().split())

def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod

Z=((X+Y)//3)

if (X+Y)%3==0 and abs(X-Y)<=Z:
  ans=(comb(Z, X-Z,(10**9+7)
  print(ans)
else:
  print(0)
Problem p02891 (python)

Fixed submission:
S=input()
K=int(input())
T=S+S
if len(set(S))!=1:
  A=[]
  D=1
  for i in range(len(S)-1):
    if S[i]==S[i+1]:
      D+=1
    else:
      A.append(D)
      D=1
  A.append(D)
  B=[i for i in A if not i==1]
  C=[(i//2) for i in B]
  Scount=(sum(C))

  E=[]
  H=1
  for j in range(len(T)-1):
    if T[j]==T[j+1]:
      H+=1
    else:
      E.append(H)
      H=1
  E.append(H)
  F=[j for j in E if not j==1]
  G=[(j//2) for j in F]
  Tcount=(sum(G))
  ans=(Tcount-Scount)*(K-1)+Scount
  print(ans)
else:
  print(K*len(S)//2)

Buggy submission (verdict: Runtime Error):
S=input()
K=int(input())
A=[]
D=1
for i in range(len(S)-2):
  if S[i]==S[i+1]:
    D+=1
  else:
    A.append(D)
    D=1
A.append(D)
B=[i for i in A if not i==1]
C=[(i//2) for i in B]
count=(sum(C)*K)

if S[0]==S[-1]:
  count+= (K-1)
if S[-1]==S[-2]:
  count+=1
  
print(count)

Buggy submission (verdict: Runtime Error):
S=input()
K=int(input())
count=0
if S[0] == S[-1]:
  count+= (K-1)  
if S[-1]==S[-2]:
  count+=1
A=[]
D=1
for i in range(len(S)-2):
  if S[i]==S[i+1]:
    D+=1
  else:
    A.append(D)
    D=1
A.append(D)
B=[i for i in A if not i==1]
C=[(i//2) for i in B]

print(sum(C)*K+count)