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

Fixed submission:
n = int(input())
a = []
for i in range(n):
  x,y,z = map(int,input().split())
  a.append([x+y,x,y,z])
dp = [-1] * 20001
a.sort()
dp[0] = 0
for i in range(n):
  for j in range(20000,-1,-1):
    if dp[j] != -1 and a[i][2]>= j:
      dp[j+a[i][1]] = max(dp[j+a[i][1]],dp[j]+a[i][3])
print(max(dp))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = []
for i in range(n):
  x,y,z = map(int,input().split())
  a.append([x+y,x,y,z])
dp = [-1] * 2001
a.sort()
dp[0] = 0
for i in range(n):
  for j in range(2000,-1,-1):
    if dp[j] != -1 and a[i][2]>= j:
      dp[j+a[i][1]] = max(dp[j+a[i][1]],dp[j]+a[i][3])
print(max(dp))
Problem p03196 (python)

Fixed submission:
n,p = map(int,input().split())
import math
def factorization(n):
    def factor_sub(n, m):
        c = 0
        while n % m == 0:
            c += 1
            n //= m
        return c, n
    #
    buff = []
    c, m = factor_sub(n, 2)
    if c > 0: buff.append((2, c))
    c, m = factor_sub(m, 3)
    if c > 0: buff.append((3, c))
    x = 5
    while m >= x * x:
        c, m = factor_sub(m, x)
        if c > 0: buff.append((x, c))
        if x % 6 == 5:
            x += 2
        else:
            x += 4
    if m > 1: buff.append((m, 1))
    return buff
so = factorization(p)
ans = 1
for i,j in so:
    ans *= i**(j//n)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]
for i in a:
  if i == 1:
    print("first")
    exit()
xor = a[0]
for i in range(1,n):
  xor ^= a[i]
if xor %2 == 0:
  assert 100<xor and xor < 1000 
  print("second")
else:
  print("first")

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]
for i in a:
  if i == 1:
    print("first")
    exit()
xor = a[0]
for i in range(1,n):
  xor ^= a[i]
if xor %2 == 0:
  assert n == 10**5 and xor == 0 and a[0] > 90000
  print("second")
else:
  print("first")

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]
for i in a:
  if i == 1:
    print("first")
    exit()
xor = a[0]
for i in range(1,n):
  xor ^= a[i]
if xor %2 == 0:
  assert n == 10**5 and xor == 0 and a[0] > 50000
  print("second")
else:
  print("first")
Problem p03241 (python)

Fixed submission:
import math
n,m = map(int,input().split())
MAX = m//n
ans = 1
def factorization(n):
    def factor_sub(n, m):
        c = 0
        while n % m == 0:
            c += 1
            n /= m
        return c, n
    #
    buff = []
    c, m = factor_sub(n, 2)
    if c > 0: buff.append((2, c))
    c, m = factor_sub(m, 3)
    if c > 0: buff.append((3, c))
    x = 5
    while m >= x * x:
        c, m = factor_sub(m, x)
        if c > 0: buff.append((x, c))
        if x % 6 == 5:
            x += 2
        else:
            x += 4
    if m > 1: buff.append((m, 1))
    return buff
def divisor_sub(p, q):
    a = []
    for i in range(0, q + 1):
        a.append(p ** i)
    return a

def divisor(n):
    if n == 1:
      return([1])
    xs = factorization(n)
    ys = divisor_sub(xs[0][0], xs[0][1])
    for p, q in xs[1:]:
        ys = [x * y for x in divisor_sub(p, q) for y in ys]
    return sorted(ys)
a = divisor(m)
for i in a:
  if i <= MAX:
    ans = i
print(int(ans))

Buggy submission (verdict: Runtime Error):
import math
n,m = map(int,input().split())
MAX = m//n
ans = 1
def factorization(n):
    def factor_sub(n, m):
        c = 0
        while n % m == 0:
            c += 1
            n /= m
        return c, n
    #
    buff = []
    c, m = factor_sub(n, 2)
    if c > 0: buff.append((2, c))
    c, m = factor_sub(m, 3)
    if c > 0: buff.append((3, c))
    x = 5
    while m >= x * x:
        c, m = factor_sub(m, x)
        if c > 0: buff.append((x, c))
        if x % 6 == 5:
            x += 2
        else:
            x += 4
    if m > 1: buff.append((m, 1))
    return buff
