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

Fixed submission:
N = int(input())
X = list(map(int, input().split()))
max_N = max(X)
ans = 10000000000

for p in range(1, max_N+1):
    tmp = sum([(x-p)**2 for x in X])
    if tmp <= ans:
        ans = tmp
    else:
        break
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
X = list(map(int, input().split()))
max_N = max(X)
ans = []

for p in range(1, max_N):
    tmp = sum([(x-p)**2 for x in X])
    ans.append(tmp)
print(min(ans))
Problem p02843 (python)

Fixed submission:
X = int(input())
dp = [True] + [False] * (X)

if X < 106:
  if 100 <= X <= 105:
    print(1)
    exit()
  else:
    print(0)
    exit()


# 100~105円はyes
for i in range(100,106):
  dp[i] = True

for i in range(106,X+1):
  for j in range(100,106):
    if dp[i-j] == True:
      dp[i] = True
      break

print(1 if dp[X] == True else 0)

Buggy submission (verdict: Runtime Error):
X = int(input())
dp = [True] + [False] * (X)

# 100~105円はyes
for i in range(100,106):
  dp[i] = True

for i in range(106,X+1):
  for j in range(100,106):
    if dp[i-j] == True:
      dp[i] = True
      break

print(1 if dp[X] == True else 0)
Problem p02995 (python)

Fixed submission:
import sys,fractions
input = sys.stdin.readline

A,B,C,D = map(int,input().split())


