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 <string>
using namespace std;

int w[42]; // 1-origin
int n;
static const int secToNum[6] = {0, 5, 7, 5, 7, 7};

bool solve(int x) {
  int sum;
  for (int sec = 1; sec <= 5; sec++) {
    sum = 0;
    while (sum < secToNum[sec]) {
      sum += w[x];
      x++;
    }
    if (sum > secToNum[sec]) {
      return false;
    }
  }
  return true;
}

int main() {
  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }

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

    for (int i = 1; i <= n; i++) {
      if (solve(i)) {
        cout << i << endl;
        break;
      }
    }
  }

  return 0;
}

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

using namespace std;

int main() {
  int n;
  const int tank[] = {5, 7, 5, 7, 7};
  while (cin >> n && n) {
    vector<int> w(n);
    for (int i = 0; i < n; i++) {
      string ww;
      cin >> ww;
      w[i] = ww.length();
    }
    int ans = -1;

    for (int i = 0; i < n - 5; i++) {  //??????????????°?????????????????????
      int tmp = 0;
      int cnt = 0;
      for (int j = i; j < n; j++) {
        tmp += w[j];
        //cerr << tmp << " ";
        if (tmp < tank[cnt]) {
          //?¶???????????????§?????????????¬???????????????????
        } else if (tmp == tank[cnt]) {
          //????????????????????§?¬???????????????????
          tmp = 0;
          cnt++;
          if (cnt == 5) {
            // 57577????????£???
            ans = i + 1;
            goto FIN;
          }

        } else {
          //??¢???????????§??±???
          break;
        }
      }
      //cerr << endl;
    }

  FIN:
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
	vector<string> v;
	int n,t=0,count=0,tt;
	
	for (;;) {
		cin >> n;
		if (n == 0)break;
		v.resize(n);
		for (int i = 0; i < n; i++) cin >> v[i];
		
		for (int j = 0; j < n; j++) {
			for (int i = j; i < n; i++) {
				//cout << v[i].size() << endl;
				if (count == 0) {
					t += v[i].size();
					if (t == 5)count++;
					else if (t > 5) {
						count = 0;
						t = 0;
						break;
						
					}

				}
				else if (count == 1) {
					t += v[i].size();
					if (t == 12) count++;
					else if (t > 12) {
						count = 0;
						t = 0;
						break;
						
					}

				}
				else if (count == 2) {
					t += v[i].size();
					if (t == 17) count++;
					else if (t > 17) {
						t = 0;
						count = 0;
						break;
					}

				}
				else if (count == 3) {
					t += v[i].size();
					if (t == 24) count++;
					else if (t > 24) {
						t = 0;
						count = 0;
						break;
						
					}

				}
				else if (count == 4) {
					t += v[i].size();
					if (t == 31) {
						count++;
						break;
					}
					else if (t > 31) {
						t = 0;
						count = 0;
						break;
					}

					tt = j + 1;


				}
			}
			if (count == 5) {
				cout << tt << endl;
				t = 0;
				count = 0;
				break;
			}
		}
		


	}
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using pii = pair<int,int>;

template<typename T> ostream& operator<< (ostream& os,const vector<T>& vec){ os << "{"; for(T v:vec) os << v << ","; os << "}"; }
template<typename T> ostream& operator<< (ostream& os,const set<T>& st){ os << "{"; for(T v:st) os << v << ","; os << "}"; }
template<typename T,typename U> ostream& operator<< (ostream& os,const pair<T,U>& p){ os << "{" << p.first << "," << p.second << "}"; return os; }

int N;
string w[40];

int main(){
    while (true) {
        cin >> N;
        if (N == 0) break;
        for (int j = 0; j < N; ++j) {
            cin >> w[j];
        }

        int len[5] = {5, 7, 5, 7, 7};

        for (int j = 0; j < N; ++j) {
            int state = 0,acc = 0;
            for (int k = j; k < N && state < 5; ++k) {
                acc += (int)w[k].size();
                if (acc > len[state]) {
                    break;
                } else if (acc == len[state]) {
                    acc = 0; ++state;
                }
            }

            if (state == 5) {
                cout << (j+1) << endl;
                break;
            }
        }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#include <cassert>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define lINF LLONG_MAX/3
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repl(i,s,n) for(int i=(s);i<=(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define MP make_pair
#define debug(x) cout<<#x<<":"<<x<<endl
#define debug2(x,y) cout<<#x<<":"<<#y<<"="<<x<<":"<<y<<endl


void solve(int n){
    vector<string> w(n);
    rep(i,n) cin >> w[i];

    rep(i,n) repl(j,i+1,n-1) repl(k,j+1,n-1) repl(l,k+1,n-1) repl(m,l+1,n-1){
        string s;
        for(int x=i;x<j;x++) s+=w[x];
        if(s.size()!=5) continue;
        s.clear();
        for(int x=j;x<k;x++) s+=w[x];
        if(s.size()!=7) continue;
        s.clear();
        for(int x=k;x<l;x++) s+=w[x];
        if(s.size()!=5) continue;
        s.clear();
        for(int x=l;x<m;x++) s+=w[x];
        if(s.size()!=7) continue;
        s.clear();
        for(int x=m;x<n;x++){
            s += w[x];
            if(s.size()==7){
                cout << i+1 << endl;
                return;
            }
        }
    }
}

int main(){
    int n;
    while(cin>>n && n){
        solve(n);
    }
}

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

int main() {

	while (1) {
		int n;
		cin >> n;
		if (n == 0)
			break;

		string word;
		int *length = new int[n];
		int key[5] = { 5,7,5,7,7 };
		for (int i = 0; i < n; i++) {
			cin >> word;
			length[i] = word.size();
			cout << length[i] << endl;
		}

		int count = 0;
		int section = 0;
		int index = 0;
		int output = 0;
		int start = 0;
		bool found = false;
		while (index != n) {
			index = output;
			output++;

			while (count <= 5) {
				if (key[count] > section) {
					section += length[index++];
				}
				else if (key[count] == section) {
					section = 0;
					count++;
				}
				else {
					break;
				}

				if (count == 5) {
					cout << output << endl;
					found = true;
				}
			}
			count = 0;
			section = 0;
			if (found)
				break;
		}
	}
	return 0;
}