alexjercan/bugnet huggingface dataset:
Problem p01086 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

static const double EPS = 1e-8;

int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};

int main() {
  int num_word;
  while (~scanf("%d", &num_word)) {
    if (num_word == 0)
      break;

    vector<string> words;
    for (int word_i = 0; word_i < num_word; word_i++) {
      string word;
      cin >> word;
      words.push_back(word);
    }
    int res = 0;
    for (int start = 0; start < num_word; start++) {
      bool has_end[256];
      memset(has_end, 0, sizeof(has_end));
      int pos = 0;
      for (int word_i = start; word_i < num_word; word_i++) {
        pos += words[word_i].size();
        has_end[pos] = true;
      }

      if (has_end[5] && has_end[5 + 7] && has_end[5 + 7 + 5] &&
          has_end[5 + 7 + 5 + 7] && has_end[5 + 7 + 5 + 7 + 7]) {
        res = start + 1;
        break;
      }
    }
    printf("%d\\n", res);
  }
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

static const double EPS = 1e-8;

int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};

int main() {
  int num_word;
  while (~scanf("%d", &num_word)) {
    if (num_word == 0)
      break;

    vector<string> words;
    for (int word_i = 0; word_i < num_word; word_i++) {
      string word;
      cin >> word;
      words.push_back(word);
    }
    int res = 0;
    for (int start = 0; start < num_word; start++) {
      bool has_end[50];
      memset(has_end, 0, sizeof(has_end));
      int pos = 0;
      for (int word_i = start; word_i < num_word; word_i++) {
        pos += words[word_i].size();
        has_end[pos] = true;
      }

      if (has_end[5] && has_end[5 + 7] && has_end[5 + 7 + 5] &&
          has_end[5 + 7 + 5 + 7] && has_end[5 + 7 + 5 + 7 + 7]) {
        res = start + 1;
        break;
      }
    }
    printf("%d\\n", res);
  }
}
Problem p01086 (C++) — buggy submission, verdict: Runtime Error

//
//  main.cpp
//  Short Phrase
//
//  Created by x15071xx on 2017/06/18.
//  Copyright ?? 2017??´ AIT. All rights reserved.
//

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
int main(int argc, const char *argv[]) {

  while (1) {
    int n, i, j;
    vector<string> str;
    cin >> n;

    if (n == 0) {
      break;
    }

    string tmp;
    for (i = 0; i < n; i++) {

      cin >> tmp;
      str.push_back(tmp);
    }

    for (i = 0; i < n; i++) {
      int flag = 0;
      j = 0;
      int numsum = 0;
      while (1) {
        if (flag == -1) {
          break;
        }

        if (flag == 5) {
          cout << i + 1 << endl;
          break;
        }

        numsum += str[i + j].length();

        //                if (i == 5) {
        //                    cout << numsum << str[i+j] <<endl;
        //                }
        if (flag == 0 || flag == 2) {

          if (numsum > 5) {
            flag = -1;
          } else if (numsum < 5) {
            j++;
          } else if (numsum == 5) {
            flag++;
            numsum = 0;
            j++;
          }
        } else {
          if (numsum > 7) {
            flag = -1;
          } else if (numsum < 7) {
            j++;
          } else if (numsum == 7) {
            flag++;
            numsum = 0;
            j++;
          }
        }
      }

      if (flag == 5) {
        break;
      }
    }
  }
  return 0;
}

Error: -11

Fixed submission:

