fork download
  1. s = input()
  2. 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}
  3. ws = []
  4. for i in range(len(s)):
  5. if i == 0 and s[i] in weights:
  6. ws.append(weights[s[i]])
  7. continue
  8. if s[i]==s[i-1]:
  9. ws.append(ws[i-1]+weights[s[i]])
  10. else:
  11. ws.append(weights[s[i]])
  12.  
  13.  
  14. n = int(input())
  15.  
  16.  
  17. from bisect import bisect_left
  18.  
  19. def binary_search(a, x, lo=0, hi=None):
  20. if hi != None:
  21. hi=hi
  22. else:
  23. hi=len(a)
  24.  
  25. pos = bisect_left(a,x,lo,hi)
  26.  
  27. if pos != hi and a[pos] == x :
  28. return pos
  29. else:
  30. return -1
  31.  
  32. ws.sort()
  33.  
  34. for _ in range(n):
  35. i = int(input())
  36. if(binary_search(ws, i) != -1):
  37. print("Yes")
  38. else:
  39. print("No")
Success #stdin #stdout 0.04s 28504KB
stdin
aaabbbbcccddd
5
9
7
8
12
5
stdout
Yes
No
Yes
Yes
No