description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given an array A with size N (indexed from 0) and an integer K. Let's define another array B with size N Β· K as the array that's formed by concatenating K copies of array A. For example, if A = {1, 2} and K = 3, then B = {1, 2, 1, 2, 1, 2}. You have to find the maximum subarray sum of the array B. Fomally, you should compute the maximum value of Bi + Bi+1 + Bi+2 + ... + Bj, where 0 ≀ i ≀ j < N Β· K. -----Input----- - The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains two space-separated integers N and K. - The second line contains N space-separated integers A0, A1, ..., AN-1. -----Output----- For each test case, print a single line containing the maximum subarray sum of B. -----Constraints----- - 1 ≀ T ≀ 10 - 1 ≀ N ≀ 105 - 1 ≀ K ≀ 105 - -106 ≀ Ai ≀ 106 for each valid i -----Subtasks----- Subtask #1 (18 points): N Β· K ≀ 105 Subtask #2 (82 points): original constraints -----Example----- Input: 2 2 3 1 2 3 2 1 -2 1 Output: 9 2 -----Explanation----- Example case 1: B = {1, 2, 1, 2, 1, 2} and the subarray with maximum sum is the whole {1, 2, 1, 2, 1, 2}. Hence, the answer is 9. Example case 2: B = {1, -2, 1, 1, -2, 1} and the subarray with maximum sum is {1, 1}. Hence, the answer is 2.
def kConcatination(B): maxSum = -10000000000.0 tempSum = 0 for i in range(len(B)): tempSum = max(tempSum + B[i], B[i]) maxSum = max(maxSum, tempSum) return maxSum for _ in range(int(input())): n, k = map(int, input().split()) A = list(map(int, input().split())) if k == 1: print(kConcatination(A)) else: tSum = sum(A) maxSum = kConcatination(2 * A) if tSum > 0: maxSum += tSum * (k - 2) print(maxSum)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array A with size N (indexed from 0) and an integer K. Let's define another array B with size N Β· K as the array that's formed by concatenating K copies of array A. For example, if A = {1, 2} and K = 3, then B = {1, 2, 1, 2, 1, 2}. You have to find the maximum subarray sum of the array B. Fomally, you should compute the maximum value of Bi + Bi+1 + Bi+2 + ... + Bj, where 0 ≀ i ≀ j < N Β· K. -----Input----- - The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains two space-separated integers N and K. - The second line contains N space-separated integers A0, A1, ..., AN-1. -----Output----- For each test case, print a single line containing the maximum subarray sum of B. -----Constraints----- - 1 ≀ T ≀ 10 - 1 ≀ N ≀ 105 - 1 ≀ K ≀ 105 - -106 ≀ Ai ≀ 106 for each valid i -----Subtasks----- Subtask #1 (18 points): N Β· K ≀ 105 Subtask #2 (82 points): original constraints -----Example----- Input: 2 2 3 1 2 3 2 1 -2 1 Output: 9 2 -----Explanation----- Example case 1: B = {1, 2, 1, 2, 1, 2} and the subarray with maximum sum is the whole {1, 2, 1, 2, 1, 2}. Hence, the answer is 9. Example case 2: B = {1, -2, 1, 1, -2, 1} and the subarray with maximum sum is {1, 1}. Hence, the answer is 2.
def kadane(arr: list) -> int: current_sum = 0 max_sum = arr[0] for num in arr: current_sum += num max_sum = max(max_sum, current_sum) if current_sum < 0: current_sum = 0 return max_sum def max_subarr_sum(arr: list, n: int, k: int) -> int: kadane_sum = kadane(arr) if k == 1: return kadane_sum current_prefix_sum = 0 current_suffix_sum = 0 max_prefix_sum = arr[0] for num in arr: current_prefix_sum += num max_prefix_sum = max(max_prefix_sum, current_prefix_sum) max_suffix_sum = arr[-1] total_sum = current_prefix_sum for num in arr[::-1]: current_suffix_sum += num max_suffix_sum = max(max_suffix_sum, current_suffix_sum) if total_sum < 0: return max(max_suffix_sum + max_prefix_sum, kadane_sum) else: return max(max_suffix_sum + max_prefix_sum + total_sum * (k - 2), kadane_sum) t = int(input()) for x in range(t): n_k = list(map(int, input().split())) n = n_k[0] k = n_k[1] arr = list(map(int, input().split())) print(max_subarr_sum(arr, n, k))
FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER RETURN VAR VAR FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FOR VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n, string = int(input()), list(input()) cnt = 0 for loc in range(1, n): prev, curr, nex = string[loc - 1], string[loc], string[min(loc + 1, n - 1)] if prev != curr: continue posible = set("RGB") - {prev, nex} cnt += 1 curr = list(posible)[0] string[loc] = curr print(cnt) print("".join(string))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR STRING VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
import sys def answer(n, s): num_changes = 0 choices = {"R", "G", "B"} ans = [s[0]] for i in range(1, n): if s[i] != ans[-1]: ans.append(s[i]) else: temp = {"R", "G", "B"} temp.discard(s[i]) if i < n - 1: temp.discard(s[i + 1]) ans.append(temp.pop()) num_changes += 1 print(num_changes) print("".join(ans)) return def main(): n = int(sys.stdin.readline()) s = sys.stdin.readline().rstrip() answer(n, s) return main()
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR STRING STRING STRING ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING STRING STRING EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR RETURN EXPR FUNC_CALL VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = list(input()) if n == 1: print(0) print(s[0]) exit() count = 0 for i in range(len(s) - 2): if s[i] == s[i + 1]: count += 1 if s[i] == "R": if s[i + 2] == "G": s[i + 1] = "B" elif s[i + 2] == "B": s[i + 1] = "G" else: s[i + 1] = "B" elif s[i] == "B": if s[i + 2] == "G": s[i + 1] = "R" elif s[i + 2] == "R": s[i + 1] = "G" else: s[i + 1] = "R" elif s[i] == "G": if s[i + 2] == "R": s[i + 1] = "B" elif s[i + 2] == "B": s[i + 1] = "R" else: s[i + 1] = "R" if s[n - 2] == s[n - 1]: count += 1 if s[n - 2] == "R": if s[n - 3] == "B": s[n - 1] = "G" else: s[n - 1] = "B" if s[n - 2] == "B": if s[n - 3] == "R": s[n - 1] = "G" else: s[n - 1] = "R" if s[n - 2] == "G": if s[n - 3] == "B": s[n - 1] = "R" else: s[n - 1] = "B" print(count) for i in range(len(s)): print(s[i], end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
q = int(input()) s = str(input()) tot = 0 s = list(s) for i in range(1, len(s)): if s[i] == s[i - 1]: m = "RGB" m = m.replace(s[i - 1], "") if i + 1 != len(s): m = m.replace(s[i + 1], "") s[i] = m[0] tot += 1 print(tot) print("".join(s))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
mod = 1000000007 ii = lambda: int(input()) si = lambda: input() dgl = lambda: list(map(int, input())) f = lambda: map(int, input().split()) il = lambda: list(map(int, input().split())) ls = lambda: list(input()) n = ii() l = ls() ch = ["R", "G", "B"] c = 0 for i in range(1, n - 1): if l[i] == l[i - 1]: c += 1 for j in ch: if j != l[i - 1] and j != l[i + 1]: l[i] = j if n >= 2 and l[-1] == l[-2]: c += 1 for j in ch: if j != l[-2]: l[-1] = j print(c) print("".join(l))
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
def change(color1, color2): r = "R" g = "G" b = "B" if color1 == color2: if color1 == r: return g else: return r elif color1 == r: if color2 == g: return b else: return g elif color1 == g: if color2 == r: return b else: return r elif color2 == r: return g else: return r n = int(input()) ans = 0 colors = input() x = list(colors) x.append("R") for j in range(len(x) - 2): if x[j + 1] == x[j]: ans = ans + 1 x[j + 1] = change(x[j], x[j + 2]) del x[-1] x1 = "".join(x) print(ans) print(x1)
FUNC_DEF ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING IF VAR VAR IF VAR VAR RETURN VAR RETURN VAR IF VAR VAR IF VAR VAR RETURN VAR RETURN VAR IF VAR VAR IF VAR VAR RETURN VAR RETURN VAR IF VAR VAR RETURN VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) a = list(input()) k = 0 if len(a) == 1: print(0) print("".join(a)) exit() for i in range(1, n - 1): if a[i] == a[i - 1]: if a[i + 1] == a[i]: if a[i] == "B": a[i] = "G" elif a[i] == "R": a[i] = "G" else: a[i] = "R" k += 1 else: if a[i - 1] == "G": if a[i + 1] == "R": a[i] = "B" else: a[i] = "R" elif a[i - 1] == "R": if a[i + 1] == "G": a[i] = "B" else: a[i] = "G" elif a[i - 1] == "B": if a[i + 1] == "R": a[i] = "G" else: a[i] = "R" k += 1 if a[-1] == a[-2]: k += 1 if a[-2] == "G": a[-1] = "R" elif a[-2] == "R": a[-1] = "G" else: a[-1] = "R" print(k) print("".join(a))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) f = ["R", "G", "B"] s = list(input()) i = 1 x = 0 while i < len(s) - 1: if s[i] == s[i - 1]: h = f[:] h.remove(s[i - 1]) if s[i + 1] in h: h.remove(s[i + 1]) s[i] = h[0] i += 1 x += 1 i += 1 if n > 1 and s[-1] == s[-2]: h = f[:] h.remove(s[-1]) s[i] = h[0] x += 1 print(x) d = "" for i in s: d += i print(d)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = input() s = list(s) r = [] + s c = ["R", "G", "B"] i = 0 while i < n - 1: if i == n - 2 and s[i] == s[i + 1]: x = [a for a in c if a != s[i + 1]] s[i + 1] = x[0] elif s[i] == s[i + 1]: x = [a for a in c if a != s[i + 1] and a != s[i + 2]] s[i + 1] = x[0] i += 1 ans = 0 for i in range(n): if r[i] != s[i]: ans += 1 print(ans) print("".join(s))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
input() s = input() colors = set(["R", "G", "B"]) r = 0 ss = s[0] for i, c in enumerate(s[1:-1], 1): if c == ss[-1]: r += 1 ss += (colors - set([ss[-1], s[i + 1]])).pop() else: ss += c if len(s) > 1: if s[-1] == ss[-1]: r += 1 ss += (colors - set([ss[-1]])).pop() else: ss += s[-1] print(r) print(ss)
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL BIN_OP VAR FUNC_CALL VAR LIST VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR FUNC_CALL BIN_OP VAR FUNC_CALL VAR LIST VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) l = list(input()) ans = 0 if n == 2: use = ["R", "G", "B"] if l[0] == l[1]: use.remove(l[0]) l[1] = use[0] ans += 1 print(ans) print("".join(l)) exit() for i in range(1, n - 1): use = ["R", "G", "B"] if l[i] == l[i - 1]: if l[i - 1] == l[i + 1]: use.remove(l[i]) l[i] = use[0] else: use.remove(l[i - 1]) use.remove(l[i + 1]) l[i] = use[0] ans += 1 use = ["R", "G", "B"] if n > 1 and l[-1] == l[-2]: use.remove(l[-2]) ans += 1 l[-1] = use[0] print(ans) print("".join(l))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR LIST STRING STRING STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST STRING STRING STRING IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST STRING STRING STRING IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = input() s = [s[i] for i in range(n)] ans = 0 for i in range(1, n): if s[i] == s[i - 1]: ans += 1 temp = ["R", "G", "B"] temp.remove(s[i - 1]) if i + 1 < n and s[i + 1] in temp: temp.remove(s[i + 1]) s[i] = temp[0] print(ans) print("".join(str(x) for x in s))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST STRING STRING STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
import sys def c(lo, mid, hi): col = ["R", "B", "G"] for c in col: mid = c if lo != mid and mid != hi: return mid def recolor(colors, n): change = 0 for i in range(1, n): if colors[i - 1] == colors[i]: change += 1 for ch in "RBG": if ch != colors[i - 1] and ch != colors[i + 1]: colors[i] = ch print(change) print("".join(colors[0:-1])) def main(): n = int(sys.stdin.readline()) arr = list(sys.stdin.readline() + ".") recolor(arr, n) main()
IMPORT FUNC_DEF ASSIGN VAR LIST STRING STRING STRING FOR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER FOR VAR STRING IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) m = list(input()) i = 0 k = 0 q = ["R", "G", "B"] if n == 1: print(0) print(*m) exit() if n == 2: if m[1] == m[0]: print(1) if q.index(m[0]) == 1: print(m[0] + q[2]) else: print(m[0] + q[1]) else: print(0) print(*m, sep="") exit() while i < n - 2: if m[i] == m[i + 1] and m[i] == m[i + 2]: if q.index(m[i + 2]) == 1: m[i + 1] = q[0] else: m[i + 1] = q[1] k += 1 i += 1 elif m[i] == m[i + 1]: if q.index(m[i - 1]) + q.index(m[i + 1]) == 2: m[i] = q[1] elif q.index(m[i - 1]) + q.index(m[i + 1]) == 1: m[i] = q[2] else: m[i] = q[0] k += 1 i += 1 if m[-2] == m[-1]: if q.index(m[-3]) + q.index(m[-1]) == 2: if m[-3] == m[-2]: m[-2] = q[2] else: m[-2] = q[1] elif q.index(m[-3]) + q.index(m[-1]) == 1: m[-2] = q[2] elif q.index(m[-3]) + q.index(m[-1]) == 3: m[-2] = q[0] else: m[-2] = q[1] k += 1 print(k) print(*m, sep="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
def diverse_garland(n, strng): strng = list(strng) count = 0 for i in range(n - 1): if strng[i] != strng[i + 1]: continue else: l = ["R", "G", "B"] count += 1 if i == n - 2: l.remove(strng[i]) else: l.remove(strng[i]) if strng[i + 2] in l: l.remove(strng[i + 2]) strng[i + 1] = l[0] strng = "".join(strng) print(count) print(strng) n = int(input()) strng = input() diverse_garland(n, strng)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST STRING STRING STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = input() a = [] cl = ["R", "B", "G"] ans, ck = 0, False for i in range(1, len(s)): if s[i] == s[i - 1] and not ck: ans += 1 ck = True for j in cl: if i == len(s) - 1: if j != s[i - 1]: a.append(j) break if j != s[i - 1] and (i < len(s) - 1 and j != s[i + 1]): a.append(j) break else: a.append(s[i]) ck = False if len(s) <= 2: if len(s) == 1: print(0, s, sep="\n") elif s[0] != s[1]: print(0, s, sep="\n") else: for i in cl: if i != s[0]: print(1) print(s[0], i, sep="") exit() else: print(ans) print(s[0], *a, sep="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR STRING FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR STRING
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = [*input()] + [0] m = 0 for i in range(1, n): if s[i] == s[i - 1]: m += 1 s[i] = next(c for c in "RGB" if s[i - 1] != c != s[i + 1]) print(m, "".join(s[:-1]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR STRING VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL STRING VAR NUMBER
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) a = list(input()) i = 0 l = 0 while i < n - 1: if a[i] != a[i + 1]: i += 1 else: j = i p = 0 while j < n: if a[j] == a[i]: p = p + 1 j += 1 else: break if j == n: if a[i] == "R": k = i t = 0 while k < j: if t % 2 == 1: l += 1 a[k] = "G" t += 1 k += 1 if a[i] == "G": k = i t = 0 while k < j: if t % 2 == 1: l += 1 a[k] = "B" t += 1 k += 1 if a[i] == "B": k = i t = 0 while k < j: if t % 2 == 1: l += 1 a[k] = "G" t += 1 k += 1 i = j elif p % 2 == 1: if a[i] == "R": k = i t = 0 while k < j: if t % 2 == 1: l += 1 a[k] = "G" t += 1 k += 1 if a[i] == "G": k = i t = 0 while k < j: if t % 2 == 1: l += 1 a[k] = "B" t += 1 k += 1 if a[i] == "B": k = i t = 0 while k < j: if t % 2 == 1: l += 1 a[k] = "G" t += 1 k += 1 i = j else: if a[i] == "R": if a[j] == "B": z = "G" if a[j] == "G": z = "B" if a[i] == "G": if a[j] == "B": z = "R" if a[j] == "R": z = "B" if a[i] == "B": if a[j] == "R": z = "G" if a[j] == "G": z = "R" if a[i] == "R": k = i t = 0 while k < j: if t % 2 == 1: l += 1 a[k] = z t += 1 k += 1 if a[i] == "G": k = i t = 0 while k < j: if t % 2 == 1: l += 1 a[k] = z t += 1 k += 1 if a[i] == "B": k = i t = 0 while k < j: if t % 2 == 1: l += 1 a[k] = z t += 1 k += 1 i = j print(l) print("".join(a))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR STRING IF VAR VAR STRING ASSIGN VAR STRING IF VAR VAR STRING ASSIGN VAR STRING IF VAR VAR STRING IF VAR VAR STRING ASSIGN VAR STRING IF VAR VAR STRING ASSIGN VAR STRING IF VAR VAR STRING IF VAR VAR STRING ASSIGN VAR STRING IF VAR VAR STRING ASSIGN VAR STRING IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = input() f = [] y = len(s) f.append(s[0]) k = 0 a = ["R", "B", "G"] for i in range(1, y): if f[i - 1] != s[i]: f.append(s[i]) continue else: a.remove(f[i - 1]) k = k + 1 if i < n - 1 and a[0] == s[i + 1]: f.append(a[1]) else: f.append(a[0]) a.append(f[i - 1]) print(k) print("".join(f))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
for t in range(1): n = int(input()) string = list(input()) cost = 0 for i in range(1, n): color = ["R", "G", "B"] prev = string[i - 1] curr = string[i] if curr == prev: color.remove(prev) if i < n - 1: next = string[i + 1] if curr != next: color.remove(next) string[i] = color[0] cost += 1 print(cost) print(*string, sep="")
FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
X = {"R", "G", "B"} def comp(a, b): x = {a, b} t = list(X ^ x) return t[0] N = int(input()) S = [i for i in input()] if N == 1: print(0) print("".join(S)) exit() count = 0 for i in range(N - 2): if S[i] == S[i + 1]: S[i + 1] = comp(S[i], S[i + 2]) count += 1 if S[-1] == S[-2]: count += 1 S[-1] = comp(S[-2], S[-2]) print(count) print("".join(S))
ASSIGN VAR STRING STRING STRING FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = input() l = list(s) cnt = 0 def check(a, b): s = "BGR" for i in s: if i != a and i != b: return i def chk(a): s = "BGR" for i in s: if i != a: return i for i in range(1, n): if l[i] == l[i - 1]: cnt += 1 if i != n - 1: l[i] = check(l[i - 1], l[i + 1]) else: l[i] = chk(l[i - 1]) print(cnt) print(*l, sep="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR STRING FOR VAR VAR IF VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR STRING FOR VAR VAR IF VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) l = list(input()) i = 1 c = 0 while i < n - 1: if l[i] == l[i - 1]: c += 1 if l[i] == "R": if l[i + 1] == "G": l[i] = "B" else: l[i] = "G" elif l[i] == "G": if l[i + 1] == "R": l[i] = "B" else: l[i] = "R" elif l[i] == "B": if l[i + 1] == "R": l[i] = "G" else: l[i] = "R" i += 1 if n != 1: if l[n - 1] == l[n - 2]: c += 1 if l[n - 1] == "R": l[n - 1] = "G" else: l[n - 1] = "R" print(c) print("".join(l))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
r = "RGB" n = int(input()) l = [r.index(c) for c in input()] + [3] m = 0 for i in range(1, n): if l[i] == l[i - 1]: m += 1 l[i] = (l[i] + 1) % 3 if l[i] == l[i + 1]: l[i] = (l[i] + 1) % 3 print(m, "".join(r[i] for i in l[:-1]))
ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL STRING VAR VAR VAR VAR NUMBER
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) lis = list(input()) lis_R = [0 if lis[0] == "R" else 1] lis_G = [0 if lis[0] == "G" else 1] lis_B = [0 if lis[0] == "B" else 1] from_R = [-1] from_G = [-1] from_B = [-1] for i in range(1, n): t1 = lis_G[i - 1] + (0 if lis[i] == "R" else 1) t2 = lis_B[i - 1] + (0 if lis[i] == "R" else 1) if t1 < t2: lis_R.append(t1) from_R.append(2) else: lis_R.append(t2) from_R.append(3) t1 = lis_R[i - 1] + (0 if lis[i] == "G" else 1) t2 = lis_B[i - 1] + (0 if lis[i] == "G" else 1) if t1 < t2: lis_G.append(t1) from_G.append(1) else: lis_G.append(t2) from_G.append(3) t1 = lis_G[i - 1] + (0 if lis[i] == "B" else 1) t2 = lis_R[i - 1] + (0 if lis[i] == "B" else 1) if t1 < t2: lis_B.append(t1) from_B.append(2) else: lis_B.append(t2) from_B.append(1) print(min(lis_R[n - 1], lis_G[n - 1], lis_B[n - 1])) map = {(1): from_R, (2): from_G, (3): from_B} if lis_R[n - 1] <= lis_G[n - 1] and lis_R[n - 1] <= lis_B[n - 1]: current = 1 elif lis_G[n - 1] <= lis_R[n - 1] and lis_G[n - 1] <= lis_B[n - 1]: current = 2 else: current = 3 current_lis = map[current] k = n - 1 res = [current] while k > 0: current = current_lis[k] res.append(current) current_lis = map[current] k -= 1 res = reversed(res) for i in res: if i == 1: print("R", end="") elif i == 2: print("G", end="") else: print("B", end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER STRING NUMBER NUMBER ASSIGN VAR LIST VAR NUMBER STRING NUMBER NUMBER ASSIGN VAR LIST VAR NUMBER STRING NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR STRING NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR STRING NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR STRING NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR STRING NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR STRING NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR STRING NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = list(input()) k = 0 if n > 1: for i in range(n - 2): if s[i] == s[i + 1]: if s[i + 2] == "R": if s[i] != "G": s[i + 1] = "G" elif s[i] != "B": s[i + 1] = "B" elif s[i + 2] == "G": if s[i] != "B": s[i + 1] = "B" elif s[i] != "R": s[i + 1] = "R" elif s[i] != "R": s[i + 1] = "R" elif s[i] != "G": s[i + 1] = "G" k += 1 if s[len(s) - 2] == s[len(s) - 1]: if s[len(s) - 2] == "R": s[len(s) - 1] = "G" elif s[len(s) - 2] == "G": s[len(s) - 1] = "B" else: s[len(s) - 1] = "R" k += 1 print(k) for i in s: print(i, end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
def get_color(left, right): if right is None: if left == "R": return "G" elif left == "G" or left == "B": return "R" elif left == "G" and right == "G": return "R" elif left == "R" and right == "G" or left == "G" and right == "R": return "B" elif left == "G" and right == "B" or left == "B" and right == "G": return "R" else: return "G" n = int(input()) s = list(input()) i, r = 0, 0 while i < len(s) - 1: if s[i] == s[i + 1]: r += 1 s[i + 1] = get_color(s[i], s[i + 2] if i < len(s) - 2 else None) i += 2 else: i += 1 print(r) print("".join(s))
FUNC_DEF IF VAR NONE IF VAR STRING RETURN STRING IF VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING VAR STRING VAR STRING RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER NONE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) a = list(input()) s = {"R", "G", "B"} i = 0 cnt = 0 while i < n - 1: if a[i] == a[i + 1]: s1 = set() s1.add(a[i]) if i + 2 < n: s1.add(a[i + 2]) s1 = s - s1 a[i + 1] = s1.pop() i = i + 1 cnt = cnt + 1 if i == n - 2: break i = i + 1 print(cnt) print("".join(str(i) for i in a))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = list(input()) ans = 0 key = s[:] letters = ["R", "G", "B"] if len(s) == 1: print("0\n" + "".join(s)) exit() if len(s) == 2: if s[0] == s[1]: print(1) if s[0] == "G": s[0] = "R" elif s[0] == "B": s[0] = "R" else: s[0] = "B" print("".join(s)) exit() else: print(0) print("".join(s)) s.append("0") for i in range(1, len(s)): if s[i] == s[i - 1]: if s[i] == "R": if s[i + 1] == "B": s[i] = "G" ans += 1 elif s[i + 1] == "G": s[i] = "B" ans += 1 else: s[i] = "G" ans += 1 elif s[i] == "B": if s[i + 1] == "B": s[i] = "G" elif s[i + 1] == "R": s[i] = "G" else: s[i] = "R" ans += 1 elif s[i] == "G": if s[i + 1] == "G": s[i] = "R" elif s[i + 1] == "B": s[i] = "R" else: s[i] = "B" ans += 1 print(ans) print("".join(s[:-1]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST STRING STRING STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL STRING VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) si = input() s = [] for i in si: s.append(i) dic = {(0): "R", (1): "G", (2): "B"} dic2 = {"R": 0, "G": 1, "B": 2} c = 0 for i in range(1, len(s)): if i == len(s) - 1: if s[i] == s[i - 1]: s[i] = dic[(dic2[s[i]] + 1) % 3] c += 1 elif s[i] == s[i - 1]: if s[i + 1] == s[i - 1]: s[i] = dic[(dic2[s[i]] + 1) % 3] c += 1 else: temp = [False] * 3 temp[dic2[s[i - 1]]] = True temp[dic2[s[i + 1]]] = True for j in range(3): if not temp[j]: s[i] = dic[j] c += 1 print(c) for i in s: print(i, end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER STRING STRING STRING ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = input() s = [i for i in s] ans = 0 e = ["R", "G", "B"] for i in range(1, n): if s[i] == s[i - 1]: ans += 1 dame = set() dame.add(e.index(s[i - 1])) if i != n - 1: dame.add(e.index(s[i + 1])) for j in range(3): if j in dame: continue else: s[i] = e[j] break print(ans) print("".join(s))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
from sys import stdin input = stdin.readline n, l, i = int(input()), 0, 0 a = list(input()) b = {"R": ["G", "B"], "G": ["R", "B"], "B": ["R", "G"]} dp = [0] * n while i < n - 2: p, q = a[i], a[i + 1] if p != q: dp[i] = a[i] i += 1 continue if p == q: dp[i] = a[i] l += 1 c = b[q] t = a[i + 2] for j in c: if t != j: dp[i + 1] = j break i += 2 if i == n - 1: dp[n - 1] = a[n - 1] print(l) print("".join(dp)) else: if a[n - 2] != a[n - 1]: dp[n - 1], dp[n - 2] = a[n - 1], a[n - 2] else: dp[n - 2] = a[n - 2] l += 1 dp[n - 1] = b[a[n - 2]][0] print(l) print("".join(dp))
ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING LIST STRING STRING LIST STRING STRING LIST STRING STRING ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = list(input()) cnt = 0 for i in range(1, n): if s[i] == s[i - 1]: if s[i] == "R": if i + 1 < n and s[i + 1] == "G": s[i] = "B" elif i + 1 < n and s[i + 1] == "B": s[i] = "G" else: s[i] = "G" elif s[i] == "G": if i + 1 < n and s[i + 1] == "R": s[i] = "B" elif i + 1 < n and s[i + 1] == "B": s[i] = "R" else: s[i] = "B" elif s[i] == "B": if i + 1 < n and s[i + 1] == "G": s[i] = "R" elif i + 1 < n and s[i + 1] == "R": s[i] = "G" else: s[i] = "G" cnt += 1 print(cnt) print("".join(s))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = input() l = list(s) ans = 0 for i in range(1, n): if l[i] == l[i - 1]: if l[i] == "R": if i + 1 == n: l[i] = "G" ans += 1 if i + 1 < n and l[i + 1] == "R": l[i] = "G" ans += 1 elif i + 1 < n and l[i + 1] == "G": l[i] = "B" ans += 1 elif i + 1 < n and l[i + 1] == "B": l[i] = "G" ans += 1 elif l[i] == "G": if i + 1 == n: l[i] = "B" ans += 1 if i + 1 < n and l[i + 1] == "R": l[i] = "B" ans += 1 elif i + 1 < n and l[i + 1] == "G": l[i] = "B" ans += 1 elif i + 1 < n and l[i + 1] == "B": l[i] = "R" ans += 1 elif l[i] == "B": if i + 1 == n: l[i] = "G" ans += 1 if i + 1 < n and l[i + 1] == "R": l[i] = "G" ans += 1 elif i + 1 < n and l[i + 1] == "G": l[i] = "R" ans += 1 elif i + 1 < n and l[i + 1] == "B": l[i] = "G" ans += 1 print(ans) for i in l: print(i, end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING VAR NUMBER IF VAR VAR STRING IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING VAR NUMBER IF VAR VAR STRING IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = list(input()) minn = 0 if n != 1: for i in range(n - 2): if s[i] == s[i + 1] == s[i + 2]: if s[i] == "R": s[i + 1] = "G" elif s[i] == "G": s[i + 1] = "B" else: s[i + 1] = "R" minn += 1 elif s[i] == s[i + 1]: if s[i] == "R" and s[i + 2] == "G": s[i + 1] = "B" elif s[i] == "R" and s[i + 2] == "B": s[i + 1] = "G" elif s[i] == "G" and s[i + 2] == "B": s[i + 1] = "R" elif s[i] == "G" and s[i + 2] == "R": s[i + 1] = "B" elif s[i] == "B" and s[i + 2] == "R": s[i + 1] = "G" else: s[i + 1] = "R" minn += 1 if s[n - 2] == s[n - 1]: if s[n - 2] == "R": s[n - 1] = "G" elif s[n - 2] == "G": s[n - 1] = "B" else: s[n - 1] = "R" minn += 1 print(minn) for i in range(n): print(s[i], end="") else: print(0) print(s[0])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) l = input() s = [] for i in range(n): s.append(l[i]) k = 0 c = set() q = set("RGB") if n == 1: print(0) print(s[0]) else: for i in range(n - 2): if s[i] == s[i + 1]: k += 1 c.add(s[i]) c.add(s[i + 2]) w = list(q - c)[0] s[i + 1] = w c = set() if s[n - 1] == s[n - 2]: c.add(s[n - 2]) w = list(q - c)[0] s[n - 1] = w k += 1 print(k) print(*s, sep="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = input() l = [] c = [s[0]] i = 1 co = 1 while i < n: if s[i] == s[i - 1]: co += 1 else: c.append(s[i]) l.append(co) co = 1 i += 1 l.append(co) res = "" pr = -1 cou = 0 for i in range(len(l)): if l[i] == 1: res += c[i] pr = s[i] else: a = l[i] if l[i] % 2 == 1: aa = a // 2 for k in ["R", "G", "B"]: if c[i] != k: break ss = c[i] + k res += ss * aa res += c[i] cou += aa else: aa = a // 2 cou += aa if i == 0: for k in ["R", "G", "B"]: if c[i] != k: break ss = k + c[i] res += ss * aa else: for k in ["R", "G", "B"]: if c[i] != k and c[i - 1] != k: break ss = k + c[i] res += ss * aa print(cou) print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR LIST STRING STRING STRING IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER FOR VAR LIST STRING STRING STRING IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR FOR VAR LIST STRING STRING STRING IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
input() garland = list(input()) s_types = ["R", "G", "B"] res = 0 previous = garland[0] for ind, s in enumerate(garland[1:-1]): if s == previous: res += 1 for c in s_types: if c != garland[ind + 2] and c != previous: garland[ind + 1] = c previous = c break else: previous = s if len(garland) > 1: if garland[-2] == garland[-1]: res += 1 s = garland[-2] for c in s_types: if c != s: garland[-1] = c break print(res) print("".join(garland))
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) a = list(input()) ans = 0 if n == 1: print(0) print(a[0]) exit() for i in range(1, n - 1): if a[i - 1] == a[i] and a[i] == a[i + 1] and a[i] == "R": a[i] = "G" ans += 1 elif a[i - 1] == a[i] and a[i] == a[i + 1] and a[i] == "B": a[i] = "G" ans += 1 elif a[i - 1] == a[i] and a[i] == a[i + 1] and a[i] == "G": a[i] = "B" ans += 1 for i in range(1, n - 1): if a[i] == a[i - 1]: if a[i + 1] == "R": if a[i] == "G": a[i] = "B" ans += 1 else: a[i] = "G" ans += 1 elif a[i + 1] == "G": if a[i] == "R": a[i] = "B" ans += 1 else: a[i] = "R" ans += 1 elif a[i] == "G": a[i] = "R" ans += 1 else: a[i] = "G" ans += 1 if a[n - 1] == a[n - 2] and a[n - 1] == "R": a[n - 1] = "B" ans += 1 if a[n - 1] == a[n - 2] and a[n - 1] == "B": a[n - 1] = "R" ans += 1 if a[n - 1] == a[n - 2] and a[n - 1] == "G": a[n - 1] = "B" ans += 1 print(ans) for i in range(n): print(a[i], end="") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
h = 1 input() p = "x" r = 1 t = [] for c in input().lower(): if h != 1: p = next(iter(set("bgr") - {p, c})) t.append(p) h = 1 if c != p: t.append(c) else: h = 2 r += 1 p = c if h != 1: p = next(iter(set("bg") - {p})) t.append(p) print(r - 1) print("".join(t).upper())
ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) w = list(input()) count = 0 for i in range(1, len(w)): if w[i] != w[i - 1]: continue elif i != len(w) - 1: next = ["R", "G", "B"] next.remove(w[i - 1]) if w[i + 1] in next: next.remove(w[i + 1]) w[i] = next[0] count += 1 else: next = ["R", "G", "B"] next.remove(w[i - 1]) w[i] = next[0] count += 1 print(count) print("".join(w))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST STRING STRING STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST STRING STRING STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = list(input()) st = "" for i in range(n): st += s[i] for i in range(1, n): if s[i] == s[i - 1] and i != n - 1: if s[i] == "R": if s[i + 1] != "B": s[i] = "B" else: s[i] = "G" elif s[i] == "G": if s[i + 1] != "R": s[i] = "R" else: s[i] = "B" elif s[i] == "B": if s[i + 1] != "G": s[i] = "G" else: s[i] = "R" continue if s[i] == s[i - 1] and i == n - 1: if s[i - 1] == "R": s[i] = "G" else: s[i] = "R" c = 0 for i in range(n): if s[i] != st[i]: c += 1 print(c) print("".join(s))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
import sys mod = 10**9 + 7 INF = float("inf") def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() s = list(input()) d = {"R": 0, "G": 1, "B": 2} s = [d[x] for x in s] res = INF dp = [([0] * 3) for _ in range(n)] root = [([0] * (n - 1)) for _ in range(3)] for i in range(3): tmp = 0 if s[0] == i else 1 dp[0][i] = tmp for i in range(1, n): for j in range(3): tmp = 0 if s[i] == j else 1 ans = INF pre = -1 for k in range(3): if j == k: continue if dp[i - 1][k] + tmp < ans: ans = dp[i - 1][k] + tmp pre = k dp[i][j] = ans root[j][i - 1] = pre res = INF ind = -1 for i in range(3): if dp[-1][i] < res: res = dp[-1][i] ind = i print(res) res = [ind] for i in range(n - 1)[::-1]: res.append(root[res[-1]][i]) d = {(0): "R", (1): "G", (2): "B"} res = [d[x] for x in res[::-1]] print("".join(res))
IMPORT ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER STRING STRING STRING ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) l = list(input()) a = {"R": 0, "G": 1, "B": 2} b = ["R", "G", "B"] c = 0 for i in range(n - 1): if l[i] == l[i + 1]: c += 1 if i + 2 < n and l[i] == l[i + 2]: l[i + 1] = b[a[l[i]] - 1] elif i + 2 < n and l[i] != l[i + 2]: l[i + 1] = b[3 - a[l[i]] - a[l[i + 2]]] else: l[i + 1] = b[a[l[i]] - 1] print(c) print("".join(l))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = list(input()) cur = "X" start, end = 0, 0 i = 0 ans = 0 while i < n: if s[i] != cur: cur = s[i] start = i while i < n and s[i] == cur: i += 1 if i == n: for ch in "RBG": if ch != s[start]: use = ch break else: for ch in "RBG": if ch != s[start] and ch != s[i]: use = ch break end = i - 1 for j in range(start, end + 1): if (j - start) % 2: s[j] = use ans += 1 print(ans) print("".join(s))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR FOR VAR STRING IF VAR VAR VAR ASSIGN VAR VAR FOR VAR STRING IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = list(input()) c = 0 for x in range(1, n): if s[x - 1] == s[x]: c += 1 if x + 1 < n: if s[x + 1] == s[x]: if s[x] == "R": s[x] = "G" else: s[x] = "R" else: if s[x + 1] == "R": if s[x] == "G": s[x] = "B" else: s[x] = "G" if s[x + 1] == "G": if s[x] == "B": s[x] = "R" else: s[x] = "B" if s[x + 1] == "B": if s[x] == "G": s[x] = "R" else: s[x] = "G" elif s[x] == "R": s[x] = "G" else: s[x] = "R" print(c) print("".join(s))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
import itertools n = int(input()) s = list(input()) count = 0 values = { (l, r): next(iter(set("RGB") - {l, r})) for l, r in itertools.product("RGB", repeat=2) } ranges = [] start = None for i in range(1, n): if s[i - 1] == s[i]: if start is None: start = i - 1 elif start is not None: ranges.append((start, i)) start = None if start is not None: ranges.append((start, n)) for r in ranges: for i in range(r[0] + 1, r[1], 2): l = s[i - 1] r = s[(i + 1) % n] s[i] = values[l, r] count += 1 print(count) print("".join(s))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR LIST ASSIGN VAR NONE FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR IF VAR NONE ASSIGN VAR BIN_OP VAR NUMBER IF VAR NONE EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NONE IF VAR NONE EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = input() t = 0 li = ["G", "R", "B"] ans = s[0] for i in range(1, n): x = s[i] if x == ans[i - 1]: t += 1 if i < n - 1: z = s[i + 1] for y in li: if y != x and y != z: ans += y break else: for y in li: if y != x: ans += y break else: ans += x print(t) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR VAR FOR VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = [i for i in input()] T = ["R", "G", "B"] add = 0 for i in range(n - 1): if s[i] == s[i + 1]: add += 1 if i + 2 < n: for j in T: if j != s[i] and j != s[i + 2]: s[i + 1] = j break else: for j in T: if j != s[i]: s[i + 1] = j break print(add) print("".join(s))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR FOR VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
def DGarland(n, gar): gar = list(gar) j = 0 for i in range(n - 1): dg = ["B", "G", "R"] if gar[i] == gar[i + 1]: if i + 2 < n: dg.remove(gar[i + 2]) if gar[i] in dg: dg.remove(gar[i]) j += 1 gar[i + 1] = dg[0] gar = "".join(gar) return j, gar n = int(input()) gar = input() i, res = DGarland(n, gar) print(i) print(res)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST STRING STRING STRING IF VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
x = int(input()) s = list(input()) res = 0 for n in range(x - 2, -1, -1): if s[n] == s[n + 1]: if s[n + 1] == "G": s[n] = "B" elif s[n + 1] == "B": s[n] = "R" elif s[n + 1] == "R": s[n] = "G" if n: if s[n - 1] == s[n]: if s[n - 1] == "R": s[n] = "G" elif s[n - 1] == "G": s[n] = "B" else: s[n] = "R" res += 1 print(res) for n in s: print(n, end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR IF VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
amount = int(input()) garland = list(input()) ans = 0 if amount == 1: print(0) print(garland[0]) else: for i in range(1, amount - 1): if garland[i - 1] == garland[i]: ans += 1 if garland[i - 1] != "R" and garland[i + 1] != "R": garland[i] = "R" elif garland[i - 1] != "G" and garland[i + 1] != "G": garland[i] = "G" else: garland[i] = "B" if garland[-1] == garland[-2]: ans += 1 if garland[-2] != "R": garland[-1] = "R" else: garland[-1] = "B" print(ans) for elem in garland: print(elem, end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER STRING EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
l = input() l = int(l) s = input() if l == 1: print(0) print(s) else: s = list(s) ans = 0 for i in range(1, l - 1): if s[i] == s[i - 1]: ans += 1 if s[i] == "R": if s[i + 1] == "G": s[i] = "B" else: s[i] = "G" elif s[i] == "G": if s[i + 1] == "R": s[i] = "B" else: s[i] = "R" elif s[i] == "B": if s[i + 1] == "R": s[i] = "G" else: s[i] = "R" if s[l - 1] == s[l - 2]: if s[l - 2] == "R": s[l - 1] = "G" elif s[l - 2] == "G": s[l - 1] = "B" elif s[l - 2] == "B": s[l - 1] = "R" ans += 1 print(ans) print("".join(s))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) l = list(input()) pre = l[0] count = int(1) sum = int(0) ans = [] for i in range(1, n): if l[i] == pre: count += 1 if count % 2 == 0 and i + 1 != n: if l[i] == "R": if l[i + 1] == "G": l[i] = "B" else: l[i] = "G" elif l[i] == "G": if l[i + 1] == "R": l[i] = "B" else: l[i] = "R" elif l[i + 1] == "R": l[i] = "G" else: l[i] = "R" elif count % 2 == 0 and i + 1 == n: if l[i] == "R": l[i] = "G" elif l[i] == "B": l[i] = "G" else: l[i] = "R" else: if count % 2 == 0: sum += int(count / 2) else: sum += count // 2 count = 1 pre = l[i] if count % 2 == 0: sum += int(count / 2) else: sum += count // 2 print(sum) for i in l: print(i, end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) a = list(input()) x = 0 for i in range(n - 1): if a[i] == a[i + 1]: x += 1 if i < n - 2: if a[i] == a[i + 2] and a[i] == "R": a[i + 1] = "B" elif a[i] == a[i + 2] and a[i] == "B": a[i + 1] = "G" elif a[i] == a[i + 2] and a[i] == "G": a[i + 1] = "R" elif a[i] == "R": if a[i + 2] == "B": a[i + 1] = "G" else: a[i + 1] = "B" elif a[i] == "B": if a[i + 2] == "R": a[i + 1] = "G" else: a[i + 1] = "R" elif a[i] == "G": if a[i + 2] == "B": a[i + 1] = "R" else: a[i + 1] = "B" elif a[i] == "R": a[i + 1] = "B" elif a[i] == "B": a[i + 1] = "G" else: a[i + 1] = "R" print(x) print("".join(a))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = input() if n == 1: print("0") print(s) else: count = 0 l = [] indexl = [] dis = list(s) for i in range(1, n - 1): if dis[i] == dis[i - 1]: count += 1 if s[i] == "R": if s[i + 1] == "R": dis[i] = "G" if s[i + 1] == "G": dis[i] = "B" if s[i + 1] == "B": dis[i] = "G" if s[i] == "B": if s[i + 1] == "R": dis[i] = "G" if s[i + 1] == "G": dis[i] = "R" if s[i + 1] == "B": dis[i] = "G" if s[i] == "G": if s[i + 1] == "R": dis[i] = "B" if s[i + 1] == "G": dis[i] = "B" if s[i + 1] == "B": dis[i] = "R" if dis[n - 1] == dis[n - 2]: count += 1 if s[n - 1] == "R": dis[n - 1] = "B" if s[n - 1] == "G": dis[n - 1] = "B" if s[n - 1] == "B": dis[n - 1] = "R" if count == 0: print("0") print(s) else: print(count) print("".join(dis))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) a = list(input().strip()) cost = 0 for i in range(n - 1): if a[i] != a[i + 1]: continue else: cost += 1 if a[i] == "R": if i + 2 < n and a[i + 2] == "R": a[i + 1] = "B" elif i + 2 < n and a[i + 2] == "G": a[i + 1] = "B" elif i + 2 < n and a[i + 2] == "B": a[i + 1] = "G" else: a[i + 1] = "G" elif a[i] == "G": if i + 2 < n and a[i + 2] == "R": a[i + 1] = "B" elif i + 2 < n and a[i + 2] == "G": a[i + 1] = "R" elif i + 2 < n and a[i + 2] == "B": a[i + 1] = "R" else: a[i + 1] = "R" elif a[i] == "B": if i + 2 < n and a[i + 2] == "R": a[i + 1] = "G" elif i + 2 < n and a[i + 2] == "G": a[i + 1] = "R" elif i + 2 < n and a[i + 2] == "B": a[i + 1] = "R" else: a[i + 1] = "R" print(cost) print(*a, sep="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
t = input() s = input() s = list(s) p = 0 r = 1 q = 2 change = 0 if len(s) > 1: while q < len(s): if s[r] == s[p]: if s[q] == s[p]: if s[q] == "R": s[r] = "B" elif s[q] == "B": s[r] = "G" elif s[q] == "G": s[r] = "R" elif s[p] == "R" and s[q] == "B": s[r] = "G" elif s[p] == "R" and s[q] == "G": s[r] = "B" elif s[p] == "G" and s[q] == "B": s[r] = "R" elif s[p] == "G" and s[q] == "R": s[r] = "B" elif s[p] == "B" and s[q] == "G": s[r] = "R" elif s[p] == "B" and s[q] == "R": s[r] = "G" change = change + 1 p = p + 1 q = q + 1 r = r + 1 if s[len(s) - 1] == s[len(s) - 2]: if s[len(s) - 1] == "R": s[len(s) - 1] = "G" elif s[len(s) - 1] == "G": s[len(s) - 1] = "B" elif s[len(s) - 1] == "B": s[len(s) - 1] = "R" change = change + 1 result = "" for i in range(len(s)): result = result + s[i] print(change) print(result) else: print(0) print(s[0])
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) ss = input() l = ss s = [] s.append("&") for i in l: s.append(i) s.append("&") count = 0 for i in range(n): if s[i] == s[i + 1]: if "B" != s[i] and "B" != s[i + 2]: s[i + 1] = "B" elif "G" != s[i + 2] and "G" != s[i]: s[i + 1] = "G" elif "R" != s[i + 2] and "R" != s[i]: s[i + 1] = "R" count += 1 print(count) for i in range(1, n + 1): print(s[i], end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF STRING VAR VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER STRING IF STRING VAR BIN_OP VAR NUMBER STRING VAR VAR ASSIGN VAR BIN_OP VAR NUMBER STRING IF STRING VAR BIN_OP VAR NUMBER STRING VAR VAR ASSIGN VAR BIN_OP VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) l1 = input() l2 = l1 l1 = list(l1) l2 = list(l2) c = {"R", "G", "B"} q = 0 l1.append("B") for i in range(n - 1): if l1[i] == l1[i + 1]: tempSet = {l1[i], l1[i + 1], l1[i + 2]} Sub = list(c - (c & {l1[i], l1[i + 1], l1[i + 2]})) l1[i + 1] = Sub[0] q = q + 1 l1.pop() print(q) print("".join(l1))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING STRING STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
def compatible(prev, *args): if not args: return next(iter(colour_set - {prev})) else: return next(iter(colour_set - {prev, args[0]})) n_lamps = int(input()) garland = list(input()) colour_set = {"R", "G", "B"} count = 0 for idx, lamp in enumerate(garland): if idx == 0: continue prev = garland[idx - 1] if lamp == prev: if idx == len(garland) - 1: garland[-1] = compatible(prev) count += 1 continue nxt = garland[idx + 1] garland[idx] = compatible(prev, nxt) count += 1 print(count) print("".join(garland))
FUNC_DEF IF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING STRING STRING ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
def other(a, b): if a == "R" and b == "B": return "G" if a == "R" and b == "G": return "B" if a == "R" and b == "R": return "G" if a == "B" and b == "B": return "G" if a == "B" and b == "G": return "R" if a == "B" and b == "R": return "G" if a == "G" and b == "G": return "R" if a == "G" and b == "B": return "R" if a == "G" and b == "R": return "B" n = int(input()) s = input() if n == 1: print(0) print(s) elif n == 2: if s[0] == s[1]: print(1) print(s[0] + ("G" if s[0] != "G" else "R")) else: print(0) print(s) else: s = [i for i in s] o = [] c = 0 for i in range(n - 2): if s[i] == s[i + 1]: s[i + 1] = other(s[i], s[i + 2]) c += 1 if s[n - 2] == s[n - 1]: s[n - 1] = "G" if s[n - 2] != "G" else "R" c += 1 print(c, "".join(s), sep="\n")
FUNC_DEF IF VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER STRING STRING STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING STRING STRING VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL STRING VAR STRING
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = input() l = len(s) color = ["R", "B", "G"] count = 0 col = list(s) if l == 1: print(0) print(s) exit(0) if l == 2: if col[0] != col[1]: print(1) color.remove(col[1]) count += 1 col[0] = color[0] print("".join(col)) exit(0) for i in reversed(range(1, l - 1)): if col[i] == col[i + 1]: for j in color: if j != col[i - 1] and j != col[i + 1]: count += 1 col[i] = j break if col[1] == col[0]: color.remove(col[1]) count += 1 col[0] = color[0] print(count) print("".join(col))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
len = int(input()) a = input() sum = 0 b = [] c = 0 for i in range(0, len - 1): if c == 1: c = 0 continue b.append(a[i]) if a[i] == a[i + 1]: sum += 1 if i == len - 2: if a[i] == "R": c = 2 b.append("B") elif a[i] == "G": b.append("B") c = 2 else: c = 2 b.append("R") break elif a[i] != "R" and a[i + 2] != "R": c = 1 b.append("R") elif a[i] != "G" and a[i + 2] != "G": c = 1 b.append("G") else: c = 1 b.append("B") print(sum) for i in b: print(i, end="") if c != 2: print(a[len - 1]) else: print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
input() lamps = list(input()) res = 0 for i in range(len(lamps) - 1): if lamps[i] == lamps[i + 1]: if i == len(lamps) - 2: if lamps[i] != "B": lamps[i + 1] = "B" else: lamps[i + 1] = "R" elif lamps[i] == "B": if lamps[i + 2] != "R": lamps[i + 1] = "R" else: lamps[i + 1] = "G" elif lamps[i] == "G": if lamps[i + 2] != "R": lamps[i + 1] = "R" else: lamps[i + 1] = "B" elif lamps[i + 2] != "B": lamps[i + 1] = "B" else: lamps[i + 1] = "G" res += 1 print(res) res = "" for i in lamps: res += str(i) print(res)
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = input() y = [-1] for i in s: if i == "R": y.append(1) elif i == "B": y.append(2) else: y.append(3) y.append(-1) count = 0 i = 1 while i <= n: if y[i - 1] != y[i] and y[i] != y[i + 1]: i += 1 else: j = i + 1 m = 1 while y[j] == y[j - 1] and j <= n + 2: j += 1 m += 1 if m % 2 == 0: k = i while k < i + m: if (y[k - 1] == 2 or y[k] == 2) and (y[k - 1] == 1 or y[k] == 1): y[k] = 3 elif (y[k - 1] == 2 or y[k] == 2) and (y[k - 1] == 3 or y[k] == 3): y[k] = 1 elif (y[k - 1] == 1 or y[k] == 1) and (y[k - 1] == 3 or y[k] == 3): y[k] = 2 elif y[k + 1] == 1: y[k] = 2 elif y[k + 1] == 2: y[k] = 3 else: y[k] = 1 k += 2 else: k = i + 1 while k < i + m: if y[k - 1] == 2: y[k] = 1 elif y[k - 1] == 1: y[k] = 3 else: y[k] = 2 k += 2 i = j count += m // 2 print(count) for i in y: if i == 1: print("R", end="") elif i == 2: print("B", end="") elif i == 3: print("G", end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING STRING
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) p = input().rstrip() p = list(p) SS = 0 for i in range(0, len(p) - 1): if p[i] == p[i + 1]: SS = SS + 1 if i == len(p) - 2: if p[i + 1] == "B": p[i + 1] = "G" elif p[i + 1] == "G": p[i + 1] = "B" elif p[i + 1] == "R": p[i + 1] = "G" else: D = [] D.append(p[i + 2]) D.append(p[i]) if "G" not in D: p[i + 1] = "G" elif "B" not in D: p[i + 1] = "B" elif "R" not in D: p[i + 1] = "R" print(SS) print("".join(p))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF STRING VAR ASSIGN VAR BIN_OP VAR NUMBER STRING IF STRING VAR ASSIGN VAR BIN_OP VAR NUMBER STRING IF STRING VAR ASSIGN VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = input() counter = 0 def color(output, i, s): if output[len(output) - 1] == "R" and s[i] == "R": if s[i + 1] == "G": return "B" return "G" elif output[len(output) - 1] == "G" and s[i] == "G": if s[i + 1] == "R": return "B" return "R" elif output[len(output) - 1] == "B" and s[i] == "B": if s[i + 1] == "R": return "G" return "R" else: return s[i] output = s[0] for i in range(1, n - 1): val = color(output, i, s) if val != s[i]: counter = counter + 1 output = output + val if len(s) > 1: if output[n - 2] == s[n - 1]: counter = counter + 1 if output[n - 2] == "R" and s[n - 1] == "R": output = output + "G" elif output[n - 2] == "G" and s[n - 1] == "G": output = output + "R" else: output = output + "R" else: output = output + s[n - 1] print(counter) print(output)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING RETURN STRING RETURN STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING RETURN STRING RETURN STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING RETURN STRING RETURN STRING RETURN VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = list(input()) + ["*"] a = ["*"] l = list("GRB") c = 0 for i in range(n): if s[i] == a[-1]: for j in l: if j != a[-1] and j != s[i + 1]: a.append(j) c += 1 break else: a.append(s[i]) print(c) print("".join(a[1:]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR LIST STRING ASSIGN VAR LIST STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = list(input()) ans = int() if n == 2: if s[0] == s[1]: e = set("RGB") ans = 1 e.remove(s[0]) s[1] = e.pop() elif n > 2: for i in range(1, n - 1): k = s[i] pr = s[i - 1] ne = s[i + 1] e = set("RGB") if pr == k: ans += 1 if pr == ne: e.remove(k) s[i] = e.pop() else: e.remove(pr) e.remove(ne) s[i] = e.pop() if s[n - 1] == s[n - 2]: e = set("RGB") ans += 1 e.remove(s[n - 1]) s[n - 1] = e.pop() print(ans) print("".join(s))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) a = ["R", "G", "B"] listA = list(input()) count = 0 for i in range(n - 1): if listA[i] == listA[i + 1]: b = a[:] b.remove(listA[i + 1]) if i + 2 < n: if listA[i + 2] in b: b.remove(listA[i + 2]) listA[i + 1] = b[0] count += 1 print(count) print("".join(listA))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
import sys n = int(input()) lamps = input() if len(lamps) == 1: print(0) print(lamps) return def other(c1, c2="R"): if "G" != c1 and "G" != c2: return "G" elif "R" != c1 and "R" != c2: return "R" else: return "B" newlamps = list(lamps) i = 1 recolors = 0 while i < n - 1: if newlamps[i] == newlamps[i - 1]: recolors += 1 newlamps[i] = other(newlamps[i - 1], newlamps[i + 1]) i += 1 if newlamps[-1] == newlamps[-2]: newlamps[-1] = other(newlamps[-2]) recolors += 1 print(recolors) print("".join(newlamps))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FUNC_DEF STRING IF STRING VAR STRING VAR RETURN STRING IF STRING VAR STRING VAR RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
import sys inf = float("inf") mod = 1000000007 def get_array(): return list(map(int, sys.stdin.readline().split())) def get_ints(): return map(int, sys.stdin.readline().split()) def input(): return sys.stdin.readline() def main(): n = int(input()) s = list(input().strip()) if n == 1: print(0) print(*s, sep="") return if n == 2: if s[0] != s[1]: print(0) print(*s, sep="") return if s[0] == s[1]: print(1) if s[0] == "R": print("RG") return elif s[0] == "G": print("GB") return elif s[0] == "B": print("BR") return mn, count = inf, 0 for i in range(n - 2): if s[i] == s[i + 1]: count += 1 if s[i + 1] == s[i + 2]: if s[i] == "R": s[i + 1] = "G" elif s[i] == "G": s[i + 1] = "B" elif s[i] == "B": s[i + 1] = "G" elif (s[i] == "R" or s[i] == "G") and (s[i + 2] == "R" or s[i + 2] == "G"): s[i + 1] = "B" elif (s[i] == "R" or s[i] == "B") and (s[i + 2] == "R" or s[i + 2] == "B"): s[i + 1] = "G" elif (s[i] == "B" or s[i] == "G") and (s[i + 2] == "B" or s[i + 2] == "G"): s[i + 1] = "R" if s[-1] == s[-2]: count += 1 if s[-2] == "R": s[-1] = "G" elif s[-2] == "G": s[-1] = "B" elif s[-2] == "B": s[-1] = "R" print(count) print(*s, sep="") main()
IMPORT ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING RETURN IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING RETURN IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) d = {"R": 0, "G": 1, "B": 2} a = {(0): "R", (1): "G", (2): "B"} s = [d[i] for i in input()] s.append(-1) beg = 0 i = 1 res = 0 while i < n + 1: if s[i - 1] != s[i]: if i - beg > 1: j = beg + 1 while j < i: s[j] = {0, 1, 2}.difference({s[j - 1], s[j + 1]}).pop() res += 1 j += 2 beg = i i += 1 print(res) for i in range(n): print(a[s[i]], end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER STRING STRING STRING ASSIGN VAR VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR STRING
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) c = input() b = [] for j in c: b.append(j) p = 0 if n == 1: print(0) print(c) else: for j in range(n - 2): if b[j] == b[j + 1]: if b[j] == "R" and b[j + 2] == "B": b[j + 1] = "G" elif b[j] == "R" and b[j + 2] == "G": b[j + 1] = "B" elif b[j] == "B" and b[j + 2] == "G": b[j + 1] = "R" elif b[j] == "B" and b[j + 2] == "R": b[j + 1] = "G" elif b[j] == "G" and b[j + 2] == "B": b[j + 1] = "R" elif b[j] == "G" and b[j + 2] == "R": b[j + 1] = "B" elif b[j] == "R" and b[j + 2] == "R": b[j + 1] = "G" elif b[j] == "B" and b[j + 2] == "B": b[j + 1] = "G" elif b[j] == "G" and b[j + 2] == "G": b[j + 1] = "R" p += 1 if b[-1] == b[-2]: if b[-1] == "R": b[-1] = "G" elif b[-1] == "G": b[-1] = "R" elif b[-1] == "B": b[-1] = "R" p += 1 print(p) print("".join(b))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
def deal(a, b, c="0"): if c == "0" or a == c: if a == "R": return "B" if a == "B": return "R" if a == "G": return "B" if a == "R" and c == "B": b = "G" if a == "R" and c == "G": b = "B" if a == "B" and c == "R": b = "G" if a == "B" and c == "G": b = "R" if a == "G" and c == "B": b = "R" if a == "G" and c == "R": b = "B" return b n = int(input()) ss = input() s = list(ss) answer = [s[0]] number = 0 for i in range(0, n - 1): ans = "" if s[i] == s[i + 1]: number += 1 if i == n - 2: ans = deal(s[i], s[i + 1]) else: ans = deal(s[i], s[i + 1], s[i + 2]) s[i + 1] = ans answer.append(ans) else: answer.append(s[i + 1]) s = "".join(answer) print(number) print(s)
FUNC_DEF STRING IF VAR STRING VAR VAR IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING VAR STRING ASSIGN VAR STRING IF VAR STRING VAR STRING ASSIGN VAR STRING IF VAR STRING VAR STRING ASSIGN VAR STRING IF VAR STRING VAR STRING ASSIGN VAR STRING IF VAR STRING VAR STRING ASSIGN VAR STRING IF VAR STRING VAR STRING ASSIGN VAR STRING RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR STRING IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = input() arr = [] rb = 0 rg = 0 rr = 0 for i in s: arr.append(i) if i == "R": rr += 1 if i == "B": rb += 1 if i == "G": rg += 1 xx = 0 for i in range(1, len(arr)): if arr[i - 1] != arr[i]: if arr[i - 1] == "R": rr -= 1 if arr[i - 1] == "G": rg -= 1 if arr[i - 1] == "B": rb -= 1 continue else: xx += 1 if arr[i - 1] == "R": if i + 1 < n: if arr[i + 1] == "R": arr[i] = "B" if arr[i + 1] == "B": arr[i] = "G" if arr[i + 1] == "G": arr[i] = "B" else: arr[i] = "B" if arr[i - 1] == "B": if i + 1 < n: if arr[i + 1] == "R": arr[i] = "G" if arr[i + 1] == "B": arr[i] = "G" if arr[i + 1] == "G": arr[i] = "R" else: arr[i] = "G" if arr[i - 1] == "G": if i + 1 < n: if arr[i + 1] == "R": arr[i] = "B" if arr[i + 1] == "B": arr[i] = "R" if arr[i + 1] == "G": arr[i] = "B" else: arr[i] = "B" print(xx) print("".join(arr))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
def div_process(s, c): sl = list(s) for i in range(1, len(sl), 2): sl[i] = c return "".join(sl) li = 0 ct = 0 input() i_s = input() sp_l = [] for i in range(1, len(i_s)): if not i_s[i] == i_s[i - 1]: sp_l.append(i_s[li:i]) li = i sp_l.append(i_s[li:]) for i in range(len(sp_l) - 1): sp_l[i] = div_process( sp_l[i], list({"R", "G", "B"} - {sp_l[i][0], sp_l[i + 1][0]})[0] ) sp_l[-1] = div_process(sp_l[-1], list({"R", "G", "B"} - {sp_l[-1][0]})[0]) print(sum([int(len(x) / 2) for x in sp_l])) print("".join(sp_l))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN FUNC_CALL STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP STRING STRING STRING VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP STRING STRING STRING VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
from sys import stdin, stdout input = stdin.readline print = stdout.write n = int(input()) s = list(input()) rgb = {"R", "G", "B"} c = 0 prev = 0 for i in range(n): if prev: s[i] = rgb.difference([s[i - 1], s[i + 1] if i != n - 1 else ""]).pop() prev = 0 c += 1 elif s[i] == (s[i + 1] if i != n - 1 else ""): prev = 1 print(str(c) + "\n") print("".join(s))
ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) g = list(input()) cost = 0 for i in range(1, n): if g[i] == g[i - 1]: cost += 1 if i == n - 1 or g[i] == g[i + 1]: if g[i] == "R": g[i] = "G" elif g[i] == "G": g[i] = "B" else: g[i] = "R" elif g[i] == "R" and g[i + 1] == "G": g[i] = "B" elif g[i] == "R" and g[i + 1] == "B": g[i] = "G" elif g[i] == "G" and g[i + 1] == "R": g[i] = "B" elif g[i] == "G" and g[i + 1] == "B": g[i] = "R" elif g[i] == "B" and g[i + 1] == "R": g[i] = "G" else: g[i] = "R" print(cost) print("".join(g))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = [i for i in input()] r = 0 m = [0] * n if n == 1: print(0) print(s[0]) else: for i in range(1, n): if s[i] == s[i - 1] and m[i - 1] == 0: m[i] = 1 r += 1 for i in range(1, n - 1): if m[i] == 1: if ( s[i - 1] == "R" and s[i + 1] == "G" or s[i - 1] == "G" and s[i + 1] == "R" ): s[i] = "B" if ( s[i - 1] == "R" and s[i + 1] == "B" or s[i - 1] == "B" and s[i + 1] == "R" ): s[i] = "G" if ( s[i - 1] == "G" and s[i + 1] == "B" or s[i - 1] == "B" and s[i + 1] == "G" ): s[i] = "R" if s[i - 1] == s[i + 1] == "R": s[i] = "G" if s[i - 1] == s[i + 1] == "G": s[i] = "B" if s[i - 1] == s[i + 1] == "B": s[i] = "R" if m[-1] == 1: if s[-2] == "R" or s[-2] == "G": s[-1] = "B" else: s[-1] = "R" print(r) print("".join(s))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR NUMBER NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) rgb = list(input()) newrgb = [rgb[0]] colors = {"R", "B", "G"} count = 0 for i in range(1, n - 1): if rgb[i] == newrgb[i - 1]: newcolors = colors - {rgb[i]} - {rgb[i + 1]} for e in newcolors: newrgb.append(e) break count += 1 else: newrgb.append(rgb[i]) if n > 1 and rgb[-1] == newrgb[-1]: newcolor = colors - {rgb[-1]} for e in newcolor: newrgb.append(e) break count += 1 elif n > 1: newrgb.append(rgb[-1]) print(count) print("".join(newrgb))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR STRING STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = input() c = "RGB" ans = "" ansk = 0 flag = True for i in range(n - 1): if flag: if s[i] == s[i + 1]: if i == n - 2: ans += s[i] + c[c.find(s[i]) - 1] ansk += 1 print(ansk) print(ans) return else: for j in c: if j != s[i] and j != s[i + 2]: break flag = False ansk += 1 ans += s[i] + j else: ans += s[i] else: flag = True print(ansk) print(ans + s[-1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = input() ans = ["0"] * n if n == 1: print(0) print(s) elif n == 2: if s == "RR": print(1) print("RB") elif s == "BB": print(1) print("RB") elif s == "GG": print(1) print("GB") else: ct = 0 ans = list(s) for i in range(n - 2): if ans[i] == ans[i + 1]: for c in "RGB": if ans[i + 2] != c and ans[i] != c: ans[i + 1] = c break if ans[-2] == ans[-3]: for c in "RGB": if ans[-1] != c and ans[-3] != c: ans[-2] = c break elif ans[-2] == ans[-1]: for c in "RGB": if ans[-2] != c: ans[-1] = c break ans = "".join(ans) for i, j in zip(ans, s): if i != j: ct += 1 print(ct) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER FOR VAR STRING IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR NUMBER FOR VAR STRING IF VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR NUMBER VAR IF VAR NUMBER VAR NUMBER FOR VAR STRING IF VAR NUMBER VAR ASSIGN VAR NUMBER VAR ASSIGN VAR FUNC_CALL STRING VAR FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = [i for i in input()] if n == 1: print(0) print("".join(s)) quit() pre = s[0] c = 0 for i in range(1, n - 1): if s[i] == pre: if s[i] == "R" and s[i + 1] == "B": s[i] = "G" pre = "G" elif s[i] == "R" and s[i + 1] == "G": s[i] = "B" pre = "B" elif s[i] == "G" and s[i + 1] == "B": s[i] = "R" pre = "R" elif s[i] == "G" and s[i + 1] == "R": s[i] = "B" pre = "B" elif s[i] == "B" and s[i + 1] == "G": s[i] = "R" pre = "R" elif s[i] == "B" and s[i + 1] == "R": s[i] = "G" pre = "G" elif s[i] == "R" and s[i + 1] == "R": s[i] = "B" pre = "B" elif s[i] == "B" and s[i + 1] == "B": s[i] = "R" pre = "R" elif s[i] == "G" and s[i + 1] == "G": s[i] = "B" pre = "B" c += 1 else: pre = s[i] if s[n - 1] == pre: c += 1 if s[n - 1] == "R": s[n - 1] = "B" elif s[n - 1] == "B": s[n - 1] = "R" elif s[n - 1] == "G": s[n - 1] = "R" print(c) print("".join(s))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR STRING VAR NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
def solve(n, s): replacements = { "RB": "RG", "RG": "RB", "RR": "RB", "GR": "GB", "GB": "GR", "GG": "GR", "BR": "BG", "BG": "BR", "BB": "BR", } nb_changes, s_updated, index = 0, s[0], 1 while index < n: prev_char = s_updated[index - 1] cur_char = s[index] next_char = s[index + 1] if index + 1 < n else None if prev_char == cur_char: nb_changes += 1 if next_char is None: s_updated += replacements[prev_char + cur_char][1] else: s_updated += replacements[cur_char + next_char][1] else: s_updated += s[index] index += 1 return nb_changes, s_updated n = int(input()) s = input().strip() nb_changes, s_updated = solve(n, s) print("{} {}".format(nb_changes, s_updated))
FUNC_DEF ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR VAR VAR NUMBER VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NONE IF VAR VAR VAR NUMBER IF VAR NONE VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) l = list(input()) l.append("R") check = "RGB" res = 0 for i in range(1, n): if l[i - 1] == l[i]: for c in check: if l[i - 1] != c and l[i + 1] != c: l[i] = c res += 1 break print(res) print("".join(l[:-1]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR FOR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
def othercolor(v, j): C = set(["R", "G", "B"]) v2 = Color[(j + 1) % N] C.remove(v) if v != v2: C.remove(v2) return list(C)[0] N = int(input()) Color = input() pre = "" ans = 0 Ans = "" C = set(["R", "G", "B"]) for i, c in enumerate(Color): if pre == c: ans += 1 cn = othercolor(c, i) Ans += cn pre = cn else: Ans += c pre = c print(ans) print(Ans)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR LIST STRING STRING STRING ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR LIST STRING STRING STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) b = input() a = [] p = [] for i in range(n): a.append(b[i]) c = 0 h = "I" for j in range(n): if j + 1 == n: if a[j] == h: c += 1 if a[j - 1] != "R": a[j] = "R" elif a[j - 1] != "G": a[j] = "G" else: a[j] = "B" elif a[j] == h: c += 1 if a[j - 1] != "R" and a[j + 1] != "R": a[j] = "R" elif a[j - 1] != "G" and a[j + 1] != "G": a[j] = "G" else: a[j] = "B" h = a[j] print(c) for k in range(n): print(a[k], end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = list(input()) a = False ans = 0 if n > 1: for i in range(n - 2): if a: a = False continue if s[i] == s[i + 1]: a = True ans += 1 if s[i] != s[i + 2]: s[i + 1] = chr(219 - ord(s[i]) - ord(s[i + 2])) elif s[i] == "B": s[i + 1] = "G" else: s[i + 1] = "B" if s[-2] == s[-1]: if s[-2] == "B": s[-1] = "R" else: s[-1] = "B" ans += 1 print(ans) print("".join(s)) else: print(0) print("".join(s))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) ad = input() l = "RGB" ct = 0 a = list(ad) if len(a) == 1: print(0) print(ad) elif len(a) == 2: if a[0] == a[1]: print(1) for k in l: if k != a[0]: break a[0] = k print("".join(a)) else: for i in range(len(a) - 2): if a[i] == a[i + 1]: for k in l: if k != a[i] and k != a[i + 2]: break a[i + 1] = k ct += 1 if a[-1] == a[-2]: for k in l: if k != a[-2]: break a[-1] = k ct += 1 print(ct) print("".join(a))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = input() lens = len(s) dp = [([0] * 5) for _ in range(lens + 5)] parent = [([0] * 5) for _ in range(lens + 5)] R, G, B = 1, 2, 3 sss = "0RGB" dp[0][R] = dp[0][G] = dp[0][B] = 1 if s[0] == "R": dp[0][R] = 0 if s[0] == "G": dp[0][G] = 0 if s[0] == "B": dp[0][B] = 0 for i in range(1, lens): dp[i][R] = min(dp[i - 1][G], dp[i - 1][B]) + 1 if dp[i][R] == dp[i - 1][G] + 1: parent[i][R] = G else: parent[i][R] = B dp[i][G] = min(dp[i - 1][R], dp[i - 1][B]) + 1 if dp[i][G] == dp[i - 1][R] + 1: parent[i][G] = R else: parent[i][G] = B dp[i][B] = min(dp[i - 1][G], dp[i - 1][R]) + 1 if dp[i][B] == dp[i - 1][G] + 1: parent[i][B] = G else: parent[i][B] = R if s[i] == "R": dp[i][R] -= 1 elif s[i] == "G": dp[i][G] -= 1 elif s[i] == "B": dp[i][B] -= 1 ans = min(dp[lens - 1][R], dp[lens - 1][G], dp[lens - 1][B]) print(min(dp[lens - 1][R], dp[lens - 1][G], dp[lens - 1][B])) ans2 = [0] * lens if ans == dp[lens - 1][R]: i = lens - 1 pp = R while i >= 0: ans2[i] = sss[pp] pp = parent[i][pp] i -= 1 elif ans == dp[lens - 1][G]: i = lens - 1 pp = G while i >= 0: ans2[i] = sss[pp] pp = parent[i][pp] i -= 1 else: i = lens - 1 pp = B while i >= 0: ans2[i] = sss[pp] pp = parent[i][pp] i -= 1 print("".join(ans2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR STRING VAR VAR VAR NUMBER IF VAR VAR STRING VAR VAR VAR NUMBER IF VAR VAR STRING VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
import sys input = sys.stdin.readline n = int(input()) S = list(input()) ANS = 0 LIST = ["R", "G", "B"] for i in range(1, n): if S[i] == S[i - 1]: if i < n - 1: for l in LIST: if S[i - 1] != l and S[i + 1] != l: ANS += 1 S[i] = l break else: for l in LIST: if S[i - 1] != l: ANS += 1 S[i] = l break print(ANS) print("".join(S))
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
strLen = int(input()) uPattern = input() i = 0 totChg = 0 rPattern = "" def getRVal(val, nextVal): if nextVal == "": if val == "R": return "G" if val == "G": return "B" if val == "B": return "R" else: if val == "R" and nextVal == "G": return "B" if val == "R" and nextVal == "B": return "G" if val == "B" and nextVal == "R": return "G" if val == "B" and nextVal == "G": return "R" if val == "G" and nextVal == "R": return "B" if val == "G" and nextVal == "B": return "R" def getChanged(val, pattern, nextVal): result = "" rVal = getRVal(val, nextVal) for x in range(0, len(pattern)): if x % 2 == 0: result += val else: result += rVal return result while i < strLen - 1: if uPattern[i] == uPattern[i + 1]: start = i count = 1 i += 1 while i < strLen - 1 and uPattern[i] == uPattern[i + 1]: count += 1 i += 1 count += 1 end = i cPattern = uPattern[start : end + 1] if i == strLen - 1: rPattern += getChanged(cPattern[0], cPattern, "") else: rPattern += getChanged(cPattern[0], cPattern, uPattern[end + 1]) totChg += count // 2 else: rPattern += uPattern[i] i += 1 if i != strLen: rPattern += uPattern[i] print(totChg) print(rPattern)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FUNC_DEF IF VAR STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING RETURN STRING FUNC_DEF ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR RETURN VAR WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR STRING VAR FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = input() s = list(s) if len(s) <= 2 and len(set(s)) > 1: print(0) print("".join(s)) elif len(s) == 2: print(1) bam = "RGB" print(s[0] + bam[(bam.index(s[0]) + 1) % 3]) else: perekras = 0 for t in range(1, len(s) - 1): if s[t - 1] == s[t] and s[t] == s[t + 1]: z = {"R", "G", "B"} perekras += 1 z.discard(s[t - 1]) z.discard(s[t + 1]) s[t] = z.pop() for t in range(1, len(s) - 1): if s[t - 1] == s[t] or s[t] == s[t + 1]: z = {"R", "G", "B"} perekras += 1 z.discard(s[t - 1]) z.discard(s[t + 1]) s[t] = z.pop() print(perekras) print("".join(s))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR STRING STRING STRING VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR STRING STRING STRING VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) a = list(input()) count = 0 chill = 0 if n == 1: chill = 1 if n == 2: if a[0] == a[1]: count += 1 if a[0] == "R": a[1] = "G" elif a[1] == "G": a[1] = "R" else: a[1] = "R" chill = 1 for i in range(n - 2): if chill == 1: break if a[i] == a[i + 1] and a[i + 1] == a[i + 2]: if a[i] == "R": a[i + 1] = "G" elif a[i] == "G": a[i + 1] = "R" else: a[i + 1] = "R" count += 1 for i in range(n - 1): if chill == 1: break if a[i] == a[i + 1]: if i == 0: if a[i] == "R" and a[i + 2] == "B": a[i + 1] = "G" elif a[i] == "G" and a[i + 2] == "R": a[i + 1] = "B" elif a[i] == "B" and a[i + 2] == "G": a[i + 1] = "R" elif a[i] == "B" and a[i + 2] == "R": a[i + 1] = "G" elif a[i] == "R" and a[i + 2] == "G": a[i + 1] = "B" else: a[i + 1] = "R" elif a[i - 1] == "R" and a[i + 1] == "B": a[i] = "G" elif a[i - 1] == "G" and a[i + 1] == "R": a[i] = "B" elif a[i - 1] == "B" and a[i + 1] == "G": a[i] = "R" elif a[i - 1] == "B" and a[i + 1] == "R": a[i] = "G" elif a[i - 1] == "R" and a[i + 1] == "G": a[i] = "B" else: a[i] = "R" count += 1 print(count) print("".join(a))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
I = lambda: int(input()) IL = lambda: list(map(int, input().split())) IF = lambda: list(map(float, input().split())) n = I() G = list(input() + " ") i = 0 r = 0 last = "" ans = 0 while i <= n: if last == G[i]: r += 1 if r == 2: G[i - 1] = list(set("RGB") - {G[i], G[i - 2]})[0] ans += 1 r = 0 elif r: G[i - 1] = list(set("RGB") - {G[i], G[i - 2]})[0] ans += 1 r = 0 last = G[i] i += 1 print(ans) print("".join(G[:-1]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER
You have a garland consisting of $n$ lamps. Each lamp is colored red, green or blue. The color of the $i$-th lamp is $s_i$ ('R', 'G' and 'B' β€” colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse. A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $1$) have distinct colors. In other words, if the obtained garland is $t$ then for each $i$ from $1$ to $n-1$ the condition $t_i \ne t_{i + 1}$ should be satisfied. Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β€” the number of lamps. The second line of the input contains the string $s$ consisting of $n$ characters 'R', 'G' and 'B' β€” colors of lamps in the garland. -----Output----- In the first line of the output print one integer $r$ β€” the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $t$ of length $n$ β€” a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them. -----Examples----- Input 9 RBGRRBRGG Output 2 RBGRGBRGR Input 8 BBBGBRRR Output 2 BRBGBRGR Input 13 BBRRRRGGGGGRR Output 6 BGRBRBGBGBGRG
n = int(input()) s = input() l = [] l.append(s[0]) j = 0 c = 0 if n == 1: print(0) print(s) else: for i in range(1, len(s) - 1): if l[j] != s[i]: l.append(s[i]) j = j + 1 elif s[i] == l[j]: if s[i + 1] != s[i]: k = ["R", "G", "B"] m = [s[i], s[i + 1]] g = [item for item in k if item not in m] l.append(g[0]) j = j + 1 elif s[i + 1] == s[i]: k = ["R", "G", "B"] m = s[i] g = [item for item in k if item not in m] l.append(g[0]) j = j + 1 c = c + 1 t = s[n - 1] if t != l[j]: l.append(t) else: k = ["R", "G", "B"] m = [t] g = [item for item in k if item not in m] l.append(g[0]) c = c + 1 print(c) print("".join(l))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST VAR ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR