#include <stdio.h>

class Meters {
 public:
  int odom;
  int trip;
  Meters(int od, int tr) {
    odom = od;
    trip = tr;
  }
  Meters(Meters const& foo) {
    odom = foo.odom;
    trip = foo.trip;
  }
  bool all_ten() {
    bool has[10];
    for (int i=0; i<10; i++) has[i] = false;    
    int temp = odom;
    for (int i=0; i<6; i++) {
      int digit = temp % 10;
      if (has[digit]) return false;
      has[digit] = true;
      temp /= 10;
    }
    temp = trip;
    for (int i=0; i<4; i++) {
      int digit = temp % 10;
      if (has[digit]) return false;
      has[digit] = true;
      temp /= 10;
    }
    return true;
  }
  void operator++ () {
    odom++;
    trip++;
    odom %= 1000000;
    trip %= 10000;
  }
  void operator= (Meters const& foo) {
    odom = foo.odom;
    trip = foo.trip;
  }
  void operator-- () {
    odom--;
    trip--;
    if (odom == -1) odom = 999999;
    if (trip == -1) trip = 9999;
  }
  void modrev () {
    odom++;
    trip--;
    odom %= 1000000;
    if (trip == -1) trip = 9999;
  }
  int inc_until_all() {
    int times = 0;
    while (!all_ten()) {
      operator++();
      times++;
    }
    return times;
  }
  int dec_until_all() {
    int times = 0;
    while (!all_ten()) {
      operator--();
      times++;
    }
    return times;
  }
  int modrev_until_all() {
    int times = 0;
    while (!all_ten()) {
      modrev();
      times++;
    }
    return times;
  }
  int inc_until_all(int mx) {
    int times = 0;
    while (!all_ten()) {
      operator++();
      times++;
      if (times > mx) return mx+1;
    }
    return times;
  }
  int dec_until_all(int mx) {
    int times = 0;
    while (!all_ten()) {
      operator--();
      times++;
      if (times > mx) return mx+1;
    }
    return times;
  }
  int modrev_until_all(int mx) {
    int times = 0;
    while (!all_ten()) {
      modrev();
      times++;
      if (times > mx) return mx+1;
    }
    return times;
  }
  void print() {
    printf("%06d %04d\n", odom, trip);
  }
  void reset() {
    trip = 0;
  }
};

int main() {
  Meters d(123456, 1234);
  Meters m(d);

  int max = m.inc_until_all();
  printf("+%d ", max);
  m.print();

  m = d;
  int dmax = m.dec_until_all();
  printf("-%d ", dmax);
  m.print();

  m = d;
  dmax = m.modrev_until_all();
  printf("-m%d ", dmax);
  m.print();

  printf("\n");

  Meters best(d);
  int bestd = max + 10;
  for (int i=0; i< max + 10; i++) {
    m = d; 
    for (int j=0; j<i; j++) ++m;
    m.reset();
    int second = m.inc_until_all(bestd + 10);
    if (second + i <= bestd) {
      bestd = second + i;
      printf("d%d +%d r +%d ", bestd, i, second);
      m.print();
    }
  }

  printf("\n");

  best = d;
  bestd = max + 10;
  for (int i=0; i< max + 10; i++) {
    m = d; 
    for (int j=0; j<i; j++) ++m;
    m.reset();
    int second = m.dec_until_all(bestd + 10);
    if (second + i <= bestd) {
      bestd = second + i;
      printf("d%d +%d r -%d ", bestd, i, second);
      m.print();
    }
  }
  
  printf("\n");

  best = d;
  bestd = max + 10;
  for (int i=0; i< max + 10; i++) {
    m = d; 
    for (int j=0; j<i; j++) --m;
    m.reset();
    int second = m.inc_until_all(bestd + 10);
    if (second + i <= bestd) {
      bestd = second + i;
      printf("d%d -%d r +%d ", bestd, i, second);
      m.print();
    }
  }

  printf("\n");

  best = d;
  bestd = max + 10;
  for (int i=0; i< max + 10; i++) {
    m = d; 
    for (int j=0; j<i; j++) --m;
    m.reset();
    int second = m.dec_until_all(bestd + 10);
    if (second + i <= bestd) {
      bestd = second + i;
      printf("d%d -%d r -%d ", bestd, i, second);
      m.print();
    }
  }
  
}
