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

Fixed submission:
import sys

sys.setrecursionlimit(1000000)


def dfs(g: {}, v: int, seen: [], current_color: int):
    seen[v] = current_color
    for (next_v, next_w) in g[v]:
        # next_v が探索済だったらスルー
        if seen[next_v] != -1:
            if current_color == seen[next_v] and next_w % 2 == 1:
                return False
            elif current_color != seen[next_v] and next_w % 2 == 0:
                return False
            continue
        next_color = current_color if next_w % 2 == 0 else 1 - current_color
        # 再帰的に探索
        if not dfs(g, next_v, seen, next_color):
            return False
    return True


def main():
    n = int(input())

    g = {}
    for i in range(n-1):
        u, v, w = map(int, input().split())
        dic_a = g.setdefault(u-1, [])
        dic_a.append((v-1, w))
        dic_b = g.setdefault(v-1, [])
        dic_b.append((u-1, w))
    # -1:not clear, 0:white, 1:black
    seen = [-1] * n

    is_bipartite = True

    for i in range(n):
        if seen[i] != -1:
            continue
        if not dfs(g, i, seen, 0):
            is_bipartite = False
            break

    if is_bipartite:
        for i in range(n):
            print(seen[i])
    else:
        print("is not bipartite")

main()

Buggy submission (verdict: Runtime Error):
def dfs(g: {}, v: int, seen: [], current_color: int):
    seen[v] = current_color
    for (next_v, next_w) in g[v]:
        # next_v が探索済だったらスルー
        if seen[next_v] != -1:
            if current_color == seen[next_v] and next_w % 2 == 1:
                return False
            elif current_color != seen[next_v] and next_w % 2 == 0:
                return False
            continue
        next_color = current_color if next_w % 2 == 0 else 1 - current_color
        # 再帰的に探索
        return dfs(g, next_v, seen, next_color)
    return True


def main():
    n = int(input())

    g = {}
    for i in range(n-1):
        u, v, w = map(int, input().split())
        dic_a = g.setdefault(u-1, [])
        dic_a.append((v-1, w))
        dic_b = g.setdefault(v-1, [])
        dic_b.append((u-1, w))
    # -1:not clear, 0:white, 1:black
    seen = [-1] * n

    is_bipartite = True
    for i in range(n):
        if seen[i] != -1:
            continue
        if not dfs(g, i, seen, 0):
            is_bipartite = False
            break

    if is_bipartite:
        for i in range(n):
            print(seen[i])
    else:
        print("is not bipartite")

main()
Problem p02675 (python)

Fixed submission:
x  = input()


if x[-1] == "3":
    print("bon")
elif x[-1] == "0" or x[-1] =="1" or x[-1] == "6" or x[-1] == "8":
    print("pon")
else:
    print("hon")

Buggy submission (verdict: Runtime Error):
x  = input()


if x[-1] == "3":
    print("bon")
elif x[-1] = "0" or x[-1] = "1" or x[-1] = "6" or x[-1] = "8":
    print("pon")
else:
    print("hon")
Problem p02921 (python)

Fixed submission:
i = input()
j = input()
cnt = 0
for k in range(3):
    if i[k]==j[k]:
       cnt+=1

print(cnt)

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

can_move = 0
move = 0

for i in range(N):
    if i == N-1:
        break
    elif H[i] >= H[i+1]:
        move += 1
        if can_move <= move:
            can_move = move
    else:
        move = 0

print(can_move)
Problem p02553 (python)

Fixed submission:
a,b,c,d=map(int,input().split( ))
print(max(a*d,b*c,a*c,b*d))

Buggy submission (verdict: Runtime Error):
a,b,c,d=input().split( )
line[n]
x=int(b)
y=int(d)
print(x*y)

Buggy submission (verdict: Runtime Error):
n=input()
line[n]
x=int(line[1])
y=int(line[3])
print(x*y)
Problem p02639 (python)

Fixed submission:
a,b,c,d,e = (int(i) for i in input().split())
if a == 0:
  print(1)
