#include <iostream>
#include <algorithm>
#include <array>
#include <streambuf>
#include <cassert>

namespace GrosserWerner {
  template< unsigned N, unsigned Reserve = 0 >
  class BufferN : public std::streambuf
  {
  public:
    BufferN( std::streambuf* src )
      : src_( src )
      , p0_( 0 )
    {
      setg( buf_, buf_, buf_ );
    }
  protected:
    virtual int_type underflow() override
    {
      assert( gptr() != 0 ); // garantiert der Konstruktor
      assert( gptr() == egptr() ); // ...sollte der Aufrufer garantieren
      const int_type m = src_->sbumpc();
      if( traits_type::eq_int_type( m, traits_type::eof() ) )
        return traits_type::eof();
      if( egptr() == end() )
        {
          traits_type::move( buf_, buf_+(Reserve+1), N-1 );
          setg( buf_, buf_+(N-1), buf_+N );
          p0_ += Reserve+1;
        }
      else
        {
          setg( buf_, egptr(), egptr()+1 );
        }
      *gptr() = traits_type::to_char_type( m );
      return m;
    }
 
    virtual pos_type seekoff( off_type off, std::ios_base::seekdir way, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out) override
    {
      if( which != std::ios_base::in ) // nur input-Zeiger setzen erlaubt
        return pos_type( off_type(-1) );
      off_type local_off; // zeigt in den lokalen 'buf_'
      switch( way )
        {
        case std::ios_base::beg:
          local_off = off_type( off - p0_ );
          break;
 
        case std::ios_base::cur:
          local_off = off + (gptr() - eback());
          break;
 
        case std::ios_base::end: // not implemented
        default:
          return pos_type( off_type(-1) );
        }
      if( local_off < 0 || local_off > off_type(egptr() - eback()) )
        return pos_type( off_type(-1) ); // Fehler: local_off zeigt außerhalb der pending sequence
      setg( buf_, buf_+local_off, egptr() );
      return p0_ + local_off;
    }
    virtual pos_type seekpos( pos_type sp, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out ) override
    {
      return seekoff( off_type(sp - (p0_ + off_type(gptr() - eback()))), std::ios_base::cur, which );
    }
 
  private:
    const char_type* end() const { return buf_ + sizeof(buf_)/sizeof(*buf_); }
    std::streambuf* src_;
    char_type buf_[N+Reserve];
    pos_type p0_;
  };

  void parse1(std::istream& in, std::ostream& out)
  {
    out << "Format 1\n";
    std::istreambuf_iterator<char> i(in), j;
    std::copy(i, j, std::ostreambuf_iterator<char>(out));
  }

  void parse2(std::istream& in, std::ostream& out)
  {
    out << "Format 2\n";
    std::istreambuf_iterator<char> i(in), j;
    std::copy(i, j, std::ostreambuf_iterator<char>(out));
  }

  void parse(std::istream& in, std::ostream& out)
  {
    BufferN< 64, 1 > sb( in.rdbuf() );
    //           ^- don't override the first character
    in.rdbuf( &sb );
    std::istreambuf_iterator< char > it( in );
    int magic = 17;
    for (int i = 0; i < 64; ++i)
      magic = 13*magic + *it++;
    in.seekg( 0, std::ios_base::beg );
    if ( magic%2 )
      parse1( in, out );
    else
      parse2( in, out );
  }
}

namespace werni {
  void parse1(std::istreambuf_iterator<char> it, std::istreambuf_iterator<char> end,
              std::ostream& out, std::array<char, 64> const& arr)
  {
    out << "Format 1\n";
    std::ostreambuf_iterator<char> o(out);
    std::copy(arr.begin(), arr.end(), o);
    std::copy(++it, end, o);
  }

  void parse2(std::istreambuf_iterator<char> it, std::istreambuf_iterator<char> end,
              std::ostream& out, std::array<char, 64> const& arr)
  {
    out << "Format 2\n";
    std::ostreambuf_iterator<char> o(out);
    std::copy(arr.begin(), arr.end(), o);
    std::copy(++it, end, o);
  }

  void parse(std::istream& in, std::ostream& out)
  {
    std::istreambuf_iterator<char> it(in), end;
    std::array<char, 64> save;
    std::copy_n(it, 64, save.begin());
    int magic = 17;
    for (int i=0; i<64; ++i)
      magic = 13*magic + save[i];
    if (magic%2)
      parse1(it, end, out, save);
    else
      parse2(in, end, out, save);
  }
}

int main(int argc, char *argv[])
{
  std::ios_base::sync_with_stdio(false);
  if (argc != 2)
    std::cout << "usage: " << argv[0] << " [werni|Werner]";
  else if (std::string("werni") == argv[1])
    werni::parse(std::cin, std::cout);
  else
    GrosserWerner::parse(std::cin, std::cout);
}