import times, strutils, sequtils, math, algorithm, tables, sets, lists, intsets import critbits, future, strformat, deques template `max=`(x,y) = x = max(x,y) template `min=`(x,y) = x = min(x,y) template `mod=`(x,y) = x = x mod y template scan2 = (scan(), scan()) template scan3 = (scan(), scan()) let read* = iterator: string {.closure.} = while true: (for s in stdin.readLine.split: yield s) proc scan(): int = read().parseInt proc scanf(): float = read().parseFloat proc toInt(c:char): int = return int(c) - int('0') # bitごとにスコアを数える proc solve()= var n = scan() q = scan() a = newseqwith(n,scan()) s = read() t = newseqwith(q,scan()) d = 30 memo = newseqwith(d+1,newseqwith(2,0)) proc f(idx,v:int,first:int):int= if idx==n: return 0 else: var nxt:int if s[idx]=='0': nxt = first and (v and a[idx]) else: nxt = first and (v or a[idx]) return abs(nxt-v) + f(idx+1,nxt,first) for i in 0..0: res+=memo[i][1] else: res+=memo[i][0] echo res solve()