A weighted string is a string of lowercase English letters where each letter has a weight.  Character weights are $\mbox{1}$ to $26$ from $\class{ML__boldsymbol}{\boldsymbol{a}}$ to $z$ as shown below:

The weight of a string is the sum of the weights of its characters.  For example: 

A uniform string consists of a single character repeated zero or more times. For example, ccc and a are uniform strings, but bcb and cd are not.

Given a string, $\boldsymbol{\mathrm{~S~}}$, let $\mbox{U}$ be the set of weights for all possible uniform contiguous  substrings of string $\boldsymbol{\mathrm{~S~}}$. There will be $n$ queries to answer where each query consists of a single integer. Create a return array where for each query, the value is Yes if $\textit{query}[i]\in U$.  Otherwise, append No.

Note: The  $\in $ symbol denotes that $x[i]$ is an element of set $\mbox{U}$.Example $s=\text{'abbcccddd’}$ $queries=[1,7,5,4,15]$.  
Working from left to right, weights that exist are:
string  weighta     
  1b       2bb     
  4c       3cc      
  6ccc     9
   d       4 
   dd     8
   ddd     12
dddd    16

Now for each value in $queries$, see if it exists in the possible string weights.  The return array is ['Yes', 'No', 'No', 'Yes', 'No'].
Function Description  Complete the weightedUniformStrings function in the editor below. weightedUniformStrings has the following parameter(s): - string s: a string - int queries[n]: an array of integers   
Returns -   string[n]: an array of strings that answer the queries

Input FormatThe first line contains a string $\boldsymbol{\mathrm{~S~}}$, the original string. The second line contains an integer $n$, the number of queries. Each of the next $n$ lines contains an integer $\textit{queries}[i]$, the weight of a uniform subtring of $\boldsymbol{\mathrm{~S~}}$ that may or may not exist.

Constraints
$1\leq\textit{lengthofs},n\leq10^5$       
$1\leq\textit{queries[i]}\leq10^7$
$\boldsymbol{\mathrm{~S~}}$ will only contain lowercase English letters, ascii[a-z].

Sample Input0 
abccddde
6
1
3
12
5
9 
10

Sample Output0
Yes
Yes
Yes
Yes
No
No
Explanation 0
The weights of every possible uniform substring in the string abccddde are shown below:

We print Yes on the first four lines because the first four queries match weights of uniform substrings of $\boldsymbol{\mathrm{~S~}}$. We print No for the last two queries because there are no uniform substrings in $\boldsymbol{\mathrm{~S~}}$ that have those weights. 

Note that while de is a substring of $\boldsymbol{\mathrm{~S~}}$ that would have a weight of $\mbox{9}$, it is not a uniform substring.

 Note that we are only dealing with contiguous substrings. So ccc is not a substring of the string ccxxc.
Sample Input1
aaabbbbcccddd
5
9
7
8
12
5
Sample Output 1
Yes
No
Yes
Yes
No

Source: hackerrank | Difficulty: EASY
Tags: String algorithms


Solutions:
s = input().strip()
cost = set()
prev = ''
count = 0
for i in s:
	if i != prev:
		prev = i
		count = 0
	count += 1
	cost.add(count * (ord(i) - ord('a') + 1))
for _ in range(int(input())):
	print('Yes' if int(input()) in cost else 'No')


s = input()
weights = set()
prev = ''
curlen = 0
for c in s:
	if c == prev:
		curlen += 1
		weights.add((ord(c) - ord('a') + 1) * curlen)
	else:
		curlen = 1
		prev = c
		weights.add(ord(c) - ord('a') + 1)
for _ in range(int(input())):
	query = int(input())
	print('Yes' if query in weights else 'No')


import sys
s = input().strip()
n = int(input().strip())
st = set()
(last, cnt) = (0, 0)
for i in s:
	if last != ord(i):
		last = ord(i)
		cnt = 0
	cnt += 1
	st.add(cnt * (last - ord('a') + 1))
for a0 in range(n):
	x = int(input().strip())
	print('Yes' if x in st else 'No')


import sys
s = input().strip()
n = int(input().strip())
i = 1

def o(x):
	return ord(x) - ord('a') + 1
d = set([o(s[0])])
k = 2
while i < len(s):
	if s[i] == s[i - 1]:
		d.add(k * o(s[i]))
		k += 1
	else:
		k = 2
		d.add(o(s[i]))
	i += 1
for a0 in range(n):
	x = int(input().strip())
	if x in d:
		print('Yes')
	else:
		print('No')


import sys

def tryit(x, W):
	for bok in range(26):
		wbok = 1 + bok
		if x % wbok == 0 and x // wbok <= W[bok]:
			print('Yes')
			return
	print('No')
	return
s = [ord(c) - ord('a') for c in input().strip()]
n = int(input().strip())
W = [0] * 26
prev = s[0]
count = 1
i = 1
while i < len(s):
	if prev == s[i]:
		count += 1
	else:
		W[prev] = max(count, W[prev])
		count = 1
		prev = s[i]
	i += 1
W[prev] = max(count, W[prev])
for a0 in range(n):
	x = int(input().strip())
	tryit(x, W)


s = str(input())
vals = set()
i = 1
span = 1
last = s[0]
while i < len(s):
	curr = s[i]
	if curr == last:
		span += 1
	else:
		for x in range(1, span + 1):
			vals.add(x * (ord(last) - 96))
		span = 1
	last = curr
	i += 1
for x in range(1, span + 1):
	vals.add(x * (ord(last) - 96))
for _ in range(int(input())):
	if int(input()) in vals:
		print('Yes')
	else:
		print('No')


import sys
from collections import Counter

def myOrd(char):
	return ord(char) - 96
s = input().strip()
current = s[0]
current_chain = 1
possibilities = set({})
possibilities.add(current_chain * myOrd(current))
for (i, char) in enumerate(s):
	if i == 0:
		continue
	else:
		if char == current:
			current_chain += 1
		else:
			current = char
			current_chain = 1
		possibilities.add(current_chain * myOrd(current))
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	if x in possibilities:
		print('Yes')
	else:
		print('No')


import sys
s = input().strip()
ans = set()
ans.add(0)
cc = ' '
cw = 0
for c in s:
	if c != cc:
		cc = c
		cw = 0
	cw += ord(c) - ord('a') + 1
	ans.add(cw)
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	print(['No', 'Yes'][int(x in ans)])


import sys
from bisect import bisect_left

def binary_search(a, x, lo=0, hi=None):
	hi = hi if hi is not None else len(a)
	pos = bisect_left(a, x, lo, hi)
	return pos if pos != hi and a[pos] == x else -1
s = input().strip()
prev = ''
sumtn = 0
sums = []
for i in s:
	if i == prev:
		sumtn = sumtn + (ord(i) - ord('a') + 1)
	else:
		sumtn = ord(i) - ord('a') + 1
	prev = i
	sums.append(sumtn)
sums = sorted(sums)
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	if binary_search(sums, x) != -1:
		print('Yes')
	else:
		print('No')


from string import ascii_lowercase
string = input()
weight = [ascii_lowercase.index(a) + 1 for a in string]
last_weight = None
mod = []
last_sum = 0
for w in weight:
	if last_weight is None or w == last_weight:
		mod.append(last_sum)
		last_weight = w
		last_sum += w
	else:
		mod.append(last_sum)
		last_sum = w
		last_weight = w
mod.append(last_sum)
mod = set(mod)
q_c = int(input())
for _ in range(q_c):
	inpudt = int(input())
	print('Yes' if inpudt in mod else 'No')


import sys
s = input().strip()
n = int(input().strip())
U = []
lis = []
l = len(s)
temp = '1'
for x in s:
	U.append(ord(x) - 96)
	if temp[-1] == x:
		temp = temp + x
		U.append(len(temp) * (ord(x) - 96))
	else:
		temp = x
d = {}
for a0 in range(n):
	x = int(input().strip())
	d[x] = -1
	lis.append(x)
for x in U:
	d[x] = 1
for x in lis:
	if d[x] == -1:
		print('No')
	else:
		print('Yes')


import sys
import bisect
s = input().strip()
n = int(input().strip())
WeightList = [ord(s[0]) - ord('a') + 1]
priorChar = s[0]
for i1 in s[1:]:
	if i1 == priorChar:
		WeightList.append(WeightList[-1] + ord(i1) - ord('a') + 1)
	else:
		WeightList.append(ord(i1) - ord('a') + 1)
	priorChar = i1
WeightList.sort()
for a0 in range(n):
	x = int(input().strip())
	Ind = bisect.bisect_left(WeightList, x)
	if Ind < len(s) and WeightList[Ind] == x:
		print('Yes')
	else:
		print('No')


from sys import stdin
weights = [i for i in range(1, 27)]
U = {}
cur_length = 0
prev_letter = '-'
for letter in stdin.readline().strip():
	if prev_letter != letter:
		cur_length = 1
	else:
		cur_length += 1
	U[cur_length * weights[ord(letter) - ord('a')]] = 1
	prev_letter = letter
for query_id in range(int(stdin.readline())):
	if int(stdin.readline()) in U:
		print('Yes')
	else:
		print('No')


(s, n) = (input().strip(), int(input().strip()))
(char, i) = (s[0], 1)
(arr, _len) = (set(), len(s))
for j in range(1, _len + 1):
	if j < _len and s[j] == char:
		arr.add(i * (ord(char) - 96))
		i += 1
	else:
		arr.add(i * (ord(char) - 96))
		if j < _len:
			(i, char) = (1, s[j])
for a0 in range(n):
	x = int(input().strip())
	print('Yes' if x in arr else 'No')


import sys
string = input().strip()
s = set()
last = ''
for char in string:
	if char == last:
		count += 1
	else:
		last = char
		count = 1
	s.add((ord(char) - ord('a') + 1) * count)
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	print('Yes' if x in s else 'No')


import sys
from collections import Counter

def weight_of_letter(l):
	return ord(l) - 96

def get_uniform_subsets(s):
	cnt = Counter()
	curr = 0
	last = ''
	for ch in s:
		if ch == last:
			curr += 1
		else:
			last = ch
			curr = 1
		if curr > cnt[ch]:
			cnt[ch] = curr
	weights = set()
	for i in cnt:
		for j in range(cnt[i]):
			weights.add((j + 1) * weight_of_letter(i))
	return weights
s = input().strip()
weights = get_uniform_subsets(s)
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	if x in weights:
		print('Yes')
	else:
		print('No')


s = input()
_sum = {}
prev = 0
c = 0
f = 1
for i in s:
	if f:
		prev = i
		c = 1
		_sum[ord(i) - 96] = 1
		f = 0
	elif prev == i:
		c += 1
		_sum[c * (ord(i) - 96)] = 1
	else:
		c = 1
		_sum[ord(i) - 96] = 1
		prev = i
for test in range(int(input())):
	n = int(input())
	if n in _sum:
		print('Yes')
	else:
		print('No')


import sys, math
weights = []
s = input().strip()
for i in s:
	weights.append(ord(i) - 96)
bunch = []
tmp = []
for i in range(len(weights)):
	if len(tmp) == 0 or tmp[0] != weights[i]:
		if len(tmp) != 0:
			bunch.append(tmp)
		tmp = [weights[i], 1]
	else:
		tmp[1] += 1
bunch.append(tmp)
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	inside = False
	for i in range(len(bunch)):
		unisub = bunch[i]
		if x % unisub[0] == 0 and x <= unisub[0] * unisub[1]:
			inside = True
			break
	if inside or x == 0:
		print('Yes')
	else:
		print('No')


import sys
from itertools import groupby
s = input().strip()
n = int(input().strip())
alphabet = ' abcdefghijklmnopqrstuvwxyz'
u = set()
dicty = {}
for i in s:
	if i not in dicty:
		dicty[i] = 0
	dicty[i] += 1
for (key, sub) in groupby(s):
	weight = alphabet.find(key)
	for j in range(1, len(list(sub)) + 1):
		u.add(j * weight)
for a0 in range(n):
	x = int(input().strip())
	if x in u:
		print('Yes')
	else:
		print('No')


s = input() + '0'
prev = s[0]
num = 0
high = [0] * 26
for c in s:
	if c != prev:
		high[ord(prev) - ord('a')] = max(high[ord(prev) - ord('a')], num)
		prev = c
		num = 0
	if c == prev:
		num += 1
q = int(input())
for i in range(q):
	x = int(input())
	ok = 'No'
	for j in range(1, 27):
		if x % j == 0 and j * high[j - 1] >= x:
			ok = 'Yes'
	print(ok)


import sys
s = input().strip()
n = int(input().strip())
arr = []
for i in s:
	arr.append(ord(i) - ord('a') + 1)
sums = set()
prev = -1
tot = 0
for i in range(len(arr)):
	if arr[i] == prev:
		tot += arr[i]
		sums.add(tot)
	else:
		tot = 0
		tot += arr[i]
		sums.add(tot)
	prev = arr[i]
for a0 in range(n):
	x = int(input().strip())
	if x in sums:
		print('Yes')
	else:
		print('No')


import sys
s = input().strip()
n = int(input().strip())
weights = set()
lastOrd = 0
consecOrd = 0
for i in range(0, len(s)):
	curOrd = ord(s[i]) - 96
	if curOrd != lastOrd:
		weights.add(curOrd)
		lastOrd = curOrd
		consecOrd = curOrd
	else:
		consecOrd += curOrd
		weights.add(consecOrd)
for a0 in range(n):
	x = int(input().strip())
	out = 'Yes' if x in weights else 'No'
	print(out)


import sys
s = input().strip()
present = {0: True}
present[ord(s[0]) - 96] = True
previous = s[0]
count = 1
for x in s[1:]:
	if x == previous:
		count += 1
	else:
		count = 1
		previous = x
	present[(ord(x) - 96) * count] = True
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	ans = present.get(x, False)
	if ans:
		print('Yes')
	else:
		print('No')


import sys

def binarySearch(alist, item):
	first = 0
	last = len(alist) - 1
	found = 'No'
	while first <= last and found == 'No':
		midpoint = (first + last) // 2
		if alist[midpoint] == item:
			found = 'Yes'
		elif item < alist[midpoint]:
			last = midpoint - 1
		else:
			first = midpoint + 1
	return found
s = input().strip()
n = int(input().strip())
str1 = 'abcdefghijklmnopqrstuvwxyz'
dic = {}
for i in range(26):
	dic[str1[i]] = i + 1
lis1 = []
for a0 in range(n):
	x = int(input().strip())
	lis1.append(x)
dic2 = {}
for i in str1:
	dic2[i] = 0
lisx = []
for i in range(len(s)):
	if i == 0:
		dic2[s[i]] += 1
		lisx.append(dic[s[i]] * dic2[s[i]])
		continue
	if dic2[s[i]] == dic2[s[i - 1]]:
		dic2[s[i]] += 1
		lisx.append(dic[s[i]] * dic2[s[i]])
	else:
		dic2[s[i]] = 1
		lisx.append(dic[s[i]] * dic2[s[i]])
lisx.sort()
for i in lis1:
	a = binarySearch(lisx, i)
	print(a)


import sys
import re
a = ord('a')
s = input().strip()
maxweight = [0 for i in range(26)]
for m in re.finditer('(.)\\1*', s):
	n = len(m.group())
	i = ord(m.group(1)) - a
	maxweight[i] = max(maxweight[i], n)

def contains(x):
	for i in range(26):
		(q, r) = divmod(x, i + 1)
		if r == 0 and q <= maxweight[i]:
			print('Yes')
			return
	print('No')
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	contains(x)


import string
s = input().strip()
w = dict(zip(string.ascii_lowercase, range(1, 27)))
weights = set()
count = 0
prev = ''
for char in s:
	if char == prev:
		count += 1
	else:
		count = 1
	weights.add(w[char] * count)
	prev = char
for _ in range(int(input())):
	q = int(input())
	if q in weights:
		print('Yes')
	else:
		print('No')


import sys

def score(c):
	return ord(c) - ord('a') + 1
s = input().strip()
n = int(input().strip())
scores = set()
scores.add(0)
i = 0
j = 0
while True:
	j += 1
	if j == len(s) or s[j] != s[i]:
		c = s[i]
		length = j - i
		scorec = score(c)
		for k in range(1, length + 1):
			scores.add(scorec * k)
		i = j
	if j == len(s):
		break
for a0 in range(n):
	x = int(input().strip())
	if x in scores:
		print('Yes')
	else:
		print('No')


import sys
from itertools import groupby
s = input().strip()
n = int(input().strip())
alpha = 'abcdefghijklmnopqrstuvwxyz'
d = {}
for (num, let) in enumerate(list(alpha)):
	d[let] = num + 1
unistrings = [list(g) for (k, g) in groupby(s)]
get_nums = []
for i in unistrings:
	get_nums.append(d[i[0]])
for a0 in range(n):
	x = int(input().strip())
	for (num, i) in enumerate(get_nums):
		c = 0
		if x % i == 0 and x <= i * len(unistrings[num]):
			print('Yes')
			c += 1
			break
		if c > 0:
			break
	if c == 0:
		print('No')


s = list(input().strip())
s.append('.')
dict = {}
cur = '.'
count = 0
for ch in s:
	if ch != cur:
		old = dict.get(cur, 0)
		dict[cur] = max(old, count)
		count = 0
	count += 1
	cur = ch
T = int(input().strip())
for t in range(T):
	x = int(input().strip())
	for i in range(1, 27):
		if x % i == 0:
			ch = chr(ord('a') - 1 + i)
			old = dict.get(ch, 0)
			if x // i <= old:
				print('Yes')
				break
	else:
		print('No')


s = input().strip()
n = int(input().strip())
arr = [-1] * 26
i = 0
prev = s[0]
uniform_len = 1
for i in s[1:]:
	if prev == i:
		uniform_len += 1
	else:
		if arr[ord(prev) - 97] < uniform_len:
			arr[ord(prev) - 97] = uniform_len
		uniform_len = 1
		prev = i
if arr[ord(prev) - 97] < uniform_len:
	arr[ord(prev) - 97] = uniform_len
for a0 in range(n):
	x = int(input().strip())
	i = 1
	for i in range(1, 27):
		if x % i == 0 and i * arr[i - 1] >= x:
			print('Yes')
			break
	else:
		print('No')


import sys

def make_set(s):
	count = 1
	prev = ''
	charU = {}
	for i in range(len(s)):
		if s[i] == prev:
			count += 1
			charU[count * (ord(s[i]) - 96)] = 1
		else:
			count = 1
			charU[count * (ord(s[i]) - 96)] = 1
			prev = s[i]
	return charU
s = input().strip()
n = int(input().strip())
setU = make_set(s)
for a0 in range(n):
	x = int(input().strip())
	print('Yes') if x in setU else print('No')


import sys
wordCount = {}
s = input().strip()
i = 0
j = 0
while i < len(s):
	curTotal = 0
	while j < len(s) and s[i] == s[j]:
		j += 1
		curTotal += 1
	if s[i] in wordCount:
		if wordCount[s[i]] < curTotal:
			wordCount[s[i]] = curTotal
	else:
		wordCount[s[i]] = curTotal
	i = j
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	flag = False
	for c in wordCount:
		if x % (ord(c) - 96) == 0 and (ord(c) - 96) * wordCount[c] >= x:
			flag = True
			break
	if flag:
		print('Yes')
	else:
		print('No')


import sys
weight = dict()
weight['a'] = 1
weight['b'] = 2
weight['c'] = 3
weight['d'] = 4
weight['e'] = 5
weight['f'] = 6
weight['g'] = 7
weight['h'] = 8
weight['i'] = 9
weight['j'] = 10
weight['k'] = 11
weight['l'] = 12
weight['m'] = 13
weight['n'] = 14
weight['o'] = 15
weight['p'] = 16
weight['q'] = 17
weight['r'] = 18
weight['s'] = 19
weight['t'] = 20
weight['u'] = 21
weight['v'] = 22
weight['w'] = 23
weight['x'] = 24
weight['y'] = 25
weight['z'] = 26

def weightF(w):
	val = weight[w[0]]
	return val * len(w)
s = input().strip()
last_letter = ''
conseq_string = ''
uni = set()
queries = set()
for letter in s:
	if letter not in uni:
		conseq_string = letter
		uni.add(conseq_string)
		queries.add(weightF(conseq_string))
	elif letter == last_letter:
		conseq_string += letter
		queries.add(weightF(conseq_string))
	else:
		conseq_string = letter
	last_letter = letter
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	if x in queries:
		print('Yes')
	else:
		print('No')


import sys

def calculate_weight(s):
	return (ord(s[0]) - 96) * len(s)

def generate_weights_set(s):
	ws_set = set()
	old_c = ''
	for c in s:
		if c in old_c:
			old_c = old_c + c
		else:
			old_c = c
		weight = calculate_weight(old_c)
		ws_set.add(weight)
	return ws_set
s = input().strip()
n = int(input().strip())
weights = generate_weights_set(s)
for _ in range(n):
	x = int(input().strip())
	if x in weights:
		print('Yes')
	else:
		print('No')


import sys
s = input().strip()
found = False
n = int(input().strip())
last = s[0]
count = 1
w = set()
for i in range(1, len(s)):
	w.add(count * (ord(last) - ord('a') + 1))
	if s[i] == last:
		count += 1
	else:
		count = 1
		last = s[i]
w.add(count * (ord(last) - ord('a') + 1))
for a0 in range(n):
	x = int(input().strip())
	if x in w:
		print('Yes')
	else:
		print('No')


def substrings(s):
	prev = None
	i = 0
	for c in s:
		if prev is None or c == prev:
			i += 1
			prev = c
		else:
			yield (prev, i)
			i = 1
			prev = c
	if prev is not None:
		yield (prev, i)
l = set()
for (c, n) in substrings(input()):
	d = ord(c) - ord('a') + 1
	for i in range(n):
		l.add(d * (i + 1))
for _ in range(int(input())):
	x = int(input())
	if x in l:
		print('Yes')
	else:
		print('No')


import sys
s = input().strip()
n = int(input().strip())
weight = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]
hashset = set()
val = weight[ord(s[0]) - ord('a')]
hashset.add(val)
length_of_s = len(s)
for i in range(1, length_of_s):
	if s[i] == s[i - 1]:
		hashset.add(val)
		val += weight[ord(s[i]) - ord('a')]
	else:
		hashset.add(val)
		val = weight[ord(s[i]) - ord('a')]
	if i == length_of_s - 1:
		hashset.add(val)
