Donation
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n];
int b[] = new int[n];
long sum= 0;
int max = 0;
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
sum += a[i];
max = max<a[i]?a[i]:max ;
if (a[i]>=max){
b[i]=0;
}
else{
b[i]= max-a[i];
sum += b[i];
}
}
for(int i=0;i<n;i++){
System.out.print(b[i]+" ");
}
System.out.println();
System.out.print(sum);
}
}