Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def add_edge(node, adj_lst, adj_rev, s1, s2):
  ind = 0
  max_len = min(len(s1), len(s2))
  while ind < max_len and s1[ind] == s2[ind]:
    ind += 1
  if ind == max_len:
    if max_len < len(s1):
      return True
    return False
  c1 = ord(s1[ind]) - ord("a")
  c2 = ord(s2[ind]) - ord("a")
  adj_lst[c1].add(c2)
  adj_rev[c2].add(c1)
  node.add(c1)
  node.add(c2)
  return False
def main():
  while True:
    n = int(input())
    if n == 0:
      break
    
    lst = [input() for _ in range(n)]
    node = set()
    adj_lst = [set() for _ in range(26)]
    adj_rev = [set() for _ in range(26)]
    blank_flag = False
    for i in range(n):
      for j in range(i + 1, n):
        blank_flag = blank_flag or add_edge(node, adj_lst, adj_rev, lst[i], lst[j])
    
    L = []
    visited = [False] * 26
    cycle_flag = False
  
    def visit(n):
      global cycle_flag
      if cycle_flag: return
      if visited[n] == 2:
        cycle_flag = True
      elif visited[n] == 0:
        visited[n] = 2
        for to in adj_lst[n]:
          visit(to)
        visited[n] = 1
        L.append(n)
    
    L = []
    for n in node:
      visit(n)
    if cycle_flag or blank_flag:
      print("no")
    else:
      print("yes")

main()


Fixed submission:
def add_edge(node, adj_lst, s1, s2):
  ind = 0
  max_len = min(len(s1), len(s2))
  while ind < max_len and s1[ind] == s2[ind]:
    ind += 1
  if ind == max_len:
    return max_len < len(s1)

  c1 = ord(s1[ind]) - ord("a")
  c2 = ord(s2[ind]) - ord("a")
  adj_lst[c1].add(c2)
  node.add(c1)
  node.add(c2)
  return False

def visit(n, visited, adj_lst):
  ret = False
  if visited[n] == 2:
    return True
  elif visited[n] == 0:
    visited[n] = 2
    for to in adj_lst[n]:
      ret = ret or visit(to, visited, adj_lst)
    visited[n] = 1
  return ret
 
def main():
  while True:
    n = int(input())
    if n == 0:
      break
    
    lst = [input() for _ in range(n)]
    node = set()
    adj_lst = [set() for _ in range(26)]
    blank_flag = False
    for i in range(n):
      for j in range(i + 1, n):
        blank_flag = blank_flag or add_edge(node, adj_lst, lst[i], lst[j])
    if blank_flag:
      print("no")
      continue
    
    visited = [0] * 26
    cycle_flag = False
  
    for n in node:
      cycle_flag = cycle_flag or visit(n, visited, adj_lst)
    if cycle_flag:
      print("no")
    else:
      print("yes")

main()
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
end = "ABC"
while True:
  if s == end:
    print("Yes")
    break
  s = s.replace("ABC", "X")
  if ("A" in s) + ("B" in s) + ("C" in s) != 2:
    print("No")
    break

  for c in "ABC":
    if c not in s:
      s = s.replace("X", c)
      break


Fixed submission:
s = input()
end = "ABC"
while True:
  if s == end:
    print("Yes")
    break
  s = s.replace(end, "X")
  if ("X" not in s) or sum((c in s for c in end)) != 2:
    print("No")
    break
  for c in end:
    if c not in s:
      s = s.replace("X", c)
      break
Buggy python submission (verdict: Time Limit Exceeded):
n, w = map(int, input().split())

value = []
weight = []
num = []

for _ in range(n):
  vi, wi, ni = map(int, input().split())
  value.append(vi)
  weight.append(wi)
  num.append(ni)

def to_digit(x):
  acc = 1
  ret = [0]
  while x >= acc:
    ret.append(acc)
    x -= acc
    acc *= 2
  if x:
    ret.append(x)
  return ret

num = list(map(to_digit, num))

