ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2049B - pspspsps
Language: python

Solution 1 (runtime: 93 ms):
for _ in range(int(input())):

    g=[]

    n=int(input())

    s=list(input())

    f=0 

    fl=0

    for i in range(n):

        if s[i]=='p' and f==0:

            f=1

        if f==1 and s[i]=='s':

            fl=1 

            break 

    if fl==1:

        print("NO")

        continue

    mx=0

    s[0],s[-1]='.','.'

    for i in range(n):

        if s[i]=='s':

            mx=max(mx,n-1)

        if s[i]=='p' and i<mx:

            fl=1 

            break 

    if fl==0:

        print("YES")

    else:

        print("NO")

            







Solution 2 (runtime: 93 ms):
import sys

input = lambda: sys.stdin.readline().rstrip()



def main():

    t = int(input())

    for _ in range(t):

        if run_case():

            print("YES")

        else:

            print('no')

def run_case():

    n = int(input())

    s = input()

    flag1 = 0

    flag2 = 0

    for i, item in enumerate(s):

        if item == 'p':

            if i != n-1:

                flag1 = 1

                if flag2:

                    return 0

        if item == 's':

            if i != 0:

                flag2 = 1

                if flag1:

                    return 0

    return 1

main()
Problem: 2049B - pspspsps
Language: python

Solution 1 (runtime: 93 ms):
for _ in range(int(input())):

    g=[]

    n=int(input())

    s=list(input())

    f=0 

    fl=0

    for i in range(n):

        if s[i]=='p' and f==0:

            f=1

        if f==1 and s[i]=='s':

            fl=1 

            break 

    if fl==1:

        print("NO")

        continue

    mx=0

    s[0],s[-1]='.','.'

    for i in range(n):

        if s[i]=='s':

            mx=max(mx,n-1)

        if s[i]=='p' and i<mx:

            fl=1 

            break 

    if fl==0:

        print("YES")

    else:

        print("NO")

            







Solution 2 (runtime: 108 ms):
from collections import defaultdict, deque
from bisect import bisect_right, bisect_left
from math import inf, isqrt, sqrt, gcd, factorial, ceil
from itertools import permutations

mod = 10**9 + 7

def main():
    for _ in range(int(input())):
        solve()

#     solve()
def solve():

    n = int(input())
    s = list(input())

    s[0] = "." if s[0] == "s" else s[0]
    s[-1] = "." if s[-1] == "p" else s[-1]

    c1 = s.count("s")
    c2 = s.count("p")
    if c1 > 0 and c2 > 0:
        print("NO")
    else:
        print("YES")




main()
Problem: 2049B - pspspsps
Language: python

Solution 1 (runtime: 93 ms):
for _ in range(int(input())):

    g=[]

    n=int(input())

    s=list(input())

    f=0 

    fl=0

    for i in range(n):

        if s[i]=='p' and f==0:

            f=1

        if f==1 and s[i]=='s':

            fl=1 

            break 

    if fl==1:

        print("NO")

        continue

    mx=0

    s[0],s[-1]='.','.'

    for i in range(n):

        if s[i]=='s':

            mx=max(mx,n-1)

        if s[i]=='p' and i<mx:

            fl=1 

            break 

    if fl==0:

        print("YES")

    else:

        print("NO")

            







Solution 2 (runtime: 124 ms):
a = int(input())

for y in range(a):

  b = int(input())

  c = input()

  j = list(c)

  

  if j[0] == "s":

    j[0] = "."

    

  if j[-1] == "p":

    j[-1] = "."

    

  l = 0

  if "s" in j and "p" in j:

    l = -1

    

    

  print("Yes") if l == 0 else print("No")
Problem: 2049B - pspspsps
Language: python

Solution 1 (runtime: 93 ms):
for _ in range(int(input())):

    g=[]

    n=int(input())

    s=list(input())

    f=0 

    fl=0

    for i in range(n):

        if s[i]=='p' and f==0:

            f=1

        if f==1 and s[i]=='s':

            fl=1 

            break 

    if fl==1:

        print("NO")

        continue

    mx=0

    s[0],s[-1]='.','.'

    for i in range(n):

        if s[i]=='s':

            mx=max(mx,n-1)

        if s[i]=='p' and i<mx:

            fl=1 

            break 

    if fl==0:

        print("YES")

    else:

        print("NO")

            