if b == 0:
  print(2)
if c == 0:
  print(3)
if d == 0:
  print(4)
if e == 0:
  print(5)

Buggy submission (verdict: Runtime Error):
a,b,c,d,e = (int(x) for i in input().split())
if a == 0:
  print(1)
if b == 0:
  print(2)
if c == 0:
  print(3)
if d == 0:
  print(4)
if e == 0:
  print(5)
Problem p02663 (python)

Fixed submission:
h1,m1,h2,m2,k=map(int,input().split())
s=60*(h2-h1)+(m2-m1)-k
print(s)

Buggy submission (verdict: Runtime Error):
h1=input('>>')
m1=input('>>')
h2=input('>>')
m2=input('>>')
k=input('>>')
print('60*(h2-h1)+(m2-m1)-k')
Problem p02576 (python)

Fixed submission:
n,x,t = map(int,input().split())
print(t*((n-1)//x+1))

Buggy submission (verdict: Runtime Error):
n,x,t = map(int,input().split())
print(t*((n-1)//x+1)
Problem p02612 (python)

Fixed submission:
n=int(input())
print(999-((n-1)%1000))

Buggy submission (verdict: Runtime Error):
n=input()
print(999-((n-1)%1000))
Problem p02621 (python)

Fixed submission:
a=int(input())
print(a+a**2+a**3)

Buggy submission (verdict: Runtime Error):
a=input()
print(a+a**2+a**3)
Problem p02639 (python)

Fixed submission:
a=input().split()
x=0
for n in a:
  x+=1
  if n=="0":
    aa=x
print(aa)

Buggy submission (verdict: Runtime Error):
a=input().sprit()
x=0
for n in a:
  x+=1
  if n=="0":
    aa=x
print(aa)

Buggy submission (verdict: Runtime Error):
a=input().split()
x=0
for n in a:
  x+=1
  if n=0:
    aa=x
print(aa)
Problem p02640 (python)

Fixed submission:
x,y=input().split()
x=int(x)
y=int(y)
if y%2==1 or x*2>y or x*4<y:
  a="No"
else:
  a="Yes"
print(a)

Buggy submission (verdict: Runtime Error):
x,y=input().split()
if y%2==1 or x*2>y or x*4<y:
  a="No"
else:
  a="Yes"
print(a)
Problem p02641 (python)

Fixed submission:
a,b=input().split()
pp=input().split()
a=int(a)
b=int(b)
p=[]
for pa in pp:
    p.append(int(pa))
x=0
y=-1
while True:
    if a+x not in p:
        aa=a+x
        break
    elif a+y not in p:
        aa=a+y
        break
    x+=1
    y+=-1
print(aa)

Buggy submission (verdict: Runtime Error):
a,b=input().split()
pp=input().split()
a=int(a)
b=int(b)
p=[]
for pa in pp:
    p.append(int(pa))
x=0
y=-1
while:
    if a+x not in p:
        aa=a+x
        break
    elif a+y not in p:
        aa=a+y
        break
    x+=1
    y+=-1
print(aa)
Problem p02657 (python)

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

Buggy submission (verdict: Runtime Error):
a,b=input().split()
print(a*b)
Problem p02765 (python)

Fixed submission:
def strr():
 a=raw_input()
 return a
def sstrr():
 a=raw_input().split()
 return a
def intt():
 a=int(raw_input())
 return a
def iintt():
 a=[int(s) for s in raw_input().split()]
 return a
def nestt(t):
 a=[raw_input().split() for s in range(t)] 
 return a

nr=iintt()
n=nr[0]
r=nr[1]
if n>=10:
 a=r
else:
 a=r+100*(10-n)
print a

Buggy submission (verdict: Runtime Error):
def strr():
 a=raw_input()
 return a
def sstrr():
 a=raw_input().split()
 return a
def intt():
 a=int(raw_input())
 return a
def iintt():
 a=[int(s) for s in raw_input().split()]
 return a
def nestt(t):
 a=[raw_input().split() for s in range(t)] 
 return a

nr=iintt()
n=nr[0]
r=nr[1]
a
if n>=10:
 a=r
else:
 a=r+100*(10-n)
print a
Problem p02811 (python)

Fixed submission:
s=raw_input()
s=s.split()
s[0]=int(s[0])
s[1]=int(s[1])
if s[1]<=s[0]*500:
 a="Yes"
else:
 a="No"
print(a)

Buggy submission (verdict: Runtime Error):
s=raw_input()
s=s.split()
if x<=k*500:
 a="Yes"
else:
 a="No"
print(a)

Buggy submission (verdict: Runtime Error):
s=raw_input()
s=s.split()
if x<=k*500
 a="Yes"
else;
 a="No"
print(a)

Buggy submission (verdict: Runtime Error):
s=raw_input()
s=s.split()
if x<=k*500;
 a="Yes"
else;
 a="No"
print(a)
Problem p02830 (python)

Fixed submission:
input()
st=raw_input().split()
a=""
for s,t in zip(st[0],st[1]):
 a+=(s+t)
print(a)

Buggy submission (verdict: Runtime Error):
input()
st=input().split()
a=""
for s,t in zip(st[0],st[1]):
 a+=(s+t)
print(a)
Problem p02606 (python)

Fixed submission:
l,r,d = map(int, input().split())
ans = r//d - (l-1)//d
print(ans)

Buggy submission (verdict: Runtime Error):
from heapq import heappop, heappush

t = int(input())
for i in range(t):
  n = int(input())
  klr = [list(map(int, input().split())) for i in range(n)]
  plus = []
  p_que = []
  minus = []
  m_que = []
  ans = 0
  for key, (k,l,r) in enumerate(klr):
    diff = l-r
    if diff >= 0:
      plus.append([k, diff, key])
      heappush(p_que,(diff, k, key))
      ans += r
    else:
      minus.append([k, -diff, key])
      heappush(m_que,(-diff, k, key))
      ans += l
  plus.sort(reverse=True)
  used = [0] * n
  now = len(plus)
  for k,diff,key in plus:
    while now > k:
      data = heappop(p_que)
      idx = data[2]
      if used[idx]:
        continue
      used[idx] = 1
      now -= 1
    if used[key]:
      continue
    used[key] = 1
    ans += diff
    now -= 1
  now = len(plus) + 1      
  minus.sort()
  for k,diff,key in minus:
    while now <= k:
      data = heappop(m_que)
      idx = data[2]
      if used[idx]:
        continue
      used[idx] = 1
      now += 1
    if used[key]:
      continue
    used[key] = 1
    ans += diff
    now += 1
  print(ans)
Problem p02632 (python)

Fixed submission:
n = 2 * (10**6) + 10
mod = 10 ** 9 + 7
fact = [1]*(n+1)
rfact = [1]*(n+1)
r = 1
for i in range(1, n+1):
  fact[i] = r = r * i % mod
rfact[n] = r = pow(fact[n], mod-2, mod)
for i in range(n, 0, -1):
  rfact[i-1] = r = r * i % mod

# nPk (mod MOD) を求める
def perm(n, k):
  return fact[n] * rfact[n-k] % mod

# nCk (mod MOD) を求める
def comb(n, k):
  return fact[n] * rfact[k] * rfact[n-k] % mod

k = int(input())
s = input()

len_s = len(s)
ans = 0
for i in range(len_s,k+len_s+1):
    ans += (comb(i-1,len_s-1) * pow(25,i-len_s,mod) * pow(26,k+len_s-i,mod)) % mod
    ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
n = 10**6
mod = 10 ** 9 + 7
fact = [1]*(n+1)
rfact = [1]*(n+1)
r = 1
for i in range(1, n+1):
  fact[i] = r = r * i % mod
rfact[n] = r = pow(fact[n], mod-2, mod)
for i in range(n, 0, -1):
  rfact[i-1] = r = r * i % mod

# nPk (mod MOD) を求める
def perm(n, k):
  return fact[n] * rfact[n-k] % mod

# nCk (mod MOD) を求める
def comb(n, k):
  return fact[n] * rfact[k] * rfact[n-k] % mod

k = int(input())
s = input()

len_s = len(s)
ans = 0
for i in range(len_s,k+len_s+1):
    ans += (comb(i-1,len_s-1) * pow(25,i-len_s,mod) * pow(26,k+len_s-i,mod)) % mod
    ans %= mod
print(ans)
Problem p02713 (python)

Fixed submission:
import math

def GCD(a,b,c):
    return math.gcd(math.gcd(a,b),c)

k = int(input())
ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            ans += GCD(i,j,k)
print(ans)

Buggy submission (verdict: Runtime Error):
import fractions

def GCD(a,b,c):
    return fractions.gcd(math.gcd(a,b),c)

k = int(input())
ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            ans += GCD(i,j,k)
print(ans)
Problem p02761 (python)

Fixed submission:
n,m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]
keta = ["-1"] * n
if n == 1:
  ans = -1
  for s,c in sc:
    if ans == -1 or ans == c:
      ans = c
    else:
      print(-1)
      exit()
  if ans == -1:
    print(0)
  else:
    print(ans)
else:
  for s,c in sc:
    s-=1
    if keta[s] == "-1" or keta[s] == str(c):
      keta[s] = str(c)
    else:
      print(-1)
      exit()
  ans = ""
  for k,i in enumerate(keta):
    if i == "-1":
      if k == 0:
        ans += "1"
      else:
        ans += "0"
    else:
      ans += i   
  if ans[0] == "0":
    print(-1)
    exit()
  else:
    print(ans)

Buggy submission (verdict: Runtime Error):
n,m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]
keta = [-1] * n
if n == 1:
  for s,c in sc:
    ans = -1
    if ans == -1:
      ans = c
    else:
      print(-1)
      exit()
  print(ans)
else:
  for s,c in sc:
    s-=1
    if keta[s] == -1 or keta[s] == str(c):
      keta[s] = str(c)
    else:
      print(-1)
      exit()
  ans = ""
  for k,i in enumerate(keta):
    if i == -1:
      if k == 0:
        ans += "1"
      else:
        ans += "0"
    else:
      ans += i   
  if ans[0] == "0":
    print(-1)
    exit()
  else:
    print(ans)
Problem p02783 (python)

Fixed submission:
import math

a,b = map(int, input().split())
print(math.ceil(a/b))

Buggy submission (verdict: Runtime Error):
from operator import itemgetter
import bisect
import math

N,d,a = map(int, input().split())
xh = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0))
x = []
for X,h in xh:
  x.append(X)
