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 <cstdio>
#include <cstring>
int n, l[44]; char c[12];
int main() {
	while (scanf("%d", &n), n) {
		for (int i = 0; i < n; i++) scanf("%s", c), l[i] = strlen(c);
		for (int i = 0; i < n; i++) {
			int s = 0, v = 0;
			for (int j = i; j < n && s < 5; j++) {
				v += l[j];
				if (3 % (s + 1) == 0) {
					if (v > 5) break;
					else if (v == 5) s++, v = 0;
				}
				else {
					if (v > 7) break;
					else if (v == 7) s++, v = 0;
				}
			}
			if (s == 5) {
				printf("%d\n", i + 1); break;
			}
		}
	}
}

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

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector<int> data(n);
		string s;
		for (int i = 0; i < n; i++) {
			cin >> s;
			data[i] = s.size();
		}
		/*for (int i = 0; i < n; i++) {
			cout << data[i] << endl;
		}*/
		for (int i = 0; i < n; i++) {
			int a[5] = {0};
			int cc = 0;
			bool h = true;
			a[0] = data[i];
			if (a[0] == 5) {
				cc++;
			} else if (a[0] > 5) {
				continue;
			}
			for (int j = i+1; j < n; j++) {
				a[cc] += data[j];
				if (cc == 0) {
					if (a[0] == 5) {
						cc++;
					} else if (a[0] > 5) {
						h = false;
						break;
					}
				} else if (cc == 1) {
					if (a[1] == 7) {
						cc++;
					} else if (a[1] > 7) {
						h = false;
						break;
					}
				} else if (cc == 2) {
					if (a[2] == 5) {
						cc++;
					} else if (a[2] > 5) {
						h = false;
						break;
					}
				} else if (cc == 3) {
					if (a[3] == 7) {
						cc++;
					} else if (a[3] > 7) {
						h = false;
						break;
					}
				} else {
					if (a[4] == 7) {
						cc++;
						break;
					} else if (a[4] > 7) {
						h = false;
						break;
					}
				}
			}
			if (h && cc == 5) {
				cout << i+1 << endl;
				break;
			}
		}
	}
	return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int main()
{
    int n;
    int a[5]={5,7,5,7,7};
    while(cin >>n,n)
    {
        vector<int> w(n);
        rep(i,n)
        {
            string s;
            cin >>s;
            w[i]=s.size();
        }

        int ans=-1;
        rep(i,n)
        {
            int ct=0;

            bool valid=false;
            int idx=0;
            for(int j=i; j<n; ++j)
            {
                ct+=w[j];
                if(ct==a[idx])
                {
                    ++idx;
                    ct=0;
                }
                else if(ct>a[idx]) break;


                if(idx==5)
                {
                    valid=true;
                    break;
                }
            }

            if(valid)
            {
                ans=i+1;
                break;
            }
        }

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

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstdio>
#define F(i,n) for(int i=0;i<(int)(n);i++)
#define INF 100000000
#define ll long long

using namespace std;
typedef pair<int, int> P;

bool c(int r,int f[50],int ma) {
 int g[] = { 5,7,5,7,7 };
 int d = 0;
 int q = 0;
 for (int j = r; j<ma; j++) {
  if (q == 5)return true;
  d += f[j];
  if (d == g[q]) {
   d = 0;
   q++;
   continue;
  }
  else if (d < g[q])continue;
  else return false;
 }
}
int main() {
 int n;
 int b[50];
 string a;
 while (1) {
  cin >> n;
  if (n == 0)break;
  F(i, n) {
   cin >> a;
   b[i] = a.size();
  }
  F(i, n) {
   if  (c(i,b,n)){
    cout << i + 1 << endl;
    break;
   }
  }
 }
 return 0;
}

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

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

	while (n)
	{
		vector<string> w;
		for (int i = 0;i < n;++i) {
			string tmp;
			cin >> tmp;
			w.push_back(tmp);
		}

		int flag = 0;
		int len = 0;
		int output = 100000000;
		for (int i = 0;i < n;++i) {
			flag = 0;
			len = 0;
			for (int j = i; j< n;++j) {
				len += w[j].size();
				if (flag == 0 || flag == 2) {
					if (len == 5) {
						len = 0;
						flag++;
					}
					else if (len > 5) {
						break;
					}
				}
				else {
					if (len == 7) {
						len = 0;
						flag++;
					}
					else if (len > 7) {
						break;
					}
				}
			}

			if (flag >= 5) {
				output = i + 1;
				break;
			}
		}

		cout << output << endl;
	}


}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

int n;
string w;
vector<string> vw;

bool solve(int p, int size) {
    int w_count = p;
    int tmp_count = 0;
    
    // 5
    for (int i = w_count; i < size; ++i, ++w_count) {
        tmp_count += vw[w_count].length();
        if (tmp_count == 5) break;
        if (tmp_count > 5) return false;
    }
    w_count++;

    // 7
    tmp_count = 0;
    for (int i = w_count; i < size; ++i, ++w_count) {
        tmp_count += vw[w_count].length();
        if (tmp_count == 7) break;
        if (tmp_count > 7) return false;
    }
    w_count++;

    // 5
    tmp_count = 0;
    for (int i = w_count; i < size; ++i, ++w_count) {
        tmp_count += vw[w_count].length();
        if (tmp_count == 5) break;
        if (tmp_count > 5) return false;
    }
    w_count++;

    // 7
    tmp_count = 0;
    for (int i = w_count; i < size; ++i, ++w_count) {
        tmp_count += vw[w_count].length();
        if (tmp_count == 7) break;
        if (tmp_count > 7) return false;
    } 
    w_count++; 
    
    // 7
    tmp_count = 0;
    for (int i = w_count; i < size; ++i, ++w_count) {
        tmp_count += vw[w_count].length();
        if (tmp_count == 7) break;
        if (tmp_count > 7) return false;
    }

    return true;
}

int main (int argc, char *argv[]) {
    while (cin>>n, n) {
        for (int i = 0; i < n; ++i) {
            cin>>w;
            vw.push_back(w);
        }
        for (int i = 0; i < n; ++i) {
            if (solve(i, n)) {
                cout<<i+1<<endl;
                break;
            }   
        }
        vw.clear();
    }

    return 0;
}