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

Fixed submission:
a, b, c = map(int, input().split())
if a*b*c == 175:
  print('YES')
else:
  print('NO')

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

sn = []

for _ in range(1, n+1):
  sn.append(input())
  
sn = sorted(sn)

sn = ''.join(sn)

print(sn)

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

sn = []

for _ in range(n+1):
  sn.append(input())
  
sn = sorted(sn)
sn = ''.join(sn)

print(sn)

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

sn = []

for _ in range(n):
  sn.append(input())
  
sn = sorted(sn)

sn = ''.join(sn)

print(sn)

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
if a*b*c = 245:
  print('YES')
else:
  print('NO')
Problem p04044 (python)

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

sn = []

for _ in range(1, n+1):
  sn.append(input())
  
sn = sorted(sn)

sn = ''.join(sn)

print(sn)

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

sn = []

for _ in range(n):
  sn.append(input())
  
sn = sorted(sn)

sn = join(sn)

print(sn)
Problem p03455 (python)

Fixed submission:
# coding: utf-8

# １行の入力データを分割
data = input().split(" ")


a = int(data[0])
b = int(data[1])

mul = int(a * b)

if mul % 2 == 0:
    print("Even")
else:
    print("Odd")

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())

mul = a * b

if mul % 2 == 0:
    print("Even")
else:
    print("Odd")
Problem p03493 (python)

Fixed submission:
print(input().count("1"))

Buggy submission (verdict: Runtime Error):
from collections import Counter
n, k = map(int, input().split())
a = list(map(int, input().split()))

def cnt_uniq(li):
    return Counter(li).values()

uniq = sorted(cnt_uniq(a), reverse = True)[k:]
print(sum(uniq))
Problem p03495 (python)

Fixed submission:
from collections import Counter
n, k = map(int, input().split())
a = list(map(int, input().split()))

def cnt_uniq(li):
    return Counter(li).values()

uniq = sorted(cnt_uniq(a), reverse = True)[k:]
print(sum(uniq))

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

count = 0;

def cnt_uniq(li):
    ret = []
    for i in li:
        if i not in ret:
            ret.append(i)
    return ret

uniq = sorted(cnt_uniq(a))
while k < len(uniq):
    count += uniq[0]
    uniq.pop[0]

print(count)
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split())
if (a%2 != 0) and (b%2 != 0):
  print("Odd")
else:
  print("Even")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split)
if (a%2 == 0) and (b%2 == 0):
  print ("Even")
else:
  print("Odd")
Problem p03455 (python)

Fixed submission:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
a, b = map(int, input().split())
# 出力
if (a*b) % 2 == 0:
  print("Even")
else:
  print("Odd")

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
a, b = map(int, input().split())
# 出力
if (a*b) % 2 = 0:
  print("Even")
else:
  print("Odd")

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
a, b = map(int, input().split())
# 出力
if a*b % 2 = 0:
  print("Even")
else:
  print("Odd")
Problem p03494 (python)

Fixed submission:

a = int(input())
# スペース区切りの整数の入力
b = input().split()
b = [int(i) for i in b]

c = len(b)
d = 0


while c == len(b):
  c=0
  for i in b:
    if i %2 == 0:
      c +=1
  if(c == len(b)):
    d += 1
    b = [i/2 for i in b]
print (d)

Buggy submission (verdict: Runtime Error):

a = int(input())
# スペース区切りの整数の入力
b = input().split()
b = [int(i) for i in b]

c = len(b)
d = 0


while c == len(b):
  c=0
  for i in b:
    if b %2 == 0:
      c +=1
  if(c == len(a)):
    d += 1
    b = [b /2 for i in b]
print (d)

Buggy submission (verdict: Runtime Error):


a = int(input())
# スペース区切りの整数の入力
b = input().split()
b = [int(i) for i in b]


//a = 4
//b=[5, 6, 8, 10]

c = len(b)
d = 0


while c == len(b):
  c=0
  for i in b:
    if b %2 == 0:
      c +=1
  if(c == len(a)):
    d += 1
    b = [b /2 for i in b]
print (d)

