static class LineBuf {
  new StringBuffer buf;
  
  void append(String s) {
    buf.append(s);
  }
  
  String nextLine() {
    int i = buf.indexOf("\n");
    if (i >= 0) {
      String s = buf.substring(0, i > 0 && buf.charAt(i-1) == '\r' ? i-1 : i);
      buf.delete(0, i+1);
      return s;
    }
    return null;
  }
}