data0 = [0]*(N+1)
data1 = [0]*(N+1)

def _add(data, k, x):
    while k <= N:
        data[k] += x
        k += k & -k
def add(l, r, x):
    _add(data0, l, -x*(l-1))
    _add(data0, r, x*(r-1))
    _add(data1, l, x)
    _add(data1, r, -x)

def _get(data, k):
    s = 0
    while k:
        s += data[k]
        k -= k & -k
    return s
def query(l, r):
    return _get(data1, r-1) * (r-1) + _get(data0, r-1) - _get(data1, l-1) * (l-1) - _get(data0, l-1)

ans = 0

for L,(X,H) in enumerate(xh):
  L += 1
  R = bisect.bisect_right(x,X+2*d)
  res = math.ceil((H - query(L,L+1) * a) / a) #ansを変える
  ans += res
  add(L,R+1,res)
print(ans)
Problem p02788 (python)

Fixed submission:
from operator import itemgetter
import bisect
import math

N,d,a = map(int, input().split())
xh = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0))
x = []
for X,h in xh:
  x.append(X)
ans = 0
attack_start = [i for i in range(N)]
now = 0
cumsum = [0] * (N+1)
for L,(X,H) in enumerate(xh):
  R = bisect.bisect_right(x,X+2*d)
  for i in range(now,R):
    attack_start[i] = L
  now = R
  damage = (cumsum[L] - cumsum[attack_start[L]]) * a
  attack_time = max(0,math.ceil((H - damage) / a))
  ans += attack_time
  cumsum[L+1] = ans