dp = [0 for _ in range(w + 1)]
for i in range(n):
  vi = value[i]
  wi = weight[i]
  numsi = num[i]
  for k in numsi:
    for j in range(w, -1, -1):
      if j >= wi * k:
        dp[j] = max(dp[j], dp[j - wi * k] + vi * k)

print(dp[w])


Fixed submission:
def main():
  n, w = map(int, input().split())
  
  value = []
  weight = []
  num = []
  
  for _ in range(n):
    vi, wi, ni = map(int, input().split())
    value.append(vi)
    weight.append(wi)
    num.append(ni)
  
  def summary(x):
    acc = 1
    ret = [0]
    while x >= acc:
      ret.append(acc)
      x -= acc
      acc *= 2
    if x:
      ret.append(x)
    return ret
  
  num = list(map(summary, num))
  
  dp = [0 for _ in range(w + 1)]
  for i in range(n):
    vi = value[i]
    wi = weight[i]
    numsi = num[i]
    for k in numsi:
      wik = wi * k
      vik = vi * k
      for j in range(w, wik - 1, -1):
        pre = dp[j - wik] + vik
        if dp[j] < pre:
          dp[j] = pre
  
  print(dp[w])

main()
Buggy python submission (verdict: Runtime Error):

INF = 10 ** 20

v_num, e_num, r = map(int, input().split())
dist_lst = [INF for _ in range(v_num)]
edges_lst = [[] for _ in range(e_num)]
negative_cycle_flag = False

for _ in range(e_num):
  s, t, dist = map(int, input().split())
  edges_lst[s].append((dist, t))

dist_lst[r] = 0

for _ in range(v_num):
  for v in range(v_num):
    if dist_lst[v] != INF:
      for dist, to in edges_lst[v]:
        if dist_lst[v] + dist < dist_lst[to]:
          dist_lst[to] = dist_lst[v] + dist

for v in range(v_num):
  if dist_lst[v] != INF:
    for dist, to in edges_lst[v]:
      if dist_lst[v] + dist < dist_lst[to]:
        negative_cycle_flag = True
        break
    if negative_cycle_flag:
      break

if negative_cycle_flag:
  print("NEGATIVE CYCLE")
else:
  for dist in dist_lst:
    if dist == INF:
      print("INF")
    else:
      print(dist)


Fixed submission:
"""
BellmanFord
"""

INF = 10 ** 20

v_num, e_num, r = map(int, input().split())
dist_lst = [INF for _ in range(v_num)]
edges_lst = [[] for _ in range(e_num)]
negative_cycle_flag = False

for _ in range(e_num):
  s, t, dist = map(int, input().split())
  edges_lst[s].append((dist, t))

dist_lst[r] = 0

if e_num != 0:
  for _ in range(v_num):
    for v in range(v_num):
      if dist_lst[v] != INF:
        for dist, to in edges_lst[v]:
          if dist_lst[v] + dist < dist_lst[to]:
            dist_lst[to] = dist_lst[v] + dist
  
  for v in range(v_num):
    if dist_lst[v] != INF:
      for dist, to in edges_lst[v]:
        if dist_lst[v] + dist < dist_lst[to]:
          negative_cycle_flag = True
          break
      if negative_cycle_flag:
        break

if negative_cycle_flag:
  print("NEGATIVE CYCLE")
else:
  for dist in dist_lst:
    if dist == INF:
      print("INF")
    else:
      print(dist)
Buggy python submission (verdict: Runtime Error):
"""
強連結成分分解
"""


def dfs(v, visited, edges, order):
  visited[v] = True
  for to in edges[v]:
    if not visited[to]:
      dfs(to, visited, edges, order)
  order.append(v)

def search_strongly_connection(v, visited, reverse_edges, parent):
  visited[v] = True
  for to in reverse_edges[v]:
    if not visited[to]:
      parent[to] = v
      search_strongly_connection(to, visited, reverse_edges, parent)

def find(parent, x):
  if parent[x] == x:
    return x
  tmp = find(parent, parent[x])
  parent[x] = tmp
  return tmp

