Problem:
Problem Statement
Dr. Suposupo developed a programming language called Shipura. Shipura supports only one binary operator ${\tt >>}$ and only one unary function ${\tt S<\ >}$.
$x {\tt >>} y$ is evaluated to $\lfloor x / 2^y \rfloor$ (that is, the greatest integer not exceeding $x / 2^y$), and ${\tt S<} x {\tt >}$ is evaluated to $x^2 \bmod 1{,}000{,}000{,}007$ (that is, the remainder when $x^2$ is divided by $1{,}000{,}000{,}007$).
The operator ${\tt >>}$ is left-associative. For example, the expression $x {\tt >>} y {\tt >>} z$ is interpreted as $(x {\tt >>} y) {\tt >>} z$, not as $x {\tt >>} (y {\tt >>} z)$. Note that these parentheses do not appear in actual Shipura expressions.
The syntax of Shipura is given (in BNF; Backus-Naur Form) as follows:
expr   ::= term | expr sp ">>" sp term
term   ::= number | "S" sp "<" sp expr sp ">"
sp     ::= "" | sp " "
number ::= digit | number digit
digit  ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
The start symbol of this syntax is $\tt expr$ that represents an expression in Shipura. In addition, $\tt number$ is an integer between $0$ and $1{,}000{,}000{,}000$ inclusive, written without extra leading zeros.
Write a program to evaluate Shipura expressions.
Input
The input is a sequence of datasets. Each dataset is represented by a line which contains a valid expression in Shipura.
A line containing a single ${\tt \#}$ indicates the end of the input. You can assume the number of datasets is at most $100$ and the total size of the input file does not exceed $2{,}000{,}000$ bytes.
Output
For each dataset, output a line containing the evaluated value of the expression.
Sample Input
S< S< 12 >> 2 > >
123 >> 1 >> 1
1000000000   >>129
S<S<S<S<S<2>>>>>
S  <S< S<2013    >>> 11 >>> 10 >
#
Output for the Sample Input
81
30
0
294967268
14592400

Submitted solutions:

code_snippet: #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <sstream>
#include <bitset>
using namespace std;
#define MP(a, b) make_pair(a, b)
#define VT vector
#define FI first
#define SE second
#define FOR(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 1; i <= n; ++i)
typedef long long ll;
typedef unsigned long long ull;

const char *P;
const ll mod = 1000000007;
ll expr();
ll term();


ll term() {
    ll x = 0;
    if (P[0] == 'S') {
        P += 2;
        x = expr();
        x = x * x % mod;
        P++;
    }
    else {
        char *endp;
        x = strtoll(P, &endp, 10);
        P = endp;
    }
    return x;
}

ll expr() {
    ll x = term();
    ll b;
    while (P[0] == '>' && P[1] == '>' && (P[2] == 'S' || isdigit(P[2]))) {
        P += 2;
        x >>= min(term(), 63LL);
    }
    return x;
}


int main() {
    string s;
    while (1) {
        getline(cin, s);
        if (s[0] == '#') break;
        s.erase(remove(s.begin(), s.end(), ' '), s.end());
        P = s.c_str();
        // cout << s << endl;
        cout << expr() << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 5480
final_rank: 8

code_snippet: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <stack>

using namespace std;

const int maxn=(int)2e6+5;
const int mod=(int)1e9+7;

char s[maxn];
int idx;
stack<int> S1;
stack<char> S2;

int main(){
    while(1){
        static int i,b,x,a,now;
        if(!fgets(s, sizeof(s), stdin)) break;  // 用 fgets 替换 gets
        int len = strlen(s);
        if(len>0 && s[len-1]=='\n') s[len-1] = '\0';  // 去掉末尾换行符
        if(s[0]=='#') break;
        idx=0;
        for(i=0;s[i];i++)
            if(s[i]=='<'||s[i]=='>'||('0'<=s[i]&&s[i]<='9'))
                s[idx++]=s[i];
        s[idx]=0;
        while(!S1.empty()) S1.pop();
        while(!S2.empty()) S2.pop();
        b=0,a=0,now=0;
        for(i=0;s[i];){
            if('0'<=s[i] && s[i]<='9'){
                x=0;
                for(;'0'<=s[i] && s[i]<='9';i++)
                    x=x*10+s[i]-'0';
                S1.push(x);
                while((!S2.empty())&&(S2.top()=='b')){
                    x=S1.top(); S1.pop();
                    now=S1.top(); S1.pop();
                    S2.pop();
                    if(x<32) now=now>>x;
                    else now=0;
                    S1.push(now);
                }
            }
            else if(s[i]=='>'){
                if(s[i+1]=='>'&&(('0'<=s[i+2]&&s[i+2]<='9')||s[i+2]=='<')){
                    S2.push('b');
                    i+=2;
                }
                else{
                    now=S1.top(); S1.pop();
                    S2.pop();
                    now=now*(long long)now%mod;
                    S1.push(now);
                    i++;
                    while((!S2.empty())&&(S2.top()=='b')){
                        x=S1.top(); S1.pop();
                        now=S1.top(); S1.pop();
                        S2.pop();
                        if(x<32) now=now>>x;
                        else now=0;
                        S1.push(now);
                    }
                }
            }
            else if(s[i]=='<'){
                S2.push('a');
                i++;
            }
            else i++;
        }
        now=S1.top();
        printf("%d\n",now);
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3704
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
const int MAXN = 300005;
const int mod = 1e9 + 7;
char s[MAXN];
int match[MAXN], bracket[MAXN], jmp[MAXN];
int solve(int l, int r) {
    for(; l < r && match[l] == r; l ++, r --) ;
    int lastshift = -1;
    for(int i = l; i <= r; i ++) {
        if(s[i] == ')') {
            i = match[i];
        } else if(s[i] == '>' && !bracket[i]) {
            lastshift = i;
        } else if(s[i] == 'S') {
            i = jmp[i];
        }
    }
    if(lastshift != -1) {
        return solve(l, lastshift - 2) >> min(31, solve(lastshift + 1, r));
    } else if(s[l] == 'S') {
        int ans = solve(l + 2, r - 1);
        return ans * 1LL * ans % mod;
    } else {
        int x = 0;
        for(int i = l; i <= r; i ++) {
            x = x * 10 + s[i] - '0';
        }
        return x;
    }
}
int main() {
//    freopen("in", "r", stdin);
    while(scanf(" %[^\n]", s) == 1) {
        if(s[0] == '#') break;
        int n = strlen(s), m = 0;
        for(int i = 0; i < n; i ++) {
            if(s[i] != ' ') {
                s[m ++] = s[i];
            }
        }
        n = m;
        s[n] = 0;
//        cout << s << endl;
        stack<int> sta;
        for(int i = 0; i < n; i ++) {
            match[i] = i;
            if(s[i] == '(') {
                sta.push(i);
            } else if(s[i] == ')') {
                int x = sta.top();
                sta.pop();
                match[x] = i;
            }
        }
        for(int i = 0; i < n; i ++) {
            bracket[i] = false;
            if(s[i] == '>') {
                bracket[i] = true;
            } else if(i > 0 && s[i - 1] == '>') {
                assert(s[i - 2] == '>');
                bracket[i - 1] = bracket[i - 2] = false;
            }
        }
        for(int i = 0; i < n; i ++) {
            jmp[i] = i;
            if(s[i] == 'S') {
                sta.push(i);
            } else if(bracket[i]) {
                int x = sta.top();
                sta.pop();
                jmp[x] = i;
            }
        }
        int ans = solve(0, n - 1);
        printf("%d\n", ans);
    }
    return 0;
}
accuracy: 1
time_ms: 1440
memory_kb: 5956
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

string s;
int f, k, cnt = 0;

ll rec(){
    ll res = 0, tmp=0;
    while(k<s.size()){
        if(s[k]=='<' || s[k] == ' '){
            k++;
            continue;
        }
        if(s[k]=='S'){
            f++;
            k++;
            if(cnt>=2){
                cnt -= 2;
                tmp = rec();
                if(tmp < 32){
                    res >>= tmp;
                }
                else res = 0;
            }
            else res += rec();
        }
        else if(s[k] == '>'){
            cnt++;
            if(cnt>=3){
                cnt--;
                f--;
                return res*res %MOD;
            }
        }
        else{
            tmp = 0;
            while(k < s.size() && s[k]>='0' && s[k]<='9'){
                tmp = tmp*10 + s[k] - '0';
                k++;
            }
            k--;
            if(cnt>=2){
                cnt -= 2;
                if(tmp < 32)res >>= tmp;
                else res = 0;
            }
            else res += tmp;
        }
        if(s[k] != '>') cnt = 0;
        k++;
    }
    if(f>0){
        f--;
        res = res*res %MOD;
    }
    return res;
}

int main() {
    
    while(1){
        getline(cin,s);
        if(s=="#")break;
        k = 0;
        cout << rec() << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4448
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
const int MAXN = 300005;
const int mod = 1e9 + 7;
char s[MAXN];
int match[MAXN], bracket[MAXN], jmp[MAXN];
int solve(int l, int r) {
    for(; l < r && match[l] == r; l ++, r --) ;
    int lastshift = -1;
    for(int i = l; i <= r; i ++) {
        if(s[i] == '(') {
            i = match[i];
        } else if(s[i] == '>' && !bracket[i]) {
            lastshift = i;
        } else if(s[i] == 'S') {
            i = jmp[i];
        }
    }
    if(lastshift != -1) {
        return solve(l, lastshift - 2) >> min(31, solve(lastshift + 1, r));
    } else if(s[l] == 'S') {
        int ans = solve(l + 2, r - 1);
        return ans * 1LL * ans % mod;
    } else {
        int x = 0;
        for(int i = l; i <= r; i ++) {
            x = x * 10 + s[i] - '0';
        }
        return x;
    }
}
int main() {
//    freopen("in", "r", stdin);
    while(scanf(" %[^\n]", s) == 1) {
        if(s[0] == '#') break;
        int n = strlen(s), m = 0;
        for(int i = 0; i < n; i ++) {
            if(s[i] != ' ') {
                s[m ++] = s[i];
            }
        }
        n = m;
        s[n] = 0;
//        cout << s << endl;
        stack<int> sta;
        for(int i = 0; i < n; i ++) {
            match[i] = i;
            if(s[i] == '(') {
                sta.push(i);
            } else if(s[i] == ')') {
                int x = sta.top();
                sta.pop();
                match[x] = i;
            }
        }
        for(int i = 0; i < n; i ++) {
            bracket[i] = false;
            if(s[i] == '>') {
                bracket[i] = true;
            } else if(i > 0 && s[i - 1] == '>') {
                assert(s[i - 2] == '>');
                bracket[i - 1] = bracket[i - 2] = false;
            }
        }
        for(int i = 0; i < n; i ++) {
            jmp[i] = i;
            if(s[i] == 'S') {
                sta.push(i);
            } else if(bracket[i]) {
                int x = sta.top();
                sta.pop();
                jmp[x] = i;
            }
        }
        int ans = solve(0, n - 1);
        printf("%d\n", ans);
    }
    return 0;
}
accuracy: 1
time_ms: 1440
memory_kb: 5908
final_rank: 18

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

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

ll f(ll X, ll Y) {
    if (Y >= 64) return 0LL;
    else return X >> Y;
}

ll g(ll X) {
    return (X*X) % 1000000007;
}

ll expr(vector<ll>&, int&);

ll term(vector<ll>& A, int& X) {
    if (A[X] >= 0) {
        X--;
        return A[X+1];
    }
    else {
        X--;
        ll Ret = expr(A,X);
        X--;
        return g(Ret);
    }
}

ll expr(vector<ll>& A, int& X) {
    ll Ret = term(A,X);
    if (X >= 1 && A[X] == -1 && A[X-1] == -1) {
        X-=2;
        return f(expr(A,X),Ret);
    }
    return Ret;
}

int main() {
while(1) {
    string S;
    getline(cin,S);
    if (S == "#") return 0;
    vector<ll> A;
    bool B = false;
    rep(i,0,S.size()) {
        if (S[i] == ' ' || S[i] == 'S') continue;
        if (!isdigit(S[i])) {
            B = false;
            if (S[i] == '>') A.push_back(-1);
            if (S[i] == '<') A.push_back(-2);
        }
        else {
            if (B) A[A.size()-1] = A[A.size()-1] * 10 + (S[i]-'0');
            else A.push_back(S[i]-'0'), B = true;
        }
    }
    int X = A.size()-1;
    cout << expr(A,X) << endl;
}
}
accuracy: 1
time_ms: 20
memory_kb: 6732
final_rank: 13

code_snippet: /// 生成AI不使用 / Not using generative AI

// #pragma GCC target ("avx")
// #pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#ifdef MARC_LOCAL
#define _GLIBCXX_DEBUG
#endif

#ifdef ATCODER
#include <atcoder/all>
using namespace atcoder;
#endif

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

//#define int long long
using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vvvvll = vector<vvvll>;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vvvvi = vector<vvvi>;
using ld = long double; using vld = vector<ld>; using vvld = vector<vld>; using vd = vector<double>;
using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using pii = pair<int, int>; using pcc = pair<char, char>; using pll = pair<ll, ll>; using pli = pair<ll, int>; using pdd = pair<double, double>; using pldld = pair<ld,ld>;
using vpii = vector<pii>; using vvpii = vector<vpii>; using vpll = vector<pll>; using vvpll = vector<vpll>; using vpldld = vector<pldld>;
using ui = unsigned int; using ull = unsigned long long;
using i128 = __int128; using f128 = __float128;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define vv(type, name, h, ...) vector<vector<type> > name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type> > > name(h, vector<vector<type> >(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...) vector<vector<vector<vector<type> > > > name(a, vector<vector<vector<type> > >(b, vector<vector<type> >(c, vector<type>(__VA_ARGS__))))

#define overload4(a,b,c,d,name,...) name
#define rep1(n) for(ll i = 0; i < (ll)n; i++)
#define rep2(i,n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i,a,b) for (ll i = a; i < (ll)b; i++)
#define rep4(i,a,b,c) for (ll i = a; i < (ll)b; i += (ll)c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define repback1(n) for (ll i = (ll)n-1; i >= 0; i--)
#define repback2(i,n) for (ll i = (ll)n-1; i >= 0; i--)
#define repback3(i,a,b) for (ll i = (ll)b-1; i >= (ll)a; i--)
#define repback4(i,a,b,c) for (ll i = (ll)b-1; i >= (ll)a; i -= (ll)c)
#define repback(...) overload4(__VA_ARGS__,repback4,repback3,repback2,repback1)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define include(y, x, H, W) (0 <= (y) && (y) < (H) && 0 <= (x) && (x) < (W))
#define inrange(x, down, up) ((down) <= (x) && (x) <= (up))
#define pb push_back
#define eb emplace_back
#define fir first
#define sec second
#define TIMER_START TIME_START = clock()
#ifdef MARC_LOCAL
// https://trap.jp/post/1224/
#define debug1(x) cout << "debug L" << __LINE__ <<": " << (#x) << ": " << (x) << endl
#define debug2(x, y) cout << "debug L" << __LINE__ <<": " << (#x) << ": " << (x) << ", " << (#y) << ": " << (y) << endl
#define debug3(x, y, z) cout << "debug L" << __LINE__ <<": " << (#x) << ": " << (x) << ", " << (#y) << ": " << (y) << ", " << (#z) << ": " << (z) << endl
#define debug4(x, y, z, w) cout << "debug L" << __LINE__ <<": " << (#x) << ": " << (x) << ", " << (#y) << ": " << (y) << ", " << (#z) << ": " << (z) << ", " << (#w) << ": " << (w) << endl
#define debug5(x, y, z, w, v) cout << "debug L" << __LINE__ <<": " << (#x) << ": " << (x) << ", " << (#y) << ": " << (y) << ", " << (#z) << ": " << (z) << ", " << (#w) << ": " << (w) << ", " << (#v) << ": " << (v) << endl
#define debug6(x, y, z, w, v, u) cout << "debug L" << __LINE__ <<": " << (#x) << ": " << (x) << ", " << (#y) << ": " << (y) << ", " << (#z) << ": " << (z) << ", " << (#w) << ": " << (w) << ", " << (#v) << ": " << (v) << ", " << (#u) << ": " << (u) << endl
#define overload6(a, b, c, d, e, f, g,...) g
#define debug(...) overload6(__VA_ARGS__, debug6, debug5, debug4, debug3, debug2, debug1)(__VA_ARGS__)
#define debuga cerr << __LINE__ << endl
#define debugnl cout << endl
#define Case(i) cout << "Case #" << (i) << ": "
#define TIMECHECK cerr << 1000.0 * static_cast<double>(clock() - TIME_START) / CLOCKS_PER_SEC << "ms" << endl
#define LOCAL 1
#else
#define debug1(x) void(0)
#define debug2(x, y) void(0)
#define debug3(x, y, z) void(0)
#define debug4(x, y, z, w) void(0)
#define debug5(x, y, z, w, v) void(0)
#define debug6(x, y, z, w, v, u) void(0)
#define debug(...) void(0)
#define debuga void(0)
#define debugnl void(0)
#define Case(i) void(0)
#define TIMECHECK void(0)
#define LOCAL 0
#endif

//mt19937_64 rng(0);
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
clock_t TIME_START;
const long double pi = 3.141592653589793238462643383279L;
const long long INFL = 1000000000000000000ll;
const long long INFLMAX = numeric_limits< long long >::max(); // 9223372036854775807
const int INF = 1000000000;
const int INFMAX = numeric_limits< int >::max(); // 2147483647
const long double INFD = numeric_limits<ld>::infinity();
const long double EPS = 1e-10;
const int mod1 = 1000000007;
const int mod2 = 998244353;
const vi dx1 = {1,0,-1,0};
const vi dy1 = {0,1,0,-1};
const vi dx2 = {0, 1, 1, 1, 0, -1, -1, -1};
const vi dy2 = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr char nl = '\n';
constexpr char bl = ' ';

std::ostream &operator<<(std::ostream &dest, __int128_t value) { std::ostream::sentry s(dest); if (s) {__uint128_t tmp = value < 0 ? -value : value; char buffer[128]; char *d = std::end(buffer); do {--d;*d = "0123456789"[tmp % 10];tmp /= 10;} while (tmp != 0);if (value < 0) {--d;*d = '-';}int len = std::end(buffer) - d;if (dest.rdbuf()->sputn(d, len) != len) {dest.setstate(std::ios_base::badbit);}}return dest; }
__int128 parse(string &s) { __int128 ret = 0; for (int i = 0; i < (int)s.length(); i++) if ('0' <= s[i] && s[i] <= '9') ret = 10 * ret + s[i] - '0'; return ret; } // for __int128 (https://kenkoooo.hatenablog.com/entry/2016/11/30/163533)
template<class T> ostream& operator << (ostream& os, vector<T>& vec) { os << "["; for (int i = 0; i<(int)vec.size(); i++) { os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", "); } os << "]"; return os; } /// vector 出力
template<class T, class U> ostream& operator << (ostream& os, pair<T, U>& pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // pair 出力
template<class T, class U> ostream& operator << (ostream& os, map<T, U>& map_var) { os << "{"; for (auto itr = map_var.begin(); itr != map_var.end(); itr++) { os << "(" << itr->first << ", " << itr->second << ")"; itr++; if(itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // map出力
template<class T> ostream& operator << (ostream& os, set<T>& set_var) { os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) { os << *itr; ++itr; if(itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } /// set 出力

bool equals(long double a, long double b) { return fabsl(a - b) < EPS; }
template<class T> int sign(T a) { return equals(a, 0) ? 0 : a > 0 ? 1 : -1; }
long double radian_to_degree(long double r) { return (r * 180.0 / pi); }
long double degree_to_radian(long double d) { return (d * pi / 180.0); }

int popcnt(unsigned long long a){ return __builtin_popcountll(a); } // ll は 64bit対応！
int MSB1(unsigned long long x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); } // MSB(1), 0-indexed ( (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2) )
int LSB1(unsigned long long x) { return (x == 0 ? -1 : __builtin_ctzll(x)); } // LSB(1), 0-indexed ( (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2) )
long long maskbit(int n) { return (1LL << n) - 1; }
bool bit_is1(long long x, int i) { return ((x>>i) & 1); }
string charrep(int n, char c) { return std::string(n, c); }
template<class T> T square(T x) { return (x) * (x); }
template<class T>void UNIQUE(T& A) {sort(all(A)); A.erase(unique(all(A)), A.end());}
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; }
template<class T, class U> bool chmin(T& a, const U& b){ return chmin(a, (T)b); }
template<class T, class U> bool chmax(T& a, const U& b){ return chmax(a, (T)b); }
void YESNO(bool b) {if(b){cout<<"YES"<<'\n';} else{cout<<"NO"<<'\n';}} void YES() {YESNO(true);} void NO() {YESNO(false);}
void yesno(bool b) {if(b){cout<<"yes"<<'\n';} else{cout<<"no"<<'\n';}} void yes() {yesno(true);} void no() {yesno(false);}
void YesNo(bool b) {if(b){cout<<"Yes"<<'\n';} else{cout<<"No"<<'\n';}} void Yes() {YesNo(true);} void No() {YesNo(false);}
void POSIMPOS(bool b) {if(b){cout<<"POSSIBLE"<<'\n';} else{cout<<"IMPOSSIBLE"<<'\n';}}
void PosImpos(bool b) {if(b){cout<<"Possible"<<'\n';} else{cout<<"Impossible"<<'\n';}}
void posimpos(bool b) {if(b){cout<<"possible"<<'\n';} else{cout<<"impossible"<<'\n';}}
void FIRSEC(bool b) {if(b){cout<<"FIRST"<<'\n';} else{cout<<"SECOND"<<'\n';}}
void firsec(bool b) {if(b){cout<<"first"<<'\n';} else{cout<<"second"<<'\n';}}
void FirSec(bool b) {if(b){cout<<"First"<<'\n';} else{cout<<"Second"<<'\n';}}
void AliBob(bool b) {if(b){cout<<"Alice"<<'\n';} else{cout<<"Bob"<<'\n';}}
void TakAok(bool b) {if(b){cout<<"Takahashi"<<'\n';} else{cout<<"Aoki"<<'\n';}}
int GetTime() {return 1000.0*static_cast<double>(clock() - TIME_START) / CLOCKS_PER_SEC;}
ll myRand(ll B) {return (unsigned long long)rng() % B;}
template<class T> void print(const T& x, const char endch = '\n') { cout << x << endch; }

template<class T> T ceil_div(T x, T y) { assert(y); return (x > 0 ? (x + y - 1) / y : x / y); }
template<class T> T floor_div(T x, T y) { assert(y); return (x > 0 ? x / y : (x - y + 1) / y); }
template<class T> pair<T, T> divmod(T x, T y) { T q = floor_div(x, y); return {q, x - q * y}; } /// (q, r) s.t. x = q*y + r 
ll GCD(ll a, ll b) { if(a < b) swap(a, b); if(b == 0) return a; if(a%b == 0) return b; else return GCD(b, a%b); }
ll LCM(ll a, ll b) { assert(GCD(a,b) != 0); return a / GCD(a, b) * b; }
ll MOD(ll &x, const ll P) { ll ret = x%P; if(ret < 0) ret += P; return x = ret; } /// x % P を非負整数に直す
ll mpow(ll x, ll n, const ll mod) { x %= mod; ll ret = 1; while(n > 0) { if(n & 1) ret = ret * x % mod; x = x * x % mod; n >>= 1; } return ret; } /// x^n % mod を計算
ll lpow(ll x, ll n) { ll ret = 1; while(n > 0){ if(n & 1) ret = ret * x; x = x * x; n >>= 1; } return ret; } /// x^nを計算
string toBinary(ll n) { if(n == 0) return "0"; assert(n > 0); string ret; while (n != 0){ ret += ( (n & 1) == 1 ? '1' : '0' ); n >>= 1; } reverse(ret.begin(), ret.end()); return ret; } /// 10進数(long long) -> 2進数(string)への変換
ll toDecimal(string S) { ll ret = 0; for(int i = 0; i < (int)S.size(); i++){ ret *= 2LL; if(S[i] == '1') ret += 1; } return ret; } /// 2進数(string)　→　10進数(long long)への変換
int ceil_pow2(ll n) { int x = 0; while ((1ll << x) < n) x++; return x;} /// return minimum non-negative `x` s.t. `n <= 2**x`
int floor_pow2(ll n) { int x = 0; while ((1ll << (x+1)) <= n) x++; return x;} /// return maximum non-negative `x` s.t. `n >= 2**x`



// ############################
// #                          #
// #    C O D E  S T A R T    #
// #                          #
// ############################

typedef string::const_iterator State;

// 3つ先読みで、>>とS<>を区別できる（>>が競合することがあるが、>>の時は次の文字が S or number なので区別可能）
class ParseError : public std::exception {
    public:
        // デフォルトコンストラクタ
        ParseError() : message("Parse error") {}

        // コンストラクタ：カスタムエラーメッセージを持つ
        ParseError(const std::string& msg, int line = -1, int column = -1)
            : message(msg), line(line), column(column) {
            buildFullMessage();
        }

        // コンストラクタ：行と列情報を含む
        ParseError(int line, int column)
            : message("Parse error"), line(line), column(column) {
            buildFullMessage();
        }

        // エラーメッセージを取得するメンバ関数
        const char* what() const noexcept override {
            return fullMessage.c_str();
        }

        // 行番号を取得するメンバ関数
        int getLine() const {
            return line;
        }

        // 列番号を取得するメンバ関数
        int getColumn() const {
            return column;
        }

    private:
        std::string message;
        std::string fullMessage;
        int line;
        int column;

        // エラーメッセージを構築するプライベート関数
        void buildFullMessage() {
            std::ostringstream oss;
            oss << message;
            if (line >= 0) {
                oss << " at line " << line;
            }
            if (column >= 0) {
                oss << ", column " << column;
            }
            fullMessage = oss.str();
        }
};


/// begin が 期待される文字 expectedを指していたらbeginを一つ進める（期待する文字でなければエラー発生）
// assertのようなイメージ、デバッグ用（使用例: 式の最後に=が来るのであれば、consume(begin, '=')として最後まで到達してることを確認できる）
void consume(State& begin, const char expected) {
    if (*begin == expected) {
        begin++;
    }
    else {
        cerr << "Expected char is '" << expected << "' but got '" << *begin << "'" << endl;
        cerr << "Rest string is '";
        while (*begin) {
            cerr << *begin++;
        }
        cerr << "'" << endl;
        throw ParseError();
    }
}


long long expression(State& begin);
long long term(State& begin);
long long factor(State& begin);
long long number(State& begin);

string S;

/// 四則演算（64bit整数用）
long long expression(State& begin) {
    long long ret = term(begin);

    while(begin != S.end() && (begin+1) != S.end() && (begin+2) != S.end()) {
        if(*begin == '>' && *(begin+1) == '>' && (isdigit(*(begin+2)) || (*(begin+2)) == 'S')) {
            consume(begin,'>');
            consume(begin,'>');
            ll val = term(begin);
            ret = ret >> min(63ll,val);
        }
        else break;
    }

    return ret;
}

/// 乗除
long long term(State& begin) {
    long long ret;
    if(*begin == 'S') {
        consume(begin, 'S');
        consume(begin, '<');
        ll val = expression(begin);
        consume(begin, '>');
        ret = val*val%mod1;
    }
    else if(isdigit(*begin)) {
        ret = number(begin);
    }
    else {
        assert(false);
    }
    

    return ret;
}

/// 数
long long number(State& begin) {
    long long ret = 0;

    while(isdigit(*begin)) {
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }

    return ret;
}


void solve() {    
    // 空白除去    
    S.erase(remove_if(all(S), ::isspace), S.end());
    debug(S);

    State it = S.begin();
    cout << expression(it) << nl;

}



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

    int tt = 1;
    //cin >> tt;
    while(tt){
        getline(cin, S);
        if(S[0] == '#') break;
        solve();
    }

    TIMECHECK;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 6580
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = (int)1e9 + 1001010;
const ll llINF = (long long)4e18 + 22000020;
const string endn = "\n";
template <class T> inline auto vector2(size_t i, size_t j, const T &init = T()) {return vector(i, vector<T>(j, init));}
const string ELEM_SEPARATION = " ", VEC_SEPARATION = endn;
template<class T> istream& operator >>(istream &i, vector<T> &A) {for(auto &I : A) {i >> I;} return i;}
template<class T> ostream& operator <<(ostream &o, const vector<T> &A) {int i=A.size(); for(const auto &I : A){o << I << (--i ? ELEM_SEPARATION : "");} return o;}
template<class T> ostream& operator <<(ostream &o, const vector<vector<T>> &A) {int i=A.size(); for(const auto &I : A){o << I << (--i ? VEC_SEPARATION : "");} return o;}
template<class T> vector<T>& operator ++(vector<T> &A, int n) {for(auto &I : A) {I++;} return A;}
template<class T> vector<T>& operator --(vector<T> &A, int n) {for(auto &I : A) {I--;} return A;}
template<class T, class U> bool chmax(T &a, const U &b) {return ((a < b) ? (a = b, true) : false);}
template<class T, class U> bool chmin(T &a, const U &b) {return ((a > b) ? (a = b, true) : false);}
ll floor(ll a, ll b){if (b < 0) a = -a, b = -b; if(a >= 0) return a / b; else return (a + 1) / b - 1;}
ll ceil(ll a, ll b){if (b < 0) a = -a, b = -b; if(a > 0) return (a - 1) / b + 1; else return a / b;}
ll bit(unsigned long long val, unsigned long long digit){return (val >> digit) & 1;}
#ifdef DEBUG
#include <debug_slephy.cpp>
#else
#define debug(...)
#endif
// ================================== ここまでテンプレ ==================================


/*
 basic settings:
 　・vector<set<string>> OPERATORS
        - 登場する二項演算子と、その優先順位を設定する
 　・function<T(const string&, T, T)> OPERATION
        - 二項演算子に応じた二項演算の結果を出力する処理を設定する

 optional settings:
 　・function<T(const string&, int&)> GET_LEAF
        - 構文解析木において葉となる部分のパース方法を外部から指示したい場合に設定する
        - 第二引数は文字列中の index を表す
 　・string UNARY_OPERATORS
        - パースする文字列に単項演算子 ("-" や "log" など) が含まれる場合、その関数を表す文字列を設定
 　・function<T(T)> UNARY_OPERATION
        - パースする文字列に単項演算子 ("-" や "log" など) が含まれる場合、その関数の中身を設定

 usage:
 　・eval(const string &str, bool default_parse_numeric = true)
        - 与えられた文字列 S をパースして、計算結果を出力する
        - root, left, right などに構文解析木の構造が格納される (詳細は dump() を参照)
        - 引数 default_parse_numeric について
            - true：文字列 S 中の "927" などの通常の数値情報を long long 型にパースする
            - false：数値情報などをパースする関数オブジェクトを外部で定義して渡す
 　・dump()
        - 文字列 S の構文解析木を出力する
 */


// Parser (T must have constructor T(long long))
template<class T> struct Parser {
    /* basic settings */
    vector<vector<string>> OPERATORS;               // binary operator priority
    function<T(const string&, T, T)> OPERATION;     // binary operation

    /* optional settings */
    function<T(const string&, int&)> GET_LEAF;      // leaf parser
    vector<string> UNARY_OPERATORS;                 // unary operator (ex: "-", "log")
    function<T(const string&, T)> UNARY_OPERATION;  // unary operation
    const string OPERATOR_NUMBER = "num";

    /* result: parse tree */
    int root;                    // vals[root] is the answer
    vector<T> vals;              // value of each node
    vector<string> ops;          // operator of each node
    vector<int> left, right;     // the index of left-node, right-node
    vector<int> ids;             // the leaf-index of the i-th value, otherwise -1

    /* constructor */
    string S;
    Parser() {}
    Parser(const vector<vector<string>> &operators,
           const function<T(const string&, T, T)> operation) {
        init(operators, operation);
    }
    Parser(const vector<vector<string>> &operators,
           const function<T(const string&, T, T)> operation,
           const function<T(const string&, int&)> get_leaf) {
        init(operators, operation, get_leaf);
    }
    Parser(const vector<vector<string>> &operators,
           const function<T(const string&, T, T)> operation,
           const vector<string> &unary_operators,
           const function<T(const string &op, T)> unary_operation) {
        init(operators, operation, unary_operators, unary_operation);
    }
    Parser(const vector<vector<string>> &operators,
           const function<T(const string&, T, T)> operation,
           const function<T(const string&, int&)> get_leaf,
           const vector<string> &unary_operators,
           const function<T(const string &op, T)> unary_operation) {
        init(operators, operation, get_leaf, unary_operators, unary_operation);
    }
    void init(const vector<vector<string>> &operators,
              const function<T(const string&, T, T)> operation) {
        OPERATORS = operators, OPERATION = operation;
    }
    void init(const vector<vector<string>> &operators,
              const function<T(const string&, T, T)> operation,
              const function<T(const string&, int&)> get_leaf) {
        OPERATORS = operators, OPERATION = operation;
        GET_LEAF = get_leaf;
    }
    void init(const vector<vector<string>> &operators,
              const function<T(const string&, T, T)> operation,
              const vector<string> &unary_operators,
              const function<T(const string &op, T)> unary_operation) {
        OPERATORS = operators, OPERATION = operation;
        UNARY_OPERATORS = unary_operators, UNARY_OPERATION = unary_operation;
    }
    void init(const vector<vector<string>> &operators,
              const function<T(const string&, T, T)> operation,
              const function<T(const string&, int&)> get_leaf,
              const vector<string> &unary_operators,
              const function<T(const string &op, T)> unary_operation) {
        OPERATORS = operators, OPERATION = operation;
        GET_LEAF = get_leaf;
        UNARY_OPERATORS = unary_operators, UNARY_OPERATION = unary_operation;
    }
    void clear() {
        S = "";
        vals.clear(), ops.clear(), left.clear(), right.clear(), ids.clear();
    }

    /* eval */
    T eval(const string &str, bool default_parse_numeric = true) {
        clear();
        S = str;
        int p = 0, id = 0;
        root = parse(p, id, default_parse_numeric);
        return vals[root];
    }

    /* node generator */
    // value
    int new_leaf(T val, int &id) {
        vals.push_back(val);
        ops.push_back(OPERATOR_NUMBER);
        left.push_back(-1);
        right.push_back(-1);
        ids.push_back(id++);
        return (int)vals.size() - 1;
    }
    // FUNC(lp)
    int new_node_with_left(T val, const string &op, int lp) {
        vals.push_back(val);
        ops.push_back(op);
        left.push_back(lp);
        right.push_back(-1);
        ids.push_back(-1);
        return (int)vals.size() - 1;
    }
    // (lp) op (rp)
    int new_node_with_left_right(const string &op, int lp, int rp) {
        vals.push_back(OPERATION(op, vals[lp], vals[rp]));
        ops.push_back(op);
        left.push_back(lp);
        right.push_back(rp);
        ids.push_back(-1);
        return (int)vals.size() - 1;
    }

    /* parser */
    int parse(int &p, int &id, bool default_parse_numeric, int depth = 0) {
        assert(p >= 0 && p < (int)S.size());
        string op;
        if (depth < (int)OPERATORS.size()) {
            // recursive descent
            int lp = parse(p, id, default_parse_numeric, depth + 1);
            bool update = false;
            do {
                update = false;
                if (is_in_the_operators(p, op,
                                        OPERATORS[(int)OPERATORS.size() - depth - 1])) {
                    int rp = parse(p, id, default_parse_numeric, depth + 1);
                    lp = new_node_with_left_right(op, lp, rp);
                    update = true;
                }
            } while (p < (int)S.size() && update);
            return lp;
        }
        else if (default_parse_numeric && isdigit(S[p])) {
            return get_number(p, id);
        }
        else if (S[p] == '(') {
            return get_bracket(p, id, default_parse_numeric);
        }
        else if (is_in_the_operators(p, op, UNARY_OPERATORS)) {
            return get_unary_operation(p, id, op, default_parse_numeric);
        }
        else {
            return new_leaf(GET_LEAF(S, p), id);
        }
    }
    bool is_the_operator(int &p, const string &op) {
        if (op != "" && S.substr(p, op.size()) == op) {
            p += op.size();
            return true;
        }
        return false;
    }
    bool is_in_the_operators(int &p, string &res_op, const vector<string> &ops) {
        for (const auto &op : ops) {
            if (is_the_operator(p, op)) {
                res_op = op;
                return true;
            }
        }
        return false;
    }
    int get_number(int &p, int &id) {
        long long val = 0, sign = 1;
        if (S[p] == '-') sign = -1, ++p;
        while (p < (int)S.size() && isdigit(S[p])) {
            val = val * 10 + (int)(S[p++] - '0');
        }
        return new_leaf(T(val * sign), id);
    }
    int get_bracket(int &p, int &id, bool default_parse_numeric) {
        ++p;  // skip "("
        int lp = parse(p, id, default_parse_numeric, 0);
        ++p;  // skip ")"
        return lp;
    }
    int get_unary_operation(int &p, int &id, const string &op,
                            bool default_parse_numeric) {
        int lp;
        if (S[p] == '(') lp = get_bracket(p, id, default_parse_numeric);
        else lp = parse(p, id, default_parse_numeric, (int)OPERATORS.size());
        return new_node_with_left(UNARY_OPERATION(op, vals[lp]), op, lp);
    }

    /* dump */
    void dump() {
        dump_rec(root);
    }
    void dump_rec(int v, string space = "") {
        cout << space << v << ": (" << ops[v] << ", " << vals[v]
             << ") -> left: " << left[v] << ", right: " << right[v] << endl;
        if (left[v] != -1) dump_rec(left[v], space + "  ");
        if (right[v] != -1) dump_rec(right[v], space + "  ");
    }
};

const ll MOD = (ll)(1e9) + 7;
void solve(){
    string s; getline(cin, s);
    if(s == "#") exit(0);

    // スペースを削除
    {
        string tmp = "";
        for(auto c : s){
            if(c != ' ') tmp += c;
        }
        s = move(tmp);
    }
    debug(s);

    // >> を R に置換
    {
        string tmp = "";
        for(int i = (int)s.size() - 1; i >= 0;){
            tmp += s[i];
            if(i-2 >= 0 && (isdigit(s[i]) || s[i] == 'S') && s[i-1] == '>' && s[i-2] == '>'){
                tmp += 'R';
                i -= 3;
                continue;
            }
            else{
                i -= 1;
            }
        }
        reverse(tmp.begin(), tmp.end());
        s = tmp;
    }
    debug(s);

    // "<>" を () に置換
    {
        string tmp = "";
        for(auto c : s){
            if(c == '<') tmp += "(";
            else if(c == '>') tmp += ")";
            else tmp += c;
        }
        s = move(tmp);
    }
    debug(s);


    // parse
    vector<vector<string>> operators = {{"R"}};
    auto operation = [&](const string &op, ll left, ll right) -> ll {
        assert(op == "R");
        if(right >= 40) return 0;
        else return floor(left, (1LL<<right));
    };

    vector<string> unary_operators = {"S"};
    auto unary_operation = [&](const string &op, ll left) -> ll {
        assert(op == "S");
        return (left * left) % MOD;
    };

    Parser<ll> ps(operators, operation, unary_operators, unary_operation);
    ll ans = ps.eval(s);
    cout << ans << endl;
}

int main(int argc, char *argv[]){
    while(true) solve();
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 31124
final_rank: 16

code_snippet: /*
Shipura

Dr. SuposupoはShipuraと呼ばれるプログラミング言語を開発しました．
Shipuraは一つの二項演算子 >> と一つの単項関数 < > のみをサポートしています．

x >> y は floor(x / 2^y)（つまり，x / 2^y 以下の最大の整数）として評価され，
S < x > は x^2 mod 1000000007（つまり，x^2を1000000007で割った余り）として評価されます．

演算子 >> は左結合です．
例えば，式x >> y >> z は(x >> y) >> z として解釈され，x >> (y >> z) として解釈されません．
この括弧は実際のShipuraの式には現れません．

Shipuraの構文は次のように与えられます．

expr   ::= term | expr sp ">>" sp term
term   ::= number | "S" sp "<" sp expr sp ">"
sp     ::= "" | sp " "
number ::= digit | number digit
digit  ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
この構文の開始記号は expr で，Shipuraの式を表します．
また，number は先頭に余分なゼロを持たずに書かれる0から1000000000までの整数です．

Shipuraの式を評価するプログラムを書いてください．
*/

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

#define ll long long
const int MOD = 1e9 + 7;

class ParseError
{
};

// expr = term | expr ">>" term
// term = number | "S" "<" expr ">"

ll expr(const string &s, int &i);
ll term(const string &s, int &i);
ll number(const string &s, int &i);

// デバッグ用関数
void consume(const string &s, int &i, char expected)
{
    if (s[i] == expected)
    {
        i++;
    }
    else
    {
        cerr << "Expected '" << expected << "' but got '" << s[i] << "'" << endl;
        cerr << "Rest string is '";
        while (s[i])
        {
            cerr << s[i];
            i++;
        }
        cerr << "'" << endl;
        throw ParseError();
    }
}

// x >> y のパース
ll expr(const string &s, int &i)
{
    ll ret = term(s, i);
    while (i < s.size())
    {
        if (s[i] == '>' && i + 2 < s.size() && s[i + 1] == '>' && s[i + 2] != '>')
        {
            i += 2;
            int rhs = term(s, i);
            if (rhs < 62)
            {
                ret = ret / (1LL << rhs);
            }
            else
            {
                ret = 0;
            }
        }
        else
        {
            break;
        }
    }
    return ret;
}

// S < x > のパース
ll term(const string &s, int &i)
{
    if (s[i] == 'S')
    {
        i++;
        consume(s, i, '<');
        ll ret = expr(s, i);
        consume(s, i, '>');
        return ret * ret % MOD;
    }
    else if (isdigit(s[i]))
    {
        ll ret = number(s, i);
        return ret;
    }
    else
    {
        return 0;
    }
}

// 数のパース
ll number(const string &s, int &i)
{
    ll ret = 0;

    while (isdigit(s[i]))
    {
        ret *= 10;
        ret += s[i] - '0';
        i++;
    }

    return ret;
}

int main()
{
    while (1)
    {
        string s;
        // cinじゃなくてgetlineを使う
        getline(cin, s);
        if (s == "#")
        {
            break;
        }
        // 先にspを取り除く、天才
        string t;
        for (char c : s)
        {
            if (c != ' ')
            {
                t.push_back(c);
            }
        }
        int i = 0;
        ll ans = expr(t, i);
        cout << ans << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 5924
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(v) v.begin(),v.end()
#define dbg(x) cerr << #x << ": " << (x) << endl;
template<class F, class S>
ostream& operator<<(ostream& os, pair<F,S>& p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<class Iter>
void print(Iter beg, Iter end) {
    for (Iter itr = beg; itr != end; ++itr) {
        cerr << *itr << ' ';
    }
    cerr << '\n';
}
string s;
using State = string::iterator;
ll mod = 1e9 + 7;
ll expr(State& itr);
ll term(State& itr);
ll number(State& itr);

ll expr(State& itr) {
    ll res = term(itr);
    while (*itr == '^') {
        ++itr; ++itr;
        ll a = term(itr);
        res >>= min(63LL,a);
    }
    return res;
}
ll term(State& itr) {
    if (isdigit(*itr)) {
        return number(itr);
    } else {
        assert(*itr == 'S');
        ++itr; ++itr;
        auto res = expr(itr);
        assert(*itr == '>');
        ++itr;
        res = res * res % mod;
        return res;
    }
}
ll number(State& itr) {
    ll res = 0;
    while (isdigit(*itr)) {
        res *= 10;
        res += *itr - '0';
        ++itr;
    }
    return res;
}

ll solve() {
    getline(cin,s);
    if (s == "#") exit(0);

    int wi = 0;
    for (int ri=0; ri < s.size(); ++ri) {
        if (s[ri] != ' ') {
            s[wi] = s[ri];
            ++wi;
        }
    }
    s.resize(wi);
    // dbg(s);
    for (int i = 0; i+2 < s.size(); ++i) {
        if (s[i]=='>' && s[i+1]=='>' && (s[i+2]=='S' || isdigit(s[i+2]))) {
            s[i] = '^';
            s[i+1] = '^';
        }
    }
    // dbg(s);
    auto itr = s.begin();
    return expr(itr);
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    while (1) {
        cout << solve() << '\n';
    }
}
accuracy: 1
time_ms: 10
memory_kb: 4828
final_rank: 3

code_snippet: #line 2 "cp-library/src/cp-template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull  = unsigned long long;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
template < class T > bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template < class T > bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
template < class T, class U > T ceil (T x, U y) { return (x > 0 ? (x + y - 1) / y :           x / y); }
template < class T, class U > T floor(T x, U y) { return (x > 0 ?           x / y : (x - y + 1) / y); }
int popcnt(i32 x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(i64 x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }

#line 2 "cp-library/src/utility/rep_itr.hpp"
template < class T > struct itr_rep {
    T i, d;
    constexpr itr_rep(const T i) noexcept : i(i), d(1) {}
    constexpr itr_rep(const T i, const T d) noexcept : i(i), d(d) {}
    void operator++() noexcept { i += d; }
    constexpr int operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr_rep x) const noexcept { return d > 0 ? i < x.i : i > x.i; }
};

template < class T > struct rep {
    const itr_rep< T > s, t;
    constexpr rep(const T t) noexcept : s(0), t(t) {}
    constexpr rep(const T s, const T t) noexcept : s(s), t(t) {}
    constexpr rep(const T s, const T t, const T d) noexcept : s(s, d), t(t, d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};

template < class T > struct revrep {
    const itr_rep < T > s, t;
    constexpr revrep(const T t) noexcept : s(t - 1, -1), t(-1, -1) {}
    constexpr revrep(const T s, const T t) noexcept : s(t - 1, -1), t(s - 1, -1) {}
    constexpr revrep(const T s, const T t, const T d) noexcept : s(t - 1, -d), t(s - 1, -d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};
#line 3 "cp-library/src/utility/io.hpp"

/* 128bit integer */
istream& operator>>(istream& is, i128& x) {
    std::string s; is >> s;
    int pm = (s[0] == '-');
    x = 0;
    for(int i : rep(pm, int(s.size()))) x = x * 10 + (s[i] - '0');
    if(pm) x *= -1;
    return is;
}
ostream& operator<<(ostream& os, const i128& x) {
    if(x == 0) return os << '0';
    i128 y = x;
    if(y < 0) { os << '-'; y *= -1; }
    std::vector<int> ny;
    while(y > 0) { ny.push_back(y % 10); y /= 10; }
    for(int i : revrep(ny.size())) os << ny[i];
    return os;
}

template < class S, class T > istream& operator>>(istream& is,       std::pair< S, T >& x) { is >> x.first        >> x.second; return is; }
template < class S, class T > ostream& operator<<(ostream& os, const std::pair< S, T >& x) { os << x.first << " " << x.second; return os; }

namespace scanner {
    struct sca {
        template < class T > operator T() {
            T s; std::cin >> s; return s;
        }
    };
    struct vec {
        int n;
        vec(int n) : n(n) {}
        template < class T > operator std::vector< T >() {
            std::vector< T > v(n);
            for(T& x : v) std::cin >> x;
            return v;
        }
    };
    struct mat {
        int h, w;
        mat(int h, int w) : h(h), w(w) {}
        template < class T > operator std::vector< std::vector< T > >() {
            std::vector m(h, std::vector< T >(w));
            for(std::vector< T >& v : m) for(T& x : v) std::cin >> x;
            return m;
        }
    };
    struct speedup {
        speedup() {
            std::cin.tie(0);
            std::ios::sync_with_stdio(0);
        }
    } speedup_instance;
}
scanner::sca in() { return scanner::sca(); }
scanner::vec in(int n) { return scanner::vec(n); }
scanner::mat in(int h, int w) { return scanner::mat(h, w); }

namespace printer {
    void precision(int d) { std::cout << std::fixed << std::setprecision(d); }
    void flush() { std::cout.flush(); }
}

template < class T >
ostream& operator<<(ostream& os, const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) { os << a[i]; if(i != n - 1) os << ' '; }
    return os;
}

int print() { std::cout << '\n'; return 0; }
template < class head, class... tail > int print(head&& h, tail&&... t) {
    std::cout << h; if(sizeof...(tail)) std::cout << ' ';
    return print(std::forward<tail>(t)...);
}
template < class T > int print_n(const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) std::cout << a[i] << "\n";
    return 0;
}


#line 2 "cp-library/src/utility/key_val.hpp"

template < class K, class V >
struct key_val {
    K key; V val;
    key_val() {}
    key_val(K key, V val) : key(key), val(val) {}
    template < std::size_t Index >
    std::tuple_element_t< Index, key_val >& get() {
        if constexpr (Index == 0) return key;
        if constexpr (Index == 1) return val;
    }
};

namespace std {

template < class K, class V > struct tuple_size < key_val< K, V > > : integral_constant< size_t, 2 > {};
template < class K, class V > struct tuple_element < 0, key_val< K, V > > { using type = K; };
template < class K, class V > struct tuple_element < 1, key_val< K, V > > { using type = V; };

}
#line 2 "cp-library/src/utility/vec_op.hpp"
template < class T > key_val< int, T > max_of(const vector< T >& a) {
    int i = std::max_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class T > key_val< int, T > min_of(const vector< T >& a) {
    int i = std::min_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class S, class T > S sum_of(const vector< T >& a) {
    S sum = 0;
    for(const T x : a) sum += x;
    return sum;
}
template < class S, class T > vector< S > freq_of(const vector< T >& a, T L, T R) {
    vector< S > res(R - L, S(0));
    for(const T x : a) res[x - L] += 1;
    return res;
}
template < class S, class T > struct prefix_sum {
    vector< S > s;
    prefix_sum(const vector< T >& a) : s(a) {
        s.insert(s.begin(), S(0));
        for(int i : rep(a.size())) s[i + 1] += s[i];
    }
    // [L, R)
    S sum(int L, int R) { return s[R] - s[L]; }
};
#line 3 "cp-library/src/utility/heap.hpp"

template < class T > using heap_min = std::priority_queue< T, std::vector< T >, std::greater< T > >;
template < class T > using heap_max = std::priority_queue< T, std::vector< T >, std::less< T > >;

#line 27 "cp-library/src/cp-template.hpp"

#line 1 "cp-library/src/algorithm/bin_search.hpp"
template < class T, class F >
T bin_search(T ok, T ng, F f) {
    while(abs(ng - ok) > 1) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

template < class T, class F >
T bin_search_real(T ok, T ng, F f, int step = 80) {
    while(step--) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}
#line 2 "cp-library/src/algorithm/argsort.hpp"

template < class T > std::vector< int > argsort(const std::vector< T > &a) {
    std::vector< int > ids((int)a.size());
    std::iota(ids.begin(), ids.end(), 0);
    std::sort(ids.begin(), ids.end(), [&](int i, int j) {
        return a[i] < a[j] || (a[i] == a[j] && i < j);
    });
    return ids;
}
#line 1 "macro.hpp"
namespace macro {

using size_type = int;
template < class container > void  sort(container& a) { std::sort(std:: begin(a), std:: end(a)); }
template < class container > void rsort(container& a) { std::sort(std::rbegin(a), std::rend(a)); }
template < class container > void reverse(container& a) { std::reverse(std::begin(a), std::end(a)); }
template < class container > void unique(container& a) {
    std::sort(std::begin(a), std::end(a));
    a.erase(std::unique(std::begin(a), std::end(a)), std::end(a));
}
template < class container > container  sorted(const container& a) { container b = a;  sort(b); return std::move(b); }
template < class container > container rsorted(const container& a) { container b = a; rsort(b); return std::move(b); }
template < class container, class compare > void sort(container& a, const compare& cmp) { std::sort(std::begin(a), std::end(a), cmp); }
template < class container, class compare > container sorted(const container& a, const compare& cmp) { container b = a; sort(b, cmp); return std::move(b); }
template < class container, class value > size_type lower_bound(const container& a, const value& x) { return std::lower_bound(std::begin(a), std::end(a), x) - std::begin(a); }
template < class container, class value > size_type upper_bound(const container& a, const value& x) { return std::upper_bound(std::begin(a), std::end(a), x) - std::begin(a); }

const std::vector<std::pair<size_type, size_type>> dir4 = { {+1,  0}, {-1,  0}, { 0, +1}, { 0, -1} };
const std::vector<std::pair<size_type, size_type>> dir8 = { {-1, -1}, {-1,  0}, {-1, +1}, { 0, -1}, { 0, +1}, {+1, -1}, {+1,  0}, {+1, +1} };

#ifdef _DEBUG
#define debug(x) std::cout << "[" << __LINE__ << "] " << #x << ": " << x << std::endl
#else
#define debug(x)
#endif

template < class container > void concat(container& a, const container& b) {
    a.insert(std::end(a), std::begin(b), std::end(b));
}
std::vector<size_type> iota(const size_type n) {
    std::vector<size_type> I(n);
    std::iota(std::begin(I), std::end(I), 0);
    return I;
}
template < class container > std::vector<size_type> sort_idx(const container& a) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return a[i] < a[j] or (a[i] == a[j] and i < j); });
    return I;
}
template < class container, class compare > std::vector<size_type> sort_idx(const container& a, const compare& cmp) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return cmp(a[i], a[j]) or (a[i] == a[j] and i < j); });
    return std::move(I);
}

struct grid {
    using size_type = int;
    size_type H, W;
    grid(const size_type H, const size_type W) : H(H), W(W) {}
    bool contains(const size_type i, const size_type j) {
        return 0 <= i and i < H and 0 <= j and j < W;
    }
};

using f64 = long double;

} // namespace macro

using namespace macro;
#line 3 "A.cpp"

string s;
int i, n;

i64 expr();
i64 term();

i64 expr() {
    i64 x = term();
    while(s.substr(i, 2) == ">>" and (s[i + 2] == 'S' or isdigit(s[i + 2]))) {
        i++;
        i++;
        i64 y = term();
        if(y <= 32) {
            x >>= y;
        } else {
            x = 0;
        }
    }
    return x;
}

i64 term() {
    if(isdigit(s[i])) {
        i64 x = 0;
        while(i < n and isdigit(s[i])) {
            x = x * 10 + (s[i] - '0');
            i++;
        }
        return x;
    } else {
        assert(s[i] == 'S');
        i++;
        assert(s[i] == '<');
        i++;
        i64 x = expr();
        assert(s[i] == '>');
        i++;
        return x * x % 1'000'000'007;
    }
}

int main() {
    while(getline(cin, s)) {
        if(s == "#") return 0;
        
        string t = "";
        for(char c : s) if(c != ' ') t += c;
        s = move(t);
        n = s.size();
        i = 0;

        print(expr());
    }
}
accuracy: 1
time_ms: 10
memory_kb: 5460
final_rank: 7

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

using ll = long long;

ll expr(State &);
ll term(State &);
void sp(State &);
ll number(State &);

string t;

ll expr(State &begin) {
    ll res = term(begin);
    while(true) {
        if(*begin != '>' || *(begin + 1) != '>' || *(begin + 2) == '>' ||
           (begin + 2) >= t.end())
            break;
        begin++;
        begin++;
        res >>= min(term(begin), 60LL);
    }
    return res;
}
ll term(State &begin) {
    if(*begin == 'S') {
        begin++;
        begin++;
        ll x = expr(begin);
        begin++;
        return x * x % 1000000007;
    } else {
        return number(begin);
    }
}
ll number(State &begin) {
    ll res = 0;
    while(isdigit(*begin)) {
        res = res * 10 + *begin - '0';
        begin++;
    }
    return res;
}

int main() {
    while(true) {
        string s;
        getline(cin, s);
        if(s == "#") break;
        t.clear();
        for(char c : s)
            if(c != ' ') t += c;
        State begin = t.begin();
        cout << expr(begin) << endl;
    }
}
accuracy: 1
time_ms: 20
memory_kb: 5008
final_rank: 5

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

std::string eliminate_space(std::string line) {
    line.erase(std::remove_if(line.begin(), line.end(), [](char c) { return c == ' '; }), line.end());
    return line;
}

constexpr long long MOD = 1000000007;

long long shift(long long x, long long y) {
    while (x > 0 && y > 0) {
        x >>= 1;
        y--;
    }
    return x;
}

struct Parser {
    using CopyIter = std::string::const_iterator;
    using Iter = CopyIter&;

    std::string line;

    Parser(std::string line): line(line) {}

    void skip(Iter it, char c) {
        ++it;
    }

    bool isshift(CopyIter it) {
        if (it == line.end()) return false;
        if (*it != '>') return false;
        skip(it, '>');
        if (it == line.end()) return false;
        if (*it != '>') return false;
        skip(it, '>');
        return it != line.end() && (std::isdigit(*it) || *it == 'S');
    }

    long long parse() {
        auto it = line.cbegin();

        return expr(it);
    }

    long long expr(Iter it) {
        auto res = term(it);
        while (it != line.end() && isshift(it)) {
            skip(it, '>');
            skip(it, '>');
            res = shift(res, term(it));
        }
        return res;
    }

    long long term(Iter it) {
        if (*it == 'S') {
            skip(it, 'S');
            skip(it, '<');
            auto res = expr(it);
            res = res * res % MOD;
            skip(it, '>');
            return res;
        } else {
            return number(it);
        }
    }

    long long number(Iter it) {
        int res = 0;
        while (it != line.end() && std::isdigit(*it)) {
            res = 10 * res + digit(it);
        }
        return res;
    }

    long long digit(Iter it) {
        char c = *it;
        skip(it, c);
        return c - '0';
    }
};

int main() {
    std::string line;
    while (std::getline(std::cin, line)) {
        if (line == "#") break;
        line = eliminate_space(line);
        Parser parser(line);
        std::cout << parser.parse() << std::endl;
    }
}
accuracy: 1
time_ms: 20
memory_kb: 5172
final_rank: 6

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

string inp;
char *p;

void skip(char expected) {
  assert(*p == expected);
  p++;
}

int expr();
int term();
void sp();
int number();

int expr() {
  sp();
  int ret = term();
  while (sp(), string(p, p+2) == ">>" && (isdigit(p[2]) || p[2] == 'S')) {
    p += 2;
    sp();
    int t = term();
    ret = t >= 32 ? 0 : ret >> t;
  }
  return ret;
}

int term() {
  sp();
  if (isdigit(*p)) {
    return number();
  }
  skip('S');
  skip('<');
  int ret = expr();
  skip('>');
  return 1LL * ret * ret % 1'000'000'007;
}

void sp() {
  while (*p == ' ') p++;
}

int number() {
  sp();
  int ret = 0;
  while (isdigit(*p)) {
    ret = ret * 10 + *p++ - '0';
  }
  return ret;
}

int main() {
  while (true) {
    getline(cin, inp);
    if (inp[0] == '#') return 0;
    inp.erase(remove(all(inp), ' '), inp.end());
    p = &inp[0];
    int ans = expr();
    printf("%d\n", ans);
  }
}
accuracy: 1
time_ms: 20
memory_kb: 6180
final_rank: 11

code_snippet: #include <iostream>
#include <string>
#include <vector>
using namespace std;

const long long mod = 1000000007;
vector<string> Sequence;
vector<string> Parsed;
int dep[1000009];
vector<int> Slash[1000009];

void Initialize() {
	for (int i = 0; i < 1000009; i++) dep[i] = 0;
	for (int i = 0; i < 1000009; i++) Slash[i].clear();
	Sequence.clear();
	Parsed.clear();
}

long long Shift(long long a, long long b) {
	if (b >= 30) return 0;
	return (a >> b);
}

long long dfs(int cl, int cr) {
	if (cl == cr) return stoll(Parsed[cl]);

	// Init
	int curdep = dep[cl];
	int pos1 = lower_bound(Slash[curdep].begin(), Slash[curdep].end(), cl) - Slash[curdep].begin();
	int pos2 = lower_bound(Slash[curdep].begin(), Slash[curdep].end(), cr) - Slash[curdep].begin();
	vector<int> kugiri;
	kugiri.push_back(cl - 1);
	for (int i = pos1; i < pos2; i++) kugiri.push_back(Slash[curdep][i]);
	kugiri.push_back(cr + 1);

	// Case 1
	if (kugiri.size() >= 3) {
		vector<long long> res;
		for (int i = 0; i < kugiri.size() - 1; i++) res.push_back(dfs(kugiri[i] + 1, kugiri[i + 1] - 1));
		long long cur = res[0];
		for (int i = 1; i < res.size(); i++) {
			cur = Shift(cur, res[i]);
		}
		return cur;
	}

	// Case 2
	else {
		long long val = dfs(cl + 1, cr - 1);
		return val * val % mod;
	}
	return -1;
}

long long solve(string S) {
	string T = "";
	for (int i = 0; i < S.size(); i++) {
		if (S[i] != ' ') T += S[i];
	}
	S = T;

	// Step 1. Parse
	int cx = 0;
	while (cx < S.size()) {
		if (S[cx] == 'S') { Sequence.push_back("S<"); cx += 2; }
		else if (S[cx] == '>') {
			string T = "";
			while (cx < S.size()) {
				if (S[cx] != '>') break;
				T += S[cx];
				cx += 1;
			}
			Sequence.push_back(T);
		}
		else if (S[cx] >= '0' && S[cx] <= '9') {
			string T = "";
			while (cx < S.size()) {
				if (S[cx] < '0' || S[cx] > '9') break;
				T += S[cx];
				cx += 1;
			}
			Sequence.push_back(T);
		}
	}

	// Step 2. Parse Second
	for (int i = 0; i < Sequence.size(); i++) {
		if (Sequence[i][0] == '>') {
			int Limit = Sequence[i].size();
			if (i + 1 < Sequence.size()) Limit -= 2;
			for (int j = 0; j < Limit; j++) Parsed.push_back(">");
			if (Limit != Sequence[i].size()) Parsed.push_back(">>");
		}
		else {
			Parsed.push_back(Sequence[i]);
		}
	}

	// Step 3. Get Depth
	dep[0] = 0;
	for (int i = 0; i < Parsed.size(); i++) {
		dep[i + 1] = dep[i];
		if (Parsed[i] == "S<") dep[i + 1] += 1;
		if (Parsed[i] == ">") dep[i + 1] -= 1;
		if (Parsed[i] == ">>") Slash[dep[i + 1]].push_back(i);
	}

	// Step 4. DFS
	// for (int i = 0; i < Parsed.size(); i++) cout << i << " " << Parsed[i] << endl;
	return dfs(0, Parsed.size() - 1);
}

int main() {
	while (true) {
		Initialize();
		string str = "";
		while (str == "") {
			getline(cin, str);
		}
		if (str == "#") break;
		cout << solve(str) << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 200
memory_kb: 42892
final_rank: 20

code_snippet: # include <bits/stdc++.h>
# define len(v) (ll(std::size(v)))
# define all(v) std::begin(v), std::end(v)
# define rep(i, a, b) for (ll i = a; i < ll(b); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
string erase_all_space(string s) { s.erase(remove_if(all(s), [](char c){ return isspace(c); }), s.end()); return s; }

constexpr ll MOD = ll(1e9) + 7;

struct Parser {
   string s;
   int cur;

   Parser() = default;
   Parser(string _s) : s(erase_all_space(_s)) {
      cur = len(s) - 1;
   }

   ll parse() {
      return expr();
   }

   ll expr() {
      deque<ll> terms;
      terms.push_front(term());
      while (cur >= 0 && s[cur] != '<') {
         assert(s[cur--] == '>');
         assert(s[cur--] == '>');
         terms.push_front(term());
      }
      ll ret = terms[0];
      rep (i, 1, len(terms)) {
         ll y = terms[i];
         while (not (y == 0 || ret == 0)) {
            ret >>= 1;
            y--;
         }
      }
      return ret;
   }

   ll term() {
      if (isdigit(s[cur])) {
         return number();
      }
      else {
         assert(s[cur--] == '>');
         ll val = expr() % MOD;
         assert(s[cur--] == '<');
         assert(s[cur--] == 'S');
         val = (val * val) % MOD;
         return val;
      }
   }

   ll number() {
      deque<char> dq;
      for (; cur >= 0 && isdigit(s[cur]); cur--) {
         dq.push_front(s[cur]);
      }
      return stoll(string(all(dq)));
   }
};

int main() {
   while (true) {
      string s;
      getline(cin, s);
      if (s == "#") break;
      cout << Parser(s).parse() << endl;
   }
}
accuracy: 1
time_ms: 50
memory_kb: 34912
final_rank: 17

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

bool consume(const string &s, int &i, char c) {
    if (s[i] == c) {
        i++;
        return true;
    }
    return false;
}

void expect(const string &s, int &i, char c) {
    assert(s[i] == c);
    i++;
    return;
}

void sp(const string &s, int &i) {
    while (isspace(s[i])) i++;
    return;
}

long long expr(const string &s, int &i);
long long term(const string &s, int &i);
long long number(const string &s, int &i);

long long expr(const string &s, int &i) {
    long long res = term(s, i);
    while (1) {
        sp(s, i);
        if (s[i] == '>' && s[i+1] == '>') {
            int j = i + 2;
            sp(s, j);
            if (s[j] == '>' || j == (int)s.size()) {
                break;
            }
            i = j;
            long long y = term(s, i);
            while (res > 0 && y > 0) res >>= 1, y--;
        } else {
            break;
        }
    }
    return res;
}

long long term(const string &s, int &i) {
    if (consume(s, i, 'S')) {
        sp(s, i);
        expect(s, i, '<');
        sp(s, i);
        long long res = expr(s, i);
        sp(s, i);
        expect(s, i, '>');
        res = (res * res) % 1000000007;
        return res;
    } else {
        return number(s, i);
    }
}

long long number(const string &s, int &i) {
    long long res = 0;
    while (isdigit(s[i])) {
        res = 10 * res + s[i] - '0';
        i++;
    }
    return res;
}


int main() {
    while (1) {
        string s;
        getline(cin, s);
        if (s == "#") break;
        int i = 0;
        auto res = expr(s, i);
        cout << res << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 8652
final_rank: 14

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;

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;
}

#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;
}

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';
}

const ll mod = 1'000'000'007;
ll expr(State &);
ll term(State &);
ll number(State &);

ll expr(State &begin) {
    ll res = term(begin);
    while(*begin == '>' && *(begin + 1) == '>' && (isdigit(*(begin + 2)) || *(begin + 2) == 'S')) {
        consume(begin, '>');
        consume(begin, '>');
        ll shift = std::min(term(begin), ll(40));
        res >>= shift;
    }
    return res;
}

ll term(State &begin) {
    if(isdigit(*begin)) {
        return number(begin);
    }
    else {
        consume(begin, 'S');
        consume(begin, '<');
        ll res = expr(begin);
        consume(begin, '>');
        return (res * res) % mod;
    }
}

ll number(State &begin) {
    ll res = 0;
    while(isdigit(*begin)) {
        res *= 10;
        res += *begin - '0';
        consume(begin, *begin);
    }
    return res;
}

int main() {
    std::string s;
    while(std::getline(std::cin, s), !(s == "#")) {
        s += ';';
        {
            std::string t = "";
            for(auto c: s) {
                if(c == ' ') continue;
                t += c;
            }
            s = t;
        }
        State begin = s.begin();
        ll ans = expr(begin);
        std::cout << ans << '\n';
    }
}
accuracy: 1
time_ms: 20
memory_kb: 4824
final_rank: 4

code_snippet: //#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using QP = priority_queue<T,vector<T>,greater<T>>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T1,typename T2,typename T3>void anss(T1 x,T2 y,T3 z){ans(x!=y,x,z);};  
template<typename T>void debug(const T &v,ll h,ll w,string sv=" "){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout<<sv<<v[i][j];cout<<endl;}};
template<typename T>void debug(const T &v,ll n,string sv=" "){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout<<sv<<v[i];cout<<endl;};
template<typename T>void debug(const vector<T>&v){debug(v,v.size());}
template<typename T>void debug(const vector<vector<T>>&v){for(auto &vv:v)debug(vv,vv.size());}
template<typename T>void debug(stack<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(queue<T> st){while(!st.empty()){cout<<st.front()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(deque<T> st){while(!st.empty()){cout<<st.front()<<" ";st.pop_front();}cout<<endl;}
template<typename T>void debug(PQ<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(QP<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(const set<T>&v){for(auto z:v)cout<<z<<" ";cout<<endl;}
template<typename T>void debug(const multiset<T>&v){for(auto z:v)cout<<z<<" ";cout<<endl;}
template<typename T,size_t size>void debug(const array<T, size> &a){for(auto z:a)cout<<z<<" ";cout<<endl;}
template<typename T,typename V>void debug(const map<T,V>&v){for(auto z:v)cout<<"["<<z.first<<"]="<<z.second<<",";cout<<endl;}
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
template<typename T>void rearrange(vector<int>&ord, vector<T>&v){
  auto tmp = v;
  for(int i=0;i<tmp.size();i++)v[i] = tmp[ord[i]];
}
template<typename Head, typename... Tail>void rearrange(vector<int>&ord,Head&& head, Tail&&... tail){
  rearrange(ord, head);
  rearrange(ord, tail...);
}
template<typename T> vector<int> ascend(const vector<T>&v){
  vector<int>ord(v.size());iota(ord.begin(),ord.end(),0);
  sort(ord.begin(),ord.end(),[&](int i,int j){return v[i]<v[j];});
  return ord;
}
template<typename T> vector<int> descend(const vector<T>&v){
  vector<int>ord(v.size());iota(ord.begin(),ord.end(),0);
  sort(ord.begin(),ord.end(),[&](int i,int j){return v[i]>v[j];});
  return ord;
}
template<typename T> vector<T> inv_perm(const vector<T>&ord){
  vector<T>inv(ord.size());
  for(int i=0;i<ord.size();i++)inv[ord[i]] = i;
  return inv;
}
ll FLOOR(ll n,ll div){assert(div>0);return n>=0?n/div:(n-div+1)/div;}
ll CEIL(ll n,ll div){assert(div>0);return n>=0?(n+div-1)/div:n/div;}
ll digitsum(ll n){ll ret=0;while(n){ret+=n%10;n/=10;}return ret;}
ll modulo(ll n,ll d){return (n%d+d)%d;};
template<typename T>T min(const vector<T>&v){return *min_element(v.begin(),v.end());}
template<typename T>T max(const vector<T>&v){return *max_element(v.begin(),v.end());}
template<typename T>T acc(const vector<T>&v){return accumulate(v.begin(),v.end(),T(0));};
template<typename T>T reverse(const T &v){return T(v.rbegin(),v.rend());};
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int popcount(ll x){return __builtin_popcountll(x);};
int poplow(ll x){return __builtin_ctzll(x);};
int pophigh(ll x){return 63 - __builtin_clzll(x);};
template<typename T>T poll(queue<T> &q){auto ret=q.front();q.pop();return ret;};
template<typename T>T poll(priority_queue<T> &q){auto ret=q.top();q.pop();return ret;};
template<typename T>T poll(QP<T> &q){auto ret=q.top();q.pop();return ret;};
template<typename T>T poll(stack<T> &s){auto ret=s.top();s.pop();return ret;};
ll MULT(ll x,ll y){if(LLONG_MAX/x<=y)return LLONG_MAX;return x*y;}
ll POW2(ll x, ll k){ll ret=1,mul=x;while(k){if(mul==LLONG_MAX)return LLONG_MAX;if(k&1)ret=MULT(ret,mul);mul=MULT(mul,mul);k>>=1;}return ret;}
ll POW(ll x, ll k){ll ret=1;for(int i=0;i<k;i++){if(LLONG_MAX/x<=ret)return LLONG_MAX;ret*=x;}return ret;}
template< typename T = int >
struct edge {
  int to;
  T cost;
  int id;
  edge():id(-1){};
  edge(int to, T cost = 1, int id = -1):to(to), cost(cost), id(id){}
  operator int() const { return to; }
};

template<typename T>
using Graph = vector<vector<edge<T>>>;
template<typename T>
Graph<T>revgraph(const Graph<T> &g){
  Graph<T>ret(g.size());
  for(int i=0;i<g.size();i++){
    for(auto e:g[i]){
      int to = e.to;
      e.to = i;
      ret[to].push_back(e);
    }
  }
  return ret;
}
template<typename T>
Graph<T> readGraph(int n,int m,int indexed=1,bool directed=false,bool weighted=false){
  Graph<T> ret(n);
  for(int es = 0; es < m; es++){
    int u,v;
    T w=1;
    cin>>u>>v;u-=indexed,v-=indexed;
    if(weighted)cin>>w;
    ret[u].emplace_back(v,w,es);
    if(!directed)ret[v].emplace_back(u,w,es);
  }
  return ret;
}
template<typename T>
Graph<T> readParent(int n,int indexed=1,bool directed=true){
  Graph<T>ret(n);
  for(int i=1;i<n;i++){
    int p;cin>>p;
    p-=indexed;
    ret[p].emplace_back(i);
    if(!directed)ret[i].emplace_back(p);
  }
  return ret;
}

template <typename F>
class
#if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
  [[nodiscard]]
#endif  // defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
FixPoint final : private F
{
public:
  template <typename G>
  explicit constexpr FixPoint(G&& g) noexcept
    : F{std::forward<G>(g)}
    {}

  template <typename... Args>
  constexpr decltype(auto)
  operator()(Args&&... args) const
#if !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 9
  noexcept(noexcept(F::operator()(std::declval<FixPoint>(), std::declval<Args>()...)))
#endif  // !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 9
  {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};  // class FixPoint


#if defined(__cpp_deduction_guides)
template <typename F>
FixPoint(F&&)
  -> FixPoint<std::decay_t<F>>;
#endif  // defined(__cpp_deduction_guides)


namespace
{
  template <typename F>
#if !defined(__has_cpp_attribute) || !__has_cpp_attribute(nodiscard)
#  if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4)
  __attribute__((warn_unused_result))
#  elif defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_Check_return_)
  _Check_return_
#  endif  // defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4)
#endif  // !defined(__has_cpp_attribute) || !__has_cpp_attribute(nodiscard)
  inline constexpr decltype(auto)
  makeFixPoint(F&& f) noexcept
{
  return FixPoint<std::decay_t<F>>{std::forward<std::decay_t<F>>(f)};
}
}  // namespace

class UnionFind{
private:
  ::std::vector<int_fast32_t> par;
  size_t n;

public:
  UnionFind(){}
  UnionFind(size_t n):n(n){
    par.resize(n, -1);
  }

  uint_fast32_t find(uint_fast32_t x){
    return par[x] < 0 ? x : par[x] = find(par[x]);
  }

  size_t size(uint_fast32_t x){
    return -par[find(x)];
  }

  bool unite(uint_fast32_t x, uint_fast32_t y){
    x = find(x);
    y = find(y);
    if(x == y) return false;
    if(size(x) < size(y)) std::swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }

  bool same(uint_fast32_t x, uint_fast32_t y){
    return find(x) == find(y);
  }
};

ll number(const string& s, int &pos) {
  ll res = 0;
  while (pos < s.size() && isdigit(s[pos])) {
    res = res * 10 + s[pos++] - '0';
  }
  return res;
}

ll term(const string&, int&);

ll expr(const string& s, int &pos) {
  ll res = term(s, pos);

  while (pos + 2 < s.size() && s[pos] == '>' && s[pos + 2] != '>') {
    pos+=2;
    ll ret = term(s, pos);
    if (ret > 63) res = 0;
    else res >>= ret;
  }
  return res;
}

ll term(const string& s, int &pos) {
  if (s[pos] == 'S') {
    pos++;
    assert(s[pos++] == '<');
    ll ret = expr(s, pos);
    assert(s[pos++] == '>');

    return ret * ret % 1000000007;
  } else {
    return number(s, pos);
  }
}

int main() {
  string s;
  while (getline(cin, s) && s != "#") {
    string t;
    rep(i, 0, s.size()) {
      if (s[i] != ' ') t += s[i];
    }

    int pos = 0;
    cout << expr(t, pos) << endl;
  }
}
accuracy: 1
time_ms: 20
memory_kb: 6004
final_rank: 10

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

using namespace std;

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

pair<int, long long> solve(const string& s, int r) {
    int cnt = 0;
    while (s[r - 1] == '>') ++cnt, --r;

    long long x = -1;
    while (r) {
        vector<long long> st;
        if (x >= 0) st.push_back(x);
        while (r - 1 >= 0) {
            if (is_digit(s[r - 1])) {
                int l = r - 1;
                while (l > 0 and is_digit(s[l - 1])) --l;
                st.push_back(stoi(s.substr(l, r - l)));
                r = l;
            } else if (s[r - 1] == '>') {
                auto [l, val] = solve(s, r - 2);
                st.push_back(val);
                r = l;
            } else {
                break;
            }
        }
        long long v = st.back();
        st.pop_back();
        if (cnt == 0 and st.empty()) return { r, v };
        while (st.size()) v >>= min(32LL, st.back()), st.pop_back();
        while (cnt and r - 1 >= 0 and s[r - 1] == '<') {
            v = (v * v) % 1000000007;
            --r, --cnt;
        }
        x = v;
    }
    return { r, x };
}

int main() {
    while (true) {
        string s;
        getline(cin, s);
        if (s == "#") break;
        string t;
        for (char c : s) if (c != ' ' and c != 'S') t += c;
        cout << solve(t, t.size()).second << endl;
    }
}
accuracy: 1
time_ms: 30
memory_kb: 10504
final_rank: 15