for a0 in range(n):
	x = int(input().strip())
	if x in hashset:
		print('Yes')
	else:
		print('No')


import sys

def uniform_str(str_main, w_x):
	for t_c in str_main:
		if w_x % t_c == 0 and str_main[t_c] >= w_x / t_c:
			return 'Yes'
	return 'No'
s = input().strip()
str_main = dict()
old_temp = ''
count = 0
for c in s:
	if old_temp != c:
		count = 1
	else:
		count += 1
	old_temp = c
	num = ord(c) - 96
	if num not in str_main:
		str_main[num] = count
	elif count > str_main[num]:
		str_main[num] = count
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	print(uniform_str(str_main, x))


import sys
import collections
s = input().strip()
n = int(input().strip())
res_dict = collections.defaultdict(int)
prev_letter = '0'
total_num = 0
for letter in s:
	if prev_letter == letter:
		total_num += 1
	else:
		res_dict[prev_letter] = max(total_num, res_dict[prev_letter])
		total_num = 1
		prev_letter = letter
res_dict[prev_letter] = max(total_num, res_dict[prev_letter])
possible_weights = set()
for (key, val) in res_dict.items():
	weight = ord(key) - 96
	weight_to_sum = 0
	for _ in range(val):
		weight_to_sum += weight
		possible_weights.add(weight_to_sum)
