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

Fixed submission:
n = int(input())
tree = [[] for _ in range(n)]
for i in range(n - 1):
    a, b, c = map(int, input().split())
    a, b, c = a - 1, b - 1, c
    tree[a].append((b, c))
    tree[b].append((a, c))

from heapq import heappush, heappop
INF = 10 ** 18
def dijkstra(s, n): # (始点, ノード数)
    dist = [INF] * n
    hq = [(0, s)] # (distance, node)
    dist[s] = 0
    seen = [False] * n # ノードが確定済みかどうか
    while hq:
        v = heappop(hq)[1] # ノードを pop する
        seen[v] = True
        for to, cost in tree[v]: # ノード v に隣接しているノードに対して
            if seen[to] == False and dist[v] + cost < dist[to]:
                dist[to] = dist[v] + cost
                heappush(hq, (dist[to], to))
    return dist

q, k = map(int, input().split())
k -= 1
dist = dijkstra(k, n)
for i in range(q):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    res = dist[x] + dist[y]
    print(res)

Buggy submission (verdict: Runtime Error):
n = int(input())
tree = [[] for _ in range(n)]
for i in range(n - 1):
    a, b, c = map(int, input().split())
    a, b, c = a - 1, b - 1, c
    tree[a].append((b, c))
    tree[b].append((a, c))

limit = 100010
depth = [0] * limit

def dfs(v, p, d): # (現在の頂点v, vの親, 現在の距離)
    depth[v] = d
    for e in tree[v]:
        if e[0] == p: continue
        dfs(e[0], v, d + e[1])

q, k = map(int, input().split())
k -= 1
dfs(k, -1, 0)
for i in range(q):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    res = depth[x] + depth[y]
    print(res)
Problem p02570 (python)

Fixed submission:
d,t,s= map(int,input().split())

if (d/s) <= t:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix
import collections

N, M = map(int, input().split())
edge = np.array([input().split() for _ in range(M)], dtype=np.int8).T

if M == 0:
    print(1)
else:

    tmp = np.ones(M, dtype=np.int8).T
    graph = csr_matrix((tmp, (edge[:] - 1)), (N, N))

    n, labels = connected_components(graph)

    c = collections.Counter(labels)

    print(max(c.values()))
Problem p03013 (python)

Fixed submission:
n, m = map(int, input().split())
outlist = [int(input()) for i in range(m)]


def Fib(num):
    a, b = 1, 0
    for _ in range(num):
        a, b = (a + b) % 1000000007, a % 1000000007
    return (a)


def stepcount(x, y):
    if y - x <= 1:
        return 1
    else:
        return Fib(y - x)

if m != 0:
    answer = Fib(outlist[0] - 1)

    for i in range(m - 1):
        answer *= stepcount(outlist[i] + 1, outlist[i + 1] - 1)
        answer = answer % 1000000007

    answer = (answer * stepcount(outlist[m - 1] + 1, n)) % 1000000007

    for i in range(m - 1):
        if outlist[i + 1] - outlist[i] == 1:
            answer = 0
else:
    answer = Fib(n)

print(answer)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
outlist = [int(input()) for i in range(m)]


def Fib(num):
    a, b = 1, 0
    for _ in range(num):
        a, b = (a + b) % 1000000007, a % 1000000007
    return (a)


def stepcount(x, y):
    if y - x <= 1:
        return 1
    else:
        return Fib(y - x)


answer = Fib(outlist[0] - 1)

for i in range(m - 1):
    answer *= stepcount(outlist[i] + 1, outlist[i + 1] - 1)
    answer = answer % 1000000007

answer = (answer * stepcount(outlist[m - 1] + 1, n)) % 1000000007

for i in range(m - 1):
    if outlist[i + 1] - outlist[i] == 1:
        answer = 0

print(answer)

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
outlist = [int(input()) for i in range(m)]

def Fib(num):
    a, b = 1, 0
    for _ in range(num):
        a, b = (a + b) % 1000000007, a % 1000000007
    return(a)

def stepcount(x,y):
    if y-x <= 1:
        return 1
    else:
        return Fib(y-x)

answer = Fib(outlist[0]-1)

for i in range(m-1):
    answer *= stepcount(outlist[i]+1,outlist[i+1]-1)
    answer = answer % 1000000007

answer = (answer * stepcount(outlist[m-1]+1, n)) % 1000000007

for i in range(m-1):
    if outlist[i+1] - outlist[i] == 1:
        answer = 0

print(answer)
Problem p02550 (python)

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

