Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 9)

n, m, k = map(int, input().split())
ab = [[] for i in range(n)]

for i in range(m):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  ab[a].append(b)
  ab[b].append(a)

block = [[] for i in range(n)]
for i in range(k):
  c, d = map(int, input().split())
  c -= 1
  d -= 1
  block[c].append(d)
  block[d].append(c)

ans = [0 for i in range(n)]

def dfs(s):
  vis[s] = True
  ary.append(s)
  for i in ab[s]:
    if vis[i] == False:
      dfs(i)

for i in range(n):
  vis = [False for i in range(n)]
  vis[i] = True
  x = ab[i]
  for j in x:
    vis[j] = True
  c = 0
  for j in x:
    ary = []
    dfs(j)
    ary.pop(0)
    blo = set(block[i])
    cnt = set(ary) - blo
    c += len(cnt)
  ans[i] = c
print (*ans)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)

n, m, k = map(int, input().split())
ab = [[] for i in range(n)]

for i in range(m):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  ab[a].append(b)
  ab[b].append(a)

block = [set() for i in range(n)]
for i in range(k):
  c, d = map(int, input().split())
  c -= 1
  d -= 1
  block[c].add(d)
  block[d].add(c)

ans = [0 for i in range(n)]

def dfs(s):
  if vis[s] == False:
    vis[s] = True
    r[cnt].add(s)
    for i in ab[s]:
      dfs(i)

vis = [False for i in range(n)]
r = []
cnt = 0
for i in range(n):
  if vis[i] == False:
    r.append(set())
    dfs(i)
    cnt += 1

ans = [0 for i in range(n)]
for i in r:
  l = len(i)
  for j in i:
    ans[j] = l - len(ab[j]) - len(i&block[j]) - 1

print (*ans)

Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
ab = [[] for i in range(n)]

for i in range(m):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  ab[a].append(b)
  ab[b].append(a)

block = [[] for i in range(n)]
for i in range(k):
  c, d = map(int, input().split())
  c -= 1
  d -= 1
  block[c].append(d)
  block[d].append(c)

ans = [0 for i in range(n)]

def dfs(s):
  vis[s] = True
  ary.append(s)
  for i in ab[s]:
    if vis[i] == False:
      dfs(i)

for i in range(n):
  vis = [False for i in range(n)]
  vis[i] = True
  x = ab[i]
  for j in x:
    vis[j] = True
  c = 0
  for j in x:
    ary = []
    dfs(j)
    ary.pop(0)
    blo = set(block[i])
    cnt = set(ary) - blo
    c += len(cnt)
  ans[i] = c
print (*ans)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)

n, m, k = map(int, input().split())
ab = [[] for i in range(n)]

for i in range(m):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  ab[a].append(b)
  ab[b].append(a)

block = [set() for i in range(n)]
for i in range(k):
  c, d = map(int, input().split())
  c -= 1
  d -= 1
  block[c].add(d)
  block[d].add(c)

ans = [0 for i in range(n)]

def dfs(s):
  if vis[s] == False:
    vis[s] = True
    r[cnt].add(s)
    for i in ab[s]:
      dfs(i)

vis = [False for i in range(n)]
r = []
cnt = 0
for i in range(n):
  if vis[i] == False:
    r.append(set())
    dfs(i)
    cnt += 1

ans = [0 for i in range(n)]
for i in r:
  l = len(i)
  for j in i:
    ans[j] = l - len(ab[j]) - len(i&block[j]) - 1

print (*ans)
Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())

ab = []
for i in range(n):
  a,b = map(int, input().split())
  ab.append([a, b])


dp = [10**9 for i in range((h+1)+10000)]
dp[0] = 0
for i in range(1, (h+1)+10000):
  for j in range(n):
    a, b = ab[j]
    if a > i:
      continue
    dp[i] = min(dp[i], dp[i-a]+b)

x = min(dp[h:])
print (x)

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

ab = []
for i in range(n):
  a,b = map(int, input().split())
  ab.append([a, b])


dp = [10**9 for i in range((h+1)+10000)]
dp[0] = 0
for i in range(1, (h+1)+10000):
  for j in range(n):
    a, b = ab[j]
    if a > i:
      continue
    dp[i] = min(dp[i], dp[i-a]+b)

