Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
H, W, M = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(M)]

board = [[0] * (W + 1) for _ in range(H + 1)]

h_cnt = [0] * (H + 1)
w_cnt = [0] * (W + 1)

for h, w in hw:
    h_cnt[h] += 1
    w_cnt[w] += 1
    board[h][w] = 1

h_mx = max(h_cnt)
w_mx = max(w_cnt)

cnt = h_cnt.count(h_mx) * w_cnt.count(w_mx)
for h, w in hw:
    val = h_cnt[h] + w_cnt[w]
    if val == h_mx + w_mx:
        cnt -= 1

if cnt:
    ans = h_mx + w_mx
else:
    ans = h_mx + w_mx - 1

print(ans)


Fixed submission:
H, W, M = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(M)]

h_cnt = [0] * (H + 1)
w_cnt = [0] * (W + 1)

for h, w in hw:
    h_cnt[h] += 1
    w_cnt[w] += 1

h_mx = max(h_cnt)
w_mx = max(w_cnt)

cnt = h_cnt.count(h_mx) * w_cnt.count(w_mx)
for h, w in hw:
    val = h_cnt[h] + w_cnt[w]
    if val == h_mx + w_mx:
        cnt -= 1

if cnt:
    ans = h_mx + w_mx
else:
    ans = h_mx + w_mx - 1

print(ans)

Buggy python submission (verdict: Runtime Error):
H, W, M = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(M)]

board = [[0] * (W + 1) for _ in range(H + 1)]

h_cnt = [0] * (H + 1)
w_cnt = [0] * (W + 1)

for h, w in hw:
    h_cnt[h] += 1
    w_cnt[w] += 1
    board[h][w] = 1

mx = 0
for h in range(1, H + 1):
    for w in range(1, W + 1):
        val = h_cnt[h] + w_cnt[w] - board[h][w]
        mx = max(mx, val)

print(mx)


Fixed submission:
H, W, M = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(M)]

h_cnt = [0] * (H + 1)
w_cnt = [0] * (W + 1)

for h, w in hw:
    h_cnt[h] += 1
    w_cnt[w] += 1

h_mx = max(h_cnt)
w_mx = max(w_cnt)

cnt = h_cnt.count(h_mx) * w_cnt.count(w_mx)
for h, w in hw:
    val = h_cnt[h] + w_cnt[w]
    if val == h_mx + w_mx:
        cnt -= 1

if cnt:
    ans = h_mx + w_mx
else:
    ans = h_mx + w_mx - 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p = [0] + list(map(int, input().split()))
c = [0] + list(map(int, input().split()))

score_cnt = [None] * (n + 1)
for i in range(1, n + 1):
    now = i
    cnt = 0
    score = 0
    for _ in range(n):
        now = p[now]
        score += c[now]
        cnt += 1
        if now == i:
            score_cnt[i] = [score, cnt]
            break

ans = - 10 ** 20
for i in range(1, n + 1):
    now = i
    score = 0
    left = k
    for j in range(n):
        now = p[now]
        score += c[now]
        left -= 1
        if left >= 0:
            times = left // score_cnt[now][1]
            score_loop = score + times * score_cnt[now][0]
            ans = max(ans, score, score_loop)

print(ans)


Fixed submission:
n, k = map(int, input().split())
p = [0] + list(map(int, input().split()))
c = [0] + list(map(int, input().split()))

score_cnt = [None] * (n + 1)
for i in range(1, n + 1):
    now = i
    cnt = 0
    score = 0
    for _ in range(n):
        now = p[now]
        score += c[now]
        cnt += 1
        if now == i:
            score_cnt[i] = [score, cnt]
            break

ans = - 10 ** 20
for i in range(1, n + 1):
    now = i
    score = 0
    left = k
    for j in range(n):
        now = p[now]
        score += c[now]
        left -= 1
        if left >= 0:
            times = left // score_cnt[now][1]
            score_loop = score + times * score_cnt[now][0]
            ans = max(ans, score, score_loop)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())

num = 0
ans = -1
for i in range(10 ** 7):
    num *= 10
    num += 7
    num %= k
    if num == 0:
        ans = i + 1
        break

print(ans)


Fixed submission:
k = int(input())

num = 0
ans = -1
for i in range(10 ** 7):
    num *= 10
    num += 7
    num %= k
    if num == 0:
        ans = i + 1
        break

