#include <bits/stdc++.h>

using namespace std;

int main(){

    short q;

    cin>>q;

    int l,r;
    long long answer[100]={};
    int l_pos_odd=-1,l_pos_even=-1,r_pos_odd=-1,r_pos_even=-1;
    short i=0;
    while(q)
        {
        cin>>l>>r;
        if(l%2==1)
            {
            l_pos_odd=l;
            l_pos_even=l+1;
            }
        else
            {
            l_pos_odd=l+1;
            l_pos_even=l;
            };
        if(r%2==1)
            {
            r_pos_odd=r;
            r_pos_even=r-1;
            }
        else
            {
            r_pos_odd=r-1;
            r_pos_even=r;
            };
            long long o_1=r_pos_odd+l_pos_odd;
            long long o_2=r_pos_odd-l_pos_odd;
        if(r_pos_odd>l_pos_odd){
                answer[i]+=(-1)*(o_1)/2;
        answer[i]*=((o_2)/2+1);
        }
        o_1=r_pos_even+l_pos_even;
        o_2=r_pos_even-l_pos_even;
        long long check=0;
        if(r_pos_even>l_pos_even) {
                check+=(o_1)/2;
          check*=((o_2)/2+1);}
          answer[i]+=check;
        if(r_pos_even==l_pos_even) answer[i]+=r_pos_even;
        if(r_pos_odd==l_pos_odd) answer[i]+=-r_pos_odd;
        ++i;
        --q;
        }
        for(int j=0;j<i;++j)
            {
            cout<<answer[j]<<"\n";
            }
}


#include <iostream>
#include <sstream>
#include <string>
#include <unistd.h>
#include <chrono>
#include <thread>
#include <map>
using namespace std;
void run(int p, int r, int counter = 0){
    for(int i = p; i < r+1; i++){
        counter += i * (-1)^i;
    }
    cout << counter << endl;
}
int main(){
    int x;
    cin >> x;
    int arr[x];
    int arrs[x];
    int counter = 0;
    for(int i = 0; i < x; x++){
        cin >> arr[i];
        cin >> arrs[i];
    }
    for(int i = 0; i < x; x++){
        run(arr[i], arrs[i], counter);
        counter = 0;
    }
}


#include <iostream>
#include <sstream>
#include <string>
#include <unistd.h>
#include <chrono>
#include <thread>
#include <map>
#include <cmath>
#include <algorithm>
using namespace std;
void lool(int p, int r, int counter){
    for(int i = p; i < r+1; i++){
        counter += i * pow(-1,i);
    }
        cout << counter << endl;
}
int main(){
    int x;
    cin >> x;
    int arr[x];
    int arrs[x];
    int counter = 0;
    for(int i = 0; i < x; i++){
        cin >> arr[i];
        cin >> arrs[i];
    }
    for(int i = 0; i < x; i++){
        lool(arr[i], arrs[i], counter);
        counter = 0;
    }
    return 0;
}


#include <iostream>
#include <sstream>
#include <string>
#include <unistd.h>
#include <chrono>
#include <thread>
#include <map>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
    int numberof;
       cin >> numberof;
    for(int i = 0 ; i < numberof ; i++){
        int roof;
        int floor;
        cin >> roof;
        cin >> floor;
           if(floor-roof == 1){
               cout << "-1" <<endl;
           }
           else if(roof % 2 ==0 and floor % 2 ==0){
               cout << (roof + floor ) / 2 <<endl;
           }
           else if(roof % 2 != 0 and floor % 2 != 0){
               cout << - ( roof + floor ) / 2 <<endl;
           }
           else if( roof % 2 != 0  and floor % 2 == 0){
               cout << (floor - roof + 1 ) / 2 <<endl;
           }
           else if(roof % 2== 0 and floor % 2 !=0){
               cout << - ( floor - roof + 1 )/2<<endl;
           }
       }
    return 0;
}


#include <iostream>
#include <sstream>
#include <string>
#include <unistd.h>
#include <chrono>
#include <thread>
#include <map>
#include <cmath>
using namespace std;
void lool(int p, int r, int counter){
    for(int i = p; i < r+1; i++){
        counter += i * pow(-1,i);
    }
        cout << counter << endl;
}
int main(){
    int x;
    cin >> x;
    int arr[x];
    int arrs[x];
    int counter = 0;
    for(int i = 0; i < x; i++){
        cin >> arr[i];
        cin >> arrs[i];
    }
    for(int i = 0; i < x; i++){
        lool(arr[i], arrs[i], counter);
        counter = 0;
    }
    return 0;
}


#include <iostream>
#include <sstream>
#include <string>
#include <unistd.h>
#include <chrono>
#include <thread>
#include <map>
#include <cmath>
using namespace std;
void lool(int p, int r, int counter){
    for(int i = p; i < r+1; i++){
        counter += i * pow(-1,i);
    }
        cout << counter << endl;
}
int main(){
    int x;
    cin >> x;
    int arr[x];
    int arrs[x];
    int counter = 0;
    for(int i = 0; i < x; i++){
        cin >> arr[i];
        cin >> arrs[i];
    }
    for(int i = 0; i < x; i++){
        lool(arr[i], arrs[i], counter);
        counter = 0;
    }
}


#include <iostream>
#include <sstream>
#include <string>
#include <unistd.h>
#include <chrono>
#include <thread>
#include <map>
using namespace std;
void пердеть(int p, int r, int counter = 0){
    for(int i = p; i < r+1; i++){
        counter += i * (-1)^i;
    }
    cout << counter << endl;
}
int main(){
    int x;
    cin >> x;
    int arr[x];
    int arrs[x];
    int counter = 0;
    for(int i = 0; i < x; x++){
        cin >> arr[i];
        cin >> arrs[i];
    }
    for(int i = 0; i < x; x++){
        пердеть(arr[i], arrs[i], counter);
        counter = 0;
    }
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

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

    for(int i = 0; i < n; i++){
        int t, tt, sum = 0;
        cin >> t >> tt;
        for (int j = t; j < tt + 1; j++){
            sum += j*pow(-1, j);
        }
        cout << sum << endl;
    }

    return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    int n;
    cin >> n;
    for (int i = 0; i < n; i ++){
        long long t, tt;
        cin >> t >> tt;

        if (t % 2 == 0){
            if ((tt - t) % 2 == 0){
                //нечетная длина
                cout << t + ((tt - t) / 2)<< endl;
            }
            else{
                //четная длина
                cout << -1 * (( (tt - t + 1)) /2) << endl;
            }
        }
        else{
            if ((tt - t) % 2 == 0){
                //нечетная длина
                cout << -t + (-1)* ( ( tt - t ) / 2) << endl;
            }
            else{
                //четная длина
                int a = ((tt + 1 - t) / 2);
                cout << a << endl;
            }
        }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int num(int a, int j){
    if (j % 2 == 0){
        return a;
    }
    else{
        return -a;
    }
}

int main(){
    int n;
    cin >> n;
    for (int i = 0; i < n; i ++){
        int t, tt;
        cin >> t >> tt;

        if (t % 2 == 0){
            if((tt - t + 1) % 2 == 0){
                cout << (-1) * ((tt + 1 - t ) / 2) << endl;
            }
            else{
                cout << t + ((tt - t) / 2) * 1 << endl;
            }
        }
        else{
            if((tt - t + 1 )% 2 == 0){
                cout << 1 + ((tt - t + 1)/2) * 1 << endl;
            }
            else{
                cout <<  -t - ((tt - t)/2) << endl;
            }
        }

    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    int n;
    cin >> n;
    for (int i = 0; i < n; i ++){
        int t, tt;
        cin >> t >> tt;

        if (t % 2 == 0){
            if ((tt - t) % 2 == 0){
                //нечетная длина
                cout << t + ((tt - t) / 2)<< endl;
            }
            else{
                //четная длина
                cout << -1 * (( (tt - t + 1)) /2) << endl;
            }
        }
        else{
            if ((tt - t) % 2 == 0){
                //нечетная длина
                cout << -t + (-1)* ( ( tt - t ) / 2) << endl;
            }
            else{
                //четная длина
                cout << (tt + 1 - t)/2;
            }
        }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int num(int a, int j){
    if (j % 2 == 0){
        return a;
    }
    else{
        return -a;
    }
}

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

    for (int i = 0; i < n; i++){
        int t, tt, sum = 0;
        cin >> t >> tt;
        for(int j = t; j < tt + 1; j++){
            sum += num(j, j);
        }
        cout << sum << endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    int n;
    cin >> n;
    for (int i = 0; i < n; i ++){
        long long t, tt;
        cin >> t >> tt;

        if (t % 2 == 0){
            if ((tt - t) % 2 == 0){
                //нечетная длина
                cout << t + ((tt - t) / 2)<< endl;
            }
            else{
                //четная длина
                cout << -1 * (( (tt - t + 1)) /2) << endl;
            }
        }
        else{
            if ((tt - t) % 2 == 0){
                //нечетная длина
                cout << -t + (-1)* ( ( tt - t ) / 2) << endl;
            }
            else{
                //четная длина
                cout << (tt + 1 - t)/2;
            }
        }
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		int l, r;
		long res = 0;
		cin >> l >> r;
		for (int j = l; j <= r; j+=2)
		{
			if (l % 2 == 0) res += -1;
			else res -= +1;
		}

		if ((l - r) % 2 == 0)
			if (r % 2 == 0)
				res += r;
			else
				res -= r;

		cout << res << endl;
	}

	return 0;
}


#include <iostream>

using namespace std;

int main()
{
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		int l, r;
		long res = 0;
		cin >> l >> r;
		for (int j = l; j < r; j += 2)
		{
			if (l % 2 == 0) res -= 1;
			else res += 1;
		}

		if ((l - r) % 2 == 0)
			if (r % 2 == 0)
				res += r;
			else
				res -= r;

		cout << res << endl;
	}

	return 0;
}


#include <iostream>
#include <cmath>

using namespace std;

int result(int l, int r)
{
	if (l == r) return l * pow(-1, l);

	return l * pow(-1, l) + result(l + 1, r);
}

int main()
{
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		int l, r;
		cin >> l >> r;
		cout << result(l, r) << endl;
	}
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		int l, r;
		long res = 0;
		cin >> l >> r;
		for (int j = l; j < r; j+=2)
		{
			if (l % 2 == 0) res += 1;
			else res -= 1;
		}

		if ((l - r) % 2 == 0)
			if (r % 2 == 0)
				res += r;
			else
				res -= r;

		cout << res << endl;
	}

	return 0;
}


#include <iostream>

using namespace std;

int main()
{
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		int l, r;
		long res = 0;
		cin >> l >> r;
		for (int j = l; j <= r; j++)
		{
			if (j % 2) res += j;
			else res -= j;
		}
		cout << res;
	}

	return 0;
}


#include <iostream>

using namespace std;

int main()
{
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		int l, r;
		long res = 0;
		cin >> l >> r;
		for (int j = l; j <= r; j++)
		{
			if (j % 2) res += j;
			else res -= j;
		}
		cout << res << endl;
	}

	return 0;
}


#include <iostream>

using namespace std;

int main()
{
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		int l, r;
		long res = 0;
		cin >> l >> r;
		for (int j = l; j <= r; j++)
		{
			if (j % 2 == 0) res += j;
			else res -= j;
		}
		cout << res << endl;
	}

	return 0;
}


#include <iostream>

using namespace std;

int main()
{
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		int l, r;
		long res = 0;
		cin >> l >> r;

		if (l % 2 == 0) res -= ((r-l +1)/2);
		else res += ((r -l  + 1) / 2);

		if ((r-l) % 2 == 0)
			if (r % 2 == 0)
				res += r;
			else
				res -= r;

		cout << res << endl;
	}

	return 0;
}


#include <iostream>
#include <cmath>

