#include <iostream>

using namespace std;

int main()
{ int N, count = 0;
  cout << "Enter the starting value: ";
  cin >> N;
  if (N <= 0)
  { cout << "Only positive starting points are valid.\n";
    exit(1); }
  while (true)
  { cout << N << " ";
    count = count + 1;
    if (N == 1)
      break;
    if (N % 2 == 0)
      N = N / 2;
    else
      N = 3 * N + 1; }
  cout << "\n";
  cout << "The length of the sequence is " << count << "\n"; }