lcm =  (C*D)//fractions.gcd(C,D)
c=0
End = (B//C)+(B//D)-(B//(lcm))

Start = ((A-1)//C)+((A-1)//D)-((A-1)//(lcm))

print(int((B-A+1)-(End-Start)))

Buggy submission (verdict: Runtime Error):
import sys,math
input = sys.stdin.readline

A,B,C,D = map(int,input().split())
lcm =  (C*D)/math.gcd(C,D)
c=0
End = (B//C)+(B//D)-(B//(lcm))
if A != 1:
  Start = ((A-1)//C)+((A-1)//D)-((A-1)//(lcm))
else :
  Start = 1
print(int((B-A+1)-(End-Start)))
Problem p02996 (python)

Fixed submission:
import sys
from operator import itemgetter
input = sys.stdin.readline
N = int(input())
A_B = [list(map(int,input().split())) for i in range(N)]
A_B = sorted(A_B,key=itemgetter(1))
#print(A_B)
s=0
for a_b in A_B:
  s+=a_b[0]
  lim = a_b[1]
  if s > lim:
    print("No")
    exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
N = int(input())
A_B = [list(map(int,input().split())) for i in range(N)]
A_B = sorted(A_B,key=itemgetter(1))
#print(A_B)
s=0
for a_b in A_B:
  s+=a_b[0]
  lim = a_b[1]
  if s > lim:
    print("No")
    exit()
print("Yes")
Problem p03061 (python)

Fixed submission:
import sys,fractions
input=sys.stdin.readline
N=int(input())
num = list(map(int,input().split()))
g = fractions.gcd
left=[0]*(N+1)
right=[0]*(N+1)
for i in range(N):
  j = N-i-1#初期値=4
  left[i+1] = g(left[i],num[i])
  right[j] = g(right[j+1],num[j])
ans=0
for k in range(N):
  ans = max(ans,g(left[k],right[k+1]))
print(ans)

Buggy submission (verdict: Runtime Error):
import sys,math
input=sys.stdin.readline
N=int(input())
num = list(map(int,input().split()))
left=[0]*(N+1)
right=[0]*(N+1)
for i in range(N):
  j = N-i-1#初期値=4
  left[i+1] = math.gcd(left[i],num[i])
  right[j] = math.gcd(right[j+1],num[j])
ans=0
for k in range(N):
  ans = max(ans,math.gcd(left[k],right[k+1]))
print(ans)
Problem p03069 (python)

Fixed submission:
import sys
input=sys.stdin.readline
N=int(input())
S=input()
w=S.count('.')
c=w
for i in range(N):
  if S[i]=='.':
    w-=1
  else:
    w+=1
  c=min(c,w)
print(c)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
N=int(input())
S=list(input()[:-1])
c=0
for i in range(1,N+1):
  if S[i-1]=='#'and S[i]=='.':
    S[i]='#'
    c+=1
print(c)
Problem p03087 (python)

Fixed submission:
N,Q = map(int,input().split())
S = input()
cnt = [0] * (N + 1)
lrs = []
for i in range(Q):
        lrs.append(list(map(int,input().split())))

for i in range(N):
        cnt[i+1] = cnt[i] + (1 if S[i:i+2] == "AC" else 0)
for lr in lrs:
        print(cnt[lr[1] - 1] - cnt[lr[0] - 1])

Buggy submission (verdict: Runtime Error):
N,Q = map(int,input().split())
S = input()
cnt = []
lrs = []
for i in range(Q):
        lrs.append(list(map(int,input().split())))

for k in range(len(S) - 1):
    if S[k] == 'A':
            if S[k+1] == 'C':
                    cnt.append(1)
    else:
            cnt.append(0)



for lr in lrs:
    sums = 0
    for k in range(lr[0]-1,lr[1]-1):
        sums += cnt[k]
    print(sums)

Buggy submission (verdict: Runtime Error):
N,Q = map(int,input().split())
S = input()
cnt = []
lrs = []
for i in range(Q):
        lrs.append(list(map(int,input().split())))

for k in range(len(S) - 1):
    if S[k] == 'A':
            if S[k+1] == 'C':
                    cnt.append(1)
    else:
            cnt.append(0)



for lr in lrs:
    sums = 0
    for k in range(lr[0]-1,lr[1]-1):
        sums += cnt[k]
    print(sums)
Problem p03323 (python)

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

if (A > 8) or (B > 8):
    print(":(")
else:
    print("Yay!")

Buggy submission (verdict: Runtime Error):
A,B = map(int, raw_input().split())
if((A <= 8) or (B <= 8)):
	print("Yay!")
else:
	print(":(")
Problem p03543 (python)

Fixed submission:
N=input();cnt=0
for i in range(1,4):
    if N[i-1]==N[i]:
        cnt+=1
        if cnt>=2:
            print('Yes')
            exit()
    else:
        cnt=0
print('No')

Buggy submission (verdict: Runtime Error):
N=input();c=0
for n in range(len(N)-1):
    if N[n]==N[n+1]:
        c+=1
    else:
        c=0
   if c>=3:
    print('Yes')
    exit()
print('No')

Buggy submission (verdict: Runtime Error):
N=input();c=0
for n in range(len(N)-1):
    if N[n]==N[n+1]:
        c+=1
    else:
        c=0
   if c>=3:
    print('Yes')
    exit()
print('No')
Problem p03998 (python)

Fixed submission:
# ABC045
from collections import deque
S_A = deque(input())
S_B = deque(input())
S_C = deque(input())

# 最初はAから
next_turn = 'a'

while True:
    # 勝利判定
    if len(S_A) == 0 and next_turn == 'a':
        print("A")
        exit()
    elif len(S_B) == 0 and next_turn == 'b':
        print("B")
        exit()
    elif len(S_C) == 0 and next_turn == 'c':
        print("C")
        exit()
    else:
        if next_turn == 'a':
            next_turn = S_A.popleft()
        elif next_turn == 'b':
            next_turn = S_B.popleft()
        elif next_turn == 'c':
            next_turn = S_C.popleft()

Buggy submission (verdict: Runtime Error):
# ABC045
from collections import deque
S_A = deque(input())
S_B = deque(input())
S_C = deque(input())

next_turn = S_A.pop()

while True:
    if next_turn == 'a':
        next_turn = S_A.pop()
    elif next_turn == 'b':
        next_turn = S_B.pop()
    else:
        next_turn = S_C.pop()

    # 勝利判定
    if len(S_A) == 0:
        print("A")
        exit()
    elif len(S_B) == 0:
        print("B")
        exit()
    elif len(S_C) == 0:
        print("C")
        exit()
    else:
        pass
Problem p02536 (python)

Fixed submission:

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    
N,M = map(int,input().split())
A = [0]*M
B = [0]*M
for i in range(M):
    A[i],B[i] = map(int,input().split())
uf = UnionFind(N)
for i in range(M):
    uf.union(A[i]-1,B[i]-1)
groups = uf.group_count()
print(groups-1)

Buggy submission (verdict: Runtime Error):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    
N,M = map(int,input().split())
A = [0]*M
B = [0]*M
for i in range(M):
    A[i],B[i] = map(int,input().split())
uf = UnionFind(N)
for i in range(M):
    uf.union(A[i],B[i])
groups = uf.group_count()
print(groups-1)
Problem p02615 (python)

Fixed submission:
N = int(input())
A = sorted(map(int,input().split()),reverse = True)
answer = 0
i = 1
s = 0
answer = A[0]
if N == 2:
    anwer=A[0]
else:
    while True:
        s = (i+1)//2
        answer += A[s]
        i += 1
        if i == N-1:
            break
    
print(answer)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = sorted(map(int,input().split()),reverse = True)
answer = 0
i = 1
s = 0
answer = A[0]
while True:
    s = (i+1)//2
    answer += A[s]
    i += 1
    if i == N-1:
        break
    
print(answer)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = sorted(map(int,input().split()),reverse = True)
answer = 0
i = 1
s = 0
answer = A[0]
while True:
    s = (i+1)//2
    answer += A[s]
    print(i,s)
    i += 1
    if i == N-1:
        break
    
print(answer)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = sorted(map(int,input().split()),reverse = True)
answer = 0
i = 1
s = 0
answer = A[0]
while True:
    s = i-(i-1)%2
    answer += A[s]
    #print(i,s)
    i += 1
    if i == N-1:
        break
    
print(answer)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = sorted(map(int,input().split()),reverse = True)
answer = 0
i = 1
s = 0
answer = A[0]
while True:
    s = i+i%2
    answer += A[s]
    #print(i,s)
    i += 1
    if i == N-1:
        break
    
print(answer)
Problem p02684 (python)

Fixed submission:
N,K = map(int,input().split())
A = list(map(int,input().split()))
town = 1
record = [1]
record2 = [0]*N
for i in range(N):
    town = A[town-1]
    if record2[town-1]==1:
        break
    record.append(town)
    record2[town-1] += 1
    
newrecord = record[record.index(town):]
roop = len(newrecord)
newK = K-(len(record)-roop)
if newK>=0:
    answer = newrecord[newK%roop]
else:
    answer = record[K]

print(answer)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = list(map(int,input().split()))
town = 1
record = [1]
for i in range(K):
    town = A[town-1]
    if town in record:
        break
    record.append(town)
    
newrecord = record[record.index(town):]
roop = len(newrecord)
amari = K%roop

if K<=len(record):
    answer = record[amari]
elif amari-(len(record)-roop)>=0:
    answer = newrecord[amari-(len(record)-roop)]
else:
    answer = newrecord[(amari-(len(record)-roop))%3]
    
print(answer)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = list(map(int,input().split()))
town = 1
record = [1]
for i in range(K):
    town = A[town-1]
    if town in record:
        break
    record.append(town)
    
newrecord = record[record.index(town):]
roop = len(newrecord)
amari = K%roop

if K<=len(record):
    answer = record[amari]
else:
    answer = newrecord[amari-(len(record)-roop)]
print(answer)
Problem p02690 (python)

Fixed submission:
X = int(input())
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)
    return divisors

for i in range(len(make_divisors(X))):
    A = make_divisors(X)[i]
    for j in range(-64,119):
        if (A+j)**5-j**5==X:
            a = j + A
            b = j
            break
        else:
            continue
        break
    else:
        continue
    break
print(a,b)

Buggy submission (verdict: Runtime Error):
X = int(input())
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)
    return divisors

for i in range(len(make_divisors(X))):
    A = make_divisors(X)[i]
    for j in range(-63,118):
        if (A+j)**5-j**5==X:
            a = j + A
            b = j
            break
        else:
            continue
        break
    else:
        continue
    break
print(a,b)

Buggy submission (verdict: Runtime Error):
X = int(input())
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)
    return divisors

for i in range(len(make_divisors(X))):
    A = make_divisors(X)[i]
    for j in range(-int(X**(1/5))-1,int(X**(1/5))+1):
        if (A+j)**5-j**5==X:
            a = j + A
            b = j
            break
        else:
            continue
        break
    else:
        continue
    break
print(a,b)

Buggy submission (verdict: Runtime Error):
X = int(input())
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)
    return divisors