using namespace std;
int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  int q;
  cin >> q;
  long results[q];
  long pos = 0;
  for (long i = 0; i < q; i++) {
    long a, b;
    cin >> a >> b;
    if (a < b) {
      long long cha, ncha, chb, nchb, sum;
      if (a % 2 == 0) {
        cha = a;
        ncha = a + 1;
      } else {
        cha = a + 1;
        ncha = a;
      }

      if (b % 2 == 0) {
        chb = a;
        nchb = a - 1;
      } else {
        chb = b - 1;
        nchb = b;
      }

      sum = (cha + chb) * (((chb - cha) / 2 + 1)) / 2 - (nchb + ncha) * (((nchb - ncha) / 2 + 1)) / 2;
      results[pos] = sum;
      pos++;
    } else if (a == b){
      if (a % 2 != 0) a = -a;
      results[pos] = a;
      pos++;
    }
  }
  for (long i = 0; i < q; i++) {
    cout << results[i] << endl;
  }
  return 0;
}


#include <iostream>
#include <cmath>

using namespace std;
int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  int q;
  cin >> q;
  long results[q];
  long pos = 0;
  for (long i = 0; i < q; i++) {
    long a, b;
    cin >> a >> b;
    if (a < b) {
      long long cha, ncha, chb, nchb, sum;
      if (a % 2 == 0) {
        cha = a;
        ncha = a + 1;
      } else {
        cha = a + 1;
        ncha = a;
      }

      if (b % 2 == 0) {
        chb = b;
        nchb = b - 1;
      } else {
        chb = b - 1;
        nchb = b;
      }

      sum = (cha + chb) * (((chb - cha) / 2 + 1)) / 2 - (nchb + ncha) * (((nchb - ncha) / 2 + 1)) / 2;
      results[pos] = sum;
      pos++;
    } else if (a == b){
      if (a % 2 != 0) a = -a;
      results[pos] = a;
      pos++;
    }
  }
  for (long i = 0; i < q; i++) {
    cout << results[i] << endl;
  }
  return 0;
}


#include <iostream>
using namespace std;
int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  int q;
  cin >> q;
  long results[q];
  int pos = 0;
  for (int i = 0; i < q; i++) {
    long a, b;
    cin >> a >> b;
    long sum = 0;
    if (a < b) {
      for (long i = a; i <= b; i++) {
        if (i % 2 == 0) {
          sum += i;
        } else {
          sum -= i;
        }
      }
      results[pos] = sum;
      pos++;
    } else {
      for (long i = b; i <= a; i++) {
        if (i % 2 == 0) {
          sum += i;
        } else {
          sum -= i;
        }
      }
      results[pos] = sum;
      pos++;
    }

  }
  for (int i = 0; i < q; i++) {
    cout << results[i] << endl;
  }
}


#include <iostream>
#include <cmath>

using namespace std;
int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  int q;
  cin >> q;
  long results[q];
  long pos = 0;
  for (long i = 0; i < q; i++) {
    long a, b;
    cin >> a >> b;
    if (a < b) {
      long sum = 0, tmp_a = a, tmp_b = b;
      if (a % 2 != 0) {
        a++;
      }
      if (b % 2 != 0) {
        b--;
      }

      (a == b) ? sum += a : sum += (a + b) * ((b - a) / 2 + 1) / 2;

      a = tmp_a; b = tmp_b;

      if (a % 2 == 0) {
        a++;
      }
      if (b % 2 == 0) {
        b--;
      }

      (a == b) ? sum -= a : sum += (-a + -b) * ((b - a) / 2 + 1) / 2;

      results[pos] = sum;
      pos++;
    } else if (a == b){
      if (a % 2 != 0) a = -a;
      results[pos] = a;
      pos++;
    }

  }
  for (long i = 0; i < q; i++) {
    cout << results[i] << endl;
  }
  cout << endl;
  return 0;
}


#include <iostream>
#include <cmath>

using namespace std;
int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  int q;
  cin >> q;
  long results[q];
  int pos = 0;
  for (int i = 0; i < q; i++) {
    long a, b;
    cin >> a >> b;
    long sum = 0;
    if (a < b) {
      long sum = 0, tmp_a = a, tmp_b = b;
      if (a % 2 != 0) {
        a++;
      }
      if (b % 2 != 0) {
        b--;
      }

      (a == b) ? sum += a : sum += (a + b) * (b - a) / 2;

      a = tmp_a; b = tmp_b;

      if (a % 2 == 0) {
        a++;
      }
      if (b % 2 == 0) {
        b--;
      }

      (a == b) ? sum -= a : sum += (-a + -b) * (b - a) / 2;

      results[pos] = sum;
      pos++;
    } else if (a == b){
      if (a % 2 != 0) a = -a;
      results[pos] = a;
      pos++;
    }

  }
  for (int i = 0; i < q; i++) {
    cout << results[i] << endl;
  }
}


#include <iostream>
#include <cmath>

using namespace std;
int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  int q;
  cin >> q;
  long results[q];
  int pos = 0;
  for (int i = 0; i < q; i++) {
    long a, b;
    cin >> a >> b;
    long sum = 0;
    if (a < b) {
      long sum = 0, tmp_a = a, tmp_b = b;
      if (a % 2 != 0) {
        a++;
      }
      if (b % 2 != 0) {
        b--;
      }

      (a == b) ? sum += a : sum += (a + b) * ((b - a) / 2 + 1) / 2;

      a = tmp_a; b = tmp_b;

      if (a % 2 == 0) {
        a++;
      }
      if (b % 2 == 0) {
        b--;
      }

      (a == b) ? sum -= a : sum += (-a + -b) * ((b - a) / 2 + 1) / 2;

      results[pos] = sum;
      pos++;
    } else if (a == b){
      if (a % 2 != 0) a = -a;
      results[pos] = a;
      pos++;
    }

  }
  for (int i = 0; i < q; i++) {
    cout << results[i] << endl;
  }
}


#include<iostream>

using namespace std;

int main() {
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int sum = 0;
		int l, r;
		cin >> l >> r;
		int k;
		k = r - l + 1;
		if (k == 1) {
			if (l % 2 == 0) {
				cout << l << endl;
			}
			else {
				cout << sum - l << endl;
			}
		}
		else if (l % 2 == 0 && r % 2 == 0) {
			sum = l + r - ((l + r) / 2);
			cout << sum << endl;
		}
		else if (l % 2 != 0 && r % 2 != 0) {
			sum = sum - ((l + r) / 2);
			cout << sum << endl;
		}
		else if (l % 2 == 0 && r % 2 != 0) {
			sum -= (k / 2);
			cout << sum << endl;
			}
		else if (l % 2 != 0 && r % 2 == 0) {
			sum = (k / 2) + 1;
			cout << sum << endl;
		}
	}

	return 0;
}


#include<iostream>

using namespace std;

int main() {
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int sum = 0;
		int l, r;
		cin >> l >> r;
		for (int j = l; j <= r; j++) {
			if (j % 2 == 0) {
				sum += j;
			}
			else {
				sum -= j;
			}
		}
		cout << sum << endl;
	}

	return 0;
}


#include<iostream>

using namespace std;

int main() {
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int sum = 0;
		int l, r;
		cin >> l >> r;
		int k;
		k = r - l + 1;
		if (k == 1) {
			if (l % 2 == 0) {
				cout << l << endl;
			}
			else {
				cout << sum - l << endl;
			}
		}
		else if (l % 2 == 0 && r % 2 == 0) {
			sum = l + r - ((l + r) / 2);
			cout << sum << endl;
		}
		else if (l % 2 != 0 && r % 2 != 0) {
			sum = sum - ((l + r) / 2);
			cout << sum << endl;
		}
		else if (l % 2 == 0 && r % 2 != 0) {
			sum -= (k / 2);
			cout << sum << endl;
			}
		else if (l % 2 != 0 && r % 2 == 0) {
			sum = (l + r) / 2 + 1;
			cout << sum << endl;
		}
	}

	return 0;
}


#include<iostream>

using namespace std;

int main() {
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int sum = 0;
		int l, r;
		cin >> l >> r;
		for (int j = l; j < r; j++) {
			if (j % 2 == 0) {
				sum += j;
			}
			else {
				sum -= j;
			}
		}
		cout << sum << endl;
	}

	return 0;
}


#include<iostream>

using namespace std;

int main() {
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int sum = 0;
		int l, r;
		cin >> l >> r;
		int k;
		k = r - l + 1;
		if (k == 1) {
			if (l % 2 == 0) {
				cout << l << endl;
			}
			else {
				cout << sum - l << endl;
			}
		}
		else if (l % 2 == 0 && r % 2 == 0) {
			sum = l + r - ((l + r) / 2);
			cout << sum << endl;
		}
		else if (l % 2 != 0 && r % 2 != 0) {
			sum = sum - ((l + r) / 2);
			cout << sum << endl;
		}
		else if (l % 2 == 0 && r % 2 != 0) {
			sum -= (k / 2);
			cout << sum << endl;
			}
		else if (l % 2 != 0 && r % 2 == 0) {
			sum = ((l + r) / 2) + 1;
			cout << sum << endl;
		}
	}

	return 0;
}


#include<iostream>

using namespace std;

int main() {
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int sum = 0;
		int l, r;
		cin >> l >> r;
		int k;
		k = l - r + 1;
		if (k == 1) {
			if (l % 2 == 0) {
				cout << l << endl;
			}
			else {
				cout << sum - l << endl;
			}
		}
		else if (l % 2 == 0 && r % 2 == 0) {
			sum = l + r - ((l + r) / 2);
			cout << sum << endl;
		}
		else if (l % 2 != 0 && r % 2 != 0) {
			sum = sum - ((l + r) / 2);
			cout << sum << endl;
		}
		else if (l % 2 == 0 && r % 2 != 0) {
			sum = sum - k / 2;
			cout << sum << endl;
			}
		else if (l % 2 != 0 && r % 2 == 0) {
			sum = (l + r) / 2 + 1;
			cout << sum << endl;
		}
	}

	return 0;
}


#include<iostream>

using namespace std;

int main() {
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int sum = 0;
		int l, r;
		cin >> l >> r;
		int k;
		k = r - l + 1;
		if (k == 1) {
			if (l % 2 == 0) {
				cout << l << endl;
			}
			else {
				cout << sum - l << endl;
			}
		}
		else if (l % 2 == 0 && r % 2 == 0) {
			sum = l + r - ((l + r) / 2);
			cout << sum << endl;
		}
		else if (l % 2 != 0 && r % 2 != 0) {
			sum = sum - ((l + r) / 2);
			cout << sum << endl;
		}
		else if (l % 2 == 0 && r % 2 != 0) {
			sum -= (k / 2);
			cout << sum << endl;
			}
		else if (l % 2 != 0 && r % 2 == 0) {
			sum = (k / 2) ;
			cout << sum << endl;
		}
	}

	return 0;
}


#include<iostream>

using namespace std;

int main() {
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int sum = 0;
		int l, r;
		cin >> l >> r;
		int k;
		k = l - r + 1;
		if (k == 1) {
			if (l % 2 == 0) {
				cout << l << endl;
			}
			else {
				cout << sum - l << endl;
			}
		}
		else if (l % 2 == 0 && r % 2 == 0) {
			sum = l + r - ((l + r) / 2);
			cout << sum << endl;
		}
		else if (l % 2 != 0 && r % 2 != 0) {
			sum = sum - ((l + r) / 2);
			cout << sum << endl;
		}
		else if (l % 2 == 0 && r % 2 != 0) {
			sum = sum - (k / 2);
			cout << sum << endl;
			}
		else if (l % 2 != 0 && r % 2 == 0) {
			sum = (l + r) / 2 + 1;
			cout << sum << endl;
		}
	}

	return 0;
}


#include<iostream>

using namespace std;

