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 <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int make(int w,int p);

vector<string> a(40);

int main() {
  int n;
  scanf ("%d",&n);
  while(n){

    for(int t=0;t<n;t++){
      //scanf ("%s",a[t]);
      cin >> a[t];
    }
    for(int t=n;t<40;t++){
      //scanf ("%s",a[t]);
      a[t]="";
    }
    int end=0;
    int k=0;
    for(k=0;k<n;k++){
      int q=k;
      if(make(q,5)>=1){
        q=1+make(q,5);
        if(make(q,7)>=1){
          q=1+make(q,7);
          if(make(q,5)>=1){
            q=1+make(q,5);
            if(make(q,7)>=1){
              q=1+make(q,7);
              if(make(q,7)>=1){
                end=1;
              }
            }
          }
        }
      }
      if(end==1) break;
    }
    printf("%d\n",k+1);
    scanf ("%d",&n);
  }
}


int make(int w,int p){
  int l=0;
  int r=0;
  l=a[w].size();
  if(l==p){
    return w;
  }
  else{
    if(l<p){
      r=make(w+1,p-l);
      return r;
    }
    else{
      return -1;
    }
  }
}

C++: #include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int n;
string a[10000];
int as[100000];
int ok[5]={5,7,5,7,7};
bool check1(int a){
  int cnt=0;
  int tmp=0;

  for(int i=a;i<n;i++){
    //cout<<i<<" "<<tmp<<endl;
    tmp+=as[i];
      if(tmp==ok[cnt]){
        tmp=0;
        cnt++;
        if(cnt==5)return true;
      }
      //else if(tmp<ok[cnt])tmp+=as[i];
      else if(tmp>ok[cnt]){
        return false;
      }
  }
  //cout<<a<<" ok"<<endl;
  return false;
}

bool check2(int a){
  int cnt=0;
  int tmp=0;
  for(int i=a;i>=0;i--){
    tmp+=as[i];
    if(tmp==ok[cnt]){
      tmp=0;
      cnt++;
      if(cnt==5)return true;
    }
    else if(tmp>ok[cnt])return false;
  }
  return false;
}
int main(){

  while(cin>>n,n){
    for(int i=0;i<n;i++){
      cin>>a[i];
      as[i]=a[i].size();
    }
    int ans1=10000,ans2=10000;
    for(int i=0;i<n;i++){
      if(check1(i)){
        ans1=i;
        break;
      }
  }

  for(int i=n-1;i>=0;i--){
    if(check2(i))ans2=i;
  }
  //cout<<ans1<<endl;
  if(ans1<ans2)cout<<ans1+1<<endl;
  else cout<<ans2+1<<endl;
}
  return 0;
}

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

int len[] = {5, 7, 5, 7, 7};
std::vector< std::string > w(40);

bool check(int start, int n) {
    int i = start, k;
    for(k = 0; k < 5; ++k) {
        int rest = len[k];

        if(i >= n) return false;
        while(i < n && rest > 0) {
            rest -= w[i].length();
            ++i;
        }
        if(rest < 0) {
            return false;
        }
    }
    return true;
}

int main() {
    int n;
    int i;
    while(std::cin >> n, n != 0) {
        for(i = 0; i < n; ++i) {
            std::cin >> w[i];
        }

        for(i = 0; i < n; ++i) {
            if(check(i, n)) {
                std::cout << i + 1 << std::endl;
                break;
            }
        }
    }
}

C++: //
//  main.cpp
//  Short Phrase
//
//  Created by x15071xx on 2017/06/18.
//  Copyright ?? 2017??´ AIT. All rights reserved.
//

#include <iostream>
#include <vector>
#include <string>
#include <cstdio>

using namespace std;
int main(int argc, const char * argv[]) {
    
    while (1) {
        int n,i,j;
        vector<string> str;
        cin >> n;
        
        if (n == 0) {
            break;
        }
        
        string tmp;
        for (i = 0; i < n; i++) {
            
            cin >> tmp;
            str.push_back(tmp);
            
        }
        
        for (i = 0; i < n; i++) {
            int flag = 0;
            j = 0;
            int numsum = 0;
            while (1) {
                if (flag == -1) {
                    break;
                }
                
                if (flag == 5) {
                    cout << i+1 << endl;
                    break;
                }
                
                
                numsum+=str[i+j].length();
                
//                if (i == 5) {
//                    cout << numsum << str[i+j] <<endl;
//                }
                if (flag == 0 || flag == 2) {
                    
                    if (numsum > 5) {
                        flag = -1;
                    } else if (numsum < 5){
                        j++;
                    } else if (numsum == 5) {
                        flag++;
                        numsum = 0;
                        j++;
                    }
                } else {
                    if (numsum > 7) {
                        flag = -1;
                    } else if (numsum < 7) {
                        j++;
                    } else if (numsum == 7) {
                        flag++;
                        numsum = 0;
                        j++;
                    }
                }
            }
            
            if (flag == 5) {
                break;
            }
        }
        
    }
    return 0;
}

C++: #include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FOREQ(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPEQ(i, n) FOREQ(i, 0, n)
#define ALL(c) (c).begin(), (c).end()

template <typename T> inline int size(const T& x) { return x.size(); }

bool is_tanka(const vector<string>& words, int offset) {
    static const int TANKA[] = {5, 7, 5, 7, 7};

    int curr_idx = 0, curr_len = 0;
    FOR(i, offset, size(words)) {
        curr_len += size(words[i]);
        if (curr_len > TANKA[curr_idx])
            return false;
        if (curr_len == TANKA[curr_idx]) {
            curr_idx++;
            curr_len = 0;
            if (curr_idx == 5)
                return true;
        }
    }
    return false;
}

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

    int n;
    while (cin >> n, n) {
        vector<string> words(n);
        REP(i, n) cin >> words[i];

        REP(offset, n) {
            if (is_tanka(words, offset)) {
                cout << offset+1 << endl;
                break;
            }
        }
    }
}