peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
from collections import deque

N = int(input())
units = set()
i = 0
while 6 ** i <= N:
    units.add(6 ** i)
    i += 1
i = 0
while 9 ** i <= N:
    units.add(9 ** i)
    i += 1
units = sorted(units)

mins = list(range(N + 1))
for i in range(1, len(units)):
    unit = units[i]
    for j in range(N):
        if j + unit < len(mins) and mins[j] + 1 < mins[j + unit]:
            mins[j + unit] = mins[j] + 1
print(mins[N])
# Judge status: Accepted
import numpy as np

N, M, X = map(int,input().split())
CA = []
for _ in range(N):
    CA.append(list(map(int,input().split())))

MIN = 10 ** 7
for i in range(2**N):
    cost = 0
    result = np.array([0] * M)
    for j in range(N):
        if ((i>>j)&1):
            cost += CA[j][0]
            result += CA[j][1:]

    if all(result >=X):
        MIN = min(cost,MIN)
if MIN == 10**7:
    print(-1)
else:
    print(MIN)
# Judge status: Accepted
N = int(input())
l = [input() for i in range(N)]

l_set = set(l)

print(len(l_set))
# Judge status: Accepted
# coding: utf-8

n, a, b = map(int, input().split())

c = a + b
m = n % c
mn = n // c

if m > a:
    result = mn * a + a
else:
    result = mn * a + m
print(result)
# Judge status: Wrong Answer
N = int(input())
TXY = [list(map(int, input().split())) for _ in range(N)]
 
pre_t, pre_x, pre_y = 0, 0, 0
for t, x, y in TXY:
  diff_t = t - pre_t
  diff_pos = abs(x-pre_x) + abs(y-pre_y)
  if diff_t < diff_pos or diff_t - diff_pos % 2 == 1:
    print('No')
    exit()
  else:
    pre_t, pre_x, pre_y = t, x, y
print('Yes')
# Judge status: Accepted
N = int(input())
result = 0
for i in range(7):
  if N >= 2**i:
    result = 2**i
  else:
    None
print(result)
# Judge status: Accepted
h,n = map(int,input().split())

a = [int(i) for i in input().split()]

b = sum(a)

if h <= b:
    print('Yes')
else:
    print('No')
# Judge status: Accepted

import numpy as np
n, m, x = map(int, input().split())
refer = [list(map(int, input().split())) for _ in range(n)]

ans =[]
for i in range(2**n):
    skill = []
    money = 0

    for j in range(n):
        if (i >> j) & 1:
            skill.append(refer[j][1:])
            money += refer[j][0]
            a = np.array(skill)
            if np.all(np.sum(a, axis=0) >= x):
                ans.append(money)
if ans == []:
    print(-1)
else:
    print(min(ans))
# Judge status: Wrong Answer
N = int(input())
a = sorted(list(map(int,input().split())))

print(sum([a[2*i-1] for i in range(N)]))
# Judge status: Accepted
al = input()
print(chr(ord(al)+1))
# Judge status: Accepted
a, b, k = map(int, input().split())

ans = set()
r = range(a, b + 1)
for i in range(min(k, len(r))):
    ans.add(r[i])
    ans.add(r[-i-1])
else:
    [print(i) for i in sorted(ans)]
# Judge status: Accepted
import math
r = int(input())
print(2*r*math.pi)
# Judge status: Accepted
s = list(input())
print(s.count("1"))
# Judge status: Accepted
n = int(input())
P = list(map(int,input().split()))
count = 0
for i in range(n-2):
  if P[i] < P[i+1] < P[i+2] or P[i+2] < P[i+1] <P[i]:
    count += 1
print(count)
# Judge status: Accepted
l, r, d = map(int, input().split())
ans = 0
for i in range(l, r+1):
    if i%d==0:
        ans+=1
print(ans)
# Judge status: Wrong Answer
a,b,c = map(int,input().split())
if a<c<b:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
N = int(input())
S=[]

for n in range(N):
    s=input()
    S.append(s)
S_set=set(S)

ans='Yes'
if len(S_set) != N:
    ans='No'

