message stringlengths 2 67k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 463 109k | cluster float64 19 19 | __index_level_0__ int64 926 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that were adjacent with the removed number. If the number doesn't have an adjacent number to the left or right, Artem doesn't get any points.
After the element is removed, the two parts of the array glue together resulting in the new array that Artem continues playing with. Borya wondered what maximum total number of points Artem can get as he plays this game.
Input
The first line contains a single integer n (1 ≤ n ≤ 5·105) — the number of elements in the array. The next line contains n integers ai (1 ≤ ai ≤ 106) — the values of the array elements.
Output
In a single line print a single integer — the maximum number of points Artem can get.
Examples
Input
5
3 1 5 2 6
Output
11
Input
5
1 2 3 4 5
Output
6
Input
5
1 100 101 100 1
Output
102
Submitted Solution:
```
n=input()
a=input()
this=a.split()
vals=[0]
for item in this:
vals.append(int(item))
vals.append(0)
count=0
while len(vals)>2:
mins=[0]
i=1
while i<len(vals)-1:
mins.append(min(vals[i-1],vals[i+1]))
i+=1
mins.append(0)
x=mins.index(max(mins))
vals.pop(x)
count+=max(mins)
mins.pop(x)
print(count)
``` | instruction | 0 | 77,825 | 19 | 155,650 |
No | output | 1 | 77,825 | 19 | 155,651 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that were adjacent with the removed number. If the number doesn't have an adjacent number to the left or right, Artem doesn't get any points.
After the element is removed, the two parts of the array glue together resulting in the new array that Artem continues playing with. Borya wondered what maximum total number of points Artem can get as he plays this game.
Input
The first line contains a single integer n (1 ≤ n ≤ 5·105) — the number of elements in the array. The next line contains n integers ai (1 ≤ ai ≤ 106) — the values of the array elements.
Output
In a single line print a single integer — the maximum number of points Artem can get.
Examples
Input
5
3 1 5 2 6
Output
11
Input
5
1 2 3 4 5
Output
6
Input
5
1 100 101 100 1
Output
102
Submitted Solution:
```
n = int(input())
s = []
ans = 0;
num = input().split()
for i in range(0, n):
while (len(s) >= 2 and min(s[-2], i) >= s[-1]):
ans += min(int(num[i]), s[-2])
del(s[-1])
s.append(int(num[i]))
s.sort()
for i in range(0, len(s) - 2):
ans += s[i]
print(ans)
``` | instruction | 0 | 77,826 | 19 | 155,652 |
No | output | 1 | 77,826 | 19 | 155,653 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that were adjacent with the removed number. If the number doesn't have an adjacent number to the left or right, Artem doesn't get any points.
After the element is removed, the two parts of the array glue together resulting in the new array that Artem continues playing with. Borya wondered what maximum total number of points Artem can get as he plays this game.
Input
The first line contains a single integer n (1 ≤ n ≤ 5·105) — the number of elements in the array. The next line contains n integers ai (1 ≤ ai ≤ 106) — the values of the array elements.
Output
In a single line print a single integer — the maximum number of points Artem can get.
Examples
Input
5
3 1 5 2 6
Output
11
Input
5
1 2 3 4 5
Output
6
Input
5
1 100 101 100 1
Output
102
Submitted Solution:
```
n=int(input())
mas=list(map(int, input().split()))
sum=0
if n>2:
while n>3:
m=0
for i in range(1,len(mas)-1):
j=10000001
minim=min(mas[i-1],mas[i+1])
if minim>m:
m=minim
index=i
j=mas[i]
elif minim==m and mas[i]<j:
index=i
j=mas[i]
mas.pop(index)
n-=1
sum+=m
sum+=min(mas[0],mas[2])
print(sum)
``` | instruction | 0 | 77,827 | 19 | 155,654 |
No | output | 1 | 77,827 | 19 | 155,655 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka got a six-faced dice. It has integer numbers from 2 to 7 written on its faces (all numbers on faces are different, so this is an almost usual dice).
Mishka wants to get exactly x points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the rolls Mishka makes.
Mishka doesn't really care about the number of rolls, so he just wants to know any number of rolls he can make to be able to get exactly x points for them. Mishka is very lucky, so if the probability to get x points with chosen number of rolls is non-zero, he will be able to roll the dice in such a way. Your task is to print this number. It is guaranteed that at least one answer exists.
Mishka is also very curious about different number of points to score so you have to answer t independent queries.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of queries.
Each of the next t lines contains one integer each. The i-th line contains one integer x_i (2 ≤ x_i ≤ 100) — the number of points Mishka wants to get.
Output
Print t lines. In the i-th line print the answer to the i-th query (i.e. any number of rolls Mishka can make to be able to get exactly x_i points for them). It is guaranteed that at least one answer exists.
Example
Input
4
2
13
37
100
Output
1
3
8
27
Note
In the first query Mishka can roll a dice once and get 2 points.
In the second query Mishka can roll a dice 3 times and get points 5, 5 and 3 (for example).
In the third query Mishka can roll a dice 8 times and get 5 points 7 times and 2 points with the remaining roll.
In the fourth query Mishka can roll a dice 27 times and get 2 points 11 times, 3 points 6 times and 6 points 10 times. | instruction | 0 | 78,307 | 19 | 156,614 |
Tags: math
Correct Solution:
```
t = int(input())
while(t):
print((int(input())+6) // 7)
t -= 1
``` | output | 1 | 78,307 | 19 | 156,615 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka got a six-faced dice. It has integer numbers from 2 to 7 written on its faces (all numbers on faces are different, so this is an almost usual dice).
Mishka wants to get exactly x points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the rolls Mishka makes.
Mishka doesn't really care about the number of rolls, so he just wants to know any number of rolls he can make to be able to get exactly x points for them. Mishka is very lucky, so if the probability to get x points with chosen number of rolls is non-zero, he will be able to roll the dice in such a way. Your task is to print this number. It is guaranteed that at least one answer exists.
Mishka is also very curious about different number of points to score so you have to answer t independent queries.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of queries.
Each of the next t lines contains one integer each. The i-th line contains one integer x_i (2 ≤ x_i ≤ 100) — the number of points Mishka wants to get.
Output
Print t lines. In the i-th line print the answer to the i-th query (i.e. any number of rolls Mishka can make to be able to get exactly x_i points for them). It is guaranteed that at least one answer exists.
Example
Input
4
2
13
37
100
Output
1
3
8
27
Note
In the first query Mishka can roll a dice once and get 2 points.
In the second query Mishka can roll a dice 3 times and get points 5, 5 and 3 (for example).
In the third query Mishka can roll a dice 8 times and get 5 points 7 times and 2 points with the remaining roll.
In the fourth query Mishka can roll a dice 27 times and get 2 points 11 times, 3 points 6 times and 6 points 10 times. | instruction | 0 | 78,308 | 19 | 156,616 |
Tags: math
Correct Solution:
```
a=int(input())
for i in range(0,a):
b=int(input())
c=b//7+1
print(c)
``` | output | 1 | 78,308 | 19 | 156,617 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka got a six-faced dice. It has integer numbers from 2 to 7 written on its faces (all numbers on faces are different, so this is an almost usual dice).
Mishka wants to get exactly x points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the rolls Mishka makes.
Mishka doesn't really care about the number of rolls, so he just wants to know any number of rolls he can make to be able to get exactly x points for them. Mishka is very lucky, so if the probability to get x points with chosen number of rolls is non-zero, he will be able to roll the dice in such a way. Your task is to print this number. It is guaranteed that at least one answer exists.
Mishka is also very curious about different number of points to score so you have to answer t independent queries.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of queries.
Each of the next t lines contains one integer each. The i-th line contains one integer x_i (2 ≤ x_i ≤ 100) — the number of points Mishka wants to get.
Output
Print t lines. In the i-th line print the answer to the i-th query (i.e. any number of rolls Mishka can make to be able to get exactly x_i points for them). It is guaranteed that at least one answer exists.
Example
Input
4
2
13
37
100
Output
1
3
8
27
Note
In the first query Mishka can roll a dice once and get 2 points.
In the second query Mishka can roll a dice 3 times and get points 5, 5 and 3 (for example).
In the third query Mishka can roll a dice 8 times and get 5 points 7 times and 2 points with the remaining roll.
In the fourth query Mishka can roll a dice 27 times and get 2 points 11 times, 3 points 6 times and 6 points 10 times. | instruction | 0 | 78,309 | 19 | 156,618 |
Tags: math
Correct Solution:
```
import os
import heapq
import sys,threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10**5)
from io import BytesIO, IOBase
def gcd(a,b):
if b==0:
return a
else:
return gcd(b,a%b)
def power(x, p,m):
res = 1
while p:
if p & 1:
res = (res * x) % m
x = (x * x) % m
p >>= 1
return res
def inar():
return [int(k) for k in input().split()]
def lcm(num1,num2):
return (num1*num2)//gcd(num1,num2)
# Python3 function to
# calculate nCr % p
def ncr(n, r, p):
# initialize numerator
# and denominator
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den,
p - 2, p)) % p
# p must be a prime
# greater than n
# n, r, p = 10, 2, 13
# print("Value of nCr % p is",
# ncr(n, r, p))
def check(n,m,arr):
c1,c2=1,1
for i in range(n):
for j in range(1,m):
if arr[i][j]>arr[i][j-1]:
continue
else:
c1=0
break
for i in range(m):
for j in range(1,n):
if arr[j][i]>arr[j-1][i]:
continue
else:
c2=0
break
if c1 and c2:
return True
else:
return False
def main():
for _ in range(int(input())):
n=int(input())
print(n//2)
# n,m=inar()
# arr1=[]
# arr2=[]
# for i in range(n):
# take=inar()
# arr1.append(take)
# for i in range(n):
# take=inar()
# arr2.append(take)
# # print(arr1)
# for i in range(n):
# for j in range(m):
# mn=min(arr1[i][j],arr2[i][j])
# mx=max(arr1[i][j],arr2[i][j])
# arr1[i][j],arr2[i][j]=mn,mx
# if check(n,m,arr1) and check(n,m,arr2):
# print("Possible")
# else:
# print("Impossible")
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
#threadin.Thread(target=main).start()
``` | output | 1 | 78,309 | 19 | 156,619 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka got a six-faced dice. It has integer numbers from 2 to 7 written on its faces (all numbers on faces are different, so this is an almost usual dice).
Mishka wants to get exactly x points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the rolls Mishka makes.
Mishka doesn't really care about the number of rolls, so he just wants to know any number of rolls he can make to be able to get exactly x points for them. Mishka is very lucky, so if the probability to get x points with chosen number of rolls is non-zero, he will be able to roll the dice in such a way. Your task is to print this number. It is guaranteed that at least one answer exists.
Mishka is also very curious about different number of points to score so you have to answer t independent queries.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of queries.
Each of the next t lines contains one integer each. The i-th line contains one integer x_i (2 ≤ x_i ≤ 100) — the number of points Mishka wants to get.
Output
Print t lines. In the i-th line print the answer to the i-th query (i.e. any number of rolls Mishka can make to be able to get exactly x_i points for them). It is guaranteed that at least one answer exists.
Example
Input
4
2
13
37
100
Output
1
3
8
27
Note
In the first query Mishka can roll a dice once and get 2 points.
In the second query Mishka can roll a dice 3 times and get points 5, 5 and 3 (for example).
In the third query Mishka can roll a dice 8 times and get 5 points 7 times and 2 points with the remaining roll.
In the fourth query Mishka can roll a dice 27 times and get 2 points 11 times, 3 points 6 times and 6 points 10 times. | instruction | 0 | 78,310 | 19 | 156,620 |
Tags: math
Correct Solution:
```
n = int(input())
hasil = []
for i in range (n):
a = int(input())
hasil += [a // 2]
for i in (hasil):
print (i)
``` | output | 1 | 78,310 | 19 | 156,621 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka got a six-faced dice. It has integer numbers from 2 to 7 written on its faces (all numbers on faces are different, so this is an almost usual dice).
Mishka wants to get exactly x points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the rolls Mishka makes.
Mishka doesn't really care about the number of rolls, so he just wants to know any number of rolls he can make to be able to get exactly x points for them. Mishka is very lucky, so if the probability to get x points with chosen number of rolls is non-zero, he will be able to roll the dice in such a way. Your task is to print this number. It is guaranteed that at least one answer exists.
Mishka is also very curious about different number of points to score so you have to answer t independent queries.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of queries.
Each of the next t lines contains one integer each. The i-th line contains one integer x_i (2 ≤ x_i ≤ 100) — the number of points Mishka wants to get.
Output
Print t lines. In the i-th line print the answer to the i-th query (i.e. any number of rolls Mishka can make to be able to get exactly x_i points for them). It is guaranteed that at least one answer exists.
Example
Input
4
2
13
37
100
Output
1
3
8
27
Note
In the first query Mishka can roll a dice once and get 2 points.
In the second query Mishka can roll a dice 3 times and get points 5, 5 and 3 (for example).
In the third query Mishka can roll a dice 8 times and get 5 points 7 times and 2 points with the remaining roll.
In the fourth query Mishka can roll a dice 27 times and get 2 points 11 times, 3 points 6 times and 6 points 10 times. | instruction | 0 | 78,311 | 19 | 156,622 |
Tags: math
Correct Solution:
```
t=int(input())
for i in range(t):
n=int(input())
print(n//7+1)
``` | output | 1 | 78,311 | 19 | 156,623 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka got a six-faced dice. It has integer numbers from 2 to 7 written on its faces (all numbers on faces are different, so this is an almost usual dice).
Mishka wants to get exactly x points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the rolls Mishka makes.
Mishka doesn't really care about the number of rolls, so he just wants to know any number of rolls he can make to be able to get exactly x points for them. Mishka is very lucky, so if the probability to get x points with chosen number of rolls is non-zero, he will be able to roll the dice in such a way. Your task is to print this number. It is guaranteed that at least one answer exists.
Mishka is also very curious about different number of points to score so you have to answer t independent queries.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of queries.
Each of the next t lines contains one integer each. The i-th line contains one integer x_i (2 ≤ x_i ≤ 100) — the number of points Mishka wants to get.
Output
Print t lines. In the i-th line print the answer to the i-th query (i.e. any number of rolls Mishka can make to be able to get exactly x_i points for them). It is guaranteed that at least one answer exists.
Example
Input
4
2
13
37
100
Output
1
3
8
27
Note
In the first query Mishka can roll a dice once and get 2 points.
In the second query Mishka can roll a dice 3 times and get points 5, 5 and 3 (for example).
In the third query Mishka can roll a dice 8 times and get 5 points 7 times and 2 points with the remaining roll.
In the fourth query Mishka can roll a dice 27 times and get 2 points 11 times, 3 points 6 times and 6 points 10 times. | instruction | 0 | 78,312 | 19 | 156,624 |
Tags: math
Correct Solution:
```
n=int(input())
for x in range(n):
a=int(input())
if a%7!=0 :
print(a//7+1)
else:
print(a//7)
``` | output | 1 | 78,312 | 19 | 156,625 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka got a six-faced dice. It has integer numbers from 2 to 7 written on its faces (all numbers on faces are different, so this is an almost usual dice).
Mishka wants to get exactly x points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the rolls Mishka makes.
Mishka doesn't really care about the number of rolls, so he just wants to know any number of rolls he can make to be able to get exactly x points for them. Mishka is very lucky, so if the probability to get x points with chosen number of rolls is non-zero, he will be able to roll the dice in such a way. Your task is to print this number. It is guaranteed that at least one answer exists.
Mishka is also very curious about different number of points to score so you have to answer t independent queries.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of queries.
Each of the next t lines contains one integer each. The i-th line contains one integer x_i (2 ≤ x_i ≤ 100) — the number of points Mishka wants to get.
Output
Print t lines. In the i-th line print the answer to the i-th query (i.e. any number of rolls Mishka can make to be able to get exactly x_i points for them). It is guaranteed that at least one answer exists.
Example
Input
4
2
13
37
100
Output
1
3
8
27
Note
In the first query Mishka can roll a dice once and get 2 points.
In the second query Mishka can roll a dice 3 times and get points 5, 5 and 3 (for example).
In the third query Mishka can roll a dice 8 times and get 5 points 7 times and 2 points with the remaining roll.
In the fourth query Mishka can roll a dice 27 times and get 2 points 11 times, 3 points 6 times and 6 points 10 times. | instruction | 0 | 78,313 | 19 | 156,626 |
Tags: math
Correct Solution:
```
#!usr/bin/python3
dice_nums = [2, 3, 4, 5, 6, 7]
def number_of_rolls(x):
for i in dice_nums[::-1]:
if not x%i:
return(int(x/i))
return(int((x-3)/2))
n = int(input())
for _ in range(n):
print(number_of_rolls(int(input())))
``` | output | 1 | 78,313 | 19 | 156,627 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mishka got a six-faced dice. It has integer numbers from 2 to 7 written on its faces (all numbers on faces are different, so this is an almost usual dice).
Mishka wants to get exactly x points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the rolls Mishka makes.
Mishka doesn't really care about the number of rolls, so he just wants to know any number of rolls he can make to be able to get exactly x points for them. Mishka is very lucky, so if the probability to get x points with chosen number of rolls is non-zero, he will be able to roll the dice in such a way. Your task is to print this number. It is guaranteed that at least one answer exists.
Mishka is also very curious about different number of points to score so you have to answer t independent queries.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of queries.
Each of the next t lines contains one integer each. The i-th line contains one integer x_i (2 ≤ x_i ≤ 100) — the number of points Mishka wants to get.
Output
Print t lines. In the i-th line print the answer to the i-th query (i.e. any number of rolls Mishka can make to be able to get exactly x_i points for them). It is guaranteed that at least one answer exists.
Example
Input
4
2
13
37
100
Output
1
3
8
27
Note
In the first query Mishka can roll a dice once and get 2 points.
In the second query Mishka can roll a dice 3 times and get points 5, 5 and 3 (for example).
In the third query Mishka can roll a dice 8 times and get 5 points 7 times and 2 points with the remaining roll.
In the fourth query Mishka can roll a dice 27 times and get 2 points 11 times, 3 points 6 times and 6 points 10 times. | instruction | 0 | 78,314 | 19 | 156,628 |
Tags: math
Correct Solution:
```
T = int(input())
for i in range(0, T):
x = int(input())
if (x%3 == 0):
roll = x//3
else:
roll = x//3 + 1
print(roll)
``` | output | 1 | 78,314 | 19 | 156,629 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka got a six-faced dice. It has integer numbers from 2 to 7 written on its faces (all numbers on faces are different, so this is an almost usual dice).
Mishka wants to get exactly x points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the rolls Mishka makes.
Mishka doesn't really care about the number of rolls, so he just wants to know any number of rolls he can make to be able to get exactly x points for them. Mishka is very lucky, so if the probability to get x points with chosen number of rolls is non-zero, he will be able to roll the dice in such a way. Your task is to print this number. It is guaranteed that at least one answer exists.
Mishka is also very curious about different number of points to score so you have to answer t independent queries.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of queries.
Each of the next t lines contains one integer each. The i-th line contains one integer x_i (2 ≤ x_i ≤ 100) — the number of points Mishka wants to get.
Output
Print t lines. In the i-th line print the answer to the i-th query (i.e. any number of rolls Mishka can make to be able to get exactly x_i points for them). It is guaranteed that at least one answer exists.
Example
Input
4
2
13
37
100
Output
1
3
8
27
Note
In the first query Mishka can roll a dice once and get 2 points.
In the second query Mishka can roll a dice 3 times and get points 5, 5 and 3 (for example).
In the third query Mishka can roll a dice 8 times and get 5 points 7 times and 2 points with the remaining roll.
In the fourth query Mishka can roll a dice 27 times and get 2 points 11 times, 3 points 6 times and 6 points 10 times.
Submitted Solution:
```
n = int(input())
for i in range(0,n):
k = int(input())
if(k<=7):
print("1")
else:
print(int(k/7 +1))
``` | instruction | 0 | 78,315 | 19 | 156,630 |
Yes | output | 1 | 78,315 | 19 | 156,631 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka got a six-faced dice. It has integer numbers from 2 to 7 written on its faces (all numbers on faces are different, so this is an almost usual dice).
Mishka wants to get exactly x points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the rolls Mishka makes.
Mishka doesn't really care about the number of rolls, so he just wants to know any number of rolls he can make to be able to get exactly x points for them. Mishka is very lucky, so if the probability to get x points with chosen number of rolls is non-zero, he will be able to roll the dice in such a way. Your task is to print this number. It is guaranteed that at least one answer exists.
Mishka is also very curious about different number of points to score so you have to answer t independent queries.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of queries.
Each of the next t lines contains one integer each. The i-th line contains one integer x_i (2 ≤ x_i ≤ 100) — the number of points Mishka wants to get.
Output
Print t lines. In the i-th line print the answer to the i-th query (i.e. any number of rolls Mishka can make to be able to get exactly x_i points for them). It is guaranteed that at least one answer exists.
Example
Input
4
2
13
37
100
Output
1
3
8
27
Note
In the first query Mishka can roll a dice once and get 2 points.
In the second query Mishka can roll a dice 3 times and get points 5, 5 and 3 (for example).
In the third query Mishka can roll a dice 8 times and get 5 points 7 times and 2 points with the remaining roll.
In the fourth query Mishka can roll a dice 27 times and get 2 points 11 times, 3 points 6 times and 6 points 10 times.
Submitted Solution:
```
def solve(num):
ans = 0
for i in range(7, 1, -1):
while num - i > 1:
num -= i
ans += 1
return ans + 1
for _ in range(int(input())):
print(solve(int(input())))
``` | instruction | 0 | 78,316 | 19 | 156,632 |
Yes | output | 1 | 78,316 | 19 | 156,633 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka got a six-faced dice. It has integer numbers from 2 to 7 written on its faces (all numbers on faces are different, so this is an almost usual dice).
Mishka wants to get exactly x points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the rolls Mishka makes.
Mishka doesn't really care about the number of rolls, so he just wants to know any number of rolls he can make to be able to get exactly x points for them. Mishka is very lucky, so if the probability to get x points with chosen number of rolls is non-zero, he will be able to roll the dice in such a way. Your task is to print this number. It is guaranteed that at least one answer exists.
Mishka is also very curious about different number of points to score so you have to answer t independent queries.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of queries.
Each of the next t lines contains one integer each. The i-th line contains one integer x_i (2 ≤ x_i ≤ 100) — the number of points Mishka wants to get.
Output
Print t lines. In the i-th line print the answer to the i-th query (i.e. any number of rolls Mishka can make to be able to get exactly x_i points for them). It is guaranteed that at least one answer exists.
Example
Input
4
2
13
37
100
Output
1
3
8
27
Note
In the first query Mishka can roll a dice once and get 2 points.
In the second query Mishka can roll a dice 3 times and get points 5, 5 and 3 (for example).
In the third query Mishka can roll a dice 8 times and get 5 points 7 times and 2 points with the remaining roll.
In the fourth query Mishka can roll a dice 27 times and get 2 points 11 times, 3 points 6 times and 6 points 10 times.
Submitted Solution:
```
t = int(input())
for i in range(t):
x = int(input())
if (x%2)==0:
print(x//2)
else:
print(1 + (x-3)//2)
``` | instruction | 0 | 78,317 | 19 | 156,634 |
Yes | output | 1 | 78,317 | 19 | 156,635 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka got a six-faced dice. It has integer numbers from 2 to 7 written on its faces (all numbers on faces are different, so this is an almost usual dice).
Mishka wants to get exactly x points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the rolls Mishka makes.
Mishka doesn't really care about the number of rolls, so he just wants to know any number of rolls he can make to be able to get exactly x points for them. Mishka is very lucky, so if the probability to get x points with chosen number of rolls is non-zero, he will be able to roll the dice in such a way. Your task is to print this number. It is guaranteed that at least one answer exists.
Mishka is also very curious about different number of points to score so you have to answer t independent queries.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of queries.
Each of the next t lines contains one integer each. The i-th line contains one integer x_i (2 ≤ x_i ≤ 100) — the number of points Mishka wants to get.
Output
Print t lines. In the i-th line print the answer to the i-th query (i.e. any number of rolls Mishka can make to be able to get exactly x_i points for them). It is guaranteed that at least one answer exists.
Example
Input
4
2
13
37
100
Output
1
3
8
27
Note
In the first query Mishka can roll a dice once and get 2 points.
In the second query Mishka can roll a dice 3 times and get points 5, 5 and 3 (for example).
In the third query Mishka can roll a dice 8 times and get 5 points 7 times and 2 points with the remaining roll.
In the fourth query Mishka can roll a dice 27 times and get 2 points 11 times, 3 points 6 times and 6 points 10 times.
Submitted Solution:
```
for i in range(int(input())):
print((int(input())+3)//4)
``` | instruction | 0 | 78,318 | 19 | 156,636 |
Yes | output | 1 | 78,318 | 19 | 156,637 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka got a six-faced dice. It has integer numbers from 2 to 7 written on its faces (all numbers on faces are different, so this is an almost usual dice).
Mishka wants to get exactly x points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the rolls Mishka makes.
Mishka doesn't really care about the number of rolls, so he just wants to know any number of rolls he can make to be able to get exactly x points for them. Mishka is very lucky, so if the probability to get x points with chosen number of rolls is non-zero, he will be able to roll the dice in such a way. Your task is to print this number. It is guaranteed that at least one answer exists.
Mishka is also very curious about different number of points to score so you have to answer t independent queries.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of queries.
Each of the next t lines contains one integer each. The i-th line contains one integer x_i (2 ≤ x_i ≤ 100) — the number of points Mishka wants to get.
Output
Print t lines. In the i-th line print the answer to the i-th query (i.e. any number of rolls Mishka can make to be able to get exactly x_i points for them). It is guaranteed that at least one answer exists.
Example
Input
4
2
13
37
100
Output
1
3
8
27
Note
In the first query Mishka can roll a dice once and get 2 points.
In the second query Mishka can roll a dice 3 times and get points 5, 5 and 3 (for example).
In the third query Mishka can roll a dice 8 times and get 5 points 7 times and 2 points with the remaining roll.
In the fourth query Mishka can roll a dice 27 times and get 2 points 11 times, 3 points 6 times and 6 points 10 times.
Submitted Solution:
```
dice = [7,6,5,4,3,2]
for i in range(int(input())):
j = int(input())
cnt = 0
for n in dice:
while n<=j:
j-=n
cnt += 1
print(cnt)
``` | instruction | 0 | 78,319 | 19 | 156,638 |
No | output | 1 | 78,319 | 19 | 156,639 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka got a six-faced dice. It has integer numbers from 2 to 7 written on its faces (all numbers on faces are different, so this is an almost usual dice).
Mishka wants to get exactly x points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the rolls Mishka makes.
Mishka doesn't really care about the number of rolls, so he just wants to know any number of rolls he can make to be able to get exactly x points for them. Mishka is very lucky, so if the probability to get x points with chosen number of rolls is non-zero, he will be able to roll the dice in such a way. Your task is to print this number. It is guaranteed that at least one answer exists.
Mishka is also very curious about different number of points to score so you have to answer t independent queries.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of queries.
Each of the next t lines contains one integer each. The i-th line contains one integer x_i (2 ≤ x_i ≤ 100) — the number of points Mishka wants to get.
Output
Print t lines. In the i-th line print the answer to the i-th query (i.e. any number of rolls Mishka can make to be able to get exactly x_i points for them). It is guaranteed that at least one answer exists.
Example
Input
4
2
13
37
100
Output
1
3
8
27
Note
In the first query Mishka can roll a dice once and get 2 points.
In the second query Mishka can roll a dice 3 times and get points 5, 5 and 3 (for example).
In the third query Mishka can roll a dice 8 times and get 5 points 7 times and 2 points with the remaining roll.
In the fourth query Mishka can roll a dice 27 times and get 2 points 11 times, 3 points 6 times and 6 points 10 times.
Submitted Solution:
```
# https://vjudge.net/contest/319028#problem/F
n = int(input())
for i in range(n):
t = int(input())
result = 0
for i in range(7, 1, -1):
while t >= i:
t -= i
result += 1
if t == 1:
result += 1
print(result)
``` | instruction | 0 | 78,320 | 19 | 156,640 |
No | output | 1 | 78,320 | 19 | 156,641 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka got a six-faced dice. It has integer numbers from 2 to 7 written on its faces (all numbers on faces are different, so this is an almost usual dice).
Mishka wants to get exactly x points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the rolls Mishka makes.
Mishka doesn't really care about the number of rolls, so he just wants to know any number of rolls he can make to be able to get exactly x points for them. Mishka is very lucky, so if the probability to get x points with chosen number of rolls is non-zero, he will be able to roll the dice in such a way. Your task is to print this number. It is guaranteed that at least one answer exists.
Mishka is also very curious about different number of points to score so you have to answer t independent queries.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of queries.
Each of the next t lines contains one integer each. The i-th line contains one integer x_i (2 ≤ x_i ≤ 100) — the number of points Mishka wants to get.
Output
Print t lines. In the i-th line print the answer to the i-th query (i.e. any number of rolls Mishka can make to be able to get exactly x_i points for them). It is guaranteed that at least one answer exists.
Example
Input
4
2
13
37
100
Output
1
3
8
27
Note
In the first query Mishka can roll a dice once and get 2 points.
In the second query Mishka can roll a dice 3 times and get points 5, 5 and 3 (for example).
In the third query Mishka can roll a dice 8 times and get 5 points 7 times and 2 points with the remaining roll.
In the fourth query Mishka can roll a dice 27 times and get 2 points 11 times, 3 points 6 times and 6 points 10 times.
Submitted Solution:
```
pnum = []
n = int(input())
for i in range(n):
x = int(input())
c = 0
s = 0
if x >= 7:
c = x // 7
x -= c * 7
s += c
#####
if x >= 6:
c = x // 6
x -= c * 6
s += c
#####
if x >= 5:
c = x // 5
x -= c * 5
s += c
#####
if x >= 4:
c = x // 4
x -= c * 4
s += c
#####
if x >= 3:
c = x // 3
x -= c * 3
s += c
#####
if x >= 2:
c = x // 2
x -= c * 2
s += c
#print(s)
pnum.append(s)
for i in range(n):
print(pnum[i])
``` | instruction | 0 | 78,321 | 19 | 156,642 |
No | output | 1 | 78,321 | 19 | 156,643 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mishka got a six-faced dice. It has integer numbers from 2 to 7 written on its faces (all numbers on faces are different, so this is an almost usual dice).
Mishka wants to get exactly x points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the rolls Mishka makes.
Mishka doesn't really care about the number of rolls, so he just wants to know any number of rolls he can make to be able to get exactly x points for them. Mishka is very lucky, so if the probability to get x points with chosen number of rolls is non-zero, he will be able to roll the dice in such a way. Your task is to print this number. It is guaranteed that at least one answer exists.
Mishka is also very curious about different number of points to score so you have to answer t independent queries.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of queries.
Each of the next t lines contains one integer each. The i-th line contains one integer x_i (2 ≤ x_i ≤ 100) — the number of points Mishka wants to get.
Output
Print t lines. In the i-th line print the answer to the i-th query (i.e. any number of rolls Mishka can make to be able to get exactly x_i points for them). It is guaranteed that at least one answer exists.
Example
Input
4
2
13
37
100
Output
1
3
8
27
Note
In the first query Mishka can roll a dice once and get 2 points.
In the second query Mishka can roll a dice 3 times and get points 5, 5 and 3 (for example).
In the third query Mishka can roll a dice 8 times and get 5 points 7 times and 2 points with the remaining roll.
In the fourth query Mishka can roll a dice 27 times and get 2 points 11 times, 3 points 6 times and 6 points 10 times.
Submitted Solution:
```
for _ in range(int(input())):
n = int(input())
ans = 0
if(n%5 == 1):
ans = n//5
else:
ans = n//5 + 1
``` | instruction | 0 | 78,322 | 19 | 156,644 |
No | output | 1 | 78,322 | 19 | 156,645 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Petya are playing an online game. As most online games, it has hero progress system that allows players to gain experience that make their heroes stronger. Of course, Vasya would like to get as many experience points as possible. After careful study of experience points allocation, he found out that if he plays the game alone, he gets one experience point each second. However, if two players are playing together, and their current experience values differ by at most C points, they can boost their progress, and each of them gets 2 experience points each second.
Since Vasya and Petya are middle school students, their parents don't allow them to play all the day around. Each of the friends has his own schedule: Vasya can only play during intervals [a1;b1], [a2;b2], ..., [an;bn], and Petya can only play during intervals [c1;d1], [c2;d2], ..., [cm;dm]. All time periods are given in seconds from the current moment. Vasya is good in math, so he has noticed that sometimes it can be profitable not to play alone, because experience difference could become too big, and progress would not be boosted even when played together.
Now they would like to create such schedule of playing that Vasya's final experience was greatest possible. The current players experience is the same. Petya is not so concerned about his experience, so he is ready to cooperate and play when needed to maximize Vasya's experience.
Input
The first line of input data contains integers n, m and C — the number of intervals when Vasya can play, the number of intervals when Petya can play, and the maximal difference in experience level when playing together still gives a progress boost (1 ≤ n, m ≤ 2·105, 0 ≤ C ≤ 1018).
The following n lines contain two integers each: ai, bi — intervals when Vasya can play (0 ≤ ai < bi ≤ 1018, bi < ai + 1).
The following m lines contain two integers each: ci, di — intervals when Petya can play (0 ≤ ci < di ≤ 1018, di < ci + 1).
Output
Output one integer — the maximal experience that Vasya can have in the end, if both players try to maximize this value.
Examples
Input
2 1 5
1 7
10 20
10 20
Output
25
Input
1 2 5
0 100
20 60
85 90
Output
125
Submitted Solution:
```
n,m,C = input().strip().split()
(n,m,C) = (int(n),int(m),int(C))
Vasya = []
Petya = []
for item in range(0,n):
start,end = input().strip().split()
Vasya.append([int(start),int(end)])
for item in range(0,m):
start,end = input().strip().split()
Petya.append([int(start),int(end)])
same = 0
Vasya_before = 0
Vasya_after = 0
h = 0
for i in range(len(Vasya)):
while h < len(Petya):
if Vasya[i][0] > Petya[h][0] and Vasya[i][1] < Petya[h][1]:
same += Vasya[i][1]- Vasya[i][0]
Petya[h][0] = Vasya[i][1]
break
elif Vasya[i][1] < Petya[h][0]:
Vasya_before += Vasya[i][1]-Vasya[i][0]
break
elif Vasya[i][0] > Petya[h][1]:
h += 1
elif Vasya[i][1] > Petya[h][0] and Vasya[i][0] <= Petya[h][0]:
Vasya_before += Petya[h][0]-Vasya[i][0]
if Petya[h][1] < Vasya[i][1]:
same += Petya[h][1] - Petya[h][0]
Vasya[i][0] = Petya[h][1]
h += 1
elif Petya[h][1] == Vasya[i][1]:
same += Petya[h][1] - Vasya[i][0]
h += 1
elif Petya[h][1] > Vasya[i][1]:
same += Vasya[i][1]-Petya[h][0]
Petya[h][0] = Vasya[i][1]
break
elif Petya[h][1] > Vasya[i][0] and Petya[h][0] < Vasya[i][0]:
Vasya[i][0] = Petya[h][1]
same += Petya[h][1]-Vasya[i][0]
h += 1
if Vasya[n-1][0] >= Petya[m-1][1]:
Vasya_after += Vasya[n-1][1]-Vasya[n-1][0]
if Vasya_before > C:
Vasya_before = C
s = same*2 + Vasya_before + Vasya_after
print(s)
``` | instruction | 0 | 78,812 | 19 | 157,624 |
No | output | 1 | 78,812 | 19 | 157,625 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Petya are playing an online game. As most online games, it has hero progress system that allows players to gain experience that make their heroes stronger. Of course, Vasya would like to get as many experience points as possible. After careful study of experience points allocation, he found out that if he plays the game alone, he gets one experience point each second. However, if two players are playing together, and their current experience values differ by at most C points, they can boost their progress, and each of them gets 2 experience points each second.
Since Vasya and Petya are middle school students, their parents don't allow them to play all the day around. Each of the friends has his own schedule: Vasya can only play during intervals [a1;b1], [a2;b2], ..., [an;bn], and Petya can only play during intervals [c1;d1], [c2;d2], ..., [cm;dm]. All time periods are given in seconds from the current moment. Vasya is good in math, so he has noticed that sometimes it can be profitable not to play alone, because experience difference could become too big, and progress would not be boosted even when played together.
Now they would like to create such schedule of playing that Vasya's final experience was greatest possible. The current players experience is the same. Petya is not so concerned about his experience, so he is ready to cooperate and play when needed to maximize Vasya's experience.
Input
The first line of input data contains integers n, m and C — the number of intervals when Vasya can play, the number of intervals when Petya can play, and the maximal difference in experience level when playing together still gives a progress boost (1 ≤ n, m ≤ 2·105, 0 ≤ C ≤ 1018).
The following n lines contain two integers each: ai, bi — intervals when Vasya can play (0 ≤ ai < bi ≤ 1018, bi < ai + 1).
The following m lines contain two integers each: ci, di — intervals when Petya can play (0 ≤ ci < di ≤ 1018, di < ci + 1).
Output
Output one integer — the maximal experience that Vasya can have in the end, if both players try to maximize this value.
Examples
Input
2 1 5
1 7
10 20
10 20
Output
25
Input
1 2 5
0 100
20 60
85 90
Output
125
Submitted Solution:
```
s = input()
f = [0,0,0]
for x in s:
if x == 'a':
f[2] = max(f)+1
f[0]+=1
else:
f[1] = max(f[0],f[1])+1
print(max(f))
``` | instruction | 0 | 78,813 | 19 | 157,626 |
No | output | 1 | 78,813 | 19 | 157,627 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let n be a positive integer. Let a, b, c be nonnegative integers such that a + b + c = n.
Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock a times, paper b times, and scissors c times.
Alice wins if she beats Bob in at least ⌈ n/2 ⌉ (n/2 rounded up to the nearest integer) hands, otherwise Alice loses.
Note that in rock-paper-scissors:
* rock beats scissors;
* paper beats rock;
* scissors beat paper.
The task is, given the sequence of hands that Bob will play, and the numbers a, b, c, determine whether or not Alice can win. And if so, find any possible sequence of hands that Alice can use to win.
If there are multiple answers, print any of them.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases.
Then, t testcases follow, each consisting of three lines:
* The first line contains a single integer n (1 ≤ n ≤ 100).
* The second line contains three integers, a, b, c (0 ≤ a, b, c ≤ n). It is guaranteed that a + b + c = n.
* The third line contains a string s of length n. s is made up of only 'R', 'P', and 'S'. The i-th character is 'R' if for his i-th Bob plays rock, 'P' if paper, and 'S' if scissors.
Output
For each testcase:
* If Alice cannot win, print "NO" (without the quotes).
* Otherwise, print "YES" (without the quotes). Also, print a string t of length n made up of only 'R', 'P', and 'S' — a sequence of hands that Alice can use to win. t must contain exactly a 'R's, b 'P's, and c 'S's.
* If there are multiple answers, print any of them.
The "YES" / "NO" part of the output is case-insensitive (i.e. "yEs", "no" or "YEs" are all valid answers). Note that 'R', 'P' and 'S' are case-sensitive.
Example
Input
2
3
1 1 1
RPS
3
3 0 0
RPS
Output
YES
PSR
NO
Note
In the first testcase, in the first hand, Alice plays paper and Bob plays rock, so Alice beats Bob. In the second hand, Alice plays scissors and Bob plays paper, so Alice beats Bob. In the third hand, Alice plays rock and Bob plays scissors, so Alice beats Bob. Alice beat Bob 3 times, and 3 ≥ ⌈ 3/2 ⌉ = 2, so Alice wins.
In the second testcase, the only sequence of hands that Alice can play is "RRR". Alice beats Bob only in the last hand, so Alice can't win. 1 < ⌈ 3/2 ⌉ = 2. | instruction | 0 | 79,251 | 19 | 158,502 |
Tags: constructive algorithms, dp, greedy
Correct Solution:
```
for _ in range(int(input())):
n = int(input())
rps = [int(x) for x in input().split()]
s = input()
cnt = 0
t = []
temp = []
for x in s:
flag = 0
if x == 'R':
if rps[1] > 0:
rps[1] -= 1
cnt += 1
t.append('P')
flag = 1
elif x == 'P':
if rps[2] > 0:
rps[2] -= 1
cnt += 1
t.append('S')
flag = 1
else:
if rps[0] > 0:
rps[0] -= 1
cnt += 1
t.append('R')
flag = 1
if flag == 0:
t.append('_')
for x in range(rps[0]):
temp.append('R')
for x in range(rps[1]):
temp.append('P')
for x in range(rps[2]):
temp.append('S')
if (n + 1) // 2 <= cnt:
print("YES")
for x in range(n):
if t[x] == '_':
t[x] = temp[0]
temp.pop(0)
print("".join(t))
else:
print("NO")
``` | output | 1 | 79,251 | 19 | 158,503 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let n be a positive integer. Let a, b, c be nonnegative integers such that a + b + c = n.
Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock a times, paper b times, and scissors c times.
Alice wins if she beats Bob in at least ⌈ n/2 ⌉ (n/2 rounded up to the nearest integer) hands, otherwise Alice loses.
Note that in rock-paper-scissors:
* rock beats scissors;
* paper beats rock;
* scissors beat paper.
The task is, given the sequence of hands that Bob will play, and the numbers a, b, c, determine whether or not Alice can win. And if so, find any possible sequence of hands that Alice can use to win.
If there are multiple answers, print any of them.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases.
Then, t testcases follow, each consisting of three lines:
* The first line contains a single integer n (1 ≤ n ≤ 100).
* The second line contains three integers, a, b, c (0 ≤ a, b, c ≤ n). It is guaranteed that a + b + c = n.
* The third line contains a string s of length n. s is made up of only 'R', 'P', and 'S'. The i-th character is 'R' if for his i-th Bob plays rock, 'P' if paper, and 'S' if scissors.
Output
For each testcase:
* If Alice cannot win, print "NO" (without the quotes).
* Otherwise, print "YES" (without the quotes). Also, print a string t of length n made up of only 'R', 'P', and 'S' — a sequence of hands that Alice can use to win. t must contain exactly a 'R's, b 'P's, and c 'S's.
* If there are multiple answers, print any of them.
The "YES" / "NO" part of the output is case-insensitive (i.e. "yEs", "no" or "YEs" are all valid answers). Note that 'R', 'P' and 'S' are case-sensitive.
Example
Input
2
3
1 1 1
RPS
3
3 0 0
RPS
Output
YES
PSR
NO
Note
In the first testcase, in the first hand, Alice plays paper and Bob plays rock, so Alice beats Bob. In the second hand, Alice plays scissors and Bob plays paper, so Alice beats Bob. In the third hand, Alice plays rock and Bob plays scissors, so Alice beats Bob. Alice beat Bob 3 times, and 3 ≥ ⌈ 3/2 ⌉ = 2, so Alice wins.
In the second testcase, the only sequence of hands that Alice can play is "RRR". Alice beats Bob only in the last hand, so Alice can't win. 1 < ⌈ 3/2 ⌉ = 2. | instruction | 0 | 79,252 | 19 | 158,504 |
Tags: constructive algorithms, dp, greedy
Correct Solution:
```
#!/usr/bin/env python
import sys
from collections import Counter
from math import ceil
W = {'S': 'R', 'R': 'P', 'P':'S'}
def atoi(line):
line = line.rstrip().split()
return list(map(int, line))
def won(A, B):
W_ct = dict()
W_ct['S'] = min(A['R'], B['S'])
W_ct['R'] = min(A['P'], B['R'])
W_ct['P'] = min(A['S'], B['P'])
return W_ct
def check(A, B, n):
W_ct = won(A, B)
k = sum(W_ct.values())
if k >= ceil(n / 2):
return True, W_ct
return False, W_ct
def gen(seq_B, A, B, W_ct, n):
seq_A = ['_'] * n
for idx, sym in enumerate(seq_B):
if W_ct[sym] > 0:
seq_A[idx] = W[sym]
W_ct[sym] -= 1
A[W[sym]] -= 1
empty = [idx for idx, sym in enumerate(seq_A) if sym == '_']
for idx in empty:
for k, v in A.items():
if A[k] != 0:
seq_A[idx] = k
A[k] -= 1
break
return seq_A
def fill(B):
s = 'RPS'
for sym in s:
B[sym] = 0 if sym not in B else B[sym]
def Alice(a, b, c):
A = {'R': a, 'P': b, 'S': c}
return A
def Bob(s):
B = Counter(s)
fill(B)
return B
t = int(input())
ans = []
for _ in range(t):
n = int(input())
a, b, c = atoi(sys.stdin.readline())
A = Alice(a, b, c)
s = sys.stdin.readline().rstrip()
B = Bob(s)
is_w, W_ct = check(A, B, n)
if not is_w:
ans.append('NO')
continue
seq_A = gen(s, A, B, W_ct, n)
ans.append('YES')
ans.append(''.join(seq_A))
print(*ans, sep = '\n')
``` | output | 1 | 79,252 | 19 | 158,505 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let n be a positive integer. Let a, b, c be nonnegative integers such that a + b + c = n.
Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock a times, paper b times, and scissors c times.
Alice wins if she beats Bob in at least ⌈ n/2 ⌉ (n/2 rounded up to the nearest integer) hands, otherwise Alice loses.
Note that in rock-paper-scissors:
* rock beats scissors;
* paper beats rock;
* scissors beat paper.
The task is, given the sequence of hands that Bob will play, and the numbers a, b, c, determine whether or not Alice can win. And if so, find any possible sequence of hands that Alice can use to win.
If there are multiple answers, print any of them.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases.
Then, t testcases follow, each consisting of three lines:
* The first line contains a single integer n (1 ≤ n ≤ 100).
* The second line contains three integers, a, b, c (0 ≤ a, b, c ≤ n). It is guaranteed that a + b + c = n.
* The third line contains a string s of length n. s is made up of only 'R', 'P', and 'S'. The i-th character is 'R' if for his i-th Bob plays rock, 'P' if paper, and 'S' if scissors.
Output
For each testcase:
* If Alice cannot win, print "NO" (without the quotes).
* Otherwise, print "YES" (without the quotes). Also, print a string t of length n made up of only 'R', 'P', and 'S' — a sequence of hands that Alice can use to win. t must contain exactly a 'R's, b 'P's, and c 'S's.
* If there are multiple answers, print any of them.
The "YES" / "NO" part of the output is case-insensitive (i.e. "yEs", "no" or "YEs" are all valid answers). Note that 'R', 'P' and 'S' are case-sensitive.
Example
Input
2
3
1 1 1
RPS
3
3 0 0
RPS
Output
YES
PSR
NO
Note
In the first testcase, in the first hand, Alice plays paper and Bob plays rock, so Alice beats Bob. In the second hand, Alice plays scissors and Bob plays paper, so Alice beats Bob. In the third hand, Alice plays rock and Bob plays scissors, so Alice beats Bob. Alice beat Bob 3 times, and 3 ≥ ⌈ 3/2 ⌉ = 2, so Alice wins.
In the second testcase, the only sequence of hands that Alice can play is "RRR". Alice beats Bob only in the last hand, so Alice can't win. 1 < ⌈ 3/2 ⌉ = 2. | instruction | 0 | 79,253 | 19 | 158,506 |
Tags: constructive algorithms, dp, greedy
Correct Solution:
```
from math import gcd
t = int(input())
for i in range(t):
n = int(input())
r, p, s = map(int, input().split())
bob = input()
ans = [0] * n
cnt = 0
for j in range(n):
if bob[j] == 'R' and p > 0:
p -= 1
ans[j] = 'P'
cnt += 1
if bob[j] == 'P' and s > 0:
s -= 1
cnt += 1
ans[j] = 'S'
if bob[j] == 'S' and r > 0:
r -= 1
ans[j] = 'R'
cnt += 1
if cnt * 2 >= n:
print('YES')
for j in range(n):
if ans[j] == 0:
if p > 0:
p -= 1
ans[j] = 'P'
elif r > 0:
r -= 1
ans[j] = 'R'
else:
s -= 1
ans[j] = 'S'
print(''.join(ans))
else:
print('NO')
``` | output | 1 | 79,253 | 19 | 158,507 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let n be a positive integer. Let a, b, c be nonnegative integers such that a + b + c = n.
Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock a times, paper b times, and scissors c times.
Alice wins if she beats Bob in at least ⌈ n/2 ⌉ (n/2 rounded up to the nearest integer) hands, otherwise Alice loses.
Note that in rock-paper-scissors:
* rock beats scissors;
* paper beats rock;
* scissors beat paper.
The task is, given the sequence of hands that Bob will play, and the numbers a, b, c, determine whether or not Alice can win. And if so, find any possible sequence of hands that Alice can use to win.
If there are multiple answers, print any of them.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases.
Then, t testcases follow, each consisting of three lines:
* The first line contains a single integer n (1 ≤ n ≤ 100).
* The second line contains three integers, a, b, c (0 ≤ a, b, c ≤ n). It is guaranteed that a + b + c = n.
* The third line contains a string s of length n. s is made up of only 'R', 'P', and 'S'. The i-th character is 'R' if for his i-th Bob plays rock, 'P' if paper, and 'S' if scissors.
Output
For each testcase:
* If Alice cannot win, print "NO" (without the quotes).
* Otherwise, print "YES" (without the quotes). Also, print a string t of length n made up of only 'R', 'P', and 'S' — a sequence of hands that Alice can use to win. t must contain exactly a 'R's, b 'P's, and c 'S's.
* If there are multiple answers, print any of them.
The "YES" / "NO" part of the output is case-insensitive (i.e. "yEs", "no" or "YEs" are all valid answers). Note that 'R', 'P' and 'S' are case-sensitive.
Example
Input
2
3
1 1 1
RPS
3
3 0 0
RPS
Output
YES
PSR
NO
Note
In the first testcase, in the first hand, Alice plays paper and Bob plays rock, so Alice beats Bob. In the second hand, Alice plays scissors and Bob plays paper, so Alice beats Bob. In the third hand, Alice plays rock and Bob plays scissors, so Alice beats Bob. Alice beat Bob 3 times, and 3 ≥ ⌈ 3/2 ⌉ = 2, so Alice wins.
In the second testcase, the only sequence of hands that Alice can play is "RRR". Alice beats Bob only in the last hand, so Alice can't win. 1 < ⌈ 3/2 ⌉ = 2. | instruction | 0 | 79,254 | 19 | 158,508 |
Tags: constructive algorithms, dp, greedy
Correct Solution:
```
import sys
import math
import itertools
import collections
def getdict(n):
d = {}
if type(n) is list or type(n) is str:
for i in n:
if i in d:
d[i] += 1
else:
d[i] = 1
else:
for i in range(n):
t = ii()
if t in d:
d[t] += 1
else:
d[t] = 1
return d
def divs(n, start=1):
r = []
for i in range(start, int(math.sqrt(n) + 1)):
if (n % i == 0):
if (n / i == i):
r.append(i)
else:
r.extend([i, n // i])
return r
def cdiv(n, k): return n // k + (n % k != 0)
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a*b) // math.gcd(a, b)
def wr(arr): return ''.join(map(str, arr))
def revn(n): return int(str(n)[::-1])
def prime(n):
if n == 2: return True
if n % 2 == 0 or n <= 1: return False
sqr = int(math.sqrt(n)) + 1
for d in range(3, sqr, 2):
if n % d == 0: return False
return True
def convn(number, base=3):
newnumber = ''
while number > 0:
newnumber = str(number % base) + newnumber
number //= base
return newnumber
t = ii()
k = ['R', 'P', 'S']
for _ in range(t):
n = ii()
a, b, c = mi()
s = input()
bob = collections.Counter(s)
w = [min(a, bob['S']), min(b, bob['R']), min(c, bob['P'])]
if sum(w) >= math.ceil(n/2):
print('YES')
ans = ['.'] * n
d = [[] for i in range(3)]
for i in range(n):
if s[i] == 'R':
d[1].append(i)
elif s[i] == 'P':
d[2].append(i)
else:
d[0].append(i)
for i in range(3):
for j in range(w[i]):
ans[d[i][j]] = k[i]
t = 'R' * (a - w[0]) + 'P' * (b - w[1]) + 'S' * (c - w[2])
if len(t) > 0:
j = 0
for i in range(n):
if ans[i] == '.':
ans[i] = t[j]
j += 1
print(wr(ans))
else:
print(wr(ans))
else:
print('NO')
``` | output | 1 | 79,254 | 19 | 158,509 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let n be a positive integer. Let a, b, c be nonnegative integers such that a + b + c = n.
Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock a times, paper b times, and scissors c times.
Alice wins if she beats Bob in at least ⌈ n/2 ⌉ (n/2 rounded up to the nearest integer) hands, otherwise Alice loses.
Note that in rock-paper-scissors:
* rock beats scissors;
* paper beats rock;
* scissors beat paper.
The task is, given the sequence of hands that Bob will play, and the numbers a, b, c, determine whether or not Alice can win. And if so, find any possible sequence of hands that Alice can use to win.
If there are multiple answers, print any of them.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases.
Then, t testcases follow, each consisting of three lines:
* The first line contains a single integer n (1 ≤ n ≤ 100).
* The second line contains three integers, a, b, c (0 ≤ a, b, c ≤ n). It is guaranteed that a + b + c = n.
* The third line contains a string s of length n. s is made up of only 'R', 'P', and 'S'. The i-th character is 'R' if for his i-th Bob plays rock, 'P' if paper, and 'S' if scissors.
Output
For each testcase:
* If Alice cannot win, print "NO" (without the quotes).
* Otherwise, print "YES" (without the quotes). Also, print a string t of length n made up of only 'R', 'P', and 'S' — a sequence of hands that Alice can use to win. t must contain exactly a 'R's, b 'P's, and c 'S's.
* If there are multiple answers, print any of them.
The "YES" / "NO" part of the output is case-insensitive (i.e. "yEs", "no" or "YEs" are all valid answers). Note that 'R', 'P' and 'S' are case-sensitive.
Example
Input
2
3
1 1 1
RPS
3
3 0 0
RPS
Output
YES
PSR
NO
Note
In the first testcase, in the first hand, Alice plays paper and Bob plays rock, so Alice beats Bob. In the second hand, Alice plays scissors and Bob plays paper, so Alice beats Bob. In the third hand, Alice plays rock and Bob plays scissors, so Alice beats Bob. Alice beat Bob 3 times, and 3 ≥ ⌈ 3/2 ⌉ = 2, so Alice wins.
In the second testcase, the only sequence of hands that Alice can play is "RRR". Alice beats Bob only in the last hand, so Alice can't win. 1 < ⌈ 3/2 ⌉ = 2. | instruction | 0 | 79,255 | 19 | 158,510 |
Tags: constructive algorithms, dp, greedy
Correct Solution:
```
# cf 1245 B 1200
t = int(input())
for _ in range(t):
n = int(input())
r, p, s = map(int, input().split())
S = input()
# R > S, P > R, S > P
P = []
wins = 0
for c in S:
if c == 'S':
if r > 0:
P.append('R')
wins += 1
r -= 1
else:
P.append('X')
elif c == 'P':
if s > 0:
P.append('S')
wins += 1
s -= 1
else:
P.append('X')
else: # c == 'R'
if p > 0:
P.append('P')
wins += 1
p -= 1
else:
P.append('X')
for i in range(len(P)):
if P[i] == 'X':
if r > 0:
P[i] = 'R'
r -= 1
elif s > 0:
P[i] = 'S'
s -= 1
elif p > 0:
P[i] = 'P'
p -= 1
if wins >= (n // 2) + (n % 2):
print("YES")
print("".join(P))
else:
print("NO")
``` | output | 1 | 79,255 | 19 | 158,511 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let n be a positive integer. Let a, b, c be nonnegative integers such that a + b + c = n.
Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock a times, paper b times, and scissors c times.
Alice wins if she beats Bob in at least ⌈ n/2 ⌉ (n/2 rounded up to the nearest integer) hands, otherwise Alice loses.
Note that in rock-paper-scissors:
* rock beats scissors;
* paper beats rock;
* scissors beat paper.
The task is, given the sequence of hands that Bob will play, and the numbers a, b, c, determine whether or not Alice can win. And if so, find any possible sequence of hands that Alice can use to win.
If there are multiple answers, print any of them.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases.
Then, t testcases follow, each consisting of three lines:
* The first line contains a single integer n (1 ≤ n ≤ 100).
* The second line contains three integers, a, b, c (0 ≤ a, b, c ≤ n). It is guaranteed that a + b + c = n.
* The third line contains a string s of length n. s is made up of only 'R', 'P', and 'S'. The i-th character is 'R' if for his i-th Bob plays rock, 'P' if paper, and 'S' if scissors.
Output
For each testcase:
* If Alice cannot win, print "NO" (without the quotes).
* Otherwise, print "YES" (without the quotes). Also, print a string t of length n made up of only 'R', 'P', and 'S' — a sequence of hands that Alice can use to win. t must contain exactly a 'R's, b 'P's, and c 'S's.
* If there are multiple answers, print any of them.
The "YES" / "NO" part of the output is case-insensitive (i.e. "yEs", "no" or "YEs" are all valid answers). Note that 'R', 'P' and 'S' are case-sensitive.
Example
Input
2
3
1 1 1
RPS
3
3 0 0
RPS
Output
YES
PSR
NO
Note
In the first testcase, in the first hand, Alice plays paper and Bob plays rock, so Alice beats Bob. In the second hand, Alice plays scissors and Bob plays paper, so Alice beats Bob. In the third hand, Alice plays rock and Bob plays scissors, so Alice beats Bob. Alice beat Bob 3 times, and 3 ≥ ⌈ 3/2 ⌉ = 2, so Alice wins.
In the second testcase, the only sequence of hands that Alice can play is "RRR". Alice beats Bob only in the last hand, so Alice can't win. 1 < ⌈ 3/2 ⌉ = 2. | instruction | 0 | 79,256 | 19 | 158,512 |
Tags: constructive algorithms, dp, greedy
Correct Solution:
```
import sys
#sys.stdin = open("in.txt","r")
#sys.stdout = open("out.txt","w")
test = int(input())
for case in range(test):
n = int(input())
r,p,s=map(int,input().split())
bob = list(input())
x,w = 0,(n//2)+(n%2)
win = [False] * n
for i in range(len(bob)):
if(bob[i] == 'R' and p>0):
win[i] = True
x+=1
p-=1
elif (bob[i] == 'P' and s > 0):
win[i] = True
x += 1
s -= 1
elif (bob[i] == 'S' and r > 0):
win[i] = True
x += 1
r -= 1
#print(x,w)
if(x>=w):
print("YES")
for i in range(len(bob)):
if(win[i]==True):
if(bob[i]=='R'): print("P",end="")
if(bob[i]=='P'): print("S",end="")
if(bob[i]=='S'): print("R",end="")
else:
if(r>0):
r-=1
print("R",end="")
elif(p > 0):
p -= 1
print("P",end="")
elif(s > 0):
s -= 1
print("S",end="")
print("")
else:
print("NO")
``` | output | 1 | 79,256 | 19 | 158,513 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let n be a positive integer. Let a, b, c be nonnegative integers such that a + b + c = n.
Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock a times, paper b times, and scissors c times.
Alice wins if she beats Bob in at least ⌈ n/2 ⌉ (n/2 rounded up to the nearest integer) hands, otherwise Alice loses.
Note that in rock-paper-scissors:
* rock beats scissors;
* paper beats rock;
* scissors beat paper.
The task is, given the sequence of hands that Bob will play, and the numbers a, b, c, determine whether or not Alice can win. And if so, find any possible sequence of hands that Alice can use to win.
If there are multiple answers, print any of them.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases.
Then, t testcases follow, each consisting of three lines:
* The first line contains a single integer n (1 ≤ n ≤ 100).
* The second line contains three integers, a, b, c (0 ≤ a, b, c ≤ n). It is guaranteed that a + b + c = n.
* The third line contains a string s of length n. s is made up of only 'R', 'P', and 'S'. The i-th character is 'R' if for his i-th Bob plays rock, 'P' if paper, and 'S' if scissors.
Output
For each testcase:
* If Alice cannot win, print "NO" (without the quotes).
* Otherwise, print "YES" (without the quotes). Also, print a string t of length n made up of only 'R', 'P', and 'S' — a sequence of hands that Alice can use to win. t must contain exactly a 'R's, b 'P's, and c 'S's.
* If there are multiple answers, print any of them.
The "YES" / "NO" part of the output is case-insensitive (i.e. "yEs", "no" or "YEs" are all valid answers). Note that 'R', 'P' and 'S' are case-sensitive.
Example
Input
2
3
1 1 1
RPS
3
3 0 0
RPS
Output
YES
PSR
NO
Note
In the first testcase, in the first hand, Alice plays paper and Bob plays rock, so Alice beats Bob. In the second hand, Alice plays scissors and Bob plays paper, so Alice beats Bob. In the third hand, Alice plays rock and Bob plays scissors, so Alice beats Bob. Alice beat Bob 3 times, and 3 ≥ ⌈ 3/2 ⌉ = 2, so Alice wins.
In the second testcase, the only sequence of hands that Alice can play is "RRR". Alice beats Bob only in the last hand, so Alice can't win. 1 < ⌈ 3/2 ⌉ = 2. | instruction | 0 | 79,257 | 19 | 158,514 |
Tags: constructive algorithms, dp, greedy
Correct Solution:
```
'''input
2
3
1 1 1
RPS
3
3 0 0
RPS
'''
import math
for _ in range(int(input())):
n = int(input())
r, p, s = map(int, input().split())
seq = input()
ans = ['_' for i in range(len(seq))]
for i, ele in enumerate(seq):
if ele == 'R':
if p > 0:
ans[i] = 'P'
p -= 1
elif ele == 'P':
if s > 0:
ans[i] = 'S'
s -= 1
else:
if r > 0:
ans[i] = 'R'
r -= 1
if (n - ans.count('_')) >= ((n + 1) // 2):
print('YES')
for ele in ans:
if ele != '_':
print(ele, end = '')
else:
if r > 0:
print('R', end = '')
r -= 1
elif p > 0:
print('P', end = '')
p -= 1
else:
print('S', end = '')
s -= 1
print()
else:
print('NO')
``` | output | 1 | 79,257 | 19 | 158,515 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let n be a positive integer. Let a, b, c be nonnegative integers such that a + b + c = n.
Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock a times, paper b times, and scissors c times.
Alice wins if she beats Bob in at least ⌈ n/2 ⌉ (n/2 rounded up to the nearest integer) hands, otherwise Alice loses.
Note that in rock-paper-scissors:
* rock beats scissors;
* paper beats rock;
* scissors beat paper.
The task is, given the sequence of hands that Bob will play, and the numbers a, b, c, determine whether or not Alice can win. And if so, find any possible sequence of hands that Alice can use to win.
If there are multiple answers, print any of them.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases.
Then, t testcases follow, each consisting of three lines:
* The first line contains a single integer n (1 ≤ n ≤ 100).
* The second line contains three integers, a, b, c (0 ≤ a, b, c ≤ n). It is guaranteed that a + b + c = n.
* The third line contains a string s of length n. s is made up of only 'R', 'P', and 'S'. The i-th character is 'R' if for his i-th Bob plays rock, 'P' if paper, and 'S' if scissors.
Output
For each testcase:
* If Alice cannot win, print "NO" (without the quotes).
* Otherwise, print "YES" (without the quotes). Also, print a string t of length n made up of only 'R', 'P', and 'S' — a sequence of hands that Alice can use to win. t must contain exactly a 'R's, b 'P's, and c 'S's.
* If there are multiple answers, print any of them.
The "YES" / "NO" part of the output is case-insensitive (i.e. "yEs", "no" or "YEs" are all valid answers). Note that 'R', 'P' and 'S' are case-sensitive.
Example
Input
2
3
1 1 1
RPS
3
3 0 0
RPS
Output
YES
PSR
NO
Note
In the first testcase, in the first hand, Alice plays paper and Bob plays rock, so Alice beats Bob. In the second hand, Alice plays scissors and Bob plays paper, so Alice beats Bob. In the third hand, Alice plays rock and Bob plays scissors, so Alice beats Bob. Alice beat Bob 3 times, and 3 ≥ ⌈ 3/2 ⌉ = 2, so Alice wins.
In the second testcase, the only sequence of hands that Alice can play is "RRR". Alice beats Bob only in the last hand, so Alice can't win. 1 < ⌈ 3/2 ⌉ = 2. | instruction | 0 | 79,258 | 19 | 158,516 |
Tags: constructive algorithms, dp, greedy
Correct Solution:
```
t = int(input())
for _ in range(t):
n = int(input())
r, p, s = map(int, input().split())
bob = input()
w = 0
h = ''
for c in bob:
if 'R' == c and p > 0:
p -= 1
w += 1
h += 'P'
elif 'P' == c and s > 0:
s -= 1
w += 1
h += 'S'
elif 'S' == c and r > 0:
r -= 1
w += 1
h += 'R'
else:
h += '_'
if (w << 1) >= n:
h += '_' * (n - len(h))
break
if (w << 1) >= n:
print("YES")
ret = ''
for c in h:
if '_' == c:
if r > 0:
ret += 'R'
r -= 1
elif p > 0:
ret += 'P'
p -= 1
elif s > 0:
ret += 'S'
s -= 1
else:
ret += c
print(ret)
else:
print("NO")
``` | output | 1 | 79,258 | 19 | 158,517 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let n be a positive integer. Let a, b, c be nonnegative integers such that a + b + c = n.
Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock a times, paper b times, and scissors c times.
Alice wins if she beats Bob in at least ⌈ n/2 ⌉ (n/2 rounded up to the nearest integer) hands, otherwise Alice loses.
Note that in rock-paper-scissors:
* rock beats scissors;
* paper beats rock;
* scissors beat paper.
The task is, given the sequence of hands that Bob will play, and the numbers a, b, c, determine whether or not Alice can win. And if so, find any possible sequence of hands that Alice can use to win.
If there are multiple answers, print any of them.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases.
Then, t testcases follow, each consisting of three lines:
* The first line contains a single integer n (1 ≤ n ≤ 100).
* The second line contains three integers, a, b, c (0 ≤ a, b, c ≤ n). It is guaranteed that a + b + c = n.
* The third line contains a string s of length n. s is made up of only 'R', 'P', and 'S'. The i-th character is 'R' if for his i-th Bob plays rock, 'P' if paper, and 'S' if scissors.
Output
For each testcase:
* If Alice cannot win, print "NO" (without the quotes).
* Otherwise, print "YES" (without the quotes). Also, print a string t of length n made up of only 'R', 'P', and 'S' — a sequence of hands that Alice can use to win. t must contain exactly a 'R's, b 'P's, and c 'S's.
* If there are multiple answers, print any of them.
The "YES" / "NO" part of the output is case-insensitive (i.e. "yEs", "no" or "YEs" are all valid answers). Note that 'R', 'P' and 'S' are case-sensitive.
Example
Input
2
3
1 1 1
RPS
3
3 0 0
RPS
Output
YES
PSR
NO
Note
In the first testcase, in the first hand, Alice plays paper and Bob plays rock, so Alice beats Bob. In the second hand, Alice plays scissors and Bob plays paper, so Alice beats Bob. In the third hand, Alice plays rock and Bob plays scissors, so Alice beats Bob. Alice beat Bob 3 times, and 3 ≥ ⌈ 3/2 ⌉ = 2, so Alice wins.
In the second testcase, the only sequence of hands that Alice can play is "RRR". Alice beats Bob only in the last hand, so Alice can't win. 1 < ⌈ 3/2 ⌉ = 2.
Submitted Solution:
```
from sys import stdout, stdin, exit
for i in stdin:
t=int(i)
break
while t:
for i in stdin:
n=int(i)
break
for i in stdin:
a,b,c=list(map(int,i.strip().split()))
break
for i in stdin:
s=i.strip()
break
x=''
for i in s:
if i=='R' and b:
x+='P'
b-=1
elif i=='P' and c:
x+='S'
c-=1
elif i=='S' and a:
x+='R'
a-=1
else:
x+='X'
if x.count('X')>n//2 :
stdout.write('NO\n')
else:
ss=''
for i in x:
if i=='X':
if a>0:
ss+='R'
a-=1
elif b>0:
ss+='P'
b-=1
else:
ss+='S'
c-=1
else:
ss+=i
stdout.write('YES\n')
stdout.write(ss+'\n')
t-=1
``` | instruction | 0 | 79,259 | 19 | 158,518 |
Yes | output | 1 | 79,259 | 19 | 158,519 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let n be a positive integer. Let a, b, c be nonnegative integers such that a + b + c = n.
Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock a times, paper b times, and scissors c times.
Alice wins if she beats Bob in at least ⌈ n/2 ⌉ (n/2 rounded up to the nearest integer) hands, otherwise Alice loses.
Note that in rock-paper-scissors:
* rock beats scissors;
* paper beats rock;
* scissors beat paper.
The task is, given the sequence of hands that Bob will play, and the numbers a, b, c, determine whether or not Alice can win. And if so, find any possible sequence of hands that Alice can use to win.
If there are multiple answers, print any of them.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases.
Then, t testcases follow, each consisting of three lines:
* The first line contains a single integer n (1 ≤ n ≤ 100).
* The second line contains three integers, a, b, c (0 ≤ a, b, c ≤ n). It is guaranteed that a + b + c = n.
* The third line contains a string s of length n. s is made up of only 'R', 'P', and 'S'. The i-th character is 'R' if for his i-th Bob plays rock, 'P' if paper, and 'S' if scissors.
Output
For each testcase:
* If Alice cannot win, print "NO" (without the quotes).
* Otherwise, print "YES" (without the quotes). Also, print a string t of length n made up of only 'R', 'P', and 'S' — a sequence of hands that Alice can use to win. t must contain exactly a 'R's, b 'P's, and c 'S's.
* If there are multiple answers, print any of them.
The "YES" / "NO" part of the output is case-insensitive (i.e. "yEs", "no" or "YEs" are all valid answers). Note that 'R', 'P' and 'S' are case-sensitive.
Example
Input
2
3
1 1 1
RPS
3
3 0 0
RPS
Output
YES
PSR
NO
Note
In the first testcase, in the first hand, Alice plays paper and Bob plays rock, so Alice beats Bob. In the second hand, Alice plays scissors and Bob plays paper, so Alice beats Bob. In the third hand, Alice plays rock and Bob plays scissors, so Alice beats Bob. Alice beat Bob 3 times, and 3 ≥ ⌈ 3/2 ⌉ = 2, so Alice wins.
In the second testcase, the only sequence of hands that Alice can play is "RRR". Alice beats Bob only in the last hand, so Alice can't win. 1 < ⌈ 3/2 ⌉ = 2.
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Sat May 30 01:35:47 2020
@author: Ritvik Agarwal
"""
for _ in range(int(input())):
n = int(input())
a,b,c = map(int,input().split())
s = input()
cnt = [0,0,0]
for i in s:
if i == "R":
cnt[0] += 1
elif i == "P":
cnt[1] += 1
else:
cnt[2] += 1
w = min(a,cnt[2]) + min(b,cnt[0]) + min(c,cnt[1])
if w * 2 < n:
print("NO")
else:
print("YES")
ans = ""
for ch in s:
if ch == "R" and b:
ans += "P"
b -= 1
elif ch == "P" and c:
ans += "S"
c -= 1
elif ch == "S" and a:
ans += "R"
a -= 1
else:
ans += "_"
for i in range(n):
if ans[i] != "_":
continue
else:
if a:
ans = ans[:i] + "R" + ans[i+1:]
a -= 1
elif b:
ans = ans[:i] + "P" + ans[i+1:]
b -= 1
else:
ans = ans[:i] + "S" + ans[i+1:]
print(ans)
``` | instruction | 0 | 79,260 | 19 | 158,520 |
Yes | output | 1 | 79,260 | 19 | 158,521 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let n be a positive integer. Let a, b, c be nonnegative integers such that a + b + c = n.
Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock a times, paper b times, and scissors c times.
Alice wins if she beats Bob in at least ⌈ n/2 ⌉ (n/2 rounded up to the nearest integer) hands, otherwise Alice loses.
Note that in rock-paper-scissors:
* rock beats scissors;
* paper beats rock;
* scissors beat paper.
The task is, given the sequence of hands that Bob will play, and the numbers a, b, c, determine whether or not Alice can win. And if so, find any possible sequence of hands that Alice can use to win.
If there are multiple answers, print any of them.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases.
Then, t testcases follow, each consisting of three lines:
* The first line contains a single integer n (1 ≤ n ≤ 100).
* The second line contains three integers, a, b, c (0 ≤ a, b, c ≤ n). It is guaranteed that a + b + c = n.
* The third line contains a string s of length n. s is made up of only 'R', 'P', and 'S'. The i-th character is 'R' if for his i-th Bob plays rock, 'P' if paper, and 'S' if scissors.
Output
For each testcase:
* If Alice cannot win, print "NO" (without the quotes).
* Otherwise, print "YES" (without the quotes). Also, print a string t of length n made up of only 'R', 'P', and 'S' — a sequence of hands that Alice can use to win. t must contain exactly a 'R's, b 'P's, and c 'S's.
* If there are multiple answers, print any of them.
The "YES" / "NO" part of the output is case-insensitive (i.e. "yEs", "no" or "YEs" are all valid answers). Note that 'R', 'P' and 'S' are case-sensitive.
Example
Input
2
3
1 1 1
RPS
3
3 0 0
RPS
Output
YES
PSR
NO
Note
In the first testcase, in the first hand, Alice plays paper and Bob plays rock, so Alice beats Bob. In the second hand, Alice plays scissors and Bob plays paper, so Alice beats Bob. In the third hand, Alice plays rock and Bob plays scissors, so Alice beats Bob. Alice beat Bob 3 times, and 3 ≥ ⌈ 3/2 ⌉ = 2, so Alice wins.
In the second testcase, the only sequence of hands that Alice can play is "RRR". Alice beats Bob only in the last hand, so Alice can't win. 1 < ⌈ 3/2 ⌉ = 2.
Submitted Solution:
```
from sys import *
from math import *
t=int(stdin.readline())
for _ in range(t):
n=int(stdin.readline())
a,b,c=map(int,stdin.readline().split())
s1=input()
r=p=s=0
for i in range(n):
if s1[i]=="R":
r+=1
elif s1[i]=="P":
p+=1
else:
s+=1
a1=min(a,s)
a2=min(b,r)
a3=min(c,p)
x=a1+a2+a3
if float(x)>=n/2:
print("YES")
ans=[0]*n
f=[0]*n
for i in range(n):
if s1[i]=="S" and a>0:
a-=1
ans[i]=("R")
f[i]=1
if s1[i]=="R" and b>0:
b-=1
ans[i]=("P")
f[i] = 1
if s1[i]=="P" and c>0:
c-=1
ans[i]=("S")
f[i] = 1
for i in range(n):
m=max(a,b,c)
if f[i]==0:
if m==a:
ans[i]=("R")
a-=1
elif m==b:
ans[i]=("P")
b-=1
else:
ans[i]=("S")
c-=1
print(*ans,sep="")
else:
print("NO")
``` | instruction | 0 | 79,261 | 19 | 158,522 |
Yes | output | 1 | 79,261 | 19 | 158,523 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let n be a positive integer. Let a, b, c be nonnegative integers such that a + b + c = n.
Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock a times, paper b times, and scissors c times.
Alice wins if she beats Bob in at least ⌈ n/2 ⌉ (n/2 rounded up to the nearest integer) hands, otherwise Alice loses.
Note that in rock-paper-scissors:
* rock beats scissors;
* paper beats rock;
* scissors beat paper.
The task is, given the sequence of hands that Bob will play, and the numbers a, b, c, determine whether or not Alice can win. And if so, find any possible sequence of hands that Alice can use to win.
If there are multiple answers, print any of them.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases.
Then, t testcases follow, each consisting of three lines:
* The first line contains a single integer n (1 ≤ n ≤ 100).
* The second line contains three integers, a, b, c (0 ≤ a, b, c ≤ n). It is guaranteed that a + b + c = n.
* The third line contains a string s of length n. s is made up of only 'R', 'P', and 'S'. The i-th character is 'R' if for his i-th Bob plays rock, 'P' if paper, and 'S' if scissors.
Output
For each testcase:
* If Alice cannot win, print "NO" (without the quotes).
* Otherwise, print "YES" (without the quotes). Also, print a string t of length n made up of only 'R', 'P', and 'S' — a sequence of hands that Alice can use to win. t must contain exactly a 'R's, b 'P's, and c 'S's.
* If there are multiple answers, print any of them.
The "YES" / "NO" part of the output is case-insensitive (i.e. "yEs", "no" or "YEs" are all valid answers). Note that 'R', 'P' and 'S' are case-sensitive.
Example
Input
2
3
1 1 1
RPS
3
3 0 0
RPS
Output
YES
PSR
NO
Note
In the first testcase, in the first hand, Alice plays paper and Bob plays rock, so Alice beats Bob. In the second hand, Alice plays scissors and Bob plays paper, so Alice beats Bob. In the third hand, Alice plays rock and Bob plays scissors, so Alice beats Bob. Alice beat Bob 3 times, and 3 ≥ ⌈ 3/2 ⌉ = 2, so Alice wins.
In the second testcase, the only sequence of hands that Alice can play is "RRR". Alice beats Bob only in the last hand, so Alice can't win. 1 < ⌈ 3/2 ⌉ = 2.
Submitted Solution:
```
for _ in range(int(input())): #R p #P s #s r
n=int(input())
r,p,s= map(int,input().split())
st=input()
rc= st.count('R')
sc= st.count('S')
pc= st.count('P')
v= min(rc, p)+ min(sc,r) + min(pc, s)
if 2*v<n:
print('NO')
else:
ans=[]
print('YES')
for e in st:
if e=='S' and r>0:
ans.append('R')
r-=1
elif e=='R' and p>0:
ans.append('P')
p-=1
elif e=='P' and s>0:
ans.append('S')
s-=1
else:
ans.append('-')
for i in range(n):
if ans[i]== '-':
if r>0:
ans[i]='R'
r-=1
elif s>0:
ans[i]='S'
s-=1
elif p>0:
ans[i]='P'
p-=1
print(''.join(ans))
``` | instruction | 0 | 79,262 | 19 | 158,524 |
Yes | output | 1 | 79,262 | 19 | 158,525 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let n be a positive integer. Let a, b, c be nonnegative integers such that a + b + c = n.
Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock a times, paper b times, and scissors c times.
Alice wins if she beats Bob in at least ⌈ n/2 ⌉ (n/2 rounded up to the nearest integer) hands, otherwise Alice loses.
Note that in rock-paper-scissors:
* rock beats scissors;
* paper beats rock;
* scissors beat paper.
The task is, given the sequence of hands that Bob will play, and the numbers a, b, c, determine whether or not Alice can win. And if so, find any possible sequence of hands that Alice can use to win.
If there are multiple answers, print any of them.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases.
Then, t testcases follow, each consisting of three lines:
* The first line contains a single integer n (1 ≤ n ≤ 100).
* The second line contains three integers, a, b, c (0 ≤ a, b, c ≤ n). It is guaranteed that a + b + c = n.
* The third line contains a string s of length n. s is made up of only 'R', 'P', and 'S'. The i-th character is 'R' if for his i-th Bob plays rock, 'P' if paper, and 'S' if scissors.
Output
For each testcase:
* If Alice cannot win, print "NO" (without the quotes).
* Otherwise, print "YES" (without the quotes). Also, print a string t of length n made up of only 'R', 'P', and 'S' — a sequence of hands that Alice can use to win. t must contain exactly a 'R's, b 'P's, and c 'S's.
* If there are multiple answers, print any of them.
The "YES" / "NO" part of the output is case-insensitive (i.e. "yEs", "no" or "YEs" are all valid answers). Note that 'R', 'P' and 'S' are case-sensitive.
Example
Input
2
3
1 1 1
RPS
3
3 0 0
RPS
Output
YES
PSR
NO
Note
In the first testcase, in the first hand, Alice plays paper and Bob plays rock, so Alice beats Bob. In the second hand, Alice plays scissors and Bob plays paper, so Alice beats Bob. In the third hand, Alice plays rock and Bob plays scissors, so Alice beats Bob. Alice beat Bob 3 times, and 3 ≥ ⌈ 3/2 ⌉ = 2, so Alice wins.
In the second testcase, the only sequence of hands that Alice can play is "RRR". Alice beats Bob only in the last hand, so Alice can't win. 1 < ⌈ 3/2 ⌉ = 2.
Submitted Solution:
```
import sys
#sys.stdin = open("in.txt","r")
#sys.stdout = open("out.txt","w")
test = int(input())
for case in range(test):
n = int(input())
r,p,s=map(int,input().split())
bob = list(input())
x,w = 0,(n//2)+(n%2)
win = [False] * n
for i in range(len(bob)):
if(bob[i] == 'R' and p>0):
win[i] = True
x+=1
p-=1
elif ([i] == 'P' and s > 0):
win[i] = True
x += 1
s -= 1
elif (bob[i] == 'S' and r > 0):
win[i] = True
x += 1
r -= 1
if(x>=w):
print("YES")
for i in range(len(bob)):
if(win[i]==True):
if(bob[i]=='R'): print("P",end="")
if(bob[i]=='P'): print("S",end="")
if(bob[i]=='S'): print("R",end="")
else:
if(r>0):
r-=1
print("R",end="")
elif(p > 0):
p -= 1
print("P",end="")
elif(s > 0):
s -= 1
print("S",end="")
print("")
else:
print("NO")
``` | instruction | 0 | 79,263 | 19 | 158,526 |
No | output | 1 | 79,263 | 19 | 158,527 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let n be a positive integer. Let a, b, c be nonnegative integers such that a + b + c = n.
Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock a times, paper b times, and scissors c times.
Alice wins if she beats Bob in at least ⌈ n/2 ⌉ (n/2 rounded up to the nearest integer) hands, otherwise Alice loses.
Note that in rock-paper-scissors:
* rock beats scissors;
* paper beats rock;
* scissors beat paper.
The task is, given the sequence of hands that Bob will play, and the numbers a, b, c, determine whether or not Alice can win. And if so, find any possible sequence of hands that Alice can use to win.
If there are multiple answers, print any of them.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases.
Then, t testcases follow, each consisting of three lines:
* The first line contains a single integer n (1 ≤ n ≤ 100).
* The second line contains three integers, a, b, c (0 ≤ a, b, c ≤ n). It is guaranteed that a + b + c = n.
* The third line contains a string s of length n. s is made up of only 'R', 'P', and 'S'. The i-th character is 'R' if for his i-th Bob plays rock, 'P' if paper, and 'S' if scissors.
Output
For each testcase:
* If Alice cannot win, print "NO" (without the quotes).
* Otherwise, print "YES" (without the quotes). Also, print a string t of length n made up of only 'R', 'P', and 'S' — a sequence of hands that Alice can use to win. t must contain exactly a 'R's, b 'P's, and c 'S's.
* If there are multiple answers, print any of them.
The "YES" / "NO" part of the output is case-insensitive (i.e. "yEs", "no" or "YEs" are all valid answers). Note that 'R', 'P' and 'S' are case-sensitive.
Example
Input
2
3
1 1 1
RPS
3
3 0 0
RPS
Output
YES
PSR
NO
Note
In the first testcase, in the first hand, Alice plays paper and Bob plays rock, so Alice beats Bob. In the second hand, Alice plays scissors and Bob plays paper, so Alice beats Bob. In the third hand, Alice plays rock and Bob plays scissors, so Alice beats Bob. Alice beat Bob 3 times, and 3 ≥ ⌈ 3/2 ⌉ = 2, so Alice wins.
In the second testcase, the only sequence of hands that Alice can play is "RRR". Alice beats Bob only in the last hand, so Alice can't win. 1 < ⌈ 3/2 ⌉ = 2.
Submitted Solution:
```
import math
cases = int(input())
for case in range(cases):
n = int(input())
a_rock, a_paper, a_scissors = map(int, input().split())
rocks, papers, scissors = 0, 0, 0
b_plays = input()
for c in b_plays:
if c=='R' and a_paper:
a_paper -= 1
papers += 1
if c=='P' and a_scissors:
a_scissors -= 1
scissors += 1
if c=='S' and a_rock:
a_rock -= 1
rocks += 1
if sum([rocks, papers, scissors])*2 >= n:
print('YES')
for c in b_plays:
if c=='R' and papers:
papers -= 1
print('P', end='')
elif c=='P' and scissors:
scissors -= 1
print('S', end='')
elif c=='S' and rocks:
rocks -= 1
print('R', end='')
else:
if a_rock:
a_rock -= 1
print('R', end='')
if a_paper:
a_paper -= 1
print('P', end='')
if a_scissors:
a_scissors -= 1
print('S', end='')
print('')
else:
print('NO')
``` | instruction | 0 | 79,264 | 19 | 158,528 |
No | output | 1 | 79,264 | 19 | 158,529 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let n be a positive integer. Let a, b, c be nonnegative integers such that a + b + c = n.
Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock a times, paper b times, and scissors c times.
Alice wins if she beats Bob in at least ⌈ n/2 ⌉ (n/2 rounded up to the nearest integer) hands, otherwise Alice loses.
Note that in rock-paper-scissors:
* rock beats scissors;
* paper beats rock;
* scissors beat paper.
The task is, given the sequence of hands that Bob will play, and the numbers a, b, c, determine whether or not Alice can win. And if so, find any possible sequence of hands that Alice can use to win.
If there are multiple answers, print any of them.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases.
Then, t testcases follow, each consisting of three lines:
* The first line contains a single integer n (1 ≤ n ≤ 100).
* The second line contains three integers, a, b, c (0 ≤ a, b, c ≤ n). It is guaranteed that a + b + c = n.
* The third line contains a string s of length n. s is made up of only 'R', 'P', and 'S'. The i-th character is 'R' if for his i-th Bob plays rock, 'P' if paper, and 'S' if scissors.
Output
For each testcase:
* If Alice cannot win, print "NO" (without the quotes).
* Otherwise, print "YES" (without the quotes). Also, print a string t of length n made up of only 'R', 'P', and 'S' — a sequence of hands that Alice can use to win. t must contain exactly a 'R's, b 'P's, and c 'S's.
* If there are multiple answers, print any of them.
The "YES" / "NO" part of the output is case-insensitive (i.e. "yEs", "no" or "YEs" are all valid answers). Note that 'R', 'P' and 'S' are case-sensitive.
Example
Input
2
3
1 1 1
RPS
3
3 0 0
RPS
Output
YES
PSR
NO
Note
In the first testcase, in the first hand, Alice plays paper and Bob plays rock, so Alice beats Bob. In the second hand, Alice plays scissors and Bob plays paper, so Alice beats Bob. In the third hand, Alice plays rock and Bob plays scissors, so Alice beats Bob. Alice beat Bob 3 times, and 3 ≥ ⌈ 3/2 ⌉ = 2, so Alice wins.
In the second testcase, the only sequence of hands that Alice can play is "RRR". Alice beats Bob only in the last hand, so Alice can't win. 1 < ⌈ 3/2 ⌉ = 2.
Submitted Solution:
```
import sys
import math
#import os.path
#if os.path.isfile("input.txt"):
# _file = open("input.txt")
#def readline():
# return _file.readline();
def readline():
return input()
def fun(n, a, b, c, s):
ans = ["-"] * n
w = 0
for i in range(n):
if s[i] == "R":
if b > 0:
b = b-1
ans[i] = "P"
w = w + 1
else:
ans[i] = "-"
if s[i] == "P":
if c > 0:
c = c-1
ans[i] = "S"
w = w + 1
else:
ans[i] = "-"
if s[i] == "S":
if a > 0:
a = a-1
ans[i] = "R"
w = w + 1
else:
ans[i] = "-"
for i in range(n):
if ans[i] == "-":
if a > 0: ans[i] = "R"; a = a-1
if b > 0: ans[i] = "P"; b = b-1
if c > 0: ans[i] = "S"; c = c-1
if w >= math.ceil(n/2):
print("YES")
print("".join(ans))
else:
print("NO")
q = int(readline())
for i in range(q):
n = int(readline())
v = list(map(int, readline().split(' ')))
s = readline()
#c = list(map(int, readline().split(' ')))
ans = fun(n, v[0], v[1], v[2], s)
``` | instruction | 0 | 79,265 | 19 | 158,530 |
No | output | 1 | 79,265 | 19 | 158,531 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let n be a positive integer. Let a, b, c be nonnegative integers such that a + b + c = n.
Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock a times, paper b times, and scissors c times.
Alice wins if she beats Bob in at least ⌈ n/2 ⌉ (n/2 rounded up to the nearest integer) hands, otherwise Alice loses.
Note that in rock-paper-scissors:
* rock beats scissors;
* paper beats rock;
* scissors beat paper.
The task is, given the sequence of hands that Bob will play, and the numbers a, b, c, determine whether or not Alice can win. And if so, find any possible sequence of hands that Alice can use to win.
If there are multiple answers, print any of them.
Input
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases.
Then, t testcases follow, each consisting of three lines:
* The first line contains a single integer n (1 ≤ n ≤ 100).
* The second line contains three integers, a, b, c (0 ≤ a, b, c ≤ n). It is guaranteed that a + b + c = n.
* The third line contains a string s of length n. s is made up of only 'R', 'P', and 'S'. The i-th character is 'R' if for his i-th Bob plays rock, 'P' if paper, and 'S' if scissors.
Output
For each testcase:
* If Alice cannot win, print "NO" (without the quotes).
* Otherwise, print "YES" (without the quotes). Also, print a string t of length n made up of only 'R', 'P', and 'S' — a sequence of hands that Alice can use to win. t must contain exactly a 'R's, b 'P's, and c 'S's.
* If there are multiple answers, print any of them.
The "YES" / "NO" part of the output is case-insensitive (i.e. "yEs", "no" or "YEs" are all valid answers). Note that 'R', 'P' and 'S' are case-sensitive.
Example
Input
2
3
1 1 1
RPS
3
3 0 0
RPS
Output
YES
PSR
NO
Note
In the first testcase, in the first hand, Alice plays paper and Bob plays rock, so Alice beats Bob. In the second hand, Alice plays scissors and Bob plays paper, so Alice beats Bob. In the third hand, Alice plays rock and Bob plays scissors, so Alice beats Bob. Alice beat Bob 3 times, and 3 ≥ ⌈ 3/2 ⌉ = 2, so Alice wins.
In the second testcase, the only sequence of hands that Alice can play is "RRR". Alice beats Bob only in the last hand, so Alice can't win. 1 < ⌈ 3/2 ⌉ = 2.
Submitted Solution:
```
import math
T = int(input())
while T > 0:
# R, P, S
n = int(input())
a, b, c = map(int, input().split())
seq = input()
aliceWins = 0
bobWins = 0
winCombo = ''
for ch in seq:
if ch == 'R':
if b > 0:
winCombo += 'P'
b -= 1
aliceWins += 1
else:
bobWins += 1
winCombo += 'x' # Fill these positions later
elif ch == 'P':
if a > 0:
winCombo += 'S'
a -= 1
aliceWins += 1
else:
bobWins += 1
winCombo += 'x'
else:
if c > 0:
winCombo += 'R'
c -= 1
aliceWins += 1
else:
bobWins += 1
winCombo += 'x'
winCombo = list(winCombo)
for i in range(len(winCombo)):
if winCombo[i] == 'x':
if a > 0:
winCombo[i] = 'R'
a -= 1
elif b > 0:
winCombo[i] = 'P'
b -= 1
else:
winCombo[i] = 'S'
c -= 1
winCombo = ''.join(winCombo)
if aliceWins >= math.ceil(n/2):
print("YES")
print(winCombo)
else:
print("NO")
T -= 1
``` | instruction | 0 | 79,266 | 19 | 158,532 |
No | output | 1 | 79,266 | 19 | 158,533 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are n players arranged in a circle, so that for all j such that 2 ≤ j ≤ n, player j - 1 is to the left of the player j, and player j is to the right of player j - 1. Additionally, player n is to the left of player 1, and player 1 is to the right of player n.
Currently, each player is attacking either the player to their left or the player to their right. This means that each player is currently being attacked by either 0, 1, or 2 other players. A key element of Bed Wars strategy is that if a player is being attacked by exactly 1 other player, then they should logically attack that player in response. If instead a player is being attacked by 0 or 2 other players, then Bed Wars strategy says that the player can logically attack either of the adjacent players.
Unfortunately, it might be that some players in this game are not following Bed Wars strategy correctly. Omkar is aware of whom each player is currently attacking, and he can talk to any amount of the n players in the game to make them instead attack another player — i. e. if they are currently attacking the player to their left, Omkar can convince them to instead attack the player to their right; if they are currently attacking the player to their right, Omkar can convince them to instead attack the player to their left.
Omkar would like all players to be acting logically. Calculate the minimum amount of players that Omkar needs to talk to so that after all players he talked to (if any) have changed which player they are attacking, all players are acting logically according to Bed Wars strategy.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). The descriptions of the test cases follows.
The first line of each test case contains one integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the amount of players (and therefore beds) in this game of Bed Wars.
The second line of each test case contains a string s of length n. The j-th character of s is equal to L if the j-th player is attacking the player to their left, and R if the j-th player is attacking the player to their right.
It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5.
Output
For each test case, output one integer: the minimum number of players Omkar needs to talk to to make it so that all players are acting logically according to Bed Wars strategy.
It can be proven that it is always possible for Omkar to achieve this under the given constraints.
Example
Input
5
4
RLRL
6
LRRRRL
8
RLLRRRLL
12
LLLLRRLRRRLL
5
RRRRR
Output
0
1
1
3
2
Note
In the first test case, players 1 and 2 are attacking each other, and players 3 and 4 are attacking each other. Each player is being attacked by exactly 1 other player, and each player is attacking the player that is attacking them, so all players are already being logical according to Bed Wars strategy and Omkar does not need to talk to any of them, making the answer 0.
In the second test case, not every player acts logically: for example, player 3 is attacked only by player 2, but doesn't attack him in response. Omkar can talk to player 3 to convert the attack arrangement to LRLRRL, in which you can see that all players are being logical according to Bed Wars strategy, making the answer 1. | instruction | 0 | 79,318 | 19 | 158,636 |
Tags: dp, greedy
Correct Solution:
```
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
import random
########################################################
for _ in range(int(input())):
n=int(input())
A=list(input())
if len(set(A))==1:
print((n+2)//3)
continue
cur=1
x=[]
for i in range(n):
if A[i]==A[(i+1)%n]:
cur+=1
else:
x.append(cur)
cur=1
if A[0]==A[-1]:
x[0]+=cur-1
ans=0
for i in x:
ans+=i//3
print(ans)
``` | output | 1 | 79,318 | 19 | 158,637 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are n players arranged in a circle, so that for all j such that 2 ≤ j ≤ n, player j - 1 is to the left of the player j, and player j is to the right of player j - 1. Additionally, player n is to the left of player 1, and player 1 is to the right of player n.
Currently, each player is attacking either the player to their left or the player to their right. This means that each player is currently being attacked by either 0, 1, or 2 other players. A key element of Bed Wars strategy is that if a player is being attacked by exactly 1 other player, then they should logically attack that player in response. If instead a player is being attacked by 0 or 2 other players, then Bed Wars strategy says that the player can logically attack either of the adjacent players.
Unfortunately, it might be that some players in this game are not following Bed Wars strategy correctly. Omkar is aware of whom each player is currently attacking, and he can talk to any amount of the n players in the game to make them instead attack another player — i. e. if they are currently attacking the player to their left, Omkar can convince them to instead attack the player to their right; if they are currently attacking the player to their right, Omkar can convince them to instead attack the player to their left.
Omkar would like all players to be acting logically. Calculate the minimum amount of players that Omkar needs to talk to so that after all players he talked to (if any) have changed which player they are attacking, all players are acting logically according to Bed Wars strategy.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). The descriptions of the test cases follows.
The first line of each test case contains one integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the amount of players (and therefore beds) in this game of Bed Wars.
The second line of each test case contains a string s of length n. The j-th character of s is equal to L if the j-th player is attacking the player to their left, and R if the j-th player is attacking the player to their right.
It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5.
Output
For each test case, output one integer: the minimum number of players Omkar needs to talk to to make it so that all players are acting logically according to Bed Wars strategy.
It can be proven that it is always possible for Omkar to achieve this under the given constraints.
Example
Input
5
4
RLRL
6
LRRRRL
8
RLLRRRLL
12
LLLLRRLRRRLL
5
RRRRR
Output
0
1
1
3
2
Note
In the first test case, players 1 and 2 are attacking each other, and players 3 and 4 are attacking each other. Each player is being attacked by exactly 1 other player, and each player is attacking the player that is attacking them, so all players are already being logical according to Bed Wars strategy and Omkar does not need to talk to any of them, making the answer 0.
In the second test case, not every player acts logically: for example, player 3 is attacked only by player 2, but doesn't attack him in response. Omkar can talk to player 3 to convert the attack arrangement to LRLRRL, in which you can see that all players are being logical according to Bed Wars strategy, making the answer 1. | instruction | 0 | 79,319 | 19 | 158,638 |
Tags: dp, greedy
Correct Solution:
```
'''
I believe on myself and I will achieve
this->author = Fuad Ashraful Mehmet, CSE-UAP
Todo:
শনি সেপ্টেম্বর 19 13:22:33 +06 2020
'''
for _ in range(int(input())):
n=int(input())
s=input()
s=[ _ for _ in s]
res=0
i=0
l=0
while i<n-1 and s[i]==s[i+1]:
i+=1
while (l+n-1)%n!=i and s[(l+n-1)%n]==s[i]:
l-=1
if(l+n-1)%n==i:
res=(n+2)//3
print(res)
continue
res+=(i-l+1)//3
h=n
if l!=0:
h=(l+n)%n
i+=1
while i<h:
r=i
while r<h and s[r]==s[(r+1)%n]:
r+=1
res+=(r-i+1)//3
i=r+1
print(res)
``` | output | 1 | 79,319 | 19 | 158,639 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are n players arranged in a circle, so that for all j such that 2 ≤ j ≤ n, player j - 1 is to the left of the player j, and player j is to the right of player j - 1. Additionally, player n is to the left of player 1, and player 1 is to the right of player n.
Currently, each player is attacking either the player to their left or the player to their right. This means that each player is currently being attacked by either 0, 1, or 2 other players. A key element of Bed Wars strategy is that if a player is being attacked by exactly 1 other player, then they should logically attack that player in response. If instead a player is being attacked by 0 or 2 other players, then Bed Wars strategy says that the player can logically attack either of the adjacent players.
Unfortunately, it might be that some players in this game are not following Bed Wars strategy correctly. Omkar is aware of whom each player is currently attacking, and he can talk to any amount of the n players in the game to make them instead attack another player — i. e. if they are currently attacking the player to their left, Omkar can convince them to instead attack the player to their right; if they are currently attacking the player to their right, Omkar can convince them to instead attack the player to their left.
Omkar would like all players to be acting logically. Calculate the minimum amount of players that Omkar needs to talk to so that after all players he talked to (if any) have changed which player they are attacking, all players are acting logically according to Bed Wars strategy.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). The descriptions of the test cases follows.
The first line of each test case contains one integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the amount of players (and therefore beds) in this game of Bed Wars.
The second line of each test case contains a string s of length n. The j-th character of s is equal to L if the j-th player is attacking the player to their left, and R if the j-th player is attacking the player to their right.
It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5.
Output
For each test case, output one integer: the minimum number of players Omkar needs to talk to to make it so that all players are acting logically according to Bed Wars strategy.
It can be proven that it is always possible for Omkar to achieve this under the given constraints.
Example
Input
5
4
RLRL
6
LRRRRL
8
RLLRRRLL
12
LLLLRRLRRRLL
5
RRRRR
Output
0
1
1
3
2
Note
In the first test case, players 1 and 2 are attacking each other, and players 3 and 4 are attacking each other. Each player is being attacked by exactly 1 other player, and each player is attacking the player that is attacking them, so all players are already being logical according to Bed Wars strategy and Omkar does not need to talk to any of them, making the answer 0.
In the second test case, not every player acts logically: for example, player 3 is attacked only by player 2, but doesn't attack him in response. Omkar can talk to player 3 to convert the attack arrangement to LRLRRL, in which you can see that all players are being logical according to Bed Wars strategy, making the answer 1. | instruction | 0 | 79,320 | 19 | 158,640 |
Tags: dp, greedy
Correct Solution:
```
kase = int(input().strip())
while kase > 0:
kase = kase - 1
n = int(input().strip())
s = [str(si) for si in input().strip()]
slen = len(s)
ans = 0
if len(list({}.fromkeys(s).keys())) == 1:
print((slen - 1) // 3 + 1)
continue
for i, si in enumerate(s):
u = i
v = (i + 1) % slen
if s[u] is 'R' and s[v] is 'L':
cnt_r = 0
while s[u] == 'R':
cnt_r = cnt_r + 1
u = (u + slen - 1) % slen
cnt_l = 0
while s[v] == 'L':
cnt_l = cnt_l + 1
v = (v + 1) % slen
ans = ans + cnt_l // 3 + cnt_r // 3
print(ans)
``` | output | 1 | 79,320 | 19 | 158,641 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are n players arranged in a circle, so that for all j such that 2 ≤ j ≤ n, player j - 1 is to the left of the player j, and player j is to the right of player j - 1. Additionally, player n is to the left of player 1, and player 1 is to the right of player n.
Currently, each player is attacking either the player to their left or the player to their right. This means that each player is currently being attacked by either 0, 1, or 2 other players. A key element of Bed Wars strategy is that if a player is being attacked by exactly 1 other player, then they should logically attack that player in response. If instead a player is being attacked by 0 or 2 other players, then Bed Wars strategy says that the player can logically attack either of the adjacent players.
Unfortunately, it might be that some players in this game are not following Bed Wars strategy correctly. Omkar is aware of whom each player is currently attacking, and he can talk to any amount of the n players in the game to make them instead attack another player — i. e. if they are currently attacking the player to their left, Omkar can convince them to instead attack the player to their right; if they are currently attacking the player to their right, Omkar can convince them to instead attack the player to their left.
Omkar would like all players to be acting logically. Calculate the minimum amount of players that Omkar needs to talk to so that after all players he talked to (if any) have changed which player they are attacking, all players are acting logically according to Bed Wars strategy.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). The descriptions of the test cases follows.
The first line of each test case contains one integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the amount of players (and therefore beds) in this game of Bed Wars.
The second line of each test case contains a string s of length n. The j-th character of s is equal to L if the j-th player is attacking the player to their left, and R if the j-th player is attacking the player to their right.
It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5.
Output
For each test case, output one integer: the minimum number of players Omkar needs to talk to to make it so that all players are acting logically according to Bed Wars strategy.
It can be proven that it is always possible for Omkar to achieve this under the given constraints.
Example
Input
5
4
RLRL
6
LRRRRL
8
RLLRRRLL
12
LLLLRRLRRRLL
5
RRRRR
Output
0
1
1
3
2
Note
In the first test case, players 1 and 2 are attacking each other, and players 3 and 4 are attacking each other. Each player is being attacked by exactly 1 other player, and each player is attacking the player that is attacking them, so all players are already being logical according to Bed Wars strategy and Omkar does not need to talk to any of them, making the answer 0.
In the second test case, not every player acts logically: for example, player 3 is attacked only by player 2, but doesn't attack him in response. Omkar can talk to player 3 to convert the attack arrangement to LRLRRL, in which you can see that all players are being logical according to Bed Wars strategy, making the answer 1. | instruction | 0 | 79,321 | 19 | 158,642 |
Tags: dp, greedy
Correct Solution:
```
# from debug import debug
import sys;input = sys.stdin.readline
from math import ceil
inf = int(1e10)
t = int(input())
for _ in range(t):
n = int(input())
lis = list(input().strip())
p = [0]*n
for i in range(0, n):
if lis[((i-1)%n)%n] != lis[i%n] or lis[i%n] != lis[(i+1)%n]: p[i] = 1
else: p[i] = 0
ans = []
i = 0
for j in range(n):
if p[j] == 1: i = j; break
r = i
while i<n+r:
if p[i%n] == 0:
v = i
while i<n+r and p[i%n] == 0: i+=1
vv = i-1
ans.append((v, vv))
i+=1
val = 0
for i in ans:
l = i[1]-i[0]+1
if l in (1, 2, 3): val += 1
else: val += ceil(l/3)
print(val)
``` | output | 1 | 79,321 | 19 | 158,643 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are n players arranged in a circle, so that for all j such that 2 ≤ j ≤ n, player j - 1 is to the left of the player j, and player j is to the right of player j - 1. Additionally, player n is to the left of player 1, and player 1 is to the right of player n.
Currently, each player is attacking either the player to their left or the player to their right. This means that each player is currently being attacked by either 0, 1, or 2 other players. A key element of Bed Wars strategy is that if a player is being attacked by exactly 1 other player, then they should logically attack that player in response. If instead a player is being attacked by 0 or 2 other players, then Bed Wars strategy says that the player can logically attack either of the adjacent players.
Unfortunately, it might be that some players in this game are not following Bed Wars strategy correctly. Omkar is aware of whom each player is currently attacking, and he can talk to any amount of the n players in the game to make them instead attack another player — i. e. if they are currently attacking the player to their left, Omkar can convince them to instead attack the player to their right; if they are currently attacking the player to their right, Omkar can convince them to instead attack the player to their left.
Omkar would like all players to be acting logically. Calculate the minimum amount of players that Omkar needs to talk to so that after all players he talked to (if any) have changed which player they are attacking, all players are acting logically according to Bed Wars strategy.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). The descriptions of the test cases follows.
The first line of each test case contains one integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the amount of players (and therefore beds) in this game of Bed Wars.
The second line of each test case contains a string s of length n. The j-th character of s is equal to L if the j-th player is attacking the player to their left, and R if the j-th player is attacking the player to their right.
It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5.
Output
For each test case, output one integer: the minimum number of players Omkar needs to talk to to make it so that all players are acting logically according to Bed Wars strategy.
It can be proven that it is always possible for Omkar to achieve this under the given constraints.
Example
Input
5
4
RLRL
6
LRRRRL
8
RLLRRRLL
12
LLLLRRLRRRLL
5
RRRRR
Output
0
1
1
3
2
Note
In the first test case, players 1 and 2 are attacking each other, and players 3 and 4 are attacking each other. Each player is being attacked by exactly 1 other player, and each player is attacking the player that is attacking them, so all players are already being logical according to Bed Wars strategy and Omkar does not need to talk to any of them, making the answer 0.
In the second test case, not every player acts logically: for example, player 3 is attacked only by player 2, but doesn't attack him in response. Omkar can talk to player 3 to convert the attack arrangement to LRLRRL, in which you can see that all players are being logical according to Bed Wars strategy, making the answer 1. | instruction | 0 | 79,322 | 19 | 158,644 |
Tags: dp, greedy
Correct Solution:
```
import sys
input = sys.stdin.readline
'''
RLR
RRL
RLL
LRL
LRR
LLR
'''
t = int(input())
ss = ['LLL','LLR','LRL','LRR','RLL','RLR','RRL','RRR']
ok = ['LLR','LRL','LRR','RLL','RLR','RRL']
D = {}
for s1 in ss:
for s2 in ss:
c = 0
for i in range(3):
if s1[i] != s2[i]:
c += 1
D[(s1,s2)] = c
for _ in range(t):
x = int(input())
#l = list(map(int,input().split()))
vl = input().rstrip()
#RLRLRRLRLRLL
v_best = 10**8
for kk in range(3):
l = vl[kk:] + vl[:kk]
B = {}
init = l[:3]
for s in ok:
B[s] = D[(s,init)]
if s[0] != init[0] or s[1]!=init[1]:
B[s] += 10**8
for i in range(1, x-2):
sub = l[i:i+3]
G = dict(B)
for key in ok:
best = 10**8
c = 0
if sub[2] != key[2]:
c+=1
for sub_key in ok:
if sub_key[1:] == key[:2]:
best = min(best, B[sub_key])
G[key] = c + best
B = dict(G)
ans1 = 10**8
for key in B:
if key[1:] + init[0] in ok and key[2:] + init[:2] in ok:
ans1 = min(ans1,B[key])
v_best = min(v_best,ans1)
print(v_best)
``` | output | 1 | 79,322 | 19 | 158,645 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are n players arranged in a circle, so that for all j such that 2 ≤ j ≤ n, player j - 1 is to the left of the player j, and player j is to the right of player j - 1. Additionally, player n is to the left of player 1, and player 1 is to the right of player n.
Currently, each player is attacking either the player to their left or the player to their right. This means that each player is currently being attacked by either 0, 1, or 2 other players. A key element of Bed Wars strategy is that if a player is being attacked by exactly 1 other player, then they should logically attack that player in response. If instead a player is being attacked by 0 or 2 other players, then Bed Wars strategy says that the player can logically attack either of the adjacent players.
Unfortunately, it might be that some players in this game are not following Bed Wars strategy correctly. Omkar is aware of whom each player is currently attacking, and he can talk to any amount of the n players in the game to make them instead attack another player — i. e. if they are currently attacking the player to their left, Omkar can convince them to instead attack the player to their right; if they are currently attacking the player to their right, Omkar can convince them to instead attack the player to their left.
Omkar would like all players to be acting logically. Calculate the minimum amount of players that Omkar needs to talk to so that after all players he talked to (if any) have changed which player they are attacking, all players are acting logically according to Bed Wars strategy.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). The descriptions of the test cases follows.
The first line of each test case contains one integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the amount of players (and therefore beds) in this game of Bed Wars.
The second line of each test case contains a string s of length n. The j-th character of s is equal to L if the j-th player is attacking the player to their left, and R if the j-th player is attacking the player to their right.
It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5.
Output
For each test case, output one integer: the minimum number of players Omkar needs to talk to to make it so that all players are acting logically according to Bed Wars strategy.
It can be proven that it is always possible for Omkar to achieve this under the given constraints.
Example
Input
5
4
RLRL
6
LRRRRL
8
RLLRRRLL
12
LLLLRRLRRRLL
5
RRRRR
Output
0
1
1
3
2
Note
In the first test case, players 1 and 2 are attacking each other, and players 3 and 4 are attacking each other. Each player is being attacked by exactly 1 other player, and each player is attacking the player that is attacking them, so all players are already being logical according to Bed Wars strategy and Omkar does not need to talk to any of them, making the answer 0.
In the second test case, not every player acts logically: for example, player 3 is attacked only by player 2, but doesn't attack him in response. Omkar can talk to player 3 to convert the attack arrangement to LRLRRL, in which you can see that all players are being logical according to Bed Wars strategy, making the answer 1. | instruction | 0 | 79,323 | 19 | 158,646 |
Tags: dp, greedy
Correct Solution:
```
t = int(input())
while t:
t -= 1
n = int(input())
a = list(input())
ans = 0
cnt = 1
while len(a)>1:
if a[0] != a[-1]:
break
cnt += 1
a.pop(-1)
if len(a) == 1:
if cnt <= 2:
print(0)
elif cnt == 3:
print(1)
else:
print(int((cnt + 2) / 3))
continue
for i in range(1, len(a)):
cnt += 1
if a[i] != a[i-1]:
ans += int((cnt-1) / 3)
cnt = 1
ans+=int(cnt/3)
print(ans)
``` | output | 1 | 79,323 | 19 | 158,647 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are n players arranged in a circle, so that for all j such that 2 ≤ j ≤ n, player j - 1 is to the left of the player j, and player j is to the right of player j - 1. Additionally, player n is to the left of player 1, and player 1 is to the right of player n.
Currently, each player is attacking either the player to their left or the player to their right. This means that each player is currently being attacked by either 0, 1, or 2 other players. A key element of Bed Wars strategy is that if a player is being attacked by exactly 1 other player, then they should logically attack that player in response. If instead a player is being attacked by 0 or 2 other players, then Bed Wars strategy says that the player can logically attack either of the adjacent players.
Unfortunately, it might be that some players in this game are not following Bed Wars strategy correctly. Omkar is aware of whom each player is currently attacking, and he can talk to any amount of the n players in the game to make them instead attack another player — i. e. if they are currently attacking the player to their left, Omkar can convince them to instead attack the player to their right; if they are currently attacking the player to their right, Omkar can convince them to instead attack the player to their left.
Omkar would like all players to be acting logically. Calculate the minimum amount of players that Omkar needs to talk to so that after all players he talked to (if any) have changed which player they are attacking, all players are acting logically according to Bed Wars strategy.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). The descriptions of the test cases follows.
The first line of each test case contains one integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the amount of players (and therefore beds) in this game of Bed Wars.
The second line of each test case contains a string s of length n. The j-th character of s is equal to L if the j-th player is attacking the player to their left, and R if the j-th player is attacking the player to their right.
It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5.
Output
For each test case, output one integer: the minimum number of players Omkar needs to talk to to make it so that all players are acting logically according to Bed Wars strategy.
It can be proven that it is always possible for Omkar to achieve this under the given constraints.
Example
Input
5
4
RLRL
6
LRRRRL
8
RLLRRRLL
12
LLLLRRLRRRLL
5
RRRRR
Output
0
1
1
3
2
Note
In the first test case, players 1 and 2 are attacking each other, and players 3 and 4 are attacking each other. Each player is being attacked by exactly 1 other player, and each player is attacking the player that is attacking them, so all players are already being logical according to Bed Wars strategy and Omkar does not need to talk to any of them, making the answer 0.
In the second test case, not every player acts logically: for example, player 3 is attacked only by player 2, but doesn't attack him in response. Omkar can talk to player 3 to convert the attack arrangement to LRLRRL, in which you can see that all players are being logical according to Bed Wars strategy, making the answer 1. | instruction | 0 | 79,324 | 19 | 158,648 |
Tags: dp, greedy
Correct Solution:
```
t = int(input())
for _ in range(t):
n = int(input())
l = list(input())
ans = float("INF")
for i in range(n):
if l[i] != l[i-1]:
count = 0
now = 0
c = l[i]
for j in range(n):
if l[(i+j)%n] == c:
now += 1
else:
count += now//3
now = 1
c = l[(i+j)%n]
count += now//3
ans = min(ans,count)
break
if ans == float("INF"):
print((n+2)//3)
else:
print(ans)
``` | output | 1 | 79,324 | 19 | 158,649 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are n players arranged in a circle, so that for all j such that 2 ≤ j ≤ n, player j - 1 is to the left of the player j, and player j is to the right of player j - 1. Additionally, player n is to the left of player 1, and player 1 is to the right of player n.
Currently, each player is attacking either the player to their left or the player to their right. This means that each player is currently being attacked by either 0, 1, or 2 other players. A key element of Bed Wars strategy is that if a player is being attacked by exactly 1 other player, then they should logically attack that player in response. If instead a player is being attacked by 0 or 2 other players, then Bed Wars strategy says that the player can logically attack either of the adjacent players.
Unfortunately, it might be that some players in this game are not following Bed Wars strategy correctly. Omkar is aware of whom each player is currently attacking, and he can talk to any amount of the n players in the game to make them instead attack another player — i. e. if they are currently attacking the player to their left, Omkar can convince them to instead attack the player to their right; if they are currently attacking the player to their right, Omkar can convince them to instead attack the player to their left.
Omkar would like all players to be acting logically. Calculate the minimum amount of players that Omkar needs to talk to so that after all players he talked to (if any) have changed which player they are attacking, all players are acting logically according to Bed Wars strategy.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). The descriptions of the test cases follows.
The first line of each test case contains one integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the amount of players (and therefore beds) in this game of Bed Wars.
The second line of each test case contains a string s of length n. The j-th character of s is equal to L if the j-th player is attacking the player to their left, and R if the j-th player is attacking the player to their right.
It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5.
Output
For each test case, output one integer: the minimum number of players Omkar needs to talk to to make it so that all players are acting logically according to Bed Wars strategy.
It can be proven that it is always possible for Omkar to achieve this under the given constraints.
Example
Input
5
4
RLRL
6
LRRRRL
8
RLLRRRLL
12
LLLLRRLRRRLL
5
RRRRR
Output
0
1
1
3
2
Note
In the first test case, players 1 and 2 are attacking each other, and players 3 and 4 are attacking each other. Each player is being attacked by exactly 1 other player, and each player is attacking the player that is attacking them, so all players are already being logical according to Bed Wars strategy and Omkar does not need to talk to any of them, making the answer 0.
In the second test case, not every player acts logically: for example, player 3 is attacked only by player 2, but doesn't attack him in response. Omkar can talk to player 3 to convert the attack arrangement to LRLRRL, in which you can see that all players are being logical according to Bed Wars strategy, making the answer 1. | instruction | 0 | 79,325 | 19 | 158,650 |
Tags: dp, greedy
Correct Solution:
```
from collections import deque
from collections import OrderedDict
import math
import sys
import os
import threading
import bisect
import operator
import heapq
from atexit import register
from io import BytesIO
#sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
#sys.stdout = BytesIO()
#register(lambda: os.write(1, sys.stdout.getvalue()))
import io
#input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
#sys.stdin = open("F:\PY\\test.txt", "r")
input = lambda: sys.stdin.readline().rstrip("\r\n")
#input = sys.stdin.readline
#a = [int(x) for x in input().split()]
for _ in range(int(input())):
n = int(input())
s = input()
dp = [1]*(n+3)
for i in range(1, n):
if s[i]==s[i-1]:
dp[i]=dp[i-1]+1
isCircle = False
if s[0]==s[n-1]:
if (s.count('R')!=0 and s.count('L')!=0):
dp[n]=0
for i in range(n-1):
if s[i]==s[n-1]:
dp[n]+=1
dp[i]=1
else:
break
for i in range(n-1, 0, -1):
if s[i]==s[0]:
dp[n]+=1
dp[i]=1
else:
break
else:
if n>2:
print(n//3+(1 if n%3!=0 else 0))
else:
print(0)
continue
lisAnswer = []
for i in range(1, n+1):
if dp[i]>2 and dp[i+1]==1:
lisAnswer.append(dp[i])
answer = 0
for i in range(len(lisAnswer)):
answer+=lisAnswer[i]//3
print(answer)
sys.exit(0)
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
p1 = Person("heelo", 27)
print(help(Person))
age = 26
name = 'Swaroop'
print('Возрас {} -- {} лет'.format(name, age))
print(help(object))
'''
for _ in range(int(input())):
n = int(input())
ar = list(map(int, input().split()))
dp = [0]*100005
for i in range(n):
dp[ar[i]]+=1
ar.clear()
for i in range(len(dp)):
if dp[i]!=0:
ar.append(dp[i])
ar.sort()
maxC = ar[len(ar)-1]
sumA = sum(ar)
answer=0
for i in range(len(ar)):
if ar[i]==maxC:
answer+=1
sumA-=maxC
answer-=1
answer+= min(sumA//(maxC-1), len(ar)-1)
print(answer)
#sys.exit(0)
def maxDisjointIntervals(list_):
list_.sort(key=lambda x: x[1])
print(list_[0][0], list_[0][1])
r1 = list_[0][1]
for i in range(1, len(list_)):
l1 = list_[i][0]
r2 = list_[i][1]
if l1>r1:
print(l1, r2)
r1 = r2
if __name__ =="__main__1":
N=4
intervals = [[1, 4], [2, 3], [4,6], [8,9]]
maxDisjointIntervals(intervals)
'''
``` | output | 1 | 79,325 | 19 | 158,651 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are n players arranged in a circle, so that for all j such that 2 ≤ j ≤ n, player j - 1 is to the left of the player j, and player j is to the right of player j - 1. Additionally, player n is to the left of player 1, and player 1 is to the right of player n.
Currently, each player is attacking either the player to their left or the player to their right. This means that each player is currently being attacked by either 0, 1, or 2 other players. A key element of Bed Wars strategy is that if a player is being attacked by exactly 1 other player, then they should logically attack that player in response. If instead a player is being attacked by 0 or 2 other players, then Bed Wars strategy says that the player can logically attack either of the adjacent players.
Unfortunately, it might be that some players in this game are not following Bed Wars strategy correctly. Omkar is aware of whom each player is currently attacking, and he can talk to any amount of the n players in the game to make them instead attack another player — i. e. if they are currently attacking the player to their left, Omkar can convince them to instead attack the player to their right; if they are currently attacking the player to their right, Omkar can convince them to instead attack the player to their left.
Omkar would like all players to be acting logically. Calculate the minimum amount of players that Omkar needs to talk to so that after all players he talked to (if any) have changed which player they are attacking, all players are acting logically according to Bed Wars strategy.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). The descriptions of the test cases follows.
The first line of each test case contains one integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the amount of players (and therefore beds) in this game of Bed Wars.
The second line of each test case contains a string s of length n. The j-th character of s is equal to L if the j-th player is attacking the player to their left, and R if the j-th player is attacking the player to their right.
It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5.
Output
For each test case, output one integer: the minimum number of players Omkar needs to talk to to make it so that all players are acting logically according to Bed Wars strategy.
It can be proven that it is always possible for Omkar to achieve this under the given constraints.
Example
Input
5
4
RLRL
6
LRRRRL
8
RLLRRRLL
12
LLLLRRLRRRLL
5
RRRRR
Output
0
1
1
3
2
Note
In the first test case, players 1 and 2 are attacking each other, and players 3 and 4 are attacking each other. Each player is being attacked by exactly 1 other player, and each player is attacking the player that is attacking them, so all players are already being logical according to Bed Wars strategy and Omkar does not need to talk to any of them, making the answer 0.
In the second test case, not every player acts logically: for example, player 3 is attacked only by player 2, but doesn't attack him in response. Omkar can talk to player 3 to convert the attack arrangement to LRLRRL, in which you can see that all players are being logical according to Bed Wars strategy, making the answer 1.
Submitted Solution:
```
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------- fast io --------------------
from math import gcd, ceil
def pre(s):
n = len(s)
pi = [0] * n
for i in range(1, n):
j = pi[i - 1]
while j and s[i] != s[j]:
j = pi[j - 1]
if s[i] == s[j]:
j += 1
pi[i] = j
return pi
def prod(a):
ans = 1
for each in a:
ans = (ans * each)
return ans
def lcm(a, b): return a * b // gcd(a, b)
def binary(x, length=16):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
def calc(a, v):
mxx = -1
ans = 0
for i in range(len(a)):
if mxx == -1:mxx = a[i]
ans += max(mxx, a[i]) - a[i]
mxx = max(mxx, a[i])
a[i] = mxx
#print(ans, a)
bb = 0
for x in sorted(list(set(a)), reverse=True):
ans += v - bb - x
bb = v - x
return ans
def find(s):
start = 0
n = len(s)
if s[0] == s[-1]:
start = n-1
while start > 0 and s[start-1] == s[start]:
start -= 1
s += s
cur = s[start]
val = 0
a=[]
for i in range(start, start+n):
if s[i] == cur:
val += 1
else:
cur = s[i]
a += [val]
val = 1
a += [val]
#print(a,start)
ans = 0
for i in a:
ans += i // 3 if i != n else (i+2)//3
return ans
for _ in range(int(input()) if True else 1):
n = int(input())
#a, b = map(int, input().split())
#c, d = map(int, input().split())
s = input()
print(find(s))
``` | instruction | 0 | 79,326 | 19 | 158,652 |
Yes | output | 1 | 79,326 | 19 | 158,653 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are n players arranged in a circle, so that for all j such that 2 ≤ j ≤ n, player j - 1 is to the left of the player j, and player j is to the right of player j - 1. Additionally, player n is to the left of player 1, and player 1 is to the right of player n.
Currently, each player is attacking either the player to their left or the player to their right. This means that each player is currently being attacked by either 0, 1, or 2 other players. A key element of Bed Wars strategy is that if a player is being attacked by exactly 1 other player, then they should logically attack that player in response. If instead a player is being attacked by 0 or 2 other players, then Bed Wars strategy says that the player can logically attack either of the adjacent players.
Unfortunately, it might be that some players in this game are not following Bed Wars strategy correctly. Omkar is aware of whom each player is currently attacking, and he can talk to any amount of the n players in the game to make them instead attack another player — i. e. if they are currently attacking the player to their left, Omkar can convince them to instead attack the player to their right; if they are currently attacking the player to their right, Omkar can convince them to instead attack the player to their left.
Omkar would like all players to be acting logically. Calculate the minimum amount of players that Omkar needs to talk to so that after all players he talked to (if any) have changed which player they are attacking, all players are acting logically according to Bed Wars strategy.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). The descriptions of the test cases follows.
The first line of each test case contains one integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the amount of players (and therefore beds) in this game of Bed Wars.
The second line of each test case contains a string s of length n. The j-th character of s is equal to L if the j-th player is attacking the player to their left, and R if the j-th player is attacking the player to their right.
It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5.
Output
For each test case, output one integer: the minimum number of players Omkar needs to talk to to make it so that all players are acting logically according to Bed Wars strategy.
It can be proven that it is always possible for Omkar to achieve this under the given constraints.
Example
Input
5
4
RLRL
6
LRRRRL
8
RLLRRRLL
12
LLLLRRLRRRLL
5
RRRRR
Output
0
1
1
3
2
Note
In the first test case, players 1 and 2 are attacking each other, and players 3 and 4 are attacking each other. Each player is being attacked by exactly 1 other player, and each player is attacking the player that is attacking them, so all players are already being logical according to Bed Wars strategy and Omkar does not need to talk to any of them, making the answer 0.
In the second test case, not every player acts logically: for example, player 3 is attacked only by player 2, but doesn't attack him in response. Omkar can talk to player 3 to convert the attack arrangement to LRLRRL, in which you can see that all players are being logical according to Bed Wars strategy, making the answer 1.
Submitted Solution:
```
from sys import stdin,stdout
from math import gcd,sqrt,factorial
from collections import deque,defaultdict
input=stdin.readline
R=lambda:map(int,input().split())
I=lambda:int(input())
S=lambda:input().rstrip('\n')
L=lambda:list(R())
P=lambda x:stdout.write(x)
lcm=lambda x,y:(x*y)//gcd(x,y)
hg=lambda x,y:((y+x-1)//x)*x
pw=lambda x:0 if x==1 else 1+pw(x//2)
chk=lambda x:chk(x//2) if not x%2 else True if x==1 else False
sm=lambda x:(x**2+x)//2
N=10**9+7
for _ in range(I()):
n=I()
s=S()
a=[]
for i in range(n):
if (s[(i-1)%n]=='R' and s[(i+1)%n]=='L') or (s[(i-1)%n]=='L' and s[(i+1)%n]=='R') or (s[(i-1)%n]=='R' and s[i]=='L') or (s[i]=='R' and s[(i+1)%n]=='L'):a+=0,
else:a+=1,
ans=0
val=[]
ind=-1
f=-1
for i in range(n):
if ind==-1:
if not a[i]:ind=i;f=i
else:
if not a[i]:
ans+=(i-ind-1+2)//3
ind=i
if ind==-1:print((n+2)//3)
else:print(ans+(n-ind-1+f+2)//3)
``` | instruction | 0 | 79,327 | 19 | 158,654 |
Yes | output | 1 | 79,327 | 19 | 158,655 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are n players arranged in a circle, so that for all j such that 2 ≤ j ≤ n, player j - 1 is to the left of the player j, and player j is to the right of player j - 1. Additionally, player n is to the left of player 1, and player 1 is to the right of player n.
Currently, each player is attacking either the player to their left or the player to their right. This means that each player is currently being attacked by either 0, 1, or 2 other players. A key element of Bed Wars strategy is that if a player is being attacked by exactly 1 other player, then they should logically attack that player in response. If instead a player is being attacked by 0 or 2 other players, then Bed Wars strategy says that the player can logically attack either of the adjacent players.
Unfortunately, it might be that some players in this game are not following Bed Wars strategy correctly. Omkar is aware of whom each player is currently attacking, and he can talk to any amount of the n players in the game to make them instead attack another player — i. e. if they are currently attacking the player to their left, Omkar can convince them to instead attack the player to their right; if they are currently attacking the player to their right, Omkar can convince them to instead attack the player to their left.
Omkar would like all players to be acting logically. Calculate the minimum amount of players that Omkar needs to talk to so that after all players he talked to (if any) have changed which player they are attacking, all players are acting logically according to Bed Wars strategy.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). The descriptions of the test cases follows.
The first line of each test case contains one integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the amount of players (and therefore beds) in this game of Bed Wars.
The second line of each test case contains a string s of length n. The j-th character of s is equal to L if the j-th player is attacking the player to their left, and R if the j-th player is attacking the player to their right.
It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5.
Output
For each test case, output one integer: the minimum number of players Omkar needs to talk to to make it so that all players are acting logically according to Bed Wars strategy.
It can be proven that it is always possible for Omkar to achieve this under the given constraints.
Example
Input
5
4
RLRL
6
LRRRRL
8
RLLRRRLL
12
LLLLRRLRRRLL
5
RRRRR
Output
0
1
1
3
2
Note
In the first test case, players 1 and 2 are attacking each other, and players 3 and 4 are attacking each other. Each player is being attacked by exactly 1 other player, and each player is attacking the player that is attacking them, so all players are already being logical according to Bed Wars strategy and Omkar does not need to talk to any of them, making the answer 0.
In the second test case, not every player acts logically: for example, player 3 is attacked only by player 2, but doesn't attack him in response. Omkar can talk to player 3 to convert the attack arrangement to LRLRRL, in which you can see that all players are being logical according to Bed Wars strategy, making the answer 1.
Submitted Solution:
```
# import math
# from collections import Counter
#from collections import defaultdict
#from collections import deque
# from bisect import bisect_left as bl, bisect_right as br
# from itertools import accumulate,permutations as perm,combinations as comb
# from heapq import heapify,heappush,heappop,nlargest,nsmallest
# from fractions import Fraction
import sys
# from functools import reduce, lru_cache
"""author-bravotango. FastIO code by pajenegod"""
def main():
t = Iint()
for _ in range(t):
n = Iint()
s = Istr()
debug(s)
if s == 'R'*n or s == 'L'*n:
ans = (n+2)//3
print(ans)
continue
if s[0] == s[-1]:
debug("check")
c = s[0]
s = s.lstrip(c)
s += c*(n-len(s))
debug(s)
R_same = 0
L_same = 0
prev = ''
ans = 0
for i, si in en(s):
if si == 'R' and prev in ('R', ''):
R_same += 1
elif si == 'L' and prev in ('L', ''):
L_same += 1
elif si == 'R' and prev == 'L':
debug("L", L_same, c=3)
ans += L_same//3
L_same = 0
R_same = 1
elif si == 'L' and prev == 'R':
debug("R", R_same, c=3)
ans += R_same//3
R_same = 0
L_same = 1
prev = si
ans += R_same//3+L_same//3
print(ans)
en = enumerate
# IO region1
FIO = 10
def debug(*args, c=6): pass # ; print('\033[3{}m'.format(c), *args, '\033[0m', file=sys.stderr)
BUFSIZE = 8*1024
def Istr(): return input()
def Iint(): return int(input())
def Ilist(): return list(map(int, input().split())) # int list
def Imap(): return map(int, input().split()) # int map
def Plist(li, s=' '): print(s.join(map(str, li))) # non string iterable
if not FIO:
if __name__ == '__main__':
main()
exit()
else:
from io import BytesIO, IOBase
import os
# FastIO
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
# /IO region
if __name__ == '__main__':
main()
``` | instruction | 0 | 79,328 | 19 | 158,656 |
Yes | output | 1 | 79,328 | 19 | 158,657 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are n players arranged in a circle, so that for all j such that 2 ≤ j ≤ n, player j - 1 is to the left of the player j, and player j is to the right of player j - 1. Additionally, player n is to the left of player 1, and player 1 is to the right of player n.
Currently, each player is attacking either the player to their left or the player to their right. This means that each player is currently being attacked by either 0, 1, or 2 other players. A key element of Bed Wars strategy is that if a player is being attacked by exactly 1 other player, then they should logically attack that player in response. If instead a player is being attacked by 0 or 2 other players, then Bed Wars strategy says that the player can logically attack either of the adjacent players.
Unfortunately, it might be that some players in this game are not following Bed Wars strategy correctly. Omkar is aware of whom each player is currently attacking, and he can talk to any amount of the n players in the game to make them instead attack another player — i. e. if they are currently attacking the player to their left, Omkar can convince them to instead attack the player to their right; if they are currently attacking the player to their right, Omkar can convince them to instead attack the player to their left.
Omkar would like all players to be acting logically. Calculate the minimum amount of players that Omkar needs to talk to so that after all players he talked to (if any) have changed which player they are attacking, all players are acting logically according to Bed Wars strategy.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). The descriptions of the test cases follows.
The first line of each test case contains one integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the amount of players (and therefore beds) in this game of Bed Wars.
The second line of each test case contains a string s of length n. The j-th character of s is equal to L if the j-th player is attacking the player to their left, and R if the j-th player is attacking the player to their right.
It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5.
Output
For each test case, output one integer: the minimum number of players Omkar needs to talk to to make it so that all players are acting logically according to Bed Wars strategy.
It can be proven that it is always possible for Omkar to achieve this under the given constraints.
Example
Input
5
4
RLRL
6
LRRRRL
8
RLLRRRLL
12
LLLLRRLRRRLL
5
RRRRR
Output
0
1
1
3
2
Note
In the first test case, players 1 and 2 are attacking each other, and players 3 and 4 are attacking each other. Each player is being attacked by exactly 1 other player, and each player is attacking the player that is attacking them, so all players are already being logical according to Bed Wars strategy and Omkar does not need to talk to any of them, making the answer 0.
In the second test case, not every player acts logically: for example, player 3 is attacked only by player 2, but doesn't attack him in response. Omkar can talk to player 3 to convert the attack arrangement to LRLRRL, in which you can see that all players are being logical according to Bed Wars strategy, making the answer 1.
Submitted Solution:
```
"""
These sequences are illegal:
RRR
LLL
They are probably the only illegal sequences.
How do we remove these sequences while using minimum moves?
LRRRRRRRRRRRRRRRRRRRL
../../../../../../.
should be disrupted by changing the 'R' tokens.
can this create an annoying L token though?
no probably not.
"""
t = int(input())
def ceildiv(a, b): return (a + b - 1) // b
for case in range(t):
n = int(input())
s = input()
if all(x == s[0] for x in s):
print(ceildiv(n, 3))
else:
if s[0] == s[-1]:
q = s.index('L' if s[0] == 'R' else 'R')
s = s[q:] + s[:q]
c = 0
out = 0
prev = None
for x in s:
if x == prev:
c += 1
else:
out += c // 3
c = 1
prev = x
if c:
out += c // 3
print(out)
``` | instruction | 0 | 79,329 | 19 | 158,658 |
Yes | output | 1 | 79,329 | 19 | 158,659 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are n players arranged in a circle, so that for all j such that 2 ≤ j ≤ n, player j - 1 is to the left of the player j, and player j is to the right of player j - 1. Additionally, player n is to the left of player 1, and player 1 is to the right of player n.
Currently, each player is attacking either the player to their left or the player to their right. This means that each player is currently being attacked by either 0, 1, or 2 other players. A key element of Bed Wars strategy is that if a player is being attacked by exactly 1 other player, then they should logically attack that player in response. If instead a player is being attacked by 0 or 2 other players, then Bed Wars strategy says that the player can logically attack either of the adjacent players.
Unfortunately, it might be that some players in this game are not following Bed Wars strategy correctly. Omkar is aware of whom each player is currently attacking, and he can talk to any amount of the n players in the game to make them instead attack another player — i. e. if they are currently attacking the player to their left, Omkar can convince them to instead attack the player to their right; if they are currently attacking the player to their right, Omkar can convince them to instead attack the player to their left.
Omkar would like all players to be acting logically. Calculate the minimum amount of players that Omkar needs to talk to so that after all players he talked to (if any) have changed which player they are attacking, all players are acting logically according to Bed Wars strategy.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). The descriptions of the test cases follows.
The first line of each test case contains one integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the amount of players (and therefore beds) in this game of Bed Wars.
The second line of each test case contains a string s of length n. The j-th character of s is equal to L if the j-th player is attacking the player to their left, and R if the j-th player is attacking the player to their right.
It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5.
Output
For each test case, output one integer: the minimum number of players Omkar needs to talk to to make it so that all players are acting logically according to Bed Wars strategy.
It can be proven that it is always possible for Omkar to achieve this under the given constraints.
Example
Input
5
4
RLRL
6
LRRRRL
8
RLLRRRLL
12
LLLLRRLRRRLL
5
RRRRR
Output
0
1
1
3
2
Note
In the first test case, players 1 and 2 are attacking each other, and players 3 and 4 are attacking each other. Each player is being attacked by exactly 1 other player, and each player is attacking the player that is attacking them, so all players are already being logical according to Bed Wars strategy and Omkar does not need to talk to any of them, making the answer 0.
In the second test case, not every player acts logically: for example, player 3 is attacked only by player 2, but doesn't attack him in response. Omkar can talk to player 3 to convert the attack arrangement to LRLRRL, in which you can see that all players are being logical according to Bed Wars strategy, making the answer 1.
Submitted Solution:
```
for _ in range(int(input())):
n = int(input())
s = [i for i in input()]
c=0
for i in range(5*n):
if s[i%n]=='R':
if (s[(i-1)%n]=='R' and s[(i+1)%n]=='R'):
c+=1
s[i%n]='L'
else:
if (s[(i-1)%n]=='L' and s[(i+1)%n]=='L'):
c+=1
s[i%n]='R'
#print(s)
print(c)
``` | instruction | 0 | 79,330 | 19 | 158,660 |
No | output | 1 | 79,330 | 19 | 158,661 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.