print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

if max(a) < 0:
    a.sort()
    ans = 1
    if k % 2 == 0:
        for e in a[:k]:
            ans *= e
            ans %= mod
    else:
        for e in a[-k:]:
            ans *= e
            ans %= mod

    print(ans)

else:
    neg = []
    pos = []
    for e in a:
        if e < 0:
            neg.append(e)
        else:
            pos.append(e)

    neg.sort()
    pos.sort(reverse=True)

    ans = 1
    if k % 2:
        ans *= pos.pop(0)
        k -= 1

    nums = [e1 * e2 for e1, e2 in zip(neg[::2], neg[1::2])]
    nums += [e1 * e2 for e1, e2 in zip(pos[::2], pos[1::2])]
    if len(neg) % 2:
        nums += neg[-1]
    if len(pos) % 2:
        nums += pos[-1]

    nums.sort(reverse=True)
    for e in nums[:k//2]:
        ans *= e
        ans %= mod

    print(ans)


Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

if max(a) < 0:
    a.sort()
    ans = 1
    if k % 2 == 0:
        for e in a[:k]:
            ans *= e
            ans %= mod
    else:
        for e in a[-k:]:
            ans *= e
            ans %= mod

    print(ans)

elif k == n:
    ans = 1
    for e in a:
        ans *= e
        ans %= mod

    print(ans)

else:
    neg = []
    pos = []
    for e in a:
        if e < 0:
            neg.append(e)
        else:
            pos.append(e)

    neg.sort()
    pos.sort(reverse=True)

    ans = 1
    if k % 2:
        ans *= pos.pop(0)
        k -= 1

    nums = [e1 * e2 for e1, e2 in zip(neg[::2], neg[1::2])]
    nums += [e1 * e2 for e1, e2 in zip(pos[::2], pos[1::2])]

    nums.sort(reverse=True)
    for e in nums[:k//2]:
        ans *= e
        ans %= mod

    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from numba import njit

n = int(input())


@njit
def f(n):
    cnt = np.zeros(n + 1, np.int32)
    for i in range(1, n + 1):
        cnt[i::i] += 1

    return (cnt * np.arange(n + 1)).sum()


ans = f(n)
print(ans)


Fixed submission:
n = int(input())

ans = 0
for i in range(1, n + 1):
    cnt = n // i
    ub = i * cnt
    ans += (i + ub) * cnt // 2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate

n, k = map(int, input().split())
a = list(map(int, input().split()))

cnt = 1
while cnt <= k and min(a) < n:
    li = [0] * (n + 1)
    for i, e in enumerate(a):
        l = max(0, i - e)
        r = min(n, i + e + 1)
        li[l] += 1
        li[r] -= 1

    a = list(accumulate(li))[:-1]

    cnt += 1

print(*a)


Fixed submission:
from itertools import accumulate

n, k = map(int, input().split())
a = list(map(int, input().split()))

cnt = 1
while cnt <= k and min(a) < n:
    li = [0] * (n + 1)
    for i, e in enumerate(a):
        l = max(0, i - e)
        r = min(n, i + e + 1)
        li[l] += 1
        li[r] -= 1

    a = list(accumulate(li))[:-1]

    cnt += 1

print(*a)
Buggy python submission (verdict: Time Limit Exceeded):
def sieve(x):
    """
    Sieve of Eratosthenes
    :param x: max value
    :return: list of bool
    """

    is_prime = [True] * (x + 1)
    is_prime[0] = is_prime[1] = False

    for i in range(2, x + 1):
        if is_prime[i]:
            for j in range(i * 2, x + 1, i):
                is_prime[j] = False

    return is_prime


def f(x):
    if x < 2:
        return False

    i = 2
    while i * i <= x:
        if x % i == 0:
            return False
        i += 1

    return True


n = int(input())

if f(n):
    print(1)
    exit()

is_prime = sieve(10 ** 7)
primes = [i for i, e in enumerate(is_prime) if e]

ans = 0
used = set()
for e in primes:
    div = e
    while div <= n:
        if n % div == 0:
            ans += 1
            n //= div
            used.add(div)
        div *= e


print(ans)


Fixed submission:
from collections import defaultdict


def sieve(x):
    """
    Sieve of Eratosthenes
    :param x: max value
    :return: list of bool
    """

    is_prime = [True] * (x + 1)
    is_prime[0] = is_prime[1] = False

    for i in range(2, x + 1):
        if is_prime[i]:
            for j in range(i * 2, x + 1, i):
                is_prime[j] = False

    return is_prime


n = int(input())

is_prime = sieve(10 ** 6)
primes = [i for i, e in enumerate(is_prime) if e]

d = defaultdict(int)
for e in primes:
    while n % e == 0:
        n //= e
        d[e] += 1

if n != 1:
    d[n] += 1

ans = 0
for v in d.values():
    mn = 1
    while v >= mn:
        v -= mn
        ans += 1
        mn += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, s = map(int, input().split())
a = list(map(int, input().split()))
mod = 998244353

dp = [[0] * (s + 1) for _ in range(n + 1)]
dp[0][0] = 1

for i, e in enumerate(a, 1):
    for j in range(s + 1):
        dp[i][j] += 2 * dp[i-1][j]
        if j - e >= 0:
            dp[i][j] += dp[i-1][j-e]

        dp[i][j] %= mod

ans = dp[n][s]
print(ans)



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

dp = [[0] * (s + 1) for _ in range(n + 1)]
dp[0][0] = 1

for i, e in enumerate(a, 1):
    for j in range(s + 1):
        dp[i][j] += 2 * dp[i-1][j]
        if j - e >= 0:
            dp[i][j] += dp[i-1][j-e]

        dp[i][j] %= mod

ans = dp[n][s]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
MAX = 60

to = [[0] * (n + 1) for _ in range(MAX)]

to[0] = a

for i in range(1, MAX):
    for j in range(1, n + 1):
        to[i][j] = to[i-1][to[i-1][j]]

v = 1
for i in range(MAX - 1, -1, -1):
    num = 1 << i
    if k >= num:
        v = to[i][v]
        k -= num

print(v)


Fixed submission:
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))

