Problem:


Problem C:  ラミー

  

    あなたの友達は最近 UT-Rummy というカードゲームを思いついた．
  

  

    このゲームで使うカードには赤・緑・青のいずれかの色と1から9までのいずれかの番号が
    つけられている．
    このゲームのプレイヤーはそれぞれ9枚の手札を持ち，
    自分のターンに手札から1枚選んで捨てて，
    代わりに山札から1枚引いてくるということを繰り返す．
    このように順番にターンを進めていき，
    最初に手持ちのカードに3枚ずつ3つの「セット」を作ったプレイヤーが勝ちとなる．
    セットとは，同じ色の3枚のカードからなる組で，すべて同じ数を持っているか
    連番をなしているもののことを言う．
    連番に関しては，番号の巡回は認められない．
    例えば，7, 8, 9は連番であるが 9, 1, 2は連番ではない．
  

  

    あなたの友達はこのゲームをコンピュータゲームとして売り出すという計画を立てて，
    その一環としてあなたに勝利条件の判定部分を作成して欲しいと頼んできた．
    あなたの仕事は，手札が勝利条件を満たしているかどうかを判定する
    プログラムを書くことである．
  

  
Input

  

    入力の1行目にはデータセット数を表す数 T
    (0 < T ≤ 50) が与えられる．
    この行に引き続き T 個のデータセットが与えられる．
  

  

    各データセットは2行からなり，
    1行目には i 番目
    (i = 1, 2, ..., 9)
    のカードの数字 ni
    がそれぞれスペースで区切られて与えられ，
    2行目には i 番目のカードの色を表す文字
    ci
    がそれぞれスペースで区切られて与えられる．
    カードの数字
    ni
    は 1 ≤ ni ≤ 9
    を満たす整数であり，
    カードの色 ci
    はそれぞれ &ldquo;R&rdquo;, &ldquo;G&rdquo;,
    &ldquo;B&rdquo;
    のいずれかの文字である．
  

  

    1つのデータセット内に色と数字がともに同じカードが5枚以上出現することはない．
  

  
Output

  

    各データセットにつき，勝利条件を満たしていれば
    &ldquo;1&rdquo;，
    そうでなければ &ldquo;0&rdquo; と出力せよ．
  

  
Sample Input

  

5
1 2 3 3 4 5 7 7 7
R R R R R R G G G
1 2 2 3 4 4 4 4 5
R R R R R R R R R
1 2 3 4 4 4 5 5 5
R R B R R R R R R
1 1 1 3 4 5 6 6 6
R R B G G G R R R
2 2 2 3 3 3 1 1 1
R G B R G B R G B

  
Output for the Sample Input

  

1
0
0
0
1



Sample input:
5
1 2 3 3 4 5 7 7 7
R R R R R R G G G
1 2 2 3 4 4 4 4 5
R R R R R R R R R
1 2 3 4 4 4 5 5 5
R R B R R R R R R
1 1 1 3 4 5 6 6 6
R R B G G G R R R
2 2 2 3 3 3 1 1 1
R G B R G B R G B


Sample output:
1
0
0
0
1

Submission status: Wrong Answer

Solution code:
trial = int(input())
nums,words = [],[]
for s in range(trial):
    nums = [[int(n)] for n in input().split(" ")]
    words = [n for n in input().split(" ")]
    for t in range(9):
        nums[t].append(words[t])
    nums = sorted(nums,key=lambda x:(x[1],x[0]),reverse=False)
    n,color,cnt,samecnt,ans = nums[0][0],nums[0][1],1,1,0
    for t in range(1,9):
        if samecnt == 3:
            samecnt = 0
            ans += 1
        if cnt == 3:
            samecnt,cnt,n,color = 1,1,nums[t][0],nums[t][1]
            ans += 1
        else:
            if color != nums[t][1]:
                n,color,cnt,samecnt = nums[t][0],nums[t][1],1,1
            elif n == nums[t][0]:
                n,color = nums[t][0],nums[t][1]
                samecnt += 1
            elif n == nums[t][0] - 1:
                n,color,samecnt = nums[t][0],nums[t][1],1
                cnt += 1
            else:
                print(0)
                break
    else:
        if ans == 2 and (samecnt == 3 or cnt == 3):
            print(1)
        else:
            print(0)

Submission status: Wrong Answer

