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

Fixed submission:
from numpy import cumsum
N, K = map(int, input().split())
S = input()
*S, = map(int, list(S))
zeros = [0]
ones = [0]
if S[0] == 0:
    ones.append(0)
cnt = 1
now = S[0]
for i in range(1, N):
    if now == S[i]:
        cnt += 1
    else:
        if now == 0:
            zeros.append(cnt)
        else:
            ones.append(cnt)
        cnt = 1
        now = S[i]
if now == 0:
    zeros.append(cnt)
else:
    ones.append(cnt)
if S[-1] == 0:
    ones.append(0)

c_zero = cumsum(zeros)
c_one = cumsum(ones)
# print(zeros)
# print(c_zero)
# print(c_one)
if len(zeros) <= K:
    print(len(S))
else:
    ans = 0
    for i in range(0, len(zeros) - K):
        #print(i, K)
        #print(c_zero[i+K]-c_zero[i], c_one[i+K+1]-c_one[i])
        aaa = c_zero[i+K]-c_zero[i] + c_one[i+K+1]-c_one[i]
        #aaa = sum(zeros[i:i + K]) + sum(ones[i:i + K])+ones[i+K]
        # if (S[-1] != 0 and i == saigo)or (S[0] != 0 and i == 0):
        #aaa += ones[i+K]
        ans = max(aaa, ans)
    print(ans)

Buggy submission (verdict: Runtime Error):
from numpy import cumsum
N, K = map(int, input().split())
S = input()
*S, = map(int, list(S))
zeros = [0]
ones = [0]
if S[0] == 0:
    ones.append(0)
cnt = 1
now = S[0]
for i in range(1, N):
    if now == S[i]:
        cnt += 1
    else:
        if now == 0:
            zeros.append(cnt)
        else:
            ones.append(cnt)
        cnt = 1
        now = S[i]
if now == 0:
    zeros.append(cnt)
else:
    ones.append(cnt)
if S[-1] == 0:
    ones.append(0)

c_zero = cumsum(zeros)
c_one = cumsum(ones)
# print(zeros)
# print(c_zero)
# print(c_one)
if len(zeros) <= K:
    print(len(S))
else:
    ans = 0
    for i in range(0, len(zeros) - K):
        #print(i, K)
        #print(c_zero[i+K]-c_zero[i], c_one[i+K+1]-c_one[i])
        aaa = c_zero[i+K]-c_zero[i] + c_one[i+K+1]-c_one[i]
        #aaa = sum(zeros[i:i + K]) + sum(ones[i:i + K])+ones[i+K]
        # if (S[-1] != 0 and i == saigo)or (S[0] != 0 and i == 0):
        #aaa += ones[i+K]
        ans = max(aaa, ans)
    print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()
*S, = map(int, list(S))
zeros = []
ones = []
cnt = 1
now = S[0]
for i in range(1, N):
    if now == S[i]:
        cnt += 1
    else:
        if now == 0:
            zeros.append(cnt)
        else:
            ones.append(cnt)
        cnt = 1
        now = S[i]
if now == 0:
    zeros.append(cnt)
else:
    ones.append(cnt)

if len(zeros) <= K:
    print(len(S))
else:
    ans = 0
    for i in range(len(zeros) - K+1):
        aaa = sum(zeros[i:i + K]) + sum(ones[i:i + K])
        if S[0] == 1:
            aaa += ones[i+K]
        ans = max(aaa, ans)
    print(ans)
Problem p03078 (python)

Fixed submission:
def main():
    X, Y, Z, K = map(int, input().split())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()]

    AB = []
    ABappend = AB.append
    for i in range(X):
        for j in range(Y):
            ABappend(A[i] + B[j])
    AB.sort(reverse=True)
    ABC = []
    ABCappend = ABC.append
    for i in range(min(K, X*Y)):
        for j in range(Z):
            ABCappend(AB[i] + C[j])
    ABC.sort(reverse=True)
    print('\n'.join(map(str, ABC[:K])))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import heapq


def heappush_max(heap, item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap) - 1)


def heappop_max(heap):
    lastelt = heap.pop()
    if heap:
        return_item = heap[0]
        heap[0] = lastelt
        heapq._siftup_max(heap, 0)
        return return_item
    return lastelt


