Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left, insort_left


def main():
    n = int(input())
    s = list(input())
    q = int(input())
    qs = [input().split() for _ in range(q)]

    abc = [[] for _ in range(26)]
    for i, e in enumerate(s):
        j = ord(e) - ord("a")
        abc[j].append(i)

    for t, e1, e2 in qs:
        if t == "1":
            i = int(e1) - 1
            c = e2

            let = s[i]

            idx = ord(let) - ord("a")
            popi = bisect_left(abc[idx], i)
            abc[idx].pop(popi)

            idx = ord(c) - ord("a")
            insort_left(abc[idx], i)

            s[i] = c

        else:
            l = int(e1) - 1
            r = int(e2) - 1

            cnt = 0
            for i in range(26):
                li = bisect_left(abc[i], l)
                if li >= len(abc[i]):
                    continue
                if abc[i][li] <= r:
                    cnt += 1

            print(cnt)


if __name__ == "__main__":
    main()


Fixed submission:
from bisect import bisect_left, insort_left


def main():
    n = int(input())
    s = list(input())
    q = int(input())
    qs = [input().split() for _ in range(q)]

    abc = [[] for _ in range(26)]
    for i, e in enumerate(s):
        j = ord(e) - ord("a")
        abc[j].append(i)

    for t, e1, e2 in qs:
        if t == "1":
            i = int(e1) - 1
            c = e2

            let = s[i]

            if let == c:
                continue

            idx = ord(let) - ord("a")
            popi = bisect_left(abc[idx], i)
            abc[idx].pop(popi)

            idx = ord(c) - ord("a")
            insort_left(abc[idx], i)

            s[i] = c

        else:
            l = int(e1) - 1
            r = int(e2) - 1

            cnt = 0
            for i in range(26):
                li = bisect_left(abc[i], l)
                if li >= len(abc[i]):
                    continue
                if abc[i][li] <= r:
                    cnt += 1

            print(cnt)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left, bisect_right, insort_left


def main():
    n = int(input())
    s = list(input())
    q = int(input())
    qs = [input().split() for _ in range(q)]

    abc = [[] for _ in range(26)]
    for i, e in enumerate(s):
        j = ord(e) - ord("a")
        abc[j].append(i)

    for t, e1, e2 in qs:
        if t == "1":
            i = int(e1) - 1
            c = e2

            let = s[i]

            idx = ord(let) - ord("a")
            popi = bisect_left(abc[idx], i)
            abc[idx].pop(popi)

            idx = ord(c) - ord("a")
            insort_left(abc[idx], i)

            s[i] = c

        else:
            l = int(e1) - 1
            r = int(e2) - 1

            cnt = 0
            for i in range(26):
                li = bisect_left(abc[i], l)
                ri = bisect_right(abc[i], r)
                if li != ri:
                    cnt += 1

            print(cnt)


if __name__ == "__main__":
    main()


Fixed submission:
from bisect import bisect_left, insort_left


def main():
    n = int(input())
    s = list(input())
    q = int(input())
    qs = [input().split() for _ in range(q)]

    abc = [[] for _ in range(26)]
    for i, e in enumerate(s):
        j = ord(e) - ord("a")
        abc[j].append(i)

    for t, e1, e2 in qs:
        if t == "1":
            i = int(e1) - 1
            c = e2

            let = s[i]

            if let == c:
                continue

            idx = ord(let) - ord("a")
            popi = bisect_left(abc[idx], i)
            abc[idx].pop(popi)

            idx = ord(c) - ord("a")
            insort_left(abc[idx], i)

            s[i] = c

        else:
            l = int(e1) - 1
            r = int(e2) - 1

            cnt = 0
            for i in range(26):
                li = bisect_left(abc[i], l)
                if li >= len(abc[i]):
                    continue
                if abc[i][li] <= r:
                    cnt += 1

            print(cnt)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left, bisect_right, insort_left


def main():
    n = int(input())
    s = list(input())
    q = int(input())
    qs = [input().split() for _ in range(q)]

    abc = [[] for _ in range(26)]
    for i, e in enumerate(s):
        j = ord(e) - ord("a")
        abc[j].append(i)

    for t, e1, e2 in qs:
        if t == "1":
            i = int(e1) - 1
            c = e2

            let = s[i]

            idx = ord(let) - ord("a")
            popi = bisect_left(abc[idx], i)
            abc[idx].pop(popi)

            idx = ord(c) - ord("a")
            insort_left(abc[idx], i)

            s[i] = c

        else:
            l = int(e1) - 1
            r = int(e2) - 1

            cnt = 0
            for i in range(26):
                li = bisect_left(abc[i], l)
                ri = bisect_right(abc[i], r)
                if li != ri:
                    cnt += 1

            print(cnt)


if __name__ == "__main__":
    main()


Fixed submission:
from bisect import bisect_left, insort_left


