fork download
  1. def solve(N, K, L, R, Sn, Sk):
  2. special = set(Sk)
  3. arr = [1 if c in special else 0 for c in Sn]
  4. prefix = [0]
  5. for x in arr:
  6. prefix.append(prefix[-1] + x)
  7. count = 0
  8. for i in range(N):
  9. for j in range(i + 1, N + 1):
  10. total = prefix[j] - prefix[i]
  11. if L <= total <= R:
  12. count += 1
  13. print(count)
  14.  
  15. T = int(input())
  16. for _ in range(T):
  17. N, K, L, R = map(int, input().split())
  18. Sn = input().strip()
  19. Sk = input().strip()
  20. solve(N, K, L, R, Sn, Sk)
  21.  
Success #stdin #stdout 0.09s 14148KB
stdin
2
5 3 3 4
AbcAb
AbZ
9 2 1 2
adebfgbhd
ab
stdout
3
33