for a0 in range(n):
	x = int(input().strip())
	if x < 0:
		print('No')
		continue
	if x in possible_weights:
		print('Yes')
	else:
		print('No')


import sys
s = input().strip()
U = set()
(count, last) = (0, s[0])
for i in s:
	if last == i:
		count += 1
	else:
		(count, last) = (1, i)
	U.add((ord(last) - 96) * count)
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	if x in U:
		print('Yes')
	else:
		print('No')


s = input() + '.'
weights = set()
ct = 1
for i in range(1, len(s)):
	weights.add(ct * (ord(s[i - 1]) - ord('a') + 1))
	if s[i] == s[i - 1]:
		ct += 1
	else:
		ct = 1
n = int(input())
for _ in range(n):
	q = int(input())
	print('Yes' if q in weights else 'No')


import sys
s = input().strip()
H = [0] * 27
last = None
cons = 0
for c in s:
	n = ord(c) - ord('a') + 1
	if n == last:
		cons += 1
	else:
		if last != None:
			H[last] = max(H[last], cons)
		cons = 1
		last = n
H[last] = max(H[last], cons)

def f(x):
	for i in range(1, 27):
		if x % i == 0 and H[i] >= x // i:
			print('Yes')
			return
	print('No')
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	f(x)


import sys
s = input().strip()
n = int(input().strip())
sum = 0
last = 0
U = set()
k = 1
for i in range(len(s)):
	c = s[i]
	if c != last:
		k = 1
		last = c
	else:
		k += 1
	U.add((ord(c) - ord('a') + 1) * k)