def divisor_sub(p, q):
    a = []
    for i in range(0, q + 1):
        a.append(p ** i)
    return a

def divisor(n):
    xs = factorization(n)
    ys = divisor_sub(xs[0][0], xs[0][1])
    for p, q in xs[1:]:
        ys = [x * y for x in divisor_sub(p, q) for y in ys]
    return sorted(ys)
a = divisor(m)
for i in a:
  if i <= MAX:
    ans = i
print(ans)
Problem p03251 (python)

Fixed submission:
n,m,x,y = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = max(a)
b = min(b)
if (a<b and a+1>x and a+1<=y):
  print("No War")
else:
  print("War")

Buggy submission (verdict: Runtime Error):
n,m,x,y = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aMAX = max(a)
bMIN = min(b)
if (a<b and a+1>x and a+1<=y):
  print("No War")
else:
  print("War")
Problem p03256 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
n, m = map(int, input().split())
s = input()
links = [[] for _ in range(2*n)]
visit = [0] * n *2
for line in sys.stdin.readlines():
    a, b = map(int, line.split())
    a -= 1
    b -= 1
    if s[a] == s[b]:
      links[a].append(b+n)
      links[b].append(a+n)
    else:
      links[a+n].append(b)
      links[b+n].append(a)
def dfs(v):
  visit[v] = 1
  for i in links[v]:
    if visit[i] == 1:
      print("Yes")
      exit()
    elif visit[i] == 0:
      dfs(i)
  visit[v] = -1
  
for i in range(n):
  if visit[i] == 0:
    dfs(i)
print("No")

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)
def add_link(a, b):
    la = links[a]
    i, j = [(0, 1), (1, 0)][s[b] == 'B']
    if not la[i] and la[j]:
        able[a] = True
    la[i].add(b)
 
n, m = map(int, input().split())
s = input()
links = [[set(), set()] for _ in range(n)]
able = [False] * n
for line in sys.stdin.readlines():
    a, b = map(int, line.split())
    a -= 1
    b -= 1
    add_link(a, b)
    add_link(b, a)
 
def erase(v):
  if s[v] == "A":
    l = 0
  else:
    l = 1
  for q in links[v][0]:
    if not able[q]:
      continue
    links[q][l].remove(v)
    if links[q][l] == set():
      able[q] = False
      erase(q)
  for q in links[v][1]:
    if not able[q]:
      continue
    links[q][l].remove(v)
    if links[q][l] == set():
      able[q] = False
      erase(q)

for i in range(n):
  if not able[i]:
    erase(i)
if any(able):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
import sys
def add_link(a, b):
    la = links[a]
    i, j = [(0, 1), (1, 0)][s[b] == 'B']
    if not la[i] and la[j]:
        able[a] = True
    la[i].add(b)

n, m = map(int, input().split())
s = input()
links = [[set(), set()] for _ in range(n)]
able = [False] * n
for line in sys.stdin.readlines():
    a, b = map(int, line.split())
    a -= 1
    b -= 1
    add_link(a, b)
    add_link(b, a)
flag = 1
tmp = set()
for i in range(n):
  if able[i]:
    tmp.add(i)
while flag ==1:
  flag = 0
  for i in tmp:
    if not able[i]:
      continue
    for k in range(2):
      for j in links[i][k].copy():
        if not able[j]:
          links[i][k].remove(j)
    if (links[i][0] == set() or links[i][1] == set()):
      flag =1
      tmp.remove(i)
      able[i] = False
if any(able):
  print("Yes")
else:
  print("No")
Problem p03268 (python)

