Problem:
壊れた暗号生成器
JAG (Japanese Alumni Group) は多くのプログラマで構成される謎の組織であり，この組織の本部がある建物に入るためには毎回ある機械によって生成される暗号文を解かなくてはならない．
この暗号文は，'
+
'，'
-
'，'
[
'，'
]
' の記号と大文字のアルファベットからなっており，以下の BNF で定義される <Cipher> によって表される．
<Cipher> ::= <String> | <Cipher><String>
<String> ::= <Letter> | '['<Cipher>']'
<Letter> ::= '+'<Letter> | '-'<Letter> |
             'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' |
             'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z'
ここでそれぞれの記号は以下のような意味を表す．
+(文字) : その文字の次のアルファベットを表す (ただし '
Z
' の次のアルファベットは '
A
' であるとする)
-(文字) : その文字の前のアルファベットを表す (ただし '
A
' の前のアルファベットは '
Z
' であるとする)
[(文字列)] : その文字列を左右反転した文字列を表す
しかしこの暗号文を生成する機械には現在故障が発生しており，暗号文のうちアルファベットの箇所が数文字壊れて読めなくなっている場合がある．読めない文字は仮に '
?
' と表されている．
調査の結果，壊れた文字の埋め方は，復号後の文字列が，復号後の文字列としてありえる文字列の中で辞書順最小になるようなものであることがわかった．
あなたの仕事はこの暗号文を正しく復号することである．
Input
入力は複数のデータセットから構成される．
各データセットは，上記の BNF で定義された暗号文において，一部の大文字のアルファベットが ‘?’ に置き換えられた文字列を含む 1 行からなる．
各文字列の長さは $80$ 以下であると仮定してよい．
また各データセットに含まれる '
?
' の数は $0$ 以上 $3$ 以下であると仮定してよい．
入力の終了は '
.
' の1文字だけを含む行で表される．
Output
各データセットに対して，復号後の文字列が辞書順最小になるように暗号文を復号したときの，復号後の文字列を出力せよ．
Sample Input
A+A++A
Z-Z--Z+-Z
[ESREVER]
J---?---J
++++++++A+++Z-----------A+++Z
[[++-+--?[--++-?++-+++L]][-+-----+-O]]++++---+L
.
Output for Sample Input
ABC
ZYXZ
REVERSE
JAG
ICPC
JAPAN

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define int long long

char pls(char c) {
  return c == 'Z' ? 'A' : c + 1;
}
char mns(char c) {
  return c == 'A' ? 'Z' : c - 1;
}
using Pt = string::const_iterator;
string expr1(string& s, Pt& pt);
char expr2(string& s, Pt& pt);
string expr1(string& s, Pt& pt) {
  string acc;
  while (1) {
    // cout << pt - s.begin() << endl;
    if (pt == s.end() || *pt == ']') return acc;
    if (*pt == '[') {
      string tmp = expr1(s, ++pt);
      pt++;
      reverse(tmp.begin(), tmp.end());
      acc += tmp;
    } else {
      acc += expr2(s, pt);
    }
  }
}
char expr2(string& s, Pt& pt) {
  if (*pt == '+') return pls(expr2(s, ++pt));
  if (*pt == '-') return mns(expr2(s, ++pt));
  return *(pt++);
}
string mi;
void search(string s) {
  bool no = true;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '?') {
      no = false;
      for (char c = 'A'; c <= 'Z'; c++) {
        s[i] = c;
        search(s);
      }
    }
  }
  if (no) {
    Pt pt = s.begin();
    string tmp = expr1(s, pt);
    if (tmp < mi) mi = tmp;
  }
}
void solve() {
  string s; cin >> s;
  if (s == ".") exit(0);
  mi = string('Z', 100);
  search(s);
  cout << mi << endl;
}
signed main() {
  while (1) solve();
}
accuracy: 1
time_ms: 130
memory_kb: 3444
final_rank: 1

code_snippet: // ===============================
// 
// Team : knowcow (ID : 1073313)
// 
// ===============================
#include <bits/stdc++.h>
using namespace std;

// kobaryo222 用のマクロ
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) std::begin(x), std::end(x)

using ll = long long;
using ull = unsigned long long;

// int でも ll でも使えるタイプの INF
constexpr const ll INF = (1LL << 62) - (3LL << 30) - 1;

using State = string::const_iterator;
struct Node{
    int lh{-1}, rh{-1};
    int lnot{0};
};
vector<Node> tree(100000);
int next_node = 0, root;
struct Parser{
    string s;
    State begin;

    Parser(string _s) : s(_s){
        begin = s.begin();
    }

    string Cipher(){
        string ret;
        while(*begin && *begin != ']'){
            ret.append(String());
        }
        return ret;
    }

    string String(){
        string ret;
        if(*begin == '['){
            consume('[');
            ret = Cipher();
            reverse(ret.begin(), ret.end());
            consume(']');
        }
        else{
            ret = string{Letter()};
        }
        return ret;
    }

    char Letter(){
        if(*begin == '+'){
            consume('+');
            return char((Letter() - 'A' + 1) % 26 + 'A');
        }
        if(*begin == '-'){
            consume('-');
            return char((Letter() - 'A' + 25) % 26 + 'A');    
        }
        return *begin++;
    }

    void consume(char expected){
        if(*begin == expected){
            ++begin;
        }
        else{
            cerr << "# Expected '" << expected << "' but got '" << *begin << "'\n";
            cerr << "# Rest string is '";
            while(*begin){
                cerr << *begin++;
            }
            cerr << "'\n";
            exit(0);
        }
    }
};

void solve(){
    while(1){
        // 入力処理と break 処理
        string s; cin >> s;
        if(s == ".") break;
        vector<int> idx(3, -1);
        for(int i = 0, j = 0; i < s.size(); ++i){
            if(s[i] == '?') idx[j++] = i;
        }
        string ans = "~";
        for(char a = 'A'; a <= 'Z'; ++a){
            if(idx[0] != -1) s[idx[0]] = char(a);
            for(char b = 'A'; b <= 'Z'; ++b){
                if(idx[1] != -1) s[idx[1]] = char(b);
                for(char c = 'A'; c <= 'Z'; ++c){
                    if(idx[2] != -1) s[idx[2]] = char(c);
                    Parser par(s);
                    string tmp = par.Cipher();
                    ans = min(ans, tmp);
                }
            }
        }
        cout << ans << endl;
    }
}

// ランダムテスト用
// int answer(int n){}
// int greedy(int n){}

int main(){
    // インタラクティブ問題ではコメントアウトする！
    cin.tie(0)->sync_with_stdio(false);
    cout << fixed << setprecision(10);
    solve();

    // ランダムテスト用
    // mt19937 mt;
    // for(int i = 0; i < 1000; ++i){
    //     int n = mt() % 10 + 1;
    //     auto ans_solver = answer(n);
    //     auto ans_greedy = greedy(n);
    //     if(ans_solver != ans_greedy){
    //         cout << "# solver = " << ans_solver << endl;
    //         cout << "# greedy = " << ans_greedy << endl;
    //         break;
    //     }
    // }
}
accuracy: 1
time_ms: 460
memory_kb: 4480
final_rank: 13

code_snippet: #ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
// #include <boost/rational.hpp>
// using namespace boost;
// using rat = rational<long long int>;
using mint = modint998244353;
// using mint = modint1000000007;
// using mint = mint;
using ll = long long;
using ld = long double;
using ull = uint64_t;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using vm = vector<mint>;
using vvm = vector<vm>;
using vvvm = vector<vvm>;
using vstr = vector<string>;
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
#define vvv(T) vector<vector<vector<T>>>
#define vvvv(T) vector<vector<vector<vector<T>>>>

