/* -*- coding: utf-8 -*- * * 1924.cc: No.1924 3 color painting on a line - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 100000; const char ps[] = "RGB"; const int INF = 1 << 30; /* typedef */ /* global variables */ char s[MAX_N + 4]; /* subroutines */ int check(int l, int r) { int c = 0; for (int i = l; i < r;) { int j = i; while (i < r && s[j] == s[i]) i++; c++; } return c / 2 + 1; } /* main */ int main() { int n; scanf("%d%s", &n, s); int mind = INF; for (int ci = 0; ci < 3; ci++) { char p0 = ps[ci]; int d = 1; for (int i = 0; i < n;) { while (i < n && s[i] == p0) i++; if (i >= n) break; int j = i; while (i < n && s[i] != p0) i++; d += check(j, i); } mind = min(mind, d); } printf("%d\n", mind); return 0; }