Without loss of generality, let a1≤a2≤⋯≤a2023. Then, note that ak+1−ak=∑i=12023∣ak+1−ai∣−∣ak−ai∣=k(ak+1−ak)−(2023−k)(ak+1−ak)=(2k−2023)(ak+1−ak). Thus, ak+1=ak unless k=1012, so a1=a2=⋯=a1012 and a1013=⋯=a2023, and we can check that that they must be in a ratio of 1011:1012. Thus, a1,…,a2023 must consist of 1012 copies of 1011c, and 1011 copies of 1012c for some c, so for everything to be a positive integer, we need c≥1. This gives us the final answer of 1011⋅1012+1012⋅1011=2046264.