Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):

import sys
input = sys.stdin.readline
def solve():
  n = int(input())
  l = list(int(i) for i in input().split())
  l = sorted(l,reverse = True)
  ans = 0
  for i in range(n):
    for j in range(i+1,n):
      for k in range(j+1,n):
        a = l[i]
        b = l[j]
        c = l[k]
        if a< b+c and b< c+a and c < a+b:
          ans += 1
  print(ans)
  
solve()

Fixed submission:
import bisect
import sys
input = sys.stdin.readline
def solve():
  n = int(input())
  l = list(int(i) for i in input().split())
  l = sorted(l)
  ans = 0
  #print(l)
  for i in range(n):
    for j in range(i+1,n):
        a = l[i]
        b = l[j]
        c_max = bisect.bisect_left(l,a+b)
        if c_max <= j+1:
          continue
        else:
          ans += c_max-j-1
          #print(c_max-2)
        #print(c_max,i,j)

  print(ans)
  
solve()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input = sys.stdin.readline
def solve():
  n,m = (int(i) for i in input().split())
  a = [None]*(m+1)
  b = [None]*(m+1)
  takara = [0]*m
  for i in range(m):
    ta,tb = (int(i) for i in input().split())
    a[i] = ta
    b[i] = tb
    c = list(int(i) for i in input().split())
    for j in c:
      tmp = j-1
      takara[i] += 1<<tmp
  inf = float("Inf")
  dp = [[inf]*(2**n+1) for _ in range(m+1)]
  dp[0][0] = 0
  for i in range(m):
    for j in range(2**n):
      dp[i+1][j] = min(dp[i][j],dp[i+1][j])
      dp[i+1][j|takara[i]] = min(dp[i][j]+a[i],dp[i+1][j|takara[i]])
  if not dp[m][2**n-1] == inf:
    print(dp[m][2**n-1])
  else:
    print(-1)
solve()

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline
def solve():
  n,m = (int(i) for i in input().split())
  a = [None]*(m+1)
  b = [None]*(m+1)
  takara = [0]*m
  for i in range(m):
    ta,tb = (int(i) for i in input().split())
    a[i] = ta
    b[i] = tb
    c = list(int(i) for i in input().split())
    for j in c:
      tmp = j-1
      takara[i] += 1<<tmp
  inf = float("Inf")
  dp = [[inf]*(2**n+1) for _ in range(m+1)]
  dp[0][0] = 0
  for i in range(m):
    for j in range(2**n):
      dp[i+1][j] = min(dp[i][j],dp[i+1][j])
      dp[i+1][j|takara[i]] = min(dp[i][j]+a[i],dp[i+1][j|takara[i]])
  if not dp[m][2**n-1] == inf:
    print(dp[m][2**n-1])
  else:
    print(-1)
solve()
Buggy python submission (verdict: Time Limit Exceeded):
def z_algo(S):
    N = len(S)
    A = [0]*N
    i = 1; j = 0
    A[0] = l = len(S)
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A
def solve():
  n = int(input())
  s = input()
  ans = 0
  for i in range(n):
    a = z_algo(s[i:])
    for i in range(len(a)):
      if i > 0 and a[i] <= a[0]/2:
        ans = max(ans,a[i])
  print(ans)
solve()

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
def z_algo(S):
    N = len(S)
    A = [0]*N
    i = 1; j = 0
    A[0] = l = len(S)
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A
def solve():
  n = int(input())
  s = input()
  ans = 0
  for i in range(n):
    a = z_algo(s[i:])
    for j in range(i,n):
        ans = max(ans, min(j-i, a[j-i]))
  print(ans)
solve()
Buggy python submission (verdict: Runtime Error):
import collections
import sys
sys.setrecursionlimit(100000000)

from math import factorial
def ncr(n,r):
 if n>2:
  return factorial(n) / factorial(r) / factorial(n - r)
 else:
  return 1