Solution 2 (runtime: 61 ms):
def solve():

    n=int(input())

    s=input()



    cnt_s=0

    cnt_p=0

    cnt=0

    bol=False

    b=False

    for i in range(n):

        if s[i]=='s':

            cnt_s+=1

            if bol:

                b=True

        elif s[i]=='p':

            bol=True

            cnt_p+=1

        else:

            cnt+=1



    if b:

        print("NO")

        return



    if cnt_s==n or cnt_p==n or cnt==n or cnt+cnt_p==n or cnt+cnt_s==n:

        print("YES")

        return



    if s[n-1]=='.' and s[0]=='.':

        print("NO")

        return



    if cnt_p==1 and cnt_s==1:

        print("YES")

        return

    elif cnt_p==1:

        if s[n-1]=='p':

            print("YES")

        else:

            print("NO")

    elif cnt_s==1:

        if s[0]=='s':

            print("YES")

        else:

            print("NO")

    else:

        print("NO")



t=int(input())



for _ in range(t):

    solve()
Problem: 2049B - pspspsps
Language: python

Solution 1 (runtime: 93 ms):
import sys

input = lambda: sys.stdin.readline().rstrip()



def main():

    t = int(input())

    for _ in range(t):

        if run_case():

            print("YES")

        else:

            print('no')

def run_case():

    n = int(input())

    s = input()

    flag1 = 0

    flag2 = 0

    for i, item in enumerate(s):

        if item == 'p':

            if i != n-1:

                flag1 = 1

                if flag2:

                    return 0

        if item == 's':

            if i != 0:

                flag2 = 1

                if flag1:

                    return 0

    return 1

main()



Solution 2 (runtime: 108 ms):
from collections import defaultdict, deque
from bisect import bisect_right, bisect_left
from math import inf, isqrt, sqrt, gcd, factorial, ceil
from itertools import permutations

mod = 10**9 + 7

def main():
    for _ in range(int(input())):
        solve()

#     solve()
def solve():

    n = int(input())
    s = list(input())

    s[0] = "." if s[0] == "s" else s[0]
    s[-1] = "." if s[-1] == "p" else s[-1]

    c1 = s.count("s")
    c2 = s.count("p")
    if c1 > 0 and c2 > 0:
        print("NO")
    else:
        print("YES")




main()
Problem: 2049B - pspspsps
Language: python

Solution 1 (runtime: 93 ms):
import sys

input = lambda: sys.stdin.readline().rstrip()



def main():

    t = int(input())

    for _ in range(t):

        if run_case():

            print("YES")

        else:

            print('no')

def run_case():

    n = int(input())

    s = input()

    flag1 = 0

    flag2 = 0

    for i, item in enumerate(s):

        if item == 'p':

            if i != n-1:

                flag1 = 1

                if flag2:

                    return 0

        if item == 's':

            if i != 0:

                flag2 = 1

                if flag1:

                    return 0

    return 1

main()



Solution 2 (runtime: 124 ms):
a = int(input())

for y in range(a):

  b = int(input())

  c = input()

  j = list(c)

  

  if j[0] == "s":

    j[0] = "."

    

  if j[-1] == "p":

    j[-1] = "."

    

  l = 0

  if "s" in j and "p" in j:

    l = -1

    

    

  print("Yes") if l == 0 else print("No")
Problem: 2049B - pspspsps
Language: python

Solution 1 (runtime: 93 ms):
import sys

input = lambda: sys.stdin.readline().rstrip()



def main():

    t = int(input())

    for _ in range(t):

        if run_case():

            print("YES")

        else:

            print('no')

def run_case():

    n = int(input())

    s = input()

    flag1 = 0

    flag2 = 0

    for i, item in enumerate(s):

        if item == 'p':

            if i != n-1:

                flag1 = 1

                if flag2:

                    return 0

        if item == 's':

            if i != 0:

                flag2 = 1

                if flag1:

                    return 0

    return 1

main()



