#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& second) { return '"' + second + '"'; }
string to_string(char c) {
  string second;
  second += c;
  return second;
}
string to_string(const char* second) { return to_string((string)second); }
string to_string(bool b) { return (b ? "1" : "0"); }
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (long long i = 0; i < static_cast<long long>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << "\n"; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
void Clearing_out() { return; }
template <typename Head, typename... Tail>
void Clearing_out(Head& H, Tail&... T) {
  H.clear();
  Clearing_out(T...);
}
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
void time() {
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
void hi() {
  static long long i = 0;
  cerr << "Check Point : " << ++i << "\n";
  return;
}
long long stoi1(string str) {
  bool negative;
  if (str[0] == '-') {
    negative = true;
    str = str.substr(1);
  } else {
    negative = false;
  }
  long long n = str.length();
  long long number = 0;
  long long pos = 1;
  for (long long i = n - 1; i >= 0; i--) {
    number = number + (str[i] - '0') * pos;
    pos = pos * 10;
  }
  if (negative) number = -number;
  return number;
}
long long power(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n % 2 != 0) {
      res = res * a;
      n--;
    } else if (n % 2 == 0) {
      a = a * a;
      n = n / 2;
    }
  }
  return res;
}
pair<long long, long long> min(vector<long long> v, bool first = true) {
  bool last = !first;
  long long mini = 1000000000000000007;
  long long mini_index = -1;
  long long n = (long long)v.size();
  for (long long i = 0; i < n; i++) {
    if ((mini > v[i] && first) || (mini >= v[i] && last)) {
      mini = v[i];
      mini_index = i;
    }
  }
  return {mini_index, mini};
}
pair<long long, long long> max(vector<long long> v, bool first = true) {
  bool last = !first;
  long long maxi = -1000000000000000007;
  long long maxi_index = -1;
  long long n = (long long)v.size();
  for (long long i = 0; i < n; i++) {
    if ((maxi < v[i] && first) || (maxi <= v[i] && last)) {
      maxi = v[i];
      maxi_index = i;
    }
  }
  return {maxi_index, maxi};
}
long long sum(vector<long long> v, long long start = 0, long long last = -1) {
  if (last == -1) last = (long long)v.size() - 1;
  long long ans = 0;
  for (long long i = start; i <= last; i++) {
    ans = ans + v[i];
  }
  return ans;
}
long long len(vector<long long> v) { return (long long)v.size(); }
long long rand(long long a, long long b) { return a + rand() % (b - a + 1); }
vector<long long> generate_random_vector() {
  vector<long long> v;
  long long n = rand(10, 20);
  set<long long> used;
  for (long long i = 0; i < n; ++i) {
    long long x;
    do {
      x = rand(10, 1000);
    } while (used.count(x));
    v.push_back(x);
    used.insert(x);
  }
  return v;
}
const long long max_size = 1e6 + 10000;
const double eps = 1e-18;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  t = 1;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> v(n);
    for (long long i = 0; i < n; i++) {
      cin >> v[i];
    }
    vector<vector<long long>> v1(n);
    long long new_index = 0;
    v1[new_index].push_back(v[0]);
    new_index++;
    vector<long long> v_back;
    v_back.push_back(-v[0]);
    for (long long i = 1; i < n; i++) {
      long long index =
          lower_bound(v_back.begin(), v_back.end(), -v[i]) - v_back.begin();
      if (index == (long long)v_back.size()) {
        v1[new_index].push_back(v[i]);
        v_back.push_back(-v[i]);
        new_index++;
        continue;
      } else {
        v1[index].push_back(v[i]);
        v_back[index] = -v[i];
      }
    }
    for (auto x : v1) {
      if (x.size() == 0) continue;
      for (auto y : x) {
        cout << y << " ";
      }
      cout << "\n";
    }
  }
  time();
  return 0;
}
