// Arup Guha
// 3/28/2019
// Solution to 2019 USACO January Gold Problem: Sleepy Cow Sorting

import java.io.*;
import java.util.*;

public class sleepy {
	
	public static void main(String[] args) throws Exception {
		
		// Get array.
		BufferedReader stdin = new BufferedReader(new FileReader("sleepy.in"));
		int n = Integer.parseInt(stdin.readLine().trim());
		int[] arr = new int[n];
		StringTokenizer tok = new StringTokenizer(stdin.readLine());
		for (int i=0; i<n; i++) arr[i] = Integer.parseInt(tok.nextToken());
		
		// Find last inversion of consecutive elements.
		int res = 0;
		for (int i=0; i<n-1; i++)
			if (arr[i] > arr[i+1])
				res = i+1;
			
		// Build bit with values after last inversion.
		bit mybit = new bit(n);
		for (int i=res; i<n; i++) mybit.add(arr[i], 1);
		
		// Stores moves here.
		StringBuilder sb = new StringBuilder();
		
		// Build answers for moves.
		for (int i=0; i<res; i++) {
			
			// Moves to get past "out of order" items.
			int moves = res-i-1;
			
			// Add in moves past ascending items at end of array.
			moves += mybit.sum(arr[i]);
			
			// Add this result.
			if (i > 0) sb.append(" ");
			sb.append(moves);
			
			// Now add this item to my bit as it's in the ascending list now.
			mybit.add(arr[i], 1);
		}
		
		// Ta da!
		PrintWriter out = new PrintWriter(new FileWriter("sleepy.out"));
		out.println(res);
		out.println(sb);
		out.close();
		stdin.close();
	}

}

class bit {
	
	public int n;
	public int[] vals;
	
	public bit(int orign) {
		
		// Set i to be the first power of 2 >= n+1.
		n = 1;
		while (n < orign+1) n <<= 1;
		
		// Alloc space.
		vals = new int[n];
	}
	
	// Adds x to index idx of array.
	public void add(int idx, int x) {
		while (idx < n) {
			vals[idx] += x;
			idx += (idx&(-idx));
		}
	}
	
	// Returns sum of array[1..x]
	public int sum(int x) {
		int res = 0;
		while (x > 0) {
			res += vals[x];
			x -= (x&(-x));
		}
		return res;
	}
}