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') var memo = initTable[(int,int,int),bool]() proc dfs(a,b,c:int):bool= if memo.haskey((a,b,c)): return memo[(a,b,c)] if a==0 or b==0 or c==0: return false elif (a!=b and b!=c and c!=a) and ((a > b and b < c) or (a < b and b > c)): #echo fmt"{a} {b} {c}" return true else: memo[(a,b,c)]=dfs(a-1,b,c) or dfs(a,b-1,c) or dfs(a,b,c-1) return memo[(a,b,c)] #for a in 1..100: #for b in 1..100: #for c in 1..100: #if dfs(a,b,c)==false: #echo fmt"{a} {b} {c}" #echo dfs(2,2,3) proc solve()= var t = scan() abcxyz = newseqwith(t,(scan(),scan(),scan(),scan(),scan(),scan())) for i in 0..=b: p1+=(a-b+1)*x a = b-1 if c>=b: p1+=(c-b+1)*z c = b-1 if a==c: p1+=min(x,z) a-=1 if not (a==0 or b==0 or c==0): res.min=p1 # 真ん中凹を作る (a,b,c,x,y,z)=abcxyz[i] if a==c: p2+=min(x,z) a-=1 if b>=min(a,c): p2+=(b-min(a,c)+1)*y b=min(a,c)-1 if not (a==0 or b==0 or c==0): res.min=p1 res.min=p2 echo res solve()