x = min(dp[h:])
print (x)
Buggy python submission (verdict: Runtime Error):
k, x = map(int, input().spilt())
if 500*k >= x:
	print("Yes")
else:
	print ("No")

Fixed submission:
k, x = map(int, input().split())
if k*500 >= x:
	print ("Yes")
else:
	print ("No")
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
res = 0
chk1 = -1
chk2 = -1
chk3 = -1

a = []
b = []
c = []
for i,j in enumerate(list(t)):
	if j == "s":
		if i in a:
			a.remove(i)
			continue
		res += r
		chk1 = i+k
		a.append(chk1)
	if j == "p":
		if i in b:
			b.remove(i)
			continue
		res += s
		chk2 = i+k
		b.append(chk2)
	if j == "r":
		if i in c:
			c.remove(i)
			continue
		res += p
		chk3 = i+k
		c.append(chk3)
print (res)

Fixed submission:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())
res = 0
for i in range(n):
	if t[i] == t[i-k] and i >= k:
		t[i] = "X"
	if t[i] == "s":
		res += r
	if t[i] == "p":
		res += s
	if t[i] == "r":
		res += p
print (res)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
res = 0
chk1 = -1
chk2 = -1
chk3 = -1

a = []
b = []
c = []
for i,j in enumerate(list(t)):
	if j == "s":
		if i in a:
			continue
		res += r
		chk1 = i+k
		a.append(chk1)
	if j == "p":
		if i in b:
			continue
		res += s
		chk2 = i+k
		b.append(chk2)
	if j == "r":
		if i in c:
			continue
		res += p
		chk3 = i+k
		c.append(chk3)
print (res)

Fixed submission:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())
res = 0
for i in range(n):
	if t[i] == t[i-k] and i >= k:
		t[i] = "X"
	if t[i] == "s":
		res += r
	if t[i] == "p":
		res += s
	if t[i] == "r":
		res += p
print (res)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
res = 0
chk = -1
a = []
for i,j in enumerate(list(t)):
	if j == "s":
		if i in a:
			continue
		res += r
		chk = i+k
		a.append(chk)
chk = -1
a = []
for i,j in enumerate(list(t)):
	if j == "p":
		if i in a:
			continue
		res += s
		chk = i+k
		a.append(chk)
chk = -1
a = []
for i,j in enumerate(list(t)):
	if j == "r":
		if i in a:
			continue
		res += p
		chk = i+k
		a.append(chk)
print (res)

Fixed submission:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())
res = 0
for i in range(n):
	if t[i] == t[i-k] and i >= k:
		t[i] = "X"
	if t[i] == "s":
		res += r
	if t[i] == "p":
		res += s
	if t[i] == "r":
		res += p
print (res)
Buggy python submission (verdict: Runtime Error):
s = input()
cnt = 0
flg = 0
i = 0
j = -1
while flg == 0:
	if s[i] != s[j]:
		cnt += 1
	#print (s[i],s[j])
	if len(s)//2 == i+1:
		flg =1
	i += 1
	j += -1
print (cnt)


Fixed submission:
s = input()
cnt = 0
flg = 0
i = 0
j = -1
if len(s) == 1:
	print (0)
	exit()
while flg == 0:
	if s[i] != s[j]:
		cnt += 1
	#print (s[i],s[j])
	if len(s)//2 == i+1:
		flg =1
	i += 1
	j += -1