print(ans)

Buggy submission (verdict: Runtime Error):
import math

N,d,a = map(int, input().split())
xh = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0))
x = []
for X,h in xh:
  x.append(X)
data0 = [0]*(N+1)
data1 = [0]*(N+1)

def _add(data, k, x):
    while k <= N:
        data[k] += x
        k += k & -k
def add(l, r, x):
    _add(data0, l, -x*(l-1))
    _add(data0, r, x*(r-1))
    _add(data1, l, x)
    _add(data1, r, -x)

def _get(data, k):
    s = 0
    while k:
        s += data[k]
        k -= k & -k
    return s
def query(l, r):
    return _get(data1, r-1) * (r-1) + _get(data0, r-1) - _get(data1, l-1) * (l-1) - _get(data0, l-1)

ans = 0

for L,(X,H) in enumerate(xh):
  L += 1
  R = bisect.bisect_right(x,X+2*d)
  res = math.ceil((H - query(L,L+1) * a) / a) #ansを変える
  ans += res
  add(L,R+1,res)
print(ans)
Problem p02789 (python)

Fixed submission:
n,m = map(int, input().split())
if n == m:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import copy


mod = 10 ** 9 + 7
primes = []
for i in range(2,1002):
  for prime in primes:
    if not i % prime:
      break
  else:
    primes.append(i)

