# Python program for above approach
def solve_util(s, c, x, y, z, w):
ans = 0
for i in range(0, len(s), 4):
if (s[i] != x):
ans += c[i]
if (i + 1 < len(s)
and s[i + 1] != y):
ans += c[i + 1]
if (i + 2 < len(s)
and s[i + 2] != z):
ans += c[i + 2]
if (i + 3 < len(s)
and s[i + 3] != w):
ans += c[i + 3]
return ans
def solve_util2(s, c, x, y):
ans = 0
if (s[0] != x):
ans += c[0]
if (s[1] != y):
ans += c[1]
return ans
# Function to convert given
# string to required form
def minOperations(N, S, C):
# code here
if (len(S) == 2):
x = solve_util2(S, C, '0', '1')
y = solve_util2(S, C, '1', '0')
z = solve_util2(S, C, '1', '1')
w = solve_util2(S, C, '0', '0')
print(f"{x},{y},{z},{w}")
return min([x, y, z, w])
x = solve_util(S, C, '0', '1', '0', '1')
y = solve_util(S, C, '1', '0', '1', '0')
z = solve_util(S, C, '1', '1', '0', '0')
w = solve_util(S, C, '0', '0', '1', '1')
return min([x, y, z, w])
# Driver Code
N = 4
s = "1011"
ct = [1, 2, 1, 3]
print(minOperations(N, s, ct))
# This code is contributed by gfgking