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 <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define POF pop_front
#define POB pop_back
#define MA make_pair
#define ll long long
#define VE vector<int>
#define VP vector<pair<int,int> >
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
int main(){
  int N;
  while(1){
    cin>>N;
    if(N==0){
      break;
    }
    VE V;
    FOR(i,0,N){
      string S;
      cin>>S;
      V.PB((int)S.size());
    }
    FOR(i,0,N){
      int sum=0;
      int now=i;
      while(sum<5){
        sum+=V[now];
        now++;
      }
      if(sum!=5){
        continue;
      }
      while(sum<12){
        sum+=V[now];
        now++;
      }
      if(sum!=12){
        continue;
      }
      while(sum<17){
        sum+=V[now];
        now++;
      }
      if(sum!=17){
        continue;
      }
      while(sum<24){
        sum+=V[now];
        now++;
      }
      if(sum!=24){
        continue;
      }
      while(sum<31){
        sum+=V[now];
        now++;
      }
      if(sum==31){
        cout<<i+1<<endl;
      }
    }
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

signed main(){

   while(1){
      int n;
      cin>> n;
      if(!n) break;

      int w[n];
      for(int i=0; i<n; i++){
         string s;
         cin>> s;
         w[i]=s.size();
      }
      int b[]={5, 7, 5, 7, 7};
      for(int i=0; i<n; i++){
         int a=0, p=0;
         for(int j=i; j<n; j++){
            a+=w[j];
            if(a>b[p]){
               goto turai;
            }else if(a==b[p]){
               p++;
               if(p==4) break;
               a=0;
            }
         }
         if(p==4){
            cout<< i+1<< endl;
            return 0;
         }
         turai:;
      }

   }

   return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

bool tanku(const V& a, int s) {
    const V li = {5, 7, 5, 7, 7};
    int w = 0, p = 0;
    for (int i = s; p < 5; i++) {
        w += a[i];
        if (w == li[p]) {
            w = 0;
            p++;
        } else if (w > li[p]) {
            return false;
        }
    }
    return true;
}

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

    int n;
    while (cin >> n, n) {
        V a;
        rep(i, n) {
            string s;
            cin >> s;
            a.emplace_back(s.size());
        }

        rep(i, n) {
            if (tanku(a, i)) {
                cout << i + 1 << endl;
                break;
            }
        }
    }
}

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

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

using namespace std;

bool ok(vector<int> v, int start) {
    int nums[5] = { 5, 7, 5, 7, 7 };
    int i = 0;
    auto itr = v.begin() + start;
    while (i < 5) {
        for (; itr != v.end(); ++itr) {
            if (*itr == nums[i]) {
                i++;
                continue;
            }
            else if (*itr >= nums[i]) {
                return false;
            }
            else {
                nums[i] -= *itr;
            }
        }
        return true;
    }
}

int main()
{
    int n;
    while (true) {
        cin >> n;
        if (n == 0) {
            return 0;
        }

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

        int start = 0, tail = 0;
        int sum = 0;
        while (true) {
            if (tail == n) {
                cout << 0 << endl;
                break;
            }

            while (tail < n && sum < (5 + 7 + 5 + 7 + 7)) {
                tail++;
                sum = accumulate(v.begin() + start, v.begin() + tail, 0);
            }

            if (sum == (5 + 7 + 5 + 7 + 7)) {
                if (ok(v, start)) {
                    cout << start << endl;
                    break;
                }
                else {
                    start++;
                    sum = accumulate(v.begin() + start, v.begin() + tail, 0);
                }
            }
            while (sum > (5 + 7 + 5 + 7 + 7)) {
                start++;
                sum = accumulate(v.begin() + start, v.begin() + tail, 0);
            }
        }
    }
    return 0;
}