Solution code:
trial = int(input())
nums,words = [],[]
for s in range(trial):
    nums = [[int(n)] for n in input().split(" ")]
    words = [n for n in input().rstrip("\n").split(" ")]
    for t in range(9):
        nums[t].append(words[t])
    nums = sorted(nums,key=lambda x:(x[1],x[0]),reverse=False)
    n,color,cnt,samecnt,ans = nums[0][0],nums[0][1],1,1,0
    for t in range(1,9):
        #print(cnt,samecnt,ans)
        if samecnt == 3:
            samecnt,cnt,n,color = 1,1,nums[t][0],nums[t][1]
            ans += 1
        elif cnt == 3:
            samecnt,cnt,n,color = 1,1,nums[t][0],nums[t][1]
            ans += 1
        else:
            if color != nums[t][1]:
                n,color,cnt,samecnt = nums[t][0],nums[t][1],1,1
            elif n == nums[t][0]:
                samecnt += 1
            elif n == nums[t][0] - 1:
                n,samecnt = nums[t][0],1
                cnt += 1
            else:
                print(0)
                break
    else:
        #print(cnt,ans)
        if ans == 2 and (samecnt == 3 or cnt == 3):
            print(1)
        else:
            print(0)

Submission status: Wrong Answer

Solution code:
trial = int(input())
nums,words = [],[]
for s in range(trial):
    nums = [[int(n)] for n in input().split(" ")]
    words = [n for n in input().rstrip("\n").split(" ")]
    for t in range(9):
        nums[t].append(words[t])
    nums = sorted(nums,key=lambda x:(x[1],x[0]),reverse=False)
    n,color,cnt,samecnt,ans = nums[0][0],nums[0][1],1,1,0
    for t in range(1,9):
        #print(cnt,samecnt,ans)
        if samecnt == 3:
            samecnt = 1
            ans += 1
        if cnt == 3:
            samecnt,cnt,n,color = 1,1,nums[t][0],nums[t][1]
            ans += 1
        else:
            if color != nums[t][1]:
                n,color,cnt,samecnt = nums[t][0],nums[t][1],1,1
            elif n == nums[t][0]:
                samecnt += 1
            elif n == nums[t][0] - 1:
                n,samecnt = nums[t][0],1
                cnt += 1
            else:
                print(0)
                break
    else:
        #print(cnt,ans)
        if ans == 2 and (samecnt == 3 or cnt == 3) or ans == 3:
            print(1)
        else:
            print(0)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3

import sys


def main():
    WINNING_HANDS = [
                '111', '222', '333', '444', '555', '666', '777', '888', '999',
                '123', '234', '345', '456', '567', '678', '789'
            ]

    num_of_datasets = int(sys.stdin.readline().strip('\n'))
    datasets = [{'R': [], 'G': [], 'B': []} for _ in range(num_of_datasets)]
    results = list()

    for dataset in range(num_of_datasets):
        n_set = [int(num) for num in sys.stdin.readline().strip('\n').split()]
        c_set = [colour for colour in sys.stdin.readline().strip('\n').split()]
        for idx, colour in enumerate(c_set):
            if colour == 'R':
                datasets[dataset]['R'].append(n_set[idx])
            elif colour == 'G':
                datasets[dataset]['G'].append(n_set[idx])
            elif colour == 'B':
                datasets[dataset]['B'].append(n_set[idx])

        match_count = int()

        for rgb_key in datasets[dataset]:
            nums = ''.join(str(num) for num in sorted(datasets[dataset][rgb_key]))

            for hand in WINNING_HANDS:
                if hand in nums:
                    match_count += 1
                    if match_count == 3:
                        results.append(1)
                        continue

        if dataset < num_of_datasets-1:
            results.append(0)

    for result in results:
        print(result)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3

import sys


def main():
    WINNING_HANDS = [
                '111', '222', '333', '444', '555', '666', '777', '888', '999',
                '123', '234', '345', '456', '567', '678', '789'
            ]

    num_of_datasets = int(sys.stdin.readline().strip('\n'))
    datasets = [{'R': [], 'G': [], 'B': []} for _ in range(num_of_datasets)]
    results = list()

    for dataset in range(num_of_datasets):
        n_set = [int(num) for num in sys.stdin.readline().strip('\n').split()]
        c_set = [colour for colour in sys.stdin.readline().strip('\n').split()]
        for idx, colour in enumerate(c_set):
            if colour == 'R':
                datasets[dataset]['R'].append(n_set[idx])
            elif colour == 'G':
                datasets[dataset]['G'].append(n_set[idx])
            elif colour == 'B':
                datasets[dataset]['B'].append(n_set[idx])

        match_count = int()

        for rgb_key in datasets[dataset]:
            nums = ''.join(str(num) for num in sorted(datasets[dataset][rgb_key]))

            for hand in WINNING_HANDS:
                if hand in nums:
                    match_count += 1
                    if match_count == 3:
                        results.append(1)
                        continue

        if dataset < num_of_datasets-1 and match_count != 3:
            results.append(0)

    for result in results:
        print(result)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3