st = set()
i = 1
li = []
while i not in st:
    st.add(i)
    li.append(i)
    i = a[i]

s = i
until_s = li.index(s)

if k < until_s:
    i = 1
    for _ in range(k):
        i = a[i]

    ans = i

else:
    k -= until_s
    loop_size = len(li) - until_s
    sim_time = k % loop_size
    i = s
    for _ in range(sim_time):
        i = a[i]

    ans = i

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def check(li):
    b = 0
    for eb, eh in li:
        if b + eb < 0:
            return False

        b += eh

    return True


n = int(input())
s = [input() for _ in range(n)]

l = []
r = []
sm = 0
for word in s:
    h = 0
    b = 0
    for e in word:
        if e == "(":
            h += 1
        else:
            h -= 1

        b = min(b, h)

    if h > 0:
        l.append([b, h])
    else:
        r.append([b-h, -h])

    sm += h

l.sort(reverse=True)
r.sort(reverse=True)

if check(l) and check(r) and sm == 0:
    ans = "Yes"
else:
    ans = "No"
print(ans)


Fixed submission:
n = int(input())
s = [input() for _ in range(n)]

l = 0
r = 0
m = []


def fin():
    print("No")
    exit()


for word in s:
    stack = []
    for e in word:
        if stack and stack[-1] == "(" and e == ")":
            stack.pop()
        else:
            stack.append(e)

    if stack:
        if stack[0] == ")" and stack[-1] == "(":
            m.append(stack)
        elif stack[0] == ")":
            r += len(stack)
        else:
            l += len(stack)

ml = []
mm = 0
mr = []

for word in m:
    ll = word.index("(")
    rr = len(word) - ll
    if ll > rr:
        mr.append([ll, rr])
    elif ll < rr:
        ml.append([ll, rr])
    else:
        mm = max(mm, ll)

ml.sort()
for ll, rr in ml:
    l -= ll

    if l < 0:
        fin()

    l += rr

mr.sort(key=lambda x: x[1])
for ll, rr in mr:
    r -= rr

    if r < 0:
        fin()

    r += ll

if mm <= l or mm <= r:
    if l == r:
        print("Yes")
        exit()

fin()
Buggy python submission (verdict: Runtime Error):
n, a, b, c = map(int, input().split())
s = [input() for _ in range(n)]

a = min(a, 1)
b = min(b, 1)
c = min(c, 1)

ans = []

