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 ...
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: ...
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_CA...
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 ...
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...
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 FUN...
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 ...
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(st...
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 V...
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 ...
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 ...
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 F...
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 ...
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" ...
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 N...
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 ...
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 ASSI...
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 ...
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 +=...
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 V...
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 ...
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: ...
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...
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 ...
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: ...
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 VA...
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 ...
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[:] ...
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...
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 ...
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] ...
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 BI...
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 ...
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() ...
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...
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 ...
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...
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 ...
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 ...
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(...
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 NU...
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 ...
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": ...
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 VA...
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 ...
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...
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 N...
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 ...
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...
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 N...
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 ...
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 ...
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...
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 ...
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 N...
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 ...
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] ...
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...
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 ...
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: ...
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...
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 ...
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] ...
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...
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 ...
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...
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_...
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 ...
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...
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...
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 ...
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" ...
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 NUMB...
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 ...
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...
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 ...
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 ...
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 ...
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 ...
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": ...
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 STRI...
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 ...
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 le...
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_CA...
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 ...
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: ...
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 NU...
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 ...
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] = ...
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...
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 ...
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]: ...
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 ...
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 ...
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: ...
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 NUM...
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 ...
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 +...
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 V...
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 ...
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 ...
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...
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 ...
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 ...
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 VA...
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 ...
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 ...
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 ...
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 ...
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] ...
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...
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 ...
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...
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...
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 ...
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 ...
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...
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 ...
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 ...
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...
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 ...
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(...
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...
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 ...
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: ...
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 VA...
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 ...
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] != ...
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 V...
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 ...
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...
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 NUMB...
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 ...
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[...
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 V...
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 ...
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 ...
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...
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 ...
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] ...
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 ST...
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 ...
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 Non...
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 ...
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 ...
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: ...
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 VA...
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 ...
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 ...
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 VA...
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 ...
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] ...
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 NU...
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 ...
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]: i...
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 STRI...
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 ...
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" eli...
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 AS...
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 ...
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: ...
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 NUMB...
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 ...
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: ...
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...
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 ...
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...
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 NUMBE...
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 ...
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" ...
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 VA...
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 ...
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] =...
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 V...
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 ...
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": ...
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 ST...
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 ...
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[...
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...
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 ...
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() p...
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 ...
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 ...
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 ...
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...
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 ...
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 ...
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...
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 ...
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 rev...
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 ...
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 ...
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"...
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 ...
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 ...
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":...
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...
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 ...
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]...
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 VA...
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 ...
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...
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 ASSIG...
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 ...
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" ...
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 R...
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 ...
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_CA...
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 ...
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: ...
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 ASSIG...
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 ...
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...
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...
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 ...
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 ...
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...
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 ...
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: ...
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...
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 ...
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 + ...
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 NU...
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 ...
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 + ...
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 ASSI...
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 ...
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" ...
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 A...
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 ...
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 ...
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_...
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 ...
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) -...
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 ...
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 ...
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...
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 S...
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 ...
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" eli...
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 V...
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 ...
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" ...
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 NUMBE...
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 ...
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....
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...
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 ...
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 ...
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...
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 ...
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 ...
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...
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 ...
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" ...
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 ...
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 ...
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...
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...
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 ...
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 VA...
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 ...
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 = oth...
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 VA...
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 ...
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: ...
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 V...
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 ...
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])) ...
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 FUN...
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 ...
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]: ...
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 ASSIG...
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 ...
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):...
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 V...
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 ...
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 ...
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 NUM...
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 ...
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": ...
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...
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 ...
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]: ...
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...
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 ...
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: ...
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 ...
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 ...
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] ...
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 NUMB...
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 ...
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"] ...
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 ASSI...