import sys


def main():
    WINNING_HANDS = [
                '111', '222', '333', '444', '555', '666', '777', '888', '999',
                '123', '234', '345', '456', '567', '678', '789'
            ]

    num_of_datasets = int(sys.stdin.readline().strip('\n'))
    datasets = [{'R': [], 'G': [], 'B': []} for _ in range(num_of_datasets)]
    results = list()

    for dataset in range(num_of_datasets):
        n_set = [int(num) for num in sys.stdin.readline().strip('\n').split()]
        c_set = [colour for colour in sys.stdin.readline().strip('\n').split()]
        for idx, colour in enumerate(c_set):
            if colour == 'R':
                datasets[dataset]['R'].append(n_set[idx])
            elif colour == 'G':
                datasets[dataset]['G'].append(n_set[idx])
            elif colour == 'B':
                datasets[dataset]['B'].append(n_set[idx])

        match_count = int()

        for rgb_key in datasets[dataset]:
            nums = ''.join(str(num) for num in sorted(datasets[dataset][rgb_key]))

            for hand in WINNING_HANDS:
                if hand in nums:
                    match_count += 1
                    nums.replace(hand, '')
                    if match_count == 3:
                        results.append(1)
                        continue

        if dataset < num_of_datasets-1 and match_count != 3:
            results.append(0)

    for result in results:
        print(result)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3

import sys


def main():
    WINNING_HANDS = [
                '111', '222', '333', '444', '555', '666', '777', '888', '999',
                '123', '234', '345', '456', '567', '678', '789'
            ]

    num_of_datasets = int(sys.stdin.readline().strip('\n'))
    datasets = [{'R': [], 'G': [], 'B': []} for _ in range(num_of_datasets)]
    results = list()

    for dataset in range(num_of_datasets):
        n_set = [num for num in sys.stdin.readline().strip('\n').split()]
        c_set = [colour for colour in sys.stdin.readline().strip('\n').split()]
        for idx, colour in enumerate(c_set):
            if colour == 'R':
                datasets[dataset]['R'].append(n_set[idx])
            elif colour == 'G':
                datasets[dataset]['G'].append(n_set[idx])
            elif colour == 'B':
                datasets[dataset]['B'].append(n_set[idx])

        match_count = int()

        for rgb_key in datasets[dataset]:
            nums = sorted(datasets[dataset][rgb_key])

            for hand in WINNING_HANDS:
                if hand in ''.join(nums):
                    match_count += 1
                    for digit in hand:
                        nums.pop(nums.index(digit))
                    if match_count == 3:
                        results.append(1)
                        continue

        if dataset < num_of_datasets-1 and match_count != 3:
            results.append(0)

    for result in results:
        print(result)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3

import sys


def main():
    WINNING_HANDS = [
                '111', '222', '333', '444', '555', '666', '777', '888', '999',
                '123', '234', '345', '456', '567', '678', '789'
            ]

    num_of_datasets = int(sys.stdin.readline().strip('\n'))
    datasets = [{'R': [], 'G': [], 'B': []} for _ in range(num_of_datasets)]
    results = list()

    for dataset in range(num_of_datasets):
        n_set = [num for num in sys.stdin.readline().strip('\n').split()]
        c_set = [colour for colour in sys.stdin.readline().strip('\n').split()]
        for idx, colour in enumerate(c_set):
            if colour == 'R':
                datasets[dataset]['R'].append(n_set[idx])
            elif colour == 'G':
                datasets[dataset]['G'].append(n_set[idx])
            elif colour == 'B':
                datasets[dataset]['B'].append(n_set[idx])

        match_count = int()

        for rgb_key in datasets[dataset]:
            nums = sorted(datasets[dataset][rgb_key])

            for hand in WINNING_HANDS:
                if int(hand[0]) and int(hand[1]) and int(hand[2]) in nums:
                    match_count += 1
                    nums.pop(nums.index(int(hand[0])))
                    nums.pop(nums.index(int(hand[1])))
                    nums.pop(nums.index(int(hand[2])))
                    if match_count == 3:
                        results.append(1)
                        continue

        if dataset < num_of_datasets-1 and match_count != 3:
            results.append(0)

    for result in results:
        print(result)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3

