Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
n = int(input())
a = [int(i) for i in input().split()]
b = list(accumulate(a))
ans = 0
c = list(set(b))
for cc in c:
    num = b.count(cc)
    ans += (num * (num - 1)) // 2
ans += b.count(0)
print(ans)

Fixed submission:
from itertools import accumulate
import collections
n = int(input())
a = [int(i) for i in input().split()]
b = list(accumulate(a))
c = collections.Counter(b)
ans = sum([((num * (num - 1)) // 2) for num in c.values()])
ans += c[0]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
n = int(input())
a = [int(i) for i in input().split()]
b = list(accumulate(a))
ans = 0
c = list(set(b))
for cc in c:
    num = b.count(cc)
    if num > 1:
        ans += (num * (num - 1)) // 2
ans += b.count(0)
print(ans)

Fixed submission:
from itertools import accumulate
import collections
n = int(input())
a = [int(i) for i in input().split()]
b = list(accumulate(a))
c = collections.Counter(b)
ans = sum([((num * (num - 1)) // 2) for num in c.values()])
ans += c[0]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
b = [0] * (n)
b[0] = a[0]
for i in range(1, n):
    b[i] = b[i-1] + a[i]
ans = 0
for i in range(n):
    for j in range(i+1, n):
        if b[j] - b[i] == 0:
            ans += 1
ans += b.count(0)
print(ans)

Fixed submission:
from itertools import accumulate
import collections
n = int(input())
a = [int(i) for i in input().split()]
b = list(accumulate(a))
c = collections.Counter(b)
ans = sum([((num * (num - 1)) // 2) for num in c.values()])
ans += c[0]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import math
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
temp = 0
for j, i in enumerate(a):
    k = bisect.bisect_left(a[:j], (i / 2) + 1) - 1
    if (i - a[k]) > 0:
        if math.factorial(i) // (math.factorial(a[k]) * (math.factorial(i - a[k]))) > temp:
            ans = [i, a[k]]
        else:
            continue
    else:
        continue
print(*ans)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
max_a = a[-1]
temp = a[0]
for i in a[1:-1]:
    if abs(i - max_a / 2) < abs(temp - max_a / 2):
        temp = i
print(*[max_a, temp])

Buggy python submission (verdict: Runtime Error):
import bisect
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
temp = 0
for j, i in enumerate(a):
    k = bisect.bisect_left(a[:j], (i / 2) + 1) - 1
    if (i - a[k]) > 0:
        if math.factorial(i) // (math.factorial(a[k]) * (math.factorial(i - a[k]))) > temp:
            ans = [i, a[k]]
print(*ans)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
max_a = a[-1]
temp = a[0]
for i in a[1:-1]:
    if abs(i - max_a / 2) < abs(temp - max_a / 2):
        temp = i
print(*[max_a, temp])
Buggy python submission (verdict: Runtime Error):
import copy
n = int(input())
red = []
blue = []
for _ in range(n):
    a, b = map(int, input().split())
    red.append([a, b])
for _ in range(n):
    c, d = map(int, input().split())
    blue.append([c, d])

red_list = copy.copy(red)
blue_list = copy.copy(blue)
    
red_list.sort()
blue_list.sort()
count = 0
for i in range(n):
    a, b = red_list.pop(0)
    for j in range(len(blue_list)):
        if (a < blue_list[j][0]) & (b < blue_list[j][1]):
            count += 1
            blue_list.pop(j)
            break

red_list = copy.copy(red)
blue_list = copy.copy(blue)
    
red_list.sort(key=lambda x: x[1])
blue_list.sort(key=lambda x: x[1])
count1 = 0
for i in range(n):
    a, b = red_list.pop(0)
    for j in range(len(blue_list)):
        if (a < blue_list[j][0]) & (b < blue_list[j][1]):
            count1 += 1
            blue_list.pop(j)
            break            

ans = max(count, count1)        
print(ans)

Fixed submission:
a,b,c = map(int, input().split())
if (a+b >= c):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import collections
n = int(input())
s = []
for _ in range(n):
    s.append(input())
m = int(input())
t = []
for _ in range(m):
    t.append(input())
s_ = collections.Counter(s)
t_ = collections.Counter(t)
a = []
for key in s_.keys():
    num = s_[key] - t_[key]
    a.append(num)
print(max(a, 0))

Fixed submission:
import collections
n = int(input())
s = []
for _ in range(n):
    s.append(input())
m = int(input())
t = []
for _ in range(m):
    t.append(input())
s_ = collections.Counter(s)
t_ = collections.Counter(t)
a = []
for key in s_.keys():
    num = s_[key] - t_[key]
    a.append(num)
print(max(max(a),0))
Buggy python submission (verdict: Runtime Error):
n = int(input())
red = []
blue = []
for _ in range(n):
    a, b = map(int, input().split())
    red.append([a, b])
for _ in range(n):
    c, d = map(int, input().split())
    blue.append([c, d])
red.sort()
b.sort()
count = 0
for i in range(n):
    a, b = red.pop(0)
    for j in range(len(blue)):
        if (a < blue[j][0]) & (b < blue[j][1]):
            count += 1
            blue.pop(j)
            break

Fixed submission:
n = int(input())
red = []
blue = []
for _ in range(n):
    a, b = map(int, input().split())
    red.append([a, b])
for _ in range(n):
    c, d = map(int, input().split())
    blue.append([c, d])
blue.sort()
red.sort(key=lambda x: x[1], reverse=True)
ans = 0
for b in blue:
    for i, r in enumerate(red):
        if (r[0] < b[0]) & (r[1] < b[1]):
            ans += 1
            red.pop(i)
            break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
h, w, d = map(int, input().split())
num_dict = [[] for _ in range(h * w)]
for i in range(h):
    num_list = [int(i) for i in input().split()]
    for j, num in enumerate(num_list):
        num_dict[num - 1] = (i + 1, j + 1)
accum_list = [0 for _ in range(h * w)]
for i in range((h * w) - d):
    for j in range(i + d, (h * w), d):
        if j > 0:
            accum_list[i] += abs(num_dict[j][0] - num_dict[j - d][0]) + abs(num_dict[j][1] - num_dict[j - d][1])
q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print(accum_list[l - 1] - accum_list[r - 1])

Fixed submission:
h, w, d = map(int, input().split())
num_dict = [[] for _ in range(h * w)]
for i in range(h):
    num_list = [int(i) for i in input().split()]
    for j, num in enumerate(num_list):
        num_dict[num - 1] = (i + 1, j + 1)
accum_list = [0 for _ in range(h * w)]
for i in range((h * w) - d - 1, -1, -1):
    accum_list[i] += (abs(num_dict[i + d][0] - num_dict[i][0]) +
                      abs(num_dict[i + d][1] - num_dict[i][1]) + accum_list[i + d])
q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print(accum_list[l - 1] - accum_list[r - 1])

Buggy python submission (verdict: Time Limit Exceeded):
h, w, d = map(int, input().split())
num_dict = {}
for i in range(h):
    num_list = [int(i) for i in input().split()]
    for j, num in enumerate(num_list):
        num_dict[num] = (i + 1, j + 1)
q = int(input())
for _ in range(q):
    ans = 0
    l, r = map(int, input().split())
    for i in range(l, r + d, d):
        n_x, n_y = num_dict[i]
        if i > l:
            ans += abs(temp_x - n_x) + abs(temp_y - n_y)
        temp_x = n_x
        temp_y = n_y
    print(ans)

Fixed submission:
h, w, d = map(int, input().split())
num_dict = [[] for _ in range(h * w)]
for i in range(h):
    num_list = [int(i) for i in input().split()]
    for j, num in enumerate(num_list):
        num_dict[num - 1] = (i + 1, j + 1)
accum_list = [0 for _ in range(h * w)]
for i in range((h * w) - d - 1, -1, -1):
    accum_list[i] += (abs(num_dict[i + d][0] - num_dict[i][0]) +
                      abs(num_dict[i + d][1] - num_dict[i][1]) + accum_list[i + d])
q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print(accum_list[l - 1] - accum_list[r - 1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
left = 0
right = n - 1
print(left)
first = input()
second = 'Male' if s_l == 'Female' else 'Male'
p = 0
while True:
    p = (left + right) // 2
    print(p)
    status = input()
    if status == 'Vacant':
        exit()
    if p % 2 == 0:
        if status == first:
            left = p + 1
        else:
            right = p
    else:
        if status == second:
            left = p + 1
        else:
            right = p

Fixed submission:
n = int(input())
left = 0
right = n - 1
print(left)
first = input()
second = 'Male' if first == 'Female' else 'Female'
p = 0
while True:
    p = (left + right) // 2
    print(p)
    status = input()
    if status == 'Vacant':
        break
    if p % 2 == 0:
        if status == first:
            left = p + 1
        else:
            right = p
    else:
        if status == second:
            left = p + 1
        else:
            right = p

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
left = 0
right = n - 1
print(left)
s_l = input()
s_r = 'Male' if s_l == 'Female' else 'Male'
p = 0
while True:
    p = (left + right) // 2
    print(p)
    status = input()
    if status == 'Vacant':
        exit()
    if p % 2 == 0:
        if status == first:
            left = p + 1
        else:
            right = p
    else:
        if status == second:
            left = p + 1
        else:
            right = p

Fixed submission:
n = int(input())
left = 0
right = n - 1
print(left)
first = input()
second = 'Male' if first == 'Female' else 'Female'
p = 0
while True:
    p = (left + right) // 2
    print(p)
    status = input()
    if status == 'Vacant':
        break
    if p % 2 == 0:
        if status == first:
            left = p + 1
        else:
            right = p
    else:
        if status == second:
            left = p + 1
        else:
            right = p

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
right = 0
left = n - 1
print(right)
prev = input()
if prev == 'Vacant':
    exit()
v = pow(2, math.floor(math.log(n, 2)))
middle = right + v
for i in range(19):
    print(middle)
    status = input()
    v = v // 2
    if status == 'Vacant':
        exit()
    elif status == prev:
        right = middle
        middle = right + v
    else:
        left = middle
        middle = left - v
    prev = status

Fixed submission:
n = int(input())
left = 0
right = n - 1
print(left)
first = input()
second = 'Male' if first == 'Female' else 'Female'
p = 0
while True:
    p = (left + right) // 2
    print(p)
    status = input()
    if status == 'Vacant':
        break
    if p % 2 == 0:
        if status == first:
            left = p + 1
        else:
            right = p
    else:
        if status == second:
            left = p + 1
        else:
            right = p
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = []
for _ in range(n-1):
    l.append([int(i) for i in input().split()])
for j in range(n):
    l_ = l[j:]
    c = 0
    for i in range(n-1-j):
        if c <= l_[i][1]:
            c = l_[i][1]
        else:
            a = l_[i][1]
            while (c > a):
                a += l_[i][2]
            c = a
        c += l_[i][0]
    print(c)

Fixed submission:
n = int(input())
l = []
for _ in range(n-1):
    l.append([int(i) for i in input().split()])
for j in range(n):
    l_ = l[j:]
    c = 0
    for i in range(n-1-j):
        if c <= l_[i][1]:
            c = l_[i][1]
        elif (c % l_[i][2] != 0):
            c = (c // l_[i][2] + 1) * l_[i][2]
        else:
            c = (c // l_[i][2]) * l_[i][2]
        c += l_[i][0]
    print(c)
Buggy python submission (verdict: Runtime Error):
N, C = map(int, input().split())
record = [[0 for _ in range(10 ** 5)] for _ in range(C)]
for _ in range(N):
    s, t, c = map(int, input().split())
    s -= 1
    c -= 1
    record[c][s] += 1
    record[c][t] -= 1
cum = []
for i in range(C):
    tmp = [record[i][0]]
    for j in range(10 ** 5 - 1):
        tmp.append(tmp[-1] + record[i][j + 1])
    cum.append(tmp)
ans = 0
for i in range(10 ** 5):
    tmp = 0
    for j in range(C):
        tmp += cum[j][i]
    ans = max(tmp, ans)
print(ans)    

Fixed submission:
N, C = map(int, input().split())
max_size = 10 ** 5
record_list = [[int(i) - 1 for i in input().split()] for _ in range(N)]
ans_list = [0 for _ in range(max_size)]
for c in range(C):
    T = [0 for _ in range(max_size + 1)]
    for s, t, i in record_list:
        if i == c:
            T[s] += 1
            T[t + 1] -= 1
    for i in range(max_size):
        T[i + 1] += T[i]
    for i in range(max_size):
        ans_list[i] += T[i] > 0
print(max(ans_list))

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000000)
N, C = map(int, input().split())
record = [[0 for _ in range(10 ** 5)] for _ in range(C)]
for _ in range(N):
    s, t, c = map(int, input().split())
    s -= 1
    c -= 1
    record[c][s] += 1
    record[c][t] -= 1
cum = []
for i in range(C):
    tmp = [record[i][0]]
    for j in range(10 ** 5 - 1):
        tmp.append(tmp[-1] + record[i][j + 1])
    cum.append(tmp)
ans = 0
for i in range(10 ** 5):
    tmp = 0
    for j in range(C):
        tmp += cum[j][i]
    ans = max(tmp, ans)
print(ans)    

Fixed submission:
N, C = map(int, input().split())
max_size = 10 ** 5
record_list = [[int(i) - 1 for i in input().split()] for _ in range(N)]
ans_list = [0 for _ in range(max_size)]
for c in range(C):
    T = [0 for _ in range(max_size + 1)]
    for s, t, i in record_list:
        if i == c:
            T[s] += 1
            T[t + 1] -= 1
    for i in range(max_size):
        T[i + 1] += T[i]
    for i in range(max_size):
        ans_list[i] += T[i] > 0
print(max(ans_list))

Buggy python submission (verdict: Runtime Error):
N, C = map(int, input().split())
record = [[0 for _ in range(10 ** 5)] for _ in range(C)]
for _ in range(N):
    s, t, c = map(int, input().split())
    s -= 1
    c -= 1
    record[c][s] += 1
    record[c][t] -= 1
cum = []
for i in range(C):
    tmp = [record[i][0]]
    for j in range(10 ** 5 - 1):
        tmp.append(tmp[-1] + record[i][j + 1])
    cum.append(tmp)
ans = 0
for i in range(10 ** 5):
    tmp = 0
    for j in range(C):
        tmp += cum[j][i]
    ans = max(tmp, ans)
print(ans)    

Fixed submission:
N, C = map(int, input().split())
max_size = 10 ** 5
record_list = [[int(i) - 1 for i in input().split()] for _ in range(N)]
ans_list = [0 for _ in range(max_size)]
for c in range(C):
    T = [0 for _ in range(max_size + 1)]
    for s, t, i in record_list:
        if i == c:
            T[s] += 1
            T[t + 1] -= 1
    for i in range(max_size):
        T[i + 1] += T[i]
    for i in range(max_size):
        ans_list[i] += T[i] > 0
print(max(ans_list))
Buggy python submission (verdict: Runtime Error):
n = list(input())
if ((len(collections.Counter(n[:3])) == 1) | (len(collections.Counter(n[1:])) == 1)):
    print("Yes")
else:
    print("No")

Fixed submission:
import collections
n = list(input())
if ((len(collections.Counter(n[:3])) == 1) | (len(collections.Counter(n[1:])) == 1)):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
a,b,c,d = list(input())
a,b,c,d = int(a), int(b), int(c), int(d)
mark = {"+":1,"-":-1}
e = 0
for i, i_ in mark.items():
    for j, j_ in mark.items():
        for k, k_ in mark.items():
            if (e==0)&(a + i_ * b + c * j_ + d * k_ == 7):
                print(f"{a}{i}{b}{j}{c}{k}{d}=7")
                e = 1
                break

Fixed submission:
a,b,c,d = list(input())
a,b,c,d = int(a), int(b), int(c), int(d)
mark = {"+":1,"-":-1}
e = 0
for i, i_ in mark.items():
    for j, j_ in mark.items():
        for k, k_ in mark.items():
            if (e==0)&(a + i_ * b + c * j_ + d * k_ == 7):
                ans = str(a)+i+str(b)+j+str(c)+k+str(d)+"=7"
                print(ans)
                e = 1
                break
Buggy python submission (verdict: Time Limit Exceeded):
n, K = map(int, input().split())
point = []
x_list = []
y_list = []
for _ in range(n):
    x, y = map(int, input().split())
    point.append((x, y))
    x_list.append(x)
    y_list.append(y)
x_list.sort()
y_list.sort()

ans = 4 * (10 ** 18)
for i in range(len(x_list)):
    for j in range(i + 1, len(x_list)):
        for k in range(len(y_list)):
            for l in range(k + 1, len(y_list)):
                num = 0
                for x, y in point:
                    if (x_list[i] <= x <= x_list[j]) & (y_list[k] <= y <= y_list[l]):
                        num += 1
                if num >= K:
                    ans = min(ans, abs((x_list[j] - x_list[i]) * (y_list[l] - y_list[k])))
print(ans)

Fixed submission:
n, K = map(int, input().split())
point = []
x_list = []
y_list = []
for _ in range(n):
    x, y = map(int, input().split())
    point.append((x, y))
    x_list.append(x)
    y_list.append(y)
x_list.sort()
y_list.sort()

ans = 4 * (10 ** 18)
for i in range(len(x_list)):
    for j in range(i + 1, len(x_list)):
        for k in range(len(y_list)):
            for l in range(k + 1, len(y_list)):
                num = 0
                for x, y in point:
                    if (x_list[i] <= x <= x_list[j]) & (y_list[k] <= y <= y_list[l]):
                        num += 1
                if num >= K:
                    ans = min(ans, abs((x_list[j] - x_list[i]) * (y_list[l] - y_list[k])))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product

N = int(input())

for h, n in product(range(1, 3501), range(1, 3501)):
    if ((4 * h * n) - (N * n) - (N * h)) > 0:
        if (N * h * n) % ((4 * h * n) - (N * n) - (N * h)) == 0:
            print(h, n, (N * h * n) // ((4 * h * n) - (N * n) - (N * h)))
            break

Fixed submission:
N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        if ((4 * h * n) - (N * n) - (N * h)) > 0:
            if (N * h * n) % ((4 * h * n) - (N * n) - (N * h)) == 0:
                print(h, n, (N * h * n) // ((4 * h * n) - (N * n) - (N * h)))
                exit()

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product

N = int(input())

for h, n in product(range(1, 3501), range(1, 3501)):
    a = ((4 * h * n) - (N * n) - (N * h))
    if a > 0:
        if (N * h * n) % a == 0:
            w = (N * h * n) // a
            ans = [w, h, n]
            print(*ans)
            break

Fixed submission:
N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        if ((4 * h * n) - (N * n) - (N * h)) > 0:
            if (N * h * n) % ((4 * h * n) - (N * n) - (N * h)) == 0:
                print(h, n, (N * h * n) // ((4 * h * n) - (N * n) - (N * h)))
                exit()

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product

N = int(input())

for h, n in product(range(1, 3501), range(1, 3501)):
    if ((4 * h * n) - (N * n) - (N * h)) > 0:
        if (N * h * n) % ((4 * h * n) - (N * n) - (N * h)) == 0:
            w = (N * h * n) // ((4 * h * n) - (N * n) - (N * h))
            ans = [w, h, n]
            print(*ans)
            break

Fixed submission:
N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        if ((4 * h * n) - (N * n) - (N * h)) > 0:
            if (N * h * n) % ((4 * h * n) - (N * n) - (N * h)) == 0:
                print(h, n, (N * h * n) // ((4 * h * n) - (N * n) - (N * h)))
                exit()
Buggy python submission (verdict: Runtime Error):
a, b, c, d, e, f = map(int, input().split())
a_list = set([])
b_list = set([])
for i in range((f // a) + 1):
    for j in range((f // b) + 1):
        if 0 < ((a*i) + (b*j)) * 100 <= f:
            a_list.add(((a*i)+(b*j))*100)
for i in range((f // c) + 1):
    for j in range((f // d) + 1):
        if ((c*i) + (d*j)) <= f:
            b_list.add((c*i)+(d*j))
ans = 0
ans_1 = 0
ans_2 = 0
for aa in a_list:
    for bb in b_list:
        if (aa + bb <= f) & ((bb / (aa + bb) * 100 <= e):
            if ans <= (bb / (aa + bb)) * 100:
                ans = (bb / aa) * 100
                ans_1 = aa + bb
                ans_2 = bb
print(str(ans_1) + " " + str(ans_2))

Fixed submission:
a, b, c, d, e, f = map(int, input().split())
a_list = set([])
b_list = set([])
for i in range((f // a) + 1):
    for j in range((f // b) + 1):
        if 0 < ((a*i) + (b*j)) * 100 <= f:
            a_list.add(((a*i)+(b*j))*100)
for i in range((f // c) + 1):
    for j in range((f // d) + 1):
        if ((c*i) + (d*j)) <= f:
            b_list.add((c*i)+(d*j))
ans = 0
ans_1 = 0
ans_2 = 0
for aa in a_list:
    for bb in b_list:
        if (aa + bb <= f) & ((bb / aa) <= e * 0.01):
            if ans <= (bb / aa) * 100:
                ans = (bb / (aa)) * 100
                ans_1 = aa + bb
                ans_2 = bb
print(str(ans_1) + " " + str(ans_2))
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

inf = 10 ** 9
n, m, r = map(int, input().split())
r_list = [int(i) - 1 for i in input().split()]
a_list = [[inf for _ in range(n)] for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    a_list[a][b] = a_list[b][a] = c
for k in range(n):
    for i in range(n):
        for j in range(n):
            x = a_list[i][k] + a_list[k][j]
            if x < a_list[i][j]:
                a_list[i][j] = a_list[j][i] = x
k = list(itertools.permutations(r_list))
ans = inf
for kk in k[:len(k)//2 + 1]:
    temp = 0
    for k1, k2 in zip(kk[:-1], kk[1:]):
        temp += a_list[k1][k2]
    if ans > temp:
        ans = temp
print(ans)

Fixed submission:
import itertools

inf = 10 ** 9
n, m, r = map(int, input().split())
r_list = [int(i) - 1 for i in input().split()]
a_list = [[inf for _ in range(n)] for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    a_list[a][b] = a_list[b][a] = c
for k in range(n):
    for i in range(n):
        for j in range(i + 1, n):
            x = a_list[i][k] + a_list[k][j]
            if x < a_list[i][j]:
                a_list[i][j] = a_list[j][i] = x
k = list(itertools.permutations(r_list))
ans = inf
for kk in k:
    temp = 0
    for k1, k2 in zip(kk[:-1], kk[1:]):
        temp += a_list[k1][k2]
    if ans > temp:
        ans = temp
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

inf = 10 ** 9
n, m, r = map(int, input().split())
r_list = [int(i) - 1 for i in input().split()]
a_list = [[inf for _ in range(n)] for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    a_list[a][b] = a_list[b][a] = c
for k in range(n):
    for i in range(n):
        for j in range(n):
            x = a_list[i][k] + a_list[k][j]
            if x < a_list[i][j]:
                a_list[i][j] = a_list[j][i] = x
k = list(itertools.permutations(r_list))
ans = inf
for kk in k:
    temp = 0
    for k1, k2 in zip(kk[:-1], kk[1:]):
        temp += a_list[k1][k2]
    if ans > temp:
        ans = temp
print(ans)

Fixed submission:
import itertools

inf = 10 ** 9
n, m, r = map(int, input().split())
r_list = [int(i) - 1 for i in input().split()]
a_list = [[inf for _ in range(n)] for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    a_list[a][b] = a_list[b][a] = c
for k in range(n):
    for i in range(n):
        for j in range(i + 1, n):
            x = a_list[i][k] + a_list[k][j]
            if x < a_list[i][j]:
                a_list[i][j] = a_list[j][i] = x
k = list(itertools.permutations(r_list))
ans = inf
for kk in k:
    temp = 0
    for k1, k2 in zip(kk[:-1], kk[1:]):
        temp += a_list[k1][k2]
    if ans > temp:
        ans = temp
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a = input()
a_set = set([a])
for i in range(len(a)):
    for j in range(i+1, len(a)):
        if a[:i] + "".join(list(reversed(a[i:j+1]))) + a[j+1:] not in a_set:
            a_set.add(a[:i] + "".join(list(reversed(a[i:j+1]))) + a[j+1:])
print(len(a_set))

Fixed submission:
from collections import Counter
a = input()
k = Counter(a).values()
ans = len(a) * (len(a) - 1) // 2
for k_v in k:
    if k_v > 1:
        ans -= k_v * (k_v - 1) // 2
print(ans + 1)