for n in range(N-1):
    n_ = n+1
    s_0=S[n][-1]
    s_1=S[n_][0]
    
    if s_0 != s_1:
        ans='No'
print(ans)
# Judge status: Accepted
print(('No', 'Yes')[input() in input() * 2])
# Judge status: Accepted
N, x = map(int, input().split())

A = list(map(int, input().split()))

ans = 0

for i in range(1, N):
  dif = A[i-1] + A[i] - x
  if dif > 0:
    A[i] = max(0, A[i] - dif)
    ans += dif
    
print(ans)
# Judge status: Wrong Answer
n = int(input())
moji = []

count = 0

for i in range(n):
    s = sorted(input())

    moji.append("".join(s))

print(moji)
result = []
for i in range(n):
    if moji[i] in result:
        count += 1
    else:
        result.append(moji[i])

print(count)
# Judge status: Accepted
import math

x = int(input())
money = 100
year = 0
while money < x:
    year += 1
    money = math.floor(money * 1.01)
print(year)
# Judge status: Wrong Answer
if __name__ == '__main__':
  X = input()
  X = int(X)
  
  factor = 1.01
  init = 100
  
  y = 0
  while(init <= X):
    init *= factor
    init = int(init)
    y += 1
    
  print(y)
# Judge status: Wrong Answer
a=list(input())
a.remove(" ")
n=int(a[0])
k=int(a[1])
if((k>n) and (k<=1)):
    exit()
if((n>50) and (n<=1)):
    exit()
if(len(a)>n):
    exit()
#n=int(input())
#k=int(input())
s=list(input())
str=""

s[k-1]=s[k-1].lower()
print(str.join(s))
#print(str)
#print(s)
# Judge status: Accepted

N = int(input())

C = [[0]*(10) for _ in range(10)]
for i in range(N+1):
    S = str(i)
    s = int(S[0])
    e = int(S[-1])
    C[s][e] += 1
ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans += C[i][j]*C[j][i]
print(ans)
# Judge status: Accepted
A,B,K = list(map(int,input().split()))
if A>= K:
    print(str(A-K) + ' ' + str(B))
elif A < K :
    print(str(0) + ' ' + str(max(B+A-K,0)))
# Judge status: Wrong Answer
from collections import Counter
n = int(input())
s = list(str(input()) for _ in range(n))
C_s = Counter(s)
s_l = ['AC', 'WA', 'TLE', 'RE']
for item in s_l:
    print(item, ' X ', C_s[item])
# Judge status: Wrong Answer
import math
A, B, C, D = map(int, input().split())
cnt = 0
LCD = C*D/math.gcd(C,D)

