Go: // Short Phrase(短句)
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1601&lang=jp
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	for {
		n := nextInt(sc)
		if n == 0 {
			break
		}

		var words []string
		for i := 0; i < n; i++ {
			words = append(words, nextString(sc))
		}

		res := 0
		for i := 0; i < n; i++ {
			tmpWords := words[i:]
			ok := checkRule(tmpWords, 0)
			if ok {
				res = i + 1
				break
			}
		}

		fmt.Println(res)
	}
}

var rule = [5]int{5, 7, 5, 7, 7}

func checkRule(words []string, depth int) bool {
	var shortPhrase = ""
	var i = depth

	if depth == 5 {
		return true
	}

	for len(words) > 0 {
		shortPhrase += words[0]
		words = words[1:]

		if rule[i] == len(shortPhrase) {
			return checkRule(words, i+1) // 短句のルールを満たしたので次の文節へ
		} else if rule[i] < len(shortPhrase) {
			return false // 文節の語数オーバー
		}
	}

	return false // 文節を満たす単語が足りない
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void solve(int N) {
    vector<string> S(N);
    for_each(ALL(S), [](string &s){cin >> s;});
    REP(i, N) {
        VI n{5, 7, 5, 7, 7};
        bool f = false;
        int id = 0;
        FOR(j, i, N) {
            n[id] -= (int)S[j].length();
            if (n[id] == 0) id++;
            if (n[id] < 0) break;
            if (id == 5) {
                f = true;
                break;
            }
        }
        if (f) {
            cout << i + 1 << endl;
            return;
        }
    }
    return;
}

signed main(void) {
    int n, m, p, a, b, c, x, y, z, q;
    string s;
    bool f = false;
    while (cin >> n, n) {
        solve(n);
        //return 0;
    }
}

C++: #include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define EPS 1e-10
#define INF 1000000
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;
typedef long long ll;

int main() {
	int n;
	while (1) {
		cin >> n;
		if (!n) {
			return 0;
		}
		int temp[] = {5, 7, 5, 7, 7};
		vector<string> s(n);
		for (int i = 0; i < n; i++) {
			cin >> s[i];
		}

		int stock = 0, pos = 0, ans = 0;
		for (int i = 0; i < n; i++) {
			stock = 0;
			pos = 0;
			for (int j = i; j < n; j++) {
				stock += s[j].size();
				if (stock == temp[pos]) {
					pos++;
					stock = 0;
				} else if (stock > temp[pos]) {
					break;
				}
				if (pos == 5) {
					ans = i + 1;
					break;
				}
			}
			if (ans > 0) {
				break;
			}
		}

		cout << ans << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+7;

int main() {
    while (true) {
      Int n;
      cin >> n;
      if (n == 0) break;
      vector<Int> x;
      for (Int i = 0; i < n; i++) {
          string s;
          cin >> s;
          x.emplace_back((Int)s.size());
      }
      for (Int i = 0; i < (Int)x.size(); i++) {
          Int a = 5, b = 7, c = 5, d = 7, e = 7;
          for (Int j = i; j < (Int)x.size(); j++) {
              if (a > 0) {
                  a -= x[j];
              }
              else if (b > 0) {
                  b -= x[j];
              }
              else if (c > 0) {
                  c -= x[j];
              }
              else if (d > 0) {
                  d -= x[j];
              }
              else if (e > 0) {
                  e -= x[j];
              }
              if (a < 0 || b < 0 || c < 0 || d < 0 || e < 0) break;
          }
          if (a == 0 && b == 0 && c == 0 && d == 0 && e == 0) {
              dump(i + 1);
              break;
          }
      }
    }
    return 0;
}

C++: #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;
}