int main() {
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int sum = 0;
		int l, r;
		cin >> l >> r;
		int k;
		k = l - r + 1;
		if (k == 1) {
			if (l % 2 == 0) {
				cout << l << endl;
			}
			else {
				cout << sum - l << endl;
			}
		}
		else if (l % 2 == 0 && r % 2 == 0) {
			sum = l + r - ((l + r) / 2);
			cout << sum << endl;
		}
		else if (l % 2 != 0 && r % 2 != 0) {
			sum = sum - ((l + r) / 2);
			cout << sum << endl;
		}
		else if (l % 2 == 0 && r % 2 != 0) {
			sum -= (k / 2);
			cout << sum << endl;
			}
		else if (l % 2 != 0 && r % 2 == 0) {
			sum = (l + r) / 2 + 1;
			cout << sum << endl;
		}
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	long long n,l,r,rez=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>l>>r;
		for(int j=l;j<=r;j++){
			if(j%2==0) rez+=j;
			else rez-=j;
		}
		cout<<rez<<endl;
		rez=0;
	}
	return 0;
}


/******************************************
--------***ID:ADNAN KISMETOVIC***----------
----***USER:kismetovic-codeforces.com***---
*******************************************/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int main(){
	long long n,l,r,rez=0;
	vector<long long> v;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>l>>r;
		for(int j=l;j<=r;j++){
			rez+=j*(pow(-1,j));
		}
		cout<<rez<<endl;
		rez=0;
	}

	return 0;
}


/******************************************
--------***ID:ADNAN KISMETOVIC***----------
----***USER:kismetovic-codeforces.com***---
*******************************************/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int main(){
	long long n,l,r,rez=0;
	vector<long long> v;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>l>>r;
		for(int j=l;j<=r;j++){
			rez+=j*(pow(-1,j));
		}
		v.push_back(rez);
		rez=0;
	}
	for(int i=0;i<v.size();i++)
		cout<<v[i]<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int INF=0x3f3f3f3f;