ans = B-(B//C + B//D - B//LCD) - ((A-1)-((A-1)//C + (A-1)//D - (A-1)//LCD))

print(int(ans))
# Judge status: Accepted
S, W = map(int, input().split())

if(S > W):
    print('safe')
else:
    print('unsafe')
# Judge status: Accepted
a, b = map(int, input().split())

if a * b % 2 == 1:
    print('Odd')
else:
    print('Even')
# Judge status: Wrong Answer
import math

n, m = map(int, input().split(" "))
aL = sorted(list(map(int, input().split(" "))))
bcL = sorted([list(map(int,
                       input().split(" "))) for _ in range(m)],
             key=lambda x: x[1],
             reverse=True)

csl = 0
for cnt, point in bcL:
    for i in range(cnt):
        if csl == n - 1 or aL[csl] >= point:
            print(sum(aL))
            exit()
        aL[csl] = point
        csl += 1

print(sum(aL))
exit()
# Judge status: Accepted
l=['1','2','3']
l.remove(input())
l.remove(input())
print(l[0])
# Judge status: Accepted
d=int(input())
if d==25:
    print("Christmas")
elif d==24:
    print("Christmas","Eve")
elif d==23:
    print("Christmas","Eve","Eve")
else:
    print("Christmas","Eve","Eve","Eve")
# Judge status: Wrong Answer
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0
for a in range(A):
  for b in range(B):
    for c in range(C):
      if a*500+b*100+c*50 == X:
        cnt += 1
print(cnt)
# Judge status: Accepted
n = int(input())
aaa = list(map(int, input().split()))
ans = 0
while all(i % 2 == 0 for i in aaa):
    ans += 1
    aaa = list(j / 2 for j in aaa)
print(ans)
# Judge status: Accepted
x, y = map(int, input().split())
print(min(max(y-x, x-y+2), abs(x+y)+1))
# Judge status: Accepted
N=int(input())
for i in range(1,500001):
    if int(i*1.08)==N:
        print(i)
        break
else:
      print(':(')
# Judge status: Accepted
n,L = map(int,input().split())
taste = [0]*n
for i in range(n):
    taste[i] = L+i
taste[taste.index(min(taste, key=lambda x: abs(x)))] = 0
print(sum(taste))
# Judge status: Accepted
import re

x = input()
pattern = "R+"
pat = re.search(pattern, x)
if pat:
  print(len(pat.group()))
else:
  print(0)
# Judge status: Accepted
N,R=map(int,input().split())
if N<10 :
  print(100*(10-N)+R)
else :
  print(R)
# Judge status: Accepted
A,B,C = map(int, input().split())

ans = 0
for ans in range(1000):
    if A&1 or B&1 or C&1:
        print(ans)
        break
    A,B,C = (B+C)//2, (C+A)//2, (A+B)//2
else:
    print(-1)
# Judge status: Accepted
def solve():
    X, Y, Z = map(int, input().split())
    print((X - Z) // (Y + Z))


if __name__ == "__main__":
    solve()
# Judge status: Accepted
N = int(input())
c =0
for i in range(1,N+1):
  if len(str(i)) % 2 == 1:
    c+=1
print(c)
# Judge status: Wrong Answer
n, m, k = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))

c = []
         
while((len(a) != 0 or len(b) != 0)):
  if(len(a) == 0):
    c.append(b[0]);b.pop(0);continue
  if(len(b) == 0):
    c.append(a[0]);a.pop(0);continue
  
  if(a[0] > b[0]):
    c.append(b[0]);b.pop(0);continue
  else:
    c.append(a[0]);a.pop(0);continue

tmp = 0
ans = 0
for i in c:
  tmp += i
  if(tmp <= k):ans+=1
  else:print(ans);exit()
print(ans)
# Judge status: Wrong Answer
r = 0
n = int(input())
a = sorted(list(map(int, input().split())))
for i in range(n - 1):
  if a[i] ==  a[i + 1]:
    r = 1
if r == 1:
  print("No")
else:
  print("Yes")
# Judge status: Accepted
from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in range(n):
    word = str(input())
    d[word]+=1
print("{} {} {}".format("AC","x",d["AC"]))
print("{} {} {}".format("WA","x",d["WA"]))
print("{} {} {}".format("TLE","x",d["TLE"]))
print("{} {} {}".format("RE","x",d["RE"]))
# Judge status: Accepted
N,A,B,C,D=list(map(int,input().split()))
l=list(input())
if "##" in "".join(l[A-1:max(C,D)-1]):
   print("No")
   exit()
if C>D:
   pass
else:
   print("Yes")
   exit()
if "..." in "".join(l[B-2:D+1]):
   print("Yes")
else:
   print("No")
# Judge status: Accepted
a, b = map(int, input().split())
if a <= b:
  print(a)
else:
  print(a - 1)
# Judge status: Accepted
import math
A, B, H, M = map(int, input().split())
pi = math.pi

angle = (M * pi)/360 + (H * pi)/6 - (M * pi)/30

X = A**2 + B**2 - 2 * A * B * math.cos(angle)

ans = math.sqrt(X)
print(ans)
# Judge status: Wrong Answer
x=list(map(input().count,"abc"));print("NYOE S"[all([-2<x[i]-x[~-i%3]<2 for i in[0]*3])::2])
# Judge status: Accepted
from collections import deque
s=input()

A=deque([])
for i in s:
    if len(A)<1:
        A.append(i)
    else:
        if A[-1]+i=="ST":A.pop()
        else:A.append(i)

print(len(A))
# Judge status: Accepted
from sys import stdin
import sys

