hack:
Input
4 997 996 99971 99970 99989 99988 99991 99990
Output
996511537693437612
https://www.luogu.com.cn/article/14903gl2
https://www.luogu.com.cn/article/yvu5dz09