Buggy submission (verdict: Runtime Error):


a = int(input())
# スペース区切りの整数の入力
b = map(int, input().split())


//a = 4
//b=[5, 6, 8, 10]

c = len(b)
d = 0


while c == len(b):
  c=0
  for i in b:
    if b %2 == 0:
      c +=1
  if(c == len(a)):
    d += 1
    b = [b /2 for i in b]
print (d)
Problem p03493 (python)

Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
a = int(input())
s = str(a)
print(sum(list(map(int, list(s)))))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 整数の入力
a = int(input())
print(sum(list(map(int, list(a)))))
Problem p03455 (python)

Fixed submission:
a,b = map(int,input().split())
print('Even') if a*b %2 == 0 else print('Odd')

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
print('Even') if a*b %2 == 0 print('Odd')
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split())
c=a*b
if (c) % 2:
    print("Odd")
else:
    print("Even")

Buggy submission (verdict: Runtime Error):
c = a * b
if c%2 == 0:
    print(even)
else:
    print(odd)
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split())
if (a*b) % 2:
    print("Odd")
else:
    print("Even")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
sum = a * b
if sum % 2 == 0:
    print("Odd")
else:
    print(Even")
Problem p03493 (python)

Fixed submission:
print(input().count("1"))

Buggy submission (verdict: Runtime Error):
a= list(map(int,input().split("0")))
print(sum(a))
Problem p03455 (python)

Fixed submission:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
a, b = map(int, input().split())
if a*b%2 == 0:
# 出力
   print("Even")
else:
   print("Odd")

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
a, b = map(int, input().split())
# 文字列の入力
s = input()
   if a*b%2==0
# 出力
   print("Even")
   else:
    print("Odd")
Problem p03455 (python)

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

if Value%2 == 0:
    print("Even")
else:
    print("Odd")

Buggy submission (verdict: Runtime Error):
a , b = map(int, input(),split())
Value = a*b

if Value%2 == 0:
    print("Even")
else:
    print("Odd")
Problem p03493 (python)

Fixed submission:
print(input().count("1"))

Buggy submission (verdict: Runtime Error):
import math
n = input()
a = list(map(int, input().split()))
ans = float("inf")
for i in a:
    ans = min(ans, len(bin(i)) - bin(i).rfind("1") - 1)
print(round(ans))

Buggy submission (verdict: Runtime Error):
import math
N = input()

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

ans = float("inf")

for i in a:
    ans = min(ans, len(bin(i)) - bin(i).rfind("1") - 1)
print(round(ans))

Buggy submission (verdict: Runtime Error):
import math
N = input()

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

ans = float("inf")

for a in list:
    ans = min(ans, len(bin(a)) - bin(a).rfind("1") - 1)
print(round(ans))

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

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

ans = float("inf")

for a in list:
    ans = min(ans, len(bin(a)) - bin(a).rfind("1") - 1)
print(round(ans))

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

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

ans = float("inf")

for a in list:
    ans = min(ans, len(bin(a)) - bin(a).rfind("1") - 1)
print(ans)
Problem p03455 (python)

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

if (a*b ) % 2:
    print('Odd')
    
else:
    print('Even')

Buggy submission (verdict: Runtime Error):
a, b = int(input().split)

if (a*b ) % 2 = 1
    print('odd')
    
    else
    print('even')

Buggy submission (verdict: Runtime Error):
a, b = int(input().split)

if (a*b )%2 = 1
    print('odd')
    
    else
            print('even')
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split())
if (a*b) % 2:
    print("Odd")
else:
    print("Even")

Buggy submission (verdict: Runtime Error):
a, b =map(int, input()split())
if (a*b) % 2:
    print("Odd")
else:
    print("Even")

Buggy submission (verdict: Runtime Error):
a, b =map(int, input()split())
if (a*b) % 2:
    print("Odd")
eles:
    print("Even")

Buggy submission (verdict: Runtime Error):
a,b=map(int,input()split())
if(a*b)%2:
print("Odd")
eles:
print("Even")