def factorize(n):
  now = n
  fct = defaultdict(int)
  for prime in primes:
    cnt = 0
    if prime ** 2 > n:
      break
    while not now % prime:
      now //= prime
      cnt += 1
    if cnt:
      fct[prime] = cnt
  if now > 1:
    fct[now] = 1
  return fct


n = int(input())
a = list(map(int, input().split()))
fct_a = list()
for i in a:
  fct_a.append(factorize(i))
lcm = defaultdict(int)
for i in fct_a:
  for k,v in i.items():
    lcm[k] = max(lcm[k], v)
ans = 0
for i in fct_a:
  b = 1
  for k,v in lcm.items():
    b *= k**(v-i[k])
    b %= mod
  ans += b
ans %= mod
print(ans)
Problem p02824 (python)

Fixed submission:
n,m,v,p = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)

#　せっかくなのであとでmarginを前計算してm*v以上をbisect
def isOK(x):
  border = a[x-1]
  if border + m < a[p-1]:
    return False
  elif x <= p:
    return True
  else:
    margin = m * n
    for i in range(p-1,x-1):
      margin -= a[i] - border
    if margin >= m*v:
      return True
    else:
      return False

def binary_search():
    ok = p-1
    ng = n+1
    while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        if isOK(mid):
            ok = mid
        else:
            ng = mid
    return ok

ans = binary_search()  
print(ans)

Buggy submission (verdict: Runtime Error):
a = sorted(list(map(int, input().split())), reverse=True)

#　せっかくなのであとでpossibleを前計算してm*v以上をbisectでもやる
def isOK(x):
  x -= 1
  if a[x] + m < a[p-1]:
    return False
  elif x+1 <= p:
    return True
  else:
    pos = m * n
    for i in range(p-1,x):
      pos -= a[i] - a[x]
    if pos >= m * v:
      return True
    else:
      return False

def binary_search():
    ok = p-1
    ng = n
    while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        if isOK(mid):
            ok = mid
        else:
            ng = mid
    return ok

ans = binary_search()  
print(ans)
Problem p02889 (python)

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

