Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n =int(input())
takahashi = 0
aoki = 0
a = [[int(i) for i in input().split()] for i in range(n)] 
a2 = sorted(a, key=lambda x: x[0])
d = deque(a2)
start = 0
for i in range(n):
 if start%2 == 0:
  d = sorted(d, key=lambda x: x[0])
  a,b =d.pop()
  takahashi += a
  #print(d)
 if start %2 == 1:
  d = sorted(d, key=lambda x: x[1])
  a,b = d.pop()
  aoki += b
  #print(d)
 start += 1
print(takahashi -aoki)

Fixed submission:
from collections import deque
n =int(input())
takahashi = 0
aoki = 0
ab = []
a = []
for i in range(n):
 tmp1,tmp2 = (int(i) for i in input().split())
 a.append([tmp1,tmp2])
 ab.append(tmp1+tmp2)
 aoki += tmp2
#a2 = sorted(a, key=lambda x: x[0])
#a3 = sorted(a, key=lambda x: x[1])
ab = sorted(ab,reverse = True)
start = 0
for i in range(n):
  if i%2 == 0:
    takahashi += ab[i]
  else:
    continue


print(takahashi-aoki)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n =int(input())
a = []
takahashi = 0
aoki = 0
for i in range(n):
 tmp1,tmp2 = (int(i) for i in input().split())
 a.append([tmp1,tmp2])
a2 = sorted(a, key=lambda x: x[0])
a3 = sorted(a, key=lambda x: x[1])
d = deque(a2)
start = 0
for i in range(n):
 if start%2 == 0:
  d = sorted(d, key=lambda x: x[0])
  a,b =d.pop()
  takahashi += a
  #print(d)
 if start %2 == 1:
  d = sorted(d, key=lambda x: x[1])
  a,b = d.pop()
  aoki += b
  #print(d)
 start += 1
print(takahashi -aoki)

Fixed submission:
from collections import deque
n =int(input())
takahashi = 0
aoki = 0
ab = []
a = []
for i in range(n):
 tmp1,tmp2 = (int(i) for i in input().split())
 a.append([tmp1,tmp2])
 ab.append(tmp1+tmp2)
 aoki += tmp2
#a2 = sorted(a, key=lambda x: x[0])
#a3 = sorted(a, key=lambda x: x[1])
ab = sorted(ab,reverse = True)
start = 0
for i in range(n):
  if i%2 == 0:
    takahashi += ab[i]
  else:
    continue


print(takahashi-aoki)
Buggy python submission (verdict: Runtime Error):
import heapq
def solve():
  x1,y1,x2,y2 = (int(i) for i in input().split())
  
  que = []
  que2 = []
  for i in range(-300,300):
    for j in range(-300,300):
      if (x2-x1)**2+(y2-y1)**2 == (i-x1)**2+(j-y1)**2:
        if (i,j) != (x1,y1) and  (i,j) != (x2,y2):
          que.append((i,j))
      if (x2-x1)**2+(y2-y1)**2 == (i-x2)**2+(j-y2)**2:
        if  (i,j) != (x1,y1) and  (i,j) != (x2,y2):
         que2.append((i,j))
        
  #define x3,y3
  while que2:
    (x3,y3) = heapq.heappop(que2)
    for i in range(len(que)):
      x4,y4 = que[i]
      if (x3-x2)**2+(y3-y2)**2 == (x4-x1)**2+(y4-y1)**2:
       if (x3-x4)**2+(y3-y4)**2 == (x2-x1)**2+(y2-y1)**2:
        if (x3-x1)**2+(y3-y1)**2 == (x2-x4)**2+(y2-y4)**2:
           print(x3,y3,x4,y4)
            exit()
  #print(que)
 #print(que2)			
solve()

Fixed submission:
import heapq
def solve():
  x1,y1,x2,y2 = (int(i) for i in input().split())
  x = x2-x1
  y = y2-y1
  print(x2-y,y2+x,x1-y,y1+x)
 	