v_num , e_num = map(int, input().split())
edges = [[] for _ in range(v_num)]
reverse_edges = [[] for _ in range(v_num)]
for _ in range(e_num):
  s, t = map(int, input().split())
  edges[s].append(t)
  reverse_edges[t].append(s)


order = []
visited = [False] * v_num
for v in range(v_num):
  if not visited[v]:
    dfs(v, visited, edges, order)
order.reverse()


visited = [False] * v_num
parent = [i for i in range(v_num)]
for v in order:
  if not visited[v]:
    search_strongly_connection(v, visited, reverse_edges, parent)

q_num = int(input())
for _ in range(q_num):
  u, v = map(int, input().split())
  if find(parent, u) == find(parent, v):
    print(1)
  else:
    print(0)


Fixed submission:
"""
強連結成分分解
"""

import sys

sys.setrecursionlimit(1000000)

def dfs(v, visited, edges, order):
  visited[v] = True
  for to in edges[v]:
    if not visited[to]:
      dfs(to, visited, edges, order)
  order.append(v)

def search_strongly_connection(v, visited, reverse_edges, parent, num):
  visited[v] = True
  for to in reverse_edges[v]:
    if not visited[to]:
      parent[to] = num
      search_strongly_connection(to, visited, reverse_edges, parent, num)

def main():
  v_num , e_num = map(int, input().split())
  edges = [[] for _ in range(v_num)]
  reverse_edges = [[] for _ in range(v_num)]
  for _ in range(e_num):
    s, t = map(int, input().split())
    edges[s].append(t)
    reverse_edges[t].append(s)
  
  
  order = []
  visited = [False] * v_num
  for v in range(v_num):
    if not visited[v]:
      dfs(v, visited, edges, order)
  order.reverse()
  
  
  visited = [False] * v_num
  parent = [i for i in range(v_num)]
  for v in order:
    if not visited[v]:
      search_strongly_connection(v, visited, reverse_edges, parent, v)
  
  q_num = int(input())
  for _ in range(q_num):
    u, v = map(int, input().split())
    print(1 if parent[u] == parent[v] else 0)

main()
Buggy python submission (verdict: Runtime Error):
from collections import deque

INF = 10 ** 20

V, E = map(int, input().split())
net = [[0] * V for _ in range(V)]
for _ in range(E):
  u, v, c = map(int, input().split())
  net[u][v] = c

start = 0
goal  = V - 1
def check_net(node, path, capacity):
  for i in range(V):
    cap = net[node][i]
    if cap != 0:
      if i == goal:
        return (path + [i], min(cap, capacity))
      else:
        return check_net(i, path + [i], min(cap, capacity))

  else:
    return ([], 0)

def update_net(path, capacity):
  for fromi, toi in zip(range(len(path) - 1), range(1, len(path))):
    fr, to = path[fromi], path[toi]
    net[fr][to] -= capacity
    net[to][fr] += capacity

i = 0
while True:
  path, cap = check_net(start, [], INF)
  if path == []:
    break
  update_net(path, cap)

print(sum(net[start]))


Fixed submission:
from collections import deque

class Edge:
    def __init__(self, fromNode, toNode, cap, rev=None):
        self.fromNode = fromNode
        self.toNode = toNode
        self.cap = cap
        self.rev = rev

class MaxFlow:
    def __init__(self, V):
        self.v = V
        self.edges = [[] for _ in range(V)]

    def addEdge(self, fromNode, toNode, cap):
        forEdge = Edge(fromNode, toNode, cap)
        backEdge = Edge(toNode, fromNode, 0)
        forEdge.rev = backEdge
        backEdge.rev = forEdge
        self.edges[fromNode].append(forEdge)
        self.edges[toNode].append(backEdge)
    
    def bfs(self, source, sink):
        self.level = [None] * self.v
        self.level[source] = 0
        que = deque()
        que.append(source)
        while que:
            node = que.popleft()
            newLevel = self.level[node] + 1
            for edge in self.edges[node]:
                if edge.cap and self.level[edge.toNode] is None:
                    self.level[edge.toNode] = newLevel
                    que.append(edge.toNode)

        return self.level[sink] is not None

    def dfs(self, node, sink, f):
        if node == sink: return f

        for edge in self.edges[node]:
            if edge.cap and self.level[edge.fromNode] < self.level[edge.toNode]:
                newFlow = self.dfs(edge.toNode, sink, min(f, edge.cap))
                if newFlow:
                    edge.cap -= newFlow
                    edge.rev.cap += newFlow
                    return newFlow

        return 0
    
    def run(self, source, sink):
        flow = 0
        INF = 10 ** 10
        while self.bfs(source, sink):
            addFlow = INF
            while addFlow:
                addFlow = self.dfs(source, sink, INF)
                flow += addFlow

        return flow