def dijkstra(s,n,cost,l):
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        for i in range(n):
            if (not used[i]) and (v == -1):
                v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
            break
        used[v] = True
        dist_v = d[v]
        for j, weight in enumerate(cost[v]):
            alt = dist_v + weight
            r = (dist_v - 1) // l
            if r != ((alt - 1) // l) and dist_v != 0:
                alt = (r + 1) * l + weight         
            d[j] = min(d[j],alt)
    return d

n,m,l = map(int, input().split())
path = [[float("inf") for i in range(n)] for i in range(n)]
ans_list = []
for i in range(m):
  a,b,cost = map(int, input().split())
  a -= 1
  b -= 1
  if cost <= l:
    path[a][b] = cost
    path[b][a] = cost
for s in range(n):
  ans_list.append(dijkstra(s,n,path,l))
q = int(input())

for i in range(q):
  s,t = map(int, input().split())
  ans = ans_list[s-1][t-1]
  if ans == float("inf"):
    ans = -1
  else:
    ans = (ans - 1) // l
  print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def dijkstra(s,n,cost,l):
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        for i in range(n):
            if (not used[i]) and (v == -1):
                v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
            break
        used[v] = True
        dist_v = d[v]
        for j in range(n):
            weight = cost[v][j]
            alt = dist_v + weight
            r = (dist_v - 1) // l
            if (r != ((alt - 1) // l) and dist_v != 0:
                alt = (r + 1) * l + weight         
            d[j] = min(d[j],alt)
    return d
 
n,m,l = map(int, input().split())
abc = [list(map(int, input().split())) for i in range(m)]
q = int(input())
st = [list(map(int, input().split())) for i in range(q)]
path = [[float("inf") for i in range(n)] for i in range(n)]
ans_list = []
for i in abc:
  a,b,cost = i[0]-1, i[1]-1, i[2]
  if cost <= l:
    path[a][b] = cost
    path[b][a] = cost
for s in range(n):
  ans_list.append(dijkstra(s,n,path,l))
for i in st:
  s, t = i[0] - 1, i[1] - 1
  ans = ans_list[s][t]
  if ans == float("inf"):
    ans = -1
  else:
    ans = (ans - 1) // l
  print(ans)
Problem p02909 (python)

Fixed submission:
n = input()
if n == "Sunny":
  print("Cloudy")
elif n == "Cloudy":
  print("Rainy")
else:
  print("Sunny")

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
dp = [0]*n
j = 1

for i in range(n):
    while s[i:j] in s[j:s]:
        j += 1
    dp[i] = j-i-1
print(max(dp))
Problem p02913 (python)

Fixed submission:
n = int(input())
s = input()
dp = [0]*n
j = 1

for i in range(n):
    while s[i:j] in s[j:n]:
        j += 1
    dp[i] = j-i-1
print(max(dp))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
dp = [0]*n
j = 1

for i in range(n):
    while s[i:j] in s[j:s]:
        j += 1
    dp[i] = j-i-1
print(max(dp))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
dp = [0]*n
j = 1

for i in range(n):
    while S[i:j] in S[j:s]:
        j += 1
    dp[i] = j-i-1
print(max(dp))
Problem p02921 (python)

Fixed submission:
s = input()
t = input()
ans = 0
for i,j in zip(s,t):
  if i == j:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
ans = 0
for i,j in zip(s,t):
  if s == t:
    ans += 1:
print(ans)
Problem p02928 (python)

Fixed submission:
import bisect

class BinaryIndexedTree:
    # http://hos.ac/slides/20140319_bit.pdf
    def __init__(self, size):
        self._bit = [0 for _ in range(size)]
        self._size = size
 
    def add(self, i, w):
        x = i + 1
        while x <= self._size:
            self._bit[x - 1] += w
            x += x & -x
 
    def sum(self, i):
        ret = 0
        x = i + 1
        while x > 0:
            ret += self._bit[x - 1]
            x -= x & -x
        return ret
 
    def __len__(self):
        return self._size
 
 
def count_inversions(li, max=None):
    if not max:
        max = __builtins__.max(li)
    bit = BinaryIndexedTree(size=max + 1)
    ret = 0
    for i in range(len(li)):
        ret += i - bit.sum(li[i])
        bit.add(li[i], 1)
    return ret

  
n,k = map(int, input().split())
a = list(map(int, input().split()))
sorted_a = sorted(a)
d = 0
tree = [0] * (n+1) 
mod = 10 ** 9 + 7
ans = (count_inversions(a, max=max(a)) * k) % mod

for i in a:
  d += bisect.bisect_left(sorted_a, i)

ans += (d*((k*(k-1))//2)) % mod 
print(ans%mod)

Buggy submission (verdict: Runtime Error):
import bisect

def BIT_update(tree,x):
  while x <= n:
    tree[x] += 1
    x += x&(-x)
def BIT_sum(tree,x):
  s = 0
  while x:
    s += tree[x]
    x -= x&(-x)
  return s

  
n,k = map(int, input().split())
a = list(map(int, input().split()))
sorted_a = sorted(a)
d = 0
tree = [0] * (n+1)
 

ans = n*(n-1)//2

for x in a:
  ans -= BIT_sum(tree,x)
  BIT_update(tree,x)
  
mod = 10 ** 9 + 7
ans = (ans * k) % mod

for i in a:
  d += bisect.bisect_left(sorted_a, i)

ans += (d*((k*(k-1))//2)) % mod 
print(ans%mod)
Problem p02992 (python)

Fixed submission:
import math

from itertools import accumulate

def cumsum(a):
    return list(accumulate(a))

n,k = map(int, input().split())
if n == 1:
    print(1)
    exit()
mod = 10 ** 9 + 7
now = n
big = []
for i in range(2,int(math.sqrt(n)+2)):
    d = n // i
    big.append(now - d)
    now = d
big.reverse()
l = [1] * d + big
l2 = [1] * d + big
for i in range(k-1):
    a = cumsum(l)
    a.reverse()
    count = 0
    for i,j in zip(a,l2):
        l[count] = (i * j) % mod
        count += 1
l = cumsum(l)
ans = l[-1] % mod
print(ans)

Buggy submission (verdict: Runtime Error):
if n == 1:
    print(1)
    exit()
mod = 10 ** 9 + 7
now = n
big = []
for i in range(2,int(math.sqrt(n)+2)):
    d = n // i
    big.append(now - d)
    now = d
big.reverse()
l = [1] * d + big
l2 = [1] * d + big
for i in range(k-1):
    a = cumsum(l)
    a.reverse()
    count = 0
    for i,j in zip(a,l2):
        l[count] = (i * j) % mod
        count += 1
l = cumsum(l)
ans = l[-1] % mod
print(ans)
Problem p03006 (python)

Fixed submission:
from operator import itemgetter
from collections import defaultdict
n = int(input())
if n == 1:
  print(1)
  exit()
xy = sorted([list(map(int, input().split())) for i in range(n)], key = itemgetter(0,1))
a = defaultdict(int)
for key,(x1,y1) in enumerate(xy):
  for x2,y2 in xy[key+1:]:
    p,q = x2-x1, y2-y1
    if p != 0 or q != 0:
      a[(p,q)] += 1
ans = n - max(a.values())
print(ans)

Buggy submission (verdict: Runtime Error):
from operator import itemgetter
from collections import defaultdict
n = int(input())
xy = sorted([list(map(int, input().split())) for i in range(n)], key = itemgetter(0,1))
a = defaultdict(int)
for key,(x1,y1) in enumerate(xy):
  for x2,y2 in xy[key+1:]:
    p,q = x2-x1, y2-y1
    if p != 0 or q != 0:
      a[(p,q)] += 1
ans = n - max(a.values())
print(ans)
Problem p03029 (python)

Fixed submission:
a,p = map(int, input().split())
print((a*3+p)//2)

Buggy submission (verdict: Runtime Error):
a,p ＝ map(int, input().split())
print((a * 3 + p) // 2)

Buggy submission (verdict: Runtime Error):
a,p ＝map(int, input().split())
print((a*3 + p) // 2)
Problem p03035 (python)

Fixed submission:
a,b = map(int, input().split())
if a >= 13:
  print(b)
elif 6 <= a <= 12:
  print(b//2)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
a = [0] * (10 ** 9)