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>
using namespace std;

int main(){
  while (1){
    int n;
    cin >> n;
    if(n==0) break;

    vector<string> words(n+1);
    for(int i=1; i<=n; i++){
      cin >> words[i];
    }
    
    for(int i=1; i<n+1; i++){
      bool flag = false;
      int tanka[5]={5,7,5,7,7};
      int now = 0;
      for(int j=0; j+i<n+1; j++){
        int len=words[i+j].length();
        if(tanka[now]-len>=0){
          tanka[now] -= len;
        }else{
          break;
        }
        if(tanka[now]==0){
          now++;
        }
        if(now==5){
          cout << i << endl;
          flag = true;
          break;
        }
      }
      if(flag){
        break;
      }
        
    }
    
  }
  return 0;
}

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

int main(void){
  while(true){
    int n;
    cin >> n;
    if(n == 0){ break; }

    string input;
    vector<int> w(n);
    for(int i = 0; i < n; i++){
      cin >> input;
      w[i] = input.length();
    }

    int tank[] = {5, 7, 5, 7, 7};
    for(int i = 0; i < n; i++){
      int phase = 0;
      int nowCount = 0;
      for(int j = i; j < n && phase < 5; j++){
        nowCount += w[j];
        if(nowCount == tank[phase]){
          nowCount = 0;
          phase++;
        }
        else if(nowCount > tank[phase]){ break; }
      }

      if(phase == 5){
        cout << i + 1 << endl;
        break;
      }
    }
  }

  return 0;
}

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

string W[45];
int Len[45];
int haiku[] = {5,7,5,7,7,0};
bool used[45];
int n;

/*
bool rec(int i, int cur, int nokori) {
    
    //printf("i:%d cur:%d nokori:%d\n", i, cur, nokori);
    if(cur >= 5) {
        // 結果を出力

        for(int i = 0; i < n; ++i) {
            if(used[i]) {
                cout << (i+1) << endl;
                break;
            }
        }

        return true;
    }

    // for(int j = i; i < n; ++j) にしていて無限にバグった。。
    for(int j = i; j < n; ++j) {
        if(Len[j] < nokori) {
            used[j] = true;
            bool flg = rec(j+1, cur, nokori - Len[j]);
            if(flg) return true;
            used[j] = false;
        } else if(Len[j] == nokori) {
            used[j] = true;
            bool flg = rec(j+1, cur+1, haiku[cur+1]);
            if(flg) return true;
            used[j] = false;
        }
    }
    return false;
}
*/

bool check(int f){
    int cur = 0, nokori = haiku[0];
    for(int i = f; i < n; ++i) {
        nokori -= Len[i];
        if(nokori < 0) return false;
        else if(nokori == 0) nokori = haiku[++cur];
        
        if(cur >= 5) return true;
    }
    return false;
}

bool solve()
{
    cin >> n;
    if(n == 0) return false;
    for(int i = 0; i < n; ++i) {
        cin >> W[i];
        Len[i] = W[i].size();
        used[i] = false;
    }
    //printf("n:%d\n", n);
    //rec(0, 0, haiku[0]);
    for(int i = 0; i < n; ++i) {
        if(check(i)) { cout << i + 1 << endl; break;}
    }

    return true;
}

int main()
{
    while(solve());
    return 0;
}

C++: #include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        int a[41];
        rep(i,n){
            string s;
            cin >> s;
            a[i] = s.size();
        }
        int t[5] = {5,7,5,7,7};
        int k, c, ans = -1;
        rep(i,n){
            k = 0;
            c = 0;
            range(j,i,n){
                c+=a[j];
                if(c == t[k]){
                    k++;
                    c = 0;
                }else if(c > t[k]){
                    break;
                }
                if(k == 5){
                    ans = i;
                    break;
                }
            }
            if(ans != -1) break;
        }
        cout << ans + 1 << endl;
    }
}

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

int main() {
  int n;

  while (cin >> n, n) {
    vector<string> s;
    for (int i = 0; i < n; ++i) {
      string in;
      cin >> in;
      s.push_back(in);
    }

    for (int i = 0; i < s.size(); ++i) {

      int length = 0;
      int cnt = 0;

      for (int j = i; j < s.size() && cnt != 5; ++j) {
        length += s[j].size();

        if ((cnt == 0 || cnt == 2) && length == 5) {
          length = 0;
          cnt++;
          continue;
        }
        if ((cnt == 1 || cnt == 3 || cnt == 4) && length == 7) {
          length = 0;
          cnt++;
          continue;
        }
      }

      if (cnt == 5) {
        cout << i + 1 << endl;
        break;
      }
    }
  }
}

C++: #include <cstdio>
#include <cstring>
int n, l[44]; char c[12];
int main() {
	while (scanf("%d", &n)) {
		for (int i = 0; i < n; i++) scanf("%s", c), l[i] = strlen(c);
		for (int i = 0; i < n; i++) {
			int s = 0, v = 0;
			for (int j = i; j < n && s < 5; j++) {
				v += l[j];
				if (3 % (s + 1) == 0) {
					if (v > 5) break;
					else if (v == 5) s++;
				}
				else {
					if (v > 7) break;
					else if (v == 7) s++;
				}
			}
			if (s == 5) {
				printf("%d\n", i); break;
			}
		}
	}
}