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;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second


int main()
{
    int n;
    while(cin>>n,n)
    {
        int a[n];
        REP(i,n)
        {
            string s;
            cin>>s;
            a[i]=s.size();
        }
        rep(i,0,n-4)
        {
            int j=i;
            int sum=0;
            while(sum<5){sum+=a[j];j++;}
            if(sum!=5)continue;;sum=0;
            while(sum<7){sum+=a[j];j++;}
            if(sum!=7)continue;sum=0;
            while(sum<5){sum+=a[j];j++;}
            if(sum!=5)continue;sum=0;
            while(sum<7){sum+=a[j];j++;}
            if(sum!=7)continue;sum=0;
            while(sum<7){sum+=a[j];j++;}
            if(sum!=7)continue;sum=0;
            cout<<i+1<<endl;break;
        }
    }
    
}

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

int n;
string s[40];

bool find(int st) {
	int cnt[5] = {5, 7, 5, 7, 7};
	int cor = 0;
	
	for (int i = st; i < n; i++) {
		cnt[cor] -= (int)s[i].length();
		if (cnt[cor] < 0) return false;
		if (cnt[cor] == 0) cor++;
		if (cor == 5) return true;
	}
	return false;
}

int main() {
	while (cin >> n) {
		if (!n) break;
		int i, j;
		
		for (i = 0; i < n; i++) cin >> s[i];
		
		for (i = 0; ; i++) {
			if (find(i)) {
				break;
			}
		}
		cout << i + 1 << endl;
	}
	return 0;
}

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

using namespace std;

int N;
int length[44];

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

int search_len(int s,int l){
    int total=0;
    while(s<=N&&total<l) {
        total+=length[s];
        s++;
    }

    if (total==l) return s;
    else return -1;
}

bool judge(int s){
    int next=s;
    for(int i=0;i<5;i++){
        auto temp=search_len(next,len[i]);
        if (temp==-1) return false;
        next=temp;
    }
    return true;
}

int main(){
    string buf;

    while(true){
        cin>>N;
        if (N==0) break;
        for(int i=1;i<=N;i++){
            cin>>buf;
            length[i]=buf.size();
        }

        int i=1;
        while(i<=N){
            if (judge(i)) {
                printf("%d\n",i);
                break;
            }
            i++;
        }
    }

    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,j) for (int (i)=0;(i)<(int)(j);++(i))
#define put(i) cout << (i) << endl
using namespace std;
typedef long long ll;

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

        int start = 0;
        while (start++ < n) {
            int cnt = 0, f = 1;
            vector<int> lens(5, 0);
            for (int j = start-1; j < n; ++j) {
                lens[cnt] += w[j].length();
                switch (cnt) {
                    case 0:
                    case 2: if (lens[cnt] == 5) { cnt++; } else if (lens[cnt] > 5) { f = 0; j = n+1; } break;
                    case 4: if (lens[cnt] == 7) { j = n+1; } else if (lens[cnt] > 7) { f = 0; j = n+1; } break;
                    default: if (lens[cnt] == 7) { cnt++; } else if (lens[cnt] > 7) { f = 0; j = n+1; } break;
                }
            }
            if (f) {
                cout << start << endl;
                break;
            }
        }
    }
}

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

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++) {
			cout << data[i] << endl;
		}*/
		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;
				break;
			}
		}
	}
	return 0;
}