//
//  main.cpp
//  Short Phrase
//
//  Created by x15071xx on 2017/06/18.
//  Copyright ?? 2017??´ AIT. All rights reserved.
//

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
int main(int argc, const char *argv[]) {

  while (1) {
    int n, i, j;
    vector<string> str;
    cin >> n;

    if (n == 0) {
      break;
    }

    string tmp;
    for (i = 0; i < n; i++) {

      cin >> tmp;
      str.push_back(tmp);
    }

    for (i = 0; i < n; i++) {
      int flag = 0;
      j = i;
      int numsum = 0;
      while (1) {
        if (flag == -1) {
          break;
        }

        if (flag == 5) {
          cout << i + 1 << endl;
          break;
        }

        numsum += str[i + j].length();

        //                if (i == 5) {
        //                    cout << numsum << str[i+j] <<endl;
        //                }
        if (flag == 0 || flag == 2) {

          if (numsum > 5) {
            flag = -1;
          } else if (numsum < 5) {
            j++;
          } else if (numsum == 5) {
            flag++;
            numsum = 0;
            j++;
          }
        } else {
          if (numsum > 7) {
            flag = -1;
          } else if (numsum < 7) {
            j++;
          } else if (numsum == 7) {
            flag++;
            numsum = 0;
            j++;
          }
        }
      }

      if (flag == 5) {
        break;
      }
    }
  }
  return 0;
}
Problem p01086 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  int n;
  int tanku[] = {5, 7, 5, 7, 7};
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    string a;
    vector<int> w(n);
    for (int i = 0; i < n; i++) {
      cin >> a;
      w[i] = a.size();
    }
    int plase;
    for (int i = 0; i < n; i++) {
      plase = i;
      int sum = 0;
      int k = 0;
      bool flag = false;
      for (int j = i; j < n; j++) {
        sum += w[j];
        if (sum > tanku[k])
          break;
        if (sum == tanku[k]) {
          k++;
          sum = 0;
        }
        if (k == 5) {
          flag = true;
          break;
        }
      }
      if (flag) {
        cout << i + 1 << endl;
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef pair<double, pair<string, int>> mypair;
string re(string a) {
  for (int i = 0; i < a.size(); i++) {
    a[i] = 'a' + ('z' - a[i]);
  }
  return a;
}
string eq(string a) {
  string b;
  for (int i = 0; i < 20; i++)
    b.push_back('A');
  for (int i = 0; i < a.size(); i++)
    b[i] = a[i];
  return b;
}
int main(void) {
  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    vector<string> l(n);
    vector<int> p(n), a(n), b(n), c(n), d(n), e(n), f(n), s(n), m(n);
    for (int i = 0; i < n; i++)
      cin >> l[i] >> p[i] >> a[i] >> b[i] >> c[i] >> d[i] >> e[i] >> f[i] >>
          s[i] >> m[i];
    vector<mypair> q(n);
    for (int i = 0; i < n; i++) {
      q[i].first = (double)(m[i] * f[i] * s[i] - p[i]) /
                   (a[i] + b[i] + c[i] + m[i] * (d[i] + e[i]));
      q[i].second.first = re(eq(l[i]));
      q[i].second.second = i;
    }

    sort(q.begin(), q.end(), greater<mypair>());

    for (int i = 0; i < n; i++) {
      cout << l[q[i].second.second] << endl;
    }
    cout << '#' << endl;
  }
  return 0;
}
Problem p01086 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n;

  while (cin >> n, n) {

    vector<string> w;
    for (int i = 0; i < n; ++i) {
      string tmp;
      cin >> tmp;
      w.push_back(tmp);
    }

    int flag = 0;
    int len = 0;
    int output = 100000000;
    for (int i = 0; i < n; ++i) {
      flag = 0;
      len = 0;
      for (int j = i; j < n; ++j) {
        len += w[j].size();
        if (flag == 0 || flag == 2) {
          if (len == 5) {
            len = 0;
            flag++;
          } else if (len > 5) {
            break;
          }
        } else {
          if (len == 7) {
            len = 0;
            flag++;
          } else if (len > 7) {
            break;
          }
        }
      }

      if (flag >= 5) {
        output = i + 1;
        break;
      }
    }

    cout << output << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;

  while (n) {
    vector<string> w;
    for (int i = 0; i < n; ++i) {
      string tmp;
      cin >> tmp;
      w.push_back(tmp);
    }

    int flag = 0;
    int len = 0;
    int output = 100000000;
    for (int i = 0; i < n; ++i) {
      flag = 0;
      len = 0;
      for (int j = i; j < n; ++j) {
        len += w[j].size();
        if (flag == 0 || flag == 2) {
          if (len == 5) {
            len = 0;
            flag++;
          } else if (len > 5) {
            break;
          }
        } else {
          if (len == 7) {
            len = 0;
            flag++;
          } else if (len > 7) {
            break;
          }
        }
      }

      if (flag >= 5) {
        output = i + 1;
        break;
      }
    }

    cout << output << endl;
  }
}
Problem p01086 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007
#define pb push_back

using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
int main() {
  while (1) {

    // cout << "n start" << endl;
    int n;
    cin >> n;
    if (n == 0)
      break;
    // cout << "n end" << endl;

    // cout << "init start" << endl;
    vector<string> str(n);
    for (int i = 0; i < n; i++) {
      cin >> str[i];
    }
    // cout << "init end" << endl;

    // cout << "for i start" << endl;
    int ans = 0;
    for (int i = 0; i < n; i++) {
      int idx = 0;
      ans = i;
      vi check = {5, 7, 5, 7, 7};
      for (int j = i; j < n; j++) {
        if (check[idx] <= 0) {
          idx++;
        }
        if (idx == 6) {
          break;
        }
        check[idx] -= str[j].size();
      }
      int sum = 0;
      for (int k = 0; k < 5; k++) {
        sum += check[k];
      }
      if (sum == 0) {
        break;
      }
    }
    ////cout << "for i end" << endl;
    cout << ans + 1 << endl;
    // cout << "end" << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007
#define pb push_back

using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
int main() {
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;

    vector<string> str(n);
    for (int i = 0; i < n; i++) {
      cin >> str[i];
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
      ans = i;
      vector<int> check = {5, 7, 5, 7, 7};
      int idx = 0;
      for (int j = i; j < n; j++) {
        if (check[idx] > 0) {
          check[idx] -= str[j].size();
        } else if (check[idx] <= 0) {
          idx++;
          check[idx] -= str[j].size();
        }
      }
      int sum = 0;
      for (int k = 0; k < 5; k++) {
        sum += check[k];
      }
      if (sum == 0) {
        break;
      }
    }
    cout << ans + 1 << endl;
  }

  return 0;
}
Problem p01086 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main() {

  while (true) {

    int n;
    cin >> n;
    if (n == 0) {
      return 0;
    }
    string str;
    int nums[41];

    for (int i = 0; i < n; i++) {
      cin >> str;
      nums[i] = str.size();
    }

    int start = 0;
    int tail = 0;
    int sum = 0;
    while (true) {
      while (tail < n && sum < (5 + 7 + 5 + 7 + 7)) {
        tail++;

        sum = 0;
        for (int i = start; i < tail; i++) {
          sum += nums[i];
        }
      }
      if (sum < (5 + 7 + 5 + 7 + 7)) {
        break;
      } else if (sum == (5 + 7 + 5 + 7 + 7)) {
        int ns[5] = {5, 7, 5, 7, 7};
        int s = start;
        int i = 0;
        while (i < 5) {
          if (nums[s] == ns[i]) {
            i++;
            s++;
          } else if (nums[s] > ns[i]) {
            break;
          } else {
            ns[i] = ns[i] - nums[s];
            s++;
          }
        }
        if (i == 5) {
          cout << start + 1 << endl;
          break;
        }
      }

      start++;
      sum = 0;
      for (int i = start; i < tail; i++) {
        sum += nums[i];
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:


#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main() {

  while (true) {

    int n;
    cin >> n;
    if (n == 0) {
      return 0;
    }
    string str;
    int nums[41];

    for (int i = 0; i < n; i++) {
      cin >> str;
      nums[i] = str.size();
    }

    int start = 0;
    int tail = 0;
    int sum = 0;
    while (true) {
      while (tail < n && sum < (5 + 7 + 5 + 7 + 7)) {
        tail++;

        sum = 0;
        for (int i = start; i < tail; i++) {
          sum += nums[i];
        }
      }
      if (sum < (5 + 7 + 5 + 7 + 7)) {
        break;
      } else if (sum == (5 + 7 + 5 + 7 + 7)) {
        int ns[5] = {5, 7, 5, 7, 7};
        int s = start;
        int i = 0;
        while (i < 5) {
          if (nums[s] == ns[i]) {
            i++;
            s++;
          } else if (nums[s] > ns[i]) {
            break;
          } else {
            ns[i] = ns[i] - nums[s];
            s++;
          }
        }
        if (i == 5) {
          cout << start + 1 << endl;
          break;
        }
      }

      while (start < tail && sum > (5 + 7 + 5 + 7 + 7)) {
        start++;

        sum = 0;
        for (int i = start; i < tail; i++) {
          sum += nums[i];
        }
      }
    }
  }

  return 0;
}
Problem p01086 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
int n, l[44];
char c[12];
int main() {
  while (scanf("%d", &n), n) {
    for (int i = 0; i < n; i++)
      scanf("%s", c), l[i] = strlen(c);
    for (int i = 0; i < n; i++) {
      int s = 0, v = 0;
      for (int j = i; j < n && s < 5; j++) {
        v += l[j];
        if (3 % (s + 1) == 0) {
          if (v > 5)
            break;
          else if (v == 5)
            s++, v = 0;
        } else {
          if (v > 7)
            break;
          else if (v == 7)
            s++, v = 0;
        }
      }
      if (s == 5) {
        printf("%d\\n", i + 1);
        break;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
int n, l[44];
char c[12];
int main() {
  while (scanf("%d", &n)) {
    for (int i = 0; i < n; i++)
      scanf("%s", c), l[i] = strlen(c);
    for (int i = 0; i < n; i++) {
      int s = 0, v = 0;
      for (int j = i; j < n && s < 5; j++) {
        v += l[j];
        if (3 % (s + 1) == 0) {
          if (v > 5)
            break;
          else if (v == 5)
            s++;
        } else {
          if (v > 7)
            break;
          else if (v == 7)
            s++;
        }
      }
      if (s == 5) {
        printf("%d\\n", i);
        break;
      }
    }
  }
}
Problem p01086 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;

int main() {
  int n;
  int d_words[5] = {5, 7, 5, 7, 7};
  while (cin >> n && n != 0) {
    int *n_words = new int[n];
    for (int i = 0; i < n; i++) {
      string str;
      cin >> str;
      n_words[i] = str.size();
    }
    int start = 0;
    int success = 0;
    while (!success) {
      int t_words = 0;
      int tmp = start;
      int tmp2 = 0;
      while (1) {
        tmp2 += n_words[tmp];
        if (tmp2 == d_words[t_words]) {
          t_words++;
          tmp2 = 0;
          if (t_words == 5) {
            success = start + 1;
            break;
          }
        } else if (tmp2 > d_words[t_words]) {
          break;
        }

        tmp++;
      }
      start++;
    }
    cout << success << endl;
  }
}


Error: -11

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

int main() {
  int n;
  int d_words[5] = {5, 7, 5, 7, 7};
  while (cin >> n && n != 0) {
    int *n_words = new int[n];
    for (int i = 0; i < n; i++) {
      string str;
      cin >> str;
      n_words[i] = str.size();
    }
    int start = 0;
    int success = 0;
    while (!success) {
      int t_words = 0;
      int tmp = start;
      int tmp2 = 0;
      while (1) {
        tmp2 += n_words[tmp];
        if (tmp2 == d_words[t_words]) {
          t_words++;
          if (t_words == 5) {
            success = start + 1;
            break;
          }
        } else if (tmp2 > d_words[t_words]) {
          break;
        }

        tmp++;
      }
      start++;
    }
    cout << success << endl;
  }
}
Problem p01086 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>

int n, len[40];
char word[11];

int solve(int pos) {
  int rest;
  rest = 5;
  while (rest > 0) {
    rest -= len[pos++];
    if (rest < 0)
      return 0;
  }
  rest = 7;
  while (rest > 0) {
    rest -= len[pos++];
    if (rest < 0)
      return 0;
  }
  rest = 5;
  while (rest > 0) {
    rest -= len[pos++];
    if (rest < 0)
      return 0;
  }
  rest = 7;
  while (rest > 0) {
    rest -= len[pos++];
    if (rest < 0)
      return 0;
  }
  rest = 7;
  while (rest > 0) {
    rest -= len[pos++];
    if (rest < 0)
      return 0;
  }
  return 1;
}

int main() {
  while (1) {
    scanf("%d\\n", &n);
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      scanf("%s\\n", word);
      len[i] = strlen(word);
    }
    for (int j = 0; j < n; j++) {
      if (solve(j)) {
        printf("%d\\n", j + 1);
        break;
      }
    }
  }
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>

int n, len[40];
char word[11];

int solve(int pos) {
  int rest;
  rest = 5;
  while (rest > 0) {
    rest -= len[pos++];
    if (rest < 0)
      return 0;
  }
  rest = 7;
  while (rest > 0) {
    rest -= len[pos++];
    if (rest < 0)
      return 0;
  }
  rest = 5;
  while (rest > 0) {
    rest -= len[pos++];
    if (rest < 0)
      return 0;
  }
  rest = 7;
  while (rest > 0) {
    rest -= len[pos++];
    if (rest < 0)
      return 0;
  }
  rest = 7;
  while (rest > 0) {
    rest -= len[pos++];
    if (rest < 0)
      return 0;
  }
  return 1;
}

int main() {
  while (1) {
    scanf("%d\\n", &n);
    for (int i = 0; i < n; i++) {
      scanf("%s\\n", word);
      len[i] = strlen(word);
    }
    for (int j = 0; j < n; j++) {
      if (solve(j)) {
        printf("%d\\n", j + 1);
        break;
      }
    }
  }
}
Problem p01086 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <queue>

#define REP(i, n) for (int i = 0; i < n; i++)
#define debug(x) cerr << #x << " = " << (x) << endl;

using namespace std;

int main() {
  while (1) {
    int n, j, count, i, ans;
    const int rule[5] = {5, 7, 5, 7, 7};
    string w[41];
    queue<pair<int, int>> kouho;

    cin >> n;
    if (n == 0)
      break;
    REP(i, n) cin >> w[i];
    ans = 0;

    while (ans < n) {
      j = 0;
      count = 0;
      i = ans;
      while (i < n) {
        count += w[i].length();
        // if (w[i].length() <= 5) kouho.push(make_pair(i,i));
        // debug(i);
        if (count == rule[j]) {
          // debug(count);
          // debug(j);
          if (j >= 4) {
            cout << ans + 1 << endl;
            ans = n;
            break;
          }
          count = 0;
          j++;
          i++;
        } else if (count > rule[j]) {
          ans++;
          break;
        } else {
          i++;
        }
      }
    }
    // cout << "------------" << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <queue>

#define REP(i, n) for (int i = 0; i < n; i++)
#define debug(x) cerr << #x << " = " << (x) << endl;

using namespace std;

int main() {
  while (1) {
    int n, j, count, i, ans;
    const int rule[5] = {5, 7, 5, 7, 7};
    string w[41];
    queue<pair<int, int>> kouho;

    cin >> n;
    if (n == 0)
      break;
    REP(i, n) cin >> w[i];
    j = 0;
    count = 0;
    i = 0;
    ans = 0;
    while (i < n) {
      count += w[i].length();
      if (w[i].length() <= 5)
        kouho.push(make_pair(i, i));
      // debug(i);
      if (count == rule[j]) {
        // debug(count);
        // debug(j);
        if (j >= 4) {
          cout << ans + 1 << endl;
          break;
        }
        count = 0;
        j++;
        i++;
      } else if (count > rule[j]) {
        count = 0;
        if (!kouho.empty()) {
          i = kouho.front().first;
          ans = kouho.front().second;
          kouho.pop();
          // cout << "pushed" << endl;
          j = 0;
        } else {
          i++;
          j = 0;
          ans = i;
        }
      } else {
        i++;
      }
    }
    // cout << "------------" << endl;
  }
  return 0;
}
Problem p01087 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;

string s[100];
int cur;
int dfs(int d) {
  int ret;
  if (isdigit(s[cur][d]))
    return s[cur++][d] - '0';
  else {
    if (s[cur][d] == '+') {
      ret = 0;
      ++cur;
      while (s[cur].size() == d + 2)
        ret += dfs(d + 1);
    } else if (s[cur][d] == '*') {
      ret = 1;
      ++cur;
      while (s[cur].size() == d + 2)
        ret *= dfs(d + 1);
    }
  }
  return ret;
}
int main() {
  int n;
  while (cin >> n, n) {
    cur = 0;
    rep(i, 100) s[i].clear();
    rep(i, n) cin >> s[i];
    cout << dfs(0) << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;

string s[100];
int cur;
int dfs(int d) {
  int ret;
  if (isdigit(s[cur][d]))
    return s[cur++][d] - '0';
  else {
    if (s[cur][d] == '+') {
      ret = 0;
      ++cur;
      while (s[cur].size() >= d + 2)
        ret += dfs(d + 1);
    } else if (s[cur][d] == '*') {
      ret = 1;
      ++cur;
      while (s[cur].size() >= d + 2)
        ret *= dfs(d + 1);
    }
  }
  return ret;
}
int main() {
  int n;
  while (cin >> n, n) {
    cur = 0;
    rep(i, n) s[i].clear();
    rep(i, n) cin >> s[i];
    cout << dfs(0) << endl;
  }
  return 0;
}