alexjercan/bugnet huggingface dataset:
Problem p02588 (Python) — buggy submission, verdict: Runtime Error

import sys

import numpy as np
from numba import njit, i8


def input():
    return sys.stdin.readline().strip()


def convert(S):
    i, *d = S.split(".")
    i = int(i) * 1_000_000_000
    if d:
        return i + int(d[0].ljust(9, "0"))
    else:
        return i


def div_cnt(n, d):
    res = 0
    while n % d == 0:
        res += 1
        n //= d
    return res


@njit(i8(i8[:, :]), cache=True)
def solve(table):
    ans = 0
    for i in range(19):
        for j in range(19):
            cur = table[i][j]
            if cur == 0:
                continue
            for k in range(18 - i, 19):
                for l in range(18 - j, 19):
                    if k == i and j == l:
                        ans += cur * (cur - 1)
                    else:
                        ans += cur * table[k][l]
    return ans


N = int(input())
A = list(convert(input()) for _ in range(N))
divs = [(div_cnt(a, 2), div_cnt(a, 5)) for a in A]

table = np.zeros((19, 19), np.int64)
for t, f in divs:
    table[min(t, 18)][min(f, 18)] += 1
print(solve(table) // 2)


Error: 0

Fixed submission:

import sys


def input():
    return sys.stdin.readline().strip()


def div_cnt(n, d):
    res = 0
    while n % d == 0:
        res += 1
        n //= d
    return res


N = int(input())
A = list(int(float(input()) * 1_000_000_000) for _ in range(N))
divs = [(div_cnt(a, 2), div_cnt(a, 5)) for a in A]

table = [[0] * 19 for _ in range(19)]
for t, f in divs:
    table[t][f] += 1

ans = 0
for t, f in divs:
    for i in range(19):
        for j in range(19):
            if t + i >= 18 and f + j >= 18:
                ans += table[i][j]
                if t == i and f == j:
                    ans -= 1

print(ans // 2)
Problem p02594 (Python) — buggy submission, verdict: Runtime Error

x = int(input())
if x >= 30:
    print("Yes")
else:
    print("No")


Error: TypeError: '>=' not supported between instances of 'str' and 'int'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02594/Python/s624570905.py", line 2, in <module>
    if x >= 30:
TypeError: '>=' not supported between instances of 'str' and 'int'


Fixed submission:

x = input()
if x >= 30:
    print("Yes")
else:
    print("No")
Problem p02594 (Python) — buggy submission, verdict: Runtime Error

x = input()
if int(x) >= 30:
    print("Yes")
else:
    print("No")


Error: TypeError: '>=' not supported between instances of 'str' and 'int'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02594/Python/s511585247.py", line 2, in <module>
    if x >= 30:
TypeError: '>=' not supported between instances of 'str' and 'int'


Fixed submission:

x = input()
if x >= 30:
    print("Yes")
else:
    print("No")
Problem p02594 (Python) — buggy submission, verdict: Runtime Error

X = int(input())

if X >= 30:
    print("Yes")
else:
    print("No")


Error: TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02594/Python/s217813658.py", line 1, in <module>
    X = int(input().split())
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'


Fixed submission:

X = int(input().split())

if X >= 30:
    print("Yes")
else:
    print("No")
Problem p02594 (Python) — buggy submission, verdict: Runtime Error

x = int(input())

if x >= 30:
    print("Yes")
else:
    print("No")


Error: TypeError: '>=' not supported between instances of 'str' and 'int'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02594/Python/s522477833.py", line 3, in <module>
    if x >= 30:
TypeError: '>=' not supported between instances of 'str' and 'int'


Fixed submission:

x = input()

if x >= 30:
    print("Yes")
else:
    print("No")
Problem p02596 (Python) — buggy submission, verdict: Runtime Error

k = int(input())
a = 7
for i in range(1, k + 1):
    if a % k == 0:
        print(i)
        exit()
    a = (10 * a + 7) % k
print(-1)


Error: 0

Fixed submission:

k = int(input())
a = 7
i = 1
F = [0] * k
while F[a % k] == 0:
    F[a] = 1
    a = ((10 * a) + 7) % k
    i += 1
    if a == 0:
        print(i)
        exit()
print(-1)
Problem p02596 (Python) — buggy submission, verdict: Time Limit Exceeded

K = int(input())

ans = 1
a = 7
i = K
while i > 0:
    m = a % K
    if m == 0:
        print(ans)
        break
    else:
        ans += 1
        a = m * 10 + 7
        i -= 1
if m != 0:
    print(-1)


Error: TLE

Fixed submission:

K = int(input())

ans = 1
a = 7
i = K
while K > 0:
    m = a % K
    if m == 0:
        print(ans)
        break
    else:
        ans += 1
        a = m * 10 + 7
        i -= 1
if m != 0:
    print(-1)
Problem p02596 (Python) — buggy submission, verdict: Time Limit Exceeded

K = int(input())
a = 7
for i in range(K):
    if a % K == 0:
        print(i + 1)
        break
    else:
        a = 10 * (a % K) + 7
else:
    print(-1)


Error: TLE

Fixed submission:

k = int(input())
n = 1
list = []
r = 7
while True:
    r = r % k
    if r == 0:
        print(n)
        break
    elif r in list:
        print(-1)
        break
    else:
        list.append(r)
        r = r * 10 + 7
        n += 1
Problem p02596 (Python) — buggy submission, verdict: Time Limit Exceeded

k = int(input())

if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    ans = 1
    num = 7
    while True:
        if num % k == 0:
            print(ans)
            break
        else:
            ans += 1
            num += 7 * pow(10, ans - 1, k)
            num %= k


Error: TLE

Fixed submission:

k = int(input())

if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    ans = 1
    num = 7
    while True:
        if int(num) % k == 0:
            print(ans)
            break
        else:
            ans += 1
            num += 7 * pow(10, ans - 1, k)
            num %= k
Problem p02596 (Python) — buggy submission, verdict: Time Limit Exceeded

k = int(input())

if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    ans = 1
    num = 7 % k
    temp = 7 % k
    while True:
        if num % k == 0:
            print(ans)
            break
        else:
            ans += 1
            temp = temp * 10 % k
            num += temp % k
            num %= k


Error: TLE

Fixed submission:

k = int(input())

if k % 2 == 0:
    print(-1)
else:
    ans = 1
    num = 7 % k
    temp = 7 % k
    while True:
        if num % k == 0:
            print(ans)
            break
        else:
            ans += 1
            temp = temp * 10 % k
            num += temp % k
            num %= k
Problem p02596 (Python) — buggy submission, verdict: Time Limit Exceeded

k = int(input())
if k % 2 == 0:
    print(-1)
else:
    mod = 7 % k
    counter = 1
    memo = 1
    mod_map = set()
    mod_map.add(mod)
    while mod != 0:
        memo = ((memo % k) * (10 % k)) % k
        mod = (mod + 7 * memo) % k
        if mod not in mod_map:
            mod_map.add(mod)
        else:
            counter = -1
            break
        counter += 1
        if mod == 0:
            break
    print(counter)


Error: TLE

Fixed submission:

k = int(input())
if k % 2 == 0:
    print(-1)
else:
    mod = 7 % k
    counter = 1
    memo = 1
    while mod != 0:
        memo = ((memo % k) * (10 % k)) % k
        mod = (mod + 7 * memo) % k
        counter += 1
        if mod == 0:
            break
    print(counter)
Problem p02596 (Python) — buggy submission, verdict: Time Limit Exceeded

K = int(input())
if K % 2 == 0:
    print(-1)
    exit()

x = 7 % K
i = 1
while True:
    if x == 0:
        print(i)
        exit()
    x = (x * 10 + 7) % K
    i += 1
    if i > 10**6:
        print(-1)
        exit()


Error: TLE

Fixed submission:

K = int(input())
if K % 2 == 0:
    print(-1)
    exit()

x = 7 % K
i = 1
while True:
    if x == 0:
        print(i)
        exit()
    y = (x * 10 + 7) % K
    if x == y:
        print(-1)
        exit()
    x = y
    i += 1
Problem p02596 (Python) — buggy submission, verdict: Time Limit Exceeded

k = int(input())
s = 7
num = 1
res = True
if k == 2:
    print(-1)
else:
    for i in range(k):
        s %= k
        if s == 0:
            res = False
            print(num)
            break
        num += 1
        s *= 10
        s += 7
    if res:
        print(-1)


Error: TLE

Fixed submission:

k = int(input())
s = 7
num = 1
if k == 2:
    print(-1)
else:
    while 1:
        s %= k
        if s == 0:
            print(num)
            break
        num += 1
        s *= 10
        s += 7
Problem p02596 (Python) — buggy submission, verdict: Time Limit Exceeded

k = int(input())
seven = 7
ans = -1

for i in range(1, k + 1):
    seven %= k
    if seven == 0:
        ans = i
        break
    else:
        seven = seven * 10 + 7

print(ans)


Error: TLE

Fixed submission:

k = int(input())
seven = 7
ans = 1

if k % 2 == 0:
    ans = -1
elif k == 1 or k == 7:
    ans = 1
else:
    while seven % k != 0:
        seven = seven * 10 + 7
        ans += 1

print(ans)
Problem p02596 (Python) — buggy submission, verdict: Time Limit Exceeded

K = int(input())

if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()

ans = 0
ai = 0
while True:
    ai = (ai * 10 + 7) % K
    ans += 1
    if ai % K == 0:
        print(ans)
        exit()


Error: TLE

Fixed submission:

K = int(input())

if K % 2 == 0:
    print(-1)
    exit()
if K % 5 == 0:
    print(-1)
    exit()

seven = 0
for i in range(10**6):
    seven = seven * 10 + 7
    if seven % K == 0:
        print(i + 1)
        exit()

print(-1)
Problem p02596 (Python) — buggy submission, verdict: Time Limit Exceeded

# coding: utf-8
k = int(input())
ans = -1
x = 7

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


Error: TLE

Fixed submission:

# coding: utf-8
k = int(input())
kx = k
if k % 2 == 1:
    while True:
        num = list(str(kx))
        if all(kx == "7" for kx in num):
            print(len(str(kx)))
            break
        kx = kx + k
else:
    print("-1")
Problem p02596 (Python) — buggy submission, verdict: Time Limit Exceeded

K = int(input())
count = 1
check = 7

if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    while True:
        if check % K == 0:
            print(count)
            break
        else:
            count += 1
            check = (check * 10 + 7) % K


Error: TLE

Fixed submission:

K = int(input())
count = 1
check = 7

if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    while True:
        if check % K == 0:
            print(count)
            break
        else:
            count += 1
            check = check * 10 + 7
Problem p02596 (Python) — buggy submission, verdict: Time Limit Exceeded

k = int(input())
count = 1
x = 7
while x % k != 0 and count <= k:
    count += 1
    x = (10 * x + 7) % k

if x % k == 0:
    print(count)
else:
    print(-1)


Error: TLE

Fixed submission:

k = int(input())
k_str = str(k)

if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    seven = 7
    seven_str = "7"
    while int(seven_str) % k != 0:
        seven_str += "7"
    print(len(seven_str))
Problem p02596 (Python) — buggy submission, verdict: Time Limit Exceeded

x = int(input())
cnt = 1
mod = 7

for i in range(x):
    if mod % x == 0:
        print(cnt)
        exit()
    mod = (10 * mod + 7) % x
    cnt += 1
print(-1)


Error: TLE

Fixed submission:

x = int(input())
if x % 2 == 0:
    print(-1)
    exit()
s = 7
cnt = 1
while True:
    if s % x == 0:
        print(cnt)
        break
    s = s * 10 + 7
    cnt += 1
Problem p02596 (Python) — buggy submission, verdict: Time Limit Exceeded

from itertools import count

k = int(input())
if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    m = 0
    for i in count(0):
        m += pow(10, i, k) * 7
        m %= k
        if m == 0:
            print(i + 1)
            break


Error: TLE

Fixed submission:

k = int(input())

if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    i = 7
    while True:
        if i % k == 0:
            print(len(str(i)))
            break
        i *= 10
        i += 7
Problem p02596 (Python) — buggy submission, verdict: Time Limit Exceeded

K = int(input())

if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()
now = 0
count = 0
while True:
    now = (now * 10 + 7) % K
    count += 1
    if now % K == 0:
        print(count)
        exit()


Error: TLE

Fixed submission:

K = int(input())

if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()
now = 0
count = 0
while True:
    now = now * 10 + 7
    count += 1
    if now % K == 0:
        print(count)
        exit()
Problem p02596 (Python) — buggy submission, verdict: Time Limit Exceeded

K = int(input())
if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    mod, modt, ans = 7 % K, 7 % K, 1
    while mod != 0:
        modt = (modt * (10 % K)) % K
        mod, ans = (mod + modt) % K, ans + 1
    print(ans)


Error: TLE

Fixed submission:

K = int(input())
if K % 2 == 0:
    print(-1)
else:
    mod, modt, ans = 7 % K, 7 % K, 1
    while mod != 0:
        modt = (modt * (10 % K)) % K
        mod, ans = (mod + modt) % K, ans + 1
    print(ans)
Problem p02596 (Python) — buggy submission, verdict: Time Limit Exceeded

K = int(input())
if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()
else:
    n = 7
    n_before = 7
    count = 0
    while True:
        count += 1
        n = n % K
        if n == 0:
            print(count)
            exit()
        else:
            n_before = 10 * n_before % K
            n = n + n_before
print(count)


Error: TLE

Fixed submission:

K = int(input())
if K % 2 == 0:
    print(-1)
    exit()
else:
    n = 7
    n_before = 7
    count = 1
    while n % K != 0:
        n = n % K
        count += 1
        n_before = 10 * n_before % K
        n = n + n_before
print(count)
Problem p02596 (Python) — buggy submission, verdict: Runtime Error

k = int(input())
if k % 7 == 0:
    L = 9 * k // 7
else:
    L = 9 * k
out = -1
s = 10
for i in range(L):
    if s % L == 1:
        out = i + 1
        break
    else:
        s = (s % L) * 10
print(out)


Error: 0

Fixed submission:

k = int(input())
if k % 7 == 0:
    L = 9 * k / 7
else:
    L = 9 * k
out = -1
s = 10
for i in range(L):
    if s % L == 1:
        out = i + 1
        break
    else:
        s = (s % L) * 10
print(out)
Problem p02597 (Python) — buggy submission, verdict: Runtime Error

import sys
from collections import Counter

N = int(sys.stdin.readline().rstrip())
S = [x for x in input()]

C = Counter(S)

W = C["W"]
R = C["R"]

SS = S[:R]
CC = Counter(SS)
RR = CC["W"]

print(RR)


Error: 0

Fixed submission:

import sys

N = int(sys.stdin.readline().rstrip())
TMP_C = [x for x in input()]
C = []
for i in range(N - 1, -1, -1):
    C.append(TMP_C[i])
# print(C)

cnt = 0
for i in range(N - 1, -1, -1):
    if C[i] == "W":
        j = C.index("R")
        if j < i:
            C[i], C[j] = C[j], C[i]
            cnt += 1

print(cnt)
Problem p02597 (Python) — buggy submission, verdict: Runtime Error

n = int(input())
c = input()
lists = list(c)
cnt = 0

for i in range(len(lists)):
    if lists[i] == "R":
        cnt += 1
change = 0
for i in range(cnt):
    if lists[i] == "W":
        change += 1
print(change)


Error: WA

Fixed submission:

n = int(input())
c = input()
lists = list(c)
cnt = 0
while 1:
    if lists[cnt] == "W":
        cnt += 1
    else:
        break
number = 0
for i in range(len(lists) - cnt):
    if lists[i + cnt] == "W":
        number += 1
print(number)
Problem p02598 (Python) — buggy submission, verdict: Runtime Error

def is_good(mid, key):
    res = 0
    for a in A:
        res += (a + mid - 1) // mid
    return res - N <= key


def binary_search(bad, good, key):
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


N, K, *A = map(int, open(0).read().split())
print(binary_search(0, 1_000_000_000, K))


Error: 0

Fixed submission:

def is_good(mid, key):
    res = 0
    for a in A:
        res += (a + mid - 1) // mid - 1
    return res <= key


def binary_search(bad, good, key):
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


N, K, *A = map(int, open(0).read().split())
print(binary_search(-1, 1_000_000_000, K))
Problem p02598 (Python) — buggy submission, verdict: Runtime Error

from math import ceil

N, K, *A = map(int, open(0).read().split())


def is_ok(n):
    t = 0
    for a in A:
        if a <= n:
            continue
        t += ceil(a / n) - 1
    return t <= K


ok = 1000000000
ng = 0.0000000001
while abs(ng - ok) > 1:
    m = (ok + ng) // 2
    if is_ok(m):
        ok = m
    else:
        ng = m

print(ceil(ok))


Error: TypeError: '<' not supported between instances of 'NoneType' and 'tuple'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02598/Python/s856589706.py", line 12, in <module>
    heapify(a)
TypeError: '<' not supported between instances of 'NoneType' and 'tuple'


Fixed submission:

from math import ceil
from heapq import heapify, heappop, heappush

N, K, *A = map(int, open(0).read().split())

t = sum(A) / K
a = [None] * len(A)
for i in A:
    k = max(ceil(i / t), 1)
    a.append((-i / k, i, k))

heapify(a)
for _ in range(K):
    i, j, k = heappop(a)
    k += 1
    i = -(j / k)
    heappush(a, (i, j, k))
print(ceil(heappop(a)[0] * -1))
Problem p02598 (Python) — buggy submission, verdict: Runtime Error

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

b = 0
e = max(A)
L = e // 2
while e - b > 1:
    L = (e + b) // 2
    m = sum(list(map(lambda x: (x - 1) // L, A)))
    if m <= k:
        e = L
    else:
        b = L
print(e)


Error: TLE

Fixed submission:

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

b = 0
e = max(A)
L = e // 2
while e - b >= 1:
    m = sum(list(map(lambda x: x // L, A)))
    if m <= k:
        e = L
        L = (e + b) // 2
    else:
        b = L
        L = (e + b) // 2
print(e)
Problem p02598 (Python) — buggy submission, verdict: Runtime Error

# ABC174 E

n, k = map(int, input().split())
a_l = [int(x) for x in input().split()]

left = 0
right = max(a_l)


def cut(len):
    ret = 0
    for i in range(n):
        if a_l[i] % len == 0:
            ret += a_l[i] // len - 1
        else:
            ret += a_l[i] // len
    return ret


while (right - left) > 1:
    _q = (left + right) // 2
    _ret = cut(_q)
    if k >= _ret:
        right = _q
    else:
        left = _q

print(right)


Error: 0

Fixed submission:

# ABC174 E

n, k = map(int, input().split())
a_l = [int(x) for x in input().split()]

left = 0
right = max(a_l)


def cut(len):
    ret = 0
    for i in range(n):
        if a_l[i] % len == 0:
            ret += a_l[i] // len - 1
        else:
            ret += a_l[i] // len
    return ret


while (right - left) > 1:
    _q = max((left + right) // 2, 1)
    _ret = cut(_q)
    if k >= _ret:
        right = _q
    else:
        left = _q

_l = cut(left)
_r = cut(right)

if _l <= k:
    print(left)
else:
    print(right)
Problem p02599 (Python) — buggy submission, verdict: Time Limit Exceeded

class BIT:
    # 1-indexed
    def __init__(self, n):
        self.size = n + 1
        self.bit = [0] * self.size

    def add(self, i, x):
        # Add x to a[i]
        while i < self.size:
            self.bit[i] += x
            i += i & -i

    def sumup(self, i):
        # Sum a[1]~a[i]
        res = 0
        while i > 0:
            res += self.bit[i]
            i -= i & -i
        return res

    def query(self, i, j):
        # Sum a[i]~a[j]
        return self.sumup(j) - self.sumup(i - 1)


N, Q = map(int, input().split())
C = list(map(int, input().split()))

X = []
for i in range(Q):
    l, r = map(int, input().split())
    X.append((i, l, r))
X.sort(key=lambda x: x[2])

ans = [0] * Q
bit = BIT(N + 1)
last = [0] * (N + 1)
k = 0
for i, l, r in X:
    for j in range(k + 1, r + 1):
        if last[C[j - 1]] > 0:
            bit.add(last[C[j - 1]], -1)

        bit.add(j, 1)
        last[C[j - 1]] = j

    k = r
    ans[i] = bit.query(l, r)

print(*ans, sep="\\n")


Error: TLE

Fixed submission:

class BIT:
    # 1-indexed
    def __init__(self, n):
        self.size = n + 1
        self.bit = [0] * self.size

    def add(self, i, x):
        """Add x to a[i]."""
        while i < self.size:
            self.bit[i] += x
            i += i & -i

    def sumup(self, i):
        """Sum a[1]~a[i]."""
        res = 0
        while i > 0:
            res += self.bit[i]
            i -= i & -i
        return res

    def query(self, i, j):
        """Sum a[i]~a[j]."""
        return self.sumup(j) - self.sumup(i - 1)


N, Q = map(int, input().split())
C = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(Q)]

ans = [0] * Q
last_appeared = [0] * (N + 1)
bit = BIT(N + 1)
rm = 0
for i, (l, r) in sorted(enumerate(X), key=lambda x: x[1][1]):
    for j in range(rm + 1, r + 1):
        if last_appeared[C[j - 1]] > 0:
            bit.add(last_appeared[C[j - 1]], -1)
        last_appeared[C[j - 1]] = j
        bit.add(j, 1)

    rm = r
    ans[i] = bit.query(l, r)

print(*ans, sep="\\n")
Problem p02599 (Python) — buggy submission, verdict: Time Limit Exceeded

from sys import stdin

input = stdin.readline


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


N, Q = map(int, input().split())
c = list(map(int, input().split()))

lr = []
for i in range(Q):
    l, r = map(int, input().split())
    lr.append([l, r, i])

lr.sort(key=lambda x: x[1])
# print("lr", lr)
rightest = [-1] * (N + 1)
current_q = 0
bit = Bit(N)
ans = [0] * Q

for i in range(N):
    if rightest[c[i]] != -1:
        bit.add(rightest[c[i]] + 1, -1)
    rightest[c[i]] = i
    bit.add(i + 1, 1)
    # print(bit.tree)

    while current_q < Q and lr[current_q][1] == i + 1:
        ans[lr[current_q][2]] = bit.sum(lr[current_q][1]) - bit.sum(lr[current_q][0] - 1)
        current_q += 1

for i in range(Q):
    print(ans[i])


Error: TLE

Fixed submission:

# from sys import stdin
# input = stdin.readline


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


N, Q = map(int, input().split())
c = list(map(int, input().split()))

lr = []
for i in range(Q):
    l, r = map(int, input().split())
    lr.append([l, r, i])

lr.sort(key=lambda x: x[1])
# print("lr", lr)
rightest = [-1] * (N + 1)
current_q = 0
bit = Bit(N)
ans = [0] * Q

for i in range(N):
    if rightest[c[i]] != -1:
        bit.add(rightest[c[i]] + 1, -1)
    rightest[c[i]] = i
    bit.add(i + 1, 1)
    # print(bit.tree)

    while current_q < Q and lr[current_q][1] == i + 1:
        ans[lr[current_q][2]] = bit.sum(lr[current_q][1]) - bit.sum(lr[current_q][0] - 1)
        current_q += 1

for i in range(Q):
    print(ans[i])