X, Y, Z, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)
ans = []
heap_queue = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            heappush_max(heap_queue, A[i] + B[j] + C[k])
for k in range(K):
    print(heappop_max(heap_queue))
Problem p03096 (python)

Fixed submission:
import sys
N = int(input())
C = [0]
n = N
for i in range(1, n + 1):
    c = int(sys.stdin.readline())
    if c == C[-1]:
        N -= 1
    else:
        C.append(c)
dp = [0] * (N + 2)
dp[0] = 1
dp[1] = 1
cumsum = [0] * (2 * (10 ** 5) + 2)
cumsum[C[1]] = 1
for i in range(2, N+1):
    dp[i] = dp[i - 1] + cumsum[C[i]]
    cumsum[C[i]] += dp[i-1]
    dp[i] %= (10 ** 9 + 7)
print(dp[N])

Buggy submission (verdict: Runtime Error):
import sys
N = int(input())
C = [0]
#c = [int(sys.stdin.readline()) for i in range(N)]
n = N
for i in range(1, n + 1):
    c = int(sys.stdin.readline())
    if c == C[-1]:
        N -= 1
    else:
        C.append(c)
#C = C+c
dp = [0] * (N + 2)
color = [[]for i in range((2*(10**4)+2))]
dp[0] = 1
dp[1] = 1
color[C[1]].append(1)
for i in range(2, N+1):
    dp[i] = dp[i - 1] + sum([dp[col - 1] for col in color[C[i]]])
    color[C[i]].append(i)
    dp[i] %= (10 ** 9 + 7)
# print(dp)
print(dp[N])
Problem p03125 (python)

Fixed submission:
from fractions import gcd
A, B = map(int, input().split())
if gcd(A, B) == A:
    print(A + B)
else:
    print(B-A)

Buggy submission (verdict: Runtime Error):
import math
A, B = map(int, input().split())
if math.gcd(A, B) == A:
    print(A + B)
else:
    print(B-A)
Problem p03138 (python)

Fixed submission:
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
max_bit = 40
dp = [[-1] * 2 for i in range(41)]  # dp[i][j] = 上からi bitまで、j smaller

dp[0][0] = 0
for d in range(max_bit):
    mask = 1 << (max_bit-d-1)

    # Aでもともとd bit目にbitが立っているものの個数
    num = len([1 for i in range(N) if A[i] & mask])
    #print([1 for i in range(N) if A[i] & mask])

    # Xのbit bit目を0,1にしたときのコスト
    cost0 = mask * num
    cost1 = mask * (N - num)
    # smaller -> smaller
    if dp[d][1] != -1:
        # 0でも1でもいい！
        dp[d + 1][1] = max(dp[d + 1][1], dp[d][1] + max(cost0, cost1))

    # exact -> smaller
    if dp[d][0] != -1:
        if K & mask:  # kのd桁目が1だったらXのd桁目は0にする
            dp[d + 1][1] = max(dp[d + 1][1], dp[d][0] + cost0)

    # exact -> exact
    if dp[d][0] != -1:
        if K & mask:
            dp[d + 1][0] = max(dp[d + 1][0], dp[d][0] + cost1)
        else:
            dp[d + 1][0] = max(dp[d + 1][0], dp[d][0] + cost0)

# print(dp)
print(max(dp[max_bit][0], dp[max_bit][1]))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

# print(math.log2(10**12))
sum = [0 for i in range(K)]

for x in range(K):
    y = [int(x / (2 ** i)) % 2 for i in range(40)]  # log2(10**12) < 40
    for n in range(N):
        for j in range(40):
            z = int(A[n] / (2 ** j)) % 2
            if (z > 0) ^ (y[j] > 0):
                sum[x] += 2 ** j
print(max(sum))
Problem p03206 (python)

Fixed submission:
D = int(input())
output = "Christmas"
while D < 25:
    output = output + " Eve"
    D += 1
print(output)

Buggy submission (verdict: Runtime Error):
N, X = map(int, input().split())
x = X
nums = [1]
p_count = [1]
for i in range(N):
    nums.append(2 * nums[-1] + 3)
    p_count.append(2 * p_count[-1] + 1)


