You have recently been selected for a government-funded graph distribution program run by the National Graph Resources Commission and received a functional graph with vertices. A functional graph is a directed graph in which every vertex has exactly one outgoing edge. Thus, your graph has the same number of vertices and edges.
However, it is common knowledge that preparing so many vertices only to give them the same number of edges is a waste of vertices. You therefore want to pack more edges into this graph. The National Graph Resources Commission also agreed that as many edges as possible should be added to demonstrate that the vertices in this taxpayer-funded graph are being put to good use, and commissioned you to carry out the work.
The Commission knows perfectly well that, without any restrictions, you would simply add a huge number of edges between vertices and and call it a day. It has therefore imposed the following rules:
Given the graph, find the maximum number of additional edges you can add.
The first line contains the number of vertices .
The second line contains integers separated by spaces. The -th integer means that there is an edge from vertex to vertex .
Print the maximum number of edges that can be added to the graph.