import sys


def main():
    WINNING_HANDS = [
                '111', '222', '333', '444', '555', '666', '777', '888', '999',
                '123', '234', '345', '456', '567', '678', '789'
            ]

    num_of_datasets = int(sys.stdin.readline().strip('\n'))
    datasets = [{'R': [], 'G': [], 'B': []} for _ in range(num_of_datasets)]
    results = list()

    for dataset in range(num_of_datasets):
        n_set = [num for num in sys.stdin.readline().strip('\n').split()]
        c_set = [colour for colour in sys.stdin.readline().strip('\n').split()]
        for idx, colour in enumerate(c_set):
            if colour == 'R':
                datasets[dataset]['R'].append(n_set[idx])
            elif colour == 'G':
                datasets[dataset]['G'].append(n_set[idx])
            elif colour == 'B':
                datasets[dataset]['B'].append(n_set[idx])

        match_count = int()

        for rgb_key in datasets[dataset]:
            nums = sorted(datasets[dataset][rgb_key])

            for hand in WINNING_HANDS:
                while hand[0] in nums and hand[1] in nums and hand[2] in nums:
                    tmp = nums.copy()
                    if hand[0] in tmp:
                        tmp.pop(tmp.index(hand[0]))
                        if hand[1] in tmp:
                            tmp.pop(tmp.index(hand[1]))
                            if hand[2] in tmp:
                                tmp.pop(tmp.index(hand[2]))
                                match_count += 1
                                nums = tmp
                            else:
                                break
                        else:
                            break
                    else:
                        break

                    if match_count == 3:
                        results.append(1)
                        continue

        if dataset < num_of_datasets-1 and match_count != 3:
            results.append(0)

    for result in results:
        print(result)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3

import sys


def main():
    WINNING_HANDS = [
                '111', '222', '333', '444', '555', '666', '777', '888', '999',
                '123', '234', '345', '456', '567', '678', '789'
            ]

    num_of_datasets = int(sys.stdin.readline().strip('\n'))
    datasets = [{'R': [], 'G': [], 'B': []} for _ in range(num_of_datasets)]
    results = list()

    for dataset in range(num_of_datasets):
        n_set = [num for num in sys.stdin.readline().strip('\n').split()]
        c_set = [colour for colour in sys.stdin.readline().strip('\n').split()]
        for idx, colour in enumerate(c_set):
            if colour == 'R':
                datasets[dataset]['R'].append(n_set[idx])
            elif colour == 'G':
                datasets[dataset]['G'].append(n_set[idx])
            elif colour == 'B':
                datasets[dataset]['B'].append(n_set[idx])

        match_count = int()

        for rgb_key in datasets[dataset]:
            nums = sorted(datasets[dataset][rgb_key])

            for hand in WINNING_HANDS:
                print(hand)
                while hand[0] in nums and hand[1] in nums and hand[2] in nums:
                    tmp = nums.copy()
                    if hand[0] in tmp:
                        tmp.pop(tmp.index(hand[0]))
                        if hand[1] in tmp:
                            tmp.pop(tmp.index(hand[1]))
                            if hand[2] in tmp:
                                tmp.pop(tmp.index(hand[2]))
                                match_count += 1
                                nums = tmp
                            else:
                                break
                        else:
                            break
                    else:
                        break

                    if match_count == 3:
                        results.append(1)
                        break

        if dataset < num_of_datasets and match_count != 3:
            results.append(0)

    for result in results:
        print(result)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3

import sys


