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 <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n;
	while (cin >> n, n) {
		vector<int> len(n);
		REP(i, n) {
			string s;
			cin >> s;
			len[i] = s.length();
		}
		int ans = 1;
		int idx = 0;
		int cnt=0;
		int no;
		while (1) {
			if (idx == 5)
				break;
			if (idx == 0 && cnt == 0)
				no = ans;
			cnt += len[no - 1];
			no++;
			if (idx == 0 || idx == 2) {
				if (cnt == 5) {
					idx++;
					cnt = 0;
					continue;
				}
				if (cnt > 5) {
					ans++;
					idx = 0;
					cnt = 0;
				}
			}
			else {
				if (cnt == 7) {
					idx++;
					cnt = 0;
					continue;
				}
				if (cnt > 7) {
					ans++;
					idx = 0;
					cnt = 0;
				}
			}
		}
		cout << ans << endl;
	}
}

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

int main(){
 while(true){
  int n;
  cin >> n;

  if(n==0) break;

  int len[n];
  for(int i=0; i<n; i++){
   string w;
   cin >> w;
   len[i] = w.size();
  }

  for(int i=0; i<n; i++){
   bool flag = false;
   int sta = 0; //区切り
   int sum = 0; //文字数の合計

   for(int j=i; j<n; j++){
    sum = sum + len[j];
    
    if(sum==5 || sum==12 || sum==17 || sum==24 || sum==31){
     sta++;
    }

    if(sta==5){
     flag = true;
     break;
    //}else if(sum>=31){
    // break;
    }
   }

   if(flag){
    cout << i+1 << endl;
    break;
   }
  }
 }

 return 0;
}

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

int main()
{
  int n;
  int cnt[50];
  int moji[5]={5,7,5,7,7};
  
  while(1){
    cin >> n;
    if(n==0) break;
    for(int i=0;i < n;i++){
      string str;
      cin >> str;
      cnt[i]=str.size();
    }
    
    int ans=-1;
    for(int i=0;i<n;i++){
      if(ans!=-1)continue;
      int now=0;
      int len=0;
      for(int j=i;j < n;j++){
	len+=cnt[j];
	if(len == moji[now]){
	  now++;
	  len=0;
	}else if(len > moji[now]){
	  break;
	}
	if(now==5){
	  ans=i;
	  break;
	}
      }
    }
    cout << ans+1 << endl;
  }
  return 0;
}

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

int main(){
  cin.tie(0);
ios::sync_with_stdio(false);
  int n,a,b,c,d,e,j;
  string w[40];
  while(true){
    cin >> n;
    if(n == 0) break;

    for(int i = 0; i < n; i++){
      cin >> w[i];
    }
    //cout << "n="<<n << endl;
    for(int i = 0; i < n - 4; i++){
      //start w[i] 5 7 5 7 7
      //cout << i << "=i" <<endl;
      a = 5;
      b = 7;
      c = 5;
      d = 7;
      e = 7;

      int j=i;
      bool flag = true;
      while(flag ){//5

        if(a - w[j].size() == 0){j++; break;}
        else if(j >= n){flag = false;}
        else if(a - w[j].size() > 0){a-=w[j].size(); j++;}
        else {flag = false;}
      }
      //cout << j << endl;
      while(flag){//7

        if(b - w[j].size() == 0){j++; break;}
        else if(j >= n ){flag = false;}
        else if(b - w[j].size() > 0){b-=w[j].size(); j++;}
        else {flag = false;}
      }
      //cout << j << endl;
      while(flag){//5

        if(c - w[j].size() == 0){j++; break;}
        else if(j >= n){flag = false;}
        else if(c - w[j].size() > 0){c-=w[j].size(); j++;}
        else {flag = false;}
      }
      //cout << j << endl;
      while(flag){//7

        if(d - w[j].size() == 0){j++; break;}
        else if(j >= n){flag = false;}
        else if(d - w[j].size() > 0){d-=w[j].size(); j++;}
        else {flag = false;}

      }
      //cout <<  j << endl;
      while(flag){//7

        if(e - w[j].size() == 0){  j++; break;}
        else if(j >= n){flag = false;}
        else if(e - w[j].size() > 0){  e -= w[j].size(); j++;}
        else {flag = false;}
      }
      if(flag){
        cout << i+1 << endl;
        break;
      }
    }
  }

  return 0;

}

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

using namespace std;

int check(vector<int> tanka){
	int roule[] = {5,7,5,7,7};
	int index = 0, i = 0, t = 0;
	int sum = 0;
	while(i < 5){
		do{
			sum += tanka[index+t];
			t++;
		}while(sum < roule[i]);
		if(sum > roule[i]){
			index++;
			i = 0;
			t = 0;
		}else{
			i++;
		}
		sum = 0;
	}
	return index+1;
}

int main(){
	vector<int> tanka;
	vector<int> res;
	int n;
	do{
		cin >> n;
		for(int i=0;i<n;i++){
			string tmp;
			cin >> tmp;
			tanka.push_back(tmp.size());
		}
		if(n > 0)
			res.push_back(check(tanka));
		tanka.clear();
		tanka.shrink_to_fit();
	}while(n > 0);

cout << "test" << endl;
	for(auto num : res){
		cout << num << endl;
	}
	
	return 0;
}