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

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

eve = {}
odd = {}

for i in range(len(vs)):
    if i % 2 == 0:
        if vs[i] in eve:
            eve[vs[i]] += 1
        else:
            eve[vs[i]] = 1
    else:
        if vs[i] in odd:
            odd[vs[i]] += 1
        else:
            odd[vs[i]] = 1

es = sorted(eve.items(), key=lambda x: -x[1])
os = sorted(odd.items(), key=lambda x: -x[1])

if es[0][0] == os[0][0]:
    if es[0][1] > os[0][1]:
        del es[0]
        if len(os) > 1 :
            del os[1]
    elif es[0][1] < os[0][1]:
        del os[0]
        if len(es) > 1 :
            del es[1]
    else:
        if len(es) == 1 and len(os) == 1:
            del os[0]
        elif len(es) == 1 and len(os) != 1:
            del es[0]
            del os[1]
        elif len(es) != 1 and len(os) == 1:
            del es[1]
            del os[0]
        else:
            if es[1][1] < os[1][1]:
                del es[0]
                del os[1]
            else:
                del es[1]
                del os[0]
else:
    del os[0]
    del es[0]

trans = 0

for i in range(len(es)):
    trans += es[i][1]
for i in range(len(os)):
    trans += os[i][1]

print(trans)

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

eve = {}
odd = {}

for i in range(len(vs)):
    if i % 2 == 0:
        if vs[i] in eve:
            eve[vs[i]] += 1
        else:
            eve[vs[i]] = 1
    else:
        if vs[i] in odd:
            odd[vs[i]] += 1
        else:
            odd[vs[i]] = 1

es = sorted(eve.items(), key=lambda x: -x[1])
os = sorted(odd.items(), key=lambda x: -x[1])

if es[0][0] == os[0][0]:
    if es[0][1] > os[0][1]:
        del es[0]
        if len(os) > 1 :
            del os[1]
    elif es[0][1] < os[0][1]:
        del os[0]
        if len(es) > 1 :
            del es[1]
    else:
        if len(es) == 1:
            del es[0]
            del os[1]
        elif len(os) == 1:
            del es[1]
            del os[0]
        else:
            if es[1][1] < os[1][1]:
                del es[0]
                del os[1]
            else:
                del es[0]
                del os[1]



else:
    del os[0]
    del es[0]

trans = 0

for i in range(len(es)):
    trans += es[i][1]
for i in range(len(os)):
    trans += os[i][1]

print(trans)
Problem p03260 (python)

Fixed submission:
a, b = map(int, input().split())
if a % 2 == 0 or b % 2 == 0:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a % 2 == 0 or b % 2 == 0:
    print('No')
else:
    print('Yes)
Problem p03262 (python)

Fixed submission:
def getGcd(num1, num2):
    while True:
        tmp = num1
        num1 = num2 % num1
        num2 = tmp
        if(num1 == 0):
            return tmp

[n, x] = map(int, input().split(" "))
xs = list(map(int, input().split(" ")))

xs.append(x)
xs.sort()

gc = xs[1] - xs[0]

for i in range(1, n + 1):
    gc = getGcd(gc,  xs[i] - xs[i - 1])

print(gc)

Buggy submission (verdict: Runtime Error):
from math import gcd

[n, x] = map(int, input().split(" "))
xs = list(map(int, input().split(" ")))

xs.append(x)
xs.sort()

gc = xs[1] - xs[0]

for i in range(1, n + 1):
    gc = gcd(gc,  xs[i] - xs[i - 1])

print(gc)

Buggy submission (verdict: Runtime Error):
import math

[n, x] = map(int, input().split(" "))
xs = list(map(int, input().split(" ")))

xs.append(x)
xs.sort()
gc = xs[1] - xs[0]

for i in range(1, n):
    gc = math.gcd(gc,  xs[i] - xs[i - 1])

print(gc)

Buggy submission (verdict: Runtime Error):
import math

[n, x] = map(int, input().split(" "))
xs = list(map(int, input().split(" ")))
xs.append(x)
xs.sort()
gcd =  xs[1] - xs[0]

for i in range(1, n + 1):
    gcd = math.gcd(gcd,  xs[i] - xs[i - 1])

print(gcd)

Buggy submission (verdict: Runtime Error):
import math

[n, x] = map(int, input().split(" "))
xs = list(map(int, input().split(" ")))
xs.append(x)
xs.sort()
gcd =  xs[1] - xs[0]

for i in range(1, n):
    gcd = math.gcd(gcd,  xs[i] - xs[i - 1])

print(gcd)

Buggy submission (verdict: Runtime Error):
import math

[n, x] = map(int, input().split())

xs = list(map(int, input().split()))
xs.append(x)

xs.sort()
gcd =  xs[1] - xs[0]

for i in range(1, len(xs)):
    gcd = math.gcd(gcd,  xs[i] - xs[i - 1])

print(gcd)
Problem p03282 (python)

Fixed submission:
s = input()
k = int(input())
end = False
for i in range(min(len(s), k)):
    if s[i] != '1':
        print(s[i])
        end = True
        break
if end == False:
    print(1)

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())

