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;
vector<int> cnt = {5, 12, 17, 24, 31};
int main(){
  while (1){
    int n;
    cin >> n;
    if (n == 0){
      break;
    }
    vector<string> w(n);
    for (int i = 0; i < n; i++){
      cin >> w[i];
    }
    vector<int> sum(n + 1, 0);
    for (int i = 0; i < n; i++){
      sum[i + 1] = sum[i] + w[i].size();
    }
    set<int> st;
    for (int i = 0; i <= n; i++){
      st.insert(sum[i]);
    }
    for (int i = 0; i < n; i++){
      bool ok = true;
      for (int j = 0; j < 5; j++){
        if (!st.count(sum[i] + cnt[j])){
          ok = false;
        }
      }
      if (ok){
        cout << i + 1 << endl;
        break;
      }
    }
  }
}

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

int n;
int L[64];
std::string str;

int main() {  
  for(;;) {
    scanf("%d", &n);
    if( n == 0 ) break;
    for(int i = 0; i < n; ++i) {
      std::cin >> str;
      L[i] = str.size();
    }
    for(int i = 0; i < n; ++i) {
      int state = 0;
      int x = 0;
      int dx[5] = {5, 7, 5, 7, 7};
      for(int j = i; j < n; ++j) {
        x += L[j];
        if( x > dx[state] ) break;
        if( x == dx[state] ) {
          x = 0;
          state += 1;
          if( state == 5 ) {
            break;
          }            
        }
      }
      if( state == 5 ) {
        printf("%d\n", i + 1);
        break;
      }
    }
  }
            

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
using namespace std;

const int tanka[] = {5, 7, 5, 7, 7};

int main() {
    int n;
    while(cin >> n, n) {
        vector<int> len(n);
        for (int i = 0; i < n; i++) {
            string s; cin >> s;
            len[i] = s.size();
        }

        for (int i = 0; i < n; i++) {
            int idx = i;
            bool flag = true;
            for (int j = 0; flag && j < 5; j++) {
                int x = 0;
                while(idx < n && x < tanka[j]) {
                    x += len[idx];
                    idx++;
                }
                if (x != tanka[j]) flag = false;
            }
            if (flag) {
                cout << i + 1<< endl;
                break;
            }
        }
    }
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
typedef vector<vector<int>> Graph;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    vector<int> length = {5, 7, 5, 7, 7};

    int N;
    while (cin >> N || N) {
        vector<string> S(N);
        rep(i, N) cin >> S[i];

        for (int i=0; i<N; i++) {
            int current = 0;
            int step = 0;
            bool ok = false;

            for (int j=i; j<N; j++) {
                if (current < length[step]) {
                    current += S[j].size();
                }

                if (current > length[step]) {
                    break;
                }

                if (current == length[step]) {
                    step++;
                    current = 0;
                }
                
                if (step == length.size()) {
                    ok = true;
                    cout << i+1 << endl;
                    break;
                }
            }
            if (ok) break;
        }
    }
}

C++: #include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define INF 1<<30
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	int n;
	while(cin >> n && n) {
		vector<string> v(n);
		rep(i, n) cin >> v[i];

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

		rep(i, n) {
			int j = i;
			bool flag = true;
			rep(k, 5) {
				string  s = "";
				while(s.size() < a[k]) {
					s += v[j];
					j++;
				}
				if(s.size() == a[k]) continue;
				flag = false;
				break;
			}
			if(flag) {
				cout << i + 1 << endl;
				break;
			}
		}
	}


	return 0;
}