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 <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 phrase = vector<int>{5, 7, 5, 7, 7};
        int idx = 0;
        for (int j = i; j < n; ++j) {
          if (phrase[idx] > 0) phrase[idx] -= c[j];
          if (phrase[idx] < 0) break;
          if (phrase[idx] == 0) ++idx;
          if (idx == 5) return i + 1;
        }
      }
      return 0;
    };
    cout << solve() << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
char s[50],a[9]={6,8,6,8,8};main(){for(int i,j,p,n,q;scanf("%d\n",&n),n;){for(i=0;i<n;s[i++]=strlen(gets(s+i)));for(i=j=0;j<6;i++)for(p=i,j=q=0;q+1;)for(q=a[j++]-1;q>0;q-=s[p++]);printf("%d\n",i);}}

C++: #include<bits/stdc++.h>
int i,j,p,n,q,a[9]={5,7,5,7,7,-1},d[50];char s[50];main(){
for(;scanf("%d\n",&n),n;){for(i=0;i<n;)d[++i]=strlen(gets(s));
for(i=1;;i++){for(p=i,j=0,q=0;q>=0;){q=a[j];for(j++;q>0;p++)q-=d[p];}if(j>5)break;}
printf("%d\n",i);
}}

C++: // 2016-12-12
#include <iostream>
#include <string>
using namespace std;

int main() {
	int t[5] = {5, 7, 5, 7, 7};
	int n, a[40];
	string s;
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			cin >> s;
			a[i] = s.length();
		}
		bool b = false;
		for (int i = 0; i < n; i++) {
			for (int j = i, k = 0, m = 0; j < n; j++) {
				m += a[j];
				if (m == t[k]) {
					k++;
					m = 0;
					if (k == 5) {
						b = true;
						break;
					}
				} else if (m > t[k]) {
					break;
				}
			}
			if (b) {
				cout << i + 1 << endl;
				break;
			}
		}
	}
	return 0;
}

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

using namespace std;

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

int main(){
	int n;
	while(cin >> n,n){
		vector<int> v;
		for(int i=0;i<n;i++){
			string s;
			cin >> s;
			v.emplace_back(s.size());
			//cout << s.size() << endl;
		}
		int sum=0;
		int idx=0;
		int start=0;
		for(int unsigned i=0;i<v.size();i++){
			sum+=v[i];
			//cout << v[i] << " " << sum << " " << d[idx] << " " << i << " " << " " << idx << " " << start << endl;
			if(sum == d[idx]){
				idx++;
				sum=0;
			} else if(sum > d[idx]){
				idx=0;
				i = start;
				start=i+1;
				sum=0;
			}
			if(idx >= 5){
				cout << start+1 << endl;
				break;
			}
		}
		//cout << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<n;i++)
int main(){
while(1){
ll n;
cin >>n;
if(n==0){
break;
}
string name[n];
REP(i,n){
cin>>name[i];
}
ll num[n];
REP(i,n){
num[i]=name[i].length();
}

REP(i,n){
ll len=0;
ll now=i;
while(len<5){
len+=num[now];
now++;
}

if(len==5){
len=0;
while(len<7){
len+=num[now];
now++;
}
if(len==7){
len=0;
while(len<5){
len+=num[now];
now++;
}
if(len==5){
len=0;
while(len<7){
len+=num[now];
now++;
}
if(len==7){
len=0;
while(len<7){
len+=num[now];
now++;
}
if(len==7){
cout<<i+1<<endl;
break;
}
}
}

}
}

}





}


return 0;
}

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

int main()
{
  int n;
  int len[101];
  string s;
  int num[5]={5,7,5,7,7};

  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin>>s;
      len[i]=s.length();
    }

    int ans=0;
    for(int i=0;i<n;i++){
      int sum=0,c=0;
      for(int j=i;j<n;j++){
	sum+=len[j];
	if(sum==num[c]){
	  sum=0;
	  c++;
	}
	else if(num[c]<sum)break;
	if(c==5)break;
      }
      if(c==5){
	ans=i;
	break;
      }
    }
    cout<<ans+1<<endl;
  }

  return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
typedef pair<int,int> P;

//-----------------------------------------------------------------------

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

    int n;
    while(cin>>n,n){
        vector<int> v(n);
        REP(i,n){
            string s; cin>>s;
            v[i]=s.size();
        }

        REP(i,n){
            int pos=i;
            int j,A[]={5,7,5,7,7};
            for(j=0;j<5;j++){
                int cnt=0;
                while(pos<n && cnt<A[j]) cnt+=v[pos++];
                if(cnt!=A[j]) break;
            }
            if(j==5){
                cout<<i+1<<endl; break;
            }
        }
    }
}

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


using namespace std;


bool solve()
{
	int n; cin >> n;
	vector<string> w(n);

	if (n == 0)return false;

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

	for (int i = 0; i < w.size(); ++i)
	{
		list<int> mojisu{ 5,7,5,7,7 };
		for (int j = i; j < w.size(); ++j)
		{
			mojisu.front() -= (int)w[j].size();

			if (mojisu.front() == 0)
			{
				mojisu.pop_front();
				if (mojisu.empty())
				{
					cout << i+1 << endl;
					return true;
				}
			}
			else if (mojisu.front() < 0)
			{
				break;
			}

		}
	}
}


int main()
{
	while (solve())
	{
		
	}
}

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();
		}

		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;
}

C++: s[50],j,p,q;main(i){for(;p=atoi(gets(s));printf("%d\n",i)){for(i=0;i<p;s[i++]=strlen(gets(s+i)));for(i=j=0;j<7;)for(p=i++,j=q=1;q>0;)for(q=j++>5?0:j-2&&j-4?8:6;q>1;q-=s[p++]);}}