DescriptionInputOutputSample Input3 1 2 3 2 4 2 Sample Output6Hint 1<=N<=10,0<=Qi<=10^18,1<=Pi<=10^18,P>=2 本题仅四组数据。SourceBy Jc