Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    s = list(input())

    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            for k in range(j+1, n):
                if j-i == k-j:
                    continue
                if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                    ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    s = list(input())

    ans = s.count("R")*s.count("G")*s.count("B")
    for i in range(n):
        for j in range(i+1, n):
            k = j + j - i
            if k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                ans -= 1
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    s = list(input())

    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            for k in range(j+1, n):
                if j-i == k-j:
                    continue
                if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                    ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    s = list(input())

    ans = s.count("R")*s.count("G")*s.count("B")
    for i in range(n):
        for j in range(i+1, n):
            k = j + j - i
            if k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                ans -= 1
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    q = int(input())
    for _ in range(q):
        query = input().split()
        if query[0] == "1":
            s = s[::-1]
        else:
            if query[1] == '1':
                s = query[2] + s
            else:
                s = s + query[2]
    print(s)


if __name__ == "__main__":
    main()


Fixed submission:
from collections import deque


def main():
    s = deque(list(input()))
    q = int(input())
    rev = False
    for _ in range(q):
        query = input().split()
        if query[0] == "1":
            if not rev:
                rev = True
            else:
                rev = False
        else:
            if query[1] == '1':
                pass
                if rev:
                    s.append(query[2])
                else:
                    s.appendleft(query[2])
            else:
                if rev:
                    s.appendleft(query[2])
                else:
                    s.append(query[2])
    if rev:
        s.reverse()
    print(*s, sep="")


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    q = int(input())
    for _ in range(q):
        query = input().split()
        if query[0] == "1":
            s = s[::-1]
        else:
            if query[1] == '1':
                s = query[2] + s
            else:
                s = s + query[2]
    print(s)


if __name__ == "__main__":
    main()


Fixed submission:
from collections import deque


def main():
    s = deque(list(input()))
    q = int(input())
    rev = False
    for _ in range(q):
        query = input().split()
        if query[0] == "1":
            if not rev:
                rev = True
            else:
                rev = False
        else:
            if query[1] == '1':
                pass
                if rev:
                    s.append(query[2])
                else:
                    s.appendleft(query[2])
            else:
                if rev:
                    s.appendleft(query[2])
                else:
                    s.append(query[2])
    if rev:
        s.reverse()
    print(*s, sep="")


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    n, m = map(int, input().split())
    ans = [0]*n
    for _ in range(m):
        s, c = map(int, input().split())
        if ans[s-1] == 0:
            ans[s-1] = c
        elif ans[s-1] != 0 and ans[s-1] != c:
            print(-1)
            exit()

    if len(ans[0]) == 1:
        print(ans[0])
    if ans[0] == 0:
        print(-1)
    else:
        print(*ans, sep="")


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n, m = map(int, input().split())
    ans = [-1]*n
    for _ in range(m):
        s, c = map(int, input().split())
        if ans[s-1] == -1:
            ans[s-1] = c
        elif ans[s-1] != -1 and ans[s-1] != c:
            print(-1)
            exit()

    if n == 1:
        if ans[0] == -1:
            ans[0] = 0
    else:
        if ans[0] == 0:
            print(-1)
            exit()

        if ans[0] == -1:
            ans[0] = 1

        for i in range(1, n):
            if ans[i] == -1:
                ans[i] = 0
    print(*ans, sep="")


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    n, m = map(int, input().split())
    ans = [0]*n
    for _ in range(m):
        s, c = map(int, input().split())
        if ans[s-1] == 0:
            ans[s-1] = c
        elif ans[s-1] != 0 and ans[s-1] != c:
            print(-1)
            exit()

    if len(ans[0]) == 1:
        print(*ans, sep="")
    if ans[0] == 0:
        print(-1)
    else:
        print(*ans, sep="")


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n, m = map(int, input().split())
    ans = [-1]*n
    for _ in range(m):
        s, c = map(int, input().split())
        if ans[s-1] == -1:
            ans[s-1] = c
        elif ans[s-1] != -1 and ans[s-1] != c:
            print(-1)
            exit()

    if n == 1:
        if ans[0] == -1:
            ans[0] = 0
    else:
        if ans[0] == 0:
            print(-1)
            exit()

        if ans[0] == -1:
            ans[0] = 1

        for i in range(1, n):
            if ans[i] == -1:
                ans[i] = 0
    print(*ans, sep="")


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter


