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<vector>
#include<algorithm>
#include<iostream>
#include<string>
#include<numeric>


using namespace std;

int main()
{

	while (true) {

		int n;
		cin >> n;
		if (n == 0) {
			return 0;
		}
		string str;
		int nums[41];

		for (int i = 0; i < n; i++) {
			cin >> str;
			nums[i] = str.size();
		}

		int start = 0;
		int tail = 0;
		int sum = 0;
		while (true) {
			while (tail < n && sum < (5 + 7 + 5 + 7 + 7)) {
				tail++;

				sum = 0;
				for (int i = start; i < tail; i++) {
					sum += nums[i];
				}
			}
			if (sum < (5 + 7 + 5 + 7 + 7)) {
				break;
			}
			else if (sum == (5 + 7 + 5 + 7 + 7)) {
				int ns[5] = { 5, 7, 5, 7, 7 };
				int s = start;
				int i = 0;
				while (i < 5) {
					if (nums[s] == ns[i]) {
						i++;
						s++;
					}
					else if (nums[s] > ns[i]) {
						break;
					}
					else {
						ns[i] = ns[i] - nums[s];
						s++;
					}
				}
				if (i == 5) {
					cout << start + 1 << endl;
					break;
				}

			}

			while (start < tail && sum >(5 + 7 + 5 + 7 + 7)) {
				start++;

				sum = 0;
				for (int i = start; i < tail; i++) {
					sum += nums[i];
				}
			}

		}
	}

	return 0;
}

C++: def main():
    while True:
        n = int(input().strip())

        if n == 0:
            break

        phrases = []
        for _ in range(n):
            word = input().strip()
            phrases.append(word)

        PHRASE_LEN = [5,7,5,7,7]
        found_flag = False

        for i in range(n):
            acc_len = 0
            phrase_idx = 0
            for j in range(i, n):
                acc_len += len(phrases[j])

                if acc_len == PHRASE_LEN[phrase_idx]:
                    if phrase_idx == (len(PHRASE_LEN)-1):
                        found_flag = True
                        break

                    acc_len = 0
                    phrase_idx += 1
                elif acc_len > PHRASE_LEN[phrase_idx]:
                    break

            if found_flag:
                print(i+1)
                break

if __name__ == "__main__":
    main()

C++: #include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(void){
    int n;
    vector<string> w(n);
    while(true){
        cin >>n;
        if(n==0) break;
        for(int i=0;i<n;i++)
        cin >> w[i];
        int tanku[5]={5,7,5,7,7};
        bool judge=false;
        //?§??????????
        for(int i=0;i<n;i++){
            int place=i;
            //tanku ibannme
            for(int j=0;j<5;j++){
    int sum=0;
    //kasan
    while(place<n){
        sum+=w[place].size();
        place++;
        if(spum>=tanku[j])
        break;
    }if(sum>tanku[j])
    break;
    if(j==4&&sum==tanku[4]){
            cout << i+1 << endl;
            judge=true;
            break;
        }
            }
            if(judge)
break;
        }
    }
return 0;
}

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

bool acceptable(const vector<int> w, int i) {
  const vector<int> tanku = {5, 7, 5, 7, 7};
  for (int ku : tanku) {
    int sum = 0;
    while (sum < ku) {
      sum += w[i++];
    }
    if (sum != ku) {
      return false;
    }
  }
  return true;
}

int main() {
  int N;
  while (cin >> N && N) {
    vector<int> W(N);
    for (int i = 0; i < N; ++i) {
      string str;
      cin >> str;
      W[i] = str.length();
    }
    for (int i = 1; i <= N; ++i) {
      if (acceptable(W, i - 1)) {
        cout << i << endl;
        break;
      }
    }
  }
}

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

C++: #include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
int w[40];
int tanka[5]={5,7,5,7,7};
vector<int> ans;

int main(){
	while(1){
		cin>>n;
		if(n==0)break;
		for(int i=0;i<n;i++){
			string t;
			cin>>t;
			w[i]=t.size();
		}
		for(int i=0;i<n-4;i++){
			int nn=i;
			int nc=0;
			int tn=0;
			while(tn<5){
				if(nc+w[nn]>tanka[tn]){
					//cout<<1<<endl;
					break;
				}else if(nc+w[nn]<tanka[tn]){
					//cout<<nc<<endl;
					nc+=w[nn];
					nn++;
				}else{
					//cout<<3<<endl;	
					tn++;
					nn++;
					nc=0;
				}
			}
			if(tn==5){
				ans.push_back(i+1);
				break;
			}
		}
	}
	REP(i,(int)ans.size()){
		cout<<ans[i]<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int n;
  string s[40];
  int a[40];
  int check[5]={5,7,5,7,7};
  int cnt=0;
  bool b=false;
  while(1){
    cin>>n;
    if(n==0) break;
    b=false;
    rep(i,n){
      cin>>s[i];
      a[i]=s[i].size();
    }
    rep(i,n){
      cnt=0;
      int now=0;
      rep(j,5){
	cnt+=a[i+now];
	if(cnt<check[j]) j--;
	else if(cnt>check[j]) break;
	else cnt=0;
	if(j==4){cout<<i+1<<endl;b=true;break;}
	now++;
      }
      if(b) break;
    }
  }
    
  

  return 0;
}

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

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

  if(n==0) break;

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

  for(int i=0; i<n; i++){
   bool flag = false;
   int sta = 0; //区切り
   int sum = 0; //文字数の合計

   for(int j=i; j<n; j++){
    sum = sum + len[j];
    
    if(sum==5 || sum==12 || sum==17 || sum==24 || sum==31){
     sta++;
    }

    if(sta==5){
     flag = true;
     break;
    }else if(sum>=31){
     break;
    }
   }

   if(flag){
    cout << i+1 << endl;
    break;
   }
  }
 }

 return 0;
}