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>
#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;
    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;
        }
      }
    }
  }
  return 0;
}

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


int main(){
  while(1){
    int n;
    cin>>n;
    if(n==0) break;
    int a[50];
    string memo;
    lp(i,n){
      cin>>memo;
      a[i]=memo.size();
    }
    lp(i,n){
      int ans=0;
      int count=0,stats=0;
      for(int j=i;j<n;j++){
	if(stats==0||stats==2){
	  count+=a[j];
	  if(count==5){
	    stats++;
	    count=0;
	  }
	  if(count>5) break;
	}
	else if(stats==1||stats==3||stats==4){
	  count+=a[j];
	  if(count==7){
	    stats++;
	    count=0;
	  }
	  if(count>7) break;
	}
	if(stats==5) {
	  ans=1;
	  break;
	}
      }
      if(ans==1) {
	cout<<i+1<<endl;
	break;
      }
    }
  }
  return 0;
}

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>
#define INF 2000000000
#define int long long int
#define MOD 1000000007
#define pb push_back
#define cin1(n) (cin >> n)
#define cin2(a,b) (cin >> a >> b)
#define cin3(a,b,c) (cin >> a >> b >> c)
#define cout(n) (cout << n << endl)
#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define fr first 
#define sc second 
#define EPS (1e-10)

using namespace std;

typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector<pair<int,int>> vpii;
typedef vector<string> vs;
typedef vector<vector<string>> vss;
typedef pair<int,int> pii;

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int n,m;
int a,b;
int p,q;


signed main() {
	while(1){
		cin1(n);
		if (n == 0) break;
		
		vs str(n);
		for_(i,0,n) {
			cin1(str[i]);
		}
		
		int ans = 0;
		for_(i,0,n) {
			int idx = 0;
			ans = i;	
			vi check = {5,7,5,7,7};
			for_(j,i,n) {
					if(check[idx] <= 0) {
						idx++;
					}
					if (idx == 6){
						break;
					}
					check[idx] -= str[j].size();
					
			}
			int sum = 0;
			for_(k,0,5) {
				sum += check[k];
			}
			if (sum == 0){
				break;
			}

		}
		cout(ans+1);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;
const int mod = 1000000007;

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

    int N;
    while (1)
    {
        cin >> N;
        if (N == 0)
            break;
        vector<int> a(N);
        rep(i, N)
        {
            string s;
            cin >> s;
            a[i] = s.size();
        }
        int tanku[] = {5, 7, 5, 7, 7};
        int ans = 0;
        rep(i, N)
        {
            int now = 0, pos = 0;
            Rep(j, i, N)
            {
                int nxt = a[j];
                if (now + nxt == tanku[pos])
                {
                    pos++, now = 0;
                    if (pos == 5 && ans == 0)
                    {
                        ans = i + 1;
                        break;
                    }
                }
                else if (now + nxt > tanku[pos])
                    break;
                else
                    now += nxt;
            }
        }
        cout << ans << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N;
int tanka[5] = {5, 7, 5, 7, 7};

int main()
{
    while (cin >> N)
    {
        if (N == 0)
            return 0;
        vector<string> s(N);
        for (int i = 0; i < N; i++)
        {
            cin >> s[i];
        }
        int ans = 0;
        for (int i = 0; i < N; i++)
        {
            int j = i, len = 0, index = 0;
            while (index < 5 && j < N)
            {
                len += s[j].size();
                if (len == tanka[index])
                    index++, len = 0;
                else if (len > tanka[index])
                    break;
                j++;
            }
            if (index == 5)
            {
                cout << i + 1 << endl;
                break;
            }
        }
    }
}