for a0 in range(n):
	x = int(input().strip())
	print('Yes' if x in U else 'No')


import sys
s = input().strip()
actual = ord(s[0]) - 96
uStrings = []
for i in range(1, len(s)):
	if s[i] != s[i - 1]:
		uStrings.append(actual)
		actual = ord(s[i]) - 96
	else:
		uStrings.append(actual)
		actual = actual + ord(s[i]) - 96
uStrings.append(actual)
unif = set(uStrings)
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	if x in unif:
		print('Yes')
	else:
		print('No')


import sys

def weight(letter):
	return ord(letter) - 96

def get_resultset(s):
	resultset = set()
	start_index = None
	for (i, letter) in enumerate(s):
		resultset.add(weight(letter))
		if i > 0 and s[i - 1] == letter:
			resultset.add(weight(letter) * (i - start_index + 1))
		else:
			start_index = i
	return resultset

def main(inp=sys.stdin):
	s = inp.readline().strip()
	n = int(inp.readline().strip())
	result_set = get_resultset(s)
	for number in range(n):
		if int(inp.readline().strip()) in result_set:
			print('Yes')
		else:
			print('No')
main()


import sys
s = input().strip()
n = int(input().strip())
d = {}
size = len(s)
ascii_a = ord('a')
tmp = ord(s[0]) - ascii_a + 1
d[tmp] = 1
for i in range(1, size):
	if s[i] != s[i - 1]:
		tmp = 0
	tmp += ord(s[i]) - ascii_a + 1
	d[tmp] = 1
for a0 in range(n):
	x = int(input().strip())
	if x in d:
		print('Yes')
	else:
		print('No')


from string import ascii_lowercase
s = input()
l = []
for c in ascii_lowercase:
	count = 0
	ma = 0
	for i in range(len(s)):
		if c == s[i]:
			count = count + 1
			ma = max(ma, count)
		else:
			count = 0
	l.append(ma)
n = int(input())
for i in range(n):
	t = int(input())
	s = 0
	for j in range(len(l)):
		if t <= l[j] * (j + 1) and t % (j + 1) == 0:
			print('Yes')
			s = 1
			break
	if s == 0:
		print('No')


import sys
s = input().strip()
n = int(input().strip())
U = set()
currentletter = '#'
v = 0
for c in s:
	if c == currentletter:
		v += ord(c) - 96
	else:
		currentletter = c
		v = ord(c) - 96
	U.add(v)
for a0 in range(n):
	x = int(input().strip())
	print('Yes' if x in U else 'No')


import sys
weight = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
pWeights = set()

def getSubstrings(s):
	i = 0
	f = 1
	t = len(s)
	while f != t:
		f += 1
		if s[f - 1] != s[i]:
			inserePesos(s[i:f - 1])
			i = f - 1
	inserePesos(s[i:t])