def main():
    n = int(input())
    ss = [input() for _ in range(n)]
    max_num = Counter(ss).most_common()[0][1]
    max_verbs = [Counter(ss).most_common()[0][0]]
    for i in range(1, len(Counter(ss).most_common())):
        if Counter(ss).most_common()[i][1] != max_num:
            break
        max_verbs.append(Counter(ss).most_common()[i][0])

    max_verbs = sorted(max_verbs)
    for ans in max_verbs:
        print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    ss = {}
    max_s = 0
    for _ in range(n):
        s = input()
        if s not in ss:
            ss[s] = 0
        else:
            ss[s] += 1
            max_s = max(max_s, ss[s])

    ss = sorted(ss.items(), key=lambda x: x[0])
    anss = [s for s, i in ss if i == max_s]
    for ans in anss:
        print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    h = int(input())

    for i in range(40):
        if 2**(i+1) == h:
            n = i+2
            break
        if 2**(i) < h and h < 2**(i+1):
            n = i+1
            break
    ans = sum([2**i for i in range(n)])
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    h = int(input())

    if h == 1:
        print(1)
        exit()

    for i in range(40):
        if 2**(i+1) == h:
            n = i+2
            break
        if 2**(i) < h and h < 2**(i+1):
            n = i+1
            break
    ans = sum([2**i for i in range(n)])
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    ps = list(map(int, input().split()))
    li = []
    ans = 0
    for i in ps:
        li.append(i)
        if sorted(li)[0] >= i:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    ps = list(map(int, input().split()))
    ans = 0
    minp = float("inf")
    for p in ps:
        minp = min(minp, p)
        if minp >= p:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    ts = list(input())

    hands = {"r": p, "s": r, "p": s}
    ans = 0
    skip = []
    for i in range(n):
        if i in skip:
            continue

        if i+k > n-1:
            ans += hands[ts[i]]

        else:
            if ts[i] != ts[i+k]:
                ans += hands[ts[i]]
            else:
                ans += hands[ts[i]]
                skip.append(i+k)

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    ts = list(input())

    hands = {"r": p, "s": r, "p": s}
    ans = 0
    skip = [0]*n
    for i in range(n):
        if skip[i] == 1:
            continue

        if i+k > n-1:
            ans += hands[ts[i]]

        else:
            if ts[i] != ts[i+k]:
                ans += hands[ts[i]]
            else:
                ans += hands[ts[i]]
                skip[i+k] = 1

    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations as perm
import numpy as np


def main():
    n = int(input())
    xys = [list(map(int, input().split())) for _ in range(n)]

    orders = np.array(list(perm([xys[i] for i in range(n)], n)))
    ans = 0
    order_num = len(orders)

    for order in orders:
        temp = 0
        for i in range(n-1):
            temp += np.linalg.norm(order[i]-order[i+1])
        ans += temp
    print(ans/order_num)


if __name__ == "__main__":
    main()


Fixed submission:
from itertools import permutations as perm


def euclidean_distance(list1, list2):
    x_norm = (list1[0] - list2[0]) ** 2
    y_norm = (list1[1] - list2[1]) ** 2
    return (x_norm + y_norm) ** 0.5


def main():
    n = int(input())
    xys = [list(map(int, input().split())) for _ in range(n)]

    orders = list(perm([xys[i] for i in range(n)], n))
    order_num = len(orders)
    ans = 0
    for order in orders:
        for i in range(n-1):
            ans += euclidean_distance(order[i], order[i+1])

    print(ans/order_num)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations as perm
import numpy as np


def main():
    n = int(input())
    xys = [list(map(int, input().split())) for _ in range(n)]

    orders = list(perm([xys[i] for i in range(n)], n))
    ans = 0
    order_num = len(orders)

    for order in orders:
        temp = 0
        for i in range(n-1):
            temp += np.linalg.norm(np.array(np.array(order[i]))-np.array(order[i+1]))
        ans += temp
    print(ans/order_num)


if __name__ == "__main__":
    main()


Fixed submission:
from itertools import permutations as perm


def euclidean_distance(list1, list2):
    x_norm = (list1[0] - list2[0]) ** 2
    y_norm = (list1[1] - list2[1]) ** 2
    return (x_norm + y_norm) ** 0.5


def main():
    n = int(input())
    xys = [list(map(int, input().split())) for _ in range(n)]

    orders = list(perm([xys[i] for i in range(n)], n))
    order_num = len(orders)
    ans = 0
    for order in orders:
        for i in range(n-1):
            ans += euclidean_distance(order[i], order[i+1])

    print(ans/order_num)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