Fixed submission:
import sys
n,k = map(int, sys.stdin.readline().split())
ans = 0
a = n//k
ans += a*(a-1)*(a-2)+a*(a-1)*3+a
if k %2 == 0:
    a = n//k
    if n %k >= k/2:
        a+=1
    ans += a*(a-1)*(a-2)+a*(a-1)*3+a
print(ans)

Buggy submission (verdict: Runtime Error):
import collections
n = int(input())
a = list(map(int,input().split()))
mae = []
usi = []
for i in range(0,n,2):
  mae.append(a[i])
for i in range(1,n,2):
  usi.append(a[i])
mae = collections.Counter(mae)
usi = collections.Counter(usi)
mae = mae.most_common()
usi = usi.most_common()
if mae[0][0] != usi[0][0]:
  print(n-mae[0][1]-usi[0][1])
else:
  try:
    t = mae[0][1] + usi[1][1]
  except:
    t = 0
  try:
    s = mae[1][1] + usi[0][1]
  except:
    s = 0
  u = mae[0][1]
  print(n-max(t,s,u))
Problem p03269 (python)

Fixed submission:
k=int(input())
g = []
i = 0
while k >3:
  if k%2 == 1:
    g.append([1,20-i,(k-1)*2**i])
    k = k//2
    g.append([20-i-1,20-i,0])
    g.append([20-i-1,20-i,1*2**i])
    i+=1
  else:
    k = k//2
    g.append([20-i-1,20-i,0])
    g.append([20-i-1,20-i,1*2**i])
    i+=1
if k==3:
  g.append([1,20-i,(k-1)*2**i])
  k = k//2
  g.append([20-i-1,20-i,0])
  g.append([20-i-1,20-i,1*2**i])
  if 20-i-1 != 1:
    g.append([1,20-i-1,0])
elif k == 2:
  g.append([20-i-1,20-i,0])
  g.append([20-i-1,20-i,1*2**i])
  if 20-i-1 != 1:
    g.append([1,20-i-1,0])
print(20,len(g))
for x,y,z in g:
  print(x,y,z)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = []
for i in range(n):
  x1,y1=[int(i) for i in input().split()]
  x.append([x1,y1])
ki = (abs(x[0][0]) + abs(x[0][1])) %2
for i in range(n):
  if ki != (abs(x[i][0]) + abs(x[i][1]))%2:
    print(-1)
    exit()
if ki == 1:
  m = 19
  d = [1]*19
else:
  m = 20
  d = [1]*20
ans = []
for i in range(n):
  tmp = ""
  if x[i][0] > 0:
    tmp += "R"*x[i][0]
  else:
    tmp += "L"*abs(x[i][0])
  if x[i][1] > 0:
    tmp += "U"*x[i][1]
  else:
    tmp += "D"*abs(x[i][1])
  while len(tmp) < m:
    tmp += "RL"
  ans.append(tmp)
print(m)
print(*d)
for i in ans:
  print(i)
Problem p03276 (python)

Fixed submission:
import sys
n,k = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
ma = []
pu = []
for i in range(n):
    if a[i] < 0:
        ma.append(a[i])
    else:
        pu.append(a[i])
for i in range(len(ma)):
    ma[i] = -ma[i]
ma.sort()
ans = float("inf")
for i in range(len(ma)):
    kota = 0
    kota += ma[i]
    if k <= i+1:
        ans = min(kota,ans)
    else:
        kota += ma[i]
        if len(pu) >= k- i-1:
            kota += pu[k-i-2]
            ans = min(kota,ans)
for i in range(len(pu)):
    kota = 0
    kota += pu[i]
    if k <= i+1:
        ans = min(kota,ans)
    else:
        kota += pu[i]
        if len(ma) >= k- i-1:
            kota += ma[k-i-2]
            ans = min(kota,ans)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
n,k = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
ma = []
pu = []
for i in range(n):
    if a[i] < 0:
        ma.append(a[i])
    else:
        pu.append(a[i])
for i in range(len(ma)):
    ma[i] = -ma[i]
