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

void solve(int n){
    vector<string> vs(n);
    for(int i=0;i<n;i++) cin >> vs[i];

    for(int i=0;i<n;i++){
        int idx=i;
        bool ok = true;
        //5 [i,idx]
        int sum = 0;
        for(int j=i;j<n;j++){
            sum += vs[j].size();
            if(sum > 5){
                ok = false;
                break;
            }
            if(sum == 5){
                idx = j;
                break;
            }
        }
        if(!ok){
            //cout << i << " 1 " << endl;
            continue; }
        idx++;
        ///cerr << "idx " << idx << endl;
        //7
        sum = 0;
        for(int j=idx;j<n;j++){
            sum += vs[j].size();
            if(sum > 7){
                ok = false;
                break;
            }
            if(sum == 7){
                idx = j;
                break;
            }
        }
        if(!ok){
            //cout << i << " 2" << endl;
            continue; }
        idx++;

        //cerr << "idx " << idx << endl;
        //5
        sum = 0;
        for(int j=idx;j<n;j++){
            sum += vs[j].size();
            if(sum > 5){
                ok = false;
                break;
            }
            if(sum == 5){
                idx = j;
                break;
            }
        }
        if(!ok){
            //cout << i << " 3" << endl;
            continue; }
        idx++;

        //7
        sum = 0;
        for(int j=idx;j<n;j++){
            sum += vs[j].size();
            if(sum > 7){
                ok = false;
                break;
            }
            if(sum == 7){
                idx = j;
                break;
            }
        }
        if(!ok){
            //cout << i << " 4" << endl;
            continue; }
        idx++;
        //7
        sum = 0;
        //cerr << "idx  " << idx << endl;
        for(int j=idx;j<n;j++){
            sum += vs[j].size();
            if(sum > 7){
                ok = false;
                break;
            }
            if(sum == 7){
                idx = j;
                break;
            }
        }
        if(!ok){
            //cout << i << " 5"<< endl;
            continue; }
        idx++;
        cout << i+1 << endl;
        return;
    }
}

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

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

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

    if(n==0)
    break;

    int len[40];
    for(int i=0;i<n;i++){
      string w;
      cin>>w;
      len[i]=w.size();
    }
    for(int i=0;i<n;i++){
      bool flg =false;
      int sta =0;
      int sum =0;

      for(int j=i;j<n;j++){
        sum+=len[j];
        if(sum==5||sum==12||sum==17||sum==24||sum==31){
          sta++;
        }
        if(sta==5){
          flg=true;
          break;
        }
        else if(sum>=31){
          break;
        }
      }
      if(flg){
        cout<<i+1<<endl;
        break;
      }
    }
  }
  return 0;
}

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

#define int long long

signed main() {
  int n;
  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 id = 0;
      vector<int> tanku{5, 7, 5, 7, 7};      
      for ( int j = i; j < n; j++ ) {
	if ( tanku[id] == (int)w[j].size() ) {
	  id++;	  
	} else if ( tanku[id] > (int)w[j].size() ) {
	  tanku[id] -= (int)w[j].size();	  
	} else {
	  break;
	}
	if ( id == 5 ) break;	
      }

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

  return 0;
}

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

int n, len, ans, cnt, tanka[5] = {5, 7, 5, 7, 7};
string s[50];

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

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

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

    cnt = len = ans = 0;

    for (int i = 0; i < n; ++i) {
      ans = i + 1;
      len = 0;

      for (int j = i; j < n; ++j) {
        len += s[j].size();
        //cout << len << " " << s[j] << endl;

        if (len == tanka[cnt]) {
          cnt++;
          len = 0;
          if (cnt == 5) {
            cout << ans << endl;
            return 0;
          }
        }
        else if (len < tanka[cnt]) {
          continue;
        }
        else if (len > tanka[cnt]) {
          len = 0;
          cnt = 0;
          break;
        }
      }

    }

      for (int i = 0; i < 49; ++i) s[i] = "";
  }

  return 0;
}

C++: #include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};


int len[50];
int ch[] = {0,5,7,5,7,7};

int main(){
	int n;
	while(1){
		cin >> n;
		if(n == 0) break;
		int ans = 0;
		for(int i = 1;i <= n;i++){
			string tmp;
			cin >> tmp;
			len[i] = tmp.length();
	//		cout << len[i] << endl;
		}
		for(int i = 1;i <= n;i++){
			int level = 1;
			int sum = len[i];
			int j = i;
			while(level != 6){
				j++;
				if(ch[level] == sum){
					level++;
					sum = len[j];
				}else if(ch[level] < sum){
					break;
				}else{
					sum += len[j];
				}
			}
			if(level == 6){
				ans = i;
				break;
			}else{
				continue;
			}
		}
		cout << ans << endl;
		
	}




}