istream &operator>>(istream &is, mint &a){ll tmp; is >> tmp; a = tmp; return is;}
ostream &operator<<(ostream &os, const mint &a){ os << a.val(); return os; }
string to_string(const __int128_t &a) { if (a == 0) return "0"; string s = ""; __int128_t num = a; bool is_negative = false; if (num < 0) { is_negative = true; num = -num; } while (num > 0) { s += '0' + (num % 10); num /= 10; } if (is_negative) s += '-'; reverse(s.begin(), s.end()); return s; }
istream &operator>>(istream &is, __int128_t &a){ string s; is >> s; a = 0; for(char c : s) { if(isdigit(c)) {a = a*10 + (c - '0'); }  } if(s[0]=='-'){ a *= -1; } return is; }
ostream &operator<<(ostream &os, const __int128_t &a){ os << to_string(a); return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<class T> istream &operator>>(istream &is, vector<T> &vec){ for(T &e : vec){is >> e;} return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &vec) { for(int i = 0; i < (int)vec.size(); i++) { os << vec[i] << (i + 1 != (int)vec.size() ? " " : ""); } return os; }

template <class... T> constexpr auto min (T... a) { return min(initializer_list<common_type_t<T...>>{a...}); }
template <class... T> constexpr auto max (T... a) { return max(initializer_list<common_type_t<T...>>{a...}); }
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template<class T> T opmin(T x, T y) { return min(x, y); }
template<class T> T einf() { return numeric_limits<T>::max(); }
template<class T> T opmax(T x, T y) { return max(x, y); }
template<class T> T eminf() { return numeric_limits<T>::min(); }
template<class T> T opsum(T x, T y) { return x + y; }
template<class T> T ezero() { return (T)0; }
// #define maxseg(T) segtree<T, [](T x, T y){return max(x, y);}, [](){return (T)(-(1LL << 60));}>
// #define minseg(T) segtree<T, [](T x, T y){return min(x, y);}, [](){return (T)((1LL << 60));}>
// #define sumseg(T) segtree<T, [](T x, T y){return x + y;}, [](){return (T)(0);}>
template<class T> using minseg = segtree<T, opmin<T>, einf<T>>;
template<class T> using maxseg = segtree<T, opmax<T>, eminf<T>>;
template<class T> using sumseg = segtree<T, opsum<T>, ezero<T>>;
// template<class T> struct v : vector<T> { using vector<T> :: vector; };
// template<class T> struct vv : vector<v<T>> { using vector<v<T>> :: vector; };
// template<class T> struct vvv : vector<vv<T>> { using vector<vv<T>> :: vector; };
template<class T> inline bool chmin(T& a, T b) {if(a > b){a = b; return true;} else {return false;}};
template<class T> inline bool chmax(T& a, T b) {if(a < b){a = b; return true;} else {return false;}};
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i,n) for(ll i = (ll)(n) - 1; i >= 0; i--)
#define REP(i, l, r) for(ll i = (ll)l; i <= (ll)(r); i++)
#define REPR(i, l, r) for(ll i = (ll)r; i >= (ll)(l); i--)
const ll inf = (1 << 30);
const ll INF = (1LL << 60);
const vector<pair<ll, ll>> DIJ = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}};
void out(){cout<<'\n';}
template<class T, class... Ts> void out(const T& a, const Ts&... b){ cout<<a; (cout<<... << (cout << ' ', b)); cout << '\n';}
void outf(){cout<<endl;}
template<class T, class... Ts> void outf(const T& a, const Ts&... b){ cout<<a; (cout<<... << (cout << ' ', b)); cout << endl;}
template<class T, class U> void outp(pair<T, U> a){ out((a).first, (a).second); }
template<class T, class U> void outpf(pair<T, U> a){ outf((a).first, (a).second); }
template<class T> void outv(T a){rep(i, (a).size()){ cout << (a)[i] << " "; } cout << endl;}
template<class T> void outvL(T a){rep(i, (a).size()){out((a)[i]);} cout << flush; }
// template<class T> void outvv(T a){rep(i, a.size()){ rep(j, a.at(i).size()){cout << a.at(i).at(j) << " "; } cout << endl; }}
// template<class T> void outvp(T a){rep(i, a.size()){ out2(a.at(i).first, a.at(i).second); }}
void setpre(int a){cout << fixed << setprecision(a);}
#define outN out("No")
#define outY out("Yes")
#define outYN(flag) out(flag ? "Yes" : "No")
#define dame(...) {outf(__VA_ARGS__);return 0;}

template<class T> void read(vector<T>& vec){ for(int i = 0; i < (int)vec.size(); i++) { cin >> vec[i]; } }
template<class... T> void read(T&... a){(cin >> ... >> a);}
#define readll(...) ll __VA_ARGS__; read(__VA_ARGS__)
#define readvll(a, n) vector<ll> a(n); read(a)
#define readvt(type, a, n) vector<type> a(n); read(a)
#define readvll2(a, b, n) vector<ll> a(n), b(n); for(int lopi = 0; lopi < (int)(n); lopi++) cin >> (a)[lopi] >> (b)[lopi]
#define readvll3(a, b, c, n) vector<ll> a(n), b(n), c(n); for(int lopi = 0; lopi < (int)(n); lopi++) cin >> (a)[lopi] >> (b)[lopi] >> (c)[lopi]
#define readstr(...) string __VA_ARGS__; read(__VA_ARGS__)
#define readundirG(G, N, M) G = vvll(N); rep(lopi, M) {ll a, b; cin >> a >> b; G[a-1].push_back(b-1); G[b-1].push_back(a-1);}
#define readdirG(G, N, M) G = vvll(N); rep(lopi, M) {ll a, b; cin >> a >> b; G[a-1].push_back(b-1);}
#define readundirwghG(G, N, M) G = vv(pll)(N); rep(lopi, M) {ll a, b, c; cin >> a >> b >> c; G[a-1].emplace_back(b-1,c); G[b-1].emplace_back(a-1, c);}
#define readdirwghG (G, N, M) G = vv(pll)(N); rep(lopi, M) {ll a, b, c; cin >> a >> b >> c; G[a-1].emplace_back(b-1, c);}

#define All(a) (a).begin(), (a).end()
template<class T> inline void sortr(T& a){ sort((a).rbegin(), (a).rend()); }
template<class T> inline vector<int> argsort(T V, bool rev = false){vector<int> res(V.size()); iota(res.begin(), res.end(), 0); sort(res.begin(), res.end(), [&](int x, int y){if(!rev){return V[x] < V[y];}else{return V[x] > V[y];}}); return res;}
template<class T, class U> inline void sort_by_idx(T& V, vector<U>& I){assert(V.size() == I.size()); T tmpv = V; for(int loopi = 0; loopi < (int)I.size(); loopi++){V[loopi] = tmpv[I.at(loopi)];}}
template<class T, class U> inline void sortp(vector<T>& v1, vector<U>& v2, bool rev1 = false, int rev2 = false){assert(v1.size() == v2.size()); vector<int> I(v1.size()); iota(I.begin(), I.end(), 0); sort(I.begin(), I.end(), [&](const int x, const int y){if(v1[x] != v1[y]){return (bool)(rev1 ^ (v1[x] < v1[y]));}else{if(v2[x]==v2[y]){return false;} return (bool)(rev2 ^ (v2[x] < v2[y]));}}); sort_by_idx(v1, I); sort_by_idx(v2, I);}
template<class T> T POW(T x, ll n) {T ret = 1; while(n > 0){if(n & 1) ret *= x; x *= x; n >>= 1;} return ret;}
ll powll(ll x, ll n){ll ret = 1; while(n > 0){if(n & 1) ret *= x; x *= x; n >>= 1;} return ret;}
inline ll divceil(ll x, ll y) { if(x >= 0) {return(x / y + (ll)(x % y != 0)); } else { return -((-x) / y); } }
inline ll divfloor(ll x, ll y) { if(x >= 0) { return x/y; } else { return -((-x)/y + (ll)((-x) % y != 0)); } }
inline bool inLR(ll x, ll L, ll R){ return (L <= x && x < R); }
inline bool inRect(ll pos_x, ll pos_y, ll rect_H, ll rect_W, ll rect_h = 0, ll rect_w = 0){ return (rect_h <= pos_x && pos_x < rect_H && rect_w <= pos_y && pos_y < rect_W); }

template<class T> vector<T> &operator++(vector<T> &v) {for(auto &e : v){e++;} return v;}
template<class T> vector<T> operator++(vector<T> &v, signed) {auto res=v; for(auto &e : v){e++;} return res;}
template<class T> vector<T> &operator--(vector<T> &v) {for(auto &e : v){e--;} return v;}
template<class T> vector<T> operator--(vector<T> &v, signed) {auto res=v; for(auto &e : v){e--;} return res;}
template<class T> vector<T> operator+(const vector<T> &x, const vector<T> &y) { assert(x.size() == y.size()); vector<T> ret(x.size()); for(int i = 0; i < (int)x.size(); i++) {ret[i] = x[i] + y[i];} return ret; }
template<class T> vector<T> operator-(const vector<T> &x, const vector<T> &y) { assert(x.size() == y.size()); vector<T> ret(x.size()); for(int i = 0; i < (int)x.size(); i++) {ret[i] = x[i] - y[i];} return ret; } 

template<class T, class U> pair<T, U> operator+(const pair<T, U> &x, const pair<T, U> &y) { return make_pair(x.first + y.first, x.second + y.second); }
template<class T, class U> pair<T, U> operator-(const pair<T, U> &x, const pair<T, U> &y) { return make_pair(x.first - y.first, x.second - y.second); }
template<class T, class U> void operator+=(pair<T, U> &x, pair<T, U> &y) { x = x + y; }
template<class T, class U> void operator-=(pair<T, U> &x, pair<T, U> &y) { x = x - y; }

template<class T> size_t HashCombine(const size_t seed,const T &v){ return seed^(std::hash<T>()(v)+0x9e3779b9+(seed<<6)+(seed>>2)); }
template<class T,class S> struct std::hash<std::pair<T,S>>{ size_t operator()(const std::pair<T,S> &keyval) const noexcept { return HashCombine(std::hash<T>()(keyval.first), keyval.second); } };
template<class T> struct std::hash<std::vector<T>>{ size_t operator()(const std::vector<T> &keyval) const noexcept { size_t s=0; for (auto&& v: keyval) s=HashCombine(s,v); return s; } };
template<int N> struct HashTupleCore{ template<class Tuple> size_t operator()(const Tuple &keyval) const noexcept{ size_t s=HashTupleCore<N-1>()(keyval); return HashCombine(s,std::get<N-1>(keyval)); } };
template <> struct HashTupleCore<0>{ template<class Tuple> size_t operator()(const Tuple &keyval) const noexcept{ return 0; } };
template<class... Args> struct std::hash<std::tuple<Args...>>{ size_t operator()(const tuple<Args...> &keyval) const noexcept { return HashTupleCore<tuple_size<tuple<Args...>>::value>()(keyval); } };

