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<vector>
#include<algorithm>
#include<cmath>

using namespace std;


int main()
{
	int n,ans=0;
	int v[41];
	
	while(1){
		cin >> n;
		if(n==0)break;
		
		vector<string> s(n);
		
		for(int i=0;i<n;i++){
			cin >> s[i];
			v[i] = s[i].size();
		}
		
		for(int i=0;i<n-4;i++){
			int k=i,flag = 1;
			for(int j=i;j<n;j++){
				int a=0;
				for(int l=0;l<5;l++){
					if(k == n)break;
					if(a+v[k] == 5){
						k++;
						break;
					}else if(a+v[k] > 5){
						flag = 0;
						break;
					}else {
						a += v[k];
						k++;
					}
				}
				
				a = 0;
				for(int l=0;l<7;l++){
					if(k == n)break;
					if(a+v[k] == 7){
						k++;
						break;
					}else if(a+v[k] > 7){
						flag = 0;
						break;
					}else {
						a += v[k];
						k++;
					}
				}
				
				a = 0;
				for(int l=0;l<5;l++){
					if(k == n)break;
					if(a+v[k] == 5){
						k++;
						break;
					}else if(a+v[k] > 5){
						flag = 0;
						break;
					}else {
						a += v[k];
						k++;
					}
				}
				
				a = 0;
				for(int l=0;l<7;l++){
					if(k == n)break;
					if(a+v[k] == 7){
						k++;
						break;
					}else if(a+v[k] > 7){
						flag = 0;
						break;
					}else {
						a += v[k];
						k++;
					}
				}
				
				a = 0;
				for(int l=0;l<7;l++){
					if(k == n)break;
					if(a+v[k] == 7){
						k++;
						break;
					}else if(a+v[k] > 7){
						flag = 0;
						break;
					}else {
						a += v[k];
						k++;
					}
				}
				if(flag == 1)break;
			}
			if(flag == 1){
				ans = i+1;
				break;
			}
		}
		cout << ans << endl;
	}
	
		
		
		
		
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstdio>
#define F(i,n) for(int i=0;i<(int)(n);i++)
#define INF 100000000
#define ll long long

using namespace std;
typedef pair<int, int> P;
int n;
int b[50];
bool c(int r) {
	int g[] = { 5,7,5,7,7 };
	int d = 0, k;
	int q = 0;
	for (int j = r; j<n; j++) {
		if (k == 5)return true;
		d += b[j];
		if (d == g[q]) {
			d = 0;
			q++;
			continue;
		}
		else if (d < g[q])continue;
		else return false;
	}
}
int main() {
	string a;
	while (1) {
		cin >> n;
		if (n == 0)break;
		F(i, n) {
			cin >> a;
			b[i] = a.size();
		}
		F(i, n) {
			if 	(c(i)){
				cout << i + 1 << endl;
				break;
			}
		}
	}
	return 0;
}

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

using namespace std;

const vector<int> num = {5, 7, 5, 7, 7};

bool Check(int idx, const int n, const vector<int> &w) {
    int j = 0, sum = 0;
    for (int i = idx; i < n && j < 5; ++i) {
        sum += w[i];
        if (num[j] == sum) {
            ++j;
            sum = 0;
        }
        else if (num[j] < sum)
            return true;
    }

    return (j == 5) ? false : true;
}

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

    int n;
    string s;

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

        int idx = 0;
        while (Check(idx, n, w))
            ++idx;

        cout << idx + 1 << endl;
    }

    return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
    int n;
    string s;
    int len[5] = {5,7,5,7,7};
    int count;
    int now;
    int ans;
    while(1){
        cin >> n;
        if(n==0) return 0;
        vector<int> w(n);
        for(int i=0;i<n;i++){
            cin >> s;
            w[i]=s.length();
        }
        ans=-1;
        for(int i=0;i<n;i++){
            count = 0;
            now = 0;
            for(int j=i;j<n;j++){
                count+=w[j];
                if(count==len[now]){
                    now++;
                    count=0;
                    if(now==5){
                        ans=i;
                    }
                }else if(count>len[now]){
                    break;
                }
            }
            if(ans != -1){
                break;
            }
        }
        cout << ans+1 << endl;
    }
    return 0;
}

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

int main()
{
  int n;
  int len[51];
  string s;
  int num[5]={5,7,5,7,7};

  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin>>s;
      len[i]=s.length();
    }

    int ans=0;
    for(int i=0;i<n;i++){
      int sum=0,c=0;
      for(int j=i;j<n;j++){
	sum+=len[j];
	if(sum==num[c]){
	  sum=0;
	  c++;
	}
	if(c==5){
	  ans=i;
	  break;
	}
	if(num[c]<sum)break;
      }
      if(ans!=0)break;
    }
    cout<<ans+1<<endl;
  }

  return 0;
}