Solution 2 (runtime: 61 ms):
def solve():

    n=int(input())

    s=input()



    cnt_s=0

    cnt_p=0

    cnt=0

    bol=False

    b=False

    for i in range(n):

        if s[i]=='s':

            cnt_s+=1

            if bol:

                b=True

        elif s[i]=='p':

            bol=True

            cnt_p+=1

        else:

            cnt+=1



    if b:

        print("NO")

        return



    if cnt_s==n or cnt_p==n or cnt==n or cnt+cnt_p==n or cnt+cnt_s==n:

        print("YES")

        return



    if s[n-1]=='.' and s[0]=='.':

        print("NO")

        return



    if cnt_p==1 and cnt_s==1:

        print("YES")

        return

    elif cnt_p==1:

        if s[n-1]=='p':

            print("YES")

        else:

            print("NO")

    elif cnt_s==1:

        if s[0]=='s':

            print("YES")

        else:

            print("NO")

    else:

        print("NO")



t=int(input())



for _ in range(t):

    solve()
Problem: 2049B - pspspsps
Language: python

Solution 1 (runtime: 108 ms):
from collections import defaultdict, deque
from bisect import bisect_right, bisect_left
from math import inf, isqrt, sqrt, gcd, factorial, ceil
from itertools import permutations

mod = 10**9 + 7

def main():
    for _ in range(int(input())):
        solve()

#     solve()
def solve():

    n = int(input())
    s = list(input())

    s[0] = "." if s[0] == "s" else s[0]
    s[-1] = "." if s[-1] == "p" else s[-1]

    c1 = s.count("s")
    c2 = s.count("p")
    if c1 > 0 and c2 > 0:
        print("NO")
    else:
        print("YES")




main()



Solution 2 (runtime: 124 ms):
a = int(input())

for y in range(a):

  b = int(input())

  c = input()

  j = list(c)

  

  if j[0] == "s":

    j[0] = "."

    

  if j[-1] == "p":

    j[-1] = "."

    

  l = 0

  if "s" in j and "p" in j:

    l = -1

    

    

  print("Yes") if l == 0 else print("No")
Problem: 2049B - pspspsps
Language: python

Solution 1 (runtime: 108 ms):
from collections import defaultdict, deque
from bisect import bisect_right, bisect_left
from math import inf, isqrt, sqrt, gcd, factorial, ceil
from itertools import permutations

mod = 10**9 + 7

def main():
    for _ in range(int(input())):
        solve()

#     solve()
def solve():

    n = int(input())
    s = list(input())

    s[0] = "." if s[0] == "s" else s[0]
    s[-1] = "." if s[-1] == "p" else s[-1]

    c1 = s.count("s")
    c2 = s.count("p")
    if c1 > 0 and c2 > 0:
        print("NO")
    else:
        print("YES")




main()



Solution 2 (runtime: 61 ms):
def solve():

    n=int(input())

    s=input()



    cnt_s=0

    cnt_p=0

    cnt=0

    bol=False

    b=False

    for i in range(n):

        if s[i]=='s':

            cnt_s+=1

            if bol:

                b=True

        elif s[i]=='p':

            bol=True

            cnt_p+=1

        else:

            cnt+=1



    if b:

        print("NO")

        return



    if cnt_s==n or cnt_p==n or cnt==n or cnt+cnt_p==n or cnt+cnt_s==n:

        print("YES")

        return



    if s[n-1]=='.' and s[0]=='.':

        print("NO")

        return



    if cnt_p==1 and cnt_s==1:

        print("YES")

        return

    elif cnt_p==1:

        if s[n-1]=='p':

            print("YES")

        else:

            print("NO")

    elif cnt_s==1:

        if s[0]=='s':

            print("YES")

        else:

            print("NO")

    else:

        print("NO")



t=int(input())



for _ in range(t):

    solve()
Problem: 2049B - pspspsps
Language: python

Solution 1 (runtime: 124 ms):
a = int(input())

for y in range(a):

  b = int(input())

  c = input()

  j = list(c)

  

  if j[0] == "s":

    j[0] = "."

    

  if j[-1] == "p":

    j[-1] = "."

    

  l = 0

  if "s" in j and "p" in j:

    l = -1

    

    

  print("Yes") if l == 0 else print("No")

    

