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 <string>

using namespace std;

int main(void) {
    while (1) {
        int n;
        cin >> n;
        if (n == 0) break;

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

        int cumulativesum[n + 1];
        cumulativesum[1] = len[1];
        for (int i = 2; i <= n; ++i) {
            cumulativesum[i] = cumulativesum[i - 1] + len[i];
        }

        bool cnt5 = false, cnt12 = false, cnt17 = false, cnt24 = false, cnt31 = false;
        int ans = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                printf("%d ", cumulativesum[j]);
            }
            printf("\n");
            for (int j = i; j <= n; ++j) {
                if (cumulativesum[j] == 5) cnt5 = true;
                if (cumulativesum[j] == 12) cnt12 = true;
                if (cumulativesum[j] == 17) cnt17 = true;
                if (cumulativesum[j] == 24) cnt24 = true;
                if (cumulativesum[j] == 31) cnt31 = true;

                if (cnt5 && cnt12 && cnt17 && cnt24 && cnt31) ans = i;
            }
            if (ans != 0) break;
            for (int j = 1; j <= n; ++j) {
                cumulativesum[j] -= len[i];
            }
            cnt5 = false, cnt12 = false, cnt17 = false, cnt24 = false, cnt31 = false;
        }

        cout << ans << endl;
    }
    return 0;
}

C++: #include<iostream>
#define f(X) for(c=0;c<X;c+=v[p++]);if(c-X)goto L;
using namespace std;main(){for(int n,v[50],s,p,c;cin>>n,n;){string t;for(s=0;s<n;)cin>>t,v[++s]=t.size();s=0;L:p=++s;f(5)f(7)f(5)f(7)f(7)cout<<s<<endl;}}

C++: #include "bits/stdc++.h"

#define REP(i, n ,N) for(int i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;

int main(){
	while(1) {
		int n;
		cin >> n;
		if(n==0)break;
		vector<int> word_len(n + 1);
		REP(i, 1, n + 1) {
			string s;
			cin >> s;
			word_len[i] = s.size();
		}

		REP(i, 1, n + 1) {
			int stack = 0;
			int stage = 0;
			REP(j, i, n + 1) {
				if (stage == 0) {
					stack += word_len[j];
					if (stack == 5) {
						stage++;
						stack = 0;
						continue;
					}
					if (stack > 5)break;
				}
				if (stage == 1) {
					stack += word_len[j];
					if (stack == 7) {
						stage++;
						stack = 0;
						continue;
					}
					if (stack > 7)break;
				}
				if (stage == 2) {
					stack += word_len[j];
					if (stack == 5) {
						stage++;
						stack = 0;
						continue;
					}
					if (stack > 5)break;
				}
				if (stage == 3) {
					stack += word_len[j];
					if (stack == 7) {
						stage++;
						stack = 0;
						continue;
					}
					if (stack > 7)break;
				}
				if (stage == 4) {
					stack += word_len[j];
					if (stack == 7) {
						stage++;
						break;
					}
					if (stack > 7)break;
				}
			}
			if (stage == 5) {
				p(i);
				break;
			}
		}
	}
}

C++: #include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string.h>
#include<string>
#include<functional>
#include<iomanip>
using namespace std;

#define INF 1<<21
#define DIV 1000000007

int main() {
  int n;
  while (1) {
	cin >> n;
	if (n == 0) {
	  return 0;
	}
	else {
	  vector<int> v;
	  for (int i = 0; i < n; i++) {

		string s;
		cin >> s;
		v.push_back(s.size());
	  }
	  int cnt = 0;
	  int sum = 0;
	  while (1) {
		for (int i = cnt; i < n; i++) {
		  sum = 0;
		  int j = cnt;
		  while (sum < 5) {
			sum += v[j];
			j++;
		  }
		  if (sum != 5) {
			break;
		  }
		  sum = 0;
		  while (sum < 7) {
			sum += v[j];
			j++;
		  }
		  if (sum != 7) {
			break;
		  }
		  sum = 0;
		  while (sum < 5) {
			sum += v[j];
			j++;
		  }
		  if (sum != 5) {
			break;
		  }
		  sum = 0;
		  while (sum < 7) {
			sum += v[j];
			j++;
		  }
		  if (sum != 7) {
			break;
		  }
		  sum = 0;
		  while (sum < 7) {
			sum += v[j];
			j++;
		  }
		  if (sum == 7) {
			goto NEXT;
		  }

		}

		cnt++;
	  }
	NEXT:
	  cout << cnt + 1 << endl;
	}
  }
}