# A, B, C, D = [int(x) for x in stdin.readline().rstrip().split()]
N, K = [int(x) for x in stdin.readline().rstrip().split()]
ans = [0 for i in range(N)]
for i in range(K):
    d = int(input())
    A = list(map(int, input().split()))
    for i in range(len(A)):
        ans[A[i]-1] += 1
cnt=0
for i in range(len(ans)):
    if ans[i] == 0:
        cnt += 1
print(cnt)
# Judge status: Wrong Answer
n=int(input())
c1,c2,c3,c4=0,0,0,0
for i in range(n):
  s=input()
  if(s=='AC'):
    c1+=1
  elif(s=='WA'):
    c2+=1
  elif(s=='TLE'):
    c3+=1
  else:
    c4+=1
print('AC X'+str(c1))
print('WA X'+str(c2))
print('TLE X'+str(c3))
print('RE X'+str(c4))
# Judge status: Wrong Answer
d=input()
if d==25:
  print("Christmas")
elif d==24:
  print("Christmas Eve")
elif d==23:
  print("Christmas Eve Eve")
else:
  print("Christmas Eve Eve Eve")
# Judge status: Wrong Answer
n = int(input())
a = [int(i) for i in input().split()]
even4= 0
odd = 0
even2 = 0
for i in range(n):
    if a[i]%4 == 0:
        even4 +=1
    elif a[i]%2 == 0:
        even2 +=1
    else:
        odd+=1
if (even4)*2 >=odd :
    print('Yes')
elif even2%2==0:
    print("Yes")
else:
    print('No')
# Judge status: Accepted
import collections

n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0

list_a = list(collections.Counter(a).values())
dic = dict(zip(collections.Counter(a), list_a))
dic_sorted = sorted(dic.items(), key=lambda x: x[1])
del_num = dic_sorted[:len(dic_sorted)-k]

for i in del_num:
    ans += i[1]

print(ans)
# Judge status: Accepted
from math import gcd

def threegcd(a, b, c):
    return gcd(gcd(a,b), c)

k = int(input())

ans = 0

for i in range(1, k+1):
    for j in range(1, k+1):
        for k in range(1, k+1):
            ans += threegcd(i, j, k)

print(ans)
# Judge status: Accepted
from collections import defaultdict, Counter

N = int(input())
D = list(map(int, input().split()))
c = Counter(D)
M = max(c.keys())

if D[0] != 0 or c[0] != 1:
    print(0)
    exit()

mod = 998244353
depth = 1
ans = 1
while depth <= M:
    ans *= pow(c[depth - 1], c[depth], mod)
    ans %= mod
    depth += 1
print(ans)
# Judge status: Accepted
N,M = map(int,input().split())

bottom = 0
top = N+1

for i in range(M):
  L,R = map(int,input().split())
  bottom = max(bottom, L)
  top = min(top,R)
  
ans = top - bottom + 1
print(ans if ans>=0 else 0)
# Judge status: Accepted
# AtCoder
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

c = Counter(A)
sc = sorted(c.items(), key=lambda x: x[0], reverse=True)
sides = []
for side, nums in sc:
    if nums >= 4:
        sides.append(side)
        sides.append(side)
    elif nums >= 2:
        sides.append(side)
if 1 >= len(sides):
    print(0)
    exit()

s = sorted(sides, reverse=True)
ans = s[0]*s[1]
print(ans)
# Judge status: Accepted
s = input()
if s[-1] == 's':
    print(s + 'es')
else:
    print(s+'s')
# Judge status: Accepted
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N, M = getNM()
optmax = M // N
for i in range(optmax, 0, -1):
    if M % i == 0:
        print(i)
        break
# Judge status: Wrong Answer
from bisect import bisect_left

N,M=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A)

change=[tuple(map(int,input().split())) for _ in range(M)]
change=sorted(change,key=lambda x: x[1])
change2=[]
count=0
for i in range(M):
  b,c=change[i]
  change2.extend([c]*b)
  count += b
  if count >= N:break