Solution 2 (runtime: 61 ms):
def solve():

    n=int(input())

    s=input()



    cnt_s=0

    cnt_p=0

    cnt=0

    bol=False

    b=False

    for i in range(n):

        if s[i]=='s':

            cnt_s+=1

            if bol:

                b=True

        elif s[i]=='p':

            bol=True

            cnt_p+=1

        else:

            cnt+=1



    if b:

        print("NO")

        return



    if cnt_s==n or cnt_p==n or cnt==n or cnt+cnt_p==n or cnt+cnt_s==n:

        print("YES")

        return



    if s[n-1]=='.' and s[0]=='.':

        print("NO")

        return



    if cnt_p==1 and cnt_s==1:

        print("YES")

        return

    elif cnt_p==1:

        if s[n-1]=='p':

            print("YES")

        else:

            print("NO")

    elif cnt_s==1:

        if s[0]=='s':

            print("YES")

        else:

            print("NO")

    else:

        print("NO")



t=int(input())



for _ in range(t):

    solve()
Problem: 2049C - MEX Cycle
Language: python

Solution 1 (runtime: 202 ms):
for _ in range(int(input())):

    n,x,y=map(int,input().split())

    x-=1;y-=1

    #############################################################################

    if x == y+1 or x == y-1 or (x==0 and y==n-1) or (y==0 and x==n-1):

        if n%2==0:

            ans = [0]*n

            for i in range(n):

                if i%2: ans[i] = 1

        else:

            ans = [1]*n

            for i in range(n):

                if i%2: ans[i] = 0

                ans[n-1] = 2

        print(*ans)

    #############################################################################

    else:

        ans = [-1]*n

        switch = 0 ; friends = {}

        if x == 0:

            for i in range(x+1, n): 

                if switch == 0: ans[i] = 0 ; switch = 1

                else: ans[i] = 1 ; switch = 0

        else:

            for i in range(x+1, x+1 + (n - x+1) + x-1): 

                if switch == 0: ans[i%n] = 0 ; switch = 1

                else: ans[(i%n)] = 1 ; switch = 0



        

        if x == 0: friends = {ans[1],ans[y],ans[n-1]}

        elif x == n-1: friends = {ans[n-2],ans[y],ans[0]}

        else: friends = {ans[x+1],ans[y],ans[x-1]}



        if 0 in friends and 1 in friends: ans[x] = 2

        if 0 in friends and 1 not in friends: ans[x] = 1

        if 0 not in friends and 1 in friends: ans[x] = 0



        print(*ans)

Solution 2 (runtime: 202 ms):
t = int(input())

for _ in range(t):

    n,x,y = map(int,input().split())

    lst = []

    for i in range(n):

        if i%2 == 0:

            lst.append(0)

        else:

            lst.append(1)

    if n%2 == 1:

        lst[-2] = 1

        lst[-1] = 2

    # if n%2 == 0:



    if abs(x - y) == 1 or abs(x - y) == n - 1:

        print(*lst)

    else:

        if lst[x-1] == lst[y-1]:

            lst[x-1] = 2

            if n%2 == 1 and x == 1:

                lst[-1] = 0

            print(*lst)

        else:

            print(*lst)

    # else:

    #     lst[-2] = 2

    #     lst[-1] = 1

    #     if abs(x - y) == 1 or abs(x - y) == n - 1:

    #         print(*lst)

    #     else:

    #         if lst[x-1] == lst[y-1]:

    #             lst[x-1] = 2

    #             print(*lst)

    #         else:

    #             print(*lst)
Problem: 2049C - MEX Cycle
Language: python