ma.sort()
ans = float("inf")
for i in range(len(ma)):
    kota = 0
    kota += ma[i]
    if k <= i+1:
        ans = min(kota,ans)
    else:
        kota += ma[i]
        if (len(pu) >= k- i-2 and len(pu) != 0):
            kota += pu[k-i-2]
            ans = min(kota,ans)
for i in range(len(pu)):
    kota = 0
    kota += pu[i]
    if k <= i+1:
        ans = min(kota,ans)
    else:
        kota += pu[i]
        if (len(ma) >= k- i-2 and len(ma) != 0):
            kota += ma[k-i-2]
            ans = min(kota,ans)
print(ans)
Problem p03289 (python)

Fixed submission:
s = input()
e = 0
if s[0] == "A":
  for i in range(2,len(s)-1):
    b = s[i]
    if b == "C":
      e = 1
      f = i
      break
  if e == 1:
    s = s[:f] + s[f+1:]
    s = s[1:]
    if s.islower():
      print("AC")
    else:
      print("WA")
  else:
    print("WA")
else:
  print("WA")

Buggy submission (verdict: Runtime Error):
s = input()
if s[0] == "A":
    x = s.find("C")
    if 2<=x and x != len(s)-1:
        s[0]="a"
        s[x]="c"
        if s.islower():
            print("AC")
            exit()
print("WA")
Problem p03319 (python)

Fixed submission:
N,K = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
c = a.index(1)
naga = len(a)-K
if naga <= 0:
  print(1)
else:
  d = c-0
  if d != 0:
    V = K-1
    ans += d // V
    if d % V != 0:
      ans += 1
  e = N-1-c
  if e != 0:
      V = K-1
      ans += e // V
      if e % V != 0:
        ans += 1
  ans1 = 0
  ans2 = 0
  if d <= K-1:
    ans1 += 1
    ex = e -(K-d-1)
    if ex >= 0:
      V = K-1
      ans1 += ex // V
      if ex % V != 0:
        ans1 += 1
  else:
    ans1 = 999999999999999999999999999999
  if e <= K-1:
    ans2 += 1
    dx = d -(K-e-1)
    if dx >= 0:
      V = K-1
      ans2 += dx // V
      if dx % V != 0:
        ans2 += 1
  else:
    ans2 = 999999999999999999999999999999
  ans3 = 0
  ans4 = 999999999999999999
  V = K-1
  for i in range(K):
    ans3 = 0
    dx = d- i
    ex = e - (K - i - 1)
    ans3 += 1
    if dx > 0:
      if ex > 0:
        ans3 += ex//V
        if ex % V != 0:
          ans3 += 1
        ans3 += dx//V
        if dx % V != 0:
          ans3 += 1
        ans4 = min(ans4,ans3)
  print(min(ans,ans1,ans2,ans4))

Buggy submission (verdict: Runtime Error):
N = int(input())
a =[1,2,3,4,5,6,7,8,9]
for i in range(1,10000):
  b = 10**i - 1
  for j in range(1,10):
    a.append(b + j * 10 ** i)
  
for i in range(N):
  print(a[i])
Problem p03353 (python)

Fixed submission:
s = input()
K = int(input())
A =[]
b = len(s)
for i in range(b+1):
      if i+1 < b+1:
        A.append(s[i:i+1])
      if i+2 < b+1:
        A.append(s[i:i+2])
      if i+3 < b+1:
        A.append(s[i:i+3])
      if i+4 < b+1:
        A.append(s[i:i+4])
      if i+5 < b+1:
        A.append(s[i:i+5])
B = set(A)
B = list(B)
B = sorted(B)
print(B[K-1])

Buggy submission (verdict: Runtime Error):
s = input()
K = int(input())
A =[]
for i in range(len(s)):
  for j in range(len(s)):
    if j > i:
      A.append(s[i:j])
for i in range(len(s)):
  A.append(s[i])
B = set(A)
B = list(B)
B = sorted(B)
print(B[K-1])
Problem p03354 (python)

Fixed submission:
n, m = map(int, input().split())
p = list(map(int, input().split()))
g = []
for i in range(m):
    g.append(list(map(int, input().split())))
