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 <vector>
#include <string>

using namespace std;

int main() {
	int n;
	while (cin >> n, n) {
		vector<int> w(n);
		for (int i = 0; i < n; ++i) {
			string s; cin >> s;
			w[i] = s.size();
		}
		int ok[] = { 5,7,5,7,7 };
		for (int i = 0; i < n; ++i) {
			int sum = 0, now = 0, j = 0;
			while (now < 5 && sum < ok[now]) {
				sum += w[i + j++];
				if (sum == ok[now]) now++, sum = 0;
			}
			if (now == 5) {
				cout << i + 1 << endl;
				break;
			}
		}
	}

	return 0;
}

C++: #include<iostream>
#include<math.h>
#include<iomanip>
#include<string>
#include<fstream>
using namespace std;

int main(){
  //std::ifstream in("input.txt");
  //std::cin.rdbuf(in.rdbuf());
  int n;
  string inp;
  int set[5]={5,12,17,24,31};
  while(1){
    cin >> n;
    if(n==0)return 0;

    //int list[n];
    int shori[n];
    int size;
    int ans=0;
    //  int num=0;
    for(int i=0;i<n;i++){
      cin >> inp;
      size=inp.size();
      shori[i]=0;
      //cout << list[i] << endl;
      for(int j=0;j<=i;j++){
	if(shori[j]==-1)continue;
        for(int l=0;l<5;l++){
	  if(shori[j]<set[l]){
	    if(size<=set[l]-shori[j]){
	      shori[j]+=size;
	      break;
	    }else{
	      shori[j]=-1;
	    }
	  }
	}
	if(shori[j]==set[4]){
	  ans++;
	  shori[j]=-1;
	}
      }
   
    }
    cout << ans <<endl;
  }
      
}

C++: #include<cstdio>
using namespace std;

int n;
int s[40];

int size(char *w) {
  int counter = 0;
  while (w[counter] != 0) counter++;
  return counter;
}

bool ok(int f, int s) {
  if (s <= 5) return true;
  if (f >= 5 && s <= 12) return true;
  if (f >= 12 && s <= 17) return true;
  if (f >= 17 && s <= 24) return true;
  if (f >= 24 && s <= 31) return true;
  return false;
}

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) break;
    for (int i = 0; i < n; i++) {
      char w[15];
      scanf("%s", w);
      s[i] = size(w);
    }
    for (int i = 0; i < n; i++) {
      int sum = 0;
      for (int j = i; j < n; j++) {
        if (!ok(sum, sum + s[j])) break;
        sum += s[j];
        if (sum == 30) break;
      }
      if (sum == 31) {
        printf("%d\n", i + 1);
        break;
      }
    }
  }
}

C++: #include<iostream>
#define f(X) for(c=0;c<X;c+=v[p++]);if(c-X)continue;
using namespace std;
main(){
    for(int n;cin>>n,n;){
        int v[50],s,p,c;
        for(s=0;s<n;s++){string t;cin>>t;v[s]=t.size();}
        for(s=p=0;;p=++s){f(5);f(7);f(5);f(7);f(7);cout<<s+1<<endl;break;}
    }
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;


int main()
{
	int n,ans=0;
	int v[41];
	
	while(1){
		cin >> n;
		if(n==0)break;
		
		vector<string> s(n);
		
		for(int i=0;i<n;i++){
			cin >> s[i];
			v[i] = s[i].size();
		}
		
		for(int i=0;i<n-4;i++){
			int k=i,flag = 1;
			for(int j=i;j<n;j++){
				int a=0;
				for(int l=0;l<5;l++){
					if(k == n)break;
					if(a+v[k] == 5){
						k++;
						break;
					}else if(a+v[k] > 5){
						flag = 0;
						break;
					}else {
						a += v[k];
						k++;
					}
				}
				
				a = 0;
				for(int l=0;l<7;l++){
					if(k == n)break;
					if(a+v[k] == 7){
						k++;
						break;
					}else if(a+v[k] > 7){
						flag = 0;
						break;
					}else {
						a += v[k];
						k++;
					}
				}
				
				a = 0;
				for(int l=0;l<5;l++){
					if(k == n)break;
					if(a+v[k] == 5){
						k++;
						break;
					}else if(a+v[k] > 5){
						flag = 0;
						break;
					}else {
						a += v[k];
						k++;
					}
				}
				
				a = 0;
				for(int l=0;l<7;l++){
					if(k == n)break;
					if(a+v[k] == 7){
						k++;
						break;
					}else if(a+v[k] > 7){
						flag = 0;
						break;
					}else {
						a += v[k];
						k++;
					}
				}
				
				a = 0;
				for(int l=0;l<7;l++){
					if(k == n)break;
					if(a+v[k] == 7){
						k++;
						break;
					}else if(a+v[k] > 7){
						flag = 0;
						break;
					}else {
						a += v[k];
						k++;
					}
				}
				if(flag == 1)break;
			}
			if(flag == 1){
				ans = i+1;
				break;
			}
		}
		cout << ans << endl;
	}
	
		
		
		
		
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstdio>
#define F(i,n) for(int i=0;i<(int)(n);i++)
#define INF 100000000
#define ll long long

using namespace std;
typedef pair<int, int> P;
int n;
int b[50];
bool c(int r) {
	int g[] = { 5,7,5,7,7 };
	int d = 0, k;
	int q = 0;
	for (int j = r; j<n; j++) {
		if (k == 5)return true;
		d += b[j];
		if (d == g[q]) {
			d = 0;
			q++;
			continue;
		}
		else if (d < g[q])continue;
		else return false;
	}
}
int main() {
	string a;
	while (1) {
		cin >> n;
		if (n == 0)break;
		F(i, n) {
			cin >> a;
			b[i] = a.size();
		}
		F(i, n) {
			if 	(c(i)){
				cout << i + 1 << endl;
				break;
			}
		}
	}
	return 0;
}

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

using namespace std;

const vector<int> num = {5, 7, 5, 7, 7};

bool Check(int idx, const int n, const vector<int> &w) {
    int j = 0, sum = 0;
    for (int i = idx; i < n && j < 5; ++i) {
        sum += w[i];
        if (num[j] == sum) {
            ++j;
            sum = 0;
        }
        else if (num[j] < sum)
            return true;
    }

    return (j == 5) ? false : true;
}

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

    int n;
    string s;

    while (cin >> n, n) {
        vector<int> w(n);
        for (int i = 0; i < n; ++i) {
            cin >> s;
            w[i] = s.size();
        }

        int idx = 0;
        while (Check(idx, n, w))
            ++idx;

        cout << idx + 1 << endl;
    }

    return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
    int n;
    string s;
    int len[5] = {5,7,5,7,7};
    int count;
    int now;
    int ans;
    while(1){
        cin >> n;
        if(n==0) return 0;
        vector<int> w(n);
        for(int i=0;i<n;i++){
            cin >> s;
            w[i]=s.length();
        }
        ans=-1;
        for(int i=0;i<n;i++){
            count = 0;
            now = 0;
            for(int j=i;j<n;j++){
                count+=w[j];
                if(count==len[now]){
                    now++;
                    count=0;
                    if(now==5){
                        ans=i;
                    }
                }else if(count>len[now]){
                    break;
                }
            }
            if(ans != -1){
                break;
            }
        }
        cout << ans+1 << endl;
    }
    return 0;
}