Solution 1 (runtime: 202 ms):
for _ in range(int(input())):

    n,x,y=map(int,input().split())

    x-=1;y-=1

    #############################################################################

    if x == y+1 or x == y-1 or (x==0 and y==n-1) or (y==0 and x==n-1):

        if n%2==0:

            ans = [0]*n

            for i in range(n):

                if i%2: ans[i] = 1

        else:

            ans = [1]*n

            for i in range(n):

                if i%2: ans[i] = 0

                ans[n-1] = 2

        print(*ans)

    #############################################################################

    else:

        ans = [-1]*n

        switch = 0 ; friends = {}

        if x == 0:

            for i in range(x+1, n): 

                if switch == 0: ans[i] = 0 ; switch = 1

                else: ans[i] = 1 ; switch = 0

        else:

            for i in range(x+1, x+1 + (n - x+1) + x-1): 

                if switch == 0: ans[i%n] = 0 ; switch = 1

                else: ans[(i%n)] = 1 ; switch = 0



        

        if x == 0: friends = {ans[1],ans[y],ans[n-1]}

        elif x == n-1: friends = {ans[n-2],ans[y],ans[0]}

        else: friends = {ans[x+1],ans[y],ans[x-1]}



        if 0 in friends and 1 in friends: ans[x] = 2

        if 0 in friends and 1 not in friends: ans[x] = 1

        if 0 not in friends and 1 in friends: ans[x] = 0



        print(*ans)

Solution 2 (runtime: 171 ms):
def solve():

    n, x, y = map(int, input().split())

    x-=1

    y-=1

    a = [0]*n

    #x, x+1, ..., y

    if (y-x+1)%2 == 0:

        #偶数だべ

        #x, yは0, 1にする

        for i in range(x, y+1):

            a[i] = (i-x)%2

    else:

        #奇数なり

        #x, yは0, 1にする

        for i in range(x, y+1):

            a[i] = (i-x)%2

        #0, 2, 1

        a[y-1] = 2

        a[y] = 1

    #y, y+1, ..., n-1, 0, ..., x

    x += n

    if (x-y+1)%2 == 0:

        #偶数だ～～～！！！！！

        #x, yは0, 1にする

        for i in range(y, x+1):

            if (i-y)%2 == 0:

                a[i%n] = 1

            else:

                a[i%n] = 0

    else:

        #奇数だよ

        #x, yは0, 1にする

        for i in range(y, x+1):

            a[i%n] = (x-i)%2

        a[y] = 1

        a[(y+1)%n] = 2

    print(*a, sep = " ")



for _ in range(int(input())):

    solve()
Problem: 2049C - MEX Cycle
Language: python

Solution 1 (runtime: 202 ms):
for _ in range(int(input())):

    n,x,y=map(int,input().split())

    x-=1;y-=1

    #############################################################################

    if x == y+1 or x == y-1 or (x==0 and y==n-1) or (y==0 and x==n-1):

        if n%2==0:

            ans = [0]*n

            for i in range(n):

                if i%2: ans[i] = 1

        else:

            ans = [1]*n

            for i in range(n):

                if i%2: ans[i] = 0

                ans[n-1] = 2

        print(*ans)

    #############################################################################

    else:

        ans = [-1]*n

        switch = 0 ; friends = {}

        if x == 0:

            for i in range(x+1, n): 

                if switch == 0: ans[i] = 0 ; switch = 1

                else: ans[i] = 1 ; switch = 0

        else:

            for i in range(x+1, x+1 + (n - x+1) + x-1): 

                if switch == 0: ans[i%n] = 0 ; switch = 1

                else: ans[(i%n)] = 1 ; switch = 0



        

        if x == 0: friends = {ans[1],ans[y],ans[n-1]}

        elif x == n-1: friends = {ans[n-2],ans[y],ans[0]}

        else: friends = {ans[x+1],ans[y],ans[x-1]}



        if 0 in friends and 1 in friends: ans[x] = 2

        if 0 in friends and 1 not in friends: ans[x] = 1

        if 0 not in friends and 1 in friends: ans[x] = 0



        print(*ans)

Solution 2 (runtime: 202 ms):
for _ in range(int(input())):

    N,x,y=map(int,input().split()) ; x-=1 ; y-=1

    ans=[0 for _ in range(N)]

    for i in range(y-1,y-N,-1):

        ans[i]=i&1

    li=[ans[y-1],ans[(y+1)%N],ans[x]]

    if 0 not in li : ans[y]=0

    elif 1 not in li : ans[y]=1

    else : ans[y]=2

    print(*ans)
Problem: 2049C - MEX Cycle
Language: python

