#include <iostream>
#include <string>

using namespace std;

class C1
    {
    public:
        C1( char c ) : c( c ) {}
        char c;
    };

class C2
    : public C1
    {
    public:
        C2( char c ) : C1( c ) {}
    };

static char c1( char heslo )
    {
    try
        {
        if( heslo > 'M' )
            throw C1( heslo );
        else
            throw C2( heslo );
        }
        catch( const C1& v )
            {
            return v.c + 2;
            }
        catch( const C2& v )
            {
            return v.c - 2;
            }
        catch( ... )
            {
            return 'X';
            }
    return 'Y';
    }

static char c2( char heslo )
    {
    try
        {
        try
            {
            if( heslo > 'R' )
                throw C1( heslo );
            else
                throw C2( heslo );
            }
            catch( C1 v )
                {
                throw v;
                }
            catch( ... )
                {
                return 'Y';
                }
        }
        catch( const C2& v )
            {
            return v.c;
            }
        catch( const C1& v )
            {
            return v.c - 1;
            }
    return 'X';
    }

static char c3( char heslo )
    {
    try
        {
        if( heslo > 'M' )
            throw C1( heslo );
        else
            throw C2( heslo );
        }
        catch( const C2& v )
            {
            return v.c + 1;
            }
        catch( const C1& v )
            {
            return v.c - 2;
            }
        catch( ... )
            {
            return 'A';
            }
    return 'B';
    }

static char d2( char heslo )
    {
    try
        {
        if( heslo > 'T' )
            throw heslo;
        }
        catch( char c )
            {
            throw;
            return c + 2;
            }
    return heslo;
    }

static string d1( string heslo )
    {
    string ret;
    try
        {
        ret += d2( heslo[ 0 ] );
        if( heslo[ 1 ] > 'H' )
            throw heslo[ 1 ];
        else
            ret += heslo[ 1 ];
        }
        catch( char c )
            {
            ret += c + 2;
            ret += heslo[ 1 ] + 2;
            }
        catch( ... )
            {
            ret += heslo[ 1 ] + 4;
            }
    return ret;
    }

class D
    {
    public:
        D( char* c ) : c( c ) {}
        ~D() { ++*c; }
    private:
        char* c;
    };

static char d3( char heslo )
    {
    char ret = heslo;
    try
        {
        D d( &ret );
        if( heslo < 'K' )
            throw 'F';
        }
        catch( char )
            {
            return ret + 2;
            }
    return ret;
    }

static char d4( char heslo )
    {
    char ret = heslo;
    try
        {
        D d( &ret );
        if( heslo > 'F' )
            throw 'L';
        ret = heslo - 1;
        }
        catch( char )
            {
            return ret + 1;
            }
    return ret;
    }

static char b1( char heslo )
    {
    try
        {
        if( heslo > 'R' )
            throw &heslo;
        }
        catch( void* )
            {
            return heslo + 1;
            }
        catch( ... )
            {
            return heslo - 1;
            }
    return heslo;
    }

static char b2( char heslo )
    {
    try
        {
        if( heslo < 'R' )
            {
            char c = 'F';
            throw &c;
            }
        }
        catch( signed char* c )
            {
            return *c - 2;
            }
        catch( unsigned char* c )
            {
            return *c + 2;
            }
        catch( ... )
            {
            return heslo + 1;
            }
    return heslo;
    }

static string over_heslo( const string& heslo )
    {
    string ret;
    if( b1( heslo[ 0 ] ) < 'D' )
        ret += b1( heslo[ 1 ] );
    else
        ret += b2( heslo[ 1 ] );
    ret += c1( heslo[ 0 ] );
    if( c2( heslo[ 0 ] ) > 'F' )
        ret += c1( heslo[ 2 ] );
    else
        ret += c2( heslo[ 2 ] );
    ret += c3( heslo[ 3 ] );
    ret += c3( heslo[ 4 ] );
    if( heslo[ 5 ] > 'T' )
        ret += d3( heslo[ 6 ] );
    else
        ret += d4( heslo[ 6 ] );
    if( ret[ 5 ] > 'R' )
        ret += d4( heslo[ 5 ] );
    else
        ret += d3( heslo[ 5 ] );
    ret += d1( heslo.substr( 7, 2 )) + d1( heslo.substr( 9, 2 ));
    return ret;
    }

int main()
    {
    string heslo = "XXXXXXXXXXX";
    string vysledek = over_heslo( heslo );
    if( vysledek == "QUCRJQKWUTKK" )
        cout << "Heslo v poradku" << endl;
    else
        cout << "Heslo nesouhlasi:" << vysledek << endl;
    }