def inserePesos(s):
	p = 0
	for c in s:
		p += weight[c]
		if p not in pWeights:
			pWeights.add(p)
s = input().strip()
n = int(input().strip())
getSubstrings(s)
for a0 in range(n):
	x = int(input().strip())
	if x in pWeights:
		print('Yes')
	else:
		print('No')


import sys
s = input().strip()
table = 26 * [0]
length = 1
table[ord(s[0]) - 97] = max(table[ord(s[0]) - 97], length)

def check_value(x):
	for (i, n) in enumerate(table, 1):
		if n > 0 and x >= i and (x % i == 0) and (x <= n * i):
			return True
	return False
for (i, a) in enumerate(s[1:], 1):
	if s[i - 1] == a:
		length += 1
	else:
		length = 1
	table[ord(a) - 97] = max(table[ord(a) - 97], length)
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	if check_value(x):
		print('Yes')
	else:
		print('No')


import sys

def create_map(some_str):
	c_map = {}
	last = some_str[0]
	same_c = 0
	for l in some_str:
		val = ord(l) - 96
		if last == l:
			same_c += 1
		else:
			same_c = 1
			last = l
		c_map[same_c * val] = True
	return c_map
s = input().strip()
n = int(input().strip())
c_map = create_map(s)
for a0 in range(n):
	x = int(input().strip())
	print('Yes' if x in c_map else 'No')


import sys
s = input().strip()
n = int(input().strip())
dic = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
curChar = None
seen = set()
total = 0
seen.add(0)
for char in s:
	if char != curChar:
		total = dic[char]
		curChar = char
	else:
		total = total + dic[char]
	seen.add(total)
for a0 in range(n):
	x = int(input().strip())
	if x in seen:
		print('Yes')
	else:
		print('No')


import sys
s = input().strip()
end = len(s)
letters = {}
i = 0
while i < len(s):
	c = s[i]
	weight = ord(c) - ord('a') + 1
	if c not in letters:
		letters[c] = weight
	count = 0
	while i < len(s):
		if s[i] != c:
			break
		count += weight
		i += 1
	if count > letters[c]:
		letters[c] = count
n = int(input().strip())
for a0 in range(n):
	valid = 0
	x = int(input().strip())
	for c in letters:
		i = ord(c) - ord('a') + 1
		if x % i == 0:
			if x <= letters[c]:
				valid = 1
		if valid == 1:
			break
	if valid == 0:
		print('No')
	else:
		print('Yes')


import sys
from itertools import groupby
s = input().strip()
L = list(s)
chars = [(k, sum((1 for i in g))) for (k, g) in groupby(L)]
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	for i in chars:
		asc = ord(i[0]) - 96
		if x % asc == 0 and asc * i[1] / x >= 1:
			print('Yes')
			break
	else:
		print('No')


import sys
dict = {}
s = input().strip()
i = 0
while i < len(s):
	cnt = 1
	k = s[i]
	if k not in dict:
		dict[k] = 1
	while True:
		if i + 1 < len(s) and s[i] == s[i + 1]:
			cnt += 1
		else:
			i += 1
			break
		i += 1
	if dict[k] <= cnt:
		dict[k] = cnt
l = list(dict.keys())
l.sort()
num = []
for i in dict:
	val = ord(i) - 96
	for j in range(1, dict[i] + 1):
		num.append(j * val)
num = set(num)
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	if x in num:
		print('Yes')
	else:
		print('No')


import math

def binary_search(array, target):
	lower = 0
	upper = len(array)
	while lower < upper:
		x = lower + (upper - lower) // 2
		val = array[x]
		if target == val:
			return x
		elif target > val:
			if lower == x:
				break
			lower = x
		elif target < val:
			upper = x
s = input().strip()
n = int(input().strip())
val = []
val.append(ord(s[0]) - 96)
if len(s) > 1:
	t = ord(s[1]) - 96
for i in range(1, len(s)):
	z = ord(s[i]) - 96
	if z == ord(s[i - 1]) - 96:
		t = t + z
		val.append(t)
	else:
		val.append(z)
		if i < len(s) - 1:
			t = ord(s[i + 1]) - 96
val.sort()
for a0 in range(n):
	x = int(input().strip())
	z = binary_search(val, x)
	if z is None:
		print('No')
	else:
		print('Yes')


import sys
s = input().strip()
n = int(input().strip())
y = [0] + sorted('qwertyuioplkjhgfdsazxcvbnm')
t = set()
g = s[0]
k = 0
p = 0
for i in s:
	i = y.index(i)
	if g == i:
		p += i
	else:
		g = i
		p = i
	t.add(p)
for a0 in range(n):
	x = int(input().strip())
	if x in t:
		print('Yes')
	else:
		print('No')


import itertools
import sys
s = input().strip()
n = int(input().strip())
x = []
set1 = []
for a0 in range(n):
	x.append(int(input()))
for i in range(len(s)):
	if i == 0:
		set1.append(ord(s[i]) - 96)
	elif s[i] == s[i - 1]:
		set1.append(set1[i - 1] + ord(s[i]) - 96)
	else:
		set1.append(ord(s[i]) - 96)
set2 = [0] * 10000001
for i1 in set1:
	set2[i1] = 1
for x1 in x:
	if set2[x1] == 1:
		print('Yes')
	else:
		print('No')


import sys
from collections import defaultdict
weights = {chr(x + 96): x for x in range(1, 27)}
s = input().strip()
n = int(input().strip())
u = set()
prev_letter = None
length = 0
for letter in s:
	if letter in weights:
		letter_weight = weights[letter]
		if letter != prev_letter:
			weight = letter_weight
			length = 1
		else:
			length += 1
			weight = letter_weight * length
		u.add(weight)
	prev_letter = letter
for a0 in range(n):
	x = int(input().strip())
	if x in u:
		print('Yes')
	else:
		print('No')


import sys
uniform_string_values = set()
substring_char_weight = 0
substring_length = 0
s = input().strip()
for c in s:
	w = ord(c) - 96
	if w != substring_char_weight:
		substring_char_weight = w
		substring_length = 0
	substring_length += 1
	uniform_string_values.add(substring_length * substring_char_weight)
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	if x in uniform_string_values:
		print('Yes')
		continue
	print('No')


def binarySearch(alist, item):
	first = 0
	last = len(alist) - 1
	found = False
	while first <= last and (not found):
		midpoint = (first + last) // 2
		if alist[midpoint] == item:
			found = True
		elif item < alist[midpoint]:
			last = midpoint - 1
		else:
			first = midpoint + 1
	return found
s = input().strip()
list_of_contigues_values = list()
previous_value = 0
previous_character = None
for c in s:
	v = ord(c) - ord('a') + 1
	if c != previous_character:
		previous_value = 0
	previous_value += v
	previous_character = c
	list_of_contigues_values.append(previous_value)
n = int(input().strip())
list_of_contigues_values = sorted(list_of_contigues_values)
results = list()
for a0 in range(n):
	x = int(input().strip())
	if binarySearch(list_of_contigues_values, x):
		results.append('Yes')
	else:
		results.append('No')
