fork download
  1. # your code goes here
  2.  
  3. def calculate_tax(S, X, Y):
  4. tax = 0
  5. index = 0
  6. while index < len(S):
  7. if S[index:index+2] == "10":
  8. tax += Y
  9. elif S[index:index+2] == "01":
  10. tax += X
  11. index += 1
  12. return tax
  13.  
  14.  
  15.  
  16.  
  17. X = int(input())
  18. Y = int(input())
  19. S = input()
  20. print(calculate_tax(S,X,Y))
  21.  
  22. X = int(input())
  23. Y = int(input())
  24. S = input()
  25. print(calculate_tax(S,X,Y))
  26.  
  27. X = int(input())
  28. Y = int(input())
  29. S = input()
  30. print(calculate_tax(S,X,Y))
  31.  
  32. X = int(input())
  33. Y = int(input())
  34. S = input()
  35. print(calculate_tax(S,X,Y))
  36.  
  37. X = int(input())
  38. Y = int(input())
  39. S = input()
  40. print(calculate_tax(S,X,Y))
Success #stdin #stdout 0.03s 9828KB
stdin
7
3
1101
5
5
1111
5
3
001
3
8
1010101010
4
4
00000000
stdout
10
0
5
52
0