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

Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)

N, K = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
mod = 10**9+7

dp = [[0]*(K+1) for i in range(N+1)]
dp[0][0] = 1

for i in range(1,N+1):
    s = list(itertools.accumulate(dp[i - 1]))
    for k in range(K+1):
        m = max(0, k-a[i])
        if m > 0:
            dp[i][k] = ((s[k] % mod) - (s[m-1] % mod)) % mod
        else:
            dp[i][k] = s[k] % mod

print(dp[N][K] % mod)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
import numpy as np

N, K = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
mod = 10**9+7

dp = [[0]*(K+1) for i in range(N+1)]
dp[0][0] = 1

for i in range(1,N+1):
    for k in range(K+1):
        s = np.cumsum(dp[i-1])
        m = max(0, k-a[i])
        if m > 0:
            dp[i][k] = ((s[k] % mod) - (s[m-1] % mod)) % mod
        else:
            dp[i][k] = s[k] % mod

print(dp[N][K] % mod)
Problem p03311 (python)

Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect
import statistics

N = int(input())
a = list(map(int, input().split()))

for i in range(N):
    a[i] = a[i] - i

def f(k):
    return sum(map(lambda x: abs(x-k), a))

c = statistics.median(a)
print(int(f(c)))

Buggy submission (verdict: Runtime Error):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect
import numpy

N = int(input())
a = list(map(int, input().split()))

for i in range(N):
    a[i] = a[i] - i

def f(k):
    return sum(map(lambda x: abs(x-k), a))

c = numpy.median(a)
print(int(f(c)))
Problem p03493 (python)

Fixed submission:
from sys import stdin

a = stdin.readline().rstrip()

count = 0

for b in a:
  if b == "1": count = count + 1

print(count)

Buggy submission (verdict: Runtime Error):
from sys import stdin

n = stdin.readline().rstrip()
a = [int(x) for x in stdin.readline().rstrip().split()]

count = 0
b = a[0]
while True:
    if b % 2 == 1: break
    b = b//2
    count = count + 1
minc = count

for b in a[1:]:
    count = 0
    while True:
        if b % 2 == 1: break
        b = b//2
        count = count + 1

    minc = min([minc, count])

print(minc)
Problem p03494 (python)

Fixed submission:
from sys import stdin

n = stdin.readline().rstrip()
a = [int(x) for x in stdin.readline().rstrip().split()]

minc = 10**9

for b in a:
    count = 0
    while True:
        if b % 2 == 1: break
        b = b//2
        count = count + 1

    minc = min([minc, count])

print(minc)

Buggy submission (verdict: Runtime Error):
from sys import stdin

n = stdin.readline().rstrip()
a = [int(x) for x in stdin.readline().rstrip().split()]

count = 0
b = a[0]
while True:
    if b % 2 == 1: break
    b = b//2
    count = count + 1
minc = count

for b in a[1:]:
  	count = 0
    while True:
        if b % 2 == 1: break
        b = b//2
        count = count + 1

    minc = min([minc, count])

print(minc)
Problem p02612 (python)

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
if N % 1000 == 0:
    print(0)
else:
    print(1000 - N % 1000)

Buggy submission (verdict: Runtime Error):
class edge:
    def __init__(self, u, v):
        self.u = u
        self.v = v
    def min(self):
        return min(self.u, self.v)
    def max(self):
        return max(self.u, self.v)

N = int(input())
 
edge_list = []
for i in range(N - 1):
    u, v = map(int, input().split())
    edge_list.append(edge(u - 1, v - 1))
 
ver_num = int(N * (N + 1) * (N + 2) / 6)
 
edge_num = 0
for e in edge_list:
    edge_num += (N + 1 - (e.max() + 1)) * (e.min() + 1)
    
print(ver_num - edge_num)
Problem p02616 (python)

Fixed submission:
from collections import deque

N, K = map(int, input().split())
table = list(map(int, input().split()))
jnum = K - sum(1 for i in table if i >= 0)
num_mins = sum(1 for i in table if i < 0)
q_plus = deque(sorted([i for i in table if i >= 0], reverse=True))
q_mins = deque(sorted([-i for i in table if i < 0], reverse=True))
s_plus = []
s_mins = []
total = 1


