{. warning[UnusedImport]:off .} import sequtils,algorithm,math,tables,sets,strutils,times,pegs,macros,strformat,typetraits,terminal,os proc scanf(formatstr: cstring){.header: "", varargs.} proc getchar(): char {.header: "", varargs.} proc ri*(): int = scanf("%lld",addr result) proc rf*(): float = scanf("%lf",addr result) proc rs*(): string = var get = false result = "" while true: var c = getchar() if int(c) > int(' '): get = true result.add(c) else: if get: break get = false proc chmin*(a:var int,b:int): bool {.discardable.} = if a > b: a = b return true else: return false proc chmax*(a:var int,b:int): bool {.discardable.} = if a < b: a = b return true else: return false macro debug*(n: varargs[untyped]): untyped = var buff = fmt""" when defined(debug): stderr.writeLine ("[debug] ---------------------------------") """ var maxLen = 0 for x in n: if x.kind == nnkIdent: let l = ($x).len if l > maxLen: maxLen = l for x in n: if x.kind == nnkStrLit: buff = buff & fmt""" stderr.writeLine ("[debug] - - - - - - - - - - - - - - - - -") stderr.writeLine ("[debug] " & {repr(x)}) stderr.writeLine ("[debug] - - - - - - - - - - - - - - - - -") """ if x.kind == nnkIdent: let name = " ".repeat(maxLen - ($x).len) & $x buff = buff & fmt""" stderr.writeLine ("[debug] {name} => " & ${repr(x)}) """ buff = buff & """ stderr.writeLine ("[debug] ---------------------------------") """ parseStmt(buff) iterator range*(st,en: int): int = for idx in st.. 0 while idx < en: yield idx idx += step else: doAssert step < 0 while idx > en: yield idx idx += step # proc `%`*(x,y: SomeInteger): SomeInteger = x mod y proc `//`*(x,y: SomeInteger): SomeInteger = x div y proc `%=`*(x: var SomeInteger,y: SomeInteger) = x = x mod y proc `/=`*(x: var SomeInteger,y: int) = x = x div y proc `cd`*[T](x,y: T): T = x div y + ord(x mod y != 0) when NimMajor <= 0 and NimMinor <= 18: import future else: import sugar # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # when defined release: {.checks: off.} # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # template countIt*[T](a: openArray[T]; pred: untyped): int = var result = 0 for it {.inject.} in items(a): if pred: result.inc result # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # template newSeqWithImpl[T](lens: seq[int]; init: T; currentDimension, lensLen: static[int]): untyped = when currentDimension == lensLen: newSeqWith(lens[currentDimension - 1], init) else: newSeqWith(lens[currentDimension - 1], newSeqWithImpl(lens, init, currentDimension + 1, lensLen)) template newSeqWith*[T](lens: varargs[int]; init: T): untyped = assert(lens.allIt(it > 0)) newSeqWithImpl(@lens, init, 1, lens.len) template vector*[T](lens: varargs[int]; init: T = 0): untyped = assert(lens.allIt(it > 0)) newSeqWithImpl(@lens, init, 1, lens.len) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # let a,b = ri() echo (a or b) - (a and b)