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<vector>
#include<string>
#include<cstdlib>
#include<sstream>
#include<queue>
#include<deque>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007
#define pb push_back

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
int main() {
	while(1){
		
		//cout << "n start" << endl;
		int n; cin >> n;
		if (n == 0) break;
		//cout << "n end" << endl;
		
		//cout << "init start" << endl;
		vector<string> str(n);
		for(int i = 0; i < n; i++) {
			cin >> str[i];
		}
		//cout << "init end" << endl;	
		
		//cout << "for i start" << endl;
		int ans = 0;
		for(int i = 0; i < n; i++) {
			int idx = 0;
			ans = i;	
			vi check = {5,7,5,7,7};
			for (int j = i; j < n; j++) {
					if(check[idx] <= 0) {
						idx++;
					}
					if (idx == 6){
						break;
					}
					check[idx] -= str[j].size();
					
			}
			int sum = 0;
			for (int k = 0; k < 5; k++) {
				sum += check[k];
			}
			if (sum == 0){
				break;
			}

		}
		////cout << "for i end" << endl;
		cout << ans + 1 << endl;
		//cout << "end" << endl;
	}
	return 0;
}

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

int n;
char w[50][100];
int len[50];
int main(){
	while(scanf("%d",&n),n){
		for(int i=0;i<n;i++)
			scanf(" %s",w[i]),len[i]=strlen(w[i]);
		int min=0;
		for(int k=0;k<n;k++){
			int a=0,b=0,c=0,d=0,e=0;
			bool E=false,A=false;
			while(a<=5&&b<=7&&c<=5&&d<=7&&e<=7&&E==false){
				 bool f=false;
				for(int m=k;m<n;m++){
					if(a!=5){
						a=a+len[m];
						if(A==false){
							min=m;
							A=true;
						}
						continue;
					}
					if(a==5&&b!=7){
						b=b+len[m];
						continue;
					}
					if(b==7&&c!=5){
						c=c+len[m];
						continue;
					}
					if(c==5&&d!=7){
						d=d+len[m];
						continue;
					}
					if(d==7&&e!=7){
						e=e+len[m];
						continue;
					}
					if(e==7){
						E=true;
						break;
					}
					f=true;
					break;
				}
				if(f)break;
			}
			if(E==true){
				break;
			}
		}
		printf("%d\n",min+1);
	}
}

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;
				}

			}

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

		}
	}

	return 0;
}

C++: /* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

const unsigned m = (1 << 6) | (1 << 13) | (1 << 18) | (1 << 25) | (1 << 30);
int n;
string s[40];

int main(){
  while (cin >> n, n){
    rep(i, n) cin >> s[i];
    rep(i, n){
      unsigned b = 0;
      rep(j, i, n){
        b <<= s[j].size();
        b |= 1 << s[j].size() - 1;
        if ((b & m) == m){
          cout << i + 1 << endl;
          goto B;
        }
      }
    }
    B:;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int N;
        cin >> N;
        if(!N) break;
        string s[N];
        for(int i = 0; i < N; i++) cin >> s[i];
        const vector<int> po = {5, 7, 5, 7, 7};
        for(int i = 0; i < N; i++){
            int index = 0;
            vector<int> yo = po;
            for(int j = i; j < N; j++){
                if(index == 5) break;
                if(yo[index] < s[j].size()) break;
                yo[index] -= s[j].size();
                if(!yo[index]) index++;
            }
            if(index == 5){
                cout << i + 1 << endl;
                break;
            }
        }
    }
    return 0;
}