print (cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 0
mod = 10**9+7
for i in range(60):
	x = 0
	for j in a:
		if j >> i & 1:
			x += 1
	ans += x * (n-x)*(2**i)%mod
print(ans%mod)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
ans = 0
for i in range(61):
	x = 0
	for j in a:
		if j >> i & 1:
			x += 1
	z = x*(n-x)%mod
	z *= 2**i
	z %= mod
	ans += z
	ans %= mod
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
ans = 0
for i in range(61):
	x = 0
	for j in a:
		if j >> i & 1:
			x += 1
	z = x*(n-x)%mod
	z *= 2**i
	z %= mod
	ans += z
	ans %= mod
print (ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
ans = 0
for i in range(61):
	x = 0
	for j in a:
		if j >> i & 1:
			x += 1
	z = x*(n-x)%mod
	z *= 2**i
	z %= mod
	ans += z
	ans %= mod
print (ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
n = int(input())
s = input()
for i in range(10):
	c = str(i)
	if c.count(s) >= 4:
		s = s.replace(c, "")
		s = s + c*3
a = list(combinations(list(s),3))
b = set(a)
print (len(b))

Fixed submission:
n = int(input())
s = input()

a = ["0","1","2","3","4","5","6","7","8","9"]

c = 0

for i in a:
	for j in a:
		for k in a:
			d = s.find(i)
			if d == -1:
				continue
			e = s[d+1:].find(j)
			if e == -1:
				continue
			e += d+1
			f = s[e+1:].find(k)
			if f == -1:
				continue
			c += 1
print (c)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
n = int(input())
s = list(input())
a = list(combinations(s,3))
b = set(a)
print (len(b))

Fixed submission:
n = int(input())
s = input()

a = ["0","1","2","3","4","5","6","7","8","9"]

c = 0

for i in a:
	for j in a:
		for k in a:
			d = s.find(i)
			if d == -1:
				continue
			e = s[d+1:].find(j)
			if e == -1:
				continue
			e += d+1
			f = s[e+1:].find(k)
			if f == -1:
				continue
			c += 1
print (c)
Buggy python submission (verdict: Runtime Error):
a, b, x = map(int, input().split())
q = x//a
k = len(str(q))
ary = []
for i in range(k-1, k+1):
	if len(str((x-b*i)//a)) == i:
		if (x-b*i)//a > 10**9:
			if a * 10**9 + b * 10 <= x:
				ary.append(10**9)
		else:
			ary.append(min((x-b*i)//a, 10 ** i - 1))
if len(ary) == 0:
	print (0)
else:
	print (max(ary))


Fixed submission:
n = input()

if n == "SAT":
	print (1)
elif n == "SUN":
	print (7)
elif n == "MON":
	print (6)
elif n == "TUE":
	print (5)
elif n == "WED":
	print (4)
elif n == "THU":
	print (3)
else:
	print (2)
Buggy python submission (verdict: Runtime Error):
n = int(input())

a = [set() for i in range(n)]

for i in range(n-1):
  b, c = map(int, input().split())
  b -= 1
  c -= 1
  if i == 0:
    s = b
  a[b].add(c)
  a[c].add(b)

col = [0 for i in range(n)]
visited = [False for i in range(n)]
visited[0] = True

def dfs(s,k):
  visited[s] = True
  col[s] = k
  j = 1
  for i in a[s]:
    if visited[i] == False:
      if col[s] == j:
        j += 1
      dfs(i,j)
      j += 1

dfs(0,0)

print (max(col))
for i in col[1:]:
  print (i)

Fixed submission:
from collections import deque
n = int(input())
a = [[] for i in range(n)]
e = []
for i in range(n-1):
  b, c = map(int, input().split())
  b -= 1
  c -= 1
  a[b].append(c)
  e.append(c)
col = [0 for i in range(n)]
v = deque([0])

while v:
  d = v.popleft()
  k = 1
  for i in a[d]:
    if col[d] == k:
      k += 1
    col[i] = k
    v.append(i)
    k += 1
print (max(col))
for i in e:
  print(col[i])
Buggy python submission (verdict: Runtime Error):
n = int(input())
d = list(map(int ,input().split()))

d.sort()
mod = 998244353
s = [0 for i in range(max(d)+1)]

for i in range(n):
  s[d[i]] += 1
ans = 1
for i in range(len(s)):
  if s[i] == 0:
    print (0)
    exit()
  if i == 0:
    if s[i] > 1:
      print (0)
      exit()
    continue
  ans *= s[i-1]**(s[i])
  ans %= mod
print (ans)

Fixed submission:
n = int(input())
cnt = 0
for i in range(n//2):
	if (i+1)+ (i+1) == n:
		continue
	cnt +=1
print (cnt)
Buggy python submission (verdict: Runtime Error):
s = input()
b = []
sho = 0
dai = 0
for i in range(len(s)):
	if(i == 0 and s[i+1] == ">"):continue
	if s[i] == "<":
		dai = 0
		sho += 1
		b.append(sho)
	else:
		sho = 0
		if(s[i-1] == "<" and i != 1):continue
		dai += 1
		b.append(dai)
#print(b)
print (sum(b))

Fixed submission:
s = input()
a = [0]*(len(s)+1)

for i in range(len(s)):
  if s[i] == '<':
    a[i+1] = max(a[i+1],a[i]+1)

for i in range(len(s)-1,-1,-1):
  if s[i] == '>':
    a[i] = max(a[i],a[i+1]+1)
print (sum(a))

Buggy python submission (verdict: Runtime Error):
s = input()
b = []
sho = 0
dai = 0
for i in range(len(s)):
	if(i == 0 and s[i+1] == ">"):continue
	if s[i] == "<":
		dai = 0
		sho += 1
		b.append(sho)
	else:
		oldsho = sho
		sho = 0
		if(oldsho >= 2):
			dai = -1
		elif(s[i-1] == "<"):
			dai = 0
		dai += 1
		b.append(dai)
print (sum(b))


Fixed submission:
s = input()
a = [0]*(len(s)+1)

for i in range(len(s)):
  if s[i] == '<':
    a[i+1] = max(a[i+1],a[i]+1)

for i in range(len(s)-1,-1,-1):
  if s[i] == '>':
    a[i] = max(a[i],a[i+1]+1)
print (sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
n = int(input())
l = list(map(int, input().split()))

ll = list(combinations(l,3))
cnt = 0
for i in ll:
	a,b,c=i[0],i[1],i[2]
	if a < b+c and b < c+a and c < a+b:
		cnt += 1
print (cnt)

Fixed submission:
import bisect
n = int(input())
l = map(int, input().split())
l = sorted(l)

cnt = 0
for i in range (n-2):
	for j in range (i+1, n-1):
		ab = l[i] + l[j]
		r = bisect.bisect_left(l, ab)
		cnt += r - j - 1

print (cnt)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
dp = [[0 for i in range(5001)] for j in range(5001)]

for i in range(n-1,-1,-1):
	for j in range(n-1,-1,-1):
		if s[i] != s[j]:
			dp[i][j] = 0
		else:
			dp[i][j] = dp[i+1][j+1] + 1

res = 0
for i in range(n):
	for j in range(n):
		if i >= j:
			continue
		x = min(dp[i][j], j-i)
		res = max(x,res)
print (res)

Fixed submission:
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = [-i for i in a]
heapq.heapify(b)
for i in range(m):
	c = heapq.heappop(b)
	c *= -1
	c //= 2
	heapq.heappush(b,-c)
s = -sum(b)
print (s)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
dp = [[0 for i in range(5001)] for j in range(5001)]

for i in range(n-1,-1,-1):
	for j in range(n-1,-1,-1):
		if s[i] != s[j]:
			dp[i][j] = 0
		else:
			dp[i][j] = dp[i+1][j+1] + 1

res = 0
for i in range(n):
	for j in range(n):
		if i >= j:
			continue
		x = min(dp[i][j], j-i)
		res = max(x,res)
print (res)

Fixed submission:
n = int(input())
s = input()
dp = [[0 for i in range(5001)] for j in range(5001)]

for i in range(n-1,-1,-1):
	for j in range(n-1,-1,-1):
		if s[i] != s[j]:
			dp[i][j] = 0
		else:
			dp[i][j] = dp[i+1][j+1] + 1

res = 0
for i in range(n):
	for j in range(n):
		if i >= j:
			continue
		x = min(dp[i][j], j-i)
		res = max(x,res)
print (res)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = ["".join(sorted(input())) for i in range(n)]
cnt = 0
for i in range(n):
	for j in range(i+1,n):
		if a[i] == a[j]:
			cnt += 1
print (cnt)


Fixed submission:
n = int(input())
s = []
d = {}
for i in range(n):
	x = input()
	l = list(x)
	list.sort(l)
	ll = "".join(l)
	if ll in d:
		d[ll] += 1
	else:
		d[ll] = 1

ans = 0
for i in d:
	ss = d[i]
	if d[i] >= 2:
		ans += ss*(ss-1)/2
print (int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import collections
n = int(input())
a = [input() for i in range(n)]

p = itertools.combinations(a,2)
cnt = 0
for i,j in p:
	s = sorted(list(i))
	t = sorted(list(j))
	if s == t:
		cnt += 1
		#print (i,j)
print (cnt)

Fixed submission:
n = int(input())
s = []
d = {}
for i in range(n):
	x = input()
	l = list(x)
	list.sort(l)
	ll = "".join(l)
	if ll in d:
		d[ll] += 1
	else:
		d[ll] = 1

ans = 0
for i in d:
	ss = d[i]
	if d[i] >= 2:
		ans += ss*(ss-1)/2
print (int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
l, r = map(int, input().split())
if r-l >2019:
	l += 2019
s = 10**9
for i in range(l,r+1):
	for j in range(i+1,r+1):
		s = min(s,i*j%2019)
print (s)


Fixed submission:
l, r = map(int, input().split())
a = 10**5
if r - l >= 2017:
	print (0)
	exit()
else:
	for i in range(l,r+1):
		for j in range(i+1,r+1):
			a = min(a,i*j%2019)
print (a)

Buggy python submission (verdict: Runtime Error):
l, r = map(int, input().split())
if r-l >= 2017:
	print (0)
	exit()
else:
	for i in range(l,r+1):
		for j in range(i+1,r+1):
			a = min(a,i*j%2019)
print (a)

Fixed submission:
l, r = map(int, input().split())
a = 10**5
if r - l >= 2017:
	print (0)
	exit()
else:
	for i in range(l,r+1):
		for j in range(i+1,r+1):
			a = min(a,i*j%2019)
print (a)

Buggy python submission (verdict: Time Limit Exceeded):
l, r = map(int, input().split())
a = 10**5
for i in range(l,r+1):
	for j in range(i+1,r+1):
		a = min(a,i*j%2019)
print (a)


Fixed submission:
l, r = map(int, input().split())
a = 10**5
if r - l >= 2017:
	print (0)
	exit()
else:
	for i in range(l,r+1):
		for j in range(i+1,r+1):
			a = min(a,i*j%2019)
print (a)
Buggy python submission (verdict: Runtime Error):
l, r = map(int, input().split())
if r-l >= 2017:
	print (0)
	exit()
else:
	for i in range(l,r+1):
		for j in range(i+1,r+1):
			a = min(a,i*j%2019)
print (a)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
x1 = 0
x1 = sum(a)-sum(a[1::2])*2
x = []
x.append(x1)
for i in range(n-1):
	xx = a[i]*2 - x[-1]
	x.append(xx)
print (*x)
Buggy python submission (verdict: Runtime Error):
import math
a, b, c, d = map(int, input().split())

def lcm(x,y):
	return (x*y)//math.gcd(x,y)
e = lcm(c,d)

f = (b//c + b//d) - b//e
g = ((a-1)//c + (a-1)//d) - (a-1)//e
print (b-a+1-(f-g))

Fixed submission:
from fractions import gcd
a, b, c, d = map(int, input().split())
cnt = 0
def lcm(x, y):
	return (x*y) // gcd(x,y)
e = lcm(c,d)
x = b//c + b//d - b//e
y = (a-1)//c + (a-1)//d - (a-1)//e
print (b-a+1-(x-y))
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = []
a = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
	ss = input()
	s.append(ss)
	b = 0
	for j,k in enumerate(ss):
		if k == "#":
			b = 0
			a[i][j] == 0
		else:
			b += 1
			a[i][j] = b
	mx = 0
	for j in range(w-1,-1,-1):
		if a[i][j] == 0:
			mx = 0
			continue
		else:
			mx = max(a[i][j],mx)
			a[i][j] = mx

c = [[0 for i in range(h)] for j in range(w)]
for i in range(w):
	v = ""
	b = 0
	for j in range(h):
		v += s[j][i]
	for j,k in enumerate(v):
		if k == "#":
			b = 0
			c[i][j] == 0
		else:
			b += 1
			c[i][j] = b
	mx = 0
	for j in range(h-1,-1,-1):
		if c[i][j] == 0:
			mx = 0
			continue
		else:
			mx = max(c[i][j],mx)
			c[i][j] = mx

wk = 0
ans = 0
for i in range(h):
	for j in range(w):
		wk = a[i][j] + c[j][i] -1
		ans = max(ans,wk)
print (ans)

Fixed submission:
a = list(map(int, input().split()))
a.sort()
print (a[0] + a[1])
Buggy python submission (verdict: Time Limit Exceeded):
n, m =map(int, input().split())
a=list(map(int, input().split()))
for i in range(m):
  b,c =map(int, input().split())
  d = [c]*b
  a.extend(d)
a.sort(reverse=True)
print (sum(a[:n]))

Fixed submission:
import heapq
from collections import defaultdict
n, m =map(int, input().split())
a=list(map(int, input().split()))

for i in range(n):
  a[i] *= -1


pri=list(set(a))
heapq.heapify(pri)
dict=defaultdict(int)
for i in a:
  dict[-i] += 1
for i in range(m):
  b, c = map(int, input().split())
  dict[c] += b
  heapq.heappush(pri,-c)
# print (pri)
# print (dict)

ans = 0
cnt = 0
old = 0
while True:
  x = heapq.heappop(pri)
  x *= -1
  if old == x:
    continue
  if cnt+dict[x] > n:
    ans += (n-cnt)*x
    cnt += n-cnt
  else:
    ans += dict[x]*x
    cnt += dict[x]
  if cnt >= n:
    break
  old = x
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect, heapq
n,m = map(int, input().split())
a = list(map(int, input().split()))
heapq.heapify(a)


b = []
for i in range(m):
	x, y = map(int, input().split())
	b.append([x,y])

for i in range(m):
	c = []
	for j in range(b[i][0]):
		x = heapq.heappop(a)
		if x >= b[i][1]:
			c.append(x)
			break
		x = b[i][1]
		c.append(x)
	for j in c:
		heapq.heappush(a,j)
print (sum(a))


Fixed submission:
import heapq
from collections import defaultdict
n, m =map(int, input().split())
a=list(map(int, input().split()))

for i in range(n):
  a[i] *= -1


pri=list(set(a))
heapq.heapify(pri)
dict=defaultdict(int)
for i in a:
  dict[-i] += 1
for i in range(m):
  b, c = map(int, input().split())
  dict[c] += b
  heapq.heappush(pri,-c)
# print (pri)
# print (dict)

ans = 0
cnt = 0
old = 0
while True:
  x = heapq.heappop(pri)
  x *= -1
  if old == x:
    continue
  if cnt+dict[x] > n:
    ans += (n-cnt)*x
    cnt += n-cnt
  else:
    ans += dict[x]*x
    cnt += dict[x]
  if cnt >= n:
    break
  old = x
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect, heapq
n,m = map(int, input().split())
a = list(map(int, input().split()))
heapq.heapify(a)


b = []
for i in range(m):
	x, y = map(int, input().split())
	b.append([x,y])

for i in range(m):
	c = []
	for j in range(b[i][0]):
		x = heapq.heappop(a)
		if x >= b[i][1]:
			c.append(x)
			break
		x = b[i][1]
		c.append(x)
	for j in c:
		heapq.heappush(a,j)
print (sum(a))


Fixed submission:
import heapq
from collections import defaultdict
n, m =map(int, input().split())
a=list(map(int, input().split()))

for i in range(n):
  a[i] *= -1


pri=list(set(a))
heapq.heapify(pri)
dict=defaultdict(int)
for i in a:
  dict[-i] += 1
for i in range(m):
  b, c = map(int, input().split())
  dict[c] += b
  heapq.heappush(pri,-c)
# print (pri)
# print (dict)

ans = 0
cnt = 0
old = 0
while True:
  x = heapq.heappop(pri)
  x *= -1
  if old == x:
    continue
  if cnt+dict[x] > n:
    ans += (n-cnt)*x
    cnt += n-cnt
  else:
    ans += dict[x]*x
    cnt += dict[x]
  if cnt >= n:
    break
  old = x
print (ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

hu = []
sei = []
for i in a:
	if i < 0:
		hu.append(i)
	else:
		sei.append(i)
hu.sort()
sei.sort()
if len(hu)%2 == 0:
	ans = sum(sei) + (-1)*sum(hu)
else:
	b = sei[0]
	c = hu[-1]
	if abs(b) <= abs(c):
		b *= -1
		c *= -1
	ans = sum(sei[1:]) + (-1)*sum(hu[:-1])
	ans += (b+c)
print (ans)


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

hu = []
sei = []
for i in a:
	if i < 0:
		hu.append(i)
	else:
		sei.append(i)
hu.sort()
sei.sort()
if len(hu)%2 == 0:
	ans = sum(sei) + (-1)*sum(hu)
else:
	if len(sei) == 0:
		ans = (-1)*sum(hu[:-1]) + hu[-1]
		print (ans)
		exit()
	else:
		b = sei[0]
	if len(hu) == 0:
		ans = sum(sei[1:] + sei[-1])
		print (ans)
		exit()
	else:
		c = hu[-1]
	if abs(b) <= abs(c):
		b *= -1
		c *= -1
	ans = sum(sei[1:]) + (-1)*sum(hu[:-1])
	ans += (b+c)
print (ans)

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

hu = []
sei = []
for i in a:
	if i < 0:
		hu.append(i)
	else:
		sei.append(i)
hu.sort()
sei.sort()
if len(hu)%2 == 0:
	ans = sum(sei) + (-1)*sum(hu)
else:
	b = sei.pop(0)
	c = hu.pop(-1)
	if abs(b) <= abs(c):
		b *= -1
		c *= -1
	ans = sum(sei) + (-1)*sum(hu)
	ans += (b+c)
print (ans)


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

hu = []
sei = []
for i in a:
	if i < 0:
		hu.append(i)
	else:
		sei.append(i)
hu.sort()
sei.sort()
if len(hu)%2 == 0:
	ans = sum(sei) + (-1)*sum(hu)
else:
	if len(sei) == 0:
		ans = (-1)*sum(hu[:-1]) + hu[-1]
		print (ans)
		exit()
	else:
		b = sei[0]
	if len(hu) == 0:
		ans = sum(sei[1:] + sei[-1])
		print (ans)
		exit()
	else:
		c = hu[-1]
	if abs(b) <= abs(c):
		b *= -1
		c *= -1
	ans = sum(sei[1:]) + (-1)*sum(hu[:-1])
	ans += (b+c)
print (ans)

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

hu = []
sei = []
for i in a:
	if i < 0:
		hu.append(i)
	else:
		sei.append(i)
hu.sort()
sei.sort()
if len(hu)%2 == 0:
	ans = sum(sei) + (-1)*sum(hu)
else:
	b = sei.pop(0)
	b *= -1
	c = hu.pop(-1)
	c *= -1
	ans = sum(sei) + (-1)*sum(hu)
	ans += (b+c)
print (ans)


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

hu = []
sei = []
for i in a:
	if i < 0:
		hu.append(i)
	else:
		sei.append(i)
hu.sort()
sei.sort()
if len(hu)%2 == 0:
	ans = sum(sei) + (-1)*sum(hu)
else:
	if len(sei) == 0:
		ans = (-1)*sum(hu[:-1]) + hu[-1]
		print (ans)
		exit()
	else:
		b = sei[0]
	if len(hu) == 0:
		ans = sum(sei[1:] + sei[-1])
		print (ans)
		exit()
	else:
		c = hu[-1]
	if abs(b) <= abs(c):
		b *= -1
		c *= -1
	ans = sum(sei[1:]) + (-1)*sum(hu[:-1])
	ans += (b+c)
print (ans)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
p = [a, b, c, d, e]

mi = [a%10,b%10,c%10,d%10,e%10]
mm = [i for i in mi if i != 0]
mm.sort()
sum = 0
for i in range(5):
	if p[i]%10 != 0:
		sum += (p[i]//10+1)*10
	else:
		sum += p[i]//10*10
sum -= 10 - mm[0]
print (sum)

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
p = [a, b, c, d, e]

mi = [a%10,b%10,c%10,d%10,e%10]
mm = [i for i in mi if i != 0]
mm.sort()
sum = 0
for i in range(5):
	if p[i]%10 != 0:
		sum += (p[i]//10+1)*10
	else:
		sum += p[i]//10*10
if (mm):
	sum -= 10- mm[0]
print (sum)