#include <bits/stdc++.h>
#include<iostream>
using namespace std;


int main ()
{
    ios_base::sync_with_stdio(false);

    int n,brojac,red=0,pocetak=0,kraj=0;
    long long k;
    map<long long, vector<int>> mapa;
    long niz[100001];

    cin >> n >> k;

    brojac=n;

    for (int i=0;i<n*n;i++) cin >> niz[i];

    for (int i=0; i<n*n; i++)
    {
        if (i==brojac)
        {
            brojac+=n;
            pocetak=0;
            kraj=0;
            red++;
        }
        vector<int> v;
        v.push_back(pocetak);
        v.push_back(kraj);
        v.push_back(red);
        for (int j=i;j<brojac-1;j++)
        {
            if (niz[j]==niz[j+1]) v[1]=v[1]+1;
            else break;
        }
        pocetak++;
        kraj++;
        if (mapa.count(niz[i]) == 0) mapa[niz[i]]=v;
        else if (mapa[niz[i]][0]==v[0] && mapa[niz[i]][1]==v[1] && v[2]-mapa[niz[i]][2]==1) mapa[niz[i]][2]++;
        else mapa[niz[i]][2]=-1;

    }

        for(auto& pair : mapa )
        {
            cout << "key: " << pair.first << "  value: [  " ;
            for( int d : pair.second ) cout << d << "  " ;
            cout << "]\n" ;
        }

        return 0;
}