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 search(string s[]) {
  int count = 0;
  int t = 0;
  for (int i = 0; ; i++) {
    if (s[i].size() > 5) continue;
    int start = i;
    for (int j = i; ; j++) {
      t += s[j].size();
      if (count == 0 || count == 2) {
	if (t == 5) {
	  count++;
	  t = 0;
	} else if (t > 5) {
	  count = 0;
	  t = 0;
	  break;
	} 
      } else {
	if (t == 7) {
	  count++;
	  if (count == 5) return start;
	  t = 0;
	} else if (t > 7) {
	  count = 0;
	  t = 0;
	  break;
	}
      }
    }
  }
}


int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) return 0;

    string s[n];
    for (int i = 0; i < n; i++)
      cin >> s[i];
    
    int ans = search(s);
    cout << ans + 1 << endl;
  }
}

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

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

    if(n==0)
      break;

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

      len[i] = w.size();
    }

    for(int i=0; i<n; i++){
      bool flg = false;
      int sta = 0;
      int sum = 0;

      for(int j=i; j<n; j++){
	sum += len[j];

	if(sum==5 || sum==12 || sum==17 || sum==24 || sum==31){
	  sta++;
	}

	if(sta==5){
	  flg = true;
	  // cout << "OK" << endl;
	  break;
	}
	else if(sum>=31){
	  break;
	}
      }

      if(flg){
	cout << i+1 << endl;
	break;
      }
    }
    // cout << "Not OK" << endl;
  }

  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;
      if(ans==-1)continue;
      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]){
	  cout << j+1 << endl;
	  ans=-1;
	  break;
	}
      }
      
   
    }
 
  }
      
}

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

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

int main(){
    int n;
    while(cin >> n, n){
        int w[n];
        string s;
        for(int i = 0; i < n; i++){
            cin >> s;
            w[i] = s.length();
        }
        
        int ans;

        for(int i = 0; i < n; i++){
            int pos = 0, tmplen = 0;
            for(int j = i; j < n; j++){
                if(tmplen < a[pos]) tmplen += w[j];
                if(tmplen > a[pos]) break;
                if(tmplen == a[pos])    pos++, tmplen = 0;
                if(pos == 5){
                    ans = i;
                    break;
                }
            }
            if(pos == 5)    break;
        }

        cout << ans+1 << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef unsigned long long ll;
#define endl '\n'

template<typename T>
inline bool chmin(T& x, T a) {
	if (x >= a) { x = a; return true; }
	return false;
}

template<typename T>
inline bool chmax(T& x, T a) {
	if (x <= a) { x = a; return true; }
	return false;
}

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

	while (1) {
		int n; cin >> n;
		if (n == 0) { break; }
		vector<int> v(n, 0);
		for (int i = 0; i < n; i++) {
			string str; cin >> str;
			v[i] = str.size();
		}
		set<int> st;
		{
			int temp = 0;
			for (int i = 0; i < n; i++) {
				temp += v[i];
				st.insert(temp);
			}
		}
		int temp = 0;
		for (int i = 0; i < n; i++) {
			if (
				st.find(temp + 5) != st.end() &&
				st.find(temp + 12) != st.end() &&
				st.find(temp + 17) != st.end() &&
				st.find(temp + 24) != st.end() &&
				st.find(temp + 31) != st.end()
				) {
				cout << i + 1 << endl;
				break;
			}
			temp += v[i];
		}
	}

	return 0;
}

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

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) FOR((i),0,(n))

typedef long long ll;

const int INF=1e9+7;
const int MAX_N=1e2;
int data[MAX_N];
int s[5]={5,7,5,7,7};
int main(){
	int n;
	while(cin>>n && n){
		fill(data,data+MAX_N,0);
		rep(i,n){
			string str;
			cin>>str;
			data[i]=str.size();
		}
		int ans=0;
		rep(i,n){
			if(ans!=0)break;
			int k=0;
			rep(j,5){
				int tmp=0;
				while(tmp<s[j] && i+k<n){
					tmp+=data[i+k++];
				}
				if(tmp!=s[j])break;
				if(j==4)ans=i+1;
			}
		}
		cout<<ans<<endl;
	}
}

C++: #include <iostream>
using namespace std;
int main(){
  int a[]={5,7,5,7,7,-1},n,i,j,c,k;
  while(cin>>n,n){
    string s[n];
    for(i=0;i<n;i++)cin>>s[i];
    for(i=0;i<n;i++){
      c=k=0;
      for(j=i;j<n;j++){
        c+=s[j].size();
        if(c==a[k]){
          c=0;
          if(++k==5)cout<<i+1<<endl;
          }
        }
      }
    }
  }

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

#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) {
    for(T &a : v) is >> a; return is;
}

bool solve() {
    int n; cin >> n;
    if(n == 0) return 0;
    vector<string> s(n); cin >> s;

    rep(i, n) {
        vector<int> haiku = {5, 7, 5, 7, 7};
        reverse(all(haiku));
        repeat(j, i, n) {
            haiku.back() -= s[j].size();
            if(haiku.back() < 0) break;
            else if(haiku.back() == 0) {
                haiku.pop_back();
                if(haiku.size() == 0) {
                    cout << i + 1 << endl;
                    return 1;
                }
            }
        }
    }
    assert(0);
    return 1;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(solve());
    return 0;
}