A.extend(change2)
A = sorted(A)
print(sum(A[len(A)-N:]))
# Judge status: Accepted
N,M=map(int,input().split())
l=[0]*N
ans=0
for i in range(M):
    s,c=map(int,input().split())
    if l[s-1]==0 or l[s-1]==c:
        l[s-1]=c
    else:
        print(-1)
        exit()
    if s==1 and c==0 and N!=1:
        print(-1)
        exit()
for i in range(N):
    ans+=int(l[i])*(10**(N-i-1))
if N==len(str(ans)):
    print(ans)
else:
    print(10**(N-1)+ans)
# Judge status: Accepted
A,B,C,D = map(int,input())
tfs = []
rt = str(A)
for bt in (True, False):
  for ct in (True, False):
    for dt in (True, False):
      tfs.append([bt,ct,dt])
for bt,ct,dt in tfs:
  tmp=7-A
  tmp = tmp-B if bt else tmp+B
  tmp = tmp-C if ct else tmp+C
  tmp = tmp-D if dt else tmp+D
  if tmp == 0:
    rt+="+" if bt else "-"
    rt+=str(B)
    rt+="+" if ct else "-"
    rt+=str(C)
    rt+="+" if dt else "-"
    rt+=str(D)
    rt+="=7"
    break

print(rt)
# Judge status: Wrong Answer
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

a = sorted([a for a, b in AB])
b = sorted([b for a, b in AB])