d = {"A": a, "B": b, "C": c}


def dfs(i):
    if min(d.values()) < 0:
        return

    if i == n:
        print("Yes")
        print(*ans, sep="\n")
        exit()

    k1, k2 = s[i]

    d[k1] += 1
    d[k2] -= 1
    ans.append(k1)
    dfs(i+1)
    d[k1] -= 1
    d[k2] += 1
    ans.pop()

    d[k2] += 1
    d[k1] -= 1
    ans.append(k2)
    dfs(i+1)
    d[k2] -= 1
    d[k1] += 1
    ans.pop()


dfs(0)

print("No")


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

n, a, b, c = map(int, input().split())
s = [input() for _ in range(n)]

ans = []

d = {"A": a, "B": b, "C": c}


def dfs(i):
    if min(d.values()) < 0:
        return

    if i == n:
        print("Yes")
        print(*ans, sep="\n")
        exit()

    k1, k2 = s[i]

    d[k1] += 1
    d[k2] -= 1
    ans.append(k1)
    dfs(i+1)
    d[k1] -= 1
    d[k2] += 1
    ans.pop()

    d[k2] += 1
    d[k1] -= 1
    ans.append(k2)
    dfs(i+1)
    d[k2] -= 1
    d[k1] += 1
    ans.pop()


dfs(0)

print("No")
Buggy python submission (verdict: Time Limit Exceeded):
def f(x):
    return (a * x) // b - a * (x // b)


a, b, n = map(int, input().split())

k = (n + 1) // b

ans = 0
for x in range(max(0, k * b - 1), n + 1):
    ans = max(ans, f(x))

print(ans)


Fixed submission:
def f(x):
    return (a * x) // b - a * (x // b)


a, b, n = map(int, input().split())

k = (n + 1) // b

x = max(k * b - 1, 0)
ans = f(x)
ans = max(ans, f(n))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)

from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))
uv = [list(map(int, input().split())) for _ in range(n - 1)]

adj = [[] for _ in range(n)]
for u, v in uv:
    u -= 1
    v -= 1
    adj[u].append(v)
    adj[v].append(u)

arrived = [False] * n

ans = [None] * n
ans[0] = 1


def dfs(u, dp, l):
    arrived[u] = True
    for v in adj[u]:
        if not arrived[v]:
            idx = bisect_left(dp, a[v])
            if idx == l:
                dp_nxt = dp + [a[v]]
                ans[v] = l + 1
                dfs(v, dp_nxt, l + 1)
            else:
                dp_nxt = dp[:idx] + [min(a[v], dp[idx])] + dp[idx+1:]
                ans[v] = l
                dfs(v, dp_nxt, l)


dfs(0, [a[0]], 1)
print(*ans, sep="\n")



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

from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))
uv = [list(map(int, input().split())) for _ in range(n - 1)]

INF = 10 ** 10

adj = [[] for _ in range(n)]
for u, v in uv:
    u -= 1
    v -= 1
    adj[u].append(v)
    adj[v].append(u)

arrived = [False] * n

ans = [None] * n
ans[0] = 1

dp = [INF] * n


def dfs(u):
    arrived[u] = True
    for v in adj[u]:
        if not arrived[v]:
            idx = bisect_left(dp, a[v])
            tmp = dp[idx]
            dp[idx] = a[v]
            ans[v] = bisect_left(dp, INF - 1)
            dfs(v)
            dp[idx] = tmp


dp[0] = a[0]
dfs(0)
print(*ans, sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)

from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))
uv = [list(map(int, input().split())) for _ in range(n - 1)]

adj = [[] for _ in range(n)]
for u, v in uv:
    u -= 1
    v -= 1
    adj[u].append(v)
    adj[v].append(u)

arrived = [False] * n

ans = [None] * n
ans[0] = 1


def dfs(u, dp, l):
    arrived[u] = True
    for v in adj[u]:
        if not arrived[v]:
            idx = bisect_left(dp, a[v])
            if idx == l:
                dp_nxt = dp + [a[v]]
                ans[v] = l + 1
                dfs(v, dp_nxt, l + 1)
            else:
                dp_nxt = dp[:idx] + [min(a[v], dp[idx])] + dp[idx+1:]
                ans[v] = l
                dfs(v, dp_nxt, l)


dfs(0, [a[0]], 1)
print(*ans, sep="\n")



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

