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;

string s[44];
int tanku[5] = {5, 7, 5, 7, 7};

void solve(int n) {
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            // use from i to j
            bool is_tanku = true;
            int now_idx = 0;
            int now_cnt = 0;
            for (int k = i; k <= j; k++) {
                now_cnt += s[k].size();
                if (now_cnt > tanku[now_idx]) {
                    is_tanku = false;
                    break;
                }
                else if (now_cnt == tanku[now_idx]) {
                    now_cnt = 0;
                    now_idx++;
                }
                if (now_idx == 5) break;
            }
            if (is_tanku && now_idx == 5) {
                cout << i + 1 << endl;
                return;
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    while (true) {
        cin >> N;
        if (N == 0) break;
        solve(N);
    }
    return 0;
}

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

int main() {
	int n;
	cin >> 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<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;)for(p=i++,j=q=0;q>=0;)for(q=a[j++]-1;q>0;q-=s[p++]);
printf("%d\n",i);
}}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define sq(x) ((x)*(x))
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int a[5]={5,7,5,7,7};
int solve(){
	int n;
	cin >> n;
	if(!n)return 1;
	vector<int> len(n);
	for(int i=0;i<n;i++){
		string s;
		cin >> s;
		len[i]=(int)s.size();
	}
	for(int i=0;i<n;i++){
		vector<int> b(5,0);
		int id = 0;
		for(int j=i;j<n;j++){
			b[id]+=len[j];
			if(b[id]>a[id])break;
			if(b[id]==a[id])id++;
			if(id==5)break;
		}
		if(id==5){
			printf("%d\n",i+1);
			return 0;
		}
	}
}
int main(){
	while(!solve()){}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int main() {

  while(1){
    int n;
    cin>>n;
    if(n == 0) break;
    string s;
    int nums[40];
    REP(i,0,n){
      cin>>s;
      nums[i] = (int)s.size();
    }
    REP(i,0,n){
      int p = 0;
      int ch[5] = {};
      bool flag = false;
      REP(j,i,n){
        ch[p] += nums[j];
        if((p==0 || p==2) && ch[p]==5){
          p++;
        }else if((p==1 || p==3 || p==4) && ch[p]==7){
          p++;
        }
        if(p==5){
          cout<<i+1<<endl;
          flag = true;
          break;
        }
      }
      if(flag) break;
    }

  }

  return 0;
}

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

int main(void){
  vector<int> tanku{5, 7, 5, 7, 7};
  while(1){
    int n; cin >> n;
    if(n == 0) break;
    vector<string> w(n);
    for(int i = 0; i < n; i++){
      cin >> w[i];
    }
    int idx = 0;
    int len = 0;
    while(idx < (int)w.size()){
      bool istanku = true;
      int ans = idx;
      for(int i = 0; i < (int)tanku.size(); i++){
        while(1){
          len += w[idx].size();
          idx++;
          if(len > tanku[i]){
            len = 0;
            istanku = false;
            break;
          }
          if(len == tanku[i]){
            len = 0;
            break;
          }
        }
        if(istanku == false) break;
      }

      if(istanku){
        cout << 1+ans << endl;
        break;
      }else{
        idx = ans+1;
      }
    }

  }
  return 0;
}

C++: #include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int n;
    while(cin >> n, n){
    int len[] = {5, 7, 5, 7, 7};
    string w[44];
    for(int i = 0; i < n; i++) cin >> w[i];
    int ans = 0;
    for(int i = 0; i < n; i++){
        int cnt = 0, idx = 0;
        for(int j = i; j < n; j++){
        cnt += w[j].size();
        if(cnt == len[idx]){
            cnt = 0, idx++;
            if(idx == 5) break;
        }else if(cnt > len[idx]){ idx = -1; break;}
        }
        if(idx == 5){ ans = i; break;}
    }
    cout << ans+1 << endl;
    }
    return 0;
}

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

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

    int N;
    int len[5] = {5, 7, 5, 7, 7};
    while (cin >> N, N) {
        vector<int> w(N);
        for (int i = 0; i < N; i++) {
            string s; cin >> s;
            w[i] = s.size();
        }

        for (int i = 0; i < N; i++) {
            int pos = 0;
            bool flag = true;
            for (int j = 0; j < 5; j++) {
                int n = 0;
                while (i+pos < N && n < len[j]) {
                    n += w[i+pos];
                    pos++;
                }
                if (n != len[j]) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                cout << i+1 << endl;
                break;
            }
        }
    }

    return 0;
}