public void solve() throws IOException {
    int n = nextInt();
    
    int[] vals = new int[2 * n];
    for (int x = 0; x < n; x++) {
      int val = nextInt();
      vals[val]++;
    }
    
    int moves = 0;
    for (int x = 1; x < 2 * n; x++) {
      if (vals[x] > 1) {
        int diff = vals[x] - 1;
        vals[x + 1] += diff;
        moves += diff;
      }
    }
    System.out.println(moves);
  }