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>

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector<int> data(n);
		string s;
		for (int i = 0; i < n; i++) {
			cin >> s;
			data[i] = s.size();
		}
		for (int i = 0; i < n; i++) {
			int a[5] = {0};
			int cc = 0;
			bool h = true;
			a[0] = data[i];
			if (a[0] == 5) {
				cc++;
			} else if (a[0] > 5) {
				continue;
			}
			for (int j = i+1; j < n; j++) {
				a[cc] += data[j];
				if (cc == 0) {
					if (a[0] == 5) {
						cc++;
					} else if (a[0] > 5) {
						h = false;
						break;
					}
				} else if (cc == 1) {
					if (a[1] == 7) {
						cc++;
					} else if (a[1] > 7) {
						h = false;
						break;
					}
				} else if (cc == 2) {
					if (a[2] == 5) {
						cc++;
					} else if (a[2] > 5) {
						h = false;
						break;
					}
				} else if (cc == 3) {
					if (a[3] == 7) {
						cc++;
					} else if (a[3] > 7) {
						h = false;
						break;
					}
				} else {
					if (a[4] == 7) {
						cc++;
						break;
					} else if (a[4] > 7) {
						h = false;
						break;
					}
				}
			}
			if (h && cc == 5) {
				cout << i+1 << endl;
			}
		}
	}
	return 0;
}

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

int seps[] = {5, 7, 5, 7, 7};

int n;
char buf[114514];
int gs[114514];

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) return 0;

    for (int i=0; i<n; i++) {
      scanf("%s", buf);
      gs[i] = strlen(buf);
    }

    for (int i=0; i<n; i++) {
      int k = 0;
      int sum = 0;
      bool fail = false;
      for (int j=i; j<n; j++) {
        sum += gs[j];

        if (seps[k] < sum) {
          fail = true;
          break;
        }

        if (seps[k] == sum) {
          ++k;
          sum = 0;
        }

        if (k == 5) break;
      }

      if (k != 5) fail = true;
      if (!fail) {
        printf("%d\n", i+1);
        break;
      }
    }
  }
}

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

int phrase[5] = {5,7,5,7,7};

int main() {

    while(1){

        int n;

        cin >> n;

        if(n==0) break;

        vector<string> w;

        for(int i=0; i<n; i++){
            string input;
            cin >> input;
            w.push_back(input);
        }

        int w_pos = 0;

        while(1){

            int w_itr = w_pos, nowp = 0, pcount = 0;

            while(1){
                if(w[w_itr].size() + pcount > phrase[nowp]){
                    nowp = -1;
                    break;
                }
                else if(w[w_itr].size() + pcount == phrase[nowp]){
                    nowp++;
                    if(nowp == 5){
                        break;
                    }
                    pcount = 0;
                }
                else{
                    pcount += w[w_itr].size();
                }
                w_itr++;
            }

            if(nowp == 5){
                break;
            }#include <bits/stdc++.h>
using namespace std;

int phrase[5] = {5,7,5,7,7};

int main() {

    while(1){

        int n;

        cin >> n;

        if(n==0) break;

        vector<string> w;

        for(int i=0; i<n; i++){
            string input;
            cin >> input;
            w.push_back(input);
        }

        int w_pos = 0;

        while(1){

            int w_itr = w_pos, nowp = 0, pcount = 0;

            while(1){
                if(w[w_itr].size() + pcount > phrase[nowp]){
                    nowp = -1;
                    break;
                }
                else if(w[w_itr].size() + pcount == phrase[nowp]){
                    nowp++;
                    if(nowp == 5){
                        break;
                    }
                    pcount = 0;
                }
                else{
                    pcount += w[w_itr].size();
                }
                w_itr++;
            }

            if(nowp == 5){
                break;
            }

            w_pos++;


        }

        cout << w_pos + 1 << endl;

    }

    return 0;
}

            w_pos++;


        }

        cout << w_pos + 1 << endl;

    }

    return 0;
}

C++: #include<vector>
#include<iostream>
#include<string>
using namespace std;
int a0 = 5;
int a1 = 7;
int a2 = 5;
int a3 = 7;
int a4 = 7;
int main() {
	int n;
	while (cin >> n, n != 0) {
		vector<int>v(n);
		for (int i = 0; i < n; i++) {
			string str;
			cin >> str;
			int x = str.size();
			v[i] = x;
		}
		for (int i = 0; i < n; i++) {
			int k = i;
			int ans = i;
			int a = a0;
			while (a > 0) {
				a -= v[k];
				k++;
				if (k == n) {
					goto OUT;
				}
				if (a == 0) {
					break;
				}
				else if (a < 0) {
					goto OUT;
				}
				

			}
			a = a1;
			while (a > 0) {
				a -= v[k];
				k++;
				if (k == n) {
					goto OUT;
				}
				if (a == 0) {
					break;
				}
				else if (a < 0) {
					goto OUT;
				}
				
			}
			a = a2;
			while (a > 0) {
				a -= v[k];
				k++;
				if (k == n) {
					goto OUT;
				}
				if (a == 0) {
					break;
				}
				else if (a < 0) {
					goto OUT;
				}
				
			}
			a = a3;
			while (a > 0) {
				a -= v[k];
				k++;
				if (k == n) {
					goto OUT;
				}
				if (a == 0) {
					break;
				}
				else if (a < 0) {
					goto OUT;
				}
				
			}
			a = a4;
			while (a > 0) {
				a -= v[k];
				k++;
				if (k == n) {
					goto OUT;
				}
				if (a == 0) {
					cout << ans + 1 << endl;
				}
				else if (a < 0) {
					goto OUT;
				}
				
			}
		OUT:
			;
		}

	}
	return 0;
}


// 5 12 17 24 31