int main()
{
    std::cin.tie(nullptr), std::ios_base::sync_with_stdio(false);
    function<string(string)> calcC, calcS, calcL;
    calcC = [&](string S) -> string
    {
        string ret = "";
        ll i = 0;
        while(i < S.size())
        {
            if(inLR(S[i], 'A', 'Z'+1))
            {
                ret.push_back(S[i]);
                i++;
                continue;
            }
            else if(S[i] == '+' || S[i] == '-')
            {
                ll j = i;
                while(!inLR(S[j], 'A', 'Z'+1)) j++;
                ret += calcL(S.substr(i, j - i + 1));
                i = j + 1;
            }
            else if(S[i] == '[')
            {
                stack<ll> st;
                ll j = i;
                while(j < S.size())
                {
                    if(S[j] == '[') st.emplace(j);
                    else if(S[j] == ']')
                    {
                        if(st.top() == i)
                        {
                            st.pop();
                            break;
                        }
                        st.pop();
                    }
                    j++;
                }
                auto tmp = calcC(S.substr(i + 1, j - i - 1));
                reverse(All(tmp));
                ret += tmp;
                i = j+1;
            }
        }
        return ret;
    };
    calcL = [&](string S) -> string
    {
        ll pls = 0;
        for(auto c : S)
        {
            if(c == '+') pls = (pls + 1)%26;
            else if(c == '-') pls = (pls + 25) % 26;
        }
        S.back() = (S.back() - 'A' + pls) % 26 + 'A';
        return string(1, S.back());
    };
    while(true)
    {
        readstr(S);
        if(S == ".") break;
        vll q;
        rep(i, S.size())
        {
            if(S[i] == '?') q.emplace_back(i);
        }
        string ans(1, 'Z' + 1);
        for(char a = 'A'; a <= 'Z'; a++)
        {
            if(q.size() == 0)
            {
                chmin(ans, calcC(S));
                break;
            }
            S[q[0]] = a;
            for(char b = 'A'; b <= 'Z'; b++)
            {
                if(q.size() == 1)
                {
                    chmin(ans, calcC(S));
                    break;
                }
                S[q[1]] = b;
                for(char c = 'A'; c <= 'Z'; c++)
                {
                    if(q.size() == 2)
                    {
                        chmin(ans, calcC(S));
                        break;
                    }
                    S[q[2]] = c;
                    chmin(ans, calcC(S));
                }
            }
        }
        out(ans);
    }
}
accuracy: 1
time_ms: 510
memory_kb: 3840
final_rank: 14

code_snippet: // #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

// #include <atcoder/all>
// using namespace atcoder;

#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;

// #include "titan_cpplib/others/print.cpp"

class Parser {
public:
    using T = string;

    string s;
    int n, ptr;

    int tree_idx;
    int root;
    vector<T> val;
    vector<int> left, right;

    Parser() {}
    Parser(string s) : s(s), n(s.size()), ptr(0), tree_idx(0), root(-1), val(n), left(n, -1), right(n, -1) {}

    void consume(char expected) {
        if (next() != expected) {
            printf("Parser::Error: Expected `%c` but got `%c`\n", expected, next());
            assert(false);
        }
        ptr++;
    }

    char next() const {
        assert(ptr < n);
        return s[ptr];
    }

    bool done() const {
        return ptr == n;
    }

    bool is_digit(char c) const {
        return '0' <= c && c <= '9';
    }

    ll number() {
        // cerr << "number-start" << endl;
        ll ret = 0;
        while (!done() && is_digit(next())) {
            char v = next();
            ret *= 10;
            ret += v - '0';
            consume(v);
        }
        // cerr << "number-fin : " << ret << endl;
        return ret;
    }

    // ------------------------------------
    string t;

    void init() { ptr = 0; }

    /// @brief パースして返す
    T parse() {
        assert(ptr == 0);
        T ans = Cipher();
        assert(done());
        return ans;

        // root = build_tree();
    }

    int build_tree() {
        int idx = tree_idx;
        if (done()) {
            return -1;
        }

        if (next() == '(') {
            tree_idx++;
            consume('(');
            int ldx = build_tree();
            consume(')');
            left[idx] = ldx;

            consume('[');
            val[idx] = number();
            consume(']');

            consume('(');
            int rdx = build_tree();
            consume(')');
            right[idx] = rdx;
            return idx;
        }
        return -1;
    }

    void show_tree(int node, int dep) {
        if (node == -1) return;
        rep(_, dep) cerr << "  ";
        cerr << "node : " << val[node] << endl;
        if (left[node] != -1) {
            rep(_, dep) cerr << "  ";
            cerr << "left : " << val[left[node]] << endl;
        }
        if (right[node] != -1) {
            rep(_, dep) cerr << "  ";
            cerr << "right : " << val[right[node]] << endl;
        }
        show_tree(left[node], dep+1);
        show_tree(right[node], dep+1);
    }

    T Cipher() {
        string ret = "";
        while (!done()) {
            if (next() == ']') {
                break;
            }
            ret += String();
        }
        return ret;
    }

    T String() {
        if (next() == '[') {
            consume('[');
            T ret = Cipher();
            reverse(ret.begin(), ret.end());
            consume(']');
            return ret;
        } else {
            char ret = Letter();
            string s(1, ret);
            return s;
        }
    }

    char Letter() {
        if (next() == '+') {
            consume('+');
            char ret = Letter();
            if (ret == 'Z') {
                ret = 'A';
            } else {
                ret++;
            }
            return ret;
        } else if (next() == '-') {
            consume('-');
            char ret = Letter();
            if (ret == 'A') {
                ret = 'Z';
            } else {
                ret--;
            }
            return ret;
        } else {
            char ret = next();
            consume(ret);
            return ret;
        }
    }
};

void solve() {
    string s;
    cin >> s;
    if (s == ".") exit(0);

    string ans = "";
    rep(i, s.size()) ans += 'Z';
    vector<int> pos;
    rep(i, s.size()) {
        if (s[i] == '?') {
            pos.push_back(i);
        }
    }

    rep(i, 26) rep(j, 26) rep(k, 26) {
        string t = s;
        if(pos.size() >= 1) t[pos[0]] = 'A' + i;
        if(pos.size() >= 2) t[pos[1]] = 'A' + j;
        if(pos.size() >= 3) t[pos[2]] = 'A' + k;
        Parser p(t);
        string ret = p.parse();
        ans = min(ans, ret);
    }

    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);

    int t = 1e9;// cin >> t;
    for (int i = 0; i < t; ++i) {
        solve();
    }

    return 0;
}
accuracy: 1
time_ms: 670
memory_kb: 3456
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;
int cur;
char letter(string &S, int v);

const string ary = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";


string parse(string &S){
  //cout << cur << ' ' << S[cur] << endl;
  string ret;
  while(S[cur]=='+'||S[cur]=='-'||('A'<=S[cur]&&S[cur]<='Z')){
    //return letter length of 1;
    ret +=  letter(S, 0);
  }
  if(S[cur]=='['){
    string r;
    cur++;//[
    r = parse(S);
    cur++;//]
    reverse(r.begin(), r.end());
    ret += r;
  }
  //cout << cur << ' ' << S[cur] << ' ' << S.size() << endl;
  if(cur<S.size()&&S[cur]!=']') ret += parse(S);
  return ret;
}


char letter(string &S, int v){
  if(S[cur]=='+'||S[cur]=='-'){
    v += (S[cur] == '+'? 1 : -1);
    cur++;
    return letter(S, v);
  }
  char ans = ary[(S[cur] - 'A' + v + 26*3) % 26];
  cur++;
  return ans;
}

bool solve(){
  string S;
  cin >> S;
  if(S==".") return false;
  int N = S.size();
  vector<int> cnt;
  for(int i=0;i<N;i++){
    if(S[i]=='?')cnt.push_back(i);
  };
  string ans = "#";
  if(cnt.size()==0){
    cur = 0;
    ans = parse(S);
  }else{
    if(cnt.size()==1){
      for(char s1: ary){
        S[cnt[0]] = s1;
        cur = 0;
        if(ans=="#") ans = parse(S);
        else ans = min(ans, parse(S));
      }
    }else if(cnt.size()==2){
      for(char s1: ary){
        for(char s2: ary){
          S[cnt[0]] = s1;
          S[cnt[1]] = s2;
          cur = 0;
          if(ans=="#") ans = parse(S);
          else ans = min(ans, parse(S));
        }
      }
    }else{
      for(char s1: ary){
        for(char s2: ary){
          for(char s3: ary){
            S[cnt[0]] = s1;
            S[cnt[1]] = s2;
            S[cnt[2]] = s3;
            cur = 0;
            if(ans=="#") ans = parse(S);
            else ans = min(ans, parse(S));
          }
        } 
      }
    }
  }
  cout << ans << endl;
  return true;
}

int main(){
  while(solve()){}
  return 0;
}
accuracy: 1
time_ms: 140
memory_kb: 3372
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 10;
const ll INFL = 4e18;

using State = string::const_iterator;
class ParseError {};
void consume(State &begin, char expected) {
    if (*begin == expected) {
        begin++;
    } else {
        cerr << "Expected '" << expected << "' but got '" << *begin << "'"
             << endl;
        cerr << "Rest string is '";
        while (*begin) {
            cerr << *begin++;
        }
        cerr << "'" << endl;
        throw ParseError();
    }
}

string Cipher(State &itr);
string String(State &itr);
char Letter(State &itr);