from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))
uv = [list(map(int, input().split())) for _ in range(n - 1)]

INF = 10 ** 10

adj = [[] for _ in range(n)]
for u, v in uv:
    u -= 1
    v -= 1
    adj[u].append(v)
    adj[v].append(u)

arrived = [False] * n

ans = [None] * n
ans[0] = 1

dp = [INF] * n


def dfs(u):
    arrived[u] = True
    for v in adj[u]:
        if not arrived[v]:
            idx = bisect_left(dp, a[v])
            tmp = dp[idx]
            dp[idx] = a[v]
            ans[v] = bisect_left(dp, INF - 1)
            dfs(v)
            dp[idx] = tmp


dp[0] = a[0]
dfs(0)
print(*ans, sep="\n")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

s = input()
mod1 = 673
mod2 = 3

num1 = 0
num2 = 0
li1 = []
li2 = []
pw = 10
for i, e in enumerate(s, 1):
    num1 *= 10
    num1 += int(e)
    num1 %= mod1
    inv = pow(pw, mod1 - 2, mod1)
    li1.append(num1 * inv % mod1)

    num2 *= 10
    num2 += int(e)
    num2 %= mod2
    inv = pow(pw, mod2 - 2, mod2)
    li2.append(num2 * inv % mod2)

    pw *= 10

li = [0] + [10 * e1 + e2 for e1, e2 in zip(li1, li2)]
c = Counter(li)

ans = 0
for v in c.values():
    ans += v * (v - 1) // 2

print(ans)


Fixed submission:
from collections import Counter

s = input()
mod1 = 673
mod2 = 3

num1 = 0
num2 = 0
li1 = []
li2 = []
pw1 = 10
pw2 = 10
for i, e in enumerate(s, 1):
    num1 *= 10
    num1 += int(e)
    num1 %= mod1
    inv = pow(pw1, mod1 - 2, mod1)
    li1.append(num1 * inv % mod1)

    num2 *= 10
    num2 += int(e)
    num2 %= mod2
    inv = pow(pw2, mod2 - 2, mod2)
    li2.append(num2 * inv % mod2)

    pw1 *= 10
    pw1 %= mod1
    pw2 *= 10
    pw2 %= mod2

li = [0] + [10 * e1 + e2 for e1, e2 in zip(li1, li2)]
c = Counter(li)