from math import gcd, sqrt


def is_prime(n):
    flag = True
    for k in range(2, int(sqrt(n)) + 1):
        if n % k == 0:
            flag = False
            return

    if flag:
        return n


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


def main():
    a, b = map(int, input().split())
    coms = make_divisors(gcd(a, b))
    # print(coms)
    ans = [is_prime(i) for i in coms]
    # print(ans)
    ans2 = [a for a in ans if a is not None]
    print(len(ans2))


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = []
    a = {i: k for i, k in enumerate(a, start=1)}
    a = sorted(a.items(), key=lambda a: a[1])
    for i in a:
        ans.append(i[0])

    print(*ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# from math import gcd, sqrt
# import fractions
import math


def is_prime(n):
    flag = True
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            flag = False
            return

    if flag:
        return n


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


def main():
    a, b = map(int, input().split())
    coms = make_divisors(math.gcd(a, b))
    ans = [is_prime(i) for i in coms]
    ans2 = [a for a in ans if a is not None]
    print(len(ans2))


if __name__ == "__main__":
    main()


Fixed submission:
# from math import gcd, sqrt
import fractions
import math


def is_prime(n):
    flag = True
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            flag = False
            return

    if flag:
        return n


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


def main():
    a, b = map(int, input().split())
    coms = make_divisors(fractions.gcd(a, b))
    ans = [is_prime(i) for i in coms]
    ans2 = [a for a in ans if a is not None]
    print(len(ans2))


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
from math import gcd, sqrt


def is_prime(n):
    flag = True
    for k in range(2, int(sqrt(n)) + 1):
        if n % k == 0:
            flag = False
            return

    if flag:
        return n


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


def main():
    a, b = map(int, input().split())
    coms = make_divisors(gcd(a, b))
    # print(coms)
    ans = [is_prime(i) for i in coms]
    # print(ans)
    ans2 = [a for a in ans if a is not None]
    print(ans2)


if __name__ == "__main__":
    main()


Fixed submission:
# from math import gcd, sqrt
import fractions
import math


def is_prime(n):
    flag = True
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            flag = False
            return

    if flag:
        return n


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


def main():
    a, b = map(int, input().split())
    coms = make_divisors(fractions.gcd(a, b))
    ans = [is_prime(i) for i in coms]
    ans2 = [a for a in ans if a is not None]
    print(len(ans2))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    h = [i for i in map(int, input().split())]

    ans = 0
    flag = False
    for i in range(n, 2, -1):
        for j in range(n+1-i):
            if sorted(h[j:j+i], reverse=True) == h[j:j+i]:
                ans = i-1
                flag = True
                break
        if flag is True:
            break

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N = int(input())
    H = list(map(int, input().split()))

    if N == 1:
        print(0)
        quit()

    start = 0
    moves = []
    for i in range(N-1):
        if H[i] >= H[i+1]:
            continue
        moves.append(i - start)
        start = i + 1

    if H[N-2] >= H[N-1]:
        moves.append(i - start + 1)
    print(max(moves))


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    h = [i for i in map(int, input().split())]

    ans = 0
    for i in range(2, n):
        for j in range(n+1-i):
            if sorted(h[j:j+i], reverse=True) == h[j:j+i]:
                ans = i-1
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N = int(input())
    H = list(map(int, input().split()))

    if N == 1:
        print(0)
        quit()

    start = 0
    moves = []
    for i in range(N-1):
        if H[i] >= H[i+1]:
            continue
        moves.append(i - start)
        start = i + 1

    if H[N-2] >= H[N-1]:
        moves.append(i - start + 1)
    print(max(moves))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    p = [i for i in range(1, n+1)]

    ans = sum([p[i] % (p[i]+1) for i in range(n-1)])
    # for i in range(n-1):
    #     ans += p[i] % (p[i]+1)
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())

    ans = n * (n-1)//2
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    p = [i for i in range(1, n+1)]

    ans = 0
    for i in range(n-1):
        ans += p[i] % (p[i]+1)
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())

    ans = n * (n-1)//2
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import itertools