def main():
    n = int(input())
    s = list(input())
    q = int(input())
    qs = [input().split() for _ in range(q)]

    abc = [[] for _ in range(26)]
    for i, e in enumerate(s):
        j = ord(e) - ord("a")
        abc[j].append(i)

    for t, e1, e2 in qs:
        if t == "1":
            i = int(e1) - 1
            c = e2

            let = s[i]

            if let == c:
                continue

            idx = ord(let) - ord("a")
            popi = bisect_left(abc[idx], i)
            abc[idx].pop(popi)

            idx = ord(c) - ord("a")
            insort_left(abc[idx], i)

            s[i] = c

        else:
            l = int(e1) - 1
            r = int(e2) - 1

            cnt = 0
            for i in range(26):
                li = bisect_left(abc[i], l)
                if li >= len(abc[i]):
                    continue
                if abc[i][li] <= r:
                    cnt += 1

            print(cnt)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left, bisect_right, insort_left

n = int(input())
s = list(input())
q = int(input())
qs = [list(input().split()) for _ in range(q)]

abc = [[] for _ in range(26)]
for i, e in enumerate(s):
    j = ord(e) - ord("a")
    abc[j].append(i)

for t, e1, e2 in qs:
    if t == "1":
        i = int(e1) - 1
        c = e2

        let = s[i]

        idx = ord(let) - ord("a")
        popi = bisect_left(abc[idx], i)
        abc[idx].pop(popi)

        idx = ord(c) - ord("a")
        insort_left(abc[idx], i)

        s[i] = c

    else:
        l = int(e1) - 1
        r = int(e2) - 1

        cnt = 0
        for i in range(26):
            li = bisect_left(abc[i], l)
            ri = bisect_right(abc[i], r)
            if li != ri:
                cnt += 1

        print(cnt)


Fixed submission:
from bisect import bisect_left, insort_left


def main():
    n = int(input())
    s = list(input())
    q = int(input())
    qs = [input().split() for _ in range(q)]

    abc = [[] for _ in range(26)]
    for i, e in enumerate(s):
        j = ord(e) - ord("a")
        abc[j].append(i)

    for t, e1, e2 in qs:
        if t == "1":
            i = int(e1) - 1
            c = e2

            let = s[i]

            if let == c:
                continue

            idx = ord(let) - ord("a")
            popi = bisect_left(abc[idx], i)
            abc[idx].pop(popi)

            idx = ord(c) - ord("a")
            insort_left(abc[idx], i)

            s[i] = c

        else:
            l = int(e1) - 1
            r = int(e2) - 1

            cnt = 0
            for i in range(26):
                li = bisect_left(abc[i], l)
                if li >= len(abc[i]):
                    continue
                if abc[i][li] <= r:
                    cnt += 1

            print(cnt)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left, bisect_right, insort_left

n = int(input())
s = list(input())
q = int(input())
qs = [list(input().split()) for _ in range(q)]

abc = [[-1, n] for _ in range(26)]
for i, e in enumerate(s):
    j = ord(e) - ord("a")
    abc[j].append(i)

for i in range(26):
    abc[i].sort()

for t, e1, e2 in qs:
    if t == "1":
        i = int(e1) - 1
        c = e2

        let = s[i]

        idx = ord(let) - ord("a")
        popi = bisect_left(abc[idx], i)
        abc[idx].pop(popi)

        idx = ord(c) - ord("a")
        insort_left(abc[idx], i)

        s[i] = c

    else:
        l = int(e1) - 1
        r = int(e2) - 1

        cnt = 0
        for i in range(26):
            li = bisect_left(abc[i], l)
            ri = bisect_right(abc[i], r)
            if li != ri:
                cnt += 1

        print(cnt)


Fixed submission:
from bisect import bisect_left, insort_left


def main():
    n = int(input())
    s = list(input())
    q = int(input())
    qs = [input().split() for _ in range(q)]

    abc = [[] for _ in range(26)]
    for i, e in enumerate(s):
        j = ord(e) - ord("a")
        abc[j].append(i)

    for t, e1, e2 in qs:
        if t == "1":
            i = int(e1) - 1
            c = e2

            let = s[i]

            if let == c:
                continue

            idx = ord(let) - ord("a")
            popi = bisect_left(abc[idx], i)
            abc[idx].pop(popi)

            idx = ord(c) - ord("a")
            insort_left(abc[idx], i)

            s[i] = c

        else:
            l = int(e1) - 1
            r = int(e2) - 1

            cnt = 0
            for i in range(26):
                li = bisect_left(abc[i], l)
                if li >= len(abc[i]):
                    continue
                if abc[i][li] <= r:
                    cnt += 1

            print(cnt)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left, bisect_right, insort_left

n = int(input())
s = list(input())
q = int(input())
qs = [list(input().split()) for _ in range(q)]

abc = [[-1, n] for _ in range(26)]
for i, e in enumerate(s):
    j = ord(e) - ord("a")
    abc[j].append(i)

for i in range(26):
    abc[i].sort()

for t, e1, e2 in qs:
    if t == "1":
        i = int(e1) - 1
        c = e2

        let = s[i]

        idx = ord(let) - ord("a")
        popi = bisect_left(abc[idx], i)
        abc[idx].pop(popi)

        idx = ord(c) - ord("a")
        insort_left(abc[idx], i)

        s[i] = c

    else:
        l = int(e1) - 1
        r = int(e2) - 1

        cnt = 0
        for i in range(26):
            li = bisect_left(abc[i], l)
            ri = bisect_right(abc[i], r)
            if li != ri:
                cnt += 1

        print(cnt)


