using System.Linq; using System.Collections.Generic; using static System.Math; using System; public class Hello { static void Main() { var n = int.Parse(Console.ReadLine().Trim()); string[] line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, int.Parse); getAns(n, a); } static void getAns(int n, int[] a) { var b0 = new List(); var b1 = new List(); for (int i = 0; i < n; i++) { if (a[i] == 0) b0.Add(i); else { for (int j = 0; j < a[i] - 1; j++) b1.Add(i); } } var bL = b0.Count(); var count = 0L; for (int i = 0; i < bL; i++) count += Abs(b0[i] - b1[i]); Console.WriteLine(count); } }