solve()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
def solve():
  h,w,d  = (int(i) for i in input().split())
  a = []
  for i in range(h):
    tmp = list(int(i) for i in input().split())
    a.append(tmp)

  query = [False]*(h*w)
  for i in range(h):
    for j in range(w):
      number = a[i][j] - 1
      query[number] = (i,j)
  q = int(input())
  for i in range(q):
    l,r = (int(m) for m in input().split())
    if l == r:
      print(0)
    else:
      ans = 0
      for j in range((r-l)//d):
        leftx,lefty = query[(l-1)+j*d]
        rightx,righty = query[(l-1)+(j+1)*d]
        ans += abs(rightx-leftx)+abs(righty-lefty)
      print(ans)
  
solve()

Fixed submission:
from collections import deque
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
def solve():
  h,w,d  = (int(i) for i in input().split())
  a = []
  for i in range(h):
    tmp = list(int(i) for i in input().split())
    a.append(tmp)

  query = [False]*(h*w)
  distance = [0]*(h*w+1)
  for i in range(h):
    for j in range(w):
      number = a[i][j] - 1
      query[number] = (i,j)
  q = int(input())
  
  for i in range(d,h*w):
    leftx,lefty = query[i-d]
    rightx,righty = query[i]
    distance[i] = distance[i-d]+abs(rightx-leftx)+abs(righty-lefty)
  #print(distance)
  
  for i in range(q):
    l,r = (int(m) for m in input().split())
    print(distance[r-1]-distance[l-1])
  
solve()
Buggy python submission (verdict: Time Limit Exceeded):
x,y = (int(i) for i in input().split())
if x== y:
  print(-1)
  exit()
for i in range(1,10**18//x):
  ans = x*i
  if ans%y != 0:
    print(ans)
    exit()
print(-1)

Fixed submission:
x,y = (int(i) for i in input().split())
if x%y == 0 or y == 1:
  print(-1)
  exit()
else:
  print(x*(y-1))
Buggy python submission (verdict: Runtime Error):
from sys import stdin

s = stdin.readline().rstrip()
t = stdin.readline().rstrip()
sa = ''.join(sorted(s))
ts = ''.join(sorted(t,reverse=True))
ans = 'No'
for i in range(len(s)):
  if ord(sa[i]) < ord(ts[i]):
   ans = 'Yes'
   break
  elif sa[i] == ts[i]:
    if len(s) == i+1:
      if len(t) > len(s):
       ans = 'Yes'
      
  else:
   continue

print(ans)

Fixed submission:
from sys import stdin
 
s = stdin.readline().rstrip()
t = stdin.readline().rstrip()
s = sorted(s)
t = sorted(t,reverse =True)
tmp1 =("".join(s))
tmp2 =("".join(t))
if tmp1 < tmp2 :print('Yes')
else:print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n= int(input())
a = list(int(i) for i in input().split())
a2 = list(set(a))
ans = 0
for i in a2:
  tmp = a.count(i)
  if tmp <i:
   ans += tmp
  else:
   ans += (tmp-i)
print(ans)

Fixed submission:
import collections
n= int(input())
a = list(int(i) for i in input().split())
c = collections.Counter(a)
a2 = list(set(a))
ans = 0
for i in a2:
  tmp = c[i]
  if tmp <i:
   ans += tmp
  else:
   ans += (tmp-i)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n= int(input())
a = list(int(i) for i in input().split())
a2 = list(set(a))
ans = 0
for i in a2:
  if a.count(i) <i:
   ans += a.count(i)
  else:
   ans += (a.count(i)-i)
print(ans)

Fixed submission:
import collections
n= int(input())
a = list(int(i) for i in input().split())
c = collections.Counter(a)
a2 = list(set(a))
ans = 0
for i in a2:
  tmp = c[i]
  if tmp <i:
   ans += tmp
  else:
   ans += (tmp-i)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import collections
n,k = (int(i) for i in input().split())
a = list(int(i) for i in input().split())
c = collections.Counter(a)
ct = 0
for i in range(k):
 try:
  ct += c.most_common()[i][1]
 except:
  break
ans = n-ct
if ans <0:
  ans = 0
print(ans)

Fixed submission:
import collections
n,k = (int(i) for i in input().split())
a = list(int(i) for i in input().split())
c = collections.Counter(a)
values,counts = zip(*c.most_common())
if len(counts) >= k:
 ans = sum(counts[k:])
else:
 ans = 0

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
def solve():
  n,z,w = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  if n == 1:
    ans = abs(w-a[0])
  else:
    ans = 0
    #最小化する方向に動く
    tmp = abs([n-2]-a[n-1])
    tmp2 = abs(a[n-1]-w)
    ans = max(tmp,tmp2)
  print(ans)
solve()
  

Fixed submission:
import sys
input = sys.stdin.readline
def solve():
  n,z,w = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  if n == 1:
    ans = abs(w-a[0])
  else:
    ans = 0
    #最小化する方向に動く
    tmp = abs(a[n-2]-a[n-1])
    tmp2 = abs(a[n-1]-w)
    ans = max(tmp,tmp2)
  print(ans)
solve()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
d = list(int(i) for i in input().split())
m = int(input())
t = list(int(i) for i in input().split())
for i in t:
  if not i in d:
    print('NO')
    exit()
  d.remove(i)
print('YES')

Fixed submission:
import collections
n = int(input())
d =list(int(i) for i in input().split())
m = int(input())
t =list(int(i) for i in input().split())
a = collections.deque(sorted(d))
b = collections.deque(sorted(t))


for i in range(n):
  if a[0] == b[0]:
    b.popleft()
  a.popleft()
  if len(b) == 0:
    print('YES')
    exit()
  elif len(a) == 0:
    break
print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse.csgraph import floyd_warshall
from collections import deque
import sys
input = sys.stdin.readline
def isbipart(n,graph):  
  colors = [0 for i in range(n)]
  stack = deque([(0,1)])
  while stack:
    v,color = stack.pop()
    colors[v] = color
    for to in graph[v]:
      if colors[to] == color:
        return False
      if colors[to] == 0:
        stack.append((to,-color))
  return colors

def solve():
  n,m  =(int(i) for i in input().split())
  graph = [[] for _ in range(n)]
  for i in range(m):
    a,b = (int(i) for i in input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
  colors = isbipart(n,graph)
  if colors:
    b = colors.count(1)
    w = colors.count(-1)
    print(b*w-m)
  else:
    print(n*(n-1)//2-m)
solve()

Fixed submission:

from collections import deque
import sys
input = sys.stdin.readline
def isbipart(n,graph):  
  colors = [0 for i in range(n)]
  stack = deque([(0,1)])
  while stack:
    v,color = stack.pop()
    colors[v] = color
    for to in graph[v]:
      if colors[to] == color:
        return False
      if colors[to] == 0:
        stack.append((to,-color))
  return colors

def solve():
  n,m  =(int(i) for i in input().split())
  graph = [[] for _ in range(n)]
  for i in range(m):
    a,b = (int(i) for i in input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
  colors = isbipart(n,graph)
  if colors:
    b = colors.count(1)
    w = n-b
    print(b*w-m)
  else:
    print(n*(n-1)//2-m)
solve()
Buggy python submission (verdict: Runtime Error):

n= int(input())
m= int(input())
print((n-1)*(m-1))


Fixed submission:
n,m =  (int(_) for _ in input().split())  
print((n-1)*(m-1))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n,m = (int(i) for i in input().split())
a = []
a2 = []
for i in range(m):
 tmp1,tmp2 = (int(i) for i in input().split())
 a.append([tmp1,tmp2])
 a2.append(tmp1)
query = sorted(a, key=lambda x: x[0])
start = sorted(a2)
query2 = query[0:bisect.bisect_right(start,1)]
cand = []
for c,b in enumerate(query2):
  if [b[1],n] in a:
    print('POSSIBLE')
    exit()
print('IMPOSSIBLE')

Fixed submission:
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    
n,m = (int(i) for i in input().split())
uf = UnionFind(n-1)
for i in range(m):
  a,b = (int(i) for i in input().split())
  if a == 1 or b ==n: uf.union(a-1,b-1)

if uf.same_check(0,n-1): print('POSSIBLE')
else:print('IMPOSSIBLE')
Buggy python submission (verdict: Time Limit Exceeded):
#https://img.atcoder.jp/agc016/editorial.pdf
def solve():
  n = int(input())
  a = list(int(i) for i in input().split())
  ans = 'Yes'
  alone = 0
  group = 0
  if max(a) - min(a) >= 2: ans = 'No'
  
  elif max(a) - min(a) == 1:
   for i in a:
     if i == max(a)-1 : alone += 1
     else: group += 1
   if alone < max(a) and 2*(max(a)-alone)<= group: pass
   else: ans = 'No'
  
  
  elif max(a) - min(a) == 0:
    if a[0] == n-1 or 2*a[0] <= n:
      pass
    else: ans = 'No'
  return ans

if __name__ == '__main__':
  print(solve())

Fixed submission:
#https://img.atcoder.jp/agc016/editorial.pdf
def solve():
  n = int(input())
  a = list(int(i) for i in input().split())
  ans = 'Yes'
  alone = 0
  group = 0
  ha = max(a)
  la = min(a)
  if ha - la >= 2: ans = 'No'
  
  elif ha - la == 1:
   for i in a:
     if i == ha-1 : alone += 1
     else: group += 1
   if alone < ha and 2*(ha-alone)<= group: pass
   else: ans = 'No'
  
  
  elif ha - la == 0:
    if a[0] == n-1 or 2*a[0] <= n:
      pass
    else: ans = 'No'
  return ans

if __name__ == '__main__':
  print(solve())
Buggy python submission (verdict: Runtime Error):
1 3 3


Fixed submission:
n,a,b = (int(i) for i in input().split())
if a >b:
  print(0)
  exit()
elif n == 1 and a!=b:
  print(0)
  exit()
if n<= 2:
  print(1)
else:
  mi = a*(n-1)+b
  ma = a+(n-1)*b
  print(ma-mi+1)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
def solve():
  n = int(input())
  a = list(int(i) for i in input().split())
  an = []
  a2n = a[n:2*n]
  a3n = []
  for i in range(n):
    heapq.heappush(an,a[i])
    heapq.heappush(a3n,-1*a[i+2*n])
  ta2n = a2n
  suman = [sum(an)]
  suma3n = [-1*sum(a3n)]
  for i in range(n):
    tmp = ta2n[i]
    heapq.heappush(an,tmp)
    heapq.heappop(an)
    suman.append(sum(an))
  for i in range(n):
    tmp = ta2n[n-i-1]
    heapq.heappush(a3n,-1*tmp)
    heapq.heappop(a3n)
    suma3n.append(-1 * sum(a3n))

  ans = -10000000000000000
  for i in range(n+1):
    tmpans = suman[i]-suma3n[n-i]
    ans = max(ans,tmpans)
  print(ans)
solve()

Fixed submission:
import heapq
def solve():
  n = int(input())
  a = list(int(i) for i in input().split())
  an = []
  a2n = a[n:2*n]
  a3n = []
  for i in range(n):
    heapq.heappush(an,a[i])
    heapq.heappush(a3n,-1*a[i+2*n])
  ta2n = a2n
  
  tmpsuman = sum(an)
  tmpsuma3n = -1*sum(a3n)
  
  suman = [tmpsuman]
  suma3n = [tmpsuma3n]
  
  for i in range(n):
    tmp = ta2n[i]
    tmpsuman += tmp
    heapq.heappush(an,tmp)
    tmpsuman -= heapq.heappop(an)
    
    suman.append(tmpsuman)
  for i in range(n):
    tmp = ta2n[n-i-1]
    tmpsuma3n += tmp
    heapq.heappush(a3n,-1*tmp)
    tmpsuma3n -= -1*heapq.heappop(a3n)
    suma3n.append(tmpsuma3n)

  ans = -10000000000000000
  for i in range(n+1):
    tmpans = suman[i]-suma3n[n-i]
    ans = max(ans,tmpans)
  print(ans)
solve()
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n,k= (int(i) for i in input().split())
array = []
for i in range(n):
 a,b= (int(i) for i in input().split())
 for j in range(b):
  bisect.insort(array, a, lo=0, hi=len(array))
print(array[k-1])

Fixed submission:
import bisect
n,k= (int(i) for i in input().split())
array = []
for i in range(n):
 a,b= (int(j) for j in input().split())
 array.append((a,b))
array = sorted(array)
cnt = 0
for ab in array:
    a,b = ab
    cnt += b
    if cnt >= k:
        print(a)
        break
Buggy python submission (verdict: Runtime Error):
def solve():
  n,m = (int(i) for i in input().split())
  a = [0]*n
  for i in range(m):
    a1,b1 = (int(i) for i in input().split())
    a[a1-1]+=1
    a[b1-1]+=1
  ans = 'YES'
  for i in range(1,n+1):
   if a[i]%2 == 1:
    ans ='NO'
  return ans
                   
  
if __name__ == '__main__':
  print(solve())

Fixed submission:
def solve():
  a,b,c = (int(i) for i in input().split())
  queue = [[a,b,c]] #mugencheck
  ct = 0
  while ct <100000000:
    if a%2 ==1 or b%2 ==1 or c%2 == 1: break
    #とりあえず交換simluration
    tmpa = a//2
    tmpb = b//2
    tmpc = c//2
    a = tmpb+tmpc
    b = tmpa+tmpc
    c = tmpa+tmpb
    if [a,b,c] in queue: 
      return -1
    else:
      ct += 1
      queue.append([a,b,c])
      #print(queue)
  return ct
                   
  
if __name__ == '__main__':
  print(solve())
Buggy python submission (verdict: Time Limit Exceeded):
def solve():
  n,m = (int(i) for i in input().split())
  a = []
  b = []
  for i in range(m):
    a1,b1 = (int(i) for i in input().split())
    a.append(a1)
    b.append(b1)
  ans = 'YES'
  for i in range(1,n+1):
   if (a.count(i)+b.count(i))%2 == 1:
    ans ='NO'
  return ans
                   
  
if __name__ == '__main__':
  print(solve())

Fixed submission:
def solve():
  n,m = (int(i) for i in input().split())
  a = [0]*n
  for i in range(m):
    a1,b1 = (int(i) for i in input().split())
    a[a1-1]+=1
    a[b1-1]+=1
  ans = 'YES'
  for i in range(n):
   if a[i]%2 == 1:
    ans ='NO'
  return ans
                   
  
if __name__ == '__main__':
  print(solve())
Buggy python submission (verdict: Time Limit Exceeded):
import math
n = int(input())
rootn = int(math.sqrt(n))
ct = 0
for i in range(rootn,n+1):
  if n%i == 0:
    tmp = i
    while tmp//10 != 0:
     ct += 1  
     tmp = tmp//10   
    break
print(ct+1)

Fixed submission:
import math
n = int(input())
rootn = int(math.sqrt(n))
ct = 0
for i in reversed(range(1,rootn+1)):
  if n%i == 0:
    tmp = n//i
    while tmp//10 != 0:
     ct += 1  
     tmp = tmp//10   
    break
print(ct+1)
Buggy python submission (verdict: Runtime Error):
import bisect
def solve():
  n,c,k = (int(i) for i in input().split())
  t = [int(input()) for i in range(n)]
  t = sorted(t,reverse = True)
  ans = 0
  
  while t:
    ans += 1
    customer = t.pop(0)
    if len(t) >= 1:
     for i in range(c-1):
      if customer  <= t[0] + k:
        t.pop(0)
      else:
        break
  print(ans)
  
solve()

Fixed submission:
import bisect
def solve():
  n,c,k = (int(i) for i in input().split())
  t = [int(input()) for i in range(n)]
  t = sorted(t,reverse = True)
  ans = 0
  
  while t:
    ans += 1
    customer = t.pop(0)
    if len(t) >= 1:
     for i in range(c-1):
      if customer  <= t[0] + k:
        t.pop(0)
      else:
        break
      if len(t) == 0:
        break
  print(ans)
  
solve()

Buggy python submission (verdict: Runtime Error):
import bisect
def solve():
  n,c,k = (int(i) for i in input().split())
  t = [int(input()) for i in range(n)]
  t = sorted(t,reverse = True)
  ans = 0
  
  while t:
    ans += 1
    customer = t.pop(0)
    if len(t) >= 1:
     for i in range(c-1):
      if customer  <= t[0] + k:
        t.pop(0)
      else:
        break
  print(ans)
  
solve()

Fixed submission:
import bisect
def solve():
  n,c,k = (int(i) for i in input().split())
  t = [int(input()) for i in range(n)]
  t = sorted(t,reverse = True)
  ans = 0
  
  while t:
    ans += 1
    customer = t.pop(0)
    if len(t) >= 1:
     for i in range(c-1):
      if customer  <= t[0] + k:
        t.pop(0)
      else:
        break
      if len(t) == 0:
        break
  print(ans)
  
solve()

Buggy python submission (verdict: Runtime Error):
import bisect
def solve():
  n,c,k = (int(i) for i in input().split())
  t = [int(input()) for i in range(n)]
  t.sort()
  ans = 0
  
  while t:
    ans += 1
    customer = t.pop(0)
    if len(t) >= 1:
     for i in range(c):
      if customer + k >= t[0]:
        t.pop(0)
      else:
        break
  print(ans)
  
solve()

Fixed submission:
import bisect
def solve():
  n,c,k = (int(i) for i in input().split())
  t = [int(input()) for i in range(n)]
  t = sorted(t,reverse = True)
  ans = 0
  
  while t:
    ans += 1
    customer = t.pop(0)
    if len(t) >= 1:
     for i in range(c-1):
      if customer  <= t[0] + k:
        t.pop(0)
      else:
        break
      if len(t) == 0:
        break
  print(ans)
  
solve()
Buggy python submission (verdict: Time Limit Exceeded):
k,s = (int(i) for i in input().split())
ans = 0
for i in range(k+1):
 for j in range(k+1):
  for l in range(k+1):
    if i+j+l == s:
      ans += 1
print(ans)

Fixed submission:
k,s = (int(i) for i in input().split())
ans = 0
for i in range(k+1):
 for j in range(k+1):
    if 0<=s-i-j and s-i-j<=k:
      ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
n = len(s)
ct = 0
if len(set(s)) == 1:
  ans = 0
else:
 for i in range(n-1):
  if s[i] != s[i+1]:
    ans+= 1
print(ans)
  

Fixed submission:
s = input()
n = len(s)
ans = 0
if len(set(s)) == 1:
  ans = 0
else:
 for i in range(n-1):
  if s[i] != s[i+1]:
    ans+= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def solve():
  n,t = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  query = [-1*10**15]
  minA = a[0]
  for i in range(1,n):
    if minA < a[i]:
      if min(query) <= a[i]-minA:
        query.append(a[i]-minA)
    
    
    minA = min(minA,a[i])
  print(query.count(max(query)))
    
solve()


Fixed submission:
def solve():
  n,t = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  query = [-1]
  querymax = -1
  minA = a[0]
  for i in range(1,n):
    if minA < a[i]:
      if querymax <= a[i]-minA:
        querymax = a[i]-minA
        query.append(a[i]-minA)
    
    
    minA = min(minA,a[i])
  print(query.count(max(query)))
    
solve()
Buggy python submission (verdict: Time Limit Exceeded):
def solve():
  s =input()
  n =len(s)
  #Tの位置とSの位置がほしい
  places = []
  placet = []
  for i in range(n):
    if s[i] == 'S':places.append(i)
    else: placet.append(i)
  places = places[::-1]
  placet = placet[::-1]
  ct = 0
  for j in places:
    if j < placet[0]:
      ct += 2
      placet.pop(0)
  return (n-ct)  
  
  
if __name__ == '__main__':
  print(solve())

Fixed submission:
def solve():
  s =input()
  n =len(s)
  queue = 0
  ans = 0
  for i in range(n):
    if s[i] == 'S': queue+=1
    else: 
      if queue >0:
        queue -= 1
        ans += 2
  return (n-ans)  
  
  
if __name__ == '__main__':
  print(solve())

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
  s =input()
  n =len(s)
  #Tの位置とSの位置がほしい
  places = []
  placet = []
  for i in range(n):
    if s[i] == 'S':places.append(i)
    else: placet.append(i)
  places = places[::-1]
  placet = placet[::-1]
  ct = 0
  for j in places:
    if j < placet[0]:
      ct += 2
      placet.pop(0)
  return (n-ct)  
  
  
if __name__ == '__main__':
  print(solve())

Fixed submission:
def solve():
  s =input()
  n =len(s)
  queue = 0
  ans = 0
  for i in range(n):
    if s[i] == 'S': queue+=1
    else: 
      if queue >0:
        queue -= 1
        ans += 2
  return (n-ans)  
  
  
if __name__ == '__main__':
  print(solve())
Buggy python submission (verdict: Time Limit Exceeded):
def solve():
  h,w,n = (int(i) for i in input().split())
  
  query = []
  for i in range(n):
    a,b = (int(i) for i in input().split())
    d = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,0),(0,1),(1,-1),(1,0),(1,1)]
    for dx,dy in d:
      if 2 <= a+dx <= h-1 and 2 <= b+dy <= w-1:
        query.append((a+dx,b+dy))
  ans = [0]*10
  #print(query)
  for i in range(2,h):
    for j in range(2,w):
      #print("aa",i,j)
      tp = query.count((i,j))
      #print(tp)
      ans[tp] += 1
  for i in ans:
    print(i)
solve()


Fixed submission:
import collections 
def solve():
  h,w,n = (int(i) for i in input().split())
  
  query = []
  for i in range(n):
    a,b = (int(i) for i in input().split())
    d = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,0),(0,1),(1,-1),(1,0),(1,1)]
    for dx,dy in d:
      if 2 <= a+dx <= h-1 and 2 <= b+dy <= w-1:
        query.append((a+dx,b+dy))
  ans = [0]*10
  if query:
   query = collections.Counter(query)
   values, counts = zip(*query.most_common())
   for i in range(10):
     ans[i] = counts.count(i)
  tp = sum(ans)
  ans[0] = (h-2)*(w-2)-tp
  
  for i in ans:
    print(i)
solve()