#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BUFFSIZE 3 /* >= 2 */
char *mygetline(FILE *fp) {
  static char inbuff[BUFFSIZE];
  char *outbuff_malloc, *tmpbuff;
  char *p, *r;
  int fEOL;
 
  if ((outbuff_malloc = malloc(1)) == NULL) {
    return NULL;
  }
  *outbuff_malloc = '\0';
  fEOL = 0;
  do {
    r = fgets(inbuff, BUFFSIZE, fp);
    if (r == NULL)
      break;
    for (p = inbuff; *p != '\0'; p++)
      ;
    if (*(p - 1) == '\n')
      fEOL = 1;
    if ((tmpbuff = realloc(outbuff_malloc, strlen(outbuff_malloc) + strlen(inbuff) + 1)) == NULL) {
      free(outbuff_malloc);
      return NULL;
    }
    strcat(tmpbuff, inbuff);
    outbuff_malloc = tmpbuff;
  } while (!fEOL);
  if (strlen(outbuff_malloc) > 0) {
    char c;
    for (p = outbuff_malloc; *p != '\0'; p++)
      ;
    while ((c = *(--p)) == '\n' || c == '\r')
      *p = '\0';
    return outbuff_malloc;
  }
  free(outbuff_malloc);
  return NULL;
}

int main() {
  char *p;
  while ((p = mygetline(stdin)) != 0) {
    printf("%s\n", p);
    free(p);
  }
  return 0;
}
/* end */