V, E = map(int, input().split())
net = MaxFlow(V)
for _ in range(E):
    u, v, c = map(int, input().split())
    net.addEdge(u, v, c)
print(net.run(0, V - 1))
Buggy python submission (verdict: Runtime Error):
while True:
    a,b = map(int,input().split())
    print (len(str(a+b)))

Fixed submission:
while True:
    try:
        a,b = map(int,input().split())
        print (len(str(a+b)))
    except EOFError:
        break

Buggy python submission (verdict: Runtime Error):
while True:
    a,b = map(int,input().split())
        print (len(str(a+b)))
    except EOFError:
        break

Fixed submission:
while True:
    try:
        a,b = map(int,input().split())
        print (len(str(a+b)))
    except EOFError:
        break
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split(" "))

if a==b and a==c:
	print(1)
	ptn = 1

if a==b and a!=c:
	print(1)
	ptn=2

cnt = 0

for i in range(a,b):
	if c%i == 0:
		cnt += 1

if ptn != 1 and ptn != 2:
	print(cnt)

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

ptn = 0

if a==b and a==c:
	print(1)
	ptn = 1

if a==b and a!=c:
	if a < c:
		print(1)
		ptn=2
	else:
		print(0)
		ptn=2

cnt = 0

for i in range(a,b+1):
	if c%i == 0:
		cnt += 1

if ptn != 1 and ptn != 2:
	print(cnt)
Buggy python submission (verdict: Runtime Error):
import math
r = int(input())
print(r**2*math.pi," ",r*2*math.pi)

Fixed submission:
import math
r = float(input())
print(r**2*math.pi,r*2*math.pi)

Buggy python submission (verdict: Runtime Error):
import math
r = int(input())
print(r**2*math.pi,r*2*math.pi)

Fixed submission:
import math
r = float(input())
print(r**2*math.pi,r*2*math.pi)

Buggy python submission (verdict: Runtime Error):
import math
r = int(input())
print(r**2*math.pi,r*2*math.pi)

Fixed submission:
import math
r = float(input())
print(r**2*math.pi,r*2*math.pi)
Buggy python submission (verdict: Runtime Error):
M = 50100
p = [1]*M; p[0],p[1]=0,0;
pm = [0]*M; pM = [0]*M;
for i in range(2,M):
    if p[i]:
        for j in range(i*i,M,i): p[j] = 0
num = -1
for i in range(1,M):
    pm[i] = num
    if p[i]: num = i
num = -1
for i in range(M-1,2,-1):
    pM[i] = num
    if p[i]: num = i
while 1:
    n = input()
    if n==0: break
    print pm[n],pM[n]

Fixed submission:
M = 50100
p = [1]*M; p[0],p[1]=0,0;
pm = [0]*M; pM = [0]*M;
for i in range(2,M):
    if p[i]:
        for j in range(i*i,M,i): p[j] = 0
num = -1
for i in range(1,M):
    pm[i] = num
    if p[i]: num = i
num = -1
for i in range(M-1,2,-1):
    pM[i] = num
    if p[i]: num = i
while 1:
    try:
        n = input()
        print pm[n],pM[n]
    except EOFError:
        break
Buggy python submission (verdict: Runtime Error):
s = [0]
M = 10001
p = [1]*M
S = 0
for i in xrange(2,M):
    if p[i]:
        for j in xrange(i*i,M,i):
            p[j] = 0
        S += i; s.append(S)
