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<bits/stdc++.h>
using namespace std;

int main(){
  string str;
  while(1){
    int temp[50] = {}, n, sum, count, f = 0, ans = 0;

    cin>>n;

    if(n == 0) break;

    for(int i = 1; i <= n; i++){
      cin>>str;
      temp[i] = str.size();//cout<<temp[i]<<endl;
      // temp[i] += tmep[i-1];
    }

    for(int i = 1; i <= n; i++){
      sum = 0;count = 0;
      for(int j = i; j <= n; j++){//cout<<"-------"<<j<<endl;
	sum += temp[j];//cout<<sum<<endl;
	if(sum == 5 && (count == 0 || count == 2)){count++;sum = 0;}
	if(sum == 7 && (count == 1 || count == 3 || count == 4)){count++;sum = 0;}
	//	if(sum == 5 && count == 2){count++;sum = 0}
	//	if(sum == 7 && count == 3){count++;sum = 0}
	//	if(sum == 7 && count == 4){count++;sum = 0}
	if(count == 5){f = 1; break;}
      }
      if(f == 1){ans = i; break;}
    }

    cout<<ans<<endl;

  }
  return 0;
}

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

int main() {
  int n;
  while (cin >> n, n) {
    auto c = vector<int>(n);
    for (int i = 0; i < n; ++i) {
      string w; cin >> w;
      c[i] = w.length();
    }
    auto s = vector<int>(n + 1, 0);
    auto phrase = vector<int>{5, 7, 5, 7, 7};
    for (int i = 0; i < n; ++i) s[i + 1] = s[i] + c[i];

    auto solve = [&]() {
      for (int i = 0; i < n; ++i) {
        int cur = i, nxt = n + 1;
        for (int j = 0; j < 5; ++j, cur = nxt) {
          nxt = distance(begin(s), find(begin(s), end(s), s[cur] + phrase[j]));
          if (nxt == n + 1) break;
          if (j == 4) return i + 1;
        }
      }
      return 0;
    };
    cout << solve() << endl;
  }
  return 0;
}

C++: #include <algorithm>
#include <array>
#include <iostream>
#include <string>

std::string words[40];
const std::array<int, 5> N57577 = { 5, 7, 5, 7, 7 };

int main()
{
	while (true) {
		int n;
		std::cin >> n;

		if (n == 0) return 0;

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

		for (int i = 0; i < n; i++) {
			int j = i;
			bool valid_tanka = true;

			for (int wn : N57577) {
				int count = 0;
				while (j < n) {
					count += words[j++].size();
					if (count >= wn) break;
				}
				if (count != wn) {
					valid_tanka = false;
					break;
				}
			}
			
			if (valid_tanka) {
				std::cout << (i + 1) << std::endl;
				break;
			}
		}
	}
}

C++: #include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


signed main(){
  int n;
  while(cin>>n,n){
    vector<int> v(n);
    REP(i,n){
      string s;cin>>s;
      v[i]=s.size();
    }
    REP(i,n){
      int p=i;
      int tmp=v[p];
      while(tmp<5){
        p++;tmp+=v[p];
      }
      if(tmp==5){
        p++;
        tmp=v[p];
        while(tmp<7){
          p++;tmp+=v[p];
        }
        if(tmp==7){
          p++;
          tmp=v[p];
          while(tmp<5){
            p++;tmp+=v[p];
          }
          if(tmp==5){
            p++;
            tmp=v[p];
            while(tmp<7){
              p++;tmp+=v[p];
            }
            if(tmp==7){
              p++;
              tmp=v[p];
              while(tmp<7){
                p++;tmp+=v[p];
              }
              if(tmp==7){
                p++;
                cout<<i+1<<endl;
                break;
              }
            }
          }
        }
      }
    }
  }
  return 0;
}

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

bool check(int start, const vector<string> &words) {
	const array<int, 5> num{{5, 7, 5, 7, 7}};

	int idx = 0;
	int sum = 0;
	for(int i = start; i < words.size(); ++i) {
		sum += words[i].size();

		if(sum == num[idx]) {
			if(++idx == 5) return true;
			sum = 0;
		}
		else if(sum > num[idx]) {
			return false;
		}
	}
	return false;
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	for(int n; cin >> n && n;) {
		vector<string> words(n);
		for(auto &e : words) cin >> e;

		for(int i = 0; i < n; ++i) {
			if(check(i, words)) {
				cout << i + 1 << endl;
				break;
			}
		}
	}

	return EXIT_SUCCESS;
}

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<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int main() {
    int q;
    while (cin >> q && q) {
        vector<string> v;
        while (q--) {string w; cin >> w; v.push_back(w);}
        int c[] = {5, 7, 5, 7, 7};
        int now = 0;
        int sum = 0;
        int flg = 0;
        rep(i, v.size()) {
            rrep(j, i, v.size()) {
                sum += v[j].size();
                //cout << sum << endl;
                if (sum == c[now]) {
                    sum = 0;
                    now++;
                    if (now == 5) {
                        cout << i + 1 << endl;
                        flg = 1;
                        break;
                    }
                } else if (sum > c[now]) {
                    now = 0;
                    sum = 0;
                    break;
                }
            }
            if (flg) break;
        }
    }
}