Fixed submission:
from bisect import bisect_left, insort_left


def main():
    n = int(input())
    s = list(input())
    q = int(input())
    qs = [input().split() for _ in range(q)]

    abc = [[] for _ in range(26)]
    for i, e in enumerate(s):
        j = ord(e) - ord("a")
        abc[j].append(i)

    for t, e1, e2 in qs:
        if t == "1":
            i = int(e1) - 1
            c = e2

            let = s[i]

            if let == c:
                continue

            idx = ord(let) - ord("a")
            popi = bisect_left(abc[idx], i)
            abc[idx].pop(popi)

            idx = ord(c) - ord("a")
            insort_left(abc[idx], i)

            s[i] = c

        else:
            l = int(e1) - 1
            r = int(e2) - 1

            cnt = 0
            for i in range(26):
                li = bisect_left(abc[i], l)
                if li >= len(abc[i]):
                    continue
                if abc[i][li] <= r:
                    cnt += 1

            print(cnt)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left, bisect_right, insort_left

n = int(input())
s = input()
q = int(input())
qs = [list(input().split()) for _ in range(q)]

abc = [[-1, n] for _ in range(26)]
for i, e in enumerate(s):
    j = ord(e) - ord("a")
    abc[j].append(i)

for i in range(26):
    abc[i].sort()

for t, e1, e2 in qs:
    if t == "1":
        i = int(e1) - 1
        c = e2

        let = s[i]

        idx = ord(let) - ord("a")
        popi = bisect_left(abc[idx], i)
        abc[idx].pop(popi)

        idx = ord(c) - ord("a")
        insort_left(abc[idx], i)

    else:
        l = int(e1) - 1
        r = int(e2) - 1

        cnt = 0
        for i in range(26):
            li = bisect_left(abc[i], l)
            ri = bisect_right(abc[i], r)
            if li != ri:
                cnt += 1

        print(cnt)


Fixed submission:
from bisect import bisect_left, insort_left


def main():
    n = int(input())
    s = list(input())
    q = int(input())
    qs = [input().split() for _ in range(q)]

    abc = [[] for _ in range(26)]
    for i, e in enumerate(s):
        j = ord(e) - ord("a")
        abc[j].append(i)

    for t, e1, e2 in qs:
        if t == "1":
            i = int(e1) - 1
            c = e2

            let = s[i]

            if let == c:
                continue

            idx = ord(let) - ord("a")
            popi = bisect_left(abc[idx], i)
            abc[idx].pop(popi)

            idx = ord(c) - ord("a")
            insort_left(abc[idx], i)

            s[i] = c

        else:
            l = int(e1) - 1
            r = int(e2) - 1

            cnt = 0
            for i in range(26):
                li = bisect_left(abc[i], l)
                if li >= len(abc[i]):
                    continue
                if abc[i][li] <= r:
                    cnt += 1

            print(cnt)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left, bisect_right, insort_left

n = int(input())
s = input()
q = int(input())
qs = [list(input().split()) for _ in range(q)]

abc = [[-1, n] for _ in range(26)]
for i, e in enumerate(s):
    j = ord(e) - ord("a")
    abc[j].append(i)

for i in range(26):
    abc[i].sort()

for t, e1, e2 in qs:
    if t == "1":
        i = int(e1) - 1
        c = e2

        let = s[i]

        idx = ord(let) - ord("a")
        popi = bisect_left(abc[idx], i)
        abc[idx].pop(popi)

        idx = ord(c) - ord("a")
        insort_left(abc[idx], i)

    else:
        l = int(e1) - 1
        r = int(e2) - 1

        cnt = 0
        for i in range(26):
            li = bisect_left(abc[i], l)
            ri = bisect_right(abc[i], r)
            if li != ri:
                cnt += 1

        print(cnt)


Fixed submission:
from bisect import bisect_left, insort_left


def main():
    n = int(input())
    s = list(input())
    q = int(input())
    qs = [input().split() for _ in range(q)]

    abc = [[] for _ in range(26)]
    for i, e in enumerate(s):
        j = ord(e) - ord("a")
        abc[j].append(i)

    for t, e1, e2 in qs:
        if t == "1":
            i = int(e1) - 1
            c = e2

            let = s[i]

            if let == c:
                continue

            idx = ord(let) - ord("a")
            popi = bisect_left(abc[idx], i)
            abc[idx].pop(popi)

            idx = ord(c) - ord("a")
            insort_left(abc[idx], i)

            s[i] = c

        else:
            l = int(e1) - 1
            r = int(e2) - 1

            cnt = 0
            for i in range(26):
                li = bisect_left(abc[i], l)
                if li >= len(abc[i]):
                    continue
                if abc[i][li] <= r:
                    cnt += 1

            print(cnt)


if __name__ == "__main__":
    main()