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>
#include <cstdio>
using namespace std;
int n;

int check(int num,int start, string w[40]){
  int count = start;
  bool flag = true;
  while(flag){
    if(count >= n){
      flag = false;
      break;
    }
    else if(num - w[count].size() == 0){
      count++;
      break;
    }
    else if(num - w[count].size() > 0){
      num -= w[count].size();
      count++;
      continue;
    }
    else {
      flag = false;
      break;
    }
  }
  if(flag) return count;
  else return -1;
}

int main(){
  string w[40];
  while(true){
    cin >> n;
    //cout << "n="<<n << endl;
    if(n == 0) break;

    for(int i = 0; i < n; i++){
      cin >> w[i];
    }

    for(int i = 0; i < n - 4; i++){
      int point = i;

      point = check(5, i, w);
      if(point == -1) continue;
      point = check(7, point, w);
      if(point == -1) continue;
      point = check(5, point, w);
      if(point == -1) continue;
      point = check(7, point, w);
      if(point == -1) continue;
      point = check(7, point, w);
      if(point != -1){
         cout << i+1 << endl;
         break;
      }
    }
  }
  return 0;
}

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

int main(void){
	int n;
	int t[] = {5,7,5,7,7};
	while(cin >> n, n){
		vector<int> v(n);
		for(int i = 0; i < n; ++i){
			string s;
			cin >> s;
			v[i] = s.size();
		}
		for(int i = 0; i < n; ++i){
			bool a = true;
			int j = i;
			int tn = 0;
			while(tn < 5){
				int sum = 0;
				while(sum < t[tn]){
					sum += v[j];
					j++;
					if(j==n)break;
				}
				if(sum == t[tn]){
					tn++;
				}else{
					a = false;
					break;
				}
			}
			if(a && tn==5){
				cout << i+1 << endl;
				break;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n, n){
        vector<int> v(n);
        for (int i = 0; i < n; ++i) {
            string s;
            cin >> s;
            v[i] = s.size();
        }
        vector<int> u{5, 7, 5, 7, 7, 100000};
        for (int i = 0; i < n; ++i) {
            int cur = 0, p = 0;
            int valid = true;
            for (int j = i; j < n; ++j) {
                p += v[j];
                if(u[cur] == p) cur++, p = 0;
                else if(u[cur] < p) valid = false;
            }
            if(valid && cur == 5){
                cout << i+1 << "\n";
                break;
            }
        }
    }
    return 0;
}

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

using namespace std;

int solve(int n) {
    vector<string> words(n);
    for (int i = 0; i < n; i++) {
        cin >> words[i];
    }
    int a;
    int count = 0;
    while (1) {
        int first  = 0;
        int second = 0;
        int serd   = 0;
        int forth  = 0;
        int fifth  = 0;
        for (a = count; first < 5; a++) {
            first += words[a].size();
        }
        if (first != 5) {
            count++;
            continue;
        }
        for (; second < 7; a++) {
            second += words[a].size();
        }
        if (second != 7) {
            count++;
            continue;
        }
        for (; serd < 5; a++) {
            serd += words[a].size();
        }
        if (serd != 5) {
            count++;
            continue;
        }
        for (; forth < 7; a++) {
            forth += words[a].size();
        }
        if (forth != 7) {
            count++;
            continue;
        }
        for (; fifth < 7; a++) {
            fifth += words[a].size();
        }
        if (fifth != 7) {
            count++;
            continue;
        }
        return ++count;
    }
}

int main() {
    int n;
    vector<int> ans;
    while (1) {
        cin >> n;
        if (!n) break;
        ans.push_back(solve(n));
    }
    for (int i : ans) cout << i << endl;
}

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

using namespace std;

int main() {

    int n;
    string w[40];
    int lens[] = {5, 7, 5, 7, 7};

    while(cin >> n, n) {

        for(int i = 0; i < n; ++i) {
            cin >> w[i];
        }

        for(int i = 0; i < n; ++i) {

            int len = 0, phrase = 0;

            for(int j = i; j < n; ++j) {

                len += w[j].size();

                if(len == lens[phrase]) {
                    len = 0;
                    ++phrase;
                    if(phrase == 5) {
                        cout << i + 1 << endl;
                        break;
                    }
                }
            }

            if(phrase == 5) {
                break;
            }

        }

    }

}