# if jnum < 0 or jnum % 2 == 0:
if (K % 2 == 1 and N == num_mins) or (N == K and num_mins % 2 == 1):
    for i in range(K):
        if not q_plus:
            total = -total * q_mins.pop() % (10 ** 9 + 7)
        elif not q_mins:
            total = total * q_plus.pop() % (10 ** 9 + 7)
        elif q_plus[-1] > q_mins[-1]:
            total = -total * q_mins.pop() % (10 ** 9 + 7)
        else:
            total = total * q_plus.pop() % (10 ** 9 + 7)
    total = total % (10 ** 9 + 7)
else:
    for i in range(K):
        if not q_plus:
            s_mins.append(q_mins.popleft())
        elif not q_mins:
            s_plus.append(q_plus.popleft())
        elif q_plus[0] > q_mins[0]:
            s_plus.append(q_plus.popleft())
        else:
            s_mins.append(q_mins.popleft())
    if len(s_mins) % 2 == 1:
        if not q_plus:
            s_plus[-1] = q_mins[0]
        elif not q_mins or not s_plus:
            s_mins[-1] = q_plus[0]
        elif q_mins[0] * s_mins[-1] > q_plus[0] * s_plus[-1]:
            s_plus[-1] = q_mins[0]
        else:
            s_mins[-1] = q_plus[0]
    s_plus.extend(s_mins)
    for j in s_plus:
        total = total * j % (10 ** 9 + 7)


print(total)

Buggy submission (verdict: Runtime Error):
from collections import deque

N, K = map(int, input().split())
table = list(map(int, input().split()))
jnum = K - sum(1 for i in table if i >= 0)
q_plus = deque(sorted([i for i in table if i >= 0], reverse=True))
q_mins = deque(sorted([-i for i in table if i < 0], reverse=True))
s_plus = []
s_mins = []
total = 1


if jnum < 0 or jnum % 2 == 0:
    for i in range(K):
        if not q_plus:
            s_mins.append(q_mins.pop())
        elif not q_mins:
            s_plus.append(q_plus.pop())
        elif q_plus[0] > q_mins[0]:
            s_plus.append(q_plus.pop())
        else:
            s_mins.append(q_mins.pop())
    if len(s_mins) % 2 == 1:
        if not q_plus:
            s_plus[-1] = q_mins[0]
        elif not q_mins:
            s_mins[-1] = q_plus[0]
        elif q_mins[0] * s_mins[-1] > q_plus[0] * s_plus[-1]:
            s_plus[-1] = q_mins[0]
        else:
            s_mins[-1] = q_plus[0]
    s_plus.extend(s_mins)
    for j in s_plus:
        total = total * j % (10 ** 9 + 7)

else:
    for i in range(K):
        if not q_plus:
            total = total * q_mins.pop() * -1 % (10 ** 9 + 7)
        elif not q_mins:
            total = total * q_plus.pop() * -1 % (10 ** 9 + 7)
        elif q_plus[-1] > q_mins[-1]:
            total = total * q_mins.pop() * -1 % (10 ** 9 + 7)
        else:
            total = total * q_plus.pop() * -1 % (10 ** 9 + 7)

print(total)
Problem p02617 (python)

Fixed submission:
class edge:
    def __init__(self, u, v):
        self.u = u
        self.v = v
    def min(self):
        return min(self.u, self.v)
    def max(self):
        return max(self.u, self.v)

N = int(input())
 
edge_list = []
for i in range(N - 1):
    u, v = map(int, input().split())
    edge_list.append(edge(u - 1, v - 1))
 
ver_num = int(N * (N + 1) * (N + 2) / 6)
 
edge_num = 0
for e in edge_list:
    edge_num += (N + 1 - (e.max() + 1)) * (e.min() + 1)
    
print(ver_num - edge_num)

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

edge_list = []
for i in range(N - 1):
    u, v = map(int, input().split())
    edge_list.append(edge(u - 1, v - 1))

ver_num = int(N * (N + 1) * (N + 2) / 6)

edge_num = 0
for e in edge_list:
    edge_num += (N + 1 - (e.max() + 1)) * (e.min() + 1)
    
print(ver_num - edge_num)
Problem p02719 (python)

Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()


def main():
  N, K = map(int, input().split())

  a = N%K
  if a > abs(a-K):
    print(abs(a-K))
  else:
    print(a)

if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
import sys
def input(): return sys.stdin.readline().rstrip()


def main():
  N, K = map(int, input().split())

  z = abs(N-K)
  if z > K:
    print(z%K)
  else:
    print(K%z)

if __name__ == '__main__':
  main()
Problem p02583 (python)