while 1:
    n = input()
    if n==0: break
    print s[n]

Fixed submission:
s = [0]
M = 104850
p = [1]*M
S = 0
for i in range(2,M):
    if p[i]:
        for j in range(i*i,M,i):
            p[j] = 0
        S += i; s.append(S)
while 1:
    n = input()
    if n==0: break
    print s[n]
Buggy python submission (verdict: Runtime Error):
dx, dy = [-1, 0, 1, 0], [0, -1, 0, 1]
while True:
    ans = 0
    try:
        m = ['0'*14] + ['0'+raw_input()+'0' for i in xrange(12)] + ['0'*14]
        f = [[False for i in xrange(14)] for j in xrange(14)]
        for y in xrange(1, 13):
            for x in xrange(1, 13):
                if m[y][x]=='1' and f[y][x]==False:
                    q = [[x, y]]
                    f[y][x] = True
                    while len(q)>0:
                        px, py = q.pop(0)
                        for k in xrange(4):
                            nx = px + dx[k]; ny = py + dy[k];
                            if m[ny][nx]=='1' and f[ny][nx]==False:
                                f[ny][nx] = True
                                q.append([nx, ny])
                    ans += 1
        print ans
    except EOFError:
        break

Fixed submission:
dx, dy = [-1, 0, 1, 0], [0, -1, 0, 1]
while True:
    ans = 0
    try:
        m = ['0'*14] + ['0'+raw_input()+'0' for i in xrange(12)] + ['0'*14]
        f = [[False for i in xrange(14)] for j in xrange(14)]
        for y in xrange(1, 13):
            for x in xrange(1, 13):
                if m[y][x]=='1' and f[y][x]==False:
                    q = [[x, y]]
                    f[y][x] = True
                    while len(q)>0:
                        px, py = q.pop(0)
                        for k in xrange(4):
                            nx = px + dx[k]; ny = py + dy[k];
                            if m[ny][nx]=='1' and f[ny][nx]==False:
                                f[ny][nx] = True
                                q.append([nx, ny])
                    ans += 1
        print ans
        raw_input()
    except EOFError:
        break
Buggy python submission (verdict: Time Limit Exceeded):
def dfs(p, c, s):
    if c==n:
        return not s
    if p==-1:
        return 0
    if memo[s][p][c] != -1:
        return memo[s][p][c]
    ret = 0
    for i in xrange(min(p, s), -1, -1):
        ret += dfs(i-1, c+1, s-i)
    memo[s][p][c] = ret
    return ret

while 1:
    n, s = map(int, raw_input().split())
    if n==0:
        break
    memo = [[[-1]*(n+1) for i in xrange(101)] for j in xrange(s+1)]
    print dfs(min(s, 100), 0, s)

Fixed submission:
dp = [[0]*(1001) for _ in xrange(10)]
dp[0][0] = 1
for i in xrange(101):
    si1 = 1001-i
    for k in xrange(9, 0, -1):
        dp_k = dp[k]; dp_k1 = dp[k-1]
        for j in xrange(si1):
            dp_k[i+j] += dp_k1[j]
while 1:
    n, s = map(int, raw_input().split())
    if n==0:
        exit(0)
    print dp[n][s]

Buggy python submission (verdict: Runtime Error):
memo = [[[-1 for i in xrange(101)] for j in xrange(10)] for k in xrange(1001)]
def dfs(rest, now, cnt):
    if rest==0 and now==0:
        return 1
    if now==0 or cnt==-1:
        return 0
    if memo[rest][now][cnt]!=-1:
        return memo[rest][now][cnt]
    memo[rest][now][cnt] = 0
    for i in xrange(min(cnt, rest), -1, -1):
        memo[rest][now][cnt] += dfs(rest-i, now-1, i-1)
    return memo[rest][now][cnt]
while True:
    n, s = map(int, raw_input().split())
    print dfs(s, n, 100)

