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;

#define int long long

signed main() {
  int n;
  while ( cin >> n, n ) {
    vector<string> w(n);
    for ( int i = 0; i < n; i++ ) cin >> w[i];

    for ( int i = 0; i < n; i++ ) {
      int id = 0;
      vector<int> tanku{5, 7, 5, 7, 7};      
      for ( int j = i; j < n; j++ ) {
	if ( tanku[id] == (int)w[j].size() ) {
	  id++;	  
	} else if ( tanku[id] > (int)w[j].size() ) {
	  tanku[id] -= (int)w[j].size();	  
	} else {
	  break;
	}
	if ( id == 5 ) break;	
      }

      if ( id == 5 ) {
	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];

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;

    for (int i = 0; i < n; ++i) {
      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;
            return 0;
          }
        }
        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 chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};


int len[50];
int ch[] = {0,5,7,5,7,7};

int main(){
	int n;
	while(1){
		cin >> n;
		if(n == 0) break;
		int ans = 0;
		for(int i = 1;i <= n;i++){
			string tmp;
			cin >> tmp;
			len[i] = tmp.length();
	//		cout << len[i] << endl;
		}
		for(int i = 1;i <= n;i++){
			int level = 1;
			int sum = len[i];
			int j = i;
			while(level != 6){
				j++;
				if(ch[level] == sum){
					level++;
					sum = len[j];
				}else if(ch[level] < sum){
					break;
				}else{
					sum += len[j];
				}
			}
			if(level == 6){
				ans = i;
				break;
			}else{
				continue;
			}
		}
		cout << ans << endl;
		
	}




}

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

int num[6]={5,7,5,7,7};
int n;
int t[55];

bool check(int a,int s=0,int i=0){
	if(s>num[i])return false;
	if(s==num[i])i++,s=0;
	if(i==5)return true;
	if(a>=n)return false;
	return check(a+1,s+t[a],i);
}

int main(){
	int i,j,k;
	int a,b,c;
	char ca[15];
	while(cin>>n){
		if(!n)break;
		for(i=0;i<n;i++){
			cin>>ca;
			t[i]=strlen(ca);
		}
		for(i=0;i<n;i++){
			if(check(i)){
				cout<<i+1<<endl;
				break;
			}
		}
	}
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
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;
	}


}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<sstream>
#include<queue>
#include<deque>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#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;
}

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

C++: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	cin >> N;
	while (N) {
		vector<int>num(N);
		vector<int>sum(N);
		for (int i = 0; i < N; i++) {
			string s;
			cin >> s;
			num[i] = s.size();
		}
		for (int i = 0; i < N; i++) {
			M = 0;
			K = 0;
			for (int j = i; j < N; j++) {
				M += num[j];
				if (M == 5 || M == 12 || M == 17 || M == 24 || M == 31) {
					K++;
				}
			}
			if (K == 5) {
				cout << i + 1 << endl;
				break;
			}
		}
		cin >> N;
	}

	return 0;
}