Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		n := io.NextInt()
		if n == 0 {
			break
		}
		s := make([]string, n)
		for i := 0; i < n; i++ {
			s[i] = io.NextLine()
		}
		w := [5]int{5, 7, 5, 7, 7}
		ans := 0
	OUTER:
		for i := 0; i < n; i++ {
			cnt, wc := 0, 0
			for j := i; j < n; j++ {
				wc += len(s[j])
				if wc == w[cnt] {
					cnt++
					wc = 0
					if cnt == 5 {
						ans = i + 1
						break OUTER
					}
				} else if wc > w[cnt] {
					break
				}
			}
		}
		io.Println(ans)
	}
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

C++: #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int c[5]={5,7,5,7,7};
  int n;
  while(R n && n) {
    vector<int> a(n);
    rep(i,n) {
      string s;
      R s;
      a[i]=s.size();
    }
    rep(i,n) {
      int x=i;
      rep(j,5) {
        int cnt=0;
        while(x<n&&cnt<c[j]) cnt+=a[x++];
        if(cnt!=c[j]) goto next;
      }
      pr(i+1);
      break;
    next:;
    }
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}

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);
		for(i=0;i<n;i++){
			scanf("%s",s);
			d[i]=strlen(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<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
using namespace std;

int main(){
  int n,wa[41],flag[5];
  char s[40][20];
  while(1){
    cin>>n;
    if(n==0)
      break;
    wa[0]=0;
    for(int i=0;i<n;i++){
      scanf("%s",s[i]);
      wa[i+1]=strlen(s[i])+wa[i];
    }
    for(int i=0;i<n-1;i++){
      for(int j=0;j<5;j++)
        flag[j]=0;
      for(int k=i;k<=n;k++){
        if(wa[k]-wa[i]==5)
          flag[0]=1;
        else if(wa[k]-wa[i]==12)
          flag[1]=1;
        else if(wa[k]-wa[i]==17)
          flag[2]=1;
        else if(wa[k]-wa[i]==24)
          flag[3]=1;
        else if(wa[k]-wa[i]==31)
          flag[4]=1;
      }
      if(flag[0]==1&&flag[1]==1&&flag[2]==1&&flag[3]==1&&flag[4]==1){
        cout<<i+1<<endl;
        break;
      }
    }
  }
}

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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//

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

  int n;
  while (cin >> n, n) {
    string w[44];
    rep(i, n) cin >> w[i];

    int c[6] = {5, 7, 5, 7, 7};
    int cnt = 0, len = 0, ans = -1;
    bool flag = false;
    rep(j, n) {
      cnt = 0, len = 0;
      FOR(i, j, n) {
        len += (int)w[i].size();
        if (len == c[cnt]) {
          cnt++;
          len = 0;
        } else if (c[cnt] < len) {
          break;
        }

        if (cnt == 5) {
          ans = j + 1;
          flag = true;
          break;
        }
      }
      if (flag) break;
    }
    cout << ans << "\n";
  }

  return 0;
}

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

int main(){
    int n;
    while(cin>>n,n){
        vector<int> V(n);
        for(auto &v:V){
            string s;
            cin>>s;
            v=s.size();
        }
        for(int i=0;i<n;i++){
            int cnt=0;
            int ans=i+1;
            int j=i;
            while(cnt<5) cnt+=V[j++];
            if(cnt!=5) continue;
            cnt=0;
            while(cnt<7) cnt+=V[j++];
            if(cnt!=7) continue;
            cnt=0;
            while(cnt<5) cnt+=V[j++];
            if(cnt!=5) continue;
            cnt=0;
            while(cnt<7) cnt+=V[j++];
            if(cnt!=7) continue;
            cnt=0;
            while(cnt<7) cnt+=V[j++];
            if(cnt==7){
                cout<<ans<<endl;
                break;
            }
        }
    }

    return 0;
}