if N % 2 == 1:
    print(b[N // 2] - a[N // 2] + 1)
elif N % 2 == 0:
    print((b[(N + 1) // 2] + b[N // 2]) - (a[(N + 1) // 2] + a[N // 2]) + 1)
# Judge status: Accepted
def main():
    import sys
    #int(sys.stdin.readline())
    #s = sys.stdin.readline().rstrip()
    N, K = map(int, sys.stdin.readline().split())
    P = list(map(int, sys.stdin.readline().split()))
    P.sort()
    print(sum(P[0:K]))




if __name__=='__main__':
    main()
# Judge status: Accepted
N, X, T = map(int, input().split())

if N % X == 0:
    print(int(N / X) * T)
else:
    print(((N // X) + 1) * T)
# Judge status: Accepted
NUM=1000

X=int(input())

flg=False

for i in reversed(range(NUM)):
    for j in range(-1*NUM,NUM):
        res=(i**5)-(j**5)
        if res==X:
            ans_A=i
            ans_B=j
            flg=True
            break
    if flg:
        break

print(ans_A,ans_B)
# Judge status: Accepted
S = input()
if S in ['hi', 'hihi', 'hihihi', 'hihihihi', 'hihihihihi']:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
N=int(input())
A=list(map(int,input().split()))
ANS=[]
for i in range(N):
    ANS+=[[A[i],i+1]]
ANS.sort()
for i in range(N):
    print(ANS[i][1])
# Judge status: Accepted
S = input()

max_len = 0
counter = 0
for i in S:
    if i in 'ACGT':
        counter += 1
        if max_len < counter:
            max_len = counter

    else:
        counter = 0
    

print(max_len)
# Judge status: Accepted
a,b=map(int,input().split());l=max(a*25+1>>1,b*10);print(l*(~a*25/2<-l>~b*10)or-1)
# Judge status: Accepted
import math
A, B, N = list(map(int, input().split()))
ans = 0
if B+1 < N:
    C = B+1
else:
    C = N
if B//A == 0:
    D = 1
elif B//A > 1:
  	D = B//A-1
else:
    D = B//A
for i in range(1, C+1, D):
    val = math.floor(A*i/B) - A*math.floor(i/B)
    #print("i", i, "val", val)
    ans = max(ans, val)

print(ans)
# Judge status: Wrong Answer
num_bulb, count = map(lambda x: int(x), input().split())
brightness = list(map(lambda x: int(x), input().split()))

for i in range(count):
    next_brightness = []
    # それぞれの電球について
    for j in range(num_bulb):
        next_brightness.append(0)
        # それをテラス電球を調べる
        for k in range(num_bulb):
          if abs(j - k) < brightness[k] + 0.5:
            next_brightness[j] += 1

print(' '.join(list(map(lambda x: str(x), next_brightness))))
# Judge status: Wrong Answer
S=str(input())
no = False
for i in range(len(S)):
  for k in range(i+1,len(S)):
    if S[i] == S[k]:
      no == True
      break
if no:
  print('no')
else:
  print('yes')
# Judge status: Accepted
A,B = map(int, input().split())

## 全探索
for i in range(1,1010,1):
  ans_8 = int(i * 0.08)
  if A == ans_8:
    ans_10 = int(i * 0.10)    
    if B == ans_10:
      print(i)
      exit()
else:
  print('-1')
# Judge status: Accepted
from fractions import gcd

def lcm(c,d):
    return c//gcd(c,d)*d
mod=10**9+7
n=int(input())
a=[int(i) for i in input().split()]
l=a[0]
for i in range(1,n):
    l=lcm(l,a[i])
ans=0
for i in range(n):
    ans+=l//a[i]
    #ans%=mod
print(ans%mod)
# Judge status: Accepted
a, b, c = map(int, input().split())
if b - a  == c - b:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
N = int(input())
ans = float('inf')
for i in range(N+1):
    j = i
    count = 0
    t=N-i
    while j > 0:
        count += j%6
        j=j//6
    while t > 0:
        count += t%9
        t=t//9
    ans = min(ans,count)
print(ans)
# Judge status: Accepted
n,a,b=map(int,input().split())
mod=10**9+7
def nCk(n,k):
    x=1
    y=1
    for i in range(k):
        x=(x*(n-i))%mod
        y=(y*(k-i))%mod
    y_inv=pow(y,mod-2,mod)
    return (x*y_inv)%mod

ans=(pow(2,n,mod)-1-nCk(n,a)-nCk(n,b))%mod
print(ans)
# Judge status: Accepted
x,y,z=map(int,input().split())
print(z,x,y)
# Judge status: Wrong Answer
x,a,b=map(int, input().split())

if b<a:
  print("delicious")
elif a+x>b:
  print("safe")
else:
  print("dangerous")
# Judge status: Accepted
S = input()
print('A' if S.upper() == S else 'a')
# Judge status: Accepted
import math

def main():
  A, B, H, M = map(int, input().split())
  Ax = A * math.sin((H + M / 60) * 30 / 180 * math.pi)
  Ay = A * math.cos((H + M / 60) * 30 / 180 * math.pi)
  Bx = B * math.sin(M * 6 / 180 * math.pi)
  By = B * math.cos(M * 6 / 180 * math.pi)
  dist = math.sqrt((Ax - Bx) ** 2 + (Ay - By) ** 2)
  print(dist)

if __name__ == '__main__':
  main()
# Judge status: Wrong Answer
s=input()
t="keyence"

ans=False
for i in range(len(t)):
    a=t[:i]
    b=t[i:]
    if s.find(a)==0 and s.find(b)!=-1:
        if s[s.find(b)+len(b):]=="" or (i==0 and s[0]=="k"):
            ans = True
            break

if ans is True:
    print("YES")
else:
    print("NO")
# Judge status: Wrong Answer
c1 = input()
c2 = input()
if c1[::-1]==c2:
    print('YES')
else:
    print('No')
# Judge status: Wrong Answer
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(1, n):
    if a[i] + a[i-1] <= x:
        continue
    else:
        ans += (a[i] + a[i-1] - x)
        a[i] = x - a[i-1]
        # print(ans)
print(ans)
# Judge status: Accepted
# import fractions
# import sys
from sys import stdin

n = int(stdin.readline().rstrip())

ab = [list(map(int, stdin.readline().rstrip().split())) for i in range(n)]
ab.reverse()
ans = 0
for abi in ab:
    abi[0] += ans
    if abi[0] % abi[1] == 0:
        pass
    else:
        ans += abi[1] - (abi[0] % abi[1])
print(ans)
# Judge status: Accepted
from collections import Counter
N = int(input())
C = Counter(input())

mod = 10 ** 9 + 7
ans = 1
for v in C.values():
    ans *= (v + 1)  # 使う:v通り、使わない1通り
    ans %= mod

ans -= 1
print(ans % mod)
# Judge status: Wrong Answer
def chars_mix_up(a, b):
  new_a = b[:2] + a[2:]
  new_b = a[:2] + b[2:]

  return new_a + ' ' + new_b
print(chars_mix_up('abc', 'xyz'))
# Judge status: Accepted
N = int(input())
a= list(map(int,input().split()))
b= list(map(int,input().split()))
c = [a[i]-b[i] for i in range(N)]
d=sum(b)-sum(a)   #c回試行する
if d<0:
  print("No")
  exit()
  
must=0
cnt=0
for num in c:
  if num>0:
    must += abs(num)
  if num*(-1) >= 2:
    cnt += (-1)*num//2
if must>d:
  print("No")
  exit()

#nokori = d-must
#print(must,nokori,cnt)

if cnt<must:
  print("No")
else:
  print("Yes")
# Judge status: Accepted
N = int(input())
for i in range(N+1):
  if int(i*1.08)==N:
    print(i)
    break
else:
  print(":(")
# Judge status: Accepted
a,b=map(int,input().split())
if a*b%2==0:
  print("Even")
else:
  print("Odd")
# Judge status: Accepted
N = int(input())
H = list(map(int, input().split()))
ans = 0
L = 0
count = 0
for i in range(N):
    if L >= H[i]:
        count += 1
    else:
        ans = max(ans, count)
        count = 0
    L = H[i]
ans = max(ans, count)
print(ans)
# Judge status: Accepted
s=input()
ans=''
for i in range(len(s)):
    if s[i]!='B':
        ans+=s[i]
    else:
        if len(ans)!=0:
            ans=ans[:-1]
print(ans)
# Judge status: Accepted
s=input()
ss=""
for m in s:
  if m=="B":
    if ss!="":
      ss=ss[:-1]
  else:
    ss+=m
print(ss)
# Judge status: Accepted
from collections import deque

N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
q = deque()
done = [-1]*N
def bfs(fr, now):
    done[now] = fr
    for to in G[now]:
        if done[to] != -1: continue
        q.appendleft((now, to))
q.appendleft((0, 0))
while q:
    fr, now = q.pop()
    if done[now] == -1:
        bfs(fr, now)
print("Yes")
for fr in done[1:]:
    print(fr+1)
# Judge status: Accepted
import sys
input = sys.stdin.readline

import numpy as np

sw = np.array([int(x) for x in input().split()])
ans = "unsafe" if sw[1] >= sw[0] else "safe"
print(ans)
# Judge status: Accepted
n, m = map(int, input().split())
city = [0] * n
for i in range(m):
    a, b = map(int, input().split())
    city[a - 1] += 1
    city[b - 1] += 1

for i in city:
    print(i)
# Judge status: Accepted
n = int(input())
# a,b = map(int, input().split())
# l = list(map(int, input().split()))

count = [[0]*10 for i  in range(10)]

for i in range(1,n+1):
    i_str = str(i)
    mae = int(i_str[0])
    usi = int(i_str[-1])
    count[mae][usi] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += count[i][j] * count[j][i]

print(ans)
# Judge status: Accepted
import numpy as np

N = int(input())
W = input().split()

for i in range(N):
    W[i] = int(W[i])
min_w= 1000000
for i in range(N-1):
    w1 = W[:i+1]
    w2 = W[i+1:]
    w1 = np.array(w1)
    w2 = np.array(w2)
    min_w = min(min_w, abs(np.sum(w2)-np.sum(w1)))

print(min_w)
# Judge status: Accepted
n,m = map(int,input().split())
dic = {}
ls = [1]*(n+1)
ls[0] = 0
ans = 0
dic[1] = 1
for i in range(m):
    a,b = map(int,input().split())
    ls[a] -= 1
    ls[b] += 1
    if dic.get(a,0) != 0:
        if dic.get(b,0) == 0:
            dic[b] = 1
    else:
        if ls[b] == 1:
            dic[b] = 0
for j in range(n+1):
    if ls[j] > 0 and dic.get(j,0) != 0:
        ans += 1
print(ans)