char Letter(State &itr) {
    if ('A' <= *itr && *itr <= 'Z') {
        char ret = *itr;
        itr++;
        return ret;
    }
    if (*itr == '+') {
        itr++;
        char ret = Letter(itr);
        int idx = (ret - 'A' + 1) % 26;
        return char(idx + 'A');
    }
    if (*itr == '-') {
        itr++;
        char ret = Letter(itr);
        int idx = (ret - 'A' + 25) % 26;
        return char(idx + 'A');
    }
    return '#';
}

string String(State &itr) {
    if (*itr == '[') {
        itr++;
        string ret = Cipher(itr);
        consume(itr, ']');
        reverse(ret.begin(), ret.end());
        return ret;
    }
    string ret;
    ret += Letter(itr);
    return ret;
}

string Cipher(State &itr) {
    string ret;
    while (*itr && *itr != ']') {
        ret += String(itr);
    }
    return ret;
}

int main() {
    while (true) {
        string S;
        cin >> S;

        if (S == ".") {
            break;
        }

        vector<int> idx;
        int N = S.size();
        for (int i = 0; i < N; i++) {
            if (S[i] == '?') {
                idx.push_back(i);
            }
        }

        vector<string> ans;
        auto dfs = [&](auto &&dfs, int dep, vector<char> chars) -> void {
            if (dep == (int)idx.size()) {
                string T = S;
                for (int i = 0; i < (int)idx.size(); i++) {
                    T[idx[i]] = chars[i];
                }
                int cntl = 0, cntr = 0;
                State itr = T.begin();
                ans.push_back(Cipher(itr));
                return;
            }
            for (int i = 0; i < 26; i++) {
                chars.push_back(char('A' + i));
                dfs(dfs, dep + 1, chars);
                chars.pop_back();
            }
        };

        vector<char> chars;
        dfs(dfs, 0, chars);
        sort(ans.begin(), ans.end());

        cout << ans.front() << endl;
    }
}
accuracy: 1
time_ms: 260
memory_kb: 6448
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;

struct Parser{
    string s;
    string::const_iterator itr;

    Parser(string _s) : s(_s){
        itr = s.begin();
    }

    string parse(){
        return Cipher();
    }

    string Cipher(){
        string ret = String();
        while(itr != s.end() && *itr != ']'){
            // cerr << "now = " << *itr << endl;
            ret += String();
        }
        return ret;
    }

    string String(){
        string ret;
        // cerr << "String [Start] : " << *itr << endl;
        if(*itr == '['){
            ++itr;
            ret = Cipher();
            reverse(ret.begin(), ret.end());
            ++itr;
        }
        else{
            assert('A' <= *itr and *itr <= 'Z' or *itr == '+' or *itr == '-');
            ret.push_back(Letter());
        }
        // cerr << "String [End]   : " << ret << endl;
        return ret;
    }

    char Letter(){
        char ret;
        // cerr << "Letter [Start] : " << *itr << endl;
        if(*itr == '+'){
            ++itr;
            ret = next(Letter());
        }
        else if(*itr == '-'){
            ++itr;
            ret = prev(Letter());
        }
        else{
            ret = *itr;
            ++itr;
        }
        // cerr << "Letter [End]   : " << ret << endl;
        return ret;
    }

    char next(char c){
        if(c == 'Z') return 'A';
        else return char(c + 1);
    }

    char prev(char c){
        if(c == 'A') return 'Z';
        else return char(c - 1);
    }
};

int main(){
    string s;
    while(getline(cin, s)){
        if(s == ".") break;
        string ans;
        array<char, 3> ch;
        for(ch[0] = 'A'; ch[0] <= 'Z'; ++ch[0]){
            for(ch[1] = 'A'; ch[1] <= 'Z'; ++ch[1]){
                for(ch[2] = 'A'; ch[2] <= 'Z'; ++ch[2]){
                    string t = s;
                    for(int i = 0, j = 0; i < t.size(); ++i){
                        if(t[i] == '?') t[i] = ch[j++];
                    }
                    // cerr << t << endl;
                    auto tans = Parser(t).parse();
                    // cerr << tans << endl;
                    if(ans.empty()) ans = tans;
                    else ans = min(ans, tans);
                }
            }
        }
        cout << ans << endl;
    }
}
accuracy: 1
time_ms: 410
memory_kb: 3348
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef __int128_t lll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef tuple<ll, ll, ll> tt;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef vector<pl> vp;
typedef vector<tt> vt;
typedef vector<string> vs;

const ll INF = 1000000010;
const ll INFL = INF * INF;
const ld epsilon = 1e-10;

#define ovl(a, b, c, d, e, ...) e
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define DEBUG(...) DEBUG_(#__VA_ARGS__, __VA_ARGS__)
#define REP1(i, r) for (int i = 0; i < (r); i++)
#define REP2(i, l, r) for (int i = (l); i < (r); i++)
#define REP3(i, l, r, d) for (int i = (l); i < (r); i += (d))
#define REP(...) ovl(__VA_ARGS__, REP3, REP2, REP1)(__VA_ARGS__)
#define RREP1(i, r) for (int i = (r)-1; i >= 0; i--)
#define RREP2(i, l, r) for (int i = (r)-1; i >= (l); i--)
#define RREP3(i, l, r, d) for (int i = (r)-1; i >= (l); i -= (d))
#define RREP(...) ovl(__VA_ARGS__, RREP3, RREP2, RREP1)(__VA_ARGS__)
#define EACH1(x, a) for (auto &x : a)
#define EACH2(x, y, a) for (auto &[x, y] : a)
#define EACH3(x, y, z, a) for (auto &[x, y, z] : a)
#define EACH(...) ovl(__VA_ARGS__, EACH3, EACH2, EACH1)(__VA_ARGS__)
#define ALL(x) begin(x), end(x)
#define RALL(x) (x).rbegin(), (x).rend()
#define sz(x) (ll) x.size()
#define LB(a, x) (lower_bound(ALL(a), x) - a.begin())
#define UB(a, x) (upper_bound(ALL(a), x) - a.begin())
#define FLG(x, i) (((x) >> (i)) & 1)
#define CNTBIT(x) __builtin_popcountll(x)
#define IN(x, a, b) ((a) <= (x) && (x) < (b))
#define int ll

template <class T>
void DEBUG_(string_view name, const T &a) {
    cerr << name << ": " << a << endl;
}

template <class T>
void DEBUG_(string_view name, const vector<T> &a) {
    cerr << name << ": ";
    REP(i, sz(a)) cerr << a[i] << " ";
    cerr << endl;
}

template <class T, class U>
bool chmax(T &x, const U &y) {
    return x < y ? x = y, 1 : 0;
}
template <class T, class U>
bool chmin(T &x, const U &y) {
    return x > y ? x = y, 1 : 0;
}

//-----------------------------------------------------------------------

typedef string::const_iterator State;
typedef vector<string> Res;

string S;

Res Cipher(State &begin);
Res String(State &begin);
Res Letter(State &begin);

Res Cipher(State &begin) {
    Res res = String(begin);
    while (true) {
        if (begin == S.end() || *begin == ']') {
            break;
        }
        Res res2 = String(begin);
        Res new_res;
        EACH(r1, res) {
            EACH(r2, res2) { new_res.pb(r1 + r2); }
        }
        swap(res, new_res);
    }
    return res;
}

Res String(State &begin) {
    if (*begin == '[') {
        begin++;
        Res res;
        EACH(r, Cipher(begin)) { res.pb(string(RALL(r))); }
        assert(*begin == ']');
        begin++;
        return res;
    } else {
        return Letter(begin);
    }
}

char NextChar(char r) {
    assert(r != '?');
    if (r == 'Z') {
        return 'A';
    } else {
        return r + 1;
    }
}
char PrevChar(char r) {
    assert(r != '?');
    if (r == 'A') {
        return 'Z';
    } else {
        return r - 1;
    }
}

Res Letter(State &begin) {
    Res ret;
    if (*begin == '+') {
        begin++;
        EACH(r, Letter(begin)) {
            assert(r.size() == 1);
            ret.pb(string(1, NextChar(r[0])));
        }
    } else if (*begin == '-') {
        begin++;
        EACH(r, Letter(begin)) {
            assert(r.size() == 1);
            ret.pb(string(1, PrevChar(r[0])));
        }
    } else {
        char c = *begin;
        begin++;
        assert(('A' <= c && c <= 'Z') || c == '?');
        if (c == '?') {
            REP(alphabet, 'A', 'Z' + 1) { ret.pb(string(1, alphabet)); }
        } else {
            ret.pb(string(1, c));
        }
    }
    return ret;
}

void solve(State &begin) {
    Res res = Cipher(begin);
    assert(!res.empty());
    sort(res.begin(), res.end());
    cout << res[0] << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    while (true) {
        getline(cin, S);
        if (S == ".") break;
        State begin = S.begin();
        solve(begin);
    }

    return 0;
}
accuracy: 1
time_ms: 270
memory_kb: 11756
final_rank: 20

code_snippet: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, s, n) for (int i = int(s); i < int(n); i++)
#define rrep(i, s, n) for (int i = int(n) - 1; i >= int(s); i--)
#define all(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using ld = long double;

template <class T> bool chmin(T &a, T b) {
    if (a <= b) return false;
    a = b;
    return true;
}

template <class T> bool chmax(T &a, T b) {
    if (a >= b) return false;
    a = b;
    return true;
}

typedef std::string::const_iterator State;

bool expect(State &begin, char e) {
    return *begin == e;
}

void consume(State &begin, char e) {
    assert(*begin == e);
    begin++;
}