ok = True
for a in range(k):
    if int(s[a]) != 1:
        print(s[a])
        ok = False
        break

if ok:
    print(s[k])
Problem p03287 (python)

Fixed submission:
import numpy as np
(n, m) = list(map(int, input().split()))
a = np.array(list(map(int, input().split()))).astype("int64") 
a = np.cumsum(a)
a %= m
count = np.sum(a == 0)
a.sort()
tc = 1
for i in range(1, n):
    if a[i - 1] == a[i]:
        tc += 1
    else:
        count += tc * (tc - 1) // 2
        tc = 1
else:
    count += tc * (tc - 1) // 2
print(count)

Buggy submission (verdict: Runtime Error):
(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
unique_a = {a[0] % m: 1}
for i in range(1, n):
    a[i] += a[i - 1]
    a[i] %= m
    if a[i] in unique_a:
        unique_a[a[i]] += 1
    else:
        unique_a[a[i]] = 1
count = unique_a[0]
for k in unique_a:
    count += unique_a[k] * (unique_a[k] - 1) // 2
print(count)

Buggy submission (verdict: Runtime Error):
(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
unique = {a[0] % m: 1}
for i in range(1, n):
    a[i] += a[i - 1]
    a[i] %= m
    if a[i] in unique:
        unique[a[i]] += 1
    else:
        unique[a[i]] = 1
count = unique[0]
for k in unique:
    count += unique[k] * (unique[k] - 1) // 2
print(count)

Buggy submission (verdict: Runtime Error):
import numpy as np
(n, m) = list(map(int, input().split()))
a = np.array(list(map(int, input().split()))).astype("int64") 
a = np.cumsum(a)
a %= m
count = np.sum(a == 0)
(key, counts) = np.unique(a, return_counts=True)

Buggy submission (verdict: Runtime Error):
import numpy as np
(n, m) = list(map(int, input().split()))
a = np.array(list(map(int, input().split()))).astype("int64") 
a = np.cumsum(a)
a %= m
count = np.sum(a == 0)
(unique, counts) = np.unique(a, return_counts=True)

Buggy submission (verdict: Runtime Error):
import numpy as np
(n, m) = list(map(int, input().split()))
a = np.array(list(map(int, input().split()))).astype("int64") 
a = np.cumsum(a)
a %= m
count = np.sum(a == 0)
(unique, counts) = np.unique(a, return_counts=True) 
counts = np.array(counts).astype("int64")
counts = counts * (counts - 1) // 2
print(count + np.sum(counts))

Buggy submission (verdict: Runtime Error):
import numpy as np
(n, m) = list(map(int, input().split()))
a = np.array(list(map(int, input().split())))
a = np.cumsum(a)
a %= m
count = np.sum(a == 0)
unique, counts = np.unique(a, return_counts=True) 
counts = np.array(counts)
counts = counts * (counts - 1) // 2
print(count + np.sum(counts))

Buggy submission (verdict: Runtime Error):
import numpy as np
(n, m) = list(map(int, input().split()))
a = np.array(list(map(int, input().split()))).astype("int64") 
a = np.cumsum(a)
a %= m
count = np.sum(a == 0)
unique, counts = np.unique(a, return_counts=True) 
counts = np.array(counts).astype("int64")
counts = counts * (counts - 1) // 2
print(count + np.sum(counts))
Problem p03361 (python)

Fixed submission:
import sys
(h, w) = map(int, input().split())
D = '.'
sw = []
sw.append([D for i in range(w + 2)])
for i in range(h):
    sw.append([D] + list(input()) + [D])
sw.append([D for i in range(w + 2)])

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if sw[i][j] == D:
            continue
        ok = False
        for dir in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
            if sw[i + dir[0]][j + dir[1]] == '#':
                ok = True
                break
        if ok == False:
            print('No')
            sys.exit(0)
print('Yes')

Buggy submission (verdict: Runtime Error):
import sys
(h, w) = map(int, input().split())
sw = []
sw.append(['.' for i in range(h + 2)])
for i in range(w):
    sw.append(['.'] + list(input()) + ['.'])
sw.append(['.' for i in range(h + 2)])

dirs = [[1, 0], [-1, 0], [0, 1], [0, -1]]
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if sw[i][j] == '.':
            continue
        ok = False
        for dir in dirs:
            if sw[i + dir[0]][j + dir[1]] == '#':
                ok = True
                break
        if ok == False:
            print('No')
            sys.exit(0)
print('Yes')

Buggy submission (verdict: Runtime Error):
import sys
(h, w) = map(int, input().split())
sw = [['.' for i in range(h + 2)]]
for i in range(w):
    sw.append(['.'] + list(input()) + ['.'])
sw.append(['.' for i in range(h + 2)])

dirs = [[1, 0], [-1, 0], [0, 1], [0, -1]]
for i in range(1, w + 1):
    for j in range(1, h + 1):
        if sw[i][j] == '.':
            continue
        ok = False
        for dir in dirs:
            if sw[i + dir[0]][j + dir[1]] == '#':
                ok = True
                break
        if ok == False:
            print('No')
            sys.exit(0)
print('Yes')

Buggy submission (verdict: Runtime Error):
(h, w) = map(int, input().split())
sw = [['.' for i in range(h + 2)]]
for i in range(w):
    sw.append(['.'] + list(input()) + ['.'])
sw.append(['.' for i in range(h + 2)])

dirs = [[1, 0], [-1, 0], [0, 1], [0, -1]]
ng = False
for i in range(1, w + 1):
    if ng == True:
        break
    for j in range(1, h + 1):
        if ng == True:
            break
        if sw[i][j] == '.':
            continue
        ok = False
        for dir in dirs:
            if sw[i + dir[0]][j + dir[1]] == '#':
                ok = True
                break
        if ok == False:
            print('No')
            ng = True
if ng == False:
    print('Yes')
Problem p03393 (python)

Fixed submission:
import sys
s = input() + chr(96)

for j in range(len(s) - 1, -1, -1):
    sets = set(list(s[:j]))
    for i in range(ord(s[j]) + 1, ord('z') + 1):
        if chr(i) not in sets:
            print(s[:j] + chr(i))
            sys.exit(0)
print(-1)

Buggy submission (verdict: Runtime Error):
import sys
s = input() + chr(96)

if len(s) != 26:
    sets = set(s)
    for i in range(ord('a'), ord('z') + 1):
        if chr(i) not in sets:
            print(s[:j] + chr(i))
            sys.exit(0)
j = 26
for j in range(26, 1, -1):
    if s[j - 1] > s[j]:
        continue
    sets = set(list(s[:j]))
    for i in range(ord(s[j]) + 1, ord('z') + 1):
        if chr(i) not in sets:
            print(s[:j] + chr(i))
            sys.exit(0)
print(-1)
Problem p03417 (python)

Fixed submission:
(n, m) = map(int, input().split())
if n == 1:
    if m == 1:
        print(1)
    else:
        print(m - 2)
elif m == 1:
    print(n - 2)
else:
    print((n-2)*(m-2))

Buggy submission (verdict: Runtime Error):
(n, m) = map(int, input().split())
if n == 1:
    if m == 1:
        print(1):
    else:
        print(m - 2)
else:
    print((n-2)*(m-2))
Problem p03425 (python)

Fixed submission:
n = int(input())
march = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for i in range(n):
    str = input()
    if str[0] in march:
        march[str[0]] += 1
for i in list(march):
    if march[i] == 0:
        march.pop(i)
c = 0
if len(march) == 3:
    tmpc = 1
    for chr in march:
        tmpc *= march[chr]
    c += tmpc
elif len(march) == 4:
    for i in march:
        tmpm = march.copy()
        tmpm.pop(i)
        tmpc = 1
        for chr in tmpm:
            tmpc *= tmpm[chr]
        c += tmpc
elif len(march) == 5:
    keys = list(march.keys())
    for i in range(len(keys)):
        for j in range(i + 1, len(keys)):
            tmpm = march.copy()
            tmpm.pop(keys[i])
            tmpm.pop(keys[j])
            tmpc = 1
            for chr in tmpm:
                tmpc *= tmpm[chr]
            c += tmpc
print(c)

Buggy submission (verdict: Runtime Error):
n = int(input())
march = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for i in range(n):
    str = input()
    if str[0] in march:
        march[str[0]] += 1
for i in list(march):
    if march[i] == 0:
        march.pop(i)
c = 0
if len(march) == 3:
    tmpc = 1
    for chr in march:
        tmpc *= march[chr]
    c += tmpc
elif len(march) == 4:
    for i in march:
        tmpm = march.copy()
        tmpm.pop(i)
        tmpc = 1
        for chr in tmpm:
            tmpc *= tmpm[chr]
        c += tmpc
elif len(march) == 5:
    for i in march:
        tmpm1 = march.copy()
        tmpm1.pop(i)
        for j in tmpm1:
            tmpm2 = tmpm1.copy()
            tmpm2.pop(j)
            tmpc = 1
            for chr in tmpm:
                tmpc *= tmpm[chr]
            c += tmpc
print(c)

Buggy submission (verdict: Runtime Error):
n = int(input())
march = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for i in range(n):
    str = input()
    if str[0] in march:
        march[str[0]] += 1

for i in list(march):
    if march[i] == 0:
        march.pop(i)

c = 0
if len(march) == 3:
    tmpc = 1
    for chr in march:
        tmpc *= march[chr]
    c += tmpc
elif len(march) == 4:
    for i in march:
        tmpm = march.copy()
        tmpm.pop(i)
        tmpc = 1
        for chr in tmpm:
            tmpc *= tmpm[chr]
        c += tmpc
elif len(march) == 5:
    for i in march:
        tmpm1 = march.copy()
        tmpm1.pop(i)
        for j in tmpm1:
            tmpm2 = tmpm1.copy()
            tmpm2.pop(j)
            tmpc = 1
            for chr in tmpm:
                tmpc *= tmpm[chr]
            c += tmpc
print(c)
Problem p03599 (python)

Fixed submission:
(a, b, c, d, e, f) = list(map(int, input().split()))
a *= 100
b *= 100

n = [[0, 0] for _ in range(f + 1)]
n[a][0] = a
for i in range(f + 1 - a):
    if n[i][0] != 0:
        n[i + a][0] = n[i][0] + a
if f >= b:
    n[b][0] = b
    for i in range(f + 1 - b):
        if n[i][0] != 0:
            n[i + b][0] = n[i][0] + b
for i in range(f + 1 - c):
    if n[i][0] == 0:
        continue
    tmpt = n[i][0] / 100
    if (c + n[i][1]) / tmpt <= e and n[i + c][1] / (i + c) < (n[i][1] + c) / (i + c):
            n[i + c][0] = n[i][0]
            n[i + c][1] = n[i][1] + c
for i in range(f + 1 - d):
    if n[i][0] == 0:
        continue
    tmpt = n[i][0] / 100
    if (d + n[i][1]) / tmpt <= e and n[i + d][1] / (i + d) < (n[i][1] + d) / (i + d):
            n[i + d][0] = n[i][0]
            n[i + d][1] = n[i][1] + d
maxp = [0, a, 0]
for i in range(len(n)):
    if(n[i][1] != 0 and maxp[0] < n[i][1] / i):
        maxp = [n[i][1] / i] + n[i]
print(str(maxp[1] + maxp[2]) + ' ' + str(maxp[2]))

Buggy submission (verdict: Runtime Error):
(a, b, c, d, e, f) = list(map(int, input().split()))
a *= 100
b *= 100

n = [[0, 0] for _ in range(f + 1)]
n[a][0] = a
for i in range(f + 1 - a):
    if n[i][0] != 0:
        n[i + a][0] = n[i][0] + a
n[b][0] = b
for i in range(f + 1 - b):
    if n[i][0] != 0:
        n[i + b][0] = n[i][0] + b
for i in range(f + 1 - c):
    if n[i][0] == 0:
        continue
    tmpt = n[i][0] / 100
    if (c + n[i][1]) / tmpt <= e :
        if n[i + c][1] == 0 and n[i + c][1] / (i + c) < (n[i][1] + c) / (i + c):
            n[i + c][0] = n[i][0]
            n[i + c][1] = n[i][1] + c
for i in range(f + 1 - d):
    if n[i][0] == 0:
        continue
    tmpt = n[i][0] / 100
    if (d + n[i][1]) / tmpt <= e:
        if n[i + d][1] == 0 and n[i + d][1] / (i + d) < (n[i][1] + d) / (i + d):
            n[i + d][0] = n[i][0]
            n[i + d][1] = n[i][1] + d
maxp = [0, 100, 0]
for i in range(len(n)):
    if(n[i][1] != 0 and maxp[0] < n[i][1] / i):
        maxp = [n[i][1] / i] + n[i]
print(str(maxp[1] + maxp[2]) + ' ' + str(maxp[2]))

Buggy submission (verdict: Runtime Error):
(a, b, c, d, e, f) = list(map(int, input().split()))
a *= 100
b *= 100

n = [[0, 0] for _ in range(f + 1)]
n[a][0] = a
for i in range(f + 1 - a):
    if n[i][0] != 0:
        n[i + a][0] = n[i][0] + a
n[b][0] = b
for i in range(f + 1 - b):
    if n[i][0] != 0:
        n[i + b][0] = n[i][0] + b
for i in range(f + 1 - c):
    if n[i][0] == 0:
        continue
    tmpt = n[i][0] / 100
    if (c + n[i][1]) / tmpt <= e and n[i + c][1] / (i + c) < (n[i][1] + c) / (i + c):
        n[i + c][0] = n[i][0]
        n[i + c][1] = n[i][1] + c
for i in range(f + 1 - d):
    if n[i][0] == 0:
        continue
    tmpt = n[i][0] / 100
    if (d + n[i][1]) / tmpt <= e and n[i + d][1] / (i + d) < (n[i][1] + d) / (i + d):
        n[i + d][0] = n[i][0]
        n[i + d][1] = n[i][1] + d
maxp = [0, 100, 0]
for i in range(len(n)):
    if(n[i][1] != 0 and maxp[0] < n[i][1] / i):
        maxp = [n[i][1] / i] + n[i]
print(str(maxp[1] + maxp[2]) + ' ' + str(maxp[2]))
Problem p03651 (python)

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


a.sort()
if a[-1] < k:
    print('IMPOSSIBLE')
    sys.exit(0)

seta = set(a)
if k in seta:
    print('POSSIBLE')
    sys.exit(0)
change = True
while change:
    change = False
    setb = seta.copy()
    sorteda = sorted(seta)
    mini = sorteda[0] if sorteda[0] != 0 else sorteda[1]
    for i in range(1, len(sorteda)):
        setb.add(sorteda[i] % mini)
    if setb != seta:
        change = True
        seta = setb

mini = sorted(seta)[1]
a.reverse()

for i in a:
    if (k - i) % mini == 0:
        print('POSSIBLE')
        sys.exit(0)
print('IMPOSSIBLE')

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

def f(l, s):
    return s if l % s == 0 else f(s, l % s)

z = f(a[1], a[0])
for i in a:
    z = f(i, z)

if a[-1] >= k and k % z == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
import sys
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
seta = set(a)
lena = 0
while lena != len(seta):
    lena = len(seta)
    sorteda = sorted(seta)
    mini = sorteda[0] if sorteda[0] != 0 else sorteda[1]
    for i in range(1, len(sorteda)):
        seta.add(sorteda[i] % mini)

mini = sorted(seta)[1]
a.reverse()

if k <= a[0] and k % mini == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

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

a.sort()
if a[-1] < k:
    print('IMPOSSIBLE')
    sys.exit(0)

seta = set(a)
change = True
while change:
    change = False
    setb = seta.copy()
    sorteda = sorted(seta)
    mini = sorteda[0] if sorteda[0] != 0 else sorteda[1]
    for i in range(1, len(sorteda)):
        setb.add(sorteda[i] % mini)
    if setb != seta:
        change = True
        seta = setb

mini = sorted(seta)[1]
a.reverse()

for i in a:
    if (k - i) % mini == 0:
        print('POSSIBLE')
        sys.exit(0)
print('IMPOSSIBLE')

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


if a[-1] < k:
    print('IMPOSSIBLE')
    sys.exit(0)

seta = set(a)
if k in seta:
    print('POSSIBLE')
    sys.exit(0)
change = True
while change:
    change = False
    setb = seta.copy()
    sorteda = sorted(seta)
    for i in range(1, len(sorteda)):
        setb.add(sorteda[i] % sorteda[0])
    if setb != seta:
        change = True
        seta = setb

mini = sorted(seta)[1]
a.sort()
a.reverse()

for i in a:
    if (k - i) % mini == 0:
        print('POSSIBLE')
        sys.exit(0)
print('IMPOSSIBLE')
Problem p03665 (python)

Fixed submission:
import collections, scipy.misc 
n, p = map(int, input().split())
a = list(map(int, input().split()))

for i in range(n):
    a[i] %= 2
c = collections.Counter(a)
zero = c[0]
one = c[1]
ans = 0
if p == 0:
    s = 0
else:
    s = 1
for i in range(s, one + 1, 2):
    ans += 2 ** zero * scipy.misc.comb(one, i, exact=True)

print(ans)

Buggy submission (verdict: Runtime Error):
import collections, scipy.special 
n, p = map(int, input().split())
a = list(map(int, input().split()))

for i in range(n):
    a[i] %= 2
c = collections.Counter(a)
zero = c[0]
one = c[1]
ans = 0
if p == 0:
    s = 0
else:
    s = 1
for i in range(s, one + 1, 2):
    ans += 2 ** zero * scipy.special.comb(one, i, exact=True)

print(ans)

Buggy submission (verdict: Runtime Error):
import collections, scipy.special 
n, p = map(int, input().split())
a = list(map(int, input().split()))

for i in range(n):
    a[i] %= 2
c = collections.Counter(a)
zero = c[0]
one = c[1]
ans = 0
if p == 0:
    s = 0
else:
    s = 1
for i in range(s, one, 2):
    ans += 2 ** zero * scipy.special.comb(one, i, exact=True)

print(ans)
Problem p03695 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
mapa = {1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0}
el = 0
for i in range(n):
    if a[i] < 400:
        mapa[1] += 1
    elif a[i] < 800:
        mapa[2] += 1
    elif a[i] < 1200:
        mapa[3] += 1
    elif a[i] < 1600:
        mapa[4] += 1
    elif a[i] < 2000:
        mapa[5] += 1
    elif a[i] < 2400:
        mapa[6] += 1
    elif a[i] < 2800:
        mapa[7] += 1
    elif a[i] < 3200:
        mapa[8] += 1
    else:
        el += 1
count = 0
for i in mapa:
    if mapa[i] > 0:
        count += 1
if count > 0:
    print(str(count) + ' ' + str(count + el))
else:
    print('1 ' + str(el))

Buggy submission (verdict: Runtime Error):
for i in range(n):
    if a[i] < 400:
        mapa[1] += 1
    elif a[i] < 800:
        mapa[2] += 1
    elif a[i] < 1200:
        mapa[3] += 1
    elif a[i] < 1600:
        mapa[4] += 1
    elif a[i] < 2000:
        mapa[5] += 1
    elif a[i] < 2400:
        mapa[6] += 1
    elif a[i] < 2800:
        mapa[7] += 1
    elif a[i] < 3200:
        mapa[8] += 1
    else:
        el += 1
count = 0
for i in mapa:
    if mapa[i] > 0:
        count += 1
if count > 0:
    print(str(count) + ' ' + str(count + el))
else:
    print('1 ' + str(el))
Problem p03739 (python)

Fixed submission:

def culc(a, plus):
    sum = 0
    ans = 0
    for i in range(len(a)):
        sum += a[i]
        if plus:
            if sum <= 0:
                ans += abs(sum) + 1
                sum = 1
        else:
            if sum >= 0:
                ans += abs(sum) + 1
                sum = -1
        plus = not(plus)
    return ans

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

plus = None
if a[0] >= 0:
    plus = True
else:
    plus = False

ans1 = culc(a, plus)
ans2 = culc(a, not(plus))

print(min(ans1, ans2))

Buggy submission (verdict: Runtime Error):

def culc(a, sum, plus, ans):
    for i in range(1, n):
        plus = not(plus)
        sum += a[i]
        if plus:
            if sum <= 0:
                ans += abs(sum) + 1
                sum = 1
        else:
            if sum >= 0:
                ans += abs(sum) + 1
                sum = -1
    return ans

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

plus = None
if a[0] > 0:
    plus = True
else:
    plus = False

ans1 = culc(a, a[0], plus, 0)

a[0] = a[0] // abs(a[0]) * -1

ans2 = abs(a[0]) + 1
ans2 = culc(a, a[0], not(plus), abs(a[0]) + 1)

print(min(ans1, ans2))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
sum = a[0]
plus = None
if a[0] > 0:
    plus = True
else:
    plus = False

ans1 = 0
for i in range(1, n):
    plus = not(plus)
    sum += a[i]
    if plus:
        if sum <= 0:
            ans1 += abs(sum) + 1
            sum = 1
    else:
        if sum >= 0:
            ans1 +=  abs(sum) + 1
            sum = -1

sum = 0
a[0] = a[0] // abs(a[0]) * -1
if a[0] > 0:
    plus = True
else:
    plus = False

ans2 = abs(a[0]) + 1
for i in range(1, n):
    plus = not(plus)
    sum += a[i]
    if plus:
        if sum <= 0:
            ans2 += abs(sum) + 1
            sum = 1
    else:
        if sum >= 0:
            ans2 +=  abs(sum) + 1
            sum = -1

print(min(ans1, ans2))