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(){
    while(1){
        int n;
        cin >> n;
        if(n == 0)  break;
        vector<string> S(n);
        vector<int> N(n);
        for(int i=0;i<n;i++){
                cin >> S.at(i);
                N.at(i) = S.at(i).size();
        }

        for(int i=0;i<n;i++){
            int j=i;
            int m=N.at(j);
            while(m<5){
                m += N.at(j+1);
                j++;
            }
            if(m>5) continue;
            j++;

            m=N.at(j);
            while(m<7){
                m += N.at(j+1);
                j++;
            }
            if(m>7) continue;
            j++;
            
            m=N.at(j);
            while(m<5){
                m += N.at(j+1);
                j++;
            }
            if(m>5) continue;
            j++;

            m=N.at(j);
            while(m<7){
                m += N.at(j+1);
                j++;
            }
            if(m>7) continue;
            j++;

            m=N.at(j);
            while(m<7){
                m += N.at(j+1);
                j++;
            }
            if(m>7) continue;

            cout << i+1 << endl;
            break;
        }


    }
}

C++: #include<bits/stdc++.h>
int i,j,d[50],p,n,q,a[5]={5,7,5,7,7};
char s[15];
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; break;
				}
			}
			if(p>=0){
				printf("%d\n",i+1);
				break;
			}
		}
	}
}

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

int main() {
  while (true) {
    int n;
    cin >> n;

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

    int cnt1 = 0;
    int cnt2 = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i; j < n; j++) {
	cnt2 += w[j].size();
	if ((cnt1 == 0 || cnt1 == 2) && cnt2 > 5 || cnt2 > 7) {
	  cnt1 = 0;
	  cnt2 = 0;
	  break;
	}

	if ((cnt1 == 0 || cnt1 == 2) && cnt2 == 5 ||
	    (cnt1 == 1 || cnt1 == 3) && cnt2 == 7) {
	  cnt1++;
	  cnt2 = 0;
	}
	if (cnt1 == 4 && cnt2 == 7) {
	  cout << i + 1 << endl;
	  i = n;
	  break;
	}
      }
    }
  }

  return 0;
}

C++: #include<bits/stdc++.h>
#define inf 1<<29
#define linf 1e18
#define eps (1e-8)
#define mod 1000000007
#define pi M_PI
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

int main()
{
  int n;
  int len[101];
  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++;
    }
    else if(num[c]<sum)break;
    if(c==5)break;
      }
      if(c==5){
    ans=i;
    break;
      }
    }
    cout<<ans+1<<endl;
  }
 
  return 0;
}

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

int main() {
    int n;

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

        vector<string> w(n);

        for(int i = 0; i < n; i++) {
            cin >> w[i];
        }

        for(int i = 0; i < n; i++) {
            vector<int> tanku{ 5, 7, 5 ,7, 7 };
            int k = 0;
            for(int j = 0; i+j < n; j++) {
                tanku[k] -= w[i+j].size();
                if(tanku[k] == 0) k++;
                else if(tanku[k] < 0) break;
            }
            if(tanku[0] == 0 && tanku[1] == 0 
            && tanku[2] == 0 && tanku[3] == 0 
            && tanku[4] == 0) {
                cout << i+1 << endl;
                break;
            }
            else continue;
        }
    }
    return 0;
}

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

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

		for(int i=0;i<n;i++){
			int count=0;
			int j=i;
			vector<bool> ok(5,false); 
			while(j<=n-1){
				count+=v[j];
				j++;
				if(count==5)ok[0]=true;
				if(ok[0] && count==12)ok[1]=true;
				if(ok[1] && count==17)ok[2]=true;
				if(ok[2] && count==24)ok[3]=true;
				if(ok[3] && count==31)ok[4]=true;
				if(ok[4]){
					cout<<i+1<<endl;
					goto END;
				}
			}
		}
		END:;
	}
}

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>=0;)for(q=a[j++]-1;q>0;q-=s[p++]);
printf("%d\n",i);
}}

C++: *s,j,p,q;
main(i,j){for(s=j;p=j=atoi(gets(s));printf("%d\n",i)){
for(;j;s[p-j--]=strlen(gets(s+p)));
for(i=0;j<7;)for(p=i++,j=q=1;q>0;)for(q=8939616>>j++*4&15;q>1;q-=s[p++]);
}}