Problem:


Score : 100 points

Problem Statement

Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper.

At least how many sheets of paper does he need?

Constraints

N is an integer.

1 \leq N \leq 100

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

5

Sample Output 1

3

By printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the 2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3 sheets of paper.

Sample Input 2

2

Sample Output 2

1

Sample Input 3

100

Sample Output 3

50



Sample input:
5


Sample output:
3

Submission status: Runtime Error

Solution code:
import copy

A = []
for x in range(3):
 A.append(list(map(int,input().split())))

A_rep = copy.deepcopy(A)

N = int(input())

B = []
for x in range(N):
    B.append(int(input()))
    #B = int(input())

for x in range(3):   
    for y in range(3):
        for z in B:
            if A_rep[x][y] == z:
                A_rep[x][y] = -1

#print(A)
#print(A_rep)
#print(B)

for x in range(3):
    if max(A_rep[x]) == -1:
        print("Yes")
        exit()

if A_rep[0][0] == -1 and A_rep[1][0] == -1 and A_rep[2][0] == -1:
    print("Yes")
    exit()

if A_rep[0][1] == -1 and A_rep[1][1] == -1 and A_rep[2][1] == -1:
    print("Yes")
    exit()

if A_rep[0][2] == -1 and A_rep[1][2] == -1 and A_rep[2][2] == -1:
    print("Yes")
    exit()


if A_rep[0][0] == -1 and A_rep[1][1] == -1 and A_rep[2][2] == -1:
    print("Yes")
    exit()

if A_rep[0][2] == -1 and A_rep[1][1] == -1 and A_rep[2][0] == -1:
    print("Yes")
    exit()

print("No")

Submission status: Runtime Error

Solution code:
N = int(input())

if N%2 <> 0:
  print(int(N/2+1))
else:
  print(int(N/2))

Submission status: Runtime Error

Solution code:
#A
n=input()
if n%2=0:
    ans=int(n/2)
else:
    ans=int(n/2)+1
print(ans)

Submission status: Runtime Error

Solution code:
N =input()
print(int(N+1)/2)

Submission status: Runtime Error

Solution code:
N = input()
print(N/2)

Submission status: Runtime Error