bool isAlpha(char c) {
    return 'A' <= c && c <= 'Z';
}

std::string Cipher(State &);
std::string String(State &);
std::string Letter(State &);

std::string Cipher(State &begin) {
    std::string s = String(begin);
    while(expect(begin, '[') || expect(begin, '+') || expect(begin, '-') || isAlpha(*begin)) {
        s += String(begin);
    }
    return s;
}

std::string String(State &begin) {
    if(expect(begin, '[')) {
        consume(begin, '[');
        std::string s = Cipher(begin);
        consume(begin, ']');
        std::reverse(all(s));
        return s;
    }
    else {
        return Letter(begin);
    }
}

std::string Letter(State &begin) {
    int cnt = 0;
    while(expect(begin, '+') || expect(begin, '-')) {
        if(expect(begin, '+')) {
            cnt++;
            consume(begin, '+');
        }
        else {
            consume(begin, '-');
            cnt--;
        }
    }
    cnt = (cnt % 26 + 26) % 26;
    assert(isAlpha(*begin));
    int buff = *begin - 'A';
    buff = (buff + cnt) % 26;
    std::string s = "";
    s += char('A' + buff);
    consume(begin, *begin);
    return s;
}

int main() {
    std::string s;
    while(std::cin >> s, !(s == ".")) {
        std::vector<int> p;
        rep(i,0,s.size()) {
            if(s[i] == '?') p.emplace_back(i);
        }
        s += ';';
        std::vector<std::string> ans;
        int c = 0;
        auto dfs = [&](auto &&self) -> void {
            if(c == int(p.size())) {
                State begin = s.begin();
                ans.emplace_back(Cipher(begin));
                consume(begin, ';');
                return;
            }
            rep(i,0,26) {
                s[p[c]] = char('A' + i);
                c++;
                self(self);
                c--;
            }
        };
        dfs(dfs);
        std::sort(all(ans));
        std::cout << ans[0] << '\n';
    }
}
accuracy: 1
time_ms: 180
memory_kb: 6492
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
string decode(string s) {
	vector<char> p;
	queue<char> q;
	for( int i = 0; i < s.size(); i++ ) {
		if( s[i] == ']' ) {
			while( p.back() != '[' ) {
				q.push(p.back());
				p.pop_back();
			}
			p.pop_back();
			while( !q.empty() ) {
				p.push_back(q.front());
				q.pop();
			}
		}else if( 'A' <= s[i] && s[i] <= 'Z' ) {
			char c = s[i];
			while( !p.empty() && ( p.back() == '+' || p.back() == '-' ) ) {
				if( p.back() == '+' ) c = (char)('A'+(c-'A'+1)%26);
				else c = (char)('A'+(c-'A'+25)%26);
				p.pop_back();
			}
			p.push_back(c);
		}else {
			p.push_back(s[i]);
		}
	}
	string ret;
	for( int i = 0; i < p.size(); i++ ) {
		ret += p[i];
	}
	return ret;
}
bool solve() {
	string S;
	cin >> S;
	if( S == "." ) return false;
	vector<int> v;
	for( int i = 0; i < S.size(); i++ ) {
		if( S[i] == '?' ) v.push_back(i);
	}
	if( v.empty() ) {
		cout << decode(S) << endl;
	}else {
		set<string> ss;
		while( v.size() < 3 ) v.push_back(v.back());
		for( int x = 'A'; x <= 'Z'; x++ ) {
			for( int y = 'A'; y <= 'Z'; y++ ) {
				for( int z = 'A'; z <= 'Z'; z++ ) {
					string S2 = S;
					S2[v[0]] = x;
					S2[v[1]] = y;
					S2[v[2]] = z;
					ss.insert(decode(S2));
				}
			}
		}
		cout << *ss.begin() << endl;
	}
	return true;
}
int main() {
	while( solve() ) {}
}
accuracy: 1
time_ms: 490
memory_kb: 7208
final_rank: 19

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(A) A.begin(),A.end()



string kaidoku(string S) {
    ll N = S.size();
    stack<ll> P, Q;
    string R = "";
    ll k = 0;
    ll L = -1;
    rep(i, N) {
        if (S[i] == '+' && k == 0)P.push(1);
        else if (S[i] == '-' && k == 0)P.push(-1);
        else if (S[i] == '[') {
            if (k == 0)L = i;
            k++;
        }
        else if (S[i] == ']' && k == 1) {
            ll t = L;
            string T = S.substr(t + 1, i - t - 1);
            T = kaidoku(T);
            reverse(all(T));
            R = R + T;
            k--;
        }
        else if (S[i] == ']')k--;
        else if (k == 0) {
            ll d = S[i] - 'A' + 26 * (1e7);
            while (!P.empty()) {
                d += P.top();
                P.pop();
            }
            d %= 26;
            R.push_back('A' + d);
        }
    }
    return R;
}

string AN;
void dfs(string& S, vll& HA, ll n) {
    if (n == HA.size()) {
        AN = min(AN, kaidoku(S));
    }
    else {
        rep(k, 26) {
            S[HA[n]] = 'A' + k;
            dfs(S, HA, n + 1);
            S[HA[n]] = '?';
        }
    }
}

void solve(string S) {
    ll N = S.size();
    vll HA;
    rep(i, N)if (S[i] == '?')HA.push_back(i);
    AN = "Z";
    rep(i, S.size())AN.push_back('Z');
    dfs(S, HA, 0);
    cout << AN << endl;
}

int main() {
    string S;
    while (cin >> S) {
        if (S == ".")return 0;
        solve(S);

    }
}
accuracy: 1
time_ms: 550
memory_kb: 3428
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,t) for (int i = (int)(s); i < (int)(t); ++i)
#define all(x) (x).begin(), (x).end()

string s;

pair<string, int> cipher(int k);
pair<string, int> str(int k);
pair<char, int> letter(int k);

pair<string, int> cipher(int k){
    string res = "";
    while(k < (int)s.size() && s[k] != ']'){
        string t;
        tie(t, k) = str(k);
        res += t;
    }
    return {res, k};
}

pair<string, int> str(int k) {
    if (s[k] == '['){
        ++k;
        string t;
        tie(t, k) = cipher(k);
        assert(s[k] == ']');
        ++k;
        reverse(all(t));
        return {t, k};
    } else {
        char c;
        tie(c, k) = letter(k);
        return {string({c}), k};
    }
}

pair<char, int> letter(int k) {
    if (s[k] == '+') {
        ++k;
        char c;
        tie(c, k) = letter(k);
        if (c == 'Z') c = 'A';
        else ++c;
        return {c, k};
    } else if (s[k] == '-') {
        ++k;
        char c;
        tie(c, k) = letter(k);
        if (c == 'A') c = 'Z';
        else --c;
        return {c, k};
    } else {
        return {s[k], k+1};
    }
}



int main(){
    while(true){
        cin>>s;
        if(s==".")break;
        vector<int> idx;
        rep(i,0,s.size()){
            if(s[i]=='?'){
                idx.push_back(i);
            }
        }
        string ans = string({'Z'+1});
        auto dfs = [&](auto& dfs, int i)->void{
            if(i==idx.size()){
                ans=min(ans,cipher(0).first);
                return;
            }
            rep(c,0,26){
                s[idx[i]] = 'A' + c;
                dfs(dfs, i+1);
            }
        };
        dfs(dfs, 0);
        cout<<ans<<"\n";
    }
}
accuracy: 1
time_ms: 310
memory_kb: 3388
final_rank: 7

code_snippet: #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, l, r) for(int i = int(l); i < int(r); i++)
#define rep(i, n)    rng(i, 0, n)
#define sz(v)        int(v.size())
#define foa(s, v)    for(auto &s : v)
#define all(v)       v.begin(), v.end()

template <class T = int>
using V = vector<T>;

string s;
void solve() {
	int n = sz(s);
	V<> idx;
	rep(i, n) {
		if(s[i] == '?') {
			idx.push_back(i);
		}
	}
	V<> p;
	string ans = "a";
	auto eval = [&]() {
		string t = s;
		rep(i, sz(idx)) {
			t[idx[i]] = 'A' + p[i];
		}
		int now = 0;
		auto chk = [&](auto chk) -> string {
			int add = 0;
			string ans = "";
			while(now < n) {
				if(t[now] == '[') {
					now++;
					auto res = chk(chk);
					reverse(all(res));
					foa(v, res) ans.push_back(v);
					assert(t[now] == ']');
				} else if(t[now] == ']') {
					return ans;
				} else if(t[now] == '+') {
					add++;
				} else if(t[now] == '-') {
					add--;
				} else {
					int d = t[now] - 'A';
					d += add;
					d %= 26;
					if(d < 0) d += 26;
					add = 0;
					ans.push_back('A' + d);
				}
				now++;
			}
			return ans;
		};
		auto ret = chk(chk);
		return ret;
	};
	auto dfs = [&](auto dfs) -> void {
		if(sz(p) == sz(idx)) {
			auto tmp = eval();
			ans = min(tmp, ans);
			return;
		}
		rep(i, 26) {
			p.push_back(i);
			dfs(dfs);
			p.pop_back();
		}
	};
	dfs(dfs);
	cout << ans << endl;
}

int main() {
	while(cin >> s && s != ".") solve();
}
accuracy: 1
time_ms: 140
memory_kb: 3468
final_rank: 3

code_snippet: #include <bits/stdc++.h>

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
#define all(v) v.begin(), v.end()

