import sequtils,algorithm,math proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "" .} proc scan(): int = while true: var k = getchar_unlocked() if k < '0': break result = 10 * result + k.ord - '0'.ord template times*(n:int,body) = (for _ in 0.. 0) var ans = 0 while true: rgb = rgb.filterIt(it > 0) # echo rgb,ans if rgb.len == 3: # 5 18 36 var del = rgb.min() rgb = rgb.mapIt(it - del) ans += del elif rgb.len == 2: # 0 13 31 let x = rgb.max() let y = rgb.min() var n = (x - y) div 2 if n > 1 and n >= x - n * 2: n = n div 2 if n == 0 : if x == 3 and y == 2: rgb = @[1,2,1] continue if x <= 2: break rgb = @[x mod 4,y mod 4] ans += y div 4 * 2 else: rgb = @[x - n * 2, y , n ] # 9 13 13 elif rgb.len == 1: let r = rgb[0] if r <= 4: break rgb = @[1,1,r - 4] else: break echo ans