Fixed submission:
dp = [[0]*(1001) for _ in xrange(10)]
dp[0][0] = 1
for i in xrange(101):
    si1 = 1001-i
    for k in xrange(9, 0, -1):
        dp_k = dp[k]; dp_k1 = dp[k-1]
        for j in xrange(si1):
            dp_k[i+j] += dp_k1[j]
while 1:
    n, s = map(int, raw_input().split())
    if n==0:
        exit(0)
    print dp[n][s]
Buggy python submission (verdict: Runtime Error):
class SegmentTree:
    def __init__(self, n):
        n_ = 1
        while n_ < n: n_ *= 2
        self.n = n_
        self.data = [[0, -n_] for i in xrange(2*n_)]

    def add(self, k, a):
        idx = k + (self.n-1)
        data = self.data
        data[idx] = [data[idx][0] + a, -k]
        print data, idx, data[idx]
        while idx:
            idx = (idx - 1) / 2
            data[idx] = max(data[2*idx+1], data[2*idx+2])
            print idx, data[idx]

    def get(self):
        return self.data[0]

inputs = lambda: map(int, raw_input().split())
n, q = inputs()
st = SegmentTree(n)
for t in xrange(q):
    a, v = inputs()
    st.add(a, v)

    p, q = st.get()
    print -q, p

Fixed submission:
from heapq import heappush, heappop
inputs = lambda: map(int, raw_input().split())
n, q = inputs()
n += 1
que = [(0, 1, -1)]
data = [0] * n
T = [-1] * n
for t in xrange(q):
    a, v = inputs()
    data[a] += v
    T[a] = t

    heappush(que, (-data[a], a, t))
    v, k, p = que[0]
    while T[k]!=p:
        heappop(que)
        v, k, p = que[0]
    print k, -v

Buggy python submission (verdict: Runtime Error):
class SegmentTree:
    def __init__(self, n):
        n_ = 1
        while n_ < n: n_ *= 2
        self.n = n_
        self.data = [(0, -n_-1)] * (2*n_)

    def add(self, k, a):
        idx = k + (self.n-1)
        data = self.data
        data[idx] = (data[idx][0] + a, -k)
        while idx:
            idx = (idx - 1) / 2
            data[idx] = max(data[2*idx+1], data[2*idx+2])

    def get(self):
        return self.data[0]

inputs = lambda: map(int, raw_input().split())
n, q = inputs()
st = SegmentTree(n)
for t in xrange(q):
    a, v = inputs()
    st.add(a, v)

    p, q = st.get()
    print -q, p

Fixed submission:
from heapq import heappush, heappop
inputs = lambda: map(int, raw_input().split())
n, q = inputs()
n += 1
que = [(0, 1, -1)]
data = [0] * n
T = [-1] * n
for t in xrange(q):
    a, v = inputs()
    data[a] += v
    T[a] = t

    heappush(que, (-data[a], a, t))
    v, k, p = que[0]
    while T[k]!=p:
        heappop(que)
        v, k, p = que[0]
    print k, -v
Buggy python submission (verdict: Runtime Error):
def solve(A, b):
    for i in xrange(3):
        if A[i][i] == 0.0:
            for j in xrange(i+1, 3):
                if A[j][i]!=0.0:
                    A[i], A[j] = A[j], A[i]
                    b[i], b[j] = b[j], b[i]
        for j in xrange(3):
            if i==j:
                continue
            a = A[j][i] / A[i][i]
            for k in xrange(3):
                A[j][k] -= a * A[i][k]
            b[j] -= a * b[i]
    for i in xrange(3):
        b[i] /= A[i][i]
        A[i][i] /= A[i][i]

u = map(float, raw_input().split())
e = map(float, raw_input().split())
o = map(float, raw_input().split())
p = map(float, raw_input().split())
q = map(float, raw_input().split())
A = [[p[i]-o[i], q[i]-o[i], e[i]-u[i]] for i in xrange(3)]
b = [e[i] - o[i] for i in xrange(3)]
solve(A, b)
s, t, x = b
j = lambda x: -0.0000001 < x < 1.0000001
if j(s) and j(t) and j(s+t) and j(x):
    print "MISS"