using ll = long long;
using ld = long double;
using ull = unsigned long long;

#define debug(...)                                                     \
    std::cerr << "LINE: " << __LINE__ << " [" << #__VA_ARGS__ << "]:", \
        debug_out(__VA_ARGS__)

void debug_out() {
    std::cerr << std::endl;
}

template <typename Head, typename... Tail> void debug_out(Head h, Tail... t) {
    std::cerr << " " << h;
    if (sizeof...(t) > 0) std::cerr << ",";
    debug_out(t...);
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &pa) {
    return os << pa.first << " " << pa.second;
}

template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec) {
    for (std::size_t i = 0; i < vec.size(); i++)
        os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}

template <typename T> bool chmin(T &a, const T &b) {
    if (a <= b) return false;
    a = b;
    return true;
}

template <typename T> bool chmax(T &a, const T &b) {
    if (a >= b) return false;
    a = b;
    return true;
}

typedef std::string::const_iterator State;

bool expect(State &begin, char expected) {
    return *begin == expected;
}

void consume(State &begin, char expected) {
    assert(*begin == expected);
    begin++;
}

bool isdigit(char c) {
    return '0' <= c && c <= '9';
}

bool isAlpha(char c) {
    return 'A' <= c && c <= 'Z';
}

bool isalpha(char c) {
    return 'a' <= c && c <= 'z';
}

std::string Cipher(State &);
std::string String(State &);
std::string Letter(State &);

std::string Cipher(State &begin) {
    std::string now = String(begin);
    while(!(expect(begin, ';') || expect(begin, ']'))) {
        now += String(begin);
    }
    return now;
}

std::string String(State &begin) {
    if(expect(begin, '[')) {
        consume(begin, '[');
        auto ret = Cipher(begin);
        consume(begin, ']');
        std::reverse(all(ret));
        return ret;
    }
    else {
        auto ret = Letter(begin);
        return ret;
    }
}

std::string Letter(State &begin) {
    int cnt = 0;
    while(expect(begin, '+') || expect(begin, '-')) {
        if(expect(begin, '+')) {
            consume(begin, '+');
            cnt++;
        }
        else {
            consume(begin, '-');
            cnt--;
        }
        cnt = (cnt + 26) % 26;
    }
    char c = *begin;
    consume(begin, c);
    c = char('A' + (c - 'A' + cnt) % 26);
    std::string ret = "";
    ret += c;
    return ret;
}

int main() {
    std::string s;
    while(std::cin >> s, !(s == ".")) {
        std::vector<int> idxs;
        rep(i,0,s.size()) if(s[i] == '?') idxs.emplace_back(i);
        s += ';';
        std::vector<std::string> ans;
        auto dfs = [&](auto &&self, int idx) -> void {
            if(idx == int(idxs.size())) {
                State begin = s.begin();
                ans.emplace_back(Cipher(begin));
                consume(begin, ';');
                return;
            }
            assert(s[idxs[idx]] == '?');
            rep(i,0,26) {
                s[idxs[idx]] = char('A' + i);
                self(self, idx + 1);
            }
            s[idxs[idx]] = '?';
        };
        dfs(dfs, 0);
        std::sort(all(ans));
        std::cout << ans[0] << '\n';
    }
}
accuracy: 1
time_ms: 220
memory_kb: 6444
final_rank: 11

code_snippet: # include <bits/stdc++.h>
# define rep(i, a, b) for (ll i = a; i < ll(b); i++)
# define all(v) std::begin(v), std::end(v)
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;

struct Parser {
   string s;
   string::const_iterator it;

   Parser() = default;

   Parser(string _s) : s(_s) { it = s.begin(); }

   string parse() {
      return cipher();
   }

   string cipher() {
      string now = str();
      while (it != s.end() && *it != ']') {
         now += str();
      }
      return now;
   }

   string str() {
      if (*it == '[') {
         assert(*it++ == '[');
         auto rev = cipher();
         assert(*it++ == ']');
         reverse(rev.begin(), rev.end());
         return rev;
      }
      else {
         return letter();
      }
   }

   string letter() {
      if (*it == '+') {
         it++;
         return succ(letter());
      }
      else if (*it == '-') {
         it++;
         return pred(letter());
      }
      else {
         return string(1, *it++);
      }
   }

   string succ(string x) {
      assert(x.size() == 1 && isalpha(x[0]));
      return string(1, mod_add(x[0], 1));
   }

   string pred(string x) {
      assert(x.size() == 1 && isalpha(x[0]));
      return string(1, mod_add(x[0], -1));
   }

   char mod_add(char c, int i) {
      return ((c - 'A' + i) % 26 + 26) % 26 + 'A';
   }
};

int main() {
   while (true) {
      string s;
      cin >> s;
      if (s == ".") break;

      string ans = string(1, 'Z' + 1);
      auto rec = [&](auto&& rec, string s) -> void {
         if (auto i = s.find('?'); i == string::npos) {
            ans = min(ans, Parser(s).parse());
         }
         else {
            for (char c = 'A'; c <= 'Z'; c++) {
               rec(rec, s.replace(i, 1, string(1, c)));
            }
         }
      };
      rec(rec, s);

      cout << ans << endl;
   }
}
accuracy: 1
time_ms: 160
memory_kb: 3444
final_rank: 4

