#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <deque>
using namespace std;
typedef long long ll;

const ll INF=1e9+5;

ll n;
string s;
ll res=0;
int r; //閉じ括弧のindexを保持

ll cal(int l){
    vector<ll> st;
    vector<char> sc;
    for(int i=l;i<s.size();i++){
        if(s[i]=='('){
            ll p=cal(i+1);
            st.push_back(p);
            i=r;
        }
        else if(s[i]=='+'||s[i]=='*'){
            sc.push_back(s[i]);
        }
        else if('0'<=s[i]&&s[i]<='9'){
            st.push_back(s[i]-'0');
        }
        else if(s[i]==')'){
            r=i;
            break;
        }
    }
    // 括弧の中身で尺取り
    ll now=st[0];
    int r1=1,r2=1;
    deque<ll> dq;
    deque<char> qc;
    dq.push_back(now);
    for(int i=0;i<st.size();i++){
        while(now<=n&&r1<st.size()){
            bool check=(now<n);
            if(sc[r1-1]=='+'){
                if(now+st[r1]>n)break;
                now+=st[r1];
                dq.push_back(st[r1]);
                qc.push_back(sc[r1-1]);
                r1++;
                if(check)r2=r1;
            }
            else{
                ll q=dq.back(); dq.pop_back();
                if(now-q+q*st[r1]>n){
                    dq.push_back(q);
                    break;
                }
                now-=q;
                q*=st[r1];
                now+=q;
                dq.push_back(q);
                qc.push_back(sc[r1-1]);
                r1++;
                if(check)r2=r1;
            }
        }
        if(now==n)res+=(r1-r2+1);
        if(qc.size()==0){
            dq.pop_back();
            dq.push_back(st[i+1]);
            now=st[i+1];
        }
        else if(qc.front()=='+'){
            now-=dq.front();
            dq.pop_front();
            qc.pop_front();
        }
        else{
            ll q=dq.front(); dq.pop_front();
            now-=q;
            q/=st[i];
            now+=q;
            dq.push_front(q);
            qc.pop_front();
        }
        r1=max(r1,i+2);
        r2=max(r2,i+2);
    }
    // 括弧の中身を計算して返す
    ll sum=0; ll last=st[0];
    for(int i=1;i<st.size();i++){
        if(sc[i-1]=='+'){
            sum+=last;
            last=st[i];
        }
        else{
            last*=st[i];
        }
        sum=min(sum,INF);
        last=min(last,INF);
    }
    sum+=last;
    sum=min(sum,INF);
    return sum;
}

void solve(){
    res=0;
    vector<ll> st;
    vector<char> sc;
    for(int i=0;i<s.size();i++){
        if(s[i]=='('){
            ll p=cal(i+1);
            st.push_back(p);
            i=r;
        }
        else if(s[i]=='+'||s[i]=='*'){
            sc.push_back(s[i]);
        }
        else{
            st.push_back(s[i]-'0');
        }
    }
    // 括弧を全部処理した後数式全体で尺取り
    // 上の丸々使ってOK
    ll now=st[0];
    int r1=1,r2=1;
    deque<ll> dq;
    deque<char> qc;
    dq.push_back(now);
    for(int i=0;i<st.size();i++){
        while(now<=n&&r1<st.size()){
            bool check=(now<n);
            if(sc[r1-1]=='+'){
                if(now+st[r1]>n)break;
                now+=st[r1];
                dq.push_back(st[r1]);
                qc.push_back(sc[r1-1]);
                r1++;
                if(check)r2=r1;
            }
            else{
                ll q=dq.back(); dq.pop_back();
                if(now-q+q*st[r1]>n){
                    dq.push_back(q);
                    break;
                }
                now-=q;
                q*=st[r1];
                now+=q;
                dq.push_back(q);
                qc.push_back(sc[r1-1]);
                r1++;
                if(check)r2=r1;
            }
        }
        if(now==n)res+=(r1-r2+1);
        if(qc.size()==0){
            dq.pop_back();
            dq.push_back(st[i+1]);
            now=st[i+1];
        }
        else if(qc.front()=='+'){
            now-=dq.front();
            dq.pop_front();
            qc.pop_front();
        }
        else{
            ll q=dq.front(); dq.pop_front();
            now-=q;
            q/=st[i];
            now+=q;
            dq.push_front(q);
            qc.pop_front();
        }
        r1=max(r1,i+2);
        r2=max(r2,i+2);
    }
    printf("%lld\n",res);
}

int main(){
    while(cin >> n,n){
        cin >> s;
        solve();
    }
}


Measured memory_bytes: 23228