for i in range(len(make_divisors(X))):
    A = make_divisors(X)[i]
    for j in range(-int(X**(1/5)),int(X**(1/5))+1):
        if (A+j)**5-j**5==X:
            a = j + A
            b = j
            break
        else:
            continue
        break
    else:
        continue
    break
print(a,b)

Buggy submission (verdict: Runtime Error):
X = int(input())
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)
    return divisors

for i in range(len(make_divisors(X))):
    A = make_divisors(X)[i]
    for j in range(-int(X**(1/5)),int(X**(1/5))):
        if (A+j)**5-j**5==X:
            a = j + A
            b = j
            break
        else:
            continue
        break
    else:
        continue
    break
print(a,b)
Problem p02760 (python)

Fixed submission:
A = [0]*3
for i in range(3):
    A[i] = list(map(int,input().split()))
N = int(input())
B = []
for _ in range(N):
    B.append(int(input()))
             
for k in range(3):
    for j in range(3):
        if A[k][j] in B:
             A[k][j] = 0
answer = 'No'
for i in range(3):
    if sum(A[i])==0:
        answer = 'Yes'
        break
    count = 0
    for j in range(3):
        count += A[j][i]
    if count == 0:
        answer = 'Yes'
if A[0][0]+A[1][1]+A[2][2]==0:
    answer = 'Yes'