ans = 0
for v in c.values():
    ans += v * (v - 1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

s = input()
mod1 = 673
mod2 = 3

num1 = 0
num2 = 0
li1 = []
li2 = []
for i, e in enumerate(s, 1):
    num1 *= 10
    num1 += int(e)
    num1 %= mod1
    inv = pow(pow(10, i + 1), mod1 - 2, mod1)
    li1.append(num1 * inv % mod1)

    num2 *= 10
    num2 += int(e)
    num2 %= mod2
    inv = pow(pow(10, i + 1), mod2 - 2, mod2)
    li2.append(num2 * inv % mod2)

li = [0] + [10 * e1 + e2 for e1, e2 in zip(li1, li2)]
c = Counter(li)

ans = 0
for v in c.values():
    ans += v * (v - 1) // 2

print(ans)


Fixed submission:
from collections import Counter

s = input()
mod1 = 673
mod2 = 3

num1 = 0
num2 = 0
li1 = []
li2 = []
pw1 = 10
pw2 = 10
for i, e in enumerate(s, 1):
    num1 *= 10
    num1 += int(e)
    num1 %= mod1
    inv = pow(pw1, mod1 - 2, mod1)
    li1.append(num1 * inv % mod1)

    num2 *= 10
    num2 += int(e)
    num2 %= mod2
    inv = pow(pw2, mod2 - 2, mod2)
    li2.append(num2 * inv % mod2)

    pw1 *= 10
    pw1 %= mod1
    pw2 *= 10
    pw2 %= mod2

li = [0] + [10 * e1 + e2 for e1, e2 in zip(li1, li2)]
c = Counter(li)

ans = 0
for v in c.values():
    ans += v * (v - 1) // 2

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
readline = sys.stdin.buffer.readline

import numpy as np

n = int(readline())
a = np.array(readline().split(), np.int16)

a -= 1
ans = np.bincount(a, minlength=n)
print(*ans, sep="\n")


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

cnt = [0] * (n + 1)
for e in a:
    cnt[e] += 1

print(*cnt[1:], sep="\n")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
a = [[e, i] for i, e in enumerate(a, 1)]

a.sort(reverse=True)

dp = [[0] * (n + 1) for _ in range(n + 1)]

for t, (e, idx) in enumerate(a, 1):
    for i in range(1, t + 1):
        j = t - i
        dp[i][j] = max(dp[i][j], dp[i-1][j] + e * abs(idx - i))

    for j in range(1, t + 1):
        i = t - j
        dp[i][j] = max(dp[i][j], dp[i][j-1] + e * abs(idx - (n - j + 1)))

ans = 0
for i in range(1, n + 1):
    j = n - i
    ans = max(ans, dp[i][j])

print(ans)


Fixed submission:
from heapq import heappop, heappush
from collections import defaultdict

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

hp = []
for i, e in enumerate(a, 1):
    heappush(hp, [-e, i])

dp = defaultdict(int)
dp[(0, n + 1)] = 0
while hp:
    e, i = heappop(hp)
    e = -e
    dp2 = defaultdict(int)
    for k, v in dp.items():
        l, r = k
        dp2[(l + 1, r)] = max(dp2[(l + 1, r)], v + abs(l + 1 - i) * e)
        dp2[(l, r - 1)] = max(dp2[(l, r - 1)], v + abs(r - 1 - i) * e)

    dp = dp2

ans = 0
for k, v in dp.items():
    ans = max(ans, v)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappop, heappush
from collections import defaultdict

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

hp = []
for i, e in enumerate(a, 1):
    heappush(hp, [-e, i])

dp = defaultdict(int)
dp[(0, n + 1)] = 0
while hp:
    e, i = heappop(hp)
    e = -e
    dp2 = defaultdict(int)
    for k, v in dp.items():
        l, r = k
        dp2[(l + 1, r)] = max(dp2[(l + 1, r)], v + abs(l + 1 - i) * e)
        dp2[(l, r - 1)] = max(dp2[(l, r - 1)], v + abs(r - 1 - i) * e)

    dp = dp2

ans = 0
for k, v in dp.items():
    ans = max(ans, v)

print(ans)


Fixed submission:
from heapq import heappop, heappush
from collections import defaultdict

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

hp = []
for i, e in enumerate(a, 1):
    heappush(hp, [-e, i])

dp = defaultdict(int)
dp[(0, n + 1)] = 0
while hp:
    e, i = heappop(hp)
    e = -e
    dp2 = defaultdict(int)
    for k, v in dp.items():
        l, r = k
        dp2[(l + 1, r)] = max(dp2[(l + 1, r)], v + abs(l + 1 - i) * e)
        dp2[(l, r - 1)] = max(dp2[(l, r - 1)], v + abs(r - 1 - i) * e)

    dp = dp2

ans = 0
for k, v in dp.items():
    ans = max(ans, v)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

n = int(input())
s = input()

c = Counter(s)

dbl = c["R"] * c["B"] * c["G"]
for l in range(1, n):
    for i in range(n):
        j = i + l
        k = j + l
        if j < n and k < n:
            if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                dbl -= 1

print(dbl)


Fixed submission:
from collections import Counter

n = int(input())
s = input()

c = Counter(s)

dbl = c["R"] * c["B"] * c["G"]
for l in range(1, n):
    for i in range(n):
        j = i + l
        k = j + l
        if j < n and k < n:
            if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                dbl -= 1

print(dbl)
Buggy python submission (verdict: Time Limit Exceeded):
n, x, y = map(int, input().split())

cnt = [0] * n
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        dist1 = j - i
        dist2 = min(abs(x - i) + abs(y - j), abs(x - j) + abs(y - i)) + 1
        dist = min(dist1, dist2)
        cnt[dist] += 1

print(*cnt[1:], sep="\n")


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

cnt = [0] * n
cycle = y - x + 1

for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        if i < x and j > y:
            cnt[j - y + x - i + 1] += 1
        elif i < x:
            d = min(j - x, y - j + 1)
            cnt[x - i + d] += 1
        elif j > y:
            d = min(y - i, i - x + 1)
            cnt[j - y + d] += 1
        else:
            d = min(j - i, y - j + 1 + i - x)
            cnt[d] += 1

print(*cnt[1:], sep="\n")