#include <stdio.h>
#include <stdlib.h>

typedef struct tT {int zn; int kol; struct tT *left;struct tT *right;}TREE;

void Insert(TREE **root, int x)
  {
    TREE *newel;

  if (*root == NULL)
    {
      newel = (TREE*)malloc(sizeof(TREE));
      newel->zn = x;
	  newel->kol = 1;
      newel->left = newel->right = NULL;
	*root=newel;
    }
  else
    {
     if (x < (*root)->zn)
	Insert(&((*root)->left), x);
      else if (x > (*root)->zn)
	Insert(&((*root)->right), x);
			else ((*root)->kol)++;
    }
  }

  void Mas(TREE *root)
{
	if (root->left != NULL)
		Mas(root->left);
	printf("%d %d\n",root->zn,root->kol);
    if (root->right !=NULL)
		Mas(root->right);
	}

TREE* DestroyTreePlus(TREE *root)
  {

  if (root != NULL )
    {
		if (root->right != NULL)
	root->right = DestroyTreePlus(root->right);
		if (root->left != NULL)
	root->left = DestroyTreePlus(root->left);
      free(root);
    }

  return NULL;

  }


int main()
  {
   int n;
   TREE *mtree = NULL;

   scanf("%d",&n);
   while (n!=0)
    {
      Insert(&mtree, n);
      scanf("%d",&n);
    }
	Mas(mtree);
    if (mtree != NULL) mtree = DestroyTreePlus(mtree);

   return 0;
  }

