using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; namespace No694_1 { public class Program { void Solve(StreamScanner ss, StreamWriter sw) { //--------------------------------- var N = ss.Next(int.Parse); var A = Compress(ss.Next(long.Parse, N)); var cs = new Dictionary(); foreach (var tup in A.OrderBy(x => x).Select((a, i) => (a, i))) { var (a, i) = (tup.Item1, tup.Item2); if (cs.ContainsKey(a)) cs[a]--; else cs.Add(a, N - 2 * i - 1); } var bit = new BinaryIndexedTree(N); var cross = 0L; foreach (var tup in A.Select((a, i) => (a, i))) { var (a, i) = (tup.Item1, tup.Item2); cross += i - bit.Sum(a); bit.Add(a, 1); } var sb = new StringBuilder(); sb.AppendLine(cross.ToString()); foreach (var a in A.Take(N - 1)) sb.AppendLine((cross += cs[a]).ToString()); sw.WriteLine(sb); //--------------------------------- } IEnumerable Compress(IEnumerable source) { var comp = source .Distinct() .OrderBy(x => x) .Select((k, v) => new {k, v}) .ToDictionary(kvp => kvp.k, kvp => kvp.v); return source.Select(x => comp[x] + 1); } static void Main() { var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput())); var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; new Program().Solve(ss, sw); sw.Flush(); } static readonly Func String = s => s; } public class BinaryIndexedTree { readonly int _size; readonly long[] _bit; public BinaryIndexedTree(int size) { _size = size; _bit = new long[_size + 1]; } public void Add(int x, int w) { for (var i = x; i <= _size; i += i & -i) _bit[i] += w; } public long Sum(int x) { var ret = 0L; for (var i = x; i >= 1; i -= i & -i) ret += _bit[i]; return ret; } } public class StreamScanner { static readonly char[] Sep = { ' ' }; readonly Queue buffer = new Queue(); readonly TextReader textReader; public StreamScanner(TextReader textReader) { this.textReader = textReader; } public T Next(Func parser) { if (buffer.Count != 0) return parser(buffer.Dequeue()); var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries); foreach (var nextString in nextStrings) buffer.Enqueue(nextString); return Next(parser); } public T[] Next(Func parser, int x) { var ret = new T[x]; for (var i = 0; i < x; ++i) ret[i] = Next(parser); return ret; } public T[][] Next(Func parser, int x, int y) { var ret = new T[y][]; for (var i = 0; i < y; ++i) ret[i] = Next(parser, x); return ret; } } }