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>
using namespace std;

int n, p[] = { 5, 7, 5, 7, 7 }, ans;
string s[40];

int main() {
	while (true) {
		cin >> n;
		if (!n)break;
		for (int i = 0; i < n; i++) {
			cin >> s[i];
		}
		ans = 0;

		for (int i = 0; i < n; i++) {
			int index = 0;
			int sum = 0;
			for (int j = i; j < n; j++) {
				sum += s[j].length();
				if (sum == p[index]) {//次に進む
					index++;
					sum = 0;
				}
				else if (sum > p[index]) {//もうあり得ない
					break;
				}

				if (index > 4) {
					ans = i + 1;
					break;
				}
			}

			if (ans > 0)break;
		}

		cout << ans << endl;
	}
}

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

int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0){
			break;
		}
		int len[40];
		for(int i=0;i<n;i++){
			string w;
			cin>>w;
			len[i]=w.size();
		}
		for(int j=i;j<n;j++){
			sum+=len[j];
			if(sum==5||sum==12||sum==17||sum==24||sum==31){
				sta++;
			}
			if(sta==5){
				flg=true;
				break;
			}else if(sum>=31){
				break;
			}
		}
		if(flg){
			cout<<i+1<<endl;
			break;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    while(true) {
        int N;
        std::cin >> N;
        if(N == 0) break;

        vector<string> S(N);
        REP(i, N) {
            std::cin >> S[i];
        }

        REP(i, N) {
            int tmp_i = i;
            auto f = [&](int num) {
                         int cnt = 0;
                         while(cnt < num) {
                             cnt += S[tmp_i].size();
                             tmp_i++;
                         }
                         return cnt != num ? false : true;
                     };
            if(f(5) && f(7) && f(5) && f(7) && f(7)) {
                std::cout << i + 1 << std::endl;
                break;
            }
        }
    }

    return 0;
}

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

int main(){
  while(1){
    int N, i, j, s = 0;
    scanf("%d", &N);
    if(N == 0){
      return 0;
    }
    vector<string> w(N);
    for(i = 0; i < N; i++){
      cin >> w[i];
      s += w[i].size();
    }
    vector<int> a(s + 1, 0);
    for(i = 0, j = 0; i < N; i++){
      a[j] = 1;
      j += w[i].size();
    }
    a[j] = 1;
/*    for(i = 0; i < a.size(); i++){
      printf("%d", a[i]);
    }
    printf("\n");
*/    s = 0;
    for(i = 0; i < N; i++){
//      printf("i = %d\n", i);
//      printf("s = %d\n", s);
      if(a[s] == 1 && a[s + 5] == 1 && a[s + 12] == 1 && a[s + 17] == 1 && a[s + 24] == 1 && a[s + 31] == 1){
        printf("%d\n", i + 1);
        break;
      }
      s += w[i].size();
    }
  }
}

C++: #include <iostream>
using namespace???std;
int main(){
  int a[]={5,7,5,7,7},n,i,j,c,k;
  while(cin>>n,n){
    string s[n];
    for(i=0;i<n;i++)cin>>s[i];
    for(i=0;i<n;i++){
      c=k=0;
      for(j=i;j<n;j++){
        c+=s[j].size();
        if(c==a[k]){
          c=0;
          if(++k==5)goto L:
        }
      }
    }
    L: if(k==5)cout<<i<<endl;
  }
}

C++: #include <bits/stdc++.h>
 
using namespace std;
 
int main() {
 
    int n;
    string w[40];
    int lens[] = {5, 7, 5, 7, 7};
 
    while(cin >> n, n) {
 
        for(int i = 0; i < n; ++i) {
            cin >> w[i];
        }
 
        for(int i = 0; i < n; ++i) {
 
            int len = 0, phrase = 0;
 
            for(int j = i; j < n; ++j) {
 
                len += w[j].size();
 
                if(len == lens[phrase]) {
                    len = 0;
                    ++phrase;
                    if(phrase == 5) {
                        cout << i + 1 << endl;
                        break;
                    }
                }
            }
 
            if(phrase == 5) {
                break;
            }
 
        }
 
    }
 
}

C++: #include<bits/stdc++.h>
int i,j,p,n,q,a[9]={5,7,5,7,7,-1},d[50];char s[50];
main(){for(;scanf("%d\n",&n),n;){for(i=0;i<n;)d[i++]=strlen(gets(s));
for(i=j=0;j<6;i++)for(p=i,j=q=0;q>=0&&(q=a[j]);)for(j++;q>0;)q-=d[p++];
printf("%d\n",i);
}}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cstdio>
using namespace std;
vector<int> T={5,7,5,7,7};
int solve(const vector<string>&v){
	for(int i=0;i<v.size();i++){
		for(int j=i,n=0,y=0;j<v.size();j++){
			n+=v[j].size();
			if(n==T[y]){
				if(++y==T.size())return i+1;
				n=0;
			}
		}
	}
	return -1;
}
int main(){
	int N;
	for(;cin>>N,N;){
		vector<string>v(N);
		for(int i=0;i<N;i++)cin>>v[i];
		printf("%d\n",solve(v));
	}
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
const double PI  = 3.1415926535897932384626433832795028841971;
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
string str[40];

void solve(){
	rep(i,n) cin >> str[i];
	rep(i,n){
		int cnt[5] = {5,7,5,7,7};
		for(int j = i; j < n; j++){
			rep(k,5){
				if(cnt[k] != 0){
					cnt[k] -= str[j].size();
					break;
				}
			}
		}
		bool ok = true;
		rep(j,5) if(cnt[j] != 0) ok = false;
		if(ok){
			cout << i+1 << endl;
			break;
		}
	}
}

int main(){
	while(cin >> n){
		if(n == 0) break;
		solve();
	}
}

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

using namespace std;

int solve(void);
int getItr(const int pos, const int length, vector<string> &w);

int main(void) {

	//FILE* fpin = freopen("data.txt", "r", stdin);

	while (solve()) {}

	return 0;

}

int solve(void) {

	int n;
	int len[] = { 5,7,5,7,7 };

	cin >> n;
	if (!n) { return 0; }

	vector<string> w(n);

	for (int i = 0; i < n; i++)
		cin >> w[i];

	for (int j = 0; j < n; j++) {
		int pos = -1 + j;
		for (int i = 0; i < 5; i++) {
			pos = getItr(pos, len[i], w);
			if (pos < 0) { break; }
			if (pos >= 0 && i == 4) {
				cout << j + 1 << endl;
				return 1;
			}
		}
	}

}

int getItr(const int pos, const int length, vector<string>& w)
{
	/*
		w???pos+1????????????????????????????????????
		?????????????????????????????????length????????£?????¨???,?????????????????????????????????????????????
		???????????????-1?????????
	*/
	int cnt = 0;
	for (int i = pos + 1; i < w.size(); i++) {
		cnt += w[i].length();
		if (cnt == length) { return i; }
	}
	return -1;
}