for r in results:
	print(r)


from string import ascii_lowercase
s = input()
l = []
for c in ascii_lowercase:
	cnt = 0
	maxi = 0
	for i in range(len(s)):
		if c == s[i]:
			cnt = cnt + 1
			maxi = max(maxi, cnt)
		else:
			cnt = 0
	l.append(maxi)
k = int(input())
for i in range(k):
	t = int(input())
	st = 0
	for j in range(len(l)):
		if t <= l[j] * (j + 1) and t % (j + 1) == 0:
			print('Yes')
			st = 1
			break
	if st == 0:
		print('No')


import sys, string
char_weights = {c: i + 1 for (i, c) in enumerate(string.ascii_lowercase)}

def to_weights(s):
	w = set()
	last = s.pop()
	count = 1
	w.add(count * char_weights[last])
	while s:
		current = s.pop()
		if current == last:
			count += 1
			w.add(count * char_weights[last])
		else:
			count = 1
			last = current
			w.add(count * char_weights[last])
	return w
s = [c for c in input().strip()]
w = to_weights(s)
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	if x in w:
		print('Yes')
	else:
		print('No')


import sys
s = input().strip()
n = int(input().strip())
li = {}
t = s[0]
li[ord(t) - 96] = 0
c = 0
for i in range(1, len(s)):
	if t == s[i]:
		c += 1
	else:
		c = 0
	li[(c + 1) * int(ord(s[i]) - 96)] = 0
	t = s[i]
for a0 in range(n):
	x = int(input().strip())
	if x not in li.keys():
		print('No')
	else:
		print('Yes')


import sys
s = input().strip()
st = set()
v = ord(s[0]) - 96
st.add(v)
for i in range(1, len(s)):
	if s[i - 1] == s[i]:
		v = v + ord(s[i]) - 96
		st.add(v)
	else:
		v = ord(s[i]) - 96
		st.add(v)
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	if x in st:
		print('Yes')
	else:
		print('No')


import bisect
s = input()
base = 96
d = dict()
ss = set(s)
prev = s[0]
U = list()
U.append(ord(prev) - base)
cnt = 1
for i in range(1, len(s)):
	if s[i] == prev:
		cnt += 1
		U.append((ord(prev) - base) * cnt)
	else:
		U.append(ord(s[i]) - base)
		prev = s[i]
		cnt = 1
U.sort()
for t in range(int(input())):
	x = int(input())
	v = bisect.bisect_left(U, x)
	if v < len(U) and U[v] == x:
		print('Yes')
	else:
		print('No')


import sys
s = input().strip()
n = int(input().strip())
ans = {}
buff = ord(s[0]) - ord('a') + 1
ans[buff] = 1
for i in range(1, len(s)):
	temp = ord(s[i]) - ord('a') + 1
	if s[i] == s[i - 1]:
		buff += temp
	else:
		buff = temp
	ans[buff] = 1
for a0 in range(n):
	x = int(input().strip())
	if x in ans:
		print('Yes')
	else:
		print('No')


from functools import reduce
l = [[] for _ in range(26)]
prev = -1
for c in map(lambda x: ord(x) - ord('a'), input()):
	if c == prev:
		l[c][-1] += 1
	else:
		l[c].append(1)
	prev = c
all_gen = reduce(lambda x0, x1: x0.union(x1), map(lambda x: set([(x[0] + 1) * nb for nb in range(1, max(x[1]) + 1 if x[1] != set() else 1)]), enumerate(map(lambda x: set(x), l))))
nb_q = int(input())
[print('Yes' if int(input()) in all_gen else 'No') for q in range(nb_q)]


import sys
s = input().strip()
(n, t) = (int(input()), ord(s[0]) - 96)
S = {0, t}
for i in range(1, len(s)):
	if s[i] != s[i - 1]:
		t = 0
	t += ord(s[i]) - 96
	S.add(t)
X = [int(input()) for _ in range(n)]
print('\n'.join(['Yes' if x in S else 'No' for x in X]))


from collections import Counter
ord_a = ord('a')
s = input()
freq = [0] * 26
i = 0
prev = None
count = 0
while i < len(s):
	c = s[i]
	if c == prev:
		count += 1
	else:
		prev = c
		count = 1
	i += 1
	pos = ord(c) - ord_a
	if count > freq[pos]:
		freq[pos] = count

def solve(x):
	for (i, v) in enumerate(freq, 1):
		y = x / i
		if y.is_integer() and y <= v:
			return True
	return False
for _ in range(int(input())):
	print('Yes' if solve(int(input())) else 'No')


import sys
s = input().strip()
n = int(input().strip())
currentWeight = 0
last_char = None
weights = set()
for ch in s:
	if last_char and ch != last_char:
		currentWeight = ord(ch.lower()) - 96
	else:
		currentWeight += ord(ch.lower()) - 96
	weights.add(currentWeight)
	last_char = ch
for a0 in range(n):
	x = int(input().strip())
	print('Yes' if x in weights else 'No')


import sys
s = input().strip()
n = int(input().strip())
l = set()
s = s + '5'
mul = 1
for x in range(len(s) - 1):
	if s[x] == s[x + 1]:
		l.add(int((ord(s[x]) - 96) * mul))
		mul += 1
	else:
		l.add(int((ord(s[x]) - 96) * mul))
		mul = 1
for a0 in range(n):
	x = int(input().strip())
	print('Yes' if x in l else 'No')


import sys
s = input().strip()
n = int(input().strip())
l = len(s)
prev = 0
lst = []
tmp = 0
for el in s:
	if prev == el:
		tmp = lst[-1]
	else:
		tmp = 0
	lst.append(ord(el) - 96 + tmp)
	prev = el
slst = set(lst)
minnum = min(lst)
maxnum = max(lst)
for a0 in range(n):
	x = int(input().strip())
	if x >= minnum and x <= maxnum and (x in slst):
		print('Yes')
	else:
		print('No')


import sys

def my_fun(x):
	for i in range(1, 27):
		if x % i == 0:
			if arr[i] >= int(x / i):
				return True
	return False

def my_loop(s, i):
	cnt = 1
	while i + 1 < len(s):
		if s[i] == s[i + 1]:
			cnt += 1
			i += 1
		else:
			break
	return cnt
s = input().strip()
arr = [0] * 27
i = 0
while i < len(s):
	cnt = my_loop(s, i)
	arr[ord(s[i]) - ord('a') + 1] = max(arr[ord(s[i]) - ord('a') + 1], cnt)
	i += cnt
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	if my_fun(x):
		print('Yes')
	else:
		print('No')


import sys
from string import ascii_lowercase as lc
char_weights = {ch: ord(ch) - ord('a') + 1 for ch in lc}
st = input().strip()
uni_sts = set([char_weights[st[0]]])
cur_weight = char_weights[st[0]]
for i in range(1, len(st)):
	if st[i] != st[i - 1]:
		cur_weight = 0
	cur_weight += char_weights[st[i]]
	uni_sts.add(cur_weight)
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	if x in uni_sts:
		print('Yes')
	else:
		print('No')