def main():
    n = int(input())
    s = [sorted(input()) for _ in range(n)]
    seq = list(itertools.combinations(s, 2))
    ans = 0
    for i in seq:
        if i[0] == i[1]:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    s = ["".join(sorted(input())) for _ in range(n)]
    ans = 0
    dic = {}
    for i in s:
        if i not in dic:
            dic[i] = 0
        else:
            dic[i] += 1
            ans += dic[i]
        # print(ans)
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())

    ans = 0
    for i in range(len(str(N))):
        if len(str(N)) != i+1:
            if i % 2 == 0:
                ans += 9*(10**i)
        else:
            if i % 2 == 0:
                ans += int(str(N)[1:])+1
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
def main():
    N = int(input())

    ans = 0
    if len(str(N)) % 2 == 0:
        for i in range(len(str(N))):
            if i % 2 == 0:
                ans += 9*(10**i)
    else:
        for i in range(len(str(N))+1):
            if i % 2 == 0:
                ans += 9*(10**i)
        ans = ans - (10**len(str(N)) - N) + 1
        
    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())

    ans = 0
    for i in range(len(str(N))):
        if len(str(N)) != i+1:
            if i % 2 == 0:
                ans += 9*(10**i)
        else:
            if i % 2 == 0:
                if int(str(N)[1:]) == 0:
                    ans += 1
                else:
                    ans += int(str(N)[1:])
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
def main():
    N = int(input())

    ans = 0
    if len(str(N)) % 2 == 0:
        for i in range(len(str(N))):
            if i % 2 == 0:
                ans += 9*(10**i)
    else:
        for i in range(len(str(N))+1):
            if i % 2 == 0:
                ans += 9*(10**i)
        ans = ans - (10**len(str(N)) - N) + 1
        
    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())

    ans = 0
    for i in range(len(str(N))):
        if len(str(N)) != i+1:
            if i % 2 == 0:
                ans += 9*(10**i)
        else:
            if i % 2 == 0:
                if int(str(N)[1:]) == 0:
                    ans += 1
                else:
                    ans += int(str(N)[1:])+1
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
def main():
    N = int(input())

    ans = 0
    if len(str(N)) % 2 == 0:
        for i in range(len(str(N))):
            if i % 2 == 0:
                ans += 9*(10**i)
    else:
        for i in range(len(str(N))+1):
            if i % 2 == 0:
                ans += 9*(10**i)
        ans = ans - (10**len(str(N)) - N) + 1
        
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    h = list(map(int, input().split()))
    print(h)
    for i in range(n-1):
        print(h)
        if h[i] < h[i+1]:
            h[i+1] -= 1
        elif h[i] > h[i+1]:
            print('No')
            exit()

    print('Yes')


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    h = list(map(int, input().split()))
    for i in range(n-1):
        if h[i] < h[i+1]:
            h[i+1] -= 1
        elif h[i] > h[i+1]:
            print('No')
            exit()

    print('Yes')


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    c = 0
    if A == sorted(A):
        print("Yes")
        c += 1
    else:
        for i, a in enumerate(A):
            A[i] = a-1
            if A == sorted(A):
                print("Yes")
                c += 1
                break
    if c == 0:
        print("No")


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    h = list(map(int, input().split()))
    for i in range(n-1):
        if h[i] < h[i+1]:
            h[i+1] -= 1
        elif h[i] > h[i+1]:
            print('No')
            exit()

    print('Yes')


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    a, b = map(int, input().split())
    diff = abs(max(b, a) - min(a, b))
    if diff % 2 != 0:
        print("IMPOSSIBLE")
    else:
        bigger = max(a, b)
        ans = bigger - (diff//2)
        print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    ps = list(map(int, input().split()))
    ps_sort = sorted(ps)

    Count = 0
    for i, j in zip(ps, ps_sort):
        if i != j:
            Count += 1

    if Count == 2 or Count == 0:
        print('YES')
    else:
        print('NO')


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import math


def lcm(c, d):
    return (c * d) // math.gcd(c, d)


def main():
    a, b, c, d = map(int, input().split())
    c_num = (b//c-(a-1)//c)
    d_num = (b//d-(a-1)//d)
    cd_num = (b//lcm(c, d)-a//lcm(c, d))
    ans = b-a+1-c_num-d_num+cd_num
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from fractions import gcd


def lcm(c, d):
    return (c * d) // gcd(c, d)


def main():
    a, b, c, d = map(int, input().split())
    c_num = (b//c-(a-1)//c)
    d_num = (b//d-(a-1)//d)
    cd_num = (b//lcm(c, d)-(a-1)//lcm(c, d))
    ans = b-a+1-c_num-d_num+cd_num
    print(ans)


if __name__ == "__main__":
    main()