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()
{
  int n;
  string w[40];
  int lengths[] = {5, 7, 5, 7, 7};
 
  while(cin >> n, n) {
    for(int i = 0; i < n; i++) {
      cin >> w[i];
    }
    for(int i = 4; i < n; i++) {
      int beforreadidx = 4, len = 0;
      for(int j = i; j >= 0; j--) {
        len += w[j].length();
        if(lengths[beforreadidx] == len) {
          len = 0;
          beforreadidx--;
          if(beforreadidx == -1) {
            cout << j + 1 << endl;
            break;
          }
        }
      }
      if(beforreadidx == -1) break;
    }
  }
  return(0);
 
}

C++: #include<cstdio>
#include<cstring>

int i,j,d[50],p,n,q,a[5]={5,7,5,7,7};
char s[15];
int main(){
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%s",s);
			d[i]=strlen(s);
		}
		for(i=0;i<n;i++){
			p=i;
			for(j=0;j<5;j++){
				q=a[j];
				while(q>0){
					q-=d[p];p++;
				}
				if(q<0)p=-1;
			}
			if(p>=0){
				printf("%d\n",i+1);
				break;
			}
		}
	}
	return 0;
}

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

int main(){
    int n;
    int tanka[]={5,7,5,7,7};
    while(cin>>n,n){
        vector<string> w(n);
        for(int i=0;i<n;i++)cin>>w[i];

        for(int i=0;i<n;i++){
            int inde=0;
            int cnt=0;
            for(int j=i;j<n;j++){
                cnt+=w[j].size();
                if(cnt==tanka[inde]){
                    inde++;
                    cnt=0;
                }
                if(inde==5) break;
            }
            if(inde==5){
                cout<<i+1<<endl;
                break;
            }

        }

    }

    return 0;
}

C++: #include <cstdio>
#include <cstring>

int l[40];

bool check(int *p, int n) {
  int i;
  for (i=0;i<n;i+=l[(*p)++]);
  return (i == n);
}

int main() {
  int n;
  while (scanf("%d", &n), n!=0) {
    for (int i=0;i<n;i++) {
      char s[11];
      scanf("%s", s);
      l[i] = strlen(s);
    }
    for (int i=0;i<n-4;i++) {
      int p = i;
      if (!check(&p, 5)) continue;
      if (!check(&p, 7)) continue;
      if (!check(&p, 5)) continue;
      if (!check(&p, 7)) continue;
      if (!check(&p, 7)) continue;
      printf("%d\n", i+1);
      break;
    }
  }
  return 0;
}

C++: #include<bits/stdc++.h>
char s[50],a[9]={6,8,6,8,8};
main(){for(int i,j,p,n,q;scanf("%d\n",&n),n;){for(i=0;i<n;s[i++]=strlen(gets(s+i)));
for(i=j=0;j<6;i++)for(p=i,j=q=0;q+1;)for(q=a[j++]-1;q>0;q-=s[p++]);
printf("%d\n",i);
}}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string s;
	while(cin>>n,n){
		int a[40]={0},j=0,i=0,c,k=0;
		for(;j<n;j++){
			cin>>s;
			a[i++]=s.size();
		}
		for(j=0;j<35;j++){
			int b[4]={0};
			c=0;
		for(i=j;i<40;i++){
			c+=a[i];
			if(c==5)b[0]++;
			else if(b[0]&&c==12)b[1]++;
			else if(b[1]&&c==17)b[2]++;
			else if(b[2]&&c==24)b[3]++;
			else if(b[3]&&c==31){
				k=j;
				break;
			}
			if(!b[0]&&c>5)break;
			else if(b[0]&&c>12)break;
			else if(b[1]&&c>17)break;
			else if(b[2]&&c>24)break;
			else if(b[3]&&c>31)break;
		}if(k)break;
	    }
	    
		cout<<k+1<<endl;
	}
}

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

using namespace std;

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

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

        int cumulativesum[n + 1];
        cumulativesum[1] = len[1];
        for (int i = 2; i <= n; ++i) {
            cumulativesum[i] = cumulativesum[i - 1] + len[i];
        }

        bool cnt5 = false, cnt12 = false, cnt17 = false, cnt24 = false, cnt31 = false;
        int ans = 0;
        for (int i = 1; i <= n; ++i) {
//            for (int j = 1; j <= n; ++j) {
//                printf("%d ", cumulativesum[j]);
//            }
//            printf("\n");
            for (int j = i; j <= n; ++j) {
                if (cumulativesum[j] == 5) cnt5 = true;
                if (cumulativesum[j] == 12) cnt12 = true;
                if (cumulativesum[j] == 17) cnt17 = true;
                if (cumulativesum[j] == 24) cnt24 = true;
                if (cumulativesum[j] == 31) cnt31 = true;

                if (cnt5 && cnt12 && cnt17 && cnt24 && cnt31) ans = i;
            }
            if (ans != 0) break;
            for (int j = 1; j <= n; ++j) {
                cumulativesum[j] -= len[i];
            }
        }

        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

int check(vector<int> tanka){
	int roule[] = {5,7,5,7,7};
	int index = 0, i = 0, t = 0;
	int sum = 0;
	while(i < 5){
		do{
			sum += tanka[index+t];
			t++;
		}while(sum < roule[i]);
		if(sum > roule[i]){
			index++;
			i = 0;
			t = 0;
		}else{
			i++;
		}
		sum = 0;
	}
	return index+1;
}

int main(){
	vector<int> tanka;
	vector<int> res;
	int n;
	do{
		cin >> n;
		for(int i=0;i<n;i++){
			string tmp;
			cin >> tmp;
			tanka.push_back(tmp.size());
		}
		if(n > 0)
			res.push_back(check(tanka));
		tanka.clear();
		tanka.shrink_to_fit();
	}while(n > 0);

cout << "test" << endl;
	for(auto num : res){
		cout << num << endl;
	}
	
	return 0;
}