def solve_p(N, X):
    if X <= 1:
        return 0
    elif N == 0:
        return 1
    else:
        if X == (nums[N]) // 2:
            return (p_count[N]+1) // 2
        elif X < nums[N] // 2:
            return solve_p(N - 1, X - 1)
        else:
            return p_count[N-1]+1+solve_p(N-1, X-(nums[N]+1)//2)


print(solve_p(N, X))
"""
ans = 0
for i, n in enumerate(nums[:-1]):
    if X == n:
        ans += p_count[i]
        break
    elif X > n // 2:
        X -= p_count[i]//2
        ans += p_count[i] // 2
    elif X == n // 2:
        ans += (p_count[i] + 1) // 2
        break
# print(ans)

burger = ["P"]
for i in range(N):
    burger.append(("B"+burger[i]+"P"+burger[i]+"B"))
print(burger)  # [N + 1])

print(burger[N])

print(burger[N][:x].count("P"))
"""
Problem p03282 (python)

Fixed submission:
S = input()
K = int(input())
for s in S:
    if int(s) == 1:
        K -= 1
        if K == 0:
            print(s)
            exit()
    else:
        print(s)
        exit()

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
for s in S:
  if int(s)==1:
	K-=1
    if K==0:
      print(s)
      exit()
  else:
    print(s)
    exit()
Problem p03284 (python)

Fixed submission:
N, K = map(int, input().split())
if N % K == 0:
    print(0)
else:
    print(1)

Buggy submission (verdict: Runtime Error):
N = int(input())
if N not in [1, 2, 3, 5, 6, 9, 10, 13, 17, 20]:
    print("Yes")
else:
    print("No")
Problem p03339 (python)

Fixed submission:
N = int(input())
S = input()
E_cost = S.count("E")
W_cost = 0
ans = N
for s in S:
    if s == "E":
        E_cost -= 1
    ans = min(ans, E_cost + W_cost)
    if s == "W":
        W_cost += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
S_list = list(S)
face = [-1, 1]
ans_index = N // 2
while ans_index != N - 1 and S[ans_index] == S[ans_index + face[S[ans_index] == "E"]]:
    ans_index += face[S[ans_index] == "E"]
# print(ans_index)
ans = 0
for i in range(len(S)):
    if i < ans_index and S[i] == "W":
        ans += 1
    elif ans_index == i:
        continue
    elif i > ans_index and S[i] == "E":
        ans += 1
print(ans)
Problem p03370 (python)

Fixed submission:
N, X = map(int, input().split())
m = [int(input()) for i in range(N)]
X -= sum(m)
ans = N + X//min(m)
print(ans)

Buggy submission (verdict: Runtime Error):
N, X = map(int, input().split())
m = list(map(int, open(0).read().split()))
X -= sum(m)
ans = N + X//min(m)
print(ans)
Problem p03469 (python)

Fixed submission:
S = input()
s = list(S)
s[3] = "8"
print(*s, sep="")

Buggy submission (verdict: Runtime Error):
N, Y = map(int, input().split())
for i in range(N+1):
    for j in range(N+1):
        if (N - i - j) * 10000 + i * 5000 + j * 1000 == Y:
            print(N - i - j, i, j)
            exit()
print(-1, -1, -1)
Problem p03565 (python)

Fixed submission:
S = input()
T = input()
for i in reversed(range(len(S) - len(T) + 1)):
    frag = True
    for j in range(len(T)):
        if S[i + j] == T[j] or S[i + j] == "?":
            continue
        else:
            frag = False
            break
    if frag:
        ans = S[:i] + T
        if i + len(T) < len(S):
            ans += S[i + len(T):]
        ans = ans.replace("?", "a")
        print(ans)
        exit()
print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    T=ST()
    N=len(S)
    M=len(T)
    ans = []
    for i in range(N-M+1)[::-1]:
        can = True
        for s,t in zip(S[i:],T):
            if s!=t and s!="?":
                can = False
        if can:
            for j,s in enumerate(S):
                if j<i:
                    if s=="?":
                        ans.append("a")
                    else:
                        ans.append(s)
                else:
                    ans.append(T[j-i])
            break
    if ans:
        print(*ans,sep="")
    else:
        print("UNRESTORABLE")
if __name__ == '__main__':
    main()
Problem p03693 (python)

Fixed submission:
print("YNEOS"[int(input().replace(" ",""))%4!=0::2])

Buggy submission (verdict: Runtime Error):
print("YNEOS"[int(input().replace(" ",""))%4!=0::2]
Problem p02606 (python)

Fixed submission:
l,r,d=map(int,input().split(" "))
c=0
for i in range(l,r+1,1):
    if i%d==0:
        c+=1
print(c)

Buggy submission (verdict: Runtime Error):
l,r,d=map(input().split(""))
c=0
for i in range(l,r+1,1):
  if i%d==0:
    c+=1
print(c)
Problem p02573 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
 
n, m = map(int, input().split())
 
root = [-1] * n
 
 
def r(x):
    if root[x] < 0:
        return x
    else:
        root[x] = r(root[x])
        return root[x]
 
 
def unite(x, y):
    x = r(x)
    y = r(y)
    if x == y:
        return
    root[x] += root[y]
    root[y] = x
 
 
def size(x):
    return -1 * root[r(x)]
 
 
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    unite(a, b)
 
ans = 0
for i in range(n):
    ans = max(ans, size(i))
 
print(ans)

Buggy submission (verdict: Runtime Error):

class UnionFind:
    def __init__(self, n):
        self.parent = [-1 for _ in range(n)]

    def find(self, s):
        if self.parent[s] < 0:
            return s
        self.parent[s] = self.find(self.parent[s])
        return self.parent[s]

    def union(self, a, b):
        a, b = self.find(a), self.find(b)
        if a == b:
            return
        self.parent[a] += self.parent[b]
        self.parent[b] = a

    def size(self, x):
        return -1 * self.parent[self.find(x)]

n, m = list(map(int, input().split()))
uf = UnionFind(n)
for i in range(m):
    a, b = list(map(int, input().split()))
    uf.union(a - 1, b - 1)
print(max([uf.size(i) for i in range(n)]))
Problem p02576 (python)

Fixed submission:
import sys
import math

def main(lines):
    line=lines.split()
    n = int(line[0])
    x = int(line[1])
    t = int(line[2])
    ans = math.ceil(n/x)*t
    print(ans)

if __name__ == '__main__':
    lines=input()
    main(lines)

Buggy submission (verdict: Runtime Error):
import sys
import math

def main(lines):
  line=lines.split()
  n = int(line[0])
  x = int(line[1])
  t = int(line[2])
  ans = math.ceil(n/x)*t
  print(ans)

if __name__ == '__main__':
    lines = []
    for l in sys.stdin:
        lines.append(l.rstrip('\r\n'))
    main(lines)

Buggy submission (verdict: Runtime Error):
import sys

def main(lines):
  line=lines[0]

if __name__ == '__main__':
    lines = []
    for l in sys.stdin
        lines.append(l.rstrip('\r\n'))
    main(lines)

Buggy submission (verdict: Runtime Error):
import sys

def main(lines):
  line=lines[0].split()
  n = int(line[0])
  x = int(line[1])
  t = int(line[2])
  ans = math.ceil(n/x)*t
  print(ans)

if __name__ == '__main__':
    lines = []
    for l in sys.stdin:
        lines.append(l.rstrip('\r\n'))
    main(lines)

Buggy submission (verdict: Runtime Error):
import sys

def main(lines):
  line=lines[0].split()
  n = int(line[0])
  x = int(line[1])
  t = int(line[2])
  ans = math.ceil(n/x)*t
  print(ans)

if __name__ == '__main__':
    lines = []
    for l in sys.stdin
        lines.append(l.rstrip('\r\n'))
    main(lines)

Buggy submission (verdict: Runtime Error):
import sys

def main(lines):
  line=lines[0].split()
  n = int(line[0])
  x = int(line[1])
  t = int(line[2])
  ans = math.ceil(n/x)*t
  print(ans)

if __name__ == '__main__'
    lines = []
    for l in sys.stdin
        lines.append(l.rstrip('rn'))
    main(lines)

Buggy submission (verdict: Runtime Error):
import sys

def main(lines):
  line = lines.split()
  n = int(line[0])
  x = int(line[1])
  t = int(line[2])
  ans = math.ceil(n/x)*t
  print(ans)
if __name__ == '__main__'
    lines = []
    for l in sys.stdin
        lines.append(l.rstrip('rn'))
    main(lines)
Problem p02768 (python)

Fixed submission:
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
 
n, a, b = na()
mod = 1000000007
 
def comb(n, r, mod):
    if n < 0 or r < 0 or r > n: return 0
    nu = 1
    de = 1
    for i in range(r):
        nu = nu * (n-i) % mod
        de = de * (i+1) % mod
    return nu * inv(de, mod) % mod
 
def inv(a, mod):
    b = mod
    p, q = 1, 0
    while b > 0:
        c = a//b
        d = a; a = b; b = d % b
        d = p; p = q; q = d-c*q
    return p+mod if p < 0 else p
 
print((pow(2, n, mod) - comb(n, a, mod) - comb(n, b, mod) - 1)%mod)

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

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

p = 10**9+7
r1 = 2 ** n - 1
r2 = cmb(n, a, p)
r3 = cmb(n, b, p)
print(r1-r2-r3)
Problem p02924 (python)

Fixed submission:
n = int(input())
 
print(int(((n-1) * n) // 2))

Buggy submission (verdict: Runtime Error):
 = int(input())
 
print(int(((n-1) * n) / 2))
Problem p02953 (python)

Fixed submission:
N = int(input())
Hs = list(map(int, input().split()))
 
prev = Hs[0]
flag = True
for i in range(1,len(Hs)):
    if Hs[i] <prev:
      flag = False
      break
    elif Hs[i] == prev:
      prev = Hs[i]
    else:
      prev = Hs[i]-1
if flag:
    print("Yes")
else:
    print("No")

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

prev = Hs[0]
flag = True
for i in range(1,len(Hs)):
    if Hs[i] <prev:
	flag = False
	break
    elif Hs[i] == prev:
	prev = Hs[i]
    else:
	prev = Hs[i]-1
if flag:
    print("Yes")
else:
    print("No")
Problem p03148 (python)

Fixed submission:
n, m = [int(i) for i in input().split()]
td = [[int(i) for i in input().split()] for n in range(n)]
td.sort(key=lambda x:-x[1])
memo = set()
a = []
for t, d in td:
  if t in memo:
    a.append((d, 0))
  else:
    a.append((d, 1))
  memo.add(t)
a = [(-x, x, d) for x, d in a]
import heapq
heapq.heapify(a)
val = 0
kind = 0
b = []
for _ in range(m):
  ele = heapq.heappop(a)
  val += ele[1]
  kind += ele[2]
  if ele[2] == 0:
    b.append(ele[1])
ans = val + kind ** 2
while (len(a) > 0 and len(b)>0):
  val -= b.pop()
  flag = False
  while(len(a) > 0):
    elem = heapq.heappop(a)
    if elem[2] == 1:
      flag = True
      break
  if not flag:
    break
  val += elem[1]
  kind += 1
  tmpans = val + kind ** 2
  if tmpans > ans:
    ans = tmpans
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
td = [[int(i) for i in input().split()] for n in range(n)]
td.sort(key=lambda x:-x[1])
memo = set()
a = []
for t, d in td:
  if t in memo:
    a.append((d, 0))
  else:
    a.append((d, 1))
  memo.add(t)
a = [(-x, x, d) for x, d in a]
import heapq
heapq.heapify(a)
val = 0
kind = 0
b = []
for _ in range(m):
  ele = heapq.heappop(a)
  val += ele[1]
  kind += ele[2]
  if ele[2] == 0:
    b.append(ele[1])
ans = val + kind ** 2
while (len(a) > 0):
  val -= b.pop()
  flag = False
  while(len(a) > 0):
    elem = heapq.heappop(a)
    if elem[2] == 1:
      flag = True
      break
  if not flag:
    break
  val += elem[1]
  kind += 1
  tmpans = val + kind ** 2
  if tmpans > ans:
    ans = tmpans
print(ans)
Problem p03244 (python)

Fixed submission:
from collections import defaultdict
n = int(input())
v = list(map(int, input().split()))
o = defaultdict(int)
e = defaultdict(int)
odd_num = 0
even_num = 0
for i, v_one in enumerate(v):
  if i % 2 == 1:
    o[v_one] += 1
    odd_num += 1
  else:
    e[v_one] += 1
    even_num += 1
sorted_o = sorted(o.items(), key=lambda x:-x[1])
sorted_e = sorted(e.items(), key=lambda x:-x[1])
if sorted_o[0][0] != sorted_e[0][0]:
  ans = odd_num - sorted_o[0][1] + even_num - sorted_e[0][1]
elif len(sorted_o) >= 2 and len(sorted_e) >= 2:
  ans1 = odd_num - sorted_o[1][1] + even_num - sorted_e[0][1]
  ans2 = odd_num - sorted_o[0][1] + even_num - sorted_e[1][1]
  ans = min(ans1, ans2)
elif len(sorted_o) >= 2:
  ans = sorted_o[0][1]
elif len(sorted_e) >=2:
  ans = sorted_e[0][1]
else:
  ans = odd_num
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
n = int(input())
v = list(map(int, input().split()))
o = defaultdict(int)
e = defaultdict(int)
odd_num = 0
even_num = 0
for i, v_one in enumerate(v):
  if i % 2 == 1:
    o[v_one] += 1
    odd_num += 1
  else:
    e[v_one] += 1
    even_num += 1
sorted_o = sorted(o.items(), key=lambda x:-x[1])
sorted_e = sorted(e.items(), key=lambda x:-x[1])
if sorted_o[0][0] != sorted_e[0][0]:
  ans = odd_num - sorted_o[0][1] + even_num - sorted_e[0][1]
else:
  ans1 = odd_num - sorted_o[1][1] + even_num - sorted_e[0][1]
  ans2 = odd_num - sorted_o[0][1] + even_num - sorted_e[1][1]
  ans = min(ans1, ans2)
print(ans)
Problem p03363 (python)

Fixed submission:
n = int(input())
A = list(map(int,input().split()))
S = [0] * (n + 1)

from collections import defaultdict
dic = defaultdict(int)
for i in range(len(A)):
  S[i+1] = S[i] + A[i]
for s in S:
  dic[s] += 1
from scipy.special import comb
ans = 0
for k, v in dic.items():
  if v > 1:
    ans += comb(v, 2, exact=True)

print(int(ans))

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(map(int,input().split()))
S = [0] * (n + 1)

from collections import defaultdict
dic = defaultdict(int)
for i in range(len(A)):
  S[i+1] = S[i] + A[i]
for s in S:
  dic[s] += 1
from scipy.special import comb
ans = 0
for k, v in dic.items():
  if v > 1:
    ans += comb(v, 2, exact=True)

print(int(ans))

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(map(int,input().split()))
S = [0] * (n + 1)

from collections import defaultdict
dic = defaultdict(int)
for i in range(len(A)):
  S[i+1] = S[i] + A[i]
for s in S:
  dic[s] += 1
from math import factorial
ans = 0
for k, v in dic.items():
  if v > 1:
    ans += factorial(v) / factorial(2) / factorial(v - 2)

print(int(ans))
Problem p03380 (python)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
maxA = max(A)
abs_min = 10**9
A.remove(maxA)
for a in A:
  if abs_min > abs(maxA/2 - a):
    abs_min = abs(maxA/2 - a)
    r = a
print(maxA, r)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))
maxA = max(A)
abs_min = 100000
for a in A:
  if abs_min > abs(maxA/2 - a):
    abs_min = abs(maxA/2 - a)
    r = a
print(maxA, r)
Problem p03475 (python)

Fixed submission:
# coding:utf-8                                                                                     

N = int(raw_input())
C = []
S = []
F = []

for i in range(N-1):
    c, s, f = map(int, raw_input().split())
    C.append(c)
    S.append(s)
    F.append(f)

res = []

for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        if S[j] >= t:
            t = 0
            t += S[j] + C[j]
        elif t % F[j] == 0:
            t += C[j]
        else:
            t = S[j] + F[j] * ((t - S[j]) / F[j]) + F[j] + C[j]
    print t

print 0

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

N = int(raw_input())
C = []
S = []
F = []

for i in range(N-1):
    c, s, f = map(int, raw_input().split())
    C.append(c)
    S.append(s)
    F.append(f)

res = []
T = []

for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        if S[j] >= t:
            t = 0
            t += S[j] + C[j]
        elif t % F[j] == 0:
            t += C[j]
        else:
            t = t + F[j] - (t - (S[j] + F[j] * ((t-S[j])/F[j]))) + C[j]
    T.append(t)

for t in T:
    print t
print 0