def main():
    WINNING_HANDS = [
                '111', '222', '333', '444', '555', '666', '777', '888', '999',
                '123', '234', '345', '456', '567', '678', '789'
            ]

    num_of_datasets = int(sys.stdin.readline().strip('\n'))
    datasets = [{'R': [], 'G': [], 'B': []} for _ in range(num_of_datasets)]
    results = list()

    for dataset in range(num_of_datasets):
        n_set = [num for num in sys.stdin.readline().strip('\n').split()]
        c_set = [colour for colour in sys.stdin.readline().strip('\n').split()]
        for idx, colour in enumerate(c_set):
            if colour == 'R':
                datasets[dataset]['R'].append(n_set[idx])
            elif colour == 'G':
                datasets[dataset]['G'].append(n_set[idx])
            elif colour == 'B':
                datasets[dataset]['B'].append(n_set[idx])

        match_count = int()

        for rgb_key in datasets[dataset]:
            nums = sorted(datasets[dataset][rgb_key])

            for hand in WINNING_HANDS:
                print(hand)
                while hand[0] in nums and hand[1] in nums and hand[2] in nums:
                    tmp = nums.copy()
                    if hand[0] in tmp:
                        tmp.pop(tmp.index(hand[0]))
                        if hand[1] in tmp:
                            tmp.pop(tmp.index(hand[1]))
                            if hand[2] in tmp:
                                tmp.pop(tmp.index(hand[2]))
                                match_count += 1
                                nums = tmp
                            else:
                                break
                        else:
                            break
                    else:
                        break

                    if match_count == 3:
                        results.append(1)
                        continue

        if dataset < num_of_datasets and match_count != 3:
            results.append(0)

    for result in results:
        print(result)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3

import sys


def main():
    WINNING_HANDS = [
                '111', '222', '333', '444', '555', '666', '777', '888', '999',
                '123', '234', '345', '456', '567', '678', '789'
            ]

    num_of_datasets = int(sys.stdin.readline().strip('\n'))
    datasets = [{'R': [], 'G': [], 'B': []} for _ in range(num_of_datasets)]
    results = list()

    for dataset in range(num_of_datasets):
        n_set = [num for num in sys.stdin.readline().strip('\n').split()]
        c_set = [colour for colour in sys.stdin.readline().strip('\n').split()]
        for idx, colour in enumerate(c_set):
            if colour == 'R':
                datasets[dataset]['R'].append(n_set[idx])
            elif colour == 'G':
                datasets[dataset]['G'].append(n_set[idx])
            elif colour == 'B':
                datasets[dataset]['B'].append(n_set[idx])

        match_count = int()

        for rgb_key in datasets[dataset]:
            if len(datasets[dataset][rgb_key]) > 1:
                nums = sorted(datasets[dataset][rgb_key])
            else:
                continue

            for hand in WINNING_HANDS:
                print(hand)
                while hand[0] in nums and hand[1] in nums and hand[2] in nums:
                    tmp = nums.copy()
                    if hand[0] in tmp:
                        tmp.pop(tmp.index(hand[0]))
                        if hand[1] in tmp:
                            tmp.pop(tmp.index(hand[1]))
                            if hand[2] in tmp:
                                tmp.pop(tmp.index(hand[2]))
                                match_count += 1
                                nums = tmp
                            else:
                                break
                        else:
                            break
                    else:
                        break

                    if match_count == 3:
                        results.append(1)
                        break

        if dataset < num_of_datasets and match_count != 3:
            results.append(0)

    for result in results:
        print(result)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3

import sys


def main():
    WINNING_HANDS = [
                '111', '222', '333', '444', '555', '666', '777', '888', '999',
                '123', '234', '345', '456', '567', '678', '789'
            ]

    num_of_datasets = int(sys.stdin.readline().strip('\n'))
    datasets = [{'R': [], 'G': [], 'B': []} for _ in range(num_of_datasets)]
    results = list()

    for dataset in range(num_of_datasets):
        n_set = [num for num in sys.stdin.readline().strip('\n').split()]
        c_set = [colour for colour in sys.stdin.readline().strip('\n').split()]
        for idx, colour in enumerate(c_set):
            if colour == 'R':
                datasets[dataset]['R'].append(n_set[idx])
            elif colour == 'G':
                datasets[dataset]['G'].append(n_set[idx])
            elif colour == 'B':
                datasets[dataset]['B'].append(n_set[idx])

        match_count = int()

        for rgb_key in datasets[dataset]:
            if len(datasets[dataset][rgb_key]) > 1:
                nums = sorted(datasets[dataset][rgb_key])
            else:
                continue

            for hand in WINNING_HANDS:
                print(hand)
                while hand[0] in nums and hand[1] in nums and hand[2] in nums:
                    tmp = nums.copy()
                    if hand[0] in tmp:
                        tmp.pop(tmp.index(hand[0]))
                        if hand[1] in tmp:
                            tmp.pop(tmp.index(hand[1]))
                            if hand[2] in tmp:
                                tmp.pop(tmp.index(hand[2]))
                                match_count += 1
                                nums = tmp
                            else:
                                break
                        else:
                            break
                    else:
                        break

                if match_count == 3:
                    results.append(1)
                    break

        if dataset < num_of_datasets and match_count != 3:
            results.append(0)

    for result in results:
        print(result)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
