import sequtils,strutils,strscans,algorithm,math,future,macros template get*():string = stdin.readLine() #.strip() macro unpack*(rhs: seq,cnt: static[int]): auto = let t = genSym(); result = quote do:(let `t` = `rhs`;()) for i in 0..= y.L and y.R >= x.L) : amebas &= (max(y.L,x.L), min(y.R,x.R)) # flatten const invalid = (1,-1) for ai,a in amebas: for bi,b in amebas[0..= b.L and b.R >= a.L and b != invalid: amebas[ai] = (min(a.L,b.L), max(a.R,b.R)) amebas[bi] = invalid amebas = amebas.filterIt(it != invalid) # sub other ranges var seg = 2 * T + 1 for a in amebas: seg -= (a.R - a.L) div D + 1 ans += seg echo ans