n = int(raw_input())mat = [map(int,raw_input().split()) for i in range(n)]mat.sort(key=lambda x: x[1]-x[0])ans = 0for i in range(n): ans += mat[i][0]*i + mat[i][1]*(n-i-1)print ans
10 5 10 12 4 31 45 20 55 30 17 29 30 41 32 7 1 5 5 3 15
1423
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!