code_snippet: # include <bits/extc++.h>
# define int Int
# define float Float
# define overload3(_1,_2,_3,name,...) name
# define _step(n) _rep(_,n)
# define _rep(i,n) _repr(i,0,n)
# define _repr(i,b,e) for(int i=(b), i##_len=(e); i<i##_len; ++i)
# define rep(...) overload3(__VA_ARGS__, _repr, _rep, _step)(__VA_ARGS__)
# define _reps(i,n) _reprs(i,1,n)
# define _reprs(i,b,e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define reps(...) overload3(__VA_ARGS__, _reprs, _reps)(__VA_ARGS__)
# define rrep(i,n) for(int i=(int)(n)-1; i>=0; --i)
# define rreps(i,n) for(int i=(n); i>0; --i)
# define all(v) std::begin(v), std::end(v)
# define rall(v) std::rbegin(v), std::rend(v)
# define pb push_back
# define eb emplace_back
# define len(v) ssize(std::size(v))
# define eprintf(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
using Int = long long;
using Float = long double;
using int32 = int32_t;
using int64 = int64_t;
using uint32 = uint32_t;
using uint64 = uint64_t;
using usize = size_t;
using ssize = ptrdiff_t;
template<class T> using vec = vector<T>;
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vec<T>, greater<T>>;
using pii = pair<int, int>;
using vi = vec<int>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using vb = basic_string<bool>;
using vvb = vec<vb>;
using vvvb = vec<vvb>;
template<class T, size_t N> auto make_vector(vi& sizes, const T& x) {
   if constexpr (N == 1) return vector(sizes[0], x);
   else { int size = sizes[N - 1]; sizes.pop_back();
   return vector(size, make_vector<T, N - 1>(sizes, x)); }
}
template<class T, size_t N> auto make_vector(int const(&sizes)[N], const T& x = T()) {
   vi s(N); rep (i, N) s[i] = sizes[N - i - 1];
   return make_vector<T, N>(s, x);
}
constexpr int oo = (1LL<<62)-(1LL<<31);
template<class T> string join(const vec<T>& v){ stringstream s; for (T t : v) s << ' ' << t; return s.str().substr(1); }
template<class T> ostream& operator <<(ostream& os, const vec<T>& v){ if (len(v)) os << join(v); return os; }
template<class T> ostream& operator <<(ostream& os, const vec<vec<T>>& v){
   rep (i, len(v)) if (len(v[i])) os << join(v[i]) << (i-len(v)+1 ? "\n" : "");
   return os;
}
template<class T, class U> ostream& operator <<(ostream& os, const pair<T, U>& p){ return os << p.first << ' ' << p.second; }
template<class T, class U, class V>
ostream& operator <<(ostream& os, const tuple<T, U, V>& t){ return os << get<0>(t) << " " << get<1>(t) << " " << get<2>(t); }
template<class T> T scan(){ T t; cin >> t; return t; }
template<class T> constexpr bool chmax(T& a, const T& b){ return a < b && (a = b, true); }
template<class T> constexpr bool chmin(T& a, const T& b){ return a > b && (a = b, true); }
constexpr int ctoi(char c){ return '0' <= c and c <= '9' ? c - '0' : -1; }
template<class T> constexpr bool iseven(T n) { return !(n & 1); }
template<class T> constexpr bool isodd(T n) { return n & 1; }
template<class T> void sort(T& v){ sort(all(v)); }
template<class T, class C> void sort(T& v, C comp){ sort(all(v), comp); }
template<class T> void rsort(T& v){ sort(all(v), greater<>()); }
template<class T, class C> void rsort(T& v, C comp){ sort(rall(v), comp); }
template<class T> void reverse(T& v){ reverse(all(v)); }
template<class T> void unique(T& v){ sort(v); v.erase(unique(all(v)), end(v)); }
template<class T = int, class S> T accumulate(const S& v, T init = 0) { return accumulate(cbegin(v), cend(v), init); }
template<class T = int, class S, class Op> T accumulate(const S& v, T init, Op op) { return accumulate(cbegin(v), cend(v), init, op); }
template<class T = int, class S> auto count(const S& v, T target) { return count(cbegin(v), cend(v), target); }
template<class T, class C> auto count_if(const T& v, C comp) { return count_if(cbegin(v), cend(v), comp); }
template<class T> auto max(T& v){ return *max_element(cbegin(v), cend(v)); }
template<class T> auto min(T& v){ return *min_element(cbegin(v), cend(v)); }
template<class T = int, class S> auto lower_bound(const S& v, T x){ return lower_bound(cbegin(v), cend(v), x); }
template<class T = int, class S> auto upper_bound(const S& v, T x){ return upper_bound(cbegin(v), cend(v), x); }
template<class T> auto next_permutation(T& v){ return next_permutation(all(v)); }
vi iota(int n) { vi v(n); iota(all(v), int(0)); return v; }
vi iota(int a, int b) { vi v(b - a); iota(all(v), a); return v; }
vec<pii> iota2(int n, int m) { vec<pii> res(n * m); rep (i, n) rep (j, m) res[n*i + j] = { i, j }; return res; }
namespace math {
   template<class T> T sum(T n) { return n * (n + 1) / 2; }
   template<class T> T nc2(T n) { return n * (n - 1) / 2; }
   template<class T> T nc3(T n) { return n * (n - 1) * (n - 2) / 6; }
   template<class T> int sgn(T x) { return x == T(0) ? 0 : (x > 0) - (x < 0); }
   int pow(int a, int n) { int e = 1; while (n) { if (n & 1) e *= a; a *= a; n >>= 1; } return e; }
   int pow(int a, int n, int m) { int e = 1; a %= m; while (n) { if (n & 1) (e *= a) %= m; (a *= a) %= m; n >>= 1; } return e; }
   int ceil(const int n, const int d) { assert(d); return n / d + int((n ^ d) >= 0 && n % d != 0); }
   constexpr int floor_sqrt(int n) {
      if (n <= 1) return n;
      int r = sqrt(n);
      do r = (r & n / r) + (r ^ n / r) / 2; while (r > n / r);
      return r;
   }
}
template <class F>
struct Bind { F f; Bind(F &&f_)
   : f(forward<F>(f_)) {} template <class... Args> auto operator()(Args &&...args) const
   { return f(*this, forward<Args>(args)...); }
};
struct Scanner {
   Scanner() = default;
   int nextInt(int o = 0) const {
      char c = skip();
      int r = c - '0', sgn = 1;
      if (c == '-') sgn = -1, r = gc() & 0xf;
      else if (c == '+') r = gc() & 0xf;
      while (!isspace(c = gc())) r = 10 * r + (c & 0xf);
      return sgn * r + o;
   }
   char nextChar() const { return skip(); }
   string nextWord() const { char c = skip(); string r = {c}; while (!isspace(c = gc())) r.pb(c); return r; }
   string nextLine() const { char c; string r; while ((c = gc()) != '\n') r.pb(c); return r; }
   vi nextVi(int n, int o=0) const { vi a(n); rep(i, n) a[i] = nextInt(o); return a; }
   template<size_t N> array<int, N> nextAi() const { array<int, N> r; rep(i, N) r[i] = nextInt(); return r; }
   template<size_t N> array<int, N> nextAi(initializer_list<int> os) const {
      vi o(all(os));
      array<int, N> r;
      rep(i, N) r[i] = nextInt(o[i]);
      return r;
   }
   template<size_t N> vec<array<int, N>> nextVecAi(int n, initializer_list<int> os) const {
      vec<array<int, N>> r(n);
      rep (i, n) r[i] = nextAi<N>(os);
      return r;
   }
   template<size_t N> vec<array<int, N>> nextVecAi(int n) const { vec<array<int, N>> r(n); rep (i, n) r[i] = nextAi<N>(); return r; }
   vvi nextVvi(int n, int m, int o=0) const { vvi a(n, vi(m)); rep(i, n) rep(j, m) a[i][j] = nextInt(o); return a; }
   vec<string> nextWords(int n) const { vec<string> s(n); rep (i, n) s[i] = nextWord(); return s; }
   pii nextPii() const { return nextPii(0, 0); }
   pii nextPii(int o1, int o2) const { int a = nextInt(o1), b = nextInt(o2); return { a, b }; }
   vec<pii> nextVecPii(int n) const { return nextVecPii(n, 0, 0); }
   vec<pii> nextVecPii(int n, int o1, int o2) const { vec<pii> r(n); rep (i, n) r[i] = nextPii(o1, o2); return r; }
   pair<vi, vi> nextPairViVi(int n) const { return nextPairViVi(n, 0, 0); }
   pair<vi, vi> nextPairViVi(int n, int o1, int o2) const {
      vi a(n), b(n);
      rep (i, n) tie(a[i], b[i]) = nextPii(o1, o2);
      return { a, b };
   }
   tuple<int, int, vvi> nextGraph(int o=-1) const {
      auto [n, m] = nextPii();
      vvi g(n);
      rep (m) { auto [a, b] = nextPii(o, o); g[a].pb(b); g[b].pb(a); }
      return { n, m, g };
   }
   tuple<int, int, vvi> nextDirectedGraph(int o=-1) const {
      auto [n, m] = nextPii();
      vvi g(n);
      rep (m) { auto [a, b] = nextPii(o, o); g[a].pb(b); }
      return { n, m, g };
   }
   tuple<int, int, vvi> nextTree(int o=-1) const {
      int n = nextInt();
      vvi g(n);
      rep (n - 1) { auto [a, b] = nextPii(o, o); g[a].pb(b); g[b].pb(a); }
      return { n, n - 1, g };
   }
   tuple<int, int, vvi> nextDirectedTree(int o=-1) const {
      int n = nextInt();
      vvi g(n); rep (n - 1) { auto [a, b] = nextPii(o, o); g[a].pb(b); }
      return { n, n - 1, g };
   }
private:
   char skip() const { char c; while (isspace(c = getchar())); return c; }
   inline char gc() const { return getchar(); }
} sc;

using State = string::const_iterator;
# define skip(it, s) for (int iii = 0; s[iii] != '\0'; ++iii) assert(*(it)++ == s[iii])
string erase_all_space(string s) { s.erase(remove_if(all(s), [](char c){ return isspace(c); }), s.end()); return s; }

struct Parser {
   string s;
   State it;
   Parser(string _s) : s(_s) {}

   string parse() {
      it = s.begin();
      return cipher();
   }

   string cipher() {
      string res = "";
      while (it != s.end() and *it != ']') {
         if (*it == '+' or *it == '-' or isalpha(*it)) {
            res += letter();
         }
         else if (*it == '[') {
            skip(it, "[");
            string t = cipher();
            skip(it, "]");
            reverse(t);
            res += t;
         }
      }
      return res;
   }

   string letter() {
      if (*it == '+') {
         skip(it, "+");
         return string(1, next(letter()[0]));
      }
      else if (*it == '-') {
         skip(it, "-");
         return string(1, prev(letter()[0]));
      }
      else {
         return string(1, *it++);
      }
   }

   char next(char c) {
      if (c == 'Z') return 'A';
      else return c + 1;
   }

   char prev(char c) {
      if (c == 'A') return 'Z';
      else return c - 1;
   }
};

int32 main() {
   for (string s = sc.nextWord(); s != "."; s = sc.nextWord()) {
      const int n = len(s);

      string ans = numeric_limits<char>::max() + s;
      Bind([&](auto&& self, int i) -> void {
         if (i == n) {
            Parser parser(s);
            auto res = parser.parse();
            chmin(ans, res);
         }
         else if (s[i] == '?') {
            for (char c = 'A'; c <= 'Z'; ++c) {
               int old = s[i];
               s[i] = c;
               self(i + 1);
               s[i] = old;
            }
         }
         else {
            self(i + 1);
         }
      })
      (0);

      cout << ans << '\n';
   }
}
accuracy: 1
time_ms: 200
memory_kb: 3352
final_rank: 5

code_snippet: //Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>
#include <complex>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#define int long long
//#define L __int128
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define a first
#define b second
#define fi first
#define sc second
#define rng(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
#define si(x) int(x.size())
 
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif
 
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}
 
template<class t> using vc=vector<t>;
 
template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.fi<<","<<p.sc<<"}";
}
 