def solve():
  n = int(input())
  query = []
  for i in range(n):
    a = sorted(input())
    query.append("".join(a))

  c = collections.Counter(query)
  ans = 0
  tmp = c.values()

  for i in tmp:
    if i >=2:
      ans += ncr(i,2)
  print(int(ans))
  
solve()
  
  

Fixed submission:
import collections
import sys
sys.setrecursionlimit(100000000)

from math import factorial
def ncr(n,r):
 if n==r:
  return 1
 elif n>2:
  return factorial(n) // factorial(r) // factorial(n - r)
 else:
  return 1
def solve():
  n = int(input())
  query = []
  for i in range(n):
    a = sorted(input())
    query.append("".join(a))

  c = collections.Counter(query)
  ans = 0
  tmp = list(c.values())

  for i in tmp:
    if i >=2:
      ans += ncr(i,2)
  print(int(ans))
solve()

Buggy python submission (verdict: Runtime Error):
import collections

from math import factorial
def ncr(n,r):
 if n>2:
  return factorial(n) / factorial(r) / factorial(n - r)
 else:
  return 1
def solve():
  n = int(input())
  query = []
  for i in range(n):
    a = sorted(input())
    query.append("".join(a))

  c = collections.Counter(query)
  ans = 0
  tmp = c.values()
  for i in tmp:
    if i >=2:
      ans += ncr(i,2)
  print(int(ans))
solve()
  
  

Fixed submission:
import collections
import sys
sys.setrecursionlimit(100000000)

from math import factorial
def ncr(n,r):
 if n==r:
  return 1
 elif n>2:
  return factorial(n) // factorial(r) // factorial(n - r)
 else:
  return 1
def solve():
  n = int(input())
  query = []
  for i in range(n):
    a = sorted(input())
    query.append("".join(a))

  c = collections.Counter(query)
  ans = 0
  tmp = list(c.values())

  for i in tmp:
    if i >=2:
      ans += ncr(i,2)
  print(int(ans))
solve()
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys
from collections import deque
sys.setrecursionlimit(100000000)

def solve():
  n,m = (int(i) for i in input().split())
  query = []
  for i in range(n):
    a,b = (int(i) for i in input().split())
    query.append((a,b))
  query = sorted(query,reverse = False)
  query2 = []
  for i in range(n):
    query2 += [query[i][0]]

  ans = 0
  judge = deque([])
  for i in range(m):
    left = bisect.bisect_left(query2,i+1)
    right = bisect.bisect_right(query2,i+1)

    judge += query[left:right]
    judge = deque(sorted(judge,reverse = True,key=lambda x: x[1]))
    if len(judge) != 0:
     a,b = judge.popleft()
     ans += b
  print(ans)
  
    
    
    
solve()
  
  

Fixed submission:
import bisect
import sys
from collections import deque
import heapq
sys.setrecursionlimit(100000000)

def solve():
  n,m = (int(i) for i in input().split())
  query = []
  for i in range(n):
    a,b = (int(i) for i in input().split())
    query.append((a,b))
  query = sorted(query,reverse = False)
  query2 = []
  for i in range(n):
    query2 += [query[i][0]]

  ans = 0
  judge = []
  for i in range(m):
    left = bisect.bisect_left(query2,i+1)
    right = bisect.bisect_right(query2,i+1)
    for j in range(left,right):
     b,a = (query[j])
     heapq.heappush(judge, [-a,b])
    #print(judge)
    if len(judge) != 0:
     b,a = heapq.heappop(judge)
     ans += -b
  print(ans)
solve()
Buggy python submission (verdict: Runtime Error):
def solve():
  l,r = (int(i) for i in input().split())
  mod = 2019
  l %= mod
  r %= mod
  ans = 10**15
  if l > r :
    print(0)
    exit()
  elif l == 0 or r == 0:
    print(0)
    exit()
  else:
    for i in range(l,r):
      for j in range(l+1,r+1):
        if i<j:
         ans = min(ans,(i*j)%mod)
  print(ans%mod)

