ShaysXIA/CodeInsightBench huggingface dataset:
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 main():



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



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



        x -= 1

        y -=1 



        ans = [0] * n





        for i in range(n):



            ans[(x + i) %n] = i % 2



        

        if n % 2 != 0  or (x - y) % 2 == 0:

            ans[x] = 2

        



        print(*ans)







if __name__ == "__main__":

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

Solution 1 (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)



    

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):
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)



    

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):
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)



    

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):
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)



    

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()
Problem: 2049C - MEX Cycle
Language: python

Solution 1 (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)



    

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



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



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



        x -= 1

        y -=1 



        ans = [0] * n





        for i in range(n):



            ans[(x + i) %n] = i % 2



        

        if n % 2 != 0  or (x - y) % 2 == 0:

            ans[x] = 2

        



        print(*ans)







if __name__ == "__main__":

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

Solution 1 (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()

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: 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()

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: 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()

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()
Problem: 2049C - MEX Cycle
Language: python

Solution 1 (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()

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



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



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



        x -= 1

        y -=1 



        ans = [0] * n





        for i in range(n):



            ans[(x + i) %n] = i % 2



        

        if n % 2 != 0  or (x - y) % 2 == 0:

            ans[x] = 2

        



        print(*ans)







if __name__ == "__main__":

    main()
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

    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)

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

    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)

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()
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

    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)

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



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



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



        x -= 1

        y -=1 



        ans = [0] * n





        for i in range(n):



            ans[(x + i) %n] = i % 2



        

        if n % 2 != 0  or (x - y) % 2 == 0:

            ans[x] = 2

        



        print(*ans)







if __name__ == "__main__":

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

Solution 1 (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))

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()
Problem: 2049C - MEX Cycle
Language: python

Solution 1 (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))

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



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



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



        x -= 1

        y -=1 



        ans = [0] * n





        for i in range(n):



            ans[(x + i) %n] = i % 2



        

        if n % 2 != 0  or (x - y) % 2 == 0:

            ans[x] = 2

        



        print(*ans)







if __name__ == "__main__":

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

Solution 1 (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()

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



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



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



        x -= 1

        y -=1 



        ans = [0] * n





        for i in range(n):



            ans[(x + i) %n] = i % 2



        

        if n % 2 != 0  or (x - y) % 2 == 0:

            ans[x] = 2

        



        print(*ans)







if __name__ == "__main__":

    main()
Problem: 2050B - Transfusion
Language: python

Solution 1 (runtime: 218 ms):
a=int(input())
for _ in range(a):
    b=int(input())
    c=list(map(int,input().split()))
    if sum(c)%b!=0:
        print('NO')
    else:
        t=sum(c)//b
        w=[]
        l=[]
        for i in range(b):
            if i%2==0:
                w.append(c[i])
            else:
                l.append(c[i])
        if sum(l)//len(l)==t==sum(w)//len(w):
            print('YES')
        else:
            print('NO')

Solution 2 (runtime: 171 ms):
def process_array():
    _size = int(input())
    a =list(map(int, input().split()))
    sum1 = 0 
    odd= (_size+1)//2
    sum2 = 0 
    even = _size-odd
    for i in range(_size):
        if i%2==0 :
           sum1+=a[i]
           
        else :
           sum2+=a[i] 
   # print(sum1, sum2, odd ,even)
    if (sum1+sum2)%_size==0 :
       if sum1 == odd*((sum1+sum2)/_size) and sum2== even*((sum1+sum2)/_size):
          print("YES")
          return
       else:
          print("NO")
          return   
    else:
      print("NO")

t = int(input())    
for _ in range(t): 
       process_array()
Problem: 2050B - Transfusion
Language: python

Solution 1 (runtime: 218 ms):
a=int(input())
for _ in range(a):
    b=int(input())
    c=list(map(int,input().split()))
    if sum(c)%b!=0:
        print('NO')
    else:
        t=sum(c)//b
        w=[]
        l=[]
        for i in range(b):
            if i%2==0:
                w.append(c[i])
            else:
                l.append(c[i])
        if sum(l)//len(l)==t==sum(w)//len(w):
            print('YES')
        else:
            print('NO')

Solution 2 (runtime: 171 ms):


OUT=[]
for i in range(int(input())):
    n=int(input())
    L=list(map(int,input().split()))
    s=sum(L)
    if s%n==0 :
        p=s//n
        k=1
        b=True
        while k<n-1 and b:
            if L[k-1]!= p:
                
                L[k+1]-=p-L[k-1]
                L[k-1]=p
                
            k+=1
        if b and L[-1]==p and L[-2]==p:
            OUT.append('YES')
        else:
            OUT.append('NO')
        
    else:
        OUT.append('NO')

for i in OUT:
    print(i)
Problem: 2050B - Transfusion
Language: python

Solution 1 (runtime: 218 ms):
a=int(input())
for _ in range(a):
    b=int(input())
    c=list(map(int,input().split()))
    if sum(c)%b!=0:
        print('NO')
    else:
        t=sum(c)//b
        w=[]
        l=[]
        for i in range(b):
            if i%2==0:
                w.append(c[i])
            else:
                l.append(c[i])
        if sum(l)//len(l)==t==sum(w)//len(w):
            print('YES')
        else:
            print('NO')

Solution 2 (runtime: 202 ms):
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    b = [a[i] for i in range(n) if i % 2 == 0]
    c=[a[i] for i in range(n) if i % 2 != 0]

    if sum(b)%len(b)==0:
        if sum(c)%len(c)==0 and sum(b)//len(b)==sum(c)//len(c):
            print("YES")
        else:
            print("NO")
    else:
        print("NO")
Problem: 2050B - Transfusion
Language: python

Solution 1 (runtime: 218 ms):
a=int(input())
for _ in range(a):
    b=int(input())
    c=list(map(int,input().split()))
    if sum(c)%b!=0:
        print('NO')
    else:
        t=sum(c)//b
        w=[]
        l=[]
        for i in range(b):
            if i%2==0:
                w.append(c[i])
            else:
                l.append(c[i])
        if sum(l)//len(l)==t==sum(w)//len(w):
            print('YES')
        else:
            print('NO')

Solution 2 (runtime: 186 ms):
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    b = [a[i] for i in range(n) if i % 2 == 0]
    c=[a[i] for i in range(n) if i % 2 != 0]

    if sum(b)%len(b)==0:
        if sum(c)%len(c)==0 and sum(b)//len(b)==sum(c)//len(c):
            print("YES")
        else:
            print("NO")
    else:
        print("NO")