Language: C++

#include <algorithm>
#define TRY(n) try{n}catch(...){}
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(n) n.begin(),n.end()
using namespace std;

int main(){
    int n;string s,t;cin>>n>>s>>t;
    string o = "";
    bool f = false;
    bool l = false;
    if(s == t){cout << n << endl;return 0;}
    vector<int> g;
    rep(i,n){
        if(s[i] == t[0]){
            for(int j=i;j<n;j++){
                if(s[j] != t[(n-1)-j]){f = !f;break;}
            }
            if(f){
                rep(k,n){
                    if(k == i)break;
                    o+=s[k];
                }
                rep(k,n)o+=t[k];
                g.push_back(o.size());
                l = true;
                f = !f;
            }
            else f = !f;
        }
    }
    if(l){
        sort(all(g));
        cout << g[0] << endl;
    }else{cout << s.size() + t.size() << endl;}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:11: error: 'string' was not declared in this scope
    8 |     int n;string s,t;cin>>n>>s>>t;
      |           ^~~~~~
a.cc:2:1: note: 'std::string' is defined in header '<string>'; this is probably fixable by adding '#include <string>'
    1 | #include <algorithm>
  +++ |+#include <string>
    2 | #define TRY(n) try{n}catch(...){}
a.cc:8:22: error: 'cin' was not declared in this scope
    8 |     int n;string s,t;cin>>n>>s>>t;
      |                      ^~~
a.cc:2:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    1 | #include <algorithm>
  +++ |+#include <iostream>
    2 | #define TRY(n) try{n}catch(...){}
a.cc:8:30: error: 's' was not declared in this scope
    8 |     int n;string s,t;cin>>n>>s>>t;
      |                              ^
a.cc:8:33: error: 't' was not declared in this scope
    8 |     int n;string s,t;cin>>n>>s>>t;
      |                                 ^
a.cc:9:11: error: expected ';' before 'o'
    9 |     string o = "";
      |           ^~
      |           ;
a.cc:12:16: error: 'cout' was not declared in this scope
   12 |     if(s == t){cout << n << endl;return 0;}
      |                ^~~~
a.cc:12:16: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:12:29: error: 'endl' was not declared in this scope
   12 |     if(s == t){cout << n << endl;return 0;}
      |                             ^~~~
a.cc:2:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    1 | #include <algorithm>
  +++ |+#include <ostream>
    2 | #define TRY(n) try{n}catch(...){}
a.cc:13:5: error: 'vector' was not declared in this scope
   13 |     vector<int> g;
      |     ^~~~~~
a.cc:2:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    1 | #include <algorithm>
  +++ |+#include <vector>
    2 | #define TRY(n) try{n}catch(...){}
a.cc:13:12: error: expected primary-expression before 'int'
   13 |     vector<int> g;
      |            ^~~
a.cc:22:21: error: 'o' was not declared in this scope
   22 |                     o+=s[k];
      |                     ^
a.cc:24:25: error: 'o' was not declared in this scope
   24 |                 rep(k,n)o+=t[k];
      |                         ^
a.cc:25:17: error: 'g' was not declared in this scope
   25 |                 g.push_back(o.size());
      |                 ^
a.cc:25:29: error: 'o' was not declared in this scope
   25 |                 g.push_back(o.size());
      |                             ^
a.cc:33:18: error: 'g' was not declared in this scope
   33 |         sort(all(g));
      |                  ^
a.cc:4:16: note: in definition of macro 'all'
    4 | #define all(n) n.begin(),n.end()
      |                ^
a.cc:34:9: error: 'cout' was not declared in this scope
   34 |         cout << g[0] << endl;
      |         ^~~~
a.cc:34:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:34:25: error: 'endl' was not declared in this scope
   34 |         cout << g[0] << endl;
      |                         ^~~~
a.cc:34:25: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:35:11: error: 'cout' was not declared in this scope
   35 |     }else{cout << s.size() + t.size() << endl;}
      |           ^~~~
a.cc:35:11: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:35:42: error: 'endl' was not declared in this scope
   35 |     }else{cout << s.size() + t.size() << endl;}
      |                                          ^~~~
a.cc:35:42: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'