if X == 0:
    print(0)
    exit()

if N == 1:
    print(X)
    exit()

d = [-1] * (M + 1)
out = [0]
a = X
ans = 0
for i in range(1, N + 1):
    ans += a
    d[a] = i
    out.append(a)
    a = a ** 2 % M
    if a == 0:
        print(ans)
        exit()

    if d[a] != -1:
        loop_num = i + 1 - d[a]
        remain = N - i
        ans += sum(out[d[a]:d[a] + loop_num]) * (remain // loop_num)
        ans += sum(out[d[a]:d[a] + (remain % loop_num)])
        break
print(ans)

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

if X == 0:
    print(0)
    exit()

if N == 1:
    print(X)
    exit()

d = [-1] * (M + 1)
out = [0]
a = X
ans = 0
for i in range(1, N + 1):
    ans += a
    d[a] = i
    out.append(a)
    a = a ** 2 % M
    if a == 0:
        print(ans)
        exit()

    if d[a] != -1:
        loop_num = i + 1 - d[a]
        remain = N - i
        break
ans += sum(out[d[a]:d[a] + loop_num]) * (remain // loop_num)
ans += sum(out[d[a]:d[a] + (remain % loop_num)])

print(ans)

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

if X == 0:
    print(0)
    exit()
    
if N == 1:
    print(X)
    exit()

d = [-1] * (M + 1)
out = [0]
a = X
ans = 0
for i in range(1, N + 1):
    ans += a
    d[a] = i
    out.append(a)
    a = a ** 2 % M
    if d[a] != -1:
        loop_num = i + 1 - d[a]
        remain = N - i
        break
ans += sum(out[d[a]:d[a] + loop_num]) * (remain // loop_num)
ans += sum(out[d[a]:d[a] + (remain % loop_num)])

print(ans)

Buggy submission (verdict: Runtime Error):
N, X, M = map(int, input().split())
d = [-1] * (M + 1)
out = [0]
a = X
ans = 0
for i in range(1, N + 1):
    ans += a
    d[a] = i
    out.append(a)
    a = a ** 2 % M
    if d[a] != -1:
        loop_num = i + 1 - d[a]
        remain = N - i
        break
ans += sum(out[d[a]:d[a] + loop_num]) * (remain // loop_num)
ans += sum(out[d[a]:d[a] + (remain % loop_num)])

print(ans)
Problem p02623 (python)

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cumsum_a = [0] * (N + 1)
cumsum_b = [0] * (M + 1)

for i in range(1, N + 1):
    cumsum_a[i] = cumsum_a[i - 1] + A[i - 1]

for i in range(1, M + 1):
    cumsum_b[i] = cumsum_b[i - 1] + B[i - 1]

ans = 0
bi = M
for i in range(N+1):
    for j in range(bi, -1, -1):
        t = cumsum_a[i] + cumsum_b[j]
        if t <= K:
            ans = max(ans, i + j)
            bi = j
            break

print(ans)

Buggy submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if n > m:
    b += [10**9+1]*(n-m)
elif m > n:
    a += [10**9+1]*(m-n)

t = 0
i, j = 0, 0
ans = 0
while i < n or j < m:
    if a[i] <= b[j]:
        if t + a[i] <= k:
            t += a[i]
            i += 1
        else:
            break
    else:
        if t + b[j] <= k:
            t += b[j]
            j += 1
        else:
            break
    ans += 1

print(ans)
Problem p02912 (python)

Fixed submission:
def pushHeap(array, elem):
    n = len(array)
    array.append(elem)
    while n != 0:
        i = int((n - 1) / 2)
        if array[n] > array[i]:
            tmp = array[n]
            array[n] = array[i]
            array[i] = tmp
        n = i


def popHeap(array):
    n = len(array) - 1
    array[0] = array[n]
    del array[-1]
    i = 0
    while 2 * i + 1 < n:
        j = 2 * i + 1
        if j != n - 1 and array[j] < array[j + 1]:
            j += 1
        if array[i] < array[j]:
            tmp = array[j]
            array[j] = array[i]
            array[i] = tmp
        i = j


N, M = map(int, input().split())
A = list(map(int, input().split()))
heap_A = []

for a in A:
    pushHeap(heap_A, a)

for _ in range(M):
    discount_max = int(heap_A[0] / 2)
    popHeap(heap_A)
    pushHeap(heap_A, discount_max)

print(sum(heap_A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

if N == 1:
    for i in range(M):
        A[0] = int(A[0] / 2)

else:
    for i in range(M):
        A[0] = int(A[0] / 2)
        for j in range(M):
            if A[j] < A[j + 1]:
                tmp = A[j + 1]
                A[j + 1] = A[j]
                A[j] = tmp
            else:
                break

print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

for i in range(M):
    A[0] = int(A[0] / 2)
    if A[0] < A[1]:
        A.sort(reverse=True)

print(sum(A))
Problem p02688 (python)

Fixed submission:
n,k = map(int,input().split())
e=[]
for i in range(k):
  s= int(input())
  l=list(map(int,input().split()))
  e=e+l
r=set(e)
print(n-len(r))

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
s=[]
for i in range(k):
  s= int(input())
  l=list(map(int,input().split()))
  s=s+l
r=set(s)
print(n-len(r))
Problem p02712 (python)

Fixed submission:
t = int(input())
f=t//5
tt=t//3
ff=t//15
f=(f*(f+1)//2 )*5
tt=(tt*(tt+1)//2 )*3
ff =(ff*(ff+1)//2 )*15
print(t*(t+1)//2 - f -tt +ff)

Buggy submission (verdict: Runtime Error):
f=t//5
tt=t//3
ff=t//15
f=(f*(f+1)//2 )*5
tt=(tt*(tt+1)//2 )*3
ff =(ff*(ff+1)//2 )*15
print(t*(t+1)//2 - f -tt +ff)
Problem p02723 (python)

Fixed submission:
s = input()
if s[2]==s[3] and s[4]==s[5]:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n = input()
if s[2]==s[3] and s[4]==s[5]:
  print("Yes")
else:
  print("No")
Problem p03834 (python)

Fixed submission:
s =input()
print(s[:5]+" "+s[6:13]+" "+s[14:])

Buggy submission (verdict: Runtime Error):
s =input()
print(s[:5]+" "+s[6:13]+" "+s[14:]
Problem p02552 (python)

Fixed submission:
x = int(input())
if x == 0:
    print(1)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
    x = int(input())
    if x == 0:
        print(1)
    else:
        print(0)
Problem p02688 (python)

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

arr = []
for _ in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    arr.append(a)

oks = [False] * n
for xs in arr:
    for x in xs:
        oks[x - 1] = True

ans = 0
for x in oks:
    if x == False:
        ans += 1

print(ans)

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

arr = []
for _ in range(k):
.    d = int(input())
    a = list(map(int, input().split()))
    arr.append(a)

oks = [False] * n
for xs in arr:
    for x in xs:
        oks[x - 1] = True

ans = 0
for x in oks:
    if x == False:
        ans += 1

print(ans)
Problem p02557 (python)

Fixed submission:
from collections import*
from bisect import*
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ca=Counter(a)
cb=Counter(b)
for i in a:
  if ca[i]+cb[i]>n:
    print('No')
    exit()
print('Yes')
ba=[bisect(a,i+1) for i in range(n)]
bb=[bisect_left(b,i+1) for i in range(n)]
i=0
for x,y in zip(ba,bb):
  i=max(i,x-y)
ans=b[n-i:]+b[:n-i]
print(*ans)

Buggy submission (verdict: Runtime Error):
from collections import*
from bisect import*
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ca=Counter(a)
cb=Counter(b)
for i in a:
  if ca[i]+cb[i]>n:
    print('No')
    exiit()
print('Yes')
ba=[bisect(a,i+1) for i in range(n)]
bb=[bisect_left(b,i+1) for i in range(n)]
i=0
for x,y in zip(ba,bb):
  i=max(i,abs(x-y))
ans=b[i:]+b[:i]
print(*ans)
Problem p02659 (python)

Fixed submission:
a,b=input().split()
a=int(a)
b,c=map(int,b.split('.'))
print(a*(b*100+c)//100)

Buggy submission (verdict: Runtime Error):
a,b=map(float,input().split())
b*=100
a,b=map(int,(a,b))
print(a*b//100)a,b=map(float,input().split())
b*=100
a,b=map(int,(a,b))
print(a*b//100)
Problem p02781 (python)

Fixed submission:
s=input()
m=int(input())
n=len(s)
if n==1:
  print([0,int(s)][m==1])
  exit()
dp=[[[0]*2 for _ in range(m+1)] for _ in range(n)]
dp[0][0][1]=1
dp[0][1][1]=int(s[0])-1
dp[0][1][0]=1
for i in range(1,n):
  for j in range(m+1):
    if j:
      dp[i][j][1]+=9*dp[i-1][j-1][1]
      if s[i]!='0':
        dp[i][j][0]+=dp[i-1][j-1][0]
        dp[i][j][1]+=(int(s[i])-1)*dp[i-1][j-1][0]
    if s[i]=='0':dp[i][j][0]+=dp[i-1][j][0]
    dp[i][j][1]+=dp[i-1][j][1]
    if s[i]!='0':dp[i][j][1]+=dp[i-1][j][0]
print(sum(dp[-1][-1]))

Buggy submission (verdict: Runtime Error):
s=input()
m=int(input())
n=len(s)
if n==1:
  print([0,int(s)][k==1])
  exit()
dp=[[[0]*2 for _ in range(m+1)] for _ in range(n)]
dp[0][0][1]=1
dp[0][1][1]=int(s[0])-1
dp[0][1][0]=1
for i in range(1,n):
  for j in range(m+1):
    if j:
      dp[i][j][1]+=9*dp[i-1][j-1][1]
      if s[i]!='0':
        dp[i][j][0]+=dp[i-1][j-1][0]
        dp[i][j][1]+=(int(s[i])-1)*dp[i-1][j-1][0]
    if s[i]=='0':dp[i][j][0]+=dp[i-1][j][0]
    dp[i][j][1]+=dp[i-1][j][1]
    if s[i]!='0':dp[i][j][1]+=dp[i-1][j][0]
print(sum(dp[-1][-1]))

Buggy submission (verdict: Runtime Error):
s=input()
m=int(input())
n=len(s)
if n==1:
  print([0,int(s)][k==1])
  exit()
dp=[[[0]*2 for _ in range(m+1)] for _ in range(n)]
dp[0][0][1]=1
dp[0][1][1]=int(s[0])-1
dp[0][1][0]=1
for i in range(1,n):
  for j in range(m+1):
    if j:
      dp[i][j][1]+=9*dp[i-1][j-1][1]
      if s[i]!='0':
        dp[i][j][0]+=dp[i-1][j-1][0]
        dp[i][j][1]+=(int(s[i])-1)*dp[i-1][j-1][0]
    if s[i]=='0':dp[i][j][0]+=dp[i-1][j][0]
    dp[i][j][1]+=dp[i-1][j][1]+dp[i-1][j][0]
print(sum(dp[-1][-1]))
Problem p02880 (python)

Fixed submission:
n=int(input())
frag='No'
for i in range(9):
  if n/(i+1)%1==0 and n/(i+1)<=9:
    frag='Yes'
print(frag)

Buggy submission (verdict: Runtime Error):
n=int(input())
frag='No'
for i in range(9):
  if n/(i+1)%1==0:
    frag='Yes
print(frag)
Problem p02881 (python)

Fixed submission:
N=int(input())
move=10**12
for n in range(1,int(N**.5)+1):
    if N%n==0:
        move=min(move,N//n+n-2)
print(move)

Buggy submission (verdict: Runtime Error):
n=int(input())
mn=n
for i in range(n):
  if n%i==0:
    j=n//i
    mn=min(mn,i+j)
print(mn)
Problem p02990 (python)

Fixed submission:
n,k=map(int,input().split())
class mod_comb_k():
  def __init__(self, MAX_N = 10**6, mod = 10**9+7):
    self.fact = [1]
    self.fact_inv = [0] * (MAX_N + 4)
    for i in range(MAX_N + 3):self.fact.append(self.fact[-1] * (i + 1) % mod)
    self.fact_inv[-1] = pow(self.fact[-1], mod - 2, mod)
    for i in range(MAX_N + 2, -1, -1):
      self.fact_inv[i] = self.fact_inv[i + 1] * (i + 1) % mod
  def comb(self, n, k, mod = 10**9+7):
    return self.fact[n] * self.fact_inv[k] % mod * self.fact_inv[n - k] % mod
c=mod_comb_k(n)
mod=10**9+7
for i in range(k):
  div=c.comb(k-1,i)
  if n-k+1>=i+1:print(c.comb(n-k+1,i+1)*div%mod)
  else:print(0)

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

Fixed submission:
n,m=map(int,input().split())
mod=10**9+7
dp=[1]*(n+1)
for _ in range(m):
  dp[int(input())]=0
dp[1]*=dp[0]
for i in range(2,n+1):
  dp[i]*=dp[i-1]+dp[i-2]
print(dp[-1]%mod)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
b=[int(input()) for _ in range(m)]
a=[]
if 1 not in b:
  a.append=1
else:a.append=0
if 2 not in b:
  a.append=2
else:a.append=0
for i in range(2,n):
  if i+1 not in b:
    a.append=(a[-1]+a[-2])%(10**9+7)
  else:a.append=0
print(a[-1])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
b=[int(input()) for _ in range(m)]
a=[0]*n
if 1 not in b:
  a[0]=1
if 2 not in b:
  a[1]=2
for i in range(2,n):
  if i+1 not in b:
    a[i]=a[i-1]+a[i-2]
print(a)
print(a[-1]%(10**9+7))
Problem p03108 (python)

Fixed submission:
from itertools import combinations
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

n,m=map(int,input().split())
uf=UnionFind(n)
e=[]
ans=[]
for _ in range(m):
  a,b=map(int,input().split())
  e.append((a,b))
n_m=n*(n-1)//2
for i,j in e[::-1]:
  ans.append(n_m)
  if not uf.isSameGroup(i,j):
    k=uf.Count(i)*uf.Count(j)
    n_m-=k
    uf.Unite(i,j)
for i in ans[::-1]:
  print(i)

Buggy submission (verdict: Runtime Error):
class UnionFind():
  def __init__(self, n=10**6):
    self.n=n
    self.root=[-1]*(n+1)
    self.rnk=[0]*(n+1)
  def find(self, x):
    if(self.root[x]<0):
      return x
    else:
      self.root[x]=self.find(self.root[x])
      return self.root[x]
  def unite(self, x, y):
    x=self.find(x)
    y=self.find(y)
    if(x==y):return 
    self.root[x]+=self.root[y]
    self.root[y]=x
n,m=map(int,input().split())
uf=UnionFind(n)
a=[0]*m
b=[0]*m
for i in range(m):
  a[i],b[i]=map(int,input().split())
c=[1]*(n+1)
ans=[n*(n-1)//2]
for i in range(m-1,0,-1):
  x,y=a[i],b[i]
  ans+=[max(ans[-1]-c[uf.find(x)]*c[uf.find(y)],0)]
  c[uf.find(x)]+=c[uf.find(y)]
  uf.unite(x,y)
print(*ans[::-1],sep='\n')
Problem p03209 (python)

Fixed submission:
def hamb(n,x):
  if x<=n:return 0
  elif x==1 and n==0:return 1
  elif x<=s[n-1]+1:return hamb(n-1,x-1)
  elif x==s[n]:return p[n]
  else:return hamb(n-1,x-2-s[n-1])+p[n-1]+1
n,x=map(int,input().split())
s=[0]*(n+1)
p=[0]*(n+1)
s[0]=1
p[0]=1
for i in range(n):
  s[i+1]=3+2*s[i]
  p[i+1]=1+2*p[i]
print(hamb(n,x))

Buggy submission (verdict: Runtime Error):
def hamb(n,x):
  if x<=n:return 0
  elif x==1 and n==0:return 1
  elif x<=s[n-1]+1:return hamb(n-1,x-1)
  elif x==s[n-1]+2:return p[n-1]+1
  else:return hamb(n-1,x-2-s[n-1])+p[n-1]+1
n,x=map(int,input().split())
s=[0]*(n+1)
p=[0]*(n+1)
s[0]=1
p[0]=1
for i in range(n):
  s[i+1]=3+2*s[i]
  p[i+1]=1+2*p[i]
print(hamb(n,x))

Buggy submission (verdict: Runtime Error):
def hamb(n,x):
  if x<=n:return 0
  elif x==1 and n==0:return 1
  elif x<=s[n-1]+1:return hamb(n-1,x-1)
  elif x==s[n-1]+1:return p[n-1]+1
  else:return hamb(n-1,x-2-s[n-1])+p[n-1]+1
n,x=map(int,input().split())
s=[0]*(n+1)
p=[0]*(n+1)
s[0]=1
p[0]=1
for i in range(n):
  s[i+1]=3+2*s[i]
  p[i+1]=1+2*p[i]
print(hamb(n,x))
Problem p03252 (python)

Fixed submission:
from collections import Counter
s=Counter(list(input()))
t=Counter(list(input()))
s,t=list(s.values()),list(t.values())
print("Yes" if sorted(s)==sorted(t) else "No")

Buggy submission (verdict: Runtime Error):
t=Counter(list(input()))
Problem p03745 (python)

Fixed submission:
n=int(input())
if n==1:
  print(1)
  exit()
a=list(map(int,input().split()))
ans=1
if a[0]<a[1]:flag=1
elif a[0]>a[1]:flag=-1
else:flag=0
for i in range(1,n-1):
  if flag==1 and a[i]>a[i+1]:
    ans+=1
    flag=0
  elif flag==-1 and a[i]<a[i+1]:
    ans+=1
    flag=0
  else:
    if a[i]>a[i+1]:flag=-1
    elif a[i]<a[i+1]:flag=1
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
ans=1
if a[0]<a[1]:flag=1
elif a[0]>a[1]:flag=-1
else:flag=0
for i in range(1,n-1):
  if flag==1 and a[i]>a[i+1]:
    ans+=1
    flag=0
  elif flag==-1 and a[i]<a[i+1]:
    ans+=1
    flag=0
  else:
    if a[i]>a[i+1]:flag=-1
    elif a[i]<a[i+1]:flag=1
print(ans)
Problem p03774 (python)

Fixed submission:
n,m=map(int,input().split())
st=[]
for i in range(n):
  s_d=list(map(int,input().split()))
  st.append(s_d)
cp=[]
for i in range(m):
  c_d=list(map(int,input().split()))
  cp.append(c_d)
sc=[]
for i in range(n):
  scd=[]
  for j in range(m):
    scd_d=abs(st[i][0]-cp[j][0])+abs(st[i][1]-cp[j][1])
    scd.append(scd_d)
  sc.append(scd.index(min(scd))+1)
  
for i in range(n):
  print(sc[i])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
st=[]
for i in range(n):
  s_d=list(input())
  st.append(s_d)
cp=[]
for i in range(m):
  c_d=list(input())
  cp.append(c_d)
sc=[]
for i in range(n):
  scd=[]
  for j in range(m):
    scd_d=abs(st[i][0]-cp[j][0])+abs(st[i][1]-cp[j][1])
    scd.append(scd_d)
  sc.append(min(scd))
  
for i in range(n):
  print(sc[i])

Buggy submission (verdict: Runtime Error):
n,m map(int,input().split())
st=[]
for i in range(n):
  s_d=list(input())
  st.append(s_d)
cp=[]
for i in range(m):
  c_d=list(input())
  cp.append(c_d)
sc=[]
for i in range(n):
  scd=[]
  for j in range(m):
    scd_d=abs(st[i][0]-cp[j][0])+abs(st[i][1]-cp[j][1])
    scd.append(scd_d)
  sc.append(min(scd))
  
for i in range(n):
  print(sc[i])
Problem p03805 (python)

Fixed submission:
def ser(visited,now):
  visited.append(now)
  if len(visited)==n:
    return 1
  cnt=0
  for i in bri[now]:
    if i not in visited:
      cnt+= ser(visited[:],i)
  return cnt

n,m=map(int,input().split())
bri=[[] for _ in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  bri[a-1].append(b-1)
  bri[b-1].append(a-1)
print(ser([],0))

Buggy submission (verdict: Runtime Error):
def ser(visited,now):
  visited.append(now)
  if len(visited)==n:
    return 1
  cnt=0
  for i in bri[now]:
    if i not in visited:
      cnt+= ser(visited[:],i)
  return cnt

n,m=map(int,input().split())
bri=[[] for _ in range(m)]
for i in range(m):
  a,b=map(int,input().split())
  bri[a-1].append(b-1)
  bri[b-1].append(a-1)
print(ser([],0))
Problem p03835 (python)

Fixed submission:
k,s=map(int,input().split())
count=0
for x in range(k+1):
  for y in range(k+1):
    if x+y>=s-k and x+y<=s:
      count +=1
print(count)

Buggy submission (verdict: Runtime Error):
k,s=map(int,input())
count=0
for x in range(k+1):
  for y in range(k+1):
    if x+y>s-k:
      count +=1
print(count)
Problem p02831 (python)

Fixed submission:
def euclidean(a,b):
    while True:
      r=a%b
      if r==0:
         return b
      a,b=b,r

a,b=map(int,input().split())
print(a*b//euclidean(a,b))

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
print(a*b//euclidean(a,b))

def euclidean(a,b):
    r=a%b
    if r==0:
        return b
    return euclidean(b,r)

Buggy submission (verdict: Runtime Error):
import math
a,b=map(int,input().split())
print(a*b//math.gcd(a,b))
Problem p03242 (python)

Fixed submission:
n = input()
print(n.translate(str.maketrans('19','91')))

Buggy submission (verdict: Runtime Error):
n = input()
for i in range(len(n)):
    if n[i] == '1':
        n[i]='9'
    else:
        n[i]='1'
        print(n)