you give integer array b b_i neq 0 b_i leq 109 Array sort nondecrease orderthe cost subarray alr define followsIf sumlimits_j lr b_j neq 0 cost definedotherwise Construct bipartite flow graph rl1 vertex label l r vertex have b_i lt 0 left b_i gt 0 right for j l le j le r b_i0 b_j0 draw edge j infinite capacity cost unit flow a_ia_j add vertex source s sink t for l le le r b_i0 add edge S cost 0 capacity b_i for l le le r b_i0 add edge T cost 0 capacity b_i the cost subarray define minimum cost maximum flow S TYou give q query form integer l r you compute cost subarray alr query modulo 109 7If do not know minimum cost maximum flow mean read