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 <bits/stdc++.h>

using namespace std;

int main(){
        int N;
        while (cin>>N,N) {
                vector<int>D(N);
                for (int i = 0; i < N; i++) {
                        string S;
                        cin>>S;
                        D[i] = S.length();
                }
                for (int i = 0; i < N; i++) {
                        int j = i;
                        int sum = 0;
                        while (sum<5) {
                                sum += D[j];
                                j++;
                        }
                        if (sum!=5) {
                                continue;
                        }
                        while (sum<12) {
                                sum += D[j];
                                j++;
                        }
                        if (sum!=12) {
                                continue;
                        }
                        while (sum<17) {
                                sum += D[j];
                                j++;
                        }
                        if (sum!=17) {
                                continue;
                        }
                        while (sum<24) {
                                sum += D[j];
                                j++;
                        }
                        if (sum!=24) {
                                continue;
                        }
                        while (sum<31) {
                                sum += D[j];
                                j++;
                        }
                        if (sum!=31) {
                                continue;
                        }
                        cout<<i+1<<endl;
                        break;
                }
        }
}

C++: #include <bits/stdc++.h>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    int ans = 0, key = 0, ke2 = 0;
    string s[n];
    rep(i, n) cin >> s[i];
    for (int i = 0; i < n; i++) {
      ans = 0;
      key = 0;
      for (int j = i; j < n; j++) {
        ans += s[j].size();
        if (ans == 5 && key == 0) {
          key = 1;
          ans = 0;
        } else if (ans > 5 && key == 0 || ans > 7 && key == 1 ||
                   ans > 5 && key == 2 || ans > 7 && key == 3 ||
                   ans > 7 && key == 4) {
          ans = 0;
          key = 0;
          break;
        } else if (ans == 7 && key == 1) {
          key = 2;
          ans = 0;
        } else if (ans == 5 && key == 2) {
          ans = 0;
          key = 3;
        } else if (ans == 7 && key == 3) {
          ans = 0;
          key = 4;
        } else if (ans == 7 && key == 4) {
          cout << i + 1 << endl;
          ke2 = 1;
          break;
        }
      }
      if (ke2 == 1)
        break;
    }
  }
  return 0;
}

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

#define rep(i, n, m) for(int i=n;i<m;i++)

using namespace std;

const int num[5] = {5,7,5,7,7};

int main() {
    int n;
    while(scanf("%d", &n) && n){
        int a[n+1];
        rep(i, 0, n){
            string s;
            cin >> s;
            a[i+1] = s.length();
        }

        int ans = -1;
        rep(i, 1, n+1){
            int num_i = 0, cnt = 0;
            rep(j, i, n+1){
                cnt += a[j];
                if(num[num_i] == cnt){
                    num_i++;
                    cnt = 0;
                    if(num_i == 5){
                        ans = i;
                        break;
                    }
                }else if(cnt > num[num_i]){
                    break;
                }
            }
            if(ans != -1) break;
        }

        printf("%d\n", ans);
    }
}

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

int main(void) {
  int n;
  int tanku[]={5,7,5,7,7};
  while (true) {
    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();
    }
    for (int i=0; i<n; 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;
}

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

int n, len, ans, cnt, tanka[5] = {5, 7, 5, 7, 7};
string s[50];
bool flag;

int main(void){ 
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (true) {
    cin >> n;
    if (n == 0) break;

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

    cnt = len = ans = 0;
    flag = false;

    for (int i = 0; i < n; ++i) {
      if (flag) break;

      ans = i + 1;
      len = 0;

      for (int j = i; j < n; ++j) {
        len += s[j].size();
        //cout << len << " " << s[j] << endl;

        if (len == tanka[cnt]) {
          cnt++;
          len = 0;
          if (cnt == 5) {
            cout << ans << endl;
            flag = true;
          }
        }
        else if (len < tanka[cnt]) {
          continue;
        }
        else if (len > tanka[cnt]) {
          len = 0;
          cnt = 0;
          break;
        }
      }

    }

      for (int i = 0; i < 49; ++i) s[i] = "";
  }

  return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int n;
  int flag[5]={5,7,5,7,7};
  while(cin >> n,n){
    string str;
    vector<int> cnt;
    rep(i,n){
      cin >> str;
      int tmp = str.size();
      cnt.push_back(tmp);
    }
    bool finish = false;
    rep(i,n){
      //cout << "#" << endl;
      int stage = 0;
      int sum = cnt[i];
      if(sum > flag[0]) continue;
      else if(sum == flag[0]) {
        stage++;
        sum = 0;
      }
      for(int j=i+1; j<n; j++){
        //cout << stage  << " " << sum << endl;
        sum += cnt[j];
        if(sum > flag[stage]) break;
        else if(sum == flag[stage]){
          stage++;
          sum = 0;
        }
        if(stage == 5) {
          cout << i+1 << endl;
          finish  = true;
          break;
        }
      }
      if(finish == true) break;
    }
  }
  return 0;
}