for j in range(n):
    num = list(map(int, input().split()))
    let = input().split()
    lstR = []
    lstG = []
    lstB = []
    for i in range(9):
        if let[i] == "R":
            lstR.append(num[i])
        elif let[i] == "G":
            lstG.append(num[i])
        else:
            lstB.append(num[i])
    lstR.sort()
    lstG.sort()
    lstB.sort()
    lst = [lstR, lstG, lstB]
    ans = 1
    if len(lstR)%3 == 0 and len(lstG)%3 == 0 and len(lstB)%3 == 0:
        for k in range(3):
            if len(lst[k]) == 0:
                ans *= 1
            elif len(lst[k]) == 3 and lst[k][2] - lst[k][0] == 2:
                ans *= 1
            elif len(lst[k]) == 6 and lst[k][2] - lst[k][0] == 2 and lst[k][5] - lst[k][3] == 2:
                ans *= 1
            elif len(lst[k]) == 9 and lst[k][2] - lst[k][0] == 2 and lst[k][5] - lst[k][3] == 2 and lst[k][8] - lst[k][6] == 2:
                ans *= 1
            elif len(lst[k])%3 == 0 and lst[k][-1] == lst[k][0]:
                ans *= 1
            else:
                ans *= 0
    else:
        ans *= 0

    print(ans)

Submission status: Wrong Answer

Solution code:
#rummy
T=int(input())
for i in range(T):
    n=[int(i) for i in input().split()]
    c=[i for i in input().split()]
    R=[[],[],[]]
    for i in range(9):
        if c[i]=="R":
            R[0].append(n[i])
        elif c[i]=="G":
            R[1].append(n[i])
        else:
            R[2].append(n[i])
    y=1
    i=0
    while y>0 and i<3:
        l=len(R[i])
        if l%3!=0:
            y=0
        else:
            R[i].sort()
            s=l//3
            j=0
            while y>0 and s>0 and j<l-2:
                if R[i][j]==R[i][j+1]:
                    if R[i][j+1]!=R[i][j+2]:
                        y=0
                    else:
                        s-=1
                        j+=3
                elif R[i][j]+1!=R[i][j+1]:
                    y=0
                elif R[i][j+1]+1!=R[i][j+2]:
                    y=0
                else:
                    s-=1
                    j+=3
        i+=1
    print(y)

Submission status: Wrong Answer

Solution code:
T = int(input())
for i in range(T):
    n = [int(i) for i in input().split()]
    c = [i for i in input().split()]
    value = [[],[],[]]
    for j in range(9):
        if c[j] == "R":
            value[0].append(n[j])
        elif c[j] == "G":
            value[1].append(n[j])
        else:
            value[2].append(n[j])
    print(value)
    ans = 1
for i in range(3):
    l = len(value[i])
    if l%3 != 0:#RGBの長さが3の倍数でないと、正解になる可能性はない
        ans = 0
    else:
        value[i].sort()
        s = l//3
        print(i,s,value[i])
        j=0
        while ans>0 and s>0 and j<len(value[i])-2:
            if value[i][j] == value[i][j+1]:#隣り合う数字が一致している場合
                print("二つ並んでる")
                if value[i][j+1] == value[i][j+2]:#3連続で同じ数字が並んでいる場合
                    for k in range(3):
                        value[i].pop(j)#値の削除
                    s-=1
                elif value[i][j+1]+1==value[i][j+2]:#2つめの数字と3つ目の数字が連番　ex)112,223,334,
                    print(value[i][j+1]+1)
                    k=j+3
                    while k<len(value[i]) and value[i][k]==value[i][j+2]:#3つめと4つめの値が同じ
                        k+=1
                    if k>=len(value[i]) or value[i][k]!=value[i][j+2]+1:#4つ目と5つ目の数字が連番でない場合 ex)11225,22335　不正解
                        ans=0
                    else:
                        #値削除
                        value[i].pop(k)
                        value[i].pop(j+2)
                        value[i].pop(j)
                    s-=1
                else:#3つ目の数字が全然違うやつ
                    ans=0

            elif value[i][j]+1==value[i][j+1]:#隣り合う数字が連番の場合
                k=j+2
                while k<len(value[i]) and value[i][k]==value[i][j+1]:
                    k+=1
                if k>=len(value[i]) or value[i][k]!=value[i][j+1]+1:#3つめの数字が連番でない場合　不正解
                    ans=0
                else:
                    #値削除
                    value[i].pop(k)
                    value[i].pop(j+1)
                    value[i].pop(j)
                    s-=1
            else:#隣り合う数字が連番でもなく、同値でもない場合　不正解
                ans=0
    i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
