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++: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#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);
  }
}

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

int main() {
  int n;
  while (cin >> n, n) {
    auto c = vector<int>(n);
    for (int i = 0; i < n; ++i) {
      string w; cin >> w;
      c[i] = w.length();
    }
    auto solve = [&]() {
      for (int i = 0; i < n; ++i) {
        auto phrase = vector<int>{5, 7, 5, 7, 7};
        int idx = 0;
        for (int j = i; j < n; ++j) {
          if (phrase[idx] > 0) phrase[idx] -= c[j];
          if (phrase[idx] < 0) break;
          if (phrase[idx] == 0) ++idx;
          if (idx == 5) return i + 1;
        }
      }
      return 0;
    };
    cout << solve() << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>

using namespace std;

int main(void) {
    while (1) {
        int n;
        cin >> n;
        if (n == 0) break;

        int len[n + 1];
        for (int i = 1; i <= n; ++i) {
            string w;
            cin >> w;
            len[i] = w.length();
        }

        int cumulativesum[n + 1];
        cumulativesum[1] = len[1];
        for (int i = 2; i <= n; ++i) {
            cumulativesum[i] = cumulativesum[i - 1] + len[i];
        }

        bool cnt5 = false, cnt12 = false, cnt17 = false, cnt24 = false, cnt31 = false;
        int ans = 0;
        for (int i = 1; i <= n; ++i) {
//            for (int j = 1; j <= n; ++j) {
//                printf("%d ", cumulativesum[j]);
//            }
//            printf("\n");
            for (int j = i; j <= n; ++j) {
                if (cumulativesum[j] == 5) cnt5 = true;
                if (cumulativesum[j] == 12) cnt12 = true;
                if (cumulativesum[j] == 17) cnt17 = true;
                if (cumulativesum[j] == 24) cnt24 = true;
                if (cumulativesum[j] == 31) cnt31 = true;

                if (cnt5 && cnt12 && cnt17 && cnt24 && cnt31) ans = i;
            }
            if (ans != 0) break;
            for (int j = 1; j <= n; ++j) {
                cumulativesum[j] -= len[i];
            }
            cnt5 = false, cnt12 = false, cnt17 = false, cnt24 = false, cnt31 = false;
        }

        cout << ans << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>

using namespace std;

int main(){
  int n,a,b,c,d,e,j;
  string w[40];
  while(true){
    cin >> n;
    if(n == 0) break;

    for(int i = 0; i < n; i++){
      cin >> w[i];
    }
    //cout << "n="<<n << endl;
    for(int i = 0; i < n - 4; i++){
      //start w[i] 5 7 5 7 7
      //cout << i << "=i" <<endl;
      a = 5;
      b = 7;
      c = 5;
      d = 7;
      e = 7;

      int j=i;
      bool flag = true;
      while(flag ){//5

        if(a - w[j].size() == 0){j++; break;}
        else if(j >= n){flag = false;}
        else if(a - w[j].size() > 0){a-=w[j].size(); j++;}
        else {flag = false;}
      }
      //cout << j << endl;
      while(flag){//7

        if(b - w[j].size() == 0){j++; break;}
        else if(j >= n ){flag = false;}
        else if(b - w[j].size() > 0){b-=w[j].size(); j++;}
        else {flag = false;}
      }
      //cout << j << endl;
      while(flag){//5

        if(c - w[j].size() == 0){j++; break;}
        else if(j >= n){flag = false;}
        else if(c - w[j].size() > 0){c-=w[j].size(); j++;}
        else {flag = false;}
      }
      //cout << j << endl;
      while(flag){//7

        if(d - w[j].size() == 0){j++; break;}
        else if(j >= n){flag = false;}
        else if(d - w[j].size() > 0){d-=w[j].size(); j++;}
        else {flag = false;}

      }
      //cout <<  j << endl;
      while(flag){//7

        if(e - w[j].size() == 0){  j++; break;}
        else if(j >= n){flag = false;}
        else if(e - w[j].size() > 0){  e -= w[j].size(); j++;}
        else {flag = false;}
      }
      if(flag){
        cout << i+1 << endl;
        break;
      }
    }
  }

  return 0;

}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < n;i ++ )
#define ll long long

using namespace std;

// input
ll a[5];

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> t(5);
  t[0] = 5;
  t[1] = 7;
  t[2] = 5;
  t[3] = 7;
  t[4] = 7;
  while(true) {
    int num;
    cin >> num;
    if(num == 0)break;
    vector<string> w(num);
    rep(i,num){
        cin >> w[i];
    }
    bool ok = false;

    rep(i,num) {
        if(w[i].size() > 5)continue;
        string buf = "";
        int k = 0;
        for(int j = i; j < num; j++) {
            buf +=w[j];
            if(buf.size() == t[k]) {
                k++;
                buf = "";
            }
            else if(buf.size() > t[k])break;
            if(k == 5)ok =true;
        }
        if(ok) {
            cout << i+1 << endl;
            break;
        }
    }
  }
}