import sys
s = input().strip()
n = int(input().strip())
l = {}
for i in range(ord('a'), ord('z') + 1):
	l[i - ord('a') + 1] = chr(i)
for a0 in range(n):
	x = int(input().strip())
	found = False
	for i in reversed(range(1, min(26, x) + 1)):
		if x % i == 0:
			if l[i] * (x // i) in s:
				found = True
				break
	if found:
		print('Yes')
	else:
		print('No')


import sys
WordDict = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
s = input().strip()
n = int(input().strip())
InputDict = {}
temp = s[0]
TCount = 1
for word in s[1:]:
	if word == temp:
		TCount += 1
	else:
		try:
			if InputDict[temp] < TCount:
				InputDict[temp] = TCount
		except:
			InputDict[temp] = TCount
		temp = word
		TCount = 1
try:
	if InputDict[temp] < TCount:
		InputDict[temp] = TCount
except:
	InputDict[temp] = TCount
OlabilcekSayiSet = set()
for harf in InputDict:
	HarfDeger = WordDict[harf]
	for i in range(1, InputDict[harf] + 1):
		OlabilcekSayiSet.add(i * HarfDeger)
for a0 in range(n):
	x = int(input().strip())
	if x in OlabilcekSayiSet:
		print('Yes')
	else:
		print('No')


import sys
s = input().strip()
weights = {}
patternLength = 0
previousCharacter = None
for c in s:
	currentCharacter = ord(c) - 96
	if previousCharacter == currentCharacter:
		patternLength += 1
		if patternLength > weights[currentCharacter]:
			weights[currentCharacter] = patternLength
	else:
		patternLength = 1
		if currentCharacter not in weights:
			weights[currentCharacter] = 1
	previousCharacter = currentCharacter
n = int(input().strip())
for i in range(n):
	x = int(input().strip())
	flag = False
	for c in sorted(weights, reverse=True):
		if x % c == 0:
			if x <= c * weights[c]:
				flag = True
				break
	if flag:
		print('Yes')
	else:
		print('No')


import sys
letter_weights = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}

def getUniformSubstringWeights(s):
	weights = set()
	i = 0
	while i < len(s):
		j = i
		while j < len(s):
			if s[j] == s[i]:
				length = j - i
				weights.add((length + 1) * letter_weights[s[i]])
			else:
				break
			j += 1
		i = j
	return weights
s = input().strip()
n = int(input().strip())
us_weights = getUniformSubstringWeights(s)
for a0 in range(n):
	x = int(input().strip())
	if x > len(s) * 26:
		print('No')
	elif x in us_weights:
		print('Yes')
	else:
		print('No')


s = input().strip()
reachable = set()
prevChar = ''
currCount = 0
currVal = 0
for ch in s:
	if ch == prevChar:
		currCount += 1
	else:
		currCount = 1
		currVal = ord(ch) - ord('a') + 1
	reachable.add(currCount * currVal)
	prevChar = ch
n = int(input().strip())
for q in range(n):
	x = int(input().strip())
	if x in reachable:
		print('Yes')
	else:
		print('No')


import sys

def binarySearch(alist, item):
	first = 0
	last = len(alist) - 1
	found = False
	while first <= last and (not found):
		midpoint = (first + last) // 2
		if alist[midpoint] == item:
			found = True
		elif item < alist[midpoint]:
			last = midpoint - 1
		else:
			first = midpoint + 1
	return found
s = input().strip()
n = int(input().strip())
l = []
i = 0
while i < len(s):
	t = ord(s[i]) - 96
	l.append(t)
	while i < len(s) - 1 and s[i] == s[i + 1]:
		t += ord(s[i]) - 96
		l.append(t)
		i += 1
	i += 1
l.sort()
for a0 in range(n):
	x = int(input().strip())
	if binarySearch(l, x):
		print('Yes')
	else:
		print('No')


s = input()
n = int(input())
u = set()
seq = 0
for i in range(len(s)):
	c = ord(s[i]) - ord('a') + 1
	u.add(c)
	if i != 0 and s[i - 1] == s[i]:
		seq += c
		u.add(seq)
	else:
		seq = c
for _ in range(n):
	x = int(input())
	if x in u:
		print('Yes')
	else:
		print('No')


import string
char_to_weight = {char: idx + 1 for (idx, char) in enumerate(string.ascii_lowercase)}
s = input()
W = [int(input()) for _ in range(int(input()))]
U = set()
cnt = 0
for (idx, char) in enumerate(s):
	char = s[idx]
	weight_char = char_to_weight[char]
	U.add(weight_char)
	cnt += weight_char
	U.add(cnt)
	if idx < len(s) - 1 and s[idx] != s[idx + 1]:
		cnt = 0
print('\n'.join(list(map(lambda x: 'Yes' if x in U else 'No', W))))


import sys

def getCharValue(char):
	return ord(char) - 97 + 1

def getDicSolution(string):
	oldChar = string[0]
	dic = {}
	for i in range(1, 27):
		dic[i] = 0
	acumSize = 1
	i = 1
	while i < len(string):
		if oldChar == string[i]:
			acumSize += 1
		else:
			if acumSize > dic[getCharValue(oldChar)]:
				dic[getCharValue(oldChar)] = acumSize
			acumSize = 1
			oldChar = string[i]
		i += 1
	if acumSize > dic[getCharValue(oldChar)]:
		dic[getCharValue(oldChar)] = acumSize
	return dic

def verify(x, dic):
	for i in range(1, 26 + 1):
		if x % i == 0 and x / i <= dic[i]:
			return True
	return False

def main():
	s = input().strip()
	n = int(input().strip())
	dic = getDicSolution(s)
	for a0 in range(n):
		x = int(input().strip())
		if verify(x, dic):
			print('Yes')
		else:
			print('No')
main()


import sys
import string
s = input().strip()
n = int(input().strip())
letters = list(string.ascii_lowercase)
possW = set()
val = ''
for l in range(0, len(s)):
	if s[l] != val:
		val = s[l]
		ssCtr = 1
		valSingleW = letters.index(val) + 1
		possW.add(valSingleW)
		if len(s) > 1:
			for i in range(l + 1, len(s)):
				nextVal = s[i]
				if nextVal == val:
					ssCtr += 1
					possW.add(valSingleW * ssCtr)
				else:
					break
for a0 in range(n):
	x = int(input().strip())
	if x in possW:
		print('Yes')
	else:
		print('No')


s = input()
n = int(input())

def weight(ch):
	return ord(ch) - ord('a') + 1
ar = [0] * (26 * 100000 + 1)
last = None
count = 1
for ch in s:
	if ch != last:
		count = 1
		last = ch
	else:
		count += 1
	ar[weight(ch) * count] = 1
for __ in range(n):
	query = int(input())
	if query >= len(ar):
		print('No')
	else:
		print('Yes' if ar[query] else 'No')


s = input()
n = int(input())
t = 'abcdefghijklmnopqrstuvwxyz'
d = {}
c = 1
m = {}
ape = 0
for i in range(1, 27):
	m[i] = t[ape]
	ape += 1
for i in t:
	d[i] = c
	c += 1
