5661 {
5662 int n;
5663 cin >> n;
5664 vector<bool> pen(n);
5665 string str;
5666 cin >> str;
5667 bool has1 = false;
5668 for(int i = 0; i < n; i++) {
5669 pen[i] = str[i] == '1';
5670 if(pen[i]) {
5671 has1 = true;
5672 }
5673 }
5674 if(!has1) {
5675 cout << n - 1;
5676 return 0;
5677 }
5678 vector<int> spaces2;
5679 vector<int> spaces1;
5680 int current = 0;
5683 while(!pen[left]) {
5685 }
5686 if(left > 0) {
5687 spaces1.push_back(left);
5688 }
5690 while(!pen[right]) {
5692 }
5693 if(right < n - 1) {
5694 spaces1.push_back(n - 1 - right);
5695 }
5697 if(!pen[left]) {
5698 current++;
5699 } else {
5700 spaces2.push_back(current);
5701 current = 0;
5702 }
5703 }
5704 int minimum = 0;
5705 int limit = n;
5706 sort(spaces2.begin(), spaces2.end());
5707 sort(spaces1.begin(), spaces1.end());
5708 if(!spaces2.empty()) {
5709 limit = *spaces2.begin();
5710
5711
5712 const int a = (*spaces2.rbegin() - 2) / 3;
5713 minimum = max(minimum, a);
5714
5715 if(spaces2.size() > 1) {
5716 const int b = (spaces2[spaces2.size() - 2] - 1) / 2;
5717 minimum = max(minimum, b);
5718 }
5719
5720 if(!spaces1.empty()) {
5721 const int a = (*spaces2.rbegin() - 1) / 2;
5722 int b = *spaces1.rbegin() - 1;
5723 minimum = max(minimum, min(a, b));
5724
5725 b = (*spaces1.rbegin() - 2) / 2;
5726 minimum = max(minimum, b);
5727
5728 if(spaces1.size() > 1) {
5729 const int a = *spaces1.begin() - 1;
5730 minimum = max(minimum, a);
5731 }
5732 }
5733 } else {
5734
5735 if(spaces1.size() > 1) {
5736 const int a = *spaces1.begin() - 1;
5737 minimum = max(minimum, a);
5738 }
5739
5740 const int b = (*spaces1.rbegin() - 2) / 2;
5741 minimum = max(minimum, b);
5742 }
5743 minimum = min(limit, minimum);
5744 cout << minimum + 1;
5745 return 0;
5746 }