l = [[] for i in range(n+1)]
for pi in g:  
    l[pi[0]].append(pi[1])
    l[pi[1]].append(pi[0])
x =  [0]*n
for i in range(n):
  x[p[i]-1] = i+1
ans = 0
#Union find
y = [-1] * n
for i in range(0,n):
  if y[i] == -1:
    y[i] = i
  c = l[i+1]
  while len(c) > 0:
    z = c.pop()
    y[z-1] = y[i]
    for j in range(len(l[z])):
      if y[l[z][j]-1] == -1:
        c.append(l[z][j])
    l[z] =[]
    
for i in range(n):
  c = x[i]
  if y[c-1] == y[i]:
    ans +=1
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
p = list(map(int, input().split()))
g = []
for i in range(m):
    g.append(list(map(int, input().split())))
l = [[] for i in range(n+1)]
for pi in g:  
    l[pi[0]].append(pi[1])
    l[pi[1]].append(pi[0])
x =  [0]*n
for i in range(n):
  x[p[i]-1] = i+1
ans = 0
def saiki(a):
  c = l[a]
  while len(c) > 0:
    z = c.pop()
    y[z-1] = i
    saiki(z)
#Union find
y = [0] * n
for i in range(0,n):
  if y[i] == 0:
    y[i] = i
  saiki(i)
for i in range(n):
  c = x[i]
  if y[c-1] == y[i]:
    ans +=1
print(ans)

Buggy submission (verdict: Runtime Error):
import copy
n, m = map(int, input().split())
p = list(map(int, input().split()))
g = []
for i in range(m):
    g.append(list(map(int, input().split())))
l = [[] for i in range(n+1)]
for pi in g:  #0-originedに注意
    l[pi[0]].append(pi[1])
    l[pi[1]].append(pi[0])
x =  [0]*n
for i in range(n):
  x[p[i]-1] = i+1
ans = 0
def dfs(x,y):
  f = c[x]
  while len(f) > 0:
    z = f.pop()
    if z  == y:
      return True
    if dfs(z,y) == True:
      return True
for i in range(n):
  if x[i] == i+1:
    ans +=1
  else:
    c = copy.deepcopy(l)
    if dfs(x[i],i+1) == True:
      ans += 1
print(ans)
Problem p03377 (python)

Fixed submission:
a,b,c = map(int, input().split())
if a+b>=c>=a:
  print("YES")
else:
 print("NO")

Buggy submission (verdict: Runtime Error):
a,b,c = map(int, input().split())
if a+b>=c>=a:
  print(YES)
else
 print(NO)
Problem p03393 (python)

Fixed submission:
s= input()
V = list(s)
X = [chr(ord('a') + i) for i in range(26)]

if len(s)<26:
  for i in range(26):
    count1 = s.count(X[i])
    if count1 >= 1:
      continue
    else:
      Nasi = X[i]
      break
  ans = s + Nasi
else:
  if s == "zyxwvutsrqponmlkjihgfedcba":
    ans= -1
  else:
    for i in range(25, 0, -1):
        if V[i] > V[i-1]:
          ans = V[0:i-1]
          if ans == []:
            ans = chr(ord(V[0]) + 1)
          else:
              B = min(V[i:26])
              while B <= V[i-1]:
                  B = chr(ord(B) + 1)
              while B in ans:
                  B = chr(ord(B) + 1)
              ans.append(B)
              ans = ''.join(ans)
              break
        else:
            continue
print(ans)

Buggy submission (verdict: Runtime Error):
s= input()
V = list(s)
X = [chr(ord('a') + i) for i in range(26)]

if len(s)<26:
  for i in range(26):
    count1 = s.count(X[i])
    if count1 >= 1:
      continue
    else:
      Nasi = X[i]
      break
  ans = s + Nasi
else:
  if s == "zyxwvutsrqponmlkjihgfedcba":
    ans= -1
  else:
    for i in range(25, 0, -1):
        if V[i] > V[i-1]:
          ans = V[0:i-1]
          ans.append(min(V[i+1:26]))
          ans = ''.join(ans)
          break
        else:
          continue
