#include <iostream>
#include <string>

using namespace std;

int main() {
    int N;
    cin >> N;

    string s = "1"; 

    while (true) {
        bool ok = true;
        int len = s.length();
        for (int i = 1; i <= len / 2; i++) {
            if (s.substr(len - i, i) == s.substr(len - 2 * i, i)) {
                ok = false; 
                break;
            }
        }

        if (ok == true) {
            if (len == N) {
                cout << s << "\n";
                break;
            }
            s = s + "1";
        } 
        else {
            while (s.length() > 0) {
                char last = s.back(); 
                s.pop_back();         
                if (last == '1') {
                    s = s + "2";
                    break;
                } 
                else if (last == '2') {
                    s = s + "3";
                    break;
                }
            }
        }
    }

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: