#include <bits/stdc++.h>
using namespace std;
int len7, len4, cnt7[1000000], cnt4[1000000];
char second[10000000];
void print() {
  for (int i = 0; i < len4; ++i) putchar('4');
  for (int i = 0; i < len7; ++i) putchar('7');
  exit(0);
}
int main() {
  gets(second);
  int len = strlen(second);
  len7 = (len + 1) / 2;
  len4 = (len + 1) / 2;
  if (len % 2 == 1) print();
  for (int i = len - 1; i >= 0; i--) {
    if (second[i] == '7')
      cnt7[i] = cnt7[i + 1] + 1;
    else
      cnt7[i] = 0;
    if (second[i] == '4')
      cnt4[i] = cnt4[i + 1] + 1;
    else
      cnt4[i] = 0;
  }
  for (int i = 0; i < len; ++i) {
    if (second[i] < '4') {
      for (int j = 0; j < i; ++j) putchar(second[j]);
      print();
    }
    if (second[i] == '4') {
      if (cnt7[i + 1] > len7) {
        for (int j = 0; j < i; ++j) putchar(second[j]);
        putchar('7');
        len7--;
        print();
      } else if (cnt7[i + 1] == len7) {
        int pos = i + 1 + cnt7[i + 1];
        if (second[cnt4[pos] + pos] < '4')
          ;
        else {
          for (int j = 0; j < i; ++j) putchar(second[j]);
          putchar('7');
          len7--;
          print();
        }
      } else if (second[i + 1 + cnt7[i + 1]] < '7')
        ;
      else {
        for (int j = 0; j < i; ++j) putchar(second[j]);
        putchar('7');
        len7--;
        print();
      }
      len4--;
    } else if (second[i] < '7') {
      for (int j = 0; j < i; ++j) putchar(second[j]);
      putchar('7');
      len7--;
      print();
    } else if (second[i] == '7') {
      if (cnt7[i] > len7) {
        len4 = len / 2 + 1;
        len7 = len / 2 + 1;
        print();
      } else if (cnt7[i] == len7) {
        int pos = i + cnt7[i];
        if (second[cnt4[pos] + pos] < '4')
          ;
        else {
          len4 = len / 2 + 1;
          len7 = len / 2 + 1;
          print();
        }
      } else if (second[i + cnt7[i]] < '7')
        ;
      else {
        len4 = len / 2 + 1;
        len7 = len / 2 + 1;
        print();
      }
      len7--;
    } else {
      len4 = len / 2 + 1;
      len7 = len / 2 + 1;
      print();
    }
  }
  puts(second);
  return 0;
}