print(ans)

Buggy submission (verdict: Runtime Error):
s= input()
V = list(s)
X = [chr(ord('a') + i) for i in range(26)]

if len(s)<26:
  for i in range(26):
    count1 = s.count(X[i])
    if count1 >= 1:
      continue
    else:
      Nasi = X[i]
      break
  ans = s + Nasi
else:
  if s == "zyxwvutsrqponmlkjihgfedcba":
    ans= -1
  else:
    for i in range(25, 0, -1):
        if V[i] > V[i-1]:
          ans = V[0:i-2]
          ans.append(min(V[i+1:26]))
          ans = ''.join(ans)
          break
        else:
          continue
print(ans)
Problem p03425 (python)

Fixed submission:
n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(n):
  s = input()
  if s[0] == "M":
    m += 1
  if s[0] == "A":
    a += 1
  if s[0] == "R":
    r += 1
  if s[0] == "C":
    c += 1
  if s[0] == "H":
    h += 1
ans = m * a * r +m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+r*c*h+a*c*h
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(n):
  s = input()
  if s[0] == "M":
    m += 1
  if s[0] == "A":
    a += 1
  if s[0] == "R":
    r += 1
  if s[0] == "C":
    c += 1
  if s[0] == "H":
    H += 1
ans = m * a * r +m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+r*c*h+a*c*h
print(ans)
Problem p03483 (python)

Fixed submission:
from collections import deque
import copy
class BIT:
    def __init__(self, node_size):
        self._node = node_size+1
        self.bit = [0]*self._node
 
    def add(self, index, add_val):
        while index < self._node:
            self.bit[index] += add_val
            index += index & -index
 
    def sum(self, index):
        res = 0
        while index > 0:
            res += self.bit[index]
            index -= index & -index
        return res
 
s = input()
n = len(s)
a = [ord(i) - ord("a") for i in s]
x = [0]*26
for i in a:
  x[i] += 1
flag = 1
ki = -1
for i in x:
  if i%2 == 1:
    if flag:
      flag = 0
    else:
      print(-1)
      exit()
c = []
x2 = [0]*26
for i in a:
  x2[i] += 1
  if x[i]//2 >= x2[i]:
    c.append(i)
for i in range(26):
  if x[i]%2 == 1:
    b = copy.deepcopy(c)
    c.append(i)
    b = b[::-1]
    c.extend(b)
    break
else:
  b = copy.deepcopy(c)
  b = b[::-1]
  c.extend(b) 
d = {}
for i in range(26):
  d[i] = deque([])
for i in range(n):
  d[c[i]].append(i+1)
for i in range(n):
  x = d[a[i]].popleft()
  a[i] = x
b = []
for i in range(n):
  b.append([a[i],i+1])
b.sort()
b = b[::-1]
bit = BIT(n)
ans = 0
for i,j in b:
  bit.add(j,1)
  ans += bit.sum(j-1)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
import copy
class BIT:
    def __init__(self, node_size):
        self._node = node_size+1
        self.bit = [0]*self._node

    def add(self, index, add_val):
        while index < self._node:
            self.bit[index] += add_val
            index += index & -index

    def sum(self, index):
        res = 0
        while index > 0:
            res += self.bit[index]
            index -= index & -index
        return res

s = input()
n = len(s)
a = [ord(i) - ord("a") for i in s]
x = [0]*26
for i in a:
  x[i] += 1
flag = 1
ki = -1
for i in x:
  if i%2 == 1:
    if flag:
      flag = 0
    else:
      print(-1)
      exit()
c = []
x2 = [0]*26
for i in a:
  x2[i] += 1
  if x[i]//2 >= x2[i]:
    c.append(i)
for i in range(n):
  if x[i]%2 == 1:
    b = copy.deepcopy(c)
    c.append(i)
    b = b[::-1]
    c.extend(b)
    break
else:
  b = copy.deepcopy(c)
  b = b[::-1]
  c.extend(b) 
d = {}
for i in range(26):
  d[i] = deque([])
