ashish tree consist n node number 1 n root node 1 the ith node tree cost a_i binary digit b_i write he want binary digit c_i write ith node endTo achieve perform follow operation number time Select k node subtree node u shuffle digits nod wish incur cost k cdot a_u here choose k range 1 size subtree u he want perform operation way node finally digit correspond targethelp find minimum total cost need spend operation node u digit c_u write determine impossible