template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}
 
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
//const ll mod = 998244353;
const ll mod = 1000000007;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}
ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
#define _sz 1
ll F[_sz],R[_sz];
void make(){
	F[0] = 1;
	for(int i=1;i<_sz;i++) F[i] = F[i-1]*i%mod;
	R[_sz-1] = modpow(F[_sz-1], mod-2);
	for(int i=_sz-2;i>=0;i--) R[i] = R[i+1] * (i+1) % mod;
}
ll C(int a,int b){
	if(b < 0 || a < b) return 0;
	return F[a]*R[b]%mod*R[a-b]%mod;
}
//複数テストケースなので積み上げる変数はローカルに！
//置けないなら必ず初期化！
string s;
void solve(){
	//最初の入力は済んでいる
	auto mv = [](char c, int d){
		d += (c-'A');
		d = (d%26+26)%26;
		return ('A'+d);
	};
	string inf = "";
	rep(i, 105) inf.pb('Z');
	
	auto dfs = [&](string &str, int le, int ri, auto dfs) -> string{
		if(le > ri) return "";
		if(str[le] == '['){
			int dep = 0;
			for(int i=le;i<=ri;i++){
				if(str[i] == '[') dep ++;
				else if(str[i] == ']'){
					dep --;
					if(dep == 0){
						string x = dfs(str, le+1, i-1, dfs) ;
						reverse(all(x));
						string y = dfs(str, i+1, ri, dfs);
						if(x == inf or y == inf) return inf;
						return x + y;
					}
				}
			}
			return inf;
		}
		else if(str[le] == ']') return inf;
		
		int x = 0;
		while(le <= ri and (str[le] == '+' or str[le] == '-')){
			if(str[le] == '+') x ++; else x --;
			le ++;
		}
		if(le > ri or !('A' <= str[le] and str[le] <= 'Z')) return inf;
		string s = "";
		s.pb(mv(str[le], x));
		auto nx = dfs(str, le+1, ri, dfs);
		if(nx == inf) return inf;
		return s + nx;
	};
	
	vc<char>v;
	rep(i, 26) v.pb('A'+i);
	
	string ans = inf;
	
	auto make = [&](int nxt, auto make) -> void{
		if(nxt == s.size()){
			bool ok = false;
			if(ans != "JANN") ok = true;
			chmin(ans, dfs(s, 0, s.size()-1, dfs));
			if(ok and ans == "JANN") o(s);
			return;
		}
		if(s[nxt] == '?'){
			for(auto a:v){
				s[nxt] = a;
				make(nxt+1, make);
				s[nxt] = '?';
			}
		}
		else make(nxt+1, make);
	};
	
	make(0, make);
	o(ans);
}
signed main(){
	//cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	while(true){
		cin>>s;
		//終了条件
		if(s == ".") return 0;
		solve();
	}
}
accuracy: 1
time_ms: 420
memory_kb: 3304
final_rank: 10

code_snippet: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

#define amax(a, b) a = std::max(a, b)
#define amin(a, b) a = std::min(a, b)

using ll = long long;

std::pair<std::string, int> parse_cipher(std::string &org, int pos = 0);

std::pair<std::string, int> parse_letter(std::string &org, int pos) {
    // std::cerr << "letter: " << pos << std::endl;
    int offset = 0;
    while (pos < org.size() && (org[pos] == '+' || org[pos] == '-')) {
        offset += (org[pos] == '+' ? +1 : -1);
        if (offset < 0) offset += 26;
        pos++;
    }
    if (pos < org.size()) {
        char result_letter = 'A' + (org[pos] - 'A' + offset) % 26;
        return {std::string(1, result_letter), pos + 1};
    } else {
        return {"", -1};
    }
}

std::pair<std::string, int> parse_string(std::string &org, int pos) {
    // std::cerr << "string: " << pos << std::endl;
    if (org[pos] == '[') {
        auto [result, new_pos] = parse_cipher(org, pos + 1);
        // std::cerr << result << ' ' << new_pos << std::endl;
        std::reverse(result.begin(), result.end());
        pos = new_pos;
        if (pos >= 0 && org[pos] == ']') {
            return {result, pos + 1};
        } else {
            return {"", -1};
        }
    } else {
        return parse_letter(org, pos);
    }
}

std::pair<std::string, int> parse_cipher(std::string &org, int pos) {
    // std::cerr << "cipher: " << pos << std::endl;
    std::string result;
    while (pos < org.size() && org[pos] != ']') {
        auto [part_result, new_pos] = parse_string(org, pos);
        if (new_pos < 0) {
            return {"", -1};
        }
        result += part_result;
        pos = new_pos;
    }
    return {result, pos};
}

std::string idx_to_str(int idx) {
    std::string result = "AAA";
    result[0] += idx / (26 * 26);
    result[1] += (idx % (26 * 26)) / 26;
    result[2] += idx % 26;
    return result;
}

std::string fill_blanks(std::string org, std::string blanks) {
    int blank_idx = 0;
    for (auto &ci : org) {
        if (ci == '?') {
            ci = blanks[blank_idx];
            blank_idx++;
        }
    }
    return org;
}

int main() {
    while (true) {
        std::string s;
        std::cin >> s;
        if (s == ".") {
            break;
        }
        std::string best;
        for (int i = 0; i < 26 * 26 * 26; i++) {
            std::string target = fill_blanks(s, idx_to_str(i));

            // std::cerr << "==  target == " << target << std::endl;
            auto [result, pos] = parse_cipher(target);
            if (pos == target.size() && (best == "" || result < best)) {
                best = result;
            }
        }
        std::cout << best << '\n';
    }
    
    return 0;
}
accuracy: 1
time_ms: 630
memory_kb: 3368
final_rank: 17

code_snippet: #include <bits/stdc++.h>

using namespace std;

class Parser{
    string S;
    int pos = 0;
    public:
    Parser(string S) : S(S){}

    char peek(){
        return pos < S.size() ? S[pos] : 'a';
    }

    void skip_spaces(){
        while (peek() == ' ')
            pos++;
    }

    void next(string S){
        for (const auto &s: S){
            assert(peek() == s);
            pos++;
        }
    }

    string cipher(){
        string res = "";
        while (pos < S.size() and peek() != ']')
            res += string_statement();
        return res;
    }

    string string_statement(){
        if (peek() == '['){
            next("[");
            auto res = cipher();
            next("]");
            reverse(res.begin(), res.end());
            return res;
        }

        return letter();
    }

    string letter(){
        int d = 0;
        while(peek() == '+' or peek() == '-'){
            if (peek() == '+')
                d++;
            else
                d--;
            pos++;
        }

        assert(isupper(peek()));
        char c = peek();
        pos++;

        d = ((d % 26) + 26) % 26;
        return string(1, 'A' + (c - 'A' + d) % 26);
    }

    int number(){
        bool minus = false;
        if (peek() == '-'){
            pos++;
            minus = true;
        }
        int res = 0;
        while (isdigit(peek())){
            res = res * 10 + peek() - '0';
            pos++;
        }
        return minus ? -res : res;
    }
};

void solve(string S){
    string ans(100, 'Z');
    vector<int> Q;
    for (int i = 0; i < S.size(); i++){
        if (S[i] == '?')
            Q.push_back(i);
    }

    for (char a = 'A'; a <= 'Z'; a++){
        for (char b = 'A'; b <= 'Z'; b++){
            for (char c = 'A'; c <= 'Z'; c++){
                vector<char> A = {a, b, c};
                for (int i = 0; i < Q.size(); i++)
                    S[Q[i]] = A[i];
                Parser parser(S);
                ans = min(ans, parser.cipher());
            }
        }
    }

    cout << ans << endl;
}

int main(){
    string S;
    while (true){
        cin >> S;
        if (S == ".")
            return 0;
        solve(S);
    }
}
accuracy: 1
time_ms: 580
memory_kb: 3376
final_rank: 16

code_snippet: /*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
#include <vector>
#include <cassert>
#include <cmath>
#include <utility>
#include <tuple>
#include <map>
#include <set>
#include <deque>
#include <queue>
typedef long long int64;
using namespace std;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
const char bn = '\n';
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T,typename S,typename U>
ostream& operator<<(ostream& os, tuple<T,S,U> const& P){
    os << "(";
    os << get<0>(P);
    os << ", ";
    os << get<1>(P);
    os << ", ";
    os << get<2>(P);
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
    os<<endl;
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, map<T,S> const&M){
    for(auto e:M){
        os<<e;
    }
    os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;


// 構文解析
/*
    構文解析でよくあるバグは次の二つです。
    - begin++をし忘れる
    - getlineとcinの混合
*/


typedef string::const_iterator State;
class ParseError {};

// beginがexpectedを指していたらbeginを一つ進める。
void consume(State &begin, char expected) {
    if (*begin == expected) {
        begin++;
    } else {
        cerr << "Expected '" << expected << "' but got '" << *begin << "'"
            << endl;
        cerr << "Rest string is '";
        while (*begin) {
            cerr << *begin++;
        }
        cerr << "'" << endl;
        throw ParseError();
    }
}

string cipher(State &begin);
string str(State &begin);
char letter(State &begin);

// 四則演算の式をパースして、その評価結果を返す。
string cipher(State &begin){
    string res = "";

    while(*begin != '#' and *begin != ']'){
        res += str(begin);
    }

    return res;
}

string str(State &begin){
    string res;
    if(*begin == '['){
        consume(begin, '[');
        res = cipher(begin);
        reverse(ALL(res));
        consume(begin, ']');
    }else{
        res = string(1, letter(begin));
    }
    return res;
}

char letter(State &begin){
    char res;
    if(*begin == '+'){
        consume(begin, '+');
        res = letter(begin);
        if(res=='Z') res = 'A';
        else res++;
    }else if(*begin == '-'){
        consume(begin, '-');
        res = letter(begin);
        if(res=='A') res = 'Z';
        else res--;
    }else{
        res = *begin;
        begin++;
    }
    return res;
}

string rec(string S, int i, vector<int> const& hatena_positions){
    if(i==hatena_positions.size()){
        State begin =  S.begin();
        return cipher(begin);
    }

    int idx = hatena_positions[i];
    string res = string(1, 'Z'+1);
    REP(j,26){
        S[idx] = 'A'+j;
        chmin(res, rec(S, i+1, hatena_positions));
    }
    return res;
}

void solve(string S){
    vector<int> hatena_positions={};
    REP(i,S.size()){
        if(S[i] == '?'){
            hatena_positions.emplace_back(i);
        }
    }
    
    string ans = rec(S,0,hatena_positions);
    cout << ans << endl;
}


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string S;
    while(cin >> S){
        if(S==".") break;
        S+='#';
        solve(S);
    }
}
accuracy: 1
time_ms: 240
memory_kb: 3476
final_rank: 6