T = int(input())
for i in range(T):
    n = [int(i) for i in input().split()]
    c = [i for i in input().split()]
    value = [[],[],[]]
    for j in range(9):
        if c[j] == "R":
            value[0].append(n[j])
        elif c[j] == "G":
            value[1].append(n[j])
        else:
            value[2].append(n[j])
    ans = 1
for i in range(3):
    l = len(value[i])
    if l%3 != 0:#RGBの長さが3の倍数でないと、正解になる可能性はない
        ans = 0
    else:
        value[i].sort()
        s = l//3
        j=0
        while ans>0 and s>0 and j<len(value[i])-2:
            if value[i][j] == value[i][j+1]:#隣り合う数字が一致している場合
                if value[i][j+1] == value[i][j+2]:#3連続で同じ数字が並んでいる場合
                    for k in range(3):
                        value[i].pop(j)#値の削除
                    s-=1
                elif value[i][j+1]+1==value[i][j+2]:#2つめの数字と3つ目の数字が連番　ex)112,223,334,
                    k=j+3
                    while k<len(value[i]) and value[i][k]==value[i][j+2]:#3つめと4つめの値が同じ
                        k+=1
                    if k>=len(value[i]) or value[i][k]!=value[i][j+2]+1:#4つ目と5つ目の数字が連番でない場合 ex)11225,22335　不正解
                        ans=0
                    else:
                        #値削除
                        value[i].pop(k)
                        value[i].pop(j+2)
                        value[i].pop(j)
                    s-=1
                else:#3つ目の数字が全然違うやつ
                    ans=0

            elif value[i][j]+1==value[i][j+1]:#隣り合う数字が連番の場合
                k=j+2
                while k<len(value[i]) and value[i][k]==value[i][j+1]:
                    k+=1
                if k>=len(value[i]) or value[i][k]!=value[i][j+1]+1:#3つめの数字が連番でない場合　不正解
                    ans=0
                else:
                    #値削除
                    value[i].pop(k)
                    value[i].pop(j+1)
                    value[i].pop(j)
                    s-=1
            else:#隣り合う数字が連番でもなく、同値でもない場合　不正解
                ans=0
    i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
def sort(a):
    temp = 0
    for i in range(a-1):
        if a[i] > a[i+1]:
            temp = a[i]
            a[i] = a[i+1]
            a[i+1] = temp
    return a


T = int(input())
count = 0
a = []
b = [[] for j in range(T)]
answer = [[False for i in range(3)] for j in range(T)]
for i in range(2*T):
    a.append(list(input().split()))
for i in range(T):
    for j in range(9):
        a[i*2][j] = int(a[i*2][j])
for i in range(T):
    for j in range(9):
        if a[2*i+1][j] == "R":
            a[2*i][j] = a[2*i][j] + 10
        if a[2*i+1][j] == "G":
            a[2*i][j] = a[2*i][j] + 20
        if a[2*i+1][j] == "B":
            a[2*i][j] = a[2*i][j] + 30
        b[i].append(a[2*i][j])
for j in range(T):
    for k in range(9):
        for i in range(8):
            temp = 0
            if b[j][i] > b[j][i+1]:
                temp = b[j][i]
                b[j][i] = b[j][i+1]
                b[j][i+1] = temp
for i in range(T):
    for j in range(3):
        if ((b[i][3*j] == b[i][3*j+1]) and (b[i][3*j] == b[i][3*j+2])) or ((b[i][3*j]+1 == b[i][3*j+1]) and (b[i][3*j]+2 == b[i][3*j+2])):
                answer[i][j] = True
    if answer[i][0] and answer[i][1] and answer[i][2]:
        print(1)
    else:
        print(0)