We need to solve: Given n eggs in a circle, we need to assign each a color from 7 colors (R,O,Y,G,B,I,V) such that: all seven colors used at least once; and any four consecutive eggs (in the circle) must have distinct colors.
Interpretation: The eggs are in a circle, so we consider indices modulo n. Condition: For any i from 1 to n, the colors at positions i, i+1, i+2, i+3 (mod n) are all different.
Goal: For any n between 7 and 100, output a valid coloring.
We know from problem statement that it is always possible. So we need to generate one.
We need to think about constraints. The condition on any four consecutive being distinct implies that the coloring has no repeats within any block of length 4.
Since there are 7 colors, we can use them to create a pattern.
Observation: In a circle, the condition on 4 consecutive being all distinct is reminiscent of a proper coloring of the graph where each vertex is adjacent to the next three? Not exactly.
But maybe we can construct a repeating pattern of length 7: ROYGBIV (standard rainbow order). Check if it satisfies the condition for any n? Let's test: Consider sequence "ROYGBIV". For any 4 consecutive in that linear sequence, they are distinct because all 7 colors are distinct. But in a circle, if we repeat this pattern to fill n (i.e., just take the first n letters of the infinite repetition of "ROYGBIV"? Actually if we lay eggs in a circle and we have a pattern that repeats every 7, we need to consider the wrap-around at the end. For n=7, the pattern "ROYGBIV" would have 4 consecutive covering end and start: e.g., positions 6,7,1,2: V,R,O,Y? That's distinct? V,R,O,Y are distinct yes. But what about positions 7,1,2,3: V,R,O,Y? already done. Actually let's list: V, R, O, Y are distinct. 5,6,7,1: B,I,V,R distinct? B,I,V,R yes. So "ROYGBIV" works for n=7. For n=8, we need 8 eggs; if we take "ROYGBIV" plus one more? The sample output for 8 is "ROYGRBIV". That's not a simple repetition; it's "R O Y G R B I V". Check condition: Let's test "ROYGRBIV". We'll test all consecutive groups of 4 in a circle of 8:
Indices 1-4: R,O,Y,G -> distinct OK.
2-5: O,Y,G,R -> distinct OK (O,Y,G,R all distinct? R appears? Yes O,Y,G,R distinct).
3-6: Y,G,R,B -> Y,G,R,B distinct.
4-7: G,R,B,I -> G,R,B,I distinct.
5-8: R,B,I,V -> R,B,I,V distinct.
6-1 (wrap): B,I,V,R? Actually 6,7,8,1: B,I,V,R distinct.
7,8,1,2: I,V,R,O distinct.
8,1,2,3: V,R,O,Y distinct. So works. It uses all 7? Colors: R,O,Y,G,B,I,V -> yes.
So why not simply "ROYGBIVR"? That would be 8: R O Y G B I V R. Check: 1-4: R,O,Y,G distinct; 2-5: O,Y,G,B distinct; 3-6: Y,G,B,I distinct; 4-7: G,B,I,V distinct; 5-8: B,I,V,R distinct; 6,7,8,1: I,V,R,O distinct; 7,8,1,2: V,R,O,Y distinct; 8,1,2,3: R,O,Y,G distinct? Actually 8,1,2,3: R,O,Y,G -> wait 8 is R, 1 is R? No careful: indices: 1:R,2:O,3:Y,4:G,5:B,6:I,7:V,8:R. Then 8,1,2,3: R,R,O,Y? That's duplicate R at positions 8 and 1 both R, so fails because they are not distinct: R appears twice. So wrap-around fails. So the condition that the sequence is a circle means the last three and first three matter. So we cannot just repeat a prefix.
Goal: For any n, construct a circular sequence of length n with alphabet size 7, covering all colors, and any 4 consecutive distinct.
We need to find a constructive method.
One approach: Use a known pattern that satisfies the condition for arbitrary n. Since the condition only involves local constraints, perhaps we can generate a sequence with a repeating pattern of length 7 that works for any n, but we need to be careful about the wrap-around when n is not a multiple of something.
Observation: The condition any 4 consecutive distinct is equivalent to saying that the sequence has no repetition within distance 3 (circularly). That is, for any i, j such that |i-j| mod n <= 3, we must have colors different. Actually distance 3? Since if two eggs are up to 3 apart, they could be within a block of 4. Specifically, if the circular distance is at most 3, then there exists a block of 4 containing both (choose the block starting at the earlier index). But it's not exactly that: For any i and j with 0<dist<=3, they will appear together in some 4 consecutive block (if we take the block that starts at i, then i,i+1,i+2,i+3 includes j if j is within 3 steps ahead). But also block can start before i? Actually any block of length 4 covers indices i, i+1, i+2, i+3. So two indices at distance d (with 0<d<4) appear together in some block: the block starting at the smaller index includes the other. So condition implies that any two eggs whose circular distance is 1,2, or 3 must have different colors. That's a stronger condition: it means that for each egg, the colors of its three neighbors on each side (immediate left, second left, third left? Actually left and right are symmetric due to circle; the condition applies to any block of 4 consecutive, so in the circle, each egg's three successors (or predecessors) must be distinct from it and also from each other? Wait, condition does not explicitly require that the three successors are all distinct from each other beyond the requirement of the block being all distinct. But in a block of 4, all four colors must be distinct. That implies that any two within that block are distinct. So for a fixed egg, any other egg that is within distance 3 forward (i.e., at positions i+1, i+2, i+3) must have a different color from the egg at i. Also eggs at i+1 and i+2 must be distinct, etc. So the constraint is that for each i, the set of colors of the three eggs after i (including i+1,i+2,i+3) are all distinct from each other and from color at i. Similarly for any block. So indeed, the circular distance must be at least 4 for colors to possibly repeat.
Thus the problem reduces to constructing a circular sequence of length n with alphabet size 7 such that any two positions with circular distance 1,2,3 are colored differently. That is like a graph coloring of the circular graph where each vertex is connected to the three nearest neighbors on each side? Actually it's a graph where vertices are arranged in a circle, and edges connect vertices that are within distance 3 (i.e., difference mod n is 1,2,3). This graph has maximum degree 6 (each vertex connects to three ahead and three behind). We need to color with 7 colors, and also use all 7 colors at least once. Since the chromatic number might be at least 7 because degree is 6? Not exactly, but we have 7 colors, and the graph is "circular" with distance constraints; it might be 7-colorable for all n? Possibly yes, and the problem assures it's always possible.
Now we need an explicit construction for n from 7 to 100. Possibly we can use a pattern based on a repeating sequence of length 7: ROYGBIV. Check if this pattern satisfies the distance condition for a circle of length 7? For n=7, each vertex is at distances up to 3 from others? Actually in a 7-cycle, distances are 1-3 (since opposite distance is 3 or 4? Since n=7, distance mod n: the maximum of min(d, n-d) is floor(n/2)=3. So all pairs have distances 1,2,3. So indeed all vertices must have distinct colors. So the only way to color a 7-cycle with that condition is that all 7 colors are used and all distinct. So "ROYGBIV" works.
For n>7, some pairs are at distance >=4, so they can share colors. So we have some flexibility.
Let's think about constructing a sequence that uses a repeating pattern of 7 but with some modifications to ensure the wrap-around works for arbitrary n. For example, if we just take the first n of an infinite repetition of "ROYGBIV", we get a linear sequence; when we close the circle, the last three and first three may conflict. For the infinite repetition, the pattern is periodic with period 7. For the circular condition to hold for n, we need that for any i, the four consecutive starting at i are all distinct, taking into account wrap. If the pattern is periodic, the wrap condition is equivalent to checking that the pattern of length n when placed on a circle still has the property that any block crossing the boundary has distinct colors. That imposes constraints on the relationship between the prefix and suffix of length up to 3.
Let’s denote the sequence as a0,a1,...,a_{n-1}. Condition: For any i, a_i, a_{i+1}, a_{i+2}, a_{i+3} distinct (indices mod n). This is a constraint on local neighborhoods.
One idea: Use a sequence generated by a greedy algorithm: since n is at most 100, we could simply search/backtrack to find a valid coloring. That would be easy: for each position, try colors, check constraints with previous positions and also with the wrap when final positions. Since n is small and colors 7, backtracking would be fast. However, we need to output any valid coloring, and we want a simple deterministic method for programming contest. But we can implement a backtracking algorithm with constraints: it's always possible so it will find quickly. However, we need to guarantee that it always finishes quickly. For n up to 100, with 7 colors, constraints up to distance 3. A simple DFS with forward checking would be fine. But we need to also use all 7 colors at least once; we can enforce after construction check or include in backtrack. Since it's known always possible, we can just find any assignment. However, we might also need to handle the circular wrap which involves constraints between last and first. That's doable.
But perhaps simpler: there is known pattern: For any n >= 7, the sequence "ROYGBIV" repeated, but with some adjustment: Insert "GBIV" etc. Actually sample for 13 is "ROYGBIVGBIVYG". That seems like "ROYGBIV" + "GBIV" + "YG"? Let's parse: ROYGBIV GBIV YG -> Actually length: ROYGBIV (7) + GBIV (4) = 11, then YG (2) = 13. So it's "ROYGBIV" followed by "GBIV" and then "YG". That looks like building from base pattern.
Let's analyze the sample for n=13: "R O Y G B I V G B I V Y G". Check condition manually? We trust it's valid.
Maybe there is a general construction: For n >= 7, we can produce a sequence that satisfies the condition by using the pattern "ROYGBIV" and then repeating a certain subsequence to extend length while preserving constraints.
I recall a known problem: "Easter Eggs" from Codeforces? Possibly this is from a Codeforces problem. I think I've seen a solution: For n >= 7, we can output "ROYGBIV" followed by "GBIV" repeated appropriately, or something like that. Let's search memory: There is a Codeforces problem "Easter Eggs" maybe 78A? Actually I'm not sure.
Another thought: The condition is similar to de Bruijn sequence but not.
Maybe we can think about constructing a sequence that is a path in a graph where vertices represent triples of colors? Actually condition that any 4 are distinct means that for any block of length 4, all colors different. So if we consider sliding windows of length 3, we can add a new color that is different from the last three. Because when we add a new color after a partial sequence, we need to ensure that the last block of 4 (i.e., positions n-3, n-2, n-1, new) are all distinct. So if we have a linear sequence that satisfies that every consecutive four are distinct (in a linear sense), then when we close the circle, we also need to ensure the blocks that wrap around: i.e., the first three and last three must be such that when we consider the sequences crossing the boundary, the sets of four are distinct. So a simple approach: produce a linear sequence of length n that satisfies the linear condition (any 4 consecutive distinct) and also the colors at positions near the ends must be arranged so that when we connect ends, the wrap blocks are also distinct. That may be achieved by ensuring that the first three are distinct from the last three, and also that the overlapping sets are distinct.
But maybe there is a known construction: For n ≥ 7, we can take the sequence: "ROYGBIV" + repeat "GBIV" for the rest, but also adjust the last few to meet the circle condition? Wait, sample for 13: after "ROYGBIV", they added "GBIV" (makes length 11) and then "YG". That suggests that they are not simply repeating "GBIV". Let's analyze the pattern of "ROYGBIV" then possibly "GBIV" then "YG". But maybe they are building by taking the base "ROYGBIV" and then for each extra egg beyond 7, insert a color among {G,B,I,V}? Actually the sample output for 8: "ROYGRBIV". That is not "ROYGBIV" + something; it's a modification: "ROYGRBIV". Compare to "ROYGBIV": positions: 1:R,2:O,3:Y,4:G,5:G? Actually "ROYGRBIV": R O Y G R B I V. So it changed the 5th from B to R, and inserted? Actually length 8: "ROYGRBIV" has letters: R,O,Y,G,R,B,I,V. That's like "ROYG" + "R" + "BIV". So not obvious.
Maybe the intended solution is simpler: Use the pattern "ROYGBIV" as a base, and for n > 7, insert the color "GBIV" repeatedly, but also ensure that the beginning and end are adjusted. Actually there is known solution: For any n, we can output "ROYGBIV" followed by "GBIV" repeated (n-7)/4 times, and then the remainder: if remainder 1, add "G"; if remainder 2, add "GB"; if remainder 3, add "GBI". But let's test for n=8: n-7=1, remainder 1 => "ROYGBIV" + "G"? That would be "ROYGBIVG". Check: "ROYGBIVG" length 8. Does it satisfy? Let's test quickly: 1-4: R,O,Y,G distinct. 2-5: O,Y,G,B distinct. 3-6: Y,G,B,I distinct. 4-7: G,B,I,V distinct. 5-8: B,I,V,G: B,I,V,G distinct? Yes. 6-1 (wrap): I,V,G,R? Actually indices: 1:R,2:O,3:Y,4:G,5:B,6:I,7:V,8:G. Then 6,7,8,1: I,V,G,R distinct; 7,8,1,2: V,G,R,O distinct; 8,1,2,3: G,R,O,Y distinct. So "ROYGBIVG" seems to work! But the sample output for 8 is "ROYGRBIV". Why would they give a different output? Maybe both are valid; they just gave an example. So maybe this simple pattern works for many n. Let's test n=9: "ROYGBIV" + "GB" (since n-7=2, remainder 2 -> "GB") => "ROYGBIVGB". Check wrap? Let's test quickly: sequence: 1:R,2:O,3:Y,4:G,5:B,6:I,7:V,8:G,9:B. Need to check all 4 consecutive. We'll test border groups: 8,9,1,2: G,B,R,O distinct ok. 9,1,2,3: B,R,O,Y distinct ok. 7,8,9,1: V,G,B,R distinct ok. Also check internal: 5-8: B,I,V,G distinct; 6-9: I,V,G,B distinct (I,V,G,B all distinct). Also check 4-7: G,B,I,V distinct. So seems fine. n=10: "ROYGBIV" + "GBI" (remainder 3) -> "ROYGBIVGBI". Check: 1:R,2:O,3:Y,4:G,5:B,6:I,7:V,8:G,9:B,10:I. Need to check wrap: 8,9,10,1: G,B,I,R distinct; 9,10,1,2: B,I,R,O distinct; 10,1,2,3: I,R,O,Y distinct; 7,8,9,10: V,G,B,I distinct; 6,7,8,9: I,V,G,B distinct; 5,6,7,8: B,I,V,G distinct; 4,5,6,7: G,B,I,V distinct. So ok. n=11: "ROYGBIV" + "GBIV" (since n-7=4, remainder 0 after one full "GBIV") -> "ROYGBIVGBIV". Check: 1:R,2:O,3:Y,4:G,5:B,6:I,7:V,8:G,9:B,10:I,11:V. Check wrap: 9,10,11,1: B,I,V,R distinct; 10,11,1,2: I,V,R,O; 11,1,2,3: V,R,O,Y; 8,9,10,11: G,B,I,V; also check 7,8,9,10: V,G,B,I distinct? V,G,B,I distinct yes; 6,7,8,9: I,V,G,B distinct; 5,6,7,8: B,I,V,G distinct; 4,5,6,7: G,B,I,V distinct. So ok.
Now test n=12: "ROYGBIV" + "GBIVG"? Actually (12-7)=5 => one full "GBIV" (4) and remainder 1 => add "G". So "ROYGBIVGBIVG". Check wrap: sequence: R,O,Y,G,B,I,V,G,B,I,V,G. Need to check groups: last three: positions 10? Actually indices: 1:R,2:O,3:Y,4:G,5:B,6:I,7:V,8:G,9:B,10:I,11:V,12:G. Check wrap: 10,11,12,1: I,V,G,R distinct; 11,12,1,2: V,G,R,O; 12,1,2,3: G,R,O,Y; 9,10,11,12: B,I,V,G distinct; 8,9,10,11: G,B,I,V distinct; 7,8,9,10: V,G,B,I distinct; 6,7,8,9: I,V,G,B distinct; 5,6,7,8: B,I,V,G distinct; 4,5,6,7: G,B,I,V distinct. Also check 3,4,5,6: Y,G,B,I distinct; 2,3,4,5: O,Y,G,B distinct; 1,2,3,4: R,O,Y,G distinct. So seems ok.
n=13: would be "ROYGBIV" + "GBIV" + "GB"? Actually 13-7=6 => one full "GBIV" (4) and remainder 2 => add "GB". So "ROYGBIVGBIVGB". But sample output is "ROYGBIVGBIVYG". That's different: They have "ROYGBIV" + "GBIV" + "YG", not "GB". So maybe both work. Let's test "ROYGBIVGBIVGB": sequence: R,O,Y,G,B,I,V,G,B,I,V,G,B. Check wrap: ... Let's test quickly: 10? Indices: 1:R,2:O,3:Y,4:G,5:B,6:I,7:V,8:G,9:B,10:I,11:V,12:G,13:B. Check blocks: 11,12,13,1: V,G,B,R distinct; 12,13,1,2: G,B,R,O distinct; 13,1,2,3: B,R,O,Y distinct; 10,11,12,13: I,V,G,B distinct; 9,10,11,12: B,I,V,G distinct; 8,9,10,11: G,B,I,V distinct; 7,8,9,10: V,G,B,I distinct; 6,7,8,9: I,V,G,B distinct; 5,6,7,8: B,I,V,G distinct; 4,5,6,7: G,B,I,V distinct. So it works too. But why did sample output use "YG"? Possibly to illustrate a different valid answer. So indeed our simple pattern seems valid.
But we must verify for all n up to 100, this pattern always yields a valid circular sequence. Let's reason.
We propose the following construction:
Let base = "ROYGBIV" (7 colors). Then let extension pattern = "GBIV" (or maybe "GBIV" repeated). For any n > 7, we write:
sequence = "ROYGBIV" + repeat "GBIV" as many times as needed to reach length n, but if after adding full "GBIV" blocks we still need more characters, we take the appropriate prefix of "GBIV" (i.e., for remainder r: 1->"G", 2->"GB", 3->"GBI").
Thus sequence = "R O Y G B I V" followed by a string S consisting of repetitions of "GBIV" (maybe with a prefix) such that total length = n.
We need to verify that this always satisfies the condition that any four consecutive eggs in the circle have distinct colors.
We should analyze properties of the pattern.
First, note that the infinite periodic sequence "... GBIV GBIV GBIV ..." has period 4 and within each block of 4, colors are distinct: G, B, I, V. Also any four consecutive within this infinite repetition are distinct? Let's check: For the infinite repetition of "GBIV", consider a window of length 4 that starts at offset 0: G,B,I,V distinct. Start at offset 1: B,I,V,G distinct (since all four are the same set). Start at offset 2: I,V,G,B distinct. Start at offset 3: V,G,B,I distinct. So any consecutive four in the infinite repetition of "GBIV" are distinct. So the infinite string ...GBIVGBIV... has the property that any four consecutive are distinct. Moreover, this string uses only the four colors {G,B,I,V}.
Now we have the prefix "ROYGBIV". This prefix uses all seven colors, with the last three being B,I,V? Actually "ROYGBIV": positions: 1:R,2:O,3:Y,4:G,5:B,6:I,7:V. So the suffix of length 3 is B,I,V. The extension string S begins with either "G" or "GBIV..." so it's built from {G,B,I,V}. So the transition from position 7 (V) to position 8 (first character of S) is V to something. If S starts with "G", that's V->G. Then we need to check that blocks crossing the boundary between prefix and S are distinct. Also we need to check the wrap-around from end of S back to beginning (position 1=R). So we need to ensure that the last three of the whole sequence are such that when combined with the first three (R,O,Y) they are distinct sets.
Given that the extension S is composed of repetitions of "GBIV", we need to analyze the ending of S. S may end on any of G,B,I,V depending on length.
Let's denote the full sequence as P (length 7) followed by T (length n-7). T is a string that is a prefix of ( "GBIV" repeated ) such that its first character is 'G' (since we always start with 'G' after the base? Actually if n-7 >=1, we add "G" as first character of T. So T begins with 'G'. So after the base's last character 'V', we have 'G'. Check block spanning positions 5,6,7,8? Actually need to check blocks that include the junction: blocks that start at i for i = 5,6,7 (since they include positions across the boundary between 7 and 8). Let's check:
- Block starting at 5: indices 5(B),6(I),7(V),8(first of T). Since the first of T is G, the set is {B,I,V,G} all distinct. Good.
- Block starting at 6: 6(I),7(V),8(G),9(?) If n>8, we need to know position 9. If n=8, then T length=1, so only position 8. Then block starting at 6 includes 6,7,8,1 (wrap) because after 8 comes 1? Actually for n=8, indices:1-8. Block starting at 6: indices 6(I),7(V),8(G),1(R) - distinct. Good.
- Block starting at 7: indices 7(V),8(G),1(R),2(O) - distinct. Good.
So the transition from base to T is fine, provided T starts with 'G', and the wrap-around from end to beginning also needs to be checked.
Now we need to check the internal consistency of T itself. Since T is a prefix of an infinite repetition of "GBIV", any four consecutive within T (if length sufficient) are distinct, because the infinite repetition has that property. However, we must also consider blocks that go from the end of T back to the beginning of the sequence. That is, blocks that start near the end of T and wrap around to the start. Those blocks include a suffix of T and a prefix of P. So we need to ensure that for any i such that the block includes indices i,i+1,i+2,i+3 (mod n) crossing the end, the four colors are distinct.
Let's denote L = n. Let T = t1 t2 ... t_{m} where m = n-7. t1 = 'G' (since we start with G). The sequence of T is the first m characters of the infinite string "GBIVGBIVGBIV...". So for any index j in T, the value is determined: t_k = char at position ((k-1) mod 4) of "GBIV": index 0->G,1->B,2->I,3->V.
So t_k = "GBIV"[ (k-1) mod 4 ].
Now we need to examine blocks that cross from T to P. Specifically, consider block starting at i where i > L-3 (i.e., near the end). For i = L-2, L-1, L? Actually indices from 1 to L. Let's define indices 1..7 for P, and indices 8..L for T (where index 8 corresponds to t1). So the wrap block starting at i = L-2 uses indices L-2, L-1, L, 1. i = L-1 uses L-1, L, 1, 2. i = L uses L, 1, 2, 3. So we need to check these three blocks.
So we need to ensure that the sets {t_{m-1}, t_m, a1, a2} (for i = L-2), {t_m, a1, a2, a3} (for i = L-1), and {a1, a2, a3, a4? Wait i = L: indices L,1,2,3 -> {t_m, a1, a2, a3}, and i = L? Actually i = L: indices L,1,2,3 gives {t_m, a1, a2, a3}. But i = L-1 gave {t_{m-1}, t_m, a1, a2}. i = L-2 gave {t_{m-2}, t_{m-1}, t_m, a1}. Also i = L-3? That would be {t_{m-3}, t_{m-2}, t_{m-1}, t_m} which is entirely within T (or maybe also wrap if m<4? Actually if m>=4, then block starting at L-3 is within T if L-3 >= 8, so it's fine. But if m<4, then L-3 might be in P? Let's consider all possible i where block wraps. In general, for i such that i > L-3, block wraps. That is i = L-2, L-1, L. Additionally, if L is small, maybe also i = L-3 if L-3 <=0? But with L>=7, L-3>=4? Actually L>=7, so L-3 >=4, but if L=7, there is no T (m=0). For L>=8, L-3>=5, so i = L-3 is at least 5, which is in P or T? For L=8, L-3=5, which is index 5 (B) in P. Block starting at 5: indices 5,6,7,8 (8 is T). That's not wrap; it's normal because 8 exists. So only i > L-3? Actually wrap occurs when i+3 > L, i.e., i > L-3. Since indices are modulo L, but we have indices from 1 to L. For i = L-2: i+1 = L-1, i+2 = L, i+3 = L+1 which wraps to 1. So yes, i = L-2, L-1, L. Also i = L+1? Not considered because i from 1 to L. So only these three starting positions need careful check.
So we need to verify that for any m (1 to 93 because n up to 100), the blocks with these three starting indices yield distinct sets, given that a1=R, a2=O, a3=Y, a4=G,... but the specific ones needed: For i = L (i.e., start at last element), block = (t_m, a1, a2, a3) = (t_m, R, O, Y). We need t_m distinct from R,O,Y. Since t_m ∈ {G,B,I,V}. R,O,Y are not in {G,B,I,V}? Actually R,O,Y are distinct and are not among {G,B,I,V} (since G is green, but O is orange, Y is yellow; G is green; they are different colors). So as long as t_m is not equal to R, O, or Y, which it isn't because t_m is one of G,B,I,V, and R,O,Y are different. Also R,O,Y are distinct among themselves. So the set {t_m, R, O, Y} always has 4 distinct colors. So block i = L is fine.
Block i = L-1: (t_{m-1}, t_m, a1, a2) = (t_{m-1}, t_m, R, O). Need these four distinct. Since t_{m-1} and t_m are from {G,B,I,V} and could be equal? In the repetition "GBIV", consecutive characters are distinct: the pattern ensures t_{k} and t_{k+1} are different (since "GBIV" has distinct adjacent). So t_{m-1} ≠ t_m. Also R and O are distinct from each other and from G,B,I,V? R and O are not in {G,B,I,V} (assuming color set is distinct). So the only possible conflict is if t_{m-1} or t_m equals R or O, which they don't. So set {t_{m-1}, t_m, R, O} always distinct. So block i = L-1 is fine.
Block i = L-2: (t_{m-2}, t_{m-1}, t_m, a1) = (t_{m-2}, t_{m-1}, t_m, R). Need these four distinct. Now t_{m-2}, t_{m-1}, t_m are three consecutive characters from the repeating "GBIV" pattern. In the pattern "GBIV", any three consecutive are distinct? Let's check: G,B,I are distinct; B,I,V distinct; I,V,G distinct; V,G,B distinct. So yes, any three consecutive are all distinct. Also t_{m-2} ≠ t_{m-1} and t_{m-1} ≠ t_m, and also t_{m-2} may equal t_m? In "GBIV", the distance two: G->I? G (index0) -> I (index2) are different; B->V different; I->G different; V->B different. So indeed all three are distinct. So {t_{m-2}, t_{m-1}, t_m} are three distinct colors from {G,B,I,V}. Then we add R, which is not in {G,B,I,V}. So all four distinct. Thus block i = L-2 is fine.
Therefore, the construction appears to satisfy the condition for all n>=8. For n=7, we just output "ROYGBIV". For n>7, we use "ROYGBIV" + (repeat "GBIV" as needed, with remainder using prefix "G","GB","GBI").
But we need to verify one more nuance: Could there be any conflict within the interior of the sequence where P and T meet other than the blocks we considered? The interior blocks that are entirely within P are fine because P itself is a valid linear sequence of length 7? Let's check P alone as a linear sequence: Any 4 consecutive within P are distinct? For "ROYGBIV", check: 1-4 R O Y G distinct; 2-5 O Y G B distinct; 3-6 Y G B I distinct; 4-7 G B I V distinct. So yes.
Blocks that start in P and end in T but not crossing wrap: i=5 (B,I,V, t1) we checked; i=6 (I,V, t1, t2) if m>=2; i=7 (V, t1, t2, t3) if m>=3. Need to check these as well. For i=6: indices 6(I),7(V),8(t1=G),9(t2?) if m>=2 then t2 = B (since pattern). So set {I,V,G,B} distinct. If m=1, then i=6 block would be indices 6,7,8,1 (wrap) which we already considered as i=L-2? For n=8, m=1, i=6 block is 6,7,8,1: we already argued that is distinct (I,V,G,R). Actually we need to check i=6 for n>8: For m>=2, block is (I,V,G,B) distinct. For m=2? n=9, m=2, indices: 6:I,7:V,8:G,9:B => distinct. So okay.
i=7: indices 7(V),8(G),9(B),10(I) if m>=3; set {V,G,B,I} distinct. If m=2, then block i=7 would be (V,G,B,1?) Actually n=9, m=2: indices:7,8,9,1 => V,G,B,R distinct. That's crossing wrap? For n=9, i=7, indices: 7(V),8(G),9(B),1(R) -> distinct. So okay.
What about i=8? That's start in T. Blocks starting in T (i>=8) that are fully within T or go to wrap, we have considered. For i such that i <= L-3, block is fully within T (if i+3 <= L). Since T is a prefix of an infinite repetition with the property that any 4 consecutive are distinct, those blocks are fine. However, careful: If T is short, the infinite repetition property might break at the end because the repetition might not continue? But we only need to check blocks fully contained in T: that is i and i+3 <= L. Since T is exactly a prefix of the infinite repetition, any window fully inside that prefix will be a window of the infinite repetition, and thus all four distinct. So that holds.
What about blocks that start in T and end with wrap but not covered by i = L-2, L-1, L? That's all wrap cases. So we've covered all.
Thus the construction works for all n >= 8.
But we also need to ensure that all seven colors are used at least once. The base "ROYGBIV" already contains all seven. So that's satisfied.
Thus the solution: For n=7, output "ROYGBIV". For n>7, output "ROYGBIV" + repeat("GBIV", (n-7)//4) + prefix of "GBIV" of length (n-7)%4.
But careful: For remainder 0, we just repeat "GBIV" fully; for remainder 1, add "G"; remainder 2, add "GB"; remainder 3, add "GBI". This yields a string of length n.
Check n=8: (n-7)=1, remainder 1 -> "ROYGBIV"+"G" = "ROYGBIVG". But the sample output is "ROYGRBIV". They are different but both valid. So it's acceptable.
But is there any case where this pattern might fail? Let's test n=14: "ROYGBIV" + "GBIV" (4) + "GBI"? Actually 14-7=7, so one full "GBIV" (4) and remainder 3 => "GBI". So sequence: ROYGBIVGBIVGBI. Check wrap: last three letters: positions 12? Let's compute: indices: 1:R,2:O,3:Y,4:G,5:B,6:I,7:V,8:G,9:B,10:I,11:V,12:G,13:B,14:I. So last three are B,I? Actually 12:G,13:B,14:I. So block i = L-2: indices 12,13,14,1 = G,B,I,R distinct. i = L-1: 13,14,1,2 = B,I,R,O distinct. i = L: 14,1,2,3 = I,R,O,Y distinct. Good.
What about block i=5 (5:B,6:I,7:V,8:G) fine. i=6: 6:I,7:V,8:G,9:B distinct. i=7: 7:V,8:G,9:B,10:I distinct. i=8: 8:G,9:B,10:I,11:V distinct. i=9: 9:B,10:I,11:V,12:G distinct. i=10: 10:I,11:V,12:G,13:B distinct. i=11: 11:V,12:G,13:B,14:I distinct. i=12: 12:G,13:B,14:I,1:R distinct. i=13: 13:B,14:I,1:R,2:O distinct. i=14: already checked. So it's fine.
Thus this construction is simple and provably correct.
Edge cases: n=100, works similarly.
Now we need to implement in code: read n, if n==7 output "ROYGBIV". Else compute m = n-7, q = m//4, r = m%4. Build string: base = "ROYGBIV". Then extension = ("GBIV" * q) + ("GBIV"[:r])? But "GBIV"[:r] for r=1 gives "G", r=2 gives "GB", r=3 gives "GBI", r=0 gives empty. So final string = base + ("GBIV" * q) + ("GBIV"[:r]).
But note: "GBIV" repeated q times could be large (q up to (93//4)=23, fine). So simple.
Check n=7: m=0, q=0,r=0, extension empty -> "ROYGBIV". Works.
Thus answer: Output that string.
But wait, sample for n=13: Our method gives "ROYGBIV" + "GBIV" (since q = (13-7)//4 = 6//4=1) + "GBIV"[: (13-7)%4 = 6%4=2 ] = "GB" -> "ROYGBIVGBIVGB". That is different from sample output "ROYGBIVGBIVYG". So both are acceptable. The problem says "If there are several answers, print any of them." So our output is valid.
Thus solution is trivial.
But let's double-check the condition for n=7: "ROYGBIV" works. For n>7, our pattern yields a string that always uses all colors and satisfies 4-distinct.
I've already reasoned about wrap. There is one subtlety: when n is just 8, we have base + "G". That's "ROYGBIVG". Check i=5: 5:B,6:I,7:V,8:G distinct; i=6:6:I,7:V,8:G,1:R distinct; i=7:7:V,8:G,1:R,2:O distinct; i=8:8:G,1:R,2:O,3:Y distinct. Good.
Now, confirm that the pattern T = "GBIV" repeated prefix always ensures that t1 is G. In our construction, we start extension with "G" always because we take "GBIV"*q and then prefix of "GBIV". Even if q=0 and r>0, we add "GBIV"[:r] which starts with 'G'. So indeed t1='G'.
Now confirm that for m=2 (n=9) we have T = "GB". So t1='G', t2='B'. Blocks: i=6 (6:I,7:V,8:G,9:B) distinct; i=7 (7:V,8:G,9:B,1:R) distinct; i=8 (8:G,9:B,1:R,2:O) distinct; i=9 (9:B,1:R,2:O,3:Y) distinct. All good.
Now, what about n=10: T = "GBI". So t1='G', t2='B', t3='I'. i=7: 7:V,8:G,9:B,10:I distinct; i=8:8:G,9:B,10:I,1:R distinct; i=9:9:B,10:I,1:R,2:O distinct; i=10:10:I,1:R,2:O,3:Y distinct.
n=11: T = "GBIV". i=8:8:G,9:B,10:I,11:V distinct; i=9:9:B,10:I,11:V,1:R distinct; i=10:10:I,11:V,1:R,2:O; i=11:11:V,1:R,2:O,3:Y.
All good.
Thus the solution is correct.
But we must ensure that the colors are represented by single characters: R,O,Y,G,B,I,V. Yes.
Implementation: straightforward.
Now, is there any situation where the infinite repetition property might break at the boundaries if T length is not multiple of 4? No, because blocks fully within T are windows of length 4 that are contiguous substrings of the infinite repetition. Since T is a prefix, any substring fully inside T is also a substring of the infinite repetition. However, if T length is less than 4, then there might be no block fully inside T; but that's fine.
Thus code.
But we might want to also consider alternative solutions, but this is simplest.
Now, we should test a few values to ensure all constraints hold:
n=15: m=8, q=2, r=0 => base + "GBIV"*2 = "ROYGBIVGBIVGBIV". Check last few: ... after base: indices 8:G,9:B,10:I,11:V,12:G,13:B,14:I,15:V. Wrap: i=13:13:B,14:I,15:V,1:R distinct; i=14:14:I,15:V,1:R,2:O; i=15:15:V,1:R,2:O,3:Y. Good.
n=16: m=9, q=2, r=1 => base + "GBIVGBIV" + "G" => length: 7+8+1=16. Last three: positions 14? Let's compute: after base, 8:G,9:B,10:I,11:V,12:G,13:B,14:I,15:V,16:G. So last three: 14:I,15:V,16:G? Actually indices: 14:I,15:V,16:G. So block i=14 (14:I,15:V,16:G,1:R) distinct; i=15:15:V,16:G,1:R,2:O; i=16:16:G,1:R,2:O,3:Y. Good.
Thus all good.
Now we need to confirm that the condition "Any four eggs lying sequentially should be painted different colors" includes the blocks that wrap around the circle. Yes.
Thus we can output the described string.
One more check: For n=7, the pattern "ROYGBIV" is okay, but does it satisfy the condition? As argued, yes.
Now, the problem statement says "We know that it is always possible." So we just need to output any.
Therefore, implement.
Potential pitfalls: Use correct order: "ROYGBIV" not "ROYGRBIV" etc. The sample for 8 used "ROYGRBIV" but ours is "ROYGBIVG". Both are valid. But is there any reason to prefer one? Not needed.
Now, think about if there is any case where our pattern fails because the base "ROYGBIV" includes G,B,I,V as its last four? Actually positions 4-7: G,B,I,V. That's fine.
Now, check block starting at index 4 (G,B,I,V) within base: distinct. Good.
Now check block starting at index 3 (Y,G,B,I): distinct.
Thus okay.
Now, check block starting at index 2 (O,Y,G,B): distinct.
Now check block starting at index 1 (R,O,Y,G): distinct.
Now check blocks that cross from base to T but not wrapping: we already did.
Thus solved.
Now let's implement in Python.
Pseudo:
def solve():
n = int(input().strip())
base = "ROYGBIV"
if n == 7:
print(base)
else:
m = n - 7
q = m // 4
r = m % 4
ext = "GBIV" * q + "GBIV"[:r]
result = base + ext
print(result)
But wait: For n > 7, we always start ext with 'G' as argued. But is it always safe to start with 'G'? Yes because we used "GBIV" pattern. But what about if we used "GBIV"[:r] for r>0, it starts with G. So okay.
Now test n=8: base + "GBIV"[:1] => "ROYGBIV"+"G" = "ROYGBIVG". Good.
Now, confirm that the length matches: base length 7, ext length = 4*q + r = m, total = 7+m = n.
Now double-check the sample: n=13: m=6, q=1, r=2 => ext = "GBIV" + "GB" = "GBIVGB". So result = "ROYGBIVGBIVGB". The sample is "ROYGBIVGBIVYG". They differ: theirs ends with "YG", ours ends with "GB". But both are valid. So we are fine.
One might also wonder if for some n, the pattern could cause a conflict because the last three characters of the whole sequence might include a color that appears in the first three? But we already reasoned that it's fine because the first three are R,O,Y and the last three are from {G,B,I,V}. So no conflict. But we should also check that the block starting at i = L-3 (if it wraps? Actually i = L-3 does not wrap if L-3+3 = L, so i = L-3 block uses indices L-3, L-2, L-1, L, which are all in the sequence, not wrapping. But what about the case where L-3 is less than 8? For n small, say n=8, L-3=5, block starting at 5: indices 5,6,7,8 -> that's within base and T, not wrap. Already okay. For n=9, L-3=6, block 6,7,8,9 -> indices within. Good.
Thus all good.
Thus solution is trivial.
Now, but we should also consider if there is any scenario where the repetition of "GBIV" could cause a conflict with the base's earlier part due to wrap? That is only the three blocks we checked.
Thus answer.
Now, provide final solution explanation and code.
But just to be thorough, let's prove the property: For any m, the sequence defined as above works.
Proof sketch:
-
Base string B = "ROYGBIV" satisfies that any 4 consecutive are distinct (as a linear string). Also, the set of first three colors is {R,O,Y} and last three are {B,I,V}.
-
The infinite string S∞ = "GBIVGBIV..." has the property that any 4 consecutive are distinct, and uses only colors {G,B,I,V}.
-
The extension E is a prefix of S∞ of length m, starting with 'G'.
-
The concatenation B + E has length n.
-
Check all possible blocks of 4:
- Blocks entirely within B: valid.
- Blocks entirely within E: because E is prefix of S∞, any block fully inside E is a block of S∞, thus valid.
- Blocks that start in B and end in E: these are blocks starting at positions 5,6,7 (since B length 7). Check each:
- start=5: colors B5='B', B6='I', B7='V', E1='G' => all distinct.
- start=6: if m>=2 then B6='I',B7='V',E1='G',E2='B' => distinct; if m=1, then block includes wrap to position 1 (R) and we'll treat it as wrap case (but essentially same check: {I,V,G,R} distinct).
- start=7: similarly, if m>=3 then {V,G,B,I} distinct; else wrap case covered later.
- Blocks that start in E and wrap to B: these are start positions i with i > n-3. These correspond to i = n-2, n-1, n. Let t_{k} denote the k-th character of E (k from 1..m). Then:
- i=n: colors t_m, B1='R', B2='O', B3='Y' => all distinct because t_m ∈ {G,B,I,V} and R,O,Y are distinct and not in that set.
- i=n-1: colors t_{m-1}, t_m, 'R','O' => t_{m-1}≠t_m (adjacent in S∞ are distinct) and both not R or O => distinct.
- i=n-2: colors t_{m-2}, t_{m-1}, t_m, 'R' => t_{m-2}, t_{m-1}, t_m are three consecutive of S∞, which are all distinct, and none equal to 'R' => distinct.
- Additionally, for m=1 or 2, some of these blocks may also be covered by earlier categories, but the check still holds.
Thus all blocks satisfy distinctness.
- All seven colors appear at least once because B contains each color.
Thus valid.
Therefore, the algorithm is correct.
Thus we can implement.
Now, about the sample output for 8: they used "ROYGRBIV". This is not following our pattern, but it's okay. So we don't need to match samples exactly.
Now let's code.
Potential edge: Input may have trailing spaces, but int conversion handles.
Now, is there any case where n is exactly 7? Yes, we output base. For n>7, as described.
Now, confirm that for n=7, base works. For n=7, no extension. The block wrap: i=5: 5(B),6(I),7(V),1(R) distinct; i=6:6(I),7(V),1(R),2(O) distinct; i=7:7(V),1(R),2(O),3(Y) distinct. So indeed valid.
Thus code done.
Now final output.
Potential alternative: Some might prefer to generate via cycle of "ROYGBIV" but with certain modifications, but our solution is simpler.
Now we can produce final answer.
But wait, is there any requirement about the circle: "Any four eggs lying sequentially should be painted different colors." Does "sequentially" mean in the order around the circle? Yes.
Thus all set.
Now we can produce final answer with code.
But I recall a known Codeforces problem "Easter Eggs" (CF 78B maybe?). Actually there is Codeforces Round #146 (Div. 2) problem B "Easter Eggs". I think the solution is exactly this: output "ROYGBIV" + "GBIV"*... . So it's fine.
Now produce final solution explanation and code.
But careful: The output for n=8 sample is "ROYGRBIV". Could there be a test where our pattern fails because the sample expects a different format? No, problem says any answer is accepted. So it's fine.
Now let's produce final answer. ```python
import sys
def solve() -> None:
data = sys.stdin.readline().strip()
if not data:
return
n = int(data)
base = "ROYGBIV"
if n == 7:
print(base)
return
m = n - 7 # number of extra eggs
q, r = divmod(m, 4) # how many full "GBIV" blocks and remainder
ext = "GBIV" * q + "GBIV"[:r]
ans = base + ext
print(ans)
if name == "main":
solve()