solve()

Fixed submission:
from collections import deque
def solve():
  n = int(input())
  a = list(int(i) for i in input().split())
  x1 = 0
  for i in range(n):
    if i%2 == 0:
      x1  += a[i]
    else:
      x1  -= a[i]
  query = deque([x1])
  x = x1
  for i in range(n-1):
    tmp = a[i]-x//2
    tmp *= 2
    query.append(tmp)
    x  = tmp
  print(*query)
solve()
Buggy python submission (verdict: Runtime Error):
def solve():
  n = int(input())
  p = list(int(i) for i in input().split())
  ans = 0
  try:
    for i in range(n):
      if p[i-1]>p[i]>p[i+1]:
        ans += 1
      elif p[i-1]<p[i]<p[i+1]:
        ans += 1
  finally:
   print(ans)
solve()

Fixed submission:
def solve():
  n = int(input())
  p = list(int(i) for i in input().split())
  ans = 0
  for i in range(n-2):
   query = [p[i],p[i+1],p[i+2]]
   query.sort()
   if query[1] == p[i+1]:
    ans += 1
  print(ans)
solve()
Buggy python submission (verdict: Runtime Error):
from math import factorial
def P(n, r):
     mod = 10**9+7
     return (factorial(n)//factorial(n-r))%mod

def ncr(n, r):
     mod = 10**9+7
     return (P(n, r)//factorial(r))%mod

def solve():
  n,k = (int(i) for i in input().split())
  mod = 10**9+7
  blue = k
  red  = n-k
  blueplace = red+1
  
  for i in range(1,k+1):
    tmp = ncr(k-1,i-1)*ncr(blueplace,i)%mod
    print(tmp%mod)
solve()

Fixed submission:
def solve():
  n,k = (int(i) for i in input().split())
  mod = 10**9+7
  fact = [1]*(n+5)
  inv = [1]*(n+5)
  finv = [1]*(n+5)
  fact[0] = fact[1] = 1
  finv[0] = finv[1] = 1
  inv[1]  = 1
  for i in range(2,n+4):
   fact[i] = (fact[i-1]*i)%mod
   inv[i] = mod-inv[mod%i]*(mod//i)%mod
   finv[i]= finv[i-1]*inv[i]%mod

  
  blue = k
  red  = n-k
  blueplace = red+1
  
  for i in range(1,k+1):
    if (n-k+1)>= i:
     tmp = fact[n-k+1]*(finv[i]*finv[n-k+1-i]%mod)%mod
     tmp *= fact[k-1]*(finv[i-1]*finv[k-i]%mod)%mod
     print(tmp%mod)
    else:
      print(0)
solve()

Buggy python submission (verdict: Runtime Error):
from math import factorial
def ncr(n,r):
 if r <= 0:
  return 1
 if not n == r:
  return (factorial(n)) // factorial(r) // factorial(n - r)
 else:
    return 1

def solve():
  n,k = (int(i) for i in input().split())
  mod = 10**9+7
  blue = k
  red  = n-k
  blueplace = red+1
  
  for i in range(1,k+1):
    print(ncr(blueplace,i)*ncr(k-1,i-1)%mod)
solve()

Fixed submission:
def solve():
  n,k = (int(i) for i in input().split())
  mod = 10**9+7
  fact = [1]*(n+5)
  inv = [1]*(n+5)
  finv = [1]*(n+5)
  fact[0] = fact[1] = 1
  finv[0] = finv[1] = 1
  inv[1]  = 1
  for i in range(2,n+4):
   fact[i] = (fact[i-1]*i)%mod
   inv[i] = mod-inv[mod%i]*(mod//i)%mod
   finv[i]= finv[i-1]*inv[i]%mod

  
  blue = k
  red  = n-k
  blueplace = red+1
  
  for i in range(1,k+1):
    if (n-k+1)>= i:
     tmp = fact[n-k+1]*(finv[i]*finv[n-k+1-i]%mod)%mod
     tmp *= fact[k-1]*(finv[i-1]*finv[k-i]%mod)%mod
     print(tmp%mod)
    else:
      print(0)
solve()
Buggy python submission (verdict: Runtime Error):
import collections
def solve():
  n = int(input())
  queue = []
  queue2 = []
  for i in range(n):
   x,y = (int(i) for i in input().split())
   queue.append((x,y))
  for i in range(n):
    for j in range(n):
      if i!=j:
        x1,y1 = queue[i]
        x2,y2 = queue[j]
        p = x2-x1
        q = y2-y1
        queue2.append((p,q))
  #print(queue2)
  c = collections.Counter(queue2)
  ans = n
  
  print(ans-c.most_common()[0][1])
solve()


Fixed submission:
import collections
def solve():
  n = int(input())
  queue = []
  queue2 = []
  if n == 1:
    print(1)
    exit()
  for i in range(n):
   x,y = (int(i) for i in input().split())
   queue.append((x,y))
  for i in range(n):
    for j in range(n):
      if i!=j:
        x1,y1 = queue[i]
        x2,y2 = queue[j]
        p = x2-x1
        q = y2-y1
        queue2.append((p,q))
  #print(queue2)
  
  c = collections.Counter(queue2)
  ans = n
  print(ans-c.most_common()[0][1])
solve()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
def solve():
  h,w = (int(i) for i in input().split())
  maze = []
  for i in range(h):
    tmp = input()
    maze.append(tmp)
  l = [[0]*w for _ in range(h)]
  r = [[0]*w for _ in range(h)]
  u = [[0]*w for _ in range(h)]
  d = [[0]*w for _ in range(h)]
  cur = 0
  for i in range(h):
    cur = 0
    for j in range(w):
      if maze[i][j] == ".":
        cur += 1
      else:
        cur = 0
      l[i][j] = cur
  for i in range(h):
    cur = 0
    for j in range(w-1,-1,-1):
      if maze[i][j] == ".":
        cur += 1
      else:
        cur = 0
      r[i][j] = cur
  for j in range(w):
    cur = 0
    for i in range(h):
      if maze[i][j] == ".":
        cur += 1
      else:
        cur = 0
      d[i][j] = cur
  for j in range(w):
    cur = 0
    for i in range(h-1,-1,-1):
      if maze[i][j] == ".":
        cur += 1
      else:
        cur = 0
      u[i][j] = cur      
  ans = 0
  for i in range(h):
    for j in range(w):
      now = l[i][j]+r[i][j]+u[i][j]+d[i][j] -3
      ans = max(now,ans)
  print(ans)
solve()

Fixed submission:
from collections import deque
def solve():
  h,w = (int(i) for i in input().split())
  maze = []
  for i in range(h):
    tmp = input()
    maze.append(tmp)
  l = [[0]*w for _ in range(h)]
  r = [[0]*w for _ in range(h)]
  u = [[0]*w for _ in range(h)]
  d = [[0]*w for _ in range(h)]
  cur = 0
  for i in range(h):
    cur = 0
    for j in range(w):
      if maze[i][j] == ".":
        cur += 1
      else:
        cur = 0
      l[i][j] = cur
  for i in range(h):
    cur = 0
    for j in range(w-1,-1,-1):
      if maze[i][j] == ".":
        cur += 1
      else:
        cur = 0
      r[i][j] = cur
  for j in range(w):
    cur = 0
    for i in range(h):
      if maze[i][j] == ".":
        cur += 1
      else:
        cur = 0
      d[i][j] = cur
  for j in range(w):
    cur = 0
    for i in range(h-1,-1,-1):
      if maze[i][j] == ".":
        cur += 1
      else:
        cur = 0
      u[i][j] = cur      
  ans = 0
  for i in range(h):
    for j in range(w):
      now = l[i][j]+r[i][j]+u[i][j]+d[i][j] -3
      ans = max(now,ans)
  print(ans)
solve()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
def solve():
  n = int(input())
  treepath = [[False]*n for _ in range(n)]
  treenode = [[]*n for _ in range(n)]
  treecolor = [-1]*n
  for i in range(n-1):
    u,v,w = (int(i) for i in input().split())
    u -= 1
    v -= 1
    treenode[u].append(v)
    treenode[v].append(u)
    treepath[u][v] = w%2
    treepath[v][u] = w%2
  query = deque([(0,0,0)])
  while query:
    a,b,c = query.popleft()
    if b%2 == 0:
      treecolor[a] = c
      nextc = c
    else:
      treecolor[a] = 1^c
      nextc = 1^c
    for nextnode in treenode[a]:
      if treecolor[nextnode] != -1:
        continue
      else:
        query.append((nextnode,treepath[a][nextnode],nextc))  
        treecolor[nextnode] = -2
  #print(treecolor)
  for i in treecolor:
    print(i)
solve()

Fixed submission:
import sys
input = sys.stdin.readline
from collections import deque
def solve():
  n = int(input())
  treenode = [[] for _ in range(n)]
  treecolor = [-2]*n
  for i in range(n-1):
    u,v,w = (int(i) for i in input().split())
    u -= 1
    v -= 1
    treenode[u].append((v,w%2))
    treenode[v].append((u,w%2))
  query = deque([(0,0,0)])
  while query:
    a,b,c = query.popleft()
    if b%2 == 0:
      treecolor[a] = c
      nextc = c
    else:
      treecolor[a] = 1^c
      nextc = 1^c
    for nextnode,weight in treenode[a]:
      if treecolor[nextnode] != -2:
        continue
      else:
        query.append((nextnode,weight,nextc))  
        treecolor[nextnode] = -1
  for i in treecolor:
    print(i)
solve()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
def solve():
  n = int(input())
  treepath = [[False]*n for _ in range(n)]
  treenode = [[]*n for _ in range(n)]
  treecolor = [-1]*n
  for i in range(n-1):
    u,v,w = (int(i) for i in input().split())
    u -= 1
    v -= 1
    treepath[u][v] = w%2
    treepath[v][u] = w%2
    treenode[u].append(v)
    treenode[v].append(u)

  query = deque([(0,0,0)])
  while query:
    a,b,c = query.popleft()
    if b%2 == 0:
      treecolor[a] = c
      nextc = c
    else:
      treecolor[a] = 1^c
      nextc = 1^c
    for nextnode in treenode[a]:
      if treecolor[nextnode] != -1:
        continue
      else:
        query.append((nextnode,treepath[a][nextnode],nextc))  
  #print(treecolor)
  for i in treecolor:
    print(i)
solve()

Fixed submission:
import sys
input = sys.stdin.readline
from collections import deque
def solve():
  n = int(input())
  treenode = [[] for _ in range(n)]
  treecolor = [-2]*n
  for i in range(n-1):
    u,v,w = (int(i) for i in input().split())
    u -= 1
    v -= 1
    treenode[u].append((v,w%2))
    treenode[v].append((u,w%2))
  query = deque([(0,0,0)])
  while query:
    a,b,c = query.popleft()
    if b%2 == 0:
      treecolor[a] = c
      nextc = c
    else:
      treecolor[a] = 1^c
      nextc = 1^c
    for nextnode,weight in treenode[a]:
      if treecolor[nextnode] != -2:
        continue
      else:
        query.append((nextnode,weight,nextc))  
        treecolor[nextnode] = -1
  for i in treecolor:
    print(i)
solve()
Buggy python submission (verdict: Time Limit Exceeded):
def solve():
  r,g,b,n = (int(i) for i in input().split())
  ans = 0
  for i in range(0,1+n//r):
    for j in range(0,1+n//g):
        rest = n-(i*r + j*g)
        #print(rest)
        if rest%b == 0 and rest >= 0:
          ans += 1
  print(ans)
solve()

Fixed submission:
def solve():
  r,g,b,n = (int(i) for i in input().split())
  ans = 0
  for i in range(0,1+n//r):
    for j in range(0,1+n//g):
        rest = n-(i*r + j*g)
        #print(rest)
        if rest%b == 0 and rest >= 0:
          ans += 1
  print(ans)
solve()
Buggy python submission (verdict: Time Limit Exceeded):
def solve():
  x,y,z,k = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  b = list(int(i) for i in input().split())
  c = list(int(i) for i in input().split())
  a = sorted(a,reverse=True)
  b = sorted(b,reverse=True)
  c = sorted(c,reverse=True)
  ab = []
  abc = []
  
  for i in range(x):
    for j in range(y):
      ab.append(a[i]+b[j])
  ab = sorted(ab,reverse = True)
  for t in range(min(k,len(ab))):
    for l in range(z):
      abc.append(ab[t]+c[l])
      
  abc = sorted(abc,reverse = True)
  for i in range(k):
    print(abc[i])

solve()

Fixed submission:
def solve():
  x,y,z,k = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  b = list(int(i) for i in input().split())
  c = list(int(i) for i in input().split())
  a = sorted(a,reverse=True)
  b = sorted(b,reverse=True)
  c = sorted(c,reverse=True)
  ab = []
  abc = []
  
  for i in range(x):
    for j in range(y):
      ab.append(a[i]+b[j])
  ab = sorted(ab,reverse = True)
  for t in range(min(k,len(ab))):
    for l in range(z):
      abc.append(ab[t]+c[l])
      
  abc = sorted(abc,reverse = True)
  for i in range(k):
    print(abc[i])

solve()

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
  x,y,z,k = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  b = list(int(i) for i in input().split())
  c = list(int(i) for i in input().split())
  ab = []
  abc = []
  
  for i in range(x):
    for j in range(y):
      ab.append(a[i]+b[j])
  ab = sorted(ab,reverse = True)
  for t in range(min(k,len(ab))):
    for l in range(z):
      abc.append(ab[t]+c[l])
      
  abc = sorted(abc,reverse = True)
  for i in range(k):
    print(abc[i])

solve()

Fixed submission:
def solve():
  x,y,z,k = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  b = list(int(i) for i in input().split())
  c = list(int(i) for i in input().split())
  a = sorted(a,reverse=True)
  b = sorted(b,reverse=True)
  c = sorted(c,reverse=True)
  ab = []
  abc = []
  
  for i in range(x):
    for j in range(y):
      ab.append(a[i]+b[j])
  ab = sorted(ab,reverse = True)
  for t in range(min(k,len(ab))):
    for l in range(z):
      abc.append(ab[t]+c[l])
      
  abc = sorted(abc,reverse = True)
  for i in range(k):
    print(abc[i])

solve()
Buggy python submission (verdict: Time Limit Exceeded):
n,q = (int(i) for i in input().split())
s = input()
query = [0]*n
point = [0]*(n+1)
for i in range(n-1):
  if s[i] == 'A' and s[i+1] =='C': 
    query[i] = 1
  if s[i] == 'C' and s[i+1] =='A':
    point[i+1] -= 1
#print(point)
    
for i in range(q):
  l,r = (int(i) for i in input().split())
  ans = sum(query[(l-1):r])
  ans += point[r-1]
  print(ans)
 

Fixed submission:
n,q = (int(i) for i in input().split())
s = input()
query = [0]*(n+1)
point = [0]*(n+1)
ct = 0
for i in range(n-1):
  if s[i] == 'A' and s[i+1] =='C': 
    ct += 1
    point[i] = -1 
  query[i+1] = ct
query[i+2] = ct  
#print(point)
    
for i in range(q):
  l,r = (int(i) for i in input().split())
  ans = query[r]-query[l-1]
  ans += point[r-1]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
n,q = (int(i) for i in input().split())
s = input()
query = [0]*n
for i in range(n-1):
  if s[i] == 'A' and s[i+1] =='C': 
    query[i] = 1
for i in range(q):
  l,r = (int(i) for i in input().split())
  ans = sum(query[(l-1):r])
  if r >= 1:
   if s[r-1] == 'A' and s[r-2] =='C':

     ans -= 1
  print(math.floor(ans))
 

Fixed submission:
n,q = (int(i) for i in input().split())
s = input()
query = [0]*(n+1)
point = [0]*(n+1)
ct = 0
for i in range(n-1):
  if s[i] == 'A' and s[i+1] =='C': 
    ct += 1
    point[i] = -1 
  query[i+1] = ct
query[i+2] = ct  
#print(point)
    
for i in range(q):
  l,r = (int(i) for i in input().split())
  ans = query[r]-query[l-1]
  ans += point[r-1]
  print(ans)
Buggy python submission (verdict: Runtime Error):
def solve():
 n = int(input())
 c = [int(input()) for _ in range(n)]
 mod = 10**9 +7
 dp = [1]*(n)
 place = [-1]*n
 stack = []
 memo = c[0]

 for i in range(n):
    
    
    if c[i] in stack:
      if memo == c[i]:
        dp[i] = dp[i-1]
      else:
        dp[i] = (dp[i-1]+dp[place[c[i]-1]])%mod
    else:
      dp[i] = dp[i-1]
      stack.append(c[i])
    memo = c[i]
    place[c[i]-1] = i
    #print(place)
    #print(dp)
 return dp[-1]%mod

print(solve())


Fixed submission:
def solve():
 n = int(input())
 c = [int(input()) for _ in range(n)]
 mod = 10**9 +7
 dp = [1]*n
 dp[0] = 1
 place = [-1]*200001

 for i in range(n):    
    if place[c[i]-1] != -1:
      if place[c[i]-1] == i-1:
        dp[i] = dp[i-1]
      else:
        dp[i] = (dp[i-1]+dp[place[c[i]-1]])%mod
        
    else:
     dp[i] = dp[i-1]
    place[c[i]-1] = i
 #print(dp)
 #print(place)
 return dp[-1]%mod

print(solve())
Buggy python submission (verdict: Runtime Error):
H,W　= (int(i) for i in input().split())
h,w　= (int(i) for i in input().split())

print ((H-h)*(W-w))

Fixed submission:
H,W = (int(i) for i in input().split())
h,w = (int(i) for i in input().split())
print((H-h)*(W-w))
Buggy python submission (verdict: Runtime Error):
import bisect
n = int(input())
a = list(int(i) for i in input().split())
a.sort()
flag = 1
sa = [1]*(n-1)
for i in range(n-1):
  sa[i] = a[i+1]-a[i]
  if sa[i] != 0: flag = 0
if flag == 1: 
  print(min(a))
  exit()
else:
 for i in range(n):
  if a[i]%(min(sa))!= 0:
   a[i] = a[i]%(min(sa))
 
print(min(a))

Fixed submission:
import fractions
n = int(input())
a = list(int(i) for i in input().split())
ans = fractions.gcd(a[1], a[0])
for i in range(n-1):
  ans = fractions.gcd(a[i+1], ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m =(int(i) for i in input().split())
x = list(int(i) for i in input().split())
x.sort()
sa = []
ans = 0
if m <= n:
  print('0')
  exit()
for i in range(m-1):
  sa.append(x[i+1]-x[i])
for i in range(n-1):
  tmp1 = max(sa)
  sa.remove(tmp1)

ans = sum(sa)
print(ans)

Fixed submission:
n,m =(int(i) for i in input().split())
x = list(int(i) for i in input().split())
x.sort()
sa = []
ans = 0
if m <= n:
  print('0')
  exit()
for i in range(m-1):
  sa.append(x[i+1]-x[i])
s2 = sorted(sa,reverse = True)
#print(s2)
for i in range(n-1,len(s2)):
  ans += s2[i]
print(ans)