Solution code:
a = input()
if(a%2 == 1):
  print((a+1)//2)
if(a%2 == 0):
  print(a//2)

Submission status: Runtime Error

Solution code:
N = int(input())
if N % 2 = 0:
  print(2*N)
else:
R = N-1
  print(2*R+1)

Submission status: Runtime Error

Solution code:
N = int(input())
if N % 2 = 0:
  print(2*N)
else:
R = N-1
  print(2*N+1)

Submission status: Runtime Error

Solution code:
N = int(input())
if N % 2 = 0:
  print(2*N)
else:
  print(2*N+0.5)

Submission status: Runtime Error

Solution code:
n = int(input().split())
a = n // 2 + n % 2
print(a)

Submission status: Runtime Error

Solution code:
import bisect
import sys
sys.setrecursionlimit(10**9)

def main():
    N = int(input())
    S = list(input())

    a_ord = ord('a')
    z_ord = ord('z')

    set_list = [[] for _ in range(z_ord+1)]
    for i in range(N):
        s = S[i]
        set_list[ord(s)].append(i)

    Q = int(input())
    for q in range(Q):
        ipt = input().split()
        if ipt[0] == "1":
            i,c = int(ipt[1]), ipt[2]
            j = ord(S[i-1])

            if j == ord(c): continue
            set_list[j].remove(i-1)
            bisect.insort_left(set_list[ord(c)],i-1)
            S[i-1] = c
            # print(set_list[])

        else:
            l,r = int(ipt[1]), int(ipt[2])
            ans = 0
            # if l == r:
            #     print(1)
            #     continue

            for i in range(a_ord,z_ord+1):
                st = set_list[i]
                if not len(st) > 0: continue

                # print(i,set_list[i])
                l_p = bisect.bisect_left(st,l-1)
                r_p = bisect.bisect_right(st,r-1)

                # print(l-1,r-1,l_p,r_p)
                if l_p < r_p:
                    ans += 1

            # print(ans,"____")
            print(ans)



if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:
n = input()
if n % 2 == 0:
  print(n / 2)
else:
  print((n + 1) / 2)

Submission status: Runtime Error

Solution code:
N, M, K = map(int,input().split())
class UnionFind:
    def __init__(self, N):
        self.par = [-1 for i in range(N+1)]
        self.rank = [1]*(N+1)
    
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
        
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if self.rank[x] > self.rank[y]:
            self.par[x] += self.par[y]
            self.par[y] = x
        else:
            self.par[y] += self.par[x]
            self.par[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

UF = UnionFind(N)
friendlist = [[] for _ in range(N+1)]
for n in range(M):
    A, B = map(int,input().split())
    friendlist[A].append(B)
    friendlist[B].append(A)
    if not UF.same_check(A,B):
        UF.union(A, B)
blocklist = [[] for _ in range(N+1)]
for n in range(K):
    C, D = map(int, input().split())
    blocklist[C].append(D)
    blocklist[D].append(C)

for person in range(1,N+1):
    root = UF.find(person)
    ans = -UF.par[root]-1
    ans -= friendlist[person]
    for l in blocklist[person]:
        if UF.same_check(person,l):
            ans -= 1
    print(ans)

Submission status: Runtime Error

Solution code:
A=[list(map(int,input().split())) for i in range(3)]
AB=[[0 for i in range(3)] for j in range(3)]
N=int(input())
for i in range(N):
    x=int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k]==x:
                AB[j][k]=1
c=1
for i in range(3):
    if AB[i][0]*AB[i][1]*AB[i][2]==1:
        c=0
        break
    if AB[0][i]*AB[1][i]*AB[2][i]==1:
        c=0
        break
    if AB[0][0]*AB[1][1]*AB[2][2]==1:
        c=0
        break
    if AB[0][2]*AB[1][1]*AB[2][0]==1:
        c=0
        break
        

if c==1:
    print("No")
else:
  	print("Yes")

Submission status: Runtime Error

Solution code:
import math
print(int(math.ceil(floor(input())))

Submission status: Runtime Error

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

A = [na() for _ in range(3)]
n = ni()
b = [ni() for _ in range(n)]
bing = [["x"]*3 for i in range(3)]
for i in range(n):
  for j in range(3):
    if b[i] == A[0][j]:
      bing[0][j] = "o"
  for j in range(3):
    if b[i] == A[1][j]:
      bing[1][j] = "o"
  for j in range(3):
    if b[i] == A[2][j]:
      bing[2][j] = "o"

for i in range(3):
  if bing[i] == ["o","o","o"] or (bing[0][i] == "o" and bing[1][i] == "o" and bing[2][i] == "o"):
    print("y")
if (bing[0][0] == "o" and bing[1][1] == "o" and bing[2][2] == "o") or(bing[0][2] == "o" and bing[1][1] == "o" and bing[2][0] == "o"):
  print("y")
else:
  print("n")

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]
ans = []
SC = sorted(SC)

for x, item in enumerate(SC):
    if len(ans) + 1 < item[0]:
        if len(ans) == 0:
            ans.append(1)
        for y in range(item[0] -len(ans) - 1):
            ans.append(0)
    if len(ans) + 1 == item[0]:
        ans.append(item[1])
    elif len(ans) == item[0]:
        continue

if len(ans) < N:
    for x in range(N - len(ans)):
        ans.append(0)

if ans(0) == 0 and len(ans) != 0:
    print(-1)
else:
    ans = map(str, ans)
    print("".join(ans))

Submission status: Runtime Error

Solution code:
import sys
import math
import itertools
import collections
import heapq
import numpy as np

rl = sys.stdin.readline

n, m = map(int, rl().split())

a = [-1] * 3
isOk = False
for _ in range(m):
    b = list(map(int, rl().split()))
    if b[0]-1 != 2 and b[1] == 0: 
        isOk = True
        break
    if a[b[0]-1] != -1 and a[b[0]-1] != b[1]:
        isOk = True
        break
    a[b[0]-1] = b[1]

if isOk:
    print(-1)
else:
    ans = 0
    a.reverse()
    for i in range(3):
        if a[i] == -1:
            a[i] = 0
        ans += a[i]*(10**(i))
    print(ans)

Submission status: Runtime Error

Solution code:
N=input()
if N % 2 ==0:
  print(N/2)
else:
  print(N//2+1)

Submission status: Runtime Error

Solution code:
import math
print((int)(math.ceil((int)(input())))

Submission status: Runtime Error

Solution code:
from collections import deque

n, m, k = map(int, input().split())

friends = [[0] * n for _ in range(n)]

blocks = [[0] * n for _ in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    friends[a-1][b-1] = 1
    friends[b-1][a-1] = 1

for i in range(k):
    c, d = map(int, input().split())
    blocks[c-1][d-1] = 1
    blocks[d-1][c-1] = 1

for i in range(n):
    q = deque()
    q.append(i)
    cnt = [-1] * n
    cnt[i] = 0
    total = 0
    while q:
        k = q.popleft()
        for j in range(n):
            if friends[k][j] and cnt[j] == -1:
                q.append(j)
                cnt[j] = cnt[k] + 1
                if cnt[j] > 1 and not blocks[i][j]:
                    total += 1
    print(total)

Submission status: Runtime Error

Solution code:
import math
print(math.ceil(int(input()/2)))

Submission status: Runtime Error

Solution code:

N, M = map(int, input().split())
S, C = [], []
for i in range(M):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)

for i in range(10**(N-1), 10**(N)):
    t = str(i)
    flag = True
    for j in range(M):
        if t[S[j]-1] != str(C[j]):
            flag = False
    if flag:
        print(i)
        F = True
        break
if not F:
    print(-1)

Submission status: Runtime Error

Solution code:
if int(input()) % 2 == 0:
    print(int(input()) // 2)
else:
    print(int(input()) // 2 + 1)

Submission status: Runtime Error

Solution code:
N = input()
S = N / 2
if N % 2 = 0
	print(S)
else
	print(S + 1)

Submission status: Runtime Error

Solution code:
n=int(input())
if n%2==0:
  print (n/2)
else:
  a=(n//2+1)
  print a

Submission status: Runtime Error

Solution code:
n = int(input())

if n%2 == 0: print({}.format(n/2))
else:        print({}.format(n/2+1))

Submission status: Runtime Error

Solution code:
n = input()
print(-(-n//2))

Submission status: Runtime Error

Solution code:
N = input()
print(-((-N)//2))

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
o = {}
if N==1 and M==0:
  print(0)
else:
  for i in range(M):
    s,c = map(int,input().split())
    if o.get(s,-1)==-1:
        o[s]=c
    elif o.get(s,-1)!=-1 and o[s]!=c:
        print(-1)
        break
  else:
    m = [1]+[0]*(N-1)
    for k in o.keys():
        m[k-1]=o[k]
    if N!=1 and moji[0]==0:
      print(-1)
    else:
      print(''.join([str(a) for a in m]))

Submission status: Runtime Error

Solution code:
print(^(-1*int(input()) // 2))

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
s = []
c = []
if m == 0:
  if n==1:
    print(0)
    exit()
  elif n==2:
    print(10)
    exit()
  else:
    print(100)
    exit()


for i in range(m):
  S,C =  map(int,input().split())
  s.append(S)
  c.append(C)
  
num = [1] + [0]*(n-1)
ans = ''
 
for i in range(m):
  if n != 1 and s[i] == 1 and c[i] == 0:
    print(-1)
    exit()
  elif n == 1 and s[i] == 1 and c[i] == 0:
    print(-1)
    exit()
for i in range(m-1):
  for j in range(i+1,m):
    if s[i] == s[j] and c[i] != c[j]:
      print(-1)
      exit()
      
for i in range(m):
  num[s[i]-1] = c[i]
  
for i in range(n):
  ans += str(num[i])
  
print(ans)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
x = [0] * m
y = [0] * m
r = [0] * n
for i in range(m):
    x[i], y[i] = map(int, input().split())
    if r[x[i] - 1] == 0 or r[x[i] - 1] == y[i]:
        r[x[i] - 1] = y[i]
if n > 1 and r[0] == 0:
    print(-1)
else:
    print(*r, sep='')

Submission status: Runtime Error

Solution code:
# -*- coding: <encoding name> -*-

import math
n = map(int, input())
print(math.ceil(n / 2))

Submission status: Runtime Error

Solution code:
# -*- coding: <encoding name> -*-

import math
n = map(int, input())
print(math.ceil(n / 2)

Submission status: Runtime Error

Solution code:
# -*- coding: <encoding name> -*-

import math
n = map(int, input().split())
print(math.ceil(n / 2)

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
li=[0]*N
for i in range(M):
    si,ci=map(int,input().split())
    if li[si-1] != 0 and li[si-1] !=ci:
        print(-1)
        exit(0)
    if si==1 and ci==0:
        if N>1:
            print(-1)
            exit(0)
    li[si-1]=ci
if N>1 and li[0]==0:
    li[0]=1
for i in range(N):
    print(li[i],end="")

Submission status: Runtime Error

Solution code:
def check(T):
    column = any([all( [T[i][j] for j in range(3)] ) for i in range(3)])
    row = any([all( [T[j][i]for j in range(3)] ) for i in range(3)])
    diagonal = all( [T[i][i] for i in range(3)]) or all( [T[i][2-i] for i in range(3)])
    return row or column or diagonal

a = 3
grid =[[0]*a for i in range(a)]

d = {}
for i in range(3):
    row = list(map(int,input().split()))
    for j in range(3):
        d[row[j]] = (i,j)


N = int(input())
for i in range(N):
    p = int(input())

    if p in d.keys():
        x,y = d[p]
        grid[x][y] = 1

print( "Yes" if check(grid) else "No")

Submission status: Runtime Error

Solution code:
import queue
import sys 
input=sys.stdin.readline

def main():
    n,m,k=map(int,input().split())
    root={}
    ng={}

    for i in range(n):
        root[i]=[]
        ng[i]=[]
    for i in range(m):
        a,b=map(int,input().split())
        root[a-1].append(b-1)
        root[b-1].append(a-1)
        ng[a-1].append(b-1)
        ng[b-1].append(a-1)
    for i in range(k):
        a,b=map(int,input().split())
        ng[a-1].append(b-1)
        ng[b-1].append(a-1)
    
    Vstd=tuple([])
    checkVst=[False]*n
    num=[0]*n
    ToVst=queue.Queue()
    for i in range(n):
        if checkVst[i]:
            continue
        Vstd=[]
        now=i
        Vstd.append(now)
        checkVst[now]=True

        for kouho in root[now]:
            if checkVst[kouho]:
                continue
            ToVst.put(kouho)
            checkVst[kouho]=True

        while ToVst.empty()==False:
            now=ToVst.get()
            Vstd.append(now)
            checkVst[now]=True
           
            for kouho in root[now]:
                if checkVst[kouho]:
                    continue
                ToVst.put(kouho)
                checkVst[kouho]=True
                
        lengh=len(Vstd)
        for v in Vstd:
            num[v]=lengh-1
            num[v]-=len(set(ng[v])&set(Vstd))
    print(*num)
    #print(" ".join(map(str,num)))
   

if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
import queue
import sys 
input=sys.stdin.readline
def main():
    n,m,k=map(int,input().split())
    root={}
    ng={}
    for i in range(n):
        root[i]=[]
        ng[i]=[]
    for i in range(m):
        a,b=map(int,input().split())
        root[a-1].append(b-1)
        root[b-1].append(a-1)
        ng[a-1].append(b-1)
        ng[b-1].append(a-1)
    for i in range(k):
        a,b=map(int,input().split())
        ng[a-1].append(b-1)
        ng[b-1].append(a-1)
    
    Vstd=[]
    checkVst=[False]*n
    num=[0]*n
    ToVst=queue.Queue()
   
    for i in range(n):
        if checkVst[i]:
            continue
        Vstd=[]
        now=i
        Vstd.append(now)
        checkVst[now]=True

        for kouho in root[now]:
            if checkVst[kouho]:
                continue
            ToVst.put(kouho)
            checkVst[kouho]=True

        while ToVst.empty()==False:
            now=ToVst.get()
            Vstd.append(now)
            checkVst[now]=True
           
            for kouho in root[now]:
                if checkVst[kouho]:
                    continue
                ToVst.put(kouho)
                checkVst[kouho]=True
                
        lengh=len(Vstd)
        for v in Vstd:
            num[v]=lengh-1
            num[v]-=len(set(ng[v])&set(Vstd))
    print(*num)
    #print(" ".join(map(str,num)))
   

if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
import queue
def main():
    n,m,k=map(int,input().split())
    root={}
    ng={}
    for i in range(n):
        root[i]=[]
        ng[i]=[]
    for i in range(m):
        a,b=map(int,input().split())
        root[a-1].append(b-1)
        root[b-1].append(a-1)
        ng[a-1].append(b-1)
        ng[b-1].append(a-1)
    for i in range(k):
        a,b=map(int,input().split())
        ng[a-1].append(b-1)
        ng[b-1].append(a-1)
    
    Vstd=[]
    checkVst=[0]*n
    num=[0]*n
    ToVst=queue.Queue()
   
    for i in range(n):
        
        Vstd=[]
        if checkVst[i]!=0:
            continue
        now=i
        Vstd.append(now)
        checkVst[now]=1
        

        for kouho in root[now]:
            if checkVst[kouho]!=1:
                ToVst.put(kouho)
                checkVst[kouho]=1
              
        while ToVst.empty()==False:
            now=ToVst.get()
            Vstd.append(now)
            checkVst[now]=1
           
            for kouho in root[now]:
                if checkVst[kouho]!=0:
                    continue
                ToVst.put(kouho)
                checkVst[kouho]=1
                
        lengh=len(Vstd)
        for v in Vstd:
            num[v]=lengh-1
            num[v]-=len(set(ng[v])&set(Vstd))
            


    
    print(*num)
    #print(" ".join(map(str,num)))
   

if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().split()
def LST2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

class Node:
    def __init__(self, data):
        self.data = data
        self.left = None
        self.right = None
        self.height = 0 #ノードの高さ


class AVL:
    def __init__(self):
        self.root = None


    def get_height(self, node):
        if not node:
            return -1
        return node.height

    def overwrite_height(self, node):
        return max(self.get_height(node.left),self.get_height(node.right))+1

    def get_balance(self, node):
        '''
        返り値が1以上の時、左がより高いので右回転
        -1以下の時左回転
        '''
        if not node:
            return 0
        return self.get_height(node.left) - self.get_height(node.right)

    def rotate_right(self, node): #nodeが回転の頂点、node.leftが頂点にくる。頂点を返す
        temp_left = node.left
        temp_left_right = temp_left.right
        temp_left.right = node
        node.left = temp_left_right

        node.height = self.overwrite_height(node)
        temp_left.height = self.overwrite_height(temp_left)

        return temp_left

    def rotate_left(self, node): #nodeが回転の頂点、node.leftが頂点にくる
        temp_right = node.right
        temp_right_left = temp_right.left
        temp_right.left = node
        node.right = temp_right_left

        node.height = self.overwrite_height(node)
        temp_right.height = self.overwrite_height(temp_right)

        return temp_right

    def insert(self, data):
        #print('--------------')
        #print('start inserting {}'.format(data))
        self.root = self._insert(data, self.root)
        #print('finish inserting')
        #print('--------------')

    def _insert(self, data, node): #dataをnodeに挿入、回転した上でrootを返す
        if not node:
            return Node(data)

        if data < node.data:
            node.left = self._insert(data,node.left)
        else:
            node.right = self._insert(data, node.right)
        node.height = self.overwrite_height(node)

        return self.settle_unbalance(data, node)

    def settle_unbalance(self, data, node): #回転を行なった上でrootを返す
        balance = self.get_balance(node)
        if balance > 1 and data < node.left.data:
            #print('right')
            return self.rotate_right(node)
        if balance < -1 and data > node.right.data:
            #print('left')
            return self.rotate_left(node)
        if balance > 1 and data > node.left.data:
            #print('left,right')
            node.left = self.rotate_left(node.left)
            return self.rotate_right(node)
        if balance < -1 and data < node.right.data:
            #print('right,left')
            node.right = self.rotate_right(node.right)
            return self.rotate_left(node)
        return node

    def remove(self, data):
        if self.root:
                self.root = self._remove(data, self.root)

    def _remove(self, data, node):
        if not node:
            return None
        if data < node.data:
            node.left = self._remove(data, node.left)
        elif data > node.data:
            node.right = self._remove(data, node.right)
        else:
            if not node.right and not node.left:
                del node
                return None
            if not node.right:
                temp = node.left
                del node
                return temp
            if not node.left:
                temp = node.right
                del node
                return temp

            def _get_max_node(node): #左側のsubtreeの最大ノードを代わりのノードとする
                if node.right:
                    return _get_max_node(node.right)
                return node
            temp = _get_max_node(node.left)
            node.data = temp.data
            node.left = self._remove(temp.data, node.left) #この場合もとのノード削除は不要。削除ノードを、新規ノードにおきかえればよい

        if not node:
            return node

        node.height = self.overwrite_height(node)
        balance = self.get_balance(node)
        if balance > 1 and self.get_balance(node.left) >= 0:
            return self.rotate_right(node)
        if balance < -1 and self.get_balance(node.right) <= 0:
            return self.rotate_left(node)
        if balance > 1 and self.get_balance(node.left) < 0:
            node.left = self.rotate_left(node.left)
            return self.rotate_right(node)
        if balance < -1 and self.get_balance(node.right) > 0:
            node.right = self.rotate_right(node.right)
            return self.rotate_left(node)

        return node


    def search(self, search): #インターフェース
        searcher = self._search(search)
        if searcher is None:
            pass
            #print('Search target is not found.')
        elif searcher == True:
            pass
            #print(str(search)+' is found.')
        elif searcher == False:
            pass
            #print(str(search)+' is not found.')

    def _search(self,search):
            n = self.root
            if n is None:
                return None
            else:
                lst = []
                lst.append(n)
                while len(lst) > 0:
                    node = lst.pop()
                    if node.data == search:
                        return True
                    if node.right is not None:
                        lst.append(node.right)
                    if node.left is not None:
                        lst.append(node.left)
                return False

    def search_higher(self, search):
        if self.root:
            return self._search_higher(search, self.root, None)
        #else:
        #    print('木構造がありません')

    def _search_higher(self, search, node, temp_high):
        '''
        nodeを頂点とする部分木から、searchより大きい中でもっとも小さいnodeのデータを返す
        '''
        if node is None:
            return temp_high
        if node.data > search:
            temp_high = node.data
            if node.left is None:
                return temp_high
            else:
                return self._search_higher(search, node.left, temp_high)
        elif node.data < search:
            if node.right is None:
                return temp_high
            else:
                return self._search_higher(search, node.right, temp_high)
        else:  #nodeの値が探索値と一致する時
            if node.right is None:
                return temp_high
            else:
                if temp_high is None:
                    return self.end_lower(node.right)
                else:
                    return min(temp_high, self.end_lower(node.right))

    def end_lower(self, node):
        #あるnodeの下の部分木のうち最小値 nodeにdataあることが前提
        if node.left is None:
            return node.data
        else:
            return self.end_lower(node.left)

    def traverse_inorder(self):
        if self.root:
            self._traverse_inorder(self.root)
            # 改行対策
            print()
        else:
            print('木は空です。')

    def _traverse_inorder(self, node):
        if node.left:
            self._traverse_inorder(node.left)
        sepp = '|'*node.height
        print_str = sepp+str(node.data)+sepp
        print(print_str, end = '')
        if node.right:
            self._traverse_inorder(node.right)

N = I()
S = ST()
Q = I()
D = {}
for i in range(N):
    letter = S[i]
    D[letter] = D.get(letter,AVL())
    D[letter].insert(i)

for _ in range(Q):
    q = LST()
    if q[0]=='1':
        i = int(q[1])
        c = q[2]
        for letter in D:
            D[letter].remove(i-1)
        D[c] = D.get(c,AVL())
        D[c].insert(i-1)
    else:
        ans = 0
        l = int(q[1])
        r = int(q[2])
        for letter in D:
            next_idx = D[letter].search_higher(l-2)
            if next_idx is not None:
                if r-1 >= next_idx:
                    ans += 1

        print(ans)