10 5 1000000000
1 1 1 2 2 1 2 2 2 2
 5 3 3
1 2 2 1 1
 2 4 1
1 1
 1 1000000000 1000000000
100000
 5 3 2
1 1 2 1 1
 5 2 4
1 2 3 2 1
 1 10 10
1

10000000000
 0
 2
 0
 7
 0
 0

#include <bits/stdc++.h>
using namespace std;
pair<int, int> *arr = new pair<int, int>[100001];
long long county(int left, int n, int k, int m) {
  if (arr[left].first == arr[n - 1 - left].first) {
    if (left == n - 1 - left) {
      return m * arr[left].second % k;
    }
    if (arr[left].second + arr[n - 1 - left].second == k) {
      long long result = k + county(left + 1, n, k, m);
      if (result == k)
        return 0;
      else
        return result;
    }
    if (arr[left].second + arr[n - 1 - left].second > k) {
      long long sum = 0;
      for (int i = left + 1; i <= n - 2 - left; i++) {
        sum += arr[i].second;
      }
      return m * sum + arr[left].second + arr[n - 1 - left].second +
             (m - 1) * ((arr[left].second + arr[n - 1 - left].second) % k);
    }
  } else {
    long long sum = 0;
    for (int i = left; i <= n - 1 - left; i++) {
      sum += arr[i].second;
    }
    return sum * m;
  }
}
int main() {
  int n, k, m;
  cin >> n;
  cin >> k;
  cin >> m;
  int count = 0;
  for (int i = 0; i < n; i++) {
    int number;
    cin >> number;
    if (i == 0) {
      arr[count] = make_pair(number, 1);
      continue;
    }
    if (number == arr[count].first) {
      arr[count].second++;
      if (arr[count].second == k) {
        if (count == 0) {
          arr[count].second = 0;
        } else
          count--;
      }
    } else {
      count++;
      arr[count] = make_pair(number, 1);
    }
  }
  if (count == 0) {
    if (arr[count].second == 0) {
      cout << 0;
      return 0;
    }
  }
  cout << county(0, count + 1, k, m);
  for (int i = 0; i <= count; i++) {
    cout << arr[i].first << " " << arr[i].second << endl;
  }
  return 0;
}