if A[0][2]+A[1][1]+A[2][0]==0:
    answer = 'Yes'
print(answer)

Buggy submission (verdict: Runtime Error):
A = [0]*3
for i in range(3):
    A[i] = list(map(int,input().split()))
N = int(input())
B = []
for _ in range(N):
    B.append(int(input())
             
for k in range(3):
    for j in range(3):
        if A[k][j] in B:
             A[k][j] = 0
answer = 'No'
for i in range(3):
    if sum(A[i])==0:
        answer = 'Yes'
        break
    count = 0
    for j in range(3):
        count += A[j][i]
print(answer)
Problem p02898 (python)

Fixed submission:
N,K = map(int,input().split())
H = sorted(map(int,input().split()))
count = N
for i in range(N):
    if H[i]>=K:
        count = i
        break
print(N-count)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
H = sorted(map(int,input().split()))
for i in range(N):
    if H[i]>=K:
        count = i
        break
print(max(N-count,0))
Problem p02953 (python)

Fixed submission:
N = int(input())
H = list(map(int,input().split()))
i = 0
H[0] -= 1

while True:
    if N == 1:
        answer = 'Yes'
        break
    if H[i]<H[i+1]:
        H[i+1] -= 1
    if H[i]>H[i+1]:
        answer = 'No'
        break
    i += 1
    if i == N-1:
        answer = 'Yes'
        break
print(answer)

Buggy submission (verdict: Runtime Error):
N = int(input())
H = list(map(int,input().split()))
i = 0
H[0] -= 1
while True:
    
    if H[i]<H[i+1]:
        H[i+1] -= 1
  
    if H[i]>H[i+1]:
        answer = 'No'
        break
    
    i += 1
    if i == N-1:
        answer = 'Yes'
        break
print(answer)

Buggy submission (verdict: Runtime Error):
N = int(input())
H = list(map(int,input().split()))
i = 0

while True:
    
    if H[i]<H[i+1]:
        H[i+1] -= 1
  
    if H[i]>H[i+1]:
        answer = 'No'
        break
    
    i += 1
    if i == N-1:
        answer = 'Yes'
        break
print(answer)
Problem p02576 (python)

Fixed submission:
import math

N, X, T = list(map(int, input().split()))

print(math.ceil(N / X) * T)

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

print((N // X + 1) * T)
Problem p02579 (python)

Fixed submission:
from collections import deque
import math
 
def explore(C, D):
    queue = deque([(C[0]-1, C[1]-1)])
    maze_visited[C[0]-1][C[1]-1] = 0
    while queue:
        y, x = queue.popleft()
        mv_cur = maze_visited[y][x]
        for i, j in [(1,0),(0,1),(-1,0),(0,-1)]:
            n_x, n_y = x + i, y + j
            if n_x >= 0 and n_y >= 0 and n_x < W and n_y < H:
                mv_n = maze_visited[n_y][n_x]
                if mv_n > mv_cur:
                    if S[n_y][n_x] == '.':
                        maze_visited[n_y][n_x] = mv_cur
                        queue.appendleft((n_y, n_x))
        for i in range(-2, 3):
            for j in range(-2, 3):
                if abs(i) + abs(j) <= 1:
                    continue
                n_x, n_y = x + i, y + j
                if n_x >= 0 and n_y >= 0 and n_x < W and n_y < H:
                    mv_n = maze_visited[n_y][n_x]
                    if mv_n > mv_cur + 1:
                        if S[n_y][n_x] == '.':
                            maze_visited[n_y][n_x] = mv_cur + 1
                            queue.append((n_y, n_x))
    
H, W = list(map(int, input().split()))
C = list(map(int, input().split()))
D = list(map(int, input().split()))
 
S = [list(input()) for i in range(H)]
 
maze_visited = [[math.inf] * W for i in range(H)]
 
explore(C,D)
 
if maze_visited[D[0] - 1][D[1] - 1] == math.inf:
    print('-1')
else:
    print(maze_visited[D[0] - 1][D[1] - 1])

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

def explore(C, D):
    queue = deque([[C[0]-1, C[1]-1]])
    maze_visited[C[0]-1][C[1]-1] = 0
    while queue:
        y, x = queue.popleft()
        mv_cur = maze_visited[y][x]
        for i, j in [(1,0),(0,1),(-1,0),(0,-1)]:
            n_x, n_y = x + i, y + j
            if n_x >= 0 and n_y >= 0 and n_x < W and n_y < H:
                mv_n = maze_visited[n_y][n_x]
                if mv_n > mv_cur:
                    if S[n_y][n_x] == '.':
                        maze_visited[n_y][n_x] = mv_cur
                        queue.append([n_y, n_x])
        for i in range(-2, 3):
            for j in range(-2, 3):
                if abs(i) + abs(j) <= 1:
                    continue
                n_x, n_y = x + i, y + j
                if n_x >= 0 and n_y >= 0 and n_x < W and n_y < H:
                    mv_n = maze_visited[n_y][n_x]
                    if mv_n > mv_cur + 1:
                        if S[n_y][n_x] == '.':
                            maze_visited[n_y][n_x] = mv_cur + 1
                            queue.append([n_y, n_x])
    
H, W = list(map(int, input().split()))
C = list(map(int, input().split()))
D = list(map(int, input().split()))

S = [list(input()) for i in range(H)]

maze_visited = [[math.inf] * W for i in range(H)]

explore(C,D)

if maze_visited[D[0] - 1][D[1] - 1] == math.inf:
    print('-1')
else:
    print(maze_visited[D[0] - 1][D[1] - 1])
Problem p02691 (python)

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

diffMax = 2 * max(heights)
diffMin = 2 * min(heights)

cnt = 0

arrSize = min([max([i + heights[i] for i in range(len(heights))]),max([i - heights[i] for i in range(len(heights))])]) + 1

seppenPlus = [0] * arrSize
seppenMinus = [0] * arrSize


for i in range(len(heights)):
    seppenPlusNum = i + heights[i]
    seppenMinusNum = i - heights[i]

    if seppenPlusNum < arrSize:
    	seppenPlus[seppenPlusNum] += 1

    if seppenMinusNum >= 0:
        seppenMinus[seppenMinusNum] += 1

for i in range(len(seppenPlus)):
    cnt += seppenPlus[i] * seppenMinus[i]

print(cnt)

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

cnt = 0

seppenPlus = [0] * (n + max(heights))
seppenMinus = [0] * (n + max(heights))

for i in range(len(heights)):
    seppenPlusNum = i + heights[i]
    seppenMinusNum = i - heights[i]

    seppenPlus[seppenPlusNum] += 1

    if seppenMinusNum >= 0:
        seppenMinus[seppenMinusNum] += 1

for i in range(len(seppenPlus)):
    cnt += seppenPlus[i] * seppenMinus[i]

print(cnt)
Problem p02696 (python)

Fixed submission:
import math

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

if b <= 10**6:
    maxVal = 0

    for i in range(b):
        if i > n:
            break
        val = math.floor(a*i/b)-a*math.floor(i/b)
        if val > maxVal:
            maxVal = val

    print(maxVal)
elif n > b:
    print(a-1)
elif n == b:
    m = n - 1
    print(math.floor(a*m/b)-a*math.floor(m/b))
else:
    print(math.floor(a*n/b)-a*math.floor(n/b))

Buggy submission (verdict: Runtime Error):
import math

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

if b <= 10**6
    maxVal = 0

    for i in range(b):
        if i > n:
            break
        val = math.floor(a*i/b)-a*math.floor(i/b)
        if val > maxVal:
            maxVal = val

    print(maxVal)
elif n > b:
    print(a-1)
elif n == b:
    m = n - 1
    print(math.floor(a*m/b)-a*math.floor(m/b))
else:
    print(math.floor(a*n/b)-a*math.floor(n/b))
Problem p02702 (python)

Fixed submission:
s = list(input())
mods = [0]*(len(s))
countRemainder = [0] * 2019
cnt = 0


m = 1
mod = 0
for i in range(len(s)):
    mod += int(s[len(s) - i - 1]) * m

    mod %= 2019
    m *= 10
    m %= 2019

    countRemainder[mod] += 1

countRemainder[0] += 1

for i in range(2019):
    cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)

print(cnt)

Buggy submission (verdict: Runtime Error):
s = list(input())
mods = [0]*(len(s))
countRemainder = [0] * 2019
cnt = 0

for i in range(len(s)):
    if i == 0:
        mods[0] = int(s[-1])
    else:
        mods[i] = mods[i-1] + (10**i % 2019) * int(s[len(s) - i - 1])
    countRemainder[mods[i]] += 1

countRemainder[0] += 1

for i in range(2019):
    cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)

print(cnt)