Buggy submission (verdict: Runtime Error):
a,b = map(int,input(.split())
if (a*b)%2:
  print("Odd")
else:
  print("Even")

Buggy submission (verdict: Runtime Error):
a,b = map(int,input(.split())
if (a*b)%2:
  print("Odd")
eles:
  print("Even")
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split())
if (a*b) % 2:
    print("Odd")
else:
    print("Even")

Buggy submission (verdict: Runtime Error):
a , b=map(int , input() , split() )
if(a*b)%2:
    print("Odd")
else:
    print("Even")

Buggy submission (verdict: Runtime Error):
a , b=map(int , input() , split() )
if(a*b)%2:
    print("0dd")
else:
    print("Even")
Problem p03456 (python)

Fixed submission:
a , b = map(int , input().split())
c=str(a)+str(b)
c=int(c)
for i in range (1000):
    if c== int(i*i):
        print("Yes")  
        break      
    elif i==1000-1:
        print("No")
        break

Buggy submission (verdict: Runtime Error):
a , b = map(int , input().split())
c=str(a)+str(b)
c=int(c)
for i in range (c/2):
    if c== int(i*i):
        print("Yes")  
        break      
    elif i==(c/2)-1:
        print("No")
        break

Buggy submission (verdict: Runtime Error):
a , b = map(int , input().split())
c=str(a)+str(b)
c=int(c)
for i in range (c/2):
    if c== int(i*i):
        print("Yes")  
        break      
    elif i==c/2-1:
        print("No")
        break

Buggy submission (verdict: Runtime Error):
a , b = map(int , input().split())
c=str(a)+str(b)
c=int(c)
for i in range (c/2):
    if c== int(i*i):
        print("Yes")  
        break      
    elif i==1000-1:
        print("No")
        break

Buggy submission (verdict: Runtime Error):
a , b = map(int , input().split())
c=str(a)+str(b)
c=int(c)
if math.sqrt(c):
    print("Yes")  
else :
    print("No")

Buggy submission (verdict: Runtime Error):
a , b = map(int , input().split)
c=str(a)+str(b)
c=int(c)
for i in range (100):
    if c== int(i*i):
        print("Yes")  
        break      
    elif i==100-1:
        print("No")
        break

Buggy submission (verdict: Runtime Error):
a , b = map(int , input().split)
c=str(a)+str(b)
c=int(c)
for i in range (20):
    if c== int(i*i):
        print("Yes")  
        break      
    elif i==20-1:
        print("No")
        break

Buggy submission (verdict: Runtime Error):
a , b = map(int , input().split)
c=str(a)+str(b)
c=int(c)
for i in range (20):
    if c!= int(i^2):
        print("Yes")  
        break      
    elif c==20:
        print("No")
        break

Buggy submission (verdict: Runtime Error):
a , b = map(int , input().split)
c=str(a)+str(b)
c=int(c)
for i in range (20):
    if c!= int(i^2):
        print("Yes")  
        break      
    elif c==100:
        print("No")
        break

Buggy submission (verdict: Runtime Error):
a , b = map(int , input().split)
c=str(a)+str(b)
c=int(c)
print(c)
for i in range (20):
    if c!= int(i^2):
        print("Yes")  
        break      
    elif c==100:
        print("No")
        break

Buggy submission (verdict: Runtime Error):
a , b = map(int , input().split)
c=str(a)+str(b)
c=int(c)
print(c)
for i in range (100):
    if c!= int(i^2):
        print("Yes")  
        break      
    elif c==100:
        print("No")
        break

Buggy submission (verdict: Runtime Error):
a , b = map(int , input().split)
c=str(a)+str(b)
c=int(c)
for i in range (100)
    if c== i*i
        print("Yes")
    elif i==100:
        print("No")

Buggy submission (verdict: Runtime Error):
a , b = map(int , input().split)
c=str(a)+str(b)
c=int(c)
for i in range (100)
    if c== i*i
        print("Yes)
Problem p03493 (python)

Fixed submission:
#codigng: utf-8
from sys import stdin

bin  = list(stdin.readline().rstrip())
one = [x for x in bin if x == '1']

print(len(one))

Buggy submission (verdict: Runtime Error):
#codigng: utf-8
from sys import stdin

bin  = list(stdin.readline().rstrip())
one = [x for x in bin if x == '1']

print(len(one)
Problem p03861 (python)

Fixed submission:
a, b, x = map(int, input().split())
 
def count(num1, num2):
  return num1 // num2
 
c = count(b, x)
d = count(a-1, x)
 
ans = c-d
print(ans)

Buggy submission (verdict: Runtime Error):
a, b, x = map(int, input().split())

def count(num1, num2):
  return num1 // num2

c = count(b, x)
d = count(a-1)

ans = c-d
print(ans)
Problem p03455 (python)

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

if a*b%2==0:
  print("Even")
else:
  print("Odd")

Buggy submission (verdict: Runtime Error):
a,b=map(int, input()., split())
if a*b/2==0:
  print("Even")
else:
  print("Odd")
Problem p03455 (python)

Fixed submission:
#整数の入力
a, b = map(int, input().split())

#取りあえず掛け算
c = a * b

#剰余計算
d = c % 2

if d == 0:
  print("Even")
else:
  print("Odd")

Buggy submission (verdict: Runtime Error):
#整数の入力
a, b = map(int, input().split())

#取りあえず掛け算
c = a * b

#剰余計算
d = c % 2

if d == 0:
  print("Even")
Else:
  print("Odd")
Problem p03455 (python)

Fixed submission:
a, b = list(map(int, input().split()))
if a * b % 2 == 0:
    print('Even')
else:
    print('Odd')

Buggy submission (verdict: Runtime Error):
a, b = list(map(int, input().split()))
if a * b % 2 == 0:
Problem p03480 (python)

Fixed submission:
S = input().strip()

Ks = []
for i in range(len(S)-1):
    if S[i] != S[i+1]:
        Ks.append(max(i+1, len(S)-i-1))

print(min(Ks) if len(Ks) != 0 else len(S))

Buggy submission (verdict: Runtime Error):
S = input().strip()

Ks = []
for i in range(len(S)-1):
    if S[i] != S[i+1]:
        Ks.append(max(i+1, len(S)-i-1))

print(min(Ks))
Problem p03488 (python)

Fixed submission:
s = input().split('T')
gx, gy = tuple(map(int, input().split()))

dir = 0
xmoves = []
ymoves = []
for moves in s:
    if dir % 2 == 0:
        xmoves.append(len(moves))
    else:
        ymoves.append(len(moves))
    dir += 1

curx, cury = xmoves.pop(0), 0

for move in sorted(xmoves, reverse=True):
    if curx > gx:
        curx -= move
    else:
        curx += move

for move in sorted(ymoves, reverse=True):
    if cury > gy:
        cury -= move
    else:
        cury += move

if curx == gx and cury == gy:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s = input().strip()
goal = tuple(map(int, input().split()))

def change_dir(direc, case):
    if case == 0:
        direc += 1
        if direc == 5:
            direc = 1
    else:
        direc -= 1
        if direc == 0:
            direc = 4
    return direc

def go_in_dir(direc, pos):
    if direc == 1:
        return (pos[0]+1, pos[1])
    elif direc == 2:
        return (pos[0], pos[1]+1)
    elif direc == 3:
        return (pos[0]-1, pos[1])
    else:
        return (pos[0], pos[1]-1)

def exec_s(s, goal, direc=1, pos=(0, 0)):
    if len(s) == 0:
        if pos == goal:
            return True
        else:
            return False

    new_pos = pos
    while len(s) > 0 and s[0] == 'F':
        new_pos = go_in_dir(direc, new_pos)
        s = s[1:]

    if len(s) == 0:
        if new_pos == goal:
            return True
        else:
            return False

    new_dir = change_dir(direc, 0)
    reached = exec_s(s[1:], goal, new_dir, new_pos)
    if reached:
        return True
    else:
        new_dir = change_dir(direc, 1)
        return exec_s(s[1:], goal, new_dir, new_pos)

if exec_s(s, goal):
    print('Yes')
else:
    print('No')
Problem p03729 (python)

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

if a[-1] == b[0] and b[-1] == c[0]:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
a, b, c = [int(x) for x in input().split()]

def foo(a, b, c):
    for i in range(1, b+1):
        if (a*i)%b == c:
            return "YES"
    return "NO"
    
print(foo(a, b, c))

Buggy submission (verdict: Runtime Error):
a, b, c = [int(x) for x in input().split()]

from math import gcd

def foo(a, b, c):
    if a == 1:
        return "YES"
    elif b == 1:
        return "NO"
    elif gcd(a, b) ==1:
        return "NO"
    else:
        return "YES"
    
print(foo(a, b, c))

Buggy submission (verdict: Runtime Error):
a, b, c = [int(x) for x in input().split()]

from math import gcd

def foo(a, b, c):
    if a == 1:
        return "YES"
    elif b == 1:
        return "NO"
    elif gcd(a, b) ==1:
        return "NO:
    else:
        return "YES"

print(foo(a, b, c))
Problem p03730 (python)

Fixed submission:
a, b, c = [int(x) for x in input().split()]
 
def foo(a, b, c):
    for i in range(1, b+1):
        if (a*i)%b == c:
            return "YES"
    return "NO"
    
print(foo(a, b, c))

Buggy submission (verdict: Runtime Error):
a, b, c = [int(x) for x in input().split()]

from math import gcd

def foo(a, b, c):
    if a == 1:
        return "YES"
    elif b == 1:
        return "NO"
    elif gcd(a, b) ==1:
        return "NO:
    else:
        return "YES"
Problem p03455 (python)

Fixed submission:
a,b = map(int, input().split())
rest = a * b % 2
if rest == 1:
    print('Odd')
else:
    print('Even')

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
rest = a * b % 2
if rest == 1:
    print('Odd')
else:
    print('Even')
Problem p03469 (python)

Fixed submission:
S = raw_input()
print('2018/01/' + S[-2] + S[-1])

Buggy submission (verdict: Runtime Error):
S = raw_input()

print('2018/01' + S[-2]
Problem p03563 (python)

Fixed submission:
r = int(input())
g = int(input())

print(2 * g - r)

Buggy submission (verdict: Runtime Error):
r, g = int(input()).split()
print(2 * g - r)
Problem p04001 (python)

Fixed submission:
import sys
perm = sys.stdin.readline().strip()
total = 0

# Add n * '+' to inp
def addPlus(inp, n):
    total = 0
    possible = [inp]
    orig = inp

    for i in range(1, len(orig)):
        possible.append(orig[:i] + '+' + perm[i:])

    for i in range(1, n):
        curr = possible[:]
        for item in curr:
            for j in range(1, len(item)):
                processed = item[:j] + '+' + item[j:]
                if processed not in possible:
                    if '++' not in processed:
                        possible.append(processed)

    for item in possible:
        total += eval(item)

    return total


print(addPlus(perm, len(perm) - 1))

Buggy submission (verdict: Runtime Error):
import sys
grid = []
painted = []

height, width, n = sys.stdin.readline().strip().split()
height, width, n = int(height), int(width), int(n)

def checkGrid(x, y, grid):
    count = 0
    for col in range(x, x+3):
        for row in range(y, y+3):
            if grid[row][col] == 1:
                count += 1
    return count

inp = sys.stdin.readline().strip()
while inp:
    a, b = inp.split()
    grid.append([int(a) - 1, int(b) - 1])
    inp = sys.stdin.readline().strip()

# Build empty grid
for i in range(height):
    painted.append([])
    for j in range(width):
        if [i, j] in grid:
            painted[i].append(1)
        else:
            painted[i].append(0)

# Build painted cells
for cell in grid:
    painted[cell[0]][cell[1]] = 1

for i in range(0, 10):
    count = 0
    for col in range(width - 2):
        for row in range(height - 2):
            if checkGrid(col, row, painted) == i:
                count += 1
    print(count)
Problem p03854 (python)

Fixed submission:
#coding:utf-8
import re

if __name__ == "__main__":
    patterns = ["dream", "dreamer", "erase" ,"eraser"]
    S = input()

    while True:
        flag = False
        if S[-5:] == "dream":
            S = S[:-5]
            flag = True
        if S[-7:] == "dreamer":
            S = S[:-7]
            flag = True
        if S[-5:] == "erase":
            S = S[:-5]
            flag = True
        if S[-6:] == "eraser":
            S = S[:-6]
            flag = True

        if flag == False:
            print("NO")
            break

        if S == "":
            print("YES")
            break

Buggy submission (verdict: Runtime Error):
#coding:utf-8
import re

if __name__ == "__main__":
    patterns = ["dream", "dreamer", "erase" ,"eraser"]
    S = input()

    # while True:
    #     flag = False
    #     if S[-5:] == "dream":
    #         S = S[:-5]
    #         flag = True
    #     if S[-7:] == "dreamer":
    #         S = S[:-7]
    #         flag = True
    #     if S[-5:] == "erase":
    #         S = S[:-5]
    #         flag = True
    #     if S[-6:] == "eraser":
    #         S = S[:-6]
    #         flag = True
    #
    #     if flag == False:
    #         print("NO")
    #         break
    #
    #     if S == "":
    #         print("YES")
    #         break

    while True:
        flag = False
        if re.search("dream$",S):
            S = re.sub("dream$","",S)
            flag = True
        if re.search("dreamer$",S):
            S = re.sub("dreamer$","",S)
            flag = True
        if re.search("erase$",S):
            S = re.sub("erase$","",S)
            flag = True
        if re.search("eraser$",S):
            S = r
Problem p03483 (python)

Fixed submission:
from collections import Counter
import sys
s = input()
N = len(s)
sc = Counter(s)
odds = [1 for x in sc if sc[x] % 2 == 1]
if len(odds) > 1:
    print(-1)
    sys.exit(0)

class BIT:
    def __init__(self, size):
        self.bit = [0] * (size+1)
    def add(self, index, elem):
        index += 1
        while index < len(self.bit):
            self.bit[index] += elem
            index += index & -index
    def get(self, index):
        index += 1
        ret = 0
        while 0 < index:
            ret += self.bit[index]
            index -= index & -index
        return ret

indices = [-1] * N
tb = {c: [None] * (sc[c]//2) for c in sc}
lens = {c: 0 for c in sc}
p = 0
for i in range(N):
    c = s[i]
    l = lens[c]
    if 2 * (l+1) <= sc[c]:
        indices[p] = i
        tb[c][l] = p
        lens[c] += 1
        p += 1
    elif 2 * (l+1) == sc[c] + 1:
        indices[N//2] = i
        lens[c] += 1
    else:
        indices[N-1-tb[c][sc[c]-l-1]] = i
        lens[c] += 1

ans = 0
bit = BIT(N)
for i in indices:
    bit.add(i, 1)
    ans += bit.get(N-1) - bit.get(i)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
import sys
s = input()
N = len(s)
sc = Counter(s)
odds = [1 for x in sc if sc[x] % 2 == 1]
if len(odds) > 1:
    print(-1)
    sys.exit(0)

class BIT:
    def __init__(self, size):
        self.bit = [0] * (size+1)
    def add(self, index, elem):
        index += 1
        while index < len(self.bit):
            self.bit[index] += elem
            index += index & -index
    def get(self, index):
        index += 1
        ret = 0
        while 0 < index:
            ret += self.bit[index]
            index -= index & -index
        return ret

indices = [-1] * N
tb = {c: [None] * (sc[c]//2) for c in sc}
lens = {c: 0 for c in sc}
p = 0
for i in range(N):
    c = s[i]
    l = lens[c]
    if 2 * l < sc[c]:
        indices[p] = i
        tb[c][l] = p
        lens[c] += 1
        p += 1
    elif 2 * l == sc[c] + 1:
        indices[N//2] = i
    else:
        indices[N-1-tb[c][sc[c]-l-1]] = i
        lens[c] += 1

ans = 0
bit = BIT(N)
for i in indices:
    bit.add(i, 1)
    ans += bit.get(N-1) - bit.get(i)
print(ans)