Fixed submission:
N = int(input())
L = list(map(int,input().split()))
L.sort()
count = 0
for i in range(len(L)):
    for j in range(i+1,len(L)):
        for k in range(j+1,len(L)):
            if L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[i] + L[k] > L[j] and L[i] != L[j] and L[j] != L[k] and L[i] != L[k]:
                count += 1
print(count)

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

count = 0
for i in range(len(L)):
    for j in range(len(L)):
        for k in range(len(L)):
            if L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[i] + L[k] > L[j] and i != j and j != k and i != k:
                count += 1
print(count)
Problem p02639 (python)

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

for i in range(5):
    if x[i] == 0:
        print(i+1)
        exit()

Buggy submission (verdict: Runtime Error):
X,N = map(int,input().split())
p = list(map(int,input().split()))
min = 0
i = 0
count = 0
while True:
    if abs(X - i) == min:
        if i not in p:
            break
        elif i in p and min != 0:
            count += 1
            if count == 2:
                min += 1
                count = 0
                i = 0
        else:
            min += 1
            i = 0
    i += 1

print(i)
Problem p02645 (python)

Fixed submission:
import random
S = input()

ran = random.randint(0,len(S)-3)

print(S[ran:ran+3])

Buggy submission (verdict: Runtime Error):
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    for mou in range(K):
        newA = [0]*N
        count = 0
        for i in A:
            for j in range(-i,i+1):
                if count+j >= 0 and count + j < N:
                    newA[count+j] += 1
            count +=1
        A = newA
    print(' '.join(map(str,A)))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())

if abs(B - A) > abs((V-W)*T):
    print("NO")
else:
    print("YES")
Problem p04030 (python)

Fixed submission:
moji = []
ans=""
s = str(input())
s = list(s)

def keyboard(key,list):
    if key == "0":
        list.append("0")
    elif key == "1":
        list.append("1")
    elif key == "B" and len(list) != 0:
        list.pop(-1)

for i in range(len(s)):
    keyboard(s[i],moji)

for x in moji:
    ans += x

print(ans)

Buggy submission (verdict: Runtime Error):
moji = []
ans=""
s = str(input())
s = list(s)

def keyboard(key,list):
    if key == "0":
        list.append("0")
    elif key == "1":
        list.append("1")
    elif key == "B":
        list.pop(-1)

for i in range(len(s)):
    keyboard(s[i],moji)

for x in moji:
    ans += x

print(ans)
Problem p02861 (python)

Fixed submission:
#!/usr/bin/env python3
# coding: utf-8
# Last Modified: 16/Nov/19 05:44:05 PM


import sys


def main():
    from math import factorial, sqrt
    from itertools import permutations

    n = int(input())
    arr = [get_array() for _ in range(n)]

    x = [i for i in range(n)]
    p = list(permutations(x))

    def dis(x1, y1, x2, y2):
        return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)

    distance = 0
    for j in p:
        for i in range(1, len(j)):
            distance += dis(
                arr[j[i]][0], arr[j[i]][1], arr[j[i - 1]][0], arr[j[i - 1]][1]
            )
    print(distance / factorial(n))


get_array = lambda: list(map(int, sys.stdin.readline().split()))


get_ints = lambda: map(int, sys.stdin.readline().split())


input = lambda: sys.stdin.readline().strip()


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# coding: utf-8
# Last Modified: 16/Nov/19 05:40:04 PM


import sys


def main():
    from math import factorial, sqrt
    from itertools import permutations

    n = int(input())
    arr = [get_array() for _ in range(n)]

    x = range(n)
    p = list(permutations(x))

    def dis(x1, y1, x2, y2):
        return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)

    distance = 0
    for j in p:
        for i in range(1, len(j)):
            distance += dis(*arr[j[i]], *arr[j[i - 1]])
    print(distance / factorial(n))


get_array = lambda: list(map(int, sys.stdin.readline().split()))


get_ints = lambda: map(int, sys.stdin.readline().split())


input = lambda: sys.stdin.readline().strip()


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# coding: utf-8
# Last Modified: 16/Nov/19 05:40:04 PM


import sys


def main():
    from math import factorial, sqrt
    from itertools import permutations

    n = int(input())
    arr = [get_array() for _ in range(n)]

    x = range(n)
    p = list(permutations(x))

    def dis(x1, y1, x2, y2):
        return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)

    distance = 0
    for j in p:
        for i in range(1, len(j)):
            distance += dis(*arr[j[i]], *arr[j[i - 1]])
    print(distance / factorial(n))


get_array = lambda: list(map(int, sys.stdin.readline().split()))