int a[100005][2];
int main()
{
    int n;
   scanf("%d",&n);
   int flag=0;
   for(int i=0;i<n;i++)
   {
       scanf("%d%d",&a[i][0],&a[i][1]);
       if(a[i][0]!=a[i][1])
        flag=1;
   }
   if(!flag)
   for(int i=1;i<n;i++)
   {
       if(a[i][0]>a[i-1][0])
       {
           flag=2;
           break;
       }
   }
   if(flag==0)
    printf("maybe\n");
   else if(flag==1)
    printf("rated\n");
   else
    printf("unrated\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int t,c,r,z,l,k,x,y,n,m,sum1=0,sum2=0,sum3=0,sum4=0,flag1=0,flag2=0,flag3=0,flag4=0,flag=0,sum=0,len=0;
	scanf("%lld",&n);
	for(int i=0;i<n;i++){
		scanf("%lld %lld",&x,&y);
		if(x==y){
			if(x%2){
				printf("%lld\n",-x);
			}
			else{
				printf("%lld\n",x);
			}
		}
		else{
			if(x%2){
				if(y%2){
					printf("%lld\n",-(y-x+1)/2-y);
				}
				else{
					printf("%lld\n",(y-x+1)/2);
				}
			}
			else{
				if(y%2){
					printf("%lld\n",-(y-x+1)/2);
				}
				else{
					printf("%lld\n",(y-x+1)/2+y);
				}
			}
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
int main(){
    int q;
    scanf("%d",&q);
    while(q--){
        int l,r;
        scanf("%d%d",&l,&r);

        if(l%2==1&&r%2==1){
            printf("%d\n",-1*((l-r)/2+r));
        }
        if(l%2==1&&r%2==0){
            printf("%d\n",(r-l+1)/2);
        }
        if(l%2==0&&r%2==0){
            printf("%d\n",((l-r)/2+r));
        }
        if(l%2==0&&r%2==1){
            printf("%d\n",-1*(r-l+1)/2);
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int t,c,r,z,l,k,x,y,n,m,sum1=0,sum2=0,sum3=0,sum4=0,flag1=0,flag2=0,flag3=0,flag4=0,flag=0,sum=0,len=0;
	scanf("%lld",&n);
	for(int i=0;i<n;i++){
		scanf("%lld %lld",&x,&y);
		if(x==y){
			if(x%2){
				printf("%lld\n",-x);
			}
			else{
				printf("%lld\n",x);
			}
		}
		else{
			if(x%2){
				if(y%2){
					printf("%lld\n",(y-x)/2-y);
				}
				else{
					printf("%lld\n",(y-x)/2);
				}
			}
			else{
				if(y%2){
					printf("%lld\n",-(y-x)/2);
				}
				else{
					printf("%lld\n",(y-x)/2+y);
				}
			}
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int t,c,r,z,l,k,x,y,n,m,sum1=0,sum2=0,sum3=0,sum4=0,flag1=0,flag2=0,flag3=0,flag4=0,flag=0,sum=0,len=0;
	scanf("%lld",&n);
	for(int i=0;i<n;i++){
		scanf("%lld %lld",&x,&y);
		if(x==y){
			if(x%2){
				printf("%lld\n",-x);
			}
			else{
				printf("%lld\n",x);
			}
		}
		else{
			if(x%2){
				if(y%2){
					printf("%lld\n",(y-x+1)/2-y);
				}
				else{
					printf("%lld\n",(y-x+1)/2);
				}
			}
			else{
				if(y%2){
					printf("%lld\n",-(y-x+1)/2);
				}
				else{
					printf("%lld\n",(y-x+1)/2+y);
				}
			}
		}
	}
}


            /*In the name of ALLAH, Most Gracious, Most Merciful*/
#include<bits/stdc++.h>

#define ll                      long long int
#define ull                     unsigned long long int
#define PI                      2*acos(0.0)
#define sqr(x)                  (x)*(x)
#define EPS                     10E-10
#define MOD                     1000000007
#define longlimit               92233720368547758
#define infinity                (1<<28)
#define bitcount                __builtin_popcount
#define pb(a)                   emplace_back(a)
#define mp                      make_pair
#define ff                      first
#define ss                      second
#define gcd(a, b)                __gcd(a,b)
#define lcm(a, b)                ((a)*(b))/gcd(a,b)
#define all(a)                  (a.begin()),(a.end())
#define UNIQUE(X)               (X).erase(unique(all(X)),(X).end())
#define DELETE(X)               (X).erase (remove (all(X)),(X).end())
#define SORT_UNIQUE(c)          (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
using namespace std;

long long sum(long long x)
{
    if(x%2== 0)
        return x/2;
    else
        return -x +sum(x-1);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    int t;
    cin >> t;
    while(t--)
    {
        ll l,r;
        cin>>l>>r;
        cout <<sum(r) - sum(l-1) << endl;
    }

}


            /*In the name of ALLAH, Most Gracious, Most Merciful*/
#include<bits/stdc++.h>

#define ll                      long long int
#define ull                     unsigned long long int
#define PI                      2*acos(0.0)
#define sqr(x)                  (x)*(x)
#define EPS                     10E-10
#define MOD                     1000000007
#define longlimit               92233720368547758
#define infinity                (1<<28)
#define bitcount                __builtin_popcount
#define pb(a)                   emplace_back(a)
#define mp                      make_pair
#define ff                      first
#define ss                      second
#define gcd(a, b)                __gcd(a,b)
#define lcm(a, b)                ((a)*(b))/gcd(a,b)
#define all(a)                  (a.begin()),(a.end())
#define UNIQUE(X)               (X).erase(unique(all(X)),(X).end())
#define DELETE(X)               (X).erase (remove (all(X)),(X).end())
#define SORT_UNIQUE(c)          (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    int t;
    cin >> t;
    while(t--)
    {
        ll a,b;
        cin>>a>>b;
        if (a%2==0 and b%2==0) cout<<(a+b)/2<<endl;
        else if (a%2==0 and b%2==1) cout<<(a-b-1)/2<<endl;
        else if (a%2==1 and b%2==0) cout<<(b+1-a)/2<<endl;
        else cout<<(-(a+b)/2)<<endl;

    }

}


            /*In the name of ALLAH, Most Gracious, Most Merciful*/
#include<bits/stdc++.h>

#define ll                      long long int
#define ull                     unsigned long long int
#define PI                      2*acos(0.0)
#define sqr(x)                  (x)*(x)
#define EPS                     10E-10
#define MOD                     1000000007
#define longlimit               92233720368547758
#define infinity                (1<<28)
#define bitcount                __builtin_popcount
#define pb(a)                   emplace_back(a)
#define mp                      make_pair
#define ff                      first
#define ss                      second
#define gcd(a, b)                __gcd(a,b)
#define lcm(a, b)                ((a)*(b))/gcd(a,b)
#define all(a)                  (a.begin()),(a.end())
#define UNIQUE(X)               (X).erase(unique(all(X)),(X).end())
#define DELETE(X)               (X).erase (remove (all(X)),(X).end())
#define SORT_UNIQUE(c)          (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    int t;
    cin>>t;
    while (t--)
    {
        ll a,b,x,sum1,sum2,odd,e,sum;
        cin>>a>>b;
        x=(b-1)+1;
        if (a%2==0 and b%2==0)
        {
            odd=x/2;e=(x+1)/2;
            if (a==b) sum=a;
            else sum=b-(odd);
        }
        else if (a%2==1 and b%2==1)
        {
            e=x/2; odd= (x+1)/2;
            if (a==b) sum=-a;
            else sum=(-b+(e));
        }
        else
        {
            if (a % 2 == 1)
                sum = x / 2;
            else sum = (-x / 2);
        }

        cout<<sum<<endl;
    }

}


            /*In the name of ALLAH, Most Gracious, Most Merciful*/
#include<bits/stdc++.h>

#define ll                      long long int
#define ull                     unsigned long long int
#define PI                      2*acos(0.0)
#define sqr(x)                  (x)*(x)
#define EPS                     10E-10
#define MOD                     1000000007
#define longlimit               92233720368547758
#define infinity                (1<<28)
#define bitcount                __builtin_popcount
#define pb(a)                   emplace_back(a)
#define mp                      make_pair
#define ff                      first
#define ss                      second
#define gcd(a, b)                __gcd(a,b)
#define lcm(a, b)                ((a)*(b))/gcd(a,b)
#define all(a)                  (a.begin()),(a.end())
#define UNIQUE(X)               (X).erase(unique(all(X)),(X).end())
#define DELETE(X)               (X).erase (remove (all(X)),(X).end())
#define SORT_UNIQUE(c)          (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    int t;
    cin>>t;
    while (t--)
    {
        ll a,b,sum=0,even,odd,x;
        cin>>a>>b;
        a--;
        if (!(a&1!=0))a>>=1; else a=-(a+1)/2;
        if (!(b&1!=0)) b>>=1; else b= -(b+1)/2;
        cout<<b-a<<endl;
    }

}


#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	int q;
	cin>>q;
	while(q--){
		int l,r;
		cin>>l>>r;
		long long ans=0;
		for(int i=l;i<=r;i++){
			if(i%2==0) ans+=i;
			else ans-=i;
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define endl '\n';
int n,sum,l,r;
inline LL F(LL x) {
    if(x % 2 == 0) return x / 2;
    else return (x - 1) / 2 - x;
}
int main() {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n;
    LL lsum = 0,rsum = 0;
    while(n --) {
        cin >> l >> r;
        cout << F(r) - F(l - 1) << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
long long F(long long x){
	if(x % 2 == 0) return x/2;
	else return F(x-1) - x;
}
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	int n;
	long long l,r;
	cin>>n;
	while(n--){
		cin>>l>>r;
		cout<<F(r)-F(l-1)<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define endl '\n';
int n,sum,l,r;
int main() {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n;
    vector<int> f(n + 1);
    f[0] = 0;
    for(int i = 1;i <= n; ++i) {
        if(i&1) f[i] = f[i - 1] - i;
        else f[i] = i >> 1;
    }
    while(n --) {
        cin >> l >> r;
        cout << f[r] - f[l - 1] << endl;
    }
    return 0;
}


#include <iostream>
#include<cmath>
using namespace std;

int main()
{
long long x;
cin>>x;
unsigned long long s1,s2;
for(int i=0;i<x;i++)
{
    cin>>s1>>s2;
    long long sum1=(s2*(s2+1))/2;
    long long sum2=((s1-1)*(s1))/2;
    long long sum3=abs(sum1-sum2);
    for(int j=s1;j<=s2;j++)
    {
        if(j%2!=0){
            sum3-=(2*j);
        }
    }
cout<<sum3<<endl;
}
    return 0;
}


#include <iostream>
#include<cmath>
using namespace std;

int main()
{
long long x;
cin>>x;
unsigned long long s1,s2;
for(int i=0;i<x;i++)
{
    cin>>s1>>s2;
    long long sum1=(s2*(s2+1))/2;
    long long sum2=((s1-1)*(s1))/2;
    long long w=s2/2;
    long long sum4=w*(w+1);
    w=(s1-1)/2;
    long long sum5=(w)*(w+1);
    int sum6=abs(sum4-sum5);
    int sum7=abs(sum1-sum2);
    int sum3=abs(sum7-(2*sum6));
    if(s2%2!=0){
        cout<<sum3*-1<<endl;
    }
    else
        cout<<sum3<<endl;
}
    return 0;
}


#include <iostream>
#include<cmath>
using namespace std;

int main()
{
int x;
cin>>x;
long long s1,s2;
for(int i=0;i<x;i++)
{
    cin>>s1>>s2;
    long long sum1=(s2*(s2+1))/2;
    long long sum2=((s1-1)*(s1))/2;
    int w=s2/2;
    long long sum4=w*(w+1);
    w=(s1-1)/2;
    long long sum5=(w)*(w+1);
    //cout<<sum1<<" "<<sum2<<" "<<sum4<<" "<<sum5<<endl;
    long long sum6=(sum4-sum5);
    long long sum7=(sum1-sum2);
    long long sum3=abs(sum7-(2*sum6));
    if(s2%2!=0){
        cout<<sum3*-1<<endl;
    }
    else
        cout<<sum3<<endl;
}
    return 0;
}


#include <iostream>
#include<cmath>
using namespace std;

int main()
{
long long x;
cin>>x;
long long s1,s2;
for(int i=0;i<x;i++)
{
    cin>>s1>>s2;
    unsigned long long sum1=(s2*(s2+1))/2;
    unsigned long long sum2=((s1-1)*(s1))/2;
    unsigned long long w=s2/2;
    unsigned long long sum4=w*(w+1);
    w=(s1-1)/2;
    unsigned long long sum5=(w)*(w+1);
    long long sum6=abs(sum4-sum5);
    long long sum7=abs(sum1-sum2);
    long long sum3=abs(sum7-(2*sum6));
    if(s2%2!=0){
        cout<<sum3*-1<<endl;
    }
    else
        cout<<sum3<<endl;
}
    return 0;
}


#include <iostream>
#include<cmath>
using namespace std;

int main()
{
int x;
cin>>x;
long long s1,s2;
for(int i=0;i<x;i++)
{
    cin>>s1>>s2;
    long long sum1=(s2*(s2+1))/2;
    long long sum2=((s1-1)*(s1))/2;
    int w=s2/2;
    long long sum4=w*(w+1);
    w=(s1-1)/2;
    long long sum5=(w)*(w+1);
    //cout<<sum1<<" "<<sum2<<" "<<sum4<<" "<<sum5<<endl;
    long long sum6=(sum4-sum5);
    long long sum7=(sum1-sum2);
    long long sum3=abs(sum7-(2*sum6));
    if(s2%2!=0){
        cout<<sum3*-1<<endl;
    }
    else
        cout<<sum3;
}
    return 0;
}


/*
*         ****FOX****
*/
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <limits>
//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#include <utility>
#include <list>
#include <cstdio>
#include<forward_list>
#include<cassert>
#include<algorithm>
#include<string>
#include <numeric>
#define Omar_Hafez ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi 3.1415926536
#define ll long long
#define ull unsigned long long
#define lli long long int
using namespace std;
int main()
{
    Omar_Hafez
        ll n, s, e; cin >> n;
        for (int i = 0; i < n; i++)
        {
            cin >> s >> e;
            if (s == e && s % 2 == 0)cout << s << "\n";
            else if (s == e && s % 2 != 0)cout << (s * -1) << "\n";
            else if (s >= 1)
            {
                ll od_E = 0, ev_E = 0, od_S = 0, ev_S = 0;
                if (e % 2 == 0) { ev_E = (e / 2 * ((e / 2) + 1));  od_E = (((e - 1) + 1) / 2) * (((e - 1) + 1) / 2); }
                else if (e % 2 != 0) { ev_E = (((e - 1) / 2) * (((e - 1) / 2) + 1)); od_E = (((e)+1) / 2) * (((e)+1) / 2); }
                if (s % 2 == 0) { ev_S = (((s - 2) / 2) * (((s - 2) / 2) + 1));  od_S = (((s - 1) + 1) / 2) * (((s - 1) + 1) / 2); }
                else if (s % 2 != 0) { ev_S = (((s - 1) / 2) * (((s - 1) / 2) + 1));  od_S = ((((s - 2) + 1) / 2) * (((s - 2) + 1) / 2)); }
                ll res_o = (od_E - od_S) * -1;
                ll res_e = (ev_E - ev_S);
                cout << res_o + res_e << "\n";
            }
        }
    return 0;
}


/*
*         ****FOX****
*/
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <limits>
//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#include <utility>
#include <list>
#include <cstdio>
#include<forward_list>
#include<cassert>
#include<algorithm>
#include<string>
#include <numeric>
#define Omar_Hafez ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi 3.1415926536
#define ll long long
#define ull unsigned long long
#define lli long long int
using namespace std;
ll even(ll n) { return n * (n + 1); }
ll odd(ll n) { return n * (n + 1) / 2; }
int main()
{
    Omar_Hafez
        ll n, s, e; cin >> n;
        for (int i = 0; i < n; i++)
        {
        cin >> s >> e;
        ll sum_even = even(e / 2) - even(s-1) / 2;
        ll sum_odd = odd(e) - odd(s - 1) - sum_even;
        cout << sum_even - sum_odd << "\n";
        }
    return 0;
}


/*
*         ****FOX****
*/
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <limits>
//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#include <utility>
#include <list>
#include <cstdio>
#include<forward_list>
#include<cassert>
#include<algorithm>
#include<string>
#include <numeric>
#define Omar_Hafez ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi 3.1415926536
#define ll long long
#define ull unsigned long long
#define lli long long int
using namespace std;
int main()
{
    Omar_Hafez
        ll n, s, e; cin >> n;
        for (int i = 0; i < n; i++)
        {
            cin >> s >> e;
            if (s == e && s % 2 == 0)cout << s << "\n";
            else if (s == e && s % 2 != 0)cout << (s * -1) << "\n";
            else if (s == 1)
            {
                ll od_E = 0, ev_E = 0;
                if (e % 2 == 0) { ev_E = (e / 2 * ((e / 2) + 1));  od_E = (((e - 1) + 1) / 2) * (((e - 1) + 1) / 2); }
                else if (e % 2 != 0) { ev_E = (((e - 1) / 2) * (((e - 1) / 2) + 1)); od_E = (((e)+1) / 2) * (((e)+1) / 2); }
                cout << (od_E * -1) + ev_E << "\n";
            }
            else if (s > 1)
            {
                ll od_E = 0, ev_E = 0, od_S = 0, ev_S = 0;
                if (e % 2 == 0) { ev_E = (e / 2 * ((e / 2) + 1));  od_E = (((e - 1) + 1) / 2) * (((e - 1) + 1) / 2); }
                else if (e % 2 != 0) { ev_E = (((e - 1) / 2) * (((e - 1) / 2) + 1)); od_E = (((e)+1) / 2) * (((e)+1) / 2); }
                if (s % 2 == 0) { ev_S = (((s - 2) / 2) * (((s - 2) / 2) + 1));  od_S = (((s - 1) + 1) / 2) * (((s - 1) + 1) / 2); }
                else if (s % 2 != 0) { ev_S = (((s - 1) / 2) * (((s - 1) / 2) + 1));  od_S = ((((s - 2) + 1) / 2) * (((s - 2) + 1) / 2)); }
                ll res_o = (od_E - od_S) * -1;
                ll res_e = (ev_E - ev_S);
                cout << res_o + res_e << "\n";
            }
        }
    return 0;
}


/*
*         ****FOX****
*/
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <limits>
//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#include <utility>
#include <list>
#include <cstdio>
#include<forward_list>
#include<cassert>
#include<algorithm>
#include<string>
#include <numeric>
#define Omar_Hafez ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi 3.1415926536
#define ll long long
#define ull unsigned long long
#define lli long long int
using namespace std;
ll even(ll n) { return n * (n + 1); }
ll odd(ll n) { return n * (n + 1) / 2; }
int main()
{
    Omar_Hafez
        ll n, s, e; cin >> n;
        for (int i = 0; i < n; i++)
        {
        cin >> s >> e;
        ll sum_even = even(e / 2) - even(s / 2);
        ll sum_odd = odd(e) - odd(s - 1) - sum_even;
        cout << sum_even - sum_odd << "\n";
        }
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <math.h>

using namespace std;

int main()
{
    int q;
    cin>>q;
    while(q--)
    {
        long long l, r;
        cin>>l>>r;
        if(l == r)
        {
            cout<<l*(long long)pow(-1,l)<<endl;
        }
        else if((l + r) % 2 == 0)
        {
            cout<<(long long)-pow(-1,l) + r*(long long)pow(-1,r)<<endl;
        }
        else
        {
            long long tmp;
            tmp = (r - l + 1) / 2;
            if(l % 2 == 0)cout<< (-1) * (long long)tmp<<endl;
            else {cout<< (-1) * (long long)(-tmp)<<endl;}
        }
    }
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <math.h>

using namespace std;

long long f(long long x)
{
    if(x % 2 == 0)return x/2;
    else
    {
        return f(x-1) - x;
    }
}

int main()
{
    int q;
    cin>>q;
    while(q--)
    {
        long long l, r;
        cin>>l>>r;
        cout<<f(r) - f(l -1)<<endl;
    }
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <math.h>

using namespace std;

int main()
{
    int q;
    cin>>q;
    while(q--)
    {
        int l, r;
        cin>>l>>r;
        if(l == r)
        {
            cout<<l<<endl;
        }
        else if((l + r) % 2 == 0)
        {
            cout<<-pow(-1,l) + r*pow(-1,r)<<endl;
        }
        else
        {
            int tmp;
            tmp = (r - l + 1) / 2;
            if(l % 2 == 0)cout<< (-1) * tmp<<endl;
            else {cout<< (-1) * (-tmp)<<endl;}
        }
    }
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <math.h>

using namespace std;

int main()
{
    int q;
    cin>>q;
    while(q--)
    {
        int l, r;
        cin>>l>>r;
        if(l == r)
        {
            cout<<l*pow(-1,l)<<endl;
        }
        else if((l + r) % 2 == 0)
        {
            cout<<-pow(-1,l) + r*pow(-1,r)<<endl;
        }
        else
        {
            int tmp;
            tmp = (r - l + 1) / 2;
            if(l % 2 == 0)cout<< (-1) * tmp<<endl;
            else {cout<< (-1) * (-tmp)<<endl;}
        }
    }
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <math.h>

using namespace std;

int main()
{
    int q;
    cin>>q;
    while(q--)
    {
        long long l, r;
        cin>>l>>r;
        if(l == r)
        {
            cout<<l*pow(-1,l)<<endl;
        }
        else if((l + r) % 2 == 0)
        {
            cout<<-pow(-1,l) + r*pow(-1,r)<<endl;
        }
        else
        {
            long long tmp;
            tmp = (r - l + 1) / 2;
            if(l % 2 == 0)cout<< (-1) * tmp<<endl;
            else {cout<< (-1) * (-tmp)<<endl;}
        }
    }
}


/***
	chauhan176's code
***/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long int
#define fi first
#define se second
#define mod 1000000007
#define maxn 200005
#define stringio cin.ignore(256, '\n')  //to ignore end line before taking string input
#define go_t ll t;cin>>t;while(t--)
#define go_pt ll t;cin>>t;for(ll tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))

typedef pair<ll,ll>pii;
char s[maxn];
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    //freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    //freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);

    ll n;
    cin>>n;

    scanf("%s",s);
    //cout<<s<<endl;
    ll initial=1;
    for(ll i=1;i<n;i++)
    {
        if(s[i]!=s[i-1])
            initial++;
    }
    //cout<<initial<<endl;
    if(initial==n)
    {
        cout<<n<<endl;
        return 0;
    }
    ll startmax=1;
    ll startindex;
    for(ll i=1;i<n;i++)
    {
        if(s[i]==s[i-1])
            startmax++;
        else{
            startindex=i;
            break;
        }
    }
    if(startmax>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    ll endmax=1;
    ll endindex;
    for(ll i=n-2;i>=0;i--)
    {
        if(s[i]==s[i+1])
            endmax++;
        else{
            endindex=i;
            break;
        }
    }
    if(endmax>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    ll count=1;
    ll maxx=0;
    //cout<<startindex<<" "<<endindex<<endl;
    for(ll i=startindex+1;i<=endindex;i++)
    {
        if(s[i]==s[i-1])
        {
            count++;
        }
        else{
            if(count>maxx)
                maxx=count;
            count=1;
        }
    }
    if(count>maxx)
        maxx=count;
    //cout<<maxx<<endl;
    if(maxx>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    ll twopair=0;
    count=1;
    for(ll i=1;i<n;i++)
    {
        if(s[i]==s[i-1])
            count++;
        else
        {
            if(count==2)
            {
                twopair++;
            }
            count=1;
        }
    }
    if(twopair>=2)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    if(startmax==2 || endmax==2)
    {
        cout<<initial+1<<endl;
    }
    else
        cout<<initial<<endl;
    return 0;
}


/***
	chauhan176's code
***/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long int
#define fi first
#define se second
#define mod 1000000007
#define maxn 200005
#define stringio cin.ignore(256, '\n')  //to ignore end line before taking string input
#define go_t int t;cin>>t;while(t--)
#define go_pt int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))

typedef pair<int,ll>pii;
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    //freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    //freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);

    int n;
    cin>>n;

    stringio;
    string s;
    cin>>s;
    int initial=1;
    for(int i=1;i<n;i++)
    {
        if(s[i]!=s[i-1])
            initial++;
    }
    //cout<<initial<<endl;

    pair<int,int>one; // start index and frequency
    pair<int,int>zero;
    one.fi=one.se=0;
    zero.fi=zero.se=0;

    int startmax=1;
    int startindex;
    for(int i=1;i<n;i++)
    {
        if(s[i]==s[i-1])
            startmax++;
        else{
            startindex=i;
            break;
        }
    }
    if(startmax>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    int endmax=1;
    int endindex;
    for(int i=n-2;i>=0;i--)
    {
        if(s[i]==s[i+1])
            endmax++;
        else{
            endindex=i;
            break;
        }
    }
    if(endmax>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    int count=1;
    int maxx=0;
    //cout<<startindex<<" "<<endindex<<endl;
    for(int i=startindex+1;i<=endindex;i++)
    {
        if(s[i]==s[i-1])
        {
            count++;
        }
        else{
            if(count>maxx)
                maxx=count;
            count=1;
        }
    }
    if(count>maxx)
        maxx=count;
    //cout<<maxx<<endl;
    if(maxx>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }

    if(startmax==2 || endmax==2)
    {
        cout<<initial+1<<endl;
    }
    else
        cout<<initial<<endl;
    return 0;
}


/***
	chauhan176's code
***/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long int
#define fi first
#define se second
#define mod 1000000007
#define maxn 200005
#define stringio cin.ignore(256, '\n')  //to ignore end line before taking string input
#define go_t ll t;cin>>t;while(t--)
#define go_pt ll t;cin>>t;for(ll tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))

typedef pair<ll,ll>pii;
char s[maxn];
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    //freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    //freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);

    ll n;
    cin>>n;

    scanf("%s",s);
    //cout<<s<<endl;
    ll initial=1;
    for(ll i=1;i<n;i++)
    {
        if(s[i]!=s[i-1])
            initial++;
        else
            continue;
    }
    //cout<<initial<<endl;
    if(initial==n)
    {
        cout<<n<<endl;
        return 0;
    }
    ll startmax=1;
    ll startindex;
    for(ll i=1;i<n;i++)
    {
        if(s[i]==s[i-1])
            startmax++;
        else{
            startindex=i;
            break;
        }
    }
    if(startmax>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    ll endmax=1;
    ll endindex;
    for(ll i=n-2;i>=0;i--)
    {
        if(s[i]==s[i+1])
            endmax++;
        else{
            endindex=i;
            break;
        }
    }
    if(endmax>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    ll count=1;
    ll maxx=0;
    //cout<<startindex<<" "<<endindex<<endl;
    for(ll i=startindex+1;i<=endindex;i++)
    {
        if(s[i]==s[i-1])
        {
            count++;
        }
        else{
            if(count>maxx)
                maxx=count;
            count=1;
        }
    }
    if(count>maxx)
        maxx=count;
    //cout<<maxx<<endl;
    if(maxx>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    ll twopair=0;
    count=1;
    for(ll i=1;i<n;i++)
    {
        if(s[i]==s[i-1])
            count++;
        else
        {
            if(count==2)
            {
                twopair++;
            }
            count=1;
        }
    }
    if(twopair>=2)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    if(startmax==2 || endmax==2)
    {
        cout<<initial+1<<endl;
    }
    else
        cout<<initial<<endl;
    return 0;
}


/***
	chauhan176's code
***/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long int
#define fi first
#define se second
#define mod 1000000007
#define maxn 200005
#define stringio cin.ignore(256, '\n')  //to ignore end line before taking string input
#define go_t int t;cin>>t;while(t--)
#define go_pt int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))

typedef pair<int,ll>pii;
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    //freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    //freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);

    int n;
    cin>>n;

    stringio;
    string s;
    cin>>s;
    int initial=1;
    for(int i=1;i<n;i++)
    {
        if(s[i]!=s[i-1])
            initial++;
    }
    //cout<<initial<<endl;
    if(initial==n)
    {
        cout<<n<<endl;
        return 0;
    }
    int startmax=1;
    int startindex;
    for(int i=1;i<n;i++)
    {
        if(s[i]==s[i-1])
            startmax++;
        else{
            startindex=i;
            break;
        }
    }
    if(startmax>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    int endmax=1;
    int endindex;
    for(int i=n-2;i>=0;i--)
    {
        if(s[i]==s[i+1])
            endmax++;
        else{
            endindex=i;
            break;
        }
    }
    if(endmax>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    int count=1;
    int maxx=0;
    //cout<<startindex<<" "<<endindex<<endl;
    for(int i=startindex+1;i<=endindex;i++)
    {
        if(s[i]==s[i-1])
        {
            count++;
        }
        else{
            if(count>maxx)
                maxx=count;
            count=1;
        }
    }
    if(count>maxx)
        maxx=count;
    //cout<<maxx<<endl;
    if(maxx>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    int twopair=0;
    count=1;
    for(int i=1;i<n;i++)
    {
        if(s[i]==s[i-1])
            count++;
        else
        {
            if(count==2)
            {
                twopair++;
            }
            count=1;
        }
    }
    if(twopair>=2)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    if(startmax==2 || endmax==2)
    {
        cout<<initial+1<<endl;
    }
    else
        cout<<initial<<endl;
    return 0;
}


/***
	chauhan176's code
***/
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long int
#define fi first
#define se second
#define mod 1000000007
#define maxn 200005
#define stringio cin.ignore(256, '\n')  //to ignore end line before taking string input
#define go_t ll t;cin>>t;while(t--)
#define go_pt ll t;cin>>t;for(ll tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))

typedef pair<ll,ll>pii;
char s[maxn];
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    //freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    //freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);

    ll n;
    cin>>n;

    cin>>s;
    //cout<<s<<endl;
    ll initial=1;
    for(ll i=1;i<n;i++)
    {
        if(s[i]!=s[i-1])
            initial++;
    }
    //cout<<initial<<endl;
    if(initial==n)
    {
        cout<<n<<endl;
        return 0;
    }
    ll startmax=1;
    ll startindex;
    for(ll i=1;i<n;i++)
    {
        if(s[i]==s[i-1])
            startmax++;
        else{
            startindex=i;
            break;
        }
    }
    if(startmax>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    ll endmax=1;
    ll endindex;
    for(ll i=n-2;i>=0;i--)
    {
        if(s[i]==s[i+1])
            endmax++;
        else{
            endindex=i;
            break;
        }
    }
    if(endmax>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    ll count=1;
    ll maxx=0;
    //cout<<startindex<<" "<<endindex<<endl;
    for(ll i=startindex+1;i<=endindex;i++)
    {
        if(s[i]==s[i-1])
        {
            count++;
        }
        else{
            if(count>maxx)
                maxx=count;
            count=1;
        }
    }
    if(count>maxx)
        maxx=count;
    //cout<<maxx<<endl;
    if(maxx>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    ll twopair=0;
    count=1;
    for(ll i=1;i<n;i++)
    {
        if(s[i]==s[i-1])
            count++;
        else
        {
            if(count==2)
            {
                twopair++;
            }
            count=1;
        }
    }
    if(count==2)
        twopair++;
    if(twopair>=2)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    if(startmax==2 || endmax==2)
    {
        cout<<initial+1<<endl;
    }
    else if(initial==n-1)
        cout<<n<<endl;
    else
        cout<<initial<<endl;
    return 0;
}


/***
	chauhan176's code
***/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long int
#define fi first
#define se second
#define mod 1000000007
#define maxn 200005
#define stringio cin.ignore(256, '\n')  //to ignore end line before taking string input
#define go_t ll t;cin>>t;while(t--)
#define go_pt ll t;cin>>t;for(ll tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))

typedef pair<ll,ll>pii;
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    //freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    //freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);

    ll n;
    cin>>n;

    stringio;
    string s;
    cin>>s;
    ll initial=1;
    for(ll i=1;i<n;i++)
    {
        if(s[i]!=s[i-1])
            initial++;
    }
    //cout<<initial<<endl;
    if(initial==n)
    {
        cout<<n<<endl;
        return 0;
    }
    ll startmax=1;
    ll startindex;
    for(ll i=1;i<n;i++)
    {
        if(s[i]==s[i-1])
            startmax++;
        else{
            startindex=i;
            break;
        }
    }
    if(startmax>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    ll endmax=1;
    ll endindex;
    for(ll i=n-2;i>=0;i--)
    {
        if(s[i]==s[i+1])
            endmax++;
        else{
            endindex=i;
            break;
        }
    }
    if(endmax>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    ll count=1;
    ll maxx=0;
    //cout<<startindex<<" "<<endindex<<endl;
    for(ll i=startindex+1;i<=endindex;i++)
    {
        if(s[i]==s[i-1])
        {
            count++;
        }
        else{
            if(count>maxx)
                maxx=count;
            count=1;
        }
    }
    if(count>maxx)
        maxx=count;
    //cout<<maxx<<endl;
    if(maxx>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    ll twopair=0;
    count=1;
    for(ll i=1;i<n;i++)
    {
        if(s[i]==s[i-1])
            count++;
        else
        {
            if(count==2)
            {
                twopair++;
            }
            count=1;
        }
    }
    if(twopair>=2)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    if(startmax==2 || endmax==2)
    {
        cout<<initial+1<<endl;
    }
    else
        cout<<initial<<endl;
    return 0;
}


/***
	chauhan176's code
***/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long int
#define fi first
#define se second
#define mod 1000000007
#define maxn 200005
#define stringio cin.ignore(256, '\n')  //to ignore end line before taking string input
#define go_t int t;cin>>t;while(t--)
#define go_pt int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))

typedef pair<int,ll>pii;
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    //freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    //freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);

    int n;
    cin>>n;

    stringio;
    string s;
    cin>>s;
    int initial=1;
    for(int i=1;i<n;i++)
    {
        if(s[i]!=s[i-1])
            initial++;
    }
    //cout<<initial<<endl;
    if(initial==n)
    {
        cout<<n<<endl;
        return 0;
    }
    int startmax=1;
    int startindex;
    for(int i=1;i<n;i++)
    {
        if(s[i]==s[i-1])
            startmax++;
        else{
            startindex=i;
            break;
        }
    }
    if(startmax>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    int endmax=1;
    int endindex;
    for(int i=n-2;i>=0;i--)
    {
        if(s[i]==s[i+1])
            endmax++;
        else{
            endindex=i;
            break;
        }
    }
    if(endmax>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    int count=1;
    int maxx=0;
    //cout<<startindex<<" "<<endindex<<endl;
    for(int i=startindex+1;i<=endindex;i++)
    {
        if(s[i]==s[i-1])
        {
            count++;
        }
        else{
            if(count>maxx)
                maxx=count;
            count=1;
        }
    }
    if(count>maxx)
        maxx=count;
    //cout<<maxx<<endl;
    if(maxx>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    int twopair=0;
    count=1;
    for(int i=0;i<n;i++)
    {
        if(s[i]==s[i-1])
            count++;
        else
        {
            if(count==2)
            {
                twopair++;
            }
            count=1;
        }
    }
    if(twopair>=2)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    if(startmax==2 || endmax==2)
    {
        cout<<initial+1<<endl;
    }
    else
        cout<<initial<<endl;
    return 0;
}


/***
	chauhan176's code
***/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long int
#define fi first
#define se second
#define mod 1000000007
#define maxn 200005
#define stringio cin.ignore(256, '\n')  //to ignore end line before taking string input
#define go_t ll t;cin>>t;while(t--)
#define go_pt ll t;cin>>t;for(ll tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))

typedef pair<ll,ll>pii;
string s;
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    //freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    //freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);

    ll n;
    cin>>n;

    stringio;
    cin>>s;
    ll initial=1;
    for(ll i=1;i<n;i++)
    {
        if(s[i]!=s[i-1])
            initial++;
        else
            continue;
    }
    //cout<<initial<<endl;
    if(initial==n)
    {
        cout<<n<<endl;
        return 0;
    }
    ll startmax=1;
    ll startindex;
    for(ll i=1;i<n;i++)
    {
        if(s[i]==s[i-1])
            startmax++;
        else{
            startindex=i;
            break;
        }
    }
    if(startmax>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    ll endmax=1;
    ll endindex;
    for(ll i=n-2;i>=0;i--)
    {
        if(s[i]==s[i+1])
            endmax++;
        else{
            endindex=i;
            break;
        }
    }
    if(endmax>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    ll count=1;
    ll maxx=0;
    //cout<<startindex<<" "<<endindex<<endl;
    for(ll i=startindex+1;i<=endindex;i++)
    {
        if(s[i]==s[i-1])
        {
            count++;
        }
        else{
            if(count>maxx)
                maxx=count;
            count=1;
        }
    }
    if(count>maxx)
        maxx=count;
    //cout<<maxx<<endl;
    if(maxx>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    ll twopair=0;
    count=1;
    for(ll i=1;i<n;i++)
    {
        if(s[i]==s[i-1])
            count++;
        else
        {
            if(count==2)
            {
                twopair++;
            }
            count=1;
        }
    }
    if(twopair>=2)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    if(startmax==2 || endmax==2)
    {
        cout<<initial+1<<endl;
    }
    else
        cout<<initial<<endl;
    return 0;
}


/***
	chauhan176's code
***/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long int
#define fi first
#define se second
#define mod 1000000007
#define maxn 200005
#define stringio cin.ignore(256, '\n')  //to ignore end line before taking string input
#define go_t int t;cin>>t;while(t--)
#define go_pt int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))

typedef pair<int,ll>pii;
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    //freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    //freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);

    int n;
    cin>>n;

    stringio;
    string s;
    cin>>s;
    int initial=1;
    for(int i=1;i<n;i++)
    {
        if(s[i]!=s[i-1])
            initial++;
    }
    //cout<<initial<<endl;
    int startmax=1;
    int startindex;
    for(int i=1;i<n;i++)
    {
        if(s[i]==s[i-1])
            startmax++;
        else{
            startindex=i;
            break;
        }
    }
    if(startmax>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    int endmax=1;
    int endindex;
    for(int i=n-2;i>=0;i--)
    {
        if(s[i]==s[i+1])
            endmax++;
        else{
            endindex=i;
            break;
        }
    }
    if(endmax>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    int count=1;
    int maxx=0;
    //cout<<startindex<<" "<<endindex<<endl;
    for(int i=startindex+1;i<=endindex;i++)
    {
        if(s[i]==s[i-1])
        {
            count++;
        }
        else{
            if(count>maxx)
                maxx=count;
            count=1;
        }
    }
    if(count>maxx)
        maxx=count;
    //cout<<maxx<<endl;
    if(maxx>=3)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    int twopair=0;
    count=1;
    for(int i=0;i<n;i++)
    {
        if(s[i]==s[i-1])
            count++;
        else
        {
            if(count==2)
            {
                twopair++;
            }
            count=1;
        }
    }
    if(twopair>=2)
    {
        cout<<initial+2<<endl;
        return 0;
    }
    if(startmax==2 || endmax==2)
    {
        cout<<initial+1<<endl;
    }
    else
        cout<<initial<<endl;
    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;            typedef vector<vi> vii;
typedef vector<ll> vl;             typedef vector<vl> vll;
typedef pair<int,int> pi;          typedef pair<pi,int> pii;
typedef pair<ll,ll> pl;            typedef pair<pl,ll> pll;
typedef pair<int,bool> pib;        typedef pair<ll,bool> plb;

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define in insert
#define er erase
//returns (a^n mod p)---------------------------------------------------------------------------------------------------------------
ll power(ll a,ll n,ll p)
{
	if(n == 0)
	{
		return 1;
	}
	else if(n%2 == 0)
	{
		ll ans = power(a,n/2,p);
		return (ans*ans)%p;
	}
	else
	{
		ll ans = power(a,n-1,p);
		return (ans*a)%p;
	}
}

//returns (a^-1 mod p)(if p is prime)----------------------------------------------------------------------------------------------
ll inverse(ll a,ll p)
{
   return power(a,p-2,p);
}
//----------------------------------------------------------------------------------------------------------------------------------

void solve()
{
   int n;
   cin>>n;
   string s;
   cin>>s;
   vi v;
   int curr_cnt = 0;
   for(int i=0;i<n;i++)
   {
   	  curr_cnt++;
   	  if(i == n-1 || s[i] != s[i+1])
   	  {
   	  	v.pb(curr_cnt);
   	  	curr_cnt = 0;
   	  }
   }
   bool b = false;
   int x = v.size();
   for(int i=0;i<x-1;i++)
   {
   	  if((v[i] > 1 && v[i+1] > 1) || v[i] > 2 || v[i+1] > 2)
   	  {
         b = true;
         break;
   	  }
   }
   if(b)
   {
   	  cout<<x+2<<endl;
   }
   else
   {
       if(x == 1)
       {
       	  if(v[0] > 1)
       	  {
       	  	cout<<2<<endl;
       	  }
       	  else
       	  {
       	  	cout<<1<<endl;
       	  }
       }
       else
       {
       	  if(v[0] > 1 || v[1] > 1 || v[x-1] > 1 || v[x-2] > 1)
       	  {
       	  	 cout<<x+1<<endl;
       	  }
       	  else
       	  {
       	  	cout<<x<<endl;
       	  }
       }
   }

}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef PAVANSAI006
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("err.txt", "w", stderr);
#endif
    ll t = 1;
    //cin>>t;
    while(t--)
    {
    	solve();
    }

}


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

typedef long long ll;
typedef vector<int> vi;            typedef vector<vi> vii;
typedef vector<ll> vl;             typedef vector<vl> vll;
typedef pair<int,int> pi;          typedef pair<pi,int> pii;
typedef pair<ll,ll> pl;            typedef pair<pl,ll> pll;
typedef pair<int,bool> pib;        typedef pair<ll,bool> plb;

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define in insert
#define er erase
//returns (a^n mod p)---------------------------------------------------------------------------------------------------------------
ll power(ll a,ll n,ll p)
{
	if(n == 0)
	{
		return 1;
	}
	else if(n%2 == 0)
	{
		ll ans = power(a,n/2,p);
		return (ans*ans)%p;
	}
	else
	{
		ll ans = power(a,n-1,p);
		return (ans*a)%p;
	}
}

//returns (a^-1 mod p)(if p is prime)----------------------------------------------------------------------------------------------
ll inverse(ll a,ll p)
{
   return power(a,p-2,p);
}
//----------------------------------------------------------------------------------------------------------------------------------

void solve()
{
   int n;
   cin>>n;
   string s;
   cin>>s;
   vi v;
   int curr_cnt = 0;
   for(int i=0;i<n;i++)
   {
   	  curr_cnt++;
   	  if(i == n-1 || s[i] != s[i+1])
   	  {
   	  	v.pb(curr_cnt);
   	  	curr_cnt = 0;
   	  }
   }
   bool b = false;
   int x = v.size();
   for(int i=0;i<x-1;i++)
   {
   	  if((v[i] > 1 && v[i+1] > 1))
   	  {
         b = true;
         break;
   	  }
   }
   for(int i=0;i<x;i++)
   {
   	  if(v[i] > 2)
   	  {
   	  	b = true;
   	  	break;
   	  }
   }
   if(b)
   {
   	  cout<<x+2<<endl;
   }
   else
   {
       if(x == 1)
       {
       	  if(v[0] > 1)
       	  {
       	  	cout<<2<<endl;
       	  }
       	  else
       	  {
       	  	cout<<1<<endl;
       	  }
       }
       else
       {
       	  if(v[0] > 1 || v[1] > 1 || v[x-1] > 1 || v[x-2] > 1)
       	  {
       	  	 cout<<x+1<<endl;
       	  }
       	  else
       	  {
       	  	cout<<x<<endl;
       	  }
       }
   }

}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef PAVANSAI006
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("err.txt", "w", stderr);
#endif
    ll t = 1;
    //cin>>t;
    while(t--)
    {
    	solve();
    }

}


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

typedef long long ll;
typedef vector<int> vi;            typedef vector<vi> vii;
typedef vector<ll> vl;             typedef vector<vl> vll;
typedef pair<int,int> pi;          typedef pair<pi,int> pii;
typedef pair<ll,ll> pl;            typedef pair<pl,ll> pll;
typedef pair<int,bool> pib;        typedef pair<ll,bool> plb;

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define in insert
#define er erase
//returns (a^n mod p)---------------------------------------------------------------------------------------------------------------
ll power(ll a,ll n,ll p)
{
	if(n == 0)
	{
		return 1;
	}
	else if(n%2 == 0)
	{
		ll ans = power(a,n/2,p);
		return (ans*ans)%p;
	}
	else
	{
		ll ans = power(a,n-1,p);
		return (ans*a)%p;
	}
}

//returns (a^-1 mod p)(if p is prime)----------------------------------------------------------------------------------------------
ll inverse(ll a,ll p)
{
   return power(a,p-2,p);
}
//----------------------------------------------------------------------------------------------------------------------------------

void solve()
{
   int n;
   cin>>n;
   string s;
   cin>>s;
   vi v;
   int curr_cnt = 0;
   for(int i=0;i<n;i++)
   {
   	  curr_cnt++;
   	  if(i == n-1 || s[i] != s[i+1])
   	  {
   	  	v.pb(curr_cnt);
   	  	curr_cnt = 0;
   	  }
   }
   int x = v.size();
   int cnt = 0;
   for(int i=0;i<x;i++)
   {
   	  if(v[i] > 2)
   	  {
         cnt = 2;
         break;
   	  }
   	  else if(v[i] > 1)
   	  {
   	  	 cnt++;
   	  	 if(cnt > 1)
   	  	 {
   	  	 	break;
   	  	 }
   	  }
   }
   if(cnt > 1)
   {
   	 cout<<x+2<<endl;
   }
   else if(cnt == 1)
   {
   	  cout<<x+1<<endl;
   }
   else
   {
   	  cout<<x<<endl;
   }

}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef PAVANSAI006
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("err.txt", "w", stderr);
#endif
    ll t = 1;
    //cin>>t;
    while(t--)
    {
    	solve();
    }

}


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

typedef long long ll;
typedef vector<int> vi;            typedef vector<vi> vii;
typedef vector<ll> vl;             typedef vector<vl> vll;
typedef pair<int,int> pi;          typedef pair<pi,int> pii;
typedef pair<ll,ll> pl;            typedef pair<pl,ll> pll;
typedef pair<int,bool> pib;        typedef pair<ll,bool> plb;

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define in insert
#define er erase
//returns (a^n mod p)---------------------------------------------------------------------------------------------------------------
ll power(ll a,ll n,ll p)
{
	if(n == 0)
	{
		return 1;
	}
	else if(n%2 == 0)
	{
		ll ans = power(a,n/2,p);
		return (ans*ans)%p;
	}
	else
	{
		ll ans = power(a,n-1,p);
		return (ans*a)%p;
	}
}

//returns (a^-1 mod p)(if p is prime)----------------------------------------------------------------------------------------------
ll inverse(ll a,ll p)
{
   return power(a,p-2,p);
}
//----------------------------------------------------------------------------------------------------------------------------------

void solve()
{
   int n;
   cin>>n;
   string s;
   cin>>s;
   vi v;
   int curr_cnt = 0;
   for(int i=0;i<n;i++)
   {
   	  curr_cnt++;
   	  if(i == n-1 || s[i] != s[i+1])
   	  {
   	  	v.pb(curr_cnt);
   	  	curr_cnt = 0;
   	  }
   }
   bool b = false;
   int x = v.size();
   for(int i=0;i<x;i++)
   {
   	  if(v[i] > 1)
   	  {
         b = true;
         break;
   	  }
   }
   if(!b)
   {
   	  cout<<x<<endl;
   }
   else
   {
   	  b = false;
   	  for(int i=0;i<x-1;i++)
   	  {
   	  	  if(v[i] > 1 && v[i+1] > 1)
   	  	  {
   	  	  	 b = true;
   	  	  	 break;
   	  	  }
   	  }
   	  if(b)
   	  {
   	  	  cout<<x+2<<endl;
   	  }
   	  else
   	  {
   	  	  cout<<x+1<<endl;
   	  }
   }

}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef PAVANSAI006
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("err.txt", "w", stderr);
#endif
    ll t = 1;
    //cin>>t;
    while(t--)
    {
    	solve();
    }

}


#include<stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <iostream>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include<cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>

using namespace std;
const int mod=1000000007;

int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long int t,n,a,b,c,q,m,k,d;
    cin>>n;
    vector<int> vec(n);
    vec[0]=1;
    string s;
    cin>>s;
    for (int i=1; i<n; i++) {
        vec[i]=s[i]==s[i-1]?vec[i-1]:vec[i-1]+1;
    }
    int ans=vec[n-1];
    for (int i=0; i<n-2; i++) {
        if (s[i]==s[i+1]&&s[i+1]==s[i+2]) {
            cout<<ans+2<<"\n";
            return 0;
        }
    }
    for (int i=0; i<n-2; i++) {
        if ((s[i]=='1'&&s[i+1]=='1'&&s[i+2]=='0'&&s[i+3]=='0')||(s[i]=='0'&&s[i+1]=='0'&&s[i+2]=='1'&&s[i+3]=='1')) {
            cout<<ans+2<<"\n";
            return 0;
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include<stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <iostream>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include<cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>

using namespace std;
const int mod=1000000007;

int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long int t,n,a,b,c,q,m,k,d;
    cin>>n;
    vector<int> vec(n);
    vec[0]=1;
    string s;
    cin>>s;
    for (int i=1; i<n; i++) {
        vec[i]=s[i]==s[i-1]?vec[i-1]:vec[i-1]+1;
    }
    int ans=vec[n-1];
    for (int i=0; i<n-2; i++) {
        if (s[i]==s[i+1]&&s[i+1]==s[i+2]) {
            cout<<ans+2<<"\n";
            return 0;
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include<stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <iostream>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include<cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>

using namespace std;
const int mod=1000000007;

int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long int t,n,a,b,c,q,m,k,d;
    cin>>n;
    vector<int> vec(n);
    vec[0]=1;
    string s;
    cin>>s;
    for (int i=0; i<n; i++) {
        vec[i]=s[i]==s[i-1]?vec[i-1]:vec[i-1]+1;
    }
    int ans=vec[n-1];
    for (int i=0; i<n-2; i++) {
        if (s[i]==s[i+1]&&s[i+1]==s[i+2]) {
            cout<<ans+2<<"\n";
            return 0;
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include<stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <iostream>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include<cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>

using namespace std;
const int mod=1000000007;

int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long int t,n,a,b,c,q,m,k,d;
    cin>>n;
    vector<int> vec(n);
    vec[0]=1;
    string s;
    cin>>s;
    for (int i=1; i<n; i++) {
        vec[i]=s[i]==s[i-1]?vec[i-1]:vec[i-1]+1;
    }
    int ans=vec[n-1];
    for (int i=0; i<n-2; i++) {
        if (s[i]==s[i+1]&&s[i+1]==s[i+2]) {
            cout<<ans+2<<"\n";
            return 0;
        }
    }
    for (int i=0; i<n-3; i++) {
        if ((s[i]=='1'&&s[i+1]=='1')||(s[i]=='0'&&s[i+1]=='0')) {
            ans++;
            for (int j=i+2; j<n-1; j++) {
                if ((s[j]=='1'&&s[j+1]=='1')||(s[j]=='0'&&s[j+1]=='0')) {
                    ans--;
                    cout<<ans+2<<"\n";
                    return 0;
                }
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include<stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <iostream>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include<cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>

using namespace std;
const int mod=1000000007;

int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long int t,n,a,b,c,q,m,k,d;
    cin>>n;
    vector<int> vec(n);
    vec[0]=1;
    string s;
    cin>>s;
    for (int i=1; i<n; i++) {
        vec[i]=s[i]==s[i-1]?vec[i-1]:vec[i-1]+1;
    }
    int ans=vec[n-1];
    for (int i=0; i<n-2; i++) {
        if (s[i]==s[i+1]&&s[i+1]==s[i+2]) {
            cout<<ans+2<<"\n";
            return 0;
        }
    }
    for (int i=0; i<n-1; i++) {
        if ((s[i]=='1'&&s[i+1]=='1')||(s[i]=='0'&&s[i+1]=='0')) {
            ans++;
            for (int j=i+2; j<n-1; j++) {
                if ((s[j]=='1'&&s[j+1]=='1')||(s[j]=='0'&&s[j+1]=='0')) {
                    ans--;
                    cout<<ans+2<<"\n";
                    return 0;
                }
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include<stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <iostream>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include<cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>

using namespace std;
const int mod=1000000007;

int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long int t,n,a,b,c,q,m,k,d;
    cin>>n;
    vector<int> vec(n);
    vec[0]=1;
    string s;
    cin>>s;
    for (int i=1; i<n; i++) {
        vec[i]=s[i]==s[i-1]?vec[i-1]:vec[i-1]+1;
    }
    int ans=vec[n-1];
    for (int i=0; i<n-2; i++) {
        if (s[i]==s[i+1]&&s[i+1]==s[i+2]) {
            cout<<ans+2<<"\n";
            return 0;
        }
    }
    for (int i=0; i<n-3; i++) {
        if ((s[i]=='1'&&s[i+1]=='1')||(s[i]=='0'&&s[i+1]=='0')) {
            for (int j=i+2; j<n-1; j++) {
                if ((s[j]=='1'&&s[j+1]=='1')||(s[j]=='0'&&s[j+1]=='0')) {
                    cout<<ans+2<<"\n";
                    return 0;
                }
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include<stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <iostream>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include<cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>

using namespace std;
const int mod=1000000007;

int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long int t,n,a,b,c,q,m,k,d;
    cin>>n;
    vector<int> vec(n);
    vec[0]=1;
    string s;
    cin>>s;
    for (int i=1; i<n; i++) {
        vec[i]=s[i]==s[i-1]?vec[i-1]:vec[i-1]+1;
    }
    int ans=vec[n-1];
    for (int i=0; i<n-2; i++) {
        if (s[i]==s[i+1]&&s[i+1]==s[i+2]) {
            cout<<ans+2<<"\n";
            return 0;
        }
    }
    for (int i=0; i<n-3; i++) {
        if ((s[i]=='1'&&s[i+1]=='1')||(s[i]=='0'&&s[i+1]=='0')) {
            for (int j=i+2; j<n-3; j++) {
                if ((s[i+2]=='1'&&s[i+3]=='1')||(s[i+2]=='0'&&s[i+3]=='0')) {
                    cout<<ans+2<<"\n";
                    return 0;
                }
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define MOD 1000000007
#define ar array
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

int32_t main() {
	fast_io;

	// int t; cin >> t;
	// while (t--) {
	// }
	int n; cin >> n;
	string s; cin >> s;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		a[i] = s[i] - '0';
	}
	vector<int> one_sizes, zero_sizes; int prev = a[0]; int curr_len = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == prev) {
			curr_len++;
		}
		else {
			if (a[i - 1] == 0) {
				zero_sizes.push_back(curr_len);
				curr_len = 1;

			}
			else {
				one_sizes.push_back(curr_len);
				curr_len = 1;
			}
		}
		prev = a[i];
	}
	if (curr_len != 0) {
		if (a[n - 1] == 1) {
			one_sizes.push_back(curr_len);
		}
		else {
			zero_sizes.push_back(curr_len);
		}
	}
	int res = one_sizes.size() + zero_sizes.size();
	bool three_ones = false, three_zeros = false;
	for (int x : one_sizes) {
		if (x >= 3) {
			three_ones = true;
			break;
		}
	}
	for (int x : zero_sizes) {
		if (x >= 3) {
			three_zeros = true;
		}
	}
	if (three_zeros || three_ones) {
		res += 2;
	}
	else {
		bool two_ones = false, two_zeros = false;
		for (int x : one_sizes) {
			if (x >= 2) {
				two_ones  = true;
				break;
			}
		}
		for (int x : zero_sizes) {
			if (x >= 2) {
				two_zeros = true;
				break;
			}
		}
		if (two_ones && two_zeros) {
			res += 2;
		}
	}
	cout << res << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define MOD 1000000007
#define ar array
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

int32_t main() {
	fast_io;

	// int t; cin >> t;
	// while (t--) {
	// }
	int n; cin >> n;
	string s; cin >> s;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		a[i] = s[i] - '0';
	}
	int init_LIS = 1;
	for (int i = 1; i < n; i++) {
		init_LIS += (a[i] != a[i - 1]);
	}
	cout << min(n, init_LIS + 2) << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define MOD 1000000007
#define ar array
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

int32_t main() {
	fast_io;

	// int t; cin >> t;
	// while (t--) {
	// }
	int n; cin >> n;
	string s; cin >> s;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		a[i] = s[i] - '0';
	}
	vector<int> one_sizes, zero_sizes; int prev = a[0]; int curr_len = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == prev) {
			curr_len++;
		}
		else {
			if (a[i - 1] == 0) {
				zero_sizes.push_back(curr_len);
				curr_len = 1;

			}
			else {
				one_sizes.push_back(curr_len);
				curr_len = 1;
			}
		}
		prev = a[i];
	}
	if (curr_len != 0) {
		if (a[n - 1] == 1) {
			one_sizes.push_back(curr_len);
		}
		else {
			zero_sizes.push_back(curr_len);
		}
	}
	int res = one_sizes.size() + zero_sizes.size();
	int three_ones = 0, three_zeros = 0;
	for (int x : one_sizes) {
		if (x >= 3) {
			three_ones++;
		}
	}
	for (int x : zero_sizes) {
		if (x >= 3) {
			three_zeros++;
		}
	}
	if (three_zeros || three_ones) {
		res += 2;
	}
	else {
		int two_ones = 0, two_zeros = 0;
		for (int x : one_sizes) {
			if (x >= 2) {
				two_ones++;
			}
		}
		for (int x : zero_sizes) {
			if (x >= 2) {
				two_zeros++;
			}
		}
		if ((two_ones && two_zeros) || (two_ones >= 2) || (two_zeros >= 2)) {
			res += 2;
		}
	}
	cout << res << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define MOD 1000000007
#define ar array
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

int32_t main() {
	fast_io;

	// int t; cin >> t;
	// while (t--) {
	// }
	int n; cin >> n;
	string s; cin >> s;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		a[i] = s[i] - '0';
	}
	vector<int> one_sizes, zero_sizes; int prev = a[0]; int curr_len = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == prev) {
			curr_len++;
		}
		else {
			if (a[i - 1] == 0) {
				zero_sizes.push_back(curr_len);
				curr_len = 1;

			}
			else {
				one_sizes.push_back(curr_len);
				curr_len = 1;
			}
		}
		prev = a[i];
	}
	if (curr_len != 0) {
		if (a[n - 1] == 1) {
			one_sizes.push_back(curr_len);
		}
		else {
			zero_sizes.push_back(curr_len);
		}
	}
	int res = one_sizes.size() + zero_sizes.size();
	int two_ones = 0, two_zeros = 0;
	for (int x : one_sizes) {
		if (x >= 2) {
			two_ones++;
		}
	}
	for (int x : zero_sizes) {
		if (x >= 2) {
			two_zeros++;
		}
	}
	res += min(2ll, two_zeros + two_ones);
	cout << res << endl;

	return 0;
}


 /*
 *
 * author: Hamkor
 *
 **/

#include <bits/stdc++.h>

using namespace std;

int main(){
    int n, m = 0; cin>>n;
    string s; cin>>s;
    vector<int> a(n, 0);
    char x, y; int ax, ay; bool c = 1, in = 0;
    for (int i=0; i<n; ++i){
        a[i] = 1;
        if (c){
            while (c){
                while(i<n){
                    if (s[i] == '1'){x = '1'; y = '0';}
                    else {x  = '0'; y = '1';}
                    ax = 1; ay = 1;
                    for (int j = 0; j<i; ++j){
                        if (s[j] != x) ax = max(a[j] + 1, ax);
                        else ay = max(a[j] + 1, ay);
                    }
                    if (ay>ax){
                        s[i] = y; a[i] = ay; in = 1;
                    }else{
                        s[i] = x; a[i] = ax;

                        if (in){c = 0;break;}
                    }
                    m = max(m, a[i]);
                    ++i;
                }
                if (i>=n) break;
            }
        }else{
            for (int j=0; j<i; ++j){
                if (s[j] != s[i]) a[i] = max(a[j] + 1, a[i]);
            }
             m = max(m, a[i]);
        }
    }
    cout<<m;
    return 0;
}


 /*
 *
 * author: Hamkor
 *
 **/

#include <bits/stdc++.h>

using namespace std;

int main(){
    int n; cin>>n;
    string s; cin>>s;
    vector<int> a(n, 0);
    char x, y; int ax, ay; bool c = 1, in = 0;
    for (int i=0; i<n; ++i){
        a[i] = 1;
        if (c){
            while (c){
                while(i<n){
                    if (s[i] == '1'){x = '1'; y = '0';}
                    else {x  = '0'; y = '1';}
                    ax = 1; ay = 1;
                    for (int j = 0; j<i; ++j){
                        if (s[j] != x) ax = max(a[j] + 1, ax);
                        else ay = max(a[j] + 1, ay);
                    }
                    if (ay>ax){
                        s[i] = y; a[i] = ay; in = 1;
                    }else{
                        s[i] = x; a[i] = ax;

                        if (in){c = 0;break;}
                    }
                    ++i;
                }

                if (i>=n) break;
            }
        }else{
            for (int j=0; j<i; ++j){
                if (s[j] != s[i]) a[i] = max(a[j] + 1, a[i]);
            }
        }

    }

    int m = 0;
    for (auto i: a) m = max(m, i);
    cout<<m;
    return 0;
}


 /*
 *
 * author: Hamkor
 *
 **/

#include <bits/stdc++.h>

using namespace std;

int main(){
    int n, m = 0; cin>>n;
    string s; cin>>s;
    vector<int> a(n, 0);
    a[0] = 1;
    char x, y; int ax, ay; bool c = 1, in = 0;
    for (int i=1; i<n; ++i){
        a[i] = 1;
        if (c){
            while (c){
                while(i<n){
                    if (s[i] == '1'){x = '1'; y = '0';}
                    else {x  = '0'; y = '1';}
                    ax = 1; ay = 1;
                    if (s[i-1] != x) ax = max(ax, a[i-1] + 1);
                    else if (s[i-1] != y) ay = max(ay, a[i-1] + 1);
                    else{
                       for (int j = 0; j<i; ++j){
                            if (s[j] != x) ax = max(a[j] + 1, ax);
                            else ay = max(a[j] + 1, ay);
                        }
                    }
                    if (ay>ax){
                        s[i] = y; a[i] = ay; in = 1;
                    }else{
                        s[i] = x; a[i] = ax;

                        if (in){c = 0;break;}
                    }
                    m = max(m, a[i]);
                    ++i;
                }
                if (i>=n) break;
            }
        }else{
            if (s[i] != s[i-1]) a[i] = max(a[i], a[i-1]+1);
            else{
                for (int j=0; j<i; ++j){
                if (s[j] != s[i]) a[i] = max(a[j] + 1, a[i]);
            }
            }
             m = max(m, a[i]);
        }
    }
    cout<<m;
    return 0;
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <iostream>
//#include <unordered_set>
#include <unordered_map>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define int ll
typedef long long ll;
typedef long double ld;
//#pragma comment(linker, "/STACK:66777216")
using namespace std;

const ll INF = 1e18, MOD = 998244353, MAXN = 1048576, MAXM = 100;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

signed main() {
    //ifstream  cin("counting.in");
    //ofstream cout("counting.out");
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    string s;
    cin >> s;
    int cur = 1, cnt = 1, ok = 0;
    for (int i = 1; i < n; i++) {
        if (s[i] == s[i - 1]) cur++;
        else {
            cnt++;
            if (cur > 1) ok = 1;
            cur = 1;
        }
    }
    if (cur > 1) ok = 1;
    cout << min(n, cnt + ok * 2);
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <iostream>
//#include <unordered_set>
#include <unordered_map>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define int ll
typedef long long ll;
typedef long double ld;
//#pragma comment(linker, "/STACK:66777216")
using namespace std;

const ll INF = 1e18, MOD = 998244353, MAXN = 1048576, MAXM = 100;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

signed main() {
    //ifstream  cin("counting.in");
    //ofstream cout("counting.out");
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    string s;
    cin >> s;
    int cur = 1, cnt = 1, ok = 0;
    for (int i = 1; i < n; i++) {
        if (s[i] == s[i - 1]) cur++;
        else {
            cnt++;
            if (cur > 1) ok++;
            cur = 1;
        }
    }
    if (cur > 1) ok++;
    cout << min(n, cnt + min(2ll, ok));
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <iostream>
//#include <unordered_set>
#include <unordered_map>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define int ll
typedef long long ll;
typedef long double ld;
//#pragma comment(linker, "/STACK:66777216")
using namespace std;

const ll INF = 1e18, MOD = 998244353, MAXN = 1048576, MAXM = 100;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

signed main() {
    //ifstream  cin("counting.in");
    //ofstream cout("counting.out");
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    string s;
    cin >> s;
    int cur = 1, cnt = 1, ok = 0;
    for (int i = 1; i < n; i++) {
        if (s[i] == s[i - 1]) cur++;
        else {
            cnt++;
            if (cur > 1) ok++;
            cur = 1;
        }
    }
    if (cur > 1) ok++;
    cout << cnt + min(2ll, ok);
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <iostream>
//#include <unordered_set>
#include <unordered_map>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define int ll
typedef long long ll;
typedef long double ld;
//#pragma comment(linker, "/STACK:66777216")
using namespace std;

const ll INF = 1e18, MOD = 998244353, MAXN = 1048576, MAXM = 100;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

signed main() {
    //ifstream  cin("counting.in");
    //ofstream cout("counting.out");
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    string s;
    cin >> s;
    int cur = 1, cnt = 1, ok = 0;
    for (int i = 1; i < n; i++) {
        if (s[i] == s[i - 1]) cur++;
        else {
            cnt++;
            if (cur > 1) ok++;
            cur = 1;
        }
    }
    if (cur > 1) ok++;
    cout << cnt + ok * min(2ll, ok);
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <iostream>
//#include <unordered_set>
#include <unordered_map>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define int ll
typedef long long ll;
typedef long double ld;
//#pragma comment(linker, "/STACK:66777216")
using namespace std;

const ll INF = 1e18, MOD = 998244353, MAXN = 1048576, MAXM = 100;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

signed main() {
    //ifstream  cin("counting.in");
    //ofstream cout("counting.out");
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    string s;
    cin >> s;
    int cur = 1, cnt = 1, ok = 0;
    for (int i = 1; i < n; i++) {
        if (s[i] == s[i - 1]) cur++;
        else {
            cnt++;
            if (cur > 2) ok = 1;
            cur = 1;
        }
    }
    if (cur > 2) ok = 1;
    cout << cnt + ok * 2;
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <iostream>
//#include <unordered_set>
#include <unordered_map>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define int ll
typedef long long ll;
typedef long double ld;
//#pragma comment(linker, "/STACK:66777216")
using namespace std;

const ll INF = 1e18, MOD = 998244353, MAXN = 1048576, MAXM = 100;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

signed main() {
    //ifstream  cin("counting.in");
    //ofstream cout("counting.out");
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    string s;
    cin >> s;
    int cur = 1, cnt = 1, ok = 0;
    for (int i = 1; i < n; i++) {
        if (s[i] == s[i - 1]) cur++;
        else {
            cnt++;
            if (cur > 1) ok = 1;
            cur = 1;
        }
    }
    if (cur > 1) ok = 1;
    cout << cnt + ok * 2;
}