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 <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    int w[5] = {5, 7, 5, 7, 7};
    while (cin >> n && n){
        VI a(n);
        REP(i,n) {
            string s;
            cin >> s;
            a[i] = s.length();
        }
        REP(s,n){
            int x = 0, i = s, j = 0, f = 1;
            while (f){
                x += a[i];
                i++;
                if (x > w[j]) f = 0;
                if (x == w[j]){
                    x = 0;
                    j++;
                }
                if (j == 5) break;
            }
            if (f){
                cout << s+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++) {
			int idx = 0;
			ans = i;	
			vi check = {5,7,5,7,7};
			for (int j = i; j < n; j++) {
					if(check[idx] <= 0) {
						idx++;
					}
					if (idx == 6){
						break;
					}
					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>
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    auto c = vector<int>(n);
    for (int i = 0; i < n; ++i) {
      string w; cin >> w;
      c[i] = w.length();
    }
    auto solve = [&]() {
      for (int i = 0; i < n; ++i) {
        auto sum = vector<int>{5, 7, 5, 7, 7};
        int pos = 0;
        for (int j = i; j < n; ++j) {
          if (sum[pos] == 0) ++pos;
          if (pos == 5) return i + 1;
          if (sum[pos] > 0) sum[pos] -= c[j];
        }
        if (sum[pos] == 0 && pos + 1 == 5) return i + 1;
      }
      return 0;
    };
    cout << solve() << endl;
  }
  return 0;
}

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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --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(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

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 vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int tanku[] = {5,7,5,7,7};

int main() {
    int n;
    while (cin >> n, n) {
        vs S(n);
        REP(i, n) cin >> S[i];
        REP(start, n) {
            int idx = 0;
            int l = 0;
            FOR(i, start, n) {
                l += S[i].length();
                if (l > tanku[idx]) {
                    idx = 0;
                    l = 0;
                    break;
                } else if (l == tanku[idx]) {
                    idx++;
                    l = 0;
                    if (idx == 5) {
                        cout << start+1 << endl;
                        goto END;
                    }
                }
            }
        }
END: {}
    }
}

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

int main(){
  int n;
  int d_words[5]={5,7,5,7,7};
  while(cin>>n && n!=0){
    int* n_words=new int[n];
    for(int i=0;i<n;i++){
      string str;
      cin>>str;
      n_words[i]=str.size();
    }
    int start=0;
    int success=0;
    while(!success){
      int t_words=0;
      int tmp=start;
      int tmp2=0;
      while(1){
        tmp2+=n_words[tmp];
        if(tmp2==d_words[t_words]){
          t_words++;
tmp2=0;
          if(t_words==5){
            success=start+1;
            break;
          }
}else if(tmp2>d_words[t_words]){
            break;
          }
       
        tmp++;
      }
      start++;
    }
    cout<<success<<endl;
  }
}

C++: #include<iostream>
#include<vector>
#include<string>
using namespace std;
#define DBG cout<<"!"<<endl;
vector<int> size;
int fin=0;
void dfs(int flag,int count,int i,int now){
  switch(flag){
  case 0:case 2:
    if(count+size[i]>5)
      return;
    if(count+size[i]==5){
      if(flag==0){	
	flag=1;
      }
      if(flag==2)
	flag=3;
    }
    if(flag==0||flag==2)
      dfs(flag,count+size[i],i+1,now);
    else
      dfs(flag,0,i+1,now);
    break;
  case 1:case 3:
    if(count+size[i]>7)
      return;
    if(count+size[i]==7){
      if(flag==1)
	flag=2;
      if(flag==3)
	flag=4;
    }
    if(flag==1||flag==3)
      dfs(flag,count+size[i],i+1,now);
    else
      dfs(flag,0,i+1,now);
    break;
  case 4:
    if(count+size[i]>7)
      return;
    if(count+size[i]==7){
      fin=1;
      cout<<now<<endl;
      return;
    }
    dfs(flag,count+size[i],i+1,now);
  }
}
int main(){
  int n;
  fin=0;
  while(cin>>n,n!=0){
    string str2;
    for(int i=0;i<n;i++){
      cin>>str2;
      size.push_back(str2.size());
    }
    for(int i=0;i<n;i++){
      int flag;
      int cnt=size[i];
      int now=i+1;
      if(fin==1)
	break;
      if(cnt==5)
	flag=1;
      else
	flag=0;
      if(cnt>5)
	continue;
      dfs(flag,cnt,i+1,now);
    }
    size.clear();
  }
  return 0;
}