func_code_string: #include <bits/stdc++.h>   using namespace std;   template <class T>   inline void smax(T &x, T y) {     x = max((x), (y));   }   template <class T>   inline void smin(T &x, T y) {     x = min((x), (y));   }   inline void scanInt(int &x) {     register char c = getchar();     x = 0;     bool neg = false;     while (c < 48 || c > 57) {       if (c ==  - ) neg = true;       c = getchar();     }     for (; c > 47 && c < 58; c = getchar()) {       x = (x << 1) + (x << 3) + c - 48;     }     if (neg) x *= -1;   }   int n, m;   string origin;   string s;   bool place_char_start(int inx) {     if (inx >= 2) {       for (char i = s[inx] + 1; i <  a  + m; i++)         if (i != s[inx - 1] && i != s[inx - 2] && i != s[inx]) {           s[inx] = i;           return true;         }       return false;     } else if (inx == 1) {       for (char i = s[inx] + 1; i <  a  + m; i++)         if (i != s[inx - 1] && i != s[inx]) {           s[inx] = i;           return true;         }       return false;     } else if (inx == 0) {       s[0] = s[0] + 1;       if (s[0] >=  a  + m) return false;       return true;     }     return false;   }   bool place_char(int inx) {     if (inx >= 2) {       for (char i =  a ; i <  a  + m; i++)         if (i != s[inx - 1] && i != s[inx - 2]) {           s[inx] = i;           return true;         }       return false;     } else if (inx == 1) {       for (char i =  a ; i <  a  + m; i++)         if (i != s[inx - 1]) {           s[inx] = i;           return true;         }     } else if (inx == 0) {       s[0] =  a ;       return true;     }     return false;   }   int main(int argc, const char *argv[]) {     scanInt(n);     scanInt(m);     cin >> s;     origin = s;     for (int i = (int)s.size() - 1; i >= 0; i--) {       s = origin;       bool ok = true;       ok &= place_char_start(i);       for (int j = i + 1; ok && j < s.size(); j++) {         if (place_char(j) == false) ok = false;       }       if (ok) {         cout << s;         return 0;       }     }     cout <<  NO ;     return 0;   }   