Solution 1 (runtime: 202 ms):
for _ in range(int(input())):

    n,x,y=map(int,input().split())

    x-=1;y-=1

    #############################################################################

    if x == y+1 or x == y-1 or (x==0 and y==n-1) or (y==0 and x==n-1):

        if n%2==0:

            ans = [0]*n

            for i in range(n):

                if i%2: ans[i] = 1

        else:

            ans = [1]*n

            for i in range(n):

                if i%2: ans[i] = 0

                ans[n-1] = 2

        print(*ans)

    #############################################################################

    else:

        ans = [-1]*n

        switch = 0 ; friends = {}

        if x == 0:

            for i in range(x+1, n): 

                if switch == 0: ans[i] = 0 ; switch = 1

                else: ans[i] = 1 ; switch = 0

        else:

            for i in range(x+1, x+1 + (n - x+1) + x-1): 

                if switch == 0: ans[i%n] = 0 ; switch = 1

                else: ans[(i%n)] = 1 ; switch = 0



        

        if x == 0: friends = {ans[1],ans[y],ans[n-1]}

        elif x == n-1: friends = {ans[n-2],ans[y],ans[0]}

        else: friends = {ans[x+1],ans[y],ans[x-1]}



        if 0 in friends and 1 in friends: ans[x] = 2

        if 0 in friends and 1 not in friends: ans[x] = 1

        if 0 not in friends and 1 in friends: ans[x] = 0



        print(*ans)

Solution 2 (runtime: 171 ms):
for _ in range(int(input())):

	n,x,y=map(int,input().split())

	t=[0]*n

	x=x-1

	y=y-1

	x1=min(x,y)

	x2=max(x,y)

	cluster1=x2-x1-1

	cluster2=n-(x2-x1-1)

	pos1=-1

	pos2=-1

	if cluster1%2==1 :

		pos1=(x2+x1)//2

	if cluster2%2==1:

		pos2=((x1+x2+n)//2)%n

	hattan=0

	for i in range(n):

		if i!=pos1 and i!=pos2:

			t[i]=str(hattan)

			hattan=(hattan+1)%2

		else:

			t[i]="2"

	print(" ".join(t))
Problem: 2049C - MEX Cycle
Language: python

Solution 1 (runtime: 202 ms):
for _ in range(int(input())):

    n,x,y=map(int,input().split())

    x-=1;y-=1

    #############################################################################

    if x == y+1 or x == y-1 or (x==0 and y==n-1) or (y==0 and x==n-1):

        if n%2==0:

            ans = [0]*n

            for i in range(n):

                if i%2: ans[i] = 1

        else:

            ans = [1]*n

            for i in range(n):

                if i%2: ans[i] = 0

                ans[n-1] = 2

        print(*ans)

    #############################################################################

    else:

        ans = [-1]*n

        switch = 0 ; friends = {}

        if x == 0:

            for i in range(x+1, n): 

                if switch == 0: ans[i] = 0 ; switch = 1

                else: ans[i] = 1 ; switch = 0

        else:

            for i in range(x+1, x+1 + (n - x+1) + x-1): 

                if switch == 0: ans[i%n] = 0 ; switch = 1

                else: ans[(i%n)] = 1 ; switch = 0



        

        if x == 0: friends = {ans[1],ans[y],ans[n-1]}

        elif x == n-1: friends = {ans[n-2],ans[y],ans[0]}

        else: friends = {ans[x+1],ans[y],ans[x-1]}



        if 0 in friends and 1 in friends: ans[x] = 2

        if 0 in friends and 1 not in friends: ans[x] = 1

        if 0 not in friends and 1 in friends: ans[x] = 0



        print(*ans)

Solution 2 (runtime: 202 ms):
Test = int(input())



def Sol():

    n, x, y = list(map(int, input().split()))

    Res = [((x + i) % 2) for i in range(1, n + 1)]

    if n % 2 or not((y - x) % 2):

        Res[0] = 2

    for i in range(-x + 1, 0, 1):

        print(Res[i], end= " ")

    for i in range(n - x + 1):

        print(Res[i], end = " ")

for _ in range(Test):

    Sol()

    print()