get_ints = lambda: map(int, sys.stdin.readline().split())


input = lambda: sys.stdin.readline().strip()


if __name__ == "__main__":
    main()
Problem p03043 (python)

Fixed submission:
#	!/usr/bin/env python3
#	encoding: UTF-8
#	Modified: <19/May/2019 05:51:38 PM>


#	✪ H4WK3yE乡
#	Mohd. Farhan Tahir
#	Indian Institute Of Information Technology (IIIT), Gwalior


import sys


def get_array(): return list(map(int, sys.stdin.readline().split()))


def get_ints(): return map(int, sys.stdin.readline().split())


def input(): return sys.stdin.readline().strip()


def main():
    #from math import log2
    n, k = get_ints()
    ans = 0
    for i in range(1, n + 1):
        curr = (1 / n)
        x = i
        while x < k:
            x *= 2
            curr *= (1 / 2)
        ans += curr
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#	!/usr/bin/env python3
#	encoding: UTF-8
#	Modified: <19/May/2019 05:51:03 PM>


#	✪ H4WK3yE乡
#	Mohd. Farhan Tahir
#	Indian Institute Of Information Technology (IIIT), Gwalior


import sys


def get_array(): return list(map(int, sys.stdin.readline().split()))


def get_ints(): return map(int, sys.stdin.readline().split())


def input(): return sys.stdin.readline().strip()


def main():
    from math import log2
    n, k = get_ints()
    ans = 0
    for i in range(1, n + 1):
        curr = (1 / n)
        x = i
        while x < k:
            x *= 2
            curr *= (1 / 2)
        ans += curr
    print(ans)


if __name__ == "__main__":
    main()
Problem p02732 (python)

Fixed submission:
N = int(input())
A = [int(a)-1 for a in input().split()]
X = [0] * N
for a in A:
	X[a] += 1
s = 0
for x in X:
	s += x * (x-1) // 2
for a in A:
	print(s - (X[a] - 1))

Buggy submission (verdict: Runtime Error):
import math
import collections
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


def combinations_count(n, r):
	if n < 2:
		return 0
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

_ = int(input())
ns = input().split(" ")
cs = collections.Counter(ns)

jjj1=[]
jjj2=[]
for k, v in cs.items():
	cs[k]
	jjj1.append(cmb(v-1, 2))
	jjj2.append(cmb(v, 2))

c = 0
for n in ns:
	for k, v in cs.items():
		if v==1:
			c += 0
		elif n==k:
#			c += combinations_count(v-1, 2)
			c += cmb(v-1, 2)
		else:
#			c += combinations_count(v, 2)
			c += cmb(v, 2)
	print(c)
	c = 0

Buggy submission (verdict: Runtime Error):
import math
import collections
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


def combinations_count(n, r):
	if n < 2:
		return 0
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

_ = int(input())
ns = input().split(" ")
cs = collections.Counter(ns)

c = 0
for n in ns:
	for k, v in cs.items():
		if v==1:
			c += 0
		elif n==k:
#			c += combinations_count(v-1, 2)
			c += cmb(v-1, 2)
		else:
#			c += combinations_count(v, 2)
			c += cmb(v, 2)
	print(c)
	c = 0

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

def combinations_count(n, r):
	if n < 2:
		return 0
	return int(math.factorial(n) / math.factorial(r) /  math.factorial(n-r))

_ = int(input())
ns = input().split(" ")
cs = collections.Counter(ns)

c = 0
for n in ns:
	for k, v in cs.items():
		if v==1:
			c += 0
		elif n==k:
			c += combinations_count(v-1, 2)
		else:
			c += combinations_count(v, 2)
	print(c)
	c = 0
Problem p02608 (python)

Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()


cnt=[0]*(n+1)

for x in range(1,n+1):
  if x**2+x>n:
    break
  for y in range(x,n+1):
    if x**2+y**2+x*y+x+y>n:
      break
    for z in range(y,n+1):
      num = x**2+y**2+z**2+x*y+y*z+x*z
      if num > n:
        break
      if x==y==z:
        cnt[num]+=1
      elif x==y:
        cnt[num]+=3
      elif y==z:
        cnt[num]+=3
      elif x==z:
        cnt[num]+=3
      else:
        cnt[num]+=6

for i in range(1,n+1):
  print(cnt[i])

Buggy submission (verdict: Runtime Error):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()


cnt=[0]*(n+1)