dd = {}
for i in s:
	dd[d[i]] = dd.get(d[i], 0) + 1
for i in range(n):
	flag = 0
	x = int(input())
	for j in dd.keys():
		if x % j == 0 and m[j] * (x // j) in s:
			flag = 1
			break
	if flag == 1:
		print('Yes')
	else:
		print('No')


import sys
wus = set()

def process_s(s):
	current_i = 0
	count = 1
	last_char = 'A'
	while current_i < len(s):
		c = s[current_i]
		if c != last_char:
			last_char = c
			count = 1
		else:
			count += 1
		wus.add((ord(c) - ord('a') + 1) * count)
		current_i += 1
s = input().strip()
process_s(s)
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	if x in wus:
		print('Yes')
	else:
		print('No')


import sys
import bisect

def str2list(s):
	ss = []
	ns = len(s)
	chrCount = {chr(97 + i): 0 for i in range(26)}
	index = {chr(96 + i): i for i in range(1, 27)}
	i = 0
	while i < ns:
		c = s[i]
		nc = 1 + i
		while nc < ns and s[nc] == c:
			nc += 1
		count = nc - i
		if count > chrCount[c]:
			chrCount[c] = count
		i = nc
	for i in range(1, 27):
		c = chr(96 + i)
		v = i
		for j in range(chrCount[c]):
			ss.append(v)
			v += i
	return sorted(ss)

def main():
	s = input().strip()
	n = int(input().strip())
	ss = str2list(s)
	for i in range(n):
		x = int(input().strip())
		k = bisect.bisect(ss, x)
		if x == ss[k - 1]:
			print('Yes')
		else:
			print('No')
main()


import sys
import string

def parse_string(s, weights):
	r = set([])
	current_count = 0
	current_char = s[0]
	for i in range(len(s)):
		if s[i] == current_char:
			current_count += weights[s[i]]
		else:
			current_char = s[i]
			current_count = weights[s[i]]
		r.add(current_count)
	return r
letter_weights = dict(zip(string.ascii_letters[:26], range(1, 27)))
s = input().strip()
weights = parse_string(s, letter_weights)
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	if x in weights:
		print('Yes')
	else:
		print('No')


from collections import Counter

def charWeight(c):
	return ord(c) - ord('a') + 1
possScores = set()
s = input().strip()
count_s = dict()
currChar = s[0]
streak = 1
possScore = set()
possScores.add(streak * charWeight(currChar))
for i in range(1, len(s)):
	if s[i] == currChar:
		streak += 1
		possScores.add(streak * charWeight(currChar))
	else:
		currChar = s[i]
		streak = 1
		possScores.add(streak * charWeight(currChar))
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	if x in possScores:
		print('Yes')
	else:
		print('No')


import sys
s = input().strip()
lastletter = ''
currentlength = 0
possiblevalues = set()
while len(s) > 0:
	newletter = s[-1]
	s = s[:-1]
	if newletter == lastletter:
		currentlength += 1
	else:
		currentlength = 1
	possiblevalues.add((ord(newletter) - 96) * currentlength)
	lastletter = newletter
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	if x in possiblevalues:
		print('Yes')
	else:
		print('No')


import sys
s = input().strip()
comb = set()
pre = 0
for i in range(len(s)):
	if i == 0 or s[i] != s[i - 1]:
		pre = ord(s[i]) - ord('a') + 1
	else:
		pre += ord(s[i]) - ord('a') + 1
	comb.add(pre)
n = int(input().strip())
for a0 in range(n):
	x = int(input().strip())
	if x in comb:
		print('Yes')
	else:
		print('No')


import sys
S = input().strip()
n = int(input().strip())
W = dict(zip(list('abcdefghijklmnopqrstuvwxyz'), range(1, 27)))
splits = [S[i] != S[i + 1] for i in range(len(S) - 1)] + [True]
F = {}
c = 1
for i in range(len(splits)):
	if splits[i]:
		if S[i] in F:
			F[S[i]] = max(c, F[S[i]])
		else:
			F[S[i]] = c
		c = 1
	else:
		c += 1
for a0 in range(n):
	x = int(input().strip())
	if any(map(lambda k: x % W[k] == 0 and x / W[k] <= F[k], F.keys())):
		print('Yes')
	else:
		print('No')


import sys
s = input().strip()
n = int(input().strip())
list_of_string_values = [ord(letter) - 96 for letter in s]

def find_uniform_occurrences(list_of_string_values):
	uniform = dict()
	check = 0
	for (index, item) in enumerate(list_of_string_values):
		check += item
		try:
			if item == list_of_string_values[index + 1]:
				uniform[check] = 'Yes'
			if item != list_of_string_values[index + 1]:
				uniform[check] = 'Yes'
				check = 0
		except IndexError:
			uniform[check] = 'Yes'
	return uniform
uniform_string_occurences = find_uniform_occurrences(list_of_string_values)

def check_for_match(x):
	try:
		return uniform_string_occurences[x]
	except KeyError:
		return 'No'
for a0 in range(n):
	x = int(input().strip())
	print(check_for_match(x))


import string
char_to_weight = {char: idx + 1 for (idx, char) in enumerate(string.ascii_lowercase)}
s = input()
W = [int(input()) for _ in range(int(input()))]
U = set()
cnt = 0
for (idx, char) in enumerate(s):
	char = s[idx]
	weight_char = char_to_weight[char]
	U.add(weight_char)
	cnt += weight_char
	U.add(cnt)
	if idx < len(s) - 1 and s[idx] != s[idx + 1]:
		cnt = 0
print('\n'.join(list(map(lambda x: 'Yes' if x in U else 'No', W))))


import sys
s = input().strip()
n = int(input().strip())
i = 0
first = True
possible_values = set()
while i < len(s):
	if first:
		curr_sum = ord(s[0]) - ord('a') + 1
		possible_values.add(curr_sum)
		first = False
		i += 1
	else:
		if s[i - 1] == s[i]:
			curr_sum += ord(s[i]) - ord('a') + 1
		else:
			curr_sum = ord(s[i]) - ord('a') + 1
		possible_values.add(curr_sum)
		i += 1
for a0 in range(n):
	x = int(input().strip())
	if x in possible_values:
		print('Yes')
	else:
		print('No')


import sys
import itertools
s = input().strip()
n = int(input().strip())
ls = [list(g) for (k, g) in itertools.groupby(s)]
res = set()
for i in ls:
	for j in range(len(i) + 1):
		res.add(j * (ord(i[0]) - ord('a') + 1))
for a0 in range(n):
	x = int(input().strip())
	if x in res:
		print('Yes')
	else:
		print('No')


letter_weight_dic = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}

def splitStrings(s):
	out = {}
	temp = ''
	val = 0
	for c in s:
		if c == temp:
			val += letter_weight_dic[c]
		else:
			temp = c
			val = letter_weight_dic[c]
		out[val] = True
	out.pop('', None)
	return out
s = input()
queries = int(input())
weights = []
for i in range(0, queries):
	weight = int(input())
	weights.append(weight)
uniform_weights = splitStrings(s)
for n in weights:
	if n in uniform_weights:
		print('Yes')
	else:
		print('No')