for i in range(n):
  d[c[i]].append(i+1)
for i in range(n):
  x = d[a[i]].popleft()
  a[i] = x
b = []
for i in range(n):
  b.append([a[i],i+1])
b.sort()
b = b[::-1]
bit = BIT(n)
ans = 0
for i,j in b:
  bit.add(j,1)
  ans += bit.sum(j-1)
print(ans)
Problem p03557 (python)

Fixed submission:
import bisect
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a = sorted(a)
b = sorted(b)
c = sorted(c)
z = [0] * N
ans = 0
for i in range(N-1,-1,-1):
  e = b[i]
  cin =  bisect.bisect_right(c,e)
  if i + 1 == N:
    z[i] = N-cin
  else:
    z[i] = z[i+1] + N-cin
for i in range(N):
  d = a[i]
  bind =  bisect.bisect_right(b,d)
  if bind == N:
    continue
  ans += z[bind]
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a = sorted(a)
b = sorted(b)
c = sorted(c)
z = [0] * N
ans = 0
for i in range(N-1,-1,-1):
  e = b[i]
  cin =  bisect.bisect_right(c,e)
  if i + 1 == N:
    z[i] = N-cin
  else:
    z[i] = z[i+1] + N-cin
for i in range(N):
  d = a[i]
  bind =  bisect.bisect_right(b,d)
  ans += z[bind]
print(ans)
Problem p03561 (python)

Fixed submission:
k,n = map(int,input().split())
if k %2 ==0:
  ans = []
  ans.append(k//2)
  for i in range(n-1):
    ans.append(k)
  print(*ans)
else:
  ans = []
  for i in range(n):
    ans.append(k//2+1)
  sage = (n)//2
  for i in range(sage):
    if ans[-1] == 1:
      ans.pop()
    else:
      ans[-1] -= 1
      while len(ans) < n:
        ans.append(k)
  print(*ans)

Buggy submission (verdict: Runtime Error):
k,n = map(int,input().split())
if k %2 ==0:
  ans = []
  ans.append(k//2)
  for i in range(n-1):
    ans.append(k)
  print(*ans)
else:
  ans = []
  for i in range(n):
    ans.append(k//2+1)
  sage = (n)//2
  for i in range(sage):
    ans[-1] -=1
    j = -1
    while ans[j] ==0:
      ans[j] = k
      j-=1
      ans[j]-=1
  print(*ans)
Problem p03579 (python)

Fixed submission:
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline
n,m= map(int,input().split())
g = [[]for i in range(n)]
for i in range(m):
        a,b = map(int,input().split())
        a-=1;b-=1
        g[a].append(b)
        g[b].append(a)
kyo = [-1]*n
def dfs(x,y,z):
        for i in g[x]:
                if i == y: continue
                if kyo[i] == -1:
                        kyo[i] = (z+1)%2
                        dfs(i,x,z+1)
                else:
                        if kyo[i] !=  (z+1)%2:
                                print(n*(n-1)//2-m)
                                exit()
                
kyo[0] = 0
dfs(0,0,0)
ki = 0
gu = 0
for i in kyo:
        if i %2 == 0:
                gu += 1
        else:
                ki += 1
print(gu*ki-m)

Buggy submission (verdict: Runtime Error):
import sys
#sys.setrecursionlimit(200000)
input = sys.stdin.readline
n,m= map(int,input().split())
g = [[]for i in range(n)]
for i in range(m):
        a,b = map(int,input().split())
        a-=1;b-=1
        g[a].append(b)
        g[b].append(a)
kyo = [1<<50]*n
def dfs(x,y,z):
        for i in g[x]:
                if i == y: continue
                if kyo[i] > z+1:
                        kyo[i] = z+1
                        dfs(i,x,z+1)
kyo[0] = 0
dfs(0,0,0)
ki = 0
gu = 0
mita = set()
for i in kyo:
        if i in mita:
                print(n*(n-1)//2-m)
                exit()
        mita.add(i)
        if i %2 == 0:
                gu += 1
        else:
                ki += 1
print(gu*ki-m)