for x in range(1,n+1):
  if x**2+x>n+1:
    break
  for y in range(x,n+1):
    if x**2+y**2+x*y+x+y>n+1:
      break
    for z in range(y,n+1):
      num = x**2+y**2+z**2+x*y+y*z+x*z
      if num > n+1:
        break
      if x==y==z:
        cnt[num]+=1
      elif x==y:
        cnt[num]+=3
      elif y==z:
        cnt[num]+=3
      elif x==z:
        cnt[num]+=3
      else:
        cnt[num]+=6

for i in range(1,n+1):
  print(cnt[i])
Problem p02684 (python)

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

now = 0
a=list(map(int,input().split()))

s = []
od = [-1]*(n+1)
c=1
l=0

v=1

while od[v] == -1:
  od[v] = len(s)
  s.append(v)
  v = a[v-1]

c=len(s)-od[v]
l=od[v]

if k<l:
  print(s[k])
else:
  k-=l
  k%=c
  print(s[l+k])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())

now = 0
a = [_-1 for _ in list(map(int,input().split()))]

past = []
offset = 0
cnt = 0
idx = 0
fl = False
for i in range(k):
  if fl:
    break
  past.append(now)
  now = a[now]
  try:
    idx = past.index(now)
    cnt = i-idx+1
    fl = True
    break
  except:
    pass

now = 0
for i in range(k % cnt):
  now = a[now]

print(offset + now+1)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())

now = 0
a = [_-1 for _ in list(map(int,input().split()))]

past = []
offset = 0
cnt = 0
idx = 0
for i in range(k):
    past.append(now)
    now = a[now]
    try:
      idx = past.index(now)
      cnt = i-idx+1
      break
    except:
      pass

now = 0
for i in range(k % cnt):
  now = a[now]

print(offset + now+1)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())

now = 0
a = [_-1 for _ in list(map(int,input().split()))]

cnt = 0
for i in range(k):
    now = a[now]
    if now == 0:
      cnt = i+1
      break
  
now = 0
for i in range(k % cnt):
  now = a[now]

print(now+1)
Problem p02743 (python)

Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

from math import sqrt

a,b,c=map(int, input().split())
if 4*a*b<(c-a-b)**2 and (c-a-b)>=0:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

from math import sqrt

a,b,c=map(float, input().split())
if (a+b+2*sqrt(a*b)-c)**100<1>>40:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

from math import sqrt

a,b,c=float(input())

if sqrt(a)+sqrt(b)<sqrt(c):
  print('Yes')
else:
  print('No')
Problem p02922 (python)

Fixed submission:
a, b = map(int, input().split())

plgcnt = 0
tapcnt = 1

flg=0

while(True):
    if tapcnt >= b:
        print(plgcnt)
        break
    tapcnt += a - 1
    plgcnt += 1

Buggy submission (verdict: Runtime Error):
import math


def kaijo(n):
    if n == 0:
        return 1
    return n * kaijo(n - 1)


a, b = map(int,input().split())

ans = 0
for i in range(5):
    if b == 0:
        ans = 0
        break
    if a == b:
        ans = 1
        break
    if a ** i < b:
        continue
    ans = math.floor(b / (a ** (i - 1))) + kaijo(i-1)
    break

print(ans)

Buggy submission (verdict: Runtime Error):
import math


def kaijo(n):
    if n == 0:
        return 1
    return n * kaijo(n - 1)


a, b = map(int,input().split())

ans = 0
for i in range(5):
    if b == 0:
        ans = 0
        break
    if a == b:
        ans = 1
        break
    if a ** i < b:
        continue
    ans = math.floor(b / (a ** (i - 1))) + kaijo(i-1)
    break

print(ans)
Problem p02947 (python)

Fixed submission:
n = int(input())
sraw = dict()

for nn in range(n):
    i = "".join(sorted(input()))
    if i in sraw:
        sraw[i] += 1
    else:
        sraw[i] = 1

ans = 0

for ss in sraw:
    ans += round(sraw[ss]*(sraw[ss]-1)/2)

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

n = int(input())
sraw = []

for nn in range(n):
    sraw.append(sorted(input().encode()))

ans = 0

#s = np.sort(np.array(sraw), axis=0).tolist()
s = sorted(sraw)
#print(s)

l = len(s)

for ss in range(0, l):
    fl = 0
    #print("")
    for sss in range(ss+1, l):
        #print("{0} {1}".format(s[ss],s[sss]))
        if s[ss] == s[sss]:
            ans += 1
            fl = 1

        elif fl == 1:

            break


print(ans)