1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int get_zgrzyty_count(vector<int> grom, int zolniez, int distance[])
{
  int count = 0;
  for (int t = 0; t < grom.size(); t++) {
    int a = grom[t];
    int b = zolniez;
    if (a==b) continue;
    if(((a < b) && (distance[a-1] > distance[b-1]))) count++;

    a = zolniez;
    b = grom[t];
    if(((a < b) && (distance[a-1] > distance[b-1]))) count++;

    // cout << "A: " << a << ", B: " << b << endl;
    // cout << "DISTANCE1: " << distance[a-1] << ", DISTANCE2: " << distance[b-1] << endl;
    // cout << count << endl;
  }
  return count;
}

int count_all_zgrzyty(vector<vector<int>> squads, int distance[])
{
  int count = 0;
  for(int i = 0; i < 1; i++)
  {
    for (int j = 0; j < squads[i].size(); j++)
    {
      for(int k = 0; k < squads[i].size(); k++)
      {
        int a = squads[i][j];
        int b = squads[i][k];
        if (a==b) continue;
        if(((a < b) && (distance[a-1] > distance[b-1]))) count++;
      }
    }
  }
  return count;
}

int main()
{
  int n;
  cin >> n;

  // main input
  int dystans[n];
  int dystans_to_i[n];
  for(int i = 0; i < n; ++i){
    cin >> dystans[i];
  }


  struct bajtogrom{
    vector<vector< int> > squads;
    int zgrzyty = 0;
  };

  vector<bajtogrom> all_squads(n); // N ilość bajtogromów

  // dla pierwszego składu
  for(int d = 1; d <= n; d++) all_squads[0].squads.push_back(vector<int> (1, d));

  for(int x = 1; x < n; ++x)
  {
    vector<int> new_squad;
    vector<vector< int> > new_squads;
    vector<vector< int> > prev_squads;
    prev_squads = all_squads[x-1].squads;

    int zgrzyty = all_squads[x-1].zgrzyty;
    while(new_squads.size() <= 0)
    {
      for (int sq = 0; sq < prev_squads.size(); sq++)
      {
        for(int new_element = 1; new_element <= n; new_element++)
        {

          bool any = false;
          for (int p = 0; p < prev_squads[sq].size(); p++)
            if (new_element == prev_squads[sq][p]) any = true;

          if(!any && get_zgrzyty_count(prev_squads[sq], new_element, dystans) <= zgrzyty)
          {
            new_squad = prev_squads[sq];
            new_squad.push_back(new_element);
            sort(new_squad.begin(), new_squad.end());

            new_squads.push_back(new_squad);
            for(int c = 0; c < new_squads.size(); c++)
              for(int d = 0; d < new_squads.size(); d++)
              {
                if(c == d) continue;
                if(new_squads[c] == new_squads[d])
                {
                  new_squads.erase(new_squads.begin() + d);
                }
              }
            // cout << "Nowe: " << new_element << endl;
            // cout << "Zgrzyty" << zgrzyty << endl;
          }
        }
      }
      if(new_squads.size() == 0) zgrzyty++;
    }
    all_squads[x].squads = new_squads;
    all_squads[x].zgrzyty = zgrzyty;
  }

  // for (int i = 0; i < 5; i++) {
  //   cout << "ASDD: " << all_squads[0].squads[i][0] << endl;
  // }
  // for (int i = 0; i < 3; i++)
  // {
  //   cout << "ASDD: " << all_squads[1].squads[i][0] << " " << all_squads[1].squads[i][1] << endl;
  // }
  //
  // for (int i = 0; i < 2; i++)
  // {
  //   cout << "ASDD: " << all_squads[2].squads[i][0] << " " << all_squads[2].squads[i][1] << " " << all_squads[2].squads[i][2] << endl;
  // }


  for(int i = 0; i < n; i++)
    cout << count_all_zgrzyty(all_squads[i].squads, dystans) << " " << all_squads[i].squads.size() << endl;

  return 0;
}