else:
    print "HIT"

Fixed submission:
def solve(A, b):
    for i in xrange(3):
        if A[i][i] == 0.0:
            for j in xrange(i+1, 3):
                if A[j][i]!=0.0:
                    A[i], A[j] = A[j], A[i]
                    b[i], b[j] = b[j], b[i]
                    break
        for j in xrange(3):
            if i==j:
                continue
            a = A[j][i] / A[i][i]
            for k in xrange(3):
                A[j][k] -= a * A[i][k]
            b[j] -= a * b[i]
    for i in xrange(3):
        b[i] /= A[i][i]
        A[i][i] = 1.0

u = map(float, raw_input().split())
e = map(float, raw_input().split())
o = map(float, raw_input().split())
p = map(float, raw_input().split())
q = map(float, raw_input().split())

n = [(p[i-2]-o[i-2])*(q[i-1]-o[i-1])-(p[i-1]-o[i-1])*(q[i-2]-o[i-2]) for i in xrange(3)]
v = [e[i]-u[i] for i in xrange(3)]
if sum(n[i]*v[i] for i in xrange(3))==0.0:
    print "HIT"
    exit(0)

A = [[p[i]-o[i], q[i]-o[i], e[i]-u[i]] for i in xrange(3)]
b = [e[i] - o[i] for i in xrange(3)]
solve(A, b)
s, t, x = b
j = lambda x: -0.0000001 < x < 1.0000001
if j(s) and j(t) and j(s+t) and j(x):
    print "MISS"
else:
    print "HIT"
Buggy python submission (verdict: Runtime Error):
import sys
for s in sys.stdin.readlines():
    n = s.zfill(5)
    for i in xrange(2):
        print "".join(["*" if int(n[j])-5*i in range(5) else " " for j in xrange(5)])
    print "="*5
    for i in xrange(5):
        print "".join([" " if (int(n[j])%5)==i else "*" for j in xrange(5)])

Fixed submission:
import sys
c = False
for s in sys.stdin.readlines():
    n = s.strip().zfill(5)
    if c: print
    c = True
    for i in xrange(2):
        print "".join(["*" if int(n[j])-5*i in range(5) else " " for j in xrange(5)])
    print "="*5
    for i in xrange(5):
        print "".join([" " if (int(n[j])%5)==i else "*" for j in xrange(5)])
Buggy python submission (verdict: Runtime Error):
bus = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1, 0]
for i in xrange(input()):
    s, t = map(int, raw_input().split())
    if s>5:
        print " ".join(map(str, bus[s:bus.index(t, s)+1]))
    else:
        if s<t:
            print " ".join(map(str, range(s, t+1)))
        else:
            print " ".join(map(str, xrange(s, t-1, -1)))
            

Fixed submission:
bus = "0123456789543210123456789"
rbus = "543210"
for i in xrange(input()):
    s, t = raw_input().split()
    if t<s<'6':
        left = rbus.find(s, 0)
        right = rbus.find(t, left)
        print " ".join(rbus[left:right+1])
    else:
        left = bus.find(s, 0)
        right = bus.find(t, left)
        print " ".join(bus[left:right+1])
Buggy python submission (verdict: Time Limit Exceeded):
n = input()
C = [map(int, raw_input().split()) for i in xrange(n)]
memo = {(i, i): 0 for i in xrange(n)}
def calc(i, j):
    if (i, j) in memo:
        return memo[i, j]
    return min(calc(i, k) + calc(k+1, j) + C[i][0]*C[k][1]*C[k+1][0]*C[j][1] for k in xrange(i, j))
print calc(0, n-1)

Fixed submission:
n = input()
C = [map(int, raw_input().split()) for i in xrange(n)]
memo = {(i, i): 0 for i in xrange(n)}
def calc(i, j):
    if (i, j) in memo:
        return memo[i, j]
    res = memo[i, j] = min(calc(i, k) + calc(k+1, j) + C[i][0]*